Commits

tanoku  committed 1439c9a

WIP support for text styles

  • Participants
  • Parent commits 053e9bf
  • Branches pgreloaded

Comments (0)

Files changed (4)

File examples/freetype/sdlfont.py

     font.render("or BLAND!", pygame2.Color(0, 0xCC, 28, 128), None, screen, 258, 237, ptsize=64)
     font.render("I \u2665 Unicode", pygame2.Color(0, 0xCC, 0xDD), None, screen, 298, 320, ptsize=64)
     font.render("\u2665", colors["grey_light"], colors["red"], screen, 480, 32, ptsize=148)
-    font.render("...yes, this is a SDL surface", pygame2.Color(0, 0, 0), None, screen, 380, 380, ptsize=24)
+    font.render("...yes, this is a SDL surface", pygame2.Color(0, 0, 0), None, screen, 380, 380, ptsize=24, style=ftconstants.STYLE_BOLD)
 
 
     screen.flip ()

File src/freetype/ft_render.c

 #   include "surface.h"
 #endif
 
+#define BOLD_FACTOR     0.08
+#define SLANT_FACTOR    0.22
+
 typedef void (* FontRenderPtr)(int, int, FontSurface *, FT_Bitmap *, PyColor *);
 
 /* blitters */
     FT_Face     face;
     FT_Error    error;
 
+    FT_Fixed    bold_str;
+    FT_Matrix   shear_matrix;
+
     int         x = (surface->x_offset << 6);
     int         y = (surface->y_offset << 6);
 
         pen.y = PGFT_ROUND(y - pen.y);
     }
 
+    /******************************************************
+     * Prepare data for glyph transformations
+     ******************************************************/
+
+    if (render->style & FT_STYLE_ITALIC)
+    {
+        shear_matrix.xx = (1<< 16);
+        shear_matrix.xy = (FT_Fixed)(SLANT_FACTOR * (1 << 16));
+        shear_matrix.yx = 0;
+        shear_matrix.yy = (1 << 16);
+    }
+
+    if (render->style & FT_STYLE_BOLD)
+    {
+        bold_str = FT_MulFix(face->units_per_EM, face->size->metrics.y_scale);
+        bold_str = (FT_Fixed)(bold_str * BOLD_FACTOR);
+    }
 
     /******************************************************
      * Draw text
         if (error)
             continue;
 
-        if (image->format != FT_GLYPH_FORMAT_BITMAP)
+        if (image->format == FT_GLYPH_FORMAT_OUTLINE)
         {
+            if (render->style & FT_STYLE_BOLD)
+            {
+                FT_OutlineGlyph outline;
+                outline = (FT_OutlineGlyph)image;
+                FT_Outline_Embolden(&(outline->outline), bold_str);
+            }
+
+            if (render->style & FT_STYLE_ITALIC)
+            {
+                FT_OutlineGlyph outline;
+                outline = (FT_OutlineGlyph)image;
+                FT_Outline_Transform(&(outline->outline), &shear_matrix);
+            }
+
             if (render->vertical)
                 error = FT_Glyph_Transform(image, NULL, &glyph->vvector);
 

File src/freetype/ft_style.c

 #include FT_MODULE_H
 #include FT_OUTLINE_H 
  
+
 #define BOLD_FACTOR     0.08
 #define SLANT_FACTOR    0.22
 
     slot->metrics.vertAdvance  += ystr;
     return 0;
 }
+
+

File src/freetype/ft_text.c

         {
             FT_Glyph_Metrics *metrics = &face->glyph->metrics;
 
-            if (render->style & FT_STYLE_BOLD)
-            {
-                PGFT_Style_MakeBold(face);
-            }
 
             /* note that in vertical layout, y-positive goes downwards */
             glyph->vvector.x  = metrics->vertBearingX - metrics->horiBearingX;