///|
fn pdf_draw_colour_fill_ops(colour : PdfDrawColour) -> Array[PdfContentOp] {
match colour {
PdfDrawNoCol => []
PdfDrawRGB(r, g, b) => [Op_rg(r, g, b)]
PdfDrawGrey(g) => [Op_g(g)]
PdfDrawCYMK(c, m, y, k) => [Op_k(c, m, y, k)]
}
}
///|
fn pdf_draw_colour_stroke_ops(colour : PdfDrawColour) -> Array[PdfContentOp] {
match colour {
PdfDrawNoCol => []
PdfDrawRGB(r, g, b) => [Op_RG(r, g, b)]
PdfDrawGrey(g) => [Op_G(g)]
PdfDrawCYMK(c, m, y, k) => [Op_K(c, m, y, k)]
}
}
///|
/// Convert a cpdf content colour into the draw colour variant.
pub fn PdfContentColour::to_draw_colour(
self : PdfContentColour,
) -> PdfDrawColour {
match self {
PdfContentGrey(grey) => PdfDrawGrey(grey)
PdfContentRGB(red, green, blue) => PdfDrawRGB(red, green, blue)
PdfContentCMYK(cyan, magenta, yellow, black) =>
PdfDrawCYMK(cyan, magenta, yellow, black)
}
}
///|
/// Parse a cpdf draw-control colour argument.
///
/// This ports `cpdfdrawcontrol.ml`'s `parse_colour`/`col_of_string` path while
/// preserving the draw-layer `NoCol` sentinel separately from content colours.
pub fn pdf_parse_draw_colour(text : String) -> PdfDrawColour raise PdfError {
pdf_parse_content_colour(text).to_draw_colour()
}
///|
/// Parse a cpdf draw colour, returning `PdfDrawNoCol` on malformed input.
pub fn pdf_draw_colour_of_string(text : String) -> PdfDrawColour {
pdf_parse_draw_colour(text) catch {
_ => PdfDrawNoCol
}
}