/// <summary>
        /// Creates a <see cref="StringSegment"/> structure that represents this string source.
        /// </summary>
        /// <returns>The <see cref="StringSegment"/> that was created.</returns>
        public StringSegment CreateStringSegment()
        {
            switch (ValueType)
            {
            case StringSourceUnionValueType.String:
                return(StringSource.CreateStringSegment());

            case StringSourceUnionValueType.StringBuilder:
                return(StringBuilderSource.CreateStringSegment());

            case StringSourceUnionValueType.StringSegment:
                return(StringSegmentSource.CreateStringSegment());

            case StringSourceUnionValueType.ShapedString:
            case StringSourceUnionValueType.ShapedStringBuilder:
            case StringSourceUnionValueType.ShapedStringSegment:
                throw new NotSupportedException();

            default:
                throw new InvalidOperationException();
            }
        }
        /// <summary>
        /// Creates a <see cref="StringSegment"/> structure with the same origin as this
        /// string source but a different character range. This method only differs from
        /// the <see cref="CreateStringSegmentFromSubstring(Int32, Int32)"/> method if this
        /// string source represents a substring of some other, larger string.
        /// </summary>
        /// <param name="start">The index of the first character in the created segment.</param>
        /// <param name="length">The number of characters in the created segment.</param>
        /// <returns>The <see cref="StringSegment"/> structure that was created.</returns>
        public StringSegment CreateStringSegmentFromSameOrigin(Int32 start, Int32 length)
        {
            switch (ValueType)
            {
            case StringSourceUnionValueType.String:
                return(StringSource.CreateStringSegmentFromSameOrigin(start, length));

            case StringSourceUnionValueType.StringBuilder:
                return(StringBuilderSource.CreateStringSegmentFromSameOrigin(start, length));

            case StringSourceUnionValueType.StringSegment:
                return(StringSegmentSource.CreateStringSegmentFromSameOrigin(start, length));

            case StringSourceUnionValueType.ShapedString:
            case StringSourceUnionValueType.ShapedStringBuilder:
            case StringSourceUnionValueType.ShapedStringSegment:
                throw new NotSupportedException();

            default:
                throw new InvalidOperationException();
            }
        }
        /// <inheritdoc/>
        public override Size2 MeasureGlyph(StringBuilder text, Int32 ix)
        {
            var source = new StringBuilderSource(text);

            return(MeasureGlyph(ref source, ix));
        }
        /// <inheritdoc/>
        public override Size2 MeasureString(StringBuilder text, Int32 start, Int32 count)
        {
            var source = new StringBuilderSource(text);

            return(MeasureString(ref source, start, count));
        }
        /// <inheritdoc/>
        public override Size2 MeasureString(StringBuilder text)
        {
            var source = new StringBuilderSource(text);

            return(MeasureString(ref source, 0, text.Length));
        }