few steps in the direction of to encapsulating podofo, so the client is not aware podofo is used.

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

git-svn-id: http://skia.googlecode.com/svn/trunk@9643 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/experimental/PdfViewer/generate_code.py b/experimental/PdfViewer/generate_code.py
index 5d0558b..00c9b45 100644
--- a/experimental/PdfViewer/generate_code.py
+++ b/experimental/PdfViewer/generate_code.py
@@ -341,11 +341,12 @@
         print('  const PdfObject* fPodofoObj;')
         print
         print('public:')
-        print('  SkPdf' + cls.fName + '(const PdfMemDocument* podofoDoc, const PdfObject* podofoObj) : fPodofoDoc(podofoDoc), fPodofoObj(podofoObj) {}')
+        print('  SkPdf' + cls.fName + '(const PdfMemDocument* podofoDoc = NULL, const PdfObject* podofoObj = NULL) : fPodofoDoc(podofoDoc), fPodofoObj(podofoObj) {}')
+        print('  const PdfMemDocument* doc() const { return fPodofoDoc;}')
         print('  const PdfObject* podofo() const { return fPodofoObj;}')
       else:
         print('public:')
-        print('  SkPdf' + cls.fName + '(const PdfMemDocument* podofoDoc, const PdfObject* podofoObj) : SkPdf' + cls.fBase + '(podofoDoc, podofoObj) {}')
+        print('  SkPdf' + cls.fName + '(const PdfMemDocument* podofoDoc = NULL, const PdfObject* podofoObj = NULL) : SkPdf' + cls.fBase + '(podofoDoc, podofoObj) {}')
         print
       
       #check required fieds, also, there should be an internal_valid() manually wrote for complex
@@ -354,6 +355,9 @@
       print('  virtual bool valid() const {return true;}')
       print
       
+      print('  SkPdf' + cls.fName + '& operator=(const SkPdf' + cls.fName + '& from) {this->fPodofoDoc = from.fPodofoDoc; this->fPodofoObj = from.fPodofoObj; return *this;}')
+      print
+      
       for field in cls.fFields:
         prop = field.fProp
         if prop.fCppName != '':
@@ -392,12 +396,18 @@
     for name in self.fClassesNamesInOrder:
       cls = self.fClasses[name]
       
-      print('  static bool map' + name + '(const PdfMemDocument& podofoDoc, const PdfObject& podofoObj, SkPdfObject** out) {')
+
+      print('  static bool map(const SkPdfObject& in, SkPdf' + name + '** out) {')
+      print('    return map(*in.doc(), *in.podofo(), out);')
+      print('  }') 
+      print
+
+      print('  static bool map(const PdfMemDocument& podofoDoc, const PdfObject& podofoObj, SkPdf' + name + '** out) {')
       print('    if (!isA' + name + '(podofoDoc, podofoObj)) return false;')
       print
       
       for sub in cls.fEnumSubclasses:
-        print('    if (map' + enumToCls[sub].fName + '(podofoDoc, podofoObj, out)) return true;')
+        print('    if (map(podofoDoc, podofoObj, (SkPdf' + enumToCls[sub].fName + '**)out)) return true;')
 
       print
       
@@ -424,11 +434,7 @@
             print('    if (' + prop.fCppName + ' != ' + prop.fMustBe.toCpp() + ') return false;')
             print
       
-        # hack, we only care about dictionaries now, so ret tru only if there is a match
-        if cntMust != 0 or len(cls.fEnumSubclasses) > 0:
-          print('    return true;')
-        else:
-          print('    return false;')
+        print('    return true;')
               
       print('  }') 
       print