示例#1
0
        /*
         * Obtains the dimensions of text rendered at size with Cairo's
         * Toy text API.  This is solely useful when trying to get text
         * metrics without the assistance of Pango.CairoHelper.
         */
        public static void GetToyTextMetrics(int size, string text,
                                             out int width, out int height)
        {
            width = height = 0;

            if (text == null)
            {
                return;
            }

            // Create a Cairo.Context expressly for finding out the
            // size of given text, since we're not (and shouldn't
            // be) passed a Cairo.Context.
            using (Cairo.ImageSurface s = new Cairo.ImageSurface(Cairo.Format.A1,
                                                                 300, 300))
            {
                using (Cairo.Context cr = new Cairo.Context(s)) {
                    // XXX: ugh, Cairo's toy text api
                    // doesn't do any text layout
                    string[] lines = text.Split('\n');
                    foreach (string line in lines)
                    {
                        cr.SetFontSize(size);

                        Cairo.TextExtents te = cr.TextExtents(line);

                        width   = Math.Max((int)(te.Width + te.XBearing), width);
                        height += (int)te.Height;
                    }
                    height += LEADING * (lines.Length - 1);
                }
            }
        }
示例#2
0
        /*
         * Paints text to the surface with Cairo's Toy text API.  Toy
         * text API.  This is solely useful when trying to draw
         * text without the assistance of Pango.CairoHelper.
         */
        public static void PaintToyText(Cairo.Context cr, int size,
                                        string text, int x, int y,
                                        bool centered, int hint_width)
        {
            if (text == null)
            {
                return;
            }

            cr.SetFontSize(size);

            // Do manual text layout since Cairo's toy text api is
            // just that, a toy.
            string[] lines = text.Split('\n');
            foreach (string line in lines)
            {
                // Cairo's text origin is at the bottom left
                // corner of the text rect
                Cairo.TextExtents te = cr.TextExtents(line);

                int line_x = centered
                                        ? (int)(x + (hint_width / 2) - ((te.Width + te.XBearing) / 2))
                                        : x;

                // Center the text
                cr.MoveTo(line_x, y - (te.Height + te.YBearing) + te.Height);
                cr.ShowText(line);

                y += (int)te.Height + LEADING;
            }
        }
示例#3
0
            public TagBlock(Cairo.Context cr, string tag)
            {
                bool isKnownOn = tag.StartsWith("known_on_");
                bool isNotOn   = tag.StartsWith("not_on_");

                if (isKnownOn || isNotOn)
                {
                    this.IsSiteTag = true;
                    this.Text      = tag.Replace("known_on_", "").Replace("not_on_", "");
                    this.Color     = isKnownOn ? new Color(.7, 1, .7) : new Color(1, .7, .7);
                }
                else
                {
                    this.IsSiteTag = false;
                    this.Text      = tag;

                    var tagDetails = BooruApp.BooruApplication.Database.GetTag(tag);
                    if (tagDetails == null)
                    {
                        this.Color = new Color(1, 1, 1);
                    }
                    else
                    {
                        this.Color = TagDetails.GetTagTypeColor(tagDetails.Type);
                    }
                }

                Cairo.TextExtents extents = cr.TextExtents(this.Text);
                this.Position = new PointD(0.0, 0.0);
                this.Width    = extents.XAdvance;
                this.Height   = cr.FontExtents.Height;
            }
示例#4
0
		public WarpCurl(TextExtents text, Rectangle rect)
		{
			if (text == null) throw new ArgumentNullException("text");
			if (rect == null) throw new ArgumentNullException("rect");

			_rect = rect;
			_extents = text;
		}
示例#5
0
        /// <summary>
        /// Draw the specified surface.
        /// </summary>
        /// <param name="surface">Surface.</param>
        /// <param name="x">The x coordinate.</param>
        /// <param name="y">The y coordinate.</param>
        public override void Draw(Cairo.Context surface, int x, int y)
        {
            X = x;
            Y = y;


            RetrieveData();
            FindSmallestValue(_graphData);
            FindMaxValue(_graphData);

            x_scale_ratio = DrawAssembly.ContentWidth / _totalDataPoints;
            y_scale_ratio = DrawAssembly.FrameAreaHeight / (_maxValue - _minValue);



            surface.LineWidth = GraphLineWidth;
            surface.SetSourceRGBA(R, G, B, Alpha);


            //Console.WriteLine ("the smallest value is " + smallestValue);

            for (int i = 0; i < _totalDataPoints - 1; i++)
            {
                int k = i + 1;


                _p1 = new PointD(X - DrawAssembly.FrameAreaMarginLEFT + (i * (x_scale_ratio * 0.5)), Y + DrawAssembly.FrameAreaMarginTOP - (_graphData [i] - _minValue) * (y_scale_ratio * 0.5));
                _p2 = new PointD(X - DrawAssembly.FrameAreaMarginLEFT + (k * (x_scale_ratio * 0.5)), Y + DrawAssembly.FrameAreaMarginTOP - (_graphData [k] - _minValue) * (y_scale_ratio * 0.5));


                surface.MoveTo(_p1);
                surface.LineTo(_p2);

                p1Xcoordinates [i] = _p1.X;
                p1Ycoordinates [i] = _p1.Y;
            }

            DrawGraphDots(surface);
            DrawYScale(surface);

            surface.Stroke();

            string widgetText = DataStreamId;

            surface.SetFontSize(15);
            Cairo.TextExtents text = surface.TextExtents(widgetText);

            surface.SetSourceRGBA(R, G, B, Alpha);
            surface.MoveTo(DrawAssembly.FrameAreaMarginLEFT, Y + (text.Height * Id));

            surface.ShowText(widgetText);

            /*
             * surface.SetSourceRGBA (1, 1, 1, 0.5);
             * surface.Rectangle (DrawAssembly.FrameAreaMarginLEFT, 0, DrawAssembly.FrameAreaWidth, DrawAssembly.FrameAreaHeight);
             * surface.Stroke ();
             */
        }
		internal static extern void cairo_text_extents (IntPtr cr, string utf8, out TextExtents extents);
		internal static extern void cairo_scaled_font_text_extents (IntPtr scaled_font, string utf8, out TextExtents extents);
		internal static extern void cairo_scaled_font_glyph_extents (IntPtr scaled_font, IntPtr glyphs, int num_glyphs, out TextExtents extents);
		internal static extern void cairo_glyph_extents (IntPtr cr, IntPtr glyphs, int num_glyphs, out TextExtents extents);
示例#10
0
 internal static extern void cairo_text_extents(IntPtr cr, string utf8, out TextExtents extents);
示例#11
0
 internal static extern void cairo_scaled_font_glyph_extents(IntPtr scaled_font, IntPtr glyphs, int num_glyphs, out TextExtents extents);
示例#12
0
文件: Label.cs 项目: jpbruyere/Crow
        /// <summary>
        /// Update Current Column, line and TextCursorPos
        /// from mouseLocalPos
        /// </summary>
        void computeTextCursor(Context gr)
        {
            TextExtents te;

            double cPos = 0f;

            CurrentLine = (int)(mouseLocalPos.Y / fe.Height);

            //fix cu
            if (CurrentLine >= lines.Count)
                CurrentLine = lines.Count - 1;

            for (int i = 0; i < lines[CurrentLine].Length; i++)
            {
                string c = lines [CurrentLine].Substring (i, 1);
                if (c == "\t")
                    c = new string (' ', Interface.TabSize);

                te = gr.TextExtents(c);

                double halfWidth = te.XAdvance / 2;

                if (mouseLocalPos.X <= cPos + halfWidth)
                {
                    CurrentColumn = i;
                    textCursorPos = cPos;
                    mouseLocalPos = -1;
                    return;
                }

                cPos += te.XAdvance;
            }
            CurrentColumn = lines[CurrentLine].Length;
            textCursorPos = cPos;

            //reset mouseLocalPos
            mouseLocalPos = -1;
        }
示例#13
0
文件: Label.cs 项目: jpbruyere/Crow
        protected override int measureRawSize(LayoutingType lt)
        {
            if (lines == null)
                lines = getLines;

            using (ImageSurface img = new ImageSurface (Format.Argb32, 10, 10)) {
                using (Context gr = new Context (img)) {
                    //Cairo.FontFace cf = gr.GetContextFontFace ();

                    gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight);
                    gr.SetFontSize (Font.Size);

                    fe = gr.FontExtents;
                    te = new TextExtents();

                    if (lt == LayoutingType.Height){
                        int lc = lines.Count;
                        //ensure minimal height = text line height
                        if (lc == 0)
                            lc = 1;

                        return (int)Math.Ceiling(fe.Height * lc) + Margin * 2;
                    }

                    foreach (string s in lines) {
                        string l = s.Replace("\t", new String (' ', Interface.TabSize));

                        TextExtents tmp = gr.TextExtents (l);

                        if (tmp.XAdvance > te.XAdvance)
                            te = tmp;
                    }
                    return (int)Math.Ceiling (te.XAdvance) + Margin * 2;
                }
            }
        }
示例#14
0
 internal static extern void cairo_text_extents(IntPtr cr, byte[] utf8, out TextExtents extents);
