@cj-tech-master/excelts 6.1.2 → 6.1.3-canary.20260326221818.c209bdf
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/modules/excel/stream/workbook-writer.browser.js +1 -1
- package/dist/browser/modules/excel/utils/font-data.d.ts +90 -0
- package/dist/browser/modules/excel/utils/font-data.js +719 -0
- package/dist/browser/modules/excel/utils/text-metrics.d.ts +137 -0
- package/dist/browser/modules/excel/utils/text-metrics.js +504 -0
- package/dist/browser/modules/excel/worksheet.d.ts +34 -0
- package/dist/browser/modules/excel/worksheet.js +236 -1
- package/dist/cjs/modules/excel/stream/workbook-writer.browser.js +1 -1
- package/dist/cjs/modules/excel/utils/font-data.js +729 -0
- package/dist/cjs/modules/excel/utils/text-metrics.js +520 -0
- package/dist/cjs/modules/excel/worksheet.js +236 -1
- package/dist/esm/modules/excel/stream/workbook-writer.browser.js +1 -1
- package/dist/esm/modules/excel/utils/font-data.js +719 -0
- package/dist/esm/modules/excel/utils/text-metrics.js +504 -0
- package/dist/esm/modules/excel/worksheet.js +236 -1
- package/dist/iife/excelts.iife.js +4563 -3
- package/dist/iife/excelts.iife.js.map +1 -1
- package/dist/iife/excelts.iife.min.js +34 -34
- package/dist/types/modules/excel/utils/font-data.d.ts +90 -0
- package/dist/types/modules/excel/utils/text-metrics.d.ts +137 -0
- package/dist/types/modules/excel/worksheet.d.ts +34 -0
- package/package.json +1 -1
|
@@ -49,7 +49,7 @@ export class WorkbookWriterBase {
|
|
|
49
49
|
this._worksheets = [];
|
|
50
50
|
this.views = [];
|
|
51
51
|
this.zipOptions = options.zip;
|
|
52
|
-
const level = options.zip?.zlib?.level ?? options.zip?.compressionOptions?.level ??
|
|
52
|
+
const level = options.zip?.zlib?.level ?? options.zip?.compressionOptions?.level ?? 6;
|
|
53
53
|
this.compressionLevel = Math.max(0, Math.min(9, level));
|
|
54
54
|
this.media = [];
|
|
55
55
|
this.commentRefs = [];
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Font metric data for auto-fit column width and row height calculation.
|
|
3
|
+
*
|
|
4
|
+
* ## Architecture
|
|
5
|
+
*
|
|
6
|
+
* This module provides font advance width data at three precision tiers:
|
|
7
|
+
*
|
|
8
|
+
* **Tier 1 (Bitmap-accurate):** Calibri 11pt pixel widths, verified against
|
|
9
|
+
* Excel's actual bitmap metrics (EBDT table). These values match
|
|
10
|
+
* ClosedXML and rust_xlsxwriter measurements exactly.
|
|
11
|
+
*
|
|
12
|
+
* **Tier 2 (FUnit-accurate):** Per-character advance widths in font design units
|
|
13
|
+
* (FUnits) extracted from TTF hmtx tables for Calibri and 8 other common fonts.
|
|
14
|
+
* At runtime, pixel widths are calculated via:
|
|
15
|
+
* `pixelWidth = ROUND(advanceFU / unitsPerEm * ROUND(fontSize / 72 * 96))`
|
|
16
|
+
* This matches Excel's outline rendering for all sizes except Calibri 11pt
|
|
17
|
+
* (where bitmap metrics differ from outline).
|
|
18
|
+
*
|
|
19
|
+
* **Tier 3 (Factor-based):** For ~230 other fonts, per-category average width
|
|
20
|
+
* factors (lowercase, uppercase, wide) from excelize's experimentally-tuned table.
|
|
21
|
+
*
|
|
22
|
+
* ## Key References
|
|
23
|
+
*
|
|
24
|
+
* - ClosedXML Cell Dimensions wiki: https://github.com/closedxml/closedxml/wiki/Cell-Dimensions
|
|
25
|
+
* - rust_xlsxwriter utility.rs pixel_width()
|
|
26
|
+
* - excelize templates.go supportedFontWidthFactors
|
|
27
|
+
* - ECMA-376 §18.3.1.13 (col element, width attribute)
|
|
28
|
+
*/
|
|
29
|
+
/** Calibri Regular 11pt per-character pixel widths (code point -> pixels) */
|
|
30
|
+
declare const CALIBRI_11PT_PX: Record<number, number>;
|
|
31
|
+
/** Font metrics header: unitsPerEm, usWinAscent, usWinDescent, maxDigitAdvance, sTypoAscender, sTypoDescender, sTypoLineGap */
|
|
32
|
+
export interface FontMetricsHeader {
|
|
33
|
+
unitsPerEm: number;
|
|
34
|
+
usWinAscent: number;
|
|
35
|
+
usWinDescent: number;
|
|
36
|
+
maxDigitAdvance: number;
|
|
37
|
+
sTypoAscender: number;
|
|
38
|
+
sTypoDescender: number;
|
|
39
|
+
sTypoLineGap: number;
|
|
40
|
+
}
|
|
41
|
+
/** Run-length encoded advance data: [startCodePoint, count, advanceFU] */
|
|
42
|
+
export type AdvanceRun = [start: number, count: number, advance: number];
|
|
43
|
+
export interface FontMetrics {
|
|
44
|
+
header: FontMetricsHeader;
|
|
45
|
+
/** Default advance for characters not in the table (typically Latin average) */
|
|
46
|
+
defaultAdvance: number;
|
|
47
|
+
/** Advance width for CJK ideographs (U+4E00..U+9FFF) */
|
|
48
|
+
cjkAdvance: number;
|
|
49
|
+
/** Run-length encoded advance data */
|
|
50
|
+
advances: AdvanceRun[];
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Get FUnit metrics for a font by name, optionally bold variant.
|
|
54
|
+
* Returns undefined if no FUnit data is available (falls back to Tier 3).
|
|
55
|
+
* When bold is true and no bold-specific metrics exist, returns the regular variant.
|
|
56
|
+
*/
|
|
57
|
+
export declare function getFontMetrics(fontName: string, bold?: boolean): FontMetrics | undefined;
|
|
58
|
+
/**
|
|
59
|
+
* Check if a font has a dedicated bold metrics table.
|
|
60
|
+
* When false, the bold multiplier (1.05) should be applied to width calculations.
|
|
61
|
+
*/
|
|
62
|
+
export declare function hasBoldMetrics(fontName: string): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Get the Calibri Regular metrics (default font).
|
|
65
|
+
*/
|
|
66
|
+
export declare function getDefaultFontMetrics(): FontMetrics;
|
|
67
|
+
/**
|
|
68
|
+
* Get the advance width of a character in FUnits for a given font.
|
|
69
|
+
* Returns the font's defaultAdvance if the character is not in the table.
|
|
70
|
+
*
|
|
71
|
+
* For CJK Unified Ideographs (U+4E00..U+9FFF, U+3400..U+4DBF, U+F900..U+FAFF),
|
|
72
|
+
* returns the font's cjkAdvance.
|
|
73
|
+
*/
|
|
74
|
+
export declare function getCharAdvance(metrics: FontMetrics, codePoint: number): number;
|
|
75
|
+
/**
|
|
76
|
+
* Get the Calibri 11pt bitmap pixel width for a character.
|
|
77
|
+
* Returns undefined if not in the bitmap table.
|
|
78
|
+
*/
|
|
79
|
+
export declare function getCalibri11PtPixelWidth(codePoint: number): number | undefined;
|
|
80
|
+
/**
|
|
81
|
+
* Get Tier 3 font width factors [lowercase, uppercase, wide] for a font.
|
|
82
|
+
* Returns undefined if no factors are available.
|
|
83
|
+
*/
|
|
84
|
+
export declare function getFontWidthFactors(fontName: string): [number, number, number] | undefined;
|
|
85
|
+
/**
|
|
86
|
+
* Check if a code point is an East Asian wide/fullwidth character.
|
|
87
|
+
* This replaces golang.org/x/text/width from excelize.
|
|
88
|
+
*/
|
|
89
|
+
export declare function isWideCharacter(codePoint: number): boolean;
|
|
90
|
+
export { CALIBRI_11PT_PX };
|