swf2ass/src/ass/fillColorTag.php

31 lines
1.1 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;
} else {
throw new \Exception("Invalid Fill record");
}
return new fillColorTag($color);
}
return new fillColorTag(new Color(0, 0, 0, 255));
}
public function encode(): string {
return "\\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($this->color->alpha))) . "&";
}
}