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
TypeMetric
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: TypeMetric
See Determining Font Metricsdeburgess7 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
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/
https://imagemagick.org/Usage/
Re: TypeMetric
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?
.....
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?