Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
typing [2015/04/02 16:17] christian [subsumes] |
typing [2017/09/27 18:45] (current) christian [Typed Attributes] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Typed Attributes | + | ====== 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 **'' | ||
+ | |||
+ | The PDF type hierarchy is independent of the Smalltalk class hierarchy. Often, 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 Smalltalk class is declared to represent a PDF type by implementing the class method **'' | ||
+ | |||
+ | <code smalltalk> | ||
+ | pdfTypeDefinition | ||
+ | ^PDFTypeDefinition | ||
+ | name: #Integer | ||
+ | supertype: #Number | ||
+ | section: ' | ||
+ | documentation: | ||
+ | The value shall be interpreted as a signed decimal integer and shall be converted to an integer object.' | ||
+ | version: 0 | ||
+ | </ | ||
+ | |||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | * '' | ||
+ | |||
+ | '' | ||
+ | |||
+ | ===== Typed Attributes ===== | ||
Attributes of Dictionaries are typed. The definition of an Attribute specifies the class/type of the object and wheather the object is directly stored or a reference to it. | Attributes of Dictionaries are typed. The definition of an Attribute specifies the class/type of the object and wheather the object is directly stored or a reference to it. | ||
Line 5: | 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 |
* **# | * **# | ||
- | * **# | + | * **# |
- | * **# | + | * **# |
- | * **# | + | * **# |
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 17: | Line 44: | ||
< | < | ||
</ | </ | ||
- | 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 # |
+ | * a Contents | ||
+ | * 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. | ||
- | ===== Example | + | ==== Example ==== |
The attribute /Root of /Trailer requires a reference to a /Catalog: | The attribute /Root of /Trailer requires a reference to a /Catalog: | ||
Line 36: | Line 65: | ||
=> TypeError | => TypeError | ||
- | ===== Arrays | + | ==== Arrays ==== |
As /Dictionary can be subclassed, so can /Array. The attributes are not named, but accessed positionally with their index. The attributes in subclasses of /Array should be typed and documented like dictionary attributes. For this, the same pragmas as in /Dictionary are used. In /Dictionary the pragma' | As /Dictionary can be subclassed, so can /Array. The attributes are not named, but accessed positionally with their index. The attributes in subclasses of /Array should be typed and documented like dictionary attributes. For this, the same pragmas as in /Dictionary are used. In /Dictionary the pragma' | ||
Line 57: | Line 86: | ||
Rectangle>> | Rectangle>> | ||
- | < | + | < |
^self at: 4 | ^self at: 4 | ||
</ | </ | ||
Every /Array subclass must implement # | Every /Array subclass must implement # | ||
- | ===== Specializing | + | ==== Specializing ==== |
From the pragmas above types (instances of Type) are created when sending #typesOf: to a Dictionary with the attribute name as argument. Example: | From the pragmas above types (instances of Type) are created when sending #typesOf: to a Dictionary with the attribute name as argument. Example: | ||
Line 73: | Line 102: | ||
</ | </ | ||
- | ==== Extended typing | + | === Extended typing === |
Typing is extended to be able to group several classes in different implementation hierarchies into an abstract PDF Type. | Typing is extended to be able to group several classes in different implementation hierarchies into an abstract PDF Type. | ||
Line 83: | Line 112: | ||
**/ | **/ | ||
- | ==== subsumes | + | === subsumes === |
Line 97: | Line 126: | ||
A PDF object class implements #subsumes: which is simply the test if the object #isKindOf: the class. The supertypes implement this with a list of top classes to which they delegate. | A PDF object class implements #subsumes: which is simply the test if the object #isKindOf: the class. The supertypes implement this with a list of top classes to which they delegate. | ||
- | ==== specializes | + | === specializes === |
- | aPDFObject asType: aType | + | <code smalltalk> |
+ | aPDFObject asType: aType | ||
+ | </ | ||
and | and | ||
- | PDFObject class specializes: | + | <code smalltalk> |
+ | PDFObject class specializes: | ||
+ | </ | ||
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. | ||
+ | |||
+ | |||