Context Source Edits
Introduction
The majority of PTC APP’s code is generated for element contexts. PTC APP creates a separate tag for the onEnter and onExit events associated with each context listed in Arbortext Styler’s element and context list. PTC APP does not allow source edits at the element level. Conditions are tested within the context source.
Arbortext Styler allows inline elements to be switched to block structure (and back) in property sets or conditions. For this reason, PTC APP processes everything as a block and only applies the style settings it has gathered to any inline objects it encounters.
The source for the majority of contexts follows a similar structure.
Context Preamble
The context preamble is the set-up section at the top of the onEnter source code. This section sets up the objects and starting properties needed to process the context according to the style specified in Arbortext Styler.
This section contains:
• contextProp
This object tracks the properties set and used by the source code for the context. These properties represent the items that can be changed within property sets and conditions. They are tested later in the source to ensure PTC APP applies the right structures and properties.
It is unlikely that there is any need to edit these values.
• Block
A new fBlock object is created for each context. The default paragraph and default style for this block are assigned to variables. These objects are used to set formatting properties which are then applied if PTC APP recognizes that the context has a block structure.
There is little benefit to editing these block objects in the context preamble. Making changes to the block, paragraph, and style variables are valid source edits to make later in source.
• FISH
A FISH variable tracks some information about the context, for example if it has generated text. The PTC APP template uses FISH because of their save and restore capabilities, which make it easy to pass information between the onEnter and onExit code and keep track of processing.
Context Property Setting
The properties that are set explicitly on the context are applied once the context preamble is finished. Properties from property sets are applied first, followed by block, paragraph, and style properties as appropriate.
For example, if the text height is set to 12pt for the context in the Arbortext Styler UI, this code will appear in this section:
style.height = "12pt";
Calling Property Sets
Arbortext Styler property sets feature an onEnter and onExit component. PTC APP creates a separate tag for each. These tags are called explicitly as functions from the context (or property set) that calls them. As they are JavaScript function tags, they are called using code as shown in this example:
template.content.functions[ template.stylerNamespace ].PropertySet['Standard_space'].onEnter( block, contextProp );
where:
• template.content.functions accesses the JavaScript function tags within the template.
• template.stylerNamespace is a property set on the fTemplate object to define the current stylesheet namespace, typically stylesheet0.
• PropertySet[‘Standard_space’] is a nested namespace (PropertySet:Standard_space).
PropertySet is the namespace for all property sets.
Standard_space is a namespace created for the specific property set.
• onEnter is the tag within the nested namespaces that represents the onEnter code of the property set.
• The block object created in the context preamble and the contextProp object are passed to the function as arguments so that its code can update them if necessary.
Print/PDF Property Setting
Once the context property sets are called and any explicit properties have been set, the properties defined for Print/PDF output in the Outputs to edit area of the Arbortext Styler UI are applied as overrides. The pattern for these is the same as for context properties.
Context Conditions
Once the print/PDF properties have been set, the conditions for the context are applied. The conditions are tested using if, else–if, and else statements. The code executed in these blocks applies any style changes requested and makes any requested calls to property sets. Using source edits to this section you can create your own conditions, to test anything PTC Advanced Print Publisher can test.
Generated text for conditions is handled differently from generated text for contexts. If generated text is applied to a condition, the DOM augmentation is applied inline and context streams (XML DOM tags) are created inline if they do not exist. It is possible to make changes to the generated text that would be generated in this section.
Handling the Settings
Once the formatting properties have been applied, the context code uses the contextProp settings to make changes and carry out further context setup. The code in this section is autogenerated. It should not be edited unless you have full information as to its tasks.
The code in this section carries out the following tests:
• Test if the text is of a preformatted style
Preformatted text has different style properties applied.
• Test language settings to set the hyphenation language
• Test if a column top margin is required
• Test if the context is styled as Hidden
A Hidden setting adds an instruction in the DOM to pass over the content of the element, while ensuring that generated text and element processing still occurs.
• Test whether the context starts something new, for example a column or a page, and apply the necessary breaks
• Test whether the context is applying a block
If it is set to start a block, PTC APP starts a block. If the context is of inline structure, PTC APP changes the current style.
Any changes to the block should be made in sections preceding this one.
• Test if a marker is used, for example labeling or bookmarks
This should not be edited. Application of a marker happens inside the block if one has been started.
• Test if a graphic is to be output
This should not be edited. Graphic settings are made inside the block if one has been started.
Once this section has been processed, the tag exits. Any items to be output inside the element but before the content should be coded at the end of the onEnter source.
onExit Code
The onExit code for a context uses the FISH set in the onEnter code to revert settings made in the onEnter code. The onExit component/tag of any property sets are called here. If a block was started in the onEnter code, it is ended here.
Any processing that is intended to occur outside the block should be coded at the end of the onExit code.