Tags are now initialized with proper types of parameters instead of strings, or null to indicate missing parameters. This removes the need to do parse or string conversions on tag parameters.
This commit is contained in:
@@ -41,76 +41,76 @@ text
|
||||
= value:. { return new Tags.Text(value); }
|
||||
|
||||
italicTag
|
||||
= "i" value:enableDisable? { return new Tags.Italic(value); }
|
||||
= "i" value:enableDisable? { return new Tags.Italic(value || null); }
|
||||
|
||||
boldTag
|
||||
= "b" value:(decimal)? { return new Tags.Bold(value); }
|
||||
= "b" value:(decimal)? { switch (value) { case "1": return true; case "0": return false; case "": return null; default: return parseFloat(value); } }
|
||||
|
||||
underlineTag
|
||||
= "u" value:enableDisable? { return new Tags.Underline(value); }
|
||||
= "u" value:enableDisable? { return new Tags.Underline(value || null); }
|
||||
|
||||
strikeoutTag
|
||||
= "s" value:enableDisable? { return new Tags.Strikeout(value); }
|
||||
= "s" value:enableDisable? { return new Tags.Strikeout(value || null); }
|
||||
|
||||
borderTag
|
||||
= "bord" value:decimal? { return new Tags.Border(value); }
|
||||
= "bord" value:decimal? { return new Tags.Border((value !== "") ? value : null); }
|
||||
|
||||
blurTag
|
||||
= "blur" value:decimal? { return new Tags.Blur(value); }
|
||||
= "blur" value:decimal? { return new Tags.Blur((value !== "") ? value : null); }
|
||||
|
||||
fontNameTag
|
||||
= "fn" value:[^\\}]* { return new Tags.FontName(value); }
|
||||
= "fn" value:[^\\}]* { return new Tags.FontName((value !== "") ? value : null); }
|
||||
|
||||
fontSizeTag
|
||||
= "fs" value:decimal? { return new Tags.FontSize(value); }
|
||||
= "fs" value:decimal? { return new Tags.FontSize((value !== "") ? value : null); }
|
||||
|
||||
frxTag
|
||||
= "frx" value:decimal? { return new Tags.Frx(value); }
|
||||
= "frx" value:decimal? { return new Tags.Frx((value !== "") ? value : null); }
|
||||
|
||||
fryTag
|
||||
= "fry" value:decimal? { return new Tags.Fry(value); }
|
||||
= "fry" value:decimal? { return new Tags.Fry((value !== "") ? value : null); }
|
||||
|
||||
frzTag
|
||||
= "frz" value:decimal? { return new Tags.Frz(value); }
|
||||
= "frz" value:decimal? { return new Tags.Frz((value !== "") ? value : null); }
|
||||
|
||||
faxTag
|
||||
= "fax" value:decimal? { return new Tags.Fax(value); }
|
||||
= "fax" value:decimal? { return new Tags.Fax((value !== "") ? value : null); }
|
||||
|
||||
fayTag
|
||||
= "fay" value:decimal? { return new Tags.Fay(value); }
|
||||
= "fay" value:decimal? { return new Tags.Fay((value !== "") ? value : null); }
|
||||
|
||||
primaryColorTag
|
||||
= "1"? "c" value:color? { return new Tags.PrimaryColor(value); }
|
||||
= "1"? "c" value:color? { return new Tags.PrimaryColor((value !== "") ? value : null); }
|
||||
|
||||
outlineColorTag
|
||||
= "3c" value:color? { return new Tags.OutlineColor(value); }
|
||||
= "3c" value:color? { return new Tags.OutlineColor((value !== "") ? value : null); }
|
||||
|
||||
alphaTag
|
||||
= "alpha" value:alpha? { return new Tags.Alpha(value); }
|
||||
= "alpha" value:alpha? { return new Tags.Alpha((value !== "") ? value : null); }
|
||||
|
||||
primaryAlphaTag
|
||||
= "1a" value:alpha? { return new Tags.PrimaryAlpha(value); }
|
||||
= "1a" value:alpha? { return new Tags.PrimaryAlpha((value !== "") ? value : null); }
|
||||
|
||||
outlineAlphaTag
|
||||
= "3a" value:alpha? { return new Tags.OutlineAlpha(value); }
|
||||
= "3a" value:alpha? { return new Tags.OutlineAlpha((value !== "") ? value : null); }
|
||||
|
||||
alignmentTag
|
||||
= "an" value:[1-9]? { return new Tags.Alignment(value); }
|
||||
= "an" value:[1-9]? { return new Tags.Alignment((value !== "") ? parseInt(value) : null); }
|
||||
|
||||
resetTag
|
||||
= "r" value:[^\\}]* { return new Tags.Reset(value); }
|
||||
= "r" value:[^\\}]* { return new Tags.Reset((value !== "") ? value : null); }
|
||||
|
||||
posTag
|
||||
= "pos(" x:decimal "," y:decimal ")" { return new Tags.Pos(x, y); }
|
||||
|
||||
fadeTag
|
||||
= "fad(" start:decimal "," end:decimal ")" { return new Tags.Fade((parseFloat(start) || 0) / 1000, (parseFloat(end) || 0) / 1000); }
|
||||
= "fad(" start:decimal "," end:decimal ")" { start = parseFloat(start); return new Tags.Fade(parseFloat(start) / 1000, parseFloat(end) / 1000); }
|
||||
|
||||
decimal
|
||||
= value:([0-9]+ ("." [0-9]+)?) { return value[0].join("") + (value[1][0] || "") + (value[1][1] && value[1][1].join("") || ""); }
|
||||
= sign:"-"? characteristic:[0-9]+ mantissa:("." [0-9]+)? { return parseFloat(sign + characteristic.join("") + (mantissa[0] || "") + (mantissa[1] && mantissa[1].join("") || "")); }
|
||||
|
||||
enableDisable
|
||||
= "0" / "1"
|
||||
= value:("0" / "1") { return parseInt(value); }
|
||||
|
||||
hex
|
||||
= [0-9a-fA-F]
|
||||
|
||||
+27
-39
@@ -41,7 +41,7 @@ var Dialogue = function (id, parts, style, start, end, layer) {
|
||||
m_sub.style.marginTop = m_sub.style.marginBottom = (scaleX * style.marginVertical) + "px";
|
||||
|
||||
var currentItalic = style.italic;
|
||||
var currentBold = style.bold ? "bold" : "";
|
||||
var currentBold = style.bold;
|
||||
var currentUnderline = style.underline;
|
||||
var currentStrikethrough = style.strikethrough;
|
||||
|
||||
@@ -84,7 +84,10 @@ var Dialogue = function (id, parts, style, start, end, layer) {
|
||||
currentSpan.style.fontStyle = "italic";
|
||||
}
|
||||
|
||||
if (currentBold) {
|
||||
if (currentBold === true) {
|
||||
currentSpan.style.fontWeight = "bold";
|
||||
}
|
||||
else if (currentBold !== false) {
|
||||
currentSpan.style.fontWeight = currentBold;
|
||||
}
|
||||
|
||||
@@ -102,7 +105,7 @@ var Dialogue = function (id, parts, style, start, end, layer) {
|
||||
currentSpan.style.fontSize = ((72 / dpi) * scaleY * currentFontSize) + "px";
|
||||
currentSpan.style.lineHeight = (scaleY * currentFontSize) + "px";
|
||||
|
||||
currentSpan.style.color = currentPrimaryColor;
|
||||
currentSpan.style.color = currentPrimaryColor.toRGBA();
|
||||
|
||||
var blurRadius = scaleX * currentOutlineWidth;
|
||||
if (currentBlur > 0) {
|
||||
@@ -110,7 +113,7 @@ var Dialogue = function (id, parts, style, start, end, layer) {
|
||||
}
|
||||
currentSpan.style.textShadow =
|
||||
[[1, 1], [1, -1], [-1, 1], [-1, -1]].map(function (pair) {
|
||||
return pair[0] + "px " + pair[1] + "px " + blurRadius + "px " + currentOutlineColor;
|
||||
return pair[0] + "px " + pair[1] + "px " + blurRadius + "px " + currentOutlineColor.toRGBA();
|
||||
}).join(", ");
|
||||
};
|
||||
updateSpanStyles();
|
||||
@@ -127,12 +130,7 @@ var Dialogue = function (id, parts, style, start, end, layer) {
|
||||
}
|
||||
|
||||
else if (part instanceof Tags.Bold) {
|
||||
var newBold;
|
||||
switch (part.value) {
|
||||
case true: newBold = "bold"; break;
|
||||
case false: newBold = ""; break;
|
||||
default: newBold = part.value; break;
|
||||
}
|
||||
var newBold = part.value;
|
||||
if (currentBold !== newBold) {
|
||||
currentBold = newBold;
|
||||
spanStylesChanged = true;
|
||||
@@ -208,7 +206,7 @@ var Dialogue = function (id, parts, style, start, end, layer) {
|
||||
}
|
||||
|
||||
else if (part instanceof Tags.PrimaryColor) {
|
||||
var newPrimaryColor = "#" + part.value;
|
||||
var newPrimaryColor = part.value;
|
||||
if (currentPrimaryColor !== newPrimaryColor) {
|
||||
currentPrimaryColor = newPrimaryColor;
|
||||
spanStylesChanged = true;
|
||||
@@ -216,7 +214,7 @@ var Dialogue = function (id, parts, style, start, end, layer) {
|
||||
}
|
||||
|
||||
else if (part instanceof Tags.OutlineColor) {
|
||||
var newOutlineColor = "#" + part.value;
|
||||
var newOutlineColor = part.value;
|
||||
if (currentOutlineColor !== newOutlineColor) {
|
||||
currentOutlineColor = newOutlineColor;
|
||||
spanStylesChanged = true;
|
||||
@@ -243,17 +241,7 @@ var Dialogue = function (id, parts, style, start, end, layer) {
|
||||
else {
|
||||
var newStyle = this.ass.styles.filter(function (style) { return style.name === part.value; })[0];
|
||||
currentItalic = newStyle.italic;
|
||||
switch (newStyle.bold) {
|
||||
case true:
|
||||
currentBold = "bold";
|
||||
break;
|
||||
case false:
|
||||
currentBold = "";
|
||||
break;
|
||||
default:
|
||||
currentBold = newStyle.bold.value;
|
||||
break;
|
||||
}
|
||||
currentBold = newStyle.bold;
|
||||
currentUnderline = newStyle.underline;
|
||||
currentStrikethrough = newStyle.strikethrough;
|
||||
currentOutlineWidth = newStyle.outlineWidth;
|
||||
@@ -463,38 +451,38 @@ var Tags = new function () {
|
||||
}
|
||||
});
|
||||
this.Bold = this.Tag(function (value) {
|
||||
if (value === "1") {
|
||||
if (value === 1) {
|
||||
return true;
|
||||
}
|
||||
else if (value === "0") {
|
||||
else if (value === 0) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return parseFloat(value);
|
||||
return value;
|
||||
}
|
||||
});
|
||||
this.Underline = this.Tag(function (value) {
|
||||
if (value === "1") {
|
||||
if (value === 1) {
|
||||
return true;
|
||||
}
|
||||
else if (value === "0") {
|
||||
else if (value === 0) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
this.Strikeout = this.Tag();
|
||||
|
||||
this.Border = this.Tag(parseFloat);
|
||||
this.Border = this.Tag();
|
||||
|
||||
this.Blur = this.Tag(parseFloat);
|
||||
this.Blur = this.Tag();
|
||||
|
||||
this.FontName = this.Tag();
|
||||
this.FontSize = this.Tag(parseFloat);
|
||||
this.FontSize = this.Tag();
|
||||
|
||||
this.Frx = this.Tag(parseFloat);
|
||||
this.Fry = this.Tag(parseFloat);
|
||||
this.Frz = this.Tag(parseFloat);
|
||||
this.Fax = this.Tag(parseFloat);
|
||||
this.Fay = this.Tag(parseFloat);
|
||||
this.Frx = this.Tag();
|
||||
this.Fry = this.Tag();
|
||||
this.Frz = this.Tag();
|
||||
this.Fax = this.Tag();
|
||||
this.Fay = this.Tag();
|
||||
|
||||
this.PrimaryColor = this.Tag();
|
||||
this.OutlineColor = this.Tag();
|
||||
@@ -503,13 +491,13 @@ var Tags = new function () {
|
||||
this.PrimaryAlpha = this.Tag();
|
||||
this.OutlineAlpha = this.Tag();
|
||||
|
||||
this.Alignment = this.Tag(parseInt);
|
||||
this.Alignment = this.Tag();
|
||||
|
||||
this.Reset = this.Tag();
|
||||
|
||||
this.Pos = function (x, y) {
|
||||
this.x = parseFloat(x);
|
||||
this.y = parseFloat(y);
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
};
|
||||
|
||||
this.Fade = function (start, end) {
|
||||
|
||||
@@ -189,8 +189,8 @@ ASS.parse = function (rawASS, dialogueParser) {
|
||||
parseFloat(lineParts[outlineWidthIndex]),
|
||||
lineParts[fontNameIndex],
|
||||
parseFloat(lineParts[fontSizeIndex]),
|
||||
lineParts[primaryColorIndex].match(/&H([0-9a-fA-F]{8})/)[1].toRGBA(),
|
||||
lineParts[outlineColorIndex].match(/&H([0-9a-fA-F]{8})/)[1].toRGBA(),
|
||||
lineParts[primaryColorIndex].match(/&H([0-9a-fA-F]{8})/)[1],
|
||||
lineParts[outlineColorIndex].match(/&H([0-9a-fA-F]{8})/)[1],
|
||||
parseInt(lineParts[alignmentIndex]),
|
||||
parseFloat(lineParts[marginLeftIndex]),
|
||||
parseFloat(lineParts[marginRightIndex]),
|
||||
|
||||
Reference in New Issue
Block a user