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.setWidth(sizes[0])
|
||||||
size.setHeight(sizes[1])
|
size.setHeight(sizes[1])
|
||||||
if width or height:
|
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'
|
logger.info('Rasterizing %r to %dx%d'
|
||||||
% (elem, size.width(), size.height()))
|
% (elem, size.width(), size.height()))
|
||||||
image = QImage(size, QImage.Format.Format_ARGB32_Premultiplied)
|
image = QImage(size, QImage.Format.Format_ARGB32_Premultiplied)
|
||||||
@ -183,7 +183,7 @@ class SVGRasterizer:
|
|||||||
data = QByteArray(svgitem.bytes_representation)
|
data = QByteArray(svgitem.bytes_representation)
|
||||||
svg = QSvgRenderer(data)
|
svg = QSvgRenderer(data)
|
||||||
size = svg.defaultSize()
|
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())
|
key = (svgitem.href, size.width(), size.height())
|
||||||
if key in self.images:
|
if key in self.images:
|
||||||
href = self.images[key]
|
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:
|
with lopen(ipath, 'rb') as f:
|
||||||
img = image_from_data(f.read())
|
img = image_from_data(f.read())
|
||||||
scaled, nwidth, nheight = fit_image(img.width(), img.height(), size, size)
|
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
|
dx = (size - nwidth) // 2
|
||||||
canvas.compose(img, x + dx, y)
|
canvas.compose(img, x + dx, y)
|
||||||
return canvas.export()
|
return canvas.export()
|
||||||
|
@ -932,7 +932,7 @@ class GridView(QListView):
|
|||||||
if scaled:
|
if scaled:
|
||||||
if self.ignore_render_requests.is_set():
|
if self.ignore_render_requests.is_set():
|
||||||
return
|
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)
|
p.setDevicePixelRatio(dpr)
|
||||||
cdata = p
|
cdata = p
|
||||||
# update cache
|
# update cache
|
||||||
|
@ -142,7 +142,7 @@ class ColumnIcon: # {{{
|
|||||||
if (os.path.exists(d)):
|
if (os.path.exists(d)):
|
||||||
bm = QPixmap(d)
|
bm = QPixmap(d)
|
||||||
scaled, nw, nh = fit_image(bm.width(), bm.height(), bm.width(), dim)
|
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)
|
bm.setDevicePixelRatio(self.dpr)
|
||||||
icon_bitmaps.append(bm)
|
icon_bitmaps.append(bm)
|
||||||
total_width += bm.width()
|
total_width += bm.width()
|
||||||
|
@ -153,7 +153,7 @@ class _Canvas(QGraphicsRectItem):
|
|||||||
max_width = min(br.width(), self.max_x-x)
|
max_width = min(br.width(), self.max_x-x)
|
||||||
if br.height() > max_height or br.width() > max_width:
|
if br.height() > max_height or br.width() > max_width:
|
||||||
p = ib.pixmap()
|
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))
|
Qt.TransformationMode.SmoothTransformation))
|
||||||
br = ib.boundingRect()
|
br = ib.boundingRect()
|
||||||
ib.setParentItem(self)
|
ib.setParentItem(self)
|
||||||
|
@ -25,7 +25,7 @@ class PixmapItem(QGraphicsPixmapItem):
|
|||||||
w, h = p.width(), p.height()
|
w, h = p.width(), p.height()
|
||||||
p = p.copy(x0, y0, min(w, x1-x0), min(h, y1-y0))
|
p = p.copy(x0, y0, min(w, x1-x0), min(h, y1-y0))
|
||||||
if p.width() != xsize or p.height() != ysize:
|
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)
|
QGraphicsPixmapItem.__init__(self, p)
|
||||||
self.height, self.width = ysize, xsize
|
self.height, self.width = ysize, xsize
|
||||||
self.setTransformationMode(Qt.TransformationMode.SmoothTransformation)
|
self.setTransformationMode(Qt.TransformationMode.SmoothTransformation)
|
||||||
@ -33,7 +33,7 @@ class PixmapItem(QGraphicsPixmapItem):
|
|||||||
|
|
||||||
def resize(self, width, height):
|
def resize(self, width, height):
|
||||||
p = self.pixmap()
|
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
|
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):
|
def render_img(image, dest, width=128, height=128):
|
||||||
from qt.core import QImage, Qt
|
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)
|
img.save(dest)
|
||||||
|
|
||||||
|
|
||||||
|
@ -257,7 +257,7 @@ def save_cover_data_to(
|
|||||||
changed = fmt != orig_fmt
|
changed = fmt != orig_fmt
|
||||||
if resize_to is not None:
|
if resize_to is not None:
|
||||||
changed = True
|
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()
|
owidth, oheight = img.width(), img.height()
|
||||||
nwidth, nheight = tweaks['maximum_cover_size'] if minify_to is None else minify_to
|
nwidth, nheight = tweaks['maximum_cover_size'] if minify_to is None else minify_to
|
||||||
if letterbox:
|
if letterbox:
|
||||||
@ -269,7 +269,7 @@ def save_cover_data_to(
|
|||||||
scaled, nwidth, nheight = fit_image(owidth, oheight, nwidth, nheight)
|
scaled, nwidth, nheight = fit_image(owidth, oheight, nwidth, nheight)
|
||||||
if scaled:
|
if scaled:
|
||||||
changed = True
|
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():
|
if img.hasAlphaChannel():
|
||||||
changed = True
|
changed = True
|
||||||
img = blend_image(img, bgcolor)
|
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:
|
if preserve_aspect_ratio:
|
||||||
scaled, nwidth, nheight = fit_image(img.width(), img.height(), width, height)
|
scaled, nwidth, nheight = fit_image(img.width(), img.height(), width, height)
|
||||||
if scaled:
|
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:
|
else:
|
||||||
if img.width() != width or img.height() != height:
|
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'
|
fmt = 'PNG' if as_png else 'JPEG'
|
||||||
w, h = img.width(), img.height()
|
w, h = img.width(), img.height()
|
||||||
return w, h, image_to_data(img, compression_quality=compression_quality, fmt=fmt)
|
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:
|
||||||
if area(pmap) == q:
|
if area(pmap) == q:
|
||||||
return pmap
|
return pmap
|
||||||
return pmap.scaled(size, size, aspectRatioMode=Qt.AspectRatioMode.KeepAspectRatio, transformMode=Qt.TransformationMode.SmoothTransformation)
|
return pmap.scaled(
|
||||||
return pixmaps[-1].scaled(size, size, aspectRatioMode=Qt.AspectRatioMode.KeepAspectRatio, transformMode=Qt.TransformationMode.SmoothTransformation)
|
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):
|
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)
|
pmap = hicon_to_pixmap(hicon)
|
||||||
if not pmap.isNull():
|
if not pmap.isNull():
|
||||||
if pmap.width() != size:
|
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
|
return pixmap_to_data(pmap) if as_data else pmap
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user