added fotn change API and examples
This commit is contained in:
@@ -25,6 +25,7 @@ PyWebLayout is a Python library for HTML-like layout and rendering to paginated
|
||||
### Text and HTML Support
|
||||
- 📝 **HTML Parsing** - Parse HTML content into structured document blocks
|
||||
- 🔤 **Font Support** - Multiple font sizes, weights, and styles
|
||||
- 🎨 **Dynamic Font Families** - Switch between Sans, Serif, and Monospace fonts on-the-fly
|
||||
- ↔️ **Text Alignment** - Left, center, right, and justified text
|
||||
- 📖 **Rich Content** - Headings, paragraphs, bold, italic, and more
|
||||
- 📊 **Table Rendering** - Full HTML table support with headers, borders, and styling
|
||||
@@ -138,6 +139,13 @@ The library supports various page layouts and configurations:
|
||||
<em>All 14 form field types with validation</em>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td align="center" colspan="2">
|
||||
<b>🆕 Dynamic Font Family Switching</b><br>
|
||||
<img src="docs/images/font_family_switching_vertical.png" width="600" alt="Font Switching"><br>
|
||||
<em>Switch between Sans, Serif, and Monospace fonts instantly</em>
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
## Examples
|
||||
@@ -151,11 +159,13 @@ The `examples/` directory contains working demonstrations:
|
||||
- **[04_table_rendering.py](examples/04_table_rendering.py)** - HTML table rendering with styling
|
||||
- **[05_html_table_with_images.py](examples/05_html_table_with_images.py)** - Tables with embedded images
|
||||
- **[06_functional_elements_demo.py](examples/06_functional_elements_demo.py)** - Interactive buttons and forms with callbacks
|
||||
- **[08_bundled_fonts_demo.py](examples/08_bundled_fonts_demo.py)** - Using the bundled DejaVu font families
|
||||
|
||||
### 🆕 Advanced Features (NEW)
|
||||
- **[08_pagination_demo.py](examples/08_pagination_demo.py)** - Multi-page documents with PageBreak ([11 tests](tests/examples/test_08_pagination_demo.py))
|
||||
- **[09_link_navigation_demo.py](examples/09_link_navigation_demo.py)** - All link types and navigation ([10 tests](tests/examples/test_09_link_navigation_demo.py))
|
||||
- **[10_forms_demo.py](examples/10_forms_demo.py)** - All 14 form field types ([9 tests](tests/examples/test_10_forms_demo.py))
|
||||
- **[11_font_family_switching_demo.py](examples/11_font_family_switching_demo.py)** - 🆕 Dynamic font switching in ereader
|
||||
|
||||
Run any example:
|
||||
```bash
|
||||
@@ -176,9 +186,46 @@ python -m pytest tests/examples/ -v # 30 tests, all passing ✅
|
||||
|
||||
See **[examples/README.md](examples/README.md)** for detailed documentation.
|
||||
|
||||
## Font Family Switching (NEW ✨)
|
||||
|
||||
PyWebLayout now supports dynamic font family switching in the ereader, allowing readers to change fonts on-the-fly without losing their reading position!
|
||||
|
||||
### Quick Example
|
||||
|
||||
```python
|
||||
from pyWebLayout.style.fonts import BundledFont
|
||||
from pyWebLayout.layout.ereader_manager import create_ereader_manager
|
||||
|
||||
# Create an ereader
|
||||
manager = create_ereader_manager(blocks, page_size=(600, 800))
|
||||
|
||||
# Switch to serif font
|
||||
manager.set_font_family(BundledFont.SERIF)
|
||||
|
||||
# Switch to monospace font
|
||||
manager.set_font_family(BundledFont.MONOSPACE)
|
||||
|
||||
# Restore original fonts
|
||||
manager.set_font_family(None)
|
||||
|
||||
# Query current font
|
||||
current = manager.get_font_family()
|
||||
```
|
||||
|
||||
### Features
|
||||
|
||||
- **3 Bundled Fonts**: Sans, Serif, and Monospace (DejaVu font family)
|
||||
- **Instant Switching**: Change fonts without recreating the document
|
||||
- **Position Preservation**: Reading position maintained across font changes
|
||||
- **Attribute Preservation**: Bold, italic, size, and color are preserved
|
||||
- **Smart Caching**: Automatic cache invalidation for optimal performance
|
||||
|
||||
**Learn more**: See [FONT_SWITCHING_FEATURE.md](FONT_SWITCHING_FEATURE.md) for complete documentation.
|
||||
|
||||
## Documentation
|
||||
|
||||
- **[ARCHITECTURE.md](ARCHITECTURE.md)** - Abstract/Concrete architecture guide
|
||||
- **[FONT_SWITCHING_FEATURE.md](FONT_SWITCHING_FEATURE.md)** - 🆕 Font family switching guide
|
||||
- **[examples/README.md](examples/README.md)** - Complete examples guide with tests
|
||||
- **[docs/images/README.md](docs/images/README.md)** - Visual documentation index
|
||||
- **[pyWebLayout/layout/README_EREADER_API.md](pyWebLayout/layout/README_EREADER_API.md)** - EbookReader API reference
|
||||
|
||||
Reference in New Issue
Block a user