[Drawkit] DXF reader and DrawKit text objects

Allan allandaly at me.com
Thu Feb 5 21:48:38 PST 2009


Graham,

This is a help. Thanks for your useful comments and advice. I think I  
should be in good shape now. I'll write back if/when I'm stuck again.

The convenience method to create a DKTextShape that is just the right  
size (or a little generous) from a string would be nice.

-Allan

On Feb 5, 2009, at 6:55 AM, Graham Cox wrote:
>
> Everything in DK has a bounding box. I suspect that that's also true  
> in Autocad and other apps too, it's just that the DXF file isn't  
> making that explicit for text.
>
> Basically yes, you'll have to work out the bounds you need given the  
> text itself. In turn that requires that you know how big the text  
> is. I assume that the DXF format has some way to indicate differing  
> text sizes and you can then associate these with particular fonts  
> and point sizes.
>
> For standalone text labels, I'd suggest DKTextShape. This object has  
> gone through some evolution within DK and it hasn't quite stopped  
> yet (I've got some pending changes for the next update) but it  
> should do what you want. If you can end up with an  
> NSAttributedString containing your text in the desired font,  
> figuring out the bounding box you need is as easy as calling its - 
> size method. I have found that [NSAttributedString size] is not  
> always completely accurate, though it depends on the font. Most  
> "workhorse" fonts such as Helvetica are OK, but fancy ones like  
> Zapfino come out fairly inaccurately. To make sure that the text  
> really will fit, I'd be generous with the horizontal size - maybe  
> add an extra 10%. With left alignment the extra won't be seen. You  
> can also set the vertical size to fit automatically using  
> [DKTextShape sizeVerticallyToFitText] once you've set the shape's  
> text. You can pass an attributed string directly to its setText:  
> method.
>
> The text adornment property you mention doesn't really work at the  
> moment - sorry. I was intending to make that do something like what  
> you're doing here, and I should at least make it functional or drop  
> it, but my use for it was a little different, and I ran into other  
> difficulties that I solved in a totally different manner for my app.  
> I need to go back and fix that up, but in this case I'm sure you'll  
> find it easier to use DKTextShape (it uses a DKTextAdornment  
> internally anyway, it just does so independently of the style).
>
> I'll also look into providing a convenience method that makes a text  
> shape of the right size to fit an attributed string on a single line.
>
> I hope that's some help - let me know if you need more.
>
> --Graham
>
>
> _______________________________________________
> Drawkit mailing list
> Drawkit at lists.apptree.net
> http://lists.apptree.net/listinfo.cgi/drawkit-apptree.net



More information about the Drawkit mailing list