public MRATextMarkerProperties(MRATextSource _textsource) { this.textsource = _textsource; }
protected void InvalidateText() { if (Core == null || Core.IsDisposed) { return; } ITextZone zonebackground = null; ITextZone zoneforeground = null; ITextZone zonefontweight = null; ITextZone zonefontfamily = null; ITextZone zonefontstyle = null; ITextZone zonefontstretch = null; ITextZone zonefontsize = null; ITextItem item = Core.Start.Item; textbuilder.Clear(); fontindics.Clear(); this.skipzone = null; this.skipzonestart = -1; this.openzone = null; this.closezone = null; this.intozone = null; void _FindAllZone(ITextItem startitem) { for (ITextZone zone = startitem.Parent; zone != null; zone = zone.Parent) { if (!(zone.Doc is IDocsFill)) { continue; } IDocsFill doc = (IDocsFill)(zone.Doc); if (doc.Fill == null) { continue; } if (zonebackground == null && doc.Fill.Background != null) { zonebackground = zone; } if (zoneforeground == null && doc.Fill.Foreground != null) { zoneforeground = zone; } if (zonefontweight == null && doc.Fill.FontWeight != null) { zonefontweight = zone; } if (zonefontfamily == null && doc.Fill.FontFamily != null) { zonefontfamily = zone; } if (zonefontstyle == null && doc.Fill.FontStyle != null) { zonefontstyle = zone; } if (zonefontstretch == null && doc.Fill.FontStretch != null) { zonefontstretch = zone; } if (zonefontsize == null && doc.Fill.FontSize != null) { zonefontsize = zone; } if (zonebackground == null) { continue; } if (zoneforeground == null) { continue; } if (zonefontweight == null) { continue; } if (zonefontfamily == null) { continue; } if (zonefontstyle == null) { continue; } if (zonefontsize == null) { continue; } if (zonefontstretch == null) { continue; } break; } } void _RefindAllZone(ITextItem startitem) { zonebackground = null; zoneforeground = null; zonefontweight = null; zonefontfamily = null; zonefontstyle = null; zonefontsize = null; zonefontstretch = null; _FindAllZone(startitem); } void _AppendText(ITextItem additem, string addtext) { FontFamily fontfamily = TextCore.FontFamily; FontStyle fontstyle = TextCore.FontStyle; FontStretch fontstretch = TextCore.FontStretch; FontWeight fontweight = TextCore.FontWeight; double fontsize = TextCore.FontSize; Brush background = null; Brush foreground = TextCore.Foreground; if (additem.Doc is IDocsFill) { IDocsFill doc = (IDocsFill)(additem.Doc); if (doc.Fill != null) { if (doc.Fill.FontFamily != null) { fontfamily = doc.Fill.FontFamily; } if (doc.Fill.FontStyle != null) { fontstyle = doc.Fill.FontStyle.Value; } if (doc.Fill.FontWeight != null) { fontweight = doc.Fill.FontWeight.Value; } if (doc.Fill.FontStretch != null) { fontstretch = doc.Fill.FontStretch.Value; } if (doc.Fill.FontSize != null) { fontsize = doc.Fill.FontSize.Value; } if (doc.Fill.Background != null) { background = new SolidColorBrush(doc.Fill.Background.Value); } if (doc.Fill.Foreground != null) { foreground = new SolidColorBrush(doc.Fill.Foreground.Value); } } } if (zonefontfamily?.Doc is IDocsFill) { fontfamily = ((IDocsFill)(zonefontfamily.Doc)).Fill.FontFamily; } if (zonefontstyle?.Doc is IDocsFill) { fontstyle = ((IDocsFill)(zonefontstyle.Doc)).Fill.FontStyle.Value; } if (zonefontweight?.Doc is IDocsFill) { fontweight = ((IDocsFill)(zonefontweight.Doc)).Fill.FontWeight.Value; } if (zonefontstretch?.Doc is IDocsFill) { fontstretch = ((IDocsFill)(zonefontstretch.Doc)).Fill.FontStretch.Value; } if (zonefontsize?.Doc is IDocsFill) { fontsize = ((IDocsFill)(zonefontsize.Doc)).Fill.FontSize.Value; } if (zonebackground?.Doc is IDocsFill) { background = new SolidColorBrush(((IDocsFill)(zonebackground.Doc)).Fill.Background.Value); } if (zoneforeground?.Doc is IDocsFill) { foreground = new SolidColorBrush(((IDocsFill)(zoneforeground.Doc)).Fill.Foreground.Value); } fontindics.Add(new TextFontIndex(new TextFontCore(fontstyle, fontstretch, fontfamily, fontweight, fontsize, background, foreground), textbuilder.Length)); textbuilder.Append(addtext); } void _AppendSkipZone(ITextZone skipzone) { FontFamily fontfamily = TextCore.FontFamily; FontStyle fontstyle = TextCore.FontStyle; FontStretch fontstretch = TextCore.FontStretch; FontWeight fontweight = TextCore.FontWeight; double fontsize = TextCore.FontSize; Brush background = null; Brush foreground = Brushes.Gray; TextCore.DictBrush.TryGetValue("foreground_skipzone", out foreground); skipzonestart = textbuilder.Length; skipzonecount = 3; fontindics.Add(new TextFontIndex(new TextFontCore(fontstyle, fontstretch, fontfamily, fontweight, fontsize, background, foreground), textbuilder.Length)); int showstart = 0; int showend = 0; if (TextCore.View.Counselor != null) { string zonename = skipzone?.Doc?.Name ?? "{zone_deault}"; MRATextInputContext ictx = new MRATextInputContext(skipzone, 0, 0); MRAZoneContext zctx = new MRAZoneContext(zonename, ictx, MRAZoneAction.Skip); IMRAZoneResult zret = TextCore.View.Counselor.ZoneAction(zctx); if (zret is IMRAZoneSkipResult) { IMRAZoneSkipResult zsret = (IMRAZoneSkipResult)zret; showstart = zsret.ShowStart; showend = zsret.ShowEnd; } } for (int i = 0; i < Math.Min(showstart, skipzone.Items.Count); i++) { textbuilder.Append(skipzone.Items[i].ToString()); } textbuilder.Append("..."); for (int i = Math.Max(0, skipzone.Items.Count - showend); i < skipzone.Items.Count; i++) { textbuilder.Append(skipzone.Items[i].ToString()); } } void _RemoveZone(ITextItem zone) { if (item == zonebackground) { zonebackground = null; } if (item == zoneforeground) { zoneforeground = null; } if (item == zonefontweight) { zonefontweight = null; } if (item == zonefontfamily) { zonefontfamily = null; } if (item == zonefontstyle) { zonefontstyle = null; } if (item == zonefontstretch) { zonefontstretch = null; } if (item == zonefontsize) { zonefontstretch = null; } } void _AddZone(ITextZone zone) { if (zone.Doc is IDocsFill) { IDocsFill doc = (IDocsFill)(zone.Doc); if (doc.Fill != null) { if (doc.Fill.Background != null) { zonebackground = zone; } if (doc.Fill.Foreground != null) { zoneforeground = zone; } if (doc.Fill.FontWeight != null) { zonefontweight = zone; } if (doc.Fill.FontFamily != null) { zonefontfamily = zone; } if (doc.Fill.FontStyle != null) { zonefontstyle = zone; } if (doc.Fill.FontStretch != null) { zonefontstretch = zone; } if (doc.Fill.FontSize != null) { zonefontsize = zone; } } } } _FindAllZone(item); if (Core.Start != null && Core.End != null) { ITextItem startitem = Core.Start.Item; ITextItem enditem = Core.End.Item; startitem = startitem.Parent; enditem = enditem.Parent; while (startitem.Level > enditem.Level) { startitem = startitem.Parent; } while (startitem.Level < enditem.Level) { enditem = enditem.Parent; } while (startitem != enditem) { startitem = startitem.Parent; enditem = enditem.Parent; } while (startitem?.Parent != null) { if (!(startitem is ITextLine) && ((ITextZone)startitem).LineCount > 1) { this.intozone = (ITextZone)startitem; break; } startitem = startitem.Parent; } } { ITextItem startitem = Core.Start.Item; ITextItem enditem = Core.End.Item; if (startitem.ID == 0 && !(startitem.Parent is ITextLine) && !(startitem.Parent is ITextBoxCore) && startitem.Parent.LineCount > 1) { this.openzone = startitem.Parent; } if (enditem.ID == enditem.Parent.Items.Count - 1 && !(enditem.Parent is ITextLine) && !(enditem.Parent is ITextBoxCore) && enditem.Parent.LineCount > 1) { this.closezone = enditem.Parent; } } if (Core.Start.Item == Core.End.Item) { string text = Core.Start.RightPart.Substring(0, Core.End.ItemIndex - Core.Start.ItemIndex); _AppendText(Core.Start.Item, text); } else if (Core is IMRAZoneSkipInfo) { IMRAZoneSkipInfo zscore = (IMRAZoneSkipInfo)Core; this.skipzone = zscore.SkipZone; if (Core.Start.Item.Parent != zscore.SkipZone) { _AppendText(Core.Start.Item, Core.Start.RightPart); while (item != null && item != Core.End.Item) { while (item?.Parent != null && item.ID + 1 >= item.Parent.Items.Count) { item = item.Parent; ITextZone zone = (ITextZone)item; if (!(zone is ITextLine) && zone.LineCount > 1) { this.closezone = zone; } _RemoveZone(item); } if (item?.Parent == null) { break; } item = item.Parent.Items[item.ID + 1]; _FindAllZone(item); while (item is ITextZone) { ITextZone zone = (ITextZone)item; if (zone == zscore.SkipZone) { break; } _AddZone(zone); item = zone.Items.FirstOrDefault(); } if (item == zscore.SkipZone) { break; } _AppendText(item, item.ToString()); } } _AppendSkipZone(zscore.SkipZone); if (Core.End.Item.Parent != zscore.SkipZone) { item = zscore.SkipZone; _RefindAllZone(item); while (item != null && item != Core.End.Item) { while (item?.Parent != null && item.ID + 1 >= item.Parent.Items.Count) { item = item.Parent; _RemoveZone(item); } if (item?.Parent == null) { break; } item = item.Parent.Items[item.ID + 1]; _FindAllZone(item); while (item is ITextZone) { ITextZone zone = (ITextZone)item; if (!(zone is ITextLine) && zone.LineCount > 1) { this.openzone = zone; } _AddZone(zone); item = zone.Items.FirstOrDefault(); } _AppendText(item, item.ToString()); } _AppendText(Core.End.Item, Core.End.LeftPart); } } else { _AppendText(Core.Start.Item, Core.Start.RightPart); while (item != null && item != Core.End.Item) { while (item?.Parent != null && item.ID + 1 >= item.Parent.Items.Count) { item = item.Parent; ITextZone zone = (ITextZone)item; if (!(zone is ITextLine) && zone.LineCount > 1) { this.closezone = zone; if (intozone == null || zone.Level < intozone.Level) { this.intozone = zone; } } _RemoveZone(item); } if (item?.Parent == null) { break; } item = item.Parent.Items[item.ID + 1]; _FindAllZone(item); while (item is ITextZone) { ITextZone zone = (ITextZone)item; if (!(zone is ITextLine) && zone.LineCount > 1) { this.openzone = zone; if (intozone == null || zone.Level < intozone.Level) { this.intozone = zone; } } _AddZone(zone); item = zone.Items.FirstOrDefault(); } if (item == Core.End.Item) { break; } _AppendText(item, item.ToString()); } _AppendText(Core.End.Item, Core.End.LeftPart); } this.textsource = new MRATextSource(textbuilder.ToString(), fontindics); this.textline = textfmtr.FormatLine(textsource, 0, 10000.0, new MRATextParagraphProperties(TextCore, textsource), null); }
public MRATextParagraphProperties(ITextBoxCore _core, MRATextSource _textsource) { this.core = _core; this.textsource = _textsource; }