mirror of
https://github.com/mozilla/pdf.js.git
synced 2026-08-03 12:57:20 +02:00
Compare commits
No commits in common. "81c9a34fd30f64404738fbdf567a8d429f051be8" and "cb3f956a11b1621fb7249004c5713f65b310144c" have entirely different histories.
81c9a34fd3
...
cb3f956a11
@ -2546,7 +2546,6 @@ class WidgetAnnotation extends Annotation {
|
|||||||
defaultVPadding,
|
defaultVPadding,
|
||||||
descent,
|
descent,
|
||||||
lineHeight,
|
lineHeight,
|
||||||
alignment,
|
|
||||||
annotationStorage
|
annotationStorage
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -2910,7 +2909,6 @@ class TextWidgetAnnotation extends WidgetAnnotation {
|
|||||||
vPadding,
|
vPadding,
|
||||||
descent,
|
descent,
|
||||||
lineHeight,
|
lineHeight,
|
||||||
alignment,
|
|
||||||
annotationStorage
|
annotationStorage
|
||||||
) {
|
) {
|
||||||
const combWidth = width / this.data.maxLen;
|
const combWidth = width / this.data.maxLen;
|
||||||
@ -2923,19 +2921,11 @@ class TextWidgetAnnotation extends WidgetAnnotation {
|
|||||||
buf.push(`(${escapeString(text.substring(start, end))}) Tj`);
|
buf.push(`(${escapeString(text.substring(start, end))}) Tj`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const textWidth = combWidth * positions.length;
|
|
||||||
let hShift = hPadding;
|
|
||||||
if (alignment === 1) {
|
|
||||||
hShift += Math.floor((width - textWidth) / (2 * combWidth)) * combWidth;
|
|
||||||
} else if (alignment === 2) {
|
|
||||||
hShift += width - textWidth;
|
|
||||||
}
|
|
||||||
|
|
||||||
const renderedComb = buf.join(` ${numberToString(combWidth)} 0 Td `);
|
const renderedComb = buf.join(` ${numberToString(combWidth)} 0 Td `);
|
||||||
return (
|
return (
|
||||||
`/Tx BMC q ${colors}BT ` +
|
`/Tx BMC q ${colors}BT ` +
|
||||||
defaultAppearance +
|
defaultAppearance +
|
||||||
` 1 0 0 1 ${numberToString(hShift)} ${numberToString(
|
` 1 0 0 1 ${numberToString(hPadding)} ${numberToString(
|
||||||
vPadding + descent
|
vPadding + descent
|
||||||
)} Tm ${renderedComb}` +
|
)} Tm ${renderedComb}` +
|
||||||
" ET Q EMC"
|
" ET Q EMC"
|
||||||
|
|||||||
@ -28,6 +28,7 @@ import {
|
|||||||
ISOAdobeCharset,
|
ISOAdobeCharset,
|
||||||
} from "./charsets.js";
|
} from "./charsets.js";
|
||||||
import { ExpertEncoding, StandardEncoding } from "./encodings.js";
|
import { ExpertEncoding, StandardEncoding } from "./encodings.js";
|
||||||
|
import { readInt16 } from "./core_utils.js";
|
||||||
|
|
||||||
// Maximum subroutine call depth of type 2 charstrings. Matches OTS.
|
// Maximum subroutine call depth of type 2 charstrings. Matches OTS.
|
||||||
const MAX_SUBR_NESTING = 10;
|
const MAX_SUBR_NESTING = 10;
|
||||||
@ -354,7 +355,6 @@ class CFFParser {
|
|||||||
}
|
}
|
||||||
|
|
||||||
parseDict(dict) {
|
parseDict(dict) {
|
||||||
const view = new DataView(dict.buffer, dict.byteOffset, dict.bytesLength);
|
|
||||||
let pos = 0;
|
let pos = 0;
|
||||||
|
|
||||||
function parseOperand() {
|
function parseOperand() {
|
||||||
@ -362,12 +362,14 @@ class CFFParser {
|
|||||||
if (value === 30) {
|
if (value === 30) {
|
||||||
return parseFloatOperand();
|
return parseFloatOperand();
|
||||||
} else if (value === 28) {
|
} else if (value === 28) {
|
||||||
value = view.getInt16(pos);
|
value = readInt16(dict, pos);
|
||||||
pos += 2;
|
pos += 2;
|
||||||
return value;
|
return value;
|
||||||
} else if (value === 29) {
|
} else if (value === 29) {
|
||||||
value = view.getInt32(pos);
|
value = dict[pos++];
|
||||||
pos += 4;
|
value = (value << 8) | dict[pos++];
|
||||||
|
value = (value << 8) | dict[pos++];
|
||||||
|
value = (value << 8) | dict[pos++];
|
||||||
return value;
|
return value;
|
||||||
} else if (value >= 32 && value <= 246) {
|
} else if (value >= 32 && value <= 246) {
|
||||||
return value - 139;
|
return value - 139;
|
||||||
@ -376,7 +378,7 @@ class CFFParser {
|
|||||||
} else if (value >= 251 && value <= 254) {
|
} else if (value >= 251 && value <= 254) {
|
||||||
return -((value - 251) * 256) - dict[pos++] - 108;
|
return -((value - 251) * 256) - dict[pos++] - 108;
|
||||||
}
|
}
|
||||||
warn(`CFFParser.parseDict: "${value}" is a reserved command.`);
|
warn('CFFParser_parseDict: "' + value + '" is a reserved command.');
|
||||||
return NaN;
|
return NaN;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -487,7 +489,6 @@ class CFFParser {
|
|||||||
if (!data || state.callDepth > MAX_SUBR_NESTING) {
|
if (!data || state.callDepth > MAX_SUBR_NESTING) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
const view = new DataView(data.buffer, data.byteOffset, data.bytesLength);
|
|
||||||
let stackSize = state.stackSize;
|
let stackSize = state.stackSize;
|
||||||
const stack = state.stack;
|
const stack = state.stack;
|
||||||
|
|
||||||
@ -512,7 +513,7 @@ class CFFParser {
|
|||||||
}
|
}
|
||||||
} else if (value === 28) {
|
} else if (value === 28) {
|
||||||
// number (16 bit)
|
// number (16 bit)
|
||||||
stack[stackSize] = view.getInt16(j);
|
stack[stackSize] = readInt16(data, j);
|
||||||
j += 2;
|
j += 2;
|
||||||
stackSize++;
|
stackSize++;
|
||||||
} else if (value === 14) {
|
} else if (value === 14) {
|
||||||
@ -538,7 +539,12 @@ class CFFParser {
|
|||||||
stackSize++;
|
stackSize++;
|
||||||
} else if (value === 255) {
|
} else if (value === 255) {
|
||||||
// number (32 bit)
|
// number (32 bit)
|
||||||
stack[stackSize] = view.getInt32(j) / 65536;
|
stack[stackSize] =
|
||||||
|
((data[j] << 24) |
|
||||||
|
(data[j + 1] << 16) |
|
||||||
|
(data[j + 2] << 8) |
|
||||||
|
data[j + 3]) /
|
||||||
|
65536;
|
||||||
j += 4;
|
j += 4;
|
||||||
stackSize++;
|
stackSize++;
|
||||||
} else if (value === 19 || value === 20) {
|
} else if (value === 19 || value === 20) {
|
||||||
|
|||||||
@ -13,16 +13,38 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { stringToBytes } from "../shared/util.js";
|
import { readUint32 } from "./core_utils.js";
|
||||||
|
import { string32 } from "../shared/util.js";
|
||||||
|
|
||||||
|
function writeInt16(dest, offset, num) {
|
||||||
|
dest[offset] = (num >> 8) & 0xff;
|
||||||
|
dest[offset + 1] = num & 0xff;
|
||||||
|
}
|
||||||
|
|
||||||
|
function writeInt32(dest, offset, num) {
|
||||||
|
dest[offset] = (num >> 24) & 0xff;
|
||||||
|
dest[offset + 1] = (num >> 16) & 0xff;
|
||||||
|
dest[offset + 2] = (num >> 8) & 0xff;
|
||||||
|
dest[offset + 3] = num & 0xff;
|
||||||
|
}
|
||||||
|
|
||||||
|
function writeData(dest, offset, data) {
|
||||||
|
if (data instanceof Uint8Array) {
|
||||||
|
dest.set(data, offset);
|
||||||
|
} else if (typeof data === "string") {
|
||||||
|
for (let i = 0, ii = data.length; i < ii; i++) {
|
||||||
|
dest[offset++] = data.charCodeAt(i) & 0xff;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const OTF_HEADER_SIZE = 12;
|
const OTF_HEADER_SIZE = 12;
|
||||||
const OTF_TABLE_ENTRY_SIZE = 16;
|
const OTF_TABLE_ENTRY_SIZE = 16;
|
||||||
|
|
||||||
class OpenTypeFileBuilder {
|
class OpenTypeFileBuilder {
|
||||||
#tables = new Map();
|
|
||||||
|
|
||||||
constructor(sfnt) {
|
constructor(sfnt) {
|
||||||
this.sfnt = sfnt;
|
this.sfnt = sfnt;
|
||||||
|
this.tables = Object.create(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
static getSearchParams(entriesCount, entrySize) {
|
static getSearchParams(entriesCount, entrySize) {
|
||||||
@ -44,86 +66,83 @@ class OpenTypeFileBuilder {
|
|||||||
let sfnt = this.sfnt;
|
let sfnt = this.sfnt;
|
||||||
|
|
||||||
// Tables needs to be written by ascendant alphabetic order
|
// Tables needs to be written by ascendant alphabetic order
|
||||||
const tables = this.#tables;
|
const tables = this.tables;
|
||||||
const tablesNames = [...tables.keys()].sort();
|
const tablesNames = Object.keys(tables);
|
||||||
|
tablesNames.sort();
|
||||||
const numTables = tablesNames.length;
|
const numTables = tablesNames.length;
|
||||||
|
|
||||||
|
let i, j, jj, table, tableName;
|
||||||
// layout the tables data
|
// layout the tables data
|
||||||
let offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
|
let offset = OTF_HEADER_SIZE + numTables * OTF_TABLE_ENTRY_SIZE;
|
||||||
const tableOffsets = [offset];
|
const tableOffsets = [offset];
|
||||||
for (let i = 0; i < numTables; i++) {
|
for (i = 0; i < numTables; i++) {
|
||||||
const table = tables.get(tablesNames[i]);
|
table = tables[tablesNames[i]];
|
||||||
const paddedLength = ((table.length + 3) & ~3) >>> 0;
|
const paddedLength = ((table.length + 3) & ~3) >>> 0;
|
||||||
offset += paddedLength;
|
offset += paddedLength;
|
||||||
tableOffsets.push(offset);
|
tableOffsets.push(offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
const file = new Uint8Array(offset),
|
const file = new Uint8Array(offset);
|
||||||
view = new DataView(file.buffer);
|
|
||||||
// write the table data first (mostly for checksum)
|
// write the table data first (mostly for checksum)
|
||||||
for (let i = 0; i < numTables; i++) {
|
for (i = 0; i < numTables; i++) {
|
||||||
const table = tables.get(tablesNames[i]);
|
table = tables[tablesNames[i]];
|
||||||
let tableOffset = tableOffsets[i];
|
writeData(file, tableOffsets[i], table);
|
||||||
|
|
||||||
if (table instanceof Uint8Array) {
|
|
||||||
file.set(table, tableOffset);
|
|
||||||
} else if (typeof table === "string") {
|
|
||||||
for (let j = 0, jj = table.length; j < jj; j++) {
|
|
||||||
file[tableOffset++] = table.charCodeAt(j) & 0xff;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// sfnt version (4 bytes)
|
// sfnt version (4 bytes)
|
||||||
if (sfnt === "true") {
|
if (sfnt === "true") {
|
||||||
// Windows hates the Mac TrueType sfnt version number
|
// Windows hates the Mac TrueType sfnt version number
|
||||||
sfnt = "\x00\x01\x00\x00";
|
sfnt = string32(0x00010000);
|
||||||
}
|
}
|
||||||
file.set(stringToBytes(sfnt), 0);
|
file[0] = sfnt.charCodeAt(0) & 0xff;
|
||||||
|
file[1] = sfnt.charCodeAt(1) & 0xff;
|
||||||
|
file[2] = sfnt.charCodeAt(2) & 0xff;
|
||||||
|
file[3] = sfnt.charCodeAt(3) & 0xff;
|
||||||
|
|
||||||
// numTables (2 bytes)
|
// numTables (2 bytes)
|
||||||
view.setInt16(4, numTables);
|
writeInt16(file, 4, numTables);
|
||||||
|
|
||||||
const searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
|
const searchParams = OpenTypeFileBuilder.getSearchParams(numTables, 16);
|
||||||
|
|
||||||
// searchRange (2 bytes)
|
// searchRange (2 bytes)
|
||||||
view.setInt16(6, searchParams.range);
|
writeInt16(file, 6, searchParams.range);
|
||||||
// entrySelector (2 bytes)
|
// entrySelector (2 bytes)
|
||||||
view.setInt16(8, searchParams.entry);
|
writeInt16(file, 8, searchParams.entry);
|
||||||
// rangeShift (2 bytes)
|
// rangeShift (2 bytes)
|
||||||
view.setInt16(10, searchParams.rangeShift);
|
writeInt16(file, 10, searchParams.rangeShift);
|
||||||
|
|
||||||
offset = OTF_HEADER_SIZE;
|
offset = OTF_HEADER_SIZE;
|
||||||
// writing table entries
|
// writing table entries
|
||||||
for (let i = 0; i < numTables; i++) {
|
for (i = 0; i < numTables; i++) {
|
||||||
const tableName = tablesNames[i];
|
tableName = tablesNames[i];
|
||||||
file.set(stringToBytes(tableName), offset);
|
file[offset] = tableName.charCodeAt(0) & 0xff;
|
||||||
|
file[offset + 1] = tableName.charCodeAt(1) & 0xff;
|
||||||
|
file[offset + 2] = tableName.charCodeAt(2) & 0xff;
|
||||||
|
file[offset + 3] = tableName.charCodeAt(3) & 0xff;
|
||||||
|
|
||||||
// checksum
|
// checksum
|
||||||
let checksum = 0;
|
let checksum = 0;
|
||||||
for (let j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
|
for (j = tableOffsets[i], jj = tableOffsets[i + 1]; j < jj; j += 4) {
|
||||||
const quad = view.getUint32(j);
|
const quad = readUint32(file, j);
|
||||||
checksum = (checksum + quad) >>> 0;
|
checksum = (checksum + quad) >>> 0;
|
||||||
}
|
}
|
||||||
view.setInt32(offset + 4, checksum);
|
writeInt32(file, offset + 4, checksum);
|
||||||
|
|
||||||
// offset
|
// offset
|
||||||
view.setInt32(offset + 8, tableOffsets[i]);
|
writeInt32(file, offset + 8, tableOffsets[i]);
|
||||||
// length
|
// length
|
||||||
view.setInt32(offset + 12, tables.get(tableName).length);
|
writeInt32(file, offset + 12, tables[tableName].length);
|
||||||
|
|
||||||
offset += OTF_TABLE_ENTRY_SIZE;
|
offset += OTF_TABLE_ENTRY_SIZE;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.#tables.clear();
|
|
||||||
return file;
|
return file;
|
||||||
}
|
}
|
||||||
|
|
||||||
addTable(tag, data) {
|
addTable(tag, data) {
|
||||||
if (this.#tables.has(tag)) {
|
if (tag in this.tables) {
|
||||||
throw new Error(`Table ${tag} already exists`);
|
throw new Error("Table " + tag + " already exists");
|
||||||
}
|
}
|
||||||
this.#tables.set(tag, data);
|
this.tables[tag] = data;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
1
test/pdfs/.gitignore
vendored
1
test/pdfs/.gitignore
vendored
@ -898,4 +898,3 @@
|
|||||||
!function_based_shading.pdf
|
!function_based_shading.pdf
|
||||||
!issue16091.pdf
|
!issue16091.pdf
|
||||||
!issue7821.pdf
|
!issue7821.pdf
|
||||||
!issue21068.pdf
|
|
||||||
|
|||||||
Binary file not shown.
@ -14075,27 +14075,5 @@
|
|||||||
"md5": "7f0f390a70228fffe95835518ec266c5",
|
"md5": "7f0f390a70228fffe95835518ec266c5",
|
||||||
"rounds": 1,
|
"rounds": 1,
|
||||||
"type": "eq"
|
"type": "eq"
|
||||||
},
|
|
||||||
{
|
|
||||||
"id": "issue21068",
|
|
||||||
"file": "pdfs/issue21068.pdf",
|
|
||||||
"md5": "69558d166186923ad9d639d91884dbd6",
|
|
||||||
"rounds": 1,
|
|
||||||
"type": "eq",
|
|
||||||
"print": true,
|
|
||||||
"annotationStorage": {
|
|
||||||
"27R": {
|
|
||||||
"value": "123"
|
|
||||||
},
|
|
||||||
"28R": {
|
|
||||||
"value": "123"
|
|
||||||
},
|
|
||||||
"29R": {
|
|
||||||
"value": "1234"
|
|
||||||
},
|
|
||||||
"30R": {
|
|
||||||
"value": "123"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user