当前位置:网站首页>Fabric. JS upper dash, middle dash (strikethrough), underline
Fabric. JS upper dash, middle dash (strikethrough), underline
2022-06-26 10:50:00 【InfoQ】
Brief introduction
HTMLWordFabric.jscanvas
fabric.jsITextSet on initialization
- Top line overline
- Center line linethrough
- Underline underline

<canvas id="c" width="300" height="300" style="border: 1px solid #ccc"></canvas>
<script src="../../script/fabric.5.2.1.js"></script>
<script>
const canvas = new fabric.Canvas('c')
const iText = new fabric.IText('aaa',{
styles: {
0: {
0: { overline: true }, // Top line
1: { linethrough: true }, // Center line
2: { underline: true } // Underline
}
}
})
canvas.add(iText)
</script>
astyleskey0styles: {
0: { // The first 1 That's ok
0:, // The first 1 That's ok The first 1 A word
1:, // The first 1 That's ok The first 2 A word
2: // The first 1 That's ok The first 3 A word
}
}
\nDynamic setting
Fabric.js
<button onclick="linethrough()"> Center line </button>
<canvas id="c" width="300" height="300" style="border: 1px solid #ccc"></canvas>
<canvas id="c" width="300" height="300" style="border: 1px solid #ccc"></canvas>
<!-- introduce fabric -->
<script src="../../script/fabric.5.2.1.js"></script>
<script>
const canvas = new fabric.Canvas('c') // Initialize canvas
const iText = new fabric.IText('hello wor\nld') // Create text
canvas.add(iText)
function linethrough() {
let activeTxt = canvas.getActiveObject() // Get the currently selected text
// If no text is currently selected , Then do nothing
if (!activeTxt) return
// Judge whether to enter the editing status
if (activeTxt.isEditing) {
// Edit state
const state = activeTxt.getSelectionStyles().find(item => item.linethrough !== true)
// If at present
if (!state || (JSON.stringify(state) === '{}' && activeTxt['linethrough'] === true)) {
// If the middle dash line is currently set , Then cancel the line in the overall situation
activeTxt.setSelectionStyles({ 'linethrough': false })
} else {
// If the middle dash is not currently set , Then add an upper and middle dash
activeTxt.setSelectionStyles({ 'linethrough': true })
}
} else {
// Selection status
if (activeTxt['linethrough'] === true) {
activeTxt.linethrough = false
activeTxt.dirty = true;
let s = activeTxt.styles
for(let i in s) {
for (let j in s[i]) {
s[i][j].linethrough = false
}
}
} else {
activeTxt.linethrough = true
activeTxt.dirty = true;
let s = activeTxt.styles
for(let i in s) {
for (let j in s[i]) {
s[i][j].linethrough = true
}
}
}
}
canvas.renderAll()
}
</script>
- Initialize canvas
- Create text
- Add text to the canvas
linethroughMethod to add or remove a dash line
linethroughlinethrough- Get the currently selected text
- If it is not selected, no operation will be performed
- If you choose , Determine whether to enter the editing state
- Edit state
- Gets the underline status of the currently selected text
- If the selected text has a middle dash , Just cancel the middle line
- If the selected text does not have a middle dash , Just add a middle dash
- If it is not in editing status , Just click
iTextEnter the box selection status
- If you need to cancel the dash line globally
- Global cancel
- Loop each character , And cancel the middle dash of each character
- You need to underline in the global settings
- Global settings
- Then set it individually character by character
- Re render the canvas
Code warehouse
边栏推荐
- Huawei secoclient reports an error "accept return code timeout" [svn adapter v1.0 exclamation point]
- Oracle sqlplus 查询结果显示优化
- Pit record_ TreeSet custom sorting results in less data loss
- Installer MySQL sous Linux [détails]
- Global and Chinese market of contemporary lampshade 2022-2028: Research Report on technology, participants, trends, market size and share
- 2021 Q3-Q4 Kotlin Multiplatform 使用现状 | 调查报告
- Getting started with postman
- Write data to local file
- 携程机票 App KMM 跨端 KV 存储库 MMKV-Kotlin | 开源
- RDB持久化验证测试
猜你喜欢
随机推荐
MySQL Chapter 6 Summary
Vscode environment setup: synchronous configuration
Redis中执行Lua脚本
The sixth MySQL job - query data - multiple conditions
MySQL第八次作业
Développeur, quelle est l'architecture des microservices?
用同花顺手机炒股是安全的吗?如何用同花顺炒股
MySQL Performance Monitoring and SQL statements
Tape library simple record 1
sysbench基础介绍
Enter a positive integer with no more than 5 digits, and output the last digit in reverse order
mysql性能监控和sql语句
目前为止最全的Kubernetes最新版核心命令
Servlet learning notes II
ISO 26262之——2功能安全概念
开发者,微服务架构到底是什么?
Oracle sqlplus 查询结果显示优化
Redis (basic) - learning notes
Swiftui development experience: data layer of application design for offline priority
See how I store integer data in the map < string, string > set









