📄 ocrblock.cpp
字号:
/********************************************************************** * File: ocrblock.cpp (Formerly block.c) * Description: BLOCK member functions and iterator functions. * Author: Ray Smith * Created: Fri Mar 15 09:41:28 GMT 1991 * * (C) Copyright 1991, Hewlett-Packard Ltd. ** Licensed under the Apache License, Version 2.0 (the "License"); ** you may not use this file except in compliance with the License. ** You may obtain a copy of the License at ** http://www.apache.org/licenses/LICENSE-2.0 ** Unless required by applicable law or agreed to in writing, software ** distributed under the License is distributed on an "AS IS" BASIS, ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. ** See the License for the specific language governing permissions and ** limitations under the License. * **********************************************************************/#include "mfcpch.h"#include <stdlib.h>#include "blckerr.h"#include "ocrblock.h"#include "tprintf.h"#define BLOCK_LABEL_HEIGHT 150 //char height of block idELISTIZE_S (BLOCK)/********************************************************************** * BLOCK::BLOCK * * Constructor for a simple rectangular block. **********************************************************************/BLOCK::BLOCK ( //rectangular blockconst char *name, //filenameBOOL8 prop, //proportionalinT16 kern, //kerninginT16 space, //spacinginT16 xmin, //bottom leftinT16 ymin, inT16 xmax, //top rightinT16 ymax):PDBLK (xmin, ymin, xmax, ymax),filename(name) { //box(ICOORD(xmin,ymin),ICOORD(xmax,ymax)) //boundaries ICOORDELT_IT left_it = &leftside; ICOORDELT_IT right_it = &rightside; proportional = prop; kerning = kern; spacing = space; font_class = -1; //not assigned hand_block = NULL; hand_poly = NULL; left_it.set_to_list (&leftside); right_it.set_to_list (&rightside); //make default box left_it.add_to_end (new ICOORDELT (xmin, ymin)); left_it.add_to_end (new ICOORDELT (xmin, ymax)); right_it.add_to_end (new ICOORDELT (xmax, ymin)); right_it.add_to_end (new ICOORDELT (xmax, ymax));}/********************************************************************** * BLOCK::set_sides * * Sets left and right vertex lists **********************************************************************///void BLOCK::set_sides( //set vertex lists//ICOORDELT_LIST *left, //left vertices//ICOORDELT_LIST *right //right vertices//)//{// ICOORDELT_IT left_it= &leftside; //boundaries// ICOORDELT_IT right_it= &rightside;// leftside.clear();// left_it.move_to_first();// left_it.add_list_before(left);// rightside.clear();// right_it.move_to_first();// right_it.add_list_before(right);//}/********************************************************************** * BLOCK::contains * * Return TRUE if the given point is within the block. **********************************************************************///BOOL8 BLOCK::contains( //test containment//ICOORD pt //point to test//)//{// BLOCK_RECT_IT it=this; //rectangle iterator// ICOORD bleft,tright; //corners of rectangle// for (it.start_block();!it.cycled_rects();it.forward())// {// it.bounding_box(bleft,tright); //get rectangle// if (pt.x()>=bleft.x() && pt.x()<=tright.x() //inside rect// && pt.y()>=bleft.y() && pt.y()<=tright.y())// return TRUE; //is inside// }// return FALSE; //not inside//}/********************************************************************** * BLOCK::move * * Reposition block **********************************************************************///void BLOCK::move( // reposition block//const ICOORD vec // by vector//)//{// ROW_IT row_it( &rows );// ICOORDELT_IT it( &leftside );// for( row_it.mark_cycle_pt(); !row_it.cycled_list(); row_it.forward() )// row_it.data()->move( vec );// for( it.mark_cycle_pt(); !it.cycled_list(); it.forward() )// *(it.data()) += vec;// it.set_to_list( &rightside );// for( it.mark_cycle_pt(); !it.cycled_list(); it.forward() )// *(it.data()) += vec;// box.move( vec );//}/********************************************************************** * decreasing_top_order * * Sort Comparator: Return <0 if row1 top < row2 top **********************************************************************/int decreasing_top_order( // const void *row1, const void *row2) { return (*(ROW **) row2)->bounding_box ().top () - (*(ROW **) row1)->bounding_box ().top ();}/********************************************************************** * BLOCK::sort_rows * * Order rows so that they are in order of decreasing Y coordinate **********************************************************************/void BLOCK::sort_rows() { // order on "top" ROW_IT row_it(&rows); row_it.sort (decreasing_top_order);}/********************************************************************** * BLOCK::compress * * Delete space between the rows. (And maybe one day, compress the rows) * Fill space of block from top down, left aligning rows. **********************************************************************/void BLOCK::compress() { // squash it up #define ROW_SPACING 5 ROW_IT row_it(&rows); ROW *row; ICOORD row_spacing (0, ROW_SPACING); ICOORDELT_IT icoordelt_it; sort_rows(); box = TBOX (box.topleft (), box.topleft ()); box.move_bottom_edge (ROW_SPACING); for (row_it.mark_cycle_pt (); !row_it.cycled_list (); row_it.forward ()) { row = row_it.data (); row->move (box.botleft () - row_spacing -
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -