text_style

Charmy text style module.

This module is relatively simple, which only contains ability to express fonts.

class charmy.styles.text_style.WEIGHT

基类:object

Preset constant values of fontweight.

Introduction to TrueType Fontweight

TrueType fontweight determines the thickness of text. It has some common presets which are listed below. Learn more in [MSDN docs about this](https://learn.microsoft.com/en-us/dotnet/api/system.windows.fontweights?view=netframework-4.8#remarks).

List of Presets

Thin / Hairline THIN 100 Extra Light / Ultra Light EXTRALIGHT 200 Light LIGHT 300 Regular REGULAR 400 Medium MEDIUM 500 Semi Bold SEMIBOLD 600 Bold BOLD 700 Extra Bold / Ultra Bold EXTRABOLD 800 Black / Heavy BLACK 900 Extra Black / Ultra Black EXTRABLACK 950

THIN: int = 100
EXTRALIGHT: int = 200
LIGHT: int = 300
REGULAR: int = 400
MEDIUM: int = 500
SEMIBOLD: int = 600
BOLD: int = 700
EXTRABOLD: int = 800
BLACK: int = 900
EXTRABLACK: int = 950
class charmy.styles.text_style.TextStyle(font: _typing.Optional[str] = None, size: _typing.Optional[int] | float = None, weight: int = 400, italic: bool = False, underlined: bool | _draw.DrawnLine = False, strikethrough: bool | _draw.DrawnLine = False)

基类:object

Represents text styles in Charmy.

sys_fonts: _typing.ClassVar[list[str]] = ['Arial']
sys_default: _typing.ClassVar[_typing.Self] = <charmy.styles.text_style.TextStyle object>
__init__(font: _typing.Optional[str] = None, size: _typing.Optional[int] | float = None, weight: int = 400, italic: bool = False, underlined: bool | _draw.DrawnLine = False, strikethrough: bool | _draw.DrawnLine = False)

To express a font style in Charmy.

参数:
  • font -- The name of the font to use, default is system font (reported by backend)

  • size -- The size of the text, default is system font size (reported by backend)

  • weight -- Weight of the text, in integer, default is charmy.font.WEIGHT.REGULAR which equals to 400

  • italic -- Whether the text should be italic, default is False

  • underlined -- Either a bool indicating if underlined, or a DrawnLine object to specify line used, default is False

  • strikethrough -- Either a bool indicating if striked through, or a DrawnLine object to specify line used, default is False

For parameter weight

See [TrueType fontweight](https://learn.microsoft.com/en-us/dotnet/api/system.windows.fontweights?view=netframework-4.8#remarks) to learn more about the values. Presets are provided in charmy.font.WEIGHT class, which my be used in the way shown below

font: str
size: int | float
weight: int
italic: bool
underlined: bool | _draw.DrawnLine
strikethrough: bool | _draw.DrawnLine
static from_json(json_content)
get_text_boundary(text: str, backend: _typing.Optional[_backend.Backend]) _shape.ShapeRange

Get boundary of a specific text in this style. (NOT IMPLEMENTED)