View Source Idmlx.Components.Fonts (idmlx v0.2.1)
Provides functionality for parsing and working with InDesign fonts.
This module handles:
- Parsing fonts from IDMS/IDML files
- Extracting fonts from various document elements (styles, stories)
- Merging font definitions from different sources
- Font lookup and management
Font Sources
- Base fonts (FontFamily definitions)
- Paragraph style fonts
- Character style fonts
- Story fonts
Examples
# Get all fonts from a document
fonts = Idmlx.Components.Fonts.get_fonts("template.idms")
# Find a specific font
helvetica = Idmlx.Components.Fonts.find_font_by_name(fonts, "Helvetica")
Summary
Functions
Finds a font by name in a list of fonts.
Gets all fonts from an IDMS/IDML file, including those referenced in styles and stories.
Functions
@spec find_font_by_name([Idmlx.Components.Font.t()], String.t()) :: Idmlx.Components.Font.t() | nil
Finds a font by name in a list of fonts.
Parameters
- fonts: List of Font structs to search
- name: Name of the font to find
Returns
Font struct or nil if not found
Examples
iex> fonts = [%Font{name: "Helvetica"}, %Font{name: "Arial"}]
iex> Idmlx.Components.Fonts.find_font_by_name(fonts, "Helvetica")
%Font{name: "Helvetica", ...}
@spec get_fonts(String.t()) :: [Idmlx.Components.Font.t()]
Gets all fonts from an IDMS/IDML file, including those referenced in styles and stories.
Parameters
- file_path: Path to the file to parse (defaults to "Resources/Fonts.xml")
Returns
List of unique Font structs with merged references
Examples
iex> Idmlx.Components.Fonts.get_fonts("template.idms")
[%Idmlx.Components.Font{name: "Helvetica", references: ["FontFamily", "Story:main"], ...}]