]> www.fi.muni.cz Git - evince.git/commitdiff
Adds a paper size field to the properties dialog. Fixes bug #307315. Patch
authorWouter Bolsterlee <wbolster@cvs.gnome.org>
Mon, 4 Dec 2006 11:53:25 +0000 (11:53 +0000)
committerWouter Bolsterlee <wbolster@src.gnome.org>
Mon, 4 Dec 2006 11:53:25 +0000 (11:53 +0000)
2006-12-04  Wouter Bolsterlee  <wbolster@cvs.gnome.org>

* backend/ev-document-info.h:
* data/evince-properties.glade:
* pdf/ev-poppler.cc:
* properties/ev-properties-view.c: (ev_regular_paper_size),
(ev_properties_view_set_info):
* ps/ps-document.c: (ps_document_get_info):

Adds a paper size field to the properties dialog. Fixes
bug #307315. Patch by Kasper Svendsen (with some i18n
changes done by me).

ChangeLog
backend/ev-document-info.h
data/evince-properties.glade
pdf/ev-poppler.cc
properties/ev-properties-view.c
ps/ps-document.c

index f2ac63069df02d96a2143064655e9d1c6043dbdb..83abb4b1ac7df7e41c03d2a246391c092acbe78f 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2006-12-04  Wouter Bolsterlee  <wbolster@cvs.gnome.org>
+
+       * backend/ev-document-info.h:
+       * data/evince-properties.glade:
+       * pdf/ev-poppler.cc:
+       * properties/ev-properties-view.c: (ev_regular_paper_size),
+       (ev_properties_view_set_info):
+       * ps/ps-document.c: (ps_document_get_info):
+
+       Adds a paper size field to the properties dialog. Fixes
+       bug #307315. Patch by Kasper Svendsen (with some i18n
+       changes done by me).
+
 2006-12-03  Nickolay V. Shmyrev  <nshmyrev@yandex.ru>
 
        * cut-n-paste/totem-screensaver/totem-scrsaver.c:
index 3930910fee42ce3ee106ae14bd7691de83b378e6..0cd1ef850b244e767f32bb779d1d08c510a1375c 100644 (file)
@@ -90,7 +90,8 @@ typedef enum
        EV_DOCUMENT_INFO_UI_HINTS = 1 << 12,
        EV_DOCUMENT_INFO_PERMISSIONS = 1 << 13,
        EV_DOCUMENT_INFO_N_PAGES = 1 << 14,
-       EV_DOCUMENT_INFO_SECURITY = 1 << 15
+       EV_DOCUMENT_INFO_SECURITY = 1 << 15,
+       EV_DOCUMENT_INFO_PAPER_SIZE = 1 << 16
 } EvDocumentInfoFields;
 
 struct _EvDocumentInfo
@@ -111,6 +112,8 @@ struct _EvDocumentInfo
        guint ui_hints;
        guint permissions;
        int   n_pages;
+       double paper_height;
+       double paper_width;
 
        /* Mask of all the valid fields */
        guint fields_mask;
index c33c55148b24dc9020935e1cf8859d841ca5bf99..3845d257704d89741d1236d877dd0aca1efa1f2b 100644 (file)
   <property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
   <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
   <property name="focus_on_map">True</property>
+  <property name="urgency_hint">False</property>
 
   <child>
     <widget class="GtkTable" id="general_page_root">
       <property name="border_width">12</property>
       <property name="visible">True</property>
-      <property name="n_rows">12</property>
+      <property name="n_rows">13</property>
       <property name="n_columns">2</property>
       <property name="homogeneous">False</property>
       <property name="row_spacing">6</property>
          <property name="y_options"></property>
        </packing>
       </child>
+
+      <child>
+       <widget class="GtkLabel" id="paper_size_caption">
+         <property name="visible">True</property>
+         <property name="label" translatable="yes">&lt;b&gt;Paper Size:&lt;/b&gt;</property>
+         <property name="use_underline">False</property>
+         <property name="use_markup">True</property>
+         <property name="justify">GTK_JUSTIFY_LEFT</property>
+         <property name="wrap">False</property>
+         <property name="selectable">False</property>
+         <property name="xalign">0</property>
+         <property name="yalign">0.5</property>
+         <property name="xpad">0</property>
+         <property name="ypad">0</property>
+         <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
+         <property name="width_chars">-1</property>
+         <property name="single_line_mode">False</property>
+         <property name="angle">0</property>
+       </widget>
+       <packing>
+         <property name="left_attach">0</property>
+         <property name="right_attach">1</property>
+         <property name="top_attach">12</property>
+         <property name="bottom_attach">13</property>
+         <property name="x_options">fill</property>
+         <property name="y_options"></property>
+       </packing>
+      </child>
+
+      <child>
+       <widget class="GtkLabel" id="papersize">
+         <property name="visible">True</property>
+         <property name="can_focus">True</property>
+         <property name="label" translatable="yes"></property>
+         <property name="use_underline">False</property>
+         <property name="use_markup">True</property>
+         <property name="justify">GTK_JUSTIFY_LEFT</property>
+         <property name="wrap">False</property>
+         <property name="selectable">True</property>
+         <property name="xalign">0</property>
+         <property name="yalign">0.5</property>
+         <property name="xpad">0</property>
+         <property name="ypad">0</property>
+         <property name="ellipsize">PANGO_ELLIPSIZE_END</property>
+         <property name="width_chars">25</property>
+         <property name="single_line_mode">False</property>
+         <property name="angle">0</property>
+       </widget>
+       <packing>
+         <property name="left_attach">1</property>
+         <property name="right_attach">2</property>
+         <property name="top_attach">12</property>
+         <property name="bottom_attach">13</property>
+         <property name="x_options">fill</property>
+         <property name="y_options"></property>
+       </packing>
+      </child>
     </widget>
   </child>
 </widget>
   <property name="type_hint">GDK_WINDOW_TYPE_HINT_NORMAL</property>
   <property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
   <property name="focus_on_map">True</property>
+  <property name="urgency_hint">False</property>
 
   <child>
     <widget class="GtkVBox" id="fonts_page_root">
index a90c52413a1c769d0c516460fe8e4d6e6abc8c08..148c6c56030aafe515429e73c5125720d41b5a74 100644 (file)
@@ -503,8 +503,8 @@ pdf_document_get_info (EvDocument *document)
                            EV_DOCUMENT_INFO_MOD_DATE |
                            EV_DOCUMENT_INFO_LINEARIZED |
                            EV_DOCUMENT_INFO_N_PAGES |
-                           EV_DOCUMENT_INFO_SECURITY;
-
+                           EV_DOCUMENT_INFO_SECURITY | 
+                           EV_DOCUMENT_INFO_PAPER_SIZE;
 
        g_object_get (PDF_DOCUMENT (document)->document,
                      "title", &(info->title),
@@ -523,6 +523,14 @@ pdf_document_get_info (EvDocument *document)
                      "linearized", &(info->linearized),
                      NULL);
 
+       pdf_document_get_page_size(document, 0,
+                                  &(info->paper_width),
+                                  &(info->paper_height));
+
+       // Convert to mm.
+       info->paper_width = info->paper_width / 72.0f * 25.4f;
+       info->paper_height = info->paper_height / 72.0f * 25.4f;
+
        switch (layout) {
                case POPPLER_PAGE_LAYOUT_SINGLE_PAGE:
                        info->layout = EV_DOCUMENT_LAYOUT_SINGLE_PAGE;
index fdf5cf7397b5dd6eb360fa929de91ba933af516b..98aecb564dc689b1fe424300d64b6bf2dba34500 100644 (file)
@@ -31,6 +31,7 @@
 #include <time.h>
 #include <sys/time.h>
 #include <string.h>
+#include <langinfo.h>
 
 typedef enum
 {
@@ -45,7 +46,8 @@ typedef enum
        N_PAGES_PROPERTY,
        LINEARIZED_PROPERTY,
        FORMAT_PROPERTY,
-       SECURITY_PROPERTY
+       SECURITY_PROPERTY,
+       PAPER_SIZE_PROPERTY
 } Property;
 
 typedef struct
@@ -66,7 +68,8 @@ static const PropertyInfo properties_info[] = {
        { N_PAGES_PROPERTY, "pages" },
        { LINEARIZED_PROPERTY, "optimized" },
        { FORMAT_PROPERTY, "version" },
-       { SECURITY_PROPERTY, "security" }
+       { SECURITY_PROPERTY, "security" },
+       { PAPER_SIZE_PROPERTY, "papersize" }
 };
 
 struct _EvPropertiesView {
@@ -185,6 +188,106 @@ set_property (GladeXML *xml, Property property, const char *text)
        g_free (valid_text);
 }
 
+/*
+ * All values are in mm. 
+ * Source: http://en.wikipedia.org/wiki/Paper_size
+ */
+struct regular_paper_size {
+       double width;
+       double height;
+       double width_tolerance;
+       double height_tolerance;
+       const char *description;
+} const regular_paper_sizes[] = {
+       // ISO 216 paper sizes
+       {  841.0f, 1189.0f, 3.0f, 3.0f, "A0"  },
+       {  594.0f,  841.0f, 2.0f, 3.0f, "A1"  },
+       {  420.0f,  594.0f, 2.0f, 2.0f, "A2"  },
+       {  297.0f,  420.0f, 2.0f, 2.0f, "A3"  },
+       {  210.0f,  297.0f, 2.0f, 2.0f, "A4"  },
+       {  148.0f,  210.0f, 1.5f, 2.0f, "A5"  },
+       {  105.0f,  148.0f, 1.5f, 1.5f, "A6"  },
+       {   74.0f,  105.0f, 1.5f, 1.5f, "A7"  },
+       {   52.0f,   74.0f, 1.5f, 1.5f, "A8"  },
+       {   37.0f,   52.0f, 1.5f, 1.5f, "A9"  },
+       {   26.0f,   37.0f, 1.5f, 1.5f, "A10" },
+       { 1000.0f, 1414.0f, 3.0f, 3.0f, "B0"  },
+       {  707.0f, 1000.0f, 3.0f, 3.0f, "B1"  },
+       {  500.0f,  707.0f, 2.0f, 3.0f, "B2"  },
+       {  353.0f,  500.0f, 2.0f, 2.0f, "B3"  },
+       {  250.0f,  353.0f, 2.0f, 2.0f, "B4"  },
+       {  176.0f,  250.0f, 2.0f, 2.0f, "B5"  },
+       {  125.0f,  176.0f, 1.5f, 2.0f, "B6"  },
+       {   88.0f,  125.0f, 1.5f, 1.5f, "B7"  },
+       {   62.0f,   88.0f, 1.5f, 1.5f, "B8"  },
+       {   44.0f,   62.0f, 1.5f, 1.5f, "B9"  },
+       {   31.0f,   44.0f, 1.5f, 1.5f, "B10" },
+       {  917.0f, 1297.0f, 3.0f, 3.0f, "C0"  },
+       {  648.0f,  917.0f, 3.0f, 3.0f, "C1"  },
+       {  458.0f,  648.0f, 2.0f, 3.0f, "C2"  },
+       {  324.0f,  458.0f, 2.0f, 2.0f, "C3"  },
+       {  229.0f,  324.0f, 2.0f, 2.0f, "C4"  },
+       {  162.0f,  229.0f, 2.0f, 2.0f, "C5"  },
+       {  114.0f,  162.0f, 1.5f, 2.0f, "C6"  },
+       {   81.0f,  114.0f, 1.5f, 1.5f, "C7"  },
+       {   57.0f,   81.0f, 1.5f, 1.5f, "C8"  },
+       {   40.0f,   57.0f, 1.5f, 1.5f, "C9"  },
+       {   28.0f,   40.0f, 1.5f, 1.5f, "C10" },
+
+       // US paper sizes
+       {  279.0f,  216.0f, 3.0f, 3.0f, "Letter" },
+       {  356.0f,  216.0f, 3.0f, 3.0f, "Legal"  },
+       {  432.0f,  279.0f, 3.0f, 3.0f, "Ledger" }
+};
+
+static char *
+ev_regular_paper_size (const EvDocumentInfo *info)
+{
+       const struct regular_paper_size *size;   
+       char *exact_size = NULL;
+       char *imperial = NULL;
+       char *str = NULL;
+       int i;
+       
+        imperial = nl_langinfo(_NL_MEASUREMENT_MEASUREMENT);
+        if ( imperial && imperial[0] == 2 )
+               /* Imperial measurement (inches) */
+               exact_size = g_strdup_printf( _("%.2f x %.2f in"),
+                                             info->paper_width  / 25.4f,
+                                             info->paper_height / 25.4f );
+       else
+               /* Metric measurement (millimeters) */
+               exact_size = g_strdup_printf( _("%.0f x %.0f mm"),
+                                             info->paper_width,
+                                             info->paper_height );
+       
+       for (i = G_N_ELEMENTS ( regular_paper_sizes ) - 1; i >= 0; i--) {
+               size = &regular_paper_sizes[i];
+
+               if ( ABS( info->paper_height - size->height ) <= size->height_tolerance &&
+                    ABS( info->paper_width  - size->width  ) <= size->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)"),
+                                               size->description,
+                                               exact_size );
+               } else if ( ABS( info->paper_width  - size->height ) <= size->height_tolerance &&
+                           ABS( info->paper_height - size->width  ) <= size->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)"),
+                                               size->description,
+                                               exact_size );
+               }
+       }
+
+       if (str != NULL) {
+               g_free (exact_size);
+               return str;
+       } else
+               return exact_size;
+}
+
 void
 ev_properties_view_set_info (EvPropertiesView *properties, const EvDocumentInfo *info)
 {
@@ -235,6 +338,11 @@ ev_properties_view_set_info (EvPropertiesView *properties, const EvDocumentInfo
        if (info->fields_mask & EV_DOCUMENT_INFO_SECURITY) {
                set_property (xml, SECURITY_PROPERTY, info->security);
        }
+       if (info->fields_mask & EV_DOCUMENT_INFO_PAPER_SIZE) {
+               text = ev_regular_paper_size (info);
+               set_property (xml, PAPER_SIZE_PROPERTY, text);
+               g_free (text);
+       }
 }
 
 static void
index e9c7ca55ea30c1d5ba4561a8d9f2012ee72cc819..19800109a1834b860e0cc164f6646d365f9b014c 100644 (file)
@@ -1257,17 +1257,25 @@ ps_document_get_info (EvDocument *document)
 {
        EvDocumentInfo *info;
        PSDocument *ps = PS_DOCUMENT (document);
+       int urx, ury, llx, lly;
 
        info = g_new0 (EvDocumentInfo, 1);
        info->fields_mask = EV_DOCUMENT_INFO_TITLE |
                            EV_DOCUMENT_INFO_FORMAT |
                            EV_DOCUMENT_INFO_CREATOR |
-                           EV_DOCUMENT_INFO_N_PAGES;
+                           EV_DOCUMENT_INFO_N_PAGES |
+                           EV_DOCUMENT_INFO_PAPER_SIZE;
+
        info->title = g_strdup (ps->doc->title);
        info->format = ps->doc->epsf ? g_strdup (_("Encapsulated PostScript"))
                                     : g_strdup (_("PostScript"));
        info->creator = g_strdup (ps->doc->creator);
        info->n_pages = ev_document_get_n_pages (document);
+       
+       get_page_box (PS_DOCUMENT (document), 0, &urx, &ury, &llx, &lly);
+
+       info->paper_width  = (urx - llx) / 72.0f * 25.4f;
+       info->paper_height = (ury - lly) / 72.0f * 25.4f;
 
        return info;
 }