Giter Club home page Giter Club logo

freetype-py's Introduction

FreeType (high-level Python API)

Freetype Python provides bindings for the FreeType library. Only the high-level API is bound.

Documentation available at: http://freetype-py.readthedocs.org/en/latest/

Installation

From PyPI, recommended: pip install freetype-py. This will install the library with a bundled FreeType binary, so you're ready to go on Windows, macOS and Linux (all with 32 and 64 bit x86 architecture support).

Do note: if you specify the --no-binary paramater to pip, or use a different architecture for which we don't pre-compile binaries, the package will default to using an external FreeType library. Specify the environment variable FREETYPEPY_BUNDLE_FT=1 before calling pip to compile a binary yourself.

Installation with compiling FreeType from source

If you don't want to or can't use the pre-built binaries, build FreeType yourself: export FREETYPEPY_BUNDLE_FT=yesplease && pip install .. This will download and compile FreeType with Harfbuzz support as specified in setup-build-freetype.py. Set the environment variable PYTHON_ARCH to 32 or 64 to explicitly set an architecture, default is whatever your host machine uses. On macOS, we will always build a universal 32 and 64 bit Intel binary.

  • Windows: You need CMake and a C and C++ compiler, e.g. the Visual Code Community 2017 distribution with the desktop C++ workload.
  • macOS: You need CMake and the XCode tools (full IDE not necessary)
  • Linux: You need CMake, gcc and g++. For building a 32 bit library on a 64 bit machine, you need gcc-multilib and g++-multilib (Debian) or glibc-devel.i686 and libstdc++-devel.i686 (Fedora).

Installation with an external FreeType library (the default)

Install just the pure Python library and let it find a system-wide installed FreeType at runtime.

Mac users

Freetype should be already installed on your system. If not, either install it using homebrew or compile it and place the library binary file in '/usr/local/lib'.

Linux users

Freetype should be already installed on your system. If not, either install relevant package from your package manager or compile from sources and place the library binary file in '/usr/local/lib'.

Window users

There are no official Freetype binary releases available, but they offer some links to precompiled Windows DLLs. Please see the FreeType Downloads page for links. You can also compile the FreeType library from source yourself.

If you are using freetype-py on Windows with a 32-Bit version of Python, you need the 32-Bit version of the Freetype binary. The same applies for a 64-Bit version of Python.

Because of the way Windows searches for dll files, make sure the resulting file is named 'freetype.dll' (and not something like Freetype245.dll). Windows expects the library in one of the directories listed in the $PATH environment variable. As it is not recommended to place the dll in a Windows system folder, you can choose one of the following ways to solve this:

  • Place library in a folder of your choice and edit the $PATH user environment variable
  • Place library in a folder of your choice and edit the $PATH system environment variable
  • For development purpose, place the library in the working directory of the application
  • Place the library in one of the existing directories listed in $PATH

To get a complete list of all the directories in the $PATH environment variable (user and system), open a command promt and type

echo %PATH%

Usage example

import freetype
face = freetype.Face("Vera.ttf")
face.set_char_size( 48*64 )
face.load_char('S')
bitmap = face.glyph.bitmap
print(bitmap.buffer)

Screenshots

Screenshot below comes from the wordle.py example. No clever tricks here, just brute force.

image

Screenshots below comes from the glyph-vector.py and glyph-vector-2.py examples showing how to access a glyph outline information and use it to draw the glyph. Rendering (with Bézier curves) is done using matplotlib.

image

image

Screenshot below comes from the glyph-color.py showing how to draw and combine a glyph outline with the regular glyph.

image

The screenshot below comes from the hello-world.py example showing how to draw text in a bitmap (that has been zoomed in to show antialiasing).

image

The screenshot below comes from the agg-trick.py example showing an implementation of ideas from the Texts Rasterization Exposures by Maxim Shemarev.

image

Freezing apps

Freetype implements a hook for PyInstaller to help simplify the freezing process (it e.g. ensures that the freetype DLL is included). This hook requires PyInstaller version 4+.

freetype-py's People

Contributors

anthrotype avatar asvel avatar basnijholt avatar belluzj avatar bgermann avatar carandraug avatar chrissimpkins avatar drammock avatar duelafn avatar esoma avatar hintak avatar jbg avatar jiong3 avatar josh-hadley avatar korijn avatar madig avatar mammo0 avatar mdsitton avatar mgorny avatar ncbm avatar pnemade avatar rokm avatar rougier avatar shtrom avatar stahlfabrik avatar takaakifuji avatar tilka avatar vagran avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

freetype-py's Issues

Possible to create a Font object from memory?

A binding to FT_New_Memory_Face for creating a Font object. I have a binary font in memory and I don't want to save it to disk and load it again.

Is it possible to do so?
The Font constructor in the docs seems to only take a filename.

README.md instead of README.md

It seems Pypi does not interpret restructured text but interpret markdown. Hence, it would be better to use a README.md.

The list of contributors should be updated also.

Pin FreeType version?

Me and @moyogo were discussing pinning the FreeType version for freetype-py or at least giving the option to do so, instead of just using the system-provided one, so that you could carelessly do "pip install freetype-py==1.2.1" and always get the same FT behind it. This would probably entail importing FT as a subproject or referencing it another way and maybe distributing the built library along with freetype-py (purely for internal use)? This would also be relevant for a CI service that tests on 3 platforms (#77).

I know little about shipping C libs along with a Python lib yet, but thought I should start a discussion about it.

opengl.py and wordle.py can get broken by auto-clean up of FT_Bitmap

While looking at the memory leak issue, I added a destructor to FT_Bitmap. This cleans up some of the glyph-* example without manual clean-up, but breaks opengl.py and wordle.py . With the desctructor, opengl dies with ZeroDivisionError: float division by zero, while wordle draws all black. So at least those two examples depends on the C strcutures staying around when the python object goes out of scope. I haven't looked further as manual clean-up of the glyph-* examples works. This is nice but not necessary to achieve C-style memory usage tracking, and I didn't want to spend more time on it. Somebody needs to look at the usage of the Bitmap class and decide when and whether Bitmap should clean itself or not.

This is the actual diff (which I kept for reference, but reverted and in priv repo):

diff --git a/freetype/__init__.py b/freetype/__init__.py
index 0b640a0..b5d6b36 100644
--- a/freetype/__init__.py
+++ b/freetype/__init__.py
@@ -435,6 +435,12 @@ class Bitmap(object):
     def _get_buffer(self):
         data = [self._FT_Bitmap.buffer[i] for i in range(self.rows*self.pitch)]
         return data
+    def __del__( self ):
+        '''
+        Destroy Bitmap
+        '''
+        library = get_handle()
+        FT_Bitmap_Done(library, byref(self._FT_Bitmap))
     buffer = property(_get_buffer,
        doc = '''A typeless pointer to the bitmap buffer. This value should be
                 aligned on 32-bit boundaries in most cases.''')

Request to release new tarball 1.2 release

Hi,
I saw few commits since last I submitted patch to setup.py that advanced version to 1.2 but tarball 1.2 yet not released. From the last 1.1 tarball we still have issue of egg-info generated with 1.0.2 version.

I request to release new tarball that will then have matching tarball version and egg-info version.

Updated package on pypi

The 1.0.2 version on pypi/pip is very out of date, and does not reflect the latest documentation! Please provide a new release.

Segmentation fault when loading multiple fonts

I can reliably make freetype-py segfault. This may or may not be an instance of #44, but I have a rather minimal script that causes the segfault:

import freetype

FONTS = [
    '/usr/share/fonts/truetype/noto/NotoSans-Regular.ttf',
    '/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc',
]

def arbitrary_function(x):
    pass

for filename in FONTS:
    face = freetype.Face(filename)

I tried removing the unused function, but the segfault stopped happening when I did.

Information about my system:

  • Ubuntu 16.04
  • Python 3.5.1
  • freetype-py 1.0.2
  • freetype.version() returns (2, 6, 1)
  • Trying to load fonts from fonts-noto version 20160116-1, and fonts-noto-cjk version 1:1.004+repack2-1~ubuntu1

Cannot install 1.2 on Python 3.6, Windows 10 x86_64

pip install --user -U freetype-py
Collecting freetype-py
  Downloading freetype-py-1.2.tar.gz (181kB)
    100% |████████████████████████████████| 184kB 6.2MB/s
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\NIKOLA~1.WAX\AppData\Local\Temp\pip-build-c3iwzy2b\freetype-py\setup.py", line 12, in <module>
        'README.rst')).read()
      File "c:\program files\python36\lib\encodings\cp1252.py", line 23, in decode
        return codecs.charmap_decode(input,self.errors,decoding_table)[0]
    UnicodeDecodeError: 'charmap' codec can't decode byte 0x81 in position 3934: character maps to <undefined>

Hello World example dtype problem

Hey guys, I was just passing by trying the code of examples/hello-world.py and I got this error:

Traceback (most recent call last):
File "testing.py", line 39, in
Z[y:y+h,x:x+w] += numpy.array(bitmap.buffer).reshape(h,w)
TypeError: Cannot cast ufunc add output from dtype('float64') to dtype('int32') with casting rule 'same_kind'

So I changed the line where you create Z to make it float64 and now it works like a charm:

Z = numpy.zeros((height,width), dtype=numpy.float64)

Maybe it is a problem of my settings, I am using Windows 7 32 bits and Python 2.7 Anaconda.

Best,

Gabriel.

Make a new release

The latest master includes an important fix for Python 3.4 (#21), and is causing trouble when unbundling from vispy. A new release would make this much easier.

how do I get the glyph's decender??

basically, here's my issue:
http://lh3.ggpht.com/-GmqDWP3qLbI/VXy9r5LRGKI/AAAAAAAAJPc/qeai--pHARg/s802/Screenshot%252520-%25252006132015%252520-%25252007%25253A22%25253A11%252520PM.png

with PIL and PyGame I can get the glyph height and max height...
but with this, I can't seem to get the proper max height and a very wonky glyph height :/

I need the bitmap w/h for the GL texture, and the max w/h for the transformations.

EDIT:
the base line for drawing the glyphs is positioned at the upper left, while the characters are drawn to the bottom right.

Accept path-like objects

Currently, passing a Path (args.old_font) to e.g. Face() raises an exception:

Traceback (most recent call last):
  File ".\glyphdiff\fttest.py", line 43, in <module>
    old_font_ft = freetype.Face(args.old_font)
  File "C:\Users\nikolaus.waxweiler\AppData\Local\Python\Python36\site-packages\freetype\__init__.py", line 981, in __init__
    u_filename = c_char_p(_encode_filename(filename))
  File "C:\Users\nikolaus.waxweiler\AppData\Local\Python\Python36\site-packages\freetype\__init__.py", line 152, in _encode_filename
    encoded = filename.encode(sys.getfilesystemencoding())
AttributeError: 'WindowsPath' object has no attribute 'encode'

glyph-vector/glyph-vector-2 examples do not look at the 3rd order bezier curve bit

The examples ignore the 3rd order bezier curve bit and always intepolate between off-curve points. This is strictly speaking only correct for truetype fonts (which only use 2nd order bezier curves). The difference is small but may be important for some glyphs.

Also I think they assume the first point is always on curve. First point being off is less common, but valid.

I'm not going to fix these, but would push a couple of coments in the relevant places.
I just think the examples should do the right thing if somebody want to use a different font or a different glyph, or documented not to do so quite correctly...

(cairo don't have 2nd order curves - it is either line or 3rd order; but a 2nd order curve is just a 3rd order with duplicated off points).

Glyph bounding box does not work

All values in glyph bounding boxes accessed from FT.glyph.get_glyph().get_cbox(0) return 0. Probably caused by the fact that every point in Outline._FT_Outline.points returns (0, 0).

Freetype.dll provided by other software

A quick check of the freetype.dll in some other softwares (I am using WinPython 64 bit and I use freetype-py init.py file to specify the path of the dll, note that this is the freetype-py installed via pip install freetype-py, I assume the freetype-py.0.5.3 is similar):

  1. GTK+ 3.6.4 (both 32 bit and 64 bit versions): freetype.dll is called: "libfreetype-6.dll" (32 bit) (for 64 bit, libfreetype.dll.a), the freetype-py throws the error: WindowsError: [Error 126] The specified module could not be found (for 64 bit, WindowsError: [Error 193] %1 is not a valid Win32 application), is thrown.

  2. Gimp 2 (2.8.14, version under Windows): freetype.dll is called: "freetype6.dll" (32 bit)(for 64 bit, "libfreetype-6.dll"), and the same error is thrown by freetype-py, though Gimp 2 itself can be run without problem.

  3. Inkscape-0.48.5 wind32 (version under Windows): freetype.dll is called: "freetyp6.dll", and our code throw the error: WindowsError: [Error 193] %1 is not a valid Win32 application.

It seems that freetype-py (especially under 64 bit Win7) needs to use its own freetype.dll to run. There is a necessity to provide latest win 7 version of freetype.dll (both 32 bit and 64 bit versions).

Tao

GLUT problem

On Ubuntu 14.04 when running opengl.py example

/home/cyrille/miniconda3/lib/python3.5/site-packages/OpenGL/platform/baseplatform.py in __call__(self, *args, **named)
    405             raise error.NullFunctionError(
    406                 """Attempt to call an undefined function %s, check for bool(%s) before calling"""%(
--> 407                     self.__name__, self.__name__,
    408                 )
    409             )

NullFunctionError: Attempt to call an undefined function glutInit, check for bool(glutInit) before calling

I have already done sudo apt-get install freeglut3 freeglut3-dev. I installed PyOpenGL with pip. Any ideas?

Not an issue, but a suggestion.

I remember a while ago I was trying to get this to load on windows. While doing similar things for another dll-based library for glfw, I discovered why it wasn't working.

On 32-bit python under 64-bit windows, the system32 directory silently directs to SysWOW64 instead

So, if using 32-bit python under 64-bit windows, put the 32-bit DLL in C:\Windows\SysWOW64, and then python finds it

IPython on OSX -- RuntimeError: Freetype library not found

I'm trying to get [http://stackoverflow.com/a/3886301 this code] working.

It says it can't find glumpy.

sudo pip install glumpy

No it says it can't find OpenGL.

sudo pip install pyopengl

Now it's says as it can't find freetype. But pip fails to locate that lib. Luckily anaconda works:

conda install freetype

But even though the installation completed successfully, my IPython notebook cell keeps spitting out "RuntimeError: Freetype library not found"

I'm not sure what to do next.

Notebook is here: http://pipad.org/tmp/freetype_fail.html

[Moved] Demos don't run

hey man, glad you switched to GH. :)

The requirements for this library was back when I was using freeglut...
I've been using SDL for some time now and just recently got fonts working:

but the issue with it's video resize event has me switching to Qt...

I may end up needing this library if I can't get QFont() calls working with GL

Glyph class misses the 'advance' attribute

First: thank you for this nice python module :-)
Second: the doc string says the Glyph class should contain an attribute 'advance' but it is missing. I think it should be available just as in the GlyphSlot class. ( Currently, I have to cache it separately from the Glyph obtain via face.glyph.get_glyph() )

