Initial Commit
This commit is contained in:
		
							
								
								
									
										4
									
								
								svgparser/parser/.htaccess
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										4
									
								
								svgparser/parser/.htaccess
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,4 @@ | ||||
| RewriteEngine On | ||||
| RewriteCond %{REQUEST_FILENAME} !-d | ||||
| RewriteCond %{REQUEST_FILENAME} !-f | ||||
| RewriteRule ^.*$ index.php | ||||
							
								
								
									
										281
									
								
								svgparser/parser/LICENSE
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										281
									
								
								svgparser/parser/LICENSE
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,281 @@ | ||||
| 		    GNU GENERAL PUBLIC LICENSE | ||||
| 		       Version 2, June 1991 | ||||
|  | ||||
|  Copyright (C) 1989, 1991 Free Software Foundation, Inc., | ||||
|  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||||
|  Everyone is permitted to copy and distribute verbatim copies | ||||
|  of this license document, but changing it is not allowed. | ||||
|  | ||||
| 			    Preamble | ||||
|  | ||||
|   The licenses for most software are designed to take away your | ||||
| freedom to share and change it.  By contrast, the GNU General Public | ||||
| License is intended to guarantee your freedom to share and change free | ||||
| software--to make sure the software is free for all its users.  This | ||||
| General Public License applies to most of the Free Software | ||||
| Foundation's software and to any other program whose authors commit to | ||||
| using it.  (Some other Free Software Foundation software is covered by | ||||
| the GNU Lesser General Public License instead.)  You can apply it to | ||||
| your programs, too. | ||||
|  | ||||
|   When we speak of free software, we are referring to freedom, not | ||||
| price.  Our General Public Licenses are designed to make sure that you | ||||
| have the freedom to distribute copies of free software (and charge for | ||||
| this service if you wish), that you receive source code or can get it | ||||
| if you want it, that you can change the software or use pieces of it | ||||
| in new free programs; and that you know you can do these things. | ||||
|  | ||||
|   To protect your rights, we need to make restrictions that forbid | ||||
| anyone to deny you these rights or to ask you to surrender the rights. | ||||
| These restrictions translate to certain responsibilities for you if you | ||||
| distribute copies of the software, or if you modify it. | ||||
|  | ||||
|   For example, if you distribute copies of such a program, whether | ||||
| gratis or for a fee, you must give the recipients all the rights that | ||||
| you have.  You must make sure that they, too, receive or can get the | ||||
| source code.  And you must show them these terms so they know their | ||||
| rights. | ||||
|  | ||||
|   We protect your rights with two steps: (1) copyright the software, and | ||||
| (2) offer you this license which gives you legal permission to copy, | ||||
| distribute and/or modify the software. | ||||
|  | ||||
|   Also, for each author's protection and ours, we want to make certain | ||||
| that everyone understands that there is no warranty for this free | ||||
| software.  If the software is modified by someone else and passed on, we | ||||
| want its recipients to know that what they have is not the original, so | ||||
| that any problems introduced by others will not reflect on the original | ||||
| authors' reputations. | ||||
|  | ||||
|   Finally, any free program is threatened constantly by software | ||||
| patents.  We wish to avoid the danger that redistributors of a free | ||||
| program will individually obtain patent licenses, in effect making the | ||||
| program proprietary.  To prevent this, we have made it clear that any | ||||
| patent must be licensed for everyone's free use or not licensed at all. | ||||
|  | ||||
|   The precise terms and conditions for copying, distribution and | ||||
| modification follow. | ||||
|  | ||||
| 		    GNU GENERAL PUBLIC LICENSE | ||||
|    TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION | ||||
|  | ||||
|   0. This License applies to any program or other work which contains | ||||
| a notice placed by the copyright holder saying it may be distributed | ||||
| under the terms of this General Public License.  The "Program", below, | ||||
| refers to any such program or work, and a "work based on the Program" | ||||
| means either the Program or any derivative work under copyright law: | ||||
| that is to say, a work containing the Program or a portion of it, | ||||
| either verbatim or with modifications and/or translated into another | ||||
| language.  (Hereinafter, translation is included without limitation in | ||||
| the term "modification".)  Each licensee is addressed as "you". | ||||
|  | ||||
| Activities other than copying, distribution and modification are not | ||||
| covered by this License; they are outside its scope.  The act of | ||||
| running the Program is not restricted, and the output from the Program | ||||
| is covered only if its contents constitute a work based on the | ||||
| Program (independent of having been made by running the Program). | ||||
| Whether that is true depends on what the Program does. | ||||
|  | ||||
|   1. You may copy and distribute verbatim copies of the Program's | ||||
| source code as you receive it, in any medium, provided that you | ||||
| conspicuously and appropriately publish on each copy an appropriate | ||||
| copyright notice and disclaimer of warranty; keep intact all the | ||||
| notices that refer to this License and to the absence of any warranty; | ||||
| and give any other recipients of the Program a copy of this License | ||||
| along with the Program. | ||||
|  | ||||
| You may charge a fee for the physical act of transferring a copy, and | ||||
| you may at your option offer warranty protection in exchange for a fee. | ||||
|  | ||||
|   2. You may modify your copy or copies of the Program or any portion | ||||
| of it, thus forming a work based on the Program, and copy and | ||||
| distribute such modifications or work under the terms of Section 1 | ||||
| above, provided that you also meet all of these conditions: | ||||
|  | ||||
|     a) You must cause the modified files to carry prominent notices | ||||
|     stating that you changed the files and the date of any change. | ||||
|  | ||||
|     b) You must cause any work that you distribute or publish, that in | ||||
|     whole or in part contains or is derived from the Program or any | ||||
|     part thereof, to be licensed as a whole at no charge to all third | ||||
|     parties under the terms of this License. | ||||
|  | ||||
|     c) If the modified program normally reads commands interactively | ||||
|     when run, you must cause it, when started running for such | ||||
|     interactive use in the most ordinary way, to print or display an | ||||
|     announcement including an appropriate copyright notice and a | ||||
|     notice that there is no warranty (or else, saying that you provide | ||||
|     a warranty) and that users may redistribute the program under | ||||
|     these conditions, and telling the user how to view a copy of this | ||||
|     License.  (Exception: if the Program itself is interactive but | ||||
|     does not normally print such an announcement, your work based on | ||||
|     the Program is not required to print an announcement.) | ||||
|  | ||||
| These requirements apply to the modified work as a whole.  If | ||||
| identifiable sections of that work are not derived from the Program, | ||||
| and can be reasonably considered independent and separate works in | ||||
| themselves, then this License, and its terms, do not apply to those | ||||
| sections when you distribute them as separate works.  But when you | ||||
| distribute the same sections as part of a whole which is a work based | ||||
| on the Program, the distribution of the whole must be on the terms of | ||||
| this License, whose permissions for other licensees extend to the | ||||
| entire whole, and thus to each and every part regardless of who wrote it. | ||||
|  | ||||
| Thus, it is not the intent of this section to claim rights or contest | ||||
| your rights to work written entirely by you; rather, the intent is to | ||||
| exercise the right to control the distribution of derivative or | ||||
| collective works based on the Program. | ||||
|  | ||||
| In addition, mere aggregation of another work not based on the Program | ||||
| with the Program (or with a work based on the Program) on a volume of | ||||
| a storage or distribution medium does not bring the other work under | ||||
| the scope of this License. | ||||
|  | ||||
|   3. You may copy and distribute the Program (or a work based on it, | ||||
| under Section 2) in object code or executable form under the terms of | ||||
| Sections 1 and 2 above provided that you also do one of the following: | ||||
|  | ||||
|     a) Accompany it with the complete corresponding machine-readable | ||||
|     source code, which must be distributed under the terms of Sections | ||||
|     1 and 2 above on a medium customarily used for software interchange; or, | ||||
|  | ||||
|     b) Accompany it with a written offer, valid for at least three | ||||
|     years, to give any third party, for a charge no more than your | ||||
|     cost of physically performing source distribution, a complete | ||||
|     machine-readable copy of the corresponding source code, to be | ||||
|     distributed under the terms of Sections 1 and 2 above on a medium | ||||
|     customarily used for software interchange; or, | ||||
|  | ||||
|     c) Accompany it with the information you received as to the offer | ||||
|     to distribute corresponding source code.  (This alternative is | ||||
|     allowed only for noncommercial distribution and only if you | ||||
|     received the program in object code or executable form with such | ||||
|     an offer, in accord with Subsection b above.) | ||||
|  | ||||
| The source code for a work means the preferred form of the work for | ||||
| making modifications to it.  For an executable work, complete source | ||||
| code means all the source code for all modules it contains, plus any | ||||
| associated interface definition files, plus the scripts used to | ||||
| control compilation and installation of the executable.  However, as a | ||||
| special exception, the source code distributed need not include | ||||
| anything that is normally distributed (in either source or binary | ||||
| form) with the major components (compiler, kernel, and so on) of the | ||||
| operating system on which the executable runs, unless that component | ||||
| itself accompanies the executable. | ||||
|  | ||||
| If distribution of executable or object code is made by offering | ||||
| access to copy from a designated place, then offering equivalent | ||||
| access to copy the source code from the same place counts as | ||||
| distribution of the source code, even though third parties are not | ||||
| compelled to copy the source along with the object code. | ||||
|  | ||||
|   4. You may not copy, modify, sublicense, or distribute the Program | ||||
| except as expressly provided under this License.  Any attempt | ||||
| otherwise to copy, modify, sublicense or distribute the Program is | ||||
| void, and will automatically terminate your rights under this License. | ||||
| However, parties who have received copies, or rights, from you under | ||||
| this License will not have their licenses terminated so long as such | ||||
| parties remain in full compliance. | ||||
|  | ||||
|   5. You are not required to accept this License, since you have not | ||||
| signed it.  However, nothing else grants you permission to modify or | ||||
| distribute the Program or its derivative works.  These actions are | ||||
| prohibited by law if you do not accept this License.  Therefore, by | ||||
| modifying or distributing the Program (or any work based on the | ||||
| Program), you indicate your acceptance of this License to do so, and | ||||
| all its terms and conditions for copying, distributing or modifying | ||||
| the Program or works based on it. | ||||
|  | ||||
|   6. Each time you redistribute the Program (or any work based on the | ||||
| Program), the recipient automatically receives a license from the | ||||
| original licensor to copy, distribute or modify the Program subject to | ||||
| these terms and conditions.  You may not impose any further | ||||
| restrictions on the recipients' exercise of the rights granted herein. | ||||
| You are not responsible for enforcing compliance by third parties to | ||||
| this License. | ||||
|  | ||||
|   7. If, as a consequence of a court judgment or allegation of patent | ||||
| infringement or for any other reason (not limited to patent issues), | ||||
| conditions are imposed on you (whether by court order, agreement or | ||||
| otherwise) that contradict the conditions of this License, they do not | ||||
| excuse you from the conditions of this License.  If you cannot | ||||
| distribute so as to satisfy simultaneously your obligations under this | ||||
| License and any other pertinent obligations, then as a consequence you | ||||
| may not distribute the Program at all.  For example, if a patent | ||||
| license would not permit royalty-free redistribution of the Program by | ||||
| all those who receive copies directly or indirectly through you, then | ||||
| the only way you could satisfy both it and this License would be to | ||||
| refrain entirely from distribution of the Program. | ||||
|  | ||||
| If any portion of this section is held invalid or unenforceable under | ||||
| any particular circumstance, the balance of the section is intended to | ||||
| apply and the section as a whole is intended to apply in other | ||||
| circumstances. | ||||
|  | ||||
| It is not the purpose of this section to induce you to infringe any | ||||
| patents or other property right claims or to contest validity of any | ||||
| such claims; this section has the sole purpose of protecting the | ||||
| integrity of the free software distribution system, which is | ||||
| implemented by public license practices.  Many people have made | ||||
| generous contributions to the wide range of software distributed | ||||
| through that system in reliance on consistent application of that | ||||
| system; it is up to the author/donor to decide if he or she is willing | ||||
| to distribute software through any other system and a licensee cannot | ||||
| impose that choice. | ||||
|  | ||||
| This section is intended to make thoroughly clear what is believed to | ||||
| be a consequence of the rest of this License. | ||||
|  | ||||
|   8. If the distribution and/or use of the Program is restricted in | ||||
| certain countries either by patents or by copyrighted interfaces, the | ||||
| original copyright holder who places the Program under this License | ||||
| may add an explicit geographical distribution limitation excluding | ||||
| those countries, so that distribution is permitted only in or among | ||||
| countries not thus excluded.  In such case, this License incorporates | ||||
| the limitation as if written in the body of this License. | ||||
|  | ||||
|   9. The Free Software Foundation may publish revised and/or new versions | ||||
| of the General Public License from time to time.  Such new versions will | ||||
| be similar in spirit to the present version, but may differ in detail to | ||||
| address new problems or concerns. | ||||
|  | ||||
| Each version is given a distinguishing version number.  If the Program | ||||
| specifies a version number of this License which applies to it and "any | ||||
| later version", you have the option of following the terms and conditions | ||||
| either of that version or of any later version published by the Free | ||||
| Software Foundation.  If the Program does not specify a version number of | ||||
| this License, you may choose any version ever published by the Free Software | ||||
| Foundation. | ||||
|  | ||||
|   10. If you wish to incorporate parts of the Program into other free | ||||
| programs whose distribution conditions are different, write to the author | ||||
| to ask for permission.  For software which is copyrighted by the Free | ||||
| Software Foundation, write to the Free Software Foundation; we sometimes | ||||
| make exceptions for this.  Our decision will be guided by the two goals | ||||
| of preserving the free status of all derivatives of our free software and | ||||
| of promoting the sharing and reuse of software generally. | ||||
|  | ||||
| 			    NO WARRANTY | ||||
|  | ||||
|   11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY | ||||
| FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN | ||||
| OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES | ||||
| PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED | ||||
| OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | ||||
| MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS | ||||
| TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE | ||||
| PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, | ||||
| REPAIR OR CORRECTION. | ||||
|  | ||||
|   12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING | ||||
| WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR | ||||
| REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, | ||||
| INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING | ||||
| OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED | ||||
| TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY | ||||
| YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER | ||||
| PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE | ||||
| POSSIBILITY OF SUCH DAMAGES. | ||||
|  | ||||
| 		     END OF TERMS AND CONDITIONS | ||||
|  | ||||
							
								
								
									
										344
									
								
								svgparser/parser/index.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										344
									
								
								svgparser/parser/index.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,344 @@ | ||||
| <?php | ||||
| /* | ||||
| SVG to dojox.gfx Parser | ||||
| Copyright (C) 2009  Aaron Lindsay <aclindsay@aclindsay.com> | ||||
|  | ||||
| This program is free software; you can redistribute it and/or | ||||
| modify it under the terms of the GNU General Public License | ||||
| as published by the Free Software Foundation; either version 2 | ||||
| of the License, or (at your option) any later version. | ||||
|  | ||||
| This program is distributed in the hope that it will be useful, | ||||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
| GNU General Public License for more details. | ||||
|  | ||||
| You should have received a copy of the GNU General Public License | ||||
| along with this program; if not, write to the Free Software | ||||
| Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. | ||||
| */ | ||||
|  | ||||
| require_once("parser/Parser.php"); | ||||
|  | ||||
| $requestData = ''; | ||||
| if (isset($_SERVER['CONTENT_LENGTH']) && $_SERVER['CONTENT_LENGTH'] > 0) { | ||||
| 	$httpContent = fopen('php://input', 'r'); | ||||
| 	while ($data = fread($httpContent, 1024)) { | ||||
| 		$requestData .= $data; | ||||
| 	} | ||||
| 	fclose($httpContent); | ||||
| } | ||||
|  | ||||
| if ($requestData == '') | ||||
| 	exit; | ||||
|  | ||||
| $parser = new Parser(); | ||||
| $svg = $parser->parse($requestData); | ||||
|  | ||||
| //first, create javascript objects for all the gradients | ||||
| $linearGradients = $svg->getCompleteLinearGradients(); | ||||
| $radialGradients = $svg->getCompleteRadialGradients(); | ||||
| $paths = $svg->getPaths(); | ||||
| $rects = $svg->getRectangles(); | ||||
| $circles = $svg->getCircles(); | ||||
| $ellipses = $svg->getEllipses(); | ||||
| $lines = $svg->getLines(); | ||||
| $polylines = $svg->getPolylines(); | ||||
| $texts = $svg->getTexts(); | ||||
|  | ||||
| echo "/* | ||||
| SVG to dojox.gfx Parser | ||||
| Copyright (C) 2009  Aaron Lindsay <aclindsay@aclindsay.com> | ||||
|  | ||||
| This program is free software; you can redistribute it and/or | ||||
| modify it under the terms of the GNU General Public License | ||||
| as published by the Free Software Foundation; either version 2 | ||||
| of the License, or (at your option) any later version. | ||||
|  | ||||
| This program is distributed in the hope that it will be useful, | ||||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
| GNU General Public License for more details. | ||||
|  | ||||
| You should have received a copy of the GNU General Public License | ||||
| along with this program; if not, write to the Free Software | ||||
| Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. | ||||
| */\n\n"; | ||||
| echo "//set 'g' equal to the dojo group you want to add this drawing as...\n//ex. var g = surface.createGroup()\n\n"; | ||||
|  | ||||
| //echo all the linear gradients | ||||
| foreach ($linearGradients as $gradient) { | ||||
| 	//make sure the gradient has its transform(s) applied | ||||
| 	if (!$gradient->transformsApplied()) | ||||
| 		$gradient->applyTransforms(); | ||||
| 	 | ||||
| 	echo "var gradient".$gradient->getId()." = {\n"; | ||||
| 	echo "\ttype: \"linear\",\n"; | ||||
| 	echo "\tx1: ".$gradient->getX1().", y1: ".$gradient->getY1().",\n"; | ||||
| 	echo "\tx2: ".$gradient->getX2().", y2: ".$gradient->getY2().",\n"; | ||||
| 	echo "\tcolors: [\n"; | ||||
| 	 | ||||
| 	$stops = $gradient->getStops(); | ||||
| 	for ($i = 0; $i < count($stops)-1; $i++) { | ||||
| 		echo "\t\t{offset: ".$stops[$i]->getOffset().", color: \"".$stops[$i]->getColor()."\"},\n"; | ||||
| 	} | ||||
| 	echo "\t\t{offset: ".$stops[count($stops)-1]->getOffset().", color: \"".$stops[count($stops)-1]->getColor()."\"}\n"; | ||||
| 	echo "\t]\n"; | ||||
| 	echo "};\n"; | ||||
| } | ||||
|  | ||||
| //now, do the same for all the radial gradients | ||||
| foreach ($radialGradients as $gradient) { | ||||
| 	//make sure the gradient has its transform(s) applied | ||||
| 	if (!$gradient->transformsApplied()) | ||||
| 		$gradient->applyTransforms(); | ||||
| 		 | ||||
| 	echo "var gradient".$gradient->getId()." = {\n"; | ||||
| 	echo "\ttype: \"radial\",\n"; | ||||
| 	echo "\tcx: ".$gradient->getCx().", cy: ".$gradient->getCy().",\n"; | ||||
| 	echo "\tr: ".$gradient->getR().",\n"; | ||||
| 	echo "\tfx: ".$gradient->getFx().", fy: ".$gradient->getFy().",\n"; | ||||
| 	echo "\tcolors: [\n"; | ||||
| 	 | ||||
| 	$stops = $gradient->getStops(); | ||||
| 	for ($i = 0; $i < count($stops)-1; $i++) { | ||||
| 		echo "\t\t{offset: ".$stops[$i]->getOffset().", color: \"".$stops[$i]->getColor()."\"},\n"; | ||||
| 	} | ||||
| 	echo "\t\t{offset: ".$stops[count($stops)-1]->getOffset().", color: \"".$stops[count($stops)-1]->getColor()."\"}\n"; | ||||
| 	echo "\t]\n"; | ||||
| 	echo "};\n"; | ||||
| } | ||||
|  | ||||
| //now, get all the paths | ||||
| foreach ($paths as $path) { | ||||
| 	echo "g.createPath({type: \"path\", path: \"".$path->getPath()."\"})"; | ||||
| 	addFill($path); | ||||
| 	addStroke($path); | ||||
| 	addTransform($path); | ||||
| 	echo ";\n"; | ||||
| } | ||||
|  | ||||
| //and all rectangles | ||||
| foreach ($rects as $rect) { | ||||
| 	echo "g.createRect({type: \"rect\", x: ".$rect->getX().", y: ".$rect->getY().", height: ".$rect->getHeight().", width: ".$rect->getWidth().", r: ".$rect->getR()."})"; | ||||
| 	addFill($rect); | ||||
| 	addStroke($rect); | ||||
| 	addTransform($rect); | ||||
|  | ||||
| 	echo ";\n"; | ||||
| } | ||||
|  | ||||
| //and all circles | ||||
| foreach ($circles as $circle) { | ||||
| 	echo "g.createCircle({type: \"circle\", cx:".$circle->getCx().", cy:".$circle->getCy().", r: ".$circle->getR()."})"; | ||||
| 	addFill($circle); | ||||
| 	addStroke($circle); | ||||
| 	addTransform($circle); | ||||
|  | ||||
| 	echo ";\n"; | ||||
| } | ||||
|  | ||||
| //and all ellipses | ||||
| foreach ($ellipses as $ellipse) { | ||||
| 	echo "g.createEllipse({type: \"ellipse\", cx:".$ellipse->getCx().", cy:".$ellipse->getCy().", rx: ".$ellipse->getRx().", ry: ".$ellipse->getRy()."})"; | ||||
| 	addFill($ellipse); | ||||
| 	addStroke($ellipse); | ||||
| 	addTransform($ellipse); | ||||
|  | ||||
| 	echo ";\n"; | ||||
| } | ||||
|  | ||||
| //and all lines | ||||
| foreach ($lines as $line) { | ||||
| 	echo "g.createLine({type: \"line\", x1:".$line->getX1().", y1:".$line->getY1().", x2:".$line->getX2().", y2:".$line->getY2()."})"; | ||||
| 	addStroke($line); | ||||
| 	addTransform($line); | ||||
| 	echo ";\n"; | ||||
| } | ||||
|  | ||||
| //and all polylines | ||||
| foreach ($polylines as $polyline) { | ||||
| 	echo "//TODO - implement polylines\n"; | ||||
| } | ||||
|  | ||||
| //and all texts | ||||
| foreach ($texts as $text) { | ||||
| 	echo "g.createText({type: \"text\", x: ".$text->getX().", y: ".$text->getY().", text: \"".$text->getText()."\", align: \"".$text->getTextAnchor()."\", decoration: \"".$text->getTextDecoration()."\"})"; | ||||
| 	addFill($text); | ||||
| 	addStroke($text); | ||||
| 	addTransform($text); | ||||
| 	echo ";\n"; | ||||
| } | ||||
|  | ||||
| function addFont($shape) { | ||||
| 	$putComma = false; | ||||
|  | ||||
| 	//get the font family, if available | ||||
| 	$family = $shape->getStyle("font-family"); | ||||
| 	if ($family != null) { | ||||
| 		if ($putComma) | ||||
| 			echo ","; | ||||
| 		else { | ||||
| 			echo ".setFont({"; | ||||
| 			$putComma = true; | ||||
| 		} | ||||
|  | ||||
| 		echo "family: \"".$family."\""; | ||||
| 	} | ||||
|  | ||||
| 	//get the font variant, if available | ||||
| 	$variant = $shape->getStyle("font-variant"); | ||||
| 	if ($variant != null) { | ||||
| 		if ($putComma) | ||||
| 			echo ","; | ||||
| 		else { | ||||
| 			echo ".setFont({"; | ||||
| 			$putComma = true; | ||||
| 		} | ||||
|  | ||||
| 		echo "variant: \"".$variant."\""; | ||||
| 	} | ||||
|  | ||||
| 	//get the font size, if available | ||||
| 	$size = $shape->getStyle("font-size"); | ||||
| 	if ($size != null) { | ||||
| 		if ($putComma) | ||||
| 			echo ","; | ||||
| 		else { | ||||
| 			echo ".setFont({"; | ||||
| 			$putComma = true; | ||||
| 		} | ||||
|  | ||||
| 		echo "size: \"".$size."\""; | ||||
| 	} | ||||
|  | ||||
| 	//get the font style, if available | ||||
| 	$style = $shape->getStyle("font-style"); | ||||
| 	if ($style != null) { | ||||
| 		if ($putComma) | ||||
| 			echo ","; | ||||
| 		else { | ||||
| 			echo ".setFont({"; | ||||
| 			$putComma = true; | ||||
| 		} | ||||
|  | ||||
| 		echo "style: \"".$style."\""; | ||||
| 	} | ||||
|  | ||||
| 	//get the font weight, if available | ||||
| 	$weight = $shape->getStyle("font-weight"); | ||||
| 	if ($weight != null) { | ||||
| 		if ($putComma) | ||||
| 			echo ","; | ||||
| 		else { | ||||
| 			echo ".setFont({"; | ||||
| 			$putComma = true; | ||||
| 		} | ||||
|  | ||||
| 		echo "style: \"".$weight."\""; | ||||
| 	} | ||||
|  | ||||
| 	if ($putComma) | ||||
| 		echo "})"; | ||||
| } | ||||
|  | ||||
| function addFill($shape) { | ||||
| 	$fill = $shape->getStyle("fill"); | ||||
| 	if ($fill == null) | ||||
| 		return; | ||||
|  | ||||
| 	if (ereg("url\(.*\)", $fill)) { | ||||
| 		$parts = split("[\(\)]", $fill); | ||||
| 		$url = trim($parts[1], "#"); | ||||
| 		echo ".setFill(gradient".$url.")"; | ||||
| 	} else if (ereg("#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})", $fill)) { | ||||
| 		echo ".setFill(\"".$fill."\")"; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| function addStroke($shape) { | ||||
| 	$putComma = false; | ||||
|  | ||||
| 	//get the stroke width, if available | ||||
| 	$width = $shape->getStyle("stroke-width"); | ||||
| 	if ($width != null) { | ||||
| 		if ($putComma) | ||||
| 			echo ","; | ||||
| 		else { | ||||
| 			echo ".setStroke({"; | ||||
| 			$putComma = true; | ||||
| 		} | ||||
|  | ||||
| 		$width = trim($width, "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"); | ||||
| 		echo "width: $width"; | ||||
| 	} | ||||
|  | ||||
| 	//get the stroke color, if available | ||||
| 	$color = $shape->getStyle("stroke"); | ||||
| 	if ($color != null) { | ||||
| 		if ($putComma) | ||||
| 			echo ","; | ||||
| 		else { | ||||
| 			echo ".setStroke({"; | ||||
| 			$putComma = true; | ||||
| 		} | ||||
|  | ||||
| 		echo "color: \"".$color."\""; | ||||
| 	} | ||||
|  | ||||
| 	//get the stroke cap, if available | ||||
| 	$cap = $shape->getStyle("stroke-linecap"); | ||||
| 	if ($cap != null) { | ||||
| 		if ($putComma) | ||||
| 			echo ","; | ||||
| 		else { | ||||
| 			echo ".setStroke({"; | ||||
| 			$putComma = true; | ||||
| 		} | ||||
|  | ||||
| 		echo "cap: \"$cap\""; | ||||
| 	} | ||||
|  | ||||
| 	//get the line join, if available | ||||
| 	$join = $shape->getStyle("stroke-linejoin"); | ||||
| 	if ($join != null) { | ||||
| 		if ($putComma) | ||||
| 			echo ","; | ||||
| 		else { | ||||
| 			echo ".setStroke({"; | ||||
| 			$putComma = true; | ||||
| 		} | ||||
|  | ||||
| 		if ($join == "miter") | ||||
| 			echo "join: 4"; | ||||
| 		else | ||||
| 			echo "join: \"$join\""; | ||||
| 	} | ||||
|  | ||||
| 	//if any kind of dash is made in SVG, convert it to 'style: "Dash"' in dojox.gfx | ||||
| 	$style = $shape->getStyle("stroke-dasharray"); | ||||
| 	if ($style != null && $style != 'none') { | ||||
| 		if ($putComma) | ||||
| 			echo ","; | ||||
| 		else { | ||||
| 			echo ".setStroke({"; | ||||
| 			$putComma = true; | ||||
| 		} | ||||
|  | ||||
| 		echo "style: \"Dash\""; | ||||
| 	} | ||||
|  | ||||
| 	if ($putComma) | ||||
| 		echo "})"; | ||||
| } | ||||
|  | ||||
| function addTransform($shape) { | ||||
| 	//echo "\n==== transform:"; | ||||
| 	//var_dump($shape->getTransform()); | ||||
| 	$transform = $shape->getTransform(); | ||||
| 	if (!$transform->isIdentity()) { | ||||
| 		echo ".setTransform({xx:".$transform->getXx().", xy:".$transform->getXy().", dx:".$transform->getDx().", yy:".$transform->getYy().", yx:".$transform->getYx().", dy:".$transform->getDy()."})"; | ||||
| 	} | ||||
| } | ||||
|  | ||||
| ?> | ||||
							
								
								
									
										41
									
								
								svgparser/parser/objects/Circle.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								svgparser/parser/objects/Circle.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,41 @@ | ||||
| <?php | ||||
| /* | ||||
| SVG to dojox.gfx Parser | ||||
| Copyright (C) 2009  Aaron Lindsay <aclindsay@aclindsay.com> | ||||
|  | ||||
| This program is free software; you can redistribute it and/or | ||||
| modify it under the terms of the GNU General Public License | ||||
| as published by the Free Software Foundation; either version 2 | ||||
| of the License, or (at your option) any later version. | ||||
|  | ||||
| This program is distributed in the hope that it will be useful, | ||||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
| GNU General Public License for more details. | ||||
|  | ||||
| You should have received a copy of the GNU General Public License | ||||
| along with this program; if not, write to the Free Software | ||||
| Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. | ||||
| */ | ||||
|  | ||||
| require_once("objects/Element.php"); | ||||
|  | ||||
| class Circle extends Element { | ||||
| 	private $cx; | ||||
| 	private $cy; | ||||
| 	private $r; | ||||
| 	 | ||||
| 	public function __construct() { | ||||
| 		$this->cx = 0; | ||||
| 		$this->cy = 0; | ||||
| 		$this->r = 0; | ||||
| 	} | ||||
|  | ||||
| 	public function getCx() { return $this->cx; } | ||||
| 	public function getCy() { return $this->cy; } | ||||
| 	public function getR() { return $this->r; } | ||||
| 	public function setCx($x) { $this->cx = $x; } | ||||
| 	public function setCy($x) { $this->cy = $x; } | ||||
| 	public function setR($x) { $this->r = $x; } | ||||
| } | ||||
| ?> | ||||
							
								
								
									
										183
									
								
								svgparser/parser/objects/Element.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										183
									
								
								svgparser/parser/objects/Element.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,183 @@ | ||||
| <?php | ||||
| /* | ||||
| SVG to dojox.gfx Parser | ||||
| Copyright (C) 2009  Aaron Lindsay <aclindsay@aclindsay.com> | ||||
|  | ||||
| This program is free software; you can redistribute it and/or | ||||
| modify it under the terms of the GNU General Public License | ||||
| as published by the Free Software Foundation; either version 2 | ||||
| of the License, or (at your option) any later version. | ||||
|  | ||||
| This program is distributed in the hope that it will be useful, | ||||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
| GNU General Public License for more details. | ||||
|  | ||||
| You should have received a copy of the GNU General Public License | ||||
| along with this program; if not, write to the Free Software | ||||
| Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. | ||||
| */ | ||||
|  | ||||
| class Element { | ||||
| 	private $id; | ||||
| 	private $styles; | ||||
| 	private $transforms; | ||||
| 	private $transform; | ||||
| 	 | ||||
| 	public function __construct() { | ||||
| 		$this->id = ""; | ||||
| 		$this->styles = array(); | ||||
| 		$this->transforms = array(); | ||||
| 		$this->transform = new Transform(); | ||||
| 	} | ||||
| 	 | ||||
| 	public function setId($newId) { | ||||
| 		$this->id = $newId; | ||||
| 	} | ||||
| 	public function getId() { | ||||
| 		return $this->id; | ||||
| 	} | ||||
| 	 | ||||
| 	public function setStyles($newStyles) { | ||||
| 		$this->styles = array(); | ||||
| 		$smallerStyles = split(";", $newStyles); | ||||
| 		foreach($smallerStyles as $small) { | ||||
| 			$parts = split(":", $small); | ||||
| 			$this->styles[$parts[0]] = $parts[1]; | ||||
| 		} | ||||
| 	} | ||||
| 	public function setStyle($key, $style) { | ||||
| 		$this->styles[$key] = $style; | ||||
| 	} | ||||
| 	public function getStyles() { | ||||
| 		return $this->styles; | ||||
| 	} | ||||
| 	public function getStyle($key) { | ||||
| 		if ($this->styles && array_key_exists($key, $this->styles)) | ||||
| 			return $this->styles[$key]; | ||||
| 		else | ||||
| 			return null; | ||||
| 	} | ||||
| 	public function setStroke($stroke) { | ||||
| 		$this->styles["stroke"] = $stroke; | ||||
| 	} | ||||
| 	public function setStrokeWidth($width) { | ||||
| 		$this->styles["stroke-width"] = $width; | ||||
| 	} | ||||
| 	public function setStrokeLinecap($linecap) { | ||||
| 		$this->styles["stroke-linecap"] = $linecap; | ||||
| 	} | ||||
|  | ||||
| 	public function setFill($fill) { | ||||
| 		$this->styles["fill"] = $fill; | ||||
| 	} | ||||
|  | ||||
| 	//$transform is a string of transformations | ||||
| 	public function setTransforms($transform) { | ||||
| 		$this->transforms = array(); | ||||
| 		$this->addTransforms($transform); | ||||
| 		$this->combineTransforms(); | ||||
| 	} | ||||
| 	 | ||||
| 	//$transform is a string of transformations | ||||
| 	public function addTransforms($transform) { | ||||
| 		$parts = split("\\)", $transform); | ||||
| 		foreach ($parts as $part) { | ||||
| 			//because ')' is the last character, we'll get an empty string here if we don't watch out | ||||
| 			if ($part == "") | ||||
| 				break; | ||||
| 				 | ||||
| 			$transform = split("\\(", trim($part)); | ||||
| 			switch (trim($transform[0])) { | ||||
| 				case "matrix": | ||||
| 					//get all the matrix elements, create a new transform and set them | ||||
| 					$elements = split("[[:blank:],]+", trim($transform[1])); | ||||
| 					$transformObject = new Transform(); | ||||
| 					$transformObject->setFullMatrix($elements[0], $elements[1], $elements[2], $elements[3], $elements[4], $elements[5]); | ||||
| 					$this->transforms[] = $transformObject; | ||||
| 					break; | ||||
| 				case "translate": | ||||
| 					//get all the matrix elements, create a new translate transform and set them | ||||
| 					$elements = split("[[:blank:],]+", trim($transform[1])); | ||||
| 					$transformObject = new Transform(); | ||||
| 					$transformObject->setTranslate($elements[0], $elements[1]); | ||||
| 					$this->transforms[] = $transformObject; | ||||
| 					break; | ||||
| 				case "scale": | ||||
| 					//get all the matrix elements, create a new scale transform and set them | ||||
| 					$elements = split("[[:blank:],]+", trim($transform[1])); | ||||
| 					$transformObject = new Transform(); | ||||
| 					if (count($elements) > 1) | ||||
| 						$transformObject->setScale($elements[0], $elements[1]); | ||||
| 					else | ||||
| 						$transformObject->setScale($elements[0]); | ||||
| 					$this->transforms[] = $transformObject; | ||||
| 					break; | ||||
| 				case "rotate": | ||||
| 					//get all the matrix elements, create a new rotate transform and set them | ||||
| 					$elements = split("[[:blank:],]+", trim($transform[1])); | ||||
| 					//if there are 3 arguments, they are angle, and (x,y) coordinates of the point to rotate about | ||||
| 					//to handle this, we translate, rotate, and translate back | ||||
| 					if (count($elements) >= 3) { | ||||
| 						$transformObject1 = new Transform(); | ||||
| 						$transformObject1->setTranslate(-$elements[1], -$elements[2]); | ||||
| 						$this->transforms[] = $transformObject1; | ||||
| 						 | ||||
| 						$transformObject2 = new Transform(); | ||||
| 						$transformObject2->setRotate($elements[0]); | ||||
| 						$this->transforms[] = $transformObject2; | ||||
| 						 | ||||
| 						$transformObject3 = new Transform(); | ||||
| 						$transformObject3->setTranslate($elements[1], $elements[2]); | ||||
| 						$this->transforms[] = $transformObject3; | ||||
| 					} else { | ||||
| 						$transformObject = new Transform(); | ||||
| 						$transformObject->setRotate($elements[0]); | ||||
| 						$this->transforms[] = $transformObject; | ||||
| 					} | ||||
| 					break; | ||||
| 				case "skewX": | ||||
| 					//get all the matrix elements, create a new skew transform and set them | ||||
| 					$elements = split("[[:blank:],]+", trim($transform[1])); | ||||
| 					$transformObject = new Transform(); | ||||
| 					$transformObject->setSkewX($elements[0]); | ||||
| 					$this->transforms[] = $transformObject; | ||||
| 					break; | ||||
| 				case "skewY": | ||||
| 					//get all the matrix elements, create a new skew transform and set them | ||||
| 					$elements = split("[[:blank:],]+", trim($transform[1])); | ||||
| 					$transformObject = new Transform(); | ||||
| 					$transformObject->setSkewY($elements[0]); | ||||
| 					$this->transforms[] = $transformObject; | ||||
| 					break; | ||||
| 			}  | ||||
| 		} | ||||
| 		//combine all these into one transform | ||||
| 		$this->combineTransforms(); | ||||
| 	} | ||||
| 	 | ||||
|  | ||||
| 	//combine all transforms into one transform and store in $this->transform | ||||
| 	private function combineTransforms() { | ||||
| 		$one = new Transform(); | ||||
| 		foreach ($this->transforms as $transform) | ||||
| 			$one->multiplyBy($transform); | ||||
| 		$this->transform = $one; | ||||
| 	} | ||||
|  | ||||
| 	public function setTransform($transform) { | ||||
| 		$this->transform = $transform; | ||||
| 		$this->transforms = array(); | ||||
| 		$this->transforms[] = $transform; | ||||
| 	} | ||||
|  | ||||
| 	public function getTransform() { | ||||
| 		return $this->transform; | ||||
| 	} | ||||
|  | ||||
| 	//an ARRAY of Transform objects is returned | ||||
| 	public function getTransforms() { | ||||
| 		return $this->transforms; | ||||
| 	} | ||||
| } | ||||
| ?> | ||||
							
								
								
									
										45
									
								
								svgparser/parser/objects/Ellipse.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								svgparser/parser/objects/Ellipse.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,45 @@ | ||||
| <?php | ||||
| /* | ||||
| SVG to dojox.gfx Parser | ||||
| Copyright (C) 2009  Aaron Lindsay <aclindsay@aclindsay.com> | ||||
|  | ||||
| This program is free software; you can redistribute it and/or | ||||
| modify it under the terms of the GNU General Public License | ||||
| as published by the Free Software Foundation; either version 2 | ||||
| of the License, or (at your option) any later version. | ||||
|  | ||||
| This program is distributed in the hope that it will be useful, | ||||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
| GNU General Public License for more details. | ||||
|  | ||||
| You should have received a copy of the GNU General Public License | ||||
| along with this program; if not, write to the Free Software | ||||
| Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. | ||||
| */ | ||||
|  | ||||
| require_once("objects/Element.php"); | ||||
|  | ||||
| class Ellipse extends Element { | ||||
| 	private $cx; | ||||
| 	private $cy; | ||||
| 	private $rx; | ||||
| 	private $ry; | ||||
| 	 | ||||
| 	public function __construct() { | ||||
| 		$this->cx = 0; | ||||
| 		$this->cy = 0; | ||||
| 		$this->rx = 0; | ||||
| 		$this->ry = 0; | ||||
| 	} | ||||
|  | ||||
| 	public function getCx() { return $this->cx; } | ||||
| 	public function getCy() { return $this->cy; } | ||||
| 	public function getRx() { return $this->rx; } | ||||
| 	public function getRy() { return $this->ry; } | ||||
| 	public function setCx($x) { $this->cx = $x; } | ||||
| 	public function setCy($x) { $this->cy = $x; } | ||||
| 	public function setRx($x) { $this->rx = $x; } | ||||
| 	public function setRy($x) { $this->ry = $x; } | ||||
| } | ||||
| ?> | ||||
							
								
								
									
										55
									
								
								svgparser/parser/objects/Gradient.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										55
									
								
								svgparser/parser/objects/Gradient.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,55 @@ | ||||
| <?php | ||||
| /* | ||||
| SVG to dojox.gfx Parser | ||||
| Copyright (C) 2009  Aaron Lindsay <aclindsay@aclindsay.com> | ||||
|  | ||||
| This program is free software; you can redistribute it and/or | ||||
| modify it under the terms of the GNU General Public License | ||||
| as published by the Free Software Foundation; either version 2 | ||||
| of the License, or (at your option) any later version. | ||||
|  | ||||
| This program is distributed in the hope that it will be useful, | ||||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
| GNU General Public License for more details. | ||||
|  | ||||
| You should have received a copy of the GNU General Public License | ||||
| along with this program; if not, write to the Free Software | ||||
| Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. | ||||
| */ | ||||
|  | ||||
| require_once("objects/Element.php"); | ||||
|  | ||||
| require_once("objects/Transform.php"); | ||||
|  | ||||
| class Gradient extends Element{ | ||||
| 	private $link; | ||||
| 	private $stops; | ||||
| 	 | ||||
| 	public function __construct() { | ||||
| 		parent::__construct(); | ||||
| 		$this->stops = array(); | ||||
| 	} | ||||
| 	 | ||||
| 	public function setLink($link) { | ||||
| 		$this->link = trim($link, " \t\n\r#"); | ||||
| 	} | ||||
| 	public function getLink() { | ||||
| 		return isset($this->link)?$this->link:null; | ||||
| 	} | ||||
| 	 | ||||
| 	public function addStop($stop) { | ||||
| 		$this->stops[] = $stop; | ||||
| 	} | ||||
| 	public function setStops($stops) { | ||||
| 		$this->stops = $stops; | ||||
| 	} | ||||
| 	public function getStops() { | ||||
| 		return $this->stops; | ||||
| 	} | ||||
| 	 | ||||
| 	public function isValid() { | ||||
| 		return count($this->stops) > 0; | ||||
| 	} | ||||
| } | ||||
| ?> | ||||
							
								
								
									
										58
									
								
								svgparser/parser/objects/GradientStop.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								svgparser/parser/objects/GradientStop.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,58 @@ | ||||
| <?php | ||||
| /* | ||||
| SVG to dojox.gfx Parser | ||||
| Copyright (C) 2009  Aaron Lindsay <aclindsay@aclindsay.com> | ||||
|  | ||||
| This program is free software; you can redistribute it and/or | ||||
| modify it under the terms of the GNU General Public License | ||||
| as published by the Free Software Foundation; either version 2 | ||||
| of the License, or (at your option) any later version. | ||||
|  | ||||
| This program is distributed in the hope that it will be useful, | ||||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
| GNU General Public License for more details. | ||||
|  | ||||
| You should have received a copy of the GNU General Public License | ||||
| along with this program; if not, write to the Free Software | ||||
| Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. | ||||
| */ | ||||
|  | ||||
| class GradientStop extends Element{ | ||||
| 	private $offset; | ||||
| 	 | ||||
| 	public function __construct() { | ||||
| 		parent::__construct(); | ||||
| 		$this->offset = 0; | ||||
| 	} | ||||
| 	 | ||||
| 	public function setColor($color) { | ||||
| 		$this->setStyle("stop-color", $color); | ||||
| 	} | ||||
| 	public function getColor() { | ||||
| 		$color = $this->getStyle("stop-color"); | ||||
| 		if ($color == null) | ||||
| 			return "#000000"; | ||||
| 		else | ||||
| 			return $color; | ||||
| 	} | ||||
| 	 | ||||
| 	public function setOpacity($opacity) { | ||||
| 		$this->setStyle("stop-opacity", $opacity); | ||||
| 	} | ||||
| 	public function getOpacity() { | ||||
| 		$opacity = $this->getStyle("stop-opacity"); | ||||
| 		if ($opacity == null) | ||||
| 			return 1; | ||||
| 		else | ||||
| 			return $opacity; | ||||
| 	} | ||||
| 	 | ||||
| 	public function setOffset($offset) { | ||||
| 		$this->offset = $offset; | ||||
| 	} | ||||
| 	public function getOffset() { | ||||
| 		return isset($this->offset)?$this->offset:0; | ||||
| 	} | ||||
| } | ||||
| ?> | ||||
							
								
								
									
										43
									
								
								svgparser/parser/objects/Line.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								svgparser/parser/objects/Line.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,43 @@ | ||||
| <?php | ||||
| /* | ||||
| SVG to dojox.gfx Parser | ||||
| Copyright (C) 2009  Aaron Lindsay <aclindsay@aclindsay.com> | ||||
|  | ||||
| This program is free software; you can redistribute it and/or | ||||
| modify it under the terms of the GNU General Public License | ||||
| as published by the Free Software Foundation; either version 2 | ||||
| of the License, or (at your option) any later version. | ||||
|  | ||||
| This program is distributed in the hope that it will be useful, | ||||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
| GNU General Public License for more details. | ||||
|  | ||||
| You should have received a copy of the GNU General Public License | ||||
| along with this program; if not, write to the Free Software | ||||
| Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. | ||||
| */ | ||||
|  | ||||
| class Line extends Element { | ||||
| 	private $x1; | ||||
| 	private $y1; | ||||
| 	private $x2; | ||||
| 	private $y2; | ||||
|  | ||||
| 	public function __construct() { | ||||
| 		$this->x1 = 0; | ||||
| 		$this->y1 = 0; | ||||
| 		$this->x2 = 0; | ||||
| 		$this->y2 = 0; | ||||
| 	} | ||||
|  | ||||
| 	public function getX1() { return $this->x1; } | ||||
| 	public function getY1() { return $this->y1; } | ||||
| 	public function getX2() { return $this->x2; } | ||||
| 	public function getY2() { return $this->y2; } | ||||
| 	public function setX1($x) { $this->x1 = $x; } | ||||
| 	public function setY1($x) { $this->y1 = $x; } | ||||
| 	public function setX2($x) { $this->x2 = $x; } | ||||
| 	public function setY2($x) { $this->y2 = $x; } | ||||
| } | ||||
| ?> | ||||
							
								
								
									
										90
									
								
								svgparser/parser/objects/LinearGradient.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										90
									
								
								svgparser/parser/objects/LinearGradient.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,90 @@ | ||||
| <?php | ||||
| /* | ||||
| SVG to dojox.gfx Parser | ||||
| Copyright (C) 2009  Aaron Lindsay <aclindsay@aclindsay.com> | ||||
|  | ||||
| This program is free software; you can redistribute it and/or | ||||
| modify it under the terms of the GNU General Public License | ||||
| as published by the Free Software Foundation; either version 2 | ||||
| of the License, or (at your option) any later version. | ||||
|  | ||||
| This program is distributed in the hope that it will be useful, | ||||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
| GNU General Public License for more details. | ||||
|  | ||||
| You should have received a copy of the GNU General Public License | ||||
| along with this program; if not, write to the Free Software | ||||
| Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. | ||||
| */ | ||||
|  | ||||
| require_once("objects/Gradient.php"); | ||||
|  | ||||
| class LinearGradient extends Gradient { | ||||
| 	private $x1; | ||||
| 	private $y1; | ||||
| 	private $x2; | ||||
| 	private $y2; | ||||
| 	 | ||||
| 	private $transformsApplied = false; | ||||
|  | ||||
| 	public function __construct() { | ||||
| 		parent::__construct(); | ||||
| 	} | ||||
| 	 | ||||
| 	public function setX1($x) { | ||||
| 		$this->x1 = $x; | ||||
| 	} | ||||
| 	public function setY1($x) { | ||||
| 		$this->y1 = $x; | ||||
| 	} | ||||
| 	public function setX2($x) { | ||||
| 		$this->x2 = $x; | ||||
| 	} | ||||
| 	public function setY2($x) { | ||||
| 		$this->y2 = $x; | ||||
| 	} | ||||
| 	 | ||||
| 	public function getX1() { | ||||
| 		return $this->x1; | ||||
| 	} | ||||
| 	public function getY1() { | ||||
| 		return $this->y1; | ||||
| 	} | ||||
| 	public function getX2() { | ||||
| 		return $this->x2; | ||||
| 	} | ||||
| 	public function getY2() { | ||||
| 		return $this->y2; | ||||
| 	} | ||||
| 	 | ||||
| 	public function isValid() { | ||||
| 		if (!parent::isValid()) | ||||
| 			return false; | ||||
| 		if (!isset($this->x1) || !isset($this->y1) || !isset($this->x2) || !isset($this->y2)) | ||||
| 			return false; | ||||
| 		 | ||||
| 		return true; | ||||
| 	} | ||||
| 	 | ||||
| 	public function transformsApplied() { | ||||
| 		return $this->transformsApplied; | ||||
| 	} | ||||
| 	 | ||||
| 	//apply all the transforms to the points in this gradient | ||||
| 	public function applyTransforms() { | ||||
| 		$transforms = $this->getTransforms(); | ||||
| 		foreach($transforms as $transform) { | ||||
| 			$oldX1 = $this->x1; | ||||
| 			$oldY1 = $this->y1; | ||||
| 			$oldX2 = $this->x2; | ||||
| 			$oldY2 = $this->y2; | ||||
| 			$this->x1 = $transform->applyToX($oldX1, $oldY1); | ||||
| 			$this->y1 = $transform->applyToY($oldX1, $oldY1); | ||||
| 			$this->x2 = $transform->applyToX($oldX2, $oldY2); | ||||
| 			$this->y2 = $transform->applyToY($oldX2, $oldY2); | ||||
| 		} | ||||
| 		$this->transformsApplied = true; | ||||
| 	} | ||||
| } | ||||
| ?> | ||||
							
								
								
									
										38
									
								
								svgparser/parser/objects/Path.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										38
									
								
								svgparser/parser/objects/Path.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,38 @@ | ||||
| <?php | ||||
| /* | ||||
| SVG to dojox.gfx Parser | ||||
| Copyright (C) 2009  Aaron Lindsay <aclindsay@aclindsay.com> | ||||
|  | ||||
| This program is free software; you can redistribute it and/or | ||||
| modify it under the terms of the GNU General Public License | ||||
| as published by the Free Software Foundation; either version 2 | ||||
| of the License, or (at your option) any later version. | ||||
|  | ||||
| This program is distributed in the hope that it will be useful, | ||||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
| GNU General Public License for more details. | ||||
|  | ||||
| You should have received a copy of the GNU General Public License | ||||
| along with this program; if not, write to the Free Software | ||||
| Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. | ||||
| */ | ||||
|  | ||||
| require_once("objects/Element.php"); | ||||
|  | ||||
| class Path extends Element { | ||||
| 	private $path; | ||||
| 	 | ||||
| 	public function __construct() { | ||||
| 		parent::__construct(); | ||||
| 		$this->path = ""; | ||||
| 	} | ||||
| 	 | ||||
| 	public function setPath($newPath) { | ||||
| 		$this->path = $newPath; | ||||
| 	} | ||||
| 	public function getPath() { | ||||
| 		return $this->path; | ||||
| 	} | ||||
| } | ||||
| ?> | ||||
							
								
								
									
										37
									
								
								svgparser/parser/objects/Polyline.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								svgparser/parser/objects/Polyline.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,37 @@ | ||||
| <?php | ||||
| /* | ||||
| SVG to dojox.gfx Parser | ||||
| Copyright (C) 2009  Aaron Lindsay <aclindsay@aclindsay.com> | ||||
|  | ||||
| This program is free software; you can redistribute it and/or | ||||
| modify it under the terms of the GNU General Public License | ||||
| as published by the Free Software Foundation; either version 2 | ||||
| of the License, or (at your option) any later version. | ||||
|  | ||||
| This program is distributed in the hope that it will be useful, | ||||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
| GNU General Public License for more details. | ||||
|  | ||||
| You should have received a copy of the GNU General Public License | ||||
| along with this program; if not, write to the Free Software | ||||
| Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. | ||||
| */ | ||||
|  | ||||
| require_once("objects/Element.php"); | ||||
|  | ||||
| class Polyline extends Element { | ||||
| 	private $points; | ||||
| 	 | ||||
| 	public function __construct() { | ||||
| 		$this->points=""; | ||||
| 	} | ||||
| 	 | ||||
| 	public function getPoints() { | ||||
| 		return $this->points; | ||||
| 	} | ||||
| 	public function setPoints($x) { | ||||
| 		$this->points = $x; | ||||
| 	} | ||||
| } | ||||
| ?> | ||||
							
								
								
									
										97
									
								
								svgparser/parser/objects/RadialGradient.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										97
									
								
								svgparser/parser/objects/RadialGradient.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,97 @@ | ||||
| <?php | ||||
| /* | ||||
| SVG to dojox.gfx Parser | ||||
| Copyright (C) 2009  Aaron Lindsay <aclindsay@aclindsay.com> | ||||
|  | ||||
| This program is free software; you can redistribute it and/or | ||||
| modify it under the terms of the GNU General Public License | ||||
| as published by the Free Software Foundation; either version 2 | ||||
| of the License, or (at your option) any later version. | ||||
|  | ||||
| This program is distributed in the hope that it will be useful, | ||||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
| GNU General Public License for more details. | ||||
|  | ||||
| You should have received a copy of the GNU General Public License | ||||
| along with this program; if not, write to the Free Software | ||||
| Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. | ||||
| */ | ||||
|  | ||||
| require_once("objects/Gradient.php"); | ||||
|  | ||||
| class RadialGradient extends Gradient { | ||||
| 	private $cx; | ||||
| 	private $cy; | ||||
| 	private $r; | ||||
| 	private $fx; | ||||
| 	private $fy; | ||||
| 	 | ||||
| 	private $transformsApplied = false; | ||||
|  | ||||
| 	public function __construct() { | ||||
| 		parent::__construct(); | ||||
| 	} | ||||
| 	 | ||||
| 	public function setCx($x) { | ||||
| 		$this->cx = $x; | ||||
| 	} | ||||
| 	public function setCy($x) { | ||||
| 		$this->cy = $x; | ||||
| 	} | ||||
| 	public function setR($x) { | ||||
| 		$this->r = $x; | ||||
| 	} | ||||
| 	public function setFx($x) { | ||||
| 		$this->fx = $x; | ||||
| 	} | ||||
| 	public function setFy($x) { | ||||
| 		$this->fy = $x; | ||||
| 	} | ||||
| 	 | ||||
| 	public function getCx() { | ||||
| 		return $this->cx; | ||||
| 	} | ||||
| 	public function getCy() { | ||||
| 		return $this->cy; | ||||
| 	} | ||||
| 	public function getR() { | ||||
| 		return $this->r; | ||||
| 	} | ||||
| 	public function getFx() { | ||||
| 		return $this->fx; | ||||
| 	} | ||||
| 	public function getFy() { | ||||
| 		return $this->fy; | ||||
| 	} | ||||
| 	 | ||||
| 	public function isValid() { | ||||
| 		if (!parent::isValid()) | ||||
| 			return false; | ||||
| 		if (!isset($this->cx) || !isset($this->cy) || !isset($this->r) || !isset($this->fx)  || !isset($this->fy)) | ||||
| 			return false; | ||||
| 		 | ||||
| 		return true; | ||||
| 	} | ||||
| 	 | ||||
| 	public function transformsApplied() { | ||||
| 		return $this->transformsApplied; | ||||
| 	} | ||||
| 	 | ||||
| 	//apply all the transforms to the points in this gradient | ||||
| 	public function applyTransforms() { | ||||
| 		$transforms = $this->getTransforms(); | ||||
| 		foreach($transforms as $transform) { | ||||
| 			$oldCx = $this->cx; | ||||
| 			$oldCy = $this->cy; | ||||
| 			$oldFx = $this->fx; | ||||
| 			$oldFy = $this->fy; | ||||
| 			$this->cx = $transform->applyToX($oldCx, $oldCy); | ||||
| 			$this->cy = $transform->applyToY($oldCx, $oldCy); | ||||
| 			$this->fx = $transform->applyToX($oldFx, $oldFy); | ||||
| 			$this->fy = $transform->applyToY($oldFx, $oldFy); | ||||
| 		} | ||||
| 		$this->transformsApplied = true; | ||||
| 	} | ||||
| } | ||||
| ?> | ||||
							
								
								
									
										66
									
								
								svgparser/parser/objects/Rectangle.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										66
									
								
								svgparser/parser/objects/Rectangle.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,66 @@ | ||||
| <?php | ||||
| /* | ||||
| SVG to dojox.gfx Parser | ||||
| Copyright (C) 2009  Aaron Lindsay <aclindsay@aclindsay.com> | ||||
|  | ||||
| This program is free software; you can redistribute it and/or | ||||
| modify it under the terms of the GNU General Public License | ||||
| as published by the Free Software Foundation; either version 2 | ||||
| of the License, or (at your option) any later version. | ||||
|  | ||||
| This program is distributed in the hope that it will be useful, | ||||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
| GNU General Public License for more details. | ||||
|  | ||||
| You should have received a copy of the GNU General Public License | ||||
| along with this program; if not, write to the Free Software | ||||
| Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. | ||||
| */ | ||||
|  | ||||
| require_once("objects/Element.php"); | ||||
|  | ||||
| class Rectangle extends Element { | ||||
| 	private $x; | ||||
| 	private $y; | ||||
| 	private $height; | ||||
| 	private $width; | ||||
| 	private $rx; | ||||
| 	private $ry; | ||||
|  | ||||
| 	public function __construct() { | ||||
| 		$this->x = 0; | ||||
| 		$this->y = 0; | ||||
| 		$this->height = 0; | ||||
| 		$this->width = 0; | ||||
| 		$this->rx = null; | ||||
| 		$this->ry = null; | ||||
| 	} | ||||
|  | ||||
| 	public function getX() { return $this->x; } | ||||
| 	public function getY() { return $this->y; } | ||||
| 	public function getHeight() { return $this->height; } | ||||
| 	public function getWidth() { return $this->width; } | ||||
| 	public function getRx() { return ($this->rx != null)?$this->rx:0; } | ||||
| 	public function getRy() { return ($this->ry != null)?$this->ry:0; } | ||||
| 	public function getR() { | ||||
| 		if ($this->rx != null && $this->ry != null) | ||||
| 			return ($this->rx + $this->ry) / 2; | ||||
| 		else if ($this->rx != null) | ||||
| 			return $this->rx; | ||||
| 		else if ($this->ry != null) | ||||
| 			return $this->ry; | ||||
| 		else | ||||
| 			return 0; | ||||
| 	} | ||||
| 	 | ||||
| 	public function setX($x) { $this->x = $x; } | ||||
| 	public function setY($x) { $this->y = $x; } | ||||
| 	public function setHeight($x) { $this->height = $x; } | ||||
| 	public function setWidth($x) { $this->width = $x; } | ||||
| 	public function setRx($x) { $this->rx = $x; } | ||||
| 	public function setRy($x) { $this->ry = $x; } | ||||
| 	public function setR($r) { $this->setRx($r); $this->setRy($r); } | ||||
|  | ||||
| } | ||||
| ?> | ||||
							
								
								
									
										153
									
								
								svgparser/parser/objects/SVG.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										153
									
								
								svgparser/parser/objects/SVG.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,153 @@ | ||||
| <?php | ||||
| /* | ||||
| SVG to dojox.gfx Parser | ||||
| Copyright (C) 2009  Aaron Lindsay <aclindsay@aclindsay.com> | ||||
|  | ||||
| This program is free software; you can redistribute it and/or | ||||
| modify it under the terms of the GNU General Public License | ||||
| as published by the Free Software Foundation; either version 2 | ||||
| of the License, or (at your option) any later version. | ||||
|  | ||||
| This program is distributed in the hope that it will be useful, | ||||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
| GNU General Public License for more details. | ||||
|  | ||||
| You should have received a copy of the GNU General Public License | ||||
| along with this program; if not, write to the Free Software | ||||
| Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. | ||||
| */ | ||||
|  | ||||
| class SVG { | ||||
| 	private $paths; | ||||
| 	private $rects; | ||||
| 	private $circles; | ||||
| 	private $ellipses; | ||||
| 	private $lines; | ||||
| 	private $polylines; | ||||
| 	private $texts; | ||||
| 	private $linearGradients; | ||||
| 	private $radialGradients; | ||||
| 	 | ||||
| 	public function __construct() { | ||||
| 		$this->paths = array(); | ||||
| 		$this->rects = array(); | ||||
| 		$this->circles = array(); | ||||
| 		$this->ellipses = array(); | ||||
| 		$this->lines = array(); | ||||
| 		$this->polylines = array(); | ||||
| 		$this->texts = array(); | ||||
| 		 | ||||
| 		$this->linearGradients = array(); | ||||
| 		$this->radialGradients = array(); | ||||
| 	} | ||||
| 	 | ||||
| 	public function addPath($path) { | ||||
| 		$this->paths[] = $path; | ||||
| 	} | ||||
| 	public function getPaths() { | ||||
| 		return $this->paths; | ||||
| 	} | ||||
| 	 | ||||
| 	public function addRectangle($rect) { | ||||
| 		$this->rects[] = $rect; | ||||
| 	} | ||||
| 	public function getRectangles() { | ||||
| 		return $this->rects; | ||||
| 	} | ||||
| 	 | ||||
| 	public function addCircle($circle) { | ||||
| 		$this->circles[] = $circle; | ||||
| 	} | ||||
| 	public function getCircles() { | ||||
| 		return $this->circles; | ||||
| 	} | ||||
| 	 | ||||
| 	public function addEllipse($ellipse) { | ||||
| 		$this->ellipses[] = $ellipse; | ||||
| 	} | ||||
| 	public function getEllipses() { | ||||
| 		return $this->ellipses; | ||||
| 	} | ||||
| 	 | ||||
| 	public function addLine($line) { | ||||
| 		$this->lines[] = $line; | ||||
| 	} | ||||
| 	public function getLines() { | ||||
| 		return $this->lines; | ||||
| 	} | ||||
| 	 | ||||
| 	public function addPolyline($polyline) { | ||||
| 		$this->polylines[] = $polyline; | ||||
| 	} | ||||
| 	public function getPolylines() { | ||||
| 		return $this->polylines; | ||||
| 	} | ||||
|  | ||||
| 	public function addText($text) { | ||||
| 		$this->texts[] = $text; | ||||
| 	} | ||||
| 	public function getTexts() { | ||||
| 		return $this->texts; | ||||
| 	} | ||||
| 	 | ||||
| 	public function addLinearGradient($gradient) { | ||||
| 		$this->linearGradients[] = $gradient; | ||||
| 	} | ||||
| 	public function getLinearGradients() { | ||||
| 		return $this->linearGradients; | ||||
| 	} | ||||
| 	 | ||||
| 	public function addRadialGradient($gradient) { | ||||
| 		$this->radialGradients[] = $gradient; | ||||
| 	} | ||||
| 	public function getRadialGradients() { | ||||
| 		return $this->radialGradients; | ||||
| 	} | ||||
| 	 | ||||
| 	public function getCompleteLinearGradients() { | ||||
| 		$validGradients = array(); | ||||
| 		foreach($this->linearGradients as $gradient) { | ||||
| 			if ($gradient->isValid()) { | ||||
| 				$validGradients[] = $gradient; | ||||
| 			} else if ($gradient->getLink() != null) { | ||||
| 				$newGradient = $this->linkGradient($gradient); | ||||
| 				if ($newGradient->isValid()) { | ||||
| 					$validGradients[] = $newGradient; | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 		return $validGradients; | ||||
| 	} | ||||
| 	 | ||||
| 	public function getCompleteRadialGradients() { | ||||
| 		$validGradients = array(); | ||||
| 		foreach($this->radialGradients as $gradient) { | ||||
| 			if ($gradient->isValid()) { | ||||
| 				$validGradients[] = $gradient; | ||||
| 			} else if ($gradient->getLink() != null) { | ||||
| 				$newGradient = $this->linkGradient($gradient); | ||||
| 				if ($newGradient->isValid()) | ||||
| 					$validGradients[] = $gradient; | ||||
| 			} | ||||
| 		} | ||||
| 		return $validGradients; | ||||
| 	} | ||||
| 	 | ||||
| 	private function linkGradient($gradient) { | ||||
| 		//search through all gradients for one with an id matching the link field | ||||
| 		$link = $gradient->getLink(); | ||||
| 		$toLink = null; | ||||
| 		foreach($this->linearGradients as $match) { | ||||
| 			if ($match->getId() == $link) { | ||||
| 				$toLink = $match; | ||||
| 				break; | ||||
| 			} | ||||
| 		} | ||||
| 		if ($toLink != null) { | ||||
| 			$gradient->setStops($toLink->getStops()); | ||||
| 		} | ||||
| 		return $gradient; | ||||
| 	} | ||||
| } | ||||
| ?> | ||||
							
								
								
									
										61
									
								
								svgparser/parser/objects/Text.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										61
									
								
								svgparser/parser/objects/Text.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,61 @@ | ||||
| <?php | ||||
| /* | ||||
| SVG to dojox.gfx Parser | ||||
| Copyright (C) 2009  Aaron Lindsay <aclindsay@aclindsay.com> | ||||
|  | ||||
| This program is free software; you can redistribute it and/or | ||||
| modify it under the terms of the GNU General Public License | ||||
| as published by the Free Software Foundation; either version 2 | ||||
| of the License, or (at your option) any later version. | ||||
|  | ||||
| This program is distributed in the hope that it will be useful, | ||||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
| GNU General Public License for more details. | ||||
|  | ||||
| You should have received a copy of the GNU General Public License | ||||
| along with this program; if not, write to the Free Software | ||||
| Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. | ||||
| */ | ||||
|  | ||||
| class Text extends Element { | ||||
| 	private $x; | ||||
| 	private $y; | ||||
| 	private $text; | ||||
|  | ||||
| 	public function __construct() { | ||||
| 		$this->x = 0; | ||||
| 		$this->y = 0; | ||||
| 		$this->text = ""; | ||||
| 	} | ||||
|  | ||||
| 	public function getX() { return $this->x; } | ||||
| 	public function getY() { return $this->y; } | ||||
| 	public function getText() { return $this->text; } | ||||
| 	public function setX($x) { $this->x = $x; } | ||||
| 	public function setY($x) { $this->y = $x; } | ||||
| 	public function setText($x) { $this->text = $x; } | ||||
|  | ||||
| 	public function setTextAnchor($anchor) { | ||||
| 		$this->setStyle("text-anchor", $anchor); | ||||
| 	} | ||||
| 	public function getTextAnchor() { | ||||
| 		$anchor = $this->getStyle("text-anchor"); | ||||
| 		if ($anchor == null) | ||||
| 			return "start"; | ||||
| 		else | ||||
| 			return $anchor; | ||||
| 	} | ||||
|  | ||||
| 	public function setTextDecoration($decoration) { | ||||
| 		$this->setStyle("text-decoration", $decoration); | ||||
| 	} | ||||
| 	public function getTextDecoration() { | ||||
| 		$decoration = $this->getStyle("text-decoration"); | ||||
| 		if ($decoration == null) | ||||
| 			return "none"; | ||||
| 		else | ||||
| 			return $decoration; | ||||
| 	} | ||||
| } | ||||
| ?> | ||||
							
								
								
									
										106
									
								
								svgparser/parser/objects/Transform.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										106
									
								
								svgparser/parser/objects/Transform.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,106 @@ | ||||
| <?php | ||||
| /* | ||||
| SVG to dojox.gfx Parser | ||||
| Copyright (C) 2009  Aaron Lindsay <aclindsay@aclindsay.com> | ||||
|  | ||||
| This program is free software; you can redistribute it and/or | ||||
| modify it under the terms of the GNU General Public License | ||||
| as published by the Free Software Foundation; either version 2 | ||||
| of the License, or (at your option) any later version. | ||||
|  | ||||
| This program is distributed in the hope that it will be useful, | ||||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
| GNU General Public License for more details. | ||||
|  | ||||
| You should have received a copy of the GNU General Public License | ||||
| along with this program; if not, write to the Free Software | ||||
| Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. | ||||
| */ | ||||
|  | ||||
| class Transform { | ||||
| 	private $xx; | ||||
| 	private $xy; | ||||
| 	private $yx; | ||||
| 	private $yy; | ||||
| 	private $dx; | ||||
| 	private $dy; | ||||
| 	 | ||||
| 	public function __construct() { | ||||
| 		$this->xx = 1; | ||||
| 		$this->xy = 0; | ||||
| 		$this->yx = 0; | ||||
| 		$this->yy = 1; | ||||
| 		$this->dx = 0; | ||||
| 		$this->dy = 0; | ||||
| 	} | ||||
| 	 | ||||
| 	public function setFullMatrix($newXx, $newXy, $newYx, $newYy, $newDx, $newDy) { | ||||
| 		$this->xx = $newXx; | ||||
| 		$this->xy = $newXy; | ||||
| 		$this->yx = $newYx; | ||||
| 		$this->yy = $newYy; | ||||
| 		$this->dx = $newDx; | ||||
| 		$this->dy = $newDy; | ||||
| 	} | ||||
|  | ||||
| 	public function getXx() { return $this->xx; }  | ||||
| 	public function getXy() { return $this->xy; }  | ||||
| 	public function getYx() { return $this->yx; }  | ||||
| 	public function getYy() { return $this->yy; }  | ||||
| 	public function getDx() { return $this->dx; }  | ||||
| 	public function getDy() { return $this->dy; }  | ||||
| 	public function setXx($x) { $this->xx = $x; }  | ||||
| 	public function setXy($x) { $this->xy = $x; }  | ||||
| 	public function setYx($x) { $this->yx = $x; }  | ||||
| 	public function setYy($x) { $this->yy = $x; }  | ||||
| 	public function setDx($x) { $this->dx = $x; }  | ||||
| 	public function setDy($x) { $this->dy = $x; } | ||||
| 	 | ||||
| 	public function setTranslate($newDx, $newDy = 0) { | ||||
| 		$this->setFullMatrix(1,0,0,1,$newDx, $newDy); | ||||
| 	} | ||||
| 	 | ||||
| 	public function setScale($scaleX, $scaleY = -1) { | ||||
| 		if ($scaleY == -1) | ||||
| 			$scaleY = $scaleX; | ||||
| 		$this->setFullMatrix($scaleX, 0, 0, $scaleY, 0, 0); | ||||
| 	} | ||||
| 	 | ||||
| 	public function setRotate($angle) { | ||||
| 		$this->setFullMatrix(cos(deg2rad($angle)), sin(deg2rad($angle)), -sin(deg2rad($angle)), cos(deg2rad($angle)), 0, 0); | ||||
| 	} | ||||
| 	 | ||||
| 	public function setSkewX($angle) { | ||||
| 		$this->setFullMatrix(1, 0, tan(deg2rad($angle)), 1, 0, 0); | ||||
| 	} | ||||
| 	 | ||||
| 	public function setSkewY($angle) { | ||||
| 		$this->setFullMatrix(1, tan(deg2rad($angle)), 0, 1, 0, 0); | ||||
| 	} | ||||
| 	 | ||||
| 	public function applyToX($x, $y) { | ||||
| 		return $this->xx * $x + $this->xy * $y + $this->dx; | ||||
| 	} | ||||
| 	 | ||||
| 	public function applyToY($x, $y) { | ||||
| 		return $this->yx * $x + $this->yy * $y + $this->dy; | ||||
| 	} | ||||
|  | ||||
| 	//does multiplication of the form [$this]*[$other] | ||||
| 	//and stores the result in $this | ||||
| 	public function multiplyBy($other) { | ||||
| 		$xx = ($this->xx*$other->xx + $this->xy*$other->yx); | ||||
| 		$xy = ($this->xx*$other->xy + $this->xy*$other->yy); | ||||
| 		$dx = ($this->xx*$other->dx + $this->xy*$other->dy + $this->dx); | ||||
| 		$yx = ($this->yx*$other->xx + $this->yy*$other->yx); | ||||
| 		$yy = ($this->yx*$other->xy + $this->yy*$other->yy); | ||||
| 		$dy = ($this->yx*$other->yx + $this->yy*$other->dy + $this->dy); | ||||
| 		$this->setFullMatrix($xx, $xy, $yx, $yy, $dx, $dy); | ||||
| 	} | ||||
|  | ||||
| 	public function isIdentity() { | ||||
| 		return ($this->xx == 1 && $this->xy == 0 && $this->yx == 0 && $this->yy == 1 && $this->dx == 0 && $this->dy == 0); | ||||
| 	} | ||||
| } | ||||
| ?> | ||||
							
								
								
									
										397
									
								
								svgparser/parser/parser/Parser.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										397
									
								
								svgparser/parser/parser/Parser.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,397 @@ | ||||
| <?php | ||||
| /* | ||||
| SVG to dojox.gfx Parser | ||||
| Copyright (C) 2009  Aaron Lindsay <aclindsay@aclindsay.com> | ||||
|  | ||||
| This program is free software; you can redistribute it and/or | ||||
| modify it under the terms of the GNU General Public License | ||||
| as published by the Free Software Foundation; either version 2 | ||||
| of the License, or (at your option) any later version. | ||||
|  | ||||
| This program is distributed in the hope that it will be useful, | ||||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | ||||
| GNU General Public License for more details. | ||||
|  | ||||
| You should have received a copy of the GNU General Public License | ||||
| along with this program; if not, write to the Free Software | ||||
| Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. | ||||
| */ | ||||
|  | ||||
| require_once("objects/SVG.php"); | ||||
|  | ||||
| require_once("objects/Path.php"); | ||||
| require_once("objects/Rectangle.php"); | ||||
| require_once("objects/Circle.php"); | ||||
| require_once("objects/Ellipse.php"); | ||||
| require_once("objects/Line.php"); | ||||
| require_once("objects/Polyline.php"); | ||||
| require_once("objects/Line.php"); | ||||
| require_once("objects/Text.php"); | ||||
|  | ||||
| require_once("objects/Gradient.php"); | ||||
| require_once("objects/RadialGradient.php"); | ||||
| require_once("objects/LinearGradient.php"); | ||||
| require_once("objects/GradientStop.php"); | ||||
|  | ||||
| require_once("objects/Transform.php"); | ||||
|  | ||||
| class Parser { | ||||
| 	private $elementStack; | ||||
| 	private $svg; | ||||
| 	private $transformStack; | ||||
| 	private $characterDataStack; | ||||
| 	 | ||||
| 	public function parse($SVGstring) { | ||||
| 		//reset the stack of elements in case someone already ran this | ||||
| 		unset($this->elementStack); | ||||
| 		$this->elementStack = array(); | ||||
|  | ||||
| 		//reset the stack of transforms in case someone already ran this | ||||
| 		unset($this->transformStack); | ||||
| 		$this->transformStack = array(); | ||||
|  | ||||
| 		//reset the stack of character data (this is used for the text fields) | ||||
| 		$this->characterDataStack = array(); | ||||
| 		 | ||||
| 		$this->svg = new SVG(); | ||||
| 		 | ||||
| 		//create the parser object | ||||
| 		$parser = xml_parser_create(); | ||||
| 		xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);		//set to 0 so all the elements don't get converted to upper case | ||||
| 		xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);		//we don't like extra white-space so skip it | ||||
| 		 | ||||
| 		//set the handlers | ||||
| 		xml_set_element_handler($parser, array($this, "startElementHandler"), array($this,"endElementHandler")); | ||||
| 		xml_set_character_data_handler($parser, array($this, "characterDataHandler")); | ||||
| 		 | ||||
| 		xml_parse($parser, $SVGstring); | ||||
| 		xml_parser_free($parser);	//parser... be free!!! | ||||
| 		 | ||||
| 		return $this->svg; | ||||
| 	} | ||||
| 	 | ||||
| 	private function startElementHandler($parser, $name, $attribs) { | ||||
| 		$currentTransform = new Transform(); | ||||
|  | ||||
| 		switch ($name) { | ||||
| 			case "path": | ||||
| 				$path = new Path(); | ||||
| 				if (array_key_exists("id", $attribs)) | ||||
| 					$path->setId($attribs["id"]); | ||||
| 				if (array_key_exists("d", $attribs)) | ||||
| 					$path->setPath($attribs["d"]); | ||||
| 				if (array_key_exists("style", $attribs)) | ||||
| 					$path->setStyles($attribs["style"]); | ||||
| 				if (array_key_exists("stroke", $attribs)) | ||||
| 					$path->setStroke($attribs["stroke"]); | ||||
| 				if (array_key_exists("stroke-width", $attribs)) | ||||
| 					$path->setStrokeWidth($attribs["stroke-width"]); | ||||
| 				if (array_key_exists("stroke-linecap", $attribs)) | ||||
| 					$path->setStrokeLinecap($attribs["stroke-linecap"]); | ||||
| 				if (array_key_exists("fill", $attribs)) | ||||
| 					$path->setFill($attribs["fill"]); | ||||
| 				if (array_key_exists("transform", $attribs)) { | ||||
| 					$path->setTransforms($attribs["transform"]); | ||||
| 					$currentTransform = $path->getTransform(); | ||||
| 				} | ||||
| 				$this->elementStack[] = $path; | ||||
| 				break; | ||||
| 			case "rect": | ||||
| 				$rect = new Rectangle(); | ||||
| 				if (array_key_exists("id", $attribs)) | ||||
| 					$rect->setId($attribs["id"]); | ||||
| 				if (array_key_exists("x", $attribs)) | ||||
| 					$rect->setX($attribs["x"]); | ||||
| 				if (array_key_exists("y", $attribs)) | ||||
| 					$rect->setY($attribs["y"]); | ||||
| 				if (array_key_exists("height", $attribs)) | ||||
| 					$rect->setHeight($attribs["height"]); | ||||
| 				if (array_key_exists("width", $attribs)) | ||||
| 					$rect->setWidth($attribs["width"]); | ||||
| 				if (array_key_exists("rx", $attribs)) | ||||
| 					$rect->setRx($attribs["rx"]); | ||||
| 				if (array_key_exists("ry", $attribs)) | ||||
| 					$rect->setRy($attribs["ry"]); | ||||
| 				if (array_key_exists("style", $attribs)) | ||||
| 					$rect->setStyles($attribs["style"]); | ||||
| 				if (array_key_exists("stroke", $attribs)) | ||||
| 					$rect->setStroke($attribs["stroke"]); | ||||
| 				if (array_key_exists("stroke-width", $attribs)) | ||||
| 					$rect->setStrokeWidth($attribs["stroke-width"]); | ||||
| 				if (array_key_exists("stroke-linecap", $attribs)) | ||||
| 					$rect->setStrokeLinecap($attribs["stroke-linecap"]); | ||||
| 				if (array_key_exists("fill", $attribs)) | ||||
| 					$rect->setFill($attribs["fill"]); | ||||
| 				if (array_key_exists("transform", $attribs)) { | ||||
| 					$rect->setTransforms($attribs["transform"]); | ||||
| 					$currentTransform = $rect->getTransform(); | ||||
| 				} | ||||
| 				$this->elementStack[] = $rect; | ||||
| 				break; | ||||
| 			case "circle": | ||||
| 				$circle = new Circle(); | ||||
| 				if (array_key_exists("id", $attribs)) | ||||
| 					$circle->setId($attribs["id"]); | ||||
| 				if (array_key_exists("cx", $attribs)) | ||||
| 					$circle->setCx($attribs["cx"]); | ||||
| 				if (array_key_exists("cy", $attribs)) | ||||
| 					$circle->setCy($attribs["cy"]); | ||||
| 				if (array_key_exists("r", $attribs)) | ||||
| 					$circle->setR($attribs["r"]); | ||||
| 				if (array_key_exists("style", $attribs)) | ||||
| 					$circle->setStyles($attribs["style"]); | ||||
| 				if (array_key_exists("stroke", $attribs)) | ||||
| 					$circle->setStroke($attribs["stroke"]); | ||||
| 				if (array_key_exists("stroke-width", $attribs)) | ||||
| 					$circle->setStrokeWidth($attribs["stroke-width"]); | ||||
| 				if (array_key_exists("stroke-linecap", $attribs)) | ||||
| 					$circle->setStrokeLinecap($attribs["stroke-linecap"]); | ||||
| 				if (array_key_exists("fill", $attribs)) | ||||
| 					$circle->setFill($attribs["fill"]); | ||||
| 				if (array_key_exists("transform", $attribs)) { | ||||
| 					$circle->setTransforms($attribs["transform"]); | ||||
| 					$currentTransform = $circle->getTransform(); | ||||
| 				} | ||||
| 				$this->elementStack[] = $circle; | ||||
| 				break; | ||||
| 			case "ellipse": | ||||
| 				$ellipse = new Ellipse(); | ||||
| 				if (array_key_exists("id", $attribs)) | ||||
| 					$ellipse->setId($attribs["id"]); | ||||
| 				if (array_key_exists("cx", $attribs)) | ||||
| 					$ellipse->setCx($attribs["cx"]); | ||||
| 				if (array_key_exists("cy", $attribs)) | ||||
| 					$ellipse->setCy($attribs["cy"]); | ||||
| 				if (array_key_exists("rx", $attribs)) | ||||
| 					$ellipse->setRx($attribs["rx"]); | ||||
| 				if (array_key_exists("ry", $attribs)) | ||||
| 					$ellipse->setRy($attribs["ry"]); | ||||
| 				if (array_key_exists("style", $attribs)) | ||||
| 					$ellipse->setStyles($attribs["style"]); | ||||
| 				if (array_key_exists("stroke", $attribs)) | ||||
| 					$ellipse->setStroke($attribs["stroke"]); | ||||
| 				if (array_key_exists("stroke-width", $attribs)) | ||||
| 					$ellipse->setStrokeWidth($attribs["stroke-width"]); | ||||
| 				if (array_key_exists("stroke-linecap", $attribs)) | ||||
| 					$ellipse->setStrokeLinecap($attribs["stroke-linecap"]); | ||||
| 				if (array_key_exists("fill", $attribs)) | ||||
| 					$ellipse->setFill($attribs["fill"]); | ||||
| 				if (array_key_exists("transform", $attribs)) { | ||||
| 					$ellipse->setTransforms($attribs["transform"]); | ||||
| 					$currentTransform = $ellipse->getTransform(); | ||||
| 				} | ||||
| 				$this->elementStack[] = $ellipse; | ||||
| 				break; | ||||
| 			case "line": | ||||
| 				$line = new Line(); | ||||
| 				if (array_key_exists("id", $attribs)) | ||||
| 					$line->setId($attribs["id"]); | ||||
| 				if (array_key_exists("x1", $attribs)) | ||||
| 					$line->setX1($attribs["x1"]); | ||||
| 				if (array_key_exists("y1", $attribs)) | ||||
| 					$line->setY1($attribs["y1"]); | ||||
| 				if (array_key_exists("x2", $attribs)) | ||||
| 					$line->setX2($attribs["x2"]); | ||||
| 				if (array_key_exists("y2", $attribs)) | ||||
| 					$line->setY2($attribs["y2"]); | ||||
| 				if (array_key_exists("style", $attribs)) | ||||
| 					$line->setStyles($attribs["style"]); | ||||
| 				if (array_key_exists("stroke", $attribs)) | ||||
| 					$line->setStroke($attribs["stroke"]); | ||||
| 				if (array_key_exists("stroke-width", $attribs)) | ||||
| 					$line->setStrokeWidth($attribs["stroke-width"]); | ||||
| 				if (array_key_exists("stroke-linecap", $attribs)) | ||||
| 					$line->setStrokeLinecap($attribs["stroke-linecap"]); | ||||
| 				if (array_key_exists("transform", $attribs)) { | ||||
| 					$line->setTransforms($attribs["transform"]); | ||||
| 					$currentTransform = $line->getTransform(); | ||||
| 				} | ||||
| 				$this->elementStack[] = $line; | ||||
| 				break; | ||||
| 			case "polyline": | ||||
| 				$polyline = new Polyline(); | ||||
| 				if (array_key_exists("id", $attribs)) | ||||
| 					$polyline->setId($attribs["id"]); | ||||
| 				if (array_key_exists("points", $attribs)) | ||||
| 					$polyline->setPoints($attribs["points"]); | ||||
| 				if (array_key_exists("style", $attribs)) | ||||
| 					$polyline->setStyles($attribs["style"]); | ||||
| 				if (array_key_exists("stroke", $attribs)) | ||||
| 					$polyline->setStroke($attribs["stroke"]); | ||||
| 				if (array_key_exists("stroke-width", $attribs)) | ||||
| 					$polyline->setStrokeWidth($attribs["stroke-width"]); | ||||
| 				if (array_key_exists("stroke-linecap", $attribs)) | ||||
| 					$polyline->setStrokeLinecap($attribs["stroke-linecap"]); | ||||
| 				if (array_key_exists("transform", $attribs)) { | ||||
| 					$polyline->setTransforms($attribs["transform"]); | ||||
| 					$currentTransform = $polyline->getTransform(); | ||||
| 				} | ||||
| 				$this->elementStack[] = $polyline; | ||||
| 				break; | ||||
| 			case "text": | ||||
| 			case "tspan": | ||||
| 				$text = new Text(); | ||||
| 				if (array_key_exists("id", $attribs)) | ||||
| 					$text->setId($attribs["id"]); | ||||
| 				if (array_key_exists("x", $attribs)) | ||||
| 					$text->setX($attribs["x"]); | ||||
| 				if (array_key_exists("y", $attribs)) | ||||
| 					$text->setY($attribs["y"]); | ||||
| 				if (array_key_exists("style", $attribs)) | ||||
| 					$text->setStyles($attribs["style"]); | ||||
| 				if (array_key_exists("stroke", $attribs)) | ||||
| 					$text->setStroke($attribs["stroke"]); | ||||
| 				if (array_key_exists("stroke-width", $attribs)) | ||||
| 					$text->setStrokeWidth($attribs["stroke-width"]); | ||||
| 				if (array_key_exists("stroke-linecap", $attribs)) | ||||
| 					$text->setStrokeLinecap($attribs["stroke-linecap"]); | ||||
| 				if (array_key_exists("fill", $attribs)) | ||||
| 					$text->setFill($attribs["fill"]); | ||||
| 				if (array_key_exists("text-anchor", $attribs)) | ||||
| 					$text->setTextAnchor($attribs["text-anchor"]); | ||||
| 				if (array_key_exists("text-decoration", $attribs)) | ||||
| 					$text->setTextDecoration($attribs["text-decoration"]); | ||||
| 				if (array_key_exists("transform", $attribs)) { | ||||
| 					$text->setTransforms($attribs["transform"]); | ||||
| 					$currentTransform = $text->getTransform(); | ||||
| 				} | ||||
| 				$this->elementStack[] = $text; | ||||
| 				break; | ||||
| 			case "linearGradient": | ||||
| 				$linearGradient = new LinearGradient(); | ||||
| 				if (array_key_exists("id", $attribs)) | ||||
| 					$linearGradient->setId($attribs["id"]); | ||||
| 				if (array_key_exists("style", $attribs)) | ||||
| 					$linearGradient->setStyles($attribs["style"]); | ||||
| 				if (array_key_exists("gradientTransform", $attribs)) | ||||
| 					$linearGradient->setTransforms($attribs["gradientTransform"]); | ||||
| 				if (array_key_exists("xlink:href", $attribs)) | ||||
| 					$linearGradient->setLink($attribs["xlink:href"]); | ||||
| 				if (array_key_exists("x1", $attribs)) | ||||
| 					$linearGradient->setX1($attribs["x1"]); | ||||
| 				if (array_key_exists("y1", $attribs)) | ||||
| 					$linearGradient->setY1($attribs["y1"]); | ||||
| 				if (array_key_exists("x2", $attribs)) | ||||
| 					$linearGradient->setX2($attribs["x2"]); | ||||
| 				if (array_key_exists("y2", $attribs)) | ||||
| 					$linearGradient->setY2($attribs["y2"]); | ||||
| 				$this->elementStack[] = $linearGradient; | ||||
| 				break; | ||||
| 			case "stop": | ||||
| 				$stop = new GradientStop(); | ||||
| 				if (array_key_exists("id", $attribs)) | ||||
| 					$stop->setId($attribs["id"]); | ||||
| 				if (array_key_exists("style", $attribs)) | ||||
| 					$stop->setStyles($attribs["style"]); | ||||
| 				if (array_key_exists("offset", $attribs)) | ||||
| 					$stop->setOffset($attribs["offset"]); | ||||
| 				$this->elementStack[] = $stop; | ||||
| 				break; | ||||
| 			case "radialGradient": | ||||
| 				$radialGradient = new RadialGradient(); | ||||
| 				if (array_key_exists("id", $attribs)) | ||||
| 					$radialGradient->setId($attribs["id"]); | ||||
| 				if (array_key_exists("style", $attribs)) | ||||
| 					$radialGradient->setStyles($attribs["style"]); | ||||
| 				if (array_key_exists("gradientTransform", $attribs)) | ||||
| 					$radialGradient->setTransforms($attribs["gradientTransform"]); | ||||
| 				if (array_key_exists("xlink:href", $attribs)) | ||||
| 					$radialGradient->setLink($attribs["xlink:href"]); | ||||
| 				if (array_key_exists("cx", $attribs)) | ||||
| 					$radialGradient->setCx($attribs["cx"]); | ||||
| 				if (array_key_exists("cy", $attribs)) | ||||
| 					$radialGradient->setCy($attribs["cy"]); | ||||
| 				if (array_key_exists("r", $attribs)) | ||||
| 					$radialGradient->setR($attribs["r"]); | ||||
| 				if (array_key_exists("fx", $attribs)) | ||||
| 					$radialGradient->setFx($attribs["fx"]); | ||||
| 				if (array_key_exists("fy", $attribs)) | ||||
| 					$radialGradient->setFy($attribs["fy"]); | ||||
| 				$this->elementStack[] = $radialGradient; | ||||
| 				break; | ||||
| 			case "g": | ||||
| 				if (array_key_exists("transform", $attribs)) { | ||||
| 					$element = new Element(); | ||||
| 					$element->setTransforms($attribs["transform"]); | ||||
| 					$currentTransform = $element->getTransform(); | ||||
| 				} | ||||
| 				break; | ||||
| 		} | ||||
| 		//dump the transforms on the stack of them so if there are any nested elements, they can access them | ||||
| 		$this->transformStack[] = $currentTransform; | ||||
| 	} | ||||
| 	 | ||||
| 	private function characterDataHandler($parser, $data) { | ||||
| 		$this->characterDataStack[] = $data; | ||||
| 	} | ||||
| 	 | ||||
| 	private function endElementHandler($parser, $name) { | ||||
| 		//as well as the last text data | ||||
| 		$lastText = array_pop($this->characterDataStack); | ||||
|  | ||||
| 		switch ($name) { | ||||
| 			case "path": | ||||
| 				$element = array_pop($this->elementStack); | ||||
| 				$element->setTransform($this->getFullCurrentTransform()); | ||||
| 				$this->svg->addPath($element); | ||||
| 				break; | ||||
| 			case "rect": | ||||
| 				$element = array_pop($this->elementStack); | ||||
| 				$element->setTransform($this->getFullCurrentTransform()); | ||||
| 				$this->svg->addRectangle($element); | ||||
| 				break; | ||||
| 			case "circle": | ||||
| 				$element = array_pop($this->elementStack); | ||||
| 				$element->setTransform($this->getFullCurrentTransform()); | ||||
| 				$this->svg->addCircle($element); | ||||
| 				break; | ||||
| 			case "ellipse": | ||||
| 				$element = array_pop($this->elementStack); | ||||
| 				$element->setTransform($this->getFullCurrentTransform()); | ||||
| 				$this->svg->addEllipse($element); | ||||
| 				break; | ||||
| 			case "line": | ||||
| 				$element = array_pop($this->elementStack); | ||||
| 				$element->setTransform($this->getFullCurrentTransform()); | ||||
| 				$this->svg->addLine($element); | ||||
| 				break; | ||||
| 			case "polyline": | ||||
| 				$element = array_pop($this->elementStack); | ||||
| 				$element->setTransform($this->getFullCurrentTransform()); | ||||
| 				$this->svg->addPolyline($element); | ||||
| 				break; | ||||
| 			case "text": | ||||
| 			case "tspan": | ||||
| 				$element = array_pop($this->elementStack); | ||||
| 				$element->setTransform($this->getFullCurrentTransform()); | ||||
| 				$element->setText($lastText); | ||||
| 				//add the element only if the text has at least some non-whitespace | ||||
| 				if (trim($lastText) != "") | ||||
| 					$this->svg->addText($element); | ||||
| 				break; | ||||
| 			case "linearGradient": | ||||
| 				$this->svg->addLinearGradient(array_pop($this->elementStack)); | ||||
| 				break; | ||||
| 			case "stop": | ||||
| 				$stop = array_pop($this->elementStack); | ||||
| 				if ($this->elementStack[count($this->elementStack)-1] instanceof Gradient) | ||||
| 					$this->elementStack[count($this->elementStack)-1]->addStop($stop); | ||||
| 				break; | ||||
| 			case "radialGradient": | ||||
| 				$this->svg->addRadialGradient(array_pop($this->elementStack)); | ||||
| 				break; | ||||
| 		} | ||||
|  | ||||
| 		//pop the last transform off the stack | ||||
| 		array_pop($this->transformStack); | ||||
| 	} | ||||
|  | ||||
| 	private function getFullCurrentTransform() { | ||||
| 		$one = new Transform(); | ||||
| 		foreach ($this->transformStack as $transform) | ||||
| 			$one->multiplyBy($transform); | ||||
| 		return $one; | ||||
| 	} | ||||
| } | ||||
| ?> | ||||
		Reference in New Issue
	
	Block a user