mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Edit Book: When inserting full screen images, use the actual image dimensions in the generated SVG code, when available
This commit is contained in:
parent
34f28d22dd
commit
0250666dd9
@ -48,6 +48,7 @@ from calibre.gui2.tweak_book.widgets import (
|
|||||||
InsertSemantics, BusyCursor, InsertTag, FilterCSS, AddCover)
|
InsertSemantics, BusyCursor, InsertTag, FilterCSS, AddCover)
|
||||||
from calibre.utils.config import JSONConfig
|
from calibre.utils.config import JSONConfig
|
||||||
from calibre.utils.icu import numeric_sort_key
|
from calibre.utils.icu import numeric_sort_key
|
||||||
|
from calibre.utils.imghdr import identify
|
||||||
|
|
||||||
_diff_dialogs = []
|
_diff_dialogs = []
|
||||||
last_used_transform_rules = []
|
last_used_transform_rules = []
|
||||||
@ -861,7 +862,8 @@ class Boss(QObject):
|
|||||||
self.refresh_file_list()
|
self.refresh_file_list()
|
||||||
chosen_name = chosen_image_is_external[0]
|
chosen_name = chosen_image_is_external[0]
|
||||||
href = current_container().name_to_href(chosen_name, edname)
|
href = current_container().name_to_href(chosen_name, edname)
|
||||||
ed.insert_image(href, fullpage=fullpage, preserve_aspect_ratio=preserve_ar)
|
fmt, width, height = identify(current_container().raw_data(chosen_name, decode=False))
|
||||||
|
ed.insert_image(href, fullpage=fullpage, preserve_aspect_ratio=preserve_ar, width=width, height=height)
|
||||||
elif action[0] == 'insert_hyperlink':
|
elif action[0] == 'insert_hyperlink':
|
||||||
self.commit_all_editors_to_container()
|
self.commit_all_editors_to_container()
|
||||||
d = InsertLink(current_container(), edname, initial_text=ed.get_smart_selection(), parent=self.gui)
|
d = InsertLink(current_container(), edname, initial_text=ed.get_smart_selection(), parent=self.gui)
|
||||||
|
@ -836,7 +836,11 @@ class TextEdit(PlainTextEdit):
|
|||||||
c.setPosition(c.position() - len(suffix))
|
c.setPosition(c.position() - len(suffix))
|
||||||
self.setTextCursor(c)
|
self.setTextCursor(c)
|
||||||
|
|
||||||
def insert_image(self, href, fullpage=False, preserve_aspect_ratio=False):
|
def insert_image(self, href, fullpage=False, preserve_aspect_ratio=False, width=-1, height=-1):
|
||||||
|
if width <= 0:
|
||||||
|
width = 1200
|
||||||
|
if height <= 0:
|
||||||
|
height = 1600
|
||||||
c = self.textCursor()
|
c = self.textCursor()
|
||||||
template, alt = 'url(%s)', ''
|
template, alt = 'url(%s)', ''
|
||||||
left = min(c.position(), c.anchor)
|
left = min(c.position(), c.anchor)
|
||||||
@ -849,9 +853,9 @@ class TextEdit(PlainTextEdit):
|
|||||||
template = '''\
|
template = '''\
|
||||||
<div style="page-break-before:always; page-break-after:always; page-break-inside:avoid">\
|
<div style="page-break-before:always; page-break-after:always; page-break-inside:avoid">\
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" \
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" \
|
||||||
version="1.1" width="100%%" height="100%%" viewBox="0 0 1200 1600" preserveAspectRatio="{}">\
|
version="1.1" width="100%%" height="100%%" viewBox="0 0 {w} {h}" preserveAspectRatio="{a}">\
|
||||||
<image width="1200" height="1600" xlink:href="%s"/>\
|
<image width="{w}" height="{h}" xlink:href="%s"/>\
|
||||||
</svg></div>'''.format('xMidYMid meet' if preserve_aspect_ratio else 'none')
|
</svg></div>'''.format(w=width, h=height, a='xMidYMid meet' if preserve_aspect_ratio else 'none')
|
||||||
else:
|
else:
|
||||||
alt = _('Image')
|
alt = _('Image')
|
||||||
template = '<img alt="{0}" src="%s" />'.format(alt)
|
template = '<img alt="{0}" src="%s" />'.format(alt)
|
||||||
|
@ -228,8 +228,8 @@ class Editor(QMainWindow):
|
|||||||
func = getattr(self.editor, action)
|
func = getattr(self.editor, action)
|
||||||
func(*args)
|
func(*args)
|
||||||
|
|
||||||
def insert_image(self, href, fullpage=False, preserve_aspect_ratio=False):
|
def insert_image(self, href, fullpage=False, preserve_aspect_ratio=False, width=-1, height=-1):
|
||||||
self.editor.insert_image(href, fullpage=fullpage, preserve_aspect_ratio=preserve_aspect_ratio)
|
self.editor.insert_image(href, fullpage=fullpage, preserve_aspect_ratio=preserve_aspect_ratio, width=width, height=height)
|
||||||
|
|
||||||
def insert_hyperlink(self, href, text):
|
def insert_hyperlink(self, href, text):
|
||||||
self.editor.insert_hyperlink(href, text)
|
self.editor.insert_hyperlink(href, text)
|
||||||
@ -619,4 +619,3 @@ def launch_editor(path_to_edit, path_is_raw=False, syntax='html', callback=None)
|
|||||||
callback(t)
|
callback(t)
|
||||||
t.show()
|
t.show()
|
||||||
app.exec_()
|
app.exec_()
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user