Merge pull request #2826 from bertsky/clip-blockpolygon

make BlockPolygon usable
This commit is contained in:
zdenop 2019-12-19 09:14:25 +01:00 committed by GitHub
commit 79f191fe20
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -370,14 +370,22 @@ Pta* PageIterator::BlockPolygon() const {
return nullptr; // Already at the end!
if (it_->block()->block->pdblk.poly_block() == nullptr)
return nullptr; // No layout analysis used - no polygon.
ICOORDELT_IT it(it_->block()->block->pdblk.poly_block()->points());
// Copy polygon, so we can unrotate it to image coordinates.
POLY_BLOCK* internal_poly = it_->block()->block->pdblk.poly_block();
ICOORDELT_LIST vertices;
vertices.deep_copy(internal_poly->points(), ICOORDELT::deep_copy);
POLY_BLOCK poly(&vertices, internal_poly->isA());
poly.rotate(it_->block()->block->re_rotation());
ICOORDELT_IT it(poly.points());
Pta* pta = ptaCreate(it.length());
int num_pts = 0;
for (it.mark_cycle_pt(); !it.cycled_list(); it.forward(), ++num_pts) {
ICOORD* pt = it.data();
// Convert to top-down coords within the input image.
float x = static_cast<float>(pt->x()) / scale_ + rect_left_;
float y = rect_top_ + rect_height_ - static_cast<float>(pt->y()) / scale_;
int x = static_cast<float>(pt->x()) / scale_ + rect_left_;
int y = rect_top_ + rect_height_ - static_cast<float>(pt->y()) / scale_;
x = ClipToRange(x, rect_left_, rect_left_ + rect_width_);
y = ClipToRange(y, rect_top_, rect_top_ + rect_height_);
ptaAddPt(pta, x, y);
}
return pta;