awacke1 commited on
Commit
4322505
·
verified ·
1 Parent(s): ee2d5e8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -149,11 +149,11 @@ def apply_emoji_font(text, emoji_font):
149
  for match in emoji_pattern.finditer(content):
150
  start, end = match.span()
151
  if last_pos < start:
152
- parts.append(f'<font face="DejaVuSans">{content[last_pos:start]}</font>')
153
  parts.append(replace_emoji(match))
154
  last_pos = end
155
  if last_pos < len(content):
156
- parts.append(f'<font face="DejaVuSans">{content[last_pos:]}</font>')
157
  result.append(''.join(parts))
158
  else:
159
  # Keep links and bold tags unchanged
@@ -224,7 +224,9 @@ def create_pdf(markdown_text, base_font_size, render_with_bold, auto_bold_number
224
  selected_font_path = next((f for f in available_font_files if "NotoEmoji-Bold" in f), None)
225
  if selected_font_path:
226
  pdfmetrics.registerFont(TTFont("NotoEmoji-Bold", selected_font_path))
227
- pdfmetrics.registerFont(TTFont("DejaVuSans", "DejaVuSans.ttf"))
 
 
228
  except Exception as e:
229
  st.error(f"Font registration error: {e}")
230
  return
@@ -248,7 +250,7 @@ def create_pdf(markdown_text, base_font_size, render_with_bold, auto_bold_number
248
  adjusted_font_size = int(col_width / (avg_line_chars / 10))
249
  adjusted_font_size = max(min_font_size, adjusted_font_size)
250
  item_style = ParagraphStyle(
251
- 'ItemStyle', parent=styles['Normal'], fontName="DejaVuSans",
252
  fontSize=adjusted_font_size, leading=adjusted_font_size * 1.15, spaceAfter=1,
253
  linkUnderline=True
254
  )
@@ -259,7 +261,7 @@ def create_pdf(markdown_text, base_font_size, render_with_bold, auto_bold_number
259
  linkUnderline=True
260
  )
261
  section_style = ParagraphStyle(
262
- 'SectionStyle', parent=styles['Heading2'], fontName="DejaVuSans",
263
  textColor=colors.darkblue, fontSize=adjusted_font_size * 1.1, leading=adjusted_font_size * 1.32, spaceAfter=2,
264
  linkUnderline=True
265
  )
@@ -285,7 +287,7 @@ def create_pdf(markdown_text, base_font_size, render_with_bold, auto_bold_number
285
  heading_style = ParagraphStyle(
286
  f'Heading{level}Style',
287
  parent=styles['Heading1'],
288
- fontName="DejaVuSans",
289
  textColor=colors.darkblue if level == 1 else (colors.black if level > 2 else colors.blue),
290
  fontSize=adjusted_font_size * (1.6 - (level-1)*0.15),
291
  leading=adjusted_font_size * (1.8 - (level-1)*0.15),
@@ -301,9 +303,9 @@ def create_pdf(markdown_text, base_font_size, render_with_bold, auto_bold_number
301
  else:
302
  column_cells[col_idx].append(Paragraph(apply_emoji_font(content, "NotoEmoji-Bold"), section_style))
303
  else:
304
- column_cells[col_idx].append(Paragraph(apply_emoji_font(item, "DejaVuSans"), item_style))
305
  else:
306
- column_cells[col_idx].append(Paragraph(apply_emoji_font(str(item), "DejaVuSans"), item_style))
307
  max_cells = max(len(cells) for cells in column_cells) if column_cells else 0
308
  for cells in column_cells:
309
  cells.extend([Paragraph("", item_style)] * (max_cells - len(cells)))
 
149
  for match in emoji_pattern.finditer(content):
150
  start, end = match.span()
151
  if last_pos < start:
152
+ parts.append(f'<font face="NotoEmoji-Bold">{content[last_pos:start]}</font>')
153
  parts.append(replace_emoji(match))
154
  last_pos = end
155
  if last_pos < len(content):
156
+ parts.append(f'<font face="NotoEmoji-Bold">{content[last_pos:]}</font>')
157
  result.append(''.join(parts))
158
  else:
159
  # Keep links and bold tags unchanged
 
224
  selected_font_path = next((f for f in available_font_files if "NotoEmoji-Bold" in f), None)
225
  if selected_font_path:
226
  pdfmetrics.registerFont(TTFont("NotoEmoji-Bold", selected_font_path))
227
+ else:
228
+ st.error("NotoEmoji-Bold font not found.")
229
+ return
230
  except Exception as e:
231
  st.error(f"Font registration error: {e}")
232
  return
 
250
  adjusted_font_size = int(col_width / (avg_line_chars / 10))
251
  adjusted_font_size = max(min_font_size, adjusted_font_size)
252
  item_style = ParagraphStyle(
253
+ 'ItemStyle', parent=styles['Normal'], fontName="NotoEmoji-Bold",
254
  fontSize=adjusted_font_size, leading=adjusted_font_size * 1.15, spaceAfter=1,
255
  linkUnderline=True
256
  )
 
261
  linkUnderline=True
262
  )
263
  section_style = ParagraphStyle(
264
+ 'SectionStyle', parent=styles['Heading2'], fontName="NotoEmoji-Bold",
265
  textColor=colors.darkblue, fontSize=adjusted_font_size * 1.1, leading=adjusted_font_size * 1.32, spaceAfter=2,
266
  linkUnderline=True
267
  )
 
287
  heading_style = ParagraphStyle(
288
  f'Heading{level}Style',
289
  parent=styles['Heading1'],
290
+ fontName="NotoEmoji-Bold",
291
  textColor=colors.darkblue if level == 1 else (colors.black if level > 2 else colors.blue),
292
  fontSize=adjusted_font_size * (1.6 - (level-1)*0.15),
293
  leading=adjusted_font_size * (1.8 - (level-1)*0.15),
 
303
  else:
304
  column_cells[col_idx].append(Paragraph(apply_emoji_font(content, "NotoEmoji-Bold"), section_style))
305
  else:
306
+ column_cells[col_idx].append(Paragraph(apply_emoji_font(item, "NotoEmoji-Bold"), item_style))
307
  else:
308
+ column_cells[col_idx].append(Paragraph(apply_emoji_font(str(item), "NotoEmoji-Bold"), item_style))
309
  max_cells = max(len(cells) for cells in column_cells) if column_cells else 0
310
  for cells in column_cells:
311
  cells.extend([Paragraph("", item_style)] * (max_cells - len(cells)))