The SVGFonts package

[ Tags: bsd3, graphics, library ] [ Propose Tags ]

Native font support for the diagrams framework (http://projects.haskell.org/diagrams/). Note that this package can be used with any diagrams backend, not just the SVG backend. 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.github.io/, or use the included LinLibertine and Bitstream fonts.

Features:

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, though this only makes sense in a diagrams backend that does rasterization in Haskell, such as diagrams-rasterific.

Example:

 # LANGUAGE NoMonomorphismRestriction #

import Diagrams.Prelude
import Diagrams.Backend.Rasterific.CmdLine
import Graphics.SVGFonts

main = defaultMain (text' "Hello World")

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

[Skip to Readme]

Properties

Versions 0.1, 0.2, 0.3, 0.4, 1.0, 1.1, 1.1.1, 1.1.2, 1.2, 1.2.1, 1.3, 1.3.0.1, 1.3.0.2, 1.4, 1.4.0.1, 1.4.0.2, 1.4.0.3, 1.5.0.0, 1.5.0.1, 1.6.0.0, 1.6.0.1, 1.6.0.2, 1.6.0.3
Change log CHANGES.md
Dependencies attoparsec, base (==4.*), blaze-markup (>=0.5), blaze-svg (>=0.3.3), bytestring (>=0.10 && <1.0), cereal, cereal-vector, containers (>=0.4 && <0.6), data-default-class (<0.2), diagrams-core (>=1.3 && <1.5), diagrams-lib (>=1.3 && <1.5), directory (>=1.1), parsec, split, text, tuple, vector, xml [details]
License BSD3
Author Tillmann Vogt
Maintainer diagrams-discuss@googlegroups.com
Category Graphics
Source repository head: git clone https://github.com/diagrams/SVGFonts.git
Uploaded Tue Sep 26 03:05:00 UTC 2017 by BrentYorgey
Distributions LTSHaskell:1.6.0.3, NixOS:1.6.0.2, Tumbleweed:1.6.0.1
Downloads 10477 total (1135 in the last 30 days)
Rating 0.0 (0 ratings) [clear rating]
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2017-09-26 [all 1 reports]
Hackage Matrix CI

Modules

[Index]

Downloads

Maintainer's Corner

For package maintainers and hackage trustees


Readme for SVGFonts-1.6.0.3

[back to package description]

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

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

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

-- using a local font
text''' t = do
    font <- loadFont "path/to/font.xml"
    return $ stroke (textSVG' (TextOpts font INSIDE_H KERN False 1 1) t)

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.