[Drawkit] Problem with creating shape from glyph (was Re: Beta 4 Finally up!)
Graham Cox
graham.cox at bigpond.com
Tue Jul 22 18:33:16 PDT 2008
Hi James,
adoptPath: should still work. Yes it transforms the path you give it
to the unit square, but it can do that whether the original path is
square or not, since it applies independent scale factors in x and y.
You could also simply create the shape in the first place from your
glyph using +drawableShapeWithBezierPath: which does something very
similar to adoptPath: but should be slightly more efficient because
it's not changing a path, but starting with the fresh one you give it.
However, it still ends up calling setPath:
I can't think of a good reason why you should fall foul of the sanity
check unless you call setPath: directly with some random path, because
every other way to set the path applies an appropriate transform that
should allow the path to pass that check! So something's weird, in
other words.
Note, when a DKTextShape is converted to a plain shape, it converts
the text to a path then creates the shape using it in this way, so
there is a built-in test case that's very similar to what you are
trying to do. It currently works fine, so you might want to compare it
to your code and see what is different.
cheers, Graham
On 23 Jul 2008, at 1:57 am, James Maxwell wrote:
> Hey Graham,
>
> The new sanity check for unit size in DKDrawableShape has broken my
> glyph-based shapes.
> I'm using -adoptPath:, but of course, although adoptPath: tries to
> resize the path to unit size, it then calls setPath:, which is where
> glyphs fail. This appears to be due to the fact that -
> appendBezierPathWithGlyph:inFont: returns a path whose bounds are
> generally oddly shaped - i.e., not square - but your sanity check
> wants a square path, so even adoptPath: can't fix paths from glyphs.
> At least that's my best guess. I've hackishly overridden setPath:
> and commented out the sanity check, just to get it working for now,
> but do you have any suggestions as to how I might devise a more
> "sane" method for creating glyph-based drawable shapes? Pretty much
> all of my musical objects - notes, clefs, and so on - will be coming
> from music fonts, and need to be single objects (i.e., I tried using
> text but it was very awkward). You had suggested the idea of
> DKDrawableShape and adoptPath: a few months ago. Any other ideas? Or
> is it possible, and safe, to make the sanity check accept non-square
> paths, as long as they're equal to 1.0 in their longest dimension?
More information about the Drawkit
mailing list