- type Kern = (Map String [Int], Map String [Int], Map String [Int], Map String [Int], Vector Double)
- type SvgGlyph = Map String (String, Double, String)
- type FontData = (SvgGlyph, Kern, [Double], String)
- openFont :: FilePath -> FontData
- horizontalAdvances :: [String] -> FontData -> Bool -> [Double]
- kernAdvance :: String -> String -> Kern -> Bool -> Double
- type OutlineMap = Map String (Path R2)
- data Mode
- data Spacing
- type FileName = String
- textSVG :: String -> Double -> Path R2
- data TextOpts = TextOpts {}
- textSVG_ :: TextOpts -> Path R2
- outlMap :: String -> (FontData, OutlineMap)
- commandsToTrails :: [PathCommand] -> [Segment R2] -> R2 -> R2 -> R2 -> [Path R2]
- commands :: String -> SvgGlyph -> [PathCommand]
Documentation
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)
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
commandsToTrails :: [PathCommand] -> [Segment R2] -> R2 -> R2 -> R2 -> [Path R2]Source
commands :: String -> SvgGlyph -> [PathCommand]Source