void CPDF_Document::LoadAsynDoc(CPDF_Dictionary* pLinearized) {
    m_bLinearized = TRUE;
    m_LastObjNum = m_pParser->GetLastObjNum();
    CPDF_Object* pIndirectObj =
        GetIndirectObject(m_pParser->GetRootObjNum(), nullptr);
    m_pRootDict = pIndirectObj ? pIndirectObj->GetDict() : nullptr;
    if (!m_pRootDict) {
        return;
    }
    pIndirectObj = GetIndirectObject(m_pParser->GetInfoObjNum(), nullptr);
    m_pInfoDict = pIndirectObj ? pIndirectObj->GetDict() : nullptr;
    CPDF_Array* pIDArray = m_pParser->GetIDArray();
    if (pIDArray) {
        m_ID1 = pIDArray->GetString(0);
        m_ID2 = pIDArray->GetString(1);
    }
    FX_DWORD dwPageCount = 0;
    CPDF_Object* pCount = pLinearized->GetElement("N");
    if (ToNumber(pCount))
        dwPageCount = pCount->GetInteger();

    m_PageList.SetSize(dwPageCount);
    CPDF_Object* pNo = pLinearized->GetElement("P");
    if (ToNumber(pNo))
        m_dwFirstPageNo = pNo->GetInteger();

    CPDF_Object* pObjNum = pLinearized->GetElement("O");
    if (ToNumber(pObjNum))
        m_dwFirstPageObjNum = pObjNum->GetInteger();
}
int CPDF_Dictionary::GetInteger(const CFX_ByteStringC& key, int def) const {
  CPDF_Object* p = GetElement(key);
  if (p) {
    return p->GetInteger();
  }
  return def;
}
Example #3
0
int CPDF_Object::GetInteger() const
{
    CFX_AutoRestorer<int> restorer(&s_nCurRefDepth);
    if (++s_nCurRefDepth > OBJECT_REF_MAX_DEPTH) {
        return 0;
    }
    switch (m_Type) {
        case PDFOBJ_BOOLEAN:
            return ((CPDF_Boolean*)this)->m_bValue;
        case PDFOBJ_NUMBER:
            return ((CPDF_Number*)this)->GetInteger();
        case PDFOBJ_REFERENCE: {
                CPDF_Reference* pRef = (CPDF_Reference*)(FX_LPVOID)this;
                PARSE_CONTEXT context;
                FXSYS_memset32(&context, 0, sizeof(PARSE_CONTEXT));
                if (pRef->m_pObjList == NULL) {
                    return 0;
                }
                CPDF_Object* pObj = pRef->m_pObjList->GetIndirectObject(pRef->m_RefObjNum, &context);
                if (pObj == NULL) {
                    return 0;
                }
                return pObj->GetInteger();
            }
    }
    return 0;
}
FX_BOOL CPDF_Dictionary::GetBoolean(const CFX_ByteStringC& key,
                                    FX_BOOL bDefault) const {
  CPDF_Object* p = GetElement(key);
  if (ToBoolean(p))
    return p->GetInteger();
  return bDefault;
}
Example #5
0
DLLEXPORT int STDCALL FPDFPage_GetRotation(FPDF_PAGE page) {
  CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
  if (!pPage || !pPage->m_pFormDict || !pPage->m_pFormDict->KeyExist("Type") ||
      !pPage->m_pFormDict->GetElement("Type")->GetDirect() ||
      pPage->m_pFormDict->GetElement("Type")->GetDirect()->GetString().Compare(
          "Page")) {
    return -1;
  }
  CPDF_Dictionary* pDict = pPage->m_pFormDict;
  if (!pDict)
    return -1;

  while (pDict) {
    if (pDict->KeyExist("Rotate")) {
      CPDF_Object* pRotateObj = pDict->GetElement("Rotate")->GetDirect();
      return pRotateObj ? pRotateObj->GetInteger() / 90 : 0;
    }
    if (!pDict->KeyExist("Parent"))
      break;

    pDict = ToDictionary(pDict->GetElement("Parent")->GetDirect());
  }

  return 0;
}
uint32_t CPDF_FormField::GetFieldFlags() const {
  CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "Ff");
  if (!pObj) {
    return 0;
  }
  return pObj->GetInteger();
}
Example #7
0
int CPDF_FormField::GetTopVisibleIndex() {
  CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "TI");
  if (!pObj) {
    return 0;
  }
  return pObj->GetInteger();
}
Example #8
0
FX_DWORD CPDF_FormField::GetFieldFlags() {
  CPDF_Object* pObj = FPDF_GetFieldAttr(m_pDict, "Ff");
  if (!pObj) {
    return 0;
  }
  return pObj->GetInteger();
}
Example #9
0
int CPDF_Array::GetInteger(FX_DWORD i) const
{
    if (i >= (FX_DWORD)m_Objects.GetSize()) {
        return 0;
    }
    CPDF_Object* p = (CPDF_Object*)m_Objects.GetAt(i);
    return p->GetInteger();
}
Example #10
0
int	CPDF_StructElementImpl::GetInteger(FX_BSTR owner, FX_BSTR name, int default_value, FX_BOOL bInheritable, int subindex)
{
    CPDF_Object* pAttr = GetAttr(owner, name, bInheritable, subindex);
    if (pAttr == NULL || pAttr->GetType() != PDFOBJ_NUMBER) {
        return default_value;
    }
    return pAttr->GetInteger();
}
Example #11
0
int CPDF_StructElementImpl::GetInteger(const CFX_ByteStringC& owner,
                                       const CFX_ByteStringC& name,
                                       int default_value,
                                       FX_BOOL bInheritable,
                                       int subindex) {
  CPDF_Object* pAttr = GetAttr(owner, name, bInheritable, subindex);
  return ToNumber(pAttr) ? pAttr->GetInteger() : default_value;
}
Example #12
0
FX_BOOL Document::info(IFXJS_Context* cc, CJS_PropValue& vp, CFX_WideString& sError)
{
	ASSERT(m_pDocument != NULL);

	CPDF_Dictionary* pDictionary = m_pDocument->GetDocument()->GetInfo();
	if (!pDictionary)return FALSE;

	CFX_WideString cwAuthor			= pDictionary->GetUnicodeText("Author");
	CFX_WideString cwTitle			= pDictionary->GetUnicodeText("Title");
	CFX_WideString cwSubject		= pDictionary->GetUnicodeText("Subject");
	CFX_WideString cwKeywords		= pDictionary->GetUnicodeText("Keywords");
	CFX_WideString cwCreator		= pDictionary->GetUnicodeText("Creator");
	CFX_WideString cwProducer		= pDictionary->GetUnicodeText("Producer");
	CFX_WideString cwCreationDate	= pDictionary->GetUnicodeText("CreationDate");
	CFX_WideString cwModDate		= pDictionary->GetUnicodeText("ModDate");
	CFX_WideString cwTrapped		= pDictionary->GetUnicodeText("Trapped");

	v8::Isolate* isolate = GetIsolate(cc);
	if (vp.IsGetting())
	{
		CJS_Context* pContext = (CJS_Context *)cc;
		CJS_Runtime* pRuntime = pContext->GetJSRuntime();

		JSFXObject  pObj = JS_NewFxDynamicObj(*pRuntime, pContext, -1);

		JS_PutObjectString(isolate, pObj, L"Author", cwAuthor.c_str());
		JS_PutObjectString(isolate, pObj, L"Title", cwTitle.c_str());
		JS_PutObjectString(isolate, pObj, L"Subject", cwSubject.c_str());
		JS_PutObjectString(isolate, pObj, L"Keywords", cwKeywords.c_str());
		JS_PutObjectString(isolate, pObj, L"Creator", cwCreator.c_str());
		JS_PutObjectString(isolate, pObj, L"Producer", cwProducer.c_str());
		JS_PutObjectString(isolate, pObj, L"CreationDate", cwCreationDate.c_str());
		JS_PutObjectString(isolate, pObj, L"ModDate", cwModDate.c_str());
		JS_PutObjectString(isolate, pObj, L"Trapped", cwTrapped.c_str());

// It's to be compatible to non-standard info dictionary.
		FX_POSITION pos = pDictionary->GetStartPos();
		while(pos)
		{
			CFX_ByteString bsKey;
			CPDF_Object* pValueObj = pDictionary->GetNextElement(pos, bsKey);
			CFX_WideString wsKey  = CFX_WideString::FromUTF8(bsKey, bsKey.GetLength());
			if((pValueObj->GetType()==PDFOBJ_STRING) || (pValueObj->GetType()==PDFOBJ_NAME) )
				JS_PutObjectString(isolate, pObj, wsKey.c_str(), pValueObj->GetUnicodeText().c_str());
			if(pValueObj->GetType()==PDFOBJ_NUMBER)
				JS_PutObjectNumber(isolate,pObj, wsKey.c_str(), (float)pValueObj->GetNumber());
			if(pValueObj->GetType()==PDFOBJ_BOOLEAN)
				JS_PutObjectBoolean(isolate,pObj, wsKey.c_str(), (bool)pValueObj->GetInteger());
		}

		vp << pObj;
		return TRUE;
	}
	else
	{
		return TRUE;
	}
}
Example #13
0
void CPDF_CIDFont::LoadMetricsArray(CPDF_Array* pArray,
                                    std::vector<uint32_t>* result,
                                    int nElements) {
  int width_status = 0;
  int iCurElement = 0;
  int first_code = 0;
  int last_code = 0;
  for (size_t i = 0; i < pArray->GetCount(); i++) {
    CPDF_Object* pObj = pArray->GetDirectObjectAt(i);
    if (!pObj)
      continue;

    if (CPDF_Array* pObjArray = pObj->AsArray()) {
      if (width_status != 1)
        return;

      for (size_t j = 0; j < pObjArray->GetCount(); j += nElements) {
        result->push_back(first_code);
        result->push_back(first_code);
        for (int k = 0; k < nElements; k++)
          result->push_back(pObjArray->GetIntegerAt(j + k));
        first_code++;
      }
      width_status = 0;
    } else {
      if (width_status == 0) {
        first_code = pObj->GetInteger();
        width_status = 1;
      } else if (width_status == 1) {
        last_code = pObj->GetInteger();
        width_status = 2;
        iCurElement = 0;
      } else {
        if (!iCurElement) {
          result->push_back(first_code);
          result->push_back(last_code);
        }
        result->push_back(pObj->GetInteger());
        iCurElement++;
        if (iCurElement == nElements)
          width_status = 0;
      }
    }
  }
}
Example #14
0
int CPDF_Dictionary::GetInteger(const CFX_ByteStringC& key) const
{
    CPDF_Object* p = NULL;
    m_Map.Lookup(key, (void*&)p);
    if (p) {
        return p->GetInteger();
    }
    return 0;
}
Example #15
0
int CPDF_Dictionary::GetInteger(FX_BSTR key, int def) const
{
    CPDF_Object* p = NULL;
    m_Map.Lookup(key, (void*&)p);
    if (p) {
        return p->GetInteger();
    }
    return def;
}
Example #16
0
FX_BOOL CPDF_Dictionary::GetBoolean(FX_BSTR key, FX_BOOL bDefault) const
{
    CPDF_Object* p = NULL;
    m_Map.Lookup(key, (void*&)p);
    if (p && p->GetType() == PDFOBJ_BOOLEAN) {
        return p->GetInteger();
    }
    return bDefault;
}
Example #17
0
void CPDF_Document::LoadLinearizedDoc(CPDF_Dictionary* pLinearizationParams) {
  m_bLinearized = true;
  LoadDocInternal();

  uint32_t dwPageCount = 0;
  CPDF_Object* pCount = pLinearizationParams->GetObjectFor("N");
  if (ToNumber(pCount))
    dwPageCount = pCount->GetInteger();
  m_PageList.SetSize(dwPageCount);

  CPDF_Object* pNo = pLinearizationParams->GetObjectFor("P");
  if (ToNumber(pNo))
    m_iFirstPageNo = pNo->GetInteger();

  CPDF_Object* pObjNum = pLinearizationParams->GetObjectFor("O");
  if (ToNumber(pObjNum))
    m_dwFirstPageObjNum = pObjNum->GetInteger();
}
int CPDF_Dictionary::GetInteger(FX_BSTR key) const
{
    if (this) {
        CPDF_Object* p = NULL;
        m_Map.Lookup(key, (void*&)p);
        if (p) {
            return p->GetInteger();
        }
    }
    return 0;
}
Example #19
0
int CPDF_FormControl::GetControlAlignment() {
    if (!m_pWidgetDict)
        return 0;
    if (m_pWidgetDict->KeyExist("Q"))
        return m_pWidgetDict->GetIntegerBy("Q", 0);

    CPDF_Object* pObj = FPDF_GetFieldAttr(m_pField->m_pDict, "Q");
    if (pObj)
        return pObj->GetInteger();
    return m_pField->m_pForm->GetFormAlignment();
}
Example #20
0
uint32_t CPDF_Dest::GetPageObjNum() {
  CPDF_Array* pArray = ToArray(m_pObj);
  if (!pArray)
    return 0;

  CPDF_Object* pPage = pArray->GetDirectObjectAt(0);
  if (!pPage)
    return 0;
  if (pPage->IsNumber())
    return pPage->GetInteger();
  if (pPage->IsDictionary())
    return pPage->GetObjNum();
  return 0;
}
Example #21
0
int CPDF_Dest::GetPageIndex(CPDF_Document* pDoc) {
  CPDF_Array* pArray = ToArray(m_pObj);
  if (!pArray)
    return 0;

  CPDF_Object* pPage = pArray->GetElementValue(0);
  if (!pPage)
    return 0;
  if (pPage->IsNumber())
    return pPage->GetInteger();
  if (!pPage->IsDictionary())
    return 0;
  return pDoc->GetPageIndex(pPage->GetObjNum());
}
Example #22
0
FX_DWORD CPDF_Dest::GetPageObjNum() {
  CPDF_Array* pArray = ToArray(m_pObj);
  if (!pArray)
    return 0;

  CPDF_Object* pPage = pArray->GetElementValue(0);
  if (!pPage)
    return 0;
  if (pPage->IsNumber())
    return pPage->GetInteger();
  if (pPage->IsDictionary())
    return pPage->GetObjNum();
  return 0;
}
FX_BOOL CPDF_FormField::IsItemSelected(int index)
{
    ASSERT(GetType() == ComboBox || GetType() == ListBox);
    if (index < 0 || index >= CountOptions()) {
        return FALSE;
    }
    if (IsOptionSelected(index)) {
        return TRUE;
    }
    CFX_WideString opt_value = GetOptionValue(index);
    CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V");
    if (pValue == NULL) {
        pValue = FPDF_GetFieldAttr(m_pDict, "I");
        if (pValue == NULL) {
            return FALSE;
        }
    }
    if (pValue->GetType() == PDFOBJ_STRING) {
        if (pValue->GetUnicodeText() == opt_value) {
            return TRUE;
        }
        return FALSE;
    }
    if (pValue->GetType() == PDFOBJ_NUMBER) {
        if (pValue->GetString().IsEmpty()) {
            return FALSE;
        }
        if (pValue->GetInteger() == index) {
            return TRUE;
        }
        return FALSE;
    }
    if (pValue->GetType() != PDFOBJ_ARRAY) {
        return FALSE;
    }
    CPDF_Array* pArray = (CPDF_Array*)pValue;
    int iPos = -1;
    for (int j = 0; j < CountSelectedOptions(); j ++) {
        if (GetSelectedOptionIndex(j) == index) {
            iPos = j;
            break;
        }
    }
    for (FX_DWORD i = 0; i < pArray->GetCount(); i ++)
        if (pArray->GetElementValue(i)->GetUnicodeText() == opt_value && (int)i == iPos) {
            return TRUE;
        }
    return FALSE;
}
Example #24
0
int CPDF_FormControl::GetControlAlignment()
{
    if (m_pWidgetDict == NULL) {
        return 0;
    }
    if (m_pWidgetDict->KeyExist("Q")) {
        return m_pWidgetDict->GetInteger("Q", 0);
    } else {
        CPDF_Object* pObj = FPDF_GetFieldAttr(m_pField->m_pDict, "Q");
        if (pObj == NULL) {
            return m_pField->m_pForm->GetFormAlignment();
        }
        return pObj->GetInteger();
    }
}
Example #25
0
int CPDF_Dest::GetPageIndex(CPDF_Document* pDoc)
{
    if (m_pObj == NULL || m_pObj->GetType() != PDFOBJ_ARRAY) {
        return 0;
    }
    CPDF_Object* pPage = ((CPDF_Array*)m_pObj)->GetElementValue(0);
    if (pPage == NULL) {
        return 0;
    }
    if (pPage->GetType() == PDFOBJ_NUMBER) {
        return pPage->GetInteger();
    }
    if (pPage->GetType() != PDFOBJ_DICTIONARY) {
        return 0;
    }
    return pDoc->GetPageIndex(pPage->GetObjNum());
}
Example #26
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();
}
FX_BOOL CPDF_FormField::IsItemSelected(int index) const {
  ASSERT(GetType() == ComboBox || GetType() == ListBox);
  if (index < 0 || index >= CountOptions()) {
    return FALSE;
  }
  if (IsOptionSelected(index)) {
    return TRUE;
  }
  CFX_WideString opt_value = GetOptionValue(index);
  CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V");
  if (!pValue) {
    pValue = FPDF_GetFieldAttr(m_pDict, "I");
    if (!pValue) {
      return FALSE;
    }
  }

  if (pValue->IsString())
    return pValue->GetUnicodeText() == opt_value;

  if (pValue->IsNumber()) {
    if (pValue->GetString().IsEmpty())
      return FALSE;
    return (pValue->GetInteger() == index);
  }

  CPDF_Array* pArray = pValue->AsArray();
  if (!pArray)
    return FALSE;

  int iPos = -1;
  for (int j = 0; j < CountSelectedOptions(); j++) {
    if (GetSelectedOptionIndex(j) == index) {
      iPos = j;
      break;
    }
  }
  for (int i = 0; i < static_cast<int>(pArray->GetCount()); i++)
    if (pArray->GetDirectObjectAt(i)->GetUnicodeText() == opt_value &&
        i == iPos) {
      return TRUE;
    }
  return FALSE;
}
Example #28
0
DLLEXPORT int STDCALL FPDFPage_GetRotation(FPDF_PAGE page) {
  CPDF_Page* pPage = CPDFPageFromFPDFPage(page);
  if (!IsPageObject(pPage))
    return -1;

  CPDF_Dictionary* pDict = pPage->m_pFormDict;
  while (pDict) {
    if (pDict->KeyExist("Rotate")) {
      CPDF_Object* pRotateObj = pDict->GetObjectBy("Rotate")->GetDirect();
      return pRotateObj ? pRotateObj->GetInteger() / 90 : 0;
    }
    if (!pDict->KeyExist("Parent"))
      break;

    pDict = ToDictionary(pDict->GetObjectBy("Parent")->GetDirect());
  }

  return 0;
}
Example #29
0
int CPDF_FormField::GetSelectedIndex(int index) {
  CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V");
  if (pValue == NULL) {
    pValue = FPDF_GetFieldAttr(m_pDict, "I");
    if (pValue == NULL) {
      return -1;
    }
  }
  if (pValue->GetType() == PDFOBJ_NUMBER) {
    return pValue->GetInteger();
  }
  CFX_WideString sel_value;
  if (pValue->GetType() == PDFOBJ_STRING) {
    if (index != 0) {
      return -1;
    }
    sel_value = pValue->GetUnicodeText();
  } else {
    if (pValue->GetType() != PDFOBJ_ARRAY) {
      return -1;
    }
    if (index < 0) {
      return -1;
    }
    CPDF_Object* elementValue = ((CPDF_Array*)pValue)->GetElementValue(index);
    sel_value =
        elementValue ? elementValue->GetUnicodeText() : CFX_WideString();
  }
  if (index < CountSelectedOptions()) {
    int iOptIndex = GetSelectedOptionIndex(index);
    CFX_WideString csOpt = GetOptionValue(iOptIndex);
    if (csOpt == sel_value) {
      return iOptIndex;
    }
  }
  int nOpts = CountOptions();
  for (int i = 0; i < nOpts; i++) {
    if (sel_value == GetOptionValue(i)) {
      return i;
    }
  }
  return -1;
}
Example #30
0
int CPDF_FormField::GetSelectedIndex(int index) {
  CPDF_Object* pValue = FPDF_GetFieldAttr(m_pDict, "V");
  if (!pValue) {
    pValue = FPDF_GetFieldAttr(m_pDict, "I");
    if (!pValue)
      return -1;
  }
  if (pValue->IsNumber())
    return pValue->GetInteger();

  CFX_WideString sel_value;
  if (pValue->IsString()) {
    if (index != 0)
      return -1;
    sel_value = pValue->GetUnicodeText();
  } else {
    CPDF_Array* pArray = pValue->AsArray();
    if (!pArray || index < 0)
      return -1;

    CPDF_Object* elementValue = pArray->GetElementValue(index);
    sel_value =
        elementValue ? elementValue->GetUnicodeText() : CFX_WideString();
  }
  if (index < CountSelectedOptions()) {
    int iOptIndex = GetSelectedOptionIndex(index);
    CFX_WideString csOpt = GetOptionValue(iOptIndex);
    if (csOpt == sel_value) {
      return iOptIndex;
    }
  }
  int nOpts = CountOptions();
  for (int i = 0; i < nOpts; i++) {
    if (sel_value == GetOptionValue(i)) {
      return i;
    }
  }
  return -1;
}