HP XLFD Enhancements to Support Typographic Effects Nathan Meyers, Hewlett-Packard Company nathanm@cv.hp.com July 13, 1992 ANNOUNCEMENT ------------ Hewlett-Packard Company has donated a collection of font server enhancements to the X Consortium for distribution as contributed software. The enhancements add a set of useful typographic capabilities to scalable fonts in X, without requiring any changes to the X or the F (font server) protocol. The enhancements are intended to serve applications that require certain limited typographic capabilities, but do not need the full (and as yet undefined) typographic extension. Capabilities supported by the enhancements are font rotation, artificial obliquing (changing glyph slant), anamorphic scaling, and mirroring. Applications using the enhancements can render text at any angle, and can create many variations on a scalable font by employing the new transformations. The enhancements are accessed via backward-compatible extensions to the XLFD (X Logical Font Description) naming semantics, and do not require any changes or extensions to the existing client/server communications protocol. While the enhancements provide access to a set of useful typographic effects, they are not intended to serve as a substitute for the X typographic extension. Many issues that must be addressed by the typographic extension, such as kerning, subpixel positioning, anti- aliasing, scalable metrics, and warping, are not addressed by these enhancements. Rather, these enhancements are intended to serve the large class of applications that need more capable text rendering but do not need advanced typographic capabilities. DESCRIPTION ----------- This article provides a brief description of the HP XLFD enhancements. The reader is referred to the Summer, 1992 issue of "The X Resource" journal for more detail. The full list of font enhancements supported by the HP XLFD enhancements is: Artificial obliquing Glyph rotation Anamorphic scaling Mirroring Artificial emboldening/lightening Charset subsetting performance hint Most of these capabilities are easily obtained with most rasterizers; the XLFD enhancements simply provide a mechanism with which to ask for them. This portion of the document describes the enhancements and how they are accessed through the font's XLFD name. For purposes of illustration, we start with a basic, unenhanced font named: -adobe-utopia-medium-r-normal--*-120-100-100-p-*-iso8859-1 ARTIFICIAL OBLIQUING -------------------- Obliquing is the ability to change the slant of a font -- creating, for example, an italic-appearing font from a roman font. The obliquing enhancement allows the font to be slanted up to 45 degrees in the clockwise (oblique) or counterclockwise (reverse oblique) direction. Obliquing is specified as a numeric enhancement to the slant field. Positive numbers (preceded by '+') specify counterclockwise obliquing, negative numbers (preceded by '_') specify clockwise obliquing. Numbers are interpreted as 64ths of a degree. For example: -adobe-utopia-medium-r+1920-normal--*-120-100-100-p-*-iso8859-1 -adobe-utopia-medium-r_1280-normal--*-120-100-100-p-*-iso8859-1 The first example creates glyphs obliqued counterclockwise by 30 degrees; the second creates glyphs obliqued clockwise by 20 degrees. GLYPH ROTATION -------------- Glyphs can be rotated to any arbitrary angle around the glyph origin. Rotated glyphs can subsequently be used to render text at an angle -- later sections of this document discuss the techniques for doing this. Rotation angles are specified as a numeric enhancement to the AddStyle field; positive values ('+') specify counterclockwise rotation, negative values ('_') specify clockwise rotation. Angles are specified in 64ths of a degree. For example: -adobe-utopia-medium-r-normal-+2880-*-120-100-100-p-*-iso8859-1 -adobe-utopia-medium-r-normal-_5760-*-120-100-100-p-*-iso8859-1 -adobe-utopia-medium-r-normal-+11520-*-120-100-100-p-*-iso8859-1 The first example creates glyphs rotated 45 degrees counterclockwise, useful for writing text at a 45-degree angle (from southwest to northeast); the second example creates glyphs rotated 90 degrees clockwise; the third example creates glyphs rotated a full 180 degrees. As with unrotated glyphs, the character escapement is crucial to determining glyph placement. With a rotated glyph, the escapement is interpreted as applying *in the direction of rotation* -- in other words, escapement is unaffected (give or take roundoff) by rotation. Ideally, X would return horizontal and vertical components of character escapement. Since the protocol cannot accommodate that, it provides an absolute escapement, and leaves the client to compute the horizontal and vertical components (this is illustrated below in the section on rendering of rotated fonts). ANAMORPHIC SCALING ------------------ Traditionally, anamorphic scaling has been achieved by playing with the X- and Y-resolution values in the font name. This approach fails when other transformations, such as rotation, are added (for example, a tall, skinny font can be obtained by doubling the Y-resolution; but it will transmute into a short, fat font when rotated 90 degrees). Hence the need to support anamorphic scaling with an XLFD enhancement. Anamorphic scaling is specified via enhancements to the pointsize and pixelsize field. When anamorphic scaling is requested, the numbers in these fields are broken into two components -- vertical and horizontal -- separated by '+'. For example: -adobe-utopia-medium-r-normal--*-180+120-100-100-p-*-iso8859-1 specifies a font with a pointsize of 18 and a setsize of 12 (i.e., width appropriate for a 12-point-high font). A similar enhancement can be used in the pixelsize field: -adobe-utopia-medium-r-normal--30+20-*-100-100-p-*-iso8859-1 If both pointsizes and pixelsizes are specified, the font server verifies that they are consistent. MIRRORING --------- Fonts can be mirrored in the X and/or Y direction. These enhancements are specified with the strings "+mx" and "+my" in the AddStyle field: -adobe-utopia-medium-r-normal-+mx-*-120-100-100-p-*-iso8859-1 -adobe-utopia-medium-r-normal-+my-*-120-100-100-p-*-iso8859-1 -adobe-utopia-medium-r-normal-+mx+my-*-120-100-100-p-*-iso8859-1 X-mirroring does not change the escapement (the escapement does not change sign), and the reflection occurs around the horizontal center of the glyph. Y-mirroring reflects the character across the baseline. EMBOLDENING/LIGHTENING ---------------------- This XLFD enhancement is provided to support rasterizers that can artificially embolden or lighten glyphs. At this time, none of the donated rasterizers in the Font Server can do this. A font can be artificially emboldened or lightened by specifying a numeric enhancement to the weight field. Numbers are specified as positive (preceded by '+') for emboldening, and negative (preceded by '_') for lightening. The number is interpreted in 100ths of a percent: a positive number emboldens by a factor of , a negative number emboldens by a factor of (1 - ||). Examples: -adobe-utopia-medium+5000-r-normal--*-120-100-100-p-*-iso8859-1 -adobe-utopia-medium_2500-r-normal--*-120-100-100-p-*-iso8859-1 In the first example, the font is emboldened to 150% of normal boldness; in the second, it is lightened to 75% of normal boldness. If two numbers are specified, the first is horizontal emboldening, the second is vertical. For example: -adobe-utopia-medium+5000_2000-r-normal--*-120-100-100-p-*-iso8859-1 specifies emboldening in the horizontal direction and lightening in the vertical direction. CHARSET SUBSETTING PERFORMANCE HINT ----------------------------------- We expect that many applications taking advantage of the XLFD enhancements will be interested in rendering just a few characters from a particular font. Unfortunately, the overhead of opening scalable fonts, even to access just a few glyphs, can be quite high. Many vendors do not support glyph cacheing, and a number of factors conspire to make any future implementation of glyph cacheing very difficult. This enhancement addresses this performance problem. For clients that know exactly what glyphs they will need from a particular font, charset subsetting allows them to pass this information as a performance hint to the rasterizer. Charset subsetting is specified as a list of character codes appended to the end of the XLFD name thus: -adobe-utopia-medium-r-normal--*-120-100-100-p-*-iso8859-1=65,67 This informs the rasterizer that the client intends only to use characters 65 and 67 ('A' and 'C'); the rasterizer can choose to use this information to realize a font containing only the glyphs for those characters. Ranges can be specified with the ':' character. For example: -adobe-utopia-medium-r-normal--*-120-100-100-p-*-iso8859-1=65:70,48:57 specifies that the client is interested in characters 65-70 ('A' through 'F') and 48-57 ('0' through '9'). ORDER OF ENHANCEMENTS --------------------- The enhancements are applied to the glyphs in the following order: Emboldening Anamorphic Scaling Obliquing Rotation Mirroring The ordering between scaling, obliquing, and rotation is particularly important: it ensures that the "custom font" created by applying the first two transformations has the same appearance regardless of rotation angle. RENDERING OF ROTATED FONTS -------------------------- Most of the enhancements are simply used to create new forms of a particular font, and do not present any unusual challenges with regard to rendering. Rotated fonts are the exception: there is no Xlib support for non-horizontal rendering; new techniques are needed. The XDrawRotatedString() utility, provided with the enhancements in a separate collection of utilities, does the necessary work to draw text at any angle. The utility is usable as is, or can be optimized for use in clients that need non-horizontal text (comments in the source discuss the opportunities for optimization). BUGS ---- No known bugs at this time. DESCRIPTION OF THE CONTRIBUTION ------------------------------- The contribution consists of patches for 19 files: 18 fontlib source files and an Imakefile. Some patches provide for the XLFD enhancements, others are for Font Server bugs exposed by the enhancements (the latter have been submitted in bug reports to MIT). The patches apply to the following areas: Patches in the fontfile, fc, and util directories to support the XLFD extensions. Patches in the Type 1 rasterizer to support all of the enhancements except emboldening. Patches in the Speedo rasterizer to support all of the enhancements except emboldening. (Much thanks to Dave Lemke at NCD for help with this contribution). Patches in the bitmap scaler to support all of the enhancements except emboldening. The enhancements are provided by Hewlett-Packard as contributed software, and are not maintained by the X Consortium. We will periodically update the patches to reflect fixes in the enhancements as well as fixes in the font server. If you wish to be notified when new patches are released, please send me your e-mail address. We donate this code in the belief that it provides a useful function that meets a real need. We believe the code to be healthy and robust, but must include the customary disclaimer: THE HP XLFD ENHANCEMENTS ARE PROVIDED "AS IS", WITHOUT ANY WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED. IN NO EVENT SHALL HEWLETT-PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THESE ENHANCEMENTS. HISTORY ------- Feb 24, 1992: First donation of HP XLFD enhancements. Jul 13, 1992: Update of the HP XLFD enhancements donation, coincident with publication in the Summer, 1992 issue of "The X Resource". Includes new support for XLFD enhancements to scaled bitmap fonts. ----------------- Nathan Meyers nathanm@cv.hp.com