Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/java.desktop/share/classes/sun/awt/SunHints.java
41152 views
1
/*
2
* Copyright (c) 1998, 2013, 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
package sun.awt;
27
28
import java.awt.RenderingHints;
29
import java.lang.annotation.Native;
30
31
/**
32
* This class contains rendering hints that can be used by the
33
* {@link java.awt.Graphics2D} class, and classes that implement
34
* {@link java.awt.image.BufferedImageOp} and
35
* {@link java.awt.image.Raster}.
36
*/
37
public class SunHints {
38
/**
39
* Defines the type of all keys used to control various
40
* aspects of the rendering and imaging pipelines. Instances
41
* of this class are immutable and unique which means that
42
* tests for matches can be made using the == operator instead
43
* of the more expensive equals() method.
44
*/
45
public static class Key extends RenderingHints.Key {
46
String description;
47
48
/**
49
* Construct a key using the indicated private key. Each
50
* subclass of Key maintains its own unique domain of integer
51
* keys. No two objects with the same integer key and of the
52
* same specific subclass can be constructed. An exception
53
* will be thrown if an attempt is made to construct another
54
* object of a given class with the same integer key as a
55
* pre-existing instance of that subclass of Key.
56
*/
57
public Key(int privatekey, String description) {
58
super(privatekey);
59
this.description = description;
60
}
61
62
/**
63
* Returns the numeric index associated with this Key. This
64
* is useful for use in switch statements and quick lookups
65
* of the setting of a particular key.
66
*/
67
public final int getIndex() {
68
return intKey();
69
}
70
71
/**
72
* Returns a string representation of the Key.
73
*/
74
public final String toString() {
75
return description;
76
}
77
78
/**
79
* Returns true if the specified object is a valid value
80
* for this Key.
81
*/
82
public boolean isCompatibleValue(Object val) {
83
if (val instanceof Value) {
84
return ((Value)val).isCompatibleKey(this);
85
}
86
return false;
87
}
88
}
89
90
/**
91
* Defines the type of all "enumerative" values used to control
92
* various aspects of the rendering and imaging pipelines. Instances
93
* of this class are immutable and unique which means that
94
* tests for matches can be made using the == operator instead
95
* of the more expensive equals() method.
96
*/
97
public static class Value {
98
private SunHints.Key myKey;
99
private int index;
100
private String description;
101
102
private static Value[][] ValueObjects =
103
new Value[NUM_KEYS][VALS_PER_KEY];
104
105
private static synchronized void register(SunHints.Key key,
106
Value value) {
107
int kindex = key.getIndex();
108
int vindex = value.getIndex();
109
if (ValueObjects[kindex][vindex] != null) {
110
throw new InternalError("duplicate index: "+vindex);
111
}
112
ValueObjects[kindex][vindex] = value;
113
}
114
115
public static Value get(int keyindex, int valueindex) {
116
return ValueObjects[keyindex][valueindex];
117
}
118
119
/**
120
* Construct a value using the indicated private index. Each
121
* subclass of Value maintains its own unique domain of integer
122
* indices. Enforcing the uniqueness of the integer indices
123
* is left to the subclass.
124
*/
125
public Value(SunHints.Key key, int index, String description) {
126
this.myKey = key;
127
this.index = index;
128
this.description = description;
129
130
register(key, this);
131
}
132
133
/**
134
* Returns the numeric index associated with this Key. This
135
* is useful for use in switch statements and quick lookups
136
* of the setting of a particular key.
137
*/
138
public final int getIndex() {
139
return index;
140
}
141
142
/**
143
* Returns a string representation of this Value.
144
*/
145
public final String toString() {
146
return description;
147
}
148
149
/**
150
* Returns true if the specified object is a valid Key
151
* for this Value.
152
*/
153
public final boolean isCompatibleKey(Key k) {
154
return myKey == k;
155
}
156
157
/**
158
* The hash code for all SunHints.Value objects will be the same
159
* as the system identity code of the object as defined by the
160
* System.identityHashCode() method.
161
*/
162
public final int hashCode() {
163
return System.identityHashCode(this);
164
}
165
166
/**
167
* The equals method for all SunHints.Value objects will return
168
* the same result as the equality operator '=='.
169
*/
170
public final boolean equals(Object o) {
171
return this == o;
172
}
173
}
174
175
private static final int NUM_KEYS = 10;
176
private static final int VALS_PER_KEY = 8;
177
178
/**
179
* Rendering hint key and values
180
*/
181
@Native public static final int INTKEY_RENDERING = 0;
182
@Native public static final int INTVAL_RENDER_DEFAULT = 0;
183
@Native public static final int INTVAL_RENDER_SPEED = 1;
184
@Native public static final int INTVAL_RENDER_QUALITY = 2;
185
186
/**
187
* Antialiasing hint key and values
188
*/
189
@Native public static final int INTKEY_ANTIALIASING = 1;
190
@Native public static final int INTVAL_ANTIALIAS_DEFAULT = 0;
191
@Native public static final int INTVAL_ANTIALIAS_OFF = 1;
192
@Native public static final int INTVAL_ANTIALIAS_ON = 2;
193
194
/**
195
* Text antialiasing hint key and values
196
*/
197
@Native public static final int INTKEY_TEXT_ANTIALIASING = 2;
198
@Native public static final int INTVAL_TEXT_ANTIALIAS_DEFAULT = 0;
199
@Native public static final int INTVAL_TEXT_ANTIALIAS_OFF = 1;
200
@Native public static final int INTVAL_TEXT_ANTIALIAS_ON = 2;
201
@Native public static final int INTVAL_TEXT_ANTIALIAS_GASP = 3;
202
@Native public static final int INTVAL_TEXT_ANTIALIAS_LCD_HRGB = 4;
203
@Native public static final int INTVAL_TEXT_ANTIALIAS_LCD_HBGR = 5;
204
@Native public static final int INTVAL_TEXT_ANTIALIAS_LCD_VRGB = 6;
205
@Native public static final int INTVAL_TEXT_ANTIALIAS_LCD_VBGR = 7;
206
207
/**
208
* Font fractional metrics hint key and values
209
*/
210
@Native public static final int INTKEY_FRACTIONALMETRICS = 3;
211
@Native public static final int INTVAL_FRACTIONALMETRICS_DEFAULT = 0;
212
@Native public static final int INTVAL_FRACTIONALMETRICS_OFF = 1;
213
@Native public static final int INTVAL_FRACTIONALMETRICS_ON = 2;
214
215
/**
216
* Dithering hint key and values
217
*/
218
@Native public static final int INTKEY_DITHERING = 4;
219
@Native public static final int INTVAL_DITHER_DEFAULT = 0;
220
@Native public static final int INTVAL_DITHER_DISABLE = 1;
221
@Native public static final int INTVAL_DITHER_ENABLE = 2;
222
223
/**
224
* Interpolation hint key and values
225
*/
226
@Native public static final int INTKEY_INTERPOLATION = 5;
227
@Native public static final int INTVAL_INTERPOLATION_NEAREST_NEIGHBOR = 0;
228
@Native public static final int INTVAL_INTERPOLATION_BILINEAR = 1;
229
@Native public static final int INTVAL_INTERPOLATION_BICUBIC = 2;
230
231
/**
232
* Alpha interpolation hint key and values
233
*/
234
@Native public static final int INTKEY_ALPHA_INTERPOLATION = 6;
235
@Native public static final int INTVAL_ALPHA_INTERPOLATION_DEFAULT = 0;
236
@Native public static final int INTVAL_ALPHA_INTERPOLATION_SPEED = 1;
237
@Native public static final int INTVAL_ALPHA_INTERPOLATION_QUALITY = 2;
238
239
/**
240
* Color rendering hint key and values
241
*/
242
@Native public static final int INTKEY_COLOR_RENDERING = 7;
243
@Native public static final int INTVAL_COLOR_RENDER_DEFAULT = 0;
244
@Native public static final int INTVAL_COLOR_RENDER_SPEED = 1;
245
@Native public static final int INTVAL_COLOR_RENDER_QUALITY = 2;
246
247
/**
248
* Stroke normalization control hint key and values
249
*/
250
@Native public static final int INTKEY_STROKE_CONTROL = 8;
251
@Native public static final int INTVAL_STROKE_DEFAULT = 0;
252
@Native public static final int INTVAL_STROKE_NORMALIZE = 1;
253
@Native public static final int INTVAL_STROKE_PURE = 2;
254
255
/**
256
* Image scaling hint key and values
257
*/
258
@Native public static final int INTKEY_RESOLUTION_VARIANT = 9;
259
@Native public static final int INTVAL_RESOLUTION_VARIANT_DEFAULT = 0;
260
@Native public static final int INTVAL_RESOLUTION_VARIANT_BASE = 1;
261
@Native public static final int INTVAL_RESOLUTION_VARIANT_SIZE_FIT = 2;
262
@Native public static final int INTVAL_RESOLUTION_VARIANT_DPI_FIT = 3;
263
264
/**
265
* LCD text contrast control hint key.
266
* Value is "100" to make discontiguous with the others which
267
* are all enumerative and are of a different class.
268
*/
269
@Native public static final int INTKEY_AATEXT_LCD_CONTRAST = 100;
270
271
/**
272
* Rendering hint key and value objects
273
*/
274
public static final Key KEY_RENDERING =
275
new SunHints.Key(SunHints.INTKEY_RENDERING,
276
"Global rendering quality key");
277
public static final Object VALUE_RENDER_SPEED =
278
new SunHints.Value(KEY_RENDERING,
279
SunHints.INTVAL_RENDER_SPEED,
280
"Fastest rendering methods");
281
public static final Object VALUE_RENDER_QUALITY =
282
new SunHints.Value(KEY_RENDERING,
283
SunHints.INTVAL_RENDER_QUALITY,
284
"Highest quality rendering methods");
285
public static final Object VALUE_RENDER_DEFAULT =
286
new SunHints.Value(KEY_RENDERING,
287
SunHints.INTVAL_RENDER_DEFAULT,
288
"Default rendering methods");
289
290
/**
291
* Antialiasing hint key and value objects
292
*/
293
public static final Key KEY_ANTIALIASING =
294
new SunHints.Key(SunHints.INTKEY_ANTIALIASING,
295
"Global antialiasing enable key");
296
public static final Object VALUE_ANTIALIAS_ON =
297
new SunHints.Value(KEY_ANTIALIASING,
298
SunHints.INTVAL_ANTIALIAS_ON,
299
"Antialiased rendering mode");
300
public static final Object VALUE_ANTIALIAS_OFF =
301
new SunHints.Value(KEY_ANTIALIASING,
302
SunHints.INTVAL_ANTIALIAS_OFF,
303
"Nonantialiased rendering mode");
304
public static final Object VALUE_ANTIALIAS_DEFAULT =
305
new SunHints.Value(KEY_ANTIALIASING,
306
SunHints.INTVAL_ANTIALIAS_DEFAULT,
307
"Default antialiasing rendering mode");
308
309
/**
310
* Text antialiasing hint key and value objects
311
*/
312
public static final Key KEY_TEXT_ANTIALIASING =
313
new SunHints.Key(SunHints.INTKEY_TEXT_ANTIALIASING,
314
"Text-specific antialiasing enable key");
315
public static final Object VALUE_TEXT_ANTIALIAS_ON =
316
new SunHints.Value(KEY_TEXT_ANTIALIASING,
317
SunHints.INTVAL_TEXT_ANTIALIAS_ON,
318
"Antialiased text mode");
319
public static final Object VALUE_TEXT_ANTIALIAS_OFF =
320
new SunHints.Value(KEY_TEXT_ANTIALIASING,
321
SunHints.INTVAL_TEXT_ANTIALIAS_OFF,
322
"Nonantialiased text mode");
323
public static final Object VALUE_TEXT_ANTIALIAS_DEFAULT =
324
new SunHints.Value(KEY_TEXT_ANTIALIASING,
325
SunHints.INTVAL_TEXT_ANTIALIAS_DEFAULT,
326
"Default antialiasing text mode");
327
public static final Object VALUE_TEXT_ANTIALIAS_GASP =
328
new SunHints.Value(KEY_TEXT_ANTIALIASING,
329
SunHints.INTVAL_TEXT_ANTIALIAS_GASP,
330
"gasp antialiasing text mode");
331
public static final Object VALUE_TEXT_ANTIALIAS_LCD_HRGB =
332
new SunHints.Value(KEY_TEXT_ANTIALIASING,
333
SunHints.INTVAL_TEXT_ANTIALIAS_LCD_HRGB,
334
"LCD HRGB antialiasing text mode");
335
public static final Object VALUE_TEXT_ANTIALIAS_LCD_HBGR =
336
new SunHints.Value(KEY_TEXT_ANTIALIASING,
337
SunHints.INTVAL_TEXT_ANTIALIAS_LCD_HBGR,
338
"LCD HBGR antialiasing text mode");
339
public static final Object VALUE_TEXT_ANTIALIAS_LCD_VRGB =
340
new SunHints.Value(KEY_TEXT_ANTIALIASING,
341
SunHints.INTVAL_TEXT_ANTIALIAS_LCD_VRGB,
342
"LCD VRGB antialiasing text mode");
343
public static final Object VALUE_TEXT_ANTIALIAS_LCD_VBGR =
344
new SunHints.Value(KEY_TEXT_ANTIALIASING,
345
SunHints.INTVAL_TEXT_ANTIALIAS_LCD_VBGR,
346
"LCD VBGR antialiasing text mode");
347
348
/**
349
* Font fractional metrics hint key and value objects
350
*/
351
public static final Key KEY_FRACTIONALMETRICS =
352
new SunHints.Key(SunHints.INTKEY_FRACTIONALMETRICS,
353
"Fractional metrics enable key");
354
public static final Object VALUE_FRACTIONALMETRICS_ON =
355
new SunHints.Value(KEY_FRACTIONALMETRICS,
356
SunHints.INTVAL_FRACTIONALMETRICS_ON,
357
"Fractional text metrics mode");
358
public static final Object VALUE_FRACTIONALMETRICS_OFF =
359
new SunHints.Value(KEY_FRACTIONALMETRICS,
360
SunHints.INTVAL_FRACTIONALMETRICS_OFF,
361
"Integer text metrics mode");
362
public static final Object VALUE_FRACTIONALMETRICS_DEFAULT =
363
new SunHints.Value(KEY_FRACTIONALMETRICS,
364
SunHints.INTVAL_FRACTIONALMETRICS_DEFAULT,
365
"Default fractional text metrics mode");
366
367
/**
368
* Dithering hint key and value objects
369
*/
370
public static final Key KEY_DITHERING =
371
new SunHints.Key(SunHints.INTKEY_DITHERING,
372
"Dithering quality key");
373
public static final Object VALUE_DITHER_ENABLE =
374
new SunHints.Value(KEY_DITHERING,
375
SunHints.INTVAL_DITHER_ENABLE,
376
"Dithered rendering mode");
377
public static final Object VALUE_DITHER_DISABLE =
378
new SunHints.Value(KEY_DITHERING,
379
SunHints.INTVAL_DITHER_DISABLE,
380
"Nondithered rendering mode");
381
public static final Object VALUE_DITHER_DEFAULT =
382
new SunHints.Value(KEY_DITHERING,
383
SunHints.INTVAL_DITHER_DEFAULT,
384
"Default dithering mode");
385
386
/**
387
* Interpolation hint key and value objects
388
*/
389
public static final Key KEY_INTERPOLATION =
390
new SunHints.Key(SunHints.INTKEY_INTERPOLATION,
391
"Image interpolation method key");
392
public static final Object VALUE_INTERPOLATION_NEAREST_NEIGHBOR =
393
new SunHints.Value(KEY_INTERPOLATION,
394
SunHints.INTVAL_INTERPOLATION_NEAREST_NEIGHBOR,
395
"Nearest Neighbor image interpolation mode");
396
public static final Object VALUE_INTERPOLATION_BILINEAR =
397
new SunHints.Value(KEY_INTERPOLATION,
398
SunHints.INTVAL_INTERPOLATION_BILINEAR,
399
"Bilinear image interpolation mode");
400
public static final Object VALUE_INTERPOLATION_BICUBIC =
401
new SunHints.Value(KEY_INTERPOLATION,
402
SunHints.INTVAL_INTERPOLATION_BICUBIC,
403
"Bicubic image interpolation mode");
404
405
/**
406
* Alpha interpolation hint key and value objects
407
*/
408
public static final Key KEY_ALPHA_INTERPOLATION =
409
new SunHints.Key(SunHints.INTKEY_ALPHA_INTERPOLATION,
410
"Alpha blending interpolation method key");
411
public static final Object VALUE_ALPHA_INTERPOLATION_SPEED =
412
new SunHints.Value(KEY_ALPHA_INTERPOLATION,
413
SunHints.INTVAL_ALPHA_INTERPOLATION_SPEED,
414
"Fastest alpha blending methods");
415
public static final Object VALUE_ALPHA_INTERPOLATION_QUALITY =
416
new SunHints.Value(KEY_ALPHA_INTERPOLATION,
417
SunHints.INTVAL_ALPHA_INTERPOLATION_QUALITY,
418
"Highest quality alpha blending methods");
419
public static final Object VALUE_ALPHA_INTERPOLATION_DEFAULT =
420
new SunHints.Value(KEY_ALPHA_INTERPOLATION,
421
SunHints.INTVAL_ALPHA_INTERPOLATION_DEFAULT,
422
"Default alpha blending methods");
423
424
/**
425
* Color rendering hint key and value objects
426
*/
427
public static final Key KEY_COLOR_RENDERING =
428
new SunHints.Key(SunHints.INTKEY_COLOR_RENDERING,
429
"Color rendering quality key");
430
public static final Object VALUE_COLOR_RENDER_SPEED =
431
new SunHints.Value(KEY_COLOR_RENDERING,
432
SunHints.INTVAL_COLOR_RENDER_SPEED,
433
"Fastest color rendering mode");
434
public static final Object VALUE_COLOR_RENDER_QUALITY =
435
new SunHints.Value(KEY_COLOR_RENDERING,
436
SunHints.INTVAL_COLOR_RENDER_QUALITY,
437
"Highest quality color rendering mode");
438
public static final Object VALUE_COLOR_RENDER_DEFAULT =
439
new SunHints.Value(KEY_COLOR_RENDERING,
440
SunHints.INTVAL_COLOR_RENDER_DEFAULT,
441
"Default color rendering mode");
442
443
/**
444
* Stroke normalization control hint key and value objects
445
*/
446
public static final Key KEY_STROKE_CONTROL =
447
new SunHints.Key(SunHints.INTKEY_STROKE_CONTROL,
448
"Stroke normalization control key");
449
public static final Object VALUE_STROKE_DEFAULT =
450
new SunHints.Value(KEY_STROKE_CONTROL,
451
SunHints.INTVAL_STROKE_DEFAULT,
452
"Default stroke normalization");
453
public static final Object VALUE_STROKE_NORMALIZE =
454
new SunHints.Value(KEY_STROKE_CONTROL,
455
SunHints.INTVAL_STROKE_NORMALIZE,
456
"Normalize strokes for consistent rendering");
457
public static final Object VALUE_STROKE_PURE =
458
new SunHints.Value(KEY_STROKE_CONTROL,
459
SunHints.INTVAL_STROKE_PURE,
460
"Pure stroke conversion for accurate paths");
461
462
/**
463
* Image resolution variant hint key and value objects
464
*/
465
public static final Key KEY_RESOLUTION_VARIANT =
466
new SunHints.Key(SunHints.INTKEY_RESOLUTION_VARIANT,
467
"Global image resolution variant key");
468
public static final Object VALUE_RESOLUTION_VARIANT_DEFAULT =
469
new SunHints.Value(KEY_RESOLUTION_VARIANT,
470
SunHints.INTVAL_RESOLUTION_VARIANT_DEFAULT,
471
"Choose image resolutions based on a default"
472
+ "heuristic");
473
public static final Object VALUE_RESOLUTION_VARIANT_BASE =
474
new SunHints.Value(KEY_RESOLUTION_VARIANT,
475
SunHints.INTVAL_RESOLUTION_VARIANT_BASE,
476
"Use only the standard resolution of an image");
477
public static final Object VALUE_RESOLUTION_VARIANT_SIZE_FIT =
478
new SunHints.Value(KEY_RESOLUTION_VARIANT,
479
SunHints.INTVAL_RESOLUTION_VARIANT_SIZE_FIT,
480
"Choose image resolutions based on the DPI"
481
+ "of the screen and transform"
482
+ "in the Graphics2D context");
483
public static final Object VALUE_RESOLUTION_VARIANT_DPI_FIT =
484
new SunHints.Value(KEY_RESOLUTION_VARIANT,
485
SunHints.INTVAL_RESOLUTION_VARIANT_DPI_FIT,
486
"Choose image resolutions based only on the DPI"
487
+ " of the screen");
488
489
public static class LCDContrastKey extends Key {
490
491
public LCDContrastKey(int privatekey, String description) {
492
super(privatekey, description);
493
}
494
495
/**
496
* Returns true if the specified object is a valid value
497
* for this Key. The allowable range is 100 to 250.
498
*/
499
public final boolean isCompatibleValue(Object val) {
500
if (val instanceof Integer) {
501
int ival = ((Integer)val).intValue();
502
return ival >= 100 && ival <= 250;
503
}
504
return false;
505
}
506
507
}
508
509
/**
510
* LCD text contrast hint key
511
*/
512
public static final RenderingHints.Key
513
KEY_TEXT_ANTIALIAS_LCD_CONTRAST =
514
new LCDContrastKey(SunHints.INTKEY_AATEXT_LCD_CONTRAST,
515
"Text-specific LCD contrast key");
516
}
517
518