Preserve font face and size for bold/italic/underline runs#568
Open
LeonarddeR wants to merge 1 commit into
Open
Preserve font face and size for bold/italic/underline runs#568LeonarddeR wants to merge 1 commit into
LeonarddeR wants to merge 1 commit into
Conversation
wxMSW's wxTextCtrl::SetStyle rewrites the entire font of a range whenever the wxTextAttr carries any font attribute: it masks CFM_FACE | CFM_SIZE | ... unconditionally and fills unset fields from a default font (Arial 10pt). Applying bold/italic/underline markers as single-attribute wxTextAttrs therefore reset the run's face to Arial and size to 10, and overlapping markers clobbered each other's styles. Merge the (possibly overlapping) markers into non-overlapping segments carrying the union of active styles, then apply one full font per segment (current control font + the segment's styles). This preserves face/size and composes overlapping styles correctly on every platform. Add unit tests for the marker-merge logic.
Contributor
Author
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.
Follow-up / fixup for #557.
Problem
On Windows, bold/italic/underline runs rendered in Arial 10pt instead of
the reader's font. wxMSW's
wxTextCtrl::SetStylerewrites the entirefont of a range whenever the
wxTextAttrcarries any font attribute — itmasks
CFM_FACE | CFM_SIZE | ...unconditionally and fills unset fieldsfrom a default font (Arial 10pt). Applying each marker as a
single-attribute
wxTextAttrtherefore reset the run's face/size, andoverlapping markers (e.g. a bold word inside an italic sentence) clobbered
each other's styles.
Fix
Merge the (possibly overlapping) markers into non-overlapping segments
carrying the union of active styles, then apply one full font per
segment (current control font + the segment's styles). Preserves face/size
and composes overlapping styles correctly on every platform.
Added unit tests for the marker-merge logic.
Verification
Built and opened a document with bold/italic/underline and combined
bold+italic runs — all render in the reader font at the correct size, and
the bold+italic run shows both styles.
🤖 Generated with Claude Code