zerustech/postscript

ZerusTech Postscript 组件

dev-master / 1.0.x-dev 2016-10-09 02:36 UTC

This package is auto-updated.

Last update: 2024-09-09 15:26:23 UTC


README

Build Status

ZerusTech Postscript 组件

ZerusTech Postscript 组件是一个库,提供了与变体 Postscript 文件(包括字体类型 1 等)交互的类和工具。

安装

您可以通过两种不同的方式安装此组件

  • 通过 Composer 安装

    $ cd <project-root-directory>
    $ composer require zerustech/postscript
    
  • 使用官方 Git 仓库 zerustech/postscript

示例

AsciiHexadecimalToBinaryInputStream

此类从从属输入流中读取 ascii 十六进制字节并将它们转换为二进制字节。两个十六进制字节转换为一个二进制字节。

<?php

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

use ZerusTech\Component\IO\Stream\Input\StringInputStream;
use ZerusTech\Component\Postscript\Font\TypeOne\Stream\Input;

$in = new StringInputStream('68656c6c6f');

$input = new Input\AsciiHexadecimalToBinaryInputStream($in);

$count = $input->read($string, 5); // reads upto 5 binary bytes from the stream. 

printf("%d bytes read: %s\n", $count, $string); // 'hello'

BinaryToAsciiHexadecimalInputStream

此类从从属输入流中读取二进制字节并将它们转换为 ascii 十六进制字节。一个二进制字节转换为两个 ascii 十六进制字节。

<?php

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

use ZerusTech\Component\IO\Stream\Input\StringInputStream;
use ZerusTech\Component\Postscript\Font\TypeOne\Stream\Input;

$in = new StringInputStream('hello');

$input = new Input\BinaryToAsciiHexadecimalInputStream($in);

$count = $input->read($string, 10); // reads upto 10 hex bytes from the stream. 

printf("%d bytes read: %s\n", $count, $string); // '68656C6C6F'

AsciiHexadecimalFormatInputStream

此类从从属输入流中读取 ascii 十六进制字节,并通过插入换行符 `"\n"` 进行格式化。

<?php

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

use ZerusTech\Component\IO\Stream\Input\StringInputStream;
use ZerusTech\Component\Postscript\Font\TypeOne\Stream\Input;

$in = new StringInputStream('68656c6c6f68656c6c6f68656c6c6f');

// Formats hexadecimal string as follows:
// Current column: 0
// Columns per line: 5
$input = new Input\AsciiHexadecimalFormatInputStream($in, 0, 5);

// reads upto 33 hex bytes, including line feeds from the stream. 
$count = $input->read($string, 33);

// "68656c6c6f\n68656c6c6f\n68656c6c6f\n"
printf("%d bytes read: %s\n", $count, $string);

CharStringDecodeInputStream

此类从从属输入流中读取以字符字符串编码的字节并将它们解码为纯文本。

<?php

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

use ZerusTech\Component\IO\Stream\Input\StringInputStream;
use ZerusTech\Component\Postscript\Font\TypeOne\Stream\Input;

$in = new StringInputStream("\x8e\x8b\x0c\x10\x0c\x11\x0c\x11\x0c\x21\x0b");

$input = new Input\CharStringDecodeInputStream($in);

$string = '';

while (null != $token = $input->readToken()) {

    $string .= $token.' ';
}

// "3 0 callothersubr pop pop setcurrentpoint return "
printf("%s\n", $string);

CharStringDecryptInputStream

此类从从属输入流中读取加密的字符字符串字节并将它们解密为字符字符串编码的字节。

<?php

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

use ZerusTech\Component\IO\Stream\Input\StringInputStream;
use ZerusTech\Component\Postscript\Font\TypeOne\Stream\Input;

$in = new StringInputStream("\x10\xbf\x31\x70\x9a\xa9\xe3\x3d\xee");

$input = new Input\CharStringDecryptInputStream($in);

$string = '';

$count = $input->read($string, 5);

printf("%d bytes read: %s\n", $count, $string); // 'hello'

CharStringFormatInputStream

此类从从属输入流中读取字符字符串纯文本(已解密和解码),并通过插入换行符 `"\n"` 和制表符 "\t" 进行格式化。

<?php

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

use ZerusTech\Component\IO\Stream\Input\StringInputStream;
use ZerusTech\Component\Postscript\Font\TypeOne\Stream\Input;

$in = new StringInputStream("-45 3 -10 10 -35 74 rrcurveto -249 568 rlineto ");

$input = new Input\CharStringFormatInputStream($in);

//  "-45 3 -10 10 -35 74 rrcurveto\n\t"
printf("1st formated string: %s\n", $input->format());

// "-249 568 rlineto\n\t"
printf("2nd formatted string: %s\n", $input->format());

DecryptInputStream

此类从从属输入流中读取加密的字节并执行 eexec 或字符字符串解密。

<?php

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

use ZerusTech\Component\IO\Stream\Input\StringInputStream;
use ZerusTech\Component\Postscript\Font\TypeOne\Stream\Input;

$in = new StringInputStream("\xe9\x8d\x09\xd7\x6c\xe6\x99\x52\xf0");
// R: 55665
// n: 4
$input = new Input\DecryptInputStream($in, 55665, 4);

// Performs eexec decryption
$count = $input->read($string, 5);
// hello
printf("%d bytes read: %s\n", $count, $string);

$in = new StringInputStream("\x10\xbf\x31\x70\x9a\xa9\xe3\x3d\xee");
// R: 4330
// n: 4
$input = new Input\DecryptInputStream($in, 4330, 4);

// Performs char string decryption
$count = $input->read($string, 5);
// hello
printf("%d bytes read: %s\n", $count, $string);

EexecDecryptInputStream

此类从从属输入流中读取 eexec 加密的字节并执行 eexec 解密。

<?php

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

use ZerusTech\Component\IO\Stream\Input\StringInputStream;
use ZerusTech\Component\Postscript\Font\TypeOne\Stream\Input;

$in = new StringInputStream("\xe9\x8d\x09\xd7\x6c\xe6\x99\x52\xf0");
$input = new Input\EexecDecryptInputStream($in);

// Performs eexec decryption
$count = $input->read($string, 5);
// hello
printf("%d bytes read: %s\n", $count, $string);

PfbToPfaInputStream

此类从从属输入流中读取 pfb 字节并将 pfb 字节转换为 pfa 字节。

<?php

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

use ZerusTech\Component\IO\Stream\Input\StringInputStream;
use ZerusTech\Component\IO\Stream\Input\FileInputStream;
use ZerusTech\Component\IO\Stream\Output\FileOutputStream;

use ZerusTech\Component\Postscript\Font\TypeOne\Stream\Input;

$base = __DIR__.'/Tests/Fixtures/Font/TypeOne/';

$in = new FileInputStream($base.'NimbusRomanNo9L-Regular.pfb', 'rb');

$input = new Input\PfbToPfaInputStream($in);

$out = new FileOutputStream(__DIR__.'/test.pfa', 'wb');

// Reads pfb blocks from pfb file and converts them to pfa blocks.
while (null !== $block = $input->readBlock()) {

    $out->write($block);
}

PfbToDisasmInputStream

此类从从属输入流中读取 pfb 字节并将 pfb 字节转换为 disasm 字节。

<?php

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

use ZerusTech\Component\IO\Stream\Input\StringInputStream;
use ZerusTech\Component\IO\Stream\Input\FileInputStream;
use ZerusTech\Component\IO\Stream\Output\FileOutputStream;

use ZerusTech\Component\Postscript\Font\TypeOne\Stream\Input;

$base = __DIR__.'/Tests/Fixtures/Font/TypeOne/';

$in = new FileInputStream($base.'NimbusRomanNo9L-Regular.pfb', 'rb');

$input = new Input\PfbToDisasmInputStream($in);

$out = new FileOutputStream(__DIR__.'/test.disasm', 'wb');

// Reads pfb blocks from pfb file and converts them to disasm format.
while (null !== $block = $input->readBlock()) {

    $out->write($block);
}

AsciiHexadecimalFormatOutputStream

此类通过插入换行符 `"\n"` 格式化提供的 ascii 十六进制字节并将它们写入从属输出流。

<?php

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

use ZerusTech\Component\IO\Stream\Output\StringOutputStream;
use ZerusTech\Component\Postscript\Font\TypeOne\Stream\Output;

$string = '68656c6c6f68656c6c6f68656c6c6f';

$out = new StringOutputStream();

