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
4 changes: 2 additions & 2 deletions lib/icc_profile.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
class ICCProfile {
// store profiles as data and create spaces later?
constructor(label, data, channels, alternate) {
constructor(label, data, channels, alternate, type) {
this.label = label;
this.data = data;
this.channels = channels;
this.alternate = alternate;
this.ref = null;
this.streamRef = null;
this.type = type ?? (channels === 4 ? 'cmyk' : 'rgb');
}

embed(document) {
Expand Down
4 changes: 2 additions & 2 deletions lib/mixins/color_space.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export default {
this._colorProfiles = {};
},

iccProfile(label, data, channels, alternate) {
const profile = new ICCProfile(label, data, channels, alternate);
iccProfile(label, data, channels, alternate, type) {
const profile = new ICCProfile(label, data, channels, alternate, type);
profile.embed(this);
this._colorProfiles[label] = profile;
Comment on lines +8 to 11
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The public iccProfile(...) API now accepts a new type parameter, but the TypeScript declarations still expose only 4 parameters (see types/pdfkit.d.ts). Please update the .d.ts signature to keep the public API consistent for typed consumers.

Copilot uses AI. Check for mistakes.
return this;
Expand Down
37 changes: 32 additions & 5 deletions lib/write_svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -689,9 +689,9 @@ export default function (doc, svg, x, y, options) {
doc.page.xobjects[group.name] = group.xobj;
doc.addContent('/' + group.name + ' Do');
}
function docApplyMask(group) {
let name = 'M' + (doc._maskCount = (doc._maskCount || 0) + 1);
let gstate = doc.ref({
function docApplyAlphaMask(group) {
const name = 'M' + (doc._maskCount = (doc._maskCount || 0) + 1);
const gstate = doc.ref({
Type: 'ExtGState',
CA: 1,
ca: 1,
Comment on lines +692 to 697
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inside docApplyAlphaMask, the inline comment We only support alpha mask for now has become misleading now that luminosity masks are also supported via docApplyMask. Please reword it to clarify this helper applies an alpha SMask specifically (rather than implying alpha is the only supported mask mode overall).

Copilot uses AI. Check for mistakes.
Expand All @@ -706,6 +706,28 @@ export default function (doc, svg, x, y, options) {
doc.page.ext_gstates[name] = gstate;
doc.addContent('/' + name + ' gs');
}
function docApplyMask(group) {
const name = 'M' + (doc._maskCount = (doc._maskCount || 0) + 1);
// backdrop should be black
let bc = [0, 0, 0];
if (doc._activeColorProfile && doc._activeColorProfile.type === 'cmyk') {
bc = [1, 1, 1, 1];
}
const gstate = doc.ref({
Type: 'ExtGState',
CA: 1,
ca: 1,
BM: 'Normal',
SMask: {
S: 'Luminosity',
G: group.xobj,
BC: bc,
},
});
gstate.end();
doc.page.ext_gstates[name] = gstate;
doc.addContent('/' + name + ' gs');
}
function applyBlendMode(group, blendMode) {
// map svg blendMode to pdf
const key = String(blendMode || '').toLowerCase();
Expand Down Expand Up @@ -3297,7 +3319,7 @@ export default function (doc, svg, x, y, options) {
this.drawChildren(true, false);
doc.restore();
docEndGroup(group);
docApplyMask(group);
docApplyAlphaMask(group);
};
};

Expand All @@ -3321,11 +3343,16 @@ export default function (doc, svg, x, y, options) {
if (this.attr('maskContentUnits') === 'objectBoundingBox') {
doc.transform(bBox[2] - bBox[0], 0, 0, bBox[3] - bBox[1], bBox[0], bBox[1]);
}
const maskType = this.attr('mask-type') ?? 'luminance';
this.clip();
this.drawChildren(false, true);
doc.restore();
docEndGroup(group);
docApplyMask(group);
if (maskType === 'alpha') {
docApplyAlphaMask(group);
} else {
docApplyMask(group);
}
Comment on lines +3346 to +3355
Copy link

Copilot AI Apr 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mask-type is read via getAttribute and then compared case-sensitively to 'alpha'. Since mask-type is a CSS keyword/presentation attribute, values should be treated case-insensitively; consider normalizing (e.g., String(...).toLowerCase()) or using the style getter so valid inputs like Alpha/ALPHA work.

Copilot uses AI. Check for mistakes.
};
};

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"document",
"vector"
],
"version": "0.17.56",
"version": "0.17.58",
"homepage": "http://pdfkit.org/",
"author": {
"name": "Devon Govett",
Expand Down
3 changes: 2 additions & 1 deletion types/pdfkit.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ shader(fn: () => any): any;
data: Uint8Array | Buffer;
channels: number;
alternate: string | string[];
type?: 'cmyk' | 'rgb'
}
}

Expand Down Expand Up @@ -786,7 +787,7 @@ declare namespace PDFKit.Mixins {
}

interface PDFColorSpace {
iccProfile(label:string, data: Uint8Array | ArrayBuffer, channels: number, alternate: string|string[]): this;
iccProfile(label:string, data: Uint8Array | ArrayBuffer, channels: number, alternate: string|string[], type?: 'rgb'|'cmyk'): this;
}

interface PDFOutputIntent {
Expand Down
Loading