当前位置:网站首页>Fabric. JS iText superscript and subscript
Fabric. JS iText superscript and subscript
2022-07-02 05:18:00 【Director of Moral Education Department】
Brief introduction
give the thumbs-up + Focus on + Collection = Learned to
<br>
For projects in Mathematical Chemistry ,“ Superscript ” and “ Subscript ” Functions are commonly used , such as Power 、 chemical element Equivalent expression , Both need superscript or subscript .
<br>
stay Fabric.js
in , Text elements have Text
、IText
and Textbox
. This article mainly explains IText
How to implement superscript and subscript of . stay Text
and Textbox
The same is true of .
<br>
<br>
Superscript
const iText = new fabric.IText('32=9', { styles: { 0: { // The first 1 That's ok 1: { // The first 2 Characters deltaY: -14, // Offset down fontSize: 24, // Set font size } }})
This example shows 3 The square of is equal to 9, To set up deltaY
negative .
deltaY
Is used to define the text baseline , Moving the baseline upward sets a positive value , Move down to set a negative value , The default is 0 .
styles
The setting of is quite special , For a word , You need to locate by line number and character subscript .
Line number and Character subscript from 0 Start , and js
It's the same as an array of .
IText
Wrap is using \n
To operate .
In this case, only 1 That's ok , So the line number is 0.
2
Where the subscript is 1
.
If you don't understand this aspect , You can see Fabric.js IText Set the specified character color and background color .
<br>
<br>
Subscript
const iText = new fabric.IText('H2O', { styles: { 0: { 1: { deltaY: 0, fontSize: 24 } } }})
In this case , I am not going to shift the subscript downward , Because it doesn't look so good , So I just set fontSize
by 24, The font size has been reduced .
<br>
<br>
summary
In fact, the method of setting superscript and subscript in this article is the same , The main process is as follows 3 Step :
- Find the corresponding character by line number and text subscript
- adopt
deltaY
Sets the text baseline for the specified character - modify
fontSize
, Make the font size of the specified character smaller than that of other characters
Complete the above 3 Step can realize the function of superscript and subscript .
<br>
In addition to the above , In fact, there is another way to set superscript and subscript , But the application scenario of that method is a little different , The next article will talk about that method .
<br>
<br>
Source warehouse
Fabric IText Superscripts and subscripts
<br>
<br>
Recommended reading
《Fabric.js IText Set the specified character color and background color 》
《Fabric.js How to use an eraser ( Including recovery function )》
《Fabric.js Draw ellipses freely 》
《Fabric.js How to use the brush ?》
give the thumbs-up + Focus on + Collection = Learned to
边栏推荐
- Fabric.js 精简JSON
- Gee: create a new feature and set corresponding attributes
- LeetCode 1175. Prime number arrangement (prime number judgment + Combinatorial Mathematics)
- JS interview collection test question 1
- LeetCode 1175. 质数排列(质数判断+组合数学)
- Using Kube bench and Kube hunter to evaluate the risk of kubernetes cluster
- LS1046nfs挂载文件系统
- About PROFIBUS: communication backbone network of production plant
- Gee series: Unit 5 remote sensing image preprocessing [GEE grid preprocessing]
- MMAP zero copy knowledge point notes
猜你喜欢
Disable access to external entities in XML parsing
Cubemx DMA notes
paddle: ValueError:quality setting only supported for ‘jpeg‘ compression
黑马笔记---Map集合体系
Summary of database problems
Preparation for writing SAP ui5 applications using typescript
Creation and destruction of function stack frames
6.网络-基础
Simple and practical accounting software, so that accounts can be checked
No logic is executed after the El form is validated successfully
随机推荐
线程池批量处理数据
ubuntu20.04安装mysql8
LeetCode 241. Design priorities for operational expressions (divide and conquer / mnemonic recursion / dynamic programming)
Preparation for writing SAP ui5 applications using typescript
Fabric.js 居中元素
函数栈帧的创建和销毁
Feign realizes file uploading and downloading
Pycharm breakpoint management: temporarily cancel some breakpoints + run directly to a line
Nodejs (03) -- custom module
Splice characters in {{}}
leetcode存在重复元素go实现
Simple and practical accounting software, so that accounts can be checked
Here comes the chicken soup! Keep this quick guide for data analysts
国产全中文-自动化测试软件Apifox
Fabric. JS right click menu
Fabric.js 3个api设置画布宽高
设置滚动条默认样式 谷歌浏览器
Feign realizes file uploading and downloading
Two implementation methods of delay queue
Global and Chinese markets of semiconductor laser therapeutics 2022-2028: Research Report on technology, participants, trends, market size and share