View unanswered posts | View active topics It is currently Thu May 09, 2024 7:06 am



Reply to topic  [ 2 posts ] 
drawText() and getTextBox() question 
Author Message
pChart user
pChart user

Joined: Tue Mar 15, 2011 8:52 am
Posts: 6
Post drawText() and getTextBox() question
Hat's off to an amazing library. I was wondering if anyone knows of a better way to center text than our current method.

We are using pchart to let users dynamically create various types of charts. Therefore, we can't hardcode the x,y coordiantes of the chart title(as one example) because--although we know how wide the image will be, we don't know how long the text title will be (until some user types it in).

Our method to center a text field
-- first draw it off the canvas (at y = -100). The only reason we do this is because we need to examine the array returned by drawText() to discover the text field's rendered width and height (which we can then use later to center the title in the displayed canvas)
-- Once we know this, the width and height and can use that to center the text field in the actual image (as opposed to at y = -100)

This, in effect, means we must draw the text field twice. Once outside the displayed area to get the width and height.

The second time, we center it inside the displayed area ie ($width_of_image/2 - $width_of_rendered_text/2)

I was wondering if anyone knows of a better way?


Tue Mar 15, 2011 9:58 am
Profile WWW
Site Admin
Site Admin
User avatar

Joined: Thu Dec 02, 2010 2:31 pm
Posts: 409
Location: France
Post Re: drawText() and getTextBox() question
Hi,

Can't you use the TEXT_ALIGN_MIDDLEMIDDLE (or TOPMIDDLE / BOTTOMMIDDLE) parameter of the drawText() function? If we assume that your image is size is ($Width,$Height) you can do :

Code:
$myPicture->drawText($Width/2,20,"Your Title",array("Align"=>TEXT_ALIGN_TOPMIDDLE));


Kind regards,
JD.


Wed Mar 23, 2011 11:18 am
Profile WWW
Display posts from previous:  Sort by  
Reply to topic   [ 2 posts ] 

Who is online

Users browsing this forum: No registered users and 16 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron