我正在玩Java和SVG Salamander但是不能完全了解如何将一个简单的SVG文件渲染成一个JPanel
.
有人能给我一个简短的例子吗?试图按照官方网站上的松散教程,但找不到简单的代码来更好地理解.
我从svg开始,我创建了以下标记.
<svg width="500" height="600" class="graph-container">
<g>
<rect x="150" y="190" height="50" width="200" rx="30" ry="30" nodeId="1" children="3" style="fill: none; stroke: rgb(68, 68, 68);"></rect>
<text x="250" y="220" text-anchor="middle" fill="#444" style="font-size: 24px;">root</text>
</g>
</svg>
Run Code Online (Sandbox Code Playgroud)
我通过d3js在较大的矩形中添加了一个小圆圈.
$( document ).ready(function() {
var node = d3.select('g');
var addchild = node.append("circle")
.attr("cx",320)
.attr("cy",210)
.attr("r",10)
.attr("class","addchild")
.style("fill","none")
.style("stroke","#444");
addchild.on("click", function() {
alert("on click");
});;
});
Run Code Online (Sandbox Code Playgroud)
但是click事件没有触发.
这是相同的jsfiddle.
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
Run Code Online (Sandbox Code Playgroud)
可xmlns="http://www.w3.org/2000/svg"
这是xmlns="https://www.w3.org/2000/svg"
?
还是xmlns="//www.w3.org/2000/svg"
?
我在Inkscape中创建了一个SVG图像.我把它放在与我班级相同的目录中.
有没有办法加载该图像并将其转换为SVG路径?
这背后的想法是获取该图像getClass().getResource("image.svg").toExternalForm()
并将其转换为该imageSVG.setContent()
方法的SVGPath .之后,我想用该button.setGraphic()
方法将该SVGPath对象放入Button中.
我不想使用Transcoders或BufferedImage类.
我想将文本添加到路径的中心并水平对齐,而不是沿路径对齐.
我在中心的路径上运行了以下文本,但我想显示它是水平的,无论路径朝向什么角度.
<text text-anchor="middle">
<textPath xlink:href="#SomePath" startOffset="50%">Some Text</textPath>
</text>
Run Code Online (Sandbox Code Playgroud) 我正在尝试绘制两个谷歌树图并将它们保留在标签中并收到错误:
<width>
不允许svg属性的负值
只有一个树图可见.我假设另一个人无法完成绘画.控制台中没有其他错误描述.(谷歌浏览器).
我的代码:http: //jsfiddle.net/tTqjr/
我正在尝试将SVG文件连接到Web scraper.
如何使用svgwrite更改字体和文本大小?我知道我必须定义一个CSS样式,并以某种方式将其连接到文本对象.但是这是怎么做的?
这是我到目前为止的代码
import svgwrite
svg_document = svgwrite.Drawing(filename = "test-svgwrite3.svg",
size = ("1200px", "800px"))
#This is the line I'm stuck at
#svg_document.add(svg_document.style('style="font-family: Arial; font-size : 34;'))
svg_document.add(svg_document.rect(insert = (900, 800),
size = ("200px", "100px"),
stroke_width = "1",
stroke = "black",
fill = "rgb(255,255,0)"))
svg_document.add(svg_document.text("Reported Crimes in Sweden",
insert = (410, 50),
fill = "rgb(255,255,0)",
#This is the connection to the first line that I'm stuck at
#style = 'style="font-family: Arial; font-size : 104;'))
print(svg_document.tostring())
svg_document.save()
Run Code Online (Sandbox Code Playgroud) 我在我的Python代码中使用svgwrite模块,我想设置一个背景颜色.到目前为止,我还没有找到任何东西.有办法吗?
我希望在初始化过程中有所作为:
import svgwrite
canvas = svgwrite.drawing.Drawing(fill="#225566") # or background="#225566", or sth similar
canvas.save('image.png')
Run Code Online (Sandbox Code Playgroud)
或者我可以在整个地方绘制矩形,但这很奇怪.
我正在尝试为我的SVG添加一个阴影.它适用于所有2D对象,但是当相同的滤镜应用于直线(任一<line>
或者<path>
)时,该线变为不可见,并且不添加阴影.
拉伸png背景图像很容易:
.stretched-logo-bg {
background: url("../img/curve.png") center center no-repeat;
background-size: 100% 100%;
}
Run Code Online (Sandbox Code Playgroud)
但是,这不适用于SVG背景
.stretched-logo-bg {
background: url("../img/curve.svg") center center no-repeat;
background-size: 100% 100%;
}
Run Code Online (Sandbox Code Playgroud)
它不会被拉伸,它将保持其宽高比并保持居中。
至少在Chrome 52中