~ubuntu-branches/debian/experimental/cuneiform/experimental

« back to all changes in this revision

Viewing changes to cuneiform_src/Kern/rstr/src/cg_hcut.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Baumann
  • Date: 2009-07-10 17:58:10 UTC
  • Revision ID: james.westby@ubuntu.com-20090710175810-rqc89d2i3tki9m89
Tags: upstream-0.7.0+dfsg
Import upstream version 0.7.0+dfsg

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
#include <string.h>
 
58
#include <stdlib.h>
 
59
 
 
60
#include "nt_types.h"
 
61
#include "struct.h"
 
62
#include "func.h"
 
63
#include "cut_glue.h"
 
64
#include "fondefs.h"
 
65
#include "fon.h"
 
66
#include "ligas.h"
 
67
#include "status.h"
 
68
#include "linutil.h"
 
69
 
 
70
#include "compat_defs.h"
 
71
#include "minmax.h"
 
72
 
 
73
INT gbCol1,gbCol2;
 
74
 
 
75
typedef struct tagRecogStat
 
76
{
 
77
  INT nbig,ndust,weight;
 
78
} RecogStat;
 
79
 
 
80
static B_LINES bl;
 
81
static BOOL fb1;
 
82
static BOOL fb2;
 
83
static BOOL fb3;
 
84
static BOOL fb4;
 
85
static INT bl_lim=3;
 
86
 
 
87
static INT dirt_frag(cell **B, cell **E, cell *first, cell *last, BOOL stop_first);
 
88
static void bl_cut(cell *B, cell *E, INT cut);
 
89
static BOOL find_clust(BYTE let);
 
90
static BOOL clip_cell(INT j, cell *c, INT b1, INT b2, INT b3, INT b4, INT st_inc);
 
91
static void save_frag(cell *B, cell *E, RecogStat *rs, cell **sv_frag, INT *st_inc);
 
92
static void replace_frag(cell *B, cell *E, RecogStat *rs, cell *sv_frag);
 
93
static  INT create_cells(cell *whither, raster *r, cell *celist[], INT st_inc);
 
94
static cell *hide(cell *c, cell **clink);
 
95
static void restore(cell *clink, cell *wherever);
 
96
static void del_hided(cell *clink);
 
97
static BOOL capital(BYTE let);
 
98
 
 
99
void  base_lines_cut()
 
100
{
 
101
  cell *BI,*EI,*B0=cell_f()->nextl,*E0=cell_l();
 
102
  INT cut=0;
 
103
  get_b_lines(NULL,&bl);
 
104
  fb1=bl.n1>0 && bl.n1<255;
 
105
  fb2=bl.n2>0 && bl.n2<255;
 
106
  fb3=bl.n3>0 && bl.n3<255;
 
107
  fb4=bl.n4>0 && bl.n4<255;
 
108
 
 
109
  if (fict(B0) || !(cut=dirt_frag(&B0,&E0,B0,E0->prevl,FALSE)))
 
110
    return;
 
111
 
 
112
  BI=B0;  EI=E0=E0->nextl;
 
113
  if (E0->nextl)  E0=E0->nextl;
 
114
  while(dirt_frag(&BI,&EI,cell_f()->nextl,cell_l()->prevl,TRUE))
 
115
  {
 
116
    cell *R;
 
117
    if (fict(BI->prevl)) BI=cell_f()->next;
 
118
    else                 BI=BI->prevl;
 
119
    if (fict(EI->nextl)) { R=cell_l();   EI=R->prev;  }
 
120
    else                 { EI=EI->nextl; R=EI->nextl; }
 
121
    bl_cut(BI,EI,cut);
 
122
    BI=R;  EI=E0;
 
123
  }
 
124
}
 
125
/*
 
126
static BOOL dirt_frag(cell **B,cell **E)
 
127
{
 
128
  cell *c=cell_f()->next;
 
129
  gbCol1=gbCol2=0;
 
130
  glsnap('o',c,"Cut by bases; input r_col for begin and end");
 
131
  if (gbCol1==0 && gbCol2==0 || gbCol1>gbCol2)
 
132
    return FALSE;
 
133
 
 
134
  *B=*E=NULL;
 
135
  for ( ; c->next; c=c->next)
 
136
  {
 
137
    if (c->r_col==gbCol1)   *B=c;
 
138
    if (c->r_col==gbCol2) { *E=c;  break; }
 
139
  }
 
140
 
 
141
  return (B && E);
 
142
}
 
143
*/
 
