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

Commit

Permalink
Correctly populate subtitle file with style information.
Browse files Browse the repository at this point in the history
  • Loading branch information
LumingYin committed Apr 29, 2019
1 parent 982eeb7 commit b8600a2
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion Caption/Model/Exporter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,22 @@ enum FileType {
}

static func generateASSFromArray(arrayForCaption: [CaptionLine], episode: EpisodeProject) -> String {
let fontFamilyName = episode.styleFontFamily ?? "Helvetica"
var isBold = "0"
var isItalic = "0"
let fontFace = episode.styleFontWeight?.lowercased() ?? ""
if fontFace.contains("bold") {
isBold = "1"
}
if fontFace.contains("italic") || fontFace.contains("oblique") {
isItalic = "1"
}

let fontSize = Float(episode.styleFontSize ?? "53") ?? 53
let scaledResultingSize = "\(Int((20.0 / 53.0) * fontSize))"
let fontColor = (episode.styleFontColor ?? "ffffff").replacingOccurrences(of: "#", with: "").uppercased()
let shadow = episode.styleFontShadow == 1 ? "4" : "0"

var assString = """
[Script Info]
Collisions: Normal
Expand All @@ -39,7 +55,7 @@ enum FileType {
[V4+ Styles]
Format: Name, Fontname, Fontsize, PrimaryColour, SecondaryColour, OutlineColour, BackColour, Bold, Italic, Underline, StrikeOut, ScaleX, ScaleY, Spacing, Angle, BorderStyle, Outline, Shadow, Alignment, MarginL, MarginR, MarginV, Encoding
Style: Default,Helvetica,20,&H00FFFFFF,&HF0000000,&H00000000,&H32000000,0,0,0,0,100,100,0,0.00,1,0,4,2,5,5,15,1
Style: Default,\(fontFamilyName),\(scaledResultingSize),&H00\(fontColor),&HF0000000,&H00000000,&H32000000,\(isBold),\(isItalic),0,0,100,100,0,0.00,1,0,\(shadow),2,5,5,15,1
[Events]
Format: Layer, Start, End, Style, Name, MarginL, MarginR, MarginV, Effect, Text
Expand Down

0 comments on commit b8600a2

Please sign in to comment.