Example #1
0
void CPDFSDK_BAAnnot::SetBorderDash(const CFX_IntArray& array) {
  CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDict("BS");
  if (!pBSDict) {
    pBSDict = new CPDF_Dictionary;
    m_pAnnot->GetAnnotDict()->SetAt("BS", pBSDict);
  }

  CPDF_Array* pArray = new CPDF_Array;
  for (int i = 0, sz = array.GetSize(); i < sz; i++) {
    pArray->AddInteger(array[i]);
  }

  pBSDict->SetAt("D", pArray);
}
Example #2
0
CPDF_Object* CPDF_Page::GetPageAttr(const CFX_ByteString& name) const {
  CPDF_Dictionary* pPageDict = m_pFormDict;
  std::set<CPDF_Dictionary*> visited;
  while (1) {
    visited.insert(pPageDict);
    if (CPDF_Object* pObj = pPageDict->GetDirectObjectFor(name))
      return pObj;

    pPageDict = pPageDict->GetDictFor("Parent");
    if (!pPageDict || pdfium::ContainsKey(visited, pPageDict))
      break;
  }
  return nullptr;
}
DLLEXPORT void STDCALL FPDFPage_SetCropBox(FPDF_PAGE page, float left, float bottom, float right, float top)
{
	if(!page)
		return;

	CPDF_Page* pPage = (CPDF_Page*)page;
	CPDF_Dictionary* pPageDict = pPage->m_pFormDict;
	CPDF_Array* pCropBoxArray = new CPDF_Array;
	pCropBoxArray->Add(new CPDF_Number(left));
	pCropBoxArray->Add(new CPDF_Number(bottom));
	pCropBoxArray->Add(new CPDF_Number(FX_FLOAT(right)));
	pCropBoxArray->Add(new CPDF_Number(FX_FLOAT(top)));
	pPageDict->SetAt("CropBox", pCropBoxArray);
}
Example #4
0
void RemoveInterFormFont(CPDF_Dictionary* pFormDict, CFX_ByteString csNameTag) {
  if (!pFormDict || csNameTag.IsEmpty()) {
    return;
  }
  CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR");
  if (!pDR) {
    return;
  }
  CPDF_Dictionary* pFonts = pDR->GetDictBy("Font");
  if (!pFonts) {
    return;
  }
  pFonts->RemoveAt(csNameTag);
}
int CPDF_Document::_GetPageCount() const {
    CPDF_Dictionary* pRoot = GetRoot();
    if (!pRoot) {
        return 0;
    }
    CPDF_Dictionary* pPages = pRoot->GetDict("Pages");
    if (!pPages) {
        return 0;
    }
    if (!pPages->KeyExist("Kids")) {
        return 1;
    }
    return _CountPages(pPages, 0);
}
Example #6
0
FX_BOOL CPDF_OCContext::LoadOCGState(const CPDF_Dictionary *pOCGDict) const
{
    if (!FPDFDOC_OCG_HasIntent(pOCGDict, FX_BSTRC("View"), FX_BSTRC("View"))) {
        return TRUE;
    }
    CFX_ByteString csState = FPDFDOC_OCG_GetUsageTypeString(m_eUsageType);
    CPDF_Dictionary *pUsage = pOCGDict->GetDict(FX_BSTRC("Usage"));
    if (pUsage) {
        CPDF_Dictionary *pState = pUsage->GetDict(csState);
        if (pState) {
            CFX_ByteString csFind = csState + FX_BSTRC("State");
            if (pState->KeyExist(csFind)) {
                return pState->GetString(csFind) != FX_BSTRC("OFF");
            }
        }
        if (csState != FX_BSTRC("View")) {
            pState = pUsage->GetDict(FX_BSTRC("View"));
            if (pState && pState->KeyExist(FX_BSTRC("ViewState"))) {
                return pState->GetString(FX_BSTRC("ViewState")) != FX_BSTRC("OFF");
            }
        }
    }
    FX_BOOL bDefValid = FALSE;
    return LoadOCGStateFromConfig(csState, pOCGDict, bDefValid);
}
Example #7
0
void CPDF_AnnotList::DisplayPass(CPDF_Page* pPage,
                                 CFX_RenderDevice* pDevice,
                                 CPDF_RenderContext* pContext,
                                 FX_BOOL bPrinting,
                                 CFX_Matrix* pMatrix,
                                 FX_BOOL bWidgetPass,
                                 CPDF_RenderOptions* pOptions,
                                 FX_RECT* clip_rect) {
  for (const auto& pAnnot : m_AnnotList) {
    bool bWidget = pAnnot->GetSubtype() == CPDF_Annot::Subtype::WIDGET;
    if ((bWidgetPass && !bWidget) || (!bWidgetPass && bWidget))
      continue;

    uint32_t annot_flags = pAnnot->GetFlags();
    if (annot_flags & ANNOTFLAG_HIDDEN)
      continue;

    if (bPrinting && (annot_flags & ANNOTFLAG_PRINT) == 0)
      continue;

    if (!bPrinting && (annot_flags & ANNOTFLAG_NOVIEW))
      continue;

    if (pOptions) {
      CPDF_OCContext* pOCContext = pOptions->m_pOCContext;
      CPDF_Dictionary* pAnnotDict = pAnnot->GetAnnotDict();
      if (pOCContext && pAnnotDict &&
          !pOCContext->CheckOCGVisible(pAnnotDict->GetDictBy("OC"))) {
        continue;
      }
    }
    CFX_FloatRect annot_rect_f = pAnnot->GetRect();
    CFX_Matrix matrix = *pMatrix;
    if (clip_rect) {
      annot_rect_f.Transform(&matrix);
      FX_RECT annot_rect = annot_rect_f.GetOuterRect();
      annot_rect.Intersect(*clip_rect);
      if (annot_rect.IsEmpty()) {
        continue;
      }
    }
    if (pContext) {
      pAnnot->DrawInContext(pPage, pContext, &matrix, CPDF_Annot::Normal);
    } else if (!pAnnot->DrawAppearance(pPage, pDevice, &matrix,
                                       CPDF_Annot::Normal, pOptions)) {
      pAnnot->DrawBorder(pDevice, &matrix, pOptions);
    }
  }
}
Example #8
0
FX_BOOL CPDF_StitchFunc::v_Init(CPDF_Object* pObj) {
  CPDF_Dictionary* pDict = pObj->GetDict();
  if (pDict == NULL) {
    return FALSE;
  }
  CPDF_Array* pArray = pDict->GetArray(FX_BSTRC("Functions"));
  if (pArray == NULL) {
    return FALSE;
  }
  m_nSubs = pArray->GetCount();
  if (m_nSubs == 0) {
    return FALSE;
  }
  m_pSubFunctions = FX_Alloc(CPDF_Function*, m_nSubs);
  m_nOutputs = 0;
  int i;
  for (i = 0; i < m_nSubs; i++) {
    CPDF_Object* pSub = pArray->GetElementValue(i);
    if (pSub == pObj) {
      return FALSE;
    }
    m_pSubFunctions[i] = CPDF_Function::Load(pSub);
    if (m_pSubFunctions[i] == NULL) {
      return FALSE;
    }
    if (m_pSubFunctions[i]->CountOutputs() > m_nOutputs) {
      m_nOutputs = m_pSubFunctions[i]->CountOutputs();
    }
  }
  m_pBounds = FX_Alloc(FX_FLOAT, m_nSubs + 1);
  m_pBounds[0] = m_pDomains[0];
  pArray = pDict->GetArray(FX_BSTRC("Bounds"));
  if (pArray == NULL) {
    return FALSE;
  }
  for (i = 0; i < m_nSubs - 1; i++) {
    m_pBounds[i + 1] = pArray->GetFloat(i);
  }
  m_pBounds[m_nSubs] = m_pDomains[1];
  m_pEncode = FX_Alloc2D(FX_FLOAT, m_nSubs, 2);
  pArray = pDict->GetArray(FX_BSTRC("Encode"));
  if (pArray == NULL) {
    return FALSE;
  }
  for (i = 0; i < m_nSubs * 2; i++) {
    m_pEncode[i] = pArray->GetFloat(i);
  }
  return TRUE;
}
Example #9
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;
}
Example #10
0
DLLEXPORT FPDF_DWORD STDCALL FPDF_CountNamedDests(FPDF_DOCUMENT document)
{
    if (!document) return 0;
    CPDF_Document* pDoc = (CPDF_Document*)document;

    CPDF_Dictionary* pRoot = pDoc->GetRoot();
    if (!pRoot) return 0;

    CPDF_NameTree nameTree(pDoc, FX_BSTRC("Dests"));
    int count = nameTree.GetCount();
    CPDF_Dictionary* pDest = pRoot->GetDict(FX_BSTRC("Dests"));
    if (pDest)
        count += pDest->GetCount();
    return count;
}
int CPDF_FormField::GetMaxLen() const {
  if (CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "MaxLen"))
    return pObj->GetInteger();

  for (int i = 0; i < m_ControlList.GetSize(); i++) {
    CPDF_FormControl* pControl = m_ControlList.GetAt(i);
    if (!pControl)
      continue;

    CPDF_Dictionary* pWidgetDict = pControl->m_pWidgetDict;
    if (pWidgetDict->KeyExist("MaxLen"))
      return pWidgetDict->GetIntegerBy("MaxLen");
  }
  return 0;
}
Example #12
0
void CPDF_Document::DeletePage(int iPage) {
  CPDF_Dictionary* pPages = GetPagesDict();
  if (!pPages)
    return;

  int nPages = pPages->GetIntegerFor("Count");
  if (iPage < 0 || iPage >= nPages)
    return;

  std::set<CPDF_Dictionary*> stack = {pPages};
  if (InsertDeletePDFPage(this, pPages, iPage, nullptr, FALSE, &stack) < 0)
    return;

  m_PageList.RemoveAt(iPage);
}
Example #13
0
void CPDF_InterForm::FixPageFields(const CPDF_Page* pPage) {
  CPDF_Dictionary* pPageDict = pPage->m_pFormDict;
  if (!pPageDict)
    return;

  CPDF_Array* pAnnots = pPageDict->GetArrayFor("Annots");
  if (!pAnnots)
    return;

  for (size_t i = 0; i < pAnnots->GetCount(); i++) {
    CPDF_Dictionary* pAnnot = pAnnots->GetDictAt(i);
    if (pAnnot && pAnnot->GetStringFor("Subtype") == "Widget")
      LoadField(pAnnot, 0);
  }
}
Example #14
0
void CPDF_Document::CreateNewDoc()
{
    ASSERT(m_pRootDict == NULL && m_pInfoDict == NULL);
    m_pRootDict = FX_NEW CPDF_Dictionary;
    m_pRootDict->SetAtName("Type", "Catalog");
    int objnum = AddIndirectObject(m_pRootDict);
    CPDF_Dictionary* pPages = FX_NEW CPDF_Dictionary;
    pPages->SetAtName("Type", "Pages");
    pPages->SetAtNumber("Count", 0);
    pPages->SetAt("Kids", FX_NEW CPDF_Array);
    objnum = AddIndirectObject(pPages);
    m_pRootDict->SetAtReference("Pages", this, objnum);
    m_pInfoDict = FX_NEW CPDF_Dictionary;
    AddIndirectObject(m_pInfoDict);
}
Example #15
0
CFX_ByteString CPDF_Action::GetURI(CPDF_Document* pDoc) const {
  CFX_ByteString csURI;
  if (!m_pDict)
    return csURI;
  if (m_pDict->GetStringFor("S") != "URI")
    return csURI;

  csURI = m_pDict->GetStringFor("URI");
  CPDF_Dictionary* pRoot = pDoc->GetRoot();
  CPDF_Dictionary* pURI = pRoot->GetDictFor("URI");
  if (pURI) {
    if (csURI.Find(":", 0) < 1)
      csURI = pURI->GetStringFor("Base") + csURI;
  }
  return csURI;
}
Example #16
0
// border
void CPDFSDK_BAAnnot::SetBorderWidth(int nWidth) {
  CPDF_Array* pBorder = m_pAnnot->GetAnnotDict()->GetArrayBy("Border");

  if (pBorder) {
    pBorder->SetAt(2, new CPDF_Number(nWidth));
  } else {
    CPDF_Dictionary* pBSDict = m_pAnnot->GetAnnotDict()->GetDictBy("BS");

    if (!pBSDict) {
      pBSDict = new CPDF_Dictionary;
      m_pAnnot->GetAnnotDict()->SetAt("BS", pBSDict);
    }

    pBSDict->SetAtInteger("W", nWidth);
  }
}
Example #17
0
CFX_WideString GetFullName(CPDF_Dictionary* pFieldDict) {
  CFX_WideString full_name;
  CPDF_Dictionary* pLevel = pFieldDict;
  while (pLevel) {
    CFX_WideString short_name = pLevel->GetUnicodeText("T");
    if (short_name != L"") {
      if (full_name == L"") {
        full_name = short_name;
      } else {
        full_name = short_name + L"." + full_name;
      }
    }
    pLevel = pLevel->GetDict("Parent");
  }
  return full_name;
}
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;
}
Example #19
0
void CPDF_AnnotList::DisplayPass(const CPDF_Page* pPage, CFX_RenderDevice* pDevice,
                                 CPDF_RenderContext* pContext, FX_BOOL bPrinting, CFX_AffineMatrix* pMatrix,
                                 FX_BOOL bWidgetPass, CPDF_RenderOptions* pOptions, FX_RECT* clip_rect)
{
    for (int i = 0; i < m_AnnotList.GetSize(); i ++) {
        CPDF_Annot* pAnnot = (CPDF_Annot*)m_AnnotList[i];
        FX_BOOL bWidget = pAnnot->GetSubType() == "Widget";
        if ((bWidgetPass && !bWidget) || (!bWidgetPass && bWidget)) {
            continue;
        }
        FX_DWORD annot_flags = pAnnot->GetFlags();
        if (annot_flags & ANNOTFLAG_HIDDEN) {
            continue;
        }
        if (bPrinting && (annot_flags & ANNOTFLAG_PRINT) == 0) {
            continue;
        }
        if (!bPrinting && (annot_flags & ANNOTFLAG_NOVIEW)) {
            continue;
        }
        if (pOptions != NULL) {
            IPDF_OCContext* pOCContext = pOptions->m_pOCContext;
            CPDF_Dictionary* pAnnotDict = pAnnot->m_pAnnotDict;
            if (pOCContext != NULL && pAnnotDict != NULL &&
                    !pOCContext->CheckOCGVisible(pAnnotDict->GetDict(FX_BSTRC("OC")))) {
                continue;
            }
        }
        CPDF_Rect annot_rect_f;
        pAnnot->GetRect(annot_rect_f);
        CFX_Matrix matrix;
        matrix = *pMatrix;
        if (clip_rect) {
            annot_rect_f.Transform(&matrix);
            FX_RECT annot_rect = annot_rect_f.GetOutterRect();
            annot_rect.Intersect(*clip_rect);
            if (annot_rect.IsEmpty()) {
                continue;
            }
        }
        if (pContext) {
            pAnnot->DrawInContext(pPage, pContext, &matrix, CPDF_Annot::Normal);
        } else if (!pAnnot->DrawAppearance(pPage, pDevice, &matrix, CPDF_Annot::Normal, pOptions)) {
            pAnnot->DrawBorder(pDevice, &matrix, pOptions);
        }
    }
}
void InitInterFormDict(CPDF_Dictionary*& pFormDict, CPDF_Document* pDocument)
{
    if (pDocument == NULL) {
        return;
    }
    if (pFormDict == NULL) {
        pFormDict = CPDF_Dictionary::Create();
        if (pFormDict == NULL) {
            return;
        }
        FX_DWORD dwObjNum = pDocument->AddIndirectObject(pFormDict);
        CPDF_Dictionary* pRoot = pDocument->GetRoot();
        pRoot->SetAtReference("AcroForm", pDocument, dwObjNum);
    }
    CFX_ByteString csDA;
    if (!pFormDict->KeyExist("DR")) {
        CPDF_Font* pFont = NULL;
        CFX_ByteString csBaseName, csDefault;
        FX_BYTE charSet = CPDF_InterForm::GetNativeCharSet();
        pFont = CPDF_InterForm::AddStandardFont(pDocument, "Helvetica");
        if (pFont != NULL) {
            AddInterFormFont(pFormDict, pDocument, pFont, csBaseName);
            csDefault = csBaseName;
        }
        if (charSet != 0) {
            CFX_ByteString csFontName = CPDF_InterForm::GetNativeFont(charSet, NULL);
            if (pFont == NULL || csFontName != "Helvetica") {
                pFont = CPDF_InterForm::AddNativeFont(pDocument);
                if (pFont != NULL) {
                    csBaseName = "";
                    AddInterFormFont(pFormDict, pDocument, pFont, csBaseName);
                    csDefault = csBaseName;
                }
            }
        }
        if (pFont != NULL) {
            csDA = "/" + PDF_NameEncode(csDefault) + " 0 Tf";
        }
    }
    if (!csDA.IsEmpty()) {
        csDA += " ";
    }
    csDA += "0 g";
    if (!pFormDict->KeyExist("DA")) {
        pFormDict->SetAtString("DA", csDA);
    }
}
Example #21
0
FX_BOOL CPDF_CalGray::v_Load(CPDF_Document* pDoc, CPDF_Array* pArray) {
  CPDF_Dictionary* pDict = pArray->GetDict(1);
  CPDF_Array* pParam = pDict->GetArray(FX_BSTRC("WhitePoint"));
  int i;
  for (i = 0; i < 3; i++) {
    m_WhitePoint[i] = pParam ? pParam->GetNumber(i) : 0;
  }
  pParam = pDict->GetArray(FX_BSTRC("BlackPoint"));
  for (i = 0; i < 3; i++) {
    m_BlackPoint[i] = pParam ? pParam->GetNumber(i) : 0;
  }
  m_Gamma = pDict->GetNumber(FX_BSTRC("Gamma"));
  if (m_Gamma == 0) {
    m_Gamma = 1.0f;
  }
  return TRUE;
}
Example #22
0
CPDF_Array* CPDF_NameTree::LookupNamedDest(CPDF_Document* pDoc,
                                           const CFX_ByteStringC& sName) {
  CPDF_Object* pValue = LookupValue(sName);
  if (!pValue) {
    CPDF_Dictionary* pDests = pDoc->GetRoot()->GetDictBy("Dests");
    if (!pDests)
      return nullptr;
    pValue = pDests->GetElementValue(sName);
  }
  if (!pValue)
    return nullptr;
  if (CPDF_Array* pArray = pValue->AsArray())
    return pArray;
  if (CPDF_Dictionary* pDict = pValue->AsDictionary())
    return pDict->GetArrayBy("D");
  return nullptr;
}
Example #23
0
CPDF_Stream* CPDF_FileSpec::GetFileStream() const
{
    if (m_pObj == NULL) {
        return NULL;
    }
    FX_INT32 iType = m_pObj->GetType();
    if (iType == PDFOBJ_STREAM) {
        return (CPDF_Stream*)m_pObj;
    } else if (iType == PDFOBJ_DICTIONARY) {
        CPDF_Dictionary *pEF = ((CPDF_Dictionary*)m_pObj)->GetDict(FX_BSTRC("EF"));
        if (pEF == NULL) {
            return NULL;
        }
        return pEF->GetStream(FX_BSTRC("F"));
    }
    return NULL;
}
DLLEXPORT FPDF_BOOL STDCALL FPDFPage_GetCropBox(FPDF_PAGE page, float* left, float* bottom, float* right, float* top)
{
	if(!page)
		return FALSE;
	CPDF_Page* pPage = (CPDF_Page*)page;
	CPDF_Dictionary* pPageDict = pPage->m_pFormDict;
	CPDF_Array* pArray = pPageDict->GetArray("CropBox");
	if(pArray)
	{
		*left = pArray->GetFloat(0);
		*bottom = pArray->GetFloat(1);
		*right = pArray->GetFloat(2);
		*top = pArray->GetFloat(3);
		return TRUE;
	}
	return FALSE;
}
void CPDF_LinkList::LoadPageLinks(CPDF_Page* pPage, CFX_PtrArray* pList)
{
    CPDF_Array* pAnnotList = pPage->m_pFormDict->GetArray("Annots");
    if (pAnnotList == NULL) {
        return;
    }
    for (FX_DWORD i = 0; i < pAnnotList->GetCount(); i ++) {
        CPDF_Dictionary* pAnnot = pAnnotList->GetDict(i);
        if (pAnnot == NULL) {
            continue;
        }
        if (pAnnot->GetString("Subtype") != "Link") {
            continue;
        }
        pList->Add(pAnnot);
    }
}
void PDF_ReplaceAbbr(CPDF_Object* pObj) {
  switch (pObj->GetType()) {
    case PDFOBJ_DICTIONARY: {
      CPDF_Dictionary* pDict = pObj->AsDictionary();
      for (const auto& it : *pDict) {
        CFX_ByteString key = it.first;
        CPDF_Object* value = it.second;
        CFX_ByteStringC fullname = PDF_FindFullName(
            PDF_InlineKeyAbbr, FX_ArraySize(PDF_InlineKeyAbbr), key);
        if (!fullname.IsEmpty()) {
          pDict->ReplaceKey(key, fullname);
          key = fullname;
        }

        if (value->IsName()) {
          CFX_ByteString name = value->GetString();
          fullname = PDF_FindFullName(PDF_InlineValueAbbr,
                                      FX_ArraySize(PDF_InlineValueAbbr), name);
          if (!fullname.IsEmpty()) {
            pDict->SetAtName(key, fullname);
          }
        } else {
          PDF_ReplaceAbbr(value);
        }
      }
      break;
    }
    case PDFOBJ_ARRAY: {
      CPDF_Array* pArray = pObj->AsArray();
      for (FX_DWORD i = 0; i < pArray->GetCount(); i++) {
        CPDF_Object* pElement = pArray->GetElement(i);
        if (pElement->IsName()) {
          CFX_ByteString name = pElement->GetString();
          CFX_ByteStringC fullname = PDF_FindFullName(
              PDF_InlineValueAbbr, FX_ArraySize(PDF_InlineValueAbbr), name);
          if (!fullname.IsEmpty()) {
            pArray->SetAt(i, new CPDF_Name(fullname));
          }
        } else {
          PDF_ReplaceAbbr(pElement);
        }
      }
      break;
    }
  }
}
Example #27
0
FX_BOOL FindInterFormFont(CPDF_Dictionary* pFormDict,
                          CPDF_Document* pDocument,
                          CFX_ByteString csFontName,
                          CPDF_Font*& pFont,
                          CFX_ByteString& csNameTag) {
  if (!pFormDict) {
    return FALSE;
  }
  CPDF_Dictionary* pDR = pFormDict->GetDict("DR");
  if (!pDR) {
    return FALSE;
  }
  CPDF_Dictionary* pFonts = pDR->GetDict("Font");
  if (!pFonts) {
    return FALSE;
  }
  if (csFontName.GetLength() > 0) {
    csFontName.Remove(' ');
  }
  for (const auto& it : *pFonts) {
    const CFX_ByteString& csKey = it.first;
    CPDF_Object* pObj = it.second;
    if (!pObj) {
      continue;
    }
    CPDF_Dictionary* pElement = ToDictionary(pObj->GetDirect());
    if (!pElement)
      continue;
    if (pElement->GetString("Type") != "Font") {
      continue;
    }
    pFont = pDocument->LoadFont(pElement);
    if (!pFont) {
      continue;
    }
    CFX_ByteString csBaseFont;
    csBaseFont = pFont->GetBaseFont();
    csBaseFont.Remove(' ');
    if (csBaseFont == csFontName) {
      csNameTag = csKey;
      return TRUE;
    }
  }
  return FALSE;
}
void CPDF_FormField::LoadDA() {
  CPDF_Dictionary* pFormDict = m_pForm->m_pFormDict;
  if (!pFormDict)
    return;

  CFX_ByteString DA;
  if (CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "DA"))
    DA = pObj->GetString();

  if (DA.IsEmpty())
    DA = pFormDict->GetStringBy("DA");

  if (DA.IsEmpty())
    return;

  CPDF_Dictionary* pDR = pFormDict->GetDictBy("DR");
  if (!pDR)
    return;

  CPDF_Dictionary* pFont = pDR->GetDictBy("Font");
  if (!pFont)
    return;

  CPDF_SimpleParser syntax(DA.AsStringC());
  syntax.FindTagParamFromStart("Tf", 2);
  CFX_ByteString font_name(syntax.GetWord());
  CPDF_Dictionary* pFontDict = pFont->GetDictBy(font_name);
  if (!pFontDict)
    return;

  m_pFont = m_pForm->m_pDocument->LoadFont(pFontDict);
  m_FontSize = FX_atof(syntax.GetWord());
}
Example #29
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;
}
Example #30
0
static int InsertNewPage(CPDF_Document* pDoc, int iPage, CPDF_Dictionary* pPageDict, CFX_DWordArray &pageList)
{
    CPDF_Dictionary* pRoot = pDoc->GetRoot();
    if (!pRoot) {
        return -1;
    }
    CPDF_Dictionary* pPages = pRoot->GetDict(FX_BSTRC("Pages"));
    if (!pPages) {
        return -1;
    }
    int nPages = pDoc->GetPageCount();
    if (iPage < 0 || iPage > nPages) {
        return -1;
    }
    if (iPage == nPages) {
        CPDF_Array* pPagesList = pPages->GetArray(FX_BSTRC("Kids"));
        if (!pPagesList) {
            pPagesList = FX_NEW CPDF_Array;
            pPages->SetAt(FX_BSTRC("Kids"), pPagesList);
        }
        pPagesList->Add(pPageDict, pDoc);
        pPages->SetAtInteger(FX_BSTRC("Count"), nPages + 1);
        pPageDict->SetAtReference(FX_BSTRC("Parent"), pDoc, pPages->GetObjNum());
    } else {
        CFX_PtrArray stack;
        stack.Add(pPages);
        if (InsertDeletePDFPage(pDoc, pPages, iPage, pPageDict, TRUE, stack) < 0) {
            return -1;
        }
    }
    pageList.InsertAt(iPage, pPageDict->GetObjNum());
    return iPage;
}