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.
57
/********** ��������� **********/
58
/* ����� : ��������� �������� */
59
/* �������� : 12.03.01 */
60
/* ���� : 'Util_Line_VP.CPP' */
61
/* ���������� : ����� ������ � ������� ������� LNS. */
62
/* ���������� : ������������ �����/������ (� ��������������� ������� � ���).*/
63
/*----------------------------------------------------------------------------*/
67
/*#include <windows.h>*/
68
/* interface our-other */
81
#include "markdatadefs.h"
84
#include "line_vp_util.h" //own functions
86
/*----------------------------------------------------------------------------*/
87
/* JussiP: this function is never called and the signature clashes with
88
* the next one with the same name.
91
Bool LoadLinesVP_rv (Handle hC, int Type, void *vB, char *pStr, Word16 *pCode)
94
Word32 KeyHor, KeyVer; //// � ����� ���� �� ���������!
98
switch ((UN_LOADDATA)Type)
101
/*** ����� ���������� � ������ ***/
102
ret = LoadLinesTotalInfo_rv (hC, vB, pStr); //f-t-e-d
106
Error_CPage_Code (pCode);
108
Error_MyNoMem_Code (pCode);
111
ret = GetSomeKeys_rv (vB, &KeyHor, &KeyVer, &CntHor, &CntVer, pStr); //t-e-d
114
Error_MyNoMem_Code (pCode);
118
CleanLastDataPart (vB);
121
/*** �������������� ����� ***/
124
ret = LoadLinesSpecInfo (hC, vB, KeyHor, CntHor);
125
pB->AimPart[pB->nPart-1] = UN_DA_Hori;
128
Error_CPage_Code (pCode);
132
/*** ������������ ����� ***/
135
ret = LoadLinesSpecInfo (hC, vB, KeyVer, CntVer);
136
pB->AimPart[pB->nPart-1] = UN_DA_Vert;
139
Error_CPage_Code (pCode);
149
/*---------------------------------------------------------------------------*/
150
Bool LoadLinesVP_rv (CLINE_handle hC, int Type, void *vB, char *pStr, Word16 *pCode)
155
switch ((UN_LOADDATA)Type)
157
case UN_LD_LinesVP2 :
159
ret = LoadLinesInfo_rv (hC, vB, pStr,TRUE); //f-t-e-d
160
pB->AimPart[pB->nPart-1] = UN_DA_Hori;
164
Error_CPage_Code (pCode);
166
Error_MyNoMem_Code (pCode);
170
ret = LoadLinesInfo_rv (hC, vB, pStr,FALSE); //f-t-e-d
171
pB->AimPart[pB->nPart-1] = UN_DA_Vert;
175
Error_CPage_Code (pCode);
177
Error_MyNoMem_Code (pCode);
185
/*---------------------------------------------------------------------------*/
186
void GetKeysPumaVP (void *vLti, Handle *pKeyHor, Handle *pKeyVer)
188
LinesTotalInfo *pLti;
189
pLti = (LinesTotalInfo *)vLti;
190
*pKeyHor = pLti->Hor.Lns;
191
*pKeyVer = pLti->Ver.Lns;
193
/*---------------------------------------------------------------------------*/
194
Bool GetSomeKeys_rv (void *vB, Handle *pKeyHor, Handle *pKeyVer
195
, int *pCntHor, int *pCntVer, char *pStr)
198
LinesTotalInfo *pLti;
201
pLti = (LinesTotalInfo *)(pB->vPart[pB->nPart-1]);
202
SizeNeed = (pLti->Hor.Cnt + pLti->Ver.Cnt) * sizeof (LinesTotalInfo);
203
if (SizeNeed > pB->SizeCurr)
205
sprintf (pStr, "�� ������� ������ ��� %d �����!", pLti->Hor.Cnt + pLti->Ver.Cnt);
210
sprintf (pStr, "����� ����������, �� �� ����� �� ��������.");
213
*pKeyHor = pLti->Hor.Lns;
214
*pKeyVer = pLti->Ver.Lns;
215
*pCntHor = pLti->Hor.Cnt;
216
*pCntVer = pLti->Ver.Cnt;
219
/*---------------------------------------------------------------------------*/
220
Bool LoadLinesTotalInfo_rv (Handle hC, void *vB, char *pStr)
222
Word32 err32, nTeor, nReal;
227
hBlockLine = CPAGE_GetBlockFirst (hC, RLINE_BLOCK_TYPE);
230
sprintf (pStr, "����� �� ����������.");
233
err32 = CPAGE_GetReturnCode ();
237
AM_Console ("RLTABLE : ������ ����� ���������� - [CPAGE]%s", "[GetBlockFirst]");
241
/* ���������� ������ */
242
nTeor = sizeof (LinesTotalInfo);
243
if ((int)nTeor>pB->SizeCurr)
245
sprintf (pStr, "�� ������� ������ ��� 1, ����-�����!");
248
nReal = CPAGE_GetBlockData (hC, hBlockLine, RLINE_BLOCK_TYPE, pB->vCurr, nTeor);
249
err32 = CPAGE_GetReturnCode ();
250
if ((nReal!=nTeor)||(err32!=0))
253
AM_Console ("RLTABLE : ������ ����� ���������� - [CPAGE]%s", "[GetBlockData]");
257
EndLastDataPart (vB, UN_DA_Unknown, UN_DT_LinesTotalInfo, nTeor, 1);
260
/*---------------------------------------------------------------------------*/
261
Bool LoadLinesInfo_rv (CLINE_handle hC, void *vB, char *pStr,Bool Hori)
268
vCurr = (char *)pB->vCurr;
269
nTeor = sizeof (DLine);
270
Cnt=CLINE_GetLineCount(hC);
271
if(Cnt*((int)nTeor)>pB->SizeCurr)
273
sprintf (pStr, "�� ������� ������ ��� 1, ����-�����!");
277
for(CLINE_handle hline=CLINE_GetFirstLine(hC);hline;hline=CLINE_GetNextLine(hline))
279
CPDLine cpdata=CLINE_GetLineData(hline);
280
err32 = CLINE_GetReturnCode ();
284
AM_Console ("RLTABLE : ������ ����� ���������� - [CLINE]%s", "[GetLineData]");
288
if(Hori&&cpdata->Dir==LD_Horiz||(!Hori&&cpdata->Dir!=LD_Horiz))
290
CLINE_CopyData(vCurr,cpdata,nTeor);
295
EndLastDataPart (vB,UN_DA_Unknown,UN_DT_ClineLine,nTeor,Cnt);
298
/*---------------------------------------------------------------------------*/
299
Bool LoadLinesSpecInfo (Handle hC, void *vB, Handle Key, int Cnt)
302
Word32 err32, nTeor, nReal;
303
Handle hBlockLineSpec;
304
Handle hBlockLinePrev;
308
vCurr = (char *)pB->vCurr;
309
nTeor = sizeof (LineInfo);
310
for (i=0; i<Cnt; i++)
314
hBlockLineSpec = CPAGE_GetBlockFirst (hC, Key);
316
hBlockLineSpec = CPAGE_GetBlockNext (hC, hBlockLinePrev, Key);
317
err32 = CPAGE_GetReturnCode ();
318
if ((err32!=0)||(hBlockLineSpec==NULL))
322
AM_Console ("RLTABLE : ������ ����� ���������� - [CPAGE]%s", "[GetBlockFirst]");
324
AM_Console ("RLTABLE : ������ ����� ���������� - [CPAGE]%s", "[GetBlockNext]");
328
/* ���������� ������ */
329
nReal = CPAGE_GetBlockData (hC, hBlockLineSpec, Key, (void *)vCurr, nTeor);
330
err32 = CPAGE_GetReturnCode ();
331
if ((nReal!=nTeor)||(err32!=0))
334
AM_Console ("RLTABLE : ������ ����� ���������� - [CPAGE]%s", "[GetBlockData]");
338
hBlockLinePrev = hBlockLineSpec;
341
EndLastDataPart (vB, UN_DA_Unknown, UN_DT_LineInfo, nTeor, Cnt);
344
/*---------------------------------------------------------------------------*/
345
Bool MyReSetLines (void *vLti, int MaxNumLin, Handle hCPage, Handle HoriType
346
, Handle VertType, char *pStr)
349
Word32 err32, nTeor;//, nReal;
350
Bool32 nReal;//differ
352
Handle hBlockLineHor;
353
Handle hBlockLineVer;
354
Handle hBlockLinePrev;
356
LinesTotalInfo *pLti;
357
pLti = (LinesTotalInfo *)vLti;
358
/*** ����� ���������� � ������ ***/
361
pLti->Hor.Lns = (LineInfo *)HoriType;
362
pLti->Ver.Lns = (LineInfo *)VertType;
363
hBlockLine = CPAGE_GetBlockFirst (hCPage, RLINE_BLOCK_TYPE);
364
err32 = CPAGE_GetReturnCode ();
367
sprintf (pStr, "RLTABLE : ������ ����� ���������� - [CPAGE][GetBlockFirst]");
370
nTeor = sizeof (LinesTotalInfo);
371
nReal = CPAGE_SetBlockData (hCPage, hBlockLine, RLINE_BLOCK_TYPE, (void *)pLti, nTeor);
372
err32 = CPAGE_GetReturnCode ();
373
// if ((nReal!=nTeor)||(err32!=0))
374
if (!nReal||(err32!=0))
376
sprintf (pStr, "RLTABLE : ������ ����� ���������� - [CPAGE][SetBlockData]");
379
pLti->Hor.Lns = (LineInfo *)Hor;
380
pLti->Ver.Lns = (LineInfo *)Ver;
381
/*** �������������� ����� ***/
382
for (i=0; i<pLti->Hor.Cnt; i++)
385
hBlockLineHor = CPAGE_GetBlockFirst (hCPage, HoriType);
387
hBlockLineHor = CPAGE_GetBlockNext (hCPage, hBlockLinePrev, HoriType);
388
err32 = CPAGE_GetReturnCode ();
392
sprintf (pStr, "RLTABLE : ������ ����� ���������� - [CPAGE][GetBlockFirst]");
394
sprintf (pStr, "RLTABLE : ������ ����� ���������� - [CPAGE][GetBlockNext]");
397
nTeor = sizeof (LineInfo);
398
nReal = CPAGE_SetBlockData (hCPage, hBlockLineHor, HoriType, (void *)&(pLti->Hor.Lns[i]), nTeor);
399
err32 = CPAGE_GetReturnCode ();
400
// if ((nReal!=nTeor)||(err32!=0))
401
if (!nReal||(err32!=0))
403
sprintf (pStr, "RLTABLE : ������ ����� ���������� - [CPAGE][SetBlockData]");
406
hBlockLinePrev = hBlockLineHor;
408
/*** ������������ ����� ***/
409
for (i=0; i<pLti->Ver.Cnt; i++)
412
hBlockLineVer = CPAGE_GetBlockFirst (hCPage, VertType);
414
hBlockLineVer = CPAGE_GetBlockNext (hCPage, hBlockLinePrev, VertType);
415
err32 = CPAGE_GetReturnCode ();
419
sprintf (pStr, "RLTABLE : ������ ����� ���������� - [CPAGE][GetBlockFirst]");
421
sprintf (pStr, "RLTABLE : ������ ����� ���������� - [CPAGE][GetBlockNext]");
424
nTeor = sizeof (LineInfo);
425
nReal = CPAGE_SetBlockData (hCPage, hBlockLineVer, VertType, (void *)&(pLti->Ver.Lns[i]), nTeor);
426
err32 = CPAGE_GetReturnCode ();
427
// if ((nReal!=nTeor)||(err32!=0))
428
if (!nReal||(err32!=0))
430
sprintf (pStr, "RLTABLE : ������ ����� ���������� - [CPAGE][SetBlockData]");
433
hBlockLinePrev = hBlockLineVer;
437
/*----------------------------------------------------------------------------*/
438
Bool MyReSetLines(void* vLines,int count,CLINE_handle hCLINE,char *pStr)
442
DLine* pbeg=(DLine*)vLines;
443
DLine* pend=&(pbeg[count]);
450
for(CLINE_handle hline=CLINE_GetFirstLine(hCLINE);hline&&count;hline=CLINE_GetNextLine(hline))
452
cpdata=CLINE_GetLineData(hline);
455
sprintf (pStr, "RLTABLE : ������ ����� ���������� - [CLINE][SetLineData]");
458
Beg_X=cpdata->Line.Beg_X;
459
End_X=cpdata->Line.End_X;
460
Beg_Y=cpdata->Line.Beg_Y;
461
End_Y=cpdata->Line.End_Y;
462
for(p=pbeg;p<pend;p++)
464
if(p->Line.Beg_X==Beg_X&&p->Line.Beg_Y==Beg_Y&&p->Line.End_X==End_X&&p->Line.End_Y==End_Y)
466
if(!CLINE_SetLineData(hline,p))
468
sprintf (pStr, "RLTABLE : ������ ����� ���������� - [CLINE][SetLineData]");
477
/*----------------------------------------------------------------------------*/
478
Bool ReferForLinesVP (void *vLti, void *vB)
483
LinesTotalInfo *pLti;
484
pLti = (LinesTotalInfo *)vLti;
487
Ind = FindSuchAimedData (vB, UN_DT_LineInfo, UN_DA_Hori);
491
pLti->Hor.Lns = (LineInfo *)pB->vPart[Ind];
493
Ind = FindSuchAimedData (vB, UN_DT_LineInfo, UN_DA_Vert);
497
pLti->Ver.Lns = (LineInfo *)pB->vPart[Ind];
503
/*----------------------------------------------------------------------------*/
504
Bool PrepareLinesVP_rv (void *vB, void **vvData)
511
Ind = FindSuchData (vB, UN_DT_LinesTotalInfo);
514
*vvData = pB->vPart[Ind];
515
ret = ReferForLinesVP (*vvData, vB);
518
/*----------------------------------------------------------------------------*/
519
Bool ReferForAndCountLinesVP (void *vB, void **vvData,int* pcount,Bool Hori)
526
Ind = FindSuchAimedData(vB, UN_DT_ClineLine,UN_DA_Hori);
528
Ind=FindSuchAimedData(vB, UN_DT_ClineLine,UN_DA_Vert);
531
*vvData = pB->vPart[Ind];
532
*pcount = pB->nPartUnits[Ind];
535
/*----------------------------------------------------------------------------*/
536
Bool IsWarnAtLine (void *vLns, Bool Hori)
538
LineInfo *pLns = (LineInfo *)vLns;
541
if (abs(pLns->A.y - pLns->B.y) > abs(pLns->A.x - pLns->B.x))
544
if (!AM_Skip (FT_GetKeyOfRule (RU_FT_C_ContErr)))
545
AM_Console ("Rlt-Error-Ignore : ���������� ����� �� �������� ��������������! ��� ������������.");
549
if (pLns->A.x > pLns->B.x)
552
if (!AM_Skip (FT_GetKeyOfRule (RU_FT_C_ContWarn)))
553
AM_Console ("Rlt-Warning-Continue : ����� ������� �������������� �����!");
560
if (abs(pLns->A.y - pLns->B.y) < abs(pLns->A.x - pLns->B.x))
563
if (!AM_Skip (FT_GetKeyOfRule (RU_FT_C_ContErr)))
564
AM_Console ("Rlt-Error-Ignore : ���������� ����� �� �������� ������������! ��� ������������.");
568
if (pLns->A.y > pLns->B.y)
571
if (!AM_Skip (FT_GetKeyOfRule (RU_FT_C_ContWarn)))
572
AM_Console ("Rlt-Warning-Continue : ����� ������� ������������ �����!");
579
/*----------------------------------------------------------------------------*/
580
Bool IsWarnAtLine (void *vLine,Bool Hori,Bool zero)
582
NR_SimpLine* pLine = (NR_SimpLine*)vLine;
585
if (abs(pLine->Beg_Y-pLine->End_Y)>abs(pLine->Beg_X-pLine->End_X))
588
if (!AM_Skip (FT_GetKeyOfRule (RU_FT_C_ContErr)))
589
AM_Console ("Rlt-Error-Ignore : ���������� ����� �� �������� ��������������! ��� ������������.");
593
if (pLine->Beg_X>pLine->End_X)
596
if (!AM_Skip (FT_GetKeyOfRule (RU_FT_C_ContWarn)))
597
AM_Console ("Rlt-Warning-Continue : ����� ������� �������������� �����!");
604
if (abs(pLine->Beg_Y-pLine->End_Y)<abs(pLine->Beg_X-pLine->End_X))
607
if (!AM_Skip (FT_GetKeyOfRule (RU_FT_C_ContErr)))
608
AM_Console ("Rlt-Error-Ignore : ���������� ����� �� �������� ������������! ��� ������������.");
612
if (pLine->Beg_Y>pLine->End_Y)
615
if (!AM_Skip (FT_GetKeyOfRule (RU_FT_C_ContWarn)))
616
AM_Console ("Rlt-Warning-Continue : ����� ������� ������������ �����!");
623
/*----------------------------------------------------------------------------*/
624
void MarkTableLines (void *vLti, int *pForw, int MyMaxL)
628
LinesTotalInfo *pLti;
629
Word32 AntiFalse, AntiTrue, AntiIsAtTable, AntiIsNotAtTable;
630
AntiFalse = 0xFFFFFFFF;
631
AntiFalse ^= LI_IsFalse;
632
AntiTrue = 0xFFFFFFFF;
633
AntiTrue ^= LI_IsTrue;
634
AntiIsAtTable = 0xFFFFFFFF;
635
AntiIsAtTable ^= LI_IsAtTable;
636
AntiIsNotAtTable = 0xFFFFFFFF;
637
AntiIsNotAtTable ^= LI_IsNotAtTable;
638
pLti = (LinesTotalInfo *)vLti;
640
pLns = pLti->Hor.Lns;
643
if (LineBringToTable (i, pForw, MyMaxL))
645
pLns->Flags |= LI_IsAtTable;
646
pLns->Flags &= AntiIsNotAtTable;
650
if (!(pLns->Flags & LI_IsAtTable))
651
pLns->Flags |= LI_IsNotAtTable;
656
pLns = pLti->Ver.Lns;
659
if (LineBringToTable (i + MyMaxL, pForw, MyMaxL))
661
pLns->Flags |= LI_IsAtTable;
662
pLns->Flags &= AntiIsNotAtTable;
663
Lent = (pLns->A.x - pLns->B.x) * (pLns->A.x - pLns->B.x);
664
Lent += (pLns->A.y - pLns->B.y) * (pLns->A.y - pLns->B.y);
665
Lent = (int) sqrt ((double)Lent);
666
/* �������� ��������� ������������ - ���������! */
669
pLns->Flags &= AntiFalse;
670
pLns->Flags |= LI_IsTrue;
675
if (!(pLns->Flags & LI_IsAtTable))
676
pLns->Flags |= LI_IsNotAtTable;
681
/*----------------------------------------------------------------------------*/
682
void MarkTableLines (void *vHorLines,int hor_count,void *vVerLines,int ver_count, int *pForw, int MyMaxL)
687
int line_size=sizeof(DLine);
688
Word32 AntiFalse, AntiTrue, AntiIsAtTable, AntiIsNotAtTable;
689
AntiFalse = 0xFFFFFFFF;
690
AntiFalse ^= LI_IsFalse;
691
AntiTrue = 0xFFFFFFFF;
692
AntiTrue ^= LI_IsTrue;
693
AntiIsAtTable = 0xFFFFFFFF;
694
AntiIsAtTable ^= LI_IsAtTable;
695
AntiIsNotAtTable = 0xFFFFFFFF;
696
AntiIsNotAtTable ^= LI_IsNotAtTable;
698
pline=(DLine*)vHorLines;
699
for(i=0;i<hor_count;i++,pline++)
701
if (LineBringToTable (i, pForw, MyMaxL))
703
pline->Flags |= LI_IsAtTable;
704
pline->Flags &= AntiIsNotAtTable;
708
if (!(pline->Flags & LI_IsAtTable))
709
pline->Flags |= LI_IsNotAtTable;
714
pline=(DLine*)vVerLines;
716
for(i=MyMaxL;i<ver_count;i++,pline++)
718
if (LineBringToTable (i, pForw, MyMaxL))
720
pline->Flags |= LI_IsAtTable;
721
pline->Flags &= AntiIsNotAtTable;
722
Lent = (pline->Line.Beg_X - pline->Line.End_X) * (pline->Line.Beg_X - pline->Line.End_X);
723
Lent += (pline->Line.Beg_Y - pline->Line.End_Y) * (pline->Line.Beg_Y - pline->Line.End_Y);
724
Lent = (int) sqrt ((double)Lent);
725
/* �������� ��������� ������������ - ���������! */
728
pline->Flags &= AntiFalse;
729
pline->Flags |= LI_IsTrue;
734
if (!(pline->Flags & LI_IsAtTable))
735
pline->Flags |= LI_IsNotAtTable;
739
/*----------------------------------------------------------------------------*/
740
Bool LineBringToTable (int i, int *pForw, int MyMaxL)
748
l = pForw[2*(k+1)*MyMaxL + l];
752
/*---------------------------------------------------------------------------*/