50 lines
1.6 KiB
Python
50 lines
1.6 KiB
Python
from ..filters import FFmpegChain, FFmpegFilter
|
|
from .base import OBSSource
|
|
|
|
|
|
class TextSource(OBSSource):
|
|
def __init__(self, *args, **kwargs):
|
|
super().__init__(*args, **kwargs)
|
|
self.font = None
|
|
self.size = 32
|
|
self.color = '#ffffff'
|
|
self.contents = ''
|
|
self.shadow = 0
|
|
self.shadow_color = '#000000'
|
|
|
|
def to_ffmpeg(self, scene, item):
|
|
return [FFmpegChain(
|
|
FFmpegFilter('drawtext',
|
|
expansion='none',
|
|
fontcolor=hex(self.color),
|
|
font=self.font,
|
|
fontsize=self.size,
|
|
text=self.contents,
|
|
shadowcolor=self.shadow_color,
|
|
shadowx=self.shadow,
|
|
shadowy=self.shadow,
|
|
x=item['pos']['x'],
|
|
y=item['pos']['y'],
|
|
),
|
|
overlay=False
|
|
)]
|
|
|
|
@OBSSource.type('text_gdiplus')
|
|
class GDIPlusSource(TextSource):
|
|
def load(self, data):
|
|
self.font = data['settings']['font']['face']
|
|
self.size = data['settings']['font']['size']
|
|
self.color = data['settings']['color']
|
|
|
|
import struct
|
|
def swap32(i):
|
|
return struct.unpack("<I", struct.pack(">I", i))[0]
|
|
|
|
@OBSSource.type('text_ft2_source')
|
|
class FreeType2Source(TextSource):
|
|
def load(self, data):
|
|
self.font = data['settings']['font']['face'] + ((' ' + data['settings']['font']['style']) if data['settings']['font'].get('style') else '')
|
|
self.size = data['settings']['font']['size']
|
|
self.color = swap32(data['settings']['color1'])
|
|
self.contents = data['settings']['text']
|