private void GetDesignItems(TextElementCollection <Block> blocks, List <DesignItem> list)
        {
            bool first = true;

            foreach (var block in blocks)
            {
                if (block is Paragraph)
                {
                    if (!first)
                    {
                        list.Add(designItem.Services.Component.RegisterComponentForDesigner(new LineBreak()));
                        list.Add(designItem.Services.Component.RegisterComponentForDesigner(new LineBreak()));
                    }

                    foreach (var inline in ((Paragraph)block).Inlines)
                    {
                        list.Add(InlineToDesignItem(inline));
                    }
                }
                else if (block is Section)
                {
                    GetDesignItems(((Section)block).Blocks, list);
                }

                first = false;
            }
        }
Exemple #2
0
        private BindableRunTextMedia DoCloseSelf(bool saveContent, Inline inline, TextElementCollection <Inline> inlines)
        {
            if (saveContent)
            {
                BindingExpression bindExpr = GetBindingExpression(TextProperty);
                if (bindExpr != null)
                {
                    bindExpr.UpdateSource();
                }

                //mLastInlineBoxed.OriginalText.setText(mLastInlineBoxed.Text);

                if (Text != OriginalText.Text)
                {
                    //newRun.Text = mLastInlineBoxed.Text;
                }
            }

            var newRun = new BindableRunTextMedia(OriginalText);

            InvalidateBinding();

            inlines.InsertAfter(inline, newRun);
            inlines.Remove(inline);

            return(newRun);
        }
Exemple #3
0
 /// <summary>
 /// Creates a textline with the given paragraph as a parent.
 /// </summary>
 /// <param name="parent"></param>
 public Textline(Paragraph parent)
 {
     _height       = new Unit(0);
     _aligment     = parent.Alignment;
     _textElements = new TextElementCollection();
     _paragraph    = parent;
 }
		private void GetDesignItems(TextElementCollection<Block> blocks, List<DesignItem> list)
		{
			bool first = true;

			foreach (var block in blocks)
			{
				if (block is Paragraph)
				{
					if (!first)
					{
						list.Add(designItem.Services.Component.RegisterComponentForDesigner(new LineBreak()));
						list.Add(designItem.Services.Component.RegisterComponentForDesigner(new LineBreak()));
					}

					foreach (var inline in ((Paragraph) block).Inlines)
					{
						list.Add(InlineToDesignItem(inline));
					}
				}
				else if (block is Section)
				{
					GetDesignItems(((Section)block).Blocks, list);
				}

				first = false;
			}
		}
Exemple #5
0
        ///<summary>
        ///</summary>
        ///<param name="splitCharacters"></param>
        ///<returns></returns>
        public TextElementCollection Split(SplitCharacterList splitCharacters)
        {
            var textElementCollection = new TextElementCollection();

            String[] elementStrings = Regex.Split(_text, @"(?<=[ .,;])");
            foreach (String elementString in elementStrings)
            {
                // todo: determinate if the splitcharacter should be kept.
                var textElement = new TextElement(_paragraph, elementString, _fontStyle, _fontSize, _color);
                textElementCollection.Add(textElement);
            }
            return(textElementCollection);
        }
        /// <summary>
        /// Converts a paragraph to a textline list.
        /// </summary>
        /// <param name="maximumWidth">Unit to use for measuring the maximum width of an textline</param>
        /// <param name="paragraph">paragraph to convert to textlines.</param>
        /// <returns></returns>
        public TextlineCollection ConvertToTextlines(Unit maximumWidth, Paragraph paragraph)
        {
            IList <Textline> result             = new List <Textline>();
            float            maximumPointWidth  = maximumWidth.Points;
            float            totalMeasuredWidth = 0f;
            Textline         currentTextline    = new Textline(paragraph);

            TextElementCollection splittedTextElements = new TextElementCollection();

            if (paragraph.TextElements.Count() > 0)
            {
                foreach (TextElement textElement in paragraph.TextElements)
                {
                    splittedTextElements.AddRange(ConvertToTextElements(textElement));
                }

                foreach (TextElement splittedTextElement in splittedTextElements)
                {
                    float width          = MeasureTextElementWidth(splittedTextElement);
                    float tempTotalWidth = totalMeasuredWidth + width;

                    if (tempTotalWidth > maximumPointWidth)
                    {
                        currentTextline.Width  = new Unit(totalMeasuredWidth);
                        currentTextline.Height = paragraph.Leading;
                        result.Add(currentTextline);
                        currentTextline    = new Textline(paragraph);
                        totalMeasuredWidth = width;
                    }
                    else
                    {
                        totalMeasuredWidth = tempTotalWidth;
                    }

                    currentTextline.Add(splittedTextElement);
                }

                currentTextline.Width = new Unit(totalMeasuredWidth);
            }
            else
            {
                currentTextline.Width = new Unit(0f);
            }

            currentTextline.Height        = paragraph.Leading;
            currentTextline.EndsParagraph = true;

            result.Add(currentTextline);
            return(new TextlineCollection(result.ToList()));
        }
        /// <summary>
        /// Converts a textelement to a list with atomic textelements.
        /// </summary>
        /// <param name="textElement">Textelement to convert.</param>
        /// <returns>List with the resulting textelements.</returns>
        public TextElementCollection ConvertToTextElements(TextElement textElement)
        {
            TextElementCollection result = new TextElementCollection();

            SplitCharacterList splitCharacterList = new SplitCharacterList();

            splitCharacterList.Add(' ', SplitAction.Remove);
            splitCharacterList.Add('-', SplitAction.Add);
            splitCharacterList.Add('.', SplitAction.Add);
            splitCharacterList.Add(',', SplitAction.Add);
            TextElementCollection textElements = textElement.Split(splitCharacterList);

            return(textElements);
        }
        public static ICollection <Inline> GetInlines(TextElementCollection <Block> blocks)
        {
            var inlines      = new List <Inline>();
            var sourceBlocks = blocks.ToList();
            var index        = 0;
            var count        = sourceBlocks.Count;

            foreach (var block in sourceBlocks)
            {
                if (block is Paragraph paragraph)
                {
                    var paragraphSpan = new Span();

                    var properties = new[]
                    {
                        TextElement.FontFamilyProperty,
                        TextElement.FontSizeProperty,
                        TextElement.FontStretchProperty,
                        TextElement.FontStyleProperty,
                        TextElement.FontWeightProperty,
                        TextElement.ForegroundProperty,
                        TextElement.BackgroundProperty
                    };

                    block.CopySimilarValuesTo(paragraphSpan, properties);

                    foreach (var inline in paragraph.Inlines.ToArray())
                    {
                        paragraphSpan.Inlines.Add(inline);
                    }

                    inlines.Add(paragraphSpan);
                }
                else if (block is Section section)
                {
                    inlines.AddRange(GetInlines(section.Blocks));
                }

                if (index + 1 < count)
                {
                    inlines.Add(new LineBreak());
                    inlines.Add(new LineBreak());
                }

                index++;
            }

            return(inlines);
        }
Exemple #9
0
        private static bool AreEqual <T>([NotNull] TextElementCollection <T> x, [NotNull] TextElementCollection <T> y, StringBuilder report)
            where T : TextElement
        {
            report.AppendLine($"{x.GetType()}");
            var zipped = x.Zip(y, (a, b) => (a, b));

            foreach (var(first, second) in zipped)
            {
                if (!AreEqual((dynamic)first, (dynamic)second, report))
                {
                    report.AppendLine($"{x.GetType()} do not match");
                    return(false);
                }
            }

            return(true);
        }
        public static ICollection <Inline> GetInlines(TextElementCollection <Block> blocks)
        {
            var inlines = new List <Inline>();

            foreach (var block in blocks)
            {
                if (block is Paragraph)
                {
                    inlines.AddRange(((Paragraph)block).Inlines);
                }
                else if (block is Section)
                {
                    inlines.AddRange(GetInlines(((Section)block).Blocks));
                }
            }

            return(inlines);
        }
Exemple #11
0
 protected AbstractTextElement GetText(PonyTextStructureBase structureBase)
 {
     if (structureBase.StructureType == StructureType.NumberStruct ||
         structureBase.StructureType == StructureType.LiteralStruct)
     {
         string obj = structureBase.GetUnderlyingObject().ToString();
         return(TextElementFactory.CreateTextElement(TextElementType.TextUnit, obj));
     }
     // else if (structureBase.StructureType == StructureType.MarcoStruct) {
     //     PonyTextMarcoStruct marcoStruct = structureBase as PonyTextMarcoStruct;
     //     return GetText(ctx.MacroTable.GetMarco(marcoStruct.MarcoName));
     // }
     else if (structureBase.StructureType == StructureType.MapStruct)
     {
         throw new PreProcessorException($"Not support type.");
     }
     else if (structureBase.StructureType == StructureType.DirectiveStruct)
     {
         PonyTextContext newCtx = new DerivedTextContext(ctx,
                                                         TextElementFactory.CreateTextElement(TextElementType.TextElementCollection));
         structureBase.Evaluate(newCtx);
         TextElementCollection elementCollection = (TextElementCollection)newCtx.GetCurrentContext();
         if (elementCollection.getDocument().Count == 1)
         {
             return(elementCollection.getDocument()[0]);
         }
         return(elementCollection);
     }
     else
     {
         PonyTextContext newCtx = new DerivedTextContext(ctx,
                                                         TextElementFactory.CreateTextElement(TextElementType.TextElementCollection));
         structureBase.Evaluate(newCtx);
         return(newCtx.GetCurrentContext());
     }
 }
Exemple #12
0
 public Textline(Paragraph.AlignmentType alignmentType)
 {
     _height       = new Unit(0);
     _aligment     = alignmentType;
     _textElements = new TextElementCollection();
 }