pdf:extending
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revisionLast revisionBoth sides next revision | ||
pdf:extending [2016/03/24 09:32] – [Add a new Smalltalk class] christian | pdf:extending [2016/03/24 12:08] – [Customize an object type] christian | ||
---|---|---|---|
Line 28: | Line 28: | ||
==== Add a new Smalltalk class ==== | ==== Add a new Smalltalk class ==== | ||
- | The new class can be defined with the //'' | + | The new class can be defined with the //'' |
{{: | {{: | ||
- | |||
- | === Choose a class name === | ||
=== Choose the package === | === Choose the package === | ||
+ | |||
+ | The package is '' | ||
=== Choose the namespace === | === Choose the namespace === | ||
- | === Choose | + | This should be '' |
- | Firstly, | + | === Choose |
- | * a name | + | |
- | * a package | + | |
- | * a namespace (which should be '' | + | |
- | * a superclass which may be Dictionary, TypedDictionary if the object has an attribute **/Type**, or someting else (see later). | + | |
- | As name for this example, I use **/BorderStyle**. Ideally the name should be the same as used in the specification. The package is **[PDF Document]**, | + | As name for this example, I use '' |
- | As class comment, | + | === Choose |
- | < | + | Most often, this will be '' |
- | PDF border style dictionary as defined in PDF 32000_2008.pdf, section 12.5.4, pp. 386. | + | |
- | An annotation may optionally be surrounded by a border when displayed or printed. If present, the border shall be drawn completely inside the annotation rectangle. In PDF 1.1, the characteristics of the border shall be specified by the Border entry in the annotation dictionary (see Table 164). Beginning with PDF 1.2, the border characteristics for some types of annotations may instead be specified in a border style dictionary designated by the annotation’s BS entry. Such dictionaries may also be used to specify the width and dash pattern for the lines drawn by line, square, circle, and ink annotations. Table 166 summarizes the contents of the border style dictionary. If neither the Border nor the BS entry is present, the border shall be drawn as a solid line with a width of 1 point. | + | === Add a class comment === |
- | </ | + | |
- | I usually edit this text to add line breaks after sentences and remove any cross references to other parts of the specification: | + | The first line should give the reference to the PDF specification, |
< | < | ||
Line 68: | Line 63: | ||
</ | </ | ||
- | Two more bits of information should be added as methods on the class side: | + | === Add class methods === |
+ | |||
+ | Two more bits of information should be added as methods on the class side. | ||
+ | |||
+ | The '' | ||
<code smalltalk> | <code smalltalk> | ||
documentationPlace | documentationPlace | ||
Line 74: | Line 74: | ||
</ | </ | ||
- | This is a recent addition intended to be able to jump directly to the corresponding place in the specification | + | If the object type was not part of the original |
<code smalltalk> | <code smalltalk> | ||
Line 81: | Line 81: | ||
</ | </ | ||
- | This notes the minor part of the PDF version in which this feature first occurred, allowing for computing | + | The version is usually mentioned in the specification |
- | Since a new type is defined, the object types have to be reset with '' | + | === Reset the object types === |
+ | |||
+ | Since a new type is defined, the object types have to be reset with | ||
+ | <code smalltalk> | ||
+ | PDF resetObjecttypes. | ||
+ | </ | ||
+ | This clears the cache for all the object types (Smalltalk classes - 137 at the time of writing). On next access, the cache is filled with all known types, including the newly defined ones, so that the new type can be found. | ||
+ | |||
+ | This has to be done only when a new class is defined. | ||
+ | |||
+ | === Use the new type for the containing attributes === | ||
The new type can now be used. Therefore, the type of the attribute which contains the object should be set to the new type. In the example, in the method '' | The new type can now be used. Therefore, the type of the attribute which contains the object should be set to the new type. In the example, in the method '' | ||
Line 104: | Line 114: | ||
</ | </ | ||
- | The result looks like this in the PDFExplorer (after hitting F5 for refresh): | + | The result looks like this in the PDFExplorer (after hitting F5 for refresh): |
{{: | {{: | ||
+ | the style is recognized as **BorderStyle** and it shows the right version (PDF-1.2), but the required field '' | ||
==== Add attributes ==== | ==== Add attributes ==== | ||
- | add attribute method | + | Attributes are added as methods in protocol '' |
- | add pragmas | + | The first two attributes (of 4) look like this in the PDF specification: |
+ | |||
+ | {{: | ||
+ | |||
+ | The corresponding methods look like this: | ||
+ | |||
+ | <code smalltalk> | ||
+ | Type | ||
+ | <type: #Name> | ||
+ | < | ||
+ | ^self objectAt: #Type ifAbsent: [#Border asPDF] | ||
+ | </ | ||
+ | |||
+ | <code smalltalk> | ||
+ | W | ||
+ | <type: # | ||
+ | < | ||
+ | ^self objectAt: #W ifAbsent: [1 asPDF] | ||
+ | </ | ||
+ | |||
+ | An attribute method consists of a number of describing | ||
+ | |||
+ | === The type: pragma === | ||
+ | |||
+ | Mandatory is the ''< | ||
+ | |||
+ | === The documentation pragma === | ||
+ | |||
+ | The documentation is specified in the ''< | ||
+ | |||
+ | The documentation is taken directly from the specification and edited, so that all information is removed which is expressed directly in the method. In our example, the " | ||
+ | |||
+ | The description of the default value is also removed, because this is evident from the access code. | ||
+ | |||
+ | Also references to other parts of the specification are removed (which is not the case in the example). | ||
+ | |||
+ | === The version: pragma === | ||
+ | |||
+ | Often, new attributes were added with later PDF versions. The version of an attribute, if it is higher than the version of the type, can be noted with the ''< | ||
+ | |||
+ | === The access code === | ||
+ | |||
+ | The access code can be either | ||
+ | <code smalltalk> | ||
+ | ^self objectAt: #Type ifAbsent: [#Border asPDF] | ||
+ | </ | ||
+ | |||
+ | for optional attributes with a default value, or | ||
+ | <code smalltalk> | ||
+ | ^self objectAt: #Type | ||
+ | </ | ||
+ | |||
+ | for a required attribute. This will raise an error if the attribute is not present in the object. | ||
+ | |||
+ | The method will return the object of the value of the attribute. The object is either stored directly in the attribute or a reference to it. In any case, the object is returned. To access the value (object or reference), the following methods can be used: | ||
+ | <code smalltalk> | ||
+ | ^self at: #Type ifAbsent: [#Border asPDF] | ||
+ | </ | ||
+ | <code smalltalk> | ||
+ | ^self at: #Type | ||
+ | </ | ||
- | copy and edit comment | ||
===== Customize an object type ===== | ===== Customize an object type ===== | ||
- | docs, icon, string, attributes | + | Now, the PDF type is sufficiently defined to be usefully displayed in the PDFExplorer. But more can be done by defining some of the following methods. |
+ | |||
+ | ==== Optional customization methods ==== | ||
+ | |||
+ | === Display name === | ||
+ | |||
+ | The method '' | ||
+ | |||
+ | === Icon === | ||
+ | |||
+ | The method '' | ||
+ | |||
+ | === Excluding | ||
+ | |||
+ | Some attributes clutter the treeview on the left side of the PDFExplorer. For example, every '' | ||
+ | |||
+ | By defining the method '' | ||
+ | |||
+ | <code smalltalk> | ||
+ | displayKeysToOmit | ||
+ | ^super displayKeysToOmit | ||
+ | </ |
/var/www/virtual/code4hl/html/dokuwiki/data/pages/pdf/extending.txt · Last modified: 2016/03/30 09:00 by christian