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 18 19 #include <ft2build.h> 20 #include FT_INTERNAL_DEBUG_H 21 #include FT_INTERNAL_STREAM_H 22 #include FT_INTERNAL_PFR_H 23 #include "pfrdrivr.h" 24 #include "pfrobjs.h" 25 26 27 static FT_Error 28 pfr_get_kerning( PFR_Face face, 29 FT_UInt left, 30 FT_UInt right, 31 FT_Vector *avector ) 32 { 33 FT_Error error; 34 35 error = pfr_face_get_kerning( face, left, right, avector ); 36 if ( !error ) 37 { 38 PFR_PhyFont phys = &face->phy_font; 39 40 /* convert from metrics to outline units when necessary */ 41 if ( phys->outline_resolution != phys->metrics_resolution ) 42 { 43 if ( avector->x != 0 ) 44 avector->x = FT_MulDiv( avector->x, phys->outline_resolution, 45 phys->metrics_resolution ); 46 47 if ( avector->y != 0 ) 48 avector->y = FT_MulDiv( avector->x, phys->outline_resolution, 49 phys->metrics_resolution ); 50 } 51 } 52 return error; 53 } 54 55 56 static FT_Error 57 pfr_get_advance( PFR_Face face, 58 FT_UInt gindex, 59 FT_Pos *aadvance ) 60 { 61 FT_Error error = FT_Err_Bad_Argument; 62 63 *aadvance = 0; 64 if ( face ) 65 { 66 PFR_PhyFont phys = &face->phy_font; 67 68 if ( gindex < phys->num_chars ) 69 { 70 *aadvance = phys->chars[ gindex ].advance; 71 error = 0; 72 } 73 } 74 75 return error; 76 } 77 78 79 static FT_Error 80 pfr_get_metrics( PFR_Face face, 81 FT_UInt *aoutline_resolution, 82 FT_UInt *ametrics_resolution, 83 FT_Fixed *ametrics_x_scale, 84 FT_Fixed *ametrics_y_scale ) 85 { 86 PFR_PhyFont phys = &face->phy_font; 87 FT_Fixed x_scale, y_scale; 88 FT_Size size = face->root.size; 89 90 if ( aoutline_resolution ) 91 *aoutline_resolution = phys->outline_resolution; 92 93 if ( ametrics_resolution ) 94 *ametrics_resolution = phys->metrics_resolution; 95 96 x_scale = 0x10000L; 97 y_scale = 0x10000L; 98 99 if ( size ) 100 { 101 x_scale = FT_DivFix( size->metrics.x_ppem << 6, 102 phys->metrics_resolution ); 103 104 y_scale = FT_DivFix( size->metrics.y_ppem << 6, 105 phys->metrics_resolution ); 106 } 107 108 if ( ametrics_x_scale ) 109 *ametrics_x_scale = x_scale; 110 111 if ( ametrics_y_scale ) 112 *ametrics_y_scale = y_scale; 113 114 return 0; 115 } 116 117 118 FT_CALLBACK_TABLE_DEF 119 const FT_PFR_ServiceRec pfr_service_rec = 120 { 121 (FT_PFR_GetMetricsFunc) pfr_get_metrics, 122 (FT_PFR_GetKerningFunc) pfr_get_kerning, 123 (FT_PFR_GetAdvanceFunc) pfr_get_advance 124 }; 125 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 134 sizeof( FT_DriverRec ), 135 136 "pfr", 137 0x10000L, 138 0x20000L, 139 140 (FT_PFR_Service) &pfr_service_rec, /* format interface */ 141 142 (FT_Module_Constructor)NULL, 143 (FT_Module_Destructor) NULL, 144 (FT_Module_Requester) NULL 145 }, 146 147 sizeof( PFR_FaceRec ), 148 sizeof( PFR_SizeRec ), 149 sizeof( PFR_SlotRec ), 150 151 (FT_Face_InitFunc) pfr_face_init, 152 (FT_Face_DoneFunc) pfr_face_done, 153 (FT_Size_InitFunc) NULL, 154 (FT_Size_DoneFunc) NULL, 155 (FT_Slot_InitFunc) pfr_slot_init, 156 (FT_Slot_DoneFunc) pfr_slot_done, 157 158 (FT_Size_ResetPointsFunc) NULL, 159 (FT_Size_ResetPixelsFunc) NULL, 160 (FT_Slot_LoadFunc) pfr_slot_load, 161 162 (FT_Face_GetKerningFunc) pfr_get_kerning, 163 (FT_Face_AttachFunc) 0, 164 (FT_Face_GetAdvancesFunc) 0 165 }; 166 167 168 /* END */ 169