示例#1
0
        public System.Drawing.Bitmap KiRotate(System.Drawing.Bitmap bmp, float angle)
        {
            int w = bmp.Width + 2;
            int h = bmp.Height + 2;

            System.Drawing.Imaging.PixelFormat pf;

            pf = bmp.PixelFormat;

            System.Drawing.Bitmap   tmp = new System.Drawing.Bitmap(w, h, pf);
            System.Drawing.Graphics g   = System.Drawing.Graphics.FromImage(tmp);
            //g.Clear(bkColor);
            g.DrawImageUnscaled(bmp, 1, 1);
            g.Dispose();

            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
            path.AddRectangle(new System.Drawing.RectangleF(0f, 0f, w, h));
            System.Drawing.Drawing2D.Matrix mtrx = new System.Drawing.Drawing2D.Matrix();
            mtrx.Rotate(angle);
            System.Drawing.RectangleF rct = path.GetBounds(mtrx);

            System.Drawing.Bitmap dst = new System.Drawing.Bitmap((int)rct.Width, (int)rct.Height, pf);
            g = System.Drawing.Graphics.FromImage(dst);
            //g.Clear(bkColor);
            g.TranslateTransform(-rct.X, -rct.Y);
            g.RotateTransform(angle);
            g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
            g.DrawImageUnscaled(tmp, 0, 0);
            g.Dispose();

            tmp.Dispose();

            return(dst);
        }
示例#2
0
        static public Rect Rect(string text, Emugen.Image.Primitive.Font efont, PointF position)
        {
            var frameSize    = 0.0;
            var frameSizeMax = 0.0;
            var rfontFrames  = new List <Emugen.Image.Primitive.Font.FontFrame>();

            foreach (var frame in efont.fontFrames)
            {
                frameSizeMax += frame.size / 2;
                rfontFrames.Insert(0, frame);
            }
            frameSize = frameSizeMax;

            // Todo : フォントフレームの幅分だけマージンの対応が必要
            var margin = (int)System.Math.Floor(frameSize + subMargin);

            var font         = CreateFont(efont.fontPath, efont.fontSize);
            var emFontFize   = (float)font.Height * font.FontFamily.GetEmHeight(font.Style) / font.FontFamily.GetLineSpacing(font.Style);
            var stringFormat = new System.Drawing.StringFormat();

            // 描画
            var path = new System.Drawing.Drawing2D.GraphicsPath();

            path.AddString(text, font.FontFamily, (int)font.Style, emFontFize,
                           //path.AddString(text, font.FontFamily, (int)font.Style, (float)efont.fontSize,
                           new System.Drawing.PointF((float)(position.X), (float)(position.Y)),
                           stringFormat);

            var bound = path.GetBounds();
            //var result = new Rect(new Vector2D(bound.X - margin, bound.Y - margin), new Vector2D(bound.Width + margin * 2, bound.Height + margin * 2));
            var result = new Rect(new Vector2D(bound.X, bound.Y), new Vector2D(bound.Width, bound.Height));

            return(result);
        }
示例#3
0
        void Command_Image_Rotate(ImageRotateDialog.Result result)
        {
            var variables = GetVariables();
            var angle     = new NEExpression(result.AngleExpression).Evaluate <float>(variables, "deg");

            var bitmap = GetBitmap();
            var path   = new System.Drawing.Drawing2D.GraphicsPath();

            path.AddRectangle(new System.Drawing.Rectangle(0, 0, bitmap.Width, bitmap.Height));
            var matrix = new System.Drawing.Drawing2D.Matrix();

            matrix.Rotate(angle);
            var rect         = path.GetBounds(matrix);
            var resultBitmap = new System.Drawing.Bitmap((int)rect.Width, (int)rect.Height, bitmap.PixelFormat);

            using (var g = System.Drawing.Graphics.FromImage(resultBitmap))
            {
                g.TranslateTransform(-rect.X, -rect.Y);
                g.RotateTransform(angle);
                g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBilinear;
                g.DrawImageUnscaled(bitmap, 0, 0);
            }

            Replace(new List <Range> {
                FullRange
            }, new List <string> {
                Coder.BitmapToString(resultBitmap)
            });
            SetSelections(new List <Range> {
                BeginRange
            });
        }
        // Graphics methods
        //chuck's new code 2/20/04
        //this method indicates whether point is along outline of graphic
        //and if so, what type of cursor should show
        public virtual void BoundaryTest(System.Drawing.Point pt, SizeDirection dir)
        {
            System.Drawing.Drawing2D.GraphicsPath gp       = new System.Drawing.Drawing2D.GraphicsPath();
            System.Drawing.Drawing2D.Matrix       myMatrix = new System.Drawing.Drawing2D.Matrix();
            System.Drawing.Pen pen = new System.Drawing.Pen(System.Drawing.Color.Black, 3);

            gp.AddRectangle(new System.Drawing.Rectangle(this.m_Position.X - 3, this.m_Position.Y - 3, this.m_Size.Width + 6, this.m_Size.Height + 6));
            if (this.m_Rotation != 0)
            {
                myMatrix.RotateAt((float)this.m_Rotation, new System.Drawing.PointF((float)this.X, (float)this.Y), System.Drawing.Drawing2D.MatrixOrder.Append);
            }

            gp.Transform(myMatrix);
            dir = SizeDirection.NA;
            if (gp.IsOutlineVisible(pt, pen))
            {
                //user has placed the mouse along the outline of the selected
                //object - change the mouse to allow for resizing
                System.Drawing.RectangleF rect = gp.GetBounds();
                if (Math.Abs((int)rect.Left - pt.X) <= 2)
                {
                    if (Math.Abs((int)rect.Top - pt.Y) <= 2)
                    {
                        dir = SizeDirection.Northwest;
                    }
                    else if (Math.Abs((int)rect.Bottom - pt.Y) <= 2)
                    {
                        dir = SizeDirection.Southwest;
                    }
                    else
                    {
                        dir = SizeDirection.West;
                    }
                }
                else if (Math.Abs((int)rect.Right - pt.X) <= 2)
                {
                    if (Math.Abs((int)rect.Top - pt.Y) <= 2)
                    {
                        dir = SizeDirection.Northeast;
                    }
                    else if (Math.Abs((int)rect.Bottom - pt.Y) <= 2)
                    {
                        dir = SizeDirection.Southeast;
                    }
                    else
                    {
                        dir = SizeDirection.East;
                    }
                }
                else if (Math.Abs((int)rect.Top - pt.Y) <= 2)
                {
                    dir = SizeDirection.North;
                }
                else
                {
                    dir = SizeDirection.South;
                }
            }
        }
 public virtual bool HitTest(System.Drawing.Rectangle rect)
 {//is this object contained within the supplied rectangle
     System.Drawing.Drawing2D.GraphicsPath gp       = new System.Drawing.Drawing2D.GraphicsPath();
     System.Drawing.Drawing2D.Matrix       myMatrix = new System.Drawing.Drawing2D.Matrix();
     gp.AddRectangle(new System.Drawing.Rectangle(this.m_Position.X, this.m_Position.Y, this.m_Size.Width, this.m_Size.Height));
     if (this.m_Rotation != 0)
     {
         myMatrix.RotateAt((float)this.m_Rotation, new System.Drawing.PointF((float)this.m_Position.X, (float)this.m_Position.Y),
                           System.Drawing.Drawing2D.MatrixOrder.Append);
     }
     gp.Transform(myMatrix);
     System.Drawing.Rectangle gpRect = System.Drawing.Rectangle.Round(gp.GetBounds());
     return(rect.Contains(gpRect));
 }
示例#6
0
        /// <summary>
        /// Erase the trail of the gesture and stop drawing
        /// </summary>
        public void RefreshAndStopDrawing()
        {
            // the drawing of gestures was finished
            m_gestureDrawing = false;
            // drawing in thread timer tick should not continue
            m_drawingEnded = true;
            // stop the thread timer
            m_threadTimerDraw.Change(-1, -1);

            if (!m_threadDrawing)
            {
                int      lastIndex = m_curvePoints.Count;
                PointF[] points    = m_curvePoints.GetRange(m_lastIndex, lastIndex - m_lastIndex).ToArray();
                m_lastIndex = lastIndex - 1;
                if (points.Length > 1)
                {
                    m_gp.DrawLines(m_pen, points);
                }
            }

            List <PointF> allPoints = new List <PointF>(m_curvePoints.ToArray());

            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
            path.AddLines(allPoints.ToArray());
            RectangleF rect      = path.GetBounds();
            int        rectShift = m_penWidth * 6;

            rect.X      -= rectShift;
            rect.Y      -= rectShift;
            rect.Width  += rectShift * 2;
            rect.Height += rectShift * 2;
            //Win32.RECT r = new Win32.RECT(rect);
            m_drawnRegion = new Win32.RECT(rect);
            //Rectangle r = new Rectangle((int)rect.X, (int)rect.Y, (int)rect.Width, (int)rect.Height);
            if (!m_threadDrawing)
            {
                Debug.WriteLine(String.Format("##### InvalidateRect in MOUSE UP left: {0}, top: {1}, right: {2}, bottom: {3} ######",
                                              m_drawnRegion.left, m_drawnRegion.top, m_drawnRegion.right, m_drawnRegion.bottom));
                //Win32.InvalidateRect(m_hwndForm, ref m_drawnRegion, true);
                Win32.RedrawWindow(m_hwndForm, ref m_drawnRegion, IntPtr.Zero, Win32.RDW_ERASE | Win32.RDW_INVALIDATE | Win32.RDW_UPDATENOW);
                MakeNonTopMost();
            }
            else
            {
                m_redrawInTick = true;
            }
            //this.Invalidate(r);
            //Win32.RedrawWindow(m_hwndForm, ref r, IntPtr.Zero, 0x2);
        }
示例#7
0
        private Size MeasureText(Graphics graphics, string text, Font font)
        {
            var sz = TextRenderer.MeasureText(graphics, text, this.Font, new Size(0, 0), tf);
            return sz;

            var bounds = new RectangleF();
            using (var textPath = new System.Drawing.Drawing2D.GraphicsPath())
            {
                textPath.AddString(
                    text,
                    font.FontFamily,
                    (int)font.Style,
                    font.Size,
                    new PointF(0, 0),
                    StringFormat.GenericTypographic);
                bounds = textPath.GetBounds();
            }
            return new Size((int)bounds.Width, (int)bounds.Height);
        }
示例#8
0
        public override System.Drawing.RectangleF GetTransformedVObjectBounds()
        {
            //
            // We cannot use evident way to get bounds of the Path, something like this:
            //
            // return this.Path.GetBounds(_matrix, _pen);
            //
            // because this implementation returns wrong values. It seems that the GraphicsPath algorithm
            // first finds bounds and after that applies matrix! Also it returns wrong (too large)
            // rectangle for curves (e.g. for ellipse). To avoid first issue we have to clone path
            // and manually transform it. To avoid second problem we have to use Flatten() method.
            //

            using (System.Drawing.Drawing2D.GraphicsPath c = (System.Drawing.Drawing2D.GraphicsPath) this.Path.Clone())
            {
                c.Flatten(_matrix, 1.0f);
                return(c.GetBounds(_identityMatrix, _pen));
            }
        }
示例#9
0
            public ViewGeo(EvalGraphControl con)
            {
                plyMax = Math.Max((Math.Max(con.evaldata.maxIndex, con.evaldata.selectedIndex) + 9) / 10 * 10, 50);
                var plyMaxLen = $"{plyMax}".Length;

                hScrollValue  = con.HorizontalScroll.Value;
                scoreFontSize = Math.Max(Math.Min(con.Width / 16f, con.Height / 16f), 1f);
                lineWidthMul  = Math.Max(Math.Min(con.Width, con.Height) / 512f, 1f);
                scaleLineLen  = 6 * lineWidthMul;
                scaleTextPad  = 8 * lineWidthMul;
                RectangleF bounds;

                using (var path = new System.Drawing.Drawing2D.GraphicsPath())
                {
                    using (var font = new FontFamily(con.fontFamilyName))
                        path.AddString(
                            "+9999",
                            font,
                            (int)FontStyle.Regular,
                            scoreFontSize,
                            new PointF(0f, 0f),
                            new StringFormat()
                        {
                            Alignment = StringAlignment.Far, LineAlignment = StringAlignment.Near
                        }
                            );
                    bounds = path.GetBounds();
                    lPad   = 4 + (int)(-1.0f * bounds.Left + scaleTextPad);
                    rPad   = 4 + (int)(-0.1f * plyMaxLen * bounds.Left);
                    uPad   = 4 + (int)(+0.5f * bounds.Bottom);
                    bPad   = 4 + (int)(+1.0f * bounds.Bottom + scaleTextPad);
                }
                xlen           = con.evalGraphPictureBox.Width - lPad - rPad;
                ymul           = (con.evalGraphPictureBox.Height - uPad - bPad) * 0.5f;
                yadd           = uPad + ymul;
                graphBodyWidth = con.Width - lPad - rPad;
                plyWidth       = Math.Max(graphBodyWidth / plyMax, 4f);
                plyFontSize    = Math.Max(Math.Min(scoreFontSize * plyWidth * -80f / (plyMaxLen * bounds.Left), scoreFontSize), 1f);
                scoreRound     = Math.Max(Math.Min(con.Height * 0.01f, plyWidth * 0.5f), 3f);
                scoreLineWidth = Math.Max(scoreRound * 0.5f, 1f);
                boxWidth       = Math.Max((int)(lPad + rPad + plyMax * plyWidth), con.Width);
            }
示例#10
0
        /// <summary>
        /// Gets the default plot symbol size for all graphics in this graph, using the provided property context.
        /// </summary>
        /// <param name="context">The property context.</param>
        /// <returns>Default plot symbol size in points (1/72 inch).</returns>
        public static double GetDefaultSymbolSize(Altaxo.Main.Properties.IReadOnlyPropertyBag context)
        {
            double result = 1;

            if (null != context)
            {
                var font = context.GetValue(PropertyKeyDefaultFont);
                using (var path = new System.Drawing.Drawing2D.GraphicsPath())
                {
                    path.AddString("x", Gdi.GdiFontManager.ToGdi(font.Font).FontFamily, (int)font.Style, (float)font.Size, new System.Drawing.PointF(0, 0), System.Drawing.StringFormat.GenericTypographic);
                    var bounds = path.GetBounds();

                    if (bounds.Height > 0)
                    {
                        result = Calc.Rounding.RoundToNumberOfSignificantDigits(bounds.Height, 2, MidpointRounding.ToEven);
                    }
                }
            }
            return(result);
        }
示例#11
0
        private Size MeasureText(Graphics graphics, string text, Font font)
        {
            var sz = TextRenderer.MeasureText(graphics, text, this.Font, new Size(0, 0), tf);

            return(sz);

            var bounds = new RectangleF();

            using (var textPath = new System.Drawing.Drawing2D.GraphicsPath())
            {
                textPath.AddString(
                    text,
                    font.FontFamily,
                    (int)font.Style,
                    font.Size,
                    new PointF(0, 0),
                    StringFormat.GenericTypographic);
                bounds = textPath.GetBounds();
            }
            return(new Size((int)bounds.Width, (int)bounds.Height));
        }
        //UPGRADE_TODO: Interface 'java.awt.Shape' was converted to 'System.Drawing.Drawing2D.GraphicsPath' which has a different behavior. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1073'"
        public ShapeWithStyleBuilder(System.Drawing.Drawing2D.GraphicsPath shape, GraphicContext graphicContext, bool outline, bool fill)
        {
            Point origin = new Point((double)graphicContext.getPen().X, (double)graphicContext.getPen().Y);

            System.Drawing.Brush paint  = graphicContext.Paint;
            System.Drawing.Pen   stroke = graphicContext.Stroke;

            FillStyle fs = null;
            LineStyle ls = null;

            if (fill && paint != null)
            {
                System.Drawing.RectangleF tempAux = shape.GetBounds();
                //UPGRADE_NOTE: ref keyword was added to struct-type parameters. "ms-help://MS.VSCC.v80/dv_commoner/local/redirect.htm?index='!DefaultContextWindowIndex'&keyword='jlca1303'"
                fs = FillStyleBuilder.build(paint, ref tempAux, graphicContext.Transform);
            }

            if (outline && stroke != null)
            {
                ls = LineStyleBuilder.build(paint, stroke);
            }

            init(shape, origin, fs, ls, fill);
        }
示例#13
0
 protected override void GeneratePath()
 {
     _Path = new System.Drawing.Drawing2D.GraphicsPath();
     _Path.AddRectangle(new Rectangle(Location, Size));
     InvalidationArea = Rectangle.Round(_Path.GetBounds());
 }
示例#14
0
        } // End Function GetWarpCaptcha

        public static System.Drawing.Drawing2D.GraphicsPath BezierWarp(
            System.Drawing.Drawing2D.GraphicsPath text, System.Drawing.Size size)
        {
            // Control points for a cubic Bézier spline
            System.Drawing.PointF P0 = new System.Drawing.PointF();
            System.Drawing.PointF P1 = new System.Drawing.PointF();
            System.Drawing.PointF P2 = new System.Drawing.PointF();
            System.Drawing.PointF P3 = new System.Drawing.PointF();

            float shrink = 20;
            float shift  = 0;

            P0.X = shrink;
            P0.Y = shrink + shift;
            P1.X = size.Width - shrink;
            P1.Y = shrink;
            P2.X = shrink;
            P2.Y = size.Height - shrink;
            P3.X = size.Width - shrink;
            P3.Y = size.Height - shrink - shift;

            // Calculate coefficients A thru H from the control points
            float A = P3.X - 3 * P2.X + 3 * P1.X - P0.X;
            float B = 3 * P2.X - 6 * P1.X + 3 * P0.X;
            float C = 3 * P1.X - 3 * P0.X;
            float D = P0.X;

            float E = P3.Y - 3 * P2.Y + 3 * P1.Y - P0.Y;
            float F = 3 * P2.Y - 6 * P1.Y + 3 * P0.Y;
            float G = 3 * P1.Y - 3 * P0.Y;
            float H = P0.Y;

            System.Drawing.PointF[]   pathPoints = text.PathPoints;
            System.Drawing.RectangleF textBounds = text.GetBounds();

            for (int i = 0; i < pathPoints.Length; i++)
            {
                System.Drawing.PointF pt = pathPoints[i];
                float textX = pt.X;
                float textY = pt.Y;

                // Normalize the x coordinate into the parameterized
                // value with a domain between 0 and 1.
                float t  = textX / textBounds.Width;
                float t2 = (t * t);
                float t3 = (t * t * t);

                // Calculate spline point for parameter t
                float Sx = A * t3 + B * t2 + C * t + D;
                float Sy = E * t3 + F * t2 + G * t + H;

                // Calculate the tangent vector for the point
                float Tx = 3 * A * t2 + 2 * B * t + C;
                float Ty = 3 * E * t2 + 2 * F * t + G;

                // Rotate 90 or 270 degrees to make it a perpendicular
                float Px = -Ty;
                float Py = Tx;

                // Normalize the perpendicular into a unit vector
                float magnitude = (float)System.Math.Sqrt((Px * Px) + (Py * Py));
                Px /= magnitude;
                Py /= magnitude;

                // Assume that input text point y coord is the "height" or
                // distance from the spline.  Multiply the perpendicular
                // vector with y. it becomes the new magnitude of the vector
                Px *= textY;
                Py *= textY;

                // Translate the spline point using the resultant vector
                float finalX = Px + Sx;
                float finalY = Py + Sy;

                pathPoints[i] = new System.Drawing.PointF(finalX, finalY);
            }

            return(new System.Drawing.Drawing2D.GraphicsPath(pathPoints, text.PathTypes));
        }
示例#15
0
        public static byte[] GetWarpCaptcha()
        {
            byte[] imageBytes = null;

            string text = "I can haz Peanut";

            text = "This is a test";
            text = Helpers.GenerateRandomCode();
            text = Helpers.GenerateRandomNumber();

            System.Drawing.Drawing2D.GraphicsPath textPath = new System.Drawing.Drawing2D.GraphicsPath();

            float fontSize = 23;

            // textPath.AddString("st", null, 123, 12, )

            // the baseline should start at 0,0, so the next line is not quite correct
            textPath.AddString(
                text
                , System.Drawing.FontFamily.GenericSansSerif
                , (int)System.Drawing.FontStyle.Bold, fontSize
                , new System.Drawing.Point(0, 0)
                , System.Drawing.StringFormat.GenericTypographic
                );

            System.Drawing.RectangleF textBounds = textPath.GetBounds();


            using (System.Drawing.Bitmap bmp = new System.Drawing.Bitmap(300, 150))
            {
                using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bmp))
                {
                    g.Clear(System.Drawing.Color.White);

                    System.Drawing.Drawing2D.HatchBrush hatchBrush =
                        new System.Drawing.Drawing2D.HatchBrush(
                            //System.Drawing.Drawing2D.HatchStyle.SmallConfetti
                            System.Drawing.Drawing2D.HatchStyle.Wave
                            //System.Drawing.Drawing2D.HatchStyle.Plaid
                            , System.Drawing.Color.LightGray
                            //, System.Drawing.Color.Black
                            , System.Drawing.Color.White
                            );
                    g.FillRectangle(hatchBrush, 0, 0, bmp.Width, bmp.Height);


                    // GraphicsPath bezierPath = textPath;
                    // GraphicsPath bezierPath = BezierWarp(textPath, new System.Drawing.Size((int)textBounds.Width, (int)textBounds.Height));
                    System.Drawing.Drawing2D.GraphicsPath bezierPath = BezierWarp(textPath, new System.Drawing.Size(bmp.Width, bmp.Height));

                    // draw the transformed text path
                    g.DrawPath(System.Drawing.Pens.Black, bezierPath);

                    // Draw the Bézier for reference
                    // g.DrawBezier(Pens.Black, P0, P1, P2, P3);
                } // End Using g

                using (System.IO.MemoryStream ms = new System.IO.MemoryStream())
                {
                    bmp.Save(ms, System.Drawing.Imaging.ImageFormat.Png);
                    imageBytes = ms.ToArray();
                } // End Using ms
            }     // End Using bmp

            return(imageBytes);
        } // End Function GetWarpCaptcha
示例#16
0
 public virtual System.Drawing.Rectangle getBounds(System.Drawing.Drawing2D.Matrix transform)
 {
     System.Drawing.Rectangle tempAux = System.Drawing.Rectangle.Truncate(shape.GetBounds());
     //UPGRADE_NOTE: ref keyword was added to struct-type parameters. 'ms-help://MS.VSCC.2003/commoner/redir/redirect.htm?keyword="jlca1303_3"'
     return(Util.transform(transform, ref tempAux));
 }
示例#17
0
 protected override void GeneratePath()
 {
     _Path = new System.Drawing.Drawing2D.GraphicsPath();
     _Path.AddRectangle(new Rectangle(Location, Size));
     InvalidationArea = Rectangle.Round(_Path.GetBounds());
 }
示例#18
0
        /// <summary>
        /// Analyzuje pole vertexů jako polygon a zjistí jeho geometrický střed (centroid), šířku a výšku
        /// </summary>
        /// <param name="Vertices">Pole vertexů</param>
        /// <returns>Výsledek analýzy polygonu</returns>
        public static GeometryDescriptor AnalyzeVertexGroup(PointF[] Vertices)
        {
            if (Vertices.Length <= 1)
                throw new ArgumentException();

            GeometryDescriptor Description = new GeometryDescriptor(Vertices);
            Description.FrontalArea = PolygonArea(Vertices);

            for (int i = 0,j = 0; i < Vertices.Length; i++)
            {
                j = (i + 1) % Vertices.Length;
                Description.Centroid.X += (Vertices[i].X + Vertices[j].X) * (Vertices[i].X * Vertices[j].Y - Vertices[i].Y * Vertices[j].X);
                Description.Centroid.Y += (Vertices[i].Y + Vertices[j].Y) * (Vertices[i].X * Vertices[j].Y - Vertices[i].Y * Vertices[j].X);
            }

            Description.ConvexHull = ConvexHull.GetConvexHull(Vertices);
            Description.Centroid.X /= (float)(Description.FrontalArea * 6);
            Description.Centroid.Y /= (float)(Description.FrontalArea * 6);

            using (System.Drawing.Drawing2D.GraphicsPath p = new System.Drawing.Drawing2D.GraphicsPath())
            {
                p.AddPolygon(Vertices);
                RectangleF r = p.GetBounds();

                Description.Width = r.Width;
                Description.Height = r.Height;
            }

            return Description;
        }
示例#19
0
        public Caption Render(string message, Position position, string fontName, float fontSize, bool isBold, bool isItalic, Color fontColor, Color bgColor, float bgBorder)
        {
            using (Graphics g = Graphics.FromImage(bitmap))
            {
                float padding = bgBorder * g.DpiX / 72;
                float x = padding;
                float y = padding;

                int fontStyle = (int)System.Drawing.FontStyle.Regular;
                if (isBold) fontStyle |= (int)System.Drawing.FontStyle.Bold;
                if (isItalic) fontStyle |= (int)System.Drawing.FontStyle.Italic;

                Font font = new Font(fontName, fontSize);
                Brush brush = new SolidBrush(fontColor);
                Brush bbrush = new SolidBrush(bgColor);
                Pen pen = new Pen(bbrush, padding);

                pen.LineJoin = System.Drawing.Drawing2D.LineJoin.Round;
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;

                // Get Render Bounds
                RectangleF rect;
                using (var gp = new System.Drawing.Drawing2D.GraphicsPath())
                {
                    gp.AddString(message, new FontFamily(fontName), fontStyle, fontSize, new RectangleF(new PointF(padding, padding), new SizeF(bitmap.Width - padding, bitmap.Height - padding)), StringFormat.GenericTypographic);

                    rect = gp.GetBounds();
                }

                // Render
                if (position == K4WDisclaimer.Position.Bottom)
                {
                    y = bitmap.Height - rect.Height - rect.Y - padding;
                }
                using (var gp = new System.Drawing.Drawing2D.GraphicsPath())
                {

                    gp.AddString(message, new FontFamily(fontName), fontStyle, fontSize, new RectangleF(new PointF(x, y), new SizeF(bitmap.Width - padding, bitmap.Height - padding)), StringFormat.GenericTypographic);
                    g.FillPath(bbrush, gp);
                    g.DrawPath(pen, gp);
                    g.FillPath(brush, gp);
                }

                brush.Dispose();
                bbrush.Dispose();
                pen.Dispose();
                font.Dispose();
            }
            return this;
        }
示例#20
0
        public System.Drawing.Bitmap CreateBitmap(string text, double fontSize, Color color, int bitmap_bounds_margin, out FontStringInfo info)
        {
            var bitmap = default(System.Drawing.Bitmap);

            info = new FontStringInfo();

            var font         = default(System.Drawing.Font);
            var emFontFize   = default(float);
            var stringFormat = default(System.Drawing.StringFormat);
            var path         = default(System.Drawing.Drawing2D.GraphicsPath);
            var path2        = default(System.Drawing.Drawing2D.GraphicsPath);
            var bounds       = default(System.Drawing.RectangleF);

            //var fontStyle = System.Drawing.FontStyle.Bold;
            //var fontName = "Rounded-X Mgen+ 1cp bold";
            font = new System.Drawing.Font(fontFamily, (float)fontSize, fontStyle);
            //try {}
            ////try { font = new System.Drawing.Font(fontName, (float)fontSize, System.Drawing.FontStyle.Bold); }
            //catch (Exception exp) {
            //    Log.WriteLine($"CreateBitmap 1-1\n{exp}");
            //    try
            //    {
            //        font = new System.Drawing.Font("MS ゴシック", (float)fontSize, System.Drawing.FontStyle.Regular);
            //        Log.WriteLine($"CreateBitmap 1-1 Success\n代替えフォントに\"MS ゴシック\"を利用");
            //    }
            //    catch
            //    {
            //        Log.WriteLine($"CreateBitmap 1-1-1\n{exp}");
            //    }
            //}

            //EmugenUnityDll.Common.Log.WriteLine($"CreateBitmap UseFontName {font.Name}");

            emFontFize   = (float)font.Height * font.FontFamily.GetEmHeight(font.Style) / font.FontFamily.GetLineSpacing(font.Style);
            stringFormat = new System.Drawing.StringFormat();
            path         = new System.Drawing.Drawing2D.GraphicsPath();
            path.AddString(text, font.FontFamily, (int)fontStyle, emFontFize, new System.Drawing.PointF(0, 0), stringFormat);
            bounds = path.GetBounds();
            path2  = new System.Drawing.Drawing2D.GraphicsPath();
            path2.AddString(text, fontFamily, (int)fontStyle, emFontFize,
                            new System.Drawing.PointF((float)(-bounds.Left + bitmap_bounds_margin), (float)(-bounds.Top + bitmap_bounds_margin)),
                            stringFormat);
            bitmap = new System.Drawing.Bitmap(
                (int)(bounds.Width + bitmap_bounds_margin * 2 + 2),
                (int)(bounds.Height + bitmap_bounds_margin * 2 + 2), System.Drawing.Imaging.PixelFormat.Format32bppArgb);
            info.offsetX = (int)bounds.Left - bitmap_bounds_margin;
            info.offsetY = (int)bounds.Top - bitmap_bounds_margin;



            using (var g = System.Drawing.Graphics.FromImage(bitmap))
            {
                var brush = default(System.Drawing.SolidBrush);
                brush           = new System.Drawing.SolidBrush(System.Drawing.Color.FromArgb(255, 0, 0, 0));
                g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                g.FillPath(brush, path2);
                //try {  }
                //catch (Exception exp) { Log.WriteLine($"CreateBitmap 1-11\n{exp}"); }

                //try {  }
                //catch (Exception exp) { Log.WriteLine($"CreateBitmap 1-12\n{exp}"); }

                //try { }
                //catch (Exception exp) { Log.WriteLine($"CreateBitmap 1-13\n{exp}"); }
            }

            return(bitmap);
        }
        /// <summary>
        /// Erase the trail of the gesture and stop drawing
        /// </summary>
        public void RefreshAndStopDrawing()
        {

            // the drawing of gestures was finished
            m_gestureDrawing = false;
            // drawing in thread timer tick should not continue
            m_drawingEnded = true;
            // stop the thread timer
            m_threadTimerDraw.Change(-1, -1);

            if (!m_threadDrawing)
            {
                int lastIndex = m_curvePoints.Count;
                PointF[] points = m_curvePoints.GetRange(m_lastIndex, lastIndex - m_lastIndex).ToArray();
                m_lastIndex = lastIndex - 1;
                if (points.Length > 1)
                    m_gp.DrawLines(m_pen, points);
            }

            List<PointF> allPoints = new List<PointF>(m_curvePoints.ToArray());
            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
            path.AddLines(allPoints.ToArray());
            RectangleF rect = path.GetBounds();
            int rectShift = m_penWidth * 6;
            rect.X -= rectShift;
            rect.Y -= rectShift;
            rect.Width += rectShift * 2;
            rect.Height += rectShift * 2;
            //Win32.RECT r = new Win32.RECT(rect);
            m_drawnRegion = new Win32.RECT(rect);
            //Rectangle r = new Rectangle((int)rect.X, (int)rect.Y, (int)rect.Width, (int)rect.Height);
            if (!m_threadDrawing)
            {
                Debug.WriteLine(String.Format("##### InvalidateRect in MOUSE UP left: {0}, top: {1}, right: {2}, bottom: {3} ######",
                    m_drawnRegion.left, m_drawnRegion.top, m_drawnRegion.right, m_drawnRegion.bottom));
                //Win32.InvalidateRect(m_hwndForm, ref m_drawnRegion, true);
                Win32.RedrawWindow(m_hwndForm, ref m_drawnRegion, IntPtr.Zero, Win32.RDW_ERASE | Win32.RDW_INVALIDATE | Win32.RDW_UPDATENOW);                
                MakeNonTopMost();
            }
            else
                m_redrawInTick = true;
            //this.Invalidate(r);
            //Win32.RedrawWindow(m_hwndForm, ref r, IntPtr.Zero, 0x2);
        }
示例#22
0
        /// <summary>
        /// This is the method that actually does the work.
        /// </summary>
        /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param>
        protected override void SolveInstance(IGH_DataAccess DA)
        {
            string S = "";

            DA.GetData(0, ref S);
            string fontString = "";

            DA.GetData(1, ref fontString);
            bool close = false;

            DA.GetData(2, ref close);
            double size = 0.0;

            DA.GetData(3, ref size);
            double precision = 0.0;

            DA.GetData(4, ref precision);
            Plane basePlane = new Plane();

            DA.GetData(5, ref basePlane);
            int J = 0;

            DA.GetData(6, ref J);

            float fS         = size == 0 ? 1 : (float)size;
            Font  local_font = new Font(fontString, (float)fS);

            System.Drawing.Drawing2D.GraphicsPath path = new System.Drawing.Drawing2D.GraphicsPath();
            path.AddString(S, local_font.FontFamily, (int)local_font.Style, local_font.Size, new PointF(0, 0), new StringFormat());

            System.Drawing.Drawing2D.Matrix matrix = new System.Drawing.Drawing2D.Matrix(); // transformation matrix
            matrix.Reset();                                                                 // build identity matrix

            // __________________ autoList part __________________

            // variable for the list
            Grasshopper.Kernel.Special.GH_ValueList vList;
            // tries to cast input as list
            try
            {
                // if the list is not the first parameter then change Input[6] to the corresponding value
                vList = Params.Input[6].Sources[0] as Grasshopper.Kernel.Special.GH_ValueList;

                // check if the list must be created

                if (!vList.NickName.Equals("Justification"))
                {
                    vList.ClearData();
                    vList.ListItems.Clear();
                    vList.NickName = "Justification";

                    for (int i = 0; i < justification.Length; i++)
                    {
                        vList.ListItems.Add(new Grasshopper.Kernel.Special.GH_ValueListItem(justification[i][0], justification[i][1]));
                    }

                    //var item1 = new Grasshopper.Kernel.Special.GH_ValueListItem("TopLeft", "0");
                    //var item2 = new Grasshopper.Kernel.Special.GH_ValueListItem("MiddleLeft", "1");
                    //var item3 = new Grasshopper.Kernel.Special.GH_ValueListItem("BottomLeft", "2");
                    //var item4 = new Grasshopper.Kernel.Special.GH_ValueListItem("TopCenter", "3");
                    //var item5 = new Grasshopper.Kernel.Special.GH_ValueListItem("MiddleCenter", "4");
                    //var item6 = new Grasshopper.Kernel.Special.GH_ValueListItem("BottomCenter", "5");
                    //var item7 = new Grasshopper.Kernel.Special.GH_ValueListItem("TopRight", "6");
                    //var item8 = new Grasshopper.Kernel.Special.GH_ValueListItem("MiddleRight", "7");
                    //var item9 = new Grasshopper.Kernel.Special.GH_ValueListItem("BottomRight", "8");
                    //vList.ListItems.Add(item1);
                    //vList.ListItems.Add(item2);
                    //vList.ListItems.Add(item3);
                    //vList.ListItems.Add(item4);
                    //vList.ListItems.Add(item5);
                    //vList.ListItems.Add(item6);
                    //vList.ListItems.Add(item7);
                    //vList.ListItems.Add(item8);
                    //vList.ListItems.Add(item9);

                    vList.ListItems[0].Value.CastTo(out J);
                }
            }
            catch
            {
                // handles anything that is not a value list
            }

            // ______________ text justification ______________

            RectangleF rec = path.GetBounds(); // bounding rectangle for text
            float      dX = Convert.ToSingle(rec.Width * -0.5), dY = Convert.ToSingle(rec.Height * 0.5);

            switch (J)
            {
            case 0:    // top left
                dX = 0;
                dY = fS;
                break;

            case 1:     // middle left
                dX = 0;
                dY = Convert.ToSingle((-rec.Height) * 0.5 + fS);
                break;

            case 2:      // bottom left
                dX = 0;
                dY = Convert.ToSingle(-rec.Height + fS * 0.5);
                break;

            case 3:     // top center
                dX = Convert.ToSingle(rec.Width * -0.5);
                dY = fS;
                break;

            case 4:     // middle center
                dX = Convert.ToSingle(rec.Width * -0.5);
                dY = Convert.ToSingle((-rec.Height) * 0.5 + fS);
                break;

            case 5:     // bottom center
                dX = Convert.ToSingle(rec.Width * -0.5);
                dY = Convert.ToSingle(-rec.Height + fS * 0.5);
                break;

            case 6:     // top right
                dX = Convert.ToSingle(rec.Width * -1);
                dY = fS;
                break;

            case 7:     // middle right
                dX = Convert.ToSingle(rec.Width * -1);
                dY = Convert.ToSingle((-rec.Height) * 0.5 + fS);
                break;

            case 8:     // bottom right
                dX = Convert.ToSingle(rec.Width * -1);
                dY = Convert.ToSingle(-rec.Height + fS * 0.5);
                break;
            }
            //float dX = Convert.ToSingle(rec.Width * -0.5);
            //float dY = Convert.ToSingle(rec.Height * 0.5);
            System.Drawing.Drawing2D.Matrix mTrans = new System.Drawing.Drawing2D.Matrix(1, 0, 0, 1, dX, dY); // build transformation matrix
            path.Transform(mTrans);                                                                           // transform text path

            // ______________ convert to polylines ______________

            path.Flatten(matrix, (float)(size / precision)); // turns the path into a polyline that approximates the path

            PointF[]        pts     = path.PathPoints;       // get path points
            Byte[]          tps     = path.PathTypes;        // get path point types
            List <Polyline> strokes = new List <Polyline>(); // List for strokes
            Polyline        stroke  = new Polyline();

            Byte typ_start = Convert.ToByte(System.Drawing.Drawing2D.PathPointType.Start);// find start points condition

            // the conversion loop
            for (int i = 0; i < pts.Length; i++)
            {
                // if a start point is found, and the existing polyline is not null nor a single point,
                // add polyline to the strokes and create a new polyline
                if (tps[i] == typ_start)
                {
                    if (stroke != null && stroke.Count > 1)
                    {
                        if (close && !stroke.IsClosed)
                        {
                            stroke.Add(stroke[0]);                            // close polyline if necessary
                        }
                        strokes.Add(stroke);
                    }
                    stroke = new Polyline();
                }
                // in any other case add the next point to a polyline
                stroke.Add(pts[i].X, -pts[i].Y + size, 0);
                // add last stroke to the list
                if (i == pts.Length - 1)
                {
                    if (close && !stroke.IsClosed)
                    {
                        stroke.Add(stroke[0]);                            // and close it if necessary
                    }
                    strokes.Add(stroke);
                }
            }


            // ______________ align strokes to given plane ______________

            Transform align = Transform.PlaneToPlane(Plane.WorldXY, basePlane); // align transformation

            for (int j = 0; j < strokes.Count; j++)
            {
                strokes[j].Transform(align);
            }

            DA.SetDataList(0, strokes);
        }
示例#23
0
文件: Carte.cs 项目: crocovert/Musliw
        private void Carte_Paint(object sender, PaintEventArgs e)
        {
            int   i;
            float w, h;
            //projet = ((Musliw.MusliW)(this.MdiParent)).projet;
            Graphics page = e.Graphics;

            //page.Clear(this.BackColor);

            w = this.Width;
            h = this.Height;

            Pen  stylo = new Pen(fen.stylo_couleur, fen.epaisseur);
            Font fonte = new Font(FontFamily.GenericSansSerif, 7, FontStyle.Bold);

            this.ForeColor = Color.Black;
            Brush brosse = new SolidBrush(fen.brosse_couleur);
            Brush brosse_texte = new SolidBrush(fen.couleur_texte);
            float dx = w / (projet.reseaux[nproj].xu - projet.reseaux[nproj].xl);
            float dy = h / (projet.reseaux[nproj].yu - projet.reseaux[nproj].yl);
            float deltax, deltay, voldeltax, voldeltay;
            float cx = 0.5f * (projet.reseaux[nproj].xu + projet.reseaux[nproj].xl);
            float cy = 0.5f * (projet.reseaux[nproj].yu + projet.reseaux[nproj].yl);

            //MessageBox.Show(xl.ToString() + " " + yu.ToString());
            PointF p1 = new PointF();
            PointF p2 = new PointF();
            PointF p3 = new PointF();
            PointF p4 = new PointF();
            PointF p5 = new PointF();


            PointF[] points = new PointF[4];
            float    angle = 0, norme = 0;
            float    sinx = 0, cosx = 1;

            if (fen.volume_echelle < 1e-6f)
            {
                fen.volume_echelle = 1e-6f;
            }
            for (i = 0; i < projet.reseaux[nproj].links.Count; i++)
            {
                norme = fen.norme(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, fen.ecart + 0.5f * fen.epaisseur);
                if ((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].is_visible == true && projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].is_visible == true && norme > 0) && (projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].is_valid == true && projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].is_valid == true))
                {
                    //page.DrawRectangle(stylo, 0f, 0f, 200, 200);
                    //MessageBox.Show(((res.nodes[i].x - res.xl) * delta).ToString() + " " + ((res.yu - res.nodes[i].y) * delta).ToString()+" "+w.ToString()+" "+h.ToString());
                    deltax = fen.deltax(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, fen.ecart + 0.5f * fen.epaisseur);
                    deltay = fen.deltay(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, fen.ecart + 0.5f * fen.epaisseur);
                    cosx   = fen.deltax(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, 1);
                    sinx   = fen.deltay(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, 1);

                    voldeltax = fen.deltax(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, fen.ecart + 0.5f * fen.epaisseur + projet.reseaux[projet.reseau_actif].links[i].volau / fen.volume_echelle);
                    voldeltay = fen.deltay(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, fen.ecart + 0.5f * fen.epaisseur + projet.reseaux[projet.reseau_actif].links[i].volau / fen.volume_echelle);
                    page.DrawLine(stylo, ((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x - fen.xl) / fen.echelle) + deltay, ((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y) / fen.echelle) + deltax, ((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x - fen.xl) / fen.echelle) + deltay, ((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y) / fen.echelle) + deltax);


                    p1.X = ((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x - fen.xl) / fen.echelle) + deltay;
                    p1.Y = ((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y) / fen.echelle) + deltax;
                    p2.X = ((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x - fen.xl) / fen.echelle) + voldeltay;
                    p2.Y = ((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y) / fen.echelle) + voldeltax;
                    p3.X = ((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x - fen.xl) / fen.echelle) + voldeltay;
                    p3.Y = ((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y) / fen.echelle) + voldeltax;
                    p4.X = ((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x - fen.xl) / fen.echelle) + deltay;
                    p4.Y = ((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y) / fen.echelle) + deltax;


                    System.Drawing.Drawing2D.GraphicsPath epaisseur       = new System.Drawing.Drawing2D.GraphicsPath();
                    System.Drawing.Drawing2D.GraphicsPath texte_epaisseur = new System.Drawing.Drawing2D.GraphicsPath();
                    epaisseur.StartFigure();
                    points[0] = p1;
                    points[1] = p2;
                    points[2] = p3;
                    points[3] = p4;


                    epaisseur.AddPolygon(points);
                    epaisseur.CloseFigure();
                    //page.FillPath(brosse, epaisseur);
                    //page.FillPolygon(brosse, points);
                    //page.DrawPolygon(stylo,points);
                    epaisseur.Reset();
                    texte_epaisseur.StartFigure();
                    p5.X = 0.5f * (p3.X + p2.X);
                    p5.Y = 0.5f * (p3.Y + p2.Y);
                    texte_epaisseur.AddString(projet.reseaux[projet.reseau_actif].links[i].volau.ToString("0"), FontFamily.GenericSansSerif, 0, fen.taille_texte, new PointF(p5.X, p5.Y), StringFormat.GenericDefault);
                    RectangleF encombrement = texte_epaisseur.GetBounds();
                    // texte_epaisseur.AddRectangle(encombrement);
                    //texte_epaisseur.AddPie(p5.X,p5.Y,2,2,0,360);

                    page.FillPolygon(brosse, points);
                    page.DrawPolygon(stylo, points);

                    if (encombrement.Width < fen.norme(p1.X, p4.X, p1.Y, p4.Y, 1) && projet.reseaux[projet.reseau_actif].links[i].volau > 0)
                    {
                        System.Drawing.Drawing2D.Matrix rotation = new System.Drawing.Drawing2D.Matrix();

                        if (cosx >= 0 && sinx <= 0)
                        {
                            angle = 180f * ((float)Math.Acos(cosx) / (float)Math.PI);
                            rotation.RotateAt(angle, p5);
                            rotation.Translate(p5.X - encombrement.X, p5.Y - encombrement.Y);
                            System.Drawing.Drawing2D.Matrix trans = new System.Drawing.Drawing2D.Matrix();
                            texte_epaisseur.Transform(rotation);
                            trans.Translate(-0.5f * encombrement.Width * cosx, 0.5f * encombrement.Width * sinx);
                            texte_epaisseur.Transform(trans);
                            texte_epaisseur.CloseFigure();
                            page.FillPath(brosse_texte, texte_epaisseur);
                        }
                        else if (cosx <= 0 && sinx >= 0)
                        {
                            angle = 180f - 180f * ((float)Math.Acos(cosx) / (float)Math.PI);
                            rotation.RotateAt(angle, p5);
                            rotation.Translate(p5.X - encombrement.X, p5.Y - encombrement.Y);
                            System.Drawing.Drawing2D.Matrix trans = new System.Drawing.Drawing2D.Matrix();
                            texte_epaisseur.Transform(rotation);
                            trans.Translate(+0.5f * encombrement.Width * cosx + (encombrement.Height) * sinx, -0.5f * encombrement.Width * sinx + (encombrement.Height) * cosx);
                            texte_epaisseur.Transform(trans);
                            texte_epaisseur.CloseFigure();

                            page.FillPath(brosse_texte, texte_epaisseur);
                        }
                        else if (cosx >= 0 && sinx >= 0)
                        {
                            angle = -180f * (float)Math.Acos(cosx) / (float)Math.PI;
                            rotation.RotateAt(angle, p5);
                            rotation.Translate(p5.X - encombrement.X, p5.Y - encombrement.Y);
                            System.Drawing.Drawing2D.Matrix trans = new System.Drawing.Drawing2D.Matrix();
                            texte_epaisseur.Transform(rotation);
                            trans.Translate(-0.5f * encombrement.Width * cosx, 0.5f * encombrement.Width * sinx);
                            texte_epaisseur.Transform(trans);
                            texte_epaisseur.CloseFigure();

                            page.FillPath(brosse_texte, texte_epaisseur);
                        }
                        else if (cosx <= 0 && sinx <= 0)
                        {
                            angle = 180 + 180f * ((float)Math.Acos(cosx) / (float)Math.PI);
                            rotation.RotateAt(angle, p5);
                            rotation.Translate(p5.X - encombrement.X, p5.Y - encombrement.Y);
                            System.Drawing.Drawing2D.Matrix trans = new System.Drawing.Drawing2D.Matrix();
                            texte_epaisseur.Transform(rotation);
                            trans.Translate(+0.5f * encombrement.Width * cosx + (encombrement.Height) * sinx, -0.5f * encombrement.Width * sinx + (encombrement.Height) * cosx);
                            texte_epaisseur.Transform(trans);
                            texte_epaisseur.CloseFigure();

                            page.FillPath(brosse_texte, texte_epaisseur);
                        }
                    }
                    epaisseur.Dispose();
                    texte_epaisseur.Dispose();
                }
            }

            /*        for (i = 0; i < projet.reseaux[nproj].nodes.Count; i++)
             *  {
             *      if (projet.reseaux[nproj].nodes[i].i != 0)
             *      {
             *          //page.DrawRectangle(stylo, 0f, 0f, 200, 200);
             *          //MessageBox.Show(((res.nodes[i].x - res.xl) * delta).ToString() + " " + ((res.yu - res.nodes[i].y) * delta).ToString()+" "+w.ToString()+" "+h.ToString());
             *          page.FillRectangle(brosse, (res.nodes[i].x - res.xl) * delta, (res.yu - res.nodes[i].y) * delta, 30f, 20f);
             *          page.DrawRectangle(stylo, (res.nodes[i].x - res.xl) * delta, (res.yu - res.nodes[i].y) * delta, 30f, 20f);
             *          page.DrawString(res.nodes[i].i.ToString(), fonte, Brushes.Black, new RectangleF((res.nodes[i].x - res.xl) * delta, (res.yu - res.nodes[i].y) * delta, 30f, 20f));
             *      }
             *  }*/
        }
示例#24
0
        private void ShowOSD(string message)
        {
            if (this.osdDelayTask != null)
            {
                this.osdDelayTask.CancelAsync();
            }

            lock (this.osdLock)
            {
                if (this.osdMessage != null)
                {
                    this.osdMessage.Dispose();
                    this.osdMessage = null;
                }

                var ff = new FontFamily("Microsoft YaHei UI");
                var f  = new Font(ff, 24, FontStyle.Regular, GraphicsUnit.Point);
                var gp = new System.Drawing.Drawing2D.GraphicsPath();
                gp.AddString(message, ff, (int)FontStyle.Regular, 18, Point.Empty, StringFormat.GenericDefault);
                var gpb = gp.GetBounds();

                Bitmap text = new Bitmap((int)gpb.Width + 10, (int)gpb.Height + 10);
                using (var tg = Graphics.FromImage(text))
                {
                    tg.SmoothingMode     = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
                    tg.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
                    tg.FillPath(Brushes.Yellow, gp);
                    tg.Dispose();
                }

                this.osdMessage = text;
            }
            this.Invoke(new Action(this.openGLControl1.DoRender));

            this.osdDelayTask = new BackgroundWorker();
            this.osdDelayTask.WorkerSupportsCancellation = true;
            this.osdDelayTask.DoWork += (sender, e) =>
            {
                Thread.Sleep(this.osdDelay);
                if (((BackgroundWorker)sender).CancellationPending)
                {
                    e.Cancel = true;
                    return;
                }
            };
            this.osdDelayTask.RunWorkerCompleted += (sender, e) =>
            {
                if (e.Cancelled)
                {
                    return;
                }
                lock (this.osdLock)
                {
                    if (this.osdMessage != null)
                    {
                        this.osdMessage.Dispose();
                        this.osdMessage = null;
                    }
                }
                this.Invoke(new Action(this.openGLControl1.DoRender));
            };
            this.osdDelayTask.RunWorkerAsync();
        }
示例#25
0
文件: Carte.cs 项目: crocovert/musliw
        private void Carte_Paint(object sender, PaintEventArgs e)
        {
            int i;
            double w, h;
            //projet = ((Musliw.MusliW)(this.MdiParent)).projet;
            Graphics page = e.Graphics;

            //page.Clear(this.BackColor);

            w = this.Width;
            h = this.Height;

            Pen stylo = new Pen(fen.stylo_couleur, (int)fen.epaisseur);
            Font fonte = new Font(FontFamily.GenericSansSerif, 7,FontStyle.Bold);
            this.ForeColor = Color.Black;
            Brush brosse =new SolidBrush(fen.brosse_couleur);
            Brush brosse_texte = new SolidBrush(fen.couleur_texte);
            double dx = w / (projet.reseaux[nproj].xu - projet.reseaux[nproj].xl);
            double dy = h / (projet.reseaux[nproj].yu - projet.reseaux[nproj].yl);
            double deltax,deltay,voldeltax,voldeltay;
            double cx = 0.5f * (projet.reseaux[nproj].xu + projet.reseaux[nproj].xl);
            double cy = 0.5f * (projet.reseaux[nproj].yu + projet.reseaux[nproj].yl);

            //MessageBox.Show(xl.ToString() + " " + yu.ToString());
            PointF p1=new PointF();
            PointF p2 = new PointF();
            PointF p3 = new PointF();
            PointF p4 = new PointF();
            PointF p5 = new PointF();

            PointF[] points = new PointF[4] ;
               double angle=0,norme=0;
            double sinx = 0, cosx = 1;
            if (fen.volume_echelle < 1e-6f)
            {
                fen.volume_echelle = 1e-6f;
            }
            for (i = 0; i < projet.reseaux[nproj].links.Count; i++)
            {
                norme = fen.norme(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, fen.ecart + 0.5f * fen.epaisseur);
                if ((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].is_visible == true && projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].is_visible == true && norme > 0) && (projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].is_valid == true && projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].is_valid == true))
                {

                    //page.DrawRectangle(stylo, 0f, 0f, 200, 200);
                    //MessageBox.Show(((res.nodes[i].x - res.xl) * delta).ToString() + " " + ((res.yu - res.nodes[i].y) * delta).ToString()+" "+w.ToString()+" "+h.ToString());
                deltax = fen.deltax(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, fen.ecart+0.5f*fen.epaisseur);
                deltay = fen.deltay(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, fen.ecart+0.5f*fen.epaisseur);
                cosx = fen.deltax(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, 1);
                sinx = fen.deltay(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, 1);

                    voldeltax = fen.deltax(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, fen.ecart + 0.5f * fen.epaisseur + projet.reseaux[projet.reseau_actif].links[i].volau / fen.volume_echelle);
                    voldeltay = fen.deltay(projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y, projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y, fen.ecart + 0.5f * fen.epaisseur + projet.reseaux[projet.reseau_actif].links[i].volau / fen.volume_echelle);
                    page.DrawLine(stylo, (float)(((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x - fen.xl) / fen.echelle) + deltay), (float)(((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y) / fen.echelle) + deltax),(float) (((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x - fen.xl) / fen.echelle) + deltay),(float) (((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y) / fen.echelle) + deltax));

                    p1.X = (float)(((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x - fen.xl) / fen.echelle) + deltay);
                    p1.Y = (float)(((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y) / fen.echelle) + deltax);
                    p2.X = (float)(((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].x - fen.xl) / fen.echelle) + voldeltay);
                    p2.Y = (float)(((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].no].y) / fen.echelle) + voldeltax);
                    p3.X = (float)(((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x - fen.xl) / fen.echelle) + voldeltay);
                    p3.Y = (float)(((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y) / fen.echelle) + voldeltax);
                    p4.X = (float)(((projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].x - fen.xl) / fen.echelle) + deltay);
                    p4.Y = (float)(((fen.yu - projet.reseaux[nproj].nodes[projet.reseaux[nproj].links[i].nd].y) / fen.echelle) + deltax);

                    System.Drawing.Drawing2D.GraphicsPath epaisseur = new System.Drawing.Drawing2D.GraphicsPath();
                    System.Drawing.Drawing2D.GraphicsPath texte_epaisseur = new System.Drawing.Drawing2D.GraphicsPath();
                    epaisseur.StartFigure();
                    points[0] = p1;
                    points[1] = p2;
                    points[2] = p3;
                    points[3] = p4;

                    epaisseur.AddPolygon(points);
                    epaisseur.CloseFigure();
                    //page.FillPath(brosse, epaisseur);
                    //page.FillPolygon(brosse, points);
                    //page.DrawPolygon(stylo,points);
                    epaisseur.Reset();
                    texte_epaisseur.StartFigure();
                    p5.X = 0.5f * (p3.X + p2.X);
                    p5.Y = 0.5f * (p3.Y + p2.Y);
                    texte_epaisseur.AddString(projet.reseaux[projet.reseau_actif].links[i].volau.ToString("0"), FontFamily.GenericSansSerif, 0, (float)fen.taille_texte, new PointF(p5.X, p5.Y), StringFormat.GenericDefault);
                    RectangleF encombrement = texte_epaisseur.GetBounds();
                    // texte_epaisseur.AddRectangle(encombrement);
                    //texte_epaisseur.AddPie(p5.X,p5.Y,2,2,0,360);

                    page.FillPolygon(brosse, points);
                    page.DrawPolygon(stylo, points);

                    if (encombrement.Width < fen.norme(p1.X, p4.X, p1.Y, p4.Y, 1) && projet.reseaux[projet.reseau_actif].links[i].volau > 0)
                    {
                        System.Drawing.Drawing2D.Matrix rotation = new System.Drawing.Drawing2D.Matrix();

                        if (cosx >= 0 && sinx <= 0)
                        {
                            angle = 180f * ((float)Math.Acos(cosx) / (float)Math.PI);
                            rotation.RotateAt((float)angle, p5);
                            rotation.Translate(p5.X - encombrement.X, p5.Y - encombrement.Y);
                            System.Drawing.Drawing2D.Matrix trans = new System.Drawing.Drawing2D.Matrix();
                            texte_epaisseur.Transform(rotation);
                            trans.Translate((float)(-0.5f * encombrement.Width * cosx),(float)( 0.5f * encombrement.Width * sinx));
                            texte_epaisseur.Transform(trans);
                            texte_epaisseur.CloseFigure();
                            page.FillPath(brosse_texte, texte_epaisseur);

                        }
                        else if (cosx <= 0 && sinx >= 0)
                        {
                            angle = 180f - 180f * ((float)Math.Acos(cosx) / (float)Math.PI);
                            rotation.RotateAt((float)angle, p5);
                            rotation.Translate(p5.X - encombrement.X, p5.Y - encombrement.Y);
                            System.Drawing.Drawing2D.Matrix trans = new System.Drawing.Drawing2D.Matrix();
                            texte_epaisseur.Transform(rotation);
                            trans.Translate((float)(+0.5f * encombrement.Width * cosx + (encombrement.Height) * sinx),(float)( -0.5f * encombrement.Width * sinx + (encombrement.Height) * cosx));
                            texte_epaisseur.Transform(trans);
                            texte_epaisseur.CloseFigure();

                            page.FillPath(brosse_texte, texte_epaisseur);

                        }
                        else if (cosx >= 0 && sinx >= 0)
                        {
                            angle = -180f * (float)Math.Acos(cosx) / (float)Math.PI;
                            rotation.RotateAt((float)angle, p5);
                            rotation.Translate(p5.X - encombrement.X, p5.Y - encombrement.Y);
                            System.Drawing.Drawing2D.Matrix trans = new System.Drawing.Drawing2D.Matrix();
                            texte_epaisseur.Transform(rotation);
                            trans.Translate((float)(-0.5f * encombrement.Width * cosx),(float)( 0.5f * encombrement.Width * sinx));
                            texte_epaisseur.Transform(trans);
                            texte_epaisseur.CloseFigure();

                            page.FillPath(brosse_texte, texte_epaisseur);
                        }
                        else if (cosx <= 0 && sinx <= 0)
                        {
                            angle = 180 + 180f * ((float)Math.Acos(cosx) / (float)Math.PI);
                            rotation.RotateAt((float)angle, p5);
                            rotation.Translate(p5.X - encombrement.X, p5.Y - encombrement.Y);
                            System.Drawing.Drawing2D.Matrix trans = new System.Drawing.Drawing2D.Matrix();
                            texte_epaisseur.Transform(rotation);
                            trans.Translate((float)(+0.5f * encombrement.Width * cosx + (encombrement.Height) * sinx),(float)( -0.5f * encombrement.Width * sinx + (encombrement.Height) * cosx));
                            texte_epaisseur.Transform(trans);
                            texte_epaisseur.CloseFigure();

                            page.FillPath(brosse_texte, texte_epaisseur);
                        }

                    }
                    epaisseur.Dispose();
                    texte_epaisseur.Dispose();
                }

            }
            /*        for (i = 0; i < projet.reseaux[nproj].nodes.Count; i++)
            {
                if (projet.reseaux[nproj].nodes[i].i != 0)
                {
                    //page.DrawRectangle(stylo, 0f, 0f, 200, 200);
                    //MessageBox.Show(((res.nodes[i].x - res.xl) * delta).ToString() + " " + ((res.yu - res.nodes[i].y) * delta).ToString()+" "+w.ToString()+" "+h.ToString());
                    page.FillRectangle(brosse, (res.nodes[i].x - res.xl) * delta, (res.yu - res.nodes[i].y) * delta, 30f, 20f);
                    page.DrawRectangle(stylo, (res.nodes[i].x - res.xl) * delta, (res.yu - res.nodes[i].y) * delta, 30f, 20f);
                    page.DrawString(res.nodes[i].i.ToString(), fonte, Brushes.Black, new RectangleF((res.nodes[i].x - res.xl) * delta, (res.yu - res.nodes[i].y) * delta, 30f, 20f));
                }
            }*/
        }
示例#26
0
        public CanvasRectangleF GetBounds()
        {
            var rectangleF = _path.GetBounds();

            return(new CanvasRectangleF(rectangleF.X, rectangleF.Y, rectangleF.Width, rectangleF.Height));
        }
示例#27
0
        public void Update(bool recalculateTextBounds)
        {
            if (_path != null)
            {
                _path.Dispose();
            }

            if (_boundsPath != null)
            {
                _boundsPath.Dispose();
            }

            _format.FormatFlags |= System.Drawing.StringFormatFlags.LineLimit;
            _path = new System.Drawing.Drawing2D.GraphicsPath();

            if (recalculateTextBounds)
            {
                System.Drawing.PointF origin = System.Drawing.PointF.Empty;
                switch (_format.Alignment)
                {
                case System.Drawing.StringAlignment.Far:
                    origin.X = _textArea.Right;
                    break;

                case System.Drawing.StringAlignment.Center:
                    origin.X = _textArea.Left + _textArea.Width / 2;
                    break;

                case System.Drawing.StringAlignment.Near:
                    origin.X = _textArea.Left;
                    break;

                default:
                    throw new Aurigma.GraphicsMill.UnexpectedException();
                }

                switch (_format.LineAlignment)
                {
                case System.Drawing.StringAlignment.Far:
                    origin.Y = TextArea.Bottom;
                    break;

                case System.Drawing.StringAlignment.Center:
                    origin.Y = _textArea.Top + _textArea.Height / 2;
                    break;

                case System.Drawing.StringAlignment.Near:
                    origin.Y = _textArea.Top;
                    break;

                default:
                    throw new Aurigma.GraphicsMill.UnexpectedException();
                }

                _path.AddString(_text, _font.FontFamily, (int)_font.Style, _font.Size, origin, _format);
                UpdateTextArea(origin);
            }
            else
            {
                _path.AddString(_text, _font.FontFamily, (int)_font.Style, _font.Size, _textArea, _format);

                System.Drawing.RectangleF stringBounds = _path.GetBounds();
            }

            _boundsPath = new System.Drawing.Drawing2D.GraphicsPath();
            _boundsPath.AddRectangle(_textArea);

            base.Update();
        }