libcrn  3.9.5
A document image processing library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CRNAltoLayout.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: CRNAltoLayout.h
19  * \author Yann LEYDIER
20  */
21 
23 #ifdef CRNAlto_HEADER
24 
30 class Layout: public Element
31 {
32  public:
33  Layout(const Layout&) = delete;
34  Layout(Layout&&) = default;
35  virtual ~Layout() override {}
36  Layout& operator=(const Layout&) = delete;
37  Layout& operator=(Layout&&) = default;
38 
40  std::vector<Id> GetStyles() const;
42  void AddStyle(const Id &styleid);
44  void RemoveStyle(const Id &styleid);
45 
50  class Page: public Element
51  {
52  public:
53  enum class Position { Undef = 0, Left, Right, Foldout, Single, Cover };
54 
55  Page(const Page&) = delete;
56  Page(Page&&) = default;
57  virtual ~Page() override {}
58  Page& operator=(const Page&) = delete;
59  Page& operator=(Page&&) = default;
60 
62  const Id& GetId() const { return id; }
64  Option<StringUTF8> GetPageClass() const;
66  void SetPageClass(const StringUTF8 &s);
68  std::vector<Id> GetStyles() const;
70  void AddStyle(const Id &styleid);
72  void RemoveStyle(const Id &styleid);
74  Option<int> GetHeight() const;
76  void SetHeight(int i);
78  Option<int> GetWidth() const;
80  void SetWidth(int i);
82  int GetPhysicalImageNumber() const;
84  void SetPhysicalImageNumber(int pnum);
86  Option<StringUTF8> GetPrintedImageNumber() const;
88  void SetPrintedImageNumber(const StringUTF8 &s);
91  Option<Quality> GetQuality() const;
93  void SetQuality(Quality q);
95  Option<StringUTF8> GetQualityDetail() const;
97  void SetQualityDetail(const StringUTF8 &s);
99  Option<Position> GetPosition() const;
101  Option<Id> GetProcessing() const;
103  Option<double> GetAccuracy() const;
105  void SetAccuracy(double acc);
107  Option<double> GetPageConfidence() const;
109  void SetPageConfidence(double c);
110 
111 #include <CRNXml/CRNAltoSpace.hpp>
112  typedef std::weak_ptr<Space> SpacePtr;
114  SpacePtr GetTopMargin() { return topMargin; }
116  SpacePtr GetLeftMargin() { return leftMargin; }
118  SpacePtr GetRightMargin() { return rightMargin; }
120  SpacePtr GetBottomMargin() { return bottomMargin; }
122  SpacePtr GetPrintSpace() { return printSpace; }
124  Space& GetSpace(const Id &sid);
125 
127  Space& AddTopMargin(const Id &id_, double x, double y, double w, double h);
129  Space& AddLeftMargin(const Id &id_, double x, double y, double w, double h);
131  Space& AddRightMargin(const Id &id_, double x, double y, double w, double h);
133  Space& AddBottomMargin(const Id &id_, double x, double y, double w, double h);
135  Space& AddPrintSpace(const Id &id_, double x, double y, double w, double h);
137  std::vector<SpacePtr> GetSpaces() const;
138 
140  void RemoveSpace(const Id &sid);
141 
142  private:
144  Page(const Element &el);
146  Page(const Element &el, const Id &id_, int image_number, Option<int> width, Option<int> height, Option<Position> position);
148  void update_subelements();
149 
150  Id id;
151  SpacePtr topMargin, leftMargin, rightMargin, bottomMargin, printSpace;
152  std::vector<std::shared_ptr<Space> > spaces;
153  std::map<Id, std::weak_ptr<Space> > id_spaces;
154 
155  friend class Layout;
156  };
157  typedef std::weak_ptr<Page> PagePtr;
158 
160  Page& GetPage(const Id &pid);
162  std::vector<PagePtr> GetPages() const;
164  Page& AddPage(const Id &id_, int image_number, Option<int> width_ = Option<int>(), Option<int> height_ = Option<int>(), Option<Page::Position> pos = Option<Page::Position>());
166  Page& AddPageAfter(const Id &pred, const Id &id_, int image_number, Option<int> width_ = Option<int>(), Option<int> height_ = Option<int>(), Option<Page::Position> pos = Option<Page::Position>());
168  Page& AddPageBefore(const Id &next, const Id &id_, int image_number, Option<int> width_ = Option<int>(), Option<int> height_ = Option<int>(), Option<Page::Position> pos = Option<Page::Position>());
169 
171  void RemovePage(const Id &pid);
172 
173  private:
175  Layout(const Element &el);
177  void update_subelements();
178 
179  std::vector<std::shared_ptr<Page> > pages;
180  std::map<Id, std::weak_ptr<Page> > id_pages;
181 
182  friend class Root;
183 };
184 
185 #else
186 #error you cannot include this file directly
187 #endif
XML Alto layout element.
Page & operator=(const Page &)=delete
SpacePtr GetLeftMargin()
Returns the left margin.
Option< Position > GetPosition() const
Returns the position of the page.
void SetQuality(Quality q)
Sets the quality of the original page.
A print space on a page.
void SetAccuracy(double acc)
Sets the estimated % of OCR accuracy on the page [0, 100].
Space & GetSpace(const Id &sid)
Returns a space.
crn::StringUTF8 Id
Definition: CRNAltoUtils.h:31
void SetQualityDetail(const StringUTF8 &s)
Sets the details on the quality of the original page.
Layout(const Layout &)=delete
void SetHeight(int i)
Sets the height of the page.
std::vector< Id > GetStyles() const
Returns the list of style references.
Option< StringUTF8 > GetPageClass() const
Returns the class of the page (user defined class such as "title")
void SetPageClass(const StringUTF8 &s)
Sets the class of the page (user defined class such as "title")
void RemovePage(const Id &pid)
Removes a page.
Page & AddPage(const Id &id_, int image_number, Option< int > width_=Option< int >(), Option< int > height_=Option< int >(), Option< Page::Position > pos=Option< Page::Position >())
Adds a page.
Option< double > GetAccuracy() const
Returns the estimated % of OCR accuracy on the page [0, 100].
Option< double > GetPageConfidence() const
Returns the confidence of OCR on the page [0, 1].
virtual ~Layout() override
Option< StringUTF8 > GetPrintedImageNumber() const
Returns the page number that is printed on the document.
void AddStyle(const Id &styleid)
Adds a reference to a style.
void RemoveSpace(const Id &sid)
Removes a space.
std::vector< Id > GetStyles() const
Returns the list of style references.
Option< Quality > GetQuality() const
Returns the quality of the original page.
SpacePtr GetPrintSpace()
Returns the main print space.
SpacePtr GetBottomMargin()
Returns the bottom margin.
SpacePtr GetRightMargin()
Returns the right margin.
virtual ~Page() override
XML Alto Page element.
Layout & operator=(const Layout &)=delete
void SetPhysicalImageNumber(int pnum)
Sets the number of the page within the document.
void SetPageConfidence(double c)
Sets the confidence of OCR on the page [0, 1].
void RemoveStyle(const Id &styleid)
Removes a reference to a style.
std::vector< PagePtr > GetPages() const
Returns the list of all pages.
std::weak_ptr< Space > SpacePtr
void AddStyle(const Id &styleid)
Adds a reference to a style.
Space & AddRightMargin(const Id &id_, double x, double y, double w, double h)
Adds a right margin.
Option< StringUTF8 > GetQualityDetail() const
Returns details on the quality of the original page.
const Id & GetId() const
Returns the id of the element.
void SetPrintedImageNumber(const StringUTF8 &s)
Sets the page number that is printed on the document.
void SetWidth(int i)
Sets the width of the page.
Space & AddBottomMargin(const Id &id_, double x, double y, double w, double h)
Adds a bottom margin.
Page & GetPage(const Id &pid)
Returns a page.
Page & AddPageBefore(const Id &next, const Id &id_, int image_number, Option< int > width_=Option< int >(), Option< int > height_=Option< int >(), Option< Page::Position > pos=Option< Page::Position >())
Adds a page before another.
SpacePtr GetTopMargin()
Returns the top margin.
Option< int > GetHeight() const
Returns the height of the page.
Page & AddPageAfter(const Id &pred, const Id &id_, int image_number, Option< int > width_=Option< int >(), Option< int > height_=Option< int >(), Option< Page::Position > pos=Option< Page::Position >())
Adds a page after another.
Space & AddLeftMargin(const Id &id_, double x, double y, double w, double h)
Adds a left margin.
Option< Id > GetProcessing() const
Returns the id of the processing applied to the page.
std::weak_ptr< Page > PagePtr
Space & AddTopMargin(const Id &id_, double x, double y, double w, double h)
Adds a top margin.
Option< int > GetWidth() const
Returns the width of the page.
Page(const Page &)=delete
int GetPhysicalImageNumber() const
Returns the number of the page within the document.
void RemoveStyle(const Id &styleid)
Removes a reference to a style.
Space & AddPrintSpace(const Id &id_, double x, double y, double w, double h)
Adds the print space.
friend class Root
std::vector< SpacePtr > GetSpaces() const
Returns the list of all spaces.