PointText.bounds is always {x:0, y:0, height:0, width:0}

432 views
Skip to first unread message

Jing

unread,
Sep 18, 2011, 3:52:56 PM9/18/11
to Paper.js
PointText.bounds is always {x:0, y:0, height:0, width:0}.

I can understand why its height and width are always 0. It is the size
of a Point. That's why it is called PointText.

But I don't understand why bounds.center is always (0, 0). This makes
transformation harder to calculate on groups containing PointText.

zeffii

unread,
Nov 9, 2011, 7:55:59 AM11/9/11
to Paper.js
I too would like to know more about the plans for this feature and
areaText.

Xin Wang

unread,
Nov 9, 2011, 10:06:33 PM11/9/11
to pap...@googlegroups.com

I use a hidden span to calculate text width to temporarily avoid the
problem. Some sample code: http://pastebin.com/3DiYJANZ

--
王欣 (Xin Wang)
blog: http://dram.me/

Oliver Beattie

unread,
Nov 16, 2011, 11:14:14 AM11/16/11
to pap...@googlegroups.com
I've implemented this so you can measure height and width of the text accurately. It's not something I'd consider opening a pull request for at the moment (the implementation depends on you specifying a line-height in pixels which it uses as the height, but you can see what I've done here:


Note that this is mixed-in with some other enhancements I've made, but I'm sure you can pick out the relevant parts.

Dave

unread,
Nov 16, 2011, 2:45:35 PM11/16/11
to pap...@googlegroups.com
Nice stuff, been meaning to tackle this myself.

Can probably remove the 'getPosition' override function in pointtext now that you've supported get bounds.

Do you have plans to work on this more? I'd like to help get this to pull-request ready and since I'm interested in the text functionality might make sense for me to fork off or your fork instead of the master. Want to talk about what your plans are for further work on this if you're interested.

Oliver Beattie

unread,
Nov 16, 2011, 3:52:46 PM11/16/11
to pap...@googlegroups.com
I'm certainly interested in prettying this up and making it into a pull request as time permits (hopefully soon!)

One thing that I would like clarified is that I don't really know how "Scriptographer-esque" paper.js is trying to be. I haven't looked at the documentation for PointText in Scriptographer, and it may well have the exact API that I need to implement this; but if it doesn't, I'd like to know what the "policy" is on deviating away from that API. If a core developer (which you may very well be, I'm not sure :) could weigh in, that would be great.

As far as my plans for developing this further go, it would be really nice if we could get this to the stage where you can do more or less anything you'd like with it, within the (limited) confines of the Canvas text APIs. From my limited exploration into the functionality provided by other Canvas scene libraries my conclusion was, well, that they don't support a lot. It'd certainly be very nice if paper.js could deliver more in this area.

In any case, as I say, I'd love to put more time into this when I have it, but feel free to fork off mine. I'm probably going to try and clean up the caching stuff, since I now realize there's a rasterize method I wasn't aware of before (I'm unsure, however, whether it works for PointText).

Jürg Lehni

unread,
Nov 20, 2011, 5:58:44 AM11/20/11
to pap...@googlegroups.com
Hi Oliver,

Thanks for your work on this.

I am now in the process of solving the bounding box problem for PointText, while also adding support for multi-line text.

Expect a commit for this soon!

Best,

Jürg

Jürg Lehni

unread,
Nov 27, 2011, 8:53:07 AM11/27/11
to pap...@googlegroups.com
This is all there now:

https://github.com/paperjs/paper.js/commit/b114f71dda13a5c8d2dea7ea21f9f4d600f9df7b

The way the internal _getBounds works was changed and simplified a lot, as part of the process of adding matrix support to all items and allow nested matrices (discussed earlier on this list).

lineHeight is affected by ParagraphStyle#leading, to use the same wording as in Scriptographer.

J

Reply all
Reply to author
Forward
0 new messages