MSWStruct.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 MSW structures
*/
#ifndef MSW_STRUCT
# define MSW_STRUCT
#include <iostream>
#include <string>
#include <vector>
#include "libmwaw_internal.hxx"
#include "MWAWFont.hxx"
#include "MWAWParagraph.hxx"
namespace MSWStruct
{
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 (int i = 0; i < NumFlags; i++) m_flags[i]=Variable<int>(0);
}
void insert(Font const &font, Font const *styleFont=0);
void updateFontToFinalState(Font const *styleFont=0);
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;
}
Variable<MWAWFont> m_font;
Variable<float> m_size;
Variable<int> m_value;
Variable<int> m_flags[NumFlags];
Variable<long> m_picturePos;
Variable<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);
Variable<int> m_id;
Variable<int> m_type;
Variable<int> m_paragraphId;
Variable<int> m_col;
Variable<float> m_colSep;
Variable<bool> m_colBreak;
Variable<int> m_flag;
std::string m_extra;
};
struct Table {
struct Cell;
Table() : m_height(0), m_justify(MWAWParagraph::JustificationLeft), m_indent(0), m_backColor(),
m_columns(), m_cells(), m_extra("") {
}
void insert(Table const &table) {
m_height.insert(table.m_height);
m_justify.insert(table.m_justify);
m_indent.insert(table.m_indent);
m_backColor.insert(table.m_backColor);
m_columns.insert(table.m_columns);
size_t tNumCells = table.m_cells.size();
if (tNumCells > m_cells.size())
m_cells.resize(tNumCells, Variable<Cell>());
for (size_t i=0; i < tNumCells; i++) {
if (!m_cells[i].isSet())
m_cells[i] = table.m_cells[i];
else if (table.m_cells[i].isSet())
m_cells[i]->insert(*table.m_cells[i]);
}
m_extra+=table.m_extra;
}
bool read(MWAWInputStreamPtr &input, long endPos);
Variable<Cell> &getCell(int id);
friend std::ostream &operator<<(std::ostream &o, Table const &table);
Variable<float> m_height;
Variable<MWAWParagraph::Justification> m_justify;
Variable<float> m_indent;
Variable<float> m_backColor;
Variable<std::vector<float> > m_columns;
std::vector<Variable<Cell> > m_cells;
std::string m_extra;
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 (size_t i = 0; i < m_borders.size(); i++)
if (m_borders[i].isSet() && m_borders[i]->m_style != MWAWBorder::None)
return true;
return false;
}
friend std::ostream &operator<<(std::ostream &o, Cell const &cell);
std::vector<Variable<MWAWBorder> > m_borders;
Variable<float> m_backColor;
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);
Variable<int> m_type;
Variable<Vec2f> m_dim;
Variable<int> m_numLines;
std::string m_error;
};
struct Paragraph : public MWAWParagraph {
Paragraph(int version) : MWAWParagraph(), m_version(version), m_styleId(-1000),
m_deletedTabs(), m_info(), m_font(), m_modFont(), m_section(),
m_bordersStyle(), m_inCell(false), m_tableDef(false), m_table() {
m_tabsRelativeToLeftMargin=false;
}
void insert(Paragraph const &para, bool insertModif=true);
bool read(MWAWInputStreamPtr &input, long endPos);
bool getFont(Font &font, Font const *styleFont=0) 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;
Variable<int> m_styleId;
Variable<std::vector<float> > m_deletedTabs;
Variable<ParagraphInfo> m_info;
Variable<Font> m_font, m_modFont ;
Variable<Section> m_section;
Variable<MWAWBorder> m_bordersStyle;
Variable<bool> m_inCell;
Variable<bool> m_tableDef;
Variable<Table> m_table;
};
}
#endif
// vim: set filetype=cpp tabstop=2 shiftwidth=2 cindent autoindent smartindent noexpandtab:
MSWStruct::Section
the section structure of a Microsoft Word file
Definition: MSWStruct.hxx:109
MSWStruct::ParagraphInfo::m_dim
Variable< Vec2f > m_dim
the zone dimension
Definition: MSWStruct.hxx:278
MSWStruct::Section::readV3
bool readV3(MWAWInputStreamPtr &input, long endPos)
try to read a data ( v3 code )
Definition: MSWStruct.cxx:233
MSWStruct::Paragraph::m_font
Variable< Font > m_font
the font
Definition: MSWStruct.hxx:322
MSWStruct::Section::m_extra
std::string m_extra
the errors
Definition: MSWStruct.hxx:151
MSWStruct::Font::updateFontToFinalState
void updateFontToFinalState(Font const *styleFont=0)
update the font to obtain the final font
Definition: MSWStruct.cxx:98
MSWStruct::Paragraph::operator<<
friend std::ostream & operator<<(std::ostream &o, Paragraph const &ind)
operator<<
Definition: MSWStruct.cxx:1052
MSWStruct::Table::m_cells
std::vector< Variable< Cell > > m_cells
the table cells
Definition: MSWStruct.hxx:198
MSWStruct::Paragraph::m_inCell
Variable< bool > m_inCell
a cell/textbox
Definition: MSWStruct.hxx:328
libmwaw_internal.hxx
Variable::insert
void insert(Variable const &orig)
update the current value if orig is set
Definition: libmwaw_internal.hxx:374
MSWStruct::Paragraph::print
void print(std::ostream &o, MWAWFontConverterPtr converter) const
operator<<
Definition: MSWStruct.cxx:1132
MSWStruct::Table::operator<<
friend std::ostream & operator<<(std::ostream &o, Table const &table)
operator<<
Definition: MSWStruct.cxx:617
MSWStruct::Font::insert
void insert(Font const &font, Font const *styleFont=0)
insert new font data ( beginning by updating font flags )
Definition: MSWStruct.cxx:82
MSWStruct::Paragraph
the paragraph structure of a Microsoft Word file
Definition: MSWStruct.hxx:286
MSWStruct::getBorder
MWAWBorder getBorder(int val, std::string &extra)
generic function use to fill a border using the read data
Definition: MSWStruct.cxx:1142
MSWStruct::Paragraph::m_modFont
Variable< Font > m_modFont
font (modifier)
Definition: MSWStruct.hxx:322
Variable::isSet
bool isSet() const
return true if the variable is set
Definition: libmwaw_internal.hxx:403
MSWStruct::Table::m_indent
Variable< float > m_indent
the indent
Definition: MSWStruct.hxx:192
MSWStruct::Paragraph::m_bordersStyle
Variable< MWAWBorder > m_bordersStyle
the border style ( old v3)
Definition: MSWStruct.hxx:326
MSWStruct::Table::Cell::m_extra
std::string m_extra
extra data
Definition: MSWStruct.hxx:231
MSWStruct::Font::m_value
Variable< int > m_value
a unknown value
Definition: MSWStruct.hxx:97
MSWStruct::Table
the table in a Microsoft Word file
Definition: MSWStruct.hxx:155
MSWStruct::Table::Cell
the cells definitions in a Microsoft Word Table
Definition: MSWStruct.hxx:203
MSWStruct::Table::m_justify
Variable< MWAWParagraph::Justification > m_justify
the justification
Definition: MSWStruct.hxx:190
MSWStruct::Font::NumFlags
the number of flags needed to store all datas
Definition: MSWStruct.hxx:58
MSWStruct::Section::m_col
Variable< int > m_col
the num of columns
Definition: MSWStruct.hxx:143
MSWStruct::Section::read
bool read(MWAWInputStreamPtr &input, long endPos)
try to read a data
Definition: MSWStruct.cxx:167
MSWStruct::Section::m_colBreak
Variable< bool > m_colBreak
only a column break
Definition: MSWStruct.hxx:147
MSWStruct::Table::m_height
Variable< float > m_height
the row height in inches
Definition: MSWStruct.hxx:188
MSWStruct::Table::Cell::operator<<
friend std::ostream & operator<<(std::ostream &o, Cell const &cell)
operator<<
Definition: MSWStruct.cxx:599
MWAWBorder
a border
Definition: libmwaw_internal.hxx:232
MSWStruct::Paragraph::Paragraph
Paragraph(int version)
Constructor.
Definition: MSWStruct.hxx:288
MSWStruct::Table::Cell::Cell
Cell()
constructor
Definition: MSWStruct.hxx:205
MSWStruct::Paragraph::inTable
bool inTable() const
returns true if we are in table
Definition: MSWStruct.hxx:300
MSWStruct::Table::read
bool read(MWAWInputStreamPtr &input, long endPos)
try to read a data
Definition: MSWStruct.cxx:435
MSWStruct::Font::m_picturePos
Variable< long > m_picturePos
a picture file position (if this corresponds to a picture)
Definition: MSWStruct.hxx:101
MSWStruct::Section::getSection
MWAWSection getSection(double pageWidth) const
returns a section
Definition: MSWStruct.cxx:150
MWAWParagraph::m_tabsRelativeToLeftMargin
Variable< 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:154
MSWStruct::ParagraphInfo::insert
void insert(ParagraphInfo const &pInfo)
insert the new values
Definition: MSWStruct.cxx:681
MSWStruct::Font::m_extra
std::string m_extra
extra data
Definition: MSWStruct.hxx:105
MSWStruct::Font::operator<<
friend std::ostream & operator<<(std::ostream &o, Font const &font)
operator<<
Definition: MSWStruct.cxx:44
MSWStruct::Table::m_backColor
Variable< float > m_backColor
the table background gray color
Definition: MSWStruct.hxx:194
MWAWBorder::None
Definition: libmwaw_internal.hxx:234
MSWStruct::Paragraph::m_tableDef
Variable< bool > m_tableDef
a table flag
Definition: MSWStruct.hxx:330
MSWStruct::Table::m_columns
Variable< std::vector< float > > m_columns
the table columns
Definition: MSWStruct.hxx:196
MWAWSection
a class which stores section properties
Definition: MWAWSection.hxx:45
MSWStruct::Table::Cell::m_borders
std::vector< Variable< MWAWBorder > > m_borders
the borders TLBR
Definition: MSWStruct.hxx:227
MWAWInputStreamPtr
shared_ptr< MWAWInputStream > MWAWInputStreamPtr
a smart pointer of MWAWInputStream
Definition: libmwaw_internal.hxx:336
MSWStruct::Table::Cell::insert
void insert(Cell const &cell)
update the cell data by merging
Definition: MSWStruct.hxx:208
MSWStruct::ParagraphInfo
the paragraph information of a Microsoft Word file (PHE)
Definition: MSWStruct.hxx:236
MSWStruct::Paragraph::m_info
Variable< ParagraphInfo > m_info
the dimension
Definition: MSWStruct.hxx:320
Variable::get
T const & get() const
return the current value
Definition: libmwaw_internal.hxx:399
MSWStruct::ParagraphInfo::isLineSet
bool isLineSet() const
returns true if num lines is set
Definition: MSWStruct.hxx:241
MSWStruct::Paragraph::m_section
Variable< Section > m_section
the section
Definition: MSWStruct.hxx:324
MSWStruct::ParagraphInfo::ParagraphInfo
ParagraphInfo()
constructor
Definition: MSWStruct.hxx:238
MSWStruct::ParagraphInfo::m_error
std::string m_error
the errors
Definition: MSWStruct.hxx:282
MSWStruct::Table::Cell::m_backColor
Variable< float > m_backColor
the background gray color
Definition: MSWStruct.hxx:229
MWAWFontConverterPtr
shared_ptr< MWAWFontConverter > MWAWFontConverterPtr
a smart pointer of MWAWFontConverter
Definition: libmwaw_internal.hxx:334
MSWStruct::Table::insert
void insert(Table const &table)
insert the new values
Definition: MSWStruct.hxx:162
MSWStruct::Section::m_colSep
Variable< float > m_colSep
the spacing between column
Definition: MSWStruct.hxx:145
MSWStruct::Section::operator<<
friend std::ostream & operator<<(std::ostream &o, Section const &section)
operator<<
Definition: MSWStruct.cxx:406
MSWStruct::Paragraph::m_version
int m_version
the file version
Definition: MSWStruct.hxx:314
MWAWParagraph
class to store the paragraph properties
Definition: MWAWParagraph.hxx:83
MSWStruct::Paragraph::getFont
bool getFont(Font &font, Font const *styleFont=0) const
returns the font which correspond to the paragraph if possible
Definition: MSWStruct.cxx:1074
MSWStruct::Paragraph::read
bool read(MWAWInputStreamPtr &input, long endPos)
try to read a data
Definition: MSWStruct.cxx:690
MSWStruct::Font::m_font
Variable< MWAWFont > m_font
the font
Definition: MSWStruct.hxx:93
MSWStruct::Font
the font structure of a Microsoft Word file
Definition: MSWStruct.hxx:57
MSWStruct::Font::Font
Font()
the constructor
Definition: MSWStruct.hxx:61
MSWStruct::Table::Cell::hasBorders
bool hasBorders() const
returns true if the cell has borders
Definition: MSWStruct.hxx:218
MSWStruct::Section::Section
Section()
constructor
Definition: MSWStruct.hxx:111
MSWStruct::Font::m_flags
Variable< int > m_flags[NumFlags]
a list of flags
Definition: MSWStruct.hxx:99
MSWStruct::Paragraph::insert
void insert(Paragraph const &para, bool insertModif=true)
insert the new values
Definition: MSWStruct.cxx:1088
MSWStruct::Paragraph::m_table
Variable< Table > m_table
the table
Definition: MSWStruct.hxx:332
MSWStruct::Font::m_unknown
Variable< int > m_unknown
some unknown flag
Definition: MSWStruct.hxx:103
MSWStruct::Font::cmp
int cmp(Font const &oth) const
operator==
Definition: MSWStruct.hxx:75
MSWStruct::ParagraphInfo::isEmpty
bool isEmpty() const
returns true if no data are been set
Definition: MSWStruct.hxx:245
MSWStruct::ParagraphInfo::operator<<
friend std::ostream & operator<<(std::ostream &o, ParagraphInfo const &pInfo)
operator<<
Definition: MSWStruct.hxx:254
MSWStruct::Table::getCell
Variable< Cell > & getCell(int id)
returns the ith Cell
Definition: MSWStruct.cxx:424
MSWStruct::ParagraphInfo::read
bool read(MWAWInputStreamPtr &input, long endPos, int vers)
try to read a data
Definition: MSWStruct.cxx:666
MSWStruct::Paragraph::m_styleId
Variable< int > m_styleId
the style id (if known)
Definition: MSWStruct.hxx:316
MSWStruct::Section::m_paragraphId
Variable< int > m_paragraphId
the paragraph id
Definition: MSWStruct.hxx:141
MSWStruct::ParagraphInfo::m_numLines
Variable< int > m_numLines
the number of lines
Definition: MSWStruct.hxx:280
MSWStruct::Section::insert
void insert(Section const &sec)
insert the new values
Definition: MSWStruct.hxx:118
MSWStruct::ParagraphInfo::m_type
Variable< int > m_type
the type
Definition: MSWStruct.hxx:276
MSWStruct::Paragraph::getNumLines
int getNumLines() const
returns the number of line stored in m_info or -1
Definition: MSWStruct.hxx:310
MSWStruct::Paragraph::m_deletedTabs
Variable< std::vector< float > > m_deletedTabs
the delete tabulation
Definition: MSWStruct.hxx:318
MSWStruct::Section::m_id
Variable< int > m_id
the identificator
Definition: MSWStruct.hxx:137
MWAWParagraph.hxx
Variable< MWAWFont >
MSWStruct::Font::m_size
Variable< float > m_size
a second size
Definition: MSWStruct.hxx:95
MSWStruct::Table::m_extra
std::string m_extra
the errors
Definition: MSWStruct.hxx:200
MSWStruct::Section::m_type
Variable< int > m_type
the type
Definition: MSWStruct.hxx:139
MSWStruct::Section::m_flag
Variable< int > m_flag
some flag ( in the main position)
Definition: MSWStruct.hxx:149
MSWStruct::Table::Table
Table()
constructor
Definition: MSWStruct.hxx:158