Skip to main content

Glyph - 2.0.0.a

Pygame typesetting library

Chandler Armstrong
glyph is a library for manipulating text and printing it to a pygame window.

so what? there are about a million pygame libraries to do that already.

glyph is different for a few reasons:

1) glyph provides a within string literal mini-language for text manipulation. you can use the mini-language to indicate what you want exactly where you want it, all right within the string literal.

2) glyph provides typesetting like functionality: positioning text, wrapping text, justifying text, scrolling text, switching font, text color, background color, even inserting images into text

3) glyph provides 'linked' text: text that returns a value whenever the mouse is hovering over it. this can be used to route the user around your program, or provide tooltips.

one simple object, the Glyph object, provides all this functionality. how? because Glyph interprets a mini-language, provided in string literals, that indicates how the Glyph object should treat text.


With this new release, glyph now offers in-text typesetting commands. to my knowledge, glyph is the only pygame package offering this capability. this allows you to use a mini-language to provide commands in the text to do things such as change fonts, color text, or making text selectable. this sort of functionality is invaluable for games or interfaces which must use a lot of text.

This is an alpha release, and changes may occur in the mini-language. I asked interested users to try out glyph and let me know what they think of the syntax, and suggest any improvements.

please note that glyph-2.0.0 and later versions will not be compatible with any earlier versions.

below is a quick description of the mini-language syntax. it is modeled after LaTeX environment syntax, and is pretty simple, but get's the job done.

glyph accepts special commands given through markup in text. using these commands, glyph can be told to color text, or to treat words as 'selectable', and return that they are selected when the mouse is hovering over them.

the commands given to glyph are called 'environments'. all text inside of an environment is treated according to the environemnt type. for example, text can be italicized by starting an italics font environment, and all text inside the environment will be blitted to the screen as the italics font.

environments are started with a left curly bracket '{', and terminated with a right curly bracket '}'. the first text following the left curly bracket is the type of the environment. currently, the following types are available:

* font - tells glyph that this font should be used in this environment
* color - tells glyph that this color should be used in this environment

environments can be nested, however there can never be the same types nested together. thus, one font environment cannot be nested inside of another, but a color environment can be nested in a font environment (allowing for a different font of a different color).

immediately following the environment type are the arguments. the arguments specify what the environment will do to the text within it. arguments must be seperated with commas and terminated with a semi-colon. below are the environments and the arguments they expect:

* font file, size
- file is the path to the directory containing the font file
- size will be the size of the font

* color RGB
- RGB is an RGB color tuple

below are some example environments:

glyph can {font fonts\\silkscreen_bold, 8; bold} text for you.
it can also {color (255, 0, 0); color} text for you.
it can even {font fonts\\silkscreen_bold, 8; nest these {color (255, 0, 0); features} for you}.

the environments and arguments can become cumbersome to type out. fortunately, glyph can store macros, that will allow long rules to be abbreviated. to do this, simply add an entry to the glyph.Macro dictionary, with the key being the abbreviation, and the value being the rule type and rule:

glyph.Macros['b'] = ('font', 'silkscreen_bold, 8')
glyph.Macros['red'] = ('color', '(255, 0, 0)')

with macros set, simply use the abbreviation at the start of environments rather than the name and argument list:

glyph can {b bold} text for you.
it can also {red color} text for you.
it can even {b nest these {red features} for you}.

NOTE: glyph recognizes all standard textual commands such as newlines (\n) and newpages (\f).


Home Page


Glyph 2.5.4rc — 27 Jul, 2011

Glyph 2.6.0b — 6 Jul, 2012

Glyph 2.6.5 — 23 Dec, 2012

Glyph 1.1.0 — 10 Jan, 2009

Glyph 1.0.0 — 3 Jan, 2009

Glyph 1.2.0 — 14 Jan, 2009

Glyph 2.5.3rc — 9 Jul, 2011

Glyph 2.4.0 — 12 Dec, 2010

Glyph 2.5.0 — 2 Mar, 2011

Glyph 2.5.2rc — 25 Jun, 2011

Glyph 2.5.1 — 27 Mar, 2011

Glyph 2.0.0.a — 18 Jul, 2010

Glyph 2.0.0.a2 — 1 Aug, 2010

Glyph 2.1.0b — 5 Oct, 2010 account Comments

  • pooootrick 2013-05-07 08:11:56

    yaaaaay pygame