/modules/freetype2/src/pfr/pfrdrivr.c

http://github.com/zpao/v8monkey · C · 214 lines · 136 code · 52 blank · 26 comment · 14 complexity · 4b711ff01becb10320088b9422590bf2 MD5 · raw file

  1. /***************************************************************************/
  2. /* */
  3. /* pfrdrivr.c */
  4. /* */
  5. /* FreeType PFR driver interface (body). */
  6. /* */
  7. /* Copyright 2002, 2003, 2004, 2006, 2008, 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_INTERNAL_DEBUG_H
  19. #include FT_INTERNAL_STREAM_H
  20. #include FT_SERVICE_PFR_H
  21. #include FT_SERVICE_XFREE86_NAME_H
  22. #include "pfrdrivr.h"
  23. #include "pfrobjs.h"
  24. #include "pfrerror.h"
  25. FT_CALLBACK_DEF( FT_Error )
  26. pfr_get_kerning( FT_Face pfrface, /* PFR_Face */
  27. FT_UInt left,
  28. FT_UInt right,
  29. FT_Vector *avector )
  30. {
  31. PFR_Face face = (PFR_Face)pfrface;
  32. PFR_PhyFont phys = &face->phy_font;
  33. pfr_face_get_kerning( pfrface, left, right, avector );
  34. /* convert from metrics to outline units when necessary */
  35. if ( phys->outline_resolution != phys->metrics_resolution )
  36. {
  37. if ( avector->x != 0 )
  38. avector->x = FT_MulDiv( avector->x, phys->outline_resolution,
  39. phys->metrics_resolution );
  40. if ( avector->y != 0 )
  41. avector->y = FT_MulDiv( avector->x, phys->outline_resolution,
  42. phys->metrics_resolution );
  43. }
  44. return PFR_Err_Ok;
  45. }
  46. /*
  47. * PFR METRICS SERVICE
  48. *
  49. */
  50. FT_CALLBACK_DEF( FT_Error )
  51. pfr_get_advance( FT_Face pfrface, /* PFR_Face */
  52. FT_UInt gindex,
  53. FT_Pos *anadvance )
  54. {
  55. PFR_Face face = (PFR_Face)pfrface;
  56. FT_Error error = PFR_Err_Invalid_Argument;
  57. *anadvance = 0;
  58. if ( !gindex )
  59. goto Exit;
  60. gindex--;
  61. if ( face )
  62. {
  63. PFR_PhyFont phys = &face->phy_font;
  64. if ( gindex < phys->num_chars )
  65. {
  66. *anadvance = phys->chars[gindex].advance;
  67. error = PFR_Err_Ok;
  68. }
  69. }
  70. Exit:
  71. return error;
  72. }
  73. FT_CALLBACK_DEF( FT_Error )
  74. pfr_get_metrics( FT_Face pfrface, /* PFR_Face */
  75. FT_UInt *anoutline_resolution,
  76. FT_UInt *ametrics_resolution,
  77. FT_Fixed *ametrics_x_scale,
  78. FT_Fixed *ametrics_y_scale )
  79. {
  80. PFR_Face face = (PFR_Face)pfrface;
  81. PFR_PhyFont phys = &face->phy_font;
  82. FT_Fixed x_scale, y_scale;
  83. FT_Size size = face->root.size;
  84. if ( anoutline_resolution )
  85. *anoutline_resolution = phys->outline_resolution;
  86. if ( ametrics_resolution )
  87. *ametrics_resolution = phys->metrics_resolution;
  88. x_scale = 0x10000L;
  89. y_scale = 0x10000L;
  90. if ( size )
  91. {
  92. x_scale = FT_DivFix( size->metrics.x_ppem << 6,
  93. phys->metrics_resolution );
  94. y_scale = FT_DivFix( size->metrics.y_ppem << 6,
  95. phys->metrics_resolution );
  96. }
  97. if ( ametrics_x_scale )
  98. *ametrics_x_scale = x_scale;
  99. if ( ametrics_y_scale )
  100. *ametrics_y_scale = y_scale;
  101. return PFR_Err_Ok;
  102. }
  103. FT_CALLBACK_TABLE_DEF
  104. const FT_Service_PfrMetricsRec pfr_metrics_service_rec =
  105. {
  106. pfr_get_metrics,
  107. pfr_face_get_kerning,
  108. pfr_get_advance
  109. };
  110. /*
  111. * SERVICE LIST
  112. *
  113. */
  114. static const FT_ServiceDescRec pfr_services[] =
  115. {
  116. { FT_SERVICE_ID_PFR_METRICS, &pfr_metrics_service_rec },
  117. { FT_SERVICE_ID_XF86_NAME, FT_XF86_FORMAT_PFR },
  118. { NULL, NULL }
  119. };
  120. FT_CALLBACK_DEF( FT_Module_Interface )
  121. pfr_get_service( FT_Module module,
  122. const FT_String* service_id )
  123. {
  124. FT_UNUSED( module );
  125. return ft_service_list_lookup( pfr_services, service_id );
  126. }
  127. FT_CALLBACK_TABLE_DEF
  128. const FT_Driver_ClassRec pfr_driver_class =
  129. {
  130. {
  131. FT_MODULE_FONT_DRIVER |
  132. FT_MODULE_DRIVER_SCALABLE,
  133. sizeof( FT_DriverRec ),
  134. "pfr",
  135. 0x10000L,
  136. 0x20000L,
  137. NULL,
  138. 0,
  139. 0,
  140. pfr_get_service
  141. },
  142. sizeof( PFR_FaceRec ),
  143. sizeof( PFR_SizeRec ),
  144. sizeof( PFR_SlotRec ),
  145. pfr_face_init,
  146. pfr_face_done,
  147. 0, /* FT_Size_InitFunc */
  148. 0, /* FT_Size_DoneFunc */
  149. pfr_slot_init,
  150. pfr_slot_done,
  151. #ifdef FT_CONFIG_OPTION_OLD_INTERNALS
  152. ft_stub_set_char_sizes,
  153. ft_stub_set_pixel_sizes,
  154. #endif
  155. pfr_slot_load,
  156. pfr_get_kerning,
  157. 0, /* FT_Face_AttachFunc */
  158. 0, /* FT_Face_GetAdvancesFunc */
  159. 0, /* FT_Size_RequestFunc */
  160. 0, /* FT_Size_SelectFunc */
  161. };
  162. /* END */