racket/draw: change font face name interpretation again

Treat a "face" as a font description only if it has a comma,
otherwise go back to treating it as a family name.

This change fixes the problem of parsing "Times New Roman"
as "Times New, Roman".
This commit is contained in:
Matthew Flatt 2012-02-17 10:33:19 -07:00
parent 8378b742c7
commit 530b353798
5 changed files with 36 additions and 20 deletions

View File

@ -133,17 +133,24 @@
(and desc
(install! desc)
desc))
(let* ([desc (pango_font_description_from_string (if ps?
(send the-font-name-directory
get-post-script-name
id
weight
style)
(send the-font-name-directory
get-screen-name
id
weight
style)))])
(let* ([desc-str (if ps?
(send the-font-name-directory
get-post-script-name
id
weight
style)
(send the-font-name-directory
get-screen-name
id
weight
style))]
[desc (if (regexp-match #rx"," desc-str)
;; comma -> a font description
(pango_font_description_from_string desc-str)
;; no comma -> a font family
(let ([desc (pango_font_description_new)])
(pango_font_description_set_family desc desc-str)
desc))])
(unless (eq? style 'normal)
(pango_font_description_set_style desc (case style
[(normal) PANGO_STYLE_NORMAL]
@ -304,7 +311,7 @@
(for/list ([face (in-list (pango_font_family_list_faces fam))])
(string-append
(pango_font_family_get_name fam)
" "
", "
(pango_font_face_get_face_name face))))))
string<?))

View File

@ -31,7 +31,7 @@ A @defterm{font} is an object which determines the appearance of text,
@margin-note{The terminology ``family'' and ``face'' is mangled
relative to its usual meaning. A @racket[font%] ``face''
is really used more like a font family in the usual
terminology, or more generally as a face-description
terminology or more generally as a face-description
string that is combined with other @racket[font%]
attributes to arrive at a face. A @racket[font%]
``family'' is a kind of abstract font family that is

View File

@ -31,15 +31,16 @@ For a family without a face string, the corresponding font ID has a
@racket[printer-dc%]).
Currently, on all platforms, a face string is interpreted as a
@hyperlink["http://www.pango.org"]{Pango} font description. A
description can be a family name such as @racket["Helvetica"], a face
name such as @racket["Helvetica Bold"], or a list of comma-separated
families followed by space-separated font options such as
@racket["Helvetica,Arial bold italic"]. Any size in a font
@hyperlink["http://www.pango.org"]{Pango} font description when it
contains a comma, otherwise it is treated as a family name. A
face can thus be just a family name such as @racket["Helvetica"], a family
followed by a comma and font modifiers as in @racket["Helvetica, Bold"], or a sequence of comma-separated
familie names followed by space-separated font options as an
@racket["Helvetica, Arial, bold italic"]. Any size in a font
description is overridden by a given @racket[font%]'s size. Any
(slant) style or weight options in a font description are overridden
by a non-@racket['normal] value for a given @racket[font%]'s style
or weight, respectively.
by a non-@racket['normal] value for a given @racket[font%]'s style or
weight, respectively.
@defmethod[(find-family-default-font-id [family (one-of/c 'default 'decorative 'roman 'script
'swiss 'modern 'symbol 'system)])

View File

@ -502,4 +502,9 @@
;; ----------------------------------------
(test #f 'no-commas (ormap (lambda (s) (regexp-match? #rx"," s)) (get-face-list)))
(test #t 'all-commas (andmap (lambda (s) (regexp-match? #rx"," s)) (get-face-list #:all-variants? #t)))
;; ----------------------------------------
(report-errs)

View File

@ -3,6 +3,8 @@ Added prop:cpointer
Fixed handle-evt to disallow a handle-evt
mysterx: removed ActiveX support plus com-add-ref and
com-ref-count
racket/draw: treat a face as a Pango font description
only when it contains a comma
Version 5.2.1.5
Added racket/future to re-exports of racket
@ -39,6 +41,7 @@ net/mime: allow any subtype in input; made exception structs a
subtype of exn:fail
compiler/zo-structs: added inline-variant
racket/stream: added stream constructor
racket/draw: treat a face as a Pango font description
Version 5.2, November 2011
Generalized begin-with-syntax to allow phase-N definitions,