Class CharacterStyler
- class ooodev.write.style.direct.character_styler.CharacterStyler(write_doc, component)[source]
Bases:
WriteDocPropPartial,EventsPartial,LoInstPropsPartial,FontOnlyPartial,FontEffectsPartial,FontPartial,WriteCharBordersPartial,FontPositionPartial,HighlightPartial,TheDictionaryPartialCharacter 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_APPLYINGevent is raised before a style is applied. TheWriteNamedEvent.CHARACTER_STYLE_APPLIEDevent is raised after a style has been applied. The event data is a dictionary that contains the following:cancel_apply: If set toTruethe style will not be applied. This is only used in theCHARACTER_STYLE_APPLYINGevent.this_component: The component that the style is being applied to. This is the normally same component passed to the constructor. Usually aXTextCursor.styler_object: The style that is being applied. This isNonewhenCHARACTER_STYLE_APPLYINGis raised. Is the style that was applied whenCHARACTER_STYLE_APPLIEDis raised.
Other style specific data is also in the dictionary such as the parameter values used to apply the style.
The
event_args.event_sourceis the instance of theCharacterStylerclass.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
triggermethod called when this classtriggermethod 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.
- remove_event_observer(observer)
Removes an observer
- Parameters:
observer (EventObserver) – One or more observers to add.
- Returns:
Trueif 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,rightare ignoredshadow (Shadow | None, optional) – Character Shadow
padding (Padding | None, optional) – Character padding
- Raises:
CancelEventError – If the event
before_style_char_bordersis cancelled and not handled.- Returns:
Attribute Options Style instance or
Noneif cancelled.- Return type:
Borders | None
Hint
BorderLinecan be imported fromooodev.format.writer.direct.char.bordersBorderLine2can be imported fromooodev.format.writer.direct.char.bordersBorderLineKindcan be imported fromooodev.format.writer.direct.char.bordersBorderscan be imported fromooodev.format.writer.direct.char.bordersLineSizecan be imported fromooodev.format.writer.direct.char.bordersPaddingcan be imported fromooodev.format.writer.direct.char.bordersShadowcan be imported fromooodev.format.inner.direct.write.char.border.shadowShadowFormatcan be imported fromooodev.format.writer.direct.char.bordersSidecan be imported fromooodev.format.writer.direct.char.borderssidecan be imported fromooodev.format.writer.direct.char.bordersSidescan be imported fromooodev.format.writer.direct.char.bordersShadowLocationcan be importedfrom 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
mmunits) or Class UnitT.right (float, UnitT, optional) – Right (in
mmunits) or Class UnitT.top (float, UnitT, optional) – Top (in
mmunits) or Class UnitT.bottom (float, UnitT, optional) – Bottom (in
mmunits) or Class UnitT.all_sides (float, UnitT, optional) – Left, right, top, bottom (in
mmunits) or Class UnitT. If argument is present thenleft,right,top, andbottomarguments are ignored.
- Raises:
CancelEventError – If the event
before_style_char_bordersis cancelled and not handled.- Returns:
Borders Style instance or
Noneif 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. DefaultStandardColor.BLACKwidth (LineSize, float, UnitT, optional) – Contains the width in of a single line or the width of outer part of a double line (in
ptunits) or Class UnitT. If this value is zero, no line is drawn. DefaultLineSize.THINshadow (Shadow | None, optional) – Character Shadow
padding (Padding | None, optional) – Character padding
- Raises:
CancelEventError – If the event
before_style_char_bordersis cancelled and not handled.- Returns:
Borders Style instance or
Noneif cancelled.- Return type:
Borders | None
Hint
BorderLinecan be imported fromooodev.format.writer.direct.char.bordersBorderLine2can be imported fromooodev.format.writer.direct.char.bordersBorderLineKindcan be imported fromooodev.format.writer.direct.char.bordersLineSizecan be imported fromooodev.format.writer.direct.char.bordersPaddingcan be imported fromooodev.format.writer.direct.char.bordersShadowcan be imported fromooodev.format.writer.direct.char.bordersShadowFormatcan be imported fromooodev.format.writer.direct.char.bordersShadowLocationcan be importedfrom ooo.dyn.table.shadow_location
- style_font(name=None, size=None, font_style=None, lang=None)
Style Font.
- Parameters:
- Raises:
CancelEventError – If the event
before_style_font_onlyis cancelled and not handled.- Returns:
Font Only instance or
Noneif cancelled.- Return type:
FontOnlyT | None
See also
- 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-1the automatic color is applied.transparency (Intensity, int, optional) – The transparency value from
0to100for 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_effectis cancelled and not handled.- Returns:
Font Effects instance or
Noneif cancelled.- Return type:
FontEffectsT | None
Hint
CaseMapEnumcan be imported fromooo.dyn.style.case_mapFontReliefEnumcan be imported fromooo.dyn.awt.font_reliefFontStrikeoutEnumcan be imported fromooo.dyn.awt.font_strikeoutFontLinecan be imported fromooodev.format.inner.direct.write.char.font.font_effectsIntensitycan be imported fromooodev.utils.data_type.intensityFontUnderlineEnumcan be imported fromooo.dyn.awt.font_underline
- style_font_effect_get()
Gets the font effect Style.
- Raises:
CancelEventError – If the event
before_style_font_effect_getis cancelled and not handled.- Returns:
Font Effect style or
Noneif 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-1the automatic color is applied.line (FontUnderlineEnum, optional) – Font Line kind.
overline (bool, optional) – If
Truethe line is overline, otherwise it is underline.
- Raises:
CancelEventError – If the event
before_style_font_effectis cancelled and not handled.- Returns:
Font Effects instance or
Noneif cancelled.- Return type:
FontEffectsT | None
Hint
FontUnderlineEnumcan be imported fromooo.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
weightto bold.i (bool, optional) – Shortcut to set
slantto italic.u (bool, optional) – Shortcut ot set
underlineto 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-1will 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_fontis cancelled and not handled.- Returns:
Font instance or
Noneif cancelled.- Return type:
FontT | None
Hint
FontFamilyEnumcan be imported fromooo.dyn.awt.font_familyCharSetEnumcan be imported fromooo.dyn.awt.char_setShadowFormatcan be imported fromooo.dyn.table.shadow_formatFontSlantcan be imported fromooo.dyn.awt.font_slantFontStrikeoutEnumcan be imported fromooo.dyn.awt.font_strikeoutFontWeightEnumcan be imported fromooo.dyn.awt.font_weightFontLinecan be imported fromooodev.format.inner.direct.write.char.font.font_effectsCharSpacingKindcan be imported fromooodev.format.inner.direct.write.char.font.font_position
- style_font_get()
Gets the font Style.
- Raises:
CancelEventError – If the event
before_style_font_only_getis cancelled and not handled.- Returns:
Font style or
Noneif 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
0for automatic; Otherwise value from1to100.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_numberis cancelled and not handled.- Returns:
Font Only instance or
Noneif cancelled.- Return type:
FontPositionT | None
Hint
Anglecan be imported fromooodev.unitsCharSpacingKindcan be imported fromooodev.format.writer.direct.char.fontFontScriptKindcan be imported fromooodev.format.writer.direct.char.fontIntensitycan be imported fromooodev.utils.data_type.intensity
- style_font_position_get()
Gets the Font Position Style.
- Raises:
CancelEventError – If the event
before_style_number_number_getis cancelled and not handled.- Returns:
Font Position style or
Noneif cancelled.- Return type:
FontPositionT | None
- style_highlight(color)
Style Font Highlight.
- Parameters:
color (Color, optional) – Highlight Color. A value of
-1Set color to Transparent.- Raises:
CancelEventError – If the event
before_style_font_highlightis cancelled and not handled.- Returns:
Font Only instance or
Noneif cancelled.- Return type:
HighlightT | None
See also
- style_highlight_get()
Gets the font highlight style.
- Raises:
CancelEventError – If the event
before_style_font_highlight_getis cancelled and not handled.- Returns:
Font style or
Noneif 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:
- 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:
- property office_doc: OfficeDocumentT
Office Document.
- Return type: