/
var
/
www
/
greso.tech
/
server
/
nsm
/
node_modules
/
pdf-lib
/
es
/
core
/
embedders
/
/var/www/greso.tech/server/nsm/node_modules/pdf-lib/es/core/embedders
mkdir
upload
Name
Size
Mode
Actions
CMap.d.ts
237
0644
edit
dl
rm
CMap.d.ts.map
226
0644
edit
dl
rm
CMap.js
2125
0644
edit
dl
rm
CMap.js.map
1716
0644
edit
dl
rm
CustomFontEmbedder.d.ts
2192
0644
edit
dl
rm
CustomFontEmbedder.d.ts.map
1766
0644
edit
dl
rm
CustomFontEmbedder.js
11364
0644
edit
dl
rm
CustomFontEmbedder.js.map
7315
0644
edit
dl
rm
CustomFontSubsetEmbedder.d.ts
1003
0644
edit
dl
rm
CustomFontSubsetEmbedder.d.ts.map
731
0644
edit
dl
rm
CustomFontSubsetEmbedder.js
3101
0644
edit
dl
rm
CustomFontSubsetEmbedder.js.map
2333
0644
edit
dl
rm
FileEmbedder.d.ts
1108
0644
edit
dl
rm
FileEmbedder.d.ts.map
871
0644
edit
dl
rm
FileEmbedder.js
3405
0644
edit
dl
rm
FileEmbedder.js.map
1955
0644
edit
dl
rm
FontFlags.d.ts
395
0644
edit
dl
rm
FontFlags.d.ts.map
517
0644
edit
dl
rm
FontFlags.js
1112
0644
edit
dl
rm
FontFlags.js.map
1295
0644
edit
dl
rm
JavaScriptEmbedder.d.ts
435
0644
edit
dl
rm
JavaScriptEmbedder.d.ts.map
467
0644
edit
dl
rm
JavaScriptEmbedder.js
1285
0644
edit
dl
rm
JavaScriptEmbedder.js.map
809
0644
edit
dl
rm
JpegEmbedder.d.ts
846
0644
edit
dl
rm
JpegEmbedder.d.ts.map
613
0644
edit
dl
rm
JpegEmbedder.js
4325
0644
edit
dl
rm
JpegEmbedder.js.map
2761
0644
edit
dl
rm
PDFPageEmbedder.d.ts
1370
0644
edit
dl
rm
PDFPageEmbedder.d.ts.map
878
0644
edit
dl
rm
PDFPageEmbedder.js
4344
0644
edit
dl
rm
PDFPageEmbedder.js.map
3080
0644
edit
dl
rm
PngEmbedder.d.ts
759
0644
edit
dl
rm
PngEmbedder.d.ts.map
565
0644
edit
dl
rm
PngEmbedder.js
2533
0644
edit
dl
rm
PngEmbedder.js.map
1651
0644
edit
dl
rm
StandardFontEmbedder.d.ts
1439
0644
edit
dl
rm
StandardFontEmbedder.d.ts.map
989
0644
edit
dl
rm
StandardFontEmbedder.js
4215
0644
edit
dl
rm
StandardFontEmbedder.js.map
3662
0644
edit
dl
rm
Edit:
/var/www/greso.tech/server/nsm/node_modules/pdf-lib/es/core/embedders/CustomFontEmbedder.js
(11364B)
import { __awaiter, __generator } from "tslib"; import { createCmap } from "./CMap"; import { deriveFontFlags } from "./FontFlags"; import PDFHexString from "../objects/PDFHexString"; import PDFString from "../objects/PDFString"; import { byAscendingId, Cache, sortedUniq, toHexStringOfMinLength, } from "../../utils"; /** * A note of thanks to the developers of https://github.com/foliojs/pdfkit, as * this class borrows from: * https://github.com/devongovett/pdfkit/blob/e71edab0dd4657b5a767804ba86c94c58d01fbca/lib/image/jpeg.coffee */ var CustomFontEmbedder = /** @class */ (function () { function CustomFontEmbedder(font, fontData, customName, fontFeatures) { var _this = this; this.allGlyphsInFontSortedById = function () { var glyphs = new Array(_this.font.characterSet.length); for (var idx = 0, len = glyphs.length; idx < len; idx++) { var codePoint = _this.font.characterSet[idx]; glyphs[idx] = _this.font.glyphForCodePoint(codePoint); } return sortedUniq(glyphs.sort(byAscendingId), function (g) { return g.id; }); }; this.font = font; this.scale = 1000 / this.font.unitsPerEm; this.fontData = fontData; this.fontName = this.font.postscriptName || 'Font'; this.customName = customName; this.fontFeatures = fontFeatures; this.baseFontName = ''; this.glyphCache = Cache.populatedBy(this.allGlyphsInFontSortedById); } CustomFontEmbedder.for = function (fontkit, fontData, customName, fontFeatures) { return __awaiter(this, void 0, void 0, function () { var font; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, fontkit.create(fontData)]; case 1: font = _a.sent(); return [2 /*return*/, new CustomFontEmbedder(font, fontData, customName, fontFeatures)]; } }); }); }; /** * Encode the JavaScript string into this font. (JavaScript encodes strings in * Unicode, but embedded fonts use their own custom encodings) */ CustomFontEmbedder.prototype.encodeText = function (text) { var glyphs = this.font.layout(text, this.fontFeatures).glyphs; var hexCodes = new Array(glyphs.length); for (var idx = 0, len = glyphs.length; idx < len; idx++) { hexCodes[idx] = toHexStringOfMinLength(glyphs[idx].id, 4); } return PDFHexString.of(hexCodes.join('')); }; // The advanceWidth takes into account kerning automatically, so we don't // have to do that manually like we do for the standard fonts. CustomFontEmbedder.prototype.widthOfTextAtSize = function (text, size) { var glyphs = this.font.layout(text, this.fontFeatures).glyphs; var totalWidth = 0; for (var idx = 0, len = glyphs.length; idx < len; idx++) { totalWidth += glyphs[idx].advanceWidth * this.scale; } var scale = size / 1000; return totalWidth * scale; }; CustomFontEmbedder.prototype.heightOfFontAtSize = function (size, options) { if (options === void 0) { options = {}; } var _a = options.descender, descender = _a === void 0 ? true : _a; var _b = this.font, ascent = _b.ascent, descent = _b.descent, bbox = _b.bbox; var yTop = (ascent || bbox.maxY) * this.scale; var yBottom = (descent || bbox.minY) * this.scale; var height = yTop - yBottom; if (!descender) height -= Math.abs(descent) || 0; return (height / 1000) * size; }; CustomFontEmbedder.prototype.sizeOfFontAtHeight = function (height) { var _a = this.font, ascent = _a.ascent, descent = _a.descent, bbox = _a.bbox; var yTop = (ascent || bbox.maxY) * this.scale; var yBottom = (descent || bbox.minY) * this.scale; return (1000 * height) / (yTop - yBottom); }; CustomFontEmbedder.prototype.embedIntoContext = function (context, ref) { this.baseFontName = this.customName || context.addRandomSuffix(this.fontName); return this.embedFontDict(context, ref); }; CustomFontEmbedder.prototype.embedFontDict = function (context, ref) { return __awaiter(this, void 0, void 0, function () { var cidFontDictRef, unicodeCMapRef, fontDict; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.embedCIDFontDict(context)]; case 1: cidFontDictRef = _a.sent(); unicodeCMapRef = this.embedUnicodeCmap(context); fontDict = context.obj({ Type: 'Font', Subtype: 'Type0', BaseFont: this.baseFontName, Encoding: 'Identity-H', DescendantFonts: [cidFontDictRef], ToUnicode: unicodeCMapRef, }); if (ref) { context.assign(ref, fontDict); return [2 /*return*/, ref]; } else { return [2 /*return*/, context.register(fontDict)]; } return [2 /*return*/]; } }); }); }; CustomFontEmbedder.prototype.isCFF = function () { return this.font.cff; }; CustomFontEmbedder.prototype.embedCIDFontDict = function (context) { return __awaiter(this, void 0, void 0, function () { var fontDescriptorRef, cidFontDict; return __generator(this, function (_a) { switch (_a.label) { case 0: return [4 /*yield*/, this.embedFontDescriptor(context)]; case 1: fontDescriptorRef = _a.sent(); cidFontDict = context.obj({ Type: 'Font', Subtype: this.isCFF() ? 'CIDFontType0' : 'CIDFontType2', CIDToGIDMap: 'Identity', BaseFont: this.baseFontName, CIDSystemInfo: { Registry: PDFString.of('Adobe'), Ordering: PDFString.of('Identity'), Supplement: 0, }, FontDescriptor: fontDescriptorRef, W: this.computeWidths(), }); return [2 /*return*/, context.register(cidFontDict)]; } }); }); }; CustomFontEmbedder.prototype.embedFontDescriptor = function (context) { return __awaiter(this, void 0, void 0, function () { var fontStreamRef, scale, _a, italicAngle, ascent, descent, capHeight, xHeight, _b, minX, minY, maxX, maxY, fontDescriptor; var _c; return __generator(this, function (_d) { switch (_d.label) { case 0: return [4 /*yield*/, this.embedFontStream(context)]; case 1: fontStreamRef = _d.sent(); scale = this.scale; _a = this.font, italicAngle = _a.italicAngle, ascent = _a.ascent, descent = _a.descent, capHeight = _a.capHeight, xHeight = _a.xHeight; _b = this.font.bbox, minX = _b.minX, minY = _b.minY, maxX = _b.maxX, maxY = _b.maxY; fontDescriptor = context.obj((_c = { Type: 'FontDescriptor', FontName: this.baseFontName, Flags: deriveFontFlags(this.font), FontBBox: [minX * scale, minY * scale, maxX * scale, maxY * scale], ItalicAngle: italicAngle, Ascent: ascent * scale, Descent: descent * scale, CapHeight: (capHeight || ascent) * scale, XHeight: (xHeight || 0) * scale, // Not sure how to compute/find this, nor is anybody else really: // https://stackoverflow.com/questions/35485179/stemv-value-of-the-truetype-font StemV: 0 }, _c[this.isCFF() ? 'FontFile3' : 'FontFile2'] = fontStreamRef, _c)); return [2 /*return*/, context.register(fontDescriptor)]; } }); }); }; CustomFontEmbedder.prototype.serializeFont = function () { return __awaiter(this, void 0, void 0, function () { return __generator(this, function (_a) { return [2 /*return*/, this.fontData]; }); }); }; CustomFontEmbedder.prototype.embedFontStream = function (context) { return __awaiter(this, void 0, void 0, function () { var fontStream, _a, _b; return __generator(this, function (_c) { switch (_c.label) { case 0: _b = (_a = context).flateStream; return [4 /*yield*/, this.serializeFont()]; case 1: fontStream = _b.apply(_a, [_c.sent(), { Subtype: this.isCFF() ? 'CIDFontType0C' : undefined, }]); return [2 /*return*/, context.register(fontStream)]; } }); }); }; CustomFontEmbedder.prototype.embedUnicodeCmap = function (context) { var cmap = createCmap(this.glyphCache.access(), this.glyphId.bind(this)); var cmapStream = context.flateStream(cmap); return context.register(cmapStream); }; CustomFontEmbedder.prototype.glyphId = function (glyph) { return glyph ? glyph.id : -1; }; CustomFontEmbedder.prototype.computeWidths = function () { var glyphs = this.glyphCache.access(); var widths = []; var currSection = []; for (var idx = 0, len = glyphs.length; idx < len; idx++) { var currGlyph = glyphs[idx]; var prevGlyph = glyphs[idx - 1]; var currGlyphId = this.glyphId(currGlyph); var prevGlyphId = this.glyphId(prevGlyph); if (idx === 0) { widths.push(currGlyphId); } else if (currGlyphId - prevGlyphId !== 1) { widths.push(currSection); widths.push(currGlyphId); currSection = []; } currSection.push(currGlyph.advanceWidth * this.scale); } widths.push(currSection); return widths; }; return CustomFontEmbedder; }()); export default CustomFontEmbedder; //# sourceMappingURL=CustomFontEmbedder.js.map
Save
cmd:
run