Skip to content
Merged
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
17 changes: 17 additions & 0 deletions source/NVDAObjects/window/excel.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@
xlPatternRectangularGradient:_("rectangular gradient"),
}

from excelCellBorder import getCellBorderStyleDescription

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 @@ -985,6 +987,21 @@ def _getFormatFieldAndOffsets(self,offset,formatConfig,calculateOffsets=True):
formatField['background-color']=colors.RGB.fromCOLORREF(int(cellObj.interior.color))
except COMError:
pass
if formatConfig["reportBorderStyle"]:
borders = None
hasMergedCells = self.obj.excelCellObject.mergeCells
if hasMergedCells:
mergeArea = self.obj.excelCellObject.mergeArea
try:
borders = mergeArea.DisplayFormat.borders # for later versions of office
except COMError:
borders = mergeArea.borders # for office 2007
else:
borders = cellObj.borders
try:
formatField['border-style']=getCellBorderStyleDescription(borders,reportBorderColor=formatConfig['reportBorderColor'])
except COMError:
pass
return formatField,(self._startOffset,self._endOffset)

def _get_locationText(self):
Expand Down
159 changes: 159 additions & 0 deletions source/NVDAObjects/window/excelCellBorder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
#NVDAObjects/window/excelCellBorder.py
#A part of NonVisual Desktop Access (NVDA)
#Copyright (C) 2016 Takuya Nishimoto
#This file is covered by the GNU General Public License.
#See the file COPYING for more details.

from collections import OrderedDict
import colors
# XlBordersIndex Enumeration
# see https://msdn.microsoft.com/en-us/library/office/ff835915.aspx
xlDiagonalDown = 5
xlDiagonalUp = 6
xlEdgeBottom = 9
xlEdgeLeft = 7
xlEdgeRight = 10
xlEdgeTop = 8
xlInsideHorizontal = 12
xlInsideVertical = 11
bordersIndexLabels=OrderedDict((
# Translators: border positions in Microsoft Excel.
(xlEdgeTop, _("top edge")),
# Translators: border positions in Microsoft Excel.
(xlEdgeBottom, _("bottom edge")),
# Translators: border positions in Microsoft Excel.
(xlEdgeLeft, _("left edge")),
# Translators: border positions in Microsoft Excel.
(xlEdgeRight, _("right edge")),
# Translators: border positions in Microsoft Excel.
(xlDiagonalUp, _("up-right diagonal line")),
# Translators: border positions in Microsoft Excel.
(xlDiagonalDown, _("down-right diagonal line")),
# Translators: border positions in Microsoft Excel.
(xlInsideHorizontal, _("horizontal borders except outside")),
# Translators: border positions in Microsoft Excel.
(xlInsideVertical, _("vertical borders except outside")),
))
# XlLineStyle Enumeration
# see https://msdn.microsoft.com/en-us/library/office/ff821622.aspx
xlContinuous = 1
xlDash = -4115
xlDashDot = 4
xlDashDotDot = 5
xlDot = -4118
xlDouble = -4119
xlLineStyleNone = -4142
xlSlantDashDot = 13
borderStyleLabels={
# Translators: border styles in Microsoft Excel.
xlContinuous:_("continuous"),
# Translators: border styles in Microsoft Excel.
xlDash:_("dashed"),
# Translators: border styles in Microsoft Excel.
xlDashDot:_("dash dot"),
# Translators: border styles in Microsoft Excel.
xlDashDotDot:_("dash dot dot"),
# Translators: border styles in Microsoft Excel.
xlDot:_("dotted"),
# Translators: border styles in Microsoft Excel.
xlDouble:_("double"),
# Translators: border styles in Microsoft Excel.
xlSlantDashDot:_("slanted dash dot"),
}
# XlBorderWeight Enumeration
# see https://msdn.microsoft.com/en-us/library/office/ff197515.aspx
xlHairline = 1 # thinnest border
xlThin = 2
xlMedium = -4138
xlThick = 4 # widest border
borderWeightLabels={
# Translators: border styles in Microsoft Excel.
xlHairline:_("hair"),
# Translators: border styles in Microsoft Excel.
xlThin:_("thin"),
# Translators: border styles in Microsoft Excel.
xlMedium:_("medium"),
# Translators: border styles in Microsoft Excel.
xlThick:_("thick"),
}
borderStyleAndWeightLabels={
# Translators: border styles in Microsoft Excel.
(xlContinuous, xlHairline):_("hair"),
# Translators: border styles in Microsoft Excel.
(xlDot, xlThin):_("dotted"),
# Translators: border styles in Microsoft Excel.
(xlDashDotDot, xlThin):_("dash dot dot"),
# Translators: border styles in Microsoft Excel.
(xlDashDot, xlThin):_("dash dot"),
# Translators: border styles in Microsoft Excel.
(xlDash, xlThin):_("dashed"),
# Translators: border styles in Microsoft Excel.
(xlContinuous, xlThin):_("thin"),
# Translators: border styles in Microsoft Excel.
(xlDashDotDot, xlMedium):_("medium dash dot dot"),
# Translators: border styles in Microsoft Excel.
(xlSlantDashDot, xlMedium):_("slanted dash dot"),
# Translators: border styles in Microsoft Excel.
(xlDashDot, xlMedium):_("medium dash dot"),
# Translators: border styles in Microsoft Excel.
(xlDash, xlMedium):_("medium dashed"),
# Translators: border styles in Microsoft Excel.
(xlContinuous, xlMedium):_("medium"),
# Translators: border styles in Microsoft Excel.
(xlContinuous, xlThick):_("thick"),
# Translators: border styles in Microsoft Excel.
(xlDouble, xlThick):_("double"),
}

def getCellBorderStyleDescription(bordersObj,reportBorderColor=False):
d=OrderedDict()
for pos in bordersIndexLabels.keys():
border=bordersObj[pos]
if border.lineStyle != xlLineStyleNone:
style=border.lineStyle
weight=border.weight
desc=borderStyleAndWeightLabels.get((style,weight))
if not desc:
# Translators: border styles in Microsoft Excel.
desc=_("{weight} {style}").format(
style=borderStyleLabels.get(style),
weight=borderWeightLabels.get(weight)
)
if reportBorderColor:
# Translators: border styles in Microsoft Excel.
d[pos]=_("{color} {desc}").format(
color=colors.RGB.fromCOLORREF(int(border.color)).name,
desc=desc
)
else:
d[pos]=desc
s=[]
if d.get(xlEdgeTop) == d.get(xlEdgeBottom) == d.get(xlEdgeLeft) == d.get(xlEdgeRight) and d.get(xlEdgeTop) is not None:
# Translators: border styles in Microsoft Excel.
s.append(_("{desc} surrounding border").format(desc=d.get(xlEdgeTop)))
del d[xlEdgeTop]
del d[xlEdgeBottom]
del d[xlEdgeLeft]
del d[xlEdgeRight]
if d.get(xlEdgeTop) == d.get(xlEdgeBottom) and d.get(xlEdgeTop) is not None:
# Translators: border styles in Microsoft Excel.
s.append(_("{desc} top and bottom edges").format(desc=d.get(xlEdgeTop)))
del d[xlEdgeTop]
del d[xlEdgeBottom]
if d.get(xlEdgeLeft) == d.get(xlEdgeRight) and d.get(xlEdgeLeft) is not None:
# Translators: border styles in Microsoft Excel.
s.append(_("{desc} left and right edges").format(desc=d.get(xlEdgeLeft)))
del d[xlEdgeLeft]
del d[xlEdgeRight]
if d.get(xlDiagonalUp) == d.get(xlDiagonalDown) and d.get(xlDiagonalUp) is not None:
# Translators: border styles in Microsoft Excel.
s.append(_("{desc} up-right and down-right diagonal lines").format(desc=d.get(xlDiagonalUp)))
del d[xlDiagonalUp]
del d[xlDiagonalDown]
for pos,desc in d.items():
# Translators: border styles in Microsoft Excel.
s.append(_("{desc} {position}").format(
desc=desc,
position=bordersIndexLabels.get(pos)
))
return ', '.join(s)
2 changes: 2 additions & 0 deletions source/config/configSpec.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@
includeLayoutTables = boolean(default=False)
reportTableHeaders = boolean(default=True)
reportTableCellCoords = boolean(default=True)
reportBorderStyle = boolean(default=True)
reportBorderColor = boolean(default=True)
reportLinks = boolean(default=true)
reportComments = boolean(default=true)
reportLists = boolean(default=true)
Expand Down
1 change: 1 addition & 0 deletions source/globalCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -1271,6 +1271,7 @@ def script_reportFormatting(self,gesture):
"reportPage":False,"reportLineNumber":False,"reportLineIndentation":True,"reportLineIndentationWithTones":False,"reportParagraphIndentation":True,"reportLineSpacing":True,"reportTables":False,
"reportLinks":False,"reportHeadings":False,"reportLists":False,
"reportBlockQuotes":False,"reportComments":False,
"reportBorderStyle":True,"reportBorderColor":True,
}
textList=[]
info=api.getReviewPosition()
Expand Down
27 changes: 26 additions & 1 deletion source/gui/settingsDialogs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,28 @@ def makeSettings(self, settingsSizer):
self.tableCellCoordsCheckBox=tablesGroup.addItem(wx.CheckBox(scrolledPanel,label=_("Cell c&oordinates")))
self.tableCellCoordsCheckBox.SetValue(config.conf["documentFormatting"]["reportTableCellCoords"])

borderChoices=[
# Translators: This is the label for a combobox in the
# document formatting settings dialog.
_("Off"),
# Translators: This is the label for a combobox in the
# document formatting settings dialog.
_("Styles"),
# Translators: This is the label for a combobox in the
# document formatting settings dialog.
_("Both Colors and Styles"),
]
# Translators: This is the label for a combobox in the
# document formatting settings dialog.
self.borderComboBox=tablesGroup.addLabeledControl(_("Cell borders:"), wx.Choice, choices=borderChoices)
curChoice = 0
if config.conf["documentFormatting"]["reportBorderStyle"]:
if config.conf["documentFormatting"]["reportBorderColor"]:
curChoice = 2
else:
curChoice = 1
self.borderComboBox.SetSelection(curChoice)

# Translators: This is the label for a group of document formatting options in the
# document formatting settings dialog
elementsGroupText = _("Elements")
Expand Down Expand Up @@ -1272,7 +1294,10 @@ def onOk(self,evt):
config.conf["documentFormatting"]["reportLineSpacing"]=self.lineSpacingCheckBox.IsChecked()
config.conf["documentFormatting"]["reportTables"]=self.tablesCheckBox.IsChecked()
config.conf["documentFormatting"]["reportTableHeaders"]=self.tableHeadersCheckBox.IsChecked()
config.conf["documentFormatting"]["reportTableCellCoords"]=self.tableCellCoordsCheckBox.IsChecked()
config.conf["documentFormatting"]["reportTableCellCoords"]=self.tableCellCoordsCheckBox.IsChecked()
choice = self.borderComboBox.GetSelection()
config.conf["documentFormatting"]["reportBorderStyle"] = choice in (1,2)
config.conf["documentFormatting"]["reportBorderColor"] = (choice == 2)
config.conf["documentFormatting"]["reportLinks"]=self.linksCheckBox.IsChecked()
config.conf["documentFormatting"]["reportHeadings"]=self.headingsCheckBox.IsChecked()
config.conf["documentFormatting"]["reportLists"]=self.listsCheckBox.IsChecked()
Expand Down
10 changes: 10 additions & 0 deletions source/speech.py
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,16 @@ def getFormatFieldSpeech(attrs,attrsCache=None,formatConfig=None,reason=None,uni
# A style is a collection of formatting settings and depends on the application.
text=_("default style")
textList.append(text)
if formatConfig["reportBorderStyle"]:
borderStyle=attrs.get("border-style")
oldBorderStyle=attrsCache.get("border-style") if attrsCache is not None else None
if borderStyle!=oldBorderStyle:
if borderStyle:
text=borderStyle
else:
# Translators: Indicates that cell does not have border lines.
text=_("no border lines")
textList.append(text)
if formatConfig["reportFontName"]:
fontFamily=attrs.get("font-family")
oldFontFamily=attrsCache.get("font-family") if attrsCache is not None else None
Expand Down
1 change: 1 addition & 0 deletions user_docs/en/userGuide.t2t
Original file line number Diff line number Diff line change
Expand Up @@ -1263,6 +1263,7 @@ You can configure reporting of:
- Tables
- Row/column headers
- Cell coordinates
- Cell borders [(Off, Styles, Both Colors and Styles)
- Elements
- Headings
- Links
Expand Down