Class: FT2::Bitmap

Inherits:
Object
  • Object
show all
Defined in:
ext/ft2-ruby/ft2.c

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.initializeObject

Constructor for FT2::Bitmap.

This method is currently empty. You should never call this method directly unless you’re instantiating a derived class (ie, you know what you’re doing).



122
123
124
# File 'ext/ft2-ruby/ft2.c', line 122

static VALUE ft_bitmap_init(VALUE self) {
  return self;
}

Instance Method Details

#bufferObject

Return the buffer (e.g. raw pixel data) of an FT2::Bitmap object.

Examples:

# return the rendered pixels as a binary string
buffer = bitmap.buffer

# assume a render method called render_font(buffer, width, height)
render_font(bitmap.buffer, bitmap.width, bitmap.rows)


179
180
181
182
183
# File 'ext/ft2-ruby/ft2.c', line 179

static VALUE ft_bitmap_buffer(VALUE self) {
  FT_Bitmap *bitmap;
  Data_Get_Struct(self, FT_Bitmap, bitmap);
  return rb_str_new((char*) bitmap->buffer, ABS(bitmap->pitch) * bitmap->rows);
}

#num_graysObject

Return the number of grays in an FT2::Bitmap object.

Note:

Only used if Ft2::Bitmap#pixel_mode is FT2::PixelMode::GRAYS.

Examples:

depth = bitmap.num_grays


195
196
197
198
199
# File 'ext/ft2-ruby/ft2.c', line 195

static VALUE ft_bitmap_num_grays(VALUE self) {
  FT_Bitmap *bitmap;
  Data_Get_Struct(self, FT_Bitmap, bitmap);
  return INT2FIX(bitmap->num_grays);
}

#paletteObject

Return the palette of an FT2::Bitmap object.

Note:

Returns a binary string of RGB or RGBA elements (check
FT2::Bitmap#palette_mode to determine which).

Examples:

case bitmap.palette_mode
when FT2::PaletteMode::RGBA
  rgba_palette_string = bitmap.palette
when FT2::PaletteMode::RGB
  rgb_palette_string = bitmap.palette
end


260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
# File 'ext/ft2-ruby/ft2.c', line 260

static VALUE ft_bitmap_palette(VALUE self) {
  FT_Bitmap *bitmap;
  /* int size; */
  Data_Get_Struct(self, FT_Bitmap, bitmap);

  return Qnil;
  /* FIXME i don't know how big the palette memory is, so i'll just
   * assume it's 256 entries :/
   *
   * none of this shit compiles, so I'm disabling it for now.
  if (bitmap->palette_mode == ft_palette_mode_rgb)
    size = 3 * 256;
  else if (bitmap->palette_mode == ft_palette_mode_rgba)
    size = 4 * 256;
  else
    rb_raise(rb_eException, "Unknown palette mode: %d.",
             INT2FIX(bitmap->palette_mode));

  return rb_str_new(bitmap->palette, size); */
}

#palette_modeObject

Return the palette mode of an FT2::Bitmap object.

Note:

Always returns one of the values avaiable in FT2::PaletteMode.

Examples:

case bitmap.palette_mode
when FT2::PaletteMode::RGBA
  puts "we have an alpha channel!"
when FT2::PaletteMode::RGB
  puts "no alpha channel for you"
end


238
239
240
241
242
# File 'ext/ft2-ruby/ft2.c', line 238

static VALUE ft_bitmap_palette_mode(VALUE self) {
  FT_Bitmap *bitmap;
  Data_Get_Struct(self, FT_Bitmap, bitmap);
  return INT2FIX(bitmap->palette_mode);
}

#pitchObject

Return the pitch (bytes per row) of an FT2::Bitmap object.

Return the pitch (bytes per row, including alignment padding) of an FT2::Bitmap object.

Examples:

width = bitmap.width


162
163
164
165
166
# File 'ext/ft2-ruby/ft2.c', line 162

static VALUE ft_bitmap_pitch(VALUE self) {
  FT_Bitmap *bitmap;
  Data_Get_Struct(self, FT_Bitmap, bitmap);
  return INT2FIX(bitmap->pitch);
}

#pixel_modeObject

Return the pixel mode (e.g. bit depth) of an FT2::Bitmap object.

Note:

Always returns one of the values avaiable in FT2::PixelMode (for a
full list, try the following code: "p FT2::PixelMode.constants.sort")

Examples:

case bitmap.pixel_mode
when FT2::PixelMode::RGB32
  puts "wow that's a lot of colors!"
when FT2::PixelMode::MONO
  puts "time to get a better monitor..."
end


217
218
219
220
221
# File 'ext/ft2-ruby/ft2.c', line 217

static VALUE ft_bitmap_pixel_mode(VALUE self) {
  FT_Bitmap *bitmap;
  Data_Get_Struct(self, FT_Bitmap, bitmap);
  return INT2FIX(bitmap->pixel_mode);
}

#rowsObject

Return the number of rows in a FT2::Bitmap object.

Examples:

rows = bitmap.rows


133
134
135
136
137
# File 'ext/ft2-ruby/ft2.c', line 133

static VALUE ft_bitmap_rows(VALUE self) {
  FT_Bitmap *bitmap;
  Data_Get_Struct(self, FT_Bitmap, bitmap);
  return INT2FIX(bitmap->rows);
}

#widthObject

Return the width of an FT2::Bitmap object.

Examples:

width = bitmap.width


146
147
148
149
150
# File 'ext/ft2-ruby/ft2.c', line 146

static VALUE ft_bitmap_width(VALUE self) {
  FT_Bitmap *bitmap;
  Data_Get_Struct(self, FT_Bitmap, bitmap);
  return INT2FIX(bitmap->width);
}