33 Alto::Styles::Styles(
const Element &el):
36 for (
Element el = BeginElement(); el != EndElement(); ++el)
39 if (elname ==
"TextStyle")
41 std::unique_ptr<Text> t(
new Text(el));
42 textStyles.insert(std::make_pair(t->GetId(), std::move(t)));
44 else if (elname ==
"ParagraphStyle")
46 std::unique_ptr<Paragraph> p(
new Paragraph(el));
47 parStyles.insert(std::make_pair(p->GetId(), std::move(p)));
53 std::vector<Id> Alto::Styles::GetTextStyles()
const
55 std::vector<Id> styles;
56 for (std::map<
Id, std::unique_ptr<Text> >::
const_iterator it = textStyles.begin(); it != textStyles.end(); ++it)
58 styles.push_back(it->first);
64 std::vector<Id> Alto::Styles::GetParagraphStyles()
const
66 std::vector<Id> styles;
67 for (std::map<
Id, std::unique_ptr<Paragraph> >::
const_iterator it = parStyles.begin(); it != parStyles.end(); ++it)
69 styles.push_back(it->first);
79 const Alto::Styles::Text& Alto::Styles::GetTextStyle(
const Id &id_)
const
81 std::map<Id, std::unique_ptr<Text> >
::const_iterator it = textStyles.find(id_);
82 if (it != textStyles.end())
93 Alto::Styles::Text& Alto::Styles::GetTextStyle(
const Id &id_)
95 std::map<Id, std::unique_ptr<Text> >::iterator it = textStyles.find(id_);
96 if (it != textStyles.end())
106 Alto::Styles::Text& Alto::Styles::AddTextStyle(
const Id &id_,
double size)
108 Element el(PushBackElement(
"TextStyle"));
111 auto res = textStyles.insert(std::make_pair(id_, std::unique_ptr<Text>(
new Text(el))));
112 return *res.first->second;
120 const Alto::Styles::Paragraph& Alto::Styles::GetParagraphStyle(
const Id &id_)
const
122 std::map<Id, std::unique_ptr<Paragraph> >
::const_iterator it = parStyles.find(id_);
123 if (it != parStyles.end())
124 return *(it->second);
134 Alto::Styles::Paragraph& Alto::Styles::GetParagraphStyle(
const Id &id_)
136 std::map<Id, std::unique_ptr<Paragraph> >::iterator it = parStyles.find(id_);
137 if (it != parStyles.end())
138 return *(it->second);
146 Alto::Styles::Paragraph& Alto::Styles::AddParagraphStyle(
const Id &id_)
148 Element el(PushBackElement(
"ParagraphStyle"));
150 auto res = parStyles.insert(std::make_pair(id_, std::unique_ptr<Paragraph>(
new Paragraph(el))));
151 return *res.first->second;
158 Alto::Styles::Text::Text(
const Element &el):
161 id = GetAttribute<StringUTF8>(
"ID",
false);
162 GetAttribute<double>(
"FONTSIZE",
false);
168 StringUTF8 str = GetAttribute<StringUTF8>(
"FONTFAMILY");
174 void Alto::Styles::Text::SetFontFamily(
const StringUTF8 &ff)
176 SetAttribute(
"FONTFAMILY", ff);
179 void Alto::Styles::Text::UnsetFontFamily()
181 RemoveAttribute(
"FONTFAMILY");
187 StringUTF8 str = GetAttribute<StringUTF8>(
"FONTTYPE");
191 fontType = Text::FontType::Serif;
192 else if (str ==
"sans-serif")
193 fontType = Text::FontType::SansSerif;
198 void Alto::Styles::Text::SetFontType(Alto::Styles::Text::FontType ft)
202 case Text::FontType::Serif:
203 SetAttribute(
"FONTTYPE",
"Serif");
205 case Text::FontType::SansSerif:
206 SetAttribute(
"FONTTYPE",
"Sans-Serif");
211 void Alto::Styles::Text::UnsetFontType()
213 RemoveAttribute(
"FONTTYPE");
219 StringUTF8 str = GetAttribute<StringUTF8>(
"FONTWIDTH");
222 if (str ==
"proporitional")
223 fontWidth = Text::FontWidth::Proportional;
224 else if (str ==
"fixed")
225 fontWidth = Text::FontWidth::Fixed;
230 void Alto::Styles::Text::SetFontWidth(Alto::Styles::Text::FontWidth fw)
234 case Text::FontWidth::Proportional:
235 SetAttribute(
"FONTWIDTH",
"proportional");
237 case Text::FontWidth::Fixed:
238 SetAttribute(
"FONTWIDTH",
"fixed");
243 void Alto::Styles::Text::UnsetFontWidth()
245 RemoveAttribute(
"FONTWIDTH");
248 double Alto::Styles::Text::GetFontSize()
const
250 return GetAttribute<double>(
"FONTSIZE",
false);
253 void Alto::Styles::Text::SetFontSize(
double fs)
255 SetAttribute(
"FONTSIZE", fs);
261 try { fontColor = GetAttribute<unsigned int>(
"FONTCOLOR",
false); }
catch (...) { }
265 void Alto::Styles::Text::SetFontColor(uint32_t fc)
267 SetAttribute(
"FONTCOLOR", fc);
270 void Alto::Styles::Text::UnsetFontColor()
272 RemoveAttribute(
"FONTCOLOR");
278 StringUTF8 str = GetAttribute<StringUTF8>(
"FONTSTYLE");
281 FontStyle val = FontStyle::Undef;
282 if (str.
Find(
"bold") != String::NPos())
283 val |= Text::FontStyle::Bold;
284 if (str.
Find(
"italics") != String::NPos())
285 val |= Text::FontStyle::Italics;
286 if (str.
Find(
"subscript") != String::NPos())
287 val |= Text::FontStyle::Subscript;
288 if (str.
Find(
"superscript") != String::NPos())
289 val |= Text::FontStyle::Superscript;
290 if (str.
Find(
"smallcaps") != String::NPos())
291 val |= Text::FontStyle::SmallCaps;
292 if (str.
Find(
"underline") != String::NPos())
293 val |= Text::FontStyle::Underline;
294 if (val != FontStyle::Undef)
300 void Alto::Styles::Text::SetFontStyle(Alto::Styles::Text::FontStyle fs)
303 if (!!(fs & Text::FontStyle::Bold))
305 if (!!(fs & Text::FontStyle::Italics))
307 if (!!(fs & Text::FontStyle::Subscript))
309 if (!!(fs & Text::FontStyle::Superscript))
310 av +=
"superscript ";
311 if (!!(fs & Text::FontStyle::SmallCaps))
313 if (!!(fs & Text::FontStyle::Underline))
314 av +=
"undunderline ";
315 SetAttribute(
"FONTSTYLE", av);
318 void Alto::Styles::Text::UnsetFontStyle()
320 RemoveAttribute(
"FontStyle");
327 Alto::Styles::Paragraph::Paragraph(
const Element &el):
330 id = GetAttribute<StringUTF8>(
"ID",
false);
336 StringUTF8 str(GetAttribute<StringUTF8>(
"ALIGN"));
340 align = Paragraph::Align::Left;
341 else if (str ==
"Right")
342 align = Paragraph::Align::Right;
343 else if (str ==
"Center")
344 align = Paragraph::Align::Center;
345 else if (str ==
"Block")
346 align = Paragraph::Align::Block;
351 void Alto::Styles::Paragraph::SetAlign(Alto::Styles::Paragraph::Align a)
355 case Paragraph::Align::Left:
356 SetAttribute(
"ALIGN",
"Left");
358 case Paragraph::Align::Right:
359 SetAttribute(
"ALIGN",
"Right");
361 case Paragraph::Align::Center:
362 SetAttribute(
"ALIGN",
"Center");
364 case Paragraph::Align::Block:
365 SetAttribute(
"ALIGN",
"Block");
370 void Alto::Styles::Paragraph::UnsetAlign()
372 RemoveAttribute(
"ALIGN");
378 try { leftIndent = GetAttribute<double>(
"LEFT",
false); }
catch (...) { }
382 void Alto::Styles::Paragraph::UnsetLeftIndent()
384 RemoveAttribute(
"LEFT");
387 void Alto::Styles::Paragraph::SetLeftIndent(
double i)
389 SetAttribute(
"LEFT", i);
395 try { rightIndent = GetAttribute<double>(
"RIGHT",
false); }
catch (...) { }
399 void Alto::Styles::Paragraph::SetRightIndent(
double i)
401 SetAttribute(
"RIGHT", i);
404 void Alto::Styles::Paragraph::UnsetRightIndent()
406 RemoveAttribute(
"RIGHT");
412 try { ls = GetAttribute<double>(
"LINESPACE",
false); }
catch (...) { }
416 void Alto::Styles::Paragraph::SetLineSpace(
double i)
418 SetAttribute(
"LINESPACE", i);
421 void Alto::Styles::Paragraph::UnsetLineSpace()
423 RemoveAttribute(
"LINESPACE");
426 Option<double> Alto::Styles::Paragraph::GetFirstLineIndent()
const
429 try { fli = GetAttribute<double>(
"FIRSTLINE",
false); }
catch (...) { }
433 void Alto::Styles::Paragraph::SetFirstLineIndent(
double i)
435 SetAttribute(
"FIRSTLINE", i);
438 void Alto::Styles::Paragraph::UnsetFirstLineIndent()
440 RemoveAttribute(
"FIRSTLINE");
StringUTF8 GetName() const
Gets the label of the element.
bool IsNotEmpty() const noexcept
Checks if the string is not empty.
void SetAttribute(const StringUTF8 &name, const StringUTF8 &value)
Sets the value of an attribute.
A character string class.
size_t Find(const StringUTF8 &s, size_t from_pos=0) const
Finds the first occurrence of a string.
A class to store an optional value.
An item was not found in a container.