def it_wraps_lines_to_help_best_fit(self, request): line_source, remainder = _LineSource("foo bar"), _LineSource("bar") _break_line_ = method_mock( request, TextFitter, "_break_line", side_effect=[("foo", remainder), ("bar", _LineSource(""))], ) text_fitter = TextFitter(None, (None, None), None) text_fitter._wrap_lines(line_source, 21) assert _break_line_.call_args_list == [ call(text_fitter, line_source, 21), call(text_fitter, remainder, 21), ]
def wrap_fixture(self, _break_line_): text_fitter = TextFitter(None, (None, None), None) point_size = 21 line_source, remainder = _LineSource("foo bar"), _LineSource("bar") _break_line_.side_effect = [("foo", remainder), ("bar", _LineSource(""))] return text_fitter, line_source, point_size, remainder
def it_provides_a_fits_inside_predicate_fn( self, request, line_source_, _rendered_size_, extents, point_size, text_lines, expected_value, ): _wrap_lines_ = method_mock(request, TextFitter, "_wrap_lines", return_value=text_lines) _rendered_size_.return_value = (None, 50) text_fitter = TextFitter(line_source_, extents, "foobar.ttf") predicate = text_fitter._fits_inside_predicate result = predicate(point_size) _wrap_lines_.assert_called_once_with(text_fitter, line_source_, point_size) _rendered_size_.assert_called_once_with("Ty", point_size, text_fitter._font_file) assert result is expected_value
def fits_pred_fixture(self, request, line_source_, _wrap_lines_, _rendered_size_): extents, point_size, text_lines, expected_value = request.param text_fitter = TextFitter(line_source_, extents, "foobar.ttf") _wrap_lines_.return_value = text_lines _rendered_size_.return_value = (None, 50) return text_fitter, point_size, _rendered_size_, expected_value
def _best_fit_fixture(self, _BinarySearchTree_, _fits_inside_predicate_): text_fitter = TextFitter(None, (None, None), None) max_size = 42 sizes_ = _BinarySearchTree_.from_ordered_sequence.return_value predicate_ = _fits_inside_predicate_.return_value font_size_ = sizes_.find_max.return_value return (text_fitter, max_size, _BinarySearchTree_, sizes_, predicate_, font_size_)
def it_breaks_off_a_line_to_help_wrap(self, request, line_source_, _BinarySearchTree_): bst_ = instance_mock(request, _BinarySearchTree) _fits_in_width_predicate_ = method_mock(request, TextFitter, "_fits_in_width_predicate") _BinarySearchTree_.from_ordered_sequence.return_value = bst_ predicate_ = _fits_in_width_predicate_.return_value max_value_ = bst_.find_max.return_value text_fitter = TextFitter(None, (None, None), None) value = text_fitter._break_line(line_source_, 21) _BinarySearchTree_.from_ordered_sequence.assert_called_once_with( line_source_) text_fitter._fits_in_width_predicate.assert_called_once_with( text_fitter, 21) bst_.find_max.assert_called_once_with(predicate_) assert value is max_value_
def wrap_fixture(self, _break_line_): text_fitter = TextFitter(None, (None, None), None) point_size = 21 line_source, remainder = _LineSource('foo bar'), _LineSource('bar') _break_line_.side_effect = [ ('foo', remainder), ('bar', _LineSource('')), ] return text_fitter, line_source, point_size, remainder
def break_fixture(self, line_source_, _BinarySearchTree_, bst_, _fits_in_width_predicate_): text_fitter = TextFitter(None, (None, None), None) point_size = 21 _BinarySearchTree_.from_ordered_sequence.return_value = bst_ predicate_ = _fits_in_width_predicate_.return_value max_value_ = bst_.find_max.return_value return (text_fitter, line_source_, point_size, _BinarySearchTree_, bst_, predicate_, max_value_)
def _best_fit_font_size(self, family, max_size, bold, italic, font_file): """ Return the largest integer point size not greater than *max_size* that allows all the text in this text frame to fit inside its extents when rendered using the font described by *family*, *bold*, and *italic*. If *font_file* is specified, it is used to calculate the fit, whether or not it matches *family*, *bold*, and *italic*. """ if font_file is None: font_file = FontFiles.find(family, bold, italic) return TextFitter.best_fit_font_size(self.text, self._extents, max_size, font_file)
def it_can_determine_the_best_fit_font_size(self, best_fit_fixture): text, extents, max_size, font_file = best_fit_fixture[:4] _LineSource_, _init_, line_source_ = best_fit_fixture[4:7] _best_fit_font_size_, font_size_ = best_fit_fixture[7:] font_size = TextFitter.best_fit_font_size(text, extents, max_size, font_file) _LineSource_.assert_called_once_with(text) _init_.assert_called_once_with(line_source_, extents, font_file) _best_fit_font_size_.assert_called_once_with(max_size) assert font_size is font_size_
def _best_fit_font_size(self, family, max_size, bold, italic, font_file): """ Return the largest integer point size not greater than *max_size* that allows all the text in this text frame to fit inside its extents when rendered using the font described by *family*, *bold*, and *italic*. If *font_file* is specified, it is used to calculate the fit, whether or not it matches *family*, *bold*, and *italic*. """ if font_file is None: font_file = FontFiles.find(family, bold, italic) return TextFitter.best_fit_font_size( self.text, self._extents, max_size, font_file )
def it_can_determine_the_best_fit_font_size(self, request, line_source_): _LineSource_ = class_mock(request, "pptx.text.layout._LineSource", return_value=line_source_) _init_ = initializer_mock(request, TextFitter) _best_fit_font_size_ = method_mock(request, TextFitter, "_best_fit_font_size", return_value=36) extents, max_size = (19, 20), 42 font_size = TextFitter.best_fit_font_size("Foobar", extents, max_size, "foobar.ttf") _LineSource_.assert_called_once_with("Foobar") _init_.assert_called_once_with(line_source_, extents, "foobar.ttf") _best_fit_font_size_.assert_called_once_with(ANY, max_size) assert font_size == 36
def fits_cx_pred_fixture(self, request, _rendered_size_): rendered_width, expected_value = request.param text_fitter = TextFitter(None, (50, None), "foobar.ttf") point_size, line = 12, _Line("foobar", None) _rendered_size_.return_value = (rendered_width, None) return (text_fitter, point_size, line, _rendered_size_, expected_value)