From c02eee4d3f135fc59d8230c473b29caba0a2ef5d Mon Sep 17 00:00:00 2001 From: Joseph Lee Date: Sun, 7 Jul 2019 14:35:19 -0700 Subject: [PATCH 1/3] NVDAObjects/window/Scintilla: copyright header --- source/NVDAObjects/window/scintilla.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/source/NVDAObjects/window/scintilla.py b/source/NVDAObjects/window/scintilla.py index 7a9998767e1..51f19c9dd8c 100755 --- 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 From ed86d6e020593f7d1dbf5df5421f5096eb802d08 Mon Sep 17 00:00:00 2001 From: Joseph Lee Date: Sun, 7 Jul 2019 14:37:14 -0700 Subject: [PATCH 2/3] Scintilla: convert font name to Unicode via text utils module. Re #9892. When a user attempts to obtain font info and other formatting attributes from Scintilla controls such as Notepad++, type error is thrown becasue font name is returned as bytes. Thus use text utils module to convert this into Unicode. --- source/NVDAObjects/window/scintilla.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/NVDAObjects/window/scintilla.py b/source/NVDAObjects/window/scintilla.py index 51f19c9dd8c..f868bad7a76 100755 --- a/source/NVDAObjects/window/scintilla.py +++ b/source/NVDAObjects/window/scintilla.py @@ -119,14 +119,15 @@ def _getFormatFieldAndOffsets(self,offset,formatConfig,calculateOffsets=True): formatField=textInfos.FormatField() if formatConfig["reportFontName"]: #To get font name, We need to allocate memory with in Scintilla's process, and then copy it out - fontNameBuf=ctypes.create_string_buffer(32) + fontNameLength=32 + fontNameBuf=ctypes.create_string_buffer(fontNameLength) internalBuf=winKernel.virtualAllocEx(self.obj.processHandle,None,len(fontNameBuf),winKernel.MEM_COMMIT,winKernel.PAGE_READWRITE) try: watchdog.cancellableSendMessage(self.obj.windowHandle,SCI_STYLEGETFONT,style, internalBuf) 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"]=textUtils.getTextFromRawBytes(fontNameBuf.raw,numChars=fontNameLength) if formatConfig["reportFontSize"]: formatField["font-size"]="%spt"%watchdog.cancellableSendMessage(self.obj.windowHandle,SCI_STYLEGETSIZE,style,0) if formatConfig["reportLineNumber"]: From 5574b7abf6a61e6e97436fb0128c53e3a53745fc Mon Sep 17 00:00:00 2001 From: Joseph Lee Date: Sun, 7 Jul 2019 21:32:41 -0700 Subject: [PATCH 3/3] Scintilla: just decode font name directly. Re #9892. Reviewed by Leonard de Ruijter (Babbage): if using text utils, make sure to pass in encoding keyword (utf_8). One workaround for using text utils is passing in buffer.value, but that is an overkill. Thus resort to using a simple buffer.value.decode call. --- source/NVDAObjects/window/scintilla.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/source/NVDAObjects/window/scintilla.py b/source/NVDAObjects/window/scintilla.py index f868bad7a76..efd56d02db4 100755 --- a/source/NVDAObjects/window/scintilla.py +++ b/source/NVDAObjects/window/scintilla.py @@ -119,15 +119,14 @@ def _getFormatFieldAndOffsets(self,offset,formatConfig,calculateOffsets=True): formatField=textInfos.FormatField() if formatConfig["reportFontName"]: #To get font name, We need to allocate memory with in Scintilla's process, and then copy it out - fontNameLength=32 - fontNameBuf=ctypes.create_string_buffer(fontNameLength) + fontNameBuf=ctypes.create_string_buffer(32) internalBuf=winKernel.virtualAllocEx(self.obj.processHandle,None,len(fontNameBuf),winKernel.MEM_COMMIT,winKernel.PAGE_READWRITE) try: watchdog.cancellableSendMessage(self.obj.windowHandle,SCI_STYLEGETFONT,style, internalBuf) winKernel.readProcessMemory(self.obj.processHandle,internalBuf,fontNameBuf,len(fontNameBuf),None) finally: winKernel.virtualFreeEx(self.obj.processHandle,internalBuf,0,winKernel.MEM_RELEASE) - formatField["font-name"]=textUtils.getTextFromRawBytes(fontNameBuf.raw,numChars=fontNameLength) + 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"]: