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
|
## 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.,
|
## with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
## 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.
|
Code to convert HTML ebooks into LRF ebooks.
|
||||||
|
|
||||||
@ -127,7 +128,8 @@ class HTMLConverter(object):
|
|||||||
'center' : {'text-align' : 'center'},
|
'center' : {'text-align' : 'center'},
|
||||||
'th' : {'font-size' : 'large', 'font-weight':'bold'},
|
'th' : {'font-size' : 'large', 'font-weight':'bold'},
|
||||||
'big' : {'font-size' : 'large', 'font-weight':'bold'},
|
'big' : {'font-size' : 'large', 'font-weight':'bold'},
|
||||||
'.libprs500_dropcaps' : {'font-size': 'xx-large'},
|
'.libprs500_dropcaps' : {'font-size': 'xx-large'},
|
||||||
|
'u' : {'text-decoration': 'underline'},
|
||||||
}
|
}
|
||||||
|
|
||||||
def __init__(self, book, fonts, options, logger, path):
|
def __init__(self, book, fonts, options, logger, path):
|
||||||
@ -635,6 +637,11 @@ class HTMLConverter(object):
|
|||||||
for prop in unneeded:
|
for prop in unneeded:
|
||||||
fp.pop(prop)
|
fp.pop(prop)
|
||||||
elem = Span(text=src, **fp) if (fp or force_span_use) else src
|
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)
|
self.current_para.append(elem)
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
</head>
|
</head>
|
||||||
<h1>Demo of <span style='font-family:monospace'>html2lrf</span></h1>
|
<h1>Demo of <span style='font-family:monospace'>html2lrf</span></h1>
|
||||||
<p>
|
<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>
|
</p>
|
||||||
<br/>
|
<br/>
|
||||||
<h2 id="toc">Table of Contents</h2>
|
<h2 id="toc">Table of Contents</h2>
|
||||||
@ -96,13 +96,14 @@
|
|||||||
<h2><a name='text'>Text formatting</a></h2>
|
<h2><a name='text'>Text formatting</a></h2>
|
||||||
<p>
|
<p>
|
||||||
A simple <i>paragraph</i> of <b>formatted
|
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>.
|
Super<sup>scripts</sup> and Sub<sub>scripts</sub>.
|
||||||
</p>
|
</p>
|
||||||
<hr/>
|
<hr/>
|
||||||
|
<br/>
|
||||||
<p> A
|
<p> A
|
||||||
<span style='font-style:italic'>similar</span>
|
<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>
|
<span style='font-weight:bold'>CSS</span>
|
||||||
to perform the text formatting.</p>
|
to perform the text formatting.</p>
|
||||||
<hr/>
|
<hr/>
|
||||||
|
@ -102,8 +102,7 @@ def writeIdList(f, idList):
|
|||||||
|
|
||||||
def writeColor(f, color):
|
def writeColor(f, color):
|
||||||
# TODO: allow color names, web format
|
# TODO: allow color names, web format
|
||||||
color = int(color, 0)
|
f.write(struct.pack(">I", int(color, 0)))
|
||||||
f.write(struct.pack(">I", color))
|
|
||||||
|
|
||||||
def writeLineWidth(f, width):
|
def writeLineWidth(f, width):
|
||||||
writeWord(f, int(width)//5)
|
writeWord(f, int(width)//5)
|
||||||
@ -147,7 +146,7 @@ def writeRuledLine(f, lineInfo):
|
|||||||
writeWord(f, LINE_TYPE_ENCODING[lineType])
|
writeWord(f, LINE_TYPE_ENCODING[lineType])
|
||||||
writeWord(f, lineWidth)
|
writeWord(f, lineWidth)
|
||||||
writeColor(f, lineColor)
|
writeColor(f, lineColor)
|
||||||
|
|
||||||
|
|
||||||
LRF_SIGNATURE = "L\x00R\x00F\x00\x00\x00"
|
LRF_SIGNATURE = "L\x00R\x00F\x00\x00\x00"
|
||||||
|
|
||||||
|
@ -525,15 +525,17 @@ class Book(Delegator):
|
|||||||
method(content)
|
method(content)
|
||||||
|
|
||||||
|
|
||||||
def renderLrs(self, lrsFilename):
|
def renderLrs(self, lrsFile):
|
||||||
lrsFile = codecs.open(lrsFilename, "wb", encoding="utf-16")
|
if isinstance(lrsFile, basestring):
|
||||||
|
lrsFile = codecs.open(lrsFile, "wb", encoding="utf-16")
|
||||||
self.render(lrsFile)
|
self.render(lrsFile)
|
||||||
lrsFile.close()
|
lrsFile.close()
|
||||||
|
|
||||||
|
|
||||||
def renderLrf(self, lrfFilename):
|
def renderLrf(self, lrfFile):
|
||||||
self.appendReferencedObjects(self)
|
self.appendReferencedObjects(self)
|
||||||
lrfFile = file(lrfFilename, "wb")
|
if isinstance(lrfFile, basestring):
|
||||||
|
lrfFile = file(lrfFile, "wb")
|
||||||
lrfWriter = LrfWriter(self.sourceencoding)
|
lrfWriter = LrfWriter(self.sourceencoding)
|
||||||
|
|
||||||
lrfWriter.optimizeTags = self.optimizeTags
|
lrfWriter.optimizeTags = self.optimizeTags
|
||||||
@ -1045,7 +1047,7 @@ class StyleDefault(LrsAttributes):
|
|||||||
defaults = dict(rubyalign="start", rubyadjust="none",
|
defaults = dict(rubyalign="start", rubyadjust="none",
|
||||||
rubyoverhang="none", empdotsposition="before",
|
rubyoverhang="none", empdotsposition="before",
|
||||||
empdotsfontname="Dutch801 Rm BT Roman",
|
empdotsfontname="Dutch801 Rm BT Roman",
|
||||||
empdotscode="0x002e", emplineposition="before",
|
empdotscode="0x002e", emplineposition="after",
|
||||||
emplinetype = "solid", setwaitprop="noreplay")
|
emplinetype = "solid", setwaitprop="noreplay")
|
||||||
|
|
||||||
alsoAllow = ["refempdotsfont"]
|
alsoAllow = ["refempdotsfont"]
|
||||||
@ -1143,17 +1145,17 @@ class TextStyle(LrsStyle):
|
|||||||
"""
|
"""
|
||||||
baseDefaults = dict(
|
baseDefaults = dict(
|
||||||
columnsep="0", charspace="0",
|
columnsep="0", charspace="0",
|
||||||
textlinewidth="0", align="head", linecolor="0x00000000",
|
textlinewidth="10", align="head", linecolor="0x00000000",
|
||||||
column="1", fontsize="100", fontwidth="-10", fontescapement="0",
|
column="1", fontsize="100", fontwidth="-10", fontescapement="0",
|
||||||
fontorientation="0", fontweight="400",
|
fontorientation="0", fontweight="400",
|
||||||
fontfacename="Dutch801 Rm BT Roman",
|
fontfacename="Dutch801 Rm BT Roman",
|
||||||
textcolor="0x00000000", wordspace="25", letterspace="0",
|
textcolor="0x00000000", wordspace="25", letterspace="0",
|
||||||
baselineskip="120", linespace="10", parindent="0", parskip="0",
|
baselineskip="120", linespace="10", parindent="0", parskip="0",
|
||||||
textbgcolor="0xFF000000")
|
textbgcolor="0xFF000000", emplinetype="solid", emplineposition="after")
|
||||||
|
|
||||||
alsoAllow = ["empdotscode", "empdotsfontname", "refempdotsfont",
|
alsoAllow = ["empdotscode", "empdotsfontname", "refempdotsfont",
|
||||||
"rubyadjust", "rubyalign", "rubyoverhang",
|
"rubyadjust", "rubyalign", "rubyoverhang",
|
||||||
"empdotsposition", "emplineposition", "emplinetype"]
|
"empdotsposition"]
|
||||||
|
|
||||||
validSettings = baseDefaults.keys() + alsoAllow
|
validSettings = baseDefaults.keys() + alsoAllow
|
||||||
|
|
||||||
@ -1682,9 +1684,6 @@ class Italic(LrsSimpleChar1, LrsTextTag):
|
|||||||
def __init__(self, text=None):
|
def __init__(self, text=None):
|
||||||
LrsTextTag.__init__(self, text, [LrsSimpleChar1])
|
LrsTextTag.__init__(self, text, [LrsSimpleChar1])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Sub(LrsSimpleChar1, LrsTextTag):
|
class Sub(LrsSimpleChar1, LrsTextTag):
|
||||||
def __init__(self, text=None):
|
def __init__(self, text=None):
|
||||||
LrsTextTag.__init__(self, text, [])
|
LrsTextTag.__init__(self, text, [])
|
||||||
@ -1797,13 +1796,43 @@ class Span(LrsSimpleChar1, LrsContainer):
|
|||||||
|
|
||||||
|
|
||||||
def toElement(self, se):
|
def toElement(self, se):
|
||||||
element = Element("Span")
|
element = Element('Span')
|
||||||
for (key, value) in self.attrs.items():
|
for (key, value) in self.attrs.items():
|
||||||
element.set(key, str(value))
|
element.set(key, str(value))
|
||||||
|
|
||||||
appendTextElements(element, self.contents, se)
|
appendTextElements(element, self.contents, se)
|
||||||
return element
|
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):
|
class Bold(Span):
|
||||||
"""
|
"""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user