Interface IXLGraphicEngine
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
fontIXLFontBasedpiYdouble
Returns
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
graphemeClusterReadOnlySpan<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).
fontIXLFontBaseFont used to determine size of a glyph for the grapheme cluster.
dpiDpiA 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
fontIXLFontBasedpiXdouble
Returns
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
imageStreamStreamStream is at the beginning of the image.
expectedFormatXLPictureFormatThe expected format of the image. Use Unknown for auto detection.
Returns
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
fontIXLFontBasedpiYdouble
Returns
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
textstringfontIXLFontBasedpiXdouble