TextExtents() public method

public TextExtents ( byte utf8 ) : TextExtents
utf8 byte
return TextExtents
示例#1
0
 public virtual void Paint(Context ctx)
 {
     PointD size = this.MeasureSize (ctx);
     PaintContour (ctx,size);
     KnownColors.SetFontFacePieceName(ctx);
     TextExtents te = ctx.TextExtents(this.Name), ten;
     double y0 = 0.5d*(size.Y-te.Width);
     ctx.MoveTo(0.5d*Margin,y0);
     ctx.Save();
     ctx.Rotate(0.5d*Math.PI);
     ctx.ShowText(this.Name);
     ctx.Restore();
     double x0 = Margin+te.Height;
     KnownColors.SetFontFaceNormal(ctx);
     te = ctx.TextExtents(OptionalString);
     y0 = 2.0d*Margin;
     int index = 0x00;
     PointD siz;
     foreach(IPuzzlePiece ipp in this.arguments) {
         ctx.Save();
         ctx.Translate(x0,Margin);
         if(ipp == null) {
             siz = new PointD(MinimumWidth,size.Y-4.0d*Margin);
             ctx.Rectangle(Margin,Margin,siz.X,siz.Y);
             ctx.Pattern = KnownColors.ConstructionPattern;
             ctx.FillPreserve();
         }
         else {
             siz = ipp.MeasureSize(ctx);
         }
         ctx.Rectangle(0.0d,0.0d,siz.X+2.0d*Margin,siz.Y+2.0d*Margin);
         ctx.Color = KnownColors.Black;
         ctx.StrokePreserve();
         if(ipp == null) {
             ctx.Pattern = ExtensionMethods.GenerateColorSequencePattern(siz.X+2.0d*Margin,TypeColorArguments[index]);
             ctx.Fill();
             ctx.Translate(Margin,Margin);
             ctx.MoveTo(0.0d,0.0d);
             ctx.LineTo(MinimumWidth,0.0d);
             ctx.RelLineTo(0.0d,5.0d);
             ctx.LineTo(5.0d,5.0d);
             ctx.ClosePath();
             ctx.Pattern = KnownColors.ShadowDownPattern;
             ctx.Fill();
             ctx.MoveTo(0.0d,0.0d);
             ctx.LineTo(0.0d,siz.Y);
             ctx.RelLineTo(5.0d,0.0d);
             ctx.LineTo(5.0d,5.0d);
             ctx.ClosePath();
             ctx.Pattern = KnownColors.ShadowRightPattern;
             ctx.Fill();
         }
         else {
             ctx.Pattern = ExtensionMethods.GenerateColorSequencePattern(siz.X+2.0d*Margin,TypeColorArguments[index]);
             ctx.Fill();
             ctx.Color = KnownColors.Black;
             ctx.Translate(Margin,Margin);
             ipp.Paint(ctx);
         }
         ctx.Restore();
         subpieces[index] = new Rectangle(x0+Margin,2.0d*Margin,siz.X,siz.Y);
         x0 += siz.X+3.0d*Margin;
         if(index >= NumberOfArguments-NumberOfOptionalArguments) {
             ctx.MoveTo(x0-2.0d*Margin-0.5d*(siz.X+te.Width),siz.Y+3.0d*Margin-2.0d);
             ctx.ShowText(OptionalString);
         }
         if(this.ArgumentNames != null && index < arguments.Length) {
             ten = ctx.TextExtents(this.ArgumentNames[index]);
             ctx.MoveTo(x0-2.0d*Margin-0.5d*(siz.X+ten.Width),-te.YBearing+Margin+2.0d);
             ctx.ShowText(this.ArgumentNames[index]);
         }
         index++;
     }
 }
示例#2
0
 protected void DrawRightsideHorisontalNumbers(Context g, Gdk.Rectangle area, float ySize)
 {
     for (int i = 0; i <= NumbersY; i++) {
         float actualLoc = (1 - i/NumbersY) * (area.Height - numberSpacingYTotal) + NumberSpacingYUp;
         String text = (i*ySize/NumbersY).ToString ("0.0");
         TextExtents size = g.TextExtents (text);
         g.MoveTo (area.Width-NumberSpacingXRight, actualLoc + size.Height / 2);
         g.ShowText (text);
     }
 }
示例#3
0
文件: Label.cs 项目: jpbruyere/Crow
        protected override void onDraw(Context gr)
        {
            base.onDraw (gr);

            gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight);
            gr.SetFontSize (Font.Size);
            gr.FontOptions = Interface.FontRenderingOptions;
            gr.Antialias = Interface.Antialias;

            rText = new Rectangle(new Size(
                measureRawSize(LayoutingType.Width), measureRawSize(LayoutingType.Height)));
            rText.Width -= 2 * Margin;
            rText.Height -= 2 * Margin;

            widthRatio = 1f;
            heightRatio = 1f;

            Rectangle cb = ClientRectangle;

            rText.X = cb.X;
            rText.Y = cb.Y;

            if (horizontalStretch) {
                widthRatio = (float)cb.Width / (float)rText.Width;
                if (!verticalStretch)
                    heightRatio = widthRatio;
            }

            if (verticalStretch) {
                heightRatio = (float)cb.Height / (float)rText.Height;
                if (!horizontalStretch)
                    widthRatio = heightRatio;
            }

            rText.Width = (int)(widthRatio * (float)rText.Width);
            rText.Height = (int)(heightRatio * (float)rText.Height);

            switch (TextAlignment)
            {
            case Alignment.TopLeft:     //ok
                rText.X = cb.X;
                rText.Y = cb.Y;
                break;
            case Alignment.Top:   //ok
                rText.Y = cb.Y;
                rText.X = cb.X + cb.Width / 2 - rText.Width / 2;
                break;
            case Alignment.TopRight:    //ok
                rText.Y = cb.Y;
                rText.X = cb.Right - rText.Width;
                break;
            case Alignment.Left://ok
                rText.X = cb.X;
                rText.Y = cb.Y + cb.Height / 2 - rText.Height / 2;
                break;
            case Alignment.Right://ok
                rText.X = cb.X + cb.Width - rText.Width;
                rText.Y = cb.Y + cb.Height / 2 - rText.Height / 2;
                break;
            case Alignment.Bottom://ok
                rText.X = cb.Width / 2 - rText.Width / 2;
                rText.Y = cb.Height - rText.Height;
                break;
            case Alignment.BottomLeft://ok
                rText.X = cb.X;
                rText.Y = cb.Bottom - rText.Height;
                break;
            case Alignment.BottomRight://ok
                rText.Y = cb.Bottom - rText.Height;
                rText.X = cb.Right - rText.Width;
                break;
            case Alignment.Center://ok
                rText.X = cb.X + cb.Width / 2 - rText.Width / 2;
                rText.Y = cb.Y + cb.Height / 2 - rText.Height / 2;
                break;
            }

            gr.FontMatrix = new Matrix(widthRatio * (float)Font.Size, 0, 0, heightRatio * (float)Font.Size, 0, 0);
            fe = gr.FontExtents;

            #region draw text cursor
            if (HasFocus && Selectable)
            {
                if (mouseLocalPos >= 0)
                {
                    computeTextCursor(gr);

                    if (SelectionInProgress)
                    {
                        if (SelBegin < 0){
                            SelBegin = new Point(CurrentColumn, CurrentLine);
                            SelStartCursorPos = textCursorPos;
                            SelRelease = -1;
                        }else{
                            SelRelease = new Point(CurrentColumn, CurrentLine);
                            if (SelRelease == SelBegin)
                                SelRelease = -1;
                            else
                                SelEndCursorPos = textCursorPos;
                        }
                    }
                }else
                    computeTextCursorPosition(gr);

                Foreground.SetAsSource (gr);
                gr.LineWidth = 1.0;
                gr.MoveTo (0.5 + textCursorPos + rText.X, rText.Y + CurrentLine * fe.Height);
                gr.LineTo (0.5 + textCursorPos + rText.X, rText.Y + (CurrentLine + 1) * fe.Height);
                gr.Stroke();
            }
            #endregion

            //****** debug selection *************
            //			if (SelRelease >= 0) {
            //				gr.Color = Color.Green;
            //				Rectangle R = new Rectangle (
            //					             rText.X + (int)SelEndCursorPos - 2,
            //					             rText.Y + (int)(SelRelease.Y * fe.Height),
            //					             4,
            //					             (int)fe.Height);
            //				gr.Rectangle (R);
            //				gr.Fill ();
            //			}
            //			if (SelBegin >= 0) {
            //				gr.Color = Color.UnmellowYellow;
            //				Rectangle R = new Rectangle (
            //					rText.X + (int)SelStartCursorPos - 2,
            //					rText.Y + (int)(SelBegin.Y * fe.Height),
            //					4,
            //					(int)fe.Height);
            //				gr.Rectangle (R);
            //				gr.Fill ();
            //			}
            //*******************

            for (int i = 0; i < lines.Count; i++) {
                string l = lines [i].Replace ("\t", new String (' ', Interface.TabSize));
                int lineLength = (int)gr.TextExtents (l).XAdvance;
                Rectangle lineRect = new Rectangle (
                    rText.X,
                    rText.Y + (int)Math.Ceiling(i * fe.Height),
                    lineLength,
                    (int)Math.Ceiling(fe.Height));

            //				if (TextAlignment == Alignment.Center ||
            //					TextAlignment == Alignment.Top ||
            //					TextAlignment == Alignment.Bottom)
            //					lineRect.X += (rText.Width - lineLength) / 2;
            //				else if (TextAlignment == Alignment.Right ||
            //					TextAlignment == Alignment.TopRight ||
            //					TextAlignment == Alignment.BottomRight)
            //					lineRect.X += (rText.Width - lineLength);
                if (Selectable) {
                    if (SelRelease >= 0 && i >= selectionStart.Y && i <= selectionEnd.Y) {
                        gr.SetSourceColor (selBackground);

                        Rectangle selRect = lineRect;

                        int cpStart = (int)SelStartCursorPos,
                        cpEnd = (int)SelEndCursorPos;

                        if (SelBegin.Y > SelRelease.Y) {
                            cpStart = cpEnd;
                            cpEnd = (int)SelStartCursorPos;
                        }

                        if (i == selectionStart.Y) {
                            selRect.Width -= cpStart;
                            selRect.Left += cpStart;
                        }
                        if (i == selectionEnd.Y)
                            selRect.Width -= (lineLength - cpEnd);

                        gr.Rectangle (selRect);
                        gr.Fill ();
                    }
                }

                if (string.IsNullOrWhiteSpace (l))
                    continue;

                Foreground.SetAsSource (gr);
                gr.MoveTo (lineRect.X, rText.Y + fe.Ascent + fe.Height * i);
                gr.ShowText (l);
                gr.Fill ();
            }
        }
