public Matrix(RectangleF rect, PointF[] plgpts) { if (plgpts == null) { throw new ArgumentNullException("plgpts"); } if (plgpts.Length != 3) { throw SafeNativeMethods.Gdip.StatusException(2); } IntPtr handle = SafeNativeMethods.Gdip.ConvertPointToMemory(plgpts); try { IntPtr zero = IntPtr.Zero; GPRECTF gprectf = new GPRECTF(rect); int status = SafeNativeMethods.Gdip.GdipCreateMatrix3(ref gprectf, new HandleRef(null, handle), out zero); if (status != 0) { throw SafeNativeMethods.Gdip.StatusException(status); } this.nativeMatrix = zero; } finally { Marshal.FreeHGlobal(handle); } }
/// <include file='doc\LinearGradientBrush.uex' path='docs/doc[@for="LinearGradientBrush.LinearGradientBrush2"]/*' /> /// <devdoc> /// <para> /// Encapsulates a new instance of the <see cref='System.Drawing.Drawing2D.LinearGradientBrush'/> class with /// the specified points, colors, and orientation. /// </para> /// </devdoc> public LinearGradientBrush(RectangleF rect, Color color1, Color color2, LinearGradientMode linearGradientMode) { //validate the LinearGradientMode enum if (!Enum.IsDefined(typeof(LinearGradientMode), linearGradientMode)) { throw new InvalidEnumArgumentException("linearGradientMode", (int)linearGradientMode, typeof(LinearGradientMode)); } //validate the rect if (rect.Width == 0.0 || rect.Height == 0.0) { throw new ArgumentException(SR.GetString(SR.GdiplusInvalidRectangle, rect.ToString())); } IntPtr brush = IntPtr.Zero; GPRECTF gprectf = new GPRECTF(rect); int status = SafeNativeMethods.GdipCreateLineBrushFromRect(ref gprectf, color1.ToArgb(), color2.ToArgb(), (int)linearGradientMode, (int)WrapMode.Tile, out brush); if (status != SafeNativeMethods.Ok) { throw SafeNativeMethods.StatusException(status); } SetNativeBrush(brush); }
public Matrix(RectangleF rect, PointF[] plgpts) { if (plgpts == null) { throw new ArgumentNullException("plgpts"); } if (plgpts.Length != 3) { throw SafeNativeMethods.Gdip.StatusException(SafeNativeMethods.Gdip.InvalidParameter); } IntPtr buf = SafeNativeMethods.Gdip.ConvertPointToMemory(plgpts); try { GPRECTF gprectf = new GPRECTF(rect); IntPtr nativeMatrix; int status = SafeNativeMethods.Gdip.GdipCreateMatrix3(ref gprectf, new HandleRef(null, buf), out nativeMatrix); if (status != SafeNativeMethods.Gdip.Ok) { throw SafeNativeMethods.Gdip.StatusException(status); } this.nativeMatrix = nativeMatrix; } finally { Marshal.FreeHGlobal(buf); } }
public LinearGradientBrush(RectangleF rect, Color color1, Color color2, LinearGradientMode linearGradientMode) { if (linearGradientMode < LinearGradientMode.Horizontal || linearGradientMode > LinearGradientMode.BackwardDiagonal) { throw new InvalidEnumArgumentException(nameof(linearGradientMode), unchecked ((int)linearGradientMode), typeof(LinearGradientMode)); } if (rect.Width == 0.0 || rect.Height == 0.0) { throw new ArgumentException(SR.Format(SR.GdiplusInvalidRectangle, rect.ToString())); } var gprectf = new GPRECTF(rect); IntPtr nativeBrush; int status = SafeNativeMethods.Gdip.GdipCreateLineBrushFromRect(ref gprectf, color1.ToArgb(), color2.ToArgb(), unchecked ((int)linearGradientMode), (int)WrapMode.Tile, out nativeBrush); SafeNativeMethods.Gdip.CheckStatus(status); SetNativeBrushInternal(nativeBrush); }
/// <include file='doc\LinearGradientBrush.uex' path='docs/doc[@for="LinearGradientBrush.LinearGradientBrush5"]/*' /> /// <devdoc> /// <para> /// Encapsulates a new instance of the <see cref='System.Drawing.Drawing2D.LinearGradientBrush'/> class with the /// specified points, colors, and orientation. /// </para> /// </devdoc> public LinearGradientBrush(RectangleF rect, Color color1, Color color2, float angle, bool isAngleScaleable) { IntPtr brush = IntPtr.Zero; //validate the rect if (rect.Width == 0.0 || rect.Height == 0.0) { throw new ArgumentException(SR.GetString(SR.GdiplusInvalidRectangle, rect.ToString())); } GPRECTF gprectf = new GPRECTF(rect); int status = SafeNativeMethods.GdipCreateLineBrushFromRectWithAngle(ref gprectf, color1.ToArgb(), color2.ToArgb(), angle, isAngleScaleable, (int)WrapMode.Tile, out brush); if (status != SafeNativeMethods.Ok) { throw SafeNativeMethods.StatusException(status); } SetNativeBrush(brush); }
// System.Drawing.Graphics /// <summary>Measures the specified string when drawn with the specified <see cref="T:System.Drawing.Font" /> and formatted with the specified <see cref="T:System.Drawing.StringFormat" />.</summary> /// <returns>This method returns a <see cref="T:System.Drawing.SizeF" /> structure that represents the size, in the units specified by the <see cref="P:System.Drawing.Graphics.PageUnit" /> property, of the string specified by the <paramref name="text" /> parameter as drawn with the <paramref name="font" /> parameter and the <paramref name="stringFormat" /> parameter.</returns> /// <param name="text">String to measure. </param> /// <param name="font"> /// <see cref="T:System.Drawing.Font" /> defines the text format of the string. </param> /// <param name="origin"> /// <see cref="T:System.Drawing.PointF" /> structure that represents the upper-left corner of the string. </param> /// <param name="stringFormat"> /// <see cref="T:System.Drawing.StringFormat" /> that represents formatting information, such as line spacing, for the string. </param> /// <exception cref="T:System.ArgumentException"> /// <paramref name="font" /> is null.</exception> /// <filterpriority>1</filterpriority> public SizeF MeasureString(string text, Font font, PointF origin, StringFormat stringFormat) { if (text == null || text.Length == 0) { return(new SizeF(0f, 0f)); } if (font == null) { throw new ArgumentNullException("font"); } GPRECTF gPRECTF = default(GPRECTF); GPRECTF gPRECTF2 = default(GPRECTF); gPRECTF.X = origin.X; gPRECTF.Y = origin.Y; gPRECTF.Width = 0f; gPRECTF.Height = 0f; int num2; int num3; throw new NotImplementedException(); //int num = SafeNativeMethods.Gdip.GdipMeasureString(new HandleRef(this, this.NativeGraphics), text, text.Length, new HandleRef(font, font.NativeFont), ref gPRECTF, new HandleRef(stringFormat, (stringFormat == null) ? IntPtr.Zero : stringFormat.nativeFormat), ref gPRECTF2, out num2, out num3); //if (num != 0) //{ // throw SafeNativeMethods.Gdip.StatusException(num); //} return(gPRECTF2.SizeF); }
public void Complement(RectangleF rect) { var gprectf = new GPRECTF(rect); int status = SafeNativeMethods.Gdip.GdipCombineRegionRect(new HandleRef(this, _nativeRegion), ref gprectf, CombineMode.Complement); SafeNativeMethods.Gdip.CheckStatus(status); }
/// <summary> /// Initializes a new instance of the <see cref='Metafile'/> class with the specified filename. /// </summary> public Metafile(string fileName, IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit, EmfType type, String description) { // Called in order to emulate exception behavior from netfx related to invalid file paths. Path.GetFullPath(fileName); if (fileName.Length > MaxPath) { throw new PathTooLongException(); } IntPtr metafile = IntPtr.Zero; GPRECTF rectf = new GPRECTF(frameRect); int status = SafeNativeMethods.Gdip.GdipRecordMetafileFileName(fileName, new HandleRef(null, referenceHdc), unchecked((int)type), ref rectf, unchecked((int)frameUnit), description, out metafile); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); SetNativeImage(metafile); }
public LinearGradientBrush(RectangleF rect, Color color1, Color color2, LinearGradientMode linearGradientMode) { //validate the LinearGradientMode enum //valid values are 0x0 to 0x3 if (!ClientUtils.IsEnumValid(linearGradientMode, unchecked ((int)linearGradientMode), (int)LinearGradientMode.Horizontal, (int)LinearGradientMode.BackwardDiagonal)) { throw new InvalidEnumArgumentException("linearGradientMode", unchecked ((int)linearGradientMode), typeof(LinearGradientMode)); } //validate the rect if (rect.Width == 0.0 || rect.Height == 0.0) { throw new ArgumentException(SR.Format(SR.GdiplusInvalidRectangle, rect.ToString())); } GPRECTF gprectf = new GPRECTF(rect); IntPtr nativeBrush; int status = SafeNativeMethods.Gdip.GdipCreateLineBrushFromRect(ref gprectf, color1.ToArgb(), color2.ToArgb(), unchecked ((int)linearGradientMode), (int)WrapMode.Tile, out nativeBrush); if (status != SafeNativeMethods.Gdip.Ok) { throw SafeNativeMethods.Gdip.StatusException(status); } SetNativeBrushInternal(nativeBrush); }
public void Intersect(RectangleF rect) { GPRECTF gprectf = rect.ToGPRECTF(); int status = SafeNativeMethods.Gdip.GdipCombineRegionRect(new HandleRef(this, _nativeRegion), ref gprectf, CombineMode.Intersect); SafeNativeMethods.Gdip.CheckStatus(status); }
public RectangleF GetBounds(Matrix matrix, Pen pen) { GPRECTF gprectf = new GPRECTF(); IntPtr nativeMatrix = IntPtr.Zero, nativePen = IntPtr.Zero; if (matrix != null) { nativeMatrix = matrix.nativeMatrix; } if (pen != null) { nativePen = pen.NativePen; } int status = SafeNativeMethods.Gdip.GdipGetPathWorldBounds(new HandleRef(this, nativePath), ref gprectf, new HandleRef(matrix, nativeMatrix), new HandleRef(pen, nativePen)); if (status != SafeNativeMethods.Gdip.Ok) { throw SafeNativeMethods.Gdip.StatusException(status); } return(gprectf.ToRectangleF()); }
public void AddString(string s, FontFamily family, int style, float emSize, RectangleF layoutRect, StringFormat format) { GPRECTF gprectf = new GPRECTF(layoutRect); int status = SafeNativeMethods.Gdip.GdipAddPathString(new HandleRef(this, this.nativePath), s, s.Length, new HandleRef(family, (family != null) ? family.NativeFamily : IntPtr.Zero), style, emSize, ref gprectf, new HandleRef(format, (format != null) ? format.nativeFormat : IntPtr.Zero)); if (status != 0) { throw SafeNativeMethods.Gdip.StatusException(status); } }
public Region(RectangleF rect) { IntPtr region = IntPtr.Zero; var gprectf = new GPRECTF(rect); int status = SafeNativeMethods.Gdip.GdipCreateRegionRect(ref gprectf, out region); SafeNativeMethods.Gdip.CheckStatus(status); SetNativeRegion(region); }
// float version /// <include file='doc\Region.uex' path='docs/doc[@for="Region.Exclude"]/*' /> /// <devdoc> /// Updates this <see cref='System.Drawing.Region'/> to the portion of its interior /// that does not intersect with the specified <see cref='System.Drawing.RectangleF'/>. /// </devdoc> public void Exclude(RectangleF rect) { GPRECTF gprectf = new GPRECTF(rect); int status = SafeNativeMethods.Gdip.GdipCombineRegionRect(new HandleRef(this, nativeRegion), ref gprectf, CombineMode.Exclude); if (status != SafeNativeMethods.Gdip.Ok) { throw SafeNativeMethods.Gdip.StatusException(status); } }
/// <summary> /// Gets a bounding rectangle in the specified units for this <see cref='Image'/>. /// </summary> public RectangleF GetBounds(ref GraphicsUnit pageUnit) { GPRECTF gprectf = new GPRECTF(); int status = SafeNativeMethods.Gdip.GdipGetImageBounds(new HandleRef(this, nativeImage), ref gprectf, out pageUnit); SafeNativeMethods.Gdip.CheckStatus(status); return(gprectf.ToRectangleF()); }
// float version /// <include file='doc\Region.uex' path='docs/doc[@for="Region.Complement"]/*' /> /// <devdoc> /// Updates this <see cref='System.Drawing.Region'/> to the portion of the /// specified <see cref='System.Drawing.RectangleF'/> that does not intersect with this <see cref='System.Drawing.Region'/>. /// </devdoc> public void Complement(RectangleF rect) { GPRECTF gprectf = rect.ToGPRECTF(); int status = SafeNativeMethods.Gdip.GdipCombineRegionRect(new HandleRef(this, nativeRegion), ref gprectf, CombineMode.Complement); if (status != SafeNativeMethods.Gdip.Ok) { throw SafeNativeMethods.Gdip.StatusException(status); } }
private RectangleF _GetRectangle() { GPRECTF gprectf = new GPRECTF(); int status = SafeNativeMethods.Gdip.GdipGetPathGradientRect(new HandleRef(this, base.NativeBrush), ref gprectf); if (status != 0) { throw SafeNativeMethods.Gdip.StatusException(status); } return(gprectf.ToRectangleF()); }
public RectangleF GetBounds(ref GraphicsUnit pageUnit) { GPRECTF gprectf = new GPRECTF(); int status = SafeNativeMethods.Gdip.GdipGetImageBounds(new HandleRef(this, this.nativeImage), ref gprectf, out pageUnit); if (status != 0) { throw SafeNativeMethods.Gdip.StatusException(status); } return(gprectf.ToRectangleF()); }
/// <include file='doc\Region.uex' path='docs/doc[@for="Region.GetRegionScans"]/*' /> /// <devdoc> /// <para> /// Returns an array of <see cref='System.Drawing.RectangleF'/> /// objects that approximate this Region on the specified /// </para> /// </devdoc> public RectangleF[] GetRegionScans(Matrix matrix) { if (matrix == null) { throw new ArgumentNullException("matrix"); } int count = 0; // call first time to get actual count of rectangles int status = SafeNativeMethods.Gdip.GdipGetRegionScansCount(new HandleRef(this, nativeRegion), out count, new HandleRef(matrix, matrix.nativeMatrix)); if (status != SafeNativeMethods.Gdip.Ok) { throw SafeNativeMethods.Gdip.StatusException(status); } RectangleF[] rectangles; int rectsize = (int)Marshal.SizeOf(typeof(GPRECTF)); IntPtr memoryRects = Marshal.AllocHGlobal(checked (rectsize * count)); try { status = SafeNativeMethods.Gdip.GdipGetRegionScans(new HandleRef(this, nativeRegion), memoryRects, out count, new HandleRef(matrix, matrix.nativeMatrix)); if (status != SafeNativeMethods.Gdip.Ok) { throw SafeNativeMethods.Gdip.StatusException(status); } int index; GPRECTF gprectf = new GPRECTF(); rectangles = new RectangleF[count]; for (index = 0; index < count; index++) { gprectf = (GPRECTF)UnsafeNativeMethods.PtrToStructure((IntPtr)(checked ((long)memoryRects + rectsize * index)), typeof(GPRECTF)); rectangles[index] = gprectf.ToRectangleF(); } } finally { Marshal.FreeHGlobal(memoryRects); } return(rectangles); }
/** * Get source rectangle */ private RectangleF _GetRectangle() { GPRECTF rect = new GPRECTF(); int status = SafeNativeMethods.GdipGetLineRect(new HandleRef(this, nativeBrush), ref rect); if (status != SafeNativeMethods.Ok) { throw SafeNativeMethods.StatusException(status); } return(rect.ToRectangleF()); }
public Metafile(Stream stream, IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit, EmfType type, string description) { System.Drawing.IntSecurity.ObjectFromWin32Handle.Demand(); IntPtr zero = IntPtr.Zero; GPRECTF gprectf = new GPRECTF(frameRect); int status = SafeNativeMethods.Gdip.GdipRecordMetafileStream(new GPStream(stream), new HandleRef(null, referenceHdc), (int)type, ref gprectf, (int)frameUnit, description, out zero); if (status != 0) { throw SafeNativeMethods.Gdip.StatusException(status); } base.SetNativeImage(zero); }
public RectangleF GetBounds(Graphics g) { if (g == null) { throw new ArgumentNullException(nameof(g)); } var gprectf = new GPRECTF(); int status = SafeNativeMethods.Gdip.GdipGetRegionBounds(new HandleRef(this, _nativeRegion), new HandleRef(g, g.NativeGraphics), ref gprectf); SafeNativeMethods.Gdip.CheckStatus(status); return(gprectf.ToRectangleF()); }
public RectangleF GetBounds(Graphics g) { if (g == null) { throw new ArgumentNullException("g"); } GPRECTF gprectf = new GPRECTF(); int status = SafeNativeMethods.Gdip.GdipGetRegionBounds(new HandleRef(this, this.nativeRegion), new HandleRef(g, g.NativeGraphics), ref gprectf); if (status != 0) { throw SafeNativeMethods.Gdip.StatusException(status); } return(gprectf.ToRectangleF()); }
public Region(RectangleF rect) { IntPtr region = IntPtr.Zero; GPRECTF gprectf = rect.ToGPRECTF(); int status = SafeNativeMethods.Gdip.GdipCreateRegionRect(ref gprectf, out region); if (status != SafeNativeMethods.Gdip.Ok) { throw SafeNativeMethods.Gdip.StatusException(status); } SetNativeRegion(region); }
/// <summary> /// Initializes a new instance of the <see cref='Metafile'/> class from the specified device context, bounded /// by the specified rectangle. /// </summary> public Metafile(IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit, EmfType type, String description) { IntPtr metafile = IntPtr.Zero; GPRECTF rectf = new GPRECTF(frameRect); int status = SafeNativeMethods.Gdip.GdipRecordMetafile(new HandleRef(null, referenceHdc), unchecked((int)type), ref rectf, unchecked((int)frameUnit), description, out metafile); if (status != SafeNativeMethods.Gdip.Ok) throw SafeNativeMethods.Gdip.StatusException(status); SetNativeImage(metafile); }
public LinearGradientBrush(RectangleF rect, Color color1, Color color2, float angle, bool isAngleScaleable) { IntPtr zero = IntPtr.Zero; if ((rect.Width == 0.0) || (rect.Height == 0.0)) { throw new ArgumentException(System.Drawing.SR.GetString("GdiplusInvalidRectangle", new object[] { rect.ToString() })); } GPRECTF gprectf = new GPRECTF(rect); int status = SafeNativeMethods.Gdip.GdipCreateLineBrushFromRectWithAngle(ref gprectf, color1.ToArgb(), color2.ToArgb(), angle, isAngleScaleable, 0, out zero); if (status != 0) { throw SafeNativeMethods.Gdip.StatusException(status); } base.SetNativeBrushInternal(zero); }
/// <include file='doc\Metafile.uex' path='docs/doc[@for="Metafile.Metafile10"]/*' /> /// <devdoc> /// <para> /// Initializes a new instance of the <see cref='System.Drawing.Imaging.Metafile'/> class from the specified device context, /// bounded by the specified rectangle. /// </para> /// </devdoc> public Metafile(IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit, EmfType type, String description) { IntSecurity.ObjectFromWin32Handle.Demand(); IntPtr metafile = IntPtr.Zero; GPRECTF rectf = new GPRECTF(frameRect); int status = SafeNativeMethods.GdipRecordMetafile(new HandleRef(null, referenceHdc), (int)type, ref rectf, (int)frameUnit, description, out metafile); if (status != SafeNativeMethods.Ok) { throw SafeNativeMethods.StatusException(status); } SetNativeImage(metafile); }
public void AddString(string s, FontFamily family, int style, float emSize, PointF origin, StringFormat format) { GPRECTF rectf = new GPRECTF(origin.X, origin.Y, 0, 0); int status = SafeNativeMethods.Gdip.GdipAddPathString(new HandleRef(this, nativePath), s, s.Length, new HandleRef(family, (family != null) ? family.NativeFamily : IntPtr.Zero), style, emSize, ref rectf, new HandleRef(format, (format != null) ? format.nativeFormat : IntPtr.Zero)); if (status != SafeNativeMethods.Gdip.Ok) { throw SafeNativeMethods.Gdip.StatusException(status); } }
public LinearGradientBrush(RectangleF rect, Color color1, Color color2, LinearGradientMode linearGradientMode) { if (!System.Drawing.ClientUtils.IsEnumValid(linearGradientMode, (int)linearGradientMode, 0, 3)) { throw new InvalidEnumArgumentException("linearGradientMode", (int)linearGradientMode, typeof(LinearGradientMode)); } if ((rect.Width == 0.0) || (rect.Height == 0.0)) { throw new ArgumentException(System.Drawing.SR.GetString("GdiplusInvalidRectangle", new object[] { rect.ToString() })); } IntPtr zero = IntPtr.Zero; GPRECTF gprectf = new GPRECTF(rect); int status = SafeNativeMethods.Gdip.GdipCreateLineBrushFromRect(ref gprectf, color1.ToArgb(), color2.ToArgb(), (int)linearGradientMode, 0, out zero); if (status != 0) { throw SafeNativeMethods.Gdip.StatusException(status); } base.SetNativeBrushInternal(zero); }
public RectangleF[] GetRegionScans(Matrix matrix) { if (matrix == null) { throw new ArgumentNullException(nameof(matrix)); } int count = 0; int status = SafeNativeMethods.Gdip.GdipGetRegionScansCount(new HandleRef(this, _nativeRegion), out count, new HandleRef(matrix, matrix.nativeMatrix)); SafeNativeMethods.Gdip.CheckStatus(status); int rectsize = (int)Marshal.SizeOf(typeof(GPRECTF)); IntPtr memoryRects = Marshal.AllocHGlobal(checked (rectsize * count)); try { status = SafeNativeMethods.Gdip.GdipGetRegionScans(new HandleRef(this, _nativeRegion), memoryRects, out count, new HandleRef(matrix, matrix.nativeMatrix)); SafeNativeMethods.Gdip.CheckStatus(status); var gprectf = new GPRECTF(); var rectangles = new RectangleF[count]; for (int index = 0; index < count; index++) { gprectf = (GPRECTF)Marshal.PtrToStructure((IntPtr)(checked ((long)memoryRects + rectsize * index)), typeof(GPRECTF)); rectangles[index] = gprectf.ToRectangleF(); } return(rectangles); } finally { Marshal.FreeHGlobal(memoryRects); } }