| 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 |
: QXP3HeaderBase(fileType) |
| 21 |
, m_type() |
| 22 |
, m_pagesCount(0) |
| 23 |
, m_masterPagesCount(0) |
| 24 |
, m_seed(0) |
| 25 |
, m_increment(0) |
| 26 |
, m_documentProperties() |
| 27 |
{ |
| 28 |
} |
| 29 |
|
| 30 |
bool QXP4Header::load(const std::shared_ptr<librevenge::RVNGInputStream> &input) |
| 31 |
{ |
| 32 |
QXP3HeaderBase::load(input); |
| 33 |
|
| 34 |
seek(input, 12); |
| 35 |
m_type = readString(input, 2); |
| 36 |
|
| 37 |
skip(input, 20); |
| 38 |
const uint16_t pagesCountObf = readU16(input, isBigEndian()); |
| 39 |
skip(input, 41); |
| 40 |
m_masterPagesCount = readU8(input); |
| 41 |
|
| 42 |
seek(input, 0x52); |
| 43 |
m_increment = readU16(input, !isLittleEndian()); |
| 44 |
|
| 45 |
seek(input, 0x58); |
| 46 |
m_documentProperties.setAutoLeading(readFraction(input, isBigEndian())); |
| 47 |
|
| 48 |
seek(input, 0x80); |
| 49 |
m_seed = readU16(input, !isLittleEndian()); |
| 50 |
|
| 51 |
QXP4Deobfuscator deobfuscate(m_seed, m_increment); |
| 52 |
const unsigned pagesCount = deobfuscate(pagesCountObf); |
| 53 |
m_pagesCount = (pagesCount & 0xfffc) | ((pagesCount & 0x3) ^ 0x3); |
| 54 |
|
| 55 |
seekRelative(input, 42); |
| 56 |
m_documentProperties.superscriptOffset = readFraction(input, isBigEndian()); |
| 57 |
m_documentProperties.superscriptHScale = readFraction(input, isBigEndian()); |
| 58 |
m_documentProperties.superscriptVScale = readFraction(input, isBigEndian()); |
| 59 |
m_documentProperties.subscriptOffset = -readFraction(input, isBigEndian()); |
| 60 |
m_documentProperties.subscriptHScale = readFraction(input, isBigEndian()); |
| 61 |
m_documentProperties.subscriptVScale = readFraction(input, isBigEndian()); |
| 62 |
m_documentProperties.superiorHScale = readFraction(input, isBigEndian()); |
| 63 |
m_documentProperties.superiorVScale = readFraction(input, isBigEndian()); |
| 64 |
|
| 65 |
seek(input, 512); |
| 66 |
|
| 67 |
return true; |
| 68 |
} |
| 69 |
|
| 70 |
QXPDocument::Type QXP4Header::getType() const |
| 71 |
{ |
| 72 |
if (m_fileType) |
| 73 |
return get(m_fileType); |
| 74 |
|
| 75 |
if (m_type == "BK") |
| 76 |
return QXPDocument::TYPE_BOOK; |
| 77 |
else if (m_type == "DC") |
| 78 |
return QXPDocument::TYPE_DOCUMENT; |
| 79 |
else if (m_type == "LB") |
| 80 |
return QXPDocument::TYPE_LIBRARY; |
| 81 |
else if (m_type == "TP") |
| 82 |
return QXPDocument::TYPE_TEMPLATE; |
| 83 |
else |
| 84 |
return QXPDocument::TYPE_UNKNOWN; |
| 85 |
} |
| 86 |
|
| 87 |
std::unique_ptr<QXPParser> QXP4Header::createParser(const std::shared_ptr<librevenge::RVNGInputStream> &input, librevenge::RVNGDrawingInterface *painter) |
| 88 |
{ |
| 89 |
return std::unique_ptr<QXPParser>(new QXP4Parser(input, painter, shared_from_this())); |
| 90 |
} |
| 91 |
|
| 92 |
uint16_t QXP4Header::pagesCount() const |
| 93 |
{ |
| 94 |
return m_pagesCount; |
| 95 |
} |
| 96 |
|
| 97 |
uint16_t QXP4Header::masterPagesCount() const |
| 98 |
{ |
| 99 |
return m_masterPagesCount; |
| 100 |
} |
| 101 |
|
| 102 |
uint16_t QXP4Header::seed() const |
| 103 |
{ |
| 104 |
return m_seed; |
| 105 |
} |
| 106 |
|
| 107 |
uint16_t QXP4Header::increment() const |
| 108 |
{ |
| 109 |
return m_increment; |
| 110 |
} |
| 111 |
|
| 112 |
const QXPDocumentProperties &QXP4Header::documentProperties() const |
| 113 |
{ |
| 114 |
return m_documentProperties; |
| 115 |
} |
| 116 |
|
| 117 |
} |
| 118 |
|
| 119 |
/* vim:set shiftwidth=2 softtabstop=2 expandtab: */ |