support top level Lang; version-->3.1.54
authorrobin
Thu, 16 Apr 2015 14:52:55 +0100
changeset 4184 4e8fc7fc7092
parent 4183 66b0c5b63b07
child 4185 8c932a166cd2
support top level Lang; version-->3.1.54
src/reportlab/__init__.py
src/reportlab/pdfbase/pdfdoc.py
src/reportlab/pdfgen/canvas.py
src/reportlab/platypus/doctemplate.py
--- a/src/reportlab/__init__.py	Wed Apr 15 14:43:00 2015 +0100
+++ b/src/reportlab/__init__.py	Thu Apr 16 14:52:55 2015 +0100
@@ -3,7 +3,7 @@
 #history http://www.reportlab.co.uk/cgi-bin/viewcvs.cgi/public/reportlab/trunk/reportlab/__init__.py
 __version__=''' $Id$ '''
 __doc__="""The Reportlab PDF generation library."""
-Version = "3.1.53"
+Version = "3.1.54"
 
 import sys, os, imp
 
--- a/src/reportlab/pdfbase/pdfdoc.py	Wed Apr 15 14:43:00 2015 +0100
+++ b/src/reportlab/pdfbase/pdfdoc.py	Thu Apr 16 14:52:55 2015 +0100
@@ -997,6 +997,7 @@
     # to override, set as attributes
     __Defaults__ = {"Type": PDFName("Catalog"),
                 "PageMode": PDFName("UseNone"),
+                "Lang": None,
                 }
     __NoDefault__ = """
         Dests Outlines Pages Threads AcroForm Names OpenAction PageMode URI
@@ -1008,20 +1009,14 @@
         defaults = self.__Defaults__
         Refs = self.__Refs__
         D = {}
-        for k in defaults.keys():
-            default = defaults[k]
-            v = None
-            if hasattr(self, k) and getattr(self,k) is not None:
-                v = getattr(self, k)
-            elif default is not None:
-                v = default
+        for k,v in defaults.items():
+            v = getattr(self,k,v)
             if v is not None:
                 D[k] = v
         for k in self.__NoDefault__:
-            if hasattr(self, k):
-                v = getattr(self,k)
-                if v is not None:
-                    D[k] = v
+            v = getattr(self,k,None)
+            if v is not None:
+                D[k] = v
         # force objects to be references where required
         for k in Refs:
             if k in D:
--- a/src/reportlab/pdfgen/canvas.py	Wed Apr 15 14:43:00 2015 +0100
+++ b/src/reportlab/pdfgen/canvas.py	Thu Apr 16 14:52:55 2015 +0100
@@ -1833,6 +1833,23 @@
         '''you'll get an error here if none have been set'''
         del self._doc.Catalog.ViewerPreferences[pref]
 
+    def setCatalogEntry(self,key,value):
+        from reportlab.pdfbase.pdfdoc import PDFDictionary, PDFArray, PDFString
+        if isStr(value):
+            value = PDFString(value)
+        elif isinstance(value,(list,tuple)):
+            value = PDFArray(value)
+        elif isinstance(value,dict):
+            value = PDFDictionary(value)
+        setattr(self._doc.Catalog,key,value)
+
+    def getCatalogEntry(self,key):
+        return getattr(self._doc.Catalog,key)
+
+    def delCatalogEntry(self,key):
+        '''you'll get an error here if it's not been set'''
+        delattr(self._doc.Catalog,key)
+
     def addPageLabel(self, pageNum, style=None, start=None, prefix=None):
         '''add a PDFPageLabel for pageNum'''
         catalog = self._doc.Catalog
--- a/src/reportlab/platypus/doctemplate.py	Wed Apr 15 14:43:00 2015 +0100
+++ b/src/reportlab/platypus/doctemplate.py	Thu Apr 16 14:52:55 2015 +0100
@@ -36,6 +36,7 @@
 import reportlab.lib.sequencer
 from reportlab.pdfgen import canvas
 from reportlab.lib.utils import isSeq, encode_label, decode_label, annotateException, strTypes
+
 try:
     set
 except NameError:
@@ -451,6 +452,7 @@
                     'cropMarks': None,
                     'enforceColorSpace': None,
                     'displayDocTitle': None,
+                    'lang': None,
                     }
     _invalidInitArgs = ()
     _firstPageTemplateIndex = 0
@@ -867,6 +869,8 @@
         self.canv.setKeywords(self.keywords)
         if self.displayDocTitle is not None:
             self.canv.setViewerPreference('DisplayDocTitle',['false','true'][self.displayDocTitle])
+        if self.lang:
+            self.canv.setCatalogEntry('Lang',self.lang)
 
         if self._onPage:
             self.canv.setPageCallBack(self._onPage)