Skip to content
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
9 changes: 9 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import noUnsanitized from "eslint-plugin-no-unsanitized";
import perfectionist from "eslint-plugin-perfectionist";
import preferMathClamp from "./external/eslint_plugins/prefer-math-clamp.mjs";
import prettierRecommended from "eslint-plugin-prettier/recommended";
import regexpPlugin from "eslint-plugin-regexp";
import unicorn from "eslint-plugin-unicorn";

const jsFiles = folder => {
Expand Down Expand Up @@ -55,6 +56,14 @@ export default [
\* ======================================================================== */

prettierRecommended,
{
files: jsFiles("."),
plugins: regexpPlugin.configs["flat/recommended"].plugins,
rules: {
...regexpPlugin.configs["flat/recommended"].rules,
"regexp/no-legacy-features": "off",
},
},
{
files: ["**/*.json", "**/.*.json"],
language: "json/json",
Expand Down
2 changes: 1 addition & 1 deletion extensions/chromium/contentscript.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ function watchObjectOrEmbed(elem) {
// <embed src> <object data>
var srcAttribute = "src" in elem ? "src" : "data";
var path = elem[srcAttribute];
if (!mimeType && !/\.pdf($|[?#])/i.test(path)) {
if (!mimeType && !/\.pdf(?:$|[?#])/i.test(path)) {
return;
}

Expand Down
3 changes: 2 additions & 1 deletion external/builder/builder.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function preprocess(inFilename, outFilename, defines) {
}
}
function expand(line) {
line = line.replaceAll(/__[\w]+__/g, function (variable) {
line = line.replaceAll(/__\w+__/g, function (variable) {
variable = variable.substring(2, variable.length - 2);
if (variable in defines) {
return defines[variable];
Expand All @@ -158,6 +158,7 @@ function preprocess(inFilename, outFilename, defines) {
let state = STATE_NONE;
const stack = [];
const control =
// eslint-disable-next-line regexp/no-super-linear-backtracking
/^(?:\/\/|\s*\/\*|\s*<!--)\s*#(if|elif|else|endif|expand|include|error)\b(?:\s+(.*?)(?:\*\/|-->)?$)?/;

while ((line = readLine()) !== null) {
Expand Down
2 changes: 1 addition & 1 deletion external/check_l10n/check_l10n.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ function extractFtlIds(ftlPath) {
const lines = readFileSync(ftlPath, "utf8").split("\n");
const ids = [];
for (const line of lines) {
const match = line.match(/^([a-zA-Z][a-zA-Z0-9-]*)\s*=/);
const match = line.match(/^([a-z][a-z0-9-]*)\s*=/i);
if (match) {
ids.push(match[1]);
}
Expand Down
4 changes: 2 additions & 2 deletions external/cmapscompress/parse.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/

function parseAdobeCMap(content) {
let m = /(\bbegincmap\b[\s\S]*?)\bendcmap\b/.exec(content);
let m = /(\bbegincmap\b[\s\S]+?)\bendcmap\b/.exec(content);
if (!m) {
throw new Error("cmap was not found");
}
Expand All @@ -37,7 +37,7 @@ function parseAdobeCMap(content) {
result.usecmap = m[1];
}
const re =
/(\d+)\s+(begincodespacerange|beginnotdefrange|begincidchar|begincidrange|beginbfchar|beginbfrange)\n([\s\S]*?)\n(endcodespacerange|endnotdefrange|endcidchar|endcidrange|endbfchar|endbfrange)/g;
/(\d+)\s+(begincodespacerange|beginnotdefrange|begincidchar|begincidrange|beginbfchar|beginbfrange)\n([\s\S]*?)\n(?:endcodespacerange|endnotdefrange|endcidchar|endcidrange|endbfchar|endbfrange)/g;
while ((m = re.exec(body))) {
const lines = m[3].toLowerCase().split("\n");

Expand Down
2 changes: 1 addition & 1 deletion gulpfile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1135,7 +1135,7 @@ gulp.task("locale", function () {
if (!checkDir(dirPath)) {
continue;
}
if (!/^[a-z][a-z]([a-z])?(-[A-Z][A-Z])?$/.test(locale)) {
if (!/^[a-z]{2,3}(?:-[A-Z]{2})?$/.test(locale)) {
console.log("Skipping invalid locale: " + locale);
continue;
}
Expand Down
75 changes: 75 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"eslint-plugin-no-unsanitized": "^4.1.5",
"eslint-plugin-perfectionist": "^5.9.0",
"eslint-plugin-prettier": "^5.5.5",
"eslint-plugin-regexp": "^3.1.0",
"eslint-plugin-unicorn": "^64.0.0",
"globals": "^17.6.0",
"gulp": "^5.0.1",
Expand Down
2 changes: 1 addition & 1 deletion src/core/core_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ function validateFontName(fontFamily, mustWarn = false) {
} else {
// See https://developer.mozilla.org/en-US/docs/Web/CSS/custom-ident.
for (const ident of fontFamily.split(/[ \t]+/)) {
if (/^(\d|(-(\d|-)))/.test(ident) || !/^[\w-\\]+$/.test(ident)) {
if (/^(?:\d|-[\d-])/.test(ident) || !/^[\w\\-]+$/.test(ident)) {
if (mustWarn) {
warn(`FontFamily contains invalid <custom-ident>: ${fontFamily}.`);
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -1392,7 +1392,7 @@ class PDFDocument {
}
let fontFamily = descriptor.get("FontFamily");
// For example, "Wingdings 3" is not a valid font name in the css specs.
fontFamily = fontFamily.replaceAll(/[ ]+(\d)/g, "$1");
fontFamily = fontFamily.replaceAll(/ +(\d)/g, "$1");
const fontWeight = descriptor.get("FontWeight");

// Angle is expressed in degrees counterclockwise in PDF
Expand Down
11 changes: 8 additions & 3 deletions src/core/evaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -4203,9 +4203,7 @@ class PartialEvaluator {
isSerifFont(baseFontName) {
// Simulating descriptor flags attribute
const fontNameWoStyle = baseFontName.split("-", 1)[0];
return (
fontNameWoStyle in getSerifFonts() || /serif/gi.test(fontNameWoStyle)
);
return fontNameWoStyle in getSerifFonts() || /serif/i.test(fontNameWoStyle);
}

getBaseFontMetrics(name) {
Expand Down Expand Up @@ -4436,6 +4434,13 @@ class PartialEvaluator {
// FontDescriptor is only required for Type3 fonts when the document
// is a tagged pdf.
descriptor = Dict.empty;
} else if (composite) {
// Some PDFs omit the FontDescriptor on the descendant CIDFont when
// referencing one of the standard Acrobat CJK fonts via a predefined
// CMap (e.g. /Encoding /90ms-RKSJ-H with /BaseFont /HeiseiMin-W3).
// Fall through so the CMap is loaded by the composite-font path
// below; otherwise multi-byte codes would be decoded byte-by-byte.
descriptor = Dict.empty;
} else {
// Before PDF 1.5 if the font was one of the base 14 fonts, having a
// FontDescriptor was not required.
Expand Down
9 changes: 3 additions & 6 deletions src/core/font_renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,10 @@ function getFloat214(view, offset) {

function getSubroutineBias(subrs) {
const numSubrs = subrs.length;
let bias = 32768;
if (numSubrs < 1240) {
bias = 107;
} else if (numSubrs < 33900) {
bias = 1131;
if (numSubrs >= 33900) {
return 32768;
}
return bias;
return numSubrs < 1240 ? 107 : 1131;
}

function parseCmap(data, start, end) {
Expand Down
Loading
Loading