Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion TeXmacs/plugins/account/data/ocr.tex
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
\begin{document}
\[ e^{i\pi} + 1 = 0 \]
很抱歉,目前OCR功能仅为会员用户提供。\
详情请见 \url{https://liiistem.cn/} 注册即送14天会员!
\end{document}
22 changes: 12 additions & 10 deletions TeXmacs/plugins/account/progs/liii/ocr.scm
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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))
(insert-latex))
4 changes: 2 additions & 2 deletions TeXmacs/progs/generic/format-edit.scm
Original file line number Diff line number Diff line change
Expand Up @@ -173,15 +173,15 @@
(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)
(tree-is? (tree-ref t 0) 'string)
(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
Expand Down
16 changes: 13 additions & 3 deletions devel/201_41.md
Original file line number Diff line number Diff line change
Expand Up @@ -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识别

Expand Down
4 changes: 2 additions & 2 deletions src/Edit/Interface/edit_mouse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
7 changes: 1 addition & 6 deletions src/Plugins/Qt/QTMImagePopup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 0 additions & 2 deletions src/Plugins/Qt/QTMImagePopup.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 ();
Expand Down
6 changes: 2 additions & 4 deletions src/Plugins/Qt/qt_simple_widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Plugins/Qt/qt_simple_widget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down