Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93

Warning: Undefined array key "page_file_edit_line" in /home/sportsfever/public_html/filemanger/edit_text_line.php on line 32
/home/sportsfe.../httpdocs/wp-conte.../plugins/embedpre.../assets/pdf/build
File: pdf.worker.js
const width = this.data.rect[2] - this.data.rect[0];
[55500] Fix | Delete
const height = this.data.rect[3] - this.data.rect[1];
[55501] Fix | Delete
const rect = rotation === 0 || rotation === 180 ? `0 0 ${width} ${height} re` : `0 0 ${height} ${width} re`;
[55502] Fix | Delete
let str = "";
[55503] Fix | Delete
if (this.backgroundColor) {
[55504] Fix | Delete
str = `${getPdfColor(this.backgroundColor, true)} ${rect} f `;
[55505] Fix | Delete
}
[55506] Fix | Delete
if (this.borderColor) {
[55507] Fix | Delete
const borderWidth = this.borderStyle.width || 1;
[55508] Fix | Delete
str += `${borderWidth} w ${getPdfColor(this.borderColor, false)} ${rect} S `;
[55509] Fix | Delete
}
[55510] Fix | Delete
return str;
[55511] Fix | Delete
}
[55512] Fix | Delete
async getOperatorList(evaluator, task, intent, renderForms, annotationStorage) {
[55513] Fix | Delete
if (renderForms && !(this instanceof SignatureWidgetAnnotation) && !this.data.noHTML && !this.data.hasOwnCanvas) {
[55514] Fix | Delete
return {
[55515] Fix | Delete
opList: new OperatorList(),
[55516] Fix | Delete
separateForm: true,
[55517] Fix | Delete
separateCanvas: false
[55518] Fix | Delete
};
[55519] Fix | Delete
}
[55520] Fix | Delete
if (!this._hasText) {
[55521] Fix | Delete
return super.getOperatorList(evaluator, task, intent, renderForms, annotationStorage);
[55522] Fix | Delete
}
[55523] Fix | Delete
const content = await this._getAppearance(evaluator, task, intent, annotationStorage);
[55524] Fix | Delete
if (this.appearance && content === null) {
[55525] Fix | Delete
return super.getOperatorList(evaluator, task, intent, renderForms, annotationStorage);
[55526] Fix | Delete
}
[55527] Fix | Delete
const opList = new OperatorList();
[55528] Fix | Delete
if (!this._defaultAppearance || content === null) {
[55529] Fix | Delete
return {
[55530] Fix | Delete
opList,
[55531] Fix | Delete
separateForm: false,
[55532] Fix | Delete
separateCanvas: false
[55533] Fix | Delete
};
[55534] Fix | Delete
}
[55535] Fix | Delete
const isUsingOwnCanvas = !!(this.data.hasOwnCanvas && intent & RenderingIntentFlag.DISPLAY);
[55536] Fix | Delete
const matrix = [1, 0, 0, 1, 0, 0];
[55537] Fix | Delete
const bbox = [0, 0, this.data.rect[2] - this.data.rect[0], this.data.rect[3] - this.data.rect[1]];
[55538] Fix | Delete
const transform = getTransformMatrix(this.data.rect, bbox, matrix);
[55539] Fix | Delete
let optionalContent;
[55540] Fix | Delete
if (this.oc) {
[55541] Fix | Delete
optionalContent = await evaluator.parseMarkedContentProps(this.oc, null);
[55542] Fix | Delete
}
[55543] Fix | Delete
if (optionalContent !== undefined) {
[55544] Fix | Delete
opList.addOp(OPS.beginMarkedContentProps, ["OC", optionalContent]);
[55545] Fix | Delete
}
[55546] Fix | Delete
opList.addOp(OPS.beginAnnotation, [this.data.id, this.data.rect, transform, this.getRotationMatrix(annotationStorage), isUsingOwnCanvas]);
[55547] Fix | Delete
const stream = new StringStream(content);
[55548] Fix | Delete
await evaluator.getOperatorList({
[55549] Fix | Delete
stream,
[55550] Fix | Delete
task,
[55551] Fix | Delete
resources: this._fieldResources.mergedResources,
[55552] Fix | Delete
operatorList: opList
[55553] Fix | Delete
});
[55554] Fix | Delete
opList.addOp(OPS.endAnnotation, []);
[55555] Fix | Delete
if (optionalContent !== undefined) {
[55556] Fix | Delete
opList.addOp(OPS.endMarkedContent, []);
[55557] Fix | Delete
}
[55558] Fix | Delete
return {
[55559] Fix | Delete
opList,
[55560] Fix | Delete
separateForm: false,
[55561] Fix | Delete
separateCanvas: isUsingOwnCanvas
[55562] Fix | Delete
};
[55563] Fix | Delete
}
[55564] Fix | Delete
_getMKDict(rotation) {
[55565] Fix | Delete
const mk = new Dict(null);
[55566] Fix | Delete
if (rotation) {
[55567] Fix | Delete
mk.set("R", rotation);
[55568] Fix | Delete
}
[55569] Fix | Delete
if (this.borderColor) {
[55570] Fix | Delete
mk.set("BC", getPdfColorArray(this.borderColor));
[55571] Fix | Delete
}
[55572] Fix | Delete
if (this.backgroundColor) {
[55573] Fix | Delete
mk.set("BG", getPdfColorArray(this.backgroundColor));
[55574] Fix | Delete
}
[55575] Fix | Delete
return mk.size > 0 ? mk : null;
[55576] Fix | Delete
}
[55577] Fix | Delete
amendSavedDict(annotationStorage, dict) {}
[55578] Fix | Delete
async save(evaluator, task, annotationStorage) {
[55579] Fix | Delete
const storageEntry = annotationStorage?.get(this.data.id);
[55580] Fix | Delete
let value = storageEntry?.value,
[55581] Fix | Delete
rotation = storageEntry?.rotation;
[55582] Fix | Delete
if (value === this.data.fieldValue || value === undefined) {
[55583] Fix | Delete
if (!this._hasValueFromXFA && rotation === undefined) {
[55584] Fix | Delete
return null;
[55585] Fix | Delete
}
[55586] Fix | Delete
value ||= this.data.fieldValue;
[55587] Fix | Delete
}
[55588] Fix | Delete
if (rotation === undefined && !this._hasValueFromXFA && Array.isArray(value) && Array.isArray(this.data.fieldValue) && value.length === this.data.fieldValue.length && value.every((x, i) => x === this.data.fieldValue[i])) {
[55589] Fix | Delete
return null;
[55590] Fix | Delete
}
[55591] Fix | Delete
if (rotation === undefined) {
[55592] Fix | Delete
rotation = this.rotation;
[55593] Fix | Delete
}
[55594] Fix | Delete
let appearance = null;
[55595] Fix | Delete
if (!this._needAppearances) {
[55596] Fix | Delete
appearance = await this._getAppearance(evaluator, task, RenderingIntentFlag.SAVE, annotationStorage);
[55597] Fix | Delete
if (appearance === null) {
[55598] Fix | Delete
return null;
[55599] Fix | Delete
}
[55600] Fix | Delete
} else {}
[55601] Fix | Delete
let needAppearances = false;
[55602] Fix | Delete
if (appearance?.needAppearances) {
[55603] Fix | Delete
needAppearances = true;
[55604] Fix | Delete
appearance = null;
[55605] Fix | Delete
}
[55606] Fix | Delete
const {
[55607] Fix | Delete
xref
[55608] Fix | Delete
} = evaluator;
[55609] Fix | Delete
const originalDict = xref.fetchIfRef(this.ref);
[55610] Fix | Delete
if (!(originalDict instanceof Dict)) {
[55611] Fix | Delete
return null;
[55612] Fix | Delete
}
[55613] Fix | Delete
const dict = new Dict(xref);
[55614] Fix | Delete
for (const key of originalDict.getKeys()) {
[55615] Fix | Delete
if (key !== "AP") {
[55616] Fix | Delete
dict.set(key, originalDict.getRaw(key));
[55617] Fix | Delete
}
[55618] Fix | Delete
}
[55619] Fix | Delete
const xfa = {
[55620] Fix | Delete
path: this.data.fieldName,
[55621] Fix | Delete
value
[55622] Fix | Delete
};
[55623] Fix | Delete
const encoder = val => isAscii(val) ? val : stringToUTF16String(val, true);
[55624] Fix | Delete
dict.set("V", Array.isArray(value) ? value.map(encoder) : encoder(value));
[55625] Fix | Delete
this.amendSavedDict(annotationStorage, dict);
[55626] Fix | Delete
const maybeMK = this._getMKDict(rotation);
[55627] Fix | Delete
if (maybeMK) {
[55628] Fix | Delete
dict.set("MK", maybeMK);
[55629] Fix | Delete
}
[55630] Fix | Delete
const buffer = [];
[55631] Fix | Delete
const changes = [{
[55632] Fix | Delete
ref: this.ref,
[55633] Fix | Delete
data: "",
[55634] Fix | Delete
xfa,
[55635] Fix | Delete
needAppearances
[55636] Fix | Delete
}];
[55637] Fix | Delete
if (appearance !== null) {
[55638] Fix | Delete
const newRef = xref.getNewTemporaryRef();
[55639] Fix | Delete
const AP = new Dict(xref);
[55640] Fix | Delete
dict.set("AP", AP);
[55641] Fix | Delete
AP.set("N", newRef);
[55642] Fix | Delete
const resources = this._getSaveFieldResources(xref);
[55643] Fix | Delete
const appearanceStream = new StringStream(appearance);
[55644] Fix | Delete
const appearanceDict = appearanceStream.dict = new Dict(xref);
[55645] Fix | Delete
appearanceDict.set("Subtype", Name.get("Form"));
[55646] Fix | Delete
appearanceDict.set("Resources", resources);
[55647] Fix | Delete
appearanceDict.set("BBox", [0, 0, this.data.rect[2] - this.data.rect[0], this.data.rect[3] - this.data.rect[1]]);
[55648] Fix | Delete
const rotationMatrix = this.getRotationMatrix(annotationStorage);
[55649] Fix | Delete
if (rotationMatrix !== IDENTITY_MATRIX) {
[55650] Fix | Delete
appearanceDict.set("Matrix", rotationMatrix);
[55651] Fix | Delete
}
[55652] Fix | Delete
await writeObject(newRef, appearanceStream, buffer, xref);
[55653] Fix | Delete
changes.push({
[55654] Fix | Delete
ref: newRef,
[55655] Fix | Delete
data: buffer.join(""),
[55656] Fix | Delete
xfa: null,
[55657] Fix | Delete
needAppearances: false
[55658] Fix | Delete
});
[55659] Fix | Delete
buffer.length = 0;
[55660] Fix | Delete
}
[55661] Fix | Delete
dict.set("M", `D:${getModificationDate()}`);
[55662] Fix | Delete
await writeObject(this.ref, dict, buffer, xref);
[55663] Fix | Delete
changes[0].data = buffer.join("");
[55664] Fix | Delete
return changes;
[55665] Fix | Delete
}
[55666] Fix | Delete
async _getAppearance(evaluator, task, intent, annotationStorage) {
[55667] Fix | Delete
const isPassword = this.hasFieldFlag(AnnotationFieldFlag.PASSWORD);
[55668] Fix | Delete
if (isPassword) {
[55669] Fix | Delete
return null;
[55670] Fix | Delete
}
[55671] Fix | Delete
const storageEntry = annotationStorage?.get(this.data.id);
[55672] Fix | Delete
let value, rotation;
[55673] Fix | Delete
if (storageEntry) {
[55674] Fix | Delete
value = storageEntry.formattedValue || storageEntry.value;
[55675] Fix | Delete
rotation = storageEntry.rotation;
[55676] Fix | Delete
}
[55677] Fix | Delete
if (rotation === undefined && value === undefined && !this._needAppearances) {
[55678] Fix | Delete
if (!this._hasValueFromXFA || this.appearance) {
[55679] Fix | Delete
return null;
[55680] Fix | Delete
}
[55681] Fix | Delete
}
[55682] Fix | Delete
const colors = this.getBorderAndBackgroundAppearances(annotationStorage);
[55683] Fix | Delete
if (value === undefined) {
[55684] Fix | Delete
value = this.data.fieldValue;
[55685] Fix | Delete
if (!value) {
[55686] Fix | Delete
return `/Tx BMC q ${colors}Q EMC`;
[55687] Fix | Delete
}
[55688] Fix | Delete
}
[55689] Fix | Delete
if (Array.isArray(value) && value.length === 1) {
[55690] Fix | Delete
value = value[0];
[55691] Fix | Delete
}
[55692] Fix | Delete
assert(typeof value === "string", "Expected `value` to be a string.");
[55693] Fix | Delete
value = value.trim();
[55694] Fix | Delete
if (this.data.combo) {
[55695] Fix | Delete
const option = this.data.options.find(({
[55696] Fix | Delete
exportValue
[55697] Fix | Delete
}) => value === exportValue);
[55698] Fix | Delete
value = option?.displayValue || value;
[55699] Fix | Delete
}
[55700] Fix | Delete
if (value === "") {
[55701] Fix | Delete
return `/Tx BMC q ${colors}Q EMC`;
[55702] Fix | Delete
}
[55703] Fix | Delete
if (rotation === undefined) {
[55704] Fix | Delete
rotation = this.rotation;
[55705] Fix | Delete
}
[55706] Fix | Delete
let lineCount = -1;
[55707] Fix | Delete
let lines;
[55708] Fix | Delete
if (this.data.multiLine) {
[55709] Fix | Delete
lines = value.split(/\r\n?|\n/).map(line => line.normalize("NFC"));
[55710] Fix | Delete
lineCount = lines.length;
[55711] Fix | Delete
} else {
[55712] Fix | Delete
lines = [value.replace(/\r\n?|\n/, "").normalize("NFC")];
[55713] Fix | Delete
}
[55714] Fix | Delete
const defaultPadding = 1;
[55715] Fix | Delete
const defaultHPadding = 2;
[55716] Fix | Delete
let totalHeight = this.data.rect[3] - this.data.rect[1];
[55717] Fix | Delete
let totalWidth = this.data.rect[2] - this.data.rect[0];
[55718] Fix | Delete
if (rotation === 90 || rotation === 270) {
[55719] Fix | Delete
[totalWidth, totalHeight] = [totalHeight, totalWidth];
[55720] Fix | Delete
}
[55721] Fix | Delete
if (!this._defaultAppearance) {
[55722] Fix | Delete
this.data.defaultAppearanceData = parseDefaultAppearance(this._defaultAppearance = "/Helvetica 0 Tf 0 g");
[55723] Fix | Delete
}
[55724] Fix | Delete
let font = await WidgetAnnotation._getFontData(evaluator, task, this.data.defaultAppearanceData, this._fieldResources.mergedResources);
[55725] Fix | Delete
let defaultAppearance, fontSize, lineHeight;
[55726] Fix | Delete
const encodedLines = [];
[55727] Fix | Delete
let encodingError = false;
[55728] Fix | Delete
for (const line of lines) {
[55729] Fix | Delete
const encodedString = font.encodeString(line);
[55730] Fix | Delete
if (encodedString.length > 1) {
[55731] Fix | Delete
encodingError = true;
[55732] Fix | Delete
}
[55733] Fix | Delete
encodedLines.push(encodedString.join(""));
[55734] Fix | Delete
}
[55735] Fix | Delete
if (encodingError && intent & RenderingIntentFlag.SAVE) {
[55736] Fix | Delete
return {
[55737] Fix | Delete
needAppearances: true
[55738] Fix | Delete
};
[55739] Fix | Delete
}
[55740] Fix | Delete
if (encodingError && this._isOffscreenCanvasSupported) {
[55741] Fix | Delete
const fontFamily = this.data.comb ? "monospace" : "sans-serif";
[55742] Fix | Delete
const fakeUnicodeFont = new FakeUnicodeFont(evaluator.xref, fontFamily);
[55743] Fix | Delete
const resources = fakeUnicodeFont.createFontResources(lines.join(""));
[55744] Fix | Delete
const newFont = resources.getRaw("Font");
[55745] Fix | Delete
if (this._fieldResources.mergedResources.has("Font")) {
[55746] Fix | Delete
const oldFont = this._fieldResources.mergedResources.get("Font");
[55747] Fix | Delete
for (const key of newFont.getKeys()) {
[55748] Fix | Delete
oldFont.set(key, newFont.getRaw(key));
[55749] Fix | Delete
}
[55750] Fix | Delete
} else {
[55751] Fix | Delete
this._fieldResources.mergedResources.set("Font", newFont);
[55752] Fix | Delete
}
[55753] Fix | Delete
const fontName = fakeUnicodeFont.fontName.name;
[55754] Fix | Delete
font = await WidgetAnnotation._getFontData(evaluator, task, {
[55755] Fix | Delete
fontName,
[55756] Fix | Delete
fontSize: 0
[55757] Fix | Delete
}, resources);
[55758] Fix | Delete
for (let i = 0, ii = encodedLines.length; i < ii; i++) {
[55759] Fix | Delete
encodedLines[i] = stringToUTF16String(lines[i]);
[55760] Fix | Delete
}
[55761] Fix | Delete
const savedDefaultAppearance = Object.assign(Object.create(null), this.data.defaultAppearanceData);
[55762] Fix | Delete
this.data.defaultAppearanceData.fontSize = 0;
[55763] Fix | Delete
this.data.defaultAppearanceData.fontName = fontName;
[55764] Fix | Delete
[defaultAppearance, fontSize, lineHeight] = this._computeFontSize(totalHeight - 2 * defaultPadding, totalWidth - 2 * defaultHPadding, value, font, lineCount);
[55765] Fix | Delete
this.data.defaultAppearanceData = savedDefaultAppearance;
[55766] Fix | Delete
} else {
[55767] Fix | Delete
if (!this._isOffscreenCanvasSupported) {
[55768] Fix | Delete
warn("_getAppearance: OffscreenCanvas is not supported, annotation may not render correctly.");
[55769] Fix | Delete
}
[55770] Fix | Delete
[defaultAppearance, fontSize, lineHeight] = this._computeFontSize(totalHeight - 2 * defaultPadding, totalWidth - 2 * defaultHPadding, value, font, lineCount);
[55771] Fix | Delete
}
[55772] Fix | Delete
let descent = font.descent;
[55773] Fix | Delete
if (isNaN(descent)) {
[55774] Fix | Delete
descent = BASELINE_FACTOR * lineHeight;
[55775] Fix | Delete
} else {
[55776] Fix | Delete
descent = Math.max(BASELINE_FACTOR * lineHeight, Math.abs(descent) * fontSize);
[55777] Fix | Delete
}
[55778] Fix | Delete
const defaultVPadding = Math.min(Math.floor((totalHeight - fontSize) / 2), defaultPadding);
[55779] Fix | Delete
const alignment = this.data.textAlignment;
[55780] Fix | Delete
if (this.data.multiLine) {
[55781] Fix | Delete
return this._getMultilineAppearance(defaultAppearance, encodedLines, font, fontSize, totalWidth, totalHeight, alignment, defaultHPadding, defaultVPadding, descent, lineHeight, annotationStorage);
[55782] Fix | Delete
}
[55783] Fix | Delete
if (this.data.comb) {
[55784] Fix | Delete
return this._getCombAppearance(defaultAppearance, font, encodedLines[0], fontSize, totalWidth, totalHeight, defaultHPadding, defaultVPadding, descent, lineHeight, annotationStorage);
[55785] Fix | Delete
}
[55786] Fix | Delete
const bottomPadding = defaultVPadding + descent;
[55787] Fix | Delete
if (alignment === 0 || alignment > 2) {
[55788] Fix | Delete
return `/Tx BMC q ${colors}BT ` + defaultAppearance + ` 1 0 0 1 ${numberToString(defaultHPadding)} ${numberToString(bottomPadding)} Tm (${escapeString(encodedLines[0])}) Tj` + " ET Q EMC";
[55789] Fix | Delete
}
[55790] Fix | Delete
const prevInfo = {
[55791] Fix | Delete
shift: 0
[55792] Fix | Delete
};
[55793] Fix | Delete
const renderedText = this._renderText(encodedLines[0], font, fontSize, totalWidth, alignment, prevInfo, defaultHPadding, bottomPadding);
[55794] Fix | Delete
return `/Tx BMC q ${colors}BT ` + defaultAppearance + ` 1 0 0 1 0 0 Tm ${renderedText}` + " ET Q EMC";
[55795] Fix | Delete
}
[55796] Fix | Delete
static async _getFontData(evaluator, task, appearanceData, resources) {
[55797] Fix | Delete
const operatorList = new OperatorList();
[55798] Fix | Delete
const initialState = {
[55799] Fix | Delete
font: null,
[55800] Fix | Delete
clone() {
[55801] Fix | Delete
return this;
[55802] Fix | Delete
}
[55803] Fix | Delete
};
[55804] Fix | Delete
const {
[55805] Fix | Delete
fontName,
[55806] Fix | Delete
fontSize
[55807] Fix | Delete
} = appearanceData;
[55808] Fix | Delete
await evaluator.handleSetFont(resources, [fontName && Name.get(fontName), fontSize], null, operatorList, task, initialState, null);
[55809] Fix | Delete
return initialState.font;
[55810] Fix | Delete
}
[55811] Fix | Delete
_getTextWidth(text, font) {
[55812] Fix | Delete
return font.charsToGlyphs(text).reduce((width, glyph) => width + glyph.width, 0) / 1000;
[55813] Fix | Delete
}
[55814] Fix | Delete
_computeFontSize(height, width, text, font, lineCount) {
[55815] Fix | Delete
let {
[55816] Fix | Delete
fontSize
[55817] Fix | Delete
} = this.data.defaultAppearanceData;
[55818] Fix | Delete
let lineHeight = (fontSize || 12) * LINE_FACTOR,
[55819] Fix | Delete
numberOfLines = Math.round(height / lineHeight);
[55820] Fix | Delete
if (!fontSize) {
[55821] Fix | Delete
const roundWithTwoDigits = x => Math.floor(x * 100) / 100;
[55822] Fix | Delete
if (lineCount === -1) {
[55823] Fix | Delete
const textWidth = this._getTextWidth(text, font);
[55824] Fix | Delete
fontSize = roundWithTwoDigits(Math.min(height / LINE_FACTOR, textWidth > width ? width / textWidth : Infinity));
[55825] Fix | Delete
numberOfLines = 1;
[55826] Fix | Delete
} else {
[55827] Fix | Delete
const lines = text.split(/\r\n?|\n/);
[55828] Fix | Delete
const cachedLines = [];
[55829] Fix | Delete
for (const line of lines) {
[55830] Fix | Delete
const encoded = font.encodeString(line).join("");
[55831] Fix | Delete
const glyphs = font.charsToGlyphs(encoded);
[55832] Fix | Delete
const positions = font.getCharPositions(encoded);
[55833] Fix | Delete
cachedLines.push({
[55834] Fix | Delete
line: encoded,
[55835] Fix | Delete
glyphs,
[55836] Fix | Delete
positions
[55837] Fix | Delete
});
[55838] Fix | Delete
}
[55839] Fix | Delete
const isTooBig = fsize => {
[55840] Fix | Delete
let totalHeight = 0;
[55841] Fix | Delete
for (const cache of cachedLines) {
[55842] Fix | Delete
const chunks = this._splitLine(null, font, fsize, width, cache);
[55843] Fix | Delete
totalHeight += chunks.length * fsize;
[55844] Fix | Delete
if (totalHeight > height) {
[55845] Fix | Delete
return true;
[55846] Fix | Delete
}
[55847] Fix | Delete
}
[55848] Fix | Delete
return false;
[55849] Fix | Delete
};
[55850] Fix | Delete
numberOfLines = Math.max(numberOfLines, lineCount);
[55851] Fix | Delete
while (true) {
[55852] Fix | Delete
lineHeight = height / numberOfLines;
[55853] Fix | Delete
fontSize = roundWithTwoDigits(lineHeight / LINE_FACTOR);
[55854] Fix | Delete
if (isTooBig(fontSize)) {
[55855] Fix | Delete
numberOfLines++;
[55856] Fix | Delete
continue;
[55857] Fix | Delete
}
[55858] Fix | Delete
break;
[55859] Fix | Delete
}
[55860] Fix | Delete
}
[55861] Fix | Delete
const {
[55862] Fix | Delete
fontName,
[55863] Fix | Delete
fontColor
[55864] Fix | Delete
} = this.data.defaultAppearanceData;
[55865] Fix | Delete
this._defaultAppearance = createDefaultAppearance({
[55866] Fix | Delete
fontSize,
[55867] Fix | Delete
fontName,
[55868] Fix | Delete
fontColor
[55869] Fix | Delete
});
[55870] Fix | Delete
}
[55871] Fix | Delete
return [this._defaultAppearance, fontSize, height / numberOfLines];
[55872] Fix | Delete
}
[55873] Fix | Delete
_renderText(text, font, fontSize, totalWidth, alignment, prevInfo, hPadding, vPadding) {
[55874] Fix | Delete
let shift;
[55875] Fix | Delete
if (alignment === 1) {
[55876] Fix | Delete
const width = this._getTextWidth(text, font) * fontSize;
[55877] Fix | Delete
shift = (totalWidth - width) / 2;
[55878] Fix | Delete
} else if (alignment === 2) {
[55879] Fix | Delete
const width = this._getTextWidth(text, font) * fontSize;
[55880] Fix | Delete
shift = totalWidth - width - hPadding;
[55881] Fix | Delete
} else {
[55882] Fix | Delete
shift = hPadding;
[55883] Fix | Delete
}
[55884] Fix | Delete
const shiftStr = numberToString(shift - prevInfo.shift);
[55885] Fix | Delete
prevInfo.shift = shift;
[55886] Fix | Delete
vPadding = numberToString(vPadding);
[55887] Fix | Delete
return `${shiftStr} ${vPadding} Td (${escapeString(text)}) Tj`;
[55888] Fix | Delete
}
[55889] Fix | Delete
_getSaveFieldResources(xref) {
[55890] Fix | Delete
const {
[55891] Fix | Delete
localResources,
[55892] Fix | Delete
appearanceResources,
[55893] Fix | Delete
acroFormResources
[55894] Fix | Delete
} = this._fieldResources;
[55895] Fix | Delete
const fontName = this.data.defaultAppearanceData?.fontName;
[55896] Fix | Delete
if (!fontName) {
[55897] Fix | Delete
return localResources || Dict.empty;
[55898] Fix | Delete
}
[55899] Fix | Delete
for (const resources of [localResources, appearanceResources]) {
[55900] Fix | Delete
if (resources instanceof Dict) {
[55901] Fix | Delete
const localFont = resources.get("Font");
[55902] Fix | Delete
if (localFont instanceof Dict && localFont.has(fontName)) {
[55903] Fix | Delete
return resources;
[55904] Fix | Delete
}
[55905] Fix | Delete
}
[55906] Fix | Delete
}
[55907] Fix | Delete
if (acroFormResources instanceof Dict) {
[55908] Fix | Delete
const acroFormFont = acroFormResources.get("Font");
[55909] Fix | Delete
if (acroFormFont instanceof Dict && acroFormFont.has(fontName)) {
[55910] Fix | Delete
const subFontDict = new Dict(xref);
[55911] Fix | Delete
subFontDict.set(fontName, acroFormFont.getRaw(fontName));
[55912] Fix | Delete
const subResourcesDict = new Dict(xref);
[55913] Fix | Delete
subResourcesDict.set("Font", subFontDict);
[55914] Fix | Delete
return Dict.merge({
[55915] Fix | Delete
xref,
[55916] Fix | Delete
dictArray: [subResourcesDict, localResources],
[55917] Fix | Delete
mergeSubDicts: true
[55918] Fix | Delete
});
[55919] Fix | Delete
}
[55920] Fix | Delete
}
[55921] Fix | Delete
return localResources || Dict.empty;
[55922] Fix | Delete
}
[55923] Fix | Delete
getFieldObject() {
[55924] Fix | Delete
return null;
[55925] Fix | Delete
}
[55926] Fix | Delete
}
[55927] Fix | Delete
class TextWidgetAnnotation extends WidgetAnnotation {
[55928] Fix | Delete
constructor(params) {
[55929] Fix | Delete
super(params);
[55930] Fix | Delete
this.data.hasOwnCanvas = this.data.readOnly && !this.data.noHTML;
[55931] Fix | Delete
this._hasText = true;
[55932] Fix | Delete
const dict = params.dict;
[55933] Fix | Delete
if (typeof this.data.fieldValue !== "string") {
[55934] Fix | Delete
this.data.fieldValue = "";
[55935] Fix | Delete
}
[55936] Fix | Delete
let alignment = getInheritableProperty({
[55937] Fix | Delete
dict,
[55938] Fix | Delete
key: "Q"
[55939] Fix | Delete
});
[55940] Fix | Delete
if (!Number.isInteger(alignment) || alignment < 0 || alignment > 2) {
[55941] Fix | Delete
alignment = null;
[55942] Fix | Delete
}
[55943] Fix | Delete
this.data.textAlignment = alignment;
[55944] Fix | Delete
let maximumLength = getInheritableProperty({
[55945] Fix | Delete
dict,
[55946] Fix | Delete
key: "MaxLen"
[55947] Fix | Delete
});
[55948] Fix | Delete
if (!Number.isInteger(maximumLength) || maximumLength < 0) {
[55949] Fix | Delete
maximumLength = 0;
[55950] Fix | Delete
}
[55951] Fix | Delete
this.data.maxLen = maximumLength;
[55952] Fix | Delete
this.data.multiLine = this.hasFieldFlag(AnnotationFieldFlag.MULTILINE);
[55953] Fix | Delete
this.data.comb = this.hasFieldFlag(AnnotationFieldFlag.COMB) && !this.hasFieldFlag(AnnotationFieldFlag.MULTILINE) && !this.hasFieldFlag(AnnotationFieldFlag.PASSWORD) && !this.hasFieldFlag(AnnotationFieldFlag.FILESELECT) && this.data.maxLen !== 0;
[55954] Fix | Delete
this.data.doNotScroll = this.hasFieldFlag(AnnotationFieldFlag.DONOTSCROLL);
[55955] Fix | Delete
}
[55956] Fix | Delete
get hasTextContent() {
[55957] Fix | Delete
return !!this.appearance && !this._needAppearances;
[55958] Fix | Delete
}
[55959] Fix | Delete
_getCombAppearance(defaultAppearance, font, text, fontSize, width, height, hPadding, vPadding, descent, lineHeight, annotationStorage) {
[55960] Fix | Delete
const combWidth = width / this.data.maxLen;
[55961] Fix | Delete
const colors = this.getBorderAndBackgroundAppearances(annotationStorage);
[55962] Fix | Delete
const buf = [];
[55963] Fix | Delete
const positions = font.getCharPositions(text);
[55964] Fix | Delete
for (const [start, end] of positions) {
[55965] Fix | Delete
buf.push(`(${escapeString(text.substring(start, end))}) Tj`);
[55966] Fix | Delete
}
[55967] Fix | Delete
const renderedComb = buf.join(` ${numberToString(combWidth)} 0 Td `);
[55968] Fix | Delete
return `/Tx BMC q ${colors}BT ` + defaultAppearance + ` 1 0 0 1 ${numberToString(hPadding)} ${numberToString(vPadding + descent)} Tm ${renderedComb}` + " ET Q EMC";
[55969] Fix | Delete
}
[55970] Fix | Delete
_getMultilineAppearance(defaultAppearance, lines, font, fontSize, width, height, alignment, hPadding, vPadding, descent, lineHeight, annotationStorage) {
[55971] Fix | Delete
const buf = [];
[55972] Fix | Delete
const totalWidth = width - 2 * hPadding;
[55973] Fix | Delete
const prevInfo = {
[55974] Fix | Delete
shift: 0
[55975] Fix | Delete
};
[55976] Fix | Delete
for (let i = 0, ii = lines.length; i < ii; i++) {
[55977] Fix | Delete
const line = lines[i];
[55978] Fix | Delete
const chunks = this._splitLine(line, font, fontSize, totalWidth);
[55979] Fix | Delete
for (let j = 0, jj = chunks.length; j < jj; j++) {
[55980] Fix | Delete
const chunk = chunks[j];
[55981] Fix | Delete
const vShift = i === 0 && j === 0 ? -vPadding - (lineHeight - descent) : -lineHeight;
[55982] Fix | Delete
buf.push(this._renderText(chunk, font, fontSize, width, alignment, prevInfo, hPadding, vShift));
[55983] Fix | Delete
}
[55984] Fix | Delete
}
[55985] Fix | Delete
const colors = this.getBorderAndBackgroundAppearances(annotationStorage);
[55986] Fix | Delete
const renderedText = buf.join("\n");
[55987] Fix | Delete
return `/Tx BMC q ${colors}BT ` + defaultAppearance + ` 1 0 0 1 0 ${numberToString(height)} Tm ${renderedText}` + " ET Q EMC";
[55988] Fix | Delete
}
[55989] Fix | Delete
_splitLine(line, font, fontSize, width, cache = {}) {
[55990] Fix | Delete
line = cache.line || line;
[55991] Fix | Delete
const glyphs = cache.glyphs || font.charsToGlyphs(line);
[55992] Fix | Delete
if (glyphs.length <= 1) {
[55993] Fix | Delete
return [line];
[55994] Fix | Delete
}
[55995] Fix | Delete
const positions = cache.positions || font.getCharPositions(line);
[55996] Fix | Delete
const scale = fontSize / 1000;
[55997] Fix | Delete
const chunks = [];
[55998] Fix | Delete
let lastSpacePosInStringStart = -1,
[55999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function