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

« back to all changes in this revision

Viewing changes to cuneiform_src/Kern/rstr/src/cutpoint.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:
2
2
Copyright (c) 1993-2008, Cognitive Technologies
3
3
All rights reserved.
4
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
 
�������� ��� ������ ���� ���� �������� � ����������� ����� ������� � ������.
 
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
32
 
33
33
Redistribution and use in source and binary forms, with or without modification,
34
34
are permitted provided that the following conditions are met:
59
59
#include <stdlib.h>
60
60
#include <string.h>
61
61
 
62
 
#include "nt_types.h"
63
62
#include "struct.h"
64
63
#include "cuthdr.h"
65
64
#include "dmconst.h"
72
71
#include "compat_defs.h"
73
72
 
74
73
//  snap globals
75
 
extern BYTE db_status;      // snap presence byte
76
 
extern BYTE db_trace_flag;  // 2 - more detailed estimate (ALT-F7)
77
 
extern CHAR db_pass;
78
 
 
79
 
extern BYTE *ForRaster1;
80
 
 
81
 
static void begin(INT,INT);
 
74
extern uchar db_status;      // snap presence byte
 
75
extern uchar db_trace_flag;  // 2 - more detailed estimate (ALT-F7)
 
76
extern char db_pass;
 
77
 
 
78
extern uchar *ForRaster1;
 
79
 
 
80
static void begin(int16_t,int16_t);
82
81
static void allcuts();
83
82
static void interlines();
84
 
static void minlincut(CHAR);
85
 
static void fixcut(INT,INT,INT,INT);
86
 
static INT scamin(INT,INT,INT);
87
 
static void regmin(CHAR);
 
83
static void minlincut(char);
 
84
static void fixcut(int16_t,int16_t,int16_t,int16_t);
 
85
static int16_t scamin(int16_t,int16_t,int16_t);
 
86
static void regmin(char);
88
87
static void make_limits();
89
88
static void findbotbnd();
90
 
static INT bot_serif(CHAR);
91
 
// static INT verifh(PCHAR,CHAR,CHAR);
92
 
static INT walltest(INT,INT,INT,INT,INT);
93
 
static INT middle_puso(CHAR);
94
 
static INT lower_gap(CHAR);
95
 
static void lower_pen(CHAR);
 
89
static int16_t bot_serif(char);
 
90
// static int16_t verifh(pchar,char,CHAR);
 
91
static int16_t walltest(int16_t,int16_t,int16_t,int16_t,int16_t);
 
92
static int16_t middle_puso(char);
 
93
static int16_t lower_gap(char);
 
94
static void lower_pen(char);
96
95
static void findtopbnd();
97
 
static INT top_serif(CHAR);
98
 
static INT upper_gap(CHAR);
99
 
// static INT lower_gap2(CHAR);
100
 
static void define_cat(struct extrem_elem *,CHAR);
 
96
static int16_t top_serif(char);
 
97
static int16_t upper_gap(char);
 
98
// static int16_t lower_gap2(char);
 
99
static void define_cat(struct extrem_elem *,char);
101
100
static void make_func();
102
 
static INT make_extrem(PCHAR,struct extrem_elem *);
103
 
static INT make_absextr(CHAR,struct extrem_elem *);
 
101
static int16_t make_extrem(pchar,struct extrem_elem *);
 
102
static int16_t make_absextr(char,struct extrem_elem *);
104
103
static void make_info();
105
 
static CHAR bodyes[128], cut_place[128];
106
 
static CHAR foots[128], heads[128];
 
104
static char bodyes[128], cut_place[128];
 
105
static char foots[128], heads[128];
107
106
static struct extrem_elem exbody[MAX_HOR/2];
108
107
static struct extrem_elem exfoot[MAX_HOR/2];
109
108
static struct extrem_elem exhead[MAX_HOR/2];
110
 
static INT totalh;
 
109
static int16_t totalh;
111
110
//Lepik searches objezd:
112
 
 static INT  SearchObjezd(INT x,  PBYTE c,
113
 
                          INT width, INT y,
114
 
                          INT dh, INT r0,
115
 
                          INT height, INT y_beg);
116
 
 
117
 
 
118
 
static void begin(INT width,INT height)
 
111
 static int16_t  SearchObjezd(int16_t x,  puchar c,
 
112
                          int16_t width, int16_t y,
 
113
                          int16_t dh, int16_t r0,
 
114
                          int16_t height, int16_t y_beg);
 
115
 
 
116
 
 
117
static void begin(int16_t width,int16_t height)
119
118
//
120
119
//      This procedure sets up all variables.
121
120
//
138
137
// This procedure builds graphics and finds all reasonable cutting points.
139
138
//
140
139
 {
141
 
 INT  cline;
142
 
 CHAR svbest, svbestx;
 
140
 int16_t  cline;
 
141
 char svbest, svbestx;
143
142
 struct extrem_elem *Extrc;
144
 
 INT  pnt;
 
143
 int16_t  pnt;
145
144
 
146
145
 
147
146
 lastmax=0;
167
166
  if ((cline==path[0]) || (cline==path[path_lth-1])) goto try;
168
167
  if (less_vertices[cline].n_connect == 1) continue;
169
168
try:
170
 
  svbestx=bestx=(CHAR)pnt; svbest=best=Extrc->val;
 
169
  svbestx=bestx=(char)pnt; svbest=best=Extrc->val;
171
170
  // TRY TO AVOID ALL semantic - just take minbody
172
171
 if (svbest < 3) { regmin(4); continue; }
173
172
/****************************************************************
205
204
 
206
205
 lower_pen(3);
207
206
 
208
 
 Eahn=(CHAR)make_absextr(0,exhead);
209
 
 Eafn=(CHAR)make_absextr(1,exfoot);
 
207
 Eahn=(char)make_absextr(0,exhead);
 
208
 Eafn=(char)make_absextr(1,exfoot);
210
209
 
211
210
 extrc=&exhead[2];
212
211
 extrp=&exhead[1];
252
251
{  // NOT USED YET      analyze points at lines
253
252
}
254
253
 
255
 
static void minlincut(CHAR arg)
 
254
static void minlincut(char arg)
256
255
//
257
256
//    This procedure builds graphics and finds all reasonable cutting points.
258
257
//
259
258
 {
260
 
 INT nx, cline,min, max, svf, svn, svl,twh, tw2, tw3, is4,
 
259
 int16_t nx, cline,min, max, svf, svn, svl,twh, tw2, tw3, is4,
261
260
     wdsfl, lastx, lastw, curw, nfix, flgr, fldef;
262
261
 struct info_elm *inf;
263
262
 
288
287
  {
289
288
  curw=inf->sumb;
290
289
  is4=curw<<2;
291
 
  if ((INT)min >= (INT)(inf->botf)) min=inf->botf;
292
 
  if ((INT)max <= (INT)(inf->toph)) max=inf->toph;
293
 
  if ((INT)is4 > (INT)t_width)
 
290
  if ((int16_t)min >= (int16_t)(inf->botf)) min=inf->botf;
 
291
  if ((int16_t)max <= (int16_t)(inf->toph)) max=inf->toph;
 
292
  if ((int16_t)is4 > (int16_t)t_width)
294
293
   { wdsfl++;  nfix=2; }            // may look at thin line
295
 
  if (((INT)(max-min) > (INT)twh) && ((nx >(INT)5) && svn))
 
294
  if (((int16_t)(max-min) > (int16_t)twh) && ((nx >(int16_t)5) && svn))
296
295
   { fixcut(svf,svl,svn,arg); svn=0; max=0; min=127; }
297
 
  if ((INT)lastw == (INT)curw)
 
296
  if ((int16_t)lastw == (int16_t)curw)
298
297
   continue;
299
 
  if ((INT)lastw > (INT)curw)                 // became narrower
 
298
  if ((int16_t)lastw > (int16_t)curw)                 // became narrower
300
299
   {
301
 
   if (((INT)nx > (INT)(t_height-4)) && ((INT)(nx-lastx) > (INT)2))
 
300
   if (((int16_t)nx > (int16_t)(t_height-4)) && ((int16_t)(nx-lastx) > (int16_t)2))
302
301
                                        // close to pattern end
303
302
    {
304
303
     if ((lastw<<2) > tw3)           // too thick
355
354
 fixcut(127,lastx,nx,arg);
356
355
 }
357
356
 
358
 
static void fixcut(INT fl,INT x1,INT x2,INT arg)
 
357
static void fixcut(int16_t fl,int16_t x1,int16_t x2,int16_t arg)
359
358
 {
360
 
 INT ctf;
 
359
 int16_t ctf;
361
360
 
362
361
 switch (arg)
363
362
  {
372
371
  }
373
372
 if (fl>1)
374
373
  if (! scamin(x1,-1,ctf))
375
 
   { bestx=(CHAR)x1; regmin((CHAR)ctf); }
 
374
   { bestx=(char)x1; regmin((char)ctf); }
376
375
 if (fl<127)
377
376
  if (! scamin(x2,1,ctf))
378
 
   { bestx=(CHAR)x1; regmin((CHAR)ctf); }
 
377
   { bestx=(char)x1; regmin((char)ctf); }
379
378
 if ((fl>1) && (fl<127))
380
379
  {
381
380
  bestx=(x1+x2)>>1;
382
 
  regmin((CHAR)ctf);
 
381
  regmin((char)ctf);
383
382
  }
384
383
 }
385
384
 
386
 
static INT scamin(INT a,INT d,INT r)
 
385
static int16_t scamin(int16_t a,int16_t d,int16_t r)
387
386
 {
388
 
 INT nx, y, m;
 
387
 int16_t nx, y, m;
389
388
 
390
389
 nx=a;
391
390
 y=points[nx].sumb;
394
393
  while ((nx>4) && (nx <(t_height-4)) &&  ((points[nx].sumb-y) <= 1));
395
394
 if (abs(m-a) > 2)
396
395
  {
397
 
  bestx=(CHAR)m;
398
 
  regmin((CHAR)r);
 
396
  bestx=(char)m;
 
397
  regmin((char)r);
399
398
  return 1;
400
399
  }
401
400
 return 0;
402
401
 }
403
402
 
404
 
static void regmin(CHAR c)
 
403
static void regmin(char c)
405
404
// cut in x=bestx, method=c;
406
405
 {
407
 
 INT v, line_num; CHAR rept, full, w, wx, ww, dh, h, vr;
 
406
 int16_t v, line_num; char rept, full, w, wx, ww, dh, h, vr;
408
407
 struct info_elm *inf;
409
408
 struct own_cut *ad;
410
409
 
416
415
 
417
416
 if (full)
418
417
  {
419
 
  h=dh=(CHAR)t_width;
 
418
  h=dh=(char)t_width;
420
419
  if (inf->lnum==1)
421
420
   {
422
421
   if ((3*inf->sumb) > (t_width<<1))
437
436
 
438
437
 line_num = linumsx[wx];
439
438
 if (line_num==0)
440
 
 { h=dh=(CHAR)t_width;}
 
439
 { h=dh=(char)t_width;}
441
440
 else
442
441
 {
443
442
   struct short_line_header *l_ptr;
444
443
   struct segment *s_ptr;
445
444
   line_num--;
446
445
   l_ptr=&Ed_lines[line_num];
447
 
   s_ptr = (struct segment *) ((BYTE *)t_line_ptr + l_ptr->segm_addr);
 
446
   s_ptr = (struct segment *) ((uchar *)t_line_ptr + l_ptr->segm_addr);
448
447
   s_ptr += wx-l_ptr->top;
449
448
   dh=s_ptr->lth;
450
449
   h=s_ptr->end;
494
493
 
495
494
static void make_limits()
496
495
 {
497
 
 CHAR nx, min, max, w;
 
496
 char nx, min, max, w;
498
497
 
499
 
 Exbn=(CHAR)make_extrem(bodyes,exbody);
 
498
 Exbn=(char)make_extrem(bodyes,exbody);
500
499
 ExbM=ExtreM; Exbm=Extrem; Exbx=Extrex;
501
 
 Exfn=(CHAR)make_extrem(foots,exfoot);
 
500
 Exfn=(char)make_extrem(foots,exfoot);
502
501
 ExfM=ExtreM; Exfm=Extrem;
503
 
 Exhn=(CHAR)make_extrem(heads,exhead);
 
502
 Exhn=(char)make_extrem(heads,exhead);
504
503
 ExhM=ExtreM; Exhm=Extrem;
505
504
 define_cat(exbody,Exbn);
506
505
 define_cat(exfoot,Exfn);
528
527
 
529
528
static void findbotbnd()
530
529
 {
531
 
 CHAR nm, nx, v1, lr;
 
530
 char nm, nx, v1, lr;
532
531
 
533
532
                   // find two BIG Maxima; point-candidate between them
534
533
 extrc=&exhead[0];
573
572
                                //    move it right untill thick enough
574
573
 
575
574
 v1=bodyes[rbnd];
576
 
 while ((WORD)rbnd < totalh)
 
575
 while ((uint16_t)rbnd < totalh)
577
576
  {
578
577
  if ((bodyes[rbnd]<<2)  < 3*v1) break;
579
578
  rbnd++;
580
579
  }
581
 
 if (rbnd > (totalh-3)) rbnd=(CHAR)totalh;
 
580
 if (rbnd > (totalh-3)) rbnd=(char)totalh;
582
581
 
583
582
 v1=bodyes[rwpnt];
584
583
 lr=MIN(rwpnt+4,totalh);
601
600
 return;
602
601
 }
603
602
 
604
 
static INT bot_serif(CHAR ret)
 
603
static int16_t bot_serif(char ret)
605
604
 {
606
 
 INT  nx, x, x1, x2 /*, ty, cy*/;
607
 
 CHAR *cf, maxf, minf;
608
 
 CHAR *ch, maxh, minh;
 
605
 int16_t  nx, x, x1, x2 /*, ty, cy*/;
 
606
 char *cf, maxf, minf;
 
607
 char *ch, maxh, minh;
609
608
 
610
609
                                   // are there two maxima around ?
611
610
 if ((nmax1 | nmax2) & 0x80) return 0;
636
635
                                   // serif-to-vertical-wall
637
636
 if (((foots[Rbnd-1]-foots[Rbnd]) > 3) ||
638
637
     ((foots[Lbnd]-foots[Lbnd-1]) > 3))
639
 
  { bestx=(CHAR)x; regmin(ret); return 1; }
 
638
  { bestx=(char)x; regmin(ret); return 1; }
640
639
 
641
640
                                   // serif-to-vertical-wall
642
641
 if (((heads[Rbnd]-heads[Rbnd-1]) > 3) &&
643
642
     ((foots[Rbnd-1]-foots[Rbnd]) < 2))
644
 
  { bestx=(CHAR)x; regmin(ret); return 1; }
 
643
  { bestx=(char)x; regmin(ret); return 1; }
645
644
 
646
645
                                   // test significant Max between
647
646
 if ((nmax2-nmax1) > 2) return 0;
673
672
 }
674
673
 
675
674
 
676
 
static INT walltest(INT flg, INT dn1, INT dn2, INT k1, INT k2)
 
675
static int16_t walltest(int16_t flg, int16_t dn1, int16_t dn2, int16_t k1, int16_t k2)
677
676
 {
678
 
 INT nx, w, wt, n1, n2, maxh, minf;
 
677
 int16_t nx, w, wt, n1, n2, maxh, minf;
679
678
 
680
679
 maxh=0; minf=256;
681
680
 wt= t_width * k1;
702
701
 return 0;
703
702
 }
704
703
 
705
 
static INT middle_puso(CHAR ret)
 
704
static int16_t middle_puso(char ret)
706
705
 {
707
 
 INT nm;
 
706
 int16_t nm;
708
707
 
709
708
 if (heads[bestx]+foots[bestx] < t_width)
710
709
  {
738
737
  }
739
738
 }
740
739
 
741
 
static INT lower_gap(CHAR ret)
 
740
static int16_t lower_gap(char ret)
742
741
 {
743
 
 CHAR  nm, x1, x2;
744
 
 INT line_num;
 
742
 char  nm, x1, x2;
 
743
 int16_t line_num;
745
744
 
746
745
 extrp = &exfoot[0];
747
746
 extrc = &exfoot[1];
785
784
 }
786
785
 
787
786
 
788
 
static void lower_pen(CHAR ret)
 
787
static void lower_pen(char ret)
789
788
 {
790
 
 CHAR  dx1, dx2, dy1, dy2, a1, a2, v;
 
789
 char  dx1, dx2, dy1, dy2, a1, a2, v;
791
790
 
792
791
 extrc=&exhead[2];
793
792
 extrp=&exhead[1];
827
826
 
828
827
static void findtopbnd()
829
828
 {
830
 
 CHAR nm, nx, v1;
 
829
 char nm, nx, v1;
831
830
 
832
831
                      // find two BIG Maxima; point-candidate between them
833
832
 extrc=&exfoot[0];
863
862
                           // rbnd - the same to the right of the pnt
864
863
                           //   move it right untill thick enough
865
864
 v1=bodyes[rbnd];
866
 
 while ((WORD)rbnd < totalh)
 
865
 while ((uint16_t)rbnd < totalh)
867
866
  {
868
867
  if ((bodyes[rbnd]<<2)  < 3*v1) break;
869
868
  rbnd++;
870
869
  }
871
 
 if (rbnd > (totalh-3)) rbnd=(CHAR)totalh;
 
870
 if (rbnd > (totalh-3)) rbnd=(char)totalh;
872
871
 
873
872
                      // define minima area as "about the same value of body"
874
873
 nx=bestx+1;
881
880
 }
882
881
 
883
882
 
884
 
static INT top_serif(CHAR ret)
 
883
static int16_t top_serif(char ret)
885
884
 {
886
 
 INT nx;
887
 
 INT x, x1, x2, v1, v2, v3, v4;
888
 
 CHAR cmin, cmax;
 
885
 int16_t nx;
 
886
 int16_t x, x1, x2, v1, v2, v3, v4;
 
887
 char cmin, cmax;
889
888
 
890
889
                                 // serif has not to be too thick
891
890
 if (best>4) return 0;           // ?????????? Etalon=4 IS RUBBISH !!!!!!
902
901
 for (nx=bestx; nx<totalh; nx++)
903
902
  {
904
903
  if ((bodyes[nx]-v1) > 1) break;
905
 
  Rbnd=(CHAR)nx;
 
904
  Rbnd=(char)nx;
906
905
  }
907
906
 
908
907
 for (nx=bestx; nx>=0; nx--)
909
908
  {
910
909
  v4=bodyes[nx]-v1;
911
 
  if(!v4) { Lbnd=(CHAR)nx; continue; }
 
910
  if(!v4) { Lbnd=(char)nx; continue; }
912
911
  if (v4 < 0) { v1=v4; continue; }
913
 
  if (v4 < 2) { Lbnd=(CHAR)nx; continue; }
 
912
  if (v4 < 2) { Lbnd=(char)nx; continue; }
914
913
  break;
915
914
  }
916
915
                                 // not beside MAxbody
940
939
 for (nx=bestx; nx<totalh; nx++)
941
940
  {
942
941
  if ( ((v2=bodyes[nx])-v1) > 1) break;
943
 
  cmax=(CHAR)nx;
 
942
  cmax=(char)nx;
944
943
  if (v2==0)
945
 
   rbnd=(CHAR)nx;
 
944
   rbnd=(char)nx;
946
945
  }
947
946
 for (nx=bestx; nx>=0; nx--)
948
947
  {
949
948
  if (((v2=bodyes[nx])-v1) > 1) break;
950
 
  cmin=(CHAR)nx;
 
949
  cmin=(char)nx;
951
950
  if (v2==0)
952
 
   lbnd=(CHAR)nx;
 
951
   lbnd=(char)nx;
953
952
  }
954
953
 
955
954
                                  // 1. isn't this a circle
962
961
  if (v2<v1) break;              // till end of rising bridge
963
962
  if ((v2-v3)>3) break;          // 'r' and other upper bridges not
964
963
                                 //    to rise too much
965
 
  cmax=(CHAR)nx;
 
964
  cmax=(char)nx;
966
965
  v1=v2;
967
966
 
968
967
  }
973
972
  if (nx < Lbnd) goto ok;
974
973
  v2=heads[nx];
975
974
  if (v2<v3) break;
976
 
  if (cmin > nx) cmin=(CHAR)nx;
 
975
  if (cmin > nx) cmin=(char)nx;
977
976
 
978
977
  }
979
978
ok:
988
987
 }
989
988
 
990
989
 
991
 
static INT upper_gap(CHAR ret)
 
990
static int16_t upper_gap(char ret)
992
991
 {
993
 
 CHAR nx, y;
994
 
 INT line_num;
 
992
 char nx, y;
 
993
 int16_t line_num;
995
994
 
996
995
                                       // not beside MAxbody
997
996
 if (!FlM) return 0;
1018
1017
 }
1019
1018
 
1020
1019
 
1021
 
static void define_cat(struct extrem_elem *fun, CHAR N)
 
1020
static void define_cat(struct extrem_elem *fun, char N)
1022
1021
 {
1023
 
 INT nm;
 
1022
 int16_t nm;
1024
1023
 
1025
1024
 extrp = &fun[0];
1026
1025
 extrc = &fun[1];
1043
1042
 {
1044
1043
 struct short_line_header *l_ptr;
1045
1044
 struct segment  *s_ptr;
1046
 
 INT n,x,y,z,bd,bn, cps,cpn, u,p;
1047
 
 CHAR *h1, *h2, *h3, *f1, *f2, *f3, *cb, *cp;
 
1045
 int16_t n,x,y,z,bd,bn, cps,cpn, u,p;
 
1046
 char *h1, *h2, *h3, *f1, *f2, *f3, *cb, *cp;
1048
1047
 
1049
1048
 totalh=0;
1050
1049
 for (n=0; n < t_height; n++)
1051
1050
 {
1052
 
   heads[n]=(CHAR)t_width;
1053
 
   bodyes[n]=(CHAR)t_width;
 
1051
   heads[n]=(char)t_width;
 
1052
   bodyes[n]=(char)t_width;
1054
1053
   foots[n]=0;
1055
1054
   linums[n]=0;
1056
1055
 }
1058
1057
  {
1059
1058
  p=path[n];
1060
1059
  l_ptr=&Ed_lines[p];
1061
 
  s_ptr = (struct segment *) ((BYTE *)t_line_ptr + l_ptr->segm_addr);
 
1060
  s_ptr = (struct segment *) ((uchar *)t_line_ptr + l_ptr->segm_addr);
1062
1061
  for (x=l_ptr->top; x < l_ptr->bot; x++,s_ptr++,totalh++)
1063
1062
   {
1064
1063
   heads[totalh]=s_ptr->end;
1097
1096
     if (y > z ) { bd=x-y+1; goto back; }
1098
1097
     bd=x-z; goto back;
1099
1098
  back:
1100
 
   if (n==0) { *cp=(CHAR)cps; *cb=(CHAR)bd; continue; }
 
1099
   if (n==0) { *cp=(char)cps; *cb=(char)bd; continue; }
1101
1100
   if ((u=*h3) > (x=*h1))
1102
1101
    {
1103
1102
     cpn=x; y=*f3;
1121
1120
     bn=x-z; goto compl;
1122
1121
  compl:
1123
1122
   if (bn <= bd)
1124
 
     { *cp=(CHAR)cpn; *cb=(CHAR)bn; }
 
1123
     { *cp=(char)cpn; *cb=(char)bn; }
1125
1124
   else
1126
 
     {*cp=(CHAR)cps; *cb=(CHAR)bd;}
 
1125
     {*cp=(char)cps; *cb=(char)bd;}
1127
1126
  } // loop end
1128
1127
 }
1129
1128
 
1130
1129
 
1131
 
static INT make_extrem( CHAR func[], struct extrem_elem extr[])
 
1130
static int16_t make_extrem( char func[], struct extrem_elem extr[])
1132
1131
 {
1133
 
 INT N,n;
1134
 
 CHAR prevx, prevf, prevd;
1135
 
 CHAR curf, curd;
 
1132
 int16_t N,n;
 
1133
 char prevx, prevf, prevd;
 
1134
 char curf, curd;
1136
1135
 struct extrem_elem *el;
1137
1136
 
1138
1137
 ExtreM=0; Extrem=127;
1171
1170
   }
1172
1171
jump:
1173
1172
  prevf = curf;
1174
 
  prevx = (CHAR)n;
 
1173
  prevx = (char)n;
1175
1174
  prevd = curd;
1176
1175
  }
1177
1176
 
1178
1177
 N++; el++;
1179
1178
 el->val=curf;
1180
1179
 el->type=0;  /*-prevd;*/              // no extrem on right bound
1181
 
 el->end = (CHAR)totalh;
 
1180
 el->end = (char)totalh;
1182
1181
 el->beg = prevx;
1183
1182
 N++;
1184
1183
 return(N);
1185
1184
 }
1186
1185
 
1187
 
static INT make_absextr( CHAR f, struct extrem_elem extr[])
 
1186
static int16_t make_absextr( char f, struct extrem_elem extr[])
1188
1187
 {
1189
 
 INT N,n;
1190
 
 CHAR prevx, prevf, prevd;
1191
 
 CHAR curf, curd;
 
1188
 int16_t N,n;
 
1189
 char prevx, prevf, prevd;
 
1190
 char curf, curd;
1192
1191
 struct extrem_elem *el;
1193
1192
 
1194
1193
 ExtreM=0; Extrem=127;
1233
1232
   }
1234
1233
  jump:
1235
1234
  prevf = curf;
1236
 
  prevx = (CHAR)n;
 
1235
  prevx = (char)n;
1237
1236
  prevd = curd;
1238
1237
  }
1239
1238
 
1240
1239
 N++; el++;
1241
1240
 el->val=curf;
1242
1241
 el->type=0 /*-prevd*/ ;                 // no extrem on right bound
1243
 
 el->end = (CHAR)t_height /*totalh*/;
 
1242
 el->end = (char)t_height /*totalh*/;
1244
1243
 el->beg = prevx;
1245
1244
 N++;
1246
1245
 return(N);
1248
1247
 
1249
1248
static void make_info()
1250
1249
 {
1251
 
 INT nx, nl;
 
1250
 int16_t nx, nl;
1252
1251
 struct short_line_header *l_ptr;
1253
1252
 struct segment  *s_ptr;
1254
1253
 struct info_elm *inf;
1263
1262
 for (nl=0; nl < max_line; nl++)
1264
1263
  {
1265
1264
  l_ptr=&Ed_lines[nl];
1266
 
  s_ptr = (struct segment *) ((BYTE *)t_line_ptr + l_ptr->segm_addr);
 
1265
  s_ptr = (struct segment *) ((uchar *)t_line_ptr + l_ptr->segm_addr);
1267
1266
 
1268
1267
  for (nx=l_ptr->top; nx < l_ptr->bot; nx++,s_ptr++)
1269
1268
   {
1274
1273
    {
1275
1274
    inf->topf=s_ptr->end-s_ptr->lth;
1276
1275
    inf->toph=s_ptr->end;
1277
 
    inf->topline=(CHAR)nl;
 
1276
    inf->topline=(char)nl;
1278
1277
    }
1279
1278
   if (s_ptr->end <= inf->botf)
1280
1279
    {
1281
1280
    inf->botf=s_ptr->end-s_ptr->lth;
1282
1281
    inf->both=s_ptr->end;
1283
 
    inf->botline=(CHAR)nl;
 
1282
    inf->botline=(char)nl;
1284
1283
    }
1285
1284
   }
1286
1285
  }
1287
1286
 }
1288
1287
 
1289
 
INT cut_points(INT width,INT height,BYTE *r,struct cut_elm *ans)
 
1288
int16_t cut_points(int16_t width,int16_t height,uchar *r,struct cut_elm *ans)
1290
1289
 {
1291
 
 CHAR n, a, i;
 
1290
 char n, a, i;
1292
1291
 struct cut_elm *a1;
1293
1292
 struct own_cut oct[STK_H], *oc1;
1294
1293
 Z=&string;
1300
1299
 s_raster=r;
1301
1300
 c_rastror(s_raster,t_raster(),s_width,s_height);
1302
1301
                              // turn s_raster for 90 degrees clockwise
1303
 
 t_comp_ptr=c_locomp(t_raster(),t_width_b,t_height,0,(INT)(-t_left_shift));
 
1302
 t_comp_ptr=c_locomp(t_raster(),t_width_b,t_height,0,(int16_t)(-t_left_shift));
1304
1303
                              // extraction components from t_raster
1305
1304
 if (t_comp_ptr == NULL)
1306
1305
   return -1;
1307
1306
 t_line_ptr=c_boxln(t_comp_ptr);
1308
1307
                              // box presentation of a component ->
1309
1308
                              //   line presentation of the component
1310
 
 if ((i=(CHAR)make_graph()) <= 0)   // make graph of shortened lines for
 
1309
 if ((i=(char)make_graph()) <= 0)   // make graph of shortened lines for
1311
1310
                              //   turned raster
1312
1311
  return i;
1313
1312
 if (i==1)
1351
1350
 return a;
1352
1351
 }
1353
1352
/////////////////////
1354
 
INT Alik_cut_points(INT width,INT height,BYTE *r,struct cut_elm *ans,INT row)
 
1353
int16_t Alik_cut_points(int16_t width,int16_t height,uchar *r,struct cut_elm *ans,int16_t row)
1355
1354
 {
1356
 
 CHAR n,a,i;
 
1355
 char n,a,i;
1357
1356
 struct cut_elm *a1;
1358
1357
 struct own_cut oct[STK_H+1];
1359
1358
 struct own_cut *oc1;
1369
1368
 
1370
1369
 s_raster=r;
1371
1370
 c_rastror(s_raster,t_raster(),s_width,s_height); // turn s_raster for 90 degrees clockwise
1372
 
 t_comp_ptr=c_locomp(t_raster(),t_width_b,t_height,0,(INT)(-t_left_shift)); // extraction components from t_raster
 
1371
 t_comp_ptr=c_locomp(t_raster(),t_width_b,t_height,0,(int16_t)(-t_left_shift)); // extraction components from t_raster
1373
1372
 if (t_comp_ptr == NULL)     return -1;
1374
1373
 t_line_ptr=c_boxln(t_comp_ptr);                  // box presentation of a component ->  line presentation of the component
1375
 
 if ((i=(CHAR)make_graph()) <= 0 && width<20)  return i;        // make graph of shortened lines for  turned raster
 
1374
 if ((i=(char)make_graph()) <= 0 && width<20)  return i;        // make graph of shortened lines for  turned raster
1376
1375
 
1377
 
 //Alik_define_cut_points((PCHAR)ForRaster1,&oct[1],width,height,row);
 
1376
 //Alik_define_cut_points((pchar)ForRaster1,&oct[1],width,height,row);
1378
1377
 RCUTP_SetBL_for_CutPoints(minrow,bbs1,bbs2,bbs3,bbs4,Nb1,Nb2,Nb3,language);
1379
 
 RCUTP_CutPoints((PCHAR)ForRaster1, &oct[1], width, height, row);
 
1378
 RCUTP_CutPoints((pchar)ForRaster1, &oct[1], width, height, row);
1380
1379
 
1381
1380
 for (a1=&ans[1],oc1=&oct[1],n=0, a=0; n<STK_H-1; n++)
1382
1381
  {
1392
1391
}
1393
1392
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1394
1393
// AK changed 26.03.98
1395
 
MN  *cut_rast(PBYTE r,INT width, INT height,INT upper, INT left,
1396
 
              struct cut_elm *cuts, CHAR p, CHAR flg, CHAR *svp, cut_pos *cpos)
 
1394
MN  *cut_rast(puchar r,int16_t width, int16_t height,int16_t upper, int16_t left,
 
1395
              struct cut_elm *cuts, char p, char flg, char *svp, cut_pos *cpos)
1397
1396
{
1398
 
        BYTE *c, *s;
1399
 
        BYTE b, bt, bs;
1400
 
        CHAR x, h, dh, fl;
1401
 
        INT totc, dx, y, r0, tr1, tr2, r1, r2, f1;
 
1397
        uchar *c, *s;
 
1398
        uchar b, bt, bs;
 
1399
        char x, h, dh, fl;
 
1400
        int16_t totc, dx, y, r0, tr1, tr2, r1, r2, f1;
1402
1401
        //  flg - request type :
1403
1402
        //  0 -  glue back
1404
1403
        //  1 -  make cut
1406
1405
        //  3 -  create components after all cuts made
1407
1406
 
1408
1407
        if (flg==3)
1409
 
                return(c_locomp(r,(INT)((width+7)>>3),height,upper,left));
 
1408
                return(c_locomp(r,(int16_t)((width+7)>>3),height,upper,left));
1410
1409
 
1411
1410
        if (flg)
1412
1411
                memset (svp,0,16);
1431
1430
 
1432
1431
                for (y=0;  y < dh; y++,c+=dx)
1433
1432
                {
1434
 
                        if ( s < svp || s > ( svp + 32 ) )    //AK! add crash debug
 
1433
                        if ( (char*)s < svp || (char*)s > ( svp + 32 ) )    //AK! add crash debug
1435
1434
                        {
1436
1435
                                continue;
1437
1436
                        }
1474
1473
        {
1475
1474
                for (y=0; y < dh; y++,r0++,c+=dx)
1476
1475
                {
1477
 
                        if ( s < svp || s > (svp + 32 ))              //AK! add
 
1476
                        if ( (char*)s < svp || (char*)s > (svp + 32 ))              //AK! add
1478
1477
                        {
1479
1478
                                continue;
1480
1479
                        }
1481
1480
 
1482
 
                        if ((BYTE)(*c & bt) != 0)   // interval starts or continues
 
1481
                        if ((uchar)(*c & bt) != 0)   // interval starts or continues
1483
1482
                        {
1484
1483
                                // Lepik:
1485
1484
                                if( !cuts_point_methode )
1486
1485
                                        if ((fl ==0) &&(!(f1 & 1)))      // beginning of vertical interval
1487
1486
                                        {
1488
 
                                                INT ret;
1489
 
                                                ret = SearchObjezd(x, c, width, y, dh, r0, height, (INT)(height -h));
 
1487
                                                int16_t ret;
 
1488
                                                ret = SearchObjezd(x, c, width, y, dh, r0, height, (int16_t)(height -h));
1490
1489
                                                if (ret)
1491
1490
                                                {
1492
1491
                                                        ret -=1;
1496
1495
                                                        while (ret-- >=0)
1497
1496
                                                        {
1498
1497
                                                                *s |= bs;
1499
 
                                                                bs = (BYTE)(bs>>1);
 
1498
                                                                bs = (uchar)(bs>>1);
1500
1499
                                                                if (bs==0)
1501
1500
                                                                {
1502
1501
                                                                        bs=0x80;
1534
1533
                                        f1 |=2;
1535
1534
                                };
1536
1535
        //
1537
 
                        bs = (BYTE)(bs>>1);
 
1536
                        bs = (uchar)(bs>>1);
1538
1537
 
1539
1538
                        if (bs==0)
1540
1539
                        {
1549
1548
        {
1550
1549
                for (y=0; y < dh; y++,c+=dx)
1551
1550
                {
1552
 
                        if ( s < svp || s > (svp + 32 ))              //AK! add
 
1551
                        if ( (char*)s < svp || (char*)s > (svp + 32 ))              //AK! add
1553
1552
                        {
1554
1553
                                continue;
1555
1554
                        }
1557
1556
                        if (*s & bs)
1558
1557
                                *c |= bt;
1559
1558
 
1560
 
                        bs = (BYTE)(bs>>1);
 
1559
                        bs = (uchar)(bs>>1);
1561
1560
 
1562
1561
                        if (bs==0)
1563
1562
                        {
1598
1597
        }
1599
1598
 
1600
1599
        if (flg==2)
1601
 
                return(c_locomp(r,(INT)((width+7)>>3),height,upper,left));
 
1600
                return(c_locomp(r,(int16_t)((width+7)>>3),height,upper,left));
1602
1601
 
1603
1602
        return NULL;
1604
1603
}
1605
1604
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
1606
1605
#define obLook  4
1607
1606
//                       0    1    2    3    4    5    6    7
1608
 
static BYTE bits[8] ={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
1609
 
static BYTE lstr[8] ={0x80,0xC0,0xE0,0xF0,0x78,0x3C,0x1E,0x0F};
1610
 
static BYTE rstr[8] ={0xF0,0x78,0x3C,0x1E,0x0F,0x07,0x03,0x01};
1611
 
static BYTE  aux[8] ={0x07,0x03,0x01,0x00,0x00,0x80,0xC0,0xE0};
1612
 
 
1613
 
 
1614
 
INT  SearchObjezd(INT     x,         // column number where cutting is going.
1615
 
                  PBYTE   c,         // pointer to curr byte in raster
1616
 
                  INT width,         // width of raster (pixs)
1617
 
                  INT     y,         // current row (in relative coords)
1618
 
                  INT    dh,         // no of rows to investigate(rel coords)
1619
 
                  INT    r0,         // first row (in rast coords)
1620
 
                  INT height,        // height of raster
1621
 
                  INT beg_y)         // first row for cut
 
1607
static uchar bits[8] ={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
 
1608
static uchar lstr[8] ={0x80,0xC0,0xE0,0xF0,0x78,0x3C,0x1E,0x0F};
 
1609
static uchar rstr[8] ={0xF0,0x78,0x3C,0x1E,0x0F,0x07,0x03,0x01};
 
1610
static uchar  aux[8] ={0x07,0x03,0x01,0x00,0x00,0x80,0xC0,0xE0};
 
1611
 
 
1612
 
 
1613
int16_t  SearchObjezd(int16_t     x,         // column number where cutting is going.
 
1614
                  puchar   c,         // pointer to curr byte in raster
 
1615
                  int16_t width,         // width of raster (pixs)
 
1616
                  int16_t     y,         // current row (in relative coords)
 
1617
                  int16_t    dh,         // no of rows to investigate(rel coords)
 
1618
                  int16_t    r0,         // first row (in rast coords)
 
1619
                  int16_t height,        // height of raster
 
1620
                  int16_t beg_y)         // first row for cut
1622
1621
 {
1623
 
  INT  i;
1624
 
  PBYTE cc;
1625
 
  INT dx;             //  width of raster in bytes.
1626
 
  INT  bitNo;         // Curr Bit No in byte
1627
 
  BYTE  CurB, aCurB,  Mask, aMask, Accu, aAccu;
1628
 
  INT strategy; // 0 - left and right strips in one byte,
 
1622
  int16_t  i;
 
1623
  puchar cc;
 
1624
  int16_t dx;             //  width of raster in bytes.
 
1625
  int16_t  bitNo;         // Curr Bit No in byte
 
1626
  uchar  CurB, aCurB,  Mask, aMask, Accu, aAccu;
 
1627
  int16_t strategy; // 0 - left and right strips in one byte,
1629
1628
                // 1 - right split by byte,
1630
1629
                // 2 - left   split by byte.
1631
1630
 
1637
1636
 
1638
1637
               // the following block searches the last row of interval.
1639
1638
  {
1640
 
    BYTE b;
 
1639
    uchar b;
1641
1640
    b=0x80>>bitNo;
1642
1641
    for (i =y+1, cc =c+dx; i <dh; i++, cc+=dx)
1643
1642
       if (! (*cc & b))  break;