Exemple #1
0
        public void LoadInstalledFont(IEnumerable <string> getFontFileIter)
        {
            installedFonts = ReadPreviewFontData(getFontFileIter);
            //classify
            //do
            int j = installedFonts.Count;

            for (int i = 0; i < j; ++i)
            {
                InstalledFont f = installedFonts[i];
                if (f == null || f.FontName == "" || f.FontName.StartsWith("\0"))
                {
                    //no font name?
                    continue;
                }
                switch (f.FontSubFamily)
                {
                case "Normal":
                case "Regular":
                {
                    regular_Fonts.Add(f.FontName.ToUpper(), f);
                }
                break;

                case "Italic":
                case "Italique":
                {
                    italic_Fonts.Add(f.FontName.ToUpper(), f);
                }
                break;

                case "Bold":
                {
                    bold_Fonts.Add(f.FontName.ToUpper(), f);
                }
                break;

                case "Bold Italic":
                {
                    boldItalic_Fonts.Add(f.FontName.ToUpper(), f);
                }
                break;

                case "Gras":
                {
                    gras_Fonts.Add(f.FontName.ToUpper(), f);
                }
                break;

                case "Gras Italique":
                {
                    grasItalic_Fonts.Add(f.FontName.ToUpper(), f);
                }
                break;

                default:
                    throw new NotSupportedException();
                }
            }
        }
Exemple #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);
        }
Exemple #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);
        }
Exemple #4
0
        /// <summary>
        /// get typeface from wellknown style
        /// </summary>
        /// <param name="fontname"></param>
        /// <param name="style"></param>
        /// <returns></returns>
        public Typeface GetTypeface(string fontname, InstalledFontStyle style)
        {
            InstalledFont installedFont = FontCollection.GetFont(fontname, style);

            if (installedFont == null && _fontNotFoundHandler != null)
            {
                installedFont = _fontNotFoundHandler(this.FontCollection, fontname, null, style);
            }
            if (installedFont == null)
            {
                return(null);
            }
            return(GetTypefaceOrCreateNew(installedFont));
        }
Exemple #5
0
        public Typeface GetTypeface(string fontname, string fontSubFam)
        {
            InstalledFont installedFont = FontCollection.GetFont(fontname, fontSubFam);

            //convert from
            if (installedFont == null && _fontNotFoundHandler != null)
            {
                installedFont = _fontNotFoundHandler(this.FontCollection, fontname, fontSubFam, FontCollection.GetWellknownFontStyle(fontSubFam));
            }
            if (installedFont == null)
            {
                return(null);
            }
            return(GetTypefaceOrCreateNew(installedFont));
        }
Exemple #6
0
        public static List <InstalledFont> ReadPreviewFontData(IEnumerable <string> getFontFileIter)
        {
            //-------------------------------------------------
            //TODO: review here, this is not platform depend
            //-------------------------------------------------
            //check if MAC or linux font folder too
            //-------------------------------------------------

            List <InstalledFont> installedFonts = new List <InstalledFont>();

            foreach (string fontFilename in getFontFileIter)
            {
                InstalledFont installedFont = FontPreview.GetFontDetails(fontFilename);
                installedFonts.Add(installedFont);
            }
            return(installedFonts);
        }
Exemple #7
0
        Typeface GetTypefaceOrCreateNew(InstalledFont installedFont)
        {
            //load
            //check if we have create this typeface or not
            Typeface typeface;

            if (!_loadedTypefaces.TryGetValue(installedFont, out typeface))
            {
                //TODO: review how to load font here
                using (var fs = new FileStream(installedFont.FontPath, FileMode.Open, FileAccess.Read))
                {
                    var reader = new OpenFontReader();
                    typeface = reader.Read(fs);
                }
                return(_loadedTypefaces[installedFont] = typeface);
            }
            return(typeface);
        }
Exemple #8
0
        bool RegisterFont(InstalledFont newfont)
        {
            FontGroup selectedFontGroup;
            string    fontsubFamUpperCaseName = newfont.FontSubFamily.ToUpper();

            if (!_subFamToFontGroup.TryGetValue(fontsubFamUpperCaseName, out selectedFontGroup))
            {
                //create new group, we don't known this font group before
                //so we add to 'other group' list
                selectedFontGroup = new FontGroup();
                _subFamToFontGroup.Add(fontsubFamUpperCaseName, selectedFontGroup);
                _allFontGroups.Add(selectedFontGroup);
            }
            //
            string fontNameUpper = newfont.FontName.ToUpper();

            InstalledFont found;

            if (selectedFontGroup.TryGetValue(fontNameUpper, out found))
            {
                //TODO:
                //we already have this font name
                //(but may be different file
                //we let user to handle it
                switch (fontNameDuplicatedHandler(found, newfont))
                {
                default: throw new NotSupportedException();

                case FontNameDuplicatedDecision.Skip:
                    return(false);

                case FontNameDuplicatedDecision.Replace:
                    selectedFontGroup.Replace(newfont);
                    return(true);
                }
            }
            else
            {
                selectedFontGroup.AddFont(newfont);
                return(true);
            }
        }
Exemple #9
0
        public void ChangeFont(RequestFont font)
        {
            //1.  resolve actual font file
            this._reqFont = font;
            InstalledFont installedFont = _fontLoader.GetFont(font.Name, font.Style.ConvToInstalledFontStyle());
            Typeface      foundTypeface;

            if (!TryGetTypeface(installedFont, out foundTypeface))
            {
                //if not found then create a new one
                //if not found
                //create the new one
                using (FileStream fs = new FileStream(installedFont.FontPath, FileMode.Open, FileAccess.Read))
                {
                    var reader = new OpenFontReader();
                    foundTypeface = reader.Read(fs);
                }
                RegisterTypeface(installedFont, foundTypeface);
            }

            this.Typeface = foundTypeface;
        }
Exemple #10
0
 void RegisterTypeface(InstalledFont instFont, Typeface typeface)
 {
     _cachedTypefaces[instFont] = typeface;
 }
Exemple #11
0
 bool TryGetTypeface(InstalledFont instFont, out Typeface found)
 {
     return(_cachedTypefaces.TryGetValue(instFont, out found));
 }
Exemple #12
0
 public void Replace(InstalledFont newone)
 {
     _members[newone.FontName.ToUpper()] = newone;
 }
Exemple #13
0
 public bool TryGetValue(string fontName, out InstalledFont found)
 {
     return(_members.TryGetValue(fontName, out found));
 }
Exemple #14
0
 public void AddFont(InstalledFont installedFont)
 {
     _members.Add(installedFont.FontName.ToUpper(), installedFont);
 }
Exemple #15
0
 public Typeface GetTypeface(InstalledFont installedFont)
 {
     return(GetTypefaceOrCreateNew(installedFont));
 }