## SwingOSC – Java-based GUI classes

This class is meant as an emulation of Font. last mod: 17-Jul-09 sciss

no-op / not working
antiAliasing_ | has no effect
smoothing_ | has no effect
different behaviour
availableFonts | needs to be called asynchronously the first time
extended functionality
style | extra field for plain / bold / italic

# JFont

Note: please use the abstraction layer Font if possible!

`JFont` is a typeface description that can used with some JSCView objects to define the type of font used for text rendering. JSCStaticText, JSCButton, JSCNumberBox, JSCDragView, JSCDragSink, JSCDragBoth, JSCCheckBox can set their fonts.

Besides, fonts can be used in user generated views : see JSCUserView and JPen for details.

## Instantiation

    	JFont.new( <name>, <size>, [ <style> ] )

- `name` – a String of the font face name
- `size` – the Integer font size in points
- `style` – an Integer of `0` (plain = default), `1` (bold), `2` (italic) or a combination of these.
  Note: `style` is not supported for cocoa fonts (you use special font names instead), so it is advised to not use it if possible.

Example:

    (
    var w,f;

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

    [
    "Helvetica",
    "Futura",
    "Courier",
    "Times",
    "Lucida Grande",
    "Monotype Corsiva"

    ].do({ arg name;
        var v, s, n, spec, p, height = 16;

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

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

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

        f.nextLine;
    });

    w.front;
    )

## Retrieving All Available Fonts

        JFont.availableFonts

Note: on SwingOSC this call is asynchronous the first time, because the names must be fetched from the server. this requires that the call is placed inside a Routine. Successive calls can be carried out normally. You can avoid the extra hassle by calling `*availableFonts` once in your startup procedure like this:

        { JFont.availableFonts }.fork( AppClock );

Example:

    (
    var w, f, t, c, names, range, char, start, stop, lastStop, fontSize = 14; // change fontSize if you like

    w       = JSCWindow( "Fonts", Rect( 128, 128, 800, (fontSize + 9) * 20 + 80 ), resizable: false );
    t       = JSCTabbedPane( w, w.view.bounds );
    names   = JFont.availableFonts;
    stop        = 0;
    lastStop    = stop;
    while({ stop < names.size }, {
        if( names[ stop ].first != char, {
            char    = names[ stop ].first;
            start   = stop;
        });
        stop = stop + 1;
        if( (((stop - lastStop) % 60) == 0) || (stop == names.size), {
            if( (stop < names.size) && (start > lastStop), {
                stop = start;
            });
            c = JSCCompositeView( t, t.bounds );
            c.decorator = f = FlowLayout( c.bounds, 4 @ 4, 4 @ 2 );
            range = names.copyRange( lastStop, stop - 1 );
            t.setTitleAt( t.numTabs - 1, range.first.first ++ " ... " ++ range.last.first );
            range.do({ arg name, i; var font;
                font = JFont( name, 13 );

                JSCStaticText( c, Rect( 0, 0, 56, fontSize + 7 ))
                    .font_( font )
                    .string_( name );

                JSCButton( c, Rect( 0, 0, 140, fontSize + 7 ))
                    .font_( font )
                    .states_([[ name ]])
                    .action_({ font.postcs });

                JSCNumberBox( c, Rect( 0, 0, 56, fontSize + 7 ))
                    .font_( font )
                    .object_( pi );

                if( (i = i + 1) % 3 == 0, { f.nextLine });
            });
            lastStop = stop;
        });
    });
    t.value = 0;
    w.front;
    )

## Logical Names and Variants

Since it typically depends on your platform which fonts are available, convenient methods are provided to access some standard types of fonts and to get variants of fonts:

        JFont.defaultSansFace
        JFont.defaultSerifFace
        JFont.defaultMonoFace
        <aFont>.boldVariant

Example:

    (
    var w, f, font;

    w = JSCWindow( "Fonts", Rect( 256, 256, 240, 120 ), resizable: false );
    w.view.decorator = f = FlowLayout( w.view.bounds, 4 @ 4, 4 @ 2 );

    [
    "sans",  JFont.defaultSansFace,
    "serif", JFont.defaultSerifFace,
    "mono",  JFont.defaultMonoFace
    ].pairsDo({ arg label, name;
        font = JFont( name, 14 );
        JSCStaticText( w, Rect( 0, 0, 100, 22 ))
            .font_( font )
            .string_( label );
        font = font.boldVariant;
        JSCStaticText( w, Rect( 0, 0, 100, 22 ))
            .font_( font )
            .string_( label ++ "-bold" );
        f.nextLine;
    });

    w.front;

    )