comparison man/xemacs/custom.texi @ 3387:f5d8dba84d4f

[xemacs-hg @ 2006-05-09 05:00:26 by stephent] Xft customization docs, first cut. <87slnjn69l.fsf@tleepslib.sk.tsukuba.ac.jp>
author stephent
date Tue, 09 May 2006 05:00:30 +0000
parents e1bc252950d9
children 06a586083be3
comparison
equal deleted inserted replaced
3386:b41588b239f8 3387:f5d8dba84d4f
1
2 @c FIXME -- we demand a detail menu!
1 3
2 @node Customization, Quitting, Emulation, Top 4 @node Customization, Quitting, Emulation, Top
3 @chapter Customization 5 @chapter Customization
4 @cindex customization 6 @cindex customization
5 7
2031 have a region of text that displays with completely different 2033 have a region of text that displays with completely different
2032 attributes when its buffer is viewed from a different X window. 2034 attributes when its buffer is viewed from a different X window.
2033 2035
2034 The display attributes of faces may be specified either in Lisp or through 2036 The display attributes of faces may be specified either in Lisp or through
2035 the X resource manager. 2037 the X resource manager.
2038
2039 Basic Xft support has been merged into the mainline, and it looks pretty
2040 good. However, customization UI and documentation still leaves a lot to
2041 be desired. Here's a first cut, as a separate node.
2042
2043 @menu
2044 * Xft Font Customization::
2045 @end menu
2036 2046
2037 @subsection Customizing Faces 2047 @subsection Customizing Faces
2038 2048
2039 You can change the face of an extent with the functions in 2049 You can change the face of an extent with the functions in
2040 this section. All the functions prompt for a @var{face} as an 2050 this section. All the functions prompt for a @var{face} as an
2213 @code{set-face-underline-p}. The argument @var{underline-p} can be used 2223 @code{set-face-underline-p}. The argument @var{underline-p} can be used
2214 to make underlining an attribute of the face or not. If the optional 2224 to make underlining an attribute of the face or not. If the optional
2215 @var{frame} argument is provided, the face is changed only in that 2225 @var{frame} argument is provided, the face is changed only in that
2216 frame; otherwise, it is changed in all frames. 2226 frame; otherwise, it is changed in all frames.
2217 2227
2228
2229 @node Xft Font Customization, , , Faces
2230 @section Xft Font Customization
2231
2232 This section was written by @email{stephen@@xemacs.org,Stephen Turnbull},
2233 and is very much a work in progress. I've tried to provide pointers to
2234 as much of the relevant information as possible, but many of the APIs
2235 and UIs are in flux, so it seemed more work than it was worth to
2236 completely translate the tables of constants, and so on. Feel free to
2237 ask for clarifications, @emph{etc.} Please Cc
2238 @email{xemacs-beta@@xemacs.org,the XEmacs Beta Testers' mailing list},
2239 as that is the issue tracking channel of record, and there are a few
2240 others who can answer the questions or improve documentation when I'm
2241 not able to respond quickly.
2242
2243 @c Don't blame Ben (or Eric and Matthias, for that matter). Feel free to
2244 @c add, edit, and share the blame, everybody!
2245
2246 @c #### Make these @urlref's!!
2247 As of mid-2005, we have added support for the
2248 @file{Xft} library, which provides a more robust @emph{font
2249 configuration} mechanism via Keith Packard's @file{fontconfig} library;
2250 improved glyph rendering, including antialiasing, via the
2251 @file{freetype} library; and client-side rendering (saving bandwidth and
2252 server memory) via the @file{XRender extension}.
2253
2254 @c #### Describe Alexey Gladkov and Yury Konovalov's work.
2255
2256 @subheading Font configuration
2257
2258 In XEmacs, font configuration is handled via @emph{faces}. Currently
2259 XEmacs uses a special type of @emph{font specifier} to map XEmacs
2260 locales to font names. Especially under X11, this can cause annoying
2261 problems because of the unreliability of X servers' mappings from
2262 @samp{XLFD} names to X11 fonts, over which XEmacs has no influence
2263 whatsoever. However, the @file{fontconfig} library which is used with
2264 @file{Xft} provides much more reliable mapping, along with a more
2265 reliably parsable naming scheme similar to that used by TrueType fonts
2266 on MS Windows and the Macintosh.
2267
2268 @subheading fontconfig
2269
2270 Fontconfig is dramatically different from the X model in several ways.
2271 In particular, when queried for a font @emph{fontconfig always returns a
2272 font}, whereas X queries may return ``not found.'' However, the font
2273 returned need not be anything like the desired font. This is not really
2274 a problem in practice, because users generally have a pretty good idea
2275 of what fonts are available on their display. However, users should be
2276 aware that as of XEmacs 21.5.26 the font selection internals have not
2277 been revised to account for this radically different model, so some
2278 surprising results are possible.
2279
2280 From the user's point of view, @file{fontconfig} provides a naming
2281 convention which is @emph{precise}, @emph{accurate}, and
2282 @emph{convenient}. Precision means that all properties available in the
2283 programming API can be individually specified. Accuracy means that the
2284 truename of the font is exactly the list of all properties specified by
2285 the font. Thus, the anomolies that occur with XLFDs on many servers
2286 (including modern Linux distributions with XFree86 or X.org servers)
2287 cannot occur. Convenience is subjective, of course. However,
2288 @file{fontconfig} provides a configuration system which (1) explicitly
2289 specifies the defaults and substitutions that will be made in processing
2290 user queries, (2) allows the user to specify search configuration,
2291 abbreviations, substitutions, and defaults that override the system's,
2292 in the same format as used by system files, and (3) allows flexible
2293 aliases that can resolve to any of several actual fonts depending on
2294 which fonts are installed.
2295
2296 Further, a @dfn{standard minimal configuration} is defined that ensures
2297 that at least the @emph{serif}, @emph{sans-serif}, and @emph{monospace}
2298 font aliases are available on all @file{fontconfig} systems.
2299
2300 @subheading fontconfig font names
2301
2302 @file{fontconfig} font names are very regular, and constitute a precise
2303 and extensible specification of a font's properties.
2304
2305 The basic @file{fontconfig} font name has three components: the font
2306 family name, the size, and a list of named attribute fields. All
2307 attribute names and values are strings encoded in Unicode UTF-8, or
2308 decimal numbers with optional decimal point and fraction. The
2309 characters @samp{-}, @samp{:}, @samp{,}, @samp{=}, and @samp{\} are
2310 syntactically significant to @file{fontconfig}. They may be used in
2311 font name components by the familiar mechanism of backslash escaping.
2312 This simply removes any special meaning from the following character.
2313 It is always safe to use an escape even if it is not needed.
2314
2315 Most string values are case-insensitive, but this is attribute-specific.
2316
2317 The @dfn{font family name} is an arbitrary string, which may contain any
2318 character, including spaces, hyphens, and commas. Don't forget to
2319 escape hyphens, colons, commas, and backslashes!
2320
2321 The @dfn{size} is a decimal number with optional decimal point and
2322 fractional part. It is interpreted as point size.
2323
2324 A @dfn{named attribute field} is a key-value pair separated by an equal
2325 sign. Some attributes have predefined semantics. (These include such
2326 familiar attributes as @samp{slant} and @samp{dpi} -- note that
2327 @file{fontconfig} does not distinguish between vertical and horizontal
2328 resolution!
2329
2330 The basic syntax of a font name is simple and regular. The @emph{font
2331 family name} comes first, followed by a hyphen and the @emph{size},
2332 followed by a list of @emph{named attribute fields}, each introduced by
2333 a colon:
2334
2335 @example
2336 @var{font family name}-@var{size}:@var{key1}=@var{value1}:@var{key2}=@var{value2}...
2337 @end example
2338
2339 There are four extensions to the basic syntax. First, all of the
2340 fields are optional. If size is omitted, the hyphen should be omitted
2341 as well. There should never be a trailing colon. Note that
2342 @file{fontconfig} does @emph{not} interpret an omitted field as
2343 ``default to current.'' @file{fontconfig} does not have access to that
2344 context. Instead, omitted fields are filled in according to a set of
2345 defaults specified in the system @file{fonts.conf} file and in the
2346 user's @file{.fonts.cont} file. The user's configuration gets
2347 precedence, of course.
2348
2349 The second is that the @emph{font family name}, the @emph{size}, and the
2350 @emph{value} component of a @emph{named attribute field} may be a
2351 comma-separated list of values. This is called a @dfn{pattern}. In
2352 queries, @file{fontconfig} tries to match each entry in the list in
2353 order. (I suspect that order of attributes is also significant.
2354 @emph{I.e.}, font family always gets highest precedence, followed by
2355 size, followed by the remaining named attributes. Testing and reports
2356 to the @email{xemacs-beta@@xemacs.org,XEmacs Beta Testers mailing list}
2357 are very welcome!)
2358
2359 The third is the definition of @dfn{constants} to represent numerical
2360 values. For example, both @samp{slant} and @samp{weight} are defined as
2361 integer attributes, but the magnitudes are arbitrary; only the ordering
2362 and relative distances are useful. (``Relative distance'' is used to
2363 implement the concept that although strictly speaking @emph{italic} and
2364 @emph{oblique} are different faces, most users don't know the
2365 difference, and even professional typographers would agree that they are
2366 much closer to each other than either is to @emph{roman}.) So
2367 @emph{constants} like @samp{roman} (0) and @samp{italic} (100) are
2368 defined for @samp{slant}, and @samp{medium} (100) and @samp{bold} (200)
2369 are defined for @samp{weight}.
2370
2371 The fourth is that a @dfn{style} may be defined as an alias for an
2372 instance of a @emph{named attribute field}, that is, specifying both key
2373 and value. The @emph{styles} @samp{bold}, an alias for
2374 @samp{weight=200}, and @samp{italic}, an alias for @samp{slant=100}, are
2375 commonly used.
2376
2377 Styles and constants can be defined by the application. XEmacs
2378 currently defines none, but suggestions are welcome if some convenient
2379 alias is lacking from @file{fontconfig}. Note that we will not provide
2380 additional aliases where standard ones exist, @emph{e.g.}, @samp{heavy}
2381 as an additional alias for @samp{bold} would almost certainly be
2382 rejected. These cause more confusion than they are worth, and would
2383 decrease portability of user specifications to other applications.
2384
2385 (Attributes can also be defined, but they must be implemented by the
2386 fonts to be useful. Until XEmacs provides its own fonts with
2387 non-standardized attributes, this is not useful.)
2388
2389 Here are some examples of font names and query patterns:
2390
2391 @example
2392 Times-12 12-point Times Roman
2393 Times-12:bold 12-point Times Bold
2394 Courier:italic Courier Italic in the default size
2395 Monospace:matrix=1 .1 0 1 The user's preferred monospace font
2396 with artificial obliquing
2397 Mikachan\-PB-16 16-point Mikachan-PB
2398 LucidaTypewriter,Courier-9 9-point LucidaTypewriter if available,
2399 otherwise 9-point Courier
2400 @end example
2401
2402 Note how @emph{styles} are used in the second and third examples, how
2403 @samp{matrix} has a complex value containing spaces, and the
2404 escaped hyphen in the font family name @samp{Mikachan\-PB}.
2405
2406 @c #### FIXME here and also in fontconfig.texi (in general-docs package).
2407 Here is a (somewhat outdated) list of current standard named attributes:
2408
2409 @example
2410 Property CPP symbol Type Description
2411
2412 family FC_FAMILY String Font family name
2413 style FC_STYLE String Font style. Overrides weight and slant
2414 slant FC_SLANT Int Italic, oblique or roman
2415 weight FC_WEIGHT Int Light, medium, demibold, bold or black
2416 size FC_SIZE Double Point size
2417 aspect FC_ASPECT Double Stretch glyphs horizontally, then hint
2418 pixelsize FC_PIXEL_SIZE Double Pixel size
2419 spacing FC_SPACING Int Proportional, monospace or charcell
2420 foundry FC_FOUNDRY String Font foundry name
2421 antialias FC_ANTIALIAS Bool Should glyphs be antialiased?
2422 hinting FC_HINTING Bool Should the rasterizer use hinting?
2423 verticallayout FC_VERTICAL_LAYOUT Bool Use vertical layout
2424 autohint FC_AUTOHINT Bool Use autohinter instead of normal hinter
2425 globaladvance FC_GLOBAL_ADVANCE Bool Use font global advance data
2426 file FC_FILE String The filename holding the font
2427 index FC_INDEX Int The index of the font within the file
2428 ftface FC_FT_FACE FT_Face Use the specified FreeType face object
2429 rasterizer FC_RASTERIZER String Which rasterizer is in use
2430 outline FC_OUTLINE Bool Whether the glyphs are outlines
2431 scalable FC_SCALABLE Bool Whether glyphs can be scaled
2432 scale FC_SCALE Double Point->pixel conversion scale factor
2433 dpi FC_DPI Double Target dots per inch
2434 rgba FC_RGBA Int unknown, rgb, bgr, vrgb, vbgr, none
2435 - subpixel geometry
2436 source FC_SOURCE String X11, freetype
2437 minspace FC_MINSPACE Bool Eliminate leading from line spacing
2438 charset FC_CHARSET CharSet Unicode chars encoded by the font
2439 lang FC_LANG String List of RFC-3066-style languages
2440 this font supports
2441 fontversion FC_FONTVERSION Int From 'head' table
2442 @end example
2443
2444 Here is a list of current standard constants:
2445
2446 @example
2447 Constant Property CPP symbol
2448
2449 light weight FC_WEIGHT_LIGHT
2450 medium weight FC_WEIGHT_MEDIUM
2451 demibold weight FC_WEIGHT_DEMIBOLD
2452 bold weight FC_WEIGHT_BOLD
2453 black weight FC_WEIGHT_BLACK
2454 roman slant FC_SLANT_ROMAN
2455 italic slant FC_SLANT_ITALIC
2456 oblique slant FC_SLANT_OBLIQUE
2457 proportional spacing FC_PROPORTIONAL
2458 mono spacing FC_MONO
2459 charcell spacing FC_CHARCELL
2460 unknown rgba FC_RGBA_UNKNOWN
2461 rgb rgba FC_RGBA_RGB
2462 bgr rgba FC_RGBA_BGR
2463 vrgb rgba FC_RGBA_VRGB
2464 vbgr rgba FC_RGBA_VBGR
2465 none rgba FC_RGBA_NONE
2466 @end example
2467
2468 Note that this is the @file{fontconfig} API list; you can expect that
2469 XEmacs will define corresponding keywords by substituting @samp{:} for
2470 the leading @samp{FC_}, @samp{-} for @samp{_}, removing the key of the
2471 attribute if present, and lowercasing the name. Thus
2472 @samp{FC_WEIGHT_BOLD} becomes @samp{:bold}.
2473 @kbd{M-x apropos RET fc-.*-mapping} will give a list of variables each
2474 of which lists such keywords and their meanings.
2475
2476 @subheading Font menus
2477
2478 The @samp{Options->Font} and @samp{Options->Font Sizes} menus are
2479 broken, by design, not just by @file{Xft}. The problem is that many
2480 fonts are unavailable because they don't match the current size---which
2481 is very strange, since @file{Xft} fonts are of course scalable. But the
2482 whole idea of requiring that the font match the size is strange. And
2483 the @samp{Options->Font Weights} menu is just disabled, and has been for
2484 eons.
2485
2486 @subheading X resources
2487
2488 Currently there are @emph{four} treatments of font resources. There are
2489 the @samp{XEmacs.@var{face}.attributeFont} resources used to set a
2490 single global font specification. In the widgets, some (still) have a
2491 @samp{font} resource using the automatic @file{Xt} resource conversion
2492 to X's @samp{FontStruct}, some have separate @samp{font} and @samp{xftFont}
2493 resources with the former automatically converted to @samp{FontStruct}
2494 by @file{Xt} and the latter left as a string, to be converted to a
2495 fontconfig @samp{FcPattern} by
2496 @samp{FcParseName} later, and some have a single @samp{font} resource
2497 which is converted to @samp{FontStruct} by @file{Xt} or the latter left
2498 as a string, depending on whether @file{Xft} was enabled by
2499 @samp{configure} or not.
2500
2501 Eventually these should be converted to use the face
2502 approach, perhaps with some way to set specifications for individual
2503 widgets, frames, or buffers. This will require some careful design work
2504 to incorporate face support in the widgets. Stephen's current thinking
2505 is that XEmacs should just accept any
2506 or all of @samp{font}, @samp{fontSet}, and @samp{fontList} resources,
2507 treat them all as lists of font names, either @samp{XLFD}- or
2508 @file{fontconfig}-style, parse them ourselves (ie, not use the @file{Xt}
2509 resource manager), and add them to font specifiers as appropriate. But
2510 this will require a bit of thought to obey POLA vis-a-vis usual @file{Xt}
2511 conventions.
2512
2513 @subheading Specifiers, charsets, and languages
2514
2515 Traditionally Mule uses a rather rigid and low-level abstraction, the
2516 @emph{charset}, to characterize font repertoires. Unfortunately,
2517 support for a given charset is generally neither necessary nor
2518 sufficient to support a language. Worse, in XEmacs's current
2519 implementation Xft doesn't help much. Instead you need to add the fonts
2520 for different charsets to the font specifier in the right order.
2521
2522 There currently is no explicit way to specify that a particular font be
2523 used only for a given language. However, since many fonts support only
2524 a limited repertoire such as ISO 8859/1, you can use the precedence of
2525 specifications for a given specifier locale to get something of this
2526 effect for non-Latin character sets. This will normally work rather
2527 poorly for multiple Latin character sets, however, because the
2528 repertoires tend to have large amounts of overlap. Support for
2529 specifying font by @emph{language} as well as by character set is
2530 planned.
2531
2532 Because fonts supporting other languages tend to support English as
2533 well, if you want to use one font for English and another for the other
2534 language, you must use the @code{append} method when adding font
2535 specifications for the @emph{other} language.
2536
2537 However, this simple method leaves you with a problem if you want to
2538 change the other language's font: you have to remove the existing
2539 specification so it won't shadow the new one when you append.
2540
2541 In order to provide a convenient way to change ``other-language fonts'',
2542 I use @code{remove-tag-set-append} and @code{define-specifier-tag} like
2543 this:
2544
2545 @example
2546 (define-specifier-tag 'lang-ja)
2547 ;; No, I don't try to do real work with this font! But it makes it
2548 ;; obvious that I got the requested font. :-)
2549 (set-face-font 'default "AirCut-14")
2550 (set-face-font 'default "Kochi Mincho-14" nil '(lang-ja) 'append)
2551 ;; Oops, too sober. Try something to match AirCut.
2552 (set-face-font 'default "Mikachan-14"
2553 nil '(lang-ja) 'remove-tag-set-append)
2554 @end example
2555
2556 The only way to configure widget fonts at the present time is to use X
2557 resources (or hack the source and rebuild). Currently supported widgets
2558 are
2559 @itemize
2560 @item
2561 menubars
2562 @item
2563 tab controls
2564 @end itemize
2565
2566 Here are the resources I use. @strong{Warning:} @emph{This interface
2567 will change. Pay attention to beta announcements, and complain loudly
2568 if changes aren't documented here!} The tab control and menubar have
2569 separate Font and XftFont resources, and use the X resource manager to
2570 instantiate a FontStruct from the Font resource. There is no converter
2571 facility for XftFont yet, and creating one that handles both FontStruct
2572 and XftFont depending on XEmacs's configuration and the font name seems
2573 error-prone at best. Probably we will use a simple string
2574 representation for this resource, and convert to a face in XEmacs rather
2575 than a font in Xt/Xft.
2576 @example
2577 XEmacs*Tabs.xftFont: Bitstream Vera Sans-16
2578 XEmacs*menubar*xftFont: Bitstream Vera Sans-16
2579 XEmacs.modeline.attributeFont: Bitstream Charter-16
2580 XEmacs.default.attributeFont: Bitstream Vera Sans Mono-16
2581 @end example
2582 I highly recommend use of a proportional font in the modeline because it
2583 allows a lot more text to fit there.
2584 @c Previously the font sizes were quite varied, and there was a comment
2585 @c that this weirdness gave good balance. This isn't true on my main
2586 @c platform, Mac OS X, and needs to be rechecked on Linux, where it was
2587 @c observed.
2588
2589 @subheading Known Problems
2590
2591 @table @code
2592 @item Options->Font
2593 @itemx Options->Font Size
2594 These menus don't work. All fonts are greyed out. All sizes are
2595 available, but many (most?) faces don't change size, in particular,
2596 @samp{default} does not.
2597
2598 @item Antialiased text bleeding outside of reported extent
2599 This is most obvious with the underscore character in that
2600 font, and with cursors. The bottom of the underscore is antialiased,
2601 and insertions or deletions in the same line before the underscore leave
2602 a series of "phantom" underlines.
2603
2604 I think this is probably an Xft bug, but I'm not sure.
2605 @end table
2606
2607 @subheading Variables Used with Xft and Fontconfig
2608
2609 @defvar xft-debug-level
2610
2611 Level of debugging messages to issue to stderr for @var{Xft}.
2612 A nonnegative integer. Set to 0 to suppress all warnings.
2613 Default is 1 to ensure a minimum of debugging output at initialization.
2614 Higher levels give more information.
2615 @end defvar
2616
2617 @defvar xft-version
2618
2619 The major version number of the Xft library compiled with.
2620 @end defvar
2621
2622 @defvar xft-xlfd-font-regexp
2623
2624 Regular expression matching XLFD font names.
2625 @end defvar
2626
2627
2218 @node Frame Components 2628 @node Frame Components
2219 @section Frame Components 2629 @section Frame Components
2220 2630
2221 You can control the presence and position of most frame components, such 2631 You can control the presence and position of most frame components, such
2222 as the menubar, toolbars, and gutters. 2632 as the menubar, toolbars, and gutters.