swf2ass/src/ass/borderTag.php

43 lines
1.4 KiB
PHP

<?php
namespace swf2ass\ass;
use swf2ass\Constants;
use swf2ass\FillStyleRecord;
use swf2ass\LineStyleRecord;
use swf2ass\StyleRecord;
use swf2ass\Vector2;
class borderTag implements ASSStyleTag {
private Vector2 $size;
public function __construct(Vector2 $size) {
$this->size = $size;
}
public function transitionStyleRecord(ASSLine $line, StyleRecord $record): ?borderTag {
return self::fromStyleRecord($record);
}
public function encode(ASSEventTime $event): string {
if($this->size->x === $this->size->y){
return sprintf("\\bord%.02F", $this->size->x);
}else{
return sprintf("\\xbord%.02F\\ybord%.02F", $this->size->x, $this->size->y);
}
}
public static function fromStyleRecord(StyleRecord $record): ?borderTag {
if ($record instanceof LineStyleRecord) {
return new borderTag(new Vector2($record->width / Constants::TWIP_SIZE, $record->width / Constants::TWIP_SIZE));
}else if ($record instanceof FillStyleRecord and $record->border !== null) {
return new borderTag(new Vector2($record->border->width / Constants::TWIP_SIZE, $record->border->width / Constants::TWIP_SIZE));
}
return new borderTag(new Vector2(0, 0));
}
public function equals(ASSTag $tag): bool {
return $tag instanceof $this and $this->size->equals($tag->size);
}
}