User Tools

Site Tools


geda:pcb_fonts

This is an old revision of the document!


Fonts

A font system has been implemented in the git branch home/cparker/font_fun. This system was initially designed by Chad Parker. The initial set of fonts were converted for PCB by Erich Heinzle. With this system, the font of a design can be easily changed, and multiple fonts can be used in the same design. This system also reduces the need to store font data in saved design files, because a font name should be forever. If a font ever changes, it should be given a new name. So, saved designs can reference only the font name without having to worry about the font changing and a design being different when it is next opened.

Usage

Getting the Feature Branch

To test the font system, check out the feature branch from git. Switch to the feature branch with

git checkout home/cparker/font_fun

reconfigure if necessary and build. Then, run pcb by executing the pcbtest.sh script in the src directory. This is important because it sets the font path so that pcb can load some of the included fonts.

Font Settings

All font settings can be viewed and edited from the Fonts tab in the preferences window.

There are three font related options that can be configured:

  • “Save font data in files”
    When enabled, this will save the font of text objects in saved design files. If disabled, it will not, and the design will be backwards compatible with older versions of pcb.
  • “Save current system font as symbols in pcb files (old format).”
    This option is only available when “Save font data in files” is disabled. This option does exactly what it says. This is how you can save a font in a design file that is compatible with older versions of pcb.
  • “Embed used fonts in pcb files”
    This option is only available when “Save font data in files” is enabled. This option will store the font information of every font used in the design into the saved pcb file. This makes the pcb file portable to other systems that may not have the same fonts installed, or a different version of a font installed.

There are two fonts that can be configured:

  • System font:
    The system font is used for all new objects that are added to the design, and also for system generated text such as pin numbers and pin functions. System font information is not stored in saved designs.
  • PCB font:
    The PCB font is stored in saved files as the default font for a design. It is used for any texts that cannot be assigned a font, presently reference designators. It's also the font that is assigned to any texts that don't have a specific font assigned when the design is loaded. The system font is set to this after loading.
If a design is loaded and requests a font that is not on the system, it will issue a warning to the message log and the text will be displayed using the system font. If the system font is changed, it will also change. (This behavior should be reviewed.)

Font Libraries

There are two font libraries:

  • System Font Library:
    This library contains all of the fonts that pcb knows about that are stored on the local system. Fonts can be loaded and unloaded from this library using actions. This functionality is not yet available in the preferences menu, but it is planned to be eventually.
  • Embedded Font Library:
    This library contains the fonts that are stored in the pcb file of the current design. The only control a user has over this library is in the fonts that he or she chooses to use in the design. This library is populated whenever a pcb file is loaded. If you load a file, add an object with a different font, and choose to save the file with fonts embedded, the additional fonts will be saved in the file, but the embedded library will only be updated if you reload the pcb file. A possible future extension might be to allow the user to explicitly move fonts into the embedded library.

Changing Fonts

Fonts can be easily changed using the Fonts tab in the preferences window:

  • Open the Preferences window and switch to the Fonts tab.
  • Select the new font to be assigned to the text objects.
  • In the main window, select the text objects to which the font should be assigned.
  • Click the “Change Selected” button to assign the new font to the text objects.

Alternatively, all text in a design can have a font assigned by using the “Change All” button.

Note that these methods will only change the font of discrete text objects. Reference designators of components cannot presently have fonts assigned to them individually. However, the font of *all* reference designators can be changed together by setting the PCB Font to the desired font.

Compatibility with Older Versions of PCB

Previous versions of pcb would store the data of a single font in saved files as symbols. Alternatively, if the file did not contain symbols, perhaps because they were deleted, then pcb would load the default font instead. This feature branch will still play nicely with these scenarios.

If you load an existing design that has symbols stored in the design, the symbols will be converted into an embedded font (Font 0), all the text objects in the design will use that font, and that font will be set as the system font. If the design does not have symbols stored in it, then the text objects will be assigned the system font. So, if you've changed the system font then the text objects will not look exactly as they did when you saved them. However, If you load a design and don't like the font the text ends up in, it's easy to change the font.

Implementation

The font system is implemented using a few data structures and several actions.

Data Structures

Font Type

The font data structure is called FontType and is defined in global.h as follows:

typedef struct
{
    char * Name;
    char * SourceFile;
    Coord MaxHeight; /*!< Maximum cell width. */
    Coord MaxWidth; /*!< Maximum cell height. */
    BoxType DefaultSymbol; /*!< The default symbol is a filled box. */
    SymbolType Symbol[MAX_FONTPOSITION + 1];
    int nSymbols;
} FontType;

The MaxHeight and MaxWidth parameters are set by the SetFontInfo function that's been relocated into font.c. This structure has updated to include two new fields for the name of the font and the source file of the font.

Font Libraries

The two font libraries (system and embedded) are both implemented as GLib GSLists. Each list element points to a FontType structure. The choice of a GSList was made because its a simple structure, and at the moment I don't anticipate there being a vast database of fonts to choose from, so searching through a list ought not to take all that long. GLib includes many functions for working with GSLists, and these are used for managing and accessing the list items.

Finding Fonts

Searching through the library for a font is done by using the FindFontInLibrary function. This function iterates through the list once comparing the name of the font to the provided reference string. If a match is not found, the list is searched through again comparing the name of the source file. If it's still not found then a null is returned.

A second function, FindFont, is available for searching. This function searches first through the embedded library, and if the font is not found, it will then search through the system library. This way, the embedded library always has precedence. So, if a customized version of a font is stored in the pcb file and there is a system font with the same name, the embedded font will be used. The assumption is that if the font was explicitly stored in the file, it was done so to ensure that it was used.

Font File Format

The format for font files is basically the same as the format for symbols in complete pcb files, with one new keyword: Font. The argument of the Font keyword is the name of the font. Following the Font keyword a set of symbols using the existing pcb format are wrapped inside of normal parenthesis.

Font("Default") (
Symbol(' ' 18)
(
)
Symbol('!' 12)
(
	SymbolLine(0 35 0 40 8)
	SymbolLine(0 0 0 25 8)
)
...
) # end font

A font file can have one or more fonts defined in succession.

PCB File Format Changes

Actions

Change Font

Load Font

Unload Font

List Fonts

Processes

Startup

File Load

File Save

To Do List

These are tasks and ideas related to the font subsystem that still need to be done, could be done, or are in progress:

  • Add fonts to install (and figure out where they should go)
  • Write test scripts
  • Add documentation to doc/ tree
  • Add flow diagrams to code comments
  • Font preview in settings window
  • Character map for selecting non standard characters
  • Add licensing info to font files
  • User control of fonts in embedded library
  • Save font(s) to a file
  • “Font mode” saving of fonts to font files.
geda/pcb_fonts.1480287449.txt.gz · Last modified: 2016/11/27 17:57 by cparker