ttext::ttext() : #if PANGO_VERSION_CHECK(1,22,0) context_(pango_font_map_create_context(pango_cairo_font_map_get_default())), #else context_(pango_cairo_font_map_create_context(( reinterpret_cast<PangoCairoFontMap*>(pango_cairo_font_map_get_default())))), #endif layout_(pango_layout_new(context_)), rect_(), surface_(), #ifdef SDL_GPU texture_(), #endif text_(), markedup_text_(false), link_aware_(false), link_color_(), font_class_(font::FONT_SANS_SERIF), font_size_(14), font_style_(STYLE_NORMAL), foreground_color_(0xFFFFFFFF), // solid white maximum_width_(-1), characters_per_line_(0), maximum_height_(-1), ellipse_mode_(PANGO_ELLIPSIZE_END), alignment_(PANGO_ALIGN_LEFT), maximum_length_(std::string::npos), calculation_dirty_(true), length_(0), surface_dirty_(true), surface_buffer_(nullptr) { // With 72 dpi the sizes are the same as with SDL_TTF so hardcoded. pango_cairo_context_set_resolution(context_, 72.0); pango_layout_set_ellipsize(layout_, ellipse_mode_); pango_layout_set_alignment(layout_, alignment_); pango_layout_set_wrap(layout_, PANGO_WRAP_WORD_CHAR); /* * Set the pango spacing a bit bigger since the default is deemed to small * http://www.wesnoth.org/forum/viewtopic.php?p=358832#p358832 */ pango_layout_set_spacing(layout_, 2 * PANGO_SCALE); cairo_font_options_t *fo = cairo_font_options_create(); cairo_font_options_set_hint_style(fo, CAIRO_HINT_STYLE_FULL); cairo_font_options_set_hint_metrics(fo, CAIRO_HINT_METRICS_ON); #ifdef _WIN32 // Cairo on Windows (at least the latest available version from gtk.org // as of 2014-02-22, version 1.10.2) has issues with ClearType resulting // in glitchy anti-aliasing with CAIRO_ANTIALIAS_SUBPIXEL or // CAIRO_ANTIALIAS_DEFAULT, but not CAIRO_ANTIALIAS_GRAY, so we use that // as a workaround until the Windows package is updated to use a newer // version of Cairo (see Wesnoth bug #21648). cairo_font_options_set_antialias(fo, CAIRO_ANTIALIAS_GRAY); #endif pango_cairo_context_set_font_options(context_, fo); cairo_font_options_destroy(fo); }
/** * _init: * @fo_doc_cairo: #FoDocCairo object to initialise. * * Implements #GInstanceInitFunc for #FoDocCairo. **/ static void _init (FoDocCairo *fo_doc_cairo) { PangoFontMap *font_map = pango_cairo_font_map_get_default (); pango_cairo_font_map_set_resolution ((PangoCairoFontMap*) font_map, 72); FO_DOC (fo_doc_cairo)->pango_context = pango_cairo_font_map_create_context ((PangoCairoFontMap*) font_map); }
// We should create the layout with our actual context but we can't access it from here. static PangoLayout* getDefaultPangoLayout(const TextRun& run) { static PangoFontMap* map = pango_cairo_font_map_get_default(); static PangoContext* pangoContext = pango_cairo_font_map_create_context(PANGO_CAIRO_FONT_MAP(map)); PangoLayout* layout = pango_layout_new(pangoContext); return layout; }
/** * cogl_pango_font_map_create_context: * @fm: a #CoglPangoFontMap * * Creates a new #PangoContext from the passed font map. * * Return value: the newly created #PangoContext * * Since: 1.0 */ PangoContext * cogl_pango_font_map_create_context (CoglPangoFontMap *fm) { g_return_val_if_fail (COGL_PANGO_IS_FONT_MAP (fm), NULL); /* We can just directly use the pango context from the Cairo font map */ return pango_cairo_font_map_create_context (PANGO_CAIRO_FONT_MAP (fm)); }
// We should create the layout with our actual context but we can't access it from here. static PangoLayout* getDefaultPangoLayout(const TextRun& run) { static PangoFontMap* map = pango_cairo_font_map_get_default(); #if PANGO_VERSION_CHECK(1, 21, 5) static PangoContext* pangoContext = pango_font_map_create_context(map); #else // Deprecated in Pango 1.21. static PangoContext* pangoContext = pango_cairo_font_map_create_context(PANGO_CAIRO_FONT_MAP(map)); #endif PangoLayout* layout = pango_layout_new(pangoContext); return layout; }
ttext::ttext() : #if PANGO_VERSION_CHECK(1,22,0) context_(pango_font_map_create_context(pango_cairo_font_map_get_default())), #else context_(pango_cairo_font_map_create_context(( reinterpret_cast<PangoCairoFontMap*>(pango_cairo_font_map_get_default())))), #endif layout_(pango_layout_new(context_)), rect_(), surface_(), text_(), markedup_text_(false), link_aware_(false), link_color_(), font_class_(font::FONT_SANS_SERIF), font_size_(14), font_style_(STYLE_NORMAL), foreground_color_(0xFFFFFFFF), // solid white maximum_width_(-1), characters_per_line_(0), maximum_height_(-1), ellipse_mode_(PANGO_ELLIPSIZE_END), alignment_(PANGO_ALIGN_LEFT), maximum_length_(std::string::npos), calculation_dirty_(true), length_(0), surface_dirty_(true), surface_buffer_(nullptr) { // With 72 dpi the sizes are the same as with SDL_TTF so hardcoded. pango_cairo_context_set_resolution(context_, 72.0); pango_layout_set_ellipsize(layout_, ellipse_mode_); pango_layout_set_alignment(layout_, alignment_); pango_layout_set_wrap(layout_, PANGO_WRAP_WORD_CHAR); /* * Set the pango spacing a bit bigger since the default is deemed to small * http://www.wesnoth.org/forum/viewtopic.php?p=358832#p358832 */ pango_layout_set_spacing(layout_, 4 * PANGO_SCALE); cairo_font_options_t *fo = cairo_font_options_create(); cairo_font_options_set_hint_style(fo, CAIRO_HINT_STYLE_FULL); cairo_font_options_set_hint_metrics(fo, CAIRO_HINT_METRICS_ON); cairo_font_options_set_antialias(fo, CAIRO_ANTIALIAS_DEFAULT); pango_cairo_context_set_font_options(context_, fo); cairo_font_options_destroy(fo); }
/* Create/get a pango context * * On windows we use the win32 context creator, on everything else we * use the cairo one. */ PangoContext * splitter_create_pango_context(void) { #ifdef _WIN32 return pango_win32_get_context(); #else PangoContext *context = NULL; PangoFontMap *fontmap = pango_cairo_font_map_get_default(); context = pango_cairo_font_map_create_context(PANGO_CAIRO_FONT_MAP(fontmap)); g_object_unref(G_OBJECT(fontmap)); return context; #endif }
static void lsm_dom_view_init (LsmDomView *view) { PangoFontMap *font_map; PangoContext *pango_context; cairo_font_options_t *font_options; view->resolution_ppi = LSM_DOM_VIEW_DEFAULT_RESOLUTION; view->viewport_pt.x = 0; view->viewport_pt.y = 0; view->viewport_pt.width = LSM_DOM_VIEW_DEFAULT_VIEWBOX_WIDTH; view->viewport_pt.height = LSM_DOM_VIEW_DEFAULT_VIEWBOX_HEIGHT; view->font_description = pango_font_description_new (); font_map = pango_cairo_font_map_get_default (); #if PANGO_VERSION_CHECK(1,22,0) pango_context = pango_font_map_create_context (font_map); #else pango_context = pango_cairo_font_map_create_context (PANGO_CAIRO_FONT_MAP (font_map)); #endif pango_cairo_context_set_resolution (pango_context, 72.0); view->measure_pango_layout = pango_layout_new (pango_context); font_options = cairo_font_options_create (); cairo_font_options_set_hint_metrics (font_options, CAIRO_HINT_METRICS_OFF); cairo_font_options_set_hint_style (font_options, CAIRO_HINT_STYLE_NONE); pango_cairo_context_set_font_options (pango_context, font_options); cairo_font_options_destroy (font_options); g_object_unref (pango_context); view->pango_layout = NULL; view->cairo = NULL; view->is_vector = FALSE; }
static void hippo_canvas_context_win_init(HippoCanvasContextWin *canvas_win) { PangoFontDescription *desc; canvas_win->pointer = HIPPO_CANVAS_POINTER_UNSET; /* canvas_win->pango = pango_win32_get_context(); */ PangoCairoFontMap *font_map = (PangoCairoFontMap*) pango_cairo_font_map_get_default(); canvas_win->pango = pango_cairo_font_map_create_context(font_map); g_object_unref((void*) font_map); desc = pango_font_description_new(); // Sans is resolved in the pango.aliases we install; since the first element // is already "Arial", we specify just Sans here, rather than the "Arial,sans-serif" // we use in site.css. pango_font_description_set_family_static(desc, "Sans"); pango_font_description_set_absolute_size(desc, 12 * PANGO_SCALE); // FIXME on my laptop (Visual Studio 2005) this has crashed Pango with a g_error(), // but it seems to have mysteriously gone away. pango_context_set_font_description(canvas_win->pango, desc); pango_font_description_free(desc); }
static void hippo_canvas_context_win_init(HippoCanvasContextWin *canvas_win) { PangoFontDescription *desc; canvas_win->pointer = HIPPO_CANVAS_POINTER_UNSET; /* canvas_win->pango = pango_win32_get_context(); */ PangoCairoFontMap *font_map = (PangoCairoFontMap*) pango_cairo_font_map_get_default(); canvas_win->pango = pango_cairo_font_map_create_context(font_map); g_object_unref((void*) font_map); desc = pango_font_description_new(); // Note that this matches the web font in our site.css // We only set Arial instead of Arial, sans-serif because // pango cairo doesn't like a font list here. pango_font_description_set_family_static(desc, "Arial"); pango_font_description_set_absolute_size(desc, 12 * PANGO_SCALE); // FIXME on my laptop (Visual Studio 2005) this has crashed Pango with a g_error(), // but it seems to have mysteriously gone away. pango_context_set_font_description(canvas_win->pango, desc); pango_font_description_free(desc); }
static boolean pango_textlayout(textspan_t * span, char **fontpath) { static char buf[1024]; /* returned in fontpath, only good until next call */ static PangoFontMap *fontmap; static PangoContext *context; static PangoFontDescription *desc; static char *fontname; static double fontsize; static gv_font_map* gv_fmap; char *fnt, *psfnt = NULL; PangoLayout *layout; PangoRectangle logical_rect; cairo_font_options_t* options; PangoFont *font; #ifdef ENABLE_PANGO_MARKUP PangoAttrList *attrs; GError *error = NULL; int flags; #endif char *text; double textlayout_scale; PostscriptAlias *pA; if (!context) { fontmap = pango_cairo_font_map_new(); gv_fmap = get_font_mapping(fontmap); #ifdef HAVE_PANGO_FONT_MAP_CREATE_CONTEXT context = pango_font_map_create_context (fontmap); #else context = pango_cairo_font_map_create_context (PANGO_CAIRO_FONT_MAP(fontmap)); #endif options=cairo_font_options_create(); cairo_font_options_set_antialias(options,CAIRO_ANTIALIAS_GRAY); cairo_font_options_set_hint_style(options,CAIRO_HINT_STYLE_FULL); cairo_font_options_set_hint_metrics(options,CAIRO_HINT_METRICS_ON); cairo_font_options_set_subpixel_order(options,CAIRO_SUBPIXEL_ORDER_BGR); pango_cairo_context_set_font_options(context, options); pango_cairo_context_set_resolution(context, FONT_DPI); cairo_font_options_destroy(options); g_object_unref(fontmap); } if (!fontname || strcmp(fontname, span->font->name) != 0 || fontsize != span->font->size) { fontname = span->font->name; fontsize = span->font->size; pango_font_description_free (desc); pA = span->font->postscript_alias; if (pA) { psfnt = fnt = gv_fmap[pA->xfig_code].gv_font; if(!psfnt) psfnt = fnt = pango_psfontResolve (pA); } else fnt = fontname; desc = pango_font_description_from_string(fnt); /* all text layout is done at a scale of FONT_DPI (nominaly 96.) */ pango_font_description_set_size (desc, (gint)(fontsize * PANGO_SCALE)); if (fontpath && (font = pango_font_map_load_font(fontmap, context, desc))) { /* -v support */ const char *fontclass; fontclass = G_OBJECT_CLASS_NAME(G_OBJECT_GET_CLASS(font)); buf[0] = '\0'; if (psfnt) { strcat(buf, "(ps:pango "); strcat(buf, psfnt); strcat(buf, ") "); } strcat(buf, "("); strcat(buf, fontclass); strcat(buf, ") "); #ifdef HAVE_PANGO_FC_FONT_LOCK_FACE if (strcmp(fontclass, "PangoCairoFcFont") == 0) { FT_Face face; PangoFcFont *fcfont; FT_Stream stream; FT_StreamDesc streamdesc; fcfont = PANGO_FC_FONT(font); face = pango_fc_font_lock_face(fcfont); if (face) { strcat(buf, "\""); strcat(buf, face->family_name); strcat(buf, ", "); strcat(buf, face->style_name); strcat(buf, "\" "); stream = face->stream; if (stream) { streamdesc = stream->pathname; if (streamdesc.pointer) strcat(buf, (char*)streamdesc.pointer); else strcat(buf, "*no pathname available*"); } else strcat(buf, "*no stream available*"); } pango_fc_font_unlock_face(fcfont); } else #endif { PangoFontDescription *tdesc; char *tfont; tdesc = pango_font_describe(font); tfont = pango_font_description_to_string(tdesc); strcat(buf, "\""); strcat(buf, tfont); strcat(buf, "\" "); g_free(tfont); } *fontpath = buf; } } #ifdef ENABLE_PANGO_MARKUP if ((span->font) && (flags = span->font->flags)) { unsigned char buf[BUFSIZ]; agxbuf xb; agxbinit(&xb, BUFSIZ, buf); agxbput(&xb,"<span"); if (flags & HTML_BF) agxbput(&xb," weight=\"bold\""); if (flags & HTML_IF) agxbput(&xb," style=\"italic\""); if (flags & HTML_UL) agxbput(&xb," underline=\"single\""); if (flags & HTML_S) agxbput(&xb," strikethrough=\"true\""); agxbput (&xb,">"); if (flags & HTML_SUP) agxbput(&xb,"<sup>"); if (flags & HTML_SUB) agxbput(&xb,"<sub>"); agxbput (&xb,xml_string0(span->str, TRUE)); if (flags & HTML_SUB) agxbput(&xb,"</sub>"); if (flags & HTML_SUP) agxbput(&xb,"</sup>"); agxbput (&xb,"</span>"); if (!pango_parse_markup (agxbuse(&xb), -1, 0, &attrs, &text, NULL, &error)) { fprintf (stderr, "Error - pango_parse_markup: %s\n", error->message); text = span->str; attrs = NULL; } agxbfree (&xb); } else { text = span->str; attrs = NULL; } #else text = span->str; #endif layout = pango_layout_new (context); span->layout = (void *)layout; /* layout free with textspan - see labels.c */ span->free_layout = pango_free_layout; /* function for freeing pango layout */ pango_layout_set_text (layout, text, -1); pango_layout_set_font_description (layout, desc); #ifdef ENABLE_PANGO_MARKUP if (attrs) pango_layout_set_attributes (layout, attrs); #endif pango_layout_get_extents (layout, NULL, &logical_rect); /* if pango doesn't like the font then it sets width=0 but height = garbage */ if (logical_rect.width == 0) logical_rect.height = 0; textlayout_scale = POINTS_PER_INCH / (FONT_DPI * PANGO_SCALE); span->size.x = (int)(logical_rect.width * textlayout_scale + 1); /* round up so that width/height are never too small */ span->size.y = (int)(logical_rect.height * textlayout_scale + 1); /* FIXME -- Horrible kluge !!! */ /* For now we are using pango for single line blocks only. * The logical_rect.height seems to be too high from the font metrics on some platforms. * Use an assumed height based on the point size. */ span->size.y = (int)(span->font->size * 1.1 + .5); /* The y offset from baseline to 0,0 of the bitmap representation */ #if !defined(WIN32) && defined PANGO_VERSION_MAJOR && (PANGO_VERSION_MAJOR >= 1) span->yoffset_layout = pango_layout_get_baseline (layout) * textlayout_scale; #else { /* do it the hard way on rhel5/centos5 */ PangoLayoutIter *iter = pango_layout_get_iter (layout); span->yoffset_layout = pango_layout_iter_get_baseline (iter) * textlayout_scale; } #endif /* The distance below midline for y centering of text strings */ span->yoffset_centerline = 0.2 * span->font->size; if (logical_rect.width == 0) return FALSE; return TRUE; }
static boolean pango_textlayout(textpara_t * para, char **fontpath) { static char buf[1024]; /* returned in fontpath, only good until next call */ static PangoFontMap *fontmap; static PangoContext *context; static PangoFontDescription *desc; static char *fontname; static double fontsize; static gv_font_map* gv_fmap; char *fnt, *psfnt = NULL; PangoLayout *layout; PangoRectangle logical_rect; cairo_font_options_t* options; PangoFont *font; #ifdef ENABLE_PANGO_MARKUP PangoAttrList *attrs; GError *error = NULL; int flags; #endif char *text; double textlayout_scale; if (!context) { fontmap = pango_cairo_font_map_new(); gv_fmap = get_font_mapping(fontmap); context = pango_cairo_font_map_create_context (PANGO_CAIRO_FONT_MAP(fontmap)); options=cairo_font_options_create(); cairo_font_options_set_antialias(options,CAIRO_ANTIALIAS_GRAY); cairo_font_options_set_hint_style(options,CAIRO_HINT_STYLE_FULL); cairo_font_options_set_hint_metrics(options,CAIRO_HINT_METRICS_ON); cairo_font_options_set_subpixel_order(options,CAIRO_SUBPIXEL_ORDER_BGR); pango_cairo_context_set_font_options(context, options); pango_cairo_context_set_resolution(context, FONT_DPI); cairo_font_options_destroy(options); g_object_unref(fontmap); } if (!fontname || strcmp(fontname, para->fontname) != 0 || fontsize != para->fontsize) { fontname = para->fontname; fontsize = para->fontsize; pango_font_description_free (desc); if (para->postscript_alias) { psfnt = fnt = gv_fmap[para->postscript_alias->xfig_code].gv_font; if(!psfnt) psfnt = fnt = pango_psfontResolve (para->postscript_alias); } else fnt = fontname; desc = pango_font_description_from_string(fnt); /* all text layout is done at a scale of FONT_DPI (nominaly 96.) */ pango_font_description_set_size (desc, (gint)(fontsize * PANGO_SCALE)); if (fontpath && (font = pango_font_map_load_font(fontmap, context, desc))) { /* -v support */ const char *fontclass; fontclass = G_OBJECT_CLASS_NAME(G_OBJECT_GET_CLASS(font)); buf[0] = '\0'; if (psfnt) { strcat(buf, "(ps:pango "); strcat(buf, psfnt); strcat(buf, ") "); } strcat(buf, "("); strcat(buf, fontclass); strcat(buf, ") "); #ifdef HAVE_PANGO_FC_FONT_LOCK_FACE if (strcmp(fontclass, "PangoCairoFcFont") == 0) { FT_Face face; PangoFcFont *fcfont; FT_Stream stream; FT_StreamDesc streamdesc; fcfont = PANGO_FC_FONT(font); face = pango_fc_font_lock_face(fcfont); if (face) { strcat(buf, "\""); strcat(buf, face->family_name); strcat(buf, ", "); strcat(buf, face->style_name); strcat(buf, "\" "); stream = face->stream; if (stream) { streamdesc = stream->pathname; if (streamdesc.pointer) strcat(buf, (char*)streamdesc.pointer); else strcat(buf, "*no pathname available*"); } else strcat(buf, "*no stream available*"); } pango_fc_font_unlock_face(fcfont); } else #endif { PangoFontDescription *tdesc; char *tfont; tdesc = pango_font_describe(font); tfont = pango_font_description_to_string(tdesc); strcat(buf, "\""); strcat(buf, tfont); strcat(buf, "\" "); g_free(tfont); } *fontpath = buf; } } #ifdef ENABLE_PANGO_MARKUP if ((para->font) && (flags = para->font->flags)) { char* markup = N_NEW(strlen(para->str) + sizeof(FULL_MARKUP), char); strcpy(markup,"<span"); if (flags & HTML_BF) strcat(markup," weight=\"bold\""); if (flags & HTML_IF) strcat(markup," style=\"italic\""); if (flags & HTML_UL) strcat(markup," underline=\"single\""); strcat (markup,">"); if (flags & HTML_SUP) strcat(markup,"<sup>"); if (flags & HTML_SUB) strcat(markup,"<sub>"); strcat (markup,para->str); if (flags & HTML_SUB) strcat(markup,"</sub>"); if (flags & HTML_SUP) strcat(markup,"</sup>"); strcat (markup,"</span>"); if (!pango_parse_markup (markup, -1, 0, &attrs, &text, NULL, &error)) { fprintf (stderr, "Error - pango_parse_markup: %s\n", error->message); text = para->str; attrs = NULL; } free (markup); }
GtkWidget *setupLCD(GtkWidget *parent, int rows, int cols, char *font){ int i; int width; int wid, hgt; #ifdef GTK_VER_1_1 static GtkTargetEntry targetlist[] = { /* Target Flags Info */ { "STRING", 0, TARGET_STRING }, { "TEXT", 0, TARGET_TEXT }, { "COMPOUND_TEXT", 0, TARGET_COMPOUND_TEXT } }; static gint ntargets = sizeof(targetlist) / sizeof(targetlist[0]); #endif /* store arguments */ lcdWidth = cols; lcdHeight = rows; #ifdef USE_PANGO lcdDA = gtk_drawing_area_new(); pango_layout = gtk_widget_create_pango_layout(lcdDA, NULL); pango_desc = pango_font_description_from_string(font?font:"Liberation Mono 16"); pango_fontmap = pango_cairo_font_map_get_default(); pango_context = pango_cairo_font_map_create_context( (PangoCairoFontMap *)pango_fontmap ); pango_font = pango_context_load_font(pango_context, pango_desc); pango_metrics = pango_context_get_metrics(pango_context, pango_desc, pango_language_get_default()); fontW = (pango_font_metrics_get_approximate_digit_width(pango_metrics))/PANGO_SCALE; fontH = (pango_font_metrics_get_ascent(pango_metrics) + pango_font_metrics_get_descent(pango_metrics))/PANGO_SCALE; fontD = pango_font_metrics_get_descent(pango_metrics)/PANGO_SCALE; gtk_widget_modify_font(lcdDA, pango_desc); #else fontW = 0; fontH = 0; fontD = 0; /* get a font for the main window */ if(font != NULL){ if(NULL == (lcdFont = gdk_font_load(font))){ fprintf(stderr, "Unable to load font %s.\n", font); exit(0); } } else if(NULL == (lcdFont = gdk_font_load(FONT1)) && NULL == (lcdFont = gdk_font_load(FONT2)) && NULL == (lcdFont = gdk_font_load(FONT3)) && NULL == (lcdFont = gdk_font_load(FONT4)) && NULL == (lcdFont = gdk_font_load(FONT5)) && NULL == (lcdFont = gdk_font_load(FONT6))){ fprintf(stderr, "Unable to load a font.\n"); exit(0); } /* find max font width */ for(i=0; i<256; i++){ width = gdk_char_width(lcdFont, (gchar)i); if(width < 50 && width > fontW) fontW = width; } /* globals we use all over the place */ fontH = lcdFont->ascent + lcdFont->descent; fontD = lcdFont->descent; #endif if(fontW == 0 || fontH == 0){ fprintf(stderr, "Error: can not determine font dimentions.\n"); exit(0); } wid = (2 * BORDER) + (lcdWidth * fontW); hgt = (2 * BORDER) + (lcdHeight * fontH); #ifndef USE_PANGO lcdDA = gtk_drawing_area_new(); #endif gtk_drawing_area_size(GTK_DRAWING_AREA(lcdDA), wid, hgt); gtk_box_pack_start(GTK_BOX(parent), lcdDA, TRUE, TRUE, 0); /* Signals used to handle window ops */ gtk_signal_connect(GTK_OBJECT(lcdDA), "expose_event", (GtkSignalFunc)lcdExposeCB, NULL); gtk_signal_connect(GTK_OBJECT(lcdDA),"configure_event", (GtkSignalFunc)lcdResizeCB, NULL); /* Event signals (Selection) */ gtk_signal_connect(GTK_OBJECT(lcdDA), "selection_received", (GtkSignalFunc)lcdPasteCB, NULL); gtk_signal_connect(GTK_OBJECT(lcdDA), "selection_clear_event", (GtkSignalFunc)loseSelection, NULL); /* gtk_signal_connect(GTK_OBJECT(lcdDA), "selection_request_event", (GtkSignalFunc)convertSelection, NULL); */ #ifdef GTK_VER_1_1 gtk_selection_add_targets(lcdDA, GDK_SELECTION_PRIMARY, targetlist, ntargets); gtk_signal_connect(GTK_OBJECT(lcdDA), "selection_get", (GtkSignalFunc)convertSelection, NULL); #else gtk_selection_add_handler(lcdDA, GDK_SELECTION_PRIMARY, GDK_SELECTION_TYPE_STRING, convertSelection, NULL); #endif /* Event signals (Input) */ gtk_signal_connect(GTK_OBJECT(lcdDA), "motion_notify_event", (GtkSignalFunc)lcdMotionEvnt, NULL); gtk_signal_connect(GTK_OBJECT(lcdDA), "button_press_event", (GtkSignalFunc)lcdButtonPressEvnt, NULL); gtk_signal_connect(GTK_OBJECT(lcdDA), "button_release_event", (GtkSignalFunc)lcdButtonReleaseEvnt, NULL); gtk_signal_connect_after(GTK_OBJECT(lcdDA), "key_press_event", (GtkSignalFunc)lcdKeyPressEvnt, NULL); gtk_signal_connect_after(GTK_OBJECT(lcdDA), "key_release_event", (GtkSignalFunc)lcdKeyReleaseEvnt, NULL); gtk_widget_set_events(lcdDA, GDK_EXPOSURE_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_KEY_PRESS_MASK | GDK_KEY_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK); GTK_WIDGET_SET_FLAGS(lcdDA, GTK_CAN_FOCUS); gtk_widget_show(lcdDA); gtk_widget_grab_focus(lcdDA); return lcdDA; }
void drawTextWithSpacing(GraphicsContext* graphicsContext, const SimpleFontData* font, const wxColour& color, const GlyphBuffer& glyphBuffer, int from, int numGlyphs, const FloatPoint& point) { #if USE(WXGC) wxGCDC* dc = static_cast<wxGCDC*>(graphicsContext->platformContext()); wxGraphicsContext* gc = dc->GetGraphicsContext(); gc->PushState(); cairo_t* cr = (cairo_t*)gc->GetNativeContext(); wxFont* wxfont = font->getWxFont(); cairo_scaled_font_t* scaled_font = 0; #if wxUSE_PANGO PangoFont* pangoFont = createPangoFontForFont(wxfont); PangoFontMap* fontMap = pangoFontMap(); PangoContext* pangoContext = pango_cairo_font_map_create_context(PANGO_CAIRO_FONT_MAP(fontMap)); scaled_font = createScaledFontForFont(wxfont); #elif __WXMSW__ cairo_matrix_t sizeMatrix, ctm; cairo_matrix_init_identity(&ctm); int size = font->platformData().size(); cairo_matrix_init_scale(&sizeMatrix, size, size); cairo_font_options_t* fontOptions = cairo_font_options_create(); cairo_font_options_set_antialias(fontOptions, CAIRO_ANTIALIAS_SUBPIXEL); cairo_font_face_t* win_face = cairo_win32_font_face_create_for_hfont((HFONT)wxfont->GetHFONT()); scaled_font = cairo_scaled_font_create(win_face, &sizeMatrix, &ctm, fontOptions); #endif ASSERT(scaled_font); GlyphBufferGlyph* glyphs = const_cast<GlyphBufferGlyph*>(glyphBuffer.glyphs(from)); float offset = point.x(); for (int i = 0; i < numGlyphs; i++) { #if wxUSE_PANGO glyphs[i].index = pango_font_get_glyph(pangoFont, pangoContext, glyphBuffer.glyphAt(from + i)); #endif glyphs[i].x = offset; glyphs[i].y = point.y(); offset += glyphBuffer.advanceAt(from + i); } cairo_set_source_rgba(cr, color.Red()/255.0, color.Green()/255.0, color.Blue()/255.0, color.Alpha()/255.0); cairo_set_scaled_font(cr, scaled_font); cairo_show_glyphs(cr, glyphs, numGlyphs); cairo_scaled_font_destroy(scaled_font); gc->PopState(); #else wxDC* dc = graphicsContext->platformContext(); wxFont* wxfont = font->getWxFont(); if (wxfont && wxfont->IsOk()) dc->SetFont(*wxfont); dc->SetTextForeground(color); // convert glyphs to wxString GlyphBufferGlyph* glyphs = const_cast<GlyphBufferGlyph*>(glyphBuffer.glyphs(from)); int offset = point.x(); wxString text = wxEmptyString; for (unsigned i = 0; i < numGlyphs; i++) { text = text.Append((wxChar)glyphs[i]); offset += glyphBuffer.advanceAt(from + i); } // the y point is actually the bottom point of the text, turn it into the top float height = font->ascent() - font->descent(); wxCoord ypoint = (wxCoord) (point.y() - height); dc->DrawText(text, (wxCoord)point.x(), ypoint); #endif }
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; }
static void aosd_osd_create ( void ) { gint max_width, layout_width, layout_height; PangoRectangle ink, log; GdkScreen *screen = gdk_screen_get_default(); gint pos_x = 0, pos_y = 0; gint pad_left = 0 , pad_right = 0 , pad_top = 0 , pad_bottom = 0; gint screen_width, screen_height; aosd_deco_style_data_t style_data; /* calculate screen_width and screen_height */ if ( osd_data->cfg_osd->position.multimon_id > -1 ) { /* adjust coordinates and size according to selected monitor */ GdkRectangle rect; gdk_screen_get_monitor_geometry( screen , osd_data->cfg_osd->position.multimon_id , &rect ); pos_x = rect.x; pos_y = rect.y; screen_width = rect.width; screen_height = rect.height; } else { /* use total space available, even when composed by multiple monitor */ screen_width = gdk_screen_get_width( screen ); screen_height = gdk_screen_get_height( screen ); pos_x = 0; pos_y = 0; } /* pick padding from selected decoration style */ aosd_deco_style_get_padding( osd_data->cfg_osd->decoration.code , &pad_top , &pad_bottom , &pad_left , &pad_right ); if ( osd_data->cfg_osd->position.maxsize_width > 0 ) { gint max_width_default = screen_width - pad_left - pad_right - abs(osd_data->cfg_osd->position.offset_x); max_width = osd_data->cfg_osd->position.maxsize_width - pad_left - pad_right; /* ignore user-defined max_width if it is too small or too large */ if (( max_width < 1 ) || ( max_width > max_width_default )) max_width = max_width_default; } else { max_width = screen_width - pad_left - pad_right - abs(osd_data->cfg_osd->position.offset_x); } osd_data->pango_context = pango_cairo_font_map_create_context( PANGO_CAIRO_FONT_MAP(pango_cairo_font_map_get_default())); osd_data->pango_layout = pango_layout_new(osd_data->pango_context); pango_layout_set_markup( osd_data->pango_layout, osd_data->markup_message , -1 ); pango_layout_set_ellipsize( osd_data->pango_layout , PANGO_ELLIPSIZE_NONE ); pango_layout_set_justify( osd_data->pango_layout , FALSE ); pango_layout_set_width( osd_data->pango_layout , PANGO_SCALE * max_width ); pango_layout_get_pixel_extents( osd_data->pango_layout , &ink , &log ); layout_width = ink.width; layout_height = log.height; /* osd position */ switch ( osd_data->cfg_osd->position.placement ) { case AOSD_POSITION_PLACEMENT_TOP: pos_x += (screen_width - (layout_width + pad_left + pad_right)) / 2; pos_y += 0; break; case AOSD_POSITION_PLACEMENT_TOPRIGHT: pos_x += screen_width - (layout_width + pad_left + pad_right); pos_y += 0; break; case AOSD_POSITION_PLACEMENT_MIDDLELEFT: pos_x += 0; pos_y += (screen_height - (layout_height + pad_top + pad_bottom)) / 2; break; case AOSD_POSITION_PLACEMENT_MIDDLE: pos_x += (screen_width - (layout_width + pad_left + pad_right)) / 2; pos_y += (screen_height - (layout_height + pad_top + pad_bottom)) / 2; break; case AOSD_POSITION_PLACEMENT_MIDDLERIGHT: pos_x += screen_width - (layout_width + pad_left + pad_right); pos_y += (screen_height - (layout_height + pad_top + pad_bottom)) / 2; break; case AOSD_POSITION_PLACEMENT_BOTTOMLEFT: pos_x += 0; pos_y += screen_height - (layout_height + pad_top + pad_bottom); break; case AOSD_POSITION_PLACEMENT_BOTTOM: pos_x += (screen_width - (layout_width + pad_left + pad_right)) / 2; pos_y += screen_height - (layout_height + pad_top + pad_bottom); break; case AOSD_POSITION_PLACEMENT_BOTTOMRIGHT: pos_x += screen_width - (layout_width + pad_left + pad_right); pos_y += screen_height - (layout_height + pad_top + pad_bottom); break; case AOSD_POSITION_PLACEMENT_TOPLEFT: default: pos_x += 0; pos_y += 0; break; } /* add offset to position */ pos_x += osd_data->cfg_osd->position.offset_x; pos_y += osd_data->cfg_osd->position.offset_y; ghosd_set_position( osd , pos_x , pos_y , layout_width + pad_left + pad_right , layout_height + pad_top + pad_bottom ); ghosd_set_event_button_cb( osd , aosd_button_func , NULL ); style_data.layout = osd_data->pango_layout; style_data.text = &(osd_data->cfg_osd->text); style_data.decoration = &(osd_data->cfg_osd->decoration); osd_data->fade_data.surface = NULL; osd_data->fade_data.user_data = &style_data; osd_data->fade_data.width = layout_width + pad_left + pad_right; osd_data->fade_data.height = layout_height + pad_top + pad_bottom; osd_data->fade_data.alpha = 0; osd_data->fade_data.deco_code = osd_data->cfg_osd->decoration.code; osd_data->dalpha_in = 1.0 / ( osd_data->cfg_osd->animation.timing_fadein / (gfloat)AOSD_TIMING ); osd_data->dalpha_out = 1.0 / ( osd_data->cfg_osd->animation.timing_fadeout / (gfloat)AOSD_TIMING ); osd_data->ddisplay_stay = 1.0 / ( osd_data->cfg_osd->animation.timing_display / (gfloat)AOSD_TIMING ); ghosd_set_render( osd , (GhosdRenderFunc)aosd_fade_func , &(osd_data->fade_data) , NULL ); /* show the osd (with alpha 0, invisible) */ ghosd_show( osd ); return; }
FontPlatformData::FontPlatformData(const FontDescription& fontDescription, const AtomicString& familyName) : m_context(0) , m_font(0) , m_size(fontDescription.computedSize()) , m_syntheticBold(false) , m_syntheticOblique(false) , m_scaledFont(0) { FontPlatformData::init(); CString stored_family = familyName.string().utf8(); char const* families[] = { stored_family.data(), NULL }; switch (fontDescription.genericFamily()) { case FontDescription::SerifFamily: families[1] = "serif"; break; case FontDescription::SansSerifFamily: families[1] = "sans"; break; case FontDescription::MonospaceFamily: families[1] = "monospace"; break; case FontDescription::NoFamily: case FontDescription::StandardFamily: default: families[1] = "sans"; break; } PangoFontDescription* description = pango_font_description_new(); pango_font_description_set_absolute_size(description, fontDescription.computedSize() * PANGO_SCALE); // FIXME: Map all FontWeight values to Pango font weights. if (fontDescription.weight() >= FontWeight600) pango_font_description_set_weight(description, PANGO_WEIGHT_BOLD); if (fontDescription.italic()) pango_font_description_set_style(description, PANGO_STYLE_ITALIC); #if PANGO_VERSION_CHECK(1,21,5) // deprecated in 1.21 m_context = pango_font_map_create_context(m_fontMap); #else m_context = pango_cairo_font_map_create_context(PANGO_CAIRO_FONT_MAP(m_fontMap)); #endif for (unsigned int i = 0; !m_font && i < G_N_ELEMENTS(families); i++) { pango_font_description_set_family(description, families[i]); pango_context_set_font_description(m_context, description); m_font = pango_font_map_load_font(m_fontMap, m_context, description); } #if PANGO_VERSION_CHECK(1,18,0) if (m_font) m_scaledFont = cairo_scaled_font_reference(pango_cairo_font_get_scaled_font(PANGO_CAIRO_FONT(m_font))); #else // This compatibility code for older versions of Pango is not well-tested. if (m_font) { PangoFcFont* fcfont = PANGO_FC_FONT(m_font); cairo_font_face_t* face = cairo_ft_font_face_create_for_pattern(fcfont->font_pattern); double size; if (FcPatternGetDouble(fcfont->font_pattern, FC_PIXEL_SIZE, 0, &size) != FcResultMatch) size = 12.0; cairo_matrix_t fontMatrix; cairo_matrix_init_scale(&fontMatrix, size, size); cairo_font_options_t* fontOptions; if (pango_cairo_context_get_font_options(m_context)) fontOptions = cairo_font_options_copy(pango_cairo_context_get_font_options(m_context)); else fontOptions = cairo_font_options_create(); cairo_matrix_t ctm; cairo_matrix_init_identity(&ctm); m_scaledFont = cairo_scaled_font_create(face, &fontMatrix, &ctm, fontOptions); cairo_font_options_destroy(fontOptions); cairo_font_face_destroy(face); } #endif pango_font_description_free(description); }
FontPlatformData::FontPlatformData(const FontDescription& fontDescription, const UChar *characters, int length) : m_context(0) , m_font(0) , m_size(fontDescription.computedSize()) , m_syntheticBold(false) , m_syntheticOblique(false) , m_scaledFont(0) { FontPlatformData::init(); const UChar character = characters[0]; char const *family; switch (fontDescription.genericFamily()) { case FontDescription::SerifFamily: family = "serif"; break; case FontDescription::SansSerifFamily: family = "sans"; break; case FontDescription::MonospaceFamily: family = "monospace"; break; case FontDescription::NoFamily: case FontDescription::StandardFamily: default: family = "sans"; break; } m_context = pango_cairo_font_map_create_context(PANGO_CAIRO_FONT_MAP(m_fontMap)); PangoFontDescription* description = pango_font_description_new(); pango_font_description_set_absolute_size(description, fontDescription.computedSize() * PANGO_SCALE); if (fontDescription.weight() >= FontWeight600) pango_font_description_set_weight(description, PANGO_WEIGHT_BOLD); if (fontDescription.italic()) pango_font_description_set_style(description, PANGO_STYLE_ITALIC); pango_font_description_set_family(description, family); pango_context_set_font_description(m_context, description); PangoFontset *fset = pango_font_map_load_fontset (m_fontMap, m_context, description, NULL); // Get the font from the fontset which contains the best glyph for this character m_font = pango_fontset_get_font(fset, (guint)character); #if PANGO_VERSION_CHECK(1,18,0) if (m_font) m_scaledFont = cairo_scaled_font_reference(pango_cairo_font_get_scaled_font(PANGO_CAIRO_FONT(m_font))); #else // This compatibility code for older versions of Pango is not well-tested. if (m_font) { PangoFcFont* fcfont = PANGO_FC_FONT(m_font); cairo_font_face_t* face = cairo_ft_font_face_create_for_pattern(fcfont->font_pattern); double size; if (FcPatternGetDouble(fcfont->font_pattern, FC_PIXEL_SIZE, 0, &size) != FcResultMatch) size = 12.0; cairo_matrix_t fontMatrix; cairo_matrix_init_scale(&fontMatrix, size, size); cairo_font_options_t* fontOptions; if (pango_cairo_context_get_font_options(m_context)) fontOptions = cairo_font_options_copy(pango_cairo_context_get_font_options(m_context)); else fontOptions = cairo_font_options_create(); cairo_matrix_t ctm; cairo_matrix_init_identity(&ctm); m_scaledFont = cairo_scaled_font_create(face, &fontMatrix, &ctm, fontOptions); cairo_font_options_destroy(fontOptions); cairo_font_face_destroy(face); } #endif pango_font_description_free(description); }
static VALUE rg_create_context(VALUE self) { return GOBJ2RVAL_UNREF(pango_cairo_font_map_create_context(_SELF(self))); }