The FontMetricsData objects generate and store the font metrics data for a particular font. The glyph set is currently restricted to US ASCII characters.
The constructor can be used in two different modes. If all font data is supplied, the object just stores the supplied font data. If only the font name is given, the class uses the prawn library to generate the font metrics for the requested font.
# File lib/taskjuggler/Painter/FontMetricsData.rb, line 30 def initialize(fontName, type = :normal, ptSize = 24, height = nil, wData = nil, kData = nil) @fontName = fontName @type = type @height = height @ptSize = ptSize @averageWidth = 0.0 if wData && kData @charWidth = wData @kerningDelta = kData else generateMetrics end end
The average with of all glyphs.
# File lib/taskjuggler/Painter/FontMetricsData.rb, line 53 def averageWidth return (@averageWidth * (3.0 / 4.0)).to_i end
Return the width of the glyph c. This must be a single character String. If the glyph is not known, nil is returned.
# File lib/taskjuggler/Painter/FontMetricsData.rb, line 48 def glyphWidth(c) return @charWidth[c] end
Generate the FontMetricsData initialization code for the particular font. The output will be Ruby syntax.
# File lib/taskjuggler/Painter/FontMetricsData.rb, line 59 def to_ruby indent = ' ' * 6 s = "#{indent}Font_#{@fontName.gsub(/-/, '_')}_#{@type} = " + "Painter::FontMetricsData.new('#{@fontName}', :#{@type}, " + "#{@ptSize}, #{"%.3f" % @height},\n" s << "#{indent} @charWidth = {" i = 0 @charWidth.each do |c, w| s << (i % 4 == 0 ? "\n#{indent} " : ' ') i += 1 s << "'#{escapedChars(c)}' => #{"%0.3f" % w}," end s << "\n#{indent} },\n" s << "#{indent} @kerningDelta = {" i = 0 @kerningDelta.each do |cp, w| s << (i % 4 == 0 ? "\n#{indent} " : ' ') i += 1 s << "'#{cp}' => #{"%.3f" % w}," end s << "\n#{indent} }\n#{indent})\n" end
Generated with the Darkfish Rdoc Generator 2.