@@ -1958,6 +1958,21 @@ def getControlFieldSpeech( # noqa: C901
19581958 return []
19591959
19601960
1961+ def _getColorName (color , withRGB = False ):
1962+ """Helper function that will return the appropriate string presentation of a color,
1963+ based on whether the user wants the RGB value reported or not.
1964+ """
1965+ if not isinstance (color , colors .RGB ):
1966+ return str (color )
1967+ if withRGB :
1968+ return (
1969+ f"{ color .name } "
1970+ f" (RGB: { color .red } , { color .green } , { color .blue } "
1971+ f" / #{ color .red :02x} { color .green :02x} { color .blue :02x} )"
1972+ )
1973+ return color .name
1974+
1975+
19611976# C901 'getFormatFieldSpeech' is too complex
19621977# Note: when working on getFormatFieldSpeech, look for opportunities to simplify
19631978# and move logic out into smaller helper functions.
@@ -1973,6 +1988,7 @@ def getFormatFieldSpeech( # noqa: C901
19731988 if not formatConfig :
19741989 formatConfig = config .conf ["documentFormatting" ]
19751990 textList = []
1991+ technical = formatConfig .get ("technical" , False )
19761992 if formatConfig ["reportTables" ]:
19771993 tableInfo = attrs .get ("table-info" )
19781994 oldTableInfo = attrsCache .get ("table-info" ) if attrsCache is not None else None
@@ -2095,35 +2111,34 @@ def getFormatFieldSpeech( # noqa: C901
20952111 textList .append (fontSize )
20962112 if formatConfig ["reportColor" ]:
20972113 color = attrs .get ("color" )
2114+ colorName = _getColorName (color , withRGB = technical )
20982115 oldColor = attrsCache .get ("color" ) if attrsCache is not None else None
20992116 backgroundColor = attrs .get ("background-color" )
21002117 oldBackgroundColor = attrsCache .get ("background-color" ) if attrsCache is not None else None
21012118 backgroundColor2 = attrs .get ("background-color2" )
21022119 oldBackgroundColor2 = attrsCache .get ("background-color2" ) if attrsCache is not None else None
21032120 bgColorChanged = backgroundColor != oldBackgroundColor or backgroundColor2 != oldBackgroundColor2
2104- bgColorText = backgroundColor . name if isinstance (backgroundColor ,colors . RGB ) else backgroundColor
2121+ bgColorName = _getColorName (backgroundColor , withRGB = technical )
21052122 if backgroundColor2 :
2106- bg2Name = backgroundColor2 . name if isinstance (backgroundColor2 ,colors . RGB ) else backgroundColor2
2123+ bgColor2Name = _getColorName (backgroundColor2 , withRGB = technical )
21072124 # Translators: Reported when there are two background colors.
21082125 # This occurs when, for example, a gradient pattern is applied to a spreadsheet cell.
21092126 # {color1} will be replaced with the first background color.
21102127 # {color2} will be replaced with the second background color.
2111- bgColorText = _ ("{color1} to {color2}" ).format (color1 = bgColorText , color2 = bg2Name )
2128+ bgColorName = _ ("{color1} to {color2}" ).format (color1 = bgColorName , color2 = bgColor2Name )
21122129 if color and backgroundColor and color != oldColor and bgColorChanged :
21132130 # Translators: Reported when both the text and background colors change.
21142131 # {color} will be replaced with the text color.
21152132 # {backgroundColor} will be replaced with the background color.
2116- textList .append (_ ("{color} on {backgroundColor}" ).format (
2117- color = color .name if isinstance (color ,colors .RGB ) else color ,
2118- backgroundColor = bgColorText ))
2133+ textList .append (_ ("{color} on {backgroundColor}" ).format (color = colorName , backgroundColor = bgColorName ))
21192134 elif color and color != oldColor :
21202135 # Translators: Reported when the text color changes (but not the background color).
21212136 # {color} will be replaced with the text color.
2122- textList .append (_ ("{color}" ).format (color = color . name if isinstance ( color , colors . RGB ) else color ))
2137+ textList .append (_ ("{color}" ).format (colorName ))
21232138 elif backgroundColor and bgColorChanged :
21242139 # Translators: Reported when the background color changes (but not the text color).
21252140 # {backgroundColor} will be replaced with the background color.
2126- textList .append (_ ("{backgroundColor} background" ).format (backgroundColor = bgColorText ))
2141+ textList .append (_ ("{backgroundColor} background" ).format (backgroundColor = bgColorName ))
21272142 backgroundPattern = attrs .get ("background-pattern" )
21282143 oldBackgroundPattern = attrsCache .get ("background-pattern" ) if attrsCache is not None else None
21292144 if backgroundPattern and backgroundPattern != oldBackgroundPattern :
0 commit comments