public static int CountStyle(this Block block, ComplexStyle style, double defaultSize, ref TextPointer position, bool positionOnly) { if (position != null) { return(0); } var section = block as Section; if (section != null) { return(section.CountStyle(style, defaultSize, ref position, positionOnly)); } var paragraph = block as Paragraph; if (paragraph != null) { return(paragraph.CountStyle(style, defaultSize, ref position, positionOnly)); } var list = block as List; if (list != null) { return(list.CountStyle(style, defaultSize, ref position, positionOnly)); } return(0); }
public void ClearDefaultWithout(ComplexStyle sty) { foreach (var complexStyle in Styles.Styles.Where(elem => !ComplexStyle.Equals(elem, sty) && elem.IsDefault)) { complexStyle.IsDefault = false; } }
public static int CountStyle(this Section section, ComplexStyle style, double defaultSize, ref TextPointer position, bool positionOnly) { var counter = 0; foreach (var block in section.Blocks.ToList()) { counter += block.CountStyle(style, defaultSize, ref position, positionOnly); } return(counter); }
public static bool CheckAndChangeFonts(this FlowDocument document, ComplexStyle oldStyle, ComplexStyle newStyle) { var update = false; foreach (var block in document.Blocks.ToList()) { update |= block.ChangeMainFont(oldStyle, newStyle); update |= block.CheckAndChangeFonts(oldStyle, newStyle); } return(update); }
private static bool UpdateFonts(Section section, ComplexStyle oldStyle, ComplexStyle newStyle) { var updated = false; foreach (var block in section.Blocks.ToList()) { updated |= block.ChangeMainFont(oldStyle, newStyle); updated |= block.CheckAndChangeFonts(oldStyle, newStyle); } return(updated); }
public static bool Equals(ComplexStyle style1, ComplexStyle style2) { if (style1 == null && style2 == null) { return(true); } if (style1 == null || style2 == null) { return(false); } return(style1.Equals(style2)); }
public static int CountStyle(this ListItem item, ComplexStyle style, double defaultSize, ref TextPointer position, bool positionOnly) { var counter = 0; if (position != null) { return(0); } foreach (var block in item.Blocks.ToList()) { counter += block.CountStyle(style, defaultSize, ref position, positionOnly); } return(counter); }
public static int CountStyle(this List list, ComplexStyle style, double defaultSize, ref TextPointer position, bool positionOnly) { if (position != null) { return(0); } var counter = 0; foreach (var listItem in list.ListItems.ToList()) { counter += listItem.CountStyle(style, defaultSize, ref position, positionOnly); } return(counter); }
public static bool IsStyle(this TextElement text, ComplexStyle style, double defaultSize, out TextPointer position) { position = null; var run = text as Run; if (run != null && string.IsNullOrEmpty(run.Text)) { return(false); } var range = new TextRange(text.ContentStart, text.ContentEnd); var sty = GetCurrentStyle(range, defaultSize); position = text.ContentStart; return(ComplexStyle.Equals(sty, style)); }
public static void CollectStyles(this TextElement text, ref List <ComplexStyle> styles, double defaultSize) { var run = text as Run; if (run != null && string.IsNullOrEmpty(run.Text)) { return; } var range = new TextRange(text.ContentStart, text.ContentEnd); var style = GetCurrentStyle(range, defaultSize); if (!styles.Any(elem => ComplexStyle.Equals(elem, style))) { styles.Add(style); } }
public static ComplexStyle GetCurrentStyle(TextRange range, double defaultsize) { var test = range.GetPropertyValue(FlowDocument.FontSizeProperty); var applyableStyle = new ComplexStyle(); applyableStyle.FontFamily = range.GetPropertyValue(Control.FontFamilyProperty) as FontFamily; applyableStyle.FontSize = test != DependencyProperty.UnsetValue ? (double)test : defaultsize; applyableStyle.IsBold = range.GetPropertyValue(Control.FontWeightProperty).Equals(FontWeights.Bold); applyableStyle.IsItalic = range.GetPropertyValue(Control.FontStyleProperty).Equals(FontStyles.Italic); applyableStyle.IsCondenced = range.GetPropertyValue(Control.FontStretchProperty).Equals(FontStretches.Condensed); applyableStyle.IsUnderlined = Equals(range.GetPropertyValue(Inline.TextDecorationsProperty), TextDecorations.Underline); applyableStyle.IsStrikedOut = Equals(range.GetPropertyValue(Inline.TextDecorationsProperty), TextDecorations.Strikethrough); applyableStyle.BackgroundBrush = range.GetPropertyValue(FlowDocument.BackgroundProperty) as SolidColorBrush; applyableStyle.ForegroundBrush = range.GetPropertyValue(FlowDocument.ForegroundProperty) as SolidColorBrush; return(applyableStyle); }
public static bool CheckAndChangeFonts(this Block block, ComplexStyle oldStyle, ComplexStyle newStyle) { var section = block as Section; if (section != null) { return(UpdateFonts(section, oldStyle, newStyle)); } var paragraph = block as Paragraph; if (paragraph != null) { return(UpdateFonts(paragraph, oldStyle, newStyle)); } var list = block as List; return(list != null && UpdateFonts(list, oldStyle, newStyle)); }
public static int CountStyle(this Paragraph paragraph, ComplexStyle style, double defaultSize, ref TextPointer position, bool positionOnly) { if (position != null) { return(0); } var count = 0; foreach (Inline inline in paragraph.Inlines) { TextPointer pos = null; if (!inline.IsStyle(style, defaultSize, out pos)) { continue; } if (position == null) { position = pos; } count++; } return(count); }
private bool EqualNullable(ComplexStyle sty) { return(IsSamebrush(sty.BackgroundBrush, BackgroundBrush) && IsSamebrush(sty.ForegroundBrush, ForegroundBrush) && IsSameFamily(sty.FontFamily, FontFamily)); }
public static bool ChangeMainFont(this TextElement elem, ComplexStyle oldStyle, ComplexStyle newStyle) { try { if (!elem.FontFamily.Equals(oldStyle.FontFamily)) { return(true); } if (!oldStyle.FontSize.Equals(elem.FontSize)) { return(true); } if (!oldStyle.Style.Equals(elem.FontStyle)) { return(true); } if (!oldStyle.Weight.Equals(elem.FontWeight)) { return(true); } var range = new TextRange(elem.ContentStart, elem.ContentEnd); Brush brush; try { brush = (SolidColorBrush)range.GetPropertyValue(FlowDocument.ForegroundProperty); if (brush != null && !oldStyle.ForegroundBrush.ToString().Equals(brush.ToString())) { return(true); } } catch (Exception) { return(true); } try { brush = (SolidColorBrush)range.GetPropertyValue(FlowDocument.BackgroundProperty); if (brush != null && !oldStyle.BackgroundBrush.ToString().Equals(brush.ToString())) { return(true); } } catch (Exception) { return(true); } var dec = (TextDecorationCollection)range.GetPropertyValue(Inline.TextDecorationsProperty); if (!AreEqualTextDecorations(dec, oldStyle.Decoration)) { return(true); } range.ApplyPropertyValue(TextElement.FontFamilyProperty, newStyle.FontFamily); range.ApplyPropertyValue(TextElement.FontSizeProperty, newStyle.FontSize); range.ApplyPropertyValue(TextElement.FontWeightProperty, newStyle.Weight); range.ApplyPropertyValue(TextElement.FontStyleProperty, newStyle.Style); range.ApplyPropertyValue(TextElement.ForegroundProperty, newStyle.ForegroundBrush); range.ApplyPropertyValue(TextElement.BackgroundProperty, newStyle.BackgroundBrush); range.ApplyPropertyValue(Inline.TextDecorationsProperty, newStyle.Decoration); range.ApplyPropertyValue(TextElement.FontStretchProperty, newStyle.Stretch); return(true); } catch (Exception) { return(false); } }
private static bool UpdateFonts(List list, ComplexStyle oldStyle, ComplexStyle newStyle) { return(list.ListItems.ToList().Aggregate(false, (current, listItem) => current | listItem.CheckAndChangeFonts(oldStyle, newStyle))); }
private static bool UpdateFonts(Paragraph paragraph, ComplexStyle oldStyle, ComplexStyle newStyle) { return(paragraph.Inlines.ToList().Aggregate(false, (current, inline) => current | inline.ChangeMainFont(oldStyle, newStyle))); }
public static bool CheckAndChangeFonts(this ListItem listItem, ComplexStyle oldStyle, ComplexStyle newStyle) { return(listItem.Blocks.ToList().Aggregate(false, (current, block) => current | block.CheckAndChangeFonts(oldStyle, newStyle))); }