| OLD | NEW |
| 1 | 1 |
| 2 | 2 |
| 3 import sys | 3 import sys |
| 4 | 4 |
| 5 import datatypes | 5 import datatypes |
| 6 from autogen.pdfspec_autogen import * | 6 from autogen.pdfspec_autogen import * |
| 7 | 7 |
| 8 knowTypes = { | 8 knowTypes = { |
| 9 '(any)': ['SkPdfObject*', 'ObjectFromDictionary', datatypes.CppNull(), 'true'], | 9 '(any)': ['SkPdfObject*', 'SkPdfObjectFromDictionary', datatypes.CppNull(), 'tru
e', 'use a mapper'], |
| 10 '(undefined)': ['SkPdfObject*', 'ObjectFromDictionary', datatypes.CppNull(), 'tr
ue'], | 10 '(undefined)': ['SkPdfObject*', 'SkPdfObjectFromDictionary', datatypes.CppNull()
, 'true', 'use a mapper'], |
| 11 '(various)': ['SkPdfObject*', 'ObjectFromDictionary', datatypes.CppNull(), 'true
'], | 11 '(various)': ['SkPdfObject*', 'SkPdfObjectFromDictionary', datatypes.CppNull(),
'true', 'use a mapper'], |
| 12 'array': ['SkPdfArray*', 'ArrayFromDictionary', datatypes.CppNull(), 'ret->podof
o()->GetDataType() == ePdfDataType_Array'], | 12 'array': ['SkPdfArray*', 'ArrayFromDictionary', datatypes.CppNull(), 'ret->podof
o()->GetDataType() == PoDoFo::ePdfDataType_Array'], |
| 13 'boolean': ['bool', 'BoolFromDictionary', datatypes.PdfBoolean('false'), 'ret->p
odofo()->GetDataType() == ePdfDataType_Bool'], | 13 'boolean': ['bool', 'BoolFromDictionary', datatypes.PdfBoolean('false'), 'ret->p
odofo()->GetDataType() == PoDoFo::ePdfDataType_Bool'], |
| 14 'date': ['SkPdfDate', 'DateFromDictionary', datatypes.PdfDateNever(), 'ret->podo
fo()->GetDataType() == ePdfDataType_Array'], | 14 'date': ['SkPdfDate', 'DateFromDictionary', datatypes.PdfDateNever(), 'ret->podo
fo()->GetDataType() == PoDoFo::ePdfDataType_Array'], |
| 15 'dictionary': ['SkPdfDictionary*', 'DictionaryFromDictionary', datatypes.CppNull
(), 'ret->podofo()->GetDataType() == ePdfDataType_Dictionary'], | 15 'dictionary': ['SkPdfDictionary*', 'SkPdfDictionaryFromDictionary', datatypes.Cp
pNull(), 'ret->podofo()->GetDataType() == PoDoFo::ePdfDataType_Dictionary', 'use
a mapper'], |
| 16 'function': ['SkPdfFunction', 'FunctionFromDictionary', datatypes.PdfFunctionNon
e(), 'ret->podofo()->GetDataType() == ePdfDataType_Reference'], | 16 'function': ['SkPdfFunction', 'FunctionFromDictionary', datatypes.PdfFunctionNon
e(), 'ret->podofo()->GetDataType() == PoDoFo::ePdfDataType_Reference'], |
| 17 'integer': ['long', 'LongFromDictionary', datatypes.PdfInteger(0), 'ret->podofo(
)->GetDataType() == ePdfDataType_Number'], | 17 'integer': ['long', 'LongFromDictionary', datatypes.PdfInteger(0), 'ret->podofo(
)->GetDataType() == PoDoFo::ePdfDataType_Number'], |
| 18 'file_specification': ['SkPdfFileSpec', 'FileSpecFromDictionary', datatypes.File
SpecNone(), 'ret->podofo()->GetDataType() == ePdfDataType_Reference'], | 18 'file_specification': ['SkPdfFileSpec', 'FileSpecFromDictionary', datatypes.File
SpecNone(), 'ret->podofo()->GetDataType() == PoDoFo::ePdfDataType_Reference'], |
| 19 'name': ['std::string', 'NameFromDictionary', datatypes.PdfString('""'), 'ret->p
odofo()->GetDataType() == ePdfDataType_Name'], | 19 'name': ['std::string', 'NameFromDictionary', datatypes.PdfString('""'), 'ret->p
odofo()->GetDataType() == PoDoFo::ePdfDataType_Name'], |
| 20 'tree': ['SkPdfTree*', 'TreeFromDictionary', datatypes.CppNull(), 'ret->podofo()
->GetDataType() == ePdfDataType_Reference'], | 20 'tree': ['SkPdfTree*', 'TreeFromDictionary', datatypes.CppNull(), 'ret->podofo()
->GetDataType() == PoDoFo::ePdfDataType_Reference'], |
| 21 'number': ['double', 'DoubleFromDictionary', datatypes.PdfNumber(0), 'ret->podof
o()->GetDataType() == ePdfDataType_Real || ret->podofo()->GetDataType() == ePdfD
ataType_Number'], | 21 'number': ['double', 'DoubleFromDictionary', datatypes.PdfNumber(0), 'ret->podof
o()->GetDataType() == PoDoFo::ePdfDataType_Real || ret->podofo()->GetDataType()
== PoDoFo::ePdfDataType_Number'], |
| 22 'rectangle': ['SkRect*', 'SkRectFromDictionary', datatypes.CppNull(), 'ret->podo
fo()->GetDataType() == ePdfDataType_Array && ret->podofo()->GetArray().GetLength
() == 4'], | 22 'rectangle': ['SkRect*', 'SkRectFromDictionary', datatypes.CppNull(), 'ret->podo
fo()->GetDataType() == PoDoFo::ePdfDataType_Array && ret->podofo()->GetArray().G
etLength() == 4'], |
| 23 'stream': ['SkPdfStream*', 'StreamFromDictionary', datatypes.CppNull(), 'ret->p
odofo()->HasStream()'], | 23 'stream': ['SkPdfStream*', 'StreamFromDictionary', datatypes.CppNull(), 'ret->p
odofo()->HasStream()'], |
| 24 'string': ['std::string', 'StringFromDictionary', datatypes.PdfString('""'), 're
t->podofo()->GetDataType() == ePdfDataType_String || ret->podofo()->GetDataType(
) == ePdfDataType_HexString'], | 24 'string': ['std::string', 'StringFromDictionary', datatypes.PdfString('""'), 're
t->podofo()->GetDataType() == PoDoFo::ePdfDataType_String || ret->podofo()->GetD
ataType() == PoDoFo::ePdfDataType_HexString'], |
| 25 'text': ['std::string', 'StringFromDictionary', datatypes.PdfString('""'), 'ret-
>podofo()->GetDataType() == ePdfDataType_String || ret->podofo()->GetDataType()
== ePdfDataType_HexString'], | 25 'text': ['std::string', 'StringFromDictionary', datatypes.PdfString('""'), 'ret-
>podofo()->GetDataType() == PoDoFo::ePdfDataType_String || ret->podofo()->GetDat
aType() == PoDoFo::ePdfDataType_HexString'], |
| 26 'text string': ['std::string', 'StringFromDictionary', datatypes.PdfString('""')
, 'ret->podofo()->GetDataType() == ePdfDataType_String || ret->podofo()->GetData
Type() == ePdfDataType_HexString'], | 26 'text string': ['std::string', 'StringFromDictionary', datatypes.PdfString('""')
, 'ret->podofo()->GetDataType() == PoDoFo::ePdfDataType_String || ret->podofo()-
>GetDataType() == PoDoFo::ePdfDataType_HexString'], |
| 27 'matrix': ['SkMatrix*', 'SkMatrixFromDictionary', datatypes.CppNull(), 'ret->pod
ofo()->GetDataType() == ePdfDataType_Array && ret->podofo()->GetArray().GetLengt
h() == 4'], | 27 'matrix': ['SkMatrix*', 'SkMatrixFromDictionary', datatypes.CppNull(), 'ret->pod
ofo()->GetDataType() == PoDoFo::ePdfDataType_Array && ret->podofo()->GetArray().
GetLength() == 4'], |
| 28 } | 28 } |
| 29 | 29 |
| 30 | 30 |
| 31 class PdfField: | 31 class PdfField: |
| 32 def __init__(self, parent, name, abr): | 32 def __init__(self, parent, name, abr): |
| 33 self.fParent = parent | 33 self.fParent = parent |
| 34 self.fName = name | 34 self.fName = name |
| 35 self.fAbr = abr | 35 self.fAbr = abr |
| 36 | 36 |
| 37 self.fDefault = '' | 37 self.fDefault = '' |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 94 self.fProp = PdfField(self, name, abr) | 94 self.fProp = PdfField(self, name, abr) |
| 95 return self.fProp | 95 return self.fProp |
| 96 | 96 |
| 97 def done(self): | 97 def done(self): |
| 98 return self.fParent | 98 return self.fParent |
| 99 | 99 |
| 100 class PdfClass: | 100 class PdfClass: |
| 101 def __init__(self, name, base, comment): | 101 def __init__(self, name, base, comment): |
| 102 self.fFields = [] | 102 self.fFields = [] |
| 103 self.fIncludes = [] | 103 self.fIncludes = [] |
| 104 self.fCCPublic = [] | 104 self.fCCPublicPodofo = [] |
| 105 self.fCCPrivate = [] | 105 self.fCCPublicPodofoCpp = [] |
| 106 self.fName = name | 106 self.fName = name |
| 107 self.fBase = base | 107 self.fBase = base |
| 108 self.fComment = comment | 108 self.fComment = comment |
| 109 | 109 |
| 110 self.fEnumSubclasses = [] | 110 self.fEnumSubclasses = [] |
| 111 | 111 |
| 112 self.fEnum = '!UNDEFINED' | 112 self.fEnum = '!UNDEFINED' |
| 113 self.fEnumEnd = '!UNDEFINED' | 113 self.fEnumEnd = '!UNDEFINED' |
| 114 self.fCheck = '' | 114 self.fCheck = '' |
| 115 | 115 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 133 # ; separate props | 133 # ; separate props |
| 134 #inheritable | 134 #inheritable |
| 135 #version | 135 #version |
| 136 #required, if | 136 #required, if |
| 137 #optional, if | 137 #optional, if |
| 138 | 138 |
| 139 def include(self, path): | 139 def include(self, path): |
| 140 self.fIncludes.append(path) | 140 self.fIncludes.append(path) |
| 141 return self | 141 return self |
| 142 | 142 |
| 143 def carbonCopyPublic(self, cc): | 143 def carbonCopyPublicPodofo(self, cc): |
| 144 self.fCCPublic.append(cc) | 144 self.fCCPublicPodofo.append(cc) |
| 145 return self | 145 return self |
| 146 | 146 |
| 147 def carbonCopyPrivate(self, cc): | 147 def carbonCopyPublicPodofoCpp(self, cc): |
| 148 self.fCCPrivate.append(cc) | 148 self.fCCPublicPodofoCpp.append(cc) |
| 149 return self | 149 return self |
| 150 | 150 |
| 151 def done(self): | 151 def done(self): |
| 152 return | 152 return |
| 153 | 153 |
| 154 class PdfClassManager: | 154 class PdfClassManager: |
| 155 def __init__(self): | 155 def __init__(self): |
| 156 self.fClasses = {} | 156 self.fClasses = {} |
| 157 self.fClassesNamesInOrder = [] | 157 self.fClassesNamesInOrder = [] |
| 158 | 158 |
| 159 def addClass(self, name, base='Object', comment=''): | 159 def addClass(self, name, base='Object', comment=''): |
| 160 if name == 'Object': | 160 if name == 'Object': |
| (...skipping 11 matching lines...) Expand all Loading... |
| 172 | 172 |
| 173 cnt = 0 | 173 cnt = 0 |
| 174 for sub in cls.fEnumSubclasses: | 174 for sub in cls.fEnumSubclasses: |
| 175 self.writeEnum(fileEnums, cls.fEnumSubclasses[cnt], enumToCls) | 175 self.writeEnum(fileEnums, cls.fEnumSubclasses[cnt], enumToCls) |
| 176 cnt = cnt + 1 | 176 cnt = cnt + 1 |
| 177 | 177 |
| 178 if cnt != 0: | 178 if cnt != 0: |
| 179 fileEnums.write(' ' + cls.fEnumEnd + ',\n') | 179 fileEnums.write(' ' + cls.fEnumEnd + ',\n') |
| 180 | 180 |
| 181 | 181 |
| 182 def writeAsNull(self, fileClass, cls, enumToCls): | 182 def writeAsNull(self, podofoFileClass, cls, enumToCls): |
| 183 fileClass.write(' virtual SkPdf' + cls.fName +'* as' + cls.fName + '() {ret
urn NULL;}\n') | 183 podofoFileClass.write(' virtual SkPdf' + cls.fName +'* as' + cls.fName + '(
) {return NULL;}\n') |
| 184 fileClass.write(' virtual const SkPdf' + cls.fName +'* as' + cls.fName + '(
) const {return NULL;}\n') | 184 podofoFileClass.write(' virtual const SkPdf' + cls.fName +'* as' + cls.fNa
me + '() const {return NULL;}\n') |
| 185 fileClass.write('\n') | 185 podofoFileClass.write('\n') |
| 186 | 186 |
| 187 cnt = 0 | 187 cnt = 0 |
| 188 for sub in cls.fEnumSubclasses: | 188 for sub in cls.fEnumSubclasses: |
| 189 self.writeAsNull(fileClass, enumToCls[cls.fEnumSubclasses[cnt]], enumToCls
) | 189 self.writeAsNull(podofoFileClass, enumToCls[cls.fEnumSubclasses[cnt]], enu
mToCls) |
| 190 cnt = cnt + 1 | 190 cnt = cnt + 1 |
| 191 | 191 |
| 192 | 192 |
| 193 def writeAsFoo(self, fileClass, cls, enumToCls): | 193 def writeAsFoo(self, podofoFileClass, cls, enumToCls): |
| 194 # TODO(edisonn): add a container, with sections, public, private, default, .
.. | 194 # TODO(edisonn): add a container, with sections, public, private, default, .
.. |
| 195 # the end code will be grouped | 195 # the end code will be grouped |
| 196 | 196 |
| 197 # me | 197 # me |
| 198 fileClass.write('public:\n') | 198 podofoFileClass.write('public:\n') |
| 199 fileClass.write(' virtual SkPdf' + cls.fName +'* as' + cls.fName + '() {ret
urn this;}\n') | 199 |
| 200 fileClass.write(' virtual const SkPdf' + cls.fName +'* as' + cls.fName + '(
) const {return this;}\n') | 200 podofoFileClass.write('public:\n') |
| 201 fileClass.write('\n') | 201 podofoFileClass.write(' SkPdf' + cls.fName +'* as' + cls.fName + '() {retu
rn this;}\n') |
| 202 podofoFileClass.write(' virtual const SkPdf' + cls.fName +'* as' + cls.fNam
e + '() const {return this;}\n') |
| 203 podofoFileClass.write('\n') |
| 202 | 204 |
| 203 if cls.fName == 'Object': | 205 if cls.fName == 'Object': |
| 204 cnt = 0 | 206 cnt = 0 |
| 205 for sub in cls.fEnumSubclasses: | 207 for sub in cls.fEnumSubclasses: |
| 206 self.writeAsNull(fileClass, enumToCls[cls.fEnumSubclasses[cnt]], enumToC
ls) | 208 self.writeAsNull(podofoFileClass, enumToCls[cls.fEnumSubclasses[cnt]], e
numToCls) |
| 207 cnt = cnt + 1 | 209 cnt = cnt + 1 |
| 208 | 210 |
| 209 if cls.fName != 'Object': | 211 if cls.fName != 'Object': |
| 210 fileClass.write('private:\n') | 212 podofoFileClass.write('private:\n') |
| 211 base = self.fClasses[cls.fBase] | 213 base = self.fClasses[cls.fBase] |
| 212 cnt = 0 | 214 cnt = 0 |
| 213 for sub in base.fEnumSubclasses: | 215 for sub in base.fEnumSubclasses: |
| 214 if enumToCls[base.fEnumSubclasses[cnt]].fName != cls.fName: | 216 if enumToCls[base.fEnumSubclasses[cnt]].fName != cls.fName: |
| 215 self.writeAsNull(fileClass, enumToCls[base.fEnumSubclasses[cnt]], enum
ToCls) | 217 self.writeAsNull(podofoFileClass, enumToCls[base.fEnumSubclasses[cnt]]
, enumToCls) |
| 216 cnt = cnt + 1 | 218 cnt = cnt + 1 |
| 217 | 219 |
| 218 | 220 |
| 219 def determineAllMustBe(self, cls, field, enumToCls): | 221 def determineAllMustBe(self, cls, field, enumToCls): |
| 220 mustBe = [] | 222 mustBe = [] |
| 221 for sub in cls.fEnumSubclasses: | 223 for sub in cls.fEnumSubclasses: |
| 222 mustBe = mustBe + self.determineAllMustBe(enumToCls[sub], field, enumToCls
) | 224 mustBe = mustBe + self.determineAllMustBe(enumToCls[sub], field, enumToCls
) |
| 223 | 225 |
| 224 for subField in cls.fFields: | 226 for subField in cls.fFields: |
| 225 if subField.fProp.fName == field.fProp.fName: | 227 if subField.fProp.fName == field.fProp.fName: |
| 226 mustBe = mustBe + subField.fProp.fMustBe | 228 mustBe = mustBe + subField.fProp.fMustBe |
| 227 | 229 |
| 228 # while cls.fBase != '': | 230 # while cls.fBase != '': |
| 229 # cls = self.fClasses[cls.fBase] | 231 # cls = self.fClasses[cls.fBase] |
| 230 # # TODO(edisonn): bad perf | 232 # # TODO(edisonn): bad perf |
| 231 # for subField in cls.fFields: | 233 # for subField in cls.fFields: |
| 232 # if subField.fProp.fName == field.fProp.fName: | 234 # if subField.fProp.fName == field.fProp.fName: |
| 233 # mustBe = mustBe + subField.fProp.fMustBe | 235 # mustBe = mustBe + subField.fProp.fMustBe |
| 234 | 236 |
| 235 return mustBe | 237 return mustBe |
| 236 | 238 |
| 237 def write(self): | 239 def write(self): |
| 238 global fileHeaders | 240 global fileHeadersPodofo |
| 239 global fileHeadersCpp | 241 global fileHeadersPodofoCpp |
| 240 global knowTypes | 242 global knowTypes |
| 241 | 243 |
| 242 # generate enum | 244 # generate enum |
| 243 enumsRoot = [] | 245 enumsRoot = [] |
| 244 | 246 |
| 245 enumToCls = {} | 247 enumToCls = {} |
| 246 | 248 |
| 247 for name in self.fClasses: | 249 for name in self.fClasses: |
| 248 cls = self.fClasses[name] | 250 cls = self.fClasses[name] |
| 249 cls.fEnum = 'k' + name + '_SkPdfObjectType' | 251 cls.fEnum = 'k' + name + '_SkPdfObjectType' |
| 250 cls.fEnumEnd = 'k' + name + '__End_SkPdfObjectType' | 252 cls.fEnumEnd = 'k' + name + '__End_SkPdfObjectType' |
| 251 | 253 |
| 252 fileHeaders.write('#include "SkPdf' + cls.fName + '_autogen.h"\n') | 254 fileHeadersPodofo.write('#include "SkPdf' + cls.fName + '_autogen.h"\n') |
| 253 fileHeadersCpp.write('#include "SkPdf' + cls.fName + '_autogen.cpp"\n') | 255 fileHeadersPodofoCpp.write('#include "SkPdf' + cls.fName + '_autogen.cpp"\
n') |
| 254 | 256 |
| 255 if cls.fBase != '': | 257 if cls.fBase != '': |
| 256 self.fClasses[cls.fBase].fEnumSubclasses.append(cls.fEnum) | 258 self.fClasses[cls.fBase].fEnumSubclasses.append(cls.fEnum) |
| 257 | 259 |
| 258 if cls.fBase == '': | 260 if cls.fBase == '': |
| 259 enumsRoot.append(cls.fEnum) | 261 enumsRoot.append(cls.fEnum) |
| 260 | 262 |
| 261 enumToCls[cls.fEnum] = cls | 263 enumToCls[cls.fEnum] = cls |
| 262 | 264 |
| 263 enumsRoot.sort() | 265 enumsRoot.sort() |
| 264 | 266 |
| 265 | 267 |
| 266 # TODO(edisonn): move each .h in it's own file | 268 # TODO(edisonn): move each .h in it's own file |
| 267 # write imports | 269 # write imports |
| 268 | 270 |
| 269 # write enums | 271 # write enums |
| 270 fileEnums = open('SkPdfEnums_autogen.h', 'w') | 272 fileEnums = open(sys.argv[1] + 'autogen/SkPdfEnums_autogen.h', 'w') |
| 271 fileEnums.write('#ifndef __DEFINED__SkPdfEnums\n') | 273 fileEnums.write('#ifndef __DEFINED__SkPdfEnums\n') |
| 272 fileEnums.write('#define __DEFINED__SkPdfEnums\n') | 274 fileEnums.write('#define __DEFINED__SkPdfEnums\n') |
| 273 fileEnums.write('\n') | 275 fileEnums.write('\n') |
| 274 | 276 |
| 275 fileEnums.write('enum SkPdfObjectType {\n') | 277 fileEnums.write('enum SkPdfObjectType {\n') |
| 276 for enum in enumsRoot: | 278 for enum in enumsRoot: |
| 277 self.writeEnum(fileEnums, enum, enumToCls) | 279 self.writeEnum(fileEnums, enum, enumToCls) |
| 278 fileEnums.write('};\n') | 280 fileEnums.write('};\n') |
| 279 fileEnums.write('\n') | 281 fileEnums.write('\n') |
| 280 | 282 |
| 281 # write forward class declaration | 283 # write forward class declaration |
| 282 for name in self.fClassesNamesInOrder: | 284 for name in self.fClassesNamesInOrder: |
| 283 fileEnums.write('class SkPdf' + name + ';\n') | 285 fileEnums.write('class SkPdf' + name + ';\n') |
| 284 fileEnums.write('\n') | 286 fileEnums.write('\n') |
| 285 | 287 |
| 286 fileEnums.write('#endif // __DEFINED__SkPdfEnums\n') | 288 fileEnums.write('#endif // __DEFINED__SkPdfEnums\n') |
| 287 fileEnums.close() | 289 fileEnums.close() |
| 288 | 290 |
| 289 for name in self.fClassesNamesInOrder: | 291 for name in self.fClassesNamesInOrder: |
| 290 cls = self.fClasses[name] | 292 cls = self.fClasses[name] |
| 291 enum = cls.fEnum | 293 enum = cls.fEnum |
| 292 | 294 |
| 293 fileClass = open('SkPdf' + cls.fName + '_autogen.h', 'w') | 295 podofoFileClass = open(sys.argv[1] + 'podofo/autogen/SkPdf' + cls.fName +
'_autogen.h', 'w') |
| 294 fileClassCpp = open('SkPdf' + cls.fName + '_autogen.cpp', 'w') | 296 podofoFileClassCpp = open(sys.argv[1] + 'podofo/autogen/SkPdf' + cls.fName
+ '_autogen.cpp', 'w') |
| 295 fileClass.write('#ifndef __DEFINED__SkPdf' + cls.fName + '\n') | 297 |
| 296 fileClass.write('#define __DEFINED__SkPdf' + cls.fName + '\n') | 298 podofoFileClass.write('#ifndef __DEFINED__SkPdf' + cls.fName + '\n') |
| 297 fileClass.write('\n') | 299 podofoFileClass.write('#define __DEFINED__SkPdf' + cls.fName + '\n') |
| 298 | 300 podofoFileClass.write('\n') |
| 299 fileClassCpp.write('#include "SkPdf' + cls.fName + '_autogen.h"\n\n') | 301 |
| 300 fileClass.write('#include "SkPdfUtils.h"\n') | 302 podofoFileClassCpp.write('#include "SkPdf' + cls.fName + '_autogen.h"\n\n'
) |
| 301 fileClass.write('#include "SkPdfEnums_autogen.h"\n') | 303 podofoFileClassCpp.write('#include "podofo.h"\n') |
| 302 fileClass.write('#include "SkPdfArray_autogen.h"\n') | 304 podofoFileClassCpp.write('#include "SkPodofoUtils.h"\n') |
| 305 podofoFileClassCpp.write('#include "SkPdfMapper_autogen.h"\n') |
| 306 podofoFileClassCpp.write('\n') |
| 307 |
| 308 |
| 309 if cls.fBase == '': |
| 310 podofoFileClass.write('#include "stddef.h"\n') |
| 311 podofoFileClass.write('#include <string>\n') |
| 312 podofoFileClass.write('#include "SkPdfEnums_autogen.h"\n') |
| 313 podofoFileClass.write('#include "SkPdfNYI.h"\n') |
| 314 podofoFileClass.write('#include "SkPodofoUtils.h"\n') |
| 315 |
| 303 if cls.fBase != '': | 316 if cls.fBase != '': |
| 304 fileClass.write('#include "SkPdf' + cls.fBase + '_autogen.h"\n') | 317 podofoFileClass.write('#include "SkPdf' + cls.fBase + '_autogen.h"\n') |
| 305 fileClass.write('\n') | 318 |
| 319 if cls.fBase == '': |
| 320 podofoFileClass.write('#include "SkPodofoParsedPDF.h"\n') |
| 321 |
| 322 podofoFileClass.write('\n') |
| 323 |
| 324 if cls.fBase == '': |
| 325 podofoFileClass.write('namespace PoDoFo {\n') |
| 326 podofoFileClass.write('class PdfMemDocument;\n') |
| 327 podofoFileClass.write('class PdfObject;\n') |
| 328 podofoFileClass.write('}\n') |
| 306 | 329 |
| 307 if cls.fComment != '': | 330 if cls.fComment != '': |
| 308 fileClass.write('// ' + cls.fComment + '\n') | 331 podofoFileClass.write('// ' + cls.fComment + '\n') |
| 309 | 332 |
| 310 if cls.fBase == '': | 333 if cls.fBase == '': |
| 311 fileClass.write('class SkPdf' + cls.fName + ' {\n') | 334 podofoFileClass.write('class SkPdf' + cls.fName + ' {\n') |
| 312 else: | 335 else: |
| 313 fileClass.write('class SkPdf' + cls.fName + ' : public SkPdf' + cls.fBas
e + ' {\n') | 336 podofoFileClass.write('class SkPdf' + cls.fName + ' : public SkPdf' + cl
s.fBase + ' {\n') |
| 314 | 337 |
| 315 fileClass.write('public:\n') | 338 podofoFileClass.write('public:\n') |
| 316 fileClass.write(' virtual SkPdfObjectType getType() const { return ' + cl
s.fEnum + ';}\n') | 339 podofoFileClass.write(' virtual SkPdfObjectType getType() const { return
' + cls.fEnum + ';}\n') |
| 317 if len(cls.fEnumSubclasses) == 0: | 340 if len(cls.fEnumSubclasses) == 0: |
| 318 fileClass.write(' virtual SkPdfObjectType getTypeEnd() const { return (
SkPdfObjectType)(' + cls.fEnum + ' + 1);}\n') | 341 podofoFileClass.write(' virtual SkPdfObjectType getTypeEnd() const { re
turn (SkPdfObjectType)(' + cls.fEnum + ' + 1);}\n') |
| 319 else: | 342 else: |
| 320 fileClass.write(' virtual SkPdfObjectType getTypeEnd() const { return '
+ cls.fEnumEnd + ';}\n') | 343 podofoFileClass.write(' virtual SkPdfObjectType getTypeEnd() const { re
turn ' + cls.fEnumEnd + ';}\n') |
| 321 | 344 |
| 322 self.writeAsFoo(fileClass, cls, enumToCls) | 345 self.writeAsFoo(podofoFileClass, cls, enumToCls) |
| 323 | 346 |
| 324 fileClass.write('public:\n') | 347 podofoFileClass.write('public:\n') |
| 325 for cc in cls.fCCPublic: | 348 |
| 326 fileClass.write(' ' + cc + '\n') | 349 for cc in cls.fCCPublicPodofo: |
| 327 | 350 podofoFileClass.write(' ' + cc + '\n') |
| 328 fileClass.write('private:\n') | 351 |
| 329 for cc in cls.fCCPrivate: | 352 for cc in cls.fCCPublicPodofoCpp: |
| 330 fileClass.write(' ' + cc + '\n') | 353 podofoFileClassCpp.write(cc + '\n\n') |
| 331 | 354 |
| 332 if cls.fBase == '': | 355 |
| 333 fileClass.write('protected:\n') | 356 if cls.fBase == '': |
| 334 fileClass.write(' const PdfMemDocument* fPodofoDoc;\n') | 357 podofoFileClass.write('protected:\n') |
| 335 fileClass.write(' const PdfObject* fPodofoObj;\n') | 358 podofoFileClass.write(' const PoDoFo::PdfMemDocument* fPodofoDoc;\n') |
| 336 fileClass.write('\n') | 359 podofoFileClass.write(' const SkPodofoParsedPDF* fParsedDoc;\n') |
| 337 fileClass.write('public:\n') | 360 podofoFileClass.write(' const PoDoFo::PdfObject* fPodofoObj;\n') |
| 338 fileClass.write(' SkPdf' + cls.fName + '(const PdfMemDocument* podofoDo
c = NULL, const PdfObject* podofoObj = NULL) : fPodofoDoc(podofoDoc), fPodofoObj
(podofoObj) {}\n') | 361 podofoFileClass.write('\n') |
| 339 fileClass.write(' SkPdf' + cls.fName + '(const SkPdf' + cls.fName + '&
from) : fPodofoDoc(from.fPodofoDoc), fPodofoObj(from.fPodofoObj) {}\n') | 362 |
| 340 fileClass.write('\n') | 363 podofoFileClass.write('public:\n') |
| 341 fileClass.write(' const PdfMemDocument* doc() const { return fPodofoDoc
;}\n') | 364 |
| 342 fileClass.write(' const PdfObject* podofo() const { return fPodofoObj;}
\n') | 365 podofoFileClass.write(' SkPdf' + cls.fName + '(const SkPodofoParsedPDF*
doc = NULL, const PoDoFo::PdfObject* podofoObj = NULL) : fPodofoDoc(doc->podofo
()), fParsedDoc(doc), fPodofoObj(podofoObj) {}\n') |
| 343 else: | 366 podofoFileClass.write('\n') |
| 344 fileClass.write('public:\n') | 367 podofoFileClass.write(' const SkPodofoParsedPDF* doc() const { return f
ParsedDoc;}\n') |
| 345 fileClass.write(' SkPdf' + cls.fName + '(const PdfMemDocument* podofoDo
c = NULL, const PdfObject* podofoObj = NULL) : SkPdf' + cls.fBase + '(podofoDoc,
podofoObj) {}\n') | 368 podofoFileClass.write(' const void* data() const {return fPodofoObj;}\n
') |
| 346 fileClass.write('\n') | 369 podofoFileClass.write(' const PoDoFo::PdfObject* podofo() const {return
fPodofoObj;}\n') |
| 347 fileClass.write(' SkPdf' + cls.fName + '(const SkPdf' + cls.fName + '&
from) : SkPdf' + cls.fBase + '(from.fPodofoDoc, from.fPodofoObj) {}\n') | 370 else: |
| 348 fileClass.write('\n') | 371 podofoFileClass.write('public:\n') |
| 349 | 372 podofoFileClass.write(' SkPdf' + cls.fName + '(const SkPodofoParsedPDF*
doc = NULL, const PoDoFo::PdfObject* podofoObj = NULL) : SkPdf' + cls.fBase + '
(doc, podofoObj) {}\n') |
| 350 | 373 podofoFileClass.write('\n') |
| 374 |
| 375 |
| 376 # TODO(edisonn): add is valid ? |
| 351 #check required fieds, also, there should be an internal_valid() manually
wrote for complex | 377 #check required fieds, also, there should be an internal_valid() manually
wrote for complex |
| 352 # situations | 378 # situations |
| 353 # right now valid return true | 379 # right now valid return true |
| 354 fileClass.write(' virtual bool valid() const {return true;}\n') | 380 #podofoFileClass.write(' virtual bool valid() const {return true;}\n') |
| 355 fileClass.write('\n') | 381 #podofoFileClass.write('\n') |
| 356 | |
| 357 fileClass.write(' SkPdf' + cls.fName + '& operator=(const SkPdf' + cls.fN
ame + '& from) {this->fPodofoDoc = from.fPodofoDoc; this->fPodofoObj = from.fPod
ofoObj; return *this;}\n') | |
| 358 fileClass.write('\n') | |
| 359 | 382 |
| 360 for field in cls.fFields: | 383 for field in cls.fFields: |
| 361 prop = field.fProp | 384 prop = field.fProp |
| 362 if prop.fCppName != '': | 385 if prop.fCppName != '': |
| 363 | 386 |
| 364 lines = prop.fComment.split('\n') | 387 lines = prop.fComment.split('\n') |
| 365 if prop.fComment != '' and len(lines) > 0: | 388 if prop.fComment != '' and len(lines) > 0: |
| 366 fileClass.write('/** ' + lines[0] + '\n') | 389 podofoFileClass.write('/** ' + lines[0] + '\n') |
| 367 for line in lines[1:]: | 390 for line in lines[1:]: |
| 368 fileClass.write(' * ' + line + '\n') | 391 podofoFileClass.write(' * ' + line + '\n') |
| 369 fileClass.write('**/\n') | 392 podofoFileClass.write('**/\n') |
| 370 | 393 |
| 371 if prop.fCppName[0] == '[': | 394 if prop.fCppName[0] == '[': |
| 372 fileClass.write('/*\n') # comment code of the atributes that can ha
ve any name | 395 podofoFileClass.write('/*\n') # comment code of the atributes that
can have any name |
| 373 fileClassCpp.write('/*\n') # comment code of the atributes that can
have any name | 396 podofoFileClassCpp.write('/*\n') # comment code of the atributes th
at can have any name |
| 374 | 397 |
| 375 # TODO(edisonn): has_foo(); | |
| 376 fileClass.write(' bool has_' + prop.fCppName + '() const {\n') | |
| 377 fileClass.write(' return (ObjectFromDictionary(fPodofoDoc, fPodofoO
bj->GetDictionary(), \"' + prop.fName + '\", \"' + prop.fAbr + '\", NULL));\n') | |
| 378 fileClass.write(' }\n') | |
| 379 fileClass.write('\n') | |
| 380 | 398 |
| 381 if len(prop.fTypes.split()) == 1: | 399 if len(prop.fTypes.split()) == 1: |
| 382 t = prop.fTypes.strip() | 400 t = prop.fTypes.strip() |
| 383 fileClass.write(' ' + knowTypes[t][0] + ' ' + prop.fCppName + '() c
onst;\n') | 401 |
| 384 fileClassCpp.write('' + knowTypes[t][0] + ' SkPdf' + cls.fName + '::
' + prop.fCppName + '() const {\n') | 402 podofoFileClass.write(' ' + knowTypes[t][0] + ' ' + prop.fCppName +
'() const;\n') |
| 385 fileClassCpp.write(' ' + knowTypes[t][0] + ' ret;\n') | 403 podofoFileClassCpp.write('' + knowTypes[t][0] + ' SkPdf' + cls.fName
+ '::' + prop.fCppName + '() const {\n') |
| 386 fileClassCpp.write(' if (' + knowTypes[t][1] + '(fPodofoDoc, fPodof
oObj->GetDictionary(), \"' + prop.fName + '\", \"' + prop.fAbr + '\", &ret)) ret
urn ret;\n') | 404 podofoFileClassCpp.write(' ' + knowTypes[t][0] + ' ret;\n') |
| 405 |
| 406 #hack, find out if it is dict, they have an extra entry in the array |
| 407 if len(knowTypes[t]) == 5: |
| 408 podofoFileClassCpp.write(' if (fParsedDoc->mapper()->' + knowType
s[t][1] + '(podofo()->GetDictionary(), \"' + prop.fName + '\", \"' + prop.fAbr +
'\", &ret)) return ret;\n') |
| 409 else: |
| 410 podofoFileClassCpp.write(' if (' + knowTypes[t][1] + '(fParsedDoc
, podofo()->GetDictionary(), \"' + prop.fName + '\", \"' + prop.fAbr + '\", &ret
)) return ret;\n') |
| 411 |
| 387 if field.fRequired == False and prop.fDefault != '': | 412 if field.fRequired == False and prop.fDefault != '': |
| 388 fileClassCpp.write(' return ' + prop.fDefault.toCpp() + ';\n'); | 413 podofoFileClassCpp.write(' return ' + prop.fDefault.toCpp() + ';\
n'); |
| 389 else: | 414 else: |
| 390 fileClassCpp.write(' // TODO(edisonn): warn about missing require
d field, assert for known good pdfs\n') | 415 podofoFileClassCpp.write(' // TODO(edisonn): warn about missing r
equired field, assert for known good pdfs\n') |
| 391 fileClassCpp.write(' return ' + knowTypes[t][2].toCpp() + ';\n'); | 416 podofoFileClassCpp.write(' return ' + knowTypes[t][2].toCpp() + '
;\n'); |
| 392 fileClassCpp.write('}\n') | 417 podofoFileClassCpp.write('}\n') |
| 393 fileClassCpp.write('\n') | 418 podofoFileClassCpp.write('\n') |
| 394 else: | 419 else: |
| 395 for type in prop.fTypes.split(): | 420 for type in prop.fTypes.split(): |
| 396 t = type.strip() | 421 t = type.strip() |
| 397 fileClass.write(' bool is' + prop.fCppName + 'A' + t.title() + '(
) const {\n') | 422 |
| 398 fileClass.write(' SkPdfObject* ret = NULL;\n') | 423 podofoFileClass.write(' bool is' + prop.fCppName + 'A' + t.title(
) + '() const;\n') |
| 399 fileClass.write(' if (!ObjectFromDictionary(fPodofoDoc, fPodofo
Obj->GetDictionary(), \"' + prop.fName + '\", \"' + prop.fAbr + '\", &ret)) retu
rn false;\n') | 424 |
| 400 fileClass.write(' return ' + knowTypes[t][3] + ';\n') | 425 podofoFileClassCpp.write('bool SkPdf' + cls.fName + '::is' + prop.
fCppName + 'A' + t.title() + '() const {\n') |
| 401 fileClass.write(' }\n') | 426 podofoFileClassCpp.write(' SkPdfObject* ret = NULL;\n') |
| 402 fileClass.write('\n') | 427 podofoFileClassCpp.write(' if (!fParsedDoc->mapper()->SkPdfObject
FromDictionary(podofo()->GetDictionary(), \"' + prop.fName + '\", \"' + prop.fAb
r + '\", &ret)) return false;\n') |
| 403 | 428 podofoFileClassCpp.write(' return ' + knowTypes[t][3] + ';\n') |
| 404 fileClass.write(' ' + knowTypes[t][0] + ' get' + prop.fCppName +
'As' + t.title() + '() const;\n') | 429 podofoFileClassCpp.write('}\n') |
| 405 fileClassCpp.write('' + knowTypes[t][0] + ' SkPdf' + cls.fName + '
::get' + prop.fCppName + 'As' + t.title() + '() const {\n') | 430 podofoFileClassCpp.write('\n') |
| 406 fileClassCpp.write(' ' + knowTypes[t][0] + ' ret = ' + knowTypes[
t][2].toCpp() + ';\n') | 431 |
| 407 fileClassCpp.write(' if (' + knowTypes[t][1] + '(fPodofoDoc, fPod
ofoObj->GetDictionary(), \"' + prop.fName + '\", \"' + prop.fAbr + '\", &ret)) r
eturn ret;\n') | 432 podofoFileClass.write(' ' + knowTypes[t][0] + ' get' + prop.fCppN
ame + 'As' + t.title() + '() const;\n') |
| 408 fileClassCpp.write(' // TODO(edisonn): warn about missing require
d field, assert for known good pdfs\n') | 433 podofoFileClassCpp.write('' + knowTypes[t][0] + ' SkPdf' + cls.fNa
me + '::get' + prop.fCppName + 'As' + t.title() + '() const {\n') |
| 409 fileClassCpp.write(' return ' + knowTypes[t][2].toCpp() + ';\n') | 434 podofoFileClassCpp.write(' ' + knowTypes[t][0] + ' ret = ' + know
Types[t][2].toCpp() + ';\n') |
| 410 fileClassCpp.write('}\n') | 435 |
| 411 fileClassCpp.write('\n') | 436 # hack |
| 437 if len(knowTypes[t]) == 5: |
| 438 podofoFileClassCpp.write(' if (fParsedDoc->mapper()->' + knowTy
pes[t][1] + '(podofo()->GetDictionary(), \"' + prop.fName + '\", \"' + prop.fAbr
+ '\", &ret)) return ret;\n') |
| 439 else: |
| 440 podofoFileClassCpp.write(' if (' + knowTypes[t][1] + '(fParsedD
oc, podofo()->GetDictionary(), \"' + prop.fName + '\", \"' + prop.fAbr + '\", &r
et)) return ret;\n') |
| 441 |
| 442 podofoFileClassCpp.write(' // TODO(edisonn): warn about missing r
equired field, assert for known good pdfs\n') |
| 443 podofoFileClassCpp.write(' return ' + knowTypes[t][2].toCpp() + '
;\n') |
| 444 podofoFileClassCpp.write('}\n') |
| 445 podofoFileClassCpp.write('\n') |
| 412 | 446 |
| 447 podofoFileClass.write(' bool has_' + prop.fCppName + '() const;\n') |
| 448 podofoFileClassCpp.write('bool SkPdf' + cls.fName + '::has_' + prop.fC
ppName + '() const {\n') |
| 449 podofoFileClassCpp.write(' return (ObjectFromDictionary(fParsedDoc, p
odofo()->GetDictionary(), \"' + prop.fName + '\", \"' + prop.fAbr + '\", NULL));
\n') |
| 450 podofoFileClassCpp.write('}\n') |
| 451 podofoFileClassCpp.write('\n') |
| 413 | 452 |
| 414 if prop.fCppName[0] == '[': | 453 if prop.fCppName[0] == '[': |
| 415 fileClass.write('*/\n') # comment code of the atributes that can ha
ve any name | 454 podofoFileClass.write('*/\n') # comment code of the atributes that
can have any name |
| 416 fileClassCpp.write('*/\n') # comment code of the atributes that can
have any name | 455 podofoFileClassCpp.write('*/\n') # comment code of the atributes th
at can have any name |
| 417 | 456 |
| 418 | 457 |
| 419 fileClass.write('};\n') | 458 podofoFileClass.write('};\n') |
| 420 fileClass.write('\n') | 459 podofoFileClass.write('\n') |
| 421 | 460 |
| 422 fileClass.write('#endif // __DEFINED__SkPdf' + cls.fName + '\n') | 461 podofoFileClass.write('#endif // __DEFINED__PODOFO_SkPdf' + cls.fName + '
\n') |
| 423 fileClass.close() | 462 |
| 424 fileClassCpp.close() | 463 podofoFileClass.close() |
| 425 | 464 podofoFileClassCpp.close() |
| 426 | |
| 427 | 465 |
| 428 # generate constructor when knowing the type | 466 # generate constructor when knowing the type |
| 429 # later, p2, generate constructor when not knowing the type - very similar
with parsing? | 467 # later, p2, generate constructor when not knowing the type - very similar
with parsing? |
| 430 | 468 |
| 431 # generate parser | 469 # generate parser |
| 432 # TODO(edisonn): fast recognition based on must attributes. | 470 # TODO(edisonn): fast recognition based on must attributes. |
| 433 fileMapper = open('SkPdfPodofoMapper_autogen.h', 'w') | 471 fileMapperPodofo = open(sys.argv[1] + 'podofo/autogen/SkPdfMapper_autogen.h'
, 'w') |
| 434 fileMapperCpp = open('SkPdfPodofoMapper_autogen.cpp', 'w') | 472 fileMapperPodofoCpp = open(sys.argv[1] + 'podofo/autogen/SkPdfMapper_autogen
.cpp', 'w') |
| 435 fileMapper.write('#ifndef __DEFINED__SkPdfPodofoMapper\n') | 473 |
| 436 fileMapper.write('#define __DEFINED__SkPdfPodofoMapper\n') | 474 fileMapperPodofo.write('#ifndef __DEFINED__SkPdfMapper\n') |
| 437 fileMapper.write('\n') | 475 fileMapperPodofo.write('#define __DEFINED__SkPdfMapper\n') |
| 438 | 476 fileMapperPodofo.write('\n') |
| 439 fileMapper.write('#include "SkPdfHeaders_autogen.h"\n') | 477 |
| 440 fileMapperCpp.write('#include "SkPdfPodofoMapper_autogen.h"\n') | 478 fileMapperPodofo.write('#include "SkPdfHeaders_autogen.h"\n') |
| 441 # fileMapper.write('class PodofoMapper {\n') | 479 |
| 442 # fileMapper.write('public:\n') | 480 |
| 481 fileMapperPodofo.write('namespace PoDoFo {\n') |
| 482 fileMapperPodofo.write('class PdfDictionary;\n') |
| 483 fileMapperPodofo.write('class PdfMemDocument;\n') |
| 484 fileMapperPodofo.write('class PdfObject;\n') |
| 485 fileMapperPodofo.write('}\n') |
| 486 |
| 487 fileMapperPodofoCpp.write('#include "SkPdfMapper_autogen.h"\n') |
| 488 fileMapperPodofoCpp.write('#include "SkPdfUtils.h"\n') |
| 489 fileMapperPodofoCpp.write('#include "podofo.h"\n') |
| 490 fileMapperPodofoCpp.write('\n') |
| 491 |
| 492 fileMapperPodofo.write('class SkPdfMapper {\n') |
| 493 |
| 494 fileMapperPodofo.write(' const SkPodofoParsedPDF* fParsedDoc;\n') |
| 495 fileMapperPodofo.write(' const PoDoFo::PdfMemDocument* fPodofoDoc;\n') |
| 496 |
| 497 fileMapperPodofo.write('public:\n') |
| 498 |
| 499 fileMapperPodofo.write(' SkPdfMapper(const SkPodofoParsedPDF* doc) : fParse
dDoc(doc), fPodofoDoc(doc ? doc->podofo() : NULL) {}\n') |
| 500 fileMapperPodofo.write('\n') |
| 501 |
| 443 for name in self.fClassesNamesInOrder: | 502 for name in self.fClassesNamesInOrder: |
| 444 cls = self.fClasses[name] | 503 cls = self.fClasses[name] |
| 445 | 504 |
| 446 | 505 fileMapperPodofo.write(' bool map' + name + '(const SkPdfObject* in, SkPd
f' + name + '** out) const;\n') |
| 447 fileMapper.write('bool map' + name + '(const SkPdfObject& in, SkPdf' + nam
e + '** out);\n') | 506 |
| 448 | 507 fileMapperPodofoCpp.write('bool SkPdfMapper::map' + name + '(const SkPdfOb
ject* in, SkPdf' + name + '** out) const {\n') |
| 449 fileMapperCpp.write('bool map' + name + '(const SkPdfObject& in, SkPdf' +
name + '** out) {\n') | 508 fileMapperPodofoCpp.write(' return map' + name + '((const PoDoFo::PdfObje
ct*)in->data(), (SkPdf' + name + '**)out);\n') |
| 450 fileMapperCpp.write(' return map' + name + '(*in.doc(), *in.podofo(), out
);\n') | 509 fileMapperPodofoCpp.write('}\n') |
| 451 fileMapperCpp.write('}\n') | 510 fileMapperPodofoCpp.write('\n') |
| 452 fileMapperCpp.write('\n') | 511 |
| 453 | 512 fileMapperPodofo.write(' bool map' + name + '(const PoDoFo::PdfObject* po
dofoObj, SkPdf' + name + '** out) const ;\n') |
| 454 fileMapper.write('bool map' + name + '(const PdfMemDocument& podofoDoc, co
nst PdfObject& podofoObj, SkPdf' + name + '** out);\n') | 513 fileMapperPodofoCpp.write('bool SkPdfMapper::map' + name + '(const PoDoFo:
:PdfObject* podofoObj, SkPdf' + name + '** out) const {\n') |
| 455 fileMapperCpp.write('bool map' + name + '(const PdfMemDocument& podofoDoc,
const PdfObject& podofoObj, SkPdf' + name + '** out) {\n') | 514 fileMapperPodofoCpp.write(' if (!is' + name + '(podofoObj)) return false;
\n') |
| 456 fileMapperCpp.write(' if (!is' + name + '(podofoDoc, podofoObj)) return f
alse;\n') | 515 fileMapperPodofoCpp.write('\n') |
| 457 fileMapperCpp.write('\n') | |
| 458 | 516 |
| 459 # stream must be last one | 517 # stream must be last one |
| 460 hasStream = False | 518 hasStream = False |
| 461 for sub in cls.fEnumSubclasses: | 519 for sub in cls.fEnumSubclasses: |
| 462 if cls.fName == 'Object' and enumToCls[sub].fName == 'Stream': | 520 if cls.fName == 'Object' and enumToCls[sub].fName == 'Stream': |
| 463 hasStream = True | 521 hasStream = True |
| 464 else: | 522 else: |
| 465 fileMapperCpp.write(' if (map' + enumToCls[sub].fName + '(podofoDoc,
podofoObj, (SkPdf' + enumToCls[sub].fName + '**)out)) return true;\n') | 523 fileMapperPodofoCpp.write(' if (map' + enumToCls[sub].fName + '(podof
oObj, (SkPdf' + enumToCls[sub].fName + '**)out)) return true;\n') |
| 466 | 524 |
| 467 if hasStream: | 525 if hasStream: |
| 468 fileMapperCpp.write(' if (mapStream(podofoDoc, podofoObj, (SkPdfStream*
*)out)) return true;\n') | 526 fileMapperPodofoCpp.write(' if (mapStream(podofoObj, (SkPdfStream**)out
)) return true;\n') |
| 469 | 527 |
| 470 | 528 |
| 471 fileMapperCpp.write('\n') | 529 fileMapperPodofoCpp.write('\n') |
| 472 | 530 |
| 473 fileMapperCpp.write(' *out = new SkPdf' + name + '(&podofoDoc, &podofoObj
);\n') | 531 fileMapperPodofoCpp.write(' *out = new SkPdf' + name + '(fParsedDoc, podo
foObj);\n') |
| 474 fileMapperCpp.write(' return true;\n') | 532 fileMapperPodofoCpp.write(' return true;\n') |
| 475 fileMapperCpp.write('}\n') | 533 fileMapperPodofoCpp.write('}\n') |
| 476 fileMapperCpp.write('\n') | 534 fileMapperPodofoCpp.write('\n') |
| 477 | 535 |
| 478 for name in self.fClassesNamesInOrder: | 536 for name in self.fClassesNamesInOrder: |
| 479 cls = self.fClasses[name] | 537 cls = self.fClasses[name] |
| 480 | 538 |
| 481 fileMapper.write('bool is' + name + '(const PdfMemDocument& podofoDoc, con
st PdfObject& podofoObj);\n') | 539 fileMapperPodofo.write(' bool is' + name + '(const PoDoFo::PdfObject* pod
ofoObj) const ;\n') |
| 482 fileMapperCpp.write('bool is' + name + '(const PdfMemDocument& podofoDoc,
const PdfObject& podofoObj) {\n') | 540 fileMapperPodofoCpp.write('bool SkPdfMapper::is' + name + '(const PoDoFo::
PdfObject* podofoObj) const {\n') |
| 483 | 541 |
| 484 if cls.fCheck != '': | 542 if cls.fCheck != '': |
| 485 fileMapperCpp.write(' return ' + cls.fCheck + ';\n') | 543 fileMapperPodofoCpp.write(' return ' + cls.fCheck + ';\n') |
| 486 else: | 544 else: |
| 487 cntMust = 0 | 545 cntMust = 0 |
| 488 for field in cls.fFields: | 546 for field in cls.fFields: |
| 489 prop = field.fProp | 547 prop = field.fProp |
| 490 if prop.fHasMust: | 548 if prop.fHasMust: |
| 491 cntMust = cntMust + 1 | 549 cntMust = cntMust + 1 |
| 492 fileMapperCpp.write(' ' + knowTypes[prop.fTypes.strip()][0] + ' ' +
prop.fCppName + ';\n') | 550 fileMapperPodofoCpp.write(' ' + knowTypes[prop.fTypes.strip()][0] +
' ' + prop.fCppName + ';\n') |
| 493 fileMapperCpp.write(' if (!podofoObj.IsDictionary()) return false;\
n') | 551 fileMapperPodofoCpp.write(' if (!podofoObj->IsDictionary()) return
false;\n') |
| 494 fileMapperCpp.write(' if (!' + knowTypes[prop.fTypes.strip()][1] +
'(&podofoDoc, podofoObj.GetDictionary(), \"' + prop.fName + '\", \"' + prop.fAbr
+ '\", &' + prop.fCppName + ')) return false;\n') | 552 fileMapperPodofoCpp.write(' if (!' + knowTypes[prop.fTypes.strip()]
[1] + '(fParsedDoc, podofoObj->GetDictionary(), \"' + prop.fName + '\", \"' + pr
op.fAbr + '\", &' + prop.fCppName + ')) return false;\n') |
| 495 | 553 |
| 496 eval = ''; | 554 eval = ''; |
| 497 # TODO(edisonn): this could get out of hand, and could have poor per
formance if continued on this path | 555 # TODO(edisonn): this could get out of hand, and could have poor per
formance if continued on this path |
| 498 # but if we would write our parser, then best thing would be to crea
te a map of (key, value) -> to bits | 556 # but if we would write our parser, then best thing would be to crea
te a map of (key, value) -> to bits |
| 499 # and at each (key, value) we do an and with the bits existent, then
we check what bits are left, which would tell the posible types of this diction
ary | 557 # and at each (key, value) we do an and with the bits existent, then
we check what bits are left, which would tell the posible types of this diction
ary |
| 500 # and for non unique posinilities (if any) based on context, or the
requester of dictionry we can determine fast the dictionary type | 558 # and for non unique posinilities (if any) based on context, or the
requester of dictionry we can determine fast the dictionary type |
| 501 mustBe = self.determineAllMustBe(cls, field, enumToCls) | 559 mustBe = self.determineAllMustBe(cls, field, enumToCls) |
| 502 if len(mustBe) > 0: | 560 if len(mustBe) > 0: |
| 503 for cnd in mustBe: | 561 for cnd in mustBe: |
| 504 if eval == '': | 562 if eval == '': |
| 505 eval = '(' + prop.fCppName + ' != ' + cnd.toCpp() + ')' | 563 eval = '(' + prop.fCppName + ' != ' + cnd.toCpp() + ')' |
| 506 else: | 564 else: |
| 507 eval = eval + ' && ' + '(' + prop.fCppName + ' != ' + cnd.toCp
p() + ')' | 565 eval = eval + ' && ' + '(' + prop.fCppName + ' != ' + cnd.toCp
p() + ')' |
| 508 fileMapperCpp.write(' if (' + eval + ') return false;\n') | 566 fileMapperPodofoCpp.write(' if (' + eval + ') return false;\n') |
| 509 fileMapperCpp.write('\n') | 567 fileMapperPodofoCpp.write('\n') |
| 510 | 568 |
| 511 fileMapperCpp.write(' return true;\n') | 569 fileMapperPodofoCpp.write(' return true;\n') |
| 512 | 570 |
| 513 fileMapperCpp.write('}\n') | 571 fileMapperPodofoCpp.write('}\n') |
| 514 fileMapperCpp.write('\n') | 572 fileMapperPodofoCpp.write('\n') |
| 515 | 573 |
| 516 fileMapper.write('bool ' + name + 'FromDictionary(const PdfMemDocument* pd
fDoc, const PdfDictionary& dict, const char* key, SkPdf' + name + '** data);\n') | 574 fileMapperPodofo.write(' bool SkPdf' + name + 'FromDictionary(const PoDoF
o::PdfDictionary& dict, const char* key, SkPdf' + name + '** data) const ;\n') |
| 517 fileMapperCpp.write('bool ' + name + 'FromDictionary(const PdfMemDocument*
pdfDoc, const PdfDictionary& dict, const char* key, SkPdf' + name + '** data) {
\n') | 575 fileMapperPodofoCpp.write('bool SkPdfMapper::SkPdf' + name + 'FromDictiona
ry(const PoDoFo::PdfDictionary& dict, const char* key, SkPdf' + name + '** data)
const {\n') |
| 518 fileMapperCpp.write(' const PdfObject* value = resolveReferenceObject(pdf
Doc, dict.GetKey(PdfName(key)), true);\n') | 576 fileMapperPodofoCpp.write(' const PoDoFo::PdfObject* value = resolveRefer
enceObject(fParsedDoc, dict.GetKey(PoDoFo::PdfName(key)), true);\n') |
| 519 fileMapperCpp.write(' if (value == NULL) { return false; }\n') | 577 fileMapperPodofoCpp.write(' if (value == NULL) { return false; }\n') |
| 520 fileMapperCpp.write(' if (data == NULL) { return true; }\n') | 578 fileMapperPodofoCpp.write(' if (data == NULL) { return true; }\n') |
| 521 fileMapperCpp.write(' return map' + name + '(*pdfDoc, *value, (SkPdf' + n
ame + '**)data);\n') | 579 fileMapperPodofoCpp.write(' return map' + name + '(value, (SkPdf' + name
+ '**)data);\n') |
| 522 fileMapperCpp.write('}\n') | 580 fileMapperPodofoCpp.write('}\n') |
| 523 fileMapperCpp.write('\n') | 581 fileMapperPodofoCpp.write('\n') |
| 524 | 582 |
| 525 fileMapper.write('bool ' + name + 'FromDictionary(const PdfMemDocument* pd
fDoc, const PdfDictionary& dict, const char* key, const char* abr, SkPdf' + name
+ '** data);\n') | 583 fileMapperPodofo.write(' bool SkPdf' + name + 'FromDictionary(const PoDoF
o::PdfDictionary& dict, const char* key, const char* abr, SkPdf' + name + '** da
ta) const ;\n') |
| 526 fileMapperCpp.write('bool ' + name + 'FromDictionary(const PdfMemDocument*
pdfDoc, const PdfDictionary& dict, const char* key, const char* abr, SkPdf' + n
ame + '** data) {\n') | 584 fileMapperPodofoCpp.write('bool SkPdfMapper::SkPdf' + name + 'FromDictiona
ry(const PoDoFo::PdfDictionary& dict, const char* key, const char* abr, SkPdf' +
name + '** data) const {\n') |
| 527 fileMapperCpp.write(' if (' + name + 'FromDictionary(pdfDoc, dict, key, d
ata)) return true;\n') | 585 fileMapperPodofoCpp.write(' if (SkPdf' + name + 'FromDictionary(dict, key
, data)) return true;\n') |
| 528 fileMapperCpp.write(' if (abr == NULL || *abr == \'\\0\') return false;\n
') | 586 fileMapperPodofoCpp.write(' if (abr == NULL || *abr == \'\\0\') return fa
lse;\n') |
| 529 fileMapperCpp.write(' return ' + name + 'FromDictionary(pdfDoc, dict, abr
, data);\n') | 587 fileMapperPodofoCpp.write(' return SkPdf' + name + 'FromDictionary(dict,
abr, data);\n') |
| 530 fileMapperCpp.write('}\n') | 588 fileMapperPodofoCpp.write('}\n') |
| 531 fileMapperCpp.write('\n') | 589 fileMapperPodofoCpp.write('\n') |
| 532 | 590 |
| 533 #fileMapper.write('};\n') | 591 fileMapperPodofo.write('};\n') |
| 534 fileMapper.write('\n') | 592 fileMapperPodofo.write('\n') |
| 535 | 593 |
| 536 fileMapper.write('#endif // __DEFINED__SkPdfPodofoMapper\n') | 594 fileMapperPodofo.write('#endif // __DEFINED__SkPdfMapper\n') |
| 537 fileMapper.close() | 595 |
| 596 fileMapperPodofo.close() |
| 597 fileMapperPodofoCpp.close() |
| 538 | 598 |
| 539 return | 599 return |
| 540 | 600 |
| 541 def generateCode(): | 601 def generateCode(): |
| 542 global fileHeaders | 602 global fileHeadersPodofo |
| 543 global fileHeadersCpp | 603 global fileHeadersPodofoCpp |
| 544 global knowTypes | 604 global knowTypes |
| 545 | 605 |
| 546 fileHeaders = open('SkPdfHeaders_autogen.h', 'w') | 606 fileHeadersPodofo = open(sys.argv[1] + 'podofo/autogen/SkPdfHeaders_autogen.h'
, 'w') |
| 547 fileHeadersCpp = open('SkPdfHeaders_autogen.cpp', 'w') | 607 fileHeadersPodofoCpp = open(sys.argv[1] + 'podofo/autogen/SkPdfHeaders_autogen
.cpp', 'w') |
| 548 fileHeaders.write('#ifndef __DEFINED__SkPdfHeaders\n') | |
| 549 fileHeaders.write('#define __DEFINED__SkPdfHeaders\n') | |
| 550 fileHeaders.write('\n') | |
| 551 | 608 |
| 552 fileHeaders.write('#include "SkPdfEnums_autogen.h"\n') | 609 fileHeadersPodofo.write('#ifndef __DEFINED__SkPdfHeaders\n') |
| 610 fileHeadersPodofo.write('#define __DEFINED__SkPdfHeaders\n') |
| 611 fileHeadersPodofo.write('\n') |
| 553 | 612 |
| 554 fileHeadersCpp.write('#include "SkPdfHeaders_autogen.h"\n') | 613 fileHeadersPodofoCpp.write('#include "SkPdfHeaders_autogen.h"\n') |
| 555 | 614 |
| 556 manager = PdfClassManager() | 615 manager = PdfClassManager() |
| 557 | 616 |
| 558 manager.addClass('Object') | 617 manager.addClass('Object') |
| 559 | 618 |
| 560 manager.addClass('Null').check('podofoObj.GetDataType() == ePdfDataType_Null') | 619 # TODO(edisonn): perf, instead of virtual functions, store data in field and r
eurn it. |
| 561 manager.addClass('Boolean').check('podofoObj.GetDataType() == ePdfDataType_Boo
l')\ | 620 # maybe in constructor load it, or laizy load it |
| 562 .carbonCopyPublic('bool value() const {return fPodo
foObj->GetBool();}') | 621 |
| 622 manager.addClass('Null').check('podofoObj->GetDataType() == PoDoFo::ePdfDataTy
pe_Null') |
| 623 manager.addClass('Boolean').check('podofoObj->GetDataType() == PoDoFo::ePdfDat
aType_Bool')\ |
| 624 .carbonCopyPublicPodofo('bool value() const;')\ |
| 625 .carbonCopyPublicPodofoCpp('bool SkPdfBoolean::valu
e() const {return podofo()->GetBool();}') |
| 563 | 626 |
| 564 manager.addClass('Integer').check('podofoObj.GetDataType() == ePdfDataType_Num
ber || podofoObj.GetDataType() == ePdfDataType_Real')\ | 627 manager.addClass('Integer').check('podofoObj->GetDataType() == PoDoFo::ePdfDat
aType_Number || podofoObj->GetDataType() == PoDoFo::ePdfDataType_Real')\ |
| 565 .carbonCopyPublic('long value() const {return fPodo
foObj->GetNumber();}') | 628 .carbonCopyPublicPodofo('long value() const;')\ |
| 629 .carbonCopyPublicPodofoCpp('long SkPdfInteger::valu
e() const {return podofo()->GetNumber();}') |
| 566 | 630 |
| 567 manager.addClass('Number', 'Integer').check('podofoObj.GetDataType() == ePdfDa
taType_Number || podofoObj.GetDataType() == ePdfDataType_Real')\ | 631 manager.addClass('Number', 'Integer').check('podofoObj->GetDataType() == PoDoF
o::ePdfDataType_Number || podofoObj->GetDataType() == PoDoFo::ePdfDataType_Real'
)\ |
| 568 .carbonCopyPublic('double value() const {return fPo
dofoObj->GetReal();}') | 632 .carbonCopyPublicPodofo('double value() const;')\ |
| 633 .carbonCopyPublicPodofoCpp('double SkPdfNumber::val
ue() const {return podofo()->GetReal();}')\ |
| 569 | 634 |
| 570 manager.addClass('Name').check('podofoObj.GetDataType() == ePdfDataType_Name')
\ | 635 manager.addClass('Name').check('podofoObj->GetDataType() == PoDoFo::ePdfDataTy
pe_Name')\ |
| 571 .carbonCopyPublic('const std::string& value() const
{return fPodofoObj->GetName().GetName();}') | 636 .carbonCopyPublicPodofo('const std::string& value()
const;')\ |
| 637 .carbonCopyPublicPodofoCpp('const std::string& SkPd
fName::value() const {return podofo()->GetName().GetName();}') |
| 572 | 638 |
| 573 manager.addClass('Reference').check('podofoObj.GetDataType() == ePdfDataType_R
eference') | 639 manager.addClass('Reference').check('podofoObj->GetDataType() == PoDoFo::ePdfD
ataType_Reference') |
| 574 | 640 |
| 575 manager.addClass('Array').check('podofoObj.GetDataType() == ePdfDataType_Array
')\ | 641 manager.addClass('Array').check('podofoObj->GetDataType() == PoDoFo::ePdfDataT
ype_Array')\ |
| 576 .carbonCopyPublic('const int size() const {return f
PodofoObj->GetArray().GetSize();}')\ | 642 .carbonCopyPublicPodofo('const int size() const;')\ |
| 577 .carbonCopyPublic('SkPdfObject* operator[](int i) c
onst { SkPdfObject* ret = NULL; skpdfmap(*fPodofoDoc, fPodofoObj->GetArray()[i]
, &ret); return ret; }')\ | 643 .carbonCopyPublicPodofoCpp('const int SkPdfArray::s
ize() const {return podofo()->GetArray().GetSize();}')\ |
| 644 .carbonCopyPublicPodofo('SkPdfObject* operator[](in
t i) const;')\ |
| 645 .carbonCopyPublicPodofoCpp('SkPdfObject* SkPdfArray
::operator[](int i) const { SkPdfObject* ret = NULL; fParsedDoc->mapper()->mapO
bject(&podofo()->GetArray()[i], &ret); return ret; }') |
| 578 | 646 |
| 579 manager.addClass('String').check('podofoObj.GetDataType() == ePdfDataType_Stri
ng || podofoObj.GetDataType() == ePdfDataType_HexString')\ | 647 manager.addClass('String').check('podofoObj->GetDataType() == PoDoFo::ePdfData
Type_String || podofoObj->GetDataType() == PoDoFo::ePdfDataType_HexString')\ |
| 580 .carbonCopyPublic('const std::string& value() const
{return fPodofoObj->GetString().GetStringUtf8();}') | 648 .carbonCopyPublicPodofo('const std::string& value()
const;')\ |
| 649 .carbonCopyPublicPodofoCpp('const std::string& SkPdf
String::value() const {return podofo()->GetString().GetStringUtf8();}')\ |
| 650 .carbonCopyPublicPodofo('const char* c_str() const;'
)\ |
| 651 .carbonCopyPublicPodofoCpp('const char* SkPdfString:
:c_str() const {return podofo()->GetString().GetString();}')\ |
| 652 .carbonCopyPublicPodofo('size_t len() const;')\ |
| 653 .carbonCopyPublicPodofoCpp('size_t SkPdfString::len(
) const {return podofo()->GetString().GetLength();}') |
| 581 | 654 |
| 582 manager.addClass('HexString', 'String').check('podofoObj.GetDataType() == ePdf
DataType_HexString')\ | 655 manager.addClass('HexString', 'String').check('podofoObj->GetDataType() == PoD
oFo::ePdfDataType_HexString')\ |
| 583 .carbonCopyPublic('const std::string& value() const
{return fPodofoObj->GetString().GetStringUtf8();}') | |
| 584 | 656 |
| 585 manager.addClass('Dictionary').check('podofoObj.GetDataType() == ePdfDataType_
Dictionary')\ | 657 manager.addClass('Dictionary').check('podofoObj->GetDataType() == PoDoFo::ePdf
DataType_Dictionary')\ |
| 586 .carbonCopyPublic('SkPdfObject* get(const char*
dictionaryKeyName) const {return new SkPdfObject(fPodofoDoc, resolveReferenceObj
ect(fPodofoDoc, fPodofoObj->GetDictionary().GetKey(PdfName(dictionaryKeyName))))
;}')\ | 658 .carbonCopyPublicPodofo('SkPdfObject* get(const
char* dictionaryKeyName) const;')\ |
| 587 .carbonCopyPublic('SkPdfObject* get(const char*
dictionaryKeyName) {return new SkPdfObject(fPodofoDoc, resolveReferenceObject(fP
odofoDoc, fPodofoObj->GetDictionary().GetKey(PdfName(dictionaryKeyName))));}')\ | 659 .carbonCopyPublicPodofoCpp('SkPdfObject* SkPdfDi
ctionary::get(const char* dictionaryKeyName) const {SkPdfObject* ret = NULL; fPa
rsedDoc->mapper()->mapObject(resolveReferenceObject(fParsedDoc, podofo()->GetDic
tionary().GetKey(PoDoFo::PdfName(dictionaryKeyName))), &ret); return ret;}')\ |
| 588 | 660 |
| 589 manager.addClass('Stream') # attached to a dictionary in podofo | 661 # attached to a dictionary in podofo |
| 662 manager.addClass('Stream')\ |
| 663 .carbonCopyPublicPodofo('bool GetFilteredCopy(char** buffer, long*
len) const;')\ |
| 664 .carbonCopyPublicPodofoCpp('bool SkPdfStream::GetFilteredCopy(char
** buffer, long* len) const {try {PoDoFo::pdf_long podofoLen = 0; *buffer = NULL
; *len = 0;podofo()->GetStream()->GetFilteredCopy(buffer, &podofoLen); *len = (l
ong)podofoLen;} catch (PoDoFo::PdfError& e) { return false; } return true;}') |
| 590 | 665 |
| 591 | 666 |
| 592 # these classes are not explicitely backed by a table in the pdf spec | 667 # these classes are not explicitely backed by a table in the pdf spec |
| 593 manager.addClass('XObjectDictionary', 'Dictionary') | 668 manager.addClass('XObjectDictionary', 'Dictionary') |
| 594 | 669 |
| 595 manager.addClass('FontDictionary', 'Dictionary') | 670 manager.addClass('FontDictionary', 'Dictionary') |
| 596 | 671 |
| 597 manager.addClass('TrueTypeFontDictionary', 'Type1FontDictionary')\ | 672 manager.addClass('TrueTypeFontDictionary', 'Type1FontDictionary')\ |
| 598 .required('NULL')\ | 673 .required('NULL')\ |
| 599 .field('Subtype')\ | 674 .field('Subtype')\ |
| (...skipping 12 matching lines...) Expand all Loading... |
| 612 .field('Subtype')\ | 687 .field('Subtype')\ |
| 613 .name('Subtype')\ | 688 .name('Subtype')\ |
| 614 .type('name')\ | 689 .type('name')\ |
| 615 .comment('')\ | 690 .comment('')\ |
| 616 .must([datatypes.PdfName('MMType1')])\ | 691 .must([datatypes.PdfName('MMType1')])\ |
| 617 .done().done()\ | 692 .done().done()\ |
| 618 | 693 |
| 619 | 694 |
| 620 manager.write() | 695 manager.write() |
| 621 | 696 |
| 622 fileHeaders.write('#endif // __DEFINED__SkPdfHeaders\n') | 697 fileHeadersPodofo.write('#endif // __DEFINED__SkPdfHeaders\n') |
| 623 fileHeaders.close() | 698 |
| 624 fileHeadersCpp.close() | 699 fileHeadersPodofo.close() |
| 625 | 700 fileHeadersPodofoCpp.close() |
| 626 return 1 | |
| 627 | 701 |
| 628 if '__main__' == __name__: | 702 if '__main__' == __name__: |
| 703 #print sys.argv |
| 629 sys.exit(generateCode()) | 704 sys.exit(generateCode()) |
| 630 | 705 |
| OLD | NEW |