Drawing glyphs with separate transformations for path construction and stroking

37 views
Skip to first unread message

Edwin Steiner

unread,
Jun 29, 2020, 5:37:57 AM6/29/20
to skia-discuss
Dear Skia community,

I'm using Skia to render PDF content and I ran into the following problem when stroking glyphs:
PDF defines a "text rendering matrix" that can be used to stretch glyphs, for example, independently in the horizontal and vertical directions.
The tricky thing is that this transformation matrix is supposed to be only used for defining the glyph path, not for stroking it, i.e. it should not affect the line width.

When I use Skia's "drawTextBlob" with the text rendering matrix set up and a stroking paint, the transformation also applies to the stroke, which is not desired in this case.

Can you advise me about the best way to use separate transformations for the glyph path construction and the subsequent painting?
(I guess this is also relevant for filling/shading etc. if the fill depends on the coordinate space in any way. I found some special-case handling for shaders in the Skia code with regard to RSX forms for glyph drawing but I don't think it is sufficient for my case.)

I attach a rendering example showing the expected result rendered by Adobe Reader on the left and my current rendering using Skia on the right.

best regards

Edwin

test_text_type1_fill_and_stroke_string_Tz.pdf.side-by-side.png


Ben Wagner

unread,
Jun 29, 2020, 9:19:18 AM6/29/20
to skia-d...@googlegroups.com
So there is SkFont::setScaleX and ::setSkewX which do what you want to the x direction. Internally we actually have a 2x2 matrix for this but we don't seem to allow setting SkewY (ScaleY is essentially the size). One way to do this right now is probably to call SkFont::getPath or ::getPaths to get the paths, transform them (and their positions) using the 'text matrix', then draw them (or their outlines) to the canvas. Note that you'll need to take care of non-path based glyphs by drawing them 'normally' but these are usually color glyphs to which don't use the fill. However, this doesn't use the glyph cache as well and may run into other strange bits.

--
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 view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/e4cfdec4-6b58-492a-8f59-1129a9b0e597o%40googlegroups.com.

Edwin Steiner

unread,
Jun 29, 2020, 6:46:00 PM6/29/20
to skia-discuss
Thank you! setScaleX, etc., sound promising. It would even be an option for me to patch Skia locally to be able to set the full 2x2 matrix, as I build the library form source and link it statically.

The more difficult cases you mentioned will probably mean that I will need to check some conditions in my code and then decide whether to go the fully manual getPaths, ... route or whether to use the text drawing functions.

best regards

Edwin


Am Montag, 29. Juni 2020 15:19:18 UTC+2 schrieb bungeman:
So there is SkFont::setScaleX and ::setSkewX which do what you want to the x direction. Internally we actually have a 2x2 matrix for this but we don't seem to allow setting SkewY (ScaleY is essentially the size). One way to do this right now is probably to call SkFont::getPath or ::getPaths to get the paths, transform them (and their positions) using the 'text matrix', then draw them (or their outlines) to the canvas. Note that you'll need to take care of non-path based glyphs by drawing them 'normally' but these are usually color glyphs to which don't use the fill. However, this doesn't use the glyph cache as well and may run into other strange bits.

On Mon, Jun 29, 2020 at 5:38 AM Edwin Steiner <estei...@gmail.com> wrote:
Dear Skia community,

I'm using Skia to render PDF content and I ran into the following problem when stroking glyphs:
PDF defines a "text rendering matrix" that can be used to stretch glyphs, for example, independently in the horizontal and vertical directions.
The tricky thing is that this transformation matrix is supposed to be only used for defining the glyph path, not for stroking it, i.e. it should not affect the line width.

When I use Skia's "drawTextBlob" with the text rendering matrix set up and a stroking paint, the transformation also applies to the stroke, which is not desired in this case.

Can you advise me about the best way to use separate transformations for the glyph path construction and the subsequent painting?
(I guess this is also relevant for filling/shading etc. if the fill depends on the coordinate space in any way. I found some special-case handling for shaders in the Skia code with regard to RSX forms for glyph drawing but I don't think it is sufficient for my case.)

I attach a rendering example showing the expected result rendered by Adobe Reader on the left and my current rendering using Skia on the right.

best regards

Edwin

test_text_type1_fill_and_stroke_string_Tz.pdf.side-by-side.png


--
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-d...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages