mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
more pyqt6 busyword QFontMetrics::width -> horizontalAdvance
This commit is contained in:
parent
d63d8190bd
commit
d99b1bd628
@ -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):]
|
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]
|
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)
|
text = chomp(text)
|
||||||
return str(text)
|
return str(text)
|
||||||
|
|
||||||
|
@ -399,7 +399,7 @@ class Line(QGraphicsItem):
|
|||||||
if self.valign is not None:
|
if self.valign is not None:
|
||||||
font.setPixelSize(font.pixelSize()/1.5)
|
font.setPixelSize(font.pixelSize()/1.5)
|
||||||
fm = QFontMetrics(font)
|
fm = QFontMetrics(font)
|
||||||
single_space_width = fm.width(' ')
|
single_space_width = fm.horizontalAdvance(' ')
|
||||||
height, descent = fm.height(), fm.descent()
|
height, descent = fm.height(), fm.descent()
|
||||||
for match in matches:
|
for match in matches:
|
||||||
processed = True
|
processed = True
|
||||||
@ -408,7 +408,7 @@ class Line(QGraphicsItem):
|
|||||||
right = left
|
right = left
|
||||||
space_width = single_space_width * (right-left)
|
space_width = single_space_width * (right-left)
|
||||||
word = phrase[phrase_pos:left]
|
word = phrase[phrase_pos:left]
|
||||||
width = fm.width(word)
|
width = fm.horizontalAdvance(word)
|
||||||
if self.current_width + width < self.line_length:
|
if self.current_width + width < self.line_length:
|
||||||
self.commit(word, width, height, descent, ts, font)
|
self.commit(word, width, height, descent, ts, font)
|
||||||
if space_width > 0 and self.current_width + space_width < self.line_length:
|
if space_width > 0 and self.current_width + space_width < self.line_length:
|
||||||
@ -421,14 +421,14 @@ class Line(QGraphicsItem):
|
|||||||
tokens = hyphenate_word(word)
|
tokens = hyphenate_word(word)
|
||||||
for i in range(len(tokens)-2, -1, -1):
|
for i in range(len(tokens)-2, -1, -1):
|
||||||
word = ''.join(tokens[0:i+1])+'-'
|
word = ''.join(tokens[0:i+1])+'-'
|
||||||
width = fm.width(word)
|
width = fm.horizontalAdvance(word)
|
||||||
if self.current_width + width < self.line_length:
|
if self.current_width + width < self.line_length:
|
||||||
self.commit(word, width, height, descent, ts, font)
|
self.commit(word, width, height, descent, ts, font)
|
||||||
return phrase_pos + len(word)-1, True
|
return phrase_pos + len(word)-1, True
|
||||||
if self.current_width < 5: # Force hyphenation as word is longer than line
|
if self.current_width < 5: # Force hyphenation as word is longer than line
|
||||||
for i in range(len(word)-5, 0, -5):
|
for i in range(len(word)-5, 0, -5):
|
||||||
part = word[:i] + '-'
|
part = word[:i] + '-'
|
||||||
width = fm.width(part)
|
width = fm.horizontalAdvance(part)
|
||||||
if self.current_width + width < self.line_length:
|
if self.current_width + width < self.line_length:
|
||||||
self.commit(part, width, height, descent, ts, font)
|
self.commit(part, width, height, descent, ts, font)
|
||||||
return phrase_pos + len(part)-1, True
|
return phrase_pos + len(part)-1, True
|
||||||
|
Loading…
x
Reference in New Issue
Block a user