/// <summary> /// Renders given range of text /// </summary> /// <param name="gr">Graphics object</param> /// <param name="position">Position of the range in absolute control coordinates</param> /// <param name="range">Rendering range of text</param> public override void Draw(Graphics gr, Point position, Range range) { //draw background if (BackgroundBrush != null) { gr.SmoothingMode = SmoothingMode.None; var rect = new Rectangle(position.X, position.Y, (range.End.iChar - range.Start.iChar) * range.tb.CharWidth, range.tb.CharHeight); if (rect.Width == 0) { return; } gr.FillRectangle(BackgroundBrush, rect); // if (ForegroundBrush != null) { //draw text gr.SmoothingMode = SmoothingMode.AntiAlias; var r = new Range(range.tb, range.Start.iChar, range.Start.iLine, Math.Min(range.tb[range.End.iLine].Count, range.End.iChar), range.End.iLine); using (var style = new ZeroitFastTextStyle(ForegroundBrush, null, FontStyle.Regular)) style.Draw(gr, new Point(position.X, position.Y - 1), r); } } }
/// <summary> /// Gets the CSS. /// </summary> /// <param name="styleIndex">Index of the style.</param> /// <returns>System.String.</returns> private string GetCss(StyleIndex styleIndex) { List <Style> styles = new List <Style>(); //find text renderer ZeroitFastTextStyle textStyle = null; int mask = 1; bool hasZeroitFastTextStyle = false; for (int i = 0; i < tb.Styles.Length; i++) { if (tb.Styles[i] != null && ((int)styleIndex & mask) != 0) { if (tb.Styles[i].IsExportable) { var style = tb.Styles[i]; styles.Add(style); bool isZeroitFastTextStyle = style is ZeroitFastTextStyle; if (isZeroitFastTextStyle) { if (!hasZeroitFastTextStyle || tb.AllowSeveralZeroitFastTextStyleDrawing) { hasZeroitFastTextStyle = true; textStyle = style as ZeroitFastTextStyle; } } } } mask = mask << 1; } //add ZeroitFastTextStyle css string result = ""; if (!hasZeroitFastTextStyle) { //draw by default renderer result = tb.DefaultStyle.GetCSS(); } else { result = textStyle.GetCSS(); } //add no ZeroitFastTextStyle css foreach (var style in styles) { // if (style != textStyle) if (!(style is ZeroitFastTextStyle)) { result += style.GetCSS(); } } return(result); }
/// <summary> /// Gets the RTF descriptor. /// </summary> /// <param name="styleIndex">Index of the style.</param> /// <returns>RTFStyleDescriptor.</returns> private RTFStyleDescriptor GetRtfDescriptor(StyleIndex styleIndex) { List <Style> styles = new List <Style>(); //find text renderer ZeroitFastTextStyle textStyle = null; int mask = 1; bool hasZeroitFastTextStyle = false; for (int i = 0; i < tb.Styles.Length; i++) { if (tb.Styles[i] != null && ((int)styleIndex & mask) != 0) { if (tb.Styles[i].IsExportable) { var style = tb.Styles[i]; styles.Add(style); bool isZeroitFastTextStyle = style is ZeroitFastTextStyle; if (isZeroitFastTextStyle) { if (!hasZeroitFastTextStyle || tb.AllowSeveralZeroitFastTextStyleDrawing) { hasZeroitFastTextStyle = true; textStyle = style as ZeroitFastTextStyle; } } } } mask = mask << 1; } //add ZeroitFastTextStyle css RTFStyleDescriptor result = null; if (!hasZeroitFastTextStyle) { //draw by default renderer result = tb.DefaultStyle.GetRTF(); } else { result = textStyle.GetRTF(); } return(result); }
/// <summary> /// Initializes the default style. /// </summary> public virtual void InitDefaultStyle() { DefaultStyle = new ZeroitFastTextStyle(null, null, FontStyle.Regular); }