Index: freetyp2.c
===================================================================
--- freetyp2.c (revision 1033)
+++ freetyp2.c (working copy)
@@ -693,55 +693,57 @@
slot = handle->face->glyph;
gm = &slot->metrics;
- error = FT_Render_Glyph(slot, aa ? ft_render_mode_normal : ft_render_mode_mono);
- if (error) {
- ft2_push_message(error);
- i_push_errorf(0, "rendering glyph 0x%04X (character \\x%02X)");
- return 0;
- }
- if (slot->bitmap.pixel_mode == ft_pixel_mode_mono) {
- bmp = slot->bitmap.buffer;
- for (y = 0; y < slot->bitmap.rows; ++y) {
- int pos = 0;
- int bit = 0x80;
- for (x = 0; x < slot->bitmap.width; ++x) {
- if (bmp[pos] & bit)
- i_ppix(im, tx+x+slot->bitmap_left, ty+y-slot->bitmap_top, cl);
-
- bit >>= 1;
- if (bit == 0) {
- bit = 0x80;
- ++pos;
- }
- }
- bmp += slot->bitmap.pitch;
+ if (gm->width) {
+ error = FT_Render_Glyph(slot, aa ? ft_render_mode_normal : ft_render_mode_mono);
+ if (error) {
+ ft2_push_message(error);
+ i_push_errorf(0, "rendering glyph 0x%04X (character \\x%02X)");
+ return 0;
}
- }
- else {
- /* grey scale or something we can treat as greyscale */
- /* we create a map to convert from the bitmap values to 0-255 */
- if (last_mode != slot->bitmap.pixel_mode
- || last_grays != slot->bitmap.num_grays) {
- if (!make_bmp_map(&slot->bitmap, map))
- return 0;
- last_mode = slot->bitmap.pixel_mode;
- last_grays = slot->bitmap.num_grays;
+ if (slot->bitmap.pixel_mode == ft_pixel_mode_mono) {
+ bmp = slot->bitmap.buffer;
+ for (y = 0; y < slot->bitmap.rows; ++y) {
+ int pos = 0;
+ int bit = 0x80;
+ for (x = 0; x < slot->bitmap.width; ++x) {
+ if (bmp[pos] & bit)
+ i_ppix(im, tx+x+slot->bitmap_left, ty+y-slot->bitmap_top, cl);
+
+ bit >>= 1;
+ if (bit == 0) {
+ bit = 0x80;
+ ++pos;
+ }
+ }
+ bmp += slot->bitmap.pitch;
+ }
}
-
- bmp = slot->bitmap.buffer;
- for (y = 0; y < slot->bitmap.rows; ++y) {
- for (x = 0; x < slot->bitmap.width; ++x) {
- int value = map[bmp[x]];
- if (value) {
- i_gpix(im, tx+x+slot->bitmap_left, ty+y-slot->bitmap_top, &pel);
- for (ch = 0; ch < im->channels; ++ch) {
- pel.channel[ch] =
- ((255-value)*pel.channel[ch] + value * cl->channel[ch]) / 255;
- }
- i_ppix(im, tx+x+slot->bitmap_left, ty+y-slot->bitmap_top, &pel);
- }
- }
- bmp += slot->bitmap.pitch;
+ else {
+ /* grey scale or something we can treat as greyscale */
+ /* we create a map to convert from the bitmap values to 0-255 */
+ if (last_mode != slot->bitmap.pixel_mode
+ || last_grays != slot->bitmap.num_grays) {
+ if (!make_bmp_map(&slot->bitmap, map))
+ return 0;
+ last_mode = slot->bitmap.pixel_mode;
+ last_grays = slot->bitmap.num_grays;
+ }
+
+ bmp = slot->bitmap.buffer;
+ for (y = 0; y < slot->bitmap.rows; ++y) {
+ for (x = 0; x < slot->bitmap.width; ++x) {
+ int value = map[bmp[x]];
+ if (value) {
+ i_gpix(im, tx+x+slot->bitmap_left, ty+y-slot->bitmap_top, &pel);
+ for (ch = 0; ch < im->channels; ++ch) {
+ pel.channel[ch] =
+ ((255-value)*pel.channel[ch] + value * cl->channel[ch]) / 255;
+ }
+ i_ppix(im, tx+x+slot->bitmap_left, ty+y-slot->bitmap_top, &pel);
+ }
+ }
+ bmp += slot->bitmap.pitch;
+ }
}
}
Index: t/t38ft2font.t
===================================================================
--- t/t38ft2font.t (revision 1033)
+++ t/t38ft2font.t (working copy)
@@ -1,7 +1,7 @@
#!perl -w
use strict;
use lib 't';
-use Test::More tests => 158;
+use Test::More tests => 160;
++$|;
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.pl'
@@ -19,13 +19,13 @@
SKIP:
{
- i_has_format("ft2") or skip("no freetype2 library found", 157);
+ i_has_format("ft2") or skip("no freetype2 library found", 159);
print "# has ft2\n";
my $fontname=$ENV{'TTFONTTEST'}||'./fontfiles/dodge.ttf';
- -f $fontname or skip("cannot find fontfile $fontname", 157);
+ -f $fontname or skip("cannot find fontfile $fontname", 159);
my $bgcolor=i_color_new(255,0,0,0);
@@ -399,6 +399,19 @@
}
ok($im->write(file=>'testout/t38align.ppm'), "save align image");
}
+
+
+ { # outputting a space in non-AA could either crash
+ # or fail (ft 2.2+)
+ my $font = Imager::Font->new(file=>'fontfiles/ImUgly.ttf', type=>'ft2');
+ my $im = Imager->new(xsize => 100, ysize => 100);
+ ok($im->string(x => 10, y => 10, string => "test space", aa => 0,
+ color => '#FFF', size => 8, font => $font),
+ "draw space non-antialiased (color)");
+ ok($im->string(x => 10, y => 50, string => "test space", aa => 0,
+ channel => 0, size => 8, font => $font),
+ "draw space non-antialiased (channel)");
+ }
}
sub align_test {
@@ -440,7 +453,6 @@
else {
SKIP: { skip("couldn't draw text", 7) };
}
-
}
sub okmatchcolor {