Page 1 of 1

fonts

Posted: Wed Oct 12, 2011 7:32 pm
by 15960028
Having a bit of trouble with the textHeight method. I'm creating a blank canvas and writing 1-12 character string on to it using textOut. I then need to draw a rectangle or ellipse around that text.. actually I do it in the reverse order but it works fine. I use the textHeight($text) method to find the height in pixels to use for the rectangle. I notice that it always returns a height of 15 pixels, regardless of what point size i set the canvas pen to.

What font setting does the textHeight method reference ? I can set the canvas font size to default and textheight tells me what ever string I give it is 15 pixels high. I can then set the canvas font size to 20 pt and it tells me the height in pixels is 15. It always produces the same size rectangle regardless of the size of the actual height of the text "measured".

It's like it's referencing one of the other pens, footer, header etc.. ( I know it's not header).

$chart1->getGraphics3D()->textHeight("A");
$chart1->getGraphics3D()->textHeight("-");

I quick example to illustrate the problem:

// prep graph area

$xchartwidth = 800;
$ychartheight = 600;
$chart1 = new TChart($xchartwidth,$ychartheight);
$chart1->getChart()->getHeader()->getFont()->setSize(14);
$chart1->getChart()->getHeader()->setText("SCATTER PLOTTER");
$chart1->getAspect()->setView3D(false);
$chart1->getAxes()->setVisible(true); //false turns off the frame.....

// default font size is 8pt.

$chart1->render("chart1.png");
$g=$chart1->getGraphics3D();
$g->getBrush()->setVisible(true); //this turned on the color in the free canvas forms
$fs= $g->getFont()->getFontSize();
echo "font stuff fs = $fs <br>";
$hA = $g->textHeight("A");
$hu= $g->textHeight("-");
echo " fontsize ($fs) --text height of A = $hA -- height = $hu <br>";

// change font size to 6pt and repeat all measurements.

$chart1->getGraphics3D()->getFont()->setSize(6); // text written to canvas is now 6 point.
$fs= $g->getFont()->getFontSize();
echo "font stuff fs = $fs <br>";
$hA = $g->textHeight("A");
$hU= $g->textHeight("-");
echo " fontsize ($fs) --text height of A = $hA -- height = $hu <br>";

imagepng($chart1->getChart()->getGraphics3d()->img, "chart1.png"); //this seems to draw the image when ready
print '<font face="Verdana" size="2">Annotation Tool<p>';
print '<img src="chart1.png?rand='.$rand.'"><p>';

// end code

The result is textHeight returns the same value for the default font size (8pt) and for 6pt.

What's going on ?

**** New point.. I also use the textWidth method to get the width of the text string and use that to determine the width of the rectangle that is drawn around the text.. that works perfectly. If the font gets bigger the width returned are correct. Only the TextHeight value seems to be broken it's always 15 regardless of the size of the font used.

Re: fonts

Posted: Fri Oct 14, 2011 1:25 pm
by yeray
Hello,

I've reproduce the situation here. We're investigating it and we'll be back here asap.

Re: fonts

Posted: Fri Oct 14, 2011 4:49 pm
by 15960028
Woohoo!!
I'm happy it's not my server this time. I bet this amounts to little more than a typo in the source code.

Re: fonts

Posted: Tue Oct 18, 2011 7:36 am
by yeray
Hello,

We've corrected the textHeight function. Find the affected files attached.
TextHeight_fix.zip
(49.11 KiB) Downloaded 474 times

Re: fonts

Posted: Tue Oct 18, 2011 3:38 pm
by 15960028
Excellent!! That appears to have done the trick.

Re: fonts

Posted: Wed Oct 19, 2011 7:16 am
by yeray
Hi,

I'm glad to hear it! :)