~ubuntu-branches/debian/experimental/inkscape/experimental

« back to all changes in this revision

Viewing changes to share/extensions/empty_page.py

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2014-12-18 09:30:56 UTC
  • mfrom: (1.3.8)
  • Revision ID: package-import@ubuntu.com-20141218093056-3dty68h4ttk2z79i
Tags: 0.91~pre3-1
* New upstream pre-release
* debian/control: Uploader e-mail address updated
* debian/control: S-V bump 3.9.5 => 3.9.6 (no changes needed)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/env python
2
2
 
 
3
# Rewritten by Tavmjong Bah to add correct viewBox, inkscape:cx, etc. attributes
 
4
 
3
5
import inkex
4
6
 
5
7
class C(inkex.Effect):
8
10
    self.OptionParser.add_option("-s", "--size", action="store", type="string", dest="page_size", default="a4", help="Page size")
9
11
    self.OptionParser.add_option("-o", "--orientation", action="store", type="string", dest="page_orientation", default="vertical", help="Page orientation")
10
12
 
11
 
  def effect(self): 
 
13
  def effect(self):
 
14
 
 
15
    width  = 300
 
16
    height = 300
 
17
    units  = 'px'
 
18
 
 
19
    if self.options.page_size == "a5":
 
20
      width = 148
 
21
      height= 210
 
22
      units = 'mm'
 
23
 
 
24
    if self.options.page_size == "a4":
 
25
      width = 210
 
26
      height= 297
 
27
      units = 'mm'
 
28
 
 
29
    if self.options.page_size == "a3":
 
30
      width = 297
 
31
      height= 420
 
32
      units = 'mm'
 
33
 
 
34
    if self.options.page_size == "letter":
 
35
      width  = 8.5
 
36
      height = 11
 
37
      units  = 'in'
 
38
 
 
39
    if self.options.page_orientation == "horizontal":
 
40
      width, height = height, width
 
41
 
 
42
 
12
43
    root = self.document.getroot()
13
 
    root.set("width", "12in")
14
 
    root.set("height", "12in")
15
 
    if self.options.page_size == "a4" and self.options.page_orientation == "vertical":
16
 
        root.set("width", "210mm")
17
 
        root.set("height", "297mm")
18
 
    if self.options.page_size == "a4" and self.options.page_orientation == "horizontal":
19
 
        root.set("height", "210mm")
20
 
        root.set("width", "297mm")
21
 
        
22
 
    if self.options.page_size == "a5" and self.options.page_orientation == "vertical":
23
 
        root.set("width", "148mm")
24
 
        root.set("height", "210mm")
25
 
    if self.options.page_size == "a5" and self.options.page_orientation == "horizontal":
26
 
        root.set("width", "210mm")
27
 
        root.set("height", "148mm")
28
 
        
29
 
    if self.options.page_size == "a3" and self.options.page_orientation == "vertical":
30
 
        root.set("width", "297mm")
31
 
        root.set("height", "420mm")
32
 
    if self.options.page_size == "a3" and self.options.page_orientation == "horizontal":
33
 
        root.set("width", "420mm")
34
 
        root.set("height", "297mm")
35
 
        
36
 
    if self.options.page_size == "letter" and self.options.page_orientation == "vertical":
37
 
        root.set("width", "8.5in")
38
 
        root.set("height", "11in")
39
 
    if self.options.page_size == "letter" and self.options.page_orientation == "horizontal":
40
 
        root.set("width", "11in")
41
 
        root.set("height", "8.5in")
 
44
    root.set("id", "SVGRoot")
 
45
    root.set("width",  str(width)  + units)
 
46
    root.set("height", str(height) + units)
 
47
    root.set("viewBox", "0 0 " + str(width) + " " + str(height) )
 
48
 
 
49
    namedview = root.find(inkex.addNS('namedview', 'sodipodi'))
 
50
    if namedview is None:
 
51
        namedview = inkex.etree.SubElement( root, inkex.addNS('namedview', 'sodipodi') );
 
52
     
 
53
    namedview.set(inkex.addNS('document-units', 'inkscape'), units)
 
54
 
 
55
    # Until units are supported in 'cx', etc.
 
56
    namedview.set(inkex.addNS('cx', 'inkscape'), str(self.uutounit( width,  'px' )/2.0 ) )
 
57
    namedview.set(inkex.addNS('cy', 'inkscape'), str(self.uutounit( height, 'px' )/2.0 ) )
 
58
 
42
59
 
43
60
c = C()
44
61
c.affect()