26 Drawing Functions

▼ |  | The Racket Drawing Toolkit

1 | Overview
2 | bitmap%
3 | bitmap-dc%
4 | brush%
5 | brush-list%
6 | color%
7 | color-database<%>
8 | dc<%>
9 | dc-path%
10 | font%
11 | font-list%
12 | font-name-directory<%>
13 | gl-config%
14 | gl-context<%>
15 | linear-gradient%
16 | pdf-dc%
17 | pen%
18 | pen-list%
19 | point%
20 | post-script-dc%
21 | ps-setup%
22 | radial-gradient%
23 | record-dc%
24 | region%
25 | svg-dc%
26 | Drawing Functions
27 | Drawing Contracts
28 | Signature and Unit
29 | Unsafe Libraries
30 | Drawing Conveniences
31 | Platform Dependencies
| Bibliography
| Index

On this page:

current-ps-setup
get-face-list
get-family-builtin-face
make-bitmap
make-brush
make-color
make-font
current-font-list
make-monochrome-bitmap
make-pen
make-platform-bitmap
read-bitmap
recorded-datum->procedure
the-brush-list
the-color-database
the-font-list
the-font-name-directory
the-pen-list

top contents ← prev up next →

## 26 Drawing Functions🔗ℹ

> parameter (current-ps-setup) → (is-a?/c ps-setup%)
> (current-ps-setup pss) → void?
> pss : (is-a?/c ps-setup%)

A parameter that determines the current PostScript configuration settings. See post-script-dc% and printer-dc%.

