diff --git a/lib/Sabberworm/CSS/Parser.php b/lib/Sabberworm/CSS/Parser.php index ccbba6ae2..f3d05331e 100644 --- a/lib/Sabberworm/CSS/Parser.php +++ b/lib/Sabberworm/CSS/Parser.php @@ -385,32 +385,22 @@ private function parseNumericValue($bForColor = false) { } } $fSize = floatval($sSize); + $sUnit = null; - if ($this->comes('%')) { - $sUnit = $this->consume('%'); - } else if ($this->comes('em')) { - $sUnit = $this->consume('em'); - } else if ($this->comes('ex')) { - $sUnit = $this->consume('ex'); - } else if ($this->comes('px')) { - $sUnit = $this->consume('px'); - } else if ($this->comes('deg')) { - $sUnit = $this->consume('deg'); - } else if ($this->comes('s')) { - $sUnit = $this->consume('s'); - } else if ($this->comes('cm')) { - $sUnit = $this->consume('cm'); - } else if ($this->comes('pt')) { - $sUnit = $this->consume('pt'); - } else if ($this->comes('in')) { - $sUnit = $this->consume('in'); - } else if ($this->comes('pc')) { - $sUnit = $this->consume('pc'); - } else if ($this->comes('cm')) { - $sUnit = $this->consume('cm'); - } else if ($this->comes('mm')) { - $sUnit = $this->consume('mm'); + $units = array( + '%', 'em', 'ex', 'px', 'deg', 's', 'cm', 'pt', 'in', 'pc', 'cm', + 'mm', + // These are non "size" values, but they are still numeric + 'deg', 'grad', 'rad', 'turns', 's', 'ms', 'Hz', 'kHz' + ); + + foreach ($units as $val) { + if ($this->comes($val)) { + $sUnit = $this->consume($val); + break; + } } + return new Size($fSize, $sUnit, $bForColor); }