More flexible search for shared libraries
This commit is contained in:
parent
707d234e2b
commit
5f98498669
1 changed files with 12 additions and 2 deletions
|
@ -18,6 +18,7 @@ http://www.cairographics.org/freetypepython/
|
||||||
import cairo
|
import cairo
|
||||||
import ctypes
|
import ctypes
|
||||||
import ctypes.util
|
import ctypes.util
|
||||||
|
import os
|
||||||
|
|
||||||
_freetypeInitialized = False
|
_freetypeInitialized = False
|
||||||
|
|
||||||
|
@ -28,6 +29,15 @@ class PycairoContext(ctypes.Structure):
|
||||||
("base", ctypes.c_void_p)
|
("base", ctypes.c_void_p)
|
||||||
]
|
]
|
||||||
|
|
||||||
|
def findLib(fileNameGuess, libNameGuesses):
|
||||||
|
if os.path.exists(fileNameGuess):
|
||||||
|
return fileNameGuess
|
||||||
|
for libNameGuess in libNameGuesses:
|
||||||
|
libPath = ctypes.util.find_library(libNameGuess)
|
||||||
|
if libPath:
|
||||||
|
return libPath
|
||||||
|
return None
|
||||||
|
|
||||||
def fontFaceFromFile(filename):
|
def fontFaceFromFile(filename):
|
||||||
global _freetypeInitialized
|
global _freetypeInitialized
|
||||||
global _freetype_so
|
global _freetype_so
|
||||||
|
@ -40,11 +50,11 @@ def fontFaceFromFile(filename):
|
||||||
|
|
||||||
if not _freetypeInitialized:
|
if not _freetypeInitialized:
|
||||||
# Find shared libraries.
|
# Find shared libraries.
|
||||||
freetypeLibName = ctypes.util.find_library("freetype")
|
freetypeLibName = findLib("freetype6.dll", ["freetype", "freetype6"])
|
||||||
if not freetypeLibName:
|
if not freetypeLibName:
|
||||||
raise Exception("FreeType library not found.")
|
raise Exception("FreeType library not found.")
|
||||||
|
|
||||||
cairoLibName = ctypes.util.find_library("cairo")
|
cairoLibName = findLib("libcairo-2.dll", ["cairo", "libcairo-2"])
|
||||||
if not cairoLibName:
|
if not cairoLibName:
|
||||||
raise Exception("Cairo library not found.")
|
raise Exception("Cairo library not found.")
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue