Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UIFontWeightTrait not set on iOS #13900

Closed
4 of 7 tasks
hampustagerud opened this issue Sep 6, 2018 · 10 comments
Closed
4 of 7 tasks

UIFontWeightTrait not set on iOS #13900

hampustagerud opened this issue Sep 6, 2018 · 10 comments
Labels
Milestone

Comments

@hampustagerud
Copy link

Describe the problem

I am maintaining the FontAwesome 5 part of oblador/react-native-vector-icons in which we currently use hacks to get the right style to be chosen by React Native.

In the core of React Native it uses the UIFontWeightTrait trait to compare fonts of the same family. However, all Font Awesome 5 fonts are reporting a font weight of 0 which makes it impossible to predict (or choose) which style will be used to render the icon.

We are using the *.ttf files but .otf has the same problem.

What did you expect?

I would like the UIFontWeightTrait to differ between the different styles in order for Xcode and React Native to be able to select the fonts natively.

What version and implementation are you using?

Version: 5.3.1 (Pro and Free)

  • SVG with JS
  • Web Fonts with CSS
  • SVG Sprites
  • On the Desktop

Reproducible test case

I use the following code to check traits:

for (NSString *family in [UIFont familyNames]) {
  if ([family hasPrefix:@"Font Awesome 5"]) {     
    for (NSString *fontName in [UIFont fontNamesForFamilyName:family]) {
      UIFont *font = [UIFont fontWithName:fontName size:12];
        
      NSLog(@"%@", fontName);
      NSDictionary *traits = [font.fontDescriptor objectForKey:UIFontDescriptorTraitsAttribute];
      for (NSString *key in traits.allKeys)
        NSLog(@"\t%@: %@", key, [traits valueForKey:key]);
    } 
  }
}

Which produces:

screenshot

Brands are never an issue since they have a different family name.

Bug report checklist

  • I have filled out as much of the above information as I can
  • I have included a test case because my odds go way up that the team can fix this when I do
  • I have searched for existing issues and to the best of my knowledge this is not a duplicate

Possibly related to: #13557

@tagliala
Copy link
Member

tagliala commented Sep 6, 2018

Hi!

Thanks for being part of the Font Awesome Community.

We are using the *.ttf files but .otf has the same problem.

Please do not use the .ttf files since they are optimized for the web and for ancient browsers

I will leave this open, but I suppose this depends on #13557

@hampustagerud
Copy link
Author

Thank you for a fast reply 🙂

Please do not use the .ttf files since they are optimized for the web and for ancient browsers

There are a couple of reasons why .ttf files are used instead of .otf. The package also targets react-native-web which could mean that the files might end up being used on the web. We are also using a script to auto-update the fonts using your npm packages and since they don't include .otf files it's easier to just use .ttf instead. Smaller filesizes are just a bonus as well 🙂

Now, if the fix would be to use the .otf I wouldn't mind changing the code but for now its not. If this was the case it would be greatly appreciated if there could be a @fortawesome/fontawesome-desktop package (or maybe include the .otf files in the standard packages) so downloads could be easily automated (I have also written a utility to upgrade the fonts to Pro, if the user has a npm-token, which is quite useful when there has been a new release).

I will leave this open, but I suppose this depends on #13557

I suspect this might be resolved by #13557 but not sure since the issue is a little bit different (maybe has the same fix though). I appreciate that this is left open until #13557 is resolved in case it is a different issue.

I will try to look into it more myself but I have very limited experience when dealing with the internals and meta-info of font files which I think is the cause of this issue 🙂

@tagliala
Copy link
Member

tagliala commented Sep 6, 2018

which could mean that the files might end up being used on the web

Can you do the same with .woff2 or .woff?

@hampustagerud
Copy link
Author

hampustagerud commented Sep 26, 2018

This is currently no option and really shouldn't make a difference. Other fonts are working fine using .ttf, .otf could be an option but .ttf would be preferable.

Also, maybe related to #13320 as well.

@robmadole
Copy link
Member

traits

@hampustagerud does this help? These are the numbers from what will be 5.7.0.

@hampustagerud
Copy link
Author

hampustagerud commented Jan 5, 2019

@robmadole Yes, that looks correct 🙌 I think they are the same values that are set after we manually modify the font information before loading the font but this should render most of the hack redundant! Is there an ETA for 5.7.0? 🙂

@robmadole
Copy link
Member

@hampustagerud we will probably be releasing 5.7.0 this week but don't hold my feet to the fire on that one.

@hampustagerud
Copy link
Author

@robmadole That was sooner than I expected anyways, sounds awesome (😬)! Thanks for the reply and hard work put into the font!

@tagliala
Copy link
Member

Font Awesome 5.7.0 has been just released. Could you please test and provide feedback?

@hampustagerud
Copy link
Author

hampustagerud commented Jan 29, 2019

I can confirm that the numbers are now correct on iOS which now seems able to distinguish between the fonts by choosing Thin, Regular or Bold font 🙂

Thank you @tagliala and @robmadole, this issue seems resolved 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants