Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
H
html-shot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
劳工
html-shot
Commits
7e99b4f9
Commit
7e99b4f9
authored
Jan 23, 2021
by
wjf
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
文本textBaseline改成bottom
parent
cb9eb363
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
8 deletions
+12
-8
toCanvas.ts
src/toCanvas.ts
+12
-8
No files found.
src/toCanvas.ts
View file @
7e99b4f9
...
...
@@ -54,10 +54,10 @@ export interface RenderOptions {
* @return Promise<HTMLCanvasElement | string>
*/
export
async
function
toCanvas
(
data
:
ICData
,
options
:
RenderOptions
=
{},
callback
?:
(
canvas
:
HTMLCanvasElement
)
=>
void
):
Promise
<
HTMLCanvasElement
|
string
>
{
const
{
type
:
exportType
=
'png'
,
quality
=
0.7
}
=
options
;
let
{
scale
=
window
[
'devicePixelRatio'
]
||
1
}
=
options
;
const
{
type
:
exportType
=
'png'
,
quality
=
0.7
}
=
options
;
let
{
scale
=
window
[
'devicePixelRatio'
]
||
1
}
=
options
;
let
{
nodes
,
width
,
height
}
=
data
;
let
{
nodes
,
width
,
height
}
=
data
;
width
*=
scale
;
height
*=
scale
;
...
...
@@ -113,7 +113,7 @@ export async function toCanvas(data: ICData, options: RenderOptions = {}, callba
* @param scale
*/
function
drawImage
(
data
:
INodeData
,
ctx
:
CanvasRenderingContext2D
,
scale
:
number
)
{
let
{
x
,
y
,
img
,
width
,
height
,
borderRadius
:
borderRadiusTxt
}
=
data
;
let
{
x
,
y
,
img
,
width
,
height
,
borderRadius
:
borderRadiusTxt
}
=
data
;
x
*=
scale
;
y
*=
scale
;
width
*=
scale
;
...
...
@@ -182,9 +182,13 @@ function drawText(data: INodeData, ctx: CanvasRenderingContext2D, scale: number)
if
(
fontStyle
)
font
=
fontStyle
+
" "
+
font
;
ctx
.
font
=
font
;
ctx
.
textBaseline
=
"
top
"
;
ctx
.
textBaseline
=
"
bottom
"
;
ctx
.
fillStyle
=
color
;
let
widthAll
=
ctx
.
measureText
(
text
).
width
;
var
textMetrics
=
ctx
.
measureText
(
text
);
let
widthAll
=
textMetrics
.
width
;
// var actualBoundingBoxAscent = textMetrics.actualBoundingBoxAscent;
// console.log(actualBoundingBoxAscent)
// console.log(ctx.measureText(text))
//超过宽度需要换行,且需要用到居中方式
if
(
wordWrap
==
"break-word"
&&
widthAll
>
width
)
{
...
...
@@ -216,10 +220,10 @@ function drawText(data: INodeData, ctx: CanvasRenderingContext2D, scale: number)
//有待考虑.现在直接拿高度取平均算每行高度
let
lineH
=
height
/
realLines
.
length
;
realLines
.
forEach
((
r
,
i
)
=>
{
ctx
.
fillText
(
r
,
x
+
tx
,
y
+
i
*
lineH
)
ctx
.
fillText
(
r
,
x
+
tx
,
y
+
i
*
lineH
+
lineH
)
})
}
else
{
ctx
.
textAlign
=
"left"
ctx
.
fillText
(
text
,
x
,
y
)
ctx
.
fillText
(
text
,
x
,
y
+
height
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment