Switched to using Pango background color attributes. Unix code done for now.
This commit is contained in:
parent
602060a673
commit
bffe311afe
|
@ -77,6 +77,7 @@ extern void uiprivUninitUnderlineColors(void);
|
||||||
extern CFAttributedStringRef uiprivAttributedStringToCFAttributedString(uiDrawTextLayoutParams *p, NSArray **backgroundParams);
|
extern CFAttributedStringRef uiprivAttributedStringToCFAttributedString(uiDrawTextLayoutParams *p, NSArray **backgroundParams);
|
||||||
|
|
||||||
// drawtext.m
|
// drawtext.m
|
||||||
|
// TODO figure out where this type should *really* go in all the headers...
|
||||||
@interface uiprivDrawTextBackgroundParams : NSObject {
|
@interface uiprivDrawTextBackgroundParams : NSObject {
|
||||||
size_t start;
|
size_t start;
|
||||||
size_t end;
|
size_t end;
|
||||||
|
|
|
@ -7,24 +7,8 @@
|
||||||
// TODO make this name less generic?
|
// TODO make this name less generic?
|
||||||
struct foreachParams {
|
struct foreachParams {
|
||||||
PangoAttrList *attrs;
|
PangoAttrList *attrs;
|
||||||
// TODO use pango's built-in background attribute
|
|
||||||
GPtrArray *backgroundParams;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
static void addBackgroundAttribute(struct foreachParams *p, size_t start, size_t end, double r, double g, double b, double a)
|
|
||||||
{
|
|
||||||
uiprivDrawTextBackgroundParams *dtb;
|
|
||||||
|
|
||||||
dtb = uiprivNew(uiprivDrawTextBackgroundParams);
|
|
||||||
dtb->start = start;
|
|
||||||
dtb->end = end;
|
|
||||||
dtb->r = r;
|
|
||||||
dtb->g = g;
|
|
||||||
dtb->b = b;
|
|
||||||
dtb->a = a;
|
|
||||||
g_ptr_array_add(p->backgroundParams, dtb);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void addattr(struct foreachParams *p, size_t start, size_t end, PangoAttribute *attr)
|
static void addattr(struct foreachParams *p, size_t start, size_t end, PangoAttribute *attr)
|
||||||
{
|
{
|
||||||
if (attr == NULL) // in case of a future attribute
|
if (attr == NULL) // in case of a future attribute
|
||||||
|
@ -77,8 +61,16 @@ static uiForEach processAttribute(const uiAttributedString *s, const uiAttribute
|
||||||
(guint16) (a * 65535.0)));
|
(guint16) (a * 65535.0)));
|
||||||
break;
|
break;
|
||||||
case uiAttributeTypeBackground:
|
case uiAttributeTypeBackground:
|
||||||
|
// TODO make sure this works properly with line paragraph spacings (after figuring out what that means, of course)
|
||||||
uiAttributeColor(attr, &r, &g, &b, &a);
|
uiAttributeColor(attr, &r, &g, &b, &a);
|
||||||
addBackgroundAttribute(p, start, end, r, g, b, a);
|
addattr(p, start, end,
|
||||||
|
pango_attr_background_new(
|
||||||
|
(guint16) (r * 65535.0),
|
||||||
|
(guint16) (g * 65535.0),
|
||||||
|
(guint16) (b * 65535.0)));
|
||||||
|
addattr(p, start, end,
|
||||||
|
FUTURE_pango_attr_background_alpha_new(
|
||||||
|
(guint16) (a * 65535.0)));
|
||||||
break;
|
break;
|
||||||
case uiAttributeTypeUnderline:
|
case uiAttributeTypeUnderline:
|
||||||
switch (uiAttributeUnderline(attr)) {
|
switch (uiAttributeUnderline(attr)) {
|
||||||
|
@ -143,18 +135,11 @@ static uiForEach processAttribute(const uiAttributedString *s, const uiAttribute
|
||||||
return uiForEachContinue;
|
return uiForEachContinue;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void freeBackgroundParams(gpointer data)
|
PangoAttrList *uiprivAttributedStringToPangoAttrList(uiDrawTextLayoutParams *p)
|
||||||
{
|
|
||||||
uiprivFree((uiprivDrawTextBackgroundParams *) data);
|
|
||||||
}
|
|
||||||
|
|
||||||
PangoAttrList *uiprivAttributedStringToPangoAttrList(uiDrawTextLayoutParams *p, GPtrArray **backgroundParams)
|
|
||||||
{
|
{
|
||||||
struct foreachParams fep;
|
struct foreachParams fep;
|
||||||
|
|
||||||
fep.attrs = pango_attr_list_new();
|
fep.attrs = pango_attr_list_new();
|
||||||
fep.backgroundParams = g_ptr_array_new_with_free_func(freeBackgroundParams);
|
|
||||||
uiAttributedStringForEachAttribute(p->String, processAttribute, &fep);
|
uiAttributedStringForEachAttribute(p->String, processAttribute, &fep);
|
||||||
*backgroundParams = fep.backgroundParams;
|
|
||||||
return fep.attrs;
|
return fep.attrs;
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,16 +17,4 @@ extern PangoFontDescription *uiprivFontDescriptorToPangoFontDescription(const ui
|
||||||
extern void uiprivFontDescriptorFromPangoFontDescription(PangoFontDescription *pdesc, uiFontDescriptor *uidesc);
|
extern void uiprivFontDescriptorFromPangoFontDescription(PangoFontDescription *pdesc, uiFontDescriptor *uidesc);
|
||||||
|
|
||||||
// attrstr.c
|
// attrstr.c
|
||||||
extern PangoAttrList *uiprivAttributedStringToPangoAttrList(uiDrawTextLayoutParams *p, GPtrArray **backgroundParams);
|
extern PangoAttrList *uiprivAttributedStringToPangoAttrList(uiDrawTextLayoutParams *p);
|
||||||
|
|
||||||
// drawtext.c
|
|
||||||
// TODO figure out where this type should *really* go in all the headers...
|
|
||||||
typedef struct uiprivDrawTextBackgroundParams uiprivDrawTextBackgroundParams;
|
|
||||||
struct uiprivDrawTextBackgroundParams {
|
|
||||||
size_t start;
|
|
||||||
size_t end;
|
|
||||||
double r;
|
|
||||||
double g;
|
|
||||||
double b;
|
|
||||||
double a;
|
|
||||||
};
|
|
||||||
|
|
|
@ -5,7 +5,6 @@
|
||||||
|
|
||||||
struct uiDrawTextLayout {
|
struct uiDrawTextLayout {
|
||||||
PangoLayout *layout;
|
PangoLayout *layout;
|
||||||
GPtrArray *backgroundParams;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// we need a context for a few things
|
// we need a context for a few things
|
||||||
|
@ -51,7 +50,7 @@ uiDrawTextLayout *uiDrawNewTextLayout(uiDrawTextLayoutParams *p)
|
||||||
|
|
||||||
pango_layout_set_alignment(tl->layout, pangoAligns[p->Align]);
|
pango_layout_set_alignment(tl->layout, pangoAligns[p->Align]);
|
||||||
|
|
||||||
attrs = uiprivAttributedStringToPangoAttrList(p, &(tl->backgroundParams));
|
attrs = uiprivAttributedStringToPangoAttrList(p);
|
||||||
pango_layout_set_attributes(tl->layout, attrs);
|
pango_layout_set_attributes(tl->layout, attrs);
|
||||||
pango_attr_list_unref(attrs);
|
pango_attr_list_unref(attrs);
|
||||||
|
|
||||||
|
@ -60,18 +59,12 @@ uiDrawTextLayout *uiDrawNewTextLayout(uiDrawTextLayoutParams *p)
|
||||||
|
|
||||||
void uiDrawFreeTextLayout(uiDrawTextLayout *tl)
|
void uiDrawFreeTextLayout(uiDrawTextLayout *tl)
|
||||||
{
|
{
|
||||||
g_ptr_array_unref(tl->backgroundParams);
|
|
||||||
g_object_unref(tl->layout);
|
g_object_unref(tl->layout);
|
||||||
uiprivFree(tl);
|
uiprivFree(tl);
|
||||||
}
|
}
|
||||||
|
|
||||||
void uiDrawText(uiDrawContext *c, uiDrawTextLayout *tl, double x, double y)
|
void uiDrawText(uiDrawContext *c, uiDrawTextLayout *tl, double x, double y)
|
||||||
{
|
{
|
||||||
guint i;
|
|
||||||
|
|
||||||
for (i = 0; i < tl->backgroundParams->len; i++) {
|
|
||||||
// TODO
|
|
||||||
}
|
|
||||||
// TODO have an implicit save/restore on each drawing functions instead? and is this correct?
|
// TODO have an implicit save/restore on each drawing functions instead? and is this correct?
|
||||||
cairo_set_source_rgb(c->cr, 0.0, 0.0, 0.0);
|
cairo_set_source_rgb(c->cr, 0.0, 0.0, 0.0);
|
||||||
cairo_move_to(c->cr, x, y);
|
cairo_move_to(c->cr, x, y);
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
// added in pango 1.38; we need 1.36
|
// added in pango 1.38; we need 1.36
|
||||||
static PangoAttribute *(*newFeaturesAttr)(const gchar *features) = NULL;
|
static PangoAttribute *(*newFeaturesAttr)(const gchar *features) = NULL;
|
||||||
static PangoAttribute *(*newFGAlphaAttr)(guint16 alpha) = NULL;
|
static PangoAttribute *(*newFGAlphaAttr)(guint16 alpha) = NULL;
|
||||||
|
static PangoAttribute *(*newBGAlphaAttr)(guint16 alpha) = NULL;
|
||||||
|
|
||||||
// added in GTK+ 3.20; we need 3.10
|
// added in GTK+ 3.20; we need 3.10
|
||||||
static void (*gwpIterSetObjectName)(GtkWidgetPath *path, gint pos, const char *name) = NULL;
|
static void (*gwpIterSetObjectName)(GtkWidgetPath *path, gint pos, const char *name) = NULL;
|
||||||
|
@ -24,6 +25,7 @@ void loadFutures(void)
|
||||||
#define GET(var, fn) *((void **) (&var)) = dlsym(handle, #fn)
|
#define GET(var, fn) *((void **) (&var)) = dlsym(handle, #fn)
|
||||||
GET(newFeaturesAttr, pango_attr_font_features_new);
|
GET(newFeaturesAttr, pango_attr_font_features_new);
|
||||||
GET(newFGAlphaAttr, pango_attr_foreground_alpha_new);
|
GET(newFGAlphaAttr, pango_attr_foreground_alpha_new);
|
||||||
|
GET(newBGAlphaAttr, pango_attr_background_alpha_new);
|
||||||
GET(gwpIterSetObjectName, gtk_widget_path_iter_set_object_name);
|
GET(gwpIterSetObjectName, gtk_widget_path_iter_set_object_name);
|
||||||
dlclose(handle);
|
dlclose(handle);
|
||||||
}
|
}
|
||||||
|
@ -42,6 +44,13 @@ PangoAttribute *FUTURE_pango_attr_foreground_alpha_new(guint16 alpha)
|
||||||
return (*newFGAlphaAttr)(alpha);
|
return (*newFGAlphaAttr)(alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PangoAttribute *FUTURE_pango_attr_background_alpha_new(guint16 alpha)
|
||||||
|
{
|
||||||
|
if (newBGAlphaAttr == NULL)
|
||||||
|
return NULL;
|
||||||
|
return (*newBGAlphaAttr)(alpha);
|
||||||
|
}
|
||||||
|
|
||||||
gboolean FUTURE_gtk_widget_path_iter_set_object_name(GtkWidgetPath *path, gint pos, const char *name)
|
gboolean FUTURE_gtk_widget_path_iter_set_object_name(GtkWidgetPath *path, gint pos, const char *name)
|
||||||
{
|
{
|
||||||
if (gwpIterSetObjectName == NULL)
|
if (gwpIterSetObjectName == NULL)
|
||||||
|
|
|
@ -57,4 +57,5 @@ extern GtkCellRenderer *newCellRendererButton(void);
|
||||||
extern void loadFutures(void);
|
extern void loadFutures(void);
|
||||||
extern PangoAttribute *FUTURE_pango_attr_font_features_new(const gchar *features);
|
extern PangoAttribute *FUTURE_pango_attr_font_features_new(const gchar *features);
|
||||||
extern PangoAttribute *FUTURE_pango_attr_foreground_alpha_new(guint16 alpha);
|
extern PangoAttribute *FUTURE_pango_attr_foreground_alpha_new(guint16 alpha);
|
||||||
|
extern PangoAttribute *FUTURE_pango_attr_background_alpha_new(guint16 alpha);
|
||||||
extern gboolean FUTURE_gtk_widget_path_iter_set_object_name(GtkWidgetPath *path, gint pos, const char *name);
|
extern gboolean FUTURE_gtk_widget_path_iter_set_object_name(GtkWidgetPath *path, gint pos, const char *name);
|
||||||
|
|
Loading…
Reference in New Issue