Skip to content

Commit

Permalink
reworking the reverse font index -> unicode maps code
Browse files Browse the repository at this point in the history
Now the mapping tables each have their own size instead of a statically
allocated table filled with 0.
It also remove the restriction on font sizes
  • Loading branch information
kakwa committed May 11, 2017
1 parent 5ac4328 commit 5b43466
Show file tree
Hide file tree
Showing 3 changed files with 789 additions and 59 deletions.
24 changes: 13 additions & 11 deletions goodies/mapping_builder.pl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
# It's meant to be lauched with a .ttf file as argument.
# Reverse mapping will add the reverse mapping directly inside
# the "inc/font_mapping.h" header.
#
# libfont-ttf-perl (Debian/Ubunutu package)

use strict;
use Font::TTF::Font;
Expand All @@ -24,26 +26,26 @@
my $num = $f->{'maxp'}->read->{'numGlyphs'};
my $name = $f->{'name'}->read->find_name(4);

# We have a limited number of glyphs, it may be needed to rework this for larger fonts
my $MAX_GLYPH = 1500;
if ($MAX_GLYPH < $num) {
print "ERROR, max number of glyphes exceeded";
exit(1);
}

# Open the header file
open my $header, $map_header or die "Could not open $map_header: $!";

# Create some temporary file
my $tmp = new File::Temp( UNLINK => 0 );

my $table_var_name = $name;
$table_var_name =~ s/[^\w]/_/g;
$table_var_name = 'emf2svg_fm_' . lc($table_var_name);

# Read the header file line by line, and rewrite those line in the temporary file
while(my $line = <$header>) {
# if we hit this marker, we add the new reverse mapping structure
# corresponding to the font we just used
if( $line eq "// Mappings END\n"){
print $tmp "{\"$name\", $num, {\n";
for (my $i = 0; $i < $MAX_GLYPH; $i++)
if( $line eq "// Mappings Collection END\n"){
print $tmp "{\"$name\", $num, $table_var_name},\n";
}
if( $line eq "// Mappings Table END\n"){
print $tmp "\nuint32_t ${table_var_name}\[\] = {\n";
for (my $i = 0; $i < $num; $i++)
{
my ($pname) = $p->{'VAL'}[$i];
my ($uid) = $rev[$i];
Expand All @@ -58,7 +60,7 @@
printf $tmp (" ");
}
}
print $tmp "},},\n"
print $tmp "};\n"
}
print $tmp "$line";
}
Expand Down
Loading

0 comments on commit 5b43466

Please sign in to comment.