FX_FLOAT CPDF_Dictionary::GetNumber(const CFX_ByteStringC& key) const { CPDF_Object* p = GetElement(key); if (p) { return p->GetNumber(); } return 0; }
FX_FLOAT CPDF_Array::GetNumber(FX_DWORD i) const { if (i >= (FX_DWORD)m_Objects.GetSize()) { return 0; } CPDF_Object* p = (CPDF_Object*)m_Objects.GetAt(i); return p->GetNumber(); }
FX_FLOAT CPDF_StructElementImpl::GetNumber(const CFX_ByteStringC& owner, const CFX_ByteStringC& name, FX_FLOAT default_value, FX_BOOL bInheritable, int subindex) { CPDF_Object* pAttr = GetAttr(owner, name, bInheritable, subindex); return ToNumber(pAttr) ? pAttr->GetNumber() : default_value; }
FX_FLOAT CPDF_StructElementImpl::GetNumber(FX_BSTR owner, FX_BSTR name, FX_FLOAT 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->GetNumber(); }
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; } }
FX_FLOAT CPDF_Dictionary::GetNumber(FX_BSTR key) const { CPDF_Object* p = NULL; m_Map.Lookup(key, (void*&)p); if (p) { return p->GetNumber(); } return 0; }
FX_FLOAT CPDF_Object::GetNumber() const { switch (m_Type) { case PDFOBJ_NUMBER: return AsNumber()->GetNumber(); case PDFOBJ_REFERENCE: { const CPDF_Reference* pRef = AsReference(); if (!pRef->m_pObjList) break; CPDF_Object* pObj = pRef->m_pObjList->GetIndirectObject(pRef->GetRefObjNum(), nullptr); return pObj ? pObj->GetNumber() : 0; } } return 0; }
void CPDF_StreamContentParser::Handle_ShowText_Positioning() { CPDF_Array* pArray = GetObject(0) ? GetObject(0)->GetArray() : NULL; if (!pArray) { return; } int n = pArray->GetCount(); int nsegs = 0; for (int i = 0; i < n; i++) { if (pArray->GetElementValue(i)->IsString()) nsegs++; } if (nsegs == 0) { for (int i = 0; i < n; i++) { m_pCurStates->m_TextX -= FXSYS_Mul(pArray->GetNumber(i), m_pCurStates->m_TextState.GetFontSize()) / 1000; } return; } CFX_ByteString* pStrs = new CFX_ByteString[nsegs]; FX_FLOAT* pKerning = FX_Alloc(FX_FLOAT, nsegs); int iSegment = 0; FX_FLOAT fInitKerning = 0; for (int i = 0; i < n; i++) { CPDF_Object* pObj = pArray->GetElementValue(i); if (pObj->IsString()) { CFX_ByteString str = pObj->GetString(); if (str.IsEmpty()) { continue; } pStrs[iSegment] = str; pKerning[iSegment++] = 0; } else { FX_FLOAT num = pObj ? pObj->GetNumber() : 0; if (iSegment == 0) { fInitKerning += num; } else { pKerning[iSegment - 1] += num; } } } AddTextObject(pStrs, fInitKerning, pKerning, iSegment); delete[] pStrs; FX_Free(pKerning); }
FX_FLOAT CPDF_Object::GetNumber() const { switch (m_Type) { case PDFOBJ_NUMBER: return ((CPDF_Number*)this)->GetNumber(); case PDFOBJ_REFERENCE: { CPDF_Reference* pRef = (CPDF_Reference*)(FX_LPVOID)this; if (pRef->m_pObjList == NULL) { break; } CPDF_Object* pObj = pRef->m_pObjList->GetIndirectObject(pRef->m_RefObjNum); if (pObj == NULL) { return 0; } return pObj->GetNumber(); } } return 0; }
FX_FLOAT CPDF_Reference::GetNumber() const { CPDF_Object* obj = SafeGetDirect(); return obj ? obj->GetNumber() : 0; }
void CPDF_AllStates::ProcessExtGS(CPDF_Dictionary* pGS, CPDF_StreamContentParser* pParser) { for (const auto& it : *pGS) { const CFX_ByteString& key_str = it.first; CPDF_Object* pElement = it.second.get(); CPDF_Object* pObject = pElement ? pElement->GetDirect() : nullptr; if (!pObject) continue; uint32_t key = key_str.GetID(); switch (key) { case FXBSTR_ID('L', 'W', 0, 0): m_GraphState.SetLineWidth(pObject->GetNumber()); break; case FXBSTR_ID('L', 'C', 0, 0): m_GraphState.SetLineCap( static_cast<CFX_GraphStateData::LineCap>(pObject->GetInteger())); break; case FXBSTR_ID('L', 'J', 0, 0): m_GraphState.SetLineJoin( static_cast<CFX_GraphStateData::LineJoin>(pObject->GetInteger())); break; case FXBSTR_ID('M', 'L', 0, 0): m_GraphState.SetMiterLimit(pObject->GetNumber()); break; case FXBSTR_ID('D', 0, 0, 0): { CPDF_Array* pDash = pObject->AsArray(); if (!pDash) break; CPDF_Array* pArray = pDash->GetArrayAt(0); if (!pArray) break; SetLineDash(pArray, pDash->GetNumberAt(1), 1.0f); break; } case FXBSTR_ID('R', 'I', 0, 0): m_GeneralState.SetRenderIntent(pObject->GetString()); break; case FXBSTR_ID('F', 'o', 'n', 't'): { CPDF_Array* pFont = pObject->AsArray(); if (!pFont) break; m_TextState.SetFontSize(pFont->GetNumberAt(1)); m_TextState.SetFont(pParser->FindFont(pFont->GetStringAt(0))); break; } case FXBSTR_ID('T', 'R', 0, 0): if (pGS->KeyExist("TR2")) { continue; } case FXBSTR_ID('T', 'R', '2', 0): m_GeneralState.SetTR(pObject && !pObject->IsName() ? pObject : nullptr); break; case FXBSTR_ID('B', 'M', 0, 0): { CPDF_Array* pArray = pObject->AsArray(); m_GeneralState.SetBlendMode(pArray ? pArray->GetStringAt(0) : pObject->GetString()); if (m_GeneralState.GetBlendType() > FXDIB_BLEND_MULTIPLY) pParser->GetPageObjectHolder()->SetBackgroundAlphaNeeded(true); break; } case FXBSTR_ID('S', 'M', 'a', 's'): if (ToDictionary(pObject)) { m_GeneralState.SetSoftMask(pObject); m_GeneralState.SetSMaskMatrix(pParser->GetCurStates()->m_CTM); } else { m_GeneralState.SetSoftMask(nullptr); } break; case FXBSTR_ID('C', 'A', 0, 0): m_GeneralState.SetStrokeAlpha(ClipFloat(pObject->GetNumber())); break; case FXBSTR_ID('c', 'a', 0, 0): m_GeneralState.SetFillAlpha(ClipFloat(pObject->GetNumber())); break; case FXBSTR_ID('O', 'P', 0, 0): m_GeneralState.SetStrokeOP(!!pObject->GetInteger()); if (!pGS->KeyExist("op")) m_GeneralState.SetFillOP(!!pObject->GetInteger()); break; case FXBSTR_ID('o', 'p', 0, 0): m_GeneralState.SetFillOP(!!pObject->GetInteger()); break; case FXBSTR_ID('O', 'P', 'M', 0): m_GeneralState.SetOPMode(pObject->GetInteger()); break; case FXBSTR_ID('B', 'G', 0, 0): if (pGS->KeyExist("BG2")) { continue; } case FXBSTR_ID('B', 'G', '2', 0): m_GeneralState.SetBG(pObject); break; case FXBSTR_ID('U', 'C', 'R', 0): if (pGS->KeyExist("UCR2")) { continue; } case FXBSTR_ID('U', 'C', 'R', '2'): m_GeneralState.SetUCR(pObject); break; case FXBSTR_ID('H', 'T', 0, 0): m_GeneralState.SetHT(pObject); break; case FXBSTR_ID('F', 'L', 0, 0): m_GeneralState.SetFlatness(pObject->GetNumber()); break; case FXBSTR_ID('S', 'M', 0, 0): m_GeneralState.SetSmoothness(pObject->GetNumber()); break; case FXBSTR_ID('S', 'A', 0, 0): m_GeneralState.SetStrokeAdjust(!!pObject->GetInteger()); break; case FXBSTR_ID('A', 'I', 'S', 0): m_GeneralState.SetAlphaSource(!!pObject->GetInteger()); break; case FXBSTR_ID('T', 'K', 0, 0): m_GeneralState.SetTextKnockout(!!pObject->GetInteger()); break; } } m_GeneralState.SetMatrix(m_CTM); }