even more mac fixes
[swftools.git] / spec / transpstack.py
blob6bc151c5414e1a65af41987ef1f9b0f373677edc
1 #!/usr/bin/python
2 import sys
3 sys.path += ["../scripts/"]
4 import pdf
6 # a test for transparency groups:
7 # form xobjects used for doing transparency groups can do savestate (q)
8 # without ever needing to do a corresponding restorestate (Q) because
9 # their content stream is self-contained.
11 # Test that this doesn't confuse the pdf reader.
13 file = pdf.PDF()
15 page = file.add_page(612,100)
17 group1 = file.create_object("/XObject", "/Form")
18 group1.stream = """
19 0.0 1.0 0.0 rg
20 0.0 0.0 0.0 RG
21 10 10 m 70 10 l 70 70 l 10 70 l 10 10 l f
22 10 10 m 70 10 l 70 70 l 10 70 l 10 10 l s
23 0.0 0.0 1.0 rg
24 0.0 0.0 0.0 RG
25 30 30 m 90 30 l 90 90 l 30 90 l 30 30 l f
26 30 30 m 90 30 l 90 90 l 30 90 l 30 30 l s
27 1.0 0 0 1.0 1000 1000 cm q
28 1.0 0 0 1.0 1000 1000 cm q
29 1.0 0 0 1.0 1000 1000 cm q
30 1.0 0 0 1.0 1000 1000 cm q
31 """
32 isolated = "true"
33 knockout = "true"
34 group1["/Group"] = pdf.PDFDict({"/S": "/Transparency", "/CS": "/DeviceRGB", "/I": isolated, "/K": knockout})
35 group1["/BBox"] = pdf.PDFArray([0, 0, 100, 100])
37 gs = file.create_object("/ExtGState")
38 gs["/BM"] = "/Normal"
39 gs["/CA"] = "1.0" # stroke alpha
40 gs["/ca"] = "1.0" # fill alpha
42 resources = file.create_object("/Resources")
43 resources["/XObject"] = pdf.PDFDict({"/mygroup": group1})
44 resources["/ExtGState"] = pdf.PDFDict({"/gs0": gs})
46 page.header["/Resources"] = resources
48 page.stream = """q
50 1.0 0.0 0.0 rg
52 0 40 m 612 40 l 612 60 l 0 60 l 0 40 l f
53 q /gs0 gs 1.0 0 0 1.0 0 0 cm /mygroup Do Q
55 Q"""
57 file.write("transpstack.pdf")