Source code

Revision control

Copy as Markdown

Other Tools

Test Info:

/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
// These tests use pdfTest.ttf, generated by generate_pdfTest_font.py. In that
// font, glyphs which are only reachable via OpenType substitution have no cmap
// entry and the font contains no glyph names. Therefore, PDF consumers can only
// get the text for those glyphs from the source text Gecko provides.
/**
* Add a test which renders `markup` using pdfTest.ttf and asserts that the
* text in the PDF matches `expected`. See getPdfText. If `expected` is a
* function, it is called with the text instead.
*/
function addSourceTextTest(testName, markup, expected) {
addPdfTest(
testName,
PDF_TEST_FONT_STYLE + markup,
async pdf => {
await assertPdfUsesTestFont(pdf);
const texts = await getPdfText(pdf);
if (typeof expected == "function") {
expected(texts);
} else {
SimpleTest.isDeeply(texts, expected, "PDF text correct");
}
},
{ chrome: true, topLevel: true, remoteIframe: true }
);
}
addSourceTextTest("testLigature", `<p>muffin fish</p>`, ["muffin fish"]);
// The source text for this contrived ligature contains surrogate pairs.
addSourceTextTest("testNonBmpLigature", `<p>&#x1D400;&#x1D401;</p>`, [
"\u{1D400}\u{1D401}",
]);
addSourceTextTest(
"testFontFeatureSettings",
`<p style='font-feature-settings: "ssty" 1;'>2</p>`,
["2"]
);
// In inline math, the numerator and denominator of a fraction use script style
// alternates (ssty). The mi is also transformed to MATHEMATICAL ITALIC SMALL X
// before the ssty substitution.
addSourceTextTest(
"testMathScriptStyle",
`<math><mfrac><mi>x</mi><mn>2</mn></mfrac></math>`,
["x", "2"]
);
// Synthetic oblique for vertical upright text draws each glyph separately, so
// each glyph must get the correct part of the source text. Ligatures aren't
// enabled by default for vertical text, so enable them explicitly.
addSourceTextTest(
"testVerticalSyntheticOblique",
`<p style='writing-mode: vertical-rl; text-orientation: upright; font-style: italic; font-feature-settings: "liga" 1;'>coffin</p>`,
["coffin"]
);
addSourceTextTest(
"testGeneratedContent",
`<p id="p"></p><style>#p::before { content: "affirm"; }</style>`,
["affirm"]
);
addSourceTextTest("testInput", `<input value="fish">`, ["fish"]);
// The source text of a masked password must not be exposed. The mask
// characters are substituted in pdfTest.ttf, so the password would be
// visible if its source text were provided.
addSourceTextTest(
"testPassword",
`<input type="password" value="muffin">`,
texts => {
is(texts.length, 1, "Got password text");
ok(!/[a-z]/.test(texts[0]), "Password not exposed");
}
);