View Source Idmlx.StyleCreator.ColorHelper (idmlx v0.2.1)
Utility module for handling color-related operations for IDML documents.
Summary
Functions
Creates a new color definition for IDML. This would be used when you need to create custom colors that don't already exist in the document.
Creates a complete color XML definition for insertion into an IDMS document.
Formats a color object or name into the format expected by InDesign.
Converts a hex color value to CMYK values. Returns a tuple of {C, M, Y, K} values as percentages (0-100).
Converts RGB values (0-255) to CMYK values (0-100).
Functions
Creates a new color definition for IDML. This would be used when you need to create custom colors that don't already exist in the document.
Creates a complete color XML definition for insertion into an IDMS document.
Parameters
- name: The name of the color.
- options: Options for the color definition.
Options
:type
- Color type, one of "cmyk", "rgb", "lab", "hex", etc.:values
- List of color values or hex string for hex type.:space
- Color space (defaults based on type).:model
- Color model (defaults to "Process").:visible
- Whether the color is visible (defaults to true).:editable
- Whether the color is editable (defaults to true).:removable
- Whether the color is removable (defaults to true).
Examples
iex> Idmlx.StyleCreator.ColorHelper.create_color_xml("MochaMousse", %{
...> type: "cmyk",
...> values: [30, 50, 75, 10]
...> })
# Returns XML string with the color definition
iex> Idmlx.StyleCreator.ColorHelper.create_color_xml("BrightRed", %{
...> type: "hex",
...> values: "#FF0000"
...> })
# Returns XML string with converted CMYK color definition
Formats a color object or name into the format expected by InDesign.
Examples
iex> Idmlx.StyleCreator.ColorHelper.format_color("Black")
"Color/Black"
iex> Idmlx.StyleCreator.ColorHelper.format_color(%{type: "cmyk", values: [0, 0, 0, 100]})
# Would return an appropriate CMYK color reference
iex> Idmlx.StyleCreator.ColorHelper.format_color(%{type: "hex", values: "#FF0000"})
# Would convert hex to CMYK and return appropriate reference
Converts a hex color value to CMYK values. Returns a tuple of {C, M, Y, K} values as percentages (0-100).
Examples
iex> Idmlx.StyleCreator.ColorHelper.hex_to_cmyk("#FF0000")
{0, 100, 100, 0}
iex> Idmlx.StyleCreator.ColorHelper.hex_to_cmyk("#000000")
{0, 0, 0, 100}
Converts RGB values (0-255) to CMYK values (0-100).