Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
DCloud
hello uni-app x
提交
26f3c8a1
H
hello uni-app x
项目概览
DCloud
/
hello uni-app x
通知
5995
Star
90
Fork
162
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
18
列表
看板
标记
里程碑
合并请求
1
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
H
hello uni-app x
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
18
Issue
18
列表
看板
标记
里程碑
合并请求
1
合并请求
1
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
26f3c8a1
编写于
8月 20, 2024
作者:
X
xty
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
canvas自定义字体示例
上级
062a2bc8
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
37 addition
and
28 deletion
+37
-28
pages/component/canvas/canvas-context.uvue
pages/component/canvas/canvas-context.uvue
+37
-28
未找到文件。
pages/component/canvas/canvas-context.uvue
浏览文件 @
26f3c8a1
...
@@ -33,7 +33,8 @@
...
@@ -33,7 +33,8 @@
canvasContext: null as CanvasContext | null,
canvasContext: null as CanvasContext | null,
renderingContext: null as CanvasRenderingContext2D | null,
renderingContext: null as CanvasRenderingContext2D | null,
canvasWidth: 0,
canvasWidth: 0,
canvasHeight: 0,
canvasHeight: 0,
fontLoaded: false,
names: [...API_PATH, ...API_DRAW, ...API_STATE, ...API_PROPERTIES, "measureText", "path2D"].sort() as string[]
names: [...API_PATH, ...API_DRAW, ...API_STATE, ...API_PROPERTIES, "measureText", "path2D"].sort() as string[]
}
}
},
},
...
@@ -808,34 +809,42 @@
...
@@ -808,34 +809,42 @@
path2DRect.rect(10, 10, 100, 20);
path2DRect.rect(10, 10, 100, 20);
context.fill(path2DRect);
context.fill(path2DRect);
},
},
fontTTF() {
fontTTF() {
const context = this.renderingContext!
const context = this.renderingContext!
const fontMap = new Map<string,UTSJSONObject>([
const fontMap = new Map<string, UTSJSONObject>([
["AlimamaDaoLiTiOTF", {path: "/static/font/AlimamaDaoLiTi.otf", text: "阿里妈妈刀隶体字体otf加载成功"} as UTSJSONObject],
["AlimamaDaoLiTiOTF", { path: "/static/font/AlimamaDaoLiTi.otf", text: "阿里妈妈刀隶体字体otf加载成功" } as UTSJSONObject],
["AlimamaDaoLiTiWOFF", {path: "/static/font/AlimamaDaoLiTi.woff", text: "阿里妈妈刀隶体字体Woff加载成功"} as UTSJSONObject],
["AlimamaDaoLiTiWOFF", { path: "/static/font/AlimamaDaoLiTi.woff", text: "阿里妈妈刀隶体字体Woff加载成功" } as UTSJSONObject],
["iconfont-star", {path: "/static/fonts/icon-star.ttf", text: "\ue879"} as UTSJSONObject ],
["iconfont-star", { path: "/static/fonts/icon-star.ttf", text: "\ue879" } as UTSJSONObject],
]);
]);
var yOffset = 0
var yOffset = 0
fontMap.forEach((value: UTSJSONObject, key: string)=>{
console.log(`key:${key} value:${value["path"]}`)
var drawFont = (key : string, value : UTSJSONObject) => {
uni.loadFontFace({
console.log(`${key}字体加载成功`)
family: key,
context.save()
source: `url('${value["path"]}')`,
const text = value["text"] as string
success: () => {
context.font = `20px ${key}`
console.log(`${key}字体加载成功`)
context.fillStyle = "red"
context.save()
yOffset += 25
const text = value["text"] as string
context.fillText(text, 0, yOffset)
context.font = `20px ${key}`
yOffset += 25
context.fillStyle = "red"
context.strokeText(text, 0, yOffset)
yOffset += 25
context.restore()
context.fillText(text, 0, yOffset)
}
yOffset += 25
fontMap.forEach((value : UTSJSONObject, key : string) => {
context.strokeText(text, 0, yOffset)
console.log(`key:${key} value:${value["path"]}`)
context.restore()
if (this.fontLoaded) {
}
drawFont(key, value)
})
} else {
})
uni.loadFontFace({
family: key,
source: `url('${value["path"]}')`,
success: () => {
drawFont(key, value)
}
})
}
})
this.fontLoaded = true
}
}
}
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录