pfrdrivr.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. /***************************************************************************/
  2. /* */
  3. /* pfrdrivr.c */
  4. /* */
  5. /* FreeType PFR driver interface (body). */
  6. /* */
  7. /* Copyright 2002 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_INTERNAL_PFR_H
  21. #include "pfrdrivr.h"
  22. #include "pfrobjs.h"
  23. static FT_Error
  24. pfr_get_kerning( PFR_Face face,
  25. FT_UInt left,
  26. FT_UInt right,
  27. FT_Vector *avector )
  28. {
  29. FT_Error error;
  30. error = pfr_face_get_kerning( face, left, right, avector );
  31. if ( !error )
  32. {
  33. PFR_PhyFont phys = &face->phy_font;
  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. }
  45. return error;
  46. }
  47. static FT_Error
  48. pfr_get_advance( PFR_Face face,
  49. FT_UInt gindex,
  50. FT_Pos *aadvance )
  51. {
  52. FT_Error error = FT_Err_Bad_Argument;
  53. *aadvance = 0;
  54. if ( face )
  55. {
  56. PFR_PhyFont phys = &face->phy_font;
  57. if ( gindex < phys->num_chars )
  58. {
  59. *aadvance = phys->chars[ gindex ].advance;
  60. error = 0;
  61. }
  62. }
  63. return error;
  64. }
  65. static FT_Error
  66. pfr_get_metrics( PFR_Face face,
  67. FT_UInt *aoutline_resolution,
  68. FT_UInt *ametrics_resolution,
  69. FT_Fixed *ametrics_x_scale,
  70. FT_Fixed *ametrics_y_scale )
  71. {
  72. PFR_PhyFont phys = &face->phy_font;
  73. FT_Fixed x_scale, y_scale;
  74. FT_Size size = face->root.size;
  75. if ( aoutline_resolution )
  76. *aoutline_resolution = phys->outline_resolution;
  77. if ( ametrics_resolution )
  78. *ametrics_resolution = phys->metrics_resolution;
  79. x_scale = 0x10000L;
  80. y_scale = 0x10000L;
  81. if ( size )
  82. {
  83. x_scale = FT_DivFix( size->metrics.x_ppem << 6,
  84. phys->metrics_resolution );
  85. y_scale = FT_DivFix( size->metrics.y_ppem << 6,
  86. phys->metrics_resolution );
  87. }
  88. if ( ametrics_x_scale )
  89. *ametrics_x_scale = x_scale;
  90. if ( ametrics_y_scale )
  91. *ametrics_y_scale = y_scale;
  92. return 0;
  93. }
  94. FT_CALLBACK_TABLE_DEF
  95. const FT_PFR_ServiceRec pfr_service_rec =
  96. {
  97. (FT_PFR_GetMetricsFunc) pfr_get_metrics,
  98. (FT_PFR_GetKerningFunc) pfr_get_kerning,
  99. (FT_PFR_GetAdvanceFunc) pfr_get_advance
  100. };
  101. FT_CALLBACK_TABLE_DEF
  102. const FT_Driver_ClassRec pfr_driver_class =
  103. {
  104. {
  105. ft_module_font_driver |
  106. ft_module_driver_scalable,
  107. sizeof( FT_DriverRec ),
  108. "pfr",
  109. 0x10000L,
  110. 0x20000L,
  111. (FT_PFR_Service) &pfr_service_rec, /* format interface */
  112. (FT_Module_Constructor)NULL,
  113. (FT_Module_Destructor) NULL,
  114. (FT_Module_Requester) NULL
  115. },
  116. sizeof( PFR_FaceRec ),
  117. sizeof( PFR_SizeRec ),
  118. sizeof( PFR_SlotRec ),
  119. (FT_Face_InitFunc) pfr_face_init,
  120. (FT_Face_DoneFunc) pfr_face_done,
  121. (FT_Size_InitFunc) NULL,
  122. (FT_Size_DoneFunc) NULL,
  123. (FT_Slot_InitFunc) pfr_slot_init,
  124. (FT_Slot_DoneFunc) pfr_slot_done,
  125. (FT_Size_ResetPointsFunc) NULL,
  126. (FT_Size_ResetPixelsFunc) NULL,
  127. (FT_Slot_LoadFunc) pfr_slot_load,
  128. (FT_Face_GetKerningFunc) pfr_get_kerning,
  129. (FT_Face_AttachFunc) 0,
  130. (FT_Face_GetAdvancesFunc) 0
  131. };
  132. /* END */