dia r3920 - in trunk: . plug-ins plug-ins/cairo



Author: hans
Date: Sun Mar 16 19:30:32 2008
New Revision: 3920
URL: http://svn.gnome.org/viewvc/dia?rev=3920&view=rev

Log:
2008-03-16  Hans Breuer  <hans breuer org>

	* plug-ins/cairo/diacairo-renderer.c(_rounded_rect) : use cairo_arc()
	instead of approximating arcs with beziers

	* plug-ins/cairo/diacairo.c plug-ins/makefile.msc : resurrection of
	EMF via cairo (cairo-1.6 will support EMF creation via win32-printing
	surface so my own cairo patch is finally obsolete)

	* sheets/*/*.xpm shapes/**/*.xpm : removed all those obsolete XPM



Modified:
   trunk/ChangeLog
   trunk/plug-ins/cairo/diacairo-renderer.c
   trunk/plug-ins/cairo/diacairo.c
   trunk/plug-ins/makefile.msc

Modified: trunk/plug-ins/cairo/diacairo-renderer.c
==============================================================================
--- trunk/plug-ins/cairo/diacairo-renderer.c	(original)
+++ trunk/plug-ins/cairo/diacairo-renderer.c	Sun Mar 16 19:30:32 2008
@@ -812,30 +812,25 @@
   cairo_set_source_rgba (renderer->cr, color->red, color->green, color->blue, 1.0);
 
   cairo_new_path (renderer->cr);
