Properly get font family name for UILabels#1243
Conversation
| _isBold = (mask & UIFontDescriptorTraitBold) > 0; | ||
| _isItalic = (mask & UIFontDescriptorTraitItalic) > 0; | ||
| std::wstring wideBuffer = Strings::NarrowToWide<std::wstring>(text); | ||
| ConstructGlyphs([[font fontName] UTF8String], wideBuffer.c_str(), wideBuffer.length()); |
There was a problem hiding this comment.
Why not font fontFamilyName? We should be returning the right family name there.
There was a problem hiding this comment.
do you mean familyName? That will return an incompatible name
There was a problem hiding this comment.
The question I am really asking is, why aren't we fixing that method?
There was a problem hiding this comment.
The method returns the "correct" value, which is taken directly from the font file as I understand it. The issue is Xaml expects the family name to be a different value than the one on the file in some cases. A developer may expect familyName to be the actual value from the file, in which case changing it in the CoreText/UIKit calls would be incorrect.
There was a problem hiding this comment.
I don't know if it is "correct" if it works with one framework and not the other. If you really want to keep this separate go with a UIFont private property that rest of UIKit can use where it integrates with xaml.
The correct fix IMO would be for coretext to also handle font family names like xaml does (xaml is also built on dwrite), but that would likely be bigger change than what we want to do at this point.
There was a problem hiding this comment.
Let me try to clarify on correctness here. [UIFont familyName] for this on the reference platform would return "Franklin Gothic Medium Cond". This is the same with XAML and DWrite, as well as several websites such as http://fontsgeek.com/fonts/Franklin-Gothic-Medium-Cond-Regular which enumerate family names for fonts, suggesting that it's a property of the ttf file itself.
However, XAML/DWrite only accept "Franklin Gothic" as the input family name, even though they give something else as output. This is fundamentally a mismatch on their end, so I don't know that there's anything "more correct" than this UIFont private function right now.
Please don't make any changes to the compositor; this class doesn't even exist anymore in the refactor branch (https://github.com/jaredhms/WinObjC/tree/compositor_latest2). Let's discuss how I can best roll this into my changes; it looks like I should be calling _DWriteGetFamilyNameForFontName when I need to grab the font family name? Refers to: Frameworks/UIKit/StarboardXaml/CompositorInterface.h:150 in e193e65. [](commit_id = e193e65, deletion_comment = False) |
|
|
I talked with Raj offline; we can take this if needed, and I already have a fix for it queued up in my branch. In reply to: 256707554 [](ancestors = 256707554) Refers to: Frameworks/UIKit/StarboardXaml/CompositorInterface.h:150 in e193e65. [](commit_id = e193e65, deletion_comment = False) |
| EXPECT_OBJCEQ(@"Times New Roman", (id)_DWriteGetFamilyNameForFontName(CFSTR("Times New Roman Italic"))); | ||
| EXPECT_OBJCEQ(@"Times New Roman", (id)_DWriteGetFamilyNameForFontName(CFSTR("Times New Roman Bold"))); | ||
| EXPECT_OBJCEQ(@"Times New Roman", (id)_DWriteGetFamilyNameForFontName(CFSTR("Times New Roman Bold Italic"))); | ||
| EXPECT_OBJCEQ(@"Franklin Gothic", (id)_DWriteGetFamilyNameForFontName(CFSTR("Franklin Gothic Medium Cond"))); |
There was a problem hiding this comment.
uhhh don't check this in, our lab machines don't have this font (though our build machines do)
rajsesh
left a comment
There was a problem hiding this comment.
contingent on the unit test being fixed.
| EXPECT_OBJCEQ(@"Times New Roman", (id)_DWriteGetFamilyNameForFontName(CFSTR("Times New Roman Italic"))); | ||
| EXPECT_OBJCEQ(@"Times New Roman", (id)_DWriteGetFamilyNameForFontName(CFSTR("Times New Roman Bold"))); | ||
| EXPECT_OBJCEQ(@"Times New Roman", (id)_DWriteGetFamilyNameForFontName(CFSTR("Times New Roman Bold Italic"))); | ||
| EXPECT_OBJCEQ(@"Franklin Gothic", (id)_DWriteGetFamilyNameForFontName(CFSTR("Franklin Gothic Medium Cond"))); |
|
|
| float _desiredWidth, _desiredHeight; | ||
| void Measure(float width, float height); | ||
| void ConstructGlyphs(const char* fontName, const wchar_t* str, int len); | ||
| void ConstructGlyphs(Microsoft::WRL::Wrappers::HString fontFamilyName, const wchar_t* str, int len); |
There was a problem hiding this comment.
This needs to be a const & otherwise it's pass by Val which will copy the inner string
Getting the Font Family Name from DWrite would for certain fonts return a different value than Xaml expects, causing Segue to be used as a default.
Partially fixes #1217
This change is