Exemplo n.º 1
0
        public static Rectangle DrawText(this Context g, PointD p, string family, Cairo.FontSlant slant, Cairo.FontWeight weight, double size, Cairo.Color color, double width, string text)
        {
            g.Save();
            g.MoveTo(p.X, p.Y);
            g.Color = color;
            Pango.Layout layout = Pango.CairoHelper.CreateLayout(g);
            layout.Wrap  = Pango.WrapMode.Char;
            layout.Width = (int)(width * Pango.Scale.PangoScale);
            Pango.FontDescription fd = new Pango.FontDescription();
            fd.Family = family;


            fd.Style  = CairoToPangoSlant(slant);
            fd.Weight = CairoToPangoWeight(weight);

            fd.AbsoluteSize        = size * Pango.Scale.PangoScale;
            layout.FontDescription = fd;

            layout.Spacing   = 0;
            layout.Alignment = Pango.Alignment.Left;
            layout.SetText(text);

            Pango.Rectangle unused = Pango.Rectangle.Zero;
            Pango.Rectangle te     = Pango.Rectangle.Zero;
            layout.GetExtents(out unused, out te);
            Pango.CairoHelper.ShowLayout(g, layout);

            layout.GetExtents(out unused, out te);

            (layout as IDisposable).Dispose();

            g.Restore();

            return(new Rectangle(p.X + unused.X / Pango.Scale.PangoScale, p.Y + unused.Y / Pango.Scale.PangoScale, (unused.Width / Pango.Scale.PangoScale), (unused.Height / Pango.Scale.PangoScale)));
        }
Exemplo n.º 2
0
 private static Pango.Weight CairoToPangoWeight(Cairo.FontWeight weight)
 {
     return((weight == Cairo.FontWeight.Bold) ? Pango.Weight.Bold : Pango.Weight.Normal);
 }