diff --git a/TeXmacs/plugins/account/data/ocr.tex b/TeXmacs/plugins/account/data/ocr.tex index 5dd1a2406a..3e9c29a1d4 100644 --- a/TeXmacs/plugins/account/data/ocr.tex +++ b/TeXmacs/plugins/account/data/ocr.tex @@ -1,3 +1,4 @@ \begin{document} -\[ e^{i\pi} + 1 = 0 \] +很抱歉,目前OCR功能仅为会员用户提供。\ +详情请见 \url{https://liiistem.cn/} 注册即送14天会员! \end{document} \ No newline at end of file diff --git a/TeXmacs/plugins/account/progs/liii/ocr.scm b/TeXmacs/plugins/account/progs/liii/ocr.scm index 2a02062ce5..ca3b67e9b1 100644 --- a/TeXmacs/plugins/account/progs/liii/ocr.scm +++ b/TeXmacs/plugins/account/progs/liii/ocr.scm @@ -62,15 +62,19 @@ (when (url-exists? p) (string-load p))) -(tm-define (insert-tips p) - (go-to p) +(tm-define (insert-tips) + (go-to (cursor-path)) (go-to-next-node) + (let* ((content (get-file-string (unix->url "$TEXMACS_PATH/plugins/account/data/ocr.md")))) + (insert `(with "par-mode" "center" (document ,(utf8->cork content)))))) + + +(tm-define (insert-latex) + (go-to (cursor-path)) (go-to-next-node) - (let* ((content (get-file-string (unix->url "$TEXMACS_PATH/plugins/account/data/ocr.md"))) - (latex-code (get-file-string (unix->url "$TEXMACS_PATH/plugins/account/data/ocr.tex"))) + (let* ((latex-code (get-file-string (unix->url "$TEXMACS_PATH/plugins/account/data/ocr.tex"))) (parsed-latex (parse-latex latex-code)) (texmacs-latex (latex->texmacs parsed-latex))) - (insert `(with "par-mode" "center" (document ,(utf8->cork content)))) (insert texmacs-latex))) (tm-define (image-ocr-to-latex t) @@ -85,14 +89,12 @@ (binary-data (decode-base64 base64-str))) (string-save binary-data temp-name) (display* "Image has saved to " temp-name "\n")))) - (sleep 5) - (go-to (cursor-path)) - (insert `(with "par-mode" "center" (document ,(utf8->cork "很抱歉,目前OCR功能仅为会员用户提供。"))))) + (insert-latex)) ; (get-image-extention (get-image t 0 #t)) 获取文件后缀,创建对应临时文件 ; (get-image t 0 #f) 获取 raw-data -(tm-define (create-temp-image t p) +(tm-define (create-temp-image t) (let* ((extention (get-image-extention (get-image t 0 #t))) (temp-name @@ -104,4 +106,4 @@ (binary-data (decode-base64 base64-str))) (string-save binary-data temp-name) (display* "Image has saved to " temp-name "\n")))) - (insert-tips p)) \ No newline at end of file + (insert-latex)) \ No newline at end of file diff --git a/TeXmacs/progs/generic/format-edit.scm b/TeXmacs/progs/generic/format-edit.scm index 6063d573c2..35dbfe5ed6 100644 --- a/TeXmacs/progs/generic/format-edit.scm +++ b/TeXmacs/progs/generic/format-edit.scm @@ -173,7 +173,7 @@ (string=? (tree->string (tree-ref t 0)) "par-mode") (>= (tree-arity t) 3)) (tree-set! t 1 align) - (debug-message "std-warning" "Invalid tree structure for set-image-alignment" "\n"))) + (debug-message "std-warning" "Invalid tree structure for set-image-alignment\n"))) (tm-define (get-image-alignment t) (if (and (tree-is? t 'with) @@ -181,7 +181,7 @@ (string=? (tree->string (tree-ref t 0)) "par-mode") (>= (tree-arity t) 3)) (tree->string (tree-ref t 1)) - (debug-message "std-warning" "Invalid tree structure for get-image-alignment" "\n"))) + (debug-message "std-warning" "Invalid tree structure for get-image-alignment\n"))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Inserting and toggling with-like tags diff --git a/devel/201_41.md b/devel/201_41.md index a1e1f7566e..f7dadbc4f1 100644 --- a/devel/201_41.md +++ b/devel/201_41.md @@ -2,10 +2,20 @@ ## 如何测试 打开201_41.tmu,进行以下测试项: -+ 点击图片悬浮菜单的 OCR 按钮,查看是否在图片下方插入了一条 **很抱歉,目前OCR功能仅为会员用户提供。**,以及一行数学公式。 ++ 点击图片悬浮菜单的 OCR 按钮,查看是否在图片下方插入了一条 **很抱歉,目前OCR功能仅为会员用户提供** + 查看日志中的提示 **Image has saved to /tmp/temp-currenttime.png**,其中 currenttime 为图片保存时的时间戳,每人各不相同,以控制台日志输出为准。前往目标目录,查看文件是否存在,以及是否能够正常打开。 -+ 在数学模式下使用选择性粘贴功能,对应快捷键 **Ctrl+Alt+v**,呼出菜单后选择OCR,点击确定,等待5秒后会插入一句提示信息 -+ 使用智能粘贴功能,对应快捷键 **Ctrl+Shift+v**,确保剪贴板最新的内容是一张图片,按下快捷键,等待5秒后会插入一句提示信息 ++ 在数学模式下使用选择性粘贴功能,对应快捷键 **Ctrl+Alt+v**,呼出菜单后选择OCR,点击确定,等待5秒后会插入一条 **很抱歉,目前OCR功能仅为会员用户提供** ++ 使用智能粘贴功能,对应快捷键 **Ctrl+Shift+v**,确保剪贴板最新的内容是一张图片,按下快捷键,等待5秒后会插入一条 **很抱歉,目前OCR功能仅为会员用户提供** ++ 使用 **插入图片** 与 **粘贴图片** 以外的方式,即除了 **Ctrl+Alt+v** 粘贴图片以及 **插入->图片->插入图片** 以外的任何方式向编辑器输入一张图片,这里建议的方法是直接将文件夹中的图片拖入 Mogan,这样会插入一个没有经过处理的,能够稳定弹出警告的图片。插入后将鼠标移入移出图片范围,查看控制台是否正常输出 **std-warning**,而不是 **too many arguments...** + +## 2025/12/25 模拟OCR通信流程 + +### What + ++ 商业版编写 demo 文件,跑通 OCR 识别全流程 ++ 进行了代码集成的尝试,待后续测试与改进 ++ 修改了插入文字的位置,新的插入位置为图片块内部,图片的下方 ++ 修复了负责控制图片对齐方式的函数的警告信息输出问题,使用正确的参数个数 ## 2025/12/24 模拟OCR识别 diff --git a/src/Edit/Interface/edit_mouse.cpp b/src/Edit/Interface/edit_mouse.cpp index faef137b10..22444d8141 100644 --- a/src/Edit/Interface/edit_mouse.cpp +++ b/src/Edit/Interface/edit_mouse.cpp @@ -605,8 +605,8 @@ edit_interface_rep::mouse_any (string type, SI x, SI y, int mods, time_t t, set_cursor_style ("pointing_hand"); path with_path= path_up (current_path); tree with_tree= subtree (et, with_path); - show_image_popup (current_path, with_tree, selr, magf, get_scroll_x (), - get_scroll_y (), get_canvas_x ()); + show_image_popup (with_tree, selr, magf, get_scroll_x (), get_scroll_y (), + get_canvas_x ()); } else { set_cursor_style ("normal"); diff --git a/src/Plugins/Qt/QTMImagePopup.cpp b/src/Plugins/Qt/QTMImagePopup.cpp index b34f911c93..85e33777ad 100644 --- a/src/Plugins/Qt/QTMImagePopup.cpp +++ b/src/Plugins/Qt/QTMImagePopup.cpp @@ -76,7 +76,7 @@ QTMImagePopup::QTMImagePopup (QWidget* parent, qt_simple_widget_rep* owner) else if (button == rightBtn) call ("set-image-alignment", current_tree, "right"); else if (button == ocrBtn) - call ("create-temp-image", current_tree, current_path); + call ("create-temp-image", current_tree); current_align= as_string (call ("get-image-alignment", current_tree)); }); @@ -106,11 +106,6 @@ QTMImagePopup::showImagePopup (rectangle selr, double magf, int scroll_x, show (); } -void -QTMImagePopup::setImagePath (path p) { - this->current_path= p; -} - void QTMImagePopup::setImageTree (tree t) { this->current_tree= t; diff --git a/src/Plugins/Qt/QTMImagePopup.hpp b/src/Plugins/Qt/QTMImagePopup.hpp index 26209adee2..3fd68ede7c 100644 --- a/src/Plugins/Qt/QTMImagePopup.hpp +++ b/src/Plugins/Qt/QTMImagePopup.hpp @@ -32,7 +32,6 @@ class QTMImagePopup : public QWidget { int cached_scroll_y; // 页面滚动位置y int cached_canvas_x; double cached_magf; // 缩放因子 - path current_path; tree current_tree; string current_align; QToolButton* leftBtn; @@ -49,7 +48,6 @@ class QTMImagePopup : public QWidget { int canvas_x); void updatePosition (); void scrollBy (int x, int y); - void setImagePath (path p); void setImageTree (tree t); void updateButtonStates (); void autoSize (); diff --git a/src/Plugins/Qt/qt_simple_widget.cpp b/src/Plugins/Qt/qt_simple_widget.cpp index a9f2ecf745..b814ce9dd8 100644 --- a/src/Plugins/Qt/qt_simple_widget.cpp +++ b/src/Plugins/Qt/qt_simple_widget.cpp @@ -760,12 +760,10 @@ qt_simple_widget_rep::ensure_image_popup () { } void -qt_simple_widget_rep::show_image_popup (path current_path, tree current_tree, - rectangle selr, double magf, - int scroll_x, int scroll_y, +qt_simple_widget_rep::show_image_popup (tree current_tree, rectangle selr, + double magf, int scroll_x, int scroll_y, int canvas_x) { ensure_image_popup (); - imagePopUp->setImagePath (current_path); imagePopUp->setImageTree (current_tree); imagePopUp->showImagePopup (selr, magf, scroll_x, scroll_y, canvas_x); } diff --git a/src/Plugins/Qt/qt_simple_widget.hpp b/src/Plugins/Qt/qt_simple_widget.hpp index 7cc6d885b5..4d0ee920f6 100644 --- a/src/Plugins/Qt/qt_simple_widget.hpp +++ b/src/Plugins/Qt/qt_simple_widget.hpp @@ -115,8 +115,8 @@ class qt_simple_widget_rep : public qt_widget_rep { ////////////////////// Image popup support void ensure_image_popup (); - void show_image_popup (path current_path, tree current_tree, rectangle selr, - double magf, int scroll_x, int scroll_y, int canvas_x); + void show_image_popup (tree current_tree, rectangle selr, double magf, + int scroll_x, int scroll_y, int canvas_x); void hide_image_popup (); void scroll_image_popup_by (SI x, SI y);