<commit_before>/**
 * libjass
 *
 * https://github.com/Arnavion/libjass
 *
 * Copyright 2013 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import { valueOrDefault, BorderStyle } from "./misc";

import { parse } from "../parser/parse";

import { Color } from "../parts/index";

import { Map } from "../utility/map";

/**
 * This class represents a single global style declaration in a {@link libjass.ASS} script. The styles can be obtained via the {@link libjass.ASS.styles} property.
 *
 * @param {!Map.<string, string>} template The template object that contains the style's properties. It is a map of the string values read from the ASS file.
 * @param {string} template["Name"] The name of the style
 * @param {string} template["Italic"] -1 if the style is italicized
 * @param {string} template["Bold"] -1 if the style is bold
 * @param {string} template["Underline"] -1 if the style is underlined
 * @param {string} template["StrikeOut"] -1 if the style is struck-through
 * @param {string} template["Fontname"] The name of the font
 * @param {string} template["Fontsize"] The size of the font
 * @param {string} template["ScaleX"] The horizontal scaling of the font
 * @param {string} template["ScaleY"] The vertical scaling of the font
 * @param {string} template["Spacing"] The letter spacing of the font
 * @param {string} template["PrimaryColour"] The primary color
 * @param {string} template["OutlineColour"] The outline color
 * @param {string} template["BackColour"] The shadow color
 * @param {string} template["Outline"] The outline thickness
 * @param {string} template["Shadow"] The shadow depth
 * @param {string} template["Alignment"] The alignment number
 * @param {string} template["MarginL"] The left margin
 * @param {string} template["MarginR"] The right margin
 * @param {string} template["MarginV"] The vertical margin
 */
export class Style {
	private _name: string;

	private _italic: boolean;
	private _bold: boolean;
	private _underline: boolean;
	private _strikeThrough: boolean;

	private _fontName: string;
	private _fontSize: number;

	private _fontScaleX: number;
	private _fontScaleY: number;

	private _letterSpacing: number;

	private _rotationZ: number;

	private _primaryColor: Color;
	private _secondaryColor: Color;
	private _outlineColor: Color;
	private _shadowColor: Color;

	private _outlineThickness: number;
	private _borderStyle: BorderStyle;

	private _shadowDepth: number;

	private _alignment: number;

	private _marginLeft: number;
	private _marginRight: number;
	private _marginVertical: number;

	constructor(template: Map<string, string>) {
		this._name = template.get("Name");
		if (this._name === undefined || this._name === null || this._name.constructor !== String) {
			throw new Error("Style doesn't have a name.");
		}

		this._italic = template.get("Italic") === "-1";
		this._bold = template.get("Bold") === "-1";
		this._underline = template.get("Underline") === "-1";
		this._strikeThrough = template.get("StrikeOut") === "-1";

		this._fontName = template.get("Fontname");
		this._fontSize = valueOrDefault(template, "Fontsize", parseFloat, value => !isNaN(value), "50");

		this._fontScaleX = valueOrDefault(template, "ScaleX", parseFloat, value => !isNaN(value), "100") / 100;
		this._fontScaleY = valueOrDefault(template, "ScaleY", parseFloat, value => !isNaN(value), "100") / 100;

		this._letterSpacing = valueOrDefault(template, "Spacing", parseFloat, value => !isNaN(value), "0");

		this._rotationZ = valueOrDefault(template, "Angle", parseFloat, value => !isNaN(value), "0");

		this._primaryColor = valueOrDefault(template, "PrimaryColour", str => <Color>parse(str, "colorWithAlpha"), null, "&H0000FFFF");
		this._secondaryColor = valueOrDefault(template, "SecondaryColour", str => <Color>parse(str, "colorWithAlpha"), null, "&H00000000");
		this._outlineColor = valueOrDefault(template, "OutlineColour", str => <Color>parse(str, "colorWithAlpha"), null, "&H00000000");
		this._shadowColor = valueOrDefault(template, "BackColour", str => <Color>parse(str, "colorWithAlpha"), null, "&H00000000");

		this._outlineThickness = valueOrDefault(template, "Outline", parseFloat, value => !isNaN(value), "1");
		this._borderStyle = valueOrDefault(template, "BorderStyle", parseInt, value => !isNaN(value), "1");

		this._shadowDepth = valueOrDefault(template, "Shadow", parseFloat, value => !isNaN(value), "1");

		this._alignment = valueOrDefault(template, "Alignment", parseInt, value => !isNaN(value), "2");<commit_msg>Use "sans-serif" as default font name for new styles.<commit_after>/**
 * libjass
 *
 * https://github.com/Arnavion/libjass
 *
 * Copyright 2013 <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

import { valueOrDefault, BorderStyle } from "./misc";

import { parse } from "../parser/parse";

import { Color } from "../parts/index";

import { Map } from "../utility/map";

/**
 * This class represents a single global style declaration in a {@link libjass.ASS} script. The styles can be obtained via the {@link libjass.ASS.styles} property.
 *
 * @param {!Map.<string, string>} template The template object that contains the style's properties. It is a map of the string values read from the ASS file.
 * @param {string} template["Name"] The name of the style
 * @param {string} template["Italic"] -1 if the style is italicized
 * @param {string} template["Bold"] -1 if the style is bold
 * @param {string} template["Underline"] -1 if the style is underlined
 * @param {string} template["StrikeOut"] -1 if the style is struck-through
 * @param {string} template["Fontname"] The name of the font
 * @param {string} template["Fontsize"] The size of the font
 * @param {string} template["ScaleX"] The horizontal scaling of the font
 * @param {string} template["ScaleY"] The vertical scaling of the font
 * @param {string} template["Spacing"] The letter spacing of the font
 * @param {string} template["PrimaryColour"] The primary color
 * @param {string} template["OutlineColour"] The outline color
 * @param {string} template["BackColour"] The shadow color
 * @param {string} template["Outline"] The outline thickness
 * @param {string} template["Shadow"] The shadow depth
 * @param {string} template["Alignment"] The alignment number
 * @param {string} template["MarginL"] The left margin
 * @param {string} template["MarginR"] The right margin
 * @param {string} template["MarginV"] The vertical margin
 */
export class Style {
	private _name: string;

	private _italic: boolean;
	private _bold: boolean;
	private _underline: boolean;
	private _strikeThrough: boolean;

	private _fontName: string;
	private _fontSize: number;

	private _fontScaleX: number;
	private _fontScaleY: number;

	private _letterSpacing: number;

	private _rotationZ: number;

	private _primaryColor: Color;
	private _secondaryColor: Color;
	private _outlineColor: Color;
	private _shadowColor: Color;

	private _outlineThickness: number;
	private _borderStyle: BorderStyle;

	private _shadowDepth: number;

	private _alignment: number;

	private _marginLeft: number;
	private _marginRight: number;
	private _marginVertical: number;

	constructor(template: Map<string, string>) {
		this._name = template.get("Name");
		if (this._name === undefined || this._name === null || this._name.constructor !== String) {
			throw new Error("Style doesn't have a name.");
		}

		this._italic = template.get("Italic") === "-1";
		this._bold = template.get("Bold") === "-1";
		this._underline = template.get("Underline") === "-1";
		this._strikeThrough = template.get("StrikeOut") === "-1";

		this._fontName = valueOrDefault(template, "Fontname", str => str, value => value.constructor === String, "sans-serif");
		this._fontSize = valueOrDefault(template, "Fontsize", parseFloat, value => !isNaN(value), "50");

		this._fontScaleX = valueOrDefault(template, "ScaleX", parseFloat, value => !isNaN(value), "100") / 100;
		this._fontScaleY = valueOrDefault(template, "ScaleY", parseFloat, value => !isNaN(value), "100") / 100;

		this._letterSpacing = valueOrDefault(template, "Spacing", parseFloat, value => !isNaN(value), "0");

		this._rotationZ = valueOrDefault(template, "Angle", parseFloat, value => !isNaN(value), "0");

		this._primaryColor = valueOrDefault(template, "PrimaryColour", str => <Color>parse(str, "colorWithAlpha"), null, "&H0000FFFF");
		this._secondaryColor = valueOrDefault(template, "SecondaryColour", str => <Color>parse(str, "colorWithAlpha"), null, "&H00000000");
		this._outlineColor = valueOrDefault(template, "OutlineColour", str => <Color>parse(str, "colorWithAlpha"), null, "&H00000000");
		this._shadowColor = valueOrDefault(template, "BackColour", str => <Color>parse(str, "colorWithAlpha"), null, "&H00000000");

		this._outlineThickness = valueOrDefault(template, "Outline", parseFloat, value => !isNaN(value), "1");
		this._borderStyle = valueOrDefault(template, "BorderStyle", parseInt, value => !isNaN(value), "1");

		this._shadowDepth = valueOrDefault(template, "Shadow", parseFloat, value => !isNaN(value), "1");

		this._alignment = valueOrDefault(template, "Alignment", parseInt, value => !isNaN(value), "2");
{'fraction_non_alphanumeric': 0.13715637008572273, 'fraction_numerical': 0.01261208000788255, 'mean_word_length': 5.211750305997552, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 45, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 6, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5067342', 'n_tokens_mistral': 3105, 'n_tokens_neox': 2920, 'n_words': 992}