Skip to content

Commit

Permalink
move win32 font support in a new directory, and use Imager::Probe
Browse files Browse the repository at this point in the history
change i_utf8_advance to accept the working length as a size_t and
propagate that change through anything that uses it
  • Loading branch information
Tony Cook committed Sep 16, 2010
1 parent 6725cca commit 718b8c9
Show file tree
Hide file tree
Showing 23 changed files with 456 additions and 246 deletions.
3 changes: 3 additions & 0 deletions Imager.pm
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ my %format_classes =
gif => "Imager::File::GIF",
tiff => "Imager::File::TIFF",
jpeg => "Imager::File::JPEG",
w32 => "Imager::Font::W32",
);

tie %formats, "Imager::FORMATS", \%formats_low, \%format_classes;
Expand Down Expand Up @@ -3906,6 +3907,8 @@ sub _check {
sub FETCH {
my ($self, $key) = @_;

$DB::single = 1;

exists $self->[IX_FORMATS]{$key} and return $self->[IX_FORMATS]{$key};

$self->[IX_CLASSES]{$key} or return undef;
Expand Down
92 changes: 3 additions & 89 deletions Imager.xs
Original file line number Diff line number Diff line change
Expand Up @@ -2129,7 +2129,7 @@ i_t1_glyph_name(handle, text_sv, utf8 = 0)
PREINIT:
char const *text;
STRLEN work_len;
int len;
size_t len;
char name[255];
PPCODE:
#ifdef SvUTF8
Expand Down Expand Up @@ -2323,7 +2323,7 @@ i_tt_glyph_name(handle, text_sv, utf8 = 0)
PREINIT:
char const *text;
STRLEN work_len;
int len;
size_t len;
int outsize;
char name[255];
PPCODE:
Expand Down Expand Up @@ -3808,92 +3808,6 @@ i_tags_count(im)
OUTPUT:
RETVAL

#ifdef HAVE_WIN32

void
i_wf_bbox(face, size, text_sv, utf8=0)
char *face
int size
SV *text_sv
int utf8
PREINIT:
int cords[BOUNDING_BOX_COUNT];
int rc, i;
char const *text;
STRLEN text_len;
PPCODE:
text = SvPV(text_sv, text_len);
#ifdef SvUTF8
if (SvUTF8(text_sv))
utf8 = 1;
#endif
if (rc = i_wf_bbox(face, size, text, text_len, cords, utf8)) {
EXTEND(SP, rc);
for (i = 0; i < rc; ++i)
PUSHs(sv_2mortal(newSViv(cords[i])));
}

undef_int
i_wf_text(face, im, tx, ty, cl, size, text_sv, align, aa, utf8 = 0)
char *face
Imager::ImgRaw im
int tx
int ty
Imager::Color cl
int size
SV *text_sv
int align
int aa
int utf8
PREINIT:
char const *text;
STRLEN text_len;
CODE:
text = SvPV(text_sv, text_len);
#ifdef SvUTF8
if (SvUTF8(text_sv))
utf8 = 1;
#endif
RETVAL = i_wf_text(face, im, tx, ty, cl, size, text, text_len,
align, aa, utf8);
OUTPUT:
RETVAL

undef_int
i_wf_cp(face, im, tx, ty, channel, size, text_sv, align, aa, utf8 = 0)
char *face
Imager::ImgRaw im
int tx
int ty
int channel
int size
SV *text_sv
int align
int aa
int utf8
PREINIT:
char const *text;
STRLEN text_len;
CODE:
text = SvPV(text_sv, text_len);
#ifdef SvUTF8
if (SvUTF8(text_sv))
utf8 = 1;
#endif
RETVAL = i_wf_cp(face, im, tx, ty, channel, size, text, text_len,
align, aa, utf8);
OUTPUT:
RETVAL

undef_int
i_wf_addfont(font)
char *font

undef_int
i_wf_delfont(font)
char *font

#endif

#ifdef HAVE_FT2

Expand Down Expand Up @@ -4147,7 +4061,7 @@ i_ft2_glyph_name(handle, text_sv, utf8 = 0, reliable_only = 1)
PREINIT:
char const *text;
STRLEN work_len;
int len;
size_t len;
char name[255];
PPCODE:
#ifdef SvUTF8
Expand Down
11 changes: 8 additions & 3 deletions MANIFEST
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,14 @@ TIFF/testimg/srgba16.tif
TIFF/testimg/srgba32.tif
TIFF/testimg/srgbaa.tif RGB with 2 alpha
TIFF/testimg/tiffwarn.tif Generates a warning while being read
W32/fontfiles/ExistenceTest.ttf
W32/imw32.h
W32/lib/Imager/Font/Win32.pm
W32/t/t10win32.t Tests Win32 GDI font support
W32/win32.c Implements font support through Win32 GDI
W32/Makefile.PL
W32/W32.pm
W32/W32.xs
apidocs.perl Build lib/Imager/APIRef.pm
bigtest.perl Library selection tester
bmp.c Reading and writing Windows BMP files
Expand Down Expand Up @@ -236,7 +244,6 @@ lib/Imager/Font/FreeType2.pm
lib/Imager/Font/Image.pm
lib/Imager/Font/Truetype.pm
lib/Imager/Font/Type1.pm
lib/Imager/Font/Win32.pm
lib/Imager/Font/Wrap.pm
lib/Imager/Fountain.pm
lib/Imager/Handy.pod
Expand Down Expand Up @@ -322,7 +329,6 @@ t/t21draw.t Basic drawing tests
t/t30t1font.t
t/t35ttfont.t
t/t36oofont.t
t/t37w32font.t Tests Win32 GDI font support
t/t38ft2font.t Tests freetype2 support
t/t40scale.t
t/t50basicoo.t
Expand Down Expand Up @@ -424,4 +430,3 @@ tga.c Reading and writing Targa files
trans2.c
transform.perl Shell interface to Imager::Transform
typemap
win32.c Implements font support through Win32 GDI
28 changes: 14 additions & 14 deletions Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -626,20 +626,20 @@ visual quality esp on low resultions. The freetype library is
used to rasterize for us. The only drawback is that there
are alot of badly designed fonts out there.}
};
$formats{'w32'} = {
order=>40,
def=>'HAVE_WIN32',
inccheck=>sub { -e catfile($_[0], 'windows.h') },
libcheck=>sub { lc $_[0] eq 'gdi32.lib'
|| lc $_[0] eq 'libgdi32.a' },
libfiles=>$^O eq 'cygwin' ? '-lgdi32' : '',
objfiles=>'win32.o',
docs => <<DOCS
Uses the Win32 GDI for rendering text.
This currently only works on under normal Win32 and cygwin.
DOCS
};
# $formats{'w32'} = {
# order=>40,
# def=>'HAVE_WIN32',
# inccheck=>sub { -e catfile($_[0], 'windows.h') },
# libcheck=>sub { lc $_[0] eq 'gdi32.lib'
# || lc $_[0] eq 'libgdi32.a' },
# libfiles=>$^O eq 'cygwin' ? '-lgdi32' : '',
# objfiles=>'win32.o',
# docs => <<DOCS
# Uses the Win32 GDI for rendering text.

