fix: preserve multi-byte UTF-8 in text preprocessing (fixes #1705)#1820
Merged
krystophny merged 1 commit intomainfrom Apr 25, 2026
Merged
fix: preserve multi-byte UTF-8 in text preprocessing (fixes #1705)#1820krystophny merged 1 commit intomainfrom
krystophny merged 1 commit intomainfrom
Conversation
The preprocess_math_text and process_latex_in_text functions processed text byte-by-byte, breaking multi-byte UTF-8 sequences (e.g. superscript ² U+00B2 encoded as bytes C2 B2). Orphaned continuation bytes were misinterpreted as new character starts, producing spurious glyphs in rendered output. Fix makes both functions UTF-8 aware: multi-byte characters are now detected via utf8_char_length and copied as intact sequences rather than processed byte-by-byte. Adds test_utf8_text_preprocessing with coverage for: - preprocess_math_text with superscripts, Greek letters, mixed ASCII/UTF-8 - process_latex_in_text with Unicode pass-through - prepare_text_for_raster full pipeline - 1x3 subplot rendering with Unicode ylabel + ASCII suptitle
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
preprocess_math_textandprocess_latex_in_textUTF-8 aware so multi-byte characters (superscripts, Greek letters, etc.) are copied as intact byte sequences rather than being processed byte-by-byteChanges
src/text/fortplot_text_layout.f90:preprocess_math_textusesutf8_char_lengthto detect and copy multi-byte sequences intactsrc/utilities/text/fortplot_latex_parser.f90:process_latex_in_textusesutf8_char_lengthto detect and copy multi-byte sequences intacttest/test_utf8_text_preprocessing.f90: new test covering UTF-8 preservation through the full preprocessing pipeline plus the exact issue scenarioVerification
Requirement: suptitle renders without spurious glyph
Command:
pdftotext output/example/fortran/subplot_demo/subplot_1x3_demo.pdf -Output excerpt:
Polynomial Growth Comparison— clean text, no extra characters between "Growth" and "Comparison"Requirement: Unicode superscripts in labels preserved
Command:
fpm test --target test_utf8_text_preprocessingOutput:
Requirement: artifact verification passes
Command:
make verify-artifactsOutput:
Artifact verification passed.(all checks green, including unicode_demo α and ω assertions)Artifact paths
output/example/fortran/subplot_demo/subplot_1x3_demo.pdf— suptitle cleanoutput/example/fortran/subplot_demo/subplot_1x3_demo.png— suptitle cleanbuild/test/output/test_utf8_suptitle.png— test-generated artifact with Unicode ylabel + ASCII suptitle