Spaces:
Paused
Paused
File size: 10,215 Bytes
342973b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 |
"""
Layout Manager - Manage document layout and professional design
"""
from typing import Dict, List, Optional, Tuple
class LayoutManager:
"""
Manage professional document layouts, spacing, and design.
"""
def __init__(self):
"""Initialize layout manager."""
self.page_width = 8.5 # inches (letter size)
self.page_height = 11.0
self.margin_top = 1.0
self.margin_bottom = 1.0
self.margin_left = 1.0
self.margin_right = 1.0
def calculate_usable_area(self) -> Tuple[float, float]:
"""
Calculate usable page area (excluding margins).
Returns:
Tuple of (width, height) in inches
"""
width = self.page_width - self.margin_left - self.margin_right
height = self.page_height - self.margin_top - self.margin_bottom
return (width, height)
def create_two_column_layout(
self, left_width_percent: float = 50
) -> Dict[str, Dict[str, float]]:
"""
Create two-column layout specification.
Args:
left_width_percent: Width percentage of left column
Returns:
Layout specification dictionary
"""
usable_width, usable_height = self.calculate_usable_area()
left_width = (usable_width * left_width_percent) / 100
right_width = usable_width - left_width
gutter = 0.25 # Space between columns
return {
"left_column": {
"x": self.margin_left,
"y": self.margin_top,
"width": left_width - gutter / 2,
"height": usable_height,
},
"right_column": {
"x": self.margin_left + left_width + gutter / 2,
"y": self.margin_top,
"width": right_width - gutter / 2,
"height": usable_height,
},
}
def create_three_column_layout(self) -> Dict[str, Dict[str, float]]:
"""
Create three-column layout specification.
Returns:
Layout specification dictionary
"""
usable_width, usable_height = self.calculate_usable_area()
col_width = (usable_width - 0.5) / 3
gutter = 0.25
return {
"left_column": {
"x": self.margin_left,
"y": self.margin_top,
"width": col_width - gutter / 2,
"height": usable_height,
},
"center_column": {
"x": self.margin_left + col_width + gutter,
"y": self.margin_top,
"width": col_width - gutter,
"height": usable_height,
},
"right_column": {
"x": self.margin_left + 2 * col_width + 2 * gutter,
"y": self.margin_top,
"width": col_width - gutter / 2,
"height": usable_height,
},
}
def get_heading_styles(self) -> Dict[str, Dict]:
"""
Get professional heading styles.
Returns:
Dictionary of heading style specifications
"""
return {
"h1": {
"font_size": 28,
"font_weight": "bold",
"color": "#000000",
"spacing_before": 24,
"spacing_after": 12,
},
"h2": {
"font_size": 22,
"font_weight": "bold",
"color": "#1a1a1a",
"spacing_before": 18,
"spacing_after": 10,
},
"h3": {
"font_size": 16,
"font_weight": "bold",
"color": "#333333",
"spacing_before": 12,
"spacing_after": 6,
},
"body": {
"font_size": 11,
"font_weight": "normal",
"color": "#000000",
"line_height": 1.5,
"spacing_after": 12,
},
}
def get_color_palette(self, theme: str = "professional") -> Dict[str, str]:
"""
Get color palette for theme.
Args:
theme: Theme name (professional, academic, modern, classic)
Returns:
Dictionary of color definitions
"""
palettes = {
"professional": {
"primary": "#1a73e8",
"secondary": "#34a853",
"accent": "#f57c00",
"text": "#202124",
"light_bg": "#f8f9fa",
"border": "#dadce0",
},
"academic": {
"primary": "#003366",
"secondary": "#006699",
"accent": "#cc0000",
"text": "#000000",
"light_bg": "#f5f5f5",
"border": "#cccccc",
},
"modern": {
"primary": "#6200ea",
"secondary": "#03dac6",
"accent": "#ff0266",
"text": "#1f1f1f",
"light_bg": "#fafafa",
"border": "#e0e0e0",
},
"classic": {
"primary": "#2c3e50",
"secondary": "#3498db",
"accent": "#e74c3c",
"text": "#2c3e50",
"light_bg": "#ecf0f1",
"border": "#bdc3c7",
},
}
return palettes.get(theme, palettes["professional"])
def get_spacing_rules(self) -> Dict[str, float]:
"""
Get spacing rules (in inches).
Returns:
Dictionary of spacing values
"""
return {
"extra_small": 0.125,
"small": 0.25,
"medium": 0.5,
"large": 0.75,
"extra_large": 1.0,
"section_break": 1.5,
"page_break": self.page_height,
}
def create_sidebar_layout(
self, sidebar_width_percent: float = 25
) -> Dict[str, Dict[str, float]]:
"""
Create sidebar layout specification.
Args:
sidebar_width_percent: Width percentage of sidebar
Returns:
Layout specification dictionary
"""
usable_width, usable_height = self.calculate_usable_area()
sidebar_width = (usable_width * sidebar_width_percent) / 100
content_width = usable_width - sidebar_width
gutter = 0.25
return {
"sidebar": {
"x": self.margin_left,
"y": self.margin_top,
"width": sidebar_width - gutter / 2,
"height": usable_height,
},
"main_content": {
"x": self.margin_left + sidebar_width + gutter,
"y": self.margin_top,
"width": content_width - gutter / 2,
"height": usable_height,
},
}
def calculate_text_wrap(self, text: str, column_width: float, chars_per_inch: float = 10) -> List[str]:
"""
Calculate text wrapping for column width.
Args:
text: Text to wrap
column_width: Column width in inches
chars_per_inch: Characters per inch (depending on font)
Returns:
List of wrapped lines
"""
max_chars_per_line = int(column_width * chars_per_inch)
words = text.split()
lines = []
current_line = ""
for word in words:
if len(current_line) + len(word) + 1 <= max_chars_per_line:
current_line += word + " "
else:
if current_line:
lines.append(current_line.strip())
current_line = word + " "
if current_line:
lines.append(current_line.strip())
return lines
def get_professional_margins(self, format_type: str = "A4") -> Dict[str, float]:
"""
Get professional margin settings for different formats.
Args:
format_type: Format type (A4, Letter, etc.)
Returns:
Dictionary of margin values
"""
formats = {
"A4": {"top": 1.0, "bottom": 1.0, "left": 1.0, "right": 1.0},
"Letter": {"top": 1.0, "bottom": 1.0, "left": 1.0, "right": 1.0},
"Narrow": {"top": 0.5, "bottom": 0.5, "left": 0.5, "right": 0.5},
"Wide": {"top": 1.5, "bottom": 1.5, "left": 1.5, "right": 1.5},
}
return formats.get(format_type, formats["A4"])
def get_typography_settings(self) -> Dict[str, any]:
"""
Get professional typography settings.
Returns:
Dictionary of typography settings
"""
return {
"font_family": "Calibri, Arial, sans-serif",
"base_font_size": 11,
"line_height": 1.5,
"letter_spacing": 0,
"paragraph_spacing": 12,
"heading_font": "Calibri, Arial, sans-serif",
"heading_weight": "bold",
"body_weight": "normal",
"emphasis_style": "italic",
}
def create_title_page_layout(self) -> Dict[str, any]:
"""
Create title page layout specification.
Returns:
Title page layout dictionary
"""
usable_width, usable_height = self.calculate_usable_area()
return {
"title": {
"y": usable_height * 0.25,
"font_size": 36,
"alignment": "center",
"spacing_after": 24,
},
"subtitle": {
"y": usable_height * 0.35,
"font_size": 18,
"alignment": "center",
"spacing_after": 60,
},
"author": {
"y": usable_height * 0.6,
"font_size": 12,
"alignment": "center",
"spacing_after": 12,
},
"date": {
"y": usable_height * 0.65,
"font_size": 12,
"alignment": "center",
"spacing_after": 0,
},
}
|