public static Font LoadFont(string filename, int fontPointSize) { //load font from specific file NativeFontFace fontFace; if (!fonts.TryGetValue(filename, out fontFace)) { //if not found //then load it byte[] fontFileContent = File.ReadAllBytes(filename); int filelen = fontFileContent.Length; IntPtr unmanagedMem = Marshal.AllocHGlobal(filelen); Marshal.Copy(fontFileContent, 0, unmanagedMem, filelen); //--------------------------------------------------- //convert font point size to pixel size //--------------------------------------------------- IntPtr faceHandle = NativeMyFontsLib.MyFtNewMemoryFace(unmanagedMem, filelen); if (faceHandle != IntPtr.Zero) { //ok pass //------------------- //test change font size //NativeMyFontsLib.MyFtSetCharSize(faceHandle, // 0, //char_width in 1/64th of points, value 0 => same as height // 16 * 64,//16 pt //char_height in 1*64 of ppoints // 96,//horizontal device resolution (eg screen resolution 96 dpi) // 96);// vertical device resolution //------------------- fontFace = new NativeFontFace(unmanagedMem, faceHandle); ExportTypeFaceInfo exportTypeInfo = new ExportTypeFaceInfo(); NativeMyFontsLib.MyFtGetFaceInfo(faceHandle, ref exportTypeInfo); fontFace.HasKerning = exportTypeInfo.hasKerning; //for shaping engine*** SetShapingEngine(fontFace, "th", HBDirection.HB_DIRECTION_LTR, HBScriptCode.HB_SCRIPT_THAI); fonts.Add(filename, fontFace); } else { //load font error Marshal.FreeHGlobal(unmanagedMem); } } //------------------------------------------------- //get font that specific size from found font face //------------------------------------------------- return(fontFace.GetFontAtPointSize(fontPointSize)); }
public override void GetGlyphPos(char[] buffer, int start, int len, ProperGlyph[] properGlyphs) { unsafe { fixed(ProperGlyph *propGlyphH = &properGlyphs[0]) fixed(char *head = &buffer[0]) { NativeMyFontsLib.MyFtShaping( this.NativeFontFace.HBFont, head, buffer.Length, propGlyphH); } } }
internal FontGlyph ReloadGlyphFromChar(char unicodeChar, int pixelSize) { if (currentFacePixelSize != pixelSize) { currentFacePixelSize = pixelSize; NativeMyFontsLib.MyFtSetPixelSizes(this.ftFaceHandle, pixelSize); } //-------------------------------------------------- unsafe { ExportGlyph exportTypeFace = new ExportGlyph(); NativeMyFontsLib.MyFtLoadChar(ftFaceHandle, unicodeChar, ref exportTypeFace); FontGlyph fontGlyph = new FontGlyph(); BuildGlyph(fontGlyph, &exportTypeFace, pixelSize); return(fontGlyph); } }
protected override void OnDispose() { if (this.ftFaceHandle != IntPtr.Zero) { NativeMyFontsLib.MyFtDoneFace(this.ftFaceHandle); ftFaceHandle = IntPtr.Zero; } if (unmanagedMem != IntPtr.Zero) { Marshal.FreeHGlobal(unmanagedMem); unmanagedMem = IntPtr.Zero; } if (fonts != null) { fonts.Clear(); fonts = null; } }
internal Font GetFontAtPixelSize(int pixelSize) { Font found; if (!fonts.TryGetValue(pixelSize, out found)) { //---------------------------------- //set current fontface size currentFacePixelSize = pixelSize; NativeMyFontsLib.MyFtSetPixelSizes(this.ftFaceHandle, pixelSize); //create font size NativeFont f = new NativeFont(this, pixelSize); fonts.Add(pixelSize, f); //------------------------------------ return(f); } return(found); }
internal static void SetShapingEngine(NativeFontFace fontFace, string lang, HBDirection hb_direction, int hb_scriptcode) { //string lang = "en"; //PixelFarm.Font2.NativeMyFontsLib.MyFtSetupShapingEngine(ftFaceHandle, // lang, // lang.Length, // HBDirection.HB_DIRECTION_LTR, // HBScriptCode.HB_SCRIPT_LATIN); ExportTypeFaceInfo exportTypeInfo = new ExportTypeFaceInfo(); NativeMyFontsLib.MyFtSetupShapingEngine(fontFace.Handle, lang, lang.Length, hb_direction, hb_scriptcode, ref exportTypeInfo); fontFace.HBFont = exportTypeInfo.hb_font; }
static NativeMyFontsLib() { //dynamic load dll string appBaseDir = AppDomain.CurrentDomain.BaseDirectory; LoadLib(appBaseDir + "\\" + myfontLib); //--------------- //init library int initResult = 0; lock (syncObj) { if (!isInitLib) { initResult = NativeMyFontsLib.MyFtInitLib(); isInitLib = true; } } //--------------- nativeModuleHolder = new NativeModuleHolder(); }
public void Dispose() { NativeMyFontsLib.MyFtShutdownLib(); }