Issue 16 in freetype-py: Bitmaps are automatically cropped, despite FT_LOAD_CROP_BITMAP not being set

10 views
Skip to first unread message

freet...@googlecode.com

unread,
Sep 22, 2011, 7:30:18 PM9/22/11
to Nicolas...@inria.fr
Status: New
Owner: ----
Labels: Type-Defect Priority-Medium

New issue 16 by yarosla...@gmail.com: Bitmaps are automatically cropped,
despite FT_LOAD_CROP_BITMAP not being set
http://code.google.com/p/freetype-py/issues/detail?id=16

In the code below I generate the same glyph using Fontforge and
freetype-py, freetype-py gives a cropped glyph even though flags seem the
same (grepping fontforge sources for outline.flags)

import sys, pickle, numpy, Image
from freetype import *

face = Face('1550.ttf')
face.set_char_size(48*64)

face.load_glyph(14, FT_LOAD_RENDER|FT_OUTLINE_HIGH_PRECISION)
bitmap = face.glyph.bitmap
w,h = bitmap.width, bitmap.rows

reshaped = numpy.array(bitmap.buffer).reshape(h,w)
reshaped2 = numpy.zeros((h, w), dtype=numpy.ubyte)
reshaped2[0:h,0:w]|=reshaped

I = Image.fromarray(255-reshaped2)
I.save('freetype_glyph.png')

import fontforge
font = fontforge.open('1550.ttf')
glyphs = [g for g in font.glyphs()]
glyphs[14].export('fontforge_glyph.png')


Attachments:
1550.ttf 201 KB
fontforge_glyph.png 1015 bytes
freetype_glyph.png 147 bytes

freet...@googlecode.com

unread,
Sep 23, 2011, 2:44:21 AM9/23/11
to Nicolas...@inria.fr
Updates:
Status: Invalid

Comment #1 on issue 16 by Nicolas.Rougier: Bitmaps are automatically

cropped, despite FT_LOAD_CROP_BITMAP not being set
http://code.google.com/p/freetype-py/issues/detail?id=16

I think fontforge is doing some transformation before outputting the glyph.
The white space above the glyph is not right IMHO and I'm pretty sure
freetype does not encode such "useless" white space when generating
the "raw" glyph.

I suspect fontforge is in fact re-aligning the glyph taking the font height
into account. One way to check would be to look at the height of some other
glyphs and check they have same size.


freet...@googlecode.com

unread,
Sep 23, 2011, 3:22:53 AM9/23/11
to Nicolas...@inria.fr

Comment #2 on issue 16 by yarosla...@gmail.com: Bitmaps are automatically
cropped, despite FT_LOAD_CROP_BITMAP not being set
http://code.google.com/p/freetype-py/issues/detail?id=16

I see....
Fontforge renders glyphs of roughly the same height, not identical, but
close.
This whitespace is useful when trying to see all characters in a font, ie,
consider apostrophe vs comma

Attachments:
letters.png 120 KB

freet...@googlecode.com

unread,
Sep 23, 2011, 3:50:29 AM9/23/11
to Nicolas...@inria.fr

Comment #3 on issue 16 by Nicolas.Rougier: Bitmaps are automatically
cropped, despite FT_LOAD_CROP_BITMAP not being set
http://code.google.com/p/freetype-py/issues/detail?id=16

You can achieve the same output using the glyph information.
Have a look at:
http://code.google.com/p/freetype-py/source/browse/trunk/examples/hello-world.py

Reply all
Reply to author
Forward
0 new messages