mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
py310: More float->int goodness
Fixes #1955311 [Error converting ePUB to MOBI during Rasterizing SVG images](https://bugs.launchpad.net/calibre/+bug/1955311)
This commit is contained in:
parent
dafa08e921
commit
b50a2449fe
@ -87,7 +87,7 @@ class SVGRasterizer:
|
||||
size.setWidth(sizes[0])
|
||||
size.setHeight(sizes[1])
|
||||
if width or height:
|
||||
size.scale(width, height, Qt.AspectRatioMode.KeepAspectRatio)
|
||||
size.scale(int(width), int(height), Qt.AspectRatioMode.KeepAspectRatio)
|
||||
logger.info('Rasterizing %r to %dx%d'
|
||||
% (elem, size.width(), size.height()))
|
||||
image = QImage(size, QImage.Format.Format_ARGB32_Premultiplied)
|
||||
@ -183,7 +183,7 @@ class SVGRasterizer:
|
||||
data = QByteArray(svgitem.bytes_representation)
|
||||
svg = QSvgRenderer(data)
|
||||
size = svg.defaultSize()
|
||||
size.scale(width, height, Qt.AspectRatioMode.KeepAspectRatio)
|
||||
size.scale(int(width), int(height), Qt.AspectRatioMode.KeepAspectRatio)
|
||||
key = (svgitem.href, size.width(), size.height())
|
||||
if key in self.images:
|
||||
href = self.images[key]
|
||||
|
@ -187,7 +187,7 @@ def create_cover(report, icons=(), cols=5, size=120, padding=16):
|
||||
with lopen(ipath, 'rb') as f:
|
||||
img = image_from_data(f.read())
|
||||
scaled, nwidth, nheight = fit_image(img.width(), img.height(), size, size)
|
||||
img = img.scaled(nwidth, nheight, Qt.AspectRatioMode.IgnoreAspectRatio, Qt.TransformationMode.SmoothTransformation)
|
||||
img = img.scaled(int(nwidth), int(nheight), Qt.AspectRatioMode.IgnoreAspectRatio, Qt.TransformationMode.SmoothTransformation)
|
||||
dx = (size - nwidth) // 2
|
||||
canvas.compose(img, x + dx, y)
|
||||
return canvas.export()
|
||||
|
@ -932,7 +932,7 @@ class GridView(QListView):
|
||||
if scaled:
|
||||
if self.ignore_render_requests.is_set():
|
||||
return
|
||||
p = p.scaled(nwidth, nheight, Qt.AspectRatioMode.IgnoreAspectRatio, Qt.TransformationMode.SmoothTransformation)
|
||||
p = p.scaled(int(nwidth), int(nheight), Qt.AspectRatioMode.IgnoreAspectRatio, Qt.TransformationMode.SmoothTransformation)
|
||||
p.setDevicePixelRatio(dpr)
|
||||
cdata = p
|
||||
# update cache
|
||||
|
@ -142,7 +142,7 @@ class ColumnIcon: # {{{
|
||||
if (os.path.exists(d)):
|
||||
bm = QPixmap(d)
|
||||
scaled, nw, nh = fit_image(bm.width(), bm.height(), bm.width(), dim)
|
||||
bm = bm.scaled(nw, nh, aspectRatioMode=Qt.AspectRatioMode.IgnoreAspectRatio, transformMode=Qt.TransformationMode.SmoothTransformation)
|
||||
bm = bm.scaled(int(nw), int(nh), aspectRatioMode=Qt.AspectRatioMode.IgnoreAspectRatio, transformMode=Qt.TransformationMode.SmoothTransformation)
|
||||
bm.setDevicePixelRatio(self.dpr)
|
||||
icon_bitmaps.append(bm)
|
||||
total_width += bm.width()
|
||||
|
@ -153,7 +153,7 @@ class _Canvas(QGraphicsRectItem):
|
||||
max_width = min(br.width(), self.max_x-x)
|
||||
if br.height() > max_height or br.width() > max_width:
|
||||
p = ib.pixmap()
|
||||
ib.setPixmap(p.scaled(max_width, max_height, Qt.AspectRatioMode.IgnoreAspectRatio,
|
||||
ib.setPixmap(p.scaled(int(max_width), int(max_height), Qt.AspectRatioMode.IgnoreAspectRatio,
|
||||
Qt.TransformationMode.SmoothTransformation))
|
||||
br = ib.boundingRect()
|
||||
ib.setParentItem(self)
|
||||
|
@ -25,7 +25,7 @@ class PixmapItem(QGraphicsPixmapItem):
|
||||
w, h = p.width(), p.height()
|
||||
p = p.copy(x0, y0, min(w, x1-x0), min(h, y1-y0))
|
||||
if p.width() != xsize or p.height() != ysize:
|
||||
p = p.scaled(xsize, ysize, Qt.AspectRatioMode.IgnoreAspectRatio, Qt.TransformationMode.SmoothTransformation)
|
||||
p = p.scaled(int(xsize), int(ysize), Qt.AspectRatioMode.IgnoreAspectRatio, Qt.TransformationMode.SmoothTransformation)
|
||||
QGraphicsPixmapItem.__init__(self, p)
|
||||
self.height, self.width = ysize, xsize
|
||||
self.setTransformationMode(Qt.TransformationMode.SmoothTransformation)
|
||||
@ -33,7 +33,7 @@ class PixmapItem(QGraphicsPixmapItem):
|
||||
|
||||
def resize(self, width, height):
|
||||
p = self.pixmap()
|
||||
self.setPixmap(p.scaled(width, height, Qt.AspectRatioMode.IgnoreAspectRatio, Qt.TransformationMode.SmoothTransformation))
|
||||
self.setPixmap(p.scaled(int(width), int(height), Qt.AspectRatioMode.IgnoreAspectRatio, Qt.TransformationMode.SmoothTransformation))
|
||||
self.width, self.height = width, height
|
||||
|
||||
|
||||
|
@ -1300,7 +1300,7 @@ def write_appdata(key, entry, base, translators):
|
||||
|
||||
def render_img(image, dest, width=128, height=128):
|
||||
from qt.core import QImage, Qt
|
||||
img = QImage(I(image)).scaled(width, height, Qt.AspectRatioMode.IgnoreAspectRatio, Qt.TransformationMode.SmoothTransformation)
|
||||
img = QImage(I(image)).scaled(int(width), int(height), Qt.AspectRatioMode.IgnoreAspectRatio, Qt.TransformationMode.SmoothTransformation)
|
||||
img.save(dest)
|
||||
|
||||
|
||||
|
@ -257,7 +257,7 @@ def save_cover_data_to(
|
||||
changed = fmt != orig_fmt
|
||||
if resize_to is not None:
|
||||
changed = True
|
||||
img = img.scaled(resize_to[0], resize_to[1], Qt.AspectRatioMode.IgnoreAspectRatio, Qt.TransformationMode.SmoothTransformation)
|
||||
img = img.scaled(int(resize_to[0]), int(resize_to[1]), Qt.AspectRatioMode.IgnoreAspectRatio, Qt.TransformationMode.SmoothTransformation)
|
||||
owidth, oheight = img.width(), img.height()
|
||||
nwidth, nheight = tweaks['maximum_cover_size'] if minify_to is None else minify_to
|
||||
if letterbox:
|
||||
@ -269,7 +269,7 @@ def save_cover_data_to(
|
||||
scaled, nwidth, nheight = fit_image(owidth, oheight, nwidth, nheight)
|
||||
if scaled:
|
||||
changed = True
|
||||
img = img.scaled(nwidth, nheight, Qt.AspectRatioMode.IgnoreAspectRatio, Qt.TransformationMode.SmoothTransformation)
|
||||
img = img.scaled(int(nwidth), int(nheight), Qt.AspectRatioMode.IgnoreAspectRatio, Qt.TransformationMode.SmoothTransformation)
|
||||
if img.hasAlphaChannel():
|
||||
changed = True
|
||||
img = blend_image(img, bgcolor)
|
||||
@ -411,10 +411,10 @@ def scale_image(data, width=60, height=80, compression_quality=70, as_png=False,
|
||||
if preserve_aspect_ratio:
|
||||
scaled, nwidth, nheight = fit_image(img.width(), img.height(), width, height)
|
||||
if scaled:
|
||||
img = img.scaled(nwidth, nheight, Qt.AspectRatioMode.KeepAspectRatio, Qt.TransformationMode.SmoothTransformation)
|
||||
img = img.scaled(int(nwidth), int(nheight), Qt.AspectRatioMode.KeepAspectRatio, Qt.TransformationMode.SmoothTransformation)
|
||||
else:
|
||||
if img.width() != width or img.height() != height:
|
||||
img = img.scaled(width, height, Qt.AspectRatioMode.IgnoreAspectRatio, Qt.TransformationMode.SmoothTransformation)
|
||||
img = img.scaled(int(width), int(height), Qt.AspectRatioMode.IgnoreAspectRatio, Qt.TransformationMode.SmoothTransformation)
|
||||
fmt = 'PNG' if as_png else 'JPEG'
|
||||
w, h = img.width(), img.height()
|
||||
return w, h, image_to_data(img, compression_quality=compression_quality, fmt=fmt)
|
||||
|
@ -62,8 +62,10 @@ def load_icon_resource_as_pixmap(icon_resource, size=ICON_SIZE):
|
||||
if area(pmap) >= q:
|
||||
if area(pmap) == q:
|
||||
return pmap
|
||||
return pmap.scaled(size, size, aspectRatioMode=Qt.AspectRatioMode.KeepAspectRatio, transformMode=Qt.TransformationMode.SmoothTransformation)
|
||||
return pixmaps[-1].scaled(size, size, aspectRatioMode=Qt.AspectRatioMode.KeepAspectRatio, transformMode=Qt.TransformationMode.SmoothTransformation)
|
||||
return pmap.scaled(
|
||||
int(size), int(size), aspectRatioMode=Qt.AspectRatioMode.KeepAspectRatio, transformMode=Qt.TransformationMode.SmoothTransformation)
|
||||
return pixmaps[-1].scaled(
|
||||
int(size), int(size), aspectRatioMode=Qt.AspectRatioMode.KeepAspectRatio, transformMode=Qt.TransformationMode.SmoothTransformation)
|
||||
|
||||
|
||||
def load_icon_resource(icon_resource, as_data=False, size=ICON_SIZE):
|
||||
@ -83,7 +85,8 @@ def load_icon_for_file(path: str, as_data=False, size=ICON_SIZE):
|
||||
pmap = hicon_to_pixmap(hicon)
|
||||
if not pmap.isNull():
|
||||
if pmap.width() != size:
|
||||
pmap = pmap.scaled(size, size, aspectRatioMode=Qt.AspectRatioMode.KeepAspectRatio, transformMode=Qt.TransformationMode.SmoothTransformation)
|
||||
pmap = pmap.scaled(
|
||||
int(size), int(size), aspectRatioMode=Qt.AspectRatioMode.KeepAspectRatio, transformMode=Qt.TransformationMode.SmoothTransformation)
|
||||
return pixmap_to_data(pmap) if as_data else pmap
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user