Permalink
Browse files

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.
  • Loading branch information...
Daniel Dotsenko
Daniel Dotsenko committed Nov 1, 2012
1 parent 4d69f46 commit 556133afc56feedecb7ad50655bb198b4ce0ab17
Showing with 25 additions and 4 deletions.
  1. +25 −4 jspdf.plugin.from_html.js
View
@@ -375,25 +375,46 @@ function ResolveFont(css_font_family_string){
// return ratio to "normal" font size. in other words, it's fraction of 16 pixels.
function ResolveUnitedNumber(css_line_height_string){
var undef
+ , normal = 16.00
, value = UnitedNumberMap[css_line_height_string]
if (value) {
return value
}
+ // not in cache, ok. need to parse it.
+
+ // Could it be a named value?
+ // we will use Windows 94dpi sizing with CSS2 suggested 1.2 step ratio
+ // where "normal" or "medium" is 16px
+ // see: http://style.cleverchimp.com/font_size_intervals/altintervals.html
+ value = ({
+ 'xx-small':9
+ , 'x-small':11
+ , 'small':13
+ , 'medium':16
+ , 'large':19
+ , 'x-large':23
+ , 'xx-large':28
+ , 'auto':0
+ })[css_line_height_string]
+ if (value !== undef) {
+ // caching, returning
+ return UnitedNumberMap[css_line_height_string] = value / normal
+ }
+
// not in cache, ok. need to parse it.
// is it int?
- value = parseFloat(css_line_height_string)
- if (value) {
+ if (value = parseFloat(css_line_height_string)) {
// caching, returning
- return UnitedNumberMap[css_line_height_string] = value / 16.00
+ return UnitedNumberMap[css_line_height_string] = value / normal
}
// must be a "united" value ('123em', '134px' etc.)
// most browsers convert it to px so, only handling the px
value = css_line_height_string.match( /([\d\.]+)(px)/ )
if (value.length === 3) {
// caching, returning
- return UnitedNumberMap[css_line_height_string] = parseFloat( value[1] ) / 16.00
+ return UnitedNumberMap[css_line_height_string] = parseFloat( value[1] ) / normal
}
return UnitedNumberMap[css_line_height_string] = 1

0 comments on commit 556133a

Please sign in to comment.