Skip to content

Commit

Permalink
Update ocrd_models/ocrd_page_user_methods.py
Browse files Browse the repository at this point in the history
Co-authored-by: Robert Sachunsky <38561704+bertsky@users.noreply.github.com>
  • Loading branch information
kba and bertsky authored May 14, 2020
1 parent 2162f0f commit b728885
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion ocrd_models/ocrd_page_user_methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,26 @@ def get_AllRegions(self, regions=None, reading_order=False):
ret = []
for region in regions:
ret += getattr(self, 'get_{}Region'.format(region))()
return ret
if reading_order:
reading_order = reading_order.get_OrderedGroup() or reading_order.get_UnorderedGroup()
if reading_order:
def get_recursive_reading_order(rogroup):
if isinstance(rogroup, (OrderedGroupType, OrderedGroupIndexedType)):
elements = rogroup.get_AllIndexed()
if isinstance(rogroup, (UnorderedGroupType, UnorderedGroupIndexedType)):
elements = (rogroup.get_RegionRef() + rogroup.get_OrderedGroup() + rogroup.get_UnorderedGroup())
regionrefs = list()
for elem in elements:
regionrefs.append(elem.get_regionRef())
if not isinstance(elem, (RegionRefType, RegionRefIndexedType)):
regionrefs.extend(get_recursive_reading_order(elem))
return regionrefs
reading_order = get_recursive_reading_order(reading_order)
if reading_order:
ret = dict([(region.id, region) for region in ret])
return [ret[region_id] for region_id in reading_order if region_id in ret]
else:
return ret
''', class_names=r'^(PageType)$')

#
Expand Down

0 comments on commit b728885

Please sign in to comment.