public void SetForegroundBrush(IBrush brush, int startIndex, int count) { var scb = brush as SolidColorBrush; if (scb != null) { var color = new Pango.Color(); color.Parse(string.Format("#{0}", scb.Color.ToString().Substring(3))); var brushAttr = new Pango.AttrForeground(color); brushAttr.StartIndex = (uint)TextIndexToPangoIndex(startIndex); brushAttr.EndIndex = (uint)TextIndexToPangoIndex(startIndex + count); Layout.Attributes.Insert(brushAttr); } }
public FormattedTextImpl( Pango.Context context, string text, Typeface typeface, TextAlignment textAlignment, TextWrapping wrapping, Size constraint, IReadOnlyList <FormattedTextStyleSpan> spans) { Contract.Requires <ArgumentNullException>(context != null); Contract.Requires <ArgumentNullException>(text != null); Layout = new Pango.Layout(context); Layout.SetText(text); Layout.FontDescription = new Pango.FontDescription { Family = typeface?.FontFamilyName ?? "monospace", Size = Pango.Units.FromDouble(CorrectScale(typeface?.FontSize ?? 12)), Style = (Pango.Style)(typeface?.Style ?? FontStyle.Normal), Weight = (typeface?.Weight ?? FontWeight.Normal).ToCairo(), }; Layout.Alignment = textAlignment.ToCairo(); Layout.Attributes = new Pango.AttrList(); Layout.Width = double.IsPositiveInfinity(constraint.Width) ? -1 : Pango.Units.FromDouble(constraint.Width); if (spans != null) { foreach (var span in spans) { if (span.ForegroundBrush is SolidColorBrush scb) { var color = new Pango.Color(); color.Parse(string.Format("#{0}", scb.Color.ToString().Substring(3))); var brushAttr = new Pango.AttrForeground(color); brushAttr.StartIndex = (uint)TextIndexToPangoIndex(span.StartIndex); brushAttr.EndIndex = (uint)TextIndexToPangoIndex(span.StartIndex + span.Length); this.Layout.Attributes.Insert(brushAttr); } } } Size = Measure(); }
public void SetForegroundBrush(IBrush brush, int startIndex, int count) { var scb = brush as SolidColorBrush; if (scb != null) { var color = new Pango.Color(); color.Parse(string.Format("#{0}", scb.Color.ToString().Substring(3))); var brushAttr = new Pango.AttrForeground(color); brushAttr.StartIndex = (uint)TextIndexToPangoIndex(startIndex); brushAttr.EndIndex = (uint)TextIndexToPangoIndex(startIndex + count); Layout.Attributes.Insert(brushAttr); } }