File: fontdiff

package info (click to toggle)
fonts-fantasque-sans 1.7.2~alpha.3~dfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 17,084 kB
  • sloc: sh: 213; python: 149; makefile: 24
file content (113 lines) | stat: -rwxr-xr-x 2,227 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/env bash

# Generate a webpage that allows the comparison of two fonts.
# Pass TTF font files as arguments

if ! type fontforge &> /dev/null; then echo "ERROR: Missing dependency: fontforge" 1>&2; exit 1; fi

OUTPUT="fontdiff.html"

cat > "$OUTPUT" <<EOF
<!DOCTYPE html>
<html>
<head>
<title>Fontdiff $1 vs. $2</title>
<style>
EOF

fontfacedecl() {
  base64=$(base64 --wrap=0 "$1")
  cat >> "$OUTPUT" <<EOF
@font-face {
  font-family: '$2';
  src: url('data:font/ttf;base64,$base64') format('truetype');
}
EOF
}

fontfacedecl "$1" font1
fontfacedecl "$2" font2

cat >> "$OUTPUT" <<EOF
h1 {
font-weight: normal;
}

div {
  float: left;
  width: 150px;
  text-align: center;
}
div.font2 {
  margin-left: -150px;
}

pre.glyph {
  margin: 0;
  font-size: 140px;
  line-height: 200px;
}

pre.blank-glyph {
  height: 200px;
}

.font1 {
  color: rgba(255, 0, 0, 0.5);
}
.font2 {
  color: rgba(0, 0, 255, 0.5);
}

.font1 .glyph, h1.font1 {
  font-family: font1;
}
.font2 .glyph, h1.font2 {
  font-family: font2;
}

</style>
</head>
<body>
<h1 class="font1">$1</h1>
<h1 class="font2">$2</h1>
EOF

# Use fontforge to list available glyphs of each font
fontforge -lang=py -script - >> "$OUTPUT" <<EOF
import fontforge;

def print_glyph(_class, glyph):
  if glyph and glyph.unicode > 0:
    print '<div class="font%s"><pre class="glyph">&#%s;</pre><div class="name">%s</div></div>'%(_class, glyph.unicode, glyph.glyphname)
  else:
    print '<div class="font%s"><pre class="glyph blank-glyph"></pre><div class="name"></div></div>'%(_class)

font1 = fontforge.open("$1");
font2 = fontforge.open("$2");

glyphs1 = sorted(font1.glyphs(), key = lambda g: g.unicode)
glyphs2 = sorted(font2.glyphs(), key = lambda g: g.unicode)

while glyphs1 and glyphs2:
  if glyphs1[0].unicode > glyphs2[0].unicode: 
    print_glyph(1, None)
    print_glyph(2, glyphs2.pop(0))
  elif glyphs1[0].unicode < glyphs2[0].unicode:
    print_glyph(1, glyphs1.pop(0))
    print_glyph(2, None)
  else:
    print_glyph(1, glyphs1.pop(0))
    print_glyph(2, glyphs2.pop(0))

while glyphs1 or glyphs2:
  print_glyph(1, glyphs1.pop(0) if glyphs1 else None)
  print_glyph(2, glyphs2.pop(0) if glyphs2 else None)

EOF

cat >> "$OUTPUT" <<EOF
</body>
</html>

EOF