152 lines
6.2 KiB
PHP
152 lines
6.2 KiB
PHP
<?php
|
|
|
|
namespace swf2ass;
|
|
|
|
|
|
class MorphStyleList {
|
|
/** @var FillStyleRecord[] */
|
|
public array $startFillStyles;
|
|
/** @var FillStyleRecord[] */
|
|
public array $endFillStyles;
|
|
/** @var LineStyleRecord[] */
|
|
public array $startLineStyles;
|
|
/** @var LineStyleRecord[] */
|
|
public array $endLineStyles;
|
|
|
|
/**
|
|
* @param FillStyleRecord[] $startFillStyles
|
|
* @param FillStyleRecord[] $endFillStyles
|
|
* @param LineStyleRecord[] $startLineStyles
|
|
* @param LineStyleRecord[] $endLineStyles
|
|
*/
|
|
public function __construct(array $startFillStyles = [], array $endFillStyles = [], array $startLineStyles = [], array $endLineStyles = []) {
|
|
$this->startFillStyles = $startFillStyles;
|
|
$this->endFillStyles = $endFillStyles;
|
|
$this->startLineStyles = $startLineStyles;
|
|
$this->endLineStyles = $endLineStyles;
|
|
}
|
|
|
|
/**
|
|
* @param array $node
|
|
* @return FillStyleRecord[]
|
|
* @throws \Exception
|
|
*/
|
|
public static function parseFillStyleRecord(array $node): array {
|
|
switch ($node["fillStyleType"]) {
|
|
case 0x00: // Solid fill
|
|
return [new FillStyleRecord(Color::fromArray($node["startColor"])), new FillStyleRecord(Color::fromArray($node["endColor"]))];
|
|
break;
|
|
case 0x10: // Linear gradient fill
|
|
//TODO
|
|
return [new FillStyleRecord(new Color(0, 0, 0, 20)), new FillStyleRecord(new Color(0, 0, 255, 20))];
|
|
return [new FillStyleRecord(LinearGradient::fromArray($node["gradient"], MatrixTransform::fromSWFArray($node["startGradientMatrix"]))), new FillStyleRecord(LinearGradient::fromArray($node["gradient"], MatrixTransform::fromSWFArray($node["endGradientMatrix"])))];
|
|
break;
|
|
case 0x12: // Radial gradient fill
|
|
//TODO
|
|
return [new FillStyleRecord(new Color(0, 0, 0, 20)), new FillStyleRecord(new Color(0, 0, 255, 20))];
|
|
return [new FillStyleRecord(RadialGradient::fromArray($node["gradient"], MatrixTransform::fromSWFArray($node["startGradientMatrix"]))), new FillStyleRecord(RadialGradient::fromArray($node["gradient"], MatrixTransform::fromSWFArray($node["endGradientMatrix"])))];
|
|
break;
|
|
case 0x13: // Focal gradient fill
|
|
//TODO
|
|
return [new FillStyleRecord(new Color(0, 0, 0, 20)), new FillStyleRecord(new Color(0, 0, 255, 20))];
|
|
return [new FillStyleRecord(FocalGradient::fromArray($node["focalGradient"], MatrixTransform::fromSWFArray($node["startGradientMatrix"]))), new FillStyleRecord(FocalGradient::fromArray($node["focalGradient"], MatrixTransform::fromSWFArray($node["endGradientMatrix"])))];
|
|
break;
|
|
case 0x40: // Repeating bitmap fill
|
|
case 0x41: // Clipped bitmap fill
|
|
case 0x42: // Non-smoothed repeating bitmap
|
|
case 0x43: // Non-smoothed clipped bitmap
|
|
var_dump($node);
|
|
return $node["bitmapId"] === 65535 ? [new FillStyleRecord(new Color(0, 0, 0, 0)), new FillStyleRecord(new Color(0, 0, 0, 0))] : [new FillStyleRecord(new Color(0, 0, 0, 20)), new FillStyleRecord(new Color(255, 0, 0, 20))];
|
|
break;
|
|
default:
|
|
var_dump($node);
|
|
throw new \Exception("Unknown style " . $node["type"]);
|
|
}
|
|
}
|
|
|
|
public function getStartStyleList() : StyleList{
|
|
return new StyleList($this->startFillStyles, $this->startLineStyles);
|
|
}
|
|
|
|
public function getEndStyleList() : StyleList{
|
|
return new StyleList($this->endFillStyles, $this->endLineStyles);
|
|
}
|
|
|
|
public static function fromArray(array $element): MorphStyleList {
|
|
$startFillStyles = [];
|
|
$endFillStyles = [];
|
|
$startLineStyles = [];
|
|
$endLineStyles = [];
|
|
foreach ($element["morphFillStyles"] as $node) {
|
|
$record = self::parseFillStyleRecord($node);
|
|
$startFillStyles[] = $record[0];
|
|
$endFillStyles[] = $record[1];
|
|
}
|
|
foreach ($element["morphLineStyles"] as $node) {
|
|
$startColor = isset($node["startColor"]) ? Color::fromArray($node["startColor"]) : null;
|
|
$endColor = isset($node["endColor"]) ? Color::fromArray($node["endColor"]) : null;
|
|
|
|
//TODO: fill flag
|
|
if ($startColor === null) {
|
|
var_dump($node);
|
|
//TODO
|
|
/*
|
|
if(isset($node["fillType"])){
|
|
$color = self::parseFillStyleRecord($node["fillType"])->fill;
|
|
if($color instanceof Gradient){
|
|
$color = $color->getItems()[0]->color;
|
|
}
|
|
}
|
|
*/
|
|
}
|
|
if ($endColor === null) {
|
|
var_dump($node);
|
|
//TODO
|
|
/*
|
|
if(isset($node["fillType"])){
|
|
$color = self::parseFillStyleRecord($node["fillType"])->fill;
|
|
if($color instanceof Gradient){
|
|
$color = $color->getItems()[0]->color;
|
|
}
|
|
}
|
|
*/
|
|
}
|
|
//TODO: any reason for max(Constants::TWIP_SIZE)?
|
|
$startLineStyles[] = new LineStyleRecord(max(Constants::TWIP_SIZE, $node["startWidth"]), $startColor);
|
|
$endLineStyles[] = new LineStyleRecord(max(Constants::TWIP_SIZE, $node["endWidth"]), $startColor);
|
|
}
|
|
return new MorphStyleList($startFillStyles, $endFillStyles, $startLineStyles, $endLineStyles);
|
|
}
|
|
|
|
/**
|
|
* @param $i
|
|
* @return FillStyleRecord|null
|
|
*/
|
|
public function getStartFillStyle($i): ?FillStyleRecord {
|
|
return $this->startFillStyles[$i] ?? null;
|
|
}
|
|
|
|
/**
|
|
* @param $i
|
|
* @return FillStyleRecord|null
|
|
*/
|
|
public function getEndFillStyle($i): ?FillStyleRecord {
|
|
return $this->endFillStyles[$i] ?? null;
|
|
}
|
|
|
|
/**
|
|
* @param $i
|
|
* @return LineStyleRecord|null
|
|
*/
|
|
public function getStartLineStyle($i): ?LineStyleRecord {
|
|
return $this->startLineStyles[$i] ?? null;
|
|
}
|
|
|
|
/**
|
|
* @param $i
|
|
* @return LineStyleRecord|null
|
|
*/
|
|
public function getEndLineStyle($i): ?LineStyleRecord {
|
|
return $this->endLineStyles[$i] ?? null;
|
|
}
|
|
} |