~ubuntu-branches/ubuntu/precise/cuneiform/precise

« back to all changes in this revision

Viewing changes to .pc/swapbytes.diff/cuneiform_src/Kern/rstr/src/perc.c

  • Committer: Bazaar Package Importer
  • Author(s): Jakub Wilk, c-assert.diff, slovenian-slv.diff
  • Date: 2011-01-26 21:53:07 UTC
  • mfrom: (5.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20110126215307-62x61mcesr607qb7
Tags: 1.0.0+dfsg-2
* Upload to unstable.
* Explicitly build-depend on pkg-config. Thanks to Stefano Rivera for the
  bug report.
* Add Vcs-* fields.
* Use the standard C assert() macro, rather than custom Cuneiform one.
  [c-assert.diff]
* Pass CFLAGS, CXXFLAGS and LDFLAGS (get from dpkg-buildflags) to cmake
  (closes: #608345). Thanks to Sami Liedes for the bug report.
  + Build depend on dpkg-dev (>= 1.15.7).
* Pass --parallel to dh.
  + Bump debhelper minimum version to 7.4.10.
* Update debian/copyright to the latest DEP-5 version.
* Bump year in debian/copyright.
* Explicitly link to GraphicsMagick (rather than via the ImageMagick
  compatibility layer).
* Don't ship /usr/lib/cuneiform/*.so symlinks. These libraries are
  considered private, at least until #598616 is fixed.
* Rename some private variables in debian/rules to make them lowercase.
* Update patch headers.
* Provide proper ‘build-arch’ and ‘build-indep’ targets in debian/rules.
* Document input format in the manual page (closes: #572061). Thanks to
  Janusz S. Bień for the bug report.
* Use ‘slv’ (rather than ‘slo’) as language code for Slovenian.
  [slovenian-slv.diff]
* Fix package description: Slovenian is supported, Slovak is not.
* Improve documentation of the language (-l) option (closes: #602512).
  Thanks to Jari Aalto for the bug report.
* Install reasons file for vrms.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright (c) 1993-2008, Cognitive Technologies
 
3
All rights reserved.
 
4
 
 
5
����������� ��������� ��������������� � ������������� ��� � ���� ��������� ����,
 
6
��� � � �������� �����, � ����������� ��� ���, ��� ���������� ��������� �������:
 
7
 
 
8
      * ��� ��������� ��������������� ��������� ���� ������ ���������� ���������
 
9
        ���� ����������� �� ��������� �����, ���� ������ ������� � �����������
 
10
        ����� �� ��������.
 
11
      * ��� ��������� ��������������� ��������� ���� � ������������ �/��� �
 
12
        ������ ����������, ������������ ��� ���������������, ������ �����������
 
13
        ��������� ���� ���������� �� ��������� �����, ���� ������ ������� �
 
14
        ����������� ����� �� ��������.
 
15
      * �� �������� Cognitive Technologies, �� ����� �� ����������� �� �����
 
16
        ���� ������������ � �������� �������� ��������� �/��� �����������
 
17
        ���������, ���������� �� ���� ��, ��� ���������������� �����������
 
18
        ����������.
 
19
 
 
20
��� ��������� ������������� ����������� ��������� ���� �/��� ������� ������ "���
 
21
��� ����" ��� ������-���� ���� ��������, ���������� ���� ��� ���������������,
 
22
������� �������� ������������ �������� � ����������� ��� ���������� ����, �� ��
 
23
������������� ���. �� �������� ��������� ���� � �� ���� ������ ����, �������
 
24
����� �������� �/��� �������� �������������� ���������, �� � ���� ������ ��
 
25
��Ѩ� ���������������, ������� ����� �����, ���������, ����������� ���
 
26
������������� ������, ��������� � �������������� ��� ���������� ����������
 
27
������������� ������������� ��������� (������� ������ ������, ��� ������,
 
28
������� ���������, ��� ������ �/��� ������ �������, ���������� ��-�� ��������
 
29
������� ��� �/��� ������ ��������� �������� ��������� � ������� �����������,
 
30
�� �� ������������� ����� ��������), �� �� ������������� ���, ���� ���� �����
 
31
�������� ��� ������ ���� ���� �������� � ����������� ����� ������� � ������.
 
32
 
 
33
Redistribution and use in source and binary forms, with or without modification,
 
34
are permitted provided that the following conditions are met:
 
35
 
 
36
    * Redistributions of source code must retain the above copyright notice,
 
37
      this list of conditions and the following disclaimer.
 
38
    * Redistributions in binary form must reproduce the above copyright notice,
 
39
      this list of conditions and the following disclaimer in the documentation
 
40
      and/or other materials provided with the distribution.
 
41
    * Neither the name of the Cognitive Technologies nor the names of its
 
42
      contributors may be used to endorse or promote products derived from this
 
43
      software without specific prior written permission.
 
44
 
 
45
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 
46
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 
47
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 
48
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
 
49
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 
50
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 
51
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 
52
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 
53
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 
54
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
55
*/
 
56
 
 
57
/*********************************************************************/
 
58
/*                                                                   */
 
59
/*                           module PERC                             */
 
60
/*                  the processing of the 'percent' symbol           */
 
61
/*********************************************************************/
 
62
 
 
63
/*
 
64
 This procedure inspects given cell and makes a decision whether it is
 
65
  the percent symbol or not. The object under consideration is 'left
 
66
  upper' percent or 'right lower' percent or right slash '/'.
 
67
 
 
68
 1. 'left upper' percent case:
 
69
     right dust exists, and the box of the dust has the correct
 
70
     overlap with the box of given cell. The overlap is correct if:
 
71
      a) dust right lower corner can stretch out of given cell by
 
72
      BH_K_NOM                             BW_K_NOM
 
73
      ---------- * height of the cell and  ----------- * width of the cell;
 
74
      BH_K_DENOM                           BW_K_DENOM
 
75
 
 
76
                                                    EW_K_NOM
 
77
      b) the width of the dust must be less, than  ---------- of the
 
78
                                                    EW_K_DENOM
 
79
          width of the cell, and the height of the dust must be less,
 
80
                  EH_K_NOM
 
81
          than   ----------  of the height of the cell.
 
82
                 EH_K_DENOM
 
83
 
 
84
  2. 'right lower' percent case:
 
85
     the left dust exists, and the box of the dust has the correct
 
86
     overlap with the box of given cell. The overlap is correct if:
 
87
      a). dust left upper corner can stretch out of given cell by
 
88
      BH_K_NOM                             BW_K_NOM
 
89
      ---------- * height of the cell and  ----------- * width of the cell;
 
90
      BH_K_DENOM                           BW_K_DENOM
 
91
 
 
92
                                                    EW_K_NOM
 
93
      b). the width of the dust must be less, than  ---------- of the
 
94
                                                    EW_K_DENOM
 
95
          width of the cell, and the height of the dust must be less,
 
96
                  EH_K_NOM
 
97
          than   ----------  of the height of the cell.
 
98
                 EH_K_DENOM
 
99
 
 
100
  3. 'right slash' case:
 
101
     the left and rights dusts exist, and the boxes of the dusts have
 
102
     the correct overlaps with the box of given cell. The correctness
 
103
     of the overlaps is the same as p.1. and p.2. for right dust
 
104
     and left dust respectevly.
 
105
 
 
106
*/
 
107
#include <stdio.h>
 
108
#include <stdlib.h>
 
109
#include <string.h>
 
110
#include <assert.h>
 
111
 
 
112
#include "struct.h"
 
113
#include "func.h"
 
114
#include "ligas.h"
 
115
#include "lang.h"
 
116
#include "leo.h"
 
117
#include "std.h"
 
118
 
 
119
#include "compat_defs.h"
 
120
 
 
121
#define NUMBER      '#'
 
122
#define PRO_NUMBER  0xC3
 
123
#define PRO_NUM_PART '�'
 
124
 
 
125
#define BW_K_NOM     1
 
126
#define BW_K_DENOM   2
 
127
#define BH_K_NOM     1
 
128
#define BH_K_DENOM   7
 
129
#define EW_K_NOM     4
 
130
#define EW_K_DENOM   5
 
131
#define EH_K_NOM     4   //for percent
 
132
#define EH_K_DENOM   5
 
133
#define EH_K_NOM_N   11   //for number
 
134
#define EH_K_DENOM_N 10
 
135
#define  H_K_DENOM_N  8   //for number
 
136
 
 
137
#define LeftDust     1
 
138
#define RightDust    2
 
139
 
 
140
#define RELIABLE_SL  220
 
141
#define RELIABLE_O   210
 
142
#define RELIABLE_NUM 200
 
143
#define LIKE_O       100
 
144
#define middle(x) ((x)->r_col + ((x)->w>>1))
 
145
 
 
146
extern uchar db_status;
 
147
 
 
148
 
 
149
typedef struct bnd_allowed
 
150
 {
 
151
  int16_t     bw,                 /* beginning of the widht interval */
 
152
                  ew,                 /* end of the widht interval */
 
153
                  bh,                 /* beginning of the height interval */
 
154
                  eh;                 /* end of the height interval */
 
155
 } bnd_allowed;
 
156
 
 
157
typedef struct  perc_struct
 
158
 {
 
159
  cell *          BC;           /* pointer to the currente cell */
 
160
  cell *          RC;           /* the first 'right dust' cells */
 
161
  cell *          ldcp;         /* pointer to the 'left dust' cell for percent
 
162
                                   or 'undeline cell' for number */
 
163
  cell *          rdcp;         /* pointer to the 'right dust' cell */
 
164
  uchar            FL;           /* existing 'good' dusts flag */
 
165
  int16_t             rcps;         /* the return code of the percent searching */
 
166
  int16_t             n_ver_perc;   /* the number of the found percent version */
 
167
  /* the allowed boundaries of the upper dust */
 
168
  int16_t     ubw,          /* beginning of the widht interval */
 
169
                  uew,          /* end of the widht interval */
 
170
                  ubh,          /* beginning of the height interval */
 
171
                  ueh;          /* end of the height interval */
 
172
  /* the allowed boundaries of the lower dust */
 
173
  int16_t     lbw,          /* beginning of the widht interval */
 
174
                  lew,          /* end of the widht interval */
 
175
                  lbh,          /* beginning of the height interval */
 
176
                  leh;          /* end of the height interval */
 
177
  int16_t     mw,           /* "middl" of the widht */
 
178
          mh;           /* "middl" of the height */
 
179
  int16_t maxh;         /* maximum of height */
 
180
  int16_t like_O;       /* tolerence for circle in number */
 
181
 } perc_struct;
 
182
 
 
183
/*
 
184
        This procedure inspects given cell and makes a desision
 
185
        whether it is the percent symbol or not.
 
186
*/
 
187
/********** Prototypes of the functions ******************/
 
188
static int16_t search_perc_vers();
 
189
static int16_t search_left_dust();
 
190
static int16_t search_right_dust(int16_t like_o);
 
191
static int16_t compare_bound(cell *,char);
 
192
static int16_t rec_O0(cell *);
 
193
static int16_t change_vers();
 
194
static void collect_cell(cell *mainc, cell *c2);
 
195
static cell *collect_cell_save(cell *mainc, cell *c2);
 
196
static void prc_setup();
 
197
static void proc_perc();
 
198
static void merge_ld();
 
199
static void merge_rd();
 
200
static void compute_bnd_lbox(cell *pc,bnd_allowed *bnd);
 
201
static void compute_bnd_ubox(cell *pc,bnd_allowed *bnd);
 
202
static int16_t  search_underline_dust();
 
203
static cell *rest_composition(cell *cmplx);
 
204
static int16_t test_O0(cell *c);
 
205
static void  improve_proN();
 
206
 
 
207
Bool test_cell(cell *c);
 
208
//void Leo_ContStoreC(cell *c);
 
209
/******* Global variable *********/
 
210
perc_struct *gpt;
 
211
 
 
212
 
 
213
void number( void ) // Andrew for compose number
 
214
{
 
215
perc_struct glstr;
 
216
 
 
217
 snap_newpass('h');
 
218
 
 
219
 gpt=&glstr;
 
220
 gpt->BC=cell_f();
 
221
 while (1)
 
222
  {
 
223
    gpt->BC=gpt->BC->nextl;
 
224
    if (!gpt->BC) break;
 
225
    if (!gpt->BC->next) break;   /* dummy cell at end reached  */
 
226
 
 
227
    if( language==LANG_CROATIAN )
 
228
      continue;
 
229
 
 
230
        // �������� ��� ��� ��� PRO_NUMBER=0xc3 �����������
 
231
        // � ��������� ������ AA_semicircle. 31.05.2001 E.P.
 
232
    if( language==LANG_ROMAN)
 
233
      continue;
 
234
 
 
235
    if  ((gpt->rcps=search_perc_vers()) != (uchar)PRO_NUMBER &&    /* find the proNumber version */
 
236
          gpt->rcps != 'N')
 
237
     continue;
 
238
 
 
239
    if( db_status && snap_activity('h') ){
 
240
       snap_newcell(gpt->BC);
 
241
       snap_monitor();
 
242
    }
 
243
 
 
244
    if (gpt->rcps==(uchar)PRO_NUMBER && gpt->BC->vers[0].prob<RELIABLE_NUM)
 
245
      improve_proN();
 
246
    else
 
247
    if (gpt->rcps==(uchar)PRO_NUM_PART)
 
248
    {
 
249
      improve_proN();
 
250
      if (gpt->BC->vers[0].let != (uchar)PRO_NUMBER)
 
251
        continue;
 
252
    }
 
253
 
 
254
    prc_setup();
 
255
    proc_perc();
 
256
 
 
257
    if( gpt->BC->vers[0].let != (uchar)NUMBER && gpt->rcps != 'N'){
 
258
       gpt->BC->vers[gpt->n_ver_perc].prob = 0; // kill proNumber
 
259
       sort_vers(gpt->BC);
 
260
       gpt->BC->vers[gpt->BC->nvers].let = gpt->BC->nvers>0? 0:bad_char;
 
261
       gpt->BC->vers[gpt->BC->nvers].prob= 0; /* Set correct tail */
 
262
    }
 
263
 
 
264
  } /* end-while */
 
265
 
 
266
  return;
 
267
}/*number*/
 
268
 
 
269
 
 
270
void perc()
 
271
{
 
272
perc_struct glstr;
 
273
 
 
274
 snap_newpass('h');
 
275
 
 
276
 gpt=&glstr;
 
277
 gpt->BC=cell_f();
 
278
 while (1)
 
279
  {
 
280
    gpt->BC=gpt->BC->nextl;
 
281
    if (!gpt->BC) break;
 
282
    if (!gpt->BC->next) break;   /* dummy cell at end reached  */
 
283
    if  ((gpt->rcps=search_perc_vers())== 0)    /* find the percent version */
 
284
     continue;
 
285
 
 
286
    if( db_status && snap_activity('h') ){
 
287
       snap_newcell(gpt->BC);
 
288
       snap_monitor();
 
289
    }
 
290
 
 
291
    if (gpt->rcps==(uchar)PRO_NUMBER && gpt->BC->vers[0].prob<RELIABLE_NUM)
 
292
      improve_proN();
 
293
    else
 
294
    if (gpt->rcps==(uchar)PRO_NUM_PART)
 
295
    {
 
296
      improve_proN();
 
297
      if (gpt->BC->vers[0].let != (uchar)PRO_NUMBER)
 
298
        continue;
 
299
    }
 
300
 
 
301
    prc_setup();
 
302
    proc_perc();
 
303
  } /* end-while */
 
304
}
 
305
 
 
306
static void prc_setup()
 
307
{
 
308
cell *prd=gpt->BC;
 
309
int16_t midBC=middle(gpt->BC);
 
310
 
 
311
 while (!(prd->next->flg & c_f_fict) && middle(prd)<=midBC)
 
312
 {
 
313
   prd=prd->next;
 
314
 }
 
315
 gpt->RC=prd;
 
316
 gpt->ldcp = gpt->rdcp = NULL;
 
317
 gpt->FL=0;
 
318
 gpt->ubw=(gpt->rcps=='/') ?
 
319
   (midBC - gpt->BC->h*2/3) :
 
320
   (gpt->BC->r_col - (gpt->BC->w*BW_K_NOM)/BW_K_DENOM);
 
321
 gpt->ubh=(gpt->BC->r_row - (gpt->BC->h*BH_K_NOM)/BH_K_DENOM);
 
322
 gpt->uew=(gpt->BC->r_col + (gpt->BC->w*EW_K_NOM)/EW_K_DENOM);
 
323
 gpt->ueh=(gpt->BC->r_row + (gpt->BC->h*EH_K_NOM)/EH_K_DENOM);
 
324
 
 
325
 gpt->lbw=(gpt->BC->r_col + (gpt->BC->w*(EW_K_DENOM-EW_K_NOM))/EW_K_DENOM);
 
326
 gpt->lbh=(gpt->rcps=='N') ?
 
327
   (gpt->BC->r_row) :
 
328
   ((gpt->rcps==(uchar)PRO_NUMBER) ?
 
329
    (gpt->BC->r_row + (gpt->BC->h*(EH_K_DENOM_N-EH_K_NOM_N))/EH_K_DENOM_N) :
 
330
    (gpt->BC->r_row + (gpt->BC->h*(EH_K_DENOM-EH_K_NOM))/EH_K_DENOM)
 
331
   );
 
332
 gpt->lew=(gpt->rcps=='/') ?
 
333
   (midBC + gpt->BC->h*2/3) :
 
334
   ((gpt->rcps=='N') ?
 
335
    (gpt->BC->r_col + gpt->BC->w*2) :
 
336
    (gpt->BC->r_col + gpt->BC->w*(BW_K_DENOM+BW_K_NOM)/BW_K_DENOM)
 
337
   );
 
338
 gpt->leh=(gpt->BC->r_row + gpt->BC->h*(BH_K_DENOM+BH_K_NOM)/BH_K_DENOM);
 
339
 
 
340
 gpt->maxh=gpt->BC->h-(gpt->BC->h+H_K_DENOM_N/2)/H_K_DENOM_N;
 
341
 
 
342
 gpt->mw = gpt->BC->r_col + ((gpt->BC->w)/3);
 
343
 gpt->mh = gpt->BC->r_row + ((gpt->BC->h)>>1);
 
344
 gpt->like_O = LIKE_O;
 
345
} /*------------------------------------------------------------------*/
 
346
 
 
347
static void proc_perc()
 
348
 
 
349
{
 
350
int16_t rcslds;                /* the return code of the left dust searching */
 
351
int16_t rcsrds;                /* the return code of the right dust searching */
 
352
uchar p;
 
353
 switch (gpt->rcps)
 
354
  {
 
355
   case  '/':
 
356
      rcslds=search_left_dust();
 
357
      rcsrds=search_right_dust(gpt->like_O);
 
358
//      if ( gpt->ldcp == gpt->rdcp )
 
359
//        break;
 
360
      if ( (rcslds) && (rcsrds)&& gpt->BC->vers[gpt->n_ver_perc].prob>=RELIABLE_SL ||
 
361
           rcslds>=RELIABLE_O && gpt->FL & RightDust ||
 
362
           rcsrds>=RELIABLE_O && gpt->FL & LeftDust
 
363
         )
 
364
        goto compose;
 
365
      break;
 
366
   case  liga_uperc:
 
367
      rcsrds=search_right_dust(gpt->like_O);
 
368
      if (rcsrds == 0) break;
 
369
      goto compose;
 
370
   case  liga_lperc:
 
371
      rcslds=search_left_dust();
 
372
      if (rcslds == 0) break;
 
373
      goto compose;
 
374
   case  (uchar)PRO_NUMBER:
 
375
      rcslds=search_underline_dust();
 
376
      rcsrds=search_right_dust(gpt->like_O);
 
377
      p=gpt->BC->vers[gpt->n_ver_perc].prob;
 
378
      if (p>=RELIABLE_NUM && rcsrds ||
 
379
          rcsrds>=RELIABLE_O && rcslds &&
 
380
          gpt->ldcp->r_row > gpt->rdcp->r_row+gpt->rdcp->h)
 
381
        goto compose;
 
382
      break;
 
383
   case  'N':
 
384
      rcslds=search_underline_dust();
 
385
      rcsrds=search_right_dust(gpt->like_O);
 
386
      p=gpt->BC->vers[gpt->n_ver_perc].prob;
 
387
      if (p>=RELIABLE_NUM && rcsrds && rcslds ||
 
388
          rcsrds>=RELIABLE_O && rcslds &&
 
389
          gpt->ldcp->r_row > gpt->rdcp->r_row+gpt->rdcp->h)
 
390
        goto compose;
 
391
      break;
 
392
  } /* end-switch */
 
393
 
 
394
//not recognised
 
395
  if (gpt->ldcp)  rest_composition(gpt->ldcp);
 
396
  if (gpt->rdcp)  rest_composition(gpt->rdcp);
 
397
 
 
398
  return;
 
399
 
 
400
compose:
 
401
  merge_ld();
 
402
  merge_rd();
 
403
  change_vers();
 
404
//  Leo_ContStoreC(gpt->BC);
 
405
  return;
 
406
} /*------------------------------------------------------------------*/
 
407
 
 
408
static int16_t search_perc_vers()
 
409
{   /* searching the percent-symbol version */
 
410
 
 
411
int16_t i,rc;
 
412
uchar l=gpt->BC->vers[0].let;
 
413
 if (language==LANG_RUSSIAN)
 
414
   if (l==(uchar)'�' || l==(uchar)'�')  return PRO_NUM_PART;
 
415
 
 
416
 for (i=0,rc=0; i<=gpt->BC->nvers; i++)
 
417
  {
 
418
    if ( gpt->BC->vers[i].let == '/' )
 
419
     {
 
420
      rc='/';
 
421
      gpt->n_ver_perc=i;
 
422
      break;
 
423
     }
 
424
    if ( gpt->BC->vers[i].let == liga_uperc )
 
425
     {
 
426
      rc=liga_uperc;
 
427
      gpt->n_ver_perc=i;
 
428
      break;
 
429
     }
 
430
    if ( gpt->BC->vers[i].let == liga_lperc )
 
431
     {
 
432
      rc=liga_lperc;
 
433
      gpt->n_ver_perc=i;
 
434
      break;
 
435
     }
 
436
    if ( gpt->BC->vers[i].let == (uchar)PRO_NUMBER )
 
437
     {
 
438
      rc=(uchar)PRO_NUMBER;
 
439
      gpt->n_ver_perc=i;
 
440
      break;
 
441
     }
 
442
    if ( gpt->BC->vers[i].let == 'N' )
 
443
     {
 
444
      rc='N';
 
445
      gpt->n_ver_perc=i;
 
446
     }
 
447
  } /* end-for */
 
448
 return(rc);
 
449
} /*------------------------------------------------------------------*/
 
450
 
 
451
static int16_t search_left_dust()
 
452
{
 
453
cell *pld;
 
454
int16_t rv=0;
 
455
 
 
456
 pld=gpt->RC->prev;
 
457
 while (pld->prev && pld->r_col>=gpt->ubw)
 
458
 {
 
459
   if (pld != gpt->BC && compare_bound(pld,'L'))
 
460
   {
 
461
     pld->complist=NULL;           //single
 
462
     gpt->FL=gpt->FL | LeftDust;
 
463
     if ((rv=test_O0(pld))>LIKE_O)
 
464
     {
 
465
       if (gpt->ldcp)  rest_composition(gpt->ldcp);
 
466
       gpt->ldcp=pld;
 
467
       break;
 
468
     }
 
469
     if (gpt->ldcp)
 
470
     {
 
471
       pld=collect_cell_save(gpt->ldcp,pld);
 
472
       if ((rv=test_O0(pld))>LIKE_O)  break;
 
473
     }
 
474
     else
 
475
       gpt->ldcp=pld;
 
476
   }
 
477
   pld=pld->prev;
 
478
 }
 
479
 return rv;
 
480
} /*------------------------------------------------------------------*/
 
481
 
 
482
static int16_t search_right_dust(int16_t like_o)
 
483
{
 
484
cell *prd;
 
485
int16_t rv=0,po=0;
 
486
 
 
487
 prd=gpt->RC;
 
488
 while (prd->next && prd->r_col<=gpt->lew)
 
489
 {
 
490
   if (prd != gpt->BC && prd != gpt->ldcp && compare_bound(prd,'R'))
 
491
   {
 
492
     if (prd->h > gpt->maxh/2 && prd->w > (gpt->lew-gpt->lbw)/5)
 
493
       rv=1;
 
494
     prd->complist=NULL;           //single
 
495
     gpt->FL=gpt->FL | RightDust;
 
496
     if ((po=test_O0(prd))>like_o)
 
497
     {
 
498
       if (gpt->rdcp)  rest_composition(gpt->rdcp);
 
499
       gpt->rdcp=prd;
 
500
       break;
 
501
     }
 
502
     if (gpt->rdcp)
 
503
     {
 
504
       prd=collect_cell_save(gpt->rdcp,prd);
 
505
       if ((po=test_O0(prd))>like_o)  break;
 
506
     }
 
507
     else
 
508
       gpt->rdcp=prd;
 
509
   }
 
510
   prd=prd->next;
 
511
 }
 
512
 return MAX(rv,po);
 
513
} /*------------------------------------------------------------------*/
 
514
 
 
515
static int16_t change_vers()
 
516
{
 
517
 if ( gpt->rcps == (uchar)PRO_NUMBER || gpt->rcps == 'N' ){
 
518
    gpt->BC->vers[0].let = NUMBER;   /* first version is number */
 
519
 }
 
520
 else{
 
521
    gpt->BC->vers[0].let = '%';   /* first version is '%' */
 
522
 }
 
523
 gpt->BC->dens = 255; // undef for calc BOLD
 
524
 gpt->BC->vers[0].prob=254;
 
525
 gpt->BC->nvers=1;   /* the number of versions is 1 */
 
526
 gpt->BC->vers[1].let=0; /* end of list */
 
527
 if (gpt->BC->flg & c_f_bad)  gpt->BC->flg ^= c_f_bad | c_f_let;
 
528
 
 
529
 return  1;
 
530
 
 
531
} /*------------------------------------------------------------------*/
 
532
 
 
533
static void merge_ld()
 
534
{
 
535
 
 
536
 if (gpt->ldcp)  collect_cell(gpt->BC, gpt->ldcp);
 
537
// del_cell(gpt->ldcp);
 
538
} /*------------------------------------------------------------------*/
 
539
 
 
540
static void merge_rd()
 
541
{
 
542
 
 
543
 if (gpt->rdcp)  collect_cell(gpt->BC, gpt->rdcp);
 
544
 // del_cell(gpt->rdcp);
 
545
} /*------------------------------------------------------------------*/
 
546
 
 
547
static void collect_cell(cell *mainc, cell *c2)
 
548
{
 
549
cell * coll[3];
 
550
coll[0]=mainc;
 
551
coll[1]=c2;
 
552
compose_cell (2,coll,mainc);
 
553
snap_newcell(mainc);
 
554
} /*------------------------------------------------------------------*/
 
555
 
 
556
static cell *collect_cell_save(cell *mainc, cell *c2)
 
557
{
 
558
  cell * coll[3];
 
559
  if (!mainc->complist)  // store single cell
 
560
  {                      // complex cell is stored by components
 
561
    cell *nc=new_cell();
 
562
    memcpy(nc,mainc,sizeof(cell));
 
563
    insert_cell(nc,mainc);
 
564
    mainc->complist=(c_comp *)del_save_cell(nc);
 
565
  }
 
566
  coll[0]=mainc;
 
567
  coll[1]=c2;
 
568
  compose_cell_save (2,coll,mainc);
 
569
  c2->complist=mainc->complist;
 
570
  mainc->complist=(c_comp *)del_save_cell(c2);
 
571
  snap_newcell(mainc);
 
572
  return mainc;
 
573
} /*------------------------------------------------------------------*/
 
574
 
 
575
static int16_t compare_bound(cell *pc, char rorl)
 
576
{
 
577
bnd_allowed ldbnd;
 
578
 
 
579
 if (rorl=='R')
 
580
  {                      /* right (lower) 'dust' box case */
 
581
   compute_bnd_lbox(pc,&ldbnd);
 
582
   if (
 
583
       ( (ldbnd.bw >= gpt->lbw) && (ldbnd.bw >= gpt->mw) ) &&
 
584
       (ldbnd.bh >= gpt->lbh) &&
 
585
       (ldbnd.ew <= gpt->lew) &&
 
586
       (ldbnd.eh <= gpt->leh) &&
 
587
       (pc->h <= gpt->maxh)
 
588
      )      return(1);
 
589
   else      return(0);
 
590
  }
 
591
 if (rorl=='L')
 
592
  {                    /* left (upper) 'dust' box case */
 
593
   compute_bnd_ubox(pc,&ldbnd);
 
594
   if (
 
595
       (ldbnd.bw >= gpt->ubw) &&
 
596
       ( (ldbnd.bh >= gpt->ubh) && (ldbnd.bh <= gpt->mh) ) &&
 
597
       (ldbnd.ew <= gpt->uew) &&
 
598
       (ldbnd.eh <= gpt->ueh) &&
 
599
       (pc->h <= gpt->maxh)
 
600
      )    return(1);
 
601
   else    return(0);
 
602
  }
 
603
 return(0);
 
604
} /*------------------------------------------------------------------*/
 
605
 
 
606
static void compute_bnd_ubox(cell *pc,bnd_allowed *bnd)
 
607
{
 
608
  bnd->bw=(pc->r_col);
 
609
  bnd->bh=(pc->r_row);
 
610
  bnd->ew=(pc->r_col+pc->w);
 
611
  bnd->eh=(pc->r_row+pc->h);
 
612
} /*------------------------------------------------------------------*/
 
613
 
 
614
static void compute_bnd_lbox(cell *pc,bnd_allowed *bnd)
 
615
{
 
616
  bnd->bw=(pc->r_col);
 
617
  bnd->bh=(pc->r_row);
 
618
  bnd->ew=(pc->r_col+pc->w);
 
619
  bnd->eh=(pc->r_row+pc->h);
 
620
} /*------------------------------------------------------------------*/
 
621
 
 
622
static int16_t test_O0(cell *pc)
 
623
{
 
624
uchar rc=0;
 
625
uint16_t save_c_flg;
 
626
int16_t  saveN;
 
627
uchar saveV[VERS_IN_CELL*sizeof(version)];
 
628
version *v;
 
629
 
 
630
 
 
631
  save_c_flg=pc->flg;         /* save flag of the cell */
 
632
  saveN = pc->nvers;
 
633
  if( saveN>0 )
 
634
    memcpy(saveV,pc->vers,VERS_IN_CELL*sizeof(version));
 
635
 /* the flag storing is necessary because of short_recog_cell may change
 
636
    this flag but doas not correct the lists of the cells  */
 
637
  memset(pc->vers,0,4*sizeof(version));
 
638
  pc->nvers=3;
 
639
  pc->vers[0].let='0';   pc->vers[1].let=(uchar)'�';  pc->vers[2].let='O';
 
640
  if (test_cell(pc))
 
641
    for (v=pc->vers; v->let; v++)
 
642
      rc=MAX(rc,v->prob);
 
643
 
 
644
    if( db_status && snap_activity('h') ){
 
645
       pc->vers[0].prob=rc;
 
646
       snap_newcell(pc);
 
647
       snap_monitor();
 
648
    }
 
649
 
 
650
  pc->flg=save_c_flg;
 
651
  pc->nvers = saveN ;
 
652
  if( saveN>0 )
 
653
    memcpy(pc->vers,saveV,VERS_IN_CELL*sizeof(version));
 
654
  else
 
655
    set_bad_cell(pc);
 
656
  return(rc);
 
657
}
 
658
//------------------------------------------------
 
659
 
 
660
static int16_t rec_O0(cell *pc)
 
661
{
 
662
int16_t wi,rc;
 
663
uint16_t save_c_flg;
 
664
int16_t  saveN;
 
665
uchar saveV[VERS_IN_CELL*sizeof(version)];
 
666
 
 
667
 
 
668
  save_c_flg=pc->flg;         /* save flag of the cell */
 
669
  saveN = pc->nvers;
 
670
  if( saveN>0 )
 
671
    memcpy(saveV,pc->vers,VERS_IN_CELL*sizeof(version));
 
672
 /* the flag storing is necessary because of short_recog_cell may change
 
673
    this flag but doas not correct the lists of the cells  */
 
674
  short_recog_cell(pc);
 
675
  for (wi=0; wi < pc->nvers; wi++)
 
676
   {
 
677
    if (
 
678
        (pc->vers[wi].let == 'O') ||
 
679
    (pc->vers[wi].let == 'o') ||
 
680
        (language==LANG_RUSSIAN && ((pc->vers[wi].let == (uchar)'�')  ||
 
681
                                    (pc->vers[wi].let == (uchar)'�')))||
 
682
  (pc->vers[wi].let == '0')
 
683
       )
 
684
       {  rc=pc->vers[wi].prob;goto Rexit;}
 
685
   }  /* end-for */
 
686
  rc=0;
 
687
Rexit:
 
688
    if( db_status && snap_activity('h') ){
 
689
       snap_newcell(pc);
 
690
       snap_monitor();
 
691
    }
 
692
 
 
693
  pc->flg=save_c_flg;
 
694
  pc->nvers = saveN ;
 
695
  if( saveN>0 )
 
696
    memcpy(pc->vers,saveV,VERS_IN_CELL*sizeof(version));
 
697
  return(rc);
 
698
} /*------------------------------------------------------------------*/
 
699
 
 
700
static int16_t search_underline_dust()
 
701
{
 
702
cell *prd=gpt->RC;
 
703
Bool weak=FALSE;
 
704
 
 
705
 while (prd->next && prd->r_col<=gpt->lew)
 
706
 {
 
707
   if (prd != gpt->BC && prd->w<<1 > prd->h*3 && prd->w > gpt->BC->w>>2 &&
 
708
       compare_bound(prd,'R'))
 
709
   {
 
710
     gpt->ldcp=prd;
 
711
     prd->complist=NULL;           //single
 
712
     if (prd->w > prd->h<<1)
 
713
       return 1;
 
714
     else
 
715
       weak=TRUE;
 
716
   }
 
717
   prd=prd->next;
 
718
 }
 
719
 if (weak)  gpt->like_O=0;
 
720
 return 0;
 
721
}
 
722
 
 
723
static cell *rest_composition(cell *cmplx)
 
724
{
 
725
  cell *c=(cell *)cmplx->complist,*cl=c;
 
726
 
 
727
  if (c==NULL)  return cl;   // cmplx is single
 
728
  do
 
729
  {
 
730
    cl=rest_cell(c,cmplx);
 
731
    c=(cell *)cl->complist;
 
732
  }
 
733
  while (c);
 
734
  del_cell(cmplx);
 
735
  return cl;
 
736
}
 
737
 
 
738
static void  improve_proN()
 
739
{
 
740
  cell *BC=gpt->BC,*cl=BC->prev,*cr=BC->next;
 
741
  int16_t p=BC->vers[gpt->n_ver_perc].prob;
 
742
  int16_t w3=(5*BC->w+6)/12,h8=BC->h/8;
 
743
  int16_t bot=BC->r_row+BC->h,right=BC->r_col+BC->w;
 
744
 
 
745
  BC->complist=NULL;   //single
 
746
  while (cl->flg & c_f_dust &&
 
747
         cl->r_col>=BC->r_col-w3 && cl->r_row>BC->r_row && cl->r_row+cl->h<bot+h8)
 
748
  {
 
749
    BC=collect_cell_save(BC,cl);
 
750
    cl=BC->prev;
 
751
  }
 
752
 
 
753
  while (cr->next && middle(cr)<=right)  cr=cr->next;
 
754
  while (cr->flg & c_f_dust &&
 
755
         cr->r_col+cr->w<=right+w3 &&
 
756
         cr->r_row>BC->r_row-h8 && cr->r_row+cr->h<bot)
 
757
  {
 
758
    BC=collect_cell_save(BC,cr);
 
759
    cr=BC->next;
 
760
  }
 
761
 
 
762
  if (BC->complist != NULL)
 
763
  {
 
764
    test_cell(BC);
 
765
    if (BC->vers[0].let != (uchar)PRO_NUMBER || BC->vers[0].prob<=p)
 
766
      BC=rest_composition(BC);
 
767
    else
 
768
    {
 
769
      gpt->rcps = PRO_NUMBER;  gpt->n_ver_perc=0;
 
770
    }
 
771
    gpt->BC=BC;
 
772
  }
 
773
}
 
774
 
 
775
static RecRaster workRaster;
 
776
 
 
777
/* swapbytes takes a 32 bit value and does an endianness change.
 
778
 * Since it was only used on Windows (not Mac) I'm assuming it means
 
779
 * "swap 32 bytes between big endian and current byte order".
 
780
 */
 
781
#if defined(WIN32) && defined(_MSC_VER) && (_MSC_VER > 800)
 
782
  #define   swapbytes(a) __asm {                      \
 
783
                                 __asm   mov   EAX,a  \
 
784
                                 __asm   bswap EAX    \
 
785
                                 __asm   mov   a,EAX  \
 
786
                               }
 
787
#elif defined(__GNUC__) /* FIXME: also check that we are on x86. And little-endian. */
 
788
    #define swapbytes(a) asm ("bswap %0;" :"=r"(a) :"0"(a));
 
789
#else
 
790
  #error You must define swapbytes for your platform
 
791
#endif
 
792
 
 
793
Bool makeRasterC( c_comp* comp, RecRaster** rast )
 
794
{
 
795
   int          i,cInter,beg,end,beg31,end31,beg32,end32,width32;
 
796
   uint32_t       tmp;
 
797
   uint32_t*      rast32;
 
798
   lnhead*   plnhead;
 
799
   interval* inter;
 
800
 
 
801
   memset(&workRaster.Raster[0],0,REC_MAX_RASTER_SIZE);
 
802
   workRaster.lnPixWidth  = comp->w;
 
803
   workRaster.lnPixHeight = comp->h;
 
804
   workRaster.lnRasterBufSize = REC_MAX_RASTER_SIZE;
 
805
   width32 = REC_GW_WORD32(workRaster.lnPixWidth);
 
806
   rast32 = (uint32_t*)&workRaster.Raster[0];
 
807
 
 
808
//   assert(4*width32*workRaster.lnPixHeight <= REC_MAX_RASTER_SIZE);  Paul 10-6-97
 
809
   if (4*width32*workRaster.lnPixHeight > REC_MAX_RASTER_SIZE)
 
810
           return FALSE;
 
811
 
 
812
   plnhead = (lnhead*)((char*)comp + sizeof(c_comp) + sizeof(uint16_t));
 
813
   while( plnhead->lth ){
 
814
      cInter = plnhead->row;
 
815
      inter = (interval*)(plnhead+1);
 
816
      while( inter->l ){
 
817
         beg = inter->e - inter->l;
 
818
         end = inter->e - 1;
 
819
         beg32 = cInter*width32 + beg/32;
 
820
         end32 = cInter*width32 + end/32;
 
821
         beg31 = beg & 31;
 
822
         end31 = end & 31;
 
823
 
 
824
         for(i = beg32+1; i < end32; i++)
 
825
            rast32[i] = 0xFFFFFFFF;
 
826
         if( beg32 == end32 ){
 
827
            tmp = ( (uint32_t)0xFFFFFFFF >> beg31 ) &
 
828
                  ( (uint32_t)0xFFFFFFFF << (31-end31) );
 
829
            swapbytes(tmp);
 
830
            rast32[beg32] |= tmp;
 
831
         }
 
832
         else{
 
833
            tmp = (uint32_t)0xFFFFFFFF >> beg31;
 
834
            swapbytes(tmp);
 
835
            rast32[beg32] |= tmp;
 
836
            tmp = (uint32_t)0xFFFFFFFF << (31-end31);
 
837
            swapbytes(tmp);
 
838
            rast32[end32] |= tmp;
 
839
         }
 
840
 
 
841
         inter++;
 
842
         cInter++;
 
843
      }
 
844
      plnhead = (lnhead*)((char*)plnhead+plnhead->lth);
 
845
   }
 
846
 
 
847
   *rast = &workRaster;
 
848
   return TRUE;
 
849
}//makeRasterC
 
850
 
 
851
Bool test_cell(cell *c)
 
852
{
 
853
#ifdef _USE_LEO_
 
854
 
 
855
  RecRaster*     rst=NULL;
 
856
  RecVersions*   result;
 
857
  RecObject   recobj;
 
858
  RecAlt* alt;
 
859
  version *v;
 
860
  c_comp*  comp = c->env;
 
861
  int16_t i;
 
862
 
 
863
   // Oleg : 26-07-1995 : TCell without env can't recog
 
864
  if( !comp )
 
865
    return FALSE;
 
866
 
 
867
  memset(&recobj,0,sizeof(recobj));
 
868
  if (!makeRasterC(comp,&rst))
 
869
    return FALSE;
 
870
  memcpy(&recobj.recData.recRaster,rst,sizeof(RecRaster));
 
871
  recobj.recData.lwCompCnt = 1;
 
872
  if (c->broken_II)  recobj.recData.lwStatus |= REC_STATUS_BROKEN_II;
 
873
 
 
874
  {
 
875
    Rect16 r;
 
876
    r.left  = comp->left -1;//  + 8*(fieldRect.left/8);
 
877
    r.top   = comp->upper-1;//  + fieldRect.top ;
 
878
    r.right = comp->left  + comp->w;
 
879
    r.bottom= comp->upper + comp->h;
 
880
    recobj.recData.rect = r;
 
881
  }
 
882
  result = &recobj.recResults;
 
883
  result->lnAltCnt=c->nvers;
 
884
  assert(REC_MAX_VERS==VERS_IN_CELL);
 
885
  for (i=0,alt=result->Alt,v=c->vers; i<c->nvers; i++,alt++,v++)
 
886
    alt->Code=stdAsciiToAnsi(v->let);
 
887
//  memcpy(result->Alt,c->vers,sizeof(version)*c->nvers);
 
888
  if (!LEORecogCharPRN_expert(&recobj))  return FALSE;
 
889
  c->nvers=(int16_t)result->lnAltCnt;
 
890
  for (i=0,alt=result->Alt,v=c->vers; i<c->nvers; i++,alt++,v++)
 
891
  {
 
892
    v->let=stdAnsiToAscii(alt->Code);
 
893
    v->prob=alt->Prob;
 
894
  }
 
895
  v->let=v->prob=0;
 
896
//  memcpy(c->vers,result->Alt,sizeof(version)*c->nvers);
 
897
return TRUE;
 
898
#else
 
899
return FALSE;
 
900
#endif
 
901
 
 
902
}