forked from prawnpdf/prawn
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for modifying the text rendering mode
* Block form is available via the Prawn::Document#text_rendering_mode() method * Inline for is available as the :mode option to the Prawn::Document#text() method
- Loading branch information
Showing
5 changed files
with
137 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# encoding: utf-8 | ||
# | ||
# Example of character spacing | ||
# | ||
# | ||
require File.expand_path(File.join(File.dirname(__FILE__), | ||
%w[.. example_helper])) | ||
|
||
Prawn::Document.generate "rendering_mode.pdf" do |pdf| | ||
pdf.fill_color "00ff00" | ||
pdf.stroke_color "0000ff" | ||
|
||
# inline rendering mode | ||
pdf.text("Inline mode", :mode => 1, :size => 40) | ||
|
||
# block rendering mode | ||
pdf.text_rendering_mode(1) do | ||
pdf.text("Block", :size => 30) | ||
pdf.text("Mode", :size => 30) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# encoding: utf-8 | ||
|
||
require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper") | ||
|
||
describe "#text_rendering_mode" do | ||
it "should draw the text rendering mode to the document" do | ||
create_pdf | ||
@pdf.text_rendering_mode(1) do | ||
@pdf.text("hello world") | ||
end | ||
contents = PDF::Inspector::Text.analyze(@pdf.render) | ||
contents.text_rendering_mode.first.should == 1 | ||
end | ||
it "should not draw the text rendering mode to the document" + | ||
" when the new mode matches the old" do | ||
create_pdf | ||
@pdf.text_rendering_mode(0) do | ||
@pdf.text("hello world") | ||
end | ||
contents = PDF::Inspector::Text.analyze(@pdf.render) | ||
contents.text_rendering_mode.should.be.empty | ||
end | ||
it "should restore character spacing to 0" do | ||
create_pdf | ||
@pdf.text_rendering_mode(1) do | ||
@pdf.text("hello world") | ||
end | ||
contents = PDF::Inspector::Text.analyze(@pdf.render) | ||
contents.text_rendering_mode.should == [1,0] | ||
end | ||
it "should function as an accessor when no parameter given" do | ||
create_pdf | ||
@pdf.text_rendering_mode(2) do | ||
@pdf.text("hello world") | ||
@pdf.text_rendering_mode.should == 2 | ||
end | ||
@pdf.text_rendering_mode.should == 0 | ||
end | ||
it "should raise an exception when passed a value < 0 or > 7" do | ||
create_pdf | ||
lambda { @pdf.text_rendering_mode(-1) }.should raise_error(ArgumentError) | ||
lambda { @pdf.text_rendering_mode(8) }.should raise_error(ArgumentError) | ||
end | ||
end |