Repository: nvaccess/nvda

Issue:
Excel: Text which isn't too wide, announced as overflowing / cropped when using high DPI
When the DPI is changed in Windows (usually via the "Make text and other items larger or smaller" setting), it makes everything bigger or smaller - text, icons, the size of cells in Excel.  The text "abcdefghi" fits neatly in a default sized cell at the default Calibri 11pt font.  This is the same regardless of the DPI as while a higher DPI makes the text bigger, it also makes the cells in Excel bigger, so the same text still fits.  There is a small discrepancy - I've found that you can fit a "j" on the end in some conditions.

When the DPI is set above 100%, NVDA seems to behave as if the text has got bigger but the size of the cell hasn't (just a guess).  At 200%, I can about half fill a cell before NVDA announces it as overflowing (or cropped if there is text in the next cell).  I tested this on Windows 10 with Excel 2016, and Windows 7 with Excel 2007.

To reproduce:
- Set "Make text and other items larger or smaller" to anything above 100% - the higher the value, the more obvious the effect.
- Sign out / back in.
- Open Excel
- Type text in a cell.  The text "abcdefghi" fits in a cell at the default Calibri 11 under every condition I tried.
- Navigate away from the cell and back (tab then shift+tab).  NVDA reads the text and reports "overflowing".



Discussion:
P3 because its information related to presentation and there could be a reasonable cost to fix.
@Qchristensen Do you think there is cause for this to be higher than P3?

P3 is fine, announcing cropped or overflowing when the text doesn't exceed
the cell width is less of a risk than NOT announcing when text is wider
than the cell.

## 

22 Point

Web: http://www.22point.com.au
Facebook: https://www.facebook.com/22Point
Twitter: https://twitter.com/22PointApps

Check out our first app, RapiTap! - Tap targets fast & avoid decoys:
Adrenaline pumping, Challenging, Accessible!
https://play.google.com/store/apps/details?id=au.com.twentytwopoint.rapitap
Free trial:
https://play.google.com/store/apps/details?id=au.com.twentytwopoint.rapitapfree

On 26 October 2016 at 12:58, Reef Turner notifications@github.com wrote:

> P3 because its information related to presentation and there could be a
> reasonable cost to fix.
> @Qchristensen https://github.com/Qchristensen Do you think there is
> cause for this to be higher than P3?
> 
> —
> You are receiving this because you were mentioned.
> Reply to this email directly, view it on GitHub
> https://github.com/nvaccess/nvda/issues/6472#issuecomment-256229393, or mute
> the thread
> https://github.com/notifications/unsubscribe-auth/APKmCPdKwtEeB8DEEclw6eQRVr4y-ePXks5q3rPcgaJpZM4KYLi_
> .


Resolving patch:
diff --git a/source/NVDAObjects/window/excel.py b/source/NVDAObjects/window/excel.py
--- a/source/NVDAObjects/window/excel.py
+++ b/source/NVDAObjects/window/excel.py
@@ -1168,7 +1168,7 @@ def event_typedCharacter(self,ch):
 			return
 		super(ExcelCell,self).event_typedCharacter(ch)
 
-	def getCellWidthAndTextWidth(self):
+	def getCellTextWidth(self):
 		#handle to Device Context
 		hDC = ctypes.windll.user32.GetDC(self.windowHandle)
 		tempDC = ctypes.windll.gdi32.CreateCompatibleDC(hDC)
@@ -1178,12 +1178,10 @@ def getCellWidthAndTextWidth(self):
 		#handle to the bitmap object
 		hOldBMP = ctypes.windll.gdi32.SelectObject(tempDC, hBMP)
 		#Pass Device Context and LOGPIXELSX, the horizontal resolution in pixels per unit inch
-		deviceCaps = ctypes.windll.gdi32.GetDeviceCaps(tempDC, 88)
+		dpi = ctypes.windll.gdi32.GetDeviceCaps(tempDC, LOGPIXELSX)
 		#Fetching Font Size and Weight information
 		iFontSize = self.excelCellObject.Font.Size
 		iFontSize = 11 if iFontSize is None else int(iFontSize)
-		iFontSize = ctypes.c_int(iFontSize)
-		iFontSize = ctypes.windll.kernel32.MulDiv(iFontSize, deviceCaps, 72)
 		#Font  Weight for Bold FOnt is 700 and for normal font it's 400
 		iFontWeight = 700 if self.excelCellObject.Font.Bold else 400
 		#Fetching Font Name and style information
@@ -1234,14 +1232,13 @@ class structText(ctypes.Structure):
 		#Release & Delete the device context
 		ctypes.windll.gdi32.DeleteDC(tempDC)
 		#Retrieve the text width
-		textWidth = StructText.width+5
-		cellWidth  = self.excelCellObject.ColumnWidth * xlCellWidthUnitToPixels	#Conversion factor to convert the cellwidth to pixels
-		return (cellWidth,textWidth)
+		textWidth = StructText.width
+		return textWidth
 
 	def _get__overlapInfo(self):
-		(cellWidth, textWidth) = self.getCellWidthAndTextWidth()
-		isWrapText = self.excelCellObject.WrapText
-		isShrinkToFit = self.excelCellObject.ShrinkToFit
+		textWidth = self.getCellTextWidth()
+		if self.excelCellObject.WrapText or self.excelCellObject.ShrinkToFit:
+			return None
 		isMerged = self.excelWindowObject.Selection.MergeCells
 		try:
 			adjacentCell = self.excelCellObject.Offset(0,1)
@@ -1253,15 +1250,23 @@ def _get__overlapInfo(self):
 			isAdjacentCellEmpty = not adjacentCell.Text
 		info = {}
 		if isMerged:
-			columnCountInMergeArea = self.excelCellObject.MergeArea.Columns.Count
-			curCol = self.excelCellObject.Column
-			curRow = self.excelCellObject.Row
-			cellWidth = 0
-			for x in xrange(columnCountInMergeArea):
-				cellWidth += self.excelCellObject.Cells(curRow, curCol).ColumnWidth
-				curCol += 1
-			cellWidth = cellWidth * xlCellWidthUnitToPixels #Conversion factor to convert the cellwidth to pixels
-		if isWrapText or isShrinkToFit or textWidth <= cellWidth:
+			columns=self.excelCellObject.mergeArea.columns
+			columnCount=columns.count
+			firstColumn=columns.item(1)
+			lastColumn=columns.item(columnCount)
+			firstColumnLeft=firstColumn.left
+			lastColumnLeft=lastColumn.left
+			lastColumnWidth=lastColumn.width
+			cellLeft=firstColumnLeft
+			cellRight=lastColumnLeft+lastColumnWidth
+		else:
+			cellLeft=self.excelCellObject.left
+			cellRight=cellLeft+self.excelCellObject.width
+		pointsToPixels=self.excelCellObject.Application.ActiveWindow.PointsToScreenPixelsX
+		cellLeft=pointsToPixels(cellLeft)
+		cellRight=pointsToPixels(cellRight)
+		cellWidth=(cellRight-cellLeft)
+		if textWidth <= cellWidth:
 			info = None
 		else:
 			if isAdjacentCellEmpty:


Test patch: