View Source Idmlx.Components.Font (idmlx v0.2.1)

Represents a font in an InDesign document.

This module provides functionality for handling font definitions, including:

  • Font metadata management
  • URL and format settings
  • CSS generation for web output
  • Reference tracking for font usage

Font Structure

  • name - The font family name
  • format - The font format (e.g., "woff2", "ttf")
  • url - URL to the font resource
  • style - Font style information
  • references - List of places where the font is used

Examples

%Idmlx.Components.Font{
  name: "Helvetica",
  format: "woff2",
  url: "https://fonts.example.com/helvetica.woff2",
  style: "Regular",
  references: ["ParagraphStyle:Body", "Story:main"]
}

Summary

Functions

Adds a reference to a font's reference list.

Sets the format for a font.

Sets the style for a font.

Sets the URL for a font.

Generates CSS @font-face declaration for the font.

Types

t()

@type t() :: %Idmlx.Components.Font{
  format: String.t() | nil,
  name: String.t(),
  references: [String.t()] | nil,
  style: String.t() | nil,
  url: String.t() | nil
}

Functions

add_reference(font, reference)

@spec add_reference(t(), String.t()) :: t()

Adds a reference to a font's reference list.

Parameters

  • font: The font struct to update
  • reference: The reference to add (e.g., "ParagraphStyle:Body")

Examples

iex> font = %Idmlx.Components.Font{name: "Helvetica", references: ["Story:main"]}
iex> Idmlx.Components.Font.add_reference(font, "ParagraphStyle:Body")
%Idmlx.Components.Font{name: "Helvetica", references: ["Story:main", "ParagraphStyle:Body"]}

set_format(font, format)

@spec set_format(t(), String.t()) :: t()

Sets the format for a font.

Parameters

  • font: The font struct to update
  • format: The format to set (e.g., "woff2", "ttf")

Examples

iex> font = %Idmlx.Components.Font{name: "Helvetica"}
iex> Idmlx.Components.Font.set_format(font, "woff2")
%Idmlx.Components.Font{name: "Helvetica", format: "woff2"}

set_style(font, style)

@spec set_style(t(), String.t()) :: t()

Sets the style for a font.

Parameters

  • font: The font struct to update
  • style: The style to set (e.g., "Regular", "Bold")

Examples

iex> font = %Idmlx.Components.Font{name: "Helvetica"}
iex> Idmlx.Components.Font.set_style(font, "Bold")
%Idmlx.Components.Font{name: "Helvetica", style: "Bold"}

set_url(font, url)

@spec set_url(t(), String.t()) :: t()

Sets the URL for a font.

Parameters

  • font: The font struct to update
  • url: The URL to set

Examples

iex> font = %Idmlx.Components.Font{name: "Helvetica"}
iex> Idmlx.Components.Font.set_url(font, "https://fonts.example.com/helvetica.woff2")
%Idmlx.Components.Font{name: "Helvetica", url: "https://fonts.example.com/helvetica.woff2"}

to_css(font)

@spec to_css(t()) :: String.t()

Generates CSS @font-face declaration for the font.

Parameters

  • font: The font struct to generate CSS for

Returns

CSS @font-face declaration as a string

Examples

iex> font = %Idmlx.Components.Font{name: "Helvetica", url: "fonts/helvetica.woff2", format: "woff2"}
iex> Idmlx.Components.Font.to_css(font)
"""
@font-face {
  font-family: Helvetica;
  src: prince-lookup("Helvetica"),
      url("fonts/helvetica.woff2") format("woff2");
}
"""