Files
jadb/lib/_data_ingestion/kanjivg/objects.dart
T
oysteikt 80d19543fb
Build and test / build (push) Successful in 5m28s
WIP: add kanjivg data
2026-06-08 16:22:19 +09:00

169 lines
3.9 KiB
Dart

import 'package:jadb/_data_ingestion/sql_writable.dart';
/// Enum set in the kvg:position attribute, used by `<g>` elements in the KanjiVG SVG files.
enum KanjiPathGroupPosition {
upperA,
upperB,
lower1,
lower2,
bottom,
kamae,
kamaec,
left,
middle,
nyo,
nyoc,
right,
tare,
tarec,
top;
static KanjiPathGroupPosition? fromString(String? str) {
if (str == null) return null;
switch (str) {
case '⿵A':
return KanjiPathGroupPosition.upperA;
case '⿵B':
return KanjiPathGroupPosition.upperB;
case '⿶1':
return KanjiPathGroupPosition.lower1;
case '⿶2':
return KanjiPathGroupPosition.lower2;
case 'bottom':
return KanjiPathGroupPosition.bottom;
case 'kamae':
return KanjiPathGroupPosition.kamae;
case 'kamaec':
return KanjiPathGroupPosition.kamaec;
case 'left':
return KanjiPathGroupPosition.left;
case 'middle':
return KanjiPathGroupPosition.middle;
case 'nyo':
return KanjiPathGroupPosition.nyo;
case 'nyoc':
return KanjiPathGroupPosition.nyoc;
case 'right':
return KanjiPathGroupPosition.right;
case 'tare':
return KanjiPathGroupPosition.tare;
case 'tarec':
return KanjiPathGroupPosition.tarec;
case 'top':
return KanjiPathGroupPosition.top;
default:
throw ArgumentError('Unknown position: $str');
}
}
}
enum KanjiVGRadical {
general,
jis,
nelson,
tradit;
static KanjiVGRadical? fromString(String? str) {
if (str == null) return null;
switch (str) {
case 'general':
return KanjiVGRadical.general;
case 'jis':
return KanjiVGRadical.jis;
case 'nelson':
return KanjiVGRadical.nelson;
case 'tradit':
return KanjiVGRadical.tradit;
default:
throw ArgumentError('Unknown radical: $str');
}
}
}
/// Contents of a \<g> element in the KanjiVG SVG files.
class KanjiPathGroupTreeNode extends SQLWritable {
final int id;
final List<KanjiPathGroupTreeNode> children;
final String? element;
final String? original;
final KanjiPathGroupPosition? position;
final KanjiVGRadical? radical;
final int? part;
// Currently unused data.
final bool radicalForm;
final bool tradForm;
final bool partial;
final String? variant;
KanjiPathGroupTreeNode({
required this.id,
this.children = const [],
this.element,
this.original,
this.position,
this.radical,
this.part,
this.variant,
this.radicalForm = false,
this.tradForm = false,
this.partial = false,
});
@override
Map<String, Object?> get sqlValue => {
'groupId': id,
'element': element,
'original': original,
'position': position?.name,
'radical': radical?.name,
'part': part,
};
}
/// Contents of a `<text>` element in the StrokeNumber's group in the KanjiVG SVG files
class KanjiStrokeNumber extends SQLWritable {
final int num;
final double x;
final double y;
KanjiStrokeNumber(this.num, this.x, this.y);
@override
Map<String, Object?> get sqlValue => {'strokeNum': num, 'x': x, 'y': y};
}
/// Contents of a `<path>` element in the KanjiVG SVG files
class KanjiVGPath extends SQLWritable {
final int id;
final String? type;
final String svgPath;
KanjiVGPath({required this.id, required this.type, required this.svgPath});
@override
Map<String, Object?> get sqlValue => {
'pathId': id,
'type': type,
'svgPath': svgPath,
};
}
class KanjiVGItem extends SQLWritable {
final String character;
final List<KanjiVGPath> paths;
final List<KanjiStrokeNumber> strokeNumbers;
final List<KanjiPathGroupTreeNode> pathGroups;
KanjiVGItem({
required this.character,
required this.paths,
required this.strokeNumbers,
required this.pathGroups,
});
@override
Map<String, Object?> get sqlValue => {'character': character};
}