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
Functions
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"
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
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
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"
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
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
@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
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"
@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
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;
...
}"""