SVGFonts

Fonts from the SVG-Font format

Version on this page:1.4.0.3
LTS Haskell 22.17:1.8.0.1
Stackage Nightly 2024-04-19:1.8.0.1
Latest on Hackage:1.8.0.1

See all snapshots SVGFonts appears in

BSD-3-Clause licensed by Tillmann Vogt
Maintained by [email protected]
This version can be pinned in stack with:SVGFonts-1.4.0.3@sha256:ed735174ec5a253f36457a1735e68b10dda0d94e57f1a00ed0f73210977e252e,3510

SVGFonts

Native font support for the Diagrams library. The SVG-Font format is easy to parse and was therefore chosen for a font library completely written in Haskell.

You can convert your own font to SVG with http://fontforge.sourceforge.net/ or use the included LinLibertine, Bitstream.

Features

Complete implementation of the features that fontforge produces (but not the complete SVG format):

  • Kerning (e.g. the two characters in “VA” have a shorter distance than in “VV”)
  • Unicode
  • Ligatures
  • Text boxes with syntax highlighting

XML speed issues can be solved by trimming the svg file to only those characters that are used (or maybe binary xml one day)

Version 1.0 of this library supports texturing which would only make sense in a Diagrams Backend that does rasterization in Haskell.

Example

{-# LANGUAGE NoMonomorphismRestriction #-}

import Diagrams.Prelude
import Diagrams.Backend.Cairo.CmdLine
import Graphics.SVGFonts.ReadFont

main = defaultMain ( (text' "Hello World") <> (rect 8 1) # alignBL )

text'  t = stroke (textSVG t 1) # fc purple # fillRule EvenOdd
text'' t = stroke (textSVG_ $ TextOpts t lin INSIDE_H KERN 1 1 )
             # fc purple # fillRule EvenOdd

Usage

Convert your favourite font (i.e. .ttf) into a .svg file with fontforge (the menu item under “Save All”). If a font converted on your own doesn’t work, try the repair options, and if this still doesn’t work edit the file by hand or tell me. Remember that a lot of fonts are not allowed to be distributed freely.

Changes

1.4.0.3 (2 June 2014)

  • Allow diagrams-lib-1.2.

1.4.0.1 (25 November 2013)

  • Bump diagrams-lib upper bound to < 1.1.

1.4 (10 September 2013)

  • FontData can now be written back to SVG using makeSvgFont inside of the WriteFont module. It is possible to only write back a specfic set of glyphs.
  • The SVG font-face element is now completely supported. This means all possible attributes are read and written back to it. Correct defaults are also set on non optional attributes. Some optional attributes are still required though, due to their use in font rendering.
  • The ReadPath module does not use unsafePerformIO anymore. ReadFont is now the only module with unsafe calls.
  • Minor bug fixes:
    • stemh and stemv are now optional attributes.

1.3.0.2 (14 August 2013)

  • remove old comment causing Haddock build to fail

1.3.0.1 (12 August 2013)

  • fix repo location in .cabal file

1.3: 9 August 2013

  • A bunch of bug fixes, cleanup, and reorganization:
    • Proper data type for Kern and FontData instead of mega-tuples.
    • Fixed several Prelude.read error on font-face attributes.
    • Fixed wrong attribute names.
    • Switched to data-default-class instead of data-default.
  • Require diagrams-lib-0.7.