rbpdf-font 1.19.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CHANGELOG +9 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +12 -0
- data/lib/fonts/README.z +2 -0
- data/lib/fonts/arialunicid0_cw.rb +1738 -0
- data/lib/fonts/cid0cs.rb +21 -0
- data/lib/fonts/cid0ct.rb +21 -0
- data/lib/fonts/cid0jp.rb +21 -0
- data/lib/fonts/cid0kr.rb +21 -0
- data/lib/fonts/courier.rb +37 -0
- data/lib/fonts/dejavu-fonts-ttf-2.35/AUTHORS +56 -0
- data/lib/fonts/dejavu-fonts-ttf-2.35/BUGS +3 -0
- data/lib/fonts/dejavu-fonts-ttf-2.35/LICENSE +99 -0
- data/lib/fonts/dejavu-fonts-ttf-2.35/NEWS +1429 -0
- data/lib/fonts/dejavu-fonts-ttf-2.35/README +59 -0
- data/lib/fonts/dejavusans.ctg.z +0 -0
- data/lib/fonts/dejavusans.rb +551 -0
- data/lib/fonts/dejavusans.z +0 -0
- data/lib/fonts/dejavusansb.ctg.z +0 -0
- data/lib/fonts/dejavusansb.rb +551 -0
- data/lib/fonts/dejavusansb.z +0 -0
- data/lib/fonts/dejavusansbi.ctg.z +0 -0
- data/lib/fonts/dejavusansbi.rb +496 -0
- data/lib/fonts/dejavusansbi.z +0 -0
- data/lib/fonts/dejavusanscondensed.ctg.z +0 -0
- data/lib/fonts/dejavusanscondensed.rb +551 -0
- data/lib/fonts/dejavusanscondensed.z +0 -0
- data/lib/fonts/dejavusanscondensedb.ctg.z +0 -0
- data/lib/fonts/dejavusanscondensedb.rb +551 -0
- data/lib/fonts/dejavusanscondensedb.z +0 -0
- data/lib/fonts/dejavusanscondensedbi.ctg.z +0 -0
- data/lib/fonts/dejavusanscondensedbi.rb +496 -0
- data/lib/fonts/dejavusanscondensedbi.z +0 -0
- data/lib/fonts/dejavusanscondensedi.ctg.z +0 -0
- data/lib/fonts/dejavusanscondensedi.rb +496 -0
- data/lib/fonts/dejavusanscondensedi.z +0 -0
- data/lib/fonts/dejavusansextralight.ctg.z +0 -0
- data/lib/fonts/dejavusansextralight.rb +213 -0
- data/lib/fonts/dejavusansextralight.z +0 -0
- data/lib/fonts/dejavusansi.ctg.z +0 -0
- data/lib/fonts/dejavusansi.rb +496 -0
- data/lib/fonts/dejavusansi.z +0 -0
- data/lib/fonts/dejavusansmono.ctg.z +0 -0
- data/lib/fonts/dejavusansmono.rb +340 -0
- data/lib/fonts/dejavusansmono.z +0 -0
- data/lib/fonts/dejavusansmonob.ctg.z +0 -0
- data/lib/fonts/dejavusansmonob.rb +340 -0
- data/lib/fonts/dejavusansmonob.z +0 -0
- data/lib/fonts/dejavusansmonobi.ctg.z +0 -0
- data/lib/fonts/dejavusansmonobi.rb +282 -0
- data/lib/fonts/dejavusansmonobi.z +0 -0
- data/lib/fonts/dejavusansmonoi.ctg.z +0 -0
- data/lib/fonts/dejavusansmonoi.rb +282 -0
- data/lib/fonts/dejavusansmonoi.z +0 -0
- data/lib/fonts/dejavuserif.ctg.z +0 -0
- data/lib/fonts/dejavuserif.rb +348 -0
- data/lib/fonts/dejavuserif.z +0 -0
- data/lib/fonts/dejavuserifb.ctg.z +0 -0
- data/lib/fonts/dejavuserifb.rb +346 -0
- data/lib/fonts/dejavuserifb.z +0 -0
- data/lib/fonts/dejavuserifbi.ctg.z +0 -0
- data/lib/fonts/dejavuserifbi.rb +347 -0
- data/lib/fonts/dejavuserifbi.z +0 -0
- data/lib/fonts/dejavuserifcondensed.ctg.z +0 -0
- data/lib/fonts/dejavuserifcondensed.rb +348 -0
- data/lib/fonts/dejavuserifcondensed.z +0 -0
- data/lib/fonts/dejavuserifcondensedb.ctg.z +0 -0
- data/lib/fonts/dejavuserifcondensedb.rb +346 -0
- data/lib/fonts/dejavuserifcondensedb.z +0 -0
- data/lib/fonts/dejavuserifcondensedbi.ctg.z +0 -0
- data/lib/fonts/dejavuserifcondensedbi.rb +347 -0
- data/lib/fonts/dejavuserifcondensedbi.z +0 -0
- data/lib/fonts/dejavuserifcondensedi.ctg.z +0 -0
- data/lib/fonts/dejavuserifcondensedi.rb +347 -0
- data/lib/fonts/dejavuserifcondensedi.z +0 -0
- data/lib/fonts/dejavuserifi.ctg.z +0 -0
- data/lib/fonts/dejavuserifi.rb +347 -0
- data/lib/fonts/dejavuserifi.z +0 -0
- data/lib/fonts/freefont-20080912/AUTHORS +191 -0
- data/lib/fonts/freefont-20080912/COPYING +341 -0
- data/lib/fonts/freefont-20080912/CREDITS +506 -0
- data/lib/fonts/freefont-20080912/ChangeLog +3320 -0
- data/lib/fonts/freefont-20080912/INSTALL +81 -0
- data/lib/fonts/freefont-20080912/README +108 -0
- data/lib/fonts/freemono.ctg.z +0 -0
- data/lib/fonts/freemono.rb +204 -0
- data/lib/fonts/freemono.z +0 -0
- data/lib/fonts/freemonob.ctg.z +0 -0
- data/lib/fonts/freemonob.rb +121 -0
- data/lib/fonts/freemonob.z +0 -0
- data/lib/fonts/freemonobi.ctg.z +0 -0
- data/lib/fonts/freemonobi.rb +85 -0
- data/lib/fonts/freemonobi.z +0 -0
- data/lib/fonts/freemonoi.ctg.z +0 -0
- data/lib/fonts/freemonoi.rb +137 -0
- data/lib/fonts/freemonoi.z +0 -0
- data/lib/fonts/freesans.ctg.z +0 -0
- data/lib/fonts/freesans.rb +197 -0
- data/lib/fonts/freesans.z +0 -0
- data/lib/fonts/freesansb.ctg.z +0 -0
- data/lib/fonts/freesansb.rb +137 -0
- data/lib/fonts/freesansb.z +0 -0
- data/lib/fonts/freesansbi.ctg.z +0 -0
- data/lib/fonts/freesansbi.rb +109 -0
- data/lib/fonts/freesansbi.z +0 -0
- data/lib/fonts/freesansi.ctg.z +0 -0
- data/lib/fonts/freesansi.rb +137 -0
- data/lib/fonts/freesansi.z +0 -0
- data/lib/fonts/freeserif.ctg.z +0 -0
- data/lib/fonts/freeserif.rb +286 -0
- data/lib/fonts/freeserif.z +0 -0
- data/lib/fonts/freeserifb.ctg.z +0 -0
- data/lib/fonts/freeserifb.rb +165 -0
- data/lib/fonts/freeserifb.z +0 -0
- data/lib/fonts/freeserifbi.ctg.z +0 -0
- data/lib/fonts/freeserifbi.rb +131 -0
- data/lib/fonts/freeserifbi.z +0 -0
- data/lib/fonts/freeserifi.ctg.z +0 -0
- data/lib/fonts/freeserifi.rb +152 -0
- data/lib/fonts/freeserifi.z +0 -0
- data/lib/fonts/helvetica.rb +34 -0
- data/lib/fonts/helveticab.rb +34 -0
- data/lib/fonts/helveticabi.rb +34 -0
- data/lib/fonts/helveticai.rb +34 -0
- data/lib/fonts/hysmyeongjostdmedium.rb +31 -0
- data/lib/fonts/kozgopromedium.rb +47 -0
- data/lib/fonts/kozminproregular.rb +46 -0
- data/lib/fonts/msungstdlight.rb +23 -0
- data/lib/fonts/stsongstdlight.rb +23 -0
- data/lib/fonts/symbol.rb +33 -0
- data/lib/fonts/times.rb +34 -0
- data/lib/fonts/timesb.rb +34 -0
- data/lib/fonts/timesbi.rb +34 -0
- data/lib/fonts/timesi.rb +34 -0
- data/lib/fonts/ttf2ufm/README.TXT +132 -0
- data/lib/fonts/ttf2ufm/enc/cp1250.map +251 -0
- data/lib/fonts/ttf2ufm/enc/cp1251.map +255 -0
- data/lib/fonts/ttf2ufm/enc/cp1252.map +251 -0
- data/lib/fonts/ttf2ufm/enc/cp1253.map +239 -0
- data/lib/fonts/ttf2ufm/enc/cp1254.map +249 -0
- data/lib/fonts/ttf2ufm/enc/cp1255.map +233 -0
- data/lib/fonts/ttf2ufm/enc/cp1257.map +244 -0
- data/lib/fonts/ttf2ufm/enc/cp1258.map +247 -0
- data/lib/fonts/ttf2ufm/enc/cp874.map +225 -0
- data/lib/fonts/ttf2ufm/enc/iso-8859-1.map +256 -0
- data/lib/fonts/ttf2ufm/enc/iso-8859-11.map +248 -0
- data/lib/fonts/ttf2ufm/enc/iso-8859-15.map +256 -0
- data/lib/fonts/ttf2ufm/enc/iso-8859-16.map +256 -0
- data/lib/fonts/ttf2ufm/enc/iso-8859-2.map +256 -0
- data/lib/fonts/ttf2ufm/enc/iso-8859-4.map +256 -0
- data/lib/fonts/ttf2ufm/enc/iso-8859-5.map +256 -0
- data/lib/fonts/ttf2ufm/enc/iso-8859-7.map +250 -0
- data/lib/fonts/ttf2ufm/enc/iso-8859-9.map +256 -0
- data/lib/fonts/ttf2ufm/enc/koi8-r.map +256 -0
- data/lib/fonts/ttf2ufm/enc/koi8-u.map +256 -0
- data/lib/fonts/ttf2ufm/makeallttffonts.rb +48 -0
- data/lib/fonts/ttf2ufm/makefont.rb +617 -0
- data/lib/fonts/ttf2ufm/ttf2ufm +0 -0
- data/lib/fonts/uni2cid_ac15.rb +23613 -0
- data/lib/fonts/uni2cid_ag15.rb +30222 -0
- data/lib/fonts/uni2cid_aj16.rb +15705 -0
- data/lib/fonts/uni2cid_ak12.rb +17530 -0
- data/lib/fonts/zapfdingbats.rb +33 -0
- data/lib/rbpdf-font.rb +46 -0
- data/rbpdf-font.gemspec +35 -0
- data/test/rbpdf_font_file_test.rb +118 -0
- data/test/test_helper.rb +4 -0
- metadata +257 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
#============================================================+
|
|
2
|
+
# File name : makeallttffonts.rb
|
|
3
|
+
# Begin : 2015-09-20
|
|
4
|
+
# Last Update : 2015-09-20
|
|
5
|
+
# License : GNU LGPL (http://www.gnu.org/copyleft/lesser.html)
|
|
6
|
+
# ----------------------------------------------------------------------------
|
|
7
|
+
# This program is free software: you can redistribute it and/or modify
|
|
8
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
|
9
|
+
# the Free Software Foundation, either version 2.1 of the License, or
|
|
10
|
+
# (at your option) any later version.
|
|
11
|
+
#
|
|
12
|
+
# This program is distributed in the hope that it will be useful,
|
|
13
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
14
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
15
|
+
# GNU Lesser General Public License for more details.
|
|
16
|
+
#
|
|
17
|
+
# You should have received a copy of the GNU Lesser General Public License
|
|
18
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
19
|
+
# ----------------------------------------------------------------------------
|
|
20
|
+
# Description : Process all TTF files on current directory to
|
|
21
|
+
# build RBPDF compatible font files.
|
|
22
|
+
#
|
|
23
|
+
# Author: Jun NAITOH
|
|
24
|
+
#============================================================+
|
|
25
|
+
|
|
26
|
+
#
|
|
27
|
+
# Process all TTF files on current directory to build RBPDF compatible font files.
|
|
28
|
+
# @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
|
|
29
|
+
#
|
|
30
|
+
|
|
31
|
+
if RUBY_VERSION < '1.9'
|
|
32
|
+
abort("Error: Ruby 1.8.7 not supported.")
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
require "open3"
|
|
36
|
+
|
|
37
|
+
# read directory for files (only graphics files).
|
|
38
|
+
Dir.glob("*ttf").each{|file|
|
|
39
|
+
basename = File.basename(file, ".*")
|
|
40
|
+
o, s = Open3.capture2('./ttf2ufm -a -F ' + file)
|
|
41
|
+
puts o
|
|
42
|
+
o, s = Open3.capture2('ruby makefont.rb ' + file + ' ' + basename + '.ufm')
|
|
43
|
+
puts o
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
#============================================================+
|
|
47
|
+
# END OF FILE
|
|
48
|
+
#============================================================+
|
|
@@ -0,0 +1,617 @@
|
|
|
1
|
+
#============================================================+
|
|
2
|
+
# File name : makefont.rb
|
|
3
|
+
# Begin : 2004-12-31
|
|
4
|
+
# Last Update : 2010-03-19
|
|
5
|
+
# Version : 1.2.006
|
|
6
|
+
# License : GNU LGPL (http://www.gnu.org/copyleft/lesser.html)
|
|
7
|
+
# ----------------------------------------------------------------------------
|
|
8
|
+
# Copyright (C) 2008 Nicola Asuni - Tecnick.com S.r.l.
|
|
9
|
+
#
|
|
10
|
+
# This program is free software: you can redistribute it and/or modify
|
|
11
|
+
# it under the terms of the GNU Lesser General Public License as published by
|
|
12
|
+
# the Free Software Foundation, either version 2.1 of the License, or
|
|
13
|
+
# (at your option) any later version.
|
|
14
|
+
#
|
|
15
|
+
# This program is distributed in the hope that it will be useful,
|
|
16
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
17
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
18
|
+
# GNU Lesser General Public License for more details.
|
|
19
|
+
#
|
|
20
|
+
# You should have received a copy of the GNU Lesser General Public License
|
|
21
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
22
|
+
#
|
|
23
|
+
# See LICENSE.TXT file for more information.
|
|
24
|
+
# ----------------------------------------------------------------------------
|
|
25
|
+
#
|
|
26
|
+
# Description : Utility to generate font definition files for RBPDF
|
|
27
|
+
#
|
|
28
|
+
# Authors: Nicola Asuni, Olivier Plathey, Steven Wittens
|
|
29
|
+
#
|
|
30
|
+
# (c) Copyright:
|
|
31
|
+
# Nicola Asuni
|
|
32
|
+
# Tecnick.com S.r.l.
|
|
33
|
+
# Via della Pace, 11
|
|
34
|
+
# 09044 Quartucciu (CA)
|
|
35
|
+
# ITALY
|
|
36
|
+
# www.tecnick.com
|
|
37
|
+
# info@tecnick.com
|
|
38
|
+
#============================================================+
|
|
39
|
+
|
|
40
|
+
#
|
|
41
|
+
# Utility to generate font definition files fot RBPDF.
|
|
42
|
+
# @author Nicola Asuni, Olivier Plathey, Steven Wittens
|
|
43
|
+
# @copyright 2004-2008 Nicola Asuni - Tecnick.com S.r.l (www.tecnick.com) Via Della Pace, 11 - 09044 - Quartucciu (CA) - ITALY - www.tecnick.com - info@tecnick.com
|
|
44
|
+
# @package com.tecnick.tcpdf
|
|
45
|
+
# @link http://www.tcpdf.org
|
|
46
|
+
# @license http://www.gnu.org/copyleft/lesser.html LGPL
|
|
47
|
+
#
|
|
48
|
+
|
|
49
|
+
#
|
|
50
|
+
# [@param string :fontfile] path to font file (TTF, OTF or PFB).
|
|
51
|
+
# [@param string :fmfile] font metrics file (UFM or AFM).
|
|
52
|
+
# [@param boolean :embedded] Set to false to not embed the font, true otherwise (default).
|
|
53
|
+
# [@param string :enc] Name of the encoding table to use. Omit this parameter for TrueType Unicode, OpenType Unicode and symbolic fonts like Symbol or ZapfDingBats.
|
|
54
|
+
# [@param hash :patch] Optional modification of the encoding
|
|
55
|
+
#
|
|
56
|
+
def MakeFont(fontfile, fmfile, embedded=true, enc='cp1252', patch={})
|
|
57
|
+
# Generate a font definition file
|
|
58
|
+
unless File.exist?(fontfile)
|
|
59
|
+
abort('Error: file not found: ' + fontfile)
|
|
60
|
+
end
|
|
61
|
+
unless File.exist?(fmfile)
|
|
62
|
+
abort('Error: file not found: ' + fmfile)
|
|
63
|
+
end
|
|
64
|
+
cidtogidmap = ''
|
|
65
|
+
map = []
|
|
66
|
+
diff = ''
|
|
67
|
+
dw = 0 # default width
|
|
68
|
+
ffext = fontfile[-3..-1].downcase
|
|
69
|
+
fmext = fmfile[-3..-1].downcase
|
|
70
|
+
type = ''
|
|
71
|
+
if fmext == 'afm'
|
|
72
|
+
if (ffext == 'ttf') or (ffext == 'otf')
|
|
73
|
+
type = 'TrueType'
|
|
74
|
+
elsif ffext == 'pfb'
|
|
75
|
+
type = 'Type1'
|
|
76
|
+
else
|
|
77
|
+
abort('Error: unrecognized font file extension: ' + ffext)
|
|
78
|
+
end
|
|
79
|
+
if enc
|
|
80
|
+
map = ReadMap(enc)
|
|
81
|
+
patch.each {|cc, gn|
|
|
82
|
+
map[cc] = gn
|
|
83
|
+
}
|
|
84
|
+
end
|
|
85
|
+
fm, map = ReadAFM(fmfile, map)
|
|
86
|
+
#if widths['.notdef']
|
|
87
|
+
# dw = widths['.notdef']
|
|
88
|
+
#end
|
|
89
|
+
if enc
|
|
90
|
+
diff = MakeFontEncoding(map)
|
|
91
|
+
end
|
|
92
|
+
fd = MakeFontDescriptor(fm, map.empty?)
|
|
93
|
+
elsif fmext == 'ufm'
|
|
94
|
+
enc = ''
|
|
95
|
+
if (ffext == 'ttf') or (ffext == 'otf')
|
|
96
|
+
type = 'TrueTypeUnicode'
|
|
97
|
+
else
|
|
98
|
+
abort('Error: not a TrueType font: ' + ffext)
|
|
99
|
+
end
|
|
100
|
+
fm, cidtogidmap = ReadUFM(fmfile, cidtogidmap)
|
|
101
|
+
dw = fm['MissingWidth']
|
|
102
|
+
fd = MakeFontDescriptor(fm, false)
|
|
103
|
+
end
|
|
104
|
+
# Start generation
|
|
105
|
+
basename = File.basename(fmfile, ".*").downcase
|
|
106
|
+
s = 'RBPDFFontDescriptor.define(\'' + basename + "') do |font|\n"
|
|
107
|
+
s << " font[:type]='" + type + "'\n"
|
|
108
|
+
s << " font[:name]='" + fm['FontName'] + "'\n"
|
|
109
|
+
s << " font[:desc]=" + fd + "\n"
|
|
110
|
+
if fm['UnderlinePosition'].nil?
|
|
111
|
+
fm['UnderlinePosition'] = -100
|
|
112
|
+
end
|
|
113
|
+
if fm['UnderlineThickness'].nil?
|
|
114
|
+
fm['UnderlineThickness'] = 50
|
|
115
|
+
end
|
|
116
|
+
s << " font[:up]=" + fm['UnderlinePosition'].to_s + "\n"
|
|
117
|
+
s << " font[:ut]=" + fm['UnderlineThickness'].to_s + "\n"
|
|
118
|
+
if dw <= 0
|
|
119
|
+
if fm['Widths'][32] and (fm['Widths'][32].to_i > 0)
|
|
120
|
+
# assign default space width
|
|
121
|
+
dw = fm['Widths'][32].to_i
|
|
122
|
+
else
|
|
123
|
+
dw = 600
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
s << " font[:dw]=" + dw.to_s + "\n"
|
|
127
|
+
s << " font[:cw]=" + MakeWidthArray(fm) + "\n"
|
|
128
|
+
s << " font[:enc]='" + enc + "'\n"
|
|
129
|
+
s << " font[:diff]='" + diff + "'\n"
|
|
130
|
+
if embedded
|
|
131
|
+
# Embedded font
|
|
132
|
+
if (type == 'TrueType') or (type == 'TrueTypeUnicode')
|
|
133
|
+
CheckTTF(fontfile)
|
|
134
|
+
end
|
|
135
|
+
f = open(fontfile, 'rb')
|
|
136
|
+
if !f
|
|
137
|
+
abort('Error: Unable to open ' + fontfile)
|
|
138
|
+
end
|
|
139
|
+
file = f.read(File::stat(fontfile).size)
|
|
140
|
+
f.close
|
|
141
|
+
if type == 'Type1'
|
|
142
|
+
# Find first two sections and discard third one
|
|
143
|
+
header = (file[0, 1].unpack('C')[0] == 128)
|
|
144
|
+
if header
|
|
145
|
+
# Strip first binary header
|
|
146
|
+
file = file[6,-1]
|
|
147
|
+
end
|
|
148
|
+
pos = file.index('eexec')
|
|
149
|
+
if pos.nil?
|
|
150
|
+
abort('Error: font file does not seem to be valid Type1')
|
|
151
|
+
end
|
|
152
|
+
size1 = pos + 6
|
|
153
|
+
if header and (file{size1}.unpack('C')[0] == 128)
|
|
154
|
+
# Strip second binary header
|
|
155
|
+
file = file[0, size1] + file[(size1 + 6)..-1]
|
|
156
|
+
end
|
|
157
|
+
pos = file.index('00000000')
|
|
158
|
+
if pos.nil?
|
|
159
|
+
abort('Error: font file does not seem to be valid Type1')
|
|
160
|
+
end
|
|
161
|
+
size2 = pos - size1
|
|
162
|
+
file = file[0, size1 + size2]
|
|
163
|
+
end
|
|
164
|
+
basename = basename.downcase
|
|
165
|
+
if Object.const_defined?(:Zlib)
|
|
166
|
+
cmp = basename + '.z'
|
|
167
|
+
SaveToFile(cmp, Zlib::Deflate.deflate(file, 9), 'b')
|
|
168
|
+
s << ' font[:file]=\'' + cmp + "'\n"
|
|
169
|
+
print "Font file compressed (" + cmp + ")\n"
|
|
170
|
+
unless cidtogidmap.empty?
|
|
171
|
+
cmp = basename + '.ctg.z'
|
|
172
|
+
SaveToFile(cmp, Zlib::Deflate.deflate(cidtogidmap, 9), 'b')
|
|
173
|
+
print "CIDToGIDMap created and compressed (" + cmp + ")\n"
|
|
174
|
+
s << ' font[:ctg]=\'' + cmp + "'\n"
|
|
175
|
+
end
|
|
176
|
+
else
|
|
177
|
+
s << 'file=\'' + File.basename(fontfile, ".*") + "'\n"
|
|
178
|
+
print "Notice: font file could not be compressed (zlib extension not available)\n"
|
|
179
|
+
if !cidtogidmap.empty?
|
|
180
|
+
cmp = basename + '.ctg'
|
|
181
|
+
f = open(cmp, 'wb')
|
|
182
|
+
f.write(cidtogidmap)
|
|
183
|
+
f.close
|
|
184
|
+
print "CIDToGIDMap created (" + cmp + ")\n"
|
|
185
|
+
s << ' font[:ctg]=\'' + cmp + "'\n"
|
|
186
|
+
end
|
|
187
|
+
end
|
|
188
|
+
if type == 'Type1'
|
|
189
|
+
s << ' font[:size1]=' + size1 + "\n"
|
|
190
|
+
s << ' font[:size2]=' + size2 + "\n"
|
|
191
|
+
else
|
|
192
|
+
s << ' font[:originalsize]=' + File::stat(fontfile).size.to_s + "\n"
|
|
193
|
+
end
|
|
194
|
+
else
|
|
195
|
+
# Not embedded font
|
|
196
|
+
s << ' font[:file]=' + "''\n"
|
|
197
|
+
end
|
|
198
|
+
s << "end\n"
|
|
199
|
+
SaveToFile(basename + '.rb',s)
|
|
200
|
+
print "Font definition file generated (" + basename + ".rb)\n"
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
#
|
|
204
|
+
# Read the specified encoding map.
|
|
205
|
+
# [@param string :enc] map name (see /enc/ folder for valid names).
|
|
206
|
+
# [@return array]
|
|
207
|
+
#
|
|
208
|
+
def ReadMap(enc)
|
|
209
|
+
# Read a map file
|
|
210
|
+
file = File.dirname(__FILE__) + '/enc/' + enc.downcase + '.map'
|
|
211
|
+
a = File.open(file).readlines
|
|
212
|
+
if a.empty?
|
|
213
|
+
abort('Error: encoding not found: ' + enc)
|
|
214
|
+
end
|
|
215
|
+
#puts a.length
|
|
216
|
+
cc2gn = []
|
|
217
|
+
a.each {|l|
|
|
218
|
+
if l[0, 1] == '!'
|
|
219
|
+
#puts l
|
|
220
|
+
e = l.rstrip.split(/[ \t]+/)
|
|
221
|
+
cc = e[0][1..-1].hex
|
|
222
|
+
gn = e[2]
|
|
223
|
+
cc2gn[cc] = gn
|
|
224
|
+
end
|
|
225
|
+
}
|
|
226
|
+
256.times {|i|
|
|
227
|
+
if cc2gn[i].nil?
|
|
228
|
+
cc2gn[i] = '.notdef'
|
|
229
|
+
end
|
|
230
|
+
}
|
|
231
|
+
return cc2gn
|
|
232
|
+
end
|
|
233
|
+
|
|
234
|
+
#
|
|
235
|
+
# Read UFM file
|
|
236
|
+
# [@return hash :fm]
|
|
237
|
+
# [@return string :cidtogidmap]
|
|
238
|
+
#
|
|
239
|
+
def ReadUFM(file, cidtogidmap)
|
|
240
|
+
# Prepare empty CIDToGIDMap
|
|
241
|
+
cidtogidmap = ''.ljust(256 * 256 * 2, "\x00")
|
|
242
|
+
# Read a font metric file
|
|
243
|
+
a = File.open(file).readlines
|
|
244
|
+
if a.empty?
|
|
245
|
+
abort('File not found')
|
|
246
|
+
end
|
|
247
|
+
widths = {}
|
|
248
|
+
fm = {}
|
|
249
|
+
a.each {|l|
|
|
250
|
+
e = l.rstrip.split(' ')
|
|
251
|
+
if e.length < 2
|
|
252
|
+
next
|
|
253
|
+
end
|
|
254
|
+
code = e[0]
|
|
255
|
+
param = e[1]
|
|
256
|
+
if code == 'U'
|
|
257
|
+
# U 827 ; WX 0 ; N squaresubnosp ; G 675
|
|
258
|
+
# Character metrics
|
|
259
|
+
cc = e[1].to_i
|
|
260
|
+
if cc != -1
|
|
261
|
+
gn = e[7]
|
|
262
|
+
w = e[4].to_i
|
|
263
|
+
glyph = e[10].to_i
|
|
264
|
+
widths[cc] = w
|
|
265
|
+
if cc == 'X'.unpack('C')[0]
|
|
266
|
+
fm['CapXHeight'] = e[13]
|
|
267
|
+
end
|
|
268
|
+
# Set GID
|
|
269
|
+
if (cc >= 0) and (cc < 0xFFFF) and glyph
|
|
270
|
+
cidtogidmap[cc * 2, 1] = (glyph >> 8).chr
|
|
271
|
+
cidtogidmap[cc * 2 + 1, 1] = (glyph & 0xFF).chr
|
|
272
|
+
end
|
|
273
|
+
end
|
|
274
|
+
if (gn and (gn == '.notdef')) and fm['MissingWidth'].nil?
|
|
275
|
+
fm['MissingWidth'] = w
|
|
276
|
+
end
|
|
277
|
+
elsif code == 'FontName'
|
|
278
|
+
fm['FontName'] = param
|
|
279
|
+
elsif code == 'Weight'
|
|
280
|
+
fm['Weight'] = param
|
|
281
|
+
elsif code == 'ItalicAngle'
|
|
282
|
+
fm['ItalicAngle'] = param.to_f
|
|
283
|
+
elsif code == 'Ascender'
|
|
284
|
+
fm['Ascender'] = param.to_i
|
|
285
|
+
elsif code == 'Descender'
|
|
286
|
+
fm['Descender'] = param.to_i
|
|
287
|
+
elsif code == 'UnderlineThickness'
|
|
288
|
+
fm['UnderlineThickness'] = param.to_i
|
|
289
|
+
elsif code == 'UnderlinePosition'
|
|
290
|
+
fm['UnderlinePosition'] = param.to_i
|
|
291
|
+
elsif code == 'IsFixedPitch'
|
|
292
|
+
fm['IsFixedPitch'] = (param == 'true')
|
|
293
|
+
elsif code == 'FontBBox'
|
|
294
|
+
fm['FontBBox'] = [e[1], e[2], e[3], e[4]]
|
|
295
|
+
elsif code == 'CapHeight'
|
|
296
|
+
fm['CapHeight'] = param.to_i
|
|
297
|
+
elsif code == 'StdVW'
|
|
298
|
+
fm['StdVW'] = param.to_i
|
|
299
|
+
end
|
|
300
|
+
}
|
|
301
|
+
if fm['MissingWidth'].nil?
|
|
302
|
+
fm['MissingWidth'] = 600
|
|
303
|
+
end
|
|
304
|
+
if fm['FontName'].nil?
|
|
305
|
+
abort('FontName not found')
|
|
306
|
+
end
|
|
307
|
+
fm['Widths'] = widths
|
|
308
|
+
return fm, cidtogidmap
|
|
309
|
+
end
|
|
310
|
+
|
|
311
|
+
#
|
|
312
|
+
# Read AFM file
|
|
313
|
+
# [@return hash :fm]
|
|
314
|
+
# [@return array :map]
|
|
315
|
+
#
|
|
316
|
+
def ReadAFM(file, map)
|
|
317
|
+
# Read a font metric file
|
|
318
|
+
a = File.open(file).readlines
|
|
319
|
+
if a.empty?
|
|
320
|
+
abort('File not found')
|
|
321
|
+
end
|
|
322
|
+
widths = {}
|
|
323
|
+
fm = {}
|
|
324
|
+
fix = {
|
|
325
|
+
'Edot'=>'Edotaccent',
|
|
326
|
+
'edot'=>'edotaccent',
|
|
327
|
+
'Idot'=>'Idotaccent',
|
|
328
|
+
'Zdot'=>'Zdotaccent',
|
|
329
|
+
'zdot'=>'zdotaccent',
|
|
330
|
+
'Odblacute' => 'Ohungarumlaut',
|
|
331
|
+
'odblacute' => 'ohungarumlaut',
|
|
332
|
+
'Udblacute'=>'Uhungarumlaut',
|
|
333
|
+
'udblacute'=>'uhungarumlaut',
|
|
334
|
+
'Gcedilla'=>'Gcommaaccent',
|
|
335
|
+
'gcedilla'=>'gcommaaccent',
|
|
336
|
+
'Kcedilla'=>'Kcommaaccent',
|
|
337
|
+
'kcedilla'=>'kcommaaccent',
|
|
338
|
+
'Lcedilla'=>'Lcommaaccent',
|
|
339
|
+
'lcedilla'=>'lcommaaccent',
|
|
340
|
+
'Ncedilla'=>'Ncommaaccent',
|
|
341
|
+
'ncedilla'=>'ncommaaccent',
|
|
342
|
+
'Rcedilla'=>'Rcommaaccent',
|
|
343
|
+
'rcedilla'=>'rcommaaccent',
|
|
344
|
+
'Scedilla'=>'Scommaaccent',
|
|
345
|
+
'scedilla'=>'scommaaccent',
|
|
346
|
+
'Tcedilla'=>'Tcommaaccent',
|
|
347
|
+
'tcedilla'=>'tcommaaccent',
|
|
348
|
+
'Dslash'=>'Dcroat',
|
|
349
|
+
'dslash'=>'dcroat',
|
|
350
|
+
'Dmacron'=>'Dcroat',
|
|
351
|
+
'dmacron'=>'dcroat',
|
|
352
|
+
'combininggraveaccent'=>'gravecomb',
|
|
353
|
+
'combininghookabove'=>'hookabovecomb',
|
|
354
|
+
'combiningtildeaccent'=>'tildecomb',
|
|
355
|
+
'combiningacuteaccent'=>'acutecomb',
|
|
356
|
+
'combiningdotbelow'=>'dotbelowcomb',
|
|
357
|
+
'dongsign'=>'dong'
|
|
358
|
+
}
|
|
359
|
+
a.each {|l|
|
|
360
|
+
e = l.rstrip.split(' ')
|
|
361
|
+
if e.length < 2
|
|
362
|
+
next
|
|
363
|
+
end
|
|
364
|
+
code = e[0]
|
|
365
|
+
param = e[1]
|
|
366
|
+
if code == 'C'
|
|
367
|
+
# Character metrics
|
|
368
|
+
cc = e[1].to_i
|
|
369
|
+
w = e[4]
|
|
370
|
+
gn = e[7]
|
|
371
|
+
if gn[-4..-1] == '20AC'
|
|
372
|
+
gn = 'Euro'
|
|
373
|
+
end
|
|
374
|
+
if fix[gn]
|
|
375
|
+
# Fix incorrect glyph name
|
|
376
|
+
map.each_with_index {|n, c|
|
|
377
|
+
if n == fix[gn]
|
|
378
|
+
map[c] = gn
|
|
379
|
+
end
|
|
380
|
+
}
|
|
381
|
+
end
|
|
382
|
+
if map.empty?
|
|
383
|
+
# Symbolic font: use built-in encoding
|
|
384
|
+
widths[cc] = w
|
|
385
|
+
else
|
|
386
|
+
widths[gn] = w
|
|
387
|
+
if gn == 'X'
|
|
388
|
+
fm['CapXHeight'] = e[13]
|
|
389
|
+
end
|
|
390
|
+
end
|
|
391
|
+
if gn == '.notdef'
|
|
392
|
+
fm['MissingWidth'] = w
|
|
393
|
+
end
|
|
394
|
+
elsif code == 'FontName'
|
|
395
|
+
fm['FontName'] = param
|
|
396
|
+
elsif code == 'Weight'
|
|
397
|
+
fm['Weight'] = param
|
|
398
|
+
elsif code == 'ItalicAngle'
|
|
399
|
+
fm['ItalicAngle'] = param.to_f
|
|
400
|
+
elsif code == 'Ascender'
|
|
401
|
+
fm['Ascender'] = param.to_i
|
|
402
|
+
elsif code == 'Descender'
|
|
403
|
+
fm['Descender'] = param.to_i
|
|
404
|
+
elsif code == 'UnderlineThickness'
|
|
405
|
+
fm['UnderlineThickness'] = param.to_i
|
|
406
|
+
elsif code == 'UnderlinePosition'
|
|
407
|
+
fm['UnderlinePosition'] = param.to_i
|
|
408
|
+
elsif code == 'IsFixedPitch'
|
|
409
|
+
fm['IsFixedPitch'] = (param == 'true')
|
|
410
|
+
elsif code == 'FontBBox'
|
|
411
|
+
fm['FontBBox'] = [e[1], e[2], e[3], e[4]]
|
|
412
|
+
elsif code == 'CapHeight'
|
|
413
|
+
fm['CapHeight'] = param.to_i
|
|
414
|
+
elsif code == 'StdVW'
|
|
415
|
+
fm['StdVW'] = param.to_i
|
|
416
|
+
end
|
|
417
|
+
}
|
|
418
|
+
if fm['FontName'].nil?
|
|
419
|
+
abort('FontName not found')
|
|
420
|
+
end
|
|
421
|
+
if !map.empty?
|
|
422
|
+
if widths['.notdef'].nil?
|
|
423
|
+
widths['.notdef'] = 600
|
|
424
|
+
end
|
|
425
|
+
if widths['Delta'].nil? and widths['increment']
|
|
426
|
+
widths['Delta'] = widths['increment']
|
|
427
|
+
end
|
|
428
|
+
# Order widths according to map
|
|
429
|
+
256.times {|i|
|
|
430
|
+
if widths[map[i]].nil?
|
|
431
|
+
print "Warning: character " + map[i] + " is missing\n"
|
|
432
|
+
widths[i] = widths['.notdef']
|
|
433
|
+
else
|
|
434
|
+
widths[i] = widths[map[i]]
|
|
435
|
+
end
|
|
436
|
+
}
|
|
437
|
+
end
|
|
438
|
+
fm['Widths'] = widths
|
|
439
|
+
return fm, map
|
|
440
|
+
end
|
|
441
|
+
|
|
442
|
+
def MakeFontDescriptor(fm, symbolic=false)
|
|
443
|
+
# Ascent
|
|
444
|
+
asc = fm['Ascender'] ? fm['Ascender'] : 1000
|
|
445
|
+
fd = "{'Ascent'=>" + asc.to_s
|
|
446
|
+
# Descent
|
|
447
|
+
desc = fm['Descender'] ? fm['Descender'] : -200
|
|
448
|
+
fd << ",'Descent'=>" + desc.to_s
|
|
449
|
+
# CapHeight
|
|
450
|
+
if fm['CapHeight']
|
|
451
|
+
ch = fm['CapHeight']
|
|
452
|
+
elsif fm['CapXHeight']
|
|
453
|
+
ch = fm['CapXHeight']
|
|
454
|
+
else
|
|
455
|
+
ch = asc
|
|
456
|
+
end
|
|
457
|
+
fd << ",'CapHeight'=>" + ch.to_s
|
|
458
|
+
# Flags
|
|
459
|
+
flags = 0
|
|
460
|
+
if fm['IsFixedPitch'] and (fm['IsFixedPitch'] == true)
|
|
461
|
+
flags += 1<<0
|
|
462
|
+
end
|
|
463
|
+
if symbolic
|
|
464
|
+
flags += 1<<2
|
|
465
|
+
else
|
|
466
|
+
flags += 1<<5
|
|
467
|
+
end
|
|
468
|
+
if fm['ItalicAngle'] and (fm['ItalicAngle'] != 0)
|
|
469
|
+
flags += 1<<6
|
|
470
|
+
end
|
|
471
|
+
fd << ",'Flags'=>" + flags.to_s
|
|
472
|
+
# FontBBox
|
|
473
|
+
if fm['FontBBox']
|
|
474
|
+
fbb = fm['FontBBox']
|
|
475
|
+
else
|
|
476
|
+
fbb = [0, desc - 100, 1000, asc + 100]
|
|
477
|
+
end
|
|
478
|
+
fd << ",'FontBBox'=>'[" + fbb[0].to_s + ' ' + fbb[1].to_s + ' ' + fbb[2].to_s + ' ' + fbb[3].to_s + "]'"
|
|
479
|
+
# ItalicAngle
|
|
480
|
+
ia = fm['ItalicAngle'] ? fm['ItalicAngle'] : 0
|
|
481
|
+
fd << ",'ItalicAngle'=>" + ia.to_s
|
|
482
|
+
# StemV
|
|
483
|
+
if fm['StdVW']
|
|
484
|
+
stemv = fm['StdVW']
|
|
485
|
+
elsif fm['Weight'] and fm['Weight'] =~ /(bold|black)/i
|
|
486
|
+
stemv = 120
|
|
487
|
+
else
|
|
488
|
+
stemv = 70
|
|
489
|
+
end
|
|
490
|
+
fd << ",'StemV'=>" + stemv.to_s
|
|
491
|
+
# MissingWidth
|
|
492
|
+
if fm['MissingWidth']
|
|
493
|
+
fd << ",'MissingWidth'=>" + fm['MissingWidth'].to_s
|
|
494
|
+
end
|
|
495
|
+
fd << '}'
|
|
496
|
+
return fd
|
|
497
|
+
end
|
|
498
|
+
|
|
499
|
+
def MakeWidthArray(fm)
|
|
500
|
+
# Make character width array
|
|
501
|
+
s = '{'
|
|
502
|
+
cw = fm['Widths']
|
|
503
|
+
els = []
|
|
504
|
+
c = -1
|
|
505
|
+
cw.each{|i,w|
|
|
506
|
+
if i.is_a? Integer
|
|
507
|
+
els.push(((((c += 1) % 10) == 0) ? "\n " : '') + i.to_s + '=>' + w.to_s)
|
|
508
|
+
end
|
|
509
|
+
}
|
|
510
|
+
s << els.join(',')
|
|
511
|
+
s << '}'
|
|
512
|
+
return s
|
|
513
|
+
end
|
|
514
|
+
|
|
515
|
+
def MakeFontEncoding(map)
|
|
516
|
+
# Build differences from reference encoding
|
|
517
|
+
ref = ReadMap('cp1252')
|
|
518
|
+
s = ''
|
|
519
|
+
last = 0
|
|
520
|
+
32.upto(255) {|i|
|
|
521
|
+
if map[i] != ref[i]
|
|
522
|
+
if i != last + 1
|
|
523
|
+
s << i.to_s + ' '
|
|
524
|
+
end
|
|
525
|
+
last = i
|
|
526
|
+
s << '/' + map[i] + ' '
|
|
527
|
+
end
|
|
528
|
+
}
|
|
529
|
+
return s.rstrip
|
|
530
|
+
end
|
|
531
|
+
|
|
532
|
+
def SaveToFile(file, s, mode='b')
|
|
533
|
+
f = open(file, 'w' + mode)
|
|
534
|
+
if !f
|
|
535
|
+
abort('Can\'t write to file ' + file)
|
|
536
|
+
end
|
|
537
|
+
f.write(s)
|
|
538
|
+
f.close
|
|
539
|
+
end
|
|
540
|
+
|
|
541
|
+
def ReadShort(f)
|
|
542
|
+
a = f.read(2).unpack('n1')
|
|
543
|
+
return a[0]
|
|
544
|
+
end
|
|
545
|
+
|
|
546
|
+
def ReadLong(f)
|
|
547
|
+
a = f.read(4).unpack('N1')
|
|
548
|
+
return a[0]
|
|
549
|
+
end
|
|
550
|
+
|
|
551
|
+
def CheckTTF(file)
|
|
552
|
+
# Check if font license allows embedding
|
|
553
|
+
f = open(file, 'rb')
|
|
554
|
+
if !f
|
|
555
|
+
abort('Error: unable to open ' + file)
|
|
556
|
+
end
|
|
557
|
+
# Extract number of tables
|
|
558
|
+
f.seek(4, IO::SEEK_CUR)
|
|
559
|
+
nb = ReadShort(f)
|
|
560
|
+
f.seek(6, IO::SEEK_CUR)
|
|
561
|
+
# Seek OS/2 table
|
|
562
|
+
found = false
|
|
563
|
+
nb.times {|i|
|
|
564
|
+
if f.read(4) == 'OS/2'
|
|
565
|
+
found = true
|
|
566
|
+
break
|
|
567
|
+
end
|
|
568
|
+
f.seek(12, IO::SEEK_CUR)
|
|
569
|
+
}
|
|
570
|
+
if !found
|
|
571
|
+
f.close
|
|
572
|
+
return
|
|
573
|
+
end
|
|
574
|
+
f.seek(4, IO::SEEK_CUR)
|
|
575
|
+
offset = ReadLong(f)
|
|
576
|
+
f.seek(offset, IO::SEEK_SET)
|
|
577
|
+
# Extract fsType flags
|
|
578
|
+
f.seek(8, IO::SEEK_CUR)
|
|
579
|
+
fsType = ReadShort(f)
|
|
580
|
+
rl = (fsType & 0x02) != 0
|
|
581
|
+
pp = (fsType & 0x04) != 0
|
|
582
|
+
e = (fsType & 0x08) != 0
|
|
583
|
+
f.close
|
|
584
|
+
if rl and !pp and !e
|
|
585
|
+
print "Warning: font license does not allow embedding\n"
|
|
586
|
+
end
|
|
587
|
+
end
|
|
588
|
+
|
|
589
|
+
if RUBY_VERSION < '1.9'
|
|
590
|
+
abort("Error: Ruby 1.8.7 not supported.")
|
|
591
|
+
end
|
|
592
|
+
|
|
593
|
+
require 'zlib'
|
|
594
|
+
|
|
595
|
+
arg = ARGV.dup
|
|
596
|
+
if arg.length >= 2
|
|
597
|
+
if arg.length == 3
|
|
598
|
+
arg[3] = arg[2]
|
|
599
|
+
arg[2] = true
|
|
600
|
+
else
|
|
601
|
+
if arg[2].nil?
|
|
602
|
+
arg[2] = true
|
|
603
|
+
end
|
|
604
|
+
if arg[3].nil?
|
|
605
|
+
arg[3] = 'cp1252'
|
|
606
|
+
end
|
|
607
|
+
end
|
|
608
|
+
if arg[4].nil?
|
|
609
|
+
arg[4] = {}
|
|
610
|
+
else
|
|
611
|
+
arg[4] = eval(ARGV[4])
|
|
612
|
+
end
|
|
613
|
+
MakeFont(arg[0], arg[1], arg[2], arg[3], arg[4])
|
|
614
|
+
else
|
|
615
|
+
print "Usage: makefont.rb <ttf/otf/pfb file> <afm/ufm file> <encoding> <patch>\n"
|
|
616
|
+
end
|
|
617
|
+
|