Ruby Prawn - monophonic font width detection

I am trying to overlay polygons on top of a grid of monosized characters. To calculate the coordinates for polygons, I need to know how wide one character is. How do you determine the width of a single character with a monolayer (Courier 12) using a Ruby Prawn gem?

+4
source share
1 answer

According to this, there is a width_of method, buried in shrimp:

 pdf.width_of(text, :size => 10) 

Here is a bit more documentation that I could dig up. As for your question, I think you would do:

 pdf.width_of('a', :size => 12) #provided a was the single character in question 
+9
source

Source: https://habr.com/ru/post/1401274/


All Articles