File: font_metric_cache_spec.rb

package info (click to toggle)
ruby-prawn 1.3.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,936 kB
  • ctags: 802
  • sloc: ruby: 13,906; sh: 43; makefile: 15
file content (52 lines) | stat: -rw-r--r-- 1,405 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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# encoding: utf-8

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

describe "Font metrics caching" do
  let(:document) { Prawn::Document.new }

  subject { Prawn::FontMetricCache.new( document ) }

  it "should start with an empty cache" do
    subject.instance_variable_get( :@cache ).should be_empty
  end

  it "should cache the width of the provided string" do
    subject.width_of('M', {})

    subject.instance_variable_get( :@cache ).should have(1).entry
  end

  it "should only cache a single copy of the same string" do
    subject.width_of('M', {})
    subject.width_of('M', {})

    subject.instance_variable_get( :@cache ).should have(1).entry
  end

  it "should cache different copies for different strings" do
    subject.width_of('M', {})
    subject.width_of('W', {})

    subject.instance_variable_get( :@cache ).should have(2).entries
  end

  it "should cache different copies of the same string with different font sizes" do
    subject.width_of('M', {})

    document.font_size 24
    subject.width_of('M', {})

    subject.instance_variable_get( :@cache ).should have(2).entries
  end

  it "should cache different copies of the same string with different fonts" do
    subject.width_of('M', {})

    document.font 'Courier'
    subject.width_of('M', {})

    subject.instance_variable_get( :@cache ).should have(2).entries
  end
end