Font-FreeType

 view release on metacpan or  search on metacpan

TODO  view on Meta::CPAN

   from other glyphs.  E.g., magick.pl doesn't work with kochi-minco.ttf
   because it doesn't have a glyph for Acircumflex, but fontforge says it
   does provide that character, just that it doesn't have an outline or
   bitmap.  It says it's composed of U+0041 and U+0302.
   The current situation is that bitmap() will return a 0x0 bitmap, which
   breaks bitmap_magick(), and the outline doesn't cause any problems
   apart from not being there.

 * Tests:
    * decomposing outlines.  Also test the postscript() and svg_path() methods.
    * bitmap_magick() -- skip tests if Image::Magick not installed

 * Maybe provide some defaults for $face->set_char_size(), so that you don't
   have to pass in all four values.

 * $face->glyph_from_char() should work with Unicode characters properly.

 * There should be a way of getting glyphs by index.

 * The underline methods ($face->underline_position() and
   $face->underline_thickness()) should scale their values to the same

examples/magick.pl  view on Meta::CPAN

#!/usr/bin/perl -w
use strict;

# This program demonstrates using Font::FreeType with Image::Magick.
# It uses the font metrics to position glyphs next to each other as
# a typesetting engine would, and renders them both by compositing a
# bitmap of each glyph onto the output image (using the bitmap_magick()
# convenience method) and by drawing the outline using ImageMagick
# drawing functions.

# TODO - use kerning.

use Font::FreeType;
use Image::Magick;
use List::Util qw( sum );

my $text = "\xC2g.";     # 'Ag.', with a circumflex over the 'A'
my $size = 72;
my $dpi = 600;
my $border = 23;

die "Usage: $0 font-filename output-filename.png\n"
  unless @ARGV == 2;

examples/magick.pl  view on Meta::CPAN

my @glyphs = map { $face->glyph_from_char_code(ord $_) } split //, $text;

# Work out how big the text will be.
my $width = sum map { $_->horizontal_advance } @glyphs;
$width -= $glyphs[0]->left_bearing;
$width -= $glyphs[-1]->right_bearing;
my $height = $face->height;
$width += $border * 2;
$height += $border * 2;

my $img = Image::Magick->new(size => "${width}x$height");
$img->Read('xc:white');
$img->Set(stroke => '#0000AA');

my $origin_y = -$face->descender + $border;
my ($text_x, $text_y) = (-$glyphs[0]->left_bearing + $border, $origin_y);

my (undef, $adj_base_y) = adjust_position(0, 0);
my (undef, $adj_top_y) = adjust_position(0, $face->ascender);
my (undef, $adj_btm_y) = adjust_position(0, $face->descender);
$img->Draw(primitive => 'line', points => "0,$adj_base_y $width,$adj_base_y",

lib/Font/FreeType/Glyph.pm  view on Meta::CPAN

    my $self = shift;
    my ($bmp, $left, $top) = $self->bitmap(@_);

    my $wd = length $bmp->[0];
    my $ht = @$bmp;
    return ("P5\n$wd $ht\n255\n" . join('', @$bmp), $left, $top);
}

sub bitmap_magick
{
    require Image::Magick;

    my $self = shift;
    my ($bmp, $left, $top) = $self->bitmap(@_);

    my $wd = length $bmp->[0];
    my $ht = @$bmp;

    my $img = Image::Magick->new(magick=>'gray', size => "${wd}x$ht",
                                 depth => 8);
    my $err = $img->BlobToImage(join '', @$bmp);
    croak "error creating Image::Magick object: $err" if $err;
    return ($img, $left, $top);
}

1;

__END__

=head1 NAME

Font::FreeType::Glyph - glyphs from font typefaces loaded from Font::FreeType

lib/Font/FreeType/Glyph.pm  view on Meta::CPAN

Render in colour for an LCD display, with three times as many rows
down the image as normal.  This mode probably won't work yet.

Only available with Freetype version 2.1.3 or newer.

=back

=item bitmap_magick([I<render_mode>])

A simple wrapper around the C<bitmap()> method.  Renders the bitmap as
normal and returns it as an L<Image::Magick|Image::Magick> object,
which can then be composited onto a larger bitmapped image, or manipulated
using any of the features available in Image::Magick.

The image is in the 'gray' format, with a depth of 8 bits.

The left and top distances in pixels are returned as well, in the
same way as for the C<bitmap()> method.

This method, particularly the use of the left and top offsets for
correct positioning of the bitmap, is demonstrated in the
I<magick.pl> example program.



( run in 1.898 second using v1.01-cache-2.11-cpan-39bf76dae61 )