Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
F
flot
Project
Project
Details
Activity
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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
HS-public
flot
Commits
9ca3e834
Commit
9ca3e834
authored
Apr 02, 2013
by
David Schnur
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use actual line height for canvas text rendering.
parent
825cd36e
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
15 additions
and
26 deletions
+15
-26
jquery.flot.canvas.js
jquery.flot.canvas.js
+15
-26
No files found.
jquery.flot.canvas.js
View file @
9ca3e834
...
...
@@ -187,28 +187,30 @@ browser, but needs to redraw with canvas text when exporting as an image.
// If the font was provided as CSS, create a div with those
// classes and examine it to generate a canvas font spec.
// Note the trick of using a line-height of 1, without units;
// this sets it equal to the font-size, even if the font-size
// is something abstract, like 'smaller'. This enables us to
// read the real font-size via the element's height, working
// around browsers that return the literal 'smaller' value.
if
(
typeof
font
!==
"object"
)
{
var
element
=
$
(
"<div> </div>"
)
.
css
(
"position"
,
"absolute"
)
.
addClass
(
typeof
font
===
"string"
?
font
:
null
)
.
css
({
position
:
"absolute"
,
padding
:
0
,
'line-height'
:
1
})
.
appendTo
(
this
.
getTextLayer
(
layer
));
font
=
{
lineHeight
:
element
.
height
(),
style
:
element
.
css
(
"font-style"
),
variant
:
element
.
css
(
"font-variant"
),
weight
:
element
.
css
(
"font-weight"
),
size
:
element
.
height
(),
family
:
element
.
css
(
"font-family"
),
color
:
element
.
css
(
"color"
)
};
// Setting line-height to 1, without units, sets it equal
// to the font-size, even if the font-size is abstract,
// like 'smaller'. This enables us to read the real size
// via the element's height, working around browsers that
// return the literal 'smaller' value.
font
.
size
=
element
.
css
(
"line-height"
,
1
).
height
();
element
.
remove
();
}
...
...
@@ -241,28 +243,15 @@ browser, but needs to redraw with canvas text when exporting as an image.
for
(
var
i
=
0
;
i
<
lines
.
length
;
++
i
)
{
var
lineText
=
lines
[
i
],
measured
=
context
.
measureText
(
lineText
),
lineWidth
,
lineHeight
;
lineWidth
=
measured
.
width
;
// Height might not be defined; not in the standard yet
lineHeight
=
measured
.
height
||
font
.
size
;
// Add a bit of margin since font rendering is not pixel
// perfect and cut off letters look bad. This also doubles
// as spacing between lines.
lineHeight
+=
Math
.
round
(
font
.
size
*
0.15
);
measured
=
context
.
measureText
(
lineText
);
info
.
width
=
Math
.
max
(
lineW
idth
,
info
.
width
);
info
.
height
+=
lineHeight
;
info
.
width
=
Math
.
max
(
measured
.
w
idth
,
info
.
width
);
info
.
height
+=
font
.
lineHeight
;
info
.
lines
.
push
({
text
:
lineText
,
width
:
lineW
idth
,
height
:
lineHeight
width
:
measured
.
w
idth
,
height
:
font
.
lineHeight
});
}
...
...
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