[cairo] pango+cairo how to get position of each character?

Naveen M K naveen at syrusdark.website
Sat May 8 16:39:08 UTC 2021


> For example, I have a text string "hello" and a truetype font file, and I want to apply different color to different character, currently I cannot find a way to implement it. 

You can simple use `PangoAttribute`[0] for coloring each character 
differently or use you can also use PangoMarkup[1] for achieving that.

For loading a font from truetype font file, I don't know whether Pango 
would be able to do that. I think it usually requires you to install the 
font before hand and reference by the name.

> then if no api to render one by one

There is an API for rendering a Layout character by character, 
`pango_cairo_show_layout_line`[2] where you can iterate a PangoLayout 
using `pango_layout_get_line`[3] to achieve that.

>  I can use freetype library to render each glyph

No idea how it will work.

[0]: https://developer.gnome.org/pango/1.46/pango-Text-Attributes.html
[1]: https://developer.gnome.org/pango/1.46/pango-Markup.html

-- Naveen

More information about the cairo mailing list