def reset(self): """ reset internal data here Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding """ #['Format','Name','Fontname','Fontsize','PrimaryColour','SecondaryColour','OutlineColour','BackColour','Bold','Italic', #'Underline','StrikeOut','ScaleX','ScaleY','Spacing','Angle','BorderStyle','Outline','Shadow','Alignment','MarginL','MarginR','MarginV','Encoding'] self.name = '' self.fontname = '' self.fontsize = '' self.primary_color = AssColor() self.secondary_color = AssColor() self.outline_color = AssColor() self.back_color = AssColor() self.bold = False self.italic = False self.underline = False self.strikeout = False self.scalex = 0 #Modifies the width of the font. [percent] self.scaley = 0 #Modifies the height of the font. [percent] self.spacing = 0 #Extra space between characters. [pixels] self.angle = 0.0 #The origin of the rotation is defined by the alignment. Can be a floating point number. [degrees] self.borderstyle = 0 self.outline = 0 self.shadow = 0 self.alignment = 0 self.margin_l = 0 self.margin_r = 0 self.margin_v = 0 self.encoding = 0
class AssEntryStyle(AssEntry): """ AssStyle类 实现[Stlyes] Section中的Stlye项目存储和操作 V4.0+ Format: Name, Fontname, Fontsize, #3 PrimaryColour, SecondaryColour, OutlineColour, BackColour, #4 Bold, Italic, #2 Underline, StrikeOut, #2 ScaleX, ScaleY, Spacing, Angle, #4 BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, #7 Encoding #1 V4.0 Format: Name, Fontname, Fontsize, #3 PrimaryColour, SecondaryColour, TertiaryColour, BackColour, #4 Bold, Italic, #2 #0 #0 BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, #7 AlphaLevel, #1 Encoding #1 """ def __init__(self, data, section, version): AssEntry.__init__(self, data, section) self.type = ENTRY_STYLE self.reset() self.need_update = False self.parse(self.data, version) def reset(self): """ reset internal data here Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding """ #['Format','Name','Fontname','Fontsize','PrimaryColour','SecondaryColour','OutlineColour','BackColour','Bold','Italic', #'Underline','StrikeOut','ScaleX','ScaleY','Spacing','Angle','BorderStyle','Outline','Shadow','Alignment','MarginL','MarginR','MarginV','Encoding'] self.name = '' self.fontname = '' self.fontsize = '' self.primary_color = AssColor() self.secondary_color = AssColor() self.outline_color = AssColor() self.back_color = AssColor() self.bold = False self.italic = False self.underline = False self.strikeout = False self.scalex = 0 #Modifies the width of the font. [percent] self.scaley = 0 #Modifies the height of the font. [percent] self.spacing = 0 #Extra space between characters. [pixels] self.angle = 0.0 #The origin of the rotation is defined by the alignment. Can be a floating point number. [degrees] self.borderstyle = 0 self.outline = 0 self.shadow = 0 self.alignment = 0 self.margin_l = 0 self.margin_r = 0 self.margin_v = 0 self.encoding = 0 def get_type(self): return ENTRY_STYLE def parse(self, line, version): """ parse ass style here Note: 1. """ try: style_list = line.split(':', 1) if style_list[0].lower() != 'style': #self.reset() raise InvaildDataError('Invaild Data <%s>' % (line)) return style_list = style_list[1].split(',') #parse i = 0 self.name = style_list[i].strip() #0 i += 1 self.fontname = style_list[i].strip() #1 i += 1 self.fontsize = int(style_list[i]) #2 i += 1 self.primary_color.set(style_list[i].strip()) #3 i += 1 self.secondary_color.set(style_list[i].strip()) #4 i += 1 self.outline_color.set(style_list[i].strip()) #5 i += 1 self.back_color.set(style_list[i].strip()) #6 if version is 0: #SSA uses BackColour for both outline and shadow, this will destroy SSA's TertiaryColour self.outline_color = self.back_color #ssa color i += 1 self.bold = int(style_list[i]) and True or False #7 i += 1 self.italic = int(style_list[i]) and True or False #8 if version is not 0: i += 1 self.underline = int(style_list[i]) and True or False #9 i += 1 self.strikeout = int(style_list[i]) and True or False #10 i += 1 self.scalex = float(style_list[i]) #11 i += 1 self.scaley = float(style_list[i]) #12 i += 1 self.spacing = float(style_list[i]) #13 i += 1 self.angle = float(style_list[i]) #14 else: self.underline = False self.strikeout = False self.scalex = 100 self.scaley = 100 self.spacing = 0 self.angle = 0.0 i += 1 self.borderstyle = int(style_list[i]) #15 / #15-6 for ssa i += 1 self.outline = int(style_list[i]) #16 / #16-6 for ssa i += 1 self.shadow = int(style_list[i]) #17 / #17-6 for ssa i += 1 self.alignment = int(style_list[i]) #18 / #18-6 for ssa i += 1 self.margin_l = int(style_list[i]) #19 / #19-6 for ssa i += 1 self.margin_r = int(style_list[i]) #20 / #20-6 for ssa i += 1 self.margin_v = int(style_list[i]) #21 / #21-6 for ssa #Note: 如果是version=2, 即v4.0++ 则包含4个margin参数 #TODO: if version is 2: i += 1 self.margin_4 = int(style_list[i]) #22 if version is 0: i += 1 i += 1 self.encoding = int(style_list[i]) #23-6 for ssa else: i += 1 self.encoding = int( style_list[i]) #22 / #23 for ass v4.0++ except IndexError, msg: print IndexError, ':', msg return else:
class AssEntryStyle(AssEntry): """ AssStyle类 实现[Stlyes] Section中的Stlye项目存储和操作 V4.0+ Format: Name, Fontname, Fontsize, #3 PrimaryColour, SecondaryColour, OutlineColour, BackColour, #4 Bold, Italic, #2 Underline, StrikeOut, #2 ScaleX, ScaleY, Spacing, Angle, #4 BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, #7 Encoding #1 V4.0 Format: Name, Fontname, Fontsize, #3 PrimaryColour, SecondaryColour, TertiaryColour, BackColour, #4 Bold, Italic, #2 #0 #0 BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, #7 AlphaLevel, #1 Encoding #1 """ def __init__(self, data, section, version): AssEntry.__init__(self, data, section) self.type = ENTRY_STYLE self.reset() self.need_update = False self.parse(self.data, version) def reset(self): """ reset internal data here Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding """ #['Format','Name','Fontname','Fontsize','PrimaryColour','SecondaryColour','OutlineColour','BackColour','Bold','Italic', #'Underline','StrikeOut','ScaleX','ScaleY','Spacing','Angle','BorderStyle','Outline','Shadow','Alignment','MarginL','MarginR','MarginV','Encoding'] self.name = '' self.fontname = '' self.fontsize = '' self.primary_color = AssColor() self.secondary_color = AssColor() self.outline_color = AssColor() self.back_color = AssColor() self.bold = False self.italic = False self.underline = False self.strikeout = False self.scalex = 0 #Modifies the width of the font. [percent] self.scaley = 0 #Modifies the height of the font. [percent] self.spacing = 0 #Extra space between characters. [pixels] self.angle = 0.0 #The origin of the rotation is defined by the alignment. Can be a floating point number. [degrees] self.borderstyle = 0 self.outline = 0 self.shadow = 0 self.alignment = 0 self.margin_l = 0 self.margin_r = 0 self.margin_v = 0 self.encoding = 0 def get_type(self): return ENTRY_STYLE def parse(self, line, version): """ parse ass style here Note: 1. """ try: style_list = line.split(':', 1) if style_list[0].lower() != 'style': #self.reset() raise InvaildDataError('Invaild Data <%s>' % (line) ) return style_list = style_list[1].split(',') #parse i = 0; self.name = style_list[i].strip() #0 i += 1; self.fontname = style_list[i].strip() #1 i += 1; self.fontsize = int(style_list[i]) #2 i += 1; self.primary_color.set(style_list[i].strip()) #3 i += 1; self.secondary_color.set(style_list[i].strip()) #4 i += 1; self.outline_color.set(style_list[i].strip()) #5 i += 1; self.back_color.set(style_list[i].strip()) #6 if version is 0: #SSA uses BackColour for both outline and shadow, this will destroy SSA's TertiaryColour self.outline_color= self.back_color #ssa color i += 1; self.bold = int(style_list[i]) and True or False #7 i += 1; self.italic = int(style_list[i]) and True or False #8 if version is not 0: i += 1; self.underline = int(style_list[i]) and True or False #9 i += 1; self.strikeout = int(style_list[i]) and True or False #10 i += 1; self.scalex = float(style_list[i]) #11 i += 1; self.scaley = float(style_list[i]) #12 i += 1; self.spacing = float(style_list[i]) #13 i += 1; self.angle = float(style_list[i]) #14 else: self.underline = False; self.strikeout = False; self.scalex = 100; self.scaley = 100; self.spacing = 0; self.angle = 0.0; i += 1; self.borderstyle = int(style_list[i]) #15 / #15-6 for ssa i += 1; self.outline = int(style_list[i]) #16 / #16-6 for ssa i += 1; self.shadow = int(style_list[i]) #17 / #17-6 for ssa i += 1; self.alignment = int(style_list[i]) #18 / #18-6 for ssa i += 1; self.margin_l = int(style_list[i]) #19 / #19-6 for ssa i += 1; self.margin_r = int(style_list[i]) #20 / #20-6 for ssa i += 1; self.margin_v = int(style_list[i]) #21 / #21-6 for ssa #Note: 如果是version=2, 即v4.0++ 则包含4个margin参数 #TODO: if version is 2: i += 1; self.margin_4 = int(style_list[i]) #22 if version is 0: i += 1 i += 1; self.encoding = int(style_list[i]) #23-6 for ssa else: i += 1; self.encoding = int(style_list[i]) #22 / #23 for ass v4.0++ except IndexError, msg: print IndexError, ':', msg return else: