mirror of
https://github.com/vodemn/m3_lightmeter.git
synced 2024-11-21 23:10:40 +00:00
add text to screenshots (wip)
This commit is contained in:
parent
7dc155080b
commit
e91da61238
4 changed files with 45 additions and 0 deletions
BIN
screenshots/assets/fonts/SF-Pro-Display-Bold.zip
Normal file
BIN
screenshots/assets/fonts/SF-Pro-Display-Bold.zip
Normal file
Binary file not shown.
BIN
screenshots/assets/fonts/SF-Pro-Display-Regular.zip
Normal file
BIN
screenshots/assets/fonts/SF-Pro-Display-Regular.zip
Normal file
Binary file not shown.
|
@ -16,17 +16,25 @@ enum ScreenshotLayout {
|
|||
iphone65inch(
|
||||
size: (width: 1242, height: 2688),
|
||||
contentPadding: (left: 150, top: 192, right: 150, bottom: 192),
|
||||
titleFontPath: 'screenshots/assets/fonts/SF-Pro-Display-Bold.zip',
|
||||
subtitleFontPath: 'screenshots/assets/fonts/SF-Pro-Display-Regular.zip',
|
||||
),
|
||||
iphone55inch(
|
||||
size: (width: 1242, height: 2208),
|
||||
contentPadding: (left: 150, top: 192, right: 150, bottom: 192),
|
||||
titleFontPath: 'screenshots/assets/fonts/SF-Pro-Display-Bold.zip',
|
||||
subtitleFontPath: 'screenshots/assets/fonts/SF-Pro-Display-Regular.zip',
|
||||
);
|
||||
|
||||
final ({int height, int width}) size;
|
||||
final ({int left, int top, int right, int bottom}) contentPadding;
|
||||
final String titleFontPath;
|
||||
final String subtitleFontPath;
|
||||
|
||||
const ScreenshotLayout({
|
||||
required this.size,
|
||||
required this.contentPadding,
|
||||
required this.titleFontPath,
|
||||
required this.subtitleFontPath,
|
||||
});
|
||||
}
|
||||
|
|
|
@ -102,4 +102,41 @@ extension ScreenshotImage on Image {
|
|||
backgroundColor: getPixel(0, 0),
|
||||
);
|
||||
}
|
||||
|
||||
Image addText(ScreenshotLayout layout, String title, String subtitle) {
|
||||
final titleFont = BitmapFont.fromZip(File(layout.titleFontPath).readAsBytesSync());
|
||||
final subtitleFont = BitmapFont.fromZip(File(layout.subtitleFontPath).readAsBytesSync());
|
||||
final textImage = fill(
|
||||
Image(
|
||||
height: titleFont.lineHeight + 36 + subtitleFont.lineHeight * 2,
|
||||
width: layout.size.width - (layout.contentPadding.left + layout.contentPadding.right),
|
||||
),
|
||||
color: getPixel(0, 0),
|
||||
);
|
||||
|
||||
drawString(
|
||||
textImage,
|
||||
title,
|
||||
font: titleFont,
|
||||
y: 0,
|
||||
);
|
||||
|
||||
int subtitleDy = titleFont.lineHeight + 36;
|
||||
subtitle.split('\n').forEach((line) {
|
||||
drawString(
|
||||
textImage,
|
||||
line,
|
||||
font: subtitleFont,
|
||||
y: subtitleDy,
|
||||
);
|
||||
subtitleDy += subtitleFont.lineHeight;
|
||||
});
|
||||
|
||||
return compositeImage(
|
||||
this,
|
||||
textImage,
|
||||
dstX: layout.contentPadding.left,
|
||||
dstY: layout.contentPadding.top,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue