-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathtest-base_font.R
113 lines (89 loc) · 3.75 KB
/
test-base_font.R
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
testsetup()
test_that("get_base_font works", {
wb <- wb_workbook()
expect_equal(
wb$get_base_font(),
list(
size = list(val = "11"),
# should this be "#000000"?
color = list(theme = "1"),
name = list(val = "Aptos Narrow")
)
)
wb$set_base_font(fontSize = 9, fontName = "Arial", fontColour = wb_colour("red"))
expect_equal(
wb$get_base_font(),
list(
size = list(val = "9"),
color = list(rgb = "FFFF0000"),
name = list(val = "Arial")
)
)
})
test_that("wb_set_base_font() actually alters the base font", {
wb <- wb_workbook()$add_worksheet()
# per default a workbook has no theme until it is written
fS <- xml_node(wb$theme, "a:theme", "a:themeElements", "a:fontScheme")
expect_equal(character(), fS)
# if we alter the base font, a theme is created
wb$set_base_font(font_name = "Calibri")
fS <- xml_node(wb$theme, "a:theme", "a:themeElements", "a:fontScheme")
exp <- "<a:latin typeface=\"Calibri\" panose=\"020F0502020204030204\"/>"
got <- xml_node(fS, "a:fontScheme", "a:majorFont", "a:latin")
expect_equal(exp, got)
got <- xml_node(fS, "a:fontScheme", "a:minorFont", "a:latin")
expect_equal(exp, got)
# if we request a theme, this is present
wb <- wb_workbook(theme = "Old Office Theme")$add_worksheet()
fS <- xml_node(wb$theme, "a:theme", "a:themeElements", "a:fontScheme")
exp <- "<a:latin typeface=\"Cambria\"/>"
got <- xml_node(fS, "a:fontScheme", "a:majorFont", "a:latin")
expect_equal(exp, got)
exp <- "<a:latin typeface=\"Calibri\"/>"
got <- xml_node(fS, "a:fontScheme", "a:minorFont", "a:latin")
expect_equal(exp, got)
# this can also be altered
wb$set_base_font(font_name = "Aptos Narrow")
fS <- xml_node(wb$theme, "a:theme", "a:themeElements", "a:fontScheme")
exp <- "<a:latin typeface=\"Aptos Narrow\" panose=\"020B0004020202020204\"/>"
got <- xml_node(fS, "a:fontScheme", "a:majorFont", "a:latin")
expect_equal(exp, got)
got <- xml_node(fS, "a:fontScheme", "a:minorFont", "a:latin")
expect_equal(exp, got)
wb$set_base_font(font_name = "Calibri")
fS <- xml_node(wb$theme, "a:theme", "a:themeElements", "a:fontScheme")
# only the font_size is altered
wb <- wb_workbook()$add_worksheet()$set_base_font(font_size = 16)
fS <- xml_node(wb$theme, "a:theme", "a:themeElements", "a:fontScheme")
expect_equal(character(), fS)
# custom panose values are possible
wb <- wb_workbook()$
set_base_font(font_name = "Monaco", font_panose = "xxxxxxxxxxxxxx")
fS <- xml_node(wb$theme, "a:theme", "a:themeElements", "a:fontScheme")
exp <- "<a:latin typeface=\"Monaco\" panose=\"xxxxxxxxxxxxxx\"/>"
got <- xml_node(fS, "a:fontScheme", "a:majorFont", "a:latin")
expect_equal(exp, got)
got <- xml_node(fS, "a:fontScheme", "a:minorFont", "a:latin")
expect_equal(exp, got)
# different font types are possible for panose, not sure how useful this is
wb <- wb_workbook()$
set_base_font(font_name = "Arial", font_type = "Italic")
fS <- xml_node(wb$theme, "a:theme", "a:themeElements", "a:fontScheme")
exp <- "<a:latin typeface=\"Arial\" panose=\"020B0604020202090204\"/>"
got <- xml_node(fS, "a:fontScheme", "a:majorFont", "a:latin")
expect_equal(exp, got)
got <- xml_node(fS, "a:fontScheme", "a:minorFont", "a:latin")
expect_equal(exp, got)
})
test_that("hyperlink font size works", {
wb <- wb_workbook()$
set_base_font(font_size = 13, font_name = "Monaco")$
add_worksheet()$
add_formula(x = create_hyperlink(text = "foo", file = "bar"))
exp <- c(
"<font><color theme=\"1\"/><family val=\"2\"/><name val=\"Monaco\"/><scheme val=\"minor\"/><sz val=\"13\"/></font>",
"<font><color theme=\"10\"/><name val=\"Monaco\"/><sz val=\"13\"/><u val=\"single\"/></font>"
)
got <- wb$styles_mgr$styles$fonts
expect_equal(exp, got)
})