Skip to content

fix: 수식 위첨자 baseline 배치 개선 — 분수/괄호 base (#532)#582

Closed
oksure wants to merge 1 commit intoedwardkim:develfrom
oksure:contrib/fix-eq-superscript-baseline
Closed

fix: 수식 위첨자 baseline 배치 개선 — 분수/괄호 base (#532)#582
oksure wants to merge 1 commit intoedwardkim:develfrom
oksure:contrib/fix-eq-superscript-baseline

Conversation

@oksure
Copy link
Copy Markdown
Contributor

@oksure oksure commented May 4, 2026

문제

분수형 위첨자나 괄호+분수 base에 위첨자를 붙일 때 지수가 base 기준선
아래로 렌더링됨.

재현 사례:

  • 25^{1/3}: 분수 1/3의 분모 3이 base 25 아래로 내려옴
  • (1/5)^{x-3}: 지수 x-3이 괄호 아래에 배치
  • (x^3+2)^5: 바깥 지수 5가 아래첨자처럼 배치

원인

layout_superscript()sup_shift 계산:

let sup_shift = b.baseline - s.height * 0.7;

s.height가 큰 경우 (분수형 sup) → sup_shift 음수 → 기존 코드가
sup_box.y = |sup_shift|로 위첨자를 아래로 밀어냄.

해결

sup_shift 부호에 따른 분기 정리:

  • 양수 (일반 case): sup를 상단(y=0), base를 적절히 하단 배치
  • 음수 (tall sup): sup를 상단(y=0), base를 |sup_shift|만큼 하단으로

위첨자는 항상 base보다 위에 위치하는 것이 수학 조판 규칙.

검증

  • 회귀 테스트 추가: test_superscript_fraction_baseline (sup.y ≤ base.y, sup baseline < base baseline)
  • 기존 52 equation 테스트 전체 통과
  • cargo test + cargo clippy -- -D warnings 통과

Closes #532

분수형 위첨자(25^{1/3})나 괄호로 감싼 분수에 위첨자를 붙일 때
sup_shift가 음수가 되면 위첨자가 base 아래로 밀리는 버그 수정.

기존 로직: sup_shift < 0 → sup_box.y = |sup_shift| (아래로 밀림)
수정 로직: sup_shift < 0 → sup_box.y = 0 (상단), base_box.y = |sup_shift| (base를 내림)

위첨자는 항상 base 상단 위에 위치하며, base가 필요에 따라 아래로
내려가는 것이 올바른 수학 조판 규칙.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings May 4, 2026 07:48
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

This PR adjusts the equation layout engine’s superscript vertical positioning so that tall superscripts (notably fractions) no longer render with their baselines below the base expression, addressing the baseline inversion described in #532.

Changes:

  • Refactors layout_superscript() to branch on the sign of sup_shift and shift the base instead of pushing tall superscripts downward.
  • Adds a regression unit test asserting that a fraction superscript’s baseline remains above the base baseline (25^{1/3}).

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

Comment on lines +400 to +403
// 위첨자가 base 높이 내에 들어감 — sup를 상단에, base를 아래로
sup_y = 0.0;
base_y = sup_shift.max(s.height - b.height).max(0.0);
total_h = (base_y + b.height).max(s.height);
let b = self.layout_node(base, fs);
let s = self.layout_node(sup, fs * SCRIPT_SCALE);

// sup_shift: 기준선으로부터 위첨자 상단까지의 거리 (양수 = base 상단 아래)
let s = self.layout_node(sup, fs * SCRIPT_SCALE);

// sup_shift: 기준선으로부터 위첨자 상단까지의 거리 (양수 = base 상단 아래)
let sup_shift = b.baseline - s.height * 0.7;
@edwardkim edwardkim added this to the v1.0.0 milestone May 4, 2026
@edwardkim edwardkim added the enhancement New feature or request label May 4, 2026
@edwardkim edwardkim self-requested a review May 4, 2026 08:33
@edwardkim
Copy link
Copy Markdown
Owner

메인테이너의 mydocs/manual/memory 쪽은 클로드 코드에게 컨텍스트 메모리 덤프를 지시해서 관리하고 있습니다. 메인테이너의 페르소나를 구체적으로 덤프파일로 생성시켜서 인간 지시자와 클로드 코드의 일관성있는 작업에 이용하고 있습니다. 시간될 때 한번 검토해주세요. 클로드 코드의 메모리 덤프에서 강제하고자 하는 곳은 수정 후 다시 로딩시키고 있습니다.

edwardkim added a commit that referenced this pull request May 4, 2026
cherry-pick:
- 773ac95 (391dd6d): fix: 수식 위첨자 baseline 배치 개선 — 분수/괄호 base (#532)

본질:
- src/renderer/equation/layout.rs +44/-7 (단일 파일)
- sup_shift 부호 기반 분기 정합:
  · 양수 (일반): sup 상단, base 하단
  · 음수 (tall sup, 분수형): sup 상단, base 를 |sup_shift| 만큼 하단으로
- 위첨자가 항상 base 위에 위치 (수학 조판 규칙)

검증:
- cargo test --lib 1124 passed (신규 test_superscript_fraction_baseline GREEN)
- cargo test --test issue_505/530/546/418/501 회귀 0
- cargo test --test svg_snapshot 6/6 passed
- cargo clippy --lib 0 건
- WASM 4,588,360 bytes (+2,362 from PR #562) + studio 동기화

작업지시자 시각 판정:
- "svg 와 웹 에디터 모두에서 지수 처리가 개선되었음을 메인테이너가 확인"

작성자: @oksure (Hyunwoo Park) — 두 번째 PR

closes #532

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
edwardkim added a commit that referenced this pull request May 4, 2026
…oksure 1 commit) — closes #532

본 PR 은 외부 컨트리뷰터 @oksure (Hyunwoo Park) 의 두 번째 PR.

cherry-pick:
- 773ac95 (391dd6d): src/renderer/equation/layout.rs +44/-7
  · sup_shift 부호 기반 분기 정합
  · test_superscript_fraction_baseline 신규 회귀 테스트

검증:
- cargo test --lib 1124 passed (신규 +1 GREEN)
- 회귀 0 (issue_505/530/546/418/501/svg_snapshot)
- WASM 4,588,360 bytes + rhwp-studio 동기화

작업지시자 시각 판정 (SVG + web Canvas) 통과.
@edwardkim
Copy link
Copy Markdown
Owner

@oksure 님, 두 번째 PR 도 cherry-pick 머지로 devel 에 반영했습니다 (devel `de280c4`).

머지된 commit

author 는 @oksure 으로 보존되었습니다.

검증

  • `cargo test --lib` 1124 passed (신규 `test_superscript_fraction_baseline` GREEN)
  • 회귀 0 (issue_505/530/546/418/501/svg_snapshot)
  • `cargo clippy --lib` 0 건
  • WASM 4,588,360 bytes + rhwp-studio 동기화

시각 판정 (작업지시자, SVG + web Canvas)

✅ 통과 — 작업지시자 인용:

svg 와 웹 에디터 모두에서 지수 처리가 개선되었음을 메인테이너가 확인했습니다.

분수형 위첨자 (`25^{1/3}`) / 괄호+분수 base (`(1/5)^{x-3}`) / 다중 위첨자 (`(x^3+2)^5`) 모두 정합 확인.

정합한 영역 인정

본 PR 의 정합한 영역 (PR #581 에 이어 두 번째 모범 사례):

  1. 본질 분석 정합 — `sup_shift` 부호 기반 분기 + 수학 조판 규칙 (위첨자 항상 base 위) 명시
  2. 신규 회귀 테스트 추가 — `test_superscript_fraction_baseline` (sup.y ≤ base.y, sup baseline < base baseline)
  3. 기존 52 equation 테스트 회귀 0 — 정정 영향 정밀 격리
  4. PR 본문 정합 — 결함 사례 / 원인 코드 / 정정 절차 / 검증 모두 명시
  5. 단일 파일 + 작은 변경 (+44 / -7) — 빠른 검토

컨트리뷰터께 부탁드리는 사항 — devel 동기화

PR #581 close 시 안내드린 fork devel 동기화가 본 PR 에서도 미적용 상태였습니다. base 차이로 PR diff stat 에 본 환경 최근 변경분이 "삭제" 로 표시되었지만 본 commit 의 실제 변경은 단일 파일 정합.

다음 PR 작업 전 본 환경 `devel` 동기화 부탁드립니다 — PR #581 close 댓글의 절차 참조:

```bash
git fetch upstream
git checkout devel
git pull --ff-only upstream devel
git push origin devel
git checkout -b contrib/your-next-task
```

이슈 #532 close

본 PR closes #532 명시 + 정정 적용으로 자동 close 처리 (수동 close 도 진행).

처리 보고서: `mydocs/pr/archives/pr_582_report.md`

매우 정합한 두 번째 PR 입니다.

@edwardkim edwardkim closed this May 4, 2026
edwardkim added a commit that referenced this pull request May 4, 2026
- mydocs/pr/pr_582_report.md → archives/

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
edwardkim added a commit that referenced this pull request May 4, 2026
cherry-pick:
- 21fe401 (8dc75f6): fix: 그룹 내 그림(Picture) 직렬화 구현 + 라운드트립 테스트

본질:
- src/serializer/control.rs +13/-2 (serialize_group_child Picture 분기)
- src/serializer/control/tests.rs +79 (라운드트립 테스트 신규)
- 기존 단독 Picture 직렬화와 동일 패턴 적용
  · HWPTAG_SHAPE_COMPONENT (comp_level)
  · HWPTAG_SHAPE_COMPONENT_PICTURE (type_level)
- 다른 그룹 자식 (Line/Rectangle/Ellipse/Chart/OLE) 과 동일 구조

검증:
- cargo test --lib 1125 passed (신규 test_roundtrip_group_picture_child GREEN)
- 회귀 0 (issue_505/530/546/418/501/svg_snapshot)
- cargo clippy --lib 0 건

직렬화 영역 (저장 시 누락 정정), 시각 영향 없음 — B 처리 (라운드트립 테스트로 결정적 검증).

작성자: @oksure (Hyunwoo Park) — 세 번째 PR (PR #581/#582 후속)

PR #428 후속 — Copilot 리뷰 피드백 (라운드트립 테스트 부재) 반영.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
edwardkim added a commit that referenced this pull request May 4, 2026
…commit)

본 PR 은 외부 컨트리뷰터 @oksure (Hyunwoo Park) 의 세 번째 PR (PR #581/#582 후속).

cherry-pick:
- 21fe401 (8dc75f6): fix: 그룹 내 그림(Picture) 직렬화 구현 + 라운드트립 테스트
  · src/serializer/control.rs +13/-2
  · src/serializer/control/tests.rs +79

본질: serialize_group_child 의 ShapeObject::Picture TODO 빈 분기 → 단독 Picture
직렬화와 동일 패턴 적용 (HWPTAG_SHAPE_COMPONENT + HWPTAG_SHAPE_COMPONENT_PICTURE).
PR #428 후속 (Copilot 리뷰 피드백 반영, 라운드트립 테스트 포함).

검증:
- cargo test --lib 1125 passed (신규 GREEN +1)
- test_roundtrip_group_picture_child 통과
- 회귀 0 (issue_505/530/546/418/501/svg_snapshot)
- cargo clippy --lib 0 건

작업지시자 의견 정합 (HWP 직렬화 영역, PR #553 close 시 명시).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants