~ubuntu-branches/ubuntu/karmic/calibre/karmic

« back to all changes in this revision

Viewing changes to src/calibre/ebooks/pdf/pageoptions.py

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-07-30 12:49:41 UTC
  • mto: This revision was merged to the branch mainline in revision 13.
  • Revision ID: james.westby@ubuntu.com-20090730124941-kviipg9ypwgppulc
Tags: upstream-0.6.3+dfsg
ImportĀ upstreamĀ versionĀ 0.6.3+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
__license__ = 'GPL 3'
 
3
__copyright__ = '2009, John Schember <john@nachtimwald.com>'
 
4
__docformat__ = 'restructuredtext en'
 
5
 
 
6
from PyQt4.Qt import QPrinter
 
7
 
 
8
UNITS = {
 
9
            'millimeter' : QPrinter.Millimeter,
 
10
            'point' : QPrinter.Point,
 
11
            'inch' : QPrinter.Inch,
 
12
            'pica' : QPrinter.Pica,
 
13
            'didot' : QPrinter.Didot,
 
14
            'cicero' : QPrinter.Cicero,
 
15
            'devicepixel' : QPrinter.DevicePixel,
 
16
        }
 
17
 
 
18
def unit(unit):
 
19
    return UNITS.get(unit, QPrinter.Inch)
 
20
 
 
21
PAPER_SIZES = {
 
22
                'a0' : QPrinter.A0, # 841 x 1189 mm
 
23
                'a1' : QPrinter.A1, # 594 x 841 mm
 
24
                'a2' : QPrinter.A2, # 420 x 594 mm
 
25
                'a3' : QPrinter.A3, # 297 x 420 mm
 
26
                'a4' : QPrinter.A4, # 210 x 297 mm, 8.26 x 11.69 inches
 
27
                'a5' : QPrinter.A5, # 148 x 210 mm
 
28
                'a6' : QPrinter.A6, # 105 x 148 mm
 
29
                'a7' : QPrinter.A7, # 74 x 105 mm
 
30
                'a8' : QPrinter.A8, # 52 x 74 mm
 
31
                'a9' : QPrinter.A9, # 37 x 52 mm
 
32
                'b0' : QPrinter.B0, # 1030 x 1456 mm
 
33
                'b1' : QPrinter.B1, # 728 x 1030 mm
 
34
                'b2' : QPrinter.B2, # 515 x 728 mm
 
35
                'b3' : QPrinter.B3, # 364 x 515 mm
 
36
                'b4' : QPrinter.B4, # 257 x 364 mm
 
37
                'b5' : QPrinter.B5, # 182 x 257 mm, 7.17 x 10.13 inches
 
38
                'b6' : QPrinter.B6, # 128 x 182 mm
 
39
                'b7' : QPrinter.B7, # 91 x 128 mm
 
40
                'b8' : QPrinter.B8, # 64 x 91 mm
 
41
                'b9' : QPrinter.B9, # 45 x 64 mm
 
42
                'b10' : QPrinter.B10, # 32 x 45 mm
 
43
                'c5e' : QPrinter.C5E, # 163 x 229 mm
 
44
                'comm10e' : QPrinter.Comm10E, # 105 x 241 mm, U.S. Common 10 Envelope
 
45
                'dle' : QPrinter.DLE, # 110 x 220 mm
 
46
                'executive' : QPrinter.Executive, # 7.5 x 10 inches, 191 x 254 mm
 
47
                'folio' : QPrinter.Folio, # 210 x 330 mm
 
48
                'ledger' : QPrinter.Ledger, # 432 x 279 mm
 
49
                'legal' : QPrinter.Legal, # 8.5 x 14 inches, 216 x 356 mm
 
50
                'letter' : QPrinter.Letter, # 8.5 x 11 inches, 216 x 279 mm
 
51
                'tabloid' : QPrinter.Tabloid, #  279 x 432 mm
 
52
                #'custom' : QPrinter.Custom, # Unknown, or a user defined size.
 
53
             }
 
54
 
 
55
def paper_size(size):
 
56
    return PAPER_SIZES.get(size, QPrinter.Letter)
 
57
 
 
58
ORIENTATIONS = {
 
59
                'portrait' : QPrinter.Portrait,
 
60
                'landscape' : QPrinter.Landscape,
 
61
               }
 
62
 
 
63
def orientation(orientation):
 
64
    return ORIENTATIONS.get(orientation, QPrinter.Portrait)
 
65
 
 
66
def size(size):
 
67
    try:
 
68
        return int(size)
 
69
    except:
 
70
        return 1