Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.desktop/macosx/native/libawt_lwawt/font/CGGlyphOutlines.m
41152 views
1
/*
2
* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation. Oracle designates this
8
* particular file as subject to the "Classpath" exception as provided
9
* by Oracle in the LICENSE file that accompanied this code.
10
*
11
* This code is distributed in the hope that it will be useful, but WITHOUT
12
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14
* version 2 for more details (a copy is included in the LICENSE file that
15
* accompanied this code).
16
*
17
* You should have received a copy of the GNU General Public License version
18
* 2 along with this work; if not, write to the Free Software Foundation,
19
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20
*
21
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22
* or visit www.oracle.com if you need additional information or have any
23
* questions.
24
*/
25
26
#import "CGGlyphOutlines.h"
27
28
static void
29
AWTPathGetMoreSpaceIfNecessary(AWTPathRef path)
30
{
31
while ((path->fAllocatedSegmentTypeSpace - path->fNumberOfSegments) < 1) {
32
size_t growth = sizeof(jbyte)*path->fAllocatedSegmentTypeSpace*kStorageSizeChangeOnGetMoreFactor;
33
path->fSegmentType = (jbyte*) realloc(path->fSegmentType, growth);
34
path->fAllocatedSegmentTypeSpace *= kStorageSizeChangeOnGetMoreFactor;
35
}
36
37
while ((path->fAllocatedSegmentDataSpace - path->fNumberOfDataElements) < 7) {
38
size_t growth = sizeof(jfloat)*path->fAllocatedSegmentDataSpace*kStorageSizeChangeOnGetMoreFactor;
39
path->fSegmentData = (jfloat*) realloc(path->fSegmentData, growth);
40
path->fAllocatedSegmentDataSpace *= kStorageSizeChangeOnGetMoreFactor;
41
}
42
}
43
44
static void
45
AWTPathMoveTo(void* data, CGPoint p)
46
{
47
CGFloat x = p.x;
48
CGFloat y = p.y;
49
50
AWTPathRef path = (AWTPathRef)data;
51
CGFloat tx = path->fTranslate.width;
52
CGFloat ty = path->fTranslate.height;
53
CGFloat pathX = x+tx;
54
CGFloat pathY = -y+ty;
55
56
#ifdef AWT_GV_DEBUG
57
fprintf(stderr, "eMoveTo \n");
58
fprintf(stderr, " tx=%f, ty=%f\n", tx, ty);
59
fprintf(stderr, " x=%f, y=%f\n", x, y);
60
fprintf(stderr, " pathX=%f, pathY=%f\n", pathX, pathY);
61
#endif
62
63
AWTPathGetMoreSpaceIfNecessary(path);
64
65
path->fSegmentType[path->fNumberOfSegments++] = (jbyte)eMoveTo;
66
67
path->fSegmentData[path->fNumberOfDataElements++] = pathX;
68
path->fSegmentData[path->fNumberOfDataElements++] = pathY;
69
}
70
71
static void
72
AWTPathLineTo(void* data, CGPoint p)
73
{
74
CGFloat x = p.x;
75
CGFloat y = p.y;
76
77
AWTPathRef path = (AWTPathRef)data;
78
CGFloat tx = path->fTranslate.width;
79
CGFloat ty = path->fTranslate.height;
80
CGFloat pathX = x+tx;
81
CGFloat pathY = -y+ty;
82
83
#ifdef AWT_GV_DEBUG
84
fprintf(stderr, "eLineTo \n");
85
fprintf(stderr, " tx=%f, ty=%f\n", tx, ty);
86
fprintf(stderr, " x=%f, y=%f\n", x, y);
87
fprintf(stderr, " pathX=%f, pathY=%f\n", pathX, pathY);
88
#endif
89
90
AWTPathGetMoreSpaceIfNecessary(path);
91
92
path->fSegmentType[path->fNumberOfSegments++] = (jbyte)eLineTo;
93
94
path->fSegmentData[path->fNumberOfDataElements++] = pathX;
95
path->fSegmentData[path->fNumberOfDataElements++] = pathY;
96
}
97
98
static void
99
AWTPathQuadTo(void* data, CGPoint p1, CGPoint p2)
100
{
101
CGFloat x1 = p1.x;
102
CGFloat y1 = p1.y;
103
CGFloat x2 = p2.x;
104
CGFloat y2 = p2.y;
105
106
AWTPathRef path = (AWTPathRef)data;
107
CGFloat tx = path->fTranslate.width;
108
CGFloat ty = path->fTranslate.height;
109
CGFloat pathX1 = x1+tx;
110
CGFloat pathY1 = -y1+ty;
111
CGFloat pathX2 = x2+tx;
112
CGFloat pathY2 = -y2+ty;
113
114
#ifdef AWT_GV_DEBUG
115
fprintf(stderr, "eQuadTo \n");
116
fprintf(stderr, " tx=%f, ty=%f\n", tx, ty);
117
fprintf(stderr, " x1=%f, y1=%f\n", x1, y1);
118
fprintf(stderr, " x2=%f, y2=%f\n", x2, y2);
119
fprintf(stderr, " pathX1=%f, path1Y=%f\n", pathX1, pathY1);
120
fprintf(stderr, " pathX2=%f, pathY2=%f\n", pathX2, pathY2);
121
#endif
122
123
AWTPathGetMoreSpaceIfNecessary(path);
124
125
path->fSegmentType[path->fNumberOfSegments++] = (jbyte)eQuadTo;
126
127
path->fSegmentData[path->fNumberOfDataElements++] = pathX1;
128
path->fSegmentData[path->fNumberOfDataElements++] = pathY1;
129
path->fSegmentData[path->fNumberOfDataElements++] = pathX2;
130
path->fSegmentData[path->fNumberOfDataElements++] = pathY2;
131
}
132
133
static void
134
AWTPathCubicTo(void* data, CGPoint p1, CGPoint p2, CGPoint p3)
135
{
136
CGFloat x1 = p1.x;
137
CGFloat y1 = p1.y;
138
CGFloat x2 = p2.x;
139
CGFloat y2 = p2.y;
140
CGFloat x3 = p3.x;
141
CGFloat y3 = p3.y;
142
143
AWTPathRef path = (AWTPathRef)data;
144
CGFloat tx = path->fTranslate.width;
145
CGFloat ty = path->fTranslate.height;
146
CGFloat pathX1 = x1+tx;
147
CGFloat pathY1 = -y1+ty;
148
CGFloat pathX2 = x2+tx;
149
CGFloat pathY2 = -y2+ty;
150
CGFloat pathX3 = x3+tx;
151
CGFloat pathY3 = -y3+ty;
152
153
#ifdef AWT_GV_DEBUG
154
fprintf(stderr, "eCubicTo \n");
155
fprintf(stderr, " tx=%f, ty=%f\n", tx, ty);
156
fprintf(stderr, " x1=%f, y1=%f\n", x1, y1);
157
fprintf(stderr, " x2=%f, y2=%f\n", x2, y2);
158
fprintf(stderr, " x3=%f, y3=%f\n", x3, y3);
159
fprintf(stderr, " pathX1=%f, path1Y=%f\n", pathX1, pathY1);
160
fprintf(stderr, " pathX2=%f, pathY2=%f\n", pathX2, pathY2);
161
fprintf(stderr, " pathX3=%f, pathY3=%f\n", pathX3, pathY3);
162
#endif
163
164
AWTPathGetMoreSpaceIfNecessary(path);
165
166
path->fSegmentType[path->fNumberOfSegments++] = (jbyte)eCubicTo;
167
168
path->fSegmentData[path->fNumberOfDataElements++] = pathX1;
169
path->fSegmentData[path->fNumberOfDataElements++] = pathY1;
170
path->fSegmentData[path->fNumberOfDataElements++] = pathX2;
171
path->fSegmentData[path->fNumberOfDataElements++] = pathY2;
172
path->fSegmentData[path->fNumberOfDataElements++] = pathX3;
173
path->fSegmentData[path->fNumberOfDataElements++] = pathY3;
174
}
175
176
static void
177
AWTPathClose(void* data)
178
{
179
#ifdef AWT_GV_DEBUG
180
fprintf(stderr, "GVGlyphPathCallBackClosePath \n");
181
#endif
182
183
AWTPathRef path = (AWTPathRef) data;
184
AWTPathGetMoreSpaceIfNecessary(path);
185
186
path->fSegmentType[path->fNumberOfSegments++] = (jbyte)eClosePath;
187
}
188
189
AWTPathRef
190
AWTPathCreate(CGSize translate)
191
{
192
#ifdef AWT_GV_DEBUG
193
fprintf(stderr, "AWTPathCreate \n");
194
fprintf(stderr, " translate.width=%f \n", translate.width);
195
fprintf(stderr, " translate.height=%f \n", translate.height);
196
#endif
197
198
AWTPathRef path = (AWTPathRef) malloc(sizeof(AWTPath));
199
path->fTranslate = translate;
200
path->fSegmentData = (jfloat*)malloc(sizeof(jfloat) * kInitialAllocatedPathSegments);
201
path->fSegmentType = (jbyte*)malloc(sizeof(jbyte) * kInitialAllocatedPathSegments);
202
path->fNumberOfDataElements = 0;
203
path->fNumberOfSegments = 0;
204
path->fAllocatedSegmentTypeSpace = kInitialAllocatedPathSegments;
205
path->fAllocatedSegmentDataSpace = kInitialAllocatedPathSegments;
206
207
return path;
208
}
209
210
void
211
AWTPathFree(AWTPathRef pathRef)
212
{
213
#ifdef AWT_GV_DEBUG
214
fprintf(stderr, "--B--AWTPathFree\n");
215
fprintf(stderr, "pathRef->fSegmentData (%p)\n",pathRef->fSegmentData);
216
#endif
217
218
free(pathRef->fSegmentData);
219
//fprintf(stderr, "pathRef->fSegmentType (%d)\n",pathRef->fSegmentType);
220
free(pathRef->fSegmentType);
221
//fprintf(stderr, "pathRef (%d)\n", pathRef);
222
free(pathRef);
223
//fprintf(stderr, "--E--AWTPathFree\n");
224
}
225
226
static void
227
AWTPathApplierCallback(void *info, const CGPathElement *element)
228
{
229
switch (element->type) {
230
case kCGPathElementMoveToPoint:
231
AWTPathMoveTo(info, element->points[0]);
232
break;
233
case kCGPathElementAddLineToPoint:
234
AWTPathLineTo(info, element->points[0]);
235
break;
236
case kCGPathElementAddQuadCurveToPoint:
237
AWTPathQuadTo(info, element->points[0], element->points[1]);
238
break;
239
case kCGPathElementAddCurveToPoint:
240
AWTPathCubicTo(info, element->points[0],
241
element->points[1], element->points[2]);
242
break;
243
case kCGPathElementCloseSubpath:
244
AWTPathClose(info);
245
break;
246
}
247
}
248
249
OSStatus
250
AWTGetGlyphOutline(CGGlyph *glyphs, NSFont *font,
251
CGSize *advanceArray, CGAffineTransform *tx,
252
UInt32 inStartIndex, size_t length,
253
AWTPathRef* outPath)
254
{
255
#ifdef AWT_GV_DEBUG
256
fprintf(stderr, "AWTGetGlyphOutline\n");
257
fprintf(stderr, " inAffineTransform a=%f, b=%f, c=%f, d=%f, tx=%f, ty=%f \n", tx->a, tx->b, tx->c, tx->d, tx->tx, tx->ty);
258
#endif
259
260
OSStatus status = noErr;
261
262
if ( isnan(tx->a) || isnan(tx->b) || isnan(tx->c) ||
263
isnan(tx->d) || isnan(tx->tx) || isnan(tx->ty)) {
264
return status;
265
}
266
glyphs = glyphs + inStartIndex;
267
// advanceArray = advanceArray + inStartIndex; // TODO(cpc): use advance
268
269
CGPathRef cgPath = CTFontCreatePathForGlyph((CTFontRef)font, glyphs[0], tx);
270
CGPathApply(cgPath, *outPath, AWTPathApplierCallback);
271
CGPathRelease(cgPath);
272
273
return status;
274
}
275
276