summaryrefslogtreecommitdiff
path: root/opentype-gx/opentypegx_slides.py
blob: cbdbd1fed34545346ae02ab1ae36f5afe3590276 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
#!/usr/bin/python
# -*- coding:utf8 -*-

# Copyright 2016 Behdad Esfahbod <behdad@google.com>

# A slides file should populate the variable slides with
# a list of tuples.  Each tuple should have:
#
#	- Slide content
#	- User data
#	- Canvas width
#	- Canvas height
#
# Slide content can be a string, a list of strings,
# a function returning one of those, or a generator
# yielding strings.  The user data should be a dictionary or
# None, and is both used to communicate options to the
# renderer and to pass extra options to the theme functions.
#
# A function-based slide content will be passed a renderer object.
# Renderer is an object similar to a cairo.Context and
# pangocairo.CairoContext but has its own methods too.
# The more useful of them here are put_text, put_image, and
# set_allocation.  See their pydocs.

title_font="Impact"
subtitle_font="Oswald Bold"
head_font="sans Bold" # "Oswald Bold"
body_font="sans" # "PT Sans"
mono_font="Consolas, monospace"

slides = []
def slide_add(f, data=None, width=1920, height=1200):
	if data is None:
		data = {}
	if "desc" not in data:
		data['desc'] = body_font
	slides.append ((f, data, width, height))
	return f

import pango, pangocairo, cairo, os, signal
from pangopygments import highlight

# We use slide data to tell the theme who's speaking.
# That is, which side the bubble should point to.
behdad = -1
whois = 0
def who(name):
	global whois
	whois = name

# And convenience functions to add a slide.  Can be
# used as a function decorator, or called directly.
def slide_who(f, who, data=None):
	if data:
		data = dict (data)
	else:
		data = {}
	data['who'] = who
	return slide_add (f, data)

def slide(f, data=None):
	return slide_who (f, whois, data=data)

def slide_heading(f, data=None):
	if data is None:
		data = {}
	if 'desc' not in data:
		data['desc'] = head_font
	if data and 'who' in data:
		return slide_who (f, data['who'], data=data)
	else:
		return slide_who (f, 0, data=data)

def slide_title (title, text):
	def s (r):
		ts = "<span font_desc='"+head_font+"'>"+title+"</span>\n"
		return ts + text
	s.__name__ = title
	data={'desc': body_font, 'align': pango.ALIGN_LEFT}
	slide (s, data)
def bullet_list_slide (title, items):
	def s (r):
		ts = "<span font_desc='"+head_font+"'>"+title+"</span>\n"
		return ts + '\n'.join ("• " + item for item in items)
	s.__name__ = title
	data={'desc': body_font, 'align': pango.ALIGN_LEFT}
	slide (s, data)

def image_slide (f, width=600, height=600, imgwidth=0, imgheight=0, xoffset=0, yoffset=0, data=None):
	def s (r):
		r.move_to (400+xoffset, 300+yoffset)
		r.put_image (f, width=imgwidth, height=imgheight)
		x = (800 - width) * .5
		y = (600 - height) * .5
		r.set_allocation (x, y, width, height)
	s.__name__ = f
	slide (s, data)
	return s

def draw_image (r, f, width=600, height=600, imgwidth=0, imgheight=0, xoffset=0, yoffset=0, data=None):
	r.move_to (400+xoffset, 300+yoffset)
	r.put_image (f, width=imgwidth, height=imgheight)
	x = (800 - width) * .5
	y = (600 - height) * .5
	r.set_allocation (x, y, width, height)

def source_slide(s, lang):
	s = highlight(s, lang)
	s = "<span font_desc='"+mono_font+"'>" + s + "</span>"
	slide_heading (s, data={'align': pango.ALIGN_LEFT})

def python_slide(s):
	source_slide(s, lang="py")

def xml_slide(s):
	source_slide(s, lang="xml")

def patch_slide(s):
	lines = s.split ("\n")
	new_lines = []
	for s in lines:
		s = s.replace("&", "&amp;").replace("<", "&lt;")
		if not s: s = ' '
		if s[0] == '-':
			s = "<span fgcolor='#d00'>%s</span>" % s
		elif s[0] == '+':
			s = "<span fgcolor='#0a0'>%s</span>" % s
		elif s[0] != ' ':
			s = "<b>%s</b>" % s

		new_lines.append (s)

	s = '\n'.join (new_lines)
	s = "<span font_desc='"+mono_font+"'>" + s + "</span>"
	slide_heading (s, data={'align': pango.ALIGN_LEFT})

def commit_slide(s, who=None):
	lines = s.split ("\n")
	new_lines = []
	for s in lines:
		s = s.replace("&", "&amp;").replace("<", "&lt;")
		if not s: s = ' '
		if s[0] != ' ':
			s = "<b>%s</b>" % s

		new_lines.append (s)

	s = '\n'.join (new_lines)
	s = "<span font_desc='"+mono_font+"'>" + s + "</span>"
	if who:
		slide_heading (s, data={'align': pango.ALIGN_LEFT, 'who': who})
	else:
		slide_heading (s, data={'align': pango.ALIGN_LEFT})


#
# Slides start here
#

who (behdad)

@slide
def title_slide (r):
	r.move_to (960, 400)
	r.put_text ("<span font_desc='"+title_font+"' font_size='large'>OpenType GX</span>\n"+
		    "<span font_desc='"+subtitle_font+"' font_size='xx-small'>an exploratory proposal</span>",
		    valign=0, halign=0, desc=title_font+" 200")

	r.move_to (960, 800)
	r.put_text ("<span font_size='large' font_desc='"+mono_font+"' foreground='blue'>https://goo.gl/0N3zLy</span>\n\n"+
		    "Behdad Esfahbod\n<span font_size='x-small' font_desc='"+mono_font+"'>behdad@google.com</span>", desc=body_font+" 50", halign=0, valign=+1)

def agenda(i=None):
	items = [
	"Background",
	"Architecture",
	"Practicalities",
	"Proposal",
	"Implementation",
	"Possibilities",
	"Demos",
	"Discussion",
	]
	if i is not None:
		i = items.index(i)
		items[i] = "<span foreground='#444488'>%s</span>" % items[i]
	bullet_list_slide("Agenda", items)

agenda()

agenda('Background')
bullet_list_slide("Background", [
	"ATypI 2014 Barcelona",
	"Noto Phase III",
	"FontTools + Sascha = gvar",
	"FreeType + Adam = IUP",
	"Skia graphics + Skia font",
	"ATypI 2015: OpenType 2.0",
	"OpenType GX, the proposal",
	])

agenda('Architecture')
bullet_list_slide("Architecture", [
	"MM vs TrueType GX",
	"Copy some tables over",
	"Possibly extend (later)",
	"Extend OpenType tables",
	])
bullet_list_slide("Architecture", [
	"Non-invasive",
	"Existing workflows...\n"
	"  → Glyphs\n"
	"  → UFO+.designspace\n"
	"  → FontLab?"
	])

agenda('Practicalities')
bullet_list_slide("Practicalities", [
	"Overlap removal",
	"Cubic-to-quadratic",
	"CFF point numbers",
	"Extrapolation",
	])

agenda('Proposal')
bullet_list_slide("Proposal", [
	"Font variation metadata",
	"Glyph shape variation",
	"Font metrics variation",
	"Positioning variation",
	"Conditional subst &amp; pos",
	"Glyph metrics variation",
	"Hinting data variation",
	])

bullet_list_slide("Font var metadata", [
	"Apple 'fvar' table\n"
	"  → Arbitrary axes\n"
	"  → Named instances",
	"Apple 'avar' table\n"
	"  → MutatorMath Bender\n"
	"  → Luc(as) curve\n"
	"  → Pablo curve",
	"Clarify standard axes",
	])

bullet_list_slide("Glyph shape var", [
	"Apple 'gvar' table\n"
	"  → Arbitrary masters\n"
	"  → per glyph",
	"Apply to 'glyf' / CFF",
	])

bullet_list_slide("Font metrics var", [
	"Apple 'fmtx' table",
	"'fmtx' 2.0 for OS/2, etc",
	"No UPEM var allowed",
	])

bullet_list_slide("Positioning var", [
	"GPOS / GDEF",
	"Value / Anchor / Caret",
	"Device table\n"
	"  → VariationDevice",
	"Merger script",
	])

bullet_list_slide("Condi'nal subst &amp; pos", [
	"GSUB / GPOS",
	"Alternate lookups\n"
	"  → MutatorMath subst\n"
	"  → Glyphs 'bracket' trick",
	])

bullet_list_slide("Glyph metrics var", [
	"Needed for layout",
	"Performance",
	"New table for\n"
	"  → 'hmtx' vars\n"
	"  → 'vmtx' vars\n"
	"  → 'VORG' vars",
	])

bullet_list_slide("Hinting: TrueType", [
	"Apple 'cvar' table",
	"Extend ttfautohint",
	"FreeType autohinter",
	])
bullet_list_slide("Hinting: CFF", [
	"Hint op vars",
	"Extend AFDKO autohinter",
	"Run-time AFDKO hinter",
	])

agenda('Implementation')
slide_title("Implementation", (
	"fvar / avar / gvar / cvar\n"
	"  → Apple: OS X, iOS?\n"
	"  → FreeType (bug fixes)"
	))
slide_title("Implementation", (
	"fvar / avar / gvar / cvar\n"
	"  → FontTools\n"
	"    → varLib.__init__\n"
	"    → varLib.mutator"
	))
slide_title("Implementation", (
	"Combined with other tools\n"
	"  → UFO + .designspace\n"
	"  → Glyphs"
	))
slide_title("Implementation", (
	"GSUB / GPOS / GDEF\n"
	"  → Design\n"
	"  → Prototype"
	))

agenda('Possibilities')
source_slide("""
@font-face {
	font-family: MyFont;
	font-weight: 700;
	font-stretch: condensed;
	src: url("fonts/myvar.ttc#2,wght=1.4,wdth=0.7")
		format(collection,variation),
	     url("fonts/fallback-bold-cond.ttf"),
		format(truetype);
}
""", "css")
source_slide("""
@font-family {
	font-family: MyFont;
	src: url("myvar.ttf") format(truetype);
	font-weight-min: 100;
	font-weight-max: 500;
	font-stretch-min: 70;
	font-stretch-max: 130;
}
""", "css")
bullet_list_slide("Possibilities", [
	"Justification",
	"Animation",
	"Grading",
	"Tickling",
	"...",
	])

agenda('Demos')

agenda('Discussion')

bullet_list_slide("Links", [
	"https://github.com/behdad/fonttools",
	"https://github.com/googlei18n/fontmake",
	"https://groups.google.com/forum/#!forum/fonttools",
])

slide("<b>Q?</b>", data={"desc":title_font})

if __name__ == "__main__":
	import slippy
	import opentypegx_theme
	slippy.main (slides, opentypegx_theme, args=['--geometry', '1920x1200'])