Skip to content

Commit 98b3ec9

Browse files
author
wout
committedJul 31, 2014
Reworked sub-pixel offset fix
1 parent b2ab346 commit 98b3ec9

File tree

7 files changed

+36
-63
lines changed

7 files changed

+36
-63
lines changed
 

‎CHANGELOG.md

+4-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
- changed `track` reference to `track()` on `SVG.Text` -> __TODO!__
2929
- fixed a bug in clipping and masking where empty nodes persists after removal -> __TODO!__
3030
- added raw svg import functionality with the `svg()` method -> __TODO!__
31-
- moved sup-pixel offset fix to a separate plugin -> __TODO!__
31+
- reworked sup-pixel offset implementation to be more compact
3232
- added `native()` method to elements and matrix to get to the native api
3333
- added `untransform()` method to remove all transformations
3434
- fixed a bug in IE11 with `mouseenter` and `mouseleave` -> __TODO!__
@@ -37,6 +37,9 @@
3737
- changed `to()` method to `at()` method in `SVG.FX`
3838
- added reverse functionality for animations
3939
- documented the `situation` object in `SVG.FX`
40+
- renamed `SVG.SetFX` to `SVG.FX.Set`
41+
- added distinction between relative and absolute matrix transformations -> __TODO!__
42+
- added specs for `SVG.FX` -> __TODO!__
4043

4144
# 1.0.0-rc.9 (17/06/2014)
4245

‎README.md

+12-3
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,17 @@ Svg.js also works outside of the HTML DOM, inside an SVG document for example:
6767
</svg>
6868
```
6969

70-
### Sub pixel offset fix
71-
By default sub pixel offset won't be corrected. To enable it, call the `fixSubPixelOffset()` method:
70+
### Sub-pixel offset fix
71+
Call the `spof()` method to fix sub-pixel offset:
7272

7373
```javascript
74-
var draw = SVG('drawing').fixSubPixelOffset()
74+
var draw = SVG('drawing').spof()
75+
```
76+
77+
To enable automatic sub-pixel offset correction when the window is resized:
78+
79+
```javascript
80+
SVG.on(window, 'resize', function() { draw.spof() })
7581
```
7682

7783
## Parent elements
@@ -3642,6 +3648,9 @@ SVG.extend(SVG.Rect, {
36423648
})
36433649
```
36443650

3651+
### Refactor your code
3652+
Once your implementation is ready, revisit and rework it. We like to keep it [DRY](http://en.wikipedia.org/wiki/Don't_repeat_yourself).
3653+
36453654
### Test. Your. Code.
36463655
It's not that hard to write at least one example per implementation, although we prefer more. Your code might seem to work by quickly testing it in your brwoser but more than often you can't forsee everything.
36473656

‎dist/svg.js

+7-26
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* @copyright Wout Fierens <wout@impinc.co.uk>
77
* @license MIT
88
*
9-
* BUILT: Wed Jul 30 2014 11:04:18 GMT+0200 (CEST)
9+
* BUILT: Thu Jul 31 2014 20:23:11 GMT+0200 (CEST)
1010
*/
1111
;(function() {
1212
// The main wrapping element
@@ -2707,41 +2707,22 @@ SVG.Doc = SVG.invent({
27072707
, parent: function() {
27082708
return this.node.parentNode.nodeName == '#document' ? null : this.node.parentNode
27092709
}
2710-
}
2711-
2712-
})
2713-
2714-
// Fix for possible sub-pixel offset. See:
2715-
// https://bugzilla.mozilla.org/show_bug.cgi?id=608812
2716-
SVG.extend(SVG.Doc, {
2717-
// Callback
2718-
spof: function() {
2719-
if (this.doSpof) {
2710+
// Fix for possible sub-pixel offset. See:
2711+
// https://bugzilla.mozilla.org/show_bug.cgi?id=608812
2712+
, spof: function(spof) {
27202713
var pos = this.node.getScreenCTM()
27212714

27222715
if (pos)
27232716
this
27242717
.style('left', (-pos.e % 1) + 'px')
27252718
.style('top', (-pos.f % 1) + 'px')
2726-
}
2727-
2728-
return this
2729-
}
27302719

2731-
// Sub-pixel offset enabler
2732-
, fixSubPixelOffset: function() {
2733-
var self = this
2734-
2735-
// Enable spof
2736-
this.doSpof = true
2737-
2738-
// Make sure sub-pixel offset is fixed every time the window is resized
2739-
SVG.on(window, 'resize', function() { self.spof() })
2740-
2741-
return this.spof()
2720+
return this
2721+
}
27422722
}
27432723

27442724
})
2725+
27452726
SVG.Shape = SVG.invent({
27462727
// Initialize node
27472728
create: function(element) {

‎dist/svg.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎gulpfile.js

-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ var parts = [
5757
, 'src/gradient.js'
5858
, 'src/pattern.js'
5959
, 'src/doc.js'
60-
, 'src/spof.js'
6160
, 'src/shape.js'
6261
, 'src/symbol.js'
6362
, 'src/use.js'

‎src/doc.js

+12
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@ SVG.Doc = SVG.invent({
5353
, parent: function() {
5454
return this.node.parentNode.nodeName == '#document' ? null : this.node.parentNode
5555
}
56+
// Fix for possible sub-pixel offset. See:
57+
// https://bugzilla.mozilla.org/show_bug.cgi?id=608812
58+
, spof: function(spof) {
59+
var pos = this.node.getScreenCTM()
60+
61+
if (pos)
62+
this
63+
.style('left', (-pos.e % 1) + 'px')
64+
.style('top', (-pos.f % 1) + 'px')
65+
66+
return this
67+
}
5668
}
5769

5870
})

‎src/spof.js

-31
This file was deleted.

0 commit comments

Comments
 (0)