protected override Task LoadContent() #endif { // Create a new SpriteBatch, which can be used to draw textures. _spriteBatch = new SpriteBatch(GraphicsDevice); // TODO: use this.Content to load your game content here var fontSystems = new List <FontSystem>(); // Simple var fontSystem = new FontSystem(); LoadFontSystem(fontSystem); fontSystems.Add(fontSystem); // Blurry var settings = new FontSystemSettings { Effect = FontSystemEffect.Blurry, EffectAmount = EffectAmount, }; var blurryFontSystem = new FontSystem(settings); LoadFontSystem(blurryFontSystem); fontSystems.Add(blurryFontSystem); // Stroked settings.Effect = FontSystemEffect.Stroked; var strokedFontSystem = new FontSystem(settings); LoadFontSystem(strokedFontSystem); fontSystems.Add(strokedFontSystem); _fontSystems = fontSystems.ToArray(); _currentFontSystem = _fontSystems[0]; #if MONOGAME || FNA _white = new Texture2D(GraphicsDevice, 1, 1); _white.SetData(new[] { Color.White }); #elif STRIDE _white = Texture2D.New2D(GraphicsDevice, 1, 1, false, PixelFormat.R8G8B8A8_UNorm_SRgb, TextureFlags.ShaderResource); _white.SetData(GraphicsContext.CommandList, new[] { Color.White }); #endif GC.Collect(); #if STRIDE return(base.LoadContent()); #endif }
public void ExistingTexture() { Texture2D existingTexture; using (var stream = TestsEnvironment.Assembly.OpenResourceStream("Resources.default_ui_skin.png")) { existingTexture = Texture2D.FromStream(TestsEnvironment.GraphicsDevice, stream); } var settings = new FontSystemSettings { ExistingTexture = existingTexture, ExistingTextureUsedSpace = new Rectangle(0, 0, existingTexture.Width, 160) }; var fontSystem = new FontSystem(settings); fontSystem.AddFont(TestsEnvironment.Assembly.ReadResourceAsBytes("Resources.DroidSans.ttf")); var atlasFull = false; fontSystem.CurrentAtlasFull += (s, a) => atlasFull = true; for (var size = 64; size < 128; ++size) { var font = fontSystem.GetFont(size); for (var codePoint = (int)'a'; codePoint < 'z'; ++codePoint) { var glyph = (DynamicFontGlyph)font.GetGlyph(TestsEnvironment.GraphicsDevice, codePoint); // Make sure glyph doesnt intersects with the used space if (!atlasFull) { Assert.IsFalse(settings.ExistingTextureUsedSpace.Intersects(glyph.Bounds)); } else { // If we've moved to the next atlas // The new glyph should override old existing texture used space Assert.IsTrue(settings.ExistingTextureUsedSpace.Intersects(glyph.Bounds)); // This concludes the testing goto finish; } } } finish: ; }
public StbTrueTypeNativeSource(byte[] data, FontSystemSettings settings) { if (data == null) { throw new ArgumentNullException(nameof(data)); } if (settings == null) { throw new ArgumentNullException(nameof(settings)); } _font = new NativeFont(data); _settings = settings; }
public static StbTrueTypeNativeSource FromMemory(byte[] data, FontSystemSettings settings) { var font = new StbTrueTypeNativeSource(data, settings); int ascent, descent, lineGap; font._font.GetFontVMetrics(out ascent, out descent, out lineGap); var fh = ascent - descent; font.AscentBase = ascent / (float)fh; font.DescentBase = descent / (float)fh; font.LineHeightBase = (fh + lineGap) / (float)fh; return(font); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. _spriteBatch = new SpriteBatch(GraphicsDevice); // TODO: use this.Content to load your game content here var fontSystems = new List <FontSystem>(); _renderer = new Renderer(_spriteBatch); // Simple var fontSystem = new FontSystem(); LoadFontSystem(fontSystem); fontSystems.Add(fontSystem); // Blurry var settings = new FontSystemSettings { Effect = FontSystemEffect.Blurry, EffectAmount = EffectAmount }; var blurryFontSystem = new FontSystem(settings); LoadFontSystem(blurryFontSystem); fontSystems.Add(blurryFontSystem); // Stroked settings.Effect = FontSystemEffect.Stroked; var strokedFontSystem = new FontSystem(settings); LoadFontSystem(strokedFontSystem); fontSystems.Add(strokedFontSystem); _fontSystems = fontSystems.ToArray(); _currentFontSystem = _fontSystems[0]; _white = new Texture2D(GraphicsDevice, 1, 1); _white.SetData(new[] { Color.White }); GC.Collect(); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary> protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. _spriteBatch = new SpriteBatch(GraphicsDevice); // TODO: use this.Content to load your game content here var settings = new FontSystemSettings { TextureWidth = AtlasSize, TextureHeight = AtlasSize }; _fontSystem = new FontSystem(settings); _fontSystem.AddFont(File.ReadAllBytes(@"Fonts/DroidSans.ttf")); _white = new Texture2D(GraphicsDevice, 1, 1); _white.SetData(new[] { Color.White }); GC.Collect(); }
private void DoLoad() { if (fontsystem == null) { if (settings == null) { settings = new FontSystemSettings(); } fontsystem = new FontSystem(settings); if (source == ContentSource.GameContent) { fontsystem.AddFont(Game.Device.StreamContent(name, FontExtensions)); } else { fontsystem.AddFont(Game.ResourceContent.StreamInternalFont(name)); } font = fontsystem.GetFont(Size); GenerateCommonGlyphs(); } }
public IFontSource Load(byte[] data, FontSystemSettings settings) { return(StbTrueTypeNativeSource.FromMemory(data, settings)); }