博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
svg 创建文本 create text
阅读量:4030 次
发布时间:2019-05-24

本文共 1553 字,大约阅读时间需要 5 分钟。

既然svg无法显示换行文本,则必须创建多个文本。怎么创建呢,下面是个网上的例子,不太好找,把它转过来。

(http://osdir.com/ml/text.xml.svg.devel/2002-08/msg01252.html)

 

node=svgdoc.createElement("text");

node.setAttribute("id",yourId);
node.setAttribute("x",yourx);
node.setAttribute("y",youry);
node.setAttribute("style",yourstyle);
textnode=svgdoc.createTextNode("Hello Dynamic Text");
node.appendChild(textnode);
yourparent.appendChild(node);
this should do the job...
the only difference is that you have to create a special textNode that will be
appended to the text-element, which is then appended to it's parent.
Hope this helps,
Andreas
--- In svg-developers@xxxx, "dennis_joel_david" <dennis.myren@xxxx> wrote:
> Isnt it possible todynamically create a text element and setting its
> text?
> I am trying to use this function to achieve this.
> This doesnt work, but it seems like when I have already a text
> element with this id, and where text is more than empty string
> already, there is no problem.
> What am I doing wrong?
> Because it has to be possible, because I dont know how many text
> elements will be created during the session when my SVG document
> loads.
> Thank you
> Dennis
> function createTextElement(text, x, y)
> {
> Ind = _osvgdoc.createElement('text');
> Ind.setAttribute('id', '1100');
> Ind.setAttribute('x', x + (width / 2));
> Ind.setAttribute('y', y + (height / 2) + 10);
> Ind.setAttribute('style', 'text-anchor:middle; font-size:16; font-
> family:Arial; fill:black;');
> Ind.setData('kalle');
> //Ind.getFirstChild().setData('kalle');
> parent.appendChild(Ind);
> }

 

转载地址:http://kpqbi.baihongyu.com/

你可能感兴趣的文章
C primer plus 基础总结(一)
查看>>
剑指offer算法题分析与整理(一)
查看>>
剑指offer算法题分析与整理(三)
查看>>
部分笔试算法题整理
查看>>
Ubuntu 13.10使用fcitx输入法
查看>>
pidgin-lwqq 安装
查看>>
mint/ubuntu安装搜狗输入法
查看>>
C++动态申请数组和参数传递问题
查看>>
opencv学习——在MFC中读取和显示图像
查看>>
retext出现Could not parse file contents, check if you have the necessary module installed解决方案
查看>>
pyQt不同窗体间的值传递(一)——对话框关闭时返回值给主窗口
查看>>
linux mint下使用外部SMTP(如网易yeah.net)发邮件
查看>>
北京联通华为光猫HG8346R破解改桥接
查看>>
python使用win32*模块模拟人工操作——城通网盘下载器(一)
查看>>
python append 与浅拷贝
查看>>
Matlab与CUDA C的混合编程配置出现的问题及解决方案
查看>>
2017阿里内推笔试题--算法工程师(运筹优化)
查看>>
python自动化工具之pywinauto(零)
查看>>
python自动化工具之pywinauto(四)——批量转换exe视频
查看>>
python一句话之利用文件对话框获取文件路径
查看>>