저자: Steffen Zeidler (sigma_z@web.de)
예제 #1
0
파일: Wmf.php 프로젝트: naivists/PHPUnit
 /**
  * code for parsing the wmf is originally from: http://www.fpdf.de/downloads/addons/55/
  * as an addon for FPDF, written by Martin HALL-MAY
  */
 private function setImageDimension()
 {
     $headerSize = $this->getHeaderSize();
     fseek($this->_stream, $headerSize);
     while (!feof($this->_stream)) {
         $recordInfo = unpack('Lsize/Sfunc', fread($this->_stream, 6));
         // size of record given in WORDs (= 2 bytes)
         $size = $recordInfo['size'];
         // func is number of GDI function
         $func = $recordInfo['func'];
         // parameters are read as one block and processed
         // as necessary by the case statement below.
         // the data are stored in little-endian format and are unpacked using:
         // s - signed 16-bit int
         // S - unsigned 16-bit int (or WORD)
         // L - unsigned 32-bit int (or DWORD)
         // NB. parameters to GDI functions are stored in reverse order
         // however structures are not reversed,
         // e.g. POINT { int x, int y } where x=3000 (0x0BB8) and y=-1200 (0xFB50)
         // is stored as B8 0B 50 FB
         if ($size > 3) {
             $params = fread($this->_stream, 2 * ($size - 3));
         }
         switch ($func) {
             case 0x20c:
                 // SetWindowExt
                 $sizes = array_reverse(unpack('s2', $params));
                 $this->setImageWidth(PHPRtfLite_Unit::getPointsInTwips($sizes[0]));
                 $this->setImageHeight(PHPRtfLite_Unit::getPointsInTwips($sizes[1]));
                 return;
             case 0x0:
                 return;
         }
     }
 }
예제 #2
0
파일: Format.php 프로젝트: naivists/PHPUnit
 /**
  * constructor
  *
  * @param   integer     $size   size of border
  * @param   string      $color  color of border (example '#ff0000' or '#f00')
  * @param   string      $type   represented by class constants PHPRtfLite_Border_Format::TYPE_*<br>
  *   Possible values:<br>
  *     TYPE_SINGLE:     single (default)<br>
  *     TYPE_DOT:        dot<br>
  *     TYPE_DASH:       dash<br>
  *     TYPE_DOTDASH:    dotdash<br>
  * @param   float       $space  space between borders and the paragraph
  */
 public function __construct($size = 0, $color = null, $type = null, $space = 0)
 {
     $this->_size = $size * PHPRtfLite::SPACE_IN_POINTS;
     $this->_type = $type;
     $this->_color = $color;
     $this->_space = PHPRtfLite_Unit::getUnitInTwips($space);
 }
예제 #3
0
 /**
  * constructor
  *
  * @param   float       $size   size of border
  * @param   string      $color  color of border (example '#ff0000' or '#f00')
  * @param   string      $type   represented by class constants PHPRtfLite_Border_Format::TYPE_*<br>
  *   Possible values:<br>
  *     TYPE_SINGLE:     single (default)<br>
  *     TYPE_DOT:        dot<br>
  *     TYPE_DASH:       dash<br>
  *     TYPE_DOTDASH:    dotdash<br>
  * @param   float       $space  space between borders and the paragraph
  */
 public function __construct($size = 0.0, $color = null, $type = null, $space = 0.0)
 {
     $this->_size = round($size * PHPRtfLite::SPACE_IN_POINTS);
     // convert points to twips
     $this->_type = $type;
     $this->_color = $color;
     $this->_space = PHPRtfLite_Unit::getUnitInTwips($space);
 }
예제 #4
0
 /**
  * sets text indent
  *
  * @param   float   $indent
  */
 public function setTextIndent($indent)
 {
     $this->_textIndent = PHPRtfLite_Unit::getUnitInTwips($indent);
 }
예제 #5
0
 /**
  * streams rtf code for header/footer
  * @return string rtf code
  */
 public function render()
 {
     $stream = $this->_rtf->getWriter();
     if (isset($this->_offsetHeight)) {
         $stream->write('\\' . $this->getRtfType() . 'y' . PHPRtfLite_Unit::getUnitInTwips($this->_offsetHeight));
     }
     $stream->write('{\\' . $this->getTypeAsRtfCode() . ' ');
     parent::render();
     $containerElements = $this->getElements();
     if ($containerElements && $containerElements[count($containerElements) - 1] instanceof PHPRtfLite_Element) {
         $stream->write('\\par');
     }
     $stream->write('}' . "\r\n");
 }
예제 #6
0
 /**
  * prepares rtf contents
  */
 protected function render()
 {
     $this->_writer->open();
     $this->_writer->write('{\\rtf\\ansi\\deff0' . "\r\n");
     $this->_writer->write($this->getFontTable()->getContent());
     $this->_writer->write($this->getColorTable()->getContent());
     $this->_writer->write($this->getInfoPart());
     $paperWidth = $this->_paperWidth;
     $paperHeight = $this->_paperHeight;
     // page properties
     if ($this->_isLandscape) {
         $this->_writer->write('\\landscape ');
         if ($paperWidth < $paperHeight) {
             $tmp = $paperHeight;
             $paperHeight = $paperWidth;
             $paperWidth = $tmp;
         }
     }
     $this->_writer->write('\\paperw' . PHPRtfLite_Unit::getUnitInTwips($paperWidth) . ' ');
     $this->_writer->write('\\paperh' . PHPRtfLite_Unit::getUnitInTwips($paperHeight) . ' ');
     // hyphenation
     if ($this->_isHyphenation) {
         $this->_writer->write('\\hyphauto1');
     }
     $this->_writer->write('\\deftab' . PHPRtfLite_Unit::getUnitInTwips($this->_defaultTabWidth) . ' ');
     $this->_writer->write('\\margl' . PHPRtfLite_Unit::getUnitInTwips($this->_marginLeft) . ' ');
     $this->_writer->write('\\margr' . PHPRtfLite_Unit::getUnitInTwips($this->_marginRight) . ' ');
     $this->_writer->write('\\margt' . PHPRtfLite_Unit::getUnitInTwips($this->_marginTop) . ' ');
     $this->_writer->write('\\margb' . PHPRtfLite_Unit::getUnitInTwips($this->_marginBottom) . ' ');
     if (null !== $this->_gutter) {
         $this->_writer->write('\\gutter' . PHPRtfLite_Unit::getUnitInTwips($this->_gutter) . ' ');
     }
     if (true == $this->_useMirrorMargins) {
         $this->_writer->write('\\margmirror ');
     }
     if (null !== $this->_viewMode) {
         $this->_writer->write('\\viewkind' . $this->_viewMode . ' ');
     }
     if (null !== $this->_zoomMode) {
         $this->_writer->write('\\viewzk' . $this->_zoomMode . ' ');
     }
     if (null !== $this->_zoomLevel) {
         $this->_writer->write('\\viewscale' . $this->_zoomLevel . ' ');
     }
     if (isset($this->_sections[0]) && $this->_sections[0]->getBorder()) {
         $this->_writer->write($this->_sections[0]->getBorder()->getContent('\\pg'));
     } elseif ($this->_border) {
         $this->_writer->write($this->_border->getContent('\\pg'));
     }
     // page numbering start
     $this->_writer->write('\\pgnstart' . $this->_pageNumberStart);
     //headers and footers properties
     if ($this->_useOddEvenDifferent) {
         $this->_writer->write('\\facingp ');
     }
     if ($this->_titlepg) {
         $this->_writer->write('\\titlepg ');
     }
     // document header definition for footnotes and endnotes
     $this->_writer->write($this->getNoteDocHead()->getContent());
     //headers and footers if there are no sections
     if (count($this->_sections) == 0) {
         foreach ($this->_headers as $header) {
             $header->render();
         }
         foreach ($this->_footers as $footer) {
             $footer->render();
         }
     }
     //sections
     foreach ($this->_sections as $key => $section) {
         if ($key != 0) {
             $this->_writer->write('\\sect\\sectd ');
         }
         $section->render();
     }
     $this->_writer->write('}');
     $this->_writer->close();
 }
예제 #7
0
 /**
  * sets global unit
  *
  * @param string $unit
  */
 public static function setGlobalUnit($unit)
 {
     self::$_unit = $unit;
 }
예제 #8
0
 /**
  * renders row definition
  *
  * @param PHPRtfLite_Table_Row $row
  */
 public function renderRowDefinition(PHPRtfLite_Table_Row $row)
 {
     $rowIndex = $row->getRowIndex();
     $stream = $this->getRtf()->getWriter();
     $stream->write('\\trowd');
     if ($this->_alignment) {
         switch ($this->_alignment) {
             case self::ALIGN_CENTER:
                 $stream->write('\\trqc');
                 break;
             case self::ALIGN_RIGHT:
                 $stream->write('\\trqr');
                 break;
             default:
                 $stream->write('\\trql');
                 break;
         }
     }
     $rowHeight = $row->getHeight();
     if ($rowHeight) {
         $stream->write('\\trrh' . PHPRtfLite_Unit::getUnitInTwips($rowHeight));
     }
     if ($this->isPreventPageBreak()) {
         $stream->write('\\trkeep ');
     }
     if ($this->isFirstRowHeader() && $rowIndex == 1) {
         $stream->write('\\trhdr ');
     }
     if ($this->getLeftPosition() != '') {
         $stream->write('\\trleft' . PHPRtfLite_Unit::getUnitInTwips($this->getLeftPosition()) . ' ');
     }
     $width = 0;
     foreach ($this->getColumns() as $columnIndex => $column) {
         $cell = $this->getCell($rowIndex, $columnIndex + 1);
         // render cell definition
         if (!$cell->isHorizontalMerged()) {
             $cell->renderDefinition();
             // cell width
             $width += PHPRtfLite_Unit::getUnitInTwips($cell->getWidth());
             $stream->write('\\cellx' . $width);
         }
     }
 }
예제 #9
0
 /**
  * renders rtf code of section
  */
 public function render()
 {
     $stream = $this->_rtf->getWriter();
     //headers
     $headers = $this->_headers ? $this->_headers : $this->_rtf->getHeaders();
     if (!empty($headers)) {
         foreach ($headers as $header) {
             $header->render();
         }
     }
     //footers
     $footers = $this->_footers ? $this->_footers : $this->_rtf->getFooters();
     if (!empty($footers)) {
         foreach ($footers as $footer) {
             $footer->render();
         }
     }
     //borders
     $border = $this->_border ? $this->_border : $this->_rtf->getBorder();
     if ($border) {
         $stream->write($border->getContent('\\pg'));
     }
     //do not break within the section
     if ($this->_doNotBreak) {
         $stream->write('\\sbknone ');
     }
     //set column index, when using more than one column for this section
     if ($this->_numberOfColumns > 1) {
         $stream->write('\\cols' . $this->_numberOfColumns . ' ');
     }
     if (empty($this->_columnWidths)) {
         if ($this->_spaceBetweenColumns) {
             $stream->write('\\colsx' . PHPRtfLite_Unit::getUnitInTwips($this->_spaceBetweenColumns) . ' ');
         }
     } else {
         $width = 0;
         foreach ($this->_columnWidths as $value) {
             $width += PHPRtfLite_Unit::getUnitInTwips($value);
         }
         $printableWidth = $this->_rtf->getPaperWidth() - $this->_rtf->getMarginLeft() - $this->_rtf->getMarginRight();
         $space = round((PHPRtfLite_Unit::getUnitInTwips($printableWidth) - $width) / (count($this->_columnWidths) - 1));
         $i = 1;
         foreach ($this->_columnWidths as $key => $value) {
             $stream->write('\\colno' . $i . '\\colw' . PHPRtfLite_Unit::getUnitInTwips($value));
             if (!empty($this->_columnWidths[$key])) {
                 $stream->write('\\colsr' . $space);
             }
             $i++;
         }
         $stream->write(' ');
     }
     if ($this->_lineBetweenColumns) {
         $stream->write('\\linebetcol ');
     }
     /*---Page part---*/
     if ($this->_paperWidth) {
         $stream->write('\\pgwsxn' . PHPRtfLite_Unit::getUnitInTwips($this->_paperWidth) . ' ');
     }
     if ($this->_paperHeight) {
         $stream->write('\\pghsxn' . PHPRtfLite_Unit::getUnitInTwips($this->_paperHeight) . ' ');
     }
     if ($this->_marginLeft) {
         $stream->write('\\marglsxn' . PHPRtfLite_Unit::getUnitInTwips($this->_marginLeft) . ' ');
     }
     if ($this->_marginRight) {
         $stream->write('\\margrsxn' . PHPRtfLite_Unit::getUnitInTwips($this->_marginRight) . ' ');
     }
     if ($this->_marginTop) {
         $stream->write('\\margtsxn' . PHPRtfLite_Unit::getUnitInTwips($this->_marginTop) . ' ');
     }
     if ($this->_marginBottom) {
         $stream->write('\\margbsxn' . PHPRtfLite_Unit::getUnitInTwips($this->_marginBottom) . ' ');
     }
     if ($this->_gutter) {
         $stream->write('\\guttersxn' . PHPRtfLite_Unit::getUnitInTwips($this->_gutter) . ' ');
     }
     if ($this->_useMirrorMargins) {
         $stream->write('\\margmirsxn ');
     }
     $stream->write("\r\n");
     parent::render();
     $stream->write("\r\n");
 }
예제 #10
0
파일: Image.php 프로젝트: naivists/PHPUnit
 /**
  * gets rtf image height
  *
  * @return integer
  */
 private function getImageRtfHeight()
 {
     if ($this->_height > 0) {
         return PHPRtfLite_Unit::getUnitInTwips($this->_height);
     }
     $imageHeight = $this->_imageHeight ? $this->_imageHeight : 100;
     if ($this->_width > 0) {
         $imageWidth = $this->_imageWidth ? $this->_imageWidth : 100;
         $height = $imageHeight / $imageWidth * $this->_width;
         return PHPRtfLite_Unit::getUnitInTwips($height);
     }
     return PHPRtfLite_Unit::getPointsInTwips($imageHeight);
 }
예제 #11
0
 /**
  * renders cell definition
  */
 public function renderDefinition()
 {
     $stream = $this->_rtf->getWriter();
     if ($this->isVerticalMerged()) {
         if ($this->isVerticalMergedFirstInRange()) {
             $stream->write('\\clvmgf');
         } else {
             $stream->write('\\clvmrg');
         }
     }
     $backgroundColor = $this->getBackgroundColor();
     if ($backgroundColor) {
         $colorTable = $this->_rtf->getColorTable();
         $stream->write('\\clcbpat' . $colorTable->getColorIndex($backgroundColor) . ' ');
     }
     switch ($this->getVerticalAlignment()) {
         case self::VERTICAL_ALIGN_TOP:
             $stream->write('\\clvertalt');
             break;
         case self::VERTICAL_ALIGN_CENTER:
             $stream->write('\\clvertalc');
             break;
         case self::VERTICAL_ALIGN_BOTTOM:
             $stream->write('\\clvertalb');
             break;
     }
     switch ($this->getRotateTo()) {
         case self::ROTATE_RIGHT:
             $stream->write('\\cltxtbrl');
             break;
         case self::ROTATE_LEFT:
             $stream->write('\\cltxbtlr');
             break;
     }
     // NOTE: microsoft and all other rtf readers I know confound left with top cell padding
     if ($this->_paddingLeft) {
         $stream->write('\\clpadft3\\clpadt' . PHPRtfLite_Unit::getUnitInTwips($this->_paddingLeft) . ' ');
     }
     if ($this->_paddingTop) {
         $stream->write('\\clpadfl3\\clpadl' . PHPRtfLite_Unit::getUnitInTwips($this->_paddingTop) . ' ');
     }
     if ($this->_paddingBottom) {
         $stream->write('\\clpadfb3\\clpadb' . PHPRtfLite_Unit::getUnitInTwips($this->_paddingBottom) . ' ');
     }
     if ($this->_paddingRight) {
         $stream->write('\\clpadfr3\\clpadr' . PHPRtfLite_Unit::getUnitInTwips($this->_paddingRight) . ' ');
     }
     $border = $this->getBorder();
     if ($border) {
         $stream->write($border->getContent('\\cl'));
     }
 }
예제 #12
0
 /**
  * gets rtf code of paragraph
  *
  * @return  string  rtf code
  */
 public function getContent()
 {
     $content = '';
     switch ($this->_alignment) {
         case self::TEXT_ALIGN_RIGHT:
             $content .= '\\qr ';
             break;
         case self::TEXT_ALIGN_CENTER:
             $content .= '\\qc ';
             break;
         case self::TEXT_ALIGN_JUSTIFY:
             $content .= '\\qj ';
             break;
         default:
             $content .= '\\ql ';
             break;
     }
     if ($this->_indentFirstLine != 0) {
         $content .= '\\fi' . PHPRtfLite_Unit::getUnitInTwips($this->_indentFirstLine) . ' ';
     }
     if ($this->_indentLeft > 0) {
         $content .= '\\li' . PHPRtfLite_Unit::getUnitInTwips($this->_indentLeft) . ' ';
     }
     if ($this->_indentRight > 0) {
         $content .= '\\ri' . PHPRtfLite_Unit::getUnitInTwips($this->_indentRight) . ' ';
     }
     if ($this->_spaceBefore > 0) {
         $content .= '\\sb' . $this->_spaceBefore . ' ';
     }
     if ($this->_spaceAfter > 0) {
         $content .= '\\sa' . $this->_spaceAfter . ' ';
     }
     if ($this->_spaceBetweenLines > 0) {
         $content .= '\\sl' . $this->_spaceBetweenLines . ' ';
     }
     if ($this->_border) {
         $content .= $this->_border->getContent('\\');
     }
     if ($this->_shading > 0) {
         $content .= '\\shading' . $this->_shading . ' ';
     }
     if ($this->_backgroundColor && $this->_colorTable) {
         $colorIndex = $this->_colorTable->getColorIndex($this->_backgroundColor);
         if ($colorIndex !== false) {
             $content .= '\\cbpat' . $colorIndex . ' ';
         }
     }
     return $content;
 }