Пример #1
0
CPDF_StreamAcc* CPDF_DocPageData::GetFontFileStreamAcc(CPDF_Stream* pFontStream)
{
    if (!pFontStream) {
        return NULL;
    }
    CPDF_CountedObject<CPDF_StreamAcc*>* ftData;
    if (m_FontFileMap.Lookup(pFontStream, ftData)) {
        ftData->m_nCount ++;
        return ftData->m_Obj;
    }
    ftData = FX_NEW CPDF_CountedObject<CPDF_StreamAcc*>;
    if (!ftData) {
        return NULL;
    }
    CPDF_StreamAcc* pFontFile = FX_NEW CPDF_StreamAcc;
    if (!pFontFile) {
        delete ftData;
        return NULL;
    }
    CPDF_Dictionary* pFontDict = pFontStream->GetDict();
    FX_INT32 org_size = pFontDict->GetInteger(FX_BSTRC("Length1")) + pFontDict->GetInteger(FX_BSTRC("Length2")) + pFontDict->GetInteger(FX_BSTRC("Length3"));
    if (org_size < 0) {
        org_size = 0;
    }
    pFontFile->LoadAllData(pFontStream, FALSE, org_size);
    ftData->m_nCount = 2;
    ftData->m_Obj = pFontFile;
    m_FontFileMap.SetAt(pFontStream, ftData);
    return pFontFile;
}
Пример #2
0
FX_BOOL CPDF_SampledFunc::v_Init(CPDF_Object* pObj) {
  if (pObj->GetType() != PDFOBJ_STREAM) {
    return FALSE;
  }
  CPDF_Stream* pStream = (CPDF_Stream*)pObj;
  CPDF_Dictionary* pDict = pStream->GetDict();
  CPDF_Array* pSize = pDict->GetArray(FX_BSTRC("Size"));
  CPDF_Array* pEncode = pDict->GetArray(FX_BSTRC("Encode"));
  CPDF_Array* pDecode = pDict->GetArray(FX_BSTRC("Decode"));
  m_nBitsPerSample = pDict->GetInteger(FX_BSTRC("BitsPerSample"));
  if (m_nBitsPerSample > 32) {
    return FALSE;
  }
  m_SampleMax = 0xffffffff >> (32 - m_nBitsPerSample);
  m_pSampleStream = new CPDF_StreamAcc;
  m_pSampleStream->LoadAllData(pStream, FALSE);
  m_pEncodeInfo = FX_Alloc(SampleEncodeInfo, m_nInputs);
  FX_SAFE_DWORD nTotalSampleBits = 1;
  for (int i = 0; i < m_nInputs; i++) {
    m_pEncodeInfo[i].sizes = pSize ? pSize->GetInteger(i) : 0;
    if (!pSize && i == 0) {
      m_pEncodeInfo[i].sizes = pDict->GetInteger(FX_BSTRC("Size"));
    }
    nTotalSampleBits *= m_pEncodeInfo[i].sizes;
    if (pEncode) {
      m_pEncodeInfo[i].encode_min = pEncode->GetFloat(i * 2);
      m_pEncodeInfo[i].encode_max = pEncode->GetFloat(i * 2 + 1);
    } else {
      m_pEncodeInfo[i].encode_min = 0;
      if (m_pEncodeInfo[i].sizes == 1) {
        m_pEncodeInfo[i].encode_max = 1;
      } else {
        m_pEncodeInfo[i].encode_max = (FX_FLOAT)m_pEncodeInfo[i].sizes - 1;
      }
    }
  }
  nTotalSampleBits *= m_nBitsPerSample;
  nTotalSampleBits *= m_nOutputs;
  FX_SAFE_DWORD nTotalSampleBytes = nTotalSampleBits;
  nTotalSampleBytes += 7;
  nTotalSampleBytes /= 8;
  if (!nTotalSampleBytes.IsValid() || nTotalSampleBytes.ValueOrDie() == 0 ||
      nTotalSampleBytes.ValueOrDie() > m_pSampleStream->GetSize()) {
    return FALSE;
  }
  m_pDecodeInfo = FX_Alloc(SampleDecodeInfo, m_nOutputs);
  for (int i = 0; i < m_nOutputs; i++) {
    if (pDecode) {
      m_pDecodeInfo[i].decode_min = pDecode->GetFloat(2 * i);
      m_pDecodeInfo[i].decode_max = pDecode->GetFloat(2 * i + 1);
    } else {
      m_pDecodeInfo[i].decode_min = m_pRanges[i * 2];
      m_pDecodeInfo[i].decode_max = m_pRanges[i * 2 + 1];
    }
  }
  return TRUE;
}
Пример #3
0
void CPDF_StructElementImpl::LoadKid(FX_DWORD PageObjNum, CPDF_Object* pKidObj, CPDF_StructKid* pKid)
{
    pKid->m_Type = CPDF_StructKid::Invalid;
    if (pKidObj == NULL) {
        return;
    }
    if (pKidObj->GetType() == PDFOBJ_NUMBER) {
        if (m_pTree->m_pPage && m_pTree->m_pPage->GetObjNum() != PageObjNum) {
            return;
        }
        pKid->m_Type = CPDF_StructKid::PageContent;
        pKid->m_PageContent.m_ContentId = pKidObj->GetInteger();
        pKid->m_PageContent.m_PageObjNum = PageObjNum;
        return;
    }
    if (pKidObj->GetType() != PDFOBJ_DICTIONARY) {
        return;
    }
    CPDF_Dictionary* pKidDict = (CPDF_Dictionary*)pKidObj;
    CPDF_Object* pPageObj = pKidDict->GetElement(FX_BSTRC("Pg"));
    if (pPageObj && pPageObj->GetType() == PDFOBJ_REFERENCE) {
        PageObjNum = ((CPDF_Reference*)pPageObj)->GetRefObjNum();
    }
    CFX_ByteString type = pKidDict->GetString(FX_BSTRC("Type"));
    if (type == FX_BSTRC("MCR")) {
        if (m_pTree->m_pPage && m_pTree->m_pPage->GetObjNum() != PageObjNum) {
            return;
        }
        pKid->m_Type = CPDF_StructKid::StreamContent;
        CPDF_Object* pStreamObj = pKidDict->GetElement(FX_BSTRC("Stm"));
        if (pStreamObj && pStreamObj->GetType() == PDFOBJ_REFERENCE) {
            pKid->m_StreamContent.m_RefObjNum = ((CPDF_Reference*)pStreamObj)->GetRefObjNum();
        } else {
            pKid->m_StreamContent.m_RefObjNum = 0;
        }
        pKid->m_StreamContent.m_PageObjNum = PageObjNum;
        pKid->m_StreamContent.m_ContentId = pKidDict->GetInteger(FX_BSTRC("MCID"));
    } else if (type == FX_BSTRC("OBJR")) {
        if (m_pTree->m_pPage && m_pTree->m_pPage->GetObjNum() != PageObjNum) {
            return;
        }
        pKid->m_Type = CPDF_StructKid::Object;
        CPDF_Object* pObj = pKidDict->GetElement(FX_BSTRC("Obj"));
        if (pObj && pObj->GetType() == PDFOBJ_REFERENCE) {
            pKid->m_Object.m_RefObjNum = ((CPDF_Reference*)pObj)->GetRefObjNum();
        } else {
            pKid->m_Object.m_RefObjNum = 0;
        }
        pKid->m_Object.m_PageObjNum = PageObjNum;
    } else {
        pKid->m_Type = CPDF_StructKid::Element;
        pKid->m_Element.m_pDict = pKidDict;
        if (m_pTree->m_pPage == NULL) {
            pKid->m_Element.m_pElement = FX_NEW CPDF_StructElementImpl(m_pTree, this, pKidDict);
        } else {
            pKid->m_Element.m_pElement = NULL;
        }
    }
}
Пример #4
0
int32_t CPDF_ViewerPreferences::NumCopies() const {
  CPDF_Dictionary* pDict = m_pDoc->GetRoot();
  pDict = pDict->GetDict(FX_BSTRC("ViewerPreferences"));
  if (!pDict) {
    return 1;
  }
  return pDict->GetInteger(FX_BSTRC("NumCopies"));
}
Пример #5
0
DLLEXPORT int STDCALL FPDF_GetSecurityHandlerRevision(FPDF_DOCUMENT document)
{
    if (document == NULL) return -1;
    CPDF_Document*pDoc = (CPDF_Document*)document;
    CPDF_Parser* pParser = (CPDF_Parser*)pDoc->GetParser();
    CPDF_Dictionary* pDict = pParser->GetEncryptDict();
    if (pDict == NULL) return -1;

    return pDict->GetInteger("R");
}
Пример #6
0
// jabdelmalek: changed return type from FX_DWORD to build on Linux (and match header).
DLLEXPORT unsigned long STDCALL FPDF_GetDocPermissions(FPDF_DOCUMENT document)
{
    if (document == NULL) return 0;
    CPDF_Document*pDoc = (CPDF_Document*)document;
    CPDF_Parser* pParser = 	(CPDF_Parser*)pDoc->GetParser();
    CPDF_Dictionary* pDict = pParser->GetEncryptDict();
    if (pDict == NULL) return (FX_DWORD)-1;

    return pDict->GetInteger("P");
}
Пример #7
0
FX_BOOL CPDF_Image::LoadImageF(CPDF_Stream* pStream, FX_BOOL bInline) {
  m_pStream = pStream;
  if (m_bInline && m_pInlineDict) {
    m_pInlineDict->Release();
    m_pInlineDict = NULL;
  }
  m_bInline = bInline;
  CPDF_Dictionary* pDict = pStream->GetDict();
  if (m_bInline) {
    m_pInlineDict = ToDictionary(pDict->Clone());
  }
  m_pOC = pDict->GetDict(FX_BSTRC("OC"));
  m_bIsMask = !pDict->KeyExist(FX_BSTRC("ColorSpace")) ||
              pDict->GetInteger(FX_BSTRC("ImageMask"));
  m_bInterpolate = pDict->GetInteger(FX_BSTRC("Interpolate"));
  m_Height = pDict->GetInteger(FX_BSTRC("Height"));
  m_Width = pDict->GetInteger(FX_BSTRC("Width"));
  return TRUE;
}
Пример #8
0
void CPDF_PageObjects::LoadTransInfo()
{
    if (m_pFormDict == NULL) {
        return;
    }
    CPDF_Dictionary* pGroup = m_pFormDict->GetDict(FX_BSTRC("Group"));
    if (pGroup == NULL) {
        return;
    }
    if (pGroup->GetString(FX_BSTRC("S")) != FX_BSTRC("Transparency")) {
        return;
    }
    m_Transparency |= PDFTRANS_GROUP;
    if (pGroup->GetInteger(FX_BSTRC("I"))) {
        m_Transparency |= PDFTRANS_ISOLATED;
    }
    if (pGroup->GetInteger(FX_BSTRC("K"))) {
        m_Transparency |= PDFTRANS_KNOCKOUT;
    }
}
Пример #9
0
FX_BOOL CPDF_MeshStream::Load(CPDF_Stream* pShadingStream, CPDF_Function** pFuncs, int nFuncs, CPDF_ColorSpace* pCS)
{
    m_Stream.LoadAllData(pShadingStream);
    m_BitStream.Init(m_Stream.GetData(), m_Stream.GetSize());
    m_pFuncs = pFuncs;
    m_nFuncs = nFuncs;
    m_pCS = pCS;
    CPDF_Dictionary* pDict = pShadingStream->GetDict();
    m_nCoordBits = pDict->GetInteger(FX_BSTRC("BitsPerCoordinate"));
    m_nCompBits = pDict->GetInteger(FX_BSTRC("BitsPerComponent"));
    m_nFlagBits = pDict->GetInteger(FX_BSTRC("BitsPerFlag"));
    if (!m_nCoordBits || !m_nCompBits) {
        return FALSE;
    }
    int nComps = pCS->CountComponents();
    if (nComps > 8) {
        return FALSE;
    }
    m_nComps = nFuncs ? 1 : nComps;
    if (((int)m_nComps < 0) || m_nComps > 8) {
        return FALSE;
    }
    m_CoordMax = m_nCoordBits == 32 ? -1 : (1 << m_nCoordBits) - 1;
    m_CompMax = (1 << m_nCompBits) - 1;
    CPDF_Array* pDecode = pDict->GetArray(FX_BSTRC("Decode"));
    if (pDecode == NULL || pDecode->GetCount() != 4 + m_nComps * 2) {
        return FALSE;
    }
    m_xmin = pDecode->GetNumber(0);
    m_xmax = pDecode->GetNumber(1);
    m_ymin = pDecode->GetNumber(2);
    m_ymax = pDecode->GetNumber(3);
    for (FX_DWORD i = 0; i < m_nComps; i ++) {
        m_ColorMin[i] = pDecode->GetNumber(i * 2 + 4);
        m_ColorMax[i] = pDecode->GetNumber(i * 2 + 5);
    }
    return TRUE;
}
Пример #10
0
static int InsertDeletePDFPage(CPDF_Document* pDoc,
                               CPDF_Dictionary* pPages,
                               int nPagesToGo,
                               CPDF_Dictionary* pPage,
                               FX_BOOL bInsert,
                               CFX_ArrayTemplate<CPDF_Dictionary*>& stackList) {
  CPDF_Array* pKidList = pPages->GetArray("Kids");
  if (!pKidList) {
    return -1;
  }
  int nKids = pKidList->GetCount();
  for (int i = 0; i < nKids; i++) {
    CPDF_Dictionary* pKid = pKidList->GetDict(i);
    if (pKid->GetString("Type") == "Page") {
      if (nPagesToGo == 0) {
        if (bInsert) {
          pKidList->InsertAt(i, new CPDF_Reference(pDoc, pPage->GetObjNum()));
          pPage->SetAtReference("Parent", pDoc, pPages->GetObjNum());
        } else {
          pKidList->RemoveAt(i);
        }
        pPages->SetAtInteger("Count",
                             pPages->GetInteger("Count") + (bInsert ? 1 : -1));
        return 1;
      }
      nPagesToGo--;
    } else {
      int nPages = pKid->GetInteger("Count");
      if (nPagesToGo < nPages) {
        int stackCount = stackList.GetSize();
        for (int j = 0; j < stackCount; ++j) {
          if (pKid == stackList[j]) {
            return -1;
          }
        }
        stackList.Add(pKid);
        if (InsertDeletePDFPage(pDoc, pKid, nPagesToGo, pPage, bInsert,
                                stackList) < 0) {
          return -1;
        }
        stackList.RemoveAt(stackCount);
        pPages->SetAtInteger("Count",
                             pPages->GetInteger("Count") + (bInsert ? 1 : -1));
        return 1;
      }
      nPagesToGo -= nPages;
    }
  }
  return 0;
}
Пример #11
0
CPDF_TilingPattern::CPDF_TilingPattern(CPDF_Document* pDoc, CPDF_Object* pPatternObj, const CFX_AffineMatrix* parentMatrix) :
    CPDF_Pattern(parentMatrix)
{
    m_PatternType = PATTERN_TILING;
    m_pPatternObj = pPatternObj;
    m_pDocument = pDoc;
    CPDF_Dictionary* pDict = m_pPatternObj->GetDict();
    ASSERT(pDict != NULL);
    m_Pattern2Form = pDict->GetMatrix(FX_BSTRC("Matrix"));
    m_bColored = pDict->GetInteger(FX_BSTRC("PaintType")) == 1;
    if (parentMatrix) {
        m_Pattern2Form.Concat(*parentMatrix);
    }
    m_pForm = NULL;
}
Пример #12
0
static FX_BOOL _LoadCryptInfo(CPDF_Dictionary* pEncryptDict,
                              const CFX_ByteStringC& name,
                              int& cipher,
                              int& keylen) {
  int Version = pEncryptDict->GetInteger(FX_BSTRC("V"));
  cipher = FXCIPHER_RC4;
  keylen = 0;
  if (Version >= 4) {
    CPDF_Dictionary* pCryptFilters = pEncryptDict->GetDict(FX_BSTRC("CF"));
    if (pCryptFilters == NULL) {
      return FALSE;
    }
    if (name == FX_BSTRC("Identity")) {
      cipher = FXCIPHER_NONE;
    } else {
      CPDF_Dictionary* pDefFilter = pCryptFilters->GetDict(name);
      if (pDefFilter == NULL) {
        return FALSE;
      }
      int nKeyBits = 0;
      if (Version == 4) {
        nKeyBits = pDefFilter->GetInteger(FX_BSTRC("Length"), 0);
        if (nKeyBits == 0) {
          nKeyBits = pEncryptDict->GetInteger(FX_BSTRC("Length"), 128);
        }
      } else {
        nKeyBits = pEncryptDict->GetInteger(FX_BSTRC("Length"), 256);
      }
      if (nKeyBits < 40) {
        nKeyBits *= 8;
      }
      keylen = nKeyBits / 8;
      CFX_ByteString cipher_name = pDefFilter->GetString(FX_BSTRC("CFM"));
      if (cipher_name == FX_BSTRC("AESV2") ||
          cipher_name == FX_BSTRC("AESV3")) {
        cipher = FXCIPHER_AES;
      }
    }
  } else {
    keylen =
        Version > 1 ? pEncryptDict->GetInteger(FX_BSTRC("Length"), 40) / 8 : 5;
  }
  if (keylen > 32 || keylen < 0) {
    return FALSE;
  }
  return TRUE;
}
Пример #13
0
CPDF_Pattern* CPDF_DocPageData::GetPattern(CPDF_Object* pPatternObj, FX_BOOL bShading, const CFX_AffineMatrix* matrix)
{
    if (!pPatternObj) {
        return NULL;
    }
    CPDF_CountedObject<CPDF_Pattern*>* ptData = NULL;
    if (m_PatternMap.Lookup(pPatternObj, ptData)) {
        if (ptData->m_Obj) {
            ptData->m_nCount++;
            return ptData->m_Obj;
        }
    }
    FX_BOOL bNew = FALSE;
    if (!ptData) {
        ptData = FX_NEW CPDF_CountedObject<CPDF_Pattern*>;
        bNew = TRUE;
        if (!ptData) {
            return NULL;
        }
    }
    CPDF_Pattern* pPattern = NULL;
    if (bShading) {
        pPattern = FX_NEW CPDF_ShadingPattern(m_pPDFDoc, pPatternObj, bShading, matrix);
    } else {
        CPDF_Dictionary* pDict = pPatternObj ? pPatternObj->GetDict() : NULL;
        if (pDict) {
            int type = pDict->GetInteger(FX_BSTRC("PatternType"));
            if (type == 1) {
                pPattern = FX_NEW CPDF_TilingPattern(m_pPDFDoc, pPatternObj, matrix);
            } else if (type == 2) {
                pPattern = FX_NEW CPDF_ShadingPattern(m_pPDFDoc, pPatternObj, FALSE, matrix);
            }
        }
    }
    if (!pPattern) {
        if (bNew) {
            delete ptData;
        }
        return NULL;
    }
    ptData->m_nCount = 2;
    ptData->m_Obj = pPattern;
    m_PatternMap.SetAt(pPatternObj, ptData);
    return pPattern;
}
Пример #14
0
int CPDF_FormField::GetMaxLen() {
  CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "MaxLen");
  if (pObj == NULL) {
    int iCount = m_ControlList.GetSize();
    for (int i = 0; i < iCount; i++) {
      CPDF_FormControl* pControl = (CPDF_FormControl*)m_ControlList.GetAt(i);
      if (pControl == NULL) {
        continue;
      }
      CPDF_Dictionary* pWidgetDict = pControl->m_pWidgetDict;
      if (pWidgetDict->KeyExist("MaxLen")) {
        return pWidgetDict->GetInteger("MaxLen");
      }
    }
    return 0;
  }
  return pObj->GetInteger();
}
Пример #15
0
int ParserAnnots( CPDF_Document* pSourceDoc, CPDF_Dictionary * pPageDic, CPDF_RectArray * pRectArray, CPDF_ObjectArray * pObjectArray, int nUsage)
{
	if (!pSourceDoc || !pPageDic) return FLATTEN_FAIL;
	
	GetContentsRect( pSourceDoc, pPageDic, pRectArray );
	CPDF_Array* pAnnots = pPageDic->GetArray("Annots");
	if (pAnnots)
	{
		FX_DWORD dwSize = pAnnots->GetCount();
		
		for (int i = 0; i < (int)dwSize; i++)
		{
			CPDF_Object* pObj = pAnnots->GetElementValue(i);
			
			if (!pObj)continue;
			
			if (pObj->GetType() == PDFOBJ_DICTIONARY)
			{
				CPDF_Dictionary* pAnnotDic = (CPDF_Dictionary*)pObj;
				CFX_ByteString sSubtype = pAnnotDic->GetString("Subtype");
				if (sSubtype == "Popup")continue;

				int nAnnotFlag = pAnnotDic->GetInteger("F");

				if(nAnnotFlag & ANNOTFLAG_HIDDEN) 
					continue;
				if(nUsage == FLAT_NORMALDISPLAY)
				{
					if(nAnnotFlag & ANNOTFLAG_INVISIBLE)
						continue;
					ParserStream( pPageDic, pAnnotDic, pRectArray, pObjectArray );		
				}
				else
				{
					if(nAnnotFlag & ANNOTFLAG_PRINT)
						ParserStream( pPageDic, pAnnotDic, pRectArray, pObjectArray );
				}			
			}
		}
		return FLATTEN_SUCCESS;
	}else{
		return FLATTEN_NOTINGTODO;
	}
}
Пример #16
0
FX_BOOL CPDF_ShadingPattern::Load()
{
    if (m_ShadingType != 0) {
        return TRUE;
    }
    CPDF_Dictionary* pShadingDict = m_pShadingObj ? m_pShadingObj->GetDict() : NULL;
    if (pShadingDict == NULL) {
        return FALSE;
    }
    if (m_nFuncs) {
        for (int i = 0; i < m_nFuncs; i ++)
            if (m_pFunctions[i]) {
                delete m_pFunctions[i];
            }
        m_nFuncs = 0;
    }
    CPDF_Object* pFunc = pShadingDict->GetElementValue(FX_BSTRC("Function"));
    if (pFunc) {
        if (pFunc->GetType() == PDFOBJ_ARRAY) {
            m_nFuncs = ((CPDF_Array*)pFunc)->GetCount();
            if (m_nFuncs > 4) {
                m_nFuncs = 4;
            }
            for (int i = 0; i < m_nFuncs; i ++) {
                m_pFunctions[i] = CPDF_Function::Load(((CPDF_Array*)pFunc)->GetElementValue(i));
            }
        } else {
            m_pFunctions[0] = CPDF_Function::Load(pFunc);
            m_nFuncs = 1;
        }
    }
    CPDF_Object* pCSObj = pShadingDict->GetElementValue(FX_BSTRC("ColorSpace"));
    if (pCSObj == NULL) {
        return FALSE;
    }
    CPDF_DocPageData* pDocPageData = m_pDocument->GetPageData();
    m_pCS = pDocPageData->GetColorSpace(pCSObj, NULL);
    if (m_pCS) {
        m_pCountedCS = pDocPageData->FindColorSpacePtr(m_pCS->GetArray());
    }
    m_ShadingType = pShadingDict->GetInteger(FX_BSTRC("ShadingType"));
    return TRUE;
}
Пример #17
0
void CPDF_Document::DeletePage(int iPage) {
  CPDF_Dictionary* pRoot = GetRoot();
  if (!pRoot) {
    return;
  }
  CPDF_Dictionary* pPages = pRoot->GetDict("Pages");
  if (!pPages) {
    return;
  }
  int nPages = pPages->GetInteger("Count");
  if (iPage < 0 || iPage >= nPages) {
    return;
  }
  CFX_ArrayTemplate<CPDF_Dictionary*> stack;
  stack.Add(pPages);
  if (InsertDeletePDFPage(this, pPages, iPage, NULL, FALSE, stack) < 0) {
    return;
  }
  m_PageList.RemoveAt(iPage);
}
Пример #18
0
FX_BOOL CPDF_TilingPattern::Load()
{
    if (m_pForm != NULL) {
        return TRUE;
    }
    CPDF_Dictionary* pDict = m_pPatternObj->GetDict();
    if (pDict == NULL) {
        return FALSE;
    }
    m_bColored = pDict->GetInteger(FX_BSTRC("PaintType")) == 1;
    m_XStep = (FX_FLOAT)FXSYS_fabs(pDict->GetNumber(FX_BSTRC("XStep")));
    m_YStep = (FX_FLOAT)FXSYS_fabs(pDict->GetNumber(FX_BSTRC("YStep")));
    if (m_pPatternObj->GetType() != PDFOBJ_STREAM) {
        return FALSE;
    }
    CPDF_Stream* pStream = (CPDF_Stream*)m_pPatternObj;
    m_pForm = FX_NEW CPDF_Form(m_pDocument, NULL, pStream);
    m_pForm->ParseContent(NULL, &m_ParentMatrix, NULL, NULL);
    m_BBox = pDict->GetRect(FX_BSTRC("BBox"));
    return TRUE;
}
Пример #19
0
CPDF_Dictionary* CPDF_Document::_FindPDFPage(CPDF_Dictionary* pPages,
        int iPage,
        int nPagesToGo,
        int level) {
    CPDF_Array* pKidList = pPages->GetArray("Kids");
    if (!pKidList) {
        if (nPagesToGo == 0) {
            return pPages;
        }
        return NULL;
    }
    if (level >= FX_MAX_PAGE_LEVEL) {
        return NULL;
    }
    int nKids = pKidList->GetCount();
    for (int i = 0; i < nKids; i++) {
        CPDF_Dictionary* pKid = pKidList->GetDict(i);
        if (!pKid) {
            nPagesToGo--;
            continue;
        }
        if (pKid == pPages) {
            continue;
        }
        if (!pKid->KeyExist("Kids")) {
            if (nPagesToGo == 0) {
                return pKid;
            }
            m_PageList.SetAt(iPage - nPagesToGo, pKid->GetObjNum());
            nPagesToGo--;
        } else {
            int nPages = pKid->GetInteger("Count");
            if (nPagesToGo < nPages) {
                return _FindPDFPage(pKid, iPage, nPagesToGo, level + 1);
            }
            nPagesToGo -= nPages;
        }
    }
    return NULL;
}
Пример #20
0
int	CPDFSDK_Annot::GetBorderWidth() const
{
	ASSERT(m_pAnnot != NULL);
	ASSERT(m_pAnnot->m_pAnnotDict != NULL);

	CPDF_Array* pBorder = m_pAnnot->m_pAnnotDict->GetArray("Border");

	if (pBorder)
	{
		return pBorder->GetInteger(2);
	}
	else
	{
		CPDF_Dictionary* pBSDict = m_pAnnot->m_pAnnotDict->GetDict("BS");

		if (pBSDict)
		{
			return pBSDict->GetInteger("W", 1);
		}
	}
	return 1;
}
Пример #21
0
CFX_WideString CPDF_PageLabel::GetLabel(int nPage) const
{
    CFX_WideString wsLabel;
    if (m_pDocument == NULL) {
        return wsLabel;
    }
    CPDF_Dictionary* pPDFRoot = m_pDocument->GetRoot();
    if (pPDFRoot == NULL) {
        return wsLabel;
    }
    CPDF_Dictionary* pLabels = pPDFRoot->GetDict(FX_BSTRC("PageLabels"));
    CPDF_NumberTree numberTree(pLabels);
    CPDF_Object* pValue = NULL;
    int n = nPage;
    while (n >= 0) {
        pValue = numberTree.LookupValue(n);
        if (pValue != NULL) {
            break;
        }
        n--;
    }
    if (pValue != NULL) {
        pValue = pValue->GetDirect();
        if (pValue->GetType() == PDFOBJ_DICTIONARY) {
            CPDF_Dictionary* pLabel = (CPDF_Dictionary*)pValue;
            if (pLabel->KeyExist(FX_BSTRC("P"))) {
                wsLabel += pLabel->GetUnicodeText(FX_BSTRC("P"));
            }
            CFX_ByteString bsNumberingStyle = pLabel->GetString(FX_BSTRC("S"), NULL);
            int nLabelNum = nPage - n + pLabel->GetInteger(FX_BSTRC("St"), 1);
            CFX_WideString wsNumPortion = _GetLabelNumPortion(nLabelNum, bsNumberingStyle);
            wsLabel += wsNumPortion;
            return wsLabel;
        }
    }
    wsLabel.Format(L"%d", nPage + 1);
    return wsLabel;
}
Пример #22
0
FX_BOOL CPDF_SampledFunc::v_Init(CPDF_Object* pObj)
{
    if (pObj->GetType() != PDFOBJ_STREAM) {
        return FALSE;
    }
    CPDF_Stream* pStream = (CPDF_Stream*)pObj;
    CPDF_Dictionary* pDict = pStream->GetDict();
    CPDF_Array* pSize = pDict->GetArray(FX_BSTRC("Size"));
    CPDF_Array* pEncode = pDict->GetArray(FX_BSTRC("Encode"));
    CPDF_Array* pDecode = pDict->GetArray(FX_BSTRC("Decode"));
    m_nBitsPerSample = pDict->GetInteger(FX_BSTRC("BitsPerSample"));
    m_SampleMax = 0xffffffff >> (32 - m_nBitsPerSample);
    m_pSampleStream = FX_NEW CPDF_StreamAcc;
    m_pSampleStream->LoadAllData(pStream, FALSE);
    m_pEncodeInfo = FX_Alloc(SampleEncodeInfo, m_nInputs);
    int i;
    FX_DWORD nTotalSamples = 1;
    for (i = 0; i < m_nInputs; i ++) {
        m_pEncodeInfo[i].sizes = pSize ? pSize->GetInteger(i) : 0;
        if (!pSize && i == 0) {
            m_pEncodeInfo[i].sizes = pDict->GetInteger(FX_BSTRC("Size"));
        }
        if (nTotalSamples > 0 && (FX_UINT32)(m_pEncodeInfo[i].sizes) > UINT_MAX / nTotalSamples) {
            return FALSE;
        }
        nTotalSamples *= m_pEncodeInfo[i].sizes;
        if (pEncode) {
            m_pEncodeInfo[i].encode_min = pEncode->GetFloat(i * 2);
            m_pEncodeInfo[i].encode_max = pEncode->GetFloat(i * 2 + 1);
        } else {
            m_pEncodeInfo[i].encode_min = 0;
            if (m_pEncodeInfo[i].sizes == 1) {
                m_pEncodeInfo[i].encode_max = 1;
            } else {
                m_pEncodeInfo[i].encode_max = (FX_FLOAT)m_pEncodeInfo[i].sizes - 1;
            }
        }
    }
    if (nTotalSamples > 0 && m_nBitsPerSample > UINT_MAX / nTotalSamples) {
        return FALSE;
    }
    nTotalSamples *= m_nBitsPerSample;
    if (nTotalSamples > 0 && ((FX_UINT32)m_nOutputs) > UINT_MAX / nTotalSamples) {
        return FALSE;
    }
    nTotalSamples *= m_nOutputs;
    if (nTotalSamples == 0 || m_pSampleStream->GetSize() * 8 < nTotalSamples) {
        return FALSE;
    }
    m_pDecodeInfo = FX_Alloc(SampleDecodeInfo, m_nOutputs);
    for (i = 0; i < m_nOutputs; i ++) {
        if (pDecode) {
            m_pDecodeInfo[i].decode_min = pDecode->GetFloat(2 * i);
            m_pDecodeInfo[i].decode_max = pDecode->GetFloat(2 * i + 1);
        } else {
            m_pDecodeInfo[i].decode_min = m_pRanges[i * 2];
            m_pDecodeInfo[i].decode_max = m_pRanges[i * 2 + 1];
        }
    }
    return TRUE;
}
Пример #23
0
static FX_BOOL IsTagged(const CPDF_Document* pDoc)
{
    CPDF_Dictionary* pCatalog = pDoc->GetRoot();
    CPDF_Dictionary* pMarkInfo = pCatalog->GetDict(FX_BSTRC("MarkInfo"));
    return pMarkInfo != NULL && pMarkInfo->GetInteger(FX_BSTRC("Marked"));
}
Пример #24
0
FX_BOOL CPDF_ICCBasedCS::v_Load(CPDF_Document* pDoc, CPDF_Array* pArray)
{
    CPDF_Stream* pStream = pArray->GetStream(1);
    if (pStream == NULL) {
        return FALSE;
    }
    m_pProfile = pDoc->LoadIccProfile(pStream);
    if (!m_pProfile) {
        return FALSE;
    }
    m_nComponents = m_pProfile->GetComponents(); //Try using the nComponents from ICC profile
    CPDF_Dictionary* pDict = pStream->GetDict();
    if (m_pProfile->m_pTransform == NULL) { // No valid ICC profile or using sRGB
        CPDF_Object* pAlterCSObj = pDict ? pDict->GetElementValue(FX_BSTRC("Alternate")) : NULL;
        if (pAlterCSObj) {
            CPDF_ColorSpace* pAlterCS = CPDF_ColorSpace::Load(pDoc, pAlterCSObj);
            if (pAlterCS) {
                if (m_nComponents == 0) { // NO valid ICC profile
                    if (pAlterCS->CountComponents() > 0) { // Use Alternative colorspace
                        m_nComponents = pAlterCS->CountComponents();
                        m_pAlterCS = pAlterCS;
                        m_bOwn = TRUE;
                    }
                    else { // No valid alternative colorspace
                        pAlterCS->ReleaseCS();
                        int32_t nDictComponents = pDict ? pDict->GetInteger(FX_BSTRC("N")) : 0;
                        if (nDictComponents != 1 && nDictComponents != 3 && nDictComponents != 4) {
                            return FALSE;
                        }
                        m_nComponents = nDictComponents;
                    }

                }
                else { // Using sRGB
                    if (pAlterCS->CountComponents() != m_nComponents) {
                        pAlterCS->ReleaseCS();
                    }
                    else {
                        m_pAlterCS = pAlterCS;
                        m_bOwn = TRUE;
                    }
                }
            }
        }
        if (!m_pAlterCS) {
            if (m_nComponents == 1) {
                m_pAlterCS = GetStockCS(PDFCS_DEVICEGRAY);
            }
            else if (m_nComponents == 3) {
                m_pAlterCS = GetStockCS(PDFCS_DEVICERGB);
            }
            else if (m_nComponents == 4) {
                m_pAlterCS = GetStockCS(PDFCS_DEVICECMYK);
            }
        }
    }
    CPDF_Array* pRanges = pDict->GetArray(FX_BSTRC("Range"));
    m_pRanges = FX_Alloc2D(FX_FLOAT, m_nComponents, 2);
    for (int i = 0; i < m_nComponents * 2; i ++) {
        if (pRanges) {
            m_pRanges[i] = pRanges->GetNumber(i);
        } else if (i % 2) {
            m_pRanges[i] = 1.0f;
        } else {
            m_pRanges[i] = 0;
        }
    }
    return TRUE;
}
Пример #25
0
FX_BOOL CPDF_QuickStretcher::Start(CPDF_ImageObject* pImageObj,
                                   CFX_AffineMatrix* pImage2Device,
                                   const FX_RECT* pClipBox) {
    if (FXSYS_fabs(pImage2Device->a) < FXSYS_fabs(pImage2Device->b) * 10 &&
            FXSYS_fabs(pImage2Device->d) < FXSYS_fabs(pImage2Device->c) * 10) {
        return FALSE;
    }
    CFX_FloatRect image_rect_f = pImage2Device->GetUnitRect();
    FX_RECT image_rect = image_rect_f.GetOutterRect();
    m_DestWidth = image_rect.Width();
    m_DestHeight = image_rect.Height();
    m_bFlipX = pImage2Device->a < 0;
    m_bFlipY = pImage2Device->d > 0;
    FX_RECT result_rect = *pClipBox;
    result_rect.Intersect(image_rect);
    if (result_rect.IsEmpty()) {
        return FALSE;
    }
    m_ResultWidth = result_rect.Width();
    m_ResultHeight = result_rect.Height();
    m_ResultLeft = result_rect.left;
    m_ResultTop = result_rect.top;
    m_ClipLeft = result_rect.left - image_rect.left;
    m_ClipTop = result_rect.top - image_rect.top;
    CPDF_Dictionary* pDict = pImageObj->m_pImage->GetDict();
    if (pDict->GetInteger(FX_BSTRC("BitsPerComponent")) != 8) {
        return FALSE;
    }
    if (pDict->KeyExist(FX_BSTRC("SMask")) || pDict->KeyExist(FX_BSTRC("Mask"))) {
        return FALSE;
    }
    m_SrcWidth = pDict->GetInteger(FX_BSTRC("Width"));
    m_SrcHeight = pDict->GetInteger(FX_BSTRC("Height"));
    m_pCS = NULL;
    m_Bpp = 3;
    CPDF_Object* pCSObj = pDict->GetElementValue(FX_BSTRC("ColorSpace"));
    if (pCSObj == NULL) {
        return FALSE;
    }
    m_pCS = CPDF_ColorSpace::Load(pImageObj->m_pImage->GetDocument(), pCSObj);
    if (m_pCS == NULL) {
        return FALSE;
    }
    if (!_IsSupported(m_pCS)) {
        return FALSE;
    }
    m_Bpp = m_pCS->CountComponents();
    if (m_pCS->sRGB()) {
        m_pCS->ReleaseCS();
        m_pCS = NULL;
    }
    CPDF_Stream* pStream = pImageObj->m_pImage->GetStream();
    m_StreamAcc.LoadAllData(pStream, FALSE, m_SrcWidth * m_SrcHeight * m_Bpp,
                            TRUE);
    m_pDecoder = NULL;
    if (!m_StreamAcc.GetImageDecoder().IsEmpty()) {
        if (m_StreamAcc.GetImageDecoder() == FX_BSTRC("DCTDecode")) {
            const CPDF_Dictionary* pParam = m_StreamAcc.GetImageParam();
            m_pDecoder = CPDF_ModuleMgr::Get()->GetJpegModule()->CreateDecoder(
                             m_StreamAcc.GetData(), m_StreamAcc.GetSize(), m_SrcWidth, m_SrcHeight,
                             m_Bpp,
                             pParam ? pParam->GetInteger(FX_BSTRC("ColorTransform"), 1) : 1);
        } else if (m_StreamAcc.GetImageDecoder() == FX_BSTRC("FlateDecode")) {
            m_pDecoder = FPDFAPI_CreateFlateDecoder(
                             m_StreamAcc.GetData(), m_StreamAcc.GetSize(), m_SrcWidth, m_SrcHeight,
                             m_Bpp, 8, m_StreamAcc.GetImageParam());
        } else {
            return FALSE;
        }
        m_pDecoder->DownScale(m_DestWidth, m_DestHeight);
    }
    m_pBitmap = new CFX_DIBitmap;
#if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_
    m_pBitmap->Create(m_ResultWidth, m_ResultHeight, FXDIB_Rgb32);
#else
    m_pBitmap->Create(m_ResultWidth, m_ResultHeight, FXDIB_Rgb);
#endif
    m_LineIndex = 0;
    return TRUE;
}