Example #1
0
void CPDF_Annot::GetRect(CPDF_Rect& rect) const
{
    if (m_pAnnotDict == NULL) {
        return;
    }
    rect = m_pAnnotDict->GetRect("Rect");
    rect.Normalize();
}
Example #2
0
void CPWL_NoteItem::RePosChildWnd()
{
	if (this->IsValid())
	{
		ASSERT(m_pSubject != NULL);
		ASSERT(m_pDateTime != NULL);
		ASSERT(m_pContents != NULL);

		CPDF_Rect rcClient = GetClientRect();

		CPDF_Rect rcSubject = rcClient;
		rcSubject.left += POPUP_ITEM_TEXT_INDENT;
		rcSubject.top = rcClient.top;
		rcSubject.right = PWL_MIN(rcSubject.left + m_pSubject->GetContentRect().Width() + 1.0f, rcClient.right);
		rcSubject.bottom = rcSubject.top - m_pSubject->GetContentRect().Height();
		rcSubject.Normalize();
		m_pSubject->Move(rcSubject, TRUE, FALSE);
		m_pSubject->SetVisible(CPWL_Utils::ContainsRect(rcClient, rcSubject));

		CPDF_Rect rcDate = rcClient;
		rcDate.right -= POPUP_ITEM_TEXT_INDENT;
		rcDate.left = PWL_MAX(rcDate.right - m_pDateTime->GetContentRect().Width() - 1.0f, rcSubject.right);
		rcDate.bottom = rcDate.top - m_pDateTime->GetContentRect().Height();
		rcDate.Normalize();
		m_pDateTime->Move(rcDate, TRUE, FALSE);
		m_pDateTime->SetVisible(CPWL_Utils::ContainsRect(rcClient, rcDate));

		CPDF_Rect rcContents = rcClient;
		rcContents.left += 1.0f;
		rcContents.right -= 1.0f;
		rcContents.top = rcDate.bottom - POPUP_ITEM_HEAD_BOTTOM;
		rcContents.bottom += POPUP_ITEM_BOTTOMWIDTH;
		rcContents.Normalize();
		m_pContents->Move(rcContents, TRUE, FALSE);
		m_pContents->SetVisible(CPWL_Utils::ContainsRect(rcClient, rcContents));
	}

	SetClipRect(CPWL_Utils::InflateRect(GetWindowRect(),1.0f));
}
Example #3
0
CFX_AffineMatrix GetMatrix(CPDF_Rect rcAnnot, CPDF_Rect rcStream, CFX_AffineMatrix matrix)
{
	if(rcStream.IsEmpty())
		return CFX_AffineMatrix();
	
	matrix.TransformRect(rcStream);
	rcStream.Normalize();
	
	FX_FLOAT a = rcAnnot.Width()/rcStream.Width();
	FX_FLOAT d = rcAnnot.Height()/rcStream.Height();
	
	FX_FLOAT e = rcAnnot.left - rcStream.left * a;
	FX_FLOAT f = rcAnnot.bottom - rcStream.bottom * d;
	return CFX_AffineMatrix(a, 0, 0, d, e, f);
}
Example #4
0
void CPWL_Note::RePosNoteChildren()
{
	if (m_bResizing) return;

	m_bResizing = TRUE;

	if (this->IsValid())
	{
		ASSERT(m_pSubject != NULL);
		ASSERT(m_pDateTime != NULL);
		ASSERT(m_pContents != NULL);
		ASSERT(m_pAuthor != NULL);
		ASSERT(m_pCloseBox != NULL);
		ASSERT(m_pIcon != NULL);
		ASSERT(m_pLBBox != NULL);
		ASSERT(m_pRBBox != NULL);
		ASSERT(m_pContentsBar != NULL);
		ASSERT(m_pOptions != NULL);

		CPDF_Rect rcClient = GetClientRect();

		CPDF_Rect rcIcon = rcClient;
		rcIcon.top -= 2.0f;
		rcIcon.right = rcIcon.left + 14.0f;
		rcIcon.bottom = rcIcon.top - 14.0f;
		rcIcon.Normalize();
		m_pIcon->Move(rcIcon, TRUE, FALSE);
		m_pIcon->SetVisible(CPWL_Utils::ContainsRect(rcClient, rcIcon));

		CPDF_Rect rcCloseBox = rcClient;
		rcCloseBox.right -= 1.0f;
		rcCloseBox.top -= 1.0f;
		rcCloseBox.left = rcCloseBox.right - 14.0f;
		rcCloseBox.bottom = rcCloseBox.top - 14.0f;
		rcCloseBox.Normalize();
		m_pCloseBox->Move(rcCloseBox, TRUE, FALSE);
		m_pCloseBox->SetVisible(CPWL_Utils::ContainsRect(rcClient, rcCloseBox));

		CPDF_Rect rcDate = rcClient;
		rcDate.right = rcCloseBox.left - POPUP_ITEM_TEXT_INDENT;
		rcDate.left = PWL_MAX(rcDate.right - m_pDateTime->GetContentRect().Width() - 1.0f, rcIcon.right + 1.0f);
		rcDate.top = rcClient.top - 2.0f;
		rcDate.bottom = rcDate.top - m_pDateTime->GetContentRect().Height();
		rcDate.Normalize();
		m_pDateTime->Move(rcDate, TRUE, FALSE);
		m_pDateTime->SetVisible(CPWL_Utils::ContainsRect(rcClient, rcDate));

		CPDF_Rect rcSubject = rcClient;
		rcSubject.top = rcClient.top - 2.0f;
		rcSubject.left = rcIcon.right + POPUP_ITEM_TEXT_INDENT;
		rcSubject.right = PWL_MIN(rcSubject.left + m_pSubject->GetContentRect().Width() + 1.0f, rcDate.left - 1.0f);
		rcSubject.bottom = rcSubject.top - m_pSubject->GetContentRect().Height();
		rcSubject.Normalize();
		m_pSubject->Move(rcSubject, TRUE, FALSE);	
		m_pSubject->SetVisible(CPWL_Utils::ContainsRect(rcClient, rcSubject));

		CPDF_Rect rcOptions = rcClient;
		rcOptions.left = PWL_MAX(rcOptions.right - m_pOptions->GetContentRect().Width(), rcIcon.right + 1.0f);
		rcOptions.top = rcSubject.bottom - 4.0f;
		rcOptions.bottom = rcOptions.top - m_pOptions->GetContentRect().Height();
		rcOptions.Normalize();
		m_pOptions->Move(rcOptions, TRUE, FALSE);
		m_pOptions->SetVisible(CPWL_Utils::ContainsRect(rcClient, rcOptions));

		CPDF_Rect rcAuthor = rcClient;
		rcAuthor.top = rcSubject.bottom - 4.0f;
		rcAuthor.left = rcSubject.left;
		rcAuthor.right = PWL_MIN(rcSubject.left + m_pAuthor->GetContentRect().Width() + 1.0f, rcOptions.left - 1.0f);
		rcAuthor.bottom = rcAuthor.top - m_pAuthor->GetContentRect().Height();
		rcAuthor.Normalize();
		m_pAuthor->Move(rcAuthor, TRUE, FALSE);
		m_pAuthor->SetVisible(CPWL_Utils::ContainsRect(rcClient, rcAuthor));

		CPDF_Rect rcLBBox = rcClient;
		rcLBBox.top = rcLBBox.bottom + 7.0f;
		rcLBBox.right = rcLBBox.left + 7.0f;
		rcLBBox.Normalize();
		m_pLBBox->Move(rcLBBox, TRUE, FALSE);
		m_pLBBox->SetVisible(CPWL_Utils::ContainsRect(rcClient, rcLBBox));

		CPDF_Rect rcRBBox = rcClient;
		rcRBBox.top = rcRBBox.bottom + 7.0f;
		rcRBBox.left = rcRBBox.right - 7.0f;
		rcRBBox.Normalize();
		m_pRBBox->Move(rcRBBox, TRUE, FALSE);
		m_pRBBox->SetVisible(CPWL_Utils::ContainsRect(rcClient, rcRBBox));

		CPDF_Rect rcContents = rcClient;
		rcContents.top = rcAuthor.bottom - POPUP_ITEM_HEAD_BOTTOM;
		rcContents.left += 3.0f;
		rcContents.right -= 3.0f;
		if (m_pContentsBar->IsVisible())
			rcContents.right -= PWL_SCROLLBAR_WIDTH;
		rcContents.bottom += 14.0f;
		rcContents.Normalize();
		m_pContents->Move(rcContents, FALSE, FALSE);
		m_pContents->SetVisible(CPWL_Utils::ContainsRect(rcClient, rcContents));

		CPDF_Rect rcContentsBar = rcContents;
		rcContentsBar.right = rcClient.right - 3.0f;
		rcContentsBar.left = rcContentsBar.right - PWL_SCROLLBAR_WIDTH;
		rcContentsBar.Normalize();
		m_pContentsBar->Move(rcContentsBar, TRUE, FALSE);
		
		m_rcCaption = rcClient;
		m_rcCaption.bottom = rcContents.top;
	}

	m_bResizing = FALSE;
}
Example #5
0
DLLEXPORT int STDCALL FPDFPage_Flatten( FPDF_PAGE page, int nFlag)
{
	if (!page)
	{
		return FLATTEN_FAIL;
	}

	CPDF_Page * pPage = (CPDF_Page*)( page );
	CPDF_Document * pDocument = pPage->m_pDocument;
	CPDF_Dictionary * pPageDict = pPage->m_pFormDict;
	
	if ( !pDocument || !pPageDict )
	{
		return FLATTEN_FAIL;
	}

	CPDF_ObjectArray ObjectArray;
	CPDF_RectArray  RectArray;

	int iRet = FLATTEN_FAIL;
	iRet = ParserAnnots( pDocument, pPageDict, &RectArray, &ObjectArray, nFlag);
	if (iRet == FLATTEN_NOTINGTODO)
	{
		return FLATTEN_NOTINGTODO;
	}else if (iRet == FLATTEN_FAIL)
	{
		return FLATTEN_FAIL;
	}
	
	CPDF_Rect rcOriginalCB;
	CPDF_Rect rcMerger = CalculateRect( &RectArray );
	CPDF_Rect rcOriginalMB = pPageDict->GetRect("MediaBox");

	if (pPageDict->KeyExist("CropBox"))
		rcOriginalMB = pPageDict->GetRect("CropBox");
	
	if (rcOriginalMB.IsEmpty()) 	
	{
		rcOriginalMB = CPDF_Rect(0.0f, 0.0f, 612.0f, 792.0f);
	}
	
	rcMerger.left = rcMerger.left < rcOriginalMB.left? rcOriginalMB.left : rcMerger.left;
	rcMerger.right = rcMerger.right > rcOriginalMB.right? rcOriginalMB.right : rcMerger.right;
	rcMerger.top = rcMerger.top > rcOriginalMB.top? rcOriginalMB.top : rcMerger.top;
	rcMerger.bottom = rcMerger.bottom < rcOriginalMB.bottom? rcOriginalMB.bottom : rcMerger.bottom;
	
	if (pPageDict->KeyExist("ArtBox"))
		rcOriginalCB = pPageDict->GetRect("ArtBox");
	else
		rcOriginalCB = rcOriginalMB;

	if (!rcOriginalMB.IsEmpty())
	{
		CPDF_Array* pMediaBox = FX_NEW CPDF_Array();	

		pMediaBox->Add(FX_NEW CPDF_Number(rcOriginalMB.left));
		pMediaBox->Add(FX_NEW CPDF_Number(rcOriginalMB.bottom));
		pMediaBox->Add(FX_NEW CPDF_Number(rcOriginalMB.right));
		pMediaBox->Add(FX_NEW CPDF_Number(rcOriginalMB.top));

		pPageDict->SetAt("MediaBox",pMediaBox);
	}
	
	if (!rcOriginalCB.IsEmpty())
	{
		CPDF_Array* pCropBox = FX_NEW CPDF_Array();
		pCropBox->Add(FX_NEW CPDF_Number(rcOriginalCB.left));
		pCropBox->Add(FX_NEW CPDF_Number(rcOriginalCB.bottom));
		pCropBox->Add(FX_NEW CPDF_Number(rcOriginalCB.right));
		pCropBox->Add(FX_NEW CPDF_Number(rcOriginalCB.top));
		pPageDict->SetAt("ArtBox", pCropBox);
	}

	CPDF_Dictionary* pRes = NULL;
	pRes = pPageDict->GetDict("Resources");
	if (!pRes)
	{
		pRes = FX_NEW CPDF_Dictionary;
		pPageDict->SetAt( "Resources", pRes );
	}

	CPDF_Stream* pNewXObject = FX_NEW CPDF_Stream(NULL, 0, FX_NEW CPDF_Dictionary);
	FX_DWORD dwObjNum = pDocument->AddIndirectObject(pNewXObject);
	CPDF_Dictionary* pPageXObject = pRes->GetDict("XObject");
	if (!pPageXObject)
	{
		pPageXObject = FX_NEW CPDF_Dictionary;
		pRes->SetAt("XObject", pPageXObject);
	}

	CFX_ByteString key = "";
	int nStreams = ObjectArray.GetSize();

	if (nStreams > 0)
	{
		for (int iKey = 0; /*iKey < 100*/; iKey++)
		{
			char sExtend[5] = {0};
			FXSYS_itoa(iKey, sExtend, 10);
			key = CFX_ByteString("FFT") + CFX_ByteString(sExtend);

			if (!pPageXObject->KeyExist(key))
				break;
		}
	}

	SetPageContents(key, pPageDict, pDocument);

	CPDF_Dictionary* pNewXORes = NULL;

	if (!key.IsEmpty())
	{
		pPageXObject->SetAtReference(key, pDocument, dwObjNum);
		CPDF_Dictionary* pNewOXbjectDic = pNewXObject->GetDict();
		pNewXORes = FX_NEW CPDF_Dictionary;
		pNewOXbjectDic->SetAt("Resources", pNewXORes);
		pNewOXbjectDic->SetAtName("Type", "XObject");
		pNewOXbjectDic->SetAtName("Subtype", "Form");
		pNewOXbjectDic->SetAtInteger("FormType", 1);
		pNewOXbjectDic->SetAtName("Name", "FRM");
		CPDF_Rect rcBBox = pPageDict->GetRect("ArtBox"); 
		pNewOXbjectDic->SetAtRect("BBox", rcBBox);
	}
	
	for (int i = 0; i < nStreams; i++)
	{
		CPDF_Dictionary* pAnnotDic = ObjectArray.GetAt(i);
		if (!pAnnotDic)continue;

		CPDF_Rect rcAnnot = pAnnotDic->GetRect("Rect");
		rcAnnot.Normalize();

		CFX_ByteString sAnnotState = pAnnotDic->GetString("AS");
		CPDF_Dictionary* pAnnotAP = pAnnotDic->GetDict("AP");
		if (!pAnnotAP)continue;

		CPDF_Stream* pAPStream = pAnnotAP->GetStream("N");
		if (!pAPStream)
		{
			CPDF_Dictionary* pAPDic = pAnnotAP->GetDict("N");
			if (!pAPDic)continue;

			if (!sAnnotState.IsEmpty())
			{
				pAPStream = pAPDic->GetStream(sAnnotState);
			}
			else
			{
				FX_POSITION pos = pAPDic->GetStartPos();
				if (pos)
				{
					CFX_ByteString sKey;
					CPDF_Object* pFirstObj = pAPDic->GetNextElement(pos, sKey);
					if (pFirstObj)
					{
						if (pFirstObj->GetType() == PDFOBJ_REFERENCE)
							pFirstObj = pFirstObj->GetDirect();
						
						if (pFirstObj->GetType() != PDFOBJ_STREAM)
							continue;

						pAPStream = (CPDF_Stream*)pFirstObj;
					}
				}
			}
		}

		if (!pAPStream)continue;

		CPDF_Dictionary* pAPDic = pAPStream->GetDict();
		CFX_AffineMatrix matrix = pAPDic->GetMatrix("Matrix");

		CPDF_Rect rcStream;
		if (pAPDic->KeyExist("Rect"))
			rcStream = pAPDic->GetRect("Rect");
		else if (pAPDic->KeyExist("BBox"))
			rcStream = pAPDic->GetRect("BBox");

		if (rcStream.IsEmpty())continue;

		CPDF_Object* pObj = pAPStream;

		if (pObj)
		{		
			CPDF_Dictionary* pObjDic = pObj->GetDict();
			if (pObjDic)
			{
				pObjDic->SetAtName("Type", "XObject");
				pObjDic->SetAtName("Subtype", "Form");
			}
		}

		CPDF_Dictionary* pXObject = pNewXORes->GetDict("XObject");
		if (!pXObject)
		{
			pXObject = FX_NEW CPDF_Dictionary;
			pNewXORes->SetAt("XObject", pXObject);
		}

		CFX_ByteString sFormName;
		sFormName.Format("F%d", i);
		FX_DWORD dwObjNum = pDocument->AddIndirectObject(pObj);
		pXObject->SetAtReference(sFormName, pDocument, dwObjNum);

		CPDF_StreamAcc acc;
		acc.LoadAllData(pNewXObject);

		FX_LPCBYTE pData = acc.GetData();
		CFX_ByteString sStream(pData, acc.GetSize());
		CFX_ByteString sTemp;

		if (matrix.IsIdentity())
		{
			matrix.a = 1.0f;
			matrix.b = 0.0f;
			matrix.c = 0.0f;
			matrix.d = 1.0f;
			matrix.e = 0.0f;
			matrix.f = 0.0f;
		}

		CFX_AffineMatrix m = GetMatrix(rcAnnot, rcStream, matrix);
		sTemp.Format("q %f 0 0 %f %f %f cm /%s Do Q\n", m.a, m.d, m.e, m.f, sFormName.c_str());
		sStream += sTemp;

		pNewXObject->SetData((FX_LPCBYTE)sStream, sStream.GetLength(), FALSE, FALSE);
	}
	pPageDict->RemoveAt( "Annots" );

	ObjectArray.RemoveAll();
	RectArray.RemoveAll();

	return FLATTEN_SUCCESS;
}