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
3 changes: 3 additions & 0 deletions src/display/filter_factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,9 @@ class DOMFilterFactory extends BaseFilterFactory {
if (!this.#_defs) {
const div = this.#document.createElement("div");
const { style } = div;
// The pdf colors are mostly in light mode (white background with a black
// foreground), so the filters are created in light mode.
style.colorScheme = "only light";
style.visibility = "hidden";
style.contain = "strict";
style.width = style.height = 0;
Expand Down
3 changes: 2 additions & 1 deletion src/display/text_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,8 @@ class TextLayer {
// OffscreenCanvas.
const canvas = document.createElement("canvas");
canvas.style.cssText =
"position:absolute;top:0;left:0;width:0;height:0;display:none";
"position:absolute;top:0;left:0;width:0;height:0;display:none;" +
"letter-spacing:normal;word-spacing:normal";
canvas.lang = lang;
document.body.append(canvas);
ctx = canvas.getContext("2d", {
Expand Down
55 changes: 55 additions & 0 deletions test/integration/text_layer_spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,61 @@ import { startBrowser } from "../test.mjs";
*/

describe("Text layer", () => {
describe("Text layout", () => {
let pages;

beforeEach(async () => {
pages = await loadAndWait(
"tracemonkey.pdf",
".textLayer .endOfContent",
100,
{
postPageSetup: async page => {
await page.evaluate(() => {
const style = document.createElement("style");
style.textContent = `
body,
#mainContainer {
letter-spacing: 5px;
word-spacing: 5px;
}
`;
document.documentElement.append(style);
});
},
}
);
});

afterEach(async () => {
await closePages(pages);
});

it("must ignore inherited text spacing styles", async () => {
await Promise.all(
pages.map(async ([_, page]) => {
const spacing = await page.evaluate(() => {
const textLayer = document.querySelector(".textLayer");
const span = textLayer.querySelector("span");
const textLayerStyle = getComputedStyle(textLayer);
const spanStyle = getComputedStyle(span);
return {
textLayerLetterSpacing: textLayerStyle.letterSpacing,
textLayerWordSpacing: textLayerStyle.wordSpacing,
spanLetterSpacing: spanStyle.letterSpacing,
spanWordSpacing: spanStyle.wordSpacing,
};
});

expect(spacing.textLayerLetterSpacing).toEqual("normal");
expect(spacing.spanLetterSpacing).toEqual("normal");
expect(["0px", "normal"]).toContain(spacing.textLayerWordSpacing);
expect(["0px", "normal"]).toContain(spacing.spanWordSpacing);
})
);
});
});

describe("Text selection", () => {
// page.mouse.move(x, y, { steps: ... }) doesn't work in Firefox, because
// puppeteer will send fractional intermediate positions and Firefox doesn't
Expand Down
2 changes: 2 additions & 0 deletions web/text_layer_builder.css
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
overflow: clip;
opacity: 1;
line-height: 1;
letter-spacing: normal;
word-spacing: normal;
text-size-adjust: none;
forced-color-adjust: none;
transform-origin: 0 0;
Expand Down
Loading