本文整理汇总了C#中PdfSharp.Drawing.XSize类的典型用法代码示例。如果您正苦于以下问题:C# XSize类的具体用法?C# XSize怎么用?C# XSize使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
XSize类属于PdfSharp.Drawing命名空间,在下文中一共展示了XSize类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BarCode
/// <summary>
/// Initializes a new instance of the <see cref="BarCode"/> class.
/// </summary>
/// <param name="text"></param>
/// <param name="size"></param>
/// <param name="direction"></param>
public BarCode(string text, XSize size, CodeDirection direction)
: base(text, size, direction)
{
this.text = text;
this.size = size;
this.direction = direction;
}
示例2: Format
/// <summary>
/// Calculates the space used for the X axis.
/// </summary>
internal override void Format()
{
AxisRendererInfo xari = ((ChartRendererInfo)this.rendererParms.RendererInfo).xAxisRendererInfo;
if (xari.axis != null)
{
AxisTitleRendererInfo atri = xari.axisTitleRendererInfo;
// Calculate space used for axis title.
XSize titleSize = new XSize(0, 0);
if (atri != null && atri.AxisTitleText != null && atri.AxisTitleText.Length > 0)
titleSize = this.rendererParms.Graphics.MeasureString(atri.AxisTitleText, atri.AxisTitleFont);
// Calculate space used for tick labels.
XSize size = new XSize(0, 0);
foreach (XSeries xs in xari.XValues)
{
foreach (XValue xv in xs)
{
XSize valueSize = this.rendererParms.Graphics.MeasureString(xv.Value, xari.TickLabelsFont);
size.Height += valueSize.Height;
size.Width = Math.Max(valueSize.Width, size.Width);
}
}
// Remember space for later drawing.
if (atri != null)
atri.AxisTitleSize = titleSize;
xari.TickLabelsHeight = size.Height;
xari.Height = size.Height;
xari.Width = titleSize.Width + size.Width + xari.MajorTickMarkWidth;
}
}
示例3: MeasureString
// ...took a look at the source code of WPF. About 50 classes and several 10,000 lines of code
// deal with that what colloquial is called 'fonts'.
// So let's start simple.
/// <summary>
/// Simple measure string function.
/// </summary>
public static XSize MeasureString(string text, XFont font, XStringFormat stringFormat)
{
XSize size = new XSize();
OpenTypeDescriptor descriptor = FontDescriptorStock.Global.CreateDescriptor(font) as OpenTypeDescriptor;
if (descriptor != null)
{
size.Height = (descriptor.Ascender + Math.Abs(descriptor.Descender)) * font.Size / font.unitsPerEm;
Debug.Assert(descriptor.Ascender > 0);
bool symbol = descriptor.fontData.cmap.symbol;
int length = text.Length;
int width = 0;
for (int idx = 0; idx < length; idx++)
{
char ch = text[idx];
int glyphIndex = 0;
if (symbol)
{
glyphIndex = ch + (descriptor.fontData.os2.usFirstCharIndex & 0xFF00); // @@@
glyphIndex = descriptor.CharCodeToGlyphIndex((char)glyphIndex);
}
else
glyphIndex = descriptor.CharCodeToGlyphIndex(ch);
//double width = descriptor.GlyphIndexToEmfWidth(glyphIndex, font.Size);
//size.Width += width;
width += descriptor.GlyphIndexToWidth(glyphIndex);
}
size.Width = width * font.Size * (font.Italic ? 1 : 1) / descriptor.UnitsPerEm;
}
Debug.Assert(descriptor != null, "No OpenTypeDescriptor.");
return size;
}
示例4: RenderPage
public override void RenderPage(XGraphics gfx)
{
base.RenderPage(gfx);
DrawGridlines(gfx);
// Create a new graphical path
XGraphicsPath path = new XGraphicsPath();
XSize size = new XSize(90, 140);
double rotationAngle = 130;
path.AddArc(new XPoint(100, 100), new XPoint(200, 200), size, rotationAngle, false, System.Windows.Media.SweepDirection.Clockwise);
path.StartFigure();
path.AddArc(new XPoint(400, 100), new XPoint(500, 200), size, rotationAngle, false, System.Windows.Media.SweepDirection.Counterclockwise);
path.StartFigure();
path.AddArc(new XPoint(100, 300), new XPoint(200, 400), size, rotationAngle, true, System.Windows.Media.SweepDirection.Clockwise);
path.StartFigure();
path.AddArc(new XPoint(400, 300), new XPoint(500, 400), size, rotationAngle, true, System.Windows.Media.SweepDirection.Counterclockwise);
path.StartFigure();
#if DEBUG_
gfx.WriteComment("PathArcSegment");
#endif
gfx.DrawPath(XPens.Red, path);
}
示例5: XGraphics
/// <summary>
/// Initializes a new instance of the XGraphics class.
/// </summary>
/// <param name="gfx">The GFX.</param>
/// <param name="size">The size.</param>
/// <param name="pageUnit">The page unit.</param>
/// <param name="pageDirection">The page direction.</param>
XGraphics(Graphics gfx, XSize size, XGraphicsUnit pageUnit, XPageDirection pageDirection)
{
if (gfx == null)
throw new ArgumentNullException("gfx");
this.gfx = gfx;
this.drawGraphics = true;
this.pageSize = new XSize(size.width, size.height);
this.pageUnit = pageUnit;
switch (pageUnit)
{
case XGraphicsUnit.Point:
this.pageSizePoints = new XSize(size.width, size.height);
break;
case XGraphicsUnit.Inch:
this.pageSizePoints = new XSize(XUnit.FromInch(size.width), XUnit.FromInch(size.height));
break;
case XGraphicsUnit.Millimeter:
this.pageSizePoints = new XSize(XUnit.FromMillimeter(size.width), XUnit.FromMillimeter(size.height));
break;
case XGraphicsUnit.Centimeter:
this.pageSizePoints = new XSize(XUnit.FromCentimeter(size.width), XUnit.FromCentimeter(size.height));
break;
default:
throw new NotImplementedException("unit");
}
this.pageDirection = pageDirection;
Initialize();
}
示例6: XRect
/// <summary>
/// Initializes a new instance of the XRect class.
/// </summary>
public XRect(XPoint location, XSize size)
{
this.x = location.X;
this.y = location.Y;
this.width = size.Width;
this.height = size.Height;
}
示例7: plpage_Paint
private void plpage_Paint(object sender, PaintEventArgs e)
{
if (m_source != null)
{
float zoom = zoomControl1.Zoom * m_zoomFactor;
GraphicsState state = e.Graphics.Save();
e.Graphics.ScaleTransform(zoom, zoom);
XSize size = new XSize(plpage.Width * zoom, plpage.Height * zoom);
m_source.DrawPage(XGraphics.FromGraphics(e.Graphics, size), tbpage.Value);
e.Graphics.Restore(state);
}
}
示例8: FromType
/// <summary>
/// Creates a bar code from the specified code type.
/// </summary>
public static BarCode FromType(CodeType type, string text, XSize size, CodeDirection direction)
{
switch (type)
{
case CodeType.Code2of5Interleaved:
return new Code2of5Interleaved(text, size, direction);
case CodeType.Code3of9Standard:
return new Code3of9Standard(text, size, direction);
default:
throw new InvalidEnumArgumentException("type", (int)type, typeof(CodeType));
}
}
示例9: Format
/// <summary>
/// Calculates the space used for the Y axis.
/// </summary>
internal override void Format()
{
AxisRendererInfo yari = ((ChartRendererInfo)this.rendererParms.RendererInfo).yAxisRendererInfo;
if (yari.axis != null)
{
XGraphics gfx = this.rendererParms.Graphics;
XSize size = new XSize(0, 0);
// height of all ticklabels
double yMin = yari.MinimumScale;
double yMax = yari.MaximumScale;
double yMajorTick = yari.MajorTick;
double lineHeight = Double.MinValue;
XSize labelSize = new XSize(0, 0);
for (double y = yMin; y <= yMax; y += yMajorTick)
{
string str = y.ToString(yari.TickLabelsFormat);
labelSize = gfx.MeasureString(str, yari.TickLabelsFont);
size.Height += labelSize.Height;
size.Width = Math.Max(size.Width, labelSize.Width);
lineHeight = Math.Max(lineHeight, labelSize.Height);
}
// add space for tickmarks
size.Width += yari.MajorTickMarkWidth * 1.5;
// Measure axis title
XSize titleSize = new XSize(0, 0);
if (yari.axisTitleRendererInfo != null)
{
RendererParameters parms = new RendererParameters();
parms.Graphics = gfx;
parms.RendererInfo = yari;
AxisTitleRenderer atr = new AxisTitleRenderer(parms);
atr.Format();
titleSize.Height = yari.axisTitleRendererInfo.Height;
titleSize.Width = yari.axisTitleRendererInfo.Width;
}
yari.Height = Math.Max(size.Height, titleSize.Height);
yari.Width = size.Width + titleSize.Width;
yari.InnerRect = yari.Rect;
yari.InnerRect.Y += yari.TickLabelsFont.Height / 2;
yari.LabelSize = labelSize;
}
}
示例10: Format
/// <summary>
/// Layouts and calculates the space used by the legend.
/// </summary>
internal override void Format()
{
ChartRendererInfo cri = (ChartRendererInfo)this.rendererParms.RendererInfo;
LegendRendererInfo lri = cri.legendRendererInfo;
if (lri == null)
return;
RendererParameters parms = new RendererParameters();
parms.Graphics = this.rendererParms.Graphics;
bool verticalLegend = (lri.legend.docking == DockingType.Left || lri.legend.docking == DockingType.Right);
XSize maxMarkerArea = new XSize();
LegendEntryRenderer ler = new LegendEntryRenderer(parms);
foreach (LegendEntryRendererInfo leri in lri.Entries)
{
parms.RendererInfo = leri;
ler.Format();
maxMarkerArea.Width = Math.Max(leri.MarkerArea.Width, maxMarkerArea.Width);
maxMarkerArea.Height = Math.Max(leri.MarkerArea.Height, maxMarkerArea.Height);
if (verticalLegend)
{
lri.Width = Math.Max(lri.Width, leri.Width);
lri.Height += leri.Height;
}
else
{
lri.Width += leri.Width;
lri.Height = Math.Max(lri.Height, leri.Height);
}
}
// Add padding to left, right, top and bottom
int paddingFactor = 1;
if (lri.BorderPen != null)
paddingFactor = 2;
lri.Width += (LegendRenderer.LeftPadding + LegendRenderer.RightPadding) * paddingFactor;
lri.Height += (LegendRenderer.TopPadding + LegendRenderer.BottomPadding) * paddingFactor;
if (verticalLegend)
lri.Height += LegendRenderer.EntrySpacing * (lri.Entries.Length - 1);
else
lri.Width += LegendRenderer.EntrySpacing * (lri.Entries.Length - 1);
foreach (LegendEntryRendererInfo leri in lri.Entries)
leri.MarkerArea = maxMarkerArea;
}
示例11: MeasureString
/// <summary>
/// Measure string directly from font data.
/// </summary>
public static XSize MeasureString(string text, XFont font, XStringFormat stringFormat)
{
XSize size = new XSize();
OpenTypeDescriptor descriptor = FontDescriptorCache.GetOrCreateDescriptorFor(font) as OpenTypeDescriptor;
if (descriptor != null)
{
// Height is the sum of ascender and descender.
size.Height = (descriptor.Ascender + descriptor.Descender) * font.Size / font.UnitsPerEm;
Debug.Assert(descriptor.Ascender > 0);
bool symbol = descriptor.FontFace.cmap.symbol;
int length = text.Length;
int width = 0;
for (int idx = 0; idx < length; idx++)
{
char ch = text[idx];
// HACK: Unclear what to do here.
if (ch < 32)
continue;
if (symbol)
{
// Remap ch for symbol fonts.
ch = (char)(ch | (descriptor.FontFace.os2.usFirstCharIndex & 0xFF00)); // @@@ refactor
// Used | instead of + because of: http://pdfsharp.codeplex.com/workitem/15954
}
int glyphIndex = descriptor.CharCodeToGlyphIndex(ch);
width += descriptor.GlyphIndexToWidth(glyphIndex);
}
// What? size.Width = width * font.Size * (font.Italic ? 1 : 1) / descriptor.UnitsPerEm;
size.Width = width * font.Size / descriptor.UnitsPerEm;
// Adjust bold simulation.
if ((font.GlyphTypeface.StyleSimulations & XStyleSimulations.BoldSimulation) == XStyleSimulations.BoldSimulation)
{
// Add 2% of the em-size for each character.
// Unsure how to deal with white space. Currently count as regular character.
size.Width += length * font.Size * Const.BoldEmphasis;
}
}
Debug.Assert(descriptor != null, "No OpenTypeDescriptor.");
return size;
}
示例12: XGraphics
/// <summary>
/// Initializes a new instance of the XGraphics class.
/// </summary>
/// <param name="gfx">The gfx.</param>
/// <param name="size">The size.</param>
/// <param name="pageUnit">The page unit.</param>
/// <param name="pageDirection">The page direction.</param>
XGraphics(Graphics gfx, XSize size, XGraphicsUnit pageUnit, XPageDirection pageDirection)
{
if (gfx == null)
{
//throw new ArgumentNullException("gfx");
gfx = Graphics.FromHwnd(IntPtr.Zero);
}
this.gsStack = new GraphicsStateStack(this);
this.targetContext = XGraphicTargetContext.GDI;
this.gfx = gfx;
this.drawGraphics = true;
this.pageSize = new XSize(size.width, size.height);
this.pageUnit = pageUnit;
switch (pageUnit)
{
case XGraphicsUnit.Point:
this.pageSizePoints = new XSize(size.width, size.height);
break;
case XGraphicsUnit.Inch:
this.pageSizePoints = new XSize(XUnit.FromInch(size.width), XUnit.FromInch(size.height));
break;
case XGraphicsUnit.Millimeter:
this.pageSizePoints = new XSize(XUnit.FromMillimeter(size.width), XUnit.FromMillimeter(size.height));
break;
case XGraphicsUnit.Centimeter:
this.pageSizePoints = new XSize(XUnit.FromCentimeter(size.width), XUnit.FromCentimeter(size.height));
break;
case XGraphicsUnit.Presentation:
this.pageSizePoints = new XSize(XUnit.FromPresentation(size.width), XUnit.FromPresentation(size.height));
break;
default:
throw new NotImplementedException("unit");
}
this.pageDirection = pageDirection;
Initialize();
}
示例13: MatrixCode
/// <summary>
/// Initializes a new instance of the <see cref="MatrixCode"/> class.
/// </summary>
public MatrixCode(string text, string encoding, int rows, int columns, XSize size)
: base(text, size, CodeDirection.LeftToRight)
{
this.encoding = encoding;
if (this.encoding == "" || this.encoding == null)
this.encoding = new String('a', this.text.Length);
if (columns < rows)
{
this.rows = columns;
this.columns = rows;
}
else
{
this.columns = columns;
this.rows = rows;
}
this.Text = text;
}
示例14: Format
/// <summary>
/// Calculates the space used for the X axis.
/// </summary>
internal override void Format()
{
AxisRendererInfo xari = ((ChartRendererInfo)_rendererParms.RendererInfo).xAxisRendererInfo;
if (xari._axis != null)
{
AxisTitleRendererInfo atri = xari._axisTitleRendererInfo;
// Calculate space used for axis title.
XSize titleSize = new XSize(0, 0);
if (atri != null && atri.AxisTitleText != null && atri.AxisTitleText.Length > 0)
{
titleSize = _rendererParms.Graphics.MeasureString(atri.AxisTitleText, atri.AxisTitleFont);
atri.AxisTitleSize = titleSize;
}
// Calculate space used for tick labels.
XSize size = new XSize(0, 0);
if (xari.XValues.Count > 0)
{
XSeries xs = xari.XValues[0];
foreach (XValue xv in xs)
{
if (xv != null)
{
string tickLabel = xv._value;
XSize valueSize = _rendererParms.Graphics.MeasureString(tickLabel, xari.TickLabelsFont);
size.Height = Math.Max(valueSize.Height, size.Height);
size.Width += valueSize.Width;
}
}
}
// Remember space for later drawing.
xari.TickLabelsHeight = size.Height;
xari.Height = titleSize.Height + size.Height + xari.MajorTickMarkWidth;
xari.Width = Math.Max(titleSize.Width, size.Width);
}
}
示例15: AreClose
/// <summary>
/// Indicates whether the values are so close that they can be considered as equal.
/// </summary>
public static bool AreClose(XSize size1, XSize size2)
{
return AreClose(size1.Width, size2.Width) && AreClose(size1.Height, size2.Height);
}