glyph-vector-2 svg example, bitmap inverted and also scaling wrong.

glyph-vector-2

I have rewritten the vector outline sample ( output at
#55 (comment) ) and is on to the composite bitmap +output sample in vector-2, and found it to be wrong in a few ways:

  • the bitmap in the background is inverted. It is actually a g, but I thought it was a stylized 'a',, when I first looked at it!

  • the scaling between the outline and the bitmap is meaningless - the outline is scaled to the width of "any-filled pixels", which means it is a lot wider and taller than the actual outline used for calculating the bitmap (half-pixels means it is a light-shade, etc), by up to almost two squares in both directions. In the above, the bitmap is 17x 25, and the outline is scaled to 17x25 - but it can be seen quite clearly from the figure above, that the bitmap is really calculated from an outline which was only just over 15 pixels wide in this scale.

Full example of rendering SVG text

Hi rougier,

I'd find it useful if there was a full example for rendering the entire outline of a word using Matplotlib, as opposed to just one character (as in ./examples/glyph-vector.py). Is this relatively easy for you to do? If not, or you're currently busy, let me know and I can try to figure it out myself.

PS -- my use case is essentially getting a vectorized output of e.g. the wordle example.

can't load_char() for FT_LOAD_TARGET_MONO

Hi all,

I found this library for monochrome font glyphs. If it is a standard, Gray 8 is set, which can be obtained. However monochrome seems impossible.

import freetype

face = freetype.Face("mplus-1p-black.ttf")
face.set_char_size( 1500 )
face.load_char('S', freetype.FT_LOAD_TARGETS['FT_LOAD_TARGET_MONO'])
bitmap = face.glyph.bitmap
print(bitmap.buffer) # error!

Comments?

Not showing actual error with "Freetype library not found"

It is very unfortunate in freetype-py/freetype/raw.py that any kind of library load errors results in the very unhelpful:

RuntimeError: Freetype library not found

I notice this because my freetype build was slightly out of sync (stale object files after a fetch/rebase). I only found out my freetype build was slightly out of sync and got the actual error when I ran ctype directly (the FT_UINT_TO_POINTER macro was introduced upstream 10 days ago) like this:

$ LD_LIBRARY_PATH=my-dev/freetype2/objs/.libs/ python
>>> from ctypes import *
>>> cdll.LoadLibrary("libfreetype.so.6")  
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib64/python2.7/ctypes/__init__.py", line 435, in LoadLibrary
    return self._dlltype(name)
  File "/usr/lib64/python2.7/ctypes/__init__.py", line 357, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: my-dev/freetype2/objs/.libs/libfreetype.so.6: undefined symbol: FT_UINT_TO_POINTER
>>> 

It would be better if freetype-py/freetype/raw.py does not lump every load error under library not found.

RuntimeError: Freetype library not found

h le5bock de 0k zm 83r

run at python3.4 pip list
appdirs (1.4.3)
Django (1.10.6)
django-reversion (2.0.8)
freetype-py (1.0.2)
olefile (0.44)
packaging (16.8)
Pillow (4.0.0)
pip (9.0.1)
PyMySQL (0.7.10)
pyparsing (2.2.0)
setuptools (34.3.2)
six (1.10.0)
wheel (0.29.0)
xlwt (1.2.0)

python manage.py runserver

RuntimeError: Freetype library not found

Suggestion: Add more pythonic way to get all character codes

Hi,

thanks for the library, very useful! I use it to get a list of all the supported codepoints in a font and it was not immediatly clear to me how to do it. I think a generator might be more pythonic:

def get_chars(self):
    charcode, agindex = self.get_first_char()
    yield (charcode, agindex)

    while agindex != 0:
        charcode, agindex = self.get_next_char(charcode, 0)
        yield (charcode, agindex)

freetype.ft_errors.FT_Exception: FT_Exception: (cannot open resource)

Hi,

I am new to Python programming. I don't know where else to post this issue. I installed freetype like this:
python -m pip install --user freetype-py

It seemed to install okay.

There is an error when the following code is run in IDLE:

import freetype
face = freetype.Face("Vera.ttf")
face.set_char_size( 48*64 )
face.load_char('S')
bitmap = face.glyph.bitmap
print (bitmap.buffer)

I suspect there is no "Vera.ttf" file. The code doesn't work for common windows "ttf" files. Do fonts need to be moved to a specific directory?

Windows 10 Pro
64-bit OS and processor

The error is:

Python 3.6.5 (v3.6.5:f59c0932b4, Mar 28 2018, 17:00:18) [MSC v.1900 64 bit (AMD64)] on win32
Type "copyright", "credits" or "license()" for more information.

= RESTART: C:\Users\jeff5\Desktop\Python\OpenGL_Exercises\freetypeExample.py =
Traceback (most recent call last):
File "C:\Users\jeff5\Desktop\Python\OpenGL_Exercises\freetypeExample.py", line 2, in
face = freetype.Face("Vera.ttf")
File "C:\Users\jeff5\AppData\Roaming\Python\Python36\site-packages\freetype_init_.py", line 989, in init
if error: raise FT_Exception( error )
freetype.ft_errors.FT_Exception: FT_Exception: (cannot open resource)

Install and use freetype-py in Win 7 64 bit

Hi,

I am using Windows 7 64bit, and I want to install and use freetype-py (from https://pypi.python.org/pypi/freetype-py).

I have installed GnuWin32 freetype6.dll, and freetype-py in Winpython 2.6.7.4.
When I import freetype in my python code, the system said:

raise RuntimeError('Freetype library not found')
RuntimeError: Freetype library not found

Then, I deleted the freetype-py 0.5.1, and used pip to install freetype-py 1.0. When I compiled the code, the system said:

dll = ctypes.CDLL(FT_Library_filename)
File "C:\WinPython-32bit-2.7.6.4\python-2.7.6\lib\ctypes__init__.py", line 365, in init
self._handle = _dlopen(self._name, mode)
WindowsError: [Error 126] The specified module could not be found.

It seems that the system cannot use CDLL function in ctypes, and I do not know how to fix it. The code works in my win 7 32 home premium 32 bit machine. I tried this in another Win 7 64bit laptop, and it throws the same error. I do not know how to fix it.

Another thing, when I put a copy of freetype.dll into Windows/SysWOW64, FT_Library_filename = ctypes.util.find_library('freetype') will set FT_Library_filename to "C:\Windows\System32\freetype.dll". This seems an error.

Anyway, the critical problem is that Class CDLL(object) does not work. I googled the Error 126, it seems that it concerns the dependencies of DLLs, but in this work, I am only using freetype.dll. There are three places I put freetype.dll: 1) Program Files\GnuWin32\bin; 2) Windows\System32; 3) Windows\SysWOW64. I changed the dll name from freetype6 to freetype.

