mirror of
git://github.com/kovidgoyal/calibre.git
synced 2026-05-09 07:03:41 +02:00
This commit is contained in:
parent
40e6f28b4d
commit
9187c19baf
1 changed files with 21 additions and 20 deletions
|
|
@ -26,6 +26,26 @@
|
|||
if isosx and hasattr(sys, 'frameworks_dir'):
|
||||
PDFTOXML = os.path.join(getattr(sys, 'frameworks_dir'), PDFTOXML)
|
||||
|
||||
class StyleContainer(object):
|
||||
|
||||
def set_style(self, iterator):
|
||||
styles = set([])
|
||||
for tok in iterator:
|
||||
if hasattr(tok, 'style'):
|
||||
styles.add(tok.style)
|
||||
counts = [0*i for i in range(len(styles))]
|
||||
for i in range(len(styles)):
|
||||
counts[i] = sum([1 for j in self if j.style == styles[i]])
|
||||
max = max(counts)
|
||||
for i in range(len(counts)):
|
||||
if counts[i] == max:
|
||||
break
|
||||
self.style = styles[i]
|
||||
for obj in iterator:
|
||||
if obj.style == self.style:
|
||||
obj.style = None
|
||||
|
||||
|
||||
class Page(object):
|
||||
|
||||
def __init__(self, attrs):
|
||||
|
|
@ -78,7 +98,7 @@ def look_for_page_break(self):
|
|||
self.page_break_after = max < 0.8*self.height
|
||||
|
||||
|
||||
class Group(object, StyleContainer):
|
||||
class Group(StyleContainer):
|
||||
|
||||
def __init__(self, lines):
|
||||
self.lines = lines
|
||||
|
|
@ -150,25 +170,6 @@ def to_xhtml(self):
|
|||
return ' '.join(res)
|
||||
|
||||
|
||||
class StyleContainer(object):
|
||||
|
||||
def set_style(self, iterator):
|
||||
styles = set([])
|
||||
for tok in iterator:
|
||||
if hasattr(tok, 'style'):
|
||||
styles.add(tok.style)
|
||||
counts = [0*i for i in range(len(styles))]
|
||||
for i in range(len(styles)):
|
||||
counts[i] = sum([1 for j in self if j.style == styles[i]])
|
||||
max = max(counts)
|
||||
for i in range(len(counts)):
|
||||
if counts[i] == max:
|
||||
break
|
||||
self.style = styles[i]
|
||||
for obj in iterator:
|
||||
if obj.style == self.style:
|
||||
obj.style = None
|
||||
|
||||
class Line(list, StyleContainer):
|
||||
|
||||
def calculate_geometry(self):
|
||||
|
|
|
|||
Loading…
Reference in a new issue