Skip to content

Commit cee531d

Browse files
committed
Merge remote-tracking branch 'slusarz/unit_fix'
2 parents 3e6b053 + 607e65b commit cee531d

File tree

1 file changed

+14
-24
lines changed

1 file changed

+14
-24
lines changed

lib/Sabberworm/CSS/Parser.php

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -385,32 +385,22 @@ private function parseNumericValue($bForColor = false) {
385385
}
386386
}
387387
$fSize = floatval($sSize);
388+
388389
$sUnit = null;
389-
if ($this->comes('%')) {
390-
$sUnit = $this->consume('%');
391-
} else if ($this->comes('em')) {
392-
$sUnit = $this->consume('em');
393-
} else if ($this->comes('ex')) {
394-
$sUnit = $this->consume('ex');
395-
} else if ($this->comes('px')) {
396-
$sUnit = $this->consume('px');
397-
} else if ($this->comes('deg')) {
398-
$sUnit = $this->consume('deg');
399-
} else if ($this->comes('s')) {
400-
$sUnit = $this->consume('s');
401-
} else if ($this->comes('cm')) {
402-
$sUnit = $this->consume('cm');
403-
} else if ($this->comes('pt')) {
404-
$sUnit = $this->consume('pt');
405-
} else if ($this->comes('in')) {
406-
$sUnit = $this->consume('in');
407-
} else if ($this->comes('pc')) {
408-
$sUnit = $this->consume('pc');
409-
} else if ($this->comes('cm')) {
410-
$sUnit = $this->consume('cm');
411-
} else if ($this->comes('mm')) {
412-
$sUnit = $this->consume('mm');
390+
$units = array(
391+
'%', 'em', 'ex', 'px', 'deg', 's', 'cm', 'pt', 'in', 'pc', 'cm',
392+
'mm',
393+
// These are non "size" values, but they are still numeric
394+
'deg', 'grad', 'rad', 'turns', 's', 'ms', 'Hz', 'kHz'
395+
);
396+
397+
foreach ($units as $val) {
398+
if ($this->comes($val)) {
399+
$sUnit = $this->consume($val);
400+
break;
401+
}
413402
}
403+
414404
return new Size($fSize, $sUnit, $bForColor);
415405
}
416406

0 commit comments

Comments
 (0)