Beispiel #1
0
    def it_can_replace_the_text_it_contains(self, text_set_fixture):
        txBody, text, expected_xml = text_set_fixture
        text_frame = TextFrame(txBody, None)

        text_frame.text = text

        assert text_frame._element.xml == expected_xml
Beispiel #2
0
    def it_can_replace_the_text_it_contains(self, text_set_fixture):
        txBody, text, expected_xml = text_set_fixture
        text_frame = TextFrame(txBody, None)

        text_frame.text = text

        assert text_frame._element.xml == expected_xml
Beispiel #3
0
    def it_applies_fit_to_help_fit_text(self, request):
        family, font_size, bold, italic = "Family", 42, True, False
        _set_font_ = method_mock(request, TextFrame, "_set_font")
        text_frame = TextFrame(element("p:txBody/a:bodyPr"), None)

        text_frame._apply_fit(family, font_size, bold, italic)

        assert text_frame.auto_size is MSO_AUTO_SIZE.NONE
        assert text_frame.word_wrap is True
        _set_font_.assert_called_once_with(text_frame, family, font_size, bold, italic)
Beispiel #4
0
    def text_frame(self):
        """
        |TextFrame| instance containing the text that appears in the cell.

        :rtype: TextFrame
        """
        txBody = self._tc.get_or_add_txBody()
        return TextFrame(txBody, self)
Beispiel #5
0
    def text_frame(self):
        """|TextFrame| instance for this shape.

        Contains the text of the shape and provides access to text formatting
        properties.
        """
        txBody = self._element.get_or_add_txBody()
        return TextFrame(txBody, self)
    def it_can_resize_its_text_to_best_fit(self, text_prop_,
                                           _best_fit_font_size_, _apply_fit_):
        family, max_size, bold, italic, font_file, font_size = ('Family', 42,
                                                                'bold',
                                                                'italic',
                                                                'font_file',
                                                                21)
        text_prop_.return_value = 'some text'
        _best_fit_font_size_.return_value = font_size
        text_frame = TextFrame(None, None)

        text_frame.fit_text(family, max_size, bold, italic, font_file)

        text_frame._best_fit_font_size.assert_called_once_with(
            family, max_size, bold, italic, font_file)
        text_frame._apply_fit.assert_called_once_with(family, font_size, bold,
                                                      italic)
Beispiel #7
0
    def text_frame(self):
        """|TextFrame| instance for this axis title.

        Return a |TextFrame| instance allowing read/write access to the text
        of this axis title and its text formatting properties. Accessing this
        property is destructive as it adds a new text frame if not already
        present.
        """
        rich = self._title.get_or_add_tx_rich()
        return TextFrame(rich, self)
Beispiel #8
0
 def fit_text_fixture(self, _best_fit_font_size_, _apply_fit_):
     text_frame = TextFrame(None, None)
     family, max_size, bold, italic, font_file, font_size = ('Family', 42,
                                                             'bold',
                                                             'italic',
                                                             'font_file',
                                                             21)
     _best_fit_font_size_.return_value = font_size
     return (text_frame, family, max_size, bold, italic, font_file,
             font_size)
Beispiel #9
0
 def size_font_fixture(self, FontFiles_, TextFitter_, text_prop_,
                       _extents_prop_):
     text_frame = TextFrame(None, None)
     family, max_size, bold, italic = 'Family', 42, True, False
     text, extents, font_size, font_file = 'text', (111, 222), 21, 'f.ttf'
     text_prop_.return_value = text
     _extents_prop_.return_value = extents
     FontFiles_.find.return_value = font_file
     TextFitter_.best_fit_font_size.return_value = font_size
     return (text_frame, family, max_size, bold, italic, FontFiles_,
             TextFitter_, text, extents, font_file, font_size)
Beispiel #10
0
    def text_frame(self):
        """|TextFrame| instance for this chart title.

        Return a |TextFrame| instance allowing read/write access to the text
        of this chart title and its text formatting properties. Accessing this
        property is destructive in the sense it adds a text frame if one is
        not present. Use :attr:`has_text_frame` to test for the presence of
        a text frame non-destructively.
        """
        rich = self._title.get_or_add_tx_rich()
        return TextFrame(rich, self)
Beispiel #11
0
    def it_knows_what_text_it_contains(
        self, request, text_get_fixture, paragraphs_prop_
    ):
        paragraph_texts, expected_value = text_get_fixture
        paragraphs_prop_.return_value = tuple(
            instance_mock(request, _Paragraph, text=text) for text in paragraph_texts
        )
        text_frame = TextFrame(None, None)

        text = text_frame.text

        assert text == expected_value
    def it_can_resize_its_text_to_best_fit(
        self, text_prop_, _best_fit_font_size_, _apply_fit_
    ):
        family, max_size, bold, italic, font_file, font_size = (
            "Family",
            42,
            "bold",
            "italic",
            "font_file",
            21,
        )
        text_prop_.return_value = "some text"
        _best_fit_font_size_.return_value = font_size
        text_frame = TextFrame(None, None)

        text_frame.fit_text(family, max_size, bold, italic, font_file)

        text_frame._best_fit_font_size.assert_called_once_with(
            family, max_size, bold, italic, font_file
        )
        text_frame._apply_fit.assert_called_once_with(family, font_size, bold, italic)
