我想在我的 pango 软件中使用三种字体:
- 字体 1:拉丁文、Crylic 字符
- Font2:韩文字符
- Font3:日文字符
Pango 正确渲染文本,但我想选择一种字体
有什么方法可以表明这种偏好 pango 字体?
我使用:linux和pango 1.29
最简单的方法是使用 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) 来显示结果。设置仅在内容更改时才需要更改 - 它保持绘制信号中的值。