Safe Haskell | None |
---|---|
Language | Haskell2010 |
Module in charge of loading fonts.
Synopsis
- decodeFont :: ByteString -> Either String Font
- loadFontFile :: FilePath -> IO (Either String Font)
- getStringCurveAtPoint :: Dpi -> (Float, Float) -> [(Font, PointSize, String)] -> [[Vector (Float, Float)]]
- unitsPerEm :: Font -> Word16
- isPlaceholder :: Font -> Char -> Bool
- getCharacterGlyphsAndMetrics :: Font -> Char -> (Float, Vector RawGlyph)
- getGlyphForStrings :: Dpi -> [(Font, PointSize, String)] -> [[Vector (Float, Float)]]
- stringBoundingBox :: Font -> Dpi -> PointSize -> String -> BoundingBox
- findFontOfFamily :: String -> FontStyle -> IO (Maybe FilePath)
- pointInPixelAtDpi :: PointSize -> Dpi -> Float
- pixelSizeInPointAtDpi :: Float -> Dpi -> PointSize
- data FontCache
- data FontDescriptor = FontDescriptor {}
- emptyFontCache :: FontCache
- findFontInCache :: FontCache -> FontDescriptor -> Maybe FilePath
- buildCache :: IO FontCache
- enumerateFonts :: FontCache -> [FontDescriptor]
- descriptorOf :: Font -> Maybe FontDescriptor
- data Font
- data FontStyle = FontStyle {
- _fontStyleBold :: !Bool
- _fontStyleItalic :: !Bool
- data RawGlyph = RawGlyph {
- _rawGlyphCompositionScale :: ![CompositeScaling]
- _rawGlyphIndex :: !Int
- _rawGlyphContour :: ![Vector (Int16, Int16)]
- type Dpi = Int
- newtype PointSize = PointSize {}
- data CompositeScaling = CompositeScaling {}
- data BoundingBox = BoundingBox {}
Functions
decodeFont :: ByteString -> Either String Font #
Decode a in-memory true type file.
loadFontFile :: FilePath -> IO (Either String Font) #
Load a font file, the file path must be pointing to the true type file (.ttf)
:: Dpi | Dot per inch of the output. |
-> (Float, Float) | Initial position of the baseline. |
-> [(Font, PointSize, String)] | Text to draw |
-> [[Vector (Float, Float)]] | List of contours for each char |
Extract a list of outlines for every char in the string. The given curves are in an image like coordinate system, with the origin point in the upper left corner.
unitsPerEm :: Font -> Word16 #
Return the number of pixels relative to the point size.
isPlaceholder :: Font -> Char -> Bool #
True if the character is not present in the font, therefore it will appear as a placeholder in renderings.
getCharacterGlyphsAndMetrics #
Retrive the glyph contours and associated transformations. The coordinate system is assumed to be the TTF one (y upward). No transformation is performed.
getGlyphForStrings :: Dpi -> [(Font, PointSize, String)] -> [[Vector (Float, Float)]] #
This function return the list of all contour for all char with the given
font in a string. All glyph are at the same position, they are not placed
like with getStringCurveAtPoint
. It is a function helpful to extract
the glyph geometry for further external manipulation.
stringBoundingBox :: Font -> Dpi -> PointSize -> String -> BoundingBox #
Compute the bounding box of a string displayed with a font at a given size. The resulting coordinate represent the width and the height in pixels.
findFontOfFamily :: String -> FontStyle -> IO (Maybe FilePath) #
This function will scan the system's font folder to find a font with the desired properties. Favor using a FontCache to speed up the lookup process.
pointInPixelAtDpi :: PointSize -> Dpi -> Float #
pixelSizeInPointAtDpi :: Float -> Dpi -> PointSize #
Font cache
A font cache is a cache listing all the found fonts on the system, allowing faster font lookup once created
FontCache is an instance of binary, to get okish performance you should save it in a file somewhere instead of rebuilding it everytime!
The font cache is dependent on the version of rasterific, you must rebuild it for every version.
data FontDescriptor #
A font descriptor is a key used to find a font in a font cache.
FontDescriptor | |
|
Instances
Eq FontDescriptor # | |
Defined in Graphics.Text.TrueType.FontFolders (==) :: FontDescriptor -> FontDescriptor -> Bool # (/=) :: FontDescriptor -> FontDescriptor -> Bool # | |
Ord FontDescriptor # | |
Defined in Graphics.Text.TrueType.FontFolders compare :: FontDescriptor -> FontDescriptor -> Ordering # (<) :: FontDescriptor -> FontDescriptor -> Bool # (<=) :: FontDescriptor -> FontDescriptor -> Bool # (>) :: FontDescriptor -> FontDescriptor -> Bool # (>=) :: FontDescriptor -> FontDescriptor -> Bool # max :: FontDescriptor -> FontDescriptor -> FontDescriptor # min :: FontDescriptor -> FontDescriptor -> FontDescriptor # | |
Show FontDescriptor # | |
Defined in Graphics.Text.TrueType.FontFolders showsPrec :: Int -> FontDescriptor -> ShowS # show :: FontDescriptor -> String # showList :: [FontDescriptor] -> ShowS # | |
Binary FontDescriptor # | |
Defined in Graphics.Text.TrueType.FontFolders |
Font cache with no pre-existing fonts in it.
findFontInCache :: FontCache -> FontDescriptor -> Maybe FilePath #
Try to find a font with the given properties in the font cache.
buildCache :: IO FontCache #
This function will search in the system for truetype files and index them in a cache for further fast search.
enumerateFonts :: FontCache -> [FontDescriptor] #
Returns a list of descriptors of fonts stored in the given cache.
descriptorOf :: Font -> Maybe FontDescriptor #
If possible, returns a descriptor of the Font.
Types
Type representing a font.
Describe the basic stylistic properties of a font.
FontStyle | |
|
This type represent unscaled glyph information, everything is still in its raw form.
RawGlyph | |
|
Font size expressed in points. You must convert size expressed in pixels to point using the DPI information. See pixelSizeInPointAtDpi
data CompositeScaling #
Transformation matrix used to transform composite glyph
| a b | | c d |
Instances
Eq CompositeScaling # | |
Defined in Graphics.Text.TrueType.Glyph (==) :: CompositeScaling -> CompositeScaling -> Bool # (/=) :: CompositeScaling -> CompositeScaling -> Bool # | |
Show CompositeScaling # | |
Defined in Graphics.Text.TrueType.Glyph showsPrec :: Int -> CompositeScaling -> ShowS # show :: CompositeScaling -> String # showList :: [CompositeScaling] -> ShowS # |
data BoundingBox #
String bounding box. with value for min/max.
Instances
Eq BoundingBox # | |
Defined in Graphics.Text.TrueType (==) :: BoundingBox -> BoundingBox -> Bool # (/=) :: BoundingBox -> BoundingBox -> Bool # |