Finally, by checking the Freetype Library documentation, I found that line 138 of init.py:
FT_Get_Advance = dll.FT_Get_Advance
Should be:
FT_Get_Advance = dll.FT_Get_PFR_Advance
Since there is no FT_Get_Advance method in freetype.

Thanks,
tao ([email protected])

Wordle example failure

I get the following failure when running the wordle.py example:

Traceback (most recent call last):
  File ".\wordle.py", line 125, in <module>
    I[y-h//2:y-h//2+h, x-w//2:x-w//2+w,0] |= (c * L).astype(int)
TypeError: ufunc 'bitwise_or' output (typecode 'i') could not be coerced to provided output parameter (typecode 'B') acc
ording to the casting rule ''same_kind''

access violation writing error in Face.__del__()

Hi, I'm learning to use Freetype recently, and I encounter an exception when I'm using freetype module in python:

Exception ignored in: <bound method Face.__del__ of <freetype.Face object at 0x000001AFDAC06860>>
Traceback (most recent call last):
  File "C:\Users\Xiaoqin\AppData\Local\Programs\Python\Python35\lib\site-packages\freetype\__init__.py", line 989, in __del__
OSError: exception: access violation writing 0x0000000000000054

I'm running Python 3 on Windows 64-bit and using the latest freetype-py and a homemade 64-bit freetype DLL found in a previous issue post.
I have tried in 2 computers in the same environment above, with a simple single-character rendering program, and have the same exception. Any idea how to deal with it?

Fast access of bitmap buffer with numpy

Hi,

currently the bitmap buffer can be accessed using freetype.Bitmap.buffer which returns a python list of all the bytes. Then I can use np.fromiter to get a numpy array, however, due to the python loop through all the bytes, this is really slow.

Is there a way to access the memory that the buffer points to directly with numpy? Anything I have to consider if I try to do that?

Freetype fails to detect kerning data

On many fonts that certainly have kerning pairs, Face.has_kerning is reporting False and the kern pairs come out to be zero.

import freetype

F = freetype.Face('FiraSans-Book.otf')
print(F.has_kerning)

>> False

Freetype library name on windows and Mac OS X

Am a bit surprised that freetype-py looks only for freetype.dll or libfreetype.so.6 . It is usually freetype6.dll built from upstream 's visual studio project, and libfreetype.6.dylib in Mac OS X's convention.

Memory leak when using glyph.stroke() / glyph.to_bitmap()

Hi,

when using the glyph.stroke() method with destroy=False, the script below will start eating up memory. For my purposes I think I can use destroy=True since the result seems to be the same, but I am not sure when exactly the glyph can be destroyed and when it should be kept. A memory leak shouldn't happen in any case, though.

Edit: If the last line is uncommented it will leak, no matter which value is used for destroy, to_bitmap(..., destroy=True) also doesn't seem to help

import freetype as ft

FONT_PATH = '../Fonts/Files/Arial Unicode.ttf'

SIZE = 100

ft_face = ft.Face(FONT_PATH, index=0)

for i in range(10000000):
    ft_face.set_pixel_sizes(SIZE, SIZE)
    load_options = ft.FT_LOAD_DEFAULT | ft.FT_LOAD_NO_BITMAP
    ft_face.load_char('A', load_options)

    slot = ft_face.glyph
    glyph = slot.get_glyph()
    stroker = ft.Stroker()
    stroker.set(int(SIZE * 64),
                ft.FT_STROKER_LINECAP_ROUND,
                ft.FT_STROKER_LINEJOIN_ROUND, 0)
    # leak
    glyph.stroke(stroker, destroy=False)
    # no leak
    #glyph.stroke(stroker, destroy=True)

    # leak, independent of value for destroy
    #blyph = glyph.to_bitmap(ft.FT_RENDER_MODE_NORMAL, ft.Vector(0, 0))

Freetype API - load flags - not quite up to date.

I found FT_LOAD_COMPUTE_METRICS not yet in freetype-py . It was introduced with freetype 2.6.1 . ( I contributed that change upstream, and also pushed the equivalent to the C# binding in SharpFont a while ago).

Also a related question: what version of freetype is freetype-py last sync to? Or is it just added as needed?

can't get freetype.dll to load

ok, so from the start, I've downloaded both x86 and x64 versions of freetype.dll provided on this issue.
(obviousely these work... lol)

I've been kinda pushing a working portable (from flash drive) extension-local dll load method on other developers, so I've modified raw.py to forcefully work with my method...
(when I say "pushing" I don't mean it offensively, and everyone likes it) ;)
here's to show you what I did:

import sys
filename = os.path.dirname( sys.modules['freetype'].__file__ ).replace('\\','/')+'/DLLS/freetype.dll'
try: _lib = ctypes.cdll.LoadLibrary(filename) # modified this using PyAssimp's load method
except (OSError, TypeError):
    _lib = None
    raise RuntimeError('Freetype library not found')

so I've placed the dll in that directory, but I'm still getting a not found error.

I'm currently running portable python x86 2.7.6.1 on Wine x86 on Xubuntu 14.04

this is the same method that works with PyOpenGL, PyGLFW, and PyAssimp, along with other modules I've fixed up...

I'm not exactly pro though, think you could tell me anything that could help me get this working?? :)

I've even tried printing the exception text itself rather than your forwarded message, and IT even says not found:

Python 2.7.6 (default, Nov 10 2013, 19:24:18) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>> 
/media/tcll/copy/Tcll/UMC_workspace/UMCSL/examples/freetype/DLLS/freetype.dll
[Error 126] Module not found

Traceback (most recent call last):
  File "\media\tcll\copy\Tcll\UMC_workspace\UMCSL\examples\opengl.py", line 10, in <module>
    from freetype import *
  File "\media\tcll\copy\Tcll\UMC_workspace\UMCSL\examples\freetype\__init__.py", line 21, in <module>
    from freetype.raw import *
  File "\media\tcll\copy\Tcll\UMC_workspace\UMCSL\examples\freetype\raw.py", line 45, in <module>
    raise RuntimeError('Freetype library not found')
RuntimeError: Freetype library not found
>>> 

so yea... I'm at a loss... :(
think you could help??

btw, my CPU is AMD, not intel... lol :P

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.