Vuo
2.4.4
Loading...
Searching...
No Matches
type
VuoFont.c
Go to the documentation of this file.
1
10
#include <math.h>
11
#include <stdlib.h>
12
#include <string.h>
13
#include "
VuoFont.h
"
14
16
#ifdef VUO_COMPILER
17
VuoModuleMetadata
({
18
"title"
:
"Font"
,
19
"description"
:
"A font description: family, style, point size, underline."
,
20
"keywords"
: [
"text"
,
"style"
,
"bold"
,
"italic"
,
"sans"
,
"serif"
,
"monospace"
,
"kerning"
,
"spacing"
,
"double-space"
,
"alignment"
,
"left"
,
"center"
,
"right"
],
21
"version"
:
"1.0.0"
,
22
"dependencies"
: [
23
"VuoBoolean"
,
24
"VuoColor"
,
25
"VuoHorizontalAlignment"
,
26
"VuoInteger"
,
27
"VuoReal"
,
28
"VuoText"
29
]
30
});
31
#endif
33
37
VuoFont
VuoFont_make
(
VuoText
fontName,
VuoReal
pointSize,
VuoBoolean
underline,
VuoColor
color,
VuoHorizontalAlignment
alignment,
VuoReal
characterSpacing,
VuoReal
lineSpacing)
38
{
39
VuoFont
f;
40
f.
fontName
= fontName;
41
f.pointSize = pointSize;
42
f.underline = underline;
43
f.color = color;
44
f.alignment = alignment;
45
f.
characterSpacing
= characterSpacing;
46
f.
lineSpacing
= lineSpacing;
47
return
f;
48
}
49
55
VuoFont
VuoFont_makeDefault
(
void
)
56
{
57
return
(
VuoFont
) { NULL, 18,
false
, (
VuoColor
){1,1,1,1}, VuoHorizontalAlignment_Center, 1, 1 };
58
}
59
64
VuoFont
VuoFont_makeFromJson
(json_object * js)
65
{
66
return
(
VuoFont
){
67
VuoJson_getObjectValue
(
VuoText
, js,
"fontName"
, NULL),
68
VuoJson_getObjectValue
(
VuoReal
, js,
"pointSize"
, 0),
69
VuoJson_getObjectValue
(
VuoBoolean
, js,
"underline"
,
false
),
70
VuoJson_getObjectValue
(
VuoColor
, js,
"color"
, (
VuoColor
){1,1,1,1}),
71
VuoJson_getObjectValue
(
VuoHorizontalAlignment
, js,
"alignment"
, VuoHorizontalAlignment_Left),
72
VuoJson_getObjectValue
(
VuoReal
, js,
"characterSpacing"
, 1),
73
VuoJson_getObjectValue
(
VuoReal
, js,
"lineSpacing"
, 1)
74
};
75
}
76
81
json_object *
VuoFont_getJson
(
const
VuoFont
value)
82
{
83
json_object *js = json_object_new_object();
84
json_object_object_add(js,
"fontName"
,
VuoText_getJson
(value.
fontName
));
85
json_object_object_add(js,
"pointSize"
,
VuoReal_getJson
(value.pointSize));
86
json_object_object_add(js,
"underline"
,
VuoBoolean_getJson
(value.underline));
87
json_object_object_add(js,
"color"
,
VuoColor_getJson
(value.color));
88
json_object_object_add(js,
"alignment"
,
VuoHorizontalAlignment_getJson
(value.alignment));
89
json_object_object_add(js,
"characterSpacing"
,
VuoReal_getJson
(value.
characterSpacing
));
90
json_object_object_add(js,
"lineSpacing"
,
VuoReal_getJson
(value.
lineSpacing
));
91
return
js;
92
}
93
98
char
*
VuoFont_getSummary
(
const
VuoFont
value)
99
{
100
const
char
*fontName = value.
fontName
? value.
fontName
:
"No font"
;
101
const
char
*underline = value.underline ?
"<li>underlined</li>"
:
""
;
102
char
*color =
VuoColor_getShortSummary
(value.color);
103
char
*alignment =
VuoHorizontalAlignment_getSummary
(value.alignment);
104
105
char
*summary =
VuoText_format
(
"%s %gpt<ul><li>color %s</li>%s<li>%s-aligned</li><li>character spacing: %g</li><li>line spacing: %g</li></ul>"
,
106
fontName, value.pointSize, color, underline, alignment, value.
characterSpacing
, value.
lineSpacing
);
107
108
free(color);
109
free(alignment);
110
return
summary;
111
}
112
116
bool
VuoFont_areEqual
(
const
VuoFont
value1,
const
VuoFont
value2)
117
{
118
return
VuoText_areEqual
(value1.
fontName
, value2.
fontName
)
119
&&
VuoReal_areEqual
(value1.pointSize, value2.pointSize)
120
&& (value1.underline == value2.underline)
121
&&
VuoColor_areEqual
(value1.color, value2.color)
122
&& (value1.alignment == value2.alignment)
123
&&
VuoReal_areEqual
(value1.
characterSpacing
, value2.
characterSpacing
)
124
&&
VuoReal_areEqual
(value1.
lineSpacing
, value2.
lineSpacing
);
125
}
126
130
bool
VuoFont_isLessThan
(
const
VuoFont
a,
const
VuoFont
b)
131
{
132
VuoType_returnInequality
(
VuoText
, a.
fontName
, b.
fontName
);
133
VuoType_returnInequality
(
VuoReal
, a.pointSize, b.pointSize);
134
VuoType_returnInequality
(
VuoBoolean
, a.underline, b.underline);
135
VuoType_returnInequality
(
VuoColor
, a.color, b.color);
136
VuoType_returnInequality
(
VuoHorizontalAlignment
, a.alignment, b.alignment);
137
VuoType_returnInequality
(
VuoReal
, a.
characterSpacing
, b.
characterSpacing
);
138
VuoType_returnInequality
(
VuoReal
, a.
lineSpacing
, b.
lineSpacing
);
139
return
false
;
140
}
Generated on Thu Nov 9 2023 16:59:30 for Vuo by
1.9.8