Style

Style helpers for colors and style strings.

Source

Functions

Sgnw\Core\Style\_prefix_color

function _prefix_color($color)

The style module contains regular expressions and functions for parsing and composing style strings.

Style string definition:
https://datatracker.ietf.org/doc/id/draft-slevinski-formal-signwriting-10.html#name-styling-string

Sgnw\Core\Style\style_parse

function style_parse($style_string)

Parse a style string to a structured dictionary.

Parameters

ParameterType
style_stringstring

Returns

array

Examples

\Sgnw\Core\Style\style_parse('-CP10G_blue_D_red,Cyan_');

Sgnw\Core\Style\_prefix_color

function _prefix_color(trim($p))

Sgnw\Core\Style\style_compose

function style_compose($style_dict)

Function to compose style string from dictionary.

Parameters

ParameterType
style_dictarray

Returns

string|null

Examples

\Sgnw\Core\Style\style_compose(['colorize' => true, 'padding' => 10]);

Sgnw\Core\Style\_rgb_to_arr

function _rgb_to_arr($rgb)

Sgnw\Core\Style\_arr_to_hex

function _arr_to_hex($arr)

Sgnw\Core\Style\style_rgb_to_hex

function style_rgb_to_hex($rgb, $tolerance = 0.0)

Function to convert rgb color to hex or "transparent" if below tolerance.

Parameters

ParameterType
rgbstring
tolerancefloat

Returns

string

Examples

\Sgnw\Core\Style\style_rgb_to_hex('rgb(255,255,255)');

Sgnw\Core\Style\style_rgba_to_hex

function style_rgba_to_hex($color, $background)

Function to merge color with background based on alpha transparency.

Parameters

ParameterType
colorstring
backgroundstring

Returns

string

Examples

\Sgnw\Core\Style\style_rgba_to_hex('rgba(255,255,255,0.5)', 'rgb(0,0,0)');

Sgnw\Core\Style\style_merge

function style_merge($style1, $style2)

Function to merge style dictionaries.

Parameters

ParameterType
style1mixed
style2mixed

Returns

array

Examples

\Sgnw\Core\Style\style_merge(['colorize' => true], ['zoom' => 2]);