Shyam Sundar Kulkarni
Shyam Sundar Kulkarni

Reputation: 321

SKIA :: Get Text height of a text inside a canvas

I am using Skia for one of my sample program. I have a canvas and inside this I am writing text with font_size 30, this is the code snippet.

string  = "Test String";
SkString text(string);
SkPaint paint;
SkScalar textWidth;
paint.setTextSize(SkIntToScalar(font_size));
paint.getFontMetrics(&metrics);
textWidth = paint.measureText(text.c_str(), text.size());

textWidth will give the exact width of the text inside the canvas. My question is how can I get the height of the text ? Please help.

Upvotes: 5

Views: 5418

Answers (2)

duckduckgo
duckduckgo

Reputation: 1295

the font size your have specified as "font_size" is the height of single line text

Upvotes: -1

Sean_A91
Sean_A91

Reputation: 353

I once had to look into this myself in the past, this link here should help you, even though it is java, fonts all work on the same idea as far as I know.

I assume you will want from the ascender to the baseline, Which is just the ascent. Or you may want the whole thing from top to bottom which is the ascent and descent combined,

If you were writing on lined paper, the baseline is the same as the line you write on, anything above that is the ascent, anything below is the descent.

I dont know anything about skia, But A quick look into skia, at this link here, that there is a public member called fAscent in FontMetrics, and fDescent, Maybe you can use those.

Upvotes: 5

Related Questions