Am 16.09.2012 17:56, schrieb Arno Trautmann: > Paul Isambert wrote: >> Arno Trautmann <[email protected]> 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 ;) > 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? > Your 'per glyph' approach ignores kerning and composed characters. I doubt that the results would be meaningful, if you ignore what typesetting is about. I also doubt, that the wanted information is available in a font. To summarize it: this approach is based on insecure data and also hard to implement (in any case no fun).
Sounds like a dead end to me. The best way I can think of, is to create a standard pdf document and then use ImageMagick or GraphicMagick to convert that pdf into a b&w only png graphic (600ppi or higher). The conversion itself is done by ghostscript, but I guess you can also use the graphic tools to count the black points. If that is not possible, export as a RAW graphic and count the black pixels per algorithm. No font information or tricky algorithms needed. The other advantages of this approach are: - it's universal (create the same PDF with Word, Q-Express, whatever and compare the gray scale values) - low error (if resolution is high enough), as you get what you see - fast The hardest part is probably to figure out what standards exists to measure the gray scale of a given document. Hope that helps, Peter
