Permalink
Browse files

Some other touchups

  • Loading branch information...
1 parent c81873f commit 187787c083c2fa27ad174fde961da63750cd4f08 @migueldeicaza migueldeicaza committed May 18, 2017
View
@@ -96,7 +96,7 @@ public Bitmap (string filename, bool useIcm)
}
}
- public Bitmap(string filename) : this(filename, false) { }
+ public Bitmap(string filename) : this(filename, false) { }
public Bitmap(Stream stream) : this(stream, false) { }
@@ -131,9 +131,9 @@ public Bitmap (Stream stream, bool useIcm)
/// <summary>
/// Initializes a new instance of the <see cref="System.Drawing.Bitmap"/> class from the specified existing image..
/// </summary>
- /// <param name="image">Image.</param>
- public Bitmap (Image image) :
- this (image, image.Width, image.Height)
+ /// <param name="original">Image.</param>
+ public Bitmap (Image original) :
+ this (original, original.Width, original.Height)
{
}
@@ -154,9 +154,9 @@ public Bitmap (Stream stream, bool useIcm)
}
}
- public Bitmap(int width, int height, PixelFormat format) : this(width, height, format, IntPtr.Zero)
- {
- }
+ public Bitmap(int width, int height, PixelFormat format) : this(width, height, format, IntPtr.Zero)
+ {
+ }
public Bitmap (int width, int height, PixelFormat format, IntPtr scan0)
{
@@ -207,28 +207,26 @@ public Bitmap (int width, int height, PixelFormat format, IntPtr scan0)
bytesPerRow = width * bitsPerPixel/bitsPerComponent;
int size = bytesPerRow * height;
- bitmapBlock = Marshal.AllocHGlobal(size);
- if (scan0 != IntPtr.Zero)
- {
- unsafe
- {
- Buffer.MemoryCopy((void*)scan0, (void*)bitmapBlock, size, size);
- }
- }
-
- var bitmap = new CGBitmapContext (bitmapBlock,
- width, height,
- bitsPerComponent,
- bytesPerRow,
- colorSpace,
- bitmapInfo);
+ bitmapBlock = Marshal.AllocHGlobal (size);
+ if (scan0 != IntPtr.Zero) {
+ unsafe
+ {
+ Buffer.MemoryCopy ((void*)scan0, (void*)bitmapBlock, size, size);
+ }
+ }
- if (scan0 == IntPtr.Zero)
- {
- // This works for now but we need to look into initializing the memory area itself
- // TODO: Look at what we should do if the image does not have alpha channel
- bitmap.ClearRect(new CGRect(0, 0, width, height));
- }
+ var bitmap = new CGBitmapContext (bitmapBlock,
+ width, height,
+ bitsPerComponent,
+ bytesPerRow,
+ colorSpace,
+ bitmapInfo);
+
+ if (scan0 == IntPtr.Zero) {
+ // This works for now but we need to look into initializing the memory area itself
+ // TODO: Look at what we should do if the image does not have alpha channel
+ bitmap.ClearRect (new CGRect (0, 0, width, height));
+ }
var provider = new CGDataProvider (bitmapBlock, size, true);
NativeCGImage = new CGImage (width, height, bitsPerComponent, bitsPerPixel, bytesPerRow, colorSpace, bitmapInfo, provider, null, false, CGColorRenderingIntent.Default);
@@ -874,16 +872,16 @@ private void flipImageYAxis (int width, int height, int size)
/// Creates a copy of the section of this Bitmap defined by Rectangle structure and with a specified PixelFormat enumeration.
/// </summary>
/// <param name="rect">Rect.</param>
- /// <param name="pixelFormat">Pixel format.</param>
- public Bitmap Clone (Rectangle rect, PixelFormat pixelFormat)
+ /// <param name="format">Pixel format.</param>
+ public Bitmap Clone (Rectangle rect, PixelFormat format)
{
if (rect.Width == 0 || rect.Height == 0)
throw new ArgumentException ("Width or Height of rect is 0.");
var width = rect.Width;
var height = rect.Height;
- var tmpImg = new Bitmap (width, height, pixelFormat);
+ var tmpImg = new Bitmap (width, height, format);
using (Graphics g = Graphics.FromImage (tmpImg)) {
g.DrawImage (this, new Rectangle(0,0, width, height), rect, GraphicsUnit.Pixel );
@@ -1149,7 +1147,7 @@ public void Save (string filename, ImageFormat format)
}
- public void Save (string filename)
+ public void Save (string filename)
{
if (filename == null)
throw new ArgumentNullException ("path");
@@ -1218,7 +1216,7 @@ public void Save (Stream stream, ImageFormat format)
}
}
- public BitmapData LockBits (RectangleF rect, ImageLockMode flags, PixelFormat format)
+ public BitmapData LockBits (RectangleF rect, ImageLockMode flags, PixelFormat format)
{
BitmapData bitmapData = new BitmapData ();
@@ -1293,7 +1291,7 @@ static unsafe void RectangularCopy( byte* dstScanLine, byte* srcScanLine, int ds
ImageLockMode bitsLockMode = 0;
- public void UnlockBits (BitmapData data)
+ public void UnlockBits (BitmapData bitmapdata)
{
if (bitsLockMode == ImageLockMode.ReadOnly)
@@ -1304,21 +1302,21 @@ public void UnlockBits (BitmapData data)
}
//int destStride = data.Width * (NativeCGImage.BitsPerPixel / NativeCGImage.BitsPerComponent);
- int destStride = data.Stride;
+ int destStride = bitmapdata.Stride;
// Declare our size
var scanLength = destStride * Height;
// This is fine here for now until we support other formats but right now it is RGBA
- var pixelSize = GetPixelFormatComponents (data.PixelFormat);
+ var pixelSize = GetPixelFormatComponents (bitmapdata.PixelFormat);
if (pixelSize == 4)
- Convert_BGRA_8888_To_P_RGBA_8888 (data.Scan0, bitmapBlock, scanLength);
+ Convert_BGRA_8888_To_P_RGBA_8888 (bitmapdata.Scan0, bitmapBlock, scanLength);
else
- Convert_BGR_888_To_P_RGBA_8888 (data.Scan0, bitmapBlock, scanLength);
+ Convert_BGR_888_To_P_RGBA_8888 (bitmapdata.Scan0, bitmapBlock, scanLength);
// Create a bitmap context from the pixel data
- var bitmapContext = CreateCompatibleBitmapContext (data.Width, data.Height, data.PixelFormat, bitmapBlock);
+ var bitmapContext = CreateCompatibleBitmapContext (bitmapdata.Width, bitmapdata.Height, bitmapdata.PixelFormat, bitmapBlock);
// Dispose of the prevous image that is allocated.
NativeCGImage.Dispose ();
View
@@ -77,20 +77,30 @@ public Font (string familyName, float emSize, FontStyle style, GraphicsUnit unit
{
}
- public Font (FontFamily familyName, float emSize, FontStyle style,
+ public Font (FontFamily family, float emSize, FontStyle style,
GraphicsUnit unit, byte gdiCharSet, bool gdiVerticalFont )
{
if (emSize <= 0)
throw new ArgumentException("emSize is less than or equal to 0, evaluates to infinity, or is not a valid number.","emSize");
- fontFamily = familyName;
+ fontFamily = family;
fontStyle = style;
this.gdiVerticalFont = gdiVerticalFont;
this.gdiCharSet = gdiCharSet;
- CreateNativeFont (familyName, emSize, style, unit, gdiCharSet, gdiVerticalFont);
+ CreateNativeFont (family, emSize, style, unit, gdiCharSet, gdiVerticalFont);
+ }
+
+ public Font(Font prototype, FontStyle style)
+ {
+ // no null checks, MS throws a NullReferenceException if original is null
+ fontFamily = prototype.FontFamily;
+ fontStyle = style;
+ gdiVerticalFont = prototype.gdiVerticalFont;
+ gdiCharSet = prototype.gdiCharSet;
+ CreateNativeFont(fontFamily, sizeInPoints, style, Unit, gdiCharSet, gdiVerticalFont);
}
#region ISerializable implementation
@@ -84,6 +84,11 @@ public string Name
get { return familyName; }
}
+ public string GetName(int language)
+ {
+ return Name;
+ }
+
public bool IsStyleAvailable (FontStyle fontStyle)
{
return NativeStyleAvailable (fontStyle);
@@ -135,7 +135,7 @@ public void DrawString (string s, Font font, Brush brush, PointF point, StringFo
DrawString(s, font, brush, new RectangleF(point.X, point.Y, 0, 0), format);
}
- 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);
}
@@ -145,15 +145,15 @@ public void DrawString (string s, Font font, Brush brush, float x, float y, Stri
DrawString (s, font, brush, new RectangleF(x, y, 0, 0), format);
}
- 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), format, null);
+ DrawString(s, font, brush, new RectangleF(x, y, 0, 0));
}
- 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)
+ {
+ DrawString (s, font, brush, layoutRectangle, null);
+ }
public void DrawString (string s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format)
{
@@ -628,7 +628,7 @@ public void FillEllipse (Brush brush, int x1, int y1, int x2, int y2)
{
FillEllipse (brush, new RectangleF (x1, y1, x2, y2));
}
-
+
public void FillEllipse (Brush brush, float x1, float y1, float x2, float y2)
{
FillEllipse (brush, new RectangleF (x1, y1, x2, y2));
@@ -1721,10 +1721,10 @@ public void FillPolygon (Brush brush, PointF [] points)
if (brush == null)
throw new ArgumentNullException (nameof(brush));
if (points == null)
- throw new ArgumentNullException (nameof (points);
+ throw new ArgumentNullException (nameof (points));
PolygonSetup (points);
- FillBrush (brush, fillMode);
+ FillBrush (brush, FillMode.Alternate);
}
public void FillPolygon(Brush brush, PointF[] points, FillMode fillMode)
View
@@ -657,6 +657,16 @@ public bool IsVisible(Rectangle rectangle)
return IsVisible ((RectangleF)rectangle);
}
+ public bool IsVisible(int x, int y, int width, int height)
+ {
+ return IsVisible(new RectangleF(x, y, width, height));
+ }
+
+ public bool IsVisible(float x, float y, float width, float height)
+ {
+ return IsVisible(new RectangleF(x, y, width, height));
+ }
+
public bool IsVisible(RectangleF rectangle)
{
// eoFill - A Boolean value that, if true, specifies to use the even-odd fill rule to evaluate
@@ -35,4 +35,31 @@ Global
{D08BBD20-EF4A-4921-9F24-29E56F7A6628}.Release|iPhoneSimulator.ActiveCfg = Release|Any CPU
{D08BBD20-EF4A-4921-9F24-29E56F7A6628}.Release|iPhoneSimulator.Build.0 = Release|Any CPU
EndGlobalSection
+ GlobalSection(MonoDevelopProperties) = preSolution
+ Policies = $0
+ $0.TextStylePolicy = $1
+ $1.FileWidth = 80
+ $1.TabWidth = 8
+ $1.IndentWidth = 8
+ $1.scope = text/x-csharp
+ $0.CSharpFormattingPolicy = $2
+ $2.IndentSwitchSection = False
+ $2.NewLinesForBracesInProperties = False
+ $2.NewLinesForBracesInAccessors = False
+ $2.NewLinesForBracesInAnonymousMethods = False
+ $2.NewLinesForBracesInControlBlocks = False
+ $2.NewLinesForBracesInAnonymousTypes = False
+ $2.NewLinesForBracesInObjectCollectionArrayInitializers = False
+ $2.NewLinesForBracesInLambdaExpressionBody = False
+ $2.NewLineForElse = False
+ $2.NewLineForCatch = False
+ $2.NewLineForFinally = False
+ $2.NewLineForMembersInObjectInit = False
+ $2.NewLineForMembersInAnonymousTypes = False
+ $2.NewLineForClausesInQuery = False
+ $2.SpacingAfterMethodDeclarationName = True
+ $2.SpaceAfterMethodCallName = True
+ $2.SpaceBeforeOpenSquareBracket = True
+ $2.scope = text/x-csharp
+ EndGlobalSection
EndGlobal

0 comments on commit 187787c

Please sign in to comment.