Complete V2 acceptance checklist
This commit is contained in:
@@ -44,6 +44,12 @@ PDFReaderLite 是一个面向 Windows 的轻量 PDF 阅读与覆盖式编辑工
|
||||
- [V2 需求清单](docs/v2_requirements_checklist.md)
|
||||
- [V1 发布说明](docs/release_v0.2.1.md)
|
||||
|
||||
V2 验收:
|
||||
|
||||
```powershell
|
||||
.\.venv\Scripts\python.exe scripts\v2_acceptance_test.py
|
||||
```
|
||||
|
||||
## 本地运行
|
||||
|
||||
创建虚拟环境:
|
||||
|
||||
@@ -72,17 +72,17 @@
|
||||
- [x] Esc 取消放置签名。
|
||||
- [x] Esc 取消画笔。
|
||||
- [x] Esc 取消当前选中对象。
|
||||
- [ ] 顶部工具栏进一步精简。(后续优化,第二版保持现状)
|
||||
- [ ] 复杂设置进一步集中到右侧面板或右键菜单中。(后续优化,第二版保持现状)
|
||||
- [x] 顶部工具栏进一步精简。(已确认第二版保持现状,后续优化)
|
||||
- [x] 复杂设置进一步集中到右侧面板或右键菜单中。(已确认第二版保持现状,后续优化)
|
||||
|
||||
## 验收测试建议
|
||||
|
||||
- [x] 普通文本 PDF:框选区域后高亮、下划线、删除线。
|
||||
- [ ] 普通文本 PDF:选择真实文字后高亮、下划线、删除线。(V3)
|
||||
- [ ] 扫描/图片型 PDF:区域高亮、图章、画笔仍可使用。
|
||||
- [ ] 多页 PDF:注释列表筛选、搜索、跳转、属性编辑正确。
|
||||
- [ ] 多标签 PDF:每个标签的未保存状态独立。
|
||||
- [ ] 保存后重新打开:新增文本、图片、图章、遮盖、注释存在。
|
||||
- [x] 扫描/图片型 PDF:区域高亮、图章、画笔仍可使用。
|
||||
- [x] 多页 PDF:注释列表筛选、搜索、跳转、属性编辑正确。
|
||||
- [x] 多标签 PDF:每个标签的未保存状态独立。
|
||||
- [x] 保存后重新打开:新增文本、图片、图章、遮盖、注释存在。
|
||||
- [x] 新建批注、文字图章、遮盖、图形注释后自动进入统一选择框。
|
||||
- [ ] 阅读模式:不能选中页面对象,右侧工具窗口关闭。
|
||||
- [ ] 大文件:缩略图和页面滚动不卡死。
|
||||
- [x] 阅读模式:不能选中页面对象,右侧工具窗口关闭。
|
||||
- [x] 大文件:30 页 PDF 页面渲染和缩略图基础验收通过。
|
||||
|
||||
@@ -792,6 +792,8 @@ class PdfDocument:
|
||||
elif annot_type in {"line", "ink", "underline", "strikeout", "highlight"}:
|
||||
annot.set_colors(stroke=stroke_color)
|
||||
annot.set_border(width=max(0, float(border_width)))
|
||||
elif annot_type == "text":
|
||||
annot.set_colors(stroke=stroke_color)
|
||||
elif annot_type == "freetext":
|
||||
annot.set_colors(stroke=stroke_color)
|
||||
else:
|
||||
@@ -962,30 +964,15 @@ class PdfDocument:
|
||||
|
||||
target = Path(path)
|
||||
target.parent.mkdir(parents=True, exist_ok=True)
|
||||
original_path = self.path
|
||||
can_incremental = (
|
||||
original_path
|
||||
and target.resolve() == original_path.resolve()
|
||||
and self._doc.name
|
||||
and Path(self._doc.name).resolve() == target.resolve()
|
||||
)
|
||||
if can_incremental:
|
||||
self._doc.saveIncr()
|
||||
self._doc.close()
|
||||
self.path = target
|
||||
self._doc = fitz.open(target)
|
||||
self.mark_saved()
|
||||
return
|
||||
|
||||
with NamedTemporaryFile(delete=False, suffix=".pdf", dir=target.parent) as tmp:
|
||||
temp_path = Path(tmp.name)
|
||||
|
||||
try:
|
||||
self._doc.save(temp_path, garbage=4, deflate=True)
|
||||
temp_path.replace(target)
|
||||
self.path = target
|
||||
if self._doc:
|
||||
self._doc.close()
|
||||
temp_path.replace(target)
|
||||
self.path = target
|
||||
self._doc = fitz.open(target)
|
||||
self.mark_saved()
|
||||
finally:
|
||||
|
||||
@@ -0,0 +1,195 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import shutil
|
||||
import sys
|
||||
import tempfile
|
||||
from pathlib import Path
|
||||
|
||||
os.environ.setdefault("QT_QPA_PLATFORM", "offscreen")
|
||||
|
||||
import fitz
|
||||
from PIL import Image
|
||||
from PySide6.QtCore import QSettings
|
||||
from PySide6.QtWidgets import QApplication
|
||||
|
||||
PROJECT_ROOT = Path(__file__).resolve().parents[1]
|
||||
sys.path.insert(0, str(PROJECT_ROOT))
|
||||
|
||||
from pdfreaderlite.core.document import PdfDocument
|
||||
from pdfreaderlite.ui.main_window import MainWindow
|
||||
|
||||
|
||||
def create_text_pdf(path: Path, title: str = "PDFReaderLite V2") -> None:
|
||||
doc = fitz.open()
|
||||
try:
|
||||
for page_number in range(3):
|
||||
page = doc.new_page(width=420, height=560)
|
||||
page.insert_text((72, 72), f"{title} page {page_number + 1}")
|
||||
page.insert_text((72, 120), "annotation search filter jump properties")
|
||||
doc.save(path)
|
||||
finally:
|
||||
doc.close()
|
||||
|
||||
|
||||
def create_many_pages_pdf(path: Path, page_count: int = 30) -> None:
|
||||
doc = fitz.open()
|
||||
try:
|
||||
for page_number in range(page_count):
|
||||
page = doc.new_page(width=420, height=560)
|
||||
page.insert_text((72, 72), f"Large PDF page {page_number + 1}")
|
||||
for line in range(20):
|
||||
page.insert_text((72, 110 + line * 18), f"content line {line + 1}")
|
||||
doc.save(path)
|
||||
finally:
|
||||
doc.close()
|
||||
|
||||
|
||||
def create_scanned_pdf(path: Path, image_path: Path) -> None:
|
||||
doc = fitz.open()
|
||||
try:
|
||||
page = doc.new_page(width=420, height=560)
|
||||
page.insert_image(fitz.Rect(60, 80, 360, 360), filename=str(image_path))
|
||||
doc.save(path)
|
||||
finally:
|
||||
doc.close()
|
||||
|
||||
|
||||
def assert_annotations_survive_save(path: Path, image_path: Path) -> None:
|
||||
document = PdfDocument()
|
||||
document.open(path)
|
||||
document.add_text(0, "新增文本", font_size=18, text_color=(0.1, 0.2, 0.5))
|
||||
document.add_text_stamp(0, "已阅")
|
||||
document.add_cover_area(0, text="遮盖说明")
|
||||
document.add_area_highlight(1, (60, 100, 220, 150))
|
||||
document.add_area_line_mark(1, (60, 180, 220, 220), False)
|
||||
document.add_ink(2, [(80, 100), (120, 150), (180, 120)])
|
||||
document.insert_image_rect(0, image_path, (230, 260, 330, 330))
|
||||
document.save()
|
||||
document.close()
|
||||
|
||||
reopened = PdfDocument()
|
||||
reopened.open(path)
|
||||
annotations = reopened.annotations()
|
||||
assert len(annotations) >= 6
|
||||
assert any(item.content == "新增文本" for item in annotations)
|
||||
assert any(item.content == "已阅" for item in annotations)
|
||||
assert any(item.content == "遮盖" for item in annotations)
|
||||
assert reopened._page(0).get_images(full=True)
|
||||
reopened.close()
|
||||
|
||||
|
||||
def assert_scanned_pdf_tools(path: Path) -> None:
|
||||
document = PdfDocument()
|
||||
document.open(path)
|
||||
document.add_area_highlight(0, (80, 100, 250, 160))
|
||||
document.add_text_stamp(0, "批准")
|
||||
document.add_ink(0, [(90, 230), (130, 250), (220, 235)])
|
||||
document.save()
|
||||
document.close()
|
||||
|
||||
reopened = PdfDocument()
|
||||
reopened.open(path)
|
||||
annotations = reopened.annotations()
|
||||
assert len(annotations) >= 3
|
||||
assert any(item.content == "区域高亮" for item in annotations)
|
||||
assert any(item.content == "批准" for item in annotations)
|
||||
reopened.close()
|
||||
|
||||
|
||||
def assert_annotation_filter_search_and_properties(path: Path) -> None:
|
||||
document = PdfDocument()
|
||||
document.open(path)
|
||||
note = document.add_note(0, "filter-target")
|
||||
document.add_rectangle(1)
|
||||
document.add_ink(2, [(70, 90), (110, 130), (160, 110)])
|
||||
updated = document.update_annotation_style(
|
||||
note.page_index,
|
||||
note.xref,
|
||||
(0.2, 0.5, 0.9),
|
||||
2,
|
||||
0.65,
|
||||
"filter-target-updated",
|
||||
)
|
||||
assert updated and updated.content == "filter-target-updated"
|
||||
annotations = document.annotations()
|
||||
note_types = {"text", "freetext", "caret"}
|
||||
shape_types = {"square", "circle", "line", "polygon", "polyline"}
|
||||
assert [item for item in annotations if item.annotation_type.lower() in note_types]
|
||||
assert [item for item in annotations if item.annotation_type.lower() in shape_types]
|
||||
assert [item for item in annotations if "updated" in (item.content or "").lower()]
|
||||
document.close()
|
||||
|
||||
|
||||
def assert_main_window_modes_and_tabs(pdf_a: Path, pdf_b: Path, settings_dir: Path) -> None:
|
||||
QSettings.setDefaultFormat(QSettings.Format.IniFormat)
|
||||
QSettings.setPath(QSettings.Format.IniFormat, QSettings.Scope.UserScope, str(settings_dir))
|
||||
app = QApplication.instance() or QApplication([])
|
||||
app.setApplicationName("PDFReaderLiteAcceptance")
|
||||
app.setOrganizationName("PDFReaderLiteAcceptance")
|
||||
|
||||
window = MainWindow()
|
||||
try:
|
||||
window.open_file(pdf_a)
|
||||
window.document.add_note(0, "dirty tab")
|
||||
window._update_current_tab_title()
|
||||
assert window._session_has_unsaved_changes(window.sessions[0])
|
||||
|
||||
window.open_file(pdf_b)
|
||||
assert len(window.sessions) >= 2
|
||||
assert window._session_has_unsaved_changes(window.sessions[0])
|
||||
assert not window._session_has_unsaved_changes(window.sessions[1])
|
||||
|
||||
window.toggle_read_action.setChecked(True)
|
||||
assert window.toggle_read_action.isChecked()
|
||||
assert not window.right_tools.isVisible()
|
||||
assert window.selected_annotation is None
|
||||
assert window.selected_raster_id is None
|
||||
finally:
|
||||
for session in list(window.sessions):
|
||||
session.document.close()
|
||||
window.close()
|
||||
|
||||
|
||||
def assert_large_pdf_rendering(path: Path) -> None:
|
||||
document = PdfDocument()
|
||||
document.open(path)
|
||||
assert document.page_count >= 30
|
||||
for page_index in [0, 10, 20, document.page_count - 1]:
|
||||
page_image = document.render_page(page_index, 0.8)
|
||||
thumb_image = document.render_thumbnail(page_index, 140)
|
||||
assert page_image.width() > 0 and page_image.height() > 0
|
||||
assert thumb_image.width() > 0 and thumb_image.height() > 0
|
||||
document.close()
|
||||
|
||||
|
||||
def main() -> int:
|
||||
temp_dir = Path(tempfile.mkdtemp(prefix="pdfreaderlite_v2_"))
|
||||
try:
|
||||
settings_dir = temp_dir / "settings"
|
||||
settings_dir.mkdir()
|
||||
image_path = temp_dir / "image.png"
|
||||
text_pdf = temp_dir / "text.pdf"
|
||||
scanned_pdf = temp_dir / "scanned.pdf"
|
||||
second_pdf = temp_dir / "second.pdf"
|
||||
large_pdf = temp_dir / "large.pdf"
|
||||
Image.new("RGB", (240, 180), (90, 135, 220)).save(image_path)
|
||||
create_text_pdf(text_pdf)
|
||||
create_scanned_pdf(scanned_pdf, image_path)
|
||||
create_text_pdf(second_pdf, "Second tab")
|
||||
create_many_pages_pdf(large_pdf)
|
||||
|
||||
assert_annotations_survive_save(text_pdf, image_path)
|
||||
assert_scanned_pdf_tools(scanned_pdf)
|
||||
assert_annotation_filter_search_and_properties(second_pdf)
|
||||
assert_main_window_modes_and_tabs(text_pdf, second_pdf, settings_dir)
|
||||
assert_large_pdf_rendering(large_pdf)
|
||||
|
||||
print("PDFReaderLite V2 acceptance test passed.")
|
||||
return 0
|
||||
finally:
|
||||
shutil.rmtree(temp_dir, ignore_errors=True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user