Class CharacterStyler

class ooodev.write.style.direct.character_styler.CharacterStyler(write_doc, component)[source]

Bases: WriteDocPropPartial, EventsPartial, LoInstPropsPartial, FontOnlyPartial, FontEffectsPartial, FontPartial, WriteCharBordersPartial, FontPositionPartial, HighlightPartial, TheDictionaryPartial

Character Styler class.

Class set various character properties.

Events are raises when a style is being applied and when a style has been applied. The WriteNamedEvent.CHARACTER_STYLE_APPLYING event is raised before a style is applied. The WriteNamedEvent.CHARACTER_STYLE_APPLIED event is raised after a style has been applied. The event data is a dictionary that contains the following:

  • cancel_apply: If set to True the style will not be applied. This is only used in the CHARACTER_STYLE_APPLYING event.

  • this_component: The component that the style is being applied to. This is the normally same component passed to the constructor. Usually a XTextCursor.

  • styler_object: The style that is being applied. This is None when CHARACTER_STYLE_APPLYING is raised. Is the style that was applied when CHARACTER_STYLE_APPLIED is raised.

Other style specific data is also in the dictionary such as the parameter values used to apply the style.

The event_args.event_source is the instance of the CharacterStyler class.

Subscribing to Events:

from ooodev.events.write_named_event import WriteNamedEvent
# ... other code

def on_char_style_applied(src: Any, event_args: EventArgs) -> None:
    styler = cast(CharacterStyler, src)
    skip = styler.extra_data.get("skip", False)
    if skip:
        return
    cursor = cast("XTextCursor", event_args.event_data.get("this_component", None))
    if cursor is None:
        return
    cursor.gotoEnd(False)
    styler.clear()
    event_args.event_source

doc = WriteDoc.create_doc(visible=True)
cursor = doc.get_cursor()

# subscribe to the event that resets the cursor when a style is applied.
cursor.style_direct_char.subscribe_event(WriteNamedEvent.CHARACTER_STYLE_APPLIED, on_char_style_applied)
# or alternatively
# cursor.subscribe_event(WriteNamedEvent.CHARACTER_STYLE_APPLIED, on_char_style_applied)
Parameters:
  • write_doc (WriteDoc) –

  • component (Any) –

__init__(write_doc, component)[source]

Constructor.

Parameters:
  • write_doc (WriteDoc) – Write Document instance.

  • component (Any) – component instance. Usually a XTextCursor.

Return type:

None

add_event_observers(*args)

Adds observers that gets their trigger method called when this class trigger method is called.

Parameters:

args (EventObserver) – One or more observers to add.

Return type:

None

Note

Observers are removed automatically when they are out of scope.

clear()[source]

Clears the formatting of the character.

Return type:

None

remove_event_observer(observer)

Removes an observer

Parameters:

observer (EventObserver) – One or more observers to add.

Returns:

True if observer has been removed; Otherwise, False.

Return type:

bool

style_borders(*, right=None, left=None, top=None, bottom=None, border_side=None, shadow=None, padding=None)

Style Write Character Borders.

Parameters:
  • left (Side | None, optional) – Determines the line style at the left edge.

  • right (Side | None, optional) – Determines the line style at the right edge.

  • top (Side | None, optional) – Determines the line style at the top edge.

  • bottom (Side | None, optional) – Determines the line style at the bottom edge.

  • border_side (Side | None, optional) – Determines the line style at the top, bottom, left, right edges. If this argument has a value then arguments top, bottom, left, right are ignored

  • shadow (Shadow | None, optional) – Character Shadow

  • padding (Padding | None, optional) – Character padding

Raises:

CancelEventError – If the event before_style_char_borders is cancelled and not handled.

Returns:

Attribute Options Style instance or None if cancelled.

Return type:

Borders | None

