def setUp(self): bboxes = ( BBox(Coordinate(466.681, 770.160), Coordinate(472.219, 801.755)), BBox(Coordinate(472.199, 771.160), Coordinate(477.736, 100.755)), BBox(Coordinate(524.519, 788.160), Coordinate(527.287, 70.755)), ) self.merged_bbox = bbox_merge(bboxes)
def __init__(self): super(ChildClass, self).__init__( BBox(Coordinate(466.681, 788.160), Coordinate(527.287, 70.755))) self.my_child_nodes = [ PositionedNode( BBox(Coordinate(466.681, 770.160), Coordinate(472.219, 801.755))), PositionedNode( BBox(Coordinate(472.199, 771.160), Coordinate(477.736, 100.755))), PositionedNode( BBox(Coordinate(524.519, 788.160), Coordinate(527.287, 70.755))), ]
def merge(self) -> Page: lower_right_ys = [] lower_right_xs = [] for page in self.pages: lower_right_ys.append(page.bbox.lower_right_coordinate.y) lower_right_xs.append(page.bbox.lower_right_coordinate.x) merged_page = Page( BBox(Coordinate(0, 0), Coordinate(max(lower_right_xs), sum(lower_right_ys)))) lower_right_ys.reverse() lower_right_y_count = len(lower_right_ys) - 1 for i, page in enumerate(self.pages): y_offset = sum(lower_right_ys[i:lower_right_y_count]) for text_box in page.text_boxes: # Change y coordinates append the necessary y_offset post page-merge text_box.bbox.lower_right_coordinate.y = text_box.bbox.lower_right_coordinate.y + y_offset text_box.bbox.upper_left_coordinate.y = text_box.bbox.upper_left_coordinate.y + y_offset for text_line in text_box.text_lines: text_line.bbox.lower_right_coordinate.y = text_line.bbox.lower_right_coordinate.y + y_offset text_line.bbox.upper_left_coordinate.y = text_line.bbox.upper_left_coordinate.y + y_offset for text in text_line.texts: text.bbox.lower_right_coordinate.y = text.bbox.lower_right_coordinate.y + y_offset text.bbox.upper_left_coordinate.y = text.bbox.upper_left_coordinate.y + y_offset merged_page.text_boxes.append(text_box) return merged_page
def setUp(self): pages = Pages() page = Page(BBox(Coordinate(0,0), Coordinate(595.320,841.920))) bbox = BBox(Coordinate(79.2,793.923), Coordinate(139.809,807.518)) tl = TextLine(bbox) tl.texts.append(Text(bbox, 'test')) tb = TextBox(bbox) tb.text_lines.append(tl) page.text_boxes.append(tb) pages.pages.append(page) page = Page(BBox(Coordinate(0,0), Coordinate(595.320,841.920))) bbox = BBox(Coordinate(79.2,793.923), Coordinate(139.809,807.518)) tl = TextLine(bbox) tl.texts.append(Text(bbox, 'test')) tb = TextBox(bbox) tb.text_lines.append(tl) page.text_boxes.append(tb) pages.pages.append(page) page = Page(BBox(Coordinate(0,0), Coordinate(595.320,841.920))) bbox = BBox(Coordinate(79.2,793.923), Coordinate(139.809,807.518)) tl = TextLine(bbox) tl.texts.append(Text(bbox, 'test')) tb = TextBox(bbox) tb.text_lines.append(tl) page.text_boxes.append(tb) pages.pages.append(page) self.page = pages.merge()
def setUp(self): self.page = Page({}) bbox = BBox(Coordinate(79.2,793.923), Coordinate(139.809,807.518)) tl = TextLine(bbox) tl.texts.append(Text(bbox, 'test')) tb = TextBox(bbox) tb.text_lines.append(tl) self.page.text_boxes.append(tb) bbox = BBox(Coordinate(70,793.923), Coordinate(354.369,807.518)) tl = TextLine(bbox) tl.texts.append(Text(bbox, 'test')) tb = TextBox(bbox) tb.text_lines.append(tl) self.page.text_boxes.append(tb) bbox = BBox(Coordinate(505.2,793.923), Coordinate(530.169,807.518)) tl = TextLine(bbox) tl.texts.append(Text(bbox, 'test')) tb = TextBox(bbox) tb.text_lines.append(tl) self.page.text_boxes.append(tb)
def setUp(self): self.positioned_node = PositionedNode( BBox(Coordinate(79.2, 793.923), Coordinate(139.809, 807.518)))
def test_is_center_true(self): positioned_node = PositionedNode( BBox(Coordinate(218.4, 748.128), Coordinate(379.764, 765.312))) self.assertTrue(positioned_node.is_center_x(73.794, 527.736, 10))
def setUp(self): text_line = TextLine( BBox(Coordinate(459.840, 753.697), Coordinate(521.235, 765.210))) text_line.texts.append( Text( BBox(Coordinate(459.840, 753.697), Coordinate(462.075, 765.210)), 'I', TextStyle('Arial-BoldMT', 11.513, 'ICCBased', '[0]'))) text_line.texts.append( Text( BBox(Coordinate(462.120, 753.697), Coordinate(467.483, 765.210)), 'S', TextStyle('Arial-BoldMT', 11.513, 'ICCBased', '[0]'))) text_line.texts.append( Text( BBox(Coordinate(467.402, 753.697), Coordinate(472.765, 765.210)), 'S', TextStyle('Arial-BoldMT', 11.513, 'ICCBased', '[0]'))) text_line.texts.append( Text( BBox(Coordinate(472.802, 753.697), Coordinate(478.607, 765.210)), 'N', TextStyle('Arial-BoldMT', 11.513, 'ICCBased', '[0]'))) text_line.texts.append( Text( BBox(Coordinate(478.562, 753.697), Coordinate(480.797, 765.210)), ' ', TextStyle('Arial-BoldMT', 11.513, 'ICCBased', '[0]'))) text_line.texts.append( Text( BBox(Coordinate(480.840, 754.107), Coordinate(485.310, 765.082)), '1', TextStyle('ArialMT', 10.975, 'ICCBased', '[0]'))) text_line.texts.append( Text( BBox(Coordinate(485.278, 754.107), Coordinate(489.748, 765.082)), '3', TextStyle('ArialMT', 10.975, 'ICCBased', '[0]'))) text_line.texts.append( Text( BBox(Coordinate(489.716, 754.107), Coordinate(494.186, 765.082)), '2', TextStyle('ArialMT', 10.975, 'ICCBased', '[0]'))) text_line.texts.append( Text( BBox(Coordinate(494.154, 754.107), Coordinate(498.624, 765.082)), '2', TextStyle('ArialMT', 10.975, 'ICCBased', '[0]'))) text_line.texts.append( Text( BBox(Coordinate(498.600, 754.107), Coordinate(501.277, 765.082)), '-', TextStyle('ArialMT', 10.975, 'ICCBased', '[0]'))) text_line.texts.append( Text( BBox(Coordinate(501.240, 754.107), Coordinate(505.710, 765.082)), '0', TextStyle('ArialMT', 10.975, 'ICCBased', '[0]'))) text_line.texts.append( Text( BBox(Coordinate(505.678, 754.107), Coordinate(510.148, 765.082)), '3', TextStyle('ArialMT', 10.975, 'ICCBased', '[0]'))) text_line.texts.append( Text( BBox(Coordinate(510.116, 754.107), Coordinate(514.586, 765.082)), '3', TextStyle('ArialMT', 10.975, 'ICCBased', '[0]'))) text_line.texts.append( Text( BBox(Coordinate(514.554, 754.107), Coordinate(519.024, 765.082)), '0', TextStyle('ArialMT', 10.975, 'ICCBased', '[0]'))) text_line.texts.append( Text( BBox(Coordinate(519.000, 754.107), Coordinate(521.235, 765.082)), ' ', TextStyle('ArialMT', 10.975, 'ICCBased', '[0]'))) self.compacted_text_line = text_line self.compacted_text_line.compact_texts()