diff --git a/TeXmacs/progs/dynamic/fold-menu.scm b/TeXmacs/progs/dynamic/fold-menu.scm index 3a7a174de0..df0196179d 100644 --- a/TeXmacs/progs/dynamic/fold-menu.scm +++ b/TeXmacs/progs/dynamic/fold-menu.scm @@ -467,7 +467,7 @@ (=> (balloon (eval (upcase-first (short-font-menu-name))) "Main document font") (link document-short-font-menu)) - (=> (balloon (eval (string-append (get-init "font-base-size") "pt")) + (=> (balloon (eval (font-base-size-menu-name)) "Font size") (link document-font-base-size-menu)) (=> (balloon (icon (eval (current-page-icon))) "Page layout") diff --git a/TeXmacs/progs/generic/document-menu.scm b/TeXmacs/progs/generic/document-menu.scm index df261328ac..6562ed92da 100644 --- a/TeXmacs/progs/generic/document-menu.scm +++ b/TeXmacs/progs/generic/document-menu.scm @@ -268,10 +268,26 @@ ("Roman" (init-env "prog-font" "roman")) ("Times" (init-env "prog-font" "times")))) +(tm-define (init-font-base-size-interactive) + (:interactive #t) + (interactive (lambda (s) + (let* ((num (string->number s)) + (normalized (if num (/ (floor (+ (* num 2) 0.5)) 2) 10)) + (val (if (= normalized (floor normalized)) + (number->string (inexact->exact (floor normalized))) + (number->string normalized)))) + (set-init-env "font-base-size" val))) + (list "Font size" "string" (get-init-env "font-base-size")))) + (define (font-base-size-menu-name) - (if (== (get-init "font-base-size") "10") - "Font size" - (string-append (get-init "font-base-size") "pt"))) + (let* ((raw (string->number (get-init "font-base-size"))) + (normalized (if raw (/ (floor (+ (* raw 2) 0.5)) 2) 10)) + (sz-str (if (= normalized (floor normalized)) + (number->string (inexact->exact (floor normalized))) + (number->string normalized)))) + (if (== sz-str "10") + "Font size" + (string-append sz-str "pt")))) (menu-bind document-font-base-size-menu ("Default" (init-default "font-base-size")) @@ -283,7 +299,7 @@ ("12" (init-env "font-base-size" "12")) ("14" (init-env "font-base-size" "14")) --- - ("Other" (init-interactive-env "font-base-size"))) + ("Other" (init-font-base-size-interactive))) (menu-bind document-font-dpi-menu ("Default" (init-default "dpi")) diff --git a/devel/222_46.md b/devel/222_46.md new file mode 100644 index 0000000000..c38d3fe29b --- /dev/null +++ b/devel/222_46.md @@ -0,0 +1,25 @@ +### Fixes + +Issue #2808: Decimal font sizes not displayed correctly in status bar and font size selector + +--- + +### Summary + +Normalize font size display to the nearest 0.5 across the status bar and font size selector, ensuring consistent and accurate representation. + +--- + +### Changes + +- Changed `get_env_int` to `get_env_double` for `FONT_BASE_SIZE` in `edit_footer.cpp` to preserve decimal values. +- Replaced `(int)` cast with `round(x * 2.0) / 2.0` normalization for text, math, and prog modes in the status bar. +- Updated `font-base-size-menu-name` in `document-menu.scm` to display the normalized font size instead of raw user input. +- Added `init-font-base-size-interactive` to sanitize the "Other" input dialog — invalid or non-numeric entries default to 10. +- Reused `font-base-size-menu-name` in `fold-menu.scm` for the beamer toolbar instead of raw string display. + +--- + +### Reason + +The status bar used `get_env_int` which truncated decimal font sizes (e.g., 10.5 displayed as 10). Additionally, `(int)` casts discarded fractional values before display. The font size selector showed raw user input without any validation, leading to inconsistent display between the status bar and selector, and potential errors from non-numeric input. \ No newline at end of file diff --git a/src/Edit/Interface/edit_footer.cpp b/src/Edit/Interface/edit_footer.cpp index 8629d1183a..c94144792b 100644 --- a/src/Edit/Interface/edit_footer.cpp +++ b/src/Edit/Interface/edit_footer.cpp @@ -39,7 +39,7 @@ edit_interface_rep::append_left_footer (tree& l, string env_var) { void edit_interface_rep::set_left_footer () { tree s = concat (); - double base_sz= get_env_int (FONT_BASE_SIZE); + double base_sz= get_env_double (FONT_BASE_SIZE); double sz = get_env_double (FONT_SIZE); /* tree the_style= get_style (); @@ -55,14 +55,20 @@ edit_interface_rep::set_left_footer () { if ((mode == "text") || (mode == "src")) { s << tree (" ") << verbatim (main_family (get_env_string (FONT))); append_left_footer (s, FONT_FAMILY); - s << tree (" ") << as_string ((int) ((base_sz + 0.5) * sz)); + { + double display_sz= round (base_sz * sz * 2.0) / 2.0; + s << tree (" ") << as_string (display_sz); + } append_left_footer (s, FONT_SERIES); append_left_footer (s, FONT_SHAPE); } else if (mode == "math") { s << tree (" ") << verbatim (get_env_string (MATH_FONT)); append_left_footer (s, MATH_FONT_FAMILY); - s << " " << as_string ((int) ((base_sz + 0.5) * sz)); + { + double display_sz= round (base_sz * sz * 2.0) / 2.0; + s << tree (" ") << as_string (display_sz); + } append_left_footer (s, MATH_FONT_SERIES); append_left_footer (s, MATH_FONT_SHAPE); } @@ -71,7 +77,10 @@ edit_interface_rep::set_left_footer () { if (session_name != "default") s << "-" << session_name; s << tree (" ") << verbatim (get_env_string (PROG_FONT)); append_left_footer (s, PROG_FONT_FAMILY); - s << " " << as_string ((int) ((base_sz + 0.5) * sz)); + { + double display_sz= round (base_sz * sz * 2.0) / 2.0; + s << tree (" ") << as_string (display_sz); + } append_left_footer (s, PROG_FONT_SERIES); append_left_footer (s, PROG_FONT_SHAPE); }