Area and perimeter calculation of font body

57 views
Skip to first unread message

avroh...@gmail.com

unread,
Dec 29, 2019, 3:19:49 PM12/29/19
to fonttools
Given a particular font + character, and a set width or height, I'd like to be able to calculate the area taken up by the font.
So if for example I wanted to make a 20ft tall "A" with the arial font out of grass, I can calculate how much square footage I will need for materials. 

I'm also interested in knowing the length of the perimeter of the font, so if I needed some sort of edge banding to go around my grass installation, I could calculate the length of the edge banding needed. 

Is this something that can be done in fonttools?
Could someone point me in the right direction and how I might get started?  

Adam Twardoch (Lists)

unread,
Dec 29, 2019, 4:21:18 PM12/29/19
to avroh...@gmail.com, fonttools
You may be best served if you install Harfbuzz 
https://harfbuzz.github.io/install-harfbuzz.html and then use the hb-view commandline utility 

Check 

hb-view --help-all 

for all commandline options. You'll be able to render an image to PNG at a given pixel size, and then you can use any image processing library to load the PNG, make it monochrome, measure the dimensions and count the black pixels.

--
You received this message because you are subscribed to the Google Groups "fonttools" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fonttools+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fonttools/d60173f8-84d2-4bc9-9910-51f64341fc0f%40googlegroups.com.

Behdad Esfahbod

unread,
Dec 29, 2019, 5:07:27 PM12/29/19
to Adam Twardoch (Lists), avroh...@gmail.com, fonttools
Check or fontTools.pens.perimeterPen and fontTools.pens.areaPen

avroh...@gmail.com

unread,
Dec 29, 2019, 11:06:48 PM12/29/19
to fonttools
Could you recommend any place to get started on learning how to use the code?
I'm assuming I need to get from a font file into a "pen"?


On Sunday, December 29, 2019 at 5:07:27 PM UTC-5, behdad wrote:
Check or fontTools.pens.perimeterPen and fontTools.pens.areaPen

On Sun, Dec 29, 2019, 9:21 PM Adam Twardoch (Lists) <list...@twardoch.com> wrote:
You may be best served if you install Harfbuzz 
https://harfbuzz.github.io/install-harfbuzz.html and then use the hb-view commandline utility 

Check 

hb-view --help-all 

for all commandline options. You'll be able to render an image to PNG at a given pixel size, and then you can use any image processing library to load the PNG, make it monochrome, measure the dimensions and count the black pixels.
On Sun, 29 Dec 2019 at 21:19, <avroh...@gmail.com> wrote:
Given a particular font + character, and a set width or height, I'd like to be able to calculate the area taken up by the font.
So if for example I wanted to make a 20ft tall "A" with the arial font out of grass, I can calculate how much square footage I will need for materials. 

I'm also interested in knowing the length of the perimeter of the font, so if I needed some sort of edge banding to go around my grass installation, I could calculate the length of the edge banding needed. 

Is this something that can be done in fonttools?
Could someone point me in the right direction and how I might get started?  

--
You received this message because you are subscribed to the Google Groups "fonttools" group.
To unsubscribe from this group and stop receiving emails from it, send an email to font...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "fonttools" group.
To unsubscribe from this group and stop receiving emails from it, send an email to font...@googlegroups.com.

Adam Twardoch (Lists)

unread,
Dec 29, 2019, 11:36:53 PM12/29/19
to avroh...@gmail.com, fonttools

Adam Twardoch (Lists)

unread,
Dec 29, 2019, 11:38:46 PM12/29/19
to avroh...@gmail.com, fonttools

avroh...@gmail.com

unread,
Dec 30, 2019, 12:55:58 AM12/30/19
to fonttools
This looks like exactly what I need!
Forgive the beginner questions, if you've got the patience to respond...
(these numbers are for the letter R in arial.)

Do I have this right? 

letter_area = 0.194393,
land = 4 sqft 
letters_space = land * letter_area

so space taken up by letter is 0.777572 sqft?

How is perimeter used?
perimeter = 4.36786 
length = perimeter * land
so 17.47144 ft of edges?

Thank you so much for your time, I'm delighted to have gotten this far!! 

Behdad Esfahbod

unread,
Dec 30, 2019, 8:43:41 PM12/30/19
to avroh...@gmail.com, fonttools
On Mon, Dec 30, 2019 at 5:56 AM <avroh...@gmail.com> wrote:
This looks like exactly what I need!
Forgive the beginner questions, if you've got the patience to respond...
(these numbers are for the letter R in arial.)

Do I have this right? 

letter_area = 0.194393,
land = 4 sqft 

I assume that means land is 2x2 ft.  Let's call that:

scale = 2 ft

letters_space = land * letter_area

so space taken up by letter is 0.777572 sqft?

Correct.
 
How is perimeter used?
perimeter = 4.36786 
length = perimeter * land
so 17.47144 ft of edges?

No.

length = perimeter * scale
so 8.73572 ft of edges.

Thank you so much for your time, I'm delighted to have gotten this far!! 

Glad someone found this tool useful. :)

b
 
To unsubscribe from this group and stop receiving emails from it, send an email to fonttools+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fonttools/d2e35565-0770-4671-b0d5-0ca15dd78808%40googlegroups.com.


--

avroh...@gmail.com

unread,
Dec 31, 2019, 9:22:28 PM12/31/19
to fonttools
I'm afraid I don't understand. 

I've taken the aerial letter "I" and got 1.62109 as the perimeter.
Say my goal is to cut a single string that will go around the perimeter of the letter perfectly and match the string ends, end to end, with the height of the "I" being 1ft.
I measured, the actual number I need for that case is 2.25 ft of string.

How can I get to 2.25 from 1.62109?

Behdad Esfahbod

unread,
Jan 4, 2020, 7:02:10 AM1/4/20
to avroh...@gmail.com, fonttools
First.  You should use statisticsPen that is the latest evolution of that code.

We should change that code to also report glyph extents. Then you need to take the extents into account to scale further.

You need to learn some math I'm afraid.   Let's see if someone else can help based on my comment above 

To unsubscribe from this group and stop receiving emails from it, send an email to fonttools+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fonttools/dfdb4adb-5a25-455c-8537-e6316fa979a4%40googlegroups.com.


Reply all
Reply to author
Forward
0 new messages