@@ -94,28 +94,36 @@ SGenum SG_EXPORT sgmFontsFaceCreate(void** face, SGStream* stream)
9494 return SG_UNKNOWN_ERROR ;
9595 return SG_OK ;
9696}
97- SGuint SG_EXPORT sgmFontsFaceDestroy (void * face )
97+ SGenum SG_EXPORT sgmFontsFaceDestroy (void * face )
9898{
9999 if (face == NULL )
100100 return SG_OK ; // SG_INVALID_VALUE
101101 FT_Done_Face (((FontFace * )face )-> ftface );
102102 free (face );
103103 return SG_OK ;
104104}
105- SGuint SG_EXPORT sgmFontsFaceSetHeight (void * face , float height )
105+
106+ SGenum SG_EXPORT sgmFontsFaceSetHeight (void * face , float height , SGuint dpi )
106107{
107108 if (face == NULL )
108109 return SG_OK ; // SG_INVALID_VALUE
109110 ((FontFace * )face )-> height = height ;
110- FT_Set_Char_Size (((FontFace * )face )-> ftface , (SGuint )(height * 64 ), (SGuint )(height * 64 ), 72 , 72 );
111+ FT_Set_Char_Size (((FontFace * )face )-> ftface , (SGuint )(height * 64 ), (SGuint )(height * 64 ), dpi , dpi );
111112 return SG_OK ;
112113}
113- /*SGuint SG_EXPORT sgmFontsFaceGetHeight (void* face, float* height )
114+ SGenum SG_EXPORT sgmFontsFaceGetMetrics (void * face , float * ascent , float * descent , float * linegap )
114115{
115- *height = ((FontFace*)face)->height;
116+ if (!face ) return SG_INVALID_VALUE ;
117+ FontFace * fface = face ;
118+
119+ * ascent = fface -> ftface -> size -> metrics .ascender / 64.0 ;
120+ * descent = fface -> ftface -> size -> metrics .descender / 64.0 ;
121+ * linegap = fface -> ftface -> size -> metrics .height / 64.0 + * descent - * ascent ;
122+
116123 return SG_OK ;
117- }*/
118- SGuint SG_EXPORT sgmFontsCharsCreate (void * face , SGuint * chars , SGuint charnum , float * width , float * height , float * prex , float * prey , float * postx , float * posty , SGuint * datawidth , SGuint * dataheight , void * * data )
124+ }
125+
126+ SGenum SG_EXPORT sgmFontsCharsCreate (void * face , const SGdchar * chars , size_t numchars , float * width , float * height , float * prex , float * prey , float * postx , float * posty , size_t * datawidth , size_t * dataheight , void * * data )
119127{
120128 if (face == NULL )
121129 {
@@ -137,8 +145,8 @@ SGuint SG_EXPORT sgmFontsCharsCreate(void* face, SGuint* chars, SGuint charnum,
137145 FT_Glyph glyph ;
138146 FT_BitmapGlyph bitmap_glyph ;
139147 FT_Bitmap bitmap ;
140- SGuint i /*, j*/ ;
141- for (i = 0 ; i < charnum ; i ++ )
148+ SGuint i ;
149+ for (i = 0 ; i < numchars ; i ++ )
142150 {
143151 ret = FT_Load_Glyph (fface -> ftface , FT_Get_Char_Index (fface -> ftface , chars [i ]), FT_LOAD_DEFAULT );
144152 if (ret )
@@ -160,27 +168,45 @@ SGuint SG_EXPORT sgmFontsCharsCreate(void* face, SGuint* chars, SGuint charnum,
160168
161169 data [i ] = malloc (bitmap .width * bitmap .rows );
162170 memcpy (data [i ], bitmap .buffer , bitmap .width * bitmap .rows );
163- /*for(j = 0; j < bitmap.rows; j++)
164- memcpy((char*)data[i] + j * bitmap.width, bitmap.buffer + (bitmap.rows - j - 1) * bitmap.width, bitmap.width);*/
165171
166172 prex [i ] = bitmap_glyph -> left ;
167- //prey[i] = -bitmap_glyph->top + bitmap.rows;
168173 prey [i ] = - bitmap_glyph -> top ;
169174
170175 postx [i ] = fface -> ftface -> glyph -> advance .x / 64.0 ;
171176 posty [i ] = 0 ;
172177
173- width [i ] = fface -> ftface -> glyph -> /*bitmap .width*/ advance . x / 64.0 ;
174- height [i ] = fface -> height ;
178+ width [i ] = fface -> ftface -> glyph -> metrics .width ;
179+ height [i ] = fface -> ftface -> glyph -> metrics . height ;
175180
176181 FT_Done_Glyph (glyph );
177182 }
178183
179184 return SG_OK ;
180185}
181-
182- SGuint SG_EXPORT sgmFontsCharsFreeData (void * data )
186+ SGenum SG_EXPORT sgmFontsCharsFreeData (void * data )
183187{
184188 free (data );
185189 return SG_OK ;
186190}
191+
192+ SGenum SG_EXPORT sgmFontsCharsGetKerning (void * face , const SGdchar * chars , size_t numchars , float * kerning )
193+ {
194+ if (!face ) return SG_INVALID_VALUE ;
195+ FontFace * fface = face ;
196+
197+ FT_Vector vec ;
198+
199+ FT_UInt prev = numchars ? FT_Get_Char_Index (fface -> ftface , chars [0 ]) : 0 ;
200+ FT_UInt curr ;
201+
202+ size_t i ;
203+ for (i = 1 ; i < numchars ; i ++ )
204+ {
205+ curr = FT_Get_Char_Index (fface -> ftface , chars [i ]);
206+ FT_Get_Kerning (fface -> ftface , prev , curr , FT_KERNING_DEFAULT , & vec );
207+ kerning [i - 1 ] = vec .x / 64.0 ;
208+ prev = curr ;
209+ }
210+
211+ return SG_OK ;
212+ }
0 commit comments