97 lines
3.4 KiB
Python
Executable File
97 lines
3.4 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""
|
|
Test script to demonstrate font family setting functionality.
|
|
"""
|
|
|
|
from pyWebLayout.style.fonts import BundledFont
|
|
from dreader.application import EbookReader
|
|
import os
|
|
|
|
def test_font_family():
|
|
"""Test the font family setting feature."""
|
|
# Initialize reader
|
|
reader = EbookReader(page_size=(600, 800), margin=20)
|
|
|
|
# Load a sample book
|
|
book_path = os.path.join(os.path.dirname(__file__), '..', 'examples', 'beowulf.epub')
|
|
|
|
if not os.path.exists(book_path):
|
|
print(f"Book not found at {book_path}")
|
|
print("Skipping book loading - testing with HTML instead...")
|
|
# Load a simple HTML document instead
|
|
sample_html = """
|
|
<html>
|
|
<head><title>Font Family Test</title></head>
|
|
<body>
|
|
<h1>Font Family Test Document</h1>
|
|
<p>This is a test document to demonstrate the font family setting feature.</p>
|
|
<p>The quick brown fox jumps over the lazy dog. 0123456789</p>
|
|
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit.</p>
|
|
</body>
|
|
</html>
|
|
"""
|
|
reader.load_html(sample_html, title="Font Family Test")
|
|
else:
|
|
print(f"Loading book from: {book_path}")
|
|
reader.load_epub(book_path)
|
|
|
|
# Get initial page
|
|
print("\n1. Rendering with default font family...")
|
|
page1 = reader.get_current_page()
|
|
print(f" Current font family: {reader.get_font_family()}")
|
|
|
|
# Switch to serif
|
|
print("\n2. Switching to SERIF font family...")
|
|
reader.set_font_family(BundledFont.SERIF)
|
|
page2 = reader.get_current_page()
|
|
print(f" Current font family: {reader.get_font_family()}")
|
|
|
|
# Switch to sans-serif
|
|
print("\n3. Switching to SANS font family...")
|
|
reader.set_font_family(BundledFont.SANS)
|
|
page3 = reader.get_current_page()
|
|
print(f" Current font family: {reader.get_font_family()}")
|
|
|
|
# Switch to monospace
|
|
print("\n4. Switching to MONOSPACE font family...")
|
|
reader.set_font_family(BundledFont.MONOSPACE)
|
|
page4 = reader.get_current_page()
|
|
print(f" Current font family: {reader.get_font_family()}")
|
|
|
|
# Restore original fonts
|
|
print("\n5. Restoring document default font family...")
|
|
reader.set_font_family(None)
|
|
page5 = reader.get_current_page()
|
|
print(f" Current font family: {reader.get_font_family()}")
|
|
|
|
# Test settings persistence
|
|
print("\n6. Testing settings persistence...")
|
|
reader.set_font_family(BundledFont.SERIF)
|
|
settings = reader.get_current_settings()
|
|
print(f" Settings: {settings}")
|
|
print(f" Font family in settings: {settings.get('font_family')}")
|
|
|
|
# Apply settings
|
|
print("\n7. Applying settings with MONOSPACE...")
|
|
new_settings = settings.copy()
|
|
new_settings['font_family'] = 'MONOSPACE'
|
|
reader.apply_settings(new_settings)
|
|
print(f" Current font family: {reader.get_font_family()}")
|
|
|
|
# Test with settings overlay
|
|
print("\n8. Opening settings overlay...")
|
|
overlay_image = reader.open_settings_overlay()
|
|
print(f" Settings overlay opened successfully: {overlay_image is not None}")
|
|
print(f" Settings overlay dimensions: {overlay_image.size if overlay_image else 'N/A'}")
|
|
|
|
print("\n✓ All font family tests passed!")
|
|
return True
|
|
|
|
if __name__ == "__main__":
|
|
try:
|
|
test_font_family()
|
|
except Exception as e:
|
|
print(f"\n✗ Test failed with error: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|