Skip to content

Commit

Permalink
feat: Pixels to Points
Browse files Browse the repository at this point in the history
  • Loading branch information
wilsondealmeida committed Oct 22, 2024
1 parent c531f87 commit ea6154b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/prawn/measurement_extensions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,11 @@ def ft
def pt
pt2pt(self)
end

# Convert from pixels to points.
#
# @return [Number]
def px
px2pt(self)
end
end
8 changes: 8 additions & 0 deletions lib/prawn/measurements.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions spec/prawn/measurements_extensions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit ea6154b

Please sign in to comment.