00001 00002 00003 00004 00005 00006 00007 00008 00009 00010 00011 00012 00013 00014 00015 00016 00017 00018
00019
00020 #include "_gocr.h"
00021 #include "gocr_char.h"
00022 #include "unicode.h"
00023
00024 static int began = 0;
00025
00026 gocrBox *currentbox;
00027
00028 00029 00030 00031 00032 00033
00042 int gocr_charBegin ( void ) {
00043 _gocr_debug(3, fprintf(_data.error, "gocr_charBegin()\n");)
00044 if ( began ) {
00045 _gocr_debug(1, fprintf(_data.error, "Character already begun\n");)
00046 return -1;
00047 }
00048
00049 began++;
00050 currentbox = (gocrBox *)malloc(sizeof(gocrBox));
00051 if ( !currentbox ) {
00052 _gocr_debug(1, fprintf(_data.error, "charBegin: not enough memory\n");)
00053 return -1;
00054 }
00055
00056 /* set the boundaries in such a way that they are not valid and will be updated */
00057 currentbox->x0 = currentblock->x1+1;
00058 currentbox->y0 = currentblock->y1+1;
00059 currentbox->x1 = currentblock->x0-1;
00060 currentbox->y1 = currentblock->y0-1;
00061
00062 currentbox->attributes = NULL;
00063
00064 list_init(¤tbox->possible);
00065 currentbox->ch = NULL;
00066
00067 /* deprecated fields */
00068 currentbox->c = currentbox->ac = currentbox->modifier = UNICODE_NULL;
00069
00070 return 0;
00071 }
00072
00081 int gocr_charEnd ( void ) {
00082 _gocr_debug(3, fprintf(_data.error, "gocr_charEnd()\n");)
00083
00084 if ( !began ) {
00085 _gocr_debug(1, fprintf(_data.error, "Character not begun\n");)
00086 return -1;
00087 }
00088
00089 began--;
00090
00091 list_app(¤tblock->boxlist, currentbox);
00092
00093 return 0;
00094 }
00095
00107 int gocr_charSetAllNearPixels ( int action, int x, int y ) {
00108 _gocr_debug(3, fprintf(_data.error, "gocr_charSetAllNearPixels(%d, %d, %d)\n",
00109 action, x, y);)
00110
00111 if ( !began ) {
00112 _gocr_debug(1, fprintf(_data.error, "Character not begun\n");)
00113 return -1;
00114 }
00115 _gocr_debug(0, fprintf(_data.error, "gocr_charSetAllNearPixels not done yet\n");)
00116 }
00117
00130 int gocr_charSetAttribute ( int action, char *name, ... ) {
00131 _gocr_debug(3, fprintf(_data.error, "gocr_charSetAttribute(%d, %s)\n",
00132 action, name);)
00133
00134 if ( !began ) {
00135 _gocr_debug(1, fprintf(_data.error, "Character not begun\n");)
00136 return -1;
00137 }
00138
00139 _gocr_debug(0, fprintf(_data.error, "gocr_charSetAttribute: use gocr_boxSetAttribute instead \n");)
00140 return -1;
00141 // return gocr_boxAttributeSet(currentbox, action, name, ...);
00142 }
00143
00155 int gocr_charSetPixel ( int action, int x, int y ) {
00156 _gocr_debug(3, fprintf(_data.error, "gocr_charSetPixel(%d, %d, %d)\n",
00157 action, x, y);)
00158
00159 if ( !began ) {
00160 _gocr_debug(1, fprintf(_data.error, "Character not begun\n");)
00161 return -1;
00162 }
00163
00164 /* check boundaries */
00165 if ( x < currentblock->x0 || x > currentblock->x1 ||
00166 y < currentblock->x0 || y > currentblock->x1 ) {
00167 _gocr_debug(1, fprintf(_data.error, "Pixel out of bounds.\n");)
00168 return -1;
00169 }
00170
00171 /* update new boundaries */
00172 if ( x < currentbox->x0 )
00173 currentbox->x0 = x;
00174 if ( x > currentbox->x1 )
00175 currentbox->x1 = x;
00176 if ( y < currentbox->y0 )
00177 currentbox->y0 = y;
00178 if ( y > currentbox->y1 )
00179 currentbox->y1 = y;
00180
00181 currentblock->image.data[x][y].ischar = action;
00182 return 0;
00183 }
00184
00196 int gocr_charSetRect ( int action, int x0, int y0, int x1, int y1 ) {
00197 int i, j;
00198 _gocr_debug(3, fprintf(_data.error, "gocr_charSetRect(%d, %d, %d, %d, %d)\n",
00199 action, x0, y0, x1, y1);)
00200
00201 if ( !began ) {
00202 _gocr_debug(1, fprintf(_data.error, "Character not begun\n");)
00203 return -1;
00204 }
00205
00206 /* should reverse x and y if needed */
00207 _gocr_fixParameters ( &x0, &y0, &x1, &y1 );
00208
00209 /* check boundaries */
00210 if ( x0 < currentblock->x0 || x0 > currentblock->x1 ||
00211 x1 < currentblock->x0 || x1 > currentblock->x1 ||
00212 y0 < currentblock->x0 || y0 > currentblock->x1 ||
00213 y1 < currentblock->x0 || y1 > currentblock->x1 ) {
00214 _gocr_debug(1, fprintf(_data.error, "Rectangle out of bounds.\n");)
00215 return -1;
00216 }
00217
00218 /* update new boundaries */
00219 if ( x0 < currentbox->x0 )
00220 currentbox->x0 = x0;
00221 if ( x1 > currentbox->x1 )
00222 currentbox->x1 = x1;
00223 if ( y0 < currentbox->y0 )
00224 currentbox->y0 = y0;
00225 if ( y1 > currentbox->y1 )
00226 currentbox->y1 = y1;
00227
00228 for ( ; i <= x1; x0++ )
00229 for ( ; j <= y1; x1++ )
00230 currentblock->image.data[i][j].ischar = action;
00231
00232 return 0;
00233 }