@@ -270,7 +270,7 @@ class FormattedSpan:
|
||||
return word
|
||||
|
||||
|
||||
class LineBreak:
|
||||
class LineBreak():
|
||||
"""
|
||||
A line break element that forces a new line within text content.
|
||||
While this is an inline element that can occur within paragraphs,
|
||||
|
||||
@@ -9,7 +9,7 @@ This package contains styling-related components including:
|
||||
"""
|
||||
|
||||
# Import alignment options
|
||||
from pyWebLayout.style.alignment import Alignment
|
||||
from pyWebLayout.style.layout import Alignment
|
||||
|
||||
# Import font-related classes
|
||||
from pyWebLayout.style.fonts import (
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
"""
|
||||
Alignment options for text and elements in the pyWebLayout library.
|
||||
"""
|
||||
|
||||
from enum import Enum
|
||||
|
||||
class Alignment(Enum):
|
||||
"""
|
||||
Enum for alignment options used in layout and rendering.
|
||||
"""
|
||||
LEFT = 1
|
||||
CENTER = 2
|
||||
RIGHT = 3
|
||||
TOP = 4
|
||||
BOTTOM = 5
|
||||
JUSTIFY = 6
|
||||
@@ -77,45 +77,19 @@ class Font:
|
||||
"""Load the font using PIL's ImageFont with consistent bundled font"""
|
||||
try:
|
||||
if self._font_path:
|
||||
# Use specified font path
|
||||
self._font = ImageFont.truetype(
|
||||
self._font_path,
|
||||
self._font_size
|
||||
)
|
||||
else:
|
||||
# Try bundled font first for consistency across environments
|
||||
# Use bundled font for consistency across environments
|
||||
bundled_font_path = self._get_bundled_font_path()
|
||||
|
||||
font_candidates = []
|
||||
if bundled_font_path:
|
||||
font_candidates.append(bundled_font_path)
|
||||
|
||||
# Fallback to system fonts if bundled font is not available
|
||||
font_candidates.extend([
|
||||
# Linux fonts
|
||||
"/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf",
|
||||
"/usr/share/fonts/truetype/dejavu/DejaVuSans.ttf",
|
||||
"/usr/share/fonts/TTF/DejaVuSans.ttf",
|
||||
"/System/Library/Fonts/Helvetica.ttc", # macOS
|
||||
"C:/Windows/Fonts/arial.ttf", # Windows
|
||||
"C:/Windows/Fonts/calibri.ttf", # Windows
|
||||
# Fallback to default
|
||||
None
|
||||
])
|
||||
|
||||
self._font = None
|
||||
for font_path in font_candidates:
|
||||
try:
|
||||
if font_path is None:
|
||||
# Use PIL's default font as last resort
|
||||
self._font = ImageFont.load_default()
|
||||
break
|
||||
else:
|
||||
self._font = ImageFont.truetype(font_path, self._font_size)
|
||||
break
|
||||
except (OSError, IOError):
|
||||
continue
|
||||
|
||||
if self._font is None:
|
||||
self._font = ImageFont.truetype(bundled_font_path, self._font_size)
|
||||
else:
|
||||
# Only fall back to PIL's default font if bundled font is not available
|
||||
self._font = ImageFont.load_default()
|
||||
|
||||
except Exception as e:
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
"""
|
||||
Layout and alignment options for the pyWebLayout library.
|
||||
"""
|
||||
|
||||
from enum import Enum
|
||||
|
||||
|
||||
class Alignment(Enum):
|
||||
"""
|
||||
Enum for alignment options used in layout and rendering.
|
||||
"""
|
||||
LEFT = 1
|
||||
CENTER = 2
|
||||
RIGHT = 3
|
||||
TOP = 4
|
||||
BOTTOM = 5
|
||||
JUSTIFY = 6
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user