예제 #1
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));
        }
예제 #2
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));
        }
예제 #3
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);
        }
예제 #4
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);
            }
        }
예제 #5
0
 public void Replace(InstalledFont newone)
 {
     _members[newone.FontName.ToUpper()] = newone;
 }
예제 #6
0
 public bool TryGetValue(string fontName, out InstalledFont found)
 {
     return(_members.TryGetValue(fontName, out found));
 }
예제 #7
0
 public void AddFont(InstalledFont installedFont)
 {
     _members.Add(installedFont.FontName.ToUpper(), installedFont);
 }
예제 #8
0
 public Typeface GetTypeface(InstalledFont installedFont)
 {
     return(GetTypefaceOrCreateNew(installedFont));
 }