Пример #1
0
if (!is_dir($options['outpath']) || !is_writable($options['outpath'])) {
    fwrite(STDERR, 'ERROR: Can\'t write to ' . $options['outpath'] . "\n\n");
    exit(2);
}
if (empty($options['fonts'])) {
    fwrite(STDERR, 'ERROR: missing input fonts (try --help for usage)' . "\n\n");
    exit(3);
}
fwrite(STDOUT, "\n" . '>>> Converting fonts:' . "\n" . '*** Output directory set to ' . $options['outpath'] . "\n");
// count conversions
$convert_errors = 0;
$convert_success = 0;
require_once dirname(dirname(__DIR__)) . '/vendor/autoload.php';
foreach ($options['fonts'] as $font) {
    try {
        $import = new \Com\Tecnick\Pdf\Font\Import(realpath($font), $options['outpath'], $options['type'], $options['encoding'], $options['flags'], $options['platform_id'], $options['encoding_id'], $options['linked']);
        $fontname = $import->getFontName();
        fwrite(STDOUT, "" . '+++ OK   : ' . $font . ' added as ' . $fontname . "\n");
        ++$convert_success;
    } catch (\Exception $exc) {
        ++$convert_errors;
        fwrite(STDERR, "" . '--- ERROR: can\'t add ' . $font . "\n           " . $exc->getMessage() . "\n");
    }
}
$endmsg = '>>> PROCESS COMPLETED: ' . $convert_success . ' CONVERTED FONT(S), ' . $convert_errors . ' ERROR(S)!' . "\n\n";
if ($convert_errors > 0) {
    fwrite(STDERR, "" . $endmsg . 'ERROR' . "");
    exit(4);
}
fwrite(STDOUT, "" . $endmsg . "");
exit(0);
Пример #2
0
 /**
  * @dataProvider importDataProvider
  */
 public function testImport($fontdir, $font, $outname, $type = null, $encoding = null)
 {
     $indir = __DIR__ . '/../util/vendor/font/' . $fontdir . '/';
     $outdir = __DIR__ . '/../target/tmptest/' . $fontdir . '/';
     system('rm -rf ' . __DIR__ . '/../target/tmptest/ && mkdir -p ' . $outdir);
     $imp = new \Com\Tecnick\Pdf\Font\Import($indir . $font, $outdir, $type, $encoding);
     $this->assertEquals($outname, $imp->getFontName());
     $json = json_decode(file_get_contents($outdir . $outname . '.json'), true);
     $this->assertNotNull($json);
     $this->assertArrayHasKey('type', $json);
     $this->assertArrayHasKey('name', $json);
     $this->assertArrayHasKey('up', $json);
     $this->assertArrayHasKey('ut', $json);
     $this->assertArrayHasKey('dw', $json);
     $this->assertArrayHasKey('diff', $json);
     $this->assertArrayHasKey('desc', $json);
     $this->assertArrayHasKey('Flags', $json['desc']);
     $metric = $imp->getFontMetrics();
     $this->assertEquals('[' . $metric['bbox'] . ']', $json['desc']['FontBBox']);
     $this->assertEquals($metric['italicAngle'], $json['desc']['ItalicAngle']);
     $this->assertEquals($metric['Ascent'], $json['desc']['Ascent']);
     $this->assertEquals($metric['Descent'], $json['desc']['Descent']);
     $this->assertEquals($metric['Leading'], $json['desc']['Leading']);
     $this->assertEquals($metric['CapHeight'], $json['desc']['CapHeight']);
     $this->assertEquals($metric['XHeight'], $json['desc']['XHeight']);
     $this->assertEquals($metric['StemV'], $json['desc']['StemV']);
     $this->assertEquals($metric['StemH'], $json['desc']['StemH']);
     $this->assertEquals($metric['AvgWidth'], $json['desc']['AvgWidth']);
     $this->assertEquals($metric['MaxWidth'], $json['desc']['MaxWidth']);
     $this->assertEquals($metric['MissingWidth'], $json['desc']['MissingWidth']);
 }