Bool32 FillPicsInTables(Handle hCCOM, Handle hCPAGE) { POLY_ block; Handle h = NULL; CCOM_comp * comp; for(h = CPAGE_GetBlockFirst(hCPAGE,POSSIBLE_PICTURES); h!=NULL; h = CPAGE_GetBlockNext(hCPAGE,h,POSSIBLE_PICTURES)) { CPAGE_GetBlockData(hCPAGE,h,POSSIBLE_PICTURES, &block, sizeof(block)); CPAGE_DeleteBlock(hCPAGE, h); if (nPics % PICS_QUANTUM == 0) { pPics = (CCOM_comp *) realloc (pPics, (size_t) ((nPics / PICS_QUANTUM + 1)* PICS_QUANTUM * sizeof (CCOM_comp))); } comp = &pPics[nPics++]; comp->upper = block.com.Vertex[0].y; comp->left = block.com.Vertex[0].x; comp->w = block.com.Vertex[1].x - block.com.Vertex[0].x; comp->h = block.com.Vertex[2].y - block.com.Vertex[1].y; } return TRUE; }
Bool32 FillBigLetters (Handle hCCOM,Handle hCPAGE) { Handle BlockType; Handle pBlock; RPIC_Comp_Rect CompRect; BlockType = CPAGE_GetInternalType("pic's to letters boxes"); pBlock = CPAGE_GetBlockFirst(hCPAGE, BlockType); while(pBlock) { if (nBigLetters % BIG_LETTERS_QUANTUM == 0) { pBigLetters = (RPIC_Comp_Rect*)realloc (pBigLetters, (size_t) ((nBigLetters / BIG_LETTERS_QUANTUM + 1) * BIG_LETTERS_QUANTUM * sizeof (RPIC_Comp_Rect))); } CPAGE_GetBlockData(hCPAGE, pBlock, BlockType, &CompRect, sizeof(CompRect)); nBigLetters++; pBigLetters[nBigLetters-1] = CompRect; pBlock = CPAGE_GetBlockNext(hCPAGE, pBlock, BlockType); } return TRUE; }
///////////////////////////////////////////////////////////////////////////// // CFPage::CreateArray_For_TextFragments void CFPage::CreateArray_For_TextFragments( ) { Handle hPage = CPAGE_GetHandlePage( CPAGE_GetCurrentPage() ); Handle hBlock = CPAGE_GetBlockFirst( hPage , 0 ); while( hBlock ) { if(CPAGE_GetBlockType( hPage , hBlock ) == TYPE_TEXT){ uint32_t BlockNumber = CPAGE_GetBlockInterNum( hPage, hBlock); FragmentsArray.push_back( BlockNumber ); } hBlock = CPAGE_GetBlockNext( hPage , hBlock , 0); } }
RSL_FUNC(Bool32) RSL_SetImportData(uint32_t dwType, void * pData) { Bool32 rc = RESULT; if (dwType != RSL_HANDLE) return FALSE; Handle* phCPage = (Handle*) pData; RSPreProcessImage IImage; PRSPreProcessImage Image = &IImage; uint32_t nTeor = sizeof (RSPreProcessImage); Handle hPage = CPAGE_GetHandlePage(CPAGE_GetCurrentPage()); Handle VerifyN = CPAGE_GetBlockFirst (*phCPage, RSL_VERLINE);//hPage, RSL_VERLINE); uint32_t nReal = CPAGE_GetBlockData (*phCPage, VerifyN, RSL_VERLINE, Image, nTeor); // uint32_t err32 = CPAGE_GetReturnCode (); // if (err32) // return FALSE; if( *Image->pgrc_line ) { if(LDPUMA_Skip(Image->hDebugCancelVerifyLines)) { Regime_VerifyLines val = Image->gnTables ? RVL_FutuTablCorr:RVL_Default; if( !RVERLINE_SetImportData(RVERLINE_DTRVERLINE_RegimeOfVerifyLines,&val)|| !RVERLINE_MarkLines(*Image->phCCOM, Image->hCPAGE)) { SetReturnCode_rshelllines((uint16_t)RVERLINE_GetReturnCode()); rc = FALSE; } else { Bool32 BadScan = FALSE; int32_t ScanQual= 0; AboutLines(Image, &BadScan, &ScanQual); } if(!*Image->pgneed_clean_line) LDPUMA_Console("Warning: RSL said that the lines don't need to be erased from the picture.\n"); } else LDPUMA_Console("Missing stage of the evaluation lines.\n"); } //CPAGE_DeleteBlock(&phCPage, VerifyN); return rc; }
///////////////////////////////////////////////////////////////////////////// // CFPage::ProcessingComingLine void CFPage::ProcessingComingLine( CSTR_line* Comingline ) { CSTR_line line; CSTR_attr attr; CFragment* Fragment; Handle hCPAGE; Handle hBlock; POLY_ poly; line = *Comingline; if( !CSTR_GetLineAttr( line , &attr ) || attr.Flags&CSTR_STR_EMPTY ) return; m_nCurFragNumber = attr.fragment; if( m_nCurFragNumber != m_nPrevFragNumber ){ m_arFrags.push_back( new CFragment() ); Fragment = m_arFrags[Count.Frags]; assert(Fragment); hCPAGE = CPAGE_GetHandlePage( CPAGE_GetCurrentPage()); hBlock = CPAGE_GetBlockFirst( hCPAGE, NULL ); while(hBlock) { if(CPAGE_GetBlockInterNum(hCPAGE,hBlock)==(uint32_t)m_nCurFragNumber){ Fragment->m_wUserNumber = (uint32_t)CPAGE_GetBlockUserNum( hCPAGE, hBlock ); Fragment->m_Flags = attr.Flags; //nega if(attr.Flags == CSTR_STR_NEGATIVE){ //nega_str CPAGE_GetBlockData(hCPAGE,hBlock,TYPE_TEXT, &poly, sizeof(POLY_)); Fragment->m_rectFrag.left = poly.com.Vertex[0].x - TemplateOffset.x; Fragment->m_rectFrag.right = poly.com.Vertex[2].x - TemplateOffset.x; Fragment->m_rectFrag.top = poly.com.Vertex[0].y - TemplateOffset.y; Fragment->m_rectFrag.bottom = poly.com.Vertex[2].y - TemplateOffset.y; } break; } hBlock = CPAGE_GetBlockNext(hCPAGE,hBlock, NULL ); } assert(hBlock!=NULL); ++Count.Frags; } AddString(Comingline); m_nPrevFragNumber = m_nCurFragNumber; }
/*---------------------------------------------------------------------------*/ Bool LoadLinesSpecInfo (Handle hC, void *vB, Handle Key, int Cnt) { int i; uint32_t err32, nTeor, nReal; Handle hBlockLineSpec; Handle hBlockLinePrev; UN_BUFF *pB; char *vCurr; pB = (UN_BUFF *)vB; vCurr = (char *)pB->vCurr; nTeor = sizeof (LineInfo); for (i=0; i<Cnt; i++) { /* ключ к данным */ if (i==0) hBlockLineSpec = CPAGE_GetBlockFirst (hC, Key); else hBlockLineSpec = CPAGE_GetBlockNext (hC, hBlockLinePrev, Key); err32 = CPAGE_GetReturnCode (); if ((err32!=0)||(hBlockLineSpec==NULL)) { #ifdef Almi if (i==0) AM_Console ("RLTABLE : Ошибка чужой библиотеки - [CPAGE]%s", "[GetBlockFirst]"); else AM_Console ("RLTABLE : Ошибка чужой библиотеки - [CPAGE]%s", "[GetBlockNext]"); #endif return FALSE; } /* собственно данные */ nReal = CPAGE_GetBlockData (hC, hBlockLineSpec, Key, (void *)vCurr, nTeor); err32 = CPAGE_GetReturnCode (); if ((nReal!=nTeor)||(err32!=0)) { #ifdef Almi AM_Console ("RLTABLE : Ошибка чужой библиотеки - [CPAGE]%s", "[GetBlockData]"); #endif return FALSE; } hBlockLinePrev = hBlockLineSpec; vCurr += nTeor; } EndLastDataPart (vB, UN_DA_Unknown, UN_DT_LineInfo, nTeor, Cnt); return TRUE; }
/*---------------------------------------------------------------------------*/ Bool LoadLinesTotalInfo_rv (Handle hC, void *vB, char *pStr) { uint32_t err32, nTeor, nReal; Handle hBlockLine; UN_BUFF *pB; pB = (UN_BUFF *)vB; /* ключ к данным */ hBlockLine = CPAGE_GetBlockFirst (hC, RLINE_BLOCK_TYPE); if (!hBlockLine) { sprintf (pStr, "Линии не выделялись."); return RV_EMPTY; } err32 = CPAGE_GetReturnCode (); if (err32!=0) { #ifdef Almi AM_Console ("RLTABLE : Ошибка чужой библиотеки - [CPAGE]%s", "[GetBlockFirst]"); #endif return RV_FALSE; } /* собственно данные */ nTeor = sizeof (LinesTotalInfo); if ((int)nTeor>pB->SizeCurr) { sprintf (pStr, "Не хватило памяти под 1, инфо-линии!"); return RV_DOUBT; } nReal = CPAGE_GetBlockData (hC, hBlockLine, RLINE_BLOCK_TYPE, pB->vCurr, nTeor); err32 = CPAGE_GetReturnCode (); if ((nReal!=nTeor)||(err32!=0)) { #ifdef Almi AM_Console ("RLTABLE : Ошибка чужой библиотеки - [CPAGE]%s", "[GetBlockData]"); #endif return RV_FALSE; } EndLastDataPart (vB, UN_DA_Unknown, UN_DT_LinesTotalInfo, nTeor, 1); return RV_TRUE; }
Bool32 MyGetZher (void **vvZher, int32_t *nZher, int32_t MaxZher, Handle hCPage) { uint32_t err32, nTeor, nReal; Handle hBlockZher; Handle hBlockPrev; int i; nTeor = sizeof (void *); i=0; while (1) { if (i==0) hBlockZher = CPAGE_GetBlockFirst (hCPage, RVERLINE_ZHERTVY_LINIY); else hBlockZher = CPAGE_GetBlockNext (hCPage, hBlockPrev, RVERLINE_ZHERTVY_LINIY); err32 = CPAGE_GetReturnCode (); if (err32!=0) { //if (i==0) // Error_CPage ("[GetBlockFirst]"); //else // Error_CPage ("[GetBlockNext]"); return FALSE; } if (!hBlockZher) break; if (i>=MaxZher) return FALSE; nReal = CPAGE_GetBlockData (hCPage, hBlockZher, RVERLINE_ZHERTVY_LINIY, (void *)&(vvZher[i]), nTeor); err32 = CPAGE_GetReturnCode (); if (!nReal||(err32!=0)) { //Error_CPage ("[SetBlockData]"); return FALSE; } hBlockPrev = hBlockZher; i++; } *nZher = i; return TRUE; }
//########################################### // Если блоки конвертируемы один в другой, тогда имеет смысл оставить только один, // наиболее полный тип. Именно это и делает эта функция. // CPAGE_FUNC(Bool32) CPAGE_UpdateBlocks( Handle hPage, Handle type ) { PROLOG; Bool32 rc = TRUE; uint32_t size = 0; char * lpData = NULL; Handle temporaray = 0; SetReturnCode_cpage(IDS_ERR_NO); #ifdef _DEBUG _ASSERT(CPAGE_GetNameInternalType(type)); #endif SetReturnCode_cpage(IDS_ERR_NO); Handle hBlock = CPAGE_GetBlockFirst(hPage,type); if(!hBlock) { rc = TRUE; goto lOut; } // Создадим временные блоки и удалим старые. // Тем самым предотвращаем зацикливание. temporaray = CPAGE_GetInternalType("temporary"); while(hBlock) { Handle hNextBlock = CPAGE_GetBlockNext(hPage,hBlock,type);// type - запрашиваемый тип блока Handle dwType = CPAGE_GetBlockType(hPage,hBlock); // dwType - Реальный тип блока if(dwType != type) // Была произведена конвертация из типа dwType ! { uint32_t UserNum = CPAGE_GetBlockUserNum(hPage,hBlock); uint32_t Flags = CPAGE_GetBlockFlags(hPage,hBlock); if(lpData == NULL) { // Определим необходимый размер и отведем память. size = CPAGE_GetBlockData(hPage,hBlock,type,NULL,0); if(size) { lpData = (char *)myAlloc(size); if(!lpData) { rc = FALSE; SetReturnCode_cpage(IDS_ERR_NO_MEMORY); break; } } else { SetReturnCode_cpage(IDS_ERR_DISCREP); rc = FALSE; break; } } if(CPAGE_GetBlockData(hPage,hBlock,type,lpData,size)==size) { CPAGE_DeleteBlock(hPage,hBlock); if(!CPAGE_CreateBlock(hPage,temporaray, UserNum , Flags, lpData, size)) { SetReturnCode_cpage(IDS_ERR_NO_MEMORY); rc = FALSE; break; } } } hBlock = hNextBlock; } // Переименуем временные блоки if(lpData) // Проверка на существование таких блоков { myFree(lpData); for(hBlock = CPAGE_GetBlockFirst(hPage,temporaray); hBlock; hBlock = CPAGE_GetBlockNext(hPage,hBlock,temporaray)) { BLOCK_H_H(hPage,hBlock).SetType(type); } } lOut:EPILOG; return rc; }
void SeparatorsGet (void) { #define ABS1 10 #define ABS2 40 //int nl; PAGEINFO pInfo; // LineInfo lInfo; // LinesTotalInfo lti; // Handle pBlock; Handle pPage; // uint32_t HorType; // uint32_t VerType; uint32_t ResolutionCoeff; uint32_t i,j; Handle hPage = CPAGE_GetHandlePage(CPAGE_GetCurrentPage( )); Handle hBlock; // Point16 p_start, p_end; uint32_t key; uint32_t color; int32_t nPics; POLY_ *pPics; // extern Handle hUseCLine; uint32_t size_line_com=sizeof(LINE_COM); CLINE_handle hline; extern CLINE_handle HCLINE; pPage = CPAGE_GetHandlePage(CPAGE_GetCurrentPage( )); CPAGE_GetPageData( pPage, PT_PAGEINFO, (void*)&pInfo, sizeof(pInfo)); ResolutionCoeff = pInfo.DPIY/2; SeparatorsFreeData (); // if(!LDPUMA_Skip(hUseCLine)) // { hline = CLINE_GetFirstLine(HCLINE); if(!hline) return; while(hline) { CPDLine cpdata=CLINE_GetLineData(hline); if(!cpdata) hline=CLINE_GetNextLine(hline); else { nSeps++; pSeps = realloc (pSeps, nSeps*sizeof(SEPARATOR)); pSeps [nSeps-1].xBegin = cpdata->Line.Beg_X; pSeps [nSeps-1].yBegin = cpdata->Line.Beg_Y; pSeps [nSeps-1].xEnd = cpdata->Line.End_X; pSeps [nSeps-1].yEnd = cpdata->Line.End_Y; pSeps [nSeps-1].nWidth = cpdata->Line.Wid10/10; if(cpdata->Dir==LD_Horiz) pSeps [nSeps-1].Type = SEP_HORZ; else pSeps [nSeps-1].Type = SEP_VERT; hline=CLINE_GetNextLine(hline); } } // } /* else { pBlock = CPAGE_GetBlockFirst ( pPage, RLINE_BLOCK_TYPE ); if(pBlock == NULL) return; CPAGE_GetBlockData( pPage, pBlock, RLINE_BLOCK_TYPE, <i, sizeof(LinesTotalInfo)); HorType = (uint32_t)lti.Hor.Lns; VerType = (uint32_t)lti.Ver.Lns; pBlock = CPAGE_GetBlockFirst ( pPage, HorType ); while ( pBlock ) { CPAGE_GetBlockData( pPage, pBlock, HorType, &lInfo, sizeof(LineInfo)); nSeps++; pSeps = realloc (pSeps, nSeps*sizeof(SEPARATOR)); pSeps [nSeps-1].xBegin = lInfo.A.x; pSeps [nSeps-1].yBegin = lInfo.A.y; pSeps [nSeps-1].xEnd = lInfo.B.x; pSeps [nSeps-1].yEnd = lInfo.B.y; pSeps [nSeps-1].nWidth = lInfo.Thickness; pSeps [nSeps-1].Type = SEP_HORZ; pBlock = CPAGE_GetBlockNext( pPage, pBlock, HorType ); } pBlock = CPAGE_GetBlockFirst ( pPage, VerType ); while ( pBlock ) { CPAGE_GetBlockData( pPage, pBlock, VerType, &lInfo, sizeof(LineInfo)); nSeps++; pSeps = realloc (pSeps, nSeps*sizeof(SEPARATOR)); pSeps [nSeps-1].xBegin = lInfo.A.x; pSeps [nSeps-1].yBegin = lInfo.A.y; pSeps [nSeps-1].xEnd = lInfo.B.x; pSeps [nSeps-1].yEnd = lInfo.B.y; pSeps [nSeps-1].nWidth = lInfo.Thickness; pSeps [nSeps-1].Type = SEP_VERT; pBlock = CPAGE_GetBlockNext( pPage, pBlock, VerType ); } } */ color = 200; key = 111; /* Deleting short separators */ for(i = 0; i < nSeps; i++) { if(pSeps [i].Type == SEP_VERT) { if(pSeps[i].yEnd - pSeps[i].yBegin < ResolutionCoeff) { DeleteSeps(i); i--; } else { /* p_start.x = pSeps[i].xBegin; p_start.y = pSeps[i].yBegin; p_end.x = pSeps[i].xEnd; p_end.y = pSeps[i].yEnd; LDPUMA_DrawLine(NULL, &p_start, &p_end, 0, color, 4, key); */ } } else { if(pSeps[i].xEnd - pSeps[i].xBegin < ResolutionCoeff) { DeleteSeps(i); i--; } else { /* p_start.x = pSeps[i].xBegin; p_start.y = pSeps[i].yBegin; p_end.x = pSeps[i].xEnd; p_end.y = pSeps[i].yEnd; LDPUMA_DrawLine(NULL, &p_start, &p_end, 0, color, 4, key); */ } } } //LDPUMA_WaitUserInput(NULL, NULL); //LDPUMA_DeleteLines(NULL, key); /* Deleting separators from pictures */ nPics = 0; pPics = NULL; # define PICS_QUANTUM 128 for(hBlock = CPAGE_GetBlockFirst(hPage,TYPE_IMAGE); hBlock!=NULL; hBlock = CPAGE_GetBlockNext(hPage,hBlock,TYPE_IMAGE)) { if (nPics % PICS_QUANTUM == 0) { pPics = realloc (pPics, (size_t) ((nPics / PICS_QUANTUM + 1) * PICS_QUANTUM * sizeof (POLY_))); } CPAGE_GetBlockData(hPage,hBlock,TYPE_IMAGE, &pPics[nPics++], sizeof(POLY_)); } for (i = 0; i < nPics; i++) { for (j = 0; j < nSeps; j++) { if( (pSeps[j].xBegin > pPics[i].com.Vertex[0].x-10) && (pSeps[j].yBegin > pPics[i].com.Vertex[0].y-10) && (pSeps[j].xEnd < pPics[i].com.Vertex[1].x+10) && (pSeps[j].yEnd < pPics[i].com.Vertex[2].y+10)) { DeleteSeps(j); j--; } } } if (pPics != NULL) { free (pPics); pPics = NULL; } nPics = 0; /* Удаление близколежащих сепараторов */ for (i = 0; i < nSeps; i++) { for (j = 0; j < nSeps; j++) { if(pSeps [i].Type == SEP_VERT && pSeps [j].Type == SEP_VERT) { if((uint32_t)(abs(pSeps[i].xBegin - pSeps[j].xEnd ) < ResolutionCoeff/2) && (uint32_t)(abs(pSeps[i].xEnd - pSeps[j].xBegin) < ResolutionCoeff/2) && (pSeps[i].yBegin < pSeps[j].yBegin) && (pSeps[i].yEnd > pSeps[j].yEnd)) { DeleteSeps(j); j--; } } } } /* Объединение сепараторов */ for (i = 0; i < nSeps; i++) { for (j = 0; j < nSeps; j++) { if(pSeps [i].Type == SEP_VERT && pSeps [j].Type == SEP_VERT) { if((abs(pSeps[i].xBegin - pSeps[j].xEnd) < ABS1) && (pSeps[i].yBegin > pSeps[j].yEnd) && (uint32_t)(pSeps[i].yBegin - pSeps[j].yEnd) < ResolutionCoeff/2) { pSeps[i].xBegin = MIN(pSeps[i].xBegin, pSeps[j].xBegin); pSeps[i].xEnd = MAX(pSeps[i].xEnd, pSeps[j].xEnd); pSeps[i].yBegin = pSeps[j].yBegin; DeleteSeps(j); j--; } } if(pSeps [i].Type == SEP_HORZ && pSeps [j].Type == SEP_HORZ) { if((abs(pSeps[i].yBegin - pSeps[j].yEnd) < ABS1) && (pSeps[i].xBegin > pSeps[j].xEnd) && (pSeps[i].xBegin - pSeps[j].xEnd) < ABS2) { pSeps[i].yBegin = MIN(pSeps[i].yBegin, pSeps[j].yBegin); pSeps[i].yEnd = MAX(pSeps[i].yEnd, pSeps[j].yEnd); pSeps[i].xBegin = pSeps[j].xBegin; DeleteSeps(j); j--; } } } } /* for(i = 0; i < nSeps; i++) { color = 200; key = 111; p_start.x = pSeps[i].xBegin; p_start.y = pSeps[i].yBegin; p_end.x = pSeps[i].xEnd; p_end.y = pSeps[i].yEnd; LDPUMA_DrawLine(NULL, &p_start, &p_end, 0, color, 4, key); } */ //LDPUMA_WaitUserInput(NULL, NULL); }
/*---------------------------------------------------------------------------*/ Bool LoadPicts_rv (Handle hC, void *vB, char *pStr) { int SizeCurr, Deficit, nRc; uint32_t err32, nTeor, nReal; Bool ret; POLY_ Pict; Handle hBlockPictSpec; Handle hBlockPictPrev; UN_BUFF *pB; Rect16 *pCurr; pB = (UN_BUFF *)vB; nRc = 0; Deficit = 0; pCurr = (Rect16 *)pB->vCurr; SizeCurr = pB->SizeCurr; nTeor = sizeof (POLY_); hBlockPictPrev = NULL; while (1) { /* ключ к данным */ if (hBlockPictPrev==NULL) hBlockPictSpec = CPAGE_GetBlockFirst (hC, TYPE_IMAGE); else hBlockPictSpec = CPAGE_GetBlockNext (hC, hBlockPictPrev, TYPE_IMAGE); err32 = CPAGE_GetReturnCode (); if (hBlockPictSpec==NULL) break; if (err32!=0) { if (hBlockPictPrev==NULL) sprintf (pStr, "[GetBlockFirst]"); else sprintf (pStr, "[GetBlockNext]"); return FALSE; } /* собственно данные */ nReal = CPAGE_GetBlockData (hC, hBlockPictSpec, TYPE_IMAGE, (void *)(&Pict), nTeor); err32 = CPAGE_GetReturnCode (); if ((nReal!=nTeor)||(err32!=0)) { sprintf (pStr, "[GetBlockData]"); return FALSE; } hBlockPictPrev = hBlockPictSpec; if ((int)nTeor > SizeCurr) { Deficit++; continue; } nRc++; ret = MakeRectFromPict (pCurr, (void *)(&Pict)); #include "am_comm.h" #ifdef Almi #include "ft_rule.h" if (!ret) { if (!AM_Skip (FT_GetKeyOfRule (RU_FT_C_ContWarn))) AM_Console ("Не удалось осмыслить картинку!"); continue; } #endif pCurr++; SizeCurr -= sizeof (Rect16); } if (nRc==0) { sprintf (pStr, "Нет картинок"); return RV_EMPTY; } EndLastDataPart (vB, UN_DA_PictReal, UN_DT_Rect16, sizeof (Rect16), nRc); if (Deficit > 0) { sprintf (pStr, "Не хватило памяти под %d %s!", Deficit, "коробки картинок"); return RV_DOUBT; } return RV_TRUE; }
Bool32 RPIC_SearchPictures(CCOM_handle hCCOM, CCOM_handle hCCOM_big, Handle hCPAGE) { CCOM_comp * comp = NULL; CCOM_comp common; PAGEINFO pInfo; POLY_ block; uint32_t i, j; Rect16 rect; uint32_t key; uint32_t color; uint32_t tmp_comp = 0; Handle MainWindowD = NULL; MainWindowD = LDPUMA_GetWindowHandle("Изображение после разворота"); if (!MainWindowD) MainWindowD = LDPUMA_GetWindowHandle("Main"); OpenLogRes(); file_name = (char*) LDPUMA_GetFileName(NULL); //color = 23650; color = 200; key = 111; nPics = 0; if (pPics) { free(pPics); pPics = NULL; } nComps = 0; CPAGE_GetPageData(hCPAGE, PT_PAGEINFO, (void*) &pInfo, sizeof(pInfo)); for (i = 0; i < MaxHeightOfLetter; i++) { pHystogram[i] = 0; } //LDPUMA_FPuts(hFile, (char*)&pInfo.szImageName); LDPUMA_FPuts(logFile_comp, "*******************************************************\n"); LDPUMA_FPuts(logFile_comp, "new_file \n"); if ((pInfo.Angle == 90) || (pInfo.Angle == 270)) { uint32_t tmp; tmp = pInfo.Width; pInfo.Width = pInfo.Height; pInfo.Height = tmp; } //stepa_am comp = CCOM_GetFirst(hCCOM_big, NULL); while (comp) { tmp_comp++; if ((comp->h > MinHeightOfLetter) && (comp->h < MaxHeightOfLetter)) { nComps++; pHystogram[comp->h]++; } if (comp->scale < 1) goto lNextComp_big; /* if( comp->cs == 255) { comp->type = CCOM_CH_LETTER; goto lNextComp; } */ if (IsNotGoodComp(pInfo, comp)) { if (!LDPUMA_Skip(hShowAllCancelledGreat)) { rect.left = comp->left; rect.top = comp->upper; rect.right = comp->left + comp->w; rect.bottom = comp->upper + comp->h; LDPUMA_DrawRect(MainWindowD, &rect, 0, color, 4, key); } goto lNextComp_big; } if (nPics % PICS_QUANTUM == 0) { pPics = (CCOM_comp *) realloc(pPics, (size_t) ((nPics / PICS_QUANTUM + 1) * PICS_QUANTUM * sizeof(CCOM_comp))); } pPics[nPics++] = *comp; lNextComp_big: comp = CCOM_GetNext(comp, NULL); } //end stepa_am comp = CCOM_GetFirst(hCCOM, NULL); while (comp) { tmp_comp++; if ((comp->h > MinHeightOfLetter) && (comp->h < MaxHeightOfLetter)) { nComps++; pHystogram[comp->h]++; } if ( /*comp->scale < */1) goto lNextComp; /* if( comp->cs == 255) { comp->type = CCOM_CH_LETTER; goto lNextComp; } */ if (IsNotGoodComp(pInfo, comp)) { if (!LDPUMA_Skip(hShowAllCancelledGreat)) { rect.left = comp->left; rect.top = comp->upper; rect.right = comp->left + comp->w; rect.bottom = comp->upper + comp->h; LDPUMA_DrawRect(MainWindowD, &rect, 0, color, 4, key); } goto lNextComp; } if (nPics % PICS_QUANTUM == 0) { pPics = (CCOM_comp *) realloc(pPics, (size_t) ((nPics / PICS_QUANTUM + 1) * PICS_QUANTUM * sizeof(CCOM_comp))); } pPics[nPics++] = *comp; lNextComp: comp = CCOM_GetNext(comp, NULL); } if (!LDPUMA_Skip(hShowAllCancelledGreat)) { LDPUMA_Console("RPIC_Отмененные большие компоненты \n"); LDPUMA_WaitUserInput(hShowAllCancelledGreat, MainWindowD); LDPUMA_DeleteRects(MainWindowD, key); } if (!nComps) // OLEG return TRUE; // STEPA_AM if (!nPics) return TRUE; /**************************************************/ for (i = 0; i < MaxHeightOfLetter; i++) { nAverageHeight += pHystogram[i] * i; /* sprintf(tmp_str, " %i (i)\n", i); LDPUMA_FPuts(logFile,tmp_str); sprintf(tmp_str, " %i (pHystogram[i])\n", pHystogram[i]); LDPUMA_FPuts(logFile,tmp_str); */ } nAverageHeight /= nComps; sprintf(tmp_str, "Average height %i (nAverageHeight)\n", nAverageHeight); LDPUMA_FPuts(logFile_comp, tmp_str); /**************************************************/ /************** first union all crossed and included pictures ******************/ /* for (i=0; i<nPics; i++) { for (j=0; j<nPics; j++) { if ( (pPics[i].upper < pPics[j].upper)&& (pPics[i].left < pPics[j].left)&& (pPics[i].left + pPics[i].w > pPics[j].left + pPics[j].w)&& (pPics[i].upper + pPics[i].h > pPics[j].upper + pPics[j].h) ) { DeleteFromPics (j); j--; } } } for (i=0; i<nPics; i++) { for (j=0; j<nPics; j++) { if (i==j) continue; if ( (pPics[i].upper - VER_BOUND_SIZE < pPics[j].upper + pPics[j].h)&& (pPics[i].left - HOR_BOUND_SIZE < pPics[j].left + pPics[j].w)&& (pPics[i].left + pPics[i].w + HOR_BOUND_SIZE > pPics[j].left)&& (pPics[i].upper + pPics[i].h + VER_BOUND_SIZE > pPics[j].upper) ) { common = pPics[i]; if (pPics[i].upper >= pPics[j].upper) common.upper = pPics[j].upper; if (pPics[i].left >= pPics[j].left) common.left = pPics[j].left; if (pPics[i].upper + pPics[i].h < pPics[j].upper + pPics[j].h) common.h = pPics[j].upper + pPics[j].h - pPics[i].upper; if (pPics[i].left + pPics[i].w < pPics[j].left + pPics[j].w) common.w = pPics[j].left + pPics[j].w - pPics[i].left; common.h += pPics[i].upper - common.upper; common.w += pPics[i].left - common.left; pPics[i] = common; DeleteFromPics (j); j=0; i=0; } } } */ /***********************************************************************************/ color = 200; key = 111; if ((!LDPUMA_Skip(hShowAllGreat)) && nPics) { for (i = 0; i < nPics; i++) { rect.left = pPics[i].left; rect.top = pPics[i].upper; rect.right = pPics[i].left + pPics[i].w; rect.bottom = pPics[i].upper + pPics[i].h; LDPUMA_DrawRect(MainWindowD, &rect, 0, color, 2, key); } LDPUMA_Console("RPIC_Рассматриваемые большие компоненты \n"); LDPUMA_WaitUserInput(hShowAllGreat, MainWindowD); LDPUMA_DeleteRects(MainWindowD, key); } //sprintf(tmp_str, "Amount of 'letters' on the first step %i (nComps)\n", nComps); //LDPUMA_FPuts(logFile_comp,tmp_str); //sprintf(tmp_str, " <2 Н Страница = %d \n", page_count++); //LDPUMA_FPuts(resFile_comp,tmp_str); //char* str; //str = LDPUMA_GetFileName(NULL); LDPUMA_FPuts(resFile_comp, " <2 Н Страница ="); LDPUMA_FPuts(resFile_comp, file_name); LDPUMA_FPuts(resFile_comp, " \n"); //LDPUMA_FPuts(resFile_comp, " <2 Н Страница \n"); LDPUMA_FPuts(resFile_comp, " <3 Н Компоненты \n"); sprintf(tmp_str, " <4 П Перед выделением линий \n", nComps); LDPUMA_FPuts(resFile_comp, tmp_str); sprintf(tmp_str, " <4 Р %d \n", nComps); LDPUMA_FPuts(resFile_comp, tmp_str); sprintf(tmp_str, "Amount of pictures on the before first step %i (nPics)\n", nPics); LDPUMA_FPuts(logFile_comp, tmp_str); /*******************************************************************/ if (LDPUMA_Skip(hRectanglePictures)) SearchRectanglePictures(hCCOM, hCCOM_big, hCPAGE); if (LDPUMA_Skip(hPolyPictures)) SearchPolyPictures(hCCOM, hCPAGE); /*******************************************************************/ /************** final union all crossed and included pictures ******************/ for (i = 0; i < nPics; i++) { if (pPics[i].large & CCOM_LR_KILLED) { continue; } for (j = 0; j < nPics; j++) { if ((pPics[i].upper < pPics[j].upper) && (pPics[i].left < pPics[j].left) && (pPics[i].left + pPics[i].w > pPics[j].left + pPics[j].w) && (pPics[i].upper + pPics[i].h > pPics[j].upper + pPics[j].h)) { /* if((pPics[i].type!=CCOM_CH_LETTER)||(pPics[j].type!=CCOM_CH_LETTER)) { pPics[i].type = CCOM_CH_MERGE; } */ if (pPics[j].large & CCOM_LR_KILLED) { // it's bad, but will work cause pPics[].large not initialised in RPIC pPics[i].large |= CCOM_LR_TAKEN; continue; } DeleteFromPics(j); //j--; } } } for (i = 0; i < nPics; i++) { if (pPics[i].large & CCOM_LR_KILLED) { continue; } for (j = 0; j < nPics; j++) { if (pPics[j].large & CCOM_LR_KILLED) { continue; } if (i == j) continue; if ((pPics[i].upper - VER_BOUND_SIZE < pPics[j].upper + pPics[j].h) && (pPics[i].left - HOR_BOUND_SIZE < pPics[j].left + pPics[j].w) && (pPics[i].left + pPics[i].w + HOR_BOUND_SIZE > pPics[j].left) && (pPics[i].upper + pPics[i].h + VER_BOUND_SIZE > pPics[j].upper)) { common = pPics[i]; if (pPics[i].upper >= pPics[j].upper) common.upper = pPics[j].upper; if (pPics[i].left >= pPics[j].left) common.left = pPics[j].left; if (pPics[i].upper + pPics[i].h < pPics[j].upper + pPics[j].h) common.h = pPics[j].upper + pPics[j].h - pPics[i].upper; if (pPics[i].left + pPics[i].w < pPics[j].left + pPics[j].w) common.w = pPics[j].left + pPics[j].w - pPics[i].left; common.h += pPics[i].upper - common.upper; common.w += pPics[i].left - common.left; pPics[i] = common; DeleteFromPics(j); } } } LastCheck(hCCOM, hCCOM_big, hCPAGE); LDPUMA_FPuts(resFile_pict, " <2 Н Страница ="); LDPUMA_FPuts(resFile_pict, file_name); LDPUMA_FPuts(resFile_pict, " \n"); LDPUMA_FPuts(resFile_pict, " <3 Н Картинки \n"); LDPUMA_FPuts(resFile_pict, " <4 Н После первого прохода \n"); sprintf(tmp_str, " <4 Р %d %d %d \n", nPics, 0, 0); LDPUMA_FPuts(resFile_pict, tmp_str); int32_t min_image_width = (int32_t)(100 * ((double) (pInfo.DPIX + 1) / 300)); int32_t min_image_height = (int32_t)(100 * ((double) (pInfo.DPIY + 1) / 300)); for (i = 0; i < nPics; i++) { if (pPics[i].large & CCOM_LR_KILLED && !(pPics[i].large & CCOM_LR_TAKEN)) { continue; } block.com.type = TYPE_TEXT;//Текст, Картинка, Таблица; block.com.number = 0;//порядковый номер block.com.count = 4; block.com.Flags = 0; block.com.Vertex[0].rx() = pPics[i].left; block.com.Vertex[0].ry() = pPics[i].upper; block.com.Vertex[1].rx() = pPics[i].left + pPics[i].w; block.com.Vertex[1].ry() = pPics[i].upper; block.com.Vertex[2].rx() = pPics[i].left + pPics[i].w; block.com.Vertex[2].ry() = pPics[i].upper + pPics[i].h; block.com.Vertex[3].rx() = pPics[i].left; block.com.Vertex[3].ry() = pPics[i].upper + pPics[i].h; block.alphabet = 0; sprintf(tmp_str, " <4 О 1 %4d %4d %4d %4d %d \n", pPics[i].left, pPics[i].upper, pPics[i].left + pPics[i].w, pPics[i].upper, pPics[i].h); LDPUMA_FPuts(resFile_pict, tmp_str); if (pPics[i].large & CCOM_LR_TAKEN || pPics[i].w < min_image_width && pPics[i].h < min_image_height) { CPAGE_CreateBlock(hCPAGE, POSSIBLE_PICTURES, 0, 0, &block, sizeof(POLY_)); } else { CPAGE_CreateBlock(hCPAGE, TYPE_IMAGE, 0, 0, &block, sizeof(POLY_)); } } LDPUMA_FPuts(resFile_pict, " <4 К После первого прохода \n"); sprintf(tmp_str, "Amount of comps on the first step %i (tmp_comp) \n", tmp_comp); LDPUMA_FPuts(logFile_comp, tmp_str); sprintf(tmp_str, "Amount of pictures on the first step %i (nPics) \n", nPics); LDPUMA_FPuts(logFile_comp, tmp_str); LDPUMA_FPuts(logFile_comp, "*******************************************************\n"); if (pPics != NULL) { free(pPics); pPics = NULL; } nPics = 0; CloseLogRes(); Handle h = NULL; if (!LDPUMA_Skip(hShowFirstAttempt)) { h = NULL; nPics = 0; for (h = CPAGE_GetBlockFirst(hCPAGE, TYPE_IMAGE); h != NULL; h = CPAGE_GetBlockNext(hCPAGE, h, TYPE_IMAGE)) { nPics++; CPAGE_GetBlockData(hCPAGE, h, TYPE_IMAGE, &block, sizeof(block)); rect.left = block.com.Vertex[0].x(); rect.top = block.com.Vertex[0].y(); rect.right = block.com.Vertex[1].x(); rect.bottom = block.com.Vertex[2].y(); LDPUMA_DrawRect(MainWindowD, &rect, 0, color, 2, key); } if (nPics) { LDPUMA_Console("RPIC_Картинки после первого прохода \n"); LDPUMA_WaitUserInput(hShowFirstAttempt, MainWindowD); LDPUMA_DeleteRects(MainWindowD, key); } } if (!LDPUMA_Skip(hShowPossiblePics)) { h = NULL; nPics = 0; for (h = CPAGE_GetBlockFirst(hCPAGE, POSSIBLE_PICTURES); h != NULL; h = CPAGE_GetBlockNext(hCPAGE, h, POSSIBLE_PICTURES)) { nPics++; CPAGE_GetBlockData(hCPAGE, h, POSSIBLE_PICTURES, &block, sizeof(block)); rect.left = block.com.Vertex[0].x(); rect.top = block.com.Vertex[0].y(); rect.right = block.com.Vertex[1].x(); rect.bottom = block.com.Vertex[2].y(); LDPUMA_DrawRect(MainWindowD, &rect, 0, color, 2, key); } if (nPics) { LDPUMA_Console("RPIC_Неуверенные картинки после первого прохода \n"); LDPUMA_WaitUserInput(hShowPossiblePics, MainWindowD); LDPUMA_DeleteRects(MainWindowD, key); } } Handle BlockType = CPAGE_GetInternalType("pic's to letters boxes"); RPIC_Comp_Rect CompRect; if (!LDPUMA_Skip(hShowBigLetters)) { h = NULL; nPics = 0; for (h = CPAGE_GetBlockFirst(hCPAGE, BlockType); h != NULL; h = CPAGE_GetBlockNext(hCPAGE, h, BlockType)) { nPics++; CPAGE_GetBlockData(hCPAGE, h, BlockType, &CompRect, sizeof(CompRect)); rect.left = CompRect.left; rect.top = CompRect.upper; rect.right = CompRect.left + CompRect.w - 1; rect.bottom = CompRect.upper + CompRect.h - 1; LDPUMA_DrawRect(MainWindowD, &rect, 0, color, 2, key); } if (nPics) { LDPUMA_Console("RPIC_Буквицы \n"); LDPUMA_WaitUserInput(hShowBigLetters, MainWindowD); LDPUMA_DeleteRects(MainWindowD, key); } } return TRUE; }
/*---------------------------------------------------------------------------*/ Bool MyReSetLines (void *vLti, int MaxNumLin, Handle hCPage, Handle HoriType , Handle VertType, char *pStr) { int i; uint32_t err32, nTeor;//, nReal; Bool32 nReal;//differ Handle hBlockLine; Handle hBlockLineHor; Handle hBlockLineVer; Handle hBlockLinePrev; void *Hor, *Ver; LinesTotalInfo *pLti; pLti = (LinesTotalInfo *)vLti; /*** Общая информация о линиях ***/ Hor = pLti->Hor.Lns; Ver = pLti->Ver.Lns; pLti->Hor.Lns = (LineInfo *)HoriType; pLti->Ver.Lns = (LineInfo *)VertType; hBlockLine = CPAGE_GetBlockFirst (hCPage, RLINE_BLOCK_TYPE); err32 = CPAGE_GetReturnCode (); if (err32!=0) { sprintf (pStr, "RLTABLE : Ошибка чужой библиотеки - [CPAGE][GetBlockFirst]"); return FALSE; } nTeor = sizeof (LinesTotalInfo); nReal = CPAGE_SetBlockData (hCPage, hBlockLine, RLINE_BLOCK_TYPE, (void *)pLti, nTeor); err32 = CPAGE_GetReturnCode (); // if ((nReal!=nTeor)||(err32!=0)) if (!nReal||(err32!=0)) { sprintf (pStr, "RLTABLE : Ошибка чужой библиотеки - [CPAGE][SetBlockData]"); return FALSE; } pLti->Hor.Lns = (LineInfo *)Hor; pLti->Ver.Lns = (LineInfo *)Ver; /*** Горизонтальные линии ***/ for (i=0; i<pLti->Hor.Cnt; i++) { if (i==0) hBlockLineHor = CPAGE_GetBlockFirst (hCPage, HoriType); else hBlockLineHor = CPAGE_GetBlockNext (hCPage, hBlockLinePrev, HoriType); err32 = CPAGE_GetReturnCode (); if (err32!=0) { if (i==0) sprintf (pStr, "RLTABLE : Ошибка чужой библиотеки - [CPAGE][GetBlockFirst]"); else sprintf (pStr, "RLTABLE : Ошибка чужой библиотеки - [CPAGE][GetBlockNext]"); return FALSE; } nTeor = sizeof (LineInfo); nReal = CPAGE_SetBlockData (hCPage, hBlockLineHor, HoriType, (void *)&(pLti->Hor.Lns[i]), nTeor); err32 = CPAGE_GetReturnCode (); // if ((nReal!=nTeor)||(err32!=0)) if (!nReal||(err32!=0)) { sprintf (pStr, "RLTABLE : Ошибка чужой библиотеки - [CPAGE][SetBlockData]"); return FALSE; } hBlockLinePrev = hBlockLineHor; } /*** Вертикальные линии ***/ for (i=0; i<pLti->Ver.Cnt; i++) { if (i==0) hBlockLineVer = CPAGE_GetBlockFirst (hCPage, VertType); else hBlockLineVer = CPAGE_GetBlockNext (hCPage, hBlockLinePrev, VertType); err32 = CPAGE_GetReturnCode (); if (err32!=0) { if (i==0) sprintf (pStr, "RLTABLE : Ошибка чужой библиотеки - [CPAGE][GetBlockFirst]"); else sprintf (pStr, "RLTABLE : Ошибка чужой библиотеки - [CPAGE][GetBlockNext]"); return FALSE; } nTeor = sizeof (LineInfo); nReal = CPAGE_SetBlockData (hCPage, hBlockLineVer, VertType, (void *)&(pLti->Ver.Lns[i]), nTeor); err32 = CPAGE_GetReturnCode (); // if ((nReal!=nTeor)||(err32!=0)) if (!nReal||(err32!=0)) { sprintf (pStr, "RLTABLE : Ошибка чужой библиотеки - [CPAGE][SetBlockData]"); return FALSE; } hBlockLinePrev = hBlockLineVer; } return TRUE; }