-
Notifications
You must be signed in to change notification settings - Fork 12
/
glyphs.ml
162 lines (149 loc) · 5.62 KB
/
glyphs.ml
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
(*---------------------------------------------------------------------------
Copyright (c) 2013 The vg programmers. All rights reserved.
SPDX-License-Identifier: ISC
---------------------------------------------------------------------------*)
open Gg
open Vg
;;
(** Test images for glyphs. *)
let open_sans_xbold =
{ Font.name = "Open Sans"; size = 1.0; weight = `W800; slant = `Normal}
(* Font info for the string "Revolt!" as found in Open_sans.extra_bold. *)
let glyphs = [ 53; 72; 89; 82; 79; 87; 4 ]
let advances = [1386.; 1266.; 1251.; 1305.; 662.; 942.; 594.;]
let u_to_em = 2048.
;;
Db.image "glyph-revolt" __POS__ ~author:Db.dbuenzli
~title:"Revolt in black"
~tags:["glyph"]
~note:"Black characters “Revolt!”, approximatively centered \
in the image."
~size:(Size2.v 135. 45.)
~view:(Box2.v P2.o (Size2.v 3. 1.))
begin fun _ ->
let font = { open_sans_xbold with Font.size = 0.7 } in
let text = "Revolt!" in
I.const Color.black |> I.cut_glyphs ~text font glyphs |>
I.move (V2.v 0.23 0.25)
end;
Db.image "glyph-revolt-outline" __POS__ ~author:Db.dbuenzli
~title:"Revolt outline in black"
~tags:["glyph"]
~note:"Black outlined characters “Revolt!”, approximatively centered \
in the image with bevel path joins."
~size:(Size2.v 135. 45.)
~view:(Box2.v P2.o (Size2.v 3. 1.))
begin fun _ ->
let font = { open_sans_xbold with Font.size = 0.7 } in
let area = `O { P.o with P.width = 0.03; join = `Bevel } in
let text = "Revolt!" in
I.const Color.black |> I.cut_glyphs ~area ~text font glyphs |>
I.move (V2.v 0.23 0.25)
end;
Db.image "glyph-revolt-fade" __POS__ ~author:Db.dbuenzli
~title:"Revolt from black to white"
~tags:["glyph"; "gradient" ]
~note:"Characters “Revolt!”, approximatively centered \
in the image and fading from black to white"
~size:(Size2.v 135. 45.)
~view:(Box2.v P2.o (Size2.v 3. 1.))
begin fun _ ->
let font = { open_sans_xbold with Font.size = 0.7 } in
let text = "Revolt!" in
let stops = [0.0, Color.black; 1.0, Color.white] in
I.axial stops P2.o (P2.v 3. 0.) |> I.cut_glyphs ~text font glyphs |>
I.move (V2.v 0.23 0.25)
end;
Db.image "glyph-aspect" __POS__ ~author:Db.dbuenzli
~title:"Glyph aspect"
~tags:["glyph"]
~note:"The character should read “R”, without distortion."
~size:(Size2.v 25. 50.)
~view:(Box2.v P2.o (Size2.v 2. 1.))
begin fun _ ->
let font = { open_sans_xbold with Font.size = 0.5 } in
let text = "R" in
let sq = P.empty |> P.rect (Box2.v (P2.v 0. 0.75) (P2.v 0.25 0.25)) in
I.const Color.black |> I.cut sq |>
I.blend (I.const Color.black |> I.cut_glyphs ~text font [53;]) |>
I.scale (V2.v 4.0 1.0)
end;
Db.image "glyph-multi" __POS__ ~author:Db.dbuenzli
~title:"Multiple revolts"
~tags:["glyph"]
~note:"Rectangle filled with revolts rotated by 30°."
~size:(Size2.v 108. 135.)
~view:(Box2.v P2.o (P2.v 0.8 1.0))
begin fun view ->
let font = { open_sans_xbold with Font.size = 0.025 } in
let text = "Revolt!" in
let angle = Float.rad_of_deg 30. in
let revolt pos =
I.const Color.black |> I.cut_glyphs ~text font glyphs |>
I.move pos
in
let next max dv pt =
if V2.x pt < V2.x max then Some (V2.v (V2.x pt +. V2.x dv) (V2.y pt)) else
let y = V2.y pt +. V2.y dv in
if y > V2.y max then None else Some (V2.v 0. y)
in
let max = V2.v 1.3 1.3 in
let dv = V2.v 0.11 0.03 in
let rec blend_revolt acc = function
| None -> acc
| Some pt -> blend_revolt (acc |> I.blend (revolt pt)) (next max dv pt)
in
let margin =
let area = `O { P.o with P.width = 0.1 } in
I.const Color.white |> I.cut ~area (P.empty |> P.rect view)
in
blend_revolt (I.const Color.white) (Some P2.o) |> I.rot angle |>
I.move (P2.v 0.2 (-. sin (angle))) |>
I.blend margin
end;
Db.image "glyph-advances" __POS__ ~author:Db.dbuenzli
~title:"Advancing revolt"
~tags:["glyph"]
~note:"First line, no advances specified. Second line advances with glyph
advances, should render same as first line. Third line, funky glyph
advances with up and down."
~size:(Size2.v 135. (45. *. 3.))
~view:(Box2.v P2.o (Size2.v 3. 3.))
begin fun _ ->
let fsize = 0.7 in
let font = { open_sans_xbold with Font.size = fsize } in
let text = "Revolt!" in
let black = I.const Color.black in
let ypos n = V2.v 0.23 (0.25 +. n *. 0.98) in
let no_advances = I.cut_glyphs ~text font glyphs in
let adv_advances =
let adv a = V2.v ((a *. fsize) /. u_to_em) 0. in
I.cut_glyphs ~text ~advances:(List.map adv advances) font glyphs
in
let funky_advances =
let adv i a =
V2.v ((a *. fsize) /. u_to_em) (if i mod 2 = 0 then 0.2 else -0.2)
in
I.cut_glyphs ~text ~advances:(List.mapi adv advances) font glyphs
in
black |> funky_advances |> I.move (ypos 0.) |>
I.blend (black |> adv_advances |> I.move (ypos 1.)) |>
I.blend (black |> no_advances |> I.move (ypos 2.))
end
;;
Db.image "glyph-affiche-blocks" __POS__ ~author:Db.dbuenzli
~title:"Affiché with ligature and text to glyph correspondence"
~tags:["glyph"]
~note:"The ffi is a single glyph and the é glyph is encoded as the sequence
<U+0065, U+0301> in the text string."
~size:(Size2.v 135. 45.)
~view:(Box2.v P2.o (Size2.v 3. 1.))
begin fun _ ->
let font = { open_sans_xbold with Font.size = 0.7 } in
let glyphs = [ 36; 605; 70; 75; 171 ] in
let text = "Affiche\xCC\x81" in
let blocks = false, [(1,1); (3,1); (1,1); (1,1); (2,1)] in
I.const Color.black |> I.cut_glyphs ~text ~blocks font glyphs |>
I.move (V2.v 0.23 0.25)
end
;;