@@ -102,7 +102,7 @@ private void LoadGlyph(int glyphId)
102102 throw new FreeTypeException ( err ) ;
103103 }
104104
105- private void GetCurrentGlyph ( out FT_GlyphSlotRec_ glyph )
105+ public void GetCurrentGlyph ( out FT_GlyphSlotRec_ glyph )
106106 {
107107 glyph = Marshal . PtrToStructure < FT_GlyphSlotRec_ > ( ( IntPtr ) _faceRec ->glyph ) ;
108108 }
@@ -137,30 +137,8 @@ static byte LuminanceFromLinearRGB(byte r, byte g, byte b)
137137 // Y = 0.2126*R + 0.7152*G + 0.0722*B. Computed on the integer pipe.
138138 return ( byte ) ( ( 4732UL * r + 46871UL * g + 13933UL * b ) >> 16 ) ;
139139 }
140- public unsafe void RasterizeGlyphBitmap ( int glyphId , float fontSize , byte [ ] buffer , int startIndex , int outWidth , int outHeight , int outStride , FontStyle fontStyle )
140+ public void FetchGlyphBitmapBuffer ( int glyphId , float fontSize , byte [ ] buffer , int startIndex , int outWidth , int outHeight , int outStride , FontStyle fontStyle )
141141 {
142- SetPixelSizes ( 0 , fontSize ) ;
143- LoadGlyph ( glyphId ) ;
144-
145- FT_Render_Glyph ( _faceRec ->glyph , _renderMode ) ;
146-
147- if ( ( fontStyle & FontStyle . Bold ) != 0 && ( _faceRec ->style_flags & ( int ) FT_STYLE_FLAG . FT_STYLE_FLAG_BOLD ) == 0 )
148- FT_Bitmap_Embolden ( _libraryHandle , & _faceRec ->glyph ->bitmap , 64 , 0 ) ;
149-
150- if ( ( fontStyle & FontStyle . Italic ) != 0 && ( _faceRec ->style_flags & ( int ) FT_STYLE_FLAG . FT_STYLE_FLAG_ITALIC ) == 0 )
151- {
152- FT_Matrix_ italicMatrix = new FT_Matrix_
153- {
154- xx = 0x10000 ,
155- xy = ( nint ) ( 0.3f * 0x10000 ) ,
156- yx = 0 ,
157- yy = 0x10000
158- } ;
159- FT_Set_Transform ( _faceRec , & italicMatrix , default ) ;
160- }
161- else
162- FT_Set_Transform ( _faceRec , default , default ) ;
163-
164142 FT_GlyphSlotRec_ glyph ;
165143 GetCurrentGlyph ( out glyph ) ;
166144 var ftbmp = glyph . bitmap ;
@@ -229,5 +207,36 @@ public unsafe void RasterizeGlyphBitmap(int glyphId, float fontSize, byte[] buff
229207 }
230208 }
231209 }
210+
211+ public void RasterizeGlyphBitmap ( int glyphId , float fontSize , FontStyle fontStyle )
212+ {
213+ SetPixelSizes ( 0 , fontSize ) ;
214+
215+ if ( ( fontStyle & FontStyle . Italic ) != 0 && ( _faceRec ->style_flags & ( int ) FT_STYLE_FLAG . FT_STYLE_FLAG_ITALIC ) == 0 )
216+ {
217+ FT_Matrix_ italicMatrix = new FT_Matrix_
218+ {
219+ xx = 0x10000 ,
220+ xy = ( nint ) ( 0.3f * 0x10000 ) ,
221+ yx = 0 ,
222+ yy = 0x10000
223+ } ;
224+ FT_Set_Transform ( _faceRec , & italicMatrix , default ) ;
225+ }
226+ else
227+ FT_Set_Transform ( _faceRec , default , default ) ;
228+
229+ LoadGlyph ( glyphId ) ;
230+
231+ FT_Render_Glyph ( _faceRec ->glyph , _renderMode ) ;
232+
233+ if ( ( fontStyle & FontStyle . Bold ) != 0 && ! HasStyleFlag ( FT_STYLE_FLAG . FT_STYLE_FLAG_BOLD ) )
234+ FT_Bitmap_Embolden ( _libraryHandle , & _faceRec ->glyph ->bitmap , 64 , 0 ) ; // 1Pixel embolden
235+ }
236+
237+ public bool HasStyleFlag ( FT_STYLE_FLAG flag )
238+ {
239+ return ( _faceRec ->style_flags & ( int ) flag ) != 0 ;
240+ }
232241 }
233242}
0 commit comments