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 com.sun.javafx.font.directwrite;
27
28 import com.sun.javafx.font.DisposerRecord;
29 import com.sun.javafx.font.FontResource;
30 import com.sun.javafx.font.FontStrikeDesc;
31 import com.sun.javafx.font.Glyph;
32 import com.sun.javafx.font.PrismFontFactory;
33 import com.sun.javafx.font.PrismFontStrike;
34 import com.sun.javafx.geom.Path2D;
35 import com.sun.javafx.geom.Point2D;
36 import com.sun.javafx.geom.RectBounds;
37 import com.sun.javafx.geom.transform.BaseTransform;
38
39 class DWFontStrike extends PrismFontStrike<DWFontFile> {
40 DWRITE_MATRIX matrix;
41 static final boolean SUBPIXEL_ON;
42 static final boolean SUBPIXEL_Y;
43 static final boolean SUBPIXEL_NATIVE;
44 static {
45 int mode = PrismFontFactory.getFontFactory().getSubPixelMode();
46 SUBPIXEL_ON = (mode & PrismFontFactory.SUB_PIXEL_ON) != 0;
47 SUBPIXEL_Y = (mode & PrismFontFactory.SUB_PIXEL_Y) != 0;
48 SUBPIXEL_NATIVE = (mode & PrismFontFactory.SUB_PIXEL_NATIVE) != 0;
49 }
50
51 DWFontStrike(DWFontFile fontResource, float size, BaseTransform tx,
52 int aaMode, FontStrikeDesc desc) {
53 super(fontResource, size, tx, aaMode, desc);
54 float maxDim = 80f;
55 if (tx.isTranslateOrIdentity()) {
56 drawShapes = size > maxDim;
57 } else {
58 BaseTransform tx2d = getTransform();
59 matrix = new DWRITE_MATRIX();
60 matrix.m11 = (float)tx2d.getMxx();
61 matrix.m12 = (float)tx2d.getMyx();
62 matrix.m21 = (float)tx2d.getMxy();
63 matrix.m22 = (float)tx2d.getMyy();
64
65 if (Math.abs(matrix.m11 * size) > maxDim ||
66 Math.abs(matrix.m12 * size) > maxDim ||
67 Math.abs(matrix.m21 * size) > maxDim ||
68 Math.abs(matrix.m22 * size) > maxDim)
69 {
70 drawShapes = true;
71 }
72 }
73 }
74
75 @Override protected DisposerRecord createDisposer(FontStrikeDesc desc) {
76 return null;
77 }
78
79 @Override
80 public int getQuantizedPosition(Point2D point) {
81 if (SUBPIXEL_ON && (matrix == null || SUBPIXEL_NATIVE)) {
82 /* Using DirectWrite to produce subpixel glyph masks for grayscale
83 * text and (by default) let Prism produce subpixel glyphs for LCD
84 * using shaders (thus, saving texture and memory).
85 */
86 if (getAAMode() == FontResource.AA_GREYSCALE || SUBPIXEL_NATIVE) {
87 float subPixel = point.x;
88 point.x = (int)point.x;
89 subPixel -= point.x;
90 int index = 0;
91 if (subPixel >= 0.66f) {
92 index = 2;
93 } else if (subPixel >= 0.33f) {
94 index = 1;
95 }
96 if (SUBPIXEL_Y) {
97 subPixel = point.y;
98 point.y = (int)point.y;
99 subPixel -= point.y;
100 if (subPixel >= 0.66f) {
101 index += 6;
|
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 com.sun.javafx.font.directwrite;
27
28 import com.sun.javafx.font.DisposerRecord;
29 import com.sun.javafx.font.FontResource;
30 import com.sun.javafx.font.FontStrikeDesc;
31 import com.sun.javafx.font.Glyph;
32 import com.sun.javafx.font.PrismFontFactory;
33 import com.sun.javafx.font.PrismFontStrike;
34 import com.sun.javafx.geom.Path2D;
35 import com.sun.javafx.geom.Point2D;
36 import com.sun.javafx.geom.RectBounds;
37 import com.sun.javafx.geom.transform.BaseTransform;
38
39 class DWFontStrike extends PrismFontStrike<DWFontFile> {
40 DWRITE_MATRIX matrix;
41 boolean embeddedBitmap;
42 static final boolean SUBPIXEL_ON;
43 static final boolean SUBPIXEL_Y;
44 static final boolean SUBPIXEL_NATIVE;
45 static {
46 int mode = PrismFontFactory.getFontFactory().getSubPixelMode();
47 SUBPIXEL_ON = (mode & PrismFontFactory.SUB_PIXEL_ON) != 0;
48 SUBPIXEL_Y = (mode & PrismFontFactory.SUB_PIXEL_Y) != 0;
49 SUBPIXEL_NATIVE = (mode & PrismFontFactory.SUB_PIXEL_NATIVE) != 0;
50 }
51
52 DWFontStrike(DWFontFile fontResource, float size, BaseTransform tx,
53 int aaMode, FontStrikeDesc desc) {
54 super(fontResource, size, tx, aaMode, desc);
55 float maxDim = 80f;
56 if (tx.isTranslateOrIdentity()) {
57 drawShapes = size > maxDim;
58 } else {
59 BaseTransform tx2d = getTransform();
60 matrix = new DWRITE_MATRIX();
61 matrix.m11 = (float)tx2d.getMxx();
62 matrix.m12 = (float)tx2d.getMyx();
63 matrix.m21 = (float)tx2d.getMxy();
64 matrix.m22 = (float)tx2d.getMyy();
65
66 if (Math.abs(matrix.m11 * size) > maxDim ||
67 Math.abs(matrix.m12 * size) > maxDim ||
68 Math.abs(matrix.m21 * size) > maxDim ||
69 Math.abs(matrix.m22 * size) > maxDim)
70 {
71 drawShapes = true;
72 }
73 }
74 }
75
76 @Override
77 protected int calculateAAMode(int aaMode) {
78 aaMode = super.calculateAAMode(aaMode);
79 if (aaMode == FontResource.AA_GREYSCALE) return aaMode;
80 BaseTransform tx2d = getTransform();
81 if (tx2d.getType() > BaseTransform.TYPE_UNIFORM_SCALE) return aaMode;
82 int intSize = (int)(getSize() * tx2d.getMyy());
83 DWFontFile fr = getFontResource();
84 embeddedBitmap = fr.useEmbeddedBitmapsForSize(intSize);
85 return embeddedBitmap ? FontResource.AA_GREYSCALE : aaMode;
86 }
87
88 @Override protected DisposerRecord createDisposer(FontStrikeDesc desc) {
89 return null;
90 }
91
92 @Override
93 public int getQuantizedPosition(Point2D point) {
94 if (!embeddedBitmap && SUBPIXEL_ON && (matrix == null || SUBPIXEL_NATIVE)) {
95 /* Using DirectWrite to produce subpixel glyph masks for grayscale
96 * text and (by default) let Prism produce subpixel glyphs for LCD
97 * using shaders (thus, saving texture and memory).
98 */
99 if (getAAMode() == FontResource.AA_GREYSCALE || SUBPIXEL_NATIVE) {
100 float subPixel = point.x;
101 point.x = (int)point.x;
102 subPixel -= point.x;
103 int index = 0;
104 if (subPixel >= 0.66f) {
105 index = 2;
106 } else if (subPixel >= 0.33f) {
107 index = 1;
108 }
109 if (SUBPIXEL_Y) {
110 subPixel = point.y;
111 point.y = (int)point.y;
112 subPixel -= point.y;
113 if (subPixel >= 0.66f) {
114 index += 6;
|