Lines 1029-1048
Link Here
|
1029 |
return nsnull; |
1029 |
return nsnull; |
1030 |
} |
1030 |
} |
1031 |
|
1031 |
|
1032 |
/*FT_CALLBACK_DEF*/ |
|
|
1033 |
FT_Error |
1034 |
nsXftFaceRequester(FTC_FaceID face_id, FT_Library lib, |
1035 |
FT_Pointer request_data, FT_Face* aFace) |
1036 |
{ |
1037 |
nsXftEntry *faceID = (nsXftEntry *)face_id; |
1038 |
|
1039 |
FT_Error fterror = FT_New_Face(lib, faceID->mFontFileName.get(), |
1040 |
faceID->mFaceIndex, aFace); |
1041 |
if (fterror) |
1042 |
*aFace = nsnull; |
1043 |
return 0; |
1044 |
} |
1045 |
|
1046 |
nsFontPSXft::nsFontPSXft(const nsFont& aFont, |
1032 |
nsFontPSXft::nsFontPSXft(const nsFont& aFont, |
1047 |
nsFontMetricsPS* aFontMetrics) |
1033 |
nsFontMetricsPS* aFontMetrics) |
1048 |
:nsFontPS(aFont, aFontMetrics) |
1034 |
:nsFontPS(aFont, aFontMetrics) |
Lines 1064-1098
Link Here
|
1064 |
|
1050 |
|
1065 |
mPixelSize = NSToIntRound(app2dev * mFont->size); |
1051 |
mPixelSize = NSToIntRound(app2dev * mFont->size); |
1066 |
|
1052 |
|
1067 |
mImageDesc.font.face_id = (void*)mEntry; |
|
|
1068 |
mImageDesc.font.pix_width = mPixelSize; |
1069 |
mImageDesc.font.pix_height = mPixelSize; |
1070 |
mImageDesc.image_type = 0; |
1071 |
|
1072 |
FT_Error fterror; |
1053 |
FT_Error fterror; |
1073 |
fterror = FT_Init_FreeType(&mFreeTypeLibrary); |
1054 |
fterror = FT_Init_FreeType(&mFreeTypeLibrary); |
1074 |
if (fterror) { |
1055 |
if (fterror) { |
1075 |
NS_ASSERTION(!fterror, "failed to initialize FreeType library"); |
1056 |
NS_ERROR("failed to initialize FreeType library"); |
1076 |
mFreeTypeLibrary = nsnull; |
1057 |
mFreeTypeLibrary = nsnull; |
1077 |
return NS_ERROR_FAILURE; |
1058 |
return NS_ERROR_FAILURE; |
1078 |
} |
1059 |
} |
1079 |
fterror = FTC_Manager_New(mFreeTypeLibrary, 0, 0, 0, nsXftFaceRequester, |
|
|
1080 |
NULL, &mFTCacheManager); |
1081 |
NS_ASSERTION(!fterror, "failed to create FreeType Cache manager"); |
1082 |
if (fterror) |
1083 |
return NS_ERROR_FAILURE; |
1084 |
|
1085 |
fterror = FTC_Image_Cache_New(mFTCacheManager, &mImageCache); |
1086 |
NS_ASSERTION(!fterror, "failed to create FreeType image cache"); |
1087 |
if (fterror) |
1088 |
return NS_ERROR_FAILURE; |
1089 |
|
1090 |
return NS_OK; |
1060 |
return NS_OK; |
1091 |
} |
1061 |
} |
1092 |
|
1062 |
|
1093 |
nsFontPSXft::~nsFontPSXft() |
1063 |
nsFontPSXft::~nsFontPSXft() |
1094 |
{ |
1064 |
{ |
1095 |
FTC_Manager_Done(mFTCacheManager); |
1065 |
if (mEntry->mFace) |
|
|
1066 |
FT_Done_Face(mEntry->mFace); |
1096 |
|
1067 |
|
1097 |
if (FT_Done_FreeType(mFreeTypeLibrary)) |
1068 |
if (FT_Done_FreeType(mFreeTypeLibrary)) |
1098 |
return; |
1069 |
return; |
Lines 1103-1118
Link Here
|
1103 |
FT_Face |
1074 |
FT_Face |
1104 |
nsFontPSXft::getFTFace() |
1075 |
nsFontPSXft::getFTFace() |
1105 |
{ |
1076 |
{ |
1106 |
FT_Error error; |
|
|
1107 |
FT_Face face = mEntry->mFace; |
1077 |
FT_Face face = mEntry->mFace; |
1108 |
|
1078 |
|
1109 |
if (face) |
1079 |
if (face) |
1110 |
return (face); |
1080 |
return (face); |
1111 |
|
1081 |
|
1112 |
error = FTC_Manager_Lookup_Size(mFTCacheManager, &mImageDesc.font, |
1082 |
if (FT_New_Face(mFreeTypeLibrary, mEntry->mFontFileName.get(), |
1113 |
&face, nsnull); |
1083 |
mEntry->mFaceIndex, &face) || |
1114 |
NS_ASSERTION(error == 0, "failed to get face/size"); |
1084 |
FT_Set_Pixel_Sizes(face, mPixelSize, 0)) |
1115 |
if (error) |
|
|
1116 |
return nsnull; |
1085 |
return nsnull; |
1117 |
|
1086 |
|
1118 |
mEntry->mFace = face; |
1087 |
mEntry->mFace = face; |
Lines 1150-1164
Link Here
|
1150 |
if (!face) |
1119 |
if (!face) |
1151 |
return 0; |
1120 |
return 0; |
1152 |
|
1121 |
|
|
|
1122 |
// XXX : we might need some caching here |
1153 |
for (PRUint32 i=0; i<aLength; i++) { |
1123 |
for (PRUint32 i=0; i<aLength; i++) { |
1154 |
glyph_index = FT_Get_Char_Index((FT_Face)face, aString[i]); |
1124 |
glyph_index = FT_Get_Char_Index((FT_Face)face, aString[i]); |
1155 |
FT_Error error = FTC_Image_Cache_Lookup(mImageCache, &mImageDesc, |
1125 |
if (FT_Load_Glyph(face, glyph_index, FT_LOAD_DEFAULT) || |
1156 |
glyph_index, &glyph); |
1126 |
FT_Get_Glyph(face->glyph, &glyph)) { |
1157 |
if (error) { |
|
|
1158 |
origin_x += FT_REG_TO_16_16(face->size->metrics.x_ppem/2 + 2); |
1127 |
origin_x += FT_REG_TO_16_16(face->size->metrics.x_ppem/2 + 2); |
1159 |
continue; |
1128 |
continue; |
1160 |
} |
1129 |
} |
1161 |
origin_x += glyph->advance.x; |
1130 |
origin_x += glyph->advance.x; |
|
|
1131 |
FT_Done_Glyph(glyph); |
1162 |
} |
1132 |
} |
1163 |
|
1133 |
|
1164 |
NS_ENSURE_TRUE(mFontMetrics, 0); |
1134 |
NS_ENSURE_TRUE(mFontMetrics, 0); |
Lines 2416-2434
Link Here
|
2416 |
mFreeTypeLibrary = nsnull; |
2386 |
mFreeTypeLibrary = nsnull; |
2417 |
return NS_ERROR_FAILURE; |
2387 |
return NS_ERROR_FAILURE; |
2418 |
} |
2388 |
} |
2419 |
error = FTC_Manager_New(mFreeTypeLibrary, 0, 0, 0, nsXftFaceRequester, |
|
|
2420 |
NULL, &mFTCacheManager); |
2421 |
NS_ASSERTION(!error, "failed to create FreeType Cache manager"); |
2422 |
if (error) |
2423 |
return NS_ERROR_FAILURE; |
2424 |
|
2389 |
|
2425 |
return NS_OK; |
2390 |
return NS_OK; |
2426 |
} |
2391 |
} |
2427 |
|
2392 |
|
2428 |
nsXftType8Generator::~nsXftType8Generator() |
2393 |
nsXftType8Generator::~nsXftType8Generator() |
2429 |
{ |
2394 |
{ |
2430 |
FTC_Manager_Done(mFTCacheManager); |
2395 |
if (mEntry->mFace) |
2431 |
|
2396 |
FT_Done_Face(mEntry->mFace); |
2432 |
if (FT_Done_FreeType(mFreeTypeLibrary)) |
2397 |
if (FT_Done_FreeType(mFreeTypeLibrary)) |
2433 |
return; |
2398 |
return; |
2434 |
|
2399 |
|
Lines 2437-2459
Link Here
|
2437 |
|
2402 |
|
2438 |
void nsXftType8Generator::GeneratePSFont(FILE* aFile) |
2403 |
void nsXftType8Generator::GeneratePSFont(FILE* aFile) |
2439 |
{ |
2404 |
{ |
2440 |
FT_Error error; |
|
|
2441 |
FT_Face face = mEntry->mFace; |
2405 |
FT_Face face = mEntry->mFace; |
2442 |
|
2406 |
|
2443 |
if (face == nsnull) { |
2407 |
if (face == nsnull) { |
2444 |
mImageDesc.font.face_id = (void*)mEntry; |
2408 |
if (FT_New_Face(mFreeTypeLibrary, mEntry->mFontFileName.get(), mEntry->mFaceIndex, &face) || |
2445 |
mImageDesc.font.pix_width = 16; |
2409 |
face == nsnull /* || FT_Set_Pixel_Sizes(face, 16, 0) */) |
2446 |
mImageDesc.font.pix_height = 16; |
|
|
2447 |
mImageDesc.image_type = 0; |
2448 |
error = FTC_Manager_Lookup_Size(mFTCacheManager, &mImageDesc.font, |
2449 |
&face, nsnull); |
2450 |
if (error) |
2451 |
return; |
2410 |
return; |
|
|
2411 |
mEntry->mFace = face; |
2452 |
} |
2412 |
} |
2453 |
|
2413 |
|
2454 |
if (face == nsnull) |
|
|
2455 |
return; |
2456 |
|
2457 |
int wmode = 0; |
2414 |
int wmode = 0; |
2458 |
if (!mSubset.IsEmpty()) |
2415 |
if (!mSubset.IsEmpty()) |
2459 |
FT2SubsetToType8(face, mSubset.get(), mSubset.Length(), wmode, aFile); |
2416 |
FT2SubsetToType8(face, mSubset.get(), mSubset.Length(), wmode, aFile); |