2 * This file is part of the KDE project
4 * Copyright (C) 2003 Stephan Kulow (coolo@kde.org)
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
23 #include "ecma/kjs_proxy.h"
25 #define QT_NO_FONTCONFIG 1
26 #define QT_NO_FREETYPE 1
27 #include <private/qfontengine_p.h>
29 # include <private/qfontengine_x11_p.h>
31 #include <QtGui/QFontDatabase>
32 #include <QtGui/QFont>
33 #include "khtml_settings.h"
34 #include <QtGui/QImage>
36 #include <QtGui/QX11Info>
37 #include <QtGui/QPainter>
41 #if QT_VERSION >= 0x040500
53 typedef QFixed QtFontDim
;
55 static int dimToInt(QtFontDim dim
) {
60 static MetricsInfo compatMetrics
[] = {
61 {"-Adobe-Courier-Medium-R-Normal--10-100-75-75-M-60-ISO10646-1", 8, 1, 2},
62 {"-Adobe-Courier-Medium-O-Normal--10-100-75-75-M-60-ISO10646-1", 8, 1, 2},
63 {"-Adobe-Courier-Bold-R-Normal--10-100-75-75-M-60-ISO10646-1", 8, 1, 2},
64 {"-Adobe-Courier-Bold-O-Normal--10-100-75-75-M-60-ISO10646-1", 8, 1, 2},
65 {"-Adobe-Courier-Medium-R-Normal--12-120-75-75-M-70-ISO10646-1", 10, 2, 2},
66 {"-Adobe-Courier-Medium-O-Normal--12-120-75-75-M-70-ISO10646-1", 10, 2, 2},
67 {"-Adobe-Courier-Bold-R-Normal--12-120-75-75-M-70-ISO10646-1", 10, 2, 2},
68 {"-Adobe-Courier-Bold-O-Normal--12-120-75-75-M-70-ISO10646-1", 10, 2, 2},
69 {"-Adobe-Courier-Medium-R-Normal--18-180-75-75-M-110-ISO10646-1", 14, 3, 3},
70 {"-Adobe-Courier-Medium-O-Normal--18-180-75-75-M-110-ISO10646-1", 14, 3, 3},
71 {"-Adobe-Courier-Bold-R-Normal--18-180-75-75-M-110-ISO10646-1", 14, 3, 3},
72 {"-Adobe-Courier-Bold-O-Normal--18-180-75-75-M-110-ISO10646-1", 14, 3, 3},
73 {"-Adobe-Courier-Medium-R-Normal--24-240-75-75-M-150-ISO10646-1", 19, 4, 4},
74 {"-Adobe-Courier-Medium-O-Normal--24-240-75-75-M-150-ISO10646-1", 19, 4, 4},
75 {"-Adobe-Courier-Bold-R-Normal--24-240-75-75-M-150-ISO10646-1", 19, 4, 4},
76 {"-Adobe-Courier-Bold-O-Normal--24-240-75-75-M-150-ISO10646-1", 19, 4, 4},
77 {"-Adobe-Times-Medium-R-Normal--8-80-75-75-P-44-ISO10646-1", 7, 1, 1},
78 {"-Adobe-Times-Medium-R-Normal--8-80-75-75-P-44-ISO10646-1", 7, 1, 1},
79 {"-Adobe-Times-Medium-R-Normal--8-80-75-75-P-44-ISO10646-1", 7, 1, 1},
80 {"-Adobe-Times-Medium-R-Normal--8-80-75-75-P-44-ISO10646-1", 7, 1, 1},
81 {"-Adobe-Times-Medium-R-Normal--8-80-75-75-P-44-ISO10646-1", 7, 1, 1},
82 {"-Adobe-Times-Medium-R-Normal--8-80-75-75-P-44-ISO10646-1", 7, 1, 1},
83 {"-Adobe-Times-Medium-R-Normal--8-80-75-75-P-44-ISO10646-1", 7, 1, 1},
84 {"-Adobe-Times-Medium-R-Normal--8-80-75-75-P-44-ISO10646-1", 7, 1, 1},
85 {"-Adobe-Times-Medium-R-Normal--8-80-75-75-P-44-ISO10646-1", 7, 1, 1},
86 {"-Adobe-Times-Medium-R-Normal--8-80-75-75-P-44-ISO10646-1", 7, 1, 1},
87 {"-Adobe-Times-Medium-R-Normal--8-80-75-75-P-44-ISO10646-1", 7, 1, 1},
88 {"-Adobe-Times-Medium-R-Normal--8-80-75-75-P-44-ISO10646-1", 7, 1, 1},
89 {"-Adobe-Times-Medium-R-Normal--8-80-75-75-P-44-ISO10646-1", 7, 1, 1},
90 {"-Adobe-Times-Medium-R-Normal--8-80-75-75-P-44-ISO10646-1", 7, 1, 1},
91 {"-Adobe-Times-Medium-R-Normal--8-80-75-75-P-44-ISO10646-1", 7, 1, 1},
92 {"-Adobe-Times-Medium-R-Normal--8-80-75-75-P-44-ISO10646-1", 7, 1, 1},
93 {"-Adobe-Helvetica-Medium-R-Normal--10-100-75-75-P-56-ISO10646-1", 10, 1, 2},
94 {"-Adobe-Helvetica-Medium-O-Normal--10-100-75-75-P-57-ISO10646-1", 10, 1, 2},
95 {"-Adobe-Helvetica-Bold-R-Normal--10-100-75-75-P-60-ISO10646-1", 10, 1, 2},
96 {"-Adobe-Helvetica-Bold-O-Normal--10-100-75-75-P-60-ISO10646-1", 10, 1, 2},
97 {"-Adobe-Helvetica-Medium-R-Normal--12-120-75-75-P-67-ISO10646-1", 11, 2, 2},
98 {"-Adobe-Helvetica-Medium-O-Normal--12-120-75-75-P-67-ISO10646-1", 11, 2, 2},
99 {"-Adobe-Helvetica-Bold-R-Normal--12-120-75-75-P-70-ISO10646-1", 11, 2, 2},
100 {"-Adobe-Helvetica-Bold-O-Normal--12-120-75-75-P-69-ISO10646-1", 11, 2, 2},
101 {"-Adobe-Helvetica-Medium-R-Normal--18-180-75-75-P-98-ISO10646-1", 16, 4, 3},
102 {"-Adobe-Helvetica-Medium-O-Normal--18-180-75-75-P-98-ISO10646-1", 16, 4, 3},
103 {"-Adobe-Helvetica-Bold-R-Normal--18-180-75-75-P-103-ISO10646-1", 16, 4, 3},
104 {"-Adobe-Helvetica-Bold-O-Normal--18-180-75-75-P-104-ISO10646-1", 16, 4, 3},
105 {"-Adobe-Helvetica-Medium-R-Normal--24-240-75-75-P-130-ISO10646-1", 22, 4, 4},
106 {"-Adobe-Helvetica-Medium-O-Normal--24-240-75-75-P-130-ISO10646-1", 22, 4, 4},
107 {"-Adobe-Helvetica-Bold-R-Normal--24-240-75-75-P-138-ISO10646-1", 22, 4, 4},
108 {"-Adobe-Helvetica-Bold-O-Normal--24-240-75-75-P-138-ISO10646-1", 22, 4, 4},
109 {"-Adobe-Courier-Medium-R-Normal--10-100-75-75-M-60-ISO10646-1", 8, 1, 2},
110 {"-Adobe-Courier-Medium-O-Normal--10-100-75-75-M-60-ISO10646-1", 8, 1, 2},
111 {"-Adobe-Courier-Bold-R-Normal--10-100-75-75-M-60-ISO10646-1", 8, 1, 2},
112 {"-Adobe-Courier-Bold-O-Normal--10-100-75-75-M-60-ISO10646-1", 8, 1, 2},
113 {"-Adobe-Courier-Medium-R-Normal--12-120-75-75-M-70-ISO10646-1", 10, 2, 2},
114 {"-Adobe-Courier-Medium-O-Normal--12-120-75-75-M-70-ISO10646-1", 10, 2, 2},
115 {"-Adobe-Courier-Bold-R-Normal--12-120-75-75-M-70-ISO10646-1", 10, 2, 2},
116 {"-Adobe-Courier-Bold-O-Normal--12-120-75-75-M-70-ISO10646-1", 10, 2, 2},
117 {"-Adobe-Courier-Medium-R-Normal--18-180-75-75-M-110-ISO10646-1", 14, 3, 3},
118 {"-Adobe-Courier-Medium-O-Normal--18-180-75-75-M-110-ISO10646-1", 14, 3, 3},
119 {"-Adobe-Courier-Bold-R-Normal--18-180-75-75-M-110-ISO10646-1", 14, 3, 3},
120 {"-Adobe-Courier-Bold-O-Normal--18-180-75-75-M-110-ISO10646-1", 14, 3, 3},
121 {"-Adobe-Courier-Medium-R-Normal--24-240-75-75-M-150-ISO10646-1", 19, 4, 4},
122 {"-Adobe-Courier-Medium-O-Normal--24-240-75-75-M-150-ISO10646-1", 19, 4, 4},
123 {"-Adobe-Courier-Bold-R-Normal--24-240-75-75-M-150-ISO10646-1", 19, 4, 4},
124 {"-Adobe-Courier-Bold-O-Normal--24-240-75-75-M-150-ISO10646-1", 19, 4, 4},
125 {"-Adobe-Times-Medium-R-Normal--8-80-75-75-P-44-ISO10646-1", 7, 1, 1},
126 {"-Adobe-Times-Medium-R-Normal--8-80-75-75-P-44-ISO10646-1", 7, 1, 1},
127 {"-Adobe-Times-Medium-R-Normal--8-80-75-75-P-44-ISO10646-1", 7, 1, 1},
128 {"-Adobe-Times-Medium-R-Normal--8-80-75-75-P-44-ISO10646-1", 7, 1, 1},
129 {"-Adobe-Times-Medium-R-Normal--8-80-75-75-P-44-ISO10646-1", 7, 1, 1},
130 {"-Adobe-Times-Medium-R-Normal--8-80-75-75-P-44-ISO10646-1", 7, 1, 1},
131 {"-Adobe-Times-Medium-R-Normal--8-80-75-75-P-44-ISO10646-1", 7, 1, 1},
132 {"-Adobe-Times-Medium-R-Normal--8-80-75-75-P-44-ISO10646-1", 7, 1, 1},
133 {"-Adobe-Times-Medium-R-Normal--8-80-75-75-P-44-ISO10646-1", 7, 1, 1},
134 {"-Adobe-Times-Medium-R-Normal--8-80-75-75-P-44-ISO10646-1", 7, 1, 1},
135 {"-Adobe-Times-Medium-R-Normal--8-80-75-75-P-44-ISO10646-1", 7, 1, 1},
136 {"-Adobe-Times-Medium-R-Normal--8-80-75-75-P-44-ISO10646-1", 7, 1, 1},
137 {"-Adobe-Times-Medium-R-Normal--8-80-75-75-P-44-ISO10646-1", 7, 1, 1},
138 {"-Adobe-Times-Medium-R-Normal--8-80-75-75-P-44-ISO10646-1", 7, 1, 1},
139 {"-Adobe-Times-Medium-R-Normal--8-80-75-75-P-44-ISO10646-1", 7, 1, 1},
140 {"-Adobe-Times-Medium-R-Normal--8-80-75-75-P-44-ISO10646-1", 7, 1, 1},
141 {"-Adobe-Helvetica-Medium-R-Normal--10-100-75-75-P-56-ISO10646-1", 10, 1, 2},
142 {"-Adobe-Helvetica-Medium-O-Normal--10-100-75-75-P-57-ISO10646-1", 10, 1, 2},
143 {"-Adobe-Helvetica-Bold-R-Normal--10-100-75-75-P-60-ISO10646-1", 10, 1, 2},
144 {"-Adobe-Helvetica-Bold-O-Normal--10-100-75-75-P-60-ISO10646-1", 10, 1, 2},
145 {"-Adobe-Helvetica-Medium-R-Normal--12-120-75-75-P-67-ISO10646-1", 11, 2, 2},
146 {"-Adobe-Helvetica-Medium-O-Normal--12-120-75-75-P-67-ISO10646-1", 11, 2, 2},
147 {"-Adobe-Helvetica-Bold-R-Normal--12-120-75-75-P-70-ISO10646-1", 11, 2, 2},
148 {"-Adobe-Helvetica-Bold-O-Normal--12-120-75-75-P-69-ISO10646-1", 11, 2, 2},
149 {"-Adobe-Helvetica-Medium-R-Normal--18-180-75-75-P-98-ISO10646-1", 16, 4, 3},
150 {"-Adobe-Helvetica-Medium-O-Normal--18-180-75-75-P-98-ISO10646-1", 16, 4, 3},
151 {"-Adobe-Helvetica-Bold-R-Normal--18-180-75-75-P-103-ISO10646-1", 16, 4, 3},
152 {"-Adobe-Helvetica-Bold-O-Normal--18-180-75-75-P-104-ISO10646-1", 16, 4, 3},
153 {"-Adobe-Helvetica-Medium-R-Normal--24-240-75-75-P-130-ISO10646-1", 22, 4, 4},
154 {"-Adobe-Helvetica-Medium-O-Normal--24-240-75-75-P-130-ISO10646-1", 22, 4, 4},
155 {"-Adobe-Helvetica-Bold-R-Normal--24-240-75-75-P-138-ISO10646-1", 22, 4, 4},
156 {"-Adobe-Helvetica-Bold-O-Normal--24-240-75-75-P-138-ISO10646-1", 22, 4, 4},
160 static MetricsInfo
* grabMetrics(QString name
)
162 for (int pos
= 0; compatMetrics
[pos
].name
; ++pos
)
163 if (name
== QLatin1String(compatMetrics
[pos
].name
))
164 return &compatMetrics
[pos
];
168 class QFakeFontEngine
: public QFontEngineXLFD
173 QFakeFontEngine( XFontStruct
*fs
, const char *name
, int size
);
177 QtFontDim m_ascent
, m_descent
, m_leading
;
182 QtFontDim
fallBackWidth() const {
183 QtFontDim fbw
= xfs
->min_bounds
.width
;
186 fbw
= m_ascent
; //### we really should get rid of these and regen..
194 void recalcAdvances(QGlyphLayout
*glyphs
, QTextEngine::ShaperFlags flags
) const
196 QFontEngineXLFD::recalcAdvances(glyphs
, flags
);
198 // Go through the glyhs with glyph 0 and fix up their x advance
199 // to make sense (or at least match Qt3)
200 QtFontDim fbw
= fallBackWidth();
202 for (int c
= 0; c
< glyphs
->numGlyphs
; ++c
) {
203 if (!glyphs
->glyphs
[c
])
204 glyphs
->advances_x
[c
] = fbw
;
208 void recalcAdvances(int len
, QGlyphLayout
*glyphs
, QTextEngine::ShaperFlags flags
) const
210 QFontEngineXLFD::recalcAdvances(len
, glyphs
, flags
);
212 // Go through the glyhs with glyph 0 and fix up their x advance
213 // to make sense (or at least match Qt3)
214 QtFontDim fbw
= fallBackWidth();
216 QGlyphLayout
* g
= glyphs
+ len
;
217 while (g
!= glyphs
) {
229 return QFontEngine::Freetype
;
231 return QFontEngine::XLFD
;
235 QtFontDim
ascent() const
240 return QFontEngineXLFD::ascent();
243 QtFontDim
descent() const
248 return QFontEngineXLFD::descent();
251 QtFontDim
leading() const
255 else if (haveMetrics
)
258 return QFontEngineXLFD::leading();
261 bool canRender( const QChar
*string
, int len
);
264 //OK. This is evil. Since we don't use Xft, we hijack the FreeType painting hook in the X11 engine
265 //for ahem, as unfortunately the drawing is in the paint engine, and not the font engine in Qt4
267 class KDE_EXPORT QX11PaintEngine
: public QPaintEngine
269 void drawFreetype(const QPointF
&p
, const QTextItemInt
&si
);
272 void QX11PaintEngine::drawFreetype(const QPointF
&p
, const QTextItemInt
&si
)
275 int cnt
= si
.glyphs
.numGlyphs
;
277 int cnt
= si
.num_glyph
;
283 QFakeFontEngine
*eng
= static_cast<QFakeFontEngine
*>(si
.fontEngine
);
288 int pixS
= int(eng
->pixS
);
290 int ascent
= dimToInt(eng
->ascent());
291 int descent
= dimToInt(eng
->descent());
293 if (si
.flags
& QTextItem::RightToLeft
)
295 x
= x
+ advance
* (cnt
- 1);
299 for (int pos
= 0; pos
< cnt
; ++pos
)
304 switch (si
.chars
[pos
].unicode())
306 switch (si
.glyphs
[pos
].glyph
)
313 //Below the baseline, including it
314 rect
= QRect(x
, y
, pixS
, descent
+ 1);
318 rect
= QRect(x
, y
- ascent
, pixS
, ascent
);
322 rect
= QRect(x
, y
- ascent
, pixS
, pixS
);
325 QPainter
* p
= painter();
326 p
->fillRect(rect
, p
->pen().color());
333 QFakeFontEngine::QFakeFontEngine( XFontStruct
*fs
, const char *name
, int size
)
334 : QFontEngineXLFD( fs
, name
, 0)
338 this->name
= QLatin1String(name
);
339 ahem
= this->name
.contains("ahem");
341 MetricsInfo
* metrics
= grabMetrics(name
);
345 m_ascent
= metrics
->ascent
;
346 m_descent
= metrics
->descent
;
347 m_leading
= metrics
->leading
;
353 QFakeFontEngine::~QFakeFontEngine()
358 bool QFakeFontEngine::canRender( const QChar
*, int )
363 static QString
courier_pickxlfd( int pixelsize
, bool italic
, bool bold
)
365 if ( pixelsize
>= 24 )
367 else if ( pixelsize
>= 18 )
369 else if ( pixelsize
>= 12 )
374 return QString( "-adobe-courier-%1-%2-normal--%3-*-75-75-m-*-iso10646-1" ).arg( bold
? "bold" : "medium" ).arg( italic
? "o" : "r" ).arg( pixelsize
);
377 static QString
ahem_pickxlfd( int pixelsize
)
379 return QString( "-misc-ahem-medium-r-normal--%1-*-100-100-c-*-iso10646-1" ).arg( pixelsize
);
382 static QString
helv_pickxlfd( int pixelsize
, bool italic
, bool bold
)
384 if ( pixelsize
>= 24 )
386 else if ( pixelsize
>= 18 )
388 else if ( pixelsize
>= 12 )
393 return QString( "-adobe-helvetica-%1-%2-normal--%3-*-75-75-p-*-iso10646-1" ).arg( bold
? "bold" : "medium" ).arg( italic
? "o" : "r" ).arg( pixelsize
);
397 static QFontEngine
* loadFont(const QFontDef
& request
)
400 QString family
= request
.family
.toLower();
401 if ( family
== "adobe courier" || family
== "courier" || family
== "fixed" ) {
402 xlfd
= courier_pickxlfd( request
.pixelSize
, request
.style
== QFont::StyleItalic
, request
.weight
> 50 );
404 else if ( family
== "times new roman" || family
== "times" )
405 xlfd
= "-adobe-times-medium-r-normal--8-80-75-75-p-44-iso10646-1";
406 else if ( family
== "ahem" )
407 xlfd
= ahem_pickxlfd( request
.pixelSize
);
409 xlfd
= helv_pickxlfd( request
.pixelSize
, request
.style
== QFont::StyleItalic
, request
.weight
> 50 );
414 xfs
= XLoadQueryFont( QX11Info::display(), xlfd
.toLatin1() );
415 if (!xfs
) // as long as you don't do screenshots, it's maybe fine
416 qFatal("we need some fonts. So make sure you have %s installed.", qPrintable(xlfd
));
419 if ( !XGetFontProperty( xfs
, XA_FONT
, &value
) )
422 char *n
= XGetAtomName( QX11Info::display(), value
);
427 fe
= new QFakeFontEngine( xfs
, xlfd
.toLatin1(),request
.pixelSize
);
432 QFontEngine
*QFontDatabase::loadXlfd(int /* screen */, int /* script */,
433 const QFontDef
&request
, int /* force_encoding_id */)
435 return loadFont(request
);
438 extern "C" KDE_EXPORT
int FcInit() {
439 /* Make sure Qt uses the Xlfd path, which we intercept */
443 KDE_EXPORT
bool QFontDatabase::isBitmapScalable( const QString
&,
444 const QString
&) const
449 KDE_EXPORT
bool QFontDatabase::isSmoothlyScalable( const QString
&,
450 const QString
&) const
455 const QString
&KHTMLSettings::availableFamilies()
458 avFamilies
= new QString
;
459 *avFamilies
= ",Adobe Courier,Arial,Comic Sans MS,Courier,Helvetica,Times,Times New Roman,Utopia,Fixed,Ahem,";
466 bool KHTMLSettings::unfinishedImageFrame() const
471 KDE_EXPORT
int QX11Info::appDpiY( int )
476 KDE_EXPORT
int QX11Info::appDpiX( int )
481 KDE_EXPORT
void QFont::insertSubstitution(const QString
&,
486 KDE_EXPORT
void QFont::insertSubstitutions(const QString
&,
491 #include <kprotocolinfo.h>
492 bool KProtocolInfo::isKnownProtocol( const QString
& _protocol
)
494 return ( _protocol
== "file" );
497 #include <kprotocolinfofactory.h>
499 QString
KProtocolInfo::exec( const QString
& _protocol
)
501 if ( _protocol
!= "file" )
504 KProtocolInfo::Ptr prot
= KProtocolInfoFactory::self()->findProtocol(_protocol
);
511 #include <dcopclient.h>
513 bool DCOPClient::attach()
518 bool DCOPClient::isAttached() const
523 void DCOPClient::processSocketData( int )
527 #include <QtGui/QApplication>
528 #include <QtGui/QPalette>
531 KDE_EXPORT
void QApplication::setPalette( const QPalette
&, bool ,
534 static bool done
= false;
538 xfs
= XLoadQueryFont(QPaintDevice::x11AppDisplay(), xlfd
.toLatin1().constData() );
539 if (!xfs
) // as long as you don't do screenshots, it's maybe fine
540 qFatal("We will need some fonts. So make sure you have %s installed.", xlfd
.toLatin1().constData());
541 XFreeFont(QPaintDevice::x11AppDisplay(), xfs
);
546 #include <kapplication.h>
547 // void KApplication::dcopFailure( const QString & )
549 // qDebug( "KApplication::dcopFailure" );
552 #include <kparts/historyprovider.h>
554 bool KParts::HistoryProvider::contains( const QString
& t
) const
556 return ( t
== "http://www.kde.org/" || t
== "http://www.google.com/");
560 #include <ksslsettings.h>
562 bool KSSLSettings::warnOnEnter() const { return false; }
563 bool KSSLSettings::warnOnUnencrypted() const { return false; }
564 bool KSSLSettings::warnOnLeave() const { return false; }
566 #include <kparts/plugin.h>
568 KParts::Plugin
* KParts::Plugin::loadPlugin( QObject
* /* parent */, const char* /* libname */) { return 0; }