public
Description: Fast, Nimble PDF Writer for Ruby
Homepage: http://prawn.majesticseacreature.com
Clone URL: git://github.com/sandal/prawn.git
Add new font features
sandal (author)
Sun Oct 26 10:11:16 -0700 2008
commit  50e53a09409d600d000d1e4f7b45ba9539138fab
tree    85844d75c18f2732da9040c50dbeff2f46ac381d
parent  6ca21044092ec8078a3f63e8b7333999166da992
...
15
16
17
 
 
 
 
 
18
19
 
 
 
 
20
...
15
16
17
18
19
20
21
22
23
 
24
25
26
27
28
0
@@ -15,5 +15,13 @@ Prawn::Document.generate "font_size.pdf", :page_size => "A4" do
0
     text 'Font at 9 point'
0
   end
0
   
0
+  font("Times-Roman", :style => :italic, :size => 12) do
0
+    text "Font in times at 12"
0
+    font.size(16) { text "Font in Times at 16" }
0
+  end
0
+  
0
   text 'Font at 16 point'
0
-end
0
+  
0
+  font "Courier", :size => 40
0
+  text "40 pt!"
0
+end
0
\ No newline at end of file
...
22
23
24
 
 
 
 
 
25
26
27
...
34
35
36
37
 
 
 
 
 
 
 
 
 
 
38
39
40
...
134
135
136
137
 
 
 
 
 
138
139
140
...
22
23
24
25
26
27
28
29
30
31
32
...
39
40
41
 
42
43
44
45
46
47
48
49
50
51
52
53
54
...
148
149
150
 
151
152
153
154
155
156
157
158
0
@@ -22,6 +22,11 @@ module Prawn
0
     # more portable.
0
     #
0
     def font(name=nil, options={}) 
0
+      if block_given?
0
+        original_name = font.name
0
+        original_size = font.size
0
+      end
0
+      
0
       if name     
0
         if font_families.key?(name)
0
           ff = name                                                      
0
@@ -34,7 +39,16 @@ module Prawn
0
         Prawn::Font.register("Helvetica", :for => self, :family => "Helvetica") 
0
         @font_name = "Helvetica"             
0
       end  
0
-      font_registry[@font_name] 
0
+     
0
+      font_obj = font_registry[@font_name] 
0
+      font_obj.size = options[:size] if options[:size]
0
+      
0
+      if block_given?
0
+        yield
0
+        font(original_name, :size => original_size)
0
+      else
0
+        font_obj
0
+      end
0
     end      
0
        
0
     # Hash of Font objects keyed by names
0
@@ -134,7 +148,11 @@ module Prawn
0
       end  
0
       
0
       add_to_current_page    
0
-    end      
0
+    end     
0
+    
0
+    def inspect
0
+      "Prawn::Font< #{name}: #{size} >"
0
+    end
0
     
0
     # Sets the default font size for use within a block. Individual overrides
0
     # can be used as desired. The previous font size will be restored after the
...
70
71
72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
73
74
75
...
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
0
@@ -70,6 +70,28 @@ describe "font style support" do
0
       
0
 end
0
 
0
+describe "Transactional font handling" do
0
+  before(:each) { create_pdf }
0
+  
0
+  it "should allow setting of size directly when font is created" do
0
+    @pdf.font "Courier", :size => 16
0
+    @pdf.font.size.should == 16 
0
+  end
0
+  
0
+  it "should allow temporary setting of a new font using a transaction" do
0
+    original = @pdf.font
0
+    
0
+    @pdf.font "Courier", :size => 16 do
0
+      @pdf.font.name.should == "Courier"
0
+      @pdf.font.size.should == 16
0
+    end
0
+    
0
+    @pdf.font.should == original  
0
+  end
0
+  
0
+end
0
+
0
+
0
 describe "Document#page_fonts" do
0
   before(:each) { create_pdf } 
0
   

Comments