144
 
 
145
LONG testDirt(CSTR_rast *beg, CSTR_rast *end)
 
146
{
 
147
  CSTR_rast rst=*beg,first=rst,last=CSTR_GetNext(*end);
 
148
  CSTR_rast capb=0,cape=0;
 
149
  INT dirtup=0,dirtdown=0,ncap=0;
 
150
 
 
151
  get_b_lines(NULL,&bl);
 
152
  fb1=bl.n1>0 && bl.n1<255;
 
153
  fb2=bl.n2>0 && bl.n2<255;
 
154
  fb3=bl.n3>0 && bl.n3<255;
 
155
  fb4=bl.n4>0 && bl.n4<255;
 
156
 
 
157
  *beg=*end=0;
 
158
 
 
159
  for ( ; rst != last; rst=CSTR_GetNext(rst))
 
160
  {
 
161
    CSTR_rast_attr attr;
 
162
    UniVersions     uni;
 
163
    CSTR_GetAttr(rst,&attr);
 
164
 
 
165
    if (fb1 && attr.row+bl_lim < bl.b1)      { dirtup++;   goto mark; }
 
166
    if (fb4 && attr.row+attr.h-bl_lim > bl.b4) { dirtdown++; goto mark; }
 
167
 
 
168
    CSTR_GetCollectionUni(rst,&uni);
 
169
 
 
170
    if (uni.Alt[0].Prob<trs2)
 
171
    {
 
172
      BYTE let=uni.Alt[0].Code[0],letpos = let_linpos[let];
 
173
      INT bot=attr.row+attr.h;
 
174
      BOOL d2=attr.row<bl.b2-bl_lim,d3=bot>bl.b3+bl_lim;
 
175
 
 
176
      if (uni.lnAltCnt==0)
 
177
      {
 
178
        if (d2)  { dirtup++;   goto mark; }
 
179
        if (d3)  { dirtdown++; goto mark; }
 
180
      }
 
181
      if (rst != first && capital(let))
 
182
      {
 
183
        ncap++;
 
184
        if (!capb)  capb=rst;
 
185
        cape=rst;
 
186
      }
 
187
      switch(letpos & 0x0F)
 
188
      {
 
189
      case 1: case 4:
 
190
        if (fb3 && d3)  { dirtdown++; goto mark; };
 
191
        break;
 
192
      case 2: case 5: case 6: case 7:
 
193
        if (fb4 && bot>bl.b4-bl_lim)  { dirtdown++; goto mark; };
 
194
        break;
 
195
      }
 
196
      if (!strchr("3568�������",let))
 
197
      {
 
198
        letpos >>= 4;
 
199
        switch(letpos)
 
200
        {
 
201
        case 1:
 
202
          if (fb1 && abs(attr.row-bl.b1)>bl_lim)  { dirtup++;   goto mark; }
 
203
          break;
 
204
        case 2: case 10:
 
205
          if (fb2 && d2)  { dirtup++;   goto mark; }
 
206
          break;
 
207
        case 3:  case 4:  case 5:
 
208
          if (fb1 && attr.row<bl.b1+bl_lim)  { dirtup++;   goto mark; }
 
209
          break;
 
210
        }
 
211
      }
 
212
    }
 
213
    continue;
 
214
 
 
215
mark:
 
216
    if (!(*beg))  *beg=rst;
 
217
    *end=rst;
 
218
  }
 
219
 
 
220
  if (dirtup==0 && ncap>1)  dirtup += ncap;
 
221
  if (!(*beg))   { *beg=capb;  *end=cape; }
 
222
  if (dirtup > 2*dirtdown)  return  1;
 
223
  if (dirtdown > 2*dirtup)  return -1;
 
224
  return 0;
 
225
}
 
226
 
 
227
static INT dirt_frag(cell **B, cell **E, cell *first, cell *last, BOOL stop_first)
 
228
{
 
229
  cell *c=*B,*end=*E;
 
230
  cell *capb=NULL,*cape=NULL;
 
231
  INT dirtup=0,dirtdown=0,ncap=0;
 
232
/*
 
233
  gbCol1=gbCol2=0;
 
234
  glsnap('o',c,"Cut by bases; input r_col for begin and end");
 
235
  if (gbCol1 != 0 && gbCol2 != 0 && abs(gbCol1)<=abs(gbCol2))
 
236
    return gbCol1/abs(gbCol1);
 
237
*/
 
238
  *B=*E=NULL;
 
239
  for ( ; c != end && !fict(c); c=c->nextl)
 
240
  {
 
241
    if (c==last && 4*c->w < c->h)  continue;
 
242
 
 
243
    if (fb1 && c->row+bl_lim < bl.b1)      { dirtup++;   goto mark; }
 
244
    if (fb4 && c->row+c->h-bl_lim > bl.b4) { dirtdown++; goto mark; }
 
245
 
 
246
    if (c->vers[0].prob<trs2)
 
247
    {
 
248
      BYTE let=c->vers[0].let;
 
249
      BYTE letpos = let_linpos[let];
 
250
      INT bot=c->row+c->h;
 
251
      BOOL d2 = (fb2) ? c->row<bl.b2-bl_lim : TRUE;
 
252
      BOOL d3 = (fb3) ? bot>bl.b3+bl_lim : TRUE;
 
253
 
 
254
      if ((c->pr_vers.prob>=220 ||
 
255
                                strchr("���",c->pr_vers.let) &&
 
256
                !is_russian_baltic_conflict(c->pr_vers.let)&&// 17.07.2001 E.P.
 
257
                                !is_russian_turkish_conflict(c->pr_vers.let) // 21.05.2002 E.P.
 
258
                        ) && !find_clust(c->pr_vers.let)
 
259
                  )
 
260
        continue;
 
261
 
 
262
      if (!c->nvers)
 
263
      {
 
264
        BYTE let=c->pr_vers.let;
 
265
//        if (c->pr_vers.prob>=220)  continue;
 
266
        if (d2)
 
267
        {
 
268
          if (!d3)
 
269
          {
 
270
            if (c->pr_vers.prob>100 && strchr("3568EH�������",let))
 
271
              continue;
 
272
            if (strchr("EH������",let) || 5*c->w < 4*c->h)
 
273
            {
 
274
              STICK *st;
 
275
              if (c->n_baton==255)
 
276
                sticks_in_letter(c,0,&st);
 
277
              if (c->n_baton==1 && abs(c->save_baton[0].l-c->h)<=bl_lim ||
 
278
                  c->n_baton==2 && abs(c->save_baton[1].l-c->h)<=bl_lim)
 
279
              continue;
 
280
            }
 
281
          }
 
282
          dirtup++;
 
283
          goto mark;
 
284
        }
 
285
        if (d3)
 
286
        {
 
287
          if (!d2)
 
288
            if (
 
289
                                // 16.07.2001 E.P. �������� � a_bottom_accent_baltic 0xe0
 
290
                                !is_baltic_language(language) &&
 
291
                                let=='�' &&     // 0xe0
 
292
                                (c->pr_vers.prob>100 || abs(c->save_baton[0].l-c->h)<=bl_lim)
 
293
                           )
 
294
              continue;
 
295
 
 
296
          dirtdown++;
 
297
          goto mark;
 
298
        }
 
299
      }
 
300
 
 
301
      if ((c != first || stop_first) && capital(let))
 
302
      {
 
303
        ncap++;
 
304
        if (!capb)  capb=c;
 
305
        cape=c;
 
306
      }
 
307
      if (let!='�' ||
 
308
                        // 16.07.2001 E.P. �������� � a_bottom_accent_baltic 0xe0
 
309
                    is_baltic_language(language)
 
310
                  )
 
311
        switch(letpos & 0x0F)
 
312
        {
 
313
        case 1: case 4:
 
314
          if (fb3 && d3)  { dirtdown++; goto mark; };
 
315
          break;
 
316
        case 2: case 5: case 6: case 7:
 
317
          if (fb4 && bot>bl.b4-bl_lim)  { dirtdown++; goto mark; };
 
318
          break;
 
319
        }
 
320
      letpos >>= 4;
 
321
      if (!strchr("3568�������",let))
 
322
        switch(letpos)
 
323
        {
 
324
        case 1:
 
325
          if (fb1 && abs(c->row-bl.b1)>bl_lim)  { dirtup++;   goto mark; }
 
326
          break;
 
327
        case 2: case 10:
 
328
          if (fb2 && d2)  { dirtup++;   goto mark; }
 
329
          break;
 
330
        case 3:  case 4:  case 5:
 
331
          if (fb1 && c->row<bl.b1+bl_lim)  { dirtup++;   goto mark; }
 
332
          break;
 
333
        }
 
334
/*
 
335
      if (d2 || d3)
 
336
      {
 
337
        ClustInfo cli;
 
338
        LONG nc=FONGetNumCluster(c->r_clink);
 
339
              FONGetClustInfo(&cli,nc);
 
340
        if (cli.prob>=trs2)
 
341
        {
 
342
          if (d2) dirtup++;
 
343
          if (d3) dirtdown++;
 
344
          goto mark;
 
345
        }
 
346
      }
 
347
*/
 
348
    }
 
349
    if (stop_first && *B)  break;
 
350
    continue;
 
351
 
 
352
mark:
 
353
    if (!(*B))  *B=c;
 
354
    *E=c;
 
355
  }
 
356
 
 
357
  if (dirtup==0 && ncap>1)  dirtup += ncap;
 
358
  if (!(*B))   { *B=capb;  *E=cape; }
 
359
/*
 
360
  if (*B && !fict((*B)->prevl))  *B=(*B)->prevl;
 
361
  if (*E && !fict((*E)->nextl))  *E=(*E)->nextl;
 
362
*/
 
363
  if (dirtup > 2*dirtdown)  return  1;
 
364
  if (dirtdown > 2*dirtup)  return -1;
 
365
  return 0;
 
366
}
 
367
 
 
368
static BOOL find_clust(BYTE let)
 
369
{
 
370
#ifdef _USE_FON_
 
371
  ClustInfo clustinfo;
 
372
  clustinfo.let=let;
 
373
  return FONGetClustInfo( &clustinfo,1) > 0;
 
374
#else
 
375
  return FALSE;
 
376
#endif
 
377
}
 
378
 
 
379
static void bl_cut(cell *B, cell *E, INT cut)
 
380
{
 
381
  cell *f=B,*LC=B->prev,*RC=E->next;
 
382
  RecogStat rs;
 
383
  cell *sv_frag=NULL;
 
384
  INT st_inc;          //�।��� ������
 
385
  BOOL repair=TRUE;
 
386
 
 
387
  //save current state
 
388
  save_frag(B,E,&rs,&sv_frag,&st_inc);
 
389
 
 
390
  //make cut by base lines
 
391
  while (f != RC)
 
392
  {
 
393
    cell *c=f;
 
394
    f=f->next;
 
395
    c->cg_flag &= ~c_cg_cutdone;  //c_cg_cutdone flag prevents cell to cut in smart_cut
 
396
    if (let_or_bad(c) && c->vers[0].prob>=trs2)
 
397
    {
 
398
      c->flg &= ~c_f_bad;  c->flg |= c_f_let;
 
399
    }
 
400
    else
 
401
    {
 
402
      INT b1 = (fb1 && cut>0) ? bl.b1-c->row : 0;
 
403
      INT b2 = (fb2 && cut>0) ? bl.b2-c->row : 0;
 
404
      INT b3 = (fb3 && cut<0) ? bl.b3-c->row : 0;
 
405
      INT b4 = (fb4 && cut<0) ? bl.b4-c->row : 0;
 
406
 
 
407
      if (let_or_bad(c))
 
408
      {
 
409
        c->flg &= ~c_f_let;  c->flg |= c_f_bad;
 
410
      }
 
411
 
 
412
      if (b1>0 || b2>0 || b3<c->h || b4<c->h)
 
413
      {
 
414
        glsnap('o',c,"try clip");
 
415
        repair &= clip_cell(0,c,b1,b2,b3,b4,st_inc);
 
416
      }
 
417
    }
 
418
  }
 
419
 
 
420
  if (!repair)
 
421
  {
 
422
    if (LC->next != RC && LC != RC->prev)
 
423
    {
 
424
      process_word(LC->next,RC->prev);
 
425
      replace_frag(LC->next,RC->prev,&rs,sv_frag);
 
426
    }
 
427
  }
 
428
  else
 
429
    del_hided(sv_frag);
 
430
}
 
431
 
 
432
static BOOL clip_cell(INT j, cell *c, INT b1, INT b2, INT b3, INT b4, INT st_inc)
 
433
{
 
434
//��१��� �� c ��, �� ��室�� �� b1,b4 (����� �� c->row); b2,b3 - �������⥫�� ࠧ१�,
 
435
// �᫨ �㦭�
 
436
//  INT j;
 
437
  INT crow=c->row;  //b1,b2,b3,b4 refer to crow
 
438
  BOOL repair=TRUE;
 
439
 
 
440
//  for (j=0; j<2 && c; j++)
 
441
  if (j<2)
 
442
  {
 
443
    BOOL cut_made=FALSE;
 
444
 
 
445
    if (j==0)
 
446
    {
 
447
      if (b1<=2 || b1>=c->h)  b1=0;
 
448
      if (b4>=c->h-2)  b4=0;
 
449
      cut_made = b1>0 || b4>0;
 
450
    }
 
451
    else
 
452
    {
 
453
      if (b2<=2 || b2>=c->h)   b2=0;
 
454
      if (b3<=0 || b3>c->h-2)  b3=0;
 
455
      cut_made = b2>0 || b3>0;
 
456
    }
 
457
 
 
458
    if (cut_made)
 
459
    {
 
460
      raster r;                   //�஬������ ����
 
461
      cell *celist[MAX_SECT+1];
 
462
      INT wbyte=(c->w+7)>>3,i,nall,size=((c->w+7)>>3)*c->h;
 
463
      INT nbig=0;
 
464
 
 
465
      if (size>sizeof(r.pict))
 
466
        return FALSE;
 
467
      memcpy(&(r.pict),(BYTE*)save_raster(c),size);
 
468
      r.w=c->w; r.h=c->h; r.top=c->r_row; r.left=c->r_col;
 
469
 
 
470
      if (j==0)
 
471
      {
 
472
        if (b1>0)  memset(r.pict,0,b1*wbyte);
 
473
        if (b4>0)  memset(&(r.pict[(b4+1)*wbyte]),0,(c->h-b4-1)*wbyte);
 
474
      }
 
475
      else
 
476
      {
 
477
        if (b2>0)  memset(&(r.pict[b2*wbyte]),0,wbyte);
 
478
        if (b3>0)  memset(&(r.pict[(b3+1)*wbyte]),0,wbyte);
 
479
      }
 
480
 
 
481
      if (!(nall=create_cells(c,&r,celist,st_inc)))
 
482
        return FALSE;
 
483
 
 
484
      for (i=0; i<nall; i++)
 
485
      {
 
486
        cell *t=celist[i];
 
487
        t->flg_new |= CSTR_fn_bl_cut;
 
488
        t->cg_flag=c->cg_flag;
 
489
        if (t->r_col != c->r_col)           t->cg_flag &= ~c_cg_cutl;
 
490
        if (t->r_col+t->w != c->r_col+c->w) t->cg_flag &= ~c_cg_cutr;
 
491
        if (dust(t))
 
492
        {
 
493
//          if (t->row+t->h==crow+b2 || t->row==crow+b3+2)
 
494
          continue;
 
495
        }
 
496
        nbig++;
 
497
        if (bad(t))
 
498
        {
 
499
          full_recog(t,NULL,trs2,trs2);
 
500
          if (!let(t))  repair &= clip_cell((INT)(j+1),t,0,(INT)(crow+b2-t->row),(INT)(crow+b3-t->row),0,st_inc);
 
501
        }
 
502
      }
 
503
      del_cell(c);
 
504
      c=NULL;
 
505
      return repair && nbig != 0;
 
506
    }
 
507
    else
 
508
      return clip_cell((INT)(j+1),c,0,(INT)(crow+b2-c->row),(INT)(crow+b3-c->row),0,st_inc);
 
509
  }
 
510
  return let(c) != 0;
 
511
}
 
