Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
typing [2016/10/14 17:57]
christian [PDF Object Types]
typing [2017/09/27 18:45] (current)
christian [Typed Attributes]
Line 1: Line 1:
 ====== PDF Object Types ====== ====== PDF Object Types ======
  
-Objects in PDF have a type and attributes of PDF objects expect to hold objects of a specific type. The types form a hierarchy with ''Object'' as root. The PDF type hierarchy is independent of the Smalltalk class hierarchy of the classes implementing the PDF type+Objects in PDF have a type and attributes of PDF objects expect to hold objects of a specific type. The types form a hierarchy with **''Object''** as root. 
  
-PDF type is implemented by a Smalltalk class. Each clas must implement the class method ''pdfType'' which returns a PDFType object like:+The PDF type hierarchy is independent of the Smalltalk class hierarchyOften, the Smalltalk class hierarchy coincides with the PDF type hierarchy, but this is not required. Also, the name of the PDF type can be different from the name of the Smalltalk class, but often they are the same. PDF types and Smalltalk classes are connected by a 1 to 1 relationship: a class can implement only one type and a type can only be implemented by one class. 
 + 
 +A Smalltalk class is declared to represent a PDF type by implementing the class method **''pdfTypeDefinition''** which returns a PDFTypeDefinition object like:
  
 <code smalltalk> <code smalltalk>
-pdfType +pdfTypeDefinition 
-  ^PDFType+  ^PDFTypeDefinition
     name: #Integer     name: #Integer
     supertype: #Number     supertype: #Number
Line 16: Line 18:
 </code> </code>
  
-  * The ''name'' of a PDFType is a symbol used as type for the type declarations of an attribute. +  * ''name'' is a symbol used as type for the type declarations of an attribute. The name should be identical or very similar to the name used in the PDF specification
-  * The ''supertype'' symbol denotes the parent type. It is ''nil'' for the top PDF type ''Object''.  +  * ''supertype'' denotes the parent type. It is ''nil'' for the top PDF type ''Object''.  
-  * The ''section'' specifies the section of the PDF specification where the type is defined. This allows the PDF specification to be opened on the documentation of the type. +  * ''section'' specifies the section of the PDF specification where the type is defined. This will allow the PDF specification to be opened on the documentation of the type. 
   * ''documentation'' holds a short description of the type, usually copied (and slightly edited) from the first paragraph in the PDF specification.    * ''documentation'' holds a short description of the type, usually copied (and slightly edited) from the first paragraph in the PDF specification. 
-  * Optional is the attribute ''version'' which holds an integer specifying the minor PDF version (mayor version is 1) where the type was introduced. When omitted the version defaults to ''0'' (corresponding to PDF version 1.0).+  * ''version'' is optional and holds an integer specifying the minor PDF version (mayor version is 1) where the type was introduced. When omitted the version defaults to ''0'' (corresponding to PDF version 1.0).
  
-''pdfType'' is a special method used to construct the PDF type hierarchy. ALL ''pdfType'' methods shall only construct and return a PDFType object. In order to do so, ALL implementers of ''pdfType'' are collected, evaluated and sorted into the type hierarchy. Therefore, none of the ''pdfType'' methods shall have any side effects. This allows to define a PDF object class independent of the Smalltalk class hierarchy.+''pdfTypeDefinition'' is a special method used to construct the PDF type hierarchy. ALL ''pdfTypeDefinition'' methods shall only construct and return a PDFTypeDefinition object. In order to do so, ALL implementers of ''pdfTypeDefinition'' are collected, evaluated and sorted into the type hierarchy. Therefore, none of the ''pdfTypeDefinition'' methods shall have any side effects. This allows to define a PDF object type independent of the Smalltalk class hierarchy.
  
 ===== Typed Attributes ===== ===== Typed Attributes =====
Line 30: Line 32:
 The following pragmas are used for declaring a type: The following pragmas are used for declaring a type:
  
-  * **#type:** *aSymbol* The value (or references) should be of type aSymbol+  * **#type:** *aSymbol* The value (or referenced value) should be of type aSymbol
   * **#typeDirect:** *aSymbol* The value should be of type aSymbol   * **#typeDirect:** *aSymbol* The value should be of type aSymbol
-  * **#typeIndirect:** *aSymbol* The value should be a reference of type aSymbol +  * **#typeIndirect:** *aSymbol* The value should be a reference to an object of type aSymbol 
-  * **#typeArrayOf:** *aSymbol* The value should be an array with values (or references) of type aSymbol +  * **#typeArrayOf:** *aSymbol* The value should be an array with values (or referenced values) of type aSymbol 
-  * **#typeDictionaryOf:** *aSymbol* The value should be a dictionary with values (or references) of type aSymbol+  * **#typeDictionaryOf:** *aSymbol* The value should be a dictionary with values (or referenced values) of type aSymbol
  
 The pragmas can occur several times. One of the given types should apply. The pragmas can occur several times. One of the given types should apply.
Line 42: Line 44:
   <typeArrayOf: #Contents>   <typeArrayOf: #Contents>
 </code> </code>
-The symbol is the type name of the PDF object. So far, the type name corresponds to the class name in the Smalltalk implementation hierarchy.+This declares that the attribute #Contents of a Page can hold either  
 +  * a Contents object or  
 +  * an array of Contents objects.
  
 A type of an object is used when it gets assigned to an attribute. With the type requirement of the attribute, the object is specialized to the attribute type if possible. If this is not possible, a TypeError is raised.  A type of an object is used when it gets assigned to an attribute. With the type requirement of the attribute, the object is specialized to the attribute type if possible. If this is not possible, a TypeError is raised. 
Line 82: Line 86:
  
 Rectangle>>ury Rectangle>>ury
-  <attribute: 4 documentation: 'upper right corner x'>+  <attribute: 4 documentation: 'upper right corner y'>
   ^self at: 4   ^self at: 4
 </code> </code>
Line 132: Line 136:
 </code> </code>
 When an object is not a subclass of a type, it can be specialized if the objects class subsumes the type. When an object is not a subclass of a type, it can be specialized if the objects class subsumes the type.
 +
 +
  
  • typing.1476460639.txt.gz
  • Last modified: 2016/10/14 17:57
  • by christian