_HYPlatformButton::_HYPlatformButton (void) { _HYButton * parent = (_HYButton*)this; buttonControl = nil; buttonRect = (GdkRectangle){0,0,100,100}; buttonFontDesc = pango_font_description_new (); }
static PangoFontDescription * get_pango_font_description_from_info (gchar *font_family, gchar *font_weight, gint font_size) { PangoFontDescription *description = NULL; PangoWeight pw = PANGO_WEIGHT_NORMAL; g_assert(font_family); g_assert(font_weight); g_assert(font_size > 0); description = pango_font_description_new(); pango_font_description_set_family(description, font_family); if (!g_strcmp0(font_weight, "bold")) { pw = PANGO_WEIGHT_BOLD; } else { pw = PANGO_WEIGHT_NORMAL; } pango_font_description_set_weight(description, pw); pango_font_description_set_size(description, font_size * PANGO_SCALE); return description; }
GtkWidget * create_welcome_dialog(void) { I7App *theapp = i7_app_get(); GFile *file = i7_app_get_data_file_va(theapp, "ui", "welcomedialog.ui", NULL); GtkBuilder *builder = create_new_builder(file, theapp); g_object_unref(file); GtkWidget *retval = GTK_WIDGET(load_object(builder, "welcomedialog")); /* Set the background pixmap for this window */ GtkRcStyle *newstyle = gtk_widget_get_modifier_style(retval); file = i7_app_get_data_file_va(theapp, "Resources", "Welcome Background.png", NULL); newstyle->bg_pixmap_name[GTK_STATE_NORMAL] = g_file_get_path(file); /* take ownership */ g_object_unref(file); gtk_widget_modify_style(retval, newstyle); /* Set the font size to 12 pixels for the widgets in this window */ PangoFontDescription *font = pango_font_description_new(); pango_font_description_set_absolute_size(font, 12.0 * PANGO_SCALE); gtk_widget_modify_font(GTK_WIDGET(load_object(builder, "welcome_label")), font); pango_font_description_free(font); /* If there is no "last project", make the reopen button inactive */ GFile *last_project = i7_app_get_last_opened_project(theapp); if(last_project) { gtk_widget_set_sensitive(GTK_WIDGET(load_object(builder, "welcome_reopen_button")), TRUE); g_object_unref(last_project); } g_object_unref(builder); return retval; }
static void add_text(cairo_surface_t* surface, int x, int y, int size, const char* text) { cairo_t* cr = cairo_create(surface); cairo_set_source_rgb(cr, 1., 1., 1.); PangoLayout* layout = pango_cairo_create_layout(cr); pango_layout_set_text(layout, text, -1); PangoFontDescription* desc = pango_font_description_new(); pango_font_description_set_family(desc, "sans"); pango_font_description_set_weight(desc, PANGO_WEIGHT_BOLD); pango_font_description_set_absolute_size(desc, size * PANGO_SCALE); pango_layout_set_font_description(layout, desc); pango_font_description_free(desc); int w = 0; int h = 0; pango_layout_get_pixel_size(layout, &w, &h); cairo_move_to(cr, (x >= 0) ? x : -(x + (double)w), (y >= 0) ? y : -(y + (double)h)); pango_cairo_show_layout(cr, layout); g_object_unref(layout); cairo_destroy(cr); }
/* ml_init */ static MailerPlugin * _ml_init(MailerPluginHelper * helper) { MailingLists * ml; PangoFontDescription * bold; if((ml = malloc(sizeof(*ml))) == NULL) return NULL; ml->helper = helper; /* widgets */ bold = pango_font_description_new(); pango_font_description_set_weight(bold, PANGO_WEIGHT_BOLD); ml->vbox = gtk_vbox_new(FALSE, 4); ml->folder = gtk_label_new(""); gtk_widget_modify_font(ml->folder, bold); gtk_misc_set_alignment(GTK_MISC(ml->folder), 0.0, 0.5); gtk_box_pack_start(GTK_BOX(ml->vbox), ml->folder, FALSE, TRUE, 0); ml->message = gtk_label_new(""); gtk_misc_set_alignment(GTK_MISC(ml->message), 0.0, 0.5); gtk_box_pack_start(GTK_BOX(ml->vbox), ml->message, FALSE, TRUE, 0); ml->name = gtk_label_new(""); gtk_misc_set_alignment(GTK_MISC(ml->name), 0.0, 0.5); gtk_box_pack_start(GTK_BOX(ml->vbox), ml->name, FALSE, TRUE, 0); pango_font_description_free(bold); return ml; }
static void gst_time_overlay_class_init (GstTimeOverlayClass * klass) { GstTextOverlayClass *gsttextoverlay_class; PangoContext *context; PangoFontDescription *font_description; gsttextoverlay_class = (GstTextOverlayClass *) klass; gsttextoverlay_class->get_text = gst_time_overlay_get_text; g_mutex_lock (GST_TEXT_OVERLAY_CLASS (klass)->pango_lock); context = GST_TEXT_OVERLAY_CLASS (klass)->pango_context; pango_context_set_language (context, pango_language_from_string ("en_US")); pango_context_set_base_dir (context, PANGO_DIRECTION_LTR); font_description = pango_font_description_new (); pango_font_description_set_family_static (font_description, "Monospace"); pango_font_description_set_style (font_description, PANGO_STYLE_NORMAL); pango_font_description_set_variant (font_description, PANGO_VARIANT_NORMAL); pango_font_description_set_weight (font_description, PANGO_WEIGHT_NORMAL); pango_font_description_set_stretch (font_description, PANGO_STRETCH_NORMAL); pango_font_description_set_size (font_description, 18 * PANGO_SCALE); pango_context_set_font_description (context, font_description); pango_font_description_free (font_description); g_mutex_unlock (GST_TEXT_OVERLAY_CLASS (klass)->pango_lock); }
/* title_init */ static Title * _title_init(PanelAppletHelper * helper, GtkWidget ** widget) { Title * title; PangoFontDescription * bold; if((title = malloc(sizeof(*title))) == NULL) { error_set("%s: %s", applet.name, strerror(errno)); return NULL; } title->helper = helper; bold = pango_font_description_new(); pango_font_description_set_weight(bold, PANGO_WEIGHT_BOLD); title->widget = gtk_label_new(""); #if GTK_CHECK_VERSION(3, 0, 0) gtk_widget_override_font(title->widget, bold); #else gtk_widget_modify_font(title->widget, bold); #endif pango_font_description_free(bold); title->source = g_signal_connect(title->widget, "screen-changed", G_CALLBACK(_title_on_screen_changed), title); title->display = NULL; title->screen = NULL; title->root = NULL; title->atom_active = 0; title->atom_name = 0; title->atom_visible_name = 0; gtk_widget_show(title->widget); *widget = title->widget; return title; }
void SetUpStatusBarStuff (GtkWidget* aWindow) { _String fName = baseDirectory & "GTKResources/striped.xpm"; statusBarLayout = pango_layout_new (screenPContext); statusBarFontDesc = pango_font_description_new (); stripedFill = gdk_pixmap_create_from_xpm (GDK_DRAWABLE(aWindow->window), NULL, NULL, fName.sData); stripedFillGC = gdk_gc_new (GDK_DRAWABLE(aWindow->window)); if (stripedFill) { gdk_gc_set_fill (stripedFillGC,GDK_TILED); gdk_gc_set_tile (stripedFillGC,stripedFill); } else { printf ("Failed to load a status bar .xpm from %s\n", fName.sData); } gdk_gc_set_line_attributes (stripedFillGC, 1, GDK_LINE_SOLID, GDK_CAP_NOT_LAST, GDK_JOIN_MITER); GdkColor saveFG = {0,0,0,0}; gdk_gc_set_foreground (stripedFillGC, &saveFG); pango_font_description_set_family (statusBarFontDesc, statusBarFont.face.sData); pango_font_description_set_style (statusBarFontDesc, (statusBarFont.style & HY_FONT_ITALIC) ? PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL); pango_font_description_set_weight (statusBarFontDesc, (statusBarFont.style & HY_FONT_BOLD) ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL); pango_font_description_set_size (statusBarFontDesc, statusBarFont.size*PANGO_SCALE); pango_layout_set_font_description (statusBarLayout, statusBarFontDesc ); // ref ? pango_layout_set_width (statusBarLayout, -1); redButtonIcon = (GdkPixbuf*)ProcureIconResource(4000); yellowButtonIcon = (GdkPixbuf*)ProcureIconResource(4001); greenButtonIcon = (GdkPixbuf*)ProcureIconResource(4002); orangeButtonIcon = (GdkPixbuf*)ProcureIconResource(4003); }
static void gst_time_overlay_init (GstTimeOverlay * overlay, GstTimeOverlayClass * klass) { PangoFontDescription *font_description; GstTextOverlay *textoverlay; PangoContext *context; textoverlay = GST_TEXT_OVERLAY (overlay); context = GST_TEXT_OVERLAY_CLASS (klass)->pango_context; pango_context_set_language (context, pango_language_from_string ("en_US")); pango_context_set_base_dir (context, PANGO_DIRECTION_LTR); font_description = pango_font_description_new (); pango_font_description_set_family_static (font_description, "Monospace"); pango_font_description_set_style (font_description, PANGO_STYLE_NORMAL); pango_font_description_set_variant (font_description, PANGO_VARIANT_NORMAL); pango_font_description_set_weight (font_description, PANGO_WEIGHT_NORMAL); pango_font_description_set_stretch (font_description, PANGO_STRETCH_NORMAL); pango_font_description_set_size (font_description, 18 * PANGO_SCALE); pango_context_set_font_description (context, font_description); pango_font_description_free (font_description); textoverlay->valign = GST_TEXT_OVERLAY_VALIGN_TOP; textoverlay->halign = GST_TEXT_OVERLAY_HALIGN_LEFT; }
static VALUE rg_font(VALUE self) { PangoFontDescription* desc; PangoLanguage* lang; GSList* extra_attrs; VALUE ary, ret; desc = pango_font_description_new(); pango_attr_iterator_get_font(_SELF(self), desc, &lang, &extra_attrs); ary = rb_ary_new(); while(extra_attrs) { rb_ary_push(ary, ATTR2RVAL(extra_attrs->data)); extra_attrs = extra_attrs->next; } ret = rb_ary_new3(3, PANGOFONTDESCRIPTION2RVAL(desc), PANGOLANGUAGE2RVAL(lang), ary); pango_font_description_free(desc); return ret; }
void wxFontRefData::Init(int pointSize, wxFontFamily family, wxFontStyle style, wxFontWeight weight, bool underlined, bool strikethrough, const wxString& faceName, wxFontEncoding WXUNUSED(encoding)) { if (family == wxFONTFAMILY_DEFAULT) family = wxFONTFAMILY_SWISS; m_underlined = underlined; m_strikethrough = strikethrough; // Create native font info m_nativeFontInfo.description = pango_font_description_new(); // And set its values if (!faceName.empty()) { pango_font_description_set_family( m_nativeFontInfo.description, wxGTK_CONV_SYS(faceName) ); } else { SetFamily(family); } SetStyle( style == wxDEFAULT ? wxFONTSTYLE_NORMAL : style ); SetPointSize( (pointSize == wxDEFAULT || pointSize == -1) ? wxDEFAULT_FONT_SIZE : pointSize ); SetWeight( weight == wxDEFAULT ? wxFONTWEIGHT_NORMAL : weight ); }
//________________________________________________________ long GetVisibleStringWidth (_String& s, _HYFont& f) { static PangoLayout* textLayout = pango_layout_new (screenPContext); static PangoFontDescription * fd = pango_font_description_new (); static _HYFont stashedFont; if (s.sLength) { if (stashedFont.size!=f.size || stashedFont.style != f.style || stashedFont.face != f.face) { HYFont2PangoFontDesc(f,fd); pango_layout_set_width (textLayout,-1); pango_layout_set_font_description(textLayout,fd); stashedFont = f; } pango_layout_set_text (textLayout, s.sData,s.sLength); //PangoRectangle charPos; //pango_layout_index_to_pos (textLayout,s.sLength-1,&charPos); //return PANGO_PIXELS(charPos.x+charPos.width); PangoRectangle extents, logical_ext; pango_layout_get_pixel_extents (textLayout,&extents,&logical_ext); return logical_ext.width; } else { return 0; } }
GdkPixbuf * pixbuf_render_text(GtkWidget *da, const char *str, int point_size, int r, int g, int b, int *w, int *h) { int width; int height; PangoLayout *layout = gtk_widget_create_pango_layout(da, NULL); PangoFontDescription *desc = pango_font_description_new(); pango_font_description_set_size(desc, point_size * PANGO_SCALE); pango_layout_set_font_description(layout, desc); pango_font_description_free(desc); pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER); pango_layout_set_text(layout, str, -1); pango_layout_get_pixel_size(layout, &width, &height); GdkPixbuf *pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, width, height); pixbuf_set_rect_fill(pixbuf, 0, 0, width, height, 0, 0, 0, 0); pixbuf_draw_layout(pixbuf, layout, da, 0, 0, r, g, b, 255); //gdk_draw_layout(da->window, da->style->fg_gc[GTK_STATE_NORMAL], 0, 0, layout); g_object_unref(G_OBJECT(layout)); *w = width; *h = height; return pixbuf; }
int main(int argc, char **argv) { GtkWidget *win; GtkButton *button; PangoFontDescription *pd; gtk_init(&argc, &argv); win = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(win), "Basic Animation"); g_signal_connect(G_OBJECT(win), "delete-event", gtk_main_quit, NULL); label = (GtkLabel *)gtk_label_new(hello); // since we shift a whole character per time, it's better to use // a monospace font, so that the shifting seems done at the same pace pd = pango_font_description_new(); pango_font_description_set_family(pd, "monospace"); gtk_widget_modify_font(GTK_WIDGET(label), pd); button = (GtkButton *)gtk_button_new(); gtk_container_add(GTK_CONTAINER(button), GTK_WIDGET(label)); gtk_container_add(GTK_CONTAINER(win), GTK_WIDGET(button)); g_signal_connect(G_OBJECT(button), "clicked", G_CALLBACK(change_dir), NULL); slen = strlen(hello); g_timeout_add(125, scroll_it, NULL); gtk_widget_show_all(GTK_WIDGET(win)); gtk_main(); return 0; }
_HYPlatformPullDown::_HYPlatformPullDown(void) { _HYPullDown * parent = (_HYPullDown*)this; theMenu = gtk_combo_new (); backFill = HYColorToGDKColor((_HYColor) { 255,255,255 }); gtk_combo_set_value_in_list (GTK_COMBO(theMenu),true,false); gtk_container_add(GTK_CONTAINER(parent->parentWindow),theMenu); gtk_entry_set_editable(GTK_ENTRY(GTK_COMBO(theMenu)->entry),false); GList* children = gtk_container_get_children(GTK_CONTAINER(theMenu)); g_signal_connect (GTK_WIDGET(children->next->data),"event",(GCallback)hy_pulldown_selection_start_callback_event,(_HYPullDown*)this); g_signal_connect (GTK_COMBO(theMenu)->entry,"changed",(GCallback)hy_pulldown_selection_callback,(_HYPullDown*)this); g_signal_connect (GTK_COMBO(theMenu)->popwin,"hide",(GCallback)hy_pulldown_unmap_event,(_HYPullDown*)this); g_list_free (children); //gtk_container_set_resize_mode(GTK_CONTAINER(theMenu), GTK_RESIZE_IMMEDIATE); selection = 0; cbSelection = -1; if (!defaultPullDownFontPD) { defaultPullDownFontPD = pango_font_description_new(); defaultPullDownFont.size = defaultPullDownFont.size*fontConversionFactor; HYFont2PangoFontDesc (defaultPullDownFont,defaultPullDownFontPD); } gtk_widget_modify_font (theMenu, defaultPullDownFontPD); gtk_widget_modify_font (GTK_COMBO(theMenu)->entry, defaultPullDownFontPD); gtk_widget_show (theMenu); //g_signal_connect (GTK_COMBO(theMenu)->entry,"changed",hy_pulldown_selection_callback,(_HYPullDown*)this); }
/* title_init */ static Title * _title_init(PanelAppletHelper * helper, GtkWidget ** widget) { Title * title; PangoFontDescription * bold; if((title = malloc(sizeof(*title))) == NULL) return NULL; title->helper = helper; bold = pango_font_description_new(); pango_font_description_set_weight(bold, PANGO_WEIGHT_BOLD); title->widget = gtk_label_new(""); gtk_widget_modify_font(title->widget, bold); pango_font_description_free(bold); g_signal_connect(G_OBJECT(title->widget), "screen-changed", G_CALLBACK( _on_screen_changed), title); title->display = NULL; title->screen = NULL; title->root = NULL; title->atom_active = 0; title->atom_name = 0; title->atom_visible_name = 0; gtk_widget_show(title->widget); *widget = title->widget; return title; }
void wxFontRefData::Init(int pointSize, wxFontFamily family, wxFontStyle style, wxFontWeight weight, bool underlined, const wxString& faceName, wxFontEncoding encoding) { m_family = family == wxFONTFAMILY_DEFAULT ? wxFONTFAMILY_SWISS : family; m_faceName = faceName; // we accept both wxDEFAULT and wxNORMAL here - should we? m_style = style == wxDEFAULT ? wxFONTSTYLE_NORMAL : style; m_weight = weight == wxDEFAULT ? wxFONTWEIGHT_NORMAL : weight; m_underlined = underlined; m_encoding = encoding; #if wxUSE_UNICODE if ( m_nativeFontInfo.description ) pango_font_description_free(m_nativeFontInfo.description); // Create native font info m_nativeFontInfo.description = pango_font_description_new(); // if a face name is specified, use it if it's available, otherwise use // just the family if ( faceName.empty() || !wxFontEnumerator::IsValidFacename(faceName) ) { // TODO: scan system for valid fonts matching the given family instead // of hardcoding them here switch ( m_family ) { case wxFONTFAMILY_TELETYPE: m_faceName = wxT("monospace"); break; case wxFONTFAMILY_ROMAN: m_faceName = wxT("serif"); break; default: m_faceName = wxT("sans"); } } else // specified face name is available, use it { m_faceName = faceName; } m_nativeFontInfo.SetFaceName(m_faceName); m_nativeFontInfo.SetWeight((wxFontWeight)m_weight); m_nativeFontInfo.SetStyle((wxFontStyle)m_style); #endif // wxUSE_UNICODE SetPointSize(pointSize); }
/* Widget behaviour */ void netinfo_toggle_state (Netinfo * netinfo, gboolean state, gpointer user_data) { GdkCursor *cursor; PangoFontDescription *font_desc; g_assert (netinfo != NULL); g_return_if_fail (netinfo != NULL); if (! netinfo->toggle) { netinfo->running = !state; return; } if (GTK_IS_WIDGET (netinfo->sensitive)) { gtk_widget_set_sensitive (GTK_WIDGET (netinfo->sensitive), state); } font_desc = pango_font_description_new (); if (state) { pango_font_description_set_weight (font_desc, PANGO_WEIGHT_NORMAL); netinfo_progress_indicator_stop (netinfo); gdk_window_set_cursor (gtk_widget_get_window(netinfo->output), NULL); netinfo->child_pid = 0; gtk_statusbar_pop (GTK_STATUSBAR (netinfo->status_bar), 0); gtk_statusbar_push (GTK_STATUSBAR (netinfo->status_bar), 0, _("Idle")); } else { pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD); netinfo_progress_indicator_start (netinfo); cursor = gdk_cursor_new (GDK_WATCH); if (!gtk_widget_get_realized (netinfo->output)) gtk_widget_realize (GTK_WIDGET (netinfo->output)); gdk_window_set_cursor (gtk_widget_get_window(netinfo->output), cursor); gdk_cursor_unref (cursor); if (netinfo->stbar_text) { gtk_statusbar_pop (GTK_STATUSBAR (netinfo->status_bar), 0); gtk_statusbar_push (GTK_STATUSBAR (netinfo->status_bar), 0, netinfo->stbar_text); } } gtk_widget_modify_font (netinfo->page_label, font_desc); pango_font_description_free (font_desc); netinfo->running = !state; netinfo_toggle_button (netinfo); }
JNIEXPORT void JNICALL Java_gnu_java_awt_peer_gtk_GdkClasspathFontPeer_setFont (JNIEnv *env, jobject self, jstring family_name_str, jint style_int, jint size) { struct peerfont *pfont = NULL; PangoFontMap *map = NULL; char const *family_name = NULL; gdk_threads_enter (); enum java_awt_font_style 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); pango_font_description_set_size (pfont->desc, size * PANGO_SCALE); 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); /* FIXME: these are possibly wrong, and should in any case probably be cached between calls. */ map = pango_ft2_font_map_for_display (); g_assert (map != NULL); if (pfont->ctx == NULL) pfont->ctx = pango_ft2_font_map_create_context (PANGO_FT2_FONT_MAP (map)); g_assert (pfont->ctx != NULL); if (pfont->font != NULL) g_object_unref (pfont->font); pfont->font = pango_font_map_load_font (map, pfont->ctx, pfont->desc); g_assert (pfont->font != NULL); gdk_threads_leave (); }
static struct fontmap * loadfont(char *fontalias, int font_style, int *symbol) { struct fontmap *fcur; PangoFontDescription *pfont; PangoStyle style; PangoWeight weight; *symbol = FALSE; if (nhash_get_ptr(Gra2cairoConf->fontmap, fontalias, (void *) &fcur)) { int i; if (nhash_get_int(CompatibleFontHash, fontalias, &i) == 0) { if (nhash_get_ptr(Gra2cairoConf->fontmap, CompatibleFont[i].name, (void *) &fcur) == 0) { font_style = CompatibleFont[i].style; *symbol = CompatibleFont[i].symbol; } } if (fcur == NULL && nhash_get_ptr(Gra2cairoConf->fontmap, DEFAULT_FONT, (void *) &fcur)) { return NULL; } } if (fcur->font) { pfont = fcur->font; } else { gchar *ptr; pfont = pango_font_description_new(); ptr = g_strdup_printf("%s%s%s", fcur->fontname, (fcur->alternative) ? "," : "", CHK_STR(fcur->alternative)); if (ptr) { pango_font_description_set_family(pfont, ptr); g_free(ptr); } else { return NULL; } } if (font_style > 0 && (font_style & GRA_FONT_STYLE_ITALIC)) { style = PANGO_STYLE_ITALIC; } else { style = PANGO_STYLE_NORMAL; } pango_font_description_set_style(pfont, style); if (font_style > 0 && (font_style & GRA_FONT_STYLE_BOLD)) { weight = PANGO_WEIGHT_BOLD; } else { weight = PANGO_WEIGHT_NORMAL; } pango_font_description_set_weight(pfont, weight); fcur->font = pfont; return fcur; }
G_MODULE_EXPORT gboolean display_init() { gdk_color_parse("lightgray", &inst_color_lightgray_); gdk_color_parse("black", &inst_color_black_); font_sans12_desc = pango_font_description_new(); pango_font_description_set_family(font_sans12_desc, "Sans"); pango_font_description_set_size(font_sans12_desc, 12 * PANGO_SCALE); font_sans8_desc = pango_font_description_new(); pango_font_description_set_family(font_sans8_desc, "Sans"); pango_font_description_set_size(font_sans8_desc, 8 * PANGO_SCALE); GdkScreen* const screen = gdk_screen_get_default(); const gint monitor_num = gdk_screen_get_primary_monitor(screen); gdk_screen_get_monitor_geometry(screen, monitor_num, &screen_rect); return TRUE; }
void Picture::set_font(const char *family, int height) { if (font_description == NULL) { font_description = pango_font_description_new( ); } pango_font_description_set_family(font_description, family); pango_font_description_set_weight(font_description, PANGO_WEIGHT_BOLD); pango_font_description_set_absolute_size(font_description, height * PANGO_SCALE); }
static void gtk_cell_renderer_text_init (GtkCellRendererText *celltext) { GTK_CELL_RENDERER (celltext)->xalign = 0.0; GTK_CELL_RENDERER (celltext)->yalign = 0.5; GTK_CELL_RENDERER (celltext)->xpad = 2; GTK_CELL_RENDERER (celltext)->ypad = 2; celltext->fixed_height_rows = -1; celltext->font = pango_font_description_new (); }
RrFont *RrFontOpen(const RrInstance *inst, const gchar *name, gint size, RrFontWeight weight, RrFontSlant slant) { RrFont *out; PangoWeight pweight; PangoStyle pstyle; PangoAttrList *attrlist; out = g_slice_new(RrFont); out->inst = inst; out->ref = 1; out->font_desc = pango_font_description_new(); out->layout = pango_layout_new(inst->pango); out->shortcut_underline = pango_attr_underline_new(PANGO_UNDERLINE_LOW); out->shortcut_underline->start_index = 0; out->shortcut_underline->end_index = 0; attrlist = pango_attr_list_new(); /* shortcut_underline is owned by the attrlist */ pango_attr_list_insert(attrlist, out->shortcut_underline); /* the attributes are owned by the layout */ pango_layout_set_attributes(out->layout, attrlist); pango_attr_list_unref(attrlist); switch (weight) { case RR_FONTWEIGHT_LIGHT: pweight = PANGO_WEIGHT_LIGHT; break; case RR_FONTWEIGHT_NORMAL: pweight = PANGO_WEIGHT_NORMAL; break; case RR_FONTWEIGHT_SEMIBOLD: pweight = PANGO_WEIGHT_SEMIBOLD; break; case RR_FONTWEIGHT_BOLD: pweight = PANGO_WEIGHT_BOLD; break; case RR_FONTWEIGHT_ULTRABOLD: pweight = PANGO_WEIGHT_ULTRABOLD; break; default: g_assert_not_reached(); } switch (slant) { case RR_FONTSLANT_NORMAL: pstyle = PANGO_STYLE_NORMAL; break; case RR_FONTSLANT_ITALIC: pstyle = PANGO_STYLE_ITALIC; break; case RR_FONTSLANT_OBLIQUE: pstyle = PANGO_STYLE_OBLIQUE; break; default: g_assert_not_reached(); } /* setup the font */ pango_font_description_set_family(out->font_desc, name); pango_font_description_set_weight(out->font_desc, pweight); pango_font_description_set_style(out->font_desc, pstyle); pango_font_description_set_size(out->font_desc, size * PANGO_SCALE); /* setup the layout */ pango_layout_set_font_description(out->layout, out->font_desc); pango_layout_set_wrap(out->layout, PANGO_WRAP_WORD_CHAR); /* get the ascent and descent */ measure_font(inst, out); return out; }
void start() { cairo_surface_t* cairo_surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, m_width, m_height); cairo_t* cr = cairo_create(cairo_surface); cairo_set_source_rgba(cr, 0.0, 0.0, 0.0, 0.0); cairo_paint(cr); PangoFontDescription *font_description = pango_font_description_new(); pango_font_description_set_family(font_description, m_font.Family.c_str()); pango_font_description_set_style(font_description, m_font.Style); pango_font_description_set_weight(font_description, m_font.Weight); pango_font_description_set_variant(font_description, m_font.Variant); pango_font_description_set_size(font_description, m_font.Size * PANGO_SCALE); PangoLayout *layout = pango_cairo_create_layout(cr); pango_layout_set_font_description(layout, font_description); pango_layout_set_text(layout, m_text_file.file_content_p(), -1); unsigned char* color = m_font.ColorRGB; // shortcut cairo_set_source_rgb(cr, color[0] / 255.0, color[1] / 255.0, color[2] / 255.0); cairo_move_to(cr, 0.0, 0.0); pango_cairo_show_layout(cr, layout); // To texture { cairo_surface_flush(cairo_surface); std::vector<unsigned char> rgba_data; rgba_from_cairo_ARGB32( cairo_image_surface_get_data(cairo_surface) , m_width , m_height , cairo_image_surface_get_stride(cairo_surface) , rgba_data ); glPixelStorei ( GL_UNPACK_ALIGNMENT, 1 ); m_texture.bind(); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, m_width, m_height, 0, GL_RGBA, GL_UNSIGNED_BYTE, &(rgba_data[0])); assert(glGetError() == GL_NO_ERROR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); assert(glGetError() == GL_NO_ERROR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); assert(glGetError() == GL_NO_ERROR); } g_object_unref(layout); pango_font_description_free(font_description); cairo_destroy(cr); cairo_surface_destroy(cairo_surface); }
EXPORT int audgui_get_digit_width (GtkWidget * widget) { int width; PangoLayout * layout = gtk_widget_create_pango_layout (widget, "0123456789"); PangoFontDescription * desc = pango_font_description_new (); pango_font_description_set_weight (desc, PANGO_WEIGHT_BOLD); pango_layout_set_font_description (layout, desc); pango_layout_get_pixel_size (layout, & width, NULL); pango_font_description_free (desc); return (width + 9) / 10; }
PangoFontDescription* GetPangoFontDescription(const char* font, int size, int dpi) { PangoFontDescription* desc; desc = pango_font_description_new(); if (dpi) pango_font_description_set_size(desc, size * PANGO_SCALE); else pango_font_description_set_absolute_size(desc, size * PANGO_SCALE); pango_font_description_set_family(desc, font); return desc; }
static void dump_font_sizes (PangoContext *context, FILE *f, guint flags) { PangoFont *font; PangoFontDescription *pfd; int nf; real height; fprintf (f, "height/cm"); for (nf = 0; test_families[nf] != NULL; ++nf) fprintf (f, "\t%s", test_families[nf]); fprintf (f, "\n"); for (height = 0.1; height <= 10.0; height += 0.1) { fprintf (f, "%g", height); for (nf = 0; test_families[nf] != NULL; ++nf) { pfd = pango_font_description_new (); pango_font_description_set_family (pfd, test_families[nf]); //pango_font_description_set_size (pfd, height * pixels_per_cm * PANGO_SCALE); if (flags & DUMP_ABSOLUTE) pango_font_description_set_absolute_size (pfd, height * pixels_per_cm * PANGO_SCALE); else pango_font_description_set_size (pfd, height * pixels_per_cm * PANGO_SCALE); font = pango_context_load_font (context, pfd); if (font) { PangoFontMetrics *metrics = pango_font_get_metrics (font, NULL); /* now make a font-size where the font/line-height matches the given pixel size */ real total = ((double)pango_font_metrics_get_ascent (metrics) + pango_font_metrics_get_descent (metrics)) / PANGO_SCALE; real factor = height*pixels_per_cm/total; real line_height; if (flags & DUMP_ABSOLUTE) pango_font_description_set_absolute_size (pfd, factor * height * pixels_per_cm * PANGO_SCALE); else pango_font_description_set_size (pfd, factor * height * pixels_per_cm * PANGO_SCALE); pango_font_metrics_unref (metrics); g_object_unref (font); font = pango_context_load_font (context, pfd); metrics = pango_font_get_metrics (font, NULL); line_height = ((double)pango_font_metrics_get_ascent (metrics) + pango_font_metrics_get_descent (metrics)) / PANGO_SCALE; fprintf (f, "\t%.3g", flags & DUMP_FACTORS ? factor : line_height); g_object_unref (font); } pango_font_description_free (pfd); } fprintf (f, "\n"); } }
font_instance *font_factory::Face(char const *family, int variant, int style, int weight, int stretch, int /*size*/, int /*spacing*/) { PangoFontDescription *temp_descr = pango_font_description_new(); pango_font_description_set_family(temp_descr,family); pango_font_description_set_weight(temp_descr,(PangoWeight)weight); pango_font_description_set_stretch(temp_descr,(PangoStretch)stretch); pango_font_description_set_style(temp_descr,(PangoStyle)style); pango_font_description_set_variant(temp_descr,(PangoVariant)variant); font_instance *res = Face(temp_descr); pango_font_description_free(temp_descr); return res; }
int tag_func_define_font_info (SwfdecSwfDecoder *s, guint tag) { SwfdecFont *font; guint id, len, i; int reserved, wide, ansi, jis; char *name; /* we just assume Latin1 (FIXME: option to change this?) */ SwfdecLanguage language = SWFDEC_LANGUAGE_LATIN; id = swfdec_bits_get_u16 (&s->b); font = swfdec_swf_decoder_get_character (s, id); if (!SWFDEC_IS_FONT (font)) { SWFDEC_WARNING ("didn't find a font with id %u", id); return SWFDEC_STATUS_OK; } len = swfdec_bits_get_u8 (&s->b); /* this string is locale specific */ name = swfdec_bits_get_string_length (&s->b, len, s->version); reserved = swfdec_bits_getbits (&s->b, 2); font->small = swfdec_bits_getbit (&s->b); jis = swfdec_bits_getbit (&s->b); ansi = swfdec_bits_getbit (&s->b); if (jis != 0 || ansi != 0) { SWFDEC_LOG ("ansi = %d, jis = %d", ansi, jis); if (tag == SWFDEC_TAG_DEFINEFONTINFO2) SWFDEC_INFO ("ANSI and JIS flags are supposed to be 0 in DefineFontInfo"); if (jis) language = SWFDEC_LANGUAGE_JAPANESE; } font->italic = swfdec_bits_getbit (&s->b); font->bold = swfdec_bits_getbit (&s->b); wide = swfdec_bits_getbit (&s->b); if (tag == SWFDEC_TAG_DEFINEFONTINFO2) language = swfdec_bits_get_u8 (&s->b); g_free (name); if (font->name) { SWFDEC_LOG ("Creating font description for font %d", id); font->desc = pango_font_description_new (); pango_font_description_set_family_static (font->desc, font->name); if (font->bold) pango_font_description_set_weight (font->desc, PANGO_WEIGHT_BOLD); if (font->italic) pango_font_description_set_style (font->desc, PANGO_STYLE_ITALIC); } for (i = 0; i < font->glyphs->len; i++) { g_array_index (font->glyphs, SwfdecFontEntry, i).value = wide ? swfdec_bits_get_u16 (&s->b) : swfdec_bits_get_u8 (&s->b); } return SWFDEC_STATUS_OK; }