| 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 |
/* |
| 35 |
* Class to read/store the text font and paragraph styles |
| 36 |
*/ |
| 37 |
|
| 38 |
#ifndef MS_WRD_TEXT_STYLES |
| 39 |
# define MS_WRD_TEXT_STYLES |
| 40 |
|
| 41 |
#include <iostream> |
| 42 |
#include <map> |
| 43 |
#include <string> |
| 44 |
|
| 45 |
#include "libmwaw_internal.hxx" |
| 46 |
|
| 47 |
#include "MWAWEntry.hxx" |
| 48 |
#include "MWAWParagraph.hxx" |
| 49 |
|
| 50 |
struct MsWrdEntry; |
| 51 |
class MsWrdParser; |
| 52 |
class MsWrdText; |
| 53 |
|
| 54 |
namespace MsWrdStruct |
| 55 |
{ |
| 56 |
struct Font; |
| 57 |
struct Paragraph; |
| 58 |
struct Section; |
| 59 |
} |
| 60 |
|
| 61 |
namespace MsWrdTextStylesInternal |
| 62 |
{ |
| 63 |
struct State; |
| 64 |
} |
| 65 |
|
| 66 |
/** \brief the main class to read/store the text font, paragraph, section stylesread */ |
| 67 |
class MsWrdTextStyles |
| 68 |
{ |
| 69 |
friend class MsWrdText; |
| 70 |
public: |
| 71 |
enum ZoneType { TextZone, TextStructZone, StyleZone, InParagraphDefinition }; |
| 72 |
//! constructor |
| 73 |
explicit MsWrdTextStyles(MsWrdText &textParser); |
| 74 |
//! destructor |
| 75 |
virtual ~MsWrdTextStyles(); |
| 76 |
|
| 77 |
/** returns the file version */ |
| 78 |
int version() const; |
| 79 |
|
| 80 |
protected: |
| 81 |
// font: |
| 82 |
//! returns the default font |
| 83 |
MWAWFont const &getDefaultFont() const; |
| 84 |
//! return a font corresponding to an index |
| 85 |
bool getFont(ZoneType type, int id, MsWrdStruct::Font &actFont); |
| 86 |
|
| 87 |
/* send a font */ |
| 88 |
void setProperty(MsWrdStruct::Font const &font); |
| 89 |
/** try to read a font. |
| 90 |
\param font : the read font, |
| 91 |
\param type : the zone in which the font is read */ |
| 92 |
bool readFont(MsWrdStruct::Font &font, ZoneType type); |
| 93 |
|
| 94 |
// pararagraph: |
| 95 |
//! return a paragraph corresponding to an index |
| 96 |
bool getParagraph(ZoneType type, int id, MsWrdStruct::Paragraph ¶); |
| 97 |
//! try to read a paragraph |
| 98 |
bool readParagraph(MsWrdStruct::Paragraph ¶, int dataSz=-1); |
| 99 |
//! send a default paragraph |
| 100 |
void sendDefaultParagraph(); |
| 101 |
|
| 102 |
//! read the main char/paragraph plc list |
| 103 |
bool readPLCList(MsWrdEntry const &entry); |
| 104 |
//! read the paragraphs at the beginning of the text structure zone |
| 105 |
bool readTextStructList(MsWrdEntry &entry); |
| 106 |
/** read the property modifier (2 bytes last bytes of text struct ). |
| 107 |
Returns a textstruct parag id or -1 (PRM) */ |
| 108 |
int readPropertyModifier(bool &complex, std::string &extra); |
| 109 |
//! read the char/paragraph plc : type=0: char, type=1: parag |
| 110 |
bool readPLC(MsWrdEntry &entry, int type, MWAWVec2<long> const &fileLimit); |
| 111 |
|
| 112 |
// section: |
| 113 |
//! return a section corresponding to an index |
| 114 |
bool getSection(ZoneType type, int id, MsWrdStruct::Section §ion); |
| 115 |
//! return a paragraph corresponding to the section |
| 116 |
bool getSectionParagraph(ZoneType type, int id, MsWrdStruct::Paragraph ¶); |
| 117 |
//! return a font corresponding to the section |
| 118 |
bool getSectionFont(ZoneType type, int id, MsWrdStruct::Font &font); |
| 119 |
//! read the text section |
| 120 |
bool readSection(MsWrdEntry &entry, std::vector<long> &cLimits); |
| 121 |
//! try to send a section |
| 122 |
bool sendSection(int id, int textStructId); |
| 123 |
|
| 124 |
//! try to read the section data |
| 125 |
bool readSection(MsWrdStruct::Section §ion, long pos); |
| 126 |
//! send section properties |
| 127 |
void setProperty(MsWrdStruct::Section const &sec); |
| 128 |
|
| 129 |
// style |
| 130 |
//! try to read the styles zone |
| 131 |
bool readStyles(MsWrdEntry &entry); |
| 132 |
//! try to read the styles hierachy |
| 133 |
bool readStylesHierarchy(MsWrdEntry &entry, int N, std::vector<int> &orig); |
| 134 |
//! try to read the styles names and fill the number of "named" styles... |
| 135 |
bool readStylesNames(MsWrdEntry const &zone, int N, int &Nnamed); |
| 136 |
//! try to read the styles fonts |
| 137 |
bool readStylesFont(MsWrdEntry &zone, int N, std::vector<int> const &previous, |
| 138 |
std::vector<int> const &order); |
| 139 |
//! try to read the styles fonts |
| 140 |
bool readStylesParagraph(MsWrdEntry &zone, int N, std::vector<int> const &previous, |
| 141 |
std::vector<int> const &order); |
| 142 |
//! returns the style id to next style id map |
| 143 |
std::map<int,int> const &getNextStyleMap() const; |
| 144 |
//! try to reorder the styles to find a good order |
| 145 |
static std::vector<int> orderStyles(std::vector<int> const &previous); |
| 146 |
|
| 147 |
private: |
| 148 |
MsWrdTextStyles(MsWrdTextStyles const &orig) = delete; |
| 149 |
MsWrdTextStyles &operator=(MsWrdTextStyles const &orig) = delete; |
| 150 |
|
| 151 |
protected: |
| 152 |
// |
| 153 |
// data |
| 154 |
// |
| 155 |
//! the parser state |
| 156 |
MWAWParserStatePtr m_parserState; |
| 157 |
|
| 158 |
//! the state |
| 159 |
std::shared_ptr<MsWrdTextStylesInternal::State> m_state; |
| 160 |
|
| 161 |
//! the main parser; |
| 162 |
MsWrdParser *m_mainParser; |
| 163 |
|
| 164 |
//! the text parser; |
| 165 |
MsWrdText *m_textParser; |
| 166 |
}; |
| 167 |
#endif |
| 168 |
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab: |