mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Add support for underline and overline
This commit is contained in:
parent
1bffc5a8cf
commit
d317872bbd
@ -14,6 +14,7 @@
|
||||
## You should have received a copy of the GNU General Public License along
|
||||
## with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
from libprs500.ebooks.lrf.pylrs.pylrs import EmpLine
|
||||
"""
|
||||
Code to convert HTML ebooks into LRF ebooks.
|
||||
|
||||
@ -128,6 +129,7 @@ class HTMLConverter(object):
|
||||
'th' : {'font-size' : 'large', 'font-weight':'bold'},
|
||||
'big' : {'font-size' : 'large', 'font-weight':'bold'},
|
||||
'.libprs500_dropcaps' : {'font-size': 'xx-large'},
|
||||
'u' : {'text-decoration': 'underline'},
|
||||
}
|
||||
|
||||
def __init__(self, book, fonts, options, logger, path):
|
||||
@ -635,6 +637,11 @@ class HTMLConverter(object):
|
||||
for prop in unneeded:
|
||||
fp.pop(prop)
|
||||
elem = Span(text=src, **fp) if (fp or force_span_use) else src
|
||||
if css.has_key('text-decoration'):
|
||||
dec = css['text-decoration'].lower()
|
||||
linepos = 'after' if dec == 'underline' else 'before' if dec == 'overline' else None
|
||||
if linepos is not None:
|
||||
elem = EmpLine(elem, lineposition=linepos)
|
||||
self.current_para.append(elem)
|
||||
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
</head>
|
||||
<h1>Demo of <span style='font-family:monospace'>html2lrf</span></h1>
|
||||
<p>
|
||||
This file contains a demonstration of the capabilities of <span style='font-family:monospace'>html2lrf</span>, the HTML to LRF converter from <em>libprs500.</em> To obtain libprs500 visit<br/><span style='font:sans-serif'>https://libprs500.kovidgoyal.net</span>
|
||||
This document contains a demonstration of the capabilities of <span style='font-family:monospace'>html2lrf</span>, the HTML to LRF converter from <em>libprs500.</em> To obtain libprs500 visit<br/><span style='font:sans-serif'>https://libprs500.kovidgoyal.net</span>
|
||||
</p>
|
||||
<br/>
|
||||
<h2 id="toc">Table of Contents</h2>
|
||||
@ -96,13 +96,14 @@
|
||||
<h2><a name='text'>Text formatting</a></h2>
|
||||
<p>
|
||||
A simple <i>paragraph</i> of <b>formatted
|
||||
<i>text</i></b>, with a ruled line following it.
|
||||
<i>text</i></b>, with a <u>ruled line</u> following it.
|
||||
Super<sup>scripts</sup> and Sub<sub>scripts</sub>.
|
||||
</p>
|
||||
<hr/>
|
||||
<br/>
|
||||
<p> A
|
||||
<span style='font-style:italic'>similar</span>
|
||||
paragraph, but now using
|
||||
paragraph, but now <span style="text-decoration:overline">using</span>
|
||||
<span style='font-weight:bold'>CSS</span>
|
||||
to perform the text formatting.</p>
|
||||
<hr/>
|
||||
|
@ -102,8 +102,7 @@ def writeIdList(f, idList):
|
||||
|
||||
def writeColor(f, color):
|
||||
# TODO: allow color names, web format
|
||||
color = int(color, 0)
|
||||
f.write(struct.pack(">I", color))
|
||||
f.write(struct.pack(">I", int(color, 0)))
|
||||
|
||||
def writeLineWidth(f, width):
|
||||
writeWord(f, int(width)//5)
|
||||
|
@ -525,15 +525,17 @@ class Book(Delegator):
|
||||
method(content)
|
||||
|
||||
|
||||
def renderLrs(self, lrsFilename):
|
||||
lrsFile = codecs.open(lrsFilename, "wb", encoding="utf-16")
|
||||
def renderLrs(self, lrsFile):
|
||||
if isinstance(lrsFile, basestring):
|
||||
lrsFile = codecs.open(lrsFile, "wb", encoding="utf-16")
|
||||
self.render(lrsFile)
|
||||
lrsFile.close()
|
||||
|
||||
|
||||
def renderLrf(self, lrfFilename):
|
||||
def renderLrf(self, lrfFile):
|
||||
self.appendReferencedObjects(self)
|
||||
lrfFile = file(lrfFilename, "wb")
|
||||
if isinstance(lrfFile, basestring):
|
||||
lrfFile = file(lrfFile, "wb")
|
||||
lrfWriter = LrfWriter(self.sourceencoding)
|
||||
|
||||
lrfWriter.optimizeTags = self.optimizeTags
|
||||
@ -1045,7 +1047,7 @@ class StyleDefault(LrsAttributes):
|
||||
defaults = dict(rubyalign="start", rubyadjust="none",
|
||||
rubyoverhang="none", empdotsposition="before",
|
||||
empdotsfontname="Dutch801 Rm BT Roman",
|
||||
empdotscode="0x002e", emplineposition="before",
|
||||
empdotscode="0x002e", emplineposition="after",
|
||||
emplinetype = "solid", setwaitprop="noreplay")
|
||||
|
||||
alsoAllow = ["refempdotsfont"]
|
||||
@ -1143,17 +1145,17 @@ class TextStyle(LrsStyle):
|
||||
"""
|
||||
baseDefaults = dict(
|
||||
columnsep="0", charspace="0",
|
||||
textlinewidth="0", align="head", linecolor="0x00000000",
|
||||
textlinewidth="10", align="head", linecolor="0x00000000",
|
||||
column="1", fontsize="100", fontwidth="-10", fontescapement="0",
|
||||
fontorientation="0", fontweight="400",
|
||||
fontfacename="Dutch801 Rm BT Roman",
|
||||
textcolor="0x00000000", wordspace="25", letterspace="0",
|
||||
baselineskip="120", linespace="10", parindent="0", parskip="0",
|
||||
textbgcolor="0xFF000000")
|
||||
textbgcolor="0xFF000000", emplinetype="solid", emplineposition="after")
|
||||
|
||||
alsoAllow = ["empdotscode", "empdotsfontname", "refempdotsfont",
|
||||
"rubyadjust", "rubyalign", "rubyoverhang",
|
||||
"empdotsposition", "emplineposition", "emplinetype"]
|
||||
"empdotsposition"]
|
||||
|
||||
validSettings = baseDefaults.keys() + alsoAllow
|
||||
|
||||
@ -1682,9 +1684,6 @@ class Italic(LrsSimpleChar1, LrsTextTag):
|
||||
def __init__(self, text=None):
|
||||
LrsTextTag.__init__(self, text, [LrsSimpleChar1])
|
||||
|
||||
|
||||
|
||||
|
||||
class Sub(LrsSimpleChar1, LrsTextTag):
|
||||
def __init__(self, text=None):
|
||||
LrsTextTag.__init__(self, text, [])
|
||||
@ -1797,13 +1796,43 @@ class Span(LrsSimpleChar1, LrsContainer):
|
||||
|
||||
|
||||
def toElement(self, se):
|
||||
element = Element("Span")
|
||||
element = Element('Span')
|
||||
for (key, value) in self.attrs.items():
|
||||
element.set(key, str(value))
|
||||
|
||||
appendTextElements(element, self.contents, se)
|
||||
return element
|
||||
|
||||
class EmpLine(LrsTextTag, LrsSimpleChar1):
|
||||
linetypes = ['none', 'solid', 'dotted', 'dashed', 'double']
|
||||
linepositions = ['before', 'after']
|
||||
|
||||
def __init__(self, text=None, lineposition='before', linetype='solid'):
|
||||
LrsTextTag.__init__(self, text, [LrsSimpleChar1])
|
||||
if lineposition not in self.__class__.linepositions:
|
||||
raise LrsError('lineposition for an EmpLine must be one of: '+str(self.__class__.linepositions))
|
||||
if linetype not in self.__class__.linetypes:
|
||||
raise LrsError('linetype for an EmpLine must be one of: '+str(self.__class__.linetypes))
|
||||
|
||||
self.emplinetype=linetype
|
||||
self.emplineposition=lineposition
|
||||
|
||||
def toLrfContainer(self, lrfWriter, parent):
|
||||
parent.appendLrfTag(LrfTag(self.__class__.__name__, (self.emplineposition, self.emplinetype)))
|
||||
parent.appendLrfTag(LrfTag('emplineposition', self.emplineposition))
|
||||
parent.appendLrfTag(LrfTag('emplinetype', self.emplinetype))
|
||||
for content in self.contents:
|
||||
content.toLrfContainer(lrfWriter, parent)
|
||||
|
||||
parent.appendLrfTag(LrfTag(self.__class__.__name__ + "End"))
|
||||
|
||||
def toElement(self, se):
|
||||
element = Element(self.__class__.__name__)
|
||||
element.set('emplineposition', self.emplineposition)
|
||||
element.set('emplinetype', self.emplinetype)
|
||||
|
||||
appendTextElements(element, self.contents, se)
|
||||
return element
|
||||
|
||||
class Bold(Span):
|
||||
"""
|
||||
|
Loading…
x
Reference in New Issue
Block a user