aboutsummaryrefslogtreecommitdiff
path: root/src/share/native/sun/font/freetypeScaler.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/share/native/sun/font/freetypeScaler.c')
-rw-r--r--src/share/native/sun/font/freetypeScaler.c165
1 files changed, 79 insertions, 86 deletions
diff --git a/src/share/native/sun/font/freetypeScaler.c b/src/share/native/sun/font/freetypeScaler.c
index 4a45aaadde..65c24d42d2 100644
--- a/src/share/native/sun/font/freetypeScaler.c
+++ b/src/share/native/sun/font/freetypeScaler.c
@@ -48,6 +48,7 @@
#include FT_SIZES_H
#include FT_OUTLINE_H
#include FT_SYNTHESIS_H
+#include FT_LCD_FILTER_H
#include FT_MODULE_H
#include FT_LCD_FILTER_H
@@ -941,6 +942,8 @@ static int setupFTContext(JNIEnv *env, jobject font2D, FTScalerInfo *scalerInfo,
if (logFC) fprintf(stderr, "\n");
#endif
}
+
+ FT_Library_SetLcdFilter(scalerInfo->library, FT_LCD_FILTER_DEFAULT);
}
return 0;
@@ -1010,6 +1013,14 @@ Java_sun_font_FreetypeFontScaler_getFontMetricsNative(
/* See https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=657854 */
#define FT_MulFixFloatShift6(a, b) (((float) (a)) * ((float) (b)) / 65536.0 / 64.0)
+#define contextAwareMetricsX(x, y) \
+ (FTFixedToFloat(context->transform.xx) * (x) - \
+ FTFixedToFloat(context->transform.xy) * (y))
+
+#define contextAwareMetricsY(x, y) \
+ (-FTFixedToFloat(context->transform.yx) * (x) + \
+ FTFixedToFloat(context->transform.yy) * (y))
+
/*
* See FreeType source code: src/base/ftobjs.c ft_recompute_scaled_metrics()
* http://icedtea.classpath.org/bugzilla/show_bug.cgi?id=1659
@@ -1056,9 +1067,13 @@ Java_sun_font_FreetypeFontScaler_getFontMetricsNative(
mx = txx * mx;
metrics = (*env)->NewObject(env,
- sunFontIDs.strikeMetricsClass,
- sunFontIDs.strikeMetricsCtr,
- ax, ay, dx, dy, bx, by, lx, ly, mx, my);
+ sunFontIDs.strikeMetricsClass,
+ sunFontIDs.strikeMetricsCtr,
+ contextAwareMetricsX(ax, ay), contextAwareMetricsY(ax, ay),
+ contextAwareMetricsX(dx, dy), contextAwareMetricsY(dx, dy),
+ bx, by,
+ contextAwareMetricsX(lx, ly), contextAwareMetricsY(lx, ly),
+ contextAwareMetricsX(mx, my), contextAwareMetricsY(mx, my));
return metrics;
}
@@ -1125,10 +1140,14 @@ Java_sun_font_FreetypeFontScaler_getGlyphMetricsNative(
pScalerContext, pScaler, glyphCode);
info = (GlyphInfo*) jlong_to_ptr(image);
- (*env)->SetFloatField(env, metrics, sunFontIDs.xFID, info->advanceX);
- (*env)->SetFloatField(env, metrics, sunFontIDs.yFID, info->advanceY);
-
- free(info);
+ if (info != NULL) {
+ (*env)->SetFloatField(env, metrics, sunFontIDs.xFID, info->advanceX);
+ (*env)->SetFloatField(env, metrics, sunFontIDs.yFID, info->advanceY);
+ free(info);
+ } else {
+ (*env)->SetFloatField(env, metrics, sunFontIDs.xFID, 0.0f);
+ (*env)->SetFloatField(env, metrics, sunFontIDs.yFID, 0.0f);
+ }
}
@@ -1680,86 +1699,60 @@ static int allocateSpaceForGP(GPData* gpdata, int npoints, int ncontours) {
return 1;
}
+static void addSeg(GPData *gp, jbyte type) {
+ gp->pointTypes[gp->numTypes++] = type;
+}
+
+static void addCoords(GPData *gp, FT_Vector *p) {
+ gp->pointCoords[gp->numCoords++] = F26Dot6ToFloat(p->x);
+ gp->pointCoords[gp->numCoords++] = -F26Dot6ToFloat(p->y);
+}
+
+static int moveTo(FT_Vector *to, GPData *gp) {
+ if (gp->numCoords)
+ addSeg(gp, SEG_CLOSE);
+ addCoords(gp, to);
+ addSeg(gp, SEG_MOVETO);
+ return FT_Err_Ok;
+}
+
+static int lineTo(FT_Vector *to, GPData *gp) {
+ addCoords(gp, to);
+ addSeg(gp, SEG_LINETO);
+ return FT_Err_Ok;
+}
+
+static int conicTo(FT_Vector *control, FT_Vector *to, GPData *gp) {
+ addCoords(gp, control);
+ addCoords(gp, to);
+ addSeg(gp, SEG_QUADTO);
+ return FT_Err_Ok;
+}
+
+static int cubicTo(FT_Vector *control1,
+ FT_Vector *control2,
+ FT_Vector *to,
+ GPData *gp) {
+ addCoords(gp, control1);
+ addCoords(gp, control2);
+ addCoords(gp, to);
+ addSeg(gp, SEG_CUBICTO);
+ return FT_Err_Ok;
+}
+
static void addToGP(GPData* gpdata, FT_Outline*outline) {
- jbyte current_type=SEG_UNKNOWN;
- int i, j;
- jfloat x, y;
-
- j = 0;
- for(i=0; i<outline->n_points; i++) {
- x = F26Dot6ToFloat(outline->points[i].x);
- y = -F26Dot6ToFloat(outline->points[i].y);
-
- if (FT_CURVE_TAG(outline->tags[i]) == FT_CURVE_TAG_ON) {
- /* If bit 0 is unset, the point is "off" the curve,
- i.e., a Bezier control point, while it is "on" when set. */
- if (current_type == SEG_UNKNOWN) { /* special case:
- very first point */
- /* add segment */
- gpdata->pointTypes[gpdata->numTypes++] = SEG_MOVETO;
- current_type = SEG_LINETO;
- } else {
- gpdata->pointTypes[gpdata->numTypes++] = current_type;
- current_type = SEG_LINETO;
- }
- } else {
- if (current_type == SEG_UNKNOWN) { /* special case:
- very first point */
- if (FT_CURVE_TAG(outline->tags[i+1]) == FT_CURVE_TAG_ON) {
- /* just skip first point. Adhoc heuristic? */
- continue;
- } else {
- x = (x + F26Dot6ToFloat(outline->points[i+1].x))/2;
- y = (y - F26Dot6ToFloat(outline->points[i+1].y))/2;
- gpdata->pointTypes[gpdata->numTypes++] = SEG_MOVETO;
- current_type = SEG_LINETO;
- }
- } else if (FT_CURVE_TAG(outline->tags[i]) == FT_CURVE_TAG_CUBIC) {
- /* Bit 1 is meaningful for 'off' points only.
- If set, it indicates a third-order Bezier arc control
- point; and a second-order control point if unset. */
- current_type = SEG_CUBICTO;
- } else {
- /* two successive conic "off" points forces the rasterizer
- to create (during the scan-line conversion process
- exclusively) a virtual "on" point amidst them, at their
- exact middle. This greatly facilitates the definition of
- successive conic Bezier arcs. Moreover, it is the way
- outlines are described in the TrueType specification. */
- if (current_type == SEG_QUADTO) {
- gpdata->pointCoords[gpdata->numCoords++] =
- F26Dot6ToFloat(outline->points[i].x +
- outline->points[i-1].x)/2;
- gpdata->pointCoords[gpdata->numCoords++] =
- - F26Dot6ToFloat(outline->points[i].y +
- outline->points[i-1].y)/2;
- gpdata->pointTypes[gpdata->numTypes++] = SEG_QUADTO;
- }
- current_type = SEG_QUADTO;
- }
- }
- gpdata->pointCoords[gpdata->numCoords++] = x;
- gpdata->pointCoords[gpdata->numCoords++] = y;
- if (outline->contours[j] == i) { //end of contour
- int start = j > 0 ? outline->contours[j-1]+1 : 0;
- gpdata->pointTypes[gpdata->numTypes++] = current_type;
- if (current_type == SEG_QUADTO &&
- FT_CURVE_TAG(outline->tags[start]) != FT_CURVE_TAG_ON) {
- gpdata->pointCoords[gpdata->numCoords++] =
- (F26Dot6ToFloat(outline->points[start].x) + x)/2;
- gpdata->pointCoords[gpdata->numCoords++] =
- (-F26Dot6ToFloat(outline->points[start].y) + y)/2;
- } else {
- gpdata->pointCoords[gpdata->numCoords++] =
- F26Dot6ToFloat(outline->points[start].x);
- gpdata->pointCoords[gpdata->numCoords++] =
- -F26Dot6ToFloat(outline->points[start].y);
- }
- gpdata->pointTypes[gpdata->numTypes++] = SEG_CLOSE;
- current_type = SEG_UNKNOWN;
- j++;
- }
- }
+ static const FT_Outline_Funcs outline_funcs = {
+ (FT_Outline_MoveToFunc) moveTo,
+ (FT_Outline_LineToFunc) lineTo,
+ (FT_Outline_ConicToFunc) conicTo,
+ (FT_Outline_CubicToFunc) cubicTo,
+ 0, /* shift */
+ 0, /* delta */
+ };
+
+ FT_Outline_Decompose(outline, &outline_funcs, gpdata);
+ if (gpdata->numCoords)
+ addSeg(gpdata, SEG_CLOSE);
/* If set to 1, the outline will be filled using the even-odd fill rule */
if (outline->flags & FT_OUTLINE_EVEN_ODD_FILL) {