softcover 1.2.6 → 1.2.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4808d28606e926f2e31806692d5fdda88747ce99
4
- data.tar.gz: cf29b0559c4cd6b3a03505dbcd92b026647137e1
3
+ metadata.gz: b898b99eecd64b980a244b0e8cb071d62e607beb
4
+ data.tar.gz: aba03346eeab27fcf482445621e0b61dc450f97a
5
5
  SHA512:
6
- metadata.gz: d62b11c809d1b2e416a252314bb4368407482d3e9452eef8d2e3f888035aa32e382e560f59f5c117943fa84c5ecb904b4630410e15a1db194d2aab7212ff341f
7
- data.tar.gz: 2014320f079f3e3c4927389b463424ffda8c1e16cd87b331076393cc16f4dd0afb14168fd62590c19fb0eed9be056318f769f728f1b84d905c72afc08085228e
6
+ metadata.gz: bc02c7d4e3bd9fc0303d87ba24c5b2dde04358701b04ccb99c0c0e5e714c2b26c3a72bcc1eeb7ac7504fd6cc2a08325797027b3f87812bbba8d92eca10a2bf18
7
+ data.tar.gz: 42b19d4cc49c42213cf835be214a55d3262dc18a16597827218528402a0d54b384c55841623e9dc7aa761b434cc221b9df44fbc7e58e22d7d3172cecfc114509
data/README.md CHANGED
@@ -14,6 +14,8 @@ On some systems, you may need to add an extra option to handle SSL correctly:
14
14
 
15
15
  $ gem install softcover -- --with-cppflags=-I/usr/local/opt/openssl/include
16
16
 
