示例#1
0
 static NativeFontFace LoadFreeTypeFontFace(InstalledFont installedFont)
 {
     //if not found
     //then load it
     byte[] fontFileContent = File.ReadAllBytes(installedFont.FontPath);
     int filelen = fontFileContent.Length;
     IntPtr unmanagedMem = Marshal.AllocHGlobal(filelen);
     Marshal.Copy(fontFileContent, 0, unmanagedMem, filelen);
     //---------------------------------------------------
     //convert font point size to pixel size 
     //---------------------------------------------------
     //load font from memory
     IntPtr faceHandle = NativeMyFontsLib.MyFtNewMemoryFace(unmanagedMem, filelen);
     if (faceHandle == IntPtr.Zero)
     {
         //error
         //load font error
         Marshal.FreeHGlobal(unmanagedMem);
         return null;
     }
     //------------------------------------------------------- 
     NativeFontFace fontFace = new NativeFontFace(unmanagedMem, faceHandle, installedFont.FontName,
         installedFont.FontPath, FontStyle.Regular);
     fontFace.LoadFromFilename = installedFont.FontPath;
     ExportTypeFaceInfo exportTypeInfo = new ExportTypeFaceInfo();
     NativeMyFontsLib.MyFtGetFaceInfo(faceHandle, ref exportTypeInfo);
     fontFace.HasKerning = exportTypeInfo.hasKerning;
     //------------------------------------------------------- 
     return fontFace;
 }
示例#2
0
        static NativeFontFace LoadFreeTypeFontFace(InstalledFont installedFont)
        {
            //if not found
            //then load it
            byte[] fontFileContent = File.ReadAllBytes(installedFont.FontPath);
            int    filelen         = fontFileContent.Length;
            IntPtr unmanagedMem    = Marshal.AllocHGlobal(filelen);

            Marshal.Copy(fontFileContent, 0, unmanagedMem, filelen);
            //---------------------------------------------------
            //convert font point size to pixel size
            //---------------------------------------------------
            //load font from memory
            IntPtr faceHandle = NativeMyFontsLib.MyFtNewMemoryFace(unmanagedMem, filelen);

            if (faceHandle == IntPtr.Zero)
            {
                //error
                //load font error
                Marshal.FreeHGlobal(unmanagedMem);
                return(null);
            }
            //-------------------------------------------------------
            NativeFontFace fontFace = new NativeFontFace(unmanagedMem, faceHandle, installedFont.FontName,
                                                         installedFont.FontPath, FontStyle.Regular);

            fontFace.LoadFromFilename = installedFont.FontPath;
            ExportTypeFaceInfo exportTypeInfo = new ExportTypeFaceInfo();

            NativeMyFontsLib.MyFtGetFaceInfo(faceHandle, ref exportTypeInfo);
            fontFace.HasKerning = exportTypeInfo.hasKerning;
            //-------------------------------------------------------
            return(fontFace);
        }
示例#3
0
        public static FontFace LoadFont(InstalledFont installedFont, string lang, HBDirection direction, int defaultScriptCode = 0)
        {
            NativeFontFace fontFace = LoadFreeTypeFontFace(installedFont);

            SetShapingEngine(fontFace, lang, direction, defaultScriptCode);
            return(fontFace);
        }
示例#4
0
        //static ActualFont LoadFont(InstalledFont installedFont,
        //    float sizeInPoints,
        //    string lang,
        //    HBDirection direction,
        //    int scriptCode)
        //{
        //    //load font from specific file

        //    NativeFontFace fontFace;
        //    //if not found
        //    //then load it
        //    byte[] fontFileContent = File.ReadAllBytes(installedFont.FontPath);
        //    int filelen = fontFileContent.Length;
        //    IntPtr unmanagedMem = Marshal.AllocHGlobal(filelen);
        //    Marshal.Copy(fontFileContent, 0, unmanagedMem, filelen);
        //    //---------------------------------------------------
        //    //convert font point size to pixel size
        //    //---------------------------------------------------
        //    //load font from memory
        //    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
        //        //-------------------
        //        //TODO: review here
        //        fontFace = new NativeFontFace(unmanagedMem, faceHandle, installedFont.FontName, FontStyle.Regular);
        //        fontFace.LoadFromFilename = installedFont.FontPath;
        //        ExportTypeFaceInfo exportTypeInfo = new ExportTypeFaceInfo();
        //        NativeMyFontsLib.MyFtGetFaceInfo(faceHandle, ref exportTypeInfo);
        //        fontFace.HasKerning = exportTypeInfo.hasKerning;
        //        //for shaping engine***
        //        //SetShapingEngine(fontFace,
        //        //    lang,
        //        //    defaultHbDirection,
        //        //    defaultScriptCode);

        //        //-------------------
        //        //uint glyphIndex1;
        //        //int char1 = NativeMyFontsLib.MyFtGetFirstChar(faceHandle, out glyphIndex1);
        //        //List<CharAndGlyphMap> charMap = new List<CharAndGlyphMap>();
        //        //while (char1 != 0)
        //        //{
        //        //    char c = (char)char1;
        //        //    charMap.Add(new CharAndGlyphMap(glyphIndex1, c));
        //        //    char1 = NativeMyFontsLib.MyFtGetNextChar(faceHandle, char1, out glyphIndex1);
        //        //}
        //        //-------------------

        //        //load glyph map
        //    }
        //    else
        //    {
        //        //load font error
        //        Marshal.FreeHGlobal(unmanagedMem);
        //    }

        //    //-------------------------------------------------
        //    //get font that specific size from found font face
        //    //-------------------------------------------------
        //    NativeFont nativeFont = fontFace.GetFontAtPointSize(sizeInPoints);
        //    //TODO: review here again, not hard code
        //    var fontKey = new FontKey(installedFont.FontName, sizeInPoints, FontStyle.Regular);
        //    registerFonts.Add(fontKey, nativeFont);
        //    return nativeFont;
        //}
        static void SetShapingEngine(NativeFontFace fontFace, string lang, HBDirection hb_direction, int hb_scriptcode)
        {
            ExportTypeFaceInfo exportTypeInfo = new ExportTypeFaceInfo();

            NativeMyFontsLib.MyFtSetupShapingEngine(fontFace.Handle,
                                                    lang,
                                                    lang.Length,
                                                    hb_direction,
                                                    hb_scriptcode,
                                                    ref exportTypeInfo);
            fontFace.HBFont = exportTypeInfo.hb_font;
        }
示例#5
0
        internal NativeFont(NativeFontFace ownerFace, string fontName, FontStyle fontStyle, int pixelSize)
        {
            this.fontName = fontName;
            this.fontStyle = fontStyle;
            //store unmanage font file information
            this.ownerFace = ownerFace;
            this.fontSizeInPixelUnit = pixelSize;
            this.fontStyle = fontStyle;
            int ascentEmSize = ownerFace.Ascent / ownerFace.UnitPerEm;
            fontFaceAscentInPx = RequestFont.ConvEmSizeInPointsToPixels(ascentEmSize);

            int descentEmSize = ownerFace.Descent / ownerFace.UnitPerEm;
            fontFaceDescentInPx = RequestFont.ConvEmSizeInPointsToPixels(descentEmSize);


            int lineGap = ownerFace.LineGapInDzUnit / ownerFace.UnitPerEm;
            lineGapInPx = RequestFont.ConvEmSizeInPointsToPixels(lineGap);
        }
