[reportlab-users] diagonal ShadedRect and Clipping ?
Dirk Datzert
reportlab-users@reportlab.com
Sun, 11 Aug 2002 11:38:12 +0200
Dies ist eine mehrteilige Nachricht im MIME-Format.
--------------35D0F83FAAAF2476D1BC79E2
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Hi,
based on the new clipping for renderPM and ShadedRect I wrote a class
RotatedShadedRect.
RotatedShadedRect implements 3 new orientations 'diagonal' same as
'diagonalup' and 'diagonaldown'
The shadding goes than from one corner to the diagonal opposite.
You can set any rotation angle instead, with the attribute angle (in
degrees).
This class shows only the implementation howto do this effect.
Robin, Dinu and me (and hopefully some more) are currently discussing
how to define a new class which take ShadedRect and RotatedShadedRect
and probably some other shading mode all together.
Regards,
Dirk
--------------35D0F83FAAAF2476D1BC79E2
Content-Type: application/x-unknown-content-type-py_auto_file;
name="srect.py"
Content-Transfer-Encoding: base64
Content-Disposition: inline;
filename="srect.py"
ZnJvbSByZXBvcnRsYWIubGliLnZhbGlkYXRvcnMgaW1wb3J0ICoKZnJvbSByZXBvcnRsYWIu
bGliLmF0dHJtYXAgaW1wb3J0ICoKZnJvbSByZXBvcnRsYWIuZ3JhcGhpY3Muc2hhcGVzIGlt
cG9ydCBHcm91cCwgUGF0aCwgRW1wdHlDbGlwUGF0aApmcm9tIGdyaWRzIGltcG9ydCBTaGFk
ZWRSZWN0CgpjbGFzcyBSb3RhdGVkU2hhZGVkUmVjdChTaGFkZWRSZWN0KToKCSIiIlRoaXMg
bWFrZXMgYSByZWN0YW5nbGUgd2l0aCBzaGFkZWQgY29sb3JzIGJldHdlZW4gdHdvIGNvbG9y
cy4KCglDb2xvcnMgYXJlIGludGVycG9sYXRlZCBsaW5lYXJseSBiZXR3ZWVuICdmaWxsQ29s
b3JTdGFydCcKCWFuZCAnZmlsbENvbG9yRW5kJywgYm90aCBvZiB3aGljaCBhcHBlYXIgYXQg
dGhlIG1hcmdpbnMuCglJZiAnbnVtU2hhZGVzJyBpcyBzZXQgdG8g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2VsZi53aWR0
aCwgc2VsZi5oZWlnaHQKCiAgICAgICAgICAgICAgICBpZiBzZWxmLm9yaWVudGF0aW9uWzo4
XSAhPSAnZGlhZ29uYWwnOgogICAgICAgICAgICAgICAgICAgIHdoaWxlIHNlbGYuYW5nbGUg
PCAtMzYwOgogICAgICAgICAgICAgICAgICAgICAgICBzZWxmLmFuZ2xlID0gc2VsZi5hbmds
ZSArIDM2MAogICAgICAgICAgICAgICAgICAgIHdoaWxlIHNlbGYuYW5nbGUgPiAzNjA6CiAg
ICAgICAgICAgICAgICAgICAgICAgIHNlbGYuYW5nbGUgPSBzZWxmLmFuZ2xlIC0gMzYwCgog
ICAgICAgICAgICAgICAgaWYgc2VsZi5vcmllbnRhdGlvbls6OF0gPT0gJ2RpYWdvbmFsJzoK
ICAgICAgICAgICAgICAgICAgICBkID0gc3FydCh3KioyK2gqKjIpCiAgICAgICAgICAgICAg
ICAgICAgc3JlY3Qud2lkdGggID0gZAogICAgICAgICAgICAgICAgICAgIHNyZWN0LmhlaWdo
dCA9IDIqaCp3L2QKICAgICAgICAgICAgICAgICAgICBzZWxmLmFuZ2xlID0gYWNvcyh3L2Qp
KjE4MC9waQogICAgICAgICAgICAgICAgICAgIGlmIHNlbGYub3JpZW50YXRpb25bLTQ6XSA9
PSAnZG93bic6CiAgICAgICAgICAgICAgICAgICAgICAgIHNlbGYuYW5nbGUgPSAtc2VsZi5h
bmdsZQogICAgICAgICAgICAgICAgZWxpZiBzZWxmLmFuZ2xlIG5vdCBpbiBbMCwxODAsLTE4
MF06CiAgICAgICAgICAgICAgICAgICAgYWxwaGEgPSBzZWxmLmFuZ2xlLzE4MCpwaQoKICAg
ICAgICAgICAgICAgICAgICBpZiBhbHBoYSA8IDA6CiAgICAgICAgICAgICAgICAgICAgICAg
IGFscGhhID0gLWFscGhhCgogICAgICAgICAgICAgICAgICAgIGlmIGFscGhhIDw9IHBpLzIg
b3IgKGFscGhhID4gcGkgYW5kIGFscGhhIDw9IDMqcGkvMik6CiAgICAgICAgICAgICAgICAg
ICAgICAgIHNyZWN0LndpZHRoID0gdypjb3MoYWxwaGEpK2gvc2luKGFscGhhKS1oKmNvcyhh
bHBoYSkqKjIvc2luKGFscGhhKQogICAgICAgICAgICAgICAgICAgICAgICBzcmVjdC5oZWln
aHQgPSBoKmNvcyhhbHBoYSkrdy9zaW4oYWxwaGEpLXcqY29zKGFscGhhKSoqMi9zaW4oYWxw
aGEpCiAgICAgICAgICAgICAgICAgICAgZWxzZToKICAgICAgICAgICAgICAgICAgICAgICAg
YWxwaGEgPSBhbHBoYSAtIHBpLzIKICAgICAgICAgICAgICAgICAgICAgICAgc3JlY3QuaGVp
Z2h0ID0gdypjb3MoYWxwaGEpK2gvc2luKGFscGhhKS1oKmNvcyhhbHBoYSkqKjIvc2luKGFs
cGhhKQogICAgICAgICAgICAgICAgICAgICAgICBzcmVjdC53aWR0aCA9IGgqY29zKGFscGhh
KSt3L3NpbihhbHBoYSktdypjb3MoYWxwaGEpKioyL3NpbihhbHBoYSkKICAgICAgICAgICAg
ICAgIGVsc2U6CiAgICAgICAgICAgICAgICAgICAgc3JlY3Qud2lkdGggPSBzZWxmLndpZHRo
CiAgICAgICAgICAgICAgICAgICAgc3JlY3QuaGVpZ2h0ID0gc2VsZi5oZWlnaHQKCiAgICAg
ICAgICAgICAgICBpZiBzZWxmLmFuZ2xlICE9IDA6CiAgICAgICAgICAgICAgICAgICAgc3Jl
Y3QueCA9IC1zcmVjdC53aWR0aC8yCiAgICAgICAgICAgICAgICAgICAgc3JlY3QueSA9IC1z
cmVjdC5oZWlnaHQvMgogICAgICAgICAgICAgICAgZWxzZToKICAgICAgICAgICAgICAgICAg
ICBzcmVjdC54ID0gc2VsZi54CiAgICAgICAgICAgICAgICAgICAgc3JlY3QueSA9IHNlbGYu
eQoKICAgICAgICAgICAgICAgIGlmIHNlbGYub3JpZW50YXRpb25bOjhdICE9ICdkaWFnb25h
bCc6CiAgICAgICAgICAgICAgICAgICAgc3JlY3Qub3JpZW50YXRpb24gPSBzZWxmLm9yaWVu
dGF0aW9uIAogICAgICAgICAgICAgICAgZWxzZToKICAgICAgICAgICAgICAgICAgICBzcmVj
dC5vcmllbnRhdGlvbiA9ICd2ZXJ0aWNhbCcKCgkJc3JlY3QubnVtU2hhZGVzID0gc2VsZi5u
dW1TaGFkZXMKCQlzcmVjdC5zdHJva2VDb2xvciA9IE5vbmUKCQlzcmVjdC5zdHJva2VXaWR0
aCA9IDAKCQlzcmVjdC5maWxsQ29sb3JTdGFydCA9IHNlbGYuZmlsbENvbG9yU3RhcnQKCQlz
cmVjdC5maWxsQ29sb3JFbmQgICA9IHNlbGYuZmlsbENvbG9yRW5kCgkJc3JlY3QuY3lsaW5k
ZXJNb2RlID0gc2VsZi5jeWxpbmRlck1vZGUKCiAgICAgICAgICAgICAgICBpZiBzZWxmLmFu
Z2xlICE9IDA6CiAgICAgICAgICAgICAgICAgICAgY2xpcCA9IFBhdGgoKQogICAgICAgICAg
ICAgICAgICAgIGNsaXAuaXNDbGlwUGF0aCA9IDEKICAgICAgICAgICAgICAgICAgICBjbGlw
Lm1vdmVUbyhzZWxmLngsc2VsZi55KQogICAgICAgICAgICAgICAgICAgIGNsaXAubGluZVRv
KHNlbGYueCtzZWxmLndpZHRoLHNlbGYueSkKICAgICAgICAgICAgICAgICAgICBjbGlwLmxp
bmVUbyhzZWxmLngrc2VsZi53aWR0aCxzZWxmLnkrc2VsZi5oZWlnaHQpCiAgICAgICAgICAg
ICAgICAgICAgY2xpcC5saW5lVG8oc2VsZi54LHNlbGYueStzZWxmLmhlaWdodCkKICAgICAg
ICAgICAgICAgICAgICBjbGlwLmNsb3NlUGF0aCgpCgogICAgICAgICAgICAgICAgICAgIGJw
bGFuZSA9IEdyb3VwKCkKICAgICAgICAgICAgICAgICAgICBicGxhbmUuYWRkKHNyZWN0KQog
ICAgICAgICAgICAgICAgICAgIGJwbGFuZS5yb3RhdGUoc2VsZi5hbmdsZSkKICAgICAgICAg
ICAgICAgICAgICBicGxhbmUuc2hpZnQoc2VsZi54K3NlbGYud2lkdGgvMixzZWxmLnkrc2Vs
Zi5oZWlnaHQvMikKICAgICAgICAgICAgICAgICAgICBwbGFuZS5hZGQoY2xpcCkKICAgICAg
ICAgICAgICAgICAgICBwbGFuZS5hZGQoYnBsYW5lKQogICAgICAgICAgICAgICAgICAgIHBs
YW5lLmFkZChFbXB0eUNsaXBQYXRoKQogICAgICAgICAgICAgICAgZWxzZToKICAgICAgICAg
ICAgICAgICAgICBwbGFuZS5hZGQoc3JlY3QpCgogICAgICAgICAgICAgICAgcGxhbmUuYWRk
KHJlY3QpCgkJCiAgICAgICAgICAgICAgICByZXR1cm4gcGxhbmUKCQkKCg==
--------------35D0F83FAAAF2476D1BC79E2--