[API Proposal]: Trim friendly Font ToLogFont/FromLogFont
See original GitHub issueBackground 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
namespace 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 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
Issue Analytics
- State:
- Created a year ago
- Comments:13 (13 by maintainers)
Top Results From Across the Web
[API Proposal]: Trim friendly Font ToLogFont/FromLogFont
NET UI framework for building Windows desktop applications. - [API Proposal]: Trim friendly Font ToLogFont/FromLogFont · dotnet/winforms@6013922.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve implemented this and will be putting up a PR tomorrow.
Video