Esempio n. 1
0
        public void SetColor(Pango.RenderPart part, Pango.Color color)
        {
            IntPtr native_color = GLib.Marshaller.StructureToPtrAlloc(color);

            pango_renderer_set_color(Handle, (int)part, native_color);
            Marshal.FreeHGlobal(native_color);
        }
Esempio n. 2
0
        public Pango.Color GetColor(Pango.RenderPart part)
        {
            IntPtr raw_ret = pango_renderer_get_color(Handle, (int)part);

            Pango.Color ret = Pango.Color.New(raw_ret);
            return(ret);
        }
Esempio n. 3
0
        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);
            }
        }
Esempio n. 4
0
        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();
        }
Esempio n. 5
0
        void RenderTextModeText(Context cr)
        {
            Pango.Color color = new Pango.Color();
            color.Blue = color.Red = color.Green = (ushort)(ushort.MaxValue * text_box_scale);
            Gdk.Rectangle cursor = TextUtility.RenderLayoutText(cr, GLib.Markup.EscapeText(Context.GetPaneQuery(Focus)),
                                                                drawing_area.X + 10, drawing_area.Y + TextModeOffset + 5,
                                                                drawing_area.Width - 20, 18, color,
                                                                Pango.Alignment.Left, Pango.EllipsizeMode.None);
            if (cursor.X == cursor.Y && cursor.X == 0)
            {
                return;
            }

            cr.Rectangle(cursor.X, cursor.Y, 2, cursor.Height);
            cr.SetSourceRGBA(.4, .5, 1, .85);
            cr.Fill();
        }
Esempio n. 6
0
        public Gdk.Rectangle RenderLayoutText(Context cr, string text, int x, int y, int width, int textHeight,
                                              Pango.Color color, Pango.Alignment align, Pango.EllipsizeMode ellipse)
        {
            if (string.IsNullOrEmpty(text))
            {
                return(new Gdk.Rectangle());
            }

            if (layout != null)
            {
                layout.Context.Dispose();
                layout.FontDescription.Dispose();
                layout.Dispose();
            }
            layout = new Pango.Layout(ReferenceWidget.CreatePangoContext());
            layout.FontDescription = new Pango.FontDescription();
            layout.FontDescription.AbsoluteSize = Pango.Units.FromPixels(textHeight);

            layout.Width     = Pango.Units.FromPixels(width);
            layout.Ellipsize = ellipse;
            layout.Alignment = align;

            if (ellipse == Pango.EllipsizeMode.None)
            {
                layout.Wrap = Pango.WrapMode.WordChar;
            }

            text = string.Format("<span foreground=\"{0}\">{1}</span>", color, text);
            layout.SetMarkup(text);

            cr.Rectangle(x, y, width, 155);
            cr.Clip();
            cr.MoveTo(x, y);
            Pango.CairoHelper.ShowLayout(cr, layout);
            Pango.Rectangle strong, weak;
            layout.GetCursorPos(layout.Lines [layout.LineCount - 1].StartIndex +
                                layout.Lines [layout.LineCount - 1].Length,
                                out strong, out weak);
            cr.ResetClip();
            return(new Gdk.Rectangle(Pango.Units.ToPixels(weak.X) + x,
                                     Pango.Units.ToPixels(weak.Y) + y,
                                     Pango.Units.ToPixels(weak.Width),
                                     Pango.Units.ToPixels(weak.Height)));
        }
Esempio n. 7
0
        void RenderPaneText(Pane pane, Context cr, string text)
        {
            if (text.Length == 0)
            {
                return;
            }

            if (Context.GetPaneTextMode(pane))
            {
                Pango.Color color = new Pango.Color();
                color.Blue = color.Green = color.Red = ushort.MaxValue;
                int y = drawing_area.Y + WindowBorder + TitleBarHeight + 6;
                int x = drawing_area.X + PaneOffset(pane) + 5;

                TextUtility.RenderLayoutText(cr, text, x, y, BoxWidth - 10, TextHeight, color,
                                             Pango.Alignment.Left, Pango.EllipsizeMode.None);
            }
            else
            {
                string query = Context.GetPaneQuery(pane);
                if (!string.IsNullOrEmpty(query))
                {
                    text = Util.FormatCommonSubstrings(text, query, HighlightFormat);
                }

                if (PaneOutlineRenderer.StackIconText)
                {
                    int y = drawing_area.Y + WindowBorder + TitleBarHeight + BoxHeight - TextHeight - 9;
                    int x = drawing_area.X + PaneOffset(pane) + 5;
                    TextUtility.RenderLayoutText(cr, text, x, y, BoxWidth - 10, TextHeight);
                }
                else
                {
                    int y = drawing_area.Y + WindowBorder + TitleBarHeight + (int)(BoxHeight / 2);
                    int x = drawing_area.X + PaneOffset(pane) + IconSize + 10;
                    TextUtility.RenderLayoutText(cr, text, x, y, BoxWidth - IconSize - 20, TextHeight);
                }
            }
        }
Esempio n. 8
0
 static void ReadNative(IntPtr native, ref Pango.Color target)
 {
     target = New(native);
 }
 public AttrUnderlineColor(Pango.Color color) : this(pango_attr_underline_color_new(color.Red, color.Green, color.Blue))
 {
 }
Esempio n. 10
0
 public AttrBackground(Pango.Color color) : this(pango_attr_background_new(color.Red, color.Green, color.Blue))
 {
 }
Esempio n. 11
0
 public AttrStrikethroughColor(Pango.Color color) : this(pango_attr_strikethrough_color_new(color.Red, color.Green, color.Blue))
 {
 }
Esempio n. 12
0
        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);
            }
        }
Esempio n. 13
0
 public AttrForeground(Pango.Color color) : this(pango_attr_foreground_new(color.Red, color.Green, color.Blue))
 {
 }
Esempio n. 14
0
 public void RenderLayoutText(Context cr, string text, int x, int y, int width, int textHeight)
 {
     Pango.Color color = new Pango.Color();
     color.Blue = color.Red = color.Green = ushort.MaxValue;
     RenderLayoutText(cr, text, x, y, width, textHeight, color, Pango.Alignment.Center, Pango.EllipsizeMode.End);
 }