メインコンテンツまでスキップ

Requests: Fonts

OpenFont​

fid: FONT
name: STRING8
Errors: IDChoice, Name, Alloc

Loads the specified font, if necessary, and associates identifier fid with it. The font can be used as a source for any drawable. The font name should use the ASCII encoding, and upper/lower case does not matter.

CloseFont​

font: FONT
Errors: Font

Deletes the association between the resource id and the font. The font itself will be freed when no other resource references it.

QueryFont​

font: FONT or GCONTEXT

=>

font-info: FONTINFO
char-infos: LISTofCHARINFO

where

FONTINFO: [draw-direction: {LeftToRight, RightToLeft}
min-char-or-byte2,max-char-or-byte2:CARD16
min-byte1, max-byte1: CARD8
all-chars-exist: BOOL
default-char: CARD16
min-bounds: CHARINFO
max-bounds: CHARINFO
font-ascent: INT16
font-descent: INT16
properties: LISTofFONTPROP]
FONTPROP: [name: ATOM
value: INT32 or CARD32]
CHARINFO: [left-side-bearing: INT16
right-side-bearing: INT16
character-width: INT16
ascent: INT16
descent: INT16
attributes: CARD16]
Errors: Font

Returns logical information about a font.

The draw-direction is essentially just a hint, indicating whether most char-infos have a positive (LeftToRight) or a negative (RightToLeft) character-width metric. The core protocol defines no support for vertical text.

If min-byte1 and max-byte1 are both zero, then min-char-or-byte2 specifies the linear character index corresponding to the first elementb of char-infos, and max-char-or-byte2 specifies the linear character index of the last element. If either min-byte1 or max-byte1 are non-zero, then both min-char-or-byte2 and max-char-or-byte2 will be less than 256, and the two-byte character index values corresponding to char-infos element N (counting from 0) are

byte1 = N/D + min-byte1
byte2 = N\D + min-char-or-byte2

where

D = max-char-or-byte2 - min-char-or-byte2 + 1
/ = integer division
\ = integer modulus

If char-infos has length zero, then min-bounds and max-bounds will be identical, and the effective char-infos is one filled with this char-info, of length

L = D * (max-byte1 - min-byte1 + 1)

That is, all glyphs in the specified linear or matrix range have the same information, as given by min-bounds (and max-bounds). If all-chars-exist is True, then all characters in char-infos have non-zero bounding boxes.

The default-char specifies the character that will be used when an undefined or non-existent character is used. Note that default-char is a CARD16 (not CHAR2B); for a font using two-byte matrix format, the default-char has byte1 in the most significant byte, and byte2 in the least significant byte. If the default-char itself specifies an undefined or non-existent character, then no printing is performed for an undefined or non-existent character.

The min-bounds and max-bounds contain the minimum and maximum values of each individual CHARINFO component over all char-infos (ignoring non-existent characters). The bounding box of the font, i.e., the smallest rectangle enclosing the shape obtained by superimposing all characters at the same origin [x,y], has its upper left coordinate at [x + min-bounds.left-side-bearing, y - max-bounds.

ascent] with a width of

max-bounds.right-side-bearing - min-bounds.

left-side-bearing and a height of

max-bounds.ascent + max-bounds.descent The font-ascent is the logical extent of the font above the baseline, for determining line spacing. Specific characters may extend beyond this. The font-descent is the logical extent of the font at or below the baseline, for determining line spacing. Specific characters may extend beyond this. If the baseline is at Y-coordinate y, then the logical extent of the font is inclusive between the Y-coordinate values (y - font-ascent) and (y + font-descent - 1).

A font is not guaranteed to have any properties. Whether a property value is signed or unsigned must be derived from a prior knowledge of the property. When possible, fonts should have at least the following properties (note that the trailing colon is not part of the name, and that upper/lower case matters).

MIN_SPACE: CARD32

The minimum interword spacing, in pixels.

NORM_SPACE: CARD32
The normal interword spacing, in pixels.
MAX_SPACE: CARD32
The maximum interword spacing, in pixels
SUBSCRIPT_X: INT32
SUBSCRIPT_Y: INT32
Offsets from the character origin where subscripts
should begin, in pixels. If the origin is at [x,y],
then subscripts should begin at [x + SubscriptX,
y + SubscriptY].
UNDERLINE_POSITION: INT32
Y offset from the baseline to the top of an underline,
in pixels. If the baseline is Y-coordinate y, then
the top of the underline is at (y +
UnderlinePosition).
UNDERLINE_THICKNESS: CARD32
Thickness of the underline, in pixels.
STRIKEOUT_ASCENT: INT32
STRIKEOUT_DESCENT: INT32
Vertical extents for boxing or voiding characters, in
pixels. If the baseline is at Y-coordinate y, then
the top of the strikeout box is at (y -
StrikeoutAscent), and the height of the box is
(StrikeoutAscent + StrikeoutDescent).
ITALIC_ANGLE: INT32
The angle of characters in the font, in degrees
    scaled by 64, relative to the three-oclock position
