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 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 _get_font_style(self, data, **kwargs): """generate font and text style object @note font definition data is extracted from `PyRTF` package @param data basic text style information (dict) @return (string, font_obj, text_style_obj) """ font_short_name = data.get('font', self.DEFAULT_FONT_NAME) font_size = data.get('size', int(self.DEFAULT_FONT_SIZE)) font_decor = data.get('modifier', self.MODIFIER_REGULAR) # _FONT_ARG_HUB = { 'Arial': ('swiss', 0, 2, '020b0604020202020204'), #self.DEFAULT_FONT_NAME: ('swiss', 0, 2, '020b0604020202020204'), 'Arial Black': ('swiss', 0, 2, '020b0a04020102020204'), 'Courier New': ('modern', 0, 1, '02070309020205020404'), #('Bitstream Vera Sans Mono', 'modern', 0, 1, '020b0609030804020204'), #('Monotype Corsiva', 'script', 0, 2, '03010101010201010101'), #('Tahoma', 'swiss', 0, 2, '020b0604030504040204'), #('Trebuchet MS', 'swiss', 0, 2, '020b0603020202020204'), } additional_font_mapping = kwargs.get('alt.font.map', None) if isinstance(additional_font_mapping, dict): _FONT_ARG_HUB.update(additional_font_mapping) # if font_decor is None: font_decor = self.MODIFIER_REGULAR # font_obj = None txt_style_obj = None font_full_name = self.FORMAT_FONT_FULL_NAME.format( name=font_short_name, size=font_size, modifier=font_decor) # from PyRTF.Styles import TextStyle from PyRTF.PropertySets import Font from PyRTF.PropertySets import TextPropertySet font_args = _FONT_ARG_HUB.get(font_short_name, _FONT_ARG_HUB[self.DEFAULT_FONT_NAME]) font_obj = Font(font_short_name, *font_args) txt_style_obj = TextStyle(TextPropertySet( font=font_obj, size=2 * font_size, bold=True if font_decor.find(self.MODIFIER_BOLD) > -1 else False, italic=True if font_decor.find(self.MODIFIER_ITALIC) > -1 else False, underline=False, ), name=font_full_name) return (font_full_name, font_obj, txt_style_obj)
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 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
def basic_table_with_input(dependent_variable_name, rows_statistical_significance, number_of_observations, r_squared): #from PyRTF.Elements import Document, Section, BorderPropertySet, FramePropertySet, Table from PyRTF.utils import RTFTestCase from PyRTF.Elements import Document from PyRTF.document.section import Section from PyRTF.document.paragraph import Cell, Paragraph, Table #from PyRTF.Styles import TextStyle, ParagraphStyle from PyRTF.document.character import Text from PyRTF.PropertySets import BorderPropertySet, FramePropertySet, MarginsPropertySet, ParagraphPropertySet, TabPropertySet, TextPropertySet # doc = Document() ss = doc.StyleSheet section = Section() doc.Sections.append(section) # thin_edge = BorderPropertySet(width=20, style=BorderPropertySet.SINGLE, colour=ss.Colours.Black) thick_edge = BorderPropertySet(width=80, style=BorderPropertySet.SINGLE) zero_edge_thin = BorderPropertySet(width=20, style=BorderPropertySet.SINGLE, colour=ss.Colours.White) # thin_frame = FramePropertySet(thin_edge, thin_edge, thin_edge, thin_edge) thick_frame = FramePropertySet(thick_edge, thick_edge, thick_edge, thick_edge) thin_frame_top_only = FramePropertySet(top=thin_edge, left=None, bottom=None, right=None) thin_frame_bottom_only = FramePropertySet(top=None, left=None, bottom=thin_edge, right=None) thin_frame_top_and_bottom_only = FramePropertySet(top=thin_edge, left=None, bottom=thin_edge, right=None) zero_frame = FramePropertySet(top=None, left=None, bottom=None, right=None) # table = Table(TabPropertySet.DEFAULT_WIDTH * 5, TabPropertySet.DEFAULT_WIDTH * 3, TabPropertySet.DEFAULT_WIDTH * 3) # c1 = Cell(Paragraph(''), thin_frame_top_and_bottom_only) c2 = Cell(Paragraph(dependent_variable_name + ' - coeff'), thin_frame_top_and_bottom_only) c3 = Cell(Paragraph(dependent_variable_name + ' - Std error'), thin_frame_top_and_bottom_only) table.AddRow(c1, c2, c3) # for row in rows_statistical_significance: c1 = Cell(Paragraph(row[0]), zero_frame) c2 = Cell(Paragraph(row[1]), zero_frame) c3 = Cell(Paragraph(row[2]), zero_frame) table.AddRow(c1, c2, c3) # #c1 = Cell(Paragraph(''), thin_frame_bottom_only) #c2 = Cell(Paragraph('(.013)'), thin_frame_bottom_only) #c3 = Cell(Paragraph('tbd'), thin_frame_bottom_only) #table.AddRow(c1, c2) # c1 = Cell(Paragraph('Observations'), thin_frame_top_only) c2 = Cell(Paragraph(number_of_observations), thin_frame_top_only) c3 = Cell(Paragraph(''), thin_frame_top_only) table.AddRow(c1, c2, c3) # tps = TextPropertySet(italic=True) text = Text('R^2', tps) # #c1 = Cell(Paragraph('R^2', text), thin_frame_bottom_only) c1 = Cell(Paragraph(text), thin_frame_bottom_only) c2 = Cell(Paragraph(r_squared), thin_frame_bottom_only) c3 = Cell(Paragraph(''), thin_frame_bottom_only) table.AddRow(c1, c2, c3) # section.append(table) # section.append('Standard errors in parentheses') section.append('* p<0.1, ** p<0.05, *** p<0.01') # return doc
def basic_table(): #from PyRTF.Elements import Document, Section, BorderPropertySet, FramePropertySet, Table from PyRTF.utils import RTFTestCase from PyRTF.Elements import Document from PyRTF.document.section import Section from PyRTF.document.paragraph import Cell, Paragraph, Table #from PyRTF.Styles import TextStyle, ParagraphStyle from PyRTF.document.character import Text from PyRTF.PropertySets import BorderPropertySet, FramePropertySet, MarginsPropertySet, ParagraphPropertySet, TabPropertySet, TextPropertySet # doc = Document() ss = doc.StyleSheet section = Section() doc.Sections.append(section) # thin_edge = BorderPropertySet(width=20, style=BorderPropertySet.SINGLE, colour=ss.Colours.Black) thick_edge = BorderPropertySet(width=80, style=BorderPropertySet.SINGLE) zero_edge_thin = BorderPropertySet(width=20, style=BorderPropertySet.SINGLE, colour=ss.Colours.White) # thin_frame = FramePropertySet(thin_edge, thin_edge, thin_edge, thin_edge) thick_frame = FramePropertySet(thick_edge, thick_edge, thick_edge, thick_edge) thin_frame_top_only = FramePropertySet(top=thin_edge, left=None, bottom=None, right=None) thin_frame_bottom_only = FramePropertySet(top=None, left=None, bottom=thin_edge, right=None) thin_frame_top_and_bottom_only = FramePropertySet(top=thin_edge, left=None, bottom=thin_edge, right=None) # table = Table(TabPropertySet.DEFAULT_WIDTH * 5, TabPropertySet.DEFAULT_WIDTH * 3) # c1 = Cell(Paragraph(''), thin_frame_top_and_bottom_only) c2 = Cell(Paragraph('Recommends AI'), thin_frame_top_and_bottom_only) #c3 = Cell(Paragraph('tbd'), thin_frame_top_and_bottom_only) table.AddRow(c1, c2) # c1 = Cell(Paragraph('Read ethics article'), thin_frame_top_only) c2 = Cell(Paragraph('-.38***'), thin_frame_top_only) #c3 = Cell(Paragraph('tbd'), thin_frame_top_only) table.AddRow(c1, c2) # c1 = Cell(Paragraph(''), thin_frame_bottom_only) c2 = Cell(Paragraph('(.013)'), thin_frame_bottom_only) #c3 = Cell(Paragraph('tbd'), thin_frame_bottom_only) table.AddRow(c1, c2) # c1 = Cell(Paragraph('Observations'), thin_frame_top_only) c2 = Cell(Paragraph('5000'), thin_frame_top_only) #c3 = Cell(Paragraph('tbd'), thin_frame_top_and_bottom_only) table.AddRow(c1, c2) # tps = TextPropertySet(italic=True) text = Text('R^2', tps) # #c1 = Cell(Paragraph('R^2', text), thin_frame_bottom_only) c1 = Cell(Paragraph(text), thin_frame_bottom_only) c2 = Cell(Paragraph('0.147'), thin_frame_bottom_only) #c3 = Cell(Paragraph('tbd'), thin_frame_bottom_only) table.AddRow(c1, c2) # section.append(table) # section.append('Standard errors in parentheses') section.append('* p<0.1, ** p<0.05, *** p<0.01') # return doc