pcf-parser

Parser for the pcf bitmap font format

PCF Parser

A parser for .pcf bitmap fonts

Usage

Install the pcf-parser shard

  1. shards init
  2. Add the dependency to the shard.yml file
...
dependencies:
  pcf-parser:
    github: stumpycr/pcf-parser
...
  1. shards install

Read a font file

require "pcf-parser"

font = PCFParser::Font.from_file("./font.pcf")

# look up chars by their "name" (e.g. 'A', 'B') or their "number" (e.g. 65)
#
# font.lookup("test") returns an array of characters

char = font.lookup('A')

height = char.ascent + char.descent
width = char.width

(0...height).each do |y|
  (0...width).each do |x|
    print char.get(x, y) ? "#" : " "
  end
  print "\n"
end

Output:




    ##
   ####
  ##  ##
  ##  ##
 ##    ##
 ##    ##
 ##    ##
 ########
 ##    ##
 ##    ##
 ##    ##
 ##    ##
 ##    ##




TODO

  • Implement support for reverse bit order
  • Documentation
  • Add a collection of .pcf fonts
Repository

pcf-parser

Owner
Statistic
  • 1
  • 1
  • 0
  • 1
  • 0
  • about 4 years ago
  • May 4, 2017
License

MIT License

Links
Synced at

Sun, 17 Nov 2024 13:07:34 GMT

Languages