/* 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", `
muffin fish
`, ["muffin fish"]); // The source text for this contrived ligature contains surrogate pairs. addSourceTextTest("testNonBmpLigature", `𝐀𝐁
`, [ "\u{1D400}\u{1D401}", ]); addSourceTextTest( "testFontFeatureSettings", `2
`, ["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", ``, ["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", `coffin
`, ["coffin"] ); addSourceTextTest( "testGeneratedContent", ``, ["affirm"] ); addSourceTextTest("testInput", ``, ["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", ``, texts => { is(texts.length, 1, "Got password text"); ok(!/[a-z]/.test(texts[0]), "Password not exposed"); } );