Source for file Escher.php
Documentation is available at Escher.php
* Copyright (c) 2006 - 2011 PHPExcel
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* @package PHPExcel_Reader_Excel5
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
* @license http://www.gnu.org/licenses/old-licenses/lgpl-2.1.txt LGPL
* @version 1.7.6, 2011-02-27
* PHPExcel_Reader_Excel5_Escher
* @package PHPExcel_Reader_Excel5
* @copyright Copyright (c) 2006 - 2011 PHPExcel (http://www.codeplex.com/PHPExcel)
const DGGCONTAINER = 0xF000;
const BSTORECONTAINER = 0xF001;
const DGCONTAINER = 0xF002;
const SPGRCONTAINER = 0xF003;
const SPCONTAINER = 0xF004;
const CLIENTTEXTBOX = 0xF00D;
const CLIENTANCHOR = 0xF010;
const CLIENTDATA = 0xF011;
const SPLITMENUCOLORS = 0xF11E;
const TERTIARYOPT = 0xF122;
* Escher stream data (binary)
* Size in bytes of the Escher stream data
* Current position of stream pointer in Escher stream data
* The object to be returned by the reader. Modified during load.
* Create a new PHPExcel_Reader_Excel5_Escher instance
$this->_object = $object;
* Load Escher stream data. May be a partial Escher stream.
public function load($data)
// total byte size of Excel data (workbook global substream + sheet substreams)
$this->_dataSize = strlen($this->_data);
while ($this->_pos < $this->_dataSize) {
// offset: 2; size: 2: Record Type
case self::DGGCONTAINER: $this->_readDggContainer(); break;
case self::DGG: $this->_readDgg(); break;
case self::BSTORECONTAINER: $this->_readBstoreContainer(); break;
case self::BSE: $this->_readBSE(); break;
case self::BLIPJPEG: $this->_readBlipJPEG(); break;
case self::BLIPPNG: $this->_readBlipPNG(); break;
case self::OPT: $this->_readOPT(); break;
case self::TERTIARYOPT: $this->_readTertiaryOPT(); break;
case self::SPLITMENUCOLORS: $this->_readSplitMenuColors(); break;
case self::DGCONTAINER: $this->_readDgContainer(); break;
case self::DG: $this->_readDg(); break;
case self::SPGRCONTAINER: $this->_readSpgrContainer(); break;
case self::SPCONTAINER: $this->_readSpContainer(); break;
case self::SPGR: $this->_readSpgr(); break;
case self::SP: $this->_readSp(); break;
case self::CLIENTTEXTBOX: $this->_readClientTextbox(); break;
case self::CLIENTANCHOR: $this->_readClientAnchor(); break;
case self::CLIENTDATA: $this->_readClientData(); break;
default: $this->_readDefault(); break;
private function _readDefault()
// offset 0; size: 2; recVer and recInstance
// offset: 2; size: 2: Record Type
// bit: 0-3; mask: 0x000F; recVer
$recVer = (0x000F & $verInstance) >> 0;
$recordData = substr($this->_data, $this->_pos + 8, $length);
// move stream pointer to next record
$this->_pos += 8 + $length;
* Read DggContainer record (Drawing Group Container)
private function _readDggContainer()
$recordData = substr($this->_data, $this->_pos + 8, $length);
// move stream pointer to next record
$this->_pos += 8 + $length;
// record is a container, read contents
$this->_object->setDggContainer($dggContainer);
$reader->load($recordData);
* Read Dgg record (Drawing Group)
private function _readDgg()
$recordData = substr($this->_data, $this->_pos + 8, $length);
// move stream pointer to next record
$this->_pos += 8 + $length;
* Read BstoreContainer record (Blip Store Container)
private function _readBstoreContainer()
$recordData = substr($this->_data, $this->_pos + 8, $length);
// move stream pointer to next record
$this->_pos += 8 + $length;
// record is a container, read contents
$this->_object->setBstoreContainer($bstoreContainer);
$reader->load($recordData);
private function _readBSE()
// offset: 0; size: 2; recVer and recInstance
// bit: 4-15; mask: 0xFFF0; recInstance
$recordData = substr($this->_data, $this->_pos + 8, $length);
// move stream pointer to next record
$this->_pos += 8 + $length;
// add BSE to BstoreContainer
$this->_object->addBSE($BSE);
$BSE->setBLIPType($recInstance);
// offset: 0; size: 1; btWin32 (MSOBLIPTYPE)
$btWin32 = ord($recordData[0]);
// offset: 1; size: 1; btWin32 (MSOBLIPTYPE)
$btMacOS = ord($recordData[1]);
// offset: 2; size: 16; MD4 digest
$rgbUid = substr($recordData, 2, 16);
// offset: 18; size: 2; tag
// offset: 20; size: 4; size of BLIP in bytes
// offset: 24; size: 4; number of references to this BLIP
// offset: 28; size: 4; MSOFO file offset
// offset: 32; size: 1; unused1
$unused1 = ord($recordData{32});
// offset: 33; size: 1; size of nameData in bytes (including null terminator)
$cbName = ord($recordData{33});
// offset: 34; size: 1; unused2
$unused2 = ord($recordData{34});
// offset: 35; size: 1; unused3
$unused3 = ord($recordData{35});
// offset: 36; size: $cbName; nameData
$nameData = substr($recordData, 36, $cbName);
// offset: 36 + $cbName, size: var; the BLIP data
$blipData = substr($recordData, 36 + $cbName);
// record is a container, read contents
$reader->load($blipData);
* Read BlipJPEG record. Holds raw JPEG image data
private function _readBlipJPEG()
// offset: 0; size: 2; recVer and recInstance
// bit: 4-15; mask: 0xFFF0; recInstance
$recordData = substr($this->_data, $this->_pos + 8, $length);
// move stream pointer to next record
$this->_pos += 8 + $length;
// offset: 0; size: 16; rgbUid1 (MD4 digest of)
$rgbUid1 = substr($recordData, 0, 16);
// offset: 16; size: 16; rgbUid2 (MD4 digest), only if $recInstance = 0x46B or 0x6E3
if (in_array($recInstance, array(0x046B, 0x06E3))) {
$rgbUid2 = substr($recordData, 16, 16);
// offset: var; size: 1; tag
$tag = ord($recordData{$pos});
// offset: var; size: var; the raw image data
$data = substr($recordData, $pos);
$this->_object->setBlip($blip);
* Read BlipPNG record. Holds raw PNG image data
private function _readBlipPNG()
// offset: 0; size: 2; recVer and recInstance
// bit: 4-15; mask: 0xFFF0; recInstance
$recordData = substr($this->_data, $this->_pos + 8, $length);
// move stream pointer to next record
$this->_pos += 8 + $length;
// offset: 0; size: 16; rgbUid1 (MD4 digest of)
$rgbUid1 = substr($recordData, 0, 16);
// offset: 16; size: 16; rgbUid2 (MD4 digest), only if $recInstance = 0x46B or 0x6E3
if ($recInstance == 0x06E1) {
$rgbUid2 = substr($recordData, 16, 16);
// offset: var; size: 1; tag
$tag = ord($recordData{$pos});
// offset: var; size: var; the raw image data
$data = substr($recordData, $pos);
$this->_object->setBlip($blip);
* Read OPT record. This record may occur within DggContainer record or SpContainer
private function _readOPT()
// offset: 0; size: 2; recVer and recInstance
// bit: 4-15; mask: 0xFFF0; recInstance
$recordData = substr($this->_data, $this->_pos + 8, $length);
// move stream pointer to next record
$this->_pos += 8 + $length;
$this->_readOfficeArtRGFOPTE($recordData, $recInstance);
* Read TertiaryOPT record
private function _readTertiaryOPT()
// offset: 0; size: 2; recVer and recInstance
// bit: 4-15; mask: 0xFFF0; recInstance
$recordData = substr($this->_data, $this->_pos + 8, $length);
// move stream pointer to next record
$this->_pos += 8 + $length;
* Read SplitMenuColors record
private function _readSplitMenuColors()
$recordData = substr($this->_data, $this->_pos + 8, $length);
// move stream pointer to next record
$this->_pos += 8 + $length;
* Read DgContainer record (Drawing Container)
private function _readDgContainer()
$recordData = substr($this->_data, $this->_pos + 8, $length);
// move stream pointer to next record
$this->_pos += 8 + $length;
// record is a container, read contents
$this->_object->setDgContainer($dgContainer);
$escher = $reader->load($recordData);
* Read Dg record (Drawing)
private function _readDg()
$recordData = substr($this->_data, $this->_pos + 8, $length);
// move stream pointer to next record
$this->_pos += 8 + $length;
* Read SpgrContainer record (Shape Group Container)
private function _readSpgrContainer()
// context is either context DgContainer or SpgrContainer
$recordData = substr($this->_data, $this->_pos + 8, $length);
// move stream pointer to next record
$this->_pos += 8 + $length;
// record is a container, read contents
$this->_object->setSpgrContainer($spgrContainer);
$this->_object->addChild($spgrContainer);
$escher = $reader->load($recordData);
* Read SpContainer record (Shape Container)
private function _readSpContainer()
$recordData = substr($this->_data, $this->_pos + 8, $length);
// add spContainer to spgrContainer
$this->_object->addChild($spContainer);
// move stream pointer to next record
$this->_pos += 8 + $length;
// record is a container, read contents
$escher = $reader->load($recordData);
* Read Spgr record (Shape Group)
private function _readSpgr()
$recordData = substr($this->_data, $this->_pos + 8, $length);
// move stream pointer to next record
$this->_pos += 8 + $length;
private function _readSp()
// offset: 0; size: 2; recVer and recInstance
// bit: 4-15; mask: 0xFFF0; recInstance
$recordData = substr($this->_data, $this->_pos + 8, $length);
// move stream pointer to next record
$this->_pos += 8 + $length;
* Read ClientTextbox record
private function _readClientTextbox()
// offset: 0; size: 2; recVer and recInstance
// bit: 4-15; mask: 0xFFF0; recInstance
$recordData = substr($this->_data, $this->_pos + 8, $length);
// move stream pointer to next record
$this->_pos += 8 + $length;
* Read ClientAnchor record. This record holds information about where the shape is anchored in worksheet
private function _readClientAnchor()
$recordData = substr($this->_data, $this->_pos + 8, $length);
// move stream pointer to next record
$this->_pos += 8 + $length;
// offset: 2; size: 2; upper-left corner column index (0-based)
// offset: 4; size: 2; upper-left corner horizontal offset in 1/1024 of column width
// offset: 6; size: 2; upper-left corner row index (0-based)
// offset: 8; size: 2; upper-left corner vertical offset in 1/256 of row height
// offset: 10; size: 2; bottom-right corner column index (0-based)
// offset: 12; size: 2; bottom-right corner horizontal offset in 1/1024 of column width
// offset: 14; size: 2; bottom-right corner row index (0-based)
// offset: 16; size: 2; bottom-right corner vertical offset in 1/256 of row height
// set the start coordinates
$this->_object->setStartOffsetX($startOffsetX);
$this->_object->setStartOffsetY($startOffsetY);
// set the end coordinates
$this->_object->setEndOffsetX($endOffsetX);
$this->_object->setEndOffsetY($endOffsetY);
private function _readClientData()
$recordData = substr($this->_data, $this->_pos + 8, $length);
// move stream pointer to next record
$this->_pos += 8 + $length;
* Read OfficeArtRGFOPTE table of property-value pairs
* @param string $data Binary data
* @param int $n Number of properties
private function _readOfficeArtRGFOPTE($data, $n) {
$splicedComplexData = substr($data, 6 * $n);
// loop through property-value pairs
for ($i = 0; $i < $n; ++ $i) {
// read 6 bytes at a time
$fopte = substr($data, 6 * $i, 6);
// offset: 0; size: 2; opid
// bit: 0-13; mask: 0x3FFF; opid.opid
$opidOpid = (0x3FFF & $opid) >> 0;
// bit: 14; mask 0x4000; 1 = value in op field is BLIP identifier
$opidFBid = (0x4000 & $opid) >> 14;
// bit: 15; mask 0x8000; 1 = this is a complex property, op field specifies size of complex data
$opidFComplex = (0x8000 & $opid) >> 15;
// offset: 2; size: 4; the value for this property
$complexData = substr($splicedComplexData, 0, $op);
$splicedComplexData = substr($splicedComplexData, $op);
// we store string value with complex data
// we store integer value
$this->_object->setOPT($opidOpid, $value);
|