-
Notifications
You must be signed in to change notification settings - Fork 1
/
extrafonts.go
99 lines (91 loc) · 2.57 KB
/
extrafonts.go
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
// # Extra fonts
//
// Add additional fonts.
package patches
import (
"io"
"github.com/pgaskin/lithiumpatch/fonts"
. "github.com/pgaskin/lithiumpatch/patches/patchdef"
)
func init() {
Register("extrafonts", extrafonts{})
}
type extrafonts struct{}
func (extrafonts) Do(apk string, diffwriter io.Writer) error {
xs := fonts.All()
if len(xs) == 0 {
return nil
}
var pt []Instruction
for _, f := range xs {
if f.Regular != nil {
pt = append(pt, WriteFile("assets/fonts/"+f.Base+"-Regular.ttf", f.Regular))
}
if f.Bold != nil {
pt = append(pt, WriteFile("assets/fonts/"+f.Base+"-Bold.ttf", f.Bold))
}
if f.Italic != nil {
pt = append(pt, WriteFile("assets/fonts/"+f.Base+"-Italic.ttf", f.Italic))
}
if f.BoldItalic != nil {
pt = append(pt, WriteFile("assets/fonts/"+f.Base+"-BoldItalic.ttf", f.BoldItalic))
}
}
pt = append(pt, PatchFile("smali/com/faultexception/reader/fonts/Fonts.smali",
InMethod("<clinit>()V",
ReplaceStringAppend(
FixIndent("\n"+`
invoke-static {v0}, Ljava/util/Arrays;->asList([Ljava/lang/Object;)Ljava/util/List;
move-result-object v0
`),
FixIndent("\n"+`
new-instance v1, Ljava/util/ArrayList;
invoke-direct {v1, v0}, Ljava/util/ArrayList;-><init>(Ljava/util/Collection;)V
move-object v0, v1
invoke-static {v0}, Lcom/faultexception/reader/fonts/Fonts;->initCustomFonts(Ljava/util/ArrayList;)V
`),
),
),
AppendString(
FixIndent(ExecuteTemplate("\n"+`
.method private static initCustomFonts(Ljava/util/ArrayList;)V
.locals 7
{{range .}}
const-string v1, "{{.Name}}"
{{if .Regular -}}
const-string v2, "{{.Base}}-Regular.ttf"
{{- else -}}
const/4 v2, 0x0
{{- end}}
{{if .Bold -}}
const-string v3, "{{.Base}}-Bold.ttf"
{{- else -}}
const/4 v3, 0x0
{{- end}}
{{if .Italic -}}
const-string v4, "{{.Base}}-Italic.ttf"
{{- else -}}
const/4 v4, 0x0
{{- end}}
{{if .BoldItalic -}}
const-string v5, "{{.Base}}-BoldItalic.ttf"
{{- else -}}
const/4 v5, 0x0
{{- end}}
const/4 v6, {{.Script.Flags | printf "%#x"}} # {{.Script}}
new-instance v0, Lcom/faultexception/reader/fonts/Font;
invoke-direct/range {v0 .. v6}, Lcom/faultexception/reader/fonts/Font;-><init>(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;I)V
invoke-virtual {p0, v0}, Ljava/util/ArrayList;->add(Ljava/lang/Object;)Z
{{end}}
return-void
.end method
`, xs)),
),
))
for _, x := range pt {
if err := x.Do(apk, diffwriter); err != nil {
return err
}
}
return nil
}