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);
|
||||
|
||||
// drawtext.m
|
||||
// TODO figure out where this type should *really* go in all the headers...
|
||||
@interface uiprivDrawTextBackgroundParams : NSObject {
|
||||
size_t start;
|
||||
size_t end;
|
||||
|
|
|
@ -7,24 +7,8 @@
|
|||
// TODO make this name less generic?
|
||||
struct foreachParams {
|
||||
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)
|
||||
{
|
||||
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)));
|
||||
break;
|
||||
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);
|
||||
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;
|
||||
case uiAttributeTypeUnderline:
|
||||
switch (uiAttributeUnderline(attr)) {
|
||||
|
@ -143,18 +135,11 @@ static uiForEach processAttribute(const uiAttributedString *s, const uiAttribute
|
|||
return uiForEachContinue;
|
||||
}
|
||||
|
||||
static void freeBackgroundParams(gpointer data)
|
||||
{
|
||||
uiprivFree((uiprivDrawTextBackgroundParams *) data);
|
||||
}
|
||||
|
||||
PangoAttrList *uiprivAttributedStringToPangoAttrList(uiDrawTextLayoutParams *p, GPtrArray **backgroundParams)
|
||||
PangoAttrList *uiprivAttributedStringToPangoAttrList(uiDrawTextLayoutParams *p)
|
||||
{
|
||||
struct foreachParams fep;
|
||||
|
||||
fep.attrs = pango_attr_list_new();
|
||||
fep.backgroundParams = g_ptr_array_new_with_free_func(freeBackgroundParams);
|
||||
uiAttributedStringForEachAttribute(p->String, processAttribute, &fep);
|
||||
*backgroundParams = fep.backgroundParams;
|
||||
return fep.attrs;
|
||||
}
|
||||
|
|
|
@ -17,16 +17,4 @@ extern PangoFontDescription *uiprivFontDescriptorToPangoFontDescription(const ui
|
|||
extern void uiprivFontDescriptorFromPangoFontDescription(PangoFontDescription *pdesc, uiFontDescriptor *uidesc);
|
||||
|
||||
// attrstr.c
|
||||
extern PangoAttrList *uiprivAttributedStringToPangoAttrList(uiDrawTextLayoutParams *p, GPtrArray **backgroundParams);
|
||||
|
||||
// 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;
|
||||
};
|
||||
extern PangoAttrList *uiprivAttributedStringToPangoAttrList(uiDrawTextLayoutParams *p);
|
||||
|
|
|
@ -5,7 +5,6 @@
|
|||
|
||||
struct uiDrawTextLayout {
|
||||
PangoLayout *layout;
|
||||
GPtrArray *backgroundParams;
|
||||
};
|
||||
|
||||
// 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]);
|
||||
|
||||
attrs = uiprivAttributedStringToPangoAttrList(p, &(tl->backgroundParams));
|
||||
attrs = uiprivAttributedStringToPangoAttrList(p);
|
||||
pango_layout_set_attributes(tl->layout, attrs);
|
||||
pango_attr_list_unref(attrs);
|
||||
|
||||
|
@ -60,18 +59,12 @@ uiDrawTextLayout *uiDrawNewTextLayout(uiDrawTextLayoutParams *p)
|
|||
|
||||
void uiDrawFreeTextLayout(uiDrawTextLayout *tl)
|
||||
{
|
||||
g_ptr_array_unref(tl->backgroundParams);
|
||||
g_object_unref(tl->layout);
|
||||
uiprivFree(tl);
|
||||
}
|
||||
|
||||
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?
|
||||
cairo_set_source_rgb(c->cr, 0.0, 0.0, 0.0);
|
||||
cairo_move_to(c->cr, x, y);
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
// added in pango 1.38; we need 1.36
|
||||
static PangoAttribute *(*newFeaturesAttr)(const gchar *features) = NULL;
|
||||
static PangoAttribute *(*newFGAlphaAttr)(guint16 alpha) = NULL;
|
||||
static PangoAttribute *(*newBGAlphaAttr)(guint16 alpha) = NULL;
|
||||
|
||||
// added in GTK+ 3.20; we need 3.10
|
||||
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)
|
||||
GET(newFeaturesAttr, pango_attr_font_features_new);
|
||||
GET(newFGAlphaAttr, pango_attr_foreground_alpha_new);
|
||||
GET(newBGAlphaAttr, pango_attr_background_alpha_new);
|
||||
GET(gwpIterSetObjectName, gtk_widget_path_iter_set_object_name);
|
||||
dlclose(handle);
|
||||
}
|
||||
|
@ -42,6 +44,13 @@ PangoAttribute *FUTURE_pango_attr_foreground_alpha_new(guint16 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)
|
||||
{
|
||||
if (gwpIterSetObjectName == NULL)
|
||||
|
|
|
@ -57,4 +57,5 @@ extern GtkCellRenderer *newCellRendererButton(void);
|
|||
extern void loadFutures(void);
|
||||
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_background_alpha_new(guint16 alpha);
|
||||
extern gboolean FUTURE_gtk_widget_path_iter_set_object_name(GtkWidgetPath *path, gint pos, const char *name);
|
||||
|
|
Loading…
Reference in New Issue