character.cc (ocrad-0.24) | : | character.cc (ocrad-0.25) | ||
---|---|---|---|---|
/* GNU Ocrad - Optical Character Recognition program | /* GNU Ocrad - Optical Character Recognition program | |||
Copyright (C) 2003-2014 Antonio Diaz Diaz. | Copyright (C) 2003-2015 Antonio Diaz Diaz. | |||
This program is free software: you can redistribute it and/or modify | This program is free software: you can redistribute it and/or modify | |||
it under the terms of the GNU General Public License as published by | it under the terms of the GNU General Public License as published by | |||
the Free Software Foundation, either version 2 of the License, or | the Free Software Foundation, either version 2 of the License, or | |||
(at your option) any later version. | (at your option) any later version. | |||
This program is distributed in the hope that it will be useful, | This program is distributed in the hope that it will be useful, | |||
but WITHOUT ANY WARRANTY; without even the implied warranty of | but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |||
GNU General Public License for more details. | GNU General Public License for more details. | |||
You should have received a copy of the GNU General Public License | You should have received a copy of the GNU General Public License | |||
along with this program. If not, see <http://www.gnu.org/licenses/>. | along with this program. If not, see <http://www.gnu.org/licenses/>. | |||
*/ | */ | |||
#include <algorithm> | #include <algorithm> | |||
#include <cstdio> | #include <cstdio> | |||
#include <string> | ||||
#include <vector> | #include <vector> | |||
#include <stdint.h> | #include <stdint.h> | |||
#include "common.h" | #include "common.h" | |||
#include "rectangle.h" | #include "rectangle.h" | |||
#include "segment.h" | #include "segment.h" | |||
#include "ucs.h" | #include "ucs.h" | |||
#include "user_filter.h" | ||||
#include "bitmap.h" | #include "bitmap.h" | |||
#include "blob.h" | #include "blob.h" | |||
#include "character.h" | #include "character.h" | |||
#include "profile.h" | #include "profile.h" | |||
#include "feats.h" | #include "feats.h" | |||
Character::Character( const Character & c ) | Character::Character( const Character & c ) | |||
: Rectangle( c ), blobpv( c.blobpv ), gv( c.gv ) | : Rectangle( c ), blobpv( c.blobpv ), gv( c.gv ) | |||
{ | { | |||
for( unsigned i = 0; i < blobpv.size(); ++i ) | for( unsigned i = 0; i < blobpv.size(); ++i ) | |||
skipping to change at line 59 | skipping to change at line 61 | |||
gv = c.gv; | gv = c.gv; | |||
} | } | |||
return *this; | return *this; | |||
} | } | |||
Character::~Character() | Character::~Character() | |||
{ | { | |||
for( unsigned i = 0; i < blobpv.size(); ++i ) delete blobpv[i]; | for( unsigned i = 0; i < blobpv.size(); ++i ) delete blobpv[i]; | |||
} | } | |||
// Return the filled area of the main blobs only (no recursive) | // Returns the filled area of the main blobs only (no recursive) | |||
// | // | |||
int Character::area() const | int Character::area() const | |||
{ | { | |||
int a = 0; | int a = 0; | |||
for( int i = 0; i < blobs(); ++i ) a += blobpv[i]->area(); | for( int i = 0; i < blobs(); ++i ) a += blobpv[i]->area(); | |||
return a; | return a; | |||
} | } | |||
const Blob & Character::blob( const int i ) const | const Blob & Character::blob( const int i ) const | |||
{ | { | |||
skipping to change at line 362 | skipping to change at line 364 | |||
if( !UCS::isdigit( code ) && !UCS::isspace( code ) ) | if( !UCS::isdigit( code ) && !UCS::isspace( code ) ) | |||
{ | { | |||
for( int i = 1; i < guesses(); ++i ) | for( int i = 1; i < guesses(); ++i ) | |||
if( UCS::isdigit( gv[i].code ) ) { swap_guesses( 0, i ); break; } | if( UCS::isdigit( gv[i].code ) ) { swap_guesses( 0, i ); break; } | |||
if( !UCS::isdigit( gv[0].code ) ) | if( !UCS::isdigit( gv[0].code ) ) | |||
gv[0].code = UCS::to_nearest_digit( gv[0].code ); | gv[0].code = UCS::to_nearest_digit( gv[0].code ); | |||
if( remove && !UCS::isdigit( gv[0].code ) ) clear_guesses(); | if( remove && !UCS::isdigit( gv[0].code ) ) clear_guesses(); | |||
} | } | |||
break; | break; | |||
case Filter::same_height: break; // handled at line level | case Filter::same_height: break; // handled at line level | |||
case Filter::text_block: break; // handled at block level | ||||
case Filter::upper_num_mark: // fall through | ||||
case Filter::upper_num_only: | case Filter::upper_num_only: | |||
remove = true; // fall through | remove = true; // fall through | |||
case Filter::upper_num: | case Filter::upper_num: | |||
if( !UCS::isupper( code ) && !UCS::isdigit( code ) && | if( !UCS::isupper( code ) && !UCS::isdigit( code ) && | |||
!UCS::isspace( code ) ) | !UCS::isspace( code ) ) | |||
{ | { | |||
for( int i = 1; i < guesses(); ++i ) | for( int i = 1; i < guesses(); ++i ) | |||
if( UCS::isupper( gv[i].code ) || UCS::isdigit( gv[i].code ) ) | if( UCS::isupper( gv[i].code ) || UCS::isdigit( gv[i].code ) ) | |||
{ swap_guesses( 0, i ); break; } | { swap_guesses( 0, i ); break; } | |||
if( !UCS::isupper( gv[0].code ) && !UCS::isdigit( gv[0].code ) ) | if( !UCS::isupper( gv[0].code ) && !UCS::isdigit( gv[0].code ) ) | |||
gv[0].code = UCS::to_nearest_upper_num( gv[0].code ); | gv[0].code = UCS::to_nearest_upper_num( gv[0].code ); | |||
if( remove && !UCS::isupper( gv[0].code ) && !UCS::isdigit( gv[0].code ) ) | if( remove && !UCS::isupper( gv[0].code ) && !UCS::isdigit( gv[0].code ) ) | |||
clear_guesses(); | clear_guesses(); | |||
} | } | |||
break; | break; | |||
case Filter::user: break; // handled by apply_user_filter | ||||
} | ||||
} | ||||
void Character::apply_user_filter( const User_filter & user_filter ) | ||||
{ | ||||
if( !guesses() || UCS::isspace( gv[0].code ) ) return; | ||||
int new_code = user_filter.get_new_code( gv[0].code ); | ||||
if( new_code >= 0 ) gv[0].code = new_code; | ||||
else // disabled | ||||
{ | ||||
for( int i = 1; i < guesses(); ++i ) | ||||
{ | ||||
new_code = user_filter.get_new_code( gv[i].code ); | ||||
if( new_code >= 0 ) | ||||
{ swap_guesses( 0, i ); gv[0].code = new_code; break; } | ||||
} | ||||
if( new_code < 0 ) clear_guesses(); | ||||
} | } | |||
} | } | |||
End of changes. 6 change blocks. | ||||
2 lines changed or deleted | 25 lines changed or added |