[dia] Taking another stab at bug 147386 - clipped PNG
- From: Hans Breuer <hans src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dia] Taking another stab at bug 147386 - clipped PNG
- Date: Wed, 1 Jun 2011 15:57:09 +0000 (UTC)
commit af9e49e5cbce7c5706f318a4cd1da3292da0f0cf
Author: Hans Breuer <hans breuer org>
Date: Sat May 14 21:32:36 2011 +0200
Taking another stab at bug 147386 - clipped PNG
To ensure no clipping at top/left we need some extra gymnastics,
otherwise a box with a line width one one pixel might loose the
top/left border as in bug #147386
Also some ceil for width and height when sizing the PNG surface.
plug-ins/cairo/diacairo-renderer.c | 9 ++++++++-
plug-ins/cairo/diacairo.c | 13 ++++++-------
2 files changed, 14 insertions(+), 8 deletions(-)
---
diff --git a/plug-ins/cairo/diacairo-renderer.c b/plug-ins/cairo/diacairo-renderer.c
index 6db8fa2..8de2785 100644
--- a/plug-ins/cairo/diacairo-renderer.c
+++ b/plug-ins/cairo/diacairo-renderer.c
@@ -74,6 +74,8 @@
#include "diacairo.h"
+static void ensure_minimum_one_device_unit(DiaCairoRenderer *renderer, real *value);
+
/*
* render functions
*/
@@ -81,6 +83,7 @@ static void
begin_render(DiaRenderer *self)
{
DiaCairoRenderer *renderer = DIA_CAIRO_RENDERER (self);
+ real onedu = 0.0;
if (renderer->surface)
renderer->cr = cairo_create (renderer->surface);
@@ -88,7 +91,11 @@ begin_render(DiaRenderer *self)
g_assert (renderer->cr);
cairo_scale (renderer->cr, renderer->scale, renderer->scale);
- cairo_translate (renderer->cr, -renderer->dia->extents.left, -renderer->dia->extents.top);
+ /* to ensure no clipping at top/left we need some extra gymnastics,
+ * otherwise a box with a line witdh one one pixel might loose the
+ * top/left border as in bug #147386 */
+ ensure_minimum_one_device_unit (renderer, &onedu);
+ 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);
diff --git a/plug-ins/cairo/diacairo.c b/plug-ins/cairo/diacairo.c
index 5b28cec..83d5c10 100644
--- a/plug-ins/cairo/diacairo.c
+++ b/plug-ins/cairo/diacairo.c
@@ -160,9 +160,8 @@ export_data(DiagramData *data, const gchar *filename,
case OUTPUT_PNG :
/* quite arbitrary, but consistent with ../pixbuf ;-) */
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;
-
+ 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));
/* use case screwed by API shakeup. We need to special case */
renderer->surface = cairo_image_surface_create(
@@ -190,8 +189,8 @@ export_data(DiagramData *data, const gchar *filename,
case OUTPUT_SVG :
/* quite arbitrary, but consistent with ../pixbuf ;-) */
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;
+ 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));
/* use case screwed by API shakeup. We need to special case */
renderer->surface = cairo_svg_surface_create(
@@ -245,8 +244,8 @@ export_data(DiagramData *data, const gchar *filename,
default :
/* quite arbitrary, but consistent with ../pixbuf ;-) */
renderer->scale = 20.0 * data->paper.scaling;
- width = (data->extents.right - data->extents.left) * renderer->scale;
- height = (data->extents.bottom - data->extents.top) * renderer->scale;
+ 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));
renderer->surface = cairo_image_surface_create (CAIRO_FORMAT_A8, (int)width, (int)height);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]