diff --git a/src/converter/content.py b/src/converter/content.py index 48bb78b..59bbb79 100644 --- a/src/converter/content.py +++ b/src/converter/content.py @@ -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, @@ -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, diff --git a/src/converter/wrap/parallel.py b/src/converter/wrap/parallel.py index 365c754..3adc7b3 100644 --- a/src/converter/wrap/parallel.py +++ b/src/converter/wrap/parallel.py @@ -22,17 +22,15 @@ 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, ) @@ -40,13 +38,14 @@ def create_parallel_process( 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) @@ -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 diff --git a/src/converter/wrap/sequence.py b/src/converter/wrap/sequence.py index ec0e06f..8cede88 100644 --- a/src/converter/wrap/sequence.py +++ b/src/converter/wrap/sequence.py @@ -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: @@ -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, diff --git a/src/style/main.py b/src/style/main.py index 3f20f2e..abd5d43 100644 --- a/src/style/main.py +++ b/src/style/main.py @@ -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()