View Source Idmlx.Components.Style (idmlx v0.2.0)

Represents a style in an InDesign document.

This module provides functionality for handling and manipulating InDesign styles, including:

  • Font and text formatting
  • Color management
  • Style inheritance
  • CSS conversion

Style Structure

  • name - Full style identifier (e.g., "ParagraphStyle/Body")
  • applied_font - Font information for the style
  • attributes - List of style attributes and their values
  • based_on - Parent style reference for inheritance

Style Types

Supports three main types of styles:

  • Paragraph styles
  • Character styles
  • Object styles

Examples

%Idmlx.Components.Style{
  name: "ParagraphStyle/Body",
  applied_font: %Font{name: "Helvetica"},
  attributes: [%{key: :PointSize, value: "12"}],
  based_on: "ParagraphStyle/$ID/[No paragraph style]"
}

Summary

Functions

Formats the font style (weight/italic) based on InDesign font style.

Formats hyphenation setting based on InDesign hyphenation value.

Formats letter spacing based on InDesign tracking value.

Formats text alignment based on InDesign justification.

Formats vertical alignment based on InDesign vertical justification.

Gets an attribute value, considering overrides and inheritance.

Gets fill color for a style, considering tint.

Gets the font family for a style, considering overrides and inheritance.

Gets stroke color for a style, considering tint.

Converts a style to CSS.

Types

attribute()

@type attribute() :: %{key: atom() | String.t(), value: any()}

t()

@type t() :: %Idmlx.Components.Style{
  applied_font: Font.t() | nil,
  attributes: [attribute()] | nil,
  based_on: String.t() | nil,
  name: String.t() | nil
}

Functions

format_font_style(style, overrides \\ %{}, styles \\ [])

@spec format_font_style(t(), map(), [t()]) :: String.t()

Formats the font style (weight/italic) based on InDesign font style.

Parameters

  • style: The style to format
  • overrides: Map of style overrides
  • styles: List of all styles for inheritance lookup

Returns

CSS font-style or font-weight value

Examples

iex> style = %Style{attributes: [%{key: :FontStyle, value: "Bold Italic"}]}
iex> Style.format_font_style(style)
"italic"

format_hyphenation(style, overrides \\ %{}, styles \\ [])

@spec format_hyphenation(t(), map(), [t()]) :: String.t()

Formats hyphenation setting based on InDesign hyphenation value.

Parameters

  • style: The style to format
  • overrides: Map of style overrides
  • styles: List of all styles for inheritance lookup

Returns

CSS word-break value

format_letter_spacing(style, overrides \\ %{}, styles \\ [])

@spec format_letter_spacing(t(), map(), [t()]) :: String.t()

Formats letter spacing based on InDesign tracking value.

Parameters

  • style: The style to format
  • overrides: Map of style overrides
  • styles: List of all styles for inheritance lookup

Returns

CSS letter-spacing value in pixels

format_text_align(style, overrides \\ %{}, styles \\ [])

@spec format_text_align(t(), map(), [t()]) :: String.t()

Formats text alignment based on InDesign justification.

Parameters

  • style: The style to format
  • overrides: Map of style overrides
  • styles: List of all styles for inheritance lookup

Returns

CSS text-align value

Examples

iex> style = %Style{attributes: [%{key: :Justification, value: "CenterAlign"}]}
iex> Style.format_text_align(style)
"center"

format_vertical_align(style, overrides \\ %{}, styles \\ [])

@spec format_vertical_align(t(), map(), [t()]) :: String.t()

Formats vertical alignment based on InDesign vertical justification.

Parameters

  • style: The style to format
  • overrides: Map of style overrides
  • styles: List of all styles for inheritance lookup

Returns

CSS vertical-align value

get_attribute_value(style, key, overrides \\ %{}, styles \\ [])

@spec get_attribute_value(t(), atom() | String.t(), map(), [t()]) :: any()

Gets an attribute value, considering overrides and inheritance.

Parameters

  • style: The style to get the value from
  • key: Attribute key to look up
  • overrides: Map of style overrides
  • styles: List of all styles for inheritance lookup

Returns

Attribute value or nil if not found

get_fill_color(style, colors, overrides \\ %{}, styles \\ [])

@spec get_fill_color(t(), [Idmlx.Components.Color.t()], map(), [t()]) :: String.t()

Gets fill color for a style, considering tint.

Parameters

  • style: The style to get the color from
  • colors: List of available colors
  • overrides: Map of style overrides
  • styles: List of all styles for inheritance lookup

Returns

CSS color value

get_font_family(style, overrides \\ %{}, styles \\ [])

@spec get_font_family(t(), map(), [t()]) :: String.t()

Gets the font family for a style, considering overrides and inheritance.

Parameters

  • style: The style to get the font family from
  • overrides: Map of style overrides
  • styles: List of all styles for inheritance lookup

Returns

Font family name as string, defaults to "Arial"

Examples

iex> style = %Style{applied_font: %Font{name: "Helvetica"}}
iex> Style.get_font_family(style)
"Helvetica"

get_stroke_color(style, colors, overrides \\ %{}, styles \\ [])

@spec get_stroke_color(t(), [Idmlx.Components.Color.t()], map(), [t()]) ::
  String.t() | nil

Gets stroke color for a style, considering tint.

Parameters

  • style: The style to get the color from
  • colors: List of available colors
  • overrides: Map of style overrides
  • styles: List of all styles for inheritance lookup

Returns

CSS color value or nil

to_css(style, styles \\ [])

@spec to_css(t(), [t()]) :: String.t()

Converts a style to CSS.

Parameters

  • style: The style to convert
  • styles: List of all styles for inheritance lookup

Returns

CSS rules as string

Examples

iex> style = %Style{name: "ParagraphStyle/Body"}
iex> Style.to_css(style)
""".Body {
  font-size: 10px;
  ...
}"""