Merge from trunk

This commit is contained in:
Charles Haley 2012-07-05 17:45:30 +02:00
commit 25712ea2cd
84 changed files with 15358 additions and 13839 deletions

Binary file not shown.

View File

@ -99,7 +99,7 @@ class ANDROID(USBMS):
0x681c : [0x0222, 0x0223, 0x0224, 0x0400], 0x681c : [0x0222, 0x0223, 0x0224, 0x0400],
0x6640 : [0x0100], 0x6640 : [0x0100],
0x685b : [0x0400, 0x0226], 0x685b : [0x0400, 0x0226],
0x685e : [0x0400], 0x685e : [0x0400, 0x226],
0x6860 : [0x0400], 0x6860 : [0x0400],
0x6863 : [0x226], 0x6863 : [0x226],
0x6877 : [0x0400], 0x6877 : [0x0400],

View File

@ -7,8 +7,6 @@
### ###
log = window.calibre_utils.log log = window.calibre_utils.log
viewport_to_document = window.calibre_utils.viewport_to_document
absleft = window.calibre_utils.absleft
class PagedDisplay class PagedDisplay
# This class is a namespace to expose functions via the # This class is a namespace to expose functions via the
@ -126,7 +124,25 @@ class PagedDisplay
return sm return sm
fit_images: () -> 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_pos: (frac) ->
# Scroll to the position represented by frac (number between 0 and 1) # Scroll to the position represented by frac (number between 0 and 1)
@ -263,7 +279,7 @@ class PagedDisplay
elem.scrollIntoView() elem.scrollIntoView()
if this.in_paged_mode if this.in_paged_mode
# Ensure we are scrolled to the column containing elem # 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: () -> snap_to_selection: () ->
# Ensure that the viewport is positioned at the start of the column # Ensure that the viewport is positioned at the start of the column
@ -272,7 +288,7 @@ class PagedDisplay
sel = window.getSelection() sel = window.getSelection()
r = sel.getRangeAt(0).getBoundingClientRect() r = sel.getRangeAt(0).getBoundingClientRect()
node = sel.anchorNode 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 # Ensure we are scrolled to the column containing the start of the
# selection # selection
@ -331,5 +347,5 @@ if window?
window.paged_display = new PagedDisplay() window.paged_display = new PagedDisplay()
# TODO: # TODO:
# Resizing of images
# Highlight on jump_to_anchor # Highlight on jump_to_anchor
# Handle document specified margins and allow them to be overridden

View File

@ -117,7 +117,6 @@ class PDFMetadata(object):
if len(oeb_metadata.creator) >= 1: if len(oeb_metadata.creator) >= 1:
self.author = authors_to_string([x.value for x in oeb_metadata.creator]) self.author = authors_to_string([x.value for x in oeb_metadata.creator])
class PDFWriter(QObject): # {{{ class PDFWriter(QObject): # {{{
def __init__(self, opts, log, cover_data=None): def __init__(self, opts, log, cover_data=None):
@ -185,8 +184,8 @@ class PDFWriter(QObject): # {{{
from PyQt4.Qt import QSize, QPainter from PyQt4.Qt import QSize, QPainter
if self.paged_js is None: if self.paged_js is None:
from calibre.utils.resources import compiled_coffeescript from calibre.utils.resources import compiled_coffeescript
self.paged_js = compiled_coffeescript('ebooks.oeb.display.paged', self.paged_js = compiled_coffeescript('ebooks.oeb.display.utils')
dynamic=False) self.paged_js += compiled_coffeescript('ebooks.oeb.display.paged')
printer = get_pdf_printer(self.opts, output_file_name=outpath) printer = get_pdf_printer(self.opts, output_file_name=outpath)
painter = QPainter(printer) painter = QPainter(printer)
zoomx = printer.logicalDpiX()/self.view.logicalDpiX() zoomx = printer.logicalDpiX()/self.view.logicalDpiX()
@ -202,6 +201,7 @@ class PDFWriter(QObject): # {{{
document.body.style.backgroundColor = "white"; document.body.style.backgroundColor = "white";
paged_display.set_geometry(1, 0, 0, 0); paged_display.set_geometry(1, 0, 0, 0);
paged_display.layout(); paged_display.layout();
paged_display.fit_images();
''') ''')
mf = self.view.page().mainFrame() mf = self.view.page().mainFrame()
while True: while True:

View File

@ -736,6 +736,9 @@ class Application(QApplication):
def __init__(self, args, force_calibre_style=False): def __init__(self, args, force_calibre_style=False):
self.file_event_hook = None 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] qargs = [i.encode('utf-8') if isinstance(i, unicode) else i for i in args]
QApplication.__init__(self, qargs) QApplication.__init__(self, qargs)
global gui_thread, qt_app global gui_thread, qt_app

View File

@ -26,8 +26,8 @@ class Printing(QObject):
for x in (Qt.Horizontal, Qt.Vertical): for x in (Qt.Horizontal, Qt.Vertical):
mf.setScrollBarPolicy(x, Qt.ScrollBarAlwaysOff) mf.setScrollBarPolicy(x, Qt.ScrollBarAlwaysOff)
self.view.loadFinished.connect(self.load_finished) self.view.loadFinished.connect(self.load_finished)
self.paged_js = compiled_coffeescript('ebooks.oeb.display.paged', self.paged_js = compiled_coffeescript('ebooks.oeb.display.utils')
dynamic=False) self.paged_js += compiled_coffeescript('ebooks.oeb.display.paged')
def load_finished(self, ok): def load_finished(self, ok):
self.loaded_ok = ok self.loaded_ok = ok
@ -70,6 +70,7 @@ class Printing(QObject):
document.body.style.backgroundColor = "white"; document.body.style.backgroundColor = "white";
paged_display.set_geometry(1, 0, 0, 0); paged_display.set_geometry(1, 0, 0, 0);
paged_display.layout(); paged_display.layout();
paged_display.fit_images();
''') ''')
while True: 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

View File

@ -241,7 +241,7 @@ icu_Collator_contractions(icu_Collator *self, PyObject *args, PyObject *kwargs)
if (self->contractions == NULL) { if (self->contractions == NULL) {
self->contractions = uset_open(1, 0); self->contractions = uset_open(1, 0);
if (self->contractions == NULL) return PyErr_NoMemory(); 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; status = U_ZERO_ERROR;
@ -273,6 +273,8 @@ icu_Collator_contractions(icu_Collator *self, PyObject *args, PyObject *kwargs)
} // }}} } // }}}
// Collator.span_contractions {{{ // Collator.span_contractions {{{
#ifndef __APPLE__
// uset_span is not available in the version of ICU on Apple's idiotic OS
static PyObject * static PyObject *
icu_Collator_span_contractions(icu_Collator *self, PyObject *args, PyObject *kwargs) { icu_Collator_span_contractions(icu_Collator *self, PyObject *args, PyObject *kwargs) {
int span_type; int span_type;
@ -288,7 +290,7 @@ icu_Collator_span_contractions(icu_Collator *self, PyObject *args, PyObject *kwa
if (self->contractions == NULL) { if (self->contractions == NULL) {
self->contractions = uset_open(1, 0); self->contractions = uset_open(1, 0);
if (self->contractions == NULL) return PyErr_NoMemory(); 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; 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); ret = uset_span(self->contractions, s, slen, span_type);
free(s); free(buf); free(s); free(buf);
return Py_BuildValue("i", ret); return Py_BuildValue("i", ret);
} // }}} }
#endif
// }}}
static PyObject* static PyObject*
icu_Collator_clone(icu_Collator *self, PyObject *args, PyObject *kwargs); 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." "contractions() -> returns the contractions defined for this collator."
}, },
#ifndef __APPLE__
{"span_contractions", (PyCFunction)icu_Collator_span_contractions, METH_VARARGS, {"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." "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", (PyCFunction)icu_Collator_clone, METH_VARARGS,
"clone() -> returns a clone of this collator." "clone() -> returns a clone of this collator."
@ -609,7 +614,10 @@ initicu(void)
UErrorCode status = U_ZERO_ERROR; UErrorCode status = U_ZERO_ERROR;
u_init(&status); u_init(&status);
if (U_FAILURE(status)) {
PyErr_SetString(PyExc_RuntimeError, u_errorName(status));
return;
}
if (PyType_Ready(&icu_CollatorType) < 0) if (PyType_Ready(&icu_CollatorType) < 0)
return; return;

View File

@ -33,7 +33,7 @@ def load_icu():
if _icu is None: if _icu is None:
_icu = plugins['icu'][0] _icu = plugins['icu'][0]
if _icu is None: if _icu is None:
print plugins['icu'][1] print 'Loading ICU failed with: ', plugins['icu'][1]
else: else:
if not getattr(_icu, 'ok', False): if not getattr(_icu, 'ok', False):
print 'icu not ok' print 'icu not ok'
@ -184,6 +184,7 @@ def primary_find(pat, src):
################################################################################ ################################################################################
def test(): # {{{ def test(): # {{{
from calibre import prints
# Data {{{ # Data {{{
german = ''' german = '''
Sonntag Sonntag
@ -277,8 +278,6 @@ pêché'''
german = create(german) german = create(german)
c = _icu.Collator('de') c = _icu.Collator('de')
gs = list(sorted(german, key=c.sort_key)) gs = list(sorted(german, key=c.sort_key))
for x in gs:
print '\t', x.encode('utf-8')
if gs != create(german_good): if gs != create(german_good):
print 'German sorting failed' print 'German sorting failed'
return return
@ -286,8 +285,6 @@ pêché'''
french = create(french) french = create(french)
c = _icu.Collator('fr') c = _icu.Collator('fr')
fs = list(sorted(french, key=c.sort_key)) fs = list(sorted(french, key=c.sort_key))
for x in fs:
print '\t', x.encode('utf-8')
if fs != create(french_good): if fs != create(french_good):
print 'French sorting failed (note that French fails with icu < 4.6)' print 'French sorting failed (note that French fails with icu < 4.6)'
return return
@ -306,10 +303,10 @@ pêché'''
for k, v in {u'pèché': u'peche', u'flüße':u'flusse', for k, v in {u'pèché': u'peche', u'flüße':u'flusse',
u'Štepánek':u'Štepanek'}.iteritems(): u'Štepánek':u'Štepanek'}.iteritems():
if primary_strcmp(k, v) != 0: 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 return
if primary_find(v, u' '+k)[0] != 1: 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 return
global _primary_collator global _primary_collator
@ -318,6 +315,14 @@ pêché'''
print 'Primary collation in Spanish locale failed' print 'Primary collation in Spanish locale failed'
return 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__': if __name__ == '__main__':