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

« back to all changes in this revision

Viewing changes to cuneiform_src/Kern/rstr/src/compkit.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 "nt_types.h"
 
59
#include "struct.h"
 
60
#include "func.h"
 
61
 
 
62
BOOL boxes_account();
 
63
 
 
64
extern c_comp wcomp;
 
65
extern MN * main_number_ptr;
 
66
extern BOX * boxchain, *dl_last_in_chain;
 
67
extern BYTE lpool[];
 
68
extern WORD lpool_lth;
 
69
extern BYTE work_raster[];
 
70
//extern version * start_rec, * rec_ptr;
 
71
extern BYTE records_change;
 
72
 
 
73
static void boxes_to_line();
 
74
 
 
75
BOOL component_account()
 
76
{
 
77
 if (boxes_account())  { boxes_to_line(); wcomp.type = 0; return TRUE; }
 
78
 return FALSE;
 
79
}
 
80
 
 
81
BOOL boxes_account()
 
82
{
 
83
 MN *mn;
 
84
 BOX *bp;
 
85
 INT left, right, n;
 
86
 memset (&wcomp,0,sizeof(wcomp));
 
87
 mn = main_number_ptr; bp = mn->mnfirstbox;
 
88
 left = bp->boxleft; right = bp->boxright; boxchain = bp;
 
89
 while ((bp = (dl_last_in_chain = bp)->boxnext) != NULL)
 
90
  {
 
91
   if (bp->boxleft < left) left = bp->boxleft;
 
92
   if (bp->boxright > right) right = bp->boxright;
 
93
  }
 
94
 
 
95
 wcomp.upper = mn->mnupper; wcomp.left = left;
 
96
 wcomp.h = mn->mnlower - mn->mnupper;
 
97
 wcomp.rw = ((wcomp.w = right - left) + 7)/8;
 
98
 wcomp.nl = mn->mnlines; wcomp.begs = mn->mnbegs; wcomp.ends = mn->mnends;
 
99
 
 
100
 if (mn->mnflag & mnpicture) return FALSE;
 
101
 if ((wcomp.w > RASTER_MAX_WIDTH) || (wcomp.h > RASTER_MAX_HEIGHT))
 
102
                        return FALSE;
 
103
 if (mn->mnboxcnt > great_box_count) return FALSE;
 
104
 if (wcomp.nl < usual_box_count) return TRUE;
 
105
 
 
106
 for (bp = boxchain, n=0; bp; bp = bp->boxnext)
 
107
  {
 
108
   if ((bp->boxflag & BOXBEG) == 0) continue;
 
109
   if (bp->boxptr > sizeof(BOX) + sizeof(LNSTRT) + 2) {n++; continue;}
 
110
   if ((bp->boxflag & (BOXFREEBEG + BOXFREEEND - BOXBEG - BOXEND)) == 0) n++;
 
111
  }
 
112
 if (n >= usual_box_count) return FALSE; else return TRUE;
 
113
}
 
114
 
 
115
static void boxes_to_line()
 
116
{
 
117
 BOX *bp;
 
118
 lnhead *lnp;
 
119
 LNSTRT *lsp;
 
120
 interval * ip;
 
121
 BOXINT * bip;
 
122
 INT x, n;
 
123
 
 
124
 bp = boxchain; lnp = (lnhead *)lpool; goto enter_loop;
 
125
next_line:
 
126
 bp = bp->boxnext;
 
127
enter_loop:
 
128
 lsp = (LNSTRT *)(bp+1); lnp->row = lsp->y - wcomp.upper;
 
129
 lnp->flg = bp->boxflag; ip = (interval *) (lnp+1);
 
130
 ip->l = (BYTE)lsp->l; x = lsp->x - wcomp.left;
 
131
 (ip++)->e = (BYTE)x;
 
132
 bip = (BOXINT *)(lsp+1);
 
133
 n = (bp->boxptr - sizeof(BOX) - sizeof(LNSTRT))/sizeof(BOXINT);
 
134
cont_box:
 
135
 while (n--)
 
136
        {
 
137
        ip->l = (BYTE)bip->l;
 
138
        x += (bip++)->d;
 
139
        (ip++)->e = (BYTE)x ;
 
140
        }
 
141
 if ((bp->boxflag & BOXEND) == 0)
 
142
  {
 
143
   bp = bp->boxnext; bip = (BOXINT *)(bp+1);
 
144
   n = (bp->boxptr - sizeof(BOX))/ sizeof(BOXINT); goto cont_box;
 
145
  }
 
146
 (ip++)->l = 0;
 
147
 lnp->lth = (PBYTE)ip - (PBYTE)lnp;
 
148
 lnp->h = (lnp->lth - sizeof(*lnp) - sizeof(*ip))/sizeof(*ip);
 
149
 lnp->flg |= bp->boxflag; lnp = (lnhead *)ip;
 
150
 if (bp != dl_last_in_chain) goto next_line;
 
151
 lnp->lth = 0;
 
152
 lpool_lth = (PBYTE)lnp - lpool + sizeof (lnp->lth);
 
153
}
 
154
 
 
155
static BYTE make_fill[] = {0, 1, 3, 7, 15, 31, 63, 127, 255};
 
156
 
 
157
PBYTE make_raster()
 
158
{
 
159
 lnhead * lp;
 
160
 interval *ip;
 
161
 PBYTE p, pp;
 
162
 INT x, l, sh;
 
163
 WORD w;
 
164
 
 
165
 memset (work_raster,0,wcomp.rw*wcomp.h);
 
166
 lp = (lnhead *)lpool;
 
167
 while (lp->lth)
 
168
  {
 
169
   pp = work_raster + lp->row * wcomp.rw; ip = (interval *) (lp+1);
 
170
   while (x = ip->e, (l = (ip++)->l) != 0)
 
171
    {
 
172
     p = pp + (x>>3); sh = x & 7;
 
173
     while (l > 8) { w = 0xff00 >> sh; *p |= w & 0xff; *(--p) |= w>>8; l-=8; }
 
174
     w = make_fill[l]; w = w << (8-sh); *p |= w & 0xff; *(p-1) |= w >> 8;
 
175
     pp += wcomp.rw;
 
176
    }
 
177
   lp = (lnhead *)ip;
 
178
  }
 
179
 return work_raster;
 
180
}
 
181
 
 
182
 
 
183
PBYTE make_extended_raster(c_comp *cp)
 
184
{
 
185
 lnhead * lp;
 
186
 large_interval *ip;
 
187
 PBYTE p, pp;
 
188
 INT x, l, sh;
 
189
 WORD wd,w;
 
190
 
 
191
 memset (work_raster,0,cp->rw * cp->h); wd = cp->rw;
 
192
 lp = (lnhead *)((PBYTE)cp + cp->lines + sizeof(DWORD));
 
193
 while (lp->lth)
 
194
  {
 
195
   pp = work_raster + lp->row * wd; ip = (large_interval *) (lp+1);
 
196
   while (x = ip->e, (l = (ip++)->l) != 0)
 
197
    {
 
198
     p = pp + (x>>3); sh = x & 7;
 
199
     while (l > 8) { w = 0xff00 >> sh; *p |= w & 0xff; *(--p) |= w>>8; l-=8; }
 
200
     w = make_fill[l]; w = w << (8-sh); *p |= w & 0xff; *(p-1) |= w >> 8;
 
201
     pp += wd;
 
202
    }
 
203
   lp = (lnhead *)((PBYTE)ip - sizeof(WORD));
 
204
  }
 
205
 return work_raster;
 
206
}
 
207
 
 
208
lnhead *c_boxln(MN *mn)
 
209
{
 
210
 main_number_ptr = mn;
 
211
 boxes_account();
 
212
 boxes_to_line();
 
213
 return (lnhead *)lpool;
 
214
}
 
215
 
 
216
INT MN_to_line(MN * mn)
 
217
{
 
218
 main_number_ptr = mn;
 
219
 boxes_account();
 
220
 boxes_to_line();
 
221
 wcomp.type = 0;
 
222
 return 0;
 
223
}
 
224
 
 
225
WORD length_table[] = {0x100, 0x300, 0x700,0xf00,0x1f00,0x3f00,0x7f00,0xff00};
 
226
 
 
227
BYTE byte_seg_size[256] = {
 
228
// 0   1    2    3    4    5    6    7    8    9    a    b    c    d    e    f
 
229
0x00,0x18,0x17,0x28,0x16,0x00,0x27,0x38,0x15,0x00,0x00,0x00,0x26,0x00,0x37,0x48,        // 0
 
230
0x14,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x25,0x00,0x00,0x00,0x36,0x00,0x47,0x58,        // 1
 
231
0x13,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,        // 2
 
232
0x24,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x35,0x00,0x00,0x00,0x46,0x00,0x57,0x68,        // 3
 
233
0x12,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,        // 4
 
234
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,        // 5
 
235
0x23,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,        // 6
 
236
0x34,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x45,0x00,0x00,0x00,0x56,0x00,0x67,0x78,        // 7
 
237
0x11,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,        // 8
 
238
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,        // 9
 
239
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,        // a
 
240
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,        // b
 
241
0x22,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,        // c
 
242
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,        // d
 
243
0x33,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,        // e
 
244
0x44,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x55,0x00,0x00,0x00,0x66,0x00,0x77,0x88         // f
 
245
};
 
246