Files
S.P.L.U.R.T-Station-13/interface/fonts/fonts_datum.dm
SandPoot 217e23fc7f push
2023-07-18 15:22:24 -03:00

79 lines
2.0 KiB
Plaintext

/// A font datum, it exists to define a custom font to use in a span style later.
/datum/font
/// Font name, just so people know what to put in their span style.
var/name
/// The font file we link to.
var/font_family
/// Font features and metrics
/// Generated by Lummox's dmifontsplus (https://www.byond.com/developer/LummoxJR/DmiFontsPlus)
/// Note: these variable names have been changed, so you can't straight copy/paste from dmifontsplus.exe
/// list of font size/spacing metrics
var/list/metrics
/// total height of a line
var/height
/// distance above baseline (including whitespace)
var/ascent
/// distance below baseline
var/descent
/// average character width
var/average_width
/// maximum character width
var/max_width
/// extra width, such as from italics, for a line
var/overhang
/// internal leading vertical space, for accent marks
var/in_leading
/// external leading vertical space, just plain blank
var/ex_leading
/// default character (for undefined chars)
var/default_character
/// first character in metrics
var/start
/// last character in metrics
var/end
/// Get font metrics
/// From Lummox's dmifontsplus (https://www.byond.com/developer/LummoxJR/DmiFontsPlus)
/datum/font/proc/get_metrics(text, flags, first_line)
. = 0
var/longest = 0
if(!length(text))
return
var/i = 1
var/idx
while(i <= length(text))
var/character = text2ascii(text, i++)
if(character <= 10)
if(character <= 7)
. += character // spacers for justification
if(character <= 9)
continue // soft-break chars
if(. && idx && !(flags & INCLUDE_AC))
. -= max(metrics[idx + 3], 0)
longest = max(longest, . + first_line)
. = 0
first_line = 0
idx = 0
continue
idx = (character - start) * 3
if(idx <= 0 || idx >= metrics.len)
idx = (default_character - start) * 3
if(!. && !(flags & INCLUDE_AC))
. -= metrics[idx + 1]
. += metrics[idx + 1] + metrics[idx + 2] + metrics[idx +3]
if(. && idx && !(flags & INCLUDE_AC))
. -= max(metrics[idx + 3], 0)
. = max(. + first_line, longest)
if(. > 0)
. += overhang