diff --git a/docs/ENGINES.md b/docs/ENGINES.md
index 7969aedab..873cd222d 100644
--- a/docs/ENGINES.md
+++ b/docs/ENGINES.md
@@ -27,7 +27,7 @@ Filee chooses engines automatically. Settings → *Engines* shows their status,
| PDF slides | built in (PDFium, PdfPig) | **PDF → PPTX**: a picture of each page on its own slide (looks like the PDF, not editable), the page's text in the speaker notes |
| PDF tables | built in (PdfPig) | **PDF → XLSX, ODS, CSV** (#267): each table drawn with lines on its own sheet, numbers and dates as real values, merged cells and column widths kept |
| **PostScript writer** | built in | **PDF → PS (LanguageLevel 3), EPS** (one per page) without Ghostscript: vectors, text with its embedded fonts, pictures, shadings, patterns; pages with transparency as pictures (see [PDF → PostScript and EPS](#pdf--postscript-and-eps)) |
-| Document tables | built in | **DOCX (+ DOCM/DOTX/DOTM), HTML, MHTML → XLSX, ODS, CSV** (#1016): each table on its own sheet, numbers and dates as real values, merged cells, borders and column widths kept |
+| Document tables | built in | **DOCX (+ DOCM/DOTX/DOTM), DOC (+ DOT/WPS), ODT, RTF, HWP, HWPX, HTML, MHTML → XLSX, ODS, CSV** (#1016): each table on its own sheet, numbers and dates as real values, merged cells, borders, fill, alignment and column widths kept |
| E-mail | built in (MimeKit, MsgReader) | **EML, Outlook MSG → HTML** (headers + body, inline pictures), **TXT**, **ZIP** (the attachments); **MSG → EML**; **MHTML → HTML** (the saved page in one file, pictures inlined; on to PDF, DOCX, HWPX, TXT, Markdown, EPUB from there) |
| Signed files | built in (System.Security.Cryptography.Pkcs) | **P7M → the signed file inside** (CMS / PKCS #7, CAdES: Italian e-invoices `*.xml.p7m`, signed PDFs `*.pdf.p7m`), then on from its format (P7M → PDF → JPG); the signature isn't checked |
| Data | built in (System.Text.Json, YamlDotNet, Tomlyn, System.Xml) | **JSON, JSON Lines, YAML, TOML, XML, CSV ↔ each other** (CSV for tables); **vCard, iCalendar ↔ CSV**; **property lists (.plist, XML and binary) → each of them and TXT**; FreeMASTER oscilloscope TXT → CSV; spreadsheets, contacts and events reach JSON / YAML / TOML / XML through CSV |
@@ -828,8 +828,20 @@ so DOCX → HWPX and HWP keep editable equations and DOCX → PDF draws them wit
The box an equation is stored with (`hp:sz`) is measured like rhwp lays the script out (estimated character
widths, script scale 0.7, fraction and root spacing, from rhwp's `equation/layout.rs`): rhwp stretches an equation to
its stored width, so a wrong box would distort it. 한글 lays the script out again when the equation is edited.
-The model's other writers (HTML, EPUB, Markdown, TXT …) write a linear form instead, `(a+b)/(2c)`, `x_i^2`, `√(x)`,
-which is also the equation's alternative text in HWPX.
+The model's other writers (Markdown, TXT, ODT, PPTX …) write a linear form instead, `(a+b)/(2c)`, `x_i^2`, `√(x)`,
+which is also the equation's alternative text in HWPX. The DOCX writer writes every equation back as Word math
+(`Hwp/Hwpx/Docx/OmmlWriter.cs`), the HTML and EPUB writers as MathML (`Hwp/Hwpx/MathMLWriter.cs`; EPUB pages with it
+carry `properties="mathml"`; MOBI keeps the text).
+
+**TeX math in Markdown** (#1652): `$…$`, `$$…$$`, `\(…\)` and `\[…\]` (`Hwp/Hwpx/MarkdownMath.cs`, Pandoc's rules
+for dollars: no space inside the delimiters, no digit after the closing `$`, code spans win) are read by
+`Hwp/Hwpx/LatexMath.cs` into the same tree: fractions, roots, scripts, Greek letters and symbols, sums, integrals and
+`\lim` with their limits, `\left … \right`, matrices, `cases`, `aligned` and `gather`, accents, `\text`, `\mathbf`,
+`\mathrm`, `\mathbb` and the spacing commands. So Markdown → PDF typesets them, → DOCX gives Word math, → HWPX 한글
+equations, → HTML and EPUB MathML (with the TeX as its annotation). Display math alone in its paragraph is centred.
+An unknown command stays as its text (`\foo`); a formula longer than 32,768 characters or nested deeper than 100
+levels stays its source, and the equations count against `MaxObjects`. Writers without equations keep the TeX
+source as written (`$\frac{a}{b}$`).
## Spreadsheets
@@ -863,8 +875,8 @@ the text the spreadsheet shows, the value behind it and its Excel number format.
The XLSX donut also offers **PDF + Edit** (`tool-sheet-studio`). This interactive tool preserves the original
workbook, makes one disposable copy per selected sheet region, applies that region's print settings, and prints it
with the same engine as an ordinary XLSX → PDF: Filee's own print engine (below), or LibreOffice when **Use
-LibreOffice for spreadsheets → PDF** is on and it is installed (and, as in a conversion, for a workbook with charts or
-other objects the print engine doesn't draw yet; without LibreOffice the studio shows the printer's notice). Every
+LibreOffice for spreadsheets → PDF** is on and it is installed (and, as in a conversion, for a workbook with chart
+sheets, 3D charts or other objects the print engine doesn't draw yet; without LibreOffice the studio shows the printer's notice). Every
studio setting (paper, orientation, margins, scale or fit to pages, page order, print area, hidden rows and columns,
manual breaks, sheet choice) is written into the copy and read by the print engine; the sheet's own gridlines,
headings, centring and headers / footers are kept. PDFsharp combines the resulting PDFs. The live preview follows
@@ -944,7 +956,10 @@ services (FontResolver with font fallback, the HarfBuzz shaper, the UAX #14 line
Each sheet's page count is checked against `MaxPages` before anything is drawn (a cell in A1 and one in
XFD1048576 would be about 35 million pages), and the layout runs under `LayoutGuard`. `DocumentFuzzTests` mutates
an XLSX and an ODS built in code and prints them.
-- **Not printed yet.** Charts, shapes, text boxes, comments, sparklines; data bars, icon sets and conditional formats
+- **Charts** (bar, column, line, area, pie, doughnut, scatter) on a sheet are printed from their chart part by the
+ [chart drawer](#charts); 3D, radar, stock, surface and bubble charts, new chart types (`chartex`) and chart sheets
+ are named, so such a workbook takes LibreOffice where it is installed.
+- **Not printed yet.** Chart sheets, shapes with text, text boxes, comments, sparklines; data bars, icon sets and conditional formats
with formulas of their own; conditional formats of XLS and ODS files; rich text in XLS cells; text running past the
edge of a page onto the next one; black-and-white and draft printing; the margins a real printer can't print in
(a PDF has none).
@@ -1053,9 +1068,9 @@ test turns it on.
were always off by default and are left as the user set them. Tests: `FileeRendererConverterTests`
(`Libreoffice_chosen_for_*`), `RoutePlannerTests` (the costs).
- **The check before converting** (`ConversionEdge.Checked`, `ICapabilityCheck`): the engine looks through an HWPX, Word
- or ODT package (an HWP as the HWPX package it becomes, a DOC as the DOCX package it becomes) for what it doesn't draw yet — OLE objects and charts, vertical
- text, form controls, videos, SmartArt — and a deck for what the slide renderer doesn't draw (charts without a
- stored picture, shadows and other effects, 3D, WordArt warps, presets it lacks, ...) — and `JobQueue` plans again
+ or ODT package (an HWP as the HWPX package it becomes, a DOC as the DOCX package it becomes) for what it doesn't draw yet — OLE objects, charts
+ other than the DrawingML ones the [chart drawer](#charts) draws, vertical text, form controls, videos, SmartArt — and a deck for what the slide
+ renderer doesn't draw (charts the chart drawer doesn't draw without a stored picture, shadows and other effects, 3D, WordArt warps, presets it lacks, ...) — and `JobQueue` plans again
without it, so such a file takes its usual route (logged). The choice is made once, before the conversion. A checked edge is only ever a route's first step, where the
file is the one the engine looked at. Text formats hold nothing it can't draw.
- Its edges aren't `Unshaped`: with it on, Arabic, Hebrew, Indic and Thai documents are shaped by it instead of
@@ -1540,8 +1555,8 @@ a slide.
fonts (`+mj-lt`, `+mn-ea`, script fonts by the run's language); theme style references (`fillRef`, `lnRef`,
`fontRef`, `bgRef`); tables with `tableStyles.xml` styles (PowerPoint's default *Medium Style 2 – Accent 1* is built
in, as files often name it without writing it out); SmartArt through the drawing PowerPoint keeps with it (the data
- part's `dsp:dataModelExt`); OLE objects and charts through their stored picture; `mc:AlternateContent` through its
- fallback.
+ part's `dsp:dataModelExt`); charts from their chart part ([Charts](#charts)); OLE objects and other charts through
+ their stored picture; `mc:AlternateContent` through its fallback.
- **Text frames:** insets, the geometry's text rectangle, anchoring (top, middle, bottom, centred across),
wrapping on or off, columns, vertical frames (`vert`, `vert270`), the body's own rotation; "shrink text on overflow"
with the font scale and line spacing reduction PowerPoint stored; line spacing as a multiple of the fonts' own line
@@ -1573,7 +1588,7 @@ a slide.
- **Pictures of slides:** the PDF options' page range and resolution (`RenderDpi`, lowered so one picture stays within
200 million pixels), then the image options (`ImageEncoder.ApplyOptions`), one file per slide (`_p2`, ...).
- **The check** (`SlideCapabilities.cs`) looks at the shown slides and the layouts and masters they use, leaving out
- what a fallback replaces, and names: charts without a stored picture, SmartArt without its drawing, OLE objects and
+ what a fallback replaces, and names: charts the chart drawer doesn't draw without a stored picture, SmartArt without its drawing, OLE objects and
other embedded content without a picture, ink, shadows and other effects (on shapes, pictures and text, or through
the theme's effect styles), 3D, WordArt warps, outlined text, East Asian vertical text, preset names outside
ST_ShapeType, and TIFF and JPEG XR pictures.
@@ -1596,7 +1611,37 @@ Every slide's text reads back, nothing is outside a slide, every font is embedde
Not yet: shadows, glow, reflection, soft edges and 3D (named by the check); WordArt warps and text outlines; East Asian
vertical text (upright characters); gradient-filled text (the first stop's colour); tiled pictures at their own
resolution (taken as 96 dpi); a gradient that doesn't turn with its shape; "rect" path gradients (drawn as an ellipse
-through the corners); charts drawn from their data; notes pages and handouts.
+through the corners); 3D and other charts the chart drawer doesn't draw; notes pages and handouts.
+
+## Charts
+
+`Charts/` reads a DrawingML chart part (`c:chartSpace`, ECMA-376 Part 1 §21.2) and draws it with Skia, text as glyph
+runs, for the sheet printer (`XlsxDrawing`, XLSX and XLSB), the document renderer (Word `c:chart` through
+`DocxReader` and `FloatingObjects`) and the slide renderer (`PptxSlideReader`, `SlideRenderer`).
+
+- **Read** (`ChartReader`): bar and column (clustered, stacked, 100 %, horizontal), line (markers, smooth, stacked),
+ area, pie (first slice angle, pulled-out slices), doughnut and scatter plots, several in one plot area against
+ their own axes; values and categories from the part's caches (`c:numCache`, `c:strCache`, `c:multiLvlStrCache`,
+ literals), so no formula is evaluated; title (rich text, a cell's text, or the lone series' name Office shows),
+ axis titles, category / date / value axes (scaling, logarithmic base, orientation, number format, gridlines, tick
+ marks, label position, crossing, label skip and turn), legend (position, deleted entries), data labels (value,
+ category, series, percent, position), fills and outlines of the chart area, plot area, series and points (solid,
+ first colour of a gradient or pattern, none), the theme's accents in Office's order (then darker and lighter
+ variations), manual layouts of plot area, title and legend.
+- **Drawn** (`ChartDrawer`): Office's automatic layout (title on top, legend on its side, axes' labels and titles
+ around the plot); value axes scale as Excel's (zero kept unless the values sit far from it, 1-2-5 units for the
+ axis' length, a little room above the top value); category labels level, wrapped at spaces, turned 45° or thinned
+ out. Writers that take pictures get a PNG of the chart (`ChartPicture`): the Word chart's picture in HWPX, ODT,
+ EPUB, ...; the slide's picture in ODP and in a deck's text.
+- **Named instead** (the left-out notice says "charts"; the checks send the file to LibreOffice where it is
+ installed): 3D, radar, bubble, stock, surface and bar-of-pie charts and new chart types (`chartex`); a fallback
+ picture, when the file stores one, is drawn for those on slides.
+- **Hostile input:** the part comes through the package's XML limits; more than 1,024 series or 1,048,576 points per
+ chart (a cache's `ptCount` or highest index counts, not only the points it holds) is refused with
+ `error.document_too_complex`, as is a document whose charts draw more than ten times that (`ChartBudget`, a chart
+ placed many times counting each time); texts are cut at 1,024 characters, values clamped to ±1e100, data labels
+ (4,096), markers (100,000), measured category labels (2,000) and ticks per axis (1,000) capped. `ChartTests` builds
+ the charts in code; `ChartFuzzTests` mutates chart parts alone and in a printed workbook.
## DOCX writer
@@ -2225,26 +2270,35 @@ not found.
workbook. The same tables can be written as ODS, or as CSV (one file per sheet). These edges are direct only: an image
made into a PDF has no ruled tables, so no picture reaches a spreadsheet through PDF.
-## DOCX / HTML → XLSX
+## Documents → XLSX
-`Office/DocumentTablesConverter.cs` puts the tables of a Word document (DOCX and its DOCM / DOTX / DOTM variants), a web
-page (HTML) or a saved web page (MHTML) into a workbook (#1016). The tables are the ones the DOCX and HTML readers give
-the HWPX and DOCX writers, with their merged cells (`gridSpan` / `vMerge`, `colspan` / `rowspan`); text outside the
-tables is left out. The cells are written as in PDF → XLSX (`Office/Sheets/TableSheets.cs`, shared by both).
+`Office/DocumentTablesConverter.cs` puts the tables of a Word document (DOCX and its DOCM / DOTX / DOTM variants, DOC
+and its DOT / WPS variants), an OpenDocument text (ODT), an RTF file, a 한글 file (HWP, HWPX), a web page (HTML) or a
+saved web page (MHTML) into a workbook (#1016). The tables are the ones the built-in readers give the HWPX and DOCX
+writers, with their merged cells (`gridSpan` / `vMerge`, DOC's merge flags, `number-columns-spanned` /
+`number-rows-spanned`, `\clmgf` / `\clvmgf`, 한글's `cellSpan`, `colspan` / `rowspan`); text outside the tables is left
+out. The cells are written as in PDF → XLSX (`Office/Sheets/TableSheets.cs`, shared by both).
- **One sheet per table** ("Table 1", "Table 2" …) in reading order, a table inside a cell too (its text isn't repeated
in the outer cell). Nothing is joined: a Word table running over a page break is one table already. A table without
any text, such as a web page's layout table around the real one, gets no sheet.
-- **Numbers and dates** become real values by the same rules as PDF → XLSX (above).
+- **Numbers and dates** become real values by the same rules as PDF → XLSX (above). 한글 files are read as the renderer
+ reads them, so a number typed as an equation (common in 한글 tables) is its text ("40"), not its script ("40~~~").
- Cells keep their own borders (a Word table style's lines, the HTML grid unless `border="0"`), shading, vertical
- alignment and bold. Column widths come from the Word grid or the HTML `
` / first-row widths (shares of an A4
- text width); without either, a column is as wide as its longest line, up to 60 characters. Rows fit their text: a
- Word row height is only a minimum. Leading header rows (Word's "repeat as header row", HTML `` or rows of
- ``) are frozen.
+ alignment, bold and italic (when all the cell's text is), and centred or right alignment (when all its paragraphs
+ are; left and justified text keeps Excel's own, numbers to the right). Column widths come from the document's grid
+ (Word, DOC, RTF, ODT, 한글) or the HTML `` / first-row widths (shares of an A4 text width); without either, a
+ column is as wide as its longest line, up to 60 characters. Rows fit their text: a document's row height is only a
+ minimum. Excel doesn't fit a row to a merged cell, so the rows under a merged cell get the height its lines need.
+ Leading header rows (Word's and RTF's "repeat as header row", ODT header rows, 한글's title cells, HTML `` or
+ rows of ``) are frozen.
- A file without tables fails with `error.document_no_tables`. The edges are direct only, like PDF → XLSX: a PDF,
a picture or an e-book that became a DOCX on the way doesn't reach spreadsheets this way, and a document's tables
- don't go on to JSON or XML. For the same reason DOC (which LibreOffice reads into a DOCX first) isn't an input: the
- XLSX preset's note says to convert it to DOCX first.
+ don't go on to JSON or XML. DOC edges are checked: a Word 6.0 / 95 or Works file the DOC reader doesn't read gets
+ the reader's own message (LibreOffice has no Writer → spreadsheet route to fall back on).
+- Limits: the tables of one file get at most 10,000 sheets, 1,048,576 rows each (Excel's) and 10,000,000 cell
+ positions together (`HwpxWriter.MaxTableCells`), counted before anything is written; more is refused with
+ `error.document_too_complex`. Nested tables are walked with a stack, not recursion.
## PDF → PPTX
diff --git a/src/Filee.App/Assets/i18n/ar.json b/src/Filee.App/Assets/i18n/ar.json
index b190e5a2d..94d98dafe 100644
--- a/src/Filee.App/Assets/i18n/ar.json
+++ b/src/Filee.App/Assets/i18n/ar.json
@@ -298,7 +298,7 @@
"engine.pdf-ps.name": "كاتب PostScript (مدمج)",
"engine.pdf-ps.description": "يحوّل ملفات PDF إلى PostScript وEPS دون Ghostscript: يحتفظ النص بخطوطه وتبقى الرسوم متجهة. الصفحات التي فيها شفافية تصبح صورًا.",
"engine.document-tables.name": "Document tables (built-in)",
- "engine.document-tables.description": "يحوّل جداول مستندات Word (DOCX) وصفحات الويب (HTML وMHTML) إلى مصنف Excel، لكل جدول ورقة، مع الأرقام والتواريخ كقيم حقيقية.",
+ "engine.document-tables.description": "يحوّل جداول المستندات (DOCX, DOC, ODT, RTF, HWP, HWPX) وصفحات الويب (HTML وMHTML) إلى مصنف Excel، لكل جدول ورقة، مع الأرقام والتواريخ كقيم حقيقية.",
"engine.email.name": "E-mail (built-in)",
"engine.email.description": "تحويل رسائل البريد (EML وOutlook MSG) إلى HTML ونص مع المرسل والمستلمين والتاريخ والصور، وتجميع المرفقات في ZIP.\nتحويل MSG إلى EML، وصفحات الويب المحفوظة (MHTML) إلى ملف HTML واحد مع صورها.",
"engine.p7m.name": "Signed files (built-in)",
@@ -1115,7 +1115,7 @@
"presets.split_minutes": "دقائق لكل جزء",
"presets.video_parts_hint": "يُنسخ كما هو دون إعادة ترميز، لذا لا تنطبق إعدادات الجودة والحجم والترميز. ينتهي كل جزء عند إطار رئيسي، لذا قد يطول بضع ثوانٍ عمّا طُلب.",
"presets.pdf_tables_note": "من ملف PDF يصبح كل جدول مرسوم بخطوط ورقة مستقلة (ويبقى الجدول الممتد إلى الصفحة التالية ورقة واحدة)، وتصبح الأرقام والتواريخ قيمًا حقيقية. يُترك النص خارج الجداول.",
- "presets.document_tables_note": "من مستند Word (DOCX) أو صفحة ويب (HTML) يصبح كل جدول ورقة مستقلة، وتصبح الأرقام والتواريخ قيمًا حقيقية. يُترك النص خارج الجداول. حوّل ملف DOC إلى DOCX أولًا.",
+ "presets.document_tables_note": "من مستند (DOCX, DOC, ODT, RTF, HWP, HWPX) أو صفحة ويب (HTML) يصبح كل جدول ورقة مستقلة، وتصبح الأرقام والتواريخ قيمًا حقيقية. يُترك النص خارج الجداول.",
"presets.pdf_compression": "الضغط",
"presets.pdf_compression.None": "دون ضغط",
"presets.pdf_compression.Screen": "أصغر حجم (الصور بدقة 72 dpi)",
diff --git a/src/Filee.App/Assets/i18n/bn-BD.json b/src/Filee.App/Assets/i18n/bn-BD.json
index c5989b448..4793168df 100644
--- a/src/Filee.App/Assets/i18n/bn-BD.json
+++ b/src/Filee.App/Assets/i18n/bn-BD.json
@@ -312,7 +312,7 @@
"engine.pdf-ps.name": "PostScript রাইটার (বিল্ট-ইন)",
"engine.pdf-ps.description": "Ghostscript ছাড়াই পিডিএফকে PostScript ও EPS-এ রূপান্তর করে: লেখা তার ফন্ট রাখে, অঙ্কন ভেক্টর থাকে। স্বচ্ছতা থাকা পৃষ্ঠাগুলো ছবি হয়ে যায়।",
"engine.document-tables.name": "ডকুমেন্ট সারণি (বিল্ট-ইন)",
- "engine.document-tables.description": "ওয়ার্ড ডকুমেন্ট (DOCX) ও ওয়েব পেজের (HTML, MHTML) সারণিগুলোকে এক্সেল ওয়ার্কবুকে পরিণত করে, প্রতিটির জন্য একটি শিট, যেখানে সংখ্যা এবং তারিখগুলো প্রকৃত মান হিসেবে থাকে।",
+ "engine.document-tables.description": "ডকুমেন্ট (DOCX, DOC, ODT, RTF, HWP, HWPX) ও ওয়েব পেজের (HTML, MHTML) সারণিগুলোকে এক্সেল ওয়ার্কবুকে পরিণত করে, প্রতিটির জন্য একটি শিট, যেখানে সংখ্যা এবং তারিখগুলো প্রকৃত মান হিসেবে থাকে।",
"engine.email.name": "ই-মেইল (বিল্ট-ইন)",
"engine.email.description": "ই-মেইল (EML, Outlook MSG) থেকে প্রেরক, প্রাপক ও তারিখসহ এইচটিএমএল এবং টেক্সটে রূপান্তর, ছবিসহ; সংযুক্ত ফাইলগুলো একটি ZIP-এ।\nMSG থেকে EML। সংরক্ষিত ওয়েব পেজ (Mএইচটিএমএল) ছবিসহ একটি একক এইচটিএমএল ফাইলে।",
"engine.p7m.name": "স্বাক্ষরিত ফাইল (বিল্ট-ইন)",
@@ -1114,7 +1114,7 @@
"presets.split_minutes": "মিনিট প্রতি ভাগ",
"presets.video_parts_hint": "আবার এনকোড না করে যেমন আছে তেমন কপি হয়, তাই কোয়ালিটি, সাইজ আর কোডেকের সেটিং খাটে না। প্রতিটি ভাগ একটি কী ফ্রেমে শেষ হয়, তাই চাওয়ার চেয়ে কয়েক সেকেন্ড লম্বা হতে পারে।",
"presets.pdf_tables_note": "একটি পিডিএফ থেকে রেখা দিয়ে আঁকা প্রতিটি সারণি নিজস্ব শিট হয়ে যায় (পরবর্তী পৃষ্ঠায় বিস্তৃত সারণি একটি একক শিটেই থাকে), যেখানে সংখ্যা ও তারিখ প্রকৃত মান হিসেবে থাকে। সারণির বাইরের টেক্সট বাদ দেওয়া হয়।",
- "presets.document_tables_note": "একটি ওয়ার্ড ডকুমেন্ট (DOCX) বা ওয়েব পেজ (HTML) থেকে প্রতিটি সারণি নিজস্ব শিট হয়ে যায়, যেখানে সংখ্যা ও তারিখ প্রকৃত মান হিসেবে থাকে। সারণির বাইরের টেক্সট বাদ দেওয়া হয়। DOC ফাইল আগে DOCX-এ রূপান্তর করুন।",
+ "presets.document_tables_note": "একটি ডকুমেন্ট (DOCX, DOC, ODT, RTF, HWP, HWPX) বা ওয়েব পেজ (HTML) থেকে প্রতিটি সারণি নিজস্ব শিট হয়ে যায়, যেখানে সংখ্যা ও তারিখ প্রকৃত মান হিসেবে থাকে। সারণির বাইরের টেক্সট বাদ দেওয়া হয়।",
"presets.pdf_compression": "সংকোচন (কম্প্রেশন)",
"presets.pdf_compression.None": "সংকুচিত করবেন না",
"presets.pdf_compression.Screen": "সবচেয়ে ছোট (৭২ dpi-তে ছবি)",
diff --git a/src/Filee.App/Assets/i18n/de.json b/src/Filee.App/Assets/i18n/de.json
index c36f41e20..b51797dec 100644
--- a/src/Filee.App/Assets/i18n/de.json
+++ b/src/Filee.App/Assets/i18n/de.json
@@ -298,7 +298,7 @@
"engine.pdf-ps.name": "PostScript-Writer (integriert)",
"engine.pdf-ps.description": "Wandelt PDFs ohne Ghostscript in PostScript und EPS um: Text behält seine Schriften, Zeichnungen bleiben Vektoren. Seiten mit Transparenz werden zu Bildern.",
"engine.document-tables.name": "Dokumenttabellen (integriert)",
- "engine.document-tables.description": "Überträgt die Tabellen aus Word-Dokumenten (DOCX) und Webseiten (HTML, MHTML) in eine Excel-Arbeitsmappe, jeweils auf ein eigenes Blatt. Zahlen und Datumsangaben bleiben echte Werte.",
+ "engine.document-tables.description": "Überträgt die Tabellen aus Dokumenten (DOCX, DOC, ODT, RTF, HWP, HWPX) und Webseiten (HTML, MHTML) in eine Excel-Arbeitsmappe, jeweils auf ein eigenes Blatt. Zahlen und Datumsangaben bleiben echte Werte.",
"engine.email.name": "E-Mail (integriert)",
"engine.email.description": "E-Mails (EML, Outlook MSG) in HTML und Text mit Absender, Empfängern, Datum und Bildern; Anhänge in eine ZIP-Datei.\nMSG in EML. Gespeicherte Webseiten (MHTML) in eine HTML-Datei mit ihren Bildern.",
"engine.p7m.name": "Signierte Dateien (integriert)",
@@ -1115,7 +1115,7 @@
"presets.split_minutes": "Minuten pro Teil",
"presets.video_parts_hint": "Wird unverändert kopiert, ohne neu zu kodieren: Qualität, Größe und Codec gelten hier nicht. Jeder Teil endet an einem Schlüsselbild und kann daher ein paar Sekunden länger sein als gewählt.",
"presets.pdf_tables_note": "Jede Tabelle mit eingezeichneten Linien in einer PDF wird zu einem eigenen Tabellenblatt. Eine über mehrere Seiten fortgesetzte Tabelle bleibt auf einem Blatt. Zahlen und Datumsangaben bleiben echte Werte. Text außerhalb der Tabellen wird weggelassen.",
- "presets.document_tables_note": "Jede Tabelle in einem Word-Dokument (DOCX) oder einer Webseite (HTML) wird zu einem eigenen Tabellenblatt. Zahlen und Datumsangaben bleiben echte Werte. Text außerhalb der Tabellen wird weggelassen. Eine DOC-Datei zuerst in DOCX umwandeln.",
+ "presets.document_tables_note": "Jede Tabelle in einem Dokument (DOCX, DOC, ODT, RTF, HWP, HWPX) oder einer Webseite (HTML) wird zu einem eigenen Tabellenblatt. Zahlen und Datumsangaben bleiben echte Werte. Text außerhalb der Tabellen wird weggelassen.",
"presets.pdf_compression": "Komprimieren",
"presets.pdf_compression.None": "Nicht komprimieren",
"presets.pdf_compression.Screen": "Kleinste Datei (Bilder mit 72 dpi)",
diff --git a/src/Filee.App/Assets/i18n/en.json b/src/Filee.App/Assets/i18n/en.json
index b37832e4a..c2abcf181 100644
--- a/src/Filee.App/Assets/i18n/en.json
+++ b/src/Filee.App/Assets/i18n/en.json
@@ -305,7 +305,7 @@
"engine.pdf-ps.name": "PostScript writer (built-in)",
"engine.pdf-ps.description": "Turns PDFs into PostScript and EPS without Ghostscript: text keeps its fonts, drawings stay vector. Pages with transparency become pictures.",
"engine.document-tables.name": "Document tables (built-in)",
- "engine.document-tables.description": "Turns the tables of Word documents (DOCX) and web pages (HTML, MHTML) into an Excel workbook, one sheet each, with numbers and dates as real values.",
+ "engine.document-tables.description": "Turns the tables of documents (DOCX, DOC, ODT, RTF, HWP, HWPX) and web pages (HTML, MHTML) into an Excel workbook, one sheet each, with numbers and dates as real values.",
"engine.email.name": "E-mail (built-in)",
"engine.email.description": "E-mails (EML, Outlook MSG) to HTML and text with sender, recipients and date, pictures included; attachments into a ZIP.\nMSG to EML. Saved web pages (MHTML) to one HTML file with their pictures.",
"engine.p7m.name": "Signed files (built-in)",
@@ -1130,7 +1130,7 @@
"presets.split_minutes": "minutes per part",
"presets.video_parts_hint": "Copied as it is, without encoding again, so the quality, size and codec settings don't apply. Each part ends at a key frame, so it can run a few seconds longer than asked.",
"presets.pdf_tables_note": "From a PDF, each table drawn with lines becomes its own sheet (a table that goes on over the next page stays one sheet), with numbers and dates as real values. Text outside the tables is left out.",
- "presets.document_tables_note": "From a Word document (DOCX) or a web page (HTML), each table becomes its own sheet, with numbers and dates as real values. Text outside the tables is left out. Convert a DOC file to DOCX first.",
+ "presets.document_tables_note": "From a document (DOCX, DOC, ODT, RTF, HWP, HWPX) or a web page (HTML), each table becomes its own sheet, with numbers and dates as real values. Text outside the tables is left out.",
"presets.pdf_compression": "Compress",
"presets.pdf_compression.None": "Don't compress",
"presets.pdf_compression.Screen": "Smallest (pictures at 72 dpi)",
diff --git a/src/Filee.App/Assets/i18n/es.json b/src/Filee.App/Assets/i18n/es.json
index 08816e86e..460a757b8 100644
--- a/src/Filee.App/Assets/i18n/es.json
+++ b/src/Filee.App/Assets/i18n/es.json
@@ -298,7 +298,7 @@
"engine.pdf-ps.name": "Generador PostScript (integrado)",
"engine.pdf-ps.description": "Convierte PDF en PostScript y EPS sin Ghostscript: el texto conserva sus fuentes y los dibujos siguen siendo vectoriales. Las páginas con transparencias se convierten en imágenes.",
"engine.document-tables.name": "Document tables (built-in)",
- "engine.document-tables.description": "Convierte las tablas de documentos de Word (DOCX) y páginas web (HTML, MHTML) en un libro de Excel, una hoja por tabla, con números y fechas como valores reales.",
+ "engine.document-tables.description": "Convierte las tablas de documentos (DOCX, DOC, ODT, RTF, HWP, HWPX) y páginas web (HTML, MHTML) en un libro de Excel, una hoja por tabla, con números y fechas como valores reales.",
"engine.email.name": "E-mail (built-in)",
"engine.email.description": "Correos electrónicos (EML, Outlook MSG) a HTML y texto con remitente, destinatarios y fecha, imágenes incluidas; los adjuntos van a un ZIP.\nMSG a EML. Páginas web guardadas (MHTML) a un solo archivo HTML con sus imágenes.",
"engine.p7m.name": "Signed files (built-in)",
@@ -1115,7 +1115,7 @@
"presets.split_minutes": "minutos por parte",
"presets.video_parts_hint": "Se copia tal cual, sin volver a codificar, así que la calidad, el tamaño y el códec no se aplican. Cada parte termina en un fotograma clave, por lo que puede durar unos segundos más de lo pedido.",
"presets.pdf_tables_note": "De un PDF, cada tabla dibujada con líneas pasa a su propia hoja (una tabla que sigue en la página siguiente queda en una sola hoja), con números y fechas como valores reales. El texto fuera de las tablas se omite.",
- "presets.document_tables_note": "De un documento de Word (DOCX) o una página web (HTML), cada tabla pasa a su propia hoja, con números y fechas como valores reales. El texto fuera de las tablas se omite. Convierte primero un archivo DOC a DOCX.",
+ "presets.document_tables_note": "De un documento (DOCX, DOC, ODT, RTF, HWP, HWPX) o una página web (HTML), cada tabla pasa a su propia hoja, con números y fechas como valores reales. El texto fuera de las tablas se omite.",
"presets.pdf_compression": "Comprimir",
"presets.pdf_compression.None": "No comprimir",
"presets.pdf_compression.Screen": "El más pequeño (imágenes a 72 ppp)",
diff --git a/src/Filee.App/Assets/i18n/fa.json b/src/Filee.App/Assets/i18n/fa.json
index c109d2bf6..7f0aec436 100644
--- a/src/Filee.App/Assets/i18n/fa.json
+++ b/src/Filee.App/Assets/i18n/fa.json
@@ -312,7 +312,7 @@
"engine.pdf-ps.name": "نویسنده PostScript (داخلی)",
"engine.pdf-ps.description": "بدون Ghostscript فایلهای PDF را به PostScript و EPS تبدیل میکند: متن قلمهای خود را نگه میدارد و طرحها وکتور میمانند. صفحههای دارای شفافیت به تصویر تبدیل میشوند.",
"engine.document-tables.name": "جداول سند (داخلی)",
- "engine.document-tables.description": "تبدیل جداول اسناد Word (DOCX) و صفحات وب (HTML، MHTML) به کارپوشه Excel، هر جدول در یک برگه، همراه با اعداد و تاریخها به عنوان مقادیر واقعی.",
+ "engine.document-tables.description": "تبدیل جداول اسناد (DOCX, DOC, ODT, RTF, HWP, HWPX) و صفحات وب (HTML، MHTML) به کارپوشه Excel، هر جدول در یک برگه، همراه با اعداد و تاریخها به عنوان مقادیر واقعی.",
"engine.email.name": "ایمیل (داخلی)",
"engine.email.description": "تبدیل ایمیلها (EML، Outlook MSG) به HTML و متن با مشخصات فرستنده، گیرندگان و تاریخ، شامل تصاویر؛ پیوستها در یک فایل ZIP قرار میگیرند.\nتبدیل MSG به EML. صفحات وب ذخیرهشده (MHTML) به یک فایل HTML با تصاویر آنها.",
"engine.p7m.name": "فایلهای امضاشده (داخلی)",
@@ -1114,7 +1114,7 @@
"presets.split_minutes": "دقیقه در هر بخش",
"presets.video_parts_hint": "بدون رمزگذاری دوباره و همانطور که هست کپی میشود، پس تنظیمات کیفیت، اندازه و کدک اعمال نمیشوند. هر بخش روی یک فریم کلیدی تمام میشود، پس ممکن است چند ثانیه بلندتر از مقدار خواستهشده باشد.",
"presets.pdf_tables_note": "از یک فایل PDF، هر جدول کشیدهشده با خطوط به یک برگه مجزا تبدیل میشود (جدولی که تا صفحه بعد ادامه دارد به صورت یک برگه میماند)، با اعداد و تاریخها به عنوان مقادیر واقعی. متن خارج از جدولها نادیده گرفته میشود.",
- "presets.document_tables_note": "از یک سند Word (DOCX) یا یک صفحه وب (HTML)، هر جدول به یک برگه مجزا تبدیل میشود، با اعداد و تاریخها به عنوان مقادیر واقعی. متن خارج از جدولها نادیده گرفته میشود. فایل DOC را ابتدا به DOCX تبدیل کنید.",
+ "presets.document_tables_note": "از یک سند (DOCX, DOC, ODT, RTF, HWP, HWPX) یا یک صفحه وب (HTML)، هر جدول به یک برگه مجزا تبدیل میشود، با اعداد و تاریخها به عنوان مقادیر واقعی. متن خارج از جدولها نادیده گرفته میشود.",
"presets.pdf_compression": "فشردهسازی تصاویر PDF",
"presets.pdf_compression.None": "بدون تغییر (حفظ کیفیت)",
"presets.pdf_compression.Screen": "مناسب نمایش روی صفحه (کوچکترین اندازه)",
diff --git a/src/Filee.App/Assets/i18n/fr.json b/src/Filee.App/Assets/i18n/fr.json
index 2e3d07f7e..138df6b6a 100644
--- a/src/Filee.App/Assets/i18n/fr.json
+++ b/src/Filee.App/Assets/i18n/fr.json
@@ -305,7 +305,7 @@
"engine.pdf-ps.name": "Générateur PostScript (intégré)",
"engine.pdf-ps.description": "Convertit les PDF en PostScript et EPS sans Ghostscript : le texte garde ses polices, les dessins restent vectoriels. Les pages avec de la transparence deviennent des images.",
"engine.document-tables.name": "Document tables (built-in)",
- "engine.document-tables.description": "Transforme les tableaux des documents Word (DOCX) et des pages web (HTML, MHTML) en classeur Excel, une feuille par tableau, avec les nombres et les dates en vraies valeurs.",
+ "engine.document-tables.description": "Transforme les tableaux des documents (DOCX, DOC, ODT, RTF, HWP, HWPX) et des pages web (HTML, MHTML) en classeur Excel, une feuille par tableau, avec les nombres et les dates en vraies valeurs.",
"engine.email.name": "E-mail (built-in)",
"engine.email.description": "E-mails (EML, MSG Outlook) en HTML et texte avec expéditeur, destinataires et date, images comprises ; pièces jointes dans un ZIP.\nMSG en EML. Pages web enregistrées (MHTML) en un seul fichier HTML avec leurs images.",
"engine.p7m.name": "Signed files (built-in)",
@@ -1130,7 +1130,7 @@
"presets.split_minutes": "minutes par partie",
"presets.video_parts_hint": "Copiée telle quelle, sans réencodage : la qualité, la taille et le codec ne s'appliquent pas. Chaque partie se termine sur une image clé et peut donc durer quelques secondes de plus que demandé.",
"presets.pdf_tables_note": "D'un PDF, chaque tableau tracé avec des lignes devient une feuille (un tableau qui continue sur la page suivante reste une seule feuille), avec les nombres et les dates en vraies valeurs. Le texte hors des tableaux est omis.",
- "presets.document_tables_note": "D'un document Word (DOCX) ou d'une page web (HTML), chaque tableau devient une feuille, avec les nombres et les dates en vraies valeurs. Le texte hors des tableaux est omis. Convertissez d'abord un fichier DOC en DOCX.",
+ "presets.document_tables_note": "D'un document (DOCX, DOC, ODT, RTF, HWP, HWPX) ou d'une page web (HTML), chaque tableau devient une feuille, avec les nombres et les dates en vraies valeurs. Le texte hors des tableaux est omis.",
"presets.pdf_compression": "Compresser",
"presets.pdf_compression.None": "Ne pas compresser",
"presets.pdf_compression.Screen": "Le plus léger (images à 72 ppp)",
diff --git a/src/Filee.App/Assets/i18n/hi.json b/src/Filee.App/Assets/i18n/hi.json
index ef80cd11b..e8b621698 100644
--- a/src/Filee.App/Assets/i18n/hi.json
+++ b/src/Filee.App/Assets/i18n/hi.json
@@ -298,7 +298,7 @@
"engine.pdf-ps.name": "PostScript लेखक (अंतर्निहित)",
"engine.pdf-ps.description": "Ghostscript के बिना PDF को PostScript और EPS में बदलता है: टेक्स्ट अपने फ़ॉन्ट रखता है, चित्र वेक्टर रहते हैं। पारदर्शिता वाले पेज चित्र बन जाते हैं।",
"engine.document-tables.name": "Document tables (built-in)",
- "engine.document-tables.description": "Word दस्तावेज़ों (DOCX) और वेब पेजों (HTML, MHTML) की तालिकाओं को Excel वर्कबुक में बदलता है, हर तालिका एक शीट, संख्याओं और तारीखों को असली मानों के रूप में।",
+ "engine.document-tables.description": "दस्तावेज़ों (DOCX, DOC, ODT, RTF, HWP, HWPX) और वेब पेजों (HTML, MHTML) की तालिकाओं को Excel वर्कबुक में बदलता है, हर तालिका एक शीट, संख्याओं और तारीखों को असली मानों के रूप में।",
"engine.email.name": "E-mail (built-in)",
"engine.email.description": "ई-मेल (EML, Outlook MSG) को भेजने वाले, प्राप्तकर्ताओं और तारीख के साथ HTML और टेक्स्ट में बदलता है, तस्वीरों सहित; अटैचमेंट ZIP में।\nMSG से EML। सहेजे गए वेब पेज (MHTML) उनकी तस्वीरों सहित एक HTML फ़ाइल में।",
"engine.p7m.name": "Signed files (built-in)",
@@ -1115,7 +1115,7 @@
"presets.split_minutes": "मिनट प्रति हिस्सा",
"presets.video_parts_hint": "बिना दोबारा एन्कोड किए जैसा है वैसा कॉपी होता है, इसलिए क्वालिटी, साइज़ और कोडेक की सेटिंग लागू नहीं होतीं। हर हिस्सा किसी की फ़्रेम पर खत्म होता है, इसलिए वह तय समय से कुछ सेकंड लंबा हो सकता है।",
"presets.pdf_tables_note": "PDF से, रेखाओं से बनी हर तालिका अपनी अलग शीट बनती है (अगले पेज पर जारी तालिका एक ही शीट रहती है), और संख्याएँ व तारीखें असली मान बनती हैं। तालिकाओं के बाहर का टेक्स्ट छोड़ दिया जाता है।",
- "presets.document_tables_note": "Word दस्तावेज़ (DOCX) या वेब पेज (HTML) से, हर तालिका अपनी अलग शीट बनती है, और संख्याएँ व तारीखें असली मान बनती हैं। तालिकाओं के बाहर का टेक्स्ट छोड़ दिया जाता है। DOC फ़ाइल को पहले DOCX में बदलें।",
+ "presets.document_tables_note": "दस्तावेज़ (DOCX, DOC, ODT, RTF, HWP, HWPX) या वेब पेज (HTML) से, हर तालिका अपनी अलग शीट बनती है, और संख्याएँ व तारीखें असली मान बनती हैं। तालिकाओं के बाहर का टेक्स्ट छोड़ दिया जाता है।",
"presets.pdf_compression": "कंप्रेस करें",
"presets.pdf_compression.None": "कंप्रेस न करें",
"presets.pdf_compression.Screen": "सबसे छोटा (तस्वीरें 72 dpi पर)",
diff --git a/src/Filee.App/Assets/i18n/id.json b/src/Filee.App/Assets/i18n/id.json
index 9332026c8..d85557e2e 100644
--- a/src/Filee.App/Assets/i18n/id.json
+++ b/src/Filee.App/Assets/i18n/id.json
@@ -298,7 +298,7 @@
"engine.pdf-ps.name": "Penulis PostScript (bawaan)",
"engine.pdf-ps.description": "Mengubah PDF menjadi PostScript dan EPS tanpa Ghostscript: teks tetap memakai fontnya, gambar tetap vektor. Halaman dengan transparansi menjadi gambar.",
"engine.document-tables.name": "Tabel dokumen (bawaan)",
- "engine.document-tables.description": "Mengubah tabel dalam dokumen Word (DOCX) dan halaman web (HTML, MHTML) menjadi buku kerja Excel, masing-masing tabel satu lembar, dengan angka dan tanggal sebagai nilai data asli.",
+ "engine.document-tables.description": "Mengubah tabel dalam dokumen (DOCX, DOC, ODT, RTF, HWP, HWPX) dan halaman web (HTML, MHTML) menjadi buku kerja Excel, masing-masing tabel satu lembar, dengan angka dan tanggal sebagai nilai data asli.",
"engine.email.name": "Email (bawaan)",
"engine.email.description": "Email (EML, Outlook MSG) ke HTML dan teks dengan pengirim, penerima, tanggal, serta gambar terlampir; lampiran ke file ZIP.\nMSG ke EML. Halaman web tersimpan (MHTML) menjadi satu file HTML beserta gambarnya.",
"engine.p7m.name": "File bertanda tangan (bawaan)",
@@ -1115,7 +1115,7 @@
"presets.split_minutes": "menit per bagian",
"presets.video_parts_hint": "Disalin apa adanya tanpa encode ulang, jadi pengaturan kualitas, ukuran, dan codec tidak berlaku. Setiap bagian berakhir di key frame, jadi bisa beberapa detik lebih panjang dari yang diminta.",
"presets.pdf_tables_note": "Dari sebuah PDF, setiap tabel yang digambar dengan garis pembatas menjadi lembar tersendiri (tabel yang berlanjut ke halaman berikutnya tetap menjadi satu lembar), dengan angka dan tanggal sebagai nilai asli. Teks di luar tabel diabaikan.",
- "presets.document_tables_note": "Dari dokumen Word (DOCX) atau halaman web (HTML), setiap tabel menjadi lembar tersendiri, dengan angka dan tanggal sebagai nilai asli. Teks di luar tabel diabaikan. Ubah file DOC ke DOCX terlebih dahulu.",
+ "presets.document_tables_note": "Dari dokumen (DOCX, DOC, ODT, RTF, HWP, HWPX) atau halaman web (HTML), setiap tabel menjadi lembar tersendiri, dengan angka dan tanggal sebagai nilai asli. Teks di luar tabel diabaikan.",
"presets.pdf_compression": "Kompresi",
"presets.pdf_compression.None": "Jangan kompres",
"presets.pdf_compression.Screen": "Terkecil (gambar 72 dpi)",
diff --git a/src/Filee.App/Assets/i18n/it.json b/src/Filee.App/Assets/i18n/it.json
index e1cf5b01e..f96dacd3b 100644
--- a/src/Filee.App/Assets/i18n/it.json
+++ b/src/Filee.App/Assets/i18n/it.json
@@ -297,7 +297,7 @@
"engine.pdf-ps.name": "Writer PostScript (integrato)",
"engine.pdf-ps.description": "Converte i PDF in PostScript ed EPS senza Ghostscript: il testo mantiene i suoi font, i disegni restano vettoriali. Le pagine con trasparenze diventano immagini.",
"engine.document-tables.name": "Tabelle dei documenti (integrato)",
-"engine.document-tables.description": "Trasforma le tabelle dei documenti Word (DOCX) e delle pagine web (HTML, MHTML) in una cartella di lavoro Excel, un foglio ciascuna, con numeri e date come valori veri.",
+"engine.document-tables.description": "Trasforma le tabelle dei documenti (DOCX, DOC, ODT, RTF, HWP, HWPX) e delle pagine web (HTML, MHTML) in una cartella di lavoro Excel, un foglio ciascuna, con numeri e date come valori veri.",
"engine.email.name": "E-mail (integrato)",
"engine.email.description": "E-mail (EML, Outlook MSG) in HTML e testo con mittente, destinatari e data, immagini incluse; gli allegati in un ZIP.\nMSG in EML. Pagine web salvate (MHTML) in un unico file HTML con le loro immagini.",
"engine.p7m.name": "File firmati (integrato)",
@@ -1114,7 +1114,7 @@
"presets.split_minutes": "minuti per parte",
"presets.video_parts_hint": "Copiato così com'è, senza ricodificare: qualità, dimensione e codec non si applicano. Ogni parte finisce su un fotogramma chiave, quindi può durare qualche secondo in più del richiesto.",
"presets.pdf_tables_note": "Da un PDF, ogni tabella disegnata con linee diventa un foglio a sé (una tabella che continua nella pagina successiva resta un solo foglio), con numeri e date come valori veri. Il testo fuori dalle tabelle viene omesso.",
-"presets.document_tables_note": "Da un documento Word (DOCX) o da una pagina web (HTML), ogni tabella diventa un foglio a sé, con numeri e date come valori veri. Il testo fuori dalle tabelle viene omesso. Converti prima un file DOC in DOCX.",
+"presets.document_tables_note": "Da un documento (DOCX, DOC, ODT, RTF, HWP, HWPX) o da una pagina web (HTML), ogni tabella diventa un foglio a sé, con numeri e date come valori veri. Il testo fuori dalle tabelle viene omesso.",
"presets.pdf_compression": "Comprimi",
"presets.pdf_compression.None": "Non comprimere",
"presets.pdf_compression.Screen": "Minima (immagini a 72 dpi)",
diff --git a/src/Filee.App/Assets/i18n/ja.json b/src/Filee.App/Assets/i18n/ja.json
index 657dc177a..04cd7e3c1 100644
--- a/src/Filee.App/Assets/i18n/ja.json
+++ b/src/Filee.App/Assets/i18n/ja.json
@@ -298,7 +298,7 @@
"engine.pdf-ps.name": "PostScript ライター(組み込み)",
"engine.pdf-ps.description": "Ghostscript なしで PDF を PostScript と EPS に変換します。文字はフォントのまま、図形はベクターのままです。透明効果のあるページは画像になります。",
"engine.document-tables.name": "Document tables (built-in)",
- "engine.document-tables.description": "Word 文書(DOCX)と Web ページ(HTML、MHTML)の表を Excel ブックに変換します。表ごとに 1 シートで、数値と日付は実際の値になります。",
+ "engine.document-tables.description": "文書(DOCX, DOC, ODT, RTF, HWP, HWPX)と Web ページ(HTML、MHTML)の表を Excel ブックに変換します。表ごとに 1 シートで、数値と日付は実際の値になります。",
"engine.email.name": "E-mail (built-in)",
"engine.email.description": "メール(EML、Outlook MSG)を、差出人、宛先、日付、画像を含めてHTMLとテキストに変換します。添付ファイルはZIPにまとめます。\nMSGからEMLへの変換にも対応します。画像を含む保存済みのWebページ(MHTML)を、1つのHTMLファイルに変換します。",
"engine.p7m.name": "Signed files (built-in)",
@@ -1115,7 +1115,7 @@
"presets.split_minutes": "分ずつ",
"presets.video_parts_hint": "再エンコードせずそのままコピーするため、画質・サイズ・コーデックの設定は使われません。各パートはキーフレームで終わるので、指定より数秒長くなることがあります。",
"presets.pdf_tables_note": "PDF からは、罫線で描かれた表が 1 つずつシートになり(次のページに続く表は 1 つのシートのまま)、数値と日付は実際の値になります。表の外のテキストは含めません。",
- "presets.document_tables_note": "Word 文書(DOCX)や Web ページ(HTML)からは、表が 1 つずつシートになり、数値と日付は実際の値になります。表の外のテキストは含めません。DOC ファイルは先に DOCX に変換してください。",
+ "presets.document_tables_note": "文書(DOCX, DOC, ODT, RTF, HWP, HWPX)や Web ページ(HTML)からは、表が 1 つずつシートになり、数値と日付は実際の値になります。表の外のテキストは含めません。",
"presets.pdf_compression": "圧縮",
"presets.pdf_compression.None": "圧縮しない",
"presets.pdf_compression.Screen": "最小サイズ(画像72 dpi)",
diff --git a/src/Filee.App/Assets/i18n/ko.json b/src/Filee.App/Assets/i18n/ko.json
index 9308d6913..0ef98a896 100644
--- a/src/Filee.App/Assets/i18n/ko.json
+++ b/src/Filee.App/Assets/i18n/ko.json
@@ -305,7 +305,7 @@
"engine.pdf-ps.name": "PostScript 작성기 (내장)",
"engine.pdf-ps.description": "Ghostscript 없이 PDF를 PostScript와 EPS로 바꿔요. 글자는 글꼴 그대로, 도형은 벡터 그대로예요. 투명 효과가 있는 페이지는 그림이 돼요.",
"engine.document-tables.name": "Document tables (built-in)",
- "engine.document-tables.description": "Word 문서(DOCX)와 웹 페이지(HTML, MHTML)의 표를 Excel 통합 문서로 바꿔요. 표마다 시트 하나씩이고, 숫자와 날짜는 실제 값이 돼요.",
+ "engine.document-tables.description": "문서(DOCX, DOC, ODT, RTF, HWP, HWPX)와 웹 페이지(HTML, MHTML)의 표를 Excel 통합 문서로 바꿔요. 표마다 시트 하나씩이고, 숫자와 날짜는 실제 값이 돼요.",
"engine.email.name": "E-mail (built-in)",
"engine.email.description": "이메일(EML, Outlook MSG)을 보낸 사람·받는 사람·날짜와 본문 그림까지 담아 HTML·텍스트로 바꾸고, 첨부 파일은 ZIP으로 모아요.\nMSG는 EML로도 바꾸고, 저장한 웹 페이지(MHTML)는 그림까지 담긴 HTML 파일 하나로 바꿔요.",
"engine.p7m.name": "Signed files (built-in)",
@@ -1130,7 +1130,7 @@
"presets.split_minutes": "분씩",
"presets.video_parts_hint": "다시 인코딩하지 않고 그대로 복사해서 화질·크기·코덱 설정은 쓰이지 않아요. 각 부분은 키프레임에서 끝나서 정한 것보다 몇 초 길어질 수 있어요.",
"presets.pdf_tables_note": "PDF에서는 선으로 그린 표가 하나씩 시트가 되고(다음 페이지로 이어지는 표는 한 시트로 이어져요), 숫자와 날짜는 실제 값이 돼요. 표 밖의 텍스트는 빠져요.",
- "presets.document_tables_note": "Word 문서(DOCX)나 웹 페이지(HTML)에서는 표가 하나씩 시트가 되고, 숫자와 날짜는 실제 값이 돼요. 표 밖의 텍스트는 빠져요. DOC 파일은 먼저 DOCX로 바꿔 주세요.",
+ "presets.document_tables_note": "문서(DOCX, DOC, ODT, RTF, HWP, HWPX)나 웹 페이지(HTML)에서는 표가 하나씩 시트가 되고, 숫자와 날짜는 실제 값이 돼요. 표 밖의 텍스트는 빠져요.",
"presets.pdf_compression": "압축",
"presets.pdf_compression.None": "압축 안 함",
"presets.pdf_compression.Screen": "가장 작게 (이미지 72 dpi)",
diff --git a/src/Filee.App/Assets/i18n/mn.json b/src/Filee.App/Assets/i18n/mn.json
index 1558d49fc..617befa35 100644
--- a/src/Filee.App/Assets/i18n/mn.json
+++ b/src/Filee.App/Assets/i18n/mn.json
@@ -297,7 +297,7 @@
"engine.pdf-ps.name": "PostScript бичигч (суурилагдсан)",
"engine.pdf-ps.description": "PDF-ийг Ghostscript-гүйгээр PostScript болон EPS болгоно: текст фонтоо хадгалж, зураас вектороороо үлдэнэ. Тунгалаг хэсэгтэй хуудсууд зураг болно.",
"engine.document-tables.name": "Баримтын хүснэгт (суурилагдсан)",
- "engine.document-tables.description": "Word баримт (DOCX) болон вэб хуудасны (HTML, MHTML) хүснэгтүүдийг тоо болон огноог бодит утгаар нь хадгалан тус бүр нь нэг хуудастай Excel файл болгоно.",
+ "engine.document-tables.description": "Баримт (DOCX, DOC, ODT, RTF, HWP, HWPX) болон вэб хуудасны (HTML, MHTML) хүснэгтүүдийг тоо болон огноог бодит утгаар нь хадгалан тус бүр нь нэг хуудастай Excel файл болгоно.",
"engine.email.name": "Имэйл (суурилагдсан)",
"engine.email.description": "Имэйлүүдийг (EML, Outlook MSG) илгээгч, хүлээн авагч, огноо, зургуудын хамт HTML болон текст рүү, хавсралтуудыг ZIP рүү хөрвүүлнэ.\nMSG-г EML рүү. Хадгалсан вэб хуудсыг (MHTML) зургуудынх нь хамт нэг HTML файл болгоно.",
"engine.p7m.name": "Гарын үсэгтэй файл (суурилагдсан)",
@@ -1114,7 +1114,7 @@
"presets.split_minutes": "нэг хэсгийн минут",
"presets.video_parts_hint": "Дахин кодлохгүйгээр байгаагаар нь хуулах тул чанар, хэмжээ болон кодекийн тохиргоо үйлчлэхгүй. Хэсэг бүр тулгуур кадр дээр дуусдаг тул хүссэнээс хэдэн секундээр урт байж болно.",
"presets.pdf_tables_note": "PDF-ээс зураасаар зурсан хүснэгт бүр тусдаа ажлын хуудас болно (дараагийн хуудас руу үргэлжилсэн хүснэгт нэг хуудас хэвээр үлдэнэ), тоо болон огноо бодит утгаараа орно. Хүснэгтээс гадуурх текст орхигдоно.",
- "presets.document_tables_note": "Word баримт (DOCX) эсвэл вэб хуудаснаас (HTML) хүснэгт бүр тусдаа ажлын хуудас болох ба тоо, огноо бодит утгаараа орно. Хүснэгтээс гадуурх текст орхигдоно. DOC файлыг эхлээд DOCX болгож хөрвүүлнэ үү.",
+ "presets.document_tables_note": "Баримт (DOCX, DOC, ODT, RTF, HWP, HWPX) эсвэл вэб хуудаснаас (HTML) хүснэгт бүр тусдаа ажлын хуудас болох ба тоо, огноо бодит утгаараа орно. Хүснэгтээс гадуурх текст орхигдоно.",
"presets.pdf_compression": "Шахах",
"presets.pdf_compression.None": "Шахахгүй",
"presets.pdf_compression.Screen": "Хамгийн жижиг (зургууд 72 dpi)",
diff --git a/src/Filee.App/Assets/i18n/ne.json b/src/Filee.App/Assets/i18n/ne.json
index e4887eada..faf50e740 100644
--- a/src/Filee.App/Assets/i18n/ne.json
+++ b/src/Filee.App/Assets/i18n/ne.json
@@ -298,7 +298,7 @@
"engine.pdf-ps.name": "PostScript लेखक (भित्री)",
"engine.pdf-ps.description": "Ghostscript बिना PDF लाई PostScript र EPS मा बदल्छ: पाठले आफ्नो फन्ट राख्छ, चित्रहरू भेक्टर नै रहन्छन्। पारदर्शिता भएका पृष्ठहरू चित्र बन्छन्।",
"engine.document-tables.name": "Document tables (built-in)",
- "engine.document-tables.description": "Word कागजात (DOCX) र वेब पेज (HTML, MHTML) का तालिकाहरूलाई Excel वर्कबुकमा बदल्छ, हरेक तालिका एउटा शिट, अङ्क र मितिहरू वास्तविक मानका रूपमा।",
+ "engine.document-tables.description": "कागजात (DOCX, DOC, ODT, RTF, HWP, HWPX) र वेब पेज (HTML, MHTML) का तालिकाहरूलाई Excel वर्कबुकमा बदल्छ, हरेक तालिका एउटा शिट, अङ्क र मितिहरू वास्तविक मानका रूपमा।",
"engine.email.name": "E-mail (built-in)",
"engine.email.description": "इमेलहरू (EML, Outlook MSG) लाई प्रेषक, प्राप्तकर्ता र मितिसहित HTML र पाठमा रूपान्तरण गर्दछ, तस्बिरहरूसहित; संलग्नकहरू ZIP मा।\nMSG लाई EML मा। सुरक्षित वेब पृष्ठहरू (MHTML) लाई तिनका तस्बिरहरूसहित एउटै HTML फाइलमा।",
"engine.p7m.name": "Signed files (built-in)",
@@ -1111,7 +1111,7 @@
"presets.split_minutes": "मिनेट प्रति भाग",
"presets.video_parts_hint": "फेरि इन्कोड नगरी जस्तो छ त्यस्तै कपी हुन्छ, त्यसैले गुणस्तर, आकार र कोडेक सेटिङ लागू हुँदैनन्। हरेक भाग की फ्रेममा सकिन्छ, त्यसैले तोकिएभन्दा केही सेकेन्ड लामो हुन सक्छ।",
"presets.pdf_tables_note": "PDF बाट, रेखाले बनाइएको हरेक तालिका आफ्नै शिट बन्छ (अर्को पेजमा जारी तालिका एउटै शिट रहन्छ), र अङ्क र मितिहरू वास्तविक मान बन्छन्। तालिकाबाहिरको पाठ छोडिन्छ।",
- "presets.document_tables_note": "Word कागजात (DOCX) वा वेब पेज (HTML) बाट, हरेक तालिका आफ्नै शिट बन्छ, र अङ्क र मितिहरू वास्तविक मान बन्छन्। तालिकाबाहिरको पाठ छोडिन्छ। DOC फाइललाई पहिले DOCX मा बदल्नुहोस्।",
+ "presets.document_tables_note": "कागजात (DOCX, DOC, ODT, RTF, HWP, HWPX) वा वेब पेज (HTML) बाट, हरेक तालिका आफ्नै शिट बन्छ, र अङ्क र मितिहरू वास्तविक मान बन्छन्। तालिकाबाहिरको पाठ छोडिन्छ।",
"presets.pdf_compression": "कम्प्रेस गर्नुहोस्",
"presets.pdf_compression.None": "कम्प्रेस नगर्नुहोस्",
"presets.pdf_compression.Screen": "सबैभन्दा सानो (तस्बिरहरू ७२ dpi मा)",
diff --git a/src/Filee.App/Assets/i18n/pl.json b/src/Filee.App/Assets/i18n/pl.json
index 407170ba7..3d0705eec 100644
--- a/src/Filee.App/Assets/i18n/pl.json
+++ b/src/Filee.App/Assets/i18n/pl.json
@@ -305,7 +305,7 @@
"engine.pdf-ps.name": "Generator PostScript (wbudowany)",
"engine.pdf-ps.description": "Zamienia PDF na PostScript i EPS bez Ghostscripta: tekst zachowuje czcionki, rysunki pozostają wektorowe. Strony z przezroczystością stają się obrazami.",
"engine.document-tables.name": "Document tables (built-in)",
- "engine.document-tables.description": "Zamienia tabele z dokumentów Word (DOCX) i stron internetowych (HTML, MHTML) na skoroszyt Excel, każdą na osobnym arkuszu, z liczbami i datami jako prawdziwymi wartościami.",
+ "engine.document-tables.description": "Zamienia tabele z dokumentów (DOCX, DOC, ODT, RTF, HWP, HWPX) i stron internetowych (HTML, MHTML) na skoroszyt Excel, każdą na osobnym arkuszu, z liczbami i datami jako prawdziwymi wartościami.",
"engine.email.name": "E-mail (built-in)",
"engine.email.description": "E-maile (EML, Outlook MSG) do HTML i tekstu z nadawcą, odbiorcami i datą, razem z obrazami; załączniki do ZIP.\nMSG do EML. Zapisane strony internetowe (MHTML) do jednego pliku HTML razem z obrazami.",
"engine.p7m.name": "Signed files (built-in)",
@@ -1130,7 +1130,7 @@
"presets.split_minutes": "minut na część",
"presets.video_parts_hint": "Kopiowane bez zmian, bez ponownego kodowania, więc jakość, rozmiar i kodek nie mają zastosowania. Każda część kończy się na klatce kluczowej, więc może trwać kilka sekund dłużej, niż wybrano.",
"presets.pdf_tables_note": "Z PDF każda tabela narysowana liniami trafia na osobny arkusz (tabela ciągnąca się na następną stronę zostaje jednym arkuszem), a liczby i daty stają się prawdziwymi wartościami. Tekst poza tabelami jest pomijany.",
- "presets.document_tables_note": "Z dokumentu Word (DOCX) lub strony internetowej (HTML) każda tabela trafia na osobny arkusz, a liczby i daty stają się prawdziwymi wartościami. Tekst poza tabelami jest pomijany. Plik DOC najpierw przekonwertuj na DOCX.",
+ "presets.document_tables_note": "Z dokumentu (DOCX, DOC, ODT, RTF, HWP, HWPX) lub strony internetowej (HTML) każda tabela trafia na osobny arkusz, a liczby i daty stają się prawdziwymi wartościami. Tekst poza tabelami jest pomijany.",
"presets.pdf_compression": "Kompresja",
"presets.pdf_compression.None": "Bez kompresji",
"presets.pdf_compression.Screen": "Najmniejszy (obrazy w 72 dpi)",
diff --git a/src/Filee.App/Assets/i18n/pt-BR.json b/src/Filee.App/Assets/i18n/pt-BR.json
index 6fe00b692..8c4669138 100644
--- a/src/Filee.App/Assets/i18n/pt-BR.json
+++ b/src/Filee.App/Assets/i18n/pt-BR.json
@@ -305,7 +305,7 @@
"engine.pdf-ps.name": "Gerador PostScript (mecanismo integrado)",
"engine.pdf-ps.description": "Converte PDFs em PostScript e EPS sem o Ghostscript: o texto mantém as fontes e os desenhos continuam vetoriais. Páginas com transparência viram imagens.",
"engine.document-tables.name": "Tabelas de documentos (mecanismo integrado)",
- "engine.document-tables.description": "Transforma as tabelas de documentos do Word (DOCX) e de páginas da web (HTML, MHTML) em uma pasta de trabalho do Excel, uma planilha por tabela, com números e datas como valores reais.",
+ "engine.document-tables.description": "Transforma as tabelas de documentos (DOCX, DOC, ODT, RTF, HWP, HWPX) e de páginas da web (HTML, MHTML) em uma pasta de trabalho do Excel, uma planilha por tabela, com números e datas como valores reais.",
"engine.email.name": "E-mail (mecanismo integrado)",
"engine.email.description": "E-mails (EML, MSG do Outlook) para HTML e texto, com remetente, destinatários e data, imagens incluídas; anexos num ZIP.\nMSG para EML. Páginas da web salvas (MHTML) para um único arquivo HTML com as imagens.",
"engine.p7m.name": "Arquivos assinados (mecanismo integrado)",
@@ -1130,7 +1130,7 @@
"presets.split_minutes": "minutos por parte",
"presets.video_parts_hint": "Copiado como está, sem codificar de novo, então qualidade, tamanho e codec não se aplicam. Cada parte termina num quadro-chave, por isso pode durar alguns segundos a mais do que o pedido.",
"presets.pdf_tables_note": "De um PDF, cada tabela desenhada com linhas vira uma planilha própria (uma tabela que continua na página seguinte fica em uma só planilha), com números e datas como valores reais. O texto fora das tabelas fica de fora.",
- "presets.document_tables_note": "De um documento do Word (DOCX) ou de uma página da web (HTML), cada tabela vira uma planilha própria, com números e datas como valores reais. O texto fora das tabelas fica de fora. Converta antes um arquivo DOC para DOCX.",
+ "presets.document_tables_note": "De um documento (DOCX, DOC, ODT, RTF, HWP, HWPX) ou de uma página da web (HTML), cada tabela vira uma planilha própria, com números e datas como valores reais. O texto fora das tabelas fica de fora.",
"presets.pdf_compression": "Comprimir",
"presets.pdf_compression.None": "Não comprimir",
"presets.pdf_compression.Screen": "Menor (imagens a 72 dpi)",
diff --git a/src/Filee.App/Assets/i18n/pt-PT.json b/src/Filee.App/Assets/i18n/pt-PT.json
index 42ecf92e7..c68cb36ad 100644
--- a/src/Filee.App/Assets/i18n/pt-PT.json
+++ b/src/Filee.App/Assets/i18n/pt-PT.json
@@ -305,7 +305,7 @@
"engine.pdf-ps.name": "Gerador PostScript (motor integrado)",
"engine.pdf-ps.description": "Converte PDFs em PostScript e EPS sem o Ghostscript: o texto mantém os tipos de letra e os desenhos continuam vetoriais. As páginas com transparência passam a imagens.",
"engine.document-tables.name": "Tabelas de documentos (motor integrado)",
- "engine.document-tables.description": "Converte as tabelas de documentos do Word (DOCX) e de páginas web (HTML, MHTML) num livro do Excel, com uma folha por tabela e valores numéricos e de data.",
+ "engine.document-tables.description": "Converte as tabelas de documentos (DOCX, DOC, ODT, RTF, HWP, HWPX) e de páginas web (HTML, MHTML) num livro do Excel, com uma folha por tabela e valores numéricos e de data.",
"engine.email.name": "E-mail (motor integrado)",
"engine.email.description": "E-mails (EML, MSG do Outlook) para HTML e texto com remetente, destinatários, data e imagens; anexos para ZIP.\nMSG para EML. Páginas Web guardadas (MHTML) para um ficheiro HTML com as respetivas imagens.",
"engine.p7m.name": "Ficheiros assinados (motor integrado)",
@@ -1130,7 +1130,7 @@
"presets.split_minutes": "minutos por parte",
"presets.video_parts_hint": "Copiado tal como está, sem nova codificação, por isso a qualidade, o tamanho e o codec não se aplicam. Cada parte termina num fotograma-chave, pelo que pode durar alguns segundos a mais do que o pedido.",
"presets.pdf_tables_note": "A partir de um PDF, cada tabela delimitada por linhas ocupa uma folha (uma tabela que continua na página seguinte mantém-se na mesma folha), com valores numéricos e de data. O texto fora das tabelas é omitido.",
- "presets.document_tables_note": "A partir de um documento do Word (DOCX) ou de uma página web (HTML), cada tabela ocupa uma folha, com valores numéricos e de data. O texto fora das tabelas é omitido. Converta primeiro um ficheiro DOC para DOCX.",
+ "presets.document_tables_note": "A partir de um documento (DOCX, DOC, ODT, RTF, HWP, HWPX) ou de uma página web (HTML), cada tabela ocupa uma folha, com valores numéricos e de data. O texto fora das tabelas é omitido.",
"presets.pdf_compression": "Comprimir",
"presets.pdf_compression.None": "Não comprimir",
"presets.pdf_compression.Screen": "Tamanho mínimo (imagens a 72 dpi)",
diff --git a/src/Filee.App/Assets/i18n/ru.json b/src/Filee.App/Assets/i18n/ru.json
index 1c05484fd..303a8c356 100644
--- a/src/Filee.App/Assets/i18n/ru.json
+++ b/src/Filee.App/Assets/i18n/ru.json
@@ -305,7 +305,7 @@
"engine.pdf-ps.name": "Генератор PostScript (встроенный)",
"engine.pdf-ps.description": "Преобразует PDF в PostScript и EPS без Ghostscript: текст сохраняет шрифты, рисунки остаются векторными. Страницы с прозрачностью становятся изображениями.",
"engine.document-tables.name": "Document tables (built-in)",
- "engine.document-tables.description": "Превращает таблицы документов Word (DOCX) и веб-страниц (HTML, MHTML) в книгу Excel — по листу на таблицу, с числами и датами как настоящими значениями.",
+ "engine.document-tables.description": "Превращает таблицы документов (DOCX, DOC, ODT, RTF, HWP, HWPX) и веб-страниц (HTML, MHTML) в книгу Excel — по листу на таблицу, с числами и датами как настоящими значениями.",
"engine.email.name": "E-mail (built-in)",
"engine.email.description": "Письма (EML, Outlook MSG) — в HTML и текст с отправителем, получателями и датой, вместе с картинками; вложения — в ZIP.\nMSG в EML. Сохранённые веб-страницы (MHTML) — в один HTML-файл с картинками.",
"engine.p7m.name": "Signed files (built-in)",
@@ -1130,7 +1130,7 @@
"presets.split_minutes": "минут в части",
"presets.video_parts_hint": "Копируется как есть, без перекодирования, поэтому качество, размер и кодек не применяются. Каждая часть заканчивается на ключевом кадре, поэтому может быть на несколько секунд длиннее заданного.",
"presets.pdf_tables_note": "Из PDF каждая таблица, нарисованная линиями, становится отдельным листом (таблица, продолжающаяся на следующей странице, остаётся одним листом), а числа и даты — настоящими значениями. Текст вне таблиц не сохраняется.",
- "presets.document_tables_note": "Из документа Word (DOCX) или веб-страницы (HTML) каждая таблица становится отдельным листом, а числа и даты — настоящими значениями. Текст вне таблиц не сохраняется. Файл DOC сначала преобразуйте в DOCX.",
+ "presets.document_tables_note": "Из документа (DOCX, DOC, ODT, RTF, HWP, HWPX) или веб-страницы (HTML) каждая таблица становится отдельным листом, а числа и даты — настоящими значениями. Текст вне таблиц не сохраняется.",
"presets.pdf_compression": "Сжатие",
"presets.pdf_compression.None": "Не сжимать",
"presets.pdf_compression.Screen": "Минимальный размер (картинки 72 dpi)",
diff --git a/src/Filee.App/Assets/i18n/th.json b/src/Filee.App/Assets/i18n/th.json
index 00c42fb13..d777d4e4b 100644
--- a/src/Filee.App/Assets/i18n/th.json
+++ b/src/Filee.App/Assets/i18n/th.json
@@ -298,7 +298,7 @@
"engine.pdf-ps.name": "ตัวเขียน PostScript (ในตัว)",
"engine.pdf-ps.description": "แปลง PDF เป็น PostScript และ EPS โดยไม่ต้องใช้ Ghostscript ข้อความใช้ฟอนต์เดิม ภาพวาดยังเป็นเวกเตอร์ หน้าที่มีความโปร่งใสจะกลายเป็นรูปภาพ",
"engine.document-tables.name": "Document tables (built-in)",
- "engine.document-tables.description": "แปลงตารางในเอกสาร Word (DOCX) และหน้าเว็บ (HTML, MHTML) เป็นสมุดงาน Excel ตารางละหนึ่งชีต โดยตัวเลขและวันที่เป็นค่าจริง",
+ "engine.document-tables.description": "แปลงตารางในเอกสาร (DOCX, DOC, ODT, RTF, HWP, HWPX) และหน้าเว็บ (HTML, MHTML) เป็นสมุดงาน Excel ตารางละหนึ่งชีต โดยตัวเลขและวันที่เป็นค่าจริง",
"engine.email.name": "E-mail (built-in)",
"engine.email.description": "อีเมล (EML, Outlook MSG) เป็น HTML และข้อความ พร้อมผู้ส่ง ผู้รับ วันที่ และรูปภาพ แนบไฟล์ลงใน ZIP\nMSG เป็น EML บันทึกหน้าเว็บ (MHTML) เป็นไฟล์ HTML ไฟล์เดียวพร้อมรูปภาพ",
"engine.p7m.name": "Signed files (built-in)",
@@ -1115,7 +1115,7 @@
"presets.split_minutes": "นาทีต่อส่วน",
"presets.video_parts_hint": "คัดลอกตามเดิมโดยไม่เข้ารหัสใหม่ จึงไม่ใช้การตั้งค่าคุณภาพ ขนาด และโคเดก แต่ละส่วนจะจบที่คีย์เฟรม จึงอาจยาวกว่าที่ตั้งไว้สองสามวินาที",
"presets.pdf_tables_note": "จาก PDF ตารางที่วาดด้วยเส้นแต่ละตารางจะเป็นชีตของตัวเอง (ตารางที่ต่อไปยังหน้าถัดไปยังคงเป็นชีตเดียว) และตัวเลขกับวันที่จะเป็นค่าจริง ข้อความนอกตารางจะถูกละไว้",
- "presets.document_tables_note": "จากเอกสาร Word (DOCX) หรือหน้าเว็บ (HTML) ตารางแต่ละตารางจะเป็นชีตของตัวเอง และตัวเลขกับวันที่จะเป็นค่าจริง ข้อความนอกตารางจะถูกละไว้ ไฟล์ DOC ให้แปลงเป็น DOCX ก่อน",
+ "presets.document_tables_note": "จากเอกสาร (DOCX, DOC, ODT, RTF, HWP, HWPX) หรือหน้าเว็บ (HTML) ตารางแต่ละตารางจะเป็นชีตของตัวเอง และตัวเลขกับวันที่จะเป็นค่าจริง ข้อความนอกตารางจะถูกละไว้",
"presets.pdf_compression": "บีบอัด",
"presets.pdf_compression.None": "ไม่บีบอัด",
"presets.pdf_compression.Screen": "ขนาดเล็กที่สุด (ภาพที่ 72 dpi)",
diff --git a/src/Filee.App/Assets/i18n/tr.json b/src/Filee.App/Assets/i18n/tr.json
index 99a46de17..55ad5284b 100644
--- a/src/Filee.App/Assets/i18n/tr.json
+++ b/src/Filee.App/Assets/i18n/tr.json
@@ -298,7 +298,7 @@
"engine.pdf-ps.name": "PostScript oluşturucu (yerleşik)",
"engine.pdf-ps.description": "PDF'leri Ghostscript olmadan PostScript ve EPS'ye dönüştürür: metin yazı tiplerini korur, çizimler vektör kalır. Saydamlık içeren sayfalar resme dönüşür.",
"engine.document-tables.name": "Belge tabloları (yerleşik)",
- "engine.document-tables.description": "Word belgelerindeki (DOCX) ve web sayfalarındaki (HTML, MHTML) tabloları, her biri ayrı çalışma sayfasında olacak şekilde Excel'e dönüştürür; sayı ve tarihler gerçek değerler olarak tutulur.",
+ "engine.document-tables.description": "Belgelerdeki (DOCX, DOC, ODT, RTF, HWP, HWPX) ve web sayfalarındaki (HTML, MHTML) tabloları, her biri ayrı çalışma sayfasında olacak şekilde Excel'e dönüştürür; sayı ve tarihler gerçek değerler olarak tutulur.",
"engine.email.name": "E-posta (yerleşik)",
"engine.email.description": "E-postaları (EML, Outlook MSG) gönderen, alıcı, tarih ve görselleriyle HTML ve metne; ekleri ZIP'e dönüştürür.\nMSG → EML. Kaydedilmiş web sayfalarını (MHTML) görselleriyle tek bir HTML dosyasına dönüştürür.",
"engine.p7m.name": "İmzalı dosyalar (yerleşik)",
@@ -1115,7 +1115,7 @@
"presets.split_minutes": "dakikada bir parça",
"presets.video_parts_hint": "Yeniden kodlanmadan olduğu gibi kopyalanır; kalite, boyut ve codec ayarları uygulanmaz. Her parça bir anahtar karede biter, bu yüzden istenenden birkaç saniye uzun olabilir.",
"presets.pdf_tables_note": "PDF'deki çizgilerle oluşturulmuş her tablo ayrı çalışma sayfası olur (sonraki sayfada devam eden tablo aynı çalışma sayfasında kalır); sayı ve tarihler gerçek değerler olarak tutulur. Tabloların dışındaki metin çıkarılır.",
- "presets.document_tables_note": "Word belgesindeki (DOCX) veya web sayfasındaki (HTML) her tablo ayrı çalışma sayfası olur; sayı ve tarihler gerçek değerler olarak tutulur. Tabloların dışındaki metin çıkarılır. DOC dosyasını önce DOCX'e dönüştürün.",
+ "presets.document_tables_note": "Bir belgedeki (DOCX, DOC, ODT, RTF, HWP, HWPX) veya web sayfasındaki (HTML) her tablo ayrı çalışma sayfası olur; sayı ve tarihler gerçek değerler olarak tutulur. Tabloların dışındaki metin çıkarılır.",
"presets.pdf_compression": "Sıkıştır",
"presets.pdf_compression.None": "Sıkıştırma",
"presets.pdf_compression.Screen": "En küçük (görseller 72 dpi)",
diff --git a/src/Filee.App/Assets/i18n/vi.json b/src/Filee.App/Assets/i18n/vi.json
index 22ff52c33..413231bc4 100644
--- a/src/Filee.App/Assets/i18n/vi.json
+++ b/src/Filee.App/Assets/i18n/vi.json
@@ -305,7 +305,7 @@
"engine.pdf-ps.name": "Trình ghi PostScript (tích hợp)",
"engine.pdf-ps.description": "Chuyển PDF sang PostScript và EPS mà không cần Ghostscript: chữ giữ nguyên phông, hình vẽ vẫn là vector. Các trang có độ trong suốt sẽ thành ảnh.",
"engine.document-tables.name": "Bảng tài liệu (tích hợp)",
- "engine.document-tables.description": "Chuyển các bảng trong tài liệu Word (DOCX) và trang web (HTML, MHTML) thành sổ làm việc Excel, mỗi bảng một trang tính, số và ngày là giá trị thực.",
+ "engine.document-tables.description": "Chuyển các bảng trong tài liệu (DOCX, DOC, ODT, RTF, HWP, HWPX) và trang web (HTML, MHTML) thành sổ làm việc Excel, mỗi bảng một trang tính, số và ngày là giá trị thực.",
"engine.email.name": "Email (tích hợp)",
"engine.email.description": "Email (EML, Outlook MSG) sang HTML và văn bản kèm người gửi, người nhận và ngày, có cả ảnh; tệp đính kèm vào một tệp ZIP.\nMSG sang EML. Trang web đã lưu (MHTML) sang một tệp HTML kèm ảnh.",
"engine.p7m.name": "Tệp đã ký (tích hợp)",
@@ -1130,7 +1130,7 @@
"presets.split_minutes": "phút mỗi phần",
"presets.video_parts_hint": "Được sao chép nguyên trạng, không mã hóa lại, nên chất lượng, kích thước và codec không áp dụng. Mỗi phần kết thúc ở một khung hình chính, nên có thể dài hơn vài giây so với yêu cầu.",
"presets.pdf_tables_note": "Từ PDF, mỗi bảng kẻ bằng đường kẻ thành một trang tính riêng (bảng kéo dài sang trang sau vẫn là một trang tính), số và ngày là giá trị thực. Văn bản bên ngoài bảng bị bỏ qua.",
- "presets.document_tables_note": "Từ tài liệu Word (DOCX) hoặc trang web (HTML), mỗi bảng thành một trang tính riêng, số và ngày là giá trị thực. Văn bản bên ngoài bảng bị bỏ qua. Hãy chuyển tệp DOC sang DOCX trước.",
+ "presets.document_tables_note": "Từ tài liệu (DOCX, DOC, ODT, RTF, HWP, HWPX) hoặc trang web (HTML), mỗi bảng thành một trang tính riêng, số và ngày là giá trị thực. Văn bản bên ngoài bảng bị bỏ qua.",
"presets.pdf_compression": "Nén",
"presets.pdf_compression.None": "Không nén",
"presets.pdf_compression.Screen": "Nhỏ nhất (ảnh 72 dpi)",
diff --git a/src/Filee.App/Assets/i18n/zh-CN.json b/src/Filee.App/Assets/i18n/zh-CN.json
index c69d574b9..396970caf 100644
--- a/src/Filee.App/Assets/i18n/zh-CN.json
+++ b/src/Filee.App/Assets/i18n/zh-CN.json
@@ -305,7 +305,7 @@
"engine.pdf-ps.name": "PostScript 生成器(内置)",
"engine.pdf-ps.description": "无需 Ghostscript 即可把 PDF 转换为 PostScript 和 EPS:文字保留字体,图形保持矢量。含透明效果的页面会变成图片。",
"engine.document-tables.name": "Document tables (built-in)",
- "engine.document-tables.description": "把 Word 文档(DOCX)和网页(HTML、MHTML)中的表格转换为 Excel 工作簿,每个表格一个工作表,数字和日期为真正的数值。",
+ "engine.document-tables.description": "把文档(DOCX, DOC, ODT, RTF, HWP, HWPX)和网页(HTML、MHTML)中的表格转换为 Excel 工作簿,每个表格一个工作表,数字和日期为真正的数值。",
"engine.email.name": "E-mail (built-in)",
"engine.email.description": "将电子邮件(EML、Outlook MSG)连同发件人、收件人、日期和图片转为 HTML 和文本,附件打包为 ZIP。\nMSG 也可转为 EML。保存的网页(MHTML)可连同图片转为单个 HTML 文件。",
"engine.p7m.name": "Signed files (built-in)",
@@ -1130,7 +1130,7 @@
"presets.split_minutes": "分钟一段",
"presets.video_parts_hint": "按原样复制,不重新编码,所以画质、大小和编码设置不起作用。每段在关键帧处结束,可能比设定的长几秒。",
"presets.pdf_tables_note": "从 PDF 转换时,每个用线条画出的表格成为一个工作表(续到下一页的表格仍为一个工作表),数字和日期会成为真正的数值。表格外的文字不包含在内。",
- "presets.document_tables_note": "从 Word 文档(DOCX)或网页(HTML)转换时,每个表格成为一个工作表,数字和日期会成为真正的数值。表格外的文字不包含在内。DOC 文件请先转换为 DOCX。",
+ "presets.document_tables_note": "从文档(DOCX, DOC, ODT, RTF, HWP, HWPX)或网页(HTML)转换时,每个表格成为一个工作表,数字和日期会成为真正的数值。表格外的文字不包含在内。",
"presets.pdf_compression": "压缩",
"presets.pdf_compression.None": "不压缩",
"presets.pdf_compression.Screen": "最小(图片 72 dpi)",
diff --git a/src/Filee.App/Assets/i18n/zh-TW.json b/src/Filee.App/Assets/i18n/zh-TW.json
index 13efccba7..b2f47e05e 100644
--- a/src/Filee.App/Assets/i18n/zh-TW.json
+++ b/src/Filee.App/Assets/i18n/zh-TW.json
@@ -305,7 +305,7 @@
"engine.pdf-ps.name": "PostScript 產生器(內建)",
"engine.pdf-ps.description": "不需 Ghostscript 即可把 PDF 轉成 PostScript 與 EPS:文字保留字型,圖形維持向量。含透明效果的頁面會變成圖片。",
"engine.document-tables.name": "Document tables (built-in)",
- "engine.document-tables.description": "把 Word 文件(DOCX)和網頁(HTML、MHTML)中的表格轉成 Excel 活頁簿,每個表格一個工作表,數字與日期為真正的數值。",
+ "engine.document-tables.description": "把文件(DOCX, DOC, ODT, RTF, HWP, HWPX)和網頁(HTML、MHTML)中的表格轉成 Excel 活頁簿,每個表格一個工作表,數字與日期為真正的數值。",
"engine.email.name": "E-mail (built-in)",
"engine.email.description": "將電子郵件(EML、Outlook MSG)連同發件人、收件人、日期和圖片轉為 HTML 和文字,附件打包為 ZIP。\nMSG 也可轉為 EML。儲存的網頁(MHTML)可連同圖片轉為單個 HTML 檔案。",
"engine.p7m.name": "Signed files (built-in)",
@@ -1130,7 +1130,7 @@
"presets.split_minutes": "分鐘一段",
"presets.video_parts_hint": "照原樣複製,不重新編碼,所以畫質、大小和編碼設定不會套用。每段在關鍵影格處結束,可能比設定的長幾秒。",
"presets.pdf_tables_note": "從 PDF 轉換時,每個以線條繪製的表格會成為一個工作表(延續到下一頁的表格仍為一個工作表),數字與日期會成為真正的數值。表格外的文字不包含在內。",
- "presets.document_tables_note": "從 Word 文件(DOCX)或網頁(HTML)轉換時,每個表格會成為一個工作表,數字與日期會成為真正的數值。表格外的文字不包含在內。DOC 檔案請先轉換為 DOCX。",
+ "presets.document_tables_note": "從文件(DOCX, DOC, ODT, RTF, HWP, HWPX)或網頁(HTML)轉換時,每個表格會成為一個工作表,數字與日期會成為真正的數值。表格外的文字不包含在內。",
"presets.pdf_compression": "壓縮",
"presets.pdf_compression.None": "不壓縮",
"presets.pdf_compression.Screen": "最小(圖片 72 dpi)",
diff --git a/src/Filee.Engines/Archives/Bzip2Sort.cs b/src/Filee.Engines/Archives/Bzip2Sort.cs
index 796d5f9fb..41672b7ee 100644
--- a/src/Filee.Engines/Archives/Bzip2Sort.cs
+++ b/src/Filee.Engines/Archives/Bzip2Sort.cs
@@ -24,14 +24,15 @@ public static int Transform(ReadOnlySpan block, Span output, Cancell
block.CopyTo(output);
return 0;
}
- var shift = SmallestRotation(block);
+ var shift = SmallestRotation(block, out var periodic);
var word = ArrayPool.Shared.Rent(n);
var sa = ArrayPool.Shared.Rent(n);
try
{
block[shift..].CopyTo(word);
block[..shift].CopyTo(word.AsSpan(n - shift));
- var root = RootLength(word.AsSpan(0, n), sa);
+ // Only a block that equals one of its other rotations has a shorter root (and needs the prefix function).
+ var root = periodic ? RootLength(word.AsSpan(0, n), sa) : n;
var repeats = n / root;
SuffixArray(new ByteText(word), root, 256, sa, cancellationToken);
@@ -60,8 +61,16 @@ public static int Transform(ReadOnlySpan block, Span output, Cancell
}
}
- /// Where the lexicographically smallest rotation of starts (two candidates race).
- internal static int SmallestRotation(ReadOnlySpan text)
+ ///
+ /// Where the lexicographically smallest rotation of starts (two candidates race), and whether
+ /// equals another of its rotations (is a power of a shorter piece).
+ ///
+ ///
+ /// A candidate is only dropped, with the k places after it, when a rotation there is larger than another, so a
+ /// smallest rotation is never dropped. A periodic text has two or more: the candidates end up on two of them and
+ /// match all the way round. A text with one runs out of candidates before.
+ ///
+ internal static int SmallestRotation(ReadOnlySpan text, out bool periodic)
{
var n = text.Length;
int i = 0, j = 1, k = 0;
@@ -83,6 +92,7 @@ internal static int SmallestRotation(ReadOnlySpan text)
j++;
k = 0;
}
+ periodic = k >= n;
return Math.Min(i, j);
}
@@ -111,22 +121,37 @@ private static int RootLength(ReadOnlySpan text, int[] scratch)
private interface IText
{
int this[int index] { get; }
+
+ /// Whether the characters at and are the same.
+ bool Same(int a, int b, int length);
}
private readonly struct ByteText(byte[] text) : IText
{
public int this[int index] => text[index];
+
+ public bool Same(int a, int b, int length) => text.AsSpan(a, length).SequenceEqual(text.AsSpan(b, length));
}
private readonly struct IntText(int[] text) : IText
{
public int this[int index] => text[index];
+
+ public bool Same(int a, int b, int length) => text.AsSpan(a, length).SequenceEqual(text.AsSpan(b, length));
}
///
/// The suffix array of the first characters of (values below
/// ), with an implied end character smaller than all others, into .
///
+ ///
+ /// SA-IS, written so that each step reads as little as it can:
+ /// - No array of suffix types: a suffix's type follows from its first two characters and the scan that places it
+ /// (), and a bit per position marks the LMS ones.
+ /// - LMS substrings are named by comparing their characters in one go, their lengths kept in the unused half of
+ /// the suffix array.
+ /// The string of names is sorted the same way when names repeat; its alphabet is at most half the size.
+ ///
private static void SuffixArray(T text, int n, int alphabet, int[] sa, CancellationToken cancellationToken)
where T : struct, IText
{
@@ -143,29 +168,19 @@ private static void SuffixArray(T text, int n, int alphabet, int[] sa, Cancel
sa[1] = firstSmaller ? 1 : 0;
return;
}
+ ArgumentOutOfRangeException.ThrowIfGreaterThan(n, sa.Length);
cancellationToken.ThrowIfCancellationRequested();
- // S-type: the suffix is smaller than the one after it. The last character is L-type (the end is smaller).
- var stype = ArrayPool.Shared.Rent(n);
var starts = ArrayPool.Shared.Rent(alphabet);
var ends = ArrayPool.Shared.Rent(alphabet);
var fill = ArrayPool.Shared.Rent(alphabet);
- // Leftmost S-type positions (LMS) are never next to each other, so position / 2 indexes them.
- var lmsIndex = ArrayPool.Shared.Rent(n / 2 + 1);
var lms = ArrayPool.Shared.Rent(n / 2 + 1);
+ var isLms = ArrayPool.Shared.Rent((n >> 6) + 1);
int[]? sorted = null;
int[]? names = null;
int[]? reducedSa = null;
try
{
- stype[n - 1] = false;
- for (var i = n - 2; i >= 0; i--)
- {
- var a = text[i];
- var b = text[i + 1];
- stype[i] = a < b || a == b && stype[i + 1];
- }
-
Array.Clear(starts, 0, alphabet);
for (var i = 0; i < n; i++)
starts[text[i]]++;
@@ -178,123 +193,157 @@ private static void SuffixArray(T text, int n, int alphabet, int[] sa, Cancel
ends[c] = sum;
}
+ // LMS positions (an S-type suffix after an L-type one; the last suffix is L-type), found right to left.
+ // S-type: smaller than the suffix after it, so the first character is smaller, or equal and that one S-type.
+ Array.Clear(isLms, 0, (n >> 6) + 1);
var m = 0;
- for (var i = 1; i < n; i++)
+ var nextS = 0;
+ var next = text[n - 1];
+ for (var i = n - 2; i >= 0; i--)
{
- if (stype[i] && !stype[i - 1])
- {
- lmsIndex[i >> 1] = m;
- lms[m++] = i;
- }
+ var c = text[i];
+ var s = c < next ? 1 : c == next ? nextS : 0;
+ // Written every time and counted only for an LMS position: no branch to mispredict.
+ var lmsHere = nextS & (s ^ 1);
+ lms[m] = i + 1;
+ m += lmsHere;
+ isLms[(i + 1) >> 6] |= (ulong)lmsHere << (i + 1);
+ nextS = s;
+ next = c;
}
-
- // First pass: the LMS positions in text order; inducing sorts them by their LMS substrings.
- Induce(text, n, alphabet, stype, starts, ends, fill, lms.AsSpan(0, m), sa);
if (m == 0)
+ {
+ // No S-type suffix: the characters never rise, and the L-type ones induce from the last suffix alone.
+ Array.Clear(sa, 0, n);
+ Induce(text, n, sa, starts, ends, fill, alphabet);
return;
+ }
+ lms.AsSpan(0, m).Reverse();
+
+ // First pass: the LMS positions at the ends of their buckets; inducing sorts them by their LMS substrings.
+ Array.Clear(sa, 0, n);
+ Array.Copy(ends, fill, alphabet);
+ for (var k = m - 1; k >= 0; k--)
+ sa[--fill[text[lms[k]]]] = lms[k];
+ Induce(text, n, sa, starts, ends, fill, alphabet);
cancellationToken.ThrowIfCancellationRequested();
- sorted = ArrayPool.Shared.Rent(m);
- var k = 0;
+ // The LMS positions in that order, to the front.
+ var found = 0;
for (var i = 0; i < n; i++)
{
var p = sa[i];
- if (p > 0 && stype[p] && !stype[p - 1])
- sorted[k++] = p;
+ sa[found] = p;
+ found += (int)(isLms[p >> 6] >> p) & 1;
}
- // Name the LMS substrings (from one LMS position to the next, both included) by their sorted order.
- names = ArrayPool.Shared.Rent(m);
+ // Name the LMS substrings (from one LMS position to the next, both included) in that order. Each one's
+ // length, then its name, goes to sa[m + p / 2] (LMS positions are never next to each other); the last one
+ // runs into the end, so it is unlike any other (length -1).
+ Array.Clear(sa, m, n - m);
+ for (var k = 0; k < m; k++)
+ sa[m + (lms[k] >> 1)] = k + 1 < m ? lms[k + 1] - lms[k] + 1 : -1;
var name = 0;
- names[lmsIndex[sorted[0] >> 1]] = 0;
- for (var i = 1; i < m; i++)
+ int previous = -1, previousLength = 0;
+ for (var i = 0; i < m; i++)
{
- if (!SameLmsSubstring(text, n, lms, m, lmsIndex, sorted[i - 1], sorted[i]))
+ var p = sa[i];
+ var length = sa[m + (p >> 1)];
+ if (length < 0 || length != previousLength || !text.Same(p, previous, length))
name++;
- names[lmsIndex[sorted[i] >> 1]] = name;
+ sa[m + (p >> 1)] = name; // 1 and up; 0 is a gap
+ previous = p;
+ previousLength = length;
}
- if (name + 1 < m)
+ sorted = ArrayPool.Shared.Rent(m);
+ if (name < m)
{
// Some substrings repeat: sort the string of names (in text order) to order the LMS suffixes.
+ names = ArrayPool.Shared.Rent(m);
+ var k = 0;
+ for (var i = m; i < n && k < m; i++)
+ {
+ if (sa[i] != 0)
+ names[k++] = sa[i] - 1;
+ }
reducedSa = ArrayPool.Shared.Rent(m);
- SuffixArray(new IntText(names), m, name + 1, reducedSa, cancellationToken);
+ SuffixArray(new IntText(names), m, name, reducedSa, cancellationToken);
for (var i = 0; i < m; i++)
sorted[i] = lms[reducedSa[i]];
}
else
{
- for (var i = 0; i < m; i++)
- sorted[names[i]] = lms[i];
+ for (var k = 0; k < m; k++)
+ sorted[sa[m + (lms[k] >> 1)] - 1] = lms[k];
}
- Induce(text, n, alphabet, stype, starts, ends, fill, sorted.AsSpan(0, m), sa);
+ // Second pass: the sorted LMS suffixes at the ends of their buckets, the rest induced from them.
+ Array.Clear(sa, 0, n);
+ Array.Copy(ends, fill, alphabet);
+ for (var k = m - 1; k >= 0; k--)
+ sa[--fill[text[sorted[k]]]] = sorted[k];
+ Induce(text, n, sa, starts, ends, fill, alphabet);
}
finally
{
if (reducedSa is not null) ArrayPool.Shared.Return(reducedSa);
if (names is not null) ArrayPool.Shared.Return(names);
if (sorted is not null) ArrayPool.Shared.Return(sorted);
+ ArrayPool.Shared.Return(isLms);
ArrayPool.Shared.Return(lms);
- ArrayPool.Shared.Return(lmsIndex);
ArrayPool.Shared.Return(fill);
ArrayPool.Shared.Return(ends);
ArrayPool.Shared.Return(starts);
- ArrayPool.Shared.Return(stype);
}
}
///
- /// Induced sorting: the LMS positions go to the ends of their buckets in the given order, the L-type suffixes are
- /// placed from them left to right, then the S-type ones right to left.
+ /// Induced sorting from the LMS suffixes placed at the ends of their buckets (the rest of
+ /// zero): L-type suffixes left to right from the bucket starts, then S-type ones right to left from the bucket ends,
+ /// which places the LMS ones again.
///
- private static void Induce(T text, int n, int alphabet, bool[] stype, int[] starts, int[] ends, int[] fill,
- ReadOnlySpan lms, int[] sa)
+ ///
+ /// An entry placed as p means that the scan reaching it places p − 1; ~p (below zero) means it has nothing to place
+ /// in that scan. Which it is follows from two characters: in the L scan, p − 1 is L-type when its character is not
+ /// below p's (p being L-type, or LMS, whose character is below the one before it); in the S scan, p − 1 is S-type
+ /// when its character is not above p's (p being S-type). The L scan turns over every entry it passes: an L-type
+ /// suffix whose predecessor is L-type has nothing to place in the S scan, one whose predecessor is S-type has. The
+ /// S scan leaves every entry as the plain position. 0 is both a gap and suffix 0, which never places anything.
+ ///
+ private static void Induce(T text, int n, int[] sa, int[] starts, int[] ends, int[] fill, int alphabet)
where T : struct, IText
{
- Array.Fill(sa, -1, 0, n);
- Array.Copy(ends, fill, alphabet);
- for (var i = lms.Length - 1; i >= 0; i--)
- {
- var p = lms[i];
- sa[--fill[text[p]]] = p;
- }
-
Array.Copy(starts, fill, alphabet);
- // The suffix before the end: the last character, L-type.
- sa[fill[text[n - 1]]++] = n - 1;
+ // The last suffix, L-type (the end comes after it), first in its bucket.
+ var last = n - 1;
+ var c = text[last];
+ sa[fill[c]++] = text[last - 1] >= c ? last : ~last;
for (var i = 0; i < n; i++)
{
- var p = sa[i] - 1;
- if (p >= 0 && !stype[p])
- sa[fill[text[p]]++] = p;
+ var v = sa[i];
+ sa[i] = ~v;
+ if (v <= 0)
+ continue;
+ var j = v - 1;
+ c = text[j];
+ sa[fill[c]++] = j > 0 && text[j - 1] >= c ? j : ~j;
}
Array.Copy(ends, fill, alphabet);
for (var i = n - 1; i >= 0; i--)
{
- var p = sa[i] - 1;
- if (p >= 0 && stype[p])
- sa[--fill[text[p]]] = p;
- }
- }
-
- /// Whether the LMS substrings at and are equal.
- private static bool SameLmsSubstring(T text, int n, int[] lms, int m, int[] lmsIndex, int a, int b)
- where T : struct, IText
- {
- var nextA = lmsIndex[a >> 1] + 1;
- var nextB = lmsIndex[b >> 1] + 1;
- var endA = nextA < m ? lms[nextA] : n;
- var endB = nextB < m ? lms[nextB] : n;
- // The substring that runs into the end is unlike any other.
- if (endA == n || endB == n || endA - a != endB - b)
- return false;
- for (; a <= endA; a++, b++)
- {
- if (text[a] != text[b])
- return false;
+ var v = sa[i];
+ if (v > 0)
+ {
+ var j = v - 1;
+ c = text[j];
+ sa[--fill[c]] = j > 0 && text[j - 1] <= c ? j : ~j;
+ }
+ else if (v < 0)
+ {
+ sa[i] = ~v;
+ }
}
- return true;
}
}
diff --git a/src/Filee.Engines/Archives/Lzma/Crc64.cs b/src/Filee.Engines/Archives/Lzma/Crc64.cs
index 2f9288e96..94c887d52 100644
--- a/src/Filee.Engines/Archives/Lzma/Crc64.cs
+++ b/src/Filee.Engines/Archives/Lzma/Crc64.cs
@@ -1,5 +1,20 @@
// CRC-64 as the .xz format uses it (ECMA-182 polynomial, reflected: 0xC96C5795D7870F42, initial and final value all
// ones). System.IO.Hashing's Crc64 is the unreflected variant, so it does not give the same value.
+//
+// Long inputs are folded 16 bytes at a time with the processor's carry-less multiply (x64 PCLMULQDQ), the way CRCs are
+// usually computed at speed: in the reflected bit order a 16-byte piece stands for a polynomial of degree below 128
+// (the first byte's lowest bit the highest power), and the piece so far times x^128, plus the next piece, is the same
+// modulo the polynomial as its low half times (x^192 mod P) and its high half times (x^128 mod P), plus the next
+// piece. A carry-less product of two reflected 64-bit values comes out one place short of the 128-bit order, so the
+// constants used are those powers divided by x: x^191 and x^127 mod P. What is left at the end (one 16-byte piece,
+// whose CRC from a zero register is the folded state's, and the last 0 … 15 bytes) goes through the tables. The
+// constants are worked out once from the polynomial. Elsewhere (and for short inputs) the tables do all of it.
+
+using System.Buffers.Binary;
+using System.Runtime.CompilerServices;
+using System.Runtime.InteropServices;
+using System.Runtime.Intrinsics;
+using System.Runtime.Intrinsics.X86;
namespace Filee.Engines.Archives.Lzma;
@@ -8,9 +23,15 @@ internal sealed class Crc64
{
private const ulong Polynomial = 0xC96C5795D7870F42;
+ /// Inputs shorter than this go through the tables only.
+ private const int FoldFrom = 64;
+
// Four tables, so four bytes are folded in per step.
private static readonly ulong[][] Tables = CreateTables();
+ // x^191 mod P (for the low half) and x^127 mod P (for the high half), reflected.
+ private static readonly Vector128 FoldConstants = Vector128.Create(PowerOfX(191), PowerOfX(127));
+
private ulong _crc = ulong.MaxValue;
/// The checksum of everything passed to so far.
@@ -19,26 +40,69 @@ internal sealed class Crc64
public void Append(ReadOnlySpan data)
{
var crc = _crc;
+ if (data.Length >= FoldFrom && Pclmulqdq.IsSupported)
+ {
+ var whole = data.Length & ~15;
+ crc = Fold(crc, data[..whole]);
+ data = data[whole..];
+ }
+ _crc = Update(crc, data);
+ }
+
+ /// CRC-64 of .
+ public static ulong Compute(ReadOnlySpan data)
+ {
+ var crc = new Crc64();
+ crc.Append(data);
+ return crc.Value;
+ }
+
+ /// The register after (a multiple of 16 bytes, 32 or more), by folding.
+ private static ulong Fold(ulong crc, ReadOnlySpan data)
+ {
+ ref var at = ref MemoryMarshal.GetReference(data);
+ // The register so far goes into the first eight bytes (the same as starting from zero with them changed).
+ var state = Vector128.LoadUnsafe(ref at) ^ Vector128.CreateScalar(crc).AsByte();
+ var constants = FoldConstants;
+ for (var offset = 16; offset < data.Length; offset += 16)
+ {
+ var low = Pclmulqdq.CarrylessMultiply(state.AsUInt64(), constants, 0x00);
+ var high = Pclmulqdq.CarrylessMultiply(state.AsUInt64(), constants, 0x11);
+ state = (low ^ high).AsByte() ^ Vector128.LoadUnsafe(ref at, (nuint)offset);
+ }
+ Span last = stackalloc byte[16];
+ state.CopyTo(last);
+ return Update(0, last);
+ }
+
+ /// The register after , four bytes per step through the tables.
+ private static ulong Update(ulong crc, ReadOnlySpan data)
+ {
var (t0, t1, t2, t3) = (Tables[0], Tables[1], Tables[2], Tables[3]);
var i = 0;
for (; i + 4 <= data.Length; i += 4)
{
- var word = (uint)crc ^ (data[i] | (uint)data[i + 1] << 8 | (uint)data[i + 2] << 16 | (uint)data[i + 3] << 24);
+ var word = (uint)crc ^ BinaryPrimitives.ReadUInt32LittleEndian(data[i..]);
crc = t3[word & 0xFF] ^ t2[(word >> 8) & 0xFF] ^ t1[(word >> 16) & 0xFF] ^ t0[word >> 24] ^ (crc >> 32);
}
for (; i < data.Length; i++)
crc = t0[(crc ^ data[i]) & 0xFF] ^ (crc >> 8);
- _crc = crc;
+ return crc;
}
- /// CRC-64 of .
- public static ulong Compute(ReadOnlySpan data)
+ /// x^ mod P, reflected (bit i stands for x^(63 − i)).
+ private static ulong PowerOfX(int n)
{
- var crc = new Crc64();
- crc.Append(data);
- return crc.Value;
+ var value = 1UL << 63; // x^0
+ for (var i = 0; i < n; i++)
+ value = MultiplyByX(value);
+ return value;
}
+ /// Times x, mod P, in the reflected order: x^63 (bit 0) becomes x^64, which is P less its top term.
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ private static ulong MultiplyByX(ulong value) => (value >> 1) ^ ((value & 1) != 0 ? Polynomial : 0);
+
private static ulong[][] CreateTables()
{
var tables = new ulong[4][];
diff --git a/src/Filee.Engines/Archives/Lzma/MatchFinder.cs b/src/Filee.Engines/Archives/Lzma/MatchFinder.cs
index fbb2ad515..0bcd78ea4 100644
--- a/src/Filee.Engines/Archives/Lzma/MatchFinder.cs
+++ b/src/Filee.Engines/Archives/Lzma/MatchFinder.cs
@@ -369,6 +369,7 @@ private int ChainSearch(int pos, int maxLength, int[] lengths, uint[] distances)
ref var links = ref MemoryMarshal.GetArrayDataReference(_links);
var mask = _mask;
Unsafe.Add(ref links, stored & mask) = candidate;
+ PrefetchCandidate(ref links, ref data, candidate, offset, mask, buffer.Length);
// The next position is searched or entered right after this one: its table slots (mostly not in the cache)
// are asked for now, so they arrive while this chain is walked.
if (pos + 5 <= Filled)
@@ -415,6 +416,22 @@ private unsafe void PrefetchSlots(uint value)
Sse.Prefetch0(Unsafe.AsPointer(ref Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(_head4), (int)((value * 2654435761u) >> _hash4Shift))));
}
+ ///
+ /// A hint to load the first candidate of the chain (its link and its first bytes) into the cache (x86; elsewhere
+ /// nothing), so the walk's first steps don't wait for them after the two- and three-byte candidates are checked.
+ /// Only addresses inside the tables and the buffer are used; nothing is read through them.
+ ///
+ [MethodImpl(MethodImplOptions.AggressiveInlining)]
+ private static unsafe void PrefetchCandidate(ref int links, ref byte data, int candidate, int offset, int mask, int length)
+ {
+ if (!Sse.IsSupported || candidate <= 0)
+ return;
+ Sse.Prefetch0(Unsafe.AsPointer(ref Unsafe.Add(ref links, candidate & mask)));
+ var at = candidate - offset;
+ if ((uint)at < (uint)length)
+ Sse.Prefetch0(Unsafe.AsPointer(ref Unsafe.Add(ref data, at)));
+ }
+
/// The chain's two-byte slot for the bytes in the low half of .
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static int ChainHash2(uint value) => (int)(((value & 0xFFFF) * 2654435761u) >> (32 - ChainHash2Bits));
diff --git a/src/Filee.Engines/Charts/ChartDrawer.cs b/src/Filee.Engines/Charts/ChartDrawer.cs
new file mode 100644
index 000000000..c215c825a
--- /dev/null
+++ b/src/Filee.Engines/Charts/ChartDrawer.cs
@@ -0,0 +1,1718 @@
+// Draws a chart (ChartModel.cs) into a box of a page: fills and lines with Skia, text as glyph runs (ChartText), so
+// the sheet printer, the document renderer and the slide renderer all draw charts the same way, as vectors.
+//
+// Layout follows Office's automatic one: the chart area less a margin; the title at the top; the legend on its side
+// (right, left, top, bottom or the top-right corner) unless it overlays the plot; the plot area what is left, less its
+// axes' labels and titles, or where a manual layout puts it. Value axes scale themselves as Excel does when the file
+// sets no bounds: zero is kept unless the values sit far from it, the unit is 1, 2 or 5 times a power of ten giving
+// a readable number of gridlines for the axis' length, and the top gets a little room above the highest value.
+// Category labels are drawn level, wrapped at spaces, turned 45° or thinned out, whichever fits first.
+//
+// Plots: bars and columns (clustered with gap width and overlap, stacked, 100 %), lines (stacked, smooth, markers),
+// areas, scatter (lines and markers), pies (first slice angle, pulled-out slices) and doughnuts (one ring per series),
+// with data labels where the file asks for them. Combined plots share the plot area, each against its own axes.
+//
+// Bounds: data labels and markers drawn per chart are capped (MaxLabels, MaxMarkers), category labels are measured
+// for at most MaxMeasured of them (the rest thinned out), and gridlines and ticks per axis at most MaxTicks.
+
+using System.Globalization;
+using Filee.Engines.Office.Sheets;
+using Filee.Engines.Rendering;
+using SkiaSharp;
+
+namespace Filee.Engines.Charts;
+
+internal sealed class ChartDrawer
+{
+ private const int MaxLabels = 4096;
+ private const int MaxMarkers = 100_000;
+ private const int MaxMeasured = 2000;
+ private const int MaxTicks = 1000;
+
+ private static readonly string[] AutoSymbols = ["diamond", "square", "triangle", "x", "star", "circle", "plus", "dash", "dot"];
+
+ /// Lines of axes and gridlines when the file doesn't say.
+ private static readonly SKColor AxisGray = new(0x86, 0x86, 0x86), GridGray = new(0xD9, 0xD9, 0xD9);
+
+ private readonly Chart _chart;
+ private readonly PageContent _page;
+ private readonly ChartFonts _fonts;
+ private readonly float _s;
+ private readonly SKMatrix? _transform;
+ private readonly SKRect? _clip;
+ private readonly NumberFormatter _formatter;
+ private readonly List> _shapes = [];
+ private readonly List<(ChartTextLine Line, float X, float Baseline, SKMatrix? Local)> _texts = [];
+ private int _labels;
+ private int _markers;
+
+ private ChartDrawer(Chart chart, PageContent page, ChartFonts fonts, float scale, SKMatrix? transform, SKRect? clip)
+ {
+ _chart = chart;
+ _page = page;
+ _fonts = fonts;
+ _s = scale;
+ _transform = transform is { IsIdentity: false } ? transform : null;
+ _clip = clip;
+ _formatter = new NumberFormatter(chart.Date1904);
+ }
+
+ ///
+ /// Draws into , its text and lines times their
+ /// size (a sheet printed smaller or larger); maps the box's coordinates onto the page and
+ /// only what lies in (page coordinates) is drawn.
+ ///
+ public static void Draw(PageContent page, Chart chart, SKRect box, ChartFonts fonts, float scale = 1, SKMatrix? transform = null, SKRect? clip = null)
+ {
+ if (!(box.Width >= 2 && box.Height >= 2) || !float.IsFinite(box.Left) || !float.IsFinite(box.Top) || !float.IsFinite(box.Width)
+ || !float.IsFinite(box.Height) || !(scale > 0) || !float.IsFinite(scale))
+ return;
+ var drawer = new ChartDrawer(chart, page, fonts, scale, transform, clip);
+ drawer.Run(box);
+ drawer.Flush();
+ }
+
+ // ───────────────────────── Output ─────────────────────────
+
+ private void Flush()
+ {
+ var shapes = _shapes.ToArray();
+ var (transform, clip) = (_transform, _clip);
+ _page.Draw(canvas =>
+ {
+ if (clip is { } area)
+ canvas.ClipRect(area);
+ if (transform is { } matrix)
+ canvas.Concat(in matrix);
+ foreach (var shape in shapes)
+ shape(canvas);
+ });
+ foreach (var (line, x, baseline, local) in _texts)
+ {
+ SKMatrix? matrix = (_transform, local) switch
+ {
+ ({ } outer, { } inner) => outer.PreConcat(inner),
+ ({ } outer, null) => outer,
+ (null, { } inner) => inner,
+ _ => null,
+ };
+ line.Draw(_page, x, baseline, matrix, _clip);
+ }
+ }
+
+ private void Shape(Action draw) => _shapes.Add(draw);
+
+ private void Clipped(SKRect area, Action draw) => _shapes.Add(canvas =>
+ {
+ canvas.Save();
+ canvas.ClipRect(area);
+ draw(canvas);
+ canvas.Restore();
+ });
+
+ private static void FillPath(SKCanvas canvas, SKPath path, SKColor? fill)
+ {
+ if (fill is not { } color || color.Alpha == 0)
+ return;
+ using var paint = new SKPaint { IsAntialias = true, Style = SKPaintStyle.Fill, Color = color };
+ canvas.DrawPath(path, paint);
+ }
+
+ private static void StrokePath(SKCanvas canvas, SKPath path, Pen? pen, bool round = false)
+ {
+ if (pen is not { } p)
+ return;
+ using var dash = p.Dash is { Length: >= 2 } pattern
+ ? SKPathEffect.CreateDash([.. (pattern.Length % 2 == 0 ? pattern : [.. pattern, .. pattern]).Select(d => Math.Max(0.05f, d * p.Width))], 0)
+ : null;
+ using var paint = new SKPaint
+ {
+ IsAntialias = true,
+ Style = SKPaintStyle.Stroke,
+ Color = p.Color,
+ StrokeWidth = p.Width,
+ PathEffect = dash,
+ StrokeJoin = round ? SKStrokeJoin.Round : SKStrokeJoin.Miter,
+ StrokeCap = round ? SKStrokeCap.Round : SKStrokeCap.Butt,
+ };
+ canvas.DrawPath(path, paint);
+ }
+
+ /// A visible line: colour, width in page points, dashes.
+ private readonly record struct Pen(SKColor Color, float Width, float[]? Dash);
+
+ /// The pen of a line: the file's, or colour and width; null for no line.
+ private Pen? PenOf(ChartLine? line, SKColor? auto, float autoWidth)
+ {
+ if (line is { None: true })
+ return null;
+ var color = line?.Color ?? auto;
+ var width = line?.Width ?? autoWidth;
+ if (color is not { } c || c.Alpha == 0 || !(width > 0))
+ return null;
+ return new Pen(c, Math.Max(width, 0.25f) * _s, line?.Dash);
+ }
+
+ private static SKColor? FillOf(ChartShapeStyle style, SKColor? auto) =>
+ style.Fill is { } fill ? fill.Alpha == 0 ? null : fill : auto;
+
+ private ChartTextLine Text(string text, ChartTextStyle style) => _fonts.Line(text, style, style.Size * _s);
+
+ /// Text with its top-left corner at (x, y).
+ private void TextAt(ChartTextLine line, float x, float y) => _texts.Add((line, x, y + line.Ascent, null));
+
+ /// Text centred on (cx, cy), turned by clockwise about that point.
+ private void TextCentred(ChartTextLine line, float cx, float cy, float degrees = 0)
+ {
+ if (degrees == 0)
+ {
+ _texts.Add((line, cx - line.Width / 2, cy - line.Height / 2 + line.Ascent, null));
+ return;
+ }
+ var local = SKMatrix.CreateTranslation(cx, cy).PreConcat(SKMatrix.CreateRotationDegrees(degrees));
+ _texts.Add((line, -line.Width / 2, -line.Height / 2 + line.Ascent, local));
+ }
+
+ private string Format(double value, string? format)
+ {
+ var text = _formatter.Format(value, format);
+ return text.Length > ChartReader.MaxText ? text[..ChartReader.MaxText] : text;
+ }
+
+ // ───────────────────────── Chart ─────────────────────────
+
+ private void Run(SKRect box)
+ {
+ // The chart area: white with a light outline unless the file says otherwise.
+ var area = _chart.Area;
+ var fill = FillOf(area, SKColors.White);
+ var outline = PenOf(area.Line, area.Line is null ? GridGray : null, 0.75f);
+ var corner = _chart.RoundedCorners && outline is not null ? Math.Min(10 * _s, Math.Min(box.Width, box.Height) / 8) : 0;
+ Shape(canvas =>
+ {
+ using var path = new SKPath();
+ var inset = outline is { } pen ? pen.Width / 2 : 0;
+ var rect = SKRect.Inflate(box, -inset, -inset);
+ if (corner > 0)
+ path.AddRoundRect(rect, corner, corner);
+ else
+ path.AddRect(rect);
+ FillPath(canvas, path, fill);
+ StrokePath(canvas, path, outline);
+ });
+
+ var pad = 7 * _s;
+ var content = new SKRect(box.Left + pad, box.Top + pad, box.Right - pad, box.Bottom - pad);
+ if (content.Width <= 0 || content.Height <= 0)
+ return;
+ content = Title(content, box);
+ content = Legend(content, box);
+ if (content.Width <= 4 || content.Height <= 4)
+ return;
+ Plots(content, box);
+ }
+
+ private SKRect Title(SKRect content, SKRect box)
+ {
+ if (_chart.Title is not { Lines.Count: > 0 } title)
+ return content;
+ var lines = title.Lines.Select(l => Text(l, title.Style)).ToList();
+ var height = lines.Sum(l => l.Height);
+ var y = content.Top;
+ float? x = null;
+ if (title.Layout is { } layout)
+ {
+ x = box.Left + (float)layout.X * box.Width;
+ y = box.Top + (float)layout.Y * box.Height;
+ }
+ foreach (var line in lines)
+ {
+ TextAt(line, x ?? content.MidX - line.Width / 2, y);
+ y += line.Height;
+ }
+ if (title.Overlay || title.Layout is not null)
+ return content;
+ return new SKRect(content.Left, content.Top + height + 6 * _s, content.Right, content.Bottom);
+ }
+
+ // ───────────────────────── Legend ─────────────────────────
+
+ private enum KeyKind
+ {
+ Box,
+ Line,
+ }
+
+ private sealed record LegendEntry(string Text, KeyKind Kind, SKColor? Fill, Pen? Line, ChartMarker? Marker, SKColor MarkerColor);
+
+ private List LegendEntries()
+ {
+ var entries = new List();
+ var plots = _chart.Plots;
+ // One pie, doughnut or other plot of one series in varied colours: an entry per category.
+ if (plots.Count == 1 && plots[0] is { Series.Count: > 0 } only
+ && (only.Kind is ChartKind.Pie || only.Kind == ChartKind.Doughnut || only.VaryColors && only.Series.Count == 1 && only.Kind == ChartKind.Bar))
+ {
+ var series = only.Series[0];
+ var count = Math.Min(series.Values.Count, MaxLabels);
+ for (var i = 0; i < count; i++)
+ {
+ var style = series.Points.GetValueOrDefault(i) ?? series.Style;
+ var auto = _chart.Palette.Color(i);
+ entries.Add(new LegendEntry(Category(series, i), KeyKind.Box, FillOf(style, auto), PenOf(style.Line, null, 0.75f), null, auto));
+ }
+ return entries;
+ }
+ foreach (var plot in plots)
+ {
+ foreach (var series in plot.Series)
+ {
+ if (entries.Count >= MaxLabels)
+ return entries;
+ var auto = _chart.Palette.Color(series.Index);
+ var name = series.Name ?? $"Series{series.Index + 1}";
+ if (plot.Kind is ChartKind.Line or ChartKind.Scatter)
+ {
+ var line = plot.Lines ? PenOf(series.Style.Line, auto, plot.Kind == ChartKind.Line ? 2.25f : 1.5f) : null;
+ entries.Add(new LegendEntry(name, KeyKind.Line, null, line, MarkerOf(plot, series), auto));
+ }
+ else
+ {
+ entries.Add(new LegendEntry(name, KeyKind.Box, FillOf(series.Style, auto), PenOf(series.Style.Line, null, 0.75f), null, auto));
+ }
+ }
+ }
+ return entries;
+ }
+
+ private SKRect Legend(SKRect content, SKRect box)
+ {
+ if (_chart.Legend is not { } legend)
+ return content;
+ var entries = LegendEntries();
+ entries = [.. entries.Where((_, i) => !legend.Deleted.Contains(i))];
+ if (entries.Count == 0)
+ return content;
+ var s = _s;
+ var texts = entries.Select(e => Text(e.Text, legend.Style)).ToList();
+ var keyWidth = entries.Any(e => e.Kind == KeyKind.Line) ? 20 * s : 7 * s;
+ var gap = 4 * s;
+ var lineHeight = Math.Max(texts.Max(t => t.Height), 7 * s);
+ var vertical = legend.Position is "r" or "l" or "tr";
+ var maxText = Math.Min(texts.Max(t => t.Width), (vertical ? 0.45f : 0.9f) * content.Width);
+ var entryWidth = keyWidth + gap + maxText;
+
+ // Entries in rows (top, bottom) or one column (right, left).
+ var placed = new List<(int Index, float X, float Y)>();
+ float width, height;
+ if (vertical)
+ {
+ var rows = Math.Max(1, (int)Math.Min(entries.Count, (content.Height + 2 * s) / (lineHeight + 2 * s)));
+ width = entryWidth + 2 * gap;
+ height = rows * lineHeight + (rows - 1) * 2 * s + 2 * gap;
+ for (var i = 0; i < rows; i++)
+ placed.Add((i, gap, gap + i * (lineHeight + 2 * s)));
+ }
+ else
+ {
+ var rows = new List>();
+ var row = new List<(int Index, float Width)>();
+ var x = 0f;
+ for (var i = 0; i < entries.Count; i++)
+ {
+ var w = keyWidth + gap + Math.Min(texts[i].Width, maxText);
+ if (row.Count > 0 && x + w > content.Width - 2 * gap)
+ {
+ rows.Add(row);
+ row = [];
+ x = 0;
+ if ((rows.Count + 1) * (lineHeight + 2 * s) > content.Height / 2)
+ break;
+ }
+ row.Add((i, w));
+ x += w + 12 * s;
+ }
+ if (row.Count > 0 && (rows.Count + 1) * (lineHeight + 2 * s) <= Math.Max(content.Height / 2, lineHeight + 2 * s))
+ rows.Add(row);
+ float RowWidth(List<(int Index, float Width)> r) => r.Sum(e => e.Width) + 12 * s * (r.Count - 1);
+ var widest = rows.Count == 0 ? 0 : rows.Max(RowWidth);
+ width = widest + 2 * gap;
+ height = rows.Count * lineHeight + Math.Max(0, rows.Count - 1) * 2 * s + 2 * gap;
+ for (var r = 0; r < rows.Count; r++)
+ {
+ var left0 = gap + (widest - RowWidth(rows[r])) / 2;
+ foreach (var (index, w) in rows[r])
+ {
+ placed.Add((index, left0, gap + r * (lineHeight + 2 * s)));
+ left0 += w + 12 * s;
+ }
+ }
+ }
+
+ float left, top;
+ if (legend.Layout is { } layout)
+ {
+ left = box.Left + (float)layout.X * box.Width;
+ top = box.Top + (float)layout.Y * box.Height;
+ }
+ else
+ {
+ (left, top) = legend.Position switch
+ {
+ "l" => (content.Left, content.MidY - height / 2),
+ "t" => (content.MidX - width / 2, content.Top),
+ "b" => (content.MidX - width / 2, content.Bottom - height),
+ "tr" => (content.Right - width, content.Top),
+ _ => (content.Right - width, content.MidY - height / 2),
+ };
+ }
+ foreach (var (index, x, y) in placed)
+ {
+ var entry = entries[index];
+ var keyLeft = left + x;
+ var middle = top + y + lineHeight / 2;
+ LegendKey(entry, new SKRect(keyLeft, middle - 3.5f * s, keyLeft + keyWidth, middle + 3.5f * s));
+ var text = texts[index];
+ TextAt(text, keyLeft + keyWidth + gap, middle - text.Height / 2);
+ }
+ if (legend.Overlay || legend.Layout is not null)
+ return content;
+ var margin = 6 * s;
+ return legend.Position switch
+ {
+ "l" => new SKRect(content.Left + width + margin, content.Top, content.Right, content.Bottom),
+ "t" => new SKRect(content.Left, content.Top + height + margin, content.Right, content.Bottom),
+ "b" => new SKRect(content.Left, content.Top, content.Right, content.Bottom - height - margin),
+ _ => new SKRect(content.Left, content.Top, content.Right - width - margin, content.Bottom),
+ };
+ }
+
+ private void LegendKey(LegendEntry entry, SKRect key)
+ {
+ if (entry.Kind == KeyKind.Box)
+ {
+ var square = SKRect.Create(key.Left, key.MidY - key.Height / 2, key.Height, key.Height);
+ var (fill, line) = (entry.Fill, entry.Line);
+ Shape(canvas =>
+ {
+ using var path = new SKPath();
+ path.AddRect(square);
+ FillPath(canvas, path, fill);
+ StrokePath(canvas, path, line);
+ });
+ return;
+ }
+ var pen = entry.Line;
+ var (y, x0, x1) = (key.MidY, key.Left, key.Right);
+ Shape(canvas =>
+ {
+ using var path = new SKPath();
+ path.MoveTo(x0, y);
+ path.LineTo(x1, y);
+ StrokePath(canvas, path, pen);
+ });
+ if (entry.Marker is { } marker)
+ Marker(marker, entry.MarkerColor, new SKPoint(key.MidX, y), counted: false);
+ }
+
+ // ───────────────────────── Plot area ─────────────────────────
+
+ /// An axis as drawn: which way it runs, its scale (values) or count (categories), and its labels.
+ private sealed class Axis(ChartAxis definition, bool horizontal)
+ {
+ public ChartAxis Definition { get; } = definition;
+ public bool Horizontal { get; } = horizontal;
+ public bool IsValue => Definition.IsValue;
+ public double Low { get; set; } = double.PositiveInfinity;
+ public double High { get; set; } = double.NegativeInfinity;
+ public bool Percent { get; set; }
+ public string? Format { get; set; }
+ public Scale? Scale { get; set; }
+ public int Count { get; set; }
+ public IReadOnlyList Labels { get; set; } = [];
+
+ /// Points between the category ticks (bars always are).
+ public bool Between { get; set; } = true;
+
+ /// The other axis of the pair.
+ public Axis? Cross { get; set; }
+
+ public bool Shown => !Definition.Deleted;
+
+ /// A bar plot is drawn against the axis (its points sit between the ticks).
+ public bool HasBars { get; set; }
+
+ /// The category labels last set for a length of the axis.
+ public (float Length, CategoryLabels? Labels)? Measured { get; set; }
+
+ /// The side the labels and title are on: b or t (horizontal), l or r (vertical).
+ public string Side => Horizontal ? Definition.Position == "t" ? "t" : "b" : Definition.Position == "r" ? "r" : "l";
+
+ public void Include(double value)
+ {
+ if (!double.IsFinite(value))
+ return;
+ Low = Math.Min(Low, value);
+ High = Math.Max(High, value);
+ }
+
+ /// Where a category (0-based) or value sits along the axis, 0 to 1.
+ public double Fraction(double value)
+ {
+ double f;
+ if (Scale is { } scale)
+ return scale.Fraction(value);
+ var n = Math.Max(1, Count);
+ f = Between ? (value + 0.5) / n : n == 1 ? 0.5 : value / (n - 1);
+ return Definition.Reversed ? 1 - f : f;
+ }
+
+ /// The edge of category slot 's start (0) or end (1) along the axis.
+ public double Edge(double index)
+ {
+ var n = Math.Max(1, Count);
+ var f = Between ? index / n : n == 1 ? index : (index - 0.5) / (n - 1);
+ return Definition.Reversed ? 1 - f : f;
+ }
+ }
+
+ /// A value axis' range and unit.
+ private sealed class Scale(double min, double max, double unit, double? log, bool reversed)
+ {
+ public double Min { get; } = min;
+ public double Max { get; } = max;
+ public double Unit { get; } = unit;
+ public double? Log { get; } = log;
+
+ public double Fraction(double value)
+ {
+ double f;
+ if (Log is not null)
+ {
+ var lo = Math.Log(Min);
+ var hi = Math.Log(Max);
+ f = value > 0 ? (Math.Log(value) - lo) / (hi - lo) : double.NegativeInfinity;
+ }
+ else
+ {
+ f = (value - Min) / (Max - Min);
+ }
+ if (double.IsNaN(f))
+ f = 0;
+ f = Math.Clamp(f, -100, 100);
+ return reversed ? 1 - f : f;
+ }
+
+ public List Ticks()
+ {
+ var ticks = new List();
+ if (Log is { } logBase)
+ {
+ for (var v = Min; v <= Max * (1 + 1e-9) && ticks.Count < MaxTicks; v *= logBase)
+ ticks.Add(v);
+ return ticks;
+ }
+ for (var k = 0; ticks.Count < MaxTicks; k++)
+ {
+ var v = Min + k * Unit;
+ if (v > Max + Unit * 1e-9)
+ break;
+ ticks.Add(Math.Abs(v) < Unit * 1e-9 ? 0 : v);
+ }
+ return ticks;
+ }
+
+ /// Where the crossing axis stands on this one (c:crosses), as a value.
+ public double Crossing(ChartAxis crossing) => crossing.Crosses switch
+ {
+ ChartCrossing.Min => Min,
+ ChartCrossing.Max => Max,
+ ChartCrossing.At => Math.Clamp(crossing.CrossesAt, Min, Max),
+ _ => Log is not null ? Min : Math.Clamp(0, Min, Max),
+ };
+ }
+
+ private void Plots(SKRect content, SKRect box)
+ {
+ var plotStyle = _chart.PlotArea;
+ if (_chart.Plots.All(p => p.Kind is ChartKind.Pie or ChartKind.Doughnut))
+ {
+ var area = Manual(content, box);
+ PlotBackground(area, plotStyle);
+ foreach (var plot in _chart.Plots)
+ Round(plot, area);
+ return;
+ }
+
+ // Axes in pairs, each plot against its own.
+ var axes = new Dictionary();
+ var pairs = new List<(ChartPlot Plot, Axis Category, Axis Value)>();
+ foreach (var plot in _chart.Plots)
+ {
+ if (plot.Kind is ChartKind.Pie or ChartKind.Doughnut)
+ continue; // a pie among other plots: not drawn (Office can't combine them either)
+ var horizontal = plot is { Kind: ChartKind.Bar, Horizontal: true };
+ var first = AxisOf(axes, plot.AxisIds.ElementAtOrDefault(0), plot.AxisIds.Count > 0, value: plot.Kind == ChartKind.Scatter, horizontal: !horizontal, fallbackId: uint.MaxValue - 1);
+ var second = AxisOf(axes, plot.AxisIds.ElementAtOrDefault(1), plot.AxisIds.Count > 1, value: true, horizontal: horizontal, fallbackId: uint.MaxValue);
+ first.Cross = second;
+ second.Cross = first;
+ pairs.Add((plot, first, second));
+ Extents(plot, first, second);
+ }
+ if (pairs.Count == 0)
+ return;
+
+ // The plot area less what its axes need: vertical axes first (their labels don't depend on the width).
+ var manual = _chart.PlotLayout;
+ var outer = manual is { Inner: false } ? Manual(content, box) : content;
+ var inner = outer;
+ var vertical = axes.Values.Where(a => !a.Horizontal).ToList();
+ var level = axes.Values.Where(a => a.Horizontal).ToList();
+ foreach (var axis in vertical)
+ Prepare(axis, inner.Height * 0.85f);
+ if (manual is not { Inner: true })
+ {
+ foreach (var axis in vertical)
+ {
+ var need = Need(axis, inner.Height, 0.4f * outer.Width);
+ inner = axis.Side == "r" ? new SKRect(inner.Left, inner.Top, inner.Right - need, inner.Bottom) : new SKRect(inner.Left + need, inner.Top, inner.Right, inner.Bottom);
+ }
+ }
+ foreach (var axis in level)
+ Prepare(axis, inner.Width);
+ if (manual is not { Inner: true })
+ {
+ foreach (var axis in level)
+ {
+ var need = Need(axis, inner.Width, 0.5f * outer.Height);
+ inner = axis.Side == "t" ? new SKRect(inner.Left, inner.Top + need, inner.Right, inner.Bottom) : new SKRect(inner.Left, inner.Top, inner.Right, inner.Bottom - need);
+ }
+ // Room for the top value label's upper half and the right end of a level axis' last label.
+ inner = new SKRect(inner.Left, inner.Top + 4 * _s, inner.Right - 4 * _s, inner.Bottom);
+ }
+ else
+ {
+ inner = Manual(content, box);
+ }
+ if (inner.Width <= 2 || inner.Height <= 2)
+ return;
+ foreach (var axis in vertical)
+ Prepare(axis, inner.Height);
+
+ PlotBackground(inner, plotStyle);
+ foreach (var axis in axes.Values)
+ Gridlines(axis, inner);
+ foreach (var (plot, category, value) in pairs)
+ {
+ switch (plot.Kind)
+ {
+ case ChartKind.Bar:
+ Bars(plot, category, value, inner);
+ break;
+ case ChartKind.Area:
+ Areas(plot, category, value, inner);
+ break;
+ case ChartKind.Line or ChartKind.Scatter:
+ Lines(plot, category, value, inner);
+ break;
+ }
+ }
+ foreach (var axis in axes.Values)
+ AxisLine(axis, inner);
+ }
+
+ private Axis AxisOf(Dictionary axes, uint id, bool given, bool value, bool horizontal, uint fallbackId)
+ {
+ if (given && axes.TryGetValue(id, out var known))
+ return known;
+ var definition = given ? _chart.Axis(id) : null;
+ // An axis the file doesn't define is drawn as Office's default one would be, without labels.
+ definition ??= new ChartAxis { Id = given ? id : fallbackId, IsValue = value, Position = horizontal ? "b" : "l", Deleted = !given };
+ if (definition.IsValue != value)
+ definition = definition with { IsValue = value };
+ var axis = new Axis(definition, horizontal);
+ axes[given ? id : fallbackId] = axis;
+ return axis;
+ }
+
+ private SKRect Manual(SKRect content, SKRect box) =>
+ _chart.PlotLayout is { } layout
+ ? SKRect.Create(box.Left + (float)layout.X * box.Width, box.Top + (float)layout.Y * box.Height,
+ (float)(layout.Width ?? 1 - layout.X) * box.Width, (float)(layout.Height ?? 1 - layout.Y) * box.Height)
+ : content;
+
+ private void PlotBackground(SKRect area, ChartShapeStyle style)
+ {
+ var fill = FillOf(style, null);
+ var line = PenOf(style.Line, null, 0.75f);
+ if (fill is null && line is null)
+ return;
+ Shape(canvas =>
+ {
+ using var path = new SKPath();
+ path.AddRect(area);
+ FillPath(canvas, path, fill);
+ StrokePath(canvas, path, line);
+ });
+ }
+
+ // ───────────────────────── Axes ─────────────────────────
+
+ /// Gathers the values (and category count) a plot puts on its two axes.
+ private static void Extents(ChartPlot plot, Axis first, Axis second)
+ {
+ var series = plot.Series;
+ var count = series.Count == 0 ? 0 : series.Max(s => Math.Max(s.Values.Count, s.Categories?.Count ?? 0));
+ if (plot.Kind == ChartKind.Scatter)
+ {
+ foreach (var s in series)
+ {
+ for (var i = 0; i < s.Values.Count; i++)
+ {
+ if (s.Values[i] is not { } y)
+ continue;
+ var x = s.XValues is { } xs ? i < xs.Count ? xs[i] : null : i + 1;
+ if (x is not { } xv)
+ continue;
+ first.Include(xv);
+ second.Include(y);
+ }
+ }
+ first.Format ??= first.Definition.Format;
+ second.Format ??= second.Definition.Format ?? series.FirstOrDefault(s => s.Format is not null)?.Format;
+ return;
+ }
+ if (!first.IsValue)
+ {
+ first.Count = Math.Max(first.Count, count);
+ if (first.Labels.Count < count)
+ first.Labels = Enumerable.Range(0, Math.Min(count, ChartReader.MaxPoints)).Select(i => Category(series, i)).ToList();
+ // Bars sit between ticks; lines and areas wherever the value axis says.
+ first.HasBars |= plot.Kind == ChartKind.Bar;
+ first.Between = first.HasBars || second.Definition.Between;
+ }
+ else
+ {
+ for (var i = 0; i < count; i++)
+ first.Include(i + 1);
+ }
+ second.Format ??= second.Definition.Format ?? (plot.Grouping == ChartGrouping.PercentStacked ? "0%" : series.FirstOrDefault(s => s.Format is not null)?.Format);
+ if (plot.Grouping == ChartGrouping.Standard)
+ {
+ foreach (var s in series)
+ {
+ foreach (var v in s.Values)
+ {
+ if (v is { } value)
+ second.Include(value);
+ }
+ }
+ if (plot.Kind is ChartKind.Bar or ChartKind.Area)
+ second.Include(0);
+ return;
+ }
+ var percent = plot.Grouping == ChartGrouping.PercentStacked;
+ second.Percent |= percent;
+ for (var i = 0; i < count; i++)
+ {
+ double up = 0, down = 0;
+ foreach (var s in series)
+ {
+ if (i < s.Values.Count && s.Values[i] is { } v)
+ {
+ if (v >= 0)
+ up += v;
+ else
+ down += v;
+ }
+ }
+ if (percent)
+ {
+ var total = up - down;
+ if (total > 0)
+ {
+ second.Include(up / total);
+ second.Include(down / total);
+ }
+ }
+ else
+ {
+ second.Include(up);
+ second.Include(down);
+ }
+ }
+ second.Include(0);
+ }
+
+ /// Scales a value axis for points, or thins out a category axis' labels.
+ private void Prepare(Axis axis, float length)
+ {
+ if (!axis.IsValue)
+ return;
+ var definition = axis.Definition;
+ var (low, high) = double.IsFinite(axis.Low) ? (axis.Low, axis.High) : (0.0, 1.0);
+ if (axis.Percent && definition.Min is null && definition.Max is null)
+ {
+ axis.Scale = new Scale(low < -1e-9 ? -1 : 0, 1, definition.MajorUnit ?? (length / _s > 250 ? 0.1 : 0.2), null, definition.Reversed);
+ return;
+ }
+ if (definition.LogBase is { } logBase)
+ {
+ var positive = low > 0 ? low : high > 0 ? high / 100 : 1;
+ var top = high > 0 ? high : 1;
+ var min = definition.Min is > 0 and var lo ? lo : Math.Pow(logBase, Math.Floor(Math.Log(positive, logBase)));
+ var max = definition.Max is { } hi && hi > min ? hi : Math.Pow(logBase, Math.Ceiling(Math.Log(top, logBase)));
+ if (max <= min)
+ max = min * logBase;
+ axis.Scale = new Scale(min, max, logBase, logBase, definition.Reversed);
+ return;
+ }
+ var label = Text("0", definition.Style).Height;
+ var spacing = axis.Horizontal ? Math.Max(50 * _s, label * 4) : Math.Max(label * 2.2f, 22 * _s);
+ var target = Math.Clamp((int)(length / spacing), 2, 10);
+ for (var attempt = 0; attempt < 4; attempt++)
+ {
+ axis.Scale = AutoScale(low, high, definition, target);
+ if (!axis.Horizontal || !axis.Shown)
+ break;
+ // Level value labels must not touch: fewer of them when they do.
+ var ticks = axis.Scale.Ticks();
+ var widest = ticks.Take(MaxMeasured).Select(t => Text(Format(t, axis.Format), definition.Style).Width).DefaultIfEmpty(0).Max();
+ if (ticks.Count <= 1 || widest * 1.3f <= length / (ticks.Count - 1) || target <= 2)
+ break;
+ target = Math.Max(2, (int)(length / (widest * 1.4f)));
+ }
+ }
+
+ private static Scale AutoScale(double low, double high, ChartAxis axis, int target)
+ {
+ if (axis.Min is { } fixedMin)
+ low = Math.Min(low, fixedMin);
+ if (axis.Max is { } fixedMax)
+ high = Math.Max(high, fixedMax);
+ if (high < low)
+ (low, high) = (high, low);
+ // Zero is kept unless all values sit far above (or below) it.
+ var min = axis.Min ?? (low >= 0 ? (high > 0 && (high - low) / high < 1 / 6.0 ? low : 0) : low);
+ var max = axis.Max ?? (high <= 0 ? (low < 0 && (high - low) / -low < 1 / 6.0 ? high : 0) : high);
+ if (max <= min)
+ {
+ var spread = Math.Abs(min) > 0 ? Math.Abs(min) / 10 : 1;
+ (min, max) = axis.Min is not null ? (min, min + spread * 10) : axis.Max is not null ? (max - spread * 10, max) : (min - spread, max + spread);
+ }
+ var unit = axis.MajorUnit ?? Nice((max - min) / target);
+ if (!(unit > 0) || !double.IsFinite(unit))
+ unit = Math.Max(Math.Abs(max - min), 1e-300) / 5;
+ if ((max - min) / unit > MaxTicks)
+ unit = Nice((max - min) / 10);
+ // A little room above the highest value (and below the lowest), to the next unit.
+ if (axis.Max is null)
+ max = high <= 0 && max <= 0 ? Math.Ceiling(max / unit - 1e-9) * unit : Math.Ceiling((max + 0.05 * (max - min)) / unit - 1e-9) * unit;
+ if (axis.Min is null)
+ min = low >= 0 && min >= 0 && min == 0 ? 0 : Math.Floor((min - (min < 0 ? 0.05 * (max - min) : 0)) / unit + 1e-9) * unit;
+ if (max <= min)
+ max = min + unit;
+ return new Scale(min, max, unit, null, axis.Reversed);
+ }
+
+ /// 1, 2 or 5 times a power of ten, at least .
+ private static double Nice(double value)
+ {
+ if (!(value > 0) || !double.IsFinite(value))
+ return 1;
+ var power = Math.Pow(10, Math.Floor(Math.Log10(value)));
+ var f = value / power;
+ return (f <= 1 ? 1 : f <= 2 ? 2 : f <= 5 ? 5 : 10) * power;
+ }
+
+ /// The label of category : the first series' that has one, else its number.
+ private static string Category(IReadOnlyList series, int index)
+ {
+ foreach (var s in series)
+ {
+ if (s.Categories is { } categories && index < categories.Count && categories[index] is { } label)
+ return label;
+ }
+ return series.Any(s => s.Categories is not null) ? "" : (index + 1).ToString(CultureInfo.InvariantCulture);
+ }
+
+ private static string Category(ChartSeries series, int index) => Category([series], index);
+
+ /// How a category axis' labels are set: every n-th one, level, wrapped or turned.
+ private sealed record CategoryLabels(int Step, float Rotation, List<(int Index, List Lines)> Labels);
+
+ private CategoryLabels? Categories(Axis axis, float length)
+ {
+ if (axis.Measured is { } cached && cached.Length == length)
+ return cached.Labels;
+ var labels = MeasureCategories(axis, length);
+ axis.Measured = (length, labels);
+ return labels;
+ }
+
+ private CategoryLabels? MeasureCategories(Axis axis, float length)
+ {
+ if (axis.IsValue || axis.Definition.LabelPosition == "none" || axis.Count == 0)
+ return null;
+ var style = axis.Definition.Style;
+ var n = axis.Count;
+ var slot = length / n;
+ var step = axis.Definition.LabelSkip > 0 ? axis.Definition.LabelSkip : Math.Max(1, (int)Math.Ceiling(n / (double)MaxMeasured));
+ var lineHeight = Text("Ag", style).Height;
+ List<(int, List)> Measure(int every) =>
+ [.. Enumerable.Range(0, (n + every - 1) / every).Select(k => k * every).Select(i => (i, new List { Text(Label(axis, i), style) }))];
+
+ if (!axis.Horizontal)
+ {
+ // Labels beside a vertical axis: as many as fit one above the other.
+ if (axis.Definition.LabelSkip == 0)
+ step = Math.Max(step, (int)Math.Ceiling(lineHeight * 1.1 / Math.Max(slot, 0.01)));
+ return new CategoryLabels(step, 0, Measure(step));
+ }
+ var first = step;
+ var labels = Measure(step);
+ var widest = labels.Count == 0 ? 0 : labels.Max(l => l.Item2[0].Width);
+ var fixedRotation = axis.Definition.LabelRotation;
+ if (fixedRotation is { } turn && turn != 0)
+ {
+ var across = Math.Abs(Math.Sin(turn * Math.PI / 180)) > 0.5 ? lineHeight : widest;
+ if (axis.Definition.LabelSkip == 0)
+ step = Math.Max(step, (int)Math.Ceiling(across * 1.1 / Math.Max(slot, 0.01)));
+ return new CategoryLabels(step, (float)turn, step == first ? labels : Measure(step));
+ }
+ if (widest <= slot * step * 0.95f)
+ return new CategoryLabels(step, 0, labels);
+ // Wrapped at spaces into up to three lines, each within its slot.
+ var wrapped = new List<(int, List)>();
+ var fits = true;
+ foreach (var (index, lines) in labels)
+ {
+ var broken = Wrap(lines[0].Text, style, slot * step * 0.95f, 3);
+ if (broken is null)
+ {
+ fits = false;
+ break;
+ }
+ wrapped.Add((index, broken));
+ }
+ if (fits)
+ return new CategoryLabels(step, 0, wrapped);
+ if (fixedRotation is null)
+ {
+ // Turned 45°: thinned out until their line heights fit side by side.
+ if (axis.Definition.LabelSkip == 0)
+ step = Math.Max(step, (int)Math.Ceiling(lineHeight * 1.5 / Math.Max(slot, 0.01)));
+ return new CategoryLabels(step, -45, step == first ? labels : Measure(step));
+ }
+ if (axis.Definition.LabelSkip == 0)
+ step = Math.Max(step, (int)Math.Ceiling(widest * 1.1 / Math.Max(slot, 0.01)));
+ return new CategoryLabels(step, 0, Measure(step));
+ }
+
+ private static string Label(Axis axis, int index) => index < axis.Labels.Count ? axis.Labels[index] : (index + 1).ToString(CultureInfo.InvariantCulture);
+
+ /// The text broken at spaces into lines no wider than ; null when a word is wider or more lines are needed.
+ private List? Wrap(string text, ChartTextStyle style, float width, int maxLines)
+ {
+ var whole = Text(text, style);
+ if (whole.Width <= width)
+ return [whole];
+ var words = text.Split(' ', StringSplitOptions.RemoveEmptyEntries);
+ if (words.Length < 2)
+ return null;
+ var lines = new List();
+ var current = "";
+ foreach (var word in words)
+ {
+ var candidate = current.Length == 0 ? word : current + " " + word;
+ if (Text(candidate, style).Width <= width)
+ {
+ current = candidate;
+ continue;
+ }
+ if (current.Length == 0)
+ return null;
+ lines.Add(Text(current, style));
+ current = word;
+ if (Text(word, style).Width > width || lines.Count >= maxLines)
+ return null;
+ }
+ lines.Add(Text(current, style));
+ return lines.Count <= maxLines ? lines : null;
+ }
+
+ /// How far an axis' labels, ticks and title reach out from the plot (points).
+ private float Need(Axis axis, float length, float cap)
+ {
+ if (!axis.Shown)
+ return 0;
+ var definition = axis.Definition;
+ var need = definition.MajorTicks is "out" or "cross" ? 4 * _s : 0;
+ if (definition.LabelPosition != "none")
+ {
+ need += 3 * _s;
+ if (axis.IsValue && axis.Scale is { } scale)
+ {
+ var texts = scale.Ticks().Take(MaxMeasured).Select(t => Text(Format(t, axis.Format), definition.Style)).ToList();
+ if (texts.Count > 0)
+ need += axis.Horizontal ? texts.Max(t => t.Height) : texts.Max(t => t.Width);
+ }
+ else if (Categories(axis, length) is { } categories && categories.Labels.Count > 0)
+ {
+ if (!axis.Horizontal)
+ need += categories.Labels.Max(l => l.Lines.Max(t => t.Width));
+ else if (categories.Rotation != 0)
+ {
+ var radians = Math.Abs(categories.Rotation) * Math.PI / 180;
+ var widest = categories.Labels.Max(l => l.Lines.Max(t => t.Width));
+ var height = categories.Labels.Max(l => l.Lines.Max(t => t.Height));
+ need += (float)(widest * Math.Sin(radians) + height * Math.Cos(radians));
+ }
+ else
+ {
+ need += categories.Labels.Max(l => l.Lines.Sum(t => t.Height));
+ }
+ }
+ }
+ if (definition.Title is { Lines.Count: > 0 } title)
+ need += title.Lines.Sum(l => Text(l, title.Style).Height) + 4 * _s;
+ return Math.Min(need, cap);
+ }
+
+ private float Along(Axis axis, double fraction, SKRect inner) =>
+ axis.Horizontal ? inner.Left + (float)fraction * inner.Width : inner.Bottom - (float)fraction * inner.Height;
+
+ /// Where an axis' line stands across the plot: at the crossing on the other axis (points).
+ private float LinePosition(Axis axis, SKRect inner)
+ {
+ if (axis.Cross is not { } other)
+ return axis.Horizontal ? inner.Bottom : inner.Left;
+ double fraction;
+ if (other.Scale is { } scale)
+ fraction = scale.Fraction(scale.Crossing(axis.Definition));
+ else
+ {
+ var n = Math.Max(1, other.Count);
+ var index = axis.Definition.Crosses switch
+ {
+ ChartCrossing.Max => other.Between ? n : n - 1,
+ ChartCrossing.At => Math.Clamp(axis.Definition.CrossesAt - 1, 0, other.Between ? n : n - 1),
+ _ => 0,
+ };
+ fraction = other.Between ? other.Edge(index) : other.Fraction(index);
+ }
+ return Along(other, Math.Clamp(fraction, 0, 1), inner);
+ }
+
+ private void Gridlines(Axis axis, SKRect inner)
+ {
+ var definition = axis.Definition;
+ if (definition.MajorGridlines is null && definition.MinorGridlines is null)
+ return;
+ var lines = new List<(float Position, Pen Pen)>();
+ void Add(ChartLine? line, IEnumerable fractions)
+ {
+ if (PenOf(line, GridGray, 0.75f) is not { } pen)
+ return;
+ foreach (var f in fractions)
+ {
+ if (f is >= -1e-6 and <= 1 + 1e-6)
+ lines.Add((Along(axis, f, inner), pen));
+ }
+ }
+ if (axis.Scale is { } scale)
+ {
+ var ticks = scale.Ticks();
+ if (definition.MinorGridlines is not null && scale.Log is null && ticks.Count < MaxTicks / 5)
+ Add(definition.MinorGridlines, Enumerable.Range(0, (ticks.Count - 1) * 5 + 1).Select(k => scale.Fraction(scale.Min + k * scale.Unit / 5)));
+ Add(definition.MajorGridlines, ticks.Select(scale.Fraction));
+ }
+ else if (axis.Count > 0)
+ {
+ var count = Math.Min(axis.Count, MaxTicks);
+ Add(definition.MajorGridlines, axis.Between
+ ? Enumerable.Range(0, count + 1).Select(i => axis.Edge(i))
+ : Enumerable.Range(0, count).Select(i => axis.Fraction(i)));
+ }
+ if (lines.Count == 0)
+ return;
+ var horizontal = axis.Horizontal;
+ Shape(canvas =>
+ {
+ foreach (var (position, pen) in lines)
+ {
+ using var path = new SKPath();
+ if (horizontal)
+ {
+ path.MoveTo(position, inner.Top);
+ path.LineTo(position, inner.Bottom);
+ }
+ else
+ {
+ path.MoveTo(inner.Left, position);
+ path.LineTo(inner.Right, position);
+ }
+ StrokePath(canvas, path, pen);
+ }
+ });
+ }
+
+ /// An axis' line, ticks, labels and title.
+ private void AxisLine(Axis axis, SKRect inner)
+ {
+ if (!axis.Shown)
+ return;
+ var definition = axis.Definition;
+ var at = LinePosition(axis, inner);
+ var side = axis.Side;
+ var outward = side is "b" or "r" ? 1 : -1;
+ var pen = PenOf(definition.Line, AxisGray, 0.75f);
+ var tick = 4 * _s;
+ var (tickFrom, tickTo) = definition.MajorTicks switch
+ {
+ "out" => (0f, tick),
+ "in" => (-tick, 0f),
+ "cross" => (-tick, tick),
+ _ => (0f, 0f),
+ };
+ var fractions = axis.Scale is { } scale ? scale.Ticks().Select(scale.Fraction).ToList()
+ : axis.Between ? [.. Enumerable.Range(0, Math.Min(axis.Count, MaxTicks) + 1).Select(i => axis.Edge(i))]
+ : [.. Enumerable.Range(0, Math.Min(axis.Count, MaxTicks)).Select(i => axis.Fraction(i))];
+ if (pen is { } p)
+ {
+ var horizontal = axis.Horizontal;
+ var marks = tickFrom != tickTo ? fractions.Where(f => f is >= -1e-6 and <= 1 + 1e-6).Select(f => Along(axis, f, inner)).ToList() : [];
+ Shape(canvas =>
+ {
+ using var path = new SKPath();
+ if (horizontal)
+ {
+ path.MoveTo(inner.Left, at);
+ path.LineTo(inner.Right, at);
+ foreach (var x in marks)
+ {
+ path.MoveTo(x, at + tickFrom * outward);
+ path.LineTo(x, at + tickTo * outward);
+ }
+ }
+ else
+ {
+ path.MoveTo(at, inner.Top);
+ path.LineTo(at, inner.Bottom);
+ foreach (var y in marks)
+ {
+ path.MoveTo(at + tickFrom * outward, y);
+ path.LineTo(at + tickTo * outward, y);
+ }
+ }
+ StrokePath(canvas, path, p);
+ });
+ }
+
+ // Labels next to the line, or at the low or high edge of the plot.
+ var labelsAt = definition.LabelPosition switch
+ {
+ "low" => axis.Horizontal ? (axis.Cross?.Definition.Reversed == true ? inner.Top : inner.Bottom) : (axis.Cross?.Definition.Reversed == true ? inner.Right : inner.Left),
+ "high" => axis.Horizontal ? (axis.Cross?.Definition.Reversed == true ? inner.Bottom : inner.Top) : (axis.Cross?.Definition.Reversed == true ? inner.Left : inner.Right),
+ _ => at,
+ };
+ var offset = (definition.MajorTicks is "out" or "cross" ? tick : 0) + 3 * _s;
+ var reach = offset;
+ if (definition.LabelPosition != "none")
+ {
+ if (axis.Scale is { } valueScale)
+ {
+ foreach (var value in valueScale.Ticks())
+ {
+ var text = Text(Format(value, axis.Format), definition.Style);
+ var position = Along(axis, valueScale.Fraction(value), inner);
+ Place(text, axis.Horizontal, position, labelsAt, offset, outward);
+ reach = Math.Max(reach, offset + (axis.Horizontal ? text.Height : text.Width));
+ }
+ }
+ else if (Categories(axis, axis.Horizontal ? inner.Width : inner.Height) is { } categories)
+ {
+ foreach (var (index, lines) in categories.Labels)
+ {
+ var position = Along(axis, axis.Fraction(index), inner);
+ if (categories.Rotation != 0)
+ {
+ var line = lines[0];
+ // Turned labels end at their tick.
+ var radians = categories.Rotation * (float)Math.PI / 180;
+ var anchor = axis.Horizontal ? new SKPoint(position, labelsAt + offset * outward) : new SKPoint(labelsAt + offset * outward, position);
+ var local = SKMatrix.CreateTranslation(anchor.X, anchor.Y).PreConcat(SKMatrix.CreateRotationDegrees(categories.Rotation));
+ var x = categories.Rotation < 0 ? -line.Width : 0;
+ _texts.Add((line, x, (line.Ascent - line.Descent) / 2, local));
+ reach = Math.Max(reach, offset + (float)Math.Abs(line.Width * Math.Sin(radians)) + line.Height);
+ continue;
+ }
+ var total = lines.Sum(l => l.Height);
+ var y = 0f;
+ foreach (var line in lines)
+ {
+ if (axis.Horizontal)
+ {
+ var top = outward > 0 ? labelsAt + offset + y : labelsAt - offset - total + y;
+ TextAt(line, position - line.Width / 2, top);
+ }
+ else
+ {
+ Place(line, false, position - total / 2 + y + line.Height / 2, labelsAt, offset, outward);
+ }
+ y += line.Height;
+ }
+ reach = Math.Max(reach, offset + (axis.Horizontal ? total : lines.Max(l => l.Width)));
+ }
+ }
+ }
+
+ // The title beyond the labels, turned for a vertical axis.
+ if (definition.Title is { Lines.Count: > 0 } title)
+ {
+ var lines = title.Lines.Select(l => Text(l, title.Style)).ToList();
+ var height = lines.Sum(l => l.Height);
+ var edge = axis.Horizontal ? (outward > 0 ? Math.Max(labelsAt, inner.Bottom) : Math.Min(labelsAt, inner.Top)) : (outward > 0 ? Math.Max(labelsAt, inner.Right) : Math.Min(labelsAt, inner.Left));
+ var distance = reach + 4 * _s;
+ var y = -height / 2;
+ foreach (var line in lines)
+ {
+ if (axis.Horizontal)
+ TextCentred(line, inner.MidX, edge + outward * (distance + height / 2) + y + line.Height / 2);
+ else
+ TextCentred(line, edge + outward * (distance + height / 2) + (y + line.Height / 2) * -outward, inner.MidY, outward > 0 ? 90 : -90);
+ y += line.Height;
+ }
+ }
+ }
+
+ /// A label beside a level (or vertical) axis at along it.
+ private void Place(ChartTextLine text, bool horizontal, float position, float line, float offset, int outward)
+ {
+ if (horizontal)
+ {
+ var top = outward > 0 ? line + offset : line - offset - text.Height;
+ TextAt(text, position - text.Width / 2, top);
+ }
+ else
+ {
+ var left = outward > 0 ? line + offset : line - offset - text.Width;
+ TextAt(text, left, position - text.Height / 2);
+ }
+ }
+
+ // ───────────────────────── Bars ─────────────────────────
+
+ private SKColor SeriesColor(ChartPlot plot, ChartSeries series, int point) =>
+ plot.VaryColors && plot.Series.Count == 1 && plot.Kind is ChartKind.Bar or ChartKind.Pie or ChartKind.Doughnut
+ ? _chart.Palette.Color(point)
+ : _chart.Palette.Color(series.Index);
+
+ private void Bars(ChartPlot plot, Axis category, Axis value, SKRect inner)
+ {
+ if (value.Scale is not { } scale)
+ return;
+ var series = plot.Series;
+ var n = series.Count;
+ if (n == 0 || category.Count == 0)
+ return;
+ var stacked = plot.Grouping != ChartGrouping.Standard;
+ var percent = plot.Grouping == ChartGrouping.PercentStacked;
+ var gap = plot.GapWidth / 100.0;
+ var overlap = stacked ? 1 : plot.Overlap / 100.0;
+ var bars = stacked ? 1 : n;
+ // In slot units: bars of width w overlapping by overlap, a gap of gap × w shared out on both sides.
+ var width = 1 / (bars - (bars - 1) * overlap + gap);
+ var baseline = scale.Crossing(category.Definition);
+ var count = Math.Min(category.Count, ChartReader.MaxPoints);
+ var totals = percent ? Totals(series, count) : null;
+ var rects = new List<(SKRect Rect, SKColor? Fill, Pen? Line)>();
+ var labels = new List<(ChartSeries Series, int Index, double Value, SKRect Rect, bool Negative)>();
+ var up = new double[count];
+ var down = new double[count];
+ for (var k = 0; k < n; k++)
+ {
+ var s = series[k];
+ for (var i = 0; i < Math.Min(count, s.Values.Count); i++)
+ {
+ if (s.Values[i] is not { } v)
+ continue;
+ var shown = percent ? totals![i] > 0 ? v / totals[i] : 0 : v;
+ double from, to;
+ if (stacked)
+ {
+ if (shown >= 0)
+ {
+ from = up[i];
+ up[i] += shown;
+ to = up[i];
+ }
+ else
+ {
+ from = down[i];
+ down[i] += shown;
+ to = down[i];
+ }
+ }
+ else
+ {
+ (from, to) = (baseline, shown);
+ }
+ // The slot from its start: the half gap, then the k-th bar.
+ var start = gap * width / 2 + (stacked ? 0 : k * width * (1 - overlap));
+ var a = category.Edge(i);
+ var b = category.Edge(i + 1);
+ var c0 = a + (b - a) * start;
+ var c1 = a + (b - a) * (start + width);
+ var v0 = scale.Fraction(from);
+ var v1 = scale.Fraction(to);
+ SKRect rect;
+ if (category.Horizontal)
+ rect = new SKRect(Along(category, Math.Min(c0, c1), inner), Along(value, Math.Max(v0, v1), inner), Along(category, Math.Max(c0, c1), inner), Along(value, Math.Min(v0, v1), inner));
+ else
+ rect = new SKRect(Along(value, Math.Min(v0, v1), inner), Along(category, Math.Max(c0, c1), inner), Along(value, Math.Max(v0, v1), inner), Along(category, Math.Min(c0, c1), inner));
+ var style = s.Points.GetValueOrDefault(i) ?? s.Style;
+ var auto = SeriesColor(plot, s, i);
+ rects.Add((rect, FillOf(style, auto), PenOf(style.Line, null, 0.75f)));
+ labels.Add((s, i, v, rect, to < from));
+ }
+ }
+ Clipped(inner, canvas =>
+ {
+ foreach (var (rect, fill, line) in rects)
+ {
+ using var path = new SKPath();
+ path.AddRect(rect);
+ FillPath(canvas, path, fill);
+ StrokePath(canvas, path, line);
+ }
+ });
+ foreach (var (s, i, v, rect, negative) in labels)
+ {
+ if ((s.Labels ?? plot.Labels) is not { Any: true } options || DataLabel(plot, s, i, v, options) is not { } text)
+ continue;
+ var position = options.Position ?? (stacked ? "ctr" : "outEnd");
+ // Along the bar: its far end is the top of a column (or bottom of a negative one), the right of a bar.
+ var grows = category.Horizontal ? (negative ^ value.Definition.Reversed ? 1 : -1) : (negative ^ value.Definition.Reversed ? -1 : 1);
+ var pad = 3 * _s;
+ if (category.Horizontal)
+ {
+ var end = grows < 0 ? rect.Top : rect.Bottom;
+ var baseEnd = grows < 0 ? rect.Bottom : rect.Top;
+ var cy = position switch
+ {
+ "ctr" => rect.MidY,
+ "inEnd" => end - grows * (pad + text.Height / 2),
+ "inBase" => baseEnd + grows * (pad + text.Height / 2),
+ _ => end + grows * (pad + text.Height / 2),
+ };
+ TextCentred(text, rect.MidX, cy);
+ }
+ else
+ {
+ var end = grows > 0 ? rect.Right : rect.Left;
+ var baseEnd = grows > 0 ? rect.Left : rect.Right;
+ var cx = position switch
+ {
+ "ctr" => rect.MidX,
+ "inEnd" => end - grows * (pad + text.Width / 2),
+ "inBase" => baseEnd + grows * (pad + text.Width / 2),
+ _ => end + grows * (pad + text.Width / 2),
+ };
+ TextCentred(text, cx, rect.MidY);
+ }
+ }
+ }
+
+ private static double[] Totals(List series, int count)
+ {
+ var totals = new double[count];
+ foreach (var s in series)
+ {
+ for (var i = 0; i < Math.Min(count, s.Values.Count); i++)
+ totals[i] += Math.Abs(s.Values[i] ?? 0);
+ }
+ return totals;
+ }
+
+ /// The text of a data label (series name, category, value, percent), or null when it shows nothing or too many are drawn.
+ private ChartTextLine? DataLabel(ChartPlot plot, ChartSeries series, int index, double value, ChartLabels options, double? percent = null)
+ {
+ if (++_labels > MaxLabels)
+ return null;
+ var parts = new List(4);
+ if (options.Series && series.Name is { Length: > 0 } name)
+ parts.Add(name);
+ if (options.Category)
+ parts.Add(Category(series, index));
+ if (options.Value)
+ parts.Add(Format(value, options.Format ?? series.Format));
+ if (options.Percent && percent is { } share)
+ parts.Add(Format(share, "0%"));
+ _ = plot;
+ return parts.Count == 0 ? null : Text(string.Join(", ", parts), options.Style);
+ }
+
+ // ───────────────────────── Lines, areas, scatter ─────────────────────────
+
+ /// The marker a line or scatter series draws, or null for none.
+ private static ChartMarker? MarkerOf(ChartPlot plot, ChartSeries series)
+ {
+ var symbol = series.Marker?.Symbol ?? "auto";
+ if (symbol == "none" || series.Marker is null && !plot.Markers)
+ return null;
+ if (symbol == "auto")
+ symbol = AutoSymbols[series.Index % AutoSymbols.Length];
+ return new ChartMarker(symbol, series.Marker?.Size ?? 5, series.Marker?.Style ?? ChartShapeStyle.Auto);
+ }
+
+ private void Lines(ChartPlot plot, Axis x, Axis y, SKRect inner)
+ {
+ if (y.Scale is not { } scale)
+ return;
+ var scatter = plot.Kind == ChartKind.Scatter;
+ var percent = plot.Grouping == ChartGrouping.PercentStacked;
+ var stacked = plot.Grouping != ChartGrouping.Standard;
+ var count = plot.Series.Count == 0 ? 0 : plot.Series.Max(s => s.Values.Count);
+ var totals = percent ? Totals(plot.Series, count) : null;
+ var sums = new double[count];
+ foreach (var series in plot.Series)
+ {
+ var points = new List(series.Values.Count);
+ for (var i = 0; i < series.Values.Count; i++)
+ {
+ var v = series.Values[i];
+ if (v is null && !scatter && _chart.BlanksAs == "zero")
+ v = 0;
+ if (v is not { } value)
+ {
+ points.Add(null);
+ continue;
+ }
+ if (stacked)
+ {
+ sums[i] += percent ? totals![i] > 0 ? value / totals[i] : 0 : value;
+ value = sums[i];
+ }
+ double position;
+ if (scatter)
+ {
+ var xv = series.XValues is { } xs ? i < xs.Count ? xs[i] : null : i + 1;
+ if (xv is not { } xValue || x.Scale is not { } xScale)
+ {
+ points.Add(null);
+ continue;
+ }
+ position = xScale.Fraction(xValue);
+ }
+ else
+ {
+ position = x.Fraction(i);
+ }
+ var px = Along(x, position, inner);
+ var py = Along(y, scale.Fraction(value), inner);
+ points.Add(x.Horizontal ? new SKPoint(px, py) : new SKPoint(py, px));
+ }
+ var auto = _chart.Palette.Color(series.Index);
+ var pen = plot.Lines ? PenOf(series.Style.Line, auto, scatter ? 1.5f : 2.25f) : null;
+ var span = _chart.BlanksAs == "span" || scatter;
+ if (pen is not null)
+ {
+ var runs = Runs(points, span);
+ var smooth = series.Smooth;
+ Clipped(inner, canvas =>
+ {
+ foreach (var run in runs)
+ {
+ using var path = Polyline(run, smooth);
+ StrokePath(canvas, path, pen, round: true);
+ }
+ });
+ }
+ if (MarkerOf(plot, series) is { } marker)
+ {
+ for (var i = 0; i < points.Count; i++)
+ {
+ if (points[i] is { } point && SKRect.Inflate(inner, 1, 1).Contains(point))
+ Marker(marker with { Style = series.Points.GetValueOrDefault(i) is { } own ? own : marker.Style }, auto, point, counted: true);
+ }
+ }
+ if ((series.Labels ?? plot.Labels) is { Any: true } options)
+ {
+ for (var i = 0; i < points.Count; i++)
+ {
+ if (points[i] is not { } point || series.Values[i] is not { } v || DataLabel(plot, series, i, v, options) is not { } text)
+ continue;
+ var pad = 4 * _s + (MarkerOf(plot, series)?.Size ?? 0) * _s / 2;
+ var (cx, cy) = (options.Position ?? "r") switch
+ {
+ "t" => (point.X, point.Y - pad - text.Height / 2),
+ "b" => (point.X, point.Y + pad + text.Height / 2),
+ "l" => (point.X - pad - text.Width / 2, point.Y),
+ "ctr" => (point.X, point.Y),
+ _ => (point.X + pad + text.Width / 2, point.Y),
+ };
+ TextCentred(text, cx, cy);
+ }
+ }
+ }
+ }
+
+ /// The unbroken stretches of a line: blanks break it unless it spans them.
+ private static List Runs(List points, bool span)
+ {
+ var runs = new List();
+ var current = new List();
+ foreach (var point in points)
+ {
+ if (point is { } p)
+ {
+ current.Add(p);
+ continue;
+ }
+ if (span)
+ continue;
+ if (current.Count > 0)
+ runs.Add([.. current]);
+ current.Clear();
+ }
+ if (current.Count > 0)
+ runs.Add([.. current]);
+ return runs;
+ }
+
+ private static SKPath Polyline(SKPoint[] points, bool smooth)
+ {
+ var path = new SKPath();
+ if (points.Length == 0)
+ return path;
+ path.MoveTo(points[0]);
+ if (points.Length == 1)
+ {
+ path.LineTo(points[0]);
+ return path;
+ }
+ for (var i = 1; i < points.Length; i++)
+ {
+ if (!smooth)
+ {
+ path.LineTo(points[i]);
+ continue;
+ }
+ // Catmull-Rom through the points, as cubic Béziers.
+ var p0 = points[Math.Max(0, i - 2)];
+ var p1 = points[i - 1];
+ var p2 = points[i];
+ var p3 = points[Math.Min(points.Length - 1, i + 1)];
+ path.CubicTo(p1.X + (p2.X - p0.X) / 6, p1.Y + (p2.Y - p0.Y) / 6, p2.X - (p3.X - p1.X) / 6, p2.Y - (p3.Y - p1.Y) / 6, p2.X, p2.Y);
+ }
+ return path;
+ }
+
+ private void Marker(ChartMarker marker, SKColor auto, SKPoint center, bool counted)
+ {
+ if (counted && ++_markers > MaxMarkers)
+ return;
+ var size = marker.Size * _s;
+ var fill = FillOf(marker.Style, auto);
+ var line = PenOf(marker.Style.Line, auto, 0.75f);
+ var symbol = marker.Symbol;
+ Shape(canvas =>
+ {
+ using var path = new SKPath();
+ var (x, y, h) = (center.X, center.Y, size / 2);
+ var open = false;
+ switch (symbol)
+ {
+ case "circle":
+ path.AddCircle(x, y, h);
+ break;
+ case "dot":
+ path.AddCircle(x, y, h / 2);
+ break;
+ case "diamond":
+ path.AddPoly([new(x, y - h), new(x + h, y), new(x, y + h), new(x - h, y)]);
+ break;
+ case "triangle":
+ path.AddPoly([new(x, y - h), new(x + h, y + h), new(x - h, y + h)]);
+ break;
+ case "x":
+ path.MoveTo(x - h, y - h);
+ path.LineTo(x + h, y + h);
+ path.MoveTo(x + h, y - h);
+ path.LineTo(x - h, y + h);
+ open = true;
+ break;
+ case "plus":
+ path.MoveTo(x - h, y);
+ path.LineTo(x + h, y);
+ path.MoveTo(x, y - h);
+ path.LineTo(x, y + h);
+ open = true;
+ break;
+ case "star":
+ path.MoveTo(x - h, y - h);
+ path.LineTo(x + h, y + h);
+ path.MoveTo(x + h, y - h);
+ path.LineTo(x - h, y + h);
+ path.MoveTo(x, y - h);
+ path.LineTo(x, y + h);
+ open = true;
+ break;
+ case "dash":
+ path.AddRect(new SKRect(x - h, y - h / 4, x + h, y + h / 4));
+ break;
+ default:
+ path.AddRect(new SKRect(x - h, y - h, x + h, y + h));
+ break;
+ }
+ if (!open)
+ FillPath(canvas, path, fill);
+ StrokePath(canvas, path, open ? line ?? (fill is { } f ? new Pen(f, 0.75f, null) : null) : line);
+ });
+ }
+
+ private void Areas(ChartPlot plot, Axis category, Axis value, SKRect inner)
+ {
+ if (value.Scale is not { } scale)
+ return;
+ var count = plot.Series.Count == 0 ? 0 : Math.Min(plot.Series.Max(s => s.Values.Count), category.Count);
+ if (count == 0)
+ return;
+ var stacked = plot.Grouping != ChartGrouping.Standard;
+ var percent = plot.Grouping == ChartGrouping.PercentStacked;
+ var totals = percent ? Totals(plot.Series, count) : null;
+ var below = new double[count];
+ var baseline = stacked ? 0 : scale.Crossing(category.Definition);
+ SKPoint Point(int i, double v)
+ {
+ var along = Along(category, category.Fraction(i), inner);
+ var across = Along(value, scale.Fraction(v), inner);
+ return category.Horizontal ? new SKPoint(along, across) : new SKPoint(across, along);
+ }
+ foreach (var series in plot.Series)
+ {
+ var top = new SKPoint[count];
+ var bottom = new SKPoint[count];
+ for (var i = 0; i < count; i++)
+ {
+ var v = i < series.Values.Count ? series.Values[i] ?? 0 : 0;
+ if (percent)
+ v = totals![i] > 0 ? v / totals[i] : 0;
+ var from = stacked ? below[i] : baseline;
+ var to = stacked ? below[i] + v : v;
+ bottom[i] = Point(i, from);
+ top[i] = Point(i, to);
+ if (stacked)
+ below[i] = to;
+ }
+ var auto = _chart.Palette.Color(series.Index);
+ var fill = FillOf(series.Style, auto);
+ var line = PenOf(series.Style.Line, null, 0.75f);
+ Clipped(inner, canvas =>
+ {
+ using var path = new SKPath();
+ path.MoveTo(top[0]);
+ for (var i = 1; i < top.Length; i++)
+ path.LineTo(top[i]);
+ for (var i = bottom.Length - 1; i >= 0; i--)
+ path.LineTo(bottom[i]);
+ path.Close();
+ FillPath(canvas, path, fill);
+ StrokePath(canvas, path, line);
+ });
+ if ((series.Labels ?? plot.Labels) is { Any: true } options)
+ {
+ for (var i = 0; i < count; i++)
+ {
+ if (i < series.Values.Count && series.Values[i] is { } v && DataLabel(plot, series, i, v, options) is { } text)
+ TextCentred(text, (top[i].X + bottom[i].X) / 2, (top[i].Y + bottom[i].Y) / 2);
+ }
+ }
+ }
+ }
+
+ // ───────────────────────── Pies and doughnuts ─────────────────────────
+
+ private void Round(ChartPlot plot, SKRect area)
+ {
+ var rings = plot.Kind == ChartKind.Doughnut ? plot.Series : plot.Series.Take(1).ToList();
+ if (rings.Count == 0)
+ return;
+ var labelled = rings.Any(s => (s.Labels ?? plot.Labels) is { Any: true, Position: "outEnd" });
+ var radius = Math.Min(area.Width, area.Height) / 2 * (labelled ? 0.75f : 0.95f);
+ var pulled = rings.SelectMany(s => s.Explosion.Values).DefaultIfEmpty(0).Max();
+ radius /= 1 + pulled / 100f;
+ if (radius <= 1)
+ return;
+ var center = new SKPoint(area.MidX, area.MidY);
+ var hole = plot.Kind == ChartKind.Doughnut ? radius * plot.HoleSize / 100f : 0;
+ var ring = (radius - hole) / rings.Count;
+ for (var r = 0; r < rings.Count; r++)
+ {
+ var series = rings[r];
+ var inner = hole + r * ring;
+ var outer = inner + ring;
+ var total = series.Values.Sum(v => Math.Abs(v ?? 0));
+ if (!(total > 0))
+ continue;
+ var angle = -90 + plot.FirstSliceAngle;
+ var slices = new List<(float Start, float Sweep, SKPoint Center, SKColor? Fill, Pen? Line)>();
+ for (var i = 0; i < series.Values.Count; i++)
+ {
+ var v = Math.Abs(series.Values[i] ?? 0);
+ if (v <= 0)
+ continue;
+ var sweep = (float)(v / total * 360);
+ var style = series.Points.GetValueOrDefault(i) ?? series.Style;
+ var auto = plot.VaryColors ? _chart.Palette.Color(i) : _chart.Palette.Color(series.Index);
+ var explosion = series.Explosion.TryGetValue(i, out var own) ? own : series.Explosion.GetValueOrDefault(-1);
+ var middle = (angle + sweep / 2) * Math.PI / 180;
+ var shift = plot.Kind == ChartKind.Pie ? radius * explosion / 100f : 0;
+ var c = new SKPoint(center.X + (float)Math.Cos(middle) * shift, center.Y + (float)Math.Sin(middle) * shift);
+ slices.Add(((float)angle, sweep, c, FillOf(style, auto), PenOf(style.Line, SKColors.White, 0.75f)));
+ if ((series.Labels ?? plot.Labels) is { Any: true } options && DataLabel(plot, series, i, series.Values[i] ?? 0, options, v / total) is { } text)
+ {
+ var position = options.Position ?? "bestFit";
+ var distance = position switch
+ {
+ "outEnd" => outer + 6 * _s + Math.Max(text.Width, text.Height) / 2,
+ "inEnd" => outer - Math.Max(text.Width, text.Height) / 2 - 3 * _s,
+ "ctr" when plot.Kind == ChartKind.Pie => outer / 2,
+ _ => plot.Kind == ChartKind.Pie ? outer * 0.62f : (inner + outer) / 2,
+ };
+ TextCentred(text, c.X + (float)Math.Cos(middle) * distance, c.Y + (float)Math.Sin(middle) * distance);
+ }
+ angle += sweep;
+ }
+ var (innerRadius, outerRadius) = (inner, outer);
+ Shape(canvas =>
+ {
+ foreach (var (start, sweep, c, fill, line) in slices)
+ {
+ using var path = new SKPath();
+ var outerBox = new SKRect(c.X - outerRadius, c.Y - outerRadius, c.X + outerRadius, c.Y + outerRadius);
+ if (sweep >= 359.999f && innerRadius <= 0)
+ {
+ path.AddOval(outerBox);
+ }
+ else if (innerRadius <= 0)
+ {
+ path.MoveTo(c);
+ path.ArcTo(outerBox, start, sweep, false);
+ path.Close();
+ }
+ else
+ {
+ var innerBox = new SKRect(c.X - innerRadius, c.Y - innerRadius, c.X + innerRadius, c.Y + innerRadius);
+ path.ArcTo(outerBox, start, Math.Min(sweep, 359.99f), true);
+ path.ArcTo(innerBox, start + Math.Min(sweep, 359.99f), -Math.Min(sweep, 359.99f), false);
+ path.Close();
+ }
+ FillPath(canvas, path, fill);
+ StrokePath(canvas, path, line);
+ }
+ });
+ }
+ }
+}
diff --git a/src/Filee.Engines/Charts/ChartModel.cs b/src/Filee.Engines/Charts/ChartModel.cs
new file mode 100644
index 000000000..efba05742
--- /dev/null
+++ b/src/Filee.Engines/Charts/ChartModel.cs
@@ -0,0 +1,297 @@
+// A DrawingML chart as ChartDrawer draws it (ECMA-376 Part 1, 21.2): the plots of the plot area with their series
+// (the values cached in the chart part), the axes they use, the title, the legend and the chart's and plot area's
+// fills. ChartReader builds it from a c:chartSpace part; the sheet printer, the document renderer and the slide
+// renderer draw it.
+
+using SkiaSharp;
+
+namespace Filee.Engines.Charts;
+
+/// The kinds of plot drawn.
+internal enum ChartKind
+{
+ Bar,
+ Line,
+ Area,
+ Pie,
+ Doughnut,
+ Scatter,
+}
+
+/// How a plot's series stand to one another (c:grouping).
+internal enum ChartGrouping
+{
+ /// Side by side (bars) or each on its own (lines, areas): clustered or standard.
+ Standard,
+ Stacked,
+ PercentStacked,
+}
+
+///
+/// A line: colour (null = the automatic one), width in points (null = the automatic one) and dashes (multiples of the
+/// width, null = solid); = no line.
+///
+internal sealed record ChartLine(SKColor? Color = null, float? Width = null, float[]? Dash = null, bool None = false)
+{
+ public static readonly ChartLine Hidden = new(None: true);
+}
+
+/// How a bar, slice, area, marker or box is filled and outlined; null parts are the automatic ones.
+internal sealed record ChartShapeStyle
+{
+ /// The fill; null = automatic (the series colour), = none.
+ public SKColor? Fill { get; init; }
+
+ /// The outline; null = automatic.
+ public ChartLine? Line { get; init; }
+
+ public static readonly ChartShapeStyle Auto = new();
+}
+
+/// How text looks: font family (null = the theme's), size in points, weight, slant and colour.
+internal sealed record ChartTextStyle(string? Family, float Size, bool Bold, bool Italic, SKColor Color)
+{
+ public static readonly ChartTextStyle Default = new(null, 10, false, false, SKColors.Black);
+}
+
+/// A title (chart or axis): its lines and how they look.
+internal sealed record ChartTitle(IReadOnlyList Lines, ChartTextStyle Style, bool Overlay = false)
+{
+ /// Where the file places the title (fractions of the chart), or null for the automatic place.
+ public ChartLayout? Layout { get; init; }
+}
+
+/// c:manualLayout: a box as fractions of the chart area; = the plot without its axis labels.
+internal readonly record struct ChartLayout(double X, double Y, double? Width, double? Height, bool Inner);
+
+/// What data labels show and where (c:dLbls).
+internal sealed record ChartLabels(bool Value, bool Category, bool Series, bool Percent, string? Position, string? Format, ChartTextStyle Style)
+{
+ public bool Any => Value || Category || Series || Percent;
+}
+
+/// A marker of a line or scatter series: symbol (none, circle, square, ...), size in points, style.
+internal sealed record ChartMarker(string Symbol, float Size, ChartShapeStyle Style);
+
+/// One series: its name, categories and values (null = blank), and how it looks.
+internal sealed class ChartSeries
+{
+ public string? Name { get; init; }
+
+ /// c:idx: the series' place in the automatic colours.
+ public int Index { get; init; }
+
+ /// Category labels (c:cat), or null for 1, 2, 3, ....
+ public IReadOnlyList? Categories { get; init; }
+
+ /// X values of a scatter series (c:xVal numbers), or null for 1, 2, 3, ....
+ public IReadOnlyList? XValues { get; init; }
+
+ public IReadOnlyList Values { get; init; } = [];
+
+ /// The number format of the cached values (c:numCache c:formatCode), or null for General.
+ public string? Format { get; init; }
+
+ public ChartShapeStyle Style { get; init; } = ChartShapeStyle.Auto;
+
+ /// Points styled on their own (c:dPt), by index.
+ public IReadOnlyDictionary Points { get; init; } = new Dictionary();
+
+ /// Slices pulled out of a pie, in percent of the radius (c:explosion), by index; -1 for the whole series.
+ public IReadOnlyDictionary Explosion { get; init; } = new Dictionary();
+
+ /// The series' marker, or null for the plot's automatic one.
+ public ChartMarker? Marker { get; init; }
+
+ public ChartLabels? Labels { get; init; }
+
+ /// A line or scatter series drawn as a smooth curve.
+ public bool Smooth { get; init; }
+}
+
+/// One plot of the plot area (c:barChart, c:lineChart, ...): its series, drawn against two axes.
+internal sealed class ChartPlot
+{
+ public ChartKind Kind { get; init; }
+ public ChartGrouping Grouping { get; init; }
+
+ /// Bars run left to right (c:barDir bar) instead of upwards.
+ public bool Horizontal { get; init; }
+
+ /// Each point in its own colour (c:varyColors), as pie slices are.
+ public bool VaryColors { get; init; }
+
+ /// Space between bar groups, in percent of a bar's width.
+ public int GapWidth { get; init; } = 150;
+
+ /// How far the bars of a group overlap, in percent of a bar's width (negative: a gap).
+ public int Overlap { get; init; }
+
+ /// The hole of a doughnut, in percent of its radius.
+ public int HoleSize { get; init; } = 50;
+
+ /// Where a pie's first slice starts, in degrees clockwise from the top.
+ public double FirstSliceAngle { get; init; }
+
+ /// Lines (and markers) of a line or scatter plot: c:marker of c:lineChart, c:scatterStyle.
+ public bool Lines { get; init; } = true;
+
+ public bool Markers { get; init; }
+
+ public ChartLabels? Labels { get; init; }
+
+ /// The axes the plot is drawn against (c:axId): category (or X) first, value (or Y) second.
+ public IReadOnlyList AxisIds { get; init; } = [];
+
+ public List Series { get; } = [];
+}
+
+/// Where an axis crosses the other (c:crosses, c:crossesAt).
+internal enum ChartCrossing
+{
+ AutoZero,
+ Min,
+ Max,
+ At,
+}
+
+/// An axis: c:catAx, c:dateAx (categories) or c:valAx (values).
+internal sealed record ChartAxis
+{
+ public uint Id { get; init; }
+
+ /// A value axis (c:valAx): numbers along it, scaled; else categories.
+ public bool IsValue { get; init; }
+
+ /// c:axPos: b, l, r or t.
+ public string Position { get; init; } = "b";
+
+ public bool Deleted { get; init; }
+
+ /// Runs from its maximum to its minimum (c:orientation maxMin).
+ public bool Reversed { get; init; }
+
+ public double? Min { get; init; }
+ public double? Max { get; init; }
+ public double? MajorUnit { get; init; }
+
+ /// A logarithmic axis' base (c:logBase), or null.
+ public double? LogBase { get; init; }
+
+ public ChartTitle? Title { get; init; }
+
+ /// The labels' number format, or null for the values' own (c:numFmt sourceLinked).
+ public string? Format { get; init; }
+
+ public ChartLine? MajorGridlines { get; init; }
+ public ChartLine? MinorGridlines { get; init; }
+
+ /// The axis line; null = automatic.
+ public ChartLine? Line { get; init; }
+
+ /// c:tickLblPos: nextTo, low, high or none.
+ public string LabelPosition { get; init; } = "nextTo";
+
+ /// c:majorTickMark: out, in, cross or none.
+ public string MajorTicks { get; init; } = "out";
+
+ public ChartCrossing Crosses { get; init; }
+ public double CrossesAt { get; init; }
+
+ /// The other axis of the pair (c:crossAx).
+ public uint CrossAxis { get; init; }
+
+ /// Points sit between the category ticks (c:crossBetween between) rather than on them (midCat).
+ public bool Between { get; init; } = true;
+
+ /// Category labels skipped: every n-th is drawn (c:tickLblSkip), or 0 for automatic.
+ public int LabelSkip { get; init; }
+
+ /// Turn of the labels in degrees (c:txPr a:bodyPr rot), or null for automatic.
+ public double? LabelRotation { get; init; }
+
+ public ChartTextStyle Style { get; init; } = ChartTextStyle.Default;
+}
+
+/// The legend: where it is, which entries are left out, how its text looks.
+internal sealed class ChartLegend
+{
+ /// c:legendPos: r, l, t, b or tr.
+ public string Position { get; init; } = "r";
+
+ public bool Overlay { get; init; }
+
+ /// Entries left out (c:legendEntry c:delete), by index.
+ public IReadOnlySet Deleted { get; init; } = new HashSet();
+
+ public ChartLayout? Layout { get; init; }
+
+ public ChartTextStyle Style { get; init; } = ChartTextStyle.Default;
+}
+
+///
+/// Office's automatic chart colours: the theme's six accents, then the same six darker and lighter in turn (Office's
+/// colour variations: 60 %, 80 % + 20 %, 80 %, 60 % + 40 %, 50 %, 70 % + 30 %, 70 %, 50 % + 50 % luminance).
+///
+internal sealed class ChartPalette(IReadOnlyList accents)
+{
+ private static readonly (double Mod, double Off)[] Variations =
+ [(1, 0), (0.6, 0), (0.8, 0.2), (0.8, 0), (0.6, 0.4), (0.5, 0), (0.7, 0.3), (0.7, 0), (0.5, 0.5)];
+
+ public static readonly ChartPalette Default = new(
+ [
+ new SKColor(0x44, 0x72, 0xC4), new SKColor(0xED, 0x7D, 0x31), new SKColor(0xA5, 0xA5, 0xA5),
+ new SKColor(0xFF, 0xC0, 0x00), new SKColor(0x5B, 0x9B, 0xD5), new SKColor(0x70, 0xAD, 0x47),
+ ]);
+
+ public SKColor Color(int index)
+ {
+ index = Math.Max(0, index);
+ var accent = accents.Count == 0 ? SKColors.Gray : accents[index % accents.Count];
+ var (mod, off) = Variations[index / Math.Max(1, accents.Count) % Variations.Length];
+ if (mod == 1 && off == 0)
+ return accent;
+ accent.ToHsl(out var h, out var s, out var l);
+ return SKColor.FromHsl(h, s, (float)Math.Clamp(l * mod + off * 100, 0, 100));
+ }
+}
+
+/// A chart part, read.
+internal sealed class Chart
+{
+ public ChartTitle? Title { get; init; }
+ public List Plots { get; } = [];
+ public List Axes { get; } = [];
+ public ChartLegend? Legend { get; init; }
+
+ /// The chart area's fill and outline (c:chartSpace c:spPr).
+ public ChartShapeStyle Area { get; init; } = ChartShapeStyle.Auto;
+
+ /// The plot area's fill and outline (c:plotArea c:spPr).
+ public ChartShapeStyle PlotArea { get; init; } = ChartShapeStyle.Auto;
+
+ public ChartLayout? PlotLayout { get; init; }
+
+ /// The chart area has rounded corners (c:roundedCorners).
+ public bool RoundedCorners { get; init; }
+
+ /// How blank values are drawn (c:dispBlanksAs): gap, zero or span (the line goes on over them).
+ public string BlanksAs { get; init; } = "gap";
+
+ /// Dates in the cached values count from 1904 (c:date1904).
+ public bool Date1904 { get; init; }
+
+ /// The chart's text when nothing else says (c:chartSpace c:txPr).
+ public ChartTextStyle Text { get; init; } = ChartTextStyle.Default;
+
+ /// The automatic colours of series and points.
+ public ChartPalette Palette { get; init; } = ChartPalette.Default;
+
+ /// The theme's body font (+mn-lt), for text without a family.
+ public string? ThemeFont { get; init; }
+
+ /// Points of all series together (what drawing the chart costs).
+ public long PointCount => Plots.Sum(p => p.Series.Sum(s => (long)s.Values.Count));
+
+ public ChartAxis? Axis(uint id) => Axes.FirstOrDefault(a => a.Id == id);
+}
diff --git a/src/Filee.Engines/Charts/ChartPicture.cs b/src/Filee.Engines/Charts/ChartPicture.cs
new file mode 100644
index 000000000..8ffe5a062
--- /dev/null
+++ b/src/Filee.Engines/Charts/ChartPicture.cs
@@ -0,0 +1,27 @@
+// A chart drawn into a picture, for what takes pictures rather than drawings: the document writers (a Word chart
+// becomes a picture in HWPX, ODT, EPUB, ...) and the ODP writer.
+
+using Filee.Engines.Rendering;
+using SkiaSharp;
+
+namespace Filee.Engines.Charts;
+
+internal static class ChartPicture
+{
+ /// Pixels of the longer side at most.
+ private const int MaxSide = 4000;
+
+ /// The chart drawn × points at , as PNG; null for an empty box.
+ public static byte[]? Png(Chart chart, float width, float height, float dpi = 192)
+ {
+ if (!(width >= 1 && height >= 1) || !float.IsFinite(width) || !float.IsFinite(height))
+ return null;
+ dpi = Math.Min(dpi, MaxSide * 72f / Math.Max(width, height));
+ var page = new PageContent(width, height);
+ using (var fonts = new ChartFonts())
+ ChartDrawer.Draw(page, chart, new SKRect(0, 0, width, height), fonts);
+ using var bitmap = page.Render(dpi);
+ using var data = bitmap.Encode(SKEncodedImageFormat.Png, 100);
+ return data?.ToArray();
+ }
+}
diff --git a/src/Filee.Engines/Charts/ChartReader.cs b/src/Filee.Engines/Charts/ChartReader.cs
new file mode 100644
index 000000000..770d6c1f1
--- /dev/null
+++ b/src/Filee.Engines/Charts/ChartReader.cs
@@ -0,0 +1,560 @@
+// A DrawingML chart part (c:chartSpace, ECMA-376 Part 1, 21.2.2) → the chart model ChartDrawer draws. Everything comes
+// from what the part caches (c:strCache, c:numCache, c:multiLvlStrCache, literals), so no formula is evaluated and no
+// workbook is opened: what Excel, Word and PowerPoint saved is what is drawn.
+//
+// Read: bar and column (clustered, stacked, 100 %), line (with markers, stacked), area, pie, doughnut and scatter plots,
+// several in one plot area (a column and line combination on two value axes); the title (rich text or a cell's text,
+// or the series name Office shows for a lone series), axis titles, category, date and value axes with their scaling,
+// number format, gridlines, tick marks, label position and crossing; the legend with deleted entries; data labels;
+// fills and outlines of the chart area, plot area, series and single points (c:spPr: solid, the first colour of a
+// gradient or pattern, none) and the theme's accent colours for the rest; manual layouts of the plot area and legend.
+// 3D charts, radar, bubble, stock, surface and bar-of-pie charts are named instead (LeftOut), and their documents say
+// "charts" were left out, or take LibreOffice where the capability checks send them.
+//
+// Hostile input: the part comes through the package's XML limits; series per chart and points per chart (a cache's
+// ptCount or highest c:idx, not only the points it holds) are bounded and a part beyond is refused with
+// error.document_too_complex; texts are cut at MaxText characters and titles at MaxLines lines; numbers that aren't
+// finite are blanks and the rest are clamped to ±MaxValue, so scaling can't overflow.
+
+using System.Globalization;
+using System.Xml.Linq;
+using Filee.Engines.Documents;
+using Filee.Engines.Office.Sheets;
+using Filee.Engines.Slides;
+using SkiaSharp;
+
+namespace Filee.Engines.Charts;
+
+/// A chart part read: the chart when it can be drawn, else what is left out ("charts").
+internal readonly record struct ChartRead(Chart? Chart, string? LeftOut);
+
+internal sealed class ChartReader
+{
+ public static readonly XNamespace C = "http://schemas.openxmlformats.org/drawingml/2006/chart";
+ private static readonly XNamespace A = DrawingColors.A;
+
+ /// Series in one chart at most (Excel allows 255).
+ internal const int MaxSeries = 1024;
+
+ /// Points of all series of one chart together at most (Excel's rows: a column of a whole sheet).
+ internal const int MaxPoints = 1_048_576;
+
+ /// Characters of one text (a title, a label, a series name) kept; the rest is cut.
+ internal const int MaxText = 1024;
+
+ /// Lines of one title kept.
+ internal const int MaxLines = 16;
+
+ /// The largest value magnitude kept; larger ones are clamped (Excel's largest number is about 1e308).
+ internal const double MaxValue = 1e100;
+
+ /// The plots ChartDrawer draws, by element name.
+ private static readonly Dictionary Kinds = new(StringComparer.Ordinal)
+ {
+ ["barChart"] = ChartKind.Bar,
+ ["lineChart"] = ChartKind.Line,
+ ["areaChart"] = ChartKind.Area,
+ ["pieChart"] = ChartKind.Pie,
+ ["doughnutChart"] = ChartKind.Doughnut,
+ ["scatterChart"] = ChartKind.Scatter,
+ };
+
+ /// Plots that are named instead of drawn.
+ private static readonly HashSet Unsupported = new(StringComparer.Ordinal)
+ {
+ "bar3DChart", "line3DChart", "area3DChart", "pie3DChart", "radarChart", "bubbleChart", "stockChart", "surfaceChart",
+ "surface3DChart", "ofPieChart",
+ };
+
+ private readonly DrawingColors _colors;
+ private readonly string? _themeFont;
+ private readonly NumberFormatter _formatter;
+ private int _points;
+
+ private ChartReader(DrawingColors colors, string? themeFont, bool date1904)
+ {
+ _colors = colors;
+ _themeFont = themeFont;
+ _formatter = new NumberFormatter(date1904);
+ }
+
+ /// The theme's body font (a:minorFont a:latin) of a theme part, or null.
+ public static string? ThemeFont(XElement? theme) =>
+ (string?)theme?.Descendants(A + "minorFont").FirstOrDefault()?.Element(A + "latin")?.Attribute("typeface") is { Length: > 0 } font ? font : null;
+
+ ///
+ /// Reads chart part (its c:chartSpace) with the host's theme colours and body font.
+ ///
+ /// The chart has more series or points than Filee draws.
+ public static ChartRead Read(XElement? root, DrawingColors colors, string? themeFont = null)
+ {
+ if (root is null || root.Name != C + "chartSpace" || root.Element(C + "chart") is not { } chart)
+ return new(null, "charts");
+ var date1904 = Bool(root.Element(C + "date1904"), false);
+ if (root.Element(C + "clrMapOvr") is { } map)
+ colors = colors.WithMap(map);
+ return new ChartReader(colors, themeFont, date1904).ReadChart(root, chart, date1904);
+ }
+
+ private ChartRead ReadChart(XElement root, XElement chart, bool date1904)
+ {
+ var plotArea = chart.Element(C + "plotArea");
+ if (plotArea is null)
+ return new(null, "charts");
+ var text = Style(new ChartTextStyle(_themeFont, 10, false, false, SKColors.Black), DefaultRun(root.Element(C + "txPr")));
+ var plots = new List();
+ foreach (var element in plotArea.Elements())
+ {
+ var name = element.Name.LocalName;
+ if (element.Name.Namespace != C)
+ continue;
+ if (Unsupported.Contains(name))
+ return new(null, "charts");
+ if (Kinds.TryGetValue(name, out var kind))
+ plots.Add(Plot(element, kind, text));
+ }
+ if (plots.Count == 0 || plots.All(p => p.Series.Count == 0))
+ return new(null, "charts");
+
+ var series = plots.SelectMany(p => p.Series).ToList();
+ var result = new Chart
+ {
+ Title = ChartTitle(chart, text, series),
+ Legend = Legend(chart.Element(C + "legend"), text),
+ Area = Shape(root.Element(C + "spPr")),
+ PlotArea = Shape(plotArea.Element(C + "spPr")),
+ PlotLayout = Layout(plotArea.Element(C + "layout")),
+ RoundedCorners = Bool(root.Element(C + "roundedCorners"), true),
+ BlanksAs = Val(chart.Element(C + "dispBlanksAs")) is ("zero" or "span") and var blanks ? blanks : "gap",
+ Date1904 = date1904,
+ Text = text,
+ Palette = new ChartPalette([.. Enumerable.Range(1, 6).Select(i => _colors.Scheme($"accent{i}"))]),
+ ThemeFont = _themeFont,
+ };
+ result.Plots.AddRange(plots);
+ foreach (var axis in plotArea.Elements())
+ {
+ if (axis.Name.Namespace == C && axis.Name.LocalName is "catAx" or "valAx" or "dateAx")
+ result.Axes.Add(Axis(axis, text));
+ }
+ return new(result, null);
+ }
+
+ // ───────────────────────── Plots and series ─────────────────────────
+
+ private ChartPlot Plot(XElement element, ChartKind kind, ChartTextStyle text)
+ {
+ var grouping = Val(element.Element(C + "grouping")) switch
+ {
+ "stacked" => ChartGrouping.Stacked,
+ "percentStacked" => ChartGrouping.PercentStacked,
+ _ => ChartGrouping.Standard,
+ };
+ var scatterStyle = Val(element.Element(C + "scatterStyle")) ?? "marker";
+ var plot = new ChartPlot
+ {
+ Kind = kind,
+ Grouping = kind is ChartKind.Pie or ChartKind.Doughnut or ChartKind.Scatter ? ChartGrouping.Standard : grouping,
+ Horizontal = Val(element.Element(C + "barDir")) == "bar",
+ // Pies and doughnuts colour their slices unless the file says not to.
+ VaryColors = Bool(element.Element(C + "varyColors"), kind is ChartKind.Pie or ChartKind.Doughnut ? element.Element(C + "varyColors") is null : false),
+ GapWidth = (int)Math.Clamp(Number(element.Element(C + "gapWidth")) ?? 150, 0, 500),
+ Overlap = (int)Math.Clamp(Number(element.Element(C + "overlap")) ?? (grouping == ChartGrouping.Standard ? 0 : 100), -100, 100),
+ HoleSize = (int)Math.Clamp(Number(element.Element(C + "holeSize")) ?? 50, 1, 90),
+ FirstSliceAngle = Math.Clamp(Number(element.Element(C + "firstSliceAng")) ?? 0, 0, 360),
+ Lines = kind != ChartKind.Scatter || scatterStyle is "lineMarker" or "line" or "smooth" or "smoothMarker",
+ Markers = kind == ChartKind.Line ? Bool(element.Element(C + "marker"), true)
+ : kind == ChartKind.Scatter && scatterStyle is "lineMarker" or "marker" or "smoothMarker",
+ Labels = Labels(element.Element(C + "dLbls"), text),
+ AxisIds = [.. element.Elements(C + "axId").Select(a => (uint)Math.Clamp(Number(a) ?? 0, 0, uint.MaxValue))],
+ };
+ foreach (var ser in element.Elements(C + "ser"))
+ {
+ if (plot.Series.Count >= MaxSeries)
+ throw DocumentLimits.Exceeded($"A chart has more than {DocumentLimits.Count(MaxSeries)} series.");
+ plot.Series.Add(Series(ser, kind, text, plot.Series.Count));
+ }
+ // c:order sets the drawing order.
+ var order = element.Elements(C + "ser").Select((s, i) => (Order: Number(s.Element(C + "order")) ?? i, Index: i)).ToList();
+ if (order.Select(o => o.Order).Distinct().Count() == order.Count)
+ {
+ var sorted = order.OrderBy(o => o.Order).Select(o => plot.Series[o.Index]).ToList();
+ plot.Series.Clear();
+ plot.Series.AddRange(sorted);
+ }
+ return plot;
+ }
+
+ private ChartSeries Series(XElement ser, ChartKind kind, ChartTextStyle text, int position)
+ {
+ var scatter = kind == ChartKind.Scatter;
+ var values = Numbers(ser.Element(C + (scatter ? "yVal" : "val")), out var format);
+ IReadOnlyList? categories = null;
+ IReadOnlyList? xValues = null;
+ if (ser.Element(C + (scatter ? "xVal" : "cat")) is { } cat)
+ {
+ if (scatter && (cat.Element(C + "numRef") is not null || cat.Element(C + "numLit") is not null))
+ xValues = Numbers(cat, out _);
+ else
+ categories = Labels(cat);
+ }
+ var points = new Dictionary();
+ var explosion = new Dictionary();
+ if (Number(ser.Element(C + "explosion")) is { } whole)
+ explosion[-1] = (int)Math.Clamp(whole, 0, 400);
+ foreach (var point in ser.Elements(C + "dPt"))
+ {
+ if (Number(point.Element(C + "idx")) is not { } index || index < 0 || index >= MaxPoints)
+ continue;
+ points[(int)index] = Shape(point.Element(C + "spPr"));
+ if (Number(point.Element(C + "explosion")) is { } pulled)
+ explosion[(int)index] = (int)Math.Clamp(pulled, 0, 400);
+ }
+ return new ChartSeries
+ {
+ Name = SeriesName(ser.Element(C + "tx")),
+ Index = (int)Math.Clamp(Number(ser.Element(C + "idx")) ?? position, 0, MaxSeries * 64),
+ Categories = categories,
+ XValues = xValues,
+ Values = values,
+ Format = format,
+ Style = Shape(ser.Element(C + "spPr")),
+ Points = points,
+ Explosion = explosion,
+ Marker = ser.Element(C + "marker") is { } marker ? Marker(marker) : null,
+ Labels = Labels(ser.Element(C + "dLbls"), text),
+ Smooth = Bool(ser.Element(C + "smooth"), false),
+ };
+ }
+
+ private ChartMarker Marker(XElement marker) => new(
+ Val(marker.Element(C + "symbol")) ?? "auto",
+ (float)Math.Clamp(Number(marker.Element(C + "size")) ?? 5, 2, 72),
+ Shape(marker.Element(C + "spPr")));
+
+ private string? SeriesName(XElement? tx)
+ {
+ if (tx is null)
+ return null;
+ if (tx.Element(C + "v") is { } literal)
+ return Cut(literal.Value);
+ var cache = tx.Element(C + "strRef")?.Element(C + "strCache");
+ return cache?.Elements(C + "pt").FirstOrDefault()?.Element(C + "v")?.Value is { } name ? Cut(name) : null;
+ }
+
+ /// Category labels of c:cat: text, numbers in their format, or the innermost level of several.
+ private IReadOnlyList? Labels(XElement cat)
+ {
+ if ((cat.Element(C + "strRef")?.Element(C + "strCache") ?? cat.Element(C + "strLit")) is { } strings)
+ return Points(strings, v => Cut(v));
+ if ((cat.Element(C + "numRef")?.Element(C + "numCache") ?? cat.Element(C + "numLit")) is { } numbers)
+ {
+ var code = (string?)numbers.Element(C + "formatCode");
+ return Points(numbers, v => Finite(v) is { } value ? Cut(_formatter.Format(value, code)) : Cut(v));
+ }
+ if (cat.Element(C + "multiLvlStrRef")?.Element(C + "multiLvlStrCache") is { } levels && levels.Element(C + "lvl") is { } inner)
+ {
+ return Points(inner, v => Cut(v), Count(levels));
+ }
+ return null;
+ }
+
+ /// The numbers of c:val, c:yVal or c:xVal (blanks null), with their format code.
+ private IReadOnlyList Numbers(XElement? element, out string? format)
+ {
+ format = null;
+ var cache = element?.Element(C + "numRef")?.Element(C + "numCache") ?? element?.Element(C + "numLit");
+ if (cache is null)
+ return [];
+ format = (string?)cache.Element(C + "formatCode") is { Length: > 0 } code && !NumberFormatter.IsGeneral(code) ? code : null;
+ return Points(cache, Finite);
+ }
+
+ /// A cache's points by c:idx, as many as its c:ptCount or highest index says, counted against .
+ private List Points(XElement cache, Func value, int? count = null)
+ {
+ var points = new List<(int Index, string Value)>();
+ var highest = -1;
+ foreach (var pt in cache.Elements(C + "pt"))
+ {
+ if (Number(pt.Attribute("idx")) is not { } index || index < 0)
+ continue;
+ if (index >= MaxPoints)
+ throw TooMany();
+ points.Add(((int)index, pt.Element(C + "v")?.Value ?? ""));
+ highest = Math.Max(highest, (int)index);
+ }
+ var length = (long)Math.Max(highest + 1, Math.Min(count ?? Count(cache), MaxPoints + 1L));
+ if ((_points += (int)Math.Min(length, MaxPoints + 1L)) > MaxPoints)
+ throw TooMany();
+ var result = new List((int)length);
+ for (var i = 0; i < length; i++)
+ result.Add(default);
+ foreach (var (index, text) in points)
+ result[index] = value(text);
+ return result;
+ }
+
+ private static int Count(XElement cache) => (int)Math.Clamp(Number(cache.Element(C + "ptCount")) ?? 0, 0, MaxPoints + 1L);
+
+ private static Core.Conversion.ConversionRefusedException TooMany() =>
+ DocumentLimits.Exceeded($"A chart has more than {DocumentLimits.Count(MaxPoints)} points.");
+
+ private static double? Finite(string text) =>
+ double.TryParse(text, NumberStyles.Float, CultureInfo.InvariantCulture, out var value) && double.IsFinite(value)
+ ? Math.Clamp(value, -MaxValue, MaxValue)
+ : null;
+
+ // ───────────────────────── Axes ─────────────────────────
+
+ private ChartAxis Axis(XElement axis, ChartTextStyle text)
+ {
+ var scaling = axis.Element(C + "scaling");
+ var numberFormat = axis.Element(C + "numFmt");
+ var txPr = axis.Element(C + "txPr");
+ var rotation = Number(txPr?.Element(A + "bodyPr")?.Attribute("rot")) is { } rot && rot is > -5_400_001 and < 5_400_001 ? rot / 60000 : (double?)null;
+ var crosses = Val(axis.Element(C + "crosses"));
+ var value = axis.Name.LocalName == "valAx";
+ return new ChartAxis
+ {
+ Id = (uint)Math.Clamp(Number(axis.Element(C + "axId")) ?? 0, 0, uint.MaxValue),
+ IsValue = value,
+ Position = Val(axis.Element(C + "axPos")) is ("l" or "r" or "t" or "b") and var position ? position : "b",
+ Deleted = Bool(axis.Element(C + "delete"), false),
+ Reversed = Val(scaling?.Element(C + "orientation")) == "maxMin",
+ Min = Number(scaling?.Element(C + "min")) is { } min ? Math.Clamp(min, -MaxValue, MaxValue) : null,
+ Max = Number(scaling?.Element(C + "max")) is { } max ? Math.Clamp(max, -MaxValue, MaxValue) : null,
+ MajorUnit = Number(axis.Element(C + "majorUnit")) is > 0 and var unit ? Math.Min(unit, MaxValue) : null,
+ LogBase = Number(scaling?.Element(C + "logBase")) is >= 2 and <= 1000 and var log ? log : null,
+ Title = axis.Element(C + "title") is { } title ? Title(title, text with { Bold = true }, null) : null,
+ Format = numberFormat is not null && !Bool(numberFormat.Attribute("sourceLinked"), false) ? (string?)numberFormat.Attribute("formatCode") : null,
+ MajorGridlines = axis.Element(C + "majorGridlines") is { } major ? Line(major.Element(C + "spPr")?.Element(A + "ln")) ?? new ChartLine() : null,
+ MinorGridlines = axis.Element(C + "minorGridlines") is { } minor ? Line(minor.Element(C + "spPr")?.Element(A + "ln")) ?? new ChartLine() : null,
+ Line = Line(axis.Element(C + "spPr")?.Element(A + "ln")),
+ LabelPosition = Val(axis.Element(C + "tickLblPos")) ?? "nextTo",
+ MajorTicks = Val(axis.Element(C + "majorTickMark")) ?? "out",
+ Crosses = axis.Element(C + "crossesAt") is not null ? ChartCrossing.At : crosses switch { "min" => ChartCrossing.Min, "max" => ChartCrossing.Max, _ => ChartCrossing.AutoZero },
+ CrossesAt = Math.Clamp(Number(axis.Element(C + "crossesAt")) ?? 0, -MaxValue, MaxValue),
+ CrossAxis = (uint)Math.Clamp(Number(axis.Element(C + "crossAx")) ?? 0, 0, uint.MaxValue),
+ Between = Val(axis.Element(C + "crossBetween")) != "midCat",
+ LabelSkip = (int)Math.Clamp(Number(axis.Element(C + "tickLblSkip")) ?? 0, 0, MaxPoints),
+ LabelRotation = rotation,
+ Style = Style(text, DefaultRun(txPr)),
+ };
+ }
+
+ // ───────────────────────── Title, legend, labels ─────────────────────────
+
+ private ChartTitle? ChartTitle(XElement chart, ChartTextStyle text, List series)
+ {
+ var deleted = Bool(chart.Element(C + "autoTitleDeleted"), false);
+ var style = text with { Size = text.Size * 1.8f, Bold = true };
+ var lone = series.Count == 1 && series[0].Name is { Length: > 0 } name ? name : null;
+ if (chart.Element(C + "title") is { } title)
+ return Title(title, style, lone ?? "Chart Title");
+ // Office titles a chart of one named series with its name until the title is deleted.
+ return !deleted && lone is not null ? new ChartTitle([lone], style) : null;
+ }
+
+ /// A c:title: its rich text or a cell's text, else (null: no title).
+ private ChartTitle? Title(XElement title, ChartTextStyle style, string? automatic)
+ {
+ style = Style(style, DefaultRun(title.Element(C + "txPr")));
+ var overlay = Bool(title.Element(C + "overlay"), false);
+ var layout = Layout(title.Element(C + "layout"));
+ var tx = title.Element(C + "tx");
+ if (tx?.Element(C + "rich") is { } rich)
+ {
+ var lines = new List();
+ var first = true;
+ foreach (var paragraph in rich.Elements(A + "p").Take(MaxLines))
+ {
+ var defaults = paragraph.Element(A + "pPr")?.Element(A + "defRPr");
+ if (first)
+ style = Style(style, defaults);
+ var line = new System.Text.StringBuilder();
+ foreach (var run in paragraph.Elements())
+ {
+ if (run.Name == A + "br")
+ {
+ lines.Add(Cut(line.ToString()));
+ line.Clear();
+ continue;
+ }
+ if (run.Name != A + "r" && run.Name != A + "fld")
+ continue;
+ if (first)
+ {
+ style = Style(style, run.Element(A + "rPr"));
+ first = false;
+ }
+ if (line.Length < MaxText)
+ line.Append(run.Element(A + "t")?.Value);
+ }
+ lines.Add(Cut(line.ToString()));
+ if (lines.Count >= MaxLines)
+ break;
+ }
+ return new ChartTitle([.. lines.Take(MaxLines)], style, overlay) { Layout = layout };
+ }
+ if (tx?.Element(C + "strRef")?.Element(C + "strCache")?.Elements(C + "pt").FirstOrDefault()?.Element(C + "v")?.Value is { } cell)
+ return new ChartTitle([.. Cut(cell).Split('\n').Take(MaxLines)], style, overlay) { Layout = layout };
+ return automatic is null ? null : new ChartTitle([automatic], style, overlay) { Layout = layout };
+ }
+
+ private ChartLegend? Legend(XElement? legend, ChartTextStyle text)
+ {
+ if (legend is null)
+ return null;
+ var deleted = new HashSet();
+ foreach (var entry in legend.Elements(C + "legendEntry"))
+ {
+ if (Bool(entry.Element(C + "delete"), false) && Number(entry.Element(C + "idx")) is { } index && index is >= 0 and < MaxPoints)
+ deleted.Add((int)index);
+ }
+ return new ChartLegend
+ {
+ Position = Val(legend.Element(C + "legendPos")) is ("r" or "l" or "t" or "b" or "tr") and var position ? position : "r",
+ Overlay = Bool(legend.Element(C + "overlay"), false),
+ Deleted = deleted,
+ Layout = Layout(legend.Element(C + "layout")),
+ Style = Style(text, DefaultRun(legend.Element(C + "txPr"))),
+ };
+ }
+
+ private ChartLabels? Labels(XElement? labels, ChartTextStyle text)
+ {
+ if (labels is null)
+ return null;
+ if (Bool(labels.Element(C + "delete"), false))
+ return new ChartLabels(false, false, false, false, null, null, text);
+ var format = labels.Element(C + "numFmt") is { } numFmt && !Bool(numFmt.Attribute("sourceLinked"), false) ? (string?)numFmt.Attribute("formatCode") : null;
+ return new ChartLabels(
+ Bool(labels.Element(C + "showVal"), false),
+ Bool(labels.Element(C + "showCatName"), false),
+ Bool(labels.Element(C + "showSerName"), false),
+ Bool(labels.Element(C + "showPercent"), false),
+ Val(labels.Element(C + "dLblPos")),
+ format,
+ Style(text, DefaultRun(labels.Element(C + "txPr"))));
+ }
+
+ private static ChartLayout? Layout(XElement? layout)
+ {
+ if (layout?.Element(C + "manualLayout") is not { } manual)
+ return null;
+ // Only boxes placed from the chart's edges are taken; factors of the automatic place are left to it.
+ if (Val(manual.Element(C + "xMode")) is "factor" || Val(manual.Element(C + "yMode")) is "factor"
+ || Number(manual.Element(C + "x")) is not { } x || Number(manual.Element(C + "y")) is not { } y)
+ return null;
+ static double? Fraction(double? value) => value is { } v ? Math.Clamp(v, 0, 1) : null;
+ return new ChartLayout(Math.Clamp(x, 0, 1), Math.Clamp(y, 0, 1), Fraction(Number(manual.Element(C + "w"))), Fraction(Number(manual.Element(C + "h"))),
+ Val(manual.Element(C + "layoutTarget")) == "inner");
+ }
+
+ // ───────────────────────── Fills, lines, text ─────────────────────────
+
+ private ChartShapeStyle Shape(XElement? properties) =>
+ properties is null ? ChartShapeStyle.Auto : new ChartShapeStyle { Fill = Fill(properties), Line = Line(properties.Element(A + "ln")) };
+
+ private SKColor? Fill(XElement properties)
+ {
+ var fill = properties.Elements().FirstOrDefault(e => e.Name.Namespace == A && e.Name.LocalName is "noFill" or "solidFill" or "gradFill" or "pattFill");
+ return fill?.Name.LocalName switch
+ {
+ "noFill" => SKColors.Transparent,
+ "solidFill" => _colors.Color(fill),
+ "gradFill" => _colors.Color(fill.Element(A + "gsLst")?.Elements(A + "gs").FirstOrDefault()),
+ "pattFill" => _colors.Color(fill.Element(A + "fgClr")),
+ _ => null,
+ };
+ }
+
+ private ChartLine? Line(XElement? line)
+ {
+ if (line is null)
+ return null;
+ var fill = line.Elements().FirstOrDefault(e => e.Name.Namespace == A && e.Name.LocalName is "noFill" or "solidFill" or "gradFill" or "pattFill");
+ if (fill?.Name.LocalName == "noFill")
+ return ChartLine.Hidden;
+ var color = fill?.Name.LocalName switch
+ {
+ "solidFill" => _colors.Color(fill),
+ "gradFill" => _colors.Color(fill.Element(A + "gsLst")?.Elements(A + "gs").FirstOrDefault()),
+ "pattFill" => _colors.Color(fill.Element(A + "fgClr")),
+ _ => null,
+ };
+ var width = Number(line.Attribute("w")) is { } w ? (float)Math.Clamp(w / 12700, 0, 100) : (float?)null;
+ var dash = Val(line.Element(A + "prstDash")) switch
+ {
+ "dot" or "sysDot" => [1f, 1.5f],
+ "dash" or "sysDash" => [4f, 3f],
+ "lgDash" => [8f, 3f],
+ "dashDot" or "sysDashDot" => [4f, 3f, 1f, 3f],
+ "lgDashDot" => [8f, 3f, 1f, 3f],
+ "lgDashDotDot" or "sysDashDotDot" => [8f, 3f, 1f, 3f, 1f, 3f],
+ _ => (float[]?)null,
+ };
+ return new ChartLine(color, width, dash);
+ }
+
+ /// The default run properties of a c:txPr (its first paragraph's a:defRPr).
+ private static XElement? DefaultRun(XElement? txPr) => txPr?.Element(A + "p")?.Element(A + "pPr")?.Element(A + "defRPr");
+
+ /// with what run properties (a:rPr, a:defRPr) set.
+ private ChartTextStyle Style(ChartTextStyle style, XElement? run)
+ {
+ if (run is null)
+ return style;
+ if (Number(run.Attribute("sz")) is { } size && size >= 100)
+ style = style with { Size = (float)Math.Min(size / 100, 400) };
+ if (run.Attribute("b") is { } bold)
+ style = style with { Bold = Bool(bold, false) };
+ if (run.Attribute("i") is { } italic)
+ style = style with { Italic = Bool(italic, false) };
+ if (run.Element(A + "solidFill") is { } fill && _colors.Color(fill) is { } color)
+ style = style with { Color = color };
+ if ((string?)(run.Element(A + "latin") ?? run.Element(A + "ea"))?.Attribute("typeface") is { Length: > 0 } family)
+ style = style with { Family = family.StartsWith('+') ? _themeFont : family };
+ return style;
+ }
+
+ // ───────────────────────── Values ─────────────────────────
+
+ private static string? Val(XElement? element) => (string?)element?.Attribute("val");
+
+ private static double? Number(XElement? element) => Number(element?.Attribute("val"));
+
+ private static double? Number(XAttribute? attribute) =>
+ double.TryParse((string?)attribute, NumberStyles.Float, CultureInfo.InvariantCulture, out var value) && double.IsFinite(value) ? value : null;
+
+ /// A CT_Boolean: an element without val is true; when there is no element.
+ private static bool Bool(XElement? element, bool absent) => element is null ? absent : Bool(element.Attribute("val"), true);
+
+ private static bool Bool(XAttribute? attribute, bool absent) => (string?)attribute switch
+ {
+ null => absent,
+ "1" or "true" or "on" => true,
+ _ => false,
+ };
+
+ private static string Cut(string text) => text.Length > MaxText ? text[..MaxText] : text;
+}
+
+///
+/// The points one document's charts draw together, each chart counted every time it is placed (a part placed many
+/// times draws many times), so a small file can't make drawing take hours; beyond, the document is refused.
+///
+internal sealed class ChartBudget
+{
+ /// Points drawn per document at most: ten full-sheet charts.
+ internal const long MaxPoints = 10L * ChartReader.MaxPoints;
+
+ private long _points;
+
+ public void Charge(Chart chart)
+ {
+ if ((_points += Math.Max(1, chart.PointCount)) > MaxPoints)
+ throw DocumentLimits.Exceeded($"The document's charts draw more than {DocumentLimits.Count(MaxPoints)} points.");
+ }
+}
diff --git a/src/Filee.Engines/Charts/ChartText.cs b/src/Filee.Engines/Charts/ChartText.cs
new file mode 100644
index 000000000..d380746c4
--- /dev/null
+++ b/src/Filee.Engines/Charts/ChartText.cs
@@ -0,0 +1,106 @@
+// Text of a chart (titles, axis and data labels, legend entries) on the layout engine's services: the font a style
+// names (or the theme's body font, else Calibri and what stands in for it), the fonts its characters fall back to,
+// shaped with HarfBuzz and drawn as glyph runs, so a PDF keeps the chart's text as text.
+
+using Filee.Engines.Rendering;
+using Filee.Engines.Typesetting;
+using SkiaSharp;
+
+namespace Filee.Engines.Charts;
+
+/// Fonts and shaping for chart text; dispose to release a shaper it made itself.
+internal sealed class ChartFonts : IDisposable
+{
+ private readonly FontResolver _resolver;
+ private readonly Shaper _shaper;
+ private readonly bool _ownsShaper;
+ private readonly Dictionary<(string? Family, bool Bold, bool Italic), ResolvedFont?> _fonts = [];
+ private readonly Dictionary _metrics = new(ReferenceEqualityComparer.Instance);
+
+ /// The renderer's font resolver, or null for the installed fonts.
+ /// The renderer's shaper (not disposed here), or null for one of its own.
+ public ChartFonts(FontResolver? resolver = null, Shaper? shaper = null)
+ {
+ _resolver = resolver ?? new FontResolver();
+ _ownsShaper = shaper is null;
+ _shaper = shaper ?? new Shaper();
+ }
+
+ public void Dispose()
+ {
+ if (_ownsShaper)
+ _shaper.Dispose();
+ }
+
+ /// One line of in at points.
+ public ChartTextLine Line(string text, ChartTextStyle style, float size)
+ {
+ var line = new ChartTextLine(text, style.Color, size);
+ if (Font(style) is not { } primary || size <= 0 || !float.IsFinite(size))
+ return line;
+ var metrics = Metrics(primary.Font);
+ var em = (float)Math.Max(1, metrics.UnitsPerEm);
+ line.Ascent = metrics.Ascender / em * size;
+ line.Descent = -metrics.Descender / em * size;
+ if (line.Ascent <= 0)
+ (line.Ascent, line.Descent) = (size * 0.8f, size * 0.2f);
+ if (text.Length == 0)
+ return line;
+ foreach (var run in _resolver.Fallback(text, 0, text.Length, primary, FontStyle.From(style.Bold, style.Italic)))
+ {
+ var shaped = _shaper.Shape(run.Font.Font, text, run.Start, run.Length);
+ line.Runs.Add((run.Font, shaped, run.Start, run.Length));
+ line.Width += shaped.Width(size);
+ }
+ return line;
+ }
+
+ private ResolvedFont? Font(ChartTextStyle style)
+ {
+ var key = (style.Family, style.Bold, style.Italic);
+ if (!_fonts.TryGetValue(key, out var font))
+ {
+ var fontStyle = FontStyle.From(style.Bold, style.Italic);
+ _fonts[key] = font = _resolver.Resolve(style.Family ?? "Calibri", fontStyle) ?? _resolver.Resolve(null, fontStyle);
+ }
+ return font;
+ }
+
+ private FontMetrics Metrics(PageFont font)
+ {
+ if (!_metrics.TryGetValue(font, out var metrics))
+ _metrics[font] = metrics = _shaper.Metrics(font);
+ return metrics;
+ }
+}
+
+/// A line of chart text, shaped: its width, ascent and descent in points, drawn at a pen position.
+internal sealed class ChartTextLine(string text, SKColor color, float size)
+{
+ public string Text { get; } = text;
+ public float Width { get; set; }
+ public float Ascent { get; set; }
+ public float Descent { get; set; }
+ public float Height => Ascent + Descent;
+
+ internal List<(ResolvedFont Font, ShapedRun Run, int Start, int Length)> Runs { get; } = [];
+
+ /// Draws the line with its pen at (, ) in 's frame.
+ public void Draw(PageContent page, float x, float baseline, SKMatrix? transform, SKRect? clip)
+ {
+ foreach (var (font, run, start, length) in Runs)
+ {
+ var glyphs = run.ToGlyphRun(font.Font, size, new SKPoint(x, baseline), Text.Substring(start, length)) with
+ {
+ Color = color,
+ Embolden = font.SyntheticBold,
+ SkewX = font.SyntheticItalic ? GlyphRun.SyntheticSlant : 0,
+ Transform = transform,
+ Clip = clip,
+ };
+ if (glyphs.Glyphs.Length > 0)
+ page.DrawGlyphs(glyphs);
+ x += run.Width(size);
+ }
+ }
+}
diff --git a/src/Filee.Engines/Ebooks/EbookConverter.cs b/src/Filee.Engines/Ebooks/EbookConverter.cs
index 7bde7435b..7e69720ba 100644
--- a/src/Filee.Engines/Ebooks/EbookConverter.cs
+++ b/src/Filee.Engines/Ebooks/EbookConverter.cs
@@ -176,7 +176,7 @@ private static void Write(Book book, ConversionStep step, string output, string
{
// One self-contained page: pictures are embedded as data: URIs.
var images = EbookFiles.NewFolder(work, "html-images");
- var page = XhtmlWriter.Write(book.Document, new XhtmlOptions { ImageSource = path => DataUri(path, images) }).Single();
+ var page = XhtmlWriter.Write(book.Document, new XhtmlOptions { ImageSource = path => DataUri(path, images), MathML = true }).Single();
File.WriteAllText(output, XhtmlWriter.Page(book.DisplayTitle(step.InputPath), page.Body, book.DisplayLanguage(), null, epub: false), new UTF8Encoding(false));
break;
}
diff --git a/src/Filee.Engines/Ebooks/EpubWriter.cs b/src/Filee.Engines/Ebooks/EpubWriter.cs
index 82781e96e..c45df2919 100644
--- a/src/Filee.Engines/Ebooks/EpubWriter.cs
+++ b/src/Filee.Engines/Ebooks/EpubWriter.cs
@@ -28,6 +28,7 @@ public static void Write(Book book, string outputPath, string sourcePath, string
ChapterFile = i => $"ch{i + 1:000}.xhtml",
ImageSource = path => package.AddImage(path, imageFolder),
Epub = true,
+ MathML = true,
});
// A cover page for covers the content does not show already (MOBI and FB2 keep the cover apart).
@@ -185,7 +186,11 @@ private string Opf(string identifier, bool fixedLayout)
sb.Append("- \n");
sb.Append("
- \n");
for (var i = 0; i < _pages.Count; i++)
- sb.Append($"
- \n");
+ {
+ // EPUB 3 names the pages with MathML in them.
+ var mathml = _pages[i].Content.Contains("
| |