public WinGdiFontFace(RequestFont f)
        {
            this.style = f.Style;
            //resolve
            InstalledFont foundInstalledFont = s_fontLoader.GetFont(f.Name, style.ConvToInstalledFontStyle());

            //TODO: review
            this.nopenTypeFontFace = OpenFontLoader.LoadFont(foundInstalledFont.FontPath);
        }
        public void ChangeFont(RequestFont font)
        {
            //from request font
            //we resolve it to actual font
            this.font = font;
            //resolve
            string fontfile = _fontLoader.GetFont(font.Name, InstalledFontStyle.Regular).FontPath;

            ff = TextureFontLoader.LoadFont(fontfile, ScriptLangs.Latin, WriteDirection.LTR, out simpleFontAtlas);
        }
        public static ActualFont GetTextureFontAtlasOrCreateNew(
            IFontLoader fontLoader,
            RequestFont font,
            out SimpleFontAtlas fontAtlas)
        {
            //check if we have created this font
            var key = new FontTextureKey();

            key.fontName    = font.Name;
            key.scriptLang  = font.ScriptLang.shortname;
            key.sizeInPoint = font.SizeInPoints;
            key.fontStyle   = font.Style;
            //------------------------
            TextureAtlasCache found;
            FontFace          ff = null;

            if (!s_cachedFontAtlas.TryGetValue(key, out found))
            {
                //if not, then create the new one
                string fontfile = fontLoader.GetFont(font.Name, font.Style.ConvToInstalledFontStyle()).FontPath;
                //ptimize here
                //TODO: review
                TextureFontCreationParams creationParams = new TextureFontCreationParams();
                creationParams.originalFontSizeInPoint = font.SizeInPoints;
                creationParams.scriptLang     = font.ScriptLang;
                creationParams.writeDirection = WriteDirection.LTR;//default
                //TODO: review here, langBits can be created with scriptLang ?
                creationParams.langBits = new Typography.OpenFont.Tables.UnicodeLangBits[]
                {
                    Typography.OpenFont.Tables.UnicodeLangBits.BasicLatin, //0-127
                    Typography.OpenFont.Tables.UnicodeLangBits.Thai        //eg. Thai, for test with complex script, you can change to your own
                };
                //
                creationParams.textureKind = Typography.Rendering.TextureKind.AggSubPixel;
                if (font.SizeInPoints >= 4 && font.SizeInPoints <= 14)
                {
                    //creationParams.hintTechnique = Typography.Rendering.HintTechnique.TrueTypeInstruction;
                    //creationParams.hintTechnique = Typography.Rendering.HintTechnique.TrueTypeInstruction_VerticalOnly;
                    creationParams.hintTechnique = Typography.Rendering.HintTechnique.CustomAutoFit;
                }
                //
                ff = TextureFontLoader.LoadFont(fontfile, creationParams, out fontAtlas);


                //cache it
                var textureAtlasCache = new TextureAtlasCache();
                textureAtlasCache.fontFace = ff;
                textureAtlasCache.atlas    = fontAtlas;
                s_cachedFontAtlas.Add(key, textureAtlasCache);
                return(ff.GetFontAtPointSize(font.SizeInPoints));
            }
            fontAtlas = found.atlas;
            ff        = found.fontFace;
            return(ff.GetFontAtPointSize(font.SizeInPoints));
        }
Exemple #4
0
        public Chip8Emu(IFontLoader fontLoader, IAudioDevice audioDevice, IPPU ppu, IInputDevice inputDevice, byte[] rom)
        {
            _audioDevice = audioDevice;
            _ppu         = ppu;
            _inputDevice = inputDevice;

            Array.Copy(rom, 0, _memory, ROM_INDEX, rom.Length);

            var font = fontLoader.GetFont();

            Array.Copy(font, 0, _memory, FONT_INDEX, font.Length);

            _opCodes = new Dictionary <byte, Action <OpCodeData> >
            {
                { 0x0, Misc0 },
                { 0x1, JumpToNNN },
                { 0x2, CallSubroutine },
                { 0x3, SkipXEqualsNN },
                { 0x4, SkipXNotEqualsNN },
                { 0x5, SkipXEqualsY },
                { 0x6, SetXToNN },
                { 0x7, AddXToNN },
                { 0x8, Arithmetic },
                { 0x9, SkipXNotEqualsY },
                { 0xA, SetIToNNN },
                { 0xB, JumpToNNNPlusV0 },
                { 0xC, SetRandomX },
                { 0xD, DrawSprite },
                { 0xE, KeyPressedOps },
                { 0xF, MiscF },
            };
            _misc0OpCodes = new Dictionary <byte, Action <OpCodeData> >
            {
                { 0xE0, ClearScreen },
                { 0xEE, ReturnSubroutine },
            };
            _miscFOpCodes = new Dictionary <byte, Action <OpCodeData> >
            {
                { 0x07, SetXToTimer },
                { 0x0A, AwaitAndStoreKeyPress },
                { 0x15, SetDelayTimer },
                { 0x18, SetSoundTimer },
                { 0x1E, AddXToI },
                { 0x29, SetIToFont },
                { 0x33, SetIToBCD },
                { 0x55, SetX },
                { 0x65, LoadX },
            };

            var timer = new Timer(1000 / DISPLAY_HZ);

            timer.Elapsed += On60HzTimerTick;
            timer.Start();
        }
        internal static SkiaSharp.SKTypeface GetInstalledFont(string typefaceName)
        {
            InstalledFont installedFont = s_fontLoader.GetFont(typefaceName, InstalledFontStyle.Normal);

            if (installedFont == null)
            {
                return(null);
            }
            else
            {
                SkiaSharp.SKTypeface loadedTypeFace;
                if (!skTypeFaces.TryGetValue(installedFont, out loadedTypeFace))
                {
                    loadedTypeFace = SkiaSharp.SKTypeface.FromFile(installedFont.FontPath);
                    skTypeFaces.Add(installedFont, loadedTypeFace);
                }
                return(loadedTypeFace);
            }
        }
        public void ChangeFont(RequestFont font)
        {
            //1.  resolve actual font file
            this._font = font;
            string resolvedFontFilename = _fontLoader.GetFont(font.Name, font.Style.ConvToInstalledFontStyle()).FontPath;

            if (resolvedFontFilename != _currentFontFilename)
            {
                //switch to another font
                //store current typeface to cache
                if (_glyphPathBuilder != null && !_cacheGlyphPathBuilders.ContainsKey(resolvedFontFilename))
                {
                    _cacheGlyphPathBuilders[_currentFontFilename] = _glyphPathBuilder;
                }
                //check if we have this in cache ?
                //if we don't have it, this _currentTypeface will set to null
                _cacheGlyphPathBuilders.TryGetValue(resolvedFontFilename, out _glyphPathBuilder);
            }
            this._currentFontFilename = resolvedFontFilename;
        }
Exemple #7
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;
        }