libcrn  3.9.5
A document image processing library
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CRNAlto.cpp
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: CRNAltoUtils.h
19  * \author Yann LEYDIER
20  */
21 
22 #include <CRNXml/CRNAlto.h>
23 #include <CRNException.h>
24 #include <CRNi18n.h>
25 
26 using namespace crn;
27 using namespace xml;
28 
36 Alto::Alto(const Path &fname, bool char_conversion_throws):
37  Document(fname, char_conversion_throws)
38 {
39  root.reset(new Root(GetRoot()));
40  register_ids();
41 }
42 
50 Alto::Alto(const Path &imagename, const StringUTF8 &ns, const StringUTF8 &encoding, const StringUTF8 &version, bool char_conversion_throws):
51  Document(encoding, version, char_conversion_throws)
52 {
53  PushBackComment("Created by CoReNum Nimrod Alto engine");
54  root.reset(new Root(PushBackElement("Alto"), imagename, ns));
55 }
56 
63 Alto::Layout::Page& Alto::GetPage(const Id &id)
64 {
65  std::vector<Layout::PagePtr> pages(GetLayout().GetPages());
66  for (const Layout::PagePtr &p : pages)
67  {
68  const std::shared_ptr<Layout::Page> sp(p.lock());
69  if (sp->GetId() == id)
70  return *sp;
71  } // pages
72  throw ExceptionNotFound(_("Page not found."));
73 }
74 
81 const Alto::Layout::Page& Alto::GetPage(const Id &id) const
82 {
83  std::vector<Layout::PagePtr> pages(GetLayout().GetPages());
84  for (const Layout::PagePtr &p : pages)
85  {
86  const std::shared_ptr<const Layout::Page> sp(p.lock());
87  if (sp->GetId() == id)
88  return *sp;
89  } // pages
90  throw ExceptionNotFound(_("Page not found."));
91 }
92 
99 Alto::Layout::Page::Space& Alto::GetSpace(const Id &id)
100 {
101  std::vector<Layout::PagePtr> pages(GetLayout().GetPages());
102  for (const Layout::PagePtr &p : pages)
103  {
104  std::vector<Layout::Page::SpacePtr> spaces(p.lock()->GetSpaces());
105  for (const Layout::Page::SpacePtr &s : spaces)
106  {
107  const std::shared_ptr<Layout::Page::Space> ss(s.lock());
108  if (ss->GetId())
109  if (ss->GetId().Get() == id)
110  return *ss;
111  } // spaces
112  } // pages
113  throw ExceptionNotFound(_("Space not found."));
114 }
115 
122 const Alto::Layout::Page::Space& Alto::GetSpace(const Id &id) const
123 {
124  std::vector<Layout::PagePtr> pages(GetLayout().GetPages());
125  for (const Layout::PagePtr &p : pages)
126  {
127  std::vector<Layout::Page::SpacePtr> spaces(p.lock()->GetSpaces());
128  for (const Layout::Page::SpacePtr &s : spaces)
129  {
130  const std::shared_ptr<const Layout::Page::Space> ss(s.lock());
131  if (ss->GetId())
132  if (ss->GetId().Get() == id)
133  return *ss;
134  } // spaces
135  } // pages
136  throw ExceptionNotFound(_("Space not found."));
137 }
138 
145 Alto::Layout::Page::Space::Block& Alto::GetBlock(const Id &id)
146 {
147  std::vector<Layout::PagePtr> pages(GetLayout().GetPages());
148  for (const Layout::PagePtr &p : pages)
149  {
150  std::vector<Layout::Page::SpacePtr> spaces(p.lock()->GetSpaces());
151  for (const Layout::Page::SpacePtr &s : spaces)
152  {
153  std::vector<Layout::Page::Space::BlockPtr> blocks(s.lock()->GetBlocks());
154  for (const Layout::Page::Space::BlockPtr &b : blocks)
155  {
156  const std::shared_ptr<Layout::Page::Space::Block> sb(b.lock());
157  if (sb->GetId() == id)
158  return *sb;
159  } // blocks
160  } // spaces
161  } // pages
162  throw ExceptionNotFound(_("Block not found."));
163 }
164 
171 const Alto::Layout::Page::Space::Block& Alto::GetBlock(const Id &id) const
172 {
173  std::vector<Layout::PagePtr> pages(GetLayout().GetPages());
174  for (const Layout::PagePtr &p : pages)
175  {
176  std::vector<Layout::Page::SpacePtr> spaces(p.lock()->GetSpaces());
177  for (const Layout::Page::SpacePtr &s : spaces)
178  {
179  std::vector<Layout::Page::Space::BlockPtr> blocks(s.lock()->GetBlocks());
180  for (const Layout::Page::Space::BlockPtr &b : blocks)
181  {
182  const std::shared_ptr<const Layout::Page::Space::Block> sb(b.lock());
183  if (sb->GetId() == id)
184  return *sb;
185  } // blocks
186  } // spaces
187  } // pages
188  throw ExceptionNotFound(_("Block not found."));
189 }
190 
197 Alto::Layout::Page::Space::TextBlock& Alto::GetTextBlock(const Id &id)
198 {
199  std::vector<Layout::PagePtr> pages(GetLayout().GetPages());
200  for (const Layout::PagePtr &p : pages)
201  {
202  std::vector<Layout::Page::SpacePtr> spaces(p.lock()->GetSpaces());
203  for (const Layout::Page::SpacePtr &s : spaces)
204  {
205  std::vector<Layout::Page::Space::BlockPtr> blocks(s.lock()->GetBlocks());
206  for (const Layout::Page::Space::BlockPtr &b : blocks)
207  {
208  const std::shared_ptr<Layout::Page::Space::TextBlock> tb(std::dynamic_pointer_cast<Layout::Page::Space::TextBlock>(b.lock()));
209  if (tb)
210  {
211  if (tb->GetId() == id)
212  return *tb;
213  } // text block
214  } // blocks
215  } // spaces
216  } // pages
217  throw ExceptionNotFound(_("Text block not found."));
218 }
219 
226 const Alto::Layout::Page::Space::TextBlock& Alto::GetTextBlock(const Id &id) const
227 {
228  std::vector<Layout::PagePtr> pages(GetLayout().GetPages());
229  for (const Layout::PagePtr &p : pages)
230  {
231  std::vector<Layout::Page::SpacePtr> spaces(p.lock()->GetSpaces());
232  for (const Layout::Page::SpacePtr &s : spaces)
233  {
234  std::vector<Layout::Page::Space::BlockPtr> blocks(s.lock()->GetBlocks());
235  for (const Layout::Page::Space::BlockPtr &b : blocks)
236  {
237  const std::shared_ptr<const Layout::Page::Space::TextBlock> tb(std::dynamic_pointer_cast<Layout::Page::Space::TextBlock>(b.lock()));
238  if (tb)
239  {
240  if (tb->GetId() == id)
241  return *tb;
242  } // text block
243  } // blocks
244  } // spaces
245  } // pages
246  throw ExceptionNotFound(_("Text block not found."));
247 }
248 
255 Alto::Layout::Page::Space::TextBlock::TextLine& Alto::GetTextLine(const Id &id)
256 {
257  std::vector<Layout::PagePtr> pages(GetLayout().GetPages());
258  for (const Layout::PagePtr &p : pages)
259  {
260  std::vector<Layout::Page::SpacePtr> spaces(p.lock()->GetSpaces());
261  for (const Layout::Page::SpacePtr &s : spaces)
262  {
263  std::vector<Layout::Page::Space::BlockPtr> blocks(s.lock()->GetBlocks());
264  for (const Layout::Page::Space::BlockPtr &b : blocks)
265  {
266  const std::shared_ptr<Layout::Page::Space::TextBlock> tb(std::dynamic_pointer_cast<Layout::Page::Space::TextBlock>(b.lock()));
267  if (tb)
268  {
269  std::vector<Layout::Page::Space::TextBlock::TextLinePtr> lines(tb->GetTextLines());
270  for (const Layout::Page::Space::TextBlock::TextLinePtr &l : lines)
271  {
272  const std::shared_ptr<Layout::Page::Space::TextBlock::TextLine> sl(l.lock());
273  if (sl->GetId() == id)
274  return *sl;
275  } // lines
276  } // text block
277  } // blocks
278  } // spaces
279  } // pages
280  throw ExceptionNotFound(_("Line not found."));
281 }
282 
289 const Alto::Layout::Page::Space::TextBlock::TextLine& Alto::GetTextLine(const Id &id) const
290 {
291  std::vector<Layout::PagePtr> pages(GetLayout().GetPages());
292  for (const Layout::PagePtr &p : pages)
293  {
294  std::vector<Layout::Page::SpacePtr> spaces(p.lock()->GetSpaces());
295  for (const Layout::Page::SpacePtr &s : spaces)
296  {
297  std::vector<Layout::Page::Space::BlockPtr> blocks(s.lock()->GetBlocks());
298  for (const Layout::Page::Space::BlockPtr &b : blocks)
299  {
300  const std::shared_ptr<const Layout::Page::Space::TextBlock> tb(std::dynamic_pointer_cast<Layout::Page::Space::TextBlock>(b.lock()));
301  if (tb)
302  {
303  std::vector<Layout::Page::Space::TextBlock::TextLinePtr> lines(tb->GetTextLines());
304  for (const Layout::Page::Space::TextBlock::TextLinePtr &l : lines)
305  {
306  const std::shared_ptr<const Layout::Page::Space::TextBlock::TextLine> sl(l.lock());
307  if (sl->GetId() == id)
308  return *sl;
309  } // lines
310  } // text block
311  } // blocks
312  } // spaces
313  } // pages
314  throw ExceptionNotFound(_("Line not found."));
315 }
316 
323 Alto::Layout::Page::Space::TextBlock::TextLine::Word& Alto::GetWord(const Id &id)
324 {
325  std::vector<Layout::PagePtr> pages(GetLayout().GetPages());
326  for (const Layout::PagePtr &p : pages)
327  {
328  std::vector<Layout::Page::SpacePtr> spaces(p.lock()->GetSpaces());
329  for (const Layout::Page::SpacePtr &s : spaces)
330  {
331  std::vector<Layout::Page::Space::BlockPtr> blocks(s.lock()->GetBlocks());
332  for (const Layout::Page::Space::BlockPtr &b : blocks)
333  {
334  const std::shared_ptr<Layout::Page::Space::TextBlock> tb(std::dynamic_pointer_cast<Layout::Page::Space::TextBlock>(b.lock()));
335  if (tb)
336  {
337  std::vector<Layout::Page::Space::TextBlock::TextLinePtr> lines(tb->GetTextLines());
338  for (const Layout::Page::Space::TextBlock::TextLinePtr &l : lines)
339  {
340  std::vector<Layout::Page::Space::TextBlock::TextLine::LineElementPtr> lels(l.lock()->GetLineElements());
341  for (const Layout::Page::Space::TextBlock::TextLine::LineElementPtr lel : lels)
342  {
343  const std::shared_ptr<Layout::Page::Space::TextBlock::TextLine::Word> w(std::dynamic_pointer_cast<Layout::Page::Space::TextBlock::TextLine::Word>(lel.lock()));
344  if (w)
345  {
346  if (w->GetId())
347  if (w->GetId().Get() == id)
348  return *w;
349  } // word
350  } // line elements
351  } // lines
352  } // text block
353  } // blocks
354  } // spaces
355  } // pages
356  throw ExceptionNotFound(_("Word not found."));
357 }
358 
365 const Alto::Layout::Page::Space::TextBlock::TextLine::Word& Alto::GetWord(const Id &id) const
366 {
367  std::vector<Layout::PagePtr> pages(GetLayout().GetPages());
368  for (const Layout::PagePtr &p : pages)
369  {
370  std::vector<Layout::Page::SpacePtr> spaces(p.lock()->GetSpaces());
371  for (const Layout::Page::SpacePtr &s : spaces)
372  {
373  std::vector<Layout::Page::Space::BlockPtr> blocks(s.lock()->GetBlocks());
374  for (const Layout::Page::Space::BlockPtr &b : blocks)
375  {
376  const std::shared_ptr<const Layout::Page::Space::TextBlock> tb(std::dynamic_pointer_cast<Layout::Page::Space::TextBlock>(b.lock()));
377  if (tb)
378  {
379  std::vector<Layout::Page::Space::TextBlock::TextLinePtr> lines(tb->GetTextLines());
380  for (const Layout::Page::Space::TextBlock::TextLinePtr &l : lines)
381  {
382  std::vector<Layout::Page::Space::TextBlock::TextLine::LineElementPtr> lels(l.lock()->GetLineElements());
383  for (const Layout::Page::Space::TextBlock::TextLine::LineElementPtr lel : lels)
384  {
385  const std::shared_ptr<const Layout::Page::Space::TextBlock::TextLine::Word> w(std::dynamic_pointer_cast<const Layout::Page::Space::TextBlock::TextLine::Word>(lel.lock()));
386  if (w)
387  {
388  if (w->GetId())
389  if (w->GetId().Get() == id)
390  return *w;
391  } // word
392  } // line elements
393  } // lines
394  } // text block
395  } // blocks
396  } // spaces
397  } // pages
398  throw ExceptionNotFound(_("Word not found."));
399 }
400 
408 {
409  std::vector<Layout::PagePtr> pages(GetLayout().GetPages());
410  for (const Layout::PagePtr &p : pages)
411  {
412  const std::shared_ptr<Layout::Page> sp(p.lock());
413  if (sp->GetId() == id)
414  return *sp;
415  std::vector<Layout::Page::SpacePtr> spaces(sp->GetSpaces());
416  for (const Layout::Page::SpacePtr &s : spaces)
417  {
418  const std::shared_ptr<Layout::Page::Space> ss(s.lock());
419  if (ss->GetId())
420  if (ss->GetId().Get() == id)
421  return *ss;
422  std::vector<Layout::Page::Space::BlockPtr> blocks(ss->GetBlocks());
423  for (Layout::Page::Space::BlockPtr &b : blocks)
424  {
425  const std::shared_ptr<Layout::Page::Space::Block> sb(b.lock());
426  if (sb->GetId() == id)
427  return *sb;
428  const std::shared_ptr<Layout::Page::Space::TextBlock> tb(std::dynamic_pointer_cast<Layout::Page::Space::TextBlock>(sb));
429  if (tb)
430  {
431  std::vector<Layout::Page::Space::TextBlock::TextLinePtr> lines(tb->GetTextLines());
432  for (const Layout::Page::Space::TextBlock::TextLinePtr &l : lines)
433  {
434  const std::shared_ptr<Layout::Page::Space::TextBlock::TextLine> sl(l.lock());
435  if (sl->GetId() == id)
436  return *sl;
437  std::vector<Layout::Page::Space::TextBlock::TextLine::LineElementPtr> lels(sl->GetLineElements());
438  for (const Layout::Page::Space::TextBlock::TextLine::LineElementPtr lel : lels)
439  {
440  const std::shared_ptr<Layout::Page::Space::TextBlock::TextLine::Word> w(std::dynamic_pointer_cast<Layout::Page::Space::TextBlock::TextLine::Word>(lel.lock()));
441  if (w)
442  {
443  if (w->GetId())
444  if (w->GetId().Get() == id)
445  return *w;
446  } // word
447  else
448  {
449  const std::shared_ptr<Layout::Page::Space::TextBlock::TextLine::WhiteSpace> s(std::dynamic_pointer_cast<Layout::Page::Space::TextBlock::TextLine::WhiteSpace>(lel.lock()));
450  if (s)
451  {
452  if (s->GetId())
453  if (s->GetId().Get() == id)
454  return *s;
455  } // white space
456  }
457  } // line elements
458  } // lines
459  } // text block
460  } // blocks
461  } // spaces
462  } // pages
463  throw ExceptionNotFound(_("Element not found."));
464 }
465 
472 const Element& Alto::GetElement(const Id &id) const
473 {
474  std::vector<Layout::PagePtr> pages(GetLayout().GetPages());
475  for (const Layout::PagePtr &p : pages)
476  {
477  const std::shared_ptr<const Layout::Page> sp(p);
478  if (sp->GetId() == id)
479  return *sp;
480  std::vector<Layout::Page::SpacePtr> spaces(sp->GetSpaces());
481  for (const Layout::Page::SpacePtr &s : spaces)
482  {
483  const std::shared_ptr<const Layout::Page::Space> ss(s.lock());
484  if (ss->GetId())
485  if (ss->GetId().Get() == id)
486  return *ss;
487  std::vector<Layout::Page::Space::BlockPtr> blocks(ss->GetBlocks());
488  for (const Layout::Page::Space::BlockPtr &b : blocks)
489  {
490  const std::shared_ptr<const Layout::Page::Space::Block> sb(b.lock());
491  if (sb->GetId() == id)
492  return *sb;
493  const std::shared_ptr<const Layout::Page::Space::TextBlock> tb(std::dynamic_pointer_cast<const Layout::Page::Space::TextBlock>(sb));
494  if (tb)
495  {
496  std::vector<Layout::Page::Space::TextBlock::TextLinePtr> lines(tb->GetTextLines());
497  for (const Layout::Page::Space::TextBlock::TextLinePtr &l : lines)
498  {
499  const std::shared_ptr<const Layout::Page::Space::TextBlock::TextLine> sl(l.lock());
500  if (sl->GetId() == id)
501  return *sl;
502  std::vector<Layout::Page::Space::TextBlock::TextLine::LineElementPtr> lels(sl->GetLineElements());
503  for (const Layout::Page::Space::TextBlock::TextLine::LineElementPtr lel : lels)
504  {
505  const std::shared_ptr<const Layout::Page::Space::TextBlock::TextLine::Word> w(std::dynamic_pointer_cast<Layout::Page::Space::TextBlock::TextLine::Word>(lel.lock()));
506  if (w)
507  {
508  if (w->GetId())
509  if (w->GetId().Get() == id)
510  return *w;
511  } // word
512  else
513  {
514  const std::shared_ptr<const Layout::Page::Space::TextBlock::TextLine::WhiteSpace> s(std::dynamic_pointer_cast<Layout::Page::Space::TextBlock::TextLine::WhiteSpace>(lel.lock()));
515  if (s)
516  {
517  if (s->GetId())
518  if (s->GetId().Get() == id)
519  return *s;
520  } // white space
521  }
522  } // line elements
523  } // lines
524  } // text block
525  } // blocks
526  } // spaces
527  } // pages
528  throw ExceptionNotFound(_("Element not found."));
529 }
530 
532 void Alto::register_ids()
533 {
534  std::vector<Id> lst(GetStyles().GetTextStyles());
535  ids.insert(lst.begin(), lst.end());
536  lst = GetStyles().GetParagraphStyles();
537  ids.insert(lst.begin(), lst.end());
538  std::vector<Layout::PagePtr> pages(GetLayout().GetPages());
539  for (const Layout::PagePtr &p : pages)
540  {
541  const std::shared_ptr<const Layout::Page> sp(p.lock());
542  ids.insert(sp->GetId());
543  std::vector<Layout::Page::SpacePtr> spaces(sp->GetSpaces());
544  for (const Layout::Page::SpacePtr &s : spaces)
545  {
546  const std::shared_ptr<const Layout::Page::Space> ss(s.lock());
547  if (ss->GetId())
548  ids.insert(ss->GetId().Get());
549  std::vector<Layout::Page::Space::BlockPtr> blocks(ss->GetBlocks());
550  for (const Layout::Page::Space::BlockPtr &b : blocks)
551  {
552  const std::shared_ptr<const Layout::Page::Space::Block> sb(b.lock());
553  ids.insert(sb->GetId());
554  const std::shared_ptr<const Layout::Page::Space::TextBlock> tb(std::dynamic_pointer_cast<const Layout::Page::Space::TextBlock>(sb));
555  if (tb)
556  {
557  std::vector<Layout::Page::Space::TextBlock::TextLinePtr> lines(tb->GetTextLines());
558  for (const Layout::Page::Space::TextBlock::TextLinePtr &l : lines)
559  {
560  const std::shared_ptr<const Layout::Page::Space::TextBlock::TextLine> sl(l.lock());
561  ids.insert(sl->GetId());
562  std::vector<Layout::Page::Space::TextBlock::TextLine::LineElementPtr> lels(sl->GetLineElements());
563  for (const Layout::Page::Space::TextBlock::TextLine::LineElementPtr lel : lels)
564  {
565  const std::shared_ptr<const Layout::Page::Space::TextBlock::TextLine::Word> w(std::dynamic_pointer_cast<Layout::Page::Space::TextBlock::TextLine::Word>(lel.lock()));
566  if (w)
567  {
568  if (w->GetId())
569  ids.insert(w->GetId().Get());
570  } // word
571  else
572  {
573  const std::shared_ptr<const Layout::Page::Space::TextBlock::TextLine::WhiteSpace> s(std::dynamic_pointer_cast<Layout::Page::Space::TextBlock::TextLine::WhiteSpace>(lel.lock()));
574  if (s)
575  {
576  if (s->GetId())
577  ids.insert(s->GetId().Get());
578  } // white space
579  }
580  } // line elements
581  } // lines
582  } // text block
583  } // blocks
584  } // spaces
585  } // pages
586 }
587 
592 {
593  bool ok = false;
594  Id id;
595  while (!ok)
596  {
598  if (ids.find(id) == ids.end())
599  {
600  ids.insert(id);
601  ok = true;
602  }
603  }
604  return id;
605 }
606 
611 bool Alto::CheckId(const Id &id) const
612 {
613  return ids.find(id) == ids.end();
614 }
615 
623 {
624  try
625  {
626  el.GetAttribute<StringUTF8>("ID", false);
627  throw crn::ExceptionInvalidArgument(_("The element already has an id."));
628  }
629  catch (crn::ExceptionNotFound&)
630  { }
631  Id id(CreateId());
632  el.SetAttribute("ID", id);
633  return id;
634 }
635 
637 // Root
639 
645 Alto::Root::Root(const Element &el):
646  Element(el)
647 {
648  if (!el)
649  throw ExceptionInvalidArgument(_("Null node."));
650  for (Element cel = BeginElement(); cel != EndElement(); ++cel)
651  {
652  StringUTF8 elname(cel.GetName());
653  if (elname == "Description")
654  {
655  description.reset(new Description(cel));
656  }
657  else if (elname == "Styles")
658  {
659  styles.reset(new Styles(cel));
660  }
661  else if (elname == "Layout")
662  {
663  layout.reset(new Layout(cel));
664  }
665  }
666  if (!layout) // mandatory element!
667  throw crn::ExceptionNotFound(_("Cannot find layout."));
668  init("file:///dev/null");
669 }
670 
677 Alto::Root::Root(const Element &el, const Path &imagename, const StringUTF8 &ns):
678  Element(el)
679 {
680  if (ns.IsEmpty())
681  throw crn::ExceptionInvalidArgument(_("Null namespace."));
682  SetAttribute("xmlns:xsi", "http://www.w3.org/2001/XMLSchema-instance");
683  SetAttribute("xmlns", ns);
684  StringUTF8 nsloc(ns);
685  nsloc += " ";
686  nsloc += "http://www.loc.gov/standards/alto/alto-v2.0.xsd";
687  SetAttribute("xsi:schemaLocation", nsloc);
688  SetAttribute("xmlns:xlink", "http://www.w3.org/TR/xlink");
689  init(imagename);
690 }
691 
695 void Alto::Root::init(const StringUTF8 &imgname)
696 {
697  if (!description)
698  description.reset(new Description(PushBackElement("Description"), imgname));
699  if (!styles)
700  styles.reset(new Styles(PushBackElement("Styles")));
701  if (!layout)
702  layout.reset(new Layout(PushBackElement("Layout")));
703 }
704 
XML Alto layout element.
Id CreateId()
Creates a new id for the document.
Definition: CRNAlto.cpp:591
Layout::Page::Space::TextBlock::TextLine & GetTextLine(const Id &id)
Definition: CRNAlto.cpp:255
List of styles used in the document.
Styles & GetStyles()
Gets the styles description part of the Alto (may be null)
Definition: CRNAlto.h:96
Comment PushBackComment(const StringUTF8 &text)
Adds a comment at the end of the children list.
Definition: CRNXml.cpp:1126
static crn::StringUTF8 CreateUniqueId(size_t len=8)
Generates an almost unique id.
XML element.
Definition: CRNXml.h:135
#define _(String)
Definition: CRNi18n.h:51
Element EndElement()
Gets a null node.
Definition: CRNXml.h:481
XML document.
Definition: CRNXml.h:429
Element GetRoot()
Gets the first element.
Definition: CRNXml.cpp:1034
Element PushBackElement(const StringUTF8 &name)
Adds an element at the end of the children list.
Definition: CRNXml.cpp:1087
std::vector< Id > GetParagraphStyles() const
Returns the ids of the paragraph styles.
Layout::Page::Space::Block & GetBlock(const Id &id)
Definition: CRNAlto.cpp:145
bool IsEmpty() const noexcept
Checks if the string is empty.
bool CheckId(const Id &id) const
Checks if an id already exists in the document.
Definition: CRNAlto.cpp:611
A convenience class for file paths.
Definition: CRNPath.h:39
Id AddId(Element &el)
Adds an id to an element.
Definition: CRNAlto.cpp:622
std::weak_ptr< Space > SpacePtr
Element BeginElement()
Gets the first child element.
Definition: CRNXml.h:479
void SetAttribute(const StringUTF8 &name, const StringUTF8 &value)
Sets the value of an attribute.
Definition: CRNXml.cpp:595
Layout & GetLayout()
Gets the layout description part of the Alto.
Definition: CRNAlto.h:101
Layout::Page & GetPage(const Id &id)
Definition: CRNAlto.cpp:63
T GetAttribute(const StringUTF8 &name, bool silent=true) const
Gets an attribute.
Definition: CRNXml.h:219
Element & GetElement(const Id &id)
Definition: CRNAlto.cpp:407
Layout::Page::Space & GetSpace(const Id &id)
Definition: CRNAlto.cpp:99
std::weak_ptr< Page > PagePtr
Alto global description.
A character string class.
Definition: CRNStringUTF8.h:49
Alto(const Path &fname, bool char_conversion_throws=true)
Constructor from a file.
Definition: CRNAlto.cpp:36
Layout::Page::Space::TextBlock & GetTextBlock(const Id &id)
Definition: CRNAlto.cpp:197
Invalid argument error (e.g.: nullptr pointer)
Definition: CRNException.h:107
Layout::Page::Space::TextBlock::TextLine::Word & GetWord(const Id &id)
Definition: CRNAlto.cpp:323
An item was not found in a container.
Definition: CRNException.h:95