Exemplo n.º 1
0
        public static GlyphString Concat(GlyphString g1, GlyphString g2)
        {
            if (g1 == null)
            {
                return(g2);
            }
            if (g2 == null)
            {
                return(g1);
            }

            int concatLen = g1.Length + g2.Length;

            GlyphChar[] arr = new GlyphChar[concatLen];
            Array.Copy(g1.Glyphs, arr, g1.Length);

            // Attention: Very confusing parameter order in the
            // many overloads for the System.Array functions
            // here we use: SourceArray, SourceIndex, DestArray, DestIndex, DestLength (hopefully)
            Array.Copy(g2.Glyphs, 0, arr, g1.Length, g2.Length);

            GlyphString result = new GlyphString(arr);

            result.Length = concatLen;
            result.Width  = g1.Width + g2.Width;
            return(result);
        }
Exemplo n.º 2
0
        public static GlyphString SubString(GlyphString g, int start, int length)
        {
            if (g == null)
            {
                return(null);
            }
            length = Math.Min(length, g.Length - (length - start + 1));
            if (length <= 0)
            {
                return(new GlyphString());
            }

            GlyphChar[] arr = new GlyphChar[length];
            Array.Copy(g.Glyphs, arr, length);

            GlyphString result = new GlyphString(arr);

            result.Length = length;
            result.Width  = arr.Sum(p => p.Width);
            return(result);
        }