-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTextOtf.cpp
More file actions
220 lines (185 loc) · 7.64 KB
/
TextOtf.cpp
File metadata and controls
220 lines (185 loc) · 7.64 KB
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
/*
* Copyright (c) 2026 ThorVG project. All rights reserved.
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "Example.h"
/************************************************************************/
/* ThorVG Drawing Contents */
/************************************************************************/
struct UserExample : tvgexam::Example
{
bool content(tvg::Canvas* canvas, uint32_t w, uint32_t h) override
{
//Background
auto shape = tvg::Shape::gen();
shape->appendRect(0, 0, w, h);
shape->fill(75, 75, 75);
canvas->add(shape);
//Load a necessary font data.
//The loaded font will be released when the Initializer::term() is called.
//Otherwise, you can immediately unload the font data.
//Please check Text::unload() APIs.
if (!tvgexam::verify(tvg::Text::load(EXAMPLE_DIR"/font/DMSans.otf"))) return false;
if (!tvgexam::verify(tvg::Text::load(EXAMPLE_DIR"/font/Pretendard.otf"))) return false;
if (!tvgexam::verify(tvg::Text::load(EXAMPLE_DIR"/font/NanumGothicCoding.otf"))) return false;
//Load from memory
ifstream file(EXAMPLE_DIR"/font/SentyCloud.otf", ios::binary);
if (!file.is_open()) return false;
file.seekg(0, std::ios::end);
auto size = file.tellg();
file.seekg(0, std::ios::beg);
auto data = (char*)malloc(size);
if (data && file.read(data, size)) {
if (!tvgexam::verify(tvg::Text::load("SentyCloud", data, size, "otf", true))) return false;
}
file.close();
free(data);
auto text = tvg::Text::gen();
text->font("DMSans");
text->size(60);
text->text("THORVG OpenType Font");
text->fill(255, 255, 255);
canvas->add(text);
auto text2 = tvg::Text::gen();
text2->font("DMSans");
text2->size(30);
text2->italic();
text2->text("Font = \"DMSans\", Size = 30, Style = Italic");
text2->translate(0, 120);
text2->fill(255, 255, 255);
canvas->add(text2);
auto text3 = tvg::Text::gen();
text3->font(nullptr); //Use any font
text3->size(40);
text3->text("Kerning Test: VA, AV, TJ, JT");
text3->fill(255, 255, 255);
text3->translate(0, 195);
canvas->add(text3);
auto text4 = tvg::Text::gen();
text4->font("DMSans");
text4->size(25);
text4->text("Purple Text");
text4->fill(255, 0, 255);
text4->translate(0, 280);
canvas->add(text4);
auto text5 = tvg::Text::gen();
text5->font("DMSans");
text5->size(25);
text5->text("Gray Text");
text5->fill(150, 150, 150);
text5->translate(220, 280);
canvas->add(text5);
auto text6 = tvg::Text::gen();
text6->font("DMSans");
text6->size(25);
text6->text("Yellow Text");
text6->fill(255, 255, 0);
text6->translate(400, 280);
canvas->add(text6);
auto text7 = tvg::Text::gen();
text7->font("Pretendard");
text7->size(15);
text7->text("Transformed Text - 30'");
text7->fill(0, 0, 0);
text7->translate(600, 370);
text7->rotate(30);
canvas->add(text7);
auto text8 = tvg::Text::gen();
text8->font("Pretendard");
text8->size(15);
text8->fill(0, 0, 0);
text8->text("Transformed Text - 90'");
text8->translate(600, 370);
text8->rotate(90);
canvas->add(text8);
auto text9 = tvg::Text::gen();
text9->font("Pretendard");
text9->size(15);
text9->fill(0, 0, 0);
text9->text("Transformed Text - 180'");
text9->translate(800, 370);
text9->rotate(180);
canvas->add(text9);
//gradient texts
float x, y, w2, h2;
auto text10 = tvg::Text::gen();
text10->font("Pretendard");
text10->size(50);
text10->text("Linear Text");
text10->bounds(&x, &y, &w2, &h2);
//LinearGradient
auto fill = tvg::LinearGradient::gen();
fill->linear(x, y + h2 * 0.5f, x + w2, y + h2 * 0.5f);
//Gradient Color Stops
tvg::Fill::ColorStop colorStops[3];
colorStops[0] = {0, 255, 0, 0, 255};
colorStops[1] = {0.5, 255, 255, 0, 255};
colorStops[2] = {1, 255, 255, 255, 255};
fill->colorStops(colorStops, 3);
text10->fill(fill);
text10->translate(0, 320);
canvas->add(text10);
auto text11 = tvg::Text::gen();
text11->font("NanumGothicCoding");
text11->size(40);
text11->text("\xeb\x82\x98\xeb\x88\x94\xea\xb3\xa0\xeb\x94\x95\xec\xbd\x94\xeb\x94\xa9\x28\x55\x54\x46\x2d\x38\x29");
text11->bounds(&x, &y, &w2, &h2);
//RadialGradient
auto fill2 = tvg::RadialGradient::gen();
fill2->radial(x + w2 * 0.5f, y + h2 * 0.5f, w2 * 0.5f, x + w2 * 0.5f, y + h2 * 0.5f, 0.0f);
//Gradient Color Stops
tvg::Fill::ColorStop colorStops2[3];
colorStops2[0] = {0, 0, 255, 255, 255};
colorStops2[1] = {0.5, 255, 255, 0, 255};
colorStops2[2] = {1, 255, 255, 255, 255};
fill2->colorStops(colorStops2, 3);
text11->fill(fill2);
text11->translate(0, 420);
canvas->add(text11);
auto text12 = tvg::Text::gen();
text12->font("SentyCloud");
text12->size(50);
text12->fill(255, 25, 25);
text12->outline(3, 255, 200, 200);
text12->text("\xe4\xb8\x8d\xe5\x88\xb0\xe9\x95\xbf\xe5\x9f\x8e\xe9\x9d\x9e\xe5\xa5\xbd\xe6\xb1\x89\xef\xbc\x81");
text12->translate(0, 495);
canvas->add(text12);
auto text13 = tvg::Text::gen();
text13->font("DMSans");
text13->size(20);
text13->fill(255, 255, 255);
text13->text("LINE-FEED TEST. THIS IS THE FIRST LINE - \nTHIS IS THE SECOND LINE.");
text13->translate(0, 595);
canvas->add(text13);
auto text14 = tvg::Text::gen();
text14->font("DMSans");
text14->size(20);
text14->fill(255, 255, 255);
text14->spacing(1.5f, 1.5f);
text14->text("1.5x SPACING TEST. THIS IS THE FIRST LINE - \nTHIS IS THE SECOND LINE.");
text14->translate(0, 670);
canvas->add(text14);
return true;
}
};
/************************************************************************/
/* Entry Point */
/************************************************************************/
int main(int argc, char **argv)
{
return tvgexam::main(new UserExample, argc, argv, false, 1024, 1024);
}