Skip to content

Instantly share code, notes, and snippets.

@chrissimpkins
Last active July 16, 2019 18:35
Show Gist options
  • Save chrissimpkins/378ce5a4a9ad87e53fa1a934ac8e0f81 to your computer and use it in GitHub Desktop.
Save chrissimpkins/378ce5a4a9ad87e53fa1a934ac8e0f81 to your computer and use it in GitHub Desktop.
fontelemetry demo source
# Copyright 2019 Google LLC. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from fontelemetry.parsers.settings import parse_settings
from fontelemetry.factories.glyph import OrderedGlyphColorListFactory
from fontelemetry.io.source import UFOGlyphSetReader
from fontelemetry.datastructures.source import UFOGlyphSetSource
UFO_DIR = "/Users/chris/code/fontelemetry/tests/ufo/GenericSans-MultiHighlight.ufo"
SETTINGS_PATH = "/Users/chris/code/fontelemetry/tests/toml/fontelemetry.toml"
ufo_gs_source = UFOGlyphSetSource(UFOGlyphSetReader(UFO_DIR).read())
settings = parse_settings(SETTINGS_PATH)
ogclf = OrderedGlyphColorListFactory(ufo_gs_source, settings=settings, color_spec="rgba")
gcobj_list = ogclf.get()
status1 = 0
status2 = 0
status3 = 0
white = 0
for glyphobj in gcobj_list:
# print(glyphobj.get_name(), glyphobj.get_color(), glyphobj.get_color_definition())
if glyphobj.get_color_definition() == "Status 1":
status1 += 1
elif glyphobj.get_color_definition() == "Status 2":
status2 += 1
elif glyphobj.get_color_definition() == "Status 3":
status3 += 1
elif glyphobj.get_color_definition() == "Done":
white += 1
total = status1 + status2 + status3 + white
percent_s1 = round((status1 / total) * 100, 2)
percent_s2 = round((status2 / total) * 100, 2)
percent_s3 = round((status3 / total) * 100, 2)
percent_white = round((white / total) * 100, 2)
print("Status 1: {} ({}%)\nStatus2: {} ({}%)\nStatus3: {} ({}%)\nWhite: {} ({}%)".format(status1, percent_s1, status2, percent_s2, status3, percent_s3, white, percent_white))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment