Menu

#2080 D2D bug with font family name and font face name

Bug
closed-fixed
5
2025-06-08
2019-02-15
Zufu Liu
No

Test "Source Code Pro Semibold" (font weight: 600, font family: "Source Code Pro").
The result of main text and auto-completion box (Another: rendered with another font, Same: rendered with same font).

SCI_STYLESETFONT GDI Text GDI Box D2D Text D2D Box
Source Code Pro Another Another Same Another
Source Code Pro Semibold Same Same Another Same

CreateTextFormat() (FontCached::FontCached(const FontParameters &fp)) need font family name,
LOGFONT (FormatAndMetrics::HFont()) need font face name but font family name is used (pTextFormat->GetFontFamilyName()).

Related

Bugs: #2262
Bugs: #2356
Scintilla: 633335b1235c5a9f657b8928

Discussion

  • Zufu Liu

    Zufu Liu - 2019-02-15

    maybe HFONT hfont; in FormatAndMetrics can be changed to LOGFONTW *plf, which pointer to the LOGFONTW lf; field (always initialized) in FontCached.

    FormatAndMetrics::HFont() then can be changed to

    return ::CreateFontIndirectW(plf);
    

    The font family name for pTextFormat can be got through
    IDWriteGdiInterop::CreateFontFromLOGFONT().

     

    Last edit: Zufu Liu 2019-02-15
  • Zufu Liu

    Zufu Liu - 2019-02-16

    Correct: adding const LOGFONTW *plf field. hfont is ued by SurfaceGDI.

     

    Last edit: Zufu Liu 2019-02-16
  • Neil Hodgson

    Neil Hodgson - 2019-02-16

    FontCached was developed for Windows 95 which had major resource problems. Windows NT+ isn't as constrained and Scintilla now does a better job of reusing Fonts in ViewStyle so FontCached should go away eventually. Pointing back from FormatAndMetrics gets in the way of this evolution to the extent that I'd feel better adding a std::wstring FormatAndMetrics::fontName.

    IDWriteGdiInterop::CreateFontFromLOGFONT goes the wrong way to retrieve the font family name - the LOGFONTW is a const argument.

    Holding onto the original name doesn't ensure that the list box text looks like the text area since the list box text is always drawn with GDI. Making the text appear the same would require a complete implementation of list box item drawing that uses Direct2D + DirectWrite. This is made more difficult by the possibility of user code calling WM_SETFONT.

     
  • Zufu Liu

    Zufu Liu - 2019-02-16

    The win32 font choosing dialog returns font face name ("Source Code Pro Semibold") in the lfFaceName field, though "Source Code Pro" is displayed in the ComboBox on Vista? and above system (https://docs.microsoft.com/en-us/windows/desktop/dlgbox/font-dialog-box).

    If lfFaceName is directly passed to SCI_STYLESETFONT, it will not works in D2D for font weight other than regular and bold (the second row in above table). using IDWriteGdiInterop to get font family name could fix this.

    I added a temporary fix at https://github.com/zufuliu/notepad2/commit/bca0cdb2160af7f0a5a3d1be39cc8150bf8d198f

     
    • Neil Hodgson

      Neil Hodgson - 2019-02-17

      One half of the patch appears to change the family name given to CreateTextFormat. This could be performed by the application. It is not completely compatible with existing code and encodes a particular policy for font naming which may need to be tweaked further. In particular, special casing some weights appears fragile. It would be safer to document the difference in font naming and leave implementation choice to the application.

       
      • Zufu Liu

        Zufu Liu - 2019-02-18

        I updated the patch to support condensed and narrow font (maybe oblique font too), the font weight restriction at the beginning of the function is removed. It's indeed overhead, unnecessary been called for each font size.
        https://github.com/zufuliu/notepad2/commit/62fe1c0372107d07d9b2a77913aede8591ddada1

        I added a font property table bellow. maybe it's better to add eight APIs:

        SetLocaleName(string name)
        SetFontFamily(string name)
        SetFontStyle(int style)
        SetFontStetch(int stetch)
        

        SetLocaleName has been discussed on https://sourceforge.net/p/scintilla/bugs/2027/

         
        • Neil Hodgson

          Neil Hodgson - 2019-02-22

          The set of font attributes on different platforms is open-ended and most have not solicited any interest from Scintilla users. I'm wary of adding to the set of attributes unless there is a real need.

           
        • Neil Hodgson

          Neil Hodgson - 2019-02-22

          Is there any documentation about what the localeName parameter to CreateTextFormat means?

          From [#2027] it appeared to control the way that the format handles text in particular languages but given all the information about getting localized names in DirectWrite, it may just be used to look up the name in the sets of localized names of fonts.

           

          Related

          Bugs: #2027

          • Zufu Liu

            Zufu Liu - 2019-02-22

            I think it's the locale (or language) of the text / script, has nothing about locale name of font. The locale name of font is only for display (the font itself) purpose, just like application name localization, it's English name and locale name refer the the same font. See "TTF Names" on https://fontforge.github.io/fontinfo.html

            I can't find match articles about the meaning of the localeName,
            https://bell0bytes.eu/text-with-directwrite/
            I think the localeName maybe used in the "Script Processor" on https://docs.microsoft.com/en-us/windows/desktop/DirectWrite/introducing-directwrite

            See example U+66DC from https://source.typekit.com/source-han-serif/, the same character may have different glyph in each locale / language. The locale name (Vista and above, locale name is preferred over old language id) is used to decide pick which glyph (maybe also from which font). Windows system at least has different fallback font list for each language in the registry.

            By set the localeName to different values (zh-TW, zh-Hant, zh-CN, zh-Hans, ja-JP and ko-KR, you may need install additional or supplement fonts for Traditional Chinese, Simplified Chinese, Japanese and Korea) you will see different shapes for the same character without change Windows UI language or system default locale.

            As previous discussed on Bug #2027. The simplest fix is pass empty string, which means current user default locale (which may diff from system default locale).

             
  • Zufu Liu

    Zufu Liu - 2019-02-16

    With CreateFontFromLOGFONT, condensed font could work. GetStretch() returns DWRITE_FONT_STRETCH_SEMI_CONDENSED (for DejaVu Sans Condensed).

     

    Last edit: Zufu Liu 2019-02-16
  • Zufu Liu

    Zufu Liu - 2019-02-18

    Font Property Table

    Platform Win32 GDI Win32 D2D GTK
    FontParameters LOGFONT IDWriteFont/IDWriteTextFormat PangoFontDescription
    *familyName GetFontFamily() set_family()
    faceName lfFaceName
    *localeName GetLocaleName()
    *style lfItalic DWRITE_FONT_STYLE PangoStyle
    *stetch DWRITE_FONT_STRETCH PangoStretch
    weight lfWeight DWRITE_FONT_WEIGHT PangoWeight
    Platform Cocoa Qt wxWidgets
    FontParameters CTFont QFont wxFont
    *familyName font name setFamily()
    faceName FaceName()
    *localeName
    *style CTFontSymbolicTraits QFont::Style wxFontStyle
    *stetch CTFontSymbolicTraits QFont::Stretch
    weight QFont::Weight wxFontWeight

    SetFontFamily(string name) can made an alias to SetFont on GTK, Cocoa and Qt.

    By the way, setWeight() is not called for QFont in Font::Create() (PlatQt.cpp line 138). https://doc.qt.io/qt-5/qfont.html#setWeight

     

    Last edit: Zufu Liu 2019-02-18
  • Neil Hodgson

    Neil Hodgson - 2019-02-24

    As mentioned in my first reply, FontCached isn't needed so was removed with [ad1559].

     

    Related

    Commit: [ad1559]

  • Zufu Liu

    Zufu Liu - 2022-09-23
    • labels: --> font
     
  • Zufu Liu

    Zufu Liu - 2022-09-28
    • labels: font --> font, directwrite
     
  • Zufu Liu

    Zufu Liu - 2025-06-08
    • status: open --> closed-fixed
     
  • Zufu Liu

    Zufu Liu - 2025-06-08

    Close as fixed: font stretch is supported since 5.5.2, auto-completion list box is rendered with same technology as editor window since 5.5.6.

     

Log in to post a comment.

MongoDB Logo MongoDB