summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMarc Jeanmougin <marc@jeanmougin.fr>2018-10-19 15:51:03 +0000
committerMarc Jeanmougin <marc@jeanmougin.fr>2018-10-19 15:51:03 +0000
commit66cf65bc1b35c9d58a6a6af7c144e08ce685edd2 (patch)
treee1f0091806f8337bbd25eaf4edde85c6ea526775 /src
parentAdd some more const to SPFilter. (diff)
downloadinkscape-66cf65bc1b35c9d58a6a6af7c144e08ce685edd2.tar.gz
inkscape-66cf65bc1b35c9d58a6a6af7c144e08ce685edd2.zip
Makes page sizes in document properties customizable
Works similarly as prefs
Diffstat (limited to 'src')
-rw-r--r--src/ui/CMakeLists.txt1
-rw-r--r--src/ui/widget/page-sizer.cpp226
-rw-r--r--src/ui/widget/pages-skeleton.h136
3 files changed, 175 insertions, 188 deletions
diff --git a/src/ui/CMakeLists.txt b/src/ui/CMakeLists.txt
index 458125c59..3411eeaba 100644
--- a/src/ui/CMakeLists.txt
+++ b/src/ui/CMakeLists.txt
@@ -400,6 +400,7 @@ set(ui_SRC
widget/notebook-page.h
widget/object-composite-settings.h
widget/page-sizer.h
+ widget/pages-skeleton.h
widget/panel.h
widget/point.h
widget/preferences-widget.h
diff --git a/src/ui/widget/page-sizer.cpp b/src/ui/widget/page-sizer.cpp
index f1a253efc..9c03367ee 100644
--- a/src/ui/widget/page-sizer.cpp
+++ b/src/ui/widget/page-sizer.cpp
@@ -18,11 +18,14 @@
*/
#include "page-sizer.h"
+#include "pages-skeleton.h"
+#include <glib.h>
#include <glibmm/i18n.h>
#include "verbs.h"
#include "helper/action.h"
#include "object/sp-root.h"
#include "ui/widget/button.h"
+#include "io/resource.h"
using std::pair;
using Inkscape::Util::unit_table;
@@ -31,174 +34,6 @@ namespace Inkscape {
namespace UI {
namespace Widget {
- /** \note
- * The ISO page sizes in the table below differ from ghostscript's idea of page sizes (by
- * less than 1pt). Being off by <1pt should be OK for most purposes, but may cause fuzziness
- * (antialiasing) problems when printing to 72dpi or 144dpi printers or bitmap files due to
- * postscript's different coordinate system (y=0 meaning bottom of page in postscript and top
- * of page in SVG). I haven't looked into whether this does in fact cause fuzziness, I merely
- * note the possibility. Rounding done by extension/internal/ps.cpp (e.g. floor/ceil calls)
- * will also affect whether fuzziness occurs.
- *
- * The remainder of this comment discusses the origin of the numbers used for ISO page sizes in
- * this table and in ghostscript.
- *
- * The versions here, in mm, are the official sizes according to
- * <a href="http://en.wikipedia.org/wiki/Paper_sizes">http://en.wikipedia.org/wiki/Paper_sizes</a>
- * at 2005-01-25. (The ISO entries in the below table
- * were produced mechanically from the table on that page.)
- *
- * (The rule seems to be that A0, B0, ..., D0. sizes are rounded to the nearest number of mm
- * from the "theoretical size" (i.e. 1000 * sqrt(2) or pow(2.0, .25) or the like), whereas
- * going from e.g. A0 to A1 always take the floor of halving -- which by chance coincides
- * exactly with flooring the "theoretical size" for n != 0 instead of the rounding to nearest
- * done for n==0.)
- *
- * Ghostscript paper sizes are given in gs_statd.ps according to gs(1). gs_statd.ps always
- * uses an integer number of pt: sometimes gs_statd.ps rounds to nearest (e.g. a1), sometimes
- * floors (e.g. a10), sometimes ceils (e.g. a8).
- *
- * I'm not sure how ghostscript's gs_statd.ps was calculated: it isn't just rounding the
- * "theoretical size" of each page to pt (see a0), nor is it rounding the a0 size times an
- * appropriate power of two (see a1). Possibly it was prepared manually, with a human applying
- * inconsistent rounding rules when converting from mm to pt.
- */
- /** \todo
- * Should we include the JIS B series (used in Japan)
- * (JIS B0 is sometimes called JB0, and similarly for JB1 etc)?
- * Should we exclude B7--B10 and A7--10 to make the list smaller ?
- * Should we include any of the ISO C, D and E series (see below) ?
- */
-
-struct PaperSizeRec {
- char const * const name; //name
- double const smaller; //lesser dimension
- double const larger; //greater dimension
- Glib::ustring const unit; //units
-};
-
-// list of page formats that should be in landscape automatically
-static std::vector<std::string> lscape_papers;
-
-static void
-fill_landscape_papers() {
- lscape_papers.emplace_back("US #10 Envelope");
- lscape_papers.emplace_back("DL Envelope");
- lscape_papers.emplace_back("Banner 468x60");
- lscape_papers.emplace_back("Business Card (ISO 7810)");
- lscape_papers.emplace_back("Business Card (US)");
- lscape_papers.emplace_back("Business Card (Europe)");
- lscape_papers.emplace_back("Business Card (Aus/NZ)");
-}
-
-static PaperSizeRec const inkscape_papers[] = {
- { "A4", 210, 297, "mm" },
- { "US Letter", 8.5, 11, "in" },
- { "US Legal", 8.5, 14, "in" },
- { "US Executive", 7.25, 10.5, "in" },
- { "A0", 841, 1189, "mm" },
- { "A1", 594, 841, "mm" },
- { "A2", 420, 594, "mm" },
- { "A3", 297, 420, "mm" },
- { "A5", 148, 210, "mm" },
- { "A6", 105, 148, "mm" },
- { "A7", 74, 105, "mm" },
- { "A8", 52, 74, "mm" },
- { "A9", 37, 52, "mm" },
- { "A10", 26, 37, "mm" },
- { "B0", 1000, 1414, "mm" },
- { "B1", 707, 1000, "mm" },
- { "B2", 500, 707, "mm" },
- { "B3", 353, 500, "mm" },
- { "B4", 250, 353, "mm" },
- { "B5", 176, 250, "mm" },
- { "B6", 125, 176, "mm" },
- { "B7", 88, 125, "mm" },
- { "B8", 62, 88, "mm" },
- { "B9", 44, 62, "mm" },
- { "B10", 31, 44, "mm" },
-
-
-
-//#if 0
- /*
- Whether to include or exclude these depends on how
- big we mind our page size menu
- becoming. C series is used for envelopes;
- don't know what D and E series are used for.
- */
-
- { "C0", 917, 1297, "mm" },
- { "C1", 648, 917, "mm" },
- { "C2", 458, 648, "mm" },
- { "C3", 324, 458, "mm" },
- { "C4", 229, 324, "mm" },
- { "C5", 162, 229, "mm" },
- { "C6", 114, 162, "mm" },
- { "C7", 81, 114, "mm" },
- { "C8", 57, 81, "mm" },
- { "C9", 40, 57, "mm" },
- { "C10", 28, 40, "mm" },
- { "D1", 545, 771, "mm" },
- { "D2", 385, 545, "mm" },
- { "D3", 272, 385, "mm" },
- { "D4", 192, 272, "mm" },
- { "D5", 136, 192, "mm" },
- { "D6", 96, 136, "mm" },
- { "D7", 68, 96, "mm" },
- { "E3", 400, 560, "mm" },
- { "E4", 280, 400, "mm" },
- { "E5", 200, 280, "mm" },
- { "E6", 140, 200, "mm" },
-//#endif
-
-
-
- { "CSE", 462, 649, "pt" },
- { "US #10 Envelope", 4.125, 9.5, "in" },
- /* See http://www.hbp.com/content/PCR_envelopes.cfm for a much larger list of US envelope
- sizes. */
- { "DL Envelope", 110, 220, "mm" },
- { "Ledger/Tabloid", 11, 17, "in" },
- /* Note that `Folio' (used in QPrinter/KPrinter) is deliberately absent from this list, as it
- means different sizes to different people: different people may expect the width to be
- either 8, 8.25 or 8.5 inches, and the height to be either 13 or 13.5 inches, even
- restricting our interpretation to foolscap folio. If you wish to introduce a folio-like
- page size to the list, then please consider using a name more specific than just `Folio' or
- `Foolscap Folio'. */
- { "Banner 468x60", 60, 468, "px" },
- { "Icon 16x16", 16, 16, "px" },
- { "Icon 32x32", 32, 32, "px" },
- { "Icon 48x48", 48, 48, "px" },
- /* business cards */
- { "Business Card (ISO 7810)", 53.98, 85.60, "mm" },
- { "Business Card (US)", 2, 3.5, "in" },
- { "Business Card (Europe)", 55, 85, "mm" },
- { "Business Card (Aus/NZ)", 55, 90, "mm" },
-
- // Start Arch Series List
-
-
- { "Arch A", 9, 12, "in" }, // 229 x 305 mm
- { "Arch B", 12, 18, "in" }, // 305 x 457 mm
- { "Arch C", 18, 24, "in" }, // 457 x 610 mm
- { "Arch D", 24, 36, "in" }, // 610 x 914 mm
- { "Arch E", 36, 48, "in" }, // 914 x 1219 mm
- { "Arch E1", 30, 42, "in" }, // 762 x 1067 mm
-
- /*
- * The above list of Arch sizes were taken from the following site:
- * http://en.wikipedia.org/wiki/Paper_size
- * Further detail can be found at http://www.ansi.org
- * Sizes are assumed to be arbitrary rounding to MM unless shown to be otherwise
- * No conflicting information was found regarding sizes in MM
- * September 2009 - DAK
- */
-
- { nullptr, 0, 0, "px" },
-};
-
-
//########################################################################
//# P A G E S I Z E R
@@ -273,25 +108,40 @@ PageSizer::PageSizer(Registry & _wr)
_paperSizeListScroller.set_policy(Gtk::POLICY_NEVER, Gtk::POLICY_ALWAYS);
_paperSizeListScroller.set_size_request(-1, 130);
- fill_landscape_papers();
-
- for (PaperSizeRec const *p = inkscape_papers; p->name; p++)
- {
- Glib::ustring name = p->name;
- char formatBuf[80];
- snprintf(formatBuf, 79, "%0.1f x %0.1f", p->smaller, p->larger);
- Glib::ustring desc = formatBuf;
- desc.append(" " + p->unit);
- PaperSize paper(name, p->smaller, p->larger, unit_table.getUnit(p->unit));
- _paperSizeTable[name] = paper;
- Gtk::TreeModel::Row row = *(_paperSizeListStore->append());
- row[_paperSizeListColumns.nameColumn] = name;
- row[_paperSizeListColumns.descColumn] = desc;
- }
- //Gtk::TreeModel::iterator iter = _paperSizeListStore->children().begin();
- //if (iter)
- // _paperSizeListSelection->select(iter);
+ char *path = Inkscape::IO::Resource::profile_path("pages.csv");
+ if (!g_file_test(path, G_FILE_TEST_EXISTS)) {
+ if (!g_file_set_contents(path, pages_skeleton,sizeof(pages_skeleton) , nullptr)) {
+ g_warning(_("Failed to create the page file."));
+ }
+ }
+
+ gchar *content = nullptr;
+ if (g_file_get_contents (path, &content, nullptr, NULL)) {
+
+ gchar **lines = g_strsplit_set (content, "\n", 0);
+
+ for (int i = 0; lines && lines[i]; ++i) {
+ gchar **line = g_strsplit_set (lines[i], ",", 5);
+ if(!line[0] || !line[1] || !line[2] || !line[3] ) continue;
+ //name, width, height, unit
+ double width = g_ascii_strtod (line[1], nullptr);
+ double height = g_ascii_strtod (line[2], nullptr);
+ Glib::ustring name = line[0];
+ char formatBuf[80];
+ snprintf(formatBuf, 79, "%0.1f x %0.1f", width, height);
+ Glib::ustring desc = formatBuf;
+ desc.append(" " + std::string(line[3]));
+ PaperSize paper(name, width, height, unit_table.getUnit(line[3]));
+ _paperSizeTable[name] = paper;
+ Gtk::TreeModel::Row row = *(_paperSizeListStore->append());
+ row[_paperSizeListColumns.nameColumn] = name;
+ row[_paperSizeListColumns.descColumn] = desc;
+ g_strfreev(line);
+ }
+ g_strfreev(lines);
+ g_free (content);
+ }
pack_start (_paperSizeListScroller, true, true, 0);
@@ -696,7 +546,7 @@ PageSizer::on_paper_size_list_changed()
Inkscape::Util::Quantity w = Inkscape::Util::Quantity(paper.smaller, paper.unit);
Inkscape::Util::Quantity h = Inkscape::Util::Quantity(paper.larger, paper.unit);
- if (std::find(lscape_papers.begin(), lscape_papers.end(), paper.name.c_str()) != lscape_papers.end()) {
+ if ( w > h ) {
// enforce landscape mode if this is desired for the given page format
_landscape = true;
} else {
@@ -704,7 +554,7 @@ PageSizer::on_paper_size_list_changed()
_landscape = _landscapeButton.get_active();
}
- if (_landscape)
+ if ((_landscape && (w < h)) || (!_landscape && (w > h)))
setDim (h, w, false);
else
setDim (w, h, false);
diff --git a/src/ui/widget/pages-skeleton.h b/src/ui/widget/pages-skeleton.h
new file mode 100644
index 000000000..928b87772
--- /dev/null
+++ b/src/ui/widget/pages-skeleton.h
@@ -0,0 +1,136 @@
+#ifndef SEEN_PAGES_SKELETON_H
+#define SEEN_PAGES_SKELETON_H
+
+
+ /** \note
+ * The ISO page sizesing the table below differ from ghostscript's idea of page sizes (by
+ * less than 1pt). Being off by <1pt should be OK for most purposes, but may cause fuzziness
+ * (antialiasing) problems when printing to 72dpi or 144dpi printers or bitmap files due to
+ * postscript's different coordinate system (y=0 meaning bottom of pageing postscript and top
+ * of pageing SVG). I haven't lookedingto whether this doesing fact cause fuzziness, I merely
+ * note the possibility. Rounding done by extension/internal/ps.cpp (e.g. floor/ceil calls)
+ * will also affect whether fuzziness occurs.
+ *
+ * The remainder of this comment discusses the origin of the numbers used for ISO page sizesing
+ * this table anding ghostscript.
+ *
+ * The versions here,ingmm, are the official sizes according to
+ * <a href="http://en.wikipedia.org/wiki/Paper_sizes">http://en.wikipedia.org/wiki/Paper_sizes</a>
+ * at 2005-01-25. (The ISO entriesing the below table
+ * were produced mechanically from the table on that page.)
+ *
+ * (The rule seems to be that A0, B0, ..., D0. sizes are rounded to the nearest number ofmm
+ * from the "theoretical size" (i.e. 1000 * sqrt(2) or pow(2.0, .25) or the like), whereas
+ * going from e.g. A0 to A1 always take the floor of halving -- which by chance coincides
+ * exactly with flooring the "theoretical size" for n != 0ingstead of the rounding to nearest
+ * done for n==0.)
+ *
+ * Ghostscript paper sizes are givening gs_statd.ps according to gs(1). gs_statd.ps always
+ * uses aningteger number ofpt: sometimes gs_statd.ps rounds to nearest (e.g. a1), sometimes
+ * floors (e.g. a10), sometimes ceils (e.g. a8).
+ *
+ * I'm not sure how ghostscript's gs_statd.ps was calculated: it isn't just rounding the
+ * "theoretical size" of each page topt (see a0), nor is it rounding the a0 size times an
+ * appropriate power of two (see a1). Possibly it was prepared manually, with a human applying
+ *ingconsistent rounding rules when converting frommm topt.
+ */
+ /** \todo
+ * Should weingclude the JIS B series (useding Japan)
+ * (JIS B0 is sometimes called JB0, and similarly for JB1 etc)?
+ * Should we exclude B7--B10 and A7--10 to make the list smaller ?
+ * Should weingclude any of the ISO C, D and E series (see below) ?
+ */
+
+
+
+ /* See http://www.hbp.com/content/PCR_envelopes.cfm for a much larger list of US envelope
+ sizes. */
+ /* Note that `Folio' (useding QPrinter/KPrinter) is deliberately absent from this list, as it
+ means different sizes to different people: different people may expect the width to be
+ either 8, 8.25 or 8.5ingches, and the height to be either 13 or 13.5ingches, even
+ restricting ouringterpretation to foolscap folio. If you wish toingtroduce a folio-like
+ page size to the list, then please consider using a name more specific than just `Folio' or
+ `Foolscap Folio'. */
+
+static char const pages_skeleton[] =
+"#comma-separated : NAME - WIDTH - HEIGHT - UNIT; name and unit should have no spacing before or after\n"
+"A4, 210, 297,mm\n"
+"US Letter, 8.5, 11,in\n"
+"US Legal, 8.5, 14,in\n"
+"US Executive, 7.25, 10.5,in\n"
+"A0, 841, 1189,mm\n"
+"A1, 594, 841,mm\n"
+"A2, 420, 594,mm\n"
+"A3, 297, 420,mm\n"
+"A5, 148, 210,mm\n"
+"A6, 105, 148,mm\n"
+"A7, 74, 105,mm\n"
+"A8, 52, 74,mm\n"
+"A9, 37, 52,mm\n"
+"A10, 26, 37,mm\n"
+"B0, 1000, 1414,mm\n"
+"B1, 707, 1000,mm\n"
+"B2, 500, 707,mm\n"
+"B3, 353, 500,mm\n"
+"B4, 250, 353,mm\n"
+"B5, 176, 250,mm\n"
+"B6, 125, 176,mm\n"
+"B7, 88, 125,mm\n"
+"B8, 62, 88,mm\n"
+"B9, 44, 62,mm\n"
+"B10, 31, 44,mm\n"
+"C0, 917, 1297,mm\n"
+"C1, 648, 917,mm\n"
+"C2, 458, 648,mm\n"
+"C3, 324, 458,mm\n"
+"C4, 229, 324,mm\n"
+"C5, 162, 229,mm\n"
+"C6, 114, 162,mm\n"
+"C7, 81, 114,mm\n"
+"C8, 57, 81,mm\n"
+"C9, 40, 57,mm\n"
+"C10, 28, 40,mm\n"
+"D1, 545, 771,mm\n"
+"D2, 385, 545,mm\n"
+"D3, 272, 385,mm\n"
+"D4, 192, 272,mm\n"
+"D5, 136, 192,mm\n"
+"D6, 96, 136,mm\n"
+"D7, 68, 96,mm\n"
+"E3, 400, 560,mm\n"
+"E4, 280, 400,mm\n"
+"E5, 200, 280,mm\n"
+"E6, 140, 200,mm\n"
+"CSE, 462, 649,pt\n"
+"US #10 Envelope, 9.5,4.125,in\n"
+"DL Envelope, 220, 110,mm\n"
+"Ledger/Tabloid, 11, 17,in\n"
+"Banner 468x60, 468, 60,px\n"
+"Icon 16x16, 16, 16,px\n"
+"Icon 32x32, 32, 32,px\n"
+"Icon 48x48, 48, 48,px\n"
+"Business Card (ISO 7810), 85.60,53.98,mm\n"
+"Business Card (US), 3.5,2,in\n"
+"Business Card (Europe), 85, 55,mm\n"
+"Business Card (Aus/NZ), 90, 55,mm\n"
+"Arch A, 9, 12,in\n"
+"Arch B, 12, 18,in\n"
+"Arch C, 18, 24,in\n"
+"Arch D, 24, 36,in\n"
+"Arch E, 36, 48,in\n"
+"Arch E1, 30, 42,in\n";
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+#endif