Object
Set whether fontconfig support should be enabled. To use this, the GD library must have been built with fontconfig support. Raises an error if fontconfig support is unavailable.
# File lib/gd2/font.rb, line 160 def self.fontconfig=(want) avail = !SYM[:gdFTUseFontConfig].call(want ? 1 : 0)[0].zero? raise FontconfigError, 'Fontconfig not available' if want && !avail @@fontconfig = want end
Return a boolean indicating whether fontconfig support has been enabled. The default is false.
# File lib/gd2/font.rb, line 153 def self.fontconfig? fontconfig end
Instantiate a TrueType font given by fontname (either a pathname or a fontconfig pattern if fontconfig is enabled) and ptsize (a point size given as a floating point number).
The possible options are:
:linespacing => The desired line spacing for multiline text, expressed as a multiple of the font height. A line spacing of 1.0 is the minimum to guarantee that lines of text do not collide. The default according to GD is 1.05.
:charmap => Specify a preference for Unicode, Shift_JIS, or Big5 character encoding. Use one of the constants Font::TrueType::CHARMAP_UNICODE, Font::TrueType::CHARMAP_SHIFT_JIS, or Font::TrueType::CHARMAP_BIG5.
:hdpi => The horizontal resolution hint for the rendering engine. The default according to GD is 96 dpi.
:vdpi => The vertical resolution hint for the rendering engine. The default according to GD is 96 dpi.
:dpi => A shortcut to specify both :hdpi and :vdpi.
:kerning => A boolean to specify whether kerning tables should be used, if fontconfig is available. The default is true.
# File lib/gd2/font.rb, line 215 def initialize(fontname, ptsize, options = {}) @fontname, @ptsize = fontname, ptsize.to_f @linespacing = options.delete(:linespacing) @linespacing = @linespacing.to_f if @linespacing @charmap = options.delete(:charmap) @hdpi = options.delete(:hdpi) @vdpi = options.delete(:vdpi) if dpi = options.delete(:dpi) @hdpi ||= dpi @vdpi ||= dpi end @kerning = options.delete(:kerning) @kerning = true if @kerning.nil? self.class.register(self) # Get the font path (and verify existence of file) strex = strex(false, true) r, rs = SYM[:gdImageStringFTEx].call(nil, Array.new(8) { 0 }, 0, @fontname, @ptsize, 0.0, 0, 0, '', strex) raise FreeTypeError, r if r strex[:fontpath].free = SYM[:gdFree] @fontpath = strex[:fontpath].to_s end
Return a hash describing the rectangle that would enclose the given string rendered in this font at the given angle. The returned hash contains the following keys:
:lower_left => The [x, y] coordinates of the lower left corner.
:lower_right => The [x, y] coordinates of the lower right corner.
:upper_right => The [x, y] coordinates of the upper right corner.
:upper_left => The [x, y] coordinates of the upper left corner.
:position => An array of floating point character position offsets for each character of the string, beginning with 0.0. The array also includes a final position indicating where the last character ends.
The upper, lower, left, and right references are relative to the text of the string, regardless of the angle.
# File lib/gd2/font.rb, line 308 def bounding_rectangle(string, angle = 0.0) data = draw(nil, 0, 0, angle, string, 0) if string.length == 1 # gd annoyingly fails to provide xshow data for strings of length 1 position = draw(nil, 0, 0, angle, string + ' ', 0)[:position] data[:position] = position[0...-1] end data end
Generated with the Darkfish Rdoc Generator 2.