TextPath 路径文字

获取Konva最新的信息

How to draw a Text along path with HTML 5 Canvas?

我们可以通过实例化一个 Konva.TextPath() 对象创建路径文字。

点击 Konva.TextPath documentation 查看详细属性和方法说明。

Konva TextPath Demoview raw
<!DOCTYPE html>
<html>
<head>
<script src="https://unpkg.com/[email protected]/konva.min.js"></script>
<meta charset="utf-8" />
<title>Konva TextPath Demo</title>
<style>
body {
margin: 0;
padding: 0;
overflow: hidden;
background-color: #f0f0f0;
}
</style>
</head>
<body>
<div id="container"></div>
<script>
var width = window.innerWidth;
var height = window.innerHeight;

var stage = new Konva.Stage({
container: 'container',
width: width,
height: height
});

var layer = new Konva.Layer();

var textpath = new Konva.TextPath({
x: 0,
y: 50,
fill: '#333',
fontSize: 16,
fontFamily: 'Arial',
text:
"All the world's a stage, and all the men and women merely players.",
data: 'M10,10 C0,0 10,150 100,100 S300,150 4.0.180'
});

layer.add(textpath);

// add the layer to the stage
stage.add(layer);
</script>
</body>
</html>