Skip to content

Commit

Permalink
In Microsoft Excel 2010 and later, cell shading and gradient fill is …
Browse files Browse the repository at this point in the history
…now reported. Automatic reporting is controlled by the Report colors option in NVDA's Document Formatting preferences.

Fixes #3683. Closes #5649 (PR).
  • Loading branch information
ManshulBelani authored and jcsteh committed Mar 8, 2016
1 parent 1b69749 commit 3427d49
Show file tree
Hide file tree
Showing 4 changed files with 126 additions and 7 deletions.
1 change: 1 addition & 0 deletions contributors.txt
Expand Up @@ -170,3 +170,4 @@ Siddalingeshwar Ingalagi
Dong Hui Park
Austin Hicks
Dinesh Kaushal
Manshul Belani
106 changes: 104 additions & 2 deletions source/NVDAObjects/window/excel.py
Expand Up @@ -72,6 +72,98 @@
xlCellTypeSameValidation =-4175 # from enum XlCellType
xlCellTypeVisible =12 # from enum XlCellType

#Excel Cell Patterns (from enum XlPattern)
xlPatternAutomatic = -4105
xlPatternChecker = 9
xlPatternCrissCross = 16
xlPatternDown = -4121
xlPatternGray16 = 17
xlPatternGray25 = -4124
xlPatternGray50 = -4125
xlPatternGray75 = -4126
xlPatternGray8 = 18
xlPatternGrid = 15
xlPatternHorizontal = -4128
xlPatternLightDown = 13
xlPatternLightHorizontal = 11
xlPatternLightUp = 14
xlPatternLightVertical = 12
xlPatternNone = -4142
xlPatternSemiGray75 = 10
xlPatternSolid = 1
xlPatternUp = -4162
xlPatternVertical = -4166
xlPatternLinearGradient = 4000
xlPatternRectangularGradient = 4001

backgroundPatternLabels={
# See https://msdn.microsoft.com/en-us/library/microsoft.office.interop.excel.xlpattern.aspx
# Translators: A type of background pattern in Microsoft Excel.
# Excel controls the pattern.
xlPatternAutomatic:_("automatic"),
# Translators: A type of background pattern in Microsoft Excel.
# Checkerboard
xlPatternChecker:_("checker"),
# Translators: A type of background pattern in Microsoft Excel.
# Criss-cross lines
xlPatternCrissCross:_("crisscross"),
# Translators: A type of background pattern in Microsoft Excel.
# Dark diagonal lines running from the upper left to the lower right
xlPatternDown:_("down"),
# Translators: A type of background pattern in Microsoft Excel.
# 16% gray
xlPatternGray16:_("gray16"),
# Translators: A type of background pattern in Microsoft Excel.
# 25% gray
xlPatternGray25:_("gray25"),
# Translators: A type of background pattern in Microsoft Excel.
# 50% gray
xlPatternGray50:_("gray50"),
# Translators: A type of background pattern in Microsoft Excel.
# 75% gray
xlPatternGray75:_("gray75"),
# Translators: A type of background pattern in Microsoft Excel.
# 8% gray
xlPatternGray8:_("gray8"),
# Translators: A type of background pattern in Microsoft Excel.
# Grid
xlPatternGrid:_("grid"),
# Translators: A type of background pattern in Microsoft Excel.
# Dark horizontal lines
xlPatternHorizontal:_("horizontal"),
# Translators: A type of background pattern in Microsoft Excel.
# Light diagonal lines running from the upper left to the lower right
xlPatternLightDown:_("light down"),
# Translators: A type of background pattern in Microsoft Excel.
# Light horizontal lines
xlPatternLightHorizontal:_("light horizontal"),
# Translators: A type of background pattern in Microsoft Excel.
# Light diagonal lines running from the lower left to the upper right
xlPatternLightUp:_("light up"),
# Translators: A type of background pattern in Microsoft Excel.
# Light vertical bars
xlPatternLightVertical:_("light vertical"),
# Translators: A type of background pattern in Microsoft Excel.
# No pattern
xlPatternNone:_("none"),
# Translators: A type of background pattern in Microsoft Excel.
# 75% dark moire
xlPatternSemiGray75:_("semi gray75"),
# Translators: A type of background pattern in Microsoft Excel.
# Solid color
xlPatternSolid:_("solid"),
# Translators: A type of background pattern in Microsoft Excel.
# Dark diagonal lines running from the lower left to the upper right
xlPatternUp:_("up"),
# Translators: A type of background pattern in Microsoft Excel.
# Dark vertical bars
xlPatternVertical:_("vertical"),
# Translators: A type of background pattern in Microsoft Excel.
xlPatternLinearGradient:_("linear gradient"),
# Translators: A type of background pattern in Microsoft Excel.
xlPatternRectangularGradient:_("rectangular gradient"),
}

re_RC=re.compile(r'R(?:\[(\d+)\])?C(?:\[(\d+)\])?')
re_absRC=re.compile(r'^R(\d+)C(\d+)(?::R(\d+)C(\d+))?$')

Expand Down Expand Up @@ -795,7 +887,11 @@ class ExcelCellTextInfo(NVDAObjectTextInfo):

