static void clip_region_add_rect(DiaRenderer *object, Rectangle *rect) { DiaCairoInteractiveRenderer *renderer = DIA_CAIRO_INTERACTIVE_RENDERER (object); GdkRectangle clip_rect; int x1,y1; int x2,y2; DiaTransform *transform; /* Our link to the display settings */ transform = dia_transform_new(renderer->visible,renderer->zoom_factor); dia_transform_coords(transform, rect->left, rect->top, &x1, &y1); dia_transform_coords(transform, rect->right, rect->bottom, &x2, &y2); g_object_unref(transform); clip_rect.x = x1; clip_rect.y = y1; clip_rect.width = x2 - x1 + 1; clip_rect.height = y2 - y1 + 1; gdk_region_union_with_rect( renderer->clip_region, &clip_rect ); gdk_gc_set_clip_region(renderer->gc, renderer->clip_region); }
static void clip_region_add_rect(DiaRenderer *self, Rectangle *rect) { DiaLibartRenderer *renderer = DIA_LIBART_RENDERER (self); int x1,y1; int x2,y2; IntRectangle r; dia_transform_coords(renderer->transform, rect->left, rect->top, &x1, &y1); dia_transform_coords(renderer->transform, rect->right, rect->bottom, &x2, &y2); if (x1 < 0) x1 = 0; if (y1 < 0) y1 = 0; if (x2 >= renderer->pixel_width) x2 = renderer->pixel_width - 1; if (y2 >= renderer->pixel_height) y2 = renderer->pixel_height - 1; r.top = y1; r.bottom = y2; r.left = x1; r.right = x2; if (renderer->clip_rect_empty) { renderer->clip_rect = r; renderer->clip_rect_empty = 0; } else { int_rectangle_union(&renderer->clip_rect, &r); } }
static void draw_polygon (DiaRenderer *object, Point *points, int num_points, Color *fill, Color *stroke) { DiaGdkRenderer *renderer = DIA_GDK_RENDERER (object); GdkGC *gc = renderer->gc; GdkColor color; GdkPoint *gdk_points; int i,x,y; gdk_points = g_new(GdkPoint, num_points); for (i=0;i<num_points;i++) { dia_transform_coords(renderer->transform, points[i].x, points[i].y, &x, &y); gdk_points[i].x = x; gdk_points[i].y = y; } if (fill && fill->alpha > 0.0) { renderer_color_convert(renderer, fill, &color); gdk_gc_set_foreground(gc, &color); gdk_draw_polygon(renderer->pixmap, gc, TRUE, gdk_points, num_points); } if (stroke && stroke->alpha > 0.0) { renderer_color_convert(renderer, stroke, &color); gdk_gc_set_foreground(gc, &color); gdk_draw_polygon(renderer->pixmap, gc, FALSE, gdk_points, num_points); } g_free(gdk_points); }
static void draw_fill_arc (DiaRenderer *object, Point *center, real width, real height, real angle1, real angle2, Color *color, gboolean fill) { DiaGdkRenderer *renderer = DIA_GDK_RENDERER (object); GdkGC *gc = renderer->gc; GdkColor gdkcolor; gint top, left, bottom, right; real dangle; gboolean counter_clockwise = angle2 > angle1; if (color->alpha == 0.0) return; dia_transform_coords(renderer->transform, center->x - width/2, center->y - height/2, &left, &top); dia_transform_coords(renderer->transform, center->x + width/2, center->y + height/2, &right, &bottom); if ((left>right) || (top>bottom)) return; renderer_color_convert(renderer, color, &gdkcolor); gdk_gc_set_foreground(gc, &gdkcolor); /* GDK wants it always counter-clockwise */ if (counter_clockwise) dangle = angle2-angle1; else dangle = angle1-angle2; if (dangle<0) dangle += 360.0; gdk_draw_arc(renderer->pixmap, gc, fill, left, top, right-left, bottom-top, (int) (counter_clockwise ? angle1 : angle2) * 64.0, (int) (dangle * 64.0)); }
static void draw_line (DiaRenderer *object, Point *start, Point *end, Color *line_color) { DiaGdkRenderer *renderer = DIA_GDK_RENDERER (object); GdkGC *gc = renderer->gc; GdkColor color; int x1,y1,x2,y2; dia_transform_coords(renderer->transform, start->x, start->y, &x1, &y1); dia_transform_coords(renderer->transform, end->x, end->y, &x2, &y2); renderer_color_convert(renderer, line_color, &color); gdk_gc_set_foreground(gc, &color); gdk_draw_line(renderer->pixmap, gc, x1, y1, x2, y2); }
static void clip_region_add_rect(DiaRenderer *object, Rectangle *rect) { DiaGdkRenderer *renderer = DIA_GDK_RENDERER (object); GdkRectangle clip_rect; int x1,y1; int x2,y2; dia_transform_coords(renderer->transform, rect->left, rect->top, &x1, &y1); dia_transform_coords(renderer->transform, rect->right, rect->bottom, &x2, &y2); clip_rect.x = x1; clip_rect.y = y1; clip_rect.width = x2 - x1 + 1; clip_rect.height = y2 - y1 + 1; gdk_region_union_with_rect( renderer->clip_region, &clip_rect ); gdk_gc_set_clip_region(renderer->gc, renderer->clip_region); }
static void fill_polygon (DiaRenderer *object, Point *points, int num_points, Color *line_color) { DiaGdkRenderer *renderer = DIA_GDK_RENDERER (object); GdkGC *gc = renderer->gc; GdkColor color; GdkPoint *gdk_points; int i,x,y; gdk_points = g_new(GdkPoint, num_points); for (i=0;i<num_points;i++) { dia_transform_coords(renderer->transform, points[i].x, points[i].y, &x, &y); gdk_points[i].x = x; gdk_points[i].y = y; } renderer_color_convert(renderer, line_color, &color); gdk_gc_set_foreground(gc, &color); gdk_draw_polygon(renderer->pixmap, gc, TRUE, gdk_points, num_points); g_free(gdk_points); }
/** Draw a TextLine object. * @param object The renderer object to use for transform and output * @param text_line The TextLine to render, including font and height. * @param pos The position to render it at. * @param color The color to render it with. */ static void draw_text_line (DiaRenderer *object, TextLine *text_line, Point *pos, Alignment alignment, Color *color) { DiaGdkRenderer *renderer = DIA_GDK_RENDERER (object); GdkColor gdkcolor; int x,y; Point start_pos; PangoLayout* layout = NULL; const gchar *text = text_line_get_string(text_line); int height_pixels; real font_height = text_line_get_height(text_line); real scale = dia_transform_length(renderer->transform, 1.0); if (text == NULL || *text == '\0') return; /* Don't render empty strings. */ point_copy(&start_pos,pos); renderer_color_convert(renderer, color, &gdkcolor); height_pixels = dia_transform_length(renderer->transform, font_height); if (height_pixels < 2) { /* "Greeking" instead of making tiny font */ int width_pixels = dia_transform_length(renderer->transform, text_line_get_width(text_line)); gdk_gc_set_foreground(renderer->gc, &gdkcolor); gdk_gc_set_dashes(renderer->gc, 0, (gint8*)"\1\2", 2); dia_transform_coords(renderer->transform, start_pos.x, start_pos.y, &x, &y); gdk_draw_line(renderer->pixmap, renderer->gc, x, y, x + width_pixels, y); return; } else { start_pos.y -= text_line_get_ascent(text_line); start_pos.x -= text_line_get_alignment_adjustment (text_line, alignment); dia_transform_coords(renderer->transform, start_pos.x, start_pos.y, &x, &y); layout = dia_font_build_layout(text, text_line->font, dia_transform_length(renderer->transform, text_line->height)/20.0); #if defined(PANGO_VERSION_ENCODE) # if (PANGO_VERSION >= PANGO_VERSION_ENCODE(1,16,0)) /* I'd say the former Pango API was broken, i.e. leaky */ # define HAVE_pango_layout_get_line_readonly # endif #endif text_line_adjust_layout_line (text_line, #if defined(HAVE_pango_layout_get_line_readonly) pango_layout_get_line_readonly(layout, 0), #else pango_layout_get_line(layout, 0), #endif scale/20.0); if (renderer->highlight_color != NULL) { draw_highlighted_string(renderer, layout, x, y, &gdkcolor); } else { #if defined HAVE_FREETYPE { FT_Bitmap ftbitmap; int width, height; GdkPixbuf *rgba = NULL; width = dia_transform_length(renderer->transform, text_line_get_width(text_line)); height = dia_transform_length(renderer->transform, text_line_get_height(text_line)); if (width > 0) { int stride; guchar* pixels; int i,j; guint8 *graybitmap; initialize_ft_bitmap(&ftbitmap, width, height); pango_ft2_render_layout(&ftbitmap, layout, 0, 0); graybitmap = ftbitmap.buffer; rgba = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, width, height); stride = gdk_pixbuf_get_rowstride(rgba); pixels = gdk_pixbuf_get_pixels(rgba); for (i = 0; i < height; i++) { for (j = 0; j < width; j++) { pixels[i*stride+j*4] = gdkcolor.red>>8; pixels[i*stride+j*4+1] = gdkcolor.green>>8; pixels[i*stride+j*4+2] = gdkcolor.blue>>8; pixels[i*stride+j*4+3] = graybitmap[i*ftbitmap.pitch+j]; } } g_free(graybitmap); gdk_draw_pixbuf(renderer->pixmap, renderer->gc, rgba, 0, 0, x, y, width, height, GDK_RGB_DITHER_NONE, 0, 0); g_object_unref(G_OBJECT(rgba)); } } #else gdk_gc_set_foreground(renderer->gc, &gdkcolor); gdk_draw_layout(renderer->pixmap, renderer->gc, x, y, layout); #endif } /* !higlight_color */ g_object_unref(G_OBJECT(layout)); } /* !greeking */