// Format hexadecimal string as follows:
// Current column: 0
// Columsn per line: 5
$output = new Output\AsciiHexadecimalFormatOutputStream($out, 0, 5);

$output->write($string);

// "68656c6c6f\n68656c6c6f\n68656c6c6f\n"
printf("Bytes written: %s\n", $out->__toString());

AsciiHexadecimalToBinaryOutputStream

此类将提供的 ascii 十六进制字节转换为二进制字节并将它们写入从属输出流。

<?php

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

use ZerusTech\Component\IO\Stream\Output\StringOutputStream;
use ZerusTech\Component\Postscript\Font\TypeOne\Stream\Output;

$string = '68656c6c6f';

$out = new StringOutputStream();

$output = new Output\AsciiHexadecimalToBinaryOutputStream($out);

$output->write($string);

// "hello"
printf("Bytes written: %s\n", $out->__toString());

BinaryToAsciiHexadecimalOutputStream

此类将提供的二进制字节转换为 ascii 十六进制字节并将它们写入从属输出流。

<?php

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

use ZerusTech\Component\IO\Stream\Output\StringOutputStream;
use ZerusTech\Component\Postscript\Font\TypeOne\Stream\Output;

$string = 'hello';

$out = new StringOutputStream();

$output = new Output\BinaryToAsciiHexadecimalOutputStream($out);

$output->write($string);

// "68656C6C6F"
printf("Bytes written: %s\n", $out->__toString());

CharStringEncodeOutputStream

此类对提供的字节执行字符字符串编码并将它们写入从属输出流。

<?php

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

use ZerusTech\Component\IO\Stream\Output\StringOutputStream;
use ZerusTech\Component\Postscript\Font\TypeOne\Stream\Output;

$string = '3 0 callothersubr pop pop setcurrentpoint return ';

$out = new StringOutputStream();

$output = new Output\CharStringEncodeOutputStream($out);

$output->write($string);

// "\x8e\x8b\x0c\x10\x0c\x11\x0c\x11\x0c\x21\x0b"
printf("Bytes written: %s\n", $out->__toString());

CharStringEncryptOutputStream

此类对提供的字符字符串编码的字节执行字符字符串加密并将它们写入从属输出流。

<?php

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

use ZerusTech\Component\IO\Stream\Output\StringOutputStream;
use ZerusTech\Component\Postscript\Font\TypeOne\Stream\Output;

$string = 'hello';

$out = new StringOutputStream();

$output = new Output\CharStringEncryptOutputStream($out);

$output->write($string);

// "\x10\xbf\x31\x70\x9a\xa9\xe3\x3d\xee"
printf("Bytes written: %s\n", $out->__toString());

EexecEncryptOutputStream

此类对提供的 eexec 字节执行 eexec 加密并将它们写入从属输出流。

<?php

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

use ZerusTech\Component\IO\Stream\Output\StringOutputStream;
use ZerusTech\Component\Postscript\Font\TypeOne\Stream\Output;

$string = 'hello';

$out = new StringOutputStream();

$output = new Output\EexecEncryptOutputStream($out);

$output->write($string);

// "\xe9\x8d\x09\xd7\x6c\xe6\x99\x52\xf0"
printf("Bytes written: %s\n", $out->__toString());

EncryptOutputStream

此类对提供的字节执行 eexec 或字符字符串加密并将它们写入从属输出流。

<?php

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

use ZerusTech\Component\IO\Stream\Output\StringOutputStream;
use ZerusTech\Component\Postscript\Font\TypeOne\Stream\Output;

// Performs eexec encryption and uses "0000" as the first 4 random bytes.
$string = 'hello';

$out = new StringOutputStream();

$output = new Output\EncryptOutputStream($out, 55665, "0000");

$output->write($string);

// "\xe9\x8d\x09\xd7\x6c\xe6\x99\x52\xf0"
printf("Bytes written: %s\n", $out->__toString());


// Performs char string encryption and uses "\x00\x00\x00\x00" as the first 4 
// random bytes.
$out = new StringOutputStream();

$output = new Output\EncryptOutputStream($out, 4330, "\x00\x00\x00\x00");

$output->write($string);

// "\x10\xbf\x31\x70\x9a\xa9\xe3\x3d\xee"
printf("Bytes written: %s\n", $out->__toString());

参考

许可证

ZerusTech Postscript 组件MIT 许可证下发布。