示例#4
0
文件: Label.cs 项目: jpbruyere/Crow
 /// <summary> Compute x offset in cairo unit from text position </summary>
 double GetXFromTextPointer(Context gr, Point pos)
 {
     try {
         string l = lines [pos.Y].Substring (0, pos.X).
             Replace ("\t", new String (' ', Interface.TabSize));
         return gr.TextExtents (l).XAdvance;
     } catch{
         return -1;
     }
 }
 private void paintNodes(Context ctx, int w, int h, IEnumerable<Node> nodes)
 {
     ctx.LineWidth = 2.0d;
     foreach(Node node in nodes) {
         PointD abs = new PointD(node.Item2.X*w, node.Item2.Y*h);
         ctx.Arc(abs.X, abs.Y, AlgorithmRadius, 0.0d, 2.0d*Math.PI);
         ctx.ClosePath();
         ctx.NewSubPath();
         ctx.Arc(abs.X, abs.Y, AlgorithmRadius-BlueprintStyle.Thickness, 0.0d, 2.0d*Math.PI);
         ctx.ClosePath();
         ctx.NewSubPath();
     }
     ctx.Pattern = BlueprintStyle.FillPattern;
     ctx.FillPreserve();
     ctx.Color = BlueprintStyle.HardWhite;
     ctx.Stroke();
     double r_2, dx, dy;
     this.nodeCenters.Clear();
     foreach(Node node in nodes) {
         PointD abs = new PointD(node.Item2.X*w, node.Item2.Y*h);
         this.nodeCenters.Add(abs);
         TextExtents te = ctx.TextExtents(node.Item1);
         r_2 = (AlgorithmRadius-BlueprintStyle.Thickness)/Math.Sqrt(te.Width*te.Width+te.Height*te.Height);
         ctx.Save();
         ctx.MoveTo(abs.X-r_2*te.Width, abs.Y+r_2*te.Height);
         ctx.Scale(2.0d*r_2, 2.0d*r_2);
         ctx.ShowText(node.Item1);
         ctx.Restore();
     }
 }
示例#6
0
		public void text_extents(Context cr, int width, int height)
		{
			double x=0.1;
			double y=0.6;
			string utf8 = "cairo";
			Normalize (cr, width, height);

			cr.SelectFontFace("Sans", FontSlant.Normal, FontWeight.Normal);

			cr.SetFontSize(0.4);
			TextExtents extents = cr.TextExtents(utf8);

			cr.MoveTo(x,y);
			cr.ShowText(utf8);

			// draw helping lines
			cr.Color = new Color (1, 0.2, 0.2, 0.6);
			cr.Arc(x, y, 0.05, 0, 2*Math.PI);
			cr.Fill();
			cr.MoveTo(x,y);
			cr.RelLineTo(0, -extents.Height);
			cr.RelLineTo(extents.Width, 0);
			cr.RelLineTo(extents.XBearing, -extents.YBearing);
			cr.Stroke();
		}
        private void RenderSkillCell(Context context, Gdk.Rectangle pix_rect, bool isSelected)
        {
            int osOffset = 0;
            int startX = pix_rect.Right - 64;

            if(ECM.Helper.CurrentPlatform == ECM.Helper.Platform.Windows)
                osOffset = 1;

            // Render Text
            context.Save();

            Color col = White;

            //if (!isSelected)
            //    col = Black;

            string s = string.Format("{0} ({1}x)", Text, SkillRank);
            TextExtents te = context.TextExtents(s);
            RenderText(context, s, pix_rect.X + 32, pix_rect.Y + 2, col);

            s = string.Format("Level {0}", SkillLevel);
            te = context.TextExtents(s);
            RenderText(context, s, startX - (te.Width + 6), pix_rect.Y + 2, col);

            s = ECM.Helper.GetDurationInWordsShort(TimeSpan.FromMinutes(SkillMinsToNext));
            te = context.TextExtents(s);
            RenderText(context, s, startX - (te.Width + 6), pix_rect.Y + te.Height + 6, col);

            s = string.Format("SP {0:0,0}/{1:0,0}", SkillCurrSP, SkillNextSP);
            context.SelectFontFace(m_FontDesc.Family, FontSlant.Normal, FontWeight.Bold);
            te = context.TextExtents(s);

            RenderText(context, s, pix_rect.X + 32, pix_rect.Y + te.Height + 6, col);

            context.Restore();

            // Render Progress bars
            context.Save();

            context.Color = Gray;
            context.Antialias = Antialias.None;
            context.LineWidth = 1;

            for (int i = 0; i < SkillLevel; i++)
            {
                context.Rectangle(startX + 2 + i * 9, pix_rect.Y + 3 + osOffset, 8, 6);
            }

            // Time Bar
            double fullWidth = 44;
            double dist = SkillNextSP - SkillLevlSP;
            double trav = SkillCurrSP - SkillLevlSP;
            double perc = 1;

            if(dist > 0)
                perc = Math.Max(0, trav / dist);

            context.Rectangle(startX + 2, pix_rect.Y + 17 + osOffset, fullWidth * perc, 2);

            context.Fill();

            context.Rectangle(startX, pix_rect.Y + 2, 47, 9);

            context.Rectangle(startX, pix_rect.Y + 16, 47, 5);

            context.Stroke();

            context.Restore();

            // Render Skillbook Icon
            context.Save();
            Gdk.CairoHelper.SetSourcePixbuf(context, new Gdk.Pixbuf(ECM.Core.SkillbookPNG), pix_rect.X, pix_rect.Y);

            context.Paint();
            context.Restore();
        }
 public void Text(Context context,  string txt, HorizontalTextAlignment horizontal = HorizontalTextAlignment.Center, VerticalTextAlignment vertical = VerticalTextAlignment.Middle)
 {
     context.SelectFontFace ("Sans", FontSlant.Normal, FontWeight.Normal);
     //context.SetFontSize (_surface.Height / 10);
     context.SetFontSize (14);
     var extends = context.TextExtents (txt);
     double x, y;
     x = -(((double)horizontal) / 2 * extends.Width + extends.XBearing);
     y = -(((double)vertical) / 2 * extends.Height + extends.YBearing);
     context.RelMoveTo (x, y);
     context.ShowText (txt);
 }
示例#9
0
        const int yc = yb + 25;  // subrow 3


        public static void RenderCharacterStatus(Gdk.Drawable d, Cairo.Context g, Character c, int x, int y, bool showFurySadness = true)
        {
            TextExtents te;

            string lvl, hp, hpm, mp, mpm;

            g.SelectFontFace(Text.MONOSPACE_FONT, FontSlant.Normal, FontWeight.Normal);

            g.Color = Colors.TEXT_TEAL;
            g.MoveTo(x + x3, y + ya);
            g.ShowText("LV");
            g.MoveTo(x + x3, y + yb);
            g.ShowText("HP");
            g.MoveTo(x + x3, y + yc);
            g.ShowText("MP");
            g.Color = Colors.WHITE;

            if (showFurySadness)
            {
                if (c.Fury)
                {
                    Text.ShadowedText(g, Colors.TEXT_MAGENTA, "[Fury]", x + x7, y);
                }
                else if (c.Sadness)
                {
                    Text.ShadowedText(g, Colors.TEXT_MAGENTA, "[Sadness]", x + x7, y);
                }
            }

            Color namec = Colors.WHITE;

            if (c.Death)
            {
                namec = Colors.TEXT_RED;
            }
            else if (c.NearDeath)
            {
                namec = Colors.TEXT_YELLOW;
            }

            Text.ShadowedText(g, namec, c.Name, x + x3, y);


            lvl = c.Level.ToString();
            te  = g.TextExtents(lvl);
            Text.ShadowedText(g, lvl, x + x4 - te.Width, y + ya);

            hp = c.HP.ToString() + "/";
            te = g.TextExtents(hp);
            Text.ShadowedText(g, hp, x + x5 - te.Width, y + yb);

            hpm = c.MaxHP.ToString();
            te  = g.TextExtents(hpm);
            Text.ShadowedText(g, hpm, x + x6 - te.Width, y + yb);

            mp = c.MP.ToString() + "/";
            te = g.TextExtents(mp);
            Text.ShadowedText(g, mp, x + x5 - te.Width, y + yc);

            mpm = c.MaxMP.ToString();
            te  = g.TextExtents(mpm);
            Text.ShadowedText(g, mpm, x + x6 - te.Width, y + yc);
        }
