Skip to content

Commit 2d5313e

Browse files
committed
refactor: use getNumberingProperties directly and ParagraphFont type
Replace the second resolveRunProperties call with a direct getNumberingProperties lookup — avoids running the full style cascade just to check if numbering defines a marker font. Use ParagraphFont type alias for getLastParagraphFont return type instead of duplicating the shape inline.
1 parent 9a4fc60 commit 2d5313e

2 files changed

Lines changed: 11 additions & 21 deletions

File tree

packages/layout-engine/pm-adapter/src/attributes/paragraph.ts

Lines changed: 9 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
resolveParagraphProperties,
2828
resolveRunProperties,
2929
resolveDocxFontFamily,
30+
getNumberingProperties,
3031
type ParagraphFrameProperties,
3132
type ParagraphProperties,
3233
type RunProperties,
@@ -332,26 +333,14 @@ export const computeParagraphAttrs = (
332333
if (!hasExplicitParagraphRunProperties(paragraphProperties) && previousParagraphFont) {
333334
// Detect whether numbering explicitly overrides the marker font family
334335
// (e.g. Symbol/Wingdings). If it does, we must NOT overwrite it.
335-
const markerRunPropertiesWithoutNumbering = resolveRunProperties(
336-
converterContext!,
337-
resolvedParagraphProperties.runProperties,
338-
resolvedParagraphProperties,
339-
converterContext!.tableInfo,
340-
false,
341-
Boolean(paragraphProperties.numberingProperties),
342-
);
343-
344-
const markerFontFamilyFromNumbering = resolveDocxFontFamily(
345-
markerRunProperties.fontFamily as Record<string, unknown>,
346-
converterContext!.docx,
347-
);
348-
const markerFontFamilyWithoutNumbering = resolveDocxFontFamily(
349-
markerRunPropertiesWithoutNumbering.fontFamily as Record<string, unknown>,
350-
converterContext!.docx,
351-
);
352-
353-
const numberingDefinesMarkerFontFamily =
354-
markerFontFamilyFromNumbering != null && markerFontFamilyFromNumbering !== markerFontFamilyWithoutNumbering;
336+
const numProps = paragraphProperties.numberingProperties;
337+
const numId = numProps?.numId;
338+
const ilvl = numProps?.ilvl ?? 0;
339+
const numberingRunProps =
340+
numId != null && numId !== 0
341+
? getNumberingProperties<RunProperties>('runProperties', converterContext!, ilvl, numId)
342+
: ({} as RunProperties);
343+
const numberingDefinesMarkerFontFamily = numberingRunProps.fontFamily != null;
355344

356345
markerFontFallback = {
357346
// When numbering explicitly sets a marker font (Symbol/Wingdings), keep it.

packages/layout-engine/pm-adapter/src/converters/paragraph.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import type {
2424
ParagraphToFlowBlocksParams,
2525
BlockIdGenerator,
2626
PositionMap,
27+
ParagraphFont,
2728
} from '../types.js';
2829
import { getStableParagraphId, shiftCachedBlocks } from '../cache.js';
2930
import type { ConverterContext } from '../converter-context.js';
@@ -939,7 +940,7 @@ const SHAPE_CONVERTERS_REGISTRY: Record<
939940
* If the latest paragraph's first run has partial or empty font info, the loop continues to the previous
940941
* paragraph so callers never receive a partial object and can fall back to defaults consistently.
941942
*/
942-
export function getLastParagraphFont(blocks: FlowBlock[]): { fontFamily: string; fontSize: number } | undefined {
943+
export function getLastParagraphFont(blocks: FlowBlock[]): ParagraphFont | undefined {
943944
for (let i = blocks.length - 1; i >= 0; i--) {
944945
const block = blocks[i];
945946
if (block.kind === 'paragraph') {

0 commit comments

Comments
 (0)