aboutsummaryrefslogtreecommitdiffhomepage
path: root/experimental/PdfViewer/pdfparser
diff options
context:
space:
mode:
authorGravatar scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-12-02 20:22:31 +0000
committerGravatar scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-12-02 20:22:31 +0000
commit5092adc5461a7c5cb3e1fad01be2174c3f4a0c46 (patch)
tree9c53fcd18cac52b437d21dcb6dc2154bbfc26792 /experimental/PdfViewer/pdfparser
parent248647cebb3724fd2ce1d41745afb786516af4f8 (diff)
Separate and update PDF_DIFF_TRACE_IN_PNG
Move its functionality out of readToken() and into its own class. Callers of the previous readToken() now call SkPdfNativeTokenizer::readToken(), which in turn calls a function for writing the diff to a file, if the caller requests it and PDF_TRACE_DIFF_IN_PNG is defined. Do not attempt to draw a diff for compatibility sections, which we do not draw. Use SkString to handle string manipulation. Hide globals only used by PDF_TRACE_DIFF_IN_PNG behind that flag. Remove hasVisualEffects, which always returns true. Rename gLastOpKeyword to gOpCounter for clarity. In SkPdfNativeTokenizer, set fEmpty to true when the entire stream has been read. Use SkBitmap::copyTo instead of manually copying an SkBitmap. Builds on https://codereview.chromium.org/79933003/ R=mtklein@google.com Review URL: https://codereview.chromium.org/80463005 git-svn-id: http://skia.googlecode.com/svn/trunk@12436 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'experimental/PdfViewer/pdfparser')
-rw-r--r--experimental/PdfViewer/pdfparser/native/SkPdfNativeTokenizer.cpp21
-rw-r--r--experimental/PdfViewer/pdfparser/native/SkPdfNativeTokenizer.h5
2 files changed, 19 insertions, 7 deletions
diff --git a/experimental/PdfViewer/pdfparser/native/SkPdfNativeTokenizer.cpp b/experimental/PdfViewer/pdfparser/native/SkPdfNativeTokenizer.cpp
index 79935bc954..5dfe14e5fc 100644
--- a/experimental/PdfViewer/pdfparser/native/SkPdfNativeTokenizer.cpp
+++ b/experimental/PdfViewer/pdfparser/native/SkPdfNativeTokenizer.cpp
@@ -6,6 +6,7 @@
*/
#include "SkPdfConfig.h"
+#include "SkPdfDiffEncoder.h"
#include "SkPdfNativeObject.h"
#include "SkPdfNativeTokenizer.h"
#include "SkPdfUtils.h"
@@ -940,6 +941,7 @@ bool SkPdfNativeTokenizer::readTokenCore(PdfToken* token) {
fUncompressedStream = skipPdfWhiteSpaces(fUncompressedStream, fUncompressedStreamEnd);
if (fUncompressedStream >= fUncompressedStreamEnd) {
+ fEmpty = true;
return false;
}
@@ -985,26 +987,33 @@ void SkPdfNativeTokenizer::PutBack(PdfToken token) {
#endif
}
-bool SkPdfNativeTokenizer::readToken(PdfToken* token) {
+bool SkPdfNativeTokenizer::readToken(PdfToken* token, bool writeDiff) {
if (fHasPutBack) {
*token = fPutBack;
fHasPutBack = false;
#ifdef PDF_TRACE_READ_TOKEN
- printf("READ_BACK %s %s\n", token->fType == kKeyword_TokenType ? "Keyword" : "Object",
- token->fKeyword ? SkString(token->fKeyword, token->fKeywordLength).c_str() :
- token->fObject->toString().c_str());
+ printf("READ_BACK %s %s\n", token->fType == kKeyword_TokenType ? "Keyword" : "Object",
+ token->fKeyword ? SkString(token->fKeyword, token->fKeywordLength).c_str() :
+ token->fObject->toString().c_str());
#endif
+ if (writeDiff) {
+ SkPdfDiffEncoder::WriteToFile(token);
+ }
return true;
}
if (fEmpty) {
#ifdef PDF_TRACE_READ_TOKEN
- printf("EMPTY TOKENIZER\n");
+ printf("EMPTY TOKENIZER\n");
#endif
return false;
}
- return readTokenCore(token);
+ const bool result = readTokenCore(token);
+ if (result && writeDiff) {
+ SkPdfDiffEncoder::WriteToFile(token);
+ }
+ return result;
}
#define DECLARE_PDF_NAME(longName) SkPdfName longName((char*)#longName)
diff --git a/experimental/PdfViewer/pdfparser/native/SkPdfNativeTokenizer.h b/experimental/PdfViewer/pdfparser/native/SkPdfNativeTokenizer.h
index 8ed354cfa1..79b070f12e 100644
--- a/experimental/PdfViewer/pdfparser/native/SkPdfNativeTokenizer.h
+++ b/experimental/PdfViewer/pdfparser/native/SkPdfNativeTokenizer.h
@@ -165,7 +165,10 @@ public:
virtual ~SkPdfNativeTokenizer();
// Reads one token. Returns false if there are no more tokens.
- bool readToken(PdfToken* token);
+ // If writeDiff is true, and a token was read, create a PNG highlighting
+ // the difference caused by this command in /tmp/log_step_by_step.
+ // If PDF_TRACE_DIFF_IN_PNG is not defined, writeDiff does nothing.
+ bool readToken(PdfToken* token, bool writeDiff = false);
// Put back a token to be read in the nextToken read. Only one token is allowed to be put
// back. Must not necesaarely be the last token read.