EStatusCode PreprocessorTest::RunTest(const string& inName, const string& inOriginalFile, const string& inOutputFile, const string& inComparisonFile) { EStatusCode status = eSuccess; StringToStringMap preprocessorDefinitions; StringList includeFolders; includeFolders.push_back(scSamplesBasePath); preprocessorDefinitions.insert(StringToStringMap::value_type("PREDEFINED_SYMBOL","2")); InputFile sourceFile; sourceFile.OpenFile(inOriginalFile); OutputFile outputFile; outputFile.OpenFile(inOutputFile); mCurrentStream = outputFile.GetOutputStream(); PreProcessor preProcessor; preProcessor.Setup(sourceFile.GetInputStream(),inOriginalFile,preprocessorDefinitions,includeFolders); preProcessor.AddListener(this); mStartRow = true; BoolAndString tokenizerResult = preProcessor.GetNextToken(); while(tokenizerResult.first) { if(!mStartRow) mCurrentStream->Write((const Byte*)" ",2); // 2 spaces, so we can clearly distinct tokens mCurrentStream->Write((const Byte*)tokenizerResult.second.c_str(),tokenizerResult.second.size()); mStartRow = false; tokenizerResult = preProcessor.GetNextToken(); } sourceFile.CloseFile(); outputFile.CloseFile(); mCurrentStream = NULL; SimpleFileComparer comparer; if(!comparer.Same(inOutputFile,inComparisonFile)) { cout<<"TokenizerTest::Run, failed in test named "<<inName<<". see result in "<<inOutputFile<<" and compare with the required result in "<<inComparisonFile<<"\n"; status = eFailure; } return status; }
EStatusCode OpenTypeTest::SaveCharstringCode(unsigned short inFontIndex,unsigned short inGlyphIndex,CFFFileInput* inCFFFileInput) { OutputFile glyphFile; EStatusCode status = glyphFile.OpenFile(string("C:\\PDFLibTests\\glyphCFF") + Long(inFontIndex).ToString() + "_" + inCFFFileInput->GetGlyphName(0,inGlyphIndex) + ".txt"); do { if(status != PDFHummus::eSuccess) break; CharStringType2Tracer tracer; status = tracer.TraceGlyphProgram(inFontIndex,inGlyphIndex,inCFFFileInput,glyphFile.GetOutputStream()); }while(false); glyphFile.CloseFile(); return status; }
EStatusCode PFBStreamTest::Run(const TestConfiguration& inTestConfiguration) { EStatusCode status; InputFile pfbFile; OutputFile decodedPFBFile; InputPFBDecodeStream decodeStream; do { pfbFile.OpenFile(RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"TestMaterials/fonts/HLB_____.PFB")); decodedPFBFile.OpenFile(RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,"decodedPFBFile.txt")); status = decodeStream.Assign(pfbFile.GetInputStream()); if(status != PDFHummus::eSuccess) { cout<<"Failed to assign pfb input stream"; break; } OutputStreamTraits traits(decodedPFBFile.GetOutputStream()); status = traits.CopyToOutputStream(&decodeStream); if(status != PDFHummus::eSuccess) { cout<<"Failed to decode pfb stream"; break; } }while(false); decodeStream.Assign(NULL); pfbFile.CloseFile(); decodedPFBFile.CloseFile(); return status; }
EStatusCode Type1Test::SaveCharstringCode(const TestConfiguration& inTestConfiguration,const string& inCharStringName,Type1Input* inType1Input) { OutputFile glyphFile; EStatusCode status = glyphFile.OpenFile( RelativeURLToLocalPath(inTestConfiguration.mSampleFileBase,string("glyphType1_") + inCharStringName + "_.txt")); do { if(status != PDFHummus::eSuccess) break; CharStringType1Tracer tracer; status = tracer.TraceGlyphProgram(inCharStringName,inType1Input,glyphFile.GetOutputStream()); }while(false); glyphFile.CloseFile(); return status; }
EStatusCode CustomLogTest::Run() { // Place log in a compressed stream, for a non-file PDF EStatusCode status; OutputFlateEncodeStream flateEncodeStream; OutputFlateDecodeStream flateDecodeStream; do { PDFWriter pdfWriter; OutputFile compressedLogFile; OutputStringBufferStream pdfStream; // setup log file with compression status = compressedLogFile.OpenFile("c:\\PDFLibTests\\CustomLogEncrypted.txt"); if(status != PDFHummus::eSuccess) break; flateEncodeStream.Assign(compressedLogFile.GetOutputStream()); // generate PDF TRACE_LOG("Starting PDF File Writing"); status = pdfWriter.StartPDFForStream(&pdfStream,ePDFVersion13,LogConfiguration(true,&flateEncodeStream)); if(status != PDFHummus::eSuccess) break; TRACE_LOG("Now will add an empty page"); PDFPage* page = new PDFPage(); page->SetMediaBox(PDFRectangle(0,0,400,400)); status = pdfWriter.WritePageAndRelease(page); if(status != PDFHummus::eSuccess) break; TRACE_LOG("Added page, now will close"); status = pdfWriter.EndPDFForStream(); if(status != PDFHummus::eSuccess) break; // since log was started by starting PDF...the ending resets it. so let's now begin again Singleton<Trace>::GetInstance()->SetLogSettings(&flateEncodeStream,true); TRACE_LOG("Finished PDF!!!1"); // dump PDF to a file, so we can review it OutputFile pdfFile; status = pdfFile.OpenFile("c:\\PDFLibTests\\DumpPDFFile.pdf"); if(status != PDFHummus::eSuccess) break; string pdfString = pdfStream.ToString(); pdfFile.GetOutputStream()->Write((const Byte*)pdfString.c_str(),pdfString.size()); pdfFile.CloseFile(); TRACE_LOG("PDF stream dumped"); // now finalize trace compressed file flateEncodeStream.Assign(NULL); compressedLogFile.CloseFile(); // Finish log Singleton<Trace>::Reset(); // now open a new file and decompress the log into it. OutputFile decryptedLogFile; status = decryptedLogFile.OpenFile("c:\\PDFLibTests\\CustomLogDecrypted.txt"); if(status != PDFHummus::eSuccess) break; // place an initial bom (cause the compressed content is unicode) unsigned short bom = (0xFE<<8) + 0xFF; decryptedLogFile.GetOutputStream()->Write((const Byte*)&bom,2); flateDecodeStream.Assign(decryptedLogFile.GetOutputStream()); OutputStreamTraits traits(&flateDecodeStream); InputFile compressedLogFileInput; status = compressedLogFileInput.OpenFile("c:\\PDFLibTests\\CustomLogEncrypted.txt"); if(status != PDFHummus::eSuccess) break; status = traits.CopyToOutputStream(compressedLogFileInput.GetInputStream()); if(status != PDFHummus::eSuccess) break; compressedLogFileInput.CloseFile(); flateDecodeStream.Assign(NULL); decryptedLogFile.CloseFile(); }while(false); if(status != PDFHummus::eSuccess) { // cancel ownership of subsstreams flateDecodeStream.Assign(NULL); flateEncodeStream.Assign(NULL); } return status; }