88 lines
3.2 KiB
PHP
88 lines
3.2 KiB
PHP
<?php
|
|
|
|
namespace swf2ass;
|
|
|
|
|
|
class StyleList {
|
|
/** @var FillStyleRecord[] */
|
|
public array $fillStyles;
|
|
/** @var LineStyleRecord[] */
|
|
public array $lineStyles;
|
|
|
|
/**
|
|
* @param FillStyleRecord[] $fillStyles
|
|
* @param LineStyleRecord[] $lineStyles
|
|
*/
|
|
public function __construct(array $fillStyles = [], array $lineStyles = []) {
|
|
$this->fillStyles = $fillStyles;
|
|
$this->lineStyles = $lineStyles;
|
|
}
|
|
|
|
public static function parseFillStyleRecord(array $node): FillStyleRecord {
|
|
switch ($node["type"]) {
|
|
case 0x00: // Solid fill
|
|
return new FillStyleRecord(Color::fromArray($node["color"]));
|
|
break;
|
|
case 0x10: // Linear gradient fill
|
|
return new FillStyleRecord(LinearGradient::fromArray($node["gradient"], MatrixTransform::fromSWFArray($node["matrix"])));
|
|
break;
|
|
case 0x12: // Radial gradient fill
|
|
return new FillStyleRecord(RadialGradient::fromArray($node["gradient"], MatrixTransform::fromSWFArray($node["matrix"])));
|
|
break;
|
|
case 0x13: // Focal gradient fill
|
|
return new FillStyleRecord(FocalGradient::fromArray($node["focalGradient"], MatrixTransform::fromSWFArray($node["matrix"])));
|
|
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, 20));
|
|
break;
|
|
default:
|
|
var_dump($node);
|
|
throw new \Exception("Unknown style " . $node["type"]);
|
|
}
|
|
}
|
|
|
|
public static function fromArray(array $element): StyleList {
|
|
$fillStyles = [];
|
|
$lineStyles = [];
|
|
foreach ($element["fillStyles"] as $node) {
|
|
$fillStyles[] = self::parseFillStyleRecord($node);
|
|
}
|
|
foreach ($element["lineStyles"] as $node) {
|
|
$color = isset($node["color"]) ? Color::fromArray($node["color"]) : null;
|
|
|
|
//TODO: fill flag
|
|
if ($color === null) {
|
|
var_dump($node);
|
|
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)?
|
|
$lineStyles[] = new LineStyleRecord(max(Constants::TWIP_SIZE, $node["width"]), $color);
|
|
}
|
|
return new StyleList($fillStyles, $lineStyles);
|
|
}
|
|
|
|
/**
|
|
* @param $i
|
|
* @return FillStyleRecord|null
|
|
*/
|
|
public function getFillStyle($i): ?FillStyleRecord {
|
|
return $this->fillStyles[$i] ?? null;
|
|
}
|
|
|
|
/**
|
|
* @param $i
|
|
* @return LineStyleRecord|null
|
|
*/
|
|
public function getLineStyle($i): ?LineStyleRecord {
|
|
return $this->lineStyles[$i] ?? null;
|
|
}
|
|
} |