From 4ab74d520d43fccca455851f962802f6ad156aae Mon Sep 17 00:00:00 2001 From: Sandro Mani Date: Mon, 5 Feb 2024 10:40:44 +0100 Subject: [PATCH] Reformat source files --- common/CCITTFax4Encoder.cc | 25 +-- common/PaperSize.cc | 309 +++++++++++++++++++------------------ common/PaperSize.hh | 2 +- formatSourceFiles.sh | 2 +- 4 files changed, 170 insertions(+), 168 deletions(-) diff --git a/common/CCITTFax4Encoder.cc b/common/CCITTFax4Encoder.cc index ca19c600..9eaccc45 100644 --- a/common/CCITTFax4Encoder.cc +++ b/common/CCITTFax4Encoder.cc @@ -295,7 +295,7 @@ CCITTFax4Encoder::~CCITTFax4Encoder() { delete m_state; } -uint8_t* CCITTFax4Encoder::encode(const uint8_t *buffer, uint32_t width, uint32_t height, uint32_t rowbytes, uint32_t &outputSize) { +uint8_t* CCITTFax4Encoder::encode(const uint8_t* buffer, uint32_t width, uint32_t height, uint32_t rowbytes, uint32_t& outputSize) { m_state->buf.resize(0); m_state->data = 0; m_state->bit = 8; @@ -320,13 +320,13 @@ uint8_t* CCITTFax4Encoder::encode(const uint8_t *buffer, uint32_t width, uint32_ void CCITTFax4Encoder::putspan(int32_t span, const TableEntry* tab) { while (span >= 2624) { - const TableEntry& te = tab[63 + (2560>>6)]; + const TableEntry& te = tab[63 + (2560 >> 6)]; putbits(te.code, te.length); span -= te.runlen; } if (span >= 64) { - const TableEntry& te = tab[63 + (span>>6)]; - assert(te.runlen == 64*(span>>6)); + const TableEntry& te = tab[63 + (span >> 6)]; + assert(te.runlen == 64 * (span >> 6)); putbits(te.code, te.length); span -= te.runlen; } @@ -357,7 +357,7 @@ void CCITTFax4Encoder::flushbits() { } static inline uint8_t pixel(const uint8_t* line, uint32_t i) { - return !(((line[i>>3]) >> (7 - (i&7))) & 1); + return !(((line[i >> 3]) >> (7 - (i & 7))) & 1); } static inline uint32_t findpixel(const uint8_t* line, uint32_t start, uint32_t length, uint8_t color) { @@ -384,24 +384,25 @@ void CCITTFax4Encoder::encode2DRow(const uint8_t* codeline, const uint8_t* refli int32_t d = b1 - a1; if (-3 <= d && d <= 3) { /* vertical mode */ - putbits(vcodes[d+3].code, vcodes[d+3].length); + putbits(vcodes[d + 3].code, vcodes[d + 3].length); a0 = a1; } else { /* horizontal mode */ uint32_t a2 = findpixel(codeline, a1 + 1, linebits, !pixel(codeline, a1)); putbits(horizcode.code, horizcode.length); - if (a0+a1 == 0 || pixel(codeline, a0) == 0) { - putspan(a1-a0, whiteCodes); - putspan(a2-a1, blackCodes); + if (a0 + a1 == 0 || pixel(codeline, a0) == 0) { + putspan(a1 - a0, whiteCodes); + putspan(a2 - a1, blackCodes); } else { - putspan(a1-a0, blackCodes); - putspan(a2-a1, whiteCodes); + putspan(a1 - a0, blackCodes); + putspan(a2 - a1, whiteCodes); } a0 = a2; } } - if (a0 >= linebits) + if (a0 >= linebits) { break; + } // Next changing pixel on codeline right of a0 a1 = findpixel(codeline, a0 + 1, linebits, !pixel(codeline, a0)); // Next changing pixel on refline right of a0 and of opposite color than a0 diff --git a/common/PaperSize.cc b/common/PaperSize.cc index 5d4a1b37..5695355a 100644 --- a/common/PaperSize.cc +++ b/common/PaperSize.cc @@ -27,28 +27,29 @@ template -bool PaperSize::Size::operator<(const Size &val){ +bool PaperSize::Size::operator<(const Size& val) { return std::tie(width, height) < std::tie(val.width, val.height); } PaperSize::Size PaperSize::getSize(PaperSize::Unit unit, const std::string& format, bool landscape) { auto result = std::find_if(paperSizes.begin(), paperSizes.end(), - [&format](const std::pair>& val) { return val.first == format; }); + [&format](const std::pair>& val) { return val.first == format; }); if(result == paperSizes.end()) { return {0.0, 0.0}; } // Translate size into cm from mm Size formatResult = {static_cast(result->second.width) / 10.0, - static_cast(result->second.height) / 10.0}; + static_cast(result->second.height) / 10.0 + }; if(landscape) { std::swap(formatResult.width, formatResult.height); } if(unit == PaperSize::inch) { return {formatResult.width / CMtoInch, formatResult.height / CMtoInch}; - } else /*if(unit == PaperSize::cm)*/ { + } else { /*if(unit == PaperSize::cm)*/ return formatResult; } } @@ -56,154 +57,154 @@ PaperSize::Size PaperSize::getSize(PaperSize::Unit unit, const std::stri const double PaperSize::CMtoInch = 2.54; const std::vector>> PaperSize::paperSizes = { - // A type - {"4A0", Size(1682, 2378)}, - {"2A0", Size(1189, 1682)}, - {"A0", Size(841, 1189)}, - {"A1", Size(594, 841)}, - {"A2", Size(420, 594)}, - {"A3", Size(297, 420)}, - {"A4", Size(210, 297)}, - {"A5", Size(148, 210)}, - {"A6", Size(105, 148)}, - {"A7", Size(74, 105)}, - {"A8", Size(52, 74)}, - {"A9", Size(37, 52)}, - {"A10", Size(26, 37)}, - {"A11", Size(18, 26)}, - {"A12", Size(13, 18)}, - {"A13", Size(9, 13)}, - - // B type - {"B0", Size(1000, 1414)}, - {"B1", Size(707, 1000)}, - {"B2", Size(500, 707)}, - {"B3", Size(353, 500)}, - {"B4", Size(250, 353)}, - {"B5", Size(176, 250)}, - {"B6", Size(125, 176)}, - {"B7", Size(88, 125)}, - {"B8", Size(62, 88)}, - {"B9", Size(44, 62)}, - {"B10", Size(31, 44)}, - {"B11", Size(22, 31)}, - {"B12", Size(15, 22)}, - {"B13", Size(11, 15)}, - - // C type - {"C0", Size(917, 1297)}, - {"C1", Size(648, 917)}, - {"C2", Size(458, 648)}, - {"C3", Size(324, 458)}, - {"C4", Size(229, 324)}, - {"C5", Size(162, 229)}, - {"C6", Size(114, 162)}, - {"C7", Size(81, 114)}, - {"C8", Size(57, 81)}, - {"C9", Size(40, 57)}, - {"C10", Size(28, 40)}, - - // D type. (German extension) - {"D0", Size(771, 1090)}, - {"D1", Size(545, 771)}, - {"D2", Size(385, 545)}, - {"D3", Size(272, 385)}, - {"D4", Size(192, 272)}, - {"D5", Size(136, 192)}, - {"D6", Size(96, 136)}, - {"D7", Size(68, 96)}, - {"D8", Size(48, 68)}, - - {"D0 (China)", Size(764, 1064)}, - {"D1 (China)", Size(532, 760)}, - {"D2 (China)", Size(380, 528)}, - {"D3 (China)", Size(264, 376)}, - {"D4 (China)", Size(188, 260)}, - {"D5 (China)", Size(130, 184)}, - {"D6 (China)", Size(92, 126)}, - - {"RD0 (China)", Size(787, 1092)}, - {"RD1 (China)", Size(546, 787)}, - {"RD2 (China)", Size(393, 546)}, - {"RD3 (China)", Size(273, 393)}, - {"RD4 (China)", Size(196, 273)}, - {"RD5 (China)", Size(136, 196)}, - {"RD6 (China)", Size(98, 136)}, - - {"CAN P1", Size(560, 860)}, - {"CAN P2", Size(430, 560)}, - {"CAN P3", Size(280, 430)}, - {"CAN P4", Size(215, 280)}, - {"CAN P5", Size(140, 215)}, - {"CAN P6", Size(107, 140)}, - - {"ANSI A", Size(216, 279)}, - {"ANSI B", Size(279, 432)}, - {"ANSI C", Size(432, 559)}, - {"ANSI D", Size(559, 864)}, - {"ANSI E", Size(864, 1118)}, - - {"Arch A/1", Size(229, 305)}, - {"Arch B/2", Size(305, 457)}, - {"Arch C/3", Size(457, 610)}, - {"Arch D/4", Size(610, 914)}, - {"Arch E/6", Size(914, 1219)}, - {"Arch E1/5", Size(762, 1067)}, - {"Arch E2", Size(660, 965)}, - {"Arch E3", Size(686, 991)}, - - {"B0 (JIS)", Size(1030, 1456)}, - {"B1 (JIS)", Size(728, 1030)}, - {"B2 (JIS)", Size(515, 728)}, - {"B3 (JIS)", Size(364, 515)}, - {"B4 (JIS)", Size(257, 364)}, - {"B5 (JIS)", Size(182, 257)}, - {"B6 (JIS)", Size(128, 182)}, - {"B7 (JIS)", Size(91, 128)}, - {"B8 (JIS)", Size(64, 91)}, - {"B9 (JIS)", Size(45, 64)}, - {"B10 (JIS)", Size(32, 45)}, - {"B11 (JIS)", Size(22, 32)}, - {"B12 (JIS)", Size(16, 22)}, - - {"F0", Size(841, 1321)}, - {"F1", Size(660, 841)}, - {"F2", Size(420, 660)}, - {"F3", Size(330, 420)}, - {"F4", Size(210, 330)}, - {"F5", Size(165, 210)}, - {"F6", Size(105, 165)}, - {"F7", Size(82, 105)}, - {"F8", Size(52, 82)}, - {"F9", Size(41, 52)}, - {"F10", Size(26, 41)}, - - // North American paper sizes - {"Letter", Size(216, 279)}, - {"Legal", Size(216, 356)}, - {"Tabloid", Size(279, 432)}, - {"Ledger", Size(432, 279)}, - {"Junior Legal", Size(127, 203)}, - {"Half Letter/Memo", Size(140, 216)}, - {"Government Letter", Size(203, 267)}, - {"Government Legal", Size(216, 330)}, - - // Traditional British paper sizes - {"Foolscap", Size(203, 330)}, - {"Quarto", Size(203, 254)}, - {"Imperial", Size(178, 229)}, - {"Kings", Size(165, 203)}, - {"Dukes", Size(140, 178)}, - - // Raw sizes - {"RA0", Size(860, 1220)}, - {"RA1", Size(610, 860)}, - {"RA2", Size(430, 610)}, - {"RA3", Size(305, 430)}, - {"RA4", Size(215, 305)}, - {"SRA0", Size(900, 1280)}, - {"SRA1", Size(640, 900)}, - {"SRA2", Size(450, 640)}, - {"SRA3", Size(320, 450)}, - {"SRA4", Size(225, 320)} + // A type + {"4A0", Size(1682, 2378)}, + {"2A0", Size(1189, 1682)}, + {"A0", Size(841, 1189)}, + {"A1", Size(594, 841)}, + {"A2", Size(420, 594)}, + {"A3", Size(297, 420)}, + {"A4", Size(210, 297)}, + {"A5", Size(148, 210)}, + {"A6", Size(105, 148)}, + {"A7", Size(74, 105)}, + {"A8", Size(52, 74)}, + {"A9", Size(37, 52)}, + {"A10", Size(26, 37)}, + {"A11", Size(18, 26)}, + {"A12", Size(13, 18)}, + {"A13", Size(9, 13)}, + + // B type + {"B0", Size(1000, 1414)}, + {"B1", Size(707, 1000)}, + {"B2", Size(500, 707)}, + {"B3", Size(353, 500)}, + {"B4", Size(250, 353)}, + {"B5", Size(176, 250)}, + {"B6", Size(125, 176)}, + {"B7", Size(88, 125)}, + {"B8", Size(62, 88)}, + {"B9", Size(44, 62)}, + {"B10", Size(31, 44)}, + {"B11", Size(22, 31)}, + {"B12", Size(15, 22)}, + {"B13", Size(11, 15)}, + + // C type + {"C0", Size(917, 1297)}, + {"C1", Size(648, 917)}, + {"C2", Size(458, 648)}, + {"C3", Size(324, 458)}, + {"C4", Size(229, 324)}, + {"C5", Size(162, 229)}, + {"C6", Size(114, 162)}, + {"C7", Size(81, 114)}, + {"C8", Size(57, 81)}, + {"C9", Size(40, 57)}, + {"C10", Size(28, 40)}, + + // D type. (German extension) + {"D0", Size(771, 1090)}, + {"D1", Size(545, 771)}, + {"D2", Size(385, 545)}, + {"D3", Size(272, 385)}, + {"D4", Size(192, 272)}, + {"D5", Size(136, 192)}, + {"D6", Size(96, 136)}, + {"D7", Size(68, 96)}, + {"D8", Size(48, 68)}, + + {"D0 (China)", Size(764, 1064)}, + {"D1 (China)", Size(532, 760)}, + {"D2 (China)", Size(380, 528)}, + {"D3 (China)", Size(264, 376)}, + {"D4 (China)", Size(188, 260)}, + {"D5 (China)", Size(130, 184)}, + {"D6 (China)", Size(92, 126)}, + + {"RD0 (China)", Size(787, 1092)}, + {"RD1 (China)", Size(546, 787)}, + {"RD2 (China)", Size(393, 546)}, + {"RD3 (China)", Size(273, 393)}, + {"RD4 (China)", Size(196, 273)}, + {"RD5 (China)", Size(136, 196)}, + {"RD6 (China)", Size(98, 136)}, + + {"CAN P1", Size(560, 860)}, + {"CAN P2", Size(430, 560)}, + {"CAN P3", Size(280, 430)}, + {"CAN P4", Size(215, 280)}, + {"CAN P5", Size(140, 215)}, + {"CAN P6", Size(107, 140)}, + + {"ANSI A", Size(216, 279)}, + {"ANSI B", Size(279, 432)}, + {"ANSI C", Size(432, 559)}, + {"ANSI D", Size(559, 864)}, + {"ANSI E", Size(864, 1118)}, + + {"Arch A/1", Size(229, 305)}, + {"Arch B/2", Size(305, 457)}, + {"Arch C/3", Size(457, 610)}, + {"Arch D/4", Size(610, 914)}, + {"Arch E/6", Size(914, 1219)}, + {"Arch E1/5", Size(762, 1067)}, + {"Arch E2", Size(660, 965)}, + {"Arch E3", Size(686, 991)}, + + {"B0 (JIS)", Size(1030, 1456)}, + {"B1 (JIS)", Size(728, 1030)}, + {"B2 (JIS)", Size(515, 728)}, + {"B3 (JIS)", Size(364, 515)}, + {"B4 (JIS)", Size(257, 364)}, + {"B5 (JIS)", Size(182, 257)}, + {"B6 (JIS)", Size(128, 182)}, + {"B7 (JIS)", Size(91, 128)}, + {"B8 (JIS)", Size(64, 91)}, + {"B9 (JIS)", Size(45, 64)}, + {"B10 (JIS)", Size(32, 45)}, + {"B11 (JIS)", Size(22, 32)}, + {"B12 (JIS)", Size(16, 22)}, + + {"F0", Size(841, 1321)}, + {"F1", Size(660, 841)}, + {"F2", Size(420, 660)}, + {"F3", Size(330, 420)}, + {"F4", Size(210, 330)}, + {"F5", Size(165, 210)}, + {"F6", Size(105, 165)}, + {"F7", Size(82, 105)}, + {"F8", Size(52, 82)}, + {"F9", Size(41, 52)}, + {"F10", Size(26, 41)}, + + // North American paper sizes + {"Letter", Size(216, 279)}, + {"Legal", Size(216, 356)}, + {"Tabloid", Size(279, 432)}, + {"Ledger", Size(432, 279)}, + {"Junior Legal", Size(127, 203)}, + {"Half Letter/Memo", Size(140, 216)}, + {"Government Letter", Size(203, 267)}, + {"Government Legal", Size(216, 330)}, + + // Traditional British paper sizes + {"Foolscap", Size(203, 330)}, + {"Quarto", Size(203, 254)}, + {"Imperial", Size(178, 229)}, + {"Kings", Size(165, 203)}, + {"Dukes", Size(140, 178)}, + + // Raw sizes + {"RA0", Size(860, 1220)}, + {"RA1", Size(610, 860)}, + {"RA2", Size(430, 610)}, + {"RA3", Size(305, 430)}, + {"RA4", Size(215, 305)}, + {"SRA0", Size(900, 1280)}, + {"SRA1", Size(640, 900)}, + {"SRA2", Size(450, 640)}, + {"SRA3", Size(320, 450)}, + {"SRA4", Size(225, 320)} }; diff --git a/common/PaperSize.hh b/common/PaperSize.hh index 117502c6..9aaa9f67 100644 --- a/common/PaperSize.hh +++ b/common/PaperSize.hh @@ -29,7 +29,7 @@ public: template struct Size { Size(T width_ = 0, T height_ = 0) : width(width_), height(height_) {} - bool operator<(const Size &val); + bool operator<(const Size& val); T width, height; }; diff --git a/formatSourceFiles.sh b/formatSourceFiles.sh index 1895935c..96f078f9 100755 --- a/formatSourceFiles.sh +++ b/formatSourceFiles.sh @@ -2,6 +2,6 @@ dir=$(dirname "$(readlink -f "$0")") which astyle &> /dev/null || ( echo "Please install astyle." && exit 1 ) -out=$(astyle --formatted --options=$dir/astyle.options $(find gtk qt \( -name '*.cc' -or -name '*.hh' \))) +out=$(astyle --formatted --options=$dir/astyle.options $(find gtk qt common \( -name '*.cc' -or -name '*.hh' \))) echo "$out" [ -z "$out" ] && exit 0 || exit 1