Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TTF font support #69

Draft
wants to merge 80 commits into
base: main
Choose a base branch
from
Draft

TTF font support #69

wants to merge 80 commits into from

Conversation

Jed-
Copy link
Contributor

@Jed- Jed- commented Sep 18, 2024

TTF font and Unicode support

All text is now rendered with TTF fonts using pangocairo, and UTF-8 strings are supported natively.

Add a dependency on pango >= 1.56.
On Linux, the game can alternatively be compiled against pango >= 1.38 and fontconfig by adding -DOLDPANGO as a compiler flag.

Bump the minimum standard version to C++11.

Player names are restricted to a subset of Latin, Cyrillic and Greek characters in order to prevent abuse. The rest of the UI, console and particles can use any set of Unicode characters without restriction. If two player names are visually identical or very similar, they are marked as duplicates even if the actual string are different.

In addition to the color codes \f0 through \f9, more codes have been added to support basic markup:

  • \fb...\fB = bold
  • \fi...\fI = italic
  • \fu...\fU = underline
  • \ft...\fT = strikethrough
    where ... is the part of the string to apply the markup to.

The colors corresponding to \f codes can now be customized with the textcolor command.

Using TTF fonts:

  • each TTF file must be registered with the registerfont command before it can be used
  • the font command is used to define a font family to use in-game
  • several commands are available to customize each font, see config/font.cfg for how to use them
  • the fontalias command has been removed

Console changes:

  • add variable conshadow (0, 255, 255): adds a black shadow to console text for increased visibility
  • add variable conoutline (0, 0, 255): adds a black outline around console text
  • change the range of conscale from (0.001, 0.45, 1000) to (0.5, 1, 2)

Command line changes:

  • add the cursorblink (0, 750, 2000) variable to customize the cursor's blink speed (0 = disable blinking)
  • add the cursorcolor (0xFFFFFF) variable to customize the cursor's color
  • the cursor does not blink while the user is typing
  • the resetcursorblink command can be used to stop the cursor blink animation for a short time

Text particle changes:

  • the function particle_text() now accepts font and language arguments
  • add function particle_hud_text(): renders a text particle as a hud mark, similar to particle_hud_mark(), this is now used to render the GOAL label in CTF mode

UI changes:

  • remove variable uitextrows; UI text scale can still be configured with uiscale
  • add variable uifps (0, 60, 1000): controls how often text elements check for text changes (0 = check every frame, may impact performace)
  • add several UI commands to customize text elements, which can be nested
  • text elements can now read keyboard and mouse input

New UI commands:

  • uiwrapalign -1|0|1 [children]: sets the alignment for multi-line paragraphs (-1 = left, 0 = center, 1 = right)
  • uijustify 0|1 [children]: controls justification for multi-line paragraphs
  • uishadow alpha [children]: draw a transparent black shadow behind the text (alpha from 0 to 255)
  • uifontoutline thickness alpha [children]: draw a transparent black outline around the text (thickness is expressed in 1/16ths of the current font height; alpha from 0 to 255)
  • uinofallback 0|1 [children]: disable falling back to system fonts for unavailable characters
  • uilanguage lang [children]: specify the language of the text, which can affect text shaping (lang must be a string in RFC-3066 format)
  • example usage:
newui test [
  uilanguage "en" [
    uishadow 0xFF [
      uiwrapalign 0 [
        uijustify 1 [
          uiwraptext "Lorem ipsum dolor sit amet" 0.5 3
        ]
      ]
    ]
  ]
]

Global font settings (users may change these to their liking):

  • fontantialias (0, 1, 1): toggle font antialiasing (only grayscale antialiasing is supported)
  • fonthinting (-1, -1, 3): set font hinting (-1 = system default, 0 = disabled, 1 = slight, 2 = medium, 3 = full)

Settings for individual fonts (to use after the font command, refer to config/font.cfg):

  • fontweight [-3..6]: < 0 = lighter, > 0 = bolder
  • fontstretch [-4..4]: < 0 = tighter, > 0 = wider (many fonts don't support this)
  • fontstyle [0..2]: 0 = normal, 1 = oblique, 2 = italic
  • fontsmallcaps 0|1
  • fontfeatures [...features]: OpenType features, in CSS font-feature-settings format
  • fontvariations "variations": for OpenType variable fonts, format: "AXIS1=VALUE,AXIS2=VALUE..."

Other added commands:

  • strbytelen str: returns the length of a string, in bytes
  • char2byteindex str ix: converts a character index to a byte index
  • byte2charindex str ix: inverse of the above

Miscellaneous changes:

  • change the filtertext function to take a flags argument rather than a series of booleans
  • remove the tabify and textbright commands
  • remove the tessfont tool

@garsipal garsipal added the enhancement New feature or aesthetic improvement label Sep 20, 2024
All text is now rendered with TTF fonts using `pangocairo`, and UTF-8 strings are supported natively.

Add a dependency on `pango >= 1.46`, `cairo >= 1.18` and `fontconfig`.

Player names are restricted to a subset of Latin, Cyrillic and Greek characters in order to prevent abuse. The rest of the UI, console and particles can use any Unicode characters without restriction.

In addition to the color codes `\f0` through `\f9`, more codes have been added to support basic markup:
- \fb...\fB = bold
- \fi...\fI = italic
- \fu...\fU = underline
- \ft...\fT = strikethrough
- \fo...\fO = overline
where `...` is the part of the string to apply the markup to.

Using TTF fonts:
- each TTF file must be registered with the `registerfont` command before it can be used
- the `font` command is used to define a font family (and optionally style) to use in-game
- several commands are available to customize each font, see `config/font.cfg` for how to use them
- the `fontalias` command has been removed

Console changes:
- add the `conshadow` (0, 255, 255) variable: adds a shadow to console text for increased visibility
- change the range of `conscale` from (0.001, 0.45, 1000) to (0.5, 1, 2)

Text input changes:
- add the `cursorblink` (0, 750, 2000) variable to customize the cursor's blink speed (0 = disable blinking)
- add the `cursorcolor` (0xFFFFFF) variable to customize the cursor's color
- the cursor does not blink while the user is typing

Text particle changes:
- the font to use for each particle can be specified as an argument to `particle_text()`
- add the `particle_hud_text()` function: renders a text particle as a hud mark, similar to `particle_hud_mark()`, this is now used to render the `GOAL` label in CTF mode

UI changes:
- `uitext` and related commands accept a `fancy` argument, used for shadows and outlines, and a `language` argument, which may be necessary to render text in certain languages correctly. The language argument must be in `RFC 3066` format.
- valid values for `fancy`: 0 = nothing; 1 = shadow; 2 = outline; 3 = shadow + outline
- remove the `uitextrows` variable; UI text scale can still be configured with `uiscale`
- add the `uifps` (0, 60, 1000) variable: controls how often text elements check for text changes (0 = check every frame, may impact performace)

Miscellaneous changes:
- change the `filtertext` function to take a `flags` argument rather than a series of booleans
- remove the `tabify` and `textbright` commands
- remove the `tessfont` tool

Global font settings (users may change these to their liking):
- fontantialias (0, 1, 1): toggle font antialiasing (only grayscale antialiasing is supported)
- fonthinting (-1, -1, 3): set font hinting (-1 = system default, 0 = disabled, 1 = slight, 2 = medium, 3 = full)

Settings for individual fonts (to use after the `font` command, refer to `config/font.cfg`):
- fontweight [-3..6]: < 0 = lighter, > 0 = bolder
- fontstretch [-4..4]: < 0 = tighter, > 0 = wider; many fonts don't support this, use `fontletterspacing` instead
- fontstyle [0..2]: 0 = normal, 1 = oblique, 2 = italic
- fontsmallcaps 0|1
- fontletterspacing val: `val` is a floating point value, measured in points; < 0 = tighter, > 0 = wider
- fontfeatures [...features]: OpenType features, in CSS `font-feature-settings` format
- fontvariations "variations": for OpenType variable fonts, format: "AXIS1=VALUE,AXIS2=VALUE..."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or aesthetic improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants