Add optional use-cache parameter to ekp-pixel-justify and ekp-pixel-range-justify
Co-authored-by: Kinneyzhang <38454496+Kinneyzhang@users.noreply.github.com>
This commit is contained in:
parent
c4240fe15c
commit
dab9ca280e
26
ekp.el
26
ekp.el
@ -728,20 +728,32 @@ So the length of line glues is: line-boxes-num + 1"
|
|||||||
(setq start end)))
|
(setq start end)))
|
||||||
(mapconcat 'identity (nreverse strings) "\n")))
|
(mapconcat 'identity (nreverse strings) "\n")))
|
||||||
|
|
||||||
(defun ekp-pixel-justify (string line-pixel)
|
(defun ekp-pixel-justify (string line-pixel &optional use-cache)
|
||||||
"Justify multiline STRING to LINE-PIXEL."
|
"Justify multiline STRING to LINE-PIXEL.
|
||||||
(let ((strs (split-string string "\n")))
|
When USE-CACHE is non-nil, use the cache for performance.
|
||||||
|
Default is nil, meaning cache is not used."
|
||||||
|
(let ((ekp-caches (if use-cache
|
||||||
|
ekp-caches
|
||||||
|
(make-hash-table
|
||||||
|
:test 'equal :size 100 :rehash-size 1.5 :weakness nil)))
|
||||||
|
(strs (split-string string "\n")))
|
||||||
(mapconcat (lambda (str)
|
(mapconcat (lambda (str)
|
||||||
(if (string-blank-p str)
|
(if (string-blank-p str)
|
||||||
""
|
""
|
||||||
(ekp--pixel-justify str line-pixel)))
|
(ekp--pixel-justify str line-pixel)))
|
||||||
strs "\n")))
|
strs "\n")))
|
||||||
|
|
||||||
(defun ekp-pixel-range-justify (string min-pixel max-pixel)
|
(defun ekp-pixel-range-justify (string min-pixel max-pixel &optional use-cache)
|
||||||
"Find the optimal breakpoint for STRING typesetting between
|
"Find the optimal breakpoint for STRING typesetting between
|
||||||
a MIN-PIXEL and MAX-PIXEL width and return a cons-cell. The car
|
a MIN-PIXEL and MAX-PIXEL width and return a cons-cell. The car
|
||||||
of it is the typeset tex and cdr is the best pixel."
|
of it is the typeset tex and cdr is the best pixel.
|
||||||
(let* ((strings (split-string string "\n"))
|
When USE-CACHE is non-nil, use the cache for performance.
|
||||||
|
Default is nil, meaning cache is not used."
|
||||||
|
(let* ((ekp-caches (if use-cache
|
||||||
|
ekp-caches
|
||||||
|
(make-hash-table
|
||||||
|
:test 'equal :size 100 :rehash-size 1.5 :weakness nil)))
|
||||||
|
(strings (split-string string "\n"))
|
||||||
(best-pixel max-pixel)
|
(best-pixel max-pixel)
|
||||||
(best-cost-lst
|
(best-cost-lst
|
||||||
(mapcar (lambda (string)
|
(mapcar (lambda (string)
|
||||||
@ -767,6 +779,6 @@ of it is the typeset tex and cdr is the best pixel."
|
|||||||
(setq best-cost curr-cost)
|
(setq best-cost curr-cost)
|
||||||
(setq best-pixel curr-pixel)))
|
(setq best-pixel curr-pixel)))
|
||||||
(cl-decf curr-pixel 1)))
|
(cl-decf curr-pixel 1)))
|
||||||
(cons (ekp-pixel-justify string best-pixel) best-pixel)))
|
(cons (ekp-pixel-justify string best-pixel use-cache) best-pixel)))
|
||||||
|
|
||||||
(provide 'ekp)
|
(provide 'ekp)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user