-  cairo_move_to (renderer->cr,
+  cairo_move_to (renderer->cr, /* north-west */
                  topleft->x + radius, topleft->y);
 
-  /* corners are _not_ control points, but halfway */
-  cairo_line_to  (renderer->cr,
+  cairo_line_to  (renderer->cr, /* north-east */
                   bottomright->x - radius, topleft->y);
-  cairo_curve_to (renderer->cr,
-                  bottomright->x - r2, topleft->y, bottomright->x, topleft->y + r2,
-                  bottomright->x, topleft->y + radius);
-  cairo_line_to  (renderer->cr,
+  cairo_arc (renderer->cr,
+             bottomright->x - radius, topleft->y + radius, radius, -G_PI_2, 0);
+  cairo_line_to  (renderer->cr, /* south-east */
                   bottomright->x, bottomright->y - radius);
-  cairo_curve_to (renderer->cr,
-                  bottomright->x, bottomright->y - r2, bottomright->x - r2, bottomright->y,
-                  bottomright->x - radius, bottomright->y);
-  cairo_line_to  (renderer->cr,
+  cairo_arc (renderer->cr,
+             bottomright->x - radius, bottomright->y - radius, radius, 0, G_PI_2);
+  cairo_line_to  (renderer->cr, /* south-west */
                   topleft->x + radius, bottomright->y);
-  cairo_curve_to (renderer->cr,
-                  topleft->x + r2, bottomright->y, topleft->x, bottomright->y - r2,
-                  topleft->x, bottomright->y - radius);
-  cairo_line_to  (renderer->cr,
+  cairo_arc (renderer->cr,
+             topleft->x + radius, bottomright->y - radius, radius, G_PI_2, G_PI);
+  cairo_line_to  (renderer->cr, /* north-west */
                   topleft->x, topleft->y + radius); 
-  cairo_curve_to (renderer->cr,
-                  topleft->x, topleft->y + r2, topleft->x + r2, topleft->y,
-                  topleft->x + radius, topleft->y);
+  cairo_arc (renderer->cr,
+             topleft->x + radius, topleft->y + radius, radius, G_PI, -G_PI_2);
   if (fill)
     cairo_fill (renderer->cr);
   else

Modified: trunk/plug-ins/cairo/diacairo.c
==============================================================================
--- trunk/plug-ins/cairo/diacairo.c	(original)
+++ trunk/plug-ins/cairo/diacairo.c	Sun Mar 16 19:30:32 2008
@@ -61,6 +61,11 @@
 #  ifdef CAIRO_HAS_SVG_SURFACE
 #  include <cairo-svg.h>
 #  endif
+#  ifdef CAIRO_HAS_WIN32_SURFACE
+#  include <cairo-win32.h>
+   /* avoid namespace collisions */
+#  define Rectangle RectangleWin32
+#  endif
 #endif
 
 #include "intl.h"
@@ -86,6 +91,11 @@
   OUTPUT_SVG
 } OutputKind;
 
+#if defined CAIRO_HAS_WIN32_SURFACE && CAIRO_VERSION > 10510
+#define DIA_CAIRO_CAN_EMF 1
+#pragma message ("DiaCairo can EMF;)")
+#endif
+
 /* dia export funtion */
 static void
 export_data(DiagramData *data, const gchar *filename_utf8, 
@@ -96,6 +106,9 @@
   real width, height;
   OutputKind kind = (OutputKind)user_data;
   gchar* filename = g_locale_from_utf8 (filename_utf8, -1, NULL, NULL, NULL);
+#if DIA_CAIRO_CAN_EMF
+  HDC hFileDC = NULL;
+#endif
 
   if (!filename) {
     message_error(_("Can't convert output filename '%s' to locale encoding.\n"
@@ -103,7 +116,7 @@
 		  dia_message_filename(filename_utf8), strerror(errno));
     return;
   }
-  file = fopen(filename, "wb"); /* "wb" for binary! */
+  file = g_fopen(filename, "wb"); /* "wb" for binary! */
 
   if (file == NULL) {
     message_error(_("Can't open output file %s: %s\n"), 
@@ -173,16 +186,31 @@
 						(int)width, (int)height);
     break;
 #endif
-  /* the default Cairo/win32 surface isn't able to do such ... */
-#ifdef CAIRO_HAS_WIN32X_SURFACE
+  /* finally cairo can render to MetaFiles */
+#if DIA_CAIRO_CAN_EMF
   case OUTPUT_EMF :
+  case OUTPUT_WMF : /* different only on close/'play' */
+    /* NOT: renderer->with_alpha = TRUE; */
     renderer->scale = 72.0;
-    renderer->surface = cairo_win32_surface_create (filename, NULL, CAIRO_WIN32_TARGET_EMF, 0, 0);
-    break;
-  case OUTPUT_WMF :
-    renderer->scale = 72.0;
-    renderer->surface = cairo_win32_surface_create (filename, NULL, CAIRO_WIN32_TARGET_WMF, 0, 0);
+    {
+      /* see wmf/wmf.cpp */
+      HDC  refDC = GetDC(NULL);
+      RECT bbox = { 0, 0, 
+#if 0
+                   (int)((data->extents.right - data->extents.left) * renderer->scale * GetDeviceCaps(refDC, LOGPIXELSX)),
+		   (int)((data->extents.bottom - data->extents.top) * renderer->scale * GetDeviceCaps(refDC, LOGPIXELSY)) };
+#else
+                   (int)((data->extents.right - data->extents.left) * renderer->scale 
+		          * 100 * GetDeviceCaps(refDC, HORZSIZE) / GetDeviceCaps(refDC, HORZRES)),
+		   (int)((data->extents.bottom - data->extents.top) * renderer->scale
+		          * 100 * GetDeviceCaps(refDC, VERTSIZE) / GetDeviceCaps(refDC, VERTRES)) };
+#endif
+      hFileDC = CreateEnhMetaFile (refDC, NULL, &bbox, "DiaCairo\0Diagram\0");
+      renderer->surface = cairo_win32_printing_surface_create (hFileDC);
+    }
     break;
+#endif
+#if 0
   case OUTPUT_CB :
     /* just testing, does not create a file but puts content in the clpboard */
     renderer->scale = 72.0;
@@ -210,6 +238,23 @@
       cairo_surface_destroy(renderer->surface);
     }
 #endif
+#if DIA_CAIRO_CAN_EMF
+  if (OUTPUT_EMF == kind) {
+    FILE* f = g_fopen(filename_utf8, "wb");
+    HENHMETAFILE hEmf = CloseEnhMetaFile(hFileDC);
+    UINT nSize = GetEnhMetaFileBits (hEmf, 0, NULL);
+    BYTE* pData = g_new(BYTE, nSize);
+    nSize = GetEnhMetaFileBits (hEmf, nSize, pData);
+    if (f) {
+      fwrite(pData,1,nSize,f);
+      fclose(f);
+    } else {
+      message_error (_("Can't write %d bytes to %s"), nSize, filename_utf8);
+    }
+    DeleteEnhMetaFile (hFileDC);
+    g_free (pData);
+  }
+#endif
   g_object_unref(renderer);
 }
 
@@ -293,7 +338,7 @@
     "cairo-alpha-png"
 };
 
-#ifdef CAIRO_HAS_WIN32X_SURFACE
+#if DIA_CAIRO_CAN_EMF
 static const gchar *emf_extensions[] = { "wmf", NULL };
 static DiaExportFilter emf_export_filter = {
     N_("Cairo WMF"),
@@ -311,7 +356,9 @@
     (void*)OUTPUT_WMF,
     "cairo-wmf"
 };
+#endif
 
+#if 0
 static const gchar *cb_extensions[] = { "cb", NULL };
 static DiaExportFilter cb_export_filter = {
     N_("Cairo Clipboard"),
@@ -388,9 +435,11 @@
   filter_register_export(&png_export_filter);
   filter_register_export(&pnga_export_filter);
 #endif
-#ifdef CAIRO_HAS_WIN32X_SURFACE
+#if DIA_CAIRO_CAN_EMF
   filter_register_export(&emf_export_filter);
   filter_register_export(&wmf_export_filter);
+#endif
+#ifdef CAIRO_HAS_WIN32X_SURFACE
   filter_register_export(&cb_export_filter);
 #endif
 

Modified: trunk/plug-ins/makefile.msc
==============================================================================
--- trunk/plug-ins/makefile.msc	(original)
+++ trunk/plug-ins/makefile.msc	Sun Mar 16 19:30:32 2008
@@ -47,7 +47,7 @@
 
 !IFDEF OBJ_cairo
 PKG_CFLAGS = $(PKG_CFLAGS) $(CAIRO_CFLAGS) -DHAVE_PANGOCAIRO_H
-PKG_LINK = $(PKG_LINK) $(CAIRO_LIBS) $(PANGOCAIRO_LIBS)
+PKG_LINK = $(PKG_LINK) $(CAIRO_LIBS) $(PANGOCAIRO_LIBS) gdi32.lib
 OBJECTS = \
 	diacairo.obj \
 	diacairo-interactive.obj \



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]