512
 
 
513
static INT create_cells(cell *whither, raster *r, cell *celist[], INT st_inc)
 
514
{
 
515
  INT i;
 
516
  MN  *mn=c_locomp(r->pict,(INT)((r->w+7)>>3),r->h,r->top,r->left);
 
517
  for (i=0; i<MAX_SECT && mn; i++,mn=mn->mnnext)
 
518
  {
 
519
    cell *c=create_my_cell(mn,whither,0,0);
 
520
    inter_diff(c);
 
521
    set_erection(c, st_inc);
 
522
    celist[i]=c;
 
523
  }
 
524
  return i;
 
525
}
 
526
 
 
527
static void save_frag(cell *B, cell *E, RecogStat *rs, cell **sv_frag, INT *st_inc)
 
528
{
 
529
  cell *celist[MAX_SECT];
 
530
  INT n=0;
 
531
  E=E->next;
 
532
  B->complist=NULL;
 
533
  rs->weight=256;  rs->nbig=rs->ndust=0;
 
534
  for ( ; B != E; B=B->next)
 
535
  {
 
536
    cell *c=new_cell();
 
537
    *c=*B;
 
538
    c->complist=(c_comp *)(*sv_frag);
 
539
    *sv_frag=c;
 
540
    if (let_or_bad(B))
 
541
    {
 
542
      rs->nbig++;
 
543
      rs->weight = MIN(rs->weight,B->vers[0].prob);
 
544
    }
 
545
    else
 
546
      if (fb2 && fb3 && c->row > bl.b2 && c->row+c->h < bl.b3)
 
547
        rs->ndust++;
 
548
    if (n<MAX_SECT)  celist[n++]=B;
 
549
  }
 
550
  *st_inc = erection_compose_inc(n, celist);
 
551
}
 
552
 
 
553
static void replace_frag(cell *B, cell *E, RecogStat *rs, cell *sv_frag)
 
554
{
 
555
  cell *c;
 
556
  INT weight=256,nbig=0,ndust=0;
 
557
//  B_LINES bs=bl;
 
558
 
 
559
  E=E->next;
 
560
  for (c=B; c != E; c=c->next)
 
561
    if (let_or_bad(c))
 
562
    {
 
563
      nbig++;
 
564
      weight = MIN(weight,c->vers[0].prob);
 
565
    }
 
566
    else
 
567
      if (fb2 && fb3 && c->row > bl.b2 && c->row+c->h < bl.b3)
 
568
        ndust++;
 
569
 
 
570
  if (nbig < rs->nbig && ndust > rs->ndust ||  //some big cells's cut to dust
 
571
      weight <= rs->weight)
 
572
  {
 
573
    for (c=B; c != E; c=c->next)  c=del_cell(c);
 
574
    restore(sv_frag,c);
 
575
  }
 
576
  else
 
577
    del_hided(sv_frag);
 
578
}
 
579
 
 
580
static cell *hide(cell *c, cell **clink)
 
581
{
 
582
    cell *cp=c->prev;
 
583
    c->complist=(c_comp *)(*clink);
 
584
    del_retain_cell(c);
 
585
    *clink=c;
 
586
    return cp;
 
587
}
 
588
 
 
589
static void restore(cell *clink, cell *wherever)
 
590
{
 
591
  while (clink)
 
592
  {
 
593
    insert_cell(clink,wherever);
 
594
    clink=(cell *)clink->complist;
 
595
  }
 
596
}
 
597
 
 
598
static void del_hided(cell *clink)
 
599
{
 
600
  while (clink)
 
601
  {
 
602
    free_cell(clink);
 
603
    clink=(cell *)clink->complist;
 
604
  }
 
605
}
 
606
 
 
607
static BOOL capital(BYTE let)
 
608
{
 
609
    return (let>='0' && let<='9' || let>='A' && let<='Z' || let>='�' && let<='�');
 
610
}