/src/libqxp/src/lib/QXP4Header.cpp
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* |
3 | | * This file is part of the libqxp project. |
4 | | * |
5 | | * This Source Code Form is subject to the terms of the Mozilla Public |
6 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
7 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
8 | | */ |
9 | | |
10 | | #include "QXP4Header.h" |
11 | | |
12 | | #include "QXP4Deobfuscator.h" |
13 | | #include "QXP4Parser.h" |
14 | | #include "libqxp_utils.h" |
15 | | |
16 | | namespace libqxp |
17 | | { |
18 | | |
19 | | QXP4Header::QXP4Header(const boost::optional<QXPDocument::Type> &fileType) |
20 | 2.18k | : QXP3HeaderBase(fileType) |
21 | 2.18k | , m_type() |
22 | 2.18k | , m_pagesCount(0) |
23 | 2.18k | , m_masterPagesCount(0) |
24 | 2.18k | , m_seed(0) |
25 | 2.18k | , m_increment(0) |
26 | 2.18k | , m_documentProperties() |
27 | 2.18k | { |
28 | 2.18k | } |
29 | | |
30 | | bool QXP4Header::load(const std::shared_ptr<librevenge::RVNGInputStream> &input) |
31 | 2.18k | { |
32 | 2.18k | QXP3HeaderBase::load(input); |
33 | | |
34 | 2.18k | seek(input, 12); |
35 | 2.18k | m_type = readString(input, 2); |
36 | | |
37 | 2.18k | skip(input, 20); |
38 | 2.18k | const uint16_t pagesCountObf = readU16(input, isBigEndian()); |
39 | 2.18k | skip(input, 41); |
40 | 2.18k | m_masterPagesCount = readU8(input); |
41 | | |
42 | 2.18k | seek(input, 0x52); |
43 | 2.18k | m_increment = readU16(input, !isLittleEndian()); |
44 | | |
45 | 2.18k | seek(input, 0x58); |
46 | 2.18k | m_documentProperties.setAutoLeading(readFraction(input, isBigEndian())); |
47 | | |
48 | 2.18k | seek(input, 0x80); |
49 | 2.18k | m_seed = readU16(input, !isLittleEndian()); |
50 | | |
51 | 2.18k | QXP4Deobfuscator deobfuscate(m_seed, m_increment); |
52 | 2.18k | const unsigned pagesCount = deobfuscate(pagesCountObf); |
53 | 2.18k | m_pagesCount = (pagesCount & 0xfffc) | ((pagesCount & 0x3) ^ 0x3); |
54 | | |
55 | 2.18k | seekRelative(input, 42); |
56 | 2.18k | m_documentProperties.superscriptOffset = readFraction(input, isBigEndian()); |
57 | 2.18k | m_documentProperties.superscriptHScale = readFraction(input, isBigEndian()); |
58 | 2.18k | m_documentProperties.superscriptVScale = readFraction(input, isBigEndian()); |
59 | 2.18k | m_documentProperties.subscriptOffset = -readFraction(input, isBigEndian()); |
60 | 2.18k | m_documentProperties.subscriptHScale = readFraction(input, isBigEndian()); |
61 | 2.18k | m_documentProperties.subscriptVScale = readFraction(input, isBigEndian()); |
62 | 2.18k | m_documentProperties.superiorHScale = readFraction(input, isBigEndian()); |
63 | 2.18k | m_documentProperties.superiorVScale = readFraction(input, isBigEndian()); |
64 | | |
65 | 2.18k | seek(input, 512); |
66 | | |
67 | 2.18k | return true; |
68 | 2.18k | } |
69 | | |
70 | | QXPDocument::Type QXP4Header::getType() const |
71 | 2.14k | { |
72 | 2.14k | if (m_fileType) |
73 | 0 | return get(m_fileType); |
74 | | |
75 | 2.14k | if (m_type == "BK") |
76 | 1 | return QXPDocument::TYPE_BOOK; |
77 | 2.14k | else if (m_type == "DC") |
78 | 2.03k | return QXPDocument::TYPE_DOCUMENT; |
79 | 108 | else if (m_type == "LB") |
80 | 2 | return QXPDocument::TYPE_LIBRARY; |
81 | 106 | else if (m_type == "TP") |
82 | 81 | return QXPDocument::TYPE_TEMPLATE; |
83 | 25 | else |
84 | 25 | return QXPDocument::TYPE_UNKNOWN; |
85 | 2.14k | } |
86 | | |
87 | | std::unique_ptr<QXPParser> QXP4Header::createParser(const std::shared_ptr<librevenge::RVNGInputStream> &input, librevenge::RVNGDrawingInterface *painter) |
88 | 2.11k | { |
89 | 2.11k | return std::unique_ptr<QXPParser>(new QXP4Parser(input, painter, shared_from_this())); |
90 | 2.11k | } |
91 | | |
92 | | uint16_t QXP4Header::pagesCount() const |
93 | 4.47k | { |
94 | 4.47k | return m_pagesCount; |
95 | 4.47k | } |
96 | | |
97 | | uint16_t QXP4Header::masterPagesCount() const |
98 | 8.93k | { |
99 | 8.93k | return m_masterPagesCount; |
100 | 8.93k | } |
101 | | |
102 | | uint16_t QXP4Header::seed() const |
103 | 1.47k | { |
104 | 1.47k | return m_seed; |
105 | 1.47k | } |
106 | | |
107 | | uint16_t QXP4Header::increment() const |
108 | 1.47k | { |
109 | 1.47k | return m_increment; |
110 | 1.47k | } |
111 | | |
112 | | const QXPDocumentProperties &QXP4Header::documentProperties() const |
113 | 2.11k | { |
114 | 2.11k | return m_documentProperties; |
115 | 2.11k | } |
116 | | |
117 | | } |
118 | | |
119 | | /* vim:set shiftwidth=2 softtabstop=2 expandtab: */ |