rhwp 0.9.1

HWP/HWPX document engine for Rust applications, WebAssembly, and CLI automation
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
//! 머리말·꼬리말 문단과 혼합 컨트롤의 배치.

use super::*;

impl LayoutEngine {
    #[allow(clippy::too_many_arguments)]
    pub(super) fn layout_header_footer_paragraphs(
        &self,
        tree: &mut PageLayoutContext,
        area_node: &mut RenderNode,
        hf_paragraphs: &[Paragraph],
        _composed: &[ComposedParagraph],
        styles: &ResolvedStyleSet,
        area: &LayoutRect,
        table_area: Option<&LayoutRect>,
        page_index: u32,
        page_number: u32,
        bin_data_content: &[BinDataContent],
        outer_section_index: Option<usize>,
        outer_hf_ref: Option<crate::renderer::render_tree::HeaderFooterImageRef>,
        is_header: bool,
        list_attr: u32,
        band_height_hu: u32,
    ) {
        // 머리말·꼬리말의 문단 장식은 본문/부모 셀의 수집 큐와 다른 소유다.
        let parent_border_ranges = std::mem::take(&mut *self.para_border_ranges.borrow_mut());
        let parent_border_override = self.border_box_override.replace(None);
        let paragraph_background_index = area_node.children.len();
        // [#6186] 머리말/꼬리말 subList 의 `vertAlign`(HWPX) = LIST_HEADER list_attr
        // 비트 21~22 (0=TOP, 1=CENTER, 2=BOTTOM). 파서는 이미 값을 싣는데
        // 레이아웃이 읽지 않아 늘 밴드 맨 위에 놓였다 — 156755659 는 BOTTOM 이라
        // 쪽번호가 21.8px 위에 붙어, 같은 자리에 겹쳐 놓인 글상자와 두 줄로 갈렸다.
        // 내용 높이를 **줄 높이 합으로 정확히 알 수 있을 때만** 정렬한다 — 표·도형·
        // 그림이 든 꼬리말은 이 합이 과소평가라 과잉 이동한다(exam_kor: 꼬리말에
        // 상자가 들어 있어 17.97px 더 내려가 한글과 멀어졌다 — 한글 A4 실측 쪽 하단
        // 82.1px 위 = A3 환산 116.2, 종전 118.5 가 맞고 변경값 100.6 은 틀림).
        // 쪽번호 같은 인라인 필드는 줄 안에서 자리를 차지하므로 줄 높이에 이미 들어
        // 있다 — 배제 대상은 **자기 높이를 갖는 개체**(표·도형·그림)뿐이다.
        let text_only_footer = !hf_paragraphs.is_empty()
            && hf_paragraphs.iter().all(|para| {
                !para.line_segs.is_empty()
                    && !para.controls.iter().any(|c| {
                        matches!(
                            c,
                            Control::Table(_) | Control::Shape(_) | Control::Picture(_)
                        )
                    })
            });
        let vert_align = if text_only_footer {
            (list_attr >> 21) & 0b11
        } else {
            0
        };
        let content_h: f64 = hf_paragraphs
            .iter()
            .filter_map(|para| para.line_segs.iter().map(|seg| seg.line_height).max())
            .map(|lh| hwpunit_to_px(lh, self.dpi))
            .sum();
        // 정렬 기준은 **문서가 선언한 밴드 높이**(HWPX subList `textHeight`)다.
        // 공유 `layout.footer_area` 는 아래 여백까지 품고 있고(그 rect 는 쪽 계산에도
        // 쓰여 건드리면 쪽수가 흔들린다 — issue_1733 등 8핀 실측), 한글의 세로 정렬은
        // 꼬리말 밴드 안에서만 일어난다. 선언값이 없으면(HWP5 등) 종전대로 area 전체.
        //
        // **선언값이 없으면(HWP5 등) 정렬을 적용하지 않는다.** `area.height` 로 물러서면
        // 밴드가 아래 여백까지 품고 있어 과잉 이동한다 — exam_kor(HWP5, A3 렌더)에서
        // 꼬리말 상자가 17.97px 더 내려가 한글과 멀어졌다(한글 A4 기준 쪽 하단에서
        // 82.1px 위 = A3 환산 116.2px; 종전 118.5px 가 맞고 변경 후 100.6px 는 틀림).
        // HWPX subList 가 `textHeight` 로 밴드를 명시할 때만 그 안에서 정렬한다.
        let slack = if band_height_hu > 0 {
            let band_h = hwpunit_to_px(band_height_hu as i32, self.dpi).min(area.height);
            (band_h - content_h).max(0.0)
        } else {
            0.0
        };
        // HWP5의 그림 혼합 footer는 저장 LINE_SEG가 footer 안 줄 grid를 완전히
        // 표현한다. `BOTTOM` subList에서 첫 줄의 vpos는 0이지만, 한컴은 첫 줄의
        // line_spacing을 footer 원점 뒤의 선행 여백으로 쓴다. 그림을 포함했다는
        // 이유만으로 text-only 정렬을 피하던 기존 경로는 이 1회 선행 여백도 버려
        // rule·로고·AutoNumber를 함께 위로 올렸다(#7333, 452 HU = 6.03px).
        //
        // 임의의 stale vpos를 원점으로 삼지 않는다. 각 문단이 정확히 한 저장 줄을
        // 가지고 vpos가 직전 줄의 height+spacing만큼 진행하며, 전체 grid가 선언한
        // subList 높이 안에 닫힐 때만 적용한다.
        let stored_mixed_footer_leading = if !text_only_footer {
            self.bottom_aligned_footer_grid_leading_px(hf_paragraphs, list_attr, band_height_hu)
        } else {
            0.0
        };
        // [#7840] 저장 줄(LINE_SEG)이 없는 머리말/꼬리말 문단도 본문·칸과 같은 줄 나눔으로
        // 줄 상자를 세운다. 줄 높이는 글자처럼 취급한 개체까지 포함한 점유 높이다 —
        // composer 의 저장 줄 부재 폴백은 글자 크기만으로 줄을 만들어, 156465345 꼬리말의
        // 49.1px 로고 셋이 12px 줄에 실렸고 BOTTOM 정렬이 그 12px 를 내용 높이로 읽어
        // 로고를 33.3px 아래로 밀었다(한/글은 밴드 위끝에 그린다). 문서 IR 은 바꾸지 않는다.
        // 위의 세로 정렬 판정은 계속 **저장** 줄만 읽는다 — 합성 줄 높이는 추정이라 그
        // 계약(줄 높이 합을 정확히 알 때만)을 채우지 못한다.
        let reflowed_hf_paragraphs: Vec<Paragraph>;
        let hf_paragraphs = if hf_paragraphs.iter().any(|para| para.line_segs.is_empty()) {
            reflowed_hf_paragraphs = hf_paragraphs
                .iter()
                .map(|para| {
                    let mut para = para.clone();
                    if para.line_segs.is_empty() {
                        let paragraph_box =
                            crate::renderer::layout_frame::ParagraphBox::content_for_style(
                                area.width,
                                styles.para_styles.get(para.para_shape_id as usize),
                                self.dpi,
                            );
                        crate::renderer::composer::reflow_line_segs(
                            &mut para,
                            paragraph_box,
                            styles,
                            self.dpi,
                        );
                    }
                    para
                })
                .collect();
            reflowed_hf_paragraphs.as_slice()
        } else {
            hf_paragraphs
        };
        let mut y_offset = area.y
            + match vert_align {
                1 => slack / 2.0,
                2 => slack,
                _ => 0.0,
            }
            + stored_mixed_footer_leading;
        let frame = self.header_footer_frame(area, is_header);
        for (i, para) in hf_paragraphs.iter().enumerate() {
            let paragraph_origin_y = y_offset;
            // 테이블 컨트롤이 있으면 테이블 렌더링
            let has_table = para.controls.iter().any(|c| matches!(c, Control::Table(_)));
            let has_shape = para.controls.iter().any(|c| matches!(c, Control::Shape(_)));
            let has_picture = para
                .controls
                .iter()
                .any(|c| matches!(c, Control::Picture(_)));
            if has_table
                && para.controls.iter().all(|control| {
                    !matches!(control, Control::Table(table) if !table.common.treat_as_char)
                })
            {
                // 글줄에 참여하는 표는 본문·각주와 같은 줄 배치 결과를 소비한다.
                // 표만 따로 배치하면 바깥여백과 같은 줄의 앞뒤 글을 잃는다.
                if let Some((plan, measured)) =
                    self.header_footer_inline_table_plan(para, i, styles, area, y_offset)
                {
                    self.layout_inline_flow_plan(
                        tree,
                        area_node,
                        para,
                        styles,
                        area,
                        outer_section_index.unwrap_or(0),
                        i,
                        bin_data_content,
                        &measured,
                        &plan,
                    );
                    y_offset = area.y + plan.end;
                } else {
                    let comp = self.compose_header_footer_paragraph(para, page_number, styles);
                    y_offset = self
                        .layout_inline_table_paragraph(
                            tree,
                            area_node,
                            para,
                            Some(&comp),
                            styles,
                            area,
                            y_offset,
                            outer_section_index.unwrap_or(0),
                            i,
                            bin_data_content,
                            &[],
                        )
                        .flow_bottom;
                }
            } else if has_table {
                for (ci, ctrl) in para.controls.iter().enumerate() {
                    if let Control::Table(t) = ctrl {
                        let alignment = styles
                            .para_styles
                            .get(para.para_shape_id as usize)
                            .map(|s| s.alignment)
                            .unwrap_or(Alignment::Left);
                        // Task #445: 꼬리말 영역의 wrap=TopAndBottom + vert=Para 표는
                        // 첫 라인의 line_height/2 만큼 아래로 anchor 됨 (HWP 가 line center
                        // 기준으로 표를 배치하는 동작과 일치). 이 보정이 없으면 페이지 번호
                        // 박스가 본문 바닥과 붙어 보이는 문제(Task #445) 발생.
                        // [Issue #924] 머릿말에서는 적용하지 않음 — 표가 header_area 안에 정확히 위치해야 함.
                        // 꼬리말은 Task #445에서 필요하므로 유지.
                        let line_anchor_offset = if !is_header
                            && matches!(
                                t.common.text_wrap,
                                crate::model::shape::TextWrap::TopAndBottom
                            )
                            && matches!(t.common.vert_rel_to, crate::model::shape::VertRelTo::Para)
                            && i == 0
                        {
                            let lh_hu = para
                                .line_segs
                                .first()
                                .map(|ls| ls.line_height as i32)
                                .unwrap_or(0);
                            hwpunit_to_px(lh_hu, self.dpi) / 2.0
                        } else {
                            0.0
                        };
                        let table_y = y_offset + line_anchor_offset;
                        let table_area = table_area.unwrap_or(area);
                        let frame_origin = self.header_footer_table_frame_origin(
                            t.as_ref(),
                            &frame,
                            paragraph_origin_y,
                        );
                        y_offset = self.layout_table(
                            tree,
                            area_node,
                            t.as_ref(),
                            0,
                            styles,
                            0,
                            table_area,
                            table_y,
                            bin_data_content,
                            None,
                            0,
                            Some((i, ci)),
                            alignment,
                            None,
                            0.0,
                            0.0,
                            None,
                            None,
                            None,
                            None,
                            false,
                            is_header,
                            0.0,
                            frame_origin,
                            Self::standalone_table_char_border_fill(Some(para), t.as_ref(), styles),
                        );
                    }
                }
            } else if has_picture {
                // Picture 컨트롤이 있는 문단
                let comp = self.compose_header_footer_paragraph(para, page_number, styles);
                if comp.tac_controls.is_empty() {
                    // 부동 그림과 일반 글자·쪽번호가 같은 머리말/꼬리말 문단에
                    // 공존할 수 있다. 그림 출력이 해당 줄의 글자 출력을 대신하지 않는다.
                    // 그림의 y 누적은 다음 그림 배치용이므로, 인라인 필드는 원래
                    // 문단 기준선(text_y)에서 따로 레이아웃한다.
                    let text_y = y_offset;
                    // 머리말/꼬리말 내 Picture: header/footer area 기준 배치
                    for (ci, ctrl) in para.controls.iter().enumerate() {
                        if let Control::Picture(pic) = ctrl {
                            if pic.common.treat_as_char {
                                let pic_container = LayoutRect {
                                    x: area.x,
                                    y: y_offset,
                                    width: area.width,
                                    height: area.height - (y_offset - area.y),
                                };
                                // [Task #825] inner para_index = i (hf_paragraphs 안 인덱스),
                                // inner control_index = ci. outer 위치는 outer_hf_ref 보존.
                                self.layout_picture_full(
                                    tree,
                                    area_node,
                                    pic,
                                    &pic_container,
                                    bin_data_content,
                                    Alignment::Left,
                                    outer_section_index,
                                    Some(i),
                                    Some(ci),
                                    outer_hf_ref.clone(),
                                    None, // [Task #1151 v4] cell_ctx: 머리말/꼬리말 path
                                    styles,
                                );
                            } else {
                                // `Paper`/`Page` 기준은 header/footer 틀을 원점으로
                                // 다시 해석하므로 para_y의 저장 grid 선행을 읽지 않는다.
                                // 완전한 BOTTOM HWP5 grid로 확인한 경우에만 그 틀 원점도
                                // 첫 줄 leading만큼 이동한다. `Para`/`Column` 그림은 이미
                                // y_offset을 쓰므로 여기서 area를 움직이면 두 번 더해진다.
                                let picture_area = if !is_header
                                    && stored_mixed_footer_leading > 0.0
                                    && matches!(
                                        pic.common.vert_rel_to,
                                        VertRelTo::Paper | VertRelTo::Page
                                    ) {
                                    LayoutRect {
                                        y: area.y + stored_mixed_footer_leading,
                                        ..*area
                                    }
                                } else {
                                    *area
                                };
                                self.layout_header_footer_picture(
                                    tree,
                                    area_node,
                                    pic,
                                    &picture_area,
                                    y_offset,
                                    bin_data_content,
                                    outer_section_index,
                                    i,
                                    ci,
                                    outer_hf_ref.clone(),
                                    styles,
                                );
                            }
                            let pic_h = hwpunit_to_px(pic.common.height as i32, self.dpi);
                            y_offset += pic_h;
                        }
                    }
                    let has_page_auto_number = para.controls.iter().any(|ctrl| {
                        matches!(
                            ctrl,
                            Control::AutoNumber(number)
                                if matches!(
                                    number.number_type,
                                    crate::model::control::AutoNumberType::Page
                                        | crate::model::control::AutoNumberType::TotalPage
                                )
                        )
                    });
                    if has_page_auto_number || para_has_visible_text(para) {
                        let text_end = self.layout_paragraph(
                            tree,
                            area_node,
                            para,
                            Some(&comp),
                            styles,
                            area,
                            text_y,
                            0,
                            usize::MAX - i,
                            None,
                            None,
                            None,
                        );
                        y_offset = y_offset.max(text_end);
                    }
                } else {
                    // TAC Picture: layout_paragraph에서 인라인 배치
                    y_offset = self.layout_paragraph(
                        tree,
                        area_node,
                        para,
                        Some(&comp),
                        styles,
                        area,
                        y_offset,
                        0,
                        usize::MAX - i,
                        None,
                        Some(bin_data_content),
                        None, // 머리말/꼬리말 컨텍스트 — wrap zone 무관
                    );
                }
            } else if has_shape {
                // [#5802] 글자처럼 취급(TAC) 도형은 paragraph_layout 이 inline 좌표를
                // 등록해야 layout_shape 가 그린다 — 미등록 TAC 는 #476 가드가 조용히
                // 스킵한다. 머리말/꼬리말 문단은 종전에 layout_shape 만 불러, 쪽번호
                // 묶음처럼 TAC 도형으로 저장된 내용이 통째로 소실됐다(611쪽 보고서
                // 꼬리말 전량). 본문 등록 키와 충돌하지 않게 구역 인덱스는 HF 전용
                // 센티널(usize::MAX)을 등록·조회 양쪽에 쓴다.
                let has_tac_shape = para
                    .controls
                    .iter()
                    .any(|c| matches!(c, Control::Shape(s) if s.common().treat_as_char));
                let hf_shape_section = usize::MAX;
                if has_tac_shape {
                    let comp = self.compose_header_footer_paragraph(para, page_number, styles);
                    self.layout_paragraph(
                        tree,
                        area_node,
                        para,
                        Some(&comp),
                        styles,
                        area,
                        y_offset,
                        hf_shape_section,
                        i,
                        None,
                        Some(bin_data_content),
                        None,
                    );
                }
                // Shape 컨트롤 렌더링 (머리말/꼬리말 내 글상자 등)
                // 머리말·꼬리말의 Paper/Page 개체도 이 틀 안에서 오프셋을 잰다.
                // 그림의 배치 계약과 같으며, 본문의 물리 용지 원점을 전달하면
                // Paper-Left/Right 글상자가 본문 여백 밖으로 이동한다.
                // 꼬리말 틀의 높이는 꼬리말 여백이다(`header_footer_frame`) — `area` 는
                // 아래 여백까지 품어 아래 정렬 글상자가 쪽 맨 아래로 내려갔다.
                for (ci, ctrl) in para.controls.iter().enumerate() {
                    if let Control::Shape(_) = ctrl {
                        self.layout_shape(
                            tree,
                            area_node,
                            hf_paragraphs,
                            i,
                            ci,
                            if has_tac_shape { hf_shape_section } else { 0 },
                            styles,
                            area,
                            &frame,
                            &frame,
                            y_offset,
                            Alignment::Left,
                            bin_data_content,
                            &std::collections::HashMap::new(),
                            is_header,
                            None,
                        );
                    }
                }
                // 텍스트도 함께 렌더링 (TAC 도형 경로는 위에서 이미 문단을 레이아웃함)
                if !has_tac_shape && !para.text.is_empty() {
                    let comp = self.compose_header_footer_paragraph(para, page_number, styles);
                    y_offset = self.layout_paragraph(
                        tree,
                        area_node,
                        para,
                        Some(&comp),
                        styles,
                        area,
                        y_offset,
                        0,
                        usize::MAX - i,
                        None,
                        None,
                        None, // 머리말/꼬리말 컨텍스트 — wrap zone 무관
                    );
                }
            } else {
                // 일반 텍스트 문단 레이아웃 (필드 마커 치환 포함)
                let comp = self.compose_header_footer_paragraph(para, page_number, styles);
                y_offset = self.layout_paragraph(
                    tree,
                    area_node,
                    para,
                    Some(&comp),
                    styles,
                    area,
                    y_offset,
                    0,
                    usize::MAX - i,
                    None,
                    None,
                    None, // 머리말/꼬리말 컨텍스트 — wrap zone 무관
                );
            }
            // 표/그림과 함께 있는 부동 도형도 같은 머리말·꼬리말 문단의 컨트롤이다.
            // 표 전진 뒤의 커서를 새 앵커로 쓰지 않고 원래 문단 원점을 소비한다.
            if has_shape && (has_table || has_picture) {
                for (ci, control) in para.controls.iter().enumerate() {
                    if matches!(control, Control::Shape(shape) if !shape.common().treat_as_char) {
                        self.layout_shape(
                            tree,
                            area_node,
                            hf_paragraphs,
                            i,
                            ci,
                            0,
                            styles,
                            area,
                            &frame,
                            &frame,
                            paragraph_origin_y,
                            Alignment::Left,
                            bin_data_content,
                            &std::collections::HashMap::new(),
                            is_header,
                            None,
                        );
                    }
                }
            }
            // 한컴은 머리말·꼬리말 틀을 넘친 문단도 본문 위에 겹쳐 그린다. 넘친 문단을 버리지 않는다.
        }
        let local_composed: Vec<_> = hf_paragraphs
            .iter()
            .map(|para| self.compose_header_footer_paragraph(para, page_number, styles))
            .collect();
        // 이미지 편집 주소의 센티널은 유지하고 장식 연결의 문단 번호만 로컬화한다.
        for range in self.para_border_ranges.borrow_mut().iter_mut() {
            if let Some(index) = usize::MAX
                .checked_sub(range.9)
                .filter(|index| *index < hf_paragraphs.len())
            {
                range.9 = index;
            }
        }
        self.render_para_border_groups(
            tree,
            &local_composed,
            area_node,
            styles,
            area,
            bin_data_content,
            paragraph_background_index,
        );
        *self.para_border_ranges.borrow_mut() = parent_border_ranges;
        self.border_box_override.set(parent_border_override);
    }

    /// 저장 줄이 없는 TAC 표는 본문과 같은 상자·줄 소속·점유 결과를 사용한다.
    /// 글자용 합성 기준선으로 표 상단을 다시 추측하지 않는다. 필드 치환과
    /// 그림·도형의 머리말 전용 주소는 각자의 기존 소비 경로에 남긴다.
    fn header_footer_inline_table_plan(
        &self,
        para: &Paragraph,
        para_index: usize,
        styles: &ResolvedStyleSet,
        area: &LayoutRect,
        y: f64,
    ) -> Option<(
        crate::renderer::inline_flow::InlineFlowPlan,
        Vec<MeasuredTable>,
    )> {
        if !crate::renderer::para_has_no_stored_line_segs(para)
            || para
                .text
                .chars()
                .any(|ch| matches!(ch, '\u{0015}' | '\u{0016}' | '\u{0017}'))
            || !para.controls.iter().all(|control| {
                matches!(control, Control::Table(table) if table.common.treat_as_char)
                    || matches!(
                        control,
                        Control::SectionDef(_)
                            | Control::ColumnDef(_)
                            | Control::PageNumberPos(_)
                            | Control::PageNumCtrl(_)
                    )
            })
        {
            return None;
        }
        let style = styles.para_styles.get(para.para_shape_id as usize)?;
        let profile = self.profile.get();
        let measurer = crate::renderer::height_measurer::HeightMeasurer::new(self.dpi)
            .with_stored_geometry_policy(profile.stored_geometry_policy())
            .with_native_hwp5(profile.hwp5_stored_pagination_layout())
            .with_hwpx_stored_layout(profile.hwpx_stored_layout())
            .with_session_edited(profile.session_edited());
        let measured: Vec<_> = para
            .controls
            .iter()
            .enumerate()
            .filter_map(|(index, control)| match control {
                Control::Table(table) => {
                    Some(measurer.measure_table(table, para_index, index, styles))
                }
                _ => None,
            })
            .collect();
        let container = LayoutRect {
            x: area.x + style.margin_left,
            width: area.width - style.margin_left - style.margin_right,
            ..*area
        };
        let (body_x, body_y, body_width, body_height) = self.current_body_area.get();
        let body = LayoutRect {
            x: body_x,
            y: body_y,
            width: body_width,
            height: body_height,
        };
        let paper = LayoutRect {
            x: 0.0,
            y: 0.0,
            width: self.current_paper_width.get(),
            height: self.current_page_height.get(),
        };
        let frame = crate::renderer::float_placement::ObjectPlacementFrame {
            container: &container,
            column: area,
            body: &body,
            paper: &paper,
            paragraph_y: y,
            alignment: style.alignment,
            dpi: self.dpi,
        };
        let mut plan =
            crate::renderer::inline_flow::plan(para, para_index, styles, &measured, &frame, &[])?;
        plan.relative_to(area.x, area.y);
        Some((plan, measured))
    }

    /// 머리말·꼬리말 안 용지·쪽 기준 개체를 재는 틀.
    ///
    /// 한/글은 머리말·꼬리말에 놓인 개체의 용지·쪽 기준 오프셋을 물리 용지나 본문
    /// 영역이 아니라 그 머리말·꼬리말 틀에서 잰다(그림은 #6608). 틀은 본문 왼쪽 끝·
    /// 본문 폭, 세로는 머리말이면 위 여백에서 머리말 여백까지, 꼬리말이면 본문
    /// 아래끝에서 꼬리말 여백까지다.
    ///
    /// `footer_area` 는 본문 아래끝부터 아래 여백까지 품는다(쪽 계산이 쓰는 rect 라
    /// 그대로 둔다). 꼬리말 틀의 높이는 `build_footer` 의 `margin_footer` 와 같은
    /// 관용구로 되찾는다 — 아래 정렬 개체가 아래 여백 끝까지 내려가지 않게.
    pub(super) fn header_footer_frame(&self, area: &LayoutRect, is_header: bool) -> LayoutRect {
        if is_header {
            return *area;
        }
        let page_height = self.current_page_height.get();
        if page_height <= 0.0 {
            return *area;
        }
        LayoutRect {
            height: (page_height - (area.y + area.height)).max(0.0),
            ..*area
        }
    }

    /// 머리말·꼬리말에 직접 놓인 용지·쪽 기준 부동 표의 원점 `(x, 위끝)`.
    ///
    /// `layout_table` 은 이 표를 본문 표처럼 용지 원점에서 재어, 위 여백만큼 위로
    /// 올린 머리말 표(용지 기준 세로 −위 여백)를 쪽 위로 내보내 잘랐고, 꼬리말 표는
    /// 쪽 맨 위(용지)·본문 위끝(쪽)·용지 오른쪽 아래 구석(아래·오른쪽 정렬)에 그렸다.
    /// 한/글 2024 PDF 실측: 글앞으로·자리차지·글뒤로·어울림 넷 모두 틀 원점이다.
    /// 정렬과 바깥 여백은 본문의 쪽·종이 기준 표와 같은 식이고(가로
    /// `compute_table_x_position`, 세로 `absolute_table_vertical_geometry`) 기준만
    /// `header_footer_frame` 이다. 문단·단 기준 가로는 종전 경로가 이미 머리말·꼬리말
    /// 영역(`table_area`) 안에서 풀므로 `None` 으로 남긴다.
    pub(super) fn header_footer_table_frame_origin(
        &self,
        table: &crate::model::table::Table,
        frame: &LayoutRect,
        paragraph_y: f64,
    ) -> Option<(Option<f64>, f64)> {
        if !table.common.treat_as_char
            && table.common.vert_rel_to == VertRelTo::Para
            && table.common.vert_align == VertAlign::Top
            && table.common.text_wrap == TextWrap::TopAndBottom
            && table.common.flow_with_text
        {
            // 본문 수용 계획이 없는 머리말·꼬리말도 문단 원점에서 바깥 상자를 연다.
            // 가로 여백은 compute_table_x_position이 소비하므로 다시 더하지 않는다.
            let lead =
                crate::renderer::float_placement::topbottom_flow_vertical_offset_hu(&table.common);
            return Some((
                None,
                paragraph_y + hwpunit_to_px(lead + i32::from(table.outer_margin_top), self.dpi),
            ));
        }
        if table.common.treat_as_char
            || !matches!(table.common.vert_rel_to, VertRelTo::Paper | VertRelTo::Page)
        {
            return None;
        }
        let width = hwpunit_to_px(signed_hwpunit(table.common.width).max(0), self.dpi);
        let height = hwpunit_to_px(signed_hwpunit(table.common.height).max(0), self.dpi);
        let x = match table.common.horz_rel_to {
            HorzRelTo::Paper | HorzRelTo::Page => {
                let h_offset =
                    hwpunit_to_px(signed_hwpunit(table.common.horizontal_offset), self.dpi);
                let slack = (frame.width - width).max(0.0);
                Some(match table.common.horz_align {
                    HorzAlign::Left | HorzAlign::Inside => frame.x + h_offset,
                    HorzAlign::Center => frame.x + slack / 2.0 + h_offset,
                    HorzAlign::Right | HorzAlign::Outside => frame.x + slack - h_offset,
                })
            }
            HorzRelTo::Column | HorzRelTo::Para => None,
        };
        let (top, _) = crate::renderer::float_placement::absolute_table_vertical_geometry(
            table,
            frame.y,
            frame.height,
            height,
            self.dpi,
        );
        Some((x, top))
    }
}