Skip to content

Commit

Permalink
draft cell class
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolaasuni committed Nov 2, 2023
1 parent c0dc40e commit 8588a03
Show file tree
Hide file tree
Showing 7 changed files with 151 additions and 140 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
8.0.37
8.0.39
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"tecnickcom/tc-lib-barcode": "^1.18",
"tecnickcom/tc-lib-color": "^1.14",
"tecnickcom/tc-lib-pdf-image": "^1.4",
"tecnickcom/tc-lib-pdf-font": "^1.15",
"tecnickcom/tc-lib-pdf-font": "^1.16",
"tecnickcom/tc-lib-file": "^1.7",
"tecnickcom/tc-lib-pdf-encrypt": "^1.6",
"tecnickcom/tc-lib-unicode-data": "^1.7",
Expand Down
2 changes: 1 addition & 1 deletion resources/debian/control
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ Vcs-Git: https://github.com/~#VENDOR#~/~#PROJECT#~.git
Package: ~#PKGNAME#~
Provides: php-~#PROJECT#~
Architecture: all
Depends: php (>= 5.4.0), php-date, php-tecnickcom-tc-lib-barcode (<< 2.0.0), php-tecnickcom-tc-lib-barcode (>= 1.18.3), php-tecnickcom-tc-lib-color (<< 2.0.0), php-tecnickcom-tc-lib-color (>= 1.14.38), php-tecnickcom-tc-lib-pdf-image (<< 2.0.0), php-tecnickcom-tc-lib-pdf-image (>= 1.4.19), php-tecnickcom-tc-lib-pdf-font (<< 2.0.0), php-tecnickcom-tc-lib-pdf-font (>= 1.15.10), php-tecnickcom-tc-lib-file (<< 2.0.0), php-tecnickcom-tc-lib-file (>= 1.7.38), php-tecnickcom-tc-lib-pdf-encrypt (<< 2.0.0), php-tecnickcom-tc-lib-pdf-encrypt (>= 1.6.34), php-tecnickcom-tc-lib-unicode-data (<< 2.0.0), php-tecnickcom-tc-lib-unicode-data (>= 1.7.32), php-tecnickcom-tc-lib-unicode (<< 2.0.0), php-tecnickcom-tc-lib-unicode (>= 1.4.32), php-tecnickcom-tc-lib-pdf-page (<< 3.0.0), php-tecnickcom-tc-lib-pdf-page (>= 3.2.10), php-tecnickcom-tc-lib-pdf-graph (<< 2.0.0), php-tecnickcom-tc-lib-pdf-graph (>= 1.7.22), ${misc:Depends}
Depends: php (>= 5.4.0), php-date, php-tecnickcom-tc-lib-barcode (<< 2.0.0), php-tecnickcom-tc-lib-barcode (>= 1.18.4), php-tecnickcom-tc-lib-color (<< 2.0.0), php-tecnickcom-tc-lib-color (>= 1.14.39), php-tecnickcom-tc-lib-pdf-image (<< 2.0.0), php-tecnickcom-tc-lib-pdf-image (>= 1.4.20), php-tecnickcom-tc-lib-pdf-font (<< 2.0.0), php-tecnickcom-tc-lib-pdf-font (>= 1.16.1), php-tecnickcom-tc-lib-file (<< 2.0.0), php-tecnickcom-tc-lib-file (>= 1.7.39), php-tecnickcom-tc-lib-pdf-encrypt (<< 2.0.0), php-tecnickcom-tc-lib-pdf-encrypt (>= 1.6.35), php-tecnickcom-tc-lib-unicode-data (<< 2.0.0), php-tecnickcom-tc-lib-unicode-data (>= 1.7.33), php-tecnickcom-tc-lib-unicode (<< 2.0.0), php-tecnickcom-tc-lib-unicode (>= 1.4.33), php-tecnickcom-tc-lib-pdf-page (<< 3.0.0), php-tecnickcom-tc-lib-pdf-page (>= 3.2.11), php-tecnickcom-tc-lib-pdf-graph (<< 2.0.0), php-tecnickcom-tc-lib-pdf-graph (>= 1.7.23), ${misc:Depends}
Description: PHP Barcode library
This library includes PHP classes to generate PDF documents.
20 changes: 10 additions & 10 deletions resources/rpm/rpm.spec
Original file line number Diff line number Diff line change
Expand Up @@ -20,25 +20,25 @@ Requires: php(language) >= 5.4.0
Requires: php-date
Requires: php-pcre
Requires: php-composer(%{c_vendor}/tc-lib-barcode) < 2.0.0
Requires: php-composer(%{c_vendor}/tc-lib-barcode) >= 1.18.3
Requires: php-composer(%{c_vendor}/tc-lib-barcode) >= 1.18.4
Requires: php-composer(%{c_vendor}/tc-lib-color) < 2.0.0
Requires: php-composer(%{c_vendor}/tc-lib-color) >= 1.14.38
Requires: php-composer(%{c_vendor}/tc-lib-color) >= 1.14.39
Requires: php-composer(%{c_vendor}/tc-lib-pdf-image) < 2.0.0
Requires: php-composer(%{c_vendor}/tc-lib-pdf-image) >= 1.4.19
Requires: php-composer(%{c_vendor}/tc-lib-pdf-image) >= 1.4.20
Requires: php-composer(%{c_vendor}/tc-lib-pdf-font) < 2.0.0
Requires: php-composer(%{c_vendor}/tc-lib-pdf-font) >= 1.15.10
Requires: php-composer(%{c_vendor}/tc-lib-pdf-font) >= 1.16.1
Requires: php-composer(%{c_vendor}/tc-lib-file) < 2.0.0
Requires: php-composer(%{c_vendor}/tc-lib-file) >= 1.7.38
Requires: php-composer(%{c_vendor}/tc-lib-file) >= 1.7.39
Requires: php-composer(%{c_vendor}/tc-lib-pdf-encrypt) < 2.0.0
Requires: php-composer(%{c_vendor}/tc-lib-pdf-encrypt) >= 1.6.34
Requires: php-composer(%{c_vendor}/tc-lib-pdf-encrypt) >= 1.6.35
Requires: php-composer(%{c_vendor}/tc-lib-unicode-data) < 2.0.0
Requires: php-composer(%{c_vendor}/tc-lib-unicode-data) >= 1.7.32
Requires: php-composer(%{c_vendor}/tc-lib-unicode-data) >= 1.7.33
Requires: php-composer(%{c_vendor}/tc-lib-unicode) < 2.0.0
Requires: php-composer(%{c_vendor}/tc-lib-unicode) >= 1.4.32
Requires: php-composer(%{c_vendor}/tc-lib-unicode) >= 1.4.33
Requires: php-composer(%{c_vendor}/tc-lib-pdf-page) < 3.0.0
Requires: php-composer(%{c_vendor}/tc-lib-pdf-page) >= 3.2.10
Requires: php-composer(%{c_vendor}/tc-lib-pdf-page) >= 3.2.11
Requires: php-composer(%{c_vendor}/tc-lib-pdf-graph) < 2.0.0
Requires: php-composer(%{c_vendor}/tc-lib-pdf-graph) >= 1.7.22
Requires: php-composer(%{c_vendor}/tc-lib-pdf-graph) >= 1.7.23

Provides: php-composer(%{c_vendor}/%{gh_project}) = %{version}
Provides: php-%{gh_project} = %{version}
Expand Down
54 changes: 54 additions & 0 deletions src/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -409,4 +409,58 @@ abstract class Base
* @var array
*/
protected $xobjects = array();

/**
* Convert user units to internal points unit.
*
* @param float $usr Value to convert.
*
* @return float
*/
public function toPoints($usr)
{
return ((float) $usr * $this->kunit);
}

/**
* Convert internal points to user unit.
*
* @param float $pnt Value to convert in user units.
*
* @return float
*/
public function toUnit($pnt)
{
return ((float) $pnt / $this->kunit);
}

/**
* Convert vertical user value to internal points unit.
* Note: the internal Y points coordinate starts at the bottom left of the page.
*
* @param float $usr Value to convert.
* @param float $pageh Optional page height in internal points ($pageh:$this->page->getPage()['pheight']).
*
* @return float
*/
public function toYPoints($usr, $pageh = -1)
{
$pageh = $pageh >= 0 ? $pageh : $this->page->getPage()['pheight'];
return ($pageh - $this->toPoints($usr));
}

/**
* Convert vertical internal points value to user unit.
* Note: the internal Y points coordinate starts at the bottom left of the page.
*
* @param float $pnt Value to convert.
* @param float $pageh Optional page height in internal points ($pageh:$this->page->getPage()['pheight']).
*
* @return float
*/
public function toYUnit($pnt, $pageh = -1)
{
$pageh = $pageh >= 0 ? $pageh : $this->page->getPage()['pheight'];
return ($pageh - $this->toUnit($pnt));
}
}
205 changes: 81 additions & 124 deletions src/Cell.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,60 +41,6 @@ abstract class Cell extends \Com\Tecnick\Pdf\Base
'padding' => array('T' => 0, 'R' => 0, 'B' => 0, 'L' => 0)
);

/**
* Convert user units to internal points unit.
*
* @param float $usr Value to convert.
*
* @return float
*/
public function toPoints($usr)
{
return ((float) $usr * $this->kunit);
}

/**
* Convert internal points to user unit.
*
* @param float $pnt Value to convert in user units.
*
* @return float
*/
public function toUnit($pnt)
{
return ((float) $pnt / $this->kunit);
}

/**
* Convert vertical user value to internal points unit.
* Note: the internal Y points coordinate starts at the bottom left of the page.
*
* @param float $usr Value to convert.
* @param float $pageh Optional page height in internal points ($pageh:$this->page->getPage()['pheight']).
*
* @return float
*/
public function toYPoints($usr, $pageh = -1)
{
$pageh = $pageh >= 0 ? $pageh : $this->page->getPage()['pheight'];
return ($pageh - $this->toPoints($usr));
}

/**
* Convert vertical internal points value to user unit.
* Note: the internal Y points coordinate starts at the bottom left of the page.
*
* @param float $pnt Value to convert.
* @param float $pageh Optional page height in internal points ($pageh:$this->page->getPage()['pheight']).
*
* @return float
*/
public function toYUnit($pnt, $pageh = -1)
{
$pageh = $pageh >= 0 ? $pageh : $this->page->getPage()['pheight'];
return ($pageh - $this->toUnit($pnt));
}

/**
* Set the default cell margin in user units.
*
Expand Down Expand Up @@ -128,133 +74,144 @@ public function setDefaultCellPadding($top, $right, $bottom, $left)
}

/**
* Returns the cell top-left Y coordinate.
* Returns the minimum cell height in points for the current font.
*
* @param float $pnty Y coordinate in internal points.
* @param float $pheight Cell height in internal points.
* @param string $align Cell vertical alignment: T=top; C=center; B=bottom.
* @param array $cell Optional cell parameters for padding, margin etc.
* @param array $cell Optional to overwrite cell parameters for padding, margin etc.
*
* @return float
*/
protected function cellVertAlign($pnty, $pheight, $align = 'T', array $cell = array())
protected function textCellMinHeight(array $cell = array())
{
if (empty($cell)) {
$cell = $this->defcell;
}
// cell vertical alignment
switch ($align) {
case 'T': // Top
return ($pnty - $cell['margin']['T']);
case 'C': // Center
return ($pnty + (($cell['margin']['T'] + $pheight + $cell['margin']['B']) / 2));
case 'B': // Bottom
return ($pnty + $cell['margin']['B'] + $pheight);
$curfont = $this->font->getCurrentFont();
return($curfont['height'] + $cell['padding']['T'] + $cell['padding']['B']);
}

/**
* Increase the cell padding to account for the border tickness.
*
* @param array $styles Optional to overwrite the styles (see: getCurrentStyleArray).
* @param array $cell Optional to overwrite cell parameters for padding, margin etc.
*
* @return array
*/
protected function adjustMinCellPadding(array $styles = array(), array $cell = array())
{
if (empty($cell)) {
$cell = $this->defcell;
}
return $pnty;
if (empty($styles)) {
$styles = $this->graph->getCurrentStyleArray();
}
$minT = $minR = $minB = $minL = 0;
if (!empty($styles['all']['lineWidth'])) {
$minT = $minR = $minB = $minL = $this->toPoints($styles['all']['lineWidth']);
} elseif (count($styles) == 4) {
$minT = $this->toPoints($styles[0]['lineWidth']);
$minR = $this->toPoints($styles[1]['lineWidth']);
$minB = $this->toPoints($styles[2]['lineWidth']);
$minL = $this->toPoints($styles[3]['lineWidth']);
} else {
return $cell;
}
$cell['padding']['T'] = max($cell['padding']['T'], $minT);
$cell['padding']['R'] = max($cell['padding']['R'], $minR);
$cell['padding']['B'] = max($cell['padding']['B'], $minB);
$cell['padding']['L'] = max($cell['padding']['L'], $minL);
return $cell;
}

/**
* Returns the top-left Y coordinate for the text inside the cell.
* Returns the cell top-left Y coordinate to account for margins.
*
* @param float $pnty 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.
* @param array $cell Optional cell parameters for padding, margin etc.
* @param float $pnty Starting top Y coordinate in internal points.
* @param float $pheight Cell height in internal points.
* @param string $align Cell vertical alignment: T=top; C=center; B=bottom.
* @param array $cell Optional to overwrite cell parameters for padding, margin etc.
*
* @return float
*/
protected function cellTextVertAlign($pnty, $pheight, $align = 'T', array $cell = array())
protected function cellVPos($pnty, $pheight, $align = 'T', array $cell = array())
{
if (empty($cell)) {
$cell = $this->defcell;
}
$curfont = $this->font->getCurrentFont();
// cell vertical alignment
switch ($align) {
case 'T': // Top
return ($pnty - $cell['padding']['T']);
return ($pnty - $cell['margin']['T']);
case 'C': // Center
return ($pnty - (($pheight - $curfont['ascent'] - $curfont['descent']) / 2));
return ($pnty + (($cell['margin']['T'] + $pheight + $cell['margin']['B']) / 2));
case 'B': // Bottom
return ($pnty - $pheight + $cell['padding']['B'] + $curfont['ascent'] + $curfont['descent']);
return ($pnty + $cell['margin']['B'] + $pheight);
}
return $pnty;
}

/**
* Returns the top-left Y coordinate for the cell containing the text.
* Returns the vertical distance between the cell top-left corner and the text baseline.
*
* @param float $pnty Y coordinate in internal points of the text.
* @param float $pheight Cell height in internal points.
* @param string $align Text vertical alignment inside the cell: T=top; C=center; B=bottom.
* @param array $cell Optional cell parameters for padding, margin etc.
* @param string $align Text vertical alignment inside the cell:
* T=top; C=center; B=bottom; A=ascent; L=baseline; D=descent.
* @param array $cell Optional to overwrite cell parameters for padding, margin etc.
*
* @return float
*/
protected function textCellVertAlign($pnty, $pheight, $align = 'T', array $cell = array())
protected function cellTextAlignment($pheight, $align = 'C', array $cell = array())
{
if (empty($cell)) {
$cell = $this->defcell;
}
$curfont = $this->font->getCurrentFont();
switch ($align) {
case 'T': // Top
return ($pnty + $cell['padding']['T']);
default:
case 'C': // Center
return ($pnty + (($pheight - $curfont['ascent'] - $curfont['descent']) / 2));
return ($curfont['midpoint'] + ($pheight / 2));
case 'T': // Top
return ($curfont['ascent'] + $cell['padding']['T']);
case 'B': // Bottom
return ($pnty + $pheight - $cell['padding']['B'] - $curfont['ascent'] - $curfont['descent']);
return ($curfont['descent'] - $cell['padding']['B'] + $pheight);
case 'L': // Center on font Baseline
return ($pheight / 2);
case 'A': // Center on font Ascent
return ($curfont['ascent'] + ($pheight / 2));
case 'D': // Center on font Descent
return ($curfont['descent'] + ($pheight / 2));
}
return $pnty;
}

/**
* Returns the cell minimum height in points for the current font.
* Returns the top-left Y coordinate of the cell wrapping the text.
*
* @param array $cell Optional cell parameters for padding, margin etc.
* @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.
* @param array $cell Optional to overwrite cell parameters for padding, margin etc.
*
* @return float
*/
protected function textCellMinHeight(array $cell = array())
protected function cellVPosFromText($txty, $pheight, $align = 'C', array $cell = array())
{
if (empty($cell)) {
$cell = $this->defcell;
}
$curfont = $this->font->getCurrentFont();
return($curfont['ascent'] + $curfont['descent'] + $cell['padding']['T'] + $cell['padding']['B']);
return ($txty + $this->cellTextAlignment($pheight, $align, $cell));
}

/**
* Increase the cell padding to account for the border tickness.
* Returns the baseline Y coordinate of the text inside the cell.
*
* @param array $styles Array of styles - one style entry for each side (T,R,B,L) and/or one global "all" entry.
* @param array $cell Optional cell parameters for padding, margin etc.
* @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.
* @param array $cell Optional to overwrite cell parameters for padding, margin etc.
*
* @return array
* @return float
*/
protected function adjustMinCellPadding(array $styles = array(), array $cell = array())
protected function textVPosFromCell($pnty, $pheight, $align = 'C', array $cell = array())
{
if (empty($cell)) {
$cell = $this->defcell;
}
if (empty($styles)) {
$styles = $this->graph->getCurrentStyleArray();
}
$minT = $minR = $minB = $minL = 0;
if (!empty($styles['all']['lineWidth'])) {
$minT = $minR = $minB = $minL = $this->toPoints($styles['all']['lineWidth']);
} elseif (count($styles) == 4) {
$minT = $this->toPoints($styles[0]['lineWidth']);
$minR = $this->toPoints($styles[1]['lineWidth']);
$minB = $this->toPoints($styles[2]['lineWidth']);
$minL = $this->toPoints($styles[3]['lineWidth']);
} else {
return $cell;
}
$cell['padding']['T'] = max($cell['padding']['T'], $minT);
$cell['padding']['R'] = max($cell['padding']['R'], $minR);
$cell['padding']['B'] = max($cell['padding']['B'], $minB);
$cell['padding']['L'] = max($cell['padding']['L'], $minL);
return $cell;
return ($pnty - $this->cellTextAlignment($pheight, $align, $cell));
}
}
Loading

0 comments on commit 8588a03

Please sign in to comment.