Mirror of
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix fonts

+14 -15
+5
.changeset/seven-glasses-grow.md
··· 1 + --- 2 + "release-image-generator": patch 3 + --- 4 + 5 + Fix fonts. Reason not working: Git + Windows did not track file rename to lowercase, so ttf files could not be found.
+2 -4
app/ReleaseImageGenerator.API/Program.cs
··· 19 19 app.UseHttpsRedirection(); 20 20 21 21 app.MapGet("/", 22 - (HttpContext context, string? text, int? width, int? height, SupportedFontFamily? fontFamily, SupportedFontWeight? fontWeight) => 22 + (string? text, int? width, int? height, SupportedFontFamily? fontFamily, SupportedFontWeight? fontWeight) => 23 23 { 24 24 var options = new ImageGeneratorOptions(text, width ?? 1920, height ?? 1080, 25 25 fontFamily ?? SupportedFontFamily.readexpro, fontWeight ?? SupportedFontWeight.bold); 26 26 var imageGenerator = new ImageGenerator(options); 27 - var result = imageGenerator.GenerateImage(); 28 - result.Item2.ForEach(s => context.Response.Headers.Append("X-Debug-Log", s)); 29 - return Results.File(result.Item1.ToArray(), "image/png"); 27 + return Results.File(imageGenerator.GenerateImage().ToArray(), "image/png"); 30 28 }) 31 29 .WithName("ImageGenerator") 32 30 .WithOpenApi();
+3 -4
app/ReleaseImageGenerator.Domain/Implementations/ImageGenerator.cs
··· 21 21 FontWeight = options.fontWeight; 22 22 } 23 23 24 - public Tuple<MemoryStream, List<string>> GenerateImage() 24 + public MemoryStream GenerateImage() 25 25 { 26 - List<string> logger = new List<string>(); 27 26 using var surface = SKSurface.Create(new SKImageInfo(Width, Height)); 28 27 var canvas = surface.Canvas; 29 28 var random = new Random(); ··· 33 32 BackgroundGenerator.GenerateBackground(canvas, Width, Height, random, primaryColor); 34 33 PatternGenerator.GeneratePattern(canvas, Width, Height, random, primaryColor); 35 34 NoiseGenerator.GenerateNoise(canvas, Width, Height, random); 36 - if (Text != null) TextGenerator.GenerateText(canvas, Text, Width, Height, FontFamily, FontWeight, primaryColor, logger); 35 + if (Text != null) TextGenerator.GenerateText(canvas, Text, Width, Height, FontFamily, FontWeight, primaryColor); 37 36 38 37 // Return as PNG 39 38 var stream = new MemoryStream(); 40 39 using var image = surface.Snapshot(); 41 40 using var data = image.Encode(SKEncodedImageFormat.Png, 100); 42 41 data.SaveTo(stream); 43 - return new Tuple<MemoryStream, List<string>>(stream, logger); 42 + return stream; 44 43 } 45 44 }
+1 -1
app/ReleaseImageGenerator.Domain/Interfaces/IImageGenerator.cs
··· 4 4 5 5 public interface IImageGenerator 6 6 { 7 - Tuple<MemoryStream, List<string>> GenerateImage(); 7 + MemoryStream GenerateImage(); 8 8 }
+3 -6
app/ReleaseImageGenerator.Domain/TextGenerator.cs
··· 9 9 public static class TextGenerator 10 10 { 11 11 public static void GenerateText(SKCanvas canvas, string text, int width, int height, SupportedFontFamily fontFamily, 12 - SupportedFontWeight fontWeight, Unicolour primaryColor, List<string> logger) 12 + SupportedFontWeight fontWeight, Unicolour primaryColor) 13 13 { 14 - var typeface = LoadFont(fontFamily.ToString(), fontWeight.ToString(), logger); 15 - logger.Add("Family Name: " + typeface.FamilyName); 14 + var typeface = LoadFont(fontFamily.ToString(), fontWeight.ToString()); 16 15 var fontsize = GetMaxFontSize(width - width / 3, typeface, text, 1f, width > height ? height / 3 : width / 3); 17 - logger.Add("Font size: " + fontsize); 18 16 19 17 // Calculate text size and position 20 18 var textPaint = new SKPaint ··· 93 91 canvas.DrawText(text, textX, textY, textPaint); 94 92 } 95 93 96 - private static SKTypeface LoadFont(string fontFamily, string fontWeight, List<string> logger) 94 + private static SKTypeface LoadFont(string fontFamily, string fontWeight) 97 95 { 98 96 var fontName = $"{fontFamily}-{fontWeight}.ttf"; 99 - logger.Add("File name: " + fontName); 100 97 101 98 return SKTypeface.FromFile($"./fonts/{fontFamily}-{fontWeight}.ttf") ?? 102 99 SKTypeface.FromFile($"./fonts/readexpro-bold.ttf") ?? SKTypeface.Default;