SuperCollider CLASSES

Font

A font object
Source: /usr/local/share/SuperCollider/SCClassLibrary/Common/GUI/ViewRedirect.sc
Inherits from: GuiRedirect : Object
Implementing class: QFont

Description

This is the object you pass to other gui objects to set their font name or size.

Class Methods

*new (name, size, bold: false, italic: false, usePointSize: false)

From implementing class

NOTE: The bold, italic and isPointSize arguments are only available in Qt GUI.

Arguments:

name

An instance of String. Must coincide with the name of a font on the system. See *availableFonts.

size

An instance of Float.

bold

A Boolean.

italic

A Boolean.

usePointSize

A Boolean. Whether to regard the size argument as point-size - adapting to the screen resolution.

Discussion:

Example:

g = Font("Helvetica", 12);

*availableFonts

From implementing class

Returns:

Array of the available fonts.

*antiAliasing

*antiAliasing = flag

From implementing class

Arguments:

flag

An instance of Boolean. Default value is false.

*smoothing

*smoothing = flag

From implementing class

Arguments:

flag

An instance of Boolean. Default value is false.

*defaultSansFace

From implementing class

Returns:

The default sans serif face Font.

*defaultSerifFace

From implementing class

Returns:

The default serif face Font.

*defaultMonoFace

From implementing class

Returns:

The default monospace face Font.

*default

*default = font

From implementing class

The global default Font.

In Qt GUI, setting this property is equivalent to Font.setDefault(font). See *setDefault for details.

*setDefault (font, class)

From implementing class
NOTE: Only available in Qt GUI

Sets the global default font. Properties of the font argument will be combined with properties of the default system font, and those of individual views.

Optionally, a class can be given, so only views of that class will be affected.

Note that this will immediately affect any existing views.

Arguments:

font

An instance of Font.

class

A Class (either QView or one of its subclasses), or nil.

*sansSerif (size, bold: false, italic: false, usePointSize: false)

From implementing class

Create a new sans serif face Font.

*monospace (size, bold: false, italic: false, usePointSize: false)

From implementing class

Create a new monospace face Font.

*serif (size, bold: false, italic: false, usePointSize: false)

From implementing class

Create a new serif face Font.

Inherited class methods

Undocumented class methods

*findFirstAvailable (fontNames, action)

Instance Methods

-name

-name = value

From implementing class

Gets/sets the name of the font.

Arguments:

(value)

An instance of String.

-size

-size = pixelSize

From implementing class

Gets/sets the size of the font.

NOTE: In Qt GUI, setting this variable is always considered as setting the -pixelSize, while getting it will return any size set. In other GUI kits, size is always considered as pixel-size anyway. See -hasPointSize for distinction.

Arguments:

pixelSize

A Float.

-hasPointSize

From implementing class
NOTE: Only in Qt GUI

A Boolean variable indicating whether the -size is regarded as pixel-size (precise amount of pixels), or point-size (adapting to screen resolution). To change this, you need to set the size via -pixelSize or -pointSize.

-pixelSize

-pixelSize = pixelSize

From implementing class
NOTE: Only in Qt GUI

Gets or sets the pixel-size of the font. When getting, returns nil if the font has point-size instead. See -hasPointSize for distinction.

Arguments:

pixelSize

Any number, but note that floats will be rounded to integer values when setting pixel-size.

-pointSize

-pointSize = pointSize

From implementing class
NOTE: Only in Qt GUI

Gets or sets the point-size of the font. When getting, returns nil if the font has pixel-size instead. See -hasPointSize for distinction.

Arguments:

pointSize

A Float.

-setDefault (class)

From implementing class

Makes this instance of Font the default.

In Qt GUI, this is equivalent to calling *setDefault with this Font and the given class as arguments.

In other GUI kits, this is equivalent to setting the *default property.

-storeArgs

From superclass: Object

(?)

Returns:

an Array, [ name, size ].

-boldVariant

From implementing class

NOTE: On the Cocoa GUI it appendes "-Bold" to the name. This is only useful for fonts that have bold variants.

Returns:

Bold variant of the Font.

Inherited instance methods

Examples

(
w = Window.new.front;
t = StaticText(w, w.view.bounds).align_(\center);
t.string=" SUPERCOLLIDER";
)
t.font = Font("Monaco", 24);


(
var updateFont;
w = Window("Fonts", Rect(150, Window.screenBounds.height - 500, 400, 400)).front;
w.view.decorator = FlowLayout(w.view.bounds);
StaticText.new(w, Rect(5, 0, 30, 20)).string_("Font").align_(\rght);
m = PopUpMenu(w, Rect(40, 0, 250, 20));
m.items = Font.availableFonts;

StaticText.new(w, Rect(290, 0, 28, 20)).string_("Size").align_(\right);
y = PopUpMenu(w, Rect(322, 0, 50, 20));
y.items = ["6","7","8","9","10","12","13","14","18","24","36","48","60","72","96"];

t = TextView(w, Rect(10, 40, 380, 150));
t.string = "\nThe quick drowned fox jumped over the lazy blog. \n\n 0 1 2 3 4 5 6 7 8 9 ";

a = StaticText(w, 200@20).string_("The quick drowned fox").background_(Color.rand).align_(\center);
b = Button(w, 200@20).states_([["The quick drowned fox"]]).background_(Color.rand);
c = PopUpMenu(w, 200@20).items_(["The quick drowned fox"]).background_(Color.rand);

y.action = {
    var font;
    font = Font(m.items[m.value],y.items[y.value].asInteger);
    a.font_(font).refresh;
    b.font_(font).refresh;
    c.font_(font).refresh;
    t.font_(font).refresh;
};

m.action = y.action;

m.valueAction = 3;
y.valueAction = 5;
)


(
var w, f;

w = Window("Fonts", Rect(128, 64, 340, 360));
w.view.decorator = f = FlowLayout(w.view.bounds,Point(4, 4),Point(4, 2));

[
"Helvetica-Bold",
"Helvetica",
"Monaco",
"Arial",
"Gadget",
"MarkerFelt-Thin"
].do({ arg name;
    var v, s, n, spec, p, height = 16;

        v = StaticText(w, Rect(0, 0, 56, height + 2));
        v.font = Font(name, 13);
        v.string = name;

        s = Button(w, Rect(0, 0, 140, height + 2));
        s.font = Font(name, 13);
        s.states = [[name]];

        n = NumberBox(w, Rect(0, 0, 56, height + 2));
        n.font = Font(name, 13);
        n.object = pi;

    f.nextLine;
});

w.front;
)


(
var w, f, i = 0;

w = Window("Fonts", Rect(128, 64, 820, 760));
b = ScrollView(w, w.view.bounds);

b.decorator = f = FlowLayout(b.bounds, Point(4,4), Point(4,2));

Font.availableFonts.do({ arg name;
    var v, s, n, spec, p, height = 16, font;
    font = Font(name,13);

        v = StaticText(b, Rect(0, 0, 56, height + 2));
        v.font = font;
        v.string = name;

        s = Button(b, Rect(0, 0, 140, height + 2));
        s.font = font;
        s.states = [[name]];
        s.action = { font.asCompileString.postln; };

        n = NumberBox(b, Rect(0, 0, 56, height + 2));
        n.font = font;
        n.object = pi;
    if( (i = i + 1) % 3 == 0,{
        f.nextLine;
    });
});

w.front;
)