Added scale mode to drawing tags
This commit is contained in:
parent
a0ca411a1d
commit
98a06228ed
|
@ -4,5 +4,5 @@ namespace swf2ass;
|
|||
|
||||
abstract class Constants {
|
||||
const TWIP_SIZE = 20;
|
||||
const EPSILON = 0.000001;
|
||||
const EPSILON = 0.000001; //TODO: maybe change to PHP_FLOAT_EPSILON
|
||||
}
|
|
@ -2,9 +2,14 @@
|
|||
|
||||
namespace swf2ass\ass;
|
||||
|
||||
use swf2ass\Constants;
|
||||
use swf2ass\MoveRecord;
|
||||
|
||||
class drawTag extends drawingTag {
|
||||
|
||||
public function encode(ASSLine $line, float $frameDurationMs): string {
|
||||
return "\\p1}" . implode(" ", $this->getCommands()) . "{\\p0";
|
||||
$scale = 6;
|
||||
$scaleMultiplier = 2 ** ($scale - 1);
|
||||
return "\\p$scale}" . implode(" ", $this->getCommands($scaleMultiplier, 0)) . "{\\p0";
|
||||
}
|
||||
}
|
|
@ -30,39 +30,39 @@ abstract class drawingTag implements ASSTag {
|
|||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
protected function getCommands(): array {
|
||||
protected function getCommands(float $scale = 1, int $precision = self::PRECISION): array {
|
||||
$commands = [];
|
||||
/** @var ?Record $lastEdge */
|
||||
$lastEdge = null;
|
||||
foreach ($this->shape->edges as $edge) {
|
||||
if ($edge instanceof MoveRecord) {
|
||||
$coords = $edge->coord->toPixel();
|
||||
$commands[] = "m " . round($coords->x, self::PRECISION) . " " . round($coords->y, self::PRECISION);
|
||||
$coords = $edge->coord->multiply($scale / Constants::TWIP_SIZE);
|
||||
$commands[] = "m " . round($coords->x, $precision) . " " . round($coords->y, $precision);
|
||||
} else if ($edge instanceof LineRecord) {
|
||||
$coords = $edge->coord->toPixel();
|
||||
$commands[] = "l " . round($coords->x, self::PRECISION) . " " . round($coords->y, self::PRECISION);
|
||||
$coords = $edge->coord->multiply($scale / Constants::TWIP_SIZE);
|
||||
$commands[] = "l " . round($coords->x, $precision) . " " . round($coords->y, $precision);
|
||||
} else if ($edge instanceof QuadraticCurveRecord or $edge instanceof CubicCurveRecord or $edge instanceof CubicSplineCurveRecord) {
|
||||
if ($edge instanceof QuadraticCurveRecord) {
|
||||
$edge = CubicCurveRecord::fromQuadraticRecord($edge);
|
||||
}
|
||||
|
||||
if ($edge instanceof CubicCurveRecord) {
|
||||
$control1 = $edge->control1->toPixel();
|
||||
$control2 = $edge->control2->toPixel();
|
||||
$anchor = $edge->anchor->toPixel();
|
||||
$commands[] = "b " . round($control1->x, self::PRECISION) . " " . round($control1->y, self::PRECISION) . " " . round($control2->x, self::PRECISION) . " " . round($control2->y, self::PRECISION) . " " . round($anchor->x, self::PRECISION) . " " . round($anchor->y, self::PRECISION);
|
||||
$control1 = $edge->control1->multiply($scale / Constants::TWIP_SIZE);
|
||||
$control2 = $edge->control2->multiply($scale / Constants::TWIP_SIZE);
|
||||
$anchor = $edge->anchor->multiply($scale / Constants::TWIP_SIZE);
|
||||
$commands[] = "b " . round($control1->x, $precision) . " " . round($control1->y, $precision) . " " . round($control2->x, $precision) . " " . round($control2->y, $precision) . " " . round($anchor->x, $precision) . " " . round($anchor->y, $precision);
|
||||
}
|
||||
|
||||
//TODO
|
||||
if ($edge instanceof CubicSplineCurveRecord) {
|
||||
$anchor = $edge->anchor->toPixel();
|
||||
$anchor = $edge->anchor->multiply($scale / Constants::TWIP_SIZE);
|
||||
$controlPoints = [];
|
||||
foreach ($edge->control as $control) {
|
||||
$control = $control->toPixel();
|
||||
$controlPoints[] = round($control->x, self::PRECISION) . " " . round($control->y, self::PRECISION);
|
||||
$control = $control->multiply($scale / Constants::TWIP_SIZE);
|
||||
$controlPoints[] = round($control->x, $precision) . " " . round($control->y, $precision);
|
||||
}
|
||||
|
||||
$commands[] = "s " . implode(" ", $controlPoints) . " " . round($anchor->x, self::PRECISION) . " " . round($anchor->y, self::PRECISION);
|
||||
$commands[] = "s " . implode(" ", $controlPoints) . " " . round($anchor->x, $precision) . " " . round($anchor->y, $precision);
|
||||
}
|
||||
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue