Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion TeXmacs/progs/dynamic/fold-menu.scm
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
24 changes: 20 additions & 4 deletions TeXmacs/progs/generic/document-menu.scm
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand All @@ -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"))
Expand Down
25 changes: 25 additions & 0 deletions devel/222_46.md
Original file line number Diff line number Diff line change
@@ -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.
17 changes: 13 additions & 4 deletions src/Edit/Interface/edit_footer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
Expand All @@ -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);
}
Expand All @@ -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);
}
Expand Down