Skip to content

Commit

Permalink
Move icc profile file to mixins data subfolder
Browse files Browse the repository at this point in the history
  • Loading branch information
blikblum committed Mar 24, 2024
1 parent d487253 commit 309cdd6
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 51 deletions.
File renamed without changes.
96 changes: 47 additions & 49 deletions lib/mixins/pdfa.js
Original file line number Diff line number Diff line change
@@ -1,58 +1,56 @@
import fs from 'fs';

export default {

initPDFA(pSubset) {
if (pSubset.charAt(pSubset.length - 3) === '-') {
this.subset_conformance = pSubset.charAt(pSubset.length - 1).toUpperCase();
this.subset = parseInt(pSubset.charAt(pSubset.length - 2));
} else {
// Default to Basic conformance when user doesn't specify
this.subset_conformance = 'B';
this.subset = parseInt(pSubset.charAt(pSubset.length - 1));
}
},

endSubset() {
this._addPdfaMetadata();
const jsPath = `${__dirname}/data/sRGB_IEC61966_2_1.icc`
const jestPath = `${__dirname}/../color_profiles/sRGB_IEC61966_2_1.icc`
this._addColorOutputIntent(fs.existsSync(jsPath) ? jsPath : jestPath);
},

_addColorOutputIntent(pICCPath) {
const iccProfile = fs.readFileSync(pICCPath);

const colorProfileRef = this.ref({
Length: iccProfile.length,
N: 3
});
colorProfileRef.write(iccProfile);
colorProfileRef.end();

const intentRef = this.ref({
Type: 'OutputIntent',
S: 'GTS_PDFA1',
Info: new String('sRGB IEC61966-2.1'),
OutputConditionIdentifier: new String('sRGB IEC61966-2.1'),
DestOutputProfile: colorProfileRef,
});
intentRef.end();

this._root.data.OutputIntents = [intentRef];
},

_getPdfaid() {
return `
initPDFA(pSubset) {
if (pSubset.charAt(pSubset.length - 3) === '-') {
this.subset_conformance = pSubset
.charAt(pSubset.length - 1)
.toUpperCase();
this.subset = parseInt(pSubset.charAt(pSubset.length - 2));
} else {
// Default to Basic conformance when user doesn't specify
this.subset_conformance = 'B';
this.subset = parseInt(pSubset.charAt(pSubset.length - 1));
}
},

endSubset() {
this._addPdfaMetadata();
this._addColorOutputIntent(`${__dirname}/data/sRGB_IEC61966_2_1.icc`);
},

_addColorOutputIntent(pICCPath) {
const iccProfile = fs.readFileSync(pICCPath);

const colorProfileRef = this.ref({
Length: iccProfile.length,
N: 3
});
colorProfileRef.write(iccProfile);
colorProfileRef.end();

const intentRef = this.ref({
Type: 'OutputIntent',
S: 'GTS_PDFA1',
Info: new String('sRGB IEC61966-2.1'),
OutputConditionIdentifier: new String('sRGB IEC61966-2.1'),
DestOutputProfile: colorProfileRef
});
intentRef.end();

this._root.data.OutputIntents = [intentRef];
},

_getPdfaid() {
return `
<rdf:Description xmlns:pdfaid="http://www.aiim.org/pdfa/ns/id/" rdf:about="">
<pdfaid:part>${this.subset}</pdfaid:part>
<pdfaid:conformance>${this.subset_conformance}</pdfaid:conformance>
</rdf:Description>
`;
},

_addPdfaMetadata() {
this.appendXML(this._getPdfaid());
},
},

}
_addPdfaMetadata() {
this.appendXML(this._getPdfaid());
}
};
4 changes: 2 additions & 2 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const external = [
'png-js',
'crypto-js',
'saslprep',
'jpeg-exif',
'jpeg-exif'
];

export default [
Expand Down Expand Up @@ -43,7 +43,7 @@ export default [
]
}),
copy({
files: ['lib/font/data/*.afm', 'lib/color_profiles/*.icc'],
files: ['lib/font/data/*.afm', 'lib/mixins/data/*.icc'],
dest: 'js/data'
})
]
Expand Down

0 comments on commit 309cdd6

Please sign in to comment.