/** * gtk_psfont_get_by_gdkfont: * @font: a #GtkPSFont * @height: font height * * Get #GdkFOnt by PS Font. * * Returns: a #GdkFont pointer. */ GdkFont * gtk_psfont_get_gdkfont(GtkPSFont *font, gint height) { PangoFontDescription *font_desc; GdkFont *gdkfont; g_return_val_if_fail (font != NULL, NULL); if (height <= 0) height = 1; font_desc = gtk_psfont_get_font_description(font, height); gdkfont = font_desc ? gdk_font_from_description(font_desc) : NULL; if (font_desc) pango_font_description_free(font_desc); if (!gdkfont) { font_desc = gtk_psfont_get_font_description(find_psfont(default_font), height); gdkfont = font_desc ? gdk_font_from_description(font_desc) : NULL; if (font_desc) pango_font_description_free(font_desc); if (gdkfont) g_message ("Pango font %s %i (PS font %s) not found, using %s instead.", font->pango_description, height, font->fontname, default_font); else g_warning ("Error, couldn't locate default font. Shouldn't happen."); } return gdkfont; }
/* subfunction of gtk_plot_cairo_draw_string(). */ static gint drawstring(GtkPlotPC *pc, gint angle, gint dx, gint dy, GtkPSFont *psfont, gint height, const gchar *text) { cairo_t *cairo = GTK_PLOT_CAIRO(pc)->cairo; PangoLayout *layout = GTK_PLOT_CAIRO(pc)->layout; PangoFontDescription *font; PangoRectangle rect; PangoFontMap *map; gint ret_value; gint dpi_cairo, dpi_screen; GdkScreen *screen = gdk_screen_get_default(); if(!text || strlen(text) == 0) return 0; cairo_save(cairo); map = pango_cairo_font_map_get_default(); dpi_cairo = pango_cairo_font_map_get_resolution(PANGO_CAIRO_FONT_MAP(map)); dpi_screen = gdk_screen_get_resolution(screen); height *= (double)dpi_screen/(double)dpi_cairo; font = gtk_psfont_get_font_description(psfont, height); pango_layout_set_font_description(GTK_PLOT_CAIRO(pc)->layout, font); pango_layout_set_text(GTK_PLOT_CAIRO(pc)->layout, text, strlen(text)); pango_layout_get_extents(GTK_PLOT_CAIRO(pc)->layout, NULL, &rect); if (psfont->i18n_latinfamily && psfont->vertical) { /* vertical-writing CJK postscript fonts. */ return rect.height; } else { /* horizontal writing */ if(angle == 90) // cairo_translate(cairo, dx, dy-PANGO_PIXELS(rect.width)); cairo_translate(cairo, dx, dy); else if(angle == 270) cairo_translate(cairo, dx+PANGO_PIXELS(rect.height), dy); else if(angle == 180) cairo_translate(cairo, dx-PANGO_PIXELS(rect.width), dy); else cairo_translate(cairo, dx, dy); } cairo_rotate(cairo, -angle * G_PI / 180); pango_cairo_update_layout(cairo, layout); pango_cairo_show_layout(cairo, layout); cairo_restore(cairo); pango_font_description_free(font); ret_value = (angle == 0 || angle == 180) ? rect.width : rect.height; return PANGO_PIXELS(rect.width); }
/* subfunction of gtk_plot_gdk_draw_string(). */ static gint drawstring(GtkPlotPC *pc, GdkDrawable *drawable, GdkGC *gc, gint angle, gint dx, gint dy, GtkPSFont *psfont, gint height, const gchar *text) { PangoFontDescription *font; PangoRectangle rect; const gchar *aux = text; gint ret_value; if(!text || strlen(text) == 0) return 0; font = gtk_psfont_get_font_description(psfont, height); pango_layout_set_font_description(GTK_PLOT_GDK(pc)->layout, font); pango_layout_set_text(GTK_PLOT_GDK(pc)->layout, text, strlen(text)); pango_layout_get_extents(GTK_PLOT_GDK(pc)->layout, NULL, &rect); if (psfont->i18n_latinfamily && psfont->vertical) { /* vertical-writing CJK postscript fonts. */ return rect.height; } else { /* horizontal writing */ if(angle == 90) gdk_draw_layout (drawable, gc, dx, dy-PANGO_PIXELS(rect.width), GTK_PLOT_GDK(pc)->layout); else if(angle == 180) gdk_draw_layout (drawable, gc, dx-PANGO_PIXELS(rect.width), dy, GTK_PLOT_GDK(pc)->layout); else gdk_draw_layout (drawable, gc, dx, dy, GTK_PLOT_GDK(pc)->layout); /* gdk_draw_layout (GTK_PLOT_GDK(pc)->drawable, gc, dx, dy, GTK_PLOT_GDK(pc)->layout); */ } pango_font_description_free(font); ret_value = (angle == 0 || angle == 180) ? rect.width : rect.height; return PANGO_PIXELS(rect.width); }
static void gtk_plot_cairo_draw_string (GtkPlotPC *pc, gint tx, gint ty, gint angle, const GdkColor *fg, const GdkColor *bg, gboolean transparent, gint border, gint border_space, gint border_width, gint shadow_width, const gchar *font_name, gint font_height, GtkJustification just, const gchar *text) { cairo_t *cairo = GTK_PLOT_CAIRO(pc)->cairo; GList *family = NULL; gint x0, y0; gint old_width, old_height; gboolean bold, italic; gint fontsize; gint ascent, descent; gint numf; gint width, height; gint x, y; gint i; PangoFontDescription *font = NULL, *latin_font = NULL; GtkPSFont *psfont, *base_psfont, *latin_psfont; gchar subs[2], insert_char; const gchar *aux = text; const gchar *lastchar = text; const gchar *wtext = text; const gchar *xaux = text; gchar *new_text; /* Support Tiny C compiler : Original : gchar new_text[strlen(text)+1];*/ gchar num[4]; PangoRectangle rect; PangoLayout *layout = NULL; gint real_x, real_y, real_width, real_height; GdkColor real_fg = *fg; GdkColor real_bg = *bg; gint sign_x = 1, sign_y = 0; gint old_tx = tx, old_ty = ty; if (!cairo) return; layout = GTK_PLOT_CAIRO(pc)->layout; cairo_save(cairo); gtk_plot_cairo_set_color(pc, fg); /* font_name = "sans"; desc = pango_font_description_from_string(font_name); // Since the name does not contain the size yet... Also there is some // factor that I have to figure out... pango_font_description_set_size (desc, font_height *0.9 * PANGO_SCALE); pango_layout_set_font_description(layout, desc); pango_layout_set_text(layout, text, -1); cairo_save(cairo); cairo_translate(cairo, tx, ty); cairo_rotate(cairo, angle * G_PI / 180); gtk_plot_cairo_set_color(pc, fg); pango_cairo_update_layout(cairo, layout); PangoFontMetrics *metrics = NULL; metrics = pango_context_get_metrics(pango_layout_get_context(layout), desc, gtk_get_default_language()); pango_layout_get_size (layout, &width, &height); ascent = pango_font_metrics_get_ascent(metrics); descent = pango_font_metrics_get_descent(metrics); if (just == GTK_JUSTIFY_RIGHT) cairo_move_to(cairo, -PANGO_PIXELS(width), -PANGO_PIXELS(ascent) ); else if (just == GTK_JUSTIFY_CENTER) cairo_move_to(cairo, -PANGO_PIXELS(width)/2.0, -PANGO_PIXELS(ascent) ); else if (just == GTK_JUSTIFY_LEFT) cairo_move_to(cairo, 0, -PANGO_PIXELS(ascent) ); pango_cairo_show_layout(cairo, layout); cairo_restore(cairo); */ gtk_plot_text_get_size(text, angle, font_name, font_height, &width, &height, &ascent, &descent); if(height == 0 || width == 0) return; old_width = width; old_height = height; if(angle == 90 || angle == 270) { old_width = height; old_height = width; } switch(angle){ case 90: sign_x = 0; sign_y = -1; break; case 180: sign_x = -1; sign_y = 0; break; case 270: sign_x = 0; sign_y = 1; break; case 0: default: sign_x = 1; sign_y = 0; break; } switch(just){ case GTK_JUSTIFY_LEFT: switch(angle){ case 0: ty -= ascent; break; case 90: ty -= height; tx -= ascent; break; case 180: tx -= width; ty -= descent; break; case 270: tx -= descent; break; } old_tx = tx; old_ty = ty; break; case GTK_JUSTIFY_RIGHT: switch(angle){ case 0: tx -= width; ty -= ascent; old_tx -= width; old_ty -= ascent; break; case 90: tx -= ascent; ty += height; old_tx -= ascent; break; case 180: tx += width; ty -= descent; old_ty -= descent; break; case 270: tx -= descent; old_tx -= descent; old_ty -= height; break; } break; case GTK_JUSTIFY_CENTER: default: switch(angle){ case 0: tx -= width / 2.; ty -= ascent; old_tx -= width / 2.; old_ty -= ascent; break; case 90: tx -= ascent; ty += height / 2.; old_tx -= ascent; old_ty -= height / 2.; break; case 180: tx += width / 2.; ty -= descent; old_tx -= width / 2.; old_ty -= descent; break; case 270: tx -= descent; ty -= height / 2.; old_tx -= descent; old_ty -= height / 2.; break; } } real_x = tx; real_y = ty; real_width = width; real_height = height; if(!transparent){ gtk_plot_cairo_set_color(pc, &real_bg); gtk_plot_cairo_draw_rectangle(pc, TRUE, old_tx, old_ty, old_width, old_height); } gtk_psfont_get_families(&family, &numf); base_psfont = psfont = gtk_psfont_get_by_name(font_name); font = gtk_psfont_get_font_description(psfont, font_height); italic = psfont->italic; bold = psfont->bold; fontsize = font_height; x0 = x = 0; y0 = y = 0; if (psfont->i18n_latinfamily) { latin_psfont = gtk_psfont_get_by_family(psfont->i18n_latinfamily, italic, bold); if(latin_font) pango_font_description_free(latin_font); latin_font = gtk_psfont_get_font_description(latin_psfont, fontsize); } else { latin_psfont = NULL; latin_font = NULL; } gtk_plot_cairo_set_color(pc, &real_fg); aux = text; while(aux && *aux != '\0' && *aux != '\n'){ if(*aux == '\\'){ aux = g_utf8_next_char(aux); switch(*aux){ case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '9': psfont = gtk_psfont_get_by_family((gchar *)g_list_nth_data(family, *aux-'0'), italic, bold); pango_font_description_free(font); font = gtk_psfont_get_font_description(psfont, fontsize); aux = g_utf8_next_char(aux); break; case '8': case 'g': psfont = gtk_psfont_get_by_family("Symbol", italic, bold); pango_font_description_free(font); font = gtk_psfont_get_font_description(psfont, fontsize); aux = g_utf8_next_char(aux); break; case 'B': bold = TRUE; psfont = gtk_psfont_get_by_family(psfont->family, italic, bold); pango_font_description_free(font); font = gtk_psfont_get_font_description(psfont, fontsize); if(latin_font){ latin_font = NULL; } if (psfont->i18n_latinfamily) { latin_psfont = gtk_psfont_get_by_family(psfont->i18n_latinfamily, italic, bold); if(latin_font) pango_font_description_free(latin_font); latin_font = gtk_psfont_get_font_description(latin_psfont, fontsize); } aux = g_utf8_next_char(aux); break; case 'x': xaux = aux + 1; for (i=0; i<3; i++){ if (xaux[i] >= '0' && xaux[i] <= '9') num[i] = xaux[i]; else break; } if (i < 3){ aux = g_utf8_next_char(aux); break; } num[3] = '\0'; insert_char = (gchar)atoi(num); subs[0] = insert_char; subs[1] = '\0'; pango_layout_set_font_description(layout, font); pango_layout_set_text(layout, subs, 1); pango_layout_get_extents(layout, NULL, &rect); x += sign_x*PANGO_PIXELS(rect.width); y += sign_y*PANGO_PIXELS(rect.width); aux += 4; lastchar = aux - 1; break; case 'i': italic = TRUE; psfont = gtk_psfont_get_by_family(psfont->family, italic, bold); pango_font_description_free(font); font = gtk_psfont_get_font_description(psfont, fontsize); if (psfont->i18n_latinfamily) { latin_psfont = gtk_psfont_get_by_family(psfont->i18n_latinfamily, italic, bold); if(latin_font) pango_font_description_free(latin_font); latin_font = gtk_psfont_get_font_description(latin_psfont, fontsize); } aux = g_utf8_next_char(aux); break; case 'S': case '^': fontsize = (int)((gdouble)fontsize * 0.6 + 0.5); pango_font_description_free(font); font = gtk_psfont_get_font_description(psfont, fontsize); if (psfont->i18n_latinfamily) { latin_font = gtk_psfont_get_font_description(latin_psfont, fontsize); } if(angle == 180) y = y0 + fontsize; else if(angle == 270) x = x0 + sign_y*fontsize; aux = g_utf8_next_char(aux); break; case 's': case '_': fontsize = (int)((gdouble)fontsize * 0.6 + 0.5); pango_font_description_free(font); font = gtk_psfont_get_font_description(psfont, fontsize); if(angle == 0) y = y0 + fontsize; else if(angle == 90) x = x0 - sign_y*fontsize; if (psfont->i18n_latinfamily) { latin_font = gtk_psfont_get_font_description(latin_psfont, fontsize); } aux = g_utf8_next_char(aux); break; case '+': fontsize += 3; y -= sign_x*3; x += sign_y*3; pango_font_description_free(font); font = gtk_psfont_get_font_description(psfont, fontsize); if (psfont->i18n_latinfamily) { latin_font = gtk_psfont_get_font_description(latin_psfont, fontsize); } aux = g_utf8_next_char(aux); break; case '-': fontsize -= 3; y += sign_x*3; x -= sign_y*3; pango_font_description_free(font); font = gtk_psfont_get_font_description(psfont, fontsize); if (psfont->i18n_latinfamily) { latin_font = gtk_psfont_get_font_description(latin_psfont, fontsize); } aux = g_utf8_next_char(aux); break; case 'N': psfont = base_psfont; fontsize = font_height; pango_font_description_free(font); font = gtk_psfont_get_font_description(psfont, fontsize); if(angle == 0 || angle == 180) y = y0; else x = x0; italic = psfont->italic; bold = psfont->bold; aux = g_utf8_next_char(aux); break; case 'b': if (lastchar) { const gchar *aux2 = lastchar; gint i = g_utf8_prev_char(lastchar) != --aux2 ? 2 : 1; pango_layout_set_text(layout, lastchar, i); pango_layout_get_extents(layout, NULL, &rect); x -= sign_x*PANGO_PIXELS(rect.width); y -= sign_y*PANGO_PIXELS(rect.width); if (lastchar == wtext) lastchar = NULL; else lastchar = g_utf8_prev_char(lastchar); } else { pango_layout_set_text(layout, "X", 1); pango_layout_get_extents(layout, NULL, &rect); x -= sign_x*PANGO_PIXELS(rect.width); y -= sign_y*PANGO_PIXELS(rect.width); } aux = g_utf8_next_char(aux); break; default: if(aux && *aux != '\0' && *aux !='\n'){ gint new_width = 0; new_width = drawstring(pc, angle, tx+x, ty+y, psfont, fontsize, aux); x += sign_x * new_width; y += sign_y * new_width; lastchar = aux; aux = g_utf8_next_char(aux); } break; } } else { gint new_len = 0; gint new_width = 0; lastchar = aux; while(aux && *aux != '\0' && *aux !='\n' && *aux != '\\'){ xaux = aux; new_len += g_utf8_next_char(aux) != ++xaux ? 2 : 1; aux = g_utf8_next_char(aux); } xaux = lastchar; new_text = (gchar *) g_new0(gchar , strlen(text)+1); /* Tiny C Compiler support */ for(i = 0; i < new_len; i++) new_text[i] = *xaux++; new_text[new_len] = '\0'; new_width = drawstring(pc, angle, tx+x, ty+y, psfont, fontsize, new_text); x += sign_x * new_width; y += sign_y * new_width; lastchar = aux; g_free (new_text); } } if(latin_font) pango_font_description_free(latin_font); /* border */ gtk_plot_cairo_set_color(pc, &real_fg); gtk_plot_pc_set_dash(pc, 0, NULL, 0); gtk_plot_pc_set_lineattr(pc, border_width, 0, 0, 0); switch(border){ case GTK_PLOT_BORDER_SHADOW: gtk_plot_pc_draw_rectangle(pc, TRUE, old_tx - border_space + shadow_width, old_ty + height + border_space, width + 2 * border_space, shadow_width); gtk_plot_pc_draw_rectangle(pc, TRUE, old_tx + width + border_space, old_ty - border_space + shadow_width, shadow_width, height + 2 * border_space); case GTK_PLOT_BORDER_LINE: gtk_plot_pc_draw_rectangle(pc, FALSE, old_tx - border_space, old_ty - border_space, width + 2*border_space, height + 2*border_space); case GTK_PLOT_BORDER_NONE: default: break; } cairo_restore(cairo); return; }
static void gtk_plot_gdk_draw_string (GtkPlotPC *pc, gint tx, gint ty, gint angle, const GdkColor *fg, const GdkColor *bg, gboolean transparent, gint border, gint border_space, gint border_width, gint shadow_width, const gchar *font_name, gint font_height, GtkJustification just, const gchar *text) { GdkGC *gc; GList *family = NULL; gint x0, y0; gint old_width, old_height; gboolean bold, italic; gint fontsize; gint ascent, descent; gint numf; gint width, height; gint x, y; gint i; PangoFontDescription *font = NULL, *latin_font = NULL; GtkPSFont *psfont, *base_psfont, *latin_psfont; gchar subs[2], insert_char; const gchar *aux = text; const gchar *lastchar = text; const gchar *wtext = text; const gchar *xaux = text; gchar new_text[strlen(text)+1]; gchar num[4]; PangoRectangle rect; PangoFontMetrics *metrics = NULL; PangoLayout *layout = NULL; gint real_x, real_y, real_width, real_height; GdkColor real_fg = *fg; GdkColor real_bg = *bg; PangoMatrix matrix = PANGO_MATRIX_INIT; PangoContext *context = GTK_PLOT_GDK(pc)->context; GdkDrawable *drawable = GTK_PLOT_GDK(pc)->drawable; gint sign_x = 1, sign_y = 0; if(!GTK_PLOT_GDK(pc)->drawable) return; if(!GTK_PLOT_GDK(pc)->gc) return; if(!text || strlen(text) == 0) return; gc = GTK_PLOT_GDK(pc)->gc; layout = GTK_PLOT_GDK(pc)->layout; if(!gc) return; gtk_plot_text_get_size(text, angle, font_name, font_height, &width, &height, &ascent, &descent); if(height == 0 || width == 0) return; old_width = width; old_height = height; if(angle == 90 || angle == 270) { old_width = height; old_height = width; } switch(angle){ case 90: sign_x = 0; sign_y = -1; break; case 180: sign_x = -1; sign_y = 0; break; case 270: sign_x = 0; sign_y = 1; break; case 0: default: sign_x = 1; sign_y = 0; break; } switch(just){ case GTK_JUSTIFY_LEFT: switch(angle){ case 0: ty -= ascent; break; case 90: ty -= height; tx -= ascent; break; case 180: tx -= width; ty -= descent; break; case 270: tx -= descent; break; } break; case GTK_JUSTIFY_RIGHT: switch(angle){ case 0: tx -= width; ty -= ascent; break; case 90: tx -= ascent; ty += height; break; case 180: tx += width; ty -= descent; break; case 270: tx -= descent; break; } break; case GTK_JUSTIFY_CENTER: default: switch(angle){ case 0: tx -= width / 2.; ty -= ascent; break; case 90: tx -= ascent; ty += height / 2.; break; case 180: tx += width / 2.; ty -= descent; break; case 270: tx -= descent; ty -= height / 2.; break; } } real_x = tx; real_y = ty; real_width = width; real_height = height; pango_matrix_rotate (&matrix, angle); pango_context_set_matrix (context, &matrix); pango_layout_context_changed (layout); if(!transparent){ gdk_gc_set_foreground(gc, &real_bg); gdk_draw_rectangle(drawable, gc, TRUE, tx, ty, old_width, old_height); } /* TEST */ /* gdk_draw_rectangle(text_pixmap, gc, FALSE, 0, 0, old_width-1, old_height-1); */ gtk_psfont_get_families(&family, &numf); base_psfont = psfont = gtk_psfont_get_by_name(font_name); font = gtk_psfont_get_font_description(psfont, font_height); italic = psfont->italic; bold = psfont->bold; fontsize = font_height; x0 = x = 0; y0 = y = 0; if (psfont->i18n_latinfamily) { latin_psfont = gtk_psfont_get_by_family(psfont->i18n_latinfamily, italic, bold); if(latin_font) pango_font_description_free(latin_font); latin_font = gtk_psfont_get_font_description(latin_psfont, fontsize); } else { latin_psfont = NULL; latin_font = NULL; } gdk_gc_set_foreground(gc, &real_fg); aux = text; while(aux && *aux != '\0' && *aux != '\n'){ if(*aux == '\\'){ aux = g_utf8_next_char(aux); switch(*aux){ case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '9': psfont = gtk_psfont_get_by_family((gchar *)g_list_nth_data(family, *aux-'0'), italic, bold); pango_font_description_free(font); font = gtk_psfont_get_font_description(psfont, fontsize); aux = g_utf8_next_char(aux); break; case '8': case 'g': psfont = gtk_psfont_get_by_family("Symbol", italic, bold); pango_font_description_free(font); font = gtk_psfont_get_font_description(psfont, fontsize); aux = g_utf8_next_char(aux); break; case 'B': bold = TRUE; psfont = gtk_psfont_get_by_family(psfont->family, italic, bold); pango_font_description_free(font); font = gtk_psfont_get_font_description(psfont, fontsize); if(latin_font){ latin_font = NULL; } if (psfont->i18n_latinfamily) { latin_psfont = gtk_psfont_get_by_family(psfont->i18n_latinfamily, italic, bold); if(latin_font) pango_font_description_free(latin_font); latin_font = gtk_psfont_get_font_description(latin_psfont, fontsize); } aux = g_utf8_next_char(aux); break; case 'x': xaux = aux + 1; for (i=0; i<3; i++){ if (xaux[i] >= '0' && xaux[i] <= '9') num[i] = xaux[i]; else break; } if (i < 3){ aux = g_utf8_next_char(aux); break; } num[3] = '\0'; insert_char = (gchar)atoi(num); subs[0] = insert_char; subs[1] = '\0'; pango_layout_set_font_description(layout, font); pango_layout_set_text(layout, subs, 1); pango_layout_get_extents(layout, NULL, &rect); x += sign_x*PANGO_PIXELS(rect.width); y += sign_y*PANGO_PIXELS(rect.width); aux += 4; lastchar = aux - 1; break; case 'i': italic = TRUE; psfont = gtk_psfont_get_by_family(psfont->family, italic, bold); pango_font_description_free(font); font = gtk_psfont_get_font_description(psfont, fontsize); if (psfont->i18n_latinfamily) { latin_psfont = gtk_psfont_get_by_family(psfont->i18n_latinfamily, italic, bold); if(latin_font) pango_font_description_free(latin_font); latin_font = gtk_psfont_get_font_description(latin_psfont, fontsize); } aux = g_utf8_next_char(aux); break; case 'S': case '^': fontsize = (int)((gdouble)fontsize * 0.6 + 0.5); pango_font_description_free(font); font = gtk_psfont_get_font_description(psfont, fontsize); if(metrics) pango_font_metrics_unref(metrics); metrics = pango_context_get_metrics(pango_layout_get_context(layout), font, pango_context_get_language(pango_layout_get_context(layout))); if (psfont->i18n_latinfamily) { latin_font = gtk_psfont_get_font_description(latin_psfont, fontsize); } if(angle == 180) y = y0 + fontsize; else if(angle == 270) x = x0 + sign_y*fontsize; aux = g_utf8_next_char(aux); break; case 's': case '_': fontsize = (int)((gdouble)fontsize * 0.6 + 0.5); pango_font_description_free(font); font = gtk_psfont_get_font_description(psfont, fontsize); if(metrics) pango_font_metrics_unref(metrics); metrics = pango_context_get_metrics(pango_layout_get_context(layout), font, pango_context_get_language(pango_layout_get_context(layout))); if(angle == 0) y = y0 + fontsize; else if(angle == 90) x = x0 - sign_y*fontsize; if (psfont->i18n_latinfamily) { latin_font = gtk_psfont_get_font_description(latin_psfont, fontsize); } aux = g_utf8_next_char(aux); break; case '+': fontsize += 3; y -= sign_x*3; x += sign_y*3; pango_font_description_free(font); font = gtk_psfont_get_font_description(psfont, fontsize); if (psfont->i18n_latinfamily) { latin_font = gtk_psfont_get_font_description(latin_psfont, fontsize); } aux = g_utf8_next_char(aux); break; case '-': fontsize -= 3; y += sign_x*3; x -= sign_y*3; pango_font_description_free(font); font = gtk_psfont_get_font_description(psfont, fontsize); if (psfont->i18n_latinfamily) { latin_font = gtk_psfont_get_font_description(latin_psfont, fontsize); } aux = g_utf8_next_char(aux); break; case 'N': psfont = base_psfont; fontsize = font_height; pango_font_description_free(font); font = gtk_psfont_get_font_description(psfont, fontsize); if(angle == 0 || angle == 180) y = y0; else x = x0; italic = psfont->italic; bold = psfont->bold; aux = g_utf8_next_char(aux); break; case 'b': if (lastchar) { const gchar *aux2 = lastchar; gint i = g_utf8_prev_char(lastchar) != --aux2 ? 2 : 1; pango_layout_set_text(layout, lastchar, i); pango_layout_get_extents(layout, NULL, &rect); x -= sign_x*PANGO_PIXELS(rect.width); y -= sign_y*PANGO_PIXELS(rect.width); if (lastchar == wtext) lastchar = NULL; else lastchar = g_utf8_prev_char(lastchar); } else { pango_layout_set_text(layout, "X", 1); pango_layout_get_extents(layout, NULL, &rect); x -= sign_x*PANGO_PIXELS(rect.width); y -= sign_y*PANGO_PIXELS(rect.width); } aux = g_utf8_next_char(aux); break; default: if(aux && *aux != '\0' && *aux !='\n'){ gint new_width = 0; new_width = drawstring(pc, drawable, gc, angle, tx+x, ty+y, psfont, fontsize, aux); x += sign_x * new_width; y += sign_y * new_width; lastchar = aux; aux = g_utf8_next_char(aux); } break; } } else { gint new_len = 0; gint new_width = 0; lastchar = aux; while(aux && *aux != '\0' && *aux !='\n' && *aux != '\\'){ xaux = aux; new_len += g_utf8_next_char(aux) != ++xaux ? 2 : 1; aux = g_utf8_next_char(aux); } xaux = lastchar; for(i = 0; i < new_len; i++) new_text[i] = *xaux++; new_text[new_len] = '\0'; new_width = drawstring(pc, drawable, gc, angle, tx+x, ty+y, psfont, fontsize, new_text); x += sign_x * new_width; y += sign_y * new_width; lastchar = aux; } } pango_font_description_free(font); if(latin_font) pango_font_description_free(latin_font); if(metrics) pango_font_metrics_unref(metrics); /* border */ gdk_gc_set_foreground(gc, &real_fg); gtk_plot_pc_set_dash(pc, 0, NULL, 0); gtk_plot_pc_set_lineattr(pc, border_width, 0, 0, 0); switch(border){ case GTK_PLOT_BORDER_SHADOW: gtk_plot_pc_draw_rectangle(pc, TRUE, tx - border_space + shadow_width, ty + height + border_space, width + 2 * border_space, shadow_width); gtk_plot_pc_draw_rectangle(pc, TRUE, tx + width + border_space, ty - border_space + shadow_width, shadow_width, height + 2 * border_space); case GTK_PLOT_BORDER_LINE: gtk_plot_pc_draw_rectangle(pc, FALSE, tx - border_space, ty - border_space, width + 2*border_space, height + 2*border_space); case GTK_PLOT_BORDER_NONE: default: break; } return; }