Implemented uiDrawTextLayoutParams and alignment on GTK+.
This commit is contained in:
parent
44f8409b8c
commit
210c4507ca
|
@ -90,7 +90,13 @@ static void computeLineMetrics(uiDrawTextLayout *tl)
|
||||||
pango_layout_iter_free(iter);
|
pango_layout_iter_free(iter);
|
||||||
}
|
}
|
||||||
|
|
||||||
uiDrawTextLayout *uiDrawNewTextLayout(uiAttributedString *s, uiDrawFontDescriptor *defaultFont, double width)
|
static const PangoAlignment pangoAligns[] = {
|
||||||
|
[uiDrawTextLayoutAlignLeft] = PANGO_ALIGN_LEFT,
|
||||||
|
[uiDrawTextLayoutAlignCenter] = PANGO_ALIGN_CENTER,
|
||||||
|
[uiDrawTextLayoutAlignRight] = PANGO_ALIGN_RIGHT,
|
||||||
|
};
|
||||||
|
|
||||||
|
uiDrawTextLayout *uiDrawNewTextLayout(uiDrawTextLayoutParams *p)
|
||||||
{
|
{
|
||||||
uiDrawTextLayout *tl;
|
uiDrawTextLayout *tl;
|
||||||
PangoContext *context;
|
PangoContext *context;
|
||||||
|
@ -106,29 +112,31 @@ uiDrawTextLayout *uiDrawNewTextLayout(uiAttributedString *s, uiDrawFontDescripto
|
||||||
g_object_unref(context);
|
g_object_unref(context);
|
||||||
|
|
||||||
// this is safe; pango_layout_set_text() copies the string
|
// this is safe; pango_layout_set_text() copies the string
|
||||||
pango_layout_set_text(tl->layout, uiAttributedStringString(s), -1);
|
pango_layout_set_text(tl->layout, uiAttributedStringString(p->String), -1);
|
||||||
|
|
||||||
desc = pango_font_description_new();
|
desc = pango_font_description_new();
|
||||||
pango_font_description_set_family(desc, defaultFont->Family);
|
pango_font_description_set_family(desc, p->DefaultFont->Family);
|
||||||
pango_font_description_set_style(desc, pangoItalics[defaultFont->Italic]);
|
pango_font_description_set_style(desc, pangoItalics[p->DefaultFont->Italic]);
|
||||||
// for the most part, pango weights correlate to ours
|
// for the most part, pango weights correlate to ours
|
||||||
// the differences:
|
// the differences:
|
||||||
// - Book — libui: 350, Pango: 380
|
// - Book — libui: 350, Pango: 380
|
||||||
// - Ultra Heavy — libui: 950, Pango: 1000
|
// - Ultra Heavy — libui: 950, Pango: 1000
|
||||||
// TODO figure out what to do about this misalignment
|
// TODO figure out what to do about this misalignment
|
||||||
pango_font_description_set_weight(desc, defaultFont->Weight);
|
pango_font_description_set_weight(desc, p->DefaultFont->Weight);
|
||||||
pango_font_description_set_stretch(desc, pangoStretches[defaultFont->Stretch]);
|
pango_font_description_set_stretch(desc, pangoStretches[p->DefaultFont->Stretch]);
|
||||||
// see https://developer.gnome.org/pango/1.30/pango-Fonts.html#pango-font-description-set-size and https://developer.gnome.org/pango/1.30/pango-Glyph-Storage.html#pango-units-from-double
|
// see https://developer.gnome.org/pango/1.30/pango-Fonts.html#pango-font-description-set-size and https://developer.gnome.org/pango/1.30/pango-Glyph-Storage.html#pango-units-from-double
|
||||||
pango_font_description_set_size(desc, pango_units_from_double(defaultFont->Size));
|
pango_font_description_set_size(desc, pango_units_from_double(p->DefaultFont->Size));
|
||||||
pango_layout_set_font_description(tl->layout, desc);
|
pango_layout_set_font_description(tl->layout, desc);
|
||||||
// this is safe; the description is copied
|
// this is safe; the description is copied
|
||||||
pango_font_description_free(desc);
|
pango_font_description_free(desc);
|
||||||
|
|
||||||
pangoWidth = cairoToPango(width);
|
pangoWidth = cairoToPango(p->Width);
|
||||||
if (width < 0)
|
if (p->Width < 0)
|
||||||
pangoWidth = -1;
|
pangoWidth = -1;
|
||||||
pango_layout_set_width(tl->layout, pangoWidth);
|
pango_layout_set_width(tl->layout, pangoWidth);
|
||||||
|
|
||||||
|
pango_layout_set_alignment(tl->layout, pangoAligns[p->Align]);
|
||||||
|
|
||||||
// TODO attributes
|
// TODO attributes
|
||||||
|
|
||||||
tl->nLines = pango_layout_get_line_count(tl->layout);
|
tl->nLines = pango_layout_get_line_count(tl->layout);
|
||||||
|
|
Loading…
Reference in New Issue