35 Alto::Layout::Layout(
const Element &el):
44 void Alto::Layout::update_subelements()
49 Element pel = GetFirstChildElement(
"Page");
52 pages.push_back(std::shared_ptr<Page>(
new Page(pel)));
53 id_pages[pages.back()->GetId()] = pages.back();
59 std::vector<Id> Alto::Layout::GetStyles()
const
67 void Alto::Layout::AddStyle(
const Id &styleid)
75 void Alto::Layout::RemoveStyle(
const Id &styleid)
85 Alto::Layout::Page& Alto::Layout::GetPage(
const Id &pid)
87 if (GetNbSubelements() != pages.size())
88 const_cast<Layout*>(
this)->update_subelements();
89 std::map<Id, std::weak_ptr<Page>>::iterator it(id_pages.find(pid));
90 if ((it != id_pages.end()) && !it->second.expired())
91 return *(it->second.lock());
92 for (
const PagePtr &p : pages)
94 const std::shared_ptr<Layout::Page> sp(p.lock());
95 if (sp->GetId() == pid)
105 std::vector<Alto::Layout::PagePtr> Alto::Layout::GetPages()
const
107 if (GetNbSubelements() != pages.size())
108 const_cast<Layout*>(
this)->update_subelements();
109 return std::vector<PagePtr>(pages.begin(), pages.end());
122 pages.push_back(std::shared_ptr<Page>(
new Page(PushBackElement(
"Page"), id_, image_number, width_, height_, pos)));
123 id_pages[id_] = pages.back();
124 return *pages.back();
139 for (std::vector<std::shared_ptr<Page> >::iterator it = pages.begin(); it != pages.end(); ++it)
141 if ((*it)->GetId() == pred)
145 if (it == pages.end())
146 return AddPage(id_, image_number, width_, height_, pos);
149 std::shared_ptr<Page> p(
new Page(InsertElement(pel,
"Page"), id_, image_number, width_, height_, pos));
171 for (std::vector<std::shared_ptr<Page> >::iterator it = pages.begin(); it != pages.end(); ++it)
173 if ((*it)->GetId() == next)
175 std::shared_ptr<Page> newpage;
176 if (it == pages.begin())
177 newpage = std::shared_ptr<Page>(
new Page(PushFrontElement(
"Page"), id_, image_number, width_, height_, pos));
179 newpage = std::shared_ptr<Page>(
new Page(InsertElement(**(it - 1),
"Page"), id_, image_number, width_, height_, pos));
180 pages.insert(it, newpage);
181 id_pages[id_] = newpage;
192 void Alto::Layout::RemovePage(
const Id &pid)
194 for (std::vector<std::shared_ptr<Page> >::iterator it = pages.begin(); it != pages.end(); ++it)
196 if ((*it)->GetId() == pid)
214 Alto::Layout::Page::Page(
const Element &el):
220 update_subelements();
224 void Alto::Layout::Page::update_subelements()
228 topMargin = leftMargin = rightMargin = bottomMargin = printSpace = SpacePtr();
230 for (
Element cel = BeginElement(); cel != EndElement(); ++cel)
233 std::shared_ptr<Space> sp;
234 if (elname ==
"TopMargin")
236 sp = std::shared_ptr<Space>(
new Space(cel));
239 else if (elname ==
"LeftMargin")
241 sp = std::shared_ptr<Space>(
new Space(cel));
244 else if (elname ==
"RightMargin")
246 sp = std::shared_ptr<Space>(
new Space(cel));
249 else if (elname ==
"BottomMargin")
251 sp = std::shared_ptr<Space>(
new Space(cel));
254 else if (elname ==
"PrintSpace")
256 sp = std::shared_ptr<Space>(
new Space(cel));
261 spaces.push_back(sp);
263 id_spaces[sp->GetId().Get()] = sp;
280 SetAttribute(
"ID",
id);
281 SetAttribute(
"PHYSICAL_IMG_NR", image_number);
283 SetAttribute(
"WIDTH", *width);
285 SetAttribute(
"HEIGHT", *height);
294 case Position::Right:
297 case Position::Foldout:
300 case Position::Single:
303 case Position::Cover:
309 SetAttribute(
"POSITION", av);
314 std::vector<Id> Alto::Layout::Page::GetStyles()
const
322 void Alto::Layout::Page::AddStyle(
const Id &styleid)
330 void Alto::Layout::Page::RemoveStyle(
const Id &styleid)
339 StringUTF8 str = GetAttribute<StringUTF8>(
"PAGECLASS");
348 void Alto::Layout::Page::SetPageClass(
const StringUTF8 &s)
350 SetAttribute(
"PAGECLASS", s);
357 try { height = GetAttribute<int>(
"HEIGHT",
false); }
catch (...) {}
362 void Alto::Layout::Page::SetHeight(
int i)
364 SetAttribute(
"HEIGHT", i);
371 try { width = GetAttribute<int>(
"WIDTH",
false); }
catch (...) {}
376 void Alto::Layout::Page::SetWidth(
int i)
378 SetAttribute(
"WIDTH", i);
382 int Alto::Layout::Page::GetPhysicalImageNumber()
const
384 return GetAttribute<int>(
"PHYSICAL_IMG_NR",
false);
391 StringUTF8 str = GetAttribute<StringUTF8>(
"PRINTED_IMG_NR");
393 printedImageNumber = str;
394 return printedImageNumber;
401 void Alto::Layout::Page::SetPhysicalImageNumber(
int pnum)
405 SetAttribute(
"PHYSICAL_IMG_NR", pnum);
411 void Alto::Layout::Page::SetPrintedImageNumber(
const StringUTF8 &s)
413 SetAttribute(
"PRINTED_IMG_NR", s);
420 StringUTF8 str = GetAttribute<StringUTF8>(
"QUALITY");
425 quality = Quality::Ok;
426 else if (str ==
"Missing")
427 quality = Quality::Missing;
428 else if (str ==
"Missing in original")
429 quality = Quality::MissingInOriginal;
430 else if (str ==
"Damaged")
431 quality = Quality::Damaged;
432 else if (str ==
"Retained")
433 quality = Quality::Retained;
434 else if (str ==
"Target")
435 quality = Quality::Target;
436 else if (str ==
"As in original")
437 quality = Quality::AsInOriginal;
446 void Alto::Layout::Page::SetQuality(Quality q)
454 case Quality::Missing:
457 case Quality::MissingInOriginal:
458 attr =
"Missing in original";
460 case Quality::Damaged:
463 case Quality::Retained:
466 case Quality::Target:
469 case Quality::AsInOriginal:
470 attr =
"As in original";
475 SetAttribute(
"QUALITY", attr);
482 StringUTF8 str = GetAttribute<StringUTF8>(
"QUALITY_DETAIL");
485 return qualityDetail;
491 void Alto::Layout::Page::SetQualityDetail(
const StringUTF8 &s)
493 SetAttribute(
"QUALITY_DETAIL", s);
500 StringUTF8 str = GetAttribute<StringUTF8>(
"POSITION");
505 position = Position::Left;
506 else if (str ==
"Right")
507 position = Position::Right;
508 else if (str ==
"Foldout")
509 position = Position::Foldout;
510 else if (str ==
"Single")
511 position = Position::Single;
512 else if (str ==
"Cover")
513 position = Position::Cover;
519 Option<Id> Alto::Layout::Page::GetProcessing()
const
522 StringUTF8 str = GetAttribute<StringUTF8>(
"PROCESSING");
532 try { accuracy = GetAttribute<double>(
"ACCURACY",
false); }
catch (...) {}
540 void Alto::Layout::Page::SetAccuracy(
double acc)
542 if ((acc < 0.0) || (acc > 100.0))
544 SetAttribute(
"ACCURACY", acc);
551 try { pageConfidence = GetAttribute<double>(
"PC",
false); }
catch (...) {}
552 return pageConfidence;
559 void Alto::Layout::Page::SetPageConfidence(
double c)
561 if ((c < 0.0) || (c > 100.0))
563 SetAttribute(
"PC", c);
574 Alto::Layout::Page::Space& Alto::Layout::Page::AddTopMargin(
const Id &id_,
double x,
double y,
double w,
double h)
576 if (!topMargin.expired())
578 spaces.push_back(std::shared_ptr<Space>(
new Space(PushBackElement(
"TopMargin"), id_, x, y, w, h)));
579 id_spaces[id_] = spaces.back();
580 topMargin = spaces.back();
581 return *topMargin.lock();
592 Alto::Layout::Page::Space& Alto::Layout::Page::AddLeftMargin(
const Id &id_,
double x,
double y,
double w,
double h)
594 if (!leftMargin.expired())
596 spaces.push_back(std::shared_ptr<Space>(
new Space(PushBackElement(
"LeftMargin"), id_, x, y, w, h)));
597 id_spaces[id_] = spaces.back();
598 leftMargin = spaces.back();
599 return *leftMargin.lock();
610 Alto::Layout::Page::Space& Alto::Layout::Page::AddRightMargin(
const Id &id_,
double x,
double y,
double w,
double h)
612 if (!rightMargin.expired())
614 spaces.push_back(std::shared_ptr<Space>(
new Space(PushBackElement(
"RightMargin"), id_, x, y, w, h)));
615 id_spaces[id_] = spaces.back();
616 rightMargin = spaces.back();
617 return *rightMargin.lock();
628 Alto::Layout::Page::Space& Alto::Layout::Page::AddBottomMargin(
const Id &id_,
double x,
double y,
double w,
double h)
630 if (!bottomMargin.expired())
632 spaces.push_back(std::shared_ptr<Space>(
new Space(PushBackElement(
"BottomMargin"), id_, x, y, w, h)));
633 id_spaces[id_] = spaces.back();
634 bottomMargin = spaces.back();
635 return *bottomMargin.lock();
646 Alto::Layout::Page::Space& Alto::Layout::Page::AddPrintSpace(
const Id &id_,
double x,
double y,
double w,
double h)
648 if (!printSpace.expired())
650 spaces.push_back(std::shared_ptr<Space>(
new Space(PushBackElement(
"PrintSpace"), id_, x, y, w, h)));
651 id_spaces[id_] = spaces.back();
652 printSpace = spaces.back();
653 return *printSpace.lock();
661 Alto::Layout::Page::Space& Alto::Layout::Page::GetSpace(
const Id &sid)
663 if (GetNbSubelements() != spaces.size())
664 const_cast<Page*>(
this)->update_subelements();
665 std::map<Id, std::weak_ptr<Space> >::iterator it(id_spaces.find(sid));
666 if ((it != id_spaces.end()) && !it->second.expired())
667 return *(it->second.lock());
668 for (
const SpacePtr &s : spaces)
670 const std::shared_ptr<Layout::Page::Space> ss(s.lock());
671 if (ss->GetId().Get() == sid)
681 std::vector<Alto::Layout::Page::SpacePtr> Alto::Layout::Page::GetSpaces()
const
683 if (GetNbSubelements() != spaces.size())
684 const_cast<Page*>(
this)->update_subelements();
686 return std::vector<SpacePtr>(spaces.begin(), spaces.end());
693 void Alto::Layout::Page::RemoveSpace(
const Id &sid)
695 for (std::vector<std::shared_ptr<Space> >::iterator it = spaces.begin(); it != spaces.end(); ++it)
696 if ((*it)->GetId().Get() == sid)
700 id_spaces.erase(sid);
StringUTF8 & ToLower()
Converts the string to lowercase.
std::vector< Id > GetStyleRefs(const Element &el)
Gets the list of style references.
bool IsNotEmpty() const noexcept
Checks if the string is not empty.
Element GetNextSiblingElement(const StringUTF8 &name="")
Gets the next sibling element.
void AddStyleRef(Element &el, const Id &id)
Adds a style reference to an element.
void RemoveStyleRef(Element &el, const Id &id)
Removes a style reference to an element.
T GetAttribute(const StringUTF8 &name, bool silent=true) const
Gets an attribute.
A character string class.
A class to store an optional value.
Invalid argument error (e.g.: nullptr pointer)
An item was not found in a container.