diff --git a/doc/config.yml.sample b/doc/config.yml.sample index 8b90a7ee8..f56c0fc94 100644 --- a/doc/config.yml.sample +++ b/doc/config.yml.sample @@ -296,4 +296,8 @@ secnolevel: 2 # 渡される引数1=作業用展開ディレクトリ、引数2=呼び出しを実行したディレクトリ # hook_afterdvipdf: null # + # 画像のscale=X.Xという指定を画像拡大縮小率からページ最大幅の相対倍率に変換します。 + # image_scale2width: true + # # pdfmaker:階層を使うものはここまで + diff --git a/lib/review/configure.rb b/lib/review/configure.rb index 3d0890521..acefb9dd0 100644 --- a/lib/review/configure.rb +++ b/lib/review/configure.rb @@ -50,6 +50,7 @@ def self.values "ext" => '.re', "image_dir" => 'images', "image_types" => %w( .ai .psd .eps .pdf .tif .tiff .png .bmp .jpg .jpeg .gif .svg ), + "image_scale2width" => true, # for LaTeX "bib_file" => "bib.re", "colophon_order" => %w(aut csl trl dsr ill cov edt pbl contact prt), "externallink" => true, diff --git a/lib/review/latexbuilder.rb b/lib/review/latexbuilder.rb index a1fd7026c..a94881ccd 100644 --- a/lib/review/latexbuilder.rb +++ b/lib/review/latexbuilder.rb @@ -345,6 +345,13 @@ def source(lines, caption, lang = nil) def image_header(id, caption) end + def handle_metric(str) + if @book.config["image_scale2width"] && str =~ /\Ascale=([\d.]+)\Z/ + return "width=#{$1}\\maxwidth" + end + str + end + def result_metric(array) "#{array.join(',')}" end diff --git a/test/test_latexbuilder.rb b/test/test_latexbuilder.rb index e8e46cb28..9d294b2c7 100644 --- a/test/test_latexbuilder.rb +++ b/test/test_latexbuilder.rb @@ -15,6 +15,7 @@ def setup "secnolevel" => 2, # for IDGXMLBuilder, EPUBBuilder "toclevel" => 2, "stylesheet" => nil, # for EPUBBuilder + "image_scale2width" => false, "texcommand" => "uplatex" }) @book = Book::Base.new(nil) @@ -364,6 +365,18 @@ def @chapter.image(id) assert_equal %Q|\\begin{reviewimage}\n\\includegraphics[scale=1.2]{./images/chap1-sampleimg.png}\n\\caption{sample photo}\n\\label{image:chap1:sampleimg}\n\\end{reviewimage}\n|, actual end + def test_image_with_metric_width + def @chapter.image(id) + item = Book::ImageIndex::Item.new("sampleimg",1) + item.instance_eval{@path="./images/chap1-sampleimg.png"} + item + end + + @config["image_scale2width"] = true + actual = compile_block("//image[sampleimg][sample photo][scale=1.2]{\n//}\n") + assert_equal %Q|\\begin{reviewimage}\n\\includegraphics[width=1.2\\maxwidth]{./images/chap1-sampleimg.png}\n\\caption{sample photo}\n\\label{image:chap1:sampleimg}\n\\end{reviewimage}\n|, actual + end + def test_image_with_metric2 def @chapter.image(id) item = Book::ImageIndex::Item.new("sampleimg",1) @@ -375,6 +388,18 @@ def @chapter.image(id) assert_equal %Q|\\begin{reviewimage}\n\\includegraphics[scale=1.2,ignore=params]{./images/chap1-sampleimg.png}\n\\caption{sample photo}\n\\label{image:chap1:sampleimg}\n\\end{reviewimage}\n|, actual end + def test_image_with_metric2_width + def @chapter.image(id) + item = Book::ImageIndex::Item.new("sampleimg",1) + item.instance_eval{@path="./images/chap1-sampleimg.png"} + item + end + + @config["image_scale2width"] = true + actual = compile_block("//image[sampleimg][sample photo][scale=1.2,html::class=sample,latex::ignore=params]{\n//}\n") + assert_equal %Q|\\begin{reviewimage}\n\\includegraphics[width=1.2\\maxwidth,ignore=params]{./images/chap1-sampleimg.png}\n\\caption{sample photo}\n\\label{image:chap1:sampleimg}\n\\end{reviewimage}\n|, actual + end + def test_indepimage def @chapter.image(id) item = Book::ImageIndex::Item.new("sampleimg",1) @@ -409,6 +434,18 @@ def @chapter.image(id) assert_equal %Q|\\begin{reviewimage}\n\\includegraphics[scale=1.2]{./images/chap1-sampleimg.png}\n\\reviewindepimagecaption{図: sample photo}\n\\end{reviewimage}\n|, actual end + def test_indepimage_with_metric_width + def @chapter.image(id) + item = Book::ImageIndex::Item.new("sampleimg",1) + item.instance_eval{@path="./images/chap1-sampleimg.png"} + item + end + + @config["image_scale2width"] = true + actual = compile_block("//indepimage[sampleimg][sample photo][scale=1.2]\n") + assert_equal %Q|\\begin{reviewimage}\n\\includegraphics[width=1.2\\maxwidth]{./images/chap1-sampleimg.png}\n\\reviewindepimagecaption{図: sample photo}\n\\end{reviewimage}\n|, actual + end + def test_indepimage_with_metric2 def @chapter.image(id) item = Book::ImageIndex::Item.new("sampleimg",1)