Font and Character Text Operators

Font Accessing and Manipulation Operators

The following operators are used to obtain, modify, and construct IndexedFonts.

DefineFont

The DefineFont operator takes one operand

<FD: DictionaryReference>

and returns a single result

<indexedfont: DictionaryReference>

FD shall be a reference to a valid Indexed Font Specification Dictionary. The returned result indexedfont is a reference to a new Indexed Font Dictionary, corresponding to FD.

FindFont

The FindFont operator takes a single operand

<ID: Name>

where ID is the value of an INTERNAL RESOURCE IDENTIFIER which is bound to a IndexedFont in the Context of Interpretation. It returns a single result

<indexedfont: DictionaryReference>

where indexedfont is a reference to the Indexed Font Dictionary to which ID is bound.

If ID is the value of a valid INTERNAL RESOURCE IDENTIFIER in the current context of interpretation and is bound to a IndexedFont, the effect of interpreting FindFont is the same as the effect of interpreting the FindResource operator with a /IndexedFont operand;. that is, the result of {ID FindFont} is the same as {ID /IndexedFont FindResource} The algorithm for selecting the Indexed Font Dictionary which best matches the attributes in a FONT REFERENCE FONT SPECIFICATION is constrained by the SATISFACTION REQUIREMENT and the MATCH RULES and may fail to find a suitable match, but a selection is always provided.

If the font reference is unsatisfied (whether for lack of a definition of a suitable Indexed Font Resource, for lack of a declaration of ID as the name of an Indexed Font Resource, or from failure to satisfy a font reference as defined in ) RaiseWarning will be invoked with FailureToSatisfyFontReference as its operand.

GetRootFont

The GetRootFont operator takes no operands and returns one result

<indexedfont: DictionaryReference>

where indexedfont is a reference to the Indexed Font Dictionary specified by the current value of the CurrentFont imaging variable (set by the most recent use of the SetFont operator).

GetSelectedFont

The GetSelectedFont operator takes no operands and returns one result

<indexedfont: DictionaryReference>

where indexedfont is a reference to a Indexed Font Dictionary, except during character text imaging, this value shall be the same as that returned by the GetRootFont operator. However, if GetSelectedFont is executed by a Procedure during character text imaging (e.g., as part of a glyph procedure) while the value of the CurrentFont imaging variable is a Composite Font, it shall instead return a reference to the currently selected Base Indexed Font Specification Dictionary. (See .)

OpenFont

The OpenFont operator takes one operand

<indexedfont: DictionaryReference>

and returns one result

<FD: DictionaryReference>

indexedfont shall be a reference to a Indexed Font Dictionary. The returned result FD is a reference to a new, modifiable copy of the Indexed Font Specification Dictionary corresponding to indexedfont.

If the Indexed Font Dictionary referenced by indexedfont has an access attribute of ExecuteOnly or NoAccess, interpreting OpenFont shall cause RaiseError to be invoked with InvalidAccess as its operand.

PutWMode

The PutWMode operator takes two operands

<wm: Cardinal>

<indexedfont1: DictionaryReference>

where wm is the number of a writing mode, and indexedfont1 is a reference to a Indexed Font Dictionary. It returns a single result

<indexedfont2: DictionaryReference>

where indexedfont2 is a reference to the new Indexed Font Dictionary which would be the result of

{indexedfont1 OpenFont Dup <WMode: Cardinal> wm Put DefineFont}

ScaleFont

The ScaleFont operator takes two operands

<sc: Number>

<indexedfont1: DictionaryReference>

where indexedfont1 is a reference to a Indexed Font Dictionary, and returns a single result

<indexedfont2: DictionaryReference>

where indexedfont2 is a reference to the new Indexed Font Dictionary which would be the result of

{indexedfont1 [sc 0 0 sc 0 0] TransformFont}.

TransformFont

The TransformFont operator takes two operands

<T2: Transformation>

<indexedfont1: DictionaryReference>

where indexedfont1 is a reference to a Indexed Font Dictionary, and returns a single result

<indexedfont2: DictionaryReference>

where indexedfont2 is a reference to the new Indexed Font Dictionary.

If indexedfont1 references a Base Font, then indexedfont2 references a new Base Font which would be the result of

  • {indexedfont1 OpenFont Dup Dup
  • /FontMatrixGet
  • /FontMatrixExch
  • T2 ConcatT Put DefineFont}

    If indexedfont1 references a Composite Font, then indexedfont2 references a new Composite Font which, when used for imaging, shall image glyphs as though the above transformation had been applied to each descendant base font. In either case, the value of the associated Transformation is not replaced by T2 but is incrementally modified by concatenation with T2.

    Graphics State Manipulation Operators

    The following operators are used to set and access the CurrentFont Graphics State Variable and the CurrentPoint Graphics State Variable.

    GetPosition

    The GetPosition operator takes no operands and returns two results

    <y: Number>

    <x: Number>

    where {x y SetPosition} would set the value of the Graphics State Variable CurrentPosition to its current value.

    SetFont

    The SetFont operator takes a single operand

    <indexedfont: DictionaryReference>

    where indexedfont is a reference to a Indexed Font Dictionary, and returns no results. It sets the value of the Graphics State Variable CurrentFont to indexedfont.

    SetPosition

    The SetPosition operator takes two operands

    <y: Number>

    <x: Number>

    and returns no results. It sets the value of the Graphics State Variable CurrentPosition to the point whose coordinates are (x, y) in the current User Coordinate System. It begins a new path segment (see ) with a start point and end point of (x, y) in UCS coordinates. If the last path segment of the CurrentPath Graphics State Variable consisted solely of a single point path element; that path segment is deleted and replaced by the new path segment created by the execution of the SetPosition operator.

    SetPositionRelative

    The SetPositionRelative operator takes two operands

    <y: Number>

    <x: Number>

    and returns no results. It changes the value of the Graphics State Variable CurrentPosition from the point whose coordinates are (CPx, CPy) in the current User Coordinate System to the point whose coordinates are (CPx+x, CPy+y). It begins a new path segment (see ) with a start point and end point of (CPx+x, CPy+y) in UCS coordinates. If the last path segment of the CurrentPath Graphics State Variable consisted solely of a single point path element; that path segment is deleted and replaced by the new path segment created by the execution of the SetPositionRelative operator.

    If no CurrentPosition is currently defined, RaiseError shall be invoked with NoCurrentPosition as its operand.

    Character Text Operators

    The following operators are used to present character text.

    ShowGlyph

    The definition of the ShowGlyph imaging operator provides the linkage between the font architecture and the imaging of character text in SPDL. All other operators which image character text are defined in terms of ShowGlyph.

    The imaging operator ShowGlyph takes a single operand

    <glyphid: Identifier>

    and returns no results. The effect of interpreting ShowGlyph depends on the value of the Graphics State Variable CurrentFont.If the value of CurrentFont is a Base Font, indexedfont, then the effect of {glyphid ShowGlyph} is as follows. (A line beginning with a percent sign ('%') is a comment and not part of the Procedure which defines ShowGlyph.)

  • {%First, save the graphics state
  • SaveGraphicsState
  • %Translate UCS so that origin is at CurrentPosition
  • GetPosition Translate
  • %Apply FontMatrix so CurrentTransformation
  • %maps Glyph Coordinate System to RCS
  • GetSelectedFont /FontMatrix Get Concat
  • %Determine writing mode of font and put result on Operand Stack
  • GetRootFont /WMode Known
  • {GetRootFont /WMode Get}
  • {0}
  • IfElse
  • %Do positioning point offset if using alternate writing mode; save initial point
  • SaveGraphicsState
  • Dup 0 NotEqual
  • {Dup 1 Equal
  • {GetSelectedFont /Metrics2 Get}
  • {Dup GetSelectedFont /OtherMetrics Get
  • Exchange 2 Subtract Get}
  • IfElse
  • %Correct metrics DictionaryReference is now on top of stack
  • %Operand Stack has GlyphID WMode MetricsDictRef
  • 2 Index Get
  • Dup 2 Get Negate Exchange 3 Get Negate
  • Translate
  • }
  • If
  • %Image the glyph: with Indexed Font Dictionary on the Context Stack
  • %and in a new Path which avoids interaction with any existing path
  • GetSelectedFont PushContextStack
  • NewPath 1 Index
  • /ConstructGlyph GetValue Execute
  • PopContextStack
  • RestoreGraphicsState
  • %Get escapement metrics using writing mode on top of Operand Stack
  • %to select the correct metrics Dictionary
  • Dup 0 Equal
  • {Pop GetSelectedFont /Metrics Get }
  • {Dup 1 Equal
  • {Pop GetSelectedFont /Metrics Get}
  • {GetSelectedFont /OtherMetrics Get
  • Exchange 2 Subtract Get}
  • IfElse}
  • IfElse
  • %The Operand Stack has: glyphid metricsDictionaryReference
  • %The escapement values are the first two elements of the metrics vector
  • Exchange Get Dup 0 Get Exchange 1 Get
  • %Move CurrentPosition to (Ex, Ey)
  • SetPosition
  • %Restore the graphic state, without nullifying escapement
  • RestoreGraphicsStateXCP
  • }

    If the current font is a Composite Font or is Null, RaiseError shall be invoked with InvalidFont as its operand. If the value of the CurrentPosition Graphics State Variable is undefined, RaiseError shall be invoked with NoCurrentPosition as its operand.

    ShowString

    The imaging operator ShowString takes a single operand

    <s: GlyphString>

    and returns no results. If the OctetString referenced by s is mapped by the Glyph Mapping algorithm to the sequence of glyph specifiers ( (bf1, gid1), (bf2, gid2), . . . . , (bfN, gidN) ), where each bfX is a Base IndexedFont and each gidX is a glyph identifier, then the effect of

    {s ShowString}

    is the same as the execution of

    {bfX SetFont gidX ShowGlyph}

    for each of the glyph specifiers (bfX, gidX) in sequence.

    If the current font is a Base IndexedFont, then all bfX will simply be the current font. If the current font is a Composite IndexedFont, then the use of the SetFont operator is figurative, as GetRootFont shall continue to return the original value of the CurrentFont imaging variable. However, use of GetSelectedFont within any Base Font bfX shall return bfX.

    If the current font is Null, RaiseError shall be invoked with InvalidFont as its operand. If the value of the CurrentPosition Graphics State Variable is undefined, RaiseError shall be invoked with NoCurrentPosition as its operand. If during the execution of the Glyph Mapping algorithms, either a font index or a glyph index is greater than or equal to the Capacity of the Encoding Vector used with that index, or the algorithm fails in any other way, RaiseError shall be invoked with RangeCheck as its operand.

    ShowStringEscapedX

    The imaging operator ShowStringEscapedX takes two operands

    <v: VectorReference>

    <s: GlyphString>

    where v must reference a Vector of Numbers, and have at least as many elements as the number of glyph specifiers derived from the GlyphString s. The operator returns no results.

    If for X = 0, . . . , n

    • (bfX, gidX) is a single glyph specifier derived from the GlyphString s;
    • <vx: Number> is the Xth element of v;
    then the effect of {s v ShowStringEscapedX} is the same as the execution of
  • {SaveGraphicsState
  • bfX SetFont gidX
  • ShowGlyph
  • RestoreGraphicsState
  • vX 0 SetPositionRelative} for X = 0, . . . , n in sequence.

    If the current font is a Base IndexedFont, then all bfX will simply be the current font. If the current font is a Composite IndexedFont, then the use of the SetFont operator is figurative, as GetRootFont shall continue to return the original value of the CurrentFont imaging variable. However, use of GetSelectedFont within any Base Font bfX shall return bfX.

    ShowStringEscapedX shall invoke RaiseError under the same conditions and with the same operands that ShowString shall. In addition, if the Vector of Numbers does not have at least as many elements as the number of glyph specifiers derived from the GlyphString s, then RaiseError shall be invoked with RangeCheck as its operand.

    ShowStringEscapedY

    The imaging operator ShowStringEscapedY takes two operands

    <v: VectorReference>

    <s: GlyphString>

    where v must reference a Vector of Numbers, and have the same number of elements as the number of glyph specifiers derived from the GlyphString s. The operator returns no results.

    If for X = 0, . . . , n

    • (bfX, gidX) is a single glyph specifier derived from the GlyphString s;
    • <vx: Number> is the Xth element of v;
    then the effect of {s v ShowStringEscapedY} is the same as the execution of
  • {SaveGraphicsState
  • bfX SetFont gidX ShowGlyph
  • RestoreGraphicsState
  • 0 vX SetPositionRelative} for X = 0, . . . , n in sequence.

    If the current font is a Base IndexedFont, then all bfX will simply be the current font. If the current font is a Composite IndexedFont then the use of the SetFont operator is figurative, as GetRootFont shall continue to return the original value of the CurrentFont imaging variable. However, use of GetSelectedFont within any Base Font bfX shall return bfX.

    ShowStringEscapedY shall invoke RaiseError under the same conditions and with the same operands that ShowString shall. In addition, if the Vector of Numbers does not have at least as many elements as the number of glyph specifiers derived from the GlyphString s, then RaiseError shall be invoked with RangeCheck as its operand.

    ShowStringEscapedXY

    The imaging operator ShowStringEscapedXY takes two operands

    <v: VectorReference>

    <s: GlyphString>

    where v must reference a Vector of Numbers, and have exactly twice the number of elements as the number of glyph specifiers derived from the GlyphString s. The operator returns no results.

    If for X = 0, . . . , n

    • (bfX, gidX) is a single glyph specifier derived from the GlyphString s;
    • <v2X: Number> and <v2X+1: Number> are respectively the 2Xth and the 2X+1st elements of v,

    then the effect of {s v ShowStringEscapedXY} is the same as the execution of

  • {SaveGraphicsState
  • bfX SetFont gidX ShowGlyph
  • RestoreGraphicsState
  • v2X v2X+1 SetPositionRelative} for X = 0, . . . , n in sequence.

    If the current font is a Base IndexedFont, then all bfX will simply be the current font. If the current font is a Composite IndexedFont then the use of the SetFont operator is figurative, as GetRootFont shall continue to return the original value of the CurrentFont imaging variable. However, use of GetSelectedFont within any Base Font bfX shall return bfX.

    ShowStringEscapedXY shall invoke RaiseError under the same conditions and with the same operands that ShowString shall. In addition, if the Vector of Numbers does not have at least two times as many elements as the number of glyph specifiers derived from the GlyphString s, then RaiseError shall be invoked with RangeCheck as its operand.

    StringWidth

    The operator StringWidth takes a single operand

  • <s: GlyphString> and returns two Numbers.
  • <wy: Number>
  • <wx: Number> where, provided the ShowString imaging is not actually done, wx wy would be the results returned by
  • {
  • SaveGraphicsState
  • % Get current X,Y coordinates
  • GetPosition
  • % Get coordinates after string is shown
  • s ShowString GetPosition
  • % Take difference of Y coordinates
  • 3 -1 Roll Subtract
  • % Take difference of X coordinates
  • 3 1 Roll Exchange Subtract
  • % Put delta X before delta Y on stack
  • Exchange
  • RestoreGraphicsState
  • }

    If the OctetString referenced by s is mapped by the Glyph Mapping algorithm to the sequence of glyph specifiers ( (bf1, gid1), (bf2, gid2), . . . . , (bfN, gidN) ), where each bfX is a Base IndexedFont and each gidX is a glyph identifier, then the effect of

    {s StringWidth}

    is the same as the execution of

    {bfX SetFont gidX ShowGlyph}

    for each of the glyph specifiers (bfX, gidX) in sequence.

    If the current font is a Base IndexedFont, then all bfX will simply be the current font. If the current font is a Composite IndexedFont, then the use of the SetFont operator is figurative, as GetRootFont shall continue to return the original value of the CurrentFont imaging variable. However, use of GetSelectedFont within any Base Font bfX shall return bfX.

    If the current font is Null, RaiseError shall be invoked with InvalidFont as its operand. If during the execution of the Glyph Mapping algorithms, either a font index or a glyph index is greater than or equal to the Capacity of the Encoding Vector used with that index, or the algorithm fails in any other way, RaiseError shall be invoked with RangeCheck as its operand.