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()).
maybe
HFONT hfont;in FormatAndMetrics can be changed toLOGFONTW *plf, which pointer to theLOGFONTW lf;field (always initialized) in FontCached.FormatAndMetrics::HFont() then can be changed to
The font family name for pTextFormat can be got through
IDWriteGdiInterop::CreateFontFromLOGFONT().
Last edit: Zufu Liu 2019-02-15
Correct: adding
const LOGFONTW *plffield. hfont is ued by SurfaceGDI.Last edit: Zufu Liu 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.
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
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.
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 has been discussed on https://sourceforge.net/p/scintilla/bugs/2027/
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.
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:
#2027I 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
localeNamemaybe used in the "Script Processor" on https://docs.microsoft.com/en-us/windows/desktop/DirectWrite/introducing-directwriteSee 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).
With CreateFontFromLOGFONT, condensed font could work. GetStretch() returns DWRITE_FONT_STRETCH_SEMI_CONDENSED (for DejaVu Sans Condensed).
Last edit: Zufu Liu 2019-02-16
Font Property Table
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
As mentioned in my first reply, FontCached isn't needed so was removed with [ad1559].
Related
Commit: [ad1559]
On GTK, the equivalent interface for locale is the Pango language attribute.
On Cocoa, there is a Character Shape Feature Type which may be available through NSFontFeatureSettingsAttribute on an NSFontDescriptor. There's also NSAccessibilityLanguageTextAttribute but that is likely only for accessibility.
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.