带有RTL的SVG支持阿拉伯语

时间:2019-02-14 10:27:35

标签: javascript svg

我在容器内创建了一个SVG。正如我尝试将SVG本身的位置和容器方向设置为RTL一样,对节点上的位置没有影响。我在g标签中包含了圆圈和文本,该标签本身包装在SVG标签中。

<svg id="sequenceSVG" xmlns="http://www.w3.org/2000/svg" width="100%" height="100%" preserveAspectRatio="xMinYMin meet" viewBox="-30 -20 680 350" class="svg-content svg-content-responsive">
  <defs>
    <marker id="end-arrow" viewBox="0 -5 10 10" refX="44" markerWidth="5" markerHeight="10" orient="auto">
    <path d="M0,-5L10,0L0,5" fill="#4A4A4A"></path>
    </marker>
  </defs>
  <defs>
    <radialGradient id="color-gradient">
      <stop offset="90%" style="stop-color:#FFFFFF;"></stop>
      <stop offset="85%" style="stop-color:#E5E5E5;"></stop>
    </radialGradient>
  </defs>
  <path class="filled" stroke="#78D64B" stroke-width="2" fill="none" d="M272,262.5L136,210L136,105"></path>
  <path class="dashed" stroke="#78D64B" stroke-width="2" style="stroke-dasharray: 4, 4; marker-end: url(&quot;#end-arrow&quot;);" d="M136,105L272,17.5"></path>
  <path class="link dragline hidden" stroke="#78D64B" stroke-width="2" d="M0,0L0,0"></path>
  <g id="circle-group-0">
    <circle cx="136" cy="105" r="25" class="filled" stroke-width="2px" fill="#78D64B" stroke="#4A4A4A" stroke-opacity="0.1" id="MC_SD_001_1_0_0" sequence="0"></circle>
    <text class="node-text" fill="#4A4A4A" text-anchor="middle" stroke="#4A4A4A" startOffset="50%" stroke-width="1px" alignment-baseline="middle" dominant-baseline="central" dx="136" dy="105">1</text>
  </g>
  <g id="circle-group-1">
    <circle cx="408" cy="70" r="25" class="empty" stroke-width="2px" fill="url(&quot;#color-gradient&quot;)" stroke="#FFFFFF" stroke-opacity="0.1" id="MC_SD_001_1_0_1" sequence="1"></circle>
    <text class="node-text" fill="#78D64B" text-anchor="middle" stroke="#78D64B" startOffset="50%" stroke-width="1px" alignment-baseline="middle" dominant-baseline="central" dx="408" dy="70">A</text>
  </g>
  <g id="circle-group-2">
    <circle cx="136" cy="210" r="25" class="filled" stroke-width="2px" fill="#78D64B" stroke="#4A4A4A" stroke-opacity="0.1" id="MC_SD_001_1_0_2" sequence="2"></circle>
    <text class="node-text" fill="#4A4A4A" text-anchor="middle" stroke="#4A4A4A" startOffset="50%" stroke-width="1px" alignment-baseline="middle" dominant-baseline="central" dx="136" dy="210">3</text>
  </g>
  <g id="circle-group-3">
    <circle cx="408" cy="157.5" r="25" class="empty" stroke-width="2px" fill="url(&quot;#color-gradient&quot;)" stroke="#FFFFFF" stroke-opacity="0.1" id="MC_SD_001_1_0_3" sequence="3"></circle>
    <text class="node-text" fill="#78D64B" text-anchor="middle" stroke="#78D64B" startOffset="50%" stroke-width="1px" alignment-baseline="middle" dominant-baseline="central" dx="408" dy="157.5">C</text>
  </g>
  <g id="circle-group-4">
    <circle cx="272" cy="262.5" r="25" class="filled" stroke-width="2px" fill="#78D64B" stroke="#4A4A4A" stroke-opacity="0.1" id="MC_SD_001_1_0_4" sequence="4"></circle>
    <text class="node-text" fill="#4A4A4A" text-anchor="middle" stroke="#4A4A4A" startOffset="50%" stroke-width="1px" alignment-baseline="middle" dominant-baseline="central" dx="272" dy="262.5">5</text>
  </g>
  <g id="circle-group-5">
    <circle cx="272" cy="17.5" r="25" class="empty dashed" stroke-width="2px" fill="url(&quot;#color-gradient&quot;)" stroke="#FFFFFF" stroke-opacity="0.1" id="MC_SD_001_1_0_5" sequence="5"></circle>
    <text class="node-text" fill="#78D64B" text-anchor="middle" stroke="#78D64B" startOffset="50%" stroke-width="1px" alignment-baseline="middle" dominant-baseline="central" dx="272" dy="17.5">E</text>
  </g>
</svg>

我希望根据所选择的语言来更改方向。这是专门针对阿拉伯语的。

1 个答案:

答案 0 :(得分:0)

SVG支持RTL语言。 SVG标准甚至包括example demonstrating Arabic text

<svg xmlns="http://www.w3.org/2000/svg"
     width="100%" height="100%" viewBox="0 100 400 100"
     direction="rtl" xml:lang="fa">

  <title direction="ltr" xml:lang="en">Right-to-left Text</title>
  <desc direction="ltr" xml:lang="en">
    A simple example for using the 'direction' property in documents
    that predominantly use right-to-left languages.
  </desc>

  <text x="200" y="200" font-size="20">داستان SVG 1.1 SE طولا ني است.</text>

</svg>