Remove skewX(0) and skewY(0) too. How do they stack?
This commit is contained in:
parent
f45173f4ee
commit
5f18a23fd7
3 changed files with 34 additions and 2 deletions
24
scour.py
24
scour.py
|
|
@ -2300,6 +2300,14 @@ def optimizeTransform(transform):
|
|||
|
||||
The transformation list is modified in-place.
|
||||
"""
|
||||
# FIXME: reordering these would optimize even more cases:
|
||||
# first: Fold consecutive runs of the same transformation
|
||||
# extra: Attempt to cast between types to create sameness:
|
||||
# "matrix(0 1 -1 0 0 0) rotate(180) scale(-1)" all
|
||||
# are rotations (90, 180, 180) -- thus "rotate(90)"
|
||||
# second: Simplify transforms where numbers are optional.
|
||||
# third: Attempt to simplify any single remaining matrix()
|
||||
#
|
||||
# if there's only one transformation and it's a matrix,
|
||||
# try to make it a shorter non-matrix transformation
|
||||
# NOTE: as matrix(a b c d e f) in SVG means the matrix:
|
||||
|
|
@ -2373,7 +2381,16 @@ def optimizeTransform(transform):
|
|||
# rotations followed immediately by other rotations,
|
||||
# scaling followed immediately by other scaling,
|
||||
# are safe to add.
|
||||
# A matrix followed immediately by another matrix
|
||||
# Identity skewX/skewY are safe to remove, but how do they accrete?
|
||||
# |¯ 1 0 0 ¯|
|
||||
# | tan(A) 1 0 | skews X coordinates by angle A
|
||||
# |_ 0 0 1 _|
|
||||
#
|
||||
# |¯ 1 tan(A) 0 ¯|
|
||||
# | 0 1 0 | skews Y coordinates by angle A
|
||||
# |_ 0 0 1 _|
|
||||
#
|
||||
# FIXME: A matrix followed immediately by another matrix
|
||||
# would be safe to multiply together, too.
|
||||
i = 1
|
||||
while i < len(transform):
|
||||
|
|
@ -2414,6 +2431,11 @@ def optimizeTransform(transform):
|
|||
# Identity scale!
|
||||
i -= 1
|
||||
del transform[i]
|
||||
elif ((currType == 'skewX' or currType == 'skewY')
|
||||
and len(currArgs) == 1 and currArgs[0] == 0):
|
||||
# Identity skew!
|
||||
i -= 1
|
||||
del transform[i]
|
||||
else:
|
||||
i += 1
|
||||
|
||||
|
|
|
|||
5
unittests/transform-skewX-is-identity.svg
Normal file
5
unittests/transform-skewX-is-identity.svg
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 9 9">
|
||||
<line stroke="rgba(255,0,0,0.5)" y1="9" x1="9" transform="skewX(0)"/>
|
||||
<line stroke="rgba(0,0,255,0.5)" y1="9" x1="9"/>
|
||||
<!-- skewX(0) is the identity transform, which can safely be removed -->
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 276 B |
5
unittests/transform-skewY-is-identity.svg
Normal file
5
unittests/transform-skewY-is-identity.svg
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
<svg xmlns="http://www.w3.org/2000/svg" version="1.1" viewBox="0 0 9 9">
|
||||
<line stroke="rgba(255,0,0,0.5)" y1="9" x1="9" transform="skewY(0)"/>
|
||||
<line stroke="rgba(0,0,255,0.5)" y1="9" x1="9"/>
|
||||
<!-- skewY(0) is the identity transform, which can safely be removed -->
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 276 B |
Loading…
Add table
Add a link
Reference in a new issue