From c2c520044fc5d572a86422b479038e9e9e968df5 Mon Sep 17 00:00:00 2001 From: Aleksey Kulikov Date: Wed, 7 Jan 2026 16:16:00 +0300 Subject: [PATCH] refactor(otf): use enchanced enums --- lib/src/otf/cff/char_string.dart | 18 +- lib/src/otf/cff/char_string_operator.dart | 118 +++++-------- lib/src/otf/cff/char_string_optimizer.dart | 20 ++- lib/src/otf/cff/dict_operator.dart | 183 +++++++-------------- lib/src/otf/cff/operator.dart | 20 +-- lib/src/otf/table/cff1.dart | 51 ++++-- lib/src/otf/table/cff2.dart | 44 +++-- lib/src/otf/table/script_list.dart | 10 +- 8 files changed, 197 insertions(+), 267 deletions(-) diff --git a/lib/src/otf/cff/char_string.dart b/lib/src/otf/cff/char_string.dart index 52092a7..6202cc0 100644 --- a/lib/src/otf/cff/char_string.dart +++ b/lib/src/otf/cff/char_string.dart @@ -50,21 +50,21 @@ class CharStringCommand implements BinaryCodable { factory CharStringCommand.hmoveto({required int dx}) { return CharStringCommand( - operator: hmoveto, + operator: CharStringOperator.hmoveto.operator, operandList: _getOperandList(operandValues: [dx]), ); } factory CharStringCommand.vmoveto({required int dy}) { return CharStringCommand( - operator: vmoveto, + operator: CharStringOperator.vmoveto.operator, operandList: _getOperandList(operandValues: [dy]), ); } factory CharStringCommand.rmoveto({required int dx, required int dy}) { return CharStringCommand( - operator: rmoveto, + operator: CharStringOperator.rmoveto.operator, operandList: _getOperandList(operandValues: [dx, dy]), ); } @@ -81,14 +81,14 @@ class CharStringCommand implements BinaryCodable { factory CharStringCommand.hlineto({required int dx}) { return CharStringCommand( - operator: hlineto, + operator: CharStringOperator.hlineto.operator, operandList: _getOperandList(operandValues: [dx]), ); } factory CharStringCommand.vlineto({required int dy}) { return CharStringCommand( - operator: vlineto, + operator: CharStringOperator.vlineto.operator, operandList: _getOperandList(operandValues: [dy]), ); } @@ -99,7 +99,7 @@ class CharStringCommand implements BinaryCodable { } return CharStringCommand( - operator: rlineto, + operator: CharStringOperator.rlineto.operator, operandList: _getOperandList(operandValues: dlist), ); } @@ -120,7 +120,7 @@ class CharStringCommand implements BinaryCodable { } return CharStringCommand( - operator: hhcurveto, + operator: CharStringOperator.hhcurveto.operator, operandList: _getOperandList(operandValues: dlist), ); } @@ -131,7 +131,7 @@ class CharStringCommand implements BinaryCodable { } return CharStringCommand( - operator: vvcurveto, + operator: CharStringOperator.vvcurveto.operator, operandList: _getOperandList(operandValues: dlist), ); } @@ -162,7 +162,7 @@ class CharStringCommand implements BinaryCodable { } return CharStringCommand( - operator: rrcurveto, + operator: CharStringOperator.rrcurveto.operator, operandList: _getOperandList(operandValues: dlist), ); } diff --git a/lib/src/otf/cff/char_string_operator.dart b/lib/src/otf/cff/char_string_operator.dart index f233596..7b8048a 100644 --- a/lib/src/otf/cff/char_string_operator.dart +++ b/lib/src/otf/cff/char_string_operator.dart @@ -1,84 +1,44 @@ -import 'dart:collection'; - import 'package:icon_font/src/otf/cff/operator.dart'; -// CharString operators -const hstem = CFFOperator(context: CFFOperatorContext.charString, b0: 1); -const vstem = CFFOperator(context: CFFOperatorContext.charString, b0: 3); -const vmoveto = CFFOperator(context: CFFOperatorContext.charString, b0: 4); -const rlineto = CFFOperator(context: CFFOperatorContext.charString, b0: 5); -const hlineto = CFFOperator(context: CFFOperatorContext.charString, b0: 6); -const vlineto = CFFOperator(context: CFFOperatorContext.charString, b0: 7); -const rrcurveto = CFFOperator(context: CFFOperatorContext.charString, b0: 8); -const callsubr = CFFOperator(context: CFFOperatorContext.charString, b0: 10); -const escape = CFFOperator(context: CFFOperatorContext.charString, b0: 12); -const vsindex = CFFOperator(context: CFFOperatorContext.charString, b0: 15); -const blend = CFFOperator(context: CFFOperatorContext.charString, b0: 16); -const hstemhm = CFFOperator(context: CFFOperatorContext.charString, b0: 18); -const hintmask = CFFOperator(context: CFFOperatorContext.charString, b0: 19); -const cntrmask = CFFOperator(context: CFFOperatorContext.charString, b0: 20); -const rmoveto = CFFOperator(context: CFFOperatorContext.charString, b0: 21); -const hmoveto = CFFOperator(context: CFFOperatorContext.charString, b0: 22); -const vstemhm = CFFOperator(context: CFFOperatorContext.charString, b0: 23); -const rcurveline = CFFOperator(context: CFFOperatorContext.charString, b0: 24); -const rlinecurve = CFFOperator(context: CFFOperatorContext.charString, b0: 25); -const vvcurveto = CFFOperator(context: CFFOperatorContext.charString, b0: 26); -const hhcurveto = CFFOperator(context: CFFOperatorContext.charString, b0: 27); -const callgsubr = CFFOperator(context: CFFOperatorContext.charString, b0: 29); -const vhcurveto = CFFOperator(context: CFFOperatorContext.charString, b0: 30); -const hvcurveto = CFFOperator(context: CFFOperatorContext.charString, b0: 31); +enum CharStringOperator { + hstem(b0: 1), + vstem(b0: 3), + vmoveto(b0: 4), + rlineto(b0: 5), + hlineto(b0: 6), + vlineto(b0: 7), + rrcurveto(b0: 8), + callsubr(b0: 10), + escape(b0: 12), + endchar(b0: 14), + vsindex(b0: 15), + blend(b0: 16), + hstemhm(b0: 18), + hintmask(b0: 19), + cntrmask(b0: 20), + rmoveto(b0: 21), + hmoveto(b0: 22), + vstemhm(b0: 23), + rcurveline(b0: 24), + rlinecurve(b0: 25), + vvcurveto(b0: 26), + hhcurveto(b0: 27), + callgsubr(b0: 29), + vhcurveto(b0: 30), + hvcurveto(b0: 31), + hflex(b0: 12, b1: 34), + flex(b0: 12, b1: 35), + hflex1(b0: 12, b1: 36), + flex1(b0: 12, b1: 37); -const hflex = CFFOperator( - context: CFFOperatorContext.charString, - b0: 12, - b1: 34, -); -const flex = CFFOperator( - context: CFFOperatorContext.charString, - b0: 12, - b1: 35, -); -const hflex1 = CFFOperator( - context: CFFOperatorContext.charString, - b0: 12, - b1: 36, -); -const flex1 = CFFOperator( - context: CFFOperatorContext.charString, - b0: 12, - b1: 37, -); + const CharStringOperator({required int b0, int? b1}) + : _b0 = b0, + _b1 = b1, + context = CFFOperatorContext.charString; -/// CFF1 endchar -const endchar = CFFOperator(context: CFFOperatorContext.charString, b0: 14); + final int _b0; + final int? _b1; + final CFFOperatorContext context; -final Map charStringOperatorNames = UnmodifiableMapView({ - vstem: 'vstem', - vmoveto: 'vmoveto', - rlineto: 'rlineto', - hlineto: 'hlineto', - vlineto: 'vlineto', - rrcurveto: 'rrcurveto', - callsubr: 'callsubr', - escape: 'escape', - vsindex: 'vsindex', - blend: 'blend', - hstemhm: 'hstemhm', - hintmask: 'hintmask', - cntrmask: 'cntrmask', - rmoveto: 'rmoveto', - hmoveto: 'hmoveto', - vstemhm: 'vstemhm', - rcurveline: 'rcurveline', - rlinecurve: 'rlinecurve', - vvcurveto: 'vvcurveto', - hhcurveto: 'hhcurveto', - callgsubr: 'callgsubr', - vhcurveto: 'vhcurveto', - hvcurveto: 'hvcurveto', - hflex: 'hflex', - flex: 'flex', - hflex1: 'hflex1', - flex1: 'flex1', - endchar: 'endchar', -}); + CFFOperator get operator => CFFOperator(context: context, b0: _b0, b1: _b1); +} diff --git a/lib/src/otf/cff/char_string_optimizer.dart b/lib/src/otf/cff/char_string_optimizer.dart index 02bfcf3..ce19b29 100644 --- a/lib/src/otf/cff/char_string_optimizer.dart +++ b/lib/src/otf/cff/char_string_optimizer.dart @@ -29,10 +29,11 @@ class CharStringOptimizer { final op = next.operator; - if (op == rlineto) { + if (op == CharStringOperator.rlineto.operator) { prevOpnds.addAll(currOpnds); return true; - } else if (op == hlineto || op == vlineto) { + } else if (op == CharStringOperator.hlineto.operator || + op == CharStringOperator.vlineto.operator) { final prevIsOdd = prevOpnds.length.isOdd; final currIsOdd = currOpnds.length.isOdd; @@ -43,10 +44,11 @@ class CharStringOptimizer { prevOpnds.addAll(currOpnds); return true; } - } else if (op == rrcurveto) { + } else if (op == CharStringOperator.rrcurveto.operator) { prevOpnds.addAll(currOpnds); return true; - } else if (op == hhcurveto || op == vvcurveto) { + } else if (op == CharStringOperator.hhcurveto.operator || + op == CharStringOperator.vvcurveto.operator) { final prevHasDelta = prevOpnds.length % 4 != 0; final currHasDelta = currOpnds.length % 4 != 0; @@ -74,11 +76,11 @@ class CharStringOptimizer { return commandList.where((e) { final everyOperandIsZero = e.operandList.every((o) => o.value == 0); final isCurveToOperator = [ - rrcurveto, - vvcurveto, - hhcurveto, - vhcurveto, - hvcurveto, + CharStringOperator.rrcurveto.operator, + CharStringOperator.vvcurveto.operator, + CharStringOperator.hhcurveto.operator, + CharStringOperator.vhcurveto.operator, + CharStringOperator.hvcurveto.operator, ].contains(e.operator); if (isCurveToOperator) { diff --git a/lib/src/otf/cff/dict_operator.dart b/lib/src/otf/cff/dict_operator.dart index 82db5a2..ddecc76 100644 --- a/lib/src/otf/cff/dict_operator.dart +++ b/lib/src/otf/cff/dict_operator.dart @@ -1,122 +1,65 @@ -import 'dart:collection'; - import 'package:icon_font/src/otf/cff/operator.dart'; -// Top DICT operators - -/// 1/unitsPerEm 0 0 1/unitsPerEm 0 0. Omitted if unitsPerEm is 1000. -const fontMatrix = CFFOperator(context: CFFOperatorContext.dict, b0: 12, b1: 7); - -/// CharStrings INDEX offset. -const charStrings = CFFOperator(context: CFFOperatorContext.dict, b0: 17); - -/// Font DICT (FD) INDEX offset. -const fdArray = CFFOperator(context: CFFOperatorContext.dict, b0: 12, b1: 36); - -/// FDSelect structure offset. OOmitted if just one Font DICT. -const fdSelect = CFFOperator(context: CFFOperatorContext.dict, b0: 12, b1: 37); - -/// VariationStore structure offset. Omitted if there is no varation data. -const vstore = CFFOperator(context: CFFOperatorContext.dict, b0: 24); - -// CFF1 Top DICT operators - -/// version -const version = CFFOperator(context: CFFOperatorContext.dict, b0: 0); - -/// Notice -const notice = CFFOperator(context: CFFOperatorContext.dict, b0: 1); - -/// Copyright -const copyright = CFFOperator(context: CFFOperatorContext.dict, b0: 12, b1: 0); - -/// Full Name -const fullName = CFFOperator(context: CFFOperatorContext.dict, b0: 2); - -/// Family Name -const familyName = CFFOperator(context: CFFOperatorContext.dict, b0: 3); - -/// Weight -const weight = CFFOperator(context: CFFOperatorContext.dict, b0: 4); - -/// Font BBox -const fontBBox = CFFOperator(context: CFFOperatorContext.dict, b0: 5); - -/// Charset offset -const charset = CFFOperator(context: CFFOperatorContext.dict, b0: 15); - -/// Encoding offset -const encoding = CFFOperator(context: CFFOperatorContext.dict, b0: 16); - -/// Nominal Width X -const nominalWidthX = CFFOperator(context: CFFOperatorContext.dict, b0: 21); - -// Font DICT operators - -/// Private DICT size and offset -const private = CFFOperator(context: CFFOperatorContext.dict, b0: 18); - -const blueValues = CFFOperator(context: CFFOperatorContext.dict, b0: 6); -const otherBlues = CFFOperator(context: CFFOperatorContext.dict, b0: 7); -const familyBlues = CFFOperator(context: CFFOperatorContext.dict, b0: 8); -const familyOtherBlues = CFFOperator(context: CFFOperatorContext.dict, b0: 9); -const stdHW = CFFOperator(context: CFFOperatorContext.dict, b0: 10); -const stdVW = CFFOperator(context: CFFOperatorContext.dict, b0: 11); -const escape = CFFOperator(context: CFFOperatorContext.dict, b0: 12); -const subrs = CFFOperator(context: CFFOperatorContext.dict, b0: 19); -const vsindex = CFFOperator(context: CFFOperatorContext.dict, b0: 22); -const blend = CFFOperator(context: CFFOperatorContext.dict, b0: 23); -const bcd = CFFOperator(context: CFFOperatorContext.dict, b0: 30); - -const blueScale = CFFOperator(context: CFFOperatorContext.dict, b0: 12, b1: 9); -const blueShift = CFFOperator(context: CFFOperatorContext.dict, b0: 12, b1: 10); -const blueFuzz = CFFOperator(context: CFFOperatorContext.dict, b0: 12, b1: 11); -const stemSnapH = CFFOperator(context: CFFOperatorContext.dict, b0: 12, b1: 12); -const stemSnapV = CFFOperator(context: CFFOperatorContext.dict, b0: 12, b1: 13); -const languageGroup = CFFOperator( - context: CFFOperatorContext.dict, - b0: 12, - b1: 17, -); -const expansionFactor = CFFOperator( - context: CFFOperatorContext.dict, - b0: 12, - b1: 18, -); - -final Map dictOperatorNames = UnmodifiableMapView({ - fontMatrix: 'FontMatrix', - charStrings: 'CharStrings', - fdArray: 'FDArray', - fdSelect: 'FDSelect', - vstore: 'vstore', - private: 'Private', - blueValues: 'BlueValues', - otherBlues: 'OtherBlues', - familyBlues: 'FamilyBlues', - familyOtherBlues: 'FamilyOtherBlues', - stdHW: 'StdHW', - stdVW: 'StdVW', - escape: 'escape', - subrs: 'Subrs', - vsindex: 'vsindex', - blend: 'blend', - bcd: 'BCD', - blueScale: 'BlueScale', - blueShift: 'BlueShift', - blueFuzz: 'BlueFuzz', - stemSnapH: 'StemSnapH', - stemSnapV: 'StemSnapV', - languageGroup: 'LanguageGroup', - expansionFactor: 'ExpansionFactor', - charset: 'charset', - encoding: 'Encoding', - version: 'version', - notice: 'Notice', - copyright: 'Copyright', - fullName: 'FullName', - familyName: 'FamilyName', - weight: 'Weight', - fontBBox: 'FontBBox', - nominalWidthX: 'nominalWidthX', -}); +enum DictOperator { + // Top DICT operators + /// 1/unitsPerEm 0 0 1/unitsPerEm 0 0. Omitted if unitsPerEm is 1000. + fontMatrix(label: 'FontMatrix', b0: 12, b1: 7), + + /// CharStrings INDEX offset. + charStrings(label: 'CharStrings', b0: 17), + + /// Font DICT (FD) INDEX offset. + fdArray(label: 'FDArray', b0: 12, b1: 36), + + /// FDSelect structure offset. Omitted if just one Font DICT. + fdSelect(label: 'FDSelect', b0: 12, b1: 37), + + /// VariationStore structure offset. Omitted if there is no varation data. + vstore(label: 'vstore', b0: 24), + + // CFF1 Top DICT operators + version(label: 'version', b0: 0), + notice(label: 'Notice', b0: 1), + copyright(label: 'Copyright', b0: 12, b1: 0), + fullName(label: 'FullName', b0: 2), + familyName(label: 'FamilyName', b0: 3), + weight(label: 'Weight', b0: 4), + fontBBox(label: 'FontBBox', b0: 5), + charset(label: 'charset', b0: 15), + encoding(label: 'Encoding', b0: 16), + nominalWidthX(label: 'nominalWidthX', b0: 21), + + // Font DICT operators + /// Private DICT size and offset + private(label: 'Private', b0: 18), + blueValues(label: 'BlueValues', b0: 6), + otherBlues(label: 'OtherBlues', b0: 7), + familyBlues(label: 'FamilyBlues', b0: 8), + familyOtherBlues(label: 'FamilyOtherBlues', b0: 9), + stdHW(label: 'StdHW', b0: 10), + stdVW(label: 'StdVW', b0: 11), + escape(label: 'escape', b0: 12), + subrs(label: 'Subrs', b0: 19), + vsindex(label: 'vsindex', b0: 22), + blend(label: 'blend', b0: 23), + bcd(label: 'BCD', b0: 30), + blueScale(label: 'BlueScale', b0: 12, b1: 9), + blueShift(label: 'BlueShift', b0: 12, b1: 10), + blueFuzz(label: 'BlueFuzz', b0: 12, b1: 11), + stemSnapH(label: 'StemSnapH', b0: 12, b1: 12), + stemSnapV(label: 'StemSnapV', b0: 12, b1: 13), + languageGroup(label: 'LanguageGroup', b0: 12, b1: 17), + expansionFactor(label: 'ExpansionFactor', b0: 12, b1: 18); + + const DictOperator({required this.label, required int b0, int? b1}) + : _b0 = b0, + _b1 = b1, + context = CFFOperatorContext.dict; + + final int _b0; + final int? _b1; + final String label; + final CFFOperatorContext context; + + CFFOperator get operator => CFFOperator(context: context, b0: _b0, b1: _b1); +} diff --git a/lib/src/otf/cff/operator.dart b/lib/src/otf/cff/operator.dart index 43b97a0..8ed7876 100644 --- a/lib/src/otf/cff/operator.dart +++ b/lib/src/otf/cff/operator.dart @@ -43,19 +43,11 @@ class CFFOperator implements BinaryCodable { @override String toString() { - var name = ''; - - switch (context) { - case CFFOperatorContext.dict: - if (dictOperatorNames.containsKey(this)) { - name = dictOperatorNames[this]!; - } - case CFFOperatorContext.charString: - if (charStringOperatorNames.containsKey(this)) { - name = charStringOperatorNames[this]!; - } - } - - return name; + return switch (context) { + CFFOperatorContext.dict => + DictOperator.values.firstWhere((o) => o.operator == this).label, + CFFOperatorContext.charString => + CharStringOperator.values.firstWhere((o) => o.operator == this).name, + }; } } diff --git a/lib/src/otf/table/cff1.dart b/lib/src/otf/table/cff1.dart index e388db9..3ad091d 100644 --- a/lib/src/otf/table/cff1.dart +++ b/lib/src/otf/table/cff1.dart @@ -123,7 +123,7 @@ class CFF1Table extends CFFTable implements CalculatableOffsets { /// CharStrings INDEX final charStringsIndexEntry = topDict.getEntryForOperator( - operator: op.charStrings, + operator: op.DictOperator.charStrings.operator, )!; final charStringsIndexOffset = charStringsIndexEntry.operandList.first.value! as int; @@ -139,7 +139,9 @@ class CFF1Table extends CFFTable implements CalculatableOffsets { /// Charsets final charsetsOffset = topDict - .getEntryForOperator(operator: op.charset)! + .getEntryForOperator( + operator: op.DictOperator.charset.operator, + )! .operandList .first .value! @@ -153,7 +155,9 @@ class CFF1Table extends CFFTable implements CalculatableOffsets { glyphCount: charStringsData.index!.count, )!; - final privateEntry = topDict.getEntryForOperator(operator: op.private)!; + final privateEntry = topDict.getEntryForOperator( + operator: op.DictOperator.private.operator, + )!; final dictOffset = entry.offset + (privateEntry.operandList.last.value! as int); final dictLength = privateEntry.operandList.first.value! as int; @@ -167,7 +171,9 @@ class CFF1Table extends CFFTable implements CalculatableOffsets { final localSubrsDataList = >[]; // NOTE: reading only first local subrs - final localSubrEntry = privateDict.getEntryForOperator(operator: op.subrs); + final localSubrEntry = privateDict.getEntryForOperator( + operator: op.DictOperator.subrs.operator, + ); if (localSubrEntry != null) { /// Offset from the start of the Private DICT final localSubrOffset = localSubrEntry.operandList.first.value! as int; @@ -232,9 +238,11 @@ class CFF1Table extends CFFTable implements CalculatableOffsets { final fontName = name.getStringByNameId(NameID.fullFontName)!; final topDictStringEntryMap = { - op.version: name.getStringByNameId(NameID.version), - op.fullName: fontName, - op.weight: name.getStringByNameId(NameID.fontSubfamily), + op.DictOperator.version.operator: name.getStringByNameId(NameID.version), + op.DictOperator.fullName.operator: fontName, + op.DictOperator.weight.operator: name.getStringByNameId( + NameID.fontSubfamily, + ), }; final entryList = [ @@ -251,7 +259,7 @@ class CFF1Table extends CFFTable implements CalculatableOffsets { CFFOperand.fromValue(head.xMax), CFFOperand.fromValue(head.yMax), ], - operator: op.fontBBox, + operator: op.DictOperator.fontBBox.operator, ), ]; final topDicts = CFFIndexWithData.create( @@ -278,7 +286,10 @@ class CFF1Table extends CFFTable implements CalculatableOffsets { ...glyph.toCharStringCommands( optimizer: CharStringOptimizer(isCFF1: true), ), - CharStringCommand(operator: cs_op.endchar, operandList: []), + CharStringCommand( + operator: cs_op.CharStringOperator.endchar.operator, + operandList: [], + ), ]; final byteData = CharStringInterpreter(isCFF1: true).writeCommands( commandList: commandList, @@ -299,7 +310,7 @@ class CFF1Table extends CFFTable implements CalculatableOffsets { entryList: [ CFFDictEntry( operandList: [CFFOperand.fromValue(0)], - operator: op.nominalWidthX, + operator: op.DictOperator.nominalWidthX.operator, ), ], ); @@ -356,18 +367,18 @@ class CFF1Table extends CFFTable implements CalculatableOffsets { final entryList = [ CFFDictEntry( operandList: [CFFOperand.fromValue(0)], - operator: op.charset, + operator: op.DictOperator.charset.operator, ), CFFDictEntry( operandList: [CFFOperand.fromValue(0)], - operator: op.charStrings, + operator: op.DictOperator.charStrings.operator, ), CFFDictEntry( operandList: [ CFFOperand.fromValue(privateDictList.first.size), CFFOperand.fromValue(0), ], - operator: op.private, + operator: op.DictOperator.private.operator, ), ]; @@ -395,11 +406,15 @@ class CFF1Table extends CFFTable implements CalculatableOffsets { final privateDictOffset = offset; offset += privateDict.size; - final charsetEntry = topDict.getEntryForOperator(operator: op.charset)!; + final charsetEntry = topDict.getEntryForOperator( + operator: op.DictOperator.charset.operator, + )!; final charStringsEntry = topDict.getEntryForOperator( - operator: op.charStrings, + operator: op.DictOperator.charStrings.operator, + )!; + final privateEntry = topDict.getEntryForOperator( + operator: op.DictOperator.private.operator, )!; - final privateEntry = topDict.getEntryForOperator(operator: op.private)!; final offsetList = [charsetOffset, charStringsOffset, privateDictOffset]; @@ -428,7 +443,9 @@ class CFF1Table extends CFFTable implements CalculatableOffsets { } // Last data offset - final lastDataEntry = topDict.getEntryForOperator(operator: op.private)!; + final lastDataEntry = topDict.getEntryForOperator( + operator: op.DictOperator.private.operator, + )!; final lastDataOffset = lastDataEntry.operandList.last.value! as int; header.offSize = (lastDataOffset.bitLength / 8).ceil(); } diff --git a/lib/src/otf/table/cff2.dart b/lib/src/otf/table/cff2.dart index 4b5a80c..5b04652 100644 --- a/lib/src/otf/table/cff2.dart +++ b/lib/src/otf/table/cff2.dart @@ -96,7 +96,7 @@ class CFF2Table extends CFFTable implements CalculatableOffsets { /// CharStrings INDEX final charStringsIndexEntry = topDict.getEntryForOperator( - operator: op.charStrings, + operator: op.DictOperator.charStrings.operator, )!; final charStringsIndexOffset = charStringsIndexEntry.operandList.first.value! as int; @@ -110,7 +110,9 @@ class CFF2Table extends CFFTable implements CalculatableOffsets { ); /// VariationStore - final vstoreEntry = topDict.getEntryForOperator(operator: op.vstore); + final vstoreEntry = topDict.getEntryForOperator( + operator: op.DictOperator.vstore.operator, + ); VariationStoreData? vstoreData; if (vstoreEntry != null) { @@ -122,7 +124,9 @@ class CFF2Table extends CFFTable implements CalculatableOffsets { // NOTE: not decoding FDSelect - using single Font DICT only /// Font DICT INDEX - final fdArrayEntry = topDict.getEntryForOperator(operator: op.fdArray)!; + final fdArrayEntry = topDict.getEntryForOperator( + operator: op.DictOperator.fdArray.operator, + )!; final fdArrayOffset = fdArrayEntry.operandList.first.value! as int; final fontIndexByteData = byteData.sublistView( @@ -143,7 +147,7 @@ class CFF2Table extends CFFTable implements CalculatableOffsets { for (var i = 0; i < fontDictList.index!.count; i++) { final privateEntry = fontDictList.data[i].getEntryForOperator( - operator: op.private, + operator: op.DictOperator.private.operator, )!; final dictOffset = entry.offset + (privateEntry.operandList.last.value! as int); @@ -153,7 +157,9 @@ class CFF2Table extends CFFTable implements CalculatableOffsets { final dict = CFFDict.fromByteData(dictByteData); privateDictList.add(dict); - final localSubrEntry = dict.getEntryForOperator(operator: op.subrs); + final localSubrEntry = dict.getEntryForOperator( + operator: op.DictOperator.subrs.operator, + ); if (localSubrEntry != null) { /// Offset from the start of the Private DICT @@ -197,16 +203,16 @@ class CFF2Table extends CFFTable implements CalculatableOffsets { final entryList = [ CFFDictEntry( operandList: [CFFOperand.fromValue(0)], - operator: op.charStrings, + operator: op.DictOperator.charStrings.operator, ), if (vstoreData != null) CFFDictEntry( operandList: [CFFOperand.fromValue(0)], - operator: op.vstore, + operator: op.DictOperator.vstore.operator, ), CFFDictEntry( operandList: [CFFOperand.fromValue(0)], - operator: op.fdArray, + operator: op.DictOperator.fdArray.operator, ), // NOTE: not encoding FDSelect - using single Font DICT only ]; @@ -232,11 +238,15 @@ class CFF2Table extends CFFTable implements CalculatableOffsets { final fdArrayOffset = offset; offset += fontDictList.size; - final vstoreEntry = topDict.getEntryForOperator(operator: op.vstore); + final vstoreEntry = topDict.getEntryForOperator( + operator: op.DictOperator.vstore.operator, + ); final charStringsEntry = topDict.getEntryForOperator( - operator: op.charStrings, + operator: op.DictOperator.charStrings.operator, + )!; + final fdArrayEntry = topDict.getEntryForOperator( + operator: op.DictOperator.fdArray.operator, )!; - final fdArrayEntry = topDict.getEntryForOperator(operator: op.fdArray)!; final offsetList = [ if (vstoreData != null) vstoreOffset!, @@ -264,7 +274,9 @@ class CFF2Table extends CFFTable implements CalculatableOffsets { charStringsData.recalculateOffsets(); // Recalculating font DICTs private offsets and SUBRS entries offsets - final fdArrayEntry = topDict.getEntryForOperator(operator: op.fdArray)!; + final fdArrayEntry = topDict.getEntryForOperator( + operator: op.DictOperator.fdArray.operator, + )!; final fdArrayOffset = fdArrayEntry.operandList.first.value! as int; var fontDictOffset = fdArrayOffset + fontDictList.index!.size; @@ -272,7 +284,9 @@ class CFF2Table extends CFFTable implements CalculatableOffsets { for (var i = 0; i < fontDictList.data.length; i++) { final fontDict = fontDictList.data[i]; final privateDict = privateDictList[i]; - final privateEntry = fontDict.getEntryForOperator(operator: op.private)!; + final privateEntry = fontDict.getEntryForOperator( + operator: op.DictOperator.private.operator, + )!; final newOperands = [ CFFOperand.fromValue(privateDict.size), @@ -283,7 +297,9 @@ class CFF2Table extends CFFTable implements CalculatableOffsets { ..addAll(newOperands); fontDictOffset += fontDict.size; - final subrsEntry = privateDict.getEntryForOperator(operator: op.subrs); + final subrsEntry = privateDict.getEntryForOperator( + operator: op.DictOperator.subrs.operator, + ); if (subrsEntry != null) { subrsEntry.operandList ..clear() diff --git a/lib/src/otf/table/script_list.dart b/lib/src/otf/table/script_list.dart index 59f2f8e..5ea29bb 100644 --- a/lib/src/otf/table/script_list.dart +++ b/lib/src/otf/table/script_list.dart @@ -5,7 +5,7 @@ import 'package:icon_font/src/otf/table/language_system.dart'; import 'package:icon_font/src/utils/constants.dart'; import 'package:icon_font/src/utils/extensions.dart'; -const kScriptRecordSize = 6; +const _scriptRecordSize = 6; class ScriptRecord implements BinaryCodable { ScriptRecord({required this.scriptTag, required this.scriptOffset}); @@ -26,7 +26,7 @@ class ScriptRecord implements BinaryCodable { int? scriptOffset; @override - int get size => kScriptRecordSize; + int get size => _scriptRecordSize; @override void encodeToBinary(ByteData byteData) { @@ -148,7 +148,7 @@ class ScriptListTable implements BinaryCodable { scriptCount, (i) => ScriptRecord.fromByteData( byteData: byteData, - offset: offset + 2 + kScriptRecordSize * i, + offset: offset + 2 + _scriptRecordSize * i, ), ); final scriptTables = List.generate( @@ -211,12 +211,12 @@ class ScriptListTable implements BinaryCodable { byteData.setUint16(0, scriptCount); var recordOffset = 2; - var tableRelativeOffset = 2 + kScriptRecordSize * scriptCount; + var tableRelativeOffset = 2 + _scriptRecordSize * scriptCount; for (var i = 0; i < scriptCount; i++) { final record = scriptRecords[i] ..scriptOffset = tableRelativeOffset - ..encodeToBinary(byteData.sublistView(recordOffset, kScriptRecordSize)); + ..encodeToBinary(byteData.sublistView(recordOffset, _scriptRecordSize)); final table = scriptTables[i]; table.encodeToBinary(