Forum


Replies: 2   Views: 2786
Issue with calculating _wordmlunits: a non-numeric value encountered
Topic closed:
Please note this is an old forum thread. Information in this post may be out-to-date and/or erroneous.
Every phpdocx version includes new features and improvements. Previously unsupported features may have been added to newer releases, or past issues may have been corrected.
We encourage you to download the current phpdocx version and check the Documentation available.

Posted by admin  · 06-07-2017 - 11:39

Hello,

The dev team has checked your change. Although a null unit should happen, the best solution is returning a valid width and type if null:

// check if the unit is not set
if ($sHtmlUnit == null) {
    return(array(0, 'dxa'));
}

This is the whole method with the change applied:

    private function _wordMLUnits($sHtmlUnit, $fontSize = false)
    {
        // check if the unit is not set
        if ($sHtmlUnit == null) {
            return(array(0, 'dxa'));
        }

        if (!preg_match('/^(-?\d*\.?\d*)(%|em|pt|px)?$/i', trim($sHtmlUnit), $match)) {
            return(array(0, 'dxa'));
        }

        $match[1] = (strpos($match[1], '.') === 0 ? '0' : '') . $match[1];
        $match[2] = empty($match[2]) ? '' : $match[2];

        //if($match[2] != 'em' && $match[2] != 'px' && !empty($fontSize)) $match[2] = 'pt';

        switch ($match[2]) {
            case '%': //in WordML the precentage is given in fiftieths of a percent
                $widthType = 'pct';
                $width = 50 * $match[1];
                break;
            case 'em':
                $widthType = 'dxa';
                $width = 20 * $match[1] * $fontSize;
                break;
            case 'pt': //in WordML the width is given in twentieths of a point
                $widthType = 'dxa';
                $width = 20 * $match[1];
                break;
            case 'px': //a pixel is around 3/4 of a point
            default: //if no unit we asume is given in pixels
                $widthType = 'dxa';
                $width = 15 * $match[1];
        }

        return(array($width, $widthType));
    }

This change will be added in the next version of phpdocx.

Regards.