Table of Contents

Interface IXLGraphicEngine

Namespace
SlapKit.Excel.Graphics
Assembly
SlapKit.Excel.dll

An interface to abstract away graphical functionality, like reading images, fonts or to determine a width of a text.

public interface IXLGraphicEngine
Extension Methods

Methods

GetDescent(IXLFontBase, double)

Get font descent in pixels (positive value).

double GetDescent(IXLFontBase font, double dpiY)

Parameters

font IXLFontBase
dpiY double

Returns

double

Remarks

Excel is using OS/2 WinAscent/WinDescent for TrueType fonts (e.g. Calibri), not a correct font ascent/descent.

GetGlyphBox(ReadOnlySpan<int>, IXLFontBase, Dpi)

Get a glyph bounding box for a grapheme cluster.

GlyphBox GetGlyphBox(ReadOnlySpan<int> graphemeCluster, IXLFontBase font, Dpi dpi)

Parameters

graphemeCluster ReadOnlySpan<int>

A part of a string in code points (or runes in C# terminology, not UTF-16 code units) that together form a grapheme. Multiple unicode codepoints can form a single glyph, e.g. family grapheme is a single glyph created from 6 codepoints (man, zero-width-join, woman, zero-width-join and a girl). A string can be split into a grapheme clusters through GetTextElementEnumerator(string).

font IXLFontBase

Font used to determine size of a glyph for the grapheme cluster.

dpi Dpi

A resolution used to determine pixel size of a glyph. Font might be rendered differently at different resolutions.

Returns

GlyphBox

Bounding box containing the glyph.

Remarks

In 99+%, grapheme cluster will be just a codepoint. Method uses grapheme instead, so it can be future-proof signature and have less braking changes. Implementing method by adding widths of individual code points is acceptable.

GetMaxDigitWidth(IXLFontBase, double)

The width of the widest 0-9 digit in pixels.

double GetMaxDigitWidth(IXLFontBase font, double dpiX)

Parameters

font IXLFontBase
dpiX double

Returns

double

Remarks

OOXML measures width of a column in multiples of widest 0-9 digit character in a normal style font.

GetPictureInfo(Stream, XLPictureFormat)

Get the info about a picture (mostly dimensions).

XLPictureInfo GetPictureInfo(Stream imageStream, XLPictureFormat expectedFormat)

Parameters

imageStream Stream

Stream is at the beginning of the image.

expectedFormat XLPictureFormat

The expected format of the image. Use Unknown for auto detection.

Returns

XLPictureInfo

Exceptions

ArgumentException

Unable to determine picture dimensions or format doesn't match the stream.

GetTextHeight(IXLFontBase, double)

Get the height of a text with the font in pixels. Should be EMHeight+descent.

double GetTextHeight(IXLFontBase font, double dpiY)

Parameters

font IXLFontBase
dpiY double

Returns

double

GetTextWidth(string, IXLFontBase, double)

Get the width of a text in pixels. Do not add any padding, there can be multiple spans of a texts with different fonts in a line.

double GetTextWidth(string text, IXLFontBase font, double dpiX)

Parameters

text string
font IXLFontBase
dpiX double

Returns

double