Exemplo n.º 1
0
        public SvgButtonWidget(string label)
            : base(label)
        {
            Background.MouseOver += Background_MouseOver;
            Background.MouseOut += Background_MouseOut;
            Background.MouseDown += Background_MouseDown;

            FLabel = new SvgText(label);
            FLabel.FontSize = 12;
            FLabel.X = 2;
            FLabel.Y = FLabel.FontSize + 2;
            FLabel.CustomAttributes["class"] = "menufont";

            Children.Add(FLabel);
        }
Exemplo n.º 2
0
        public void TestRenderCustomFont()
        {
            var builder = new SvgBuilder();

            builder.FontFamilyLookup += TestRenderCustomFont_FontFamilyLookup;
            var doc = new SvgDocument {
                SvgBuilder = builder
            };
            var text = new SvgText("Hello World")
            {
                SvgBuilder = builder
            };

            doc.Children.Add(text);
            text.Font     = NASALIZA;
            text.FontSize = new SvgUnit(22);
            text.Y        = new SvgUnit(100);
            Assert.AreEqual(text.Font, NASALIZA);
            SaveBitmap(doc.Draw(), "TestRenderCustomFont.png");
        }
 public double MeasureWidth(string s, GraphicsContext context, DeviceDescription description)
 {
     var svgContext = _mapper.MapGraphicsContextToSvg(context);
     var text = new SvgText
     {
         FontFamily = svgContext.Font.Family,
         FontSize = svgContext.Font.Size,
         FontWeight = svgContext.Font.Weight,
         Text = s,
         TextAnchor = svgContext.TextAnchor,
         X = createUnitCollection(0f),
         Y = createUnitCollection(0f),
     };
     return text.Bounds.Width;
 }
Exemplo n.º 4
0
        /// <summary>
        /// Renders the specified <see cref="HeatMapModel"/>, optionally saves the output SVG
        /// </summary>
        /// <param name="model">The model.</param>
        /// <param name="filePath">The file path.</param>
        /// <returns></returns>
        public Svg.SvgDocument Render(HeatMapModel model, String filePath = "")
        {
            rangeFinder valueRange = model.DetectMinMax();

            var lColor = style.LowColor.GetColorVersionWithAlpha(style.MinOpacity);  //.ColorToHex();
            var hColor = style.HighColor.GetColorVersionWithAlpha(style.MaxOpacity); //.ColorToHex();



            ColorGradient colorGradient = new ColorGradient(lColor, hColor, ColorGradientFunction.AllAToB);


            cursorZoneSpatialSettings format = style.fieldContainer.GetFormatSetup();

            format.spatialUnit       = 8;
            format.spatialUnitHeight = 10;

            Int32 width  = (model.weight * format.width) + format.margin.right;
            Int32 height = (model.height * format.height) + format.margin.bottom;

            Svg.SvgDocument output = new Svg.SvgDocument
            {
                Width  = width,
                Height = height,
                Ppi    = 100
            };

            var mainContainer = new SvgGroup();

            output.Children.Add(mainContainer);

            //(new SvgLength(width), new SvgLength(height));

            // output.ViewBox = new SvgViewBox(-100, -100, width+100, height+100);

            var group = new SvgGroup();

            mainContainer.Children.Add(group);

            var layerTwo = new SvgGroup();

            mainContainer.Children.Add(layerTwo);

            prepareLabels(model);

            var hor = new SvgGroup();

            if (style.options.HasFlag(HeatMapRenderOptions.addHorizontalLabels))
            {
                layerTwo.Children.Add(hor);
            }

            for (int x = 0; x < model.weight; x++)
            {
                Int32 xStart = x * format.width;

                Svg.SvgText label = xLabels[x].GetSvgText(format, x, -1);

                //Svg.SvgText label = new SvgText(xLabels[x])
                //{
                //    X = (xStart + (format.width / 2) - format.margin.right).Get_px(),
                //    Y = (-format.height / 2).Get_px(),
                //    Color = new SvgColourServer(Color.Black),
                //    Font = "Gulliver"

                //};

                hor.Children.Add(label);

                var vert = new SvgGroup();
                layerTwo.Children.Add(vert);

                var vertLabels = new SvgGroup();
                var vertValues = new SvgGroup();
                var vertScale  = new SvgGroup();

                if (style.options.HasFlag(HeatMapRenderOptions.addVerticalLabels))
                {
                    vert.Children.Add(vertLabels);
                }
                if (style.options.HasFlag(HeatMapRenderOptions.addVerticalValueScale))
                {
                    vert.Children.Add(vertScale);
                }
                if (style.options.HasFlag(HeatMapRenderOptions.addVerticalValueScale))
                {
                    vert.Children.Add(vertValues);
                }

                for (int y = 0; y < model.height; y++)
                {
                    Int32 yStart = y * format.height;

                    if (x == 0)
                    {
                        Double ratio        = valueRange.GetPositionInRange(y); //model.GetRatioForScale(y, style.minimalOpacity, model.height); //(1+ style.minimalOpacity).GetRatio(y+1);
                        Double scaleFactor2 = ratio;
                        if (!style.options.HasFlag(HeatMapRenderOptions.resizeFields))
                        {
                            scaleFactor2 = 1;
                        }

                        if (ratio > 1)
                        {
                            ratio = 1;
                        }
                        var lbl2 = format.GetRectangle((-format.width * 2), yStart, colorGradient.GetColor(ratio), Convert.ToSingle(ratio), scaleFactor2);
                        vertScale.Children.Add(lbl2);

                        Svg.SvgText label2 = yLabels[y].GetSvgText(format, -1, y);
                        vertLabels.Children.Add(label2);

                        //Svg.SvgText label = xLabels[x].GetSvgText(format, x, -1);

                        //Svg.SvgText label2 = new SvgText(yLabels[y])
                        //{
                        //    X = (format.margin.left - format.width).Get_px(),
                        //    Y = (yStart+(format.height / 2)).Get_px(),
                        //    Color = new SvgColourServer(Color.Black),

                        //    Font = "Gulliver"
                        //};

                        Int32 xp = Convert.ToInt32((-Convert.ToDouble(format.width) * 2.5) + format.margin.left);

                        //Double vl = (1.GetRatio(y + 1)) * model.ranger.Maximum;

                        Double vl = model.GetValueForScaleY(y);

                        Svg.SvgText value = vl.ToString(style.valueFormat).GetSvgText(format, -3, y);

                        //Svg.SvgText value = new SvgText()
                        //{
                        //    X = (xp- format.margin.right).Get_px(),
                        //    Y = (yStart + (format.height / 2) ).Get_px(),
                        //    Fill = new SvgColourServer(Color.Black),
                        //   // Color = new SvgColourServer(Color.White),
                        //    Font = "Gulliver"
                        //};

                        vertValues.Children.Add(value);
                    }

                    Double val  = valueRange.GetPositionInRange(model[x, y]); // model.GetRatioValue(x, y, style.minimalOpacity);
                    Color  valC = colorGradient.GetColor(val);


                    Double scaleFactor = val;

                    if (!style.options.HasFlag(HeatMapRenderOptions.resizeFields))
                    {
                        scaleFactor = 1;
                    }
                    var rct = format.GetRectangle(xStart, yStart, valC, Convert.ToSingle(val), scaleFactor);

                    group.Children.Add(rct);
                }
            }

            if (!filePath.isNullOrEmpty())
            {
                if (!filePath.EndsWith(".svg", true, CultureInfo.CurrentCulture))
                {
                    filePath += ".svg";
                }


                output.Save(filePath);

                //  throw new NotImplementedException();

                /* var code = output.GetXML();  //Encoding.UTF8.GetString(stream.GetBuffer());
                 *
                 */
            }

            return(output);
        }
Exemplo n.º 5
0
        public RulerView(TLRuler ruler, TimelineView tv)
            : base(ruler, tv)
        {
            Model = ruler;
            Parent = tv;

            PanZoomMatrix = new SvgMatrix(FView.Elements.ToList());

            MainGroup.Transforms = new SvgTransformCollection();
            MainGroup.Transforms.Add(new SvgTranslate(0, 0));

            var width = new SvgUnit(SvgUnitType.Percentage, 100);

            Background.Width = width;
            Background.Height = 25;
            Background.ID = "bg";
            Background.CustomAttributes["class"] = "ruler";

            //register event handlers
            Background.MouseDown += Background_MouseDown;
            Background.MouseUp += Background_MouseUp;
            Background.MouseMove += Background_MouseMove;

            var caller = Parent.Document.Mapper.Map<ISvgEventCaller>();
            PlayButton = SvgDocumentWidget.Load(Path.Combine(TimelineView.ResourcePath, "PlayButton.svg"), caller, 2);
            StopButton = SvgDocumentWidget.Load(Path.Combine(TimelineView.ResourcePath, "StopButton.svg"), caller, 1);
            StopButton.X = 25;

            PlayButton.Click += PlayButton_Click;
            StopButton.Click += StopButton_Click;

            TimeCodeLabelBackground.Width = CLeftOffset;
            TimeCodeLabelBackground.Height = Background.Height;
            TimeCodeLabelBackground.CustomAttributes["class"] = "ruler";
            TimeCodeLabelBackground.MouseDown += Background_MouseDown;

            TimeCodeLabel.FontSize = 20;
            TimeCodeLabel.X = 55;
            TimeCodeLabel.Y = TimeCodeLabel.FontSize;
            TimeCodeLabel.CustomAttributes["class"] = "time";
            TimeCodeLabel.ID = Model.GetID() + "_label";
            TimeCodeLabel.Text = "00:00:00:000";
            TimeCodeLabel.CustomAttributes["class"] = "time";
            TimeCodeLabel.MouseDown += Background_MouseDown;

            SizeBar.Width = Background.Width;
            SizeBar.Height = 10;
            SizeBar.ID = "SizeBar";
            SizeBar.Y = Background.Height;
            SizeBar.MouseDown += Background_MouseDown;
            SizeBar.MouseMove += Background_MouseMove;
            SizeBar.MouseUp += Background_MouseUp;

            MouseTimeLabel.ID = "MouseTimeLabel";
            MouseTimeLabel.Y = Height;
            MouseTimeLabel.FontSize = 14;

            ClipRect.Width = width;
            ClipRect.Height = Height;
            ClipRect.ID = "ClipRect";

            //document roots id is "svg". this is where the trackclips are added to
            RulerClipPath.ID = "svg_clip" + IDGenerator.NewID;
            RulerClipPath.Children.Add(ClipRect);

            var uri = new Uri("url(#" + RulerClipPath.ID + ")", UriKind.Relative);
            MainGroup.ClipPath = uri;

            NumberGroup.ID = "Ticks";
            NumberGroup.Transforms = new SvgTransformCollection();
            NumberGroup.Transforms.Add(PanZoomMatrix);

            PanZoomGroup.ID = "PanZoom";
            PanZoomGroup.Transforms = new SvgTransformCollection();
            PanZoomGroup.Transforms.Add(PanZoomMatrix);

            for (int i=0; i<70; i++)
            {
                var num = new SvgText(i.ToString());
                num.FontSize = 20;
                num.Y = num.FontSize;
                num.CustomAttributes["class"] = "time hair";
                num.Transforms = new SvgTransformCollection();
                num.Transforms.Add(new SvgTranslate(i));
                num.Transforms.Add(new SvgScale(1/Timer.PPS, 1));
                NumberGroup.Children.Add(num);
            }

            LoopRegion.ID = "LoopRegion";
            LoopRegion.Y = Background.Height / 4;
            LoopRegion.Height = Background.Height / 2;
            LoopRegion.FillOpacity = 0.7f;
            LoopRegion.CustomAttributes["pointer-events"] = "fill";
            LoopRegion.CustomAttributes["class"] = "loop";
            LoopRegion.MouseDown += Background_MouseDown;
            LoopRegion.MouseUp += Parent.Default_MouseUp;
            LoopRegion.MouseMove += Parent.Default_MouseMove;
            PanZoomGroup.Children.Add(LoopRegion);

            LoopStart.ID = "LoopStart";
            LoopStart.Width = 1/Timer.PPS * CHandlerWidth;
            LoopStart.Height = Background.Height;
            PanZoomGroup.Children.Add(LoopStart);
            LoopStart.MouseDown += Background_MouseDown;
            LoopStart.MouseUp += Parent.Default_MouseUp;
            LoopStart.MouseMove += Parent.Default_MouseMove;
            LoopStart.CustomAttributes["pointer-events"] = "fill";
            LoopStart.CustomAttributes["class"] = "loopcap";

            LoopEnd.ID = "LoopEnd";
            LoopEnd.Width = 1/Timer.PPS * CHandlerWidth;
            LoopEnd.Height = Background.Height;
            PanZoomGroup.Children.Add(LoopEnd);
            LoopEnd.MouseDown += Background_MouseDown;
            LoopEnd.MouseUp += Parent.Default_MouseUp;
            LoopEnd.MouseMove += Parent.Default_MouseMove;
            LoopEnd.CustomAttributes["pointer-events"] = "fill";
            LoopEnd.CustomAttributes["class"] = "loopcap";

            CreateMenu();

            //init scalings
            PanZoom(0, 0, 0);
            UpdateScene();
        }