Skip to content

Commit 556133a

Browse files
author
Daniel Dotsenko
committed
fromHTML plugin: making it more tolerant of old IE
When dom elem's CSS is queried with jQuery.css(), old IE (v8 and lower) doesn't return calculated values. Instead we get raw named values.
1 parent 4d69f46 commit 556133a

1 file changed

Lines changed: 25 additions & 4 deletions

File tree

jspdf.plugin.from_html.js

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -375,25 +375,46 @@ function ResolveFont(css_font_family_string){
375375
// return ratio to "normal" font size. in other words, it's fraction of 16 pixels.
376376
function ResolveUnitedNumber(css_line_height_string){
377377
var undef
378+
, normal = 16.00
378379
, value = UnitedNumberMap[css_line_height_string]
379380
if (value) {
380381
return value
381382
}
382383

384+
// not in cache, ok. need to parse it.
385+
386+
// Could it be a named value?
387+
// we will use Windows 94dpi sizing with CSS2 suggested 1.2 step ratio
388+
// where "normal" or "medium" is 16px
389+
// see: http://style.cleverchimp.com/font_size_intervals/altintervals.html
390+
value = ({
391+
'xx-small':9
392+
, 'x-small':11
393+
, 'small':13
394+
, 'medium':16
395+
, 'large':19
396+
, 'x-large':23
397+
, 'xx-large':28
398+
, 'auto':0
399+
})[css_line_height_string]
400+
if (value !== undef) {
401+
// caching, returning
402+
return UnitedNumberMap[css_line_height_string] = value / normal
403+
}
404+
383405
// not in cache, ok. need to parse it.
384406
// is it int?
385-
value = parseFloat(css_line_height_string)
386-
if (value) {
407+
if (value = parseFloat(css_line_height_string)) {
387408
// caching, returning
388-
return UnitedNumberMap[css_line_height_string] = value / 16.00
409+
return UnitedNumberMap[css_line_height_string] = value / normal
389410
}
390411

391412
// must be a "united" value ('123em', '134px' etc.)
392413
// most browsers convert it to px so, only handling the px
393414
value = css_line_height_string.match( /([\d\.]+)(px)/ )
394415
if (value.length === 3) {
395416
// caching, returning
396-
return UnitedNumberMap[css_line_height_string] = parseFloat( value[1] ) / 16.00
417+
return UnitedNumberMap[css_line_height_string] = parseFloat( value[1] ) / normal
397418
}
398419

399420
return UnitedNumberMap[css_line_height_string] = 1

0 commit comments

Comments
 (0)