page-sizer.cpp revision 200dc6f1e980354866c2ed5fc9ce277475fe37a0
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * Paper-size widget and helper functions
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * Authors:
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * bulia byak <buliabyak@users.sf.net>
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * Lauris Kaplinski <lauris@kaplinski.com>
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * Jon Phillips <jon@rejon.org>
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * Ralf Stephan <ralf@ark.in-berlin.de> (Gtkmm)
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * Copyright (C) 2000 - 2005 Authors
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * Released under GNU GPL. Read the file 'COPYING' for more information
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc//#include <gtkmm/frame.h>
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc//#include <gtkmm/table.h>
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxcnamespace UI {
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxcnamespace Widget {
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * The ISO page sizes in the table below differ from ghostscript's idea of page sizes (by
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * less than 1pt). Being off by <1pt should be OK for most purposes, but may cause fuzziness
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * (antialiasing) problems when printing to 72dpi or 144dpi printers or bitmap files due to
bcb5c89da22515e2ccf139578bad3caebcd716adSowmini Varadhan * postscript's different coordinate system (y=0 meaning bottom of page in postscript and top
bcb5c89da22515e2ccf139578bad3caebcd716adSowmini Varadhan * of page in SVG). I haven't looked into whether this does in fact cause fuzziness, I merely
bcb5c89da22515e2ccf139578bad3caebcd716adSowmini Varadhan * note the possibility. Rounding done by extension/internal/ps.cpp (e.g. floor/ceil calls)
bcb5c89da22515e2ccf139578bad3caebcd716adSowmini Varadhan * will also affect whether fuzziness occurs.
bcb5c89da22515e2ccf139578bad3caebcd716adSowmini Varadhan * The remainder of this comment discusses the origin of the numbers used for ISO page sizes in
bcb5c89da22515e2ccf139578bad3caebcd716adSowmini Varadhan * this table and in ghostscript.
bcb5c89da22515e2ccf139578bad3caebcd716adSowmini Varadhan * The versions here, in mm, are the official sizes according to
bcb5c89da22515e2ccf139578bad3caebcd716adSowmini Varadhan * <a href="http://en.wikipedia.org/wiki/Paper_sizes">http://en.wikipedia.org/wiki/Paper_sizes</a>
bcb5c89da22515e2ccf139578bad3caebcd716adSowmini Varadhan * at 2005-01-25. (The ISO entries in the below table
bcb5c89da22515e2ccf139578bad3caebcd716adSowmini Varadhan * were produced mechanically from the table on that page.)
bcb5c89da22515e2ccf139578bad3caebcd716adSowmini Varadhan * (The rule seems to be that A0, B0, ..., D0. sizes are rounded to the nearest number of mm
bcb5c89da22515e2ccf139578bad3caebcd716adSowmini Varadhan * from the "theoretical size" (i.e. 1000 * sqrt(2) or pow(2.0, .25) or the like), whereas
bcb5c89da22515e2ccf139578bad3caebcd716adSowmini Varadhan * going from e.g. A0 to A1 always take the floor of halving -- which by chance coincides
bcb5c89da22515e2ccf139578bad3caebcd716adSowmini Varadhan * exactly with flooring the "theoretical size" for n != 0 instead of the rounding to nearest
bcb5c89da22515e2ccf139578bad3caebcd716adSowmini Varadhan * done for n==0.)
bcb5c89da22515e2ccf139578bad3caebcd716adSowmini Varadhan * Ghostscript paper sizes are given in gs_statd.ps according to gs(1). gs_statd.ps always
bcb5c89da22515e2ccf139578bad3caebcd716adSowmini Varadhan * uses an integer number of pt: sometimes gs_statd.ps rounds to nearest (e.g. a1), sometimes
bcb5c89da22515e2ccf139578bad3caebcd716adSowmini Varadhan * floors (e.g. a10), sometimes ceils (e.g. a8).
bcb5c89da22515e2ccf139578bad3caebcd716adSowmini Varadhan * I'm not sure how ghostscript's gs_statd.ps was calculated: it isn't just rounding the
bcb5c89da22515e2ccf139578bad3caebcd716adSowmini Varadhan * "theoretical size" of each page to pt (see a0), nor is it rounding the a0 size times an
bcb5c89da22515e2ccf139578bad3caebcd716adSowmini Varadhan * appropriate power of two (see a1). Possibly it was prepared manually, with a human applying
bcb5c89da22515e2ccf139578bad3caebcd716adSowmini Varadhan * inconsistent rounding rules when converting from mm to pt.
bcb5c89da22515e2ccf139578bad3caebcd716adSowmini Varadhan * Should we include the JIS B series (used in Japan)
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * (JIS B0 is sometimes called JB0, and similarly for JB1 etc)?
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * Should we exclude B7--B10 and A7--10 to make the list smaller ?
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * Should we include any of the ISO C, D and E series (see below) ?
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc char const * const name;
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc double const smaller;
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc double const larger;
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc#if 0 /* Whether to include or exclude these depends on how big we mind our page size menu
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc becoming. C series is used for envelopes; don't know what D and E series are used for. */
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc { "US #10 Envelope", 4.125, 9.5, SP_UNIT_IN }, // TODO: Select landscape by default.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc /* See http://www.hbp.com/content/PCR_envelopes.cfm for a much larger list of US envelope
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc { "DL Envelope", 110, 220, SP_UNIT_MM }, // TODO: Select landscape by default.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc /* Note that `Folio' (used in QPrinter/KPrinter) is deliberately absent from this list, as it
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc means different sizes to different people: different people may expect the width to be
bcb5c89da22515e2ccf139578bad3caebcd716adSowmini Varadhan either 8, 8.25 or 8.5 inches, and the height to be either 13 or 13.5 inches, even
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc restricting our interpretation to foolscap folio. If you wish to introduce a folio-like
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc page size to the list, then please consider using a name more specific than just `Folio' or
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc `Foolscap Folio'. */
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc { "Banner 468x60", 60, 468, SP_UNIT_PX }, // TODO: Select landscape by default.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc//===================================================
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxcstatic const SPUnit _px_unit = sp_unit_get_by_id (SP_UNIT_PX);
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxcclass SizeMenuItem : public Gtk::MenuItem {
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc SizeMenuItem (PaperSizeRec const * paper, PageSizer * widget)
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc : Gtk::MenuItem (paper ? paper->name : _("Custom")),
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc _paper(paper),
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc _parent(widget)
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc PaperSizeRec const * _paper;
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc PageSizer *_parent;
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc void on_activate();
bcb5c89da22515e2ccf139578bad3caebcd716adSowmini VaradhanSizeMenuItem::on_activate()
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc if (_parent == 0) // handle Custom entry
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc double w = _paper->smaller, h = _paper->larger;
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc SPUnit const &src_unit = sp_unit_get_by_id (_paper->unit);
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc sp_convert_distance (&w, &src_unit, &_px_unit);
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc sp_convert_distance (&h, &src_unit, &_px_unit);
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc if (_parent->_landscape)
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc _parent->setDim (h, w);
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc _parent->setDim (w, h);
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc//---------------------------------------------------
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc Gtk::HBox *hbox_size = manage (new Gtk::HBox (false, 4));
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc Gtk::Label *label_size = manage (new Gtk::Label (_("P_age size:"), 1.0, 0.5));
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc //# Set up the Paper Size combo box
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc for (PaperSizeRec const *p = inkscape_papers; p->name; p++)
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc Gtk::Label *label_ori = manage (new Gtk::Label (_("Page orientation:"), 0.0, 0.5));
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc Gtk::RadioButton::Group group = _landscapeButton.get_group();
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc /* Custom paper frame */
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc Gtk::Frame *frame = manage (new Gtk::Frame(_("Custom size")));
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc Gtk::Table *table = manage (new Gtk::Table (5, 2, false));
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc manage(new Inkscape::UI::Widget::Button(_("_Fit page to selection"),
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc _("Resize the page to fit the current selection, or the entire drawing if there is no selection")));
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc // prevent fit_canv from expanding
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc Gtk::Alignment *fit_canv_cont = manage(new Gtk::Alignment(1.0,0.5,0.0,0.0));
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc _rusw.init (_("_Width:"), _("Width of paper"), "width", _rum, *_wr);
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc _rush.init (_("_Height:"), _("Height of paper"), "height", _rum, *_wr);
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc table->attach (*_rum._label, 0,1,0,1, Gtk::FILL|Gtk::EXPAND,
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc table->attach (*_rum._sel, 1,2,0,1, Gtk::FILL|Gtk::EXPAND,
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc table->attach (*_rusw.getSU(), 0,2,1,2, Gtk::FILL|Gtk::EXPAND,
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc table->attach (*_rush.getSU(), 0,2,2,3, Gtk::FILL|Gtk::EXPAND,
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc table->attach (*fit_canv_cont, 0,2,3,4, Gtk::FILL|Gtk::EXPAND,
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc _paper_size_list_connection = _paperSizeList.signal_changed().connect (
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc sigc::mem_fun (*this, &PageSizer::on_paper_size_list_changed));
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc _landscape_connection = _landscapeButton.signal_toggled().connect (
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc _portrait_connection = _portraitButton.signal_toggled().connect (
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc _changedw_connection = _rusw.getSU()->signal_value_changed().connect (
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc _changedh_connection = _rush.getSU()->signal_value_changed().connect (
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc sigc::mem_fun(*this, &PageSizer::fire_fit_canvas_to_selection_or_drawing));
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * Set document dimensions (if not called by Doc prop's update()) and
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * set the PageSizer's widgets and text entries accordingly. This is
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * somewhat slow, is there something done too often invisibly?
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * \param w, h given in px
bcb5c89da22515e2ccf139578bad3caebcd716adSowmini Varadhan static bool _called = false;
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc SPDocument *doc = sp_desktop_document(SP_ACTIVE_DESKTOP);
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * Returns an index into inkscape_papers of a paper of the specified
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc * size (specified in px), or -1 if there's no such paper.
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc double smaller = w;
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc double larger = h;
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc if ( h < w ) {
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc for (iter = paperSizeTable.begin() ; iter != paperSizeTable.end() ; iter++) {
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc double smallX = sp_units_get_pixels(paper.smaller, i_unit);
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc double largeX = sp_units_get_pixels(paper.larger, i_unit);
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc return -1;
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc if (!dt) return;
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc Verb *verb = Verb::get( SP_VERB_FIT_CANVAS_TO_SELECTION_OR_DRAWING );
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc std::map<Glib::ustring, PaperSize>::const_iterator iter =
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc g_warning("paper size '%s' not found in table", name.c_str());
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc setDim (h, w, false);
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc setDim (w, h, false);
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc} // namespace Widget
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc} // namespace UI
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc} // namespace Inkscape
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc Local Variables:
19d332fefbc61327bb6187d0eb818629f3b52c6ffei feng - Sun Microsystems - Beijing China c-file-style:"stroustrup"
19d332fefbc61327bb6187d0eb818629f3b52c6ffei feng - Sun Microsystems - Beijing China c-file-offsets:((innamespace . 0)(inline-open . 0))
bcb5c89da22515e2ccf139578bad3caebcd716adSowmini Varadhan indent-tabs-mode:nil
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc fill-column:99
0ba2cbe97e0678a691742f98d2532caed0a2c4aaxc// vim: filetype=c++:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :