Exemple #1
0
		void DrawGraphic ()
		{
			var c = new GraphicCanvas (size, textPlatform);
			if (func != null)
				func (c);
			graphic = c.Graphic;
		}
Exemple #2
0
 void DrawGraphic()
 {
     var c = new GraphicCanvas (size);
     if (func != null)
         func (c);
     graphic = c.Graphic;
 }
Exemple #3
0
		public Graphic Clone ()
		{
			var g = new Graphic (Size, ViewBox) {
				Title = Title,
				Description = Description,
			};

			g.Children.AddRange (Children.Select (x => x.Clone ()));

			return g;
		}
Exemple #4
0
		void Read (XDocument doc)
		{
			var svg = doc.Root;
			var ns = svg.Name.Namespace;

			//
			// Find the defs (gradients)
			//
			foreach (var d in svg.Descendants ()) {
				var idA = d.Attribute ("id");
				if (idA != null) {
					defs [ReadString (idA).Trim ()] = d;
				}
			}

			//
			// Get the dimensions
			//
			var widthA = svg.Attribute ("width");
			var heightA = svg.Attribute ("height");
			var width = ReadNumber (widthA);
			var height = ReadNumber (heightA);
			var size = new Size (width, height);

			var viewBox = new Rect (size);
			var viewBoxA = svg.Attribute ("viewBox") ?? svg.Attribute ("viewPort");
			if (viewBoxA != null) {
				viewBox = ReadRectangle (viewBoxA.Value);
			}

			if (widthA != null && widthA.Value.Contains ("%")) {
				size.Width *= viewBox.Width;
			}
			if (heightA != null && heightA.Value.Contains ("%")) {
				size.Height *= viewBox.Height;
			}

			//
			// Add the elements
			//
			Graphic = new Graphic (size, viewBox);

			AddElements (Graphic.Children, svg.Elements (), null, Brushes.Black);
		}
        public static void ReplaceColors( this ISvgImageRenderer This, Graphic in_Graphic, IEnumerable<ColorPair> in_Colors  )
        {
            if( (in_Colors == null) || (in_Graphic == null) )
                return;

            if( in_Colors.Count() == 0 )
                return;

            if( in_Graphic != null )
            {
                foreach( NGraphics.Interfaces.IDrawable it in in_Graphic.Children )
                {
                    if( it is NGraphics.Models.Elements.Path )
                        ReplaceColor(it as Path, in_Colors);
                    else if( it is NGraphics.Models.Elements.Group )
                        ReplaceColor(it as Group, in_Colors);
                }
            }
        }
		public void LoadSvgFromResource ()
		{
			if (SvgAssembly == null || SvgPath == null) {
				// Can be called by OnPropertyChanged as values are initially defined.
				// Don't load anything until we are sure we have enough to do so.
				return;
			}

			var svgStream = SvgAssembly.GetManifestResourceStream (SvgPath);

			if (svgStream == null) {
				throw new Exception (string.Format ("Error retrieving {0} make sure Build Action is Embedded Resource",
					SvgPath));
			}

			var r = new SvgReader (new StreamReader (svgStream));

			LoadedGraphic = r.Graphic;
		}
		static IImage RenderSectionToImage (/*this*/ Graphic graphics, Rect sourceFrame, Rect outputFrame, double finalScale, Func<Size, double, IImageCanvas> createPlatformImageCanvas)
		{
			var originalSize = graphics.Size;
			var sectionCanvas = createPlatformImageCanvas (outputFrame.Size, finalScale);

			// Redraw into final version with any scaling between the original and the output slice.
			var sliceVerticalScale = outputFrame.Height / sourceFrame.Height;
			var sliceHorizontalScale = outputFrame.Width / sourceFrame.Width;
			// Potentially setting ViewBox size smaller to enlarge result.
			graphics.ViewBox = new Rect (sourceFrame.Position, new Size (originalSize.Width / sliceHorizontalScale, originalSize.Height / sliceVerticalScale));

			graphics.Draw (sectionCanvas);
			return sectionCanvas.GetImage ();
		}
Exemple #8
0
 public GraphicCanvas(Size size)
 {
     Graphic = new Graphic (size);
 }
Exemple #9
0
 public void Invalidate()
 {
     graphic = null;
 }
Exemple #10
0
		public SvgWriter (Graphic graphic, System.IO.TextWriter writer)
		{
			Graphic = graphic;
			w = new CodeWriter (writer, "    ");
		}
		public GraphicCanvas (Size size, IPlatform textPlatform)
		{
			states.Push (NGraphics.Transform.Identity);
			TextPlatform = textPlatform;
			Graphic = new Graphic (size);
		}
Exemple #12
0
 public GraphicCanvas(Size size, IPlatform textPlatform)
 {
     states.Push(NGraphics.Transform.Identity);
     TextPlatform = textPlatform;
     Graphic      = new Graphic(size);
 }