static gboolean cb_unset2 (PangoAttribute *attr, gpointer _data) { struct cb_unset *data = _data; /* All inside cleared area. */ if (attr->start_index >= data->start_index && attr->end_index <= data->end_index) return FALSE; attr = pango_attribute_copy (attr); if (attr->end_index > data->start_index && attr->end_index <= data->end_index) /* Ends inside cleared area. */ attr->end_index = data->start_index; else if (attr->start_index >= data->start_index && attr->start_index < data->end_index) /* Starts inside cleared area. */ attr->start_index = data->end_index; else if (attr->start_index < data->start_index && attr->end_index > data->end_index) { /* Starts before, ends after. */ PangoAttribute *attr2 = pango_attribute_copy (attr); attr2->start_index = data->end_index; pango_attr_list_insert (data->list, attr2); attr->end_index = data->start_index; } pango_attr_list_insert (data->list, attr); return FALSE; }
static gboolean cb_splice (PangoAttribute *attr, gpointer _data) { struct cb_splice *data = _data; if (attr->start_index >= data->pos) { PangoAttribute *new_attr = pango_attribute_copy (attr); new_attr->start_index += data->len; new_attr->end_index += data->len; pango_attr_list_insert (data->result, new_attr); } else if (attr->end_index <= data->pos) { PangoAttribute *new_attr = pango_attribute_copy (attr); pango_attr_list_insert (data->result, new_attr); } else { PangoAttribute *new_attr = pango_attribute_copy (attr); new_attr->end_index = data->pos; pango_attr_list_insert (data->result, new_attr); new_attr = pango_attribute_copy (attr); new_attr->start_index = data->pos + data->len; new_attr->end_index += data->len; pango_attr_list_insert (data->result, new_attr); } return FALSE; }
void iupgtkFontUpdatePangoLayout(Ihandle* ih, PangoLayout* layout) { IgtkFont* gtkfont; PangoAttrList *attrs; if (!layout) return; gtkfont = gtkFontGet(ih); if (!gtkfont) return; attrs = pango_layout_get_attributes(layout); if (!attrs) { attrs = pango_attr_list_new(); pango_attr_list_insert(attrs, pango_attribute_copy(gtkfont->strikethrough)); pango_attr_list_insert(attrs, pango_attribute_copy(gtkfont->underline)); pango_layout_set_attributes(layout, attrs); } else { pango_attr_list_change(attrs, pango_attribute_copy(gtkfont->strikethrough)); pango_attr_list_change(attrs, pango_attribute_copy(gtkfont->underline)); } }
static int cdfont(cdCtxCanvas *ctxcanvas, const char *typeface, int style, int size) { int is_italic = 0, is_bold = 0; /* default is CD_PLAIN */ int is_strikeout = 0, is_underline = 0; char font[256]; PangoAttrList *attrs; if (cdStrEqualNoCase(typeface, "Courier") || cdStrEqualNoCase(typeface, "Courier New")) typeface = "Monospace"; else if (cdStrEqualNoCase(typeface, "Times") || cdStrEqualNoCase(typeface, "Times New Roman")) typeface = "Serif"; else if (cdStrEqualNoCase(typeface, "Helvetica") || cdStrEqualNoCase(typeface, "Arial")) typeface = "Sans"; if (style & CD_BOLD) is_bold = 1; if (style & CD_ITALIC) is_italic = 1; if (style & CD_UNDERLINE) is_underline = 1; if (style & CD_STRIKEOUT) is_strikeout = 1; size = cdGetFontSizePoints(ctxcanvas->canvas, size); sprintf(font, "%s, %s%s%d", typeface, is_bold?"Bold ":"", is_italic?"Italic ":"", size); if (ctxcanvas->fontdesc) pango_font_description_free(ctxcanvas->fontdesc); ctxcanvas->fontdesc = pango_font_description_from_string(font); if (!ctxcanvas->fontdesc) return 0; if (ctxcanvas->fontlayout) g_object_unref(ctxcanvas->fontlayout); ctxcanvas->fontlayout = pango_layout_new(ctxcanvas->fontcontext); pango_layout_set_font_description(ctxcanvas->fontlayout, ctxcanvas->fontdesc); attrs = pango_attr_list_new(); pango_attr_list_insert(attrs, pango_attribute_copy(pango_attr_strikethrough_new(is_strikeout ? TRUE : FALSE))); pango_attr_list_insert(attrs, pango_attribute_copy(pango_attr_underline_new(is_underline ? PANGO_UNDERLINE_SINGLE : PANGO_UNDERLINE_NONE))); pango_layout_set_attributes(ctxcanvas->fontlayout, attrs); pango_attr_list_unref(attrs); return 1; }
/** * pango_item_copy: * @item: a #PangoItem * * Copy an existing #PangoItem structure. * * Return value: the new #PangoItem **/ PangoItem * pango_item_copy (PangoItem *item) { GSList *extra_attrs, *tmp_list; PangoItem *result = g_new (PangoItem, 1); result->offset = item->offset; result->length = item->length; result->num_chars = item->num_chars; result->analysis = item->analysis; if (result->analysis.font) g_object_ref (result->analysis.font); extra_attrs = NULL; tmp_list = item->analysis.extra_attrs; while (tmp_list) { extra_attrs = g_slist_prepend (extra_attrs, pango_attribute_copy (tmp_list->data)); tmp_list = tmp_list->next; } result->analysis.extra_attrs = g_slist_reverse (extra_attrs); return result; }
static gboolean append_txorun (PangoAttribute *src, TXORun *run) { PangoAttribute *dst = pango_attribute_copy (src); dst->start_index = run->first; /* inclusive */ dst->end_index = run->last; /* exclusive */ pango_attr_list_change (run->accum, dst); return FALSE; }
static void gtkFontUpdate(IgtkFont* gtkfont) { PangoAttrList *attrs; pango_layout_set_font_description(gtkfont->layout, gtkfont->fontdesc); attrs = pango_layout_get_attributes(gtkfont->layout); if (!attrs) { attrs = pango_attr_list_new(); pango_attr_list_insert(attrs, pango_attribute_copy(gtkfont->strikethrough)); pango_attr_list_insert(attrs, pango_attribute_copy(gtkfont->underline)); pango_layout_set_attributes(gtkfont->layout, attrs); } else { pango_attr_list_change(attrs, pango_attribute_copy(gtkfont->strikethrough)); pango_attr_list_change(attrs, pango_attribute_copy(gtkfont->underline)); } }
void iupgtkFontUpdateObjectPangoLayout(Ihandle* ih, gpointer object) { PangoAttrList *attrs; IgtkFont* gtkfont = gtkFontGet(ih); if (!gtkfont) return; g_object_get(object, "attributes", &attrs, NULL); if (!attrs) { attrs = pango_attr_list_new(); pango_attr_list_insert(attrs, pango_attribute_copy(gtkfont->strikethrough)); pango_attr_list_insert(attrs, pango_attribute_copy(gtkfont->underline)); g_object_set(object, "attributes", attrs, NULL); } else { pango_attr_list_change(attrs, pango_attribute_copy(gtkfont->strikethrough)); pango_attr_list_change(attrs, pango_attribute_copy(gtkfont->underline)); } }
static void set_or_unset (PangoAttrList *dst, const PangoAttribute *attr, PangoAttrList *ref) { struct cb_set_or_unset data; data.attr = attr; data.set_in_ref = FALSE; (void)pango_attr_list_filter (ref, cb_set_or_unset, &data); if (data.set_in_ref) go_pango_attr_list_unset (dst, attr->start_index, attr->end_index, attr->klass->type); else pango_attr_list_change (dst, pango_attribute_copy (attr)); }
static void gutter_renderer_text_draw (GtkSourceGutterRenderer *renderer, cairo_t *cr, GdkRectangle *background_area, GdkRectangle *cell_area, GtkTextIter *start, GtkTextIter *end, GtkSourceGutterRendererState state) { GtkSourceGutterRendererText *text = GTK_SOURCE_GUTTER_RENDERER_TEXT (renderer); gint width; gint height; PangoAttrList *attr_list; gfloat xalign; gfloat yalign; GtkSourceGutterRendererAlignmentMode mode; GtkTextView *view; gint x = 0; gint y = 0; GtkStyleContext *context; /* Chain up to draw background */ if (GTK_SOURCE_GUTTER_RENDERER_CLASS (gtk_source_gutter_renderer_text_parent_class)->draw != NULL) { GTK_SOURCE_GUTTER_RENDERER_CLASS (gtk_source_gutter_renderer_text_parent_class)->draw (renderer, cr, background_area, cell_area, start, end, state); } view = gtk_source_gutter_renderer_get_view (renderer); if (text->priv->is_markup) { pango_layout_set_markup (text->priv->cached_layout, text->priv->text, -1); } else { pango_layout_set_text (text->priv->cached_layout, text->priv->text, -1); } attr_list = pango_layout_get_attributes (text->priv->cached_layout); if (!attr_list) { pango_layout_set_attributes (text->priv->cached_layout, pango_attr_list_copy (text->priv->cached_attr_list)); } else { pango_attr_list_insert (attr_list, pango_attribute_copy (text->priv->fg_attr)); } pango_layout_get_pixel_size (text->priv->cached_layout, &width, &height); gtk_source_gutter_renderer_get_alignment (renderer, &xalign, &yalign); mode = gtk_source_gutter_renderer_get_alignment_mode (renderer); switch (mode) { case GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_CELL: x = cell_area->x + (cell_area->width - width) * xalign; y = cell_area->y + (cell_area->height - height) * yalign; break; case GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_FIRST: center_on (renderer, cell_area, start, width, height, xalign, yalign, &x, &y); break; case GTK_SOURCE_GUTTER_RENDERER_ALIGNMENT_MODE_LAST: center_on (renderer, cell_area, end, width, height, xalign, yalign, &x, &y); break; } context = gtk_widget_get_style_context (GTK_WIDGET (view)); gtk_render_layout (context, cr, x, y, text->priv->cached_layout); }
USER_OBJECT_ toRPangoAttribute(PangoAttribute *attr, gboolean owns) { char *type = NULL; USER_OBJECT_ result; char *classes[] = { NULL, "PangoAttribute", "RGtkObject", NULL }; if (!attr) return NULL_USER_OBJECT; switch(attr->klass->type) { case PANGO_ATTR_LANGUAGE: type = "PangoAttrLanguage"; break; case PANGO_ATTR_FAMILY: type = "PangoAttrString"; break; case PANGO_ATTR_STYLE: case PANGO_ATTR_WEIGHT: case PANGO_ATTR_VARIANT: case PANGO_ATTR_STRETCH: case PANGO_ATTR_UNDERLINE: case PANGO_ATTR_STRIKETHROUGH: case PANGO_ATTR_RISE: case PANGO_ATTR_FALLBACK: case PANGO_ATTR_LETTER_SPACING: type = "PangoAttrInt"; break; case PANGO_ATTR_SIZE: case PANGO_ATTR_ABSOLUTE_SIZE: type = "PangoAttrSize"; break; case PANGO_ATTR_FONT_DESC: type = "PangoAttrFontDesc"; break; case PANGO_ATTR_FOREGROUND: case PANGO_ATTR_BACKGROUND: case PANGO_ATTR_UNDERLINE_COLOR: case PANGO_ATTR_STRIKETHROUGH_COLOR: type = "PangoAttrColor"; break; case PANGO_ATTR_SHAPE: type = "PangoAttrShape"; break; case PANGO_ATTR_SCALE: type = "PangoAttrFloat"; break; case PANGO_ATTR_INVALID: type = "PangoAttrInvalid"; break; default: PROBLEM "Error converting PangoAttribute: unknown type %d", attr->klass->type ERROR; } classes[0] = type; if (!owns) attr = pango_attribute_copy(attr); PROTECT(result = toRPointerWithFinalizer(attr, NULL, (RPointerFinalizer)pango_attribute_destroy)); SET_CLASS(result, asRStringArray(classes)); UNPROTECT(1); return(result); }