update readme

This commit is contained in:
Kinneyzhang 2025-07-27 22:33:28 +08:00
parent 6efd1985d1
commit e9b36312fb
4 changed files with 49 additions and 7 deletions

View File

@ -76,13 +76,11 @@
(if-let ((font-family (ekp-monospace-p string))) (if-let ((font-family (ekp-monospace-p string)))
(string-pixel-width (string-pixel-width
(propertize " " 'face `(:family ,font-family))) (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)) (let* ((letter (ekp-get-latin-letter string))
(font-family (ekp-font-family letter))) (font-family (ekp-font-family letter)))
(string-pixel-width (string-pixel-width
(propertize (propertize
"n" 'face `(:family ,font-family)))))) " " 'face `(:family ,font-family))))))
(defun ekp-latin-font (string) (defun ekp-latin-font (string)
(if-let ((letter (ekp-get-latin-letter string))) (if-let ((letter (ekp-get-latin-letter string)))

4
ekp.el
View File

@ -74,8 +74,8 @@
(let* ((lws-pixel (ekp-word-spacing-pixel string)) (let* ((lws-pixel (ekp-word-spacing-pixel string))
(mws-pixel (- lws-pixel 2))) (mws-pixel (- lws-pixel 2)))
(ekp-param-set (ekp-param-set
lws-pixel (round (* lws-pixel 0.5)) (round (* lws-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.33)) mws-pixel (round (* mws-pixel 0.5)) (round (* mws-pixel 0.333))
0 2 0))) 0 2 0)))
(defun ekp-param-set ( lws-ideal lws-stretch lws-shrink (defun ekp-param-set ( lws-ideal lws-stretch lws-shrink

View File

@ -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-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 ### Core Functions
Two functions are provided: 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)``` ```(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. 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.

View File

@ -14,6 +14,24 @@ Emacs-kp 实现了 knuth-plass 排版算法,但其功能不局限于英文排
### 配置项 ### 配置项
`ekp-latin-lang` 用来设置文本中主要的拉丁系语言,默认设置为 "en_US"dictionaries 下可以看到所有支持的语言,语言的名称也需要按照词典中 hyph_ 后面的名称来设置。测试用例中有德文和法文排版的例子,其他语言没有测试过,理论上应该没有问题,但不排除需要更为细节的调教。 `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)``` ```(ekp-pixel-range-justify string min-pixel max-pixel)```
在 MIN-PIXEL 到 MAX-PIXEL 的返回内寻找最优排版,返回一个 cons-cellcar 是排版后的文本cdr 是最优排版效果的像素值。 在 MIN-PIXEL 到 MAX-PIXEL 的返回内寻找最优排版,返回一个 cons-cellcar 是排版后的文本cdr 是最优排版效果的像素值。