EStatusCode IndirectObjectsReferenceRegistry::WriteState(ObjectsContext* inStateWriter,ObjectIDType inObjectID) { ObjectIDTypeList objects; inStateWriter->StartNewIndirectObject(inObjectID); DictionaryContext* myDictionary = inStateWriter->StartDictionary(); myDictionary->WriteKey("Type"); myDictionary->WriteNameValue("IndirectObjectsReferenceRegistry"); myDictionary->WriteKey("mObjectsWritesRegistry"); ObjectWriteInformationVector::iterator it = mObjectsWritesRegistry.begin(); inStateWriter->StartArray(); for(; it != mObjectsWritesRegistry.end(); ++it) { ObjectIDType objectWriteEntry = inStateWriter->GetInDirectObjectsRegistry().AllocateNewObjectID(); inStateWriter->WriteIndirectObjectReference(objectWriteEntry); objects.push_back(objectWriteEntry); } inStateWriter->EndArray(eTokenSeparatorEndLine); inStateWriter->EndDictionary(myDictionary); inStateWriter->EndIndirectObject(); ObjectIDTypeList::iterator itIDs = objects.begin(); it = mObjectsWritesRegistry.begin(); for(; it != mObjectsWritesRegistry.end(); ++it,++itIDs) { inStateWriter->StartNewIndirectObject(*itIDs); DictionaryContext* registryDictionary = inStateWriter->StartDictionary(); registryDictionary->WriteKey("Type"); registryDictionary->WriteNameValue("ObjectWriteInformation"); registryDictionary->WriteKey("mObjectWritten"); registryDictionary->WriteBooleanValue(it->mObjectWritten); if(it->mObjectWritten) { registryDictionary->WriteKey("mWritePosition"); registryDictionary->WriteIntegerValue(it->mWritePosition); } registryDictionary->WriteKey("mObjectReferenceType"); registryDictionary->WriteIntegerValue(it->mObjectReferenceType); inStateWriter->EndDictionary(registryDictionary); inStateWriter->EndIndirectObject(); } return PDFHummus::eSuccess; }
EStatusCode ObjectsContext::WriteState(ObjectsContext* inStateWriter,ObjectIDType inObjectID) { EStatusCode status; do { inStateWriter->StartNewIndirectObject(inObjectID); ObjectIDType referencesRegistryObjectID = inStateWriter->GetInDirectObjectsRegistry().AllocateNewObjectID(); ObjectIDType subsetFontsNameSequanceID = inStateWriter->GetInDirectObjectsRegistry().AllocateNewObjectID(); DictionaryContext* objectsContextDict = inStateWriter->StartDictionary(); objectsContextDict->WriteKey("Type"); objectsContextDict->WriteNameValue("ObjectsContext"); objectsContextDict->WriteKey("mReferencesRegistry"); objectsContextDict->WriteNewObjectReferenceValue(referencesRegistryObjectID); objectsContextDict->WriteKey("mCompressStreams"); objectsContextDict->WriteBooleanValue(mCompressStreams); objectsContextDict->WriteKey("mSubsetFontsNamesSequance"); objectsContextDict->WriteNewObjectReferenceValue(subsetFontsNameSequanceID); inStateWriter->EndDictionary(objectsContextDict); inStateWriter->EndIndirectObject(); status = mReferencesRegistry.WriteState(inStateWriter,referencesRegistryObjectID); if(status != PDFHummus::eSuccess) break; // write subset fonts names sequance inStateWriter->StartNewIndirectObject(subsetFontsNameSequanceID); DictionaryContext* sequanceDict = inStateWriter->StartDictionary(); sequanceDict->WriteKey("Type"); sequanceDict->WriteNameValue("UppercaseSequance"); sequanceDict->WriteKey("mSequanceString"); sequanceDict->WriteLiteralStringValue(mSubsetFontsNamesSequance.ToString()); inStateWriter->EndDictionary(sequanceDict); inStateWriter->EndIndirectObject(); }while(false); return status; }
EStatusCode UsedFontsRepository::WriteState(ObjectsContext* inStateWriter,ObjectIDType inObjectID) { EStatusCode status = PDFHummus::eSuccess; ObjectIDTypeList usedFontsObjects; inStateWriter->StartNewIndirectObject(inObjectID); DictionaryContext* usedFontsRepositoryObject = inStateWriter->StartDictionary(); usedFontsRepositoryObject->WriteKey("Type"); usedFontsRepositoryObject->WriteNameValue("UsedFontsRepository"); usedFontsRepositoryObject->WriteKey("mUsedFonts"); inStateWriter->StartArray(); StringAndLongToPDFUsedFontMap::iterator it = mUsedFonts.begin(); for(; it != mUsedFonts.end();++it) { PDFTextString aTextString(it->first.first); inStateWriter->WriteLiteralString(aTextString.ToString()); inStateWriter->WriteInteger(it->first.second); ObjectIDType usedFontID = inStateWriter->GetInDirectObjectsRegistry().AllocateNewObjectID(); inStateWriter->WriteNewIndirectObjectReference(usedFontID); usedFontsObjects.push_back(usedFontID); } inStateWriter->EndArray(eTokenSeparatorEndLine); usedFontsRepositoryObject->WriteKey("mOptionaMetricsFiles"); inStateWriter->StartArray(); StringToStringMap::iterator itOptionals = mOptionaMetricsFiles.begin(); for(; itOptionals != mOptionaMetricsFiles.end();++itOptionals) { PDFTextString aTextString(itOptionals->first); inStateWriter->WriteLiteralString(aTextString.ToString()); aTextString = itOptionals->second; inStateWriter->WriteLiteralString(aTextString.ToString()); } inStateWriter->EndArray(eTokenSeparatorEndLine); inStateWriter->EndDictionary(usedFontsRepositoryObject); inStateWriter->EndIndirectObject(); if(usedFontsObjects.size() > 0) { it = mUsedFonts.begin(); ObjectIDTypeList::iterator itIDs = usedFontsObjects.begin(); for(; it != mUsedFonts.end() && PDFHummus::eSuccess == status;++it,++itIDs) status = it->second->WriteState(inStateWriter,*itIDs); } return status; }
EStatusCode CFFEmbeddedFontWriter::WriteEmbeddedFont( FreeTypeFaceWrapper& inFontInfo, const UIntVector& inSubsetGlyphIDs, const std::string& inFontFile3SubType, const std::string& inSubsetFontName, ObjectsContext* inObjectsContext, UShortVector* inCIDMapping, ObjectIDType& outEmbeddedFontObjectID) { MyStringBuf rawFontProgram; bool notEmbedded; // as oppose to true type, the reason for using a memory stream here is mainly peformance - i don't want to start // setting file pointers and move in a file stream EStatusCode status; do { status = CreateCFFSubset(inFontInfo,inSubsetGlyphIDs,inCIDMapping,inSubsetFontName,notEmbedded,rawFontProgram); if(status != PDFHummus::eSuccess) { TRACE_LOG("CFFEmbeddedFontWriter::WriteEmbeddedFont, failed to write embedded font program"); break; } if(notEmbedded) { // can't embed. mark succesful, and go back empty outEmbeddedFontObjectID = 0; TRACE_LOG("CFFEmbeddedFontWriter::WriteEmbeddedFont, font may not be embedded. so not embedding"); return PDFHummus::eSuccess; } outEmbeddedFontObjectID = inObjectsContext->StartNewIndirectObject(); DictionaryContext* fontProgramDictionaryContext = inObjectsContext->StartDictionary(); rawFontProgram.pubseekoff(0,std::ios_base::beg); fontProgramDictionaryContext->WriteKey(scSubtype); fontProgramDictionaryContext->WriteNameValue(inFontFile3SubType); PDFStream* pdfStream = inObjectsContext->StartPDFStream(fontProgramDictionaryContext); // now copy the created font program to the output stream InputStringBufferStream fontProgramStream(&rawFontProgram); OutputStreamTraits streamCopier(pdfStream->GetWriteStream()); status = streamCopier.CopyToOutputStream(&fontProgramStream); if(status != PDFHummus::eSuccess) { TRACE_LOG("CFFEmbeddedFontWriter::WriteEmbeddedFont, failed to copy font program into pdf stream"); break; } inObjectsContext->EndPDFStream(pdfStream); delete pdfStream; }while(false); return status; }
EStatusCode PDFUsedFont::WriteState(ObjectsContext* inStateWriter,ObjectIDType inObjectID) { inStateWriter->StartNewIndirectObject(inObjectID); DictionaryContext* pdfUsedFontObject = inStateWriter->StartDictionary(); pdfUsedFontObject->WriteKey("Type"); pdfUsedFontObject->WriteNameValue("PDFUsedFont"); ObjectIDType writtenFontObject; if(mWrittenFont) { writtenFontObject = inStateWriter->GetInDirectObjectsRegistry().AllocateNewObjectID(); pdfUsedFontObject->WriteKey("mWrittenFont"); pdfUsedFontObject->WriteNewObjectReferenceValue(writtenFontObject); } inStateWriter->EndDictionary(pdfUsedFontObject); inStateWriter->EndIndirectObject(); if(mWrittenFont) mWrittenFont->WriteState(inStateWriter,writtenFontObject); return PDFHummus::eSuccess; }
EStatusCode WrittenFontCFF::WriteState(ObjectsContext* inStateWriter,ObjectIDType inObjectID) { inStateWriter->StartNewIndirectObject(inObjectID); DictionaryContext* writtenFontDictionary = inStateWriter->StartDictionary(); writtenFontDictionary->WriteKey("Type"); writtenFontDictionary->WriteNameValue("WrittenFontCFF"); writtenFontDictionary->WriteKey("mAvailablePositionsCount"); writtenFontDictionary->WriteIntegerValue(mAvailablePositionsCount); writtenFontDictionary->WriteKey("mFreeList"); inStateWriter->StartArray(); UCharAndUCharList::iterator it = mFreeList.begin(); for(; it != mFreeList.end();++it) { inStateWriter->WriteInteger(it->first); inStateWriter->WriteInteger(it->second); } inStateWriter->EndArray(eTokenSeparatorEndLine); writtenFontDictionary->WriteKey("mAssignedPositions"); inStateWriter->StartArray(); for(int i=0;i<256;++i) inStateWriter->WriteInteger(mAssignedPositions[i]); inStateWriter->EndArray(eTokenSeparatorEndLine); writtenFontDictionary->WriteKey("mAssignedPositionsAvailable"); inStateWriter->StartArray(); for(int i=0;i<256;++i) inStateWriter->WriteBoolean(mAssignedPositionsAvailable[i]); inStateWriter->EndArray(eTokenSeparatorEndLine); writtenFontDictionary->WriteKey("mIsCID"); writtenFontDictionary->WriteBooleanValue(mIsCID); EStatusCode status = AbstractWrittenFont::WriteStateInDictionary(inStateWriter,writtenFontDictionary); if(PDFHummus::eSuccess == status) { inStateWriter->EndDictionary(writtenFontDictionary); inStateWriter->EndIndirectObject(); status = AbstractWrittenFont::WriteStateAfterDictionary(inStateWriter); } return status; }
EStatusCode WrittenFontTrueType::WriteState(ObjectsContext* inStateWriter,ObjectIDType inObjectID) { inStateWriter->StartNewIndirectObject(inObjectID); DictionaryContext* writtenFontDictionary = inStateWriter->StartDictionary(); writtenFontDictionary->WriteKey("Type"); writtenFontDictionary->WriteNameValue("WrittenFontTrueType"); EStatusCode status = AbstractWrittenFont::WriteStateInDictionary(inStateWriter,writtenFontDictionary); if(PDFHummus::eSuccess == status) { inStateWriter->EndDictionary(writtenFontDictionary); inStateWriter->EndIndirectObject(); status = AbstractWrittenFont::WriteStateAfterDictionary(inStateWriter); } return status; }
PDFStream* ObjectsContext::StartPDFStream(DictionaryContext* inStreamDictionary,bool inForceDirectExtentObject) { // write stream header and allocate PDF stream. // PDF stream will take care of maintaining state for the stream till writing is finished // Write the stream header // Write Stream Dictionary (note that inStreamDictionary is optionally used) DictionaryContext* streamDictionaryContext = (NULL == inStreamDictionary ? StartDictionary() : inStreamDictionary); // Compression (if necessary) if(mCompressStreams) { streamDictionaryContext->WriteKey(scFilter); streamDictionaryContext->WriteNameValue(scFlateDecode); } PDFStream* result = NULL; if(!inForceDirectExtentObject) { // Length (write as an indirect object) streamDictionaryContext->WriteKey(scLength); ObjectIDType lengthObjectID = mReferencesRegistry.AllocateNewObjectID(); streamDictionaryContext->WriteNewObjectReferenceValue(lengthObjectID); EndDictionary(streamDictionaryContext); // Write Stream Content WriteKeyword(scStream); result = new PDFStream(mCompressStreams,mOutputStream, mEncryptionHelper,lengthObjectID,mExtender); } else result = new PDFStream(mCompressStreams,mOutputStream, mEncryptionHelper,streamDictionaryContext,mExtender); // break encryption, if any, when writing a stream, cause if encryption is desired, only top level elements should be encrypted. hence - the stream itself is, but its contents do not re-encrypt if (mEncryptionHelper) mEncryptionHelper->PauseEncryption(); return result; }
PDFStream* ObjectsContext::StartPDFStream(DictionaryContext* inStreamDictionary,bool inForceDirectExtentObject) { // write stream header and allocate PDF stream. // PDF stream will take care of maintaining state for the stream till writing is finished // Write the stream header // Write Stream Dictionary (note that inStreamDictionary is optionally used) DictionaryContext* streamDictionaryContext = (NULL == inStreamDictionary ? StartDictionary() : inStreamDictionary); // Compression (if necessary) if(mCompressStreams) { streamDictionaryContext->WriteKey(scFilter); streamDictionaryContext->WriteNameValue(scFlateDecode); } if(!inForceDirectExtentObject) { // Length (write as an indirect object) streamDictionaryContext->WriteKey(scLength); ObjectIDType lengthObjectID = mReferencesRegistry.AllocateNewObjectID(); streamDictionaryContext->WriteNewObjectReferenceValue(lengthObjectID); EndDictionary(streamDictionaryContext); // Write Stream Content WriteKeyword(scStream); return new PDFStream(mCompressStreams,mOutputStream,lengthObjectID,mExtender); } else return new PDFStream(mCompressStreams,mOutputStream,streamDictionaryContext,mExtender); }
void FontDescriptorWriter::WriteFontDescriptor( ObjectIDType inFontDescriptorObjectID, const string& inFontPostscriptName, FreeTypeFaceWrapper* inFontInfo, const UIntAndGlyphEncodingInfoVector& inEncodedGlyphs, ObjectsContext* inObjectsContext, IFontDescriptorHelper* inDescriptorHelper) { DictionaryContext* fontDescriptorDictionary; inObjectsContext->StartNewIndirectObject(inFontDescriptorObjectID); fontDescriptorDictionary = inObjectsContext->StartDictionary(); // FontName fontDescriptorDictionary->WriteKey(scFontName); fontDescriptorDictionary->WriteNameValue(inFontPostscriptName); // FontFamily fontDescriptorDictionary->WriteKey(scFontFamily); fontDescriptorDictionary->WriteLiteralStringValue((*inFontInfo)->family_name); // FontStretch fontDescriptorDictionary->WriteKey(scFontStretch); fontDescriptorDictionary->WriteNameValue(scFontStretchLabels[inFontInfo->GetFontStretch()]); // FontWeight fontDescriptorDictionary->WriteKey(scFontWeight); fontDescriptorDictionary->WriteIntegerValue(inFontInfo->GetFontWeight()); // FontBBox fontDescriptorDictionary->WriteKey(scFontBBox); fontDescriptorDictionary->WriteRectangleValue( PDFRectangle( inFontInfo->GetInPDFMeasurements((*inFontInfo)->bbox.xMin), inFontInfo->GetInPDFMeasurements((*inFontInfo)->bbox.yMin), inFontInfo->GetInPDFMeasurements((*inFontInfo)->bbox.xMax), inFontInfo->GetInPDFMeasurements((*inFontInfo)->bbox.yMax))); // ItalicAngle fontDescriptorDictionary->WriteKey(scItalicAngle); fontDescriptorDictionary->WriteDoubleValue(inFontInfo->GetItalicAngle()); // Ascent fontDescriptorDictionary->WriteKey(scAscent); fontDescriptorDictionary->WriteIntegerValue(inFontInfo->GetInPDFMeasurements((*inFontInfo)->ascender)); // Descent fontDescriptorDictionary->WriteKey(scDescent); fontDescriptorDictionary->WriteIntegerValue(inFontInfo->GetInPDFMeasurements((*inFontInfo)->descender)); // CapHeight BoolAndFTShort result = inFontInfo->GetCapHeight(); if(result.first) { fontDescriptorDictionary->WriteKey(scCapHeight); fontDescriptorDictionary->WriteIntegerValue(result.second); } // XHeight result = inFontInfo->GetxHeight(); if(result.first) { fontDescriptorDictionary->WriteKey(scXHeight); fontDescriptorDictionary->WriteIntegerValue(result.second); } // StemV fontDescriptorDictionary->WriteKey(scStemV); fontDescriptorDictionary->WriteIntegerValue(inFontInfo->GetStemV()); // ChartSet writing (variants according to ANSI/CID) inDescriptorHelper->WriteCharSet(fontDescriptorDictionary,inObjectsContext,inFontInfo,inEncodedGlyphs); // Flags fontDescriptorDictionary->WriteKey(scFlags); fontDescriptorDictionary->WriteIntegerValue(CalculateFlags(inFontInfo,inEncodedGlyphs)); // font embedding [may not happen due to font embedding restrictions. helper is supposed to avoid reference as well] inDescriptorHelper->WriteFontFileReference(fontDescriptorDictionary,inObjectsContext); inObjectsContext->EndDictionary(fontDescriptorDictionary); inObjectsContext->EndIndirectObject(); }
EStatusCode PDFWriter::Shutdown(const std::string& inStateFilePath) { EStatusCode status; do { StateWriter writer; status = writer.Start(inStateFilePath); if(status != eSuccess) { TRACE_LOG("PDFWriter::Shutdown, cant start state writing"); break; } ObjectIDType rootObjectID = writer.GetObjectsWriter()->StartNewIndirectObject(); DictionaryContext* pdfWriterDictionary = writer.GetObjectsWriter()->StartDictionary(); pdfWriterDictionary->WriteKey("Type"); pdfWriterDictionary->WriteNameValue("PDFWriter"); ObjectIDType objectsContextID = writer.GetObjectsWriter()->GetInDirectObjectsRegistry().AllocateNewObjectID(); ObjectIDType DocumentContextID = writer.GetObjectsWriter()->GetInDirectObjectsRegistry().AllocateNewObjectID(); pdfWriterDictionary->WriteKey("mObjectsContext"); pdfWriterDictionary->WriteNewObjectReferenceValue(objectsContextID); pdfWriterDictionary->WriteKey("mDocumentContext"); pdfWriterDictionary->WriteNewObjectReferenceValue(DocumentContextID); pdfWriterDictionary->WriteKey("mIsModified"); pdfWriterDictionary->WriteBooleanValue(mIsModified); if(mIsModified) { pdfWriterDictionary->WriteKey("mModifiedFileVersion"); pdfWriterDictionary->WriteIntegerValue(mModifiedFileVersion); } writer.GetObjectsWriter()->EndDictionary(pdfWriterDictionary); writer.GetObjectsWriter()->EndIndirectObject(); writer.SetRootObject(rootObjectID); status = mObjectsContext.WriteState(writer.GetObjectsWriter(),objectsContextID); if(status != eSuccess) break; status = mDocumentContext.WriteState(writer.GetObjectsWriter(),DocumentContextID); if(status != eSuccess) break; status = writer.Finish(); if(status != eSuccess) { TRACE_LOG("PDFWriter::Shutdown, cant finish state writing"); } }while(false); if(status != eSuccess) { mOutputFile.CloseFile(); TRACE_LOG("PDFWriter::Shutdown, Could not end PDF"); } else status = mOutputFile.CloseFile(); //ReleaseLog(); return status; }
EStatusCodeAndObjectIDType PDFCommentWriter::WriteCommentsTree(PDFComment* inComment) { EStatusCodeAndObjectIDType result; ObjectIDType repliedTo = 0; // if already written, return PDFCommentToObjectIDTypeMap::iterator it = mCommentsForNextPage.find(inComment); if(it != mCommentsForNextPage.end()) { result.first = eSuccess; result.second = it->second; return result; } // if has a referred comment, write it first if(inComment->ReplyTo != NULL) { EStatusCodeAndObjectIDType repliedtoResult = WriteCommentsTree(inComment->ReplyTo); if(repliedtoResult.first != eSuccess) { result.first = eFailure; result.second = 0; return result; } else repliedTo = repliedtoResult.second; } do { ObjectsContext& objectsContext = mPDFWriter->GetObjectsContext(); // Start new InDirect object for annotation dictionary result.second = objectsContext.StartNewIndirectObject(); DictionaryContext* dictionaryContext = objectsContext.StartDictionary(); // Type dictionaryContext->WriteKey("Type"); dictionaryContext->WriteNameValue("Annot"); // SubType dictionaryContext->WriteKey("Subtype"); dictionaryContext->WriteNameValue("Text"); // Rect dictionaryContext->WriteKey("Rect"); dictionaryContext->WriteRectangleValue( PDFRectangle(inComment->FrameBoundings[0], inComment->FrameBoundings[1], inComment->FrameBoundings[2], inComment->FrameBoundings[3])); // Contents dictionaryContext->WriteKey("Contents"); dictionaryContext->WriteLiteralStringValue(PDFTextString(inComment->Text).ToString()); // C (color) dictionaryContext->WriteKey("C"); objectsContext.StartArray(); if(inComment->Color.UseCMYK) { objectsContext.WriteDouble((double)inComment->Color.CMYKComponents[0]/255); objectsContext.WriteDouble((double)inComment->Color.CMYKComponents[1]/255); objectsContext.WriteDouble((double)inComment->Color.CMYKComponents[2]/255); objectsContext.WriteDouble((double)inComment->Color.CMYKComponents[3]/255); } else { objectsContext.WriteDouble((double)inComment->Color.RGBComponents[0]/255); objectsContext.WriteDouble((double)inComment->Color.RGBComponents[1]/255); objectsContext.WriteDouble((double)inComment->Color.RGBComponents[2]/255); } objectsContext.EndArray(eTokenSeparatorEndLine); // T dictionaryContext->WriteKey("T"); dictionaryContext->WriteLiteralStringValue(PDFTextString(inComment->CommentatorName).ToString()); // M dictionaryContext->WriteKey("M"); dictionaryContext->WriteLiteralStringValue(inComment->Time.ToString()); if(inComment->ReplyTo != NULL) { // IRT dictionaryContext->WriteKey("IRT"); dictionaryContext->WriteObjectReferenceValue(repliedTo); // RT (we're doing always "reply" at this point, being a reply to comment dictionaryContext->WriteKey("RT"); dictionaryContext->WriteNameValue("R"); } // Open (we'll have them all closed to begin with) dictionaryContext->WriteKey("Open"); dictionaryContext->WriteBooleanValue(false); // Name dictionaryContext->WriteKey("Name"); dictionaryContext->WriteNameValue("Comment"); if(objectsContext.EndDictionary(dictionaryContext) != eSuccess) { result.first = eFailure; TRACE_LOG("PDFCommentWriter::WriteCommentsTree, Exception in ending comment dictionary"); break; } objectsContext.EndIndirectObject(); mCommentsForNextPage.insert(PDFCommentToObjectIDTypeMap::value_type(inComment,result.second)); result.first = eSuccess; }while(false); return result; }
EStatusCode DescendentFontWriter::WriteFont( ObjectIDType inDecendentObjectID, const string& inFontName, FreeTypeFaceWrapper& inFontInfo, const UIntAndGlyphEncodingInfoVector& inEncodedGlyphs, ObjectsContext* inObjectsContext, IDescendentFontWriter* inDescendentFontWriterHelper) { EStatusCode status = PDFHummus::eSuccess; FontDescriptorWriter fontDescriptorWriter; inObjectsContext->StartNewIndirectObject(inDecendentObjectID); mFontInfo = &inFontInfo; mObjectsContext = inObjectsContext; mCIDSetObjectID = 0; do { DictionaryContext* fontContext = inObjectsContext->StartDictionary(); // Type fontContext->WriteKey(scType); fontContext->WriteNameValue(scFont); // SubType fontContext->WriteKey(scSubtype); inDescendentFontWriterHelper->WriteSubTypeValue(fontContext); // BaseFont fontContext->WriteKey(scBaseFont); fontContext->WriteNameValue(inFontName); WriteWidths(inEncodedGlyphs,fontContext); // CIDSystemInfo fontContext->WriteKey(scCIDSystemInfo); ObjectIDType cidSystemInfoObjectID = mObjectsContext->GetInDirectObjectsRegistry().AllocateNewObjectID(); fontContext->WriteObjectReferenceValue(cidSystemInfoObjectID); // FontDescriptor fontContext->WriteKey(scFontDescriptor); ObjectIDType fontDescriptorObjectID = mObjectsContext->GetInDirectObjectsRegistry().AllocateNewObjectID(); fontContext->WriteObjectReferenceValue(fontDescriptorObjectID); // free dictionary end writing inDescendentFontWriterHelper->WriteAdditionalKeys(fontContext); status = inObjectsContext->EndDictionary(fontContext); if(status != PDFHummus::eSuccess) { TRACE_LOG("CFFANSIFontWriter::WriteFont, unexpected failure. Failed to end dictionary in font write."); break; } inObjectsContext->EndIndirectObject(); WriteCIDSystemInfo(cidSystemInfoObjectID); mWriterHelper = inDescendentFontWriterHelper; // save the helper pointer, to write the font program reference in the descriptor fontDescriptorWriter.WriteFontDescriptor(fontDescriptorObjectID,inFontName,&inFontInfo,inEncodedGlyphs,inObjectsContext,this); if(mCIDSetObjectID) // set by descriptor writer callback WriteCIDSet(inEncodedGlyphs); }while(false); return status; }
EStatusCode CIDFontWriter::WriteFont(FreeTypeFaceWrapper& inFontInfo, WrittenFontRepresentation* inFontOccurrence, ObjectsContext* inObjectsContext, IDescendentFontWriter* inDescendentFontWriter) { EStatusCode status = PDFHummus::eSuccess; inObjectsContext->StartNewIndirectObject(inFontOccurrence->mWrittenObjectID); mFontInfo = &inFontInfo; mFontOccurrence = inFontOccurrence; mObjectsContext = inObjectsContext; do { DictionaryContext* fontContext = inObjectsContext->StartDictionary(); // Type fontContext->WriteKey(scType); fontContext->WriteNameValue(scFont); // SubType fontContext->WriteKey(scSubtype); fontContext->WriteNameValue(scType0); // BaseFont fontContext->WriteKey(scBaseFont); const char* postscriptFontName = FT_Get_Postscript_Name(inFontInfo); if(!postscriptFontName) { TRACE_LOG("CIDFontWriter::WriteFont, unexpected failure. no postscript font name for font"); status = PDFHummus::eFailure; break; } std::string subsetFontName = inObjectsContext->GenerateSubsetFontPrefix() + scPlus + postscriptFontName; fontContext->WriteNameValue(subsetFontName); WriteEncoding(fontContext); // DescendantFonts ObjectIDType descendantFontID = mObjectsContext->GetInDirectObjectsRegistry().AllocateNewObjectID(); fontContext->WriteKey(scDescendantFonts); mObjectsContext->StartArray(); mObjectsContext->WriteNewIndirectObjectReference(descendantFontID); mObjectsContext->EndArray(eTokenSeparatorEndLine); CalculateCharacterEncodingArray(); // put the charachter in the order of encoding, for the ToUnicode map // ToUnicode fontContext->WriteKey(scToUnicode); ObjectIDType toUnicodeMapObjectID = mObjectsContext->GetInDirectObjectsRegistry().AllocateNewObjectID(); fontContext->WriteNewObjectReferenceValue(toUnicodeMapObjectID); status = inObjectsContext->EndDictionary(fontContext); if(status != PDFHummus::eSuccess) { TRACE_LOG("CIDFontWriter::WriteFont, unexpected failure. Failed to end dictionary in font write."); break; } inObjectsContext->EndIndirectObject(); WriteToUnicodeMap(toUnicodeMapObjectID); // Write the descendant font status = inDescendentFontWriter->WriteFont(descendantFontID,subsetFontName,*mFontInfo,mCharactersVector,mObjectsContext); } while(false); return status; }