From 30d43906693b02f5f2845d9ee0c7be95da1f28ee Mon Sep 17 00:00:00 2001 From: nicolaasuni Date: Thu, 2 Nov 2023 11:26:12 +0000 Subject: [PATCH] draft cell --- src/Cell.php | 78 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 56 insertions(+), 22 deletions(-) diff --git a/src/Cell.php b/src/Cell.php index 2760e64..cd428e9 100644 --- a/src/Cell.php +++ b/src/Cell.php @@ -73,22 +73,6 @@ public function setDefaultCellPadding($top, $right, $bottom, $left) $this->defcell['padding']['L'] = $this->toPoints($left); } - /** - * Returns the minimum cell height in points for the current font. - * - * @param array $cell Optional to overwrite cell parameters for padding, margin etc. - * - * @return float - */ - protected function textCellMinHeight(array $cell = array()) - { - if (empty($cell)) { - $cell = $this->defcell; - } - $curfont = $this->font->getCurrentFont(); - return($curfont['height'] + $cell['padding']['T'] + $cell['padding']['B']); - } - /** * Increase the cell padding to account for the border tickness. * @@ -123,6 +107,41 @@ protected function adjustMinCellPadding(array $styles = array(), array $cell = a return $cell; } + /** + * Returns the minimum cell height in points for the current font. + * + * @param string $align Text vertical alignment inside the cell: + * - T=top; + * - C=center; + * - B=bottom; + * - A=center-on-font-ascent; + * - L=center-on-font-baseline; + * - D=center-on-font-descent. + * @param array $cell Optional to overwrite cell parameters for padding, margin etc. + * + * @return float + */ + protected function textCellMinHeight($align = 'C', array $cell = array()) + { + if (empty($cell)) { + $cell = $this->defcell; + } + $curfont = $this->font->getCurrentFont(); + switch ($align) { + default: + case 'C': // Center + case 'T': // Top + case 'B': // Bottom + return ($cell['padding']['T'] + $curfont['height'] + $cell['padding']['B']); + case 'L': // Center on font Baseline + return ($cell['padding']['T'] + $curfont['height'] + $curfont['midpoint'] + $cell['padding']['B']); + case 'A': // Center on font Ascent + case 'D': // Center on font Descent + return ($cell['padding']['T'] + (2 * $curfont['height']) + $cell['padding']['B']); + } + } + + /** * Returns the cell top-left Y coordinate to account for margins. * @@ -155,12 +174,17 @@ protected function cellVPos($pnty, $pheight, $align = 'T', array $cell = array() * * @param float $pheight Cell height in internal points. * @param string $align Text vertical alignment inside the cell: - * T=top; C=center; B=bottom; A=ascent; L=baseline; D=descent. + * - T=top; + * - C=center; + * - B=bottom; + * - A=center-on-font-ascent; + * - L=center-on-font-baseline; + * - D=center-on-font-descent. * @param array $cell Optional to overwrite cell parameters for padding, margin etc. * * @return float */ - protected function cellTextAlignment($pheight, $align = 'C', array $cell = array()) + protected function cellTextVAlign($pheight, $align = 'C', array $cell = array()) { if (empty($cell)) { $cell = $this->defcell; @@ -189,14 +213,19 @@ protected function cellTextAlignment($pheight, $align = 'C', array $cell = array * @param float $txty Text baseline top Y coordinate in internal points. * @param float $pheight Cell height in internal points. * @param string $align Text vertical alignment inside the cell: - * T=top; C=center; B=bottom; A=ascent; L=baseline; D=descent. + * - T=top; + * - C=center; + * - B=bottom; + * - A=center-on-font-ascent; + * - L=center-on-font-baseline; + * - D=center-on-font-descent. * @param array $cell Optional to overwrite cell parameters for padding, margin etc. * * @return float */ protected function cellVPosFromText($txty, $pheight, $align = 'C', array $cell = array()) { - return ($txty + $this->cellTextAlignment($pheight, $align, $cell)); + return ($txty + $this->cellTextVAlign($pheight, $align, $cell)); } /** @@ -205,13 +234,18 @@ protected function cellVPosFromText($txty, $pheight, $align = 'C', array $cell = * @param float $pnty Cell top Y coordinate in internal points. * @param float $pheight Cell height in internal points. * @param string $align Text vertical alignment inside the cell: - * T=top; C=center; B=bottom; A=ascent; L=baseline; D=descent. + * - T=top; + * - C=center; + * - B=bottom; + * - A=center-on-font-ascent; + * - L=center-on-font-baseline; + * - D=center-on-font-descent. * @param array $cell Optional to overwrite cell parameters for padding, margin etc. * * @return float */ protected function textVPosFromCell($pnty, $pheight, $align = 'C', array $cell = array()) { - return ($pnty - $this->cellTextAlignment($pheight, $align, $cell)); + return ($pnty - $this->cellTextVAlign($pheight, $align, $cell)); } }