awacke1 commited on
Commit
6d1ad38
·
verified ·
1 Parent(s): 0133b3c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -9
app.py CHANGED
@@ -98,7 +98,7 @@ def apply_emoji_font(text, emoji_font):
98
  segments = tag_pattern.split(text)
99
  result = []
100
 
101
- # Apply emoji font only to non-tag text
102
  emoji_pattern = re.compile(
103
  r"([\U0001F300-\U0001F5FF"
104
  r"\U0001F600-\U0001F64F"
@@ -124,17 +124,17 @@ def apply_emoji_font(text, emoji_font):
124
  # Keep tags unchanged
125
  result.append(segment)
126
  else:
127
- # Apply emoji font to all text to preserve emojis
128
  parts = []
129
  last_pos = 0
130
  for match in emoji_pattern.finditer(segment):
131
  start, end = match.span()
132
  if last_pos < start:
133
- parts.append(f'<font face="{emoji_font}">{segment[last_pos:start]}</font>')
134
  parts.append(replace_emoji(match))
135
  last_pos = end
136
  if last_pos < len(segment):
137
- parts.append(f'<font face="{emoji_font}">{segment[last_pos:]}</font>')
138
  result.append(''.join(parts))
139
 
140
  return ''.join(result)
@@ -170,7 +170,7 @@ def markdown_to_pdf_content(markdown_text, render_with_bold, auto_bold_numbers,
170
 
171
  line = detect_and_convert_links(line)
172
 
173
- # Always preserve bold and emphasis formatting to ensure emoji rendering
174
  line = re.sub(r'\*\*(.+?)\*\*', r'<b>\1</b>', line)
175
  line = re.sub(r'\*([^*]+?)\*', r'<b>\1</b>', line)
176
 
@@ -231,7 +231,7 @@ def create_pdf(markdown_text, base_font_size, render_with_bold, auto_bold_number
231
  adjusted_font_size = int(col_width / (avg_line_chars / 10))
232
  adjusted_font_size = max(min_font_size, adjusted_font_size)
233
  item_style = ParagraphStyle(
234
- 'ItemStyle', parent=styles['Normal'], fontName="NotoEmoji-Bold",
235
  fontSize=adjusted_font_size, leading=adjusted_font_size * 1.15, spaceAfter=1,
236
  linkUnderline=True
237
  )
@@ -242,7 +242,7 @@ def create_pdf(markdown_text, base_font_size, render_with_bold, auto_bold_number
242
  linkUnderline=True
243
  )
244
  section_style = ParagraphStyle(
245
- 'SectionStyle', parent=styles['Heading2'], fontName="NotoEmoji-Bold",
246
  textColor=colors.darkblue, fontSize=adjusted_font_size * 1.1, leading=adjusted_font_size * 1.32, spaceAfter=2,
247
  linkUnderline=True
248
  )
@@ -268,7 +268,7 @@ def create_pdf(markdown_text, base_font_size, render_with_bold, auto_bold_number
268
  heading_style = ParagraphStyle(
269
  f'Heading{level}Style',
270
  parent=styles['Heading1'],
271
- fontName="NotoEmoji-Bold",
272
  textColor=colors.darkblue if level == 1 else (colors.black if level > 2 else colors.blue),
273
  fontSize=adjusted_font_size * (1.6 - (level-1)*0.15),
274
  leading=adjusted_font_size * (1.8 - (level-1)*0.15),
@@ -279,7 +279,10 @@ def create_pdf(markdown_text, base_font_size, render_with_bold, auto_bold_number
279
  column_cells[col_idx].append(Paragraph(apply_emoji_font(heading_text, "NotoEmoji-Bold"), heading_style))
280
  elif item.startswith("<b>") and item.endswith("</b>"):
281
  content = item[3:-4].strip()
282
- column_cells[col_idx].append(Paragraph(apply_emoji_font(content, "NotoEmoji-Bold"), numbered_bold_style))
 
 
 
283
  else:
284
  column_cells[col_idx].append(Paragraph(apply_emoji_font(item, "NotoEmoji-Bold"), item_style))
285
  else:
 
98
  segments = tag_pattern.split(text)
99
  result = []
100
 
101
+ # Apply emoji font only to emojis, use DejaVuSans for other text
102
  emoji_pattern = re.compile(
103
  r"([\U0001F300-\U0001F5FF"
104
  r"\U0001F600-\U0001F64F"
 
124
  # Keep tags unchanged
125
  result.append(segment)
126
  else:
127
+ # Apply DejaVuSans to non-emoji text, emoji_font to emojis
128
  parts = []
129
  last_pos = 0
130
  for match in emoji_pattern.finditer(segment):
131
  start, end = match.span()
132
  if last_pos < start:
133
+ parts.append(f'<font face="DejaVuSans">{segment[last_pos:start]}</font>')
134
  parts.append(replace_emoji(match))
135
  last_pos = end
136
  if last_pos < len(segment):
137
+ parts.append(f'<font face="DejaVuSans">{segment[last_pos:]}</font>')
138
  result.append(''.join(parts))
139
 
140
  return ''.join(result)
 
170
 
171
  line = detect_and_convert_links(line)
172
 
173
+ # Preserve bold and emphasis formatting
174
  line = re.sub(r'\*\*(.+?)\*\*', r'<b>\1</b>', line)
175
  line = re.sub(r'\*([^*]+?)\*', r'<b>\1</b>', line)
176
 
 
231
  adjusted_font_size = int(col_width / (avg_line_chars / 10))
232
  adjusted_font_size = max(min_font_size, adjusted_font_size)
233
  item_style = ParagraphStyle(
234
+ 'ItemStyle', parent=styles['Normal'], fontName="DejaVuSans",
235
  fontSize=adjusted_font_size, leading=adjusted_font_size * 1.15, spaceAfter=1,
236
  linkUnderline=True
237
  )
 
242
  linkUnderline=True
243
  )
244
  section_style = ParagraphStyle(
245
+ 'SectionStyle', parent=styles['Heading2'], fontName="DejaVuSans",
246
  textColor=colors.darkblue, fontSize=adjusted_font_size * 1.1, leading=adjusted_font_size * 1.32, spaceAfter=2,
247
  linkUnderline=True
248
  )
 
268
  heading_style = ParagraphStyle(
269
  f'Heading{level}Style',
270
  parent=styles['Heading1'],
271
+ fontName="DejaVuSans",
272
  textColor=colors.darkblue if level == 1 else (colors.black if level > 2 else colors.blue),
273
  fontSize=adjusted_font_size * (1.6 - (level-1)*0.15),
274
  leading=adjusted_font_size * (1.8 - (level-1)*0.15),
 
279
  column_cells[col_idx].append(Paragraph(apply_emoji_font(heading_text, "NotoEmoji-Bold"), heading_style))
280
  elif item.startswith("<b>") and item.endswith("</b>"):
281
  content = item[3:-4].strip()
282
+ if number_pattern.match(content):
283
+ column_cells[col_idx].append(Paragraph(apply_emoji_font(content, "NotoEmoji-Bold"), numbered_bold_style))
284
+ else:
285
+ column_cells[col_idx].append(Paragraph(apply_emoji_font(content, "NotoEmoji-Bold"), section_style))
286
  else:
287
  column_cells[col_idx].append(Paragraph(apply_emoji_font(item, "NotoEmoji-Bold"), item_style))
288
  else: