コード例 #1
0
ファイル: Painter.cs プロジェクト: ventor3000/guppy2
        private Transform2d GetTextPositionTransform(GFNFont fnt, string txt, double x, double y, double size, double angle, TextAlign align, Transform2d t)
        {
            //computes the transformation needed to transform text drawn at origo to get to the wanted position
            Transform2d res = Transform2d.Translate(x, y);

            if (angle != 0.0)
            {
                res = Transform2d.Rotate(angle) * res;
            }

            if (align != TextAlign.BaseLeft)
            {
                double dx, dy;
                GetTextAlignDXDY(fnt, txt, size, align, out dx, out dy);
                res = Transform2d.Translate(dx, dy) * res;
            }

            res = Transform2d.Scale(size / fnt.CapHeight) * res;

            if (t != null)
            {
                return(res * t);
            }
            return(res);
        }
コード例 #2
0
ファイル: GFNFont.cs プロジェクト: ventor3000/guppy2
        public GFXPath GetTextPath(string txt, Transform2d transform)
        {
            GFNGlyph glyph;



            if (txt == null)
            {
                return(null);
            }


            GFXPath res = new GFXPath();

            foreach (char ch in txt)
            {
                if (CharLUT.TryGetValue(ch, out glyph))
                {
                    GFXPath glyphpath = glyph.Path.TransformCopy(transform);
                    res.AppendPath(glyphpath);
                    transform = Transform2d.Translate(glyph.DX, 0.0) * transform;    //move to next character
                }
            }

            return(res);
        }
コード例 #3
0
ファイル: GFNFont.cs プロジェクト: ventor3000/guppy2
        public void DrawString(Painter painter, string txt, Transform2d xform)
        {
            /*double scale = txtsize / capheight;
             * Transform2 tr = Transform2.Scale(scale)*Transform2.Translate(align_dx,align_dy)*Transform2.Rotate(angle)*Transform2.Translate(x, y);
             *
             * var oldt = painter.Transform;
             * painter.Transform = tr * painter.Transform;*/

            foreach (char ch in txt)
            {
                double dx = DrawGlyphT(ch, painter);
                painter.Transform = Transform2d.Translate(dx, 0.0) * painter.Transform;
            }

            //painter.Transform = oldt;
        }
コード例 #4
0
        void OnDrawAreaWheel(object sender, WheelEventArgs e)
        {
            Drawing drw = CurrentDrawing;

            if (drw != null)
            {
                double scale;
                if (e.Delta < 0)
                {
                    scale = 0.8;
                }
                else
                {
                    scale = 1.0 / 0.8;
                }

                drw.ViewTransform = drw.ViewTransform * Transform2d.Translate(-cursorpixel.X, -cursorpixel.Y) * Transform2d.Scale(scale) * Transform2d.Translate(cursorpixel.X, cursorpixel.Y);

                drawarea.Redraw();
            }
        }
コード例 #5
0
        void OnDrawAreaMotion(object sender, MotionEventArgs e)
        {
            Drawing drw = CurrentDrawing;

            if (drw != null)
            {
                var size = drawarea.PhysicalSize;
                drawarea.Focused = true; //need focus for accepting wheel events

                var    newcursorpixel = new Point2i(e.X, size.Height - e.Y - 1);
                double dx             = newcursorpixel.X - cursorpixel.X;
                double dy             = newcursorpixel.Y - cursorpixel.Y;
                cursorpixel = newcursorpixel;

                if (e.Status.HasFlag(KeyStatus.MiddleButton))
                {
                    drw.ViewTransform = drw.ViewTransform * Transform2d.Translate(dx, dy);
                    drawarea.Redraw();
                    return;
                }


                RedrawOverlay();
            }
            else
            {
                trackingpos = null;
            }



            // w.Caption = viewtransform.ToString(); // pt.ToString() + "    " + e.Status.ToString();

            //Caption = e.X.ToString();
            SetCoordText();
        }
コード例 #6
0
ファイル: GeomUtil.cs プロジェクト: ventor3000/guppy2
        public static void EllipticArcToBeziers(double cx, double cy, double aradius, double bradius, double tilt, double startangle, double sweepangle, List <double> xy)
        {
            int cnt = xy.Count;

            double startpar = EllipseAngleToParam(startangle, aradius, bradius);
            double endpar   = EllipseAngleToParam(startangle + sweepangle, aradius, bradius);


            if (sweepangle >= MathUtil.Deg360)
            { //full ellipse
                endpar = startpar + MathUtil.Deg360;
            }
            else if (sweepangle <= -MathUtil.Deg360)
            {
                endpar = startpar - MathUtil.Deg360;
            }
            else if (sweepangle > 0.0) //ccw
            {
                if (endpar <= startpar)
                {
                    endpar += MathUtil.Deg360;
                }
            }
            else //cw
            {
                if (endpar >= startpar)
                {
                    endpar -= MathUtil.Deg360;
                }
            }
            double sweepparam = endpar - startpar;
            double bulge      = GetArcBulgeFromSweepAngle(sweepparam);

            ArcToBeziers(Math.Cos(startpar), Math.Sin(startpar), Math.Cos(endpar), Math.Sin(endpar), bulge, xy);

            //transform bezier circular arc to elliptical arc
            Transform2d tr = Transform2d.Stretch(aradius, bradius) * Transform2d.Rotate(tilt) * Transform2d.Translate(cx, cy);

            for (int l = cnt; l < xy.Count; l += 2)
            {
                double tx, ty;
                tr.Apply(xy[l], xy[l + 1], out tx, out ty, true);
                xy[l]     = tx;
                xy[l + 1] = ty;
            }
        }