Skip to content
This repository has been archived by the owner on Jul 6, 2024. It is now read-only.

Commit

Permalink
add: directionプロパティの追加実装
Browse files Browse the repository at this point in the history
  • Loading branch information
PigeonsHouse committed Jan 5, 2024
1 parent f4453bb commit a28a7d0
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 42 deletions.
69 changes: 60 additions & 9 deletions src/converter/wrap/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,18 @@ def create_parallel_process(
style.object_length, video_process=video_process
)

left_width = GraphicValue("0")
is_row = style.direction is None or style.direction.is_row()
is_reverse = style.direction is None or style.direction.is_reverse
current_graphic_length = (
(
width_px_with_padding - style.padding_right
if is_row
else height_px_with_padding - style.padding_bottom
)
if is_reverse
else (style.padding_left if is_row else style.padding_top)
)

remain_margin = GraphicValue("0")

for child_process in child_processes:
Expand All @@ -61,19 +72,59 @@ def create_parallel_process(
if child_process.video is not None:
match style.layer_mode:
case LayerMode.SINGLE:
left_width += max(
child_style.margin_left,
remain_margin,
(
child_width_with_padding,
child_height_with_padding,
) = child_style.get_size_with_padding()
child_graphic_length = (
child_width_with_padding
if is_row
else child_height_with_padding
)
if is_reverse:
current_graphic_length -= child_graphic_length
else:
current_graphic_length += (
max(
child_style.margin_left,
remain_margin,
)
if is_row
else max(
child_style.margin_top,
remain_margin,
)
)
video_process = layering_filter(
video_process,
child_process.video,
left_width,
style.padding_top + child_style.margin_top,
current_graphic_length
if is_row
else style.padding_left + child_style.margin_left,
current_graphic_length
if not is_row
else style.padding_top + child_style.margin_top,
)
if is_reverse:
current_graphic_length -= (
max(
child_style.margin_left,
remain_margin,
)
if is_row
else max(
child_style.margin_top,
remain_margin,
)
)
else:
current_graphic_length += child_graphic_length

remain_margin = (
child_style.margin_right
if is_row
else child_style.margin_bottom
)
child_width, _ = child_style.get_size_with_padding()
left_width += child_width
remain_margin = child_style.margin_right
case LayerMode.MULTI:
video_process = layering_filter(
video_process,
Expand Down
1 change: 1 addition & 0 deletions src/definition/vss.py
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,7 @@
"time-padding-end": TIME_PATTERN,
"order": "(sequence|parallel)",
"layer-mode": "(single|multi)",
"direction": "(row|column|row-reverse|column-reverse)",
"opacity": "({}|{})".format(regex.REAL_NUMBER_PATTERN, PERCENT_PATTERN),
"width": GRAPHIC_PATTERN,
"min-width": "",
Expand Down
14 changes: 14 additions & 0 deletions src/style/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
audio_system_parser,
color_and_pixel_parser,
color_parser,
direction_parser,
double_time_parser,
font_style_parser,
font_weight_parser,
Expand All @@ -26,6 +27,7 @@
from .types import (
AudioSystem,
Color,
DirectionInfo,
GraphicValue,
LayerMode,
Order,
Expand All @@ -46,6 +48,7 @@ class Style:
width: GraphicValue
height: GraphicValue
layer_mode: Optional[LayerMode]
direction: Optional[DirectionInfo]
margin_top: GraphicValue
margin_left: GraphicValue
margin_right: GraphicValue
Expand Down Expand Up @@ -91,6 +94,7 @@ def __init__(
self.width = GraphicValue("auto")
self.height = GraphicValue("auto")
self.layer_mode = None
self.direction = None
self.margin_top = GraphicValue("auto")
self.margin_left = GraphicValue("auto")
self.margin_right = GraphicValue("auto")
Expand Down Expand Up @@ -139,21 +143,27 @@ def __init__(
case "cont":
self.order = Order.SEQUENCE
self.layer_mode = LayerMode.MULTI
self.direction = DirectionInfo("row")
case "wrp":
self.order = Order.SEQUENCE
self.layer_mode = LayerMode.MULTI
self.direction = DirectionInfo("row")
case "seq":
self.order = Order.SEQUENCE
self.layer_mode = LayerMode.MULTI
self.direction = DirectionInfo("row")
case "rect":
self.order = Order.SEQUENCE
self.layer_mode = LayerMode.MULTI
self.direction = DirectionInfo("row")
case "prl":
self.order = Order.PARALLEL
self.layer_mode = LayerMode.MULTI
self.direction = DirectionInfo("row")
case "layer":
self.order = Order.PARALLEL
self.layer_mode = LayerMode.SINGLE
self.direction = DirectionInfo("row")
case "vid":
meta = ffprobe(source_value)
(
Expand Down Expand Up @@ -266,6 +276,10 @@ def __init__(
parse_value = order_parser(value)
if parse_value is not None:
self.order = parse_value
case "direction":
parse_value = direction_parser(value)
if parse_value is not None:
self.direction = parse_value
case "width":
parse_value = graphic_parser(value)
if parse_value is not None:
Expand Down
10 changes: 10 additions & 0 deletions src/style/styling_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from .types import (
AudioSystem,
Color,
DirectionInfo,
GraphicValue,
LayerMode,
Order,
Expand Down Expand Up @@ -151,6 +152,15 @@ def order_parser(
return Order.PARALLEL


def direction_parser(
value: str,
) -> Optional[DirectionInfo]:
try:
return DirectionInfo(value)
except ValueError:
return


def layer_mode_parser(
value: str,
) -> Optional[LayerMode]:
Expand Down
66 changes: 66 additions & 0 deletions src/style/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,14 @@ def __add__(self, other: GraphicValue) -> GraphicValue:
pixel = self.get_pixel() + other.get_pixel()
return GraphicValue(f"{pixel}px")

def __sub__(self, other: GraphicValue) -> GraphicValue:
pixel = self.get_pixel() - other.get_pixel()
return GraphicValue(f"{pixel}px")

def __neg__(self) -> GraphicValue:
self.value *= -1
return self

def get_pixel(self, default_value: int = 0) -> int:
return self.value if self.unit == GraphicUnit.PIXEL else default_value

Expand Down Expand Up @@ -354,3 +362,61 @@ def __str__(self) -> str:

def __repr__(self) -> str:
return "'{}'".format(self.value)


class Direction(Enum):
ROW = auto()
COLUMN = auto()

def __str__(self) -> str:
match self:
case self.ROW:
return "ROW"
case self.COLUMN:
return "COLUMN"
case _:
return ""

def __repr__(self) -> str:
match self:
case self.ROW:
return "ROW"
case self.COLUMN:
return "COLUMN"
case _:
return ""


class DirectionInfo:
direction: Direction
is_reverse: bool

def __init__(self, val: str) -> None:
match val:
case "row":
self.direction = Direction.ROW
self.is_reverse = False
case "column":
self.direction = Direction.COLUMN
self.is_reverse = False
case "row-reverse":
self.direction = Direction.ROW
self.is_reverse = True
case "column-reverse":
self.direction = Direction.COLUMN
self.is_reverse = True
case _:
raise ValueError()

def is_row(self) -> bool:
return self.direction == Direction.ROW

def __str__(self) -> str:
if self.is_reverse:
return "'{}_REVERSE'".format(self.direction)
return "'{}'".format(self.direction)

def __repr__(self) -> str:
if self.is_reverse:
return "'{}_REVERSE'".format(self.direction)
return "'{}'".format(self.direction)
66 changes: 33 additions & 33 deletions src/vsml.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,19 +181,24 @@ def element_to_content(
whole_length=GraphicValue("0"),
last_margin=GraphicValue("0"),
)
calc_width = None
calc_height = None
# シングルレイヤ(横並び)モード
if (
is_single_layer = (
style.order == Order.PARALLEL
and style.layer_mode == LayerMode.SINGLE
):
calc_width = calc_catenating_graphic_length
calc_height = calc_piling_graphic_length
# マルチレイヤ(奥行き並び)モード
else:
calc_width = calc_piling_graphic_length
calc_height = calc_piling_graphic_length
)
calc_width = (
calc_catenating_graphic_length
if is_single_layer
and style.direction is not None
and style.direction.is_row()
else calc_piling_graphic_length
)
calc_height = (
calc_catenating_graphic_length
if is_single_layer
and style.direction is not None
and not style.direction.is_row()
else calc_piling_graphic_length
)

for vsml_element_child in vsml_element_children:
# 子要素Elementの作成と配列への追加
Expand All @@ -216,40 +221,35 @@ def element_to_content(

child_style = child_content.style
# 時間計算
child_object_length = child_style.get_object_length()
if calc_object_length is not None:
calc_object_length(
wrap_object_time_info,
child_style.object_length.is_fit(),
child_style.time_margin_start,
child_style.time_padding_start,
child_object_length,
child_style.get_object_length(),
child_style.time_padding_end,
child_style.time_margin_end,
)

# 幅、高さ計算
child_width = child_style.get_width()
child_height = child_style.get_height()
if child_content.exist_video:
if calc_width is not None:
calc_width(
wrap_object_horizontal_info,
child_style.margin_left,
child_style.padding_left,
child_width,
child_style.padding_right,
child_style.margin_right,
)
if calc_height is not None:
calc_height(
wrap_object_vertical_info,
child_style.margin_top,
child_style.padding_top,
child_height,
child_style.padding_bottom,
child_style.margin_bottom,
)
calc_width(
wrap_object_horizontal_info,
child_style.margin_left,
child_style.padding_left,
child_style.get_width(),
child_style.padding_right,
child_style.margin_right,
)
calc_height(
wrap_object_vertical_info,
child_style.margin_top,
child_style.padding_top,
child_style.get_height(),
child_style.padding_bottom,
child_style.margin_bottom,
)

wrap_object_time_info.include_last_margin()
wrap_object_horizontal_info.include_last_margin()
Expand Down

0 comments on commit a28a7d0

Please sign in to comment.