当前位置:网站首页>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
边栏推荐
- RDB persistence validation test
- MySQL project 8 summary
- Global and Chinese market of amateur football helmets 2022-2028: Research Report on technology, participants, trends, market size and share
- MySQL 30 military regulations
- MySQL第八次作业
- Flutter与原生通信(上)
- mysql性能監控和sql語句
- Docker中实现MySQL主从复制
- consul微服务治理中心踩坑
- 栖霞市住建局和消防救援大队开展消防安全培训
猜你喜欢

MySQL job 11 - application de la vue

MySQL seventh job - update data

Concise course of probability theory and statistics in engineering mathematics second edition review outline

Express (I) - easy to get started

【软件项目管理】期末复习知识点整理

SSH, SCP command appears permission denied, please try again solution

JS reverse | four libraries and one platform response data encryption

The sixth MySQL job - query data - multiple conditions

MySQL 13th job - transaction management

Opencv image processing - grayscale processing
随机推荐
一键部署ceph脚本
How QT uses quazip to compress and decompress files
[online simulation] Arduino uno PWM controls the speed of DC motor
开发者,微服务架构到底是什么?
JWT (SSO scheme) + three ways of identity authentication
VS或Qt编译链接过程中出现“无法解析的外部符号”的原因:
MySQL 30 military regulations
最强swarm集群一键部署+氢弹级容器管理工具介绍
Concise course of probability theory and statistics in engineering mathematics second edition review outline
Is it safe to use flush mobile phones to speculate in stocks? How to fry stocks with flush
The sixth MySQL job - query data - multiple conditions
Tape library simple record 1
近期工作汇报
Global and Chinese market of recycled paper 2022-2028: Research Report on technology, participants, trends, market size and share
Huawei secoclient reports an error "accept return code timeout" [svn adapter v1.0 exclamation point]
MySQL 11th job - view application
挖财商学院证券开户安全嘛?
DataBinding使用与原理分析
Plookup table in appliedzkp zkevm (8)
The fourteenth MySQL operation - e-mall project