Logo Home Page Project Page Download CVS repository
Reading and Writing Setting Defaults Engine and Glyph Info Graphics and Storage Area Other Defaults

The Graphics State and Xgridfit Defaults

The graphics state is a collection of variables that control the behavior of TrueType instructions. These include the round state, vectors, control-value cut-in, minimum distance, single width, auto flip, dropout control, delta shift, delta base, and enable/disable instructions. The graphics state also includes the reference pointers and zone pointers, but it is not recommended that you set these directly in Xgridfit. The uses of the graphics variables are described elsewhere in this documentation: this section describes how the graphics variables are controlled in Xgridfit.

Reading and Writing the Graphics State

The most important graphics variables can be accessed in any of three ways: they can be set via a "set" instruction or a "with" block, and they can be read or set via a special variable.

A "set" instruction simply sets the graphics variable, which remains as set until the end of the glyph program, or until set by another instruction. These are the "set" instructions in Xgridfit:

A "with" block is a block of code enclosed by an element whose name begins "with-": a graphics variable is set before the code in the "with" block is executed, and afterwards is restored to its former state. Example:

    <with-minimum-distance value="0.55">
       <diagonal-stem round="no">
         <line ref="line1"/>
         <line ref="line2"/>

These are the "with" elements in Xgridfit (note that a few "set" elements do not have corresponding "with" elements):

A graphics variable can be read by any instruction that can read variables, and most of them can be written by any instruction that can write to variables. Here is an example of how a graphics variable might be read:

    <with-minimum-distance value="minimum-distance * 0.66">
       <diagonal-stem round="no">
         <line ref="line1"/>
         <line ref="line2"/>

And here is an example of how a graphics variable might be written to:

    <set-equal target="minimum-distance" source="minimum-distance * 0.66"/>

The code above has the same effect as this:

    <set-minimum-distance value="minimum-distance * 0.66"/>

These graphics variables can be both read and written to:

Each of these variables has a "default" variant, e.g. minimum-distance-default, which records the default value, that is, the value the variable has at the beginning of each glyph program. These may be written to only in the <pre-program> (where writing to them sets the default value); but they may be used elsewhere to restore a default value:

    <set-minimum-distance value="minimum-distance-default"/>

There are two graphics variables that relate to the round state: round-state and custom-round-state. These are both read-only: the round state can be set only via <set-round-state> and <with-round-state>. The value of round-state can be tested against these constants:

When round-state = custom, the value of the period, phase and threshold is stored in custom-round-state. The three values are not separated here, as they are in the <round-state> element; rather, the three values are ANDed into a single number, which is more suitable for storage and retrieval than for analysis.

There are two other read-only values in the graphics state: pixels-per-em and point-size. Of these, pixels-per-em tends to be the more useful, and it is often used to decide when to alter the outline at low resolution:

    <if test="pixels-per-em &lt; 20">
      . . .

Setting Defaults

A default value for a graphics variable is the value it has at the beginning of each glyph program. There are two ways to set defaults in Xgridfit: one is simply to place a "set" element anywhere in the <pre-program>. The second, and recommended, method is to include a <default> element in the top level of your program file, thus:

    <default type="minimum-distance" value="0.9">

That is, in the <default> element, the type attribute identifies the graphics default to set, and the value attribute is the value. These types are available for use in <default> elements:

To reset any of these to the default value you have set (or to the TrueType default if you have not set one yourself), pass one of these types to <restore-default>, thus:

    <restore-default name="delta-shift"/>

If you want the TrueType engine to reject all attempts to set defaults (that is, if you want to use only the defaults that are standard for TrueType), include this:

    <default type="use-truetype-defaults" value="yes"/>

The result will be that "set" instructions encountered in the <pre-program> will not set defaults, and <default> elements that set the graphics state will be ignored.

Getting Information about the Engine and Glyph

You can get a limited amount of information about the TrueType engine. These read-only values are available for use in such contexts as <if> elements and expressions:

You can also get information about the current glyph, which may influence whether or how to write instructions:

The Graphics State and the Storage Area

Most TrueType graphics variables are write-only; that is, the TrueType engine provides no instructions for determining their current values. Xgridfit tracks the values of graphics variables by using several reserved locations in the TrueType storage area--the same area that is used to store variables. In order to make sure that this system functions correctly, you should take the following precautions:

Other Defaults

Several important defaults other than those relating to the graphics state are also controlled with <default> elements in the top level of your program file. These set values in the TrueType maxp table or control aspects of the Xgridfit compiler's behavior: