本文整理汇总了C#中System.Windows.Media.FormattedText.SetFontSize方法的典型用法代码示例。如果您正苦于以下问题:C# FormattedText.SetFontSize方法的具体用法?C# FormattedText.SetFontSize怎么用?C# FormattedText.SetFontSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Media.FormattedText
的用法示例。
在下文中一共展示了FormattedText.SetFontSize方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: escribeTexto
private void escribeTexto()
{
string texto = "";
FormattedText frmTxt = new FormattedText(texto,
CultureInfo.GetCultureInfo("en-us"),
FlowDirection.LeftToRight, new Typeface("Verdana"), 32, Brushes.Black);
// Set a maximum width and height. If the text overflows these values, an ellipsis "..." appears.
frmTxt.MaxTextWidth = 300;
frmTxt.MaxTextHeight = 240;
// Use a larger font size beginning at the first (zero-based) character and continuing for 5 characters.
// The font size is calculated in terms of points -- not as device-independent pixels.
frmTxt.SetFontSize(36 * (96.0 / 72.0), 0, 5);
// Use a Bold font weight beginning at the 6th character and continuing for 11 characters.
frmTxt.SetFontWeight(FontWeights.Bold, 6, 11);
// Use a linear gradient brush beginning at the 6th character and continuing for 11 characters.
frmTxt.SetForegroundBrush(
new LinearGradientBrush(
Colors.Orange,
Colors.Teal,
90.0),
6, 11);
// Use an Italic font style beginning at the 28th character and continuing for 28 characters.
frmTxt.SetFontStyle(FontStyles.Italic, 28, 28);
//// Draw the formatted text string to the DrawingContext of the control.
//drawingContext.DrawText(frmTxt, new Point(10, 0));
}
示例2: CalculateMaximumFontSize
/// <summary>
/// Calculates a maximum font size that will fit in a given space
/// </summary>
/// <param name="maximumFontSize">The maximum (and default) font size</param>
/// <param name="minimumFontSize">The minimum size the font is capped at</param>
/// <param name="reductionStep">The step to de-increment font size with. A higher step is less expensive, whereas a lower step sizes font with greater accuracy</param>
/// <param name="text">The string to measure</param>
/// <param name="fontFamily">The font family the string provided should be measured in</param>
/// <param name="containerAreaSize">The total area of the containing area for font placement, specified as a size</param>
/// <param name="containerInnerMargin">An internal margin to specify the distance the font should keep from the edges of the container</param>
/// <returns>The caculated maximum font size</returns>
public static Double CalculateMaximumFontSize(Double maximumFontSize, Double minimumFontSize, Double reductionStep, String text, FontFamily fontFamily, Size containerAreaSize, Thickness containerInnerMargin, string CultureInfo)
{
// set fontsize to maimumfont size
Double fontSize = maximumFontSize;
// holds formatted text - Culture info is setup for US-Engish, this can be changed for different language sets
FormattedText formattedText = new FormattedText(text, System.Globalization.CultureInfo.GetCultureInfo(CultureInfo), FlowDirection.LeftToRight, new Typeface(fontFamily.ToString()), fontSize, Brushes.Black);
// hold the maximum internal space allocation as an absolute value
Double maximumInternalWidth = containerAreaSize.Width - (containerInnerMargin.Left + containerInnerMargin.Right);
// if measured font is too big for container size, with regard for internal margin
if (formattedText.WidthIncludingTrailingWhitespace > maximumInternalWidth)
{
do
{
// reduce font size by step
fontSize -= reductionStep;
// set fontsize ready for re-measure
formattedText.SetFontSize(fontSize);
}
while ((formattedText.WidthIncludingTrailingWhitespace > maximumInternalWidth) && (fontSize > minimumFontSize));
}
double maximumInternalHeight = containerAreaSize.Height - (containerInnerMargin.Top + containerInnerMargin.Bottom);
if (fontSize > maximumInternalHeight)
{
do
{
// reduce font size by step
fontSize -= reductionStep;
// set fontsize ready for re-measure
formattedText.SetFontSize(fontSize);
}
while ((fontSize > maximumInternalHeight) && (fontSize > minimumFontSize));
}
// return ammended fontsize
return fontSize;
}
示例3: CreateFormattedText
public static FormattedText CreateFormattedText(string text,int fontSize,Brush brush,Typeface typeface,int maxTextWidth,TextAlignment alignment)
{
FormattedText formattedText = new FormattedText(
text,
CultureInfo.GetCultureInfo("en-us"),
FlowDirection.LeftToRight,
typeface,
fontSize,
brush);
formattedText.SetFontSize(fontSize * (96.0 / 72.0));
formattedText.TextAlignment = alignment;
formattedText.MaxTextWidth = maxTextWidth;
return formattedText;
}
示例4: GetFormattedText
public static FormattedText GetFormattedText(this FlowDocument doc)
{
if (doc == null)
{
throw new ArgumentNullException("doc");
}
FormattedText output = new FormattedText(
GetText(doc),
CultureInfo.CurrentCulture,
doc.FlowDirection,
new Typeface(doc.FontFamily, doc.FontStyle, doc.FontWeight, doc.FontStretch),
doc.FontSize,
doc.Foreground);
int offset = 0;
foreach (TextElement el in GetRunsAndParagraphs(doc))
{
Run run = el as Run;
if (run != null)
{
int count = run.Text.Length;
output.SetFontFamily(run.FontFamily, offset, count);
output.SetFontStyle(run.FontStyle, offset, count);
output.SetFontWeight(run.FontWeight, offset, count);
output.SetFontSize(run.FontSize, offset, count);
output.SetForegroundBrush(run.Foreground, offset, count);
output.SetFontStretch(run.FontStretch, offset, count);
output.SetTextDecorations(run.TextDecorations, offset, count);
offset += count;
}
else
{
offset += Environment.NewLine.Length;
}
}
return output;
}
示例5: GetOutlinedText
public static GeometryDrawing[] GetOutlinedText(string text, double maxFontSize, Rect rect, Brush fill, Brush stroke, Typeface typeFace,
double strokeThickness = 2, bool centered = false)
{
var fText = new FormattedText(text, CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight, typeFace, maxFontSize, fill);
if(!double.IsNaN(rect.Width))
{
if(fText.Width > rect.Width)
fText.SetFontSize((int)(maxFontSize * rect.Width / fText.Width));
fText.MaxTextWidth = rect.Width;
}
var point = new Point(rect.X + (centered && !double.IsNaN(rect.Width) ? (rect.Width - fText.Width) / 2 : 0), !double.IsNaN(rect.Height) ? (rect.Height - fText.Height) / 2 + fText.Height * 0.05: rect.Y);
var drawings = new[]
{
new GeometryDrawing(stroke, new Pen(Brushes.Black, strokeThickness) {LineJoin = PenLineJoin.Round}, fText.BuildGeometry(point)),
new GeometryDrawing(fill, new Pen(Brushes.White, 0), fText.BuildGeometry(point))
};
return drawings;
}
示例6: OnRender
protected override void OnRender(DrawingContext drawingContext)
{
//drawingContext.DrawRectangle(Brushes.Crimson, null, new Rect(new Point(0, 0), new Point(500, 500)));
//base.OnRender(drawingContext);
//return;
string testString = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor";
// Create the initial formatted text string.
FormattedText formattedText = new FormattedText(
testString,
CultureInfo.GetCultureInfo("en-us"),
FlowDirection.LeftToRight,
new Typeface("Verdana"),
32,
Brushes.Black);
// Set a maximum width and height. If the text overflows these values, an ellipsis "..." appears.
formattedText.MaxTextWidth = 300;
formattedText.MaxTextHeight = 240;
// Use a larger font size beginning at the first (zero-based) character and continuing for 5 characters.
// The font size is calculated in terms of points -- not as device-independent pixels.
formattedText.SetFontSize(36 * (96.0 / 72.0), 0, 5);
// Use a Bold font weight beginning at the 6th character and continuing for 11 characters.
formattedText.SetFontWeight(FontWeights.Bold, 6, 11);
// Use a linear gradient brush beginning at the 6th character and continuing for 11 characters.
formattedText.SetForegroundBrush(
new LinearGradientBrush(
Colors.Orange,
Colors.Teal,
90.0),
6, 11);
// Use an Italic font style beginning at the 28th character and continuing for 28 characters.
formattedText.SetFontStyle(FontStyles.Italic, 28, 28);
// Draw the formatted text string to the DrawingContext of the control.
drawingContext.DrawText(formattedText, new Point(10, 0));
}
示例7: Self_DrawText
public void Self_DrawText()
{
DrawingContext dc = drawvis.RenderOpen();
renderbit.Clear();
// 글씨 쓰기
string testString = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor";
// Create the initial formatted text string.
FormattedText formattedText = new FormattedText(
testString,
System.Globalization.CultureInfo.GetCultureInfo("en-us"),
FlowDirection.LeftToRight,
new Typeface("Verdana"),
30,
Brushes.Black);
// Set a maximum width and height. If the text overflows these values, an ellipsis "..." appears.
formattedText.MaxTextWidth = 300;
formattedText.MaxTextHeight = 240;
// Use a larger font size beginning at the first (zero-based) character and continuing for 5 characters.
// The font size is calculated in terms of points -- not as device-independent pixels.
formattedText.SetFontSize(36 * (96.0 / 72.0), 0, 5);
// Use a Bold font weight beginning at the 6th character and continuing for 11 characters.
formattedText.SetFontWeight(FontWeights.Bold, 2, 3);
// Use a linear gradient brush beginning at the 6th character and continuing for 11 characters.
formattedText.SetForegroundBrush(
new LinearGradientBrush(
Colors.Orange,
Colors.Teal,
90.0),
6, 11);
// Use an Italic font style beginning at the 28th character and continuing for 28 characters.
formattedText.SetFontStyle(FontStyles.Italic, 28, 28);
// Draw the formatted text string to the DrawingContext of the control.
dc.DrawText(formattedText, new Point(100, 150));
dc.Close();
renderbit.Render(drawvis);
}
示例8: CalculateMaximumFontSize
public static Double CalculateMaximumFontSize (Double maximumFontSize, Double minimumFontSize, Double reductionStep, String text, FontFamily fontFamily, Size containerAreaSize, Thickness containerInnerMargin)
{
Double fontSize = maximumFontSize;
FormattedText formattedText = new FormattedText (text, System.Globalization.CultureInfo.GetCultureInfo ("en-us"), FlowDirection.LeftToRight, new Typeface (fontFamily.ToString ()), fontSize, Brushes.Black);
Double maximumInternalWidth = containerAreaSize.Width - (containerInnerMargin.Left + containerInnerMargin.Right) * 2;
Double maximumInternalHeight = containerAreaSize.Height - (containerInnerMargin.Top + containerInnerMargin.Bottom) * 2;
Geometry TextGeometry = formattedText.BuildGeometry (new Point (0, 0));
if ((TextGeometry.Bounds.Width >= maximumInternalWidth) || (TextGeometry.Bounds.Height >= maximumInternalHeight))
{
do
{
fontSize -= reductionStep;
formattedText.SetFontSize (fontSize);
TextGeometry = formattedText.BuildGeometry(new Point(0, 0));
}
while (((TextGeometry.Bounds.Width >= maximumInternalWidth)
|| (TextGeometry.Bounds.Height >= maximumInternalHeight))
&& (fontSize > minimumFontSize));
}
return fontSize;
}
示例9: UserDrawWPF
private void UserDrawWPF(DrawingContext dc)
{
System.Windows.Media.Color m_LineColor = System.Windows.Media.Colors.Gold;
System.Windows.Media.SolidColorBrush m_LineColorBrush = System.Windows.Media.Brushes.Gold;
int m_LineWidth = 4;
try
{
int PixelX = 0;
int PixelY = 0;
if (pntSource.X != 0.0 && pntSource.Y != 0.0)
{
VMMainViewModel.Instance.ConvertCoordGroundToPixel(pntSource.X, pntSource.Y, ref PixelX, ref PixelY);
ImageSource ImageSource = new System.Windows.Media.Imaging.BitmapImage(new Uri("pack://application:,,,/Images/" + "flag_blue.png"));
Utilites.UserDrawRasterWPFScreenCoordinate(dc, ImageSource, PixelX, PixelY, 22, 22);
}
if (pntTarget.X != 0.0 && pntTarget.Y != 0.0)
{
VMMainViewModel.Instance.ConvertCoordGroundToPixel(pntTarget.X, pntTarget.Y, ref PixelX, ref PixelY);
ImageSource ImageSource = new System.Windows.Media.Imaging.BitmapImage(new Uri("pack://application:,,,/Images/" + "flag_red.png"));
Utilites.UserDrawRasterWPFScreenCoordinate(dc, ImageSource, PixelX, PixelY, 22, 22);
}
if (m_PolygonPnts == null) return;
// if (m_PolygonPnts.Count == 0) return;
// m_LineColor = System.Windows.Media.Colors.Gold;
// m_LineColorBrush.Color = System.Windows.Media.Colors.Gold;
System.Windows.Media.Pen pen = new System.Windows.Media.Pen(m_LineColorBrush, m_LineWidth);
pen.Thickness = m_LineWidth;
pen.LineJoin = PenLineJoin.Round;
System.Windows.Point[] m_ScreenPnts = new System.Windows.Point[m_PolygonPnts.Count];
for (int i = 0; i < m_PolygonPnts.Count; i++)
{
// int PixelX = 0;
// int PixelY = 0;
VMMainViewModel.Instance.ConvertCoordGroundToPixel(m_PolygonPnts[i].X, m_PolygonPnts[i].Y, ref PixelX, ref PixelY);
m_ScreenPnts[i].X = PixelX;
m_ScreenPnts[i].Y = PixelY;
}
if (m_ScreenPnts.Length > 1)
{
System.Windows.Media.PathGeometry PathGmtr = new System.Windows.Media.PathGeometry();
System.Windows.Media.PathFigure pathFigure = new System.Windows.Media.PathFigure();
System.Windows.Media.PolyLineSegment myPolyLineSegment = new System.Windows.Media.PolyLineSegment();
System.Windows.Media.PointCollection pc = new System.Windows.Media.PointCollection(m_ScreenPnts);
myPolyLineSegment.Points = pc;
pathFigure.StartPoint = m_ScreenPnts[0];
pathFigure.Segments.Add(myPolyLineSegment);
PathGmtr.Figures.Add(pathFigure);
pathFigure.IsClosed = false;
dc.DrawGeometry(null, pen, PathGmtr);
}
if (dtGridRoute != null)
{
FormattedText frm = new FormattedText("o",
System.Globalization.CultureInfo.GetCultureInfo("en-us"),
System.Windows.FlowDirection.RightToLeft,
new System.Windows.Media.Typeface("Arial"),
18, System.Windows.Media.Brushes.Red);
for (int i = 0; i < dtGridRoute.Items.Count; i++)
{
if (dtGridRoute.SelectedIndex == i)
{
frm.SetFontSize(24);
}
else
{
frm.SetFontSize(18);
}
//.........这里部分代码省略.........
示例10: OnRender
// OnRender�� �������̵�
protected override void OnRender(DrawingContext dc)
{
Size size = RenderSize;
// ���� ��� RenderSize ����
if (Stroke != null)
{
//Thickness������Ƽ ��ŭ Ÿ���� ������ ���δ�.
size.Width = Math.Max(0, size.Width - Stroke.Thickness);
size.Height = Math.Max(0, size.Height - Stroke.Thickness);
}
// Ÿ�� ����
dc.DrawEllipse(Fill, Stroke,
new Point(RenderSize.Width / 2, RenderSize.Height / 2),
size.Width / 2, size.Height / 2);
#region �߰����� �ڵ�
string testString = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor";
// FormattedText ����
FormattedText formtxt = new FormattedText(
testString, //���ڿ�
CultureInfo.GetCultureInfo("en-us"),//Text Ư�� ��ȭ��
FlowDirection.LeftToRight, //Text �д� ����
new Typeface("Verdana"), //Text ��Ÿ��
32, //�۲� ũ��
Brushes.Black); //�귯�� ����
// Set a maximum width and height. If the text overflows these values, an ellipsis "..." appears.
formtxt.MaxTextWidth = 300; //Text ���� �ִ���
formtxt.MaxTextHeight = 240; //Text ���� �ִ����
// Use a larger font size beginning at the first (zero-based) character and continuing for 5 characters.
// The font size is calculated in terms of points -- not as device-independent pixels.
formtxt.SetFontSize(36 * (96.0 / 72.0), 0, 5);
// ������ �ؽ�Ʈ �� ���� (����, ��ġ, ����)
formtxt.SetFontWeight(FontWeights.Bold, 6, 11);
// ������ �ؽ�Ʈ ���̼� �ֱ�
formtxt.SetForegroundBrush(
new LinearGradientBrush(
Colors.Orange,
Colors.Teal,
90.0), //�귯��(���̼�)
6, 11); //��ġ, ����
// ������ �ؽ�Ʈ�� ��Ʈ��Ÿ��
formtxt.SetFontStyle(FontStyles.Italic, 28, 28);
//���
dc.DrawText(formtxt, new Point((RenderSize.Width - formtxt.Width) / 2,
(RenderSize.Height - formtxt.Height) / 2));
#endregion
dc.PushClip(new RectangleGeometry(new Rect(new Point(0, 0), RenderSize)));
}
示例11: CreateTextBlock
/*
public static TextBlock CreateTextBlock(ExportText exportText,bool setBackcolor){
var textBlock = new TextBlock();
textBlock.Foreground = ConvertBrush(exportText.ForeColor);
if (setBackcolor) {
textBlock.Background = ConvertBrush(exportText.BackColor);
}
SetFont(textBlock,exportText);
textBlock.TextWrapping = TextWrapping.Wrap;
CheckForNewLine (textBlock,exportText);
SetContentAlignment(textBlock,exportText);
MeasureTextBlock (textBlock,exportText);
return textBlock;
}
*/
/*
static void CheckForNewLine(TextBlock textBlock,ExportText exportText) {
string [] inlines = exportText.Text.Split(Environment.NewLine.ToCharArray());
for (int i = 0; i < inlines.Length; i++) {
if (inlines[i].Length > 0) {
textBlock.Inlines.Add(new Run(inlines[i]));
textBlock.Inlines.Add(new LineBreak());
}
}
var li = textBlock.Inlines.LastInline;
textBlock.Inlines.Remove(li);
}
static void MeasureTextBlock(TextBlock textBlock,ExportText exportText)
{
var wpfSize = MeasureTextInWpf(exportText);
textBlock.Width = wpfSize.Width;
textBlock.Height = wpfSize.Height;
}
*/
/*
static Size MeasureTextInWpf(ExportText exportText){
if (exportText.CanGrow) {
var formattedText = NewMethod(exportText);
formattedText.MaxTextWidth = exportText.DesiredSize.Width * 96.0 / 72.0;
formattedText.SetFontSize(Math.Floor(exportText.Font.Size * 96.0 / 72.0));
var size = new Size {
Width = formattedText.WidthIncludingTrailingWhitespace,
Height = formattedText.Height + 6};
return size;
}
return new Size(exportText.Size.Width,exportText.Size.Height);
}
*/
public static FormattedText CreateFormattedText(ExportText exportText)
{
var formattedText = new FormattedText(exportText.Text,
CultureInfo.CurrentCulture,
FlowDirection.LeftToRight,
new Typeface(exportText.Font.FontFamily.Name),
exportText.Font.Size,
new SolidColorBrush(exportText.ForeColor.ToWpf()), null, TextFormattingMode.Display);
formattedText.MaxTextWidth = exportText.DesiredSize.Width * 96.0 / 72.0;
formattedText.SetFontSize(Math.Floor(exportText.Font.Size * 96.0 / 72.0));
var td = new TextDecorationCollection() ;
CheckUnderline(td,exportText);
formattedText.SetTextDecorations(td);
return formattedText;
}
示例12: GetFormattedText
private static FormattedText GetFormattedText(FlowDocument doc)
{
var output = new FormattedText(
GetText(doc),
CultureInfo.CurrentCulture,
doc.FlowDirection,
new Typeface(doc.FontFamily, doc.FontStyle, doc.FontWeight, doc.FontStretch),
doc.FontSize,
doc.Foreground);
int offset = 0;
foreach (TextElement textElement in GetRunsAndParagraphs(doc))
{
var run = textElement as Run;
if (run != null)
{
int count = run.Text.Length;
output.SetFontFamily(run.FontFamily, offset, count);
output.SetFontSize(run.FontSize, offset, count);
output.SetFontStretch(run.FontStretch, offset, count);
output.SetFontStyle(run.FontStyle, offset, count);
output.SetFontWeight(run.FontWeight, offset, count);
output.SetForegroundBrush(run.Foreground, offset, count);
output.SetTextDecorations(run.TextDecorations, offset, count);
offset += count;
}
else
{
offset += Environment.NewLine.Length;
}
}
return output;
}
示例13: _formatBody
private void _formatBody() {
var showMembers = Canvas.DisplayOptions.Has(DisplayOptions.DisplayClassMembers);
var showInherited = Canvas.DisplayOptions.Has(DisplayOptions.DisplayInheritedMembers);
var sortMembers = Canvas.DisplayOptions.Has(DisplayOptions.SortMembersByName);
if (!showMembers) {
_bodyText = null;
return;
}
var bodyParts = new List<string>();
var bodyStyles = new List<TextStyle>();
Action<string, TextStyle> addPart = (t, s) => { bodyParts.Add(t); bodyStyles.Add(s); };
Action addSpacer = () => addPart("-\n", TextStyle.Spacer);
Action<BplClass> addProperties = bplClass => {
var properties = (showInherited ? bplClass.Properties : bplClass.OwnProperties);
if (sortMembers) {
properties = properties.OrderBy(p => p.Name);
}
foreach (var prop in properties) {
var name = prop.Name.At(0).ToUpper() + prop.Name.After(0);
var type = String.Empty;
if (prop.IsPrimitive) {
type = prop.PrimitiveType.Name;
} else {
if (prop.IsReference) {
type = prop.UnderlyingType.Name;
} else if (prop.IsCollection) {
type = prop.UnderlyingItemType.Name + "*";
}
}
addPart("\u2022 " + name, (prop == bplClass.IdentityProperty ? TextStyle.Identity : TextStyle.FieldName));
addPart(" (" + type + ")\n", TextStyle.DataType);
}
};
var operation = Class.Operation;
if (operation == null) {
addProperties(Class);
} else {
addPart("INPUT:\n", TextStyle.Subtitle);
addSpacer();
addProperties(Class);
if (operation.Output != null) {
addSpacer();
addSpacer();
addPart("OUTPUT:\n", TextStyle.Subtitle);
addSpacer();
addProperties(operation.Output);
}
}
_bodyText = ToFormattedText(bodyParts.ToArray().Join(), 14, _normalFG);
for (int i = 0, j = 0; i < bodyParts.Count; i++) {
var k = bodyParts[i].Length;
switch(bodyStyles[i]) {
case TextStyle.Identity:
_bodyText.SetTextDecorations(TextDecorations.Underline, j + 2, k - 2);
break;
case TextStyle.DataType:
_bodyText.SetForegroundBrush(_lightFG, j, k);
_bodyText.SetFontStyle(FontStyles.Italic, j + 2, k - 4);
break;
case TextStyle.Subtitle:
_bodyText.SetFontSize(13, j, k);
_bodyText.SetTextDecorations(TextDecorations.Underline, j, k);
break;
case TextStyle.Spacer:
_bodyText.SetForegroundBrush(_bodyBG.Fill, j, k);
_bodyText.SetFontSize(3, j, k);
break;
}
j += k;
}
}
示例14: GetMeasurementDrawing
/// <summary>
/// Generates the drawing of the measurements.
/// </summary>
/// <param name="sourceWidth">The width of the source image.</param>
/// <param name="sourceHeight">The height of the source image.</param>
/// <param name="displayWidth">The width of the container to put the bitmap. Scales the size of the drawings.</param>
/// <param name="displayHeight">The height of the container to put the bitmap. Scales the size of the drawings.</param>
/// <param name="adornerLayerManager">The adorner information object.</param>
/// <param name="background">The background to create the drawing on.</param>
public static DrawingVisual GetMeasurementDrawing(double sourceWidth, double sourceHeight, double displayWidth, double displayHeight, AdornerLayerManager adornerLayerManager, Brush background)
{
DrawingVisual dw = new DrawingVisual();
using (DrawingContext dc = dw.RenderOpen())
{
Size sz = new Size((int)sourceWidth, (int)sourceHeight);
Pen p = new Pen();
Point pt = new Point(1, 1);
dc.DrawRectangle(background, p, new System.Windows.Rect(pt, sz));
double widthRatio = sourceWidth / displayWidth;
double heightRatio = sourceHeight / displayHeight;
double Ratio = (widthRatio < heightRatio) ? widthRatio : heightRatio;
MeasureAdorner measAdorner = (MeasureAdorner)adornerLayerManager.GetAdorner(AdornerLayerManager.MEASUREMENT_ADORNER);
foreach (MeasurementLine lineObj in measAdorner.GetMeasurementLines())
{
SolidColorBrush lscb = Brushes.Green;
Pen lp1 = new Pen(lscb, 5d * Ratio);
dc.DrawLine(lp1, lineObj.StartPoint, lineObj.EndPoint);
float lineLength = (lineObj.Length * measAdorner.SamplingSpace) / 1000;
FormattedText formattedText =
new FormattedText(lineLength.ToString("F") + "m", CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight,
new Typeface("Veranda"), 32, Brushes.Green);
//formattedText.MaxTextWidth = 300;
//formattedText.MaxTextHeight = 240;
//formattedText.SetFontSize(32 * (96.0 / 72.0));
PrintDialog tempPrnDialog = new PrintDialog();
if (sourceWidth > sourceHeight)
{
formattedText.SetFontSize((sourceWidth / tempPrnDialog.PrintableAreaWidth) * 12);
}
else
formattedText.SetFontSize((sourceHeight / tempPrnDialog.PrintableAreaHeight) * 15);
Point textMidPoint = new Point(lineObj.MidPoint.X - (formattedText.Width / 2), lineObj.MidPoint.Y - (formattedText.Height / 2));
Rect LegendRect;
LegendRect = new Rect(textMidPoint, new Size(formattedText.Width, formattedText.Height));
SolidColorBrush scb = Brushes.Green;
Pen p1 = new Pen(scb, (5D * Ratio));
RectangleGeometry rg = new RectangleGeometry(LegendRect, 0, 0);
dc.DrawGeometry(Brushes.White, null, rg);
dc.DrawText(formattedText, textMidPoint);
}
}
return dw;
}
示例15: GetAnnotationDrawing
/// <summary>
/// Generates the drawing of the annotations.
/// </summary>
/// <param name="sourceWidth">The width of the source image.</param>
/// <param name="sourceHeight">The height of the source image.</param>
/// <param name="displayWidth">The width of the container to put the bitmap. Scales the size of the drawings.</param>
/// <param name="displayHeight">The height of the container to put the bitmap. Scales the size of the drawings.</param>
/// <param name="adornerLayerManager">The adorner information object.</param>
/// <param name="background">The background to create the drawing on.</param>
public static DrawingVisual GetAnnotationDrawing(double sourceWidth, double sourceHeight, double displayWidth, double displayHeight, AdornerLayerManager adornerLayerManager, Brush background)
{
DrawingVisual dw = new DrawingVisual();
using (DrawingContext dc = dw.RenderOpen())
{
Size sz = new Size((int)sourceWidth, (int)sourceHeight);
Pen p = new Pen();
Point pt = new Point(1, 1);
dc.DrawRectangle(background, p, new System.Windows.Rect(pt, sz));
double widthRatio = sourceWidth / displayWidth;
double heightRatio = sourceHeight / displayHeight;
double Ratio = (widthRatio < heightRatio) ? widthRatio : heightRatio;
char[] letters = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z' };
int count = 0;
AnnotationAdorner annotAdorner = (AnnotationAdorner)adornerLayerManager.GetAdorner(AdornerLayerManager.ANNOTATION_ADORNER);
foreach (Annotation annotation in annotAdorner.GetAnnotations())
{
Rect rect = annotation.Marking.Rect;
RectangleGeometry rg = new RectangleGeometry(rect, annotation.Marking.RadiusX, annotation.Marking.RadiusY);
//rg.
SolidColorBrush scb = Brushes.Green;
Pen p1 = new Pen(scb, (5D * Ratio));
dc.DrawGeometry(null, p1, rg);
string index = string.Empty;
int div = (count / 26) - 1;
int rem = count % 26;
if (div >= 0)
{
index += letters[div];
}
index += letters[rem];
FormattedText formattedText =
new FormattedText(index, CultureInfo.GetCultureInfo("en-us"), FlowDirection.LeftToRight,
new Typeface("Aharoni"), 32, Brushes.Green);
//formattedText.MaxTextWidth = 300;
//formattedText.SetFontSize(32 * (96.0 / 72.0));
PrintDialog tempPrnDialog = new PrintDialog();
if (sourceWidth > sourceHeight)
{
formattedText.SetFontSize((sourceWidth / tempPrnDialog.PrintableAreaWidth) * 11);
}
else
formattedText.SetFontSize((sourceHeight / tempPrnDialog.PrintableAreaHeight) * 13);
Rect LegendRect;
if (annotation.Marking.RadiusX > 0)
LegendRect = new Rect(annotation.Marking.Rect.TopLeft.X + (annotation.Marking.Rect.Width / 2) - ((formattedText.WidthIncludingTrailingWhitespace + 10) / 2),
annotation.Marking.Rect.TopLeft.Y - formattedText.Height - 5, formattedText.WidthIncludingTrailingWhitespace + 12, formattedText.Height + 5);
else
LegendRect = new Rect(annotation.Marking.Rect.TopLeft.X, annotation.Marking.Rect.TopLeft.Y - formattedText.Height - 5, formattedText.WidthIncludingTrailingWhitespace + 12, formattedText.Height + 5);
rg = new RectangleGeometry(LegendRect, 0, 0);
dc.DrawGeometry(Brushes.LightYellow, p1, rg);
dc.DrawText(formattedText, new Point(LegendRect.TopLeft.X + 5, LegendRect.TopLeft.Y + 5));
count++;
}
}
return dw;
}