# This currently only works on under normal Win32 and cygwin.
# DOCS
# };
$formats{'freetype2'} =
{
order=>'29',
Expand Down
1 change: 0 additions & 1 deletion TIFF/TIFF.pm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ BEGIN {
XSLoader::load('Imager::File::TIFF', $VERSION);
1;
} or do {
print STDERR "Falling back to DynaLoader ($@)\n";
require DynaLoader;
push @ISA, 'DynaLoader';
bootstrap Imager::File::TIFF $VERSION;
Expand Down
117 changes: 117 additions & 0 deletions W32/Makefile.PL
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
#!perl -w
use strict;
use ExtUtils::MakeMaker qw(WriteMakefile WriteEmptyMakefile);
use Getopt::Long;
use Config;

my $verbose = $ENV{IM_VERBOSE};
my @libpaths;
my @incpaths;

GetOptions("incpath=s", \@incpaths,
"libpath=s" => \@libpaths,
"verbose|v" => \$verbose);

our $BUILDING_IMAGER;

$DB::single = 1;

my $MM_ver = eval $ExtUtils::MakeMaker::VERSION;

my %opts =
(
NAME => 'Imager::Font::W32',
VERSION_FROM => 'W32.pm',
OBJECT => 'W32.o win32.o',
);

my @inc;
if ($BUILDING_IMAGER) {
push @inc, "-I..";
unshift @INC, "../lib";
}
else {
unshift @INC, "inc";
print "Win32: building independently\n";
require Imager::ExtUtils;
push @inc, Imager::ExtUtils->includes;
$opts{TYPEMAPS} = [ Imager::ExtUtils->typemap ];

# Imager required configure through use
my @Imager_req = ( Imager => "0.77" );
if ($MM_ver >= 6.46) {
$opts{META_MERGE} =
{
configure_requires =>
{
@Imager_req,
},
build_requires =>
{
@Imager_req,
"Test::More" => "0.47",
},
resources =>
{
homepage => "http://imager.perl.org/",
repository =>
{
url => "http://imager.perl.org/svn/trunk/Imager-Font-W32",
web => "http://imager.perl.org/svnweb/public/browse/trunk/Imager-Font-W32",
type => "svn",
},
},
};
$opts{PREREQ_PM} =
{
@Imager_req,
};
}
}

require Imager::Probe;

my %probe =
(
name => "Win32",
inccheck => sub { -e File::Spec->catfile($_[0], "windows.h") },
libbase => "gdi32",
testcode => _win32_test_code(),
testcodeheaders => [ "stdio.h", "string.h", "windows.h" ],
incpath => join($Config{path_sep}, @incpaths),
libpath => join($Config{path_sep}, @libpaths),
);

my $probe_res = Imager::Probe->probe(\%probe);
if ($probe_res) {
push @inc, $probe_res->{INC};
$opts{LIBS} = $probe_res->{LIBS};

$opts{INC} = "@inc";

if ($MM_ver > 6.06) {
$opts{AUTHOR} = 'Tony Cook <[email protected]>';
$opts{ABSTRACT} = 'Win32 font file support for Imager';
}

WriteMakefile(%opts);
}
else {
if ($BUILDING_IMAGER) {
WriteEmptyMakefile(%opts);
}
else {
# fail in good way
die "OS unsupported: Win32 libraries or headers not found\n";
}
}

sub _win32_test_code {
return <<'CODE';
HDC dc = GetDC(NULL);
HDC bmpDc = CreateCompatibleDC(dc);
DeleteDC(bmpDc);
ReleaseDC(NULL, dc);
return 0;
CODE
}
Loading

0 comments on commit 718b8c9

Please sign in to comment.