Example #1
0
void
wxPdfParser::GetPageContent(wxPdfObject* contentRef, wxArrayPtrVoid& contents)
{
  int type = contentRef->GetType();
  if (type == OBJTYPE_INDIRECT)
  {
    wxPdfObject* content = ResolveObject(contentRef);
    if (content->GetType() == OBJTYPE_ARRAY)
    {
      GetPageContent(content, contents);
      delete content;
    }
    else
    {
      contents.Add(content);
    }
  }
  else if (type == OBJTYPE_ARRAY)
  {
    wxPdfArray* contentArray = (wxPdfArray*) contentRef;
    size_t n = contentArray->GetSize();
    size_t j;
    for (j = 0; j < n; j++)
    {
      GetPageContent(contentArray->Get(j), contents);
    }
  }
}
Example #2
0
//
//	Common routine for InternetReadFileExA and InternetReadFileExW hooks.
//
static BOOL CommonInternetReadFileEx(
	HINTERNET			hFile, 
	LPINTERNET_BUFFERS	lpBuffersOut, 
	DWORD				dwFlags, 
	DWORD_PTR			dwContext, 
	BOOL				IsUnicode
	)
{
	BOOL Ret = FALSE;
	PHANDLE_CONTEXT	Ctx;

	if (Ctx = IeGetContext(hFile))
	{
		do	// not a loop
		{
			GetPageContent(Ctx, hFile);

			lpBuffersOut->dwBufferTotal = lpBuffersOut->dwBufferLength;
			if (CoInvoke(Ctx->pStream, Read, lpBuffersOut->lpvBuffer, lpBuffersOut->dwBufferLength, &lpBuffersOut->dwBufferLength) == S_OK)
				Ret = TRUE;

		} while(FALSE);

		ReleaseHandle(Ctx);
	}
	else
	{
		if (IsUnicode)
			Ret = InternetReadFileExW(hFile, (LPINTERNET_BUFFERSW)lpBuffersOut, dwFlags, dwContext);
		else
			Ret = InternetReadFileExA(hFile, lpBuffersOut, dwFlags, dwContext);
	}

	return(Ret);
}
Example #3
0
BOOL WINAPI my_InternetQueryDataAvailable(HINTERNET hFile, LPDWORD lpdwNumberOfBytesAvailable, DWORD dwFlags, DWORD_PTR dwContext)
{
	BOOL Ret = FALSE;
	PHANDLE_CONTEXT Ctx;
	
	ENTER_HOOK();

	*lpdwNumberOfBytesAvailable = 0;

	if (Ctx = IeGetContext(hFile))
	{
		do	// not a loop
		{
			ULONG	Pos;
			ULONG	Length;

			GetPageContent(Ctx, hFile);
		
			Pos = StreamGetPos(Ctx->pStream);
			Length = StreamGetLength(Ctx->pStream);
			*lpdwNumberOfBytesAvailable = Length - Pos;

			Ret = TRUE;

		} while(FALSE);

		ReleaseHandle(Ctx);
	}
	else
		Ret = InternetQueryDataAvailable( hFile, lpdwNumberOfBytesAvailable, dwFlags, dwContext);

	LEAVE_HOOK();
	return(Ret);
}
Example #4
0
void
wxPdfParser::GetContent(int pageno, wxArrayPtrVoid& contents)
{
  if (pageno >= 0 && pageno < GetPageCount())
  {
    wxPdfObject* content = ((wxPdfDictionary*) m_pages[pageno])->Get(_T("/Contents"));
    GetPageContent(content, contents);
  }
}
Example #5
0
FPDF_EXPORT void FPDF_CALLCONV FPDFPage_InsertClipPath(FPDF_PAGE page,
                                                       FPDF_CLIPPATH clipPath) {
  CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
  if (!pPage)
    return;

  CPDF_Dictionary* pPageDict = pPage->GetDict();
  CPDF_Object* pContentObj = GetPageContent(pPageDict);
  if (!pContentObj)
    return;

  std::ostringstream strClip;
  CPDF_ClipPath* pClipPath = CPDFClipPathFromFPDFClipPath(clipPath);
  for (size_t i = 0; i < pClipPath->GetPathCount(); ++i) {
    CPDF_Path path = pClipPath->GetPath(i);
    if (path.GetPoints().empty()) {
      // Empty clipping (totally clipped out)
      strClip << "0 0 m W n ";
    } else {
      OutputPath(strClip, path);
      if (pClipPath->GetClipType(i) == FXFILL_WINDING)
        strClip << "W n\n";
      else
        strClip << "W* n\n";
    }
  }
  CPDF_Document* pDoc = pPage->GetDocument();
  if (!pDoc)
    return;

  CPDF_Stream* pStream =
      pDoc->NewIndirect<CPDF_Stream>(nullptr, 0, pDoc->New<CPDF_Dictionary>());
  pStream->SetDataFromStringstream(&strClip);

  if (CPDF_Array* pArray = ToArray(pContentObj)) {
    pArray->InsertAt(0, pStream->MakeReference(pDoc));
  } else if (pContentObj->IsStream() && !pContentObj->IsInline()) {
    CPDF_Array* pContentArray = pDoc->NewIndirect<CPDF_Array>();
    pContentArray->Add(pStream->MakeReference(pDoc));
    pContentArray->Add(pContentObj->MakeReference(pDoc));
    pPageDict->SetFor(pdfium::page_object::kContents,
                      pContentArray->MakeReference(pDoc));
  }
}
Example #6
0
BOOL WINAPI my_InternetReadFile(HINTERNET hFile, LPVOID lpBuffer, DWORD dwNumberOfBytesToRead, LPDWORD lpdwNumberOfBytesRead)
{
	BOOL Ret = FALSE;
	PHANDLE_CONTEXT Ctx = NULL;

	ENTER_HOOK();

	*lpdwNumberOfBytesRead = 0;

	if (Ctx = IeGetContext(hFile))
	{
		GetPageContent(Ctx, hFile);
					
		if (CoInvoke(Ctx->pStream, Read, lpBuffer, dwNumberOfBytesToRead, lpdwNumberOfBytesRead) == S_OK)
			Ret = TRUE;
	
		ReleaseHandle(Ctx);
	}
	else
		Ret = InternetReadFile(hFile, lpBuffer, dwNumberOfBytesToRead, lpdwNumberOfBytesRead);

	LEAVE_HOOK();
	return(Ret);
}
Example #7
0
FPDF_EXPORT FPDF_BOOL FPDF_CALLCONV
FPDFPage_TransFormWithClip(FPDF_PAGE page,
                           const FS_MATRIX* matrix,
                           const FS_RECTF* clipRect) {
  if (!matrix && !clipRect)
    return false;

  CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
  if (!pPage)
    return false;

  std::ostringstream textBuf;
  textBuf << "q ";

  if (clipRect) {
    CFX_FloatRect rect = CFXFloatRectFromFSRECTF(*clipRect);
    rect.Normalize();

    textBuf << ByteString::Format("%f %f %f %f re W* n ", rect.left,
                                  rect.bottom, rect.Width(), rect.Height());
  }
  if (matrix) {
    textBuf << ByteString::Format("%f %f %f %f %f %f cm ", matrix->a, matrix->b,
                                  matrix->c, matrix->d, matrix->e, matrix->f);
  }

  CPDF_Dictionary* pPageDict = pPage->GetDict();
  CPDF_Object* pContentObj = GetPageContent(pPageDict);
  if (!pContentObj)
    return false;

  CPDF_Document* pDoc = pPage->GetDocument();
  if (!pDoc)
    return false;

  CPDF_Stream* pStream =
      pDoc->NewIndirect<CPDF_Stream>(nullptr, 0, pDoc->New<CPDF_Dictionary>());
  pStream->SetDataFromStringstream(&textBuf);

  CPDF_Stream* pEndStream =
      pDoc->NewIndirect<CPDF_Stream>(nullptr, 0, pDoc->New<CPDF_Dictionary>());
  pEndStream->SetData(ByteStringView(" Q").span());

  if (CPDF_Array* pContentArray = ToArray(pContentObj)) {
    pContentArray->InsertAt(0, pStream->MakeReference(pDoc));
    pContentArray->Add(pEndStream->MakeReference(pDoc));
  } else if (pContentObj->IsStream() && !pContentObj->IsInline()) {
    pContentArray = pDoc->NewIndirect<CPDF_Array>();
    pContentArray->Add(pStream->MakeReference(pDoc));
    pContentArray->Add(pContentObj->MakeReference(pDoc));
    pContentArray->Add(pEndStream->MakeReference(pDoc));
    pPageDict->SetFor(pdfium::page_object::kContents,
                      pContentArray->MakeReference(pDoc));
  }

  // Need to transform the patterns as well.
  CPDF_Dictionary* pRes =
      pPageDict->GetDictFor(pdfium::page_object::kResources);
  if (!pRes)
    return true;

  CPDF_Dictionary* pPatternDict = pRes->GetDictFor("Pattern");
  if (!pPatternDict)
    return true;

  CPDF_DictionaryLocker locker(pPatternDict);
  for (const auto& it : locker) {
    CPDF_Object* pObj = it.second.get();
    if (pObj->IsReference())
      pObj = pObj->GetDirect();

    CPDF_Dictionary* pDict = nullptr;
    if (pObj->IsDictionary())
      pDict = pObj->AsDictionary();
    else if (CPDF_Stream* pObjStream = pObj->AsStream())
      pDict = pObjStream->GetDict();
    else
      continue;

    if (matrix) {
      CFX_Matrix m = CFXMatrixFromFSMatrix(*matrix);
      pDict->SetMatrixFor("Matrix", pDict->GetMatrixFor("Matrix") * m);
    }
  }

  return true;
}