dia r3984 - in trunk: . app objects/UML plug-ins plug-ins/wmf plug-ins/xslt samples/Self



Author: hans
Date: Sat May  3 14:43:25 2008
New Revision: 3984
URL: http://svn.gnome.org/viewvc/dia?rev=3984&view=rev

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

	* objects/UML/association.c : the transition to full StdProps broke
	the restoration of autorouting swicthed off in version 1 shapes
	* samples/Self/PyDiaObjects.dia : documentation of PyDia which
	showed the problem

	* plug-ins/xslt/xslt.c(xslt_ok) : the directory name passed into xslt
	needs to be an uri (*NIX being more tolerant). Fixes bug #472143.

	* samples/Self/dia-renderer.dia : updated one more

	* app/load_save.c : only update handle positions if the bounding box
	is empty after creation of the object

	* plug-ins/wmf/wmf.cpp : use Pango for loading the font but not for 
	rendering (taking the better part of my patch to fix bug #350726)
	* plug-ins/makefile.msc : link wmf with pangowin32.lib, clean-up

	* app/find-and-replace.c : reset last found if we start a new search

	* app/render_gdk.c(draw_pixel_rect, draw_pixel_line) : clip early to
	avoid passing out-of-range parameters to Gdk



Added:
   trunk/samples/Self/PyDiaObjects.dia   (contents, props changed)
Modified:
   trunk/ChangeLog
   trunk/app/find-and-replace.c
   trunk/app/load_save.c
   trunk/app/render_gdk.c
   trunk/objects/UML/association.c
   trunk/plug-ins/makefile.msc
   trunk/plug-ins/wmf/wmf.cpp
   trunk/plug-ins/xslt/xslt.c
   trunk/samples/Self/dia-renderer.dia

Modified: trunk/app/find-and-replace.c
==============================================================================
--- trunk/app/find-and-replace.c	(original)
+++ trunk/app/find-and-replace.c	Sat May  3 14:43:25 2008
@@ -37,14 +37,14 @@
   RESPONSE_REPLACE = -21,
   RESPONSE_REPLACE_ALL = -23
 };
-
-enum {
-  MATCH_CASE = (1<<0),
-  MATCH_WORD = (1<<1)
-};
+
+enum {
+  MATCH_CASE = (1<<0),
+  MATCH_WORD = (1<<1)
+};
 
 typedef struct _SearchData {
-  const gchar *key;
+  const gchar *key;
   guint      flags;
   Diagram *diagram;
   DiaObject *first; /* the first one found */
@@ -52,29 +52,29 @@
   DiaObject  *last; /* previously found */
   gboolean seen_last;
 } SearchData;
-
-static gboolean
-_matches (DiaObject *obj, const SearchData *sd)
-{
-  gchar* name = object_get_displayname (obj);
-  gboolean ret = FALSE;
-
-  if (sd->flags & MATCH_CASE)
-    ret = strstr (name, sd->key) != NULL;
-  else {
-    gchar *s1 = g_utf8_casefold (name, -1);
-    gchar *s2 = g_utf8_casefold (sd->key, -1);
-    ret = strstr (s1, s2) != NULL;
-    g_free (s1);
-    g_free (s2);
-  }
-
-  if (sd->flags & MATCH_WORD)
-    ret = (ret && strlen(name) == strlen(sd->key));
-
-  g_free (name);
-  return ret;
-}
+
+static gboolean
+_matches (DiaObject *obj, const SearchData *sd)
+{
+  gchar* name = object_get_displayname (obj);
+  gboolean ret = FALSE;
+
+  if (sd->flags & MATCH_CASE)
+    ret = strstr (name, sd->key) != NULL;
+  else {
+    gchar *s1 = g_utf8_casefold (name, -1);
+    gchar *s2 = g_utf8_casefold (sd->key, -1);
+    ret = strstr (s1, s2) != NULL;
+    g_free (s1);
+    g_free (s2);
+  }
+
+  if (sd->flags & MATCH_WORD)
+    ret = (ret && strlen(name) == strlen(sd->key));
+
+  g_free (name);
+  return ret;
+}
 
 static void
 find_func (DiaObject *obj, gpointer user_data)
@@ -102,17 +102,19 @@
   DDisplay *ddisp = (DDisplay*)data;
   GList *list;
   SearchData sd = { 0, };
-  sd.diagram = ddisp->diagram;
-  sd.flags =  gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON ( 
-                  g_object_get_data (G_OBJECT (widget), "match-case"))) ? MATCH_CASE : 0;
-  sd.flags |= gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON ( 
-                  g_object_get_data (G_OBJECT (widget), "match-word"))) ? MATCH_WORD : 0;
+  sd.diagram = ddisp->diagram;
+  sd.flags =  gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON ( 
+                  g_object_get_data (G_OBJECT (widget), "match-case"))) ? MATCH_CASE : 0;
+  sd.flags |= gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON ( 
+                  g_object_get_data (G_OBJECT (widget), "match-word"))) ? MATCH_WORD : 0;
   
 
   switch (response_id) {
   case RESPONSE_FIND :
     sd.key = search;
-    sd.last = g_object_get_data (G_OBJECT (widget), "last-found");
+    sd.last = g_object_get_data (G_OBJECT (widget), "last-found");
+    if (!_matches (sd.last, &sd))
+      sd.last = NULL; /* reset if we start a new search */
     diagram_remove_all_selected (ddisp->diagram, TRUE);
     data_foreach_object (ddisp->diagram->data, find_func, &sd);
     /* remember it */
@@ -190,11 +192,11 @@
 
   match_case = gtk_check_button_new_with_mnemonic (_("_Match case"));
   gtk_box_pack_start (GTK_BOX (vbox), match_case, FALSE, FALSE, 6);
-  g_object_set_data (G_OBJECT (dialog), "match-case", match_case);
+  g_object_set_data (G_OBJECT (dialog), "match-case", match_case);
 
   match_word = gtk_check_button_new_with_mnemonic (_("Match _entire word only"));
   gtk_box_pack_start (GTK_BOX (vbox), match_word, FALSE, FALSE, 6);
-  g_object_set_data (G_OBJECT (dialog), "match-word", match_word);
+  g_object_set_data (G_OBJECT (dialog), "match-word", match_word);
 
   gtk_widget_show_all (vbox);
 }

Modified: trunk/app/load_save.c
==============================================================================
--- trunk/app/load_save.c	(original)
+++ trunk/app/load_save.c	Sat May  3 14:43:25 2008
@@ -276,6 +276,9 @@
       read_connections(group_objects(obj), obj_node, objects_hash);
     } else {
       gboolean broken = FALSE;
+      /* an invalid bounding box is a good sign for some need of corrections */
+      gboolean wants_update = obj->bounding_box.left >= obj->bounding_box.left 
+                           || obj->bounding_box.top >= obj->bounding_box.bottom;
       connections = obj_node->xmlChildrenNode;
       while ((connections!=NULL) &&
 	     (xmlStrcmp(connections->name, (const xmlChar *)"connections")!=0))
@@ -323,12 +326,14 @@
 	      object_connect(obj, obj->handles[handle],
 			     to->connections[conn]);
 	      /* force an update on the connection, helpful with (incomplete) generated files */
-	      obj->handles[handle]->pos = 
-	        to->connections[conn]->last_pos = to->connections[conn]->pos;
+	      if (wants_update) {
+	        obj->handles[handle]->pos = 
+	          to->connections[conn]->last_pos = to->connections[conn]->pos;
 #if 0
-	      obj->ops->move_handle(obj, obj->handles[handle], &to->connections[conn]->pos,
-				    to->connections[conn], HANDLE_MOVE_CONNECTED,0);
+	        obj->ops->move_handle(obj, obj->handles[handle], &to->connections[conn]->pos,
+				      to->connections[conn], HANDLE_MOVE_CONNECTED,0);
 #endif
+	      }
 	    } else {
 	      message_error(_("Error loading diagram.\n"
 			      "connection point %s does not exist."),
@@ -347,7 +352,7 @@
          * Only done for the last point connected otherwise the intermediate posisitions
          * may screw the auto-routing algorithm.
          */
-        if (!broken && obj && obj->ops->set_props) {
+        if (!broken && obj && obj->ops->set_props && wants_update) {
 	  /* called for it's side-effect of update_data */
 	  obj->ops->move(obj,&obj->position);
 

Modified: trunk/app/render_gdk.c
==============================================================================
--- trunk/app/render_gdk.c	(original)
+++ trunk/app/render_gdk.c	Sat May  3 14:43:25 2008
@@ -178,8 +178,17 @@
   DiaGdkRenderer *renderer = DIA_GDK_RENDERER (object);
   GdkGC *gc = renderer->gc;
   GdkColor gdkcolor;
-
+  int target_width, target_height;
+    
   dia_gdk_renderer_set_dashes(renderer, x1+y1);
+
+  gdk_drawable_get_size (GDK_DRAWABLE (renderer->pixmap), &target_width, &target_height);
+
+  if (   (x1 < 0 && x2 < 0)
+      || (y1 < 0 && y2 < 0)
+      || (x1 > target_width && x2 > target_width) 
+      || (y1 > target_height && y2 > target_height))
+    return; /* clip early rather than failing in Gdk */
   
   color_convert(color, &gdkcolor);
   gdk_gc_set_foreground(gc, &gdkcolor);
@@ -196,9 +205,15 @@
   DiaGdkRenderer *renderer = DIA_GDK_RENDERER (object);
   GdkGC *gc = renderer->gc;
   GdkColor gdkcolor;
+  int target_width, target_height;
     
   dia_gdk_renderer_set_dashes(renderer, x+y);
 
+  gdk_drawable_get_size (GDK_DRAWABLE (renderer->pixmap), &target_width, &target_height);
+
+  if (x + width < 0 || y + height < 0 || x > target_width || y > target_height)
+    return; /* clip early rather than failing in Gdk */
+
   color_convert(color, &gdkcolor);
   gdk_gc_set_foreground(gc, &gdkcolor);
 
@@ -215,7 +230,13 @@
   DiaGdkRenderer *renderer = DIA_GDK_RENDERER (object);
   GdkGC *gc = renderer->gc;
   GdkColor gdkcolor;
+  int target_width, target_height;
     
+  gdk_drawable_get_size (GDK_DRAWABLE (renderer->pixmap), &target_width, &target_height);
+    
+  if (x + width < 0 || y + height < 0 || x > target_width || y > target_height)
+    return; /* clip early rather than failing in Gdk */
+
   color_convert(color, &gdkcolor);
   gdk_gc_set_foreground(gc, &gdkcolor);
 

Modified: trunk/objects/UML/association.c
==============================================================================
--- trunk/objects/UML/association.c	(original)
+++ trunk/objects/UML/association.c	Sat May  3 14:43:25 2008
@@ -972,6 +972,11 @@
     orth->autorouting = FALSE;
 
   if (version < 2) {
+    /* vesrion 1 used to name it differently */
+    attr = object_find_attribute(obj_node, "autorouting");
+    if (attr != NULL)
+      orth->autorouting = data_boolean(attribute_first_data(attr));
+
     attr = object_find_attribute(obj_node, "ends");
     composite = attribute_first_data(attr);
     for (i=0;i<2;i++) {

Modified: trunk/plug-ins/makefile.msc
==============================================================================
--- trunk/plug-ins/makefile.msc	(original)
+++ trunk/plug-ins/makefile.msc	Sat May  3 14:43:25 2008
@@ -113,6 +113,7 @@
 !ENDIF
 
 !IFDEF OBJ_wmf
+PKG_LINK = $(PKG_LINK) $(PANGOWIN32_LIBS)
 OBJECTS = \
   wmf.obj \
   wmf_gdi.obj
@@ -133,19 +134,6 @@
 	xsltdialog.obj
 !ENDIF
 
-!IFDEF OBJ_sissi
-EXTRACFLAGS = -DWIN32 $(LIBXSLT_CFLAGS)
-EXTRALIBS = $(LIBXSLT_LIBS)
-OBJECTS = sissi.obj \
-	faraday.obj \
-	menace.obj \
-	room.obj \
-	sissi_dialog.obj \
-	sissi_object.obj \
-	site.obj \
-	zone.obj
-!ENDIF
-
 # just one file ...
 !IFNDEF OBJECTS
 OBJECTS = $(PACKAGE).obj

Modified: trunk/plug-ins/wmf/wmf.cpp
==============================================================================
--- trunk/plug-ins/wmf/wmf.cpp	(original)
+++ trunk/plug-ins/wmf/wmf.cpp	Sat May  3 14:43:25 2008
@@ -48,6 +48,15 @@
 #  define WIN32_LEAN_AND_MEAN
 #  include <windows.h>
   }
+#undef STRICT
+typedef W32::HDC HDC;
+typedef W32::HFONT HFONT;
+typedef W32::LOGFONT LOGFONT;
+typedef W32::LOGFONTA LOGFONTA;
+typedef W32::LOGFONTW LOGFONTW;
+
+#include <pango/pangowin32.h>
+
 #elif HAVE_LIBEMF
   namespace W32 {
 #  include <emf.h>
@@ -113,6 +122,9 @@
     gboolean platform_is_nt; /* advanced line styles supported */
     gboolean target_emf; /* write enhanced metafile */
     W32::RECT margins;
+
+    gboolean use_pango;
+    PangoContext* pango_context;
 };
 
 struct _WmfRendererClass
@@ -308,6 +320,8 @@
 	W32::DeleteEnhMetaFile(hEmf);
     if (renderer->hFont)
 	W32::DeleteObject(renderer->hFont);
+    if (renderer->pango_context)
+        g_object_unref (renderer->pango_context);
 }
 
 static void
@@ -457,44 +471,66 @@
 
     DIAG_NOTE(renderer, "set_font %s %f\n", 
               dia_font_get_family (font), height);
-    if (renderer->hFont)
+    if (renderer->hFont) {
 	W32::DeleteObject(renderer->hFont);
-
-    sFace = dia_font_get_family (font);
-    style = dia_font_get_style(font);
-    dwItalic = DIA_FONT_STYLE_GET_SLANT(style) != DIA_FONT_NORMAL;
-
-    /* although there is a known algorithm avoid it for cleanness */
-    switch (DIA_FONT_STYLE_GET_WEIGHT(style)) {
-    case DIA_FONT_ULTRALIGHT    : dwWeight = FW_ULTRALIGHT; break;
-    case DIA_FONT_LIGHT         : dwWeight = FW_LIGHT; break;
-    case DIA_FONT_MEDIUM        : dwWeight = FW_MEDIUM; break;
-    case DIA_FONT_DEMIBOLD      : dwWeight = FW_DEMIBOLD; break;
-    case DIA_FONT_BOLD          : dwWeight = FW_BOLD; break;
-    case DIA_FONT_ULTRABOLD     : dwWeight = FW_ULTRABOLD; break;
-    case DIA_FONT_HEAVY         : dwWeight = FW_HEAVY; break;
-    default : dwWeight = FW_NORMAL; break;
-    }
-    //Hack to get BYTE out of namespace W32
-#  ifndef BYTE
-#  define BYTE unsigned char
-#  endif
-
-    renderer->hFont = (W32::HFONT)W32::CreateFont( 
-	- SC (height),  // logical height of font 
-	0,		// logical average character width 
-	0,		// angle of escapement
-	0,		// base-line orientation angle 
-	dwWeight,	// font weight
-	dwItalic,	// italic attribute flag
-	0,		// underline attribute flag
-	0,		// strikeout attribute flag
-	DEFAULT_CHARSET,	// character set identifier 
-	OUT_TT_PRECIS, 	// output precision 
-	CLIP_DEFAULT_PRECIS,	// clipping precision
-	PROOF_QUALITY,		// output quality 
-	DEFAULT_PITCH,		// pitch and family
-	sFace);		// pointer to typeface name string 
+	renderer->hFont = NULL;
+    }
+    if (renderer->pango_context) {
+        g_object_unref (renderer->pango_context);
+	renderer->pango_context = NULL;
+    }
+    
+    if (renderer->use_pango) {
+#ifdef __PANGOWIN32_H__ /* with the pangowin32 backend there is a better way */
+	if (!renderer->pango_context)
+	    renderer->pango_context = pango_win32_get_context ();
+	PangoFont* pf = pango_context_load_font (renderer->pango_context, dia_font_get_description (font));
+	W32::LOGFONT* lf = pango_win32_font_logfont (pf);
+	/* .93 : sligthly smaller looks much better */
+	lf->lfHeight = -SC(height*.93);
+	renderer->hFont = (W32::HFONT)W32::CreateFontIndirect (lf);
+	g_free (lf);
+	g_object_unref (pf);
+#else
+	g_assert_not_reached();
+#endif
+    } else {
+	sFace = dia_font_get_family (font);
+	style = dia_font_get_style(font);
+	dwItalic = DIA_FONT_STYLE_GET_SLANT(style) != DIA_FONT_NORMAL;
+
+	/* although there is a known algorithm avoid it for cleanness */
+	switch (DIA_FONT_STYLE_GET_WEIGHT(style)) {
+	case DIA_FONT_ULTRALIGHT    : dwWeight = FW_ULTRALIGHT; break;
+	case DIA_FONT_LIGHT         : dwWeight = FW_LIGHT; break;
+	case DIA_FONT_MEDIUM        : dwWeight = FW_MEDIUM; break;
+	case DIA_FONT_DEMIBOLD      : dwWeight = FW_DEMIBOLD; break;
+	case DIA_FONT_BOLD          : dwWeight = FW_BOLD; break;
+	case DIA_FONT_ULTRABOLD     : dwWeight = FW_ULTRABOLD; break;
+	case DIA_FONT_HEAVY         : dwWeight = FW_HEAVY; break;
+	default : dwWeight = FW_NORMAL; break;
+	}
+	//Hack to get BYTE out of namespace W32
+#       ifndef BYTE
+#       define BYTE unsigned char
+#       endif
+
+	renderer->hFont = (W32::HFONT)W32::CreateFont( 
+		- SC (height),  // logical height of font 
+		0,		// logical average character width 
+		0,		// angle of escapement
+		0,		// base-line orientation angle 
+		dwWeight,	// font weight
+		dwItalic,	// italic attribute flag
+		0,		// underline attribute flag
+		0,		// strikeout attribute flag
+		DEFAULT_CHARSET,	// character set identifier 
+		OUT_TT_PRECIS, 	// output precision 
+		CLIP_DEFAULT_PRECIS,	// clipping precision
+		PROOF_QUALITY,		// output quality 
+		DEFAULT_PITCH,		// pitch and family
+		sFace);		// pointer to typeface name string
+    }
 }
 
 static void
@@ -1223,8 +1259,14 @@
     if (user_data == (void*)1) {
 	renderer->target_emf = TRUE;
 	renderer->hPrintDC = 0;
+#ifdef __PANGOWIN32_H__ 
+        renderer->use_pango = TRUE;
+#else
+        renderer->use_pango = FALSE;
+#endif
     } else {
         renderer->hPrintDC = (W32::HDC)user_data;
+        renderer->use_pango = (user_data != NULL); // always for printing
     }
 
     DIAG_NOTE(renderer, "Saving %s:%s\n", renderer->target_emf ? "EMF" : "WMF", filename);
@@ -1324,7 +1366,6 @@
     "emf"
 };
 
-
 /* --- dia plug-in interface --- */
 
 DIA_PLUGIN_CHECK_INIT

Modified: trunk/plug-ins/xslt/xslt.c
==============================================================================
--- trunk/plug-ins/xslt/xslt.c	(original)
+++ trunk/plug-ins/xslt/xslt.c	Sat May  3 14:43:25 2008
@@ -79,9 +79,12 @@
 	char *params[] = { "directory", NULL, NULL };
 	xsltStylesheetPtr style, codestyle;
 	xmlDocPtr doc, res;
+	gchar *uri = g_filename_to_uri (g_dirname(filename), NULL, NULL);
+
+	/* strange: requires an uri, but the last char is platform specifc?! */
+	params[1] = g_strconcat("'", uri, G_DIR_SEPARATOR_S, "'", NULL);
+	g_free (uri);
 
-	params[1] = g_strconcat("'", g_dirname(filename), G_DIR_SEPARATOR_S, "'", NULL);
-	
 	file = g_fopen(diafilename, "r");
 
 	if (file == NULL) {
@@ -143,9 +146,16 @@
 
 
 	err = xsltSaveResultToFile(out, doc, codestyle);
-      /* printf("Saved to file (%i) using stylesheet: %s\n",
-         err, stylefname); */
-		
+	if(err != 0) {
+		message_error(_("Error while saving result: %s\n"), 
+			      dia_message_filename(filename));
+		return;
+	}
+
+	fprintf (out, "From:\t%s\n", diafilename);
+	fprintf (out, "With:\t%s\n", stylefname);
+	fprintf (out, "To:\t%s=%s\n", params[0], params[1]);
+
 	fclose(out);
 	fclose(file);
 

Added: trunk/samples/Self/PyDiaObjects.dia
==============================================================================
Binary file. No diff available.

Modified: trunk/samples/Self/dia-renderer.dia
==============================================================================
Binary files. No diff available.



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