/src/freetype/src/cache/ftcimage.c

https://bitbucket.org/cabalistic/ogredeps/ · C · 163 lines · 102 code · 40 blank · 21 comment · 4 complexity · 0c8752cda9960bc8d2cb1b4b17d4ca9d MD5 · raw file

  1. /***************************************************************************/
  2. /* */
  3. /* ftcimage.c */
  4. /* */
  5. /* FreeType Image cache (body). */
  6. /* */
  7. /* Copyright 2000-2001, 2003, 2004, 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_CACHE_H
  19. #include "ftcimage.h"
  20. #include FT_INTERNAL_MEMORY_H
  21. #include "ftccback.h"
  22. #include "ftcerror.h"
  23. /* finalize a given glyph image node */
  24. FT_LOCAL_DEF( void )
  25. ftc_inode_free( FTC_Node ftcinode,
  26. FTC_Cache cache )
  27. {
  28. FTC_INode inode = (FTC_INode)ftcinode;
  29. FT_Memory memory = cache->memory;
  30. if ( inode->glyph )
  31. {
  32. FT_Done_Glyph( inode->glyph );
  33. inode->glyph = NULL;
  34. }
  35. FTC_GNode_Done( FTC_GNODE( inode ), cache );
  36. FT_FREE( inode );
  37. }
  38. FT_LOCAL_DEF( void )
  39. FTC_INode_Free( FTC_INode inode,
  40. FTC_Cache cache )
  41. {
  42. ftc_inode_free( FTC_NODE( inode ), cache );
  43. }
  44. /* initialize a new glyph image node */
  45. FT_LOCAL_DEF( FT_Error )
  46. FTC_INode_New( FTC_INode *pinode,
  47. FTC_GQuery gquery,
  48. FTC_Cache cache )
  49. {
  50. FT_Memory memory = cache->memory;
  51. FT_Error error;
  52. FTC_INode inode = NULL;
  53. if ( !FT_NEW( inode ) )
  54. {
  55. FTC_GNode gnode = FTC_GNODE( inode );
  56. FTC_Family family = gquery->family;
  57. FT_UInt gindex = gquery->gindex;
  58. FTC_IFamilyClass clazz = FTC_CACHE__IFAMILY_CLASS( cache );
  59. /* initialize its inner fields */
  60. FTC_GNode_Init( gnode, gindex, family );
  61. /* we will now load the glyph image */
  62. error = clazz->family_load_glyph( family, gindex, cache,
  63. &inode->glyph );
  64. if ( error )
  65. {
  66. FTC_INode_Free( inode, cache );
  67. inode = NULL;
  68. }
  69. }
  70. *pinode = inode;
  71. return error;
  72. }
  73. FT_LOCAL_DEF( FT_Error )
  74. ftc_inode_new( FTC_Node *ftcpinode,
  75. FT_Pointer ftcgquery,
  76. FTC_Cache cache )
  77. {
  78. FTC_INode *pinode = (FTC_INode*)ftcpinode;
  79. FTC_GQuery gquery = (FTC_GQuery)ftcgquery;
  80. return FTC_INode_New( pinode, gquery, cache );
  81. }
  82. FT_LOCAL_DEF( FT_Offset )
  83. ftc_inode_weight( FTC_Node ftcinode,
  84. FTC_Cache ftccache )
  85. {
  86. FTC_INode inode = (FTC_INode)ftcinode;
  87. FT_Offset size = 0;
  88. FT_Glyph glyph = inode->glyph;
  89. FT_UNUSED( ftccache );
  90. switch ( glyph->format )
  91. {
  92. case FT_GLYPH_FORMAT_BITMAP:
  93. {
  94. FT_BitmapGlyph bitg;
  95. bitg = (FT_BitmapGlyph)glyph;
  96. size = bitg->bitmap.rows * ft_labs( bitg->bitmap.pitch ) +
  97. sizeof ( *bitg );
  98. }
  99. break;
  100. case FT_GLYPH_FORMAT_OUTLINE:
  101. {
  102. FT_OutlineGlyph outg;
  103. outg = (FT_OutlineGlyph)glyph;
  104. size = outg->outline.n_points *
  105. ( sizeof ( FT_Vector ) + sizeof ( FT_Byte ) ) +
  106. outg->outline.n_contours * sizeof ( FT_Short ) +
  107. sizeof ( *outg );
  108. }
  109. break;
  110. default:
  111. ;
  112. }
  113. size += sizeof ( *inode );
  114. return size;
  115. }
  116. #if 0
  117. FT_LOCAL_DEF( FT_Offset )
  118. FTC_INode_Weight( FTC_INode inode )
  119. {
  120. return ftc_inode_weight( FTC_NODE( inode ), NULL );
  121. }
  122. #endif /* 0 */
  123. /* END */