Hello list,

I am working on an application in which a user may insert, resize, and edit 
text boxes in a workspace.  We anticipate that a single user will have many 
(possibly hundreds) of text items in a workspace.  The user is also able to pan 
and zoom in/out of a workspace.  Because of the performance implications of 
such workspace transformations, our application uses image representations of 
the text all the time except when the user is editing the text or resizing the 
text box (in which case, the word wrapping will change).  When a user double 
clicks a text box, the image representation is hidden, and an NSTextView takes 
it's place.  When the user is done editing, the NSTextView instance is hidden 
and the image representation is re-generated and displayed.

Currently, zooming modifies the font sizes in the attributed string.  I.e. if 
the text in a particular text box is 12pt at 100%, then zooming to 200% 
increases the font size to 24pt.  Image representations of text are generated 
by using NSLayoutManager's drawGlyphsForGlyphRange:atPoint: method to draw the 
text to an image.  All text box image representations are rendered as if the 
zoom level is the max zoom level, so that regardless of the zoom level, the 
quality of the text is always high.

Everything works great, except that the text in a text box while it is being 
edited does not always perfectly overlap with the text from the image 
representation. The reason for this seems to be that the glyph metrics 
(particularly glyph advancement, line height, and baseline offset) do not scale 
linearly.

I have tried two approaches to fix this:

- Force linear scaling of text by changing the baseline offset, line height, 
and glyph advancement at any given zoom level.  I've tried using 
NSLayoutManager's defaultLineHeightForFont: and defaultBaselineOffsetForFont: 
methods to determine what these two attributes would be at the max zoom level, 
then interpolate what they should be at the current zoom level.  This hasn't 
really helped, as there is still a small vertical offset between the image 
representation and the text at the current zoom level.  As for setting the 
glyph advance, I'm not entirely sure of where to start with this, though my 
hunch would be to subclass NSTypesetter and override 
setLocation:withAdvancements:forStartOfGlyphRange:

- Instead of trying to scale text linearly, use a transformation to scale the 
NSTextView and image representation appropriately.  While this is easy to do 
with an image, I am having some issues scaling an NSTextView.  I've tried 
subclassing NSTextView, then in the drawRect method, I apply an affine 
transformation, then call the super's drawRect.  This almost works, except the 
caret acts as if no transformation was applied - it's size and position are 
unchanged even though the text is not.  I've also tried using the NSView method 
scaleUnitSquareToSize: - however this produces fuzzy text.

I would like to know if any of these approaches are correct/viable, and if they 
are, how would I go about solving the aforementioned challenges? If these 
approaches are incorrect, what direction should I take?

Thank you in advance.

Ajay
_______________________________________________

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