public ParaProps(FastTextBlock tb) { this.tb = tb; props = new TextProps(tb); }
public void UpdateParent(FastTextBlock ftb) { text = ftb.Text; props = new TextProps(ftb); }
public void UpdateParent(FastTextBlock ftb) { text = ftb.Text; props = new TextProps(ftb); }
public override TextRun GetTextRun(int textSourceCharacterIndex) { var index = textSourceCharacterIndex; if (runs.ContainsKey(index)) { var run = runs[index]; runs.Remove(index); return run; } if (index >= text.Length || text[index] == '\r' || text[index] == '\n') { if (index < text.Length && text[index] != '\r') return new TextCharacters(" ", null); else return new TextEndOfParagraph(1); } int defaultTextLength, tokenLength; TextTokenKind tokenKind; if (!tokens.Find(index, out defaultTextLength, out tokenKind, out tokenLength)) { Debug.Fail("Could not find token info"); return new TextCharacters(" ", null); } TextCharacters defaultRun = null, tokenRun = null; if (defaultTextLength != 0) { var defaultText = text.Substring(index, defaultTextLength); defaultRun = new TextCharacters(defaultText, new TextProps { background = (Brush)parent.GetValue(TextElement.BackgroundProperty), foreground = TextElement.GetForeground(parent), typeface = new Typeface( TextElement.GetFontFamily(parent), TextElement.GetFontStyle(parent), TextElement.GetFontWeight(parent), TextElement.GetFontStretch(parent) ), fontSize = TextElement.GetFontSize(parent), }); } index += defaultTextLength; if (tokenLength != 0) { var tc = GetColor(tokenKind); var tokenText = text.Substring(index, tokenLength); var textProps = new TextProps(); textProps.fontSize = TextElement.GetFontSize(parent); textProps.foreground = tc.Foreground ?? TextElement.GetForeground(parent); textProps.background = tc.Background ?? (Brush)parent.GetValue(TextElement.BackgroundProperty); textProps.typeface = new Typeface( TextElement.GetFontFamily(parent), tc.FontStyle ?? TextElement.GetFontStyle(parent), tc.FontWeight ?? TextElement.GetFontWeight(parent), TextElement.GetFontStretch(parent) ); tokenRun = new TextCharacters(tokenText, textProps); } Debug.Assert(defaultRun != null || tokenRun != null); if ((defaultRun != null) ^ (tokenRun != null)) return defaultRun ?? tokenRun; else { runs[index] = tokenRun; return defaultRun; } }
public ParaProps(FastTextBlock tb) { this.tb = tb; props = new TextProps(tb); }
public override TextRun GetTextRun(int textSourceCharacterIndex) { var index = textSourceCharacterIndex; if (index >= text.Length) { return(new TextEndOfParagraph(1)); } char c = text[index]; if (c == '\r' || c == '\n' || c == '\u0085' || c == '\u2028' || c == '\u2029') { int nlLen = c == '\r' && index + 1 < text.Length && text[index + 1] == '\n' ? 2 : 1; return(new TextEndOfParagraph(nlLen)); } int collIndex = GetStartIndex(index); Debug.Assert(collIndex >= 0); if (collIndex < 0) { return(new TextCharacters(text.Substring(index), GetDefaultTextRunProperties())); } var info = tagsList[collIndex]; if (info.Span.End == index) { Debug.Assert(collIndex + 1 < tagsList.Length); if (collIndex + 1 >= tagsList.Length) { return(new TextCharacters(text.Substring(index), GetDefaultTextRunProperties())); } info = tagsList[collIndex + 1]; } int startIndex = info.Span.Start; int endIndex = info.Span.End; int nlIndex = text.IndexOfAny(LineConstants.newLineChars, index, endIndex - startIndex); if (nlIndex > 0) { endIndex = nlIndex; } var props = classificationFormatMap.GetTextProperties(info.ClassificationType); var tokenText = text.Substring(index, endIndex - startIndex); var textProps = new TextProps(); textProps.fontSize = TextElement.GetFontSize(parent); textProps.foreground = (props.ForegroundBrushEmpty ? null : props.ForegroundBrush) ?? TextElement.GetForeground(parent); textProps.background = (props.BackgroundBrushEmpty ? null : props.BackgroundBrush) ?? (Brush)parent.GetValue(TextElement.BackgroundProperty); textProps.textEffects = props.TextEffectsEmpty ? null : props.TextEffects; textProps.textDecorations = props.TextDecorationsEmpty ? null : props.TextDecorations; textProps.typeface = new Typeface( TextElement.GetFontFamily(parent), (props.ItalicEmpty ? (FontStyle?)null : FontStyles.Italic) ?? TextElement.GetFontStyle(parent), (props.BoldEmpty ? (FontWeight?)null : FontWeights.Bold) ?? TextElement.GetFontWeight(parent), TextElement.GetFontStretch(parent) ); return(new TextCharacters(tokenText.Length == 0 ? " " : tokenText, textProps)); }
public override TextRun GetTextRun(int textSourceCharacterIndex) { var index = textSourceCharacterIndex; if (runs.ContainsKey(index)) { var run = runs[index]; runs.Remove(index); return(run); } if (index >= text.Length || text[index] == '\r' || text[index] == '\n') { if (index < text.Length && text[index] != '\r') { return(new TextCharacters(" ", null)); } else { return(new TextEndOfParagraph(1)); } } int defaultTextLength, tokenLength; TextTokenType tokenType; if (!tokens.Find(index, out defaultTextLength, out tokenType, out tokenLength)) { Debug.Fail("Could not find token info"); return(new TextCharacters(" ", null)); } TextCharacters defaultRun = null, tokenRun = null; if (defaultTextLength != 0) { var defaultText = text.Substring(index, defaultTextLength); defaultRun = new TextCharacters(defaultText, new TextProps { background = (Brush)parent.GetValue(TextElement.BackgroundProperty), foreground = TextElement.GetForeground(parent), typeface = new Typeface( TextElement.GetFontFamily(parent), TextElement.GetFontStyle(parent), TextElement.GetFontWeight(parent), TextElement.GetFontStretch(parent) ), fontSize = TextElement.GetFontSize(parent), }); } index += defaultTextLength; if (tokenLength != 0) { var hlColor = GetColor(tokenType); var tokenText = text.Substring(index, tokenLength); var textProps = new TextProps(); textProps.fontSize = TextElement.GetFontSize(parent); if (hlColor.Foreground != null) { textProps.foreground = hlColor.Foreground.GetBrush(null); } else { textProps.foreground = TextElement.GetForeground(parent); } if (hlColor.Background != null) { textProps.background = hlColor.Background.GetBrush(null); } else { textProps.background = (Brush)parent.GetValue(TextElement.BackgroundProperty); } textProps.typeface = new Typeface( TextElement.GetFontFamily(parent), hlColor.FontStyle ?? TextElement.GetFontStyle(parent), hlColor.FontWeight ?? TextElement.GetFontWeight(parent), TextElement.GetFontStretch(parent) ); tokenRun = new TextCharacters(tokenText, textProps); } Debug.Assert(defaultRun != null || tokenRun != null); if ((defaultRun != null) ^ (tokenRun != null)) { return(defaultRun ?? tokenRun); } else { runs[index] = tokenRun; return(defaultRun); } }
public override TextRun GetTextRun(int textSourceCharacterIndex) { var index = textSourceCharacterIndex; if (runs.ContainsKey(index)) { var run = runs[index]; runs.Remove(index); return(run); } if (index >= text.Length) { return(new TextEndOfParagraph(1)); } char c = text[index]; if (c == '\r' || c == '\n' || c == '\u0085' || c == '\u2028' || c == '\u2029') { int nlLen = c == '\r' && index + 1 < text.Length && text[index + 1] == '\n' ? 2 : 1; return(new TextEndOfParagraph(nlLen)); } int defaultTextLength, tokenLength; object color; if (!cachedTextColorsCollection.Find(index, out defaultTextLength, out color, out tokenLength)) { Debug.Fail("Could not find token info"); return(new TextCharacters(" ", GetDefaultTextRunProperties())); } TextCharacters defaultRun = null, tokenRun = null; if (defaultTextLength != 0) { var defaultText = text.Substring(index, defaultTextLength); defaultRun = new TextCharacters(defaultText, GetDefaultTextRunProperties()); } index += defaultTextLength; if (tokenLength != 0) { var tc = GetTextColor(themeManager.Theme, color); var tokenText = text.Substring(index, tokenLength); var textProps = new TextProps(); textProps.fontSize = TextElement.GetFontSize(parent); textProps.foreground = tc.Foreground ?? TextElement.GetForeground(parent); textProps.background = tc.Background ?? (Brush)parent.GetValue(TextElement.BackgroundProperty); textProps.typeface = new Typeface( TextElement.GetFontFamily(parent), tc.FontStyle ?? TextElement.GetFontStyle(parent), tc.FontWeight ?? TextElement.GetFontWeight(parent), TextElement.GetFontStretch(parent) ); tokenRun = new TextCharacters(tokenText.Length == 0 ? " " : tokenText, textProps); } Debug.Assert(defaultRun != null || tokenRun != null); if ((defaultRun != null) ^ (tokenRun != null)) { return(defaultRun ?? tokenRun); } else { runs[index] = tokenRun; return(defaultRun); } }
public override TextRun GetTextRun(int textSourceCharacterIndex) { var index = textSourceCharacterIndex; if (index >= text.Length) { return(new TextEndOfParagraph(1)); } char c = text[index]; if (c == '\r' || c == '\n' || c == '\u0085' || c == '\u2028' || c == '\u2029') { int nlLen = c == '\r' && index + 1 < text.Length && text[index + 1] == '\n' ? 2 : 1; return(new TextEndOfParagraph(nlLen)); } int collIndex = cachedTextColorsCollection.GetStartIndex(index); Debug.Assert(collIndex >= 0); if (collIndex < 0) { return(new TextCharacters(text.Substring(index), GetDefaultTextRunProperties())); } var info = cachedTextColorsCollection[collIndex]; if (info.Span.End == index) { Debug.Assert(collIndex + 1 < cachedTextColorsCollection.Count); if (collIndex + 1 >= cachedTextColorsCollection.Count) { return(new TextCharacters(text.Substring(index), GetDefaultTextRunProperties())); } info = cachedTextColorsCollection[collIndex + 1]; } int startIndex = info.Span.Start; int endIndex = info.Span.End; int nlIndex = text.IndexOfAny(LineConstants.newLineChars, index, endIndex - startIndex); if (nlIndex > 0) { endIndex = nlIndex; } var tc = GetTextColor(themeService.Theme, info.Data); var tokenText = text.Substring(index, endIndex - startIndex); var textProps = new TextProps(); textProps.fontSize = TextElement.GetFontSize(parent); textProps.foreground = tc.Foreground ?? TextElement.GetForeground(parent); textProps.background = tc.Background ?? (Brush)parent.GetValue(TextElement.BackgroundProperty); textProps.typeface = new Typeface( TextElement.GetFontFamily(parent), tc.FontStyle ?? TextElement.GetFontStyle(parent), tc.FontWeight ?? TextElement.GetFontWeight(parent), TextElement.GetFontStretch(parent) ); return(new TextCharacters(tokenText.Length == 0 ? " " : tokenText, textProps)); }
public override TextRun GetTextRun(int textSourceCharacterIndex) { var index = textSourceCharacterIndex; if (index >= text.Length) return new TextEndOfParagraph(1); char c = text[index]; if (c == '\r' || c == '\n' || c == '\u0085' || c == '\u2028' || c == '\u2029') { int nlLen = c == '\r' && index + 1 < text.Length && text[index + 1] == '\n' ? 2 : 1; return new TextEndOfParagraph(nlLen); } int collIndex = GetStartIndex(index); Debug.Assert(collIndex >= 0); if (collIndex < 0) return new TextCharacters(text.Substring(index), GetDefaultTextRunProperties()); var info = tagsList[collIndex]; if (info.Span.End == index) { Debug.Assert(collIndex + 1 < tagsList.Length); if (collIndex + 1 >= tagsList.Length) return new TextCharacters(text.Substring(index), GetDefaultTextRunProperties()); info = tagsList[collIndex + 1]; } int startIndex = info.Span.Start; int endIndex = info.Span.End; int nlIndex = text.IndexOfAny(LineConstants.newLineChars, index, endIndex - startIndex); if (nlIndex > 0) endIndex = nlIndex; var props = classificationFormatMap.GetTextProperties(info.ClassificationType); var tokenText = text.Substring(index, endIndex - startIndex); var textProps = new TextProps(); textProps.fontSize = TextElement.GetFontSize(parent); textProps.foreground = (props.ForegroundBrushEmpty ? null : props.ForegroundBrush) ?? TextElement.GetForeground(parent); textProps.background = (props.BackgroundBrushEmpty ? null : props.BackgroundBrush) ?? (Brush)parent.GetValue(TextElement.BackgroundProperty); textProps.textEffects = props.TextEffectsEmpty ? null : props.TextEffects; textProps.textDecorations = props.TextDecorationsEmpty ? null : props.TextDecorations; textProps.typeface = new Typeface( TextElement.GetFontFamily(parent), (props.ItalicEmpty ? (FontStyle?)null : FontStyles.Italic) ?? TextElement.GetFontStyle(parent), (props.BoldEmpty ? (FontWeight?)null : FontWeights.Bold) ?? TextElement.GetFontWeight(parent), TextElement.GetFontStretch(parent) ); return new TextCharacters(tokenText.Length == 0 ? " " : tokenText, textProps); }