-
Notifications
You must be signed in to change notification settings - Fork 53
[206_18] 字体大小支持0.5的倍数 #2702
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
[206_18] 字体大小支持0.5的倍数 #2702
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Adds 0.5‑step font size support end‑to‑end through the font stack (core font_rep, TeX/Qt/Freetype/virtual/smart fonts, typesetting environment and UI), with extensive automated and manual test coverage plus some performance/caching tweaks.
Changes:
- Refactor font sizing from
inttodoubleacross core font types and backends, introducing helper utilities (is_half_multiple,normalize_half_multiple_size,effective_size,set_font_size,to_tex_font_size) to support only 0.5‑step sizes while keeping integer behavior backward compatible. - Update environment, math script size computation, box layout logic, and virtual/rubber fonts to use floating font sizes and to cache script sizes at half‑step granularity, including TeX font loading and Freetype/TrueType integration.
- Add a new C++ test suite (
font_size_test.cpp), a TeXmacs visual test document (206_18.tmu), updated font size presets in the UI, and detailed developer documentation (devel/206_18.md) describing the design and validation.
Reviewed changes
Copilot reviewed 38 out of 38 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/Graphics/Fonts/smart_font_test.cpp | Fixes Chinese punctuation resolution test to iterate correctly over punctuations and uses a platform‑specific CJK font name instead of hard‑coding Noto. |
| tests/Graphics/Fonts/font_size_test.cpp | New comprehensive unit tests for half‑step sizing helpers, script, TeX size conversion, smart/virtual fonts, cache keys, and performance micro‑benchmarks. |
| src/Typeset/env.hpp | Changes math size_cache to array<array<double>>, promotes fn_size from int to double, and updates get_script_size’s signature to return double. |
| src/Typeset/Env/env_semantics.cpp | Reimplements determine_sizes and edit_env_rep::get_script_size to work in double precision with half‑step caching, adds benchmarking hooks, and adjusts update_font to use floating fn_size. |
| src/Typeset/Env/env_length.cpp | Updates font length computations (exec_fs_length, exec_fbs_length, exec_fn_length, exec_fns_length, exec_bls_length) to use get_double (FONT_BASE_SIZE) consistently with the new floating font size model. |
| src/Typeset/Concat/concater.cpp | Uses double script sizes from the updated get_script_size when constructing marker/ghost/flag fonts so that math and diagnostic glyphs respect half‑step sizes. |
| src/Typeset/Concat/concat_animate.cpp | Switches the sound icon font size to use the new script (double, int) function, enabling fractional script sizes. |
| src/Typeset/Boxes/Modifier/modifier_boxes.cpp | Adjusts superscript baseline computation in macro_box_rep::sup_lo_base to use effective_size() and rounds back to SI, preserving layout while using floating font sizes. |
| src/Typeset/Boxes/Composite/script_boxes.cpp | Updates several script/limit positioning computations to use fn->effective_size() with explicit rounding back to SI, ensuring math layouts behave correctly under half‑step sizing. |
| src/Plugins/Qt/qt_gui.cpp | Changes load_system_font to accept a double size, aligning the Qt font loading interface with the new floating font API. |
| src/Plugins/Qt/qt_font.hpp | Makes qt_font_rep::size a double and updates the constructor signature accordingly. |
| src/Plugins/Qt/qt_font.cpp | Normalizes Qt font sizes to half‑steps, recomputes QFont/QFontMetricsF when adjusted, and changes design_size to a float‑aware calculation; note: currently does not call set_font_size (this, size), so font_rep::effective_size() remains unset for Qt fonts. |
| src/Plugins/Metafont/tex_rubber_font.cpp | Converts rubber TeX font size parameters to double, validates/rounds to half‑steps, delegates size setting via set_font_size, and ensures magnification uses effective_size(). |
| src/Plugins/Metafont/tex_font.cpp | Generalizes tex_font_rep and its factory functions to double sizes, normalizes to half‑steps, uses effective_size() in line‑width heuristics, and passes double sizes through magnification and TeX font families. |
| src/Plugins/Metafont/load_tex.hpp | Changes load_tex’s size parameter to double and exposes the new to_tex_font_size (double) utility. |
| src/Plugins/Metafont/load_tex.cpp | Introduces to_tex_font_size for mapping point sizes/half‑steps to TeX metric sizes, switches TFM/PK loading and fallback logic to doubles, and adds in‑memory caches (tfm_cache, pk_cache) plus benchmarking for font loading. |
| src/Plugins/Freetype/unicode_font.hpp | Updates unicode_font_rep and the unicode_font factory declarations to use double sizes. |
| src/Plugins/Freetype/unicode_font.cpp | Normalizes unicode font sizes to half‑steps, uses set_font_size in the constructor, recalculates design_size as a float, and ensures magnification passes effective_size(); factory functions now emit float‑aware resource names. |
| src/Plugins/Freetype/tt_font.cpp | Migrates TrueType font sizes to double, sets type = FONT_TYPE_TT, normalizes to half‑steps in both metrics and glyphs, uses effective_size() for magnification, and generates float‑aware font keys. |
| src/Plugins/Freetype/tt_file.hpp | Changes tt_font_glyphs’s size parameter from int to double to align with the rest of the Freetype layer. |
| src/Plugins/Freetype/tt_file.cpp | Replaces the tt_fonts hashset with a hashmap<string,bool> to cache both existing and non‑existing TT fonts, improving tt_font_exists performance. |
| src/Plugins/Freetype/tt_face.hpp | Converts tt_font_metric_rep and tt_font_glyphs_rep to store double size and updates their constructors and tt_font_metric declaration accordingly. |
| src/Plugins/Freetype/tt_face.cpp | Adapts TT metric/glyph loading to double‑precision sizes, fixes FreeType FT_F26Dot6 conversions, and scales bitmap fonts based on computed target pixel sizes. |
| src/Plugins/Freetype/rubber_unicode_font.cpp | Uses base->effective_size() instead of the old integer field when creating virtual fonts inside rubber unicode fonts. |
| src/Plugins/Freetype/rubber_stix_font.cpp | Propagates base->effective_size() into various derived STIX unicode fonts to respect half‑step sizing. |
| src/Plugins/Freetype/rubber_assemble_font.cpp | Uses base->effective_size() when building emu-alt-large virtual fonts for rubber assembly. |
| src/Graphics/Fonts/virtual_font.cpp | Updates virtual_font_rep and virtual_font to double sizes, enforces half‑step normalization, and encodes sizes as integers or single‑decimal strings in the virtual font cache key. |
| src/Graphics/Fonts/virtual_enhance.cpp | Uses base->effective_size() when constructing enhancement virtual fonts, ensuring enhanced glyphs match the actual font size. |
| src/Graphics/Fonts/smart_font.hpp | Changes smart_font_rep::sz to double and updates smart_font_bis’s signature to take a floating size. |
| src/Graphics/Fonts/smart_font.cpp | Normalizes smart font sizes to half‑steps, generates float‑aware res_name/cache keys, and updates smart_font, math_smart_font, prog_smart_font, and effect calculations to work with effective_size(). |
| src/Graphics/Fonts/poor_rubber.cpp | Switches virtual font construction for poor rubber fonts to use effective_size() rather than the old integer size field. |
| src/Graphics/Fonts/font_translate.cpp | Changes closest_font’s size parameter to double and formats size components consistently (integer or single decimal) in cache keys. |
| src/Graphics/Fonts/font.hpp | Introduces half‑step helpers, reworks font_rep to use size_int/size_float with effective_size(), adds set_font_size/get_font_size/font_size_as_int, and migrates all font factory APIs and script to double. |
| src/Graphics/Fonts/font.cpp | Updates font_rep constructors for the new fields and reimplements script as a double‑precision function with benchmarking and half‑step normalization. |
| src/Graphics/Fonts/find_font.cpp | Propagates double font sizes through font discovery, adjusts TeX family helpers to work with scaled numeric sizes, and ensures resource names encode float sizes consistently. |
| devel/206_18.md | Detailed developer note (in Chinese) documenting the motivation, architecture, staged implementation, testing strategy, and performance analysis for half‑step font size support. |
| TeXmacs/tests/tmu/206_18.tmu | Visual regression document exercising integer, half‑step, and non‑half‑step sizes in text and math to manually verify rendering behavior. |
| TeXmacs/progs/fonts/font-new-widgets.scm | Updates the default font size presets exposed in the UI to include a curated set of half‑step sizes (e.g., 5.5, 6.5, 7.5, 10.5, 11.5, 12.5). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| // 重新初始化 QFont 和 QFontMetricsF 使用修正后的尺寸 | ||
| qfn= QFont (to_qstring (family), size); | ||
| qfm= QFontMetricsF (qfn); | ||
| } |
Copilot
AI
Jan 29, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The qt_font_rep constructor normalizes the local size variable but never updates the base font_rep size fields, so font_rep::effective_size() will remain 0.0 for Qt-backed fonts. To keep the new size_float/size_int fields in sync and ensure generic code that relies on effective_size() (e.g., effects or rubber/virtual fonts) sees the correct size, consider calling set_font_size (this, size) after normalizing size and before computing design_size and other metrics.
| } | |
| } | |
| set_font_size (this, size); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added
No description provided.