]> www.fi.muni.cz Git - evince.git/commitdiff
Use gtk+ builtin paper list to identify the document's paper size. Fixes
authorCarlos Garcia Campos <carlosgc@gnome.org>
Tue, 8 May 2007 10:31:45 +0000 (10:31 +0000)
committerCarlos Garcia Campos <carlosgc@src.gnome.org>
Tue, 8 May 2007 10:31:45 +0000 (10:31 +0000)
2007-05-08  Carlos Garcia Campos  <carlosgc@gnome.org>
* configure.ac:
* properties/ev-properties-view.c: (ev_regular_paper_size):
Use gtk+ builtin paper list to identify the document's paper size.
Fixes bug #382438.

svn path=/trunk/; revision=2438

ChangeLog
configure.ac
properties/ev-properties-view.c

index fc08568fb63cb597c2940a3c2ab81d060f111416..9171b20234715115f98c23091944190cabb49f3a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2007-05-08  Carlos Garcia Campos  <carlosgc@gnome.org>
+
+       * configure.ac:
+       * properties/ev-properties-view.c: (ev_regular_paper_size):
+
+       Use gtk+ builtin paper list to identify the document's paper size.
+       Fixes bug #382438. 
+
 2007-05-04  Carlos Garcia Campos  <carlosgc@gnome.org>
 
        * configure.ac:
index f6b37be2bf168028ac386a9a0a85f043fe7fe4f5..3af99394841018858489ee3d17e3f03a2c9be329 100644 (file)
@@ -443,6 +443,11 @@ if test "x$enable_impress" = "xyes"; then
 fi
 AC_SUBST(EVINCE_MIME_TYPES)
 
+evince_save_LIBS=$LIBS
+LIBS="$LIBS $FRONTEND_LIBS"
+AC_CHECK_FUNCS(gtk_paper_size_get_paper_sizes)
+LIBS=$evince_save_LIBS
+
 AC_CONFIG_FILES([
 backend/Makefile
 backend/comics/Makefile
index 2c2d8f0d37e4b5e32321c2b59ae8fcd9283f3e1c..0df238aaba8ee201e8adc4a7cfd95f4f732b1635 100644 (file)
@@ -193,6 +193,110 @@ set_property (GladeXML *xml, Property property, const char *text)
        g_free (valid_text);
 }
 
+#if HAVE_GTK_PAPER_SIZE_GET_PAPER_SIZES
+static GtkUnit
+get_default_user_units (void)
+{
+       /* Translate to the default units to use for presenting
+        * lengths to the user. Translate to default:inch if you
+        * want inches, otherwise translate to default:mm.
+        * Do *not* translate it to "predefinito:mm", if it
+        * it isn't default:mm or default:inch it will not work
+        */
+       gchar *e = _("default:mm");
+
+#ifdef HAVE__NL_MEASUREMENT_MEASUREMENT
+       gchar *imperial = NULL;
+       
+       imperial = nl_langinfo (_NL_MEASUREMENT_MEASUREMENT);
+       if (imperial && imperial[0] == 2)
+               return GTK_UNIT_INCH;  /* imperial */
+       if (imperial && imperial[0] == 1)
+               return GTK_UNIT_MM;  /* metric */
+#endif
+
+       if (strcmp (e, "default:inch") == 0)
+               return GTK_UNIT_INCH;
+       else if (strcmp (e, "default:mm") == 0)
+               g_warning ("Whoever translated default:mm did so wrongly.\n");
+                               
+       return GTK_UNIT_MM;
+}
+
+static gdouble
+get_tolerance (gdouble size)
+{
+       if (size < 150.0f)
+               return 1.5f;
+       else if (size >= 150.0f && size <= 600.0f)
+               return 2.0f;
+       else
+               return 3.0f;
+}
+
+static char *
+ev_regular_paper_size (const EvDocumentInfo *info)
+{
+       GList *paper_sizes, *l;
+       gchar *exact_size;
+       gchar *str = NULL;
+       GtkUnit units;
+
+       units = get_default_user_units ();
+
+       if (units == GTK_UNIT_MM) {
+               exact_size = g_strdup_printf(_("%.0f x %.0f mm"),
+                                            info->paper_width,
+                                            info->paper_height);
+       } else {
+               exact_size = g_strdup_printf (_("%.2f x %.2f inch"),
+                                             info->paper_width  / 25.4f,
+                                             info->paper_height / 25.4f);
+       }
+
+       paper_sizes = gtk_paper_size_get_paper_sizes (FALSE);
+       
+       for (l = paper_sizes; l && l->data; l = g_list_next (l)) {
+               GtkPaperSize *size = (GtkPaperSize *) l->data;
+               gdouble paper_width;
+               gdouble paper_height;
+               gdouble width_tolerance;
+               gdouble height_tolerance;
+
+               paper_width = gtk_paper_size_get_width (size, GTK_UNIT_MM);
+               paper_height = gtk_paper_size_get_height (size, GTK_UNIT_MM);
+
+               width_tolerance = get_tolerance (paper_width);
+               height_tolerance = get_tolerance (paper_height);
+
+               if (ABS (info->paper_height - paper_height) <= height_tolerance &&
+                   ABS (info->paper_width  - paper_width) <= width_tolerance) {
+                       /* Note to translators: first placeholder is the paper name (eg.
+                        * A4), second placeholder is the paper size (eg. 297x210 mm) */
+                       str = g_strdup_printf (_("%s, Portrait (%s)"),
+                                              gtk_paper_size_get_display_name (size),
+                                              exact_size);
+               } else if (ABS (info->paper_width  - paper_height) <= height_tolerance &&
+                          ABS (info->paper_height - paper_width) <= width_tolerance) {
+                       /* Note to translators: first placeholder is the paper name (eg.
+                        * A4), second placeholder is the paper size (eg. 297x210 mm) */
+                       str = g_strdup_printf ( _("%s, Landscape (%s)"),
+                                               gtk_paper_size_get_display_name (size),
+                                               exact_size);
+               }
+       }
+
+       g_list_foreach (paper_sizes, (GFunc) gtk_paper_size_free, NULL);
+       g_list_free (paper_sizes);
+
+       if (str != NULL) {
+               g_free (exact_size);
+               return str;
+       }
+       
+       return exact_size;
+}
+#else
 /*
  * All values are in mm. 
  * Source: http://en.wikipedia.org/wiki/Paper_size
@@ -326,6 +430,7 @@ ev_regular_paper_size (const EvDocumentInfo *info)
        } else
                return exact_size;
 }
+#endif /* HAVE_GTK_PAPER_SIZE_GET_PAPER_SIZES */
 
 void
 ev_properties_view_set_info (EvPropertiesView *properties, const EvDocumentInfo *info)