1- import {
1+ import type {
22 Content ,
33 ContentText ,
44 ContentImage ,
55 PDFEasyDefaults ,
66 InternalGlobals ,
7+ HexColor ,
8+ RunOptionsBase ,
79} from '../types'
810import { getCorrectFontFamily } from './transform'
911import { getImageRaw , SvgToPNG } from '../content/image'
12+ import { HEXToCMYK } from 'src/schema/color'
13+
14+ export const resolveColor = ( color : HexColor , run : RunOptionsBase ) => {
15+ return run ?. colorSchema === 'CMYK' ? HEXToCMYK ( color ) : color
16+ }
1017
1118export const resolveCover = async ( app : PDFKit . PDFDocument , based : string ) => {
1219 const { raw } = await getImageRaw ( based )
@@ -23,7 +30,8 @@ export const resolveContent = async (
2330 app : PDFKit . PDFDocument ,
2431 defaults : PDFEasyDefaults ,
2532 content : Content ,
26- globals : InternalGlobals
33+ globals : InternalGlobals ,
34+ run : RunOptionsBase
2735) => {
2836 const addStack = async ( ) => {
2937 const stack = content . stack as Content [ ]
@@ -41,7 +49,7 @@ export const resolveContent = async (
4149 )
4250 )
4351 . fontSize ( entity . text . fontSize || defaults . text . fontSize )
44- . fillColor ( entity . text . color || defaults . text . color )
52+ . fillColor ( resolveColor ( entity . text . color || defaults . text . color , run ) )
4553 . fillOpacity ( entity . text . opacity || defaults . text . opacity )
4654 . text ( entity . raw , {
4755 continued : ! isLast ,
@@ -66,7 +74,7 @@ export const resolveContent = async (
6674 await app
6775 . font ( getCorrectFontFamily ( style ?. font || defaults . text . font , style ) )
6876 . fontSize ( style ?. fontSize || defaults . text . fontSize )
69- . fillColor ( style ?. color || defaults . text . color )
77+ . fillColor ( resolveColor ( style ?. color || defaults . text . color , run ) )
7078 . fillOpacity ( style ?. opacity || defaults . text . opacity )
7179 . text ( data , {
7280 indent : style ?. indent || defaults . text . indent ,
@@ -84,7 +92,7 @@ export const resolveContent = async (
8492 await app
8593 . font ( getCorrectFontFamily ( defaults . text . font , { } ) )
8694 . fontSize ( defaults . text . fontSize )
87- . fillColor ( defaults . text . color )
95+ . fillColor ( resolveColor ( defaults . text . color , run ) )
8896 . fillOpacity ( defaults . text . opacity )
8997 . text ( content . raw , {
9098 indent : defaults . text . indent ,
@@ -143,10 +151,14 @@ export const resolveContent = async (
143151 }
144152
145153 const addCheckbox = async ( ) => {
146- const backgroundColor =
147- content . checkbox ?. backgroundColor ?? defaults . checkbox . backgroundColor
148- const borderColor =
149- content . checkbox ?. borderColor ?? defaults . checkbox . borderColor
154+ const backgroundColor = resolveColor (
155+ content . checkbox ?. backgroundColor ?? defaults . checkbox . backgroundColor ,
156+ run
157+ )
158+ const borderColor = resolveColor (
159+ content . checkbox ?. borderColor ?? defaults . checkbox . borderColor ,
160+ run
161+ )
150162 const size = content . checkbox ?. size ?? defaults . checkbox . size
151163
152164 app . initForm ( )
@@ -170,7 +182,7 @@ export const resolveContent = async (
170182 app
171183 . circle ( app . x + 4 , app . y + 6 , 3 )
172184 . lineWidth ( 1 )
173- . fill ( '#000' )
185+ . fill ( resolveColor ( '#000000' , run ) )
174186
175187 await addText ( false , ` ${ content . raw } ` )
176188 }
0 commit comments