public void SetCurrentFont(string fontname, InstalledFontStyle fontStyle, float fontSizeInPts, ScriptLang scLang = null)
        {
            InstalledFont installedFont = _hub._openFontStore.GetFont(fontname, fontStyle);

            if (installedFont == null)
            {
                return;                       //not found request font
            }
            if (scLang != null)
            {
                _glyphLayout.ScriptLang = scLang;
            }

            var key = new TextShapingContextKey(installedFont, _glyphLayout.ScriptLang);

            if (!_registerShapingContexts.TryGetValue(key, out _currentShapingContext))
            {
                //not found
                //the create the new one
                Typeface typeface;
                using (var fs = new System.IO.FileStream(installedFont.FontPath, System.IO.FileMode.Open, System.IO.FileAccess.Read))
                {
                    var reader = new OpenFontReader();
                    typeface = reader.Read(fs);
                }
                var shapingContext = new TextShapingContext(typeface, _glyphLayout.ScriptLang);
                //shaping context setup ...
                _registerShapingContexts.Add(key, shapingContext);
                _currentShapingContext = shapingContext;
            }
            _fontSizeInPts = fontSizeInPts;
        }
Beispiel #2
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));
        }
Beispiel #3
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));
        }
Beispiel #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);
            }

            if (newfont.TypographicFontName != newfont.FontName)
            {
            }

            //
            string fontNameUpper = newfont.FontName.ToUpper();

            if (selectedFontGroup.TryGetValue(fontNameUpper, out InstalledFont 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);
            }
        }
Beispiel #5
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);
        }
Beispiel #6
0
 public void Replace(InstalledFont newone)
 {
     _members[newone.FontName.ToUpper()] = newone;
 }
Beispiel #7
0
 public bool TryGetValue(string fontName, out InstalledFont found)
 {
     return(_members.TryGetValue(fontName, out found));
 }
Beispiel #8
0
 public void AddFont(InstalledFont installedFont)
 {
     _members.Add(installedFont.FontName.ToUpper(), installedFont);
 }
Beispiel #9
0
 public Typeface GetTypeface(InstalledFont installedFont)
 {
     return(GetTypefaceOrCreateNew(installedFont));
 }
 public TextShapingContextKey(InstalledFont installedFont, ScriptLang scLang)
 {
     this._installedFont = installedFont;
     this._scLang        = scLang;
 }