summary refs log tree commit diff
path: root/src/_ftsynth.c
diff options
context:
space:
mode:
authorWlodekM <[email protected]>2024-06-16 10:35:45 +0300
committerWlodekM <[email protected]>2024-06-16 10:35:45 +0300
commitabef6da56913f1c55528103e60a50451a39628b1 (patch)
treeb3c8092471ecbb73e568cd0d336efa0e7871ee8d /src/_ftsynth.c
initial commit
Diffstat (limited to 'src/_ftsynth.c')
-rw-r--r--src/_ftsynth.c123
1 files changed, 123 insertions, 0 deletions
diff --git a/src/_ftsynth.c b/src/_ftsynth.c
new file mode 100644
index 0000000..cd9acf8
--- /dev/null
+++ b/src/_ftsynth.c
@@ -0,0 +1,123 @@
+/***************************************************************************/
+/*                                                                         */
+/*  ftsynth.c                                                              */
+/*                                                                         */
+/*    FreeType synthesizing code for emboldening and slanting (body).      */
+/*                                                                         */
+/*  Copyright 2000-2018 by                                                 */
+/*  David Turner, Robert Wilhelm, and Werner Lemberg.                      */
+/*                                                                         */
+/*  This file is part of the FreeType project, and may only be used,       */
+/*  modified, and distributed under the terms of the FreeType project      */
+/*  license, LICENSE.TXT.  By continuing to use, modify, or distribute     */
+/*  this file you indicate that you have read the license and              */
+/*  understand and accept it fully.                                        */
+/*                                                                         */
+/***************************************************************************/
+
+#include "Core.h"
+#ifdef CC_BUILD_FREETYPE
+#include "freetype/ft2build.h"
+#include "freetype/ftsynth.h"
+#include "freetype/ftdebug.h"
+#include "freetype/ftobjs.h"
+#include "freetype/ftoutln.h"
+#include "freetype/ftbitmap.h"
+
+
+  /*************************************************************************/
+  /*                                                                       */
+  /* The macro FT_COMPONENT is used in trace mode.  It is an implicit      */
+  /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log  */
+  /* messages during execution.                                            */
+  /*                                                                       */
+#undef  FT_COMPONENT
+#define FT_COMPONENT  trace_synth
+
+
+  /*************************************************************************/
+  /*************************************************************************/
+  /****                                                                 ****/
+  /****   EXPERIMENTAL EMBOLDENING SUPPORT                              ****/
+  /****                                                                 ****/
+  /*************************************************************************/
+  /*************************************************************************/
+
+
+  /* documentation is in ftsynth.h */
+
+  FT_EXPORT_DEF( void )
+  FT_GlyphSlot_Embolden( FT_GlyphSlot  slot )
+  {
+    FT_Library  library;
+    FT_Face     face;
+    FT_Error    error;
+    FT_Pos      xstr, ystr;
+
+
+    if ( !slot )
+      return;
+
+    library = slot->library;
+    face    = slot->face;
+
+    if ( slot->format != FT_GLYPH_FORMAT_OUTLINE &&
+         slot->format != FT_GLYPH_FORMAT_BITMAP  )
+      return;
+
+    /* some reasonable strength */
+    xstr = FT_MulFix( face->units_per_EM,
+                      face->size->metrics.y_scale ) / 24;
+    ystr = xstr;
+
+    if ( slot->format == FT_GLYPH_FORMAT_OUTLINE )
+      FT_Outline_EmboldenXY( &slot->outline, xstr, ystr );
+
+    else /* slot->format == FT_GLYPH_FORMAT_BITMAP */
+    {
+      /* round to full pixels */
+      xstr &= ~63;
+      if ( xstr == 0 )
+        xstr = 1 << 6;
+      ystr &= ~63;
+
+      /*
+       * XXX: overflow check for 16-bit system, for compatibility
+       *      with FT_GlyphSlot_Embolden() since FreeType 2.1.10.
+       *      unfortunately, this function return no informations
+       *      about the cause of error.
+       */
+      if ( ( ystr >> 6 ) > FT_INT_MAX || ( ystr >> 6 ) < FT_INT_MIN )
+      {
+        FT_TRACE1(( "FT_GlyphSlot_Embolden:" ));
+        FT_TRACE1(( "too strong emboldening parameter ystr=%d\n", ystr ));
+        return;
+      }
+      error = FT_GlyphSlot_Own_Bitmap( slot );
+      if ( error )
+        return;
+
+      error = FT_Bitmap_Embolden( library, &slot->bitmap, xstr, ystr );
+      if ( error )
+        return;
+    }
+
+    if ( slot->advance.x )
+      slot->advance.x += xstr;
+
+    if ( slot->advance.y )
+      slot->advance.y += ystr;
+
+    slot->metrics.width        += xstr;
+    slot->metrics.height       += ystr;
+    slot->metrics.horiAdvance  += xstr;
+    slot->metrics.vertAdvance  += ystr;
+    slot->metrics.horiBearingY += ystr;
+
+    /* XXX: 16-bit overflow case must be excluded before here */
+    if ( slot->format == FT_GLYPH_FORMAT_BITMAP )
+      slot->bitmap_top += (FT_Int)( ystr >> 6 );
+  }
+
+#endif
+/* END */