Skip to content
This repository has been archived by the owner on Oct 30, 2021. It is now read-only.

Improvement merge text and tspan #127

Closed
JoKalliauer opened this issue Jan 13, 2018 · 2 comments
Closed

Improvement merge text and tspan #127

JoKalliauer opened this issue Jan 13, 2018 · 2 comments

Comments

@JoKalliauer
Copy link
Contributor

I would like to merge simple <text> with <tspan>

Inputexample:

 <text x="313.88" y="322.89">
  <tspan x="313.88" y="322.89">1</tspan>
 </text>

Output:

 <text x="313.88" y="322.89">1</text>

actually I am using (case-depended) following scripts:

#tspan in tspan
sed -ri -e ':a' -e 'N' -e '$!ba' -e "s/<tspan([-[:alnum:]\,\.\"\=\:\ \#]*) x=\"([-[:digit:]\.\ ]+)\" y=\"([-[:digit:]\.\ ]+)\"([-[:alnum:]\,\.\"\=\:\ \#]*)>[[:space:]]*<tspan([-[:alnum:]\,\.\"\=\:\ \#]*) x=\"([-[:digit:]\.\ ]+)\" y=\"([-[:digit:]\.\ ]+)\"([-[:alnum:]\,\.\"\=\:\ \#]*)>([-[:alnum:]\.\ \,\(\)]*)<\/tspan>/<tspan x=\"\6\" y=\"\7\"\1\4\5\8>\9/g" $i
#tspan to text
sed -ri  -e ':a' -e 'N' -e '$!ba' -e "s/<text([-aeflmnorst0-9\,\.\"\=\:\ \#\(\)]*)( x=\"[-[:digit:]\.\ ]+\" y=\"[-[:digit:]\.\ ]+\")/<text\2\1/g" $i # that x ist at the beginning (otherwise the next line would not work)
sed -ri  -e ':a' -e 'N' -e '$!ba' -e "s/<text( x=\"[-[:digit:]\.\ ]+\" y=\"[-[:digit:]\.\ ]+\"|)([-[:alnum:]\,\.\"\=\:\ \#\(\)\%\']*)>[[:space:]]*<tspan([-[:alnum:]\,\.\"\=\:\ \#]*) x=\"([-[:digit:]\.\ ]+)\" y=\"([-[:digit:]\.\ ]+)\"([-[:alnum:]\,\.\"\=\:\ #]*)>([-–[:alnum:]\.\ \,\{\(\)\♭\♯\/]*)<\/tspan>/<text x=\"\4\" y=\"\5\"\2\3\6>\7/g" $i #removes the first tspan of a text element
#tspan to text if tspan has no coordinates
sed -ri  -e ':a' -e 'N' -e '$!ba' -e "s/<text([-[:alnum:]\,\.\"\=\:\ \#\(\)]*) x=\"([-[:digit:]\.\ ]+)\" y=\"([-[:digit:]\.\ ]+)\"([-[:alnum:]\,\.\"\=\:\ \#\(\)\%\']*)>[[:space:]]*<tspan([-[:alnum:]\,\.\"\=\:\ \#\'\%]*)>([-–[:alnum:]\.\ \,\{\(\)]*)<\/tspan>/<text x=\"\2\" y=\"\3\"\1\4\5>\6/g" $i

it works in most cases but they can be buggy.

If you are interested to implement it I can post some more general testexamples.

@RazrFalcon
Copy link
Owner

There is nothing to improve because it's not implemented at all.

Also, your example is too simple. Actual text and tspan are far more complex.

This will be implemented some day.

@RazrFalcon
Copy link
Owner

Duplicate of #39

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants