Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implementing text font strikethrough #606

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/user/text.rst
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ the theme color Accent 1.
font.bold = True
font.italic = None # cause value to be inherited from theme
font.color.theme_color = MSO_THEME_COLOR.ACCENT_1
font.strikethrough = True

If you prefer, you can set the font color to an absolute RGB value. Note that
this will not change color when the theme is changed::
Expand Down
12 changes: 12 additions & 0 deletions pptx/oxml/simpletypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -727,6 +727,18 @@ class ST_TextWrappingType(XsdTokenEnumeration):
_members = (NONE, SQUARE)


class ST_TextFontStrike(XsdStringEnumeration):
"""
Valid values for <a:bodyPr strike=""> attribute
"""

NO_STRIKE = "noStrike"
SINGLE_STRIKE = "sngStrike"
DOUBLE_STRIKE = "dblStrike"

_members = (NO_STRIKE, SINGLE_STRIKE, DOUBLE_STRIKE)


class ST_UniversalMeasure(BaseSimpleType):
@classmethod
def convert_from_xml(cls, str_value):
Expand Down
4 changes: 3 additions & 1 deletion pptx/oxml/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
ST_TextSpacingPoint,
ST_TextTypeface,
ST_TextWrappingType,
ST_TextFontStrike,
XsdBoolean,
)
from pptx.oxml.xmlchemy import (
Expand Down Expand Up @@ -306,7 +307,8 @@ class CT_TextCharacterProperties(BaseOxmlElement):
b = OptionalAttribute("b", XsdBoolean)
i = OptionalAttribute("i", XsdBoolean)
u = OptionalAttribute("u", MSO_TEXT_UNDERLINE_TYPE)

strike = OptionalAttribute("strike", ST_TextFontStrike)

def _new_gradFill(self):
return CT_GradientFillProperties.new_gradFill()

Expand Down
23 changes: 22 additions & 1 deletion pptx/text/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from pptx.enum.lang import MSO_LANGUAGE_ID
from pptx.enum.text import MSO_AUTO_SIZE, MSO_UNDERLINE
from pptx.opc.constants import RELATIONSHIP_TYPE as RT
from pptx.oxml.simpletypes import ST_TextWrappingType
from pptx.oxml.simpletypes import ST_TextWrappingType, ST_TextFontStrike
from pptx.shapes import Subshape
from pptx.text.fonts import FontFiles
from pptx.text.layout import TextFitter
Expand Down Expand Up @@ -309,6 +309,27 @@ def bold(self):
def bold(self, value):
self._rPr.b = value

@property
def strikethrough(self):
return {
ST_TextFontStrike.SINGLE_STRIKE: True,
ST_TextFontStrike.DOUBLE_STRIKE: True,
ST_TextFontStrike.NO_STRIKE: False,
None: None,
}[self._rPr.strike]

@strikethrough.setter
def strikethrough(self, value):
if value not in (True, False, None):
raise ValueError(
"assigned value must be True, False, or None, got %s" % value
)
self._rPr.strike = {
True: ST_TextFontStrike.SINGLE_STRIKE,
False: ST_TextFontStrike.NO_STRIKE,
None: None,
}[value]

@lazyproperty
def color(self):
"""
Expand Down