PangoContext * dia_font_get_context() { if (pango_context == NULL) { /* Maybe this one with pangocairo dia_font_push_context (pango_cairo_font_map_create_context (pango_cairo_font_map_get_default())); * but it gives: (lt-dia:30476): Pango-CRITICAL **: pango_renderer_draw_layout: assertion `PANGO_IS_RENDERER (renderer)' failed */ #ifdef HAVE_FREETYPE /* This is suggested by new Pango (1.2.4+), but doesn't get us the * right resolution:( dia_font_push_context(pango_ft2_font_map_create_context(pango_ft2_font_map_new())); */ /* with 96x96 it gives consistent - too big - sizes with the cairo renderer, it was 75x75 with 0.96.x dia_font_push_context(pango_ft2_get_context(96,96)); */ dia_font_push_context(pango_ft2_get_context(75,75)); #else if (gdk_display_get_default ()) dia_font_push_context(gdk_pango_context_get()); else { # ifdef GDK_WINDOWING_WIN32 dia_font_push_context(pango_win32_get_context ()); # else g_warning ("dia_font_get_context() : not font context w/o display. Crashing soon."); # endif } #endif } return pango_context; }
/* NB: this is here only because we need glgdGraphConnect3 to keep backward compatibility; once glgdGraphConnect3 is gone, we can merge this into glgdGraphConnect. */ static GLboolean glgdGraphConnectInt(glgdGraph *graph, GtkWidget *gtkWindow, GtkWidget *glDrawArea) { if (graph && gtkWindow && glDrawArea) { /* Add mouse and keyboard events to the GL draw area */ gtk_widget_add_events(glDrawArea, GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_SCROLL_MASK | GDK_VISIBILITY_NOTIFY_MASK); /* Connect signals to callback routines */ g_signal_connect(G_OBJECT(glDrawArea), "button_press_event", G_CALLBACK(glgdGraphMouseButtonCB), graph); g_signal_connect(G_OBJECT(glDrawArea), "button_release_event", G_CALLBACK(glgdGraphMouseButtonCB), graph); g_signal_connect(G_OBJECT(glDrawArea), "motion_notify_event", G_CALLBACK(glgdGraphMouseMotionCB), graph); g_signal_connect(G_OBJECT(glDrawArea), "scroll_event", G_CALLBACK(glgdGraphMouseScrollCB), graph); /* GTK_CAN_FOCUS allows the <glDrawArea> to receive key events */ GTK_WIDGET_SET_FLAGS(glDrawArea, GTK_CAN_FOCUS); g_signal_connect(G_OBJECT(glDrawArea), "key_press_event", G_CALLBACK(glgdGraphKeyCB), graph); g_signal_connect(G_OBJECT(glDrawArea), "key_release_event", G_CALLBACK(glgdGraphKeyCB), graph); graph->gtkWindow = gtkWindow; graph->gtkGLDrawArea = glDrawArea; #ifdef HAVE_GLGD_PANGO graph->pangoFT2Context = pango_ft2_get_context(_PANGO_DPI, _PANGO_DPI); if (graph->pangoFT2Context == NULL) { printf("pango_ft2_get_context(%d,%d) failed\n", _PANGO_DPI, _PANGO_DPI); glgdGraphFini(graph); return GL_FALSE; } graph->layout = pango_layout_new(graph->pangoFT2Context); #endif /* HAVE_GLGD_PANGO */ return GL_TRUE; } return GL_FALSE; }
void gtk_glwidget_create_font(){ PangoFontDescription *font_desc; PangoLayout *layout; PangoRectangle log_rect; int font_ascent_pango_units; int font_descent_pango_units; if ( _debug_font_created ) { Error( "Programming error: gtk_glwidget_create_font() was already called; " "you must call gtk_glwidget_destroy_font() before creating font again" ); } _debug_font_created = 1; // This call is deprecated so we'll have to fix it sometime. ft2_context = pango_ft2_get_context( 72, 72 ); font_desc = pango_font_description_from_string( font_string ); pango_font_description_set_size( font_desc, font_height * PANGO_SCALE ); pango_context_set_font_description( ft2_context, font_desc ); pango_font_description_free( font_desc ); layout = pango_layout_new( ft2_context ); // I don't believe that's standard preprocessor syntax? #if !PANGO_VERSION_CHECK( 1,22,0 ) PangoLayoutIter *iter; iter = pango_layout_get_iter( layout ); font_ascent_pango_units = pango_layout_iter_get_baseline( iter ); pango_layout_iter_free( iter ); #else font_ascent_pango_units = pango_layout_get_baseline( layout ); #endif pango_layout_get_extents( layout, NULL, &log_rect ); g_object_unref( G_OBJECT( layout ) ); font_descent_pango_units = log_rect.height - font_ascent_pango_units; font_ascent = PANGO_PIXELS_CEIL( font_ascent_pango_units ); font_descent = PANGO_PIXELS_CEIL( font_descent_pango_units ); y_offset_bitmap_render_pango_units = ( font_ascent * PANGO_SCALE ) - font_ascent_pango_units; }
int main (int argc, char **argv) { guint flags = DUMP_ABSOLUTE; int i; PangoContext *context; for (i = 1; i < argc; ++i) { if (strcmp (argv[i], "--factors") == 0) flags |= DUMP_FACTORS; else if (strcmp (argv[i], "--relative") == 0) flags &= ~(DUMP_ABSOLUTE); } #ifdef G_OS_WIN32 context = pango_win32_get_context (); #else context = pango_ft2_get_context(75,75); #endif dump_font_sizes (context, fdopen(1, "wb"), flags); }
static void realize (GtkWidget *widget, gpointer data) { GdkGLContext *glcontext = gtk_widget_get_gl_context (widget); GdkGLDrawable *gldrawable = gtk_widget_get_gl_drawable (widget); GLUquadricObj *qobj; static GLfloat light_diffuse[] = {1.0, 0.0, 0.0, 1.0}; static GLfloat light_position[] = {1.0, 1.0, 1.0, 0.0}; /*** OpenGL BEGIN ***/ if (!gdk_gl_drawable_gl_begin (gldrawable, glcontext)) return; qobj = gluNewQuadric (); gluQuadricDrawStyle (qobj, GLU_FILL); glNewList (1, GL_COMPILE); gluSphere (qobj, 1.0, 20, 20); glEndList (); glLightfv (GL_LIGHT0, GL_DIFFUSE, light_diffuse); glLightfv (GL_LIGHT0, GL_POSITION, light_position); glEnable (GL_LIGHTING); glEnable (GL_LIGHT0); glEnable (GL_DEPTH_TEST); glClearColor (0.0, 0.0, 0.0, 0.0); glClearDepth (1.0); gdk_gl_drawable_gl_end (gldrawable); /*** OpenGL END ***/ /* Get PangoFT2 context. */ ft2_context = pango_ft2_get_context (72, 72); }
unsigned Gosu::pango::textWidth(const std::wstring& text, const std::wstring& fontFace, unsigned fontHeight, unsigned fontFlags) { g_type_init(); int dpi_x = 100, dpi_y = 100; context = pango_ft2_get_context(dpi_x, dpi_y); pango_context_set_language(context, pango_language_from_string ("en_US")); PangoDirection init_dir = PANGO_DIRECTION_LTR; pango_context_set_base_dir(context, init_dir); // static PangoFontDescription *font_description; font_description = pango_font_description_new(); pango_font_description_set_family(font_description, g_strdup(narrow(fontFace).c_str())); pango_font_description_set_style(font_description, (fontFlags & ffItalic) ? PANGO_STYLE_ITALIC : PANGO_STYLE_NORMAL); pango_font_description_set_variant(font_description, PANGO_VARIANT_NORMAL); pango_font_description_set_weight(font_description, (fontFlags & ffBold) ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL); pango_font_description_set_stretch(font_description, PANGO_STRETCH_NORMAL); int init_scale = int(fontHeight/2.0 + 0.5); pango_font_description_set_size(font_description, init_scale * PANGO_SCALE); pango_context_set_font_description(context, font_description); layout = pango_layout_new(context); if(fontFlags & ffUnderline) { // PangoAttribute *attr; attr = pango_attr_underline_new(PANGO_UNDERLINE_SINGLE); attr->start_index = 0; attr->end_index = text.length(); // PangoAttrList* attrList; attrList = pango_attr_list_new(); pango_attr_list_insert(attrList, attr); pango_layout_set_attributes(layout, attrList); pango_attr_list_unref(attrList); } // IMPR: Catch errors? (Last NULL-Pointer) gchar* utf8Str = g_ucs4_to_utf8((gunichar*)text.c_str(), text.length(), NULL, NULL, NULL); pango_layout_set_text(layout, utf8Str, -1); g_free(utf8Str); PangoDirection base_dir = pango_context_get_base_dir(context); pango_layout_set_alignment(layout, base_dir == PANGO_DIRECTION_LTR ? PANGO_ALIGN_LEFT : PANGO_ALIGN_RIGHT); pango_layout_set_width(layout, -1); PangoRectangle logical_rect; pango_layout_get_pixel_extents(layout, NULL, &logical_rect); height = logical_rect.height; width = logical_rect.width; return width; }
PangoContext *paps_get_pango_context() { return pango_ft2_get_context (PAPS_DPI, PAPS_DPI); }