pdbook 0.1.8 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/pdbook.rb +1 -1
- data/lib/pdbook/converter.rb +9 -5
- metadata +1 -1
data/lib/pdbook.rb
CHANGED
data/lib/pdbook/converter.rb
CHANGED
@@ -9,7 +9,7 @@ require "prawn/measurement_extensions"
|
|
9
9
|
|
10
10
|
module Pdbook
|
11
11
|
class Converter
|
12
|
-
def initialize(input, output, font = "#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf", options = {:page_size => "A4", :margin => 0.6.in, :font_size => 20, :spacing => 10, :compress => true})
|
12
|
+
def initialize(input, output, font = "#{Prawn::BASEDIR}/data/fonts/gkai00mp.ttf", options = {:page_size => "A4", :margin => 0.6.in, :font_size => 20, :spacing => 10, :compress => true, :encoding => "BIG5-HKSCS"})
|
13
13
|
@input = input
|
14
14
|
@output = output
|
15
15
|
@font = font
|
@@ -18,7 +18,7 @@ module Pdbook
|
|
18
18
|
@options[:margin] = (ENV["margin"].to_f * 1.in) if ENV["margin"]
|
19
19
|
@options[:font_size] = ENV["font_size"].to_f if ENV["font_size"]
|
20
20
|
@options[:spacing] = ENV["spacing"].to_f if ENV["spacing"]
|
21
|
-
|
21
|
+
@options[:encoding] = ENV["encoding"].to_f if ENV["encoding"]
|
22
22
|
@pdb = Palm::PDB.new(input)
|
23
23
|
@log = Logger.new($STDOUT)
|
24
24
|
end
|
@@ -44,10 +44,12 @@ module Pdbook
|
|
44
44
|
protected
|
45
45
|
# find current document charset
|
46
46
|
def charset
|
47
|
+
return @options[:encoding] if @options[:encoding]
|
48
|
+
|
47
49
|
text_check = @pdb.data.first.data.gsub("\e", "")
|
48
|
-
|
50
|
+
return UniversalDetector::chardet(text_check)["encoding"]
|
49
51
|
end
|
50
|
-
|
52
|
+
|
51
53
|
private
|
52
54
|
# First \e\e\e is marker for first page
|
53
55
|
# Subsequent \e is link
|
@@ -107,6 +109,7 @@ module Pdbook
|
|
107
109
|
text.gsub!('︽', '《')
|
108
110
|
text.gsub!('︾', '》')
|
109
111
|
text.gsub!('|', '—')
|
112
|
+
text.gsub!('│', '—')
|
110
113
|
text.gsub!('︵', '(')
|
111
114
|
text.gsub!('︶', ')')
|
112
115
|
text.gsub!('﹃', '『')
|
@@ -114,7 +117,8 @@ module Pdbook
|
|
114
117
|
text.gsub!('︹', '〔')
|
115
118
|
text.gsub!('︺', '〕')
|
116
119
|
text.gsub!('︻', '【')
|
117
|
-
text.gsub!('︼', '】')
|
120
|
+
text.gsub!('︼', '】')
|
121
|
+
text.gsub!('恒', '')
|
118
122
|
text
|
119
123
|
end
|
120
124
|
|