pdf viewer: fix a few warnings, and enable warning as errors

Review URL: https://codereview.chromium.org/18293012

git-svn-id: http://skia.googlecode.com/svn/trunk@9966 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/experimental/PdfViewer/SkPdfFont.cpp b/experimental/PdfViewer/SkPdfFont.cpp
index 2309f54..4f2b279 100644
--- a/experimental/PdfViewer/SkPdfFont.cpp
+++ b/experimental/PdfViewer/SkPdfFont.cpp
@@ -11,83 +11,83 @@
     // TODO (edisonn): , vs - ? what does it mean?
     // TODO (edisonn): MT, PS, Oblique=italic?, ... what does it mean?
     if (gPdfStandardFonts.empty()) {
-        gPdfStandardFonts["Arial"] = {"Arial", false, false};
-        gPdfStandardFonts["Arial,Bold"] = {"Arial", true, false};
-        gPdfStandardFonts["Arial,BoldItalic"] = {"Arial", true, true};
-        gPdfStandardFonts["Arial,Italic"] = {"Arial", false, true};
-        gPdfStandardFonts["Arial-Bold"] = {"Arial", true, false};
-        gPdfStandardFonts["Arial-BoldItalic"] = {"Arial", true, true};
-        gPdfStandardFonts["Arial-BoldItalicMT"] = {"Arial", true, true};
-        gPdfStandardFonts["Arial-BoldMT"] = {"Arial", true, false};
-        gPdfStandardFonts["Arial-Italic"] = {"Arial", false, true};
-        gPdfStandardFonts["Arial-ItalicMT"] = {"Arial", false, true};
-        gPdfStandardFonts["ArialMT"] = {"Arial", false, false};
-        gPdfStandardFonts["Courier"] = {"Courier New", false, false};
-        gPdfStandardFonts["Courier,Bold"] = {"Courier New", true, false};
-        gPdfStandardFonts["Courier,BoldItalic"] = {"Courier New", true, true};
-        gPdfStandardFonts["Courier,Italic"] = {"Courier New", false, true};
-        gPdfStandardFonts["Courier-Bold"] = {"Courier New", true, false};
-        gPdfStandardFonts["Courier-BoldOblique"] = {"Courier New", true, true};
-        gPdfStandardFonts["Courier-Oblique"] = {"Courier New", false, true};
-        gPdfStandardFonts["CourierNew"] = {"Courier New", false, false};
-        gPdfStandardFonts["CourierNew,Bold"] = {"Courier New", true, false};
-        gPdfStandardFonts["CourierNew,BoldItalic"] = {"Courier New", true, true};
-        gPdfStandardFonts["CourierNew,Italic"] = {"Courier New", false, true};
-        gPdfStandardFonts["CourierNew-Bold"] = {"Courier New", true, false};
-        gPdfStandardFonts["CourierNew-BoldItalic"] = {"Courier New", true, true};
-        gPdfStandardFonts["CourierNew-Italic"] = {"Courier New", false, true};
-        gPdfStandardFonts["CourierNewPS-BoldItalicMT"] = {"Courier New", true, true};
-        gPdfStandardFonts["CourierNewPS-BoldMT"] = {"Courier New", true, false};
-        gPdfStandardFonts["CourierNewPS-ItalicMT"] = {"Courier New", false, true};
-        gPdfStandardFonts["CourierNewPSMT"] = {"Courier New", false, false};
-        gPdfStandardFonts["Helvetica"] = {"Helvetica", false, false};
-        gPdfStandardFonts["Helvetica,Bold"] = {"Helvetica", true, false};
-        gPdfStandardFonts["Helvetica,BoldItalic"] = {"Helvetica", true, true};
-        gPdfStandardFonts["Helvetica,Italic"] = {"Helvetica", false, true};
-        gPdfStandardFonts["Helvetica-Bold"] = {"Helvetica", true, false};
-        gPdfStandardFonts["Helvetica-BoldItalic"] = {"Helvetica", true, true};
-        gPdfStandardFonts["Helvetica-BoldOblique"] = {"Helvetica", true, true};
-        gPdfStandardFonts["Helvetica-Italic"] = {"Helvetica", false, true};
-        gPdfStandardFonts["Helvetica-Oblique"] = {"Helvetica", false, true};
-        gPdfStandardFonts["Times-Bold"] = {"Times New Roman", true, false};
-        gPdfStandardFonts["Times-BoldItalic"] = {"Times New Roman", true, true};
-        gPdfStandardFonts["Times-Italic"] = {"Times New Roman", false, true};
-        gPdfStandardFonts["Times-Roman"] = {"Times New Roman", false, false};
-        gPdfStandardFonts["TimesNewRoman"] = {"Times New Roman", false, false};
-        gPdfStandardFonts["TimesNewRoman,Bold"] = {"Times New Roman", true, false};
-        gPdfStandardFonts["TimesNewRoman,BoldItalic"] = {"Times New Roman", true, true};
-        gPdfStandardFonts["TimesNewRoman,Italic"] = {"Times New Roman", false, true};
-        gPdfStandardFonts["TimesNewRoman-Bold"] = {"Times New Roman", true, false};
-        gPdfStandardFonts["TimesNewRoman-BoldItalic"] = {"Times New Roman", true, true};
-        gPdfStandardFonts["TimesNewRoman-Italic"] = {"Times New Roman", false, true};
-        gPdfStandardFonts["TimesNewRomanPS"] = {"Times New Roman", false, false};
-        gPdfStandardFonts["TimesNewRomanPS-Bold"] = {"Times New Roman", true, false};
-        gPdfStandardFonts["TimesNewRomanPS-BoldItalic"] = {"Times New Roman", true, true};
-        gPdfStandardFonts["TimesNewRomanPS-BoldItalicMT"] = {"Times New Roman", true, true};
-        gPdfStandardFonts["TimesNewRomanPS-BoldMT"] = {"Times New Roman", true, false};
-        gPdfStandardFonts["TimesNewRomanPS-Italic"] = {"Times New Roman", false, true};
-        gPdfStandardFonts["TimesNewRomanPS-ItalicMT"] = {"Times New Roman", false, true};
-        gPdfStandardFonts["TimesNewRomanPSMT"] = {"Times New Roman", false, false};
-        gPdfStandardFonts["Symbol"] = {"Symbol", false, false};
-        gPdfStandardFonts["ZapfDingbats"] = {"ZapfDingbats", false, false};
+        gPdfStandardFonts["Arial"] = SkPdfStandardFontEntry("Arial", false, false);
+        gPdfStandardFonts["Arial,Bold"] = SkPdfStandardFontEntry("Arial", true, false);
+        gPdfStandardFonts["Arial,BoldItalic"] = SkPdfStandardFontEntry("Arial", true, true);
+        gPdfStandardFonts["Arial,Italic"] = SkPdfStandardFontEntry("Arial", false, true);
+        gPdfStandardFonts["Arial-Bold"] = SkPdfStandardFontEntry("Arial", true, false);
+        gPdfStandardFonts["Arial-BoldItalic"] = SkPdfStandardFontEntry("Arial", true, true);
+        gPdfStandardFonts["Arial-BoldItalicMT"] = SkPdfStandardFontEntry("Arial", true, true);
+        gPdfStandardFonts["Arial-BoldMT"] = SkPdfStandardFontEntry("Arial", true, false);
+        gPdfStandardFonts["Arial-Italic"] = SkPdfStandardFontEntry("Arial", false, true);
+        gPdfStandardFonts["Arial-ItalicMT"] = SkPdfStandardFontEntry("Arial", false, true);
+        gPdfStandardFonts["ArialMT"] = SkPdfStandardFontEntry("Arial", false, false);
+        gPdfStandardFonts["Courier"] = SkPdfStandardFontEntry("Courier New", false, false);
+        gPdfStandardFonts["Courier,Bold"] = SkPdfStandardFontEntry("Courier New", true, false);
+        gPdfStandardFonts["Courier,BoldItalic"] = SkPdfStandardFontEntry("Courier New", true, true);
+        gPdfStandardFonts["Courier,Italic"] = SkPdfStandardFontEntry("Courier New", false, true);
+        gPdfStandardFonts["Courier-Bold"] = SkPdfStandardFontEntry("Courier New", true, false);
+        gPdfStandardFonts["Courier-BoldOblique"] = SkPdfStandardFontEntry("Courier New", true, true);
+        gPdfStandardFonts["Courier-Oblique"] = SkPdfStandardFontEntry("Courier New", false, true);
+        gPdfStandardFonts["CourierNew"] = SkPdfStandardFontEntry("Courier New", false, false);
+        gPdfStandardFonts["CourierNew,Bold"] = SkPdfStandardFontEntry("Courier New", true, false);
+        gPdfStandardFonts["CourierNew,BoldItalic"] = SkPdfStandardFontEntry("Courier New", true, true);
+        gPdfStandardFonts["CourierNew,Italic"] = SkPdfStandardFontEntry("Courier New", false, true);
+        gPdfStandardFonts["CourierNew-Bold"] = SkPdfStandardFontEntry("Courier New", true, false);
+        gPdfStandardFonts["CourierNew-BoldItalic"] = SkPdfStandardFontEntry("Courier New", true, true);
+        gPdfStandardFonts["CourierNew-Italic"] = SkPdfStandardFontEntry("Courier New", false, true);
+        gPdfStandardFonts["CourierNewPS-BoldItalicMT"] = SkPdfStandardFontEntry("Courier New", true, true);
+        gPdfStandardFonts["CourierNewPS-BoldMT"] = SkPdfStandardFontEntry("Courier New", true, false);
+        gPdfStandardFonts["CourierNewPS-ItalicMT"] = SkPdfStandardFontEntry("Courier New", false, true);
+        gPdfStandardFonts["CourierNewPSMT"] = SkPdfStandardFontEntry("Courier New", false, false);
+        gPdfStandardFonts["Helvetica"] = SkPdfStandardFontEntry("Helvetica", false, false);
+        gPdfStandardFonts["Helvetica,Bold"] = SkPdfStandardFontEntry("Helvetica", true, false);
+        gPdfStandardFonts["Helvetica,BoldItalic"] = SkPdfStandardFontEntry("Helvetica", true, true);
+        gPdfStandardFonts["Helvetica,Italic"] = SkPdfStandardFontEntry("Helvetica", false, true);
+        gPdfStandardFonts["Helvetica-Bold"] = SkPdfStandardFontEntry("Helvetica", true, false);
+        gPdfStandardFonts["Helvetica-BoldItalic"] = SkPdfStandardFontEntry("Helvetica", true, true);
+        gPdfStandardFonts["Helvetica-BoldOblique"] = SkPdfStandardFontEntry("Helvetica", true, true);
+        gPdfStandardFonts["Helvetica-Italic"] = SkPdfStandardFontEntry("Helvetica", false, true);
+        gPdfStandardFonts["Helvetica-Oblique"] = SkPdfStandardFontEntry("Helvetica", false, true);
+        gPdfStandardFonts["Times-Bold"] = SkPdfStandardFontEntry("Times New Roman", true, false);
+        gPdfStandardFonts["Times-BoldItalic"] = SkPdfStandardFontEntry("Times New Roman", true, true);
+        gPdfStandardFonts["Times-Italic"] = SkPdfStandardFontEntry("Times New Roman", false, true);
+        gPdfStandardFonts["Times-Roman"] = SkPdfStandardFontEntry("Times New Roman", false, false);
+        gPdfStandardFonts["TimesNewRoman"] = SkPdfStandardFontEntry("Times New Roman", false, false);
+        gPdfStandardFonts["TimesNewRoman,Bold"] = SkPdfStandardFontEntry("Times New Roman", true, false);
+        gPdfStandardFonts["TimesNewRoman,BoldItalic"] = SkPdfStandardFontEntry("Times New Roman", true, true);
+        gPdfStandardFonts["TimesNewRoman,Italic"] = SkPdfStandardFontEntry("Times New Roman", false, true);
+        gPdfStandardFonts["TimesNewRoman-Bold"] = SkPdfStandardFontEntry("Times New Roman", true, false);
+        gPdfStandardFonts["TimesNewRoman-BoldItalic"] = SkPdfStandardFontEntry("Times New Roman", true, true);
+        gPdfStandardFonts["TimesNewRoman-Italic"] = SkPdfStandardFontEntry("Times New Roman", false, true);
+        gPdfStandardFonts["TimesNewRomanPS"] = SkPdfStandardFontEntry("Times New Roman", false, false);
+        gPdfStandardFonts["TimesNewRomanPS-Bold"] = SkPdfStandardFontEntry("Times New Roman", true, false);
+        gPdfStandardFonts["TimesNewRomanPS-BoldItalic"] = SkPdfStandardFontEntry("Times New Roman", true, true);
+        gPdfStandardFonts["TimesNewRomanPS-BoldItalicMT"] = SkPdfStandardFontEntry("Times New Roman", true, true);
+        gPdfStandardFonts["TimesNewRomanPS-BoldMT"] = SkPdfStandardFontEntry("Times New Roman", true, false);
+        gPdfStandardFonts["TimesNewRomanPS-Italic"] = SkPdfStandardFontEntry("Times New Roman", false, true);
+        gPdfStandardFonts["TimesNewRomanPS-ItalicMT"] = SkPdfStandardFontEntry("Times New Roman", false, true);
+        gPdfStandardFonts["TimesNewRomanPSMT"] = SkPdfStandardFontEntry("Times New Roman", false, false);
+        gPdfStandardFonts["Symbol"] = SkPdfStandardFontEntry("Symbol", false, false);
+        gPdfStandardFonts["ZapfDingbats"] = SkPdfStandardFontEntry("ZapfDingbats", false, false);
 
         // TODO(edisonn): these are hacks. Load Post Script font name.
         // see FT_Get_Postscript_Name
         // Font config is not using it, yet.
         //https://bugs.freedesktop.org/show_bug.cgi?id=18095
 
-        gPdfStandardFonts["Arial-Black"] = {"Arial", true, false};
-        gPdfStandardFonts["DejaVuSans"] = {"DejaVu Sans", false, false};
-        gPdfStandardFonts["DejaVuSansMono"] = {"DejaVuSans Mono", false, false};
-        gPdfStandardFonts["DejaVuSansMono-Bold"] = {"DejaVuSans Mono", true, false};
-        gPdfStandardFonts["DejaVuSansMono-Oblique"] = {"DejaVuSans Mono", false, true};
-        gPdfStandardFonts["Georgia-Bold"] = {"Georgia", true, false};
-        gPdfStandardFonts["Georgia-BoldItalic"] = {"Georgia", true, true};
-        gPdfStandardFonts["Georgia-Italic"] = {"Georgia", false, true};
-        gPdfStandardFonts["TrebuchetMS"] = {"Trebuchet MS", false, false};
-        gPdfStandardFonts["TrebuchetMS-Bold"] = {"Trebuchet MS", true, false};
-        gPdfStandardFonts["Verdana-Bold"] = {"Verdana", true, false};
-        gPdfStandardFonts["WenQuanYiMicroHei"] = {"WenQuanYi Micro Hei", false, false};
+        gPdfStandardFonts["Arial-Black"] = SkPdfStandardFontEntry("Arial", true, false);
+        gPdfStandardFonts["DejaVuSans"] = SkPdfStandardFontEntry("DejaVu Sans", false, false);
+        gPdfStandardFonts["DejaVuSansMono"] = SkPdfStandardFontEntry("DejaVuSans Mono", false, false);
+        gPdfStandardFonts["DejaVuSansMono-Bold"] = SkPdfStandardFontEntry("DejaVuSans Mono", true, false);
+        gPdfStandardFonts["DejaVuSansMono-Oblique"] = SkPdfStandardFontEntry("DejaVuSans Mono", false, true);
+        gPdfStandardFonts["Georgia-Bold"] = SkPdfStandardFontEntry("Georgia", true, false);
+        gPdfStandardFonts["Georgia-BoldItalic"] = SkPdfStandardFontEntry("Georgia", true, true);
+        gPdfStandardFonts["Georgia-Italic"] = SkPdfStandardFontEntry("Georgia", false, true);
+        gPdfStandardFonts["TrebuchetMS"] = SkPdfStandardFontEntry("Trebuchet MS", false, false);
+        gPdfStandardFonts["TrebuchetMS-Bold"] = SkPdfStandardFontEntry("Trebuchet MS", true, false);
+        gPdfStandardFonts["Verdana-Bold"] = SkPdfStandardFontEntry("Verdana", true, false);
+        gPdfStandardFonts["WenQuanYiMicroHei"] = SkPdfStandardFontEntry("WenQuanYi Micro Hei", false, false);
 
         // TODO(edisonn): list all phonts available, builf post script name as in pdf spec
         /*
diff --git a/experimental/PdfViewer/SkPdfFont.h b/experimental/PdfViewer/SkPdfFont.h
index 324f0f6..071b324 100644
--- a/experimental/PdfViewer/SkPdfFont.h
+++ b/experimental/PdfViewer/SkPdfFont.h
@@ -20,11 +20,20 @@
 class SkPdfMultiMasterFont;
 class SkPdfFont;
 
-
 struct SkPdfStandardFontEntry {
+    // We don't own this pointer!
     const char* fName;
     bool fIsBold;
     bool fIsItalic;
+    SkPdfStandardFontEntry()
+    : fName(NULL),
+      fIsBold(false),
+      fIsItalic(false) {}
+
+    SkPdfStandardFontEntry(const char* name, bool bold, bool italic)
+        : fName(name),
+          fIsBold(bold),
+          fIsItalic(italic) {}
 };
 
 std::map<std::string, SkPdfStandardFontEntry>& getStandardFonts();
diff --git a/experimental/PdfViewer/SkPdfParser.cpp b/experimental/PdfViewer/SkPdfParser.cpp
index ea0f625..e1f549e 100644
--- a/experimental/PdfViewer/SkPdfParser.cpp
+++ b/experimental/PdfViewer/SkPdfParser.cpp
@@ -1905,12 +1905,12 @@
 // references automatically.
 
 bool SkPdfViewer::load(const SkString inputFileName, SkPicture* out) {
-    std::cout << "Init: " << inputFileName.c_str() << std::endl;
+    std::cout << "PDF Loaded: " << inputFileName.c_str() << std::endl;
 
     SkNativeParsedPDF* doc = new SkNativeParsedPDF(inputFileName.c_str());
     if (!doc->pages())
     {
-        std::cout << "ERROR: Empty Document" << inputFileName.c_str() << std::endl;
+        std::cout << "ERROR: Empty PDF Document" << inputFileName.c_str() << std::endl;
         return false;
     } else {
 
diff --git a/experimental/PdfViewer/pdf_viewer_main.cpp b/experimental/PdfViewer/pdf_viewer_main.cpp
index 20a6cae..ac1aef0 100644
--- a/experimental/PdfViewer/pdf_viewer_main.cpp
+++ b/experimental/PdfViewer/pdf_viewer_main.cpp
@@ -48,6 +48,7 @@
  * @returns false if the file did not has the expected extension.
  *  if false is returned, contents of path are undefined.
  */
+/*
 static bool replace_filename_extension(SkString* path,
                                        const char old_extension[],
                                        const char new_extension[]) {
@@ -62,7 +63,7 @@
     }
     return false;
 }
-
+*/
 /** Builds the output filename. path = dir/name, and it replaces expected
  * .skp extension with .pdf extention.
  * @param path Output filename.
@@ -70,6 +71,8 @@
  * @returns false if the file did not has the expected extension.
  *  if false is returned, contents of path are undefined.
  */
+
+/*
 static bool make_output_filepath(SkString* path, const SkString& dir,
                                  const SkString& name) {
     sk_tools::make_filepath(path, dir, name);
@@ -77,12 +80,13 @@
                                       PDF_FILE_EXTENSION,
                                       PNG_FILE_EXTENSION);
 }
-
+*/
 /** Write the output of pdf renderer to a file.
  * @param outputDir Output dir.
  * @param inputFilename The skp file that was read.
  * @param renderer The object responsible to write the pdf file.
  */
+/*
 static bool write_output(const SkString& outputDir,
                          const SkString& inputFilename,
                          const SkPdfViewer& renderer) {
@@ -106,7 +110,7 @@
 
     return true;
 }
-
+*/
 /** Reads an skp file, renders it to pdf and writes the output to a pdf file
  * @param inputPath The skp file to be read.
  * @param outputDir Output dir.
diff --git a/experimental/PdfViewer/pdfparser/native/SkPdfNativeTokenizer.cpp b/experimental/PdfViewer/pdfparser/native/SkPdfNativeTokenizer.cpp
index dd72acd..4e2f558 100644
--- a/experimental/PdfViewer/pdfparser/native/SkPdfNativeTokenizer.cpp
+++ b/experimental/PdfViewer/pdfparser/native/SkPdfNativeTokenizer.cpp
@@ -700,7 +700,9 @@
     // free the unparsed stream, we don't need it.
     // the parsed one is locked as it contains the strings and keywords referenced in objects
     if (fUncompressedStream) {
-        realloc(fUncompressedStreamStart, fUncompressedStream - fUncompressedStreamStart);
+        void* dummy = realloc(fUncompressedStreamStart, fUncompressedStream - fUncompressedStreamStart);
+        SkASSERT(dummy == fUncompressedStreamStart);
+        fUncompressedStreamStart = (unsigned char*)dummy;  // suporess compiler warning
     } else {
         SkASSERT(false);
     }