Skip to content

fix: 중고딕 계열 폰트 font-weight 500 적용 (#585)#829

Open
oksure wants to merge 3 commits into
edwardkim:develfrom
oksure:contrib/font-weight-medium
Open

fix: 중고딕 계열 폰트 font-weight 500 적용 (#585)#829
oksure wants to merge 3 commits into
edwardkim:develfrom
oksure:contrib/font-weight-medium

Conversation

@oksure
Copy link
Copy Markdown
Contributor

@oksure oksure commented May 11, 2026

변경 내용

Closes #585

중고딕 계열 폰트(신명 중고딕, HY중고딕, 한양중고딕 등)가 SVG/HTML 출력 시 font-weight 속성이 누락되어, fallback 폰트가 Regular(400) weight로 매칭되는 문제를 수정합니다.

원인

HWP 문서에서 중고딕 계열 폰트(weight 500)를 사용하는 텍스트가 SVG/HTML로 렌더링될 때 font-weight CSS 속성이 생략됩니다. 해당 폰트가 설치되지 않은 환경에서 fallback 시 weight 400(Regular)으로 매칭되어 원본 대비 얇게 표시됩니다.

수정 내용

파일 변경
style_resolver.rs is_medium_weight_face() 함수 추가 — 중고딕/태고딕 계열 감지
mod.rs TextStyle::is_medium_weight() 메서드 추가 + 테스트
svg.rs 4개 렌더링 경로에 font-weight="500" 조건 추가
html.rs style.boldstyle.is_visually_bold() 변경 + medium weight 조건 추가

기존 is_visually_bold() / is_heavy_display_face() 패턴을 그대로 따르되, weight 500 계열을 별도로 분리합니다.

테스트

  • cargo test test_medium_weight_face — 중고딕/태고딕 감지 + 비해당 폰트 거부
  • cargo test 전체 통과
  • cargo clippy -- -D warnings 경고 없음

감사합니다.

Copilot AI review requested due to automatic review settings May 11, 2026 08:22
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 missing font-weight for medium-weight Gothic fonts (e.g., 신명 중고딕 / HY중고딕) in SVG/HTML output so that fallback font selection better preserves the intended stroke thickness (weight ≈ 500), addressing #585.

Changes:

  • Added medium-weight face detection (is_medium_weight_face) and exposed it via TextStyle::is_medium_weight().
  • Updated SVG and HTML renderers to emit font-weight="500" / font-weight:500 when applicable (and to use is_visually_bold() consistently).
  • Added a unit test for medium-weight face detection.

Reviewed changes

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

File Description
src/renderer/style_resolver.rs Adds medium-weight Gothic face detection helper used by renderers.
src/renderer/mod.rs Adds TextStyle::is_medium_weight() and a unit test for the new face detector.
src/renderer/svg.rs Emits font-weight="500" in multiple SVG text rendering paths when medium-weight is detected.
src/renderer/html.rs Switches bold detection to is_visually_bold() and emits font-weight:500 for medium-weight faces.

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

Comment thread src/renderer/style_resolver.rs Outdated
Comment on lines +620 to +625
let lower = primary.to_lowercase();
lower.contains("중고딕")
|| lower.contains("태고딕")
|| matches!(primary,
"HYMediumGothic" | "HYMedium"
| "HY중고딕" | "HY태고딕"
@@ -612,6 +612,22 @@ pub(crate) fn is_heavy_display_face(font_family: &str) -> bool {
)
}

Comment thread src/renderer/mod.rs
pub fn is_visually_bold(&self) -> bool {
self.bold || crate::renderer::style_resolver::is_heavy_display_face(&self.font_family)
}

Comment thread src/renderer/svg.rs
Comment on lines 229 to 233
let mut attrs = format!("font-family=\"{}\" font-size=\"{}\" fill=\"{}\" text-anchor=\"middle\" dominant-baseline=\"central\"",
escape_xml(&font_family), font_size, color);
if run.style.is_visually_bold() { attrs.push_str(" font-weight=\"bold\""); }
else if run.style.is_medium_weight() { attrs.push_str(" font-weight=\"500\""); }
if run.style.italic { attrs.push_str(" font-style=\"italic\""); }
Comment thread src/renderer/html.rs
Comment on lines +285 to 289
if style.is_visually_bold() {
css.push_str("font-weight:bold;");
} else if style.is_medium_weight() {
css.push_str("font-weight:500;");
}
@oksure
Copy link
Copy Markdown
Contributor Author

oksure commented May 11, 2026

Copilot 리뷰 반영 (2c0cb1c):

  • doc comment 추가 (is_medium_weight_face, TextStyle::is_medium_weight)
  • matches! 열거 제거 → lower.contains() 기반으로 통합 (HYMediumGothic 등 ASCII 별칭도 case-insensitive 감지)

CI 실패(issue_617_exam_kor_page5)는 로컬 devel에는 없는 테스트입니다 — 아마 local/devel에서 아직 push되지 않은 golden이 merge ref에 반영된 것으로 보입니다. 로컬에서는 모든 테스트 통과합니다.

oksure added 3 commits May 11, 2026 12:15
- is_medium_weight_face() 함수 추가: 신명 중고딕, HY중고딕, 한양중고딕 등 감지
- TextStyle.is_medium_weight() 메서드 추가
- SVG 렌더러 4개소 + HTML 렌더러 1개소에 font-weight="500" 조건 추가
- 중고딕 폰트가 fallback 시 weight 400 대신 500으로 매칭되어 선명도 개선
- 테스트 추가: test_medium_weight_face
- is_medium_weight_face() doc comment 추가
- TextStyle::is_medium_weight() rustdoc 추가
- lowercase 비교로 ASCII 별칭(HYMediumGothic 등)도 감지
- matches! 열거 제거, contains() 기반 통합
- SVG 테스트: HY중고딕 font-weight="500" 출력 검증
- HTML 테스트: HY중고딕 font-weight:500 출력 검증
- golden SVG 갱신: exam-kor-page5 (font-weight 500 적용 반영)
- Copilot 리뷰 edwardkim#4, edwardkim#5 반영
@oksure oksure force-pushed the contrib/font-weight-medium branch from 2c0cb1c to 47913ff Compare May 11, 2026 12:19
@oksure
Copy link
Copy Markdown
Contributor Author

oksure commented May 11, 2026

Copilot 리뷰 반영 + golden SVG 갱신 (47913ff):

cargo test + cargo clippy -- -D warnings ALL GREEN.

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