File: 027_winfont

package info (click to toggle)
libpdf-builder-perl 3.027-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 23,992 kB
  • sloc: perl: 107,532; makefile: 10
file content (155 lines) | stat: -rw-r--r-- 5,094 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
#!/usr/bin/perl

use strict;
use warnings;

use File::Basename;
use PDF::Builder;
use PDF::Builder::Util;
use PDF::Builder::Win32;
use Unicode::UCD 'charinfo';
use Encode qw[:all];
use Getopt::Long;
#use Data::Dumper;
use utf8;

#my $compress = 'none'; # uncompressed streams
my $compress = 'flate'; # compressed streams

my %wxf = PDF::Builder::Win32->enumwinfonts();

foreach my $k (sort keys %wxf) {
    print "font '$wxf{$k}' has key '$k'\n";

    my $api = PDF::Builder->new(-compress => $compress);
    
    $api->mediabox(595,842);
    
    my $helv = $api->corefont('Helvetica-Bold', -encode=>'latin1');
    
    my $sx = 33;
    my $sy = 45;
    my $fx = 20;

#   my $xf = $api->winfont($k, -encode=>'latin1');
    my $xf = PDF::Builder::Win32->winfont($k, -encode=>'latin1');

    my $page = $api->page();
    $page->mediabox(595,842);

    my $gfx = $page->gfx();
    my $text = $page->text();

    $text->textlabel(50,800, $helv,20, $wxf{$k});
    
    # row number yp
    foreach my $yp (0 .. 15) {
	my $y = 15 - $yp; # row location top to bottom
	# column number x left to right
        foreach my $x (0 .. 15) {
            my $c = $yp*16 + $x;
            $text->textlabel(50+($sx*$x),50+($sy*$y), $xf,$fx, pack('C',$c));
            $text->textlabel(50+($sx*$x),50+($sy*$y)-6, $helv,6, nameByUni($c), -color=>'#a00000', -hscale=>80, -rotate=>-15);
        }
    }

    if ($xf->can('uniByCId') and $xf->can('glyphNum')) {
        my @cids = (0 .. $xf->glyphNum()-1);
        my @fbbx = $xf->fontbbox();
        my $xw = int(($fbbx[2] - $fbbx[0])/20)*20;
        my $yw = int(($fbbx[3] - $fbbx[1])/20)*20;
        my $fw = $xw>$yw? $yw: $xw;
        my $mw = 800/$fw;
        my $y0 = int((20 - $fbbx[1])/20)*20*$mw;
    
	# create pages until run out of cids
        while (scalar @cids>0) {
            $page = $api->page();
            $page->mediabox(595,842);
    
            $gfx = $page->gfx();
            $text = $page->text();
	    my $scale = 0.045;
    
	    # row positions (y value)
            foreach my $y (750,700,650,600,550,500,450,400,350,300,250,200,150,100,50) {
		# column positions (x value)
                foreach my $x (50,100,150,200,250,300,350,400,450,500) {
                    my $xo = shift(@cids);
                    $gfx->save();
                    $gfx->fillcolor('black');
                    $gfx->transform(-translate => [$x, $y], -scale => [0.045, 0.045]);
    
                    $gfx->linewidth(10);
                    $gfx->rect(0,0, 1000,1000);
                    $gfx->stroke();
    
                    my $wx = $xf->wxByCId($xo)*$mw;
                    my $x0 = (1000-$wx)/2;
    
                    $gfx->linedash(10,20);
                    $gfx->linewidth(0.5);
                    $gfx->move($x0,0);
                    $gfx->line($x0,1000);
                    $gfx->move($x0+$wx,1000);
                    $gfx->line($x0+$wx,0);
                    $gfx->move(0,$y0);
                    $gfx->line(1000,$y0);
                    $gfx->stroke();
    
                    $text->font($xf, 1000*$mw*$scale);
                    $text->translate($x+$x0*$scale,$y+$y0*$scale);
                    $text->add($xf->text_cid(pack('n',$xo)), 'Tj');
    
                    $text->font($helv, 100*$scale);
                    $text->hscale(80);
                    $text->translate($x+25*$scale,$y+860*$scale);
                    $text->text("G+$xo"); 
                    $text->translate($x+25*$scale,$y+10*$scale);
                    $text->text(sprintf('U+%04X', $xf->uniByCId($xo)));
    
                    my $name = $xf->glyphByCId($xo);
                    if ($name eq '') {
                        $text->fillcolor('red');
                        $name = "NONE";
                    } else {
                        $text->fillcolor('blue');
                    }
    
                    $text->hscale(70);
                    $text->translate($x+975*$scale,$y+860*$scale);
                    $text->text_right($name);
    
                    $text->fillcolor('black');
                    $text->translate($x+975*$scale,$y+10*$scale);
                    $text->text_right('wx='.$xf->wxByCId($xo));
    
                    $text->fillcolor('#008000');
                    $text->translate($x+500*$scale,$y+950*$scale);
                    $text->hscale(70);
                    my $ci = charinfo($xf->uniByCId($xo) || 0);
                    $text->font($helv,50*$scale);
                    $text->text_center($ci->{'name'});
    
                    # restore
		    $text->fillcolor('black');
		    $text->hscale(100);

                    $gfx->restore();
    
                    last unless scalar @cids>0;
                } # next column in row (x pos)
                last unless scalar @cids>0;
            } # next row (y pos)
            print STDERR ".";
            ## $api->finishobjects($page,$gfx);
        } # loop through cids
    } # both uniByCId and glyphNum OK

    $api->saveas("$0.$k.pdf");
    $api->end();
} # loop through keys of %wxf

#print Dumper($PDF::Builder::wf);

__END__