/// <summary> /// Returns the width of a single space character in this font, with the given context. /// </summary> /// <param name="graphicsContext"></param> /// <returns></returns> public double GetNormalSpaceWidth(IGraphicsContext graphicsContext) { if (graphicsContext is null) { throw new ArgumentNullException(nameof(graphicsContext)); } return(graphicsContext.MeasureString(Resources.SpaceCharacter, this).Width); }
/// <summary> /// Measure the size of the cell when drawn. /// </summary> /// <param name="context">The graphics context which will be used to measure and draw the cell.</param> public override void MeasureSize(IGraphicsContext context) { if (context is null) { throw new ArgumentNullException(nameof(context)); } string content = Content ?? string.Empty; var metrics = context.MeasureString(content, Font); ContentWidth = metrics.Width; ContentAscent = Font.Ascent; ContentDescent = metrics.Height - ContentAscent; ComputedBaseline = Font.Ascent; ComputedHeight = ContentAscent + ContentDescent; ComputedWidth = MinWidth; }
public static void PopulateSize(this TrainGraphAxisTickInfo tickInfo, IGraphicsContext context, IFontDescriptor font) { if (tickInfo is null) { throw new ArgumentNullException(nameof(tickInfo)); } if (context is null) { throw new ArgumentNullException(nameof(context)); } UniSize measure = context.MeasureString(tickInfo.Label, font); tickInfo.Width = measure.Width; tickInfo.Height = measure.Height; }
/// <summary> /// Construct a <see cref="Word" /> instance. /// </summary> /// <param name="content">The textual content of the word.</param> /// <param name="font">The font to use for display.</param> /// <param name="graphicsContext">The graphics context for providing metrics.</param> /// <param name="postWordSpace">The minimum amount of space to add after the word if it is not at the end of a line.</param> public Word(string content, IFontDescriptor font, IGraphicsContext graphicsContext, double postWordSpace) { if (font is null) { throw new ArgumentNullException(nameof(font)); } Content = content; Font = font; PostWordSpace = postWordSpace; if (string.IsNullOrEmpty(Content) || graphicsContext == null) { ContentWidth = 0; ContentAscent = 0; ContentDescent = 0; } else { var measure = graphicsContext.MeasureString(Content, Font); ContentWidth = measure.Width; ContentAscent = font.Ascent; ContentDescent = measure.Height - ContentAscent; } }