From 59ef7c3325f27a8fbf705ceaba46d94d26c15740 Mon Sep 17 00:00:00 2001 From: MarkBaker Date: Thu, 3 Jul 2014 01:01:39 +0100 Subject: [PATCH] Don't cache column width adjustment, because it should be based on the font size being used for a cell, and so should be dynamic --- Classes/PHPExcel/Shared/Font.php | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/Classes/PHPExcel/Shared/Font.php b/Classes/PHPExcel/Shared/Font.php index 2ded245..ee0702e 100644 --- a/Classes/PHPExcel/Shared/Font.php +++ b/Classes/PHPExcel/Shared/Font.php @@ -199,7 +199,6 @@ class PHPExcel_Shared_Font if (!in_array($pValue,self::$_autoSizeMethods)) { return FALSE; } - self::$autoSizeMethod = $pValue; return TRUE; @@ -241,8 +240,6 @@ class PHPExcel_Shared_Font return self::$trueTypeFontPath; } - private static $columnWidthAdjust; - /** * Calculate an (approximate) OpenXML column width, based on font size and text contained * @@ -271,24 +268,21 @@ class PHPExcel_Shared_Font // Try to get the exact text width in pixels $approximate = self::$autoSizeMethod == self::AUTOSIZE_METHOD_APPROX; if (!$approximate) { - if (is_null(self::$columnWidthAdjust)) { - self::$columnWidthAdjust = ceil(self::getTextWidthPixelsExact('0', $font, 0) * 1.07); - } + $columnWidthAdjust = ceil(self::getTextWidthPixelsExact('n', $font, 0) * 1.07); try { // Width of text in pixels excl. padding - $columnWidth = self::getTextWidthPixelsExact($cellText, $font, $rotation) + self::$columnWidthAdjust; + // and addition because Excel adds some padding, just use approx width of 'n' glyph + $columnWidth = self::getTextWidthPixelsExact($cellText, $font, $rotation) + $columnWidthAdjust; } catch (PHPExcel_Exception $e) { $approximate == true; } } if ($approximate) { - if (is_null(self::$columnWidthAdjust)) { - self::$columnWidthAdjust = self::getTextWidthPixelsApprox('n', $font, 0); - } + $columnWidthAdjust = self::getTextWidthPixelsApprox('n', $font, 0); // Width of text in pixels excl. padding, approximation // and addition because Excel adds some padding, just use approx width of 'n' glyph - $columnWidth = self::getTextWidthPixelsApprox($cellText, $font, $rotation) + self::$columnWidthAdjust; + $columnWidth = self::getTextWidthPixelsApprox($cellText, $font, $rotation) + $columnWidthAdjust; } // Convert from pixel width to column width