diff --git a/ekp-utils.el b/ekp-utils.el index 35af018..77d581e 100644 --- a/ekp-utils.el +++ b/ekp-utils.el @@ -76,13 +76,11 @@ (if-let ((font-family (ekp-monospace-p string))) (string-pixel-width (propertize " " 'face `(:family ,font-family))) - ;; font is not monospace, use the pixel of letter n - ;; as word spacing pixel (let* ((letter (ekp-get-latin-letter string)) (font-family (ekp-font-family letter))) (string-pixel-width (propertize - "n" 'face `(:family ,font-family)))))) + " " 'face `(:family ,font-family)))))) (defun ekp-latin-font (string) (if-let ((letter (ekp-get-latin-letter string))) diff --git a/ekp.el b/ekp.el index 97e9202..bec2ff0 100644 --- a/ekp.el +++ b/ekp.el @@ -74,8 +74,8 @@ (let* ((lws-pixel (ekp-word-spacing-pixel string)) (mws-pixel (- lws-pixel 2))) (ekp-param-set - lws-pixel (round (* lws-pixel 0.5)) (round (* lws-pixel 0.33)) - mws-pixel (round (* mws-pixel 0.5)) (round (* mws-pixel 0.33)) + lws-pixel (round (* lws-pixel 0.5)) (round (* lws-pixel 0.333)) + mws-pixel (round (* mws-pixel 0.5)) (round (* mws-pixel 0.333)) 0 2 0))) (defun ekp-param-set ( lws-ideal lws-stretch lws-shrink diff --git a/readme.md b/readme.md index acdc775..1f32844 100644 --- a/readme.md +++ b/readme.md @@ -15,6 +15,32 @@ Currently, it only supports hybrid typesetting between CJK and one Latin-based l `ekp-latin-lang` is used to set the primary Latin-based language in the text. The default setting is "en_US". All supported languages can be found in the "dictionaries" directory. The language name must match the name following "hyph_" in the dictionary files. Test cases include examples of German and French typesetting. Other languages have not been tested extensively but should theoretically work; however, finer customization may be required. +`ekp-param-set` is a function used to configure fundamental typesetting parameters. These parameters include: + +| Parameter | Meaning | +|:----------------------|:---------------------------------------------------------------| +| ekp-lws-ideal-pixel | Ideal pixel width between Latin words | +| ekp-lws-stretch-pixel | Stretchable pixel width between Latin words | +| ekp-lws-shrink-pixel | Shrinkable pixel width between Latin words | +| ekp-mws-ideal-pixel | Ideal pixel width between Latin words and CJK characters | +| ekp-mws-stretch-pixel | Stretchable pixel width between Latin words and CJK characters | +| ekp-mws-shrink-pixel | Shrinkable pixel width between Latin words and CJK characters | +| ekp-cws-ideal-pixel | Ideal pixel width between CJK characters | +| ekp-cws-stretch-pixel | Stretchable pixel width between CJK characters | +| ekp-cws-shrink-pixel | Shrinkable pixel width between CJK characters | + +For example: `(ekp-param-set 7 3 2 5 2 1 0 2 0)` sets the above parameters accordingly. **​​Do not modify these variables directly – always use this function for configuration.​​** + +If not manually configured, the default values follow KP algorithm recommendations for spaces between latin words: + +- The ideal width is set to the pixel width of a space character +- The stretchable width defaults to 1/2 of the ideal width +- The Shrinkable width defaults to 1/3 of the ideal width + +For spaces between latin word and CJK character: `ekp-mws-ideal-pixel = ekp-lws-ideal-pixel - 2` while maintaining the same stretch/shrink proportions. + +For spaces between CJK characters: Ideal width between CJK characters defaults to 0. Stretchable width between CJK characters defaults to 2 pixels. Shrinkable width between CJK characters defaults to 0 (non-compressible). + ### Core Functions Two functions are provided: @@ -25,4 +51,4 @@ Formats the text STRING to fit a pixel width of LINE-PIXEL per line and returns ```(ekp-pixel-range-justify string min-pixel max-pixel)``` -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. \ No newline at end of file +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. diff --git a/readme_zh.md b/readme_zh.md index 6b1f860..25e5615 100644 --- a/readme_zh.md +++ b/readme_zh.md @@ -14,6 +14,24 @@ Emacs-kp 实现了 knuth-plass 排版算法,但其功能不局限于英文排 ### 配置项 `ekp-latin-lang` 用来设置文本中主要的拉丁系语言,默认设置为 "en_US",dictionaries 下可以看到所有支持的语言,语言的名称也需要按照词典中 hyph_ 后面的名称来设置。测试用例中有德文和法文排版的例子,其他语言没有测试过,理论上应该没有问题,但不排除需要更为细节的调教。 +`ekp-param-set` 这是一个函数,用来设置排版的基础参数,它们分别为: + +| 参数 | 含义 | +|:----------------------|:------------------------------------------| +| ekp-lws-ideal-pixel | 拉丁语言单词之间的理想像素宽度 | +| ekp-lws-stretch-pixel | 拉丁语言单词之间的可拉伸像素宽度 | +| ekp-lws-shrink-pixel | 拉丁语言单词之间的可压缩像素宽度 | +| ekp-mws-ideal-pixel | 拉丁语言单词和CJK字符之间的理想像素宽度 | +| ekp-mws-stretch-pixel | 拉丁语言单词和CJK字符之间的可拉伸像素宽度 | +| ekp-mws-shrink-pixel | 拉丁语言单词和CJK字符之间的可压缩像素宽度 | +| ekp-cws-ideal-pixel | CJK字符之间的理想像素宽度 | +| ekp-cws-stretch-pixel | CJK字符之间的可拉伸像素宽度 | +| ekp-cws-shrink-pixel | CJK字符之间的可压缩像素宽度 | + +例如 `(ekp-param-set 7 3 2 5 2 1 0 2 0)` 对应设置上面的值。请勿直接设置上面的变量,必须要使用这个函数来设置。 + +如果不手动设置,默认会按照 KP 算法推荐的规则设置一个合适的值:理想宽度设置为空格的像素宽度;可拉伸宽度为理想宽度的1/2;可压缩宽度为理想宽度的1/3。默认设置 `ekp-mws-ideal-pixel = ekp-lws-ideal-pixel - 2`;拉伸和压缩比例与上面一致。中文字符间的理想宽度为0;可拉伸宽度2;无可压缩宽度。 + ### 核心函数 提供了两个函数: @@ -24,4 +42,4 @@ Emacs-kp 实现了 knuth-plass 排版算法,但其功能不局限于英文排 ```(ekp-pixel-range-justify string min-pixel max-pixel)``` -在 MIN-PIXEL 到 MAX-PIXEL 的返回内寻找最优排版,返回一个 cons-cell,car 是排版后的文本,cdr 是最优排版效果的像素值。 \ No newline at end of file +在 MIN-PIXEL 到 MAX-PIXEL 的返回内寻找最优排版,返回一个 cons-cell,car 是排版后的文本,cdr 是最优排版效果的像素值。