TypeMetric

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
deburgess7

TypeMetric

Post 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
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: TypeMetric

Post 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?
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
deburgess7

Re: TypeMetric

Post 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?
Post Reply