Skip to content

Commit 841451c

Browse files
committed
Update of the documantation directory
1 parent 8238594 commit 841451c

5 files changed

Lines changed: 283 additions & 0 deletions

File tree

documentation/image1.png

105 KB
Loading

documentation/image1.py

Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
# This script is meant to be run from the root level
2+
# of your font's git repository. For example, from a Unix terminal:
3+
# $ git clone my-font
4+
# $ cd my-font
5+
# $ python3 documentation/image1.py --output documentation/image1.png
6+
7+
# Import moduels from external python packages: https://pypi.org/
8+
from drawbot_skia.drawbot import *
9+
from fontTools.ttLib import TTFont
10+
from fontTools.misc.fixedTools import floatToFixedToStr
11+
12+
# Import moduels from the Python Standard Library: https://docs.python.org/3/library/
13+
import subprocess
14+
import sys
15+
import argparse
16+
17+
# Constants, these are the main "settings" for the image
18+
WIDTH, HEIGHT, MARGIN, FRAMES = 2048, 1024, 128, 1
19+
FONT_PATH = "fonts/ttf/RadioCanadaDisplay-Regular.ttf"
20+
FONT_LICENSE = "OFL v1.1"
21+
AUXILIARY_FONT = "Helvetica"
22+
AUXILIARY_FONT_SIZE = 48
23+
24+
BIG_TEXT = "AaBb"
25+
BIG_TEXT_FONT_SIZE = 730
26+
BIG_TEXT_SIDE_MARGIN = MARGIN * 1
27+
BIG_TEXT_BOTTOM_MARGIN = MARGIN * 2
28+
29+
GRID_VIEW = False # Toggle this for a grid overlay
30+
31+
# Handel the "--output" flag
32+
# For example: $ python3 documentation/image1.py --output documentation/image1.png
33+
parser = argparse.ArgumentParser()
34+
parser.add_argument("--output", metavar="PNG", help="where to write the PNG file")
35+
args = parser.parse_args()
36+
37+
# Load the font with the parts of fonttools that are imported with the line:
38+
# from fontTools.ttLib import TTFont
39+
# Docs Link: https://fonttools.readthedocs.io/en/latest/ttLib/ttFont.html
40+
ttFont = TTFont(FONT_PATH)
41+
42+
# Constants that are worked out dynamically
43+
MY_URL = subprocess.check_output("git remote get-url origin", shell=True).decode()
44+
MY_HASH = subprocess.check_output("git rev-parse --short HEAD", shell=True).decode()
45+
FONT_NAME = ttFont["name"].getDebugName(4)
46+
FONT_VERSION = "v%s" % floatToFixedToStr(ttFont["head"].fontRevision, 16)
47+
48+
49+
# Draws a grid
50+
def grid():
51+
stroke(1, 0, 0, 0.75)
52+
strokeWidth(2)
53+
STEP_X, STEP_Y = 0, 0
54+
INCREMENT_X, INCREMENT_Y = MARGIN / 2, MARGIN / 2
55+
rect(MARGIN, MARGIN, WIDTH - (MARGIN * 2), HEIGHT - (MARGIN * 2))
56+
for x in range(29):
57+
polygon((MARGIN + STEP_X, MARGIN), (MARGIN + STEP_X, HEIGHT - MARGIN))
58+
STEP_X += INCREMENT_X
59+
for y in range(29):
60+
polygon((MARGIN, MARGIN + STEP_Y), (WIDTH - MARGIN, MARGIN + STEP_Y))
61+
STEP_Y += INCREMENT_Y
62+
polygon((WIDTH / 2, 0), (WIDTH / 2, HEIGHT))
63+
polygon((0, HEIGHT / 2), (WIDTH, HEIGHT / 2))
64+
65+
66+
# Remap input range to VF axis range
67+
# This is useful for animation
68+
# (E.g. sinewave(-1,1) to wght(100,900))
69+
def remap(value, inputMin, inputMax, outputMin, outputMax):
70+
inputSpan = inputMax - inputMin # FIND INPUT RANGE SPAN
71+
outputSpan = outputMax - outputMin # FIND OUTPUT RANGE SPAN
72+
valueScaled = float(value - inputMin) / float(inputSpan)
73+
return outputMin + (valueScaled * outputSpan)
74+
75+
76+
# Draw the page/frame and a grid if "GRID_VIEW" is set to "True"
77+
def draw_background():
78+
newPage(WIDTH, HEIGHT)
79+
fill(0)
80+
rect(-2, -2, WIDTH + 2, HEIGHT + 2)
81+
if GRID_VIEW:
82+
grid()
83+
else:
84+
pass
85+
86+
87+
# Draw main text
88+
def draw_main_text():
89+
fill(1)
90+
stroke(None)
91+
font(FONT_PATH)
92+
fontSize(BIG_TEXT_FONT_SIZE)
93+
# Adjust this line to center main text manually.
94+
# TODO: This should be done automatically when drawbot-skia
95+
# has support for textBox() and FormattedString
96+
#text(BIG_TEXT, ((WIDTH / 2) - MARGIN * 4.75, (HEIGHT / 2) - MARGIN * 2.5))
97+
text(BIG_TEXT, (BIG_TEXT_SIDE_MARGIN, BIG_TEXT_BOTTOM_MARGIN))
98+
99+
100+
# Divider lines
101+
def draw_divider_lines():
102+
stroke(1)
103+
strokeWidth(5)
104+
lineCap("round")
105+
line((MARGIN, HEIGHT - (MARGIN * 1.5)), (WIDTH - MARGIN, HEIGHT - (MARGIN * 1.5)))
106+
line((MARGIN, MARGIN + (MARGIN / 2)), (WIDTH - MARGIN, MARGIN + (MARGIN / 2)))
107+
stroke(None)
108+
109+
110+
# Draw text describing the font and it's git status & repo URL
111+
def draw_auxiliary_text():
112+
# Setup
113+
font(AUXILIARY_FONT)
114+
fontSize(AUXILIARY_FONT_SIZE)
115+
POS_TOP_LEFT = (MARGIN, HEIGHT - MARGIN * 1.25)
116+
POS_TOP_RIGHT = (WIDTH - MARGIN, HEIGHT - MARGIN * 1.25)
117+
POS_BOTTOM_LEFT = (MARGIN, MARGIN)
118+
POS_BOTTOM_RIGHT = (WIDTH - MARGIN * 0.95, MARGIN)
119+
URL_AND_HASH = MY_URL + "at commit " + MY_HASH
120+
URL_AND_HASH = URL_AND_HASH.replace("\n", " ")
121+
# Draw Text
122+
text(FONT_NAME, POS_TOP_LEFT, align="left")
123+
text(FONT_VERSION, POS_TOP_RIGHT, align="right")
124+
text(URL_AND_HASH, POS_BOTTOM_LEFT, align="left")
125+
text(FONT_LICENSE, POS_BOTTOM_RIGHT, align="right")
126+
127+
128+
# Build and save the image
129+
if __name__ == "__main__":
130+
draw_background()
131+
draw_main_text()
132+
draw_divider_lines()
133+
draw_auxiliary_text()
134+
# Save output, using the "--output" flag location
135+
saveImage(args.output)
136+
# Print done in the terminal
137+
print("DrawBot: Done")