17
+ Then install the dependencies as described [http://manual.softcover.io/book/getting_started#sec-installing_softcover](here).
18
+
17
19
  ## Usage
18
20
 
19
21
  Run
@@ -18,5 +18,5 @@
18
18
 
19
19
  body {
20
20
  font-size: 80%;
21
- line-height: 1.1;
21
+ line-height: 1.4;
22
22
  }
@@ -18,5 +18,5 @@
18
18
 
19
19
  body {
20
20
  font-size: 80%;
21
- line-height: 1.1;
21
+ line-height: 1.4;
22
22
  }
@@ -304,7 +304,6 @@ module Softcover
304
304
  source.css('script').each(&:remove)
305
305
  # Remove all the MathJax preview spans.
306
306
  source.css('MathJax_Preview').each(&:remove)
307
-
308
307
  # Suck out all the SVGs
309
308
  svgs = source.css('div#book svg')
310
309
  frames = source.css('span.MathJax_SVG')
@@ -318,17 +317,43 @@ module Softcover
318
317
  svg_filename = File.join(texmath_dir, "#{digest(output)}.svg")
319
318
  svg_filename_abspath = File.join("#{Dir.pwd}", svg_filename)
320
319
  File.write(svg_filename, output)
321
- # Convert to PNG.
320
+ # Convert to PNG named:
322
321
  png_filename = svg_filename.sub('.svg', '.png')
323
322
  png_filename_abspath = svg_filename_abspath.sub('.svg', '.png')
324
323
  pngs << png_filename
324
+ #
325
+ # Settings for inline math in ePub / mobi
326
+ pt_scale_factor = 16 # scaling factor used for SVG --> PNG conversion
327
+ height_scale_factor = 0.50 # 1ex/1em for scaling math PNG's height
328
+ valign_scale_factor = 0.45 # 1ex/1em when scaling PNG's vertical-align
329
+ # these are used in three-step process below: Extract, Convert, Eeplace
330
+ # STEP1: Extract information from svg tag.
331
+ svg_height = svg['style'].scan(/height: (.*?);/).flatten.first
332
+ if svg_height
333
+ svg_height_in_ex = Float(svg_height.gsub('ex',''))
334
+ png_height = (svg_height_in_ex * height_scale_factor).to_s + 'em'
335
+ # MathJax sets SVG height in `ex` units but we wan `em` units for PNG
336
+ end
337
+ # Extract vertical-align css proprty for for inline math.
338
+ if svg.parent.parent.attr('class') == "inline_math"
339
+ vertical_align = svg['style'].scan(/vertical-align: (.*?);/).flatten.first
340
+ if vertical_align
341
+ valign_in_ex = Float(vertical_align.gsub('ex',''))
342
+ # png vertical-align in ems is the css equivalent of `depth` in TeX
343
+ png_valign = (valign_in_ex * valign_scale_factor).to_s + 'em'
344
+ else
345
+ png_valign = "0em"
346
+ end
347
+ else # No vertical align for displayed math
348
+ png_valign = nil
349
+ end
350
+ # STEP2: Generate PNG from each SVG (if necessary).
325
351
  unless File.exist?(png_filename)
352
+ h = pt_scale_factor * svg_height.to_f # PNG height in pt
326
353
  unless options[:silent] || options[:quiet]
327
354
  puts "Creating #{png_filename}"
328
355
  end
329
- svg_height = svg['style'].scan(/height: (.*?);/).flatten.first
330
- scale_factor = 8 # This scale factor turns out to look good.
331
- h = scale_factor * svg_height.to_f
356
+ # generate png from the MathJax_SVG using inkscape
332
357
  cmd = "#{inkscape} -f #{svg_filename_abspath} -e #{png_filename_abspath} -h #{h}pt"
333
358
  if options[:silent]
334
359
  silence { silence_stream(STDERR) { system cmd } }
@@ -337,10 +362,14 @@ module Softcover
337
362
  end
338
363
  end
339
364
  rm svg_filename
365
+ # STEP 3: Replace svg element with an equivalent png.
340
366
  png = Nokogiri::XML::Node.new('img', source)
341
- png['src'] = File.join('images', 'texmath',
342
- File.basename(png_filename))
367
+ png['src'] = File.join('images', 'texmath', File.basename(png_filename))
343
368
  png['alt'] = png_filename.sub('.png', '')
369
+ png['style'] = 'height:' + png_height + ';'
370
+ if png_valign
371
+ png['style'] += ' vertical-align:' + png_valign + ';'
372
+ end
344
373
  svg.replace(png)
345
374
  end
346
375
  # Make references relative.
@@ -262,7 +262,7 @@ module Softcover::Utils
262
262
  # Finds EpubCheck anywhere on the path.
263
263
  version_3 = path('epubcheck-3.0/epubcheck-3.0.jar')
264
264
  version_4 = path('epubcheck-4.0.1/epubcheck.jar')
265
- first_path(version_4) || first_path(version_3) || ""
265
+ first_path(version_4) || first_path(version_3) || get_filename(:'epubcheck') || ""
266
266
  when :inkscape
267
267
  default = '/Applications/Inkscape.app/Contents/Resources/bin/inkscape'
268
268
  filename_or_default(:inkscape, default)
@@ -1,3 +1,3 @@
1
1
  module Softcover
2
- VERSION = "1.2.6"
2
+ VERSION = "1.2.7"
3
3
  end
@@ -172,6 +172,24 @@ describe Softcover::Builders::Epub do
172
172
  expect(path("epub/OEBPS/images/texmath")).to exist
173
173
  expect(Dir[path("epub/OEBPS/images/texmath/*.png")]).not_to be_empty
174
174
  end
175
+
176
+ it "should record vertical-align of inline math SVGs" do
177
+ content = File.read(path("./epub/OEBPS/a_chapter_fragment.xhtml"))
178
+ html = Nokogiri::HTML(content)
179
+ math_imgs = html.search('span.inline_math img')
180
+ math_imgs.each do |math_img|
181
+ expect(math_img['style']).to match /vertical-align/
182
+ end
183
+ end
184
+
185
+ it "should not add vertical-align to displayed math" do
186
+ content = File.read(path("./epub/OEBPS/a_chapter_fragment.xhtml"))
187
+ html = Nokogiri::HTML(content)
188
+ math_imgs = html.search('div.equation img')
189
+ math_imgs.each do |math_img|
190
+ expect(math_img['style']).not_to match /vertical-align/
191
+ end
192
+ end
175
193
  end
176
194
 
177
195
  it "should create the style files" 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.2.6
4
+ version: 1.2.7
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: 2016-03-21 00:00:00.000000000 Z
12
+ date: 2016-04-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: polytexnic