CPFont

abstract class CPFont(origin: String) extends CPGameObject with CPAsset

Font descriptor.

Font is an asset. Just like other assets such as images, sounds, animations or videos they are not managed or governed by the CosPlay game engine unlike scenes and scene objects that are managed and governed by the game engine. Assets are typically created outside the game loop and managed by the developer, they can be freely shared between scenes or scene objects as any other standard Scala objects.

CosPlay comes with a full support for FIGLet fonts as well as standard "system" font , all of which implement this interface. In other words, there's no difference whether you are drawing with a system (1-character height) font or a FIGLet font.

See also:

CPFIGLetFont FIGLet fonts.

CPSystemFont System font.

CPStyledString Styled string using system font.

CPCanvas.drawStyledString Canvas drawing using system font or styled strings.

Example:

See CPFontsExample source code for an example of font functionality.

Source:
CPFont.scala
trait CPAsset
class Object
trait Matchable
class Any
object CPSystemFont.type

Value members

Abstract methods

def getBaseline: Int

Gets baseline of this font in standard character.

Gets baseline of this font in standard character.

Source:
CPFont.scala
def getEncoding: String

Gets encoding used by this font. Note that for the system font it returns "UTF-8".

Gets encoding used by this font. Note that for the system font it returns "UTF-8".

Source:
CPFont.scala
def getHeight: Int

Gets height of this font in standard characters.

Gets height of this font in standard characters.

Source:
CPFont.scala
def getWidth: Int

Gets width of this font in standard characters.

Gets width of this font in standard characters.

Source:
CPFont.scala
def isSystem: Boolean

Whether or not this is a "standard" 1-character height system font.

Whether or not this is a "standard" 1-character height system font.

Source:
CPFont.scala
def render(s: String, fg: CPColor, bg: Option[CPColor]): CPImage

Renders single line text as an image with this font.

Renders single line text as an image with this font.

Value parameters:
bg

Optional background color to use. Default value is None.

fg

Foreground color to use.

s

Text to render. Must be non-empty.

Returns:

Image as a rendering of the given single line text with this font.

Source:
CPFont.scala

Concrete methods

def renderMulti(s: String, fg: CPColor, bg: Option[CPColor], align: Int): CPImage

Renders given multiline text as an image. Supplied string will be split by system-specific "new line' character sequence ('\n' or '\n\r'). This call is equivalent to:

Renders given multiline text as an image. Supplied string will be split by system-specific "new line' character sequence ('\n' or '\n\r'). This call is equivalent to:

renderSeq(s.split(CPUtils.NL).filter(!_.isBlank).toSeq, fg, bg, align)
Value parameters:
align

Alignment of text. The only allowed values are:

  • -1 - left justified alignment.
  • 0 - centered alignment.
  • 1 - right justified alignment. Default value is 0.
bg

Optional background color to use. Default value is None.

fg

Foreground color to use.

s

Multiline text to render as an image. Must be non-empty.

Returns:

Image as a rendering of the given string with this font.

Source:
CPFont.scala
def renderSeq(ss: Seq[String], fg: CPColor, bg: Option[CPColor], align: Int): CPImage

Renders given multiline text as an image.

Renders given multiline text as an image.

Value parameters:
align

Alignment of text. The only allowed values are:

  • -1 - left justified alignment.
  • 0 - centered alignment.
  • 1 - right justified alignment. Default value is 0.
bg

Optional background color to use. Default value is None.

fg

Foreground color to use.

ss

Sequence of text lines to render as an image. Must be non-empty.

Returns:

Image as a rendering of the given string with this font.

Source:
CPFont.scala

Inherited methods

override def equals(obj: Any): Boolean
Definition Classes
Inherited from:
CPGameObject
Source:
CPGameObject.scala
def getId: String

Gets unique ID of this game object.

Gets unique ID of this game object.

Inherited from:
CPGameObject
Source:
CPGameObject.scala
def getTags: Set[String]

Gets optional set of organizational tags. Note that by default the set of tags is empty.

Gets optional set of organizational tags. Note that by default the set of tags is empty.

See also:
Inherited from:
CPGameObject
Source:
CPGameObject.scala

Concrete fields

override val getOrigin: String

Gets the origin of this asset. Typically, this should be a URL, file name or class name for in-code assets like array images, animations or system font.

Gets the origin of this asset. Typically, this should be a URL, file name or class name for in-code assets like array images, animations or system font.

Source:
CPFont.scala