"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/Plugins/Pdf/PDFWriter/PDFWriter.cpp" between
TeXmacs-1.99.4-src.tar.gz and TeXmacs-1.99.5-src.tar.gz

About: GNU TeXmacs is a what-you-see-is-what-you-get scientific text editor, which was both inspired by TeX and GNU Emacs.

PDFWriter.cpp  (TeXmacs-1.99.4-src):PDFWriter.cpp  (TeXmacs-1.99.5-src)
skipping to change at line 34 skipping to change at line 34
#include "StateReader.h" #include "StateReader.h"
#include "ObjectsContext.h" #include "ObjectsContext.h"
#include "DictionaryContext.h" #include "DictionaryContext.h"
#include "PDFDictionary.h" #include "PDFDictionary.h"
#include "PDFObjectCast.h" #include "PDFObjectCast.h"
#include "PDFIndirectObjectReference.h" #include "PDFIndirectObjectReference.h"
#include "IByteWriterWithPosition.h" #include "IByteWriterWithPosition.h"
#include "OutputStreamTraits.h" #include "OutputStreamTraits.h"
#include "PDFBoolean.h" #include "PDFBoolean.h"
#include "PDFInteger.h" #include "PDFInteger.h"
#include "PDFPageInput.h"
using namespace PDFHummus; using namespace PDFHummus;
const LogConfiguration LogConfiguration::DefaultLogConfiguration(false,false,"PD FWriterLog.txt"); const LogConfiguration LogConfiguration::DefaultLogConfiguration(false,false,"PD FWriterLog.txt");
const PDFCreationSettings PDFCreationSettings::DefaultPDFCreationSettings(true); const PDFCreationSettings PDFCreationSettings::DefaultPDFCreationSettings(true,t rue);
PDFWriter::PDFWriter(void) PDFWriter::PDFWriter(void)
{ {
// Gal: some trick, already set reference to objects context. this does n ot mean that the document context can start doing something. // Gal: some trick, already set reference to objects context. this does n ot mean that the document context can start doing something.
// this allows the creation of copying context before starting to write t he PDF, so that already // this allows the creation of copying context before starting to write t he PDF, so that already
// the first decision (level) about the PDF can be the result of parsing // the first decision (level) about the PDF can be the result of parsing
mDocumentContext.SetObjectsContext(&mObjectsContext); mDocumentContext.SetObjectsContext(&mObjectsContext);
mIsModified = false; mIsModified = false;
mEmbedFonts = true;
} }
PDFWriter::~PDFWriter(void) PDFWriter::~PDFWriter(void)
{ {
} }
EStatusCode PDFWriter::StartPDF( EStatusCode PDFWriter::StartPDF(
const std::string& inOutp utFilePath, const std::string& inOutp utFilePath,
EPDFVersion inPDFVersion, EPDFVersion inPDFVersion,
const LogConfiguration& i nLogConfiguration, const LogConfiguration& i nLogConfiguration,
const PDFCreationSettings & inPDFCreationSettings) const PDFCreationSettings & inPDFCreationSettings)
{ {
SetupLog(inLogConfiguration); SetupLog(inLogConfiguration);
SetupObjectsContext(inPDFCreationSettings); SetupCreationSettings(inPDFCreationSettings);
EStatusCode status = mOutputFile.OpenFile(inOutputFilePath); EStatusCode status = mOutputFile.OpenFile(inOutputFilePath);
if(status != eSuccess) if(status != eSuccess)
return status; return status;
mObjectsContext.SetOutputStream(mOutputFile.GetOutputStream()); mObjectsContext.SetOutputStream(mOutputFile.GetOutputStream());
mDocumentContext.SetOutputFileInformation(&mOutputFile); mDocumentContext.SetOutputFileInformation(&mOutputFile);
mIsModified = false; mIsModified = false;
return mDocumentContext.WriteHeader(inPDFVersion); return mDocumentContext.WriteHeader(inPDFVersion);
} }
EStatusCode PDFWriter::EndPDF() EStatusCode PDFWriter::EndPDF()
{ {
EStatusCode status; EStatusCode status;
do do
{ {
if(mIsModified) if(mIsModified)
status = mDocumentContext.FinalizeModifiedPDF(&mModifiedFileParser,m ModifiedFileVersion); status = mDocumentContext.FinalizeModifiedPDF(&mModifiedFileParser,m ModifiedFileVersion,mEmbedFonts);
else else
status = mDocumentContext.FinalizeNewPDF(); status = mDocumentContext.FinalizeNewPDF(mEmbedFonts);
if(status != eSuccess) if(status != eSuccess)
{ {
TRACE_LOG("PDFWriter::EndPDF, Could not end PDF"); TRACE_LOG("PDFWriter::EndPDF, Could not end PDF");
break; break;
} }
status = mOutputFile.CloseFile(); status = mOutputFile.CloseFile();
if(status != eSuccess) if(status != eSuccess)
{ {
TRACE_LOG("PDFWriter::EndPDF, Could not close output file"); TRACE_LOG("PDFWriter::EndPDF, Could not close output file");
break; break;
skipping to change at line 154 skipping to change at line 156
} }
void PDFWriter::SetupLog(const LogConfiguration& inLogConfiguration) void PDFWriter::SetupLog(const LogConfiguration& inLogConfiguration)
{ {
if(inLogConfiguration.LogStream) if(inLogConfiguration.LogStream)
Trace::DefaultTrace.SetLogSettings(inLogConfiguration.LogStream,i nLogConfiguration.ShouldLog); Trace::DefaultTrace.SetLogSettings(inLogConfiguration.LogStream,i nLogConfiguration.ShouldLog);
else else
Trace::DefaultTrace.SetLogSettings(inLogConfiguration.LogFileLoca tion,inLogConfiguration.ShouldLog,inLogConfiguration.StartWithBOM); Trace::DefaultTrace.SetLogSettings(inLogConfiguration.LogFileLoca tion,inLogConfiguration.ShouldLog,inLogConfiguration.StartWithBOM);
} }
void PDFWriter::SetupObjectsContext(const PDFCreationSettings& inPDFCreationSett ings) void PDFWriter::SetupCreationSettings(const PDFCreationSettings& inPDFCreationSe ttings)
{ {
mObjectsContext.SetCompressStreams(inPDFCreationSettings.CompressStreams) ; mObjectsContext.SetCompressStreams(inPDFCreationSettings.CompressStreams) ;
mEmbedFonts = inPDFCreationSettings.EmbedFonts;
} }
void PDFWriter::ReleaseLog() void PDFWriter::ReleaseLog()
{ {
//Singleton<Trace>::Reset(); //Singleton<Trace>::Reset();
} }
DocumentContext& PDFWriter::GetDocumentContext() DocumentContext& PDFWriter::GetDocumentContext()
{ {
return mDocumentContext; return mDocumentContext;
skipping to change at line 338 skipping to change at line 341
pdfWriterDictionary->WriteKey("mObjectsContext"); pdfWriterDictionary->WriteKey("mObjectsContext");
pdfWriterDictionary->WriteNewObjectReferenceValue(objectsContextI D); pdfWriterDictionary->WriteNewObjectReferenceValue(objectsContextI D);
pdfWriterDictionary->WriteKey("mDocumentContext"); pdfWriterDictionary->WriteKey("mDocumentContext");
pdfWriterDictionary->WriteNewObjectReferenceValue(DocumentContext ID); pdfWriterDictionary->WriteNewObjectReferenceValue(DocumentContext ID);
pdfWriterDictionary->WriteKey("mIsModified"); pdfWriterDictionary->WriteKey("mIsModified");
pdfWriterDictionary->WriteBooleanValue(mIsModified); pdfWriterDictionary->WriteBooleanValue(mIsModified);
pdfWriterDictionary->WriteKey("mEmbedFonts");
pdfWriterDictionary->WriteBooleanValue(mEmbedFonts);
if(mIsModified) if(mIsModified)
{ {
pdfWriterDictionary->WriteKey("mModifiedFileVersion"); pdfWriterDictionary->WriteKey("mModifiedFileVersion");
pdfWriterDictionary->WriteIntegerValue(mModifiedFileVersion); pdfWriterDictionary->WriteIntegerValue(mModifiedFileVersion);
} }
writer.GetObjectsWriter()->EndDictionary(pdfWriterDictionary); writer.GetObjectsWriter()->EndDictionary(pdfWriterDictionary);
writer.GetObjectsWriter()->EndIndirectObject(); writer.GetObjectsWriter()->EndIndirectObject();
writer.SetRootObject(rootObjectID); writer.SetRootObject(rootObjectID);
skipping to change at line 432 skipping to change at line 438
PDFObjectCastPtr<PDFBoolean> isModifiedObject(pdfWriterDictionary->Query DirectObject("mIsModified")); PDFObjectCastPtr<PDFBoolean> isModifiedObject(pdfWriterDictionary->Query DirectObject("mIsModified"));
mIsModified = isModifiedObject->GetValue(); mIsModified = isModifiedObject->GetValue();
if(mIsModified) if(mIsModified)
{ {
PDFObjectCastPtr<PDFInteger> isModifiedFileVersionObject(pdfWriterDi ctionary->QueryDirectObject("mModifiedFileVersion")); PDFObjectCastPtr<PDFInteger> isModifiedFileVersionObject(pdfWriterDi ctionary->QueryDirectObject("mModifiedFileVersion"));
mModifiedFileVersion = (EPDFVersion)(isModifiedFileVersionObject->Ge tValue()); mModifiedFileVersion = (EPDFVersion)(isModifiedFileVersionObject->Ge tValue());
} }
PDFObjectCastPtr<PDFBoolean> embedFontsObject(pdfWriterDictionary
->QueryDirectObject("mEmbedFonts"));
mEmbedFonts = embedFontsObject->GetValue();
PDFObjectCastPtr<PDFIndirectObjectReference> objectsContextObject (pdfWriterDictionary->QueryDirectObject("mObjectsContext")); PDFObjectCastPtr<PDFIndirectObjectReference> objectsContextObject (pdfWriterDictionary->QueryDirectObject("mObjectsContext"));
status = mObjectsContext.ReadState(reader.GetObjectsReader(),obje ctsContextObject->mObjectID); status = mObjectsContext.ReadState(reader.GetObjectsReader(),obje ctsContextObject->mObjectID);
if(status!= eSuccess) if(status!= eSuccess)
break; break;
PDFObjectCastPtr<PDFIndirectObjectReference> documentContextObjec t(pdfWriterDictionary->QueryDirectObject("mDocumentContext")); PDFObjectCastPtr<PDFIndirectObjectReference> documentContextObjec t(pdfWriterDictionary->QueryDirectObject("mDocumentContext"));
status = mDocumentContext.ReadState(reader.GetObjectsReader(),doc umentContextObject->mObjectID); status = mDocumentContext.ReadState(reader.GetObjectsReader(),doc umentContextObject->mObjectID);
if(status!= eSuccess) if(status!= eSuccess)
break; break;
skipping to change at line 493 skipping to change at line 502
inPageRange, inPageRange,
inCopyAdditionalObjects); inCopyAdditionalObjects);
} }
EStatusCode PDFWriter::StartPDFForStream(IByteWriterWithPosition* inOutputStream , EStatusCode PDFWriter::StartPDFForStream(IByteWriterWithPosition* inOutputStream ,
EPDFVersion inPDFVersion, EPDFVersion inPDFVersion,
const LogConfiguration& inLogConfiguration, const LogConfiguration& inLogConfiguration,
const PDFCreationSettings& inPDFCreationSettings) const PDFCreationSettings& inPDFCreationSettings)
{ {
SetupLog(inLogConfiguration); SetupLog(inLogConfiguration);
SetupObjectsContext(inPDFCreationSettings); SetupCreationSettings(inPDFCreationSettings);
mObjectsContext.SetOutputStream(inOutputStream); mObjectsContext.SetOutputStream(inOutputStream);
mIsModified = false; mIsModified = false;
return mDocumentContext.WriteHeader(inPDFVersion); return mDocumentContext.WriteHeader(inPDFVersion);
} }
EStatusCode PDFWriter::EndPDFForStream() EStatusCode PDFWriter::EndPDFForStream()
{ {
EStatusCode status; EStatusCode status;
if(mIsModified) if(mIsModified)
status = mDocumentContext.FinalizeModifiedPDF(&mModifiedFileParser,mModi fiedFileVersion); status = mDocumentContext.FinalizeModifiedPDF(&mModifiedFileParser,mModi fiedFileVersion,mEmbedFonts);
else else
status = mDocumentContext.FinalizeNewPDF(); status = mDocumentContext.FinalizeNewPDF(mEmbedFonts);
mModifiedFileParser.ResetParser(); mModifiedFileParser.ResetParser();
Cleanup(); Cleanup();
return status; return status;
} }
PDFImageXObject* PDFWriter::CreateImageXObjectFromJPGStream(IByteReaderWithPosit ion* inJPGStream) PDFImageXObject* PDFWriter::CreateImageXObjectFromJPGStream(IByteReaderWithPosit ion* inJPGStream)
{ {
return mDocumentContext.CreateImageXObjectFromJPGStream(inJPGStream); return mDocumentContext.CreateImageXObjectFromJPGStream(inJPGStream);
} }
skipping to change at line 581 skipping to change at line 590
EStatusCode PDFWriter::ModifyPDF(const std::string& inModifiedFile, EStatusCode PDFWriter::ModifyPDF(const std::string& inModifiedFile,
EPDFVersion inPDFVersion, EPDFVersion inPDFVersion,
const std::string& inOptionalAlterna tiveOutputFile, const std::string& inOptionalAlterna tiveOutputFile,
const LogConfiguration& inLogConfigu ration, const LogConfiguration& inLogConfigu ration,
const PDFCreationSettings& inPDFCrea tionSettings) const PDFCreationSettings& inPDFCrea tionSettings)
{ {
EStatusCode status = eSuccess; EStatusCode status = eSuccess;
SetupLog(inLogConfiguration); SetupLog(inLogConfiguration);
SetupObjectsContext(inPDFCreationSettings); SetupCreationSettings(inPDFCreationSettings);
do do
{ {
// either append to original file, or create a new copy and "modify" it. depending on users choice // either append to original file, or create a new copy and "modify" it. depending on users choice
if(inOptionalAlternativeOutputFile.size() == 0 || (inOptionalAlternative OutputFile == inModifiedFile)) if(inOptionalAlternativeOutputFile.size() == 0 || (inOptionalAlternative OutputFile == inModifiedFile))
{ {
status = mOutputFile.OpenFile(inModifiedFile,true); status = mOutputFile.OpenFile(inModifiedFile,true);
if(status != eSuccess) if(status != eSuccess)
break; break;
} }
skipping to change at line 625 skipping to change at line 634
status = SetupStateFromModifiedFile(inModifiedFile,inPDFVersion); status = SetupStateFromModifiedFile(inModifiedFile,inPDFVersion);
} }
while (false); while (false);
return status; return status;
} }
EStatusCode PDFWriter::ModifyPDFForStream( EStatusCode PDFWriter::ModifyPDFForStream(
IByteReaderWithPosition* inModifiedSourceS tream, IByteReaderWithPosition* inModifiedSourceS tream,
IByteWriterWithPosition* inModifiedDestina tionStream, IByteWriterWithPosition* inModifiedDestina tionStream,
bool inAppendOnly,
EPDFVersion inPDFVersion, EPDFVersion inPDFVersion,
const LogConfiguration& inLogConfiguration , const LogConfiguration& inLogConfiguration ,
const PDFCreationSettings& inPDFCreationSe ttings) const PDFCreationSettings& inPDFCreationSe ttings)
{ {
SetupLog(inLogConfiguration); SetupLog(inLogConfiguration);
SetupObjectsContext(inPDFCreationSettings); SetupCreationSettings(inPDFCreationSettings);
if(!inAppendOnly)
{
// copy original to new output stream
OutputStreamTraits traits(inModifiedDestinationStream);
EStatusCode status = traits.CopyToOutputStream(inModifiedSourceStream);
if(status != eSuccess)
return status;
inModifiedSourceStream->SetPosition(0);
}
mObjectsContext.SetOutputStream(inModifiedDestinationStream); mObjectsContext.SetOutputStream(inModifiedDestinationStream);
mIsModified = true; mIsModified = true;
return SetupStateFromModifiedStream(inModifiedSourceStream,inPDFVersion); return SetupStateFromModifiedStream(inModifiedSourceStream,inPDFVersion);
} }
EStatusCode PDFWriter::SetupStateFromModifiedStream(IByteReaderWithPosition* inM odifiedSourceStream, EStatusCode PDFWriter::SetupStateFromModifiedStream(IByteReaderWithPosition* inM odifiedSourceStream,
EPDFVersion inPDFVersion) EPDFVersion inPDFVersion)
skipping to change at line 695 skipping to change at line 715
InputFile& PDFWriter::GetModifiedInputFile() InputFile& PDFWriter::GetModifiedInputFile()
{ {
return mModifiedFile; return mModifiedFile;
} }
PDFDocumentCopyingContext* PDFWriter::CreatePDFCopyingContextForModifiedFile() PDFDocumentCopyingContext* PDFWriter::CreatePDFCopyingContextForModifiedFile()
{ {
return mDocumentContext.CreatePDFCopyingContext(&mModifiedFileParser); return mDocumentContext.CreatePDFCopyingContext(&mModifiedFileParser);
} }
DoubleAndDoublePair PDFWriter::GetImageDimensions(const std::string& inImageFile
,unsigned long inImageIndex)
{
return mDocumentContext.GetImageDimensions(inImageFile,inImageIndex);
}
PDFHummus::EHummusImageType PDFWriter::GetImageType(const std::string& inImageFi
le,unsigned long inImageIndex)
{
return mDocumentContext.GetImageType(inImageFile,inImageIndex);
}
unsigned long PDFWriter::GetImagePagesCount(const std::string& inImageFile)
{
return mDocumentContext.GetImagePagesCount(inImageFile);
}
 End of changes. 18 change blocks. 
11 lines changed or deleted 32 lines changed or added

Home  |  About  |  All  |  Newest  |  Fossies Dox  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTPS