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>
48 typedef QFixed QtFontDim
;
50 static int dimToInt(QtFontDim dim
) {
55 static MetricsInfo compatMetrics
[] = {
56 {"-Adobe-Courier-Medium-R-Normal--10-100-75-75-M-60-ISO10646-1", 8, 1, 2},
57 {"-Adobe-Courier-Medium-O-Normal--10-100-75-75-M-60-ISO10646-1", 8, 1, 2},
58 {"-Adobe-Courier-Bold-R-Normal--10-100-75-75-M-60-ISO10646-1", 8, 1, 2},
59 {"-Adobe-Courier-Bold-O-Normal--10-100-75-75-M-60-ISO10646-1", 8, 1, 2},
60 {"-Adobe-Courier-Medium-R-Normal--12-120-75-75-M-70-ISO10646-1", 10, 2, 2},
61 {"-Adobe-Courier-Medium-O-Normal--12-120-75-75-M-70-ISO10646-1", 10, 2, 2},
62 {"-Adobe-Courier-Bold-R-Normal--12-120-75-75-M-70-ISO10646-1", 10, 2, 2},
63 {"-Adobe-Courier-Bold-O-Normal--12-120-75-75-M-70-ISO10646-1", 10, 2, 2},
64 {"-Adobe-Courier-Medium-R-Normal--18-180-75-75-M-110-ISO10646-1", 14, 3, 3},
65 {"-Adobe-Courier-Medium-O-Normal--18-180-75-75-M-110-ISO10646-1", 14, 3, 3},
66 {"-Adobe-Courier-Bold-R-Normal--18-180-75-75-M-110-ISO10646-1", 14, 3, 3},
67 {"-Adobe-Courier-Bold-O-Normal--18-180-75-75-M-110-ISO10646-1", 14, 3, 3},
68 {"-Adobe-Courier-Medium-R-Normal--24-240-75-75-M-150-ISO10646-1", 19, 4, 4},
69 {"-Adobe-Courier-Medium-O-Normal--24-240-75-75-M-150-ISO10646-1", 19, 4, 4},
70 {"-Adobe-Courier-Bold-R-Normal--24-240-75-75-M-150-ISO10646-1", 19, 4, 4},
71 {"-Adobe-Courier-Bold-O-Normal--24-240-75-75-M-150-ISO10646-1", 19, 4, 4},
72 {"-Adobe-Times-Medium-R-Normal--8-80-75-75-P-44-ISO10646-1", 7, 1, 1},
73 {"-Adobe-Times-Medium-R-Normal--8-80-75-75-P-44-ISO10646-1", 7, 1, 1},
74 {"-Adobe-Times-Medium-R-Normal--8-80-75-75-P-44-ISO10646-1", 7, 1, 1},
75 {"-Adobe-Times-Medium-R-Normal--8-80-75-75-P-44-ISO10646-1", 7, 1, 1},
76 {"-Adobe-Times-Medium-R-Normal--8-80-75-75-P-44-ISO10646-1", 7, 1, 1},
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-Helvetica-Medium-R-Normal--10-100-75-75-P-56-ISO10646-1", 10, 1, 2},
89 {"-Adobe-Helvetica-Medium-O-Normal--10-100-75-75-P-57-ISO10646-1", 10, 1, 2},
90 {"-Adobe-Helvetica-Bold-R-Normal--10-100-75-75-P-60-ISO10646-1", 10, 1, 2},
91 {"-Adobe-Helvetica-Bold-O-Normal--10-100-75-75-P-60-ISO10646-1", 10, 1, 2},
92 {"-Adobe-Helvetica-Medium-R-Normal--12-120-75-75-P-67-ISO10646-1", 11, 2, 2},
93 {"-Adobe-Helvetica-Medium-O-Normal--12-120-75-75-P-67-ISO10646-1", 11, 2, 2},
94 {"-Adobe-Helvetica-Bold-R-Normal--12-120-75-75-P-70-ISO10646-1", 11, 2, 2},
95 {"-Adobe-Helvetica-Bold-O-Normal--12-120-75-75-P-69-ISO10646-1", 11, 2, 2},
96 {"-Adobe-Helvetica-Medium-R-Normal--18-180-75-75-P-98-ISO10646-1", 16, 4, 3},
97 {"-Adobe-Helvetica-Medium-O-Normal--18-180-75-75-P-98-ISO10646-1", 16, 4, 3},
98 {"-Adobe-Helvetica-Bold-R-Normal--18-180-75-75-P-103-ISO10646-1", 16, 4, 3},
99 {"-Adobe-Helvetica-Bold-O-Normal--18-180-75-75-P-104-ISO10646-1", 16, 4, 3},
100 {"-Adobe-Helvetica-Medium-R-Normal--24-240-75-75-P-130-ISO10646-1", 22, 4, 4},
101 {"-Adobe-Helvetica-Medium-O-Normal--24-240-75-75-P-130-ISO10646-1", 22, 4, 4},
102 {"-Adobe-Helvetica-Bold-R-Normal--24-240-75-75-P-138-ISO10646-1", 22, 4, 4},
103 {"-Adobe-Helvetica-Bold-O-Normal--24-240-75-75-P-138-ISO10646-1", 22, 4, 4},
104 {"-Adobe-Courier-Medium-R-Normal--10-100-75-75-M-60-ISO10646-1", 8, 1, 2},
105 {"-Adobe-Courier-Medium-O-Normal--10-100-75-75-M-60-ISO10646-1", 8, 1, 2},
106 {"-Adobe-Courier-Bold-R-Normal--10-100-75-75-M-60-ISO10646-1", 8, 1, 2},
107 {"-Adobe-Courier-Bold-O-Normal--10-100-75-75-M-60-ISO10646-1", 8, 1, 2},
108 {"-Adobe-Courier-Medium-R-Normal--12-120-75-75-M-70-ISO10646-1", 10, 2, 2},
109 {"-Adobe-Courier-Medium-O-Normal--12-120-75-75-M-70-ISO10646-1", 10, 2, 2},
110 {"-Adobe-Courier-Bold-R-Normal--12-120-75-75-M-70-ISO10646-1", 10, 2, 2},
111 {"-Adobe-Courier-Bold-O-Normal--12-120-75-75-M-70-ISO10646-1", 10, 2, 2},
112 {"-Adobe-Courier-Medium-R-Normal--18-180-75-75-M-110-ISO10646-1", 14, 3, 3},
113 {"-Adobe-Courier-Medium-O-Normal--18-180-75-75-M-110-ISO10646-1", 14, 3, 3},
114 {"-Adobe-Courier-Bold-R-Normal--18-180-75-75-M-110-ISO10646-1", 14, 3, 3},
115 {"-Adobe-Courier-Bold-O-Normal--18-180-75-75-M-110-ISO10646-1", 14, 3, 3},
116 {"-Adobe-Courier-Medium-R-Normal--24-240-75-75-M-150-ISO10646-1", 19, 4, 4},
117 {"-Adobe-Courier-Medium-O-Normal--24-240-75-75-M-150-ISO10646-1", 19, 4, 4},
118 {"-Adobe-Courier-Bold-R-Normal--24-240-75-75-M-150-ISO10646-1", 19, 4, 4},
119 {"-Adobe-Courier-Bold-O-Normal--24-240-75-75-M-150-ISO10646-1", 19, 4, 4},
120 {"-Adobe-Times-Medium-R-Normal--8-80-75-75-P-44-ISO10646-1", 7, 1, 1},
121 {"-Adobe-Times-Medium-R-Normal--8-80-75-75-P-44-ISO10646-1", 7, 1, 1},
122 {"-Adobe-Times-Medium-R-Normal--8-80-75-75-P-44-ISO10646-1", 7, 1, 1},
123 {"-Adobe-Times-Medium-R-Normal--8-80-75-75-P-44-ISO10646-1", 7, 1, 1},
124 {"-Adobe-Times-Medium-R-Normal--8-80-75-75-P-44-ISO10646-1", 7, 1, 1},
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-Helvetica-Medium-R-Normal--10-100-75-75-P-56-ISO10646-1", 10, 1, 2},
137 {"-Adobe-Helvetica-Medium-O-Normal--10-100-75-75-P-57-ISO10646-1", 10, 1, 2},
138 {"-Adobe-Helvetica-Bold-R-Normal--10-100-75-75-P-60-ISO10646-1", 10, 1, 2},
139 {"-Adobe-Helvetica-Bold-O-Normal--10-100-75-75-P-60-ISO10646-1", 10, 1, 2},
140 {"-Adobe-Helvetica-Medium-R-Normal--12-120-75-75-P-67-ISO10646-1", 11, 2, 2},
141 {"-Adobe-Helvetica-Medium-O-Normal--12-120-75-75-P-67-ISO10646-1", 11, 2, 2},
142 {"-Adobe-Helvetica-Bold-R-Normal--12-120-75-75-P-70-ISO10646-1", 11, 2, 2},
143 {"-Adobe-Helvetica-Bold-O-Normal--12-120-75-75-P-69-ISO10646-1", 11, 2, 2},
144 {"-Adobe-Helvetica-Medium-R-Normal--18-180-75-75-P-98-ISO10646-1", 16, 4, 3},
145 {"-Adobe-Helvetica-Medium-O-Normal--18-180-75-75-P-98-ISO10646-1", 16, 4, 3},
146 {"-Adobe-Helvetica-Bold-R-Normal--18-180-75-75-P-103-ISO10646-1", 16, 4, 3},
147 {"-Adobe-Helvetica-Bold-O-Normal--18-180-75-75-P-104-ISO10646-1", 16, 4, 3},
148 {"-Adobe-Helvetica-Medium-R-Normal--24-240-75-75-P-130-ISO10646-1", 22, 4, 4},
149 {"-Adobe-Helvetica-Medium-O-Normal--24-240-75-75-P-130-ISO10646-1", 22, 4, 4},
150 {"-Adobe-Helvetica-Bold-R-Normal--24-240-75-75-P-138-ISO10646-1", 22, 4, 4},
151 {"-Adobe-Helvetica-Bold-O-Normal--24-240-75-75-P-138-ISO10646-1", 22, 4, 4},
155 static MetricsInfo
* grabMetrics(QString name
)
157 for (int pos
= 0; compatMetrics
[pos
].name
; ++pos
)
158 if (name
== QLatin1String(compatMetrics
[pos
].name
))
159 return &compatMetrics
[pos
];
163 class QFakeFontEngine
: public QFontEngineXLFD
168 QFakeFontEngine( XFontStruct
*fs
, const char *name
, int size
);
172 QtFontDim m_ascent
, m_descent
, m_leading
;
177 void recalcAdvances(int len
, QGlyphLayout
*glyphs
, QTextEngine::ShaperFlags flags
) const
179 QFontEngineXLFD::recalcAdvances(len
, glyphs
, flags
);
181 // Go through the glyhs with glyph 0 and fix up their x advance
182 // to make sense (or at least match Qt3)
183 // ### set proper GPLv2 and Qt (c) when committed
184 QtFontDim fallBackWidth
= xfs
->min_bounds
.width
;
187 fallBackWidth
= m_ascent
; //### we really should get rid of these and regen..
189 fallBackWidth
= xfs
->ascent
;
192 QGlyphLayout
* g
= glyphs
+ len
;
193 while (g
!= glyphs
) {
196 g
->advance
.x
= fallBackWidth
;
204 return QFontEngine::Freetype
;
206 return QFontEngine::XLFD
;
210 QtFontDim
ascent() const
215 return QFontEngineXLFD::ascent();
218 QtFontDim
descent() const
223 return QFontEngineXLFD::descent();
226 QtFontDim
leading() const
230 else if (haveMetrics
)
233 return QFontEngineXLFD::leading();
236 bool canRender( const QChar
*string
, int len
);
239 //OK. This is evil. Since we don't use Xft, we hijack the FreeType painting hook in the X11 engine
240 //for ahem, as unfortunately the drawing is in the paint engine, and not the font engine in Qt4
242 class KDE_EXPORT QX11PaintEngine
: public QPaintEngine
244 void drawFreetype(const QPointF
&p
, const QTextItemInt
&si
);
247 void QX11PaintEngine::drawFreetype(const QPointF
&p
, const QTextItemInt
&si
)
249 if (!si
.num_glyphs
) return;
251 QFakeFontEngine
*eng
= static_cast<QFakeFontEngine
*>(si
.fontEngine
);
255 int pixS
= int(eng
->pixS
);
257 int ascent
= dimToInt(eng
->ascent());
258 int descent
= dimToInt(eng
->descent());
260 if (si
.flags
& QTextItem::RightToLeft
)
262 x
= x
+ advance
* (si
.num_glyphs
- 1);
266 for (int pos
= 0; pos
< si
.num_glyphs
; ++pos
)
269 switch (si
.glyphs
[pos
].glyph
)
275 //Below the baseline, including it
276 rect
= QRect(x
, y
, pixS
, descent
+ 1);
280 rect
= QRect(x
, y
- ascent
, pixS
, ascent
);
284 rect
= QRect(x
, y
- ascent
, pixS
, pixS
);
287 QPainter
* p
= painter();
288 p
->fillRect(rect
, p
->pen().color());
295 QFakeFontEngine::QFakeFontEngine( XFontStruct
*fs
, const char *name
, int size
)
296 : QFontEngineXLFD( fs
, name
, 0)
300 this->name
= QLatin1String(name
);
301 ahem
= this->name
.contains("ahem");
303 MetricsInfo
* metrics
= grabMetrics(name
);
307 m_ascent
= metrics
->ascent
;
308 m_descent
= metrics
->descent
;
309 m_leading
= metrics
->leading
;
315 QFakeFontEngine::~QFakeFontEngine()
320 bool QFakeFontEngine::canRender( const QChar
*, int )
325 static QString
courier_pickxlfd( int pixelsize
, bool italic
, bool bold
)
327 if ( pixelsize
>= 24 )
329 else if ( pixelsize
>= 18 )
331 else if ( pixelsize
>= 12 )
336 return QString( "-adobe-courier-%1-%2-normal--%3-*-75-75-m-*-iso10646-1" ).arg( bold
? "bold" : "medium" ).arg( italic
? "o" : "r" ).arg( pixelsize
);
339 static QString
ahem_pickxlfd( int pixelsize
)
341 return QString( "-misc-ahem-medium-r-normal--%1-*-100-100-c-*-iso10646-1" ).arg( pixelsize
);
344 static QString
helv_pickxlfd( int pixelsize
, bool italic
, bool bold
)
346 if ( pixelsize
>= 24 )
348 else if ( pixelsize
>= 18 )
350 else if ( pixelsize
>= 12 )
355 return QString( "-adobe-helvetica-%1-%2-normal--%3-*-75-75-p-*-iso10646-1" ).arg( bold
? "bold" : "medium" ).arg( italic
? "o" : "r" ).arg( pixelsize
);
359 static QFontEngine
* loadFont(const QFontDef
& request
)
362 QString family
= request
.family
.toLower();
363 if ( family
== "adobe courier" || family
== "courier" || family
== "fixed" ) {
364 xlfd
= courier_pickxlfd( request
.pixelSize
, request
.style
== QFont::StyleItalic
, request
.weight
> 50 );
366 else if ( family
== "times new roman" || family
== "times" )
367 xlfd
= "-adobe-times-medium-r-normal--8-80-75-75-p-44-iso10646-1";
368 else if ( family
== "ahem" )
369 xlfd
= ahem_pickxlfd( request
.pixelSize
);
371 xlfd
= helv_pickxlfd( request
.pixelSize
, request
.style
== QFont::StyleItalic
, request
.weight
> 50 );
376 xfs
= XLoadQueryFont( QX11Info::display(), xlfd
.toLatin1() );
377 if (!xfs
) // as long as you don't do screenshots, it's maybe fine
378 qFatal("we need some fonts. So make sure you have %s installed.", qPrintable(xlfd
));
381 if ( !XGetFontProperty( xfs
, XA_FONT
, &value
) )
384 char *n
= XGetAtomName( QX11Info::display(), value
);
389 fe
= new QFakeFontEngine( xfs
, xlfd
.toLatin1(),request
.pixelSize
);
394 QFontEngine
*QFontDatabase::loadXlfd(int /* screen */, int /* script */,
395 const QFontDef
&request
, int /* force_encoding_id */)
397 return loadFont(request
);
400 extern "C" KDE_EXPORT
int FcInit() {
401 /* Make sure Qt uses the Xlfd path, which we intercept */
405 KDE_EXPORT
bool QFontDatabase::isBitmapScalable( const QString
&,
406 const QString
&) const
411 KDE_EXPORT
bool QFontDatabase::isSmoothlyScalable( const QString
&,
412 const QString
&) const
417 const QString
&KHTMLSettings::availableFamilies()
420 avFamilies
= new QString
;
421 *avFamilies
= ",Adobe Courier,Arial,Comic Sans MS,Courier,Helvetica,Times,Times New Roman,Utopia,Fixed,Ahem,";
428 bool KHTMLSettings::unfinishedImageFrame() const
433 KDE_EXPORT
int QX11Info::appDpiY( int )
438 KDE_EXPORT
int QX11Info::appDpiX( int )
443 KDE_EXPORT
void QFont::insertSubstitution(const QString
&,
448 KDE_EXPORT
void QFont::insertSubstitutions(const QString
&,
453 #include <kprotocolinfo.h>
454 bool KProtocolInfo::isKnownProtocol( const QString
& _protocol
)
456 return ( _protocol
== "file" );
459 #include <kprotocolinfofactory.h>
461 QString
KProtocolInfo::exec( const QString
& _protocol
)
463 if ( _protocol
!= "file" )
466 KProtocolInfo::Ptr prot
= KProtocolInfoFactory::self()->findProtocol(_protocol
);
473 #include <dcopclient.h>
475 bool DCOPClient::attach()
480 bool DCOPClient::isAttached() const
485 void DCOPClient::processSocketData( int )
489 #include <QtGui/QApplication>
490 #include <QtGui/QPalette>
493 KDE_EXPORT
void QApplication::setPalette( const QPalette
&, bool ,
496 static bool done
= false;
500 xfs
= XLoadQueryFont(QPaintDevice::x11AppDisplay(), xlfd
.toLatin1().constData() );
501 if (!xfs
) // as long as you don't do screenshots, it's maybe fine
502 qFatal("We will need some fonts. So make sure you have %s installed.", xlfd
.toLatin1().constData());
503 XFreeFont(QPaintDevice::x11AppDisplay(), xfs
);
508 #include <kapplication.h>
509 // void KApplication::dcopFailure( const QString & )
511 // qDebug( "KApplication::dcopFailure" );
514 #include <kparts/historyprovider.h>
516 bool KParts::HistoryProvider::contains( const QString
& t
) const
518 return ( t
== "http://www.kde.org/" || t
== "http://www.google.com/");
522 #include <ksslsettings.h>
524 bool KSSLSettings::warnOnEnter() const { return false; }
525 bool KSSLSettings::warnOnUnencrypted() const { return false; }
526 bool KSSLSettings::warnOnLeave() const { return false; }
528 #include <kparts/plugin.h>
530 KParts::Plugin
* KParts::Plugin::loadPlugin( QObject
* /* parent */, const char* /* libname */) { return 0; }