Added ACC flipping of page
This commit is contained in:
@@ -9,14 +9,16 @@ from typing import Dict, Any, Optional
|
||||
from PIL import Image
|
||||
|
||||
from pyWebLayout.layout.ereader_manager import EreaderLayoutManager
|
||||
from pyWebLayout.style.fonts import BundledFont
|
||||
|
||||
|
||||
class SettingsManager:
|
||||
"""
|
||||
Manages font size, spacing, and rendering settings.
|
||||
Manages font size, spacing, font family, and rendering settings.
|
||||
|
||||
Responsibilities:
|
||||
- Font scale adjustment
|
||||
- Font family selection (serif, sans-serif, monospace)
|
||||
- Line spacing control
|
||||
- Inter-block spacing control
|
||||
- Word spacing control
|
||||
@@ -27,6 +29,7 @@ class SettingsManager:
|
||||
"""Initialize the settings manager."""
|
||||
self.font_scale = 1.0
|
||||
self.font_scale_step = 0.1 # 10% change per step
|
||||
self.font_family: Optional[BundledFont] = None # None = use document default
|
||||
self.manager: Optional[EreaderLayoutManager] = None
|
||||
|
||||
def set_manager(self, manager: EreaderLayoutManager):
|
||||
@@ -38,6 +41,7 @@ class SettingsManager:
|
||||
"""
|
||||
self.manager = manager
|
||||
self.font_scale = manager.font_scale
|
||||
self.font_family = manager.get_font_family()
|
||||
|
||||
def set_font_size(self, scale: float) -> Optional[Image.Image]:
|
||||
"""
|
||||
@@ -89,6 +93,36 @@ class SettingsManager:
|
||||
"""
|
||||
return self.font_scale
|
||||
|
||||
def set_font_family(self, font_family: Optional[BundledFont]) -> Optional[Image.Image]:
|
||||
"""
|
||||
Set the font family and re-render current page.
|
||||
|
||||
Args:
|
||||
font_family: BundledFont enum value (SERIF, SANS, MONOSPACE) or None for document default
|
||||
|
||||
Returns:
|
||||
Rendered page with new font family, or None if no manager
|
||||
"""
|
||||
if not self.manager:
|
||||
return None
|
||||
|
||||
try:
|
||||
self.font_family = font_family
|
||||
page = self.manager.set_font_family(font_family)
|
||||
return page.render() if page else None
|
||||
except Exception as e:
|
||||
print(f"Error setting font family: {e}")
|
||||
return None
|
||||
|
||||
def get_font_family(self) -> Optional[BundledFont]:
|
||||
"""
|
||||
Get the current font family.
|
||||
|
||||
Returns:
|
||||
Current BundledFont or None if using document default
|
||||
"""
|
||||
return self.font_family
|
||||
|
||||
def set_line_spacing(self, spacing: int) -> Optional[Image.Image]:
|
||||
"""
|
||||
Set line spacing using pyWebLayout's native support.
|
||||
@@ -195,6 +229,7 @@ class SettingsManager:
|
||||
if not self.manager:
|
||||
return {
|
||||
'font_scale': self.font_scale,
|
||||
'font_family': self.font_family.name if self.font_family else None,
|
||||
'line_spacing': 5,
|
||||
'inter_block_spacing': 15,
|
||||
'word_spacing': 0
|
||||
@@ -202,6 +237,7 @@ class SettingsManager:
|
||||
|
||||
return {
|
||||
'font_scale': self.font_scale,
|
||||
'font_family': self.font_family.name if self.font_family else None,
|
||||
'line_spacing': self.manager.page_style.line_spacing,
|
||||
'inter_block_spacing': self.manager.page_style.inter_block_spacing,
|
||||
'word_spacing': self.manager.page_style.word_spacing
|
||||
@@ -214,7 +250,7 @@ class SettingsManager:
|
||||
This should be called after loading a book to restore user preferences.
|
||||
|
||||
Args:
|
||||
settings: Dictionary with settings (font_scale, line_spacing, etc.)
|
||||
settings: Dictionary with settings (font_scale, font_family, line_spacing, etc.)
|
||||
|
||||
Returns:
|
||||
True if settings applied successfully, False otherwise
|
||||
@@ -223,6 +259,19 @@ class SettingsManager:
|
||||
return False
|
||||
|
||||
try:
|
||||
# Apply font family
|
||||
font_family_name = settings.get('font_family', None)
|
||||
if font_family_name:
|
||||
try:
|
||||
font_family = BundledFont[font_family_name]
|
||||
if font_family != self.font_family:
|
||||
self.set_font_family(font_family)
|
||||
except KeyError:
|
||||
print(f"Warning: Unknown font family '{font_family_name}', using default")
|
||||
elif font_family_name is None and self.font_family is not None:
|
||||
# Restore to document default
|
||||
self.set_font_family(None)
|
||||
|
||||
# Apply font scale
|
||||
font_scale = settings.get('font_scale', 1.0)
|
||||
if font_scale != self.font_scale:
|
||||
|
||||
Reference in New Issue
Block a user