SVGFonts- Fonts from the SVG-Font format

Safe HaskellNone




textSVG :: String -> Double -> Path R2Source

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

 import Graphics.SVGFonts

 textSVGExample = stroke $ 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.

 import Graphics.SVGFonts

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

 textPic0 = (text' "Hello World") # 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.

 import Graphics.SVGFonts

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

 textPic1 = text'' "Hello World"

data FontData 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) )




fontDataGlyphs :: SvgGlyphs
fontDataKerning :: Kern
fontDataBoundingBox :: [Double]
fontDataFileName :: String
fontDataUnderlinePos :: Double
fontDataUnderlineThickness :: Double
fontDataOverlinePos :: Maybe Double
fontDataOverlineThickness :: Maybe Double
fontDataStrikethroughPos :: Maybe Double
fontDataStrikethroughThickness :: Maybe Double
fontDataHorizontalAdvance :: Double
fontDataFamily :: String
fontDataStyle :: String
fontDataWeight :: String
fontDataVariant :: String
fontDataStretch :: String
fontDataSize :: Maybe String
fontDataUnitsPerEm :: Double
fontDataPanose :: String
fontDataSlope :: Maybe Double
fontDataAscent :: Double
fontDataDescent :: Double
fontDataXHeight :: Double
fontDataCapHeight :: Double
fontDataAccentHeight :: Maybe Double
fontDataWidths :: Maybe String
fontDataHorizontalStem :: Maybe Double

This data is not available in some fonts (e.g. Source Code Pro)

fontDataVerticalStem :: Maybe Double

This data is not available in some fonts (e.g. Source Code Pro)

fontDataUnicodeRange :: String
fontDataRawKernings :: [(String, [String], [String], [String], [String])]
fontDataIdeographicBaseline :: Maybe Double
fontDataAlphabeticBaseline :: Maybe Double
fontDataMathematicalBaseline :: Maybe Double
fontDataHangingBaseline :: Maybe Double
fontDataVIdeographicBaseline :: Maybe Double
fontDataVAlphabeticBaseline :: Maybe Double
fontDataVMathematicalBaseline :: Maybe Double
fontDataVHangingBaseline :: Maybe Double

(k, g1, g2, u1, u2)


openFont :: FilePath -> FontDataSource

Open an SVG-Font File and extract the data

type SvgGlyphsSource


 = 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

data Kern Source


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



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


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


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



Every glyph has a unique horiz. advance


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:, contains a lot of unicode characters

lin2 :: (FontData, OutlineMap)Source

Linux Libertine, cut to contain only the most common characters, resulting in a smaller file and hence a quicker load time.