[luatex] Get area of a glyph?

Taco Hoekwater taco at elvenkind.com
Mon Sep 17 12:37:21 CEST 2012


Hi Arno,

On 09/16/2012 05:56 PM, Arno Trautmann wrote:
> Paul Isambert wrote:
>> Arno Trautmann <Arno.Trautmann at gmx.de> a écrit:
>>> Hi all,
>>>
>>> again a rather unusual question: I'd like to get the black area of a
>>> glyph. Why? To estimate it's greyness: For a “–” e.g. I want to get
>>> something like “5%” (of the whole box surface), while a “m” would give
>>> some “30%”, and a black box of course would result in 100%. Of course I
>>> would also be happy with any absolute value like “0.1 square inches” or
>>> whatever. So: Is there any chance to read such a value from inside
>>> LuaTex? Or is this information not available?
>>
>> LuaTeX doesn't even read the curves used to draw a glyph, so no way you
>> can get that information, as far as I can tell; you'll have to read
>> directly from the font file
>
> I heard the rumor that LuaTeX can read several things from font files ;)

It can read several things, but it limits itself to metrics and
opentype information. Reading actual outlines would require quite
a lot of extra code that is never needed elsewhere.

> So this sounds as if I had to learn how to read a font file and to
> extract the curves in LuaTeX. Will be my task for the next few months …
>
>> (under the assumption that knowing the shape
>> of the glyph gives you its area, which I don't know, not being a
>> mathematician;
>
> Being a physicist, I guess it should give the area. But it won't be easy …
>
>> perhaps by hit or miss?).
>>
>> Perhaps approximations exist, but I've never heard of them.
>
> Maybe someone else?

Assuming you have a bitmap image containing a glyph and imagemagick,
you can do:

   $ convert <image> -colorspace gray -colors 1 -format "%c" histogram:info:

which outputs something like this:

   32658582: (222,222,222) #DEDEDE rgb(222,222,222)

meaning that there are 32658582 pixels in the (virtual) conversion
output, with color rgb(222,222,222). Divide by 256 to the overall grayness.

Best wishes,
Taco



More information about the luatex mailing list