Anonymous avatar Anonymous committed 6e7e174

Added additional attribute getters to FreeType fonts.

Comments (0)

Files changed (5)

doc/src/freetypebase.xml

 
 
   <class name="Font">
-    <constructor>Font(file, size[, index]) -> Font</constructor>
+    <constructor>Font(file [, index]) -> Font</constructor>
     <desc>
         Creates a new Font from a supported font file.
 
     <attr name="style">
       <desc>Gets or sets the style of the font. *TODO*</desc>
     </attr>
+    <attr name="fixed_width">
+      <desc>Returns whether this font is a fixed-width (bitmap) font</desc>
+    </attr>
   </class>
   
 </module>

src/freetype/ft_font.c

 static int _ftfont_setstyle(PyObject *self, PyObject *value, void *closure);
 static PyObject* _ftfont_getheight(PyObject *self, void *closure);
 static PyObject* _ftfont_getname(PyObject *self, void *closure);
+static PyObject* _ftfont_getfixedwidth(PyObject *self, void *closure);
 
 /*
  * FREETYPE FONT METHODS TABLE
         DOC_BASE_FONT_NAME, 
         NULL 
     },
+    {
+        "fixed_width",
+        _ftfont_getfixedwidth,
+        NULL,
+        DOC_BASE_FONT_FIXED_WIDTH,
+        NULL
+    },
     { NULL, NULL, NULL, NULL, NULL }
 };
 
 static PyObject*
 _ftfont_repr(PyObject *self)
 {
-    /* TODO: Print actual information about the font */
-    return Text_FromUTF8("FreeType Font");
+    return Text_FromFormat("%s (FreeType %s font)", 
+            PGFT_Face_GetName((PyFreeTypeFont *)self),
+            PGFT_Face_GetFormat((PyFreeTypeFont *)self));
 }
 
 
 static PyObject*
 _ftfont_getheight(PyObject *self, void *closure)
 {
-    /* TODO */
+    return PyInt_FromLong(PGFT_Face_GetHeight((PyFreeTypeFont *)self));
 }
 
 static PyObject*
 _ftfont_getname(PyObject *self, void *closure)
 {
-    /* TODO */
+    return Text_FromUTF8(PGFT_Face_GetName((PyFreeTypeFont *)self));
+}
+
+static PyObject*
+_ftfont_getfixedwidth(PyObject *self, void *closure)
+{
+    return PyBool_FromLong(PGFT_Face_IsFixedWidth((PyFreeTypeFont *)self));
 }
 
 

src/freetype/ft_wrap.c

 }
 
 int
+PGFT_Face_IsFixedWidth(PyFreeTypeFont *font)
+{
+    return FT_IS_FIXED_WIDTH(font->face);
+}
+
+const char *
+PGFT_Face_GetName(PyFreeTypeFont *font)
+{
+    return font->face->family_name;
+}
+
+
+const char *
+PGFT_Face_GetFormat(PyFreeTypeFont *font)
+{
+    return FT_Get_X11_Font_Format(font->face);
+}
+
+
+int
+PGFT_Face_GetHeight(PyFreeTypeFont *font)
+{
+    return font->face->height;
+}
+
+
+int
 PGFT_TryLoadFont(FreeTypeInstance *ft, PyFreeTypeFont *font)
 {
     FT_Face face;
         return error;
     }
 
+    font->face = face;
     return 0;
 }
 

src/freetype/ft_wrap.h

 int     PGFT_TryLoadFont(FreeTypeInstance *, PyFreeTypeFont *);
 void    PGFT_UnloadFont(FreeTypeInstance *, PyFreeTypeFont *);
 
+int     PGFT_Face_GetHeight(PyFreeTypeFont *);
+int     PGFT_Face_IsFixedWidth(PyFreeTypeFont *);
+const char * PGFT_Face_GetName(PyFreeTypeFont *);
+const char * PGFT_Face_GetFormat(PyFreeTypeFont *);
+
 
 #endif

src/freetype/pgfreetype.h

 #include <ft2build.h>  
 #include FT_FREETYPE_H 
 #include FT_CACHE_H
+#include FT_XFREE86_H
 
 #ifdef __cplusplus
 extern "C" {
 {
     PyFont pyfont;
     FontId id;
-
+    FT_Face face;
 } PyFreeTypeFont;
 
 #define PyFreeTypeFont_AsFont(x) (((PyFreeTypeFont *)x)->font)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.