Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in
Toggle navigation
F
Front-End
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
abdullh.alsoleman
Front-End
Commits
38533ac8
Commit
38533ac8
authored
Oct 04, 2016
by
Chris Bracken
Committed by
GitHub
Oct 04, 2016
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add icon update tool (#6201)
parent
9f673ad4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
109 additions
and
2 deletions
+109
-2
update_icons.dart
dev/tools/update_icons.dart
+102
-0
icons.dart
packages/flutter/lib/src/material/icons.dart
+7
-2
No files found.
dev/tools/update_icons.dart
0 → 100644
View file @
38533ac8
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Regenerates the material icons file.
// See https://github.com/flutter/flutter/wiki/Updating-Material-Design-Fonts
import
'dart:convert'
show
LineSplitter
;
import
'dart:io'
;
import
'package:args/args.dart'
;
import
'package:path/path.dart'
as
path
;
const
String
kOptionCodepointsPath
=
'codepoints'
;
const
String
kOptionIconsPath
=
'icons'
;
const
String
kOptionDryRun
=
'dry-run'
;
const
String
kDefaultCodepointsPath
=
'bin/cache/artifacts/material_fonts/codepoints'
;
const
String
kDefaultIconsPath
=
'packages/flutter/lib/src/material/icons.dart'
;
const
String
kBeginGeneratedMark
=
'// BEGIN GENERATED'
;
const
String
kEndGeneratedMark
=
'// END GENERATED'
;
const
Map
<
String
,
String
>
kIdentifierRewrites
=
const
<
String
,
String
>{
'360'
:
'threesixty'
,
'3d_rotation'
:
'threed_rotation'
,
'4k'
:
'four_k'
,
'class'
:
'class_'
,
};
void
main
(
List
<
String
>
args
)
{
// If we're run from the `tools` dir, set the cwd to the repo root.
if
(
path
.
basename
(
Directory
.
current
.
path
)
==
'tools'
)
Directory
.
current
=
Directory
.
current
.
parent
.
parent
;
ArgParser
argParser
=
new
ArgParser
();
argParser
.
addOption
(
kOptionCodepointsPath
,
defaultsTo:
kDefaultCodepointsPath
);
argParser
.
addOption
(
kOptionIconsPath
,
defaultsTo:
kDefaultIconsPath
);
argParser
.
addFlag
(
kOptionDryRun
,
defaultsTo:
false
);
ArgResults
argResults
=
argParser
.
parse
(
args
);
File
iconFile
=
new
File
(
path
.
absolute
(
argResults
[
kOptionIconsPath
]));
if
(!
iconFile
.
existsSync
())
{
stderr
.
writeln
(
'Icons file not found:
${iconFile.path}
'
);
exit
(
1
);
}
File
codepointsFile
=
new
File
(
path
.
absolute
(
argResults
[
kOptionCodepointsPath
]));
if
(!
codepointsFile
.
existsSync
())
{
stderr
.
writeln
(
'Codepoints file not found:
${codepointsFile.path}
'
);
exit
(
1
);
}
String
iconData
=
iconFile
.
readAsStringSync
();
String
codepointData
=
codepointsFile
.
readAsStringSync
();
String
newIconData
=
regenerateIconsFile
(
iconData
,
codepointData
);
if
(
argResults
[
kOptionDryRun
])
stdout
.
writeln
(
newIconData
);
else
iconFile
.
writeAsStringSync
(
newIconData
);
}
String
regenerateIconsFile
(
String
iconData
,
String
codepointData
)
{
StringBuffer
buf
=
new
StringBuffer
();
bool
generating
=
false
;
for
(
String
line
in
LineSplitter
.
split
(
iconData
))
{
if
(!
generating
)
buf
.
writeln
(
line
);
if
(
line
.
contains
(
kBeginGeneratedMark
))
{
generating
=
true
;
String
iconDeclarations
=
generateIconDeclarations
(
codepointData
);
buf
.
write
(
iconDeclarations
);
}
else
if
(
line
.
contains
(
kEndGeneratedMark
))
{
generating
=
false
;
buf
.
writeln
(
line
);
}
}
return
buf
.
toString
();
}
String
generateIconDeclarations
(
String
codepointData
)
{
return
LineSplitter
.
split
(
codepointData
)
.
map
((
String
l
)
=>
l
.
trim
())
.
where
((
String
l
)
=>
l
.
isNotEmpty
)
.
map
(
getIconDeclaration
)
.
join
();
}
String
getIconDeclaration
(
String
line
)
{
List
<
String
>
tokens
=
line
.
split
(
' '
);
if
(
tokens
.
length
!=
2
)
throw
new
FormatException
(
'Unexpected codepoint data:
$line
'
);
String
name
=
tokens
[
0
];
String
codepoint
=
tokens
[
1
];
String
identifier
=
kIdentifierRewrites
[
name
]
??
name
;
String
description
=
name
.
replaceAll
(
'_'
,
' '
);
return
'''
/// <p><i class="material-icons md-36">
$name
</i> — material icon named "
$description
".</p>
static const IconData
$identifier
= const IconData(0x
$codepoint
);
'''
;
}
packages/flutter/lib/src/material/icons.dart
View file @
38533ac8
...
...
@@ -42,11 +42,15 @@ class IconData {
class
Icons
{
Icons
.
_
();
// Generated code: do not hand-edit.
// See https://github.com/flutter/flutter/wiki/Updating-Material-Design-Fonts
// BEGIN GENERATED
/// <p><i class="material-icons md-36">360</i> — material icon named "360".</p>
static
const
IconData
threesixty
=
const
IconData
(
0xe577
);
/// <p><i class="material-icons md-36">3d_rotation</i> — material icon named "3d rotation".</p>
static
const
IconData
threed_rotation
=
const
IconData
(
0xe84d
);
// 3d_rotation isn't a valid identifier.
static
const
IconData
threed_rotation
=
const
IconData
(
0xe84d
);
/// <p><i class="material-icons md-36">4k</i> — material icon named "4k".</p>
static
const
IconData
four_k
=
const
IconData
(
0xe072
);
...
...
@@ -589,7 +593,7 @@ class Icons {
static
const
IconData
chrome_reader_mode
=
const
IconData
(
0xe86d
);
/// <p><i class="material-icons md-36">class</i> — material icon named "class".</p>
static
const
IconData
class_
=
const
IconData
(
0xe86e
);
// class is a reserved word in Dart.
static
const
IconData
class_
=
const
IconData
(
0xe86e
);
/// <p><i class="material-icons md-36">clear</i> — material icon named "clear".</p>
static
const
IconData
clear
=
const
IconData
(
0xe14c
);
...
...
@@ -2996,4 +3000,5 @@ class Icons {
/// <p><i class="material-icons md-36">zoom_out_map</i> — material icon named "zoom out map".</p>
static
const
IconData
zoom_out_map
=
const
IconData
(
0xe56b
);
// END GENERATED
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment