Refactors
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:pdf/pdf.dart';
|
||||
import 'package:pdf/widgets.dart';
|
||||
|
||||
class DocumentTheme {
|
||||
DocumentTheme({
|
||||
required this.primaryHex,
|
||||
required this.accentHex,
|
||||
required this.backgroundHex,
|
||||
required this.fontPath,
|
||||
required this.bulletPoint,
|
||||
});
|
||||
|
||||
factory DocumentTheme.fromToml(Map<String, dynamic> toml) => DocumentTheme(
|
||||
primaryHex: (toml['theme'] as Map)['primary_hex'] as String,
|
||||
accentHex: (toml['theme'] as Map)['accent_hex'] as String,
|
||||
backgroundHex: (toml['theme'] as Map)['background_hex'] as String,
|
||||
fontPath: (toml['theme'] as Map)['font'] as String,
|
||||
bulletPoint: (toml['theme'] as Map)['bullet_point'] as String? ?? '-',
|
||||
);
|
||||
|
||||
factory DocumentTheme.retro() => DocumentTheme(
|
||||
primaryHex: "00AA00",
|
||||
accentHex: "44EE66",
|
||||
backgroundHex: "FFFFFF",
|
||||
fontPath: "nerd.ttf",
|
||||
bulletPoint: '-',
|
||||
);
|
||||
|
||||
static const double inch = 72.0;
|
||||
static const double cm = inch / 2.54;
|
||||
static const double mm = inch / 25.4;
|
||||
|
||||
static const width = 21.0 * cm;
|
||||
static const height = 29.7 * cm;
|
||||
static const margin = 2.0 * cm;
|
||||
|
||||
final String primaryHex;
|
||||
final String accentHex;
|
||||
final String backgroundHex;
|
||||
final String fontPath;
|
||||
final String bulletPoint;
|
||||
Font? _font;
|
||||
|
||||
PdfColor get primaryColor => PdfColor.fromHex(primaryHex);
|
||||
PdfColor get accentColor => PdfColor.fromHex(accentHex);
|
||||
PdfColor get backgroundColor => PdfColor.fromHex(backgroundHex);
|
||||
|
||||
Font get font {
|
||||
_font ??= Font.ttf(File(fontPath).readAsBytesSync().buffer.asByteData());
|
||||
return _font!;
|
||||
}
|
||||
|
||||
@override
|
||||
int get hashCode {
|
||||
return Object.hashAll([primaryHex, accentHex, backgroundHex, fontPath, bulletPoint]);
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return super.hashCode == other.hashCode;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user