EStatusCode WrittenFontCFF::ReadState(PDFParser* inStateReader,ObjectIDType inObjectID) { PDFObjectCastPtr<PDFDictionary> writtenFontState(inStateReader->ParseNewObject(inObjectID)); PDFObjectCastPtr<PDFInteger> availablePositionsCount(writtenFontState->QueryDirectObject("mAvailablePositionsCount")); mAvailablePositionsCount = (unsigned char)availablePositionsCount->GetValue(); mFreeList.clear(); PDFObjectCastPtr<PDFArray> freeListState(writtenFontState->QueryDirectObject("mFreeList")); SingleValueContainerIterator<PDFObjectVector> it = freeListState->GetIterator(); PDFObjectCastPtr<PDFInteger> item; UCharAndUChar aPair; while(it.MoveNext()) { item = it.GetItem(); aPair.first = (unsigned char)item->GetValue(); it.MoveNext(); item = it.GetItem(); aPair.second = (unsigned char)item->GetValue(); mFreeList.push_back(aPair); } PDFObjectCastPtr<PDFArray> assignedPositionsState(writtenFontState->QueryDirectObject("mAssignedPositions")); it = assignedPositionsState->GetIterator(); int i=0; PDFObjectCastPtr<PDFInteger> assignedPositionItem; while(it.MoveNext()) { assignedPositionItem = it.GetItem(); mAssignedPositions[i] = (unsigned int)assignedPositionItem->GetValue(); ++i; } PDFObjectCastPtr<PDFArray> assignedPositionsAvailableState(writtenFontState->QueryDirectObject("mAssignedPositionsAvailable")); it = assignedPositionsAvailableState->GetIterator(); i=0; PDFObjectCastPtr<PDFBoolean> assignedPositionAvailableItem; while(it.MoveNext()) { assignedPositionAvailableItem = it.GetItem(); mAssignedPositionsAvailable[i] = assignedPositionAvailableItem->GetValue(); ++i; } PDFObjectCastPtr<PDFBoolean> isCIDState(writtenFontState->QueryDirectObject("mIsCID")); mIsCID = isCIDState->GetValue(); return AbstractWrittenFont::ReadStateFromObject(inStateReader,writtenFontState.GetPtr()); }
void showXObjectsPerPageInfo(PDFParser& parser,PDFObjectCastPtr<PDFDictionary> xobjects) { RefCountPtr<PDFName> key; PDFObjectCastPtr<PDFIndirectObjectReference> value; MapIterator<PDFNameToPDFObjectMap> it = xobjects->GetIterator(); while(it.MoveNext()) { key = it.GetKey(); value = it.GetValue(); cout << "XObject named " << key->GetValue().c_str() << " is object " << value->mObjectID << " of type "; PDFObjectCastPtr<PDFStreamInput> xobject(parser.ParseNewObject(value->mObjectID)); PDFObjectCastPtr<PDFDictionary> xobjectDictionary(xobject->QueryStreamDictionary()); PDFObjectCastPtr<PDFName> typeOfXObject = xobjectDictionary->QueryDirectObject("Subtype"); cout << typeOfXObject->GetValue().c_str() << "\n"; } }
ObjectIDType DCTDecodeFilterTest::FindDCTDecodedImageObject(PDFParser* inParser) { ObjectIDType imageObject = 0; do { // find image by looking for the first image in the first page RefCountPtr<PDFDictionary> firstPage = inParser->ParsePage(0); if(!firstPage) break; PDFObjectCastPtr<PDFDictionary> resourceDictionary(inParser->QueryDictionaryObject(firstPage.GetPtr(),"Resources")); if(!resourceDictionary) break; PDFObjectCastPtr<PDFDictionary> xobjectDictionary(inParser->QueryDictionaryObject(resourceDictionary.GetPtr(), "XObject")); if(!xobjectDictionary) break; MapIterator<PDFNameToPDFObjectMap> it = xobjectDictionary->GetIterator(); while(it.MoveNext()) { if(it.GetValue()->GetType() == PDFObject::ePDFObjectIndirectObjectReference) { PDFObjectCastPtr<PDFStreamInput> image( inParser->ParseNewObject(((PDFIndirectObjectReference*)it.GetValue())->mObjectID)); RefCountPtr<PDFDictionary> imageDictionary = image->QueryStreamDictionary(); PDFObjectCastPtr<PDFName> objectType = imageDictionary->QueryDirectObject("Subtype"); if(!objectType || objectType->GetValue() != "Image") continue; RefCountPtr<PDFObject> filters = imageDictionary->QueryDirectObject("Filter"); if(!filters) break; if(filters->GetType() == PDFObject::ePDFObjectName && ((PDFName*)filters.GetPtr())->GetValue() == "DCTDecode") { imageObject = ((PDFIndirectObjectReference*)it.GetValue())->mObjectID; break; } PDFArray* filtersArray = (PDFArray*)filters.GetPtr(); if(filtersArray->GetLength() == 1) { PDFObjectCastPtr<PDFName> firstDecoder(filtersArray->QueryObject(0)); if(firstDecoder->GetValue() == "DCTDecode") { imageObject = ((PDFIndirectObjectReference*)it.GetValue())->mObjectID; break; } } } } } while (false); return imageObject; }
EStatusCode UsedFontsRepository::ReadState(PDFParser* inStateReader,ObjectIDType inObjectID) { EStatusCode status = PDFHummus::eSuccess; // clear current state StringAndLongToPDFUsedFontMap::iterator itUsedFonts = mUsedFonts.begin(); for(; itUsedFonts != mUsedFonts.end();++itUsedFonts) delete (itUsedFonts->second); mUsedFonts.clear(); PDFObjectCastPtr<PDFDictionary> usedFontsRepositoryState(inStateReader->ParseNewObject(inObjectID)); mOptionaMetricsFiles.clear(); PDFObjectCastPtr<PDFArray> optionalMetricsState(usedFontsRepositoryState->QueryDirectObject("mOptionaMetricsFiles")); SingleValueContainerIterator<PDFObjectVector> it = optionalMetricsState->GetIterator(); PDFObjectCastPtr<PDFLiteralString> aStringValue; while(it.MoveNext()) { PDFTextString aKey; aStringValue = it.GetItem(); aKey = aStringValue->GetValue(); PDFTextString aValue; it.MoveNext(); aStringValue = it.GetItem(); aValue = aStringValue->GetValue(); mOptionaMetricsFiles.insert(StringToStringMap::value_type(aKey.ToUTF8String(),aValue.ToUTF8String())); } PDFObjectCastPtr<PDFArray> usedFontsState(usedFontsRepositoryState->QueryDirectObject("mUsedFonts")); it = usedFontsState->GetIterator(); PDFObjectCastPtr<PDFLiteralString> keyStringItem; PDFObjectCastPtr<PDFInteger> keyIndexItem; PDFObjectCastPtr<PDFIndirectObjectReference> valueItem; if(!mInputFontsInformation) mInputFontsInformation = new FreeTypeWrapper(); while(it.MoveNext() && PDFHummus::eSuccess == status) { keyStringItem = it.GetItem(); it.MoveNext(); keyIndexItem = it.GetItem(); it.MoveNext(); valueItem = it.GetItem(); PDFTextString aTextString(keyStringItem->GetValue()); std::string filePath = aTextString.ToUTF8String(); long fontIndex = (long)keyIndexItem->GetValue(); FT_Face face; face = mInputFontsInformation->NewFace(filePath,fontIndex); if(!face) { TRACE_LOG2("UsedFontsRepository::ReadState, Failed to load font from %s at index %ld",filePath.c_str(),fontIndex); status = PDFHummus::eFailure; break; } PDFUsedFont* usedFont; StringToStringMap::iterator itOptionlMetricsFile = mOptionaMetricsFiles.find(filePath); if(itOptionlMetricsFile != mOptionaMetricsFiles.end()) usedFont = new PDFUsedFont(face,filePath,itOptionlMetricsFile->second,fontIndex,mObjectsContext); else usedFont = new PDFUsedFont(face,filePath,"",fontIndex,mObjectsContext); if(!usedFont->IsValid()) { TRACE_LOG2("UsedFontsRepository::ReadState, Unreckognized font format for font in %s at index %ld",filePath.c_str(),fontIndex); delete usedFont; usedFont = NULL; status = PDFHummus::eFailure; break; } usedFont->ReadState(inStateReader,valueItem->mObjectID); mUsedFonts.insert(StringAndLongToPDFUsedFontMap::value_type(StringAndLong(filePath,fontIndex),usedFont)); } return status; }