from the character origin, with positive indicating
counterclockwise motion (as in Arc requests).
X_HEIGHT: INT32
"1 ex" as in TeX, but expressed in units of pixels.
Often the height of lowercase x.
QUAD_WIDTH: INT32
"1 em" as in TeX, but expressed in units of pixels.
Often the width of the digits 0-9.
WEIGHT: CARD32
The weight or boldness of the font, expressed as a
value between 0 and 1000.
POINT_SIZE: CARD32
The point size, expressed in 1/10ths, of this font at
the ideal resolution. There are 72.27 points to the
inch.
RESOLUTION: CARD32
The number of pixels per point, expressed in 1/100ths,
at which this font was created.

For a character origin at [x,y], the bounding box of a character,i.e., the smallest rectangle enclosing the character's shape, described in terms of CHARINFO components, is a rectangle with its upper left corner at

[x + left-side-bearing, y - ascent]

with a width of

right-side-bearing - left-side-bearing

and a height of

ascent + descent

and the origin for the next character is defined to be

[x + character-width, y]

Note that the baseline is logically viewed as being just below non-descending characters (when descent is zero, only pixels with Y-coordinates less than y are drawn), and that the origin is logically viewed as being coincident with the left edge of a non-kerned character (when left-side-bearing is zero, no pixels with X-coordinate less than x are drawn).

Note that CHARINFO metric values can be negative.

A non-existent character is represented with all CHARINFO components zero.

The interpretation of the per-character attributes field is undefined by the core protocol.

QueryTextExtents​

font: FONT or GCONTEXT
items: STRING16

=>

draw-direction: {LeftToRight, RightToLeft}
font-ascent: INT16
font-descent: INT16
overall-ascent: INT16
overall-descent: INT16
overall-width: INT32
overall-left: INT32
overall-right: INT32
Errors: Font

Returns the logical extents of the specified string of characters in the specified font. Draw-direction, font-ascent, and font-descent are as described in QueryFont. Overall-ascent is the maximum of the ascent metrics of all characters in the string, and overall-descent is the maximum of the descent metrics. Overall-width is the sum of the character-width metrics of all characters in the string. For each character in the string, let W be the sum of the character-width metrics of all characters preceding it in the string, let L be the left-side-bearing metric of the character plus W, and let R be the right-side-bearing metric of the character plus W. Overall-left is the minimum L of all characters in the string, and overall-right is the maximum R.

For fonts defined with linear indexing rather than two-byte matrix indexing, the server will interpret each CHAR2B as a 16-bit number that has been transmitted most significant byte first (i.e., byte1 of the CHAR2B is taken as the most significant byte).

If the font has no defined default-char, then undefined characters in the string are taken to have all zero metrics.

ListFonts​

pattern: STRING8
max-names: CARD16

=>

names: LISTofSTRING8

Returns a list of length at most max-names, of names of fonts matching the pattern. The pattern should use the ASCII encoding, and upper/lower case does not matter. In the pattern, the '?' character (octal value 77) will match any single character, and the character '*' (octal value 52) will match any number of characters. The returned names are in lower case.

ListFontsWithInfo​

pattern: STRING8
max-names: CARD16

=>

fonts: LISTofFONTDATA

where

FONTDATA: [name: STRING8
info: FONTINFO]
FONTINFO: <same type definition as in QueryFont>

Like ListFonts, but also returns information about each font. The information returned for each font is identical to what QueryFont would return (except that the per-character metrics are not returned).

SetFontPath​

path: LISTofSTRING8
Errors: Value

Defines the search path for font lookup. There is only one search path per server, not one per client. The interpretation of the strings is operating system dependent, but they are intended to specify directories to be searched in the order listed.

Setting the path to the empty list restores the default path defined for the server.

As a side-effect of executing this request, the server is guaranteed to flush all cached information about fonts for which there currently are no explicit resource ids allocated.

The meaning of an error from this request is system specific.

GetFontPath​

=>

path: LISTofSTRING8

Returns the current search path for fonts.