Remove skewX(0) and skewY(0) too. How do they stack?

This commit is contained in:
Johan Sundström 2011-02-21 02:48:07 -08:00
parent f45173f4ee
commit 5f18a23fd7
3 changed files with 34 additions and 2 deletions

View file

@ -2300,6 +2300,14 @@ def optimizeTransform(transform):
The transformation list is modified in-place. 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, # if there's only one transformation and it's a matrix,
# try to make it a shorter non-matrix transformation # try to make it a shorter non-matrix transformation
# NOTE: as matrix(a b c d e f) in SVG means the matrix: # NOTE: as matrix(a b c d e f) in SVG means the matrix:
@ -2373,8 +2381,17 @@ def optimizeTransform(transform):
# rotations followed immediately by other rotations, # rotations followed immediately by other rotations,
# scaling followed immediately by other scaling, # scaling followed immediately by other scaling,
# are safe to add. # are safe to add.
# A matrix followed immediately by another matrix # Identity skewX/skewY are safe to remove, but how do they accrete?
# would be safe to multiply together, too. # |¯ 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 i = 1
while i < len(transform): while i < len(transform):
[currType, currArgs] = transform[i] [currType, currArgs] = transform[i]
@ -2414,6 +2431,11 @@ def optimizeTransform(transform):
# Identity scale! # Identity scale!
i -= 1 i -= 1
del transform[i] 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: else:
i += 1 i += 1

View 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

View 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