calculate result text size before canvas.drawText()

450 views
Skip to first unread message

Igor Khromov

unread,
Sep 8, 2016, 8:30:06 AM9/8/16
to skia-discuss
Hi guys!

I want to create custom textField and I need to draw separate char or text on canvas. How to define canvas size before it's creation? For example I need to draw symbol "X" with some typeFace created from .ttf file, how I can calculate bitmap size before create canvas?

And do you know any textField implementations based on Skia? And if (know==YES), where I can find them)?

Thanks a lot in advance :-) !!!

Brian Salomon

unread,
Sep 8, 2016, 8:58:38 AM9/8/16
to skia-discuss
SkPaint has a measureText() method which returns the width of a text run.

Brian

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To post to this group, send email to skia-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/skia-discuss.
For more options, visit https://groups.google.com/d/optout.

Cary Clark

unread,
Sep 8, 2016, 9:22:09 AM9/8/16
to skia-d...@googlegroups.com
measureText() also takes an optional parameter that returns the bounds. And, for completeness, if you set the verticalText flag, it returns the height :)

Cary


On Thu, Sep 8, 2016 at 8:58 AM, 'Brian Salomon' via skia-discuss <skia-d...@googlegroups.com> wrote:
SkPaint has a measureText() method which returns the width of a text run.

Brian
On Thu, Sep 8, 2016 at 8:30 AM Igor Khromov <khromo...@gmail.com> wrote:
Hi guys!

I want to create custom textField and I need to draw separate char or text on canvas. How to define canvas size before it's creation? For example I need to draw symbol "X" with some typeFace created from .ttf file, how I can calculate bitmap size before create canvas?

And do you know any textField implementations based on Skia? And if (know==YES), where I can find them)?

Thanks a lot in advance :-) !!!

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss+unsubscribe@googlegroups.com.

To post to this group, send email to skia-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/skia-discuss.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss+unsubscribe@googlegroups.com.

Hal Canary

unread,
Sep 8, 2016, 11:10:18 AM9/8/16
to skia-d...@googlegroups.com

On Thu, Sep 8, 2016 at 8:58 AM, 'Brian Salomon' via skia-discuss <skia-d...@googlegroups.com> wrote:
SkPaint has a measureText() method which returns the width of a text run.

Brian
On Thu, Sep 8, 2016 at 8:30 AM Igor Khromov <khromo...@gmail.com> wrote:
Hi guys!

I want to create custom textField and I need to draw separate char or text on canvas. How to define canvas size before it's creation? For example I need to draw symbol "X" with some typeFace created from .ttf file, how I can calculate bitmap size before create canvas?

And do you know any textField implementations based on Skia? And if (know==YES), where I can find them)?

Thanks a lot in advance :-) !!!

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss+unsubscribe@googlegroups.com.

To post to this group, send email to skia-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/skia-discuss.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss+unsubscribe@googlegroups.com.

Igor Khromov

unread,
Sep 8, 2016, 11:52:01 AM9/8/16
to skia-discuss
Thanks!

One more question: how can I draw symbols separately, but aligned vertically like they all in one row?

sample image attached.

In the end I need to draw symbols in one row, so they show be aligned correctly. Do I need to create canvas with height font size? And how to align symbol on canvas than?

Thanks!


четверг, 8 сентября 2016 г., 18:10:18 UTC+3 пользователь Hal Canary написал:

On Thu, Sep 8, 2016 at 8:58 AM, 'Brian Salomon' via skia-discuss <skia-d...@googlegroups.com> wrote:
SkPaint has a measureText() method which returns the width of a text run.

Brian
On Thu, Sep 8, 2016 at 8:30 AM Igor Khromov <khromo...@gmail.com> wrote:
Hi guys!

I want to create custom textField and I need to draw separate char or text on canvas. How to define canvas size before it's creation? For example I need to draw symbol "X" with some typeFace created from .ttf file, how I can calculate bitmap size before create canvas?

And do you know any textField implementations based on Skia? And if (know==YES), where I can find them)?

Thanks a lot in advance :-) !!!

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.

To post to this group, send email to skia-d...@googlegroups.com.
Visit this group at https://groups.google.com/group/skia-discuss.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
glyph_sample.png

Igor Khromov

unread,
Sep 10, 2016, 8:38:07 AM9/10/16
to skia-discuss
Thanks, I think I got it.

All the bounds connected to baseline, so to get symbol drawn without clipping, I should create canvas with size: height = (fAscent + fDescent ), width = textBounds.width().

четверг, 8 сентября 2016 г., 18:52:01 UTC+3 пользователь Igor Khromov написал:

bungeman

unread,
Sep 13, 2016, 10:59:20 AM9/13/16
to skia-discuss


On Saturday, September 10, 2016 at 8:38:07 AM UTC-4, Igor Khromov wrote:
Thanks, I think I got it.

All the bounds connected to baseline, so to get symbol drawn without clipping, I should create canvas with size: height = (fAscent + fDescent ), width = textBounds.width().

Any reason not to just use height = textBounds.height() and draw the text at offset textBounds.y() ? Note that the ascent and descent are typographic measures having to do with layout; the glyphs are not required to fit within the typographic ascent to descent.
Reply all
Reply to author
Forward
0 new messages