def test_text(self): t = Text() t = Text('abc') style = StyleSheet() normalText = TextStyle(TextPropertySet(style.Fonts.Arial, 22)) blue = TextPropertySet(colour=style.Colours.Blue) shading = ShadingPropertySet() t = Text(normalText, blue, shading, 'abc')
def test_TextPropertySet(self): style = StyleSheet() blue = TextPropertySet(colour=style.Colours.Blue) red = blue.Copy() red.colour = style.Colours.Red # Confirm that the copies are independent objects. assert blue.colour == style.Colours.Blue assert red.colour == style.Colours.Red
def test_ParagraphStyle(self): # Normal constructor. style = StyleSheet() normalText = TextStyle(TextPropertySet(style.Fonts.Arial, 22)) ps = ParagraphStyle('Normal', normalText.Copy()) assert ps.name == 'Normal' # Not sending font to constructor. noStyle = TextStyle(TextPropertySet()) self.assertRaises(Exception, ParagraphStyle, 'Normal', noStyle) # Not sending size to constructor. fontOnlyStyle = TextStyle(TextPropertySet(style.Fonts.Arial)) self.assertRaises(Exception, ParagraphStyle, 'Normal', fontOnlyStyle)
def U(*params): textProps = TextPropertySet(underline=True) if len(params) == 1: return Text(params[0], textProps) result = Inline(textProps) result.append(*params) return result
def I(*params): textProps = TextPropertySet(italic=True) if len(params) == 1: return Text(params[0], textProps) result = Inline(textProps) result.append(*params) return result
def B(*params): textProps = TextPropertySet(bold=True) if len(params) == 1: return Text(params[0], textProps) result = Inline(textProps) apply(result.append, params) return result
def make_charFrame(): doc, section, styles = RTFTestCase.initializeDoc() p = Paragraph() thinEdge = BorderPropertySet(width=20, style=BorderPropertySet.SINGLE, colour=styles.Colours.Blue) textWithFrame = TextPropertySet(frame=thinEdge) p.append(Text('This tests frame drawn around text.', textWithFrame)) section.append(p) return doc
def TEXT(*params, **kwargs): textProps = TextPropertySet() textProps.font = kwargs.get('font', None) textProps.size = kwargs.get('size', None) textProps.bold = kwargs.get('bold', False) textProps.italic = kwargs.get('italic', False) textProps.underline = kwargs.get('underline', False) textProps.colour = kwargs.get('colour', None) if len(params) == 1: return Text(params[0], textProps) result = Inline(textProps) result.append(*params) return result
def TEXT(*params, **kwargs): textProps = TextPropertySet() textProps.font = kwargs.get('font', None) textProps.size = kwargs.get('size', None) textProps.bold = kwargs.get('bold', False) textProps.italic = kwargs.get('italic', False) textProps.underline = kwargs.get('underline', False) textProps.colour = kwargs.get('colour', None) textProps.hyperlink = kwargs.get('hyperlink', None) if len(params) == 1: return Text(params[0], textProps) result = Inline(textProps) result.append(*params) return result
def make_charColours(): doc, section, styles = RTFTestCase.initializeDoc() section.append('This example test changing the colour of fonts.') # Text properties can be specified in two ways, either a text object # can have its text properties specified via the TextPropertySet # object, or by passing the colour parameter as a style. red = TextPropertySet(colour=styles.Colours.Red) green = TextPropertySet(colour=styles.Colours.Green) blue = TextPropertySet(colour=styles.Colours.Blue) yellow = TextPropertySet(colour=styles.Colours.Yellow) p = Paragraph() p.append('This next word should be in ') p.append(Text('red', red)) p.append(', while the following should be in their respective ') p.append('colours: ', Text('blue ', blue), Text('green ', green)) p.append('and ', TEXT('yellow', colour=styles.Colours.Yellow), '.') # When specifying colours it is important to use the colours from the # style sheet supplied with the document and not the StandardColours # object each document get its own copy of the stylesheet so that # changes can be made on a document by document basis without mucking # up other documents that might be based on the same basic stylesheet. section.append(p) return doc
print str(datetime.datetime.now()) csvReader = csv.reader(open('Award Data Collection Effort Sample.csv', 'rb'), delimiter='|') n = 0 previousYear = None previousRFA = None report_title = 'Sample CTSI Pilot Award Report' doc = Document() ss = doc.StyleSheet # Improve the style sheet ps = ParagraphStyle('Title', TextStyle(TextPropertySet(ss.Fonts.Arial, 44)).Copy(), ParagraphPropertySet(space_before=60, space_after=60)) ss.ParagraphStyles.append(ps) ps = ParagraphStyle('Heading 3', TextStyle(TextPropertySet(ss.Fonts.Arial, 22)).Copy(), ParagraphPropertySet(space_before=60, space_after=60)) ss.ParagraphStyles.append(ps) ps = ParagraphStyle('Heading 4', TextStyle(TextPropertySet(ss.Fonts.Arial, 22)).Copy(), ParagraphPropertySet(space_before=60, space_after=60)) ss.ParagraphStyles.append(ps) section = Section() doc.Sections.append(section) section.FirstHeader.append(' ')
top_frame = FramePropertySet(top=thin_edge) doc = Document() ss = doc.StyleSheet # Set the margins for the section at 0.5 inch on all sides ms = MarginsPropertySet(top=720, left=720, right=720, bottom=720) section = Section(margins=ms) doc.Sections.append(section) # Improve the style sheet. 1440 twips to the inch ps = ParagraphStyle( 'Title', TextStyle(TextPropertySet(ss.Fonts.Arial, 22, bold=True)).Copy(), ParagraphPropertySet(alignment=3, space_before=270, space_after=30)) ss.ParagraphStyles.append(ps) ps = ParagraphStyle( 'Subtitle', TextStyle(TextPropertySet(ss.Fonts.Arial, 16)).Copy(), ParagraphPropertySet(alignment=3, space_before=0, space_after=0)) ss.ParagraphStyles.append(ps) ps = ParagraphStyle('SubtitleLeft', TextStyle(TextPropertySet(ss.Fonts.Arial, 16)).Copy(), ParagraphPropertySet(space_before=0, space_after=0)) ss.ParagraphStyles.append(ps) ps = ParagraphStyle( 'Heading 3', TextStyle(TextPropertySet(ss.Fonts.Arial, 22, bold=True)).Copy(), ParagraphPropertySet(space_before=180,
def render(self): """ Mostly a copy of the render method in OSHAActionPlanReportDownload, but with some changes to handle the special reqs of Italy """ document = report.createDocument(self.session) ss = document.StyleSheet # Define some more custom styles ss.ParagraphStyles.append( ParagraphStyle( "RiskPriority", TextStyle( TextPropertySet(font=ss.Fonts.Arial, size=22, italic=True, colour=ss.Colours.Blue)), ParagraphPropertySet(left_indent=300, right_indent=300))) ss.ParagraphStyles.append( ParagraphStyle( "MeasureField", TextStyle( TextPropertySet(font=ss.Fonts.Arial, size=18, underline=True)), ParagraphPropertySet(left_indent=300, right_indent=300))) ss.ParagraphStyles.append( ParagraphStyle( "ITTitle", TextStyle( TextPropertySet(font=ss.Fonts.Arial, size=36, italic=True, bold=True)), ParagraphPropertySet(left_indent=300, right_indent=300))) ss.ParagraphStyles.append( ParagraphStyle( "ITSubtitle", TextStyle( TextPropertySet(font=ss.Fonts.Arial, size=32, italic=True, bold=True)), ParagraphPropertySet(left_indent=300, right_indent=300))) ss.ParagraphStyles.append( ParagraphStyle( "ITSubSubtitle", TextStyle( TextPropertySet(font=ss.Fonts.Arial, size=28, italic=True, bold=True)), ParagraphPropertySet(left_indent=300, right_indent=300))) ss.ParagraphStyles.append( ParagraphStyle( "ITNormalBold", TextStyle( TextPropertySet(font=ss.Fonts.Arial, size=24, bold=True)), ParagraphPropertySet(left_indent=50, right_indent=50))) # XXX: This part is removed # self.addActionPlan(document) # XXX: and replaced with this part: t = lambda txt: "".join([ "\u%s?" % str(ord(e)) for e in translate(txt, context=self.request) ]) intro = createItalianIntro(document, self.context, self.request) toc = createSection(document, self.context, self.request, first_page_number=2) body = Section() heading = t( _("header_oira_report_download", default=u"OiRA Report: \"${title}\"", mapping=dict(title=self.session.title))) toc.append( Paragraph( ss.ParagraphStyles.Heading1, ParagraphPropertySet(alignment=ParagraphPropertySet.CENTER), heading, )) if self.session.report_comment: # Add comment. #5985 normal_style = document.StyleSheet.ParagraphStyles.Normal toc.append(Paragraph(normal_style, self.session.report_comment)) toc_props = ParagraphPropertySet() toc_props.SetLeftIndent(TabPropertySet.DEFAULT_WIDTH * 1) toc_props.SetRightIndent(TabPropertySet.DEFAULT_WIDTH * 1) p = Paragraph(ss.ParagraphStyles.Heading6, toc_props) txt = t(_("toc_header", default=u"Contents")) p.append(character.Text(txt)) toc.append(p) headings = [ t(u"Adempimenti/rischi identificati, valutati e gestiti con misure " "obbligatorie adottate ed eventuali misure di miglioramento"), t(u"Adempimenti/rischi non pertinenti"), ] nodes = [ self.actioned_nodes, self.risk_not_present_nodes, ] for nodes, heading in zip(nodes, headings): if not nodes: continue self.addReportNodes(document, nodes, heading, toc, body) toc.append(Paragraph(LINE)) body.append(Paragraph(LINE)) document.Sections.append(body) # Until here... renderer = Renderer() output = StringIO() renderer.Write(document, output) # Custom filename filename = u"Documento di valutazione dei rischi {}".format( self.session.title) self.request.response.setHeader( "Content-Disposition", "attachment; filename=\"%s.rtf\"" % filename.encode("utf-8")) self.request.response.setHeader("Content-Type", "application/rtf") return output.getvalue()
def render(self): """ Mostly a copy of the render method in euphorie.client, but with some changes to also show unanswered risks and non-present risks. #1517 and #1518 """ document = report.createDocument(self.session) ss = document.StyleSheet # Define some more custom styles ss.ParagraphStyles.append( ParagraphStyle( "RiskPriority", TextStyle( TextPropertySet(font=ss.Fonts.Arial, size=22, italic=True, colour=ss.Colours.Blue)), ParagraphPropertySet(left_indent=300, right_indent=300))) ss.ParagraphStyles.append( ParagraphStyle( "MeasureField", TextStyle( TextPropertySet(font=ss.Fonts.Arial, size=18, underline=True)), ParagraphPropertySet(left_indent=300, right_indent=300))) # XXX: This part is removed # self.addActionPlan(document) # XXX: and replaced with this part: t = lambda txt: "".join([ "\u%s?" % str(ord(e)) for e in translate(txt, context=self.request) ]) toc = createSection(document, self.context, self.request) body = Section() heading = t( _("header_oira_report_download", default=u"OiRA Report: \"${title}\"", mapping=dict(title=self.session.title))) toc.append( Paragraph( ss.ParagraphStyles.Heading1, ParagraphPropertySet(alignment=ParagraphPropertySet.CENTER), heading, )) if self.session.report_comment: # Add comment. #5985 normal_style = document.StyleSheet.ParagraphStyles.Normal toc.append(Paragraph(normal_style, self.session.report_comment)) toc_props = ParagraphPropertySet() toc_props.SetLeftIndent(TabPropertySet.DEFAULT_WIDTH * 1) toc_props.SetRightIndent(TabPropertySet.DEFAULT_WIDTH * 1) p = Paragraph(ss.ParagraphStyles.Heading6, toc_props) txt = t(_("toc_header", default=u"Contents")) p.append(character.Text(txt)) toc.append(p) headings = [ t( _("header_present_risks", default=u"Risks that have been identified, " u"evaluated and have an Action Plan")), t( _("header_unevaluated_risks", default=u"Risks that have been identified but " u"do NOT have an Action Plan")), t( _("header_unanswered_risks", default=u'Hazards/problems that have been "parked" ' u'and are still to be dealt with')), t( _("header_risks_not_present", default=u"Hazards/problems that have been managed " u"or are not present in your organisation")) ] nodes = [ self.actioned_nodes, self.unactioned_nodes, self.unanswered_nodes, self.risk_not_present_nodes, ] for nodes, heading in zip(nodes, headings): if not nodes: continue self.addReportNodes(document, nodes, heading, toc, body) toc.append(Paragraph(LINE)) body.append(Paragraph(LINE)) self.addConsultationBox(body, document) document.Sections.append(body) # Until here... renderer = Renderer() output = StringIO() renderer.Write(document, output) filename = translate( _("filename_report_actionplan", default=u"Action plan ${title}", mapping=dict(title=self.session.title)), context=self.request, ) self.request.response.setHeader( "Content-Disposition", "attachment; filename=\"%s.rtf\"" % filename.encode("utf-8")) self.request.response.setHeader("Content-Type", "application/rtf") return output.getvalue()
def addReportNodes(self, document, nodes, heading, toc, body): """ """ t = lambda txt: "".join([ "\u%s?" % str(ord(e)) for e in translate(txt, context=self.request) ]) ss = document.StyleSheet toc_props = ParagraphPropertySet() toc_props.SetLeftIndent(TabPropertySet.DEFAULT_WIDTH * 1) toc_props.SetRightIndent(TabPropertySet.DEFAULT_WIDTH * 1) p = Paragraph(ss.ParagraphStyles.Heading6, toc_props) p.append(character.Text(heading, TextPropertySet(italic=True))) toc.append(p) body.append(Paragraph(ss.ParagraphStyles.Heading1, heading)) survey = self.request.survey styles = ss.ParagraphStyles header_styles = { 0: styles.Heading2, 1: styles.Heading3, 2: styles.Heading4, 3: styles.Heading5, 4: styles.Heading6, } for node in nodes: zodb_node = None if node.zodb_path == 'custom-risks': title = self.title_custom_risks elif getattr(node, 'is_custom_risk', None): title = node.title else: zodb_node = survey.restrictedTraverse( node.zodb_path.split("/")) title = node_title(node, zodb_node) thin_edge = BorderPropertySet(width=20, style=BorderPropertySet.SINGLE) if node.depth == 1: p = Paragraph( header_styles.get(node.depth, styles.Heading6), FramePropertySet(thin_edge, thin_edge, thin_edge, thin_edge), u"%s %s" % (node.number, title)) else: p = Paragraph(header_styles.get(node.depth, styles.Heading6), u"%s %s" % (node.number, title)) body.append(p) if node.type != "risk": continue if node.priority: if node.priority == "low": level = _("risk_priority_low", default=u"low") elif node.priority == "medium": level = _("risk_priority_medium", default=u"medium") elif node.priority == "high": level = _("risk_priority_high", default=u"high") msg = _("risk_priority", default="This is a ${priority_value} priority risk.", mapping={'priority_value': level}) body.append(Paragraph(styles.RiskPriority, t(msg))) # In the report for Italy, don't print the description if (getattr(node, 'identification', None) == 'no' and not IOSHAItalyReportPhaseSkinLayer.providedBy( self.request)): if zodb_node is None: description = node.title else: description = zodb_node.description body.append( Paragraph( styles.Normal, ParagraphPropertySet(left_indent=300, right_indent=300), t( _( utils.html_unescape( htmllaundry.StripMarkup(description)))))) body.append(Paragraph("")) if node.comment and node.comment.strip(): body.append(Paragraph(styles.Comment, node.comment)) for (idx, measure) in enumerate(node.action_plans): if not measure.action_plan: continue if len(node.action_plans) == 1: heading = t(_("header_measure_single", default=u"Measure")) else: heading = t( _("header_measure", default=u"Measure ${index}", mapping={"index": idx + 1})) self.addMeasure(document, heading, body, measure)