Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 1 addition & 2 deletions source/NVDAObjects/window/scintilla.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
from . import Window
from .. import NVDAObjectTextInfo
from ..behaviors import EditableTextWithAutoSelectDetection
import locale
import watchdog
import eventHandler
import locationHelper
Expand Down Expand Up @@ -82,7 +81,7 @@ def _get_encoding(self):
if cp==SC_CP_UTF8:
return "utf-8"
else:
return locale.getlocale()[1]
return textUtils.USERANSICODEPAGE

def _getOffsetFromPoint(self,x,y):
x, y = winUser.ScreenToClient(self.obj.windowHandle, x, y)
Expand Down
4 changes: 2 additions & 2 deletions source/appModules/winamp.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
from NVDAObjects.IAccessible import IAccessible
import appModuleHandler
import speech
import locale
import controlTypes
import api
import watchdog
import braille
import ui
import textUtils

# message used to sent many messages to winamp's main window.
# most all of the IPC_* messages involve sending the message in the form of:
Expand Down Expand Up @@ -116,7 +116,7 @@ def _get_name(self):
winKernel.virtualFreeEx(self.processHandle,internalInfo,0,winKernel.MEM_RELEASE)
# file title is fetched in the current locale encoding.
# We need to decode it to unicode first.
encoding=locale.getlocale()[1]
encoding = textUtils.USERANSICODEPAGE
fileTitle=info.filetitle.decode(encoding,errors="replace")
return "%d.\t%s\t%s"%(curIndex+1,fileTitle,info.filelength)

Expand Down
9 changes: 4 additions & 5 deletions source/textInfos/offsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import textUtils
from dataclasses import dataclass
from typing import Optional, Tuple
import locale
from logHandler import log

@dataclass
Expand Down Expand Up @@ -282,7 +281,7 @@ def _getTextRange(self,start,end):
if self.encoding == textUtils.WCHAR_ENCODING:
offsetConverter = textUtils.WideStringOffsetConverter(text)
start, end = offsetConverter.wideToStrOffsets(start, end)
elif self.encoding not in (None, "utf_32_le", locale.getlocale()[1]):
elif self.encoding not in (None, "utf_32_le", textUtils.USERANSICODEPAGE):
raise NotImplementedError
return text[start:end]

Expand Down Expand Up @@ -346,7 +345,7 @@ def _calculateUniscribeOffsets(self, lineText: str, unit: str, relOffset: int) -
return None

def _getCharacterOffsets(self, offset):
if self.encoding not in (textUtils.WCHAR_ENCODING, None, "utf_32_le", locale.getlocale()[1]):
if self.encoding not in (textUtils.WCHAR_ENCODING, None, "utf_32_le", textUtils.USERANSICODEPAGE):
raise NotImplementedError
lineStart, lineEnd = self._getLineOffsets(offset)
lineText = self._getTextRange(lineStart, lineEnd)
Expand All @@ -363,7 +362,7 @@ def _getCharacterOffsets(self, offset):
return (offset, offset + 1)

def _getWordOffsets(self,offset):
if self.encoding not in (textUtils.WCHAR_ENCODING, None, "utf_32_le", locale.getlocale()[1]):
if self.encoding not in (textUtils.WCHAR_ENCODING, None, "utf_32_le", textUtils.USERANSICODEPAGE):
Comment thread
lukaszgo1 marked this conversation as resolved.
Outdated
raise NotImplementedError
lineStart, lineEnd = self._getLineOffsets(offset)
lineText = self._getTextRange(lineStart,lineEnd)
Expand Down Expand Up @@ -397,7 +396,7 @@ def _getLineOffsets(self,offset):
strStart=findStartOfLine(text, strOffset)
strEnd=findEndOfLine(text, strOffset)
return offsetConverter.strToWideOffsets(strStart, strEnd)
elif self.encoding not in (None, "utf_32_le", locale.getlocale()[1]):
elif self.encoding not in (None, "utf_32_le", textUtils.USERANSICODEPAGE):
raise NotImplementedError
start=findStartOfLine(text,offset)
end=findEndOfLine(text,offset)
Expand Down
13 changes: 7 additions & 6 deletions source/textUtils.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
# -*- coding: UTF-8 -*-
Comment thread
lukaszgo1 marked this conversation as resolved.
Outdated
#textUtils.py
#A part of NonVisual Desktop Access (NVDA)
#This file is covered by the GNU General Public License.
#See the file COPYING for more details.
#Copyright (C) 2018-2019 NV Access Limited, Babbage B.V.
# A part of NonVisual Desktop Access (NVDA)
# This file is covered by the GNU General Public License.
# See the file COPYING for more details.
# Copyright (C) 2018-2020 NV Access Limited, Babbage B.V., Łukasz Golonka

"""
Classes and utilities to deal with offsets variable width encodings, particularly utf_16.
Expand All @@ -18,6 +17,8 @@
from logHandler import log

WCHAR_ENCODING = "utf_16_le"
USERANSICODEPAGE = locale.getpreferredencoding()

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.

Please follow the style used for constants here:

Suggested change
USERANSICODEPAGE = locale.getpreferredencoding()
USER_ANSI_CODE_PAGE = locale.getpreferredencoding()

Or rather

Suggested change
USERANSICODEPAGE = locale.getpreferredencoding()
SYSTEM_PREFERRED_ENCODING = locale.getpreferredencoding()

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've renamed it to USER_ANSI_CODE_PAGE because it can be set per Windows user account and is not global to the system.



class WideStringOffsetConverter:
R"""
Expand Down Expand Up @@ -201,7 +202,7 @@ def getTextFromRawBytes(
if numChars > 1 and any(buf[numChars:]):
encoding = WCHAR_ENCODING
else:
encoding = locale.getlocale()[1]
encoding = USERANSICODEPAGE
else:
encoding = encodings.normalize_encoding(encoding).lower()
if encoding.startswith("utf_16"):
Expand Down