Beispiel #1
0
void CRtfWord::calcBRect() {
    PAGEINFO PageInfo;
    Handle hCPAGE = CPAGE_GetHandlePage(CPAGE_GetCurrentPage());
    if (!hCPAGE)
        throw Exception("[CRtfWord::calcBRect] CPAGE_GetHandlePage failed");

    GetPageInfo(hCPAGE, &PageInfo);

    Rect tmp = charsBRect();
    rotateRect(tmp, PageInfo.Angle, PageInfo.Width, PageInfo.Height);
    brect_ = tmp;
}
Beispiel #2
0
size_t GetPictCount() {
    size_t res = 0;
    uint32_t NumberPage = CPAGE_GetCurrentPage();
    Handle h_Page = CPAGE_GetHandlePage(NumberPage);
    Handle h_Pict = CPAGE_PictureGetFirst(h_Page);

    while (h_Pict) {
        res++;
        h_Pict = CPAGE_PictureGetNext(h_Page, h_Pict);
    }

    return res;
}
Beispiel #3
0
/////////////////////////////////////////////////////////////////////////////
//                    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;
}
Beispiel #5
0
//###########################################
CPAGE_FUNC(Bool32)  CPAGE_SetCurrentPage(uint32_t page)
{
	PROLOG;
	Bool32 rc = TRUE;
	if( page>=CPAGE_GetCountPage() ||
		page == (uint32_t)-1)
	{
		SetReturnCode_cpage(IDS_ERR_NOPAGE);
		rc = FALSE;
	}
	else
		hCurPage = CPAGE_GetHandlePage(page);

	EPILOG;
	return rc;
}
Beispiel #6
0
/////////////////////////////////////////////////////////////////////////////
//                    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;
}
Beispiel #7
0
Rect GetPictRect(uint NumberPict, uint32_t * UserNumber) {
    uint PictCount = 0;

    uint NumberPage = CPAGE_GetCurrentPage();
    Handle h_Page = CPAGE_GetHandlePage(NumberPage);
    Handle h_Pict = CPAGE_PictureGetFirst(h_Page);

    while (h_Pict && PictCount < NumberPict) {
        PictCount++;
        h_Pict = CPAGE_PictureGetNext(h_Page, h_Pict);
    }

    if (!h_Pict)
        throw std::runtime_error("[GetPictRect] can't get picture");

    *UserNumber = (uint32_t) CPAGE_GetBlockUserNum(h_Page, h_Pict);

    Point Lr, Wh;
    if (CPAGE_PictureGetPlace(h_Page, h_Pict, 0, &Lr, &Wh))
        return Rect(Lr - TemplateOffset, Wh.x(), Wh.y());
    else
        throw std::runtime_error("[GetPictRect] CPAGE_PictureGetPlace failed");
}
Beispiel #8
0
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, &lti, 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);

}
Beispiel #9
0
/////////////////////////////////////////////////////////////////////////////
//                    CreateInternalFileForFormatter
Bool CreateInternalFileForFormatter(FILE *pIFName)
{
 Bool         FReturnCode = TRUE;
 CSTR_line    line;
 CFPage       Page;
 PAGEINFO     PageInfo;

 Handle hCPAGE = CPAGE_GetHandlePage( CPAGE_GetCurrentPage());
 GetPageInfo(hCPAGE,&PageInfo);

 if(PageInfo.X && PageInfo.Y){
	 TemplateOffset.x = PageInfo.X;
     TemplateOffset.y = PageInfo.Y;
 }
 else{
	 TemplateOffset.x = 0;
     TemplateOffset.y = 0;
 }

 //Создание массива текстовых фрагментов
 Page.FragmentsArray.clear();
 Page.CreateArray_For_TextFragments( );

 //Чтение информации из хранилиша
 line = CSTR_FirstLine (1);

 while(line)
 {
	 if(CheckComingLine(&line) && Page.CheckComingLine_For_TextFragments(&line))
  	    Page.ProcessingComingLine(&line);
     line = CSTR_NextLine ( line, 1 );
 }

 CountPict  = GetPictCount();
// CountTable = GetTablCount();

 if(Page.Count.Chars>32000){
    ExFlagMode = TRUE;
 }

 if(!(Page.Count.Frags + (int)CountPict + (int)CountTable)){
	if(CreateEmptyRtfFile()<0){
 	   SetReturnCode_rfrmt(IDS_ERR_SIZEFRAGMENT);
 	   return FALSE;
    }
	return TRUE;
 }

 //Создания внутреннего файла для форматирования
 uint16_t  DistanceBetweenLeftMargin = 15;
 uint16_t  DistanceBetweenTopMargin  =  5;
 Page.m_wDpi             = (uint16_t)PageInfo.DPIX;
 PageIncline2048         = PageInfo.Incline2048;

 InternalRect VRect;
 fwrite(&Page.m_wDpi,              sizeof(uint16_t),1,pIFName); // ScanResolution
 fwrite(&Page.Count.Frags,         sizeof(uint16_t),1,pIFName); // число колонок
 fwrite(&Page.Count.Chars,         sizeof(uint16_t),1,pIFName); // число знакомест  in all page
 fwrite(&Page.Count.Words,         sizeof(uint16_t),1,pIFName); // число слов
 fwrite(&Page.Count.Strings,       sizeof(uint16_t),1,pIFName); // число строк
 fwrite(&DistanceBetweenLeftMargin,sizeof(uint16_t),1,pIFName); // distance between left margin letters- neighdoors from one word
 fwrite(&DistanceBetweenTopMargin, sizeof(uint16_t),1,pIFName); // distance between top margin

 CFragment* cFrag;
 CFString*  cString;
 CWord*     cWord;
 CChar*     cChar;

 // Processing Fragments
 for(int iPage=0; iPage < Page.Count.Frags; iPage++){
    cFrag = (CFragment*)Page.m_arFrags[iPage];
    VCopyRect( &VRect, &cFrag->m_rectFrag);
	if(CheckRect( &VRect ) == FALSE)
	  FReturnCode = FALSE ;
    fwrite(&VRect , sizeof( InternalRect ),1,pIFName);
    fwrite(&cFrag->m_wStringsCount, sizeof( uint16_t  ),1,pIFName);
    fwrite(&cFrag->m_wUserNumber  , sizeof( uint32_t ),1,pIFName);
    fwrite(&cFrag->m_Flags        , sizeof( uint32_t ),1,pIFName);

   // Processing Strings
   for(int iFrag=0; iFrag < cFrag->m_wStringsCount; iFrag++){
      cString = (CFString*)cFrag->m_arStrings[iFrag];
      VCopyRect( &VRect, &cString->m_rectBaseLine );
      fwrite( &VRect, sizeof( InternalRect ),1,pIFName);
      VCopyRect( &VRect, &cString->m_rectString );
      fwrite( &VRect, sizeof( InternalRect ),1,pIFName);
      fwrite( &cString->m_wWordsCount,  sizeof( uint16_t ),1,pIFName);
	  fwrite( &cString->S_Flags,  sizeof( uint32_t ),1,pIFName); //NEGA_STR
      // Processing Words
      for(int iString=0; iString < cString->m_wWordsCount; iString++){
         cWord = (CWord*)cString->m_arWords[iString];
         fwrite( &cWord->m_wCharsCount,   sizeof( uint16_t ),1,pIFName);
         fwrite( &cWord->m_wFontNumber,   sizeof( uint16_t ),1,pIFName);
         fwrite( &cWord->m_wFontPointSize,sizeof( uint16_t ),1,pIFName);

         // Processing Letters
         for(int iWord=0; iWord < cWord->m_wCharsCount; iWord++){
            cChar = (CChar*)cWord->m_arChars[iWord];
            VCopyRect( &VRect, &cChar->m_rectChar );
            fwrite( &VRect , sizeof( InternalRect ),1,pIFName);
            VCopyRect( &VRect, &cChar->m_RealRectChar );
            fwrite( &VRect , sizeof( InternalRect ),1,pIFName);
            fwrite( &cChar->m_wCountAlt ,    sizeof( uint16_t ),1,pIFName);
			for (int iAlt=0;iAlt<cChar->m_wCountAlt&&iAlt<REC_MAX_VERS;iAlt++)
			{
				fwrite( &cChar->m_chrVersions[iAlt].m_bChar ,sizeof( char ),1,pIFName);
				fwrite( &cChar->m_chrVersions[iAlt].m_bProbability , sizeof( char ),1,pIFName);
			}
            fwrite( &cChar->m_blanguage ,    sizeof( char ),1,pIFName);
            fwrite( &cChar->m_bFlg_spell_nocarrying, sizeof( char ),1,pIFName);
            fwrite( &cChar->m_bFlg_cup_drop ,sizeof( char ),1,pIFName);
            fwrite( &cChar->m_bFlg_spell,    sizeof( char ),1,pIFName);
            fwrite( &cChar->m_wFontNumber ,  sizeof( char ),1,pIFName);
         }
      }
   }
 }

 return	FReturnCode;
}
Beispiel #10
0
Bool32 ReadRoots(Handle hCCOM)
{
	CCOM_comp * comp = NULL;
	Handle		pPage;
	PAGEINFO	pInfo;
	uint32_t i;
	int max_h=50;

	exthCCOM = hCCOM;
    RootsFreeData ();
	nRoots = 0;


	pPage = CPAGE_GetHandlePage(CPAGE_GetCurrentPage( ));
	CPAGE_GetPageData( pPage, PT_PAGEINFO, (void*)&pInfo, sizeof(pInfo));

	max_h=(max_h*(pInfo.DPIY+1))/300;
	nBigLetters = 0;
	pBigLetters = NULL;
	FillBigLetters(hCCOM, pPage);
	FillPicsInTables(hCCOM, pPage);




	//**************************************

	for(i=0;i<MaxHeightOfLetter;i++)
	{
		pBlockHystogram[i] = 0;
	}


	comp = CCOM_GetFirst(hCCOM,NULL);
	int h;
    while (comp)
    {
		h=comp->h;
		if((h > MinHeightOfLetter) && (h < MaxHeightOfLetter))
		{
			nComps++;
			pBlockHystogram[h]++;
		}


		if(comp->scale>1)
		{
			if(comp->scale>2||h>max_h)
			{
			 if(IsNotBigLetter(comp))
				 goto lNextComp;
			}
		}

        AddRoot(comp, TRUE)
			;
	lNextComp:
			comp = CCOM_GetNext(comp,NULL);
    }


	//*********** Rom 08-02-99 *************

	nBigLetters = 0;
	if(pBigLetters!=NULL)
	{
		free(pBigLetters);
		pBigLetters = NULL;
	}


	//**************************************


    return (TRUE);

}
Beispiel #11
0
bool WritePict(uint32_t IndexPict, SectorInfo * SectorInfo, Bool OutPutTypeFrame) {
    uint32_t PictNumber = 0;
    Point RtfLt;
    CPAGE_PICTURE pict;
    uint32_t NumberPage = CPAGE_GetCurrentPage();
    Handle h_Page = CPAGE_GetHandlePage(NumberPage);
    Handle h_Pict = CPAGE_PictureGetFirst(h_Page);

    while (h_Pict) {
        if (++PictNumber > IndexPict)
            break;

        h_Pict = CPAGE_PictureGetNext(h_Page, h_Pict);
    }

    if (!h_Pict)
        return false;

    PAGEINFO pinfo;

    if (!GetPageInfo(h_Page, &pinfo))
        return false;

    CIMAGE_InfoDataInGet in;
    BitmapInfoHeader image_info;
    Point Lr;
    Point Wh;
    Point LrN;
    Point WhN;

    if (CIMAGE_GetImageInfo(pinfo.szImageName, &image_info) == FALSE)
        return false;

    CPAGE_PictureGetPlace(h_Page, h_Pict, 0, &Lr, &Wh);
    CPAGE_PictureGetPlace(h_Page, h_Pict, -pinfo.Incline2048, &LrN, &WhN);
    Lr.rx() -= TemplateOffset.x();
    Lr.ry() -= TemplateOffset.y();
    int FrameOffset = abs(WhN.x() - Wh.x());

    if (Lr.x() < 0)
        FrameOffset += abs(Lr.x());

    // Получим картинку из исходного изображения задав ее контур
    //определяем размер маски

    if (!CPAGE_PictureGetPlace(h_Page, h_Pict, -pinfo.Incline2048, &Lr, &Wh))
        return false;

    Bool rc = TRUE;

    //piter : Корректируем координаты из-за повернута страницы.
    switch (pinfo.Angle) {
    case 0:
        in.dwX = Lr.x();
        in.dwY = Lr.y();
        in.dwWidth = Wh.x();
        in.dwHeight = Wh.y();
        break;
    case 270:
        in.dwX = pinfo.Width - (Wh.y() + Lr.y());
        in.dwY = Lr.x();
        in.dwWidth = Wh.y();
        in.dwHeight = Wh.x();
        break;
    case 180:
        in.dwX = pinfo.Width - (Wh.x() + Lr.x());
        in.dwY = pinfo.Height - (Wh.y() + Lr.y());
        in.dwWidth = Wh.x();
        in.dwHeight = Wh.y();
        break;
    case 90:
        in.dwX = Lr.y();
        in.dwY = pinfo.Height - (Wh.x() + Lr.x());
        in.dwWidth = Wh.y();
        in.dwHeight = Wh.x();
        break;
    }

    // end piter
    BitmapPtr pOutDIB = NULL;

    if (!CIMAGE_GetDIBData(PUMA_IMAGE_USER, Rect(in.dwX, in.dwY, in.dwWidth, in.dwHeight), NULL, &pOutDIB)) {
        Debug() << "[WritePict] CIMAGE_GetDIBData failed: " << PUMA_IMAGE_USER << "\n";
        return false;
    }

    // Соберем изображение
    const char * szTurnName = "RFRMT:TurnPicture";
    const char * szPictName = "RFRMT:Picture";
    const char * szRotateName = "RFRMT:RotatePicture";
    const char * lpName = szPictName;

    if (CIMAGE_AddImage(szPictName, (BitmapPtr) pOutDIB)) {
        switch (pinfo.Angle) {
        case 90:
            rc = RIMAGE_Turn(szPictName, szTurnName, RIMAGE_TURN_90);
            CIMAGE_RemoveImage(lpName);
            lpName = szTurnName;
            break;
        case 180:
            rc = RIMAGE_Turn(szPictName, szTurnName, RIMAGE_TURN_180);
            CIMAGE_RemoveImage(lpName);
            lpName = szTurnName;
            break;
        case 270:
            rc = RIMAGE_Turn(szPictName, szTurnName, RIMAGE_TURN_270);
            CIMAGE_RemoveImage(lpName);
            lpName = szTurnName;
            break;
        }

        if (!rc) {
            Debug() << "[WritePict] RIMAGE_Turn failed";
            rc = FALSE;
        }
    } else {
        Debug() << "[WritePict] CIMAGE_WriteDIB failed: " << szPictName << "\n";
    }

    // Довернем изображение на малый угол.
    if (!RIMAGE_Rotate(lpName, szRotateName, pinfo.Incline2048, 2048)) {
        Debug() << "[WritePict] RIMAGE_Rotate failed\n";
        rc = FALSE;
    } else {
        CIMAGE_RemoveImage(lpName);
        lpName = szRotateName;
    }

    // Маскируем полученное изображение
    Point ptLt, ptWh;

    if (rc && CPAGE_PictureGetPlace(h_Page, h_Pict, 0, &ptLt, &ptWh)) {
        if (pinfo.Incline2048 >= 0) {
            in.dwX = ptWh.y() * pinfo.Incline2048 / 2048;
            in.dwY = 0;
        } else {
            in.dwX = 0;
            //  Beg of Almi Corr
            //                      in.dwY = ptWh.x*pinfo.Incline2048/2048;
            in.dwY = (-ptWh.x() * pinfo.Incline2048 / 2048);
            //  End of Almi Corr
        }

        if (!RIMAGE_RotatePoint(lpName, in.dwX, in.dwY, (int32_t *) &in.dwX,
                (int32_t *) &in.dwY)) {
            in.dwX = 0;
            in.dwY = 0;
        }

        in.dwWidth = ptWh.x();
        in.dwHeight = ptWh.y();
        in.wByteWidth = (unsigned short) ((in.dwWidth + 7) / 8); //?
        // Получим размер маски
        uint32_t nSize = 0;

        if (CPAGE_PictureGetMask(h_Page, h_Pict, 0, NULL, &nSize)) {
            char * lpMask = (char*) malloc(sizeof(in) + nSize);

            if (lpMask) {// Получаем маску
                *(CIMAGE_InfoDataInGet*) lpMask = in;

                if (CPAGE_PictureGetMask(h_Page, h_Pict, 0, lpMask + sizeof(in), &nSize)) {
                     cf::BitMask bit_mask(0, 0, (uchar*) lpMask + sizeof(in));

                    if (!CIMAGE_GetDIBData(lpName, Rect(in.dwX, in.dwY, in.dwWidth, in.dwHeight), &bit_mask, &pOutDIB)) {
                        Debug() << "CIMAGE_GetDIBData failed\n";
                        rc = FALSE;
                    }
                } else {
                    Debug() << "PAGE_PictureGetMask failed\n";
                    rc = FALSE;
                }

                free(lpMask);
            }
        } else {
            Debug() << "PAGE_PictureGetMask() failed\n";
            rc = FALSE;
        }
    }

    BlockElement * hPrevObject = NULL;

    if (rc) {
        CTDIB * pTmpDIB = new CTDIB;
        pTmpDIB->setBitmap(pOutDIB);
        cf::Size pictGoal;
        pictGoal.rwidth() = pTmpDIB->lineWidth();
        pictGoal.rheight() = pTmpDIB->linesNumber();
        int32_t iDIBSize = pTmpDIB->dibSize();
        delete pTmpDIB;
        Rect indent;
        Rect playout;
        Lr.rx() = MAX(0, Lr.x());
        Lr.ry() = MAX(0, Lr.y());

        Rect slayout;
        slayout.rleft() = Lr.x();
        slayout.rright() = Lr.x() + Wh.x();
        slayout.rtop() = Lr.y();
        slayout.rbottom() = Lr.y() + Wh.y();
        hPrevObject = SectorInfo->hObject;

        if (SectorInfo->FlagInColumn || (OutPutTypeFrame && SectorInfo->FlagFictiveParagraph)) {
            CEDParagraph * par = SectorInfo->hEDSector->createParagraph(SectorInfo->hColumn,
                    ALIGN_NONE, indent, SectorInfo->userNum, -1, playout);
            par->addLine(new CEDLine(NULL, false, 6));
            SectorInfo->FlagFictiveParagraph = FALSE;
        }

        if (RfrmtOptions::useNone() || SectorInfo->CountFragments == 1)
            SectorInfo->hObject = SectorInfo->hColumn;
        else {
            if (SectorInfo->FlagInColumn == TRUE) {
                Rect EdFragmRect;
                EdFragmRect.setLeft(MAX(0, SectorInfo->OffsetFromColumn.x()));
                EdFragmRect.setTop(MAX(0, SectorInfo->OffsetFromColumn.y()));
                EdFragmRect.setWidth(MAX(0, Wh.x() - FrameOffset));
                EdFragmRect.setHeight(Wh.y());

                CEDFrame * frame = new CEDFrame(NULL, CEDFrame::HPOS_COLUMN,
                        CEDFrame::VPOS_PARAGRAPH);
                frame->setBoundingRect(EdFragmRect);
                SectorInfo->hColumn->addElement(frame);
                SectorInfo->hObject = frame;
            } else {
                Rect EdFragmRect;
                EdFragmRect.setLeft(Lr.x() - SectorInfo->Offset.x());
                EdFragmRect.setTop(Lr.y() - SectorInfo->Offset.y());
                EdFragmRect.setWidth(MAX(0, Wh.x() - FrameOffset));
                EdFragmRect.setHeight(Wh.y());
                CEDFrame * frame = new CEDFrame(NULL, CEDFrame::HPOS_COLUMN,
                        CEDFrame::VPOS_PARAGRAPH);
                frame->setBoundingRect(EdFragmRect);
                frame->dxfrtextx = 0;
                frame->dxfrtexty = 0;
                SectorInfo->hColumn->addElement(frame);
                SectorInfo->hObject = frame;
            }
        }

        CEDParagraph * ced_par = SectorInfo->hEDSector->createParagraph(SectorInfo->hObject,
                ALIGN_NONE, indent, SectorInfo->userNum, -1, playout);
        CEDLine * ced_line = new CEDLine;
        // TODO hard coded font value
        ced_line->setDefaultFontHeight(6);

        CEDPicture * ced_pict = new CEDPicture();
        ced_pict->setBoundingRect(slayout);
        ced_pict->setPictureNumber(IndexPict);
        ced_pict->setAlign(ED_ALIGN_MIDDLE);
        uchar * img_data = new uchar[iDIBSize];
        memcpy(img_data, pOutDIB, iDIBSize);
        ced_pict->setImage(new Image(img_data, iDIBSize, Image::AllocatorNew));
        ced_pict->image()->setSize(slayout.size());

        ced_line->addElement(ced_pict);
        ced_par->addLine(ced_line);
    }

    // piter
    // освобождает память переданную по pOutDIB
    CIMAGE_RemoveImage(lpName);
    CIMAGE_FreeCopiedDIB(pOutDIB);
    // end piter
    SectorInfo->hObject = hPrevObject;
    return TRUE;
}