Esempio n. 1
0
        //TODO: Deprecate Cairo usage entirely
        public Gdk.Rectangle RenderLayoutText(Context cr, String text, int x, int y, int width, int textHeight,
                                              Constants.Color color, Pango.Alignment align, Pango.EllipsizeMode ellipse, int horisontalOffset = 0)
        {
            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 + horisontalOffset, 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. 2
0
        public void Label(System.Object value, int x, int y, Pango.FontDescription font, int width, Constants.Color color)
        {
            Pango.Layout layout       = new Pango.Layout(widget.PangoContext);
            LayoutHelper layoutHelper = LayoutHelper.Factor(value);

            layout.SetMarkup("<span color=" + (char)34 + "#" + color.ToString() + (char)34 + ">" + layoutHelper.Text + "</span>");

            if (width != 0)
            {
                layout.Ellipsize = Pango.EllipsizeMode.End;
                layout.Width     = Pango.Units.FromPixels(width);
            }

            //	layout.Alignment = layoutHelper.Alignment;
            layout.FontDescription = font;

            drawable.DrawLayout(gc, exposeArea.X + x, exposeArea.Y + y, layout);
        }