예제 #1
0
 public function generateContents($page = 1)
 {
     $INDEXPAGE_ROWS = $this::INDEXPAGE_ROWS - 44;
     $this->category = "Содержание";
     if ($this->format == 'A4' && $this->print) {
         $this->margins = array('top' => 34, 'right' => 64, 'bottom' => 34, 'left' => 44);
     } else {
         $this->margins = array('top' => 20, 'right' => 50, 'bottom' => 20, 'left' => 30);
     }
     if ($page % 2 == 0) {
         $this->margins = $this->swapMargins($this->margins);
     }
     $categoryIndexModel = new Model_DbTable_CategoryIndex();
     $indexes = $categoryIndexModel->getAdapter()->fetchAll("SELECT c.name AS name, ci.page AS page, ci.category_id as category_id, ci.depth as depth FROM categories AS c INNER JOIN categoryIndex AS ci ON ci.category_id = c.id ORDER BY ci.page, ci.depth");
     $page = $this->createBook($page, false);
     $colWidth = $page->getWidth();
     $pointWidth = $page->widthForStringUsingFontsize('.', Model_Static_Fonts::get('Arial Narrow'), $this->format == 'A4' ? 9.0 : 4.5);
     for ($p = 0; $p < intval(count($indexes) / $INDEXPAGE_ROWS + 1); $p++) {
         $page->setFont(Model_Static_Fonts::get('Arial Narrow'), $this->format == 'A4' ? 9.0 : 4.5);
         $page->setFillColor(new Zend_Pdf_Color_Html("#000000"));
         for ($row = 0; $row < $INDEXPAGE_ROWS; $row++) {
             $productIndex = (object) $indexes[$p * $INDEXPAGE_ROWS + $row];
             /* write */
             if (!trim($productIndex->name)) {
                 continue;
             }
             $curColWidth = $colWidth - $page->widthForStringUsingFontsize($productIndex->page, Model_Static_Fonts::get('Arial Narrow'), $this->format == 'A4' ? 9.0 : 4.5);
             switch ($productIndex->depth) {
                 case 0:
                     $nameFont = 'Arial Narrow Bold';
                     $page->setFillColor(new Zend_Pdf_Color_Html("#ef7900"));
                     break;
                 case 1:
                     $nameFont = 'Arial Narrow Bold';
                     $page->setFillColor(new Zend_Pdf_Color_Html("#000000"));
                     break;
                 case 2:
                 default:
                     $nameFont = 'Arial Narrow';
                     $page->setFillColor(new Zend_Pdf_Color_Html("#000000"));
                     break;
             }
             // append `.` to page
             $page->setFont(Model_Static_Fonts::get($nameFont), $this->format == 'A4' ? 9.0 : 4.5);
             $textWidth = $page->widthForStringUsingFontsize($productIndex->name, Model_Static_Fonts::get($nameFont), $this->format == 'A4' ? 9.0 : 4.5);
             $points = str_repeat(chr('0x2E'), intval(($curColWidth - $textWidth - intval($productIndex->depth * 10)) / 2 - 5));
             $page->drawTextBlock($productIndex->name, intval($productIndex->depth * 10), $page->getHeight() - $row * 9);
             $page->setFont(Model_Static_Fonts::get('Arial Narrow'), $this->format == 'A4' ? 9.0 : 4.5);
             $page->setFillColor(new Zend_Pdf_Color_Html("#000000"));
             $page->drawTextBlock($points, $textWidth + $productIndex->depth * 10, $page->getHeight() - $row * 9);
             $page->drawTextBlock($productIndex->page, $curColWidth, $page->getHeight() - $row * 9);
         }
         $page->drawCategory($this->category);
         $page->drawSideIcons("A");
         $page = $this->addPage(false);
     }
     return $this->book;
 }
예제 #2
0
 /**
  * Get maximal width of table column
  *
  * @param array[][] $table Table
  * @used-by $this::drawTable()
  *
  * @return array[] max widths
  */
 private function getTableColumnsMaxWidths($table, $params = false)
 {
     $widths = array();
     if (count($table) != 1) {
         foreach ($table[0] as $col) {
             $widths[] = 0;
         }
     }
     foreach ($table as $j => $rowset) {
         foreach ($rowset as $i => $col) {
             if ($j == 0 && count($table) != 1) {
                 continue;
             }
             if ($params) {
                 if (count($rowset) <= 10) {
                     $widths[$i] = max(array($this->widthForStringUsingFontsize(trim($col), Model_Static_Fonts::get("Arial Narrow"), $this->fontSizeFormat) + 20, $widths[$i]));
                 } else {
                     $widths[$i] = max(array($this->widthForStringUsingFontsize(trim($col), Model_Static_Fonts::get("Arial Narrow"), $this->fontSizeFormat) + 5, $widths[$i]));
                 }
             } else {
                 $widths[$i] = max(array($this->widthForStringUsingFontsize(trim($col), Model_Static_Fonts::get("Arial Narrow"), $this->fontSizeFormatDiscription) + 15, $widths[$i]));
             }
         }
     }
     return $widths;
 }