Repository: nvaccess/nvda

Issue:
Python 3 staging/Notepad++: obtainig font name fails because it is a bytes-like object
#9557 # Steps to reproduce:
1. Install Python 3 staging snapshot.
2. Run Notepad++ or any app that embeds Scintilla controls.
3. Try obtaining formatting info (NVDA+F).

### Actual behavior:
The following traceback is recorded:

```
ERROR - scriptHandler.executeScript (11:07:35.251):
error executing script: <bound method GlobalCommands.script_reportFormatting of <globalCommands.GlobalCommands object at 0x06B54FD0>> with gesture 'NVDA+f'
Traceback (most recent call last):
  File "scriptHandler.pyc", line 189, in executeScript
  File "globalCommands.pyc", line 1393, in script_reportFormatting
  File "globalCommands.pyc", line 1366, in _reportFormattingHelper
  File "textInfos\__init__.pyc", line 500, in getFormatFieldSpeech
  File "speech\__init__.pyc", line 1717, in getFormatFieldSpeech
TypeError: sequence item 0: expected str instance, bytes found
```
### Expected behavior:
No errors.

### System configuration
#### NVDA installed/portable/running from source:
Installed and portable

#### NVDA version:
Python 3 staging 17954

#### Windows version:
Windows 10 Version 1903

#### Name and version of other software in use when reproducing the issue:
notepad++ 7.6.6

#### Other information about your system:
None

### Other questions
#### Does the issue still occur after restarting your PC?
Yes

#### Have you tried any other versions of NVDA? If so, please report their behaviors.
Yes - master snapshot, 2019.1.1.



Discussion:
Hi,

I do have a fix for this (involves encoding font name string in UTF-8), but plan to publish a PR for it once master branch is powered by Python 3 as it is not a high priority bug.

Thanks.
Hi,

Actually, the solution is to call textUtils.getTextFromRawBytes. I bet there are other cases where this is needed.

Also, I'll come up with a PR for this one in just a moment (not a high priority one, but still it may open our eyes to usefulness of Leonard's work).

Thanks.

Resolving patch:
diff --git a/source/NVDAObjects/window/scintilla.py b/source/NVDAObjects/window/scintilla.py
--- a/source/NVDAObjects/window/scintilla.py
+++ b/source/NVDAObjects/window/scintilla.py
@@ -1,3 +1,8 @@
+#A part of NonVisual Desktop Access (NVDA)
+#Copyright (C) 2009-2019 NV Access Limited, Arnold Loubriat, Babbage B.V.
+#This file is covered by the GNU General Public License.
+#See the file COPYING for more details.
+
 import ctypes
 import IAccessibleHandler
 import speech
@@ -121,7 +126,7 @@ def _getFormatFieldAndOffsets(self,offset,formatConfig,calculateOffsets=True):
 				winKernel.readProcessMemory(self.obj.processHandle,internalBuf,fontNameBuf,len(fontNameBuf),None)
 			finally:
 				winKernel.virtualFreeEx(self.obj.processHandle,internalBuf,0,winKernel.MEM_RELEASE)
-			formatField["font-name"]=fontNameBuf.value
+			formatField["font-name"]=fontNameBuf.value.decode("utf-8")
 		if formatConfig["reportFontSize"]:
 			formatField["font-size"]="%spt"%watchdog.cancellableSendMessage(self.obj.windowHandle,SCI_STYLEGETSIZE,style,0)
 		if formatConfig["reportLineNumber"]:


Test patch: