Warning, file /office/calligra/libs/odf/KoPageFormat.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001 /* This file is part of the KDE project 0002 Copyright (C) 1998, 1999 Torben Weis <weis@kde.org> 0003 Copyright 2002, 2003 David Faure <faure@kde.org> 0004 Copyright 2003 Nicolas GOUTTE <goutte@kde.org> 0005 Copyright 2007 Thomas Zander <zander@kde.org> 0006 0007 This library is free software; you can redistribute it and/or 0008 modify it under the terms of the GNU Library General Public 0009 License as published by the Free Software Foundation; either 0010 version 2 of the License, or (at your option) any later version. 0011 0012 This library is distributed in the hope that it will be useful, 0013 but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0015 Library General Public License for more details. 0016 0017 You should have received a copy of the GNU Library General Public License 0018 along with this library; see the file COPYING.LIB. If not, write to 0019 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 0020 * Boston, MA 02110-1301, USA. 0021 */ 0022 0023 #include "KoPageFormat.h" 0024 0025 #include <klocalizedstring.h> 0026 #include <OdfDebug.h> 0027 0028 // paper formats ( mm ) 0029 #define PG_A3_WIDTH 297.0 0030 #define PG_A3_HEIGHT 420.0 0031 #define PG_A4_WIDTH 210.0 0032 #define PG_A4_HEIGHT 297.0 0033 #define PG_A5_WIDTH 148.0 0034 #define PG_A5_HEIGHT 210.0 0035 #define PG_B5_WIDTH 182.0 0036 #define PG_B5_HEIGHT 257.0 0037 #define PG_US_LETTER_WIDTH 216.0 0038 #define PG_US_LETTER_HEIGHT 279.0 0039 #define PG_US_LEGAL_WIDTH 216.0 0040 #define PG_US_LEGAL_HEIGHT 356.0 0041 #define PG_US_EXECUTIVE_WIDTH 191.0 0042 #define PG_US_EXECUTIVE_HEIGHT 254.0 0043 0044 // To ignore the clang warning we get because we have a 0045 // for (int i = 0; pageFormatInfo[i].format != -1 ;i++) 0046 // construct and pageFormatInfo has (KoPageFormat::Format) - 1 0047 #if defined(__clang__) 0048 #pragma GCC diagnostic ignored "-Wtautological-constant-out-of-range-compare" 0049 #endif 0050 0051 struct PageFormatInfo { 0052 KoPageFormat::Format format; 0053 QPrinter::PageSize qprinter; 0054 const char* shortName; // Short name 0055 const char* descriptiveName; // Full name, which will be translated 0056 qreal width; // in mm 0057 qreal height; // in mm 0058 }; 0059 0060 // NOTES: 0061 // - the width and height of non-ISO formats are rounded 0062 // http://en.wikipedia.org/wiki/Paper_size can help 0063 // - the comments "should be..." indicates the exact values if the inch sizes would be multiplied by 25.4 mm/inch 0064 0065 const PageFormatInfo pageFormatInfo[] = { 0066 { KoPageFormat::IsoA3Size, QPrinter::A3, "A3", I18N_NOOP2("Page size", "ISO A3"), 297.0, 420.0 }, 0067 { KoPageFormat::IsoA4Size, QPrinter::A4, "A4", I18N_NOOP2("Page size", "ISO A4"), 210.0, 297.0 }, 0068 { KoPageFormat::IsoA5Size, QPrinter::A5, "A5", I18N_NOOP2("Page size", "ISO A5"), 148.0, 210.0 }, 0069 { KoPageFormat::UsLetterSize, QPrinter::Letter, "Letter", I18N_NOOP2("Page size", "US Letter"), 215.9, 279.4 }, 0070 { KoPageFormat::UsLegalSize, QPrinter::Legal, "Legal", I18N_NOOP2("Page size", "US Legal"), 215.9, 355.6 }, 0071 { KoPageFormat::ScreenSize, QPrinter::A4, "Screen", I18N_NOOP2("Page size", "Screen"), PG_A4_HEIGHT, PG_A4_WIDTH }, // Custom, so fall back to A4 0072 { KoPageFormat::CustomSize, QPrinter::A4, "Custom", I18N_NOOP2("Page size", "Custom"), PG_A4_WIDTH, PG_A4_HEIGHT }, // Custom, so fall back to A4 0073 { KoPageFormat::IsoB5Size, QPrinter::B5, "B5", I18N_NOOP2("Page size", "ISO B5"), 182.0, 257.0 }, 0074 { KoPageFormat::UsExecutiveSize, QPrinter::Executive, "Executive", I18N_NOOP2("Page size", "US Executive"), 191.0, 254.0 }, // should be 190.5 mm x 254.0 mm 0075 { KoPageFormat::IsoA0Size, QPrinter::A0, "A0", I18N_NOOP2("Page size", "ISO A0"), 841.0, 1189.0 }, 0076 { KoPageFormat::IsoA1Size, QPrinter::A1, "A1", I18N_NOOP2("Page size", "ISO A1"), 594.0, 841.0 }, 0077 { KoPageFormat::IsoA2Size, QPrinter::A2, "A2", I18N_NOOP2("Page size", "ISO A2"), 420.0, 594.0 }, 0078 { KoPageFormat::IsoA6Size, QPrinter::A6, "A6", I18N_NOOP2("Page size", "ISO A6"), 105.0, 148.0 }, 0079 { KoPageFormat::IsoA7Size, QPrinter::A7, "A7", I18N_NOOP2("Page size", "ISO A7"), 74.0, 105.0 }, 0080 { KoPageFormat::IsoA8Size, QPrinter::A8, "A8", I18N_NOOP2("Page size", "ISO A8"), 52.0, 74.0 }, 0081 { KoPageFormat::IsoA9Size, QPrinter::A9, "A9", I18N_NOOP2("Page size", "ISO A9"), 37.0, 52.0 }, 0082 { KoPageFormat::IsoB0Size, QPrinter::B0, "B0", I18N_NOOP2("Page size", "ISO B0"), 1030.0, 1456.0 }, 0083 { KoPageFormat::IsoB1Size, QPrinter::B1, "B1", I18N_NOOP2("Page size", "ISO B1"), 728.0, 1030.0 }, 0084 { KoPageFormat::IsoB10Size, QPrinter::B10, "B10", I18N_NOOP2("Page size", "ISO B10"), 32.0, 45.0 }, 0085 { KoPageFormat::IsoB2Size, QPrinter::B2, "B2", I18N_NOOP2("Page size", "ISO B2"), 515.0, 728.0 }, 0086 { KoPageFormat::IsoB3Size, QPrinter::B3, "B3", I18N_NOOP2("Page size", "ISO B3"), 364.0, 515.0 }, 0087 { KoPageFormat::IsoB4Size, QPrinter::B4, "B4", I18N_NOOP2("Page size", "ISO B4"), 257.0, 364.0 }, 0088 { KoPageFormat::IsoB6Size, QPrinter::B6, "B6", I18N_NOOP2("Page size", "ISO B6"), 128.0, 182.0 }, 0089 { KoPageFormat::IsoC5Size, QPrinter::C5E, "C5", I18N_NOOP2("Page size", "ISO C5"), 163.0, 229.0 }, // Some sources tells: 162 mm x 228 mm 0090 { KoPageFormat::UsComm10Size, QPrinter::Comm10E, "Comm10", I18N_NOOP2("Page size", "US Common 10"), 105.0, 241.0 }, // should be 104.775 mm x 241.3 mm 0091 { KoPageFormat::IsoDLSize, QPrinter::DLE, "DL", I18N_NOOP2("Page size", "ISO DL"), 110.0, 220.0 }, 0092 { KoPageFormat::UsFolioSize, QPrinter::Folio, "Folio", I18N_NOOP2("Page size", "US Folio"), 210.0, 330.0 }, // should be 209.54 mm x 330.2 mm 0093 { KoPageFormat::UsLedgerSize, QPrinter::Ledger, "Ledger", I18N_NOOP2("Page size", "US Ledger"), 432.0, 279.0 }, // should be 431.8 mm x 297.4 mm 0094 { KoPageFormat::UsTabloidSize, QPrinter::Tabloid, "Tabloid", I18N_NOOP2("Page size", "US Tabloid"), 279.0, 432.0 }, // should be 297.4 mm x 431.8 mm 0095 {(KoPageFormat::Format) - 1, (QPrinter::PageSize) - 1, "", "", -1, -1 } 0096 }; 0097 0098 QPrinter::PageSize KoPageFormat::printerPageSize(KoPageFormat::Format format) 0099 { 0100 if (format == ScreenSize) { 0101 warnOdf << "You use the page layout SCREEN. Printing in ISO A4 Landscape."; 0102 return QPrinter::A4; 0103 } 0104 if (format == CustomSize) { 0105 warnOdf << "The used page layout (Custom) is not supported by KQPrinter. Printing in A4."; 0106 return QPrinter::A4; 0107 } 0108 return pageFormatInfo[ format ].qprinter; 0109 } 0110 0111 qreal KoPageFormat::width(Format format, Orientation orientation) 0112 { 0113 if (orientation == Landscape) 0114 return height(format, Portrait); 0115 return pageFormatInfo[ format ].width; 0116 } 0117 0118 qreal KoPageFormat::height(Format format, Orientation orientation) 0119 { 0120 if (orientation == Landscape) 0121 return width(format, Portrait); 0122 return pageFormatInfo[ format ].height; 0123 } 0124 0125 KoPageFormat::Format KoPageFormat::guessFormat(qreal width, qreal height) 0126 { 0127 for (int i = 0; pageFormatInfo[i].format != -1 ;i++) { 0128 // We have some tolerance. 1pt is a third of a mm, this is 0129 // barely noticeable for a page size. 0130 if (qAbs(width - pageFormatInfo[i].width) < 1.0 && qAbs(height - pageFormatInfo[i].height) < 1.0) 0131 return pageFormatInfo[i].format; 0132 } 0133 return CustomSize; 0134 } 0135 0136 QString KoPageFormat::formatString(Format format) 0137 { 0138 return QString::fromLatin1(pageFormatInfo[ format ].shortName); 0139 } 0140 0141 KoPageFormat::Format KoPageFormat::formatFromString(const QString & string) 0142 { 0143 for (int i = 0; pageFormatInfo[i].format != -1 ;i++) { 0144 if (string == QString::fromLatin1(pageFormatInfo[ i ].shortName)) 0145 return pageFormatInfo[ i ].format; 0146 } 0147 // We do not know the format name, so we have a custom format 0148 return CustomSize; 0149 } 0150 0151 KoPageFormat::Format KoPageFormat::defaultFormat() 0152 { 0153 int qprinter; 0154 if (QLocale().measurementSystem() == QLocale::ImperialSystem) { 0155 qprinter = (int)QPageSize::Letter; 0156 } 0157 else { 0158 qprinter = (int)QPageSize::A4; 0159 } 0160 for (int i = 0; pageFormatInfo[i].format != -1 ;i++) { 0161 if (pageFormatInfo[ i ].qprinter == qprinter) 0162 return static_cast<Format>(i); 0163 } 0164 return IsoA4Size; 0165 } 0166 0167 QString KoPageFormat::name(Format format) 0168 { 0169 return i18nc("Page size", pageFormatInfo[ format ].descriptiveName); 0170 } 0171 0172 QStringList KoPageFormat::localizedPageFormatNames() 0173 { 0174 QStringList lst; 0175 for (int i = 0; pageFormatInfo[i].format != -1 ;i++) { 0176 lst << i18nc("Page size", pageFormatInfo[ i ].descriptiveName); 0177 } 0178 return lst; 0179 } 0180 0181 QStringList KoPageFormat::pageFormatNames() 0182 { 0183 QStringList lst; 0184 for (int i = 0; pageFormatInfo[i].format != -1 ;i++) { 0185 lst << pageFormatInfo[ i ].shortName; 0186 } 0187 return lst; 0188 }