prune 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.ja.txt +16 -0
- data/CHANGELOG.txt +16 -0
- data/MIT-LICENSE.ja.txt +24 -0
- data/MIT-LICENSE.txt +20 -0
- data/Manifest.txt +77 -0
- data/PostInstall.txt +4 -0
- data/README.ja.rdoc +39 -0
- data/README.rdoc +39 -0
- data/Rakefile +28 -0
- data/demo/english_fonts.rb +66 -0
- data/demo/japanese_encodings_euc_jp.rb +27 -0
- data/demo/japanese_encodings_shift_jis.rb +27 -0
- data/demo/japanese_fonts.rb +54 -0
- data/demo/tables.rb +52 -0
- data/demo/text_decoration.rb +55 -0
- data/lib/prune.rb +90 -0
- data/lib/prune/constants.rb +39 -0
- data/lib/prune/document.rb +101 -0
- data/lib/prune/elements/base.rb +55 -0
- data/lib/prune/elements/catalog.rb +51 -0
- data/lib/prune/elements/font.rb +38 -0
- data/lib/prune/elements/font_descriptor.rb +38 -0
- data/lib/prune/elements/info.rb +44 -0
- data/lib/prune/elements/outlines.rb +19 -0
- data/lib/prune/elements/page.rb +115 -0
- data/lib/prune/elements/pages.rb +29 -0
- data/lib/prune/elements/procedure_sets.rb +22 -0
- data/lib/prune/elements/stream.rb +34 -0
- data/lib/prune/errors.rb +73 -0
- data/lib/prune/fonts/base.rb +92 -0
- data/lib/prune/fonts/base_en.rb +38 -0
- data/lib/prune/fonts/base_ja.rb +129 -0
- data/lib/prune/fonts/en/courier.rb +37 -0
- data/lib/prune/fonts/en/helvetica.rb +168 -0
- data/lib/prune/fonts/en/symbol.rb +60 -0
- data/lib/prune/fonts/en/times_roman.rb +168 -0
- data/lib/prune/fonts/en/zapf_dingbats.rb +60 -0
- data/lib/prune/fonts/ja/ms_gothic.rb +55 -0
- data/lib/prune/fonts/ja/ms_mincho.rb +55 -0
- data/lib/prune/fonts/ja/ms_p_gothic.rb +55 -0
- data/lib/prune/fonts/ja/ms_p_mincho.rb +55 -0
- data/lib/prune/fonts/ja/ms_pr_gothic.rb +55 -0
- data/lib/prune/fonts/ja/ms_ui_gothic.rb +55 -0
- data/lib/prune/functions.rb +18 -0
- data/lib/prune/p_objects/aliases.rb +37 -0
- data/lib/prune/p_objects/base.rb +45 -0
- data/lib/prune/p_objects/p_array.rb +62 -0
- data/lib/prune/p_objects/p_dictionary.rb +83 -0
- data/lib/prune/p_objects/p_hexadecimal_string.rb +27 -0
- data/lib/prune/p_objects/p_literal_string.rb +25 -0
- data/lib/prune/p_objects/p_name.rb +45 -0
- data/lib/prune/p_objects/p_stream.rb +29 -0
- data/lib/prune/parsers/base.rb +13 -0
- data/lib/prune/parsers/document/page/table/tr_parser.rb +77 -0
- data/lib/prune/parsers/document/page/table_parser.rb +32 -0
- data/lib/prune/parsers/document/page_parser.rb +91 -0
- data/lib/prune/parsers/document/property_parser.rb +45 -0
- data/lib/prune/parsers/document_parser.rb +26 -0
- data/lib/prune/shapes/base.rb +52 -0
- data/lib/prune/shapes/line.rb +55 -0
- data/lib/prune/shapes/rectangle.rb +64 -0
- data/lib/prune/shapes/text_box.rb +223 -0
- data/prune.gemspec +37 -0
- data/script/console +10 -0
- data/script/console.cmd +1 -0
- data/script/destroy +14 -0
- data/script/destroy.cmd +1 -0
- data/script/generate +14 -0
- data/script/generate.cmd +1 -0
- data/spec/prune/p_objects/p_array_spec.rb +46 -0
- data/spec/prune/p_objects/p_dictionary_spec.rb +61 -0
- data/spec/prune/p_objects/p_stream_spec.rb +29 -0
- data/spec/prune_spec.rb +38 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +11 -0
- data/tasks/prune.rake +38 -0
- data/tasks/rspec.rake +21 -0
- metadata +181 -0
@@ -0,0 +1,38 @@
|
|
1
|
+
# -*- coding:utf-8 -*-
|
2
|
+
require "kconv"
|
3
|
+
|
4
|
+
module Prune
|
5
|
+
module Fonts
|
6
|
+
# Base class for English fonts.
|
7
|
+
class BaseEn < Base #:nodoc: all
|
8
|
+
# Initialize.
|
9
|
+
def initialize(document)
|
10
|
+
super(document)
|
11
|
+
@main_element = Font.new(
|
12
|
+
document,
|
13
|
+
pd(
|
14
|
+
pn(:Subtype) => pn(:Type1),
|
15
|
+
pn(:Encoding) => pn(:StandardEncoding)))
|
16
|
+
end
|
17
|
+
|
18
|
+
# Decode string.
|
19
|
+
def decode(string)
|
20
|
+
raise NonAsciiStringError unless
|
21
|
+
Kconv.guess(string) == Kconv::ASCII
|
22
|
+
pl(string)
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
# Set font name.
|
27
|
+
def name=(name)
|
28
|
+
@main_element.name = name
|
29
|
+
end
|
30
|
+
|
31
|
+
# Set base_font.
|
32
|
+
def base_font=(base_font)
|
33
|
+
@main_element.base_font = base_font
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
@@ -0,0 +1,129 @@
|
|
1
|
+
# -*- coding:utf-8 -*-
|
2
|
+
require "kconv"
|
3
|
+
|
4
|
+
module Prune
|
5
|
+
module Fonts
|
6
|
+
# Base class for Japanese fonts.
|
7
|
+
class BaseJa < Base #:nodoc: all
|
8
|
+
unless const_defined?(:HALF_SIZED_CHARS)
|
9
|
+
HALF_SIZED_CHARS = (
|
10
|
+
# CID:1 to 95.
|
11
|
+
%W[
|
12
|
+
! " # $ % & ' ( ) * + , - . / 0 1 2 3 4
|
13
|
+
5 6 7 8 9 : ; < = > ? @ A B C D E F G H
|
14
|
+
I J K L M N O P Q R S T U V W X Y Z \[ \\
|
15
|
+
\] ^ _ ` a b c d e f g h i j k l m n o p
|
16
|
+
q r s t u v w x y z { | } ~
|
17
|
+
] + [' ']).collect{|char| char.toutf16}
|
18
|
+
end
|
19
|
+
|
20
|
+
def initialize(document)
|
21
|
+
super(document)
|
22
|
+
# Font descriptor element.
|
23
|
+
@descriptor_element = FontDescriptor.new(
|
24
|
+
document,
|
25
|
+
pd(
|
26
|
+
pn(:Ascent) => 859,
|
27
|
+
pn(:Descent) => -140,
|
28
|
+
pn(:CapHeight) => 769,
|
29
|
+
pn(:MissingWidth) => 500,
|
30
|
+
pn(:FontBBox) => pa(0, -136, 1000, 859)))
|
31
|
+
# Font widths.
|
32
|
+
w = pa(
|
33
|
+
# Widths for fonts from CID:1 to 95 should be half sized.
|
34
|
+
1, pa(
|
35
|
+
500, 500, 500, 500, 500, 500, 500, 500, 500, 500,
|
36
|
+
500, 500, 500, 500, 500, 500, 500, 500, 500, 500,
|
37
|
+
500, 500, 500, 500, 500, 500, 500, 500, 500, 500,
|
38
|
+
500, 500, 500, 500, 500, 500, 500, 500, 500, 500,
|
39
|
+
500, 500, 500, 500, 500, 500, 500, 500, 500, 500,
|
40
|
+
500, 500, 500, 500, 500, 500, 500, 500, 500, 500,
|
41
|
+
500, 500, 500, 500, 500, 500, 500, 500, 500, 500,
|
42
|
+
500, 500, 500, 500, 500, 500, 500, 500, 500, 500,
|
43
|
+
500, 500, 500, 500, 500, 500, 500, 500, 500, 500,
|
44
|
+
500, 500, 500, 500, 500),
|
45
|
+
# Widths for fonts from CID:327 to 389 should be half sized.
|
46
|
+
327, pa(
|
47
|
+
500, 500, 500, 500, 500, 500, 500, 500, 500, 500,
|
48
|
+
500, 500, 500, 500, 500, 500, 500, 500, 500, 500,
|
49
|
+
500, 500, 500, 500, 500, 500, 500, 500, 500, 500,
|
50
|
+
500, 500, 500, 500, 500, 500, 500, 500, 500, 500,
|
51
|
+
500, 500, 500, 500, 500, 500, 500, 500, 500, 500,
|
52
|
+
500, 500, 500, 500, 500, 500, 500, 500, 500, 500,
|
53
|
+
500, 500, 500))
|
54
|
+
# Font body element.
|
55
|
+
@body_element = Font.new(
|
56
|
+
document,
|
57
|
+
pd(
|
58
|
+
pn(:Subtype) => pn(:CIDFontType0),
|
59
|
+
pn(:CIDSystemInfo) => pd(
|
60
|
+
pn(:Registry) => pl("Adobe"),
|
61
|
+
pn(:Ordering) => pl("Japan1"),
|
62
|
+
pn(:Supplement) => 2),
|
63
|
+
pn(:FontDescriptor) => @descriptor_element.reference,
|
64
|
+
# Default width.
|
65
|
+
pn(:DW) => 1000,
|
66
|
+
# Default width for vertical writing.
|
67
|
+
pn(:DW2) => pa(880, -1000),
|
68
|
+
# Widths.
|
69
|
+
pn(:W) => w))
|
70
|
+
# Main element.
|
71
|
+
@main_element = Font.new(
|
72
|
+
document,
|
73
|
+
pd(
|
74
|
+
pn(:Subtype) => pn(:Type0),
|
75
|
+
pn(:Encoding) => pn("UniJIS-UCS2-H"),
|
76
|
+
pn(:DescendantFonts) => pa(@body_element.reference)))
|
77
|
+
end
|
78
|
+
|
79
|
+
# Decode string.
|
80
|
+
def decode(string)
|
81
|
+
ph(string.toutf16.unpack("C*").collect{|c| "%02X" % c}.join)
|
82
|
+
end
|
83
|
+
|
84
|
+
# Get width of the text.
|
85
|
+
def width(string, font_size)
|
86
|
+
bytes = string.toutf16.bytes
|
87
|
+
width = 0
|
88
|
+
bytes.each_slice(2) do |char_bytes|
|
89
|
+
char = char_bytes.pack("C2")
|
90
|
+
if HALF_SIZED_CHARS.include?(char)
|
91
|
+
width += 500
|
92
|
+
else
|
93
|
+
width += 1000
|
94
|
+
end
|
95
|
+
end
|
96
|
+
width * font_size / 1000
|
97
|
+
end
|
98
|
+
|
99
|
+
private
|
100
|
+
# Set font name.
|
101
|
+
def name=(name)
|
102
|
+
@main_element.name = name
|
103
|
+
end
|
104
|
+
|
105
|
+
# Set base font.
|
106
|
+
def base_font=(base_font)
|
107
|
+
@main_element.base_font = base_font
|
108
|
+
@body_element.base_font = base_font
|
109
|
+
@descriptor_element.font_name = base_font
|
110
|
+
end
|
111
|
+
|
112
|
+
# Set italic angle.
|
113
|
+
def italic_angle=(angle)
|
114
|
+
@descriptor_element.italic_angle = angle
|
115
|
+
end
|
116
|
+
|
117
|
+
# Set flags.
|
118
|
+
def flags=(flags)
|
119
|
+
@descriptor_element.flags = flags
|
120
|
+
end
|
121
|
+
|
122
|
+
# Set stem v.
|
123
|
+
def stem_v=(stem_v)
|
124
|
+
@descriptor_element.stem_v = stem_v
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
# -*- coding:utf-8 -*-
|
2
|
+
|
3
|
+
module Prune
|
4
|
+
module Fonts
|
5
|
+
# Courier font.
|
6
|
+
class Courier < BaseEn
|
7
|
+
class << self
|
8
|
+
def key(options)
|
9
|
+
key = font_name
|
10
|
+
key << "_bold" if bold?(options)
|
11
|
+
key << "_italic" if italic?(options)
|
12
|
+
PObjects.pn(key)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(document, options = {})
|
17
|
+
super(document)
|
18
|
+
self.name = self.class.key(options)
|
19
|
+
if bold?(options) && italic?(options)
|
20
|
+
self.base_font = pn("Courier-BoldOblique")
|
21
|
+
elsif bold?(options)
|
22
|
+
self.base_font = pn("Courier-Bold")
|
23
|
+
elsif italic?(options)
|
24
|
+
self.base_font = pn("Courier-Oblique")
|
25
|
+
else
|
26
|
+
self.base_font = pn(:Courier)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
# Get width of the text.
|
31
|
+
def width(string, font_size)
|
32
|
+
string.size * 600 * font_size / 1000
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
@@ -0,0 +1,168 @@
|
|
1
|
+
# -*- coding:utf-8 -*-
|
2
|
+
|
3
|
+
module Prune
|
4
|
+
module Fonts
|
5
|
+
# Helvetica font.
|
6
|
+
class Helvetica < BaseEn
|
7
|
+
class << self
|
8
|
+
def key(options)
|
9
|
+
key = font_name
|
10
|
+
key << "_bold" if bold?(options)
|
11
|
+
key << "_italic" if italic?(options)
|
12
|
+
PObjects.pn(key)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
WIDTHS = [
|
17
|
+
278, 278, 278, 278, 278, 278, 278, 278, 278, 278,
|
18
|
+
278, 278, 278, 278, 278, 278, 278, 278, 278, 278,
|
19
|
+
278, 278, 278, 278, 278, 278, 278, 278, 278, 278,
|
20
|
+
278, 278, 278, 278, 355, 556, 556, 889, 667, 191,
|
21
|
+
333, 333, 389, 584, 278, 333, 278, 278, 556, 556,
|
22
|
+
556, 556, 556, 556, 556, 556, 556, 556, 278, 278,
|
23
|
+
584, 584, 584, 556, 1015, 667, 667, 722, 722, 667,
|
24
|
+
611, 778, 722, 278, 500, 667, 556, 833, 722, 778,
|
25
|
+
667, 778, 722, 667, 611, 722, 667, 944, 667, 667,
|
26
|
+
611, 278, 278, 278, 469, 556, 333, 556, 556, 500,
|
27
|
+
556, 556, 278, 556, 556, 222, 222, 500, 222, 833,
|
28
|
+
556, 556, 556, 556, 333, 500, 278, 556, 500, 722,
|
29
|
+
500, 500, 500, 334, 260, 334, 584, 350, 556, 350,
|
30
|
+
222, 556, 333, 1000, 556, 556, 333, 1000, 667, 333,
|
31
|
+
1000, 350, 611, 350, 350, 222, 222, 333, 333, 350,
|
32
|
+
556, 1000, 333, 1000, 500, 333, 944, 350, 500, 667,
|
33
|
+
278, 333, 556, 556, 556, 556, 260, 556, 333, 737,
|
34
|
+
370, 556, 584, 333, 737, 333, 400, 584, 333, 333,
|
35
|
+
333, 556, 537, 278, 333, 333, 365, 556, 834, 834,
|
36
|
+
834, 611, 667, 667, 667, 667, 667, 667, 1000, 722,
|
37
|
+
667, 667, 667, 667, 278, 278, 278, 278, 722, 722,
|
38
|
+
778, 778, 778, 778, 778, 584, 778, 722, 722, 722,
|
39
|
+
722, 667, 667, 611, 556, 556, 556, 556, 556, 556,
|
40
|
+
889, 500, 556, 556, 556, 556, 278, 278, 278, 278,
|
41
|
+
556, 556, 556, 556, 556, 556, 556, 584, 611, 556,
|
42
|
+
556, 556, 556, 500, 556, 500
|
43
|
+
] unless const_defined?(:WIDTHS)
|
44
|
+
|
45
|
+
BOLD_WIDTHS = [
|
46
|
+
278, 278, 278, 278, 278, 278, 278, 278, 278, 278,
|
47
|
+
278, 278, 278, 278, 278, 278, 278, 278, 278, 278,
|
48
|
+
278, 278, 278, 278, 278, 278, 278, 278, 278, 278,
|
49
|
+
278, 278, 278, 333, 474, 556, 556, 889, 722, 238,
|
50
|
+
333, 333, 389, 584, 278, 333, 278, 278, 556, 556,
|
51
|
+
556, 556, 556, 556, 556, 556, 556, 556, 333, 333,
|
52
|
+
584, 584, 584, 611, 975, 722, 722, 722, 722, 667,
|
53
|
+
611, 778, 722, 278, 556, 722, 611, 833, 722, 778,
|
54
|
+
667, 778, 722, 667, 611, 722, 667, 944, 667, 667,
|
55
|
+
611, 333, 278, 333, 584, 556, 333, 556, 611, 556,
|
56
|
+
611, 556, 333, 611, 611, 278, 278, 556, 278, 889,
|
57
|
+
611, 611, 611, 611, 389, 556, 333, 611, 556, 778,
|
58
|
+
556, 556, 500, 389, 280, 389, 584, 350, 556, 350,
|
59
|
+
278, 556, 500, 1000, 556, 556, 333, 1000, 667, 333,
|
60
|
+
1000, 350, 611, 350, 350, 278, 278, 500, 500, 350,
|
61
|
+
556, 1000, 333, 1000, 556, 333, 944, 350, 500, 667,
|
62
|
+
278, 333, 556, 556, 556, 556, 280, 556, 333, 737,
|
63
|
+
370, 556, 584, 333, 737, 333, 400, 584, 333, 333,
|
64
|
+
333, 611, 556, 278, 333, 333, 365, 556, 834, 834,
|
65
|
+
834, 611, 722, 722, 722, 722, 722, 722, 1000, 722,
|
66
|
+
667, 667, 667, 667, 278, 278, 278, 278, 722, 722,
|
67
|
+
778, 778, 778, 778, 778, 584, 778, 722, 722, 722,
|
68
|
+
722, 667, 667, 611, 556, 556, 556, 556, 556, 556,
|
69
|
+
889, 556, 556, 556, 556, 556, 278, 278, 278, 278,
|
70
|
+
611, 611, 611, 611, 611, 611, 611, 584, 611, 611,
|
71
|
+
611, 611, 611, 556, 611, 556
|
72
|
+
] unless const_defined?(:BOLD_WIDTHS)
|
73
|
+
|
74
|
+
ITALIC_WIDTHS = [
|
75
|
+
278, 278, 278, 278, 278, 278, 278, 278, 278, 278,
|
76
|
+
278, 278, 278, 278, 278, 278, 278, 278, 278, 278,
|
77
|
+
278, 278, 278, 278, 278, 278, 278, 278, 278, 278,
|
78
|
+
278, 278, 278, 278, 355, 556, 556, 889, 667, 191,
|
79
|
+
333, 333, 389, 584, 278, 333, 278, 278, 556, 556,
|
80
|
+
556, 556, 556, 556, 556, 556, 556, 556, 278, 278,
|
81
|
+
584, 584, 584, 556, 1015, 667, 667, 722, 722, 667,
|
82
|
+
611, 778, 722, 278, 500, 667, 556, 833, 722, 778,
|
83
|
+
667, 778, 722, 667, 611, 722, 667, 944, 667, 667,
|
84
|
+
611, 278, 278, 278, 469, 556, 333, 556, 556, 500,
|
85
|
+
556, 556, 278, 556, 556, 222, 222, 500, 222, 833,
|
86
|
+
556, 556, 556, 556, 333, 500, 278, 556, 500, 722,
|
87
|
+
500, 500, 500, 334, 260, 334, 584, 350, 556, 350,
|
88
|
+
222, 556, 333, 1000, 556, 556, 333, 1000, 667, 333,
|
89
|
+
1000, 350, 611, 350, 350, 222, 222, 333, 333, 350,
|
90
|
+
556, 1000, 333, 1000, 500, 333, 944, 350, 500, 667,
|
91
|
+
278, 333, 556, 556, 556, 556, 260, 556, 333, 737,
|
92
|
+
370, 556, 584, 333, 737, 333, 400, 584, 333, 333,
|
93
|
+
333, 556, 537, 278, 333, 333, 365, 556, 834, 834,
|
94
|
+
834, 611, 667, 667, 667, 667, 667, 667, 1000, 722,
|
95
|
+
667, 667, 667, 667, 278, 278, 278, 278, 722, 722,
|
96
|
+
778, 778, 778, 778, 778, 584, 778, 722, 722, 722,
|
97
|
+
722, 667, 667, 611, 556, 556, 556, 556, 556, 556,
|
98
|
+
889, 500, 556, 556, 556, 556, 278, 278, 278, 278,
|
99
|
+
556, 556, 556, 556, 556, 556, 556, 584, 611, 556,
|
100
|
+
556, 556, 556, 500, 556, 500
|
101
|
+
] unless const_defined?(:ITALIC_WIDTHS)
|
102
|
+
|
103
|
+
BOLD_ITALIC_WIDTHS = [
|
104
|
+
278, 278, 278, 278, 278, 278, 278, 278, 278, 278,
|
105
|
+
278, 278, 278, 278, 278, 278, 278, 278, 278, 278,
|
106
|
+
278, 278, 278, 278, 278, 278, 278, 278, 278, 278,
|
107
|
+
278, 278, 278, 333, 474, 556, 556, 889, 722, 238,
|
108
|
+
333, 333, 389, 584, 278, 333, 278, 278, 556, 556,
|
109
|
+
556, 556, 556, 556, 556, 556, 556, 556, 333, 333,
|
110
|
+
584, 584, 584, 611, 975, 722, 722, 722, 722, 667,
|
111
|
+
611, 778, 722, 278, 556, 722, 611, 833, 722, 778,
|
112
|
+
667, 778, 722, 667, 611, 722, 667, 944, 667, 667,
|
113
|
+
611, 333, 278, 333, 584, 556, 333, 556, 611, 556,
|
114
|
+
611, 556, 333, 611, 611, 278, 278, 556, 278, 889,
|
115
|
+
611, 611, 611, 611, 389, 556, 333, 611, 556, 778,
|
116
|
+
556, 556, 500, 389, 280, 389, 584, 350, 556, 350,
|
117
|
+
278, 556, 500, 1000, 556, 556, 333, 1000, 667, 333,
|
118
|
+
1000, 350, 611, 350, 350, 278, 278, 500, 500, 350,
|
119
|
+
556, 1000, 333, 1000, 556, 333, 944, 350, 500, 667,
|
120
|
+
278, 333, 556, 556, 556, 556, 280, 556, 333, 737,
|
121
|
+
370, 556, 584, 333, 737, 333, 400, 584, 333, 333,
|
122
|
+
333, 611, 556, 278, 333, 333, 365, 556, 834, 834,
|
123
|
+
834, 611, 722, 722, 722, 722, 722, 722, 1000, 722,
|
124
|
+
667, 667, 667, 667, 278, 278, 278, 278, 722, 722,
|
125
|
+
778, 778, 778, 778, 778, 584, 778, 722, 722, 722,
|
126
|
+
722, 667, 667, 611, 556, 556, 556, 556, 556, 556,
|
127
|
+
889, 556, 556, 556, 556, 556, 278, 278, 278, 278,
|
128
|
+
611, 611, 611, 611, 611, 611, 611, 584, 611, 611,
|
129
|
+
611, 611, 611, 556, 611, 556
|
130
|
+
] unless const_defined?(:BOLD_ITALIC_WIDTHS)
|
131
|
+
|
132
|
+
def initialize(document, options = {})
|
133
|
+
super(document)
|
134
|
+
@font_name = :helvetica
|
135
|
+
self.name = self.class.key(options)
|
136
|
+
@bold = bold?(options)
|
137
|
+
@italic = italic?(options)
|
138
|
+
if @bold && @italic
|
139
|
+
self.base_font = pn("Helvetica-BoldOblique")
|
140
|
+
elsif @bold
|
141
|
+
self.base_font = pn("Helvetica-Bold")
|
142
|
+
elsif @italic
|
143
|
+
self.base_font = pn("Helvetica-Oblique")
|
144
|
+
else
|
145
|
+
self.base_font = pn(:Helvetica)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
# Get width of the text.
|
150
|
+
def width(string, font_size)
|
151
|
+
string_base_width = string.bytes.inject(0){|result, byte|
|
152
|
+
if @bold && @italic
|
153
|
+
byte_width = BOLD_ITALIC_WIDTHS[byte] || 1000
|
154
|
+
elsif @bold
|
155
|
+
byte_width = BOLD_WIDTHS[byte] || 1000
|
156
|
+
elsif @italic
|
157
|
+
byte_width = ITALIC_WIDTHS[byte] || 1000
|
158
|
+
else
|
159
|
+
byte_width = WIDTHS[byte] || 1000
|
160
|
+
end
|
161
|
+
result + byte_width
|
162
|
+
}
|
163
|
+
string_base_width * font_size / 1000
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
@@ -0,0 +1,60 @@
|
|
1
|
+
# -*- coding:utf-8 -*-
|
2
|
+
|
3
|
+
module Prune
|
4
|
+
module Fonts
|
5
|
+
# Symbol font.
|
6
|
+
class Symbol < BaseEn
|
7
|
+
class << self
|
8
|
+
def key(options)
|
9
|
+
FontOptionError if bold?(options) || italic?(options)
|
10
|
+
PObjects.pn(font_name)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
WIDTHS = [
|
15
|
+
250, 250, 250, 250, 250, 250, 250, 250, 250, 250,
|
16
|
+
250, 250, 250, 250, 250, 250, 250, 250, 250, 250,
|
17
|
+
250, 250, 250, 250, 250, 250, 250, 250, 250, 250,
|
18
|
+
250, 250, 250, 333, 713, 500, 549, 833, 778, 439,
|
19
|
+
333, 333, 500, 549, 250, 549, 250, 278, 500, 500,
|
20
|
+
500, 500, 500, 500, 500, 500, 500, 500, 278, 278,
|
21
|
+
549, 549, 549, 444, 549, 722, 667, 722, 612, 611,
|
22
|
+
763, 603, 722, 333, 631, 722, 686, 889, 722, 722,
|
23
|
+
768, 741, 556, 592, 611, 690, 439, 768, 645, 795,
|
24
|
+
611, 333, 863, 333, 658, 500, 500, 631, 549, 549,
|
25
|
+
494, 439, 521, 411, 603, 329, 603, 549, 549, 576,
|
26
|
+
521, 549, 549, 521, 549, 603, 439, 576, 713, 686,
|
27
|
+
493, 686, 494, 480, 200, 480, 549, 0, 0, 0,
|
28
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
29
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
30
|
+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
31
|
+
750, 620, 247, 549, 167, 713, 500, 753, 753, 753,
|
32
|
+
753, 1042, 987, 603, 987, 603, 400, 549, 411, 549,
|
33
|
+
549, 713, 494, 460, 549, 549, 549, 549, 1000, 603,
|
34
|
+
1000, 658, 823, 686, 795, 987, 768, 768, 823, 768,
|
35
|
+
768, 713, 713, 713, 713, 713, 713, 713, 768, 713,
|
36
|
+
790, 790, 890, 823, 549, 250, 713, 603, 603, 1042,
|
37
|
+
987, 603, 987, 603, 494, 329, 790, 790, 786, 713,
|
38
|
+
384, 384, 384, 384, 384, 384, 494, 494, 494, 494,
|
39
|
+
0, 329, 274, 686, 686, 686, 384, 384, 384, 384,
|
40
|
+
384, 384, 494, 494, 494, 0
|
41
|
+
] unless const_defined?(:WIDTHS)
|
42
|
+
|
43
|
+
def initialize(document, options = {})
|
44
|
+
super(document)
|
45
|
+
self.name = self.class.key(options)
|
46
|
+
self.base_font = pn(:Symbol)
|
47
|
+
end
|
48
|
+
|
49
|
+
# Get width of the text.
|
50
|
+
def width(string, font_size)
|
51
|
+
string_base_width = string.bytes.inject(0){|result, byte|
|
52
|
+
byte_width = WIDTHS[byte] || 1000
|
53
|
+
result + byte_width
|
54
|
+
}
|
55
|
+
string_base_width * font_size / 1000
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
@@ -0,0 +1,168 @@
|
|
1
|
+
# -*- coding:utf-8 -*-
|
2
|
+
|
3
|
+
module Prune
|
4
|
+
module Fonts
|
5
|
+
# Times Roman font.
|
6
|
+
class TimesRoman < BaseEn
|
7
|
+
class << self
|
8
|
+
def key(options)
|
9
|
+
key = font_name
|
10
|
+
key << "_bold" if bold?(options)
|
11
|
+
key << "_italic" if italic?(options)
|
12
|
+
PObjects.pn(key)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
WIDTHS = [
|
17
|
+
250, 250, 250, 250, 250, 250, 250, 250, 250, 250,
|
18
|
+
250, 250, 250, 250, 250, 250, 250, 250, 250, 250,
|
19
|
+
250, 250, 250, 250, 250, 250, 250, 250, 250, 250,
|
20
|
+
250, 250, 250, 333, 408, 500, 500, 833, 778, 180,
|
21
|
+
333, 333, 500, 564, 250, 333, 250, 278, 500, 500,
|
22
|
+
500, 500, 500, 500, 500, 500, 500, 500, 278, 278,
|
23
|
+
564, 564, 564, 444, 921, 722, 667, 667, 722, 611,
|
24
|
+
556, 722, 722, 333, 389, 722, 611, 889, 722, 722,
|
25
|
+
556, 722, 667, 556, 611, 722, 722, 944, 722, 722,
|
26
|
+
611, 333, 278, 333, 469, 500, 333, 444, 500, 444,
|
27
|
+
500, 444, 333, 500, 500, 278, 278, 500, 278, 778,
|
28
|
+
500, 500, 500, 500, 333, 389, 278, 500, 500, 722,
|
29
|
+
500, 500, 444, 480, 200, 480, 541, 350, 500, 350,
|
30
|
+
333, 500, 444, 1000, 500, 500, 333, 1000, 556, 333,
|
31
|
+
889, 350, 611, 350, 350, 333, 333, 444, 444, 350,
|
32
|
+
500, 1000, 333, 980, 389, 333, 722, 350, 444, 722,
|
33
|
+
250, 333, 500, 500, 500, 500, 200, 500, 333, 760,
|
34
|
+
276, 500, 564, 333, 760, 333, 400, 564, 300, 300,
|
35
|
+
333, 500, 453, 250, 333, 300, 310, 500, 750, 750,
|
36
|
+
750, 444, 722, 722, 722, 722, 722, 722, 889, 667,
|
37
|
+
611, 611, 611, 611, 333, 333, 333, 333, 722, 722,
|
38
|
+
722, 722, 722, 722, 722, 564, 722, 722, 722, 722,
|
39
|
+
722, 722, 556, 500, 444, 444, 444, 444, 444, 444,
|
40
|
+
667, 444, 444, 444, 444, 444, 278, 278, 278, 278,
|
41
|
+
500, 500, 500, 500, 500, 500, 500, 564, 500, 500,
|
42
|
+
500, 500, 500, 500, 500, 500
|
43
|
+
] unless const_defined?(:WIDTH)
|
44
|
+
|
45
|
+
BOLD_WIDTHS = [
|
46
|
+
250, 250, 250, 250, 250, 250, 250, 250, 250, 250,
|
47
|
+
250, 250, 250, 250, 250, 250, 250, 250, 250, 250,
|
48
|
+
250, 250, 250, 250, 250, 250, 250, 250, 250, 250,
|
49
|
+
250, 250, 250, 333, 555, 500, 500, 1000, 833, 278,
|
50
|
+
333, 333, 500, 570, 250, 333, 250, 278, 500, 500,
|
51
|
+
500, 500, 500, 500, 500, 500, 500, 500, 333, 333,
|
52
|
+
570, 570, 570, 500, 930, 722, 667, 722, 722, 667,
|
53
|
+
611, 778, 778, 389, 500, 778, 667, 944, 722, 778,
|
54
|
+
611, 778, 722, 556, 667, 722, 722, 1000, 722, 722,
|
55
|
+
667, 333, 278, 333, 581, 500, 333, 500, 556, 444,
|
56
|
+
556, 444, 333, 500, 556, 278, 333, 556, 278, 833,
|
57
|
+
556, 500, 556, 556, 444, 389, 333, 556, 500, 722,
|
58
|
+
500, 500, 444, 394, 220, 394, 520, 350, 500, 350,
|
59
|
+
333, 500, 500, 1000, 500, 500, 333, 1000, 556, 333,
|
60
|
+
1000, 350, 667, 350, 350, 333, 333, 500, 500, 350,
|
61
|
+
500, 1000, 333, 1000, 389, 333, 722, 350, 444, 722,
|
62
|
+
250, 333, 500, 500, 500, 500, 220, 500, 333, 747,
|
63
|
+
300, 500, 570, 333, 747, 333, 400, 570, 300, 300,
|
64
|
+
333, 556, 540, 250, 333, 300, 330, 500, 750, 750,
|
65
|
+
750, 500, 722, 722, 722, 722, 722, 722, 1000, 722,
|
66
|
+
667, 667, 667, 667, 389, 389, 389, 389, 722, 722,
|
67
|
+
778, 778, 778, 778, 778, 570, 778, 722, 722, 722,
|
68
|
+
722, 722, 611, 556, 500, 500, 500, 500, 500, 500,
|
69
|
+
722, 444, 444, 444, 444, 444, 278, 278, 278, 278,
|
70
|
+
500, 556, 500, 500, 500, 500, 500, 570, 500, 556,
|
71
|
+
556, 556, 556, 500, 556, 500
|
72
|
+
] unless const_defined?(:BOLD_WIDTHS)
|
73
|
+
|
74
|
+
ITALIC_WIDTHS = [
|
75
|
+
250, 250, 250, 250, 250, 250, 250, 250, 250, 250,
|
76
|
+
250, 250, 250, 250, 250, 250, 250, 250, 250, 250,
|
77
|
+
250, 250, 250, 250, 250, 250, 250, 250, 250, 250,
|
78
|
+
250, 250, 250, 333, 420, 500, 500, 833, 778, 214,
|
79
|
+
333, 333, 500, 675, 250, 333, 250, 278, 500, 500,
|
80
|
+
500, 500, 500, 500, 500, 500, 500, 500, 333, 333,
|
81
|
+
675, 675, 675, 500, 920, 611, 611, 667, 722, 611,
|
82
|
+
611, 722, 722, 333, 444, 667, 556, 833, 667, 722,
|
83
|
+
611, 722, 611, 500, 556, 722, 611, 833, 611, 556,
|
84
|
+
556, 389, 278, 389, 422, 500, 333, 500, 500, 444,
|
85
|
+
500, 444, 278, 500, 500, 278, 278, 444, 278, 722,
|
86
|
+
500, 500, 500, 500, 389, 389, 278, 500, 444, 667,
|
87
|
+
444, 444, 389, 400, 275, 400, 541, 350, 500, 350,
|
88
|
+
333, 500, 556, 889, 500, 500, 333, 1000, 500, 333,
|
89
|
+
944, 350, 556, 350, 350, 333, 333, 556, 556, 350,
|
90
|
+
500, 889, 333, 980, 389, 333, 667, 350, 389, 556,
|
91
|
+
250, 389, 500, 500, 500, 500, 275, 500, 333, 760,
|
92
|
+
276, 500, 675, 333, 760, 333, 400, 675, 300, 300,
|
93
|
+
333, 500, 523, 250, 333, 300, 310, 500, 750, 750,
|
94
|
+
750, 500, 611, 611, 611, 611, 611, 611, 889, 667,
|
95
|
+
611, 611, 611, 611, 333, 333, 333, 333, 722, 667,
|
96
|
+
722, 722, 722, 722, 722, 675, 722, 722, 722, 722,
|
97
|
+
722, 556, 611, 500, 500, 500, 500, 500, 500, 500,
|
98
|
+
667, 444, 444, 444, 444, 444, 278, 278, 278, 278,
|
99
|
+
500, 500, 500, 500, 500, 500, 500, 675, 500, 500,
|
100
|
+
500, 500, 500, 444, 500, 444
|
101
|
+
] unless const_defined?(:ITALIC_WIDTHS)
|
102
|
+
|
103
|
+
BOLD_ITALIC_WIDTHS = [
|
104
|
+
250, 250, 250, 250, 250, 250, 250, 250, 250, 250,
|
105
|
+
250, 250, 250, 250, 250, 250, 250, 250, 250, 250,
|
106
|
+
250, 250, 250, 250, 250, 250, 250, 250, 250, 250,
|
107
|
+
250, 250, 250, 389, 555, 500, 500, 833, 778, 278,
|
108
|
+
333, 333, 500, 570, 250, 333, 250, 278, 500, 500,
|
109
|
+
500, 500, 500, 500, 500, 500, 500, 500, 333, 333,
|
110
|
+
570, 570, 570, 500, 832, 667, 667, 667, 722, 667,
|
111
|
+
667, 722, 778, 389, 500, 667, 611, 889, 722, 722,
|
112
|
+
611, 722, 667, 556, 611, 722, 667, 889, 667, 611,
|
113
|
+
611, 333, 278, 333, 570, 500, 333, 500, 500, 444,
|
114
|
+
500, 444, 333, 500, 556, 278, 278, 500, 278, 778,
|
115
|
+
556, 500, 500, 500, 389, 389, 278, 556, 444, 667,
|
116
|
+
500, 444, 389, 348, 220, 348, 570, 350, 500, 350,
|
117
|
+
333, 500, 500, 1000, 500, 500, 333, 1000, 556, 333,
|
118
|
+
944, 350, 611, 350, 350, 333, 333, 500, 500, 350,
|
119
|
+
500, 1000, 333, 1000, 389, 333, 722, 350, 389, 611,
|
120
|
+
250, 389, 500, 500, 500, 500, 220, 500, 333, 747,
|
121
|
+
266, 500, 606, 333, 747, 333, 400, 570, 300, 300,
|
122
|
+
333, 576, 500, 250, 333, 300, 300, 500, 750, 750,
|
123
|
+
750, 500, 667, 667, 667, 667, 667, 667, 944, 667,
|
124
|
+
667, 667, 667, 667, 389, 389, 389, 389, 722, 722,
|
125
|
+
722, 722, 722, 722, 722, 570, 722, 722, 722, 722,
|
126
|
+
722, 611, 611, 500, 500, 500, 500, 500, 500, 500,
|
127
|
+
722, 444, 444, 444, 444, 444, 278, 278, 278, 278,
|
128
|
+
500, 556, 500, 500, 500, 500, 500, 570, 500, 556,
|
129
|
+
556, 556, 556, 444, 500, 444
|
130
|
+
] unless const_defined?(:BOLD_ITALIC_WIDTHS)
|
131
|
+
|
132
|
+
def initialize(document, options = {})
|
133
|
+
super(document)
|
134
|
+
@font_name = :times_roman
|
135
|
+
self.name = self.class.key(options)
|
136
|
+
@bold = bold?(options)
|
137
|
+
@italic = italic?(options)
|
138
|
+
if @bold && @italic
|
139
|
+
self.base_font = pn("Times-BoldItalic")
|
140
|
+
elsif @bold
|
141
|
+
self.base_font = pn("Times-Bold")
|
142
|
+
elsif @italic
|
143
|
+
self.base_font = pn("Times-Italic")
|
144
|
+
else
|
145
|
+
self.base_font = pn("Times-Roman")
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
# Get width of the text.
|
150
|
+
def width(string, font_size)
|
151
|
+
string_base_width = string.bytes.inject(0){|result, byte|
|
152
|
+
if @bold && @italic
|
153
|
+
byte_width = BOLD_ITALIC_WIDTHS[byte] || 1000
|
154
|
+
elsif @bold
|
155
|
+
byte_width = BOLD_WIDTHS[byte] || 1000
|
156
|
+
elsif @italic
|
157
|
+
byte_width = ITALIC_WIDTHS[byte] || 1000
|
158
|
+
else
|
159
|
+
byte_width = WIDTHS[byte] || 1000
|
160
|
+
end
|
161
|
+
result + byte_width
|
162
|
+
}
|
163
|
+
string_base_width * font_size / 1000
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|