Пример #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 FreeTypeFontLoader()
        {
#if DEBUG
            int major, minor, revision;
            NativeMyFontsLib.MyFtLibGetFullVersion(out major, out minor, out revision);
#endif
        }
Пример #3
0
 public override ActualFont GetFontAtPointSize(float fontPointSize)
 {
     currentFacePixelSize = (int)RequestFont.ConvEmSizeInPointsToPixels(fontPointSize);
     //----------------------------------
     //set current fontface size
     NativeMyFontsLib.MyFtSetPixelSizes(this.ftFaceHandle, currentFacePixelSize);
     //create font size
     return(new NativeFont(this, this.name, FontStyle.Regular, currentFacePixelSize));
 }
Пример #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
 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;
     }
 }
Пример #6
0
        internal NativeFontFace(IntPtr unmanagedMem, IntPtr ftFaceHandle, string name, string fontPath, FontStyle fontStyle)
        {
            this.name      = name;
            this.fontPath  = fontPath;
            this.fontStyle = fontStyle;

            this.unmanagedMem = unmanagedMem;
            this.ftFaceHandle = ftFaceHandle;
            //get face information
            unsafe
            {
                fixed(ExportFace *face_h = &this.exportFace)
                {
                    NativeMyFontsLib.MyFtGetFaceData(unmanagedMem, face_h);
                }
            }
        }
Пример #7
0
        //internal NativeFont GetFontAtPixelSize(int pixelSize)
        //{
        //    NativeFont 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, this.name, FontStyle.Regular, pixelSize);
        //        fonts.Add(pixelSize, f);
        //        //------------------------------------
        //        return f;
        //    }
        //    return found;
        //}
        //internal NativeFont GetFontAtPointSize(float fontPointSize)
        //{
        //    //convert from point size to pixelsize ***
        //    NativeFont nativeFont = GetFontAtPixelSize((int)RequestFont.ConvEmSizeInPointsToPixels(fontPointSize));

        //    return nativeFont;
        //}

        internal FontGlyph ReloadGlyphFromIndex(uint glyphIndex, int pixelSize)
        {
            if (currentFacePixelSize != pixelSize)
            {
                currentFacePixelSize = pixelSize;
                NativeMyFontsLib.MyFtSetPixelSizes(this.ftFaceHandle, pixelSize);
            }

            //--------------------------------------------------

            var fontGlyph = new NativeFontGlyph();
            NativeGlyphMatrix nativeGlyphMatrix;

            NativeMyFontsLib.MyFtLoadGlyph(ftFaceHandle, glyphIndex, out nativeGlyphMatrix);
            fontGlyph.glyphMatrix = nativeGlyphMatrix.matrixData;
            BuildOutlineGlyph(fontGlyph, pixelSize);
            return(fontGlyph);
        }
Пример #8
0
        internal FontGlyph ReloadGlyphFromChar(char unicodeChar, int pixelSize)
        {
            if (currentFacePixelSize != pixelSize)
            {
                currentFacePixelSize = pixelSize;
                NativeMyFontsLib.MyFtSetPixelSizes(this.ftFaceHandle, pixelSize);
            }
            //--------------------------------------------------
            var fontGlyph = new NativeFontGlyph();
            NativeGlyphMatrix nativeGlyphMatrix;

            NativeMyFontsLib.MyFtLoadChar(ftFaceHandle, unicodeChar, out nativeGlyphMatrix);
            fontGlyph.glyphMatrix      = nativeGlyphMatrix.matrixData;
            fontGlyph.nativeBmpPtr     = nativeGlyphMatrix.bitmap;
            fontGlyph.nativeOutlinePtr = nativeGlyphMatrix.outline;
            //--------------------------------------------------
            BuildOutlineGlyph(fontGlyph, pixelSize);
            return(fontGlyph);
        }
Пример #9
0
        static NativeMyFontsLib()
        {
            //dynamic load dll from current directory??
            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();
        }
Пример #10
0
 public void Dispose()
 {
     NativeMyFontsLib.MyFtShutdownLib();
 }