dongyu1918 2012-05-07 21:28
浏览 115
已采纳

SVG将组移至其他组

Want to move a group into another group, but on some way it ends up in a huge execution time, and the script is never ending. the problem is in the foreach loop rest function ok. I don't see any mistake

<?php
// fouten laten zien
error_reporting(~0); 
ini_set('display_errors', 1); 

// test bestand
$bestand = "00000000346.svg";

// maak nieuwe dom
$dom = new DOMDocument; 

// laat svg in dom
$dom->load($bestand);

// krijg svg element
$svg = $dom->getElementsByTagName("svg")->item(0);

// toevoegen link attribute
$svg->setAttribute("xmlns:xlink", "http://www.w3.org/1999/xlink");

// maak script tag
$script = $dom->createElement("script");

// zet script link
$script->setAttribute("xlink:href", "svg_zoom_pan.js");

// toevoegen aan svg
$dom->documentElement->appendChild($script);

// maak groep tag
$svgroot = $dom->createElement("g");

// zet een id
$svgroot->setAttribute("id", "svgroot");

// toevoegen aan svg
$dom->documentElement->appendChild($svgroot);

// krijg alle groepen
$groups = $dom->getElementsByTagName("g");

// doorloop groepen
foreach($groups as $group) {

    if($group->getAttribute("id") != "svgroot") {

        // clone groep
        $cloned = $group->cloneNode(true);

        // toevoegen aan svgroot groep  
        $dom->getElementById("svgroot")->appendChild($cloned);

    }
}

// opslaan bestand
$dom->save("svg_" . $bestand);

?>
  • 写回答

2条回答 默认 最新

  • dsrnwngq411594 2012-05-13 06:51
    关注

    If have find the solution to move:

    // doorloop groepen
    foreach($groups as $group) {
    
        // verplaats alleen de andere groepen maar niet de root 
        if($group->getAttribute("id") != "svgroot") {
    
            // verplaats groep in svgroot       
            $moved = $group->parentNode->removeChild($group);
    
            // toevoegen aan svgroot groep  
            $firstgroup->appendChild($moved);
    
        }
    }
    

    But it mesh up the svg code?

    part of original svg:

    <?xml version="1.0" standalone="no"?><svg xmlns="http://www.w3.org/2000/svg" width="595.000" height="841.000" viewBox="0.0 0.0 595.000 841.000">
      <title>Produce by DWG to SVG Converter 2012 MX</title>
      <desc>Produce by DWG to SVG Converter 2012 MX</desc>
    <g id="000-Onderlegger" display="visible">
    <g><path d="M382.47 595.5L382.47 404.1"
    fill="none" stroke="RGB(0,124,165)" stroke-width="0.709"/>
    </g>
    <g><path d="M382.47 404.1L384.45 404.1"
    fill="none" stroke="RGB(0,124,165)" stroke-width="0.709"/>
    </g>
    

    part of the parsed code:

    <?xml version="1.0" standalone="no"?>
    <?xml-stylesheet href="svg.css" type="text/css"?>
    <svg xmlns="http://www.w3.org/2000/svg" width="595.000" height="841.000" viewBox="0.0 0.0 595.000 841.000" onload="init(evt)" xmlns:xlink="http://www.w3.org/1999/xlink">
      <script xlink:href="svg-zoom-pan.js"/>
      <g id="svgroot">
        <g id="000-Onderlegger" display="none">
          <g>
            <path d="M382.47 404.1L384.45 404.1" fill="none" stroke="RGB(0,124,165)" stroke-width="0.709"/>
          </g>
          <g>
            <path d="M384.45 396.46L382.47 396.46" fill="none" stroke="RGB(0,124,165)" stroke-width="0.709"/>
          </g>
    

    here the difference:

    <g>
    <path d="M382.47 595.5L382.47 404.1" fill="none" stroke="RGB(0,124,165)" stroke-width="0.709"/>
    </g>
    
    <g>
    <path d="M382.47 404.1L384.45 404.1" fill="none" stroke="RGB(0,124,165)" stroke-width="0.709"/>
    </g>
    

    Have someone any idea why this happend?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 Python如何后台操作Vmwake虚拟机键鼠
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容