static Bool textRenderTextToSurface (CompScreen *s, const char *text, TextSurfaceData *data, const CompTextAttrib *attrib) { int width, height, layoutWidth; pango_font_description_set_family (data->font, attrib->family); pango_font_description_set_absolute_size (data->font, attrib->size * PANGO_SCALE); pango_font_description_set_style (data->font, PANGO_STYLE_NORMAL); if (attrib->flags & CompTextFlagStyleBold) pango_font_description_set_weight (data->font, PANGO_WEIGHT_BOLD); if (attrib->flags & CompTextFlagStyleItalic) pango_font_description_set_style (data->font, PANGO_STYLE_ITALIC); pango_layout_set_font_description (data->layout, data->font); if (attrib->flags & CompTextFlagEllipsized) pango_layout_set_ellipsize (data->layout, PANGO_ELLIPSIZE_END); pango_layout_set_auto_dir (data->layout, FALSE); pango_layout_set_text (data->layout, text, -1); pango_layout_get_pixel_size (data->layout, &width, &height); if (attrib->flags & CompTextFlagWithBackground) { width += 2 * attrib->bgHMargin; height += 2 * attrib->bgVMargin; } width = MIN (attrib->maxWidth, width); height = MIN (attrib->maxHeight, height); /* update the size of the pango layout */ layoutWidth = attrib->maxWidth; if (attrib->flags & CompTextFlagWithBackground) layoutWidth -= 2 * attrib->bgHMargin; pango_layout_set_width (data->layout, layoutWidth * PANGO_SCALE); if (!textUpdateSurface (s, data, width, height)) return FALSE; pango_cairo_update_layout (data->cr, data->layout); cairo_save (data->cr); cairo_set_operator (data->cr, CAIRO_OPERATOR_CLEAR); cairo_paint (data->cr); cairo_restore (data->cr); cairo_set_operator (data->cr, CAIRO_OPERATOR_OVER); if (attrib->flags & CompTextFlagWithBackground) { textDrawTextBackground (data->cr, 0, 0, width, height, MIN (attrib->bgHMargin, attrib->bgVMargin)); cairo_set_source_rgba (data->cr, attrib->bgColor[0] / 65535.0, attrib->bgColor[1] / 65535.0, attrib->bgColor[2] / 65535.0, attrib->bgColor[3] / 65535.0); cairo_fill (data->cr); cairo_move_to (data->cr, attrib->bgHMargin, attrib->bgVMargin); } cairo_set_source_rgba (data->cr, attrib->color[0] / 65535.0, attrib->color[1] / 65535.0, attrib->color[2] / 65535.0, attrib->color[3] / 65535.0); pango_cairo_show_layout (data->cr, data->layout); return TRUE; }
static void conting_cs_draw(ContingDrawing *self, cairo_t *cr) { ContingSymbol *symb; ContingComponent *comp; GdkColor *color; ArtPoint pw0, pw1; GdkRectangle rect; gdouble affine[6]; g_return_if_fail(self != NULL && CONTING_IS_CS(self)); symb = CONTING_SYMBOL(self); comp = CONTING_COMPONENT(self); g_object_get(self, "color", &color, NULL); pw0 = comp->p0; pw1 = comp->p1; rect.x = (pw0.x < pw1.x ? pw0.x : pw1.x); rect.y = (pw0.y < pw1.y ? pw0.y : pw1.y); rect.width = fabs(pw1.x - pw0.x); rect.height = fabs(pw1.y - pw0.y); cairo_set_antialias(cr, CAIRO_ANTIALIAS_DEFAULT); cairo_arc(cr, rect.x + ((gdouble) rect.width / 2.0), rect.y + ((gdouble) rect.height / 2.0), (gdouble) rect.width / 2.0, 0, 2 * M_PI); cairo_set_source_rgb(cr, (gdouble) color->red / (gdouble) G_MAXUINT16, (gdouble) color->green / (gdouble) G_MAXUINT16, (gdouble) color->blue / (gdouble) G_MAXUINT16); cairo_stroke(cr); cr = conting_drawing_get_cairo_absolute(self); conting_drawing_get_i2w_affine_absolute(self, affine); cairo_transform(cr, (cairo_matrix_t *) affine); cairo_set_antialias(cr, CAIRO_ANTIALIAS_DEFAULT); cairo_set_source_rgb(cr, (gdouble) color->red / (gdouble) G_MAXUINT16, (gdouble) color->green / (gdouble) G_MAXUINT16, (gdouble) color->blue / (gdouble) G_MAXUINT16); { PangoLayout *layout; PangoFontDescription *font; layout = pango_cairo_create_layout(cr); font = pango_font_description_new(); pango_font_description_set_size(font, 4 * PANGO_SCALE); /* g_print("size = %d\n", pango_font_description_get_size(font)); */ pango_font_description_set_family_static(font, "Arial"); pango_font_description_set_style(font, PANGO_STYLE_NORMAL); pango_layout_set_font_description(layout, font); pango_layout_set_text(layout, "CS", 2); cairo_move_to(cr, pw0.x + 1, pw0.y + 2); pango_cairo_update_layout(cr, layout); pango_cairo_show_layout(cr, layout); g_object_unref(layout); } cairo_stroke(cr); cairo_destroy(cr); CONTING_DRAWING_CLASS(parent_class)->draw(self, cr); }
static GnmFont * style_font_new_simple (PangoContext *context, char const *font_name, double size_pts, gboolean bold, gboolean italic) { GnmFont *font; GnmFont key; if (font_name == NULL) { g_warning ("font_name == NULL, using %s", DEFAULT_FONT); font_name = DEFAULT_FONT; } if (size_pts <= 0) { g_warning ("font_size <= 0, using %f", DEFAULT_SIZE); size_pts = DEFAULT_SIZE; } /* This cast does not mean we will change the name. */ key.font_name = (char *)font_name; key.size_pts = size_pts; key.is_bold = bold; key.is_italic = italic; key.context = context; font = (GnmFont *) g_hash_table_lookup (style_font_hash, &key); if (font == NULL) { PangoFontDescription *desc; PangoFont *pango_font; if (g_hash_table_lookup (style_font_negative_hash, &key)) return NULL; font = g_new0 (GnmFont, 1); font->font_name = g_strdup (font_name); font->size_pts = size_pts; font->is_bold = bold; font->is_italic = italic; font->context = g_object_ref (context); /* One reference for the cache, one for the caller. */ font->ref_count = 2; desc = pango_font_description_new (); pango_font_description_set_family (desc, font_name); pango_font_description_set_weight (desc, bold ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL); pango_font_description_set_style (desc, italic ? PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL); pango_font_description_set_size (desc, size_pts * PANGO_SCALE); pango_font = pango_context_load_font (context, desc); if (pango_font == NULL) { /* if we fail, try to be smart and map to something similar */ char const *sub = get_substitute_font (font_name); if (sub != NULL) { pango_font_description_set_family (desc, font_name); pango_font = pango_context_load_font (context, desc); } if (pango_font == NULL) { pango_font_description_free (desc); g_hash_table_insert (style_font_negative_hash, font, font); return NULL; } } if (pango_font) g_object_unref (pango_font); font->go.font = go_font_new_by_desc (desc); font->go.metrics = go_font_metrics_new (context, font->go.font); g_hash_table_insert (style_font_hash, font, font); } else font->ref_count++; #ifdef DEBUG_REF_COUNT g_message (__FUNCTION__ " font=%p name=%s%s%s ref_count=%d\n", font, font->font_name, font->is_bold ? " bold" : "", font->is_italic ? " italic" : "", font->ref_count); #endif return font; }
bool TextSurface::render (const CompText::Attrib &attrib, const CompString &text) { int width, height, layoutWidth; if (!valid ()) return false; pango_font_description_set_family (font, attrib.family); pango_font_description_set_absolute_size (font, attrib.size * PANGO_SCALE); pango_font_description_set_style (font, PANGO_STYLE_NORMAL); if (attrib.flags & CompText::StyleBold) pango_font_description_set_weight (font, PANGO_WEIGHT_BOLD); if (attrib.flags & CompText::StyleItalic) pango_font_description_set_style (font, PANGO_STYLE_ITALIC); pango_layout_set_font_description (layout, font); if (attrib.flags & CompText::Ellipsized) pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_END); pango_layout_set_auto_dir (layout, false); pango_layout_set_text (layout, text.c_str (), -1); pango_layout_get_pixel_size (layout, &width, &height); if (attrib.flags & CompText::WithBackground) { width += 2 * attrib.bgHMargin; height += 2 * attrib.bgVMargin; } width = MIN (attrib.maxWidth, width); height = MIN (attrib.maxHeight, height); /* update the size of the pango layout */ layoutWidth = attrib.maxWidth; if (attrib.flags & CompText::WithBackground) layoutWidth -= 2 * attrib.bgHMargin; pango_layout_set_width (layout, layoutWidth * PANGO_SCALE); if (!update (width, height)) return false; pango_cairo_update_layout (cr, layout); cairo_save (cr); cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR); cairo_paint (cr); cairo_restore (cr); cairo_set_operator (cr, CAIRO_OPERATOR_OVER); if (attrib.flags & CompText::WithBackground) { drawBackground (0, 0, width, height, MIN (attrib.bgHMargin, attrib.bgVMargin)); cairo_set_source_rgba (cr, attrib.bgColor[0] / 65535.0, attrib.bgColor[1] / 65535.0, attrib.bgColor[2] / 65535.0, attrib.bgColor[3] / 65535.0); cairo_fill (cr); cairo_move_to (cr, attrib.bgHMargin, attrib.bgVMargin); } cairo_set_source_rgba (cr, attrib.color[0] / 65535.0, attrib.color[1] / 65535.0, attrib.color[2] / 65535.0, attrib.color[3] / 65535.0); pango_cairo_show_layout (cr, layout); return true; }
cairo_surface_t* render_text_to_surface (gchar* text, gint width, gint height, const cairo_font_options_t* font_opts, gdouble dpi) { cairo_surface_t* surface; cairo_t* cr; PangoFontDescription* desc; PangoLayout* layout; // sanity check if (!text || width <= 0 || height <= 0) return NULL; // create surface surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, width, height); if (cairo_surface_status (surface) != CAIRO_STATUS_SUCCESS) return NULL; // create context cr = cairo_create (surface); if (cairo_status (cr) != CAIRO_STATUS_SUCCESS) { cairo_surface_destroy (surface); return NULL; } // clear context cairo_scale (cr, 1.0f, 1.0f); cairo_set_operator (cr, CAIRO_OPERATOR_CLEAR); cairo_paint (cr); // layout = pango_cairo_create_layout (cr); desc = pango_font_description_new (); pango_font_description_set_size (desc, 12 * PANGO_SCALE); pango_font_description_set_family_static (desc, "Candara"); pango_font_description_set_weight (desc, PANGO_WEIGHT_NORMAL); pango_font_description_set_style (desc, PANGO_STYLE_NORMAL); pango_layout_set_wrap (layout, PANGO_WRAP_WORD); pango_layout_set_font_description (layout, desc); pango_font_description_free (desc); pango_layout_set_width (layout, width * PANGO_SCALE); pango_layout_set_height (layout, height * PANGO_SCALE); pango_layout_set_alignment (layout, PANGO_ALIGN_CENTER); pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_END); // print and layout string (pango-wise) pango_layout_set_text (layout, text, -1); // make sure system-wide font-options like hinting, antialiasing etc. // are taken into account pango_cairo_context_set_font_options (pango_layout_get_context (layout), font_opts); pango_cairo_context_set_resolution (pango_layout_get_context (layout), dpi); pango_layout_context_changed (layout); // draw pango-text to our cairo-context cairo_move_to (cr, 0.0f, 0.0f); cairo_set_operator (cr, CAIRO_OPERATOR_OVER); cairo_set_source_rgba (cr, 1.0f, 1.0f, 1.0f, 1.0f); // this call leaks 3803 bytes, I've no idea how to fix that pango_cairo_show_layout (cr, layout); // clean up g_object_unref (layout); cairo_destroy (cr); return surface; }
gboolean cd_do_render_listing_notification (gpointer pUserData, CDListing *pListing, cairo_t *pCairoContext) { //g_print ("%s ()\n", __func__); int iWidth = pListing->container.iWidth, iHeight = pListing->container.iHeight; int iLeftMargin = myDialogs.dialogTextDescription.iSize + 2, iRightMargin = (myDialogs.dialogTextDescription.iSize + 2) / 2; int iTopMargin = (myDialogs.dialogTextDescription.iSize + 2) + GAP, iBottomMargin = (myDialogs.dialogTextDescription.iSize + 2) * 4 + GAP; CDEntry *pEntry; // on dessine un cadre et un fond double fRadius = MIN (6, myDialogs.dialogTextDescription.iSize/2+1); double fLineWidth = 1.; cairo_set_line_width (pCairoContext, fLineWidth); cairo_save (pCairoContext); cairo_translate (pCairoContext, 0, fLineWidth); cairo_dock_draw_rounded_rectangle (pCairoContext, fRadius, fLineWidth, iWidth - 2 * fRadius - fLineWidth, iTopMargin - GAP); cairo_set_source_rgba (pCairoContext, .8, .8, 1., 1.); cairo_stroke_preserve (pCairoContext); cairo_set_source_rgba (pCairoContext, 1., 1., 1., .7); cairo_fill (pCairoContext); cairo_translate (pCairoContext, 0, iTopMargin + fLineWidth); cairo_dock_draw_rounded_rectangle (pCairoContext, fRadius, fLineWidth, iWidth - 2 * fRadius - fLineWidth, iHeight - iTopMargin - iBottomMargin - GAP); cairo_set_source_rgba (pCairoContext, .8, .8, 1., 1.); cairo_stroke_preserve (pCairoContext); cairo_set_source_rgba (pCairoContext, 1., 1., 1., .7); cairo_fill (pCairoContext); cairo_translate (pCairoContext, 0, iHeight - iTopMargin - 2*fLineWidth - iBottomMargin + GAP); cairo_dock_draw_rounded_rectangle (pCairoContext, fRadius, fLineWidth, iWidth - 2 * fRadius - fLineWidth, iBottomMargin - GAP - fLineWidth); cairo_set_source_rgba (pCairoContext, .8, .8, 1., 1.); cairo_stroke_preserve (pCairoContext); cairo_set_source_rgba (pCairoContext, 1., 1., 1., .7); cairo_fill (pCairoContext); cairo_restore (pCairoContext); PangoLayout *pLayout = pango_cairo_create_layout (pCairoContext); PangoFontDescription *pDesc = pango_font_description_new (); pango_font_description_set_absolute_size (pDesc, myDialogs.dialogTextDescription.iSize * PANGO_SCALE); pango_font_description_set_family_static (pDesc, myDialogs.dialogTextDescription.cFont); pango_font_description_set_weight (pDesc, myDialogs.dialogTextDescription.iWeight); pango_font_description_set_style (pDesc, myLabels.iconTextDescription.iStyle); pango_layout_set_font_description (pLayout, pDesc); pango_font_description_free (pDesc); // on dessine les entrees. if (pListing->pEntries != NULL) { // on dessine chaque entree. int iNbSteps = _listing_compute_nb_steps (pListing); // nb d'etapes pour l'apparition du texte. int iOffsetX = NB_STEPS_FOR_1_ENTRY - (iNbSteps - pListing->iAppearanceAnimationCount) - 1; if (pListing->iNbEntries >= myConfig.iNbLinesInListing) iOffsetX += myConfig.iNbLinesInListing/4*NB_STEPS_LATE; // permet de donner une transparence aux 25% dernieres lignes. double dx, dy, dm = myConfig.iNbLinesInListing * (myDialogs.dialogTextDescription.iSize + 2) / 2; dm = 0; dy = iTopMargin - pListing->fCurrentOffset + 1 + dm; double ymax = MIN (iTopMargin + pListing->iNbEntries * (myDialogs.dialogTextDescription.iSize + 2), iHeight - iBottomMargin); GList *e; for (e = pListing->pEntries; e != NULL; e = e->next) { if (iOffsetX >= NB_STEPS_FOR_1_ENTRY) // en dehors a droite a partir de celui-ci. break ; pEntry = e->data; if (pEntry->bHidden) continue ; dx = myDialogs.dialogTextDescription.iSize + 2; // marge a gauche. //if (iOffsetX > 0 && pListing->iAppearanceAnimationCount > 0) // dx += (double) iOffsetX * (iWidth - (myDialogs.dialogTextDescription.iSize + 2)) / NB_STEPS_FOR_1_ENTRY; dy += (myDialogs.dialogTextDescription.iSize + 2); while (dy + myDialogs.dialogTextDescription.iSize + 2 <= iTopMargin + 1) dy += pListing->iNbEntries * (myDialogs.dialogTextDescription.iSize + 2); while (dy > ymax) dy -= pListing->iNbEntries * (myDialogs.dialogTextDescription.iSize + 2); if (dy > ymax || dy + myDialogs.dialogTextDescription.iSize + 2 <= iTopMargin + 1) continue; cairo_save (pCairoContext); cairo_translate (pCairoContext, dx, dy); // on fait un clip si necessaire. if (dy + myDialogs.dialogTextDescription.iSize + 2 > iHeight - iBottomMargin || dy < iTopMargin) // cette entree n'est que partiellement visible. { if (dy < iTopMargin) // elle depasse en haut. cairo_rectangle (pCairoContext, -iLeftMargin, iTopMargin - dy, iWidth, myDialogs.dialogTextDescription.iSize + 2 -(iTopMargin - dy)); else // elle depasse en bas. cairo_rectangle (pCairoContext, -iLeftMargin, 0, iWidth, iHeight - iBottomMargin - dy); cairo_clip (pCairoContext); } // on dessine l'icone. if (pEntry->pIconSurface != NULL) { cairo_set_source_surface (pCairoContext, pEntry->pIconSurface, - iLeftMargin + 1, 0.); cairo_paint (pCairoContext); } // on souligne l'entree courante. if (e == pListing->pCurrentEntry) { double f = 1. - (double) pListing->iCurrentEntryAnimationCount / NB_STEPS_FOR_CURRENT_ENTRY; if (f != 0) { cairo_save (pCairoContext); double rx = .5*(iWidth - iLeftMargin - iRightMargin); double ry = .5*(myDialogs.dialogTextDescription.iSize + 2); cairo_pattern_t *pPattern = cairo_pattern_create_radial (ry, ry, 0., ry, ry, f * ry); cairo_pattern_set_extend (pPattern, CAIRO_EXTEND_NONE); cairo_pattern_add_color_stop_rgba (pPattern, 0., 0., 0., 1., .3); cairo_pattern_add_color_stop_rgba (pPattern, 1., 0., 0., 0., 0.); cairo_scale (pCairoContext, rx/ry, 1.); cairo_set_source (pCairoContext, pPattern); cairo_paint (pCairoContext); cairo_pattern_destroy (pPattern); cairo_restore (pCairoContext); // on dessine l'indicateur de sous-listing. if (pEntry->list != NULL) { cairo_set_source_rgba (pCairoContext, 0., 0., 0., f); cairo_move_to (pCairoContext, iWidth - iLeftMargin - iRightMargin, myDialogs.dialogTextDescription.iSize/4); cairo_rel_line_to (pCairoContext, iRightMargin, myDialogs.dialogTextDescription.iSize/4); cairo_rel_line_to (pCairoContext, -iRightMargin, myDialogs.dialogTextDescription.iSize/4); cairo_close_path (pCairoContext); cairo_stroke (pCairoContext); } } } // on dessine le texte. cairo_set_source_rgba (pCairoContext, 0., 0., 0., 1. - (double) iOffsetX / NB_STEPS_FOR_1_ENTRY); pango_layout_set_text (pLayout, pEntry->cName, -1); pango_cairo_show_layout (pCairoContext, pLayout); // on separe la 1ere entree de la derniere. if (e->prev == NULL) { cairo_set_source_rgba (pCairoContext, 0., 0., 0., .5); cairo_move_to (pCairoContext, 0., 1.); cairo_rel_line_to (pCairoContext, iWidth - iLeftMargin - iRightMargin, 0.); double dashes = 2.; cairo_set_dash (pCairoContext, &dashes, 1, 0.); cairo_stroke (pCairoContext); cairo_set_dash (pCairoContext, &dashes, 0, 0.); } cairo_restore (pCairoContext); iOffsetX += NB_STEPS_LATE; } // on dessine le chemin de l'entree courante. if (pListing->pCurrentEntry) { pEntry = pListing->pCurrentEntry->data; cairo_save (pCairoContext); cairo_set_source_rgb (pCairoContext, 0., 0., 0.); cairo_translate (pCairoContext, fRadius - pListing->iTitleOffset, 0.); pango_layout_set_text (pLayout, pEntry->cPath ? pEntry->cPath : pEntry->cName, -1); PangoRectangle ink, log; pango_layout_get_pixel_extents (pLayout, &ink, &log); pListing->iTitleWidth = ink.width; pango_cairo_show_layout (pCairoContext, pLayout); cairo_restore (pCairoContext); } } // on dessine l'etat de la recherche. cairo_translate (pCairoContext, 0, iHeight - iBottomMargin); cairo_set_source_surface (pCairoContext, myData.pScoobySurface, 0., 0.); cairo_paint (pCairoContext); cairo_set_source_rgb (pCairoContext, 0., 0., 0.); cairo_translate (pCairoContext, 2 * (myDialogs.dialogTextDescription.iSize + 2), GAP); if (myData.cStatus != NULL) { pango_layout_set_text (pLayout, myData.cStatus, -1); } pango_cairo_show_layout (pCairoContext, pLayout); // on dessine le filtre. cairo_translate (pCairoContext, 0., myDialogs.dialogTextDescription.iSize + 2); cairo_set_source_surface (pCairoContext, (myData.iCurrentFilter & DO_MATCH_CASE) ? myData.pActiveButtonSurface : myData.pInactiveButtonSurface, 0., 0.); cairo_paint (pCairoContext); cairo_set_source_rgb (pCairoContext, 0., 0., 0.); pango_layout_set_text (pLayout, D_("(F1) Match case"), -1); pango_cairo_show_layout (pCairoContext, pLayout); cairo_translate (pCairoContext, iWidth/3, 0.); cairo_set_source_surface (pCairoContext, (myData.iCurrentFilter & DO_TYPE_MUSIC) ? myData.pActiveButtonSurface : myData.pInactiveButtonSurface, 0., 0.); cairo_paint (pCairoContext); cairo_set_source_rgb (pCairoContext, 0., 0., 0.); pango_layout_set_text (pLayout, D_("(F2) Music"), -1); pango_cairo_show_layout (pCairoContext, pLayout); cairo_translate (pCairoContext, iWidth/3, 0.); cairo_set_source_surface (pCairoContext, (myData.iCurrentFilter & DO_TYPE_IMAGE) ? myData.pActiveButtonSurface : myData.pInactiveButtonSurface, 0., 0.); cairo_paint (pCairoContext); cairo_set_source_rgb (pCairoContext, 0., 0., 0.); pango_layout_set_text (pLayout, D_("(F3) Image"), -1); pango_cairo_show_layout (pCairoContext, pLayout); cairo_translate (pCairoContext, -2*iWidth/3, myDialogs.dialogTextDescription.iSize + 2); cairo_set_source_surface (pCairoContext, (myData.iCurrentFilter & DO_TYPE_VIDEO) ? myData.pActiveButtonSurface : myData.pInactiveButtonSurface, 0., 0.); cairo_paint (pCairoContext); cairo_set_source_rgb (pCairoContext, 0., 0., 0.); pango_layout_set_text (pLayout, D_("(F4) Video"), -1); pango_cairo_show_layout (pCairoContext, pLayout); cairo_translate (pCairoContext, iWidth/3, 0.); cairo_set_source_surface (pCairoContext, (myData.iCurrentFilter & DO_TYPE_TEXT) ? myData.pActiveButtonSurface : myData.pInactiveButtonSurface, 0., 0.); cairo_paint (pCairoContext); cairo_set_source_rgb (pCairoContext, 0., 0., 0.); pango_layout_set_text (pLayout, D_("(F5) Text"), -1); pango_cairo_show_layout (pCairoContext, pLayout); cairo_translate (pCairoContext, iWidth/3, 0.); cairo_set_source_surface (pCairoContext, (myData.iCurrentFilter & DO_TYPE_HTML) ? myData.pActiveButtonSurface : myData.pInactiveButtonSurface, 0., 0.); cairo_paint (pCairoContext); cairo_set_source_rgb (pCairoContext, 0., 0., 0.); pango_layout_set_text (pLayout, D_("(F6) Html"), -1); pango_cairo_show_layout (pCairoContext, pLayout); cairo_translate (pCairoContext, -2*iWidth/3, myDialogs.dialogTextDescription.iSize + 2); cairo_set_source_surface (pCairoContext, (myData.iCurrentFilter & DO_TYPE_SOURCE) ? myData.pActiveButtonSurface : myData.pInactiveButtonSurface, 0., 0.); cairo_paint (pCairoContext); cairo_set_source_rgb (pCairoContext, 0., 0., 0.); pango_layout_set_text (pLayout, D_("(F7) Sources"), -1); pango_cairo_show_layout (pCairoContext, pLayout); g_object_unref (pLayout); }
static void freetuxtv_cellrenderer_channelslist_render (GtkCellRenderer *cell, GdkWindow *window, GtkWidget *widget, GdkRectangle *background_area, GdkRectangle *cell_area, GdkRectangle *expose_area, guint flags) #endif { FreetuxTVCellRendererChannelsList *self = FREETUXTV_CELLRENDERER_CHANNELSLIST (cell); gint width, height; PangoLayout *layout; gboolean is_selected = FALSE; gboolean is_playing = FALSE; if ((flags & GTK_CELL_RENDERER_SELECTED) != 0){ is_selected = TRUE; } if(self->type == CELLRENDERER_TYPE_CHANNEL){ if(self->is_playing){ is_playing = TRUE; } } #if GTK_API_VERSION == 3 // Set the cell state GtkStateFlags state = GTK_STATE_FLAG_NORMAL; if(is_selected){ if(self->type == CELLRENDERER_TYPE_CHANNEL){ state = GTK_STATE_FLAG_SELECTED; }else{ state = GTK_STATE_FLAG_ACTIVE; } } // Define the style of the row. GtkStyleContext *pStyleContext; pStyleContext = gtk_widget_get_style_context (GTK_WIDGET(widget)); gtk_style_context_save(pStyleContext); gtk_style_context_set_state(pStyleContext, state); if(self->type == CELLRENDERER_TYPE_CHANNEL){ gtk_style_context_add_class (pStyleContext, GTK_STYLE_CLASS_CELL); }else{ gtk_style_context_add_class (pStyleContext, GTK_STYLE_CLASS_BUTTON); } freetuxtv_cellrenderer_channelslist_get_preferred_width(cell, widget, NULL, &width); freetuxtv_cellrenderer_channelslist_get_preferred_height_for_width(cell, widget, width, NULL, &height); #else GtkStyle* pStyle; pStyle = widget->style; GtkStateType state; state = GTK_STATE_NORMAL; if(is_selected){ state = GTK_STATE_SELECTED; } freetuxtv_cellrenderer_channelslist_get_size (cell, widget, cell_area, NULL, NULL, &width, &height); #endif // Build the layout layout = gtk_widget_create_pango_layout (widget, self->name); //pango_layout_set_width(layout, 700); //pango_layout_set_height(layout, 20); pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_END); if(is_playing){ PangoFontDescription *desc; desc = pango_font_description_new(); pango_font_description_set_weight (desc, PANGO_WEIGHT_BOLD); pango_font_description_set_style (desc, PANGO_STYLE_ITALIC); pango_layout_set_font_description (layout, desc); pango_font_description_free(desc); } // gtk_paint_flat_box (widget->style, window, GTK_STATE_SELECTED, // GTK_SHADOW_NONE , NULL, widget, // NULL, // 0, cell_area->y, // cell_area->x + width, cell_area->height); // gtk_paint_hline (widget->style, window, state, // NULL, widget, NULL, // 0, widget->allocation.width, cell_area->y); // gtk_paint_hline (widget->style, window, state, // NULL, widget, NULL, // cell_area->x, cell_area->width, cell_area->y + 2); // gtk_paint_hline (widget->style, window, state, // NULL, widget, NULL, // 0, 176, cell_area->y + 3); GdkPixbuf* logo; // If the cell contain a channel if(self->type == CELLRENDERER_TYPE_CHANNEL){ // Backgroung of the cell #if GTK_API_VERSION == 3 gtk_style_context_set_state (pStyleContext, state); // gtk_style_context_set_background (pStyleContext, window); // This block the main loop gtk_render_background (pStyleContext, cr, 0, cell_area->y, cell_area->x + width, cell_area->height); gtk_render_frame (pStyleContext, cr, 0, cell_area->y, cell_area->x + width, cell_area->height); #else if(state != GTK_STATE_NORMAL){ // gtk_style_set_background (pStyle, window, state); // This block the main loop gtk_style_apply_default_background (pStyle, window, TRUE, state, NULL, 0, cell_area->y, cell_area->x + width, cell_area->height); } #endif //static int count = 0; //count++; //g_print("cell(%d) : %d %d\n", count, cell_area->x, width); // Display the logo and text of the cell logo = gdk_pixbuf_new_from_file(self->logo, NULL); int cell_xpad; int cell_ypad; #if GTK_API_VERSION == 3 gtk_cell_renderer_get_padding (cell, &cell_xpad, &cell_ypad); // Render the logo gdk_cairo_set_source_pixbuf(cr, logo, (double)cell_xpad + 1.0, cell_area->y + (double)cell_ypad + 1.0); cairo_paint(cr); // Render the channel name gtk_render_layout (pStyleContext, cr, cell_xpad * 2 + gdk_pixbuf_get_width(logo) + 5, cell_area->y + 15, layout); #else cell_xpad = cell->xpad; cell_ypad = cell->ypad; // Render the logo gdk_draw_pixbuf (GDK_DRAWABLE(window), NULL, logo, 0, 0, cell_xpad + 1, cell_area->y + cell_ypad + 1, -1, -1, GDK_RGB_DITHER_NONE, 0,0); // Render the channel name gtk_paint_layout (widget->style, window, state, TRUE, NULL, widget, NULL, cell->xpad * 2 + gdk_pixbuf_get_width(logo) + 5, cell_area->y + 15, layout); #endif if(logo){ g_object_unref(logo); logo = NULL; } } // If the cell contain a group if(self->type == CELLRENDERER_TYPE_CHANNELS_GROUP){ #if GTK_API_VERSION == 3 int x = background_area->x; int y = background_area->y; width = background_area->width; height = background_area->height; // Background of the cell gtk_render_background (pStyleContext, cr, x, y, width, height); gtk_render_frame (pStyleContext, cr, x, y, width, height); //g_print("cell_bg %s : x=%d, y=%d\n", self->name, background_area->x, background_area->y); //g_print("cell %s : x=%d, y=%d, w=%d, h=%d\n", self->name, x, y, width, height); // Render the group name gtk_render_layout (pStyleContext, cr, cell_area->x, cell_area->y + 3, layout); #else // Background of the cell gtk_style_apply_default_background (widget->style, window, TRUE, state, NULL, 0, cell_area->y, cell_area->x + width, cell_area->height); // Render the group name gtk_paint_layout (widget->style, window, state, TRUE, NULL, widget, NULL, cell_area->x, cell_area->y + 3, layout); #endif } #if GTK_API_VERSION == 3 gtk_style_context_restore(pStyleContext); #endif }
void wxSVGCanvasTextCairo::InitText(const wxString& text, const wxCSSStyleDeclaration& style, wxSVGMatrix* matrix) { BeginChar(matrix); // create path from text cairo_t* cr = ((wxSVGCanvasPathCairo*) m_char->path)->GetCr(); #if defined(__WXMSW__) || defined(__WXMAC__) int size = (int) style.GetFontSize(); int fstyle = style.GetFontStyle() == wxCSS_VALUE_ITALIC ? wxFONTSTYLE_ITALIC : (style.GetFontStyle() == wxCSS_VALUE_OBLIQUE ? wxFONTSTYLE_SLANT : wxFONTSTYLE_NORMAL); wxFontWeight weight = style.GetFontWeight() == wxCSS_VALUE_BOLD ? wxFONTWEIGHT_BOLD : style.GetFontWeight() == wxCSS_VALUE_BOLDER ? wxFONTWEIGHT_MAX : style.GetFontWeight() == wxCSS_VALUE_LIGHTER ? wxFONTWEIGHT_LIGHT : wxFONTWEIGHT_NORMAL; wxFont fnt(size, wxFONTFAMILY_DEFAULT, fstyle, weight, false, style.GetFontFamily()); #ifdef __WXMSW__ HFONT hfont = (HFONT) fnt.GetResourceHandle(); cairo_set_font_face(cr, cairo_win32_font_face_create_for_hfont(hfont)); #else CGFontRef cgFont = fnt.OSXGetCGFont(); cairo_set_font_face(cr, cairo_quartz_font_face_create_for_cgfont(cgFont)); #endif cairo_set_font_size(cr, style.GetFontSize()); cairo_font_extents_t fextents; cairo_font_extents(cr, &fextents); double maxWidth = 0; if (style.GetTextAnchor() == wxCSS_VALUE_MIDDLE || style.GetTextAnchor() == wxCSS_VALUE_END) { wxStringTokenizer tokenzr(text, wxT("\n")); while (tokenzr.HasMoreTokens()) { wxString token = tokenzr.GetNextToken(); cairo_text_extents_t extents; cairo_text_extents(cr, (const char*) token.utf8_str(), &extents); if (maxWidth < extents.width) maxWidth = extents.width; } } wxStringTokenizer tokenzr(text, wxT("\n")); double x_advance = 0; double width = 0; double height = 0; double y = 0; while (tokenzr.HasMoreTokens()) { wxString token = tokenzr.GetNextToken(); // get text extents cairo_text_extents_t extents; cairo_text_extents(cr, (const char*) token.utf8_str(), &extents); double x = style.GetTextAnchor() == wxCSS_VALUE_END ? maxWidth - extents.width : style.GetTextAnchor() == wxCSS_VALUE_MIDDLE ? (maxWidth - extents.width) / 2 : 0; m_char->path->MoveTo(m_tx + x, m_ty + y); cairo_text_path(cr, (const char*) token.utf8_str()); if (x_advance < extents.x_advance) x_advance = extents.x_advance; if (width < extents.width) width = extents.width; height += fextents.height; if (tokenzr.HasMoreTokens()) y += fextents.height; } // set bbox m_char->bbox = wxSVGRect(m_tx, m_ty, width, height); // increase current position (m_tx) if (style.GetTextAnchor() == wxCSS_VALUE_MIDDLE || style.GetTextAnchor() == wxCSS_VALUE_END) { wxSVGRect bbox = m_char->path->GetResultBBox(style); m_tx += x_advance > bbox.GetWidth() ? x_advance : bbox.GetWidth(); } else m_tx += x_advance; #else PangoLayout* layout = pango_cairo_create_layout(cr); PangoFontDescription* font = pango_font_description_new(); pango_font_description_set_family(font, style.GetFontFamily().ToAscii()); pango_font_description_set_weight(font, style.GetFontWeight() == wxCSS_VALUE_BOLD ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL); pango_font_description_set_style(font, style.GetFontStyle() == wxCSS_VALUE_ITALIC ? PANGO_STYLE_ITALIC : (style.GetFontStyle() == wxCSS_VALUE_OBLIQUE ? PANGO_STYLE_OBLIQUE : PANGO_STYLE_NORMAL)); pango_font_description_set_absolute_size(font, style.GetFontSize() * PANGO_SCALE); PangoContext* ctx = pango_layout_get_context(layout); PangoFont* f = pango_context_load_font(ctx, font); if (f == NULL) pango_font_description_set_style(font, PANGO_STYLE_NORMAL); pango_layout_set_font_description(layout, font); if (style.GetTextAnchor() != wxCSS_VALUE_START) pango_layout_set_alignment(layout, style.GetTextAnchor() == wxCSS_VALUE_MIDDLE ? PANGO_ALIGN_CENTER : PANGO_ALIGN_RIGHT); pango_layout_set_text(layout, (const char*) text.utf8_str(), -1); int baseline = pango_layout_get_baseline(layout); m_char->path->MoveTo(m_tx, m_ty - ((double)baseline / PANGO_SCALE)); pango_cairo_layout_path(cr, layout); // set bbox and increase current position (m_tx) int lwidth, lheight; pango_layout_get_size(layout, &lwidth, &lheight); double width = ((double)lwidth / PANGO_SCALE); double height = ((double)lheight / PANGO_SCALE); m_char->bbox = wxSVGRect(m_tx, m_ty, width, height); if (style.GetTextAnchor() == wxCSS_VALUE_MIDDLE || style.GetTextAnchor() == wxCSS_VALUE_END) { wxSVGRect bbox = m_char->path->GetResultBBox(style); m_tx += width > bbox.GetWidth() ? width : bbox.GetWidth(); } else m_tx += width; g_object_unref(layout); pango_font_description_free(font); #endif }
font_instance *font_factory::Face(char const *family, NRTypePosDef apos) { PangoFontDescription *temp_descr = pango_font_description_new(); pango_font_description_set_family(temp_descr, family); if ( apos.variant == NR_POS_VARIANT_SMALLCAPS ) { pango_font_description_set_variant(temp_descr, PANGO_VARIANT_SMALL_CAPS); } else { pango_font_description_set_variant(temp_descr, PANGO_VARIANT_NORMAL); } if ( apos.italic ) { pango_font_description_set_style(temp_descr, PANGO_STYLE_ITALIC); } else if ( apos.oblique ) { pango_font_description_set_style(temp_descr, PANGO_STYLE_OBLIQUE); } else { pango_font_description_set_style(temp_descr, PANGO_STYLE_NORMAL); } if ( apos.weight <= NR_POS_WEIGHT_THIN ) { pango_font_description_set_weight(temp_descr, PANGO_WEIGHT_THIN); } else if ( apos.weight <= NR_POS_WEIGHT_ULTRA_LIGHT ) { pango_font_description_set_weight(temp_descr, PANGO_WEIGHT_ULTRALIGHT); } else if ( apos.weight <= NR_POS_WEIGHT_LIGHT ) { pango_font_description_set_weight(temp_descr, PANGO_WEIGHT_LIGHT); } else if ( apos.weight <= NR_POS_WEIGHT_BOOK ) { pango_font_description_set_weight(temp_descr, PANGO_WEIGHT_BOOK); } else if ( apos.weight <= NR_POS_WEIGHT_NORMAL ) { pango_font_description_set_weight(temp_descr, PANGO_WEIGHT_NORMAL); } else if ( apos.weight <= NR_POS_WEIGHT_MEDIUM ) { pango_font_description_set_weight(temp_descr, PANGO_WEIGHT_MEDIUM); } else if ( apos.weight <= NR_POS_WEIGHT_SEMIBOLD ) { pango_font_description_set_weight(temp_descr, PANGO_WEIGHT_SEMIBOLD); } else if ( apos.weight <= NR_POS_WEIGHT_BOLD ) { pango_font_description_set_weight(temp_descr, PANGO_WEIGHT_BOLD); } else if ( apos.weight <= NR_POS_WEIGHT_ULTRA_BOLD ) { pango_font_description_set_weight(temp_descr, PANGO_WEIGHT_ULTRABOLD); } else { pango_font_description_set_weight(temp_descr, PANGO_WEIGHT_HEAVY); } // PANGO_WIEGHT_ULTRAHEAVY not used (not CSS2) if ( apos.stretch <= NR_POS_STRETCH_ULTRA_CONDENSED ) { pango_font_description_set_stretch(temp_descr, PANGO_STRETCH_EXTRA_CONDENSED); } else if ( apos.stretch <= NR_POS_STRETCH_CONDENSED ) { pango_font_description_set_stretch(temp_descr, PANGO_STRETCH_CONDENSED); } else if ( apos.stretch <= NR_POS_STRETCH_SEMI_CONDENSED ) { pango_font_description_set_stretch(temp_descr, PANGO_STRETCH_SEMI_CONDENSED); } else if ( apos.stretch <= NR_POS_STRETCH_NORMAL ) { pango_font_description_set_stretch(temp_descr, PANGO_STRETCH_NORMAL); } else if ( apos.stretch <= NR_POS_STRETCH_SEMI_EXPANDED ) { pango_font_description_set_stretch(temp_descr, PANGO_STRETCH_SEMI_EXPANDED); } else if ( apos.stretch <= NR_POS_STRETCH_EXPANDED ) { pango_font_description_set_stretch(temp_descr, PANGO_STRETCH_EXPANDED); } else { pango_font_description_set_stretch(temp_descr, PANGO_STRETCH_EXTRA_EXPANDED); } font_instance *res = Face(temp_descr); pango_font_description_free(temp_descr); return res; }
PangoFont* createPangoFontForFont(const wxFont* wxfont) { ASSERT(wxfont && wxfont->Ok()); const char* face = wxfont->GetFaceName().mb_str(wxConvUTF8); char const* families[] = { face, 0 }; switch (wxfont->GetFamily()) { case wxFONTFAMILY_ROMAN: families[1] = "serif"; break; case wxFONTFAMILY_SWISS: families[1] = "sans"; break; case wxFONTFAMILY_MODERN: families[1] = "monospace"; break; default: families[1] = "sans"; } PangoFontDescription* description = pango_font_description_new(); pango_font_description_set_absolute_size(description, wxfont->GetPointSize() * PANGO_SCALE); PangoFont* pangoFont = 0; PangoContext* pangoContext = 0; switch (wxfont->GetWeight()) { case wxFONTWEIGHT_LIGHT: pango_font_description_set_weight(description, PANGO_WEIGHT_LIGHT); break; case wxFONTWEIGHT_NORMAL: pango_font_description_set_weight(description, PANGO_WEIGHT_NORMAL); break; case wxFONTWEIGHT_BOLD: pango_font_description_set_weight(description, PANGO_WEIGHT_BOLD); break; } switch (wxfont->GetStyle()) { case wxFONTSTYLE_NORMAL: pango_font_description_set_style(description, PANGO_STYLE_NORMAL); break; case wxFONTSTYLE_ITALIC: pango_font_description_set_style(description, PANGO_STYLE_ITALIC); break; case wxFONTSTYLE_SLANT: pango_font_description_set_style(description, PANGO_STYLE_OBLIQUE); break; } PangoFontMap* fontMap = pangoFontMap(); pangoContext = pango_cairo_font_map_create_context(PANGO_CAIRO_FONT_MAP(fontMap)); for (unsigned i = 0; !pangoFont && i < G_N_ELEMENTS(families); i++) { pango_font_description_set_family(description, families[i]); pango_context_set_font_description(pangoContext, description); pangoFont = pango_font_map_load_font(fontMap, pangoContext, description); } pango_font_description_free(description); return pangoFont; }
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkFontPeer_setFont (JNIEnv *env, jobject self, jstring family_name_str, jint style_int, jint size, jboolean useGraphics2D) { struct peerfont *pfont = NULL; char const *family_name = NULL; enum java_awt_font_style style; PangoFT2FontMap *ft2_map; gdk_threads_enter (); style = (enum java_awt_font_style) style_int; g_assert (self != NULL); pfont = (struct peerfont *)NSA_GET_FONT_PTR (env, self); g_assert (pfont != NULL); if (pfont->ctx != NULL) g_object_unref (pfont->ctx); if (pfont->font != NULL) g_object_unref (pfont->font); if (pfont->desc != NULL) pango_font_description_free (pfont->desc); pfont->desc = pango_font_description_new (); g_assert (pfont->desc != NULL); family_name = (*env)->GetStringUTFChars(env, family_name_str, 0); g_assert (family_name != NULL); pango_font_description_set_family (pfont->desc, family_name); (*env)->ReleaseStringUTFChars(env, family_name_str, family_name); if (style & java_awt_font_BOLD) pango_font_description_set_weight (pfont->desc, PANGO_WEIGHT_BOLD); if (style & java_awt_font_ITALIC) pango_font_description_set_style (pfont->desc, PANGO_STYLE_ITALIC); if (useGraphics2D) { pango_font_description_set_size (pfont->desc, size * PANGO_SCALE); if (pfont->ctx == NULL) { ft2_map = PANGO_FT2_FONT_MAP(pango_ft2_font_map_for_display ()); pfont->ctx = pango_ft2_font_map_create_context (ft2_map); } } else { /* GDK uses a slightly different DPI setting. */ pango_font_description_set_size (pfont->desc, size * dpi_conversion_factor); if (pfont->ctx == NULL) pfont->ctx = gdk_pango_context_get(); } g_assert (pfont->ctx != NULL); if (pfont->font != NULL) { g_object_unref (pfont->font); pfont->font = NULL; } pango_context_set_font_description (pfont->ctx, pfont->desc); pango_context_set_language (pfont->ctx, gtk_get_default_language()); pfont->font = pango_context_load_font (pfont->ctx, pfont->desc); g_assert (pfont->font != NULL); if (pfont->layout == NULL) pfont->layout = pango_layout_new (pfont->ctx); g_assert (pfont->layout != NULL); gdk_threads_leave (); }
static PangoLayout * rsvg_text_create_layout (RsvgDrawingCtx * ctx, RsvgState * state, const char *text, PangoContext * context) { PangoFontDescription *font_desc; PangoLayout *layout; PangoAttrList *attr_list; PangoAttribute *attribute; if (state->lang) pango_context_set_language (context, pango_language_from_string (state->lang)); if (state->unicode_bidi == UNICODE_BIDI_OVERRIDE || state->unicode_bidi == UNICODE_BIDI_EMBED) pango_context_set_base_dir (context, state->text_dir); if (PANGO_GRAVITY_IS_VERTICAL (state->text_gravity)) pango_context_set_base_gravity (context, state->text_gravity); font_desc = pango_font_description_copy (pango_context_get_font_description (context)); if (state->font_family) pango_font_description_set_family_static (font_desc, state->font_family); pango_font_description_set_style (font_desc, state->font_style); pango_font_description_set_variant (font_desc, state->font_variant); pango_font_description_set_weight (font_desc, state->font_weight); pango_font_description_set_stretch (font_desc, state->font_stretch); pango_font_description_set_size (font_desc, _rsvg_css_normalize_font_size (state, ctx) * PANGO_SCALE / ctx->dpi_y * 72); layout = pango_layout_new (context); pango_layout_set_font_description (layout, font_desc); pango_font_description_free (font_desc); attr_list = pango_attr_list_new (); attribute = pango_attr_letter_spacing_new (_rsvg_css_normalize_length (&state->letter_spacing, ctx, 'h') * PANGO_SCALE); attribute->start_index = 0; attribute->end_index = G_MAXINT; pango_attr_list_insert (attr_list, attribute); if (state->has_font_decor && text) { if (state->font_decor & TEXT_UNDERLINE) { attribute = pango_attr_underline_new (PANGO_UNDERLINE_SINGLE); attribute->start_index = 0; attribute->end_index = -1; pango_attr_list_insert (attr_list, attribute); } if (state->font_decor & TEXT_STRIKE) { attribute = pango_attr_strikethrough_new (TRUE); attribute->start_index = 0; attribute->end_index = -1; pango_attr_list_insert (attr_list, attribute); } } pango_layout_set_attributes (layout, attr_list); pango_attr_list_unref (attr_list); if (text) pango_layout_set_text (layout, text, -1); else pango_layout_set_text (layout, NULL, 0); pango_layout_set_alignment (layout, (state->text_dir == PANGO_DIRECTION_LTR) ? PANGO_ALIGN_LEFT : PANGO_ALIGN_RIGHT); return layout; }