static double get_dpi_from_x_server (void) { GdkScreen *screen; double dpi; screen = gdk_screen_get_default (); if (screen) { double width_dpi, height_dpi; width_dpi = dpi_from_pixels_and_mm (gdk_screen_get_width (screen), gdk_screen_get_width_mm (screen)); height_dpi = dpi_from_pixels_and_mm (gdk_screen_get_height (screen), gdk_screen_get_height_mm (screen)); if (width_dpi < DPI_LOW_REASONABLE_VALUE || width_dpi > DPI_HIGH_REASONABLE_VALUE || height_dpi < DPI_LOW_REASONABLE_VALUE || height_dpi > DPI_HIGH_REASONABLE_VALUE) dpi = DPI_FALLBACK; else dpi = (width_dpi + height_dpi) / 2.0; } else { /* Huh!? No screen? */ dpi = DPI_FALLBACK; } return dpi; }
/* berechnet alle Werte, die man zum Zeichnen eines Koordinatensystems und von Graphen benötigt, anhand der Größe des Feldes, und den maximal erwarteten Werten */ void coord_system_adjust(CoordSystem *coord, GtkWidget *darea, gdouble min_x, gdouble max_x, gdouble min_y, gdouble max_y) { GdkScreen *screen; PangoLayout *layout; gint x_axis, y_axis, cm_x, cm_y; /* bricht ab, wenn der größte Wert niedriger als der Kleinste ist, oder umgekehrt */ if (min_x >= max_x || min_y >= max_y) return; layout = g_object_get_data(G_OBJECT(darea), "layout"); /* rechnet einen Zentimeter in Pixel um */ screen = gdk_screen_get_default(); cm_x = (gint) ((gdouble) (10 * gdk_screen_get_width(screen)) / (gdouble) gdk_screen_get_width_mm(screen) + 0.5); cm_y = (gint) ((gdouble) (10 * gdk_screen_get_height(screen)) / (gdouble) gdk_screen_get_height_mm(screen) + 0.5); /* kopiert die Minimal- und Maximalwerte in die Struktur */ coord->min_x = min_x; coord->max_x = max_x; coord->min_y = min_y; coord->max_y = max_y; /* berechnet die Beginn- und Endpunkte der Achsen */ coord->x_axis_begin = get_y_label_width(coord, layout) + 15; coord->x_axis_end = darea->allocation.width - ARROW_SHANK - get_text_size(WIDTH, layout, "%s [%s]", coord->x_title, coord->x_unit) - 5; coord->y_axis_begin = darea->allocation.height - get_x_label_height(coord, layout) - 15; coord->y_axis_end = ARROW_SHANK + get_text_size(HEIGHT, layout, "%s [%s]", coord->y_title, coord->y_unit) + 10; /* berechnet die Länge der Achsen */ x_axis = ABS(coord->x_axis_end - coord->x_axis_begin); y_axis = ABS(coord->y_axis_end - coord->y_axis_begin); /* berechnet den Faktor zum Umrechnen der Größen */ coord->x_fact = (gdouble) x_axis / (gdouble) (max_x - min_x); coord->y_fact = (gdouble) y_axis / (gdouble) (max_y - min_y); /* errechnet die Schrittgröße der Achsen */ coord->step_x = gen_step_size(2 * cm_x / coord->x_fact, coord->fract_x); coord->step_y = gen_step_size(2 * cm_y / coord->y_fact, coord->fract_y); /* berechnet die Koordinaten des Ursprungs */ coord->zero_x = coord->x_axis_begin - ((gdouble) x_axis * ((gdouble) min_x / (gdouble) (max_x - min_x))); coord->zero_y = coord->y_axis_end + ((gdouble) y_axis * ((gdouble) max_y / (gdouble) (max_y - min_y))); }
cdCtxCanvas *cdgdkCreateCanvas(cdCanvas* canvas, GdkDrawable* wnd, GdkScreen* scr, GdkVisual* vis) { cdCtxCanvas *ctxcanvas = (cdCtxCanvas *)malloc(sizeof(cdCtxCanvas)); memset(ctxcanvas, 0, sizeof(cdCtxCanvas)); ctxcanvas->scr = scr; ctxcanvas->vis = vis; ctxcanvas->wnd = wnd; ctxcanvas->gc = gdk_gc_new(wnd); if (!ctxcanvas->gc) { free(canvas); return NULL; } ctxcanvas->fontcontext = gdk_pango_context_get(); #if PANGO_VERSION_CHECK(1,16,0) pango_context_set_language(ctxcanvas->fontcontext, pango_language_get_default()); #endif ctxcanvas->canvas = canvas; canvas->ctxcanvas = ctxcanvas; gdk_drawable_get_size(wnd, &ctxcanvas->canvas->w, &ctxcanvas->canvas->h); ctxcanvas->depth = gdk_drawable_get_depth(wnd); canvas->bpp = ctxcanvas->depth; canvas->xres = ((double)gdk_screen_get_width(scr) / (double)gdk_screen_get_width_mm(scr)); canvas->yres = ((double)gdk_screen_get_height(scr) / (double)gdk_screen_get_height_mm(scr)); canvas->w_mm = ((double)canvas->w) / canvas->xres; canvas->h_mm = ((double)canvas->h) / canvas->yres; canvas->invert_yaxis = 1; if (canvas->bpp <= 8) { ctxcanvas->colormap = gdk_gc_get_colormap(ctxcanvas->gc); if (!ctxcanvas->colormap) { ctxcanvas->colormap = gdk_colormap_get_system(); gdk_gc_set_colormap(ctxcanvas->gc, ctxcanvas->colormap); } ctxcanvas->num_colors = ctxcanvas->colormap->size; } cdRegisterAttribute(canvas, &gc_attrib); cdRegisterAttribute(canvas, &rotate_attrib); cdRegisterAttribute(canvas, &pangoversion_attrib); cdRegisterAttribute(canvas, &imgdither_attrib); cdRegisterAttribute(canvas, &interp_attrib); return ctxcanvas; }
/** * gimp_get_screen_resolution: * @screen: a #GdkScreen or %NULL * @xres: returns the horizontal screen resolution (in dpi) * @yres: returns the vertical screen resolution (in dpi) * * Retrieves the screen resolution from GDK. If @screen is %NULL, the * default screen is used. **/ void gimp_get_screen_resolution (GdkScreen *screen, gdouble *xres, gdouble *yres) { gint width, height; gint width_mm, height_mm; gdouble x = 0.0; gdouble y = 0.0; g_return_if_fail (screen == NULL || GDK_IS_SCREEN (screen)); g_return_if_fail (xres != NULL); g_return_if_fail (yres != NULL); if (!screen) screen = gdk_screen_get_default (); width = gdk_screen_get_width (screen); height = gdk_screen_get_height (screen); width_mm = gdk_screen_get_width_mm (screen); height_mm = gdk_screen_get_height_mm (screen); /* * From xdpyinfo.c: * * there are 2.54 centimeters to an inch; so there are 25.4 millimeters. * * dpi = N pixels / (M millimeters / (25.4 millimeters / 1 inch)) * = N pixels / (M inch / 25.4) * = N * 25.4 pixels / M inch */ if (width_mm > 0 && height_mm > 0) { x = (width * 25.4) / (gdouble) width_mm; y = (height * 25.4) / (gdouble) height_mm; } if (x < GIMP_MIN_RESOLUTION || x > GIMP_MAX_RESOLUTION || y < GIMP_MIN_RESOLUTION || y > GIMP_MAX_RESOLUTION) { g_warning ("GDK returned bogus values for the screen resolution, " "using 96 dpi instead."); x = 96.0; y = 96.0; } /* round the value to full integers to give more pleasant results */ *xres = ROUND (x); *yres = ROUND (y); }
gdouble ev_document_misc_get_screen_dpi (GdkScreen *screen) { gdouble dp, di; /*diagonal in pixels*/ dp = hypot (gdk_screen_get_width (screen), gdk_screen_get_height (screen)); /*diagonal in inches*/ di = hypot (gdk_screen_get_width_mm(screen), gdk_screen_get_height_mm (screen)) / 25.4; return (dp / di); }
/** * gdk_screen_width_mm: * * Returns the width of the default screen in millimeters. * Note that on many X servers this value will not be correct. * * Return value: the width of the default screen in millimeters, * though it is not always correct. **/ gint gdk_screen_width_mm (void) { return gdk_screen_get_width_mm (gdk_screen_get_default ()); }
static int _s52_init (s52engine *engine) { if ((NULL==engine->eglDisplay) || (EGL_NO_DISPLAY==engine->eglDisplay)) { g_print("_init_S52(): no EGL display ..\n"); return FALSE; } eglQuerySurface(engine->eglDisplay, engine->eglSurface, EGL_WIDTH, &engine->width); eglQuerySurface(engine->eglDisplay, engine->eglSurface, EGL_HEIGHT, &engine->height); // return constant value EGL_UNKNOWN (-1) with Mesa eglQuerySurface(engine->eglDisplay, engine->eglSurface, EGL_HORIZONTAL_RESOLUTION, &engine->wmm); eglQuerySurface(engine->eglDisplay, engine->eglSurface, EGL_VERTICAL_RESOLUTION, &engine->hmm); { // FIXME: broken on some monitor GdkScreen *screen = NULL; gint w,h; gint wmm,hmm; screen = gdk_screen_get_default(); w = gdk_screen_get_width (screen); h = gdk_screen_get_height (screen); wmm = gdk_screen_get_width_mm (screen); hmm = gdk_screen_get_height_mm(screen); //w = 1280; //h = 1024; //w = engine->width; //h = engine->height; //wmm = 376; //hmm = 301; // wrong //hmm = 307; //g_print("_init_S52(): start -1- ..\n"); if (FALSE == S52_init(w, h, wmm, hmm, NULL)) { engine->do_S52init = FALSE; return FALSE; } //g_print("_init_S52(): start -2- ..\n"); S52_setViewPort(0, 0, w, h); } // can be called any time S52_version(); #ifdef S52_USE_EGL S52_setEGLcb((EGL_cb)_egl_beg, (EGL_cb)_egl_end, engine); #endif // read cell location fron s52.cfg //S52_loadCell(NULL, NULL); S52_loadCell("CA479017.000", NULL); S52_loadCell("SCX_CapSante.tif", NULL); S52_setMarinerParam(S52_MAR_DISP_RASTER, 1.0); // Rimouski //S52_loadCell("/home/sduclos/dev/gis/S57/riki-ais/ENC_ROOT/CA579041.000", NULL); //S52_loadCell("/home/vitaly/CHARTS/for_sasha/GB5X01SE.000", NULL); //S52_loadCell("/home/vitaly/CHARTS/for_sasha/GB5X01NE.000", NULL); // Ice - experimental //S52_loadCell("/home/sduclos/dev/gis/data/ice/East_Coast/--0WORLD.shp", NULL); // Bathy - experimental //S52_loadCell("/home/sduclos/dev/gis/data/bathy/2009_HD_BATHY_TRIALS/46307260_LOD2.merc.tif", NULL); //S52_loadCell("/home/sduclos/dev/gis/data/bathy/2009_HD_BATHY_TRIALS/46307250_LOD2.merc.tif", NULL); //S52_setMarinerParam(S52_MAR_DISP_RASTER, 1.0); // load AIS select symb. //S52_loadPLib("plib-test-priv.rle"); #ifdef S52_USE_WORLD // World data if (TRUE == S52_loadCell(PATH "/0WORLD/--0WORLD.shp", NULL)) { //S52_setMarinerParam(S52_MAR_DISP_WORLD, 0.0); // default S52_setMarinerParam(S52_MAR_DISP_WORLD, 1.0); // show world } #endif // debug - remove clutter from this symb in SELECT mode //S52_setS57ObjClassSupp("M_QUAL", TRUE); // supress display of the U pattern //S52_setS57ObjClassSupp("M_QUAL", FALSE); // displaythe U pattern S52_toggleObjClassON ("M_QUAL"); // suppression ON //S52_toggleObjClassOFF("M_QUAL"); // suppression OFF S52_loadPLib(PLIB); S52_loadPLib(COLS); // -- DEPTH COLOR ------------------------------------ S52_setMarinerParam(S52_MAR_TWO_SHADES, 0.0); // 0.0 --> 5 shades //S52_setMarinerParam(S52_MAR_TWO_SHADES, 1.0); // 1.0 --> 2 shades // sounding color //S52_setMarinerParam(S52_MAR_SAFETY_DEPTH, 10.0); S52_setMarinerParam(S52_MAR_SAFETY_DEPTH, 15.0); //S52_setMarinerParam(S52_MAR_SAFETY_CONTOUR, 10.0); S52_setMarinerParam(S52_MAR_SAFETY_CONTOUR, 3.0); //S52_setMarinerParam(S52_MAR_SHALLOW_CONTOUR, 10.0); S52_setMarinerParam(S52_MAR_SHALLOW_CONTOUR, 5.0); //S52_setMarinerParam(S52_MAR_DEEP_CONTOUR, 11.0); S52_setMarinerParam(S52_MAR_DEEP_CONTOUR, 10.0); //S52_setMarinerParam(S52_MAR_SHALLOW_PATTERN, 0.0); // (default off) S52_setMarinerParam(S52_MAR_SHALLOW_PATTERN, 1.0); // ON // -- DEPTH COLOR ------------------------------------ S52_setMarinerParam(S52_MAR_SHIPS_OUTLINE, 1.0); S52_setMarinerParam(S52_MAR_HEADNG_LINE, 1.0); S52_setMarinerParam(S52_MAR_BEAM_BRG_NM, 1.0); //S52_setMarinerParam(S52_MAR_FULL_SECTORS, 0.0); // (default ON) //S52_setMarinerParam(S52_MAR_DISP_CATEGORY, S52_MAR_DISP_CATEGORY_BASE); // always ON //S52_setMarinerParam(S52_MAR_DISP_CATEGORY, S52_MAR_DISP_CATEGORY_STD); // default //S52_setMarinerParam(S52_MAR_DISP_CATEGORY, S52_MAR_DISP_CATEGORY_OTHER); //S52_setMarinerParam(S52_MAR_DISP_CATEGORY, S52_MAR_DISP_CATEGORY_BASE | S52_MAR_DISP_CATEGORY_STD | S52_MAR_DISP_CATEGORY_OTHER); //S52_setMarinerParam(S52_MAR_DISP_CATEGORY, S52_MAR_DISP_CATEGORY_STD | S52_MAR_DISP_CATEGORY_OTHER); S52_setMarinerParam(S52_MAR_DISP_CATEGORY, S52_MAR_DISP_CATEGORY_SELECT); //S52_setMarinerParam(S52_MAR_DISP_LAYER_LAST, S52_MAR_DISP_LAYER_LAST_NONE ); //S52_setMarinerParam(S52_MAR_DISP_LAYER_LAST, S52_MAR_DISP_LAYER_LAST_STD ); // default //S52_setMarinerParam(S52_MAR_DISP_LAYER_LAST, S52_MAR_DISP_LAYER_LAST_OTHER); S52_setMarinerParam(S52_MAR_DISP_LAYER_LAST, S52_MAR_DISP_LAYER_LAST_SELECT); // All Mariner (Standard(default) + Other) //S52_setMarinerParam(S52_MAR_COLOR_PALETTE, 0.0); // DAY (default) //S52_setMarinerParam(S52_MAR_COLOR_PALETTE, 1.0); // DAY DARK S52_setMarinerParam(S52_MAR_COLOR_PALETTE, 5.0); // DAY 60 //S52_setMarinerParam(S52_MAR_COLOR_PALETTE, 6.0); // DUSK 60 //S52_setMarinerParam(S52_MAR_SCAMIN, 1.0); // ON (default) //S52_setMarinerParam(S52_MAR_SCAMIN, 0.0); // debug OFF - show all // remove QUAPNT01 symbole (black diagonal and a '?') S52_setMarinerParam(S52_MAR_QUAPNT01, 0.0); // off S52_setMarinerParam(S52_MAR_DISP_CALIB, 1.0); // --- TEXT ---------------------------------------------- S52_setMarinerParam(S52_MAR_SHOW_TEXT, 1.0); //S52_setMarinerParam(S52_MAR_SHOW_TEXT, 0.0); S52_setTextDisp(0, 100, TRUE); // show all text //S52_setTextDisp(0, 100, FALSE); // no text // cell's legend //S52_setMarinerParam(S52_MAR_DISP_LEGEND, 1.0); // show S52_setMarinerParam(S52_MAR_DISP_LEGEND, 0.0); // hide (default) // ------------------------------------------------------- //S52_setMarinerParam(S52_MAR_DISP_DRGARE_PATTERN, 0.0); // OFF //S52_setMarinerParam(S52_MAR_DISP_DRGARE_PATTERN, 1.0); // ON (default) S52_setMarinerParam(S52_MAR_ANTIALIAS, 1.0); // on //S52_setMarinerParam(S52_MAR_ANTIALIAS, 0.0); // off // a delay of 0.0 to tell to not delete old AIS (default +600 sec old) //S52_setMarinerParam(S52_MAR_DEL_VESSEL_DELAY, 0.0); // debug - use for timing redering //S52_setMarinerParam(S52_CMD_WRD_FILTER, S52_CMD_WRD_FILTER_SY); //S52_setMarinerParam(S52_CMD_WRD_FILTER, S52_CMD_WRD_FILTER_LS); //S52_setMarinerParam(S52_CMD_WRD_FILTER, S52_CMD_WRD_FILTER_LC); //S52_setMarinerParam(S52_CMD_WRD_FILTER, S52_CMD_WRD_FILTER_AC); //S52_setMarinerParam(S52_CMD_WRD_FILTER, S52_CMD_WRD_FILTER_AP); //S52_setMarinerParam(S52_CMD_WRD_FILTER, S52_CMD_WRD_FILTER_TX); // if first start find where we are looking _s52_computeView(&engine->state); // then (re)position the 'camera' S52_setView(engine->state.cLat, engine->state.cLon, engine->state.rNM, engine->state.north); S52_newCSYMB(); // must be first mariners' object so that the // rendering engine place it on top of OWNSHP/VESSEL //_s52_setupVRMEBL(&engine->state); //_s52_setupLEGLIN(); //_s52_setupPRDARE(&engine->state); #ifdef USE_FAKE_AIS _s52_setupVESSEL(&engine->state); _s52_setupOWNSHP(&engine->state); #endif engine->do_S52init = FALSE; engine->do_S52draw = TRUE; engine->do_S52drawLast = TRUE; engine->do_S52setViewPort = FALSE; return EGL_TRUE; }
static void init_no_multihead (GdkScreen *screen, gboolean *changed) { GdkX11Screen *x11_screen = GDK_X11_SCREEN (screen); GdkX11Display *x11_display = GDK_X11_DISPLAY (x11_screen->display); GdkX11Monitor *monitor; GdkRectangle geometry; int i; for (i = 0; i < x11_display->monitors->len; i++) { GdkX11Monitor *monitor = x11_display->monitors->pdata[i]; monitor->add = FALSE; monitor->remove = TRUE; } monitor = find_monitor_by_output (x11_display, 0); if (monitor) monitor->remove = FALSE; else { monitor = g_object_new (gdk_x11_monitor_get_type (), "display", x11_display, NULL); monitor->output = 0; monitor->add = TRUE; g_ptr_array_add (x11_display->monitors, monitor); } gdk_monitor_get_geometry (GDK_MONITOR (monitor), &geometry); if (0 != geometry.x || 0 != geometry.y || gdk_screen_get_width (screen) != geometry.width || gdk_screen_get_height (screen) != geometry.height || gdk_screen_get_width_mm (screen) != gdk_monitor_get_width_mm (GDK_MONITOR (monitor)) || gdk_screen_get_height_mm (screen) != gdk_monitor_get_height_mm (GDK_MONITOR (monitor))) *changed = TRUE; gdk_monitor_set_position (GDK_MONITOR (monitor), 0, 0); gdk_monitor_set_size (GDK_MONITOR (monitor), gdk_screen_get_width (screen), gdk_screen_get_height (screen)); g_object_notify (G_OBJECT (monitor), "workarea"); gdk_monitor_set_physical_size (GDK_MONITOR (monitor), gdk_screen_get_height_mm (screen), gdk_screen_get_height_mm (screen)); gdk_monitor_set_scale_factor (GDK_MONITOR (monitor), x11_screen->window_scale); if (x11_display->primary_monitor != 0) *changed = TRUE; x11_display->primary_monitor = 0; for (i = x11_display->monitors->len - 1; i >= 0; i--) { GdkX11Monitor *monitor = x11_display->monitors->pdata[i]; if (monitor->add) { gdk_display_monitor_added (GDK_DISPLAY (x11_display), GDK_MONITOR (monitor)); *changed = TRUE; } else if (monitor->remove) { g_object_ref (monitor); g_ptr_array_remove (x11_display->monitors, monitor); gdk_display_monitor_removed (GDK_DISPLAY (x11_display), GDK_MONITOR (monitor)); g_object_unref (monitor); *changed = TRUE; } } }
/** \brief Screen and Display size - returns the physical screen size in millimeters geometry -returns the logicaL screen size in pixels \author William J Giddings \date 03-Jan-2010 **/ int gnoclScreenCmd ( ClientData data, Tcl_Interp *interp, int objc, Tcl_Obj * const objv[] ) { static const char *cmd[] = { "size", "geometry", "name", "screens", "composited", "windowList", "toplevels", NULL }; enum optIdx { SizeIdx, GeometryIdx, NameIdx, ScreensIdx, CompositedIdx, WindowListIdx, TopLevelsIdx }; int idx; if ( objc != 2 ) { Tcl_WrongNumArgs ( interp, 1, objv, "option " ); return TCL_ERROR; } if ( Tcl_GetIndexFromObj ( interp, objv[1], cmd, "option", TCL_EXACT, &idx ) != TCL_OK ) { return TCL_ERROR; } /* display = gdk_display_get_default (); num_screen = gdk_display_get_n_screens (display); displayname = gdk_display_get_name (display); */ switch ( idx ) { case TopLevelsIdx: case WindowListIdx: { gchar buffer[16]; GdkScreen *screen; GSList *toplevels, *p; gchar *widgetName; screen = gdk_screen_get_default(); toplevels = gdk_screen_get_toplevel_windows ( screen ); /* check to see if the windows are registered with gnocl */ for ( p = toplevels; p != NULL ; p = p->next ) { /* this returns GDKWindow, not Gtk */ widgetName = gnoclGetNameFromWidget ( GTK_WIDGET ( p->data ) ); printf ( "toplevel %s\n", widgetName ); if ( widgetName != NULL ) { printf ( "toplevel %s\n", widgetName ); } else { printf ( "Missed this one! List length = %d\n", g_slist_length ( toplevels ) ); printf ( "toplevel %s\n", widgetName ); } } gboolean state = 0; sprintf ( &buffer, "%d", state ); Tcl_SetObjResult ( interp, Tcl_NewIntObj ( state ) ); } break; case CompositedIdx: { gchar buffer[16]; GdkScreen *screen; gboolean state; screen = gdk_screen_get_default(); state = gdk_screen_is_composited ( screen ); sprintf ( &buffer, "%d", state ); Tcl_SetObjResult ( interp, Tcl_NewIntObj ( state ) ); } break; case ScreensIdx: { gchar buffer[16]; GdkDisplay *display; display = gdk_display_get_default (); gint screens = gdk_display_get_n_screens ( display ); sprintf ( &buffer, "%d", screens ); Tcl_SetObjResult ( interp, Tcl_NewStringObj ( buffer, -1 ) ); } break; case NameIdx: { gchar buffer[16]; GdkDisplay *display; const gchar *name; display = gdk_display_get_default (); name = gdk_display_get_name ( display ); sprintf ( &buffer, "%s", name ); Tcl_SetObjResult ( interp, Tcl_NewStringObj ( buffer, -1 ) ); } break; case SizeIdx: { gchar buffer[16]; gint width_mm = 0; gint height_mm = 0; GdkScreen *screen; screen = gdk_screen_get_default(); width_mm = gdk_screen_get_width_mm ( screen ); height_mm = gdk_screen_get_height_mm ( screen ); sprintf ( &buffer, "%d %d", width_mm, height_mm ); Tcl_SetObjResult ( interp, Tcl_NewStringObj ( buffer, -1 ) ); } break; case GeometryIdx: { gchar buffer[16]; gint width = 0; gint height = 0; GdkScreen *screen; screen = gdk_screen_get_default(); width = gdk_screen_get_width ( screen ); height = gdk_screen_get_height ( screen ); sprintf ( &buffer, "%d %d", width, height ); Tcl_SetObjResult ( interp, Tcl_NewStringObj ( buffer, -1 ) ); } break; } return TCL_OK; }
static IgtkFont* gtkFindFont(const char *standardfont) { PangoFontMetrics* metrics; PangoFontDescription* fontdesc; int i, is_underline = 0, is_strikeout = 0, count = iupArrayCount(gtk_fonts); IgtkFont* fonts = (IgtkFont*)iupArrayGetData(gtk_fonts); /* Check if the standardfont already exists in cache */ for (i = 0; i < count; i++) { if (iupStrEqualNoCase(standardfont, fonts[i].standardfont)) return &fonts[i]; } /* not found, create a new one */ { int size; int is_bold = 0, is_italic = 0; char typeface[1024]; char *new_standardfont = NULL; const char* mapped_name; if (!iupFontParsePango(standardfont, typeface, &size, &is_bold, &is_italic, &is_underline, &is_strikeout)) return NULL; mapped_name = iupFontGetPangoName(typeface); if (mapped_name) strcpy(typeface, mapped_name); if (is_underline || is_strikeout || size<0) new_standardfont = iupStrDup(standardfont); if (is_underline) { char* under = strstr(standardfont, "Underline"); int len = strlen(standardfont); int len1 = (size_t)(under-standardfont); memcpy(new_standardfont, standardfont, len1); memcpy(new_standardfont+len1, under+9+1, len-len1-9+1); /* strlen("Underline") */ standardfont = new_standardfont; } if (is_strikeout) { char* strike = strstr(standardfont, "Strikeout"); int len = strlen(standardfont); int len1 = (size_t)(strike-standardfont); memcpy(new_standardfont, standardfont, len1); memcpy(new_standardfont+len1, strike+9+1, len-len1-9+1); /* strlen("Strikeout") */ standardfont = new_standardfont; } if (size<0) { double res; int len1, len2; char *sz, size_str[10]; sprintf(size_str, "%d", size); sz = strstr(standardfont, size_str); len1 = (size_t)(sz-standardfont); res = ((double)gdk_screen_get_width(gdk_screen_get_default()) / (double)gdk_screen_get_width_mm(gdk_screen_get_default())); /* pixels/mm */ /* 1 point = 1/72 inch 1 inch = 25.4 mm */ /* pixel = ((point/72)*25.4)*pixel/mm */ size = (int)((-size/res)*2.83464567 + 0.5); /* from pixels to points */ len2 = sprintf(size_str, "%d", size); memcpy(new_standardfont, standardfont, len1); memcpy(new_standardfont+len1, size_str, len2+1); } fontdesc = pango_font_description_from_string(standardfont); if (new_standardfont) free(new_standardfont); } if (!fontdesc) return NULL; /* create room in the array */ fonts = (IgtkFont*)iupArrayInc(gtk_fonts); strcpy(fonts[i].standardfont, standardfont); fonts[i].fontdesc = fontdesc; fonts[i].strikethrough = pango_attr_strikethrough_new(is_strikeout? TRUE: FALSE); fonts[i].underline = pango_attr_underline_new(is_underline? PANGO_UNDERLINE_SINGLE: PANGO_UNDERLINE_NONE); fonts[i].layout = pango_layout_new(gtk_fonts_context); metrics = pango_context_get_metrics(gtk_fonts_context, fontdesc, pango_context_get_language(gtk_fonts_context)); fonts[i].charheight = pango_font_metrics_get_ascent(metrics) + pango_font_metrics_get_descent(metrics); fonts[i].charheight = IUPGTK_PANGOUNITS2PIXELS(fonts[i].charheight); fonts[i].charwidth = pango_font_metrics_get_approximate_char_width(metrics); fonts[i].charwidth = IUPGTK_PANGOUNITS2PIXELS(fonts[i].charwidth); pango_font_metrics_unref(metrics); gtkFontUpdate(&(fonts[i])); return &fonts[i]; }
static IgtkFont* gtkFindFont(const char *standardfont) { PangoFontMetrics* metrics; PangoFontDescription* fontdesc; int i, is_underline = 0, is_strikeout = 0, count = iupArrayCount(gtk_fonts); IgtkFont* fonts = (IgtkFont*)iupArrayGetData(gtk_fonts); /* Check if the standardfont already exists in cache */ for (i = 0; i < count; i++) { if (iupStrEqualNoCase(standardfont, fonts[i].standardfont)) return &fonts[i]; } /* not found, create a new one */ { int size = 0, is_pango = 0; int is_bold = 0, is_italic = 0; char typeface[1024]; const char* mapped_name; /* parse the old Windows format first */ if (!iupFontParseWin(standardfont, typeface, &size, &is_bold, &is_italic, &is_underline, &is_strikeout)) { if (!iupFontParseX(standardfont, typeface, &size, &is_bold, &is_italic, &is_underline, &is_strikeout)) { if (!iupFontParsePango(standardfont, typeface, &size, &is_bold, &is_italic, &is_underline, &is_strikeout)) return NULL; else is_pango = 1; } } mapped_name = iupFontGetPangoName(typeface); if (mapped_name) strcpy(typeface, mapped_name); if (is_pango && !is_underline && !is_strikeout && size>0) fontdesc = pango_font_description_from_string(standardfont); else { char new_standardfont[200]; if (size<0) { double res = ((double)gdk_screen_get_width(gdk_screen_get_default()) / (double)gdk_screen_get_width_mm(gdk_screen_get_default())); /* pixels/mm */ /* 1 point = 1/72 inch 1 inch = 25.4 mm */ /* pixel = ((point/72)*25.4)*pixel/mm */ size = (int)((-size/res)*2.83464567 + 0.5); /* from pixels to points */ } sprintf(new_standardfont, "%s, %s%s%d", typeface, is_bold?"Bold ":"", is_italic?"Italic ":"", size); fontdesc = pango_font_description_from_string(new_standardfont); } } if (!fontdesc) return NULL; /* create room in the array */ fonts = (IgtkFont*)iupArrayInc(gtk_fonts); strcpy(fonts[i].standardfont, standardfont); fonts[i].fontdesc = fontdesc; fonts[i].strikethrough = pango_attr_strikethrough_new(is_strikeout? TRUE: FALSE); fonts[i].underline = pango_attr_underline_new(is_underline? PANGO_UNDERLINE_SINGLE: PANGO_UNDERLINE_NONE); fonts[i].layout = pango_layout_new(gtk_fonts_context); metrics = pango_context_get_metrics(gtk_fonts_context, fontdesc, pango_context_get_language(gtk_fonts_context)); fonts[i].charheight = pango_font_metrics_get_ascent(metrics) + pango_font_metrics_get_descent(metrics); fonts[i].charheight = IUPGTK_PANGOUNITS2PIXELS(fonts[i].charheight); fonts[i].charwidth = pango_font_metrics_get_approximate_char_width(metrics); fonts[i].charwidth = IUPGTK_PANGOUNITS2PIXELS(fonts[i].charwidth); pango_font_metrics_unref(metrics); gtkFontUpdate(&(fonts[i])); return &fonts[i]; }