36 Alto::Layout::Page::Space::Space(
const Element &el):
41 GetAttribute<double>(
"HEIGHT",
false);
42 GetAttribute<double>(
"WIDTH",
false);
43 GetAttribute<double>(
"VPOS",
false);
44 GetAttribute<double>(
"HPOS",
false);
50 void Alto::Layout::Page::Space::update_subelements()
55 id_textBlocks.clear();
56 illustrations.clear();
57 graphicalElements.clear();
58 composedBlocks.clear();
60 for (
Element cel = BeginElement(); cel != EndElement(); ++cel)
62 std::shared_ptr<Block> newblock;
64 if (elname ==
"TextBlock")
67 textBlocks.push_back(std::static_pointer_cast<TextBlock>(newblock));
68 id_textBlocks[newblock->GetId()] = textBlocks.back();
70 else if (elname ==
"Illustration")
72 newblock.reset(
new Illustration(cel));
73 illustrations.push_back(std::static_pointer_cast<Illustration>(newblock));
75 else if (elname ==
"GraphicalElement")
77 newblock.reset(
new GraphicalElement(cel));
78 graphicalElements.push_back(std::static_pointer_cast<GraphicalElement>(newblock));
80 else if (elname ==
"ComposedBlock")
82 newblock.reset(
new ComposedBlock(cel));
83 composedBlocks.push_back(std::static_pointer_cast<ComposedBlock>(newblock));
87 blocks.push_back(newblock);
88 id_blocks[newblock->GetId()] = newblock;
101 Alto::Layout::Page::Space::Space(
const Element &el,
const Id &id_,
double x,
double y,
double w,
double h):
104 SetAttribute(
"ID", id_);
105 SetAttribute(
"HPOS", x);
106 SetAttribute(
"VPOS", y);
107 SetAttribute(
"WIDTH", w);
108 SetAttribute(
"HEIGHT", h);
112 Option<Id> Alto::Layout::Page::Space::GetId()
const
115 StringUTF8 str = GetAttribute<StringUTF8>(
"ID");
122 double Alto::Layout::Page::Space::GetHeight()
const
124 return GetAttribute<double>(
"HEIGHT",
false);
128 void Alto::Layout::Page::Space::SetHeight(
double d)
130 SetAttribute(
"HEIGHT", d);
134 double Alto::Layout::Page::Space::GetWidth()
const
136 return GetAttribute<double>(
"WIDTH",
false);
140 void Alto::Layout::Page::Space::SetWidth(
double d)
142 SetAttribute(
"WIDTH", d);
146 double Alto::Layout::Page::Space::GetHPos()
const
148 return GetAttribute<double>(
"HPOS",
false);
152 void Alto::Layout::Page::Space::SetHPos(
double d)
154 SetAttribute(
"HPOS", d);
158 double Alto::Layout::Page::Space::GetVPos()
const
160 return GetAttribute<double>(
"VPOS",
false);
164 void Alto::Layout::Page::Space::SetVPos(
double d)
166 SetAttribute(
"VPOS", d);
170 std::vector<Id> Alto::Layout::Page::Space::GetStyles()
const
178 void Alto::Layout::Page::Space::AddStyle(
const Id &styleid)
186 void Alto::Layout::Page::Space::RemoveStyle(
const Id &styleid)
196 Alto::Layout::Page::Space::Block& Alto::Layout::Page::Space::GetBlock(
const Id &bid)
198 if (GetNbSubelements() != blocks.size())
199 const_cast<Space*>(
this)->update_subelements();
200 std::map<Id, std::weak_ptr<Block> >::iterator it(id_blocks.find(bid));
201 if ((it != id_blocks.end()) && !it->second.expired())
202 return *(it->second.lock());
203 for (
const BlockPtr &tb : blocks)
205 const std::shared_ptr<Block> stb(tb.lock());
206 if (tb.lock()->GetId() == bid)
216 std::vector<Alto::Layout::Page::Space::BlockPtr> Alto::Layout::Page::Space::GetBlocks()
const
218 if (GetNbSubelements() != blocks.size())
219 const_cast<Space*>(
this)->update_subelements();
220 return std::vector<BlockPtr>(blocks.begin(), blocks.end());
227 void Alto::Layout::Page::Space::RemoveBlock(
const Id &bid)
229 Block &b(GetBlock(bid));
231 textBlocks.erase(std::remove_if(textBlocks.begin(), textBlocks.end(), [&bid](
const TextBlockPtr &p){
return p.lock()->GetId() == bid; }), textBlocks.end());
232 id_textBlocks.erase(bid);
233 illustrations.erase(std::remove_if(illustrations.begin(), illustrations.end(), [&bid](
const IllustrationPtr &p){
return p.lock()->GetId() == bid; }), illustrations.end());
234 graphicalElements.erase(std::remove_if(graphicalElements.begin(), graphicalElements.end(), [&bid](
const GraphicalElementPtr &p){
return p.lock()->GetId() == bid; }), graphicalElements.end());
235 composedBlocks.erase(std::remove_if(composedBlocks.begin(), composedBlocks.end(), [&bid](
const ComposedBlockPtr &p){
return p.lock()->GetId() == bid; }), composedBlocks.end());
236 blocks.erase(std::remove_if(blocks.begin(), blocks.end(), [&bid](
const BlockPtr &p){
return p.lock()->GetId() == bid; }), blocks.end());
237 id_blocks.erase(bid);
241 std::vector<Id> Alto::Layout::Page::Space::Block::GetStyles()
const
249 void Alto::Layout::Page::Space::Block::AddStyle(
const Id &styleid)
257 void Alto::Layout::Page::Space::Block::RemoveStyle(
const Id &styleid)
267 Alto::Layout::Page::Space::TextBlock& Alto::Layout::Page::Space::GetTextBlock(
const Id &
id)
269 if (GetNbSubelements() != blocks.size())
270 const_cast<Space*>(
this)->update_subelements();
271 std::map<Id, TextBlockPtr>::iterator it(id_textBlocks.find(
id));
272 if ((it != id_textBlocks.end()) && !it->second.expired())
273 return *(it->second.lock());
274 for (
const TextBlockPtr &tb : textBlocks)
276 const std::shared_ptr<TextBlock> stb(tb.lock());
277 if (stb->GetId() == id)
279 id_textBlocks[id] = tb;
293 Alto::Layout::Page::Space::TextBlock& Alto::Layout::Page::Space::AddTextBlock(
const Id &id_,
int x,
int y,
int w,
int h)
295 std::shared_ptr<TextBlock> bl(
new TextBlock(PushBackElement(
"TextBlock"), id_, x, y, w, h));
296 blocks.push_back(bl);
298 textBlocks.push_back(bl);
299 id_textBlocks[id_] = textBlocks.back();
312 Alto::Layout::Page::Space::TextBlock& Alto::Layout::Page::Space::AddTextBlockAfter(
const Id &pred,
const Id &id_,
int x,
int y,
int w,
int h)
314 for (std::vector<std::shared_ptr<Block> >::iterator it = blocks.begin(); it != blocks.end(); ++it)
316 if ((*it)->GetId() == pred)
320 if (it == blocks.end())
321 return AddTextBlock(id_, x, y, w, h);
324 std::shared_ptr<TextBlock> bl(
new TextBlock(InsertElement(pel,
"TextBlock"), id_, x, y, w, h));
325 blocks.insert(it, bl);
327 for (; it != blocks.end(); ++it)
329 if (std::dynamic_pointer_cast<TextBlock>(*it))
332 if (it != blocks.end())
333 textBlocks.insert(std::find_if(textBlocks.begin(), textBlocks.end(), [&it](
const TextBlockPtr &p){
return p.lock() == *it; }), bl);
335 textBlocks.push_back(bl);
336 id_textBlocks[id_] = bl;
353 Alto::Layout::Page::Space::TextBlock& Alto::Layout::Page::Space::AddTextBlockBefore(
const Id &next,
const Id &id_,
int x,
int y,
int w,
int h)
355 for (std::vector<std::shared_ptr<Block> >::iterator it = blocks.begin(); it != blocks.end(); ++it)
357 if ((*it)->GetId() == next)
359 std::shared_ptr<TextBlock> bl;
360 if (it == blocks.begin())
361 bl.reset(
new TextBlock(PushFrontElement(
"TextBlock"), id_, x, y, w, h));
363 bl.reset(
new TextBlock(InsertElement(**(it - 1),
"TextBlock"), id_, x, y, w, h));
364 blocks.insert(it, bl);
366 for (; it != blocks.end(); ++it)
368 if (std::dynamic_pointer_cast<TextBlock>(*it))
371 if (it != blocks.end())
372 textBlocks.insert(std::find_if(textBlocks.begin(), textBlocks.end(), [&it](
const TextBlockPtr &p){
return p.lock() == *it; }), bl);
374 textBlocks.push_back(bl);
375 id_textBlocks[id_] = bl;
383 const std::vector<Alto::Layout::Page::Space::IllustrationPtr>& Alto::Layout::Page::Space::GetIllustrations()
const
385 if (GetNbSubelements() != blocks.size())
386 const_cast<Space*>(
this)->update_subelements();
387 return illustrations;
397 Alto::Layout::Page::Space::Illustration& Alto::Layout::Page::Space::AddIllustration(
const Id &id_,
int x,
int y,
int w,
int h)
399 std::shared_ptr<Illustration> bl(
new Illustration(PushBackElement(
"Illustration"), id_, x, y, w, h));
400 blocks.push_back(bl);
402 illustrations.push_back(bl);
415 Alto::Layout::Page::Space::Illustration& Alto::Layout::Page::Space::AddIllustrationAfter(
const Id &pred,
const Id &id_,
int x,
int y,
int w,
int h)
417 for (std::vector<std::shared_ptr<Block> >::iterator it = blocks.begin(); it != blocks.end(); ++it)
419 if ((*it)->GetId() == pred)
423 if (it == blocks.end())
424 return AddIllustration(id_, x, y, w, h);
427 std::shared_ptr<Illustration> bl(
new Illustration(InsertElement(pel,
"Illustration"), id_, x, y, w, h));
428 blocks.insert(it, bl);
430 for (; it != blocks.end(); ++it)
432 if (std::dynamic_pointer_cast<Illustration>(*it))
435 if (it != blocks.end())
436 illustrations.insert(std::find_if(illustrations.begin(), illustrations.end(), [&it](
const IllustrationPtr &p){
return p.lock() == *it; }), bl);
438 illustrations.push_back(bl);
455 Alto::Layout::Page::Space::Illustration& Alto::Layout::Page::Space::AddIllustrationBefore(
const Id &next,
const Id &id_,
int x,
int y,
int w,
int h)
457 for (std::vector<std::shared_ptr<Block> >::iterator it = blocks.begin(); it != blocks.end(); ++it)
459 if ((*it)->GetId() == next)
461 std::shared_ptr<Illustration> bl;
462 if (it == blocks.begin())
463 bl.reset(
new Illustration(PushFrontElement(
"Illustration"), id_, x, y, w, h));
465 bl.reset(
new Illustration(InsertElement(**(it - 1),
"Illustration"), id_, x, y, w, h));
466 blocks.insert(it, bl);
468 for (; it != blocks.end(); ++it)
470 if (std::dynamic_pointer_cast<Illustration>(*it))
473 if (it != blocks.end())
474 illustrations.insert(std::find_if(illustrations.begin(), illustrations.end(), [&it](
const IllustrationPtr &p){
return p.lock() == *it; }), bl);
476 illustrations.push_back(bl);
484 const std::vector<Alto::Layout::Page::Space::GraphicalElementPtr>& Alto::Layout::Page::Space::GetGraphicalElements()
const
486 if (GetNbSubelements() != blocks.size())
487 const_cast<Space*>(
this)->update_subelements();
488 return graphicalElements;
498 Alto::Layout::Page::Space::GraphicalElement& Alto::Layout::Page::Space::AddGraphicalElement(
const Id &id_,
int x,
int y,
int w,
int h)
500 std::shared_ptr<GraphicalElement> bl(
new GraphicalElement(PushBackElement(
"GraphicalElement"), id_, x, y, w, h));
501 blocks.push_back(bl);
503 graphicalElements.push_back(bl);
516 Alto::Layout::Page::Space::GraphicalElement& Alto::Layout::Page::Space::AddGraphicalElementAfter(
const Id &pred,
const Id &id_,
int x,
int y,
int w,
int h)
518 for (std::vector<std::shared_ptr<Block> >::iterator it = blocks.begin(); it != blocks.end(); ++it)
520 if ((*it)->GetId() == pred)
524 if (it == blocks.end())
525 return AddGraphicalElement(id_, x, y, w, h);
528 std::shared_ptr<GraphicalElement> bl(
new GraphicalElement(InsertElement(pel,
"GraphicalElement"), id_, x, y, w, h));
529 blocks.insert(it, bl);
531 for (; it != blocks.end(); ++it)
533 if (std::dynamic_pointer_cast<GraphicalElement>(*it))
536 if (it != blocks.end())
537 graphicalElements.insert(std::find_if(graphicalElements.begin(), graphicalElements.end(), [&it](
const GraphicalElementPtr &p){
return p.lock() == *it; }), bl);
539 graphicalElements.push_back(bl);
556 Alto::Layout::Page::Space::GraphicalElement& Alto::Layout::Page::Space::AddGraphicalElementBefore(
const Id &next,
const Id &id_,
int x,
int y,
int w,
int h)
558 for (std::vector<std::shared_ptr<Block> >::iterator it = blocks.begin(); it != blocks.end(); ++it)
560 if ((*it)->GetId() == next)
562 std::shared_ptr<GraphicalElement> bl;
563 if (it == blocks.begin())
564 bl.reset(
new GraphicalElement(PushFrontElement(
"GraphicalElement"), id_, x, y, w, h));
566 bl.reset(
new GraphicalElement(InsertElement(**(it - 1),
"GraphicalElement"), id_, x, y, w, h));
567 blocks.insert(it, bl);
569 for (; it != blocks.end(); ++it)
571 if (std::dynamic_pointer_cast<GraphicalElement>(*it))
574 if (it != blocks.end())
575 graphicalElements.insert(std::find_if(graphicalElements.begin(), graphicalElements.end(), [&it](
const GraphicalElementPtr &p){
return p.lock() == *it; }), bl);
577 graphicalElements.push_back(bl);
585 const std::vector<Alto::Layout::Page::Space::ComposedBlockPtr>& Alto::Layout::Page::Space::GetComposedBlocks()
const
587 if (GetNbSubelements() != blocks.size())
588 const_cast<Space*>(
this)->update_subelements();
589 return composedBlocks;
600 Alto::Layout::Page::Space::Block::Block(
const Element &el):
605 id = GetAttribute<StringUTF8>(
"ID",
false);
606 GetAttribute<int>(
"HEIGHT",
false);
607 GetAttribute<int>(
"WIDTH",
false);
608 GetAttribute<int>(
"HPOS",
false);
609 GetAttribute<int>(
"VPOS",
false);
621 Alto::Layout::Page::Space::Block::Block(
const Element &el,
const Id &id_,
int x,
int y,
int w,
int h):
627 SetAttribute(
"ID",
id);
628 SetAttribute(
"HPOS", x);
629 SetAttribute(
"VPOS", y);
630 SetAttribute(
"WIDTH", w);
631 SetAttribute(
"HEIGHT", h);
635 int Alto::Layout::Page::Space::Block::GetHeight()
const
637 return GetAttribute<int>(
"HEIGHT",
false);
641 void Alto::Layout::Page::Space::Block::SetHeight(
int i)
643 SetAttribute(
"HEIGHT", i);
647 int Alto::Layout::Page::Space::Block::GetWidth()
const
649 return GetAttribute<int>(
"WIDTH",
false);
653 void Alto::Layout::Page::Space::Block::SetWidth(
int i)
655 SetAttribute(
"WIDTH", i);
659 int Alto::Layout::Page::Space::Block::GetHPos()
const
661 return GetAttribute<int>(
"HPOS",
false);
665 void Alto::Layout::Page::Space::Block::SetHPos(
int i)
667 SetAttribute(
"HPOS", i);
671 int Alto::Layout::Page::Space::Block::GetVPos()
const
673 return GetAttribute<int>(
"VPOS",
false);
677 void Alto::Layout::Page::Space::Block::SetVPos(
int i)
679 SetAttribute(
"VPOS", i);
683 Option<double> Alto::Layout::Page::Space::Block::GetRotation()
const
686 try { rotation = GetAttribute<double>(
"ROTATION",
false); }
catch (...) { }
691 Option<Id> Alto::Layout::Page::Space::Block::GetNextId()
const
694 StringUTF8 str = GetAttribute<StringUTF8>(
"IDNEXT");
710 Alto::Layout::Page::Space::Illustration::Illustration(
const Element &el):
722 Alto::Layout::Page::Space::Illustration::Illustration(
const Element &el,
const Id &id_,
int x,
int y,
int w,
int h):
723 Block(el, id_, x, y, w, h)
730 StringUTF8 str = GetAttribute<StringUTF8>(
"TYPE");
740 StringUTF8 str = GetAttribute<StringUTF8>(
"FILEID");
755 Alto::Layout::Page::Space::GraphicalElement::GraphicalElement(
const Element &el):
772 Alto::Layout::Page::Space::GraphicalElement::GraphicalElement(
const Element &el,
const Id &id_,
int x,
int y,
int w,
int h):
773 Block(el, id_, x, y, w, h)
788 Alto::Layout::Page::Space::ComposedBlock::ComposedBlock(
const Element &el):
794 for (
Element cel = BeginElement(); cel != EndElement(); ++cel)
796 std::shared_ptr<Block> newblock;
798 if (elname ==
"TextBlock")
801 textBlocks.push_back(std::static_pointer_cast<TextBlock>(newblock));
803 else if (elname ==
"Illustration")
805 newblock.reset(
new Illustration(cel));
806 illustrations.push_back(std::static_pointer_cast<Illustration>(newblock));
808 else if (elname ==
"GraphicalElement")
810 newblock.reset(
new GraphicalElement(cel));
811 graphicalElements.push_back(std::static_pointer_cast<GraphicalElement>(newblock));
813 else if (elname ==
"ComposedBlock")
815 newblock.reset(
new ComposedBlock(cel));
816 composedBlocks.push_back(std::static_pointer_cast<ComposedBlock>(newblock));
819 blocks.push_back(newblock);
827 StringUTF8 str = GetAttribute<StringUTF8>(
"TYPE");
837 StringUTF8 str = GetAttribute<StringUTF8>(
"FILEID");
std::vector< Id > GetStyleRefs(const Element &el)
Gets the list of style references.
bool IsNotEmpty() const noexcept
Checks if the string is not empty.
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.
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.