Skip to content

Commit

Permalink
address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
eiriktsarpalis committed Feb 25, 2020
1 parent 7b2f5c9 commit fe36f59
Show file tree
Hide file tree
Showing 17 changed files with 82 additions and 80 deletions.
62 changes: 31 additions & 31 deletions src/libraries/System.Drawing.Common/ref/System.Drawing.Common.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ private static void PlatformInitialize()
internal static extern int GdipGetImageBounds(HandleRef image, out RectangleF gprectf, out GraphicsUnit unit);

[DllImport(LibraryName, ExactSpelling = true)]
internal static extern int GdipGetImageThumbnail(HandleRef image, int thumbWidth, int thumbHeight, out IntPtr thumbImage, Image.GetThumbnailImageAbort callback, IntPtr callbackdata);
internal static extern int GdipGetImageThumbnail(HandleRef image, int thumbWidth, int thumbHeight, out IntPtr thumbImage, Image.GetThumbnailImageAbort? callback, IntPtr callbackdata);

[DllImport(LibraryName, ExactSpelling = true)]
internal static extern int GdipGetImagePalette(HandleRef image, IntPtr palette, int size);
Expand Down
30 changes: 15 additions & 15 deletions src/libraries/System.Drawing.Common/src/System/Drawing/Graphics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1400,32 +1400,32 @@ public unsafe void FillClosedCurve(Brush brush, Point[] points, FillMode fillmod
/// <summary>
/// Draws a string with the specified font.
/// </summary>
public void DrawString(string s, Font font, Brush brush, float x, float y)
public void DrawString(string? s, Font font, Brush brush, float x, float y)
{
DrawString(s, font, brush, new RectangleF(x, y, 0, 0), null);
}

public void DrawString(string s, Font font, Brush brush, PointF point)
public void DrawString(string? s, Font font, Brush brush, PointF point)
{
DrawString(s, font, brush, new RectangleF(point.X, point.Y, 0, 0), null);
}

public void DrawString(string s, Font font, Brush brush, float x, float y, StringFormat format)
public void DrawString(string? s, Font font, Brush brush, float x, float y, StringFormat? format)
{
DrawString(s, font, brush, new RectangleF(x, y, 0, 0), format);
}

public void DrawString(string s, Font font, Brush brush, PointF point, StringFormat format)
public void DrawString(string? s, Font font, Brush brush, PointF point, StringFormat? format)
{
DrawString(s, font, brush, new RectangleF(point.X, point.Y, 0, 0), format);
}

public void DrawString(string s, Font font, Brush brush, RectangleF layoutRectangle)
public void DrawString(string? s, Font font, Brush brush, RectangleF layoutRectangle)
{
DrawString(s, font, brush, layoutRectangle, null);
}

public void DrawString(string s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat? format)
public void DrawString(string? s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat? format)
{
if (brush == null)
throw new ArgumentNullException(nameof(brush));
Expand All @@ -1445,10 +1445,10 @@ public void DrawString(string s, Font font, Brush brush, RectangleF layoutRectan
}

public SizeF MeasureString(
string text,
string? text,
Font font,
SizeF layoutArea,
StringFormat stringFormat,
StringFormat? stringFormat,
out int charactersFitted,
out int linesFilled)
{
Expand Down Expand Up @@ -1479,7 +1479,7 @@ public SizeF MeasureString(
return boundingBox.Size;
}

public SizeF MeasureString(string text, Font font, PointF origin, StringFormat? stringFormat)
public SizeF MeasureString(string? text, Font font, PointF origin, StringFormat? stringFormat)
{
if (string.IsNullOrEmpty(text))
return SizeF.Empty;
Expand All @@ -1503,9 +1503,9 @@ public SizeF MeasureString(string text, Font font, PointF origin, StringFormat?
return boundingBox.Size;
}

public SizeF MeasureString(string text, Font font, SizeF layoutArea) => MeasureString(text, font, layoutArea, null);
public SizeF MeasureString(string? text, Font font, SizeF layoutArea) => MeasureString(text, font, layoutArea, null);

public SizeF MeasureString(string text, Font font, SizeF layoutArea, StringFormat? stringFormat)
public SizeF MeasureString(string? text, Font font, SizeF layoutArea, StringFormat? stringFormat)
{
if (string.IsNullOrEmpty(text))
return SizeF.Empty;
Expand All @@ -1529,22 +1529,22 @@ public SizeF MeasureString(string text, Font font, SizeF layoutArea, StringForma
return boundingBox.Size;
}

public SizeF MeasureString(string text, Font font)
public SizeF MeasureString(string? text, Font font)
{
return MeasureString(text, font, new SizeF(0, 0));
}

public SizeF MeasureString(string text, Font font, int width)
public SizeF MeasureString(string? text, Font font, int width)
{
return MeasureString(text, font, new SizeF(width, 999999));
}

public SizeF MeasureString(string text, Font font, int width, StringFormat format)
public SizeF MeasureString(string? text, Font font, int width, StringFormat? format)
{
return MeasureString(text, font, new SizeF(width, 999999), format);
}

public Region[] MeasureCharacterRanges(string text, Font font, RectangleF layoutRect, StringFormat stringFormat)
public Region[] MeasureCharacterRanges(string? text, Font font, RectangleF layoutRect, StringFormat? stringFormat)
{
if (string.IsNullOrEmpty(text))
return Array.Empty<Region>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public PropertyItem GetPropertyItem(int propid)
return item;
}

public Image GetThumbnailImage(int thumbWidth, int thumbHeight, Image.GetThumbnailImageAbort callback, IntPtr callbackData)
public Image GetThumbnailImage(int thumbWidth, int thumbHeight, Image.GetThumbnailImageAbort? callback, IntPtr callbackData)
{
if ((thumbWidth <= 0) || (thumbHeight <= 0))
throw new OutOfMemoryException(SR.InvalidThumbnailSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ public void Save(Stream stream, ImageCodecInfo encoder, EncoderParameters? encod
/// <summary>
/// Adds an <see cref='EncoderParameters'/> to this <see cref='Image'/>.
/// </summary>
public void SaveAdd(EncoderParameters encoderParams)
public void SaveAdd(EncoderParameters? encoderParams)
{
IntPtr encoder = IntPtr.Zero;
if (encoderParams != null)
Expand All @@ -282,7 +282,7 @@ public void SaveAdd(EncoderParameters encoderParams)
/// <summary>
/// Adds an <see cref='EncoderParameters'/> to the specified <see cref='Image'/>.
/// </summary>
public void SaveAdd(Image image, EncoderParameters encoderParams)
public void SaveAdd(Image image, EncoderParameters? encoderParams)
{
IntPtr encoder = IntPtr.Zero;

Expand Down Expand Up @@ -374,7 +374,7 @@ public ColorPalette Palette
/// <summary>
/// Returns the thumbnail for this <see cref='Image'/>.
/// </summary>
public Image GetThumbnailImage(int thumbWidth, int thumbHeight, GetThumbnailImageAbort callback, IntPtr callbackData)
public Image GetThumbnailImage(int thumbWidth, int thumbHeight, GetThumbnailImageAbort? callback, IntPtr callbackData)
{
IntPtr thumbImage = IntPtr.Zero;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public static void Animate(Image image, EventHandler onFrameChangedHandler)
thread.Start();
}

public static bool CanAnimate(Image image)
public static bool CanAnimate(Image? image)
{
if (image == null)
return false;
Expand Down Expand Up @@ -144,7 +144,7 @@ public static void UpdateFrames()
}


public static void UpdateFrames(Image? image)
public static void UpdateFrames(Image image)
{
if (image == null)
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ private ImageAnimator()
/// <summary>
/// Advances the frame in the specified image. The new frame is drawn the next time the image is rendered.
/// </summary>
public static void UpdateFrames(Image? image)
public static void UpdateFrames(Image image)
{
if (!s_anyFrameDirty || image == null || s_imageInfoList == null)
{
Expand Down Expand Up @@ -194,7 +194,7 @@ public static void UpdateFrames()
/// Adds an image to the image manager. If the image does not support animation this method does nothing.
/// This method creates the image list and spawns the animation thread the first time it is called.
/// </summary>
public static void Animate(Image? image, EventHandler onFrameChangedHandler)
public static void Animate(Image image, EventHandler onFrameChangedHandler)
{
if (image == null)
{
Expand Down Expand Up @@ -315,7 +315,7 @@ public static bool CanAnimate(Image? image)
/// <summary>
/// Removes an image from the image manager so it is no longer animated.
/// </summary>
public static void StopAnimate(Image? image, EventHandler onFrameChangedHandler)
public static void StopAnimate(Image image, EventHandler onFrameChangedHandler)
{
// Make sure we have a list of images
if (image == null || s_imageInfoList == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,14 @@ private class ImageInfo
private bool _frameDirty;
private readonly bool _animated;
private EventHandler? _onFrameChangedHandler;
private readonly int[]? _frameDelay;
private readonly int[] _frameDelay;
private int _frameTimer;

public ImageInfo(Image image)
{
_image = image;
_animated = ImageAnimator.CanAnimate(image);
_frameDelay = null!; // guaranteed to be initialized by the final check

if (_animated)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,17 +200,17 @@ public void ClearColorMatrix(ColorAdjustType type)
/// <summary>
/// Sets a color adjust matrix for image colors and a separate gray scale adjust matrix for gray scale values.
/// </summary>
public void SetColorMatrices(ColorMatrix newColorMatrix, ColorMatrix grayMatrix)
public void SetColorMatrices(ColorMatrix newColorMatrix, ColorMatrix? grayMatrix)
{
SetColorMatrices(newColorMatrix, grayMatrix, ColorMatrixFlag.Default, ColorAdjustType.Default);
}

public void SetColorMatrices(ColorMatrix newColorMatrix, ColorMatrix grayMatrix, ColorMatrixFlag flags)
public void SetColorMatrices(ColorMatrix newColorMatrix, ColorMatrix? grayMatrix, ColorMatrixFlag flags)
{
SetColorMatrices(newColorMatrix, grayMatrix, flags, ColorAdjustType.Default);
}

public void SetColorMatrices(ColorMatrix newColorMatrix, ColorMatrix grayMatrix, ColorMatrixFlag mode,
public void SetColorMatrices(ColorMatrix newColorMatrix, ColorMatrix? grayMatrix, ColorMatrixFlag mode,
ColorAdjustType type)
{
int status = Gdip.GdipSetImageAttributesColorMatrix(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public Metafile(string fileName, IntPtr referenceHdc, RectangleF frameRect, Meta
/// <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, string desc) :
public Metafile(string fileName, IntPtr referenceHdc, RectangleF frameRect, MetafileFrameUnit frameUnit, string? desc) :
this(fileName, referenceHdc, frameRect, frameUnit, EmfType.EmfPlusDual, desc)
{
}
Expand Down Expand Up @@ -230,7 +230,7 @@ public Metafile(string fileName, IntPtr referenceHdc, Rectangle frameRect, Metaf
/// <summary>
/// Initializes a new instance of the <see cref='Metafile'/> class with the specified filename.
/// </summary>
public Metafile(string fileName, IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit, string description) :
public Metafile(string fileName, IntPtr referenceHdc, Rectangle frameRect, MetafileFrameUnit frameUnit, string? description) :
this(fileName, referenceHdc, frameRect, frameUnit, EmfType.EmfPlusDual, description)
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public override void OnStartPrint(PrintDocument document, PrintEventArgs e)
/// <summary>
/// Implements StartPage for printing to a physical printer.
/// </summary>
public override Graphics? OnStartPage(PrintDocument document, PrintPageEventArgs e)
public override Graphics OnStartPage(PrintDocument document, PrintPageEventArgs e)
{
Debug.Assert(_dc != null && _graphics == null, "PrintController methods called in the wrong order?");
Debug.Assert(_modeHandle != null);
Expand All @@ -78,7 +78,7 @@ public override void OnStartPrint(PrintDocument document, PrintEventArgs e)

_graphics = Graphics.FromHdcInternal(_dc.Hdc);

if (_graphics != null && document.OriginAtMargins)
if (document.OriginAtMargins)
{
// Adjust the origin of the graphics object to be at the
// user-specified margin location
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public override bool Equals(object? obj)
/// <summary>
/// Tests whether two <see cref='Margins'/> objects are identical.
/// </summary>
public static bool operator ==(Margins m1, Margins m2)
public static bool operator ==(Margins? m1, Margins? m2)
{
if (m1 is null)
{
Expand All @@ -232,7 +232,7 @@ public override bool Equals(object? obj)
/// <summary>
/// Tests whether two <see cref='Margins'/> objects are different.
/// </summary>
public static bool operator !=(Margins m1, Margins m2) => !(m1 == m2);
public static bool operator !=(Margins? m1, Margins? m2) => !(m1 == m2);

/// <summary>
/// Provides some interesting information for the Margins in String form.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public override Graphics OnStartPage(PrintDocument document, PrintPageEventArgs
PrintPreviewGraphics printGraphics = new PrintPreviewGraphics(document, e);
_graphics = Graphics.FromImage(metafile);

if (_graphics != null && document.OriginAtMargins)
if (document.OriginAtMargins)
{
// Adjust the origin of the graphics object to be at the
// user-specified margin location
Expand All @@ -84,7 +84,7 @@ public override Graphics OnStartPage(PrintDocument document, PrintPageEventArgs
_graphics.TranslateTransform(document.DefaultPageSettings.Margins.Left, document.DefaultPageSettings.Margins.Top);
}

_graphics!.PrintingHelper = printGraphics;
_graphics.PrintingHelper = printGraphics;

if (UseAntiAlias)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,7 @@ public PrinterSettings.PaperSourceCollection? PaperSources
return paper_sources;
}
}
public
string? PrintFileName
public string? PrintFileName
{
get { return print_filename; }
set { print_filename = value; }
Expand Down Expand Up @@ -525,9 +524,9 @@ public StringCollection(string[] array)
bool ICollection.IsSynchronized { get { return false; } }
object ICollection.SyncRoot { get { return this; } }

public virtual string? this[int index]
public virtual string this[int index]
{
get { return _Strings[index] as string; }
get { return (_Strings[index] as string)!; }
}
[EditorBrowsable(EditorBrowsableState.Never)]
public int Add(string value) { return _Strings.Add(value); }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -614,10 +614,10 @@ public Graphics CreateMeasurementGraphics()
}

//whatever the call stack calling HardMarginX and HardMarginY here is safe
public Graphics? CreateMeasurementGraphics(bool honorOriginAtMargins)
public Graphics CreateMeasurementGraphics(bool honorOriginAtMargins)
{
Graphics g = CreateMeasurementGraphics();
if (g != null && honorOriginAtMargins)
if (honorOriginAtMargins)
{
g.TranslateTransform(-_defaultPageSettings.HardMarginX, -_defaultPageSettings.HardMarginY);
g.TranslateTransform(_defaultPageSettings.Margins.Left, _defaultPageSettings.Margins.Top);
Expand All @@ -635,10 +635,10 @@ public Graphics CreateMeasurementGraphics(PageSettings pageSettings)
}

//whatever the call stack calling HardMarginX and HardMarginY here is safe
public Graphics? CreateMeasurementGraphics(PageSettings pageSettings, bool honorOriginAtMargins)
public Graphics CreateMeasurementGraphics(PageSettings pageSettings, bool honorOriginAtMargins)
{
Graphics g = CreateMeasurementGraphics();
if (g != null && honorOriginAtMargins)
if (honorOriginAtMargins)
{
g.TranslateTransform(-pageSettings.HardMarginX, -pageSettings.HardMarginY);
g.TranslateTransform(pageSettings.Margins.Left, pageSettings.Margins.Top);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -664,9 +664,11 @@ internal static void GetPrintDialogInfo(string printer, ref string port, ref str
NameValueCollection options = LoadPrinterOptions(cups_dests.options, cups_dests.num_options);

if (options["printer-state"] != null)
// TODO-NULLABLE dotnet/roslyn#34644
state = int.Parse(options["printer-state"]!);

if (options["printer-comment"] != null)
// TODO-NULLABLE dotnet/roslyn#34644
comment = options["printer-state"]!;

switch (state)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public bool Equals(Region region, Graphics g)

public bool IsVisible(PointF point) => IsVisible(point, null);

public bool IsVisible(float x, float y, Graphics g) => IsVisible(new PointF(x, y), g);
public bool IsVisible(float x, float y, Graphics? g) => IsVisible(new PointF(x, y), g);

public bool IsVisible(PointF point, Graphics? g)
{
Expand All @@ -363,7 +363,7 @@ public bool IsVisible(PointF point, Graphics? g)

public bool IsVisible(RectangleF rect) => IsVisible(rect, null);

public bool IsVisible(float x, float y, float width, float height, Graphics g) => IsVisible(new RectangleF(x, y, width, height), g);
public bool IsVisible(float x, float y, float width, float height, Graphics? g) => IsVisible(new RectangleF(x, y, width, height), g);

public bool IsVisible(RectangleF rect, Graphics? g)
{
Expand All @@ -376,7 +376,7 @@ public bool IsVisible(RectangleF rect, Graphics? g)
return isVisible != 0;
}

public bool IsVisible(int x, int y, Graphics g) => IsVisible(new Point(x, y), g);
public bool IsVisible(int x, int y, Graphics? g) => IsVisible(new Point(x, y), g);

public bool IsVisible(Point point) => IsVisible(point, null);

Expand All @@ -395,7 +395,7 @@ public bool IsVisible(Point point, Graphics? g)

public bool IsVisible(Rectangle rect) => IsVisible(rect, null);

public bool IsVisible(int x, int y, int width, int height, Graphics g) => IsVisible(new Rectangle(x, y, width, height), g);
public bool IsVisible(int x, int y, int width, int height, Graphics? g) => IsVisible(new Rectangle(x, y, width, height), g);

public bool IsVisible(Rectangle rect, Graphics? g)
{
Expand Down

0 comments on commit fe36f59

Please sign in to comment.