Example #1
0
        internal static bool TryGetCharacterBounds(IReadOnlyList <GlyphLayout> glyphLayouts, Vector2 dpi, out GlyphMetric[] characterBounds)
        {
            bool hasSize = false;

            if (glyphLayouts.Count == 0)
            {
                characterBounds = EmptyGlyphMetricArray;
                return(hasSize);
            }

            var characterBoundsList = new GlyphMetric[glyphLayouts.Count];

            for (int i = 0; i < glyphLayouts.Count; i++)
            {
                GlyphLayout c = glyphLayouts[i];

                // TODO: This sets the hasSize value to the last layout... is this correct?
                if (!c.IsControlCharacter)
                {
                    hasSize = true;
                }

                characterBoundsList[i] = new GlyphMetric(c.CodePoint, c.BoundingBox(dpi), c.IsControlCharacter);
            }

            characterBounds = characterBoundsList;
            return(hasSize);
        }
Example #2
0
        internal static FontRectangle GetBounds(IReadOnlyList <GlyphLayout> glyphLayouts, Vector2 dpi)
        {
            if (glyphLayouts.Count == 0)
            {
                return(FontRectangle.Empty);
            }

            bool hasSize = false;

            float left   = int.MaxValue;
            float top    = int.MaxValue;
            float bottom = int.MinValue;
            float right  = int.MinValue;

            for (int i = 0; i < glyphLayouts.Count; i++)
            {
                GlyphLayout c = glyphLayouts[i];
                if (!c.IsControlCharacter)
                {
                    hasSize = true;
                    FontRectangle box = c.BoundingBox(dpi);
                    if (left > box.Left)
                    {
                        left = box.Left;
                    }

                    if (top > box.Top)
                    {
                        top = box.Top;
                    }

                    if (bottom < box.Bottom)
                    {
                        bottom = box.Bottom;
                    }

                    if (right < box.Right)
                    {
                        right = box.Right;
                    }
                }
            }

            if (!hasSize)
            {
                return(FontRectangle.Empty);
            }

            float width  = right - left;
            float height = bottom - top;

            return(new FontRectangle(left, top, width, height));
        }
        internal static bool TryGetCharacterBounds(IReadOnlyList <GlyphLayout> glyphLayouts, float dpi, out GlyphBounds[] characterBounds)
        {
            bool hasSize = false;

            if (glyphLayouts.Count == 0)
            {
                characterBounds = Array.Empty <GlyphBounds>();
                return(hasSize);
            }

            var characterBoundsList = new GlyphBounds[glyphLayouts.Count];

            for (int i = 0; i < glyphLayouts.Count; i++)
            {
                GlyphLayout g = glyphLayouts[i];
                hasSize |= !g.IsStartOfLine;
                characterBoundsList[i] = new GlyphBounds(g.Glyph.GlyphMetrics.CodePoint, g.BoundingBox(dpi));
            }

            characterBounds = characterBoundsList;
            return(hasSize);
        }