Skip to content

Commit 33206e6

Browse files
committed
[201_41] 社区版ocr提示、代码整理与格式化
1 parent cebf496 commit 33206e6

File tree

7 files changed

+17
-28
lines changed

7 files changed

+17
-28
lines changed

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,16 @@
6262
(when (url-exists? p)
6363
(string-load p)))
6464

65-
(tm-define (insert-tips p)
66-
(go-to p)
67-
(go-to-next-node)
65+
(tm-define (insert-tips)
66+
(go-to (cursor-path))
6867
(go-to-next-node)
6968
(let* ((content (get-file-string (unix->url "$TEXMACS_PATH/plugins/account/data/ocr.md"))))
7069
(insert `(with "par-mode" "center" (document ,(utf8->cork content))))))
7170

7271

7372
(tm-define (insert-latex)
73+
(go-to (cursor-path))
74+
(go-to-next-node)
7475
(let* ((latex-code (get-file-string (unix->url "$TEXMACS_PATH/plugins/account/data/ocr.tex")))
7576
(parsed-latex (parse-latex latex-code))
7677
(texmacs-latex (latex->texmacs parsed-latex)))
@@ -88,15 +89,12 @@
8889
(binary-data (decode-base64 base64-str)))
8990
(string-save binary-data temp-name)
9091
(display* "Image has saved to " temp-name "\n"))))
91-
(sleep 5)
92-
(go-to (cursor-path))
93-
(go-to-next-node)
94-
(insert-latex))
92+
(insert-tips))
9593

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

99-
(tm-define (create-temp-image t p)
97+
(tm-define (create-temp-image t)
10098
(let* ((extention
10199
(get-image-extention (get-image t 0 #t)))
102100
(temp-name
@@ -108,4 +106,4 @@
108106
(binary-data (decode-base64 base64-str)))
109107
(string-save binary-data temp-name)
110108
(display* "Image has saved to " temp-name "\n"))))
111-
(insert-tips p))
109+
(insert-tips))

devel/201_41.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
## 如何测试
44
打开201_41.tmu,进行以下测试项:
5-
+ 点击图片悬浮菜单的 OCR 按钮,查看是否在图片下方插入了一条 **很抱歉,目前OCR功能仅为会员用户提供**,以及一行数学公式。
5+
+ 点击图片悬浮菜单的 OCR 按钮,查看是否在图片下方插入了一条 **很抱歉,目前OCR功能仅为会员用户提供**
66
+ 查看日志中的提示 **Image has saved to /tmp/temp-currenttime.png**,其中 currenttime 为图片保存时的时间戳,每人各不相同,以控制台日志输出为准。前往目标目录,查看文件是否存在,以及是否能够正常打开。
7-
+ 在数学模式下使用选择性粘贴功能,对应快捷键 **Ctrl+Alt+v**,呼出菜单后选择OCR,点击确定,等待5秒后会插入一个数学公式
8-
+ 使用智能粘贴功能,对应快捷键 **Ctrl+Shift+v**,确保剪贴板最新的内容是一张图片,按下快捷键,等待5秒后会插入一个数学公式
9-
+ 使用 **插入图片****粘贴图片** 以外的方式向编辑器输入一张图片,鼠标移入移出图片范围,查看控制台是否正常输出warning
7+
+ 在数学模式下使用选择性粘贴功能,对应快捷键 **Ctrl+Alt+v**,呼出菜单后选择OCR,点击确定,等待5秒后会插入一条 **很抱歉,目前OCR功能仅为会员用户提供**
8+
+ 使用智能粘贴功能,对应快捷键 **Ctrl+Shift+v**,确保剪贴板最新的内容是一张图片,按下快捷键,等待5秒后会插入一条 **很抱歉,目前OCR功能仅为会员用户提供**
9+
+ 使用 **插入图片****粘贴图片** 以外的方式,即除了 **Ctrl+Alt+v** 粘贴图片以及 **插入->图片->插入图片** 以外的任何方式向编辑器输入一张图片,这里建议的方法是直接将文件夹中的图片拖入 Mogan,这样会插入一个没有经过处理的,能够稳定弹出警告的图片。插入后将鼠标移入移出图片范围,查看控制台是否正常输出 **std-warning**,而不是 **too many arguement...**
1010

1111
## 2025/12/25 模拟OCR通信流程
1212

src/Edit/Interface/edit_mouse.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,6 @@ 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);
586585
static path current_path = path ();
587586
static rectangle selr = rectangle ();
588587
if (type == "move") {
@@ -606,8 +605,8 @@ edit_interface_rep::mouse_any (string type, SI x, SI y, int mods, time_t t,
606605
set_cursor_style ("pointing_hand");
607606
path with_path= path_up (current_path);
608607
tree with_tree= subtree (et, with_path);
609-
show_image_popup (_path, with_tree, selr, magf, get_scroll_x (),
610-
get_scroll_y (), get_canvas_x ());
608+
show_image_popup (with_tree, selr, magf, get_scroll_x (), get_scroll_y (),
609+
get_canvas_x ());
611610
}
612611
else {
613612
set_cursor_style ("normal");

src/Plugins/Qt/QTMImagePopup.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,6 @@ QTMImagePopup::showImagePopup (rectangle selr, double magf, int scroll_x,
106106
show ();
107107
}
108108

109-
void
110-
QTMImagePopup::setImagePath (path p) {
111-
this->current_path= p;
112-
}
113-
114109
void
115110
QTMImagePopup::setImageTree (tree t) {
116111
this->current_tree= t;

src/Plugins/Qt/QTMImagePopup.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ class QTMImagePopup : public QWidget {
4949
int canvas_x);
5050
void updatePosition ();
5151
void scrollBy (int x, int y);
52-
void setImagePath (path p);
5352
void setImageTree (tree t);
5453
void updateButtonStates ();
5554
void autoSize ();

src/Plugins/Qt/qt_simple_widget.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -760,12 +760,10 @@ qt_simple_widget_rep::ensure_image_popup () {
760760
}
761761

762762
void
763-
qt_simple_widget_rep::show_image_popup (path current_path, tree current_tree,
764-
rectangle selr, double magf,
765-
int scroll_x, int scroll_y,
763+
qt_simple_widget_rep::show_image_popup (tree current_tree, rectangle selr,
764+
double magf, int scroll_x, int scroll_y,
766765
int canvas_x) {
767766
ensure_image_popup ();
768-
imagePopUp->setImagePath (current_path);
769767
imagePopUp->setImageTree (current_tree);
770768
imagePopUp->showImagePopup (selr, magf, scroll_x, scroll_y, canvas_x);
771769
}

src/Plugins/Qt/qt_simple_widget.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ class qt_simple_widget_rep : public qt_widget_rep {
115115

116116
////////////////////// Image popup support
117117
void ensure_image_popup ();
118-
void show_image_popup (path current_path, tree current_tree, rectangle selr,
119-
double magf, int scroll_x, int scroll_y, int canvas_x);
118+
void show_image_popup (tree current_tree, rectangle selr, double magf,
119+
int scroll_x, int scroll_y, int canvas_x);
120120
void hide_image_popup ();
121121
void scroll_image_popup_by (SI x, SI y);
122122

0 commit comments

Comments
 (0)