libcrn  3.9.5
A document image processing library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CRNAltoStyles.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: CRNAltoStyles.h
19  * \author Yann LEYDIER
20  */
21 
23 #ifdef CRNAlto_HEADER
24 
30 class Styles: public Element
31 {
32  public:
33  Styles(const Styles&) = delete;
34  Styles(Styles&&) = default;
35  virtual ~Styles() override {}
36  Styles& operator=(const Styles&) = delete;
37  Styles& operator=(Styles&&) = default;
38 
40  std::vector<Id> GetTextStyles() const;
42  std::vector<Id> GetParagraphStyles() const;
47  class Text:public Element
48  {
49  public:
50  Text(const Text&) = default;
51  Text(Text&&) = default;
52  virtual ~Text() override {}
53  Text& operator=(const Text&) = default;
54  Text& operator=(Text&&) = default;
55 
56  const Id& GetId() const { return id; }
57 
58  Option<StringUTF8> GetFontFamily() const;
59  void SetFontFamily(const StringUTF8 &ff);
60  void UnsetFontFamily();
61 
62  enum class FontType { Undef = 0, Serif, SansSerif };
63  Option<FontType> GetFontType() const;
64  void SetFontType(FontType ft);
65  void UnsetFontType();
66 
67  enum class FontWidth { Undef = 0, Proportional, Fixed };
68  Option<FontWidth> GetFontWidth() const;
69  void SetFontWidth(FontWidth fw);
70  void UnsetFontWidth();
71 
72  double GetFontSize() const;
73  void SetFontSize(double fs);
74 
75  Option<uint32_t> GetFontColor() const;
76  void SetFontColor(uint32_t fc);
77  void UnsetFontColor();
78 
79  enum class FontStyle { Undef = 0, Bold = 1, Italics = 2, Subscript = 4, Superscript = 8, SmallCaps = 16, Underline = 32 };
80  Option<FontStyle> GetFontStyle() const;
81  void SetFontStyle(FontStyle fs);
82  void UnsetFontStyle();
83 
84  private:
85  Text(const Element &el);
86 
87  Id id;
88 
89  friend class Styles;
90  };
92  const Text& GetTextStyle(const Id &id_) const;
94  Text& GetTextStyle(const Id &id_);
96  Text& AddTextStyle(const Id &id_, double size);
97 
102  class Paragraph: public Element
103  {
104  public:
105  Paragraph(const Paragraph&) = default;
106  Paragraph(Paragraph&&) = default;
107  virtual ~Paragraph() override {}
108  Paragraph& operator=(const Paragraph&) = default;
109  Paragraph& operator=(Paragraph&&) = default;
110  const Id& GetId() const { return id; }
111 
112  enum class Align { Undef = 0, Left, Right, Center, Block };
113  Option<Align> GetAlign() const;
114  void SetAlign(Align a);
115  void UnsetAlign();
116 
117  Option<double> GetLeftIndent() const;
118  void SetLeftIndent(double i);
119  void UnsetLeftIndent();
120  Option<double> GetRightIndent() const;
121  void SetRightIndent(double i);
122  void UnsetRightIndent();
123  Option<double> GetLineSpace() const;
124  void SetLineSpace(double i);
125  void UnsetLineSpace();
126  Option<double> GetFirstLineIndent() const;
127  void SetFirstLineIndent(double i);
128  void UnsetFirstLineIndent();
129 
130  private:
131  Paragraph(const Element &el);
132 
133  Id id;
134 
135  friend class Styles;
136  };
138  const Paragraph& GetParagraphStyle(const Id &id_) const;
140  Paragraph& GetParagraphStyle(const Id &id_);
142  Paragraph& AddParagraphStyle(const Id &id_);
143 
144  private:
146  Styles(const Element &el);
147 
148  std::map<Id, std::unique_ptr<Text> > textStyles;
149  std::map<Id, std::unique_ptr<Paragraph> > parStyles;
150 
151  friend class Root;
152 };
153 
154 #else
155 #error you cannot include this file directly
156 #endif
void SetFontStyle(FontStyle fs)
Paragraph & operator=(const Paragraph &)=default
A paragraph style.
A text style.
virtual ~Text() override
std::vector< Id > GetTextStyles() const
Returns the ids of the text styles.
void SetFontWidth(FontWidth fw)
List of styles used in the document.
void SetAlign(Align a)
crn::StringUTF8 Id
Definition: CRNAltoUtils.h:31
const Id & GetId() const
Styles & operator=(const Styles &)=delete
Styles(const Styles &)=delete
void UnsetFontType()
std::vector< Id > GetParagraphStyles() const
Returns the ids of the paragraph styles.
Option< FontWidth > GetFontWidth() const
void SetRightIndent(double i)
Option< uint32_t > GetFontColor() const
Option< StringUTF8 > GetFontFamily() const
Option< Align > GetAlign() const
const Id & GetId() const
Text(const Text &)=default
Paragraph(const Paragraph &)=default
void UnsetFontColor()
Option< FontType > GetFontType() const
void SetLeftIndent(double i)
void SetFirstLineIndent(double i)
friend class Root
void UnsetFontWidth()
void UnsetFontFamily()
Paragraph & AddParagraphStyle(const Id &id_)
Adds a paragraph style.
virtual ~Styles() override
Text & operator=(const Text &)=default
void SetFontSize(double fs)
void SetLineSpace(double i)
Option< FontStyle > GetFontStyle() const
Text & AddTextStyle(const Id &id_, double size)
Adds a text style.
void UnsetFirstLineIndent()
void UnsetFontStyle()
Option< double > GetRightIndent() const
void SetFontColor(uint32_t fc)
void SetFontFamily(const StringUTF8 &ff)
double GetFontSize() const
Option< double > GetLeftIndent() const
virtual ~Paragraph() override
Option< double > GetLineSpace() const
const Text & GetTextStyle(const Id &id_) const
Returns a text style.
const Paragraph & GetParagraphStyle(const Id &id_) const
Returns a paragraph style.
void SetFontType(FontType ft)
Option< double > GetFirstLineIndent() const