/** * @group ZF-9450 */ public function testUnescapeOctal() { $input = array(0304 => '\\304', 0326 => '\\326', 0334 => '\\334'); foreach ($input as $k => $v) { $this->assertEquals(InternalType\StringObject::unescape($v), chr($k), 'expected German Umlaut'); } }
/** * Draw a line of text at the specified position. * * @param string $text * @param float $x * @param float $y * @param string $charEncoding (optional) Character encoding of source text. * Defaults to current locale. * @throws \ZendPdf\Exception\ExceptionInterface * @return \ZendPdf\Page */ public function drawText($text, $x, $y, $charEncoding = '') { if ($this->_font === null) { throw new Exception\LogicException('Font has not been set'); } $this->_addProcSet('Text'); $textObj = new InternalType\StringObject($this->_font->encodeString($text, $charEncoding)); $xObj = new InternalType\NumericObject($x); $yObj = new InternalType\NumericObject($y); $this->_contents .= "BT\n" . $xObj->toString() . ' ' . $yObj->toString() . " Td\n" . $textObj->toString() . " Tj\n" . "ET\n"; return $this; }
/** * @param ZendPage $page * @param string $text * @param float $x * @param float $y * @param int $renderMode * * @return ZendPage */ private function drawRawText(ZendPage $page, $text, $x, $y, $renderMode = 0) { $textObj = new ZendStringObject($text); $xObj = new ZendNumericObject($x); $yObj = new ZendNumericObject($y); $rObj = new ZendNumericObject($renderMode); $content = "BT\n" . $xObj->toString() . ' ' . $yObj->toString() . " Td\n" . (0 === $renderMode ? '' : $rObj->toString() . " Tr\n") . $textObj->toString() . " Tj\n" . "ET\n"; return $page->rawWrite($content, 'Text'); }
/** * Read string PDF object * Also reads trailing ')' from a pdf stream * * @return \ZendPdf\InternalType\StringObject * @throws \ZendPdf\Exception\ExceptionInterface */ private function _readString() { $start = $this->offset; $openedBrackets = 1; $this->offset += strcspn($this->data, '()\\', $this->offset); while ($this->offset < strlen($this->data)) { switch (ord($this->data[$this->offset])) { case 0x28: // '(' - opened bracket in the string, needs balanced pair. $this->offset++; $openedBrackets++; break; case 0x29: // ')' - pair to the opened bracket $this->offset++; $openedBrackets--; break; case 0x5c: // '\\' - escape sequence, skip next char from a check $this->offset += 2; } if ($openedBrackets == 0) { break; // end of string } $this->offset += strcspn($this->data, '()\\', $this->offset); } if ($openedBrackets != 0) { throw new Exception\CorruptedPdfException(sprintf('PDF file syntax error. Unexpected end of file while string reading. Offset - 0x%X. \')\' expected.', $start)); } return new InternalType\StringObject(InternalType\StringObject::unescape(substr($this->data, $start, $this->offset - $start - 1))); }