Fonts in Documents
A workbook stores the names of its fonts in its cell styles, not the fonts themselves. TX Sheet Control renders it with the fonts of the deployment, as Font Handling describes. Beyond that, you can supply fonts with a single document when you load it, map font names to other families, and embed the used fonts in the files you save, so that another TX Sheet Control application shows the document with the same fonts.
Fonts a Document Brings
When TX Sheet Control loads a file, it reads the fonts the file contains:
- ODS files with local font-face references and embedded TrueType fonts.
- XLSX files with font files in
xl/fontsand the font catalog that TX Sheet Control writes. - TXWB files with the fonts in the extension
com.txtextcontrol.fonts.
The fonts of a document belong to that document only. They are not installed on the computer, and closing or replacing the document removes them. Input is limited to 64 font faces, 32 MiB per face and 64 MiB in total. Embedding flags of the fonts are checked, and fonts that cannot be used produce import warnings.
Supply Fonts When Loading
Pass fonts in the fonts load option:
sourceslists complete font faces as Base64 bytes, each with its family and its bold and italic style.resolve, in JavaScript and TypeScript, is an asynchronous callback that TX Sheet Control calls for each missing family or incomplete character set. It receives the family, the style, the text and the reason. Loading waits for its results before it replaces the current document.substitutionsmaps a font name of the workbook to a deployed or supplied family, without changing the cell styles.
In .NET, pass DocumentFontOptions in LoadOptions.Fonts.
await editor.load(inputBytes, StreamType.OpenDocumentSpreadsheet, {
fonts: {
resolve: async request => ({
family: request.family,
bold: request.bold,
italic: request.italic,
base64: await fontProvider(request)
})
}
});
fontProvider stands for a function of your application that returns the Base64 bytes of a licensed font. When a supplied font lacks a character, TX Sheet Control takes it from a fallback font, also for text added later by editing or mail merge.
Embed the Used Fonts When Saving
Set embedUsedFonts: true in the save options, or EmbedUsedFonts = true in the .NET SaveOptions, to include the font files the document uses in a TXWB, ODS or XLSX file. The option is false by default, and PDF files always embed their fonts.
const txwb = await control.save(StreamType.InternalWorkbookFormat, { embedUsedFonts: true });
- What is embedded. The fonts used for rendering: those of the document, of the editor's catalog or of the server's font folder, including the default font. When a cell uses Arial and Arial is replaced with Liberation Sans, the file carries Liberation Sans and records Arial as its original name. A deployed Arial takes precedence.
- Where the fonts go. TXWB stores them in the extension
com.txtextcontrol.fonts, XLSX inxl/fonts. Microsoft Excel does not use these fonts; they are read by TX Sheet Control. - The size. Each embedded font adds its full file. A TXWB file with one cell in Liberation Sans grows from about 1 KB to about 400 KB.
- The open document. The option changes only the saved file, not the cells, the styles or the fonts of the open document. A
Workbookcreated without an editor or a server control has no font host and needs fonts supplied withfonts.sourcesinstead.
Next Steps
- Font Handling: the fonts of the deployment and the replacement fonts.
- Custom Fonts: add fonts to the editor and the server for every document.
- Loading and Saving Workbooks: the load and save options of every format.