// Returns a pix of the original sample image. The pix is padded all round // by padding wherever possible. // The returned Pix must be pixDestroyed after use. // If the input page_pix is nullptr, nullptr is returned. Pix* TrainingSample::GetSamplePix(int padding, Pix* page_pix) const { if (page_pix == nullptr) return nullptr; int page_width = pixGetWidth(page_pix); int page_height = pixGetHeight(page_pix); TBOX padded_box = bounding_box(); padded_box.pad(padding, padding); // Clip the padded_box to the limits of the page TBOX page_box(0, 0, page_width, page_height); padded_box &= page_box; Box* box = boxCreate(page_box.left(), page_height - page_box.top(), page_box.width(), page_box.height()); Pix* sample_pix = pixClipRectangle(page_pix, box, nullptr); boxDestroy(&box); return sample_pix; }
box pager_rep::pages_make_page (pagelet pg) { box sb= pages_format (pg); box lb= move_box (ip, sb, 0, 0); int nr= N(pages) + 1 + page_offset; SI left= (nr&1)==0? even: odd; env->write (PAGE_NR, as_string (nr)); env->write (PAGE_THE_PAGE, style[PAGE_THE_PAGE]); tree page_t= env->exec (compound (PAGE_THE_PAGE)); bool empty= N (pg->ins) == 0; box header= make_header (empty); box footer= make_footer (empty); brush bgc = make_background (empty); adjust_margins (empty); return page_box (ip, lb, page_t, nr, bgc, width, height, left, top + dtop, top + dtop + text_height, header, footer, head_sep, foot_sep); }
box page_box (path ip, box b, tree page, SI width, SI height, SI left, SI top, SI bot, box header, box footer, SI head_sep, SI foot_sep) { SI h_y= -top- header->y1+ head_sep; SI f_y= -bot- footer->y2- foot_sep; array<box> bs (1); bs [0]= b; array<SI> bs_x (1); bs_x [0]= left; array<SI> bs_y (1); bs_y [0]= -top; array<box> decs (2); decs [0]= header; decs [1]= footer; array<SI> decs_x (2); decs_x [0]= left ; decs_x [1]= left; array<SI> decs_y (2); decs_y [0]= h_y ; decs_y [1]= f_y; return page_box (ip, page, width, height, bs, bs_x, bs_y, decs, decs_x, decs_y); }