←Select platform

ClipBounds Property

Summary
Gets or sets the clipping rectangle, in pixel coordinates.
Syntax
C#
Objective-C
C++/CLI
Java
Python
public LeadRectD ClipBounds { get; set; } 
@property (nonatomic, assign) LeadRectD clipBounds; 
public LeadRectD getClipBounds() 
public void setClipBounds(LeadRectD clipBounds) 
public: 
property LeadRectD ClipBounds { 
   LeadRectD get(); 
   void set (    LeadRectD ); 
} 
ClipBounds # get and set (SvgRenderOptions) 

Property Value

The clipping rectangle, in pixel coordinates. The default value is LeadRectD.Empty.

Remarks

The engine will apply this clipping into Bounds to exclude all or parts of the objects that do not fit. The transformation set in SvgRenderOptions.Transform will not be applied to this rectangle. If this value is an empty Leadtools.LeadRectD or has 0 width and 0 height, then an Empty rectangle will be used to render the entire document and no clipping performed.

Example
C#
using Leadtools; 
using Leadtools.Codecs; 
using Leadtools.Drawing; 
using Leadtools.Forms.DocumentWriters; 
using Leadtools.Svg; 
 
using Leadtools.Document.Writer; 
 
public void SvgDocumentRenderExample() 
{ 
   // Create a form with a picture box 
   Form form = new Form(); 
   PictureBox pictureBox = new PictureBox(); 
   pictureBox.Dock = DockStyle.Fill; 
   form.Controls.Add(pictureBox); 
 
   SvgDocument document = null; 
 
   // Load a page from a document file as SVG 
   string srcFileName = Path.Combine(LEAD_VARS.ImagesDir, "Leadtools.pdf"); 
   using (var codecs = new RasterCodecs()) 
   { 
      // Set 300 as the default value for loading document files 
      codecs.Options.RasterizeDocument.Load.Resolution = 300; 
 
      document = codecs.LoadSvg(srcFileName, 1, null) as SvgDocument; 
   } 
 
   // Make sure the document is valid for rendering 
   if (!document.IsFlat) 
      document.Flat(null); 
   if (!document.Bounds.IsValid) 
      document.CalculateBounds(false); 
 
   // Optimize it for rendering to increase the speed 
   document.BeginRenderOptimize(); 
   Console.WriteLine("IsRenderOptimized is " + document.IsRenderOptimized); 
 
   // This is our paint code 
   pictureBox.Paint += (sender, e) => 
   { 
      Graphics graphics = e.Graphics; 
 
      // We will fit and center this SVG document in the client area of the picture box 
      Rectangle dstBounds = pictureBox.ClientRectangle; 
      if (dstBounds.Width < 1 || dstBounds.Height < 1) 
         return; 
 
      // Create the transformation matrix 
      LeadMatrix transform = LeadMatrix.Identity; 
      LeadRectD srcBounds = document.Bounds.Bounds; 
 
      // Calculate the zoom so we can fit 
      double zoom = 1.0; 
      if (dstBounds.Width > dstBounds.Height) 
      { 
         zoom = dstBounds.Width / srcBounds.Width; 
         if ((zoom * srcBounds.Height) > dstBounds.Height) 
            zoom = dstBounds.Height / srcBounds.Height; 
      } 
      else 
      { 
         zoom = dstBounds.Height / srcBounds.Height; 
         if ((zoom * srcBounds.Width) > dstBounds.Width) 
            zoom = dstBounds.Width / srcBounds.Width; 
      } 
 
      // We have the zoom factor, set it in the transform 
      transform.Scale(zoom, zoom); 
 
      // Center 
      double xOffset = (dstBounds.Width - (zoom * srcBounds.Width)) / 2.0; 
      double yOffset = (dstBounds.Height - (zoom * srcBounds.Height)) / 2.0; 
      transform.Translate(xOffset, yOffset); 
 
      // Now setup the rendering options 
      SvgRenderOptions options = new SvgRenderOptions(); 
      // Use our transform 
      options.Transform = transform; 
      // clipping (if any) 
      options.ClipBounds = LeadRectD.Create(e.ClipRectangle.X, e.ClipRectangle.Y, e.ClipRectangle.Width, e.ClipRectangle.Height); 
      // Fill the background with a white color 
      options.UseBackgroundColor = true; 
      options.BackgroundColor = RasterColor.FromKnownColor(RasterKnownColor.White); 
      options.Bounds = srcBounds; 
 
      // Create a rendering engine 
      using (var engine = RenderingEngineFactory.Create(graphics)) 
      { 
         // Render the document 
         document.Render(engine, options); 
      } 
   }; 
 
   form.SizeChanged += (sender, e) => pictureBox.Invalidate(); 
 
   form.ShowDialog(); 
 
   document.Dispose(); 
} 
 
static class LEAD_VARS 
{ 
   public const string ImagesDir = @"C:\LEADTOOLS22\Resources\Images"; 
} 
Requirements

Target Platforms

Help Version 22.0.2023.4.20
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Svg Assembly

Products | Support | Contact Us | Intellectual Property Notices
© 1991-2023 LEAD Technologies, Inc. All Rights Reserved.