[dia] formatting: update dia renderer code style
- From: Zander <zbrown src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dia] formatting: update dia renderer code style
- Date: Tue, 23 Jul 2019 00:09:09 +0000 (UTC)
commit 9da95ccc73077e791270ec6f8dfa3ba60a073ea2
Author: Zander Brown <zbrown gnome org>
Date: Mon Jul 22 21:57:45 2019 +0100
formatting: update dia renderer code style
Renames the vfunc implementations for clarity in traces
app/display.c | 32 +-
lib/diarenderer.h | 6 +-
lib/renderer/diacairo-interactive.c | 2 +-
lib/renderer/diacairo-print.c | 28 +-
lib/renderer/diacairo-renderer.c | 1270 ++++++++++++++++++++---------------
lib/renderer/diacairo.c | 42 +-
lib/renderer/diacairo.h | 18 +-
7 files changed, 771 insertions(+), 627 deletions(-)
---
diff --git a/app/display.c b/app/display.c
index 3aabc807..2a80e6f9 100644
--- a/app/display.c
+++ b/app/display.c
@@ -464,7 +464,8 @@ ddisplay_obj_render(DiaObject *obj, DiaRenderer *renderer,
}
void
-ddisplay_render_pixmap(DDisplay *ddisp, Rectangle *update)
+ddisplay_render_pixmap (DDisplay *ddisp,
+ Rectangle *update)
{
GList *list;
DiaObject *obj;
@@ -483,21 +484,22 @@ ddisplay_render_pixmap(DDisplay *ddisp, Rectangle *update)
/* Erase background */
g_return_if_fail (renderer->fill_pixel_rect != NULL);
- DIA_RENDERER_GET_CLASS(ddisp->renderer)->begin_render(ddisp->renderer, update);
+ DIA_RENDERER_GET_CLASS (ddisp->renderer)->begin_render (ddisp->renderer, update);
if (update) {
int x0, y0, x1, y1;
ddisplay_transform_coords (ddisp, update->left, update->top, &x0, &y0);
ddisplay_transform_coords (ddisp, update->right, update->bottom, &x1, &y1);
renderer->fill_pixel_rect (ddisp->renderer,
- x0, y0, x1-x0, y1-y0,
- &ddisp->diagram->data->bg_color);
- } else
+ x0, y0, x1-x0, y1-y0,
+ &ddisp->diagram->data->bg_color);
+ } else {
renderer->fill_pixel_rect (ddisp->renderer,
- 0, 0,
- dia_renderer_get_width_pixels (ddisp->renderer),
- dia_renderer_get_height_pixels (ddisp->renderer),
- &ddisp->diagram->data->bg_color);
+ 0, 0,
+ dia_renderer_get_width_pixels (ddisp->renderer),
+ dia_renderer_get_height_pixels (ddisp->renderer),
+ &ddisp->diagram->data->bg_color);
+ }
/* Draw grid */
grid_draw(ddisp, update);
@@ -506,8 +508,10 @@ ddisplay_render_pixmap(DDisplay *ddisp, Rectangle *update)
#ifdef TRACES
timer = g_timer_new();
#endif
- data_render(ddisp->diagram->data, ddisp->renderer, update,
- ddisplay_obj_render, (gpointer) ddisp);
+ data_render (ddisp->diagram->data,
+ ddisp->renderer, update,
+ ddisplay_obj_render,
+ (gpointer) ddisp);
#ifdef TRACES
g_print ("data_render(%g%%) took %g seconds\n", ddisp->zoom_factor * 5.0, g_timer_elapsed (timer, NULL));
g_timer_destroy (timer);
@@ -518,11 +522,11 @@ ddisplay_render_pixmap(DDisplay *ddisp, Rectangle *update)
obj = (DiaObject *) list->data;
for (i=0;i<obj->num_handles;i++) {
- handle_draw(obj->handles[i], ddisp);
- }
+ handle_draw(obj->handles[i], ddisp);
+ }
list = g_list_next(list);
}
- DIA_RENDERER_GET_CLASS(ddisp->renderer)->end_render(ddisp->renderer);
+ DIA_RENDERER_GET_CLASS (ddisp->renderer)->end_render (ddisp->renderer);
}
void
diff --git a/lib/diarenderer.h b/lib/diarenderer.h
index 41a2b3b4..bb1b1002 100644
--- a/lib/diarenderer.h
+++ b/lib/diarenderer.h
@@ -309,9 +309,9 @@ struct _DiaInteractiveRendererInterface
int width,
int height);
/*! Support for drawing selected objects highlighted */
- void (*draw_object_highlighted) (DiaRenderer *renderer,
- DiaObject *object,
- DiaHighlightType type);
+ void (*draw_object_highlighted) (DiaRenderer *renderer,
+ DiaObject *object,
+ DiaHighlightType type);
/* Draw a selection box */
void (*set_selection) (DiaRenderer *renderer,
gboolean has_selection,
diff --git a/lib/renderer/diacairo-interactive.c b/lib/renderer/diacairo-interactive.c
index 1ae3ffd4..12a0d7d1 100644
--- a/lib/renderer/diacairo-interactive.c
+++ b/lib/renderer/diacairo-interactive.c
@@ -330,7 +330,7 @@ dia_cairo_interactive_renderer_get_type (void)
NULL /* iface_data */
};
- object_type = g_type_register_static (DIA_TYPE_CAIRO_RENDERER,
+ object_type = g_type_register_static (DIA_CAIRO_TYPE_RENDERER,
"DiaCairoInteractiveRenderer",
&object_info, 0);
diff --git a/lib/renderer/diacairo-print.c b/lib/renderer/diacairo-print.c
index 94102621..23a0437b 100644
--- a/lib/renderer/diacairo-print.c
+++ b/lib/renderer/diacairo-print.c
@@ -47,8 +47,8 @@ _dia_to_gtk_page_setup (const DiagramData *data, GtkPageSetup *setup)
if (index < 0)
index = get_default_paper ();
paper_size = gtk_paper_size_new_from_ppd (
- paper->name, paper->name,
- get_paper_pswidth (index) * points_per_cm,
+ paper->name, paper->name,
+ get_paper_pswidth (index) * points_per_cm,
get_paper_psheight (index) * points_per_cm);
gtk_page_setup_set_orientation (setup, data->paper.is_portrait ?
@@ -59,7 +59,7 @@ _dia_to_gtk_page_setup (const DiagramData *data, GtkPageSetup *setup)
gtk_page_setup_set_top_margin (setup, data->paper.tmargin * 10, GTK_UNIT_MM);
gtk_page_setup_set_right_margin (setup, data->paper.rmargin * 10, GTK_UNIT_MM);
gtk_page_setup_set_bottom_margin (setup, data->paper.bmargin * 10, GTK_UNIT_MM);
-
+
}
static void
@@ -84,7 +84,7 @@ begin_print (GtkPrintOperation *operation,
/* scaling - as usual I don't get it, or do I? */
cairo_renderer->scale = (
- gtk_page_setup_get_paper_width (gtk_print_context_get_page_setup (context), GTK_UNIT_MM)
+ gtk_page_setup_get_paper_width (gtk_print_context_get_page_setup (context), GTK_UNIT_MM)
- gtk_page_setup_get_left_margin( gtk_print_context_get_page_setup (context), GTK_UNIT_MM)
- gtk_page_setup_get_right_margin( gtk_print_context_get_page_setup (context), GTK_UNIT_MM)
) / print_data->data->paper.width;
@@ -111,7 +111,7 @@ draw_page (GtkPrintOperation *operation,
if (data->paper.fitto) {
x = page_nr % data->paper.fitwidth;
y = page_nr / data->paper.fitwidth;
-
+
bounds.left = dp_width * x + data->extents.left;
bounds.top = dp_height * y + data->extents.top;
bounds.right = bounds.left + dp_width;
@@ -123,7 +123,7 @@ draw_page (GtkPrintOperation *operation,
y = page_nr / nx;
/* Respect the original pagination as shown by the page guides.
- * Caclulate the offset between page origin 0,0 and data.extents.topleft.
+ * Caclulate the offset between page origin 0,0 and data.extents.topleft.
* For the usual first page this boils down to lefttop=(0,0) but beware
* the origin being negative.
*/
@@ -153,9 +153,9 @@ draw_page (GtkPrintOperation *operation,
GtkPageSetup *setup = gtk_print_context_get_page_setup (context);
double left = gtk_page_setup_get_left_margin (setup, GTK_UNIT_MM);
double top = gtk_page_setup_get_top_margin (setup, GTK_UNIT_MM);
- double width = gtk_page_setup_get_paper_width (setup, GTK_UNIT_MM)
+ double width = gtk_page_setup_get_paper_width (setup, GTK_UNIT_MM)
- left - gtk_page_setup_get_right_margin (setup, GTK_UNIT_MM);
- double height = gtk_page_setup_get_paper_height (setup, GTK_UNIT_MM)
+ double height = gtk_page_setup_get_paper_height (setup, GTK_UNIT_MM)
- top - gtk_page_setup_get_bottom_margin (setup, GTK_UNIT_MM);
cairo_save (cairo_renderer->cr);
/* we are still in the gtk-print coordinate system */
@@ -164,7 +164,7 @@ draw_page (GtkPrintOperation *operation,
top = left = 0;
#endif
cairo_rectangle (cairo_renderer->cr, left, top, width, height);
-
+
cairo_clip (cairo_renderer->cr);
}
@@ -201,10 +201,10 @@ create_print_operation (DiagramData *data, const char *name)
/* gets deleted in end_print */
print_data = g_new0 (PrintData, 1);
print_data->data = g_object_ref (data);
- print_data->renderer = g_object_new (DIA_TYPE_CAIRO_RENDERER, NULL);
-
+ print_data->renderer = g_object_new (DIA_CAIRO_TYPE_RENDERER, NULL);
+
operation = gtk_print_operation_new ();
-
+
gtk_print_operation_set_job_name (operation, name);
setup = gtk_print_operation_get_default_page_setup (operation);
@@ -229,7 +229,7 @@ create_print_operation (DiagramData *data, const char *name)
g_signal_connect (operation, "draw_page", G_CALLBACK (draw_page), print_data);
g_signal_connect (operation, "begin_print", G_CALLBACK (begin_print), print_data);
g_signal_connect (operation, "end_print", G_CALLBACK (end_print), print_data);
-
+
return operation;
}
@@ -242,7 +242,7 @@ cairo_print_callback (DiagramData *data,
GtkPrintOperation *op = create_print_operation (data, filename ? filename : "diagram");
GtkPrintOperationResult res;
GError *error = NULL;
-
+
res = gtk_print_operation_run (op, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, NULL, &error);
if (GTK_PRINT_OPERATION_RESULT_ERROR == res) {
message_error ("%s", error->message);
diff --git a/lib/renderer/diacairo-renderer.c b/lib/renderer/diacairo-renderer.c
index 33c77b6c..6b14e74c 100644
--- a/lib/renderer/diacairo-renderer.c
+++ b/lib/renderer/diacairo-renderer.c
@@ -3,7 +3,7 @@
*
* diacairo.c -- Cairo based export plugin for dia
* Copyright (C) 2004, Hans Breuer, <Hans Breuer Org>
- * based on wpg.c
+ * based on wpg.c
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -20,13 +20,14 @@
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
+#define G_LOG_DOMAIN "DiaCairo"
+
#include <config.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <errno.h>
-#define G_LOG_DOMAIN "DiaCairo"
#include <glib.h>
#include <glib/gstdio.h>
@@ -35,10 +36,10 @@
#include <cairo.h>
/* some backend headers, win32 missing in official Cairo */
#include <cairo-svg.h>
-#ifdef CAIRO_HAS_PS_SURFACE
+#ifdef CAIRO_HAS_PS_SURFACE
#include <cairo-ps.h>
#endif
-#ifdef CAIRO_HAS_PDF_SURFACE
+#ifdef CAIRO_HAS_PDF_SURFACE
#include <cairo-pdf.h>
#endif
@@ -54,13 +55,16 @@
#include "diacairo.h"
-static void ensure_minimum_one_device_unit(DiaCairoRenderer *renderer, real *value);
+G_DEFINE_TYPE (DiaCairoRenderer, dia_cairo_renderer, DIA_TYPE_RENDERER)
-/*
- * render functions
- */
+static void ensure_minimum_one_device_unit (DiaCairoRenderer *renderer,
+ real *value);
+
+/*
+ * render functions
+ */
static void
-begin_render(DiaRenderer *self, const Rectangle *update)
+dia_cairo_renderer_begin_render (DiaRenderer *self, const Rectangle *update)
{
DiaCairoRenderer *renderer = DIA_CAIRO_RENDERER (self);
real onedu = 0.0;
@@ -69,17 +73,18 @@ begin_render(DiaRenderer *self, const Rectangle *update)
cairo_surface_get_type (renderer->surface) == CAIRO_SURFACE_TYPE_PDF && !renderer->skip_show_page;
Color background = color_white;
- if (renderer->surface && !renderer->cr)
+ if (renderer->surface && !renderer->cr) {
renderer->cr = cairo_create (renderer->surface);
- else
+ } else {
g_assert (renderer->cr);
+ }
/* remember current state, so we can start from new with every page */
cairo_save (renderer->cr);
if (paginated && renderer->dia) {
DiagramData *data = renderer->dia;
- /* Dia's paper.width already contains the scale, cairo needs it without
+ /* Dia's paper.width already contains the scale, cairo needs it without
* Similar for margins, Dia's without, but cairo wants them?
*/
real width = (data->paper.lmargin + data->paper.width * data->paper.scaling + data->paper.rmargin)
@@ -105,45 +110,44 @@ begin_render(DiaRenderer *self, const Rectangle *update)
cairo_clip (renderer->cr);
cairo_translate (renderer->cr, -update->left + lmargin, -update->top + tmargin);
} else {
- if (renderer->dia)
+ if (renderer->dia) {
cairo_translate (renderer->cr, -renderer->dia->extents.left + onedu, -renderer->dia->extents.top +
onedu);
+ }
}
/* no more blurred UML diagrams */
cairo_set_antialias (renderer->cr, CAIRO_ANTIALIAS_NONE);
/* clear background */
- if (renderer->dia)
+ if (renderer->dia) {
background = renderer->dia->bg_color;
- if (renderer->with_alpha)
- {
- cairo_set_operator (renderer->cr, CAIRO_OPERATOR_SOURCE);
- cairo_set_source_rgba (renderer->cr,
- background.red,
- background.green,
- background.blue,
- 0.0);
- }
- else
- {
- cairo_set_source_rgba (renderer->cr,
- background.red,
- background.green,
- background.blue,
- 1.0);
- }
+ }
+ if (renderer->with_alpha) {
+ cairo_set_operator (renderer->cr, CAIRO_OPERATOR_SOURCE);
+ cairo_set_source_rgba (renderer->cr,
+ background.red,
+ background.green,
+ background.blue,
+ 0.0);
+ } else {
+ cairo_set_source_rgba (renderer->cr,
+ background.red,
+ background.green,
+ background.blue,
+ 1.0);
+ }
cairo_paint (renderer->cr);
- if (renderer->with_alpha)
- {
- /* restore to default drawing */
- cairo_set_operator (renderer->cr, CAIRO_OPERATOR_OVER);
- cairo_set_source_rgba (renderer->cr,
- background.red,
- background.green,
- background.blue,
- 1.0);
- }
- if (!renderer->layout)
+ if (renderer->with_alpha) {
+ /* restore to default drawing */
+ cairo_set_operator (renderer->cr, CAIRO_OPERATOR_OVER);
+ cairo_set_source_rgba (renderer->cr,
+ background.red,
+ background.green,
+ background.blue,
+ 1.0);
+ }
+ if (!renderer->layout) {
renderer->layout = pango_cairo_create_layout (renderer->cr);
+ }
cairo_set_fill_rule (renderer->cr, CAIRO_FILL_RULE_EVEN_ODD);
@@ -163,22 +167,24 @@ begin_render(DiaRenderer *self, const Rectangle *update)
#endif
}
#endif
-
- DIAG_STATE(renderer->cr)
+
+ DIAG_STATE (renderer->cr)
}
static void
-end_render(DiaRenderer *self)
+dia_cairo_renderer_end_render (DiaRenderer *self)
{
DiaCairoRenderer *renderer = DIA_CAIRO_RENDERER (self);
- DIAG_NOTE(g_message( "end_render"));
-
- if (!renderer->skip_show_page)
+ DIAG_NOTE (g_message ("end_render"));
+
+ if (!renderer->skip_show_page) {
cairo_show_page (renderer->cr);
+ }
/* pop current state, so we can start from new with every page */
cairo_restore (renderer->cr);
- DIAG_STATE(renderer->cr)
+
+ DIAG_STATE (renderer->cr)
}
/*!
@@ -188,50 +194,66 @@ end_render(DiaRenderer *self)
* is complaining if it will return FALSE
* \memberof _DiaCairoRenderer
*/
-static gboolean
-is_capable_to (DiaRenderer *renderer, RenderCapability cap)
+static gboolean
+dia_cairo_renderer_is_capable_to (DiaRenderer *renderer,
+ RenderCapability cap)
{
static RenderCapability warned = RENDER_HOLES;
- if (RENDER_HOLES == cap)
+ if (RENDER_HOLES == cap) {
return TRUE;
- else if (RENDER_ALPHA == cap)
+ } else if (RENDER_ALPHA == cap) {
return TRUE;
- else if (RENDER_AFFINE == cap)
+ } else if (RENDER_AFFINE == cap) {
return TRUE;
- else if (RENDER_PATTERN == cap)
+ } else if (RENDER_PATTERN == cap) {
return TRUE;
- if (cap != warned)
+ }
+
+ if (cap != warned) {
g_warning ("New capability not supported by cairo??");
+ }
+
warned = cap;
+
return FALSE;
}
/*!
* \brief Remember the given pattern to use for consecutive fill
* @param self explicit this pointer
- * @param pattern linear or radial gradient
+ * @param pattern linear or radial gradient
*/
static void
-set_pattern (DiaRenderer *self, DiaPattern *pattern)
+dia_cairo_renderer_set_pattern (DiaRenderer *self,
+ DiaPattern *pattern)
{
DiaCairoRenderer *renderer = DIA_CAIRO_RENDERER (self);
DiaPattern *prev = renderer->pattern;
- if (pattern)
+
+ if (pattern) {
renderer->pattern = g_object_ref (pattern);
- else
+ } else {
renderer->pattern = pattern;
- if (prev)
+ }
+
+ if (prev) {
g_object_unref (prev);
+ }
}
static gboolean
_add_color_stop (real ofs, const Color *col, gpointer user_data)
{
- cairo_pattern_t *pat = (cairo_pattern_t *)user_data;
-
- cairo_pattern_add_color_stop_rgba (pat, ofs,
- col->red, col->green, col->blue, col->alpha);
+ cairo_pattern_t *pat = (cairo_pattern_t *) user_data;
+
+ cairo_pattern_add_color_stop_rgba (pat,
+ ofs,
+ col->red,
+ col->green,
+ col->blue,
+ col->alpha);
+
return TRUE;
}
@@ -250,19 +272,19 @@ _pattern_build_for_cairo (DiaPattern *pattern, const Rectangle *ext)
dia_pattern_get_points (pattern, &p1, &p2);
dia_pattern_get_radius (pattern, &r);
- switch (type ) {
- case DIA_LINEAR_GRADIENT :
- pat = cairo_pattern_create_linear (p1.x, p1.y, p2.x, p2.y);
- break;
- case DIA_RADIAL_GRADIENT :
- pat = cairo_pattern_create_radial (p2.x, p2.y, 0.0, p1.x, p1.y, r);
- break;
- default :
- g_warning ("_pattern_build_for_cairo non such.");
- return NULL;
+ switch (type) {
+ case DIA_LINEAR_GRADIENT :
+ pat = cairo_pattern_create_linear (p1.x, p1.y, p2.x, p2.y);
+ break;
+ case DIA_RADIAL_GRADIENT :
+ pat = cairo_pattern_create_radial (p2.x, p2.y, 0.0, p1.x, p1.y, r);
+ break;
+ default :
+ g_warning ("_pattern_build_for_cairo non such.");
+ return NULL;
}
/* this must only be optionally done */
- if ((flags & DIA_PATTERN_USER_SPACE)==0) {
+ if ((flags & DIA_PATTERN_USER_SPACE) == 0) {
cairo_matrix_t matrix;
real w = ext->right - ext->left;
real h = ext->bottom - ext->top;
@@ -270,12 +292,14 @@ _pattern_build_for_cairo (DiaPattern *pattern, const Rectangle *ext)
cairo_matrix_invert (&matrix);
cairo_pattern_set_matrix (pat, &matrix);
}
- if (flags & DIA_PATTERN_EXTEND_PAD)
+
+ if (flags & DIA_PATTERN_EXTEND_PAD) {
cairo_pattern_set_extend (pat, CAIRO_EXTEND_PAD);
- else if (flags & DIA_PATTERN_EXTEND_REPEAT)
+ } else if (flags & DIA_PATTERN_EXTEND_REPEAT) {
cairo_pattern_set_extend (pat, CAIRO_EXTEND_REPEAT);
- else if (flags & DIA_PATTERN_EXTEND_REFLECT)
+ } else if (flags & DIA_PATTERN_EXTEND_REFLECT) {
cairo_pattern_set_extend (pat, CAIRO_EXTEND_REFLECT);
+ }
dia_pattern_foreach (pattern, _add_color_stop, pat);
@@ -289,24 +313,30 @@ static void
_dia_cairo_fill (DiaCairoRenderer *renderer, gboolean preserve)
{
if (!renderer->pattern) {
- if (preserve)
+ if (preserve) {
cairo_fill_preserve (renderer->cr);
- else
+ } else {
cairo_fill (renderer->cr);
+ }
} else {
/* maybe we should cache the cairo-pattern */
cairo_pattern_t *pat;
Rectangle fe;
/* Using the extents to scale the pattern is probably not correct */
- cairo_fill_extents (renderer->cr, &fe.left, &fe.top, &fe.right, &fe.bottom);
+ cairo_fill_extents (renderer->cr,
+ &fe.left,
+ &fe.top,
+ &fe.right,
+ &fe.bottom);
pat = _pattern_build_for_cairo (renderer->pattern, &fe);
cairo_set_source (renderer->cr, pat);
- if (preserve)
+ if (preserve) {
cairo_fill_preserve (renderer->cr);
- else
+ } else {
cairo_fill (renderer->cr);
+ }
cairo_pattern_destroy (pat);
}
}
@@ -318,22 +348,26 @@ _dia_cairo_fill (DiaCairoRenderer *renderer, gboolean preserve)
* @param matrix the transformation matrix to use or NULL
*/
static void
-draw_object (DiaRenderer *self, DiaObject *object, DiaMatrix *matrix)
+dia_cairo_renderer_draw_object (DiaRenderer *self,
+ DiaObject *object,
+ DiaMatrix *matrix)
{
DiaCairoRenderer *renderer = DIA_CAIRO_RENDERER (self);
cairo_matrix_t before;
-
+
if (matrix) {
/* at least in SVG the intent of an invalid matrix is not rendering */
- if (!dia_matrix_is_invertible(matrix))
+ if (!dia_matrix_is_invertible (matrix)) {
return;
+ }
cairo_get_matrix (renderer->cr, &before);
- g_assert (sizeof(cairo_matrix_t) == sizeof(DiaMatrix));
- cairo_transform (renderer->cr, (cairo_matrix_t *)matrix);
+ g_assert (sizeof (cairo_matrix_t) == sizeof (DiaMatrix));
+ cairo_transform (renderer->cr, (cairo_matrix_t *) matrix);
}
- object->ops->draw(object, DIA_RENDERER (renderer));
- if (matrix)
+ object->ops->draw (object, DIA_RENDERER (renderer));
+ if (matrix) {
cairo_set_matrix (renderer->cr, &before);
+ }
}
/*!
@@ -344,127 +378,135 @@ draw_object (DiaRenderer *self, DiaObject *object, DiaMatrix *matrix)
* \protected \memberof _DiaCairoRenderer
*/
static void
-ensure_minimum_one_device_unit(DiaCairoRenderer *renderer, real *value)
+ensure_minimum_one_device_unit (DiaCairoRenderer *renderer, real *value)
{
double ax = 1., ay = 1.;
cairo_device_to_user_distance (renderer->cr, &ax, &ay);
ax = MAX(ax, ay);
- if (*value < ax)
- *value = ax;
+ if (*value < ax) {
+ *value = ax;
+ }
}
static void
-set_linewidth(DiaRenderer *self, real linewidth)
-{
+dia_cairo_renderer_set_linewidth (DiaRenderer *self, real linewidth)
+{
DiaCairoRenderer *renderer = DIA_CAIRO_RENDERER (self);
- DIAG_NOTE(g_message("set_linewidth %f", linewidth));
+ DIAG_NOTE (g_message ("set_linewidth %f", linewidth));
/* make hairline? Everythnig below one device unit get the same width,
* otherwise 0.0 may end up thicker than 0.0+epsilon
*/
- ensure_minimum_one_device_unit(renderer, &linewidth);
+ ensure_minimum_one_device_unit (renderer, &linewidth);
cairo_set_line_width (renderer->cr, linewidth);
- DIAG_STATE(renderer->cr)
+
+ DIAG_STATE (renderer->cr)
}
static void
-set_linecaps(DiaRenderer *self, LineCaps mode)
+dia_cairo_renderer_set_linecaps (DiaRenderer *self, LineCaps mode)
{
DiaCairoRenderer *renderer = DIA_CAIRO_RENDERER (self);
- DIAG_NOTE(g_message("set_linecaps %d", mode));
+ DIAG_NOTE (g_message ("set_linecaps %d", mode));
switch(mode) {
- case LINECAPS_DEFAULT:
- case LINECAPS_BUTT:
- cairo_set_line_cap (renderer->cr, CAIRO_LINE_CAP_BUTT);
- break;
- case LINECAPS_ROUND:
- cairo_set_line_cap (renderer->cr, CAIRO_LINE_CAP_ROUND);
- break;
- case LINECAPS_PROJECTING:
- cairo_set_line_cap (renderer->cr, CAIRO_LINE_CAP_SQUARE); /* ?? */
- break;
- default:
- g_warning("DiaCairoRenderer : Unsupported caps mode specified!\n");
+ case LINECAPS_DEFAULT:
+ case LINECAPS_BUTT:
+ cairo_set_line_cap (renderer->cr, CAIRO_LINE_CAP_BUTT);
+ break;
+ case LINECAPS_ROUND:
+ cairo_set_line_cap (renderer->cr, CAIRO_LINE_CAP_ROUND);
+ break;
+ case LINECAPS_PROJECTING:
+ cairo_set_line_cap (renderer->cr, CAIRO_LINE_CAP_SQUARE); /* ?? */
+ break;
+ default:
+ g_warning ("DiaCairoRenderer : Unsupported caps mode specified!\n");
}
- DIAG_STATE(renderer->cr)
+
+ DIAG_STATE (renderer->cr)
}
static void
-set_linejoin(DiaRenderer *self, LineJoin mode)
+dia_cairo_renderer_set_linejoin (DiaRenderer *self, LineJoin mode)
{
DiaCairoRenderer *renderer = DIA_CAIRO_RENDERER (self);
- DIAG_NOTE(g_message("set_join %d", mode));
+ DIAG_NOTE (g_message ("set_join %d", mode));
switch(mode) {
- case LINEJOIN_DEFAULT:
- case LINEJOIN_MITER:
- cairo_set_line_join (renderer->cr, CAIRO_LINE_JOIN_MITER);
- break;
- case LINEJOIN_ROUND:
- cairo_set_line_join (renderer->cr, CAIRO_LINE_JOIN_ROUND);
- break;
- case LINEJOIN_BEVEL:
- cairo_set_line_join (renderer->cr, CAIRO_LINE_JOIN_BEVEL);
- break;
- default:
- g_warning("DiaCairoRenderer : Unsupported join mode specified!\n");
+ case LINEJOIN_DEFAULT:
+ case LINEJOIN_MITER:
+ cairo_set_line_join (renderer->cr, CAIRO_LINE_JOIN_MITER);
+ break;
+ case LINEJOIN_ROUND:
+ cairo_set_line_join (renderer->cr, CAIRO_LINE_JOIN_ROUND);
+ break;
+ case LINEJOIN_BEVEL:
+ cairo_set_line_join (renderer->cr, CAIRO_LINE_JOIN_BEVEL);
+ break;
+ default:
+ g_warning("DiaCairoRenderer : Unsupported join mode specified!\n");
}
- DIAG_STATE(renderer->cr)
+
+ DIAG_STATE (renderer->cr)
}
static void
-set_linestyle(DiaRenderer *self, LineStyle mode, real dash_length)
+dia_cairo_renderer_set_linestyle (DiaRenderer *self,
+ LineStyle mode,
+ real dash_length)
{
/* dot = 10% of len */
DiaCairoRenderer *renderer = DIA_CAIRO_RENDERER (self);
double dash[6];
- DIAG_NOTE(g_message("set_linestyle %d", mode));
+ DIAG_NOTE (g_message ("set_linestyle %d", mode));
+
+ ensure_minimum_one_device_unit (renderer, &dash_length);
- ensure_minimum_one_device_unit(renderer, &dash_length);
/* line type */
switch (mode) {
- case LINESTYLE_DEFAULT:
- case LINESTYLE_SOLID:
- cairo_set_dash (renderer->cr, NULL, 0, 0);
- break;
- case LINESTYLE_DASHED:
- dash[0] = dash_length;
- dash[1] = dash_length;
- cairo_set_dash (renderer->cr, dash, 2, 0);
- break;
- case LINESTYLE_DASH_DOT:
- dash[0] = dash_length;
- dash[1] = dash_length * 0.45;
- dash[2] = dash_length * 0.1;
- dash[3] = dash_length * 0.45;
- cairo_set_dash (renderer->cr, dash, 4, 0);
- break;
- case LINESTYLE_DASH_DOT_DOT:
- dash[0] = dash_length;
- dash[1] = dash_length * (0.8/3);
- dash[2] = dash_length * 0.1;
- dash[3] = dash_length * (0.8/3);
- dash[4] = dash_length * 0.1;
- dash[5] = dash_length * (0.8/3);
- cairo_set_dash (renderer->cr, dash, 6, 0);
- break;
- case LINESTYLE_DOTTED:
- dash[0] = dash_length * 0.1;
- dash[1] = dash_length * 0.1;
- cairo_set_dash (renderer->cr, dash, 2, 0);
- break;
- default:
- g_warning("DiaCairoRenderer : Unsupported line style specified!\n");
+ case LINESTYLE_DEFAULT:
+ case LINESTYLE_SOLID:
+ cairo_set_dash (renderer->cr, NULL, 0, 0);
+ break;
+ case LINESTYLE_DASHED:
+ dash[0] = dash_length;
+ dash[1] = dash_length;
+ cairo_set_dash (renderer->cr, dash, 2, 0);
+ break;
+ case LINESTYLE_DASH_DOT:
+ dash[0] = dash_length;
+ dash[1] = dash_length * 0.45;
+ dash[2] = dash_length * 0.1;
+ dash[3] = dash_length * 0.45;
+ cairo_set_dash (renderer->cr, dash, 4, 0);
+ break;
+ case LINESTYLE_DASH_DOT_DOT:
+ dash[0] = dash_length;
+ dash[1] = dash_length * (0.8/3);
+ dash[2] = dash_length * 0.1;
+ dash[3] = dash_length * (0.8/3);
+ dash[4] = dash_length * 0.1;
+ dash[5] = dash_length * (0.8/3);
+ cairo_set_dash (renderer->cr, dash, 6, 0);
+ break;
+ case LINESTYLE_DOTTED:
+ dash[0] = dash_length * 0.1;
+ dash[1] = dash_length * 0.1;
+ cairo_set_dash (renderer->cr, dash, 2, 0);
+ break;
+ default:
+ g_warning("DiaCairoRenderer : Unsupported line style specified!\n");
}
- DIAG_STATE(renderer->cr)
+
+ DIAG_STATE (renderer->cr)
}
/*!
@@ -476,20 +518,21 @@ set_linestyle(DiaRenderer *self, LineStyle mode, real dash_length)
* \memberof _DiaCairoRenderer
*/
static void
-set_fillstyle(DiaRenderer *self, FillStyle mode)
+dia_cairo_renderer_set_fillstyle (DiaRenderer *self, FillStyle mode)
{
- DIAG_NOTE(g_message("set_fillstyle %d", mode));
+ DIAG_NOTE (g_message ("set_fillstyle %d", mode));
switch(mode) {
- case FILLSTYLE_SOLID:
- /* FIXME: how to set _no_ pattern ?
- * cairo_set_pattern (renderer->cr, NULL);
- */
- break;
- default:
- g_warning("DiaCairoRenderer : Unsupported fill mode specified!\n");
+ case FILLSTYLE_SOLID:
+ /* FIXME: how to set _no_ pattern ?
+ * cairo_set_pattern (renderer->cr, NULL);
+ */
+ break;
+ default:
+ g_warning("DiaCairoRenderer : Unsupported fill mode specified!\n");
}
- DIAG_STATE(DIA_CAIRO_RENDERER (self)->cr)
+
+ DIAG_STATE (DIA_CAIRO_RENDERER (self)->cr)
}
/* There is a recurring bug with pangocairo related to kerning and font scaling.
@@ -502,260 +545,357 @@ set_fillstyle(DiaRenderer *self, FillStyle mode)
#define FONT_SIZE_TWEAK (72.0)
static void
-set_font(DiaRenderer *self, DiaFont *font, real height)
+dia_cairo_renderer_set_font (DiaRenderer *self, DiaFont *font, real height)
{
DiaCairoRenderer *renderer = DIA_CAIRO_RENDERER (self);
/* pango/cairo wants the font size, not the (line-) height */
real size = dia_font_get_size (font) * (height / dia_font_get_height (font));
PangoFontDescription *pfd = pango_font_description_copy (dia_font_get_description (font));
- DIAG_NOTE(g_message("set_font %f %s", height, dia_font_get_family(font)));
+
+ DIAG_NOTE (g_message ("set_font %f %s", height, dia_font_get_family (font)));
/* select font and size */
- pango_font_description_set_absolute_size (pfd, (int)(size * FONT_SIZE_TWEAK * PANGO_SCALE));
+ pango_font_description_set_absolute_size (pfd,
+ (int) (size * FONT_SIZE_TWEAK * PANGO_SCALE));
pango_layout_set_font_description (renderer->layout, pfd);
pango_font_description_free (pfd);
/* for the interactive case we must maintain the font field in the base class */
if (self->is_interactive) {
- dia_font_ref(font);
- if (self->font)
- dia_font_unref(self->font);
+ dia_font_ref (font);
+ if (self->font) {
+ dia_font_unref (self->font);
+ }
self->font = font;
self->font_height = height;
}
}
static void
-draw_line(DiaRenderer *self,
- Point *start, Point *end,
- Color *color)
+dia_cairo_renderer_draw_line (DiaRenderer *self,
+ Point *start,
+ Point *end,
+ Color *color)
{
DiaCairoRenderer *renderer = DIA_CAIRO_RENDERER (self);
- DIAG_NOTE(g_message("draw_line %f,%f -> %f, %f",
- start->x, start->y, end->x, end->y));
-
- cairo_set_source_rgba (renderer->cr, color->red, color->green, color->blue, color->alpha);
- if (!renderer->stroke_pending) /* use current point from previous drawing command */
+ DIAG_NOTE (g_message ("draw_line %f,%f -> %f, %f",
+ start->x,
+ start->y,
+ end->x,
+ end->y));
+
+ cairo_set_source_rgba (renderer->cr,
+ color->red,
+ color->green,
+ color->blue,
+ color->alpha);
+ if (!renderer->stroke_pending) {
+ /* use current point from previous drawing command */
cairo_move_to (renderer->cr, start->x, start->y);
+ }
cairo_line_to (renderer->cr, end->x, end->y);
- if (!renderer->stroke_pending)
+ if (!renderer->stroke_pending) {
cairo_stroke (renderer->cr);
- DIAG_STATE(renderer->cr)
+ }
+
+ DIAG_STATE (renderer->cr)
}
static void
-draw_polyline(DiaRenderer *self,
- Point *points, int num_points,
- Color *color)
+dia_cairo_renderer_draw_polyline (DiaRenderer *self,
+ Point *points,
+ int num_points,
+ Color *color)
{
DiaCairoRenderer *renderer = DIA_CAIRO_RENDERER (self);
int i;
- DIAG_NOTE(g_message("draw_polyline n:%d %f,%f ...",
- num_points, points->x, points->y));
+ DIAG_NOTE (g_message ("draw_polyline n:%d %f,%f ...",
+ num_points,
+ points->x,
+ points->y));
- g_return_if_fail(1 < num_points);
+ g_return_if_fail (1 < num_points);
- cairo_set_source_rgba (renderer->cr, color->red, color->green, color->blue, color->alpha);
+ cairo_set_source_rgba (renderer->cr,
+ color->red,
+ color->green,
+ color->blue,
+ color->alpha);
cairo_new_path (renderer->cr);
/* point data */
cairo_move_to (renderer->cr, points[0].x, points[0].y);
- for (i = 1; i < num_points; i++)
- {
- cairo_line_to (renderer->cr, points[i].x, points[i].y);
- }
+ for (i = 1; i < num_points; i++) {
+ cairo_line_to (renderer->cr, points[i].x, points[i].y);
+ }
cairo_stroke (renderer->cr);
- DIAG_STATE(renderer->cr)
+
+ DIAG_STATE (renderer->cr)
}
static void
-_polygon(DiaRenderer *self,
- Point *points, int num_points,
- Color *color,
- gboolean fill)
+_polygon (DiaRenderer *self,
+ Point *points,
+ int num_points,
+ Color *color,
+ gboolean fill)
{
DiaCairoRenderer *renderer = DIA_CAIRO_RENDERER (self);
int i;
- DIAG_NOTE(g_message("%s_polygon n:%d %f,%f ...",
- fill ? "fill" : "draw",
- num_points, points->x, points->y));
+ DIAG_NOTE (g_message ("%s_polygon n:%d %f,%f ...",
+ fill ? "fill" : "draw",
+ num_points,
+ points->x,
+ points->y));
- g_return_if_fail(1 < num_points);
+ g_return_if_fail (1 < num_points);
- cairo_set_source_rgba (renderer->cr, color->red, color->green, color->blue, color->alpha);
+ cairo_set_source_rgba (renderer->cr,
+ color->red,
+ color->green,
+ color->blue,
+ color->alpha);
cairo_new_path (renderer->cr);
/* point data */
cairo_move_to (renderer->cr, points[0].x, points[0].y);
- for (i = 1; i < num_points; i++)
- {
- cairo_line_to (renderer->cr, points[i].x, points[i].y);
- }
+ for (i = 1; i < num_points; i++) {
+ cairo_line_to (renderer->cr, points[i].x, points[i].y);
+ }
cairo_line_to (renderer->cr, points[0].x, points[0].y);
cairo_close_path (renderer->cr);
- if (fill)
+ if (fill) {
_dia_cairo_fill (renderer, FALSE);
- else
+ } else {
cairo_stroke (renderer->cr);
- DIAG_STATE(renderer->cr)
+ }
+
+ DIAG_STATE (renderer->cr)
}
static void
-draw_polygon(DiaRenderer *self,
- Point *points, int num_points,
- Color *fill, Color *stroke)
+dia_cairo_renderer_draw_polygon (DiaRenderer *self,
+ Point *points,
+ int num_points,
+ Color *fill,
+ Color *stroke)
{
- if (fill)
+ if (fill) {
_polygon (self, points, num_points, fill, TRUE);
- if (stroke)
+ }
+ if (stroke) {
_polygon (self, points, num_points, stroke, FALSE);
+ }
}
static void
-_rect(DiaRenderer *self,
- Point *ul_corner, Point *lr_corner,
- Color *color,
- gboolean fill)
+_rect (DiaRenderer *self,
+ Point *ul_corner,
+ Point *lr_corner,
+ Color *color,
+ gboolean fill)
{
DiaCairoRenderer *renderer = DIA_CAIRO_RENDERER (self);
- DIAG_NOTE(g_message("%s_rect %f,%f -> %f,%f",
- fill ? "fill" : "draw",
- ul_corner->x, ul_corner->y, lr_corner->x, lr_corner->y));
-
- cairo_set_source_rgba (renderer->cr, color->red, color->green, color->blue, color->alpha);
-
- cairo_rectangle (renderer->cr,
- ul_corner->x, ul_corner->y,
- lr_corner->x - ul_corner->x, lr_corner->y - ul_corner->y);
-
- if (fill)
+ DIAG_NOTE (g_message ("%s_rect %f,%f -> %f,%f",
+ fill ? "fill" : "draw",
+ ul_corner->x,
+ ul_corner->y,
+ lr_corner->x,
+ lr_corner->y));
+
+ cairo_set_source_rgba (renderer->cr,
+ color->red,
+ color->green,
+ color->blue,
+ color->alpha);
+
+ cairo_rectangle (renderer->cr,
+ ul_corner->x,
+ ul_corner->y,
+ lr_corner->x - ul_corner->x,
+ lr_corner->y - ul_corner->y);
+
+ if (fill) {
_dia_cairo_fill (renderer, FALSE);
- else
+ } else {
cairo_stroke (renderer->cr);
- DIAG_STATE(renderer->cr)
+ }
+
+ DIAG_STATE (renderer->cr)
}
static void
-draw_rect(DiaRenderer *self,
- Point *ul_corner, Point *lr_corner,
- Color *fill, Color *stroke)
+dia_cairo_renderer_draw_rect (DiaRenderer *self,
+ Point *ul_corner,
+ Point *lr_corner,
+ Color *fill,
+ Color *stroke)
{
- if (fill)
+ if (fill) {
_rect (self, ul_corner, lr_corner, fill, TRUE);
- if (stroke)
+ }
+ if (stroke) {
_rect (self, ul_corner, lr_corner, stroke, FALSE);
+ }
}
static void
-draw_arc(DiaRenderer *self,
- Point *center,
- real width, real height,
- real angle1, real angle2,
- Color *color)
+dia_cairo_renderer_draw_arc (DiaRenderer *self,
+ Point *center,
+ real width,
+ real height,
+ real angle1,
+ real angle2,
+ Color *color)
{
DiaCairoRenderer *renderer = DIA_CAIRO_RENDERER (self);
Point start;
double a1, a2;
real onedu = 0.0;
- DIAG_NOTE(g_message("draw_arc %fx%f <%f,<%f",
- width, height, angle1, angle2));
+ DIAG_NOTE (g_message ("draw_arc %fx%f <%f,<%f",
+ width,
+ height,
+ angle1,
+ angle2));
g_return_if_fail (!isnan (angle1) && !isnan (angle2));
- cairo_set_source_rgba (renderer->cr, color->red, color->green, color->blue, color->alpha);
+ cairo_set_source_rgba (renderer->cr,
+ color->red,
+ color->green,
+ color->blue,
+ color->alpha);
- if (!renderer->stroke_pending)
+ if (!renderer->stroke_pending) {
cairo_new_path (renderer->cr);
- start.x = center->x + (width / 2.0) * cos((M_PI / 180.0) * angle1);
- start.y = center->y - (height / 2.0) * sin((M_PI / 180.0) * angle1);
- if (!renderer->stroke_pending) /* when activated the first current point must be set */
+ }
+ start.x = center->x + (width / 2.0) * cos ((M_PI / 180.0) * angle1);
+ start.y = center->y - (height / 2.0) * sin ((M_PI / 180.0) * angle1);
+ if (!renderer->stroke_pending) {
+ /* when activated the first current point must be set */
cairo_move_to (renderer->cr, start.x, start.y);
+ }
a1 = - (angle1 / 180.0) * G_PI;
a2 = - (angle2 / 180.0) * G_PI;
/* FIXME: to handle width != height some cairo_scale/cairo_translate would be needed */
ensure_minimum_one_device_unit (renderer, &onedu);
/* FIXME2: with too small arcs cairo goes into an endless loop */
if (height/2.0 > onedu && width/2.0 > onedu) {
- if (angle2 > angle1)
- cairo_arc_negative (renderer->cr, center->x, center->y,
- width > height ? height / 2.0 : width / 2.0, /* FIXME 2nd radius */
- a1, a2);
- else
- cairo_arc (renderer->cr, center->x, center->y,
- width > height ? height / 2.0 : width / 2.0, /* FIXME 2nd radius */
- a1, a2);
+ if (angle2 > angle1) {
+ cairo_arc_negative (renderer->cr,
+ center->x, center->y,
+ width > height ? height / 2.0 : width / 2.0, /* FIXME 2nd radius */
+ a1,
+ a2);
+ } else {
+ cairo_arc (renderer->cr,
+ center->x,
+ center->y,
+ width > height ? height / 2.0 : width / 2.0, /* FIXME 2nd radius */
+ a1,
+ a2);
+ }
}
- if (!renderer->stroke_pending)
+ if (!renderer->stroke_pending) {
cairo_stroke (renderer->cr);
- DIAG_STATE(renderer->cr)
+ }
+
+ DIAG_STATE (renderer->cr)
}
static void
-fill_arc(DiaRenderer *self,
- Point *center,
- real width, real height,
- real angle1, real angle2,
- Color *color)
+dia_cairo_renderer_fill_arc (DiaRenderer *self,
+ Point *center,
+ real width,
+ real height,
+ real angle1,
+ real angle2,
+ Color *color)
{
DiaCairoRenderer *renderer = DIA_CAIRO_RENDERER (self);
Point start;
double a1, a2;
- DIAG_NOTE(g_message("draw_arc %fx%f <%f,<%f",
- width, height, angle1, angle2));
+ DIAG_NOTE (g_message ("draw_arc %fx%f <%f,<%f",
+ width,
+ height,
+ angle1,
+ angle2));
+
+ cairo_set_source_rgba (renderer->cr,
+ color->red,
+ color->green,
+ color->blue,
+ color->alpha);
- cairo_set_source_rgba (renderer->cr, color->red, color->green, color->blue, color->alpha);
-
cairo_new_path (renderer->cr);
- start.x = center->x + (width / 2.0) * cos((M_PI / 180.0) * angle1);
- start.y = center->y - (height / 2.0) * sin((M_PI / 180.0) * angle1);
+ start.x = center->x + (width / 2.0) * cos ((M_PI / 180.0) * angle1);
+ start.y = center->y - (height / 2.0) * sin ((M_PI / 180.0) * angle1);
cairo_move_to (renderer->cr, center->x, center->y);
cairo_line_to (renderer->cr, start.x, start.y);
a1 = - (angle1 / 180.0) * G_PI;
a2 = - (angle2 / 180.0) * G_PI;
/* FIXME: to handle width != height some cairo_scale/cairo_translate would be needed */
- if (angle2 > angle1)
- cairo_arc_negative (renderer->cr, center->x, center->y,
- width > height ? height / 2.0 : width / 2.0, /* XXX 2nd radius */
- a1, a2);
- else
- cairo_arc (renderer->cr, center->x, center->y,
- width > height ? height / 2.0 : width / 2.0, /* XXX 2nd radius */
- a1, a2);
+ if (angle2 > angle1) {
+ cairo_arc_negative (renderer->cr,
+ center->x,
+ center->y,
+ width > height ? height / 2.0 : width / 2.0, /* XXX 2nd radius */
+ a1,
+ a2);
+ } else {
+ cairo_arc (renderer->cr,
+ center->x,
+ center->y,
+ width > height ? height / 2.0 : width / 2.0, /* XXX 2nd radius */
+ a1,
+ a2);
+ }
cairo_line_to (renderer->cr, center->x, center->y);
cairo_close_path (renderer->cr);
_dia_cairo_fill (renderer, FALSE);
- DIAG_STATE(renderer->cr)
+
+ DIAG_STATE (renderer->cr)
}
static void
-_ellipse(DiaRenderer *self,
- Point *center,
- real width, real height,
- Color *color,
- gboolean fill)
+_ellipse (DiaRenderer *self,
+ Point *center,
+ real width,
+ real height,
+ Color *color,
+ gboolean fill)
{
DiaCairoRenderer *renderer = DIA_CAIRO_RENDERER (self);
- DIAG_NOTE(g_message("%s_ellipse %fx%f center @ %f,%f",
- fill ? "fill" : "draw", width, height, center->x, center->y));
+ DIAG_NOTE (g_message ("%s_ellipse %fx%f center @ %f,%f",
+ fill ? "fill" : "draw",
+ width,
+ height,
+ center->x,
+ center->y));
/* avoid screwing cairo context - I'd say restore should fix it again, but it doesn't
* (dia.exe:3152): DiaCairo-WARNING **: diacairo-renderer.c:254, invalid matrix (not invertible)
*/
- if (!(width > 0. && height > 0.))
+ if (!(width > 0. && height > 0.)) {
return;
+ }
- cairo_set_source_rgba (renderer->cr, color->red, color->green, color->blue, color->alpha);
+ cairo_set_source_rgba (renderer->cr,
+ color->red,
+ color->green,
+ color->blue,
+ color->alpha);
cairo_save (renderer->cr);
- /* don't create a line from the current point to the beginning
+ /* don't create a line from the current point to the beginning
* of the ellipse */
cairo_new_sub_path (renderer->cr);
/* copied straight from cairo's documentation, and fixed the bug there */
@@ -764,152 +904,179 @@ _ellipse(DiaRenderer *self,
cairo_arc (renderer->cr, 0., 0., 1., 0., 2 * G_PI);
cairo_restore (renderer->cr);
- if (fill)
+ if (fill) {
_dia_cairo_fill (renderer, FALSE);
- else
+ } else {
cairo_stroke (renderer->cr);
- DIAG_STATE(renderer->cr)
+ }
+
+ DIAG_STATE (renderer->cr)
}
static void
-draw_ellipse(DiaRenderer *self,
- Point *center,
- real width, real height,
- Color *fill, Color *stroke)
+dia_cairo_renderer_draw_ellipse (DiaRenderer *self,
+ Point *center,
+ real width,
+ real height,
+ Color *fill,
+ Color *stroke)
{
- if (fill)
+ if (fill) {
_ellipse (self, center, width, height, fill, TRUE);
- if (stroke)
+ }
+ if (stroke) {
_ellipse (self, center, width, height, stroke, FALSE);
+ }
}
static void
-_bezier(DiaRenderer *self,
- BezPoint *points,
- int numpoints,
- Color *color,
- gboolean fill,
- gboolean closed)
+_bezier (DiaRenderer *self,
+ BezPoint *points,
+ int numpoints,
+ Color *color,
+ gboolean fill,
+ gboolean closed)
{
DiaCairoRenderer *renderer = DIA_CAIRO_RENDERER (self);
int i;
- DIAG_NOTE(g_message("%s_bezier n:%d %fx%f ...",
- fill ? "fill" : "draw", numpoints, points->p1.x, points->p1.y));
+ DIAG_NOTE (g_message ("%s_bezier n:%d %fx%f ...",
+ fill ? "fill" : "draw",
+ numpoints,
+ points->p1.x,
+ points->p1.y));
- cairo_set_source_rgba (renderer->cr, color->red, color->green, color->blue, color->alpha);
+ cairo_set_source_rgba (renderer->cr,
+ color->red,
+ color->green,
+ color->blue,
+ color->alpha);
cairo_new_path (renderer->cr);
- for (i = 0; i < numpoints; i++)
- {
- switch (points[i].type)
- {
- case BEZ_MOVE_TO:
- cairo_move_to (renderer->cr, points[i].p1.x, points[i].p1.y);
- break;
- case BEZ_LINE_TO:
- cairo_line_to (renderer->cr, points[i].p1.x, points[i].p1.y);
- break;
- case BEZ_CURVE_TO:
- cairo_curve_to (renderer->cr,
- points[i].p1.x, points[i].p1.y,
- points[i].p2.x, points[i].p2.y,
- points[i].p3.x, points[i].p3.y);
- break;
- default :
- g_assert_not_reached ();
+ for (i = 0; i < numpoints; i++) {
+ switch (points[i].type) {
+ case BEZ_MOVE_TO:
+ cairo_move_to (renderer->cr, points[i].p1.x, points[i].p1.y);
+ break;
+ case BEZ_LINE_TO:
+ cairo_line_to (renderer->cr, points[i].p1.x, points[i].p1.y);
+ break;
+ case BEZ_CURVE_TO:
+ cairo_curve_to (renderer->cr,
+ points[i].p1.x, points[i].p1.y,
+ points[i].p2.x, points[i].p2.y,
+ points[i].p3.x, points[i].p3.y);
+ break;
+ default:
+ g_assert_not_reached ();
}
}
- if (closed)
+ if (closed) {
cairo_close_path(renderer->cr);
- if (fill)
+ }
+ if (fill) {
_dia_cairo_fill (renderer, FALSE);
- else
+ } else {
cairo_stroke (renderer->cr);
+ }
+
DIAG_STATE(renderer->cr)
}
static void
-draw_bezier(DiaRenderer *self,
- BezPoint *points,
- int numpoints,
- Color *color)
+dia_cairo_renderer_draw_bezier (DiaRenderer *self,
+ BezPoint *points,
+ int numpoints,
+ Color *color)
{
_bezier (self, points, numpoints, color, FALSE, FALSE);
}
static void
-draw_beziergon (DiaRenderer *self,
- BezPoint *points,
- int numpoints,
- Color *fill,
- Color *stroke)
+dia_cairo_renderer_draw_beziergon (DiaRenderer *self,
+ BezPoint *points,
+ int numpoints,
+ Color *fill,
+ Color *stroke)
{
- if (fill)
+ if (fill) {
_bezier (self, points, numpoints, fill, TRUE, TRUE);
+ }
/* XXX: optimize if line_width is zero and fill==stroke */
- if (stroke)
+ if (stroke) {
_bezier (self, points, numpoints, stroke, FALSE, TRUE);
+ }
}
static void
-draw_string(DiaRenderer *self,
- const char *text,
- Point *pos, Alignment alignment,
- Color *color)
+dia_cairo_renderer_draw_string (DiaRenderer *self,
+ const char *text,
+ Point *pos,
+ Alignment alignment,
+ Color *color)
{
DiaCairoRenderer *renderer = DIA_CAIRO_RENDERER (self);
- int len = strlen(text);
+ int len = strlen (text);
- DIAG_NOTE(g_message("draw_string(%d) %f,%f %s",
- len, pos->x, pos->y, text));
+ DIAG_NOTE (g_message ("draw_string(%d) %f,%f %s",
+ len, pos->x, pos->y, text));
- if (len < 1) return; /* shouldn't this be handled by Dia's core ? */
+ if (len < 1) {
+ return;
+ /* shouldn't this be handled by Dia's core ? */
+ }
- cairo_set_source_rgba (renderer->cr, color->red, color->green, color->blue, color->alpha);
+ cairo_set_source_rgba (renderer->cr,
+ color->red,
+ color->green,
+ color->blue,
+ color->alpha);
cairo_save (renderer->cr);
/* alignment calculation done by pangocairo? */
pango_layout_set_alignment (renderer->layout, alignment == ALIGN_CENTER ? PANGO_ALIGN_CENTER :
alignment == ALIGN_RIGHT ? PANGO_ALIGN_RIGHT :
PANGO_ALIGN_LEFT);
pango_layout_set_text (renderer->layout, text, len);
{
- PangoLayoutIter *iter = pango_layout_get_iter(renderer->layout);
- int bline = pango_layout_iter_get_baseline(iter);
+ PangoLayoutIter *iter = pango_layout_get_iter (renderer->layout);
+ int bline = pango_layout_iter_get_baseline (iter);
/* although we give the alignment above we need to adjust the start point */
PangoRectangle extents;
int shift;
pango_layout_iter_get_line_extents (iter, NULL, &extents);
- shift = alignment == ALIGN_CENTER ? PANGO_RBEARING(extents)/2 :
- alignment == ALIGN_RIGHT ? PANGO_RBEARING(extents) : 0;
+ shift = alignment == ALIGN_CENTER ? PANGO_RBEARING (extents)/2 :
+ alignment == ALIGN_RIGHT ? PANGO_RBEARING (extents) : 0;
shift /= FONT_SIZE_TWEAK;
bline /= FONT_SIZE_TWEAK;
- cairo_move_to (renderer->cr, pos->x - (double)shift / PANGO_SCALE, pos->y - (double)bline / PANGO_SCALE);
+ cairo_move_to (renderer->cr,
+ pos->x - (double) shift / PANGO_SCALE,
+ pos->y - (double) bline / PANGO_SCALE);
pango_layout_iter_free (iter);
}
/* does this hide bug #341481? */
- cairo_scale (renderer->cr, 1.0/FONT_SIZE_TWEAK, 1.0/FONT_SIZE_TWEAK);
+ cairo_scale (renderer->cr, 1.0 / FONT_SIZE_TWEAK, 1.0 / FONT_SIZE_TWEAK);
pango_cairo_update_layout (renderer->cr, renderer->layout);
pango_cairo_show_layout (renderer->cr, renderer->layout);
/* restoring the previous scale */
cairo_restore (renderer->cr);
- DIAG_STATE(renderer->cr)
+ DIAG_STATE (renderer->cr)
}
static cairo_surface_t *
_image_to_mime_surface (DiaCairoRenderer *renderer,
- DiaImage *image)
+ DiaImage *image)
{
cairo_surface_type_t st;
const char *fname = dia_image_filename (image);
- int w = dia_image_width(image);
- int h = dia_image_height(image);
+ int w = dia_image_width (image);
+ int h = dia_image_height (image);
const char *mime_type = NULL;
- if (!renderer->surface)
+ if (!renderer->surface) {
return NULL;
+ }
/* We only use the "mime" surface if:
* - the target supports it
@@ -917,139 +1084,139 @@ _image_to_mime_surface (DiaCairoRenderer *renderer,
* - the cairo version is new enough including
* http://cgit.freedesktop.org/cairo/commit/?id=35e0a2685134
*/
- if (g_str_has_suffix (fname, ".jpg") || g_str_has_suffix (fname, ".jpeg"))
+ if (g_str_has_suffix (fname, ".jpg") || g_str_has_suffix (fname, ".jpeg")) {
mime_type = CAIRO_MIME_TYPE_JPEG;
- else if (g_str_has_suffix (fname, ".png"))
+ } else if (g_str_has_suffix (fname, ".png")) {
mime_type = CAIRO_MIME_TYPE_PNG;
+ }
st = cairo_surface_get_type (renderer->surface);
if ( mime_type
- && cairo_version() >= CAIRO_VERSION_ENCODE(1, 12, 18)
- && (CAIRO_SURFACE_TYPE_PDF == st || CAIRO_SURFACE_TYPE_SVG == st))
- {
- cairo_surface_t *surface;
- gchar *data = NULL;
- gsize length = 0;
-
- /* we still ned to create the image surface, but dont need to fill it */
- surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, w, h);
- cairo_surface_mark_dirty (surface); /* no effect */
- if ( g_file_get_contents (fname, &data, &length, NULL)
- && cairo_surface_set_mime_data (surface, mime_type,
- (unsigned char *)data,
- length, g_free, data) == CAIRO_STATUS_SUCCESS)
- return surface;
- cairo_surface_destroy (surface);
- g_free (data);
+ && cairo_version () >= CAIRO_VERSION_ENCODE (1, 12, 18)
+ && (CAIRO_SURFACE_TYPE_PDF == st || CAIRO_SURFACE_TYPE_SVG == st)) {
+ cairo_surface_t *surface;
+ gchar *data = NULL;
+ gsize length = 0;
+
+ /* we still ned to create the image surface, but dont need to fill it */
+ surface = cairo_image_surface_create (CAIRO_FORMAT_RGB24, w, h);
+ cairo_surface_mark_dirty (surface); /* no effect */
+ if ( g_file_get_contents (fname, &data, &length, NULL)
+ && cairo_surface_set_mime_data (surface, mime_type,
+ (unsigned char *) data,
+ length, g_free, data) == CAIRO_STATUS_SUCCESS) {
+ return surface;
}
+ cairo_surface_destroy (surface);
+ g_free (data);
+ }
return NULL;
}
static void
-draw_rotated_image (DiaRenderer *self,
- Point *point,
- real width, real height,
- real angle,
- DiaImage *image)
+dia_cairo_renderer_draw_rotated_image (DiaRenderer *self,
+ Point *point,
+ real width,
+ real height,
+ real angle,
+ DiaImage *image)
{
DiaCairoRenderer *renderer = DIA_CAIRO_RENDERER (self);
cairo_surface_t *surface;
guint8 *data;
- int w = dia_image_width(image);
- int h = dia_image_height(image);
- int rs = dia_image_rowstride(image);
-
- DIAG_NOTE(g_message("draw_image %fx%f [%d(%d),%d] @%f,%f",
- width, height, w, rs, h, point->x, point->y));
-
- if ((surface = _image_to_mime_surface (renderer, image)) != NULL)
- {
- data = NULL;
+ int w = dia_image_width (image);
+ int h = dia_image_height (image);
+ int rs = dia_image_rowstride (image);
+
+ DIAG_NOTE (g_message ("draw_image %fx%f [%d(%d),%d] @%f,%f",
+ width, height, w, rs, h, point->x, point->y));
+
+ if ((surface = _image_to_mime_surface (renderer, image)) != NULL) {
+ data = NULL;
+ } else if (dia_image_rgba_data (image)) {
+ const guint8 *p1 = dia_image_rgba_data (image);
+ /* we need to make a copy to rearrange channels ... */
+ guint8 *p2 = data = g_try_malloc (h * rs);
+ int i;
+
+ if (!data) {
+ message_warning (_("Not enough memory for image drawing."));
+ return;
}
- else if (dia_image_rgba_data (image))
- {
- const guint8 *p1 = dia_image_rgba_data (image);
- /* we need to make a copy to rearrange channels ... */
- guint8 *p2 = data = g_try_malloc (h * rs);
- int i;
-
- if (!data)
- {
- message_warning (_("Not enough memory for image drawing."));
- return;
- }
-
- for (i = 0; i < (h * rs) / 4; i++)
- {
+
+ for (i = 0; i < (h * rs) / 4; i++) {
# if G_BYTE_ORDER == G_LITTLE_ENDIAN
- p2[0] = p1[2]; /* b */
- p2[1] = p1[1]; /* g */
- p2[2] = p1[0]; /* r */
- p2[3] = p1[3]; /* a */
+ p2[0] = p1[2]; /* b */
+ p2[1] = p1[1]; /* g */
+ p2[2] = p1[0]; /* r */
+ p2[3] = p1[3]; /* a */
# else
- p2[3] = p1[2]; /* b */
- p2[2] = p1[1]; /* g */
- p2[1] = p1[0]; /* r */
- p2[0] = p1[3]; /* a */
+ p2[3] = p1[2]; /* b */
+ p2[2] = p1[1]; /* g */
+ p2[1] = p1[0]; /* r */
+ p2[0] = p1[3]; /* a */
# endif
- p1+=4;
- p2+=4;
- }
+ p1+=4;
+ p2+=4;
+ }
+
+ surface = cairo_image_surface_create_for_data (data,
+ CAIRO_FORMAT_ARGB32,
+ w,
+ h,
+ rs);
+ } else {
+ guint8 *p = NULL, *p2;
+ guint8 *p1 = data = dia_image_rgb_data (image);
+ /* cairo wants RGB24 32 bit aligned, so copy ... */
+ int x, y;
+
+ if (data) {
+ p = p2 = g_try_malloc(h*w*4);
+ }
- surface = cairo_image_surface_create_for_data (data, CAIRO_FORMAT_ARGB32, w, h, rs);
+ if (!p) {
+ message_warning (_("Not enough memory for image drawing."));
+ return;
}
- else
- {
- guint8 *p = NULL, *p2;
- guint8 *p1 = data = dia_image_rgb_data (image);
- /* cairo wants RGB24 32 bit aligned, so copy ... */
- int x, y;
-
- if (data)
- p = p2 = g_try_malloc(h*w*4);
-
- if (!p)
- {
- message_warning (_("Not enough memory for image drawing."));
- return;
- }
-
- for (y = 0; y < h; y++)
- {
- for (x = 0; x < w; x++)
- {
+
+ for (y = 0; y < h; y++) {
+ for (x = 0; x < w; x++) {
#if G_BYTE_ORDER == G_LITTLE_ENDIAN
- /* apparently BGR is required */
- p2[x*4 ] = p1[x*3+2];
- p2[x*4+1] = p1[x*3+1];
- p2[x*4+2] = p1[x*3 ];
- p2[x*4+3] = 0x80; /* should not matter */
+ /* apparently BGR is required */
+ p2[x*4 ] = p1[x*3+2];
+ p2[x*4+1] = p1[x*3+1];
+ p2[x*4+2] = p1[x*3 ];
+ p2[x*4+3] = 0x80; /* should not matter */
#else
- p2[x*4+3] = p1[x*3+2];
- p2[x*4+2] = p1[x*3+1];
- p2[x*4+1] = p1[x*3 ];
- p2[x*4+0] = 0x80; /* should not matter */
+ p2[x*4+3] = p1[x*3+2];
+ p2[x*4+2] = p1[x*3+1];
+ p2[x*4+1] = p1[x*3 ];
+ p2[x*4+0] = 0x80; /* should not matter */
#endif
- }
- p2 += (w*4);
- p1 += rs;
- }
- surface = cairo_image_surface_create_for_data (p, CAIRO_FORMAT_RGB24, w, h, w*4);
- g_free (data);
- data = p;
+ }
+ p2 += (w*4);
+ p1 += rs;
}
+ surface = cairo_image_surface_create_for_data (p,
+ CAIRO_FORMAT_RGB24,
+ w,
+ h,
+ w * 4);
+ g_free (data);
+ data = p;
+ }
cairo_save (renderer->cr);
cairo_translate (renderer->cr, point->x, point->y);
cairo_scale (renderer->cr, width/w, height/h);
cairo_move_to (renderer->cr, 0.0, 0.0);
cairo_set_source_surface (renderer->cr, surface, 0.0, 0.0);
- if (angle != 0.0)
- {
- DiaMatrix rotate;
- Point center = { w/2, h/2 };
+ if (angle != 0.0) {
+ DiaMatrix rotate;
+ Point center = { w/2, h/2 };
- dia_matrix_set_rotate_around (&rotate, -G_PI * angle / 180.0, ¢er);
- cairo_pattern_set_matrix (cairo_get_source (renderer->cr), (cairo_matrix_t *)&rotate);
- }
+ dia_matrix_set_rotate_around (&rotate, -G_PI * angle / 180.0, ¢er);
+ cairo_pattern_set_matrix (cairo_get_source (renderer->cr), (cairo_matrix_t *) &rotate);
+ }
#if 0
/*
* CAIRO_FILTER_FAST: aka. CAIRO_FILTER_NEAREST
@@ -1064,18 +1231,23 @@ draw_rotated_image (DiaRenderer *self,
g_free (data);
- DIAG_STATE(renderer->cr);
+ DIAG_STATE (renderer->cr);
}
static void
-draw_image (DiaRenderer *self,
- Point *point,
- real width, real height,
- DiaImage *image)
+dia_cairo_renderer_draw_image (DiaRenderer *self,
+ Point *point,
+ real width,
+ real height,
+ DiaImage *image)
{
- draw_rotated_image (self, point, width, height, 0.0, image);
+ dia_cairo_renderer_draw_rotated_image (self,
+ point,
+ width,
+ height,
+ 0.0,
+ image);
}
-static gpointer parent_class = NULL;
/*!
* \brief Fill and/or stroke a rectangle with rounded corner
@@ -1084,18 +1256,20 @@ static gpointer parent_class = NULL;
* \memberof _DiaCairoRenderer
*/
static void
-draw_rounded_rect (DiaRenderer *self,
- Point *ul_corner, Point *lr_corner,
- Color *fill, Color *stroke,
- real radius)
+dia_cairo_renderer_draw_rounded_rect (DiaRenderer *self,
+ Point *ul_corner,
+ Point *lr_corner,
+ Color *fill,
+ Color *stroke,
+ real radius)
{
DiaCairoRenderer *renderer = DIA_CAIRO_RENDERER (self);
real r2 = (lr_corner->x - ul_corner->x) / 2.0;
- radius = MIN(r2, radius);
+ radius = MIN (r2, radius);
r2 = (lr_corner->y - ul_corner->y) / 2.0;
- radius = MIN(r2, radius);
+ radius = MIN (r2, radius);
if (radius < 0.0001) {
- draw_rect (self, ul_corner, lr_corner, fill, stroke);
+ dia_cairo_renderer_draw_rect (self, ul_corner, lr_corner, fill, stroke);
return;
}
g_return_if_fail (stroke != NULL || fill != NULL);
@@ -1104,9 +1278,12 @@ draw_rounded_rect (DiaRenderer *self,
cairo_move_to (renderer->cr, ul_corner->x + radius, ul_corner->y);
renderer->stroke_pending = TRUE;
/* only stroke, no fill gives us the contour */
- DIA_RENDERER_CLASS(parent_class)->draw_rounded_rect(self,
- ul_corner, lr_corner,
- NULL, stroke ? stroke : fill, radius);
+ DIA_RENDERER_CLASS (dia_cairo_renderer_parent_class)->draw_rounded_rect (self,
+ ul_corner,
+ lr_corner,
+ NULL,
+ stroke ? stroke : fill,
+ radius);
renderer->stroke_pending = FALSE;
cairo_close_path (renderer->cr);
if (fill) { /* if a stroke follows preserve the path */
@@ -1120,9 +1297,11 @@ draw_rounded_rect (DiaRenderer *self,
}
static void
-draw_rounded_polyline (DiaRenderer *self,
- Point *points, int num_points,
- Color *color, real radius)
+dia_cairo_renderer_draw_rounded_polyline (DiaRenderer *self,
+ Point *points,
+ int num_points,
+ Color *color,
+ real radius)
{
DiaCairoRenderer *renderer = DIA_CAIRO_RENDERER (self);
@@ -1132,48 +1311,19 @@ draw_rounded_polyline (DiaRenderer *self,
renderer->stroke_pending = TRUE;
/* set the starting point to avoid move-to in between */
cairo_move_to (renderer->cr, points[0].x, points[0].y);
- DIA_RENDERER_CLASS(parent_class)->draw_rounded_polyline (self,
- points, num_points,
- color, radius);
+ DIA_RENDERER_CLASS (dia_cairo_renderer_parent_class)->draw_rounded_polyline (self,
+ points,
+ num_points,
+ color,
+ radius);
renderer->stroke_pending = FALSE;
cairo_stroke (renderer->cr);
- DIAG_STATE(renderer->cr)
-}
-/* gobject boiler plate */
-static void cairo_renderer_init (DiaCairoRenderer *r, void *p);
-static void cairo_renderer_class_init (DiaCairoRendererClass *klass);
-
-GType
-dia_cairo_renderer_get_type (void)
-{
- static GType object_type = 0;
-
- if (!object_type)
- {
- static const GTypeInfo object_info =
- {
- sizeof (DiaCairoRendererClass),
- (GBaseInitFunc) NULL,
- (GBaseFinalizeFunc) NULL,
- (GClassInitFunc) cairo_renderer_class_init,
- NULL, /* class_finalize */
- NULL, /* class_data */
- sizeof (DiaCairoRenderer),
- 0, /* n_preallocs */
- (GInstanceInitFunc)cairo_renderer_init /* init */
- };
-
- object_type = g_type_register_static (DIA_TYPE_RENDERER,
- "DiaCairoRenderer",
- &object_info, 0);
- }
-
- return object_type;
+ DIAG_STATE (renderer->cr)
}
static void
-cairo_renderer_init (DiaCairoRenderer *renderer, void *p)
+dia_cairo_renderer_init (DiaCairoRenderer *renderer)
{
renderer->scale = 1.0;
}
@@ -1184,59 +1334,59 @@ cairo_renderer_finalize (GObject *object)
DiaCairoRenderer *renderer = DIA_CAIRO_RENDERER (object);
cairo_destroy (renderer->cr);
- if (renderer->surface)
+ if (renderer->surface) {
cairo_surface_destroy (renderer->surface);
- if (renderer->layout)
- g_object_unref (renderer->layout);
+ }
+ if (renderer->layout) {
+ g_object_unref (renderer->layout);
+ }
- G_OBJECT_CLASS (parent_class)->finalize (object);
+ G_OBJECT_CLASS (dia_cairo_renderer_parent_class)->finalize (object);
}
static void
-cairo_renderer_class_init (DiaCairoRendererClass *klass)
+dia_cairo_renderer_class_init (DiaCairoRendererClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
DiaRendererClass *renderer_class = DIA_RENDERER_CLASS (klass);
- parent_class = g_type_class_peek_parent (klass);
-
object_class->finalize = cairo_renderer_finalize;
/* renderer members */
- renderer_class->begin_render = begin_render;
- renderer_class->end_render = end_render;
- renderer_class->draw_object = draw_object;
+ renderer_class->begin_render = dia_cairo_renderer_begin_render;
+ renderer_class->end_render = dia_cairo_renderer_end_render;
+ renderer_class->draw_object = dia_cairo_renderer_draw_object;
- renderer_class->set_linewidth = set_linewidth;
- renderer_class->set_linecaps = set_linecaps;
- renderer_class->set_linejoin = set_linejoin;
- renderer_class->set_linestyle = set_linestyle;
- renderer_class->set_fillstyle = set_fillstyle;
+ renderer_class->set_linewidth = dia_cairo_renderer_set_linewidth;
+ renderer_class->set_linecaps = dia_cairo_renderer_set_linecaps;
+ renderer_class->set_linejoin = dia_cairo_renderer_set_linejoin;
+ renderer_class->set_linestyle = dia_cairo_renderer_set_linestyle;
+ renderer_class->set_fillstyle = dia_cairo_renderer_set_fillstyle;
- renderer_class->set_font = set_font;
+ renderer_class->set_font = dia_cairo_renderer_set_font;
- renderer_class->draw_line = draw_line;
- renderer_class->draw_polygon = draw_polygon;
- renderer_class->draw_arc = draw_arc;
- renderer_class->fill_arc = fill_arc;
- renderer_class->draw_ellipse = draw_ellipse;
+ renderer_class->draw_line = dia_cairo_renderer_draw_line;
+ renderer_class->draw_polygon = dia_cairo_renderer_draw_polygon;
+ renderer_class->draw_arc = dia_cairo_renderer_draw_arc;
+ renderer_class->fill_arc = dia_cairo_renderer_fill_arc;
+ renderer_class->draw_ellipse = dia_cairo_renderer_draw_ellipse;
- renderer_class->draw_string = draw_string;
- renderer_class->draw_image = draw_image;
+ renderer_class->draw_string = dia_cairo_renderer_draw_string;
+ renderer_class->draw_image = dia_cairo_renderer_draw_image;
/* medium level functions */
- renderer_class->draw_rect = draw_rect;
- renderer_class->draw_polyline = draw_polyline;
+ renderer_class->draw_rect = dia_cairo_renderer_draw_rect;
+ renderer_class->draw_polyline = dia_cairo_renderer_draw_polyline;
- renderer_class->draw_bezier = draw_bezier;
- renderer_class->draw_beziergon = draw_beziergon;
+ renderer_class->draw_bezier = dia_cairo_renderer_draw_bezier;
+ renderer_class->draw_beziergon = dia_cairo_renderer_draw_beziergon;
/* highest level functions */
- renderer_class->draw_rounded_rect = draw_rounded_rect;
- renderer_class->draw_rounded_polyline = draw_rounded_polyline;
- renderer_class->draw_rotated_image = draw_rotated_image;
+ renderer_class->draw_rounded_rect = dia_cairo_renderer_draw_rounded_rect;
+ renderer_class->draw_rounded_polyline = dia_cairo_renderer_draw_rounded_polyline;
+ renderer_class->draw_rotated_image = dia_cairo_renderer_draw_rotated_image;
/* other */
- renderer_class->is_capable_to = is_capable_to;
- renderer_class->set_pattern = set_pattern;
+ renderer_class->is_capable_to = dia_cairo_renderer_is_capable_to;
+ renderer_class->set_pattern = dia_cairo_renderer_set_pattern;
}
diff --git a/lib/renderer/diacairo.c b/lib/renderer/diacairo.c
index 9d8c1ed0..1f2d3db1 100644
--- a/lib/renderer/diacairo.c
+++ b/lib/renderer/diacairo.c
@@ -3,7 +3,7 @@
*
* diacairo.c -- Cairo based export plugin for dia
* Copyright (C) 2004, Hans Breuer, <Hans Breuer Org>
- * based on wpg.c
+ * based on wpg.c
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -75,7 +75,7 @@ cairo_export_data(DiagramData *data, DiaContext *ctx,
FILE *file;
real width, height;
OutputKind kind = (OutputKind)user_data;
- /* the passed in filename is in GLib's filename encoding. On Linux everything
+ /* the passed in filename is in GLib's filename encoding. On Linux everything
* should be fine in passing it to the C-runtime (or cairo). On win32 GLib's
* filename encdong is always utf-8, so another conversion is needed.
*/
@@ -88,7 +88,7 @@ cairo_export_data(DiagramData *data, DiaContext *ctx,
file = g_fopen(filename, "wb"); /* "wb" for binary! */
if (file == NULL) {
- dia_context_add_message_with_errno(ctx, errno, _("Can't open output file %s."),
+ dia_context_add_message_with_errno(ctx, errno, _("Can't open output file %s."),
dia_context_get_filename(ctx));
return FALSE;
}
@@ -103,7 +103,7 @@ cairo_export_data(DiagramData *data, DiaContext *ctx,
}
#endif
} /* != CLIPBOARD */
- renderer = g_object_new (DIA_TYPE_CAIRO_RENDERER, NULL);
+ renderer = g_object_new (DIA_CAIRO_TYPE_RENDERER, NULL);
renderer->dia = data; /* FIXME: not sure if this a good idea */
renderer->scale = 1.0;
@@ -113,19 +113,19 @@ cairo_export_data(DiagramData *data, DiaContext *ctx,
width = data->paper.width * (72.0 / 2.54) + 0.5;
height = data->paper.height * (72.0 / 2.54) + 0.5;
renderer->scale = data->paper.scaling * (72.0 / 2.54);
- DIAG_NOTE(g_message ("PS Surface %dx%d\n", (int)width, (int)height));
+ DIAG_NOTE(g_message ("PS Surface %dx%d\n", (int)width, (int)height));
renderer->surface = cairo_ps_surface_create (filename_crt,
width, height); /* in points? */
/* maybe we should increase the resolution here as well */
break;
-#endif
+#endif
#if defined CAIRO_HAS_PNG_SURFACE || defined CAIRO_HAS_PNG_FUNCTIONS
case OUTPUT_PNGA :
renderer->with_alpha = TRUE;
/* fall through */
case OUTPUT_PNG :
/* quite arbitrary, but consistent with ../pixbuf ;-) */
- renderer->scale = 20.0 * data->paper.scaling;
+ renderer->scale = 20.0 * data->paper.scaling;
width = ceil((data->extents.right - data->extents.left) * renderer->scale) + 1;
height = ceil((data->extents.bottom - data->extents.top) * renderer->scale) + 1;
DIAG_NOTE(g_message ("PNG Surface %dx%d\n", (int)width, (int)height));
@@ -142,7 +142,7 @@ cairo_export_data(DiagramData *data, DiaContext *ctx,
#define DPI 300.0 /* 600.0? */
/* I just don't get how the scaling is supposed to work, dpi versus page size ? */
renderer->scale = data->paper.scaling * (72.0 / 2.54);
- /* Dia's paper.width already contains the scale, cairo needs it without
+ /* Dia's paper.width already contains the scale, cairo needs it without
* Similar for margins, Dia's without, but cairo wants them. The full
* extents don't matter here, because we do cairo_pdf_set_size() for every page.
*/
@@ -159,7 +159,7 @@ cairo_export_data(DiagramData *data, DiaContext *ctx,
#endif
case OUTPUT_SVG :
/* quite arbitrary, but consistent with ../pixbuf ;-) */
- renderer->scale = 20.0 * data->paper.scaling;
+ renderer->scale = 20.0 * data->paper.scaling;
width = ceil((data->extents.right - data->extents.left) * renderer->scale) + 1;
height = ceil((data->extents.bottom - data->extents.top) * renderer->scale) + 1;
DIAG_NOTE(g_message ("SVG Surface %dx%d\n", (int)width, (int)height));
@@ -171,7 +171,7 @@ cairo_export_data(DiagramData *data, DiaContext *ctx,
#ifdef CAIRO_HAS_SCRIPT_SURFACE
case OUTPUT_CAIRO_SCRIPT :
/* quite arbitrary, but consistent with ../pixbuf ;-) */
- renderer->scale = 20.0 * data->paper.scaling;
+ renderer->scale = 20.0 * data->paper.scaling;
width = (data->extents.right - data->extents.left) * renderer->scale + 0.5;
height = (data->extents.bottom - data->extents.top) * renderer->scale + 0.5;
DIAG_NOTE(g_message ("CairoScript Surface %dx%d\n", (int)width, (int)height));
@@ -192,16 +192,16 @@ cairo_export_data(DiagramData *data, DiaContext *ctx,
/* NOT: renderer->with_alpha = TRUE; */
{
/* see wmf/wmf.cpp */
- /* CreateEnhMetaFile() takes 0.01 mm, but the resulting clipboard
+ /* CreateEnhMetaFile() takes 0.01 mm, but the resulting clipboard
* image is much too big, e.g. when pasting to PowerPoint. So instead
- * of 1000 use sth smaller to scale? But that would need new scaling
- * for line thickness as well ...
+ * of 1000 use sth smaller to scale? But that would need new scaling
+ * for line thickness as well ...
* Also there is something wrong with clipping if running on a dual screen
* sometimes parts of the diagram are clipped away. Not sure if this is
* hitting some internal width limits, maintianing the viewport ratio,
* but not the diagram boundaries.
*/
- RECT bbox = { 0, 0,
+ RECT bbox = { 0, 0,
(int)((data->extents.right - data->extents.left) * data->paper.scaling * 1000.0),
(int)((data->extents.bottom - data->extents.top) * data->paper.scaling * 1000.0) };
RECT clip;
@@ -209,8 +209,8 @@ cairo_export_data(DiagramData *data, DiaContext *ctx,
hFileDC = CreateEnhMetaFile (NULL, NULL, &bbox, "DiaCairo\0Diagram\0");
#if 0
- /* On Windows 7/64 with two wide screen monitors, the clipping of the resulting
- * metafile is too small. Scaling the bbox or via SetWorldTransform() does not help.
+ /* On Windows 7/64 with two wide screen monitors, the clipping of the resulting
+ * metafile is too small. Scaling the bbox or via SetWorldTransform() does not help.
* Maybe we need to explitily set the clipping for cairo?
*/
GetClipBox (hFileDC, &clip); /* this is the display resolution */
@@ -232,15 +232,15 @@ cairo_export_data(DiagramData *data, DiaContext *ctx,
#endif
default :
/* quite arbitrary, but consistent with ../pixbuf ;-) */
- renderer->scale = 20.0 * data->paper.scaling;
+ renderer->scale = 20.0 * data->paper.scaling;
width = ceil((data->extents.right - data->extents.left) * renderer->scale) + 1;
height = ceil((data->extents.bottom - data->extents.top) * renderer->scale) + 1;
- DIAG_NOTE(g_message ("Image Surface %dx%d\n", (int)width, (int)height));
+ DIAG_NOTE(g_message ("Image Surface %dx%d\n", (int)width, (int)height));
renderer->surface = cairo_image_surface_create (CAIRO_FORMAT_A8, (int)width, (int)height);
}
/* use extents */
- DIAG_NOTE(g_message("export_data extents %f,%f -> %f,%f",
+ DIAG_NOTE(g_message("export_data extents %f,%f -> %f,%f",
data->extents.left, data->extents.top, data->extents.right, data->extents.bottom));
if (OUTPUT_PDF == kind)
@@ -289,8 +289,8 @@ cairo_export_data(DiagramData *data, DiaContext *ctx,
g_free (pData);
} else if (OUTPUT_CLIPBOARD == kind) {
HENHMETAFILE hEmf = CloseEnhMetaFile(hFileDC);
- if ( OpenClipboard(NULL)
- && EmptyClipboard()
+ if ( OpenClipboard(NULL)
+ && EmptyClipboard()
&& SetClipboardData (CF_ENHMETAFILE, hEmf)
&& CloseClipboard ()) {
hEmf = NULL; /* data now owned by clipboard */
diff --git a/lib/renderer/diacairo.h b/lib/renderer/diacairo.h
index 061ff200..a9ed1d9a 100644
--- a/lib/renderer/diacairo.h
+++ b/lib/renderer/diacairo.h
@@ -41,16 +41,11 @@
/* --- the renderer base class --- */
G_BEGIN_DECLS
-#define DIA_TYPE_CAIRO_RENDERER (dia_cairo_renderer_get_type ())
-#define DIA_CAIRO_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), DIA_TYPE_CAIRO_RENDERER,
DiaCairoRenderer))
-#define DIA_CAIRO_RENDERER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), DIA_TYPE_CAIRO_RENDERER,
DiaCairoRendererClass))
-#define DIA_IS_CAIRO_RENDERER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), DIA_TYPE_CAIRO_RENDERER))
-#define DIA_CAIRO_RENDERER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), DIA_CAIRO_TYPE_RENDERER,
DiaCairoRendererClass))
+G_DEFINE_AUTOPTR_CLEANUP_FUNC (DiaRenderer, g_object_unref)
-GType dia_cairo_renderer_get_type (void) G_GNUC_CONST;
+#define DIA_CAIRO_TYPE_RENDERER dia_cairo_renderer_get_type ()
-typedef struct _DiaCairoRenderer DiaCairoRenderer;
-typedef struct _DiaCairoRendererClass DiaCairoRendererClass;
+G_DECLARE_FINAL_TYPE (DiaCairoRenderer, dia_cairo_renderer, DIA_CAIRO, RENDERER, DiaRenderer)
/*!
* \brief Multi format renderer based on cairo API (http://cairographics.org)
@@ -58,7 +53,7 @@ typedef struct _DiaCairoRendererClass DiaCairoRendererClass;
* The DiaCairoRenderer supports various output formats depending on the build
* configuration of libcairo. Typically these include SVG, PNG, PDF, PostScript
* and the display of the windowing system in use.
- * Also - with a recent enough GTK+ version the cairo renderer is interfacing
+ * Also - with a recent enough GTK+ version the cairo renderer is interfacing
* the native printing subsystem.
* Finally - only on Windows - there is usually support for Windows Metafiles
* (WMF and EMF), the latter used for Clipboard transport of the whole diagram.
@@ -85,11 +80,6 @@ struct _DiaCairoRenderer
DiaPattern *pattern;
};
-struct _DiaCairoRendererClass
-{
- DiaRendererClass parent_class;
-};
-
typedef enum OutputKind
{
OUTPUT_PS = 1,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]