-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
Copy pathfont_attributes.js
121 lines (110 loc) · 3.86 KB
/
font_attributes.js
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
'use strict';
/*
* make a font attribute group
*
* @param {object} opts
* @param {string}
* opts.description: where & how this font is used
* @param {optional bool} arrayOk:
* should each part (family, size, color) be arrayOk? default false.
* @param {string} editType:
* the editType for all pieces of this font
* @param {optional string} colorEditType:
* a separate editType just for color
*
* @return {object} attributes object containing {family, size, color} as specified
*/
module.exports = function(opts) {
var variantValues = opts.variantValues;
var editType = opts.editType;
var colorEditType = opts.colorEditType;
if(colorEditType === undefined) colorEditType = editType;
var weight = {
editType: editType,
valType: 'integer',
min: 1,
max: 1000,
extras: ['normal', 'bold'],
dflt: 'normal',
description: [
'Sets the weight (or boldness) of the font.'
].join(' ')
};
if(opts.noNumericWeightValues) {
weight.valType = 'enumerated';
weight.values = weight.extras;
weight.extras = undefined;
weight.min = undefined;
weight.max = undefined;
}
var attrs = {
family: {
valType: 'string',
noBlank: true,
strict: true,
editType: editType,
description: [
'HTML font family - the typeface that will be applied by the web browser.',
'The web browser will only be able to apply a font if it is available on the system',
'which it operates. Provide multiple font families, separated by commas, to indicate',
'the preference in which to apply fonts if they aren\'t available on the system.',
'The Chart Studio Cloud (at https://chart-studio.plotly.com or on-premise) generates images on a server,',
'where only a select number of',
'fonts are installed and supported.',
'These include *Arial*, *Balto*, *Courier New*, *Droid Sans*,, *Droid Serif*,',
'*Droid Sans Mono*, *Gravitas One*, *Old Standard TT*, *Open Sans*, *Overpass*,',
'*PT Sans Narrow*, *Raleway*, *Times New Roman*.'
].join(' ')
},
size: {
valType: 'number',
min: 1,
editType: editType
},
color: {
valType: 'color',
editType: colorEditType
},
weight: weight,
style: {
editType: editType,
valType: 'enumerated',
values: ['normal', 'italic'],
dflt: 'normal',
description: [
'Sets whether a font should be styled with a normal or italic face from its family.'
].join(' ')
},
variant: opts.noFontVariant ? undefined : {
editType: editType,
valType: 'enumerated',
values: variantValues || [
'normal',
'small-caps',
'all-small-caps',
'all-petite-caps',
'petite-caps',
'unicase'
],
dflt: 'normal',
description: [
'Sets the variant of the font.'
].join(' ')
},
editType: editType,
// blank strings so compress_attributes can remove
// TODO - that's uber hacky... better solution?
description: '' + (opts.description || '') + ''
};
if(opts.autoSize) attrs.size.dflt = 'auto';
if(opts.autoColor) attrs.color.dflt = 'auto';
if(opts.arrayOk) {
attrs.family.arrayOk = true;
attrs.weight.arrayOk = true;
attrs.style.arrayOk = true;
attrs.variant.arrayOk = true;
attrs.size.arrayOk = true;
attrs.color.arrayOk = true;
}
return attrs;
};