📄 page.php
字号:
*/
public function extractFont($fontName)
{
if ($this->_pageDictionary->Resources->Font === null) {
// Page doesn't have any font attached
return null;
}
$fontResources = $this->_pageDictionary->Resources->Font;
foreach ($fontResources->getKeys() as $fontResourceName) {
$fontDictionary = $fontResources->$fontResourceName;
if (! ($fontDictionary instanceof Zend_Pdf_Element_Reference ||
$fontDictionary instanceof Zend_Pdf_Element_Object) ) {
// Font dictionary has to be an indirect object or object reference
continue;
}
if ($fontDictionary->BaseFont->value != $fontName) {
continue;
}
try {
// Try to extract font
return new Zend_Pdf_Resource_Font_Extracted($fontDictionary);
} catch (Zend_Pdf_Exception $e) {
if ($e->getMessage() != 'Unsupported font type.') {
throw $e;
}
// Continue searhing font with specified name
}
}
return null;
}
/** * Get current font size * * @return float $fontSize */ public function getFontSize() { return $this->_fontSize; } /** * Return the style, applied to the page. * * @return Zend_Pdf_Style|null */ public function getStyle() { return $this->_style; } /** * Save the graphics state of this page. * This takes a snapshot of the currently applied style, position, clipping area and * any rotation/translation/scaling that has been applied. * * @todo check for the open paths * @throws Zend_Pdf_Exception - if a save is performed with an open path */ public function saveGS() { $this->_saveCount++; $this->_addProcSet('PDF'); $this->_contents .= " q\n"; } /** * Restore the graphics state that was saved with the last call to saveGS(). * * @throws Zend_Pdf_Exception - if there is no previously saved state */ public function restoreGS() { if ($this->_saveCount-- <= 0) { throw new Zend_Pdf_Exception('Restoring graphics state which is not saved'); } $this->_contents .= " Q\n"; } /** * Intersect current clipping area with a circle. * * @param float $x * @param float $y * @param float $radius * @param float $startAngle * @param float $endAngle */ public function clipCircle($x, $y, $radius, $startAngle = null, $endAngle = null) { $this->clipEllipse($x - $radius, $y - $radius, $x + $radius, $y + $radius, $startAngle, $endAngle); } /** * Intersect current clipping area with a polygon. * * Method signatures: * drawEllipse($x1, $y1, $x2, $y2); * drawEllipse($x1, $y1, $x2, $y2, $startAngle, $endAngle); * * @todo process special cases with $x2-$x1 == 0 or $y2-$y1 == 0 * * @param float $x1 * @param float $y1 * @param float $x2 * @param float $y2 * @param float $startAngle * @param float $endAngle */ public function clipEllipse($x1, $y1, $x2, $y2, $startAngle = null, $endAngle = null) { $this->_addProcSet('PDF'); if ($x2 < $x1) { $temp = $x1; $x1 = $x2; $x2 = $temp; } if ($y2 < $y1) { $temp = $y1; $y1 = $y2; $y2 = $temp; } $x = ($x1 + $x2)/2.; $y = ($y1 + $y2)/2.; $xC = new Zend_Pdf_Element_Numeric($x); $yC = new Zend_Pdf_Element_Numeric($y); if ($startAngle !== null) { if ($startAngle != 0) { $startAngle = fmod($startAngle, M_PI*2); } if ($endAngle != 0) { $endAngle = fmod($endAngle, M_PI*2); } if ($startAngle > $endAngle) { $endAngle += M_PI*2; } $clipPath = $xC->toString() . ' ' . $yC->toString() . " m\n"; $clipSectors = (int)ceil(($endAngle - $startAngle)/M_PI_4); $clipRadius = max($x2 - $x1, $y2 - $y1); for($count = 0; $count <= $clipSectors; $count++) { $pAngle = $startAngle + ($endAngle - $startAngle)*$count/(float)$clipSectors; $pX = new Zend_Pdf_Element_Numeric($x + cos($pAngle)*$clipRadius); $pY = new Zend_Pdf_Element_Numeric($y + sin($pAngle)*$clipRadius); $clipPath .= $pX->toString() . ' ' . $pY->toString() . " l\n"; } $this->_contents .= $clipPath . "h\nW\nn\n"; } $xLeft = new Zend_Pdf_Element_Numeric($x1); $xRight = new Zend_Pdf_Element_Numeric($x2); $yUp = new Zend_Pdf_Element_Numeric($y2); $yDown = new Zend_Pdf_Element_Numeric($y1); $xDelta = 2*(M_SQRT2 - 1)*($x2 - $x1)/3.; $yDelta = 2*(M_SQRT2 - 1)*($y2 - $y1)/3.; $xr = new Zend_Pdf_Element_Numeric($x + $xDelta); $xl = new Zend_Pdf_Element_Numeric($x - $xDelta); $yu = new Zend_Pdf_Element_Numeric($y + $yDelta); $yd = new Zend_Pdf_Element_Numeric($y - $yDelta); $this->_contents .= $xC->toString() . ' ' . $yUp->toString() . " m\n" . $xr->toString() . ' ' . $yUp->toString() . ' ' . $xRight->toString() . ' ' . $yu->toString() . ' ' . $xRight->toString() . ' ' . $yC->toString() . " c\n" . $xRight->toString() . ' ' . $yd->toString() . ' ' . $xr->toString() . ' ' . $yDown->toString() . ' ' . $xC->toString() . ' ' . $yDown->toString() . " c\n" . $xl->toString() . ' ' . $yDown->toString() . ' ' . $xLeft->toString() . ' ' . $yd->toString() . ' ' . $xLeft->toString() . ' ' . $yC->toString() . " c\n" . $xLeft->toString() . ' ' . $yu->toString() . ' ' . $xl->toString() . ' ' . $yUp->toString() . ' ' . $xC->toString() . ' ' . $yUp->toString() . " c\n" . "h\nW\nn\n"; } /** * Intersect current clipping area with a polygon. * * @param array $x - array of float (the X co-ordinates of the vertices) * @param array $y - array of float (the Y co-ordinates of the vertices) * @param integer $fillMethod */ public function clipPolygon($x, $y, $fillMethod = Zend_Pdf_Page::FILL_METHOD_NON_ZERO_WINDING) { $this->_addProcSet('PDF'); $firstPoint = true; foreach ($x as $id => $xVal) { $xObj = new Zend_Pdf_Element_Numeric($xVal); $yObj = new Zend_Pdf_Element_Numeric($y[$id]); if ($firstPoint) { $path = $xObj->toString() . ' ' . $yObj->toString() . " m\n"; $firstPoint = false; } else { $path .= $xObj->toString() . ' ' . $yObj->toString() . " l\n"; } } $this->_contents .= $path; if ($fillMethod == Zend_Pdf_Page::FILL_METHOD_NON_ZERO_WINDING) { $this->_contents .= " h\n W\n"; } else { // Even-Odd fill method. $this->_contents .= " h\n W*\n"; } } /** * Intersect current clipping area with a rectangle. * * @param float $x1 * @param float $y1 * @param float $x2 * @param float $y2 */ public function clipRectangle($x1, $y1, $x2, $y2) { $this->_addProcSet('PDF'); $x1Obj = new Zend_Pdf_Element_Numeric($x1); $y1Obj = new Zend_Pdf_Element_Numeric($y1); $widthObj = new Zend_Pdf_Element_Numeric($x2 - $x1); $height2Obj = new Zend_Pdf_Element_Numeric($y2 - $y1); $this->_contents .= $x1Obj->toString() . ' ' . $y1Obj->toString() . ' ' . $widthObj->toString() . ' ' . $height2Obj->toString() . " re\n" . " W\n"; } /** * Draw a Zend_Pdf_ContentStream at the specified position on the page * * @param ZPdfContentStream $cs * @param float $x1 * @param float $y1 * @param float $x2 * @param float $y2 */ public function drawContentStream($cs, $x1, $y1, $x2, $y2) { } /** * Draw a circle centered on x, y with a radius of radius. * * Method signatures: * drawCircle($x, $y, $radius); * drawCircle($x, $y, $radius, $fillType); * drawCircle($x, $y, $radius, $startAngle, $endAngle); * drawCircle($x, $y, $radius, $startAngle, $endAngle, $fillType); * * * It's not a really circle, because PDF supports only cubic Bezier curves. * But _very_ good approximation. * It differs from a real circle on a maximum 0.00026 radiuses * (at PI/8, 3*PI/8, 5*PI/8, 7*PI/8, 9*PI/8, 11*PI/8, 13*PI/8 and 15*PI/8 angles). * At 0, PI/4, PI/2, 3*PI/4, PI, 5*PI/4, 3*PI/2 and 7*PI/4 it's exactly a tangent to a circle. * * @param float $x * @param float $y * @param float $radius * @param mixed $param4 * @param mixed $param5 * @param mixed $param6 */ public function drawCircle($x, $y, $radius, $param4 = null, $param5 = null, $param6 = null) { $this->drawEllipse($x - $radius, $y - $radius, $x + $radius, $y + $radius, $param4, $param5, $param6); } /** * Draw an ellipse inside the specified rectangle. * * Method signatures: * drawEllipse($x1, $y1, $x2, $y2); * drawEllipse($x1, $y1, $x2, $y2, $fillType); * drawEllipse($x1, $y1, $x2, $y2, $startAngle, $endAngle); * drawEllipse($x1, $y1, $x2, $y2, $startAngle, $endAngle, $fillType); * * @todo process special cases with $x2-$x1 == 0 or $y2-$y1 == 0 * * @param float $x1 * @param float $y1 * @param float $x2 * @param float $y2 * @param mixed $param5 * @param mixed $param6 * @param mixed $param7 */ public function drawEllipse($x1, $y1, $x2, $y2, $param5 = null, $param6 = null, $param7 = null) { if ($param5 === null) { // drawEllipse($x1, $y1, $x2, $y2); $startAngle = null; $fillType = Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE; } else if ($param6 === null) { // drawEllipse($x1, $y1, $x2, $y2, $fillType); $startAngle = null; $fillType = $param5; } else { // drawEllipse($x1, $y1, $x2, $y2, $startAngle, $endAngle); // drawEllipse($x1, $y1, $x2, $y2, $startAngle, $endAngle, $fillType); $startAngle = $param5; $endAngle = $param6; if ($param7 === null) { $fillType = Zend_Pdf_Page::SHAPE_DRAW_FILL_AND_STROKE; } else { $fillType = $param7; } } $this->_addProcSet('PDF'); if ($x2 < $x1) { $temp = $x1; $x1 = $x2; $x2 = $temp; } if ($y2 < $y1) { $temp = $y1; $y1 = $y2; $y2 = $temp; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -