public void DrawToBitmap(byte[] pData, int texWidth, int texHeight) { if (IsEmpty()) { return; } // Convert The Glyph To A Bitmap. ANT_Error error = ANT.ANT_Glyph_To_Bitmap(ref m_pGlyph, ANT_Render_Mode.ANT_RENDER_MODE_NORMAL, null, true); if (error == ANT_Error.ANT_Err_Ok) { ANT_BitmapGlyph bitmap_glyph = (ANT_BitmapGlyph)m_pGlyph; // This Reference Will Make Accessing The Bitmap Easier. ANT_Bitmap bitmap = bitmap_glyph.bitmap; int x, y = 0; int index; for (y = 0; y < bitmap.rows; y++) { for (x = 0; x < bitmap.width; x++) { index = (m_y + y) * texWidth + m_x + x; pData[index] = bitmap.buffer[y * bitmap.width + x]; } } } }
public bool Attach(string file_name) { if (m_CurrentFace != null) { m_ANTLastError = ANT.ANT_Attach_File(m_CurrentFace, file_name); return(m_ANTLastError == ANT_Error.ANT_Err_Ok); } return(false); }
public bool PrepareGlyph(int glyph_code) { m_GlyphIndex = (int)ANT.ANT_Get_Char_Index(m_CurrentFace, glyph_code); m_ANTLastError = ANT.ANT_Load_Glyph(m_CurrentFace, m_GlyphIndex, m_Hinting ? ANT_LOAD.ANT_LOAD_DEFAULT : ANT_LOAD.ANT_LOAD_NO_HINTING); if (m_ANTLastError == ANT_Error.ANT_Err_Ok) { m_AdvanceX = ANT.ANT_int26p6_to_double(m_CurrentFace.glyph.advance.x); m_AdvanceY = ANT.ANT_int26p6_to_double(m_CurrentFace.glyph.advance.y); switch (m_GlyphRenderType) { case GlyphRenderType.Mono: case GlyphRenderType.Gray8: m_ANTLastError = ANT.ANT_Render_Glyph(m_CurrentFace.glyph, m_GlyphRenderType == GlyphRenderType.Mono ? ANT_Render_Mode.ANT_RENDER_MODE_MONO : ANT_Render_Mode.ANT_RENDER_MODE_NORMAL); if (m_ANTLastError == ANT_Error.ANT_Err_Ok) { m_CurrentBitmap = ANTExt.ToBitmap(m_CurrentFace.glyph.bitmap, m_FlipY); if (m_CurrentBitmap != null) { m_Bounds.Left = m_CurrentFace.glyph.bitmap_left; m_Bounds.Top = m_CurrentFace.glyph.bitmap_top; m_Bounds.Right = m_CurrentBitmap.PixelWidth + 1; m_Bounds.Bottom = m_CurrentBitmap.PixelHeight + 1; } } else { m_Bounds = new Rect(0, 0, m_AdvanceX, m_AdvanceY); } m_GlyphDataType = m_GlyphRenderType == GlyphRenderType.Mono ? GlyphDataType.Mono : GlyphDataType.Gray8; return(true); case GlyphRenderType.Outline: m_CurrentGeometry = ANTExt.ANT_Outline_ToGeometry(m_CurrentFace.glyph.outline, m_FlipY, m_Matrix); if (m_CurrentGeometry != null) { m_Bounds = m_CurrentGeometry.Bounds; //m_Bounds.BoundFloorCeiling(); m_GlyphDataType = GlyphDataType.Outline; m_Matrix.Transform(ref m_AdvanceX, ref m_AdvanceY); return(true); } m_Bounds = Rect.Empty; break; } } return(false); }
public bool LoadFont(string font_name, GlyphRenderType ren_type, byte[] font_mem, int font_mem_size) { int face_index = 0; bool ret = false; ANT_Library library = Library; if (library != null) { m_ANTLastError = ANT_Error.ANT_Err_Ok; int idx = FindFace(font_name); if (idx >= 0) { if (m_CurrentFace == m_Faces[idx] && m_GlyphRenderType == ren_type) { return(true); } m_CurrentFace = m_Faces[idx]; m_Name = font_name; } else { ANT_Face face; if (font_mem != null && font_mem_size != 0) { m_ANTLastError = ANT.ANT_New_Memory_Face(library, font_mem, font_mem_size, face_index, out face); } else { m_ANTLastError = ANT.ANT_New_Face(library, font_name, face_index, out face); } if (m_ANTLastError == ANT_Error.ANT_Err_Ok) { m_FaceIndex++; m_Faces.Add(m_FaceIndex, face); m_FaceNames.Add(font_name, m_FaceIndex); m_CurrentFace = face; m_Name = font_name; UpdateCharSize(); } else { m_CurrentFace = null; m_Name = null; } } if (m_ANTLastError == ANT_Error.ANT_Err_Ok) { ret = true; switch (ren_type) { case GlyphRenderType.Mono: m_GlyphRenderType = GlyphRenderType.Mono; break; case GlyphRenderType.Gray8: m_GlyphRenderType = GlyphRenderType.Gray8; break; case GlyphRenderType.Outline: if (ANT.ANT_IS_SCALABLE(m_CurrentFace.face_flags)) { m_GlyphRenderType = GlyphRenderType.Outline; } else { m_GlyphRenderType = GlyphRenderType.Gray8; } break; } UpdateSignature(); } } return(ret); }