Stylesheet Development with PTC ALD > Adding PTC ALD Code to Stylesheet Source > Samples > PTC ALD Properties > Set PTC ALD Text Properties > Drops
  
Drops
Drop capital
The sample listed here describes how to apply a dropped capital as the first character in a note.
In Arbortext-path/samples/APP/TextProperties/textProperties.xml, the paragraph in the Drop capital section is a child of a note element. The first para in note context in the associated stylesheet contains PTC ALD source code edits to format the first character in the paragraph.
Access the source code edit with the Edit > Edit Context Source > APP.
The relevant code is shown below:
//The block is started
formatting.blockStart(block);
//This line ensures that the block is using the correct formatting properties
so baseline shift doesn't give the block the wrong idea of where to start
formatting.output("<?>");

//Save the current formatting properties to restore later when the drop cap
is finished
formatting.styleSave();

//Style properties for the drop cap. Height is 34pt, colour is red, the drop
cap is shifted 13.5pt down to fill the space left by the indent
var s = new fStyle(formatting.currentStyle);
s.height = "34pt";
s.color = "red";
s.baselineShift = "13.5pt";

//Apply new style formatting properties
formatting.styleChange(s);

//This line uses an APP instruction to call in the first character
formatting.output("<?char>");

//The original formatting properties are restored
formatting.styleRestore();

//A thin space is output to separate the following text from the drop capital
formatting.output("&#128;");

//The following code sets up an indent based on the current horizontal
position which is applied for 2 lines, starting at line 1

//Evaluate the current horizontal posiiton
var hPos = formatting.evaluateShowString("$^21670") + "dm";

//Create the indent using the current horizontal position
var indent = new fIndent();
indent.position = hPos;
indent.firstLine = 1;
indent.lastLine = 2;

//Apply the new indent
formatting.currentParagraph.indentLeft[0] = indent;
The code provides options for the following formatting tasks:
Start the block
formatting.blockStart(block);
Call the blockStart() method of the fFormatting object. Use a block parameter to create a new fBlock object. The new block’s properties will be defined by the attributes set for the block object.
Ensure that the block is using the correct formatting properties
formatting.output("<?>");
Call the output() method of the fFormatting object. The method parses text so you can include PTC ALD proprietary processing instructions (PI) to be resolved and their results output at the current formatting position. Include the PTC ALD PI <?> to indicate the current formatting properties.
This line is added to ensure the baselineShift property set in the next step does not affect the formatting process’s idea of current position.
Save the current style properties
The process will revert to these properties once it has formatted the drop capital.
formatting.styleSave();
Call the styleSave() method of the fFormatting object to saves the current style properties so they can be restored easily later. New formatting properties will be used until the formatting process encounters a formatting.styleRestore command. It will then revert to the previous properties to continue with the default block styling.
Set style properties for the drop capital
var s = new fStyle(formatting.currentStyle);
s.height = "34pt";
s.color = "red";
s.baselineShift = "13.5pt";
Create the variable s to hold the style information.
Call the fStyle() constructor with the keyword new to create a new fStyle object to carry the properties.
Include the parameter (formatting.currentStyle) with the constructor to specify that when the new fStyle object is created, the properties on the new object should be set to the current style properties.
Set explicit values for the height, color, and baselineShift properties of the fStyle object.
Apply new style formatting properties
formatting.styleChange(s);
Call the styleChange() method of the fFormatting object to activate the style properties for the drop capital immediately. This method takes an fStyle object as its parameter. This phrase indicates that contents of variable s should be applied. The previous step defined an fStyle object and passed it to variable s.
Call in the first character
formatting.output("<?char>");
Call the output() method of the fFormatting object (see above). Include the PTC ALD PI <?char> without parameters to cut one character, i.e. the first character, from the current text stream. The current formatting properties configured in the previous step will be applied to this single character.
Restore original formatting properties
formatting.styleRestore();
Call the styleRestore() method of the fFormatting object to restore the style properties in place when styleSave() was called.
The rest of the characters in the content will be formatted accordingly to the default styling properties for the block.
Output space to separate following text from the drop capital
formatting.output("&#128;");
Call the output() method of the fFormatting object, as described above. Include the &#128; entity reference to output a thin space at the current formatting position, i.e. after the drop capital.
Configure an indent based on the current horizontal position
Evaluate the current horizontal position
var hPos = formatting.evaluateShowString("$^21670") + "dm";
Set up the variable hPos to hold the current horizontal position.
The phrase = formatting.evaluateShowString("$^21670") + "dm" calls the evaluateShowString() method of the fFormatting object to evaluate the current value of the PTC ALD show string numbered 21670. This showstring contains information regarding the current format position from the left measure. The phrase will also append the text dm to the current showstring value to provide the measurement unit. The whole value, e.g. 3270522dm, will be stored as the current value of the hPos variable.
You reference this variable in the next step, when setting an indent at the current location.
Create the indent with the current horizontal position
var indent = new fIndent();
indent.position = hPos;
indent.firstLine = 1;
indent.lastLine = 2;
Create the variable indent to hold the indent information. Call the fIndent () constructor with the keyword new to create a new fIndent datatype object that will carry the indent information.
Set the position property of the fIndent object to the value of the hPos variable, i.e. the current horizontal position (see previous step).
Set the firstLine property of the fIndent object to a value of 1. This property indicates the number of the first line of the paragraph that will have the indent applied, counted from 1. In this case, the indent should start at line 1.
Set the lastLine property of the fIndent object to a value of 2. This property indicates the number of the last line of the paragraph that will have the indent applied, counted from 1. In this case, the indent should finish after line 2.
The indent over two lines will provide space for the drop capital.
Apply the new indent
formatting.currentParagraph.indentLeft[0] = indent;
Set the indentLeft property of the current paragraph. The currentParagraph property of the fFormatting object, which is based on an fParagraph object, takes this information.
indentLeft takes an array of values. this phrase sets the first value in the array (numbered 0). The contents of the variable indent are passed as the value.