diff --git a/unix/attrstr.c b/unix/attrstr.c index f627d6c1..cdc72da5 100644 --- a/unix/attrstr.c +++ b/unix/attrstr.c @@ -1,10 +1,8 @@ // 12 february 2017 #include "uipriv_unix.h" -// TODO ligatures items turn ligatures *OFF*?! -// TODO actually does not specifying a feature revert to default? - // we need to collect all the OpenType features and background blocks and add them all at once +// TODO this is the wrong approach; it causes Pango to end runs early, meaning attributes like the ligature attributes never get applied properly // TODO rename this struct to something that isn't exclusively foreach-ing? struct foreachParams { const char *s; @@ -89,7 +87,7 @@ static void doOpenType(const char *featureTag, uint32_t param, void *data) ensureFeaturesInRange(p->p, p->start, p->end); for (i = p->start; i < p->end; i++) { // don't use redundant entries; see below - if (!isCodepointStart(p->s[i])) + if (!isCodepointStart(p->p->s[i])) continue; s = (GString *) g_hash_table_lookup(p->p->features, &i); g_string_append_printf(s, "\"%s\" %" PRIu32 ", ", @@ -120,30 +118,23 @@ static int processAttribute(uiAttributedString *s, uiAttributeSpec *spec, size_t addattr(p, start, end, pango_attr_family_new((const char *) (spec->Value))); break; -#if 0 /* TODO */ case uiAttributeSize: addattr(p, start, end, pango_attr_size_new(cairoToPango(spec->Double))); break; case uiAttributeWeight: - ensureFontInRange(p, start, end); - adjustFontInRange(p, start, end, ^(struct fontParams *fp) { - fp->desc.Weight = (uiDrawTextWeight) (spec->Value); - }); + // TODO reverse the misalignment from drawtext.c if it is corrected + addattr(p, start, end, + pango_attr_weight_new((PangoWeight) (spec->Value))); break; case uiAttributeItalic: - ensureFontInRange(p, start, end); - adjustFontInRange(p, start, end, ^(struct fontParams *fp) { - fp->desc.Italic = (uiDrawTextItalic) (spec->Value); - }); + addattr(p, start, end, + pango_attr_style_new(pangoItalics[(uiDrawTextItalic) (spec->Value)])); break; case uiAttributeStretch: - ensureFontInRange(p, start, end); - adjustFontInRange(p, start, end, ^(struct fontParams *fp) { - fp->desc.Stretch = (uiDrawTextStretch) (spec->Value); - }); + addattr(p, start, end, + pango_attr_stretch_new(pangoStretches[(uiDrawTextStretch) (spec->Value)])); break; -#endif case uiAttributeColor: addattr(p, start, end, pango_attr_foreground_new( diff --git a/unix/drawtext.c b/unix/drawtext.c index 16ede458..f0e86b86 100644 --- a/unix/drawtext.c +++ b/unix/drawtext.c @@ -14,7 +14,7 @@ struct uiDrawTextLayout { // See https://developer.gnome.org/pango/1.30/pango-Cairo-Rendering.html#pango-Cairo-Rendering.description // For the conversion, see https://developer.gnome.org/pango/1.30/pango-Glyph-Storage.html#pango-units-to-double and https://developer.gnome.org/pango/1.30/pango-Glyph-Storage.html#pango-units-from-double #define pangoToCairo(pango) (pango_units_to_double(pango)) -#define cairoToPango(cairo) (pango_units_from_double(cairo)) +// cairoToPango() is in uipriv_unix.h because attrstr.c needs it // we need a context for a few things // the documentation suggests creating cairo_t-specific, GdkScreen-specific, or even GtkWidget-specific contexts, but we can't really do that because we want our uiDrawTextFonts and uiDrawTextLayouts to be context-independent @@ -22,13 +22,13 @@ struct uiDrawTextLayout { // so let's use gdk_pango_context_get() instead; even though it's for the default screen only, it's good enough for us #define mkGenericPangoCairoContext() (gdk_pango_context_get()) -static const PangoStyle pangoItalics[] = { +const PangoStyle pangoItalics[] = { [uiDrawTextItalicNormal] = PANGO_STYLE_NORMAL, [uiDrawTextItalicOblique] = PANGO_STYLE_OBLIQUE, [uiDrawTextItalicItalic] = PANGO_STYLE_ITALIC, }; -static const PangoStretch pangoStretches[] = { +const PangoStretch pangoStretches[] = { [uiDrawTextStretchUltraCondensed] = PANGO_STRETCH_ULTRA_CONDENSED, [uiDrawTextStretchExtraCondensed] = PANGO_STRETCH_EXTRA_CONDENSED, [uiDrawTextStretchCondensed] = PANGO_STRETCH_CONDENSED, diff --git a/unix/uipriv_unix.h b/unix/uipriv_unix.h index d2ef5bf0..78e94ad8 100644 --- a/unix/uipriv_unix.h +++ b/unix/uipriv_unix.h @@ -64,3 +64,9 @@ extern void fontdescFromPangoFontDescription(PangoFontDescription *pdesc, uiDraw // attrstr.c extern PangoAttrList *attrstrToPangoAttrList(uiDrawTextLayoutParams *p/*TODO, NSArray **backgroundBlocks*/); + +// drawtext.c +// TODO get rid of these (for attrstr.c) +#define cairoToPango(cairo) (pango_units_from_double(cairo)) +extern const PangoStyle pangoItalics[]; +extern const PangoStretch pangoStretches[];