Skip to content

Commit

Permalink
Font metrics refactor (#12)
Browse files Browse the repository at this point in the history
* Initial work on refactoring the font metric code

- Moved away from the archaic method of writing out PHP to a file and including it in the next run, by writing out the metrics data as JSON and reading from the file as required.
- General tidying up of code and trying to make sense of the > character 127 processing, and why we're doing what we're doing.
- For some reason, character widths appear to be broken for characters > 127 when reading the 127 file - when the file doesn't exist and we process on-the-fly, the widths appear to be OK. Hmmz.

* A bunch of reactors and cleanup around writing and accessing the font metrics and character widths files
  • Loading branch information
David Wilcock authored Nov 25, 2016
1 parent feb2c18 commit b21d98a
Show file tree
Hide file tree
Showing 80 changed files with 3,789 additions and 263 deletions.
17 changes: 16 additions & 1 deletion bin/generate_unicode_font_specs.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@

$arr_fonts = glob($str_search);

$obj_pdf = new \tFPDF\PDF();
$int_generated = 0;
foreach ($arr_fonts as $str_font_filename) {
$str_font_filename = basename($str_font_filename);
preg_match("/^(.*)\.ttf$/", $str_font_filename, $arr_matches);
if (count($arr_matches) > 1) {

//$str_font_family = str_replace("-", "", $arr_matches[1]);
$str_font_family = reset(explode("-", $arr_matches[1]));
$str_style = "";
Expand All @@ -28,13 +28,28 @@
$str_style .= "I";
}
$str_font_ttf = $arr_matches[0];

$obj_pdf = new \tFPDF\PDF();
$obj_pdf->AddPage();
$obj_pdf->AddFont($str_font_family, $str_style, $str_font_filename, true);
$obj_pdf->SetTextColor(0,0,0);
$obj_pdf->SetXY(5, 5);
$obj_pdf->SetFont($str_font_family, $str_style, 15);
$str_extended_ascii = 'åàõê';
$obj_pdf->MultiCell('100', 2, $str_extended_ascii);
echo "Generated files for " . $str_font_family;
if ($str_style != '') {
echo "/" . $str_style;
}
echo "\n";
$int_generated++;
$str_test_dir = "test_pdfs/";
if (!is_dir($str_test_dir)) {
mkdir($str_test_dir, 0755);
}
$str_test_file = $str_test_dir . $str_font_family . ($str_style == '' ? '' : '-' . $str_style) . ".pdf";
file_put_contents($str_test_file, $obj_pdf->output());
echo "Written " . $str_test_file . "\n";
}
}
echo "Generated " . $int_generated . " font spec files\n";
1 change: 1 addition & 0 deletions bin/test_pdf128_gen.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

$obj_pdf = new \tFPDF\PDFBarcode();
$obj_pdf->AddPage();

$obj_pdf->Code128(5, 5, '1234566700345', 50, 50);
$str_file = sys_get_temp_dir() . '/tfpdf_code128_test.pdf';
file_put_contents($str_file, $obj_pdf->output());
Expand Down
22 changes: 22 additions & 0 deletions bin/test_unicode.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
/**
* test_unicode.php
*
* @author David Wilcock <[email protected]>
* @copyright Venditan Limited 2016
*/

require_once __DIR__ . '/../vendor/autoload.php';

$obj_pdf = new \tFPDF\PDF();
$obj_pdf->AddPage();
$obj_pdf->AddFont('DejaVuSans', '', 'DejaVuSans.ttf', true);
$obj_pdf->SetFont('DejaVuSans');

$obj_pdf->SetTextColor(0,0,0);
$obj_pdf->Cell(100, 2, 'Hyggelig å møte deg');

$str_file = sys_get_temp_dir() . '/tfpdf_unicode_test.pdf';
file_put_contents($str_file, $obj_pdf->output());

