Skip to content

Commit

Permalink
- Switched to Pillow (from PIL).
Browse files Browse the repository at this point in the history
- Switched RML highlighting in RML Reference from SilverCity to Pygments.

- Bug: Properly reset pdfform before rendering a document.

- Bug: Reset fonts properly before a rendering.
  • Loading branch information
strichter committed Dec 18, 2012
1 parent b4b4749 commit de6c3ce
Show file tree
Hide file tree
Showing 15 changed files with 400 additions and 79 deletions.
17 changes: 16 additions & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,24 @@
CHANGES
=======

1.0.1 (unreleased)
1.1.0 (2012-12-18)
------------------

- Upgrade to ReportLab 2.6. This required some font changes and several
generated PDFs did not match, since some default fonts changed to sans-serif.

- Added ``pdfInclude`` directive from Alex Garel. (LP #969399).

- Switched to Pillow (from PIL).

- Switched RML highlighting in RML Reference from SilverCity to Pygments.

- Bug: Addressed a bug in ReportLab 2.6 that disallowed 3-D pie charts from
rendering.

- Bug: Properly reset pdfform before rendering a document.

- Bug: Reset fonts properly before a rendering.


1.0.0 (2012-04-02)
Expand Down
4 changes: 2 additions & 2 deletions buildout.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@ eggs = ${test:eggs}

[versions]
reportlab = 2.6
PIL = 1.1.7
lxml = 2.3
Pillow = 1.7.8
lxml = 3.0.2
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def read(*rnames):

setup (
name='z3c.rml',
version='1.0.1dev',
version='1.1.0',
author = "Stephan Richter and the Zope Community",
author_email = "zope-dev@zope.org",
description = "An alternative implementation of RML",
Expand All @@ -46,11 +46,12 @@ def read(*rnames):
extras_require = dict(
test = [
'zope.pagetemplate',
'PIL'],
'Pillow'],
pagetemplate = [
'zope.pagetemplate']
),
install_requires = [
'Pygments',
'lxml',
'pyPdf',
'reportlab',
Expand Down
1 change: 1 addition & 0 deletions src/z3c/rml/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

# Hook up our custom paragraph parser.
import z3c.rml.paraparser
import z3c.rml.rlfix
6 changes: 0 additions & 6 deletions src/z3c/rml/chart.py
Original file line number Diff line number Diff line change
Expand Up @@ -1621,12 +1621,6 @@ class PieChart3D(PieChart):
'slices': Slices3D,
})

def createChart(self, attrs):
# Bugfix for ReportLab 2.6: PieChart3D.sideLabels attr is missing.
attrs['sideLabels'] = 0
return super(PieChart3D, self).createChart(attrs)


class ISpiderChart(IChart):
"""A spider chart."""
occurence.containing(
Expand Down
10 changes: 7 additions & 3 deletions src/z3c/rml/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
from reportlab.pdfbase import pdfmetrics, ttfonts, cidfonts
from reportlab.lib import fonts

from z3c.rml import attr, directive, interfaces, occurence
from z3c.rml import canvas, stylesheet, template, pdfinclude
from z3c.rml import attr, canvas, directive, interfaces, occurence
from z3c.rml import pdfinclude, stylesheet, template


class IRegisterType1Face(interfaces.IRMLDirectiveSignature):
Expand Down Expand Up @@ -253,10 +253,14 @@ def __init__(self, element):
self.styles = {}
self.colors = {}
self.postProcessors = []
self.filename = '<unknwon>'
self.filename = '<unknown>'

def process(self, outputFile=None):
"""Process document"""
# Reset all reportlab global variables. This is very important for
# ReportLab not to fail.
reportlab.rl_config._reset()

if outputFile is None:
# TODO: This is relative to the input file *not* the CWD!!!
outputFile = open(self.element.get('filename'), 'wb')
Expand Down
2 changes: 1 addition & 1 deletion src/z3c/rml/flowable.py
Original file line number Diff line number Diff line change
Expand Up @@ -755,7 +755,7 @@ class IKeepTogether(interfaces.IRMLDirectiveSignature):
description=u'The maximum height the flowables are allotted.',
default=None,
required=False)

