Skip to content

Commit

Permalink
latest corrections from HummusJS
Browse files Browse the repository at this point in the history
pages resources inheritance support and xcode warnings cleanups
  • Loading branch information
galkahana committed Apr 7, 2018
1 parent 458737e commit c178523
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 15 deletions.
4 changes: 2 additions & 2 deletions PDFWriter/CFFANSIFontWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ bool CFFANSIFontWriter::CanWriteDifferencesFromWinAnsi()


static const std::string scCharSet = "CharSet";
static const Byte scLeftParanthesis[] = {'('};
static const Byte scRightParanthesis[] = {')'};
//static const Byte scLeftParanthesis[] = {'('};
//static const Byte scRightParanthesis[] = {')'};

void CFFANSIFontWriter::WriteCharSet( DictionaryContext* inDescriptorContext,
ObjectsContext* inObjectsContext,
Expand Down
4 changes: 2 additions & 2 deletions PDFWriter/CFFDescendentFontWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ CFFDescendentFontWriter::~CFFDescendentFontWriter(void)
{
}

static bool sEncodedGlypsSort(const UIntAndGlyphEncodingInfo& inLeft, const UIntAndGlyphEncodingInfo& inRight)
/*static bool sEncodedGlypsSort(const UIntAndGlyphEncodingInfo& inLeft, const UIntAndGlyphEncodingInfo& inRight)
{
return inLeft.first < inRight.first;
}
}*/

static const std::string scCIDFontType0C = "CIDFontType0C";
static const char* scType1 = "Type 1";
Expand Down
2 changes: 1 addition & 1 deletion PDFWriter/InputAESDecodeStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void InputAESDecodeStream::Assign(IByteReader* inSourceReader, const ByteList& i

bool InputAESDecodeStream::NotEnded()
{
return mSourceStream && mSourceStream->NotEnded() || !mHitEnd || ((mOutIndex - mOut) < mReadBlockSize);
return (mSourceStream && mSourceStream->NotEnded()) || !mHitEnd || ((mOutIndex - mOut) < mReadBlockSize);
}

LongBufferSizeType InputAESDecodeStream::Read(IOBasicTypes::Byte* inBuffer, LongBufferSizeType inSize)
Expand Down
27 changes: 23 additions & 4 deletions PDFWriter/PDFDocumentHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ EStatusCode PDFDocumentHandler::CopyResourcesIndirectObjects(PDFDictionary* inPa
// if indirect, run CopyInDirectObject on it (passing its ID and a new ID at the target PDF (just allocate as you go))
// if direct, let go.

PDFObjectCastPtr<PDFDictionary> resources(mParser->QueryDictionaryObject(inPage,"Resources"));
PDFObjectCastPtr<PDFDictionary> resources(FindPageResources(mParser, inPage));

// k. no resources...as wierd as that might be...or just wrong...i'll let it be
if(!resources)
Expand Down Expand Up @@ -629,7 +629,7 @@ EStatusCode PDFDocumentHandler::OnResourcesWrite(
// Writing resources dictionary. simply loop internal elements and copy. nicely enough, i can use read methods, trusting
// that no new objects need be written

PDFObjectCastPtr<PDFDictionary> resources(mParser->QueryDictionaryObject(mWrittenPage,"Resources"));
PDFObjectCastPtr<PDFDictionary> resources(FindPageResources(mParser, mWrittenPage));
ObjectIDTypeList dummyObjectList; // this one should remain empty...

// k. no resources...as wierd as that might be...or just wrong...i'll let it be
Expand Down Expand Up @@ -1343,7 +1343,7 @@ EStatusCode PDFDocumentHandler::MergeResourcesToPage(PDFPage* inTargetPage,PDFDi
{
// parse each individual resources dictionary separately and copy the resources. the output parameter should be used for old vs. new names

PDFObjectCastPtr<PDFDictionary> resources(mParser->QueryDictionaryObject(inPage,"Resources"));
PDFObjectCastPtr<PDFDictionary> resources(FindPageResources(mParser, inPage));

// k. no resources...as wierd as that might be...or just wrong...i'll let it be
if(!resources)
Expand Down Expand Up @@ -2219,7 +2219,7 @@ EStatusCode PDFDocumentHandler::RegisterResourcesForForm(PDFFormXObject* inTarge

do
{
PDFObjectCastPtr<PDFDictionary> resources(mParser->QueryDictionaryObject(inPageObject,"Resources"));
PDFObjectCastPtr<PDFDictionary> resources(FindPageResources(mParser, inPageObject));

// k. no resources...as wierd as that might be...or just wrong...i'll let it be
if(!resources)
Expand Down Expand Up @@ -2441,3 +2441,22 @@ void PDFDocumentHandler::RegisterFormRelatedObjects(PDFFormXObject* inFormXObjec
{
mDocumentContext->RegisterFormEndWritingTask(inFormXObject,new ObjectsCopyingTask(this,inObjectsToWrite));
}

PDFObject* PDFDocumentHandler::FindPageResources(PDFParser* inParser, PDFDictionary* inDictionary) {
if(inDictionary->Exists("Resources")) {
return inParser->QueryDictionaryObject(inDictionary, "Resources");
}
else {
PDFObjectCastPtr<PDFDictionary> parentDict(
inDictionary->Exists("Parent") ?
inParser->QueryDictionaryObject(inDictionary, "Parent"):
NULL);
if(!parentDict) {
return NULL;
}
else {
return FindPageResources(inParser,parentDict.GetPtr());
}

}
}
2 changes: 2 additions & 0 deletions PDFWriter/PDFDocumentHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class IPageEmbedInFormCommand;
class IPDFParserExtender;
class ICategoryServicesCommand;
class PDFIndirectObjectReference;
class PDFObject;


namespace PDFHummus
Expand Down Expand Up @@ -322,6 +323,7 @@ class PDFDocumentHandler : public DocumentContextExtenderAdapter
PDFHummus::EStatusCode MergePageContentToTargetXObject(PDFFormXObject* inTargetFormXObject,
PDFDictionary* inSourcePage,
const StringToStringMap& inMappedResourcesNames);
PDFObject* FindPageResources(PDFParser* inParser, PDFDictionary* inDictionary);


};
2 changes: 1 addition & 1 deletion PDFWriter/PDFParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2151,7 +2151,7 @@ void PDFParser::SetParserExtender(IPDFParserExtender* inParserExtender)

bool PDFParser::IsEncryptionSupported()
{
return mDecryptionHelper.CanDecryptDocument() || mParserExtender && mParserExtender->DoesSupportEncryption();
return mDecryptionHelper.CanDecryptDocument() || (mParserExtender && mParserExtender->DoesSupportEncryption());
}

ObjectIDType PDFParser::GetXrefSize()
Expand Down
2 changes: 1 addition & 1 deletion PDFWriter/PNGImageHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ void ReadDataFromStream(png_structp png_ptr, png_bytep data, png_size_t length)
IByteReaderWithPosition* reader = (IByteReaderWithPosition*)png_get_io_ptr(png_ptr);
IOBasicTypes::LongFilePositionType readBytes = reader->Read((IOBasicTypes::Byte*)(data), length);

if (readBytes != length)
if (readBytes != (IOBasicTypes::LongFilePositionType)length)
png_error(png_ptr, "Read Error");
}

Expand Down
6 changes: 3 additions & 3 deletions PDFWriter/SimpleStringTokenizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ void SimpleStringTokenizer::ResetReadState(const SimpleStringTokenizer& inExtern
mRecentTokenPosition = inExternalTokenizer.mRecentTokenPosition;
}

static const Byte scBackSlash[] = {'\\'};
//static const Byte scBackSlash[] = {'\\'};
static const std::string scStream = "stream";
static const char scCR = '\r';
static const char scLF = '\n';
//static const char scCR = '\r';
//static const char scLF = '\n';
BoolAndString SimpleStringTokenizer::GetNextToken()
{
BoolAndString result;
Expand Down
1 change: 0 additions & 1 deletion PDFWriter/XCryptionCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ class XCryptionCommon {
ByteListList mEncryptionKeysStack;
bool mUsingAES;
ByteList mEncryptionKey;
bool mCanXCrypt;

ByteList RC4Encode(const ByteList& inKey, const ByteList& inToEncode);
ByteList ComputeEncryptionKeyForObject(ObjectIDType inObjectNumber, unsigned long inGenerationNumber); // with algorithm3_1
Expand Down

0 comments on commit c178523

Please sign in to comment.