plotfont-0.1.0.0: Plotter-like fonts i.e. a series of straight lines which make letter shapes.

Copyright(c) 2015, M J Oldfield
StabilityExperimental
Safe HaskellSafe
LanguageHaskell2010

Graphics.PlotFont

Description

Rationale

There are many good looking fonts which optimize for appearance. I wanted some cruder fonts which had a simpler representation: a relatively small number of straight lines which could easily be plotted by a machine, or perhaps a person.

So this might be a good package for you if you're going to do something with the coordinates afterwards, but not if you just want to render some text.

License discussion

My code is licensed under the GPL version 2 or later see http://www.gnu.org/copyleft/gpl.html

The data in canvasText and fallbackGlyph come from Jim Studt's canvastext.js: http://jim.studt.net/canvastext/ which he placed in the public domain. He cites the original source as the Hershey fonts: https://en.wikipedia.org/wiki/Hershey_fonts

The Hershey fonts appear to have this license:

  1. The following acknowledgements must be distributed with the font data: - The Hershey Fonts were originally created by Dr. A. V. Hershey while working at the U. S. National Bureau of Standards. - The format of the Font data in this distribution was originally created by James Hurt Cognition, Inc. 900 Technology Park Drive Billerica, MA 01821 (mit-eddie!ci-dandelion!hurt)
  2. The font data in this distribution may be converted into any other format *EXCEPT* the format distributed by the U.S. NTIS (which organization holds the rights to the distribution and use of the font data in that particular format). Not that anybody would really *want* to use their format... each point is described in eight bytes as "xxx yyy:", where xxx and yyy are the coordinate values as ASCII numbers.

It is not clear to me if Mr Studt used 'this distribution'.

Synopsis

Documentation

data PlotFont Source

The PlotFont type wraps the basic font: a map from Char to PFGlyph

type PFStroke = [PFPoint] Source

PFStroke is the basic graphic element: a series of points joined by straight lines.

type PFGlyph = (PFWidth, [PFStroke]) Source

PFGlyph is the basic element of the font: the symbol's width, plus the strokes we need to draw it.

render :: PlotFont -> String -> Either String [PFStroke] Source

Given a PlotFont and a String, return

render' :: PlotFont -> String -> [PFStroke] Source

A varient of render which replaces unknown characters with a question mark.

It is guaranteed to render something, and thus useful if you want to ignore the possibility of errors e.g. because you're manually checking the output.

optimizeStrokes :: [PFStroke] -> [PFStroke] Source

Given a set of strokes, try to optimize their order and direction so as to prefer:

  • fewer strokes;
  • smaller gaps between strokes;
  • left-most starting position;
  • bottom-most starting position.

The code does a reasonable job of improving fonts where no thought has been given to this, but hand-tweaking is still better.

canvastextFont :: PlotFont Source

The Hershey font used by canvastext.js which provides !"#$%&()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[]^_`abcdefghijklmnopqrstuvwxyz{|}~