Rimas,

Typically the text layout system including the Cocoa Text System works in the 
typographic metrics that's based on the information embedded in the font.  So, 
most layout information returned by NSLayoutManager is in the typographic 
metrics if not documented otherwise.

The information you're seeking here is usually called the rendering or image 
metrics.  They are based on the actual rendering results in the graphics system.

The typographic metrics and image metrics are usually not compatible.  Also, 
the image metrics usually requires the rendering result (various graphical 
settings could change the pixels touched).


> 2. With some fonts (for example Eccentric Std, Palemonas, some others
> which i can't remember right now) the [myLayoutManager
> usedRectForTextContainer:myTextContainer] returns rect which does not
> covers WHOLE text. 

You can calculate the image bounds by union'ing the bounds of each glyph in the 
layout manager.  See -[NSFont getBoundingRects:forGlyphs:count:].

> To draw it correctly, I need a bounding (used) rect,
> which counts in a shadow attribute. Is it possible at all using cocoa
> text system?
This really requires the rendering result.  You can "estimate" the bounds by 
applying the shadow params to the bounding rect from above.

Aki

On 2011/04/27, at 8:34, Rimas M. wrote:

> Hi folks,
> 
> Last few days I am trying to solve very strange puzzle - how to draw
> FULL attributed string.
> 
> Short story:
> 
> I have a NSTextStorage object, which holds my formatted string
> information. I am editing it via NSTextView (NSLayoutManager +
> NSTextContainer + my NSTextStorage) mechanism. That works great until
> I am dealing with drawing. To find out rect, which will be required to
> fit my text, I am using -
> (NSRect)usedRectForTextContainer:(NSTextContainer *)aTextContainer of
> NSLayoutManager. To draw actual content I am using
> drawBackgroundForGlyphRange:(NSRange)glyphsToShow
> atPoint:(NSPoint)origin and
> drawGlyphsForGlyphRange:(NSRange)glyphsToShow atPoint:(NSPoint)origin
> from the same NSLayoutManager. And that works great for 90% of time.
> But I need 100%.
> 
> Problem:
> 
> Actually I am dealing with two drawing problems:
> 
> 1. When my attributed string (NSTextStorage) has a shadow, made by
> using Fonts panel, it is NOT INCLUDED when trying to find out used
> rect by calling [myLayoutManager
> usedRectForTextContainer:myTextContainer]. Never. The situation can be
> easily demonstrated with TextEdit:
> https://www.dropbox.com/s/vt21zpq46xl0gb5/Text-with-cropped-shadow.png
> . The same I am getting in my app. But I need a shadow, therefor I
> have set it. To draw it correctly, I need a bounding (used) rect,
> which counts in a shadow attribute. Is it possible at all using cocoa
> text system?
> 
> 2. With some fonts (for example Eccentric Std, Palemonas, some others
> which i can't remember right now) the [myLayoutManager
> usedRectForTextContainer:myTextContainer] returns rect which does not
> covers WHOLE text. Sometimes diacritic symbols of the very top line
> are missing 
> (https://www.dropbox.com/s/dpjjugzxcnp771r/Missing-diacrytic-symbol.png
> <- both letters are the same "Alt + e + e = é" combination), sometimes
> the first left symbol is cropped
> (https://www.dropbox.com/s/33mfgoqwbgwcvg1/Cropped-left-side-1.png,
> https://www.dropbox.com/s/kbgfdzuhcr1svht/Cropped-left-side-2.png,
> https://www.dropbox.com/s/ntxgufl8e562uep/Cropped-left-side-3.png).
> Question is the same - how to get rect, which would fit my whole text.
> 
> Any help is very appreciate.
> 
> p.s. don't hesitate to ask for an additional information. I could even
> make a small sample app if required.
> 
> Regards,
> 
> Rimas M.
> _______________________________________________
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> 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:
> http://lists.apple.com/mailman/options/cocoa-dev/aki%40apple.com
> 
> This email sent to a...@apple.com

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to