class KeepTogether(Flowable):
signature = IKeepTogether
klass = reportlab.platypus.flowables.KeepTogether
Expand Down
7 changes: 6 additions & 1 deletion src/z3c/rml/pdfinclude.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
pyPdf = None
from reportlab.platypus import flowables

from z3c.rml import attr, flowable, interfaces, page
from z3c.rml import attr, flowable, interfaces, occurence, page


class PDFIncludeFlowable(flowables.Flowable):
Expand Down Expand Up @@ -82,3 +82,8 @@ def process(self):


flowable.Flow.factories['pdfInclude'] = PDFInclude
flowable.IFlow.setTaggedValue(
'directives',
flowable.IFlow.getTaggedValue('directives') +
(occurence.ZeroOrMore('pdfInclude', IPDFInclude),)
)
23 changes: 8 additions & 15 deletions src/z3c/rml/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,14 @@
import copy
import re
import os
import pygments.token
import zope.schema
import zope.schema.interfaces
from lxml import etree
from xml.sax import saxutils
from pygments.lexers import XmlLexer
from z3c.rml import attr, document, interfaces, pagetemplate

try:
import SilverCity
except ImportError:
SilverCity = None


INPUT_URL = ('http://svn.zope.org/*checkout*/z3c.rml/trunk/src/z3c/'
'rml/tests/input/%s')
Expand All @@ -41,10 +38,8 @@
attr.TextNode, attr.TextNodeSequence, attr.TextNodeGrid,
attr.RawXMLContent, attr.XMLContent)
STYLES_FORMATTING = {
1 : ('<font textColor="red">', '</font>'),
#3 : ('<font textColor="blue">', '</font>'),
6 : ('<font textColor="blue">', '</font>'),
11 : ('<font textColor="red">', '</font>'),
pygments.token.Name.Tag : ('<font textColor="red">', '</font>'),
pygments.token.Literal.String : ('<font textColor="blue">', '</font>'),
}
EXAMPLE_NS = 'http://namespaces.zope.org/rml/doc'
EXAMPLE_ATTR_NAME = '{%s}example' %EXAMPLE_NS
Expand Down Expand Up @@ -79,13 +74,11 @@ def enforceColumns(rml, columns=80):
return '\n'.join(result)

def highlightRML(rml):
if SilverCity is None:
return saxutils.escape(rml)
lexer = SilverCity.XML.XMLLexer()
lexer = XmlLexer()
styledRml = ''
for piece in lexer.tokenize_by_style(rml):
start, end = STYLES_FORMATTING.get(piece['style'], ('', ''))
styledRml += start + saxutils.escape(piece['text']) + end
for ttype, token in lexer.get_tokens(rml):
start, end = STYLES_FORMATTING.get(ttype, ('', ''))
styledRml += start + saxutils.escape(token) + end
return styledRml


Expand Down
42 changes: 42 additions & 0 deletions src/z3c/rml/rlfix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
##############################################################################
#
# Copyright (c) 2012 Zope Foundation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""ReportLab fixups.
"""
__docformat__ = "reStructuredText"
from reportlab.pdfbase import pdfform
from reportlab.pdfbase.pdfpattern import PDFPattern
from reportlab.graphics import testshapes

def resetPdfForm():
pdfform.PDFDOCENC = PDFPattern(pdfform.PDFDocEncodingPattern)
pdfform.ENCODING = PDFPattern(
pdfform.EncodingPattern, PDFDocEncoding=pdfform.PDFDOCENC)
pdfform.GLOBALFONTSDICTIONARY = pdfform.FormFontsDictionary()
pdfform.GLOBALRESOURCES = pdfform.FormResources()
pdfform.ZADB = PDFPattern(pdfform.ZaDbPattern)

def resetFonts():
for f in testshapes._setup():
if f not in testshapes._FONTS:
testshapes._FONTS.append(f)

def setSideLabels():
from reportlab.graphics.charts import piecharts
piecharts.Pie3d.sideLabels = 0
setSideLabels()

from reportlab.rl_config import register_reset
register_reset(resetPdfForm)
register_reset(resetFonts)
del register_reset
Binary file modified src/z3c/rml/rml-reference.pdf
Binary file not shown.
Loading

0 comments on commit de6c3ce

Please sign in to comment.