Ejemplo n.º 1
0
        protected override ILine ProduceChild(IDocumentBuffer documentBuffer, IDimensionConstraint childConstraint)
        {
            var line = this.elementFactory.CreateLine(this.flags);

            line.Insert(documentBuffer, childConstraint);
            return(line);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Takes the remaining text that fits the flag, until a limit by the maxLength, removing that text from the buffer.
        /// </summary>
        /// <returns></returns>
        public string Take(IDimensionConstraint constraint, IFlags flags)
        {
            this.ThrowIfBufferIsEmpty();

            if (constraint.MaxWidth == null)
            {
                throw new Exception("A max width must be provided in the constraint.");
            }

            var first = this.elements.First();

            if (first.Flags == null || (flags != null && !first.Flags.Equals(flags)))
            {
                return(null);
            }

            var text = this.textScoper.GetFittingText(first.Flags.Font, first.Flags.FontSize, first.Text, (double)constraint.MaxWidth);

            if (text == first.Text)
            {
                this.elements.RemoveAt(0);
            }
            else if (text != String.Empty)
            {
                this.elements[0] = new BufferElement()
                {
                    Text  = Strings.strsubutf8(first.Text, Strings.strlenutf8(text)),
                    Flags = first.Flags,
                };
            }
            return(text);
        }
Ejemplo n.º 3
0
 protected override IDimensionConstraint GetConstraint(IDimensionConstraint originalConstraint, double widthUsed)
 {
     return(new DimensionConstraint()
     {
         MaxHeight = originalConstraint.MaxHeight,
         MaxWidth = originalConstraint.MaxWidth - widthUsed,
     });
 }
Ejemplo n.º 4
0
 protected override IDimensionConstraint GetConstraint(IDimensionConstraint oritiConstraint, double heightUsed)
 {
     return(new DimensionConstraint()
     {
         MaxHeight = this.properties.Height - (this.properties.EdgeTop + this.properties.EdgeBottom + heightUsed),
         MaxWidth = this.properties.Width - (this.properties.EdgeLeft + this.properties.EdgeRight),
     });
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Insers the content of the document buffer into itself and sub containers.
        /// </summary>
        /// <param name="documentBuffer">The document buffer.</param>
        /// <param name="dimensionConstraint">The constraining dimensions.</param>
        public void Insert(IDocumentBuffer documentBuffer, IDimensionConstraint dimensionConstraint)
        {
            if (dimensionConstraint.MaxWidth == null)
            {
                throw new Exception("The formatted text object must be given a width constraint on insert.");
            }

            var textBeforeCursor   = Strings.strsubutf8(this.text, 0, this.cursorPos);
            var xBeforeCursor      = this.textScoper.GetWidth(this.flags.Font, this.flags.FontSize, textBeforeCursor);
            var availableDimension = new DimensionConstraint()
            {
                MaxWidth  = (double)dimensionConstraint.MaxWidth - xBeforeCursor,
                MaxHeight = dimensionConstraint.MaxHeight,
            };

            var addedText = documentBuffer.Take(availableDimension, this.GetCurrentFlags());

            if (addedText == String.Empty)
            {
                return;
            }

            var addedTextSize = Strings.strlenutf8(addedText);

            if (this.cursorPos < this.GetLength()) // The cursor is not and the end. The inserted text is thus put in at the cursor position
            {
                var textAfterCursor = Strings.strsubutf8(this.text, this.cursorPos);
                this.text = Strings.strsubutf8(this.text, 0, this.cursorPos);

                var bufferEmpty = documentBuffer.EndOfBuffer();

                documentBuffer.Append(textAfterCursor, this.GetCurrentFlags());

                if (bufferEmpty)
                {
                    availableDimension = new DimensionConstraint()
                    {
                        MaxWidth  = (double)dimensionConstraint.MaxWidth - this.textScoper.GetWidth(this.flags.Font, this.flags.FontSize, this.text + addedText),
                        MaxHeight = dimensionConstraint.MaxHeight,
                    };

                    addedText += documentBuffer.Take(availableDimension, this.GetCurrentFlags());
                }
            }

            if (this.cursor != null)
            {
                this.cursorPos += addedTextSize;
                this.CursorChanged();
            }

            this.text += addedText;
            this.TextChanged();
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Peeks the remaining text that fits the flag, until a limit by the maxLength.
        /// </summary>
        /// <param name="constraint">The constraints the text must fit.</param>
        /// <param name="flags">The flags the text must fit.</param>
        /// <returns>The peeked text.</returns>
        public string Peek(IDimensionConstraint constraint, IFlags flags)
        {
            this.ThrowIfBufferIsEmpty();

            if (constraint.MaxWidth == null)
            {
                throw new Exception("A max width must be provided in the constraint.");
            }


            var first = this.elements.First();

            if (first.Flags == null || (flags != null && !first.Flags.Equals(flags)))
            {
                return(null);
            }

            return(this.textScoper.GetFittingText(first.Flags.Font, first.Flags.FontSize, first.Text, (double)constraint.MaxWidth));
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Gets the next element if it fits within the given constraint without removing it from the buffer.
        /// </summary>
        /// <param name="constraint">The constraint the resulting element should fit in.</param>
        /// <returns>The resulting element.</returns>
        public IElement Peek(IDimensionConstraint constraint)
        {
            this.ThrowIfBufferIsEmpty();

            if (constraint.MaxWidth == null)
            {
                throw new Exception("A max width must be provided in the constraint.");
            }

            if (constraint.MaxHeight == null)
            {
                throw new Exception("A max height must be provided in the constraint.");
            }

            var first = this.elements.First();

            if (first.Flags != null)
            {
                var text = this.Peek(constraint, first.Flags);
                if (text == String.Empty)
                {
                    return(null);
                }

                var formattedText = (IFormattedText)elementFactory.Create(first.Flags);
                formattedText.SetText(text);
                return(formattedText);
            }

            if (first.Element == null || first.Element.GetWidth() > constraint.MaxWidth || first.Element.GetHeight() > constraint.MaxHeight)
            {
                return(null);
            }

            return(first.Element);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Takes the next element if it fits within the given constraint, removing it from the buffer.
        /// </summary>
        /// <param name="constraint">The constraint the resulting element should fit in.</param>
        /// <returns>The resulting element.</returns>
        public IElement Take(IDimensionConstraint constraint)
        {
            this.ThrowIfBufferIsEmpty();

            if (constraint.MaxWidth == null)
            {
                throw new Exception("A max width must be provided in the constraint.");
            }

            var first = this.elements.First();

            if (first.Flags != null)
            {
                var text = this.Take(constraint, first.Flags);
                if (text == String.Empty)
                {
                    return(null);
                }

                var formattedText = (IFormattedText)this.elementFactory.Create(first.Flags);
                if (text != " ") // Ignore space, when causing a line break.
                {
                    formattedText.SetText(text);
                }

                return(formattedText);
            }

            if (first.Element == null || first.Element.GetWidth() > constraint.MaxWidth || first.Element.GetHeight() > constraint.MaxHeight)
            {
                return(null);
            }

            this.elements.RemoveAt(0);
            return(first.Element);
        }
Ejemplo n.º 9
0
 protected abstract T ProduceChild(IDocumentBuffer documentBuffer, IDimensionConstraint childConstraint);
Ejemplo n.º 10
0
        public void Insert(IDocumentBuffer documentBuffer, IDimensionConstraint dimensionConstraint)
        {
            double dimensionConsumed = 0;
            var    child             = this.FirstChild;

            while (this.CurrentCursorChild != null && child != this.CurrentCursorChild)
            {
                dimensionConsumed += this.GetDimension(child.Object);
                child              = child.Next;
            }

            var objectConstraint = this.GetConstraint(dimensionConstraint, dimensionConsumed);

            while (child != null)
            {
                child.Object.Insert(documentBuffer, objectConstraint);

                if (documentBuffer.EndOfBuffer())
                {
                    this.SizeChanged();
                    return;
                }

                dimensionConsumed += this.GetDimension(child.Object);
                objectConstraint   = this.GetConstraint(dimensionConstraint, dimensionConsumed);

                if (child.Next != null)
                {
                    child = child.Next;

                    if (this.CurrentCursorChild != null)
                    {
                        this.CurrentCursorChild.Object.ClearCursor();
                        this.CurrentCursorChild = child;
                        this.CurrentCursorChild.Object.SetCursor(false, this.Cursor);
                    }
                }
                else
                {
                    break;
                }
            }

            var newElement = this.ProduceChild(documentBuffer, objectConstraint);

            while (newElement != null)
            {
                this.AppendChild(newElement);
                dimensionConsumed += this.GetDimension(newElement);
                objectConstraint   = this.GetConstraint(dimensionConstraint, dimensionConsumed);

                if (documentBuffer.EndOfBuffer())
                {
                    break;
                }
                newElement = this.ProduceChild(documentBuffer, objectConstraint);
            }

            if (this.Cursor != null)
            {
                this.CurrentCursorChild?.Object.ClearCursor();
                this.CurrentCursorChild = this.LastChild;
                this.CurrentCursorChild.Object.SetCursor(true, this.Cursor);
            }

            this.SizeChanged();
        }
Ejemplo n.º 11
0
 protected abstract IDimensionConstraint GetConstraint(IDimensionConstraint originalConstraint, double consumed);
Ejemplo n.º 12
0
 public void Insert(IDocumentBuffer documentBuffer, IDimensionConstraint dimensionConstraint)
 {
     throw new NotImplementedException();
 }
Ejemplo n.º 13
0
 protected override IPage ProduceChild(IDocumentBuffer documentBuffer, IDimensionConstraint childConstraint)
 {
     throw new System.NotImplementedException();
 }
Ejemplo n.º 14
0
 protected override IDimensionConstraint GetConstraint(IDimensionConstraint originalConstraint, double consumed)
 {
     return(originalConstraint);
 }
Ejemplo n.º 15
0
 protected override IElement ProduceChild(IDocumentBuffer documentBuffer, IDimensionConstraint childConstraint)
 {
     return(documentBuffer.Take(childConstraint));
 }