/**
  * Return the string representation of object
  *
  * @return string representation of object
  */
 public function __toString()
 {
     $vars = get_object_vars($this);
     $result = '';
     if (is_array($vars)) {
         foreach ($vars as $line => $info) {
             if (isset($info)) {
                 $line = SVGStyle::fromCamelCase($line);
                 $result .= "{$line}:{$info};";
             }
         }
     }
     return $result;
 }
Ejemplo n.º 2
0
#add some javascript functions
$svg->addScript("\n    function changeColor(evt, element)\n    {\n        destination = document.getElementById('destination');\n\n        if ( evt.ctrlKey )\n        {\n            destination.style.stroke = element.style.fill;\n        }\n        else\n        {\n            destination.style.fill = element.style.fill;\n        }\n\n        evt.preventDefault();\n        return false;\n    }\n");
#mount a simple color array
$colors[] = 'red';
$colors[] = 'green';
$colors[] = 'blue';
$colors[] = 'yellow';
$colors[] = 'orange';
$colors[] = 'gray';
$colors[] = 'black';
$colors[] = 'white';
$text = SVGText::getInstance(10, 25, null, 'Left click for fill - control click for stroke');
$svg->addShape($text);
foreach ($colors as $line => $color) {
    $rect = SVGRect::getInstance($line * 60 + 10, 40, null, 50, 50);
    $style = new SVGStyle();
    $style->setFill($color);
    $style->setStroke("darkGray", 1);
    $rect->setStyle($style);
    $rect->addOnclick("return changeColor(evt,this);");
    $rect->addAttribute("onmouseover", "this.style.stroke = 'lightGray';");
    $rect->addAttribute("onmouseout", "this.style.stroke = 'gray';");
    $svg->addShape($rect);
}
$rect = SVGRect::getInstance(140, 100, 'destination', 200, 200);
$style = new SVGStyle();
$style->setFill('none');
$style->setStroke("darkGray", 5);
$rect->setStyle($style);
$svg->addShape($rect);
$svg->output();
 *
 *   You should have received a copy of the GNU Library General Public
 *   License along with this program; if not, access
 *   http://www.fsf.org/licensing/licenses/lgpl.html or write to the
 *   Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 * ----------------------------------------------------------------------
 */
require_once "../svglib/svglib.php";
$rotate = @$_REQUEST['rotate'];
//rotate the square using passed angle
$translate = @$_REQUEST['translate'];
//rotate the square using passed angle
$file = @$_REQUEST['file'];
//load the file passed
$fill = @$_REQUEST['fill'] ? @$_REQUEST['fill'] : 'red';
$stroke = @$_REQUEST['stroke'] ? @$_REQUEST['stroke'] : 'black';
$svg = SVGDocument::getInstance($file);
$style = new SVGStyle();
$style->setFill($fill);
$style->setStroke($stroke);
$rect = SVGRect::getInstance(50, 50, 'myRect', 100, 100, $style);
if ($rotate) {
    //uses the x and y properties to align the rect
    $rect->rotate($rotate, $rect->getX() * 2, $rect->getY() * 2);
}
if ($translate) {
    $translate = explode(',', $translate);
    $rect->translate($translate[0], $translate[1]);
}
$svg->addShape($rect);
$svg->output();
Ejemplo n.º 4
0
$rect->setRound(30);
$svg->addShape($rect);
#add the rect to svg
$style = new SVGStyle();
$style->setFill('green');
$style->setStroke('black', 5);
$circle = SVGCircle::getInstance(200, 100, 20, null, $style);
$svg->addShape($circle);
$ellipse = SVGEllipse::getInstance(200, 200, 100, 40);
$ellipse->rotate(-30, 200, 200);
$style2 = new SVGStyle();
$style2->setFill('none');
$style2->setStroke('blue', 3);
$ellipse->setStyle($style2);
$svg->addShape($ellipse);
$style = new SVGStyle();
#create a style object
#set fill and stroke
$style->setFill('#f2f2f2');
$style->setStroke('#e1a100');
$style->setStrokeWidth(2);
#create a text
$text = SVGText::getInstance(22, 50, 'myText', 'This is a text', $style);
$svg->addShape($text);
#$svg->addShape( SVGPath::getInstance( array('m 58,480','639,1'), 'myPath', 'fill:none;stroke:#000000;stroke-width:1px;') );#create a path
$svg->addShape(SVGLine::getInstance(50, 50, 500, 500, null, $style));
#many types of output
try {
    $svg->asXML(getcwd() . '/output/output.svg');
    #svg
    #example how to using SVG Inkscape
Ejemplo n.º 5
0
 *   You should have received a copy of the GNU Library General Public
 *   License along with this program; if not, access
 *   http://www.fsf.org/licensing/licenses/lgpl.html or write to the
 *   Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *----------------------------------------------------------------------
 */
require_once "../svglib/svglib.php";
$svg = SVGDocument::getInstance();
#a way to create a stop
$stop = SVGStop::getInstance();
$stop->setColor('red');
$stop->setOpacity(1);
$stops[] = $stop;
#a second way to create a stop
$stops[] = SVGStop::getInstance(null, "stop-color:blue;stop-opacity:1");
$stops[] = SVGStop::getInstance(null, "stop-color:black;stop-opacity:1");
$gradient = SVGLinearGradient::getInstance(null, $stops);
$svg->addDefs($gradient);
$style = new SVGStyle();
$style->setFill($gradient);
$svg->addShape(SVGRect::getInstance(10, 20, null, '100', '200', $style));
#second rect
$stops2[] = SVGStop::getInstance(null, "stop-color:yellow;stop-opacity:1");
$stops2[] = SVGStop::getInstance(null, "stop-color:green;stop-opacity:1");
$radial = SVGRadialGradient::getInstance(null, $stops2);
$svg->addDefs($radial);
$style2 = new SVGStyle();
$style2->setFill($radial);
$rect2 = SVGRect::getInstance(150, 20, null, 100, 200, $style2);
$svg->addShape($rect2);
$svg->output();