SVGFonts-1.2.1: Fonts from the SVG-Font format

Safe HaskellNone

Graphics.SVGFonts.ReadFont

Synopsis

Documentation

textSVG :: String -> Double -> Path R2Source

A short version of textSVG' with standard values. The Double value is the height.

 {-# LANGUAGE NoMonomorphismRestriction #-}

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

main = defaultMain (textSVG "Hello World" 1)

textSVG' :: TextOpts -> Path R2Source

The origin is at the center of the text and the boundaries are given by the outlines of the chars.

 {-# LANGUAGE NoMonomorphismRestriction #-}

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

main = defaultMain (text' "Hello World")
text' t = stroke (textSVG' $ TextOpts t lin INSIDE_H KERN False 1 1 )
          # fc blue # lc blue # bg lightgrey # fillRule EvenOdd # showOrigin

textSVG_ :: forall b. Renderable (Path R2) b => TextOpts -> QDiagram b R2 AnySource

The origin is at the left end of the baseline of of the text and the boundaries are given by the bounding box of the Font. This is best for combining Text of different fonts and for several lines of text. As you can see you can also underline text by setting underline to True.

 {-# LANGUAGE NoMonomorphismRestriction #-}

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

main = defaultMain (text'' "Hello World")

text'' t = (textSVG_ $ TextOpts t lin INSIDE_H KERN True 1 1 )
           # fc blue # lc blue # bg lightgrey # fillRule EvenOdd # showOrigin

type FontData = (SvgGlyph, Kern, [Double], String, (Double, Double), (Double, String, String, String, String, String, String, String, String, String, String, String, String))Source

This type contains everything that a typical SVG font file produced by fontforge contains.

(SvgGlyph, Kern, bbox-string, filename, (underlinePos, underlineThickness), (fontHadv, fontFamily, fontWeight, fontStretch, unitsPerEm, panose, ascent, descent, xHeight, capHeight, stemh, stemv, unicodeRange) )

openFont :: FilePath -> FontDataSource

Open an SVG-Font File and extract the data

type SvgGlyphSource

Arguments

 = Map String (String, Double, String)

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

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

Horizontal advances of characters inside a string. A character is stored with a string (because of ligatures like "ffi").

hadv :: String -> FontData -> DoubleSource

Horizontal advance of a character consisting of its width and spacing, extracted out of the font data

type KernSource

Arguments

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

u1s, u2s, g1s, g2s, k

See http://www.w3.org/TR/SVG/fonts.html#KernElements

Some explanation how kerning is computed:

In Linlibertine.svg, there are two groups of chars: e.g. <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

kernAdvance :: String -> String -> Kern -> Bool -> DoubleSource

Change the horizontal advance of two consective chars (kerning)

data Mode Source

Constructors

INSIDE_H

The string fills the complete height, width adjusted. Used in text editors. The result can be smaller or bigger than the bounding box:

INSIDE_W

The string fills the complete width, heigth adjusted. Maybe useful for single words in a diagram or headlines. The result can be smaller or bigger than the bounding box:

INSIDE_WH

The string is stretched inside Width and Height boundaries. The horizontal advances are increased if the string is shorter than there is space. The horizontal advances are decreased if the string is longer than there is space. This feature is experimental and might change in the future.

data Spacing Source

Constructors

HADV

Every glyph has a unique horiz. advance

KERN

Recommended, same as HADV but sometimes overridden by kerning: As You can see there is less space between "A" and "V":

ro :: FilePath -> FilePathSource

read only of static data (safe)

bbox_dy :: FontData -> DoubleSource

Difference between highest and lowest y-value of bounding box

bbox_lx :: FontData -> DoubleSource

Lowest x-value of bounding box

bbox_ly :: FontData -> DoubleSource

Lowest y-value of bounding box

underlinePosition :: FontData -> DoubleSource

Position of the underline bar

underlineThickness :: FontData -> DoubleSource

Thickness of the underline bar

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

Generate Font Data and a Map from chars to outline paths

bit :: (FontData, OutlineMap)Source

Bitstream, a standard monospaced font (used in gedit)

lin :: (FontData, OutlineMap)Source

Linux Libertine, for non-monospaced text: http://www.linuxlibertine.org/, contains a lot of unicode characters

lin2 :: (FontData, OutlineMap)Source

Linux Libertine, cut to the most common Characters, smaller file, quicker load time