Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PDFMaker: introduce pdfmaker/use_original_image_size parameter to disable an automatic image scaling #1463

Merged
merged 2 commits into from
Jan 2, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/config.yml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,9 @@ pdfmaker:
# 画像のscale=X.Xという指定を画像拡大縮小率からページ最大幅の相対倍率に変換する
# image_scale2width: true
#
# 画像のデフォルトのサイズを、版面横幅合わせではなく、原寸をそのまま利用する
# use_original_image_size: null
#
# PDFやIllustratorファイル(.ai)の画像のBoudingBoxの抽出に指定のボックスを採用する
# cropbox(デフォルト), mediabox, artbox, trimbox, bleedboxから選択する。
# Illustrator CC以降のIllustratorファイルに対してはmediaboxを指定する必要がある
Expand Down
4 changes: 2 additions & 2 deletions lib/review/compiler.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright (c) 2009-2019 Minero Aoki, Kenshi Muto
# Copyright (c) 2009-2020 Minero Aoki, Kenshi Muto
# Copyright (c) 2002-2007 Minero Aoki
#
# This program is free software.
Expand Down Expand Up @@ -115,7 +115,7 @@ def inline_defined?(name)
defblock :emlist, 0..2
defblock :cmd, 0..1
defblock :table, 0..2
defblock :imgtable, 0..2
defblock :imgtable, 0..3
defblock :emtable, 0..1
defblock :quote, 0
defblock :image, 2..3, true
Expand Down
5 changes: 3 additions & 2 deletions lib/review/configure.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2012-2019 Masanori Kado, Masayoshi Takahashi, Kenshi Muto
# Copyright (c) 2012-2020 Masanori Kado, Masayoshi Takahashi, Kenshi Muto
#
# This program is free software.
# You can distribute or modify this program under the terms of
Expand Down Expand Up @@ -92,7 +92,8 @@ def self.values
'makeindex_dic' => nil,
'makeindex_mecab' => true,
'makeindex_mecab_opts' => '-Oyomi',
'use_cover_nombre' => true
'use_cover_nombre' => true,
'use_original_image_size' => nil
},
'imgmath_options' => {
'format' => 'png',
Expand Down
10 changes: 9 additions & 1 deletion lib/review/latexbuilder.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Copyright (c) 2002-2007 Minero Aoki
# 2008-2009 Minero Aoki, Kenshi Muto
# 2010-2019 Minero Aoki, Kenshi Muto, TAKAHASHI Masayoshi
# 2010-2020 Minero Aoki, Kenshi Muto, TAKAHASHI Masayoshi
#
# This program is free software.
# You can distribute or modify this program under the terms of
Expand Down Expand Up @@ -482,6 +482,14 @@ def source(lines, caption = nil, lang = nil)
def image_header(id, caption)
end

def parse_metric(type, metric)
s = super(type, metric)
if @book.config['pdfmaker']['use_original_image_size'] && s.empty? && !metric.present?
return ' ' # pass empty to \reviewincludegraphics
end
s
end

def handle_metric(str)
if @book.config['image_scale2width'] && str =~ /\Ascale=([\d.]+)\Z/
return "width=#{$1}\\maxwidth"
Expand Down
102 changes: 101 additions & 1 deletion test/test_latexbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def setup
'secnolevel' => 2, # for IDGXMLBuilder, EPUBBuilder
'toclevel' => 2,
'stylesheet' => nil, # for EPUBBuilder
'image_scale2width' => false,
'image_scale2width' => nil,
'texcommand' => 'uplatex',
'review_version' => '3'
)
Expand Down Expand Up @@ -859,6 +859,20 @@ def @chapter.image(_id)
\\end{reviewimage}
EOS
assert_equal expected, actual

@book.config['pdfmaker']['use_original_image_size'] = true
actual = compile_block("//image[sampleimg][sample photo]{\n//}\n")
expected = <<-EOS
\\begin{reviewimage}%%sampleimg
\\reviewincludegraphics[ ]{./images/chap1-sampleimg.png}
\\reviewimagecaption{sample photo}
\\label{image:chap1:sampleimg}
\\end{reviewimage}
EOS
assert_equal expected, actual

actual = compile_block("//image[sampleimg][sample photo][]{\n//}\n")
assert_equal expected, actual
end

def test_image_with_metric
Expand All @@ -877,6 +891,10 @@ def @chapter.image(_id)
\\end{reviewimage}
EOS
assert_equal expected, actual

@book.config['pdfmaker']['use_original_image_size'] = true
actual = compile_block("//image[sampleimg][sample photo][scale=1.2]{\n//}\n")
assert_equal expected, actual
end

def test_image_with_metric_width
Expand All @@ -896,6 +914,10 @@ def @chapter.image(_id)
\\end{reviewimage}
EOS
assert_equal expected, actual

@book.config['pdfmaker']['use_original_image_size'] = true
actual = compile_block("//image[sampleimg][sample photo][scale=1.2]{\n//}\n")
assert_equal expected, actual
end

def test_image_with_metric2
Expand All @@ -914,6 +936,10 @@ def @chapter.image(_id)
\\end{reviewimage}
EOS
assert_equal expected, actual

@book.config['pdfmaker']['use_original_image_size'] = true
actual = compile_block("//image[sampleimg][sample photo][scale=1.2,html::class=sample,latex::ignore=params]{\n//}\n")
assert_equal expected, actual
end

def test_image_with_metric2_width
Expand All @@ -933,6 +959,10 @@ def @chapter.image(_id)
\\end{reviewimage}
EOS
assert_equal expected, actual

@book.config['pdfmaker']['use_original_image_size'] = true
actual = compile_block("//image[sampleimg][sample photo][scale=1.2,html::class=sample,latex::ignore=params]{\n//}\n")
assert_equal expected, actual
end

def test_indepimage
Expand All @@ -950,6 +980,19 @@ def @chapter.image(_id)
\\end{reviewimage}
EOS
assert_equal expected, actual

@book.config['pdfmaker']['use_original_image_size'] = true
actual = compile_block("//indepimage[sampleimg][sample photo]\n")
expected = <<-EOS
\\begin{reviewimage}%%sampleimg
\\reviewincludegraphics[ ]{./images/chap1-sampleimg.png}
\\reviewindepimagecaption{図: sample photo}
\\end{reviewimage}
EOS
assert_equal expected, actual

actual = compile_block("//indepimage[sampleimg][sample photo][]\n")
assert_equal expected, actual
end

def test_indepimage_without_caption
Expand Down Expand Up @@ -984,6 +1027,10 @@ def @chapter.image(_id)
\\end{reviewimage}
EOS
assert_equal expected, actual

@book.config['pdfmaker']['use_original_image_size'] = true
actual = compile_block("//indepimage[sampleimg][sample photo][scale=1.2]\n")
assert_equal expected, actual
end

def test_indepimage_with_metric_width
Expand All @@ -1002,6 +1049,10 @@ def @chapter.image(_id)
\\end{reviewimage}
EOS
assert_equal expected, actual

@book.config['pdfmaker']['use_original_image_size'] = true
actual = compile_block("//indepimage[sampleimg][sample photo][scale=1.2]\n")
assert_equal expected, actual
end

def test_indepimage_with_metric2
Expand All @@ -1019,6 +1070,10 @@ def @chapter.image(_id)
\\end{reviewimage}
EOS
assert_equal expected, actual

@book.config['pdfmaker']['use_original_image_size'] = true
actual = compile_block(%Q(//indepimage[sampleimg][sample photo][scale=1.2, html::class="sample",latex::ignore=params]\n))
assert_equal expected, actual
end

def test_indepimage_without_caption_but_with_metric
Expand All @@ -1036,6 +1091,10 @@ def @chapter.image(_id)
\\end{reviewimage}
EOS
assert_equal expected, actual

@book.config['pdfmaker']['use_original_image_size'] = true
actual = compile_block("//indepimage[sampleimg][][scale=1.2]\n")
assert_equal expected, actual
end

def test_table
Expand Down Expand Up @@ -1194,6 +1253,47 @@ def @chapter.image(_id)
\\end{table}
EOS
assert_equal expected, actual

@book.config['pdfmaker']['use_original_image_size'] = true
actual = compile_block("//imgtable[sampleimg][test for imgtable]{\n//}\n")

expected = <<-EOS
\\begin{table}[h]%%sampleimg
\\reviewimgtablecaption{test for imgtable}
\\label{table:chap1:sampleimg}
\\begin{reviewimage}%%sampleimg
\\reviewincludegraphics[ ]{./images/chap1-sampleimg.png}
\\end{reviewimage}
\\end{table}
EOS
assert_equal expected, actual

actual = compile_block("//imgtable[sampleimg][test for imgtable][]{\n//}\n")
assert_equal expected, actual
end

def test_imgtable_with_metrics
def @chapter.image(_id)
item = Book::Index::Item.new('sampleimg', 1, 'sample img')
item.instance_eval { @path = './images/chap1-sampleimg.png' }
item
end

actual = compile_block("//imgtable[sampleimg][test for imgtable][scale=1.2]{\n//}\n")
expected = <<-EOS
\\begin{table}[h]%%sampleimg
\\reviewimgtablecaption{test for imgtable}
\\label{table:chap1:sampleimg}
\\begin{reviewimage}%%sampleimg
\\reviewincludegraphics[scale=1.2]{./images/chap1-sampleimg.png}
\\end{reviewimage}
\\end{table}
EOS
assert_equal expected, actual

@book.config['pdfmaker']['use_original_image_size'] = true
actual = compile_block("//imgtable[sampleimg][test for imgtable][scale=1.2]{\n//}\n")
assert_equal expected, actual
end

def test_table_row_separator
Expand Down