def minimum_tb_width(self, tb): ts = tb.textStyle.attrs default_font = get_font(ts['fontfacename'], self.pts_to_pixels(ts['fontsize'])) parindent = self.pts_to_pixels(ts['parindent']) mwidth = 0 for token, attrs in tokens(tb): font = default_font if isinstance(token, numbers.Integral): # Handle para and line breaks continue if isinstance(token, Plot): return self.pts_to_pixels(token.xsize) ff = attrs.get('fontfacename', ts['fontfacename']) fs = attrs.get('fontsize', ts['fontsize']) if (ff, fs) != (ts['fontfacename'], ts['fontsize']): font = get_font(ff, self.pts_to_pixels(fs)) if not token.strip(): continue word = token.split() word = word[0] if word else "" width = font.getsize(word)[0] if width > mwidth: mwidth = width return parindent + mwidth + 2
def text_block_size(self, tb, maxwidth=sys.maxint, debug=False): ts = tb.textStyle.attrs default_font = get_font(ts['fontfacename'], self.pts_to_pixels(ts['fontsize'])) parindent = self.pts_to_pixels(ts['parindent']) top, bottom, left, right = 0, 0, parindent, parindent def add_word(width, height, left, right, top, bottom, ls, ws): if left + width > maxwidth: left = width + ws top += ls bottom = top + ls if top + ls > bottom else bottom else: left += (width + ws) right = left if left > right else right bottom = top + ls if top + ls > bottom else bottom return left, right, top, bottom for token, attrs in tokens(tb): if attrs is None: attrs = {} font = default_font ls = self.pts_to_pixels(attrs.get('baselineskip', ts['baselineskip']))+\ self.pts_to_pixels(attrs.get('linespace', ts['linespace'])) ws = self.pts_to_pixels(attrs.get('wordspace', ts['wordspace'])) if isinstance(token, numbers.Integral): # Handle para and line breaks if top != bottom: # Previous element not a line break top = bottom else: top += ls bottom += ls left = parindent if int == 1 else 0 continue if isinstance(token, Plot): width, height = self.pts_to_pixels( token.xsize), self.pts_to_pixels(token.ysize) left, right, top, bottom = add_word(width, height, left, right, top, bottom, height, ws) continue ff = attrs.get('fontfacename', ts['fontfacename']) fs = attrs.get('fontsize', ts['fontsize']) if (ff, fs) != (ts['fontfacename'], ts['fontsize']): font = get_font(ff, self.pts_to_pixels(fs)) for word in token.split(): width, height = font.getsize(word) left, right, top, bottom = add_word(width, height, left, right, top, bottom, ls, ws) return right + 3 + max(parindent, 10), bottom
def text_block_size(self, tb, maxwidth=sys.maxint, debug=False): ts = tb.textStyle.attrs default_font = get_font(ts['fontfacename'], self.pts_to_pixels(ts['fontsize'])) parindent = self.pts_to_pixels(ts['parindent']) top, bottom, left, right = 0, 0, parindent, parindent def add_word(width, height, left, right, top, bottom, ls, ws): if left + width > maxwidth: left = width + ws top += ls bottom = top+ls if top+ls > bottom else bottom else: left += (width + ws) right = left if left > right else right bottom = top+ls if top+ls > bottom else bottom return left, right, top, bottom for token, attrs in tokens(tb): if attrs is None: attrs = {} font = default_font ls = self.pts_to_pixels(attrs.get('baselineskip', ts['baselineskip']))+\ self.pts_to_pixels(attrs.get('linespace', ts['linespace'])) ws = self.pts_to_pixels(attrs.get('wordspace', ts['wordspace'])) if isinstance(token, int): # Handle para and line breaks if top != bottom: # Previous element not a line break top = bottom else: top += ls bottom += ls left = parindent if int == 1 else 0 continue if isinstance(token, Plot): width, height = self.pts_to_pixels(token.xsize), self.pts_to_pixels(token.ysize) left, right, top, bottom = add_word(width, height, left, right, top, bottom, height, ws) continue ff = attrs.get('fontfacename', ts['fontfacename']) fs = attrs.get('fontsize', ts['fontsize']) if (ff, fs) != (ts['fontfacename'], ts['fontsize']): font = get_font(ff, self.pts_to_pixels(fs)) for word in token.split(): width, height = font.getsize(word) left, right, top, bottom = add_word(width, height, left, right, top, bottom, ls, ws) return right+3+max(parindent, 10), bottom
def minimum_tb_width(self, tb): ts = tb.textStyle.attrs default_font = get_font(ts['fontfacename'], self.pts_to_pixels(ts['fontsize'])) parindent = self.pts_to_pixels(ts['parindent']) mwidth = 0 for token, attrs in tokens(tb): font = default_font if isinstance(token, int): # Handle para and line breaks continue if isinstance(token, Plot): return self.pts_to_pixels(token.xsize) ff = attrs.get('fontfacename', ts['fontfacename']) fs = attrs.get('fontsize', ts['fontsize']) if (ff, fs) != (ts['fontfacename'], ts['fontsize']): font = get_font(ff, self.pts_to_pixels(fs)) if not token.strip(): continue word = token.split() word = word[0] if word else "" width = font.getsize(word)[0] if width > mwidth: mwidth = width return parindent + mwidth + 2