Back to index

scribus-ng  1.3.4.dfsg+svn20071115
pagesize.cpp
Go to the documentation of this file.
00001 /*
00002 For general Scribus (>=1.3.2) copyright and licensing information please refer
00003 to the COPYING file provided with the program. Following this notice may exist
00004 a copyright and/or license notice that predates the release of Scribus 1.3.2
00005 for which a new license (GPL+exception) is in place.
00006 */
00007 /***************************************************************************
00008     begin                : Feb 2005
00009     copyright            : (C) 2005 by Craig Bradney
00010     email                : cbradney@zip.com.au
00011  ***************************************************************************/
00012 
00013 /***************************************************************************
00014  *                                                                         *
00015  *   This program is free software; you can redistribute it and/or modify  *
00016  *   it under the terms of the GNU General Public License as published by  *
00017  *   the Free Software Foundation; either version 2 of the License, or     *
00018  *   (at your option) any later version.                                   *
00019  *                                                                         *
00020  ***************************************************************************/
00021  
00022 #include <iostream>
00023 
00024 #include <qmap.h>
00025 #include <qobject.h>
00026 #include <qstringlist.h> 
00027 
00028 #include <cmath>
00029 
00030 #include "commonstrings.h"
00031 #include "pagesize.h"
00032 
00033 PageSize::PageSize(const QString sizeName)
00034 {
00035        bool valuesSet=false;
00036        generateSizeList();
00037        //Build based on untranslated key value
00038        if (pageSizeList.contains(sizeName))
00039        {
00040               PageSizeInfoMap::Iterator it = pageSizeList.find(sizeName);
00041               m_pageSizeName=it.key();
00042               m_width=it.data().width;
00043               m_height=it.data().height;
00044               m_pageUnitIndex=it.data().pageUnitIndex;
00045               m_trPageSizeName=it.data().trSizeName;
00046               valuesSet=true;
00047        }
00048        else //build based on translated value.
00049        {
00050               PageSizeInfoMap::Iterator it;
00051               for (it=pageSizeList.begin();it!=pageSizeList.end() && valuesSet!=true;++it)
00052               {
00053                      if (sizeName==it.data().trSizeName)
00054                      {
00055                             m_pageSizeName=it.key();
00056                             m_width=it.data().width;
00057                             m_height=it.data().height;
00058                             m_pageUnitIndex=it.data().pageUnitIndex;
00059                             m_trPageSizeName=it.data().trSizeName;
00060                             valuesSet=true;
00061                      }
00062               }
00063        }
00064        
00065        if (!valuesSet)
00066        {
00067               //qDebug("Non-existant page size selected");
00068               m_width=m_height=0.0;
00069               m_pageUnitIndex=-1;
00070               m_pageSizeName=CommonStrings::customPageSize;
00071               m_trPageSizeName=CommonStrings::trCustomPageSize;       
00072        }
00073 }
00074 
00075 PageSize::PageSize(const double w, const double h)
00076 {
00077        m_width=w;
00078        m_height=h;
00079        m_pageSizeName=CommonStrings::customPageSize;
00080        m_trPageSizeName=CommonStrings::trCustomPageSize;       
00081 }
00082 
00083 QStringList PageSize::sizeList(void) const
00084 {
00085        QStringList pageSizes;
00086        pageSizes.clear();
00087        PageSizeInfoMap::ConstIterator it;
00088        for (it=pageSizeList.begin();it!=pageSizeList.end();++it)
00089               pageSizes.append(it.key());
00090        return QStringList(pageSizes);
00091 }
00092 
00093 QStringList PageSize::sizeTRList(void) const
00094 {
00095        QStringList pageSizes;
00096        pageSizes.clear();
00097        PageSizeInfoMap::ConstIterator it;
00098        for (it=pageSizeList.begin();it!=pageSizeList.end();++it)
00099               pageSizes.append(it.data().trSizeName);
00100        return QStringList(pageSizes);
00101 }
00102 
00103 
00104 void PageSize::generateSizeList()
00105 {
00106        /*
00107        {"A5", "A6", "A7", "A8", "A9", "B0", "B1", "B2", "B3",
00108        "B4", "B5", "B6", "B7", "B8", "B9", "B10", "C5E", "Comm10E", "DLE", QObject::tr("Executive"),
00109        QObject::tr("Folio"), QObject::tr("Ledger"), QObject::tr("Legal"), QObject::tr("Letter"), QObject::tr("Tabloid")
00110        };
00111        */
00112 
00113        double width, height, tmp;
00114        int format;
00115        QString name;
00116        struct PageSizeInfo info;
00117        /* A series */
00118        width  = floor(1000.0 / sqrt(sqrt(2.0)) + 0.5);
00119        height = floor(sqrt(sqrt(2.0))*1000.0 + 0.5);
00120        //4A0
00121        info.width=mm2pts(width*2.0);
00122        info.height=mm2pts(height*2.0);
00123        info.pageUnitIndex=SC_MM;
00124        info.trSizeName=QObject::tr("4A0");
00125        pageSizeList.insert("4A0", info); 
00126        //2A0
00127        info.width=mm2pts(height);
00128        info.height=mm2pts(width*2.0);
00129        info.pageUnitIndex=SC_MM;
00130        info.trSizeName=QObject::tr("2A0");
00131        pageSizeList.insert("2A0", info); 
00132        //Continue with rest of A series
00133        for (format = 0; format <= 10; format++) {
00134               info.width=mm2pts(width);
00135               info.height=mm2pts(height);
00136               info.pageUnitIndex=SC_MM;
00137               name=QString("A%1").arg(format);
00138               info.trSizeName=name;
00139               pageSizeList.insert(name, info);
00140               tmp = height;
00141               height = width;
00142               width = floor(tmp / 2.0);
00143        }
00144        
00145        /* B series */
00146        width  = 1000.0;
00147        height = floor(sqrt(2.0)*1000.0 + 0.5);
00148 
00149        for (format = 0; format <= 10; format++) {
00150               info.width=mm2pts(width);
00151               info.height=mm2pts(height);
00152               info.pageUnitIndex=SC_MM;
00153               name=QString("B%1").arg(format);
00154               info.trSizeName=name;
00155               pageSizeList.insert(name, info);
00156 
00157               tmp = height;
00158               height = width;
00159               width = floor(tmp / 2.0);
00160        }
00161 
00162        /* C series */
00163        width  = floor(1000.0 / sqrt(sqrt(sqrt(2.0)))+0.5);
00164        height = floor(sqrt(sqrt(sqrt(8.0)))*1000.0 + 0.5);
00165 
00166        for (format = 0; format <= 10; format++) {
00167               info.width=mm2pts(width);
00168               info.height=mm2pts(height);
00169               info.pageUnitIndex=SC_MM;
00170               name=QString("C%1").arg(format);
00171               info.trSizeName=name;
00172               pageSizeList.insert(name, info);
00173 
00174               tmp = height;
00175               height = width;
00176               width = floor(tmp / 2.0);
00177        }
00178 
00179        /* PA series */
00180        width  = 840;
00181        height = 1120;
00182        for (format = 0; format <= 10; format++) {
00183               info.width=mm2pts(width);
00184               info.height=mm2pts(height);
00185               info.pageUnitIndex=SC_MM;
00186               name=QString("PA%1").arg(format);
00187               info.trSizeName=name;
00188               pageSizeList.insert(name, info);
00189               tmp = height;
00190               height = width;
00191               width = floor(tmp / 2.0);
00192        }
00193        
00194        //Imperial
00195        //http://en.wikipedia.org/wiki/Paper_sizes
00196        double impWidths[]={10.0,13.0,8.5,8.0,8.5,11.0,7.25,15.5,15.0,16.5,17.5,18.0,20.0,23.0,23.5,35.0,5.5,8.5,11.0,17.0,22.0,34.0};
00197        double impHeights[]={8.0,8.0,11.0,10.5,14.0,17.0,10.5,19.25,20.0,21.0,22.5,23.0,25.0,28.0,35.0,45.0,8.5,11.0,17.0,22.0,34.0,44.0};
00198        QString impNames[]={"Quarto","Foolscap","Letter","Govt. Letter","Legal","Ledger","Executive","Post","Crown","Large Post","Demy","Medium","Royal","Elephant","Double Demy","Quad Demy","STMT","A","B","C","D","E"};
00199        QString impTrNames[]={QObject::tr("Quarto"), QObject::tr("Foolscap"), QObject::tr("Letter"),
00200               QObject::tr("Govt. Letter"), QObject::tr("Legal"), QObject::tr("Ledger"), QObject::tr("Executive"),
00201               QObject::tr("Post"), QObject::tr("Crown"), QObject::tr("Large Post"), QObject::tr("Demy"),
00202               QObject::tr("Medium"), QObject::tr("Royal"), QObject::tr("Elephant"), QObject::tr("Double Demy"),
00203               QObject::tr("Quad Demy"), QObject::tr("STMT"), QObject::tr("A"), QObject::tr("B"), QObject::tr("C"),
00204               QObject::tr("D"), QObject::tr("E")};
00205        
00206        size_t const num_mappings_widths = (sizeof impWidths)/(sizeof *impWidths);
00207        
00208        for (uint i = 0; i < num_mappings_widths; ++i)
00209        {
00210               info.width=in2pts(impWidths[i]);
00211               info.height=in2pts(impHeights[i]);
00212               info.pageUnitIndex=SC_IN;
00213               info.trSizeName=impTrNames[i];
00214               pageSizeList.insert(impNames[i], info);
00215        }
00216        //Comm10E
00217        info.width=in2pts(4.125);
00218        info.height=in2pts(9.5);
00219        info.pageUnitIndex=SC_IN;
00220        info.trSizeName=QObject::tr("Comm10E");
00221        pageSizeList.insert("Comm10E", info); 
00222        //DLE
00223        info.width=mm2pts(110);
00224        info.height=mm2pts(220);
00225        info.pageUnitIndex=SC_MM;
00226        info.trSizeName=QObject::tr("DLE");
00227        pageSizeList.insert("DLE", info); 
00228        //Executive
00229        //Folio
00230        //Ledger
00231        //Legal
00232        //Letter
00233        //Tabloid
00234 }
00235 
00236 void PageSize::printSizeList()
00237 {
00238        PageSizeInfoMap::Iterator it;
00239        for (it=pageSizeList.begin();it!=pageSizeList.end();++it)
00240               std::cout << it.key().leftJustify(6) << ": " << it.data().width << " x " << it.data().height << ",  " << it.data().width*unitGetRatioFromIndex(it.data().pageUnitIndex) << " x " << it.data().height*unitGetRatioFromIndex(it.data().pageUnitIndex) << ",  " << it.data().trSizeName << std::endl;
00241 }
00242