Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Mirador Video
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
IIIF
Mirador
Mirador Video
Commits
277b09f6
Commit
277b09f6
authored
5 years ago
by
Jack Reed
Committed by
Chris Beer
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Setup additional stroke and fill styling for SVG -> Canvas
parent
aa5bb454
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
__tests__/src/lib/CanvasAnnotationDisplay.test.js
+2
-0
2 additions, 0 deletions
__tests__/src/lib/CanvasAnnotationDisplay.test.js
src/lib/CanvasAnnotationDisplay.js
+29
-27
29 additions, 27 deletions
src/lib/CanvasAnnotationDisplay.js
with
31 additions
and
27 deletions
__tests__/src/lib/CanvasAnnotationDisplay.test.js
+
2
−
0
View file @
277b09f6
...
...
@@ -55,6 +55,7 @@ describe('CanvasAnnotationDisplay', () => {
describe
(
'
svgContext
'
,
()
=>
{
it
(
'
draws the paths with selected arguments
'
,
()
=>
{
const
context
=
{
fill
:
jest
.
fn
(),
restore
:
jest
.
fn
(),
save
:
jest
.
fn
(),
setLineDash
:
jest
.
fn
(),
...
...
@@ -72,6 +73,7 @@ describe('CanvasAnnotationDisplay', () => {
expect
(
context
.
translate
).
toHaveBeenCalledWith
(
-
100
,
0
);
expect
(
context
.
strokeStyle
).
toEqual
(
'
#00bfff
'
);
expect
(
context
.
lineWidth
).
toEqual
(
617.4334
);
expect
(
context
.
fill
).
toHaveBeenCalled
();
});
});
describe
(
'
fragmentContext
'
,
()
=>
{
...
...
This diff is collapsed.
Click to expand it.
src/lib/CanvasAnnotationDisplay.js
+
29
−
27
View file @
277b09f6
...
...
@@ -40,31 +40,40 @@ export default class CanvasAnnotationDisplay {
this
.
context
.
save
();
this
.
context
.
translate
(
this
.
offset
.
x
,
this
.
offset
.
y
);
const
p
=
new
Path2D
(
element
.
attributes
.
d
.
nodeValue
);
/**
* Note: we could do something to return the svg styling attributes as
* some have encoded information in these values. However, how should we
* handle highlighting and other complications?
* context.strokeStyle = element.attributes.stroke.nodeValue;
* context.lineWidth = element.attributes['stroke-width'].nodeValue;
*/
this
.
setupLineDash
(
element
.
attributes
);
this
.
context
.
strokeStyle
=
this
.
strokeColor
(
// eslint-disable-line no-param-reassign
element
.
attributes
,
);
// Setup styling from SVG -> Canvas
this
.
context
.
strokeStyle
=
this
.
color
;
if
(
element
.
attributes
[
'
stroke-dasharray
'
])
{
this
.
context
.
setLineDash
(
element
.
attributes
[
'
stroke-dasharray
'
].
nodeValue
.
split
(
'
,
'
));
}
const
svgToCanvasMap
=
{
fill
:
'
fillStyle
'
,
stroke
:
'
strokeStyle
'
,
'
stroke-dashoffset
'
:
'
lineDashOffset
'
,
'
stroke-linecap
'
:
'
lineCap
'
,
'
stroke-linejoin
'
:
'
lineJoin
'
,
'
stroke-miterlimit
'
:
'
miterlimit
'
,
};
Object
.
keys
(
svgToCanvasMap
).
forEach
((
key
)
=>
{
if
(
element
.
attributes
[
key
])
{
this
.
context
[
svgToCanvasMap
[
key
]]
=
element
.
attributes
[
key
].
nodeValue
;
}
});
this
.
context
.
lineWidth
=
this
.
lineWidth
(
// eslint-disable-line no-param-reassign
element
.
attributes
,
);
this
.
context
.
stroke
(
p
);
this
.
context
.
restore
();
});
}
/** */
setupLineDash
(
elementAttributes
)
{
// stroke-dasharray
if
(
elementAttributes
[
'
stroke-dasharray
'
])
{
this
.
context
.
setLineDash
(
elementAttributes
[
'
stroke-dasharray
'
].
nodeValue
.
split
(
'
,
'
));
// Wait to set the fill, so we can adjust the globalAlpha value if we need to
if
(
element
.
attributes
.
fill
&&
element
.
attributes
.
fill
.
nodeValue
!==
'
none
'
)
{
if
(
element
.
attributes
[
'
fill-opacity
'
])
{
this
.
context
.
globalAlpha
=
element
.
attributes
[
'
fill-opacity
'
].
nodeValue
;
}
this
.
context
.
fill
(
p
);
}
this
.
context
.
restore
();
});
}
/** */
...
...
@@ -77,16 +86,9 @@ export default class CanvasAnnotationDisplay {
this
.
context
.
strokeRect
(...
fragment
);
}
/** */
strokeColor
(
elementAttributes
)
{
if
(
elementAttributes
&&
elementAttributes
.
stroke
)
{
return
elementAttributes
.
stroke
.
nodeValue
;
}
return
this
.
color
;
}
/** */
lineWidth
(
elementAttributes
)
{
console
.
log
(
this
.
zoom
,
this
.
width
);
let
calculatedWidth
=
Math
.
ceil
(
10
/
(
this
.
zoom
*
this
.
width
));
if
(
elementAttributes
&&
elementAttributes
[
'
stroke-width
'
])
{
calculatedWidth
*=
elementAttributes
[
'
stroke-width
'
].
nodeValue
;
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment