Skip to content

Commit cebf496

Browse files
committed
[201_41] 模拟OCR通信流程
1 parent ca8faca commit cebf496

File tree

4 files changed

+24
-9
lines changed

4 files changed

+24
-9
lines changed

TeXmacs/plugins/account/progs/liii/ocr.scm

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,14 @@
6666
(go-to p)
6767
(go-to-next-node)
6868
(go-to-next-node)
69-
(let* ((content (get-file-string (unix->url "$TEXMACS_PATH/plugins/account/data/ocr.md")))
70-
(latex-code (get-file-string (unix->url "$TEXMACS_PATH/plugins/account/data/ocr.tex")))
69+
(let* ((content (get-file-string (unix->url "$TEXMACS_PATH/plugins/account/data/ocr.md"))))
70+
(insert `(with "par-mode" "center" (document ,(utf8->cork content))))))
71+
72+
73+
(tm-define (insert-latex)
74+
(let* ((latex-code (get-file-string (unix->url "$TEXMACS_PATH/plugins/account/data/ocr.tex")))
7175
(parsed-latex (parse-latex latex-code))
7276
(texmacs-latex (latex->texmacs parsed-latex)))
73-
(insert `(with "par-mode" "center" (document ,(utf8->cork content))))
7477
(insert texmacs-latex)))
7578

7679
(tm-define (image-ocr-to-latex t)
@@ -87,7 +90,8 @@
8790
(display* "Image has saved to " temp-name "\n"))))
8891
(sleep 5)
8992
(go-to (cursor-path))
90-
(insert `(with "par-mode" "center" (document ,(utf8->cork "很抱歉,目前OCR功能仅为会员用户提供。")))))
93+
(go-to-next-node)
94+
(insert-latex))
9195

9296
; (get-image-extention (get-image t 0 #t)) 获取文件后缀,创建对应临时文件
9397
; (get-image t 0 #f) 获取 raw-data

TeXmacs/progs/generic/format-edit.scm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,15 +173,15 @@
173173
(string=? (tree->string (tree-ref t 0)) "par-mode")
174174
(>= (tree-arity t) 3))
175175
(tree-set! t 1 align)
176-
(debug-message "std-warning" "Invalid tree structure for set-image-alignment" "\n")))
176+
(debug-message "std-warning" "Invalid tree structure for set-image-alignment\n")))
177177

178178
(tm-define (get-image-alignment t)
179179
(if (and (tree-is? t 'with)
180180
(tree-is? (tree-ref t 0) 'string)
181181
(string=? (tree->string (tree-ref t 0)) "par-mode")
182182
(>= (tree-arity t) 3))
183183
(tree->string (tree-ref t 1))
184-
(debug-message "std-warning" "Invalid tree structure for get-image-alignment" "\n")))
184+
(debug-message "std-warning" "Invalid tree structure for get-image-alignment\n")))
185185

186186
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
187187
;; Inserting and toggling with-like tags

devel/201_41.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,18 @@
44
打开201_41.tmu,进行以下测试项:
55
+ 点击图片悬浮菜单的 OCR 按钮,查看是否在图片下方插入了一条 **很抱歉,目前OCR功能仅为会员用户提供。**,以及一行数学公式。
66
+ 查看日志中的提示 **Image has saved to /tmp/temp-currenttime.png**,其中 currenttime 为图片保存时的时间戳,每人各不相同,以控制台日志输出为准。前往目标目录,查看文件是否存在,以及是否能够正常打开。
7-
+ 在数学模式下使用选择性粘贴功能,对应快捷键 **Ctrl+Alt+v**,呼出菜单后选择OCR,点击确定,等待5秒后会插入一句提示信息
8-
+ 使用智能粘贴功能,对应快捷键 **Ctrl+Shift+v**,确保剪贴板最新的内容是一张图片,按下快捷键,等待5秒后会插入一句提示信息
7+
+ 在数学模式下使用选择性粘贴功能,对应快捷键 **Ctrl+Alt+v**,呼出菜单后选择OCR,点击确定,等待5秒后会插入一个数学公式
8+
+ 使用智能粘贴功能,对应快捷键 **Ctrl+Shift+v**,确保剪贴板最新的内容是一张图片,按下快捷键,等待5秒后会插入一个数学公式
9+
+ 使用 **插入图片****粘贴图片** 以外的方式向编辑器输入一张图片,鼠标移入移出图片范围,查看控制台是否正常输出warning
10+
11+
## 2025/12/25 模拟OCR通信流程
12+
13+
### What
14+
15+
+ 商业版编写 demo 文件,跑通 OCR 识别全流程
16+
+ 进行了代码集成的尝试,待后续测试与改进
17+
+ 修改了插入文字的位置,新的插入位置为图片块内部,图片的下方
18+
+ 修复了负责控制图片对齐方式的函数的警告信息输出问题,使用正确的参数个数
919

1020
## 2025/12/24 模拟OCR识别
1121

src/Edit/Interface/edit_mouse.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,7 @@ edit_interface_rep::mouse_any (string type, SI x, SI y, int mods, time_t t,
582582
}
583583
}
584584
bool hovering_image= false;
585+
static path _path = tree_path (path (), x, y, 0);
585586
static path current_path = path ();
586587
static rectangle selr = rectangle ();
587588
if (type == "move") {
@@ -605,7 +606,7 @@ edit_interface_rep::mouse_any (string type, SI x, SI y, int mods, time_t t,
605606
set_cursor_style ("pointing_hand");
606607
path with_path= path_up (current_path);
607608
tree with_tree= subtree (et, with_path);
608-
show_image_popup (current_path, with_tree, selr, magf, get_scroll_x (),
609+
show_image_popup (_path, with_tree, selr, magf, get_scroll_x (),
609610
get_scroll_y (), get_canvas_x ());
610611
}
611612
else {

0 commit comments

Comments
 (0)