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

LATEXBuilder: add option image_scale2width #543

Merged
merged 4 commits into from
Apr 17, 2016
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
4 changes: 4 additions & 0 deletions doc/config.yml.sample
Original file line number Diff line number Diff line change
Expand Up @@ -296,4 +296,8 @@ secnolevel: 2
# 渡される引数1=作業用展開ディレクトリ、引数2=呼び出しを実行したディレクトリ
# hook_afterdvipdf: null
#
# 画像のscale=X.Xという指定を画像拡大縮小率からページ最大幅の相対倍率に変換します。
# image_scale2width: true
#
# pdfmaker:階層を使うものはここまで

1 change: 1 addition & 0 deletions lib/review/configure.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions lib/review/latexbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
37 changes: 37 additions & 0 deletions test/test_latexbuilder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down