Author: dmeyer
Date: Sat Jun 17 15:47:11 2006
New Revision: 1546
Modified:
trunk/imlib2/src/__init__.py
trunk/imlib2/src/font.py
trunk/imlib2/src/image.py
Log:
Added function to access the text style geometry which is the
number of pixels added to font height and stringsize because
of the font style.
Modified: trunk/imlib2/src/__init__.py
==============================================================================
--- trunk/imlib2/src/__init__.py (original)
+++ trunk/imlib2/src/__init__.py Sat Jun 17 15:47:11 2006
@@ -125,3 +125,14 @@
'FontName/Size', such as 'Arial/16'
"""
return Font(font + "/" + str(size))
+
+
+def get_font_style_geometry(style):
+ """
+ Return the additional pixel the font needs for the style. This function
+ will return left, top, right, bottom as number of pixels the text will
+ start to the left/top and the number of pixels it needs more at the
+ right/bottom. To avoid extra calculations the function will also return
+ the additional width and height needed for the style.
+ """
+ return TEXT_STYLE_GEOMETRY[style]
Modified: trunk/imlib2/src/font.py
==============================================================================
--- trunk/imlib2/src/font.py (original)
+++ trunk/imlib2/src/font.py Sat Jun 17 15:47:11 2006
@@ -32,6 +32,23 @@
import _Imlib2
from kaa.strutils import utf8
+TEXT_STYLE_PLAIN, \
+TEXT_STYLE_SHADOW, \
+TEXT_STYLE_OUTLINE, \
+TEXT_STYLE_SOFT_OUTLINE, \
+TEXT_STYLE_GLOW, \
+TEXT_STYLE_OUTLINE_SHADOW, \
+TEXT_STYLE_FAR_SHADOW, \
+TEXT_STYLE_OUTLINE_SOFT_SHADOW, \
+TEXT_STYLE_SOFT_SHADOW, \
+TEXT_STYLE_FAR_SOFT_SHADOW = range(10)
+
+TEXT_STYLE_GEOMETRY = [
+ (0,0,0,0,0,0), (0,0,1,1,1,1), (1,1,1,1,2,2), (2,2,2,2,4,4),
+ (2,2,2,2,4,4), (1,1,2,2,3,3), (0,0,2,2,2,2), (1,1,4,4,5,5),
+ (1,1,3,3,4,4), (0,0,4,4,4,4)
+]
+
class Font(object):
def __init__(self, fontdesc, color=(255,255,255,255)):
"""
@@ -56,7 +73,7 @@
self.fontname = fontdesc[:sep]
self.size = fontdesc[sep + 1:]
self.set_color(color)
- self.style = 0 # TEXT_STYLE_PLAIN
+ self.style = TEXT_STYLE_PLAIN
def get_text_size(self, text):
@@ -123,7 +140,18 @@
else:
self.glow2 = glow2
-
+
+ def get_style_geometry(self):
+ """
+ Return the additional pixel the font needs for the style. This function
+ will return left, top, right, bottom as number of pixels the text will
+ start to the left/top and the number of pixels it needs more at the
+ right/bottom. To avoid extra calculations the function will also return
+ the additional width and height needed for the style.
+ """
+ return TEXT_STYLE_GEOMETRY[self.style]
+
+
def __getattr__(self, attr):
"""
These attributes are available:
Modified: trunk/imlib2/src/image.py
==============================================================================
--- trunk/imlib2/src/image.py (original)
+++ trunk/imlib2/src/image.py Sat Jun 17 15:47:11 2006
@@ -34,18 +34,7 @@
import _Imlib2
from kaa.strutils import utf8
from kaa.notifier import Signal
-from font import Font
-
-TEXT_STYLE_PLAIN, \
-TEXT_STYLE_SHADOW, \
-TEXT_STYLE_OUTLINE, \
-TEXT_STYLE_SOFT_OUTLINE, \
-TEXT_STYLE_GLOW, \
-TEXT_STYLE_OUTLINE_SHADOW, \
-TEXT_STYLE_FAR_SHADOW, \
-TEXT_STYLE_OUTLINE_SOFT_SHADOW, \
-TEXT_STYLE_SOFT_SHADOW, \
-TEXT_STYLE_FAR_SOFT_SHADOW = range(10)
+from font import *
class Image(object):
"""
_______________________________________________
Freevo-cvslog mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/freevo-cvslog