Beispiel #13
0
    def it_can_resize_its_text_to_best_fit(self, request, text_prop_):
        family, max_size, bold, italic, font_file, font_size = (
            "Family",
            42,
            "bold",
            "italic",
            "font_file",
            21,
        )
        text_prop_.return_value = "some text"
        _best_fit_font_size_ = method_mock(
            request, TextFrame, "_best_fit_font_size", return_value=font_size
        )
        _apply_fit_ = method_mock(request, TextFrame, "_apply_fit")
        text_frame = TextFrame(None, None)

        text_frame.fit_text(family, max_size, bold, italic, font_file)

        _best_fit_font_size_.assert_called_once_with(
            text_frame, family, max_size, bold, italic, font_file
        )
        _apply_fit_.assert_called_once_with(text_frame, family, font_size, bold, italic)
Beispiel #14
0
def replace_text_frame(text_frame: TextFrame,
                       text_frame_data: TextFrameDataType):
    clear_text_frame(text_frame)
    new_text = text_frame_data.value if isinstance(
        text_frame_data, TextStyle) else text_frame_data
    if new_text is None:
        new_text = ''

    style_paragraph = text_frame.paragraphs[0]
    style_run = style_paragraph.runs[0] if len(
        style_paragraph.runs) else style_paragraph.add_run()
    if isinstance(text_frame_data,
                  TextStyle):  # if value type is TextStyleType
        replace_font_style(style_paragraph, text_frame_data)
        replace_font_style(style_run, text_frame_data)

    split_text = to_unicode(f"{new_text}").split('\n')
    for line_num, line_text in enumerate(split_text):
        paragraph = text_frame.add_paragraph(
        ) if line_num != 0 else text_frame.paragraphs[0]
        replace_paragraphs_text(paragraph, line_text)
        copy_paragraph_style(style_paragraph, paragraph)
        copy_font_style(style_run, paragraph.runs[0])
Beispiel #15
0
 def it_can_clear_itself_of_content(self, txBody_cxml):
     text_frame = TextFrame(element(txBody_cxml), None)
     text_frame.clear()
     assert text_frame._element.xml == xml("p:txBody/a:p")
Beispiel #16
0
 def it_raises_on_attempt_to_set_margin_to_non_int(self):
     text_frame = TextFrame(element('p:txBody/a:bodyPr'), None)
     with pytest.raises(TypeError):
         text_frame.margin_bottom = '0.1'
Beispiel #17
0
 def text_frame_with_parent_(self, request):
     parent_ = loose_mock(request, name='parent_')
     text_frame = TextFrame(None, parent_)
     return text_frame, parent_
Beispiel #18
0
 def wrap_set_fixture(self, request):
     txBody_cxml, new_value, expected_txBody_cxml = request.param
     text_frame = TextFrame(element(txBody_cxml), None)
     expected_xml = xml(expected_txBody_cxml)
     return text_frame, new_value, expected_xml
Beispiel #19
0
 def wrap_get_fixture(self, request):
     txBody_cxml, expected_value = request.param
     text_frame = TextFrame(element(txBody_cxml), None)
     return text_frame, expected_value
Beispiel #20
0
 def text_set_fixture(self, request):
     txBody_cxml, text, expected_cxml = request.param
     text_frame = TextFrame(element(txBody_cxml), None)
     expected_xml = xml(expected_cxml)
     return text_frame, text, expected_xml
Beispiel #21
0
 def add_paragraph_fixture(self, request):
     txBody_cxml, expected_cxml = request.param
     text_frame = TextFrame(element(txBody_cxml), None)
     expected_xml = xml(expected_cxml)
     return text_frame, expected_xml
Beispiel #22
0
 def set_font_fixture(self, request):
     txBody_cxml, bold, italic, expected_cxml = request.param
     family, size = 'F', 6
     text_frame = TextFrame(element(txBody_cxml), None)
     expected_xml = xml(expected_cxml)
     return text_frame, family, size, bold, italic, expected_xml
Beispiel #23
0
 def paragraphs_fixture(self, request):
     txBody_cxml = request.param
     txBody = element(txBody_cxml)
     text_frame = TextFrame(txBody, None)
     ps = txBody.xpath('.//a:p')
     return text_frame, ps
Beispiel #24
0
 def margin_get_fixture(self, request):
     txBody_cxml, side, unit, expected_value = request.param
     text_frame = TextFrame(element(txBody_cxml), None)
     prop_name = "margin_%s" % side
     return text_frame, prop_name, unit, expected_value
Beispiel #25
0
 def apply_fit_fixture(self, _set_font_):
     txBody = element('p:txBody/a:bodyPr')
     text_frame = TextFrame(txBody, None)
     family, font_size, bold, italic = 'Family', 42, True, False
     return text_frame, family, font_size, bold, italic
Beispiel #26
0
 def it_raises_on_attempt_to_set_margin_to_non_int(self):
     text_frame = TextFrame(element("p:txBody/a:bodyPr"), None)
     with pytest.raises(TypeError):
         text_frame.margin_bottom = "0.1"
Beispiel #27
0
 def margin_set_fixture(self, request):
     txBody_cxml, side, new_value, expected_txBody_cxml = request.param
     text_frame = TextFrame(element(txBody_cxml), None)
     prop_name = "margin_%s" % side
     expected_xml = xml(expected_txBody_cxml)
     return text_frame, prop_name, new_value, expected_xml
 def apply_styles(self, text_frame: TextFrame):
     if self._word_wrap is not None:
         text_frame.word_wrap = self._word_wrap