; calc: Correct width of rules composed of Unicode glyphs

With higher values of 'calc-string-maximum-character', rules
made up of glyphs of non-unit width can be the wrong length.
Calculate the number of characters in the rule based on the
display width, rounded up to the nearest integer.  Refines
feature introduced in bug#78528.
* lisp/calc/calccomp.el (math-comp-simplify-term): Calculate
rule width with a ratio of 'string-pixel-width's.
This commit is contained in:
Jacob S. Gordon 2026-01-09 16:22:00 -05:00 committed by Eli Zaretskii
parent b233ca80e9
commit 6e37af1fe8

View file

@ -1558,8 +1558,12 @@ Not all brackets have midpieces.")
(setq c (cdr c)) (setq c (cdr c))
(while (setq c (cdr c)) (while (setq c (cdr c))
(if (eq (car-safe (car c)) 'rule) (if (eq (car-safe (car c)) 'rule)
(math-comp-add-string (make-string maxwid (nth 1 (car c))) (let* ((sep (nth 1 (car c)))
math-comp-hpos math-comp-vpos) (rule-width (ceiling
(* maxwid (string-pixel-width "-"))
(string-pixel-width (char-to-string sep)))))
(math-comp-add-string (make-string rule-width sep)
math-comp-hpos math-comp-vpos))
(let ((math-comp-hpos (+ math-comp-hpos (/ (* bias (- maxwid (let ((math-comp-hpos (+ math-comp-hpos (/ (* bias (- maxwid
(car widths))) (car widths)))
2)))) 2))))