File: iso-8859-1.pl

package info (click to toggle)
libpostscript-file-perl 2.22%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 820 kB
  • ctags: 274
  • sloc: perl: 7,056; sh: 51; makefile: 2
file content (62 lines) | stat: -rwxr-xr-x 1,547 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#! /usr/bin/perl
#---------------------------------------------------------------------
# This example is hereby placed in the public domain.
# You may copy from it freely.
#
# This displays PostScript's slightly modified version of iso-8859-1.
#---------------------------------------------------------------------

use strict;
use warnings;

use PostScript::File 1.05;      # Need iso-8859-1 support

my $ps = PostScript::File->new(
  paper    => 'letter',
  reencode => 'iso-8859-1',
  auto_hyphen => 0,             # We don't want any hyphen translation
  need_fonts  => ['Helvetica'],
  left     => 72,
  top      => 72,
);

$ps->add_to_page( <<END_PAGE );
    /Helvetica-iso findfont
    16 scalefont
    setfont

    181 700 moveto
    (PostScript's version of ISO-8859-1) show
END_PAGE

my $char = 32;

my ($xMar, $y) = ($ps->get_bounding_box)[0,3];

my $xStep = 26;
my $yStep = 24;

my $xLeft = $xMar + 50;
$y -= 2 * $yStep;

for my $i (0 .. 0xF) {
  $ps->add_to_page(sprintf "%d %d moveto\n%s show\n",
                   $xLeft + $i * $xStep, $y,
                   $ps->pstr(sprintf '%X', $i));
}

while ($char < 0x100) {
  $y -= $yStep;

  $ps->add_to_page(sprintf "%d %d moveto\n%s show\n",
                     $xMar, $y,
                     $ps->pstr(sprintf '0x%X_', $char/16));

  for my $i (0 .. 0xF) {
    $ps->add_to_page(sprintf "%d %d moveto\n%s show\n",
                     $xLeft + $i * $xStep, $y,
                     $ps->pstr(pack('C', $char++)));
  }
}

printf "Wrote %s...\n", $ps->output("iso-8859-1", $ENV{TMP});