Hint

  • BorderLine can be imported from ooodev.format.writer.direct.char.borders

  • BorderLine2 can be imported from ooodev.format.writer.direct.char.borders

  • BorderLineKind can be imported from ooodev.format.writer.direct.char.borders

  • Borders can be imported from ooodev.format.writer.direct.char.borders

  • LineSize can be imported from ooodev.format.writer.direct.char.borders

  • Padding can be imported from ooodev.format.writer.direct.char.borders

  • Shadow can be imported from ooodev.format.inner.direct.write.char.border.shadow

  • ShadowFormat can be imported from ooodev.format.writer.direct.char.borders

  • Side can be imported from ooodev.format.writer.direct.char.borders

  • side can be imported from ooodev.format.writer.direct.char.borders

  • Sides can be imported from ooodev.format.writer.direct.char.borders

  • ShadowLocation can be imported from ooo.dyn.table.shadow_location

style_borders_padding(*, left=None, right=None, top=None, bottom=None, all_sides=None)

Style Padding for Write Characters.

Parameters:
  • left (float, UnitT, optional) – Left (in mm units) or Class UnitT.

  • right (float, UnitT, optional) – Right (in mm units) or Class UnitT.

  • top (float, UnitT, optional) – Top (in mm units) or Class UnitT.

  • bottom (float, UnitT, optional) – Bottom (in mm units) or Class UnitT.

  • all_sides (float, UnitT, optional) – Left, right, top, bottom (in mm units) or Class UnitT. If argument is present then left, right, top, and bottom arguments are ignored.

Raises:

CancelEventError – If the event before_style_char_borders is cancelled and not handled.

Returns:

Borders Style instance or None if cancelled.

Return type:

Borders | None

style_borders_side(*, line=BorderLineKind.SOLID, color=0, width=LineSize.THIN, shadow=None, padding=None)

Style All Write Character Borders.

Parameters:
  • line (BorderLineStyleEnum, optional) – Line Style of the border. Default BorderLineKind.SOLID.

  • color (Color, optional) – Color of the border. Default StandardColor.BLACK

  • width (LineSize, float, UnitT, optional) – Contains the width in of a single line or the width of outer part of a double line (in pt units) or Class UnitT. If this value is zero, no line is drawn. Default LineSize.THIN

  • shadow (Shadow | None, optional) – Character Shadow

  • padding (Padding | None, optional) – Character padding

Raises:

CancelEventError – If the event before_style_char_borders is cancelled and not handled.

Returns:

Borders Style instance or None if cancelled.

Return type:

Borders | None

Hint

  • BorderLine can be imported from ooodev.format.writer.direct.char.borders

  • BorderLine2 can be imported from ooodev.format.writer.direct.char.borders

  • BorderLineKind can be imported from ooodev.format.writer.direct.char.borders

  • LineSize can be imported from ooodev.format.writer.direct.char.borders

  • Padding can be imported from ooodev.format.writer.direct.char.borders

  • Shadow can be imported from ooodev.format.writer.direct.char.borders

  • ShadowFormat can be imported from ooodev.format.writer.direct.char.borders

  • ShadowLocation can be imported from ooo.dyn.table.shadow_location

style_font(name=None, size=None, font_style=None, lang=None)

Style Font.

Parameters:
  • name (str | None, optional) – Font Name.

  • size (float | UnitT | None, optional) – Font Size in PT units or UnitT.

  • font_style (str | None, optional) – Font Style such as Bold Italics

  • lang (FontLangT | None, optional) – Font Language.

Raises:

CancelEventError – If the event before_style_font_only is cancelled and not handled.

Returns:

Font Only instance or None if cancelled.

Return type:

FontOnlyT | None

See also

FontLang

style_font_effect(*, color=None, transparency=None, overline=None, underline=None, strike=None, word_mode=None, case=None, relief=None, outline=None, shadowed=None)

Style Font options.

Parameters:
  • color (Color, optional) – The value of the text color. If value is -1 the automatic color is applied.

  • transparency (Intensity, int, optional) – The transparency value from 0 to 100 for the font color.

  • overline (FontLine, optional) – Character overline values.

  • underline (FontLine, optional) – Character underline values.

  • strike (FontStrikeoutEnum, optional) – Determines the type of the strike out of the character.

  • word_mode (bool, optional) – If True, the underline and strike-through properties are not applied to white spaces.

  • case (CaseMapEnum, optional) – Specifies the case of the font.

  • relief (FontReliefEnum, optional) – Specifies the relief of the font.

  • outline (bool, optional) – Specifies if the font is outlined.

  • shadowed (bool, optional) – Specifies if the characters are formatted and displayed with a shadow effect.

Raises:

CancelEventError – If the event before_style_font_effect is cancelled and not handled.

Returns:

Font Effects instance or None if cancelled.

Return type:

FontEffectsT | None

Hint

  • CaseMapEnum can be imported from ooo.dyn.style.case_map

  • FontReliefEnum can be imported from ooo.dyn.awt.font_relief

  • FontStrikeoutEnum can be imported from ooo.dyn.awt.font_strikeout

  • FontLine can be imported from ooodev.format.inner.direct.write.char.font.font_effects

  • Intensity can be imported from ooodev.utils.data_type.intensity

  • FontUnderlineEnum can be imported from ooo.dyn.awt.font_underline

style_font_effect_get()

Gets the font effect Style.

Raises:

CancelEventError – If the event before_style_font_effect_get is cancelled and not handled.

Returns:

Font Effect style or None if cancelled.

Return type:

FontEffectsT | None

style_font_effect_line(line=None, color=None, overline=False)

Style Font Underline or Overline.

This method is a subset of style_font_effect() method for convenience.

Parameters:
  • color (Color, optional) – The value of the text color. If value is -1 the automatic color is applied.

  • line (FontUnderlineEnum, optional) – Font Line kind.

  • overline (bool, optional) – If True the line is overline, otherwise it is underline.

Raises:

CancelEventError – If the event before_style_font_effect is cancelled and not handled.

Returns:

Font Effects instance or None if cancelled.

Return type:

FontEffectsT | None

Hint

  • FontUnderlineEnum can be imported from ooo.dyn.awt.font_underline

style_font_general(b=None, i=None, u=None, bg_color=None, bg_transparent=None, charset=None, color=None, family=None, name=None, overline=None, rotation=None, shadow_fmt=None, shadowed=None, size=None, slant=None, spacing=None, strike=None, subscript=None, superscript=None, underline=None, weight=None, word_mode=None)

Style Font.

Parameters:
  • b (bool, optional) – Shortcut to set weight to bold.

  • i (bool, optional) – Shortcut to set slant to italic.

  • u (bool, optional) – Shortcut ot set underline to underline.

  • bg_color (Color, optional) – The value of the text background color.

  • bg_transparent (bool, optional) – Determines if the text background color is set to transparent.

  • charset (CharSetEnum, optional) – The text encoding of the font.

  • color (Color, optional) – The value of the text color. Setting to -1 will cause automatic color.

  • family (FontFamilyEnum, optional) – Font Family.

  • name (str, optional) – This property specifies the name of the font style. It may contain more than one name separated by comma.

  • overline (FontLine, optional) – Character overline values.

  • rotation (int, Angle, optional) – Specifies the rotation of a character in degrees. Depending on the implementation only certain values may be allowed.

  • shadow_fmt (ShadowFormat | None) – (ShadowFormat, optional): Determines the type, color, and width of the shadow.

  • shadowed (bool, optional) – Specifies if the characters are formatted and displayed with a shadow effect.

  • size (float, UnitT, optional) – This value contains the size of the characters in pt (point) units or Class UnitT.

  • slant (FontSlant, optional) – The value of the posture of the document such as FontSlant.ITALIC.

  • spacing (CharSpacingKind, float, UnitT, optional) – Specifies character spacing in pt (point) units or Class UnitT.

  • strike (FontStrikeoutEnum, optional) – Determines the type of the strike out of the character.

  • subscript (bool, optional) – Subscript option.

  • superscript (bool, optional) – Superscript option.

  • underline (FontLine, optional) – Character underline values.

  • weight (FontWeightEnum, optional) – The value of the font weight.

  • word_mode (bool, optional) – If True, the underline and strike-through properties are not applied to white spaces.

Raises:

CancelEventError – If the event before_style_general_font is cancelled and not handled.

Returns:

Font instance or None if cancelled.

Return type:

FontT | None

Hint

  • FontFamilyEnum can be imported from ooo.dyn.awt.font_family

  • CharSetEnum can be imported from ooo.dyn.awt.char_set

  • ShadowFormat can be imported from ooo.dyn.table.shadow_format

  • FontSlant can be imported from ooo.dyn.awt.font_slant

  • FontStrikeoutEnum can be imported from ooo.dyn.awt.font_strikeout

  • FontWeightEnum can be imported from ooo.dyn.awt.font_weight

  • FontLine can be imported from ooodev.format.inner.direct.write.char.font.font_effects

  • CharSpacingKind can be imported from ooodev.format.inner.direct.write.char.font.font_position

style_font_get()

Gets the font Style.

Raises:

CancelEventError – If the event before_style_font_only_get is cancelled and not handled.

Returns:

Font style or None if cancelled.

Return type:

FontOnlyT | None

style_font_position(script_kind=None, raise_lower=None, rel_size=None, rotation=None, scale=None, fit=None, spacing=None, pair=None)

Style Axis Line.

Parameters:
  • script_kind (FontScriptKind, optional) – Specifies Superscript/Subscript option.

  • raise_lower (int, optional) – Specifies raise or Lower as percent value. Set to a value of 0 for automatic.

  • rel_size (int, Intensity, optional) – Specifies relative Font Size as percent value. Set this value to 0 for automatic; Otherwise value from 1 to 100.

  • rotation (int, Angle, optional) – Specifies the rotation of a character in degrees. Depending on the implementation only certain values may be allowed.

  • scale (int, optional) – Specifies scale width as percent value. Min value is 1.

  • fit (bool, optional) – Specifies if rotation is fit to line.

  • spacing (CharSpacingKind, float, UnitT, optional) – Specifies character spacing in pt (point) units or Class UnitT.

  • pair (bool, optional) – Specifies pair kerning.

Raises:

CancelEventError – If the event before_style_number_number is cancelled and not handled.

Returns:

Font Only instance or None if cancelled.

Return type:

FontPositionT | None

Hint

  • Angle can be imported from ooodev.units

  • CharSpacingKind can be imported from ooodev.format.writer.direct.char.font

  • FontScriptKind can be imported from ooodev.format.writer.direct.char.font

  • Intensity can be imported from ooodev.utils.data_type.intensity

style_font_position_get()

Gets the Font Position Style.

Raises:

CancelEventError – If the event before_style_number_number_get is cancelled and not handled.

Returns:

Font Position style or None if cancelled.

Return type:

FontPositionT | None

style_highlight(color)

Style Font Highlight.

Parameters:

color (Color, optional) – Highlight Color. A value of -1 Set color to Transparent.

Raises:

CancelEventError – If the event before_style_font_highlight is cancelled and not handled.

Returns:

Font Only instance or None if cancelled.

Return type:

HighlightT | None

See also

FontLang

style_highlight_get()

Gets the font highlight style.

Raises:

CancelEventError – If the event before_style_font_highlight_get is cancelled and not handled.

Returns:

Font style or None if cancelled.

Return type:

HighlightT | None

subscribe_event(event_name, callback)

Add an event listener to current instance.

Parameters:
  • event_name (str) – Event Name.

  • callback (EventCallback) – Callback of the event listener.

Return type:

None

trigger_event(event_name, event_args)

Trigger an event on current instance.

Parameters:
  • event_name (str) – Event Name.

  • event_args (EventArgsT) – Event Args.

Return type:

None

unsubscribe_event(event_name, callback)

Remove an event listener from current instance.

Parameters:
  • event_name (str) – Event Name.

  • callback (EventCallback) – Callback of the event listener.

Return type:

None

property event_observer: EventObserver

Gets/Sets The Event Observer for this instance.

Return type:

EventObserver

property extra_data: TheDict

Extra Data Key Value Pair Dictionary.

Properties can be assigned properties and access like a dictionary and with dot notation.

Note

This is a dictionary object that can be used to store key value pairs. Generally speaking this data is not part of the object’s main data structure and is not saved with the object (document).

This property is used to store data that is not part of the object’s main data structure and can be used however the developer sees fit.

Return type:

TheDict

property lo_inst: LoInst

Lo Instance

Return type:

LoInst

property office_doc: OfficeDocumentT

Office Document.

Return type:

OfficeDocumentT

property write_doc: WriteDoc

Write Document.

Return type:

WriteDoc