/* File that implements a couple of Freetype functions that are not in LSB but are used in OpenJDK 7 */ // Includes that define types and functions implemented #include #include FT_FREETYPE_H #include FT_TRIGONOMETRY_H #include FT_BITMAP_H #include FT_GLYPH_H #include "lsb_freetype.h" #include FT_Error FT_Outline_Embolden( FT_Outline* outline, FT_Pos strength ); #ifdef __LSB_PROVIDES_FT_GlyphSlot_Embolden FT_Error FT_GlyphSlot_Own_Bitmap( FT_GlyphSlot slot ); #endif #ifdef __LSB_PROVIDES_FT_GlyphSlot_Embolden void FT_GlyphSlot_Embolden( FT_GlyphSlot slot ) { FT_Library library = slot->library; FT_Face face = slot->face; FT_Error error; FT_Pos xstr, ystr; if ( slot->format != FT_GLYPH_FORMAT_OUTLINE && slot->format != FT_GLYPH_FORMAT_BITMAP ) return; /* some reasonable strength */ xstr = FT_MulFix( face->units_per_EM, face->size->metrics.y_scale ) / 24; ystr = xstr; if ( slot->format == FT_GLYPH_FORMAT_OUTLINE ) { error = FT_Outline_Embolden( &slot->outline, xstr ); /* ignore error */ /* this is more than enough for most glyphs; if you need accurate */ /* values, you have to call FT_Outline_Get_CBox */ xstr = xstr * 2; ystr = xstr; } else if ( slot->format == FT_GLYPH_FORMAT_BITMAP ) { /* round to full pixels */ xstr &= ~63; if ( xstr == 0 ) xstr = 1 << 6; ystr &= ~63; error = FT_GlyphSlot_Own_Bitmap( slot ); if ( error ) return; error = FT_Bitmap_Embolden( library, &slot->bitmap, xstr, ystr ); if ( error ) return; } if ( slot->advance.x ) slot->advance.x += xstr; if ( slot->advance.y ) slot->advance.y += ystr; slot->metrics.width += xstr; slot->metrics.height += ystr; slot->metrics.horiBearingY += ystr; slot->metrics.horiAdvance += xstr; slot->metrics.vertBearingX -= xstr / 2; slot->metrics.vertBearingY += ystr; slot->metrics.vertAdvance += ystr; if ( slot->format == FT_GLYPH_FORMAT_BITMAP ) slot->bitmap_top += ystr >> 6; } #endif #ifdef __LSB_PROVIDES_FT_GlyphSlot_Oblique void FT_GlyphSlot_Oblique( FT_GlyphSlot slot ) { FT_Matrix transform; FT_Outline* outline = &slot->outline; /* only oblique outline glyphs */ if ( slot->format != FT_GLYPH_FORMAT_OUTLINE ) return; /* we don't touch the advance width */ /* For italic, simply apply a shear transform, with an angle */ /* of about 12 degrees. */ transform.xx = 0x10000L; transform.yx = 0x00000L; transform.xy = 0x06000L; transform.yy = 0x10000L; FT_Outline_Transform( outline, &transform ); } #endif /* We encarve this internal structure here because, in order to retain binary compatibility, Freetype developers will keep at least these fields unchanged. */ typedef struct FT_GlyphLoadRec_ { FT_Outline outline; /* outline */ FT_Vector* extra_points; /* extra points table */ FT_Vector* extra_points2; /* second extra points table */ FT_UInt num_subglyphs; /* number of subglyphs */ FT_SubGlyph subglyphs; /* subglyphs */ } FT_GlyphLoadRec, *FT_GlyphLoad; typedef struct FT_GlyphLoaderRec_ { FT_Memory memory; FT_UInt max_points; FT_UInt max_contours; FT_UInt max_subglyphs; FT_Bool use_extra; FT_GlyphLoadRec base; FT_GlyphLoadRec current; void* other; /* for possible future extension? */ } FT_GlyphLoaderRec; typedef struct FT_GlyphLoaderRec_* FT_GlyphLoader ; #define FT_GLYPH_OWN_BITMAP 0x1 typedef struct FT_Slot_InternalRec_ { FT_GlyphLoader loader; FT_UInt flags; FT_Bool glyph_transformed; FT_Matrix glyph_matrix; FT_Vector glyph_delta; void* glyph_hints; } FT_GlyphSlot_InternalRec; #ifdef __LSB_PROVIDES_FT_GlyphSlot_Embolden FT_Error FT_GlyphSlot_Own_Bitmap( FT_GlyphSlot slot ) { if ( slot && slot->format == FT_GLYPH_FORMAT_BITMAP && !( slot->internal->flags & FT_GLYPH_OWN_BITMAP ) ) { FT_Bitmap bitmap; FT_Error error; FT_Bitmap_New( &bitmap ); error = FT_Bitmap_Copy( slot->library, &slot->bitmap, &bitmap ); if ( error ) return error; slot->bitmap = bitmap; slot->internal->flags |= FT_GLYPH_OWN_BITMAP; } return FT_Err_Ok; } #endif #ifdef __LSB_PROVIDES_FT_GlyphSlot_Embolden FT_Error FT_Outline_Embolden( FT_Outline* outline, FT_Pos strength ) { FT_Vector* points; FT_Vector v_prev, v_first, v_next, v_cur; FT_Angle rotate, angle_in, angle_out; FT_Int c, n, first; FT_Int orientation; if ( !outline ) return FT_Err_Invalid_Argument; strength /= 2; if ( strength == 0 ) return FT_Err_Ok; orientation = FT_Outline_Get_Orientation( outline ); if ( orientation == FT_ORIENTATION_NONE ) { if ( outline->n_contours ) return FT_Err_Invalid_Argument; else return FT_Err_Ok; } if ( orientation == FT_ORIENTATION_TRUETYPE ) rotate = -FT_ANGLE_PI2; else rotate = FT_ANGLE_PI2; points = outline->points; first = 0; for ( c = 0; c < outline->n_contours; c++ ) { int last = outline->contours[c]; v_first = points[first]; v_prev = points[last]; v_cur = v_first; for ( n = first; n <= last; n++ ) { FT_Vector in, out; FT_Angle angle_diff; FT_Pos d; FT_Fixed scale; if ( n < last ) v_next = points[n + 1]; else v_next = v_first; /* compute the in and out vectors */ in.x = v_cur.x - v_prev.x; in.y = v_cur.y - v_prev.y; out.x = v_next.x - v_cur.x; out.y = v_next.y - v_cur.y; angle_in = FT_Atan2( in.x, in.y ); angle_out = FT_Atan2( out.x, out.y ); angle_diff = FT_Angle_Diff( angle_in, angle_out ); scale = FT_Cos( angle_diff / 2 ); if ( scale < 0x4000L && scale > -0x4000L ) in.x = in.y = 0; else { d = FT_DivFix( strength, scale ); FT_Vector_From_Polar( &in, d, angle_in + angle_diff / 2 - rotate ); } outline->points[n].x = v_cur.x + strength + in.x; outline->points[n].y = v_cur.y + strength + in.y; v_prev = v_cur; v_cur = v_next; } first = last + 1; } return FT_Err_Ok; } #endif