From b6ee3dedcc000c1740cbc89529c0fb1016c081c4 Mon Sep 17 00:00:00 2001 From: Kinneyzhang Date: Tue, 29 Jul 2025 15:43:23 +0800 Subject: [PATCH 1/2] fix bug when a line only has one word ends with hyphen --- ekp.el | 10 ++++++++-- tests/ekp-tests.el | 8 +------- tests/text-zh-en_US.txt | 2 +- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/ekp.el b/ekp.el index 99caa3b..094dee9 100644 --- a/ekp.el +++ b/ekp.el @@ -546,7 +546,8 @@ return the value of KEY in plist." "Line glues include glues before first box and after last box. So the length of line glues is: line-boxes-num + 1" (let* ((boxes-widths (ekp-boxes-widths string)) - (boxes-num (length (ekp-boxes string))) + (boxes (ekp-boxes string)) + (boxes-num (length boxes)) (glues-types (ekp-glues-types string)) (ideal-prefixs (ekp-ideal-prefixs string)) (max-prefixs (ekp-max-prefixs string)) @@ -564,7 +565,12 @@ So the length of line glues is: line-boxes-num + 1" (setq line-glue (cond ((= 1 (length line-boxes-widths)) - (list 0 (- line-pixel (aref line-boxes-widths 0)))) + (if (ekp-hyphenate-p glues-types end) + ;; ends with hyphen, minus hyphen-pixel + (list 0 (- line-pixel + (ekp-hyphen-pixel string) + (aref line-boxes-widths 0))) + (list 0 (- line-pixel (aref line-boxes-widths 0))))) (is-last (append '(0) (mapcar #'ekp-glue-ideal-pixel line-glues-types) diff --git a/tests/ekp-tests.el b/tests/ekp-tests.el index ac7644f..c2014ce 100644 --- a/tests/ekp-tests.el +++ b/tests/ekp-tests.el @@ -50,7 +50,7 @@ ;; (ekp-test-justify nil "fr" "Cascadia Next SC" 666) ;; (ekp-test-justify nil "de_DE" "Cascadia Next SC" 666) ;; (ekp-test-justify "zh" "en_US" "Noto Serif" 689) -;; (ekp-test-justify "zh" nil nil 250) +;; (ekp-test-justify "zh" nil nil 980) ;;; FIXME: font size also affect! @@ -78,9 +78,3 @@ (sit-for 0.00001)))))) ;; (ekp-test-demo 400 800 1) - -;; (ekp-clear-caches) -;; (ekp-test-justify "zh2" "en_US" "Cascadia Next SC" 666) -;; (ekp-boxes (ekp-test-str "zh2" "en_US" "Cascadia Next SC")) -;; (ekp-split-to-boxes "用户可通过​​Emacs Lisp (elisp)​​ 重新定义编辑行为") -;; (ekp-split-to-boxes "用户可通过​​Emacs Lisp (elisp)​​​​ 重新定义编辑行为") diff --git a/tests/text-zh-en_US.txt b/tests/text-zh-en_US.txt index b528a74..6dad5e5 100644 --- a/tests/text-zh-en_US.txt +++ b/tests/text-zh-en_US.txt @@ -1,5 +1,5 @@ 作为神之编辑器(Editor of the Gods),Emacs 早已超越了普通文本编辑器的范畴。它是由​​Richard Stallman​​于1976年创建的​​GNU项目​核心组件,其名字源自 Editor MACroS​​。在过去的半个世纪里,Emacs演化成了一个​​self-documenting, customizable, extensible​​的生态系统,用户可通过​​Emacs Lisp (elisp)​​ 重新定义编辑行为。M-x 是每个Emacer的魔法咒语——按下Alt(或Meta键)加x即可召唤任意命令,比如M-x butterfly这样的复活节彩蛋。中国开发者常戏称其为“​​永远的操作系统​​”,因为你可以通过org-mode管理TODO list、用magit操作Git仓库、甚至用EMMS播放MP3音乐。在Unix哲学中,Emacs坚持“一个编辑器统治所有​​”(One Editor to Rule Them All)的理念,这与VS Code等现代编辑器形成鲜明对比。C-x C-f打开文件,C-x C-s保存文档,看似复杂的组合键一旦形成​​肌肉记忆​​,效率就会呈指数级飙升。著名Python库Black的开发者曾公开表示:"​​My .emacs is my second brain.​​" -当然,​​学习曲线​​(Learning Curve)也是陡峭的。新用户需要理解buffer、window、frame的区别:当你C-x 2分割视窗时,两个窗口共享同一个frame;而C-x 5 2会创建新frame——这种设计对Retina显示屏尤其友好。中文用户还必须配置ivy或helm这类模糊搜索插件来优化中文输入,著名的.emacs.d配置仓库如 purcell/emacs.d 在GitHub上有超过​​11k stars​​。最令人震撼的是其​​实时文档系统​​:按下C-h k后点击任何按键组合,都会弹出对应函数的elisp文档。这种​​introspective capability​​让定制化没有边界。有程序员开玩笑说:“当你终于调通.emacs配置时,第一件事应该是用M-x doctor找心理医生。” 毕竟,谁没经历过因为(setq indent-tabs-mode nil)配置错误导致Python代码崩溃的深夜呢? +当然,​​学习曲线​​(Learning Curve)也是陡峭的。新用户需要理解buffer、window、frame的区别:当你C-x 2分割视窗时,两个窗口共享同一个frame;而C-x 5 2会创建新frame —— 这种设计对Retina显示屏尤其友好。中文用户还必须配置ivy或helm这类模糊搜索插件来优化中文输入,著名的.emacs.d配置仓库如 purcell/emacs.d 在GitHub上有超过​​11k stars​​。最令人震撼的是其​​实时文档系统​​:按下C-h k后点击任何按键组合,都会弹出对应函数的elisp文档。这种​​introspective capability​​让定制化没有边界。有程序员开玩笑说:“当你终于调通.emacs配置时,第一件事应该是用M-x doctor找心理医生。” 毕竟,谁没经历过因为(setq indent-tabs-mode nil)配置错误导致Python代码崩溃的深夜呢? Emacs哲学的精髓在于:​​不是工具适应人,而是人塑造工具​​(Not the tool adapts to human, but human forges the tool)。正如Stallman所言:"​​Free as in freedom.​​" 当你用org-capture记录灵感时,用gnus收发邮件时,甚至用M-x tetris摸鱼时,都是在践行这种数字世界的自由意志。(注:This text intentionally contains mixed spacing/tab alignment for KP algorithm testing purposes. 本文故意包含混合空格/制表符对齐以测试KP算法。) From 3d1e975878e560d1ead8d9b5d5308eb09e82e1a6 Mon Sep 17 00:00:00 2001 From: Kinneyzhang Date: Thu, 31 Jul 2025 10:51:39 +0800 Subject: [PATCH 2/2] update readme --- readme.md | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.md b/readme.md index 6979edc..feaa3c4 100644 --- a/readme.md +++ b/readme.md @@ -56,6 +56,7 @@ Formats the text STRING to fit a pixel width of LINE-PIXEL per line and returns Searches for optimal typesetting within the range of MIN-PIXEL to MAX-PIXEL. Returns a cons-cell where the car is the formatted text and the cdr is the pixel value achieving the best typesetting result. Please Note: This function iteratively computes the typesetting cost between the minimum and maximum pixel values to find the optimal case at the minimum cost. ​​If the specified range is too large, execution time may increase significantly.​​ Future updates plan to leverage Rust dynamic libraries for parallel computation to improve performance. ## Next Todos +- [ ] Preserve the original text's text properties. - [ ] Refactor using Rust dynamic modules: Utilize Rust's parallel computing capabilities to enhance rendering performance. - [ ] Implement autocorrection for punctuation: Correct English punctuation mistakenly used in Chinese text; Correct Chinese punctuation mistakenly used in English texts...