/// <summary>Indicates whether the current object is equal to another object of the same type.</summary>
        /// <param name="other">An object to compare with this object.</param>
        /// <returns>
        ///   <span class="keyword">
        ///     <span class="languageSpecificText">
        ///       <span class="cs">true</span>
        ///       <span class="vb">True</span>
        ///       <span class="cpp">true</span>
        ///     </span>
        ///   </span>
        ///   <span class="nu">
        ///     <span class="keyword">true</span> (<span class="keyword">True</span> in Visual Basic)</span> if the current object is equal to the <paramref name="other" /> parameter; otherwise, <span class="keyword"><span class="languageSpecificText"><span class="cs">false</span><span class="vb">False</span><span class="cpp">false</span></span></span><span class="nu"><span class="keyword">false</span> (<span class="keyword">False</span> in Visual Basic)</span>.
        /// </returns>
        public override bool Equals(GorgonGlyphBrush other)
        {
            var brush = other as GorgonGlyphHatchBrush;

            return((brush == this) || ((brush != null) &&
                                       (brush.HatchStyle == HatchStyle) &&
                                       (brush.BackgroundColor == BackgroundColor) &&
                                       (brush.ForegroundColor == ForegroundColor)));
        }
        /// <summary>Indicates whether the current object is equal to another object of the same type.</summary>
        /// <param name="other">An object to compare with this object.</param>
        /// <returns>
        ///   <span class="keyword">
        ///     <span class="languageSpecificText">
        ///       <span class="cs">true</span>
        ///       <span class="vb">True</span>
        ///       <span class="cpp">true</span>
        ///     </span>
        ///   </span>
        ///   <span class="nu">
        ///     <span class="keyword">true</span> (<span class="keyword">True</span> in Visual Basic)</span> if the current object is equal to the <paramref name="other" /> parameter; otherwise, <span class="keyword"><span class="languageSpecificText"><span class="cs">false</span><span class="vb">False</span><span class="cpp">false</span></span></span><span class="nu"><span class="keyword">false</span> (<span class="keyword">False</span> in Visual Basic)</span>.
        /// </returns>
        public override bool Equals(GorgonGlyphBrush other)
        {
            var brush = other as GorgonGlyphLinearGradientBrush;

            return((brush == this) || ((brush != null) &&
                                       (brush.Angle.EqualsEpsilon(Angle)) &&
                                       (brush.ScaleAngle == ScaleAngle) &&
                                       (brush.GammaCorrection == GammaCorrection) &&
                                       (brush.Interpolation.SequenceEqual(Interpolation))));
        }
        /// <summary>Indicates whether the current object is equal to another object of the same type.</summary>
        /// <param name="other">An object to compare with this object.</param>
        /// <returns>
        ///   <span class="keyword">
        ///     <span class="languageSpecificText">
        ///       <span class="cs">true</span>
        ///       <span class="vb">True</span>
        ///       <span class="cpp">true</span>
        ///     </span>
        ///   </span>
        ///   <span class="nu">
        ///     <span class="keyword">true</span> (<span class="keyword">True</span> in Visual Basic)</span> if the current object is equal to the <paramref name="other" /> parameter; otherwise, <span class="keyword"><span class="languageSpecificText"><span class="cs">false</span><span class="vb">False</span><span class="cpp">false</span></span></span><span class="nu"><span class="keyword">false</span> (<span class="keyword">False</span> in Visual Basic)</span>.
        /// </returns>
        public override bool Equals(GorgonGlyphBrush other)
        {
            var brush = other as GorgonGlyphPathGradientBrush;

            return((brush == this) || ((brush != null) &&
                                       (brush.WrapMode == WrapMode) &&
                                       (brush.CenterColor == CenterColor) &&
                                       (brush.CenterPoint.Equals(CenterPoint)) &&
                                       (brush.FocusScales.Equals(FocusScales)) &&
                                       (brush.Points.SequenceEqual(Points)) &&
                                       (brush.BlendFactors.SequenceEqual(BlendFactors)) &&
                                       (brush.BlendPositions.SequenceEqual(BlendPositions)) &&
                                       (brush.Interpolation.SequenceEqual(Interpolation)) &&
                                       (brush.SurroundColors.SequenceEqual(SurroundColors))));
        }
예제 #4
0
        public Dictionary <char, GlyphInfo> DrawToPackedBitmaps(List <char> characters, Dictionary <char, GlyphRegions> glyphBounds, bool hasOutline)
        {
            var result = new Dictionary <char, GlyphInfo>();

            System.Drawing.Graphics packedGraphics = null;
            DX.Size2         maxGlyphSize          = GetMaxGlyphSize(glyphBounds, hasOutline);
            var              glyphBitmap           = new Bitmap(maxGlyphSize.Width + 10, maxGlyphSize.Height + 10, PixelFormat.Format32bppArgb);
            var              glyphGraphics         = System.Drawing.Graphics.FromImage(glyphBitmap);
            GorgonGlyphBrush glyphBrush            = _fontInfo.Brush ?? new GorgonGlyphSolidBrush
            {
                Color = GorgonColor.White
            };

            try
            {
                glyphGraphics.PageUnit           = GraphicsUnit.Pixel;
                glyphGraphics.CompositingMode    = CompositingMode.SourceOver;
                glyphGraphics.CompositingQuality = CompositingQuality.HighQuality;

                switch (_fontInfo.AntiAliasingMode)
                {
                case FontAntiAliasMode.AntiAlias:
                    glyphGraphics.SmoothingMode     = SmoothingMode.AntiAlias;
                    glyphGraphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                    break;

                default:
                    glyphGraphics.SmoothingMode     = SmoothingMode.None;
                    glyphGraphics.InterpolationMode = InterpolationMode.NearestNeighbor;
                    break;
                }

                while (characters.Count > 0)
                {
                    var packedBitmap = new Bitmap(_fontInfo.TextureWidth, _fontInfo.TextureHeight, PixelFormat.Format32bppArgb);
                    packedGraphics?.Dispose();
                    packedGraphics = System.Drawing.Graphics.FromImage(packedBitmap);

                    packedGraphics.CompositingMode    = CompositingMode.SourceCopy;
                    packedGraphics.CompositingQuality = CompositingQuality.HighQuality;

                    packedGraphics.Clear(Color.FromArgb(0));

                    // Sort by size.
                    characters.Sort((left, right) =>
                    {
                        var leftSize  = new DX.Size2(glyphBounds[left].CharacterRegion.Width, glyphBounds[left].CharacterRegion.Height);
                        var rightSize = new DX.Size2(glyphBounds[right].CharacterRegion.Width, glyphBounds[right].CharacterRegion.Height);

                        return(leftSize.Height == rightSize.Height ? left.CompareTo(right) : leftSize.Height < rightSize.Height ? 1 : -1);
                    });

                    GlyphPacker.CreateRoot(_fontInfo.TextureWidth - _fontInfo.PackingSpacing, _fontInfo.TextureHeight - _fontInfo.PackingSpacing);

                    RasterizeGlyphs(packedGraphics, glyphGraphics, packedBitmap, glyphBitmap, characters, glyphBounds, result, glyphBrush, hasOutline);

                    packedGraphics.Flush();
                }
            }
            finally
            {
                packedGraphics?.Dispose();
                glyphGraphics.Dispose();
                glyphBitmap.Dispose();
            }

            return(result);
        }
예제 #5
0
        /// <summary>
        /// Function to rasterize a series of glyphs to a packed bitmap.
        /// </summary>
        /// <param name="packedGraphics">The graphics context for the packed bitmap.</param>
        /// <param name="glyphGraphics">The graphics context for the glyph bitmap.</param>
        /// <param name="packedBitmap">The packed bitmap.</param>
        /// <param name="glyphBitmap">The glyph bitmap.</param>
        /// <param name="characters">The list of characters to use as glyphs.</param>
        /// <param name="glyphBounds">The list of boundaries for the glyphs.</param>
        /// <param name="packedGlyphs">The resulting set of packed glyphs.</param>
        /// <param name="brush">The brush used to draw the glyphs.</param>
        /// <param name="hasOutline"><b>true</b> if the font contains an outline, <b>false</b> if not.</param>
        private void RasterizeGlyphs(System.Drawing.Graphics packedGraphics,
                                     System.Drawing.Graphics glyphGraphics,
                                     Bitmap packedBitmap,
                                     Bitmap glyphBitmap,
                                     List <char> characters,
                                     Dictionary <char, GlyphRegions> glyphBounds,
                                     Dictionary <char, GlyphInfo> packedGlyphs,
                                     GorgonGlyphBrush brush,
                                     bool hasOutline)
        {
            int index        = 0;
            int packingSpace = _fontInfo.PackingSpacing > 0 ? _fontInfo.PackingSpacing * 2 : 1;

            while (index < characters.Count)
            {
                char character = characters[index];

                // If we've already put this glyph in, then skip it.
                if (packedGlyphs.ContainsKey(character))
                {
                    characters.Remove(character);
                    continue;
                }

                DX.Rectangle charRect = glyphBounds[character].CharacterRegion;

                // Skip whitespace characters. These won't be drawn, just measured.
                if (char.IsWhiteSpace(character))
                {
                    characters.Remove(character);
                    packedGlyphs[character] = new GlyphInfo(null, new DX.Rectangle(0, 0, charRect.Width + 1, charRect.Height + 1), DX.Point.Zero, DX.Rectangle.Empty, DX.Point.Zero);
                    continue;
                }

                DX.Rectangle outlineRect = glyphBounds[character].OutlineRegion;

                var size = new DX.Size2(charRect.Width + 1, charRect.Height + 1);

                Rectangle?placement        = GlyphPacker.Add(new Size(charRect.Width + packingSpace, charRect.Height + packingSpace));
                Rectangle?outlinePlacement = null;

                if ((hasOutline) && (!outlineRect.IsEmpty))
                {
                    outlinePlacement = GlyphPacker.Add(new Size(outlineRect.Width + packingSpace, outlineRect.Height + packingSpace));
                }

                if ((placement == null) ||
                    ((hasOutline) && (outlinePlacement == null) && (!outlineRect.IsEmpty)))
                {
                    ++index;
                    continue;
                }

                characters.Remove(character);

                Point location        = placement.Value.Location;
                Point outlineLocation = outlinePlacement?.Location ?? Point.Empty;

                location.X += _fontInfo.PackingSpacing;
                location.Y += _fontInfo.PackingSpacing;

                // If we're using a linear gradient, then we have to define the bounds for that gradient.
                if (brush.BrushType == GlyphBrushType.LinearGradient)
                {
                    ((GorgonGlyphLinearGradientBrush)brush).GradientRegion = new DX.Rectangle(charRect.Left, charRect.Top, charRect.Width, charRect.Height);
                }

                using (Brush gdiBrush = brush.ToGDIBrush())
                {
                    // Draw the main character glyph.
                    DrawGlyphCharacter(character, glyphBitmap, glyphGraphics, gdiBrush);

                    packedGraphics.DrawImage(glyphBitmap,
                                             new Rectangle(location.X, location.Y, size.Width, size.Height),
                                             new Rectangle(charRect.X, charRect.Y, size.Width, size.Height),
                                             GraphicsUnit.Pixel);

                    // Draw the outline for the character glyph.
                    if ((hasOutline) && (!outlineRect.IsEmpty))
                    {
                        outlineLocation.X += _fontInfo.PackingSpacing;
                        outlineLocation.Y += _fontInfo.PackingSpacing;
                        DrawGlyphCharacterOutline(character, glyphBitmap, glyphGraphics);

                        packedGraphics.DrawImage(glyphBitmap,
                                                 new Rectangle(outlineLocation.X, outlineLocation.Y, outlineRect.Width + 1, outlineRect.Height + 1),
                                                 new Rectangle(outlineRect.X, outlineRect.Y, outlineRect.Width + 1, outlineRect.Height + 1),
                                                 GraphicsUnit.Pixel);
                    }

                    packedGlyphs[character] = new GlyphInfo(packedBitmap,
                                                            new DX.Rectangle(location.X, location.Y, size.Width, size.Height),
                                                            new DX.Point(charRect.X, charRect.Y),
                                                            new DX.Rectangle(outlineLocation.X, outlineLocation.Y, outlineRect.Width + 1, outlineRect.Height + 1),
                                                            new DX.Point(outlineRect.X, outlineRect.Y));
                }
            }
        }
        /// <summary>Indicates whether the current object is equal to another object of the same type.</summary>
        /// <param name="other">An object to compare with this object.</param>
        /// <returns>
        ///   <span class="keyword">
        ///     <span class="languageSpecificText">
        ///       <span class="cs">true</span>
        ///       <span class="vb">True</span>
        ///       <span class="cpp">true</span>
        ///     </span>
        ///   </span>
        ///   <span class="nu">
        ///     <span class="keyword">true</span> (<span class="keyword">True</span> in Visual Basic)</span> if the current object is equal to the <paramref name="other" /> parameter; otherwise, <span class="keyword"><span class="languageSpecificText"><span class="cs">false</span><span class="vb">False</span><span class="cpp">false</span></span></span><span class="nu"><span class="keyword">false</span> (<span class="keyword">False</span> in Visual Basic)</span>.
        /// </returns>
        public override bool Equals(GorgonGlyphBrush other)
        {
            var brush = other as GorgonGlyphSolidBrush;

            return((brush == this) || ((brush != null) && (brush.Color == Color)));
        }