> > procedure
> > (get-face-list | [ | kind |
> > |  | #:all-variants? all-variants?]) |
> → (listof string?)
> kind : (or/c 'mono 'all) = 'all
> all-variants? : any/c = #f

Returns a list of font face names available on the current system. If kind is 'mono, then only faces that are known to correspond to monospace fonts are included in the list.

If all-variants? is #f (the default), then the result is in more standard terminology a list of font family names, which are combined with style and weight options to arrive at a face; if all-variants? is true, then the result includes a string for each available face in the family.

> procedure (get-family-builtin-face family) → string?
> | family |  | : |  |
> (or/c 'default 'decorative 'roman 'script
> 'swiss 'modern 'symbol 'system)

Returns the built-in default face mapping for a particular font family.

See font% for information about family.

> > procedure
> > (make-bitmap |  | width |  |  |  |
> > |  | height |  |  |  |
> > | [ | alpha? |  |  |  |
> > |  | #:backing-scale backing-scale]) |  | → |  | (is-a?/c bitmap%)
> width : exact-positive-integer?
> height : exact-positive-integer?
> alpha? : any/c = #t
> backing-scale : (>/c 0.0) = 1.0

Returns (make-object bitmap% width height #f alpha? backing-scale), but this procedure is preferred because it defaults alpha? in a more useful way.

See also make-platform-bitmap and Portability and Bitmap Variants.

Changed in version 1.1 of package draw-lib: Added the #:backing-scale optional argument.

> > procedure
> > (make-brush | [ | #:color color |  |  |  |
> > |  | #:style style |  |  |  |
> > |  | #:stipple stipple |  |  |  |
> > |  | #:gradient gradient |  |  |  |
> > |  | #:transformation transformation |  |  |  |
> > |  | #:immutable? immutable?]) |  | → |  | (is-a?/c brush%)
> color : (or/c string? (is-a?/c color%)) = (make-color 0 0 0)
> | style |  | : |  |
> (or/c 'transparent 'solid 'opaque
> 'xor 'hilite 'panel
> 'bdiagonal-hatch 'crossdiag-hatch
> 'fdiagonal-hatch 'cross-hatch
> 'horizontal-hatch 'vertical-hatch)
> |  | = |  | 'solid
> stipple : (or/c #f (is-a?/c bitmap%)) = #f
> | gradient |  | : |  |
> (or/c #f
> (is-a?/c linear-gradient%)
> (is-a?/c radial-gradient%))
> |  | = |  | #f
> | transformation |  | : |  |
> (or/c #f (vector/c (vector/c real? real? real?
> real? real? real?)
> real? real? real? real? real?))
> |  |  | = |  | #f
> immutable? : any/c = #t

Creates a brush% instance. This procedure provides a nearly equivalent interface compared to using make-object with brush%, but it also supports the creation of immutable brushes (and creates immutable burshes by default).

When stipple is #f, gradient is #f, transformation is #f, immutable? is true, and color is either a color% object or a string in the-color-database, the result brush is created via find-or-create-brush of the-brush-list.

A brush transformation has the same representation and meaning as for get-transformation in dc<%>.

> procedure (make-color red green blue [alpha]) → (is-a?/c color%)
> red : byte?
> green : byte?
> blue : byte?
> alpha : (real-in 0 1) = 1.0

Creates a color% instance. This procedure provides a nearly equivalent interface compared to using make-object with color%, but it creates an immutable color% object.

To create an immutable color based on a color string, use find-color or the-color-database.

> > procedure
> > (make-font | [ | #:size size |
> > |  | #:face face |
> > |  | #:family family |
> > |  | #:style style |
> > |  | #:weight weight |
> > |  | #:underlined? underlined? |
> > |  | #:smoothing smoothing |
> > |  | #:size-in-pixels? size-in-pixels? |
> > |  | #:hinting hinting |
> > |  | #:feature-settings feature-settings |
> > |  | #:font-list font-list]) |
> → (is-a?/c font%)
> size : (real-in 0.0 1024.0) = 12
> face : (or/c string? #f) = #f
> | family |  | : |  |
> (or/c 'default 'decorative 'roman 'script
> 'swiss 'modern 'symbol 'system)
> |  | = |  | 'default
> style : (or/c 'normal 'italic 'slant) = 'normal
> weight : font-weight/c = 'normal
> underlined? : any/c = #f
> | smoothing |  | : |  |
> (or/c 'default 'partly-smoothed
> 'smoothed 'unsmoothed)
> |  | = |  | 'default
> size-in-pixels? : any/c = #f
> hinting : (or/c 'aligned 'unaligned) = 'aligned
> feature-settings : font-feature-settings/c = (hash)
> | font-list |  | : |  | (or/c (is-a?/c font-list%) #f)
> |  |  | = |  | (current-font-list)

Finds or creates a font% instance.

When font-list is #f, make-font creates a new font using make-object with font%. Otherwise, when font-list is a font-list% instance, make-font finds or creates a font using its find-or-create-font method. In both cases, make-font merely provides a more convenient interface.

Changed in version 1.4 of package draw-lib: Changed size to allow non-integer and zero values.
Changed in version 1.14: Changed weight to allow integer values and the symbols 'thin, 'ultralight, 'semilight, 'book, 'medium, 'semibold, 'ultrabold, 'heavy, and 'ultraheavy.
Changed in version 1.19: Added the optional feature-settings and font-list arguments.

> parameter (current-font-list) → (or/c (is-a?/c font-list%) #f)
> (current-font-list font-list) → void?
> font-list : (or/c (is-a?/c font-list%) #f)
> = | #f

A parameter that determines the default value for the #:font-list argument to make-font. Defaults to #f, but see the-font-list for a possible alternative value.

Added in version 1.19 of package draw-lib.

> procedure (make-monochrome-bitmap width height [bits]) → (is-a?/c bitmap%)
> width : exact-positive-integer?
> height : exact-positive-integer?
> bits : (or/c bytes? #f) = #f

Returns (make-object bitmap% width height #t) if bits is #f, or (make-object bitmap% bits width height) otherwise. This procedure is preferred to using make-object on bitmap% because it is less overloaded.

> > procedure
> > (make-pen | [ | #:color color |  |  |  |
> > |  | #:width width |  |  |  |
> > |  | #:style style |  |  |  |
> > |  | #:cap cap |  |  |  |
> > |  | #:join join |  |  |  |
> > |  | #:stipple stipple |  |  |  |
> > |  | #:immutable? immutable?]) |  | → |  | (is-a?/c pen%)
> color : (or/c string? (is-a?/c color%)) = (make-color 0 0 0)
> width : (real-in 0 255) = 0
> | style |  | : |  |
> (or/c 'transparent 'solid 'xor 'hilite
> 'dot 'long-dash 'short-dash 'dot-dash
> 'xor-dot 'xor-long-dash 'xor-short-dash
> 'xor-dot-dash)
> |  | = |  | 'solid
> cap : (or/c 'round 'projecting 'butt) = 'round
> join : (or/c 'round 'bevel 'miter) = 'round
> stipple : (or/c #f (is-a?/c bitmap%)) = #f
> immutable? : any/c = #t

Creates a pen% instance. This procedure provides a nearly equivalent interface compared to using make-object with pen%, but it also supports the creation of immutable pens (and creates immutable pens by default).

When stipple is #f, immutable? is true, and color is either a color% object or a string in the-color-database, the result pen is created via find-or-create-pen of the-pen-list.

> > procedure
> > (make-platform-bitmap |  | width |
> > |  | height |
> > | [ | #:backing-scale backing-scale]) |
> → (is-a?/c bitmap%)
> width : exact-positive-integer?
> height : exact-positive-integer?
> backing-scale : (>/c 0.0) = 1.0

Creates a bitmap that uses platform-specific drawing operations as much as possible, which is different than a make-bitmap result on Windows and Mac OS. See Portability and Bitmap Variants for more information.

Changed in version 1.1 of package draw-lib: Added the #:backing-scale optional argument.

> > procedure
> > (read-bitmap |  | in |
> > | [ | kind |
> > |  | bg-color |
> > |  | complain-on-failure? |
> > |  | #:get-data-from-file? get-data-from-file? |
> > |  | #:backing-scale backing-scale |
> > |  | #:try-@2x? try-@2x?]) |
> → (is-a?/c bitmap%)
> in : (or path-string? input-port?)
> | kind |  | : |  |
> (or/c 'unknown 'unknown/mask 'unknown/alpha
> 'gif 'gif/mask 'gif/alpha
> 'jpeg 'jpeg/alpha
> 'png 'png/mask 'png/alpha
> 'xbm 'xbm/alpha 'xpm 'xpm/alpha
> 'bmp 'bmp/alpha)
> |  |  | = |  | 'unknown/alpha
> bg-color : (or/c (is-a?/c color%) #f) = #f
> complain-on-failure? : any/c = #t
> get-data-from-file? : any/c = #f
> backing-scale : (>/c 0.0) = 1.0
> try-@2x? : any/c = #f

Returns (make-object bitmap% in kind bg-color complain-on-failure? backing-scale), but this procedure is preferred because it defaults kind and complain-on-failure? in a more useful way.

If try-@2x? is true, in is a path, and kind is not one of the /mask symbols, then read-bitmap checks whether a file exists matching in but with "@2x" added to the name (before the file suffix, if any). If the "@2x" path exists, it is used instead of in, and backing-scale is multiplied by 2.

If get-data-from-file? is not #f, then the resulting bitmap’s get-data-from-file method will return the bytes from the file.

Changed in version 1.1 of package draw-lib: Added the #:backing-scale and #:try-@2x? optional arguments.
Changed in version 1.17: Added the #:get-data-from-file? argument.

> procedure (recorded-datum->procedure datum)
> → ((is-a?/c dc<%>) . -> . void?)
> datum : any/c

Converts a value from get-recorded-datum in record-dc% to a drawing procedure.

> value the-brush-list : (is-a?/c brush-list%)

See brush-list%.

> value the-color-database : (is-a?/c color-database<%>)

See color-database<%>.

> value the-font-list : (is-a?/c font-list%)

See font-list%.

> value the-font-name-directory : (is-a?/c font-name-directory<%>)

See font-name-directory<%>.

> value the-pen-list : (is-a?/c pen-list%)

See pen-list%.
top contents ← prev up next →