Exemplo n.º 1
0
 /**
  * @group ZF-9450
  */
 public function testUnescapeOctal()
 {
     $input = array(0304 => '\\304', 0326 => '\\326', 0334 => '\\334');
     foreach ($input as $k => $v) {
         $this->assertEquals(Zend_Pdf_Element_String::unescape($v), chr($k), 'expected German Umlaut');
     }
 }
Exemplo n.º 2
0
 /**
  * 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 Zend_Pdf_Exception
  * @return Zend_Pdf_Page
  */
 public function drawText($text, $x, $y, $charEncoding = '')
 {
     if ($this->_font === null) {
         //require_once 'Zend/Pdf/Exception.php';
         throw new Zend_Pdf_Exception('Font has not been set');
     }
     $this->_addProcSet('Text');
     $textObj = new Zend_Pdf_Element_String($this->_font->encodeString($text, $charEncoding));
     $xObj = new Zend_Pdf_Element_Numeric($x);
     $yObj = new Zend_Pdf_Element_Numeric($y);
     $this->_contents .= "BT\n" . $xObj->toString() . ' ' . $yObj->toString() . " Td\n" . $textObj->toString() . " Tj\n" . "ET\n";
     return $this;
 }
Exemplo n.º 3
0
 /**
  * Read string PDF object
  * Also reads trailing ')' from a pdf stream
  *
  * @return Zend_Pdf_Element_String
  * @throws Zend_Pdf_Exception
  */
 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) {
         require_once 'Zend/Pdf/Exception.php';
         throw new Zend_Pdf_Exception(sprintf('PDF file syntax error. Unexpected end of file while string reading. Offset - 0x%X. \')\' expected.', $start));
     }
     return new Zend_Pdf_Element_String(Zend_Pdf_Element_String::unescape(substr($this->data, $start, $this->offset - $start - 1)));
 }
Exemplo n.º 4
0
 /**
  * Draw a line of text at the specified position.
  *
  * @param string $text
  * @param float $x
  * @param float $y
  * @throws Zend_Pdf_Exception
  */
 public function drawText($text, $x, $y)
 {
     if ($this->_font === null) {
         throw new Zend_Pdf_Exception('Font has not been set');
     }
     $this->_addProcSet('Text');
     $textObj = new Zend_Pdf_Element_String($text);
     $xObj = new Zend_Pdf_Element_Numeric($x);
     $yObj = new Zend_Pdf_Element_Numeric($y);
     $this->_contents .= "BT\n" . $xObj->toString() . ' ' . $yObj->toString() . " Td\n" . $textObj->toString() . " Tj\n" . "ET\n";
 }
Exemplo n.º 5
0
 public function testUnescape()
 {
     $this->assertEquals(Zend_Pdf_Element_String::unescape("\\n\\r\\t\\b\\f\\(\\)\\\\  \nsome \\\ntext"), "\n\r\t\f()\\  \nsome text");
 }
Exemplo n.º 6
0
 /**
  * Read string PDF object
  * Also reads trailing ')' from a pdf stream
  *
  * @return Zend_Pdf_Element_String
  * @throws Zend_Pdf_Exception
  */
 private function _readString()
 {
     $start = $this->_current;
     $openedBrackets = 1;
     while ($this->_current < strlen($this->_pdfString)) {
         switch (ord($this->_pdfString[$this->_current])) {
             case 0x28:
                 // '(' - opened bracket in the string, needs balanced pair.
                 $openedBrackets++;
                 break;
             case 0x29:
                 // ')' - pair to the opened bracket
                 $openedBrackets--;
                 break;
             case 0x5c:
                 // '\\' - escape sequence, skip next char from a check
                 $this->_current++;
         }
         $this->_current++;
         if ($openedBrackets == 0) {
             break;
             // end of string
         }
     }
     if ($openedBrackets != 0) {
         throw new Zend_Pdf_Exception(sprintf('PDF file syntax error. Unexpected end of file while string reading. Offset - 0x%X. \')\' expected.', $start));
     }
     return new Zend_Pdf_Element_String(Zend_Pdf_Element_String::unescape(substr($this->_pdfString, $start, $this->_current - $start - 1)));
 }
Exemplo n.º 7
0
 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:
                 $this->offset++;
                 $openedBrackets++;
                 break;
             case 0x29:
                 $this->offset++;
                 $openedBrackets--;
                 break;
             case 0x5c:
                 $this->offset += 2;
         }
         if ($openedBrackets == 0) {
             break;
         }
         $this->offset += strcspn($this->data, '()\\', $this->offset);
     }
     if ($openedBrackets != 0) {
         throw new Zend_Pdf_Exception(sprintf('PDF file syntax error. Unexpected end of file while string reading. Offset - 0x%X. \')\' expected.', $start));
     }
     return new Zend_Pdf_Element_String(Zend_Pdf_Element_String::unescape(substr($this->data, $start, $this->offset - $start - 1)));
 }