private void ChangeElementFontSize(TextElement run, bool bAdd) { object rValue = run.GetValue(TextElement.FontSizeProperty); if (rValue != null && rValue != DependencyProperty.UnsetValue) { double oldValue = Convert.ToDouble(run.GetValue(TextElement.FontSizeProperty)); run.SetValue(TextElement.FontSizeProperty, FontSizeEnumerator.GetValue(oldValue, bAdd)); } }
private void OnTextOptionCommand(object sender, ExecutedRoutedEventArgs e) { try { if (DisplayFontsize < 0) { foreach (UIElement Elem in vPanel.Children) { TextBlock block; if (Elem is BulletDecorator) { block = ((BulletDecorator)Elem).Child as TextBlock; } else { block = Elem as TextBlock; } foreach (Run run in block.Inlines) { run.FontSize = FontSizeEnumerator.GetValue(run.FontSize, (bool)e.Parameter); } } } else { DisplayFontsize = FontSizeEnumerator.GetValue(DisplayFontsize, (bool)e.Parameter); OndisplayFontSizeChange(DisplayFontsize); } ResetLineHeight(); TranslateControlToText(); } catch (System.Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } }
void ProcessFontSizeIncrement(bool bAdd, bool bSection = true) { try { if (bSection && Selection != null && Selection.Text.Length > 0) { TextRange rang = new TextRange(Selection.Start, Selection.End); using (MemoryStream ms = new MemoryStream()) { if (rang.CanSave(DataFormats.Xaml)) { rang.Save(ms, DataFormats.Xaml, true); //string teststring = ASCIIEncoding.Default.GetString(ms.ToArray()); ms.Seek(0, SeekOrigin.Begin); object obj = XamlReader.Load(ms); if (obj is Span) { Span span = obj as Span; foreach (Run run in span.Inlines) { run.FontSize = FontSizeEnumerator.GetValue(run.FontSize, bAdd); } using (MemoryStream mso = new MemoryStream()) { XamlWriter.Save(span, mso); mso.Seek(0, SeekOrigin.Begin); rang.Load(mso, DataFormats.Xaml); } } else if (obj is Section) { Section section = obj as Section; foreach (Block block in section.Blocks)//vivid { if (block is Paragraph) { Paragraph para = block as Paragraph; foreach (Run run in para.Inlines) { run.FontSize = FontSizeEnumerator.GetValue(run.FontSize, bAdd); } } else { NLogger.Error("ProcessFontSizeIncrement->Invalid Block in section.Blocks!"); } } using (MemoryStream mso = new MemoryStream()) { XamlWriter.Save(section, mso); mso.Seek(0, SeekOrigin.Begin); rang.Load(mso, DataFormats.Xaml); } } else { NLogger.Error("Increment select span or section is null\n" + Selection.Text.ToString()); } Selection.Select(rang.Start, rang.End); } else { NLogger.Error("Increment selection can not save\n" + Selection.Text.ToString()); } } } else { if (Document != null) { foreach (Block block in Document.Blocks) { if (block is Paragraph) { Paragraph para = block as Paragraph; foreach (TextElement control in para.Inlines) { control.FontSize = FontSizeEnumerator.GetValue(control.FontSize, bAdd); } } } } } FlashPropertyBySection(Selection); } catch (System.Exception ex) { NLogger.Error("Exception in ProcessFontSizeIncrement\n" + ex.Message); } }