Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
6e74f028
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
6072
Star
94
Fork
167
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
19
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
19
Issue
19
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
6e74f028
编写于
8月 20, 2024
作者:
X
xty
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
添加canvas自定义字体示例
上级
eac328ea
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
35 addition
and
5 deletion
+35
-5
pages/component/canvas/canvas-context.uvue
pages/component/canvas/canvas-context.uvue
+35
-5
未找到文件。
pages/component/canvas/canvas-context.uvue
浏览文件 @
6e74f028
...
...
@@ -24,7 +24,7 @@
data() {
const API_PATH = ["arc", "arcTo", "bezierCurveTo", "quadraticCurve", "moveTo", "lineTo", "rect", "clip", "createPattern", "getSetImageData"]
const API_DRAW = ["stroke", "strokeRect", "strokeText", "fill", "fillRect", "fillText", "drawImage", "drawImageLocal", "clearRect"]
const API_STATE = ["beginPath", "closePath", "reset", "transform", "rotate", "resetTransform", "save", "restore", "scale", "translate"]
const API_STATE = ["beginPath", "closePath", "reset", "transform", "rotate", "resetTransform", "save", "restore", "scale", "translate"
, "fontTTF"
]
const API_PROPERTIES = ["lineCap", "lineJoin", "lineWidth", "miterLimit", "fillStyle", "strokeStyle", "globalAlpha", "font", "setLineDash", "createLinearGradient", "createRadialGradient", "textAlign"]
return {
...
...
@@ -52,8 +52,8 @@
this.canvasWidth = this.canvas!.width;
this.canvasHeight = this.canvas!.height;
}
})
})
console.log(this.names);
// 同步调用方式,仅支持 app/web
...
...
@@ -198,6 +198,9 @@
case "path2D":
this.path2DMethods();
break;
case "fontTTF":
this.fontTTF();
break;
default:
break;
}
...
...
@@ -783,7 +786,6 @@
},
path2DMethods() {
const context = this.renderingContext!
context.beginPath()
const path2D = new Path2D();
const amplitude = 64;
...
...
@@ -805,6 +807,35 @@
const path2DRect = new Path2D();
path2DRect.rect(10, 10, 100, 20);
context.fill(path2DRect);
},
fontTTF() {
const context = this.renderingContext!
const fontMap = new Map<string,UTSJSONObject>([
["AlimamaDaoLiTiOTF", {path: "/static/font/AlimamaDaoLiTi.otf", text: "阿里妈妈刀隶体字体otf加载成功"} as UTSJSONObject],
["AlimamaDaoLiTiWOFF", {path: "/static/font/AlimamaDaoLiTi.woff", text: "阿里妈妈刀隶体字体Woff加载成功"} as UTSJSONObject],
["iconfont-star", {path: "/static/fonts/icon-star.ttf", text: "\ue879"} as UTSJSONObject ],
]);
var yOffset = 0
fontMap.forEach((value: UTSJSONObject, key: string)=>{
console.log(`key:${key} value:${value["path"]}`)
uni.loadFontFace({
family: key,
source: `url('${value["path"]}')`,
success: () => {
console.log(`${key}字体加载成功`)
context.save()
const text = value["text"] as String
context.font = `20px ${key}`
context.fillStyle = "red"
yOffset += 25
context.fillText(text, 0, yOffset)
yOffset += 25
context.strokeText(text, 0, yOffset)
context.restore()
}
})
})
}
}
}
...
...
@@ -837,5 +868,4 @@
width: 50%;
padding: 5px;
}
</style>
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录