/src/freetype/src/base/ftsynth.c

https://bitbucket.org/cabalistic/ogredeps/ · C · 160 lines · 73 code · 32 blank · 55 comment · 18 complexity · 17e264b807b479fd9a41af44ac08749e MD5 · raw file

  1. /***************************************************************************/
  2. /* */
  3. /* ftsynth.c */
  4. /* */
  5. /* FreeType synthesizing code for emboldening and slanting (body). */
  6. /* */
  7. /* Copyright 2000-2001, 2002, 2003, 2004, 2005, 2006, 2010 by */
  8. /* David Turner, Robert Wilhelm, and Werner Lemberg. */
  9. /* */
  10. /* This file is part of the FreeType project, and may only be used, */
  11. /* modified, and distributed under the terms of the FreeType project */
  12. /* license, LICENSE.TXT. By continuing to use, modify, or distribute */
  13. /* this file you indicate that you have read the license and */
  14. /* understand and accept it fully. */
  15. /* */
  16. /***************************************************************************/
  17. #include <ft2build.h>
  18. #include FT_SYNTHESIS_H
  19. #include FT_INTERNAL_DEBUG_H
  20. #include FT_INTERNAL_OBJECTS_H
  21. #include FT_OUTLINE_H
  22. #include FT_BITMAP_H
  23. /*************************************************************************/
  24. /* */
  25. /* The macro FT_COMPONENT is used in trace mode. It is an implicit */
  26. /* parameter of the FT_TRACE() and FT_ERROR() macros, used to print/log */
  27. /* messages during execution. */
  28. /* */
  29. #undef FT_COMPONENT
  30. #define FT_COMPONENT trace_synth
  31. /*************************************************************************/
  32. /*************************************************************************/
  33. /**** ****/
  34. /**** EXPERIMENTAL OBLIQUING SUPPORT ****/
  35. /**** ****/
  36. /*************************************************************************/
  37. /*************************************************************************/
  38. /* documentation is in ftsynth.h */
  39. FT_EXPORT_DEF( void )
  40. FT_GlyphSlot_Oblique( FT_GlyphSlot slot )
  41. {
  42. FT_Matrix transform;
  43. FT_Outline* outline = &slot->outline;
  44. /* only oblique outline glyphs */
  45. if ( slot->format != FT_GLYPH_FORMAT_OUTLINE )
  46. return;
  47. /* we don't touch the advance width */
  48. /* For italic, simply apply a shear transform, with an angle */
  49. /* of about 12 degrees. */
  50. transform.xx = 0x10000L;
  51. transform.yx = 0x00000L;
  52. transform.xy = 0x06000L;
  53. transform.yy = 0x10000L;
  54. FT_Outline_Transform( outline, &transform );
  55. }
  56. /*************************************************************************/
  57. /*************************************************************************/
  58. /**** ****/
  59. /**** EXPERIMENTAL EMBOLDENING/OUTLINING SUPPORT ****/
  60. /**** ****/
  61. /*************************************************************************/
  62. /*************************************************************************/
  63. /* documentation is in ftsynth.h */
  64. FT_EXPORT_DEF( void )
  65. FT_GlyphSlot_Embolden( FT_GlyphSlot slot )
  66. {
  67. FT_Library library = slot->library;
  68. FT_Face face = slot->face;
  69. FT_Error error;
  70. FT_Pos xstr, ystr;
  71. if ( slot->format != FT_GLYPH_FORMAT_OUTLINE &&
  72. slot->format != FT_GLYPH_FORMAT_BITMAP )
  73. return;
  74. /* some reasonable strength */
  75. xstr = FT_MulFix( face->units_per_EM,
  76. face->size->metrics.y_scale ) / 24;
  77. ystr = xstr;
  78. if ( slot->format == FT_GLYPH_FORMAT_OUTLINE )
  79. {
  80. /* ignore error */
  81. (void)FT_Outline_Embolden( &slot->outline, xstr );
  82. /* this is more than enough for most glyphs; if you need accurate */
  83. /* values, you have to call FT_Outline_Get_CBox */
  84. xstr = xstr * 2;
  85. ystr = xstr;
  86. }
  87. else /* slot->format == FT_GLYPH_FORMAT_BITMAP */
  88. {
  89. /* round to full pixels */
  90. xstr &= ~63;
  91. if ( xstr == 0 )
  92. xstr = 1 << 6;
  93. ystr &= ~63;
  94. /*
  95. * XXX: overflow check for 16-bit system, for compatibility
  96. * with FT_GlyphSlot_Embolden() since freetype-2.1.10.
  97. * unfortunately, this function return no informations
  98. * about the cause of error.
  99. */
  100. if ( ( ystr >> 6 ) > FT_INT_MAX || ( ystr >> 6 ) < FT_INT_MIN )
  101. {
  102. FT_TRACE1(( "FT_GlyphSlot_Embolden:" ));
  103. FT_TRACE1(( "too strong embolding parameter ystr=%d\n", ystr ));
  104. return;
  105. }
  106. error = FT_GlyphSlot_Own_Bitmap( slot );
  107. if ( error )
  108. return;
  109. error = FT_Bitmap_Embolden( library, &slot->bitmap, xstr, ystr );
  110. if ( error )
  111. return;
  112. }
  113. if ( slot->advance.x )
  114. slot->advance.x += xstr;
  115. if ( slot->advance.y )
  116. slot->advance.y += ystr;
  117. slot->metrics.width += xstr;
  118. slot->metrics.height += ystr;
  119. slot->metrics.horiBearingY += ystr;
  120. slot->metrics.horiAdvance += xstr;
  121. slot->metrics.vertBearingX -= xstr / 2;
  122. slot->metrics.vertBearingY += ystr;
  123. slot->metrics.vertAdvance += ystr;
  124. /* XXX: 16-bit overflow case must be excluded before here */
  125. if ( slot->format == FT_GLYPH_FORMAT_BITMAP )
  126. slot->bitmap_top += (FT_Int)( ystr >> 6 );
  127. }
  128. /* END */