fonts
Posted: Wed Oct 12, 2011 7:32 pm
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.
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.