Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to vendoring the codepage library & general fixes. #118

Merged
merged 5 commits into from
Apr 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ help:
@echo "Valid Targets:"
@$(MAKE) -pRrq -f $(lastword $(MAKEFILE_LIST)) : 2>/dev/null | awk -v RS= -F: '/^# File/,/^# Finished Make data base/ {if ($$1 !~ "^[#._]") {print $$1}}' | sort | egrep -v -e '^[^[:alnum:]]' -e '^$@$$' | xargs

test:
deps:
@echo "Update dependencies..."
@sh ./scripts/commands/update-dependencies.sh

test: deps
@echo "Testing..."
@sh ./scripts/commands/test.sh

Expand All @@ -33,7 +37,7 @@ clean:
@echo "Cleaning build directorys."
@sh ./scripts/commands/clean.sh

rebuild: clean local
rebuild: clean deps local

cleanup:
@echo "Cleaning up build tools."
Expand Down
4 changes: 0 additions & 4 deletions README.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,11 @@ Note: Version 2.0.0 of opentype.js is not yet released, in order to use this lib

How to include the library (from the jsdelivr CDN, this cdn is recommended as they publish usage statistics for each package):
```html
<script src="https://cdn.jsdelivr.net/npm/[email protected]/cptable.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/cputils.js"></script>
<script src="https://cdn.jsdelivr.net/npm/opentype.js@^2.0.0/dist/opentype.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@sabre-js/sabre@latest/dist/sabre.min.js"></script>
```
How to include the library (from the unpkg CDN, for the more privacy minded):
```html
<script src="https://unpkg.com/[email protected]/cptable.js"></script>
<script src="https://unpkg.com/[email protected]/cputils.js"></script>
<script src="https://unpkg.com/opentype.js@^2.0.0/dist/opentype.min.js"></script>
<script src="https://unpkg.com/@sabre-js/sabre@latest/dist/sabre.min.js"></script>
```
Expand Down
4 changes: 4 additions & 0 deletions include/lib/codepage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/**
* @type {{utils:{encode:function(number,string):Array<number>,decode:function(number,ByteArray):string}}}
*/
sabre.cptable = {utils: {encode: function () {},decode: function () {}}};
9 changes: 1 addition & 8 deletions include/shared.include.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,4 @@ opentype.parse = function () {};
/**
* @typedef {Array<number>|Uint8Array}
*/
let ByteArray;

/**
* @type {{utils:{encode:function(number,string):Array<number>,decode:function(number,ByteArray):string}}}
*/
global.cptable = {utils: {encode: function () {},decode: function () {}}};

let cptable = global.cptable;
let ByteArray;
1 change: 1 addition & 0 deletions scripts/commands/clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
find "$DEBUG_BIN_DIR/" -type f -not -name .gitignore | xargs rm -f
find "$BIN_DIR/" -type f -not -name .gitignore | xargs rm -f
find "$TEMP_DIR/" -type f -not -name .gitignore | xargs rm -f
rm -rf "$TEMP_DIR/codepage"
rm -f "$TOOL_DATA_DIR/changes.cfg"
19 changes: 19 additions & 0 deletions scripts/commands/update-dependencies.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#!/bin/sh
. "$PWD/scripts/bootstrap.sh"

