-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Alternate fix: Store higher-precision copy of transform matrix
- Loading branch information
1 parent
dde9736
commit 9fa9349
Showing
5 changed files
with
102 additions
and
252 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
packages/js-draw/src/rendering/renderers/SVGRenderer.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { Color4, Mat33 } from '@js-draw/math'; | ||
import Viewport from '../../Viewport'; | ||
import SVGRenderer from './SVGRenderer'; | ||
|
||
const makeSVGRenderer = () => { | ||
const viewport = new Viewport(() => {}); | ||
const svgElement = document.createElementNS('http://www.w3.org/2000/svg', 'svg'); | ||
return { svgElement, renderer: new SVGRenderer(svgElement, viewport) }; | ||
}; | ||
|
||
describe('SVGRenderer', () => { | ||
it('text highp and CSS transforms should match', () => { | ||
const testTransforms = [ | ||
Mat33.identity, | ||
new Mat33( | ||
1, 2, 3.45678910, | ||
3, 4, 5.67891011, | ||
0, 0, 1, | ||
), | ||
new Mat33( | ||
-1, -2, 3, | ||
4, 5, 6, | ||
0, 0, 1, | ||
), | ||
new Mat33( | ||
1, 2, 0.00001, | ||
3, 4, -0.00000123, | ||
0, 0, 1, | ||
), | ||
]; | ||
|
||
for (const transform of testTransforms) { | ||
const { svgElement, renderer } = makeSVGRenderer(); | ||
|
||
renderer.drawText('test', transform, { | ||
size: 12, | ||
fontFamily: 'font', | ||
fontWeight: 'bold', | ||
renderingStyle: { | ||
fill: Color4.red, | ||
}, | ||
}); | ||
|
||
expect(svgElement.querySelectorAll('text')).toHaveLength(1); | ||
const textElement = svgElement.querySelector('text')!; | ||
expect(textElement.textContent).toBe('test'); | ||
|
||
const transformFromProperty = Mat33.fromCSSMatrix(textElement.getAttribute('data-highp-transform') ?? ''); | ||
const transformFromCSS = Mat33.fromCSSMatrix(textElement.style.transform); | ||
|
||
expect(transformFromProperty).objEq(transformFromCSS); | ||
expect(transformFromCSS).objEq(transform); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters