toptensoftware / RichTextKit

Rich text rendering for SkiaSharp
Other
361 stars 74 forks source link

Font Fallback breaks text alignment #2

Open Clancey opened 4 years ago

Clancey commented 4 years ago

Right now the current logic, is spaces uses the last Font found during the fallback. When you take into a string like Ride the Comet! ☄️ with even spaces on each side, the spacing is being used to help with padding. It should still properly center, however Emoji character spaces are a lot larger than say Helvetica.

I propose the line should be changed to RunFace = typeface;

Gillibald commented 4 years ago

The logic should just find a matching typeface for missing character to glyph mappings. Everything else should use the original typeface.

toptensoftware commented 4 years ago

There are a couple of issues here that are affected by this logic.

In general I agree with @Gillibald however this was specifically was trying to prevent breaking a sequence of words that all require font replacement into separate font runs and thereby introducing a (probably redundant) font switch at each word boundary.

I'm not sure about replacing the spaces around emojis - seems their should be some more heuristics here but not sure what they should be.

Also, this may also affect alignment of font replacements in a fixed pitch base font. eg: see this example.