public CharacterSpecification(char character, string fontName, Vector2 size, FontStyle style, FontAntiAliasMode antiAliasMode)
 {
     Character = character;
     FontName = fontName;
     Size = size;
     Style = style;
     AntiAlias = antiAliasMode;
     ListNode = new LinkedListNode<CharacterSpecification>(this);
 }
Esempio n. 2
0
 public CharacterSpecification(char character, string fontName, Vector2 size, FontStyle style, FontAntiAliasMode antiAliasMode)
 {
     Character = character;
     FontName  = fontName;
     Size      = size;
     Style     = style;
     AntiAlias = antiAliasMode;
     ListNode  = new LinkedListNode <CharacterSpecification>(this);
 }
Esempio n. 3
0
 public SpriteFont NewDynamic(float defaultSize, string fontName, FontStyle style, FontAntiAliasMode antiAliasMode, bool useKerning, float extraSpacing, float extraLineSpacing, char defaultCharacter)
 {
     return new DynamicSpriteFont
     {
         Size = defaultSize,
         DefaultCharacter = defaultCharacter,
         FontName = fontName,
         ExtraLineSpacing = extraLineSpacing,
         ExtraSpacing = extraSpacing,
         Style = style,
         UseKerning = useKerning,
         AntiAlias = antiAliasMode,
     };
 }
Esempio n. 4
0
        public SpriteFont NewDynamic(float defaultSize, string fontName, FontStyle style, FontAntiAliasMode antiAliasMode = FontAntiAliasMode.Default, bool useKerning = false, float extraSpacing = 0, float extraLineSpacing = 0, char defaultCharacter = ' ')
        {
            var font = new DynamicSpriteFont
            {
                Size = defaultSize,
                FontName = fontName,
                Style = style,
                AntiAlias = antiAliasMode,
                UseKerning = useKerning,
                ExtraSpacing = extraSpacing,
                ExtraLineSpacing = extraLineSpacing,
                DefaultCharacter = defaultCharacter,
                FontSystem = this
            };

            return font;
        }
Esempio n. 5
0
        /// <summary>
        /// Function to create a new font texture object from a GDI+ font.
        /// </summary>
        /// <param name="fontName">Name of the font texture object.</param>
        /// <param name="font">GDI+ font to use.</param>
        /// <param name="antiAliasMode">Anti-aliasing mode.</param>
        /// <param name="textureSize">Size of the textures to generate.</param>
        /// <returns>The new font texture object.</returns>
        /// <remarks>This method creates an object that contains a group of textures with font glyphs.  These textures can be used by another application to
        /// display text (or symbols) on the screen.  Kerning information (the proper spacing for a glyph) is included in the glyphs and font.
        /// <para>Please note that the <paramref name="fontName"/> parameter is user defined and does not have to be the same as the font family name in the <paramref name="font"/> parameter.</para>
        /// <para>Fonts may only be created on the immediate context.</para>
        /// </remarks>
        /// <exception cref="System.ArgumentNullException">Thrown when the fontName or <paramref name="font"/> parameters are NULL (Nothing in VB.Net).</exception>
        /// <exception cref="System.ArgumentException">Thrown when the fontName parameter is an empty string.
        /// <para>-or-</para>
        /// <para>Thrown when the <paramref name="textureSize"/> width or height is larger than can be handled by the current feature level.</para>
        /// </exception>
        /// <exception cref="GorgonLibrary.GorgonException">Thrown if the graphics context is deferred.</exception>
        public GorgonFont CreateFont(string fontName, Font font, FontAntiAliasMode antiAliasMode, Size textureSize)
        {
            if (font == null)
            {
                throw new ArgumentNullException("font");
            }

            var settings = new GorgonFontSettings
            {
                AntiAliasingMode = antiAliasMode,
                Brush            = null,
                FontFamilyName   = font.FontFamily.Name,
                FontStyle        = font.Style,
                Size             = font.SizeInPoints,
                TextureSize      = textureSize
            };

            return(CreateFont(fontName, settings));
        }
Esempio n. 6
0
        public DynamicSpriteFont(FontSystem fontSystem, DynamicSpriteFontData fontData)
            : base(fontSystem, fontData, true)
        {
            // import font properties from font data
            style      = fontData.Style;
            fontName   = fontData.FontName;
            useKerning = fontData.UseKerning;
            antiAlias  = fontData.AntiAlias;

            // retrieve needed info from the font
            float relativeLineSpacing;
            float relativeBaseOffsetY;
            float relativeMaxWidth;
            float relativeMaxHeight;

            FontManager.GetFontInfo(fontData.FontName, fontData.Style, out relativeLineSpacing, out relativeBaseOffsetY, out relativeMaxWidth, out relativeMaxHeight);

            // set required base properties
            DefaultLineSpacing = relativeLineSpacing * Size;
            BaseOffsetY        = relativeBaseOffsetY * Size;
            Textures           = FontCacheManager.Textures;
            Swizzle            = SwizzleMode.RRRR;
        }
        private Glyph ImportGlyph(Factory factory, FontFace fontFace, char character, FontMetrics fontMetrics, float fontSize, FontAntiAliasMode antiAliasMode)
        {
            var indices = fontFace.GetGlyphIndices(new int[] { character });

            var metrics = fontFace.GetDesignGlyphMetrics(indices, false);
            var metric  = metrics[0];

            var width  = (float)(metric.AdvanceWidth - metric.LeftSideBearing - metric.RightSideBearing) / fontMetrics.DesignUnitsPerEm * fontSize;
            var height = (float)(metric.AdvanceHeight - metric.TopSideBearing - metric.BottomSideBearing) / fontMetrics.DesignUnitsPerEm * fontSize;

            var xOffset = (float)metric.LeftSideBearing / fontMetrics.DesignUnitsPerEm * fontSize;
            var yOffset = (float)(metric.TopSideBearing - metric.VerticalOriginY) / fontMetrics.DesignUnitsPerEm * fontSize;

            var advanceWidth = (float)metric.AdvanceWidth / fontMetrics.DesignUnitsPerEm * fontSize;
            //var advanceHeight = (float)metric.AdvanceHeight / fontMetrics.DesignUnitsPerEm * fontSize;

            var pixelWidth  = (int)Math.Ceiling(width + 4);
            var pixelHeight = (int)Math.Ceiling(height + 4);

            var matrix = new RawMatrix3x2
            {
                M11 = 1,
                M22 = 1,
                M31 = -(float)Math.Floor(xOffset) + 1,
                M32 = -(float)Math.Floor(yOffset) + 1
            };

            Bitmap bitmap;

            if (char.IsWhiteSpace(character))
            {
                bitmap = new Bitmap(1, 1, PixelFormat.Format32bppArgb);
            }
            else
            {
                var glyphRun = new GlyphRun
                {
                    FontFace   = fontFace,
                    Advances   = new[] { (float)Math.Ceiling(advanceWidth) },
                    FontSize   = fontSize,
                    BidiLevel  = 0,
                    Indices    = indices,
                    IsSideways = false,
                    Offsets    = new[] { new GlyphOffset() }
                };


                RenderingMode renderingMode;
                if (antiAliasMode != FontAntiAliasMode.Aliased)
                {
                    var rtParams = new RenderingParams(factory);
                    renderingMode = fontFace.GetRecommendedRenderingMode(fontSize, 1.0f, MeasuringMode.Natural, rtParams);
                    rtParams.Dispose();
                }
                else
                {
                    renderingMode = RenderingMode.Aliased;
                }

                using (var runAnalysis = new GlyphRunAnalysis(factory,
                                                              glyphRun,
                                                              1.0f,
                                                              matrix,
                                                              renderingMode,
                                                              MeasuringMode.Natural,
                                                              0.0f,
                                                              0.0f))
                {
                    var bounds = new RawRectangle(0, 0, pixelWidth, pixelHeight);
                    bitmap = new Bitmap(pixelWidth, pixelHeight, PixelFormat.Format32bppArgb);

                    if (renderingMode == RenderingMode.Aliased)
                    {
                        var texture = new byte[pixelWidth * pixelHeight];
                        runAnalysis.CreateAlphaTexture(TextureType.Aliased1x1, bounds, texture, texture.Length);
                        for (int y = 0; y < pixelHeight; y++)
                        {
                            for (int x = 0; x < pixelWidth; x++)
                            {
                                int pixelX = y * pixelWidth + x;
                                var grey   = texture[pixelX];
                                var color  = Color.FromArgb(grey, grey, grey);

                                bitmap.SetPixel(x, y, color);
                            }
                        }
                    }
                    else
                    {
                        var texture = new byte[pixelWidth * pixelHeight * 3];
                        runAnalysis.CreateAlphaTexture(TextureType.Cleartype3x1, bounds, texture, texture.Length);
                        for (int y = 0; y < pixelHeight; y++)
                        {
                            for (int x = 0; x < pixelWidth; x++)
                            {
                                int pixelX = (y * pixelWidth + x) * 3;
                                var red    = LinearToGamma(texture[pixelX]);
                                var green  = LinearToGamma(texture[pixelX + 1]);
                                var blue   = LinearToGamma(texture[pixelX + 2]);
                                var color  = Color.FromArgb(red, green, blue);

                                bitmap.SetPixel(x, y, color);
                            }
                        }
                    }
                }
            }

            var glyph = new Glyph(character, bitmap)
            {
                XOffset  = -matrix.M31,
                XAdvance = advanceWidth,
                YOffset  = -matrix.M32,
            };

            return(glyph);
        }
Esempio n. 8
0
        public SpriteFont NewDynamic(float defaultSize, string fontName, FontStyle style, FontAntiAliasMode antiAliasMode = FontAntiAliasMode.Default, bool useKerning = false, float extraSpacing = 0, float extraLineSpacing = 0, char defaultCharacter = ' ')
        {
            var font = new RuntimeRasterizedSpriteFont
            {
                Size             = defaultSize,
                FontName         = fontName,
                Style            = style,
                AntiAlias        = antiAliasMode,
                UseKerning       = useKerning,
                ExtraSpacing     = extraSpacing,
                ExtraLineSpacing = extraLineSpacing,
                DefaultCharacter = defaultCharacter,
                FontSystem       = this,
            };

            return(font);
        }
        private Glyph ImportGlyph(Factory factory, FontFace fontFace, char character, FontMetrics fontMetrics, float fontSize, FontAntiAliasMode antiAliasMode)
        {
            var indices = fontFace.GetGlyphIndices(new int[] { character });

            var metrics = fontFace.GetDesignGlyphMetrics(indices, false);
            var metric = metrics[0];

            var width = (float)(metric.AdvanceWidth - metric.LeftSideBearing - metric.RightSideBearing) / fontMetrics.DesignUnitsPerEm * fontSize;
            var height = (float)(metric.AdvanceHeight - metric.TopSideBearing - metric.BottomSideBearing) / fontMetrics.DesignUnitsPerEm * fontSize;

            var xOffset = (float)metric.LeftSideBearing / fontMetrics.DesignUnitsPerEm * fontSize;
            var yOffset = (float)(metric.TopSideBearing - metric.VerticalOriginY) / fontMetrics.DesignUnitsPerEm * fontSize;

            var advanceWidth = (float)metric.AdvanceWidth / fontMetrics.DesignUnitsPerEm * fontSize;
            //var advanceHeight = (float)metric.AdvanceHeight / fontMetrics.DesignUnitsPerEm * fontSize;

            var pixelWidth = (int)Math.Ceiling(width + 4);
            var pixelHeight = (int)Math.Ceiling(height + 4);

            var matrix = new RawMatrix3x2
            {
                M11 = 1,
                M22 = 1,
                M31 = -(float)Math.Floor(xOffset) + 1,
                M32 = -(float)Math.Floor(yOffset) + 1
            };

            Bitmap bitmap;
            if (char.IsWhiteSpace(character))
            {
                bitmap = new Bitmap(1, 1, PixelFormat.Format32bppArgb);
            }
            else
            {
                var glyphRun = new GlyphRun
                {
                    FontFace = fontFace,
                    Advances = new[] { (float)Math.Ceiling(advanceWidth) },
                    FontSize = fontSize,
                    BidiLevel = 0,
                    Indices = indices,
                    IsSideways = false,
                    Offsets = new[] { new GlyphOffset() }
                };


                RenderingMode renderingMode;
                if (antiAliasMode != FontAntiAliasMode.Aliased)
                {
                    var rtParams = new RenderingParams(factory);
                    renderingMode = fontFace.GetRecommendedRenderingMode(fontSize, 1.0f, MeasuringMode.Natural, rtParams);
                    rtParams.Dispose();
                }
                else
                {
                    renderingMode = RenderingMode.Aliased;
                }

                using (var runAnalysis = new GlyphRunAnalysis(factory,
                    glyphRun,
                    1.0f,
                    matrix,
                    renderingMode,
                    MeasuringMode.Natural,
                    0.0f,
                    0.0f))
                {

                    var bounds = new RawRectangle(0, 0, pixelWidth, pixelHeight);
                    bitmap = new Bitmap(pixelWidth, pixelHeight, PixelFormat.Format32bppArgb);

                    if (renderingMode == RenderingMode.Aliased)
                    {

                        var texture = new byte[pixelWidth * pixelHeight];
                        runAnalysis.CreateAlphaTexture(TextureType.Aliased1x1, bounds, texture, texture.Length);
                        for (int y = 0; y < pixelHeight; y++)
                        {
                            for (int x = 0; x < pixelWidth; x++)
                            {
                                int pixelX = y * pixelWidth + x;
                                var grey = texture[pixelX];
                                var color = Color.FromArgb(grey, grey, grey);

                                bitmap.SetPixel(x, y, color);
                            }
                        }
                    }
                    else
                    {
                        var texture = new byte[pixelWidth * pixelHeight * 3];
                        runAnalysis.CreateAlphaTexture(TextureType.Cleartype3x1, bounds, texture, texture.Length);
                        for (int y = 0; y < pixelHeight; y++)
                        {
                            for (int x = 0; x < pixelWidth; x++)
                            {
                                int pixelX = (y * pixelWidth + x) * 3;
                                var red = LinearToGamma(texture[pixelX]);
                                var green = LinearToGamma(texture[pixelX + 1]);
                                var blue = LinearToGamma(texture[pixelX + 2]);
                                var color = Color.FromArgb(red, green, blue);

                                bitmap.SetPixel(x, y, color);
                            }
                        }
                    }
                }
            }

            var glyph = new Glyph(character, bitmap)
            {
                XOffset = -matrix.M31,
                XAdvance = advanceWidth,
                YOffset = -matrix.M32,
            };
            return glyph;
        }
Esempio n. 10
0
 public SpriteFont NewDynamic(float defaultSize, string fontName, FontStyle style, FontAntiAliasMode antiAliasMode, bool useKerning, float extraSpacing, float extraLineSpacing, char defaultCharacter)
 {
     return(new RuntimeRasterizedSpriteFont
     {
         Size = defaultSize,
         DefaultCharacter = defaultCharacter,
         FontName = fontName,
         ExtraLineSpacing = extraLineSpacing,
         ExtraSpacing = extraSpacing,
         Style = style,
         UseKerning = useKerning,
         AntiAlias = antiAliasMode,
     });
 }
Esempio n. 11
0
 /// <summary>
 /// Function to create a new font texture object from a GDI+ font.
 /// </summary>
 /// <param name="fontName">Name of the font texture object.</param>
 /// <param name="font">GDI+ font to use.</param>
 /// <param name="antiAliasMode">Anti-aliasing mode.</param>
 /// <returns>The new font texture object.</returns>
 /// <remarks>This method creates an object that contains a group of textures with font glyphs.  These textures can be used by another application to
 /// display text (or symbols) on the screen.  Kerning information (the proper spacing for a glyph) is included in the glyphs and font.
 /// <para>Please note that the <paramref name="fontName"/> parameter is user defined and does not have to be the same as the font family name in the <paramref name="font"/> parameter.</para>
 /// <para>Fonts may only be created on the immediate context.</para>
 /// </remarks>
 /// <exception cref="System.ArgumentNullException">Thrown when the fontName or <paramref name="font"/> parameters are NULL (Nothing in VB.Net).</exception>
 /// <exception cref="System.ArgumentException">Thrown when the fontName parameter is an empty string.</exception>
 /// <exception cref="GorgonLibrary.GorgonException">Thrown if the graphics context is deferred.</exception>
 public GorgonFont CreateFont(string fontName, Font font, FontAntiAliasMode antiAliasMode)
 {
     return(CreateFont(fontName, font, antiAliasMode, new Size(256, 256)));
 }
Esempio n. 12
0
        /// <summary>
        /// Function to create a new font texture object from a GDI+ font.
        /// </summary>
        /// <param name="fontName">Name of the font texture object.</param>
        /// <param name="fontFamily">Font family to use.</param>
        /// <param name="pointSize">Point size for the font.</param>
        /// <param name="style">Style to apply to the font.</param>
        /// <param name="antiAliasMode">Anti-aliasing mode.</param>
        /// <param name="textureSize">Size of the textures to generate.</param>
        /// <returns>The new font texture object.</returns>
        /// <remarks>This method creates an object that contains a group of textures with font glyphs.  These textures can be used by another application to
        /// display text (or symbols) on the screen.  Kerning information (the proper spacing for a glyph) is included in the glyphs and font.
        /// <para>Please note that the <paramref name="fontName"/> parameter is user defined and does not have to be the same as the <paramref name="fontFamily"/> parameter.</para>
        /// <para>Fonts may only be created on the immediate context.</para>
        /// </remarks>
        /// <exception cref="System.ArgumentNullException">Thrown when the fontName or fontFamily parameters are NULL (Nothing in VB.Net).</exception>
        /// <exception cref="System.ArgumentException">Thrown when the fontName or fontFamily parameters are empty strings.
        /// <para>-or-</para>
        /// <para>Thrown when the <paramref name="textureSize"/> width or height is larger than can be handled by the current feature level.</para>
        /// </exception>
        /// <exception cref="GorgonLibrary.GorgonException">Thrown if the graphics context is deferred.</exception>
        public GorgonFont CreateFont(string fontName, string fontFamily, float pointSize, FontStyle style, FontAntiAliasMode antiAliasMode, Size textureSize)
        {
            if (pointSize < 1e-6f)
            {
                pointSize = 1e-6f;
            }

            var settings = new GorgonFontSettings
            {
                AntiAliasingMode = antiAliasMode,
                Brush            = null,
                FontFamilyName   = fontFamily,
                FontStyle        = style,
                Size             = pointSize,
                TextureSize      = textureSize
            };

            return(CreateFont(fontName, settings));
        }
Esempio n. 13
0
 /// <summary>
 /// Function to create a new font texture object from a GDI+ font.
 /// </summary>
 /// <param name="fontName">Name of the font texture object.</param>
 /// <param name="fontFamily">Font family to use.</param>
 /// <param name="pointSize">Point size for the font.</param>
 /// <param name="antiAliasMode">Anti-aliasing mode.</param>
 /// <param name="textureSize">Size of the textures to generate.</param>
 /// <returns>The new font texture object.</returns>
 /// <remarks>This method creates an object that contains a group of textures with font glyphs.  These textures can be used by another application to
 /// display text (or symbols) on the screen.  Kerning information (the proper spacing for a glyph) is included in the glyphs and font.
 /// <para>Please note that the <paramref name="fontName"/> parameter is user defined and does not have to be the same as the <paramref name="fontFamily"/> parameter.</para>
 /// <para>Fonts may only be created on the immediate context.</para>
 /// </remarks>
 /// <exception cref="System.ArgumentNullException">Thrown when the fontName or fontFamily parameters are NULL (Nothing in VB.Net).</exception>
 /// <exception cref="System.ArgumentException">Thrown when the fontName or fontFamily parameters are empty strings.
 /// <para>-or-</para>
 /// <para>Thrown when the <paramref name="textureSize"/> width or height is larger than can be handled by the current feature level.</para>
 /// </exception>
 /// <exception cref="GorgonLibrary.GorgonException">Thrown if the graphics context is deferred.</exception>
 public GorgonFont CreateFont(string fontName, string fontFamily, float pointSize, FontAntiAliasMode antiAliasMode, Size textureSize)
 {
     return(CreateFont(fontName, fontFamily, pointSize, FontStyle.Regular, antiAliasMode, textureSize));
 }