/// <summary> /// 核心方法:显示文档内容 /// </summary> /// <param name="Document">FlowDocument</param> /// <param name="lpt">LPT文档</param> public static void DisplayDocument(FlowDocument Document, LptDocument lpt) { Document.Blocks.Clear(); Document.Background = new SolidColorBrush(lpt.OADisplay.BackColor); LineDisplay IADisplay = new LineDisplay(lpt.OADisplay);//清空旧的IA Document.Foreground = new SolidColorBrush(lpt.OADisplay.FontColor); Document.Background = new SolidColorBrush(lpt.OADisplay.BackColor); //用于判断下一行要不要用run 主要方法是判断行末是否有\n bool NextUseRun = false; lpt.LineNode = 1; while (lpt.ReadCanNext()) { DisplayLine(lpt.ReadNext(), Document, IADisplay, ref NextUseRun); } }
/// <summary> /// 将显示行(实意)转换成Sub集合 /// </summary> /// <returns>行(文本)</returns> public Sub[] ToSubs() { List <Sub> subs = new List <Sub>(); if (Bold) { subs.Add(new Sub("Bold", "")); } if (Italic) { subs.Add(new Sub("Italic", "")); } if (Underline) { subs.Add(new Sub("Underline", "")); } if (Strikethrough) { subs.Add(new Sub("Deleteline", "")); } subs.Add(new Sub("FontSize", FontSize.ToString("f2"))); subs.Add(new Sub("FontFamily", FontFamily.ToString())); subs.Add(new Sub("BackColor", LptDocument.ColorToHEX(BackColor))); subs.Add(new Sub("FontColor", LptDocument.ColorToHEX(FontColor))); switch (Alignment) { case TextAlignment.Left: subs.Add(new Sub("Left", "")); break; case TextAlignment.Right: subs.Add(new Sub("Right", "")); break; case TextAlignment.Center: subs.Add(new Sub("Center", "")); break; case TextAlignment.Justify: subs.Add(new Sub("Justify", "")); break; } return(subs.ToArray()); }
/// <summary> /// 获取这一xml元素的全部数据 /// </summary> /// <param name="element">ml元素</param> /// <param name="OA">全局/临时全局变量</param> /// <returns></returns> public static LineDisplay GetLineDisplayFormXmlElement(XmlElement element, LineDisplay OA) { LineDisplay tmp = new LineDisplay(OA); foreach (XmlAttribute atr in element.Attributes) { switch (atr.NodeType) { case XmlNodeType.Text: tmp.OutPut += atr.Value; break; case XmlNodeType.Attribute: switch (atr.Name) { case "": case "Margin": case "xml:lang": //弃用的参数 break; default: MessageBox.Show(atr.Name); break; //ToDo:支持图片 case "FontFamily": tmp.FontFamily = new FontFamily(atr.Value); break; case "Foreground": tmp.FontColor = LptDocument.HEXToColor(atr.Value); break; case "FontSize": tmp.FontSize = Convert.ToSingle(atr.Value); break; case "Background": tmp.BackColor = LptDocument.HEXToColor(atr.Value); break; case "FontWeight": tmp.Bold = (atr.Value == "Bold"); break; case "FontStyle": tmp.Italic = (atr.Value == "Italic"); break; case "TextDecorations": if (atr.Value == "Strikethrough") { tmp.Strikethrough = !tmp.Strikethrough; } else if (atr.Value == "Underline") { tmp.Underline = !tmp.Underline; } else { tmp.Strikethrough = false; tmp.Underline = false; } break; case "TextAlignment": switch (atr.Value) { case "Left": tmp.Alignment = TextAlignment.Left; break; case "Right": tmp.Alignment = TextAlignment.Right; break; case "Center": tmp.Alignment = TextAlignment.Center; break; case "Justify": tmp.Alignment = TextAlignment.Justify; break; default: tmp.Alignment = TextAlignment.Justify; break; } break; } break; case XmlNodeType.Element: MessageBox.Show(atr.Name); break; default: MessageBox.Show(atr.Name); break; //case XmlNodeType.Attribute: // tmp =GetLineDisplayFormXmlElement((XmlElement)atr, tmp); // break; } } return(tmp); }
/// <summary> /// 将显示行(实意)转换成Sub集合 /// </summary> /// <param name="OA">全局变量</param> /// <returns>行(文本)</returns> public Sub[] ToSubs(LineDisplay OA) { List <Sub> subs = new List <Sub>(); if (OA.Bold != Bold) { if (Bold) { subs.Add(new Sub("Bold", "")); } } if (OA.Italic != Italic) { if (Italic) { subs.Add(new Sub("Italic", "")); } } if (OA.Underline != Underline) { if (Underline) { subs.Add(new Sub("Underline", "")); } } if (OA.Strikethrough != Strikethrough) { if (Strikethrough) { subs.Add(new Sub("Deleteline", "")); } } if (OA.FontSize.ToString("f1") != FontSize.ToString("f1")) { subs.Add(new Sub("FontSize", FontSize.ToString("f2"))); } if (OA.FontFamily != FontFamily) { subs.Add(new Sub("FontFamily", FontFamily.ToString())); } if (OA.BackColor != BackColor) { subs.Add(new Sub("BackColor", LptDocument.ColorToHEX(BackColor))); } if (OA.FontColor != FontColor) { subs.Add(new Sub("FontColor", LptDocument.ColorToHEX(FontColor))); } if (OA.Alignment != Alignment) { switch (Alignment) { case TextAlignment.Left: subs.Add(new Sub("Left", "")); break; case TextAlignment.Right: subs.Add(new Sub("Right", "")); break; case TextAlignment.Center: subs.Add(new Sub("Center", "")); break; case TextAlignment.Justify: subs.Add(new Sub("Justify", "")); break; } } return(subs.ToArray()); }