Commits

Anonymous committed 8625d94

Added pygame2.freetype C API documentation. Added MacOS X font initialization. Removed physics leftovers.

Comments (0)

Files changed (8)

doc/MODULE_FAQ.txt

   +----------------+--------------------------------------------+
   | ADD_LIMIT(x,y) | Variable addition using overflow limits    |
   +----------------+--------------------------------------------+
-  |SUB_LIMIT(x,y)  | variable subtraction using overflow limits |
+  | SUB_LIMIT(x,y) | variable subtraction using overflow limits |
   +----------------+--------------------------------------------+
 
 Besides that it contains various ready-to-use macros for signed/unsigned
 .. toctree::
 
   capi/base.rst
+  capi/freetype.rst
   capi/mask.rst
   capi/sdlbase.rst
   capi/sdlcdrom.rst
   capi/sdlext.rst
   capi/sdlgfx.rst
   capi/sdlttf.rst
-

doc/capi/base.rst

   *func* is the unlock func to release any pending locks and references on the
   buffered object. On failure, this returns NULL.
 
+PyFont
+------
+.. ctype:: PyFont
+.. ctype:: PyFont_Type
+
+The PyFont object an abstract base class, to be used by inheriting classes
+and other interfaces, so it is guaranteed that font-like objects contain a
+set of same attributes and methods.
+
+Members
+^^^^^^^
+PyFont only defines a set of function pointer bindings to access and set by
+inheriting classes and interfaces. Those are
+
+.. cfunction:: PyObject* (*get_height) (PyObject *self, void *closure)
+
+  Gets the height of the :ctype:`PyFont` instance. *self* is the
+  :ctype:`PyFont` itself, the *closure* argument is the same as for the
+  Python C API getter definition.
+
+.. cfunction:: PyObject* (*get_name) (PyObject *self, void *closure)
+
+  Gets the name of the :ctype:`PyFont` instance. *self* is the :ctype:`PyFont`
+  itself, the *closure* argument is the same as for the Python C API
+  getter definition.
+
+.. cfunction:: PyObject* (*get_style) (PyObject *self, void *closure)
+
+  Gets the currently applied style of the :ctype:`PyFont`
+  instance. *self* is the :ctype:`PyFont` itself, the *closure* argument
+  is the same as for the Python C API getter definition.
+
+.. cfunction:: int (*set_style) (PyObject *self, PyObject *attr, void *closure)
+
+  Applies a style to the :ctype:`PyFont` instance. *self* is the
+  :ctype:`PyFont` itself, *attr* the style to apply, the *closure*
+  argument is the same as for the Python C API getter definition.
+
+.. cfunction:: PyObject* (*get_size) (PyObject *self, PyObject *args, PyObject *kwds)
+
+  Gets the size of the :ctype:`PyFont` instance. *self* is the
+  :ctype:`PyFont` itself, the *closure* argument is the same as for the
+  Python C API getter definition.
+
+.. cfunction:: PyObject* (*render) (PyObject *self, PyObject *args, PyObject *kwds)
+
+  Renders the :ctype:`PyFont` onto some :ctype:`PySurface` or whatever
+  is appropriate for the concrete implementation. *self* is the
+  :ctype:`PyFont` itself, the *args* and *kwds* arguments are the same as for
+  the Python C API method definition.
+
+.. cfunction:: PyObject* (*copy) (PyObject *self);
+
+  Creates an exact copy of the :ctype:`PyFont`. *self* is the
+  :ctype:`PyFont` itself.
+
+Functions
+^^^^^^^^^
+
+.. cfunction:: int PyFont_Check (PyObject *obj)
+
+  Returns true, if the argument is a :ctype:`PyFont` or a subclass of
+  :ctype:`PyFont`.
+
+.. cfunction:: PyObject* PyFont_New (void)
+
+  Creates a new, empty :ctype:`PyFont` object, which's members are set to
+  NULL. On failure, this returns NULL.
+
+
 PySurface
 ---------
 .. ctype:: PySurface
 .. ctype:: PySurface_Type
 
