コード例 #1
0
ファイル: Font.php プロジェクト: bestgoodz/toko-baju
 /**
  * Get font record data
  *
  * @return string
  */
 public function writeFont()
 {
     $font_outline = 0;
     $font_shadow = 0;
     $icv = $this->_colorIndex;
     // Index to color palette
     if ($this->_font->getSuperScript()) {
         $sss = 1;
     } else {
         if ($this->_font->getSubScript()) {
             $sss = 2;
         } else {
             $sss = 0;
         }
     }
     $bFamily = 0;
     // Font family
     $bCharSet = Shared_Font::getCharsetFromFontName($this->_font->getName());
     // Character set
     $record = 0x31;
     // Record identifier
     $reserved = 0x0;
     // Reserved
     $grbit = 0x0;
     // Font attributes
     if ($this->_font->getItalic()) {
         $grbit |= 0x2;
     }
     if ($this->_font->getStrikethrough()) {
         $grbit |= 0x8;
     }
     if ($font_outline) {
         $grbit |= 0x10;
     }
     if ($font_shadow) {
         $grbit |= 0x20;
     }
     if ($this->_BIFFVersion == 0x500) {
         $data = pack("vvvvvCCCCC", $this->_font->getSize() * 20, $grbit, $icv, $this->_mapBold($this->_font->getBold()), $sss, $this->_mapUnderline($this->_font->getUnderline()), $bFamily, $bCharSet, $reserved, strlen($this->_font->getName()));
         $data .= $this->_font->getName();
     } elseif ($this->_BIFFVersion == 0x600) {
         $data = pack("vvvvvCCCC", $this->_font->getSize() * 20, $grbit, $icv, $this->_mapBold($this->_font->getBold()), $sss, $this->_mapUnderline($this->_font->getUnderline()), $bFamily, $bCharSet, $reserved);
         $data .= Shared_String::UTF8toBIFF8UnicodeShort($this->_font->getName());
     }
     $length = strlen($data);
     $header = pack("vv", $record, $length);
     return $header . $data;
 }
コード例 #2
0
ファイル: Style.php プロジェクト: bestgoodz/toko-baju
 /**
  * Create a new Style
  *
  * @param boolean $isSupervisor
  */
 public function __construct($isSupervisor = false)
 {
     // Supervisor?
     $this->_isSupervisor = $isSupervisor;
     // Initialise values
     $this->_conditionalStyles = array();
     $this->_font = new Style_Font($isSupervisor);
     $this->_fill = new Style_Fill($isSupervisor);
     $this->_borders = new Style_Borders($isSupervisor);
     $this->_alignment = new Style_Alignment($isSupervisor);
     $this->_numberFormat = new Style_NumberFormat($isSupervisor);
     $this->_protection = new Style_Protection($isSupervisor);
     // bind parent if we are a supervisor
     if ($isSupervisor) {
         $this->_font->bindParent($this);
         $this->_fill->bindParent($this);
         $this->_borders->bindParent($this);
         $this->_alignment->bindParent($this);
         $this->_numberFormat->bindParent($this);
         $this->_protection->bindParent($this);
     }
 }
コード例 #3
0
ファイル: Excel5.php プロジェクト: bestgoodz/toko-baju
 /**
  * Read a FONT record
  */
 private function _readFont()
 {
     $length = $this->_GetInt2d($this->_data, $this->_pos + 2);
     $recordData = substr($this->_data, $this->_pos + 4, $length);
     // move stream pointer to next record
     $this->_pos += 4 + $length;
     if (!$this->_readDataOnly) {
         $objFont = new Style_Font();
         // offset: 0; size: 2; height of the font (in twips = 1/20 of a point)
         $size = $this->_GetInt2d($recordData, 0);
         $objFont->setSize($size / 20);
         // offset: 2; size: 2; option flags
         // bit: 0; mask 0x0001; bold (redundant in BIFF5-BIFF8)
         // bit: 1; mask 0x0002; italic
         $isItalic = (0x2 & $this->_GetInt2d($recordData, 2)) >> 1;
         if ($isItalic) {
             $objFont->setItalic(true);
         }
         // bit: 2; mask 0x0004; underlined (redundant in BIFF5-BIFF8)
         // bit: 3; mask 0x0008; strike
         $isStrike = (0x8 & $this->_GetInt2d($recordData, 2)) >> 3;
         if ($isStrike) {
             $objFont->setStrikethrough(true);
         }
         // offset: 4; size: 2; colour index
         $colorIndex = $this->_GetInt2d($recordData, 4);
         $objFont->colorIndex = $colorIndex;
         // offset: 6; size: 2; font weight
         $weight = $this->_GetInt2d($recordData, 6);
         switch ($weight) {
             case 0x2bc:
                 $objFont->setBold(true);
                 break;
         }
         // offset: 8; size: 2; escapement type
         $escapement = $this->_GetInt2d($recordData, 8);
         switch ($escapement) {
             case 0x1:
                 $objFont->setSuperScript(true);
                 break;
             case 0x2:
                 $objFont->setSubScript(true);
                 break;
         }
         // offset: 10; size: 1; underline type
         $underlineType = ord($recordData[10]);
         switch ($underlineType) {
             case 0x0:
                 break;
                 // no underline
             // no underline
             case 0x1:
                 $objFont->setUnderline(Style_Font::UNDERLINE_SINGLE);
                 break;
             case 0x2:
                 $objFont->setUnderline(Style_Font::UNDERLINE_DOUBLE);
                 break;
             case 0x21:
                 $objFont->setUnderline(Style_Font::UNDERLINE_SINGLEACCOUNTING);
                 break;
             case 0x22:
                 $objFont->setUnderline(Style_Font::UNDERLINE_DOUBLEACCOUNTING);
                 break;
         }
         // offset: 11; size: 1; font family
         // offset: 12; size: 1; character set
         // offset: 13; size: 1; not used
         // offset: 14; size: var; font name
         if ($this->_version == self::XLS_BIFF8) {
             $string = $this->_readUnicodeStringShort(substr($recordData, 14));
         } else {
             $string = $this->_readByteStringShort(substr($recordData, 14));
         }
         $objFont->setName($string['value']);
         $this->_objFonts[] = $objFont;
     }
 }
コード例 #4
0
ファイル: Run.php プロジェクト: bestgoodz/toko-baju
 /**
  * Get hash code
  *
  * @return string	Hash code
  */
 public function getHashCode()
 {
     return md5($this->getText() . $this->_font->getHashCode() . __CLASS__);
 }
コード例 #5
0
ファイル: Font.php プロジェクト: bestgoodz/toko-baju
 /**
  * Get the effective row height for rows without a row dimension or rows with height -1
  * For example, for Calibri 11 this is 15 points
  *
  * @param Style_Font $font The workbooks default font
  * @return float Row height in points
  */
 public static function getDefaultRowHeightByFont(Style_Font $font)
 {
     switch ($font->getName()) {
         case 'Arial':
             switch ($font->getSize()) {
                 case 10:
                     // inspection of Arial 10 workbook says 12.75pt ~17px
                     $rowHeight = 12.75;
                     break;
                 case 9:
                     // inspection of Arial 9 workbook says 12.00pt ~16px
                     $rowHeight = 12;
                     break;
                 case 8:
                     // inspection of Arial 8 workbook says 11.25pt ~15px
                     $rowHeight = 11.25;
                     break;
                 case 7:
                     // inspection of Arial 7 workbook says 9.00pt ~12px
                     $rowHeight = 9;
                     break;
                 case 6:
                 case 5:
                     // inspection of Arial 5,6 workbook says 8.25pt ~11px
                     $rowHeight = 8.25;
                     break;
                 case 4:
                     // inspection of Arial 4 workbook says 6.75pt ~9px
                     $rowHeight = 6.75;
                     break;
                 case 3:
                     // inspection of Arial 3 workbook says 6.00pt ~8px
                     $rowHeight = 6;
                     break;
                 case 2:
                 case 1:
                     // inspection of Arial 1,2 workbook says 5.25pt ~7px
                     $rowHeight = 5.25;
                     break;
                 default:
                     // use Arial 10 workbook as an approximation, extrapolation
                     $rowHeight = 12.75 * $font->getSize() / 10;
                     break;
             }
             break;
         case 'Calibri':
             switch ($font->getSize()) {
                 case 11:
                     // inspection of Calibri 11 workbook says 15.00pt ~20px
                     $rowHeight = 15;
                     break;
                 case 10:
                     // inspection of Calibri 10 workbook says 12.75pt ~17px
                     $rowHeight = 12.75;
                     break;
                 case 9:
                     // inspection of Calibri 9 workbook says 12.00pt ~16px
                     $rowHeight = 12;
                     break;
                 case 8:
                     // inspection of Calibri 8 workbook says 11.25pt ~15px
                     $rowHeight = 11.25;
                     break;
                 case 7:
                     // inspection of Calibri 7 workbook says 9.00pt ~12px
                     $rowHeight = 9;
                     break;
                 case 6:
                 case 5:
                     // inspection of Calibri 5,6 workbook says 8.25pt ~11px
                     $rowHeight = 8.25;
                     break;
                 case 4:
                     // inspection of Calibri 4 workbook says 6.75pt ~9px
                     $rowHeight = 6.75;
                     break;
                 case 3:
                     // inspection of Calibri 3 workbook says 6.00pt ~8px
                     $rowHeight = 6.0;
                     break;
                 case 2:
                 case 1:
                     // inspection of Calibri 1,2 workbook says 5.25pt ~7px
                     $rowHeight = 5.25;
                     break;
                 default:
                     // use Calibri 11 workbook as an approximation, extrapolation
                     $rowHeight = 15 * $font->getSize() / 11;
                     break;
             }
             break;
         case 'Verdana':
             switch ($font->getSize()) {
                 case 10:
                     // inspection of Verdana 10 workbook says 12.75pt ~17px
                     $rowHeight = 12.75;
                     break;
                 case 9:
                     // inspection of Verdana 9 workbook says 11.25pt ~15px
                     $rowHeight = 11.25;
                     break;
                 case 8:
                     // inspection of Verdana 8 workbook says 10.50pt ~14px
                     $rowHeight = 10.5;
                     break;
                 case 7:
                     // inspection of Verdana 7 workbook says 9.00pt ~12px
                     $rowHeight = 9.0;
                     break;
                 case 6:
                 case 5:
                     // inspection of Verdana 5,6 workbook says 8.25pt ~11px
                     $rowHeight = 8.25;
                     break;
                 case 4:
                     // inspection of Verdana 4 workbook says 6.75pt ~9px
                     $rowHeight = 6.75;
                     break;
                 case 3:
                     // inspection of Verdana 3 workbook says 6.00pt ~8px
                     $rowHeight = 6;
                     break;
                 case 2:
                 case 1:
                     // inspection of Verdana 1,2 workbook says 5.25pt ~7px
                     $rowHeight = 5.25;
                     break;
                 default:
                     // use Verdana 10 workbook as an approximation, extrapolation
                     $rowHeight = 12.75 * $font->getSize() / 10;
                     break;
             }
             break;
         default:
             // just use Calibri as an approximation
             $rowHeight = 15 * $font->getSize() / 11;
             break;
     }
     return $rowHeight;
 }
コード例 #6
0
ファイル: Drawing.php プロジェクト: kamaludinnur/toko-baju
 /**
  * Convert column width from (intrinsic) Excel units to pixels
  *
  * @param 	float	$pValue		Value in cell dimension
  * @param 	Style_Font $pDefaultFont	Default font of the workbook
  * @return 	int		Value in pixels
  */
 public static function cellDimensionToPixels($pValue = 0, Style_Font $pDefaultFont)
 {
     // Font name and size
     $name = $pDefaultFont->getName();
     $size = $pDefaultFont->getSize();
     if (isset(Shared_Font::$defaultColumnWidths[$name][$size])) {
         // Exact width can be determined
         $colWidth = $pValue * Shared_Font::$defaultColumnWidths[$name][$size]['px'] / Shared_Font::$defaultColumnWidths[$name][$size]['width'];
     } else {
         // We don't have data for this particular font and size, use approximation by
         // extrapolating from Calibri 11
         $colWidth = $pValue * $size * Shared_Font::$defaultColumnWidths['Calibri'][11]['px'] / Shared_Font::$defaultColumnWidths['Calibri'][11]['width'] / 11;
     }
     // Round pixels to closest integer
     $colWidth = (int) round($colWidth);
     return $colWidth;
 }
コード例 #7
0
ファイル: Style.php プロジェクト: bestgoodz/toko-baju
 /**
  * Write Font
  *
  * @param 	Shared_XMLWriter		$objWriter 		XML Writer
  * @param 	Style_Font				$pFont			Font style
  * @throws 	Exception
  */
 private function _writeFont(Shared_XMLWriter $objWriter = null, Style_Font $pFont = null)
 {
     // font
     $objWriter->startElement('font');
     // Name
     $objWriter->startElement('name');
     $objWriter->writeAttribute('val', $pFont->getName());
     $objWriter->endElement();
     // Size
     $objWriter->startElement('sz');
     $objWriter->writeAttribute('val', $pFont->getSize());
     $objWriter->endElement();
     // Bold. We explicitly write this element also when false (like MS Office Excel 2007 does
     // for conditional formatting). Otherwise it will apparently not be picked up in conditional
     // formatting style dialog
     $objWriter->startElement('b');
     $objWriter->writeAttribute('val', $pFont->getBold() ? '1' : '0');
     $objWriter->endElement();
     // Italic
     $objWriter->startElement('i');
     $objWriter->writeAttribute('val', $pFont->getItalic() ? '1' : '0');
     $objWriter->endElement();
     // Superscript / subscript
     if ($pFont->getSuperScript() || $pFont->getSubScript()) {
         $objWriter->startElement('vertAlign');
         if ($pFont->getSuperScript()) {
             $objWriter->writeAttribute('val', 'superscript');
         } else {
             if ($pFont->getSubScript()) {
                 $objWriter->writeAttribute('val', 'subscript');
             }
         }
         $objWriter->endElement();
     }
     // Underline
     $objWriter->startElement('u');
     $objWriter->writeAttribute('val', $pFont->getUnderline());
     $objWriter->endElement();
     // Strikethrough
     $objWriter->startElement('strike');
     $objWriter->writeAttribute('val', $pFont->getStrikethrough() ? '1' : '0');
     $objWriter->endElement();
     // Foreground color
     $objWriter->startElement('color');
     $objWriter->writeAttribute('rgb', $pFont->getColor()->getARGB());
     $objWriter->endElement();
     $objWriter->endElement();
 }
コード例 #8
0
ファイル: HTML.php プロジェクト: bestgoodz/toko-baju
 /**
  * Create CSS style (Style_Font)
  *
  * @param	Style_Font 		$pStyle			Style_Font
  * @return	array
  */
 private function _createCSSStyleFont(Style_Font $pStyle)
 {
     // Construct CSS
     $css = array();
     // Create CSS
     if ($pStyle->getBold()) {
         $css['font-weight'] = 'bold';
     }
     if ($pStyle->getUnderline() != Style_Font::UNDERLINE_NONE && $pStyle->getStrikethrough()) {
         $css['text-decoration'] = 'underline line-through';
     } else {
         if ($pStyle->getUnderline() != Style_Font::UNDERLINE_NONE) {
             $css['text-decoration'] = 'underline';
         } else {
             if ($pStyle->getStrikethrough()) {
                 $css['text-decoration'] = 'line-through';
             }
         }
     }
     if ($pStyle->getItalic()) {
         $css['font-style'] = 'italic';
     }
     $css['color'] = '#' . $pStyle->getColor()->getRGB();
     $css['font-family'] = '\'' . $pStyle->getName() . '\'';
     $css['font-size'] = $pStyle->getSize() . 'pt';
     // Return
     return $css;
 }