Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

#nullable enable

using System.Collections.Generic;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Text;
using static Interop;

namespace System.Windows.Forms.Metafiles
Expand Down Expand Up @@ -167,29 +167,29 @@ bool stateTracker(ref EmfRecord record)
}
}

public List<string> RecordsToString()
public string RecordsToString()
{
var strings = new List<string>();
StringBuilder sb = new StringBuilder(1024);
Enumerate((ref EmfRecord record) =>
{
strings.Add(record.ToString());
sb.AppendLine(record.ToString());
return true;
});

return strings;
return sb.ToString();
}

public List<string> RecordsToStringWithState(DeviceContextState state)
public string RecordsToStringWithState(DeviceContextState state)
{
var strings = new List<string>();
StringBuilder sb = new StringBuilder(1024);
EnumerateWithState((ref EmfRecord record, DeviceContextState state) =>
{
strings.Add(record.ToString(state));
sb.AppendLine(record.ToString(state));
return true;
},
state);

return strings;
return sb.ToString();
}

private static unsafe BOOL CallBack(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#nullable enable

using Xunit;

namespace System.Windows.Forms.Metafiles
{
internal class FontFaceNameValidator : IStateValidator
{
private readonly string _fontFaceName;

/// <param name="fontFaceName">The font face name to validate.</param>
public FontFaceNameValidator(string fontFaceName) => _fontFaceName = fontFaceName;

public void Validate(DeviceContextState state) => Assert.Equal(_fontFaceName, state.SelectedFont.FaceName.ToString());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,18 @@ namespace System.Windows.Forms.Metafiles
{
internal static class State
{
internal static IStateValidator TextColor(Color textColor) => new TextColorValidator(textColor);
internal static IStateValidator Brush(Color brushColor, Gdi32.BS brushStyle)
=> new BrushValidator(brushColor, brushStyle);
internal static IStateValidator BrushColor(Color brushColor) => new BrushColorValidator(brushColor);
internal static IStateValidator BrushStyle(Gdi32.BS brushStyle) => new BrushStyleValidator(brushStyle);
internal static IStateValidator FontFace(string fontFaceName) => new FontFaceNameValidator(fontFaceName);
internal static IStateValidator Pen(int penWidth, Color penColor, Gdi32.PS penStyle)
=> new PenValidator(penWidth, penColor, penStyle);
internal static IStateValidator PenColor(Color penColor) => new PenColorValidator(penColor);
internal static IStateValidator PenStyle(Gdi32.PS penStyle) => new PenStyleValidator(penStyle);
internal static IStateValidator PenWidth(int penWidth) => new PenWidthValidator(penWidth);
internal static IStateValidator Brush(Color brushColor, Gdi32.BS brushStyle)
=> new BrushValidator(brushColor, brushStyle);
internal static IStateValidator BrushColor(Color brushColor) => new BrushColorValidator(brushColor);
internal static IStateValidator BrushStyle(Gdi32.BS brushStyle) => new BrushStyleValidator(brushStyle);
internal static IStateValidator Rop2(Gdi32.R2 rop2Mode) => new Rop2Validator(rop2Mode);
internal static IStateValidator TextColor(Color textColor) => new TextColorValidator(textColor);
internal static IStateValidator Transform(Matrix3x2 transform) => new TransformValidator(transform);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,17 @@ namespace System.Windows.Forms.Metafiles
internal sealed class TextOutValidator : StateValidator
{
private readonly string? _text;
private readonly string? _fontFace;
private readonly Rectangle? _bounds;

/// <param name="text">Optional text to validate.</param>
/// <param name="bounds">Optional bounds to validate.</param>
/// <param name="fontFace">Optional font face name to validate.</param>
/// <param name="stateValidators">Optional device context state validation to perform.</param>
public TextOutValidator(
string? text,
Rectangle? bounds = default,
string? fontFace = default,
params IStateValidator[] stateValidators) : base(stateValidators)
{
_text = text;
_fontFace = fontFace;
_bounds = bounds;
}

Expand All @@ -51,11 +47,6 @@ public override unsafe void Validate(ref EmfRecord record, DeviceContextState st
{
Assert.Equal(_bounds.Value, (Rectangle)textOut->rclBounds);
}

if (_fontFace != null)
{
Assert.Equal(_fontFace, state.SelectedFont.FaceName.ToString());
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,13 @@ internal static IEmfValidator Polyline16(

/// <param name="text">Optional text to validate.</param>
/// <param name="bounds">Optional bounds to validate.</param>
/// <param name="fontFace">Optional font face name to validate.</param>
/// <param name="stateValidators">Optional device context state validation to perform.</param>
internal static IEmfValidator TextOut(
string? text = default,
Rectangle? bounds = default,
string? fontFace = default,
params IStateValidator[] stateValidators) => new TextOutValidator(
text,
bounds,
fontFace,
stateValidators);

/// <param name="from">Optional source point to validate.</param>
Expand Down
12 changes: 12 additions & 0 deletions src/System.Windows.Forms/src/System/Windows/Forms/DataGridView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1612,6 +1612,10 @@ public DataGridViewCellStyle ColumnHeadersDefaultCellStyle
{
_columnHeadersDefaultCellStyle.AddScope(this, DataGridViewCellStyleScopes.ColumnHeaders);
}

// Update ambient font flag depending on cell style font
_dataGridViewState1[State1_AmbientColumnHeadersFont] = value?.Font == base.Font;

DataGridViewCellStyleDifferences dgvcsc = cs.GetDifferencesFrom(ColumnHeadersDefaultCellStyle);
if (dgvcsc != DataGridViewCellStyleDifferences.None)
{
Expand Down Expand Up @@ -2128,6 +2132,10 @@ _defaultCellStyle.Font is null ||
{
_defaultCellStyle.AddScope(this, DataGridViewCellStyleScopes.DataGridView);
}

// Update ambient font flag depending on cell style font
_dataGridViewState1[State1_AmbientFont] = value?.Font == base.Font;

DataGridViewCellStyleDifferences dgvcsc = cs.GetDifferencesFrom(DefaultCellStyle);
if (dgvcsc != DataGridViewCellStyleDifferences.None)
{
Expand Down Expand Up @@ -3577,6 +3585,10 @@ public DataGridViewCellStyle RowHeadersDefaultCellStyle
{
_rowHeadersDefaultCellStyle.AddScope(this, DataGridViewCellStyleScopes.RowHeaders);
}

// Update ambient font flag depending on cell style font
_dataGridViewState1[State1_AmbientRowHeadersFont] = value?.Font == base.Font;

DataGridViewCellStyleDifferences dgvcsc = cs.GetDifferencesFrom(RowHeadersDefaultCellStyle);
if (dgvcsc != DataGridViewCellStyleDifferences.None)
{
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading