33 lines
1.3 KiB
PHP
33 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace swf2ass\ass;
|
|
|
|
use swf2ass\Color;
|
|
use swf2ass\FillStyleRecord;
|
|
use swf2ass\Gradient;
|
|
use swf2ass\StyleRecord;
|
|
use swf2ass\Utils;
|
|
|
|
class fillColorTag extends colorTag {
|
|
public static function fromStyleRecord(StyleRecord $record): ?fillColorTag {
|
|
if ($record instanceof FillStyleRecord) {
|
|
/** @var ?Color $color */
|
|
$color = null;
|
|
if ($record->fill instanceof Color) {
|
|
$color = $record->fill;
|
|
} else if ($record->fill instanceof Gradient) { //TODO: split this elsewhere
|
|
$color = $record->fill->getItems()[0]->color;
|
|
var_dump($record->fill);
|
|
throw new \Exception("Invalid Gradient Fill record");
|
|
} else {
|
|
throw new \Exception("Invalid Fill record");
|
|
}
|
|
return new fillColorTag($color, $color);
|
|
}
|
|
return new fillColorTag(null, null);
|
|
}
|
|
|
|
public function encode(ASSEventTime $event): string {
|
|
return $this->color === null ? "\\1a&HFF&" : ("\\1c&H" . strtoupper(Utils::padHex(dechex($this->color->b))) . strtoupper(Utils::padHex(dechex($this->color->g))) . strtoupper(Utils::padHex(dechex($this->color->r))) . "&\\1a&H" . strtoupper(Utils::padHex(dechex(255 - $this->color->alpha))) . "&");
|
|
}
|
|
} |