From fde4d9dabf362f90bc20ecccf872310b811bb913 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Wed, 3 Feb 2021 02:29:10 +0200 Subject: [PATCH] make paper size table consistent with other tables Signed-off-by: Ivailo Monev --- src/gui/painting/qprinter.cpp | 81 ++++++++++++++++++----------------- 1 file changed, 41 insertions(+), 40 deletions(-) diff --git a/src/gui/painting/qprinter.cpp b/src/gui/painting/qprinter.cpp index c516c2d3c..39dcd35a0 100644 --- a/src/gui/painting/qprinter.cpp +++ b/src/gui/painting/qprinter.cpp @@ -64,37 +64,40 @@ QT_BEGIN_NAMESPACE } // NB! This table needs to be in sync with QPrinter::PaperSize -static const float qt_paperSizes[][2] = { - {210, 297}, // A4 - {176, 250}, // B5 - {215.9f, 279.4f}, // Letter - {215.9f, 355.6f}, // Legal - {190.5f, 254}, // Executive - {841, 1189}, // A0 - {594, 841}, // A1 - {420, 594}, // A2 - {297, 420}, // A3 - {148, 210}, // A5 - {105, 148}, // A6 - {74, 105}, // A7 - {52, 74}, // A8 - {37, 52}, // A8 - {1000, 1414}, // B0 - {707, 1000}, // B1 - {31, 44}, // B10 - {500, 707}, // B2 - {353, 500}, // B3 - {250, 353}, // B4 - {125, 176}, // B6 - {88, 125}, // B7 - {62, 88}, // B8 - {33, 62}, // B9 - {163, 229}, // C5E - {105, 241}, // US Common - {110, 220}, // DLE - {210, 330}, // Folio - {431.8f, 279.4f}, // Ledger - {279.4f, 431.8f} // Tabloid +static const struct paperSizesData { + const float width; + const float height; +} paperSizesTbl[QPrinter::NPaperSize] = { + { 210, 297 }, // A4 + { 176, 250 }, // B5 + { 215.9f, 279.4f }, // Letter + {215.9f, 355.6f }, // Legal + { 190.5f, 254 }, // Executive + { 841, 1189 }, // A0 + { 594, 841 }, // A1 + { 420, 594 }, // A2 + { 297, 420 }, // A3 + { 148, 210 }, // A5 + { 105, 148 }, // A6 + { 74, 105 }, // A7 + { 52, 74 }, // A8 + { 37, 52 }, // A9 + { 1000, 1414 }, // B0 + { 707, 1000 }, // B1 + { 31, 44 }, // B10 + { 500, 707 }, // B2 + { 353, 500 }, // B3 + { 250, 353 }, // B4 + { 125, 176 }, // B6 + { 88, 125 }, // B7 + { 62, 88 }, // B8 + { 33, 62 }, // B9 + { 163, 229 }, // C5E + { 105, 241 }, // Comm10E + { 110, 220 }, // DLE + { 210, 330 }, // Folio + { 431.8f, 279.4f }, // Ledger + { 279.4f, 431.8f } // Tabloid }; /// return the multiplier of converting from the unit value to postscript-points. @@ -125,15 +128,15 @@ QSizeF qt_printerPaperSize(QPrinter::Orientation orientation, QPrinter::Unit unit, int resolution) { - int width_index = 0; - int height_index = 1; + float width = paperSizesTbl[paperSize].width; + float height = paperSizesTbl[paperSize].height; if (orientation == QPrinter::Landscape) { - width_index = 1; - height_index = 0; + width = paperSizesTbl[paperSize].height; + height = paperSizesTbl[paperSize].width; } const qreal multiplier = qt_multiplierForUnit(unit, resolution); - return QSizeF((qt_paperSizes[paperSize][width_index] * 72 / 25.4) / multiplier, - (qt_paperSizes[paperSize][height_index] * 72 / 25.4) / multiplier); + return QSizeF((width * 72 / 25.4) / multiplier, + (height * 72 / 25.4) / multiplier); } void QPrinterPrivate::createDefaultEngines() @@ -2087,9 +2090,7 @@ QPrinter::PrintRange QPrinter::printRange() const QSizeF qt_paperSizeToQSizeF(QPrinter::PaperSize size) { if (size == QPrinter::Custom) return QSizeF(0, 0); - return QSizeF(qt_paperSizes[size][0], qt_paperSizes[size][1]); -} - + return QSizeF(paperSizesTbl[size].width, paperSizesTbl[size].height); } QT_END_NAMESPACE