예제 #1
0
		void RotatedTextExposeEvent (object sender, ExposeEventArgs a)
		{
			DrawingArea drawingArea = sender as DrawingArea;

			int width = drawingArea.Allocation.Width;
			int height = drawingArea.Allocation.Height;

			double deviceRadius;

			// Get the default renderer for the screen, and set it up for drawing 
			Gdk.PangoRenderer renderer = Gdk.PangoRenderer.GetDefault (drawingArea.Screen);
			renderer.Drawable = drawingArea.GdkWindow;
			renderer.Gc = drawingArea.Style.BlackGC;

			// Set up a transformation matrix so that the user space coordinates for
			// the centered square where we draw are [-RADIUS, RADIUS], [-RADIUS, RADIUS]
			// We first center, then change the scale
			deviceRadius = Math.Min (width, height) / 2;
			Matrix matrix = Pango.Matrix.Identity;
			matrix.Translate (deviceRadius + (width - 2 * deviceRadius) / 2, deviceRadius + (height - 2 * deviceRadius) / 2);
			matrix.Scale (deviceRadius / RADIUS, deviceRadius / RADIUS);

			// Create a PangoLayout, set the font and text
			Context context = drawingArea.CreatePangoContext ();
			Pango.Layout layout = new Pango.Layout (context);
			layout.SetText ("Text");
			FontDescription desc = FontDescription.FromString ("Sans Bold 27");
			layout.FontDescription = desc;

			// Draw the layout N_WORDS times in a circle
			for (int i = 0; i < N_WORDS; i++)
			{
				Gdk.Color color = new Gdk.Color ();
				Matrix rotatedMatrix = matrix;
				int w, h;
				double angle = (360 * i) / N_WORDS;

				// Gradient from red at angle == 60 to blue at angle == 300
				color.Red = (ushort) (65535 * (1 + Math.Cos ((angle - 60) * Math.PI / 180)) / 2);
				color.Green = 0;
				color.Blue = (ushort) (65535 - color.Red);

				renderer.SetOverrideColor (RenderPart.Foreground, color);

				rotatedMatrix.Rotate (angle);
				context.Matrix = rotatedMatrix;

				// Inform Pango to re-layout the text with the new transformation matrix
				layout.ContextChanged ();
				layout.GetSize (out w, out h);
				renderer.DrawLayout (layout, - w / 2, (int) (- RADIUS * Pango.Scale.PangoScale));
			}

			// Clean up default renderer, since it is shared
			renderer.SetOverrideColor (RenderPart.Foreground, Gdk.Color.Zero);
			renderer.Drawable = null;
			renderer.Gc = null;
		}
예제 #2
0
        /// <summary>Dibuja un texto en la superficie de dibujo.</summary>
        /// <param name="c">El color del texto.</param>
        /// <param name="x">La posición x del texto.</param>
        /// <param name="y">La posición y del texto.</param>
        /// <param name="texto">El texto a dibujar en la superficie de dibujo.
        /// </param>
        /// <param name="cent">Indica si el texto está centrado (x e y se
        /// refieren al centro del texto) o no (x e y se refieren a la
        /// esquina superior del texto)</param>

        public void DibujarTexto
            (EnuColor c, int x, int y, String texto, bool cent)
        {
            int anc;
            int alt;

            lock (this)
            {
                if (pixmap != null)
                {
                    if (texto != null)
                    {
                        layout.SetText(texto);
                    }
                    else
                    {
                        layout.SetText(" ");
                    }

                    x = CoordX(x);
                    y = CoordY(y);

                    if (cent)
                    {
                        try
                        {
                            layout.GetSize(out anc, out alt);
                        }
                        catch (System.NullReferenceException)
                        {
                            this.layout = new Pango.Layout(this.PangoContext);
                            return;
                        }

                        x = x - (anc / 2200);
                        y = y - (alt / 2200);
                    }
                    pixmap.DrawLayout(GetGC(c), x, y, layout);
                }
            }
        }
예제 #3
0
        void HandleM_printDrawPage(object o, DrawPageArgs args)
        {
            // Create a Print Context from the Print Operation
            PrintContext context = args.Context;

            // Create a Cairo Context from the Print Context
            Cairo.Context cr = context.CairoContext;

            // Get the width of the Print Context
            double width = context.Width;

            // Create a rectangle to be used for the Content
            cr.Rectangle(0, 0, width, headerHeight);
            cr.SetSourceRGB(0.95, 0.95, 0.95);
            cr.FillPreserve();

            // Create a Stroke to outline the Content
            cr.SetSourceRGB(0, 0, 0);
            cr.LineWidth = 1;
            cr.Stroke();

            // Create a Pango Layout for the Text
            Pango.Layout layout = context.CreatePangoLayout();
            // Get the Text Height fromt the Height of the layout and the Height of the Page
            int layoutWidth, layoutHeight;

            layout.GetSize(out layoutWidth, out layoutHeight);
            double textHeight = (double)layoutHeight / (double)pangoScale;

            cr.MoveTo(5, (headerHeight - textHeight) / 2);

            // Set the Font and Font Size desired
            Pango.FontDescription desc = Pango.FontDescription.FromString("sans 12");
            layout.FontDescription = desc;

            // Create a Header with the FileName and center it on the page
            layout.SetText(m_cache.Name + " : " + m_cache.CacheName);
            //layout.Width = (int) width *3;
            layout.Alignment = Pango.Alignment.Left;
            Pango.CairoHelper.ShowLayout(cr, layout);


            // cr.MoveTo (width/2, (headerHeight - textHeight) / 2);


            // Set the Page Number in the Footer with a right alignment
            string pageStr = String.Format(Catalog.GetString("Page {0} of {1}"), args.PageNr + 1, m_numPages);

            layout.SetText(pageStr);
            layout.Alignment = Pango.Alignment.Right;

            cr.MoveTo(width - 75, (headerHeight - textHeight) / 2);
            Pango.CairoHelper.ShowLayout(cr, layout);

            // Create a new Pango Layout for the Content
            layout = null;
            layout = context.CreatePangoLayout();

            // Set the Description of the Content
            desc      = Pango.FontDescription.FromString("sans");
            desc.Size = (int)(m_fontSize * pangoScale);
            layout.FontDescription = desc;

            // Move to the beginning of the Content, which is after the Header Height and Gap
            cr.MoveTo(0, headerHeight + headerGap);

            int line = args.PageNr * m_linesPerPage;

            // Draw the lines on the page according to how many lines there are left and how many lines can fit on the page
            for (int i = 0; i < m_linesPerPage && line < m_numLines; i++)
            {
                layout.SetMarkup(m_Lines[line].TrimStart());
                Pango.CairoHelper.ShowLayout(cr, layout);
                cr.RelMoveTo(0, m_fontSize + 0.5);
                line++;
            }

            layout = null;
            context.Dispose();
        }
        void RotatedTextExposeEvent(object sender, ExposeEventArgs a)
        {
            DrawingArea drawingArea = sender as DrawingArea;

            int width  = drawingArea.Allocation.Width;
            int height = drawingArea.Allocation.Height;

            double deviceRadius;

            // Get the default renderer for the screen, and set it up for drawing
            Gdk.PangoRenderer renderer = Gdk.PangoRenderer.GetDefault(drawingArea.Screen);
            renderer.Drawable = drawingArea.GdkWindow;
            renderer.Gc       = drawingArea.Style.BlackGC;

            // Set up a transformation matrix so that the user space coordinates for
            // the centered square where we draw are [-RADIUS, RADIUS], [-RADIUS, RADIUS]
            // We first center, then change the scale
            deviceRadius = Math.Min(width, height) / 2;
            Matrix matrix = Pango.Matrix.Identity;

            matrix.Translate(deviceRadius + (width - 2 * deviceRadius) / 2, deviceRadius + (height - 2 * deviceRadius) / 2);
            matrix.Scale(deviceRadius / RADIUS, deviceRadius / RADIUS);

            // Create a PangoLayout, set the font and text
            Context context = drawingArea.CreatePangoContext();

            Pango.Layout layout = new Pango.Layout(context);
            layout.SetText("Text");
            FontDescription desc = FontDescription.FromString("Sans Bold 27");

            layout.FontDescription = desc;

            // Draw the layout N_WORDS times in a circle
            for (int i = 0; i < N_WORDS; i++)
            {
                Gdk.Color color = new Gdk.Color();
                Matrix    rotatedMatrix = matrix;
                int       w, h;
                double    angle = (360 * i) / N_WORDS;

                // Gradient from red at angle == 60 to blue at angle == 300
                color.Red   = (ushort)(65535 * (1 + Math.Cos((angle - 60) * Math.PI / 180)) / 2);
                color.Green = 0;
                color.Blue  = (ushort)(65535 - color.Red);

                renderer.SetOverrideColor(RenderPart.Foreground, color);

                rotatedMatrix.Rotate(angle);
                context.Matrix = rotatedMatrix;

                // Inform Pango to re-layout the text with the new transformation matrix
                layout.ContextChanged();
                layout.GetSize(out w, out h);
                renderer.DrawLayout(layout, -w / 2, (int)(-RADIUS * Pango.Scale.PangoScale));
            }

            // Clean up default renderer, since it is shared
            renderer.SetOverrideColor(RenderPart.Foreground, Gdk.Color.Zero);
            renderer.Drawable = null;
            renderer.Gc       = null;
        }
예제 #5
0
파일: Canvas.cs 프로젝트: jonasoster/smul
    public override void Layout(Cairo.Context cr)
    {
        layout = Pango.CairoHelper.CreateLayout(cr);
        Pango.FontDescription desc = Pango.FontDescription.FromString("sans 7");
        layout.FontDescription = desc;
        layout.SetMarkup(Text);
        layout.Width = (int)(Pango.Scale.PangoScale*(Width - 2*BorderWidth));
        layout.Alignment = Pango.Alignment.Center;

        int layoutWidth, layoutHeight;
        layout.GetSize (out layoutWidth, out layoutHeight);
        double textHeight = (double)layoutHeight / Pango.Scale.PangoScale;
        double textWidth = (double)layoutWidth / Pango.Scale.PangoScale;

        if(textWidth < Width)
        {
            textWidth = Width;
        }

        X0 = XCenter - textWidth/2.0 - BorderWidth;
        X1 = XCenter + textWidth/2.0 + BorderWidth;
        Y0 = YTop;
        Y1 = YTop + textHeight + 2.0*BorderWidth;
    }