#!/usr/bin/perl
#
# Name:
#	im-hax-query-font-metrics-1.pl.
#
# Purpose:
#	Demonstrate QueryFontMetrics.
#
# V 1.01 20-Feb-2002
# ------------------
# o Don't use $ENV{'TT_FONT_PATH'} in IM V 5.4.3.
#	Put font in same dir as script
# o Patch Apache httpd.conf to match. Ie:
#	PassEnv MAGICK_HOME
# o Remove TT_FONT_PATH from environment
#
# V 1.00 17-Jan-2002
# ------------------
# o Initial version
#
# Test environment:
#	OS: WinNT 4 SP 6a
#	Web server: Apache V 1.3.26
#	IM: V 5.4.7

#
# Input files:
#	./Generic.ttf
#
# Output file:
#	im-hax-png:query-font-metrics-1.png
#
# Note:
#	o tab = 4 spaces || die.
#	o Text reformatted to max 50 chars wide
#		so source can be converted to PDF
#
# Expected output:
#	Script: im-hax-query-font-metrics-1.pl.
#	Image::Magick V 5.47.
#	Image: xc:blue. Size: 100 x 100.
#	Font: Generic.ttf.
#	Font metrics: 24, 24, 20, -6, 79, 30, 18.
#	png:/temp/im-hax-query-font-metrics-1.png.
#
# Author:
#	Ron Savage <ron@savage.net.au>
#	http://savage.net.au/ImageMagick.html
#
# Licence:
#	Copyright (c) 1999-2002 Ron Savage
#
#	All Programs of mine are
#	'OSI Certified Open Source Software';
#	you can redistribute them and/or modify them
#	under the terms of the Artistic License,
#	a copy of which is available at:
#	http://www.opensource.org/licenses/index.html

use strict;
use warnings;

use Image::Magick;

# -----------------------------------------------

my($script)		= $0;
$script			=~ tr|\\|/|;
$script			=~ s|.*/||;
my($im_version)	= $Image::Magick::VERSION;

print "Script: $script. \n";
print "Image::Magick V $im_version. \n";

my($output_dir_name)	= '/temp';
my($output_file_name)	=
	"png:$output_dir_name/" .
	"im-hax-query-font-metrics-1.png";
my($image_name)			= 'xc:blue';
my($font)				= 'Generic.ttf';
my($image)				= new Image::Magick();
my($result)				=
	$image -> Set(size=>'100x100');
die $result if $result;

$result = $image -> Read($image_name);
die $result if $result;

my($x_size, $y_size) =
	$image -> Get('width', 'height');

print "Image: $image_name. Size: ",
	"$x_size x $y_size. \n";

my(%args) =
(
	text		=> 'Text test',
	font		=> $font,
	pointsize	=> 24,
	gravity		=> 'Center',
);

my(@metric) = $image -> QueryFontMetrics(%args);

print "Font: $font. \n";
print 'Font metrics: ',
	join(', ', @metric), ". \n";

$result = $image -> Annotate(%args);
die $result if $result;

$result = $image -> Write($output_file_name);
die $result if $result;

print "$output_file_name. \n";
