Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

make TransformationMatrix#horizontal_displacement_multiply! public

* allows callers to use this method directly if they know it is
  applicable, avoid the processing cost of the multiply! method
  • Loading branch information...
commit 86289299b9f791c2c64938984aebf8082fb5d6df 1 parent a788714
@yob authored
View
9 lib/pdf/reader/page_state.rb
@@ -323,14 +323,11 @@ def process_glyph_displacement(w0, tj, word_boundary)
# TODO: I'm pretty sure that tx shouldn't need to be divided by
# ctm[0] here, but this gets my tests green and I'm out of
# ideas for now
+ # TODO: support ty > 0
if ctm.a == 1
- @text_matrix.multiply!(1, 0,
- 0, 1,
- tx, ty)
+ @text_matrix.horizontal_displacement_multiply!(tx)
else
- @text_matrix.multiply!(1, 0,
- 0, 1,
- tx/ctm.a, ty)
+ @text_matrix.horizontal_displacement_multiply!(tx/ctm.a)
end
@font_size = @text_rendering_matrix = nil # invalidate cached value
end
View
14 lib/pdf/reader/transformation_matrix.rb
@@ -63,7 +63,7 @@ def multiply!(a,b=nil,c=nil, d=nil,e=nil,f=nil)
@f = f
elsif a == 1 && b == 0 && c == 0 && d == 1 && f == 0
# the other matrix is a horizontal displacement
- horizontal_displacement_multiply!(a,b,c,d,e,f)
+ horizontal_displacement_multiply!(e)
elsif @a == 1 && @b == 0 && @c == 0 && @d == 1 && @f == 0
# I'm a horizontal displacement
horizontal_displacement_multiply_reversed!(a,b,c,d,e,f)
@@ -79,21 +79,21 @@ def multiply!(a,b=nil,c=nil, d=nil,e=nil,f=nil)
self
end
- private
-
# Optimised method for when the second matrix in the calculation is
# a simple horizontal displacement.
#
# Like this:
#
- # [ 1 2 0 ] [ 1 0 0 ]
- # [ 3 4 0 ] x [ 0 1 0 ]
- # [ 5 6 1 ] [ 5 0 1 ]
+ # [ 1 2 0 ] [ 1 0 0 ]
+ # [ 3 4 0 ] x [ 0 1 0 ]
+ # [ 5 6 1 ] [ e2 0 1 ]
#
- def horizontal_displacement_multiply!(a2,b2,c2, d2,e2,f2)
+ def horizontal_displacement_multiply!(e2)
@e = @e + e2
end
+ private
+
# Optimised method for when the first matrix in the calculation is
# a simple horizontal displacement.
#
View
19 spec/transformation_matrix_spec.rb
@@ -5,7 +5,7 @@
# The results in these specs were generated at
# http://www.calcul.com/matrix-multiply-3x3-3x3 to ensure correctness.
-describe PDF::Reader::TransformationMatrix, "#multiply_with_an_object!" do
+describe PDF::Reader::TransformationMatrix, "#multiply!" do
class PDF::Reader::TransformationMatrix
# a helper method for tests
def multiply_with_an_object!(m2)
@@ -167,3 +167,20 @@ def multiply_with_an_object!(m2)
end
end
+
+describe PDF::Reader::TransformationMatrix, "#horizontal_displacement_multiply!" do
+ context "with [2,3,0 4,5,0 6 7 1]" do
+ let(:matrix_one) { PDF::Reader::TransformationMatrix.new(2,3,4,5,6,7)}
+
+ context "and a horizontal displacement" do
+ let(:displacement) { 10 }
+
+ it "should set the new matrix values" do
+ matrix_one.horizontal_displacement_multiply!(displacement)
+
+ matrix_one.to_a.should == [2,3,0, 4,5,0, 16,7,1]
+ end
+
+ end
+ end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.