28 #include "jlong.h"
29 #include "sunfontids.h"
30 #include "sun_font_FreetypeFontScaler.h"
31
32 #include<stdlib.h>
33 #include <math.h>
34 #include "ft2build.h"
35 #include FT_FREETYPE_H
36 #include FT_GLYPH_H
37 #include FT_BBOX_H
38 #include FT_SIZES_H
39 #include FT_OUTLINE_H
40 #include FT_SYNTHESIS_H
41
42 #include "fontscaler.h"
43
44 #define ftFixed1 (FT_Fixed) (1 << 16)
45 #define FloatToFTFixed(f) (FT_Fixed)((f) * (float)(ftFixed1))
46 #define FTFixedToFloat(x) ((x) / (float)(ftFixed1))
47 #define FT26Dot6ToFloat(x) ((x) / ((float) (1<<6)))
48 #define ROUND(x) ((int) (x+0.5))
49
50 typedef struct {
51 /* Important note:
52 JNI forbids sharing same env between different threads.
53 We are safe, because pointer is overwritten every time we get into
54 JNI call (see setupFTContext).
55
56 Pointer is used by font data reading callbacks
57 such as ReadTTFontFileFunc.
58
59 NB: We may consider switching to JNI_GetEnv. */
60 JNIEnv* env;
61 FT_Library library;
62 FT_Face face;
63 FT_Stream faceStream;
64 jobject font2D;
65 jobject directBuffer;
66
67 unsigned char* fontData;
68 unsigned fontDataOffset;
748 glyphInfo->width = width;
749 glyphInfo->height = height;
750 glyphInfo->topLeftX = (float) ftglyph->bitmap_left;
751 glyphInfo->topLeftY = (float) -ftglyph->bitmap_top;
752
753 if (ftglyph->bitmap.pixel_mode == FT_PIXEL_MODE_LCD) {
754 glyphInfo->width = width/3;
755 } else if (ftglyph->bitmap.pixel_mode == FT_PIXEL_MODE_LCD_V) {
756 glyphInfo->height = glyphInfo->height/3;
757 }
758
759 if (context->fmType == TEXT_FM_ON) {
760 double advh = FTFixedToFloat(ftglyph->linearHoriAdvance);
761 glyphInfo->advanceX =
762 (float) (advh * FTFixedToFloat(context->transform.xx));
763 glyphInfo->advanceY =
764 (float) (advh * FTFixedToFloat(context->transform.xy));
765 } else {
766 if (!ftglyph->advance.y) {
767 glyphInfo->advanceX =
768 (float) ROUND(FT26Dot6ToFloat(ftglyph->advance.x));
769 glyphInfo->advanceY = 0;
770 } else if (!ftglyph->advance.x) {
771 glyphInfo->advanceX = 0;
772 glyphInfo->advanceY =
773 (float) ROUND(FT26Dot6ToFloat(-ftglyph->advance.y));
774 } else {
775 glyphInfo->advanceX = FT26Dot6ToFloat(ftglyph->advance.x);
776 glyphInfo->advanceY = FT26Dot6ToFloat(-ftglyph->advance.y);
777 }
778 }
779
780 if (imageSize == 0) {
781 glyphInfo->image = NULL;
782 } else {
783 glyphInfo->image = (unsigned char*) glyphInfo + sizeof(GlyphInfo);
784 //convert result to output format
785 //output format is either 3 bytes per pixel (for subpixel modes)
786 // or 1 byte per pixel for AA and B&W
787 if (ftglyph->bitmap.pixel_mode == FT_PIXEL_MODE_MONO) {
788 /* convert from 8 pixels per byte to 1 byte per pixel */
789 CopyBW2Grey8(ftglyph->bitmap.buffer,
790 ftglyph->bitmap.pitch,
791 (void *) glyphInfo->image,
792 width,
793 width,
|
28 #include "jlong.h"
29 #include "sunfontids.h"
30 #include "sun_font_FreetypeFontScaler.h"
31
32 #include<stdlib.h>
33 #include <math.h>
34 #include "ft2build.h"
35 #include FT_FREETYPE_H
36 #include FT_GLYPH_H
37 #include FT_BBOX_H
38 #include FT_SIZES_H
39 #include FT_OUTLINE_H
40 #include FT_SYNTHESIS_H
41
42 #include "fontscaler.h"
43
44 #define ftFixed1 (FT_Fixed) (1 << 16)
45 #define FloatToFTFixed(f) (FT_Fixed)((f) * (float)(ftFixed1))
46 #define FTFixedToFloat(x) ((x) / (float)(ftFixed1))
47 #define FT26Dot6ToFloat(x) ((x) / ((float) (1<<6)))
48 #define FT26Dot6ToInt(x) (((int)(x)) >> 6)
49
50 typedef struct {
51 /* Important note:
52 JNI forbids sharing same env between different threads.
53 We are safe, because pointer is overwritten every time we get into
54 JNI call (see setupFTContext).
55
56 Pointer is used by font data reading callbacks
57 such as ReadTTFontFileFunc.
58
59 NB: We may consider switching to JNI_GetEnv. */
60 JNIEnv* env;
61 FT_Library library;
62 FT_Face face;
63 FT_Stream faceStream;
64 jobject font2D;
65 jobject directBuffer;
66
67 unsigned char* fontData;
68 unsigned fontDataOffset;
748 glyphInfo->width = width;
749 glyphInfo->height = height;
750 glyphInfo->topLeftX = (float) ftglyph->bitmap_left;
751 glyphInfo->topLeftY = (float) -ftglyph->bitmap_top;
752
753 if (ftglyph->bitmap.pixel_mode == FT_PIXEL_MODE_LCD) {
754 glyphInfo->width = width/3;
755 } else if (ftglyph->bitmap.pixel_mode == FT_PIXEL_MODE_LCD_V) {
756 glyphInfo->height = glyphInfo->height/3;
757 }
758
759 if (context->fmType == TEXT_FM_ON) {
760 double advh = FTFixedToFloat(ftglyph->linearHoriAdvance);
761 glyphInfo->advanceX =
762 (float) (advh * FTFixedToFloat(context->transform.xx));
763 glyphInfo->advanceY =
764 (float) (advh * FTFixedToFloat(context->transform.xy));
765 } else {
766 if (!ftglyph->advance.y) {
767 glyphInfo->advanceX =
768 (float) FT26Dot6ToInt(ftglyph->advance.x);
769 glyphInfo->advanceY = 0;
770 } else if (!ftglyph->advance.x) {
771 glyphInfo->advanceX = 0;
772 glyphInfo->advanceY =
773 (float) FT26Dot6ToInt(-ftglyph->advance.y);
774 } else {
775 glyphInfo->advanceX = FT26Dot6ToFloat(ftglyph->advance.x);
776 glyphInfo->advanceY = FT26Dot6ToFloat(-ftglyph->advance.y);
777 }
778 }
779
780 if (imageSize == 0) {
781 glyphInfo->image = NULL;
782 } else {
783 glyphInfo->image = (unsigned char*) glyphInfo + sizeof(GlyphInfo);
784 //convert result to output format
785 //output format is either 3 bytes per pixel (for subpixel modes)
786 // or 1 byte per pixel for AA and B&W
787 if (ftglyph->bitmap.pixel_mode == FT_PIXEL_MODE_MONO) {
788 /* convert from 8 pixels per byte to 1 byte per pixel */
789 CopyBW2Grey8(ftglyph->bitmap.buffer,
790 ftglyph->bitmap.pitch,
791 (void *) glyphInfo->image,
792 width,
793 width,
|