softcover 1.3.2 → 1.3.3
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 +4 -4
- data/lib/softcover/builders/epub.rb +16 -13
- data/lib/softcover/version.rb +1 -1
- data/spec/builders/epub_spec.rb +19 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1795e8080e63ce874821e57234085123e4781f2b
|
4
|
+
data.tar.gz: 6afb948de742c1c8533e4aaa1e7b0ffd86fcdb6c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5b400bfba389dc46e7732d0ce0c50f4b3229bb0eb2d01bb95d2697b1bf1ac090bdd4db5bec4128364698629f559bee1a5a469b75dcde2c3cc500f7884253ef38
|
7
|
+
data.tar.gz: bb1aaaa43181f8f3a8a59cb2979cb4ac968b3323b6189cf235380a078bb9bb7bd8f2f95c3ca1356af69809d4922f03f1fe68aa695ead954e13d6374b9f2e6fb1
|
@@ -311,6 +311,14 @@ module Softcover
|
|
311
311
|
# Save the SVG file.
|
312
312
|
svg['viewBox'] = svg['viewbox']
|
313
313
|
svg.remove_attribute('viewbox')
|
314
|
+
# Workaround for bug in Inkscape 0.91 on MacOS X:
|
315
|
+
# extract height/width from svg attributes and move them to style attr
|
316
|
+
svg_height = svg['height'] # in ex
|
317
|
+
svg_width = svg['width'] # in ex
|
318
|
+
svg['style'] += ' height:'+svg_height+';' + ' width:'+svg_width+';'
|
319
|
+
svg.remove_attribute('height')
|
320
|
+
svg.remove_attribute('width')
|
321
|
+
# /Workaround
|
314
322
|
first_child = frame.children.first
|
315
323
|
first_child.replace(svg) unless svg == first_child
|
316
324
|
output = svg.to_xhtml
|
@@ -322,25 +330,20 @@ module Softcover
|
|
322
330
|
png_abspath = svg_abspath.sub('.svg', '.png')
|
323
331
|
pngs << png_filename
|
324
332
|
#
|
325
|
-
# Settings for
|
333
|
+
# Settings for texmath images in ePub / mobi
|
326
334
|
ex2em_height_scaling = 0.51 # =1ex/1em for math png height
|
327
335
|
ex2em_valign_scaling = 0.481482 # =1ex/1em for math png vertical-align
|
328
336
|
ex2pt_scale_factor = 15 # =1ex/1pt scaling for SVG-->PNG conv.
|
329
|
-
# These are used a three-step process below:
|
330
|
-
# STEP1:
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
png_height = (svg_height_in_ex * ex2em_height_scaling).to_s + 'em'
|
336
|
-
end
|
337
|
-
# Extract vertical-align css proprty for for inline math.
|
337
|
+
# These are used a three-step process below: Compute, Convert, Replace
|
338
|
+
# STEP1: compute height and vertical-align in `em` units
|
339
|
+
svg_height_in_ex = Float(svg_height.gsub('ex',''))
|
340
|
+
# MathJax sets SVG height in `ex` units but we want `em` units for PNG
|
341
|
+
png_height = (svg_height_in_ex * ex2em_height_scaling).to_s + 'em'
|
342
|
+
# Extract vertical-align css proprty for inline math equations:
|
338
343
|
if svg.parent.parent.attr('class') == "inline_math"
|
339
344
|
vertical_align = svg['style'].scan(/vertical-align: (.*?);/).flatten.first
|
340
345
|
if vertical_align
|
341
346
|
valign_in_ex = Float(vertical_align.gsub('ex',''))
|
342
|
-
valign_in_ex += 0.1155 # correction factor for MathJax 1px margin
|
343
|
-
# png vertical-align in ems is the css equivalent of depth in TeX
|
344
347
|
png_valign = (valign_in_ex * ex2em_valign_scaling).to_s + 'em'
|
345
348
|
else
|
346
349
|
png_valign = "0em"
|
@@ -348,7 +351,7 @@ module Softcover
|
|
348
351
|
else # No vertical align for displayed math
|
349
352
|
png_valign = nil
|
350
353
|
end
|
351
|
-
# STEP2: Generate PNG from each SVG (
|
354
|
+
# STEP2: Generate PNG from each SVG (unless PNG exists already).
|
352
355
|
unless File.exist?(png_filename)
|
353
356
|
h = ex2pt_scale_factor * svg_height_in_ex # = PNG height in pt
|
354
357
|
unless options[:silent] || options[:quiet]
|
data/lib/softcover/version.rb
CHANGED
data/spec/builders/epub_spec.rb
CHANGED
@@ -14,7 +14,10 @@ describe Softcover::Builders::Epub do
|
|
14
14
|
|
15
15
|
it "should be valid" do
|
16
16
|
output = `softcover epub:validate`
|
17
|
-
|
17
|
+
english = "No errors or warnings"
|
18
|
+
# I (mhartl) sometimes set my system language to Spanish.
|
19
|
+
spanish = "No se han detectado errores o advertencias"
|
20
|
+
expect(output).to match(/(#{english}|#{spanish})/)
|
18
21
|
end
|
19
22
|
|
20
23
|
describe "mimetype file" do
|
@@ -173,6 +176,12 @@ describe Softcover::Builders::Epub do
|
|
173
176
|
expect(Dir[path("epub/OEBPS/images/texmath/*.png")]).not_to be_empty
|
174
177
|
end
|
175
178
|
|
179
|
+
it "math PNGs shouldn't be too small (regression test for empty PNGs)" do
|
180
|
+
Dir[path("epub/OEBPS/images/texmath/*.png")].each do |pngfile|
|
181
|
+
expect(File.size(pngfile)).to be > 500
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
176
185
|
it "should record vertical-align of inline math SVGs" do
|
177
186
|
content = File.read(path("./epub/OEBPS/a_chapter_fragment.xhtml"))
|
178
187
|
html = Nokogiri::HTML(content)
|
@@ -224,7 +233,11 @@ describe Softcover::Builders::Epub do
|
|
224
233
|
subject(:builder) { @builder }
|
225
234
|
|
226
235
|
it "should be valid" do
|
227
|
-
|
236
|
+
output = `softcover epub:validate`
|
237
|
+
english = "No errors or warnings"
|
238
|
+
# I (mhartl) sometimes set my system language to Spanish.
|
239
|
+
spanish = "No se han detectado errores o advertencias"
|
240
|
+
expect(output).to match(/(#{english}|#{spanish})/)
|
228
241
|
end
|
229
242
|
|
230
243
|
it "should not raise an error" do
|
@@ -307,7 +320,10 @@ describe "article validation" do
|
|
307
320
|
|
308
321
|
it "should be valid" do
|
309
322
|
output = `softcover epub:validate`
|
310
|
-
|
323
|
+
english = "No errors or warnings"
|
324
|
+
# I (mhartl) sometimes set my system language to Spanish.
|
325
|
+
spanish = "No se han detectado errores o advertencias"
|
326
|
+
expect(output).to match(/(#{english}|#{spanish})/)
|
311
327
|
end
|
312
328
|
|
313
329
|
it "should description" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: softcover
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Hartl
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2017-01-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: polytexnic
|
@@ -581,7 +581,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
581
581
|
version: '0'
|
582
582
|
requirements: []
|
583
583
|
rubyforge_project:
|
584
|
-
rubygems_version: 2.5.1
|
584
|
+
rubygems_version: 2.4.5.1
|
585
585
|
signing_key:
|
586
586
|
specification_version: 4
|
587
587
|
summary: An ebook production system & sales and marketing platform for technical authors
|