mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix bug in font-size-mapping algorithm.
This commit is contained in:
parent
56a64e1540
commit
0815098cf8
@ -796,7 +796,17 @@ class Processor(Parser):
|
||||
setting = ''
|
||||
face = font.attrib.pop('face', None)
|
||||
if face is not None:
|
||||
setting += 'font-face:%s;'%face
|
||||
faces = []
|
||||
for face in face.split(','):
|
||||
if ' ' in face:
|
||||
face = "%s" % face
|
||||
faces.append(face)
|
||||
for generic in ('serif', 'sans-serif', 'monospace'):
|
||||
if generic in faces:
|
||||
break
|
||||
else:
|
||||
faces.append('serif')
|
||||
setting += 'font-family:%s;'% ', '.join(faces)
|
||||
color = font.attrib.pop('color', None)
|
||||
if color is not None:
|
||||
setting += 'color:%s'%color
|
||||
|
@ -42,7 +42,7 @@ PROFILES = {
|
||||
# Not really, but let's pretend
|
||||
'MobiDesktop':
|
||||
Profile(width=280, height=300, dpi=96, fbase=18,
|
||||
fsizes=[14, 14, 16, 18, 20, 22, 22, 24]),
|
||||
fsizes=[14, 14, 16, 18, 20, 22, 24, 26]),
|
||||
|
||||
# No clue on usable screen size and DPI
|
||||
'CybookG3':
|
||||
|
@ -33,12 +33,13 @@ class KeyMapper(object):
|
||||
def relate(size, base):
|
||||
size = float(size)
|
||||
base = float(base)
|
||||
if size == base: return 0
|
||||
if abs(size - base) < 0.1: return 0
|
||||
sign = -1 if size < base else 1
|
||||
endp = 0 if size < base else 36
|
||||
diff = (abs(base - size) * 3) + ((36 - size) / 100)
|
||||
logb = abs(base - endp)
|
||||
return sign * math.log(diff, logb)
|
||||
result = sign * math.log(diff, logb)
|
||||
return result
|
||||
|
||||
def __getitem__(self, ssize):
|
||||
if ssize in self.cache:
|
||||
@ -122,6 +123,8 @@ class CSSFlattener(object):
|
||||
fsize = self.context.source.fbase
|
||||
self.baseline_node(body, stylizer, sizes, fsize)
|
||||
sbase = max(sizes.items(), key=operator.itemgetter(1))[0]
|
||||
self.oeb.logger.info(
|
||||
"Source base font size is %0.05fpt" % sbase)
|
||||
return sbase
|
||||
|
||||
def clean_edges(self, cssdict, style, fsize):
|
||||
@ -154,14 +157,14 @@ class CSSFlattener(object):
|
||||
if node.tag == XHTML('font'):
|
||||
node.tag = XHTML('span')
|
||||
if 'size' in node.attrib:
|
||||
size = node.attrib['size']
|
||||
if size.startswith('+'):
|
||||
cssdict['font-size'] = 'larger'
|
||||
elif size.startswith('-'):
|
||||
cssdict['font-size'] = 'smaller'
|
||||
else:
|
||||
size = node.attrib['size'].strip()
|
||||
if size:
|
||||
fnums = self.context.source.fnums
|
||||
cssdict['font-size'] = fnums[int(size)]
|
||||
if size[0] in ('+', '-'):
|
||||
# Oh, the warcrimes
|
||||
cssdict['font-size'] = fnums[3+int(size)]
|
||||
else:
|
||||
cssdict['font-size'] = fnums[int(size)]
|
||||
del node.attrib['size']
|
||||
if 'color' in node.attrib:
|
||||
cssdict['color'] = node.attrib['color']
|
||||
|
Loading…
x
Reference in New Issue
Block a user