def _getFormatFieldAndOffsets(self,offset,formatConfig,calculateOffsets=True):
formatField=textInfos.FormatField()
fontObj=self.obj.excelCellObject.font
if (self.obj.excelCellObject.Application.Version > "12.0"):
cellObj=self.obj.excelCellObject.DisplayFormat
else:
cellObj=self.obj.excelCellObject
fontObj=cellObj.font
if formatConfig['reportAlignment']:
value=alignmentLabels.get(self.obj.excelCellObject.horizontalAlignment)
if value:
Expand Down Expand Up @@ -825,7 +921,13 @@ def _getFormatFieldAndOffsets(self,offset,formatConfig,calculateOffsets=True):
except COMError:
pass
try:
formatField['background-color']=colors.RGB.fromCOLORREF(int(self.obj.excelCellObject.interior.color))
pattern = cellObj.Interior.Pattern
formatField['background-pattern'] = backgroundPatternLabels.get(pattern)
if pattern in (xlPatternLinearGradient, xlPatternRectangularGradient):
formatField['background-color']=(colors.RGB.fromCOLORREF(int(cellObj.Interior.Gradient.ColorStops(1).Color)))
formatField['background-color2']=(colors.RGB.fromCOLORREF(int(cellObj.Interior.Gradient.ColorStops(2).Color)))
else:
formatField['background-color']=colors.RGB.fromCOLORREF(int(cellObj.interior.color))
except COMError:
pass
return formatField,(self._startOffset,self._endOffset)
Expand Down
23 changes: 19 additions & 4 deletions source/speech.py
Expand Up @@ -1163,21 +1163,36 @@ def getFormatFieldSpeech(attrs,attrsCache=None,formatConfig=None,unit=None,extra
oldColor=attrsCache.get("color") if attrsCache is not None else None
backgroundColor=attrs.get("background-color")
oldBackgroundColor=attrsCache.get("background-color") if attrsCache is not None else None
if color and backgroundColor and color!=oldColor and backgroundColor!=oldBackgroundColor:
backgroundColor2=attrs.get("background-color2")
oldBackgroundColor2=attrsCache.get("background-color2") if attrsCache is not None else None
bgColorChanged=backgroundColor!=oldBackgroundColor or backgroundColor2!=oldBackgroundColor2
bgColorText=backgroundColor.name if isinstance(backgroundColor,colors.RGB) else unicode(backgroundColor)
if backgroundColor2:
bg2Name=backgroundColor2.name if isinstance(backgroundColor2,colors.RGB) else unicode(backgroundColor2)
# Translators: Reported when there are two background colors.
# This occurs when, for example, a gradient pattern is applied to a spreadsheet cell.
# {color1} will be replaced with the first background color.
# {color2} will be replaced with the second background color.
bgColorText=_("{color1} to {color2}").format(color1=bgColorText,color2=bg2Name)
if color and backgroundColor and color!=oldColor and bgColorChanged:
# Translators: Reported when both the text and background colors change.
# {color} will be replaced with the text color.
# {backgroundColor} will be replaced with the background color.
textList.append(_("{color} on {backgroundColor}").format(
color=color.name if isinstance(color,colors.RGB) else unicode(color),
backgroundColor=backgroundColor.name if isinstance(backgroundColor,colors.RGB) else unicode(backgroundColor)))
backgroundColor=bgColorText))
elif color and color!=oldColor:
# Translators: Reported when the text color changes (but not the background color).
# {color} will be replaced with the text color.
textList.append(_("{color}").format(color=color.name if isinstance(color,colors.RGB) else unicode(color)))
elif backgroundColor and backgroundColor!=oldBackgroundColor:
elif backgroundColor and bgColorChanged:
# Translators: Reported when the background color changes (but not the text color).
# {backgroundColor} will be replaced with the background color.
textList.append(_("{backgroundColor} background").format(backgroundColor=backgroundColor.name if isinstance(backgroundColor,colors.RGB) else unicode(backgroundColor)))
textList.append(_("{backgroundColor} background").format(backgroundColor=bgColorText))
backgroundPattern=attrs.get("background-pattern")
oldBackgroundPattern=attrsCache.get("background-pattern") if attrsCache is not None else None
if backgroundPattern and backgroundPattern!=oldBackgroundPattern:
textList.append(_("background pattern {pattern}").format(pattern=backgroundPattern))
if formatConfig["reportLineNumber"]:
lineNumber=attrs.get("line-number")
oldLineNumber=attrsCache.get("line-number") if attrsCache is not None else None
Expand Down
3 changes: 2 additions & 1 deletion user_docs/en/changes.t2t
Expand Up @@ -8,7 +8,8 @@
== New Features ==
- In browse mode in Internet Explorer and other MSHTML controls, using first letter navigation to move by annotation (a and shift+a) now moves to inserted and deleted text. (#5691)
- In Microsoft Excel, NVDA now reports the level of a group of cells, as well as whether it is collapsed or expanded. (#5690)
- Pressing the Report text formatting command twice presents the information in browse mode so it can be reviewed. (#4908)
- Pressing the Report text formatting command twice presents the information in browse mode so it can be reviewed. (#4908)
- In Microsoft Excel 2010 and later, cell shading and gradient fill is now reported. Automatic reporting is controlled by the Report colors option in NVDA's Document Formatting preferences. (#3683)


== Bug Fixes ==
Expand Down

0 comments on commit 3427d49

Please sign in to comment.