Skip to content

fix: SVG 폰트 폴백 체인 — 영문 세리프 폰트명 인식 개선 (#616)#820

Open
oksure wants to merge 2 commits into
edwardkim:develfrom
oksure:contrib/font-fallback-svg
Open

fix: SVG 폰트 폴백 체인 — 영문 세리프 폰트명 인식 개선 (#616)#820
oksure wants to merge 2 commits into
edwardkim:develfrom
oksure:contrib/font-fallback-svg

Conversation

@oksure
Copy link
Copy Markdown
Contributor

@oksure oksure commented May 11, 2026

요약

generic_fallback()이 영문 세리프/고정폭 폰트명을 제대로 인식하지 못해, 폰트 미설치 환경에서 잘못된 폴백 체인이 적용되던 문제를 수정합니다.

문제

  • Noto Serif CJK SC, Liberation Serif 등 영문명에 "Serif"를 포함하는 폰트가 sans-serif 폴백을 받음
  • char_overlap 렌더링(원문자/사각형 번호)에서 generic_fallback() 대신 하드코딩된 ,sans-serif 사용

수정

변경 파일
"serif" 포함 + "sans" 미포함 → 세리프 폴백 renderer/mod.rs
"mono" 포함 → 고정폭 폴백 renderer/mod.rs
char_overlap에서 generic_fallback() 사용 renderer/svg.rs

검증

freedomofpress/dangerzone-image 샘플로 테스트:

# Before
Noto Serif CJK SC → sans-serif chain (잘못됨)
Liberation Serif   → sans-serif chain (잘못됨)

# After
Noto Serif CJK SC → Batang,바탕,Nanum Myeongjo,...,serif (올바름)
Liberation Serif   → Batang,바탕,Nanum Myeongjo,...,serif (올바름)

Ref #616

감사합니다.

- "serif"를 포함하지만 "sans"를 포함하지 않는 폰트명(Liberation Serif,
  Noto Serif CJK 등)을 세리프 폴백 체인으로 올바르게 라우팅
- "mono"를 포함하는 폰트명을 고정폭 폴백 체인으로 라우팅
- char_overlap 렌더링에서도 generic_fallback() 사용하도록 통일
  (기존: 단순 ",sans-serif" 하드코딩)

이전에는 "Noto Serif CJK SC" 같은 세리프 폰트가 sans-serif 폴백을
받아서, 폰트 미설치 환경에서 시각적 불일치가 발생했음.

Ref edwardkim#616
Copilot AI review requested due to automatic review settings May 11, 2026 06:26
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes incorrect SVG font fallback selection when the primary font name includes English keywords like “Serif” (and improves handling for “Mono”), ensuring more appropriate serif/monospace fallback chains in font-missing environments. This aligns SVG rendering behavior with the existing generic_fallback() logic rather than hardcoding ,sans-serif for char-overlap rendering.

Changes:

  • Update generic_fallback() to treat names containing serif (but not sans) as serif, and names containing mono as monospace.
  • Update SVG CharOverlap rendering to append the computed generic_fallback() chain instead of always appending sans-serif.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/renderer/svg.rs Switch CharOverlap font-family construction from hardcoded ,sans-serif to generic_fallback()-based chaining.
src/renderer/mod.rs Improve keyword detection in generic_fallback() for English serif fonts and monospace (“mono”) fonts.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/renderer/mod.rs
Comment on lines 556 to 560
if font_family.contains("굴림체") || font_family.contains("바탕체")
|| lower.contains("gulimche") || lower.contains("batangche")
|| lower.contains("coding") || lower.contains("courier")
|| lower.contains("mono")
{
Comment thread src/renderer/mod.rs Outdated
Comment on lines 573 to 578
// 세리프 키워드 (영문) — "serif" 포함 but "sans-serif" 제외
if lower.contains("times") || lower.contains("hymjre")
|| lower.contains("palatino") || lower.contains("georgia")
|| lower.contains("batang") || lower.contains("gungsuh")
|| (lower.contains("serif") && !lower.contains("sans"))
{
Copilot 리뷰 반영:
- Noto Serif CJK SC, Liberation Serif, Noto Sans Mono 등 신규 케이스 테스트 추가
- "sans" 포함 폰트가 세리프로 오분류되지 않는지 검증
- 주석을 코드 동작과 일치하도록 정정 ("sans-serif" → "sans" 부분문자열)
@oksure
Copy link
Copy Markdown
Contributor Author

oksure commented May 11, 2026

Copilot 리뷰 반영 (ec96be9):

  1. 회귀 테스트 추가: Noto Serif CJK SC, Liberation Serif, Noto Sans Mono 등 실제 이슈에서 발견된 폰트명과 Liberation Sans/Noto Sans KR(sans 계열이 세리프로 오분류되지 않는지) 테스트 케이스 추가.
  2. 주석 정정: "sans-serif 제외" → "sans 부분문자열을 가진 폰트명 전체 제외"로 코드 동작과 일치하도록 수정.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants