comparison man/internals/internals.texi @ 2736:40dc584fce16

[xemacs-hg @ 2005-04-18 03:59:48 by stephent] add Xft LISP docs, minor updates <87mzrw4uft.fsf@tleepslib.sk.tsukuba.ac.jp>
author stephent
date Mon, 18 Apr 2005 04:00:10 +0000
parents 980ce20b8504
children a25c824ed558
comparison
equal deleted inserted replaced
2735:aca6bc1933a1 2736:40dc584fce16
23982 @menu 23982 @menu
23983 * Better Rendering Support -- Review Criteria:: 23983 * Better Rendering Support -- Review Criteria::
23984 * Better Rendering Support -- Implementation:: 23984 * Better Rendering Support -- Implementation::
23985 * Better Rendering Support -- Current Status:: 23985 * Better Rendering Support -- Current Status::
23986 * Better Rendering Support -- Configuration with the Interim Patches:: 23986 * Better Rendering Support -- Configuration with the Interim Patches::
23987 * Better Rendering Support -- Modern Font Support::
23987 @end menu 23988 @end menu
23988 23989
23989 23990
23990 @node Better Rendering Support -- Review Criteria, Better Rendering Support -- Implementation, , Future Work -- Better Rendering Support 23991 @node Better Rendering Support -- Review Criteria, Better Rendering Support -- Implementation, , Future Work -- Better Rendering Support
23991 @subsection Better Rendering Support -- Review Criteria 23992 @subsection Better Rendering Support -- Review Criteria
24247 24248
24248 I think this is probably an Xft bug, but I'm not sure. 24249 I think this is probably an Xft bug, but I'm not sure.
24249 @end table 24250 @end table
24250 24251
24251 24252
24252 @node Better Rendering Support -- Configuration with the Interim Patches, , Better Rendering Support -- Current Status, Future Work -- Better Rendering Support 24253 @node Better Rendering Support -- Configuration with the Interim Patches, Better Rendering Support -- Modern Font Support, Better Rendering Support -- Current Status, Future Work -- Better Rendering Support
24253 @subsection Better Rendering Support -- Configuration with the Interim Patches 24254 @subsection Better Rendering Support -- Configuration with the Interim Patches
24254 @cindex better rendering support, configuration with the interim patches 24255 @cindex better rendering support, configuration with the interim patches
24255 @cindex configuration with the interim patches, better rendering support 24256 @cindex configuration with the interim patches, better rendering support
24256 24257
24257 For Stephen's @samp{sjt-xft} branch, you should keep the following in 24258 For Stephen's @samp{sjt-xft} branch, you should keep the following in
24325 allows a lot more text to fit there. (Previously the font sizes were 24326 allows a lot more text to fit there. (Previously the font sizes were
24326 quite varied, and there was a comment that this weirdness gave good 24327 quite varied, and there was a comment that this weirdness gave good
24327 balance. This isn't true on my main platform, Mac OS X, and needs to be 24328 balance. This isn't true on my main platform, Mac OS X, and needs to be
24328 rechecked on Linux, where it was observed.) 24329 rechecked on Linux, where it was observed.)
24329 @end itemize 24330 @end itemize
24331
24332
24333
24334 @node Better Rendering Support -- Modern Font Support, , Better Rendering Support -- Configuration with the Interim Patches, Future Work -- Better Rendering Support
24335 @subsection Better Rendering Support -- Modern Font Support
24336
24337 @c Maybe eventually all these @cindexes should be spread about?
24338 @cindex fonts
24339 @cindex fonts, scalable
24340 @cindex fonts, antialiased
24341 @cindex fonts, TrueType
24342 @cindex fonts, OpenType
24343 @cindex fonts, Type1
24344 @cindex TrueType fonts
24345 @cindex OpenType fonts
24346 @cindex Type1 fonts
24347 @cindex antialiasing
24348 @cindex Xft
24349 @cindex fontconfig
24350
24351 @strong{NB: This subtree eventually needs to be moved to the Lispref.}
24352
24353 This chapter describes integration of the @file{Xft} font support
24354 library into XEmacs. This library is a layer over the separate
24355 @file{FreeType} rendering engine and @file{fontconfig} font query and
24356 selection libraries. @file{FreeType} provides rendering facilities for
24357 modern, good-looking TrueType fonts with hinting and antialiasing, while
24358 @file{fontconfig} provides a coherent interface to font query and
24359 selection which is independent of the rendering engine, although
24360 currently it is only used in @file{Xft} to interface to @file{FreeType}.
24361
24362 From the user's point of view, @file{fontconfig} provides a naming
24363 convention which is @emph{precise}, @emph{accurate}, and
24364 @emph{convenient}. Precision means that all properties available in the
24365 programming API can be individually specified. Accuracy means that the
24366 truename of the font is exactly the list of all properties specified by
24367 the font. Thus, the anomolies that occur with XLFDs on many servers
24368 (including modern Linux distributions with XFree86 or X.org servers)
24369 cannot occur. Convenience is subjective, of course. However,
24370 @file{fontconfig} provides a configuration system which (1) explicitly
24371 specifies the defaults and substitutions that will be made in processing
24372 user queries, and (2) allows the user to specify search configuration,
24373 abbreviations, substitutions, and defaults that override the system's,
24374 in the same format as used by system files. Further, a @dfn{standard
24375 minimal configuration} is defined that ensures that at least
24376 @emph{serif}, @emph{sans-serif}, and @emph{monospace} fonts are
24377 available on all @file{fontconfig} systems.
24378
24379 @menu
24380 * Modern Font Support -- Font Concepts:: GUI devices, fonts, glyphs, rendering.
24381 * Modern Font Support -- fontconfig:: Querying and selecting fonts.
24382 * Modern Font Support -- Xft:: Rendering fonts on X11.
24383 @end menu
24384
24385 @node Modern Font Support -- Font Concepts, Modern Font Support -- fontconfig, , Better Rendering Support -- Modern Font Support
24386 @subsubsection Modern Font Support -- Font Concepts
24387
24388 In modern systems, displays are invariably @dfn{raster graphic devices},
24389 which present an abstract interface of @dfn{pixel array} where each
24390 @dfn{pixel value} is a color, and each pixel is individually mutable,
24391 and (usually) readable. In XEmacs, such devices are collectively called
24392 @dfn{GUI devices}, as opposed to @dfn{TTY devices} which are character
24393 stream devices but may support control sequences for setting the color
24394 of individual characters, and the insertion position in a rectangular
24395 array. Here we are concerned only with control of GUI devices but use
24396 TTY devices as a standard for comparison.
24397
24398 A @dfn{font} is an indexed collection of @dfn{glyphs}, which are
24399 specifications of character shapes. On a TTY device, these shapes are
24400 entirely abstract, and the index is the identity function. Typically
24401 fonts are embedded in TTY devices, the user has no control over the font
24402 from within the application, and where choice is available, there is
24403 limited selection, and no extensibility. Simple, functional, and
24404 ... ugly.
24405
24406 On GUI devices, the situation is different in every respect. Glyphs may
24407 be provided by the device, the application, or the user. Additional
24408 glyphs may be added at will at any of those levels. Arbitrary index
24409 functions allow the same glyph to be used to display characters in
24410 different languages or using application-specific codes. Glyphs have
24411 concrete APIs, allowing fine control of rendering parameters, even
24412 user-specified shapes. To provide convenient, consistent handling of
24413 collections of glyphs, we need a well-defined font API.
24414
24415 We can separate the necessary properties into two types: properties
24416 which are common to all glyphs in the collection or a property of the
24417 collection itself, and those which are glyph-specific. Henceforth, the
24418 former are called @dfn{font properties} and the latter @dfn{glyph
24419 properties}.
24420
24421 Font properties include identification like the font @dfn{family},
24422 font-wide design parameters like @dfn{slant} and @dfn{weight}, font
24423 @dfn{metrics} like @dfn{size} (nominal height) and @dfn{average width}
24424 used for approximate layout (such as sizing a popup dialog), and
24425 properties like the @dfn{default glyph} that are associated with the
24426 font for convenient use by APIs, but aren't really an intrinsic property
24427 of the font as a collection of glyphs. There may also be a @dfn{kerning
24428 table} (used to improve spacing of adjacent glyphs).
24429
24430 Glyph properties include the @dfn{index}, glyph metrics such as
24431 @dfn{ascent}, @dfn{descent}, @dfn{width}, @dfn{offset} (the offset to
24432 the normal position of the next glyph), @dfn{italic correction} (used to
24433 improve spacing when slanted and unslanted glyphs are juxtaposed). Most
24434 important, of course, is the glyph's shape, which is provided in a
24435 format specific to a rendering engine. Common formats include bitmaps
24436 (X11 BDF), Postcript programs (Type 1), and collections of spline curves
24437 (TrueType). When the shape is not itself a bitmap, it must be
24438 @dfn{rendered} to a pixmap, either a region on the display or a separate
24439 object which is copied to the display. In that case, the shape may
24440 include ``multiple masters'' or ``hints'' to allow context-specific
24441 rendering which improves the appearance of the glyph on the display.
24442
24443 Note that this use of ``glyph'' is mostly independent of the XEmacs LISP
24444 glyph API. @ref{Glyphs}. It is possible to extract a single glyph from
24445 a font and encapsulate it in Lisp_Glyph object, but the LISP glyph API
24446 allows access to only a very few glyph properties, none of them related
24447 to the rendering process.
24448
24449 XEmacs LISP does provide an API for selecting and querying fonts, in the
24450 form of a fairly complete set of wrappers for @file{fontconfig}
24451 (@pxref{Modern Font Support -- fontconfig}). It also provides some
24452 control of rendering of text via wrappers for @file{Xft} APIs
24453 (@pxref{Modern Font Support -- Xft}), but this API is quite incomplete.
24454 Also, since the font selection and query facilities of @file{Xft} are
24455 provided by @file{fontconfig}, there is some confusion in the API. For
24456 example, use of antialiasing to improve the appearance of rendered
24457 glyphs can be enabled or disabled. The API for this is to set the
24458 @file{fontconfig} font property @code{antialias} on the font. However,
24459 from the point of view of @file{fontconfig} this is merely a hint that
24460 the rendering engine may or may not respect. This property cannot be
24461 used to select only fonts suitable for being antialiased, for example.
24462 And @code{rgba} (subpixel geometry) and @code{dpi} (pixel density) are
24463 conceptually properties of the display, not of either the font. They
24464 function as hints to the rendering process.
24465
24466 As a final confusing touch, @file{Xft} also provides some access to the
24467 @file{XRender} extension provided by some modern X servers. This is
24468 mostly limited to colors, but rectangle APIs are also provided. These
24469 are (of course) completely independent of fonts, but @file{Xft} is
24470 designed for client-side font rendering, and thus uses the
24471 @file{XRender} extension heavily.
24472
24473
24474 @node Modern Font Support -- fontconfig, Modern Font Support -- Xft, Modern Font Support -- Font Concepts, Better Rendering Support -- Modern Font Support
24475 @subsubsection Modern Font Support -- fontconfig
24476
24477 @cindex fontconfig API
24478 @cindex API, fontconfig
24479 @cindex fonts, configuring
24480 @cindex configuring fonts
24481 @cindex fonts, selecting
24482 @cindex selecting fonts
24483 @cindex fonts, querying
24484 @cindex querying fonts
24485
24486 @emph{Implementation notes}: The functions which initialize the library
24487 and handle memory management (@emph{e.g.}, @code{FcInit} and
24488 @code{FcPatternDestroy}) are intentionally not wrapped (in the latter
24489 case, @code{fc-pattern-destroy} was provided, but this was
24490 ill-considered and will be removed; LISP code should @strong{never} call
24491 this function). Thinking about some of the auxiliary constructs used by
24492 @file{fontconfig} is in transition. The @code{FcObjectSet} API has been
24493 internalized; it is exposed to LISP as a list of strings. The
24494 @code{FcFontSet} API is still in use, but it also will be internalized,
24495 probably as a list (alternatively, vector) of @code{Lisp_fc_pattern}
24496 objects. Changing the representation of @file{fontconfig} objects
24497 (property names) from LISP strings to keywords is under consideration.
24498
24499 If @file{Xft} (including @file{fontconfig}) support is integrated into
24500 the XEmacs build, XEmacs provides the symbol @code{xft} at
24501 initialization.
24502
24503 XEmacs provides the following functions wrapping the @file{fontconfig}
24504 library API.
24505
24506 @defun fc-fontset-p object
24507
24508 Returns t if @var{object} is of type fc-fontset, nil otherwise.
24509 @emph{This API is likely to be removed in the near future.}
24510 @end defun
24511
24512 @defun fc-fontset-count fcfontset
24513
24514 Counts the number of fc pattern objects stored in the fc fontset object
24515 @var{fcfontset}. @emph{This API is likely to be removed in the near
24516 future.}
24517 @end defun
24518
24519 @defun fc-fontset-ref fcfontset i
24520
24521 Return the fc pattern object at index @var{i} in fc fontset object
24522 @var{fcfontset}. Return nil if the index exceeds the bounds of
24523 @var{fcfontset}. @emph{This API is likely to be removed in the near
24524 future.}
24525 @end defun
24526
24527 @defun fc-fontset-destroy fcfontset
24528
24529 Explicitly deallocate @var{fcfontset}. @emph{Do not call this function
24530 from LISP code. You will crash. This API will be removed in the near
24531 future.}
24532 @end defun
24533
24534 @defun fc-pattern-p object
24535
24536 Returns t if @var{object} is of type fc-pattern, nil otherwise.
24537 @end defun
24538
24539 @defun fc-pattern-create
24540
24541 Return a fresh and empty fc-pattern object.
24542 @end defun
24543
24544 @defun fc-name-parse name
24545
24546 Parse string @var{name} as a fontconfig font name and return its
24547 representation as a fc pattern object.
24548 @end defun
24549
24550 @defun fc-name-unparse pattern
24551
24552 Unparse pattern object @var{pattern} to a string.
24553 @end defun
24554
24555 @file{Xft}'s similar function is actually a different API. We provide
24556 both for now. (They probably invoke the same code from
24557 @file{fontconfig} internally, but the @file{fontconfig} implementation
24558 is more conveniently called from C.)
24559
24560 @defun xft-name-unparse pattern
24561
24562 Unparse pattern object @var{pattern} to a string (using the @file{Xft}
24563 API).
24564 @end defun
24565
24566 @defun fc-pattern-duplicate pattern
24567
24568 Make a copy of pattern object @var{pattern} and return it.
24569 @end defun
24570
24571 @defun fc-pattern-add pattern property value
24572
24573 Add attributes to the pattern object @var{pattern}. @var{property} is a
24574 string naming the attribute to add, @var{value} the value for this attribute.
24575
24576 @var{value} may be a string, integer, float, or symbol, in which case
24577 the value will be added as an FcChar8[], int, double, or FcBool
24578 respectively.
24579 @end defun
24580
24581 @defun fc-pattern-del pattern, property
24582
24583 Remove attribute @var{property} from pattern object @var{pattern}.
24584 @end defun
24585
24586 This is the generic interface to @code{FcPatternGet}.
24587 We don't support the losing symbol-for-property interface. However, it
24588 might be a very good idea to use keywords for property names in LISP.
24589
24590 @defun fc-pattern-get pattern property &optional id type
24591
24592 From @var{pattern}, extract @var{property} for the @var{id}'th member, of
24593 type @var{type}.
24594
24595 @var{pattern} is an @file{Xft} (@file{fontconfig}) pattern object.
24596 @var{property} is a string naming a @file{fontconfig} font property.
24597 Optional @var{id} is a nonnegative integer indexing the list of values
24598 for @var{property} stored in @var{pattern}, defaulting to 0 (the first
24599 value).
24600 Optional @var{type} is a symbol, one of 'string, 'boolean, 'integer, 'float,
24601 'double, 'matrix, 'charset, or 'void, corresponding to the FcValue types.
24602 ('float is an alias for 'double).
24603
24604 Symbols with names of the form @samp{fc-result-@var{DESCRIPTION}} are
24605 returned when the desired value is not available. These are
24606
24607 @example
24608 fc-result-type-mismatch the value found has an unexpected type
24609 fc-result-no-match there is no such attribute
24610 fc-result-no-id there is no value for the requested ID
24611 @end example
24612 @end defun
24613
24614 The Lisp types returned will conform to @var{type}:
24615
24616 @example
24617 string string
24618 boolean `t' or `nil'
24619 integer integer
24620 double (float) float
24621 matrix not implemented
24622 charset not implemented
24623 void not implemented
24624 @end example
24625
24626 The types of the following standard properties are predefined by
24627 fontconfig. The symbol 'fc-result-type-mismatch will be returned if the
24628 object exists but @var{type} does not match the predefined type. It is
24629 best not to specify a type for predefined properties, as a mistake here
24630 ensures error returns on the correct type.
24631
24632 Each standard property has a convenience accessor defined in
24633 @file{fontconfig.el}, named in the form
24634 @samp{fc-pattern-get-@var{property}}. The convenience functions are
24635 preferred to @code{fc-pattern-get} since a typo in the string naming a
24636 property will result in a silent null return, while a typo in a function
24637 name will usually result in a compiler or runtime \"not fboundp\" error.
24638 You may use @code{defsubst} to define convenience functions for non-standard
24639 properties.
24640
24641 @example
24642 family String Font family name
24643 style String Font style. Overrides weight and slant
24644 slant Int Italic, oblique or roman
24645 weight Int Light, medium, demibold, bold or black
24646 size Double Point size
24647 aspect Double Stretches glyphs horizontally before hinting
24648 pixelsize Double Pixel size
24649 spacing Int Proportional, monospace or charcell
24650 foundry String Font foundry name
24651 antialias Bool Whether glyphs can be antialiased
24652 hinting Bool Whether the rasterizer should use hinting
24653 verticallayout Bool Use vertical layout
24654 autohint Bool Use autohinter instead of normal hinter
24655 globaladvance Bool Use font global advance data
24656 file String The filename holding the font
24657 index Int The index of the font within the file
24658 ftface FT_Face Use the specified FreeType face object
24659 rasterizer String Which rasterizer is in use
24660 outline Bool Whether the glyphs are outlines
24661 scalable Bool Whether glyphs can be scaled
24662 scale Double Scale factor for point->pixel conversions
24663 dpi Double Target dots per inch
24664 rgba Int unknown, rgb, bgr, vrgb, vbgr, none - subpixel geometry
24665 minspace Bool Eliminate leading from line spacing
24666 charset CharSet Unicode chars encoded by the font
24667 lang String List of RFC-3066-style languages this font supports
24668 @end example
24669
24670 The FT_Face, Matrix, CharSet types are unimplemented, so the corresponding
24671 properties are not accessible from Lisp at this time. If the value of a
24672 property returned has type FT_Face, FcCharSet, or FcMatrix,
24673 @code{fc-result-type-mismatch} is returned.
24674
24675 The following properties which were standard in @file{Xft} v.1 are
24676 obsolete in @file{Xft} v.2: @code{encoding}, @code{charwidth},
24677 @code{charheight}, @code{core}, and @code{render}.
24678
24679 @defun fc-pattern-destroy pattern
24680
24681 Explicitly deallocate pattern object @var{pattern}. @emph{Do not call
24682 this function from LISP code. You will crash. This API will be removed
24683 in the near future.}
24684 @end defun
24685
24686 @defun fc-font-match device pattern
24687
24688 Return the font on @var{device} that most closely matches @var{pattern}.
24689
24690 @var{pattern} is a @file{fontconfig} pattern object. @var{device} is an
24691 X11 device. Returns a @file{fontconfig} pattern object representing the
24692 closest match to the given pattern, or an error code. Possible error
24693 codes are @code{fc-result-no-match} and @code{fc-result-no-id}.
24694 @end defun
24695
24696 @defun fc-list-fonts-pattern-objects device pattern properties
24697
24698 List the fonts on @var{device} that match @var{pattern} for
24699 @var{properties}. @var{device} is an X11 device. @var{pattern} is a
24700 @file{fontconfig} pattern to be matched. @var{properties} is the list of
24701 property names (strings) that should be included in each returned
24702 pattern. The result is a @file{fontconfig} fontset object containing
24703 the set of unique matching patterns.
24704 @end defun
24705
24706 The @var{properties} argument does not affect the matching. So, for
24707 example,
24708
24709 @example
24710 (mapcar #'fc-name-unparse
24711 (let ((xfl (fc-list-fonts-pattern-objects nil
24712 (fc-name-parse "FreeMono") '("style")))
24713 (i 0)
24714 (fl nil))
24715 (while (< i (fc-fontset-count xfl))
24716 (push (fc-fontset-ref xfl i) fl)
24717 (setq i (1+ i)))
24718 fl))
24719 @end example
24720
24721 will return something like
24722 @samp{(":style=Bold" ":style=Medium" ":style=Oblique" ":style=BoldOblique")}
24723 if you have the FreeFont package installed. Note that the sets of
24724 objects in the target pattern and the returned patterns don't even
24725 intersect.
24726
24727 In using @code{fc-list-fonts-pattern-objects}, be careful that only
24728 intrinsic properties of fonts be included in the pattern. Those
24729 properties included in the pattern must be matched, or the candidate
24730 font will be eliminated from the list. When a font leaves a property
24731 unspecified, it is considered to be a mismatch for any pattern with that
24732 property specified. Thus, inclusion of extraneous properties will
24733 result in the list being empty. Note that for scalable fonts (at
24734 least), @code{size} is not an intrinsic property! Thus a specification
24735 such as @code{"Bitstream Vera Sans-12"} will return an empty list
24736 regardless of whether the font is available or not---probably not what
24737 you (as programmer or user) want.
24738
24739 The list is unsorted. In particular, the pattern
24740 @code{":style=italic,oblique"} will not return italic fonts first, then
24741 oblique ones. The fonts will be returned in some arbitrary order.
24742
24743 @emph{Implementation notes}: Fontset objects are slated for removal
24744 from the API. In the future @code{fc-list-fonts-pattern-objects} will
24745 return a list. The @var{device} argument is unused, ignored, and may be
24746 removed if it's not needed to match other font-listing APIs. This name
24747 will be changed to correspond to Ben's new nomenclature, probably simply
24748 @code{fc-font-list}.
24749
24750 @defun fc-font-sort device pattern trim
24751
24752 Return a fontset object listing all fonts sorted by proximity to
24753 @var{pattern}. @var{device} is an X11 device. @var{pattern} is a
24754 fontconfig pattern to be matched. Optional argument @var{trim}, if
24755 non-nil, means to trim trailing fonts that do not contribute new
24756 characters to the union repertoire.
24757 @end defun
24758
24759 @emph{Implementation notes}: Fontset objects are slated for removal
24760 from the API. In the future @code{fc-font-sort} will return a list (or
24761 perhaps a vector) of FcPatterns. The @var{device} argument is unused,
24762 ignored, and may be removed if it's not needed to match other
24763 font-listing APIs.
24764
24765 @defun fc-font-real-pattern fontname xdevice
24766
24767 Temporarily open font @var{fontname} (a string) on device @var{xdevice}
24768 and return the actual fc pattern matched by the Fc library. @emph{This
24769 function doesn't make much sense and will be removed from the API.}
24770 @end defun
24771
24772 @defun xlfd-font-name-p fontname
24773
24774 Check whether string @var{fontname} is a XLFD font name.
24775 @end defun
24776
24777 @defvar xft-debug-level
24778
24779 Level of debugging messages to issue to stderr for @var{Xft}.
24780 A nonnegative integer. Set to 0 to suppress all warnings.
24781 Default is 1 to ensure a minimum of debugging output at initialization.
24782 Higher levels give more information.
24783 @end defvar
24784
24785 @defvar xft-version
24786
24787 The major version number of the Xft library compiled with.
24788 @end defvar
24789
24790 @defvar xft-xlfd-font-regexp
24791
24792 Regular expression matching XLFD font names.
24793 @end defvar
24794
24795
24796
24797 @node Modern Font Support -- Xft, , Modern Font Support -- fontconfig, Better Rendering Support -- Modern Font Support
24798 @subsubsection Modern Font Support -- fontconfig
24799
24800 IIRC, we don't really provide any @file{Xft} APIs at the LISP level yet.
24801
24802
24330 24803
24331 24804
24332 24805
24333 @node Future Work Discussion, Old Future Work, Future Work, Top 24806 @node Future Work Discussion, Old Future Work, Future Work, Top
24334 @chapter Future Work Discussion 24807 @chapter Future Work Discussion