Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing argument for fontWeight #46

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
5 changes: 5 additions & 0 deletions lib/src/cli/arguments.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const kOptionNames = EnumClass<CliArgument, String>({
CliArgument.fontName: 'font-name',
CliArgument.normalize: 'normalize',
CliArgument.ignoreShapes: 'ignore-shapes',
CliArgument.fontWeight: 'font-weight',

CliArgument.recursive: 'recursive',
CliArgument.verbose: 'verbose',
Expand Down Expand Up @@ -90,6 +91,7 @@ enum CliArgument {
fontName,
ignoreShapes,
normalize,
fontWeight,

// Others
recursive,
Expand All @@ -112,6 +114,7 @@ class CliArguments {
this.fontName,
this.recursive,
this.ignoreShapes,
this.fontWeight,
this.normalize,
this.verbose,
this.configFile,
Expand All @@ -134,6 +137,7 @@ class CliArguments {
map[CliArgument.fontName] as String?,
map[CliArgument.recursive] as bool?,
map[CliArgument.ignoreShapes] as bool?,
int.tryParse((map[CliArgument.fontWeight] as String?) ?? ''),
map[CliArgument.normalize] as bool?,
map[CliArgument.verbose] as bool?,
map[CliArgument.configFile] as File?,
Expand All @@ -149,6 +153,7 @@ class CliArguments {
final String? fontName;
final bool? recursive;
final bool? ignoreShapes;
final int? fontWeight;
final bool? normalize;
final bool? verbose;
final File? configFile;
Expand Down
5 changes: 5 additions & 0 deletions lib/src/cli/options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ void defineOptions(ArgParser argParser) {
'Enables glyph normalization for the font. Disable this if every icon has the same size and positioning.',
defaultsTo: true,
)
..addOption(
kOptionNames[CliArgument.fontWeight]!,
help: 'Provide font weight (from 100 to 900).',
defaultsTo: '400',
)
..addFlag(
kOptionNames[CliArgument.ignoreShapes]!,
help: 'Disables SVG shape-to-path conversion (circle, rect, etc.).',
Expand Down
2 changes: 2 additions & 0 deletions lib/src/common/api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ SvgToOtfResult svgToOtf({
bool? ignoreShapes,
bool? normalize,
String? fontName,
int? fontWeight,
}) {
normalize ??= true;

Expand Down Expand Up @@ -59,6 +60,7 @@ SvgToOtfResult svgToOtf({
glyphList: glyphList,
fontName: fontName,
normalize: normalize,
fontWeight: fontWeight,
useOpenType: true,
usePostV2: true,
);
Expand Down
4 changes: 3 additions & 1 deletion lib/src/otf/otf.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class OpenTypeFont implements BinaryCodable {
bool? useOpenType,
bool? usePostV2,
bool? normalize,
int? fontWeight,
}) {
if (fontName?.isEmpty ?? false) {
fontName = null;
Expand Down Expand Up @@ -136,7 +137,8 @@ class OpenTypeFont implements BinaryCodable {
final maxp = MaximumProfileTable.create(fullGlyphList.length, glyf);
final cmap = CharacterToGlyphTable.create(fullGlyphList);
final gsub = GlyphSubstitutionTable.create();
final os2 = OS2Table.create(hmtx, head, hhea, cmap, gsub, achVendID);
final os2 = OS2Table.create(hmtx, head, hhea, cmap, gsub, achVendID,
fontWeight: fontWeight);

final cff =
useOpenType ? CFF1Table.create(fullGlyphList, head, hmtx, name) : null;
Expand Down
3 changes: 2 additions & 1 deletion lib/src/otf/table/os2.dart
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ class OS2Table extends FontTable {
GlyphSubstitutionTable gsub,
String achVendID, {
int version = _kVersion5,
int? fontWeight,
}) {
final asciiAchVendID = achVendID.getAsciiPrintable();

Expand Down Expand Up @@ -180,7 +181,7 @@ class OS2Table extends FontTable {
null,
version,
_getAverageWidth(hmtx),
400, // Regular weight
fontWeight ?? 400, // Regular weight
5, // Normal width
0, // Installable embedding
scriptXsize,
Expand Down