示例#15
0
        private void UpdatePixbuf()
        {
            if (base.Image == null)
            {
                return;
            }

            if (notifyCount > 0)
            {
                if (base.Image.ParentWindow == null)
                {
                    return;
                }

                Gdk.Window win = Image.ParentWindow;

                Pixmap image;

                image = new Gdk.Pixmap(win, 18, 18);

                if (image == null)
                {
                    return;
                }

                int wide, high;

                image.GetSize(out wide, out high);

                Cairo.Context cc = CairoHelper.CreateCairoDrawable(image);
                //Cairo.Context cc = new Cairo.Context(surface);

                cc.Save();
//				cc.PaintWithAlpha(1.0);
                cc.Rectangle(0, 0, wide, high);
                cc.SetSourceRGBA(1.0, 1.0, 1.0, 1.0);
                //cc.FillPreserve();
                cc.Fill();
                cc.Restore();
                cc.Stroke();

                cc.Save();
//				cc.LineWidth = 0.01;
                cc.Arc(((double)wide) / 2.0, ((double)high) / 2.0, (((double)wide) / 2.0), 0.0, 2.0 * 3.14);
                if (notifyCount < 10)                 // yellow
                {
                    cc.SetSourceRGBA(0.99, 0.91, 0.31, 1.0);
                }
                else if (notifyCount < 25)                // orange
                {
                    cc.SetSourceRGBA(0.99, 0.69, 0.24, 1.0);
                }
                else                 // red
                {
                    cc.SetSourceRGBA(0.94, 0.16, 0.16, 1.0);
                }
//				cc.FillPreserve();
                cc.Fill();
                cc.Restore();
                cc.Stroke();

                string badgeString = String.Format("{0}", notifyCount);
                cc.Save();
                cc.SetSourceRGBA(0.0, 0.0, 0.0, 1.0);
                cc.FontFace("sans", FontSlant.Normal, FontWeight.Bold);
                cc.FontSize = 12;
                Cairo.TextExtents extents = cc.TextExtents(badgeString);
                double            xpos, ypos;
                xpos = ((double)wide) / 2.0 - extents.Width / 2.0;
                ypos = (((double)high) / 2.0) + (extents.Height / 2.0) - 0.5;
                cc.MoveTo(xpos, ypos);
                cc.ShowText(badgeString);
                cc.Restore();
                cc.Stroke();

                Pixbuf dp = Gdk.Pixbuf.FromDrawable(image, image.Colormap, 0, 0, 0, 0, 18, 18);

                // Create the composite image
                Colorspace colorspace    = originalPixbuf.Colorspace;
                bool       hasAlpha      = originalPixbuf.HasAlpha;
                int        bitsPerSample = originalPixbuf.BitsPerSample;
                newPixbuf = new Pixbuf(colorspace,
                                       true,
                                       bitsPerSample,
                                       originalPixbuf.Width,
                                       originalPixbuf.Height);

                originalPixbuf.CopyArea(0, 0, originalPixbuf.Width, originalPixbuf.Height, newPixbuf, 0, 0);
                dp.CopyArea(0, 0, dp.Width, dp.Height, newPixbuf, originalPixbuf.Width - dp.Width, 0);

                ((Gtk.Image)base.Image).Pixbuf = newPixbuf;
            }
            else
            {
                if (((Gtk.Image)base.Image).Pixbuf != originalPixbuf)
                {
                    ((Gtk.Image)base.Image).Pixbuf = originalPixbuf;
                }
            }
            imageNeedsUpdating = false;
        }
示例#16
0
		public TextExtents TextExtents (string utf8)
		{
			TextExtents extents = new TextExtents ();
			CairoAPI.cairo_text_extents (state, utf8, ref extents);
			return extents;
		}
示例#17
0
 internal static extern void cairo_glyph_extents(IntPtr cr, IntPtr glyphs, int num_glyphs, out TextExtents extents);
示例#18
0
		internal static extern void cairo_text_extents (IntPtr cr, byte[] utf8, out TextExtents extents);
示例#19
0
 internal static extern void cairo_scaled_font_text_extents(IntPtr scaled_font, string utf8, out TextExtents extents);
示例#20
0
		internal static extern void cairo_scaled_font_extents (IntPtr scaled_font, TextExtents extents);
示例#21
0
文件: helpers.cs 项目: kig/filezoo
 /** FAST */
 public static bool CheckTextExtents(Context cr, TextExtents te, double x, double y)
 {
     bool retval = false;
     cr.Save ();
       PointD pt = cr.CurrentPoint;
       cr.NewPath ();
       cr.Rectangle (pt.X, pt.Y, te.Width, te.Height);
       cr.IdentityMatrix ();
       retval = cr.InFill (x, y);
       if (ShowTextExtents) {
     cr.Operator = Operator.Over;
     cr.Color = new Color (1,0.5,1,0.5);
     cr.LineWidth = 0.5;
     cr.Stroke ();
       }
     cr.Restore ();
     cr.MoveTo (pt.X, pt.Y);
     return retval;
 }
示例#22
0
 internal static extern void cairo_scaled_font_extents(IntPtr scaled_font, TextExtents extents);