character-map-uwp / Character-Map-UWP

A modern, native UWP replacement for the Win32 Character Map and Windows Font Viewer with flawless high DPI and touch support.
MIT License
615 stars 52 forks source link

#274 bugfix #273

Closed JohnnyWestlake closed 1 year ago

JohnnyWestlake commented 1 year ago

Problem

The latest build broke the character preview pane for certain fonts that come from Remote Font Providers (probably Office?)

Reason

We switched over to use DirectWrite (via a Win2D canvas control) to render the text to enable both COLRv1 and to make sure glyphs fit inside display area.

Our DirectWrite code used Win2D's CanvasTextFormat to create our IDWriteTextFormat - but this uses a different SystemFontSet from the one we use to show the font list.

Our font loading code creates our own FontSet directly from an IDWriteFactory and includes remote fonts, which Win2D's internal FontSet does not. Due to this, Win2D's IDWriteTextFormat can't actually load remote fonts from our manual FontSet because those fonts are not contained in the FontSet Win2D uses by default.

Solution

We use our own IDWriteFactory to create our own IDWriteTextFormats directly, and assign them our own FontSet that contains remote fonts. We can then convert this to a Win2D CanvasTextFormat where needed, where it will retain our underlying IDWriteTextFormat.