Subject: | Reuse.pm 0.33 TTF glyph identifier bug |
Date: | Wed, 12 Apr 2006 18:31:53 -0400 |
To: | bug-PDF-Reuse [...] rt.cpan.org |
From: | "richard hornsby" <richardjhornsby [...] gmail.com> |
Hi,
In lines 476-478 of Reuse.pm version 0.33:
for (unpack ('C*', $TxT))
{ $text .= sprintf("%04x", ($_ - 29));
}
The offset of 29 doesn't work correctly for all non-native fonts,
including any of the family of "Myriad*" OpenType fonts. You start
with an input ($TxT) of a string like "Adams" and end up with a result
of "Cfcou". (reuse_component output also shows this error - the
alphabet goes "CDEFG...?@AB")
I assume that decimal 29 (0x1d) comes from ASCII 65 (A) = 0x41. The
glyph for "A" in the Arial resource is located at 0x24. 0x41 - 0x1d =
0x24.
I grabbed a copy of FontLab Studio trying to figure it out. I don't
know exactly the reason for the problem, except that in the font "ITC
Eras" which does work correctly, the glyph for "A" is mapped to 0x24
but the glyph at 0x24 in Myriad is "C". "A" in Myriad is actually at
0x22.
A few looming limitations of this patch creep in, among them my
inexperience with patching, access to the ttf/otf file is required to
be able to look at the cmap, and two additional modules are needed for
this, Font::TTF:Font and Font::TTF::Cmap.
--- PDF-Reuse-0.33.alt-fix-usecmap/Reuse.pm 2006-04-12
16:58:57.000000000 -0400
+++ PDF-Reuse-0.33/Reuse.pm 2005-11-15 14:45:31.000000000 -0500
@@ -6,9 +6,6 @@
require Exporter;
require Digest::MD5;
-require Font::TTF::Font;
-require Font::TTF::Cmap;
-
use autouse 'Carp' => qw(carp
cluck
croak);
@@ -419,8 +416,7 @@
my $TxT = shift;
my $align = shift || 'left';
my $rot = shift || '0';
- my $fontFileResource = shift;
-
+
my $width = 0;
my $x_align_offset = 0;
@@ -477,22 +473,8 @@
else
{ my $text;
$TxT =~ s/\\(\d\d\d)/chr(oct($1))/eg;
- ## What is the proper offset to use for the locating the
- ## glyphs in the font resource?
- my $cmapOffset = 0x1d;
- my $fObj = Font::TTF::Font->open($fontFileResource) || 0;
-
- if ( $fObj ) {
- my $fCmap=$fObj->{cmap}->read;
- # We'll use "A" as an arbitrary baseline
- my $gid = $fCmap->ms_lookup(0x41);
- $cmapOffset = 0x41 - $gid;
- $fObj->release; # free the memory
- } else {
- warn("Warning! Unable to open the font file
$fontFileResource, using default cmap offset 0x1d");
- }
for (unpack ('C*', $TxT))
- { $text .= sprintf("%04x", ($_ - $cmapOffset));
+ { $text .= sprintf("%04x", ($_ - 29));
}
$stream .= $xPos+$x_align_offset . " $yPos Td \<$text\> Tj ET\n";
}