pcf-font-0.1.0.0: PCF font parsing and rendering library.

Safe HaskellNone
LanguageHaskell2010

Graphics.Text.PCF

Contents

Description

Rendering bitmap text with pcf-font is easy. Consider a program for rendering text into a PNG:

import Codec.Picture.Png
import Codec.Picture.Types
import Data.List
import Graphics.Text.PCF
import System.Environment

-- | USAGE: program <font.pcf> <output.png> <text>
main :: IO ()
main = do
    [input_file, output_file, text] <- getArgs
    pcf <- either fail return =<< loadPCF input_file
    case renderPCFText pcf text of
        Just (w, h, image_data) ->
            writePng output_file (Image w h image_data :: Image Pixel8)
        Nothing ->
            putStrLn "ERROR: Unable to render input text."

Synopsis

Decoding

loadPCF :: FilePath -> IO (Either String PCF) Source #

Load a PCF font file. File should not be compressed (e.g. ".pcf.gz" extension).

decodePCF :: ByteString -> Either String PCF Source #

Decode a PCF font from an in-memory ByteString.

Rendering

renderPCFText Source #

Arguments

:: PCF

Font to render with

-> String

Text to render

-> Maybe (Int, Int, Vector Word8)

Just width, height, and rendering; Nothing if an unrenderable character is encountered

Generate a vector of black and white pixels from a PCF font and a string.

getPCFGlyph :: PCF -> Char -> Maybe PCFGlyph Source #

Extract a single glyph bitmap from a PCF font.

getPCFGlyphPixel Source #

Arguments

:: PCFGlyph 
-> Int

X

-> Int

Y

-> Bool

True if pixel at (x,y) is opaque; False if pixel at (x,y) is transparent or (x,y) is out of the glyph's bounds

Calculate the color of a pixel in a glyph given its (x,y) coordinates.

foldPCFGlyphPixels Source #

Arguments

:: PCFGlyph 
-> (Int -> Int -> Bool -> a -> a)

Function that takes x, y, pixel value at (x,y), and an accumulator, returning a modified accumulator

-> a

Initial accumulator

-> a 

Scan over every pixel in a glyph, constructing some value in the process.

Metadata

getPCFProps :: PCF -> [(ByteString, Either ByteString Int)] Source #

List key-value pairs found in PCF properties table.

Types

data PCF Source #

Container of tables extracted from a PCF font file.

data PCFGlyph Source #

Container of a single glyph bitmap and its metadata.

Constructors

PCFGlyph 

Fields