@@ -185,4 +185,120 @@ describe('readDocumentDefinition', () => {
185185 ) ,
186186 ) ;
187187 } ) ;
188+
189+ describe ( 'outputIntents' , ( ) => {
190+ it ( 'accepts valid output intent' , ( ) => {
191+ const iccProfile = mkIccProfile ( 'RGB ' ) ;
192+ const outputIntents = [
193+ {
194+ subtype : 'GTS_PDFA1' ,
195+ outputConditionIdentifier : 'sRGB IEC61966-2.1' ,
196+ iccProfile,
197+ outputCondition : 'sRGB' ,
198+ registryName : 'http://www.color.org' ,
199+ info : 'sRGB IEC61966-2.1' ,
200+ } ,
201+ ] ;
202+
203+ const def = readDocumentDefinition ( { ...input , outputIntents } ) ;
204+
205+ expect ( def . outputIntents ) . toEqual ( outputIntents ) ;
206+ } ) ;
207+
208+ it ( 'accepts output intent with only required fields' , ( ) => {
209+ const iccProfile = mkIccProfile ( 'RGB ' ) ;
210+ const outputIntents = [
211+ { subtype : 'GTS_PDFA1' , outputConditionIdentifier : 'sRGB' , iccProfile } ,
212+ ] ;
213+
214+ const def = readDocumentDefinition ( { ...input , outputIntents } ) ;
215+
216+ expect ( def . outputIntents ) . toEqual ( outputIntents ) ;
217+ } ) ;
218+
219+ it ( 'checks subtype is required' , ( ) => {
220+ const outputIntents = [ { outputConditionIdentifier : 'sRGB' , iccProfile : mkIccProfile ( ) } ] ;
221+
222+ expect ( ( ) => readDocumentDefinition ( { ...input , outputIntents } ) ) . toThrow (
223+ / M i s s i n g v a l u e f o r " s u b t y p e " / ,
224+ ) ;
225+ } ) ;
226+
227+ it ( 'checks outputConditionIdentifier is required' , ( ) => {
228+ const outputIntents = [ { subtype : 'GTS_PDFA1' , iccProfile : mkIccProfile ( ) } ] ;
229+
230+ expect ( ( ) => readDocumentDefinition ( { ...input , outputIntents } ) ) . toThrow (
231+ / M i s s i n g v a l u e f o r " o u t p u t C o n d i t i o n I d e n t i f i e r " / ,
232+ ) ;
233+ } ) ;
234+
235+ it ( 'checks iccProfile is required' , ( ) => {
236+ const outputIntents = [ { subtype : 'GTS_PDFA1' , outputConditionIdentifier : 'sRGB' } ] ;
237+
238+ expect ( ( ) => readDocumentDefinition ( { ...input , outputIntents } ) ) . toThrow (
239+ / M i s s i n g v a l u e f o r " i c c P r o f i l e " / ,
240+ ) ;
241+ } ) ;
242+
243+ it ( 'rejects non-Uint8Array iccProfile' , ( ) => {
244+ const outputIntents = [
245+ { subtype : 'GTS_PDFA1' , outputConditionIdentifier : 'sRGB' , iccProfile : 'not-bytes' } ,
246+ ] ;
247+
248+ expect ( ( ) => readDocumentDefinition ( { ...input , outputIntents } ) ) . toThrow (
249+ / I n v a l i d v a l u e f o r " o u t p u t I n t e n t s \/ 0 \/ i c c P r o f i l e " : E x p e c t e d U i n t 8 A r r a y / ,
250+ ) ;
251+ } ) ;
252+
253+ it ( 'rejects ICC profile that is too short' , ( ) => {
254+ const outputIntents = [
255+ {
256+ subtype : 'GTS_PDFA1' ,
257+ outputConditionIdentifier : 'sRGB' ,
258+ iccProfile : new Uint8Array ( 10 ) ,
259+ } ,
260+ ] ;
261+
262+ expect ( ( ) => readDocumentDefinition ( { ...input , outputIntents } ) ) . toThrow (
263+ / I n v a l i d v a l u e f o r " o u t p u t I n t e n t s \/ 0 \/ i c c P r o f i l e " : I C C p r o f i l e i s t o o s h o r t / ,
264+ ) ;
265+ } ) ;
266+
267+ it ( 'rejects ICC profile with invalid signature' , ( ) => {
268+ const iccProfile = new Uint8Array ( 128 ) ;
269+ const outputIntents = [
270+ { subtype : 'GTS_PDFA1' , outputConditionIdentifier : 'sRGB' , iccProfile } ,
271+ ] ;
272+
273+ expect ( ( ) => readDocumentDefinition ( { ...input , outputIntents } ) ) . toThrow (
274+ / I n v a l i d v a l u e f o r " o u t p u t I n t e n t s \/ 0 \/ i c c P r o f i l e " : I n v a l i d I C C p r o f i l e : e x p e c t e d s i g n a t u r e ' a c s p ' / ,
275+ ) ;
276+ } ) ;
277+
278+ it ( 'rejects ICC profile with unsupported color space' , ( ) => {
279+ const iccProfile = mkIccProfile ( 'Lab ' ) ;
280+ const outputIntents = [
281+ { subtype : 'GTS_PDFA1' , outputConditionIdentifier : 'sRGB' , iccProfile } ,
282+ ] ;
283+
284+ expect ( ( ) => readDocumentDefinition ( { ...input , outputIntents } ) ) . toThrow (
285+ / I n v a l i d v a l u e f o r " o u t p u t I n t e n t s \/ 0 \/ i c c P r o f i l e " : U n s u p p o r t e d I C C p r o f i l e c o l o r s p a c e ' L a b ' / ,
286+ ) ;
287+ } ) ;
288+ } ) ;
188289} ) ;
290+
291+ function mkIccProfile ( colorSpace = 'RGB ' ) : Uint8Array {
292+ const data = new Uint8Array ( 128 ) ;
293+ // color space signature at offset 16
294+ data [ 16 ] = colorSpace . charCodeAt ( 0 ) ;
295+ data [ 17 ] = colorSpace . charCodeAt ( 1 ) ;
296+ data [ 18 ] = colorSpace . charCodeAt ( 2 ) ;
297+ data [ 19 ] = colorSpace . charCodeAt ( 3 ) ;
298+ // 'acsp' signature at offset 36
299+ data [ 36 ] = 0x61 ; // a
300+ data [ 37 ] = 0x63 ; // c
301+ data [ 38 ] = 0x73 ; // s
302+ data [ 39 ] = 0x70 ; // p
303+ return data ;
304+ }
0 commit comments