echo "Written file " . $str_file . PHP_EOL;
111 changes: 111 additions & 0 deletions src/font/unifont/babelstonehan-bold-character-width-127.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?php
$rangeid=32;
$prevcid=126;
$prevwidth=500;
$interval=true;
$range=array (
29 =>
array (
0 => 500,
),
32 =>
array (
0 => 500,
1 => 500,
'interval' => true,
2 => 500,
3 => 500,
4 => 500,
5 => 500,
6 => 500,
7 => 500,
8 => 500,
9 => 500,
10 => 500,
11 => 500,
12 => 500,
13 => 500,
14 => 500,
15 => 500,
16 => 500,
17 => 500,
18 => 500,
19 => 500,
20 => 500,
21 => 500,
22 => 500,
23 => 500,
24 => 500,
25 => 500,
26 => 500,
27 => 500,
28 => 500,
29 => 500,
30 => 500,
31 => 500,
32 => 500,
33 => 500,
34 => 500,
35 => 500,
36 => 500,
37 => 500,
38 => 500,
39 => 500,
40 => 500,
41 => 500,
42 => 500,
43 => 500,
44 => 500,
45 => 500,
46 => 500,
47 => 500,
48 => 500,
49 => 500,
50 => 500,
51 => 500,
52 => 500,
53 => 500,
54 => 500,
55 => 500,
56 => 500,
57 => 500,
58 => 500,
59 => 500,
60 => 500,
61 => 500,
62 => 500,
63 => 500,
64 => 500,
65 => 500,
66 => 500,
67 => 500,
68 => 500,
69 => 500,
70 => 500,
71 => 500,
72 => 500,
73 => 500,
74 => 500,
75 => 500,
76 => 500,
77 => 500,
78 => 500,
79 => 500,
80 => 500,
81 => 500,
82 => 500,
83 => 500,
84 => 500,
85 => 500,
86 => 500,
87 => 500,
88 => 500,
89 => 500,
90 => 500,
91 => 500,
92 => 500,
93 => 500,
94 => 500,
),
);
?>
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
$name='BabelStoneHan';
$type='TTF';
$desc=array (
'Ascent' => 996,
'Descent' => -238,
'CapHeight' => 678,
'Ascent' => 996.0,
'Descent' => -238.0,
'CapHeight' => 678.0,
'Flags' => 4,
'FontBBox' => '[-1012 -238 1000 996]',
'ItalicAngle' => 0,
'StemV' => 87,
'MissingWidth' => 1000,
'ItalicAngle' => 0.0,
'StemV' => 87.0,
'MissingWidth' => 1000.0,
);
$up=-72;
$ut=49;
Expand Down
111 changes: 111 additions & 0 deletions src/font/unifont/babelstonehan-bolditalic-character-width-127.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<?php
$rangeid=32;
$prevcid=126;
$prevwidth=500;
$interval=true;
$range=array (
29 =>
array (
0 => 500,
),
32 =>
array (
0 => 500,
1 => 500,
'interval' => true,
2 => 500,
3 => 500,
4 => 500,
5 => 500,
6 => 500,
7 => 500,
8 => 500,
9 => 500,
10 => 500,
11 => 500,
12 => 500,
13 => 500,
14 => 500,
15 => 500,
16 => 500,
17 => 500,
18 => 500,
19 => 500,
20 => 500,
21 => 500,
22 => 500,
23 => 500,
24 => 500,
25 => 500,
26 => 500,
27 => 500,
28 => 500,
29 => 500,
30 => 500,
31 => 500,
32 => 500,
33 => 500,
34 => 500,
35 => 500,
36 => 500,
37 => 500,
38 => 500,
39 => 500,
40 => 500,
41 => 500,
42 => 500,
43 => 500,
44 => 500,
45 => 500,
46 => 500,
47 => 500,
48 => 500,
49 => 500,
50 => 500,
51 => 500,
52 => 500,
53 => 500,
54 => 500,
55 => 500,
56 => 500,
57 => 500,
58 => 500,
59 => 500,
60 => 500,
61 => 500,
62 => 500,
63 => 500,
64 => 500,
65 => 500,
66 => 500,
67 => 500,
68 => 500,
69 => 500,
70 => 500,
71 => 500,
72 => 500,
73 => 500,
74 => 500,
75 => 500,
76 => 500,
77 => 500,
78 => 500,
79 => 500,
80 => 500,
81 => 500,
82 => 500,
83 => 500,
84 => 500,
85 => 500,
86 => 500,
87 => 500,
88 => 500,
89 => 500,
90 => 500,
91 => 500,
92 => 500,
93 => 500,
94 => 500,
),
);
?>
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
$name='BabelStoneHan';
$type='TTF';
$desc=array (
'Ascent' => 996,
'Descent' => -238,
'CapHeight' => 678,
'Ascent' => 996.0,
'Descent' => -238.0,
'CapHeight' => 678.0,
'Flags' => 4,
'FontBBox' => '[-1012 -238 1000 996]',
'ItalicAngle' => 0,
'StemV' => 87,
'MissingWidth' => 1000,
'ItalicAngle' => 0.0,
'StemV' => 87.0,
'MissingWidth' => 1000.0,
);
$up=-72;
$ut=49;
Expand Down
Loading

0 comments on commit b21d98a

Please sign in to comment.