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

Commit

Permalink
fix: direction周りのリファクタリング
Browse files Browse the repository at this point in the history
  • Loading branch information
PigeonsHouse committed Jan 6, 2024
1 parent a28a7d0 commit 4ea1f27
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 93 deletions.
16 changes: 4 additions & 12 deletions src/converter/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,10 @@ def get_process_by_source(
case SourceType.AUDIO:
audio_process = get_source_process(src_path, False, True)["audio"]
case SourceType.TEXT:
(
width_with_padding,
height_with_padding,
) = style.get_size_with_padding()
video_process = get_text_process(
src_path,
width_with_padding,
height_with_padding,
style.get_width_with_padding(),
style.get_height_with_padding(),
style.padding_left,
style.padding_top,
style.background_color,
Expand Down Expand Up @@ -81,13 +77,9 @@ def create_source_process(
style.padding_top.is_zero_over()
or style.padding_left.is_zero_over()
):
(
width_with_padding,
height_with_padding,
) = style.get_size_with_padding()
video_process = set_background_filter(
width=width_with_padding,
height=height_with_padding,
width=style.get_width_with_padding(),
height=style.get_height_with_padding(),
background_color=style.background_color,
video_process=video_process,
position_x=style.padding_left,
Expand Down
122 changes: 51 additions & 71 deletions src/converter/wrap/parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,30 @@ def create_parallel_process(
audio_process = None

style = vsml_content.style
(
width_px_with_padding,
height_px_with_padding,
) = style.get_size_with_padding()
width_with_padding = style.get_width_with_padding()
height_with_padding = style.get_height_with_padding()

background_color_code = get_background_color_code(style.background_color)
if vsml_content.exist_video:
video_process = get_background_process(
"{}x{}".format(
width_px_with_padding.get_pixel(),
height_px_with_padding.get_pixel(),
width_with_padding.get_pixel(),
height_with_padding.get_pixel(),
),
style.background_color,
)
video_process, _ = object_length_filter(
style.object_length, video_process=video_process
)

is_single = style.layer_mode == LayerMode.SINGLE
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
width_with_padding - style.padding_right
if is_row
else height_px_with_padding - style.padding_bottom
else height_with_padding - style.padding_bottom
)
if is_reverse
else (style.padding_left if is_row else style.padding_top)
Expand All @@ -70,70 +69,51 @@ def create_parallel_process(
child_process.audio,
)
if child_process.video is not None:
match style.layer_mode:
case LayerMode.SINGLE:
(
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,
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
# この子要素と一つ前の子要素の間のmarginの長さ
max_space = max(
(
child_style.margin_left
if is_row
else child_style.margin_top
),
remain_margin,
)
# この子要素の本体分のずらす長さ
child_graphic_length = (
child_style.get_width_with_padding()
if is_row
else child_style.get_height_with_padding()
)

remain_margin = (
child_style.margin_right
if is_row
else child_style.margin_bottom
)
case LayerMode.MULTI:
video_process = layering_filter(
video_process,
child_process.video,
style.padding_left + child_style.margin_left,
style.padding_top + child_style.margin_top,
)
case _:
raise Exception()
# 正順ならmargin分進んだ位置に、リバースなら全体から本体分戻した位置に子要素を配置
current_graphic_length += (
-child_graphic_length if is_reverse else max_space
)
# 左上の位置を指定して子要素を配置する
video_process = layering_filter(
video_process,
child_process.video,
(
current_graphic_length
if is_single and is_row
else style.padding_left + child_style.margin_left
),
(
current_graphic_length
if is_single and not is_row
else style.padding_top + child_style.margin_top
),
)
# 正順なら本体分進めておき、リバースならmargin分戻しておく
current_graphic_length += (
-max_space if is_reverse else child_graphic_length
)
# 次の周で使うmargin
remain_margin = (
child_style.margin_right
if is_row
else child_style.margin_bottom
)
if child_process.audio is not None:
audio_process = audio_merge_filter(
audio_process, child_process.audio
Expand Down
8 changes: 2 additions & 6 deletions src/converter/wrap/sequence.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@ def create_sequence_process(

style = vsml_content.style

(
width_with_padding,
height_with_padding,
) = style.get_size_with_padding()
background_color_code = get_background_color_code(style.background_color)

for child_process in child_processes:
Expand All @@ -53,8 +49,8 @@ def create_sequence_process(
if child_process.video is not None:
# concatのため解像度を合わせた透明背景を設定
child_process.video = set_background_filter(
width=width_with_padding,
height=height_with_padding,
width=style.get_width_with_padding(),
height=style.get_height_with_padding(),
background_color=style.background_color,
video_process=child_process.video,
fit_video_process=True,
Expand Down
9 changes: 5 additions & 4 deletions src/style/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,12 +508,13 @@ def _get_info_from_meta(
def __repr__(self) -> str:
return str(vars(self))

def get_size_with_padding(self) -> tuple[GraphicValue, GraphicValue]:
def get_width_with_padding(self) -> GraphicValue:
width = self.get_width()
return width + self.padding_left + self.padding_right

def get_height_with_padding(self) -> GraphicValue:
height = self.get_height()
width_with_padding = width + self.padding_left + self.padding_right
height_with_padding = height + self.padding_top + self.padding_bottom
return width_with_padding, height_with_padding
return height + self.padding_top + self.padding_bottom

def get_object_length_with_padding(self) -> TimeValue:
object_length = self.get_object_length()
Expand Down

0 comments on commit 4ea1f27

Please sign in to comment.