MsWrdStruct.hxx
Go to the documentation of this file.
/* -*- Mode: C++; c-default-style: "k&r"; indent-tabs-mode: nil; tab-width: 2; c-basic-offset: 2 -*- */
/* libmwaw
* Version: MPL 2.0 / LGPLv2+
*
* The contents of this file are subject to the Mozilla Public License Version
* 2.0 (the "License"); you may not use this file except in compliance with
* the License or as specified alternatively below. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* Major Contributor(s):
* Copyright (C) 2002 William Lachance (wrlach@gmail.com)
* Copyright (C) 2002,2004 Marc Maurer (uwog@uwog.net)
* Copyright (C) 2004-2006 Fridrich Strba (fridrich.strba@bluewin.ch)
* Copyright (C) 2006, 2007 Andrew Ziem
* Copyright (C) 2011, 2012 Alonso Laurent (alonso@loria.fr)
*
*
* All Rights Reserved.
*
* For minor contributions see the git repository.
*
* Alternatively, the contents of this file may be used under the terms of
* the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"),
* in which case the provisions of the LGPLv2+ are applicable
* instead of those above.
*/
/*
* Class to read/store the MsWrd structures
*/
#ifndef MS_WRD_STRUCT
# define MS_WRD_STRUCT
#include <iostream>
#include <string>
#include <vector>
#include "libmwaw_internal.hxx"
#include "MWAWFont.hxx"
#include "MWAWParagraph.hxx"
namespace MsWrdStruct
{
MWAWBorder getBorder(int val, std::string &extra);
struct Font {
enum { NumFlags =9 };
Font()
: m_font(MWAWFont(-1,0))
, m_size(0)
, m_value(0)
, m_picturePos(0)
, m_unknown(0)
, m_extra("")
{
for (auto &fl : m_flags) fl=MWAWVariable<int>(0);
}
Font(Font const &)=default;
Font &operator=(Font const &)=default;
void insert(Font const &font, Font const *styleFont=nullptr);
void updateFontToFinalState(Font const *styleFont=nullptr);
friend std::ostream &operator<<(std::ostream &o, Font const &font);
int cmp(Font const &oth) const
{
int diff = m_font.get().cmp(oth.m_font.get());
if (diff) return diff;
if (m_size.get() < oth.m_size.get()) return -1;
if (m_size.get() > oth.m_size.get()) return 1;
diff = m_value.get()-oth.m_value.get();
if (diff) return diff;
for (int i = 0; i < NumFlags; i++) {
diff = m_flags[i].get()-oth.m_flags[i].get();
if (diff) return diff;
}
if (m_picturePos.get()<oth.m_picturePos.get()) return -1;
if (m_picturePos.get()>oth.m_picturePos.get()) return 1;
diff = m_unknown.get()-oth.m_unknown.get();
if (diff) return diff;
return 0;
}
MWAWVariable<MWAWFont> m_font;
MWAWVariable<float> m_size;
MWAWVariable<int> m_value;
MWAWVariable<int> m_flags[NumFlags];
MWAWVariable<long> m_picturePos;
MWAWVariable<int> m_unknown;
std::string m_extra;
};
struct Section {
Section()
: m_id(-1)
, m_type(0)
, m_paragraphId(-9999)
, m_col(1)
, m_colSep(0.5)
, m_colBreak(false)
, m_flag(0)
, m_extra("")
{
}
MWAWSection getSection(double pageWidth) const;
void insert(Section const &sec)
{
m_id.insert(sec.m_id);
m_type.insert(sec.m_type);
m_paragraphId.insert(sec.m_paragraphId);
m_col.insert(sec.m_col);
m_colSep.insert(sec.m_colSep);
m_colBreak.insert(sec.m_colBreak);
m_flag.insert(sec.m_flag);
m_extra+=sec.m_extra;
}
bool read(MWAWInputStreamPtr &input, long endPos);
bool readV3(MWAWInputStreamPtr &input, long endPos);
friend std::ostream &operator<<(std::ostream &o, Section const &section);
MWAWVariable<int> m_id;
MWAWVariable<int> m_type;
MWAWVariable<int> m_paragraphId;
MWAWVariable<int> m_col;
MWAWVariable<float> m_colSep;
MWAWVariable<bool> m_colBreak;
MWAWVariable<int> m_flag;
std::string m_extra;
};
struct Table {
struct Cell;
Table()
: m_height(0)
, m_justify(MWAWParagraph::JustificationLeft)
, m_indent(0)
, m_columns()
, m_columnsWidthMod()
, m_cells()
, m_badCell()
, m_extra("")
{
}
void insert(Table const &table);
bool read(MWAWInputStreamPtr &input, long endPos);
MWAWVariable<Cell> &getCell(int id);
friend std::ostream &operator<<(std::ostream &o, Table const &table);
struct Cell {
Cell()
: m_borders()
, m_backColor(1.0f)
, m_extra("")
{
}
void insert(Cell const &cell)
{
size_t cNumBorders = cell.m_borders.size();
if (cNumBorders > m_borders.size())
m_borders.resize(cNumBorders);
for (size_t i=0; i < cNumBorders; i++)
if (cell.m_borders[i].isSet()) m_borders[i]=*cell.m_borders[i];
m_backColor.insert(cell.m_backColor);
m_extra+=cell.m_extra;
}
bool hasBorders() const
{
for (auto const &bd : m_borders)
if (bd.isSet() && bd->m_style != MWAWBorder::None)
return true;
return false;
}
friend std::ostream &operator<<(std::ostream &o, Cell const &cell);
std::vector<MWAWVariable<MWAWBorder> > m_borders;
MWAWVariable<float> m_backColor;
std::string m_extra;
};
MWAWVariable<float> m_height;
MWAWVariable<MWAWParagraph::Justification> m_justify;
MWAWVariable<float> m_indent;
MWAWVariable<std::vector<float> > m_columns;
MWAWVariable<std::vector<float> > m_columnsWidthMod;
std::vector<MWAWVariable<Cell> > m_cells;
MWAWVariable<Cell> m_badCell;
std::string m_extra;
};
struct ParagraphInfo {
ParagraphInfo()
: m_type(0)
, m_dim()
, m_numLines(-1)
, m_error("")
{
}
bool isLineSet() const
{
return *m_numLines!=0;
}
bool isEmpty() const
{
if (*m_numLines || *m_type) return false;
if (!m_dim.isSet()) return true;
if ((*m_dim)[0] > 0 || (*m_dim)[1] > 0) return false;
return true;
}
bool read(MWAWInputStreamPtr &input, long endPos, int vers);
friend std::ostream &operator<<(std::ostream &o, ParagraphInfo const &pInfo)
{
// find also pInfo.m_type&0x40 : ?
if (*pInfo.m_type&0xd0) o << "type?=" << ((*pInfo.m_type&0xd0)>>4) << ",";
if (*pInfo.m_type&0x0f) o << "#unkn=" << (*pInfo.m_type&0xf) << ",";
if (pInfo.m_dim.isSet()) {
if ((*pInfo.m_dim)[0] > 0)
o << "width=" << (*pInfo.m_dim)[0] << ",";
if ((*pInfo.m_dim)[1] > 0) {
o << "height=" << (*pInfo.m_dim)[1];
if (*pInfo.m_type&0x20)
o << "[total]";
o << ",";
}
}
if (pInfo.m_numLines.isSet() && *pInfo.m_numLines!=-1 && *pInfo.m_numLines!=1)
o << "nLines=" << *pInfo.m_numLines << ",";
if (pInfo.m_error.length()) o << pInfo.m_error << ",";
return o;
}
void insert(ParagraphInfo const &pInfo);
MWAWVariable<int> m_type;
MWAWVariable<MWAWVec2f> m_dim;
MWAWVariable<int> m_numLines;
std::string m_error;
};
struct Paragraph final : public MWAWParagraph {
explicit Paragraph(int version)
: MWAWParagraph()
, m_version(version)
, m_styleId(-1000)
, m_interline(0)
, m_deletedTabs()
, m_info()
, m_font()
, m_modFont()
, m_section()
, m_bordersStyle()
, m_inCell(false)
, m_tableDef(false)
, m_table()
{
m_tabsRelativeToLeftMargin=false;
}
Paragraph(Paragraph const &)=default;
Paragraph &operator=(Paragraph const &)=default;
Paragraph &operator=(Paragraph &&)=default;
~Paragraph() final;
void insert(Paragraph const &para, bool insertModif=true);
bool read(MWAWInputStreamPtr &input, long endPos);
void updateParagraphToFinalState(Paragraph const *style=nullptr);
bool getFont(Font &font, Font const *styleFont=nullptr) const;
bool inTable() const
{
return m_inCell.get();
}
friend std::ostream &operator<<(std::ostream &o, Paragraph const &ind);
void print(std::ostream &o, MWAWFontConverterPtr converter) const;
int getNumLines() const
{
return m_info.get().m_numLines.get();
}
int m_version;
MWAWVariable<int> m_styleId;
MWAWVariable<double> m_interline;
std::vector<float> m_deletedTabs;
MWAWVariable<ParagraphInfo> m_info;
MWAWVariable<Font> m_font, m_modFont ;
MWAWVariable<Section> m_section;
MWAWVariable<MWAWBorder> m_bordersStyle;
MWAWVariable<bool> m_inCell;
MWAWVariable<bool> m_tableDef;
MWAWVariable<Table> m_table;
};
}
#endif
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
MWAWFont.hxx
MWAWParagraph.hxx
MWAWFont
Class to store font.
Definition MWAWFont.hxx:44
MWAWParagraph
class to store the paragraph properties
Definition MWAWParagraph.hxx:85
MWAWParagraph::m_tabsRelativeToLeftMargin
MWAWVariable< bool > m_tabsRelativeToLeftMargin
true if the tabs are relative to left margin, false if there are relative to the page margin (default...
Definition MWAWParagraph.hxx:164
MWAWParagraph::MWAWParagraph
MWAWParagraph()
constructor
Definition MWAWParagraph.cxx:145
MWAWSection
a class which stores section properties
Definition MWAWSection.hxx:46
libmwaw_internal.hxx
MWAWFontConverterPtr
std::shared_ptr< MWAWFontConverter > MWAWFontConverterPtr
a smart pointer of MWAWFontConverter
Definition libmwaw_internal.hxx:545
MWAWInputStreamPtr
std::shared_ptr< MWAWInputStream > MWAWInputStreamPtr
a smart pointer of MWAWInputStream
Definition libmwaw_internal.hxx:551
MsWrdStruct
namespace to store the main structure which appears in a Microsoft Word 3.0-5.0 file
Definition MsWrdStruct.cxx:42
MsWrdStruct::getBorder
MWAWBorder getBorder(int val, std::string &extra)
generic function use to fill a border using the read data
Definition MsWrdStruct.cxx:1207
MWAWBorder::None
@ None
Definition libmwaw_internal.hxx:335
MWAWVariable
a generic variable template: value + flag to know if the variable is set
Definition libmwaw_internal.hxx:577
MWAWVariable::isSet
bool isSet() const
return true if the variable is set
Definition libmwaw_internal.hxx:635
MWAWVariable::get
T const & get() const
return the current value
Definition libmwaw_internal.hxx:630
MsWrdStruct::Font
the font structure of a Microsoft Word file
Definition MsWrdStruct.hxx:57
MsWrdStruct::Font::m_flags
MWAWVariable< int > m_flags[NumFlags]
a list of flags
Definition MsWrdStruct.hxx:108
MsWrdStruct::Font::m_picturePos
MWAWVariable< long > m_picturePos
a picture file position (if this corresponds to a picture)
Definition MsWrdStruct.hxx:110
MsWrdStruct::Font::m_size
MWAWVariable< float > m_size
a second size
Definition MsWrdStruct.hxx:104
MsWrdStruct::Font::operator<<
friend std::ostream & operator<<(std::ostream &o, Font const &font)
operator<<
Definition MsWrdStruct.cxx:44
MsWrdStruct::Font::cmp
int cmp(Font const &oth) const
a comparison function
Definition MsWrdStruct.hxx:83
MsWrdStruct::Font::m_extra
std::string m_extra
extra data
Definition MsWrdStruct.hxx:114
MsWrdStruct::Font::insert
void insert(Font const &font, Font const *styleFont=nullptr)
insert new font data ( beginning by updating font flags )
Definition MsWrdStruct.cxx:83
MsWrdStruct::Font::m_value
MWAWVariable< int > m_value
a unknown value
Definition MsWrdStruct.hxx:106
MsWrdStruct::Font::operator=
Font & operator=(Font const &)=default
MsWrdStruct::Font::Font
Font(Font const &)=default
MsWrdStruct::Font::updateFontToFinalState
void updateFontToFinalState(Font const *styleFont=nullptr)
update the font to obtain the final font
Definition MsWrdStruct.cxx:99
MsWrdStruct::Font::NumFlags
@ NumFlags
the number of flags needed to store all datas
Definition MsWrdStruct.hxx:58
MsWrdStruct::Font::m_unknown
MWAWVariable< int > m_unknown
some unknown flag
Definition MsWrdStruct.hxx:112
MsWrdStruct::Font::Font
Font()
the constructor
Definition MsWrdStruct.hxx:61
MsWrdStruct::Font::m_font
MWAWVariable< MWAWFont > m_font
the font
Definition MsWrdStruct.hxx:102
MsWrdStruct::ParagraphInfo
the paragraph information of a Microsoft Word file (PHE)
Definition MsWrdStruct.hxx:254
MsWrdStruct::ParagraphInfo::isEmpty
bool isEmpty() const
returns true if no data are been set
Definition MsWrdStruct.hxx:269
MsWrdStruct::ParagraphInfo::m_numLines
MWAWVariable< int > m_numLines
the number of lines
Definition MsWrdStruct.hxx:306
MsWrdStruct::ParagraphInfo::operator<<
friend std::ostream & operator<<(std::ostream &o, ParagraphInfo const &pInfo)
operator<<
Definition MsWrdStruct.hxx:279
MsWrdStruct::ParagraphInfo::isLineSet
bool isLineSet() const
returns true if num lines is set
Definition MsWrdStruct.hxx:264
MsWrdStruct::ParagraphInfo::m_dim
MWAWVariable< MWAWVec2f > m_dim
the zone dimension
Definition MsWrdStruct.hxx:304
MsWrdStruct::ParagraphInfo::m_type
MWAWVariable< int > m_type
the type
Definition MsWrdStruct.hxx:302
MsWrdStruct::ParagraphInfo::ParagraphInfo
ParagraphInfo()
constructor
Definition MsWrdStruct.hxx:256
MsWrdStruct::ParagraphInfo::read
bool read(MWAWInputStreamPtr &input, long endPos, int vers)
try to read a data
Definition MsWrdStruct.cxx:702
MsWrdStruct::ParagraphInfo::m_error
std::string m_error
the errors
Definition MsWrdStruct.hxx:308
MsWrdStruct::ParagraphInfo::insert
void insert(ParagraphInfo const &pInfo)
insert the new values
Definition MsWrdStruct.cxx:717
MsWrdStruct::Paragraph
the paragraph structure of a Microsoft Word file
Definition MsWrdStruct.hxx:312
MsWrdStruct::Paragraph::Paragraph
Paragraph(Paragraph const &)=default
MsWrdStruct::Paragraph::operator<<
friend std::ostream & operator<<(std::ostream &o, Paragraph const &ind)
operator<<
Definition MsWrdStruct.cxx:1092
MsWrdStruct::Paragraph::operator=
Paragraph & operator=(Paragraph const &)=default
MsWrdStruct::Paragraph::m_table
MWAWVariable< Table > m_table
the table
Definition MsWrdStruct.hxx:381
MsWrdStruct::Paragraph::read
bool read(MWAWInputStreamPtr &input, long endPos)
try to read a data
Definition MsWrdStruct.cxx:730
MsWrdStruct::Paragraph::~Paragraph
~Paragraph() final
destructor
Definition MsWrdStruct.cxx:726
MsWrdStruct::Paragraph::m_interline
MWAWVariable< double > m_interline
the interline if set
Definition MsWrdStruct.hxx:365
MsWrdStruct::Paragraph::getFont
bool getFont(Font &font, Font const *styleFont=nullptr) const
returns the font which correspond to the paragraph if possible
Definition MsWrdStruct.cxx:1116
MsWrdStruct::Paragraph::inTable
bool inTable() const
returns true if we are in table
Definition MsWrdStruct.hxx:345
MsWrdStruct::Paragraph::updateParagraphToFinalState
void updateParagraphToFinalState(Paragraph const *style=nullptr)
update the paragraph to obtain the final paragraph
Definition MsWrdStruct.cxx:1130
MsWrdStruct::Paragraph::m_bordersStyle
MWAWVariable< MWAWBorder > m_bordersStyle
the border style ( old v3)
Definition MsWrdStruct.hxx:375
MsWrdStruct::Paragraph::m_version
int m_version
the file version
Definition MsWrdStruct.hxx:361
MsWrdStruct::Paragraph::m_inCell
MWAWVariable< bool > m_inCell
a cell/textbox
Definition MsWrdStruct.hxx:377
MsWrdStruct::Paragraph::m_styleId
MWAWVariable< int > m_styleId
the style id (if known)
Definition MsWrdStruct.hxx:363
MsWrdStruct::Paragraph::m_font
MWAWVariable< Font > m_font
the font
Definition MsWrdStruct.hxx:371
MsWrdStruct::Paragraph::getNumLines
int getNumLines() const
returns the number of line stored in m_info or -1
Definition MsWrdStruct.hxx:356
MsWrdStruct::Paragraph::m_section
MWAWVariable< Section > m_section
the section
Definition MsWrdStruct.hxx:373
MsWrdStruct::Paragraph::print
void print(std::ostream &o, MWAWFontConverterPtr converter) const
operator<<
Definition MsWrdStruct.cxx:1197
MsWrdStruct::Paragraph::Paragraph
Paragraph(int version)
Constructor.
Definition MsWrdStruct.hxx:314
MsWrdStruct::Paragraph::m_modFont
MWAWVariable< Font > m_modFont
font (modifier)
Definition MsWrdStruct.hxx:371
MsWrdStruct::Paragraph::m_tableDef
MWAWVariable< bool > m_tableDef
a table flag
Definition MsWrdStruct.hxx:379
MsWrdStruct::Paragraph::m_deletedTabs
std::vector< float > m_deletedTabs
the delete tabulation
Definition MsWrdStruct.hxx:367
MsWrdStruct::Paragraph::insert
void insert(Paragraph const &para, bool insertModif=true)
insert the new values
Definition MsWrdStruct.cxx:1157
MsWrdStruct::Paragraph::m_info
MWAWVariable< ParagraphInfo > m_info
the dimension
Definition MsWrdStruct.hxx:369
MsWrdStruct::Paragraph::operator=
Paragraph & operator=(Paragraph &&)=default
MsWrdStruct::Section
the section structure of a Microsoft Word file
Definition MsWrdStruct.hxx:118
MsWrdStruct::Section::m_col
MWAWVariable< int > m_col
the num of columns
Definition MsWrdStruct.hxx:161
MsWrdStruct::Section::m_id
MWAWVariable< int > m_id
the identificator
Definition MsWrdStruct.hxx:155
MsWrdStruct::Section::operator<<
friend std::ostream & operator<<(std::ostream &o, Section const &section)
operator<<
Definition MsWrdStruct.cxx:407
MsWrdStruct::Section::getSection
MWAWSection getSection(double pageWidth) const
returns a section
Definition MsWrdStruct.cxx:151
MsWrdStruct::Section::m_extra
std::string m_extra
the errors
Definition MsWrdStruct.hxx:169
MsWrdStruct::Section::Section
Section()
constructor
Definition MsWrdStruct.hxx:120
MsWrdStruct::Section::m_paragraphId
MWAWVariable< int > m_paragraphId
the paragraph id
Definition MsWrdStruct.hxx:159
MsWrdStruct::Section::m_colBreak
MWAWVariable< bool > m_colBreak
only a column break
Definition MsWrdStruct.hxx:165
MsWrdStruct::Section::m_type
MWAWVariable< int > m_type
the type
Definition MsWrdStruct.hxx:157
MsWrdStruct::Section::m_colSep
MWAWVariable< float > m_colSep
the spacing between column
Definition MsWrdStruct.hxx:163
MsWrdStruct::Section::m_flag
MWAWVariable< int > m_flag
some flag ( in the main position)
Definition MsWrdStruct.hxx:167
MsWrdStruct::Section::insert
void insert(Section const &sec)
insert the new values
Definition MsWrdStruct.hxx:135
MsWrdStruct::Section::readV3
bool readV3(MWAWInputStreamPtr &input, long endPos)
try to read a data ( v3 code )
Definition MsWrdStruct.cxx:234
MsWrdStruct::Section::read
bool read(MWAWInputStreamPtr &input, long endPos)
try to read a data
Definition MsWrdStruct.cxx:168
MsWrdStruct::Table::Cell
the cells definitions in a Microsoft Word Table
Definition MsWrdStruct.hxx:198
MsWrdStruct::Table::Cell::m_borders
std::vector< MWAWVariable< MWAWBorder > > m_borders
the borders TLBR
Definition MsWrdStruct.hxx:228
MsWrdStruct::Table::Cell::operator<<
friend std::ostream & operator<<(std::ostream &o, Cell const &cell)
operator<<
Definition MsWrdStruct.cxx:628
MsWrdStruct::Table::Cell::insert
void insert(Cell const &cell)
update the cell data by merging
Definition MsWrdStruct.hxx:207
MsWrdStruct::Table::Cell::m_extra
std::string m_extra
extra data
Definition MsWrdStruct.hxx:232
MsWrdStruct::Table::Cell::m_backColor
MWAWVariable< float > m_backColor
the background gray color
Definition MsWrdStruct.hxx:230
MsWrdStruct::Table::Cell::hasBorders
bool hasBorders() const
returns true if the cell has borders
Definition MsWrdStruct.hxx:218
MsWrdStruct::Table::Cell::Cell
Cell()
constructor
Definition MsWrdStruct.hxx:200
MsWrdStruct::Table
the table in a Microsoft Word file
Definition MsWrdStruct.hxx:173
MsWrdStruct::Table::Table
Table()
constructor
Definition MsWrdStruct.hxx:176
MsWrdStruct::Table::m_columnsWidthMod
MWAWVariable< std::vector< float > > m_columnsWidthMod
the columns width modifier
Definition MsWrdStruct.hxx:244
MsWrdStruct::Table::m_height
MWAWVariable< float > m_height
the row height in inches
Definition MsWrdStruct.hxx:236
MsWrdStruct::Table::m_indent
MWAWVariable< float > m_indent
the indent
Definition MsWrdStruct.hxx:240
MsWrdStruct::Table::m_justify
MWAWVariable< MWAWParagraph::Justification > m_justify
the justification
Definition MsWrdStruct.hxx:238
MsWrdStruct::Table::m_cells
std::vector< MWAWVariable< Cell > > m_cells
the table cells
Definition MsWrdStruct.hxx:246
MsWrdStruct::Table::read
bool read(MWAWInputStreamPtr &input, long endPos)
try to read a data
Definition MsWrdStruct.cxx:435
MsWrdStruct::Table::insert
void insert(Table const &table)
insert the new values
Definition MsWrdStruct.cxx:596
MsWrdStruct::Table::m_badCell
MWAWVariable< Cell > m_badCell
empty cell used by getCell to return unknown cell
Definition MsWrdStruct.hxx:248
MsWrdStruct::Table::m_extra
std::string m_extra
the errors
Definition MsWrdStruct.hxx:250
MsWrdStruct::Table::m_columns
MWAWVariable< std::vector< float > > m_columns
the table columns
Definition MsWrdStruct.hxx:242
MsWrdStruct::Table::operator<<
friend std::ostream & operator<<(std::ostream &o, Table const &table)
operator<<
Definition MsWrdStruct.cxx:646
MsWrdStruct::Table::getCell
MWAWVariable< Cell > & getCell(int id)
returns the ith Cell
Definition MsWrdStruct.cxx:425