当前位置:网站首页>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
边栏推荐
猜你喜欢

Getting started with postman

ACK攻击是什么意思?ACK攻击怎么防御?

栖霞市住建局和消防救援大队开展消防安全培训

MySQL 8th job

MySQL seventh job - update data

April 13, 2021 interview with beaver family

Fabric.js 上划线、中划线(删除线)、下划线

MySQL第六次作业-查询数据-多条件

Adaptiveavgpool2d does not support onnx export. Customize a class to replace adaptiveavgpool2d

MySQL 9th job - connection Query & sub query
随机推荐
See how I store integer data in the map < string, string > set
MySQL第七次作业-更新数据
Flutter与原生通信(上)
Redis (IV) redis association table caching
AdaptiveAvgPool2D 不支持 onnx 导出,自定义一个类代替 AdaptiveAvgPool2D
Which PHP open source works deserve attention
SSH, SCP command appears permission denied, please try again solution
工作汇报(3)
Oracle sqlplus 查询结果显示优化
Developers, what is the microservice architecture?
Global and Chinese markets in hair conditioner 2022-2028: Research Report on technology, participants, trends, market size and share
MySQL第十一作業-視圖的應用
[difficult and miscellaneous diseases] @transitional failure summary
Huawei secoclient reports an error "accept return code timeout" [svn adapter v1.0 exclamation point]
Jasperreports - print PDF (project tool)
JS take the date of the previous month 【 pit filling 】
服务器单、双向可调一键互信脚本!
ceph运维常用指令
MySQL第九次作业-连接查询&子查询
Win10 start FTP service and set login authentication