Skip to content
Merged
Changes from 2 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
10 changes: 8 additions & 2 deletions source/NVDAObjects/window/scintilla.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -114,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)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the docs:

Under Windows, only the first 32 characters of the name are used, the name is decoded as UTF-8, ...

Suggested change
formatField["font-name"]=textUtils.getTextFromRawBytes(fontNameBuf.raw,numChars=fontNameLength)
formatField["font-name"]=textUtils.getTextFromRawBytes(fontNameBuf.raw,numChars=fontNameLength, encoding="utf_8")

if formatConfig["reportFontSize"]:
formatField["font-size"]="%spt"%watchdog.cancellableSendMessage(self.obj.windowHandle,SCI_STYLEGETSIZE,style,0)
if formatConfig["reportLineNumber"]:
Expand Down