mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-08-11 09:13:57 -04:00
Merge from trunk
This commit is contained in:
commit
25712ea2cd
Binary file not shown.
@ -99,7 +99,7 @@ class ANDROID(USBMS):
|
||||
0x681c : [0x0222, 0x0223, 0x0224, 0x0400],
|
||||
0x6640 : [0x0100],
|
||||
0x685b : [0x0400, 0x0226],
|
||||
0x685e : [0x0400],
|
||||
0x685e : [0x0400, 0x226],
|
||||
0x6860 : [0x0400],
|
||||
0x6863 : [0x226],
|
||||
0x6877 : [0x0400],
|
||||
|
@ -7,8 +7,6 @@
|
||||
###
|
||||
|
||||
log = window.calibre_utils.log
|
||||
viewport_to_document = window.calibre_utils.viewport_to_document
|
||||
absleft = window.calibre_utils.absleft
|
||||
|
||||
class PagedDisplay
|
||||
# This class is a namespace to expose functions via the
|
||||
@ -126,7 +124,25 @@ class PagedDisplay
|
||||
return sm
|
||||
|
||||
fit_images: () ->
|
||||
null
|
||||
# Ensure no images are wider than the available width in a column. Note
|
||||
# that this method use getBoundingClientRect() which means it will
|
||||
# force a relayout if the render tree is dirty.
|
||||
images = []
|
||||
for img in document.getElementsByTagName('img')
|
||||
previously_limited = calibre_utils.retrieve(img, 'width-limited', false)
|
||||
br = img.getBoundingClientRect()
|
||||
left = calibre_utils.viewport_to_document(br.left, 0, doc=img.ownerDocument)[0]
|
||||
col = this.column_at(left) * this.page_width
|
||||
rleft = left - col - this.current_margin_side
|
||||
width = br.right - br.left
|
||||
rright = rleft + width
|
||||
col_width = this.page_width - 2*this.current_margin_side
|
||||
if previously_limited or rright > col_width
|
||||
images.push([img, col_width - rleft])
|
||||
|
||||
for [img, max_width] in images
|
||||
img.style.setProperty('max-width', max_width+'px')
|
||||
calibre_utils.store(img, 'width-limited', true)
|
||||
|
||||
scroll_to_pos: (frac) ->
|
||||
# Scroll to the position represented by frac (number between 0 and 1)
|
||||
@ -263,7 +279,7 @@ class PagedDisplay
|
||||
elem.scrollIntoView()
|
||||
if this.in_paged_mode
|
||||
# Ensure we are scrolled to the column containing elem
|
||||
this.scroll_to_xpos(absleft(elem) + 5)
|
||||
this.scroll_to_xpos(calibre_utils.absleft(elem) + 5)
|
||||
|
||||
snap_to_selection: () ->
|
||||
# Ensure that the viewport is positioned at the start of the column
|
||||
@ -272,7 +288,7 @@ class PagedDisplay
|
||||
sel = window.getSelection()
|
||||
r = sel.getRangeAt(0).getBoundingClientRect()
|
||||
node = sel.anchorNode
|
||||
left = viewport_to_document(r.left, r.top, doc=node.ownerDocument)[0]
|
||||
left = calibre_utils.viewport_to_document(r.left, r.top, doc=node.ownerDocument)[0]
|
||||
|
||||
# Ensure we are scrolled to the column containing the start of the
|
||||
# selection
|
||||
@ -331,5 +347,5 @@ if window?
|
||||
window.paged_display = new PagedDisplay()
|
||||
|
||||
# TODO:
|
||||
# Resizing of images
|
||||
# Highlight on jump_to_anchor
|
||||
# Handle document specified margins and allow them to be overridden
|
||||
|
@ -117,7 +117,6 @@ class PDFMetadata(object):
|
||||
if len(oeb_metadata.creator) >= 1:
|
||||
self.author = authors_to_string([x.value for x in oeb_metadata.creator])
|
||||
|
||||
|
||||
class PDFWriter(QObject): # {{{
|
||||
|
||||
def __init__(self, opts, log, cover_data=None):
|
||||
@ -185,8 +184,8 @@ class PDFWriter(QObject): # {{{
|
||||
from PyQt4.Qt import QSize, QPainter
|
||||
if self.paged_js is None:
|
||||
from calibre.utils.resources import compiled_coffeescript
|
||||
self.paged_js = compiled_coffeescript('ebooks.oeb.display.paged',
|
||||
dynamic=False)
|
||||
self.paged_js = compiled_coffeescript('ebooks.oeb.display.utils')
|
||||
self.paged_js += compiled_coffeescript('ebooks.oeb.display.paged')
|
||||
printer = get_pdf_printer(self.opts, output_file_name=outpath)
|
||||
painter = QPainter(printer)
|
||||
zoomx = printer.logicalDpiX()/self.view.logicalDpiX()
|
||||
@ -202,6 +201,7 @@ class PDFWriter(QObject): # {{{
|
||||
document.body.style.backgroundColor = "white";
|
||||
paged_display.set_geometry(1, 0, 0, 0);
|
||||
paged_display.layout();
|
||||
paged_display.fit_images();
|
||||
''')
|
||||
mf = self.view.page().mainFrame()
|
||||
while True:
|
||||
|
@ -736,6 +736,9 @@ class Application(QApplication):
|
||||
|
||||
def __init__(self, args, force_calibre_style=False):
|
||||
self.file_event_hook = None
|
||||
if islinux and args[0].endswith(u'calibre'):
|
||||
args = list(args)
|
||||
args[0] += '-gui'
|
||||
qargs = [i.encode('utf-8') if isinstance(i, unicode) else i for i in args]
|
||||
QApplication.__init__(self, qargs)
|
||||
global gui_thread, qt_app
|
||||
|
@ -26,8 +26,8 @@ class Printing(QObject):
|
||||
for x in (Qt.Horizontal, Qt.Vertical):
|
||||
mf.setScrollBarPolicy(x, Qt.ScrollBarAlwaysOff)
|
||||
self.view.loadFinished.connect(self.load_finished)
|
||||
self.paged_js = compiled_coffeescript('ebooks.oeb.display.paged',
|
||||
dynamic=False)
|
||||
self.paged_js = compiled_coffeescript('ebooks.oeb.display.utils')
|
||||
self.paged_js += compiled_coffeescript('ebooks.oeb.display.paged')
|
||||
|
||||
def load_finished(self, ok):
|
||||
self.loaded_ok = ok
|
||||
@ -70,6 +70,7 @@ class Printing(QObject):
|
||||
document.body.style.backgroundColor = "white";
|
||||
paged_display.set_geometry(1, 0, 0, 0);
|
||||
paged_display.layout();
|
||||
paged_display.fit_images();
|
||||
''')
|
||||
|
||||
while True:
|
||||
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -241,7 +241,7 @@ icu_Collator_contractions(icu_Collator *self, PyObject *args, PyObject *kwargs)
|
||||
if (self->contractions == NULL) {
|
||||
self->contractions = uset_open(1, 0);
|
||||
if (self->contractions == NULL) return PyErr_NoMemory();
|
||||
ucol_getContractionsAndExpansions(self->collator, self->contractions, NULL, 0, &status);
|
||||
self->contractions = ucol_getTailoredSet(self->collator, &status);
|
||||
}
|
||||
status = U_ZERO_ERROR;
|
||||
|
||||
@ -273,6 +273,8 @@ icu_Collator_contractions(icu_Collator *self, PyObject *args, PyObject *kwargs)
|
||||
} // }}}
|
||||
|
||||
// Collator.span_contractions {{{
|
||||
#ifndef __APPLE__
|
||||
// uset_span is not available in the version of ICU on Apple's idiotic OS
|
||||
static PyObject *
|
||||
icu_Collator_span_contractions(icu_Collator *self, PyObject *args, PyObject *kwargs) {
|
||||
int span_type;
|
||||
@ -288,7 +290,7 @@ icu_Collator_span_contractions(icu_Collator *self, PyObject *args, PyObject *kwa
|
||||
if (self->contractions == NULL) {
|
||||
self->contractions = uset_open(1, 0);
|
||||
if (self->contractions == NULL) return PyErr_NoMemory();
|
||||
ucol_getContractionsAndExpansions(self->collator, self->contractions, NULL, 0, &status);
|
||||
self->contractions = ucol_getTailoredSet(self->collator, &status);
|
||||
}
|
||||
status = U_ZERO_ERROR;
|
||||
|
||||
@ -302,8 +304,9 @@ icu_Collator_span_contractions(icu_Collator *self, PyObject *args, PyObject *kwa
|
||||
ret = uset_span(self->contractions, s, slen, span_type);
|
||||
free(s); free(buf);
|
||||
return Py_BuildValue("i", ret);
|
||||
} // }}}
|
||||
|
||||
}
|
||||
#endif
|
||||
// }}}
|
||||
|
||||
static PyObject*
|
||||
icu_Collator_clone(icu_Collator *self, PyObject *args, PyObject *kwargs);
|
||||
@ -325,9 +328,11 @@ static PyMethodDef icu_Collator_methods[] = {
|
||||
"contractions() -> returns the contractions defined for this collator."
|
||||
},
|
||||
|
||||
#ifndef __APPLE__
|
||||
{"span_contractions", (PyCFunction)icu_Collator_span_contractions, METH_VARARGS,
|
||||
"span_contractions(src, span_condition) -> returns the length of the initial substring according to span_condition in the set of contractions for this collator. Returns 0 if src does not fit the span_condition. The span_condition can be one of USET_SPAN_NOT_CONTAINED, USET_SPAN_CONTAINED, USET_SPAN_SIMPLE."
|
||||
},
|
||||
#endif
|
||||
|
||||
{"clone", (PyCFunction)icu_Collator_clone, METH_VARARGS,
|
||||
"clone() -> returns a clone of this collator."
|
||||
@ -609,7 +614,10 @@ initicu(void)
|
||||
UErrorCode status = U_ZERO_ERROR;
|
||||
|
||||
u_init(&status);
|
||||
|
||||
if (U_FAILURE(status)) {
|
||||
PyErr_SetString(PyExc_RuntimeError, u_errorName(status));
|
||||
return;
|
||||
}
|
||||
|
||||
if (PyType_Ready(&icu_CollatorType) < 0)
|
||||
return;
|
||||
|
@ -33,7 +33,7 @@ def load_icu():
|
||||
if _icu is None:
|
||||
_icu = plugins['icu'][0]
|
||||
if _icu is None:
|
||||
print plugins['icu'][1]
|
||||
print 'Loading ICU failed with: ', plugins['icu'][1]
|
||||
else:
|
||||
if not getattr(_icu, 'ok', False):
|
||||
print 'icu not ok'
|
||||
@ -184,6 +184,7 @@ def primary_find(pat, src):
|
||||
################################################################################
|
||||
|
||||
def test(): # {{{
|
||||
from calibre import prints
|
||||
# Data {{{
|
||||
german = '''
|
||||
Sonntag
|
||||
@ -277,8 +278,6 @@ pêché'''
|
||||
german = create(german)
|
||||
c = _icu.Collator('de')
|
||||
gs = list(sorted(german, key=c.sort_key))
|
||||
for x in gs:
|
||||
print '\t', x.encode('utf-8')
|
||||
if gs != create(german_good):
|
||||
print 'German sorting failed'
|
||||
return
|
||||
@ -286,8 +285,6 @@ pêché'''
|
||||
french = create(french)
|
||||
c = _icu.Collator('fr')
|
||||
fs = list(sorted(french, key=c.sort_key))
|
||||
for x in fs:
|
||||
print '\t', x.encode('utf-8')
|
||||
if fs != create(french_good):
|
||||
print 'French sorting failed (note that French fails with icu < 4.6)'
|
||||
return
|
||||
@ -306,10 +303,10 @@ pêché'''
|
||||
for k, v in {u'pèché': u'peche', u'flüße':u'flusse',
|
||||
u'Štepánek':u'Štepanek'}.iteritems():
|
||||
if primary_strcmp(k, v) != 0:
|
||||
print 'primary_strcmp() failed with %s != %s'%(k, v)
|
||||
prints('primary_strcmp() failed with %s != %s'%(k, v))
|
||||
return
|
||||
if primary_find(v, u' '+k)[0] != 1:
|
||||
print 'primary_find() failed with %s not in %s'%(v, k)
|
||||
prints('primary_find() failed with %s not in %s'%(v, k))
|
||||
return
|
||||
|
||||
global _primary_collator
|
||||
@ -318,6 +315,14 @@ pêché'''
|
||||
print 'Primary collation in Spanish locale failed'
|
||||
return
|
||||
|
||||
print '\nTesting contractions'
|
||||
c = _icu.Collator('cs')
|
||||
if icu_contractions(c) != frozenset([u'Z\u030c', u'z\u030c', u'Ch',
|
||||
u'C\u030c', u'ch', u'cH', u'c\u030c', u's\u030c', u'r\u030c', u'CH',
|
||||
u'S\u030c', u'R\u030c']):
|
||||
print 'Contractions for the Czech language failed'
|
||||
return
|
||||
|
||||
# }}}
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
Loading…
x
Reference in New Issue
Block a user