| 1 |
/* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */ |
| 2 |
|
| 3 |
/* libmwaw |
| 4 |
* Version: MPL 2.0 / LGPLv2+ |
| 5 |
* |
| 6 |
* The contents of this file are subject to the Mozilla Public License Version |
| 7 |
* 2.0 (the "License"); you may not use this file except in compliance with |
| 8 |
* the License or as specified alternatively below. You may obtain a copy of |
| 9 |
* the License at http://www.mozilla.org/MPL/ |
| 10 |
* |
| 11 |
* Software distributed under the License is distributed on an "AS IS" basis, |
| 12 |
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License |
| 13 |
* for the specific language governing rights and limitations under the |
| 14 |
* License. |
| 15 |
* |
| 16 |
* Major Contributor(s): |
| 17 |
* Copyright (C) 2002 William Lachance ([email protected]) |
| 18 |
* Copyright (C) 2002,2004 Marc Maurer ([email protected]) |
| 19 |
* Copyright (C) 2004-2006 Fridrich Strba ([email protected]) |
| 20 |
* Copyright (C) 2006, 2007 Andrew Ziem |
| 21 |
* Copyright (C) 2011, 2012 Alonso Laurent ([email protected]) |
| 22 |
* |
| 23 |
* |
| 24 |
* All Rights Reserved. |
| 25 |
* |
| 26 |
* For minor contributions see the git repository. |
| 27 |
* |
| 28 |
* Alternatively, the contents of this file may be used under the terms of |
| 29 |
* the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"), |
| 30 |
* in which case the provisions of the LGPLv2+ are applicable |
| 31 |
* instead of those above. |
| 32 |
*/ |
| 33 |
|
| 34 |
#ifndef NISUS_WRT_STRUCT |
| 35 |
# define NISUS_WRT_STRUCT |
| 36 |
|
| 37 |
#include <iostream> |
| 38 |
#include <vector> |
| 39 |
|
| 40 |
#include "libmwaw_internal.hxx" |
| 41 |
|
| 42 |
#include "MWAWEntry.hxx" |
| 43 |
|
| 44 |
class NisusWrtParser; |
| 45 |
|
| 46 |
/** a namespace used to regroup the different structure used to parse a Nisus File */ |
| 47 |
namespace NisusWrtStruct |
| 48 |
{ |
| 49 |
/** the different zone */ |
| 50 |
enum ZoneType : unsigned { Z_Main=0, Z_Footnote, Z_HeaderFooter }; |
| 51 |
|
| 52 |
/** the different variable type */ |
| 53 |
enum VariableType { V_None=0, V_Numbering, V_Variable, V_Version }; |
| 54 |
|
| 55 |
/** a position */ |
| 56 |
struct Position { |
| 57 |
//! the constructor |
| 58 |
Position() |
| 59 |
: m_paragraph(0) |
| 60 |
, m_word(0) |
| 61 |
, m_char(0) |
| 62 |
{ |
| 63 |
} |
| 64 |
//! operator<<: prints data in form "XxYxZ" |
| 65 |
friend std::ostream &operator<< (std::ostream &o, Position const &pos); |
| 66 |
|
| 67 |
//! operator== |
| 68 |
bool operator==(Position const &p2) const |
| 69 |
{ |
| 70 |
return cmp(p2)==0; |
| 71 |
} |
| 72 |
//! operator!= |
| 73 |
bool operator!=(Position const &p2) const |
| 74 |
{ |
| 75 |
return cmp(p2)!=0; |
| 76 |
} |
| 77 |
//! a small compare operator |
| 78 |
int cmp(Position const &p2) const |
| 79 |
{ |
| 80 |
if (m_paragraph < p2.m_paragraph) return -1; |
| 81 |
if (m_paragraph > p2.m_paragraph) return 1; |
| 82 |
if (m_word < p2.m_word) return -1; |
| 83 |
if (m_word > p2.m_word) return 1; |
| 84 |
if (m_char < p2.m_char) return -1; |
| 85 |
if (m_char > p2.m_char) return 1; |
| 86 |
return 0; |
| 87 |
} |
| 88 |
/** the paragraph */ |
| 89 |
int m_paragraph; |
| 90 |
/** the word */ |
| 91 |
int m_word; |
| 92 |
/** the character position */ |
| 93 |
int m_char; |
| 94 |
|
| 95 |
//! a comparaison structure used to sort the position |
| 96 |
struct Compare { |
| 97 |
//! comparaison function |
| 98 |
bool operator()(Position const &p1, Position const &p2) const |
| 99 |
{ |
| 100 |
return p1.cmp(p2) < 0; |
| 101 |
} |
| 102 |
}; |
| 103 |
}; |
| 104 |
|
| 105 |
//////////////////////////////////////// |
| 106 |
// Internal: low level |
| 107 |
|
| 108 |
/** Internal: low level a structure helping to store the footnote information */ |
| 109 |
struct FootnoteInfo { |
| 110 |
//! constructor |
| 111 |
FootnoteInfo() |
| 112 |
: m_flags(0) |
| 113 |
, m_distToDocument(5) |
| 114 |
, m_distSeparator(36) |
| 115 |
, m_separatorLength(108) |
| 116 |
, m_unknown(0) |
| 117 |
{ |
| 118 |
} |
| 119 |
//! operator<<: prints data |
| 120 |
friend std::ostream &operator<< (std::ostream &o, FootnoteInfo const &fnote); |
| 121 |
|
| 122 |
//! returns true if we have endnote |
| 123 |
bool endNotes() const |
| 124 |
{ |
| 125 |
return (m_flags&0x8)!=0; |
| 126 |
} |
| 127 |
//! returns true if we have to reset index at the beginning of a page |
| 128 |
bool resetNumberOnNewPage() const |
| 129 |
{ |
| 130 |
return (m_flags&0x8)==0 && (m_flags&0x10); |
| 131 |
} |
| 132 |
//! the footnote flags |
| 133 |
int m_flags; |
| 134 |
//! the distance between the footnote and the document |
| 135 |
int m_distToDocument; |
| 136 |
//! the distance between two footnotes ( or between a footnote and the line sep) |
| 137 |
int m_distSeparator; |
| 138 |
//! the separator length |
| 139 |
int m_separatorLength; |
| 140 |
//! a unknown value |
| 141 |
int m_unknown; |
| 142 |
}; |
| 143 |
|
| 144 |
/** Internal: low level a structure helping to read recursifList */ |
| 145 |
struct RecursifData { |
| 146 |
struct Node; |
| 147 |
struct Info; |
| 148 |
//! constructor |
| 149 |
explicit RecursifData(NisusWrtStruct::ZoneType zone, NisusWrtStruct::VariableType vType=NisusWrtStruct::V_None, int level=0) |
| 150 |
: m_info(new Info(zone, vType)) |
| 151 |
, m_level(level) |
| 152 |
, m_childList() |
| 153 |
{ |
| 154 |
} |
| 155 |
//! copy constructor |
| 156 |
RecursifData(RecursifData const &orig) |
| 157 |
: m_info(orig.m_info) |
| 158 |
, m_level(-1) |
| 159 |
, m_childList() |
| 160 |
{ |
| 161 |
} |
| 162 |
//! copy operator |
| 163 |
RecursifData &operator=(RecursifData const &orig) |
| 164 |
{ |
| 165 |
if (this != &orig) { |
| 166 |
m_info = orig.m_info; |
| 167 |
m_level = orig.m_level; |
| 168 |
m_childList = orig.m_childList; |
| 169 |
} |
| 170 |
return *this; |
| 171 |
} |
| 172 |
//! read the data |
| 173 |
bool read(NisusWrtParser &parser, MWAWEntry const &entry); |
| 174 |
|
| 175 |
//! zone information |
| 176 |
std::shared_ptr<Info> m_info; |
| 177 |
//! the node level |
| 178 |
int m_level; |
| 179 |
//! the list of data entry |
| 180 |
std::vector<Node> m_childList; |
| 181 |
|
| 182 |
//! the zone information |
| 183 |
struct Info { |
| 184 |
//! the constructor |
| 185 |
explicit Info(NisusWrtStruct::ZoneType zType, NisusWrtStruct::VariableType vType=NisusWrtStruct::V_None) |
| 186 |
: m_zoneType(zType) |
| 187 |
, m_variableType(vType) |
| 188 |
{ |
| 189 |
} |
| 190 |
//! the zone id |
| 191 |
NisusWrtStruct::ZoneType m_zoneType; |
| 192 |
//! the variable type |
| 193 |
NisusWrtStruct::VariableType m_variableType; |
| 194 |
}; |
| 195 |
//! the data data |
| 196 |
struct Node { |
| 197 |
//! constructor |
| 198 |
Node() |
| 199 |
: m_type(0) |
| 200 |
, m_entry() |
| 201 |
, m_data() |
| 202 |
{ |
| 203 |
} |
| 204 |
//! returns true if the node is a final node |
| 205 |
bool isLeaf() const |
| 206 |
{ |
| 207 |
return !m_data; |
| 208 |
} |
| 209 |
|
| 210 |
//! the variable type |
| 211 |
int m_type; |
| 212 |
//! the entry |
| 213 |
MWAWEntry m_entry; |
| 214 |
//! the recursif data |
| 215 |
std::shared_ptr<RecursifData> m_data; |
| 216 |
}; |
| 217 |
}; |
| 218 |
} |
| 219 |
|
| 220 |
#endif |
| 221 |
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: |