Esempio n. 1
0
		private Block Clone(Block block)
		{
			var paragraph = block as Paragraph;
			if (paragraph != null)
			{
				var newParagraph = new Paragraph();
				if (DependencyPropertyHelper.GetValueSource(paragraph, Paragraph.PaddingProperty).BaseValueSource != BaseValueSource.Default)
					newParagraph.SetValue(Paragraph.PaddingProperty, paragraph.Padding);
				if (DependencyPropertyHelper.GetValueSource(paragraph, Paragraph.MarginProperty).BaseValueSource != BaseValueSource.Default)
					newParagraph.SetValue(Paragraph.MarginProperty, paragraph.Margin);
				if (DependencyPropertyHelper.GetValueSource(paragraph, Paragraph.TextAlignmentProperty).BaseValueSource != BaseValueSource.Default)
					newParagraph.SetValue(Paragraph.TextAlignmentProperty, paragraph.TextAlignment);
				CopyProperties(paragraph, newParagraph);
				foreach (var inline in paragraph.Inlines)
					newParagraph.Inlines.Add(Clone(inline));
				return newParagraph;
			}
			throw new NotSupportedException();
		}
        protected static Paragraph GetSearchResultParagraph(string source, string key,  Brush keyColor, double fontSize, Boolean ignoreCase = false)
        {
            if (String.IsNullOrEmpty(key))
            {
                Paragraph p = new Paragraph();
                p.SetValue(TextElement.FontSizeProperty, fontSize);
                Run run = new Run {Text = source};
                p.Inlines.Add(run);
                return p;
            }

            string pattern = GetRegexPattern(key);
            Regex regex = ignoreCase ? new Regex(pattern, RegexOptions.IgnoreCase) : new Regex(pattern);

            string[] collection = regex.Split(source);

            Paragraph _paragraph = new Paragraph();
            _paragraph.SetValue(TextElement.FontSizeProperty, fontSize);

            foreach (string t in collection)
            {
                if (String.IsNullOrEmpty(t))
                    continue;

                bool isKey = IsKey(key, t, ignoreCase);

                Run run = new Run {Text = t};
                if (isKey)
                {
                    run.Foreground = keyColor;
                }
                _paragraph.Inlines.Add(run);
            }

            return _paragraph;
        }
Esempio n. 3
0
        // Creates a new cell copying all its properties from a currentRow. 
        // RowSpan property is not copied; it's set to default value of 1.
        // The new cell as added to a newRow (at the endPosition of its Cells collection).
        private static TableCell AddCellCopy(TableRow newRow, TableCell currentCell, int cellInsertionIndex, bool copyRowSpan, bool copyColumnSpan)
        { 
            Invariant.Assert(currentCell != null, "null check: currentCell");
 
            TableCell newCell = new TableCell(); 

            // Add the cell to a newRow's cell collection 
            // It's good to do it here before inserting inline formatting elements
            // to avoid unnecessary TextContainer creation and content copying.
            if (cellInsertionIndex < 0)
            { 
                newRow.Cells.Add(newCell);
            } 
            else 
            {
                newRow.Cells.Insert(cellInsertionIndex, newCell); 
            }

            // Copy all properties
            LocalValueEnumerator properties = currentCell.GetLocalValueEnumerator(); 
            while (properties.MoveNext())
            { 
                LocalValueEntry propertyEntry = properties.Current; 
                if (propertyEntry.Property == TableCell.RowSpanProperty && !copyRowSpan ||
                    propertyEntry.Property == TableCell.ColumnSpanProperty && !copyColumnSpan) 
                {
                    // Skipping table structuring properties when requested
                    continue;
                } 

                // Copy a property if it is not ReadOnly 
                if (!propertyEntry.Property.ReadOnly) 
                {
                    newCell.SetValue(propertyEntry.Property, propertyEntry.Value); 
                }
            }

            // Copy a paragraph for a cell 
            if (currentCell.Blocks.FirstBlock != null)
            { 
                Paragraph newParagraph = new Paragraph(); 

                // Transfer all known formatting properties that a locally set on a sourceBlock 
                Paragraph sourceParagraph = currentCell.Blocks.FirstBlock as Paragraph;

                if (sourceParagraph != null)
                { 
                    DependencyProperty[] inheritableProperties = TextSchema.GetInheritableProperties(typeof(Paragraph));
                    DependencyProperty[] nonInheritableProperties = TextSchema.GetNoninheritableProperties(typeof(Paragraph)); 
 
                    for (int i = 0; i < nonInheritableProperties.Length; i++)
                    { 
                        DependencyProperty property = nonInheritableProperties[i];
                        object value = sourceParagraph.ReadLocalValue(property);
                        if (value != DependencyProperty.UnsetValue)
                        { 
                            newParagraph.SetValue(property, value);
                        } 
                    } 
                    for (int i = 0; i < inheritableProperties.Length; i++)
                    { 
                        DependencyProperty property = inheritableProperties[i];
                        object value = sourceParagraph.ReadLocalValue(property);
                        if (value != DependencyProperty.UnsetValue)
                        { 
                            newParagraph.SetValue(property, value);
                        } 
                    } 
                }
 
                // Add paragraph to a cell
                newCell.Blocks.Add(newParagraph);
            }
 
            return newCell;
        }