Page 1 of 1

TypeMetric

Posted: 2010-07-06T19:09:21-07:00
by deburgess7
Would someone provide a simple example of how to use the TypeMetric Class? For example how do I measure the "ascent" of a line of text?

thank you very much,
don burgess

Re: TypeMetric

Posted: 2010-07-06T20:18:15-07:00
by anthony
deburgess7 wrote:Would someone provide a simple example of how to use the TypeMetric Class? For example how do I measure the "ascent" of a line of text?

thank you very much,
don burgess
See Determining Font Metrics
http://www.imagemagick.org/Usage/text/#font_info

For some other API, I suggest you let us know what API you are using?

Re: TypeMetric

Posted: 2010-07-06T20:31:50-07:00
by deburgess7
Here is a simple code I made up:

.....

Image image( "300x300", "white" );

.....
//
// Draw text.
//
drawList.push_back(DrawableFillColor("green"));
drawList.push_back(DrawableStrokeColor(Color())); // unset color
drawList.push_back(DrawablePointSize(24));
drawList.push_back(DrawableTranslation(30,140));

string text = "This is a test!";
drawList.push_back(DrawableText(0,0,text));

..................

image.draw(drawList);

................
Magick::TypeMetric::TypeMetric metric;

image.fontTypeMetrics(text,&metric);

double ascent = metric.ascent();

cout << "ascent: " << ascent << endl;
cout << "descent: " << metric.descent() << endl;
cout << "textHeight: " << metric.textHeight() << endl;
cout << "textWidth: " << metric.textWidth() << endl;

================================================
Running the compiled code produces the output:

ascent: 11
descent: -3
textHeight: 14
textWidth: 76

=================================================

Can someone show me an example of how to use these metrics to layout text?