Bug 37715 - CTFont.WithSymbolicTraits won't initialize correctly when passed symbolic traits from a font
Summary: CTFont.WithSymbolicTraits won't initialize correctly when passed symbolic tra...
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: XI 9.4 (iOS 9.2)
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: Untriaged
Assignee: Alex Soto [MSFT]
Depends on:
Reported: 2016-01-15 05:33 UTC by bryan costanich
Modified: 2016-03-23 14:31 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

repro solution (176.99 KB, application/zip)
2016-01-15 05:33 UTC, bryan costanich
Xamarin iOS Smaller Test Case (10.80 KB, application/zip)
2016-03-23 14:22 UTC, Alex Soto [MSFT]
Xcode ObjC test case (25.88 KB, application/zip)
2016-03-23 14:24 UTC, Alex Soto [MSFT]

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description bryan costanich 2016-01-15 05:33:53 UTC
Created attachment 14593 [details]
repro solution

Hey folks, I think we an issue with CTFont.WithSymbolicTraits()

Consider the following code:

  var basefont = new CTFont("CourierPrime", 14);
  var boldFont = basefont.WithSymbolicTraits (basefont.Size, CTFontSymbolicTraits.Bold, basefont.SymbolicTraits);
  var italicFont = basefont.WithSymbolicTraits (basefont.Size, CTFontSymbolicTraits.Italic, CTFontSymbolicTraits.Italic);
  var boldItalicFont = basefont.WithSymbolicTraits (basefont.Size, CTFontSymbolicTraits.Bold | CTFontSymbolicTraits.Italic, CTFontSymbolicTraits.Bold | CTFontSymbolicTraits.Italic);

CTFont.WithSymbolicTraits has a couple of interesting arguments:
  Symbolic Trait Value (`symTraitValue`), and Symbolic Trait Mask (`symTraitMask`)

one of them (the value) tells the system what traits you want to add to the new font, and the other (the mask) tells it what traits to copy over to the new font.

if you manually specify which symbolic traits you want to mask (as seen in the italicFont and boldItalicFont ctors above), it works just fine. However, if you pass in the symbolic traits directly from the SymbolicTraits property (as seen in the `boldFont` ctor above), it'll always return null where there should be a CTFont.

to further complicate matters, if i were to do the following:

  var boldFont = basefont.WithSymbolicTraits (basefont.Size, CTFontSymbolicTraits.Bold, CTFontSymbolicTraits.Mask);

  var boldFont = basefont.WithSymbolicTraits (basefont.Size, CTFontSymbolicTraits.Bold, CTFontSymbolicTraits.None);

I would expect to get a bold font, but instead, I get a non-bolded font. 

whereas this, gets me the font i want:

  var boldFont = basefont.WithSymbolicTraits (basefont.Size, CTFontSymbolicTraits.Bold,CTFontSymbolicTraits.Bold);

I've attached a very simple repro with this code. 

Version: (Business Edition)
Hash: 7322991
Branch: master
Build date: 2015-12-08 16:20:29-0500
Comment 1 Sebastien Pouliot 2016-01-15 14:20:11 UTC
The bindings are a very straight, thin layer above the CoreText API `CTFontCreateCopyWithSymbolicTraits`. 

We'll double check this but it's very possible the same behaviour exists on ObjC.
Comment 3 Alex Soto [MSFT] 2016-03-23 14:22:34 UTC
Created attachment 15496 [details]
Xamarin iOS Smaller Test Case

Created a smaller test case so we can have a line by line port to ObjC
Comment 4 Alex Soto [MSFT] 2016-03-23 14:24:46 UTC
Created attachment 15497 [details]
Xcode ObjC test case

Objective C line by line port of Xamarin iOS Smaller test case
Comment 5 Alex Soto [MSFT] 2016-03-23 14:31:41 UTC
As Sebastien mentioned in comment #1 we have a thin layer above the CoreText API, I created a smaller test case for X.I so we could have a line by line port to ObjC. I get the same results in the ObjC app with the code provided in repro solution by Bryan.

So this seems to be the underlying CoreText API not working as we expect :/ (fortunately not a binding issue)