~ubuntu-branches/ubuntu/precise/publican/precise

« back to all changes in this revision

Viewing changes to fop-ttc-metric.pl

  • Committer: Bazaar Package Importer
  • Author(s): Raphaël Hertzog
  • Date: 2010-04-14 08:57:30 UTC
  • mfrom: (1.1.1 upstream) (2.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20100414085730-pnt4hw9bt7hinmvs
Tags: 1.6.2-1
* New upstream release.
* Fix watch file to cope with the new upstream download URL.
* Update dependencies and build-dependencies to better match the
  information in Build.PL.
* Use dh_lintian to install lintian overrides instead of custom rule
* Drop Users_Guide/Makefile from debian/publican.examples, it's no
  longer provided.
* Fix location of Users' Guide in doc-base file.
* Switch to source format 3.0 (quilt)
* Add patch fix-typo-in-doc to correct a typo in POD documentation.
* Remove lintian overrides as they are all unused.
* Add myself to Uploaders.
* Update Standards-Version to 3.8.4 (no change needed)
* Update upstream URL to match the new canonical name
* Do not compress examples files.
* Ensure clean removes all files left-over by the build. Drop unneeded
  backup of publican.cfg (it's no longer modified by the build).
* Install users guide with override_dh_installdocs instead of
  override_dh_auto_install.
* Ensure the build succeed when running with DEB_BUILD_OPTS=nocheck by
  creating the files that we copy as examples.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env perl
 
2
use strict;
 
3
use warnings;
 
4
use Getopt::Long;
 
5
use Pod::Usage;
 
6
use Carp;
 
7
 
 
8
=head1 NAME
 
9
 
 
10
fop-ttc-metrics.pl - script to handle TrueType font Collections.
 
11
 
 
12
=head1 SYNOPSIS
 
13
 
 
14
fop-ttc-metrics.pl <options>
 
15
 
 
16
Options
 
17
 
 
18
    --help              Display help message
 
19
    --man               Display the man page
 
20
    --outdir            Change the output directory for the metric xml files
 
21
    --share             Change the share directory where publican common files
 
22
                        get installed
 
23
 
 
24
=head1 DESCRIPTION
 
25
 
 
26
FOP <= 0.95 can not automatically generate metrics for true Type collections so
 
27
Publican must generate them at build time.
 
28
 
 
29
This script will look for known ttc files and generate metrics if they are found.
 
30
This requires the packaging system to Require the ttc font packages as build and
 
31
install dependencies.
 
32
 
 
33
=cut
 
34
 
 
35
my $man       = undef;
 
36
my $help      = undef;
 
37
my $outdir    = 'font-metrics';
 
38
my $share     = '/usr/share/publican';
 
39
my $conf_file = 'datadir/fop/fop.xconf';
 
40
 
 
41
GetOptions(
 
42
    'h|help|?'   => \$help,
 
43
    'man'        => \$man,
 
44
    'outdir|d=s' => \$outdir,
 
45
    'share=s'    => \$share,
 
46
    'conffile=s' => \$conf_file,
 
47
) or pod2usage(2);
 
48
pod2usage(1) if $help;
 
49
pod2usage( -verbose => 2 ) if $man;
 
50
 
 
51
# FYI you also need to add the font names to template pickfont in datadir/xsl/pdf.xsl
 
52
my %ttclist = (
 
53
    'AR PL UMing CN' => {
 
54
        path   => '/usr/share/fonts/cjkuni-uming/uming.ttc',
 
55
        style  => [ 'normal', 'italic' ],
 
56
        weight => [ 'normal', 'bold' ],
 
57
    },
 
58
    'AR PL UMing TW' => {
 
59
        path   => '/usr/share/fonts/cjkuni-uming/uming.ttc',
 
60
        style  => [ 'normal', 'italic' ],
 
61
        weight => [ 'normal', 'bold' ],
 
62
    },
 
63
);
 
64
 
 
65
my $ttfcommand
 
66
    = 'java -cp /usr/share/java/fop.jar:/usr/share/java/avalon-framework.jar:/usr/share/java/commons-logging.jar:/usr/share/java/commons-io.jar:/usr/share/java/xmlgraphics-commons.jar org.apache.fop.fonts.apps.TTFReader';
 
67
 
 
68
open( my $conf, '>', $conf_file )
 
69
    || croak("Can't open fop.xconf for output!: $!");
 
70
 
 
71
sub font_metrics {
 
72
    `rm -rf $outdir`;
 
73
    system("mkdir -p $outdir");
 
74
    croak("can't create metric dir: $!") if ($@);
 
75
 
 
76
    foreach my $font ( sort( keys(%ttclist) ) ) {
 
77
        my $path                   = $ttclist{$font}{path};
 
78
        my $spaces_break_stupid_os = $font;
 
79
        $spaces_break_stupid_os =~ s/\s/_/g;
 
80
        my $url = qq{$share/fop/font-metrics/$spaces_break_stupid_os.xml};
 
81
 
 
82
        if ( -f $path ) {
 
83
            my $command
 
84
                = qq{$ttfcommand -fn "$font" -ttcname "$font" $path $outdir/$spaces_break_stupid_os.xml};
 
85
            print STDERR $command;
 
86
            my $result = system($command );
 
87
            croak("FAILED to create font metric for $font: $!")
 
88
                if ( $@ || $result );
 
89
            print {$conf}
 
90
                qq{\t\t\t\t<font metrics-url="$url" kerning="yes" embed-url="$path">\n};
 
91
            foreach my $style ( @{ $ttclist{$font}{style} } ) {
 
92
                foreach my $weight ( @{ $ttclist{$font}{weight} } ) {
 
93
                    print {$conf}
 
94
                        qq{\t\t\t\t\t<font-triplet name="$font" style="$style" weight="$weight"/>\n};
 
95
                }
 
96
            }
 
97
            print {$conf} qq{\t\t\t\t</font>\n};
 
98
        }
 
99
    }
 
100
}
 
101
 
 
102
print {$conf} <<TOP;
 
103
<?xml version="1.0"?>
 
104
<fop version="1.0">
 
105
\t<base>.</base>
 
106
\t<source-resolution>72</source-resolution>
 
107
\t<target-resolution>72</target-resolution>
 
108
\t<default-page-settings height="240mm" width="120mm"/>
 
109
\t<renderers>
 
110
\t\t<renderer mime="application/pdf">
 
111
\t\t\t<filterList>
 
112
\t\t\t\t<value>flate</value>
 
113
\t\t\t</filterList>
 
114
\t\t\t<fonts>
 
115
TOP
 
116
 
 
117
font_metrics();
 
118
 
 
119
print {$conf} <<BOTTOM;
 
120
\t\t\t\t<auto-detect/>
 
121
\t\t\t</fonts>
 
122
\t\t</renderer>
 
123
\t</renderers>
 
124
</fop>
 
125
BOTTOM
 
126
 
 
127
close($conf);
 
128
 
 
129
exit;
 
130