File: text_with_inline_formatting_spec.rb

package info (click to toggle)
ruby-prawn 2.1.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 3,220 kB
  • ctags: 826
  • sloc: ruby: 14,469; sh: 43; makefile: 18
file content (35 lines) | stat: -rw-r--r-- 1,165 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# encoding: utf-8

require File.join(File.expand_path(File.dirname(__FILE__)), "spec_helper")

describe "#formatted_text" do
  it "should draw text" do
    create_pdf
    string = "hello world"
    format_array = [:text => string]
    @pdf.formatted_text(format_array)
    # grab the text from the rendered PDF and ensure it matches
    text = PDF::Inspector::Text.analyze(@pdf.render)
    expect(text.strings.first).to eq(string)
  end
end

describe "#text with inline styling" do
  before(:each) { create_pdf }

  it "should automatically move to a new page if the tallest fragment" \
     " on the next line won't fit in the available space" do
    create_pdf
    @pdf.move_cursor_to(@pdf.font.height)
    formatted = "this contains <font size='24'>sized</font> text"
    @pdf.text(formatted, :inline_format => true)
    pages = PDF::Inspector::Page.analyze(@pdf.render).pages
    expect(pages.size).to eq(2)
  end

  it "should embed links as literal strings" do
    @pdf.text "<link href='http://wiki.github.com/sandal/prawn/'>wiki</link>",
              :inline_format => true
    expect(@pdf.render).to match(%r{/URI\s+\(http://wiki\.github\.com})
  end
end