Beispiel #1
0
 function parseContent($tagCode, $content, $opts = array())
 {
     // DefineMorphShape, DefineMorphShape2
     $isMorph = $tagCode == 46 || $tagCode == 84;
     $reader = new IO_Bit();
     $reader->input($content);
     $this->_shapeId = $reader->getUI16LE();
     $opts = array('tagCode' => $tagCode, 'isMorph' => $isMorph);
     if ($isMorph === false) {
         // 描画スタイル
         $this->_shapeBounds = IO_SWF_TYPE_RECT::parse($reader);
         if ($tagCode == 83) {
             // DefineShape4
             $this->_edgeBounds = IO_SWF_TYPE_RECT::parse($reader);
             $this->_reserved = $reader->getUIBits(6);
             $this->_usesNonScalingStrokes = $reader->getUIBit();
             $this->_UsesScalingStrokes = $reader->getUIBit();
         }
         $this->_fillStyles = IO_SWF_TYPE_FILLSTYLEARRAY::parse($reader, $opts);
         $this->_lineStyles = IO_SWF_TYPE_LINESTYLEARRAY::parse($reader, $opts);
         // 描画枠
         $this->_shapeRecords = IO_SWF_Type_SHAPE::parse($reader, $opts);
     } else {
         $this->_startBounds = IO_SWF_TYPE_RECT::parse($reader);
         $this->_endBounds = IO_SWF_TYPE_RECT::parse($reader);
         list($offset_offset, $dummy) = $reader->getOffset();
         $this->_offset = $reader->getUI32LE();
         // 描画スタイル
         $this->_morphFillStyles = IO_SWF_TYPE_FILLSTYLEARRAY::parse($reader, $opts);
         $this->_morphLineStyles = IO_SWF_TYPE_LINESTYLEARRAY::parse($reader, $opts);
         // 描画枠
         $this->_startEdge = IO_SWF_Type_SHAPE::parse($reader, $opts);
         list($end_edge_offset, $dummy) = $reader->getOffset();
         if ($offset_offset + $this->_offset + 4 != $end_edge_offset) {
             trigger_error("offset_offset({$offset_offset}) + this->_offset({$this->_offset}) + 4 != end_edge_offset({$end_edge_offset})", E_USER_WARNING);
             $reader->setOffset($offset_offset + $this->_offset + 4, 0);
         }
         $this->_endEdge = IO_SWF_Type_SHAPE::parse($reader, $opts);
     }
 }
Beispiel #2
0
 static function parse(&$reader, $opts = array())
 {
     $tagCode = $opts['tagCode'];
     $shapeRecords = array();
     $reader->byteAlign();
     // 描画スタイルを参照するインデックスのビット幅
     $numFillBits = $reader->getUIBits(4);
     $numLineBits = $reader->getUIBits(4);
     $currentDrawingPositionX = 0;
     $currentDrawingPositionY = 0;
     $currentFillStyle0 = 0;
     $currentFillStyle1 = 0;
     $currentLineStyle = 0;
     $done = false;
     // ShapeRecords
     while ($done === false) {
         $shapeRecord = array();
         $typeFlag = $reader->getUIBit();
         $shapeRecord['TypeFlag'] = $typeFlag;
         if ($typeFlag == 0) {
             $endOfShape = $reader->getUIBits(5);
             if ($endOfShape == 0) {
                 // EndShapeRecord
                 $shapeRecord['EndOfShape'] = $endOfShape;
                 $done = true;
             } else {
                 // StyleChangeRecord
                 $reader->incrementOffset(0, -5);
                 $stateNewStyles = $reader->getUIBit();
                 $stateLineStyle = $reader->getUIBit();
                 $stateFillStyle1 = $reader->getUIBit();
                 $stateFillStyle0 = $reader->getUIBit();
                 $stateMoveTo = $reader->getUIBit();
                 if ($stateMoveTo) {
                     $moveBits = $reader->getUIBits(5);
                     //                        $shapeRecord['(MoveBits)'] = $moveBits;
                     $moveDeltaX = $reader->getSIBits($moveBits);
                     $moveDeltaY = $reader->getSIBits($moveBits);
                     //                        $currentDrawingPositionX += $moveDeltaX;
                     //                        $currentDrawingPositionY += $moveDeltaY;
                     $currentDrawingPositionX = $moveDeltaX;
                     $currentDrawingPositionY = $moveDeltaY;
                     $shapeRecord['MoveX'] = $currentDrawingPositionX;
                     $shapeRecord['MoveY'] = $currentDrawingPositionY;
                 }
                 $shapeRecord['MoveX'] = $currentDrawingPositionX;
                 $shapeRecord['MoveY'] = $currentDrawingPositionY;
                 if ($stateFillStyle0) {
                     $currentFillStyle0 = $reader->getUIBits($numFillBits);
                 }
                 if ($stateFillStyle1) {
                     $currentFillStyle1 = $reader->getUIBits($numFillBits);
                 }
                 if ($stateLineStyle) {
                     $currentLineStyle = $reader->getUIBits($numLineBits);
                 }
                 $shapeRecord['FillStyle0'] = $currentFillStyle0;
                 $shapeRecord['FillStyle1'] = $currentFillStyle1;
                 $shapeRecord['LineStyle'] = $currentLineStyle;
                 if ($stateNewStyles) {
                     $opts = array('tagCode' => $tagCode);
                     $shapeRecord['FillStyles'] = IO_SWF_TYPE_FILLSTYLEARRAY::parse($reader, $opts);
                     $shapeRecord['LineStyles'] = IO_SWF_TYPE_LINESTYLEARRAY::parse($reader, $opts);
                     $reader->byteAlign();
                     $numFillBits = $reader->getUIBits(4);
                     $numLineBits = $reader->getUIBits(4);
                 }
             }
         } else {
             // Edge records
             $shapeRecord['StraightFlag'] = $reader->getUIBit();
             if ($shapeRecord['StraightFlag']) {
                 // StraightEdgeRecord
                 $numBits = $reader->getUIBits(4);
                 //                    $shapeRecord['(NumBits)'] = $numBits;
                 $generalLineFlag = $reader->getUIBit();
                 if ($generalLineFlag == 0) {
                     $vertLineFlag = $reader->getUIBit();
                 }
                 if ($generalLineFlag || $vertLineFlag == 0) {
                     $deltaX = $reader->getSIBits($numBits + 2);
                     $currentDrawingPositionX += $deltaX;
                 }
                 if ($generalLineFlag || $vertLineFlag) {
                     $deltaY = $reader->getSIBits($numBits + 2);
                     $currentDrawingPositionY += $deltaY;
                 }
                 $shapeRecord['X'] = $currentDrawingPositionX;
                 $shapeRecord['Y'] = $currentDrawingPositionY;
             } else {
                 // CurvedEdgeRecord
                 $numBits = $reader->getUIBits(4);
                 //                    $shapeRecord['(NumBits)'] = $numBits;
                 $controlDeltaX = $reader->getSIBits($numBits + 2);
                 $controlDeltaY = $reader->getSIBits($numBits + 2);
                 $anchorDeltaX = $reader->getSIBits($numBits + 2);
                 $anchorDeltaY = $reader->getSIBits($numBits + 2);
                 $currentDrawingPositionX += $controlDeltaX;
                 $currentDrawingPositionY += $controlDeltaY;
                 $shapeRecord['ControlX'] = $currentDrawingPositionX;
                 $shapeRecord['ControlY'] = $currentDrawingPositionY;
                 $currentDrawingPositionX += $anchorDeltaX;
                 $currentDrawingPositionY += $anchorDeltaY;
                 $shapeRecord['AnchorX'] = $currentDrawingPositionX;
                 $shapeRecord['AnchorY'] = $currentDrawingPositionY;
             }
         }
         $shapeRecords[] = $shapeRecord;
     }
     return $shapeRecords;
 }