This commit is contained in:
Kovid Goyal 2008-03-12 23:55:25 +00:00
parent 3bf15427c3
commit 0c949a265c

View File

@ -1126,20 +1126,32 @@ class HTMLConverter(object):
return key return key
def font_size(val): def font_size(val):
normal = 100 #10*pts normal = int(self.current_block.textStyle.attrs['fontsize'])
ans = self.unit_convert(val, pts=True) normpts = str(normal/10) + 'pt'
ans = self.unit_convert(val, pts=True, base_length=normpts)
if ans: if ans:
if ans < 0: if ans <= 0:
ans += normal ans += normal
if ans == 0: # Common case of using -1em to mean "smaller"
ans = int(font_size("smaller"))
if ans < 0: if ans < 0:
ans = normal ans = normal
else: else:
if "xx-small" in val: if ans == 0:
ans = int(font_size("smaller"))
elif "xx-small" in val:
ans = 40 ans = 40
elif "x-small" in val: elif "x-small" in val:
ans = 60 ans = 60
elif "small" in val: elif "small" in val:
ans = 80 ans = 80
if "smaller" in val:
ans = normal - 20
elif "medium" in val:
ans = 100
elif "larger" in val:
ans = normal + 20
elif "xx-large" in val: elif "xx-large" in val:
ans = 180 ans = 180
elif "x-large" in val: elif "x-large" in val:
@ -1209,7 +1221,6 @@ class HTMLConverter(object):
def unit_convert(self, val, pts=False, base_length='10pt'): def unit_convert(self, val, pts=False, base_length='10pt'):
''' '''
Tries to convert html units in C{val} to pixels. Tries to convert html units in C{val} to pixels.
Assumes: 1em = 100% = 10pts
@param pts: If True return 10*pts instead of pixels. @param pts: If True return 10*pts instead of pixels.
@return: The number of pixels (an int) if successful. Otherwise, returns None. @return: The number of pixels (an int) if successful. Otherwise, returns None.
''' '''
@ -1226,22 +1237,25 @@ class HTMLConverter(object):
normal = self.unit_convert(base_length) normal = self.unit_convert(base_length)
result = int((unit/100.0)*normal) result = int((unit/100.0)*normal)
elif m.group(2) == 'px': elif m.group(2) == 'px':
result = int(unit) result = unit
elif m.group(2) == 'in': elif m.group(2) == 'in':
result = int(unit * dpi) result = unit * dpi
elif m.group(2) == 'pt': elif m.group(2) == 'pt':
result = int(unit * dpi/72.) result = unit * dpi/72.
elif m.group(2)== 'em': elif m.group(2) == 'em':
result = int(unit * (dpi/72.) * 10) normal = float(self.current_block.textStyle.attrs['fontsize'])
elif m.group(2)== 'pc': result = unit * normal * (dpi/720.)
result = int(unit * (dpi/72.) * 12) elif m.group(2) == 'pc':
elif m.group(2)== 'mm': result = unit * (dpi/72.) * 12
result = int(unit * 0.04 * (dpi/72.)) elif m.group(2) == 'mm':
elif m.group(2)== 'cm': result = unit * 0.04 * (dpi/72.)
result = int(unit * 0.4 * (dpi/72.)) elif m.group(2) == 'cm':
if pts: result = unit * 0.40 * (dpi/72.)
if result is not None: if result is not None:
result = int((float(result)/dpi)*720) if pts:
result = int(round(result / dpi * 720))
else:
result = int(round(result))
return result return result
def text_properties(self, tag_css): def text_properties(self, tag_css):