我想在我的pango软件中使用三种字体:
Pango正确地呈现文本,但我想选择一个字体
有什么方法来表示这种偏好pango字体吗?
我使用: linux和pango 1.29
发布于 2015-05-27 05:24:11
最简单的方法是使用PangoMarkup设置所需的字体:
// See documentation for Pango markup for details
char *pszMarkup = "<span face=\"{font family name goes here}\">"
"{text requiring font goes here}"
"</span>"; // Split for clarity
char *pszText; // Pointer for text without markup tags
PangoAttrList *pAttr; // Attribute list - will be populated with tag info
pango_parse_markup (pszMarkup, -1, 0, &attr_list, &pszText, NULL, NULL);现在您有了一个常规文本缓冲区和一个属性列表。如果您想手动设置这些字体(而不需要通过解析器),则每个字体实例需要一个PangoAttribute,并手动设置PangoAttribute.start_index和PangoAttribute.end_index。
无论您如何获得它们,现在都将它们交给一个PangoLayout:
// pWidget is the windowed widget in which the text is displayed:
PangoContext *pCtxt = gtk_widget_get_pango_context (pWidget);
PangoLayout *pLayout = pango_layout_new (pCtxt);
pango_layout_set_attributes(pLayout, pAttr);
pango_layout_set_text (pLayout, pszText, -1);就这样。使用pango_cairo_show_layout (cr,pLayout)显示结果。设置只需要在内容更改时更改--它跨绘制信号维护值。
https://stackoverflow.com/questions/30075236
复制相似问题