Ejemplo n.º 1
0
        public override void Render(Cairo.Context context)
        {
            base.Render(context);

            using Layout pangoLayout = CairoHelper.CreateLayout(context);

            pangoLayout.SetText(Text);
            Foreground.ApplyTo(context);
            context.MoveTo(RenderSize.X + Padding.Left,
                           RenderSize.Y + Padding.Top);

            pangoLayout.FontDescription = _font;
            pangoLayout.Alignment       = TextAlignment;

            CairoHelper.ShowLayout(context, pangoLayout);
        }
Ejemplo n.º 2
0
        private void DrawStringTBLR(PageText pt, Cairo.Context g, Cairo.Rectangle r)
        {
            StyleInfo si = pt.SI;
            string    s  = pt.Text;

            g.Save();

            layout = CairoHelper.CreateLayout(g);

            //Pango fonts are scaled to 72dpi, Windows fonts uses 96dpi
            float fontsize = (si.FontSize * 72 / 96);
            var   font     = FontDescription.FromString($"{si.GetFontFamily().Name} {fontsize * PixelsX(1)}");

            if (si.FontStyle == FontStyleEnum.Italic)
            {
                font.Style = Style.Italic;
            }

            switch (si.FontWeight)
            {
            case FontWeightEnum.Bold:
            case FontWeightEnum.Bolder:
            case FontWeightEnum.W500:
            case FontWeightEnum.W600:
            case FontWeightEnum.W700:
            case FontWeightEnum.W800:
            case FontWeightEnum.W900:
                font.Weight = Weight.Bold;
                break;
            }

            FontDescription oldfont = layout.FontDescription;

            layout.FontDescription = font;

            switch (si.TextAlign)
            {
            case TextAlignEnum.Right:
                layout.Alignment = Alignment.Right;
                break;

            case TextAlignEnum.Center:
                layout.Alignment = Alignment.Center;
                break;

            case TextAlignEnum.Left:
            default:
                layout.Alignment = Alignment.Left;
                break;
            }

            layout.Width = Units.FromPixels((int)(r.Height - si.PaddingTop - si.PaddingBottom - 2));

            layout.Wrap = WrapMode.WordChar;
            layout.SetText(s);

            Rectangle logical;
            Rectangle ink;

            layout.GetExtents(out ink, out logical);
            double height = logical.Height / Scale.PangoScale;
            double y      = 0;
            double x      = 0;

            switch (si.VerticalAlign)
            {
            case VerticalAlignEnum.Top:
                x = r.X + si.PaddingLeft;
                break;

            case VerticalAlignEnum.Middle:
                x = r.X + (r.Width - height) / 2;
                break;

            case VerticalAlignEnum.Bottom:
                x = r.X + (r.Width - height) + si.PaddingLeft;
                break;
            }

            // draw the background
            DrawBackground(g, r, si);

            Cairo.Rectangle box = new Cairo.Rectangle(
                x,
                r.Y + r.Height - si.PaddingBottom - 1,
                r.Height - si.PaddingBottom - si.PaddingTop,
                r.Width - si.PaddingLeft + si.PaddingRight);

            g.Color = si.Color.ToCairoColor();

            g.Rotate(270 * Math.PI / 180.0);
            CairoHelper.UpdateLayout(g, layout);

            g.MoveTo(-box.Y, box.X);
            CairoHelper.ShowLayout(g, layout);

            layout.FontDescription = oldfont;
            g.Restore();
        }
Ejemplo n.º 3
0
        private void DrawStringHorizontal(PageText pt, Cairo.Context g, Cairo.Rectangle r)
        {
            StyleInfo si = pt.SI;
            string    s  = pt.Text;

            g.Save();

            layout = CairoHelper.CreateLayout(g);

            float fontsize = si.FontSize * 72f / 96f;
            var   font     = FontDescription.FromString(string.Format("{0} {1}", si.GetFontFamily().Name,
                                                                      fontsize * PixelsX(1)));

            if (si.FontStyle == FontStyleEnum.Italic)
            {
                font.Style = Style.Italic;
            }

            switch (si.FontWeight)
            {
            case FontWeightEnum.Bold:
            case FontWeightEnum.Bolder:
            case FontWeightEnum.W500:
            case FontWeightEnum.W600:
            case FontWeightEnum.W700:
            case FontWeightEnum.W800:
            case FontWeightEnum.W900:
                font.Weight = Weight.Bold;
                break;
            }

            FontDescription oldfont = layout.FontDescription;

            layout.FontDescription = font;

            switch (si.TextAlign)
            {
            case TextAlignEnum.Right:
                layout.Alignment = Alignment.Right;
                break;

            case TextAlignEnum.Center:
                layout.Alignment = Alignment.Center;
                break;

            case TextAlignEnum.Left:
            default:
                layout.Alignment = Alignment.Left;
                break;
            }

            layout.Width = Units.FromPixels((int)(r.Width - si.PaddingLeft - si.PaddingRight - 2));
            layout.Wrap  = WrapMode.WordChar;
            layout.SetText(s);

            Rectangle logical;
            Rectangle ink;

            layout.GetExtents(out ink, out logical);
            double height = logical.Height / Scale.PangoScale;
            double y      = 0;

            switch (si.VerticalAlign)
            {
            case VerticalAlignEnum.Top:
                y = r.Y + si.PaddingTop;
                break;

            case VerticalAlignEnum.Middle:
                y = r.Y + (r.Height - height) / 2;
                break;

            case VerticalAlignEnum.Bottom:
                y = r.Y + (r.Height - height) - si.PaddingBottom;
                break;
            }

            // draw the background
            DrawBackground(g, r, si);

            Cairo.Rectangle box = new Cairo.Rectangle(
                r.X + si.PaddingLeft + 1,
                y,
                r.Width,
                r.Height);

            g.Color = si.Color.ToCairoColor();

            g.MoveTo(box.X, box.Y);

            CairoHelper.ShowLayout(g, layout);

            layout.FontDescription = oldfont;
            g.Restore();
        }