SVGFonts-1.1: Fonts from the SVG-Font format

Graphics.SVGFonts.ReadFont

Synopsis

Documentation

type KernSource

Arguments

 = (Map String [Int], Map String [Int], Map String [Int], Map String [Int], Vector Double)

u1s, u2s, g1s, g2s, k

type SvgGlyphSource

Arguments

 = Map String (String, Double, String)

[ (unicode, (glyph_name, horiz_advance, ds)) ]

type FontDataSource

Arguments

 = (SvgGlyph, Kern, [Double], String)

(SvgGlyph, Kern, bbox-string, filename)

openFont :: FilePath -> FontDataSource

Open an SVG-Font File and extract the data

Some explanation how kerning is computed:

In Linlibertine.svg, there are two groups of chars: i.e. <hkern g1="f,longs,uni1E1F,f_f" g2="parenright,bracketright,braceright" k="-37" /> This line means: If there is an f followed by parentright, reduce the horizontal advance by -37 (add 37). Therefore to quickly check if two characters need kerning assign an index to the second group (g2 or u2) and assign to every unicode in the first group (g1 or u1) this index, then sort these tuples after their name (for binary search). Because the same unicode char can appear in several g1s, reduce this multiset, ie all the ("name1",0) ("name1",1) to ("name1",[0,1]). Now the g2s are converted in the same way as the g1s. Whenever two consecutive chars are being printed try to find an intersection of the list assigned to the first char and second char

horizontalAdvances :: [String] -> FontData -> Bool -> [Double]Source

horizontal advances of characters inside a string a character is stored with a string (originally because of ligatures)

data Mode Source

Constructors

INSIDE_WH

INSIDE_WH: The string is stretched inside Width and Height boundaries

INSIDE_W

INSIDE_W: The string fills the complete width, heigth adjusted

INSIDE_H

INSIDE_H: The string fills the complete height, width adjusted

data Spacing Source

Constructors

KERN

Recommended, same as HADV but sometimes overridden by kerning: i.e. the horizontal advance in VV is bigger than in VA

HADV

Every glyph has a unique constant horiz. advance

textSVG_ :: TextOpts -> Path R2Source

Main library functions, usage:

 {-# 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_ $ TextOpts t lin INSIDE_H KERN 1 1 ) # fc purple # fillRule EvenOdd

outlMap :: String -> (FontData, OutlineMap)Source

Generate Paths of outlines