Skip to content

Commit

Permalink
Release 3.0.2
Browse files Browse the repository at this point in the history
    适配NVDA 2024.1版本。
  • Loading branch information
huaiyinfeilong committed Apr 2, 2024
1 parent 1de3e94 commit ec8ae69
Show file tree
Hide file tree
Showing 118 changed files with 2,380 additions and 2,006 deletions.
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
],
"python.defaultInterpreterPath": "../nvda/.venv/scripts/python.exe",
"[python]": {
"editor.defaultFormatter": "ms-python.autopep8"
"editor.defaultFormatter": "ms-python.python"
},
"python.formatting.provider": "none"
}
6 changes: 5 additions & 1 deletion addon/doc/zh_CN/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@

有任何意见建议欢迎沟通:

* 项目地址:https://github.com/huaiyinfeilong/xyocr
* 项目地址:[https://github.com/huaiyinfeilong/xyocr](https://github.com/huaiyinfeilong/xyocr)
* 电子邮箱:huaiyinfeilong@163.com
* QQ:354522977
* 微信:huaiyinfeilong

## 升级日志

### Version 3.0.2

* 适配NVDA 2024.1版本。

### Version 3.0.1

* 新增图片描述黑屏检测:如果在黑屏功能开启状态下进行图片描述操作,将给出提示。
Expand Down
25 changes: 18 additions & 7 deletions addon/globalPlugins/_py3_contrib/PIL/BdfFontFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@
"""
Parse X Bitmap Distribution Format (BDF)
"""
from __future__ import annotations

from typing import BinaryIO

from . import FontFile, Image

Expand All @@ -36,7 +38,17 @@
bdf_spacing = {"P": "Proportional", "M": "Monospaced", "C": "Cell"}


def bdf_char(f):
def bdf_char(
f: BinaryIO,
) -> (
tuple[
str,
int,
tuple[tuple[int, int], tuple[int, int, int, int], tuple[int, int, int, int]],
Image.Image,
]
| None
):
# skip to STARTCHAR
while True:
s = f.readline()
Expand All @@ -56,23 +68,22 @@ def bdf_char(f):
props[s[:i].decode("ascii")] = s[i + 1 : -1].decode("ascii")

# load bitmap
bitmap = []
bitmap = bytearray()
while True:
s = f.readline()
if not s or s[:7] == b"ENDCHAR":
break
bitmap.append(s[:-1])
bitmap = b"".join(bitmap)
bitmap += s[:-1]

# The word BBX
# followed by the width in x (BBw), height in y (BBh),
# and x and y displacement (BBxoff0, BByoff0)
# of the lower left corner from the origin of the character.
width, height, x_disp, y_disp = [int(p) for p in props["BBX"].split()]
width, height, x_disp, y_disp = (int(p) for p in props["BBX"].split())

# The word DWIDTH
# followed by the width in x and y of the character in device pixels.
dwx, dwy = [int(p) for p in props["DWIDTH"].split()]
dwx, dwy = (int(p) for p in props["DWIDTH"].split())

bbox = (
(dwx, dwy),
Expand All @@ -92,7 +103,7 @@ def bdf_char(f):
class BdfFontFile(FontFile.FontFile):
"""Font file plugin for the X11 BDF format."""

def __init__(self, fp):
def __init__(self, fp: BinaryIO):
super().__init__()

s = fp.readline()
Expand Down
25 changes: 6 additions & 19 deletions addon/globalPlugins/_py3_contrib/PIL/BlpImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@
- DXT3 compression is used if alpha_encoding == 1.
- DXT5 compression is used if alpha_encoding == 7.
"""
from __future__ import annotations

import os
import struct
from enum import IntEnum
from io import BytesIO

from . import Image, ImageFile
from ._deprecate import deprecate


class Format(IntEnum):
Expand All @@ -54,21 +54,6 @@ class AlphaEncoding(IntEnum):
DXT5 = 7


def __getattr__(name):
for enum, prefix in {
Format: "BLP_FORMAT_",
Encoding: "BLP_ENCODING_",
AlphaEncoding: "BLP_ALPHA_ENCODING_",
}.items():
if name.startswith(prefix):
name = name[len(prefix) :]
if name in enum.__members__:
deprecate(f"{prefix}{name}", 10, f"{enum.__name__}.{name}")
return enum[name]
msg = f"module '{__name__}' has no attribute '{name}'"
raise AttributeError(msg)


def unpack_565(i):
return ((i >> 11) & 0x1F) << 3, ((i >> 5) & 0x3F) << 2, (i & 0x1F) << 3

Expand Down Expand Up @@ -282,7 +267,7 @@ def _open(self):
msg = f"Bad BLP magic {repr(self.magic)}"
raise BLPFormatError(msg)

self.mode = "RGBA" if self._blp_alpha_depth else "RGB"
self._mode = "RGBA" if self._blp_alpha_depth else "RGB"
self.tile = [(decoder, (0, 0) + self.size, 0, (self.mode, 0, 1))]


Expand Down Expand Up @@ -435,9 +420,11 @@ class BLPEncoder(ImageFile.PyEncoder):
def _write_palette(self):
data = b""
palette = self.im.getpalette("RGBA", "RGBA")
for i in range(256):
for i in range(len(palette) // 4):
r, g, b, a = palette[i * 4 : (i + 1) * 4]
data += struct.pack("<4B", b, g, r, a)
while len(data) < 256 * 4:
data += b"\x00" * 4
return data

def encode(self, bufsize):
Expand All @@ -458,7 +445,7 @@ def encode(self, bufsize):
return len(data), 0, data


def _save(im, fp, filename, save_all=False):
def _save(im, fp, filename):
if im.mode != "P":
msg = "Unsupported BLP image mode"
raise ValueError(msg)
Expand Down
24 changes: 12 additions & 12 deletions addon/globalPlugins/_py3_contrib/PIL/BmpImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
#
# See the README file for information on usage and redistribution.
#

from __future__ import annotations

import os

Expand Down Expand Up @@ -163,7 +163,7 @@ def _bitmap(self, header=0, offset=0):
offset += 4 * file_info["colors"]

# ---------------------- Check bit depth for unusual unsupported values
self.mode, raw_mode = BIT2MODE.get(file_info["bits"], (None, None))
self._mode, raw_mode = BIT2MODE.get(file_info["bits"], (None, None))
if self.mode is None:
msg = f"Unsupported BMP pixel depth ({file_info['bits']})"
raise OSError(msg)
Expand Down Expand Up @@ -200,7 +200,7 @@ def _bitmap(self, header=0, offset=0):
and file_info["rgba_mask"] in SUPPORTED[file_info["bits"]]
):
raw_mode = MASK_MODES[(file_info["bits"], file_info["rgba_mask"])]
self.mode = "RGBA" if "A" in raw_mode else self.mode
self._mode = "RGBA" if "A" in raw_mode else self.mode
elif (
file_info["bits"] in (24, 16)
and file_info["rgb_mask"] in SUPPORTED[file_info["bits"]]
Expand All @@ -214,7 +214,7 @@ def _bitmap(self, header=0, offset=0):
raise OSError(msg)
elif file_info["compression"] == self.RAW:
if file_info["bits"] == 32 and header == 22: # 32-bit .cur offset
raw_mode, self.mode = "BGRA", "RGBA"
raw_mode, self._mode = "BGRA", "RGBA"
elif file_info["compression"] in (self.RLE8, self.RLE4):
decoder_name = "bmp_rle"
else:
Expand All @@ -230,25 +230,25 @@ def _bitmap(self, header=0, offset=0):
else:
padding = file_info["palette_padding"]
palette = read(padding * file_info["colors"])
greyscale = True
grayscale = True
indices = (
(0, 255)
if file_info["colors"] == 2
else list(range(file_info["colors"]))
)

# ----------------- Check if greyscale and ignore palette if so
# ----------------- Check if grayscale and ignore palette if so
for ind, val in enumerate(indices):
rgb = palette[ind * padding : ind * padding + 3]
if rgb != o8(val) * 3:
greyscale = False
grayscale = False

# ------- If all colors are grey, white or black, ditch palette
if greyscale:
self.mode = "1" if file_info["colors"] == 2 else "L"
# ------- If all colors are gray, white or black, ditch palette
if grayscale:
self._mode = "1" if file_info["colors"] == 2 else "L"
raw_mode = self.mode
else:
self.mode = "P"
self._mode = "P"
self.palette = ImagePalette.raw(
"BGRX" if padding == 4 else "BGR", palette
)
Expand Down Expand Up @@ -396,7 +396,7 @@ def _save(im, fp, filename, bitmap_header=True):
dpi = info.get("dpi", (96, 96))

# 1 meter == 39.3701 inches
ppm = tuple(map(lambda x: int(x * 39.3701 + 0.5), dpi))
ppm = tuple(int(x * 39.3701 + 0.5) for x in dpi)

stride = ((im.size[0] * bits + 7) // 8 + 3) & (~3)
header = 40 # or 64 for OS/2 version 2
Expand Down
3 changes: 2 additions & 1 deletion addon/globalPlugins/_py3_contrib/PIL/BufrStubImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#
# See the README file for information on usage and redistribution.
#
from __future__ import annotations

from . import Image, ImageFile

Expand Down Expand Up @@ -46,7 +47,7 @@ def _open(self):
self.fp.seek(offset)

# make something up
self.mode = "F"
self._mode = "F"
self._size = 1, 1

loader = self._load()
Expand Down
25 changes: 13 additions & 12 deletions addon/globalPlugins/_py3_contrib/PIL/ContainerIO.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,27 @@
#
# See the README file for information on usage and redistribution.
#

from __future__ import annotations

import io
from typing import IO, AnyStr, Generic, Literal


class ContainerIO:
class ContainerIO(Generic[AnyStr]):
"""
A file object that provides read access to a part of an existing
file (for example a TAR file).
"""

def __init__(self, file, offset, length):
def __init__(self, file: IO[AnyStr], offset: int, length: int) -> None:
"""
Create file object.
:param file: Existing file.
:param offset: Start of region, in bytes.
:param length: Size of region, in bytes.
"""
self.fh = file
self.fh: IO[AnyStr] = file
self.pos = 0
self.offset = offset
self.length = length
Expand All @@ -41,10 +42,10 @@ def __init__(self, file, offset, length):
##
# Always false.

def isatty(self):
def isatty(self) -> bool:
return False

def seek(self, offset, mode=io.SEEK_SET):
def seek(self, offset: int, mode: Literal[0, 1, 2] = io.SEEK_SET) -> None:
"""
Move file pointer.
Expand All @@ -63,15 +64,15 @@ def seek(self, offset, mode=io.SEEK_SET):
self.pos = max(0, min(self.pos, self.length))
self.fh.seek(self.offset + self.pos)

def tell(self):
def tell(self) -> int:
"""
Get current file pointer.
:returns: Offset from start of region, in bytes.
"""
return self.pos

def read(self, n=0):
def read(self, n: int = 0) -> AnyStr:
"""
Read data.
Expand All @@ -84,17 +85,17 @@ def read(self, n=0):
else:
n = self.length - self.pos
if not n: # EOF
return b"" if "b" in self.fh.mode else ""
return b"" if "b" in self.fh.mode else "" # type: ignore[return-value]
self.pos = self.pos + n
return self.fh.read(n)

def readline(self):
def readline(self) -> AnyStr:
"""
Read a line of text.
:returns: An 8-bit string.
"""
s = b"" if "b" in self.fh.mode else ""
s: AnyStr = b"" if "b" in self.fh.mode else "" # type: ignore[assignment]
newline_character = b"\n" if "b" in self.fh.mode else "\n"
while True:
c = self.read(1)
Expand All @@ -105,7 +106,7 @@ def readline(self):
break
return s

def readlines(self):
def readlines(self) -> list[AnyStr]:
"""
Read multiple lines of text.
Expand Down
4 changes: 2 additions & 2 deletions addon/globalPlugins/_py3_contrib/PIL/CurImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#
# See the README file for information on usage and redistribution.
#
from __future__ import annotations

from . import BmpImagePlugin, Image
from ._binary import i16le as i16
from ._binary import i32le as i32
Expand Down Expand Up @@ -64,8 +66,6 @@ def _open(self):
d, e, o, a = self.tile[0]
self.tile[0] = d, (0, 0) + self.size, o, a

return


#
# --------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions addon/globalPlugins/_py3_contrib/PIL/DcxImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#
# See the README file for information on usage and redistribution.
#
from __future__ import annotations

from . import Image
from ._binary import i32le as i32
Expand Down
Loading

0 comments on commit ec8ae69

Please sign in to comment.