|
Lines 98-103
Link Here
|
| 98 |
#include "qtextlayout_p.h" |
98 |
#include "qtextlayout_p.h" |
| 99 |
#include "qtextengine_p.h" |
99 |
#include "qtextengine_p.h" |
| 100 |
extern bool qt_has_xft; |
100 |
extern bool qt_has_xft; |
|
|
101 |
|
| 102 |
#ifndef QT_NO_XFTFREETYPE |
| 103 |
#include <ft2build.h> |
| 104 |
#include FT_OUTLINE_H |
| 105 |
#endif |
| 106 |
|
| 101 |
#endif |
107 |
#endif |
| 102 |
|
108 |
|
| 103 |
static bool qt_gen_epsf = FALSE; |
109 |
static bool qt_gen_epsf = FALSE; |
|
Lines 2076-2081
Link Here
|
| 2076 |
|
2082 |
|
| 2077 |
// ================== TTF ==================== |
2083 |
// ================== TTF ==================== |
| 2078 |
|
2084 |
|
|
|
2085 |
#ifndef QT_NO_XFTFREETYPE |
| 2086 |
|
| 2087 |
static void |
| 2088 |
getXftData( const QFontEngine *engine, |
| 2089 |
int &index, int &weight, int &slant, XftMatrix &matrix ) |
| 2090 |
{ |
| 2091 |
XftPattern* font = static_cast<const QFontEngineXft *>( engine )->pattern(); |
| 2092 |
XftMatrix unit = { 1.0, 0, 0, 1.0 }; |
| 2093 |
XftMatrix* mat; |
| 2094 |
|
| 2095 |
index = 0; |
| 2096 |
weight = XFT_WEIGHT_MEDIUM; |
| 2097 |
slant = XFT_SLANT_ROMAN; |
| 2098 |
matrix = unit; |
| 2099 |
|
| 2100 |
XftPatternGetInteger( font, XFT_INDEX, 0, &index ); |
| 2101 |
XftPatternGetInteger( font, XFT_WEIGHT, 0, &weight ); |
| 2102 |
XftPatternGetInteger( font, XFT_SLANT, 0, &slant ); |
| 2103 |
|
| 2104 |
if ( XftPatternGetMatrix( font, XFT_MATRIX, 0, &mat ) == XftResultMatch ) |
| 2105 |
matrix = *mat; |
| 2106 |
} |
| 2107 |
|
| 2108 |
#endif // QT_NO_XFTFREETYPE |
| 2109 |
|
| 2110 |
|
| 2079 |
typedef Q_UINT8 BYTE; |
2111 |
typedef Q_UINT8 BYTE; |
| 2080 |
typedef Q_UINT16 USHORT; |
2112 |
typedef Q_UINT16 USHORT; |
| 2081 |
typedef Q_UINT16 uFWord; |
2113 |
typedef Q_UINT16 uFWord; |
|
Lines 2184-2189
Link Here
|
| 2184 |
|
2216 |
|
| 2185 |
int indexToLocFormat; /* short or long offsets */ |
2217 |
int indexToLocFormat; /* short or long offsets */ |
| 2186 |
|
2218 |
|
|
|
2219 |
#ifndef QT_NO_XFTFREETYPE |
| 2220 |
FT_Face face; |
| 2221 |
int index; |
| 2222 |
int weight; |
| 2223 |
int slant; |
| 2224 |
XftMatrix matrix; |
| 2225 |
|
| 2226 |
QString StyleName_Extension; |
| 2227 |
#endif // QT_NO_XFTFREETYPE |
| 2228 |
|
| 2187 |
}; |
2229 |
}; |
| 2188 |
|
2230 |
|
| 2189 |
|
2231 |
|
|
Lines 2293-2298
Link Here
|
| 2293 |
#endif |
2335 |
#endif |
| 2294 |
offset_table = (unsigned char*) data.data(); /* first 12 bytes */ |
2336 |
offset_table = (unsigned char*) data.data(); /* first 12 bytes */ |
| 2295 |
|
2337 |
|
|
|
2338 |
#ifndef QT_NO_XFTFREETYPE |
| 2339 |
if ( target_type == 42 ) { |
| 2340 |
if ( !( d[0] == '0' && d[1] == '1' && d[2] == '0' && d[3] == '0' ) ) { |
| 2341 |
defective = TRUE; |
| 2342 |
return; |
| 2343 |
} |
| 2344 |
} |
| 2345 |
|
| 2346 |
face = 0; |
| 2347 |
StyleName_Extension = ""; |
| 2348 |
getXftData( f, index, weight, slant, matrix ); |
| 2349 |
|
| 2350 |
if ( qt_has_xft && f->type() == QFontEngine::Xft ) { |
| 2351 |
extern FT_Library _XftFTlibrary; |
| 2352 |
|
| 2353 |
if ( FT_New_Memory_Face( _XftFTlibrary, |
| 2354 |
(const FT_Byte*)data.data(), |
| 2355 |
data.size(), index, &face ) || |
| 2356 |
( face->face_flags & FT_FACE_FLAG_SCALABLE ) == 0 ) { |
| 2357 |
defective = TRUE; |
| 2358 |
return; |
| 2359 |
} |
| 2360 |
|
| 2361 |
FT_Set_Pixel_Sizes( face, 1000, 1000 ); |
| 2362 |
|
| 2363 |
bool bold = ( face->style_flags & FT_STYLE_FLAG_BOLD ) != 0; |
| 2364 |
bool italic = ( face->style_flags & FT_STYLE_FLAG_ITALIC ) != 0; |
| 2365 |
|
| 2366 |
if ( weight > XFT_WEIGHT_MEDIUM && !bold ) |
| 2367 |
StyleName_Extension += "Bold"; |
| 2368 |
if ( slant > XFT_SLANT_ROMAN && !italic ) |
| 2369 |
StyleName_Extension += "Oblique"; |
| 2370 |
|
| 2371 |
if ( !StyleName_Extension.isEmpty() ) |
| 2372 |
StyleName_Extension = "-" + StyleName_Extension; |
| 2373 |
|
| 2374 |
if ( matrix.xx != 1.0 || matrix.xy != 0.0 || |
| 2375 |
matrix.yx != 0.0 || matrix.yy != 1.0 ) |
| 2376 |
StyleName_Extension += QString( "-%1-%2-%3-%4" ) |
| 2377 |
.arg( matrix.xx, 0, 'f' ) |
| 2378 |
.arg( matrix.yx, 0, 'f' ) |
| 2379 |
.arg( matrix.xy, 0, 'f' ) |
| 2380 |
.arg( matrix.yy, 0, 'f' ); |
| 2381 |
|
| 2382 |
StyleName_Extension.replace( '.', '_' ); |
| 2383 |
} |
| 2384 |
|
| 2385 |
if ( d[0] == 't' && d[1] == 't' && d[2] == 'c' && d[3] == 'f' ) |
| 2386 |
offset_table += getULONG( offset_table + 12 + 4 * index ); |
| 2387 |
#endif |
| 2388 |
|
| 2389 |
|
| 2296 |
/* Determine how many directory entries there are. */ |
2390 |
/* Determine how many directory entries there are. */ |
| 2297 |
numTables = getUSHORT( offset_table + 4 ); |
2391 |
numTables = getUSHORT( offset_table + 4 ); |
| 2298 |
|
2392 |
|
|
Lines 2404-2409
Link Here
|
| 2404 |
// qDebug("number of glyphs is %d", numGlyphs); |
2498 |
// qDebug("number of glyphs is %d", numGlyphs); |
| 2405 |
replacementList = makePSFontNameList( f, psname ); |
2499 |
replacementList = makePSFontNameList( f, psname ); |
| 2406 |
uni2glyphSetup(); |
2500 |
uni2glyphSetup(); |
|
|
2501 |
|
| 2502 |
#ifndef QT_NO_XFTFREETYPE |
| 2503 |
psname += StyleName_Extension; |
| 2504 |
FullName += StyleName_Extension; |
| 2505 |
#endif |
| 2407 |
} |
2506 |
} |
| 2408 |
|
2507 |
|
| 2409 |
|
2508 |
|
|
Lines 2520-2526
Link Here
|
| 2520 |
if( target_type == 42 ) |
2619 |
if( target_type == 42 ) |
| 2521 |
s << "%%Creator: Converted from TrueType to type 42 by Qt\n"; |
2620 |
s << "%%Creator: Converted from TrueType to type 42 by Qt\n"; |
| 2522 |
else |
2621 |
else |
| 2523 |
s << "%%Creator: Converted from TrueType by Qt\n"; |
2622 |
s << "%%Creator: Converted from TrueType/OpenType by Qt\n"; |
| 2524 |
|
2623 |
|
| 2525 |
/* If VM usage information is available, print it. */ |
2624 |
/* If VM usage information is available, print it. */ |
| 2526 |
if( target_type == 42 && post_table) |
2625 |
if( target_type == 42 && post_table) |
|
Lines 2542-2548
Link Here
|
| 2542 |
s << "/_d{bind def}bind def\n"; |
2641 |
s << "/_d{bind def}bind def\n"; |
| 2543 |
s << "/_m{moveto}_d\n"; |
2642 |
s << "/_m{moveto}_d\n"; |
| 2544 |
s << "/_l{lineto}_d\n"; |
2643 |
s << "/_l{lineto}_d\n"; |
| 2545 |
s << "/_cl{closepath eofill}_d\n"; |
2644 |
s << "/_cl{closepath fill}_d\n"; |
| 2546 |
s << "/_c{curveto}_d\n"; |
2645 |
s << "/_c{curveto}_d\n"; |
| 2547 |
s << "/_sc{7 -1 roll{setcachedevice}{pop pop pop pop pop pop}ifelse}_d\n"; |
2646 |
s << "/_sc{7 -1 roll{setcachedevice}{pop pop pop pop pop pop}ifelse}_d\n"; |
| 2548 |
s << "/_e{exec}_d\n"; |
2647 |
s << "/_e{exec}_d\n"; |
|
Lines 2556-2562
Link Here
|
| 2556 |
if(target_type == 42) |
2655 |
if(target_type == 42) |
| 2557 |
s << "/FontMatrix[1 0 0 1 0 0]def\n"; |
2656 |
s << "/FontMatrix[1 0 0 1 0 0]def\n"; |
| 2558 |
else |
2657 |
else |
|
|
2658 |
#ifndef QT_NO_XFTFREETYPE |
| 2659 |
s << QString( "/FontMatrix[%1 %2 %3 %4 0 0]def\n" ) |
| 2660 |
.arg( 0.001 * matrix.xx, 0, 'f', 6 ) |
| 2661 |
.arg( 0.001 * matrix.yx, 0, 'f', 6 ) |
| 2662 |
.arg( 0.001 * matrix.xy, 0, 'f', 6 ) |
| 2663 |
.arg( 0.001 * matrix.yy, 0, 'f', 6 ); |
| 2664 |
#else |
| 2559 |
s << "/FontMatrix[.001 0 0 .001 0 0]def\n"; |
2665 |
s << "/FontMatrix[.001 0 0 .001 0 0]def\n"; |
|
|
2666 |
#endif |
| 2560 |
|
2667 |
|
| 2561 |
s << "/FontBBox["; |
2668 |
s << "/FontBBox["; |
| 2562 |
s<< llx; |
2669 |
s<< llx; |
|
Lines 2699-2704
Link Here
|
| 2699 |
|
2806 |
|
| 2700 |
s << "end readonly def\n"; |
2807 |
s << "end readonly def\n"; |
| 2701 |
|
2808 |
|
|
|
2809 |
if ( face ) { |
| 2810 |
FT_Done_Face( face ); |
| 2811 |
face = 0; |
| 2812 |
} |
| 2813 |
|
| 2702 |
// === trailer === |
2814 |
// === trailer === |
| 2703 |
|
2815 |
|
| 2704 |
/* If we are generating a type 3 font, we need to provide */ |
2816 |
/* If we are generating a type 3 font, we need to provide */ |
|
Lines 2841-2847
Link Here
|
| 2841 |
offset = getULONG( ptr + 8 ); |
2953 |
offset = getULONG( ptr + 8 ); |
| 2842 |
//length = getULONG( ptr + 12 ); |
2954 |
//length = getULONG( ptr + 12 ); |
| 2843 |
|
2955 |
|
| 2844 |
table = offset_table + offset; |
2956 |
table = (BYTE*)data.data() + offset; |
| 2845 |
return table; |
2957 |
return table; |
| 2846 |
} |
2958 |
} |
| 2847 |
|
2959 |
|
|
Lines 3344-3349
Link Here
|
| 3344 |
} |
3456 |
} |
| 3345 |
} |
3457 |
} |
| 3346 |
|
3458 |
|
|
|
3459 |
|
| 3460 |
#ifndef QT_NO_XFTFREETYPE |
| 3461 |
|
| 3462 |
#undef DOWNSCALE |
| 3463 |
#define DOWNSCALE( x ) ( ( (x) + 32 ) >> 6 ) |
| 3464 |
|
| 3465 |
extern "C" { |
| 3466 |
|
| 3467 |
static FT_Vector from; |
| 3468 |
|
| 3469 |
static FT_Error |
| 3470 |
PSMovetoFT( FT_Vector* to, QTextStream *s ) |
| 3471 |
{ |
| 3472 |
if ( !to ) { |
| 3473 |
stack( 100, 1, *s ); |
| 3474 |
(*s) << " _cl"; |
| 3475 |
} else { |
| 3476 |
stack( 100, 3, *s ); |
| 3477 |
(*s) << DOWNSCALE( to->x ) << " " |
| 3478 |
<< DOWNSCALE( to->y ) << " _m\n"; |
| 3479 |
from = *to; |
| 3480 |
} |
| 3481 |
|
| 3482 |
return FT_Err_Ok; |
| 3483 |
} |
| 3484 |
|
| 3485 |
static FT_Error |
| 3486 |
PSLinetoFT( FT_Vector* to, |
| 3487 |
QTextStream *s ) |
| 3488 |
{ |
| 3489 |
stack( 100, 3, *s ); |
| 3490 |
(*s) << DOWNSCALE( to->x ) << " " |
| 3491 |
<< DOWNSCALE( to->y ) << " _l\n"; |
| 3492 |
from = *to; |
| 3493 |
return FT_Err_Ok; |
| 3494 |
} |
| 3495 |
|
| 3496 |
static FT_Error |
| 3497 |
PSCubictoFT( FT_Vector* ctrl1, FT_Vector* ctrl2, FT_Vector* to, |
| 3498 |
QTextStream *s ) |
| 3499 |
{ |
| 3500 |
stack( 100, 7, *s ); |
| 3501 |
(*s) << DOWNSCALE( ctrl1->x ) << " " |
| 3502 |
<< DOWNSCALE( ctrl1->y ) << " " |
| 3503 |
<< DOWNSCALE( ctrl2->x ) << " " |
| 3504 |
<< DOWNSCALE( ctrl2->y ) << " " |
| 3505 |
<< DOWNSCALE( to->x ) << " " |
| 3506 |
<< DOWNSCALE( to->y ) << " _c\n"; |
| 3507 |
from = *to; |
| 3508 |
return FT_Err_Ok; |
| 3509 |
} |
| 3510 |
|
| 3511 |
static FT_Error |
| 3512 |
PSConictoFT( FT_Vector* ctrl, FT_Vector* to, |
| 3513 |
QTextStream *s ) |
| 3514 |
{ |
| 3515 |
FT_Vector ctrl1, ctrl2; |
| 3516 |
|
| 3517 |
|
| 3518 |
ctrl1.x = ( from.x + 2*ctrl->x ) / 3; |
| 3519 |
ctrl1.y = ( from.y + 2*ctrl->y ) / 3; |
| 3520 |
ctrl2.x = ( to->x + 2*ctrl->x ) / 3; |
| 3521 |
ctrl2.y = ( to->y + 2*ctrl->y ) / 3; |
| 3522 |
|
| 3523 |
return PSCubictoFT( &ctrl1, &ctrl2, to, s ); |
| 3524 |
} |
| 3525 |
|
| 3526 |
} // extern "C" |
| 3527 |
|
| 3528 |
static void |
| 3529 |
charprocFT( FT_Face face, FT_UInt glyph_index, |
| 3530 |
int weight, int slant, QTextStream &s ) |
| 3531 |
{ |
| 3532 |
static const FT_Outline_Funcs funcs = |
| 3533 |
{ |
| 3534 |
(FT_Outline_MoveToFunc) PSMovetoFT, |
| 3535 |
(FT_Outline_LineToFunc) PSLinetoFT, |
| 3536 |
(FT_Outline_ConicToFunc) PSConictoFT, |
| 3537 |
(FT_Outline_CubicToFunc) PSCubictoFT, |
| 3538 |
0, 0 |
| 3539 |
}; |
| 3540 |
|
| 3541 |
FT_Int32 load_flags = FT_LOAD_NO_BITMAP | |
| 3542 |
FT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH; |
| 3543 |
|
| 3544 |
Q_UNUSED( weight ); |
| 3545 |
Q_UNUSED( slant ); |
| 3546 |
|
| 3547 |
if ( !FT_Load_Glyph( face, glyph_index, load_flags ) ) { |
| 3548 |
FT_Glyph_Metrics* metrics = &face->glyph->metrics; |
| 3549 |
|
| 3550 |
stack( 100, 7, s ); |
| 3551 |
s << ( ( face->glyph->linearHoriAdvance + 0x8000L ) >> 16 ); |
| 3552 |
s << " 0 "; |
| 3553 |
s << DOWNSCALE( metrics->horiBearingX ); |
| 3554 |
s << " "; |
| 3555 |
s << DOWNSCALE( metrics->horiBearingY - metrics->height ); |
| 3556 |
s << " "; |
| 3557 |
s << DOWNSCALE( metrics->horiBearingX + metrics->width ); |
| 3558 |
s << " "; |
| 3559 |
s << DOWNSCALE( metrics->horiBearingY ); |
| 3560 |
s << " _sc\n"; |
| 3561 |
|
| 3562 |
FT_Outline_Decompose( &face->glyph->outline, &funcs, &s ); |
| 3563 |
PSMovetoFT( 0, &s ); |
| 3564 |
|
| 3565 |
} else { |
| 3566 |
stack( 7, 7, s ); |
| 3567 |
s << "0 0 0 0 0 0 0 _sc\n"; |
| 3568 |
} |
| 3569 |
|
| 3570 |
stack_end( s ); |
| 3571 |
return; |
| 3572 |
} |
| 3573 |
|
| 3574 |
#endif // QT_NO_XFTFREETYPE |
| 3575 |
|
| 3347 |
// postscript drawing commands |
3576 |
// postscript drawing commands |
| 3348 |
|
3577 |
|
| 3349 |
static void PSMoveto(FWord x, FWord y, QTextStream& ts) |
3578 |
static void PSMoveto(FWord x, FWord y, QTextStream& ts) |
|
Lines 3738-3743
Link Here
|
| 3738 |
charproc_data cd; |
3967 |
charproc_data cd; |
| 3739 |
|
3968 |
|
| 3740 |
glyphset[charindex] = TRUE; |
3969 |
glyphset[charindex] = TRUE; |
|
|
3970 |
|
| 3971 |
#ifndef QT_NO_XFTFREETYPE |
| 3972 |
if ( face ) |
| 3973 |
return; |
| 3974 |
#endif // QT_NO_XFTFREETYPE |
| 3975 |
|
| 3741 |
//printf("subsetting %s ==> ",glyphName(charindex).latin1()); |
3976 |
//printf("subsetting %s ==> ",glyphName(charindex).latin1()); |
| 3742 |
|
3977 |
|
| 3743 |
/* Get a pointer to the data. */ |
3978 |
/* Get a pointer to the data. */ |
|
Lines 3939-3944
Link Here
|
| 3939 |
s << "\n"; |
4174 |
s << "\n"; |
| 3940 |
#endif |
4175 |
#endif |
| 3941 |
|
4176 |
|
|
|
4177 |
if ( face ) { |
| 4178 |
charprocFT( face, charindex, weight, slant, s ); |
| 4179 |
return; |
| 4180 |
} |
| 4181 |
|
| 3942 |
/* Get a pointer to the data. */ |
4182 |
/* Get a pointer to the data. */ |
| 3943 |
BYTE* glyph = charprocFindGlyphData( charindex ); |
4183 |
BYTE* glyph = charprocFindGlyphData( charindex ); |
| 3944 |
|
4184 |
|
|
Lines 4885-4899
Link Here
|
| 4885 |
XftPattern *pattern = static_cast<QFontEngineXft *>( engine )->pattern(); |
5125 |
XftPattern *pattern = static_cast<QFontEngineXft *>( engine )->pattern(); |
| 4886 |
//qDebug("xfthandle=%p", font); |
5126 |
//qDebug("xfthandle=%p", font); |
| 4887 |
char *filename = 0; |
5127 |
char *filename = 0; |
| 4888 |
XftResult res; |
5128 |
XftPatternGetString (pattern, XFT_FILE, 0, &filename); |
| 4889 |
XftPattern *f = XftFontMatch(qt_xdisplay(), 0, pattern, &res); |
|
|
| 4890 |
XftPatternGetString (f, XFT_FILE, 0, &filename); |
| 4891 |
//qDebug("filename for font is '%s'", filename); |
5129 |
//qDebug("filename for font is '%s'", filename); |
|
|
5130 |
|
| 5131 |
int index, weight, slant; |
| 5132 |
XftMatrix matrix; |
| 5133 |
getXftData (engine, index, weight, slant, matrix); |
| 5134 |
|
| 5135 |
QString style = QString("-I%1-W%2-S%3-M[%4,%5,%6,%7]") |
| 5136 |
.arg(index).arg(weight).arg(slant) |
| 5137 |
.arg(matrix.xx).arg(matrix.xy) |
| 5138 |
.arg(matrix.yx).arg(matrix.yy); |
| 5139 |
|
| 4892 |
if ( filename ) { |
5140 |
if ( filename ) { |
| 4893 |
fontfilename = QString::fromLatin1( filename ); |
5141 |
fontfilename = QString::fromLatin1( filename ); |
| 4894 |
xfontname = fontfilename; |
5142 |
xfontname = fontfilename + style; |
| 4895 |
} |
5143 |
} |
| 4896 |
XftPatternDestroy( f ); |
|
|
| 4897 |
} else |
5144 |
} else |
| 4898 |
#endif |
5145 |
#endif |
| 4899 |
{ |
5146 |
{ |
|
Lines 5031-5036
Link Here
|
| 5031 |
type = PFA; |
5278 |
type = PFA; |
| 5032 |
else if (d[0]==0x00 && d[1]==0x01 && d[2]==0x00 && d[3]==0x00) |
5279 |
else if (d[0]==0x00 && d[1]==0x01 && d[2]==0x00 && d[3]==0x00) |
| 5033 |
type = TTF; |
5280 |
type = TTF; |
|
|
5281 |
#ifndef QT_NO_XFTFREETYPE |
| 5282 |
else if (d[0]=='t' && d[1]=='t' && d[2]=='c' && d[3]=='f') |
| 5283 |
type = TTF; |
| 5284 |
else if (d[0]=='O' && d[1]=='T' && d[2]=='T' && d[3]=='O') |
| 5285 |
type = TTF; |
| 5286 |
#endif // QT_NO_XFTFREETYPE |
| 5034 |
else |
5287 |
else |
| 5035 |
type = NONE; |
5288 |
type = NONE; |
| 5036 |
} else |
5289 |
} else |