示例#6
0
        internal NativeFont(NativeFontFace ownerFace, string fontName, FontStyle fontStyle, int pixelSize)
        {
            this.fontName  = fontName;
            this.fontStyle = fontStyle;
            //store unmanage font file information
            this.ownerFace           = ownerFace;
            this.fontSizeInPixelUnit = pixelSize;
            this.fontStyle           = fontStyle;
            int ascentEmSize = ownerFace.Ascent / ownerFace.UnitPerEm;

            fontFaceAscentInPx = RequestFont.ConvEmSizeInPointsToPixels(ascentEmSize);

            int descentEmSize = ownerFace.Descent / ownerFace.UnitPerEm;

            fontFaceDescentInPx = RequestFont.ConvEmSizeInPointsToPixels(descentEmSize);


            int lineGap = ownerFace.LineGapInDzUnit / ownerFace.UnitPerEm;

            lineGapInPx = RequestFont.ConvEmSizeInPointsToPixels(lineGap);
        }
示例#7
0
        //static ActualFont LoadFont(InstalledFont installedFont,
        //    float sizeInPoints,
        //    string lang,
        //    HBDirection direction,
        //    int scriptCode)
        //{
        //    //load font from specific file  

        //    NativeFontFace fontFace;
        //    //if not found
        //    //then load it
        //    byte[] fontFileContent = File.ReadAllBytes(installedFont.FontPath);
        //    int filelen = fontFileContent.Length;
        //    IntPtr unmanagedMem = Marshal.AllocHGlobal(filelen);
        //    Marshal.Copy(fontFileContent, 0, unmanagedMem, filelen);
        //    //---------------------------------------------------
        //    //convert font point size to pixel size 
        //    //---------------------------------------------------
        //    //load font from memory
        //    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  
        //        //------------------- 
        //        //TODO: review here
        //        fontFace = new NativeFontFace(unmanagedMem, faceHandle, installedFont.FontName, FontStyle.Regular);
        //        fontFace.LoadFromFilename = installedFont.FontPath;
        //        ExportTypeFaceInfo exportTypeInfo = new ExportTypeFaceInfo();
        //        NativeMyFontsLib.MyFtGetFaceInfo(faceHandle, ref exportTypeInfo);
        //        fontFace.HasKerning = exportTypeInfo.hasKerning;
        //        //for shaping engine***
        //        //SetShapingEngine(fontFace,
        //        //    lang,
        //        //    defaultHbDirection,
        //        //    defaultScriptCode);

        //        //------------------- 
        //        //uint glyphIndex1;
        //        //int char1 = NativeMyFontsLib.MyFtGetFirstChar(faceHandle, out glyphIndex1);
        //        //List<CharAndGlyphMap> charMap = new List<CharAndGlyphMap>(); 
        //        //while (char1 != 0)
        //        //{
        //        //    char c = (char)char1;
        //        //    charMap.Add(new CharAndGlyphMap(glyphIndex1, c));
        //        //    char1 = NativeMyFontsLib.MyFtGetNextChar(faceHandle, char1, out glyphIndex1);
        //        //}
        //        //------------------- 

        //        //load glyph map
        //    }
        //    else
        //    {
        //        //load font error
        //        Marshal.FreeHGlobal(unmanagedMem);
        //    }

        //    //-------------------------------------------------
        //    //get font that specific size from found font face
        //    //-------------------------------------------------
        //    NativeFont nativeFont = fontFace.GetFontAtPointSize(sizeInPoints);
        //    //TODO: review here again, not hard code
        //    var fontKey = new FontKey(installedFont.FontName, sizeInPoints, FontStyle.Regular);
        //    registerFonts.Add(fontKey, nativeFont);
        //    return nativeFont;
        //}
        static void SetShapingEngine(NativeFontFace fontFace, string lang, HBDirection hb_direction, int hb_scriptcode)
        {
            ExportTypeFaceInfo exportTypeInfo = new ExportTypeFaceInfo();
            NativeMyFontsLib.MyFtSetupShapingEngine(fontFace.Handle,
               lang,
               lang.Length,
               hb_direction,
               hb_scriptcode,
               ref exportTypeInfo);
            fontFace.HBFont = exportTypeInfo.hb_font;
        }