-The PySurface object is some sort of abstract base class, to be used by
-inheriting classes and other interfaces, so it is guaranteed that surface-like
-objects contain a set of same attributes and methods.
+The PySurface object an abstract base class, to be used by inheriting classes
+and other interfaces, so it is guaranteed that surface-like objects contain a
+set of same attributes and methods.
 
 Members
 ^^^^^^^

doc/capi/freetype.rst

+================
+pygame2.freetype
+================
+
+The :mod:`pygame2.freetype` C API contains some objects and functions for
+high-quality font, glyph and text operations.
+
+Import
+------
+Include headers::
+
+  pygame2/pgfreetype.h
+
+.. cfunction:: int import_pygame2_freetype (void)
+
+  Imports the :mod:`pygame2.freetype` module. This returns 0 on success and
+  -1 on failure.
+
+Basic Types
+-----------
+
+.. ctype:: FontId
+
+  A simple font face information structure.
+
+  .. cmember:: int FontId.face_index
+  
+    The index number of the font face within the font.
+
+  .. cmember:: FT_Open_Args FontId.open_args
+
+    The arguments used to open the face.
+
+PyFreeTypeFont
+--------------
+
+.. ctype:: PyFreeTypeFont
+.. ctype:: PyFreeTypeFont_Type
+
+The PyFreeTypeFont object is suitable for creating and managing fonts, glyph
+and text operations and text rendering.
+
+Members
+^^^^^^^
+.. cmember:: PyFont PyFreeTypeFont.pyfont
+
+  The parent :ctype:`PyFont` class the PyFreeTypeFont inherits from.
+
+.. cmember:: FontId PyFreeTypeFont.id
+
+  The used font face information.
+
+.. cmember:: FT_Int16 PyFreeTypeFont.ptsize
+
+  The default font size (height) in points.
+
+.. cmember:: FT_Byte PyFreeTypeFont.style
+
+  The default font style to apply.
+  
+.. cmember:: FT_Byte PyFreeTypeFont.vertical
+
+  Indicates, whether operations should use a vertical alignment.
+
+.. cmember:: FT_Byte PyFreeTypeFont.antialias
+
+  Indicates, whether operations should use antialiasing.
+
+Functions
+^^^^^^^^^
+
+.. cfunction:: PyFont* PyFreeTypeFont_AsFont (PyObject *obj)
+
+  Macro for accessing the *pyfont* member of the :ctype:`PyFreeTypeFont`.
+  
+  This does not perform any type or argument checks.
+
+.. cfunction:: int PyFreeTypeFont_Check (PyObject *obj)
+
+  Returns true, if the argument is a :ctype:`PyFreeTypeFont` or a subclass of
+  :ctype:`PyFreeTypeFont`.
+
+.. cfunction:: PyObject* PyFreeTypeFont_New (const char *font, int ptsize)
+
+  Creates a new :ctype:`PyFreeTypeFont` object for the given *font* and
+  default point size *ptsize*. On failure, this returns NULL.

doc/capi/sdlttf.rst

   not, this will set a :exc:`PyExc_PyGameError` and return *retval*.
 
 
-PyFont
-------
-.. ctype:: PyFont
-.. ctype:: PyFont_Type
+PySDLFont_TTF
+-------------
+.. ctype:: PySDLFont_TTF
+.. ctype:: PySDLFont_TTF_Type
 
-The PyFont object is used for rendering text to a :ctype:`PySDLSurface`.
+The PySDLFont_TTF object is used for rendering text to a :ctype:`PySDLSurface`.
 
 Members
 ^^^^^^^
-.. cmember:: TTF_Font* PyFont.font
+.. cmember:: PyFont PySDLFont_TTF.pyfont
+
+  The parent :ctype:`PyFont` class the PySDLFont_TTF inherits from.
+
+.. cmember:: TTF_Font* PySDLFont_TTF.font
 
   The TTF_Font pointer to access the underlying font.
 
 Functions
 ^^^^^^^^^^
-.. cfunction:: int PyFont_Check (PyObject *obj)
+.. cfunction:: int PySDLFont_TTF_Check (PyObject *obj)
 
-  Returns true, if the argument is a :ctype:`PyFont` or a subclass of
-  :ctype:`PyFont`.
+  Returns true, if the argument is a :ctype:`PySDLFont_TTF` or a subclass of
+  :ctype:`PySDLFont_TTF`.
 
-.. cfunction:: PyObject* PyFont_New (char *filename, int ptsize)
+.. cfunction:: PyObject* PySDLFont_TTF_New (char *filename, int ptsize)
 
-  Creates a new :ctype:`PyFont` object from the passed TrueType font
+  Creates a new :ctype:`PySDLFont_TTF` object from the passed TrueType font
   file. *ptsize* specifies the font size (height) in points. On failure,
   this returns NULL.
 
-.. cfunction:: TTF_Font* PyFont_AsFont (PyObject *obj)
+.. cfunction:: TTF_Font* PySDLFont_TTF_AsFont (PyObject *obj)
 
   Macro for accessing the *font* member of the :ctype:`PyFont`. This
   does not perform any type or argument checks.

examples/physics/__init__.py

-"""Examples for pygame2.physics."""

examples/physics/simple.py

-import sys
-import pygame2
-import pygame2.physics as physics
-
-try:
-    import pygame2.sdl.constants as sdlconst
-    import pygame2.sdl.event as event
-    import pygame2.sdl.video as video
-    import pygame2.sdl.image as image
-    import pygame2.sdl.time as time
-    import pygame2.sdl.wm as wm
-    import pygame2.sdlext.draw as draw
-except ImportError:
-    print ("No pygame2.sdl support")
-    sys.exit ()
-
-white = pygame2.Color (255, 255, 255)
-black = pygame2.Color (0, 0, 0)
-
-def render_body (screen, body):
-    points = body.get_points ()
-    draw.polygon (screen, white, points, 1)
-
-def init_world ():
-    world = None
-    world = physics.World ()
-    world.gravity = 0, 1
-    
-    for i in range(1, 2):
-        shape = physics.RectShape ((0, 0, 30, 28))
-        body = physics.Body (shape)
-        body.position = 400, 100 + 40 * i
-        body.rotation = 33 * i
-        body.restitution = 0.0
-        body.mass = 20
-        world.add_body (body)
-    
-    shape = physics.RectShape ((0, 0, 760, 20))
-    base = physics.Body (shape)
-    base.position = 20, 300
-    base.restitution = 0.0
-    base.rotation = 15
-    base.static = True
-    base.mass = 1e100
-
-    world.add_body (base)
-    return world
-
-def run ():
-    video.init ()
-    time.init ()
-    
-    world = init_world ()
-    
-    screen = video.set_mode (800, 600)
-    screen.fill (black)
-    screen.flip ()
-
-    okay = True
-    while okay:
-        for ev in event.get ():
-            if ev.type == sdlconst.QUIT:
-               okay = False 
-            if ev.type == sdlconst.KEYDOWN and ev.key == sdlconst.K_ESCAPE:
-                okay = False
-            screen.flip ()
-        world.update (.2)
-        time.delay (10)
-        screen.fill (black)
-        for body in world.bodies:
-            render_body (screen, body)
-        screen.flip ()
-
-if __name__ == "__main__":
-    run ()
     ('batang.ttc', 'Batang', False, False),
     ]
 
+_osx_font_files = {
+    'albayan': {(False, False): '/Library/Fonts/AlBayan.ttf',
+                (True, False): '/Library/Fonts/AlBayanBold.ttf'},
+    'andalemono': {(False, False): '/Library/Fonts/Andale Mono.ttf'},
+    'applebraille': {(False, False): '/System/Library/Fonts/Apple Braille Outline 6 Dot.ttf'},
+    'applegothic': {(False, False): '/System/Library/Fonts/AppleGothic.ttf'},
+    'applesymbols': {(False, False): '/System/Library/Fonts/Apple Symbols.ttf'},
+    'arial': {(False, False): '/Library/Fonts/Arial.ttf',
+              (False, True): '/Library/Fonts/Arial Italic.ttf',
+              (True, False): '/Library/Fonts/Arial Bold.ttf',
+              (True, True): '/Library/Fonts/Arial Bold Italic.ttf'},
+    'arialblack': {(False, False): '/Library/Fonts/Arial Black.ttf'},
+    'arialhebrew': {(False, False): '/Library/Fonts/ArialHB.ttf',
+                    (True, False): '/Library/Fonts/ArialHBBold.ttf'},
+    'arialnarrow': {(False, False): '/Library/Fonts/Arial Narrow.ttf',
+                    (False, True): '/Library/Fonts/Arial Narrow Italic.ttf',
+                    (True, False): '/Library/Fonts/Arial Narrow Bold.ttf',
+                    (True, True): '/Library/Fonts/Arial Narrow Bold Italic.ttf'},
+    'arialroundedmtbold': {(False, False): '/Library/Fonts/Arial Rounded Bold.ttf'},
+    'arialunicodems': {(False, False): '/Library/Fonts/Arial Unicode.ttf'},
+    'ayuthaya': {(False, False): '/Library/Fonts/Ayuthaya.ttf'},
+    'baghdad': {(False, False): '/Library/Fonts/Baghdad.ttf'},
+    'brushscriptmt': {(False, True): '/Library/Fonts/Brush Script.ttf'},
+    'chalkboard': {(False, False): '/Library/Fonts/Chalkboard.ttf',
+                   (True, False): '/Library/Fonts/ChalkboardBold.ttf'},
+    'comicsansms': {(False, False): '/Library/Fonts/Comic Sans MS.ttf',
+                    (True, False): '/Library/Fonts/Comic Sans MS Bold.ttf'},
+    'corsivahebrew': {(False, False): '/Library/Fonts/Corsiva.ttf',
+                      (True, False): '/Library/Fonts/CorsivaBold.ttf'},
+    'couriernew': {(False, False): '/Library/Fonts/Courier New.ttf',
+                   (False, True): '/Library/Fonts/Courier New Italic.ttf',
+                   (True, False): '/Library/Fonts/Courier New Bold.ttf',
+                   (True, True): '/Library/Fonts/Courier New Bold Italic.ttf'},
+    'decotypenaskh': {(False, False): '/Library/Fonts/DecoTypeNaskh.ttf'},
+    'devanagarimt': {(False, False): '/Library/Fonts/DevanagariMT.ttf',
+                     (True, False): '/Library/Fonts/DevanagariMTBold.ttf'},
+    'euphemiaucas': {(False, False): '/Library/Fonts/EuphemiaCASRegular.ttf',
+                     (False, True): '/Library/Fonts/EuphemiaCASItalic.ttf',
+                     (True, False): '/Library/Fonts/EuphemiaCASBold.ttf'},
+    'gb18030bitmap': {(False, False): '/Library/Fonts/NISC18030.ttf'},
+    'geezapro': {(False, False): '/System/Library/Fonts/Geeza Pro.ttf',
+                 (True, False): '/System/Library/Fonts/Geeza Pro Bold.ttf'},
+    'georgia': {(False, False): '/Library/Fonts/Georgia.ttf',
+                (False, True): '/Library/Fonts/Georgia Italic.ttf',
+                (True, False): '/Library/Fonts/Georgia Bold.ttf',
+                (True, True): '/Library/Fonts/Georgia Bold Italic.ttf'},
+    'gujaratimt': {(False, False): '/Library/Fonts/GujaratiMT.ttf',
+                   (True, False): '/Library/Fonts/GujaratiMTBold.ttf'},
+    'gurmukhimt': {(False, False): '/Library/Fonts/Gurmukhi.ttf'},
+    'impact': {(False, False): '/Library/Fonts/Impact.ttf'},
+    'inaimathi': {(False, False): '/Library/Fonts/InaiMathi.ttf'},
+    'kailasa': {(False, False): '/Library/Fonts/Kailasa.ttf'},
+    'kokonor': {(False, False): '/Library/Fonts/Kokonor.ttf'},
+    'krungthep': {(False, False): '/Library/Fonts/Krungthep.ttf'},
+    'kufistandardgk': {(False, False): '/Library/Fonts/KufiStandardGK.ttf'},
+    'liheipro': {(False, False): '/System/Library/Fonts/ Pro.ttf'},
+    'lisongpro': {(False, False): '/Library/Fonts/ Pro.ttf'},
+    'microsoftsansserif': {(False, False): '/Library/Fonts/Microsoft Sans Serif.ttf'},
+    'mshtakan': {(False, False): '/Library/Fonts/MshtakanRegular.ttf',
+                 (False, True): '/Library/Fonts/MshtakanOblique.ttf',
+                 (True, False): '/Library/Fonts/MshtakanBold.ttf',
+                 (True, True): '/Library/Fonts/MshtakanBoldOblique.ttf'},
+    'nadeem': {(False, False): '/Library/Fonts/Nadeem.ttf'},
+    'newpeninimmt': {(False, False): '/Library/Fonts/NewPeninimMT.ttf',
+                     (True, False): '/Library/Fonts/NewPeninimMTBoldInclined.ttf'},
+    'plantagenetcherokee': {(False, False): '/Library/Fonts/PlantagenetCherokee.ttf'},
+    'raanana': {(False, False): '/Library/Fonts/Raanana.ttf',
+                (True, False): '/Library/Fonts/RaananaBold.ttf'},
+    'sathu': {(False, False): '/Library/Fonts/Sathu.ttf'},
+    'silom': {(False, False): '/Library/Fonts/Silom.ttf'},
+    'stfangsong': {(False, False): '/Library/Fonts/.ttf'},
+    'stheiti': {(False, False): '/System/Library/Fonts/.ttf'},
+    'stkaiti': {(False, False): '/Library/Fonts/.ttf'},
+    'stsong': {(False, False): '/Library/Fonts/.ttf'},
+    'tahoma': {(False, False): '/Library/Fonts/Tahoma.ttf',
+               (True, False): '/Library/Fonts/Tahoma Bold.ttf'},
+    'thonburi': {(False, False): '/System/Library/Fonts/Thonburi.ttf',
+                 (True, False): '/System/Library/Fonts/ThonburiBold.ttf'},
+    'timesnewroman': {(False, False): '/Library/Fonts/Times New Roman.ttf',
+                      (False, True): '/Library/Fonts/Times New Roman Italic.ttf',
+                      (True, False): '/Library/Fonts/Times New Roman Bold.ttf',
+                      (True, True): '/Library/Fonts/Times New Roman Bold Italic.ttf'},
+    'trebuchetms': {(False, False): '/Library/Fonts/Trebuchet MS.ttf',
+                    (False, True): '/Library/Fonts/Trebuchet MS Italic.ttf',
+                    (True, False): '/Library/Fonts/Trebuchet MS Bold.ttf',
+                    (True, True): '/Library/Fonts/Trebuchet MS Bold Italic.ttf'},
+    'verdana': {(False, False): '/Library/Fonts/Verdana.ttf',
+                (False, True): '/Library/Fonts/Verdana Italic.ttf',
+                (True, False): '/Library/Fonts/Verdana Bold.ttf',
+                (True, True): '/Library/Fonts/Verdana Bold Italic.ttf'},
+    'webdings': {(False, False): '/Library/Fonts/Webdings.ttf'},
+    'wingdings': {(False, False): '/Library/Fonts/Wingdings.ttf'},
+    'wingdings2': {(False, False): '/Library/Fonts/Wingdings 2.ttf'},
+    'wingdings3': {(False, False): '/Library/Fonts/Wingdings 3.ttf'}
+} 
+
 def _simplename (name):
     """_simplename (name) -> str
 
             if name.find ("(") != -1:
                 name = name[:name.find ("(")].rstrip ()
             name = name.lower ()
+            bold = " bold" in name # The whitespace is important!
+            italic = " italic" in name # The whitespace is important!
+            ftype = _gettype (font)
+            _addfont (font, name, ftype, "", bold, italic)
+
+def _initdarwin ():
+    """_initdarwin () -> None
+    
+    Initializes the darwin-based font cache.
+    """
+    if os.path.exists("/usr/X11/bin/fc-list"):
+        _initunix()
+    for name, details in _osx_font_files.items ():
+        for k, apath in details.items ():
+            if os.path.exists (apath):
+                bold, italic = k
+                ftype = _gettype (font)
+                _addfont(apath, name, dtype, "", bold, italic) 
 
 def _initunix ():
     """_initunix () -> None
     if sys.platform == "win32":
         _initwin32 ()
     elif sys.platform == "darwin":
-        # TODO
-        pass
+        _initdarwin ()
     else:
         _initunix ()