示例#10
0
        /*
        [XmlIgnore]
        public FontFamily font;
        */
        public void InternalRegenerateCloud()
        {
            r = new Random();
            int id = 0;
            double minSize = Entries.Min(e => e.SizeValue);
            double maxSize = Entries.Max(e => e.SizeValue);
            double range = Math.Max(0.00001, maxSize - minSize);

            _source = new ImageSurface(Format.Argb32,ActualWidth,ActualHeight);
            pixelss = _source.Data;
            g = new Context(_source);
            g.Color = new Color(1.0,1.0,1.0);
            //g.Rectangle(0.0,0.0,ActualWidth,ActualHeight);
            g.Paint();

            g.SelectFontFace(fontname,FontSlant.Normal,FontWeight.Bold);
            g.SetFontSize(100.0);
            TextExtents te = g.TextExtents("x");
            double areaPerLetter = te.Width;

            strides = _source.Stride;
            int arraySize = (int)((ActualWidth / 4) + 2) * (int)((ActualHeight / 4) + 2);
            _mapping = new int[arraySize];
            for (int i = 0; i < arraySize; i++) _mapping[i] = -1;

            if(svgfn != null) {
                svgs = new SvgSurface(svgfn,ActualWidth,ActualHeight);
                svg = new Context(svgs);
                svg.SelectFontFace(fontname,FontSlant.Normal,FontWeight.Bold);
            }
            if(pdffn != null) {
                pdfs = new PdfSurface(pdffn,ActualWidth,ActualHeight);
                pdf = new Context(pdfs);
                pdf.SelectFontFace(fontname,FontSlant.Normal,FontWeight.Bold);
            }

            double fontMultiplier;

            if(CoverRatio > 0.0) {
                double totalsize = 0.0;
                MinFontSize = 24.0; // use big fonts for testing
                if(FontMaxRatio < 1.0 || FontMaxRatio > 500.0) FontMaxRatio = 6.0;
                MaxFontSize = FontMaxRatio*MinFontSize;
                fontMultiplier = (MaxFontSize - MinFontSize) / range;
                foreach(WordCloudEntry e in Entries) {
                    float fontsize = (float)(((e.SizeValue - minSize) * fontMultiplier) + MinFontSize);
                    g.SetFontSize(fontsize);
                    TextExtents te1 = g.TextExtents(e.Word);
                    totalsize += te1.Width*te1.Height;
                }
                double actualsize = ActualHeight*ActualWidth;
                double ratio1 = totalsize / actualsize; //this should be == CoverRatio
                //we assume that totalsize ~ MinFontSize^2 in this case
                MinFontSize = MinFontSize*Math.Sqrt(CoverRatio / ratio1);
                MaxFontSize = FontMaxRatio*MinFontSize;
                fontMultiplier = (MaxFontSize - MinFontSize) / range;
                LargestSizeWidthProportion = 0.9;
            }

            double targetWidth = Math.Max(ActualWidth, ActualHeight) * LargestSizeWidthProportion;
            WordCloudEntry od = Entries.OrderByDescending(e => (e.SizeValue - minSize) * e.Word.Length).First();
            double maxFontSize;
            if(MaxFontSize > 0.0 && CoverRatio <= 0.0) {
                maxFontSize = MaxFontSize;
                if(maxFontSize < MinFontSize) maxFontSize = MinFontSize*2.7;
            }
            else {
                g.SetFontSize(100.0);
                TextExtents te2 = g.TextExtents(od.Word);
                maxFontSize = 97.0*targetWidth / te2.Width;
                //maxFontSize = Math.Max(MinFontSize * 2.7, 100.0 / ((od.Word.Length * areaPerLetter) / targetWidth));
                if(maxFontSize > MinFontSize + 100) maxFontSize = MinFontSize + 100;
            }
            if(CoverRatio > 0.0) {
                if(maxFontSize < MaxFontSize) MaxFontSize = maxFontSize;
                fontMultiplier = (maxFontSize - MinFontSize) / range;
            }
            else fontMultiplier = (maxFontSize - MinFontSize) / range;

            var points = new[]
                             {
                                 new Point((int) (ActualWidth/2), (int) (ActualHeight/2)),
                                 new Point((int) (ActualWidth/4), (int) (ActualHeight/4)),
                                 new Point((int) (ActualWidth/4), (int) (3*ActualHeight/2)),
                                 new Point((int) (3*ActualWidth/4), (int) (ActualHeight/2)),
                                 new Point((int) (3*ActualWidth/4), (int) (3*ActualHeight/4))
                             };

            int currentPoint = 0;
            foreach (WordCloudEntry e in Entries.OrderByDescending(e => e.SizeValue))
            {
            again:
                double position = 0.0;
                Point centre = points[currentPoint];

                double angle = 0.0;
                if(vratio > 0.0)
                {
                    if(r.NextDouble() < vratio) angle = 90.0;
                }
                float fontsize = (float)(((e.SizeValue - minSize) * fontMultiplier) + MinFontSize);
                ImageSurface bm;
            imgretry:
                bm = CreateImage(e.Word,fontsize,e.Color,angle);
                // test if it fits
                if(angle == 90.0) {
                    if(bm.Height > ActualHeight) {
                        if(ActualWidth > ActualHeight) {
                            angle = 0.0;
                            bm.Destroy();
                            bm = null;
                            goto imgretry;
                        }
                        // crop the end
                        ImageSurface bm2 = new ImageSurface(Format.Argb32,bm.Width,(int)(ActualHeight*0.95));
                        Context g2 = new Context(bm2);
                        g2.SetSource(bm,0,ActualHeight-bm.Height);
                        g2.Paint();
                        ((IDisposable)g2).Dispose();
                        bm.Destroy();
                        bm = bm2;
                    }
                }
                else {
                    if(bm.Width > ActualWidth) {
                        if(ActualHeight > ActualWidth) {
                            angle = 90.0;
                            bm.Destroy();
                            bm = null;
                            goto imgretry;
                        }
                        // crop the end
                        ImageSurface bm2 = new ImageSurface(Format.Argb32,(int)(ActualWidth*0.95),bm.Height);
                        Context g2 = new Context(bm2);
                        g2.SetSource(bm,0,0);
                        g2.Paint();
                        ((IDisposable)g2).Dispose();
                        bm.Destroy();
                        bm = bm2;
                    }
                }
                //WordBitmap bm2 = new WordBitmap(bm);
                Dictionary<Point, List<Point>> lst = CreateCollisionList(bm);
                bool collided = true;
                do
                {
                    Point spiralPoint = GetSpiralPoint(position);
                    int offsetX = (bm.Width / 2);
                    int offsetY = (bm.Height / 2);
                    var testPoint = new Point((int)(spiralPoint.X + centre.X - offsetX), (int)(spiralPoint.Y + centre.Y - offsetY));
                    if (position > (2 * Math.PI) * 580)
                    {
                        //bm2.Dispose();
                        if (++currentPoint >= points.Length)
                            goto done;
              					goto again;
                    }
                    int cols = CountCollisions(testPoint, lst);
                    if (cols == 0)
                    {
                    tryagain:
                        double oldY = testPoint.Y;
                        if (Math.Abs(testPoint.X + offsetX - centre.X) > 10)
                        {
                            if (testPoint.X + offsetX < centre.X)
                            {
                                do
                                {
                                    testPoint.X += 2;
                                } while (testPoint.X + offsetX < centre.X && CountCollisions(testPoint, lst) == 0);
                                testPoint.X -= 2;
                            }
                            else
                            {
                                do
                                {
                                    testPoint.X -= 2;
                                } while (testPoint.X + offsetX > centre.X && CountCollisions(testPoint, lst) == 0);
                                testPoint.X += 2;
                            }
                        }
                        if (Math.Abs(testPoint.Y + offsetY - centre.Y) > 10)
                        {
                            if (testPoint.Y + offsetY < centre.Y)
                            {
                                do
                                {
                                    testPoint.Y += 2;
                                } while (testPoint.Y + offsetY < centre.Y && CountCollisions(testPoint, lst) == 0);
                                testPoint.Y -= 2;
                            }
                            else
                            {
                                do
                                {
                                    testPoint.Y -= 2;
                                } while (testPoint.Y + offsetY > centre.Y && CountCollisions(testPoint, lst) == 0);
                                testPoint.Y += 2;
                            }
                            if (testPoint.Y != oldY)
                                goto tryagain;
                        }

                        collided = false;
                        CopyBits(testPoint, bm, lst, Entries.IndexOf(e));
                        Console.Error.WriteLine("id: {0}, word: {1}, score: {7}, fontsize: {8}," +
                            "x: {2}, y: {3}, w: {4}, h: {5}, angle: {6}",id,e.Word,testPoint.X,testPoint.Y,
                                             bm.Width,bm.Height,angle,e.SizeValue,fontsize);
                        id++;
                        bm.Destroy();
                        if(svg != null) {
                            svg.SetFontSize(fontsize);
                            TextExtents te2 = svg.TextExtents(e.Word);
                            svg.Save();

                            if(angle == 90.0) {
                                svg.MoveTo(testPoint.X-te2.YBearing,testPoint.Y+te2.Width+te2.XBearing);
                                svg.Rotate(-0.5*Math.PI);
                            }
                            else {
                                svg.MoveTo(testPoint.X-te2.XBearing,testPoint.Y-te2.YBearing);
                            }
                            svg.Color = e.Color;
                            svg.ShowText(e.Word);
                            svg.Restore();
                        }
                        if(pdf != null) {
                            pdf.SetFontSize(fontsize);
                            TextExtents te2 = pdf.TextExtents(e.Word);
                            pdf.Save();

                            if(angle == 90.0) {
                                pdf.MoveTo(testPoint.X-te2.YBearing,testPoint.Y+te2.Width+te2.XBearing);
                                pdf.Rotate(-0.5*Math.PI);
                            }
                            else {
                                pdf.MoveTo(testPoint.X-te2.XBearing,testPoint.Y-te2.YBearing);
                            }
                            pdf.Color = e.Color;
                            pdf.ShowText(e.Word);
                            pdf.Restore();
                        }
                    }
                    else
                    {
                        if (cols <= 2)
                        {
                            position += (2 * Math.PI) / 100;
                        }
                        else

                            position += (2 * Math.PI) / 40;
                    }
                } while (collided);
            }
            done:
            ((IDisposable)g).Dispose();
            if(svgfn != null) ((IDisposable)svg).Dispose();
            if(pdffn != null) ((IDisposable)pdf).Dispose();
            Console.Error.WriteLine("# {0} words placed",id);
        }
示例#11
0
        protected override void DrawContents(Gdk.Drawable d)
        {
            Gdk.GC        gc = new Gdk.GC(d);
            Cairo.Context g  = Gdk.CairoHelper.Create(d);

            g.SelectFontFace("Lucida Console", FontSlant.Normal, FontWeight.Bold);
            g.SetFontSize(24);

            TextExtents te;


            Cairo.Color greenish = new Color(.3, .8, .8);
            Cairo.Color gray     = new Color(.4, .4, .4);
            Cairo.Color white    = new Color(1, 1, 1);

            string lvl, hp, hpm, mp, mpm, s;


            #region Character Status

            d.DrawPixbuf(gc, Graphics.GetProfile(Selected.Name), 0, 0,
                         X + xpic, Y + ypic,
                         Graphics.PROFILE_WIDTH, Graphics.PROFILE_HEIGHT,
                         Gdk.RgbDither.None, 0, 0);

            g.Color = new Color(.3, .8, .8);
            g.MoveTo(X + x3, Y + ya);
            g.ShowText("LV");
            g.MoveTo(X + x3, Y + yb);
            g.ShowText("HP");
            g.MoveTo(X + x3, Y + yc);
            g.ShowText("MP");
            g.Color = new Color(1, 1, 1);

            Graphics.ShadowedText(g, Selected.Name, X + x3, Y + y);

            lvl = Selected.Level.ToString();
            hp  = Selected.HP.ToString() + "/";
            hpm = Selected.MaxHP.ToString();
            mp  = Selected.MP.ToString() + "/";
            mpm = Selected.MaxMP.ToString();

            te = g.TextExtents(lvl);
            Graphics.ShadowedText(g, lvl, X + x4 - te.Width, Y + ya);

            te = g.TextExtents(hp);
            Graphics.ShadowedText(g, hp, X + x5 - te.Width, Y + yb);

            te = g.TextExtents(hpm);
            Graphics.ShadowedText(g, hpm, X + x6 - te.Width, Y + yb);

            te = g.TextExtents(mp);
            Graphics.ShadowedText(g, mp, X + x5 - te.Width, Y + yc);

            te = g.TextExtents(mpm);
            Graphics.ShadowedText(g, mpm, X + x6 - te.Width, Y + yc);

            #endregion Status



            Graphics.ShadowedText(g, greenish, "Attack", X + x0, Y + ym);
            Graphics.ShadowedText(g, greenish, "Halve", X + x0, Y + yn);
            Graphics.ShadowedText(g, greenish, "Void", X + x0, Y + yo);
            Graphics.ShadowedText(g, greenish, "Absorb", X + x0, Y + yp);

            g.SetFontSize(16);

            double x = (double)x1;
            double r = (double)(ym + ys);
            foreach (Element e in Enum.GetValues(typeof(Element)))
            {
                if (x > W - stop)
                {
                    x = x1;
                    r = r + ys;
                }

                s  = e.ToString() + " ";
                te = g.TextExtents(s);
                if (Selected.Halves(e))
                {
                    Graphics.ShadowedText(g, white, e.ToString(), X + x, Y + r);
                }
                else
                {
                    Graphics.ShadowedText(g, gray, e.ToString(), X + x, Y + r);
                }
                x += te.XAdvance;
            }

            x = (double)x1;
            r = (double)(yn + ys);
            foreach (Element e in Enum.GetValues(typeof(Element)))
            {
                if (x > W - stop)
                {
                    x = x1;
                    r = r + ys;
                }

                s  = e.ToString() + " ";
                te = g.TextExtents(s);
                if (Selected.Halves(e))
                {
                    Graphics.ShadowedText(g, white, e.ToString(), X + x, Y + r);
                }
                else
                {
                    Graphics.ShadowedText(g, gray, e.ToString(), X + x, Y + r);
                }
                x += te.XAdvance;
            }

            x = (double)x1;
            r = (double)(yo + ys);
            foreach (Element e in Enum.GetValues(typeof(Element)))
            {
                if (x > W - stop)
                {
                    x = x1;
                    r = r + ys;
                }

                s  = e.ToString() + " ";
                te = g.TextExtents(s);
                if (Selected.Voids(e))
                {
                    Graphics.ShadowedText(g, white, e.ToString(), X + x, Y + r);
                }
                else
                {
                    Graphics.ShadowedText(g, gray, e.ToString(), X + x, Y + r);
                }
                x += te.XAdvance;
            }

            x = (double)x1;
            r = (double)(yp + ys);
            foreach (Element e in Enum.GetValues(typeof(Element)))
            {
                if (x > W - stop)
                {
                    x = x1;
                    r = r + ys;
                }

                s  = e.ToString() + " ";
                te = g.TextExtents(s);
                if (Selected.Absorbs(e))
                {
                    Graphics.ShadowedText(g, white, e.ToString(), X + x, Y + r);
                }
                else
                {
                    Graphics.ShadowedText(g, gray, e.ToString(), X + x, Y + r);
                }
                x += te.XAdvance;
            }



            ((IDisposable)g.Target).Dispose();
            ((IDisposable)g).Dispose();
        }
示例#12
0
        protected override void DrawContents(Gdk.Drawable d)
        {
            Gdk.GC        gc = new Gdk.GC(d);
            Cairo.Context g  = Gdk.CairoHelper.Create(d);

            g.SelectFontFace("Lucida Console", FontSlant.Normal, FontWeight.Bold);
            g.SetFontSize(24);



            TextExtents te;

            string lvl, hp, hpm, mp, mpm, exp, next, llvl;


            #region Top Row

            d.DrawPixbuf(gc, Graphics.GetProfile(Selected.Name), 0, 0,
                         X + xpic, Y + ypic,
                         Graphics.PROFILE_WIDTH, Graphics.PROFILE_HEIGHT,
                         Gdk.RgbDither.None, 0, 0);

            g.Color = new Color(.3, .8, .8);
            g.MoveTo(X + x3, Y + ya);
            g.ShowText("LV");
            g.MoveTo(X + x3, Y + yb);
            g.ShowText("HP");
            g.MoveTo(X + x3, Y + yc);
            g.ShowText("MP");
            g.Color = new Color(1, 1, 1);

            Graphics.ShadowedText(g, Selected.Name, X + x3, Y + y);

            lvl  = Selected.Level.ToString();
            hp   = Selected.HP.ToString() + "/";
            hpm  = Selected.MaxHP.ToString();
            mp   = Selected.MP.ToString() + "/";
            mpm  = Selected.MaxMP.ToString();
            exp  = Selected.Exp.ToString();
            next = Selected.ToNextLevel.ToString();
            llvl = Selected.LimitLevel.ToString();

            te = g.TextExtents(lvl);
            Graphics.ShadowedText(g, lvl, X + x4 - te.Width, Y + ya);

            te = g.TextExtents(hp);
            Graphics.ShadowedText(g, hp, X + x5 - te.Width, Y + yb);

            te = g.TextExtents(hpm);
            Graphics.ShadowedText(g, hpm, X + x6 - te.Width, Y + yb);

            te = g.TextExtents(mp);
            Graphics.ShadowedText(g, mp, X + x5 - te.Width, Y + yc);

            te = g.TextExtents(mpm);
            Graphics.ShadowedText(g, mpm, X + x6 - te.Width, Y + yc);

            Graphics.ShadowedText(g, "Exp:", X + x8, Y + ya);
            Graphics.ShadowedText(g, "Next lvl:", X + x8, Y + yb);
            Graphics.ShadowedText(g, "Limit lvl:", X + x8, Y + yc);

            te = g.TextExtents(exp);
            Graphics.ShadowedText(g, exp, X + x12 - te.Width, Y + ya);
            te = g.TextExtents(next);
            Graphics.ShadowedText(g, next, X + x12 - te.Width, Y + yb);
            te = g.TextExtents(llvl);
            Graphics.ShadowedText(g, llvl, X + x11 - te.Width, Y + yc);

            #endregion Top


            #region Left

            string str, vit, dex, mag, spi, lck;
            string atk, atkp, def, defp, mat, mdf, mdfp;

            str = Selected.Strength.ToString();
            vit = Selected.Vitality.ToString();
            dex = Selected.Dexterity.ToString();
            mag = Selected.Magic.ToString();
            spi = Selected.Spirit.ToString();
            lck = Selected.Luck.ToString();

            atk  = Ally.Attack(Selected).ToString();
            atkp = Ally.AttackPercent(Selected).ToString();
            def  = Ally.Defense(Selected).ToString();
            defp = Ally.DefensePercent(Selected).ToString();
            mat  = Ally.MagicAttack(Selected).ToString();
            mdf  = Ally.MagicDefense(Selected).ToString();
            mdfp = Ally.MagicDefensePercent(Selected).ToString();

            Cairo.Color greenish = new Color(.3, .8, .8);

            Graphics.ShadowedText(g, greenish, "Strength", X + x0, Y + yq + (line * 0));
            Graphics.ShadowedText(g, greenish, "Vitality", X + x0, Y + yq + (line * 1));
            Graphics.ShadowedText(g, greenish, "Dexterity", X + x0, Y + yq + (line * 2));
            Graphics.ShadowedText(g, greenish, "Magic", X + x0, Y + yq + (line * 3));
            Graphics.ShadowedText(g, greenish, "Spirit", X + x0, Y + yq + (line * 4));
            Graphics.ShadowedText(g, greenish, "Luck", X + x0, Y + yq + (line * 5));

            Graphics.ShadowedText(g, greenish, "Attack", X + x0, Y + yr + (line * 0));
            Graphics.ShadowedText(g, greenish, "Attack %", X + x0, Y + yr + (line * 1));
            Graphics.ShadowedText(g, greenish, "Defense", X + x0, Y + yr + (line * 2));
            Graphics.ShadowedText(g, greenish, "Defense %", X + x0, Y + yr + (line * 3));
            Graphics.ShadowedText(g, greenish, "Magic", X + x0, Y + yr + (line * 4));
            Graphics.ShadowedText(g, greenish, "Magic def", X + x0, Y + yr + (line * 5));
            Graphics.ShadowedText(g, greenish, "Magic def %", X + x0, Y + yr + (line * 6));

            te = g.TextExtents(str);
            Graphics.ShadowedText(g, str, X + x1 - te.Width, Y + yq + (line * 0));
            te = g.TextExtents(vit);
            Graphics.ShadowedText(g, vit, X + x1 - te.Width, Y + yq + (line * 1));
            te = g.TextExtents(dex);
            Graphics.ShadowedText(g, dex, X + x1 - te.Width, Y + yq + (line * 2));
            te = g.TextExtents(mag);
            Graphics.ShadowedText(g, mag, X + x1 - te.Width, Y + yq + (line * 3));
            te = g.TextExtents(spi);
            Graphics.ShadowedText(g, spi, X + x1 - te.Width, Y + yq + (line * 4));
            te = g.TextExtents(lck);
            Graphics.ShadowedText(g, lck, X + x1 - te.Width, Y + yq + (line * 5));

            te = g.TextExtents(atk);
            Graphics.ShadowedText(g, atk, X + x1 - te.Width, Y + yr + (line * 0));
            te = g.TextExtents(atkp);
            Graphics.ShadowedText(g, atkp, X + x1 - te.Width, Y + yr + (line * 1));
            te = g.TextExtents(def);
            Graphics.ShadowedText(g, def, X + x1 - te.Width, Y + yr + (line * 2));
            te = g.TextExtents(defp);
            Graphics.ShadowedText(g, defp, X + x1 - te.Width, Y + yr + (line * 3));
            te = g.TextExtents(mat);
            Graphics.ShadowedText(g, mat, X + x1 - te.Width, Y + yr + (line * 4));
            te = g.TextExtents(mdf);
            Graphics.ShadowedText(g, mdf, X + x1 - te.Width, Y + yr + (line * 5));
            te = g.TextExtents(mdfp);
            Graphics.ShadowedText(g, mdfp, X + x1 - te.Width, Y + yr + (line * 6));

            #endregion Left


            #region Right


            g.Color = new Color(.1, .1, .2);
            g.Rectangle(x9, yi, 8 * xs, yj - yi);
            g.Fill();
            g.Rectangle(x9, yk, 8 * xs, yl - yk);
            g.Fill();

            Cairo.Color gray1 = new Color(.2, .2, .2);
            Cairo.Color gray2 = new Color(.7, .7, .8);

            int links, slots;

            slots = Selected.Weapon.Slots.Length;
            links = Selected.Weapon.Links;


            for (int j = 0; j < links; j++)
            {
                Graphics.RenderLine(g, gray2, 3,
                                    X + x9 + (xs / 2) + (j * 2 * xs), Y + yi - ys - zs,
                                    X + x9 + (xs / 2) + ((j * 2 + 1) * xs), Y + yi - ys - zs);
                Graphics.RenderLine(g, gray2, 3,
                                    X + x9 + (xs / 2) + (j * 2 * xs), Y + yi - ys,
                                    X + x9 + (xs / 2) + ((j * 2 + 1) * xs), Y + yi - ys);
                Graphics.RenderLine(g, gray2, 3,
                                    X + x9 + (xs / 2) + (j * 2 * xs), Y + yi - ys + zs,
                                    X + x9 + (xs / 2) + ((j * 2 + 1) * xs), Y + yi - ys + zs);
            }
            for (int i = 0; i < slots; i++)
            {
                Graphics.RenderCircle(g, gray2, 14,
                                      X + x9 + (i * xs) + (xs / 2), Y + yi - ys);
                if (Selected.Weapon.Slots[i] == null)
                {
                    Graphics.RenderCircle(g, gray1, 10,
                                          X + x9 + (i * xs) + (xs / 2), Y + yi - ys);
                }
                else
                {
                    Graphics.RenderCircle(g, Selected.Weapon.Slots[i].Color, 10,
                                          X + x9 + (i * xs) + (xs / 2), Y + yi - ys);
                }
            }

            slots = Selected.Armor.Slots.Length;
            links = Selected.Armor.Links;

            for (int j = 0; j < links; j++)
            {
                Graphics.RenderLine(g, gray2, 3,
                                    X + x9 + (xs / 2) + (j * 2 * xs), Y + yk - ys - zs,
                                    X + x9 + (xs / 2) + ((j * 2 + 1) * xs), Y + yk - ys - zs);
                Graphics.RenderLine(g, gray2, 3,
                                    X + x9 + (xs / 2) + (j * 2 * xs), Y + yk - ys,
                                    X + x9 + (xs / 2) + ((j * 2 + 1) * xs), Y + yk - ys);
                Graphics.RenderLine(g, gray2, 3,
                                    X + x9 + (xs / 2) + (j * 2 * xs), Y + yk - ys + zs,
                                    X + x9 + (xs / 2) + ((j * 2 + 1) * xs), Y + yk - ys + zs);
            }
            for (int i = 0; i < slots; i++)
            {
                Graphics.RenderCircle(g, gray2, 14,
                                      X + x9 + (i * xs) + (xs / 2), Y + yk - ys);

                if (Selected.Armor.Slots[i] == null)
                {
                    Graphics.RenderCircle(g, gray1, 10,
                                          X + x9 + (i * xs) + (xs / 2), Y + yk - ys);
                }
                else
                {
                    Graphics.RenderCircle(g, Selected.Armor.Slots[i].Color, 10,
                                          X + x9 + (i * xs) + (xs / 2), Y + yk - ys);
                }
            }


            g.Color = new Color(.3, .8, .8);
            g.MoveTo(X + x7, Y + yh);
            g.ShowText("Wpn.");
            g.MoveTo(X + x7, Y + yj);
            g.ShowText("Arm.");
            g.MoveTo(X + x7, Y + yl);
            g.ShowText("Acc.");
            g.Color = new Color(1, 1, 1);

            Graphics.ShadowedText(g, Selected.Weapon.Name, X + x8, Y + yh);
            Graphics.ShadowedText(g, Selected.Armor.Name, X + x8, Y + yj);
            Graphics.ShadowedText(g, Selected.Accessory.Name, X + x8, Y + yl);

            #endregion Right


            ((IDisposable)g.Target).Dispose();
            ((IDisposable)g).Dispose();
        }
示例#13
0
 protected void DrawVerticalReferenceLines(Context g, Gdk.Rectangle area, float xSize, float xTranslation)
 {
     for (int i = 0; i <= NumbersX; i++) {
         float actualLoc = i * (area.Width - numberSpacingXTotal) / NumbersX + NumberSpacingXLeft;
         String text = (xTranslation+i*xSize/NumbersX).ToString ("0.0");
         g.MoveTo (actualLoc - g.TextExtents (text).Width / 2, area.Height - 5);
         g.ShowText (text);
         g.MoveTo (actualLoc, area.Height - NumberSpacingYDown);
         g.LineTo (actualLoc, NumberSpacingYUp);
         g.Stroke ();
     }
 }
示例#14
0
        protected virtual void RenderCell(Context context, Gdk.Rectangle pix_rect, bool isSelected)
        {
            // Draw Icon if needed
            if (Icon != null)
            {
                context.Save();
                Gdk.CairoHelper.SetSourcePixbuf(context, Icon, pix_rect.Left, pix_rect.Y);

                context.Paint();
                context.Restore();

                m_TextXOffset = Icon.Width;
            }
            else if (AnimatedIcon != null)
            {
                context.Save();

                Gdk.CairoHelper.SetSourcePixbuf(context, AnimatedIcon.Image, pix_rect.Left, pix_rect.Y);

                context.Paint();
                context.Restore();

                m_TextXOffset = AnimatedIcon.Image.Width;
            }

            // Render Text
            if (Text != null && Text.Length > 0)
            {
                Color colour = White;

                //if (!isSelected && !IsHeading)
                //    colour = Black;

                string text = Text;

                if (TruncateText)
                {
                    TextExtents te = context.TextExtents(text);
                    int subIdx = Text.Length;

                    while (te.Width > pix_rect.Width - 16 - m_TextXOffset + 2)
                    {
                        if (subIdx <= 0) break;

                        text = string.Format("{0}...", text.Substring(0, --subIdx).TrimEnd());
                        te = context.TextExtents(text);
                    }
                }

                RenderText(context, text, pix_rect.X + m_TextXOffset + 2, pix_rect.Y + 2, colour);
            }
        }
示例#15
0
        private void DrawWeatherRegion(Context g, RegionDto dto)
        {
            string trendIcon = string.Empty;
            g.SetSourceRGB(1, 1, 1);

            double halfWidth = dto.Width / 2.0;

            TextExtents extDay;

            if (string.IsNullOrEmpty(dto.WeekDay))
            {
                extDay = g.TextExtents("test");
            }
            else
            {
                extDay = g.TextExtents(dto.WeekDay);
            }

            var t_x = dto.X + halfWidth - (extDay.Width / 2);
            var t_y = dto.Y + extDay.Height + padding;

            this.DrawTextAt(g, t_x, t_y, dto.WeekDay);

            //drawe day temp
            var extMax = g.TextExtents(dto.Max);
            var extMin = g.TextExtents(dto.Min);

            t_y = t_y + extDay.Height + padding + 2;

            t_x = dto.X + halfWidth - (extMax.Width / 2);
            this.DrawTextAt(g, t_x, t_y, dto.Max);

            if (dto.Trend.HasValue)
            {
                if (dto.Trend.Value > 0)
                {
                    trendIcon = "up.png";
                }
                else
                    if (dto.Trend < 0)
                {
                    trendIcon = "dwn.png";
                }
                if (!string.IsNullOrEmpty(trendIcon))
                {
                    string pathToImg = global::System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, string.Format("Icons/{0}", trendIcon));
                    ImageSurface image_surface = new ImageSurface(pathToImg);
                    this.DrawSurfaceAt(g, image_surface, t_x - extMax.Width / 2, t_y - extMax.Height);
                }
            }

            t_x = dto.X + halfWidth - imageWidth / 2;
            DrawWeatherCode(g, dto.WeatherCode, t_x, t_y);

            g.SetSourceRGB(0.7, 0.7, 0.7);
            t_x = dto.X + halfWidth - (extMin.Width / 2);
            t_y += 68 + extMax.Height / 2;
            this.DrawTextAt(g, t_x, t_y, dto.Min);
        }
示例#16
0
        protected TextExtents RenderText(Context context, string text, double x, double y, Color colour)
        {
            TextExtents extents = context.TextExtents(text);

            context.Save();

            context.Color = colour;

            context.MoveTo(x, y + extents.Height); // we add the height as it seems to be top left, not bottom left
            context.ShowText(text);

            context.Restore();

            return extents;
        }
示例#17
0
        private void DrawBoard(Context cr, Position pos)
        {
            Console.WriteLine("ShogibanSVG.DrawBoard");
            #region board border
            //Top
            cr.Rectangle(0, 0, Game.BOARD_SIZE * FIELD_SIZE + 2*FIELD_NAMING_SIZE, FIELD_NAMING_SIZE);
            //Left
            cr.Rectangle(0, 0, FIELD_NAMING_SIZE, Game.BOARD_SIZE * FIELD_SIZE + 2*FIELD_NAMING_SIZE);
            //Bottom
            cr.Rectangle(0, Game.BOARD_SIZE * FIELD_SIZE + FIELD_NAMING_SIZE, Game.BOARD_SIZE * FIELD_SIZE + 2*FIELD_NAMING_SIZE, FIELD_NAMING_SIZE);
            //Right
            cr.Rectangle(9*FIELD_SIZE + FIELD_NAMING_SIZE, 0, FIELD_NAMING_SIZE, Game.BOARD_SIZE * FIELD_SIZE + 2*FIELD_NAMING_SIZE);
            cr.Color = BorderColor;
            cr.Fill();
            #endregion

            #region field namings
            cr.SelectFontFace("Sans", FontSlant.Normal, FontWeight.Normal);
            cr.SetFontSize(FIELD_NAMING_SIZE * 0.9);
            cr.Color = new Color(0, 0, 0);

            for (int i = 0; i < VerticalNamings.Length; i++)
            {
                TextExtents extents = cr.TextExtents(VerticalNamings[i].ToString());
                double x = (FIELD_NAMING_SIZE/2) - (extents.Width/2 + extents.XBearing);
                double y = (FIELD_NAMING_SIZE + i*FIELD_SIZE + FIELD_SIZE/2) - (extents.Height/2 + extents.YBearing);

                cr.MoveTo(x, y);
                cr.ShowText(VerticalNamings[i].ToString());
                cr.MoveTo(x + 9*FIELD_SIZE + FIELD_NAMING_SIZE, y);
                cr.ShowText(VerticalNamings[i].ToString());
            }
            for (int i = 0; i < HorizontalNamings.Length; i++)
            {
                TextExtents extents = cr.TextExtents(HorizontalNamings[i].ToString());
                double x = (FIELD_NAMING_SIZE + i*FIELD_SIZE + FIELD_SIZE/2) - (extents.Width/2 + extents.XBearing);
                double y = (FIELD_NAMING_SIZE/2) - (extents.Height/2 + extents.YBearing);

                cr.MoveTo(x, y);
                cr.ShowText(HorizontalNamings[Game.BOARD_SIZE-i-1].ToString());
                cr.MoveTo(x, y + 9*FIELD_SIZE + FIELD_NAMING_SIZE);
                cr.ShowText(HorizontalNamings[Game.BOARD_SIZE-i-1].ToString());
            }
            #endregion

            #region board playfield
            //background
            cr.Translate(FIELD_NAMING_SIZE, FIELD_NAMING_SIZE);
            cr.Rectangle(0, 0, Game.BOARD_SIZE * FIELD_SIZE, Game.BOARD_SIZE * FIELD_SIZE);
            cr.Color = BoardColor;
            cr.Fill();

            if (gi != null)
            {
                //highlight selected piece field
                if (gi.localPlayerMoveState != LocalPlayerMoveState.Wait
                    && gi.localPlayerMoveState != LocalPlayerMoveState.PickSource
                    && CurMoveNr < 0)
                {
                    if (gi.GetLocalPlayerMove().OnHandPiece == PieceType.NONE)
                    {
                        cr.Rectangle((Game.BOARD_SIZE - gi.GetLocalPlayerMove().From.x - 1) * FIELD_SIZE, gi.GetLocalPlayerMove().From.y * FIELD_SIZE, FIELD_SIZE, FIELD_SIZE);
                        cr.Color = SelectedFieldColor;
                        cr.Fill();
                    }
                }

                //highlight last move
                if (gi.Moves.Count > 0 && CurMoveNr != 0)
                {
                    Move move;
                    if (CurMoveNr < 0)
                        move = gi.Moves[gi.Moves.Count-1].move;
                    else
                        move = gi.Moves[CurMoveNr - 1].move;

                    if (move.OnHandPiece == PieceType.NONE)
                    {
                        cr.Rectangle((Game.BOARD_SIZE - move.From.x - 1) * FIELD_SIZE, move.From.y * FIELD_SIZE, FIELD_SIZE, FIELD_SIZE);
                    }
                    cr.Rectangle((Game.BOARD_SIZE - move.To.x - 1) * FIELD_SIZE, move.To.y * FIELD_SIZE, FIELD_SIZE, FIELD_SIZE);
                    cr.Color = LastMoveFieldColor;
                    cr.Fill();
                }

                //highlight possible moves
                if (gi.localPlayerMoveState == LocalPlayerMoveState.PickDestination && CurMoveNr < 0)
                {
                    ValidMoves Moves;
                    Move LocalPlayerMove = gi.GetLocalPlayerMove();
                    if (LocalPlayerMove.OnHandPiece == PieceType.NONE)
                    {
                        Moves = pos.GetValidBoardMoves(LocalPlayerMove.From);
                    }
                    else
                    {
                        Moves = pos.GetValidOnHandMoves(LocalPlayerMove.OnHandPiece, gi.CurPlayer == gi.BlackPlayer);
                    }

                    foreach (BoardField Field in Moves)
                    {
                        cr.Rectangle((Game.BOARD_SIZE - Field.x - 1) * FIELD_SIZE, Field.y * FIELD_SIZE, FIELD_SIZE, FIELD_SIZE);
                        cr.Color = PossibleMoveColor;
                        cr.Fill();
                    }
                }
            }

            //dividing lines
            for (int i = 0; i <= Game.BOARD_SIZE; i++)
            {
                cr.MoveTo(0, i * FIELD_SIZE);
                cr.LineTo(Game.BOARD_SIZE * FIELD_SIZE, i * FIELD_SIZE);
            }
            for (int i = 0; i <= Game.BOARD_SIZE; i++)
            {
                cr.MoveTo(i * FIELD_SIZE, 0);
                cr.LineTo(i * FIELD_SIZE, Game.BOARD_SIZE * FIELD_SIZE);
            }
            cr.Color = new Color(0, 0, 0);
            cr.LineWidth = 2.5;
            cr.LineCap = LineCap.Round;
            cr.Stroke();
            #endregion

            DrawPieces(cr, pos);

            //draw promotion choice area
            if (gi != null && gi.localPlayerMoveState == LocalPlayerMoveState.PickPromotion && CurMoveNr < 0)
            {
                double PromotionChoiceAreaStartX = (Game.BOARD_SIZE - gi.GetLocalPlayerMove().To.x - 1) * FIELD_SIZE - FIELD_SIZE / 2;
                double PromotionChoiceAreaStartY = gi.GetLocalPlayerMove().To.y * FIELD_SIZE;

                cr.Save();
                //draw boarder
                cr.Translate(PromotionChoiceAreaStartX - PADDING,
                    PromotionChoiceAreaStartY - PADDING);
                cr.Rectangle(0, 0, 2 * FIELD_SIZE + 2 * PADDING, FIELD_SIZE + 2 * PADDING);
                cr.Color = new Color(0, 0, 0);
                cr.Fill();

                cr.Translate(PADDING, PADDING);
                cr.Rectangle(0, 0, 2 * FIELD_SIZE, FIELD_SIZE);
                cr.Color = BoardColor;
                cr.Fill();

                Move LocalPlayerMove = gi.GetLocalPlayerMove();
                FieldInfo From = pos.Board[LocalPlayerMove.From.x, LocalPlayerMove.From.y];
                DrawPiece(cr, From.Piece, From.Direction, 0, 0);
                DrawPiece(cr, From.Piece.GetPromotedPiece(), From.Direction, FIELD_SIZE, 0);

                cr.Restore();
            }
        }
 private void PaintEdges(Context ctx, int w, int h, IEnumerable<NotatedEdge> edges)
 {
     PointD pc, pd;
     foreach(NotatedEdge edge in edges) {
         PointD pa = new PointD(w*edge.Item1.X, h*edge.Item1.Y);
         PointD pb = new PointD(w*edge.Item2.X, h*edge.Item2.Y);
         Utils.CutTowardsCenter(pa, pb, AlgorithmRadius, out pc, out pd);
         double dxr = pc.X-pd.X;
         double dyr = pc.Y-pd.Y;
         double r = Math.Sqrt(dxr*dxr+dyr*dyr);
         ctx.MoveTo(pc);
         ctx.LineTo(pd);
         ctx.Stroke();
         ctx.Save();
         ctx.Translate(pc.X, pc.Y);
         ctx.Rotate(Math.Atan2(pb.Y-pa.Y, pb.X-pa.X));
         double v = 0.0d;//double v = tm/e.Delay;
         foreach(EdgeNotation msg in edge.Item3) {
             TextExtents te = ctx.TextExtents(msg.Item2);
             ctx.MoveTo((msg.Item1+v)*(r-te.XAdvance), te.Height+2.0d);
             ctx.ShowText(msg.Item2);
         }
         ctx.Restore();
         ctx.Save();
         ctx.Translate(pd.X, pd.Y);
         ctx.Rotate(Math.Atan2(pa.Y-pb.Y, pa.X-pb.X));
         foreach(EdgeNotation msg in edge.Item4) {
             TextExtents te = ctx.TextExtents(msg.Item2);
             ctx.MoveTo((msg.Item1+v)*(r-te.XAdvance), te.Height+2.0d);
             ctx.ShowText(msg.Item2);
         }
         ctx.Restore();
     }
 }
示例#19
0
        private void DrawOnHandPieces(Context cr, Position pos, bool BlackPlayer)
        {
            cr.Save();
            cr.Rectangle(0, 0, ON_HAND_AREA_WIDTH, 9 * FIELD_SIZE + 2 * FIELD_NAMING_SIZE);
            cr.Color = BorderColor;
            cr.FillPreserve();
            cr.Color = new Color(0.6, 0.5, 0.55);
            cr.LineWidth = 3;
            cr.Stroke();

            if (BlackPlayer)
            {
                cr.Translate(0, 8 * FIELD_SIZE + 2 * FIELD_NAMING_SIZE);
            }

            for (int i = 0; i < (int)PieceType.PIECE_TYPES_COUNT; i++)
            {
                int player_nr = BlackPlayer ? 0 : 1;
                if (pos.OnHandPieces[player_nr, i] != 0)
                {
                    //highlight selected piece
                    if (gi != null && gi.localPlayerMoveState != LocalPlayerMoveState.Wait
                        && gi.localPlayerMoveState != LocalPlayerMoveState.PickSource
                        && gi.GetLocalPlayerMove().OnHandPiece != PieceType.NONE
                        && gi.GetLocalPlayerMove().OnHandPiece == (PieceType)i
                        && !((gi.CurPlayer == gi.BlackPlayer) ^ BlackPlayer))
                    {
                        cr.Rectangle(0, 0, FIELD_SIZE, FIELD_SIZE);
                        cr.Color = new Color(0.8, 0.835, 0.4);
                        cr.Fill();
                    }

                    //draw piece
                    cr.Save();
                    if (!BlackPlayer)
                    {
                        cr.Rotate(180 * Math.PI / 180);
                        cr.Translate(-FIELD_SIZE, -FIELD_SIZE);
                    }
                    cr.Scale(FIELD_SIZE / PieceGraphics[i].Dimensions.Width, FIELD_SIZE / PieceGraphics[i].Dimensions.Width);
                    PieceGraphics[i].RenderCairo(cr);
                    cr.Restore();

                    //draw amount
                    cr.SelectFontFace("Sans", FontSlant.Normal, FontWeight.Normal);
                    cr.SetFontSize(FIELD_SIZE / 3 * 0.9);
                    cr.Color = new Color(0, 0, 0);

                    String amount_str = "x " + pos.OnHandPieces[player_nr, i].ToString();
                    TextExtents extents = cr.TextExtents(amount_str);
                    double x = (FIELD_SIZE);
                    // - (extents.Width/2 + extents.XBearing);
                    double y = (FIELD_SIZE / 2) - (extents.Height / 2 + extents.YBearing);

                    cr.MoveTo(x, y);
                    cr.ShowText(amount_str);

                    double offset = BlackPlayer ? -FIELD_SIZE - PADDING : FIELD_SIZE + PADDING;
                    cr.Translate(0, offset);
                }
            }
            cr.Restore();
        }
示例#20
0
		public void text_align_center(Context cr, int width, int height)
		{
			Normalize (cr, width, height);

			cr.SelectFontFace("Sans", FontSlant.Normal, FontWeight.Normal);
			cr.SetFontSize(0.2);
			TextExtents extents = cr.TextExtents("cairo");
			double x = 0.5 -((extents.Width/2.0) + extents.XBearing);
			double y = 0.5 -((extents.Height/2.0) + extents.YBearing);

			cr.MoveTo(x, y);
			cr.ShowText("cairo");

			// draw helping lines
			cr.Color = new Color (1, 0.2, 0.2, 0.6);
			cr.Arc(x, y, 0.05, 0, 2*Math.PI);
			cr.Fill();
			cr.MoveTo(0.5, 0);
			cr.RelLineTo(0, 1);
			cr.MoveTo(0, 0.5);
			cr.RelLineTo(1, 0);
			cr.Stroke();
		}
示例#21
0
        private Pixbuf PixbufText(string text, int size, bool transparent)
        {
            int x=0, y=36;

            surface = new Cairo.ImageSurface(Cairo.Format.Argb32,  800, 600);
            cr = new Cairo.Context(surface);

            if (!transparent) {
                cr.SetSourceRGBA (0.0, 0.0, 0.0, 1.0);
                cr.Rectangle (new Cairo.Rectangle (0, 0, 800, 600));
                cr.Fill ();
            }

            //cr.MoveTo(x, y);
            string font = "sans";
            if (Util.IsWindows ()) {
                font = "MS Gothic";
            }
            if (Util.IsLinux ()) {
                font = "TakaoGothic";
            }
            if (Util.IsMac ()) {
                font = "Hiragino Kaku Gothic ProN";
            }

            cr.SelectFontFace(font, Cairo.FontSlant.Normal, Cairo.FontWeight.Bold);
            cr.SetFontSize(size);

            Cairo.TextExtents extents = cr.TextExtents(text);
            string[] lines = text.Split ('\n');
            int min = size;
            for (int i = 0; i < lines.Length; i++) {
                string line = lines[i];
                for (int j = size; j > 8; j-=4) {
                    extents = cr.TextExtents(line);
                    if(extents.Width+extents.XBearing<800){
                        if(j<min) min = j;
                        break;
                    }
                    cr.SetFontSize(j);
                }
            }
            cr.SetFontSize(min);

            //string[] lines = text.Split ('\n');
            for (int i = 0; i < lines.Length; i++) {
                DrawText (cr, lines[i], x, y);
                y += (int)extents.Height;
                if (i > 5)
                    break;
            }

            Pixbuf buf = new Gdk.Pixbuf (surface.Data, true, 8, surface.Width, surface.Height, surface.Stride);
            return buf;

            //buf.Save ("aaa.png", "png");
            //surface.WriteToPng (file);
        }
示例#22
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;
                }
            }
        }
        protected override void RenderCell(Context context, Gdk.Rectangle pix_rect, bool isSelected)
        {
            if (!IsHeading)
            {
                Stream certIconStream = ECM.Core.CertGrade0PNG;
                string certGradeString = "None";

                if (CertGrade == 1)
                {
                    certIconStream = ECM.Core.CertGrade1PNG;
                    certGradeString = "Basic";
                }
                else if (CertGrade == 2)
                {
                    certIconStream = ECM.Core.CertGrade2PNG;
                    certGradeString = "Standard";
                }
                else if (CertGrade == 3)
                {
                    certIconStream = ECM.Core.CertGrade3PNG;
                    certGradeString = "Improved";
                }
                else if (CertGrade == 4)
                {
                    certIconStream = ECM.Core.CertGrade4PNG;
                    certGradeString = "None";
                }
                else if (CertGrade == 5)
                {
                    certIconStream = ECM.Core.CertGrade5PNG;
                    certGradeString = "Elite";
                }

                int osOffset = 0;
                int startX = pix_rect.Right - 64;

                if (ECM.Helper.CurrentPlatform == ECM.Helper.Platform.Windows)
                    osOffset = 1;

                // Render Text
                context.Save();

                Color col = White;

                //if (!isSelected)
                //    col = Black;

                TextExtents te = context.TextExtents(certGradeString);
                RenderText(context, certGradeString, startX - te.Width - 5, pix_rect.Y + 2, col);

                RenderText(context, Text, pix_rect.X + 32, pix_rect.Y + 2, col);

                context.Restore();

                // Render Progress bars
                context.Save();

                context.Color = Gray;
                context.Antialias = Antialias.None;
                context.LineWidth = 1;

                for (int i = 0; i < CertGrade; i++)
                {
                    context.Rectangle(startX + 2 + i * 9, pix_rect.Y + 3 + osOffset, 8, 6);
                }

                context.Fill();

                context.Rectangle(startX, pix_rect.Y + 2, 47, 9);

                context.Stroke();

                context.Restore();

                // Render Certificate Icon
                context.Save();

                animIter.Advance(IntPtr.Zero);
                Gdk.CairoHelper.SetSourcePixbuf(context, new Gdk.Pixbuf(certIconStream), pix_rect.X, pix_rect.Y);

                context.Paint();
                context.Restore();
            }
            else
                base.RenderCell(context, pix_rect, isSelected);
        }
示例#24
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;
        }
示例#25
0
文件: TextRun.cs 项目: jpbruyere/Crow
        protected override void onDraw(Context gr)
        {
            base.onDraw (gr);

            gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight);
            gr.SetFontSize (Font.Size);
            gr.FontOptions = Interface.FontRenderingOptions;
            gr.Antialias = Interface.Antialias;

            rText = new Rectangle (new Size (
                measureRawSize (LayoutingType.Width), measureRawSize (LayoutingType.Height)));
            rText.Width -= 2 * Margin;
            rText.Height -= 2 * Margin;

            widthRatio = 1f;
            heightRatio = 1f;

            Rectangle cb = ClientRectangle;

            //ignore text alignment if size to content = true
            //or if text size is larger than client bounds
            if (Width < 0 || Height < 0 || rText.Width > cb.Width) {
                rText.X = cb.X;
                rText.Y = cb.Y;
            } else {
                if (horizontalStretch) {
                    widthRatio = (float)cb.Width / rText.Width;
                    if (!verticalStretch)
                        heightRatio = widthRatio;
                }
                if (verticalStretch) {
                    heightRatio = (float)cb.Height / rText.Height;
                    if (!horizontalStretch)
                        widthRatio = heightRatio;
                }

                rText.Width = (int)(widthRatio * cb.Width);
                rText.Height = (int)(heightRatio * cb.Height);

                switch (TextAlignment) {
                case Alignment.TopLeft:     //ok
                    rText.X = cb.X;
                    rText.Y = cb.Y;
                    break;
                case Alignment.Top:   //ok
                    rText.Y = cb.Y;
                    rText.X = cb.X + cb.Width / 2 - rText.Width / 2;
                    break;
                case Alignment.TopRight:    //ok
                    rText.Y = cb.Y;
                    rText.X = cb.Right - rText.Width;
                    break;
                case Alignment.Left://ok
                    rText.X = cb.X;
                    rText.Y = cb.Y + cb.Height / 2 - rText.Height / 2;
                    break;
                case Alignment.Right://ok
                    rText.X = cb.X + cb.Width - rText.Width;
                    rText.Y = cb.Y + cb.Height / 2 - rText.Height / 2;
                    break;
                case Alignment.Bottom://ok
                    rText.X = cb.Width / 2 - rText.Width / 2;
                    rText.Y = cb.Height - rText.Height;
                    break;
                case Alignment.BottomLeft://ok
                    rText.X = cb.X;
                    rText.Y = cb.Bottom - rText.Height;
                    break;
                case Alignment.BottomRight://ok
                    rText.Y = cb.Bottom - rText.Height;
                    rText.X = cb.Right - rText.Width;
                    break;
                case Alignment.Center://ok
                    rText.X = cb.X + cb.Width / 2 - rText.Width / 2;
                    rText.Y = cb.Y + cb.Height / 2 - rText.Height / 2;
                    break;
                }
            }

            gr.FontMatrix = new Matrix (widthRatio * Font.Size, 0, 0, heightRatio * Font.Size, 0, 0);

            int curLineCount = 0;
            for (int i = 0; i < lines.Count; i++) {
                string l = lines [i].Replace ("\t", new String (' ', Interface.TabSize));
                List<string> wl = new List<string> ();
                int lineLength = (int)gr.TextExtents (l).XAdvance;

                if (wordWrap && lineLength > cb.Width) {
                    string tmpLine = "";
                    int curChar = 0;
                    while (curChar < l.Length) {
                        tmpLine += l [curChar];
                        if ((int)gr.TextExtents (tmpLine).XAdvance > cb.Width) {
                            tmpLine = tmpLine.Remove (tmpLine.Length - 1);
                            wl.Add (tmpLine);
                            tmpLine = "";
                            continue;
                        }
                        curChar++;
                    }
                    wl.Add (tmpLine);
                } else
                    wl.Add (l);

                foreach (string ll in wl) {
                    lineLength = (int)gr.TextExtents (ll).XAdvance;

                    if (string.IsNullOrWhiteSpace (ll)) {
                        curLineCount++;
                        continue;
                    }

                    Foreground.SetAsSource (gr);
                    gr.MoveTo (rText.X, rText.Y + fe.Ascent + fe.Height * curLineCount);

                    gr.ShowText (ll);
                    gr.Fill ();

                    curLineCount++;
                }
            }
        }
示例#26
0
 public virtual PointD MeasureSize(Context ctx)
 {
     if(sizeCache.X < 0.0d) {
         double w, th, h = MinimumHeight;
         KnownColors.SetFontFacePieceName(ctx);
         TextExtents te = ctx.TextExtents(this.Name);
         PointD siz;
         w = te.Height+Margin;
         th = te.Width;
         int index = 0x00;
         foreach(IPuzzlePiece piece in this.arguments) {
             if(piece == null) {
                 siz = new PointD(MinimumWidth,MinimumHeight);
             }
             else {
                 siz = piece.MeasureSize(ctx);
                 h = Math.Max(h,siz.Y);
             }
             this.subpieces[index++] = new Rectangle(w,2.0d*Margin,siz.X,siz.Y);
             w += siz.X+3.0d*Margin;
         }
         this.sizeCache = new PointD(w,Math.Max(th,h+2.0d*Margin)+2.0d*Margin);
     }
     return this.sizeCache;
 }
        static List<CharacterData> CreateCharacterData(
			string fontName, 
			FontSlant fontSlant, 
			FontWeight fontWeight, 
			double fontSize, 
			List<char> fontChars, 
			out double bitmapWidth, 
			out double bitmapHeight)
        {
            List<CharacterData> cds = new List<CharacterData>();

            using (ImageSurface surface = new ImageSurface(Format.Argb32, 256, 256))
            {
                using (Context g = new Context(surface))
                {
                    SetupContext(g, fontName, fontSlant, fontWeight, fontSize);

                    FontExtents fe = g.FontExtents;
                    double x = 0;
                    double y = 0;

                    for (int i = 0; i < fontChars.Count; i++)
                    {
                        CharacterData cd = new CharacterData();

                        cds.Add(cd);
                        cd.Character = new String(fontChars[i], 1);

                        TextExtents te = g.TextExtents(cd.Character);
                        double aliasSpace;

                        if (cd.Character == " ")
                            aliasSpace = 0.0;
                        else
                            aliasSpace = 1.0;

                        cd.Bearing = new PointD(-te.XBearing + aliasSpace, -te.YBearing + aliasSpace);
                        cd.Location = new Cairo.Rectangle(x, 0, te.Width + aliasSpace * 2, te.Height + aliasSpace * 2);
                        cd.Cropping = new Cairo.Rectangle(0, fe.Ascent + aliasSpace * 2 - cd.Bearing.Y, te.XAdvance + aliasSpace, cd.Location.Height);
                        cd.Kerning = new Vector3(0, (float)cd.Location.Width, (float)(cd.Bearing.X + cd.Cropping.Width - cd.Location.Width));

                        x += cd.Location.Width;

                        if (cd.Location.Height > y)
                            y = cd.Location.Height;
                    }

                    bitmapWidth = x;
                    bitmapHeight = y;
                }
            }

            return cds;
        }
示例#28
0
		public static void Draw (Context grw, TextElement text)
		{
			double dY = 0;

			if (text.Foregraund != null) {
				grw.SetSourceRGB (
					text.Foregraund.Red, 
					text.Foregraund.Green, 
					text.Foregraund.Blue);
			}

			grw.SelectFontFace (
				text.FontFamily, 
				FontSlant.Normal, 
				(FontWeight)text.Weight);

			grw.SetFontSize (text.ScaledFontSize);
			var te = grw.TextExtents (text.Text);

			double dX = 0;
			if (text.Align != null) {
				switch (text.Align.ToLowerInvariant()) {
				case AlignType.Center:
					dX = 0.5 * te.Width;

					break;
				case AlignType.Right:
					dX = te.Width;

					break;
				case AlignType.Left:
					dX = 0;
					break;
				default:					
					return;
				}
			}

			if (text.VAlign != null) {
				switch (text.VAlign.ToLowerInvariant ()) {
				case VAlignType.Top:
					dY = te.YBearing;
					break;
				case VAlignType.Center:
					dY = 0.5 * te.YBearing;
					break;
				case VAlignType.Bottom:
					dY = 0;
					break;
				default:					
					return;
				}
			}

			grw.MoveTo (
				text.Start.GeometryX - dX, 
				text.Start.GeometryY - dY);

			grw.ShowText (text.FormattedText);

			grw.Stroke ();
		}
示例#29
0
 protected void DrawHorizontalReferenceLines(Context g, Gdk.Rectangle area, float ySize)
 {
     for (int i = 0; i <= NumbersY; i++) {
         float actualLoc = (1 - i/NumbersY) * (area.Height - numberSpacingYTotal) + NumberSpacingYUp;
         String text = (i*ySize/NumbersY).ToString ("0.0");
         TextExtents size = g.TextExtents (text);
         g.MoveTo (Math.Max(NumberSpacingXLeft-size.Width, 0), actualLoc + size.Height / 2);
         g.ShowText (text);
         g.MoveTo (NumberSpacingXLeft, actualLoc);
         g.LineTo (area.Width-NumberSpacingXRight, actualLoc);
         g.Stroke ();
     }
 }