Merge pull request #17487 from calixteman/fix_final_spaces
Remove terminal white spaces when extracting text from annotation appearances
This commit is contained in:
commit
903af4ee00
@ -1195,7 +1195,7 @@ class Annotation {
|
||||
firstPosition ||= item.transform.slice(-2);
|
||||
buffer.push(item.str);
|
||||
if (item.hasEOL) {
|
||||
text.push(buffer.join(""));
|
||||
text.push(buffer.join("").trimEnd());
|
||||
buffer.length = 0;
|
||||
}
|
||||
}
|
||||
@ -1214,7 +1214,7 @@ class Annotation {
|
||||
this.reset();
|
||||
|
||||
if (buffer.length) {
|
||||
text.push(buffer.join(""));
|
||||
text.push(buffer.join("").trimEnd());
|
||||
}
|
||||
|
||||
if (text.length > 1 || text[0]) {
|
||||
@ -3788,7 +3788,9 @@ class FreeTextAnnotation extends MarkupAnnotation {
|
||||
this.data.defaultAppearanceData.fontSize ||= 10;
|
||||
const { fontColor, fontSize } = this.data.defaultAppearanceData;
|
||||
if (this._contents.str) {
|
||||
this.data.textContent = this._contents.str.split(/\r\n?|\n/);
|
||||
this.data.textContent = this._contents.str
|
||||
.split(/\r\n?|\n/)
|
||||
.map(line => line.trimEnd());
|
||||
const { coords, bbox, matrix } = FakeUnicodeFont.getFirstPositionInfo(
|
||||
this.rectangle,
|
||||
this.rotation,
|
||||
|
@ -33,6 +33,7 @@ async function runTests(results) {
|
||||
"ink_editor_spec.mjs",
|
||||
"scripting_spec.mjs",
|
||||
"stamp_editor_spec.mjs",
|
||||
"text_field_spec.mjs",
|
||||
],
|
||||
});
|
||||
|
||||
|
39
test/integration/text_field_spec.mjs
Normal file
39
test/integration/text_field_spec.mjs
Normal file
@ -0,0 +1,39 @@
|
||||
/* Copyright 2024 Mozilla Foundation
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { closePages, getSelector, loadAndWait } from "./test_utils.mjs";
|
||||
|
||||
describe("Text field", () => {
|
||||
describe("Empty text field", () => {
|
||||
let pages;
|
||||
|
||||
beforeAll(async () => {
|
||||
pages = await loadAndWait("file_pdfjs_form.pdf", getSelector("7R"));
|
||||
});
|
||||
|
||||
afterAll(async () => {
|
||||
await closePages(pages);
|
||||
});
|
||||
|
||||
it("must check that the field is empty although its appearance contains a white space", async () => {
|
||||
await Promise.all(
|
||||
pages.map(async ([browserName, page]) => {
|
||||
const text = await page.$eval(getSelector("7R"), el => el.value);
|
||||
expect(text).withContext(`In ${browserName}`).toEqual("");
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
1
test/pdfs/.gitignore
vendored
1
test/pdfs/.gitignore
vendored
@ -623,3 +623,4 @@
|
||||
!bug1872721.pdf
|
||||
!bug1871353.pdf
|
||||
!bug1871353.1.pdf
|
||||
!file_pdfjs_form.pdf
|
||||
|
BIN
test/pdfs/file_pdfjs_form.pdf
Executable file
BIN
test/pdfs/file_pdfjs_form.pdf
Executable file
Binary file not shown.
Loading…
Reference in New Issue
Block a user