PaperForge.TextMetrics (PaperForge v0.2.0)

Copy Markdown View Source

Measures text using the metrics of the standard PDF fonts.

Measurements are returned in PDF points.

Summary

Functions

Calculates the final X coordinate for horizontally aligned text.

Returns the width of one line of text in PDF points.

Returns the width of a text string in PDF points.

Types

alignment()

@type alignment() :: :left | :center | :right

Functions

aligned_x(text, x, container_width, options \\ [])

@spec aligned_x(
  binary(),
  number(),
  number(),
  keyword()
) :: float()

Calculates the final X coordinate for horizontally aligned text.

The provided x and container_width define the horizontal box.

Examples

PaperForge.TextMetrics.aligned_x(
  "Centered",
  72,
  450,
  align: :center,
  font: :helvetica,
  size: 18
)

line_width(text, options \\ [])

@spec line_width(
  binary(),
  keyword()
) :: float()

Returns the width of one line of text in PDF points.

width(text, options \\ [])

@spec width(
  binary(),
  keyword()
) :: float()

Returns the width of a text string in PDF points.

When the string contains multiple lines, the width of the longest line is returned.

Examples

PaperForge.TextMetrics.width(
  "Hello",
  font: :helvetica,
  size: 12
)