This commit is contained in:
Sengian 2010-11-18 21:37:51 +01:00
parent b4d27028c3
commit 78e4aba18c
2 changed files with 177 additions and 95 deletions

View File

@ -1,6 +1,4 @@
body { body { background-color: white; }
background-color: white;
}
p.title { p.title {
margin-top:0em; margin-top:0em;
@ -8,29 +6,49 @@ p.title {
text-align:center; text-align:center;
font-style:italic; font-style:italic;
font-size:xx-large; font-size:xx-large;
border-bottom: solid black 4px; border-bottom: solid black 2px;
} }
p.author { p.author {
margin-top:0em; margin-top:0em;
margin-bottom:0em; margin-bottom:0em;
text-align: left; text-align: center;
text-indent: 1em; text-indent: 0em;
font-size:large; font-size:large;
} }
p.tags { p.author_index {
margin-top: 0em; font-size:large;
margin-bottom: 0em; font-weight:bold;
text-align:left; text-align:left;
text-indent: 1em; margin-top:0px;
font-size: small; margin-bottom:-2px;
text-indent: 0em;
} }
p.description { p.tags {
margin-top:0.5em;
margin-bottom:0em;
text-align: left; text-align: left;
font-style: normal; text-indent: 0.0in;
}
p.formats {
font-size:90%;
margin-top:0em; margin-top:0em;
margin-bottom:0.5em;
text-align: left;
text-indent: 0.0in;
}
div.description > p:first-child {
margin: 0 0 0 0;
text-indent: 0em;
}
div.description {
margin: 0 0 0 0;
text-indent: 1em;
} }
p.date_index { p.date_index {
@ -49,19 +67,12 @@ p.letter_index {
margin-bottom:0px; margin-bottom:0px;
} }
p.author_index {
font-size: large;
text-align: left;
margin-top: 0px;
margin-bottom: 0px;
text-indent: 0em;
}
p.series { p.series {
text-align: left; font-style:italic;
margin-top: 0px; margin-top:2px;
margin-bottom:0px; margin-bottom:0px;
margin-left:2em; margin-left:2em;
text-align:left;
text-indent:-2em; text-indent:-2em;
} }
@ -81,7 +92,7 @@ p.unread_book {
text-indent:-2em; text-indent:-2em;
} }
p.missing_book { p.wishlist_item {
text-align:left; text-align:left;
margin-top:0px; margin-top:0px;
margin-bottom:0px; margin-bottom:0px;
@ -97,11 +108,13 @@ p.date_read {
text-indent:-6em; text-indent:-6em;
} }
hr.series_divider { hr.description_divider {
width: 50%; width:90%;
margin-left: 1em; margin-left:5%;
margin-top: 0em; border-top: solid white 0px;
margin-bottom: 0em; border-right: solid white 0px;
border-bottom: solid black 1px;
border-left: solid white 0px;
} }
hr.annotations_divider { hr.annotations_divider {
@ -110,3 +123,14 @@ hr.annotations_divider {
margin-top:0em; margin-top:0em;
margin-bottom:0em; margin-bottom:0em;
} }
td.publisher, td.date {
font-weight:bold;
text-align:center;
}
td.rating {
text-align: center;
}
td.thumbnail img {
-webkit-box-shadow: 4px 4px 12px #999;
}

View File

@ -9,6 +9,36 @@ from lxml import etree
from calibre.customize.conversion import InputFormatPlugin from calibre.customize.conversion import InputFormatPlugin
from calibre.ebooks.conversion.utils import PreProcessor from calibre.ebooks.conversion.utils import PreProcessor
border_style_map = {
'single' : 'solid',
'double-thickness-border' : 'double',
'shadowed-border': 'outset',
'double-border': 'double',
'dotted-border': 'dotted',
'dashed': 'dashed',
'hairline': 'solid',
'inset': 'inset',
'dash-small': 'dashed',
'dot-dash': 'dotted',
'dot-dot-dash': 'dotted',
'outset': 'outset',
'tripple': 'double',
'thick-thin-small': 'solid',
'thin-thick-small': 'solid',
'thin-thick-thin-small': 'solid',
'thick-thin-medium': 'solid',
'thin-thick-medium': 'solid',
'thin-thick-thin-medium': 'solid',
'thick-thin-large': 'solid',
'thin-thick-thin-large': 'solid',
'wavy': 'ridge',
'double-wavy': 'ridge',
'striped': 'ridge',
'emboss': 'inset',
'engrave': 'inset',
'frame': 'ridge',
}
class InlineClass(etree.XSLTExtension): class InlineClass(etree.XSLTExtension):
FMTS = ('italics', 'bold', 'underlined', 'strike-through', 'small-caps') FMTS = ('italics', 'bold', 'underlined', 'strike-through', 'small-caps')
@ -51,7 +81,6 @@ class RTFInput(InputFormatPlugin):
parser = ParseRtf( parser = ParseRtf(
in_file = stream, in_file = stream,
out_file = ofile, out_file = ofile,
deb_dir = 'H:\\Temp\\Calibre\\rtfdebug',
# Convert symbol fonts to unicode equivalents. Default # Convert symbol fonts to unicode equivalents. Default
# is 1 # is 1
convert_symbol = 1, convert_symbol = 1,
@ -138,8 +167,7 @@ class RTFInput(InputFormatPlugin):
return name return name
def write_inline_css(self, ic, border_styles):
def write_inline_css(self, ic):
font_size_classes = ['span.fs%d { font-size: %spt }'%(i, x) for i, x in font_size_classes = ['span.fs%d { font-size: %spt }'%(i, x) for i, x in
enumerate(ic.font_sizes)] enumerate(ic.font_sizes)]
color_classes = ['span.col%d { color: %s }'%(i, x) for i, x in color_classes = ['span.col%d { color: %s }'%(i, x) for i, x in
@ -163,6 +191,10 @@ class RTFInput(InputFormatPlugin):
''') ''')
css += '\n'+'\n'.join(font_size_classes) css += '\n'+'\n'.join(font_size_classes)
css += '\n' +'\n'.join(color_classes) css += '\n' +'\n'.join(color_classes)
for cls, val in border_styles.items():
css += '\n\n.%s {\n%s\n}'%(cls, val)
with open('styles.css', 'ab') as f: with open('styles.css', 'ab') as f:
f.write(css) f.write(css)
@ -182,6 +214,32 @@ class RTFInput(InputFormatPlugin):
'Failed to preprocess RTF to convert unicode sequences, ignoring...') 'Failed to preprocess RTF to convert unicode sequences, ignoring...')
return fname return fname
def convert_borders(self, doc):
border_styles = []
style_map = {}
for elem in doc.xpath(r'//*[local-name()="cell"]'):
style = ['border-style: hidden', 'border-width: 1px',
'border-color: black']
for x in ('bottom', 'top', 'left', 'right'):
bs = elem.get('border-cell-%s-style'%x, None)
if bs:
cbs = border_style_map.get(bs, 'solid')
style.append('border-%s-style: %s'%(x, cbs))
bw = elem.get('border-cell-%s-line-width'%x, None)
if bw:
style.append('border-%s-width: %spt'%(x, bw))
bc = elem.get('border-cell-%s-color'%x, None)
if bc:
style.append('border-%s-color: %s'%(x, bc))
style = ';\n'.join(style)
if style not in border_styles:
border_styles.append(style)
idx = border_styles.index(style)
cls = 'border_style%d'%idx
style_map[cls] = style
elem.set('class', cls)
return style_map
def convert(self, stream, options, file_ext, log, def convert(self, stream, options, file_ext, log,
accelerators): accelerators):
from calibre.ebooks.metadata.meta import get_metadata from calibre.ebooks.metadata.meta import get_metadata
@ -191,17 +249,16 @@ class RTFInput(InputFormatPlugin):
self.log = log self.log = log
self.log('Converting RTF to XML...') self.log('Converting RTF to XML...')
#Name of the preprocesssed RTF file #Name of the preprocesssed RTF file
#fname = self.preprocess(stream.name) fname = self.preprocess(stream.name)
fname = stream.name
try: try:
xml = self.generate_xml(fname) xml = self.generate_xml(fname)
except RtfInvalidCodeException, e: except RtfInvalidCodeException, e:
raise ValueError(_('This RTF file has a feature calibre does not ' raise ValueError(_('This RTF file has a feature calibre does not '
'support. Convert it to HTML first and then try it.\n%s')%e) 'support. Convert it to HTML first and then try it.\n%s')%e)
dataxml = open('dataxml.xml', 'w') '''dataxml = open('dataxml.xml', 'w')
dataxml.write(xml) dataxml.write(xml)
dataxml.close dataxml.close'''
d = glob.glob(os.path.join('*_rtf_pict_dir', 'picts.rtf')) d = glob.glob(os.path.join('*_rtf_pict_dir', 'picts.rtf'))
if d: if d:
@ -214,6 +271,7 @@ class RTFInput(InputFormatPlugin):
self.log('Parsing XML...') self.log('Parsing XML...')
parser = etree.XMLParser(recover=True, no_network=True) parser = etree.XMLParser(recover=True, no_network=True)
doc = etree.fromstring(xml, parser=parser) doc = etree.fromstring(xml, parser=parser)
border_styles = self.convert_borders(doc)
for pict in doc.xpath('//rtf:pict[@num]', for pict in doc.xpath('//rtf:pict[@num]',
namespaces={'rtf':'http://rtf2xml.sourceforge.net/'}): namespaces={'rtf':'http://rtf2xml.sourceforge.net/'}):
num = int(pict.get('num')) num = int(pict.get('num'))
@ -235,7 +293,7 @@ class RTFInput(InputFormatPlugin):
preprocessor = PreProcessor(self.options, log=getattr(self, 'log', None)) preprocessor = PreProcessor(self.options, log=getattr(self, 'log', None))
res = preprocessor(res) res = preprocessor(res)
f.write(res) f.write(res)
self.write_inline_css(inline_class) self.write_inline_css(inline_class, border_styles)
stream.seek(0) stream.seek(0)
mi = get_metadata(stream, 'rtf') mi = get_metadata(stream, 'rtf')
if not mi.title: if not mi.title: