Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This answer will be similar to my initial one, but updated for what, after more testing, works.</p> <p>So, first, my method of creating the italic font was deeply flawed. Instead of simply applying a rotation to the text, I needed to apply a skew transform. I ended up finding a good skew transform to apply at <a href="http://trac.webkit.org/browser/trunk/WebCore/platform/graphics/mac/FontMac.mm" rel="nofollow noreferrer">WebKit's Font code</a>. It contained the skew transform:</p> <pre><code>CGAffineTransformMake(1, 0, -tanf(SYNTHETIC_OBLIQUE_ANGLE * acosf(0) / 90), 1, 0, 0) </code></pre> <p>It does look good. </p> <p>Simply using a different font is not the correct answer. While the Lucida Sans font is virtually identical to Lucida Grande (which is returned by systemFontOfSize) and has a real italic variant, the italic variant will not draw Japanese Characters in italic. </p> <p>So, what appears to be the only answer is to obtain the systemFontOfSize, check to see if it has an italic variant, and, if not, add a skew transform.</p> <p>Here is my final solution:</p> <pre><code>NSFont *theFont = [NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSMiniControlSize]]; NSFontManager *sharedFontManager = [NSFontManager sharedFontManager]; if ( wantItalic ) { theFont = [sharedFontManager convertFont:theFont toHaveTrait:NSItalicFontMask]; NSFontTraitMask fontTraits = [sharedFontManager traitsOfFont:theFont]; if ( !( (fontTraits &amp; NSItalicFontMask) == NSItalicFontMask ) ) { const CGFloat kRotationForItalicText = -14.0; NSAffineTransform *fontTransform = [NSAffineTransform transform]; [fontTransform scaleBy:[NSFont systemFontSizeForControlSize:NSMiniControlSize]]; NSAffineTransformStruct italicTransformData; italicTransformData.m11 = 1; italicTransformData.m12 = 0; italicTransformData.m21 = -tanf( kRotationForItalicText * acosf(0) / 90 ); italicTransformData.m22 = 1; italicTransformData.tX = 0; italicTransformData.tY = 0; NSAffineTransform *italicTransform = [NSAffineTransform transform]; [italicTransform setTransformStruct:italicTransformData]; [fontTransform appendTransform:italicTransform]; theFont = [NSFont fontWithDescriptor:[theFont fontDescriptor] textTransform:fontTransform]; } } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload