本文整理汇总了C#中IRenderContext.MeasureText方法的典型用法代码示例。如果您正苦于以下问题:C# IRenderContext.MeasureText方法的具体用法?C# IRenderContext.MeasureText怎么用?C# IRenderContext.MeasureText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IRenderContext
的用法示例。
在下文中一共展示了IRenderContext.MeasureText方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Render
/// <summary>
/// Renders the text annotation.
/// </summary>
/// <param name="rc">The render context.</param>
/// <param name="model">The plot model.</param>
public override void Render(IRenderContext rc, PlotModel model)
{
base.Render(rc, model);
var position = this.Transform(this.TextPosition) + this.Offset;
var clippingRectangle = this.GetClippingRect();
var textSize = rc.MeasureText(this.Text, this.ActualFont, this.ActualFontSize, this.ActualFontWeight);
rc.SetClip(clippingRectangle);
this.actualBounds = GetTextBounds(
position, textSize, this.Padding, this.TextRotation, this.TextHorizontalAlignment, this.TextVerticalAlignment);
if ((this.TextRotation % 90).Equals(0))
{
var actualRect = new OxyRect(this.actualBounds[0], this.actualBounds[2]);
rc.DrawRectangle(actualRect, this.Background, this.Stroke, this.StrokeThickness);
}
else
{
rc.DrawPolygon(this.actualBounds, this.Background, this.Stroke, this.StrokeThickness);
}
rc.DrawMathText(
position,
this.Text,
this.GetSelectableFillColor(this.ActualTextColor),
this.ActualFont,
this.ActualFontSize,
this.ActualFontWeight,
this.TextRotation,
this.TextHorizontalAlignment,
this.TextVerticalAlignment);
rc.ResetClip();
}
示例2: Render
/// <summary>
/// Renders the series on the specified render context.
/// </summary>
/// <param name="rc">The rendering context.</param>
/// <param name="model">The model.</param>
public override void Render(IRenderContext rc, PlotModel model)
{
if (this.XAxis == null)
{
return;
}
this.symbolPosition = model.PlotArea.Bottom;
this.symbolSize = rc.MeasureText(this.Symbol, this.FontFamily, this.FontSize);
foreach (var v in this.Values)
{
if (double.IsNaN(v) || v < this.XAxis.ActualMinimum || v > this.XAxis.ActualMaximum)
{
continue;
}
double x = this.XAxis.Transform(v);
rc.DrawText(
new ScreenPoint(x, this.symbolPosition),
this.Symbol,
this.Color,
this.FontFamily,
this.FontSize,
FontWeights.Normal,
0,
HorizontalAlignment.Center,
VerticalAlignment.Bottom);
}
}
示例3: Render
/// <summary>
/// Renders the annotation on the specified context.
/// </summary>
/// <param name="rc">The render context.</param>
public override void Render(IRenderContext rc)
{
base.Render(rc);
var lon0 = this.XAxis.ActualMinimum;
var lon1 = this.XAxis.ActualMaximum;
var lat0 = this.YAxis.ActualMinimum;
var lat1 = this.YAxis.ActualMaximum;
// the desired number of tiles horizontally
double tilesx = this.PlotModel.Width / this.TileSize;
// calculate the desired zoom level
var n = tilesx / (((lon1 + 180) / 360) - ((lon0 + 180) / 360));
var zoom = (int)Math.Round(Math.Log(n) / Math.Log(2));
if (zoom < this.MinZoomLevel)
{
zoom = this.MinZoomLevel;
}
if (zoom > this.MaxZoomLevel)
{
zoom = this.MaxZoomLevel;
}
// find tile coordinates for the corners
double x0, y0;
LatLonToTile(lat0, lon0, zoom, out x0, out y0);
double x1, y1;
LatLonToTile(lat1, lon1, zoom, out x1, out y1);
double xmax = Math.Max(x0, x1);
double xmin = Math.Min(x0, x1);
double ymax = Math.Max(y0, y1);
double ymin = Math.Min(y0, y1);
var clippingRectangle = this.GetClippingRect();
// Add the tiles
for (var x = (int)xmin; x < xmax; x++)
{
for (var y = (int)ymin; y < ymax; y++)
{
string uri = this.GetTileUri(x, y, zoom);
var img = this.GetImage(uri, rc.RendersToScreen);
if (img == null)
{
continue;
}
// transform from tile coordinates to lat/lon
double latitude0, latitude1, longitude0, longitude1;
TileToLatLon(x, y, zoom, out latitude0, out longitude0);
TileToLatLon(x + 1, y + 1, zoom, out latitude1, out longitude1);
// transform from lat/lon to screen coordinates
var s00 = this.Transform(longitude0, latitude0);
var s11 = this.Transform(longitude1, latitude1);
var r = OxyRect.Create(s00.X, s00.Y, s11.X, s11.Y);
// draw the image
rc.DrawClippedImage(clippingRectangle, img, r.Left, r.Top, r.Width, r.Height, this.Opacity, true);
}
}
// draw the copyright notice
var p = new ScreenPoint(clippingRectangle.Right - 5, clippingRectangle.Bottom - 5);
var textSize = rc.MeasureText(this.CopyrightNotice, this.ActualFont, this.ActualFontSize, this.ActualFontWeight);
rc.DrawRectangle(new OxyRect(p.X - textSize.Width - 2, p.Y - textSize.Height - 2, textSize.Width + 4, textSize.Height + 4), OxyColor.FromAColor(200, OxyColors.White), OxyColors.Undefined);
rc.DrawText(
p,
this.CopyrightNotice,
OxyColors.Black,
this.ActualFont,
this.ActualFontSize,
this.ActualFontWeight,
0,
HorizontalAlignment.Right,
VerticalAlignment.Bottom);
}
示例4: Render
/// <summary>
/// Renders the text annotation.
/// </summary>
/// <param name="rc">
/// The render context.
/// </param>
/// <param name="model">
/// The plot model.
/// </param>
public override void Render(IRenderContext rc, PlotModel model)
{
base.Render(rc, model);
var position = this.Transform(this.Position);
position.X += this.Offset.X;
position.Y += this.Offset.Y;
var clippingRect = this.GetClippingRect();
var textSize = rc.MeasureText(this.Text, this.ActualFont, this.ActualFontSize, this.ActualFontWeight);
const double MinDistSquared = 4;
this.actualBounds = GetTextBounds(
position, textSize, this.Padding, this.Rotation, this.HorizontalAlignment, this.VerticalAlignment);
rc.DrawClippedPolygon(
this.actualBounds, clippingRect, MinDistSquared, this.Background, this.Stroke, this.StrokeThickness);
rc.DrawClippedText(
clippingRect,
position,
this.Text,
this.GetSelectableFillColor(this.ActualTextColor),
this.ActualFont,
this.ActualFontSize,
this.ActualFontWeight,
this.Rotation,
this.HorizontalAlignment,
this.VerticalAlignment);
}
示例5: InternalDrawMathText
/// <summary>
/// Draws text with sub- and superscript items.
/// </summary>
/// <param name="rc">The render context.</param>
/// <param name="x">The x.</param>
/// <param name="y">The y.</param>
/// <param name="dx">The x offset (in rotated coordinates).</param>
/// <param name="dy">The y offset (in rotated coordinates).</param>
/// <param name="s">The s.</param>
/// <param name="textColor">The text color.</param>
/// <param name="fontFamily">The font family.</param>
/// <param name="fontSize">The font size.</param>
/// <param name="fontWeight">The font weight.</param>
/// <param name="measureOnly">Only measure if set to <c>true</c>.</param>
/// <param name="angle">The angle of the text (degrees).</param>
/// <returns>The size of the text.</returns>
private static OxySize InternalDrawMathText(
IRenderContext rc,
double x,
double y,
double dx,
double dy,
string s,
OxyColor textColor,
string fontFamily,
double fontSize,
double fontWeight,
bool measureOnly,
double angle)
{
var i = 0;
var angleRadian = (angle * Math.PI) / 180.0;
var cosAngle = Math.Round(Math.Cos(angleRadian), 5);
var sinAngle = Math.Round(Math.Sin(angleRadian), 5);
var currentX = x;
var maximumX = x;
var minimumX = x;
var currentY = y;
var maximumY = y;
var minimumY = y;
// http://en.wikipedia.org/wiki/Subscript_and_superscript
var superScriptYDisplacement = fontSize * SuperAlignment;
var subscriptYDisplacement = fontSize * SubAlignment;
var superscriptFontSize = fontSize * SuperSize;
var subscriptFontSize = fontSize * SubSize;
Func<double, double, string, double, OxySize> drawText = (xb, yb, text, fSize) =>
{
if (!measureOnly)
{
var xr = x + ((xb - x + dx) * cosAngle) - ((yb - y + dy) * sinAngle);
var yr = y + ((xb - x + dx) * sinAngle) + ((yb - y + dy) * cosAngle);
rc.DrawText(new ScreenPoint(xr, yr), text, textColor, fontFamily, fSize, fontWeight, angle);
}
var flatSize = rc.MeasureText(text, fontFamily, fSize, fontWeight);
return new OxySize(flatSize.Width, flatSize.Height);
};
while (i < s.Length)
{
// Superscript
if (i + 1 < s.Length && s[i] == '^' && s[i + 1] == '{')
{
var i1 = s.IndexOf('}', i);
if (i1 != -1)
{
var supString = s.Substring(i + 2, i1 - i - 2);
i = i1 + 1;
var sx = currentX;
var sy = currentY + superScriptYDisplacement;
var size = drawText(sx, sy, supString, superscriptFontSize);
maximumX = Math.Max(sx + size.Width, maximumX);
maximumY = Math.Max(sy + size.Height, maximumY);
minimumX = Math.Min(sx, minimumX);
minimumY = Math.Min(sy, minimumY);
continue;
}
}
// Subscript
if (i + 1 < s.Length && s[i] == '_' && s[i + 1] == '{')
{
var i1 = s.IndexOf('}', i);
if (i1 != -1)
{
var subString = s.Substring(i + 2, i1 - i - 2);
i = i1 + 1;
var sx = currentX;
var sy = currentY + subscriptYDisplacement;
var size = drawText(sx, sy, subString, subscriptFontSize);
maximumX = Math.Max(sx + size.Width, maximumX);
maximumY = Math.Max(sy + size.Height, maximumY);
minimumX = Math.Min(sx, minimumX);
minimumY = Math.Min(sy, minimumY);
//.........这里部分代码省略.........
示例6: Measure
/// <summary>
/// Measures the size of the axis (maximum axis label width/height).
/// </summary>
/// <param name="rc">The render context.</param>
/// <returns>The size of the axis.</returns>
public virtual OxySize Measure(IRenderContext rc)
{
IList<double> majorTickValues;
IList<double> minorTickValues;
IList<double> majorLabelValues;
this.GetTickValues(out majorLabelValues, out majorTickValues, out minorTickValues);
var maximumTextSize = new OxySize();
foreach (double v in majorLabelValues)
{
string s = this.FormatValue(v);
var size = rc.MeasureText(s, this.ActualFont, this.ActualFontSize, this.ActualFontWeight);
if (size.Width > maximumTextSize.Width)
{
maximumTextSize.Width = size.Width;
}
if (size.Height > maximumTextSize.Height)
{
maximumTextSize.Height = size.Height;
}
}
var labelTextSize = rc.MeasureText(
this.ActualTitle, this.ActualFont, this.ActualFontSize, this.ActualFontWeight);
double width = 0;
double height = 0;
if (this.IsVertical())
{
switch (this.TickStyle)
{
case TickStyle.Outside:
width += this.MajorTickSize;
break;
case TickStyle.Crossing:
width += this.MajorTickSize * 0.75;
break;
}
width += this.AxisDistance;
width += this.AxisTickToLabelDistance;
width += maximumTextSize.Width;
if (labelTextSize.Height > 0)
{
width += this.AxisTitleDistance;
width += labelTextSize.Height;
}
}
else
{
// caution: this includes AngleAxis because Position=None
switch (this.TickStyle)
{
case TickStyle.Outside:
height += this.MajorTickSize;
break;
case TickStyle.Crossing:
height += this.MajorTickSize * 0.75;
break;
}
height += this.AxisDistance;
height += this.AxisTickToLabelDistance;
height += maximumTextSize.Height;
if (labelTextSize.Height > 0)
{
height += this.AxisTitleDistance;
height += labelTextSize.Height;
}
}
return new OxySize(width, height);
}
示例7: InternalDrawMathText
/// <summary>
/// The internal draw math text.
/// </summary>
/// <param name="rc">
/// The render context.
/// </param>
/// <param name="x">
/// The x.
/// </param>
/// <param name="y">
/// The y.
/// </param>
/// <param name="s">
/// The s.
/// </param>
/// <param name="textColor">
/// The text color.
/// </param>
/// <param name="fontFamily">
/// The font family.
/// </param>
/// <param name="fontSize">
/// The font size.
/// </param>
/// <param name="fontWeight">
/// The font weight.
/// </param>
/// <param name="measureOnly">
/// The measure only.
/// </param>
/// <returns>
/// The size of the text.
/// </returns>
private static OxySize InternalDrawMathText(
IRenderContext rc,
double x,
double y,
string s,
OxyColor textColor,
string fontFamily,
double fontSize,
double fontWeight,
bool measureOnly)
{
int i = 0;
double currentX = x;
double maximumX = x;
double maxHeight = 0;
// http://en.wikipedia.org/wiki/Subscript_and_superscript
double superscriptY = y + fontSize * SuperAlignment;
double superscriptFontSize = fontSize * SuperSize;
double subscriptY = y + fontSize * SubAlignment;
double subscriptFontSize = fontSize * SubSize;
Func<double, double, string, double, OxySize> drawText = (xb, yb, text, fSize) =>
{
if (!measureOnly)
{
rc.DrawText(new ScreenPoint(xb, yb), text, textColor, fontFamily, fSize, fontWeight);
}
return rc.MeasureText(text, fontFamily, fSize, fontWeight);
};
while (i < s.Length)
{
// Superscript
if (i + 1 < s.Length && s[i] == '^' && s[i + 1] == '{')
{
int i1 = s.IndexOf('}', i);
if (i1 != -1)
{
string supString = s.Substring(i + 2, i1 - i - 2);
i = i1 + 1;
OxySize size = drawText(currentX, superscriptY, supString, superscriptFontSize);
if (currentX + size.Width > maximumX)
{
maximumX = currentX + size.Width;
}
continue;
}
}
// Subscript
if (i + 1 < s.Length && s[i] == '_' && s[i + 1] == '{')
{
int i1 = s.IndexOf('}', i);
if (i1 != -1)
{
string subString = s.Substring(i + 2, i1 - i - 2);
i = i1 + 1;
OxySize size = drawText(currentX, subscriptY, subString, subscriptFontSize);
if (currentX + size.Width > maximumX)
{
maximumX = currentX + size.Width;
}
//.........这里部分代码省略.........
示例8: RenderLabelBackground
/// <summary>
/// Renders the contour label background.
/// </summary>
/// <param name="rc">The render context.</param>
/// <param name="cl">The contour label.</param>
private void RenderLabelBackground(IRenderContext rc, ContourLabel cl)
{
if (this.LabelBackground.IsInvisible())
{
return;
}
// Calculate background polygon
var size = rc.MeasureText(cl.Text, this.ActualFont, this.ActualFontSize, this.ActualFontWeight);
double a = cl.Angle / 180 * Math.PI;
double dx = Math.Cos(a);
double dy = Math.Sin(a);
double ux = dx * 0.6;
double uy = dy * 0.6;
double vx = -dy * 0.5;
double vy = dx * 0.5;
double x = cl.Position.X;
double y = cl.Position.Y;
var bpts = new[]
{
new ScreenPoint(x - (size.Width * ux) - (size.Height * vx), y - (size.Width * uy) - (size.Height * vy)),
new ScreenPoint(x + (size.Width * ux) - (size.Height * vx), y + (size.Width * uy) - (size.Height * vy)),
new ScreenPoint(x + (size.Width * ux) + (size.Height * vx), y + (size.Width * uy) + (size.Height * vy)),
new ScreenPoint(x - (size.Width * ux) + (size.Height * vx), y - (size.Width * uy) + (size.Height * vy))
};
rc.DrawPolygon(bpts, this.LabelBackground, OxyColors.Undefined);
}
示例9: RenderTitle
/// <summary>
/// Renders the title and subtitle.
/// </summary>
/// <param name="rc">The render context.</param>
private void RenderTitle(IRenderContext rc)
{
var titleSize = rc.MeasureText(this.Title, this.ActualTitleFont, this.TitleFontSize, this.TitleFontWeight);
double x = (this.TitleArea.Left + this.TitleArea.Right) * 0.5;
double y = this.TitleArea.Top;
if (!string.IsNullOrEmpty(this.Title))
{
rc.DrawMathText(
new ScreenPoint(x, y),
this.Title,
this.TitleColor.GetActualColor(this.TextColor),
this.ActualTitleFont,
this.TitleFontSize,
this.TitleFontWeight,
0,
HorizontalAlignment.Center,
VerticalAlignment.Top);
y += titleSize.Height;
}
if (!string.IsNullOrEmpty(this.Subtitle))
{
rc.DrawMathText(
new ScreenPoint(x, y),
this.Subtitle,
this.SubtitleColor.GetActualColor(this.TextColor),
this.ActualSubtitleFont,
this.SubtitleFontSize,
this.SubtitleFontWeight,
0,
HorizontalAlignment.Center,
VerticalAlignment.Top);
}
}
示例10: MeasureTitles
/// <summary>
/// Measures the size of the title and subtitle.
/// </summary>
/// <param name="rc">The rendering context.</param>
/// <returns>Size of the titles.</returns>
private OxySize MeasureTitles(IRenderContext rc)
{
var titleSize = rc.MeasureText(this.Title, this.ActualTitleFont, this.TitleFontSize, this.TitleFontWeight);
var subtitleSize = rc.MeasureText(this.Subtitle, this.SubtitleFont ?? this.ActualSubtitleFont, this.SubtitleFontSize, this.SubtitleFontWeight);
double height = titleSize.Height + subtitleSize.Height;
double width = Math.Max(titleSize.Width, subtitleSize.Width);
return new OxySize(width, height);
}
示例11: RenderTitle
/// <summary>
/// Renders the title and subtitle.
/// </summary>
/// <param name="rc">
/// The render context.
/// </param>
private void RenderTitle(IRenderContext rc)
{
OxySize size1 = rc.MeasureText(this.Title, this.ActualTitleFont, this.TitleFontSize, this.TitleFontWeight);
rc.MeasureText(
this.Subtitle, this.SubtitleFont ?? this.ActualSubtitleFont, this.SubtitleFontSize, this.SubtitleFontWeight);
// double height = size1.Height + size2.Height;
// double dy = (TitleArea.Top+TitleArea.Bottom-height)*0.5;
double dy = this.TitleArea.Top;
double dx = (this.TitleArea.Left + this.TitleArea.Right) * 0.5;
if (!string.IsNullOrEmpty(this.Title))
{
rc.DrawMathText(
new ScreenPoint(dx, dy),
this.Title,
this.TitleColor ?? this.TextColor,
this.ActualTitleFont,
this.TitleFontSize,
this.TitleFontWeight,
0,
HorizontalAlignment.Center,
VerticalAlignment.Top);
dy += size1.Height;
}
if (!string.IsNullOrEmpty(this.Subtitle))
{
rc.DrawMathText(
new ScreenPoint(dx, dy),
this.Subtitle,
this.SubtitleColor ?? this.TextColor,
this.ActualSubtitleFont,
this.SubtitleFontSize,
this.SubtitleFontWeight,
0,
HorizontalAlignment.Center,
VerticalAlignment.Top);
}
}
示例12: MeasureTitles
/// <summary>
/// Measures the size of the title and subtitle.
/// </summary>
/// <param name="rc">
/// The rendering context.
/// </param>
/// <returns>
/// Size of the titles.
/// </returns>
private OxySize MeasureTitles(IRenderContext rc)
{
OxySize size1 = rc.MeasureText(this.Title, this.ActualTitleFont, this.TitleFontSize, this.TitleFontWeight);
OxySize size2 = rc.MeasureText(
this.Subtitle, this.SubtitleFont ?? this.ActualSubtitleFont, this.SubtitleFontSize, this.SubtitleFontWeight);
double height = size1.Height + size2.Height;
double width = Math.Max(size1.Width, size2.Width);
return new OxySize(width, height);
}
示例13: InternalDrawMathText
/// <summary>
/// The internal draw math text.
/// </summary>
/// <param name="rc">The render context.</param>
/// <param name="x">The x.</param>
/// <param name="y">The y.</param>
/// <param name="s">The s.</param>
/// <param name="textColor">The text color.</param>
/// <param name="fontFamily">The font family.</param>
/// <param name="fontSize">The font size.</param>
/// <param name="fontWeight">The font weight.</param>
/// <param name="measureOnly">The measure only.</param>
/// <param name="angle">The angle of the text (degrees).</param>
/// <returns>The size of the text.</returns>
private static OxySize InternalDrawMathText(
IRenderContext rc,
double x,
double y,
string s,
OxyColor textColor,
string fontFamily,
double fontSize,
double fontWeight,
bool measureOnly,
double angle)
{
int i = 0;
double angleRadian = (angle * Math.PI) / 180.0;
double cosAngle = Math.Round(Math.Cos(angleRadian), 5);
double sinAngle = Math.Round(Math.Sin(angleRadian), 5);
double currentX = x, maximumX = x, minimumX = x;
double currentY = y, maximumY = y, minimumY = y;
// http://en.wikipedia.org/wiki/Subscript_and_superscript
double superScriptXDisplacement = sinAngle * fontSize * SuperAlignment;
double superScriptYDisplacement = cosAngle * fontSize * SuperAlignment;
double subscriptXDisplacement = sinAngle * fontSize * SubAlignment;
double subscriptYDisplacement = cosAngle * fontSize * SubAlignment;
double superscriptFontSize = fontSize * SuperSize;
double subscriptFontSize = fontSize * SubSize;
Func<double, double, string, double, OxySize> drawText = (xb, yb, text, fSize) =>
{
if (!measureOnly)
{
rc.DrawText(new ScreenPoint(xb, yb), text, textColor, fontFamily, fSize, fontWeight, angle);
}
var flatSize = rc.MeasureText(text, fontFamily, fSize, fontWeight);
double width = Math.Abs((flatSize.Width * cosAngle) + (flatSize.Height * sinAngle));
double height = Math.Abs((flatSize.Width * sinAngle) + (flatSize.Height * cosAngle));
return new OxySize(width, height);
};
while (i < s.Length)
{
// Superscript
if (i + 1 < s.Length && s[i] == '^' && s[i + 1] == '{')
{
int i1 = s.IndexOf('}', i);
if (i1 != -1)
{
string supString = s.Substring(i + 2, i1 - i - 2);
i = i1 + 1;
double sx = currentX + superScriptXDisplacement;
double sy = currentY + superScriptYDisplacement;
var size = drawText(sx, sy, supString, superscriptFontSize);
if (currentX + size.Width > maximumX)
{
maximumX = currentX + size.Width;
}
if (currentX + size.Width < minimumX)
{
minimumX = currentX + size.Width;
}
if (currentY + size.Height > maximumY)
{
maximumY = currentY + size.Height;
}
if (currentY + size.Height < minimumY)
{
minimumY = currentY + size.Height;
}
continue;
}
}
// Subscript
if (i + 1 < s.Length && s[i] == '_' && s[i + 1] == '{')
{
int i1 = s.IndexOf('}', i);
if (i1 != -1)
{
//.........这里部分代码省略.........