Thursday 01 of January 2009 01:28:16 Peter Clifton wrote:
> On Wed, 2008-12-31 at 23:27 +0100, Wojciech Kazubski wrote:
> > Hello!
> > I have two patches for png export code in gschem.
>
> Attachments missing?
Sorry,
they are now.
geda-gschem-1.5.1-png-export-fix-proportions.patch is the bugfix
geda-gschem-1.5.1-png-export-fixed-dpi.patch contains new feature

Wojciech Kazubski
diff -up geda-gschem-1.5.1/src/x_image.c.png-export-dpi geda-gschem-1.5.1/src/x_image.c
--- geda-gschem-1.5.1/src/x_image.c.png-export-dpi	2008-12-31 22:26:05.000000000 +0100
+++ geda-gschem-1.5.1/src/x_image.c	2008-12-31 22:08:46.000000000 +0100
@@ -44,7 +44,7 @@
 #define X_IMAGE_DEFAULT_TYPE "PNG"
 
 static char *x_image_sizes[] = {"320x240", "640x480", "800x600", "1200x768",
-  "1280x960", "1600x1200", "3200x2400", NULL};
+  "1280x960", "1600x1200", "3200x2400", "100dpi", "200dpi", "300dpi", NULL};
 
 #if ((GTK_MAJOR_VERSION == 2) && (GTK_MINOR_VERSION < 6))
 /* gtk_combo_box_get_active_text was included in GTK 2.6, so we need to store
@@ -327,15 +327,6 @@ void x_image_lowlevel(GSCHEM_TOPLEVEL *w
   GtkWidget *dialog;
   float prop, page_prop;
 
-  w_current->image_width = width = desired_width;
-  w_current->image_height = height = desired_height;
-
-  save_width = toplevel->width;
-  save_height = toplevel->height;
-
-  toplevel->width = width;
-  toplevel->height = height;
-
   save_page_left = toplevel->page_current->left;
   save_page_right = toplevel->page_current->right;
   save_page_top = toplevel->page_current->top;
@@ -347,6 +338,20 @@ void x_image_lowlevel(GSCHEM_TOPLEVEL *w
   page_center_left = save_page_left + (page_width / 2);
   page_center_top = save_page_top + (page_height / 2);
 
+  if (desired_width == 0) {
+    desired_width = page_width * desired_height / 1000;
+    desired_height = page_height * desired_height / 1000;
+  }
+
+  w_current->image_width = width = desired_width;
+  w_current->image_height = height = desired_height;
+
+  save_width = toplevel->width;
+  save_height = toplevel->height;
+
+  toplevel->width = width;
+  toplevel->height = height;
+
   /* Preserve proportions */
   prop = (float)width / height;
   page_prop = (float)page_width / page_height;
@@ -556,7 +561,12 @@ void x_image_setup (GSCHEM_TOPLEVEL *w_c
 #endif
 
     image_type = x_image_get_type_from_description(image_type_descr);
-    sscanf(image_size, "%ix%i", &width, &height);
+    if (strchr(image_size, 'd') == NULL)
+      sscanf(image_size, "%ix%i", &width, &height);
+    else {
+      width = 0;
+      sscanf(image_size, "%idpi", &height);
+    }
     filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
 
     x_image_lowlevel(w_current, filename, width, height, image_type);
diff -up geda-gschem-1.5.1/src/x_image.c.prop geda-gschem-1.5.1/src/x_image.c
--- geda-gschem-1.5.1/src/x_image.c.prop	2008-12-31 18:58:53.000000000 +0100
+++ geda-gschem-1.5.1/src/x_image.c	2008-12-31 21:41:20.000000000 +0100
@@ -325,7 +325,7 @@ void x_image_lowlevel(GSCHEM_TOPLEVEL *w
   GdkPixbuf *pixbuf;
   GError *gerror = NULL;
   GtkWidget *dialog;
-  float prop;
+  float prop, page_prop;
 
   w_current->image_width = width = desired_width;
   w_current->image_height = height = desired_height;
@@ -349,7 +349,8 @@ void x_image_lowlevel(GSCHEM_TOPLEVEL *w
 
   /* Preserve proportions */
   prop = (float)width / height;
-  if(page_width > page_height) {
+  page_prop = (float)page_width / page_height;
+  if (page_prop > prop) {
     page_height = (page_width / prop);
   }else{
     page_width = (page_height * prop);

_______________________________________________
geda-dev mailing list
[email protected]
http://www.seul.org/cgi-bin/mailman/listinfo/geda-dev

Reply via email to