krill 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/krill/afm.rb +1 -1
- data/lib/krill/formatter.rb +21 -9
- data/lib/krill/line.rb +14 -0
- data/lib/krill/line_wrap.rb +1 -2
- data/lib/krill/text_box.rb +4 -3
- data/lib/krill/version.rb +1 -1
- data/lib/krill/wrapped_text.rb +5 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd3f51a4af9789839d2855c32fa16ec028774135
|
4
|
+
data.tar.gz: ae4d0f52fd062ba40368f6be9ed68daa34278d09
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 19d495ab9f258a1f1b830a8634af24f6edcb0c77dbdd032bcc6551d2943ef1689e5ca51f0407e5972de2f751c96f6dd438fa41de7d9d2bc0d0667dc7d9c6b7cf
|
7
|
+
data.tar.gz: 83294c710da5637b8ed8dd28520383d11d6249dc0134b4fcad325e56214a2b73aabba62da833a69fbfa3958ce9b00eb163af4dab2c9ebd3bedf0fbcde9e0387f
|
data/lib/krill/afm.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Krill
|
2
2
|
AFM = Struct.new(:filename) do
|
3
|
-
attr_reader :name, :family, :ascender, :descender, :line_gap
|
3
|
+
attr_reader :name, :family, :ascender, :descender, :line_gap, :character_widths, :kernings
|
4
4
|
|
5
5
|
def self.open(filename)
|
6
6
|
new filename
|
data/lib/krill/formatter.rb
CHANGED
@@ -22,18 +22,16 @@ module Krill
|
|
22
22
|
# NOTE: +string+ must be UTF8-encoded.
|
23
23
|
def compute_width_of(string, kerning: true)
|
24
24
|
if kerning
|
25
|
-
kern(string).inject(0) do |
|
25
|
+
kern(string).inject(0.0) do |width, r|
|
26
26
|
if r.is_a?(Numeric)
|
27
|
-
|
27
|
+
width - r
|
28
28
|
else
|
29
|
-
r.inject(
|
29
|
+
r.inject(width) { |width2, char| width2 + width_of_char(char) }
|
30
30
|
end
|
31
|
-
end
|
31
|
+
end
|
32
32
|
else
|
33
|
-
string.chars.inject(0)
|
34
|
-
|
35
|
-
end * size
|
36
|
-
end
|
33
|
+
string.chars.inject(0.0) { |width, char| width + width_of_char(char) }
|
34
|
+
end * size
|
37
35
|
end
|
38
36
|
|
39
37
|
|
@@ -74,6 +72,7 @@ module Krill
|
|
74
72
|
|
75
73
|
private
|
76
74
|
|
75
|
+
|
77
76
|
def normalized_height
|
78
77
|
@normalized_height ||= font.ascender - font.descender + font.line_gap
|
79
78
|
end
|
@@ -94,7 +93,7 @@ module Krill
|
|
94
93
|
string.each_char do |char|
|
95
94
|
if a.empty?
|
96
95
|
a << [char]
|
97
|
-
elsif (kern =
|
96
|
+
elsif (kern = kerning_for_chars(a.last.last, char))
|
98
97
|
a << -kern << [char]
|
99
98
|
else
|
100
99
|
a.last << char
|
@@ -104,5 +103,18 @@ module Krill
|
|
104
103
|
a
|
105
104
|
end
|
106
105
|
|
106
|
+
|
107
|
+
protected
|
108
|
+
|
109
|
+
|
110
|
+
def width_of_char(char)
|
111
|
+
font.character_widths.fetch(char, 0.0)
|
112
|
+
end
|
113
|
+
|
114
|
+
def kerning_for_chars(char0, char1)
|
115
|
+
font.kernings["#{char0}#{char1}"]
|
116
|
+
end
|
117
|
+
|
118
|
+
|
107
119
|
end
|
108
120
|
end
|
data/lib/krill/line.rb
ADDED
data/lib/krill/line_wrap.rb
CHANGED
@@ -35,7 +35,6 @@ module Krill
|
|
35
35
|
while fragment = @arranger.next_string
|
36
36
|
@fragment_output = ""
|
37
37
|
|
38
|
-
fragment.lstrip! if first_fragment_on_this_line?(fragment)
|
39
38
|
next if empty_line?(fragment)
|
40
39
|
|
41
40
|
break unless apply_font_settings_and_add_fragment_to_line(fragment)
|
@@ -219,7 +218,7 @@ module Krill
|
|
219
218
|
end
|
220
219
|
|
221
220
|
def update_output_based_on_last_fragment(fragment, normalized_soft_hyphen = nil)
|
222
|
-
remaining_text = fragment.slice(@fragment_output.length..fragment.length)
|
221
|
+
remaining_text = fragment.slice(@fragment_output.length..fragment.length).lstrip
|
223
222
|
fail CannotFit if line_finished? && line_empty? && @fragment_output.empty? && !fragment.strip.empty?
|
224
223
|
@arranger.update_last_string(@fragment_output, remaining_text, normalized_soft_hyphen)
|
225
224
|
end
|
data/lib/krill/text_box.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
require "krill/line_wrap"
|
2
|
+
require "krill/line"
|
2
3
|
require "krill/arranger"
|
3
4
|
|
4
5
|
module Krill
|
5
6
|
class TextBox
|
7
|
+
attr_reader :printed_lines
|
6
8
|
|
7
9
|
def initialize(formatted_text, options={})
|
8
10
|
@original_array = formatted_text
|
@@ -189,9 +191,8 @@ module Krill
|
|
189
191
|
accumulated_width += fragment_this_line.width
|
190
192
|
end
|
191
193
|
|
192
|
-
|
193
|
-
|
194
|
-
end.join
|
194
|
+
text = printed_fragments.map { |s| s.force_encoding(::Encoding::UTF_8) }.join
|
195
|
+
@printed_lines << Krill::Line.new(text, accumulated_width)
|
195
196
|
end
|
196
197
|
|
197
198
|
def word_spacing_for_this_line
|
data/lib/krill/version.rb
CHANGED
data/lib/krill/wrapped_text.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: krill
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bob Lail
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-04-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -102,6 +102,7 @@ files:
|
|
102
102
|
- lib/krill/arranger.rb
|
103
103
|
- lib/krill/formatter.rb
|
104
104
|
- lib/krill/fragment.rb
|
105
|
+
- lib/krill/line.rb
|
105
106
|
- lib/krill/line_wrap.rb
|
106
107
|
- lib/krill/text_box.rb
|
107
108
|
- lib/krill/ttf.rb
|