CPArrayImage

Companion object contains utility functions.

Companion:
class
Source:
CPArrayImage.scala
class Object
trait Matchable
class Any

Value members

Concrete methods

def apply(pxs: Seq[CPPixel], spacePx: CPPixel, align: Int): CPImage

This is a special constructor that expects given sequence of pixels to represent one or multiple lines of text. This method takes given pixels, splits them into individual lines by the system-specific new line separator, and then aligns those lines based on the align parameter. In the end, it creates a new image from those split and optionally aligned lines of text.

This is a special constructor that expects given sequence of pixels to represent one or multiple lines of text. This method takes given pixels, splits them into individual lines by the system-specific new line separator, and then aligns those lines based on the align parameter. In the end, it creates a new image from those split and optionally aligned lines of text.

This constructor conveniently supports CPMarkup functionality. Here's an example of defining CPMarkup and using this constructor to create an image:

   val markup = CPMarkup(
       C_GREEN,
       Option(C_BLACK),
       Seq(
           CPMarkupElement("<$", "$>", _&&(C_RED, C_WHITE)),
           CPMarkupElement("{#", "#}", _&&(C_BLUE, C_YELLOW)),
           CPMarkupElement("(?", "?)", _&&(C_BLACK, C_WHITE))
       )
   )
   val pxs = markup.process("text <$ red on white (? black on white ?)$> {# blue on yellow #}")
   val img = CPArrayImage(pxs, bgPx, align = -1) // Left-aligned image.
Value parameters:
align

Alignment of text. The only allowed values are (with 2 being the default value):

  • -1 - left justified alignment, i.e. add necessary spaces to the end of the line..
  • 0 - centered alignment, i.e. add necessary spaces to both end and the beginning of the line.
  • 1 - right justified alignment, i.e. add necessary spaces at the beginning of the line.
  • 2 - no alignment, the text is taken as is. Necessary spaces added to the end of the each line.
pxs

List of pixels to split and align.

spacePx

A pixel to use to pad for leading and/or trailing spaces.

Source:
CPArrayImage.scala
def prepPadSeq(marginCh: Char, len: Int, s: String, trim: Boolean): Seq[String]

Converts margin-based Scala string into sequence of strings.

Converts margin-based Scala string into sequence of strings.

Value parameters:
len

Length to pad to each string.

marginCh

Margin character.

s

Margin-based Scala string to convert.

trim

Whether or not to trim leading and trailing empty string.

Source:
CPArrayImage.scala
def prepPadSeq(len: Int, s: String, trim: Boolean): Seq[String]

Converts margin-based Scala string into sequence of strings.

Converts margin-based Scala string into sequence of strings.

Value parameters:
len

Length to pad to each string.

s

Margin-based Scala string to convert. '|' character will be used for margin.

trim

Whether or not to trim leading and trailing empty string. The default value is true.

Source:
CPArrayImage.scala
def prepSeq(marginCh: Char, s: String, trim: Boolean): Seq[String]

Converts margin-based Scala string into sequence of strings.

Converts margin-based Scala string into sequence of strings.

Value parameters:
marginCh

Margin character.

s

Margin-based Scala string to convert.

trim

Whether or not to trim leading and trailing empty string.

Source:
CPArrayImage.scala
def prepSeq(s: String, trim: Boolean): Seq[String]

Converts margin-based Scala string into sequence of strings.

Converts margin-based Scala string into sequence of strings.

Value parameters:
s

Margin-based Scala string to convert. '|' character will be used for margin.

trim

Whether or not to trim leading and trailing empty string. The default value is true.

Source:
CPArrayImage.scala