libcrn  3.9.5
A document image processing library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CRNAltoSpace.hpp
Go to the documentation of this file.
1 /* Copyright 2011-2016 CoReNum
2  *
3  * This file is part of libcrn.
4  *
5  * libcrn is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * libcrn is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with libcrn. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * file: CRNAltoSpace.h
19  * \author Yann LEYDIER
20  */
21 
23 #ifdef CRNAlto_HEADER
24 
30 class Space: public Element
31 {
32  public:
33  Space(const Space&) = delete;
34  Space(Space&&) = default;
35  virtual ~Space() override {}
36  Space& operator=(const Space&) = delete;
37  Space& operator=(Space&&) = default;
38 
40  Option<Id> GetId() const;
41 
43  std::vector<Id> GetStyles() const;
45  void AddStyle(const Id &styleid);
47  void RemoveStyle(const Id &styleid);
48 
50  double GetHeight() const;
52  void SetHeight(double d);
54  double GetWidth() const;
56  void SetWidth(double d);
58  double GetHPos() const;
60  void SetHPos(double d);
62  double GetVPos() const;
64  void SetVPos(double d);
65 
70  class Block: public Element
71  {
72  public:
73  Block(const Block&) = delete;
74  Block(Block&&) = default;
75  virtual ~Block() override {}
76  Block& operator=(const Block&) = delete;
77  Block& operator=(Block&&) = default;
78 
80  const Id& GetId() const { return id; }
81 
83  std::vector<Id> GetStyles() const;
85  void AddStyle(const Id &styleid);
87  void RemoveStyle(const Id &styleid);
88 
90  int GetHeight() const;
92  void SetHeight(int i);
94  int GetWidth() const;
96  void SetWidth(int i);
98  int GetHPos() const;
100  void SetHPos(int i);
102  int GetVPos() const;
104  void SetVPos(int i);
106  Option<double> GetRotation() const;
108  Option<Id> GetNextId() const;
109 
110  protected:
112  Block(const Element &el);
114  Block(const Element &el, const Id &id_, int x, int y, int w, int h);
115 
117  // std::vector<crn::WeakPointer<Shape> > shapes; // TODO
118  };
119  typedef std::weak_ptr<Block> BlockPtr;
121  Block& GetBlock(const Id &bid);
123  std::vector<BlockPtr> GetBlocks() const;
124 
126  typedef std::weak_ptr<TextBlock> TextBlockPtr;
127 
129  const std::vector<std::weak_ptr<TextBlock>>& GetTextBlocks() const { return textBlocks; }
131  TextBlock& GetTextBlock(const Id &id);
133  TextBlock& AddTextBlock(const Id &id_, int x, int y, int w, int h);
135  TextBlock& AddTextBlockAfter(const Id &pred, const Id &id_, int x, int y, int w, int h);
137  TextBlock& AddTextBlockBefore(const Id &next, const Id &id_, int x, int y, int w, int h);
138 
143  class Illustration: public Block
144  {
145  public:
146  Illustration(const Illustration&) = default;
147  Illustration(Illustration&&) = default;
148  virtual ~Illustration() override {}
149  Illustration& operator=(const Illustration&) = default;
150  Illustration& operator=(Illustration&&) = default;
151 
153  Option<StringUTF8> GetType() const;
155  Option<StringUTF8> GetFileId() const;
156 
157  private:
159  Illustration(const Element &el);
161  Illustration(const Element &el, const Id &id_, int x, int y, int w, int h);
162 
163  friend class Space;
164  };
165  typedef std::weak_ptr<Illustration> IllustrationPtr;
166 
168  const std::vector<IllustrationPtr>& GetIllustrations() const;
170  Illustration& AddIllustration(const Id &id_, int x, int y, int w, int h);
172  Illustration& AddIllustrationAfter(const Id &pred, const Id &id_, int x, int y, int w, int h);
174  Illustration& AddIllustrationBefore(const Id &next, const Id &id_, int x, int y, int w, int h);
175 
180  class GraphicalElement: public Block
181  {
182  public:
183  GraphicalElement(const GraphicalElement&) = default;
184  GraphicalElement(GraphicalElement&&) = default;
185  virtual ~GraphicalElement() override {}
186  GraphicalElement& operator=(const GraphicalElement&) = default;
188 
189  private:
191  GraphicalElement(const Element &el);
193  GraphicalElement(const Element &el, const Id &id_, int x, int y, int w, int h);
194 
195  friend class Space;
196  };
197  typedef std::weak_ptr<GraphicalElement> GraphicalElementPtr;
198 
200  const std::vector<GraphicalElementPtr>& GetGraphicalElements() const;
202  GraphicalElement& AddGraphicalElement(const Id &id_, int x, int y, int w, int h);
204  GraphicalElement& AddGraphicalElementAfter(const Id &pred, const Id &id_, int x, int y, int w, int h);
206  GraphicalElement& AddGraphicalElementBefore(const Id &next, const Id &id_, int x, int y, int w, int h);
207 
212  class ComposedBlock: public Block
213  {
214  public:
215  ComposedBlock(const ComposedBlock&) = default;
216  ComposedBlock(ComposedBlock&&) = default;
217  virtual ~ComposedBlock() override {}
218  ComposedBlock& operator=(const ComposedBlock&) = default;
219  ComposedBlock& operator=(ComposedBlock&&) = default;
220 
222  Option<StringUTF8> GetType() const;
224  Option<StringUTF8> GetFileId() const;
226  std::vector<BlockPtr> GetBlocks() const { return std::vector<BlockPtr>(blocks.begin(), blocks.end()); }
228  const std::vector<std::weak_ptr<TextBlock> >& GetTextBlocks() const { return textBlocks; }
230  const std::vector<std::weak_ptr<Illustration> >& GetIllustrations() const { return illustrations; }
232  const std::vector<std::weak_ptr<GraphicalElement> >& GetGraphicalElements() const { return graphicalElements; }
234  const std::vector<std::weak_ptr<ComposedBlock> >& GetComposedBlocks() const { return composedBlocks; }
235 
236  private:
238  ComposedBlock(const Element &el);
239 
240  std::vector<std::shared_ptr<Block> > blocks;
241  std::vector<TextBlockPtr> textBlocks;
242  std::vector<IllustrationPtr> illustrations;
243  std::vector<GraphicalElementPtr> graphicalElements;
244  std::vector<std::weak_ptr<ComposedBlock> > composedBlocks;
245 
246  friend class Space;
247  };
248  typedef std::weak_ptr<ComposedBlock> ComposedBlockPtr;
249 
251  const std::vector<ComposedBlockPtr>& GetComposedBlocks() const;
252 
254  void RemoveBlock(const Id &bid);
255 
256  private:
258  Space(const Element &el);
260  Space(const Element &el, const Id &id_, double x, double y, double w, double h);
262  void update_subelements();
263 
264  std::vector<std::shared_ptr<Block> > blocks;
265  std::map<Id, std::weak_ptr<Block> > id_blocks;
266  std::vector<TextBlockPtr> textBlocks;
267  std::map<Id, TextBlockPtr> id_textBlocks;
268  std::vector<IllustrationPtr> illustrations;
269  std::vector<GraphicalElementPtr> graphicalElements;
270  std::vector<ComposedBlockPtr> composedBlocks;
271 
272  friend class Page;
273 };
274 #else
275 #error you cannot include this file directly
276 #endif
277 
void RemoveBlock(const Id &bid)
Removes a block.
Illustration & AddIllustration(const Id &id_, int x, int y, int w, int h)
Adds an illustration in the print space.
TextBlock & AddTextBlockAfter(const Id &pred, const Id &id_, int x, int y, int w, int h)
Adds a text block in the print space.
Option< StringUTF8 > GetType() const
Returns the type of block (table, advertisement…)
const std::vector< ComposedBlockPtr > & GetComposedBlocks() const
Returns the list of composed blocks in the print space.
std::weak_ptr< GraphicalElement > GraphicalElementPtr
Option< Id > GetId() const
Returns the id of the element.
void SetVPos(double d)
Sets the ordinate of the element.
A print space on a page.
std::weak_ptr< TextBlock > TextBlockPtr
void RemoveStyle(const Id &styleid)
Removes a reference to a style.
std::vector< BlockPtr > GetBlocks() const
Returns the list of subblocks in the block.
int GetHPos() const
Returns the abscissa of the element.
Illustration & AddIllustrationBefore(const Id &next, const Id &id_, int x, int y, int w, int h)
Adds an illustration in the print space.
void SetWidth(int i)
Sets the width of the element.
Illustration(const Illustration &)=default
crn::StringUTF8 Id
Definition: CRNAltoUtils.h:31
Option< StringUTF8 > GetFileId() const
Returns a link to an image containing only this illustration.
void RemoveStyle(const Id &styleid)
Adds a reference to a style.
const std::vector< std::weak_ptr< TextBlock > > & GetTextBlocks() const
Returns the list of text blocks in the block.
Block(const Block &)=delete
const std::vector< std::weak_ptr< TextBlock > > & GetTextBlocks() const
Returns the list of text blocks in the print space.
Illustration in a space.
const Id & GetId() const
Returns the id of the element.
std::vector< Id > GetStyles() const
Returns the list of style references.
std::vector< BlockPtr > GetBlocks() const
Returns the list of blocks in the print space.
int GetWidth() const
Returns the width of the element.
void SetHeight(double d)
Sets the height of the element.
const std::vector< std::weak_ptr< GraphicalElement > > & GetGraphicalElements() const
Returns the list of graphical elements in the block.
Option< StringUTF8 > GetType() const
Returns the type of illustration (photo, map, drawing, chart…)
TextBlock & AddTextBlock(const Id &id_, int x, int y, int w, int h)
Adds a text block in the print space.
const std::vector< IllustrationPtr > & GetIllustrations() const
Returns the list of illustrations in the print space.
virtual ~Block() override
A composed block in a space.
GraphicalElement & AddGraphicalElement(const Id &id_, int x, int y, int w, int h)
Adds an graphical element in the print space.
Option< Id > GetNextId() const
Returns the id of the next block.
Base class for blocks in spaces.
int GetVPos() const
Returns the ordinate of the element.
Space(const Space &)=delete
double GetWidth() const
Returns the width of the element.
GraphicalElement & AddGraphicalElementBefore(const Id &next, const Id &id_, int x, int y, int w, int h)
Adds an graphical element in the print space.
virtual ~Illustration() override
void SetHPos(double d)
Sets the abscissa of the element.
ComposedBlock(const ComposedBlock &)=default
GraphicalElement(const GraphicalElement &)=default
TextBlock & GetTextBlock(const Id &id)
Returns a text block contained in the print space.
void SetVPos(int i)
Sets the ordinate of the element.
double GetVPos() const
Returns the ordinate of the element.
const std::vector< std::weak_ptr< Illustration > > & GetIllustrations() const
Returns the list of illustrations in the block.
ComposedBlock & operator=(const ComposedBlock &)=default
void SetWidth(double d)
Sets the width of the element.
Option< StringUTF8 > GetFileId() const
Returns a link to an image containing only this block.
int GetHeight() const
Returns the height of the element.
GraphicalElement & AddGraphicalElementAfter(const Id &pred, const Id &id_, int x, int y, int w, int h)
Adds an graphical element in the print space.
Space & operator=(const Space &)=delete
std::weak_ptr< Block > BlockPtr
Illustration & operator=(const Illustration &)=default
void SetHPos(int i)
Sets the abscissa of the element.
void SetHeight(int i)
Sets the height of the element.
Block & operator=(const Block &)=delete
Block & GetBlock(const Id &bid)
Returns a text block contained in the print space.
const std::vector< std::weak_ptr< ComposedBlock > > & GetComposedBlocks() const
Returns the list of composed blocks in the block.
Option< double > GetRotation() const
Returns the rotation of the object, in degree, counterclockwise.
double GetHeight() const
Returns the height of the element.
virtual ~Space() override
const std::vector< GraphicalElementPtr > & GetGraphicalElements() const
Returns the list of graphical elements in the print space.
Alto text block.
GraphicalElement & operator=(const GraphicalElement &)=default
std::weak_ptr< Illustration > IllustrationPtr
Graphical element in a space.
void AddStyle(const Id &styleid)
Adds a reference to a style.
std::vector< Id > GetStyles() const
Returns the list of style references.
virtual ~ComposedBlock() override
friend class Page
virtual ~GraphicalElement() override
Illustration & AddIllustrationAfter(const Id &pred, const Id &id_, int x, int y, int w, int h)
Adds an illustration in the print space.
double GetHPos() const
Returns the abscissa of the element.
std::weak_ptr< ComposedBlock > ComposedBlockPtr
void AddStyle(const Id &styleid)
Adds a reference to a style.
TextBlock & AddTextBlockBefore(const Id &next, const Id &id_, int x, int y, int w, int h)
Adds a text block in the print space.