diff --git a/lib/prawn/measurement_extensions.rb b/lib/prawn/measurement_extensions.rb index ea83a01e2..b5690fe63 100644 --- a/lib/prawn/measurement_extensions.rb +++ b/lib/prawn/measurement_extensions.rb @@ -79,4 +79,11 @@ def ft def pt pt2pt(self) end + + # Convert from pixels to points. + # + # @return [Number] + def px + px2pt(self) + end end diff --git a/lib/prawn/measurements.rb b/lib/prawn/measurements.rb index 50f83ddae..872367cef 100644 --- a/lib/prawn/measurements.rb +++ b/lib/prawn/measurements.rb @@ -124,6 +124,14 @@ def m2pt(m) def pt2mm(pt) pt * 1 / mm2pt(1) # (25.4 / 72) end + + # Convert pixels to points. + # + # @param px [Number] + # @return [Number] + def px2pt(px) + px * 72 / 96.0 + end end end # rubocop: enable Naming/MethodParameterName diff --git a/spec/prawn/measurements_extensions_spec.rb b/spec/prawn/measurements_extensions_spec.rb index c081136bd..3fdc42658 100644 --- a/spec/prawn/measurements_extensions_spec.rb +++ b/spec/prawn/measurements_extensions_spec.rb @@ -19,6 +19,7 @@ expect(1.ft).to eq(72 * 12) expect(1.yd).to eq(72 * 12 * 3) expect(1.pt).to eq(1) + expect(1.px).to eq(0.75) end end end