#!/usr/bin/perl
#
# Name:
#	im-hax-query-font-metrics-2.pl.
#
# Purpose:
#	Demonstrate QueryFontMetrics.
#
# 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
#	/apache/htdocs/smile.gif
#
# Output files:
#	None
#
# 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-2.pl.
#	Image::Magick V 5.47.
#	Background: /apache/htdocs/smile.gif.
#	Bkg size: 48 x 48.
#	Font: Generic.ttf.
#	Font metrics: 36, 36, 29, -10, 131, 45, 28
#
# 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($bkg_name)	= '/apache/htdocs/smile.gif';
my($image_name)	= 'xc:maroon';
my($font)		= 'Generic.ttf';
my($background)	= Image::Magick -> new();
my($result)		= $background -> Read($bkg_name);
die $result if $result;

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

print "Background: $bkg_name. \nBkg size: ",
	"$x_size x $y_size. \n";

# Make the label image the same size as the
# background.

my($image) = Image::Magick -> new
(size => "${x_size}x$y_size");

# Warning: This program simply will not work
# without the next line.

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

$result = $image -> Set
(
	font		=> $font,
	pointsize	=> 36,
);
die $result if $result;

my($x_ppem, $y_ppem, $ascender, $descender,
$text_width, $text_height, $max_advance) =
$image -> QueryFontMetrics
(
	text	=> 'Test test',
	font	=> $font,
);

print "Font: $font. \n";
print "Font metrics: $x_ppem, $y_ppem, ",
	"$ascender, $descender, $text_width, ",
	"$text_height, $max_advance\n";
