Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions lib/src/otf/cff/char_string.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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]),
);
}
Expand All @@ -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]),
);
}
Expand All @@ -99,7 +99,7 @@ class CharStringCommand implements BinaryCodable {
}

return CharStringCommand(
operator: rlineto,
operator: CharStringOperator.rlineto.operator,
operandList: _getOperandList(operandValues: dlist),
);
}
Expand All @@ -120,7 +120,7 @@ class CharStringCommand implements BinaryCodable {
}

return CharStringCommand(
operator: hhcurveto,
operator: CharStringOperator.hhcurveto.operator,
operandList: _getOperandList(operandValues: dlist),
);
}
Expand All @@ -131,7 +131,7 @@ class CharStringCommand implements BinaryCodable {
}

return CharStringCommand(
operator: vvcurveto,
operator: CharStringOperator.vvcurveto.operator,
operandList: _getOperandList(operandValues: dlist),
);
}
Expand Down Expand Up @@ -162,7 +162,7 @@ class CharStringCommand implements BinaryCodable {
}

return CharStringCommand(
operator: rrcurveto,
operator: CharStringOperator.rrcurveto.operator,
operandList: _getOperandList(operandValues: dlist),
);
}
Expand Down
118 changes: 39 additions & 79 deletions lib/src/otf/cff/char_string_operator.dart
Original file line number Diff line number Diff line change
@@ -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<CFFOperator, String> 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);
}
20 changes: 11 additions & 9 deletions lib/src/otf/cff/char_string_optimizer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down
Loading