XML Elves

XML Elves

<community>of XML and SVG Developers</community>


Help with Cropping in svg...

This is a discussion on Help with Cropping in svg... within the SVG Questions forums, part of the SVG Forums category; Thought I'd post an update and the solution I found in case others may be interested, and to help the ...


Go Back   XML Elves > SVG Forums > SVG Questions

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read



Click here to register

 

 

LinkBack Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2 (permalink)  
Old 02-04-2010, 01:53 PM
Junior Member
 
Join Date: Feb 2010
Posts: 2
Default

Thought I'd post an update and the solution I found in case others may be interested, and to help the board be useful.

I'm sure there is a more elegant solution that a more seasoned XMLmn might know, but this worked to educate me a bit.

So, to keep my image from scaling, the x, y, width, height in the svg tag needed to remain, as did the viewbox. That is, I wanted my finished product 180x80, even though the actual content is 252x144. So the start of my svg tag looked like:
Code:
<svg x="0pt" y="0pt" width="180pt" height="80pt" viewBox="0 0 180 80"...
It should have been obvious, but after messing around with these values, and the transform in my g tag, and adding clippaths etc, it got very confusing.

In the end, the size, viewbox, and transform were the answer.

This code:
Code:
<svg x="0pt" y="0pt" width="252pt" height="144pt" viewBox="0 0 252 144" preserveAspectRatio="xMidYMid" xml:space="preserve" xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
  <g transform="matrix(1 0 0 1 0 0)"> 
	<rect x="0" y="0" width="252" height="144" style="fill:red;stroke:black;stroke-width:5;opacity:0.5"/>  
	<rect x="10" y="10" width="180" height="80" style="fill:blue"/>
	<rect x="20" y="20" width="160" height="60" style="fill:white"/>			
	<rect x="30" y="30" width="140" height="40" style="fill:purple"/>			
	<rect x="40" y="40" width="120" height="20" style="fill:yellow"/>
	<rect x="50" y="50" width="100" height="1" style="fill:black"/>
</g>  
</svg>
produces this:


and this code:
Code:
<svg x="0pt" y="0pt" width="180pt" height="80pt" viewBox="0 0 180 80" preserveAspectRatio="xMidYMid" xml:space="preserve" xmlns:xml="http://www.w3.org/XML/1998/namespace" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
  
  
  <g transform="matrix(1 0 0 1 -10 -10)" onload="replaceText();"> 
  
<rect x="0" y="0" width="252" height="144" style="fill:red;stroke:black;stroke-width:5;opacity:0.5"/>  
<rect x="10" y="10" width="180" height="80" style="fill:blue"/>
<rect x="20" y="20" width="160" height="60" style="fill:white"/>			
<rect x="30" y="30" width="140" height="40" style="fill:purple"/>			
<rect x="40" y="40" width="120" height="20" style="fill:yellow"/>
<rect x="50" y="50" width="100" height="1" style="fill:black"/>
  
  </g>  
</svg>
produces this, which is just what I want.



In the end, the only data that will change dynamically will be the two values in the transform matrix. Easy enough to do with some ecmascript, but that won't work for me. I send this svg through some internal code that converts it to a PDF and it doesn't handle the script right. So, I'll back up and change the value in my java code as I build the svg. I know you didn't care about that last part, but since it was the basis of my orig. question I thought I'd put it out there.

PS...don't mind the "pass" text in there. It was part of my ecmascript test, which I removed in the code above.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
 

Tags
cropping, svg


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On





All times are GMT -6. The time now is 05:06 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.5.0 RC3

Data recovery laptop
Need Data Recovery from your Laptop? Data Clinic have all your solutions!


1 2 3 4 5 6 7 8 9 10 11 12 13 14