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