本文整理汇总了C#中PdfSharp.Drawing.XGraphics.MeasureString方法的典型用法代码示例。如果您正苦于以下问题:C# XGraphics.MeasureString方法的具体用法?C# XGraphics.MeasureString怎么用?C# XGraphics.MeasureString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PdfSharp.Drawing.XGraphics
的用法示例。
在下文中一共展示了XGraphics.MeasureString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: RenderPage
public override void RenderPage(XGraphics gfx)
{
base.RenderPage(gfx);
string facename = "Times";
XFont fontR = new XFont(facename, 40);
XFont fontB = new XFont(facename, 40, XFontStyle.Bold);
XFont fontI = new XFont(facename, 40, XFontStyle.Italic);
XFont fontBI = new XFont(facename, 40, XFontStyle.Bold | XFontStyle.Italic);
//gfx.DrawString("Hello", this.properties.Font1.Font, this.properties.Font1.Brush, 200, 200);
double x = 80;
XPen pen = XPens.SlateBlue;
gfx.DrawLine(pen, x, 100, x, 600);
gfx.DrawLine(pen, x - 50, 200, 400, 200);
gfx.DrawLine(pen, x - 50, 300, 400, 300);
gfx.DrawLine(pen, x - 50, 400, 400, 400);
gfx.DrawLine(pen, x - 50, 500, 400, 500);
double lineSpace = fontR.GetHeight(gfx);
int cellSpace = fontR.FontFamily.GetLineSpacing(fontR.Style);
int cellAscent = fontR.FontFamily.GetCellAscent(fontR.Style);
int cellDescent = fontR.FontFamily.GetCellDescent(fontR.Style);
double cyAscent = lineSpace * cellAscent / cellSpace;
XFontMetrics metrics = fontR.Metrics;
XSize size;
gfx.DrawString("Times 40", fontR, this.properties.Font1.Brush, x, 200);
size = gfx.MeasureString("Times 40", fontR);
gfx.DrawLine(this.properties.Pen3.Pen, x, 200, x + size.Width, 200);
gfx.DrawString("Times bold 40", fontB, this.properties.Font1.Brush, x, 300);
size = gfx.MeasureString("Times bold 40", fontB);
//gfx.DrawLine(this.properties.Pen3.Pen, x, 300, x + size.Width, 300);
gfx.DrawString("Times italic 40", fontI, this.properties.Font1.Brush, x, 400);
size = gfx.MeasureString("Times italic 40", fontI);
//gfx.DrawLine(this.properties.Pen3.Pen, x, 400, x + size.Width, 400);
gfx.DrawString("Times bold italic 40", fontBI, this.properties.Font1.Brush, x, 500);
size = gfx.MeasureString("Times bold italic 40", fontBI);
//gfx.DrawLine(this.properties.Pen3.Pen, x, 500, x + size.Width, 500);
#if true___
// Check Malayalam
XPdfFontOptions options = new XPdfFontOptions(PdfFontEncoding.Unicode, PdfFontEmbedding.Always);
XFont Kartika = new XFont("Kartika", 20, XFontStyle.Regular, options);
XFont AnjaliOldLipi = new XFont("AnjaliOldLipi", 20, XFontStyle.Regular, options);
gfx.DrawString("മകനെ ഇത് ഇന്ത്യയുടെ ഭൂപടം", Kartika, this.properties.Font1.Brush, x, 600);
gfx.DrawString("മകനെ ഇത് ഇന്ത്യയുടെ ഭൂപടം", AnjaliOldLipi, this.properties.Font1.Brush, x, 650);
#endif
}
示例2: DrawPage
public void DrawPage(XGraphics gfx, PointF pagepos, PageDrawOptions opts)
{
float acty = 0;
for (int i = 0; i < m_noDelimPageCount; i++)
{
Pane pane = m_panes[i];
pane.Draw(gfx, new PointF(pagepos.X, pagepos.Y + acty), true);
acty += pane.Height;
}
if (opts != null)
{
string header = opts.Header.Replace("%c", PageNumber.ToString());
string footer = opts.Footer.Replace("%c", PageNumber.ToString());
if (header != "")
{
float hdrwi = (float)gfx.MeasureString(header, opts.HeaderFont).Width;
float hdrhi = (float)gfx.MeasureString(header, opts.HeaderFont).Height;
gfx.DrawString(header, opts.HeaderFont, opts.HeaderColor, new PointF(pagepos.X + opts.PageWidth / 2 - hdrwi / 2, pagepos.Y - hdrhi), XStringFormat.TopLeft);
}
if (footer != "")
{
float ftrwi = (float)gfx.MeasureString(footer, opts.FooterFont).Width;
gfx.DrawString(footer, opts.FooterFont, opts.FooterColor, new PointF(pagepos.X + opts.PageWidth / 2 - ftrwi / 2, pagepos.Y + opts.PageHeight), XStringFormat.TopLeft);
}
}
}
示例3: DrawMultilineString
public static void DrawMultilineString(XGraphics gfx, string text, XFont font, XRect rect, Alignment alignment)
{
var size = gfx.MeasureString(text, font, XStringFormats.Center);
rect = new XRect(rect.X, rect.Y + (rect.Height - size.Height) / 2, rect.Width, 0);
var parts = text.Split('\n');
var height = gfx.MeasureString(parts[0], font, XStringFormats.Center).Height;
rect.Height = height;
for (int i = 0; i < parts.Length; ++i)
{
DrawString(gfx, parts[i], font, rect, alignment);
rect = new XRect(rect.X, rect.Y + height, rect.Width, rect.Height);
}
}
示例4: RenderMeasureText
void RenderMeasureText(XGraphics gfx)
{
gfx.TranslateTransform(15, 20);
XFontStyle style = XFontStyle.Regular;
XFont font = new XFont("Times New Roman", 95, style);
string text = "Hello";
double x = 20, y = 100;
XSize size = gfx.MeasureString(text, font);
double lineSpace = font.GetHeight(gfx);
int cellSpace = font.FontFamily.GetLineSpacing(style);
int cellAscent = font.FontFamily.GetCellAscent(style);
int cellDescent = font.FontFamily.GetCellDescent(style);
int cellLeading = cellSpace - cellAscent - cellDescent;
// Get effective ascent
double ascent = lineSpace * cellAscent / cellSpace;
gfx.DrawRectangle(XBrushes.Bisque, x, y - ascent, size.Width, ascent);
// Get effective descent
double descent = lineSpace * cellDescent / cellSpace;
gfx.DrawRectangle(XBrushes.LightGreen, x, y, size.Width, descent);
// Get effective leading
double leading = lineSpace * cellLeading / cellSpace;
gfx.DrawRectangle(XBrushes.Yellow, x, y + descent, size.Width, leading);
// Draw text half transparent
XColor color = XColors.DarkSlateBlue;
color.A = 0.6;
gfx.DrawString(text, font, new XSolidBrush(color), x, y);
}
示例5: Draw
public void Draw(XGraphics gfx)
{
var tf = new XTextFormatter(gfx) {Alignment = Alignment};
XSize size = gfx.MeasureString(Content, Font);
Rect = new XRect(Rect.X, Rect.Y, Rect.Width, size.Height*(Math.Ceiling(size.Width/Rect.Width) + 1));
tf.DrawString(Content, Font, Brush, Rect, XStringFormats.TopLeft);
}
示例6: RenderPage
public override void RenderPage(XGraphics gfx)
{
base.RenderPage(gfx);
string text = "TgfÄÖÜWi9";
if (this.properties.Font1.Text != "")
text = this.properties.Font1.Text;
float x = 100, y = 300;
string familyName = properties.Font1.FamilyName;
XFontStyle style = this.properties.Font1.Style;
float emSize = this.properties.Font1.Size;
//familyName = "Verdana";
//style = XFontStyle.Regular;
//emSize = 20;
//text = "X";
XFont font = CreateFont(familyName, emSize, style);
//font = this.properties.Font1.Font;
XSize size = gfx.MeasureString(text, font);
double lineSpace = font.GetHeight(gfx);
int cellSpace = font.FontFamily.GetLineSpacing(style);
int cellAscent = font.FontFamily.GetCellAscent(style);
int cellDescent = font.FontFamily.GetCellDescent(style);
int cellLeading = cellSpace - cellAscent - cellDescent;
double ascent = lineSpace * cellAscent / cellSpace;
gfx.DrawRectangle(XBrushes.Bisque, x, y - ascent, size.Width, ascent);
double descent = lineSpace * cellDescent / cellSpace;
gfx.DrawRectangle(XBrushes.LightGreen, x, y, size.Width, descent);
double leading = lineSpace * cellLeading / cellSpace;
gfx.DrawRectangle(XBrushes.Yellow, x, y + descent, size.Width, leading);
//gfx.DrawRectangle(this.properties.Brush1.Brush, x, y - size.Height, size.Width, size.Height);
//gfx.DrawLine(this.properties.Pen2.Pen, x, y, x + size.Width, y);
//gfx.DrawString("Hello", this.properties.Font1.Font, this.properties.Font1.Brush, 200, 200);
#if true_
XPdfFontOptions pdfOptions = new XPdfFontOptions(false, true);
font = new XFont("Tahoma", 8, XFontStyle.Regular, pdfOptions);
text = "Hallo";
text = chinese;
#endif
gfx.DrawString(text, font, this.properties.Font1.Brush, x, y);
#if true
XFont font2 = CreateFont(familyName, emSize, XFontStyle.Italic);
gfx.DrawString(text, font2, this.properties.Font1.Brush, x, y+50);
#endif
//gfx.DrawLine(XPens.Red, x, y + 10, x + 13.7, y + 10);
//gfx.DrawString(text, font, this.properties.Font1.Brush, x, y + 20);
}
示例7: Draw
public void Draw(XGraphics gfx)
{
string s = "Testtext";
//gfx.DrawLine(XPens.GreenYellow, 5, 100, 30, 50);
//gfx.DrawEllipse(XBrushes.DarkBlue, new XRect(30, 40, 250, 235));
XFont font = new XFont("Arial", 40, XFontStyle.Italic);
gfx.DrawString(s, font, XBrushes.Firebrick, 40, 60);
XSize size = gfx.MeasureString(s, font);
gfx.DrawLine(XPens.DarkBlue, 40, 60, 40 + size.Width, 60);
gfx.DrawLine(XPens.DarkBlue, 40, 60, 40, 60 + size.Height);
}
示例8: RenderPage
/// <summary>
/// Demonstrates serveral bar code types.
/// </summary>
public override void RenderPage(XGraphics gfx)
{
base.RenderPage(gfx);
XFont font = new XFont("Verdana", 14, XFontStyle.Bold);
string info = "DataMatrix is a fake in the Open Source version!";
XSize size = gfx.MeasureString(info, font);
gfx.DrawString(info, font, XBrushes.Firebrick, (600 - size.Width) / 2, 50);
//Graphics grfx = gfx.Internals.Graphics;
CodeDataMatrix dm = new CodeDataMatrix("test", 26);
dm.Size = new XSize(XUnit.FromMillimeter(15), XUnit.FromMillimeter(15));
gfx.DrawMatrixCode(dm, XBrushes.DarkBlue, new XPoint(100, 100));
dm = new CodeDataMatrix("test", 12, 12);
dm.Size = new XSize(XUnit.FromMillimeter(15), XUnit.FromMillimeter(15));
gfx.DrawMatrixCode(dm, XBrushes.DarkBlue, new XPoint(300, 100));
dm = new CodeDataMatrix("test", 16, 48);
dm.Size = new XSize(XUnit.FromMillimeter(50), XUnit.FromMillimeter(18));
gfx.DrawMatrixCode(dm, XBrushes.DarkBlue, new XPoint(500, 100));
dm = new CodeDataMatrix("0123456789", 52);
dm.Size = new XSize(XUnit.FromMillimeter(30), XUnit.FromMillimeter(30));
gfx.DrawMatrixCode(dm, XBrushes.DarkBlue, new XPoint(100, 300));
dm = new CodeDataMatrix("0123456789", 12, 26);
dm.Direction = CodeDirection.TopToBottom;
dm.Size = new XSize(XUnit.FromMillimeter(14), XUnit.FromMillimeter(7));
gfx.DrawMatrixCode(dm, XBrushes.DarkBlue, new XPoint(300, 300));
dm = new CodeDataMatrix("0123456789", 96);
dm.Size = new XSize(XUnit.FromMillimeter(30), XUnit.FromMillimeter(30));
gfx.DrawMatrixCode(dm, XBrushes.DarkBlue, new XPoint(500, 300));
dm = new CodeDataMatrix("www.empira.de", 20);
dm.Direction = CodeDirection.BottomToTop;
dm.Size = new XSize(XUnit.FromMillimeter(7), XUnit.FromMillimeter(7));
gfx.DrawMatrixCode(dm, XBrushes.DarkBlue, new XPoint(100, 500));
dm = new CodeDataMatrix("www.empira.de", 144, 144, 2);
dm.Size = new XSize(XUnit.FromMillimeter(50), XUnit.FromMillimeter(50));
gfx.DrawMatrixCode(dm, XBrushes.DarkBlue, new XPoint(300, 500));
dm = new CodeDataMatrix("www.empira.de", 88);
dm.Direction = CodeDirection.RightToLeft;
dm.Size = new XSize(XUnit.FromMillimeter(15), XUnit.FromMillimeter(15));
gfx.DrawMatrixCode(dm, XBrushes.DarkBlue, new XPoint(500, 500));
}
示例9: DrawGridlines
protected void DrawGridlines(XGraphics gfx)
{
XPen majorpen = XPens.DarkGray.Clone();
majorpen.Width = 1;
XPen minorpen = XPens.LightGray.Clone();
minorpen.Width = 0.1f;
gfx.SmoothingMode = XSmoothingMode.HighSpeed;
DrawGridlines(gfx, new XPoint(100, 100), majorpen, 100, minorpen, 10);
string text = this.Description;
XFont font = new XFont("Verdana", 14, XFontStyle.Bold);
XSize size = gfx.MeasureString(text, font);
gfx.DrawString(text, font, XBrushes.Black, (600 - size.Width) / 2, 30);
}
示例10: DrawCodePage
void DrawCodePage(XGraphics gfx, XPoint origin)
{
const double dx = 25;
const double dy = 25;
XFont labelFont = new XFont("Verdana", 10, XFontStyle.Bold);
//XFont font = new XFont("Bauhaus", 16);
XFont font = this.properties.Font1.Font;
//XFont labelFont = font;
//font = new XFont("Symbol", 16);
Encoding encoding = Encoding.GetEncoding(1252);
double asdf = XColors.LightGray.GS;
//XBrush lighter = new XSolidBrush(XColor.FromGrayScale(XColor.LightGray.GS * 1.1));
XBrush lighter = new XSolidBrush(XColor.FromGrayScale(0.9));
XFontStyle style = font.Style;
double lineSpace = font.GetHeight(gfx);
int cellSpace = font.FontFamily.GetLineSpacing(style);
int cellAscent = font.FontFamily.GetCellAscent(style);
int cellDescent = font.FontFamily.GetCellDescent(style);
int cellLeading = cellSpace - cellAscent - cellDescent;
double ascent = lineSpace * cellAscent / cellSpace;
double descent = lineSpace * cellDescent / cellSpace;
double leading = lineSpace * cellLeading / cellSpace;
double x = origin.X + dx;
double y = origin.Y;
//for (int idx = 0; idx < 16; idx++)
// gfx.DrawString("x" + idx.ToString("X"), labelFont, XBrushes.DarkGray, x + idx * dx, y);
for (int row = 0; row < 16; row++)
{
x = origin.X;
y += dy;
//gfx.DrawString(row.ToString("X") + "x", labelFont, XBrushes.DarkGray, x, y);
for (int clm = 0; clm < 16; clm++)
{
x += dx;
string glyph = encoding.GetString(new byte[1]{Convert.ToByte(row * 16 + clm)});
glyph += "!";
XSize size = gfx.MeasureString(glyph, font);
gfx.DrawRectangle(XBrushes.LightGray, x, y - size.Height + descent, size.Width, size.Height);
gfx.DrawRectangle(lighter, x, y - size.Height + descent, size.Width, leading);
gfx.DrawRectangle(lighter, x, y, size.Width, descent);
gfx.DrawString(glyph, font, XBrushes.Black, x, y);
}
}
}
示例11: DrawString
public static void DrawString(XGraphics gfx, string text, XFont font, XRect rect, Alignment alignment)
{
var size = gfx.MeasureString(text, font, XStringFormats.Center);
switch (alignment)
{
case Alignment.Right:
rect = new XRect(new XPoint(rect.X + rect.Width - size.Width, rect.Y), new XSize(size.Width, rect.Height));
break;
case Alignment.Center:
break;
default:
rect = new XRect(new XPoint(rect.X, rect.Y), new XSize(size.Width, rect.Height));
break;
}
gfx.DrawString(text, font, XBrushes.Black, rect, XStringFormats.Center);
}
示例12: DrawName
public void DrawName(XGraphics graphics, RectangleF rect, MapOptions options, XFont font, XBrush textBrush, LabelStyle labelStyle)
{
if (graphics == null)
throw new ArgumentNullException("graphics");
RectangleF bounds = TransformedBounds;
if (bounds.IntersectsWith(rect))
{
if (Name != null)
{
string str = Name;
if (labelStyle.Uppercase)
str = str.ToUpperInvariant();
PointF pos = NamePosition;// PointF( bounds.Left + bounds.Width / 2, bounds.Top + bounds.Height / 2 );
using (RenderUtil.SaveState(graphics))
{
XMatrix matrix = new XMatrix();
matrix.TranslatePrepend(pos.X, pos.Y);
matrix.ScalePrepend(1.0f / Astrometrics.ParsecScaleX, 1.0f / Astrometrics.ParsecScaleY);
matrix.RotatePrepend(-labelStyle.Rotation); // Rotate it
graphics.MultiplyTransform(matrix, XMatrixOrder.Prepend);
XSize size = graphics.MeasureString(str, font);
graphics.TranslateTransform(-size.Width / 2, -size.Height / 2); // Center the text
RectangleF textBounds = new RectangleF(0, 0, (float)size.Width, (float)size.Height * 2); // *2 or it gets cut off at high sizes
XTextFormatter tf = new XTextFormatter(graphics);
tf.Alignment = XParagraphAlignment.Center;
tf.DrawString(str, font, textBrush, textBounds);
}
}
}
}
示例13: Draw
public override float Draw(XGraphics gfx, PointF pt, bool dorender)
{
float acty = 0;
foreach (string line in GetLines(gfx))
{
float tpos = m_x0, apos = m_x0;
SongLineParser par = new SongLineParser(line);
while (par.Current != SongLineParser.Token.End)
{
if (par.Current == SongLineParser.Token.Word)
{
float wordwi = (float)gfx.MeasureString(par.Data, Options.TextFont).Width;
if (dorender) gfx.DrawString(par.Data, Options.TextFont, Options.TextColor, new PointF(pt.X + tpos, acty + pt.Y + Options.ChordHeight), XStringFormat.TopLeft);
tpos += wordwi;
}
if (par.Current == SongLineParser.Token.Space)
{
tpos += Options.HTextSpace;
}
if (par.Current == SongLineParser.Token.Chord)
{
if (tpos < apos) tpos = apos; // aby nebyly 2 akordy pres sebe
apos = tpos;
float chordwi = (float)gfx.MeasureString(par.Data, Options.ChordFont).Width;
if (dorender) gfx.DrawString(par.Data, Options.ChordFont, Options.ChordColor, new PointF(pt.X + apos, acty + pt.Y), XStringFormat.TopLeft);
apos += chordwi + Options.HChordSpace;
}
par.Read();
}
acty += Options.ChordHeight + Options.TextHeight;
}
DrawLabel(gfx, pt, Options.ChordHeight + Options.TextHeight);
return acty;
}
示例14: CalculatePosition
private XPoint CalculatePosition(PdfPage page, XGraphics gfx, XFont font, string text, double relativeX, double relativeY, HorizontalAlignment horizontal, VerticalAlignment vertical)
{
XSize size = gfx.MeasureString(text, font);
if (!ShouldHandleOrientation(page))
{
XPoint position = new XPoint();
position.X = page.Width * relativeX;
position.Y = page.Height * relativeY;
if (horizontal == HorizontalAlignment.Center) position.X -= size.Width / 2;
if (horizontal == HorizontalAlignment.Right) position.X -= size.Width;
if (vertical == VerticalAlignment.Center) position.Y += size.Height / 2;
if (vertical == VerticalAlignment.Top) position.Y += size.Height;
return position;
}
else
{
XPoint position = new XPoint();
position.X = page.Width * (1 - relativeY);
position.Y = page.Height * relativeX;
if (horizontal == HorizontalAlignment.Center) position.Y -= size.Width / 2;
if (horizontal == HorizontalAlignment.Right) position.Y -= size.Width;
if (vertical == VerticalAlignment.Center) position.X -= size.Height / 2;
if (vertical == VerticalAlignment.Top) position.X -= size.Height;
return position;
}
}
示例15: DrawStringTopRight
/*
* Draws the text in the top right corner and returns a new rect with reduced hight that fills the rest of the rect.
*/
public static XRect DrawStringTopRight(XGraphics gfx, string text, XFont font, XRect rect)
{
if (text == null) text = string.Empty;
XSize size = gfx.MeasureString(text, font, XStringFormats.TopLeft);
XRect topRight = new XRect(rect.Right - size.Width, rect.Top, size.Width, size.Height);
gfx.DrawString(text, font, XBrushes.Black, topRight, XStringFormats.TopLeft);
return new XRect(rect.Left, rect.Top + size.Height, rect.Width, rect.Height);
}