Skip to content

Commit

Permalink
draft cell
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaasuni committed Nov 2, 2023
1 parent 8588a03 commit 30d4390
Showing 1 changed file with 56 additions and 22 deletions.
78 changes: 56 additions & 22 deletions src/Cell.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}

/**
Expand All @@ -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));
}
}

0 comments on commit 30d4390

Please sign in to comment.