LOG_FILE="$PROJECT_ROOT/dependencies.log"
if [ ! -d "$TEMP_DIR/codepage" ]; then
rm -rf "$TEMP_DIR/codepage"
git clone "https://git.sheetjs.com/sheetjs/js-codepage.git" "$TEMP_DIR/codepage"
fi
pushd "$TEMP_DIR/codepage"
printf '%s\n' "Building codepage dependency..." | tee -a $LOG_FILE
git pull 2>&1 | tee -a $LOG_FILE
make 2>&1 | tee -a $LOG_FILE
bash make.sh "$TOOL_DATA_DIR/codepage.csv" "$TEMP_DIR/codepage.js" cptable 2>&1 | tee -a $LOG_FILE
printf '%s\n' '(function(){' > "$PROJECT_SOURCE_DIR/lib/codepage.js"
cat "$TEMP_DIR/codepage.js" "$TEMP_DIR/codepage/cputils.js" | sed "s#require\('./cptable'\)#cptable#" | sed 's#root\.cptable#root["cptable"]#' | sed 's#cptable = factory(cptable)#root["cptable"] = factory(cptable)#' | sed 's#cpt\.utils#cpt["utils"]#' | sed 's#{ decode: decode, encode: encode, hascp: hascp, magic: magic, cache:cache }#{ "decode": decode, "encode": encode, "hascp": hascp, "magic": magic, "cache":cache }#' >> "$PROJECT_SOURCE_DIR/lib/codepage.js"
printf '%s\n' '}).call(sabre);' >> "$PROJECT_SOURCE_DIR/lib/codepage.js"
rm -f "$TEMP_DIR/codepage.js"
printf '%s\n' "Finished building codepage dependency." | tee -a $LOG_FILE
popd
12 changes: 7 additions & 5 deletions src/__tests__/parser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ require('../util.js')
require('../global-constants.js')
require('../color.js');
require('../style.js');
require('../lib/codepage.js');
require('../text-server.js');
require('../style-override.js');
require('../subtitle-event.js');
require("../subtitle-tags.js");
Expand Down Expand Up @@ -83,13 +85,13 @@ const ssaEventKeys = [

const loadFile = (file) => {
const { readFileSync } = require('fs');
return readFileSync(__dirname+"/testfiles/" + file,"utf8");
return readFileSync(__dirname+"/testfiles/" + file,null);
}

describe("Parser", () => {
describe("#load",() => {
test("Does basic Advanced SubStation Alpha Subtitles parsing work?", () => {
const parser = new sabre.Parser(() => {});
const parser = new sabre.Parser();
const testFile = loadFile('test1.ass');
parser.load(testFile, [], (config) => {
expect(config).not.toBeNull();
Expand Down Expand Up @@ -124,7 +126,7 @@ describe("Parser", () => {
});
});
test("Does Advanced SubStation Alpha Subtitles parsing work with arbitrary format ordering?", () => {
const parser = new sabre.Parser(() => {});
const parser = new sabre.Parser();
const testFile = loadFile('test2.ass');
parser.load(testFile, [], (config) => {
expect(config).not.toBeNull();
Expand Down Expand Up @@ -160,7 +162,7 @@ describe("Parser", () => {
});
});
test("Does basic SubStation Alpha Subtitles parsing work?", () => {
const parser = new sabre.Parser(() => {});
const parser = new sabre.Parser();
const testFile = loadFile('test1.ssa');
parser.load(testFile, [], (config) => {
expect(config).not.toBeNull();
Expand Down Expand Up @@ -196,7 +198,7 @@ describe("Parser", () => {
});
});
test("Does SubStation Alpha Subtitles parsing work with arbitrary format ordering?", () => {
const parser = new sabre.Parser(() => {});
const parser = new sabre.Parser();
const testFile = loadFile('test2.ssa');
parser.load(testFile, [], (config) => {
expect(config).not.toBeNull();
Expand Down
2 changes: 2 additions & 0 deletions src/canvas-2d-shape-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@ const shape_renderer_prototype = global.Object.create(Object, {
lineTransitionTargetOverrides,
pass
) {
this._ctx.lineCap = "round";
this._ctx.lineJoin = "round";
this._setOutline(
time,
style,
Expand Down
36 changes: 36 additions & 0 deletions src/canvas-2d-text-renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -1184,6 +1184,15 @@ const text_renderer_prototype = global.Object.create(Object, {
this._strikethrough,
this._underline
);
this._ctx.globalCompositeOperation = "xor";
this._drawGlyph(
glyph,
offsetXUnscaled,
offsetYUnscaled,
false,
this._strikethrough,
this._underline
);
} else {
for (let i = -outline_x; i <= outline_x; i++) {
this._drawGlyph(
Expand All @@ -1195,6 +1204,15 @@ const text_renderer_prototype = global.Object.create(Object, {
this._underline
);
}
this._ctx.globalCompositeOperation = "xor";
this._drawGlyph(
glyph,
offsetXUnscaled,
offsetYUnscaled,
false,
this._strikethrough,
this._underline
);
}
} else {
if (outline_gt_zero) {
Expand All @@ -1220,6 +1238,15 @@ const text_renderer_prototype = global.Object.create(Object, {
this._strikethrough,
this._underline
);
this._ctx.globalCompositeOperation = "xor";
this._drawGlyph(
glyph,
offsetXUnscaled,
offsetYUnscaled,
false,
this._strikethrough,
this._underline
);
} else {
for (let i = -outline_y; i <= outline_y; i++) {
this._drawGlyph(
Expand All @@ -1231,6 +1258,15 @@ const text_renderer_prototype = global.Object.create(Object, {
this._underline
);
}
this._ctx.globalCompositeOperation = "xor";
this._drawGlyph(
glyph,
offsetXUnscaled,
offsetYUnscaled,
false,
this._strikethrough,
this._underline
);
}
}
} else {
Expand Down
Loading