-
Notifications
You must be signed in to change notification settings - Fork 989
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[API Proposal]: Trim friendly Font ToLogFont/FromLogFont #8846
Comments
Tagging subscribers to this area: @dotnet/area-system-drawing Issue DetailsBackground and motivationRight now WinForm use API Proposalnamespace System.Drawing;
public sealed partial class Font
{
public void ToLogFont<T>(ref T logFont, Graphics graphics) where T: struct, unmanaged { throw null; }
public static Font FromLogFont<T>(in T logFont) where T: struct, unmanaged { throw null; }
public static Font FromLogFont<T>(in T logFont, IntPtr hdc) where T: struct, unmanaged { throw null; }
public void ToLogFont<T>(ref T logFont) where T: struct, unmanaged { throw null; }
} API Usage[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public unsafe struct MyLOGFONT
{
public int lfHeight;
public int lfWidth;
public int lfEscapement;
public int lfOrientation;
public int lfWeight;
public byte lfItalic;
public byte lfUnderline;
public byte lfStrikeOut;
public byte lfCharSet;
public byte lfOutPrecision;
public byte lfClipPrecision;
public byte lfQuality;
public byte lfPitchAndFamily;
private fixed char _lfFaceName[LF_FACESIZE];
}
// And similar
var f = new Font();
MyLOGFONT interopStruct = default;
f.ToLogFont(ref interopStruct); Alternative DesignsAsk users of this API, reimplement it itself within their application and make that code trim-friendly. RisksNo response
|
@JeremyKuhne @RussKie, given that there's already a PR up for the implementation, should this get reviewed in one of the api design review meetings? Would anyone of you want to be the champion for it? |
@ViktorHofer sure, mark it and I'll represent. |
I'll watch the recording |
Great, thank you. Sent out a mail. |
How urgent is this? |
@kant2002 can you answer @terrajobst's question regarding the priority of getting this into main? |
Personally I would like to have this in .Net 7, that increases chances that I annotate core WinForms libraries for trimming. |
namespace System.Drawing
{
public sealed partial class Font
{
public void ToLogFont(out Interop.LOGFONT logFont, Graphics graphics) { throw null; }
public static Font FromLogFont(in Interop.LOGFONT logFont) { throw null; }
public static Font FromLogFont(in Interop.LOGFONT logFont, IntPtr hdc) { throw null; }
public void ToLogFont(out Interop.LOGFONT logFont) { throw null; }
}
}
namespace System.Drawing.Interop
{
public unsafe struct LOGFONT
{
public int lfHeight;
public int lfWidth;
public int lfEscapement;
public int lfOrientation;
public int lfWeight;
public byte lfItalic;
public byte lfUnderline;
public byte lfStrikeOut;
public byte lfCharSet;
public byte lfOutPrecision;
public byte lfClipPrecision;
public byte lfQuality;
public byte lfPitchAndFamily;
private fixed char _lfFaceName[LF_FACESIZE];
[UnscopedRef]
public Span<char> lfFaceName => MemoryMarshal.CreateSpan(ref _lfFaceName[0], LF_FACESIZE);
}
} |
Now the API change is approved, can we reopen dotnet/runtime#70224? |
@kant2002 feel free to re-open your PR and we can give it another glance. |
These methods used by WinForms Closes #70358
@kant2002 did you want to reroll your patch now |
I've implemented this and will be putting up a PR tomorrow. |
This adds the new typed API. The new namespace conflicts with the Interop class so I had to change a number of files to add a static using for Interop. Also changes WinForms to consume the new API. Fixes dotnet#8846
This adds the new typed API. The new namespace conflicts with the Interop class so I had to change a number of files to add a static using for Interop. Also changes WinForms to consume the new API. Fixes #8846
Background and motivation
Right now WinForm use
System.Drawing.Common.Font.ToLogFont/FromLogFont
with their own interop structures. That API produce trimming warning. This API would serve same purpose as existing API, but provide trim friendly alternative.API Proposal
API Usage
Alternative Designs
Ask users of this API, reimplement it itself within their application and make that code trim-friendly.
Risks
No response
Accompanying implementation dotnet/runtime#70224
The text was updated successfully, but these errors were encountered: