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.
68
// �������� ���������� ��������� � ������� ���������
72
CED_DeletePage(ghEdPage);
77
GetPageInfo(hCPAGE,&PInfo);
80
CPAGE_DeleteAll(); hCPAGE = CreateEmptyPage();
82
strcpy((char*)PInfo.szImageName, PUMA_IMAGE_USER);
83
PInfo.Incline2048 = 0;
85
PInfo.Images=IMAGE_USER;
86
SetPageInfo(hCPAGE,PInfo);
88
CCOM_DeleteAll(); hCCOM = NULL;
89
CIMAGE_DeleteImage((PWord8)PUMA_IMAGE_BINARIZE );
90
CIMAGE_DeleteImage((PWord8)PUMA_IMAGE_DELLINE );
91
// ���������� ����������� ( PUMA_IMAGE_ROTATE) ������� ������, ��� � ��������,
92
// ��������� ��� ������������ � ����������. ��� ����� �������
93
// ���� ��� ��������� ������ ����������� �����������, ���� ���
95
CIMAGE_DeleteImage((PWord8)PUMA_IMAGE_TURN );
97
if(hCPAGE && CPAGE_GetCountBlock(hCPAGE))
100
Handle hBlock = CPAGE_GetBlockFirst(hCPAGE,0);
103
CPAGE_DeleteBlock(hCPAGE,hBlock);
104
hBlock = CPAGE_GetBlockNext(hCPAGE,hBlock,0);
109
///////////////////////////////////////////////////////
110
// ������� �������� ����������
111
Bool32 rexcProgressStep (Word32 step)
113
return ProgressStep(2,NULL,step);
115
///////////////////////////////////////////////////////
116
Bool32 ExtractComponents( Bool32 bIsRotate, Handle * prev_ccom, PWord8 name)
119
ExcControl exc = {0};
123
*prev_ccom = hCCOM ? hCCOM: NULL;
128
CCOM_DeleteContainer((CCOM_handle)hCCOM);
132
if(!REXC_SetImportData(REXC_ProgressStep, (void*)rexcProgressStep))
134
SetReturnCode_puma(REXC_GetReturnCode());
138
// ����� ������������� ��������
139
exc.Control = Ex_ExtraComp|/*Ex_EvnRecog|*/Ex_Picture;
140
//exc.Control |= Ex_NetRecog;
142
//Andrey: orientation is obtained from new library RNORM
143
//exc.Control |= ( bIsRotate ? Ex_Orient : 0 );
145
exc.Control |= Ex_PictureLarge;
147
if(rc && !REXC_SetEVNProperties(exc, GetModulePath(),(Word8)gnLanguage) )
148
{ // ���������������� ������������� �� ������� � ������ �������
149
SetReturnCode_puma(REXC_GetReturnCode());
155
Word8 w8 = (Word8)gbDotMatrix;
156
REXC_SetImportData(REXC_Word8_Matrix,&w8);
158
w8 = (Word8)gbFax100;
159
REXC_SetImportData(REXC_Word8_Fax1x2,&w8);
162
if(rc && !REXCExtraDIB( exc, lpdata,0,0,0,0) ) // ����� ��������� � DIB-e
164
CIMAGEIMAGECALLBACK clbk;
165
if(rc && !CIMAGE_GetCallbackImage(name, &clbk))
167
SetReturnCode_puma(CIMAGE_GetReturnCode());
170
if( rc && !REXCExtracomp3CB(exc, // ����� ��������� by 3CallBacks
171
(TImageOpen)clbk.CIMAGE_ImageOpen,
172
(TImageClose)clbk.CIMAGE_ImageClose,
173
(TImageRead)clbk.CIMAGE_ImageRead)
176
SetReturnCode_puma(REXC_GetReturnCode());
182
hCCOM = (Handle)REXCGetContainer();
185
SetReturnCode_puma(REXC_GetReturnCode());
192
hCCOM = (Handle)REXCGetContainer();
195
SetReturnCode_puma(REXC_GetReturnCode());
200
SetUpdate(FLG_UPDATE_NO,FLG_UPDATE_CCOM);
203
/////////////////////////////////////////////////////////////////////////////////////////////////////
204
// ����� ���������� � RSource.dll
205
Bool32 comp_over(CCOM_comp *sour,CCOM_comp *cur)
207
Int32 le,ri,up,dn,w,h;
209
if( sour->left+sour->w<=cur->left || cur->left+cur->w<=sour->left )
211
if( sour->upper+sour->h<=cur->upper || cur->upper+cur->h<=sour->upper )
214
if( sour->left<cur->left )
219
if( sour->left+sour->w<cur->left+cur->w )
220
ri = sour->left+sour->w;
222
ri = cur->left+cur->w;
224
if( sour->upper<cur->upper )
229
if( sour->upper+sour->h<cur->upper+cur->h )
230
dn = cur->upper+cur->h;
232
dn = sour->upper+sour->h;
235
if( w>0 && h>0 && cur->w<2*sour->w && cur->h<2*sour->h &&
236
w*2>cur->w && h*2>cur->h )
240
/////////////////////////////////////////////////////////////////////////////////////////////////////
241
// ����� ���������� � RSource.dll
242
Bool32 remove_overlayed(CCOM_comp *sour,CCOM_handle haCCOM)
244
CCOM_comp *cur=CCOM_GetFirst(haCCOM,NULL), *curn;
248
curn=CCOM_GetNext(cur,NULL);
249
if( cur->upper<sour->upper && sour->upper-cur->upper>10*sour->h)
254
if( comp_over(sour,cur) )
256
CCOM_Delete(haCCOM,cur);
259
if( cur->upper-sour->upper>10*sour->h)
260
break; // downer zone
265
/////////////////////////////////////////////////////////////////////////////////////////////////////
266
// ����� ���������� � RSource.dll
267
// ��������� ����������� AlMi
268
Bool32 MyGetZher (void **vvZher, Int32 *nZher, Int32 MaxZher, Handle hCPage)
270
Word32 err32, nTeor, nReal;
274
nTeor = sizeof (void *);
279
hBlockZher = CPAGE_GetBlockFirst (hCPage, RVERLINE_ZHERTVY_LINIY);
281
hBlockZher = CPAGE_GetBlockNext (hCPage, hBlockPrev, RVERLINE_ZHERTVY_LINIY);
282
err32 = CPAGE_GetReturnCode ();
286
// Error_CPage ("[GetBlockFirst]");
288
// Error_CPage ("[GetBlockNext]");
295
nReal = CPAGE_GetBlockData (hCPage, hBlockZher, RVERLINE_ZHERTVY_LINIY, (void *)&(vvZher[i]), nTeor);
296
err32 = CPAGE_GetReturnCode ();
297
if (!nReal||(err32!=0))
299
//Error_CPage ("[SetBlockData]");
302
hBlockPrev = hBlockZher;
308
/////////////////////////////////////////////////////////////////////////////////////////////////////
309
// ����� ���������� � RSource.dll
310
Bool32 RemoveLines(Handle hccom,Handle hcpage,PWord8 * lppDIB)
315
CCOM_comp *victim[100];
317
Bool32 yes_victim = FALSE;
321
if(rc && !RLINE_DeleteLines(hcpage,PUMA_IMAGE_DELLINE))
323
SetReturnCode_puma(RLINE_GetReturnCode());
327
// ������� ����������� � ���������� �������
329
if(rc && !CIMAGE_ReadDIB((PWord8)PUMA_IMAGE_DELLINE,(Handle*)&hDIB,TRUE))
331
SetReturnCode_puma(CIMAGE_GetReturnCode());
337
// ������ ���������� � ������� �� ������.
339
*lppDIB = (PWord8)hDIB;
342
if( CCOM_GetContainerVolume((CCOM_handle)hCCOM)<60000 &&
343
MyGetZher ((void**)victim, &nvict, 100, hcpage) && nvict )
348
CCOM_DeleteContainer((CCOM_handle)hCCOM);
352
if(!ExtractComponents(FALSE,&hLinesCCOM,(PWord8)PUMA_IMAGE_DELLINE))
359
GetPageInfo(hCPAGE,&inf);
360
strcpy((char*)inf.szImageName,PUMA_IMAGE_DELLINE);
361
SetPageInfo(hCPAGE,inf);
367
hCCOM = (Handle)REXCGetContainer();
370
SetReturnCode_puma(REXC_GetReturnCode());
379
CCOM_comp *exa=CCOM_GetFirst((CCOM_handle)hLinesCCOM,NULL);
389
rect1.top = exa->upper;
390
rect1.left = exa->left;
391
rect1.bottom = exa->upper+exa->h;
392
rect1.right = exa->left+exa->w;
393
LDPUMA_DrawRect(NULL, &rect1, 0, 23635, 1, key);
396
if(!LDPUMA_Skip(hShowCheckLetters))
398
LDPUMA_Console("Puma_������� ����� \n");
399
LDPUMA_WaitUserInput(NULL, NULL);
400
LDPUMA_DeleteRects(NULL, key);
406
if( remove_overlayed(exa,(CCOM_handle)hCCOM) )
408
CCOM_comp *dup=CCOM_New((CCOM_handle)hCCOM,exa->upper,exa->left,exa->w,exa->h);
413
exa->linerep, exa->nl,
414
exa->begs, exa->ends,
416
dup->scale= exa->scale;
417
dup->type = exa->type;
423
CCOM_DeleteContainer((CCOM_handle)hLinesCCOM);
427
LDPUMA_Console("�������� ���� ��������� ��������� ����� �������� �����.\n");
433
void SetOptionsToFRMT()
435
RFRMT_SetImportData(RFRMT_Bool32_Bold,&gbBold);
436
RFRMT_SetImportData(RFRMT_Bool32_Italic,&gbItalic);
437
RFRMT_SetImportData(RFRMT_Bool32_Size,&gbSize);
438
RFRMT_SetImportData(RFRMT_Word32_Format,&gnFormat);
439
RFRMT_SetImportData(RFRMT_char_SerifName,gpSerifName);
440
RFRMT_SetImportData(RFRMT_char_SansSerifName,gpSansSerifName);
441
RFRMT_SetImportData(RFRMT_char_CourierName,gpCourierName);
442
RFRMT_SetImportData(RFRMT_Word8_UnRecogSymbol,&gnUnrecogChar);
443
RFRMT_SetImportData(RFRMT_Word32_Language,&gnLanguage);
446
Bool32 SaveToText(char * lpOutFileName,int code)
449
int count = CSTR_GetMaxNumber();
451
if(code != PUMA_CODE_ANSI)
453
SetReturnCode_puma(IDS_ERR_NOTIMPLEMENT);
457
FILE * f = fopen(lpOutFileName,"wt");
460
for(int i=1;i<=count;i++)
465
lin_out = CSTR_GetLineHandle(i, 1); // OLEG
466
if(lin_out == (CSTR_line)NULL)
468
SetReturnCode_puma(CSTR_GetReturnCode());
473
if( CSTR_LineToTxt(lin_out,txt) )
475
char szString[sizeof(txt)];
476
sprintf(szString,"%s\n",txt);
477
unsigned len = strlen(szString);
478
if(fwrite(szString,sizeof(char),len,f) != len)
480
SetReturnCode_puma(IDS_ERR_FILEWRITE);
487
SetReturnCode_puma(CSTR_GetReturnCode());
497
SetReturnCode_puma(IDS_ERR_FILEOPEN);
502
////////////////////////////////////////////////////////////
505
LDPUMA_ProgressStart();
509
/////////////////////////////////////////////////////////////////////////////////////////////////////
511
void ProgressFinish()
513
LDPUMA_ProgressFinish();
517
/////////////////////////////////////////////////////////////////////////////////////////////////////
519
Bool32 ProgressStep(Word32 step,char*name,Word32 percent)
522
static Word32 old = 0;
524
g_PrgTime.dwStep = step;
525
g_PrgTime.name = name ? name : g_PrgTime.name;
527
Word32 perc = g_PrgTime.dwBeg + percent*(g_PrgTime.dwEnd - g_PrgTime.dwBeg)/100;
528
rc = LDPUMA_ProgressStep(step,g_PrgTime.name,perc);
529
// _ASSERT(perc>=old);
531
rc &= fnProgressStep(step,g_PrgTime.name,perc);
536
/////////////////////////////////////////////////////////////////////////////////////////////////////
538
Bool32 ProgressStepLayout(Word32 step,Word32 percent)
540
return ProgressStep(step, GetResourceString(IDS_PRG_OPEN), percent);
542
/////////////////////////////////////////////////////////////////////////////////////////////////////
544
Bool32 ProgressStepLines(Word32 step,Word32 percent)
546
return ProgressStep(step, GetResourceString(IDS_REMOVELINE), percent);
548
/////////////////////////////////////////////////////////////////////////////////////////////////////
550
Bool32 ProgressStepTables(Word32 step,Word32 percent)
552
return ProgressStep(step, GetResourceString(IDS_REMOVELINE), percent);
554
//////////////////////////////////////////////////////
555
Bool32 ProgressStepSearchTables(Word32 step,Word32 percent)
557
return ProgressStep(step, GetResourceString(IDS_SEARCHTABLE), percent);
559
//////////////////////////////////////////////////////
560
Bool32 ProgressStepAutoLayout(Word32 step,Word32 percent)
562
return ProgressStep(step, GetResourceString(IDS_AUTOLAYOUT), percent);
565
static Word32 bInitPrgTime = 0;
570
/////////////////////////////////////////////////////////////////////////////////////////////////////
581
/////////////////////////////////////////////////////////////////////////////////////////////////////
589
g_PrgTime.dwEnd = 100;
590
g_PrgTime.dwStep = 0;
597
/////////////////////////////////////////////////////////////////////////////////////////////////////
599
PRGTIME StorePRGTIME(Word32 beg, Word32 end)
601
PRGTIME rc = g_PrgTime;
603
Word32 newBeg = g_PrgTime.dwBeg + (g_PrgTime.dwEnd - g_PrgTime.dwBeg)*beg/100;
604
Word32 newEnd = g_PrgTime.dwBeg + (g_PrgTime.dwEnd - g_PrgTime.dwBeg)*end/100;
606
g_PrgTime.dwBeg = newBeg;
607
g_PrgTime.dwEnd = newEnd;
611
/////////////////////////////////////////////////////////////////////////////////////////////////////
613
void RestorePRGTIME(PRGTIME prev)
617
/////////////////////////////////////////////////////////////////////
618
Bool32 PrintResult(int num,CSTR_line lout,Handle hCPAGE)
621
CSTR_rast start = CSTR_GetFirstRaster (lout),
622
stop = CSTR_GetLastRaster (lout), c;
625
CSTR_attr line_attr = {0};
629
Bool32 strikeout = 0;
630
Bool32 underline = 0;
633
Word32 textcolor = 0;
634
int charset = RUSSIAN_CHARSET;
635
const char * name = NULL;
636
static Int32 nFragment = -1;
637
static Word32 deftextcolor = 0;
638
Bool32 bOutputKegl = TRUE;
640
CSTR_GetLineAttr (lout,&line_attr);
642
if(line_attr.fragment != nFragment)
646
Handle hBlock = CPAGE_GetBlockFirst(hCPAGE,0);
649
if(CPAGE_GetBlockInterNum(hCPAGE,hBlock) == (Word32)line_attr.fragment)
651
nFragment = line_attr.fragment;
654
hBlock = CPAGE_GetBlockNext(hCPAGE,hBlock,0);
659
deftextcolor = 254L + (127L<<8);
662
LDPUMA_SetConsoleProperty(0,0,0,0,0,0,deftextcolor,RUSSIAN_CHARSET,"Courier New");
663
LDPUMA_Console("��.%2i ���.%3i: <",line_attr.fragment,num);
667
c=CSTR_GetNextRaster (start,CSTR_f_all);
668
for(; c && c!=stop; c=CSTR_GetNextRaster (c,CSTR_f_all))
670
CSTR_GetAttr(c, &attr);
671
if( !(attr.flg & (CSTR_f_let|CSTR_f_punct|CSTR_f_bad|CSTR_f_space|CSTR_f_solid)) )
673
if( CSTR_GetCollectionUni(c, &vers) )
676
if(LDPUMA_Skip(hDebugCancelPropertyConsole))
678
if(attr.font&CSTR_fp_bold)
683
if(attr.font&CSTR_fp_it)
688
if(attr.font&CSTR_fp_undrln)
693
height = attr.keg*10*2;
694
switch( attr.font_spec )
697
if(attr.font & CSTR_fp_ser)
698
name = "Times New Roman";
699
else if(attr.font & CSTR_fp_gelv)
702
name = "Courier New";
703
if( attr.font & CSTR_fp_narrow )
704
name = "Arial Narrow";
706
case CSTR_fs_courier:
707
name = "Courier New";
713
if(attr.flg_spell & CSTR_fa_spell_reject)
714
textcolor |= 200<<16;// RGB
715
if(attr.flg_spell & CSTR_fa_spell_nocarrying)
718
if(!vers.lnAltCnt || vers.Alt[0].Prob<70)
722
charset = vers.Alt[0].Charset;
723
LDPUMA_SetConsoleProperty(bold,italic,strikeout,
724
underline,height,offset,textcolor,charset,name);
727
LDPUMA_Console("%c",'~');
730
if( vers.Alt[0].Code[0]=='%' )
731
LDPUMA_Console((char *)"%%");
733
LDPUMA_Console((char *)vers.Alt[0].Code);
736
if(bOutputKegl && !LDPUMA_Skip(hDebugCancelConsoleKeglOutput))
738
LDPUMA_SetConsoleProperty(0,0,0,0,0,0,150L<<8,RUSSIAN_CHARSET,NULL);
739
LDPUMA_Console(">%i<",attr.keg);
746
LDPUMA_SetConsoleProperty(0,0,0,0,0,0,deftextcolor,RUSSIAN_CHARSET,NULL);
747
LDPUMA_Console(">\n");
750
LDPUMA_SetConsoleProperty(0,0,0,0,0,0,0,RUSSIAN_CHARSET,NULL);
754
/////////////////////////////////////////////////////////////////////////////////////////////////////
756
Bool32 HL_TableExtractEx( Handle hPAGE, Word32 perc, Rect32 rect )
758
return RMARKER_SearchTableInZone(hPAGE,hCCOM,perc,rect);
760
/////////////////////////////////////////////////////////////////////////////////////////////////////
762
Bool32 IsUpdate(Word32 flg)
764
return (g_flgUpdate & flg) > 0;
767
void SetUpdate(Word32 flgAdd,Word32 flgRemove)
769
g_flgUpdate = (g_flgUpdate | flgAdd) & ~flgRemove;