documentation/image2.png

211 KB
Loading

documentation/image2.py

Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
# This script is meant to be run from the root level
2+
# of your font's git repository. For example, from a Unix terminal:
3+
# $ git clone my-font
4+
# $ cd my-font
5+
# $ python3 documentation/image1.py --output documentation/image1.png
6+
7+
# Import moduels from external python packages: https://pypi.org/
8+
from drawbot_skia.drawbot import *
9+
from fontTools.ttLib import TTFont
10+
from fontTools.misc.fixedTools import floatToFixedToStr
11+
12+
# Import moduels from the Python Standard Library: https://docs.python.org/3/library/
13+
import subprocess
14+
import sys
15+
import argparse
16+
17+
# Constants, these are the main "settings" for the image
18+
WIDTH, HEIGHT, MARGIN, FRAMES = 2048, 1024, 128, 1
19+
FONT_PATH = "fonts/ttf/RadioCanadaDisplay-Regular.ttf"
20+
FONT_LICENSE = "OFL v1.1"
21+
AUXILIARY_FONT = "Helvetica"
22+
AUXILIARY_FONT_SIZE = 48
23+
24+
LINE_ONE = "ABCDEFGHIJKLMNOPQ"
25+
LINE_TWO = "RSTUVWXYZ123456789"
26+
LINE_THREE = "abcdefghijklmnopqrstu"
27+
LINE_FOUR = "vwxyz,.;:!@#$%^&*(){}[]"
28+
BIG_TEXT_FONT_SIZE = 160
29+
BIG_TEXT_SIDE_MARGIN = MARGIN * 1
30+
BIG_TEXT_BOTTOM_MARGIN = MARGIN * 5.45
31+
32+
GRID_VIEW = False # Toggle this for a grid overlay
33+
34+
# Handel the "--output" flag
35+
# For example: $ python3 documentation/image1.py --output documentation/image1.png
36+
parser = argparse.ArgumentParser()
37+
parser.add_argument("--output", metavar="PNG", help="where to write the PNG file")
38+
args = parser.parse_args()
39+
40+
# Load the font with the parts of fonttools that are imported with the line:
41+
# from fontTools.ttLib import TTFont
42+
# Docs Link: https://fonttools.readthedocs.io/en/latest/ttLib/ttFont.html
43+
ttFont = TTFont(FONT_PATH)
44+
45+
# Constants that are worked out dynamically
46+
MY_URL = subprocess.check_output("git remote get-url origin", shell=True).decode()
47+
MY_HASH = subprocess.check_output("git rev-parse --short HEAD", shell=True).decode()
48+
FONT_NAME = ttFont["name"].getDebugName(4)
49+
FONT_VERSION = "v%s" % floatToFixedToStr(ttFont["head"].fontRevision, 16)
50+
51+
52+
# Draws a grid
53+
def grid():
54+
stroke(1, 0, 0, 0.75)
55+
strokeWidth(2)
56+
STEP_X, STEP_Y = 0, 0
57+
INCREMENT_X, INCREMENT_Y = MARGIN / 2, MARGIN / 2
58+
rect(MARGIN, MARGIN, WIDTH - (MARGIN * 2), HEIGHT - (MARGIN * 2))
59+
for x in range(29):
60+
polygon((MARGIN + STEP_X, MARGIN), (MARGIN + STEP_X, HEIGHT - MARGIN))
61+
STEP_X += INCREMENT_X
62+
for y in range(29):
63+
polygon((MARGIN, MARGIN + STEP_Y), (WIDTH - MARGIN, MARGIN + STEP_Y))
64+
STEP_Y += INCREMENT_Y
65+
polygon((WIDTH / 2, 0), (WIDTH / 2, HEIGHT))
66+
polygon((0, HEIGHT / 2), (WIDTH, HEIGHT / 2))
67+
68+
69+
# Remap input range to VF axis range
70+
# This is useful for animation
71+
# (E.g. sinewave(-1,1) to wght(100,900))
72+
def remap(value, inputMin, inputMax, outputMin, outputMax):
73+
inputSpan = inputMax - inputMin # FIND INPUT RANGE SPAN
74+
outputSpan = outputMax - outputMin # FIND OUTPUT RANGE SPAN
75+
valueScaled = float(value - inputMin) / float(inputSpan)
76+
return outputMin + (valueScaled * outputSpan)
77+
78+
79+
# Draw the page/frame and a grid if "GRID_VIEW" is set to "True"
80+
def draw_background():
81+
newPage(WIDTH, HEIGHT)
82+
fill(0)
83+
rect(-2, -2, WIDTH + 2, HEIGHT + 2)
84+
if GRID_VIEW:
85+
grid()
86+
else:
87+
pass
88+
89+
90+
# Draw main text
91+
def draw_main_text():
92+
fill(1)
93+
stroke(None)
94+
font(FONT_PATH)
95+
fontSize(BIG_TEXT_FONT_SIZE)
96+
# Adjust this line to center main text manually.
97+
# TODO: This should be done automatically when drawbot-skia
98+
# has support for textBox() and FormattedString
99+
LEADING = 1.2
100+
text(LINE_ONE, (BIG_TEXT_SIDE_MARGIN, BIG_TEXT_BOTTOM_MARGIN))
101+
text(LINE_TWO, (BIG_TEXT_SIDE_MARGIN, BIG_TEXT_BOTTOM_MARGIN - (MARGIN * LEADING)))
102+
text(LINE_THREE, (BIG_TEXT_SIDE_MARGIN, BIG_TEXT_BOTTOM_MARGIN - (MARGIN * (LEADING * 2))))
103+
text(LINE_FOUR, (BIG_TEXT_SIDE_MARGIN, BIG_TEXT_BOTTOM_MARGIN - (MARGIN * (LEADING * 3))))
104+
105+
106+
# Divider lines
107+
def draw_divider_lines():
108+
stroke(1)
109+
strokeWidth(5)
110+
lineCap("round")
111+
line((MARGIN, HEIGHT - (MARGIN * 1.5)), (WIDTH - MARGIN, HEIGHT - (MARGIN * 1.5)))
112+
line((MARGIN, MARGIN + (MARGIN / 2)), (WIDTH - MARGIN, MARGIN + (MARGIN / 2)))
113+
stroke(None)
114+
115+
116+
# Draw text describing the font and it's git status & repo URL
117+
def draw_auxiliary_text():
118+
# Setup
119+
font(AUXILIARY_FONT)
120+
fontSize(AUXILIARY_FONT_SIZE)
121+
POS_TOP_LEFT = (MARGIN, HEIGHT - MARGIN * 1.25)
122+
POS_TOP_RIGHT = (WIDTH - MARGIN, HEIGHT - MARGIN * 1.25)
123+
POS_BOTTOM_LEFT = (MARGIN, MARGIN)
124+
POS_BOTTOM_RIGHT = (WIDTH - MARGIN * 0.95, MARGIN)
125+
#URL_AND_HASH = "github.com/googlefonts/googlefonts-project-template " + "at commit " + MY_HASH
126+
URL_AND_HASH = MY_URL + "at commit " + MY_HASH
127+
URL_AND_HASH = URL_AND_HASH.replace("\n", " ")
128+
# Draw Text
129+
#text("Your Font Regular", POS_TOP_LEFT, align="left")
130+
text(FONT_NAME, POS_TOP_LEFT, align="left")
131+
text(FONT_VERSION, POS_TOP_RIGHT, align="right")
132+
text(URL_AND_HASH, POS_BOTTOM_LEFT, align="left")
133+
text(FONT_LICENSE, POS_BOTTOM_RIGHT, align="right")
134+
135+
136+
# Build and save the image
137+
if __name__ == "__main__":
138+
draw_background()
139+
draw_main_text()
140+
draw_divider_lines()
141+
draw_auxiliary_text()
142+
# Save output, using the "--output" flag location
143+
saveImage(args.output)
144+
# Print done in the terminal
145+
print("DrawBot: Done")

documentation/images-license.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
The images in this repository are licensed under the CC https://creativecommons.org/licenses/by-sa/4.0/

0 commit comments

Comments
 (0)