Skip to content

Commit 7e16b11

Browse files
committed
打包时移除JRE运行环境;优化快捷键 ESC 判断逻辑
1 parent fcc1e10 commit 7e16b11

File tree

5 files changed

+31
-16
lines changed

5 files changed

+31
-16
lines changed

pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@
8080
<verbose>true</verbose>
8181
<vendor>com.luooqi</vendor>
8282
<needShortcut>true</needShortcut>
83+
<bundleArguments>
84+
<runtime />
85+
</bundleArguments>
8386
</configuration>
8487
</plugin>
8588
</plugins>

readme.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,28 @@
88

99
> 文字识别使用了各云平台开发的识别接口,因此需要联网才能正常使用。
1010
11-
### 程序使用
12-
#### 启动截图
11+
## 程序使用
12+
### 启动截图
1313
- 方法一:在程序主界面点击截图按钮;
1414
- 方法二:点击截图快捷键 F4。
1515

16-
#### 圈选区域
16+
### 圈选区域
1717
进入截图界面后,按下鼠标左键,然后拖动即可圈选所要截取的区域;
1818
圈选结束后,可以对圈选的区域进行微调:
1919
- 使用 **方向键**,可以对所选区域的右边界和上边界进行微调;
2020
- 使用 **Shift+方向键**,可以对所选区域的左边界和下边界进行微调;
2121
- 使用 **Ctrl+A**,可以全选整个屏幕。
2222

23-
#### 确定圈选
23+
### 确定圈选
2424
圈选完成后,点击 `Enter` 或者 `Space` 键,即可确认圈选;确认圈选后,会自动对所选区域进行 OCR 文字识别。
2525

26-
### TODO
26+
## 注意事项
27+
### MAC权限设置
28+
由于监控了截图快捷键,因此MAC需要开启相应的权限,请见下图:
29+
30+
![MAC权限设置](http://img.luooqi.com/Fo31NZQIhPNF6m7gOorRGDuKvaZ_)
31+
32+
## TODO
2733
- [x] 完成图片文字识别
2834
- [x] 识别结果文本对齐(暂未实现多分栏)
2935
- [x] 全屏模式下截图的实现

src/main/java/com/luooqi/ocr/snap/ScreenCapture.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public class ScreenCapture{
4242
private GraphicsContext gc;
4343
private Scene scene;
4444
private Stage stage;
45+
public static boolean isSnaping = false;
4546

4647
/**
4748
* When a key is being pressed into the capture window then this Animation Timer is doing it's magic.
@@ -286,9 +287,11 @@ private void addKeyHandlers() {
286287

287288
if (key.getCode() == KeyCode.ESCAPE || key.getCode() == KeyCode.BACK_SPACE) {
288289
cancelSnap();
290+
isSnaping = false;
289291
} else if (key.getCode() == KeyCode.ENTER || key.getCode() == KeyCode.SPACE) {
290292
deActivateAllKeys();
291293
prepareImage();
294+
isSnaping = false;
292295
}
293296
});
294297

@@ -376,6 +379,7 @@ private void selectWholeScreen() {
376379
}
377380

378381
public void prepareForCapture() {
382+
isSnaping = true;
379383
MainFm.stage.close();
380384
Platform.runLater(()->{
381385
try {

src/main/java/com/luooqi/ocr/utils/CommUtils.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ public static byte[] imageToBytes(BufferedImage img) {
5252
}
5353
}
5454

55-
public static String combineTextBlocks(List<TextBlock> textBlocks) {
56-
Collections.sort(textBlocks, Comparator.comparingInt(o -> o.getTopLeft().y));
55+
static String combineTextBlocks(List<TextBlock> textBlocks) {
56+
textBlocks.sort(Comparator.comparingInt(o -> o.getTopLeft().y));
5757
List<List<TextBlock>> lineBlocks = new ArrayList<>();
5858
int lastY = -1;
5959
List<TextBlock> lineBlock = new ArrayList<>();
@@ -69,7 +69,7 @@ public static String combineTextBlocks(List<TextBlock> textBlocks) {
6969
sameLine = textBlock.getTopLeft().y - lastY <= SAME_LINE_LIMIT;
7070
}
7171
if (!sameLine) {
72-
Collections.sort(lineBlock, Comparator.comparingInt(o -> o.getTopLeft().x));
72+
lineBlock.sort(Comparator.comparingInt(o -> o.getTopLeft().x));
7373
lineBlocks.add(lineBlock);
7474
lineBlock = new ArrayList<>();
7575
sameLine = true;
@@ -78,7 +78,7 @@ public static String combineTextBlocks(List<TextBlock> textBlocks) {
7878
lineBlock.add(textBlock);
7979
}
8080
if (lineBlock.size() > 0) {
81-
Collections.sort(lineBlock, Comparator.comparingInt(o -> o.getTopLeft().x));
81+
lineBlock.sort(Comparator.comparingInt(o -> o.getTopLeft().x));
8282
lineBlocks.add(lineBlock);
8383
}
8484
StringBuilder sb = new StringBuilder();
@@ -99,16 +99,16 @@ public static String combineTextBlocks(List<TextBlock> textBlocks) {
9999
return sb.toString();
100100
}
101101

102-
public static Point frameToPoint(String text) {
102+
static Point frameToPoint(String text) {
103103
String[] arr = text.split(",");
104104
return new Point(Integer.valueOf(arr[0].trim()), Integer.valueOf(arr[1].trim()));
105105
}
106106

107-
public static String postMultiData(String url, byte[] data, String boundary) {
107+
static String postMultiData(String url, byte[] data, String boundary) {
108108
return postMultiData(url, data, boundary, "", "");
109109
}
110110

111-
public static String postMultiData(String url, byte[] data, String boundary, String cookie, String referer) {
111+
private static String postMultiData(String url, byte[] data, String boundary, String cookie, String referer) {
112112
try {
113113
HttpRequest request = HttpUtil.createPost(url).timeout(15000);
114114
request.contentType("multipart/form-data; boundary=" + boundary);
@@ -127,7 +127,7 @@ public static String postMultiData(String url, byte[] data, String boundary, Str
127127
}
128128
}
129129

130-
public static byte[] mergeByte(byte[]... bytes) {
130+
static byte[] mergeByte(byte[]... bytes) {
131131
int length = 0;
132132
for (byte[] b : bytes) {
133133
length += b.length;

src/main/java/com/luooqi/ocr/utils/GlobalKeyListener.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import cn.hutool.log.StaticLog;
44
import com.luooqi.ocr.MainFm;
5-
import org.jnativehook.GlobalScreen;
5+
import com.luooqi.ocr.snap.ScreenCapture;
66
import org.jnativehook.NativeInputEvent;
77
import org.jnativehook.keyboard.NativeKeyEvent;
88
import org.jnativehook.keyboard.NativeKeyListener;
@@ -22,8 +22,10 @@ public void nativeKeyPressed(NativeKeyEvent e) {
2222
MainFm.doSnap();
2323
}
2424
else if (e.getKeyCode() == NativeKeyEvent.VC_ESCAPE){
25-
preventEvent(e);
26-
MainFm.cancelSnap();
25+
if (ScreenCapture.isSnaping){
26+
preventEvent(e);
27+
MainFm.cancelSnap();
28+
}
2729
}
2830
}
2931

0 commit comments

Comments
 (0)