More attribute implementation.
This commit is contained in:
parent
4a1642cea2
commit
4ba4e4ba23
|
@ -1,10 +1,8 @@
|
||||||
// 12 february 2017
|
// 12 february 2017
|
||||||
#include "uipriv_unix.h"
|
#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
|
// 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?
|
// TODO rename this struct to something that isn't exclusively foreach-ing?
|
||||||
struct foreachParams {
|
struct foreachParams {
|
||||||
const char *s;
|
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);
|
ensureFeaturesInRange(p->p, p->start, p->end);
|
||||||
for (i = p->start; i < p->end; i++) {
|
for (i = p->start; i < p->end; i++) {
|
||||||
// don't use redundant entries; see below
|
// don't use redundant entries; see below
|
||||||
if (!isCodepointStart(p->s[i]))
|
if (!isCodepointStart(p->p->s[i]))
|
||||||
continue;
|
continue;
|
||||||
s = (GString *) g_hash_table_lookup(p->p->features, &i);
|
s = (GString *) g_hash_table_lookup(p->p->features, &i);
|
||||||
g_string_append_printf(s, "\"%s\" %" PRIu32 ", ",
|
g_string_append_printf(s, "\"%s\" %" PRIu32 ", ",
|
||||||
|
@ -120,30 +118,23 @@ static int processAttribute(uiAttributedString *s, uiAttributeSpec *spec, size_t
|
||||||
addattr(p, start, end,
|
addattr(p, start, end,
|
||||||
pango_attr_family_new((const char *) (spec->Value)));
|
pango_attr_family_new((const char *) (spec->Value)));
|
||||||
break;
|
break;
|
||||||
#if 0 /* TODO */
|
|
||||||
case uiAttributeSize:
|
case uiAttributeSize:
|
||||||
addattr(p, start, end,
|
addattr(p, start, end,
|
||||||
pango_attr_size_new(cairoToPango(spec->Double)));
|
pango_attr_size_new(cairoToPango(spec->Double)));
|
||||||
break;
|
break;
|
||||||
case uiAttributeWeight:
|
case uiAttributeWeight:
|
||||||
ensureFontInRange(p, start, end);
|
// TODO reverse the misalignment from drawtext.c if it is corrected
|
||||||
adjustFontInRange(p, start, end, ^(struct fontParams *fp) {
|
addattr(p, start, end,
|
||||||
fp->desc.Weight = (uiDrawTextWeight) (spec->Value);
|
pango_attr_weight_new((PangoWeight) (spec->Value)));
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
case uiAttributeItalic:
|
case uiAttributeItalic:
|
||||||
ensureFontInRange(p, start, end);
|
addattr(p, start, end,
|
||||||
adjustFontInRange(p, start, end, ^(struct fontParams *fp) {
|
pango_attr_style_new(pangoItalics[(uiDrawTextItalic) (spec->Value)]));
|
||||||
fp->desc.Italic = (uiDrawTextItalic) (spec->Value);
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
case uiAttributeStretch:
|
case uiAttributeStretch:
|
||||||
ensureFontInRange(p, start, end);
|
addattr(p, start, end,
|
||||||
adjustFontInRange(p, start, end, ^(struct fontParams *fp) {
|
pango_attr_stretch_new(pangoStretches[(uiDrawTextStretch) (spec->Value)]));
|
||||||
fp->desc.Stretch = (uiDrawTextStretch) (spec->Value);
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
#endif
|
|
||||||
case uiAttributeColor:
|
case uiAttributeColor:
|
||||||
addattr(p, start, end,
|
addattr(p, start, end,
|
||||||
pango_attr_foreground_new(
|
pango_attr_foreground_new(
|
||||||
|
|
|
@ -14,7 +14,7 @@ struct uiDrawTextLayout {
|
||||||
// See https://developer.gnome.org/pango/1.30/pango-Cairo-Rendering.html#pango-Cairo-Rendering.description
|
// 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
|
// 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 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
|
// 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
|
// 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
|
// 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())
|
#define mkGenericPangoCairoContext() (gdk_pango_context_get())
|
||||||
|
|
||||||
static const PangoStyle pangoItalics[] = {
|
const PangoStyle pangoItalics[] = {
|
||||||
[uiDrawTextItalicNormal] = PANGO_STYLE_NORMAL,
|
[uiDrawTextItalicNormal] = PANGO_STYLE_NORMAL,
|
||||||
[uiDrawTextItalicOblique] = PANGO_STYLE_OBLIQUE,
|
[uiDrawTextItalicOblique] = PANGO_STYLE_OBLIQUE,
|
||||||
[uiDrawTextItalicItalic] = PANGO_STYLE_ITALIC,
|
[uiDrawTextItalicItalic] = PANGO_STYLE_ITALIC,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const PangoStretch pangoStretches[] = {
|
const PangoStretch pangoStretches[] = {
|
||||||
[uiDrawTextStretchUltraCondensed] = PANGO_STRETCH_ULTRA_CONDENSED,
|
[uiDrawTextStretchUltraCondensed] = PANGO_STRETCH_ULTRA_CONDENSED,
|
||||||
[uiDrawTextStretchExtraCondensed] = PANGO_STRETCH_EXTRA_CONDENSED,
|
[uiDrawTextStretchExtraCondensed] = PANGO_STRETCH_EXTRA_CONDENSED,
|
||||||
[uiDrawTextStretchCondensed] = PANGO_STRETCH_CONDENSED,
|
[uiDrawTextStretchCondensed] = PANGO_STRETCH_CONDENSED,
|
||||||
|
|
|
@ -64,3 +64,9 @@ extern void fontdescFromPangoFontDescription(PangoFontDescription *pdesc, uiDraw
|
||||||
|
|
||||||
// attrstr.c
|
// attrstr.c
|
||||||
extern PangoAttrList *attrstrToPangoAttrList(uiDrawTextLayoutParams *p/*TODO, NSArray **backgroundBlocks*/);
|
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[];
|
||||||
|
|
Loading…
Reference in New Issue