krot

Excel width calculation

Oct 26th, 2017
76
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  /**
  2.      * @param mixed $value
  3.      * @param Font  $font
  4.      * @return float
  5.      */
  6.     public function getRenderedCellWidth($value, Font $font)
  7.     {
  8.         $box = imageftbbox($font->getSize(), 0, $this->getFontPath($font), $value);
  9.         $pixels = abs($box[4] - $box[0]);
  10.         $width = round(($pixels + 5) / 7, 3);
  11.  
  12.         return $width + 0.7;
  13.     }
  14.  
  15.     /**
  16.      * @param Font $font
  17.      * @return string
  18.      */
  19.     public function getFontPath(Font $font)
  20.     {
  21.         return __DIR__ . '/fonts/' . $this->fontMap[$font->getName()] . '.ttf';
  22.     }
RAW Paste Data