Re: Pixel-perfect migration from ATSUI to Core Text
Re: Pixel-perfect migration from ATSUI to Core Text
- Subject: Re: Pixel-perfect migration from ATSUI to Core Text
- From: Ken Thomases <email@hidden>
- Date: Mon, 29 Aug 2016 10:46:29 -0500
On Aug 29, 2016, at 9:55 AM, Andreas Falkenhahn <email@hidden> wrote:
>
> I'm migrating some code from ATSUI to Core Text. It's pretty raw stuff, i.e. it does
> all the layouting itself and only uses ATSUI/Core Text to draw single lines of text to
> raw pixel buffers and obtain measurements.
>
> The raw pixel data emitted by ATSUDrawText() and CTLineDraw() seems to match exactly.
> Also, the measurements returned by ATSUI/Core Text seem to match most of the time. Thus,
> it's usually the case that the pixels in text generated using ATSUI match exactly the
> text pixels generated by Core Text.
>
> That's nice to see and I didn't expect that but it activated a perfectionist tendency
> in me so that I ran some hardcore tests with lots of different texts printed in different
> sizes and layouts to see if I could find a deviation between ATSUI and Core Text. And I
> did ;) It happens only in very rare cases but sometimes the cursor advance returned by
> ATSUI is a pixel off from the cursor advance returned by Core Text. But only very
> seldomly. However, in complex layouts this can then accumulate and lead to an entirely
> different layout if wordwrapping is involved.
First, this has nothing to do with Cocoa and so isn't appropriate for Cocoa-Dev.
That said, when drawing strings, there are the functions CGContextSetShouldSubpixelPositionFonts() and CGContextSetAllowsFontSubpixelPositioning(). Those can be used to turn off sub-pixel positioning of glyphs. It may be that ATSUI wasn't capable of that and so turning it off gets you the same positioning as ATSUI.
There doesn't seem to be a direct way to ask Core Text for the measurements corresponding to that drawing mode. So, you may need to ask your CTLine for its CTRuns and then ask the CTRun for the individual glyph advances. Then, you would apply ceil() or round() to each and add the results together to get a total.
Regards,
Ken
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden