示例#1
0
        public void DrawText(Point point, double width, double height, string text,
                             bool escape = false, bool ellipsize = false)
        {
            Layout layout = null;

            Pango.Rectangle inkRect, logRect;

            if (text == null)
            {
                return;
            }

            if (escape)
            {
                text = GLib.Markup.EscapeText(text);
            }

            if (context is CairoContext)
            {
                layout = (context as CairoContext).PangoLayout;
            }
            if (layout == null)
            {
                layout = Pango.CairoHelper.CreateLayout(CContext);
            }
            if (ellipsize)
            {
                layout.Ellipsize = EllipsizeMode.End;
            }
            else
            {
                layout.Ellipsize = EllipsizeMode.None;
            }

            layout.FontDescription = FontDescription.FromString(
                String.Format("{0} {1}px", FontFamily, FontSize));
            layout.FontDescription.Weight = fWeight;
            layout.FontDescription.Style  = fSlant;
            layout.Width = Units.FromPixels((int)width);
            layout.SetPangoLayoutHeight(Units.FromPixels((int)height));
            layout.Alignment = fAlignment;
            layout.SetMarkup(text);
            SetColor(StrokeColor);
            Pango.CairoHelper.UpdateLayout(CContext, layout);
            layout.GetPixelExtents(out inkRect, out logRect);
            CContext.MoveTo(point.X, point.Y + height / 2 - (double)logRect.Height / 2);
            Pango.CairoHelper.ShowLayout(CContext, layout);
            CContext.NewPath();
        }