2
Copyright (c) 1993-2008, Cognitive Technologies
5
����������� ��������� ��������������� � ������������� ��� � ���� ��������� ����,
6
��� � � �������� �����, � ����������� ��� ���, ��� ���������� ��������� �������:
8
* ��� ��������� ��������������� ��������� ���� ������ ���������� ���������
9
���� ����������� �� ��������� �����, ���� ������ ������� � �����������
11
* ��� ��������� ��������������� ��������� ���� � ������������ �/��� �
12
������ ����������, ������������ ��� ���������������, ������ �����������
13
��������� ���� ���������� �� ��������� �����, ���� ������ ������� �
14
����������� ����� �� ��������.
15
* �� �������� Cognitive Technologies, �� ����� �� ����������� �� �����
16
���� ������������ � �������� �������� ��������� �/��� �����������
17
���������, ���������� �� ���� ��, ��� ���������������� �����������
20
��� ��������� ������������� ����������� ��������� ���� �/��� ������� ������ "���
21
��� ����" ��� ������-���� ���� ��������, ���������� ���� ��� ���������������,
22
������� �������� ������������ �������� � ����������� ��� ���������� ����, �� ��
23
������������� ���. �� �������� ��������� ���� � �� ���� ������ ����, �������
24
����� �������� �/��� �������� �������������� ���������, �� � ���� ������ ��
25
��Ѩ� ���������������, ������� ����� �����, ���������, ����������� ���
26
������������� ������, ��������� � �������������� ��� ���������� ����������
27
������������� ������������� ��������� (������� ������ ������, ��� ������,
28
������� ���������, ��� ������ �/��� ������ �������, ���������� ��-�� ��������
29
������� ��� �/��� ������ ��������� �������� ��������� � ������� �����������,
30
�� �� ������������� ����� ��������), �� �� ������������� ���, ���� ���� �����
31
�������� ��� ������ ���� ���� �������� � ����������� ����� ������� � ������.
33
Redistribution and use in source and binary forms, with or without modification,
34
are permitted provided that the following conditions are met:
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.
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.
60
#include "polyblock.h"
63
void CleanData(Handle Type,void * lpData,Word32 Size)
64
// �������������� ����� �������� ��������� ������ ��� ������ ��������
66
if(Type == TYPE_TEXT || Type == TYPE_IMAGE)
68
POLY_ *poly = (POLY_ *)lpData;
69
COMMON *com = &poly->com;
71
memset(&com->Vertex[com->count],0,(char*)&com->Vertex[maxnum]-(char*)&com->Vertex[com->count]);
72
memset(&poly->mark[com->count],0,(char*)&poly->mark[maxnum]-(char*)&poly->mark[com->count]);
75
if(Type == TYPE_TABLE)
77
TABLE_ *table = (TABLE_ *)lpData;
78
COMMON *com = &table->com;
79
memset(&com->Vertex[com->count],0,(char*)&com->Vertex[MaxNum]-(char*)&com->Vertex[com->count]);
80
Int32 *line=table->LineY;
81
memset(&line[table->num_rows+1],0,(char*)&line[MaxHorLines-1]-(char*)&line[table->num_rows+1]);
83
memset(&line[table->num_colons+1],0,(char*)&line[MaxVerLines-1]-(char*)&line[table->num_colons+1]);
84
for (Int32 j=0; j<MaxVerLines; j++)
85
for (Int32 i=0; i<MaxHorLines; i++)
86
if (i>=table->num_rows || j>=table->num_colons)
87
table->Visible[i][j][0]=table->Visible[i][j][1]=table->TypeCell[i][j]=0;
91
Bool32 ComplianceVersions(Handle Type, char ** lpData, Word32 *Size)
92
//���������� ������ ����� ������ � �������� ���������;
93
// ���� ��������� ������ - ����������� ������, ���� ������ - ������
96
if (Type==TYPE_TEXT || Type==TYPE_IMAGE)
97
NewSize = sizeof(POLY_);
100
NewSize = sizeof(TABLE_);
105
char *lpNewData = new char[NewSize];
108
memcpy(lpNewData,*lpData,*Size);
109
memset(lpNewData+(*Size),0,NewSize-(*Size));
111
*lpData=lpNewData; *Size=NewSize;
116
Bool32 Compress(char * lpData, Word32 Size, char ** compressedData, Word32 * compressedSize)
118
// �������� ������ �� �� ����� MIN_REPEAT ���������� �������� �� ������� ����������
119
#define MIN_REPEAT 2*sizeof(CompressHeader)
124
char *newData = new char[Size+sizeof(CompressHeader)]; //������ ������ �����, ���� ��������� �� ����������,
125
if (!newData) //����� - �� ������ ���������
127
char *lpNewData = newData;
129
// ������� ���� - ������� �������� � ��������, ����������� ����������� ���������;
130
// ����� ��� ����������
131
char * ordinary=lpData, //������� ��������
136
char * current=ordinary+1,
137
* repeating=ordinary; //��������, ����������� ����������� ���������;
140
if (*current != *repeating)
142
if (current-repeating>=MIN_REPEAT) break;
147
count=current-repeating;
149
if (count<MIN_REPEAT) //����� �� �����, � ���������� ���� - ���������
151
repeating += count; count=0;
153
if (repeating>ordinary) //������� ��������
155
CompressHeader head={0};
156
head.bCompressed=FALSE;
157
head.wCount=repeating-ordinary;
158
memcpy(lpNewData,&head,sizeof(head)); lpNewData += sizeof(head);
159
memcpy(lpNewData,ordinary,head.wCount); lpNewData += head.wCount;
161
if (count) //��������, ����������� �������� (*repeated)
163
CompressHeader head={0};
164
head.bCompressed=TRUE;
165
head.cRepeater=*repeating;
167
memcpy(lpNewData,&head,sizeof(head)); lpNewData += sizeof(head);
172
*compressedData = newData; *compressedSize = lpNewData-newData;
176
//#################################
177
Bool32 Decompress(char * lpData, Word32 Size, char ** decomData, Word32 * decomSize)
182
char * old=lpData, *end=lpData+Size;
184
//���������� ������ ����� ������������
188
CompressHeader *head = (CompressHeader *)old;
189
old += sizeof(CompressHeader);
190
if (!head->bCompressed) old += head->wCount;
191
newSize += head->wCount;
195
char *newData = new char[newSize], *modern=newData;
202
CompressHeader *head = (CompressHeader *)old;
203
old += sizeof(CompressHeader);
204
if (head->bCompressed)
205
memset(modern,head->cRepeater,head->wCount);
208
memcpy(modern,old,head->wCount);
211
modern += head->wCount;
213
*decomData=newData; *decomSize=newSize;