This is a wrapper around Sean Barrett's TrueType font rasterizer code.
The original can be found at http://nothings.org/stb/stb_truetype.h.
The version of stb-truetype
used here is 0.2
.
- data TrueType
- data Offset
- data FontInfo
- data Glyph
- loadTTF :: FilePath -> IO TrueType
- withTTF :: FilePath -> (TrueType -> IO a) -> IO a
- enumerateFonts :: TrueType -> IO [Offset]
- initFont :: TrueType -> Offset -> IO FontInfo
- findGlyphIndex :: FontInfo -> Char -> IO (Maybe Glyph)
- type Unscaled = Int
- data HorizontalMetrics = HMetrics {}
- data VerticalMetrics = VMetrics {}
- data BoundingBox a = BBox (a, a) (a, a)
- lineAdvance :: VerticalMetrics -> Unscaled
- verticalSize :: VerticalMetrics -> Unscaled
- scaleForPixelHeight :: VerticalMetrics -> Float -> Float
- getFontVerticalMetrics :: FontInfo -> IO VerticalMetrics
- getGlyphHorizontalMetrics :: FontInfo -> Glyph -> IO HorizontalMetrics
- getGlyphKernAdvance :: FontInfo -> Glyph -> Glyph -> IO Unscaled
- getGlyphBoundingBox :: FontInfo -> Glyph -> IO (BoundingBox Unscaled)
- type Scaling = (Float, Float)
- data Bitmap = Bitmap {
- bitmapSize :: (Int, Int)
- bitmapPtr :: ForeignPtr Word8
- newBitmap :: (Int, Int) -> IO Bitmap
- withBitmap :: Bitmap -> (Int -> Int -> Ptr Word8 -> IO a) -> IO a
- type BitmapOfs = (Int, Int)
- getGlyphBitmapBox :: FontInfo -> Glyph -> Scaling -> IO (BoundingBox Int)
- newGlyphBitmap :: FontInfo -> Glyph -> Scaling -> IO (Bitmap, BitmapOfs)
- renderGlyphIntoBitmap' :: FontInfo -> Glyph -> Scaling -> Bitmap -> BitmapOfs -> IO ()
- renderGlyphIntoBitmap :: FontInfo -> Glyph -> Scaling -> Bitmap -> BitmapOfs -> IO ()
- bitmapArray :: Bitmap -> IO (UArray (Int, Int) Word8)
- bitmapFloatArray :: Bitmap -> IO (UArray (Int, Int) Float)
Documentation
enumerateFonts :: TrueType -> IO [Offset]Source
Enumerates the fonts found in a TrueType file.
data HorizontalMetrics Source
data VerticalMetrics Source
ascent
is the coordinate above the baseline the font extends; descent
is the coordinate below the baseline the font extends (i.e. it is typically negative)
lineGap
is the spacing between one row's descent and the next row's ascent...
so you should advance the vertical position by ascent - descent + lineGap
data BoundingBox a Source
The convention is BBox (x0,y0) (x1,y1)
.
BBox (a, a) (a, a) |
Show a => Show (BoundingBox a) |
lineAdvance :: VerticalMetrics -> UnscaledSource
As calculated by (ascent - descent + lineGap)
.
verticalSize :: VerticalMetrics -> UnscaledSource
As calculated by (ascent - descent)
.
getGlyphKernAdvance :: FontInfo -> Glyph -> Glyph -> IO UnscaledSource
This is not yet implemented in stb_truetype
; it always returns 0.
getGlyphBoundingBox :: FontInfo -> Glyph -> IO (BoundingBox Unscaled)Source
A 8-bit grayscale bitmap.
Bitmap | |
|
getGlyphBitmapBox :: FontInfo -> Glyph -> Scaling -> IO (BoundingBox Int)Source
Returns the size of the bitmap (in pixels) needed to render the glyph with the given scaling.
The box is centered around the glyph origin; so the
bitmap width is x1-x0
, height is y1-y0
, and location to place
the bitmap top left is (leftSideBearing*scale,y0)
.
Note that the bitmap uses y-increases-down, but the shape uses
y-increases-up, so the results of getGlyphBitmapBox
and
getGlyphBoundingBox
are inverted.
newGlyphBitmap :: FontInfo -> Glyph -> Scaling -> IO (Bitmap, BitmapOfs)Source
Creates a new bitmap just enough to fit the glyph with the given scaling, and renders the glyph into it. The offset returned is the offset of the glyph origin within the bitmap.
renderGlyphIntoBitmap' :: FontInfo -> Glyph -> Scaling -> Bitmap -> BitmapOfs -> IO ()Source
The offset is the top-left corner of the bounding box of the glyph, and must be nonnegative (otherwise nothing will happen).
renderGlyphIntoBitmap :: FontInfo -> Glyph -> Scaling -> Bitmap -> BitmapOfs -> IO ()Source
The offset is the origin of the glyph. If the glyph extends from the bitmap in the positive direction, it is clipped; however, if it extends in the negative direction, no drawing will happen!