Project

General

Profile

Font Control in 4GL Widgets

Introduction

The features were implemented in #3876 which was committed to trunk as revision 11315. The first public release is FWD v4.0.

Original 4GL Approach

OpenEdge provides very weak support for fonts. One must define a set of fonts for your environment and at runtime assign fonts from this predefined set.

To configure the FONT-TABLE:

  1. Define a set of static fonts in your environment (e.g. an .ini file) and load them into the FONT-TABLE at session startup; OR
  2. Force the user to interactively pick a font using SYSTEM-DIALOG GET-FONT which edits the FONT-TABLE.

One cannot programmatically modify the FONT-TABLE or the attributes of any given entry in the FONT-TABLE. One can only use the FONT-TABLE as defined, referencing a specific font in a widget by one of the valid numeric indexes from the FONT-TABLE. You can switch environments at runtime from a set of predefined configuratons, but you cannot dynamically control/edit the FONT-TABLE entries using 4GL code (e.g. methods/attributes).

Enhanced Approach

FWD introduces new font-related attributes. The attributes can be used on all widgets that render text. This provides full dynamic/runtime control from 4GL code over the following:

  • font name
  • font size
  • font styles (bold, italics, underline)

One just directly sets the font attributes into the widget.

Attributes

Attribute Name Type Read Only Default Description
FONT-NAME CHARACTER FALSE ? Font name as defined in the server directory (custom-fonts container) or the system font name. The system font name is one of the available Java runtime fonts (given by java.awt.GraphicsEnvironment.getAvailableFontFamilyNames) in case of Swing GUI driver or one of the supported web browser fonts in case of Web GUI driver. Bitmapped fonts are not supported. When the font name doesn't yield a valid font the widget will be drawn using the font set in the FONT attribute (the legacy 4GL approach).

Please note that bitmap fonts are not supported in FWD. Bitmap (a.k.a. raster) fonts are not natively supported in Java or in web browsers. They are a very old font technology which is device dependent. This means it is fixed size and does not scale well. In a world of many devices with different resolutions, bitmap fonts are a poor fit. For this reason, FWD has not implemented a 3rd party rendering engine for these fonts. Unfortunately, the 4GL on Windows often uses bitmap fonts (examples are system or FixedSys). They cannot be used in FWD, however FWD does have good replacements available as freely licensed TrueType (vector) fonts.

Example set of valid values for Swing GUI client: Serif, SansSerif, Monospaced.
Example set of valid values for Web GUI client: Arial, Times New Roman, Courier.
FONT-SIZE INTEGER FALSE ? Font point size. This point size defines a measurement between the baseline of one line to the baseline of the following line in a single spaced text document. The point size is based on typographic points, approximately 1/72 of an inch. When the font size doesn't yield a valid font the widget will be drawn using the font set in the FONT attribute (the legacy 4GL approach).
FONT-BOLD LOGICAL FALSE FALSE A flag that controls text rendering. When TRUE the text is rendered in bold. When the value doesn't yield a valid font the widget will be drawn using the font set in the FONT attribute (the legacy 4GL approach).
FONT-ITALIC LOGICAL FALSE FALSE A flag that controls text rendering. When TRUE the text is rendered as italic. When the value doesn't yield a valid font the widget will be drawn using the font set in the FONT attribute (the legacy 4GL approach).
FONT-UNDERLINE LOGICAL FALSE FALSE A flag that controls text rendering. When TRUE the text is rendered underlined. When the value doesn't yield a valid font the widget will be drawn using the font set in the FONT attribute (the legacy 4GL approach).

Example

DEF VAR edit AS CHAR VIEW-AS FILL-IN SIZE 50 BY 2 LABEL "Sample text" FORMAT "x(50)".

DEFINE VARIABLE fonts AS CHARACTER NO-UNDO
  VIEW-AS SELECTION-LIST INNER-CHARS 15 INNER-LINES 10 SORT
  LABEL "Select font" .

DEF VAR fsize AS INT INITIAL 12 VIEW-AS FILL-IN FORMAT 99 LABEL "Size".
DEF VAR bold AS LOGICAL VIEW-AS TOGGLE-BOX LABEL "Bold".
DEF VAR italic AS LOGICAL VIEW-AS TOGGLE-BOX LABEL "Italic".
DEF VAR lunderline AS LOGICAL VIEW-AS TOGGLE-BOX LABEL "Underline".
DEF BUTTON bapply label "Apply".

DEF FRAME f edit SKIP(2) fonts fsize bold italic lunderline SKIP bapply WITH SIDE-LABELS.

edit:SCREEN-VALUE = "Sample text".
fsize:SCREEN-VALUE = "12".

fonts:ADD-LAST("<none>").

/* these font names should work in Swing GUI client */
fonts:ADD-LAST("Serif").
fonts:ADD-LAST("SansSerif").
fonts:ADD-LAST("Monospaced").
fonts:ADD-LAST("Dialog").
fonts:ADD-LAST("DialogInput").

/* these font names should work in Web GUI client */
fonts:ADD-LAST("Arial").
fonts:ADD-LAST("Times New Roman").
fonts:ADD-LAST("Courier New").
fonts:ADD-LAST("Courier").

ENABLE ALL WITH FRAME f.

ON 'choose':U OF bapply
DO:
    edit:font-name = fonts:screen-value.
    edit:font-size = integer(fsize:screen-value).
    edit:font-bold = bold:checked.
    edit:font-italic = italic:checked.
    edit:font-underline = lunderline:checked.
END.

WAIT-FOR CLOSE OF THIS-PROCEDURE.

Future Improvements

The following improvement is planned:

  • #4611 create Java API for font enumeration (this will be callable from 4GL code using direct Java access AND it will support both the Swing and Web clients)

© 2019-2020 Golden Code Development Corporation. ALL RIGHTS RESERVED.

Screenshot from 2020-04-16 21-52-10.png (17 KB) Hynek Cihlar, 04/16/2020 03:53 PM