Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Properly get font family name for UILabels#1243

Merged
aballway merged 5 commits into
microsoft:developfrom
aballway:develop
Oct 27, 2016
Merged

Properly get font family name for UILabels#1243
aballway merged 5 commits into
microsoft:developfrom
aballway:develop

Conversation

@aballway

@aballway aballway commented Oct 27, 2016

Copy link
Copy Markdown
Contributor

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 Reviewable

_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());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not font fontFamilyName? We should be returning the right family name there.

@aballway aballway Oct 27, 2016

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do you mean familyName? That will return an incompatible name

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The question I am really asking is, why aren't we fixing that method?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@jaredhms

Copy link
Copy Markdown
Contributor

class DisplayTextureXamlGlyphs : public DisplayTexture {

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)

@jaredhms

Copy link
Copy Markdown
Contributor

:shipit:

@jaredhms

Copy link
Copy Markdown
Contributor

class DisplayTextureXamlGlyphs : public DisplayTexture {

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)

@msft-Jeyaram

msft-Jeyaram commented Oct 27, 2016

Copy link
Copy Markdown

// Copyright (c) 2016 Microsoft Corporation. All rights reserved.

update #WontFix


Refers to: Frameworks/UIKit/StarboardXaml/CompositorInterface.mm:4 in e193e65. [](commit_id = e193e65, deletion_comment = False)

@aballway

Copy link
Copy Markdown
Contributor Author

// Copyright (c) 2016 Microsoft Corporation. All rights reserved.

this file is going away


In reply to: 256725429 [](ancestors = 256725429)


Refers to: Frameworks/UIKit/StarboardXaml/CompositorInterface.mm:4 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")));

@ms-jihua ms-jihua Oct 27, 2016

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uhhh don't check this in, our lab machines don't have this font (though our build machines do)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I second this.

@rajsesh rajsesh left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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")));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I second this.

@ms-jihua

Copy link
Copy Markdown
Contributor

:shipit:

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);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs to be a const & otherwise it's pass by Val which will copy the inner string

@aballway aballway merged commit c2e9246 into microsoft:develop Oct 27, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Internal graphics test app text layout is not correct

7 participants