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
This commit is contained in:
parent
ddec5e9706
commit
59ef7c3325
|
@ -199,7 +199,6 @@ class PHPExcel_Shared_Font
|
||||||
if (!in_array($pValue,self::$_autoSizeMethods)) {
|
if (!in_array($pValue,self::$_autoSizeMethods)) {
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
self::$autoSizeMethod = $pValue;
|
self::$autoSizeMethod = $pValue;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@ -241,8 +240,6 @@ class PHPExcel_Shared_Font
|
||||||
return self::$trueTypeFontPath;
|
return self::$trueTypeFontPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static $columnWidthAdjust;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Calculate an (approximate) OpenXML column width, based on font size and text contained
|
* 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
|
// Try to get the exact text width in pixels
|
||||||
$approximate = self::$autoSizeMethod == self::AUTOSIZE_METHOD_APPROX;
|
$approximate = self::$autoSizeMethod == self::AUTOSIZE_METHOD_APPROX;
|
||||||
if (!$approximate) {
|
if (!$approximate) {
|
||||||
if (is_null(self::$columnWidthAdjust)) {
|
$columnWidthAdjust = ceil(self::getTextWidthPixelsExact('n', $font, 0) * 1.07);
|
||||||
self::$columnWidthAdjust = ceil(self::getTextWidthPixelsExact('0', $font, 0) * 1.07);
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
// Width of text in pixels excl. padding
|
// 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) {
|
} catch (PHPExcel_Exception $e) {
|
||||||
$approximate == true;
|
$approximate == true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($approximate) {
|
if ($approximate) {
|
||||||
if (is_null(self::$columnWidthAdjust)) {
|
$columnWidthAdjust = self::getTextWidthPixelsApprox('n', $font, 0);
|
||||||
self::$columnWidthAdjust = self::getTextWidthPixelsApprox('n', $font, 0);
|
|
||||||
}
|
|
||||||
// Width of text in pixels excl. padding, approximation
|
// Width of text in pixels excl. padding, approximation
|
||||||
// and addition because Excel adds some padding, just use approx width of 'n' glyph
|
// 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
|
// Convert from pixel width to column width
|
||||||
|
|
Loading…
Reference in New Issue