Support specifying a font name for external font source generation#24
Conversation
| <ItemGroup> | ||
| <None Update="ANSI Shadow.flf"> | ||
| <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> | ||
| <DependentUpon>FiggleSourceGeneratorTests_ExternalFonts.cs</DependentUpon> |
| namespace Figgle.Generator.Tests; | ||
|
|
||
| public class FiggleSourceGeneratorTests | ||
| public partial class FiggleSourceGeneratorTests |
There was a problem hiding this comment.
NOTE: The code for testing external fonts was getting a bit much and was cluttering the original test file.
To improve code organization I split the external font tests and support code to another file. Using partial here allows the new test file to still access the private helpers like ValidateOutput.
drewnoakes
left a comment
There was a problem hiding this comment.
Really nice work on this one. Thanks very much 👍
|
|
||
| namespace Figgle.Generator.AcceptanceTests; | ||
|
|
||
| [GenerateFiggleText("HelloWorld", "My External Font", "Hello World!")] |
There was a problem hiding this comment.
A possible extension to this would be to generate const strings for any external font names, so that if the file is removed or the build item removed, then the code wouldn't compile. Some open questions (like how to create a valid C# member name from an arbitrary file name) but thought I'd throw it out there. This PR is great as is.

The source generator can now use external fonts when the consuming project includes the font file as an additional file:
However, if there are font files with the same file name but under different folders, the source generator will not be able to distinguish which font file to use and will use the first one found.
To make it easier for users to explicitly specify a font name for the source generator to identify, we can define a new item metadata
FontNamefor additional files:The user can then specify
MyExternalFontas the font name in theGenerateFiggleTextattribute:Implementation
Figgle.Generator.propsand add aCompilerVisibleItemMetadataforFontNameunderAdditionalFiles.Figgle.Generator.csprojto packFiggle.Generator.propsinto the nuget package under thebuildfolder.buildfolder when referencing the nuget package.FontNamemetadata and prioritize it to match the specified font name fromGenerateFiggleText.FontNamemetadata is not set, fall back to the original behavior of using the font's filename to match.Testing
FontNamemetadata and prioritizing it over the font's filename.Figgle.Generator.AcceptanceTeststo simulate consuming the source generator nuget package by referencing the generator project as a source generator and importingFiggle.Generator.propsmanually.Figgle.Generator.AcceptanceTeststhat verifies the source-generated string using the external font with an explicitFontNamemetadata matches the expected value.