@@ -94,28 +94,36 @@ SGenum SG_EXPORT sgmFontsFaceCreate(void** face, SGStream* stream)
94
94
return SG_UNKNOWN_ERROR ;
95
95
return SG_OK ;
96
96
}
97
- SGuint SG_EXPORT sgmFontsFaceDestroy (void * face )
97
+ SGenum SG_EXPORT sgmFontsFaceDestroy (void * face )
98
98
{
99
99
if (face == NULL )
100
100
return SG_OK ; // SG_INVALID_VALUE
101
101
FT_Done_Face (((FontFace * )face )-> ftface );
102
102
free (face );
103
103
return SG_OK ;
104
104
}
105
- SGuint SG_EXPORT sgmFontsFaceSetHeight (void * face , float height )
105
+
106
+ SGenum SG_EXPORT sgmFontsFaceSetHeight (void * face , float height , SGuint dpi )
106
107
{
107
108
if (face == NULL )
108
109
return SG_OK ; // SG_INVALID_VALUE
109
110
((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 );
111
112
return SG_OK ;
112
113
}
113
- /*SGuint SG_EXPORT sgmFontsFaceGetHeight (void* face, float* height )
114
+ SGenum SG_EXPORT sgmFontsFaceGetMetrics (void * face , float * ascent , float * descent , float * linegap )
114
115
{
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
+
116
123
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 )
119
127
{
120
128
if (face == NULL )
121
129
{
@@ -137,8 +145,8 @@ SGuint SG_EXPORT sgmFontsCharsCreate(void* face, SGuint* chars, SGuint charnum,
137
145
FT_Glyph glyph ;
138
146
FT_BitmapGlyph bitmap_glyph ;
139
147
FT_Bitmap bitmap ;
140
- SGuint i /*, j*/ ;
141
- for (i = 0 ; i < charnum ; i ++ )
148
+ SGuint i ;
149
+ for (i = 0 ; i < numchars ; i ++ )
142
150
{
143
151
ret = FT_Load_Glyph (fface -> ftface , FT_Get_Char_Index (fface -> ftface , chars [i ]), FT_LOAD_DEFAULT );
144
152
if (ret )
@@ -160,27 +168,45 @@ SGuint SG_EXPORT sgmFontsCharsCreate(void* face, SGuint* chars, SGuint charnum,
160
168
161
169
data [i ] = malloc (bitmap .width * bitmap .rows );
162
170
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);*/
165
171
166
172
prex [i ] = bitmap_glyph -> left ;
167
- //prey[i] = -bitmap_glyph->top + bitmap.rows;
168
173
prey [i ] = - bitmap_glyph -> top ;
169
174
170
175
postx [i ] = fface -> ftface -> glyph -> advance .x / 64.0 ;
171
176
posty [i ] = 0 ;
172
177
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 ;
175
180
176
181
FT_Done_Glyph (glyph );
177
182
}
178
183
179
184
return SG_OK ;
180
185
}
181
-
182
- SGuint SG_EXPORT sgmFontsCharsFreeData (void * data )
186
+ SGenum SG_EXPORT sgmFontsCharsFreeData (void * data )
183
187
{
184
188
free (data );
185
189
return SG_OK ;
186
190
}
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