Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

alter font size+callback #94

Open
pvidalis opened this issue Jan 22, 2018 · 1 comment
Open

alter font size+callback #94

pvidalis opened this issue Jan 22, 2018 · 1 comment

Comments

@pvidalis
Copy link

pvidalis commented Jan 22, 2018

Hi,
I'm trying find a way to alter text font size in a table cell. I created a callback which is used but can't make the font change its size.
Any help will be appreciated.

`///Wrapper Class to generate pdf reports
class CSpdf extends Cezpdf {

public function __construct($paper = 'a4', $orientation = 'portrait', $type = 'none', $options = array()) {
	parent::__construct($paper, $orientation, $type, $options);
	$this->allowedTags .= '|fontsize:?.*?';
	$this->isUnicode   = true;
	$this->fontPath    = dirname(__FILE__).'/fonts';

	// select a font and use font subsetting
	$aFontSubset = array(
		'b' => 'Arial-Unicode-Bold.ttf',
		'i' => 'Arial-Unicode-Italic.ttf',
		'bi' => 'Arial-Unicode-Bold-Italic.ttf',
		'ib' => 'Arial-Unicode-Bold-Italic.ttf'
	);
	$this->setFontFamily('Arial-Unicode-Regular', $aFontSubset);
	$this->selectFont('Arial-Unicode-Regular.ttf');		
}

/**
 * callback function to alter font height text.
 *
 * **Example**<br>
 * <pre>
 * $pdf->ezText('<c:fontsize:10>Sample Text</c:fontsize>');
 * </pre>
 *
 * @param $info
 */
public function fontsize($info) {
	switch($info['status']) {
		case 'start':
			//$this->saveState();
			//addTextWrap($x, $y, $size, $text, $width = 0, $justification = 'left', $angle = 0, $wordSpaceAdjust = 0, $test = 0)
			//addText($x, $y, $size, $text, $width, $justification, $angle, $wordSpaceAdjust, $test);
			$this->ez['fontSize'] = $info['p'];
			$this->addText($info['x'], $info['y'], $info['p'], '');
			//$this->selectFont($this->cs_fontpath.'/'.$this->currentFont);
			break;
		case 'end':
			$this->ez['fontSize'] = $info['p'];
			//$this->selectFont($this->cs_fontpath.'/'.$this->currentFont);
			//$this->restoreState();
			break;
		case 'sol':
		case 'eol':
			break;
		default:
			break;
	}
}

}`

Report

`$cols = array();
$data[] = array('test', 'testingasda', '<c:fontsize:8>test8</c:fontsize>', '');

$aParams = array(
'xPos' => 'left',
'xOrientation' => 'right',
'showLines' => 0,
'fontSize' => $report_textsize,
'showHeadings' => 1,
'shaded' => 0,
'shadeCol2' => array(0.9, 0.9, 0.9),
'width' => 555,
'cols' => array(
0 => array('justification' => 'right')));
$pdf->ezTable($data, $cols, '', $aParams);
`

@savioret
Copy link

It seems that the addText function which calls the callbacks already holds a copy of the $size of the text.
This means that no matter what you change on the ez['fontSize'] as the addText will apply the local $size parameter provided to the addText function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants