diff --git a/src/calibre/gui2/__init__.py b/src/calibre/gui2/__init__.py index 7e50803f48..a1dbfe5398 100644 --- a/src/calibre/gui2/__init__.py +++ b/src/calibre/gui2/__init__.py @@ -1466,7 +1466,7 @@ def elided_text(text, font=None, width=300, pos='middle'): return x[:max(0, mid - (delta//2))] + ellipsis + x[mid + (delta//2):] chomp = {'middle':remove_middle, 'left':lambda x:(ellipsis + x[delta:]), 'right':lambda x:(x[:-delta] + ellipsis)}[pos] - while len(text) > delta and fm.width(text) > width: + while len(text) > delta and fm.horizontalAdvance(text) > width: text = chomp(text) return str(text) diff --git a/src/calibre/gui2/lrf_renderer/text.py b/src/calibre/gui2/lrf_renderer/text.py index 4d857920e7..fa6356f3ea 100644 --- a/src/calibre/gui2/lrf_renderer/text.py +++ b/src/calibre/gui2/lrf_renderer/text.py @@ -399,7 +399,7 @@ class Line(QGraphicsItem): if self.valign is not None: font.setPixelSize(font.pixelSize()/1.5) fm = QFontMetrics(font) - single_space_width = fm.width(' ') + single_space_width = fm.horizontalAdvance(' ') height, descent = fm.height(), fm.descent() for match in matches: processed = True @@ -408,7 +408,7 @@ class Line(QGraphicsItem): right = left space_width = single_space_width * (right-left) word = phrase[phrase_pos:left] - width = fm.width(word) + width = fm.horizontalAdvance(word) if self.current_width + width < self.line_length: self.commit(word, width, height, descent, ts, font) if space_width > 0 and self.current_width + space_width < self.line_length: @@ -421,14 +421,14 @@ class Line(QGraphicsItem): tokens = hyphenate_word(word) for i in range(len(tokens)-2, -1, -1): word = ''.join(tokens[0:i+1])+'-' - width = fm.width(word) + width = fm.horizontalAdvance(word) if self.current_width + width < self.line_length: self.commit(word, width, height, descent, ts, font) return phrase_pos + len(word)-1, True if self.current_width < 5: # Force hyphenation as word is longer than line for i in range(len(word)-5, 0, -5): part = word[:i] + '-' - width = fm.width(part) + width = fm.horizontalAdvance(part) if self.current_width + width < self.line_length: self.commit(part, width, height, descent, ts, font) return phrase_pos + len(part)-1, True