From a30f5359f03c3017fa19a6770fab32d25d22cb87 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Mon, 15 Jul 2024 19:08:22 +0900 Subject: Rename graphics class nt* related files to equivalent tq* (part 1) Signed-off-by: Michele Calgaro --- src/canvas/tqcanvas.cpp | 2 +- src/canvas/tqcanvas.h | 2 +- src/dialogs/ntqcolordialog.h | 93 - src/dialogs/ntqfontdialog.h | 112 - src/dialogs/qcolordialog.cpp | 1673 --------------- src/dialogs/qfontdialog.cpp | 841 -------- src/dialogs/qprogressdialog.cpp | 2 +- src/dialogs/qt_dialogs.pri | 10 +- src/dialogs/qtabdialog.cpp | 2 +- src/dialogs/qwizard.cpp | 2 +- src/dialogs/tqcolordialog.cpp | 1673 +++++++++++++++ src/dialogs/tqcolordialog.h | 93 + src/dialogs/tqfiledialog.cpp | 2 +- src/dialogs/tqfontdialog.cpp | 841 ++++++++ src/dialogs/tqfontdialog.h | 112 + src/kernel/ntqbrush.h | 94 - src/kernel/ntqcolor.h | 229 -- src/kernel/ntqfont.h | 365 ---- src/kernel/ntqfontdatabase.h | 219 -- src/kernel/ntqfontinfo.h | 91 - src/kernel/ntqfontmetrics.h | 113 - src/kernel/ntqmovie.h | 115 - src/kernel/ntqnamespace.h | 18 +- src/kernel/ntqpaintdevice.h | 407 ---- src/kernel/ntqpaintdevicemetrics.h | 83 - src/kernel/ntqpainter.h | 698 ------ src/kernel/ntqpalette.h | 4 +- src/kernel/ntqpen.h | 2 +- src/kernel/ntqpicture.h | 2 +- src/kernel/ntqpixmap.h | 4 +- src/kernel/ntqprinter.h | 2 +- src/kernel/ntqt.h | 24 +- src/kernel/qapplication.cpp | 2 +- src/kernel/qapplication_p.h | 2 +- src/kernel/qapplication_x11.cpp | 10 +- src/kernel/qcolor.cpp | 1030 --------- src/kernel/qcolor_p.cpp | 797 ------- src/kernel/qcolor_p.h | 66 - src/kernel/qcolor_x11.cpp | 841 -------- src/kernel/qdnd_x11.cpp | 2 +- src/kernel/qdrawutil.cpp | 2 +- src/kernel/qeventloop_x11.cpp | 2 +- src/kernel/qeventloop_x11_glib.cpp | 2 +- src/kernel/qfont.cpp | 3313 ---------------------------- src/kernel/qfont_x11.cpp | 738 ------- src/kernel/qfontdata_p.h | 275 --- src/kernel/qfontdatabase.cpp | 2489 ---------------------- src/kernel/qfontdatabase_x11.cpp | 2031 ------------------ src/kernel/qfontengine_p.h | 564 ----- src/kernel/qfontengine_x11.cpp | 2724 ----------------------- src/kernel/qinternal.cpp | 2 +- src/kernel/qmovie.cpp | 1045 --------- src/kernel/qpaintdevice_x11.cpp | 1173 ---------- src/kernel/qpaintdevicemetrics.cpp | 151 -- src/kernel/qpainter.cpp | 3910 ---------------------------------- src/kernel/qpainter_p.h | 66 - src/kernel/qpainter_x11.cpp | 3183 --------------------------- src/kernel/qpicture.cpp | 4 +- src/kernel/qpixmap.cpp | 2 +- src/kernel/qpixmap_x11.cpp | 4 +- src/kernel/qprinter_unix.cpp | 2 +- src/kernel/qpsprinter.cpp | 10 +- src/kernel/qrichtext.cpp | 6 +- src/kernel/qrichtext_p.h | 8 +- src/kernel/qscriptengine.cpp | 4 +- src/kernel/qt_kernel.pri | 72 +- src/kernel/qt_pch.h | 2 +- src/kernel/qvariant.cpp | 6 +- src/kernel/qwmatrix.cpp | 2 +- src/kernel/tqbrush.h | 94 + src/kernel/tqcolor.cpp | 1030 +++++++++ src/kernel/tqcolor.h | 229 ++ src/kernel/tqcolor_p.cpp | 797 +++++++ src/kernel/tqcolor_p.h | 66 + src/kernel/tqcolor_x11.cpp | 841 ++++++++ src/kernel/tqdragobject.h | 2 +- src/kernel/tqfont.cpp | 3313 ++++++++++++++++++++++++++++ src/kernel/tqfont.h | 365 ++++ src/kernel/tqfont_x11.cpp | 738 +++++++ src/kernel/tqfontdata_p.h | 275 +++ src/kernel/tqfontdatabase.cpp | 2489 ++++++++++++++++++++++ src/kernel/tqfontdatabase.h | 219 ++ src/kernel/tqfontdatabase_x11.cpp | 2031 ++++++++++++++++++ src/kernel/tqfontengine_p.h | 564 +++++ src/kernel/tqfontengine_x11.cpp | 2724 +++++++++++++++++++++++ src/kernel/tqfontinfo.h | 91 + src/kernel/tqfontmetrics.h | 113 + src/kernel/tqiconset.cpp | 2 +- src/kernel/tqimage.cpp | 10 +- src/kernel/tqmovie.cpp | 1045 +++++++++ src/kernel/tqmovie.h | 115 + src/kernel/tqpaintdevice.h | 407 ++++ src/kernel/tqpaintdevice_x11.cpp | 1173 ++++++++++ src/kernel/tqpaintdevicemetrics.cpp | 151 ++ src/kernel/tqpaintdevicemetrics.h | 83 + src/kernel/tqpainter.cpp | 3910 ++++++++++++++++++++++++++++++++++ src/kernel/tqpainter.h | 698 ++++++ src/kernel/tqpainter_p.h | 66 + src/kernel/tqpainter_x11.cpp | 3183 +++++++++++++++++++++++++++ src/kernel/tqsizegrip.cpp | 2 +- src/kernel/tqstyle.cpp | 2 +- src/kernel/tqstyle.h | 2 +- src/kernel/tqstylesheet.cpp | 2 +- src/kernel/tqtextengine.cpp | 6 +- src/kernel/tqtextengine_p.h | 2 +- src/kernel/tqtextlayout.cpp | 4 +- src/kernel/tqttdeintegration_x11.cpp | 4 +- src/kernel/tqwidget.cpp | 4 +- src/kernel/tqwidget.h | 8 +- src/kernel/tqwidget_x11.cpp | 6 +- src/libqt.map | 8 +- src/opengl/ntqglcolormap.h | 2 +- src/opengl/qgl.cpp | 2 +- src/opengl/qgl_x11.cpp | 2 +- src/sql/tqdatatable.cpp | 2 +- src/styles/qcdestyle.cpp | 2 +- src/styles/qcommonstyle.cpp | 2 +- src/styles/qcompactstyle.cpp | 4 +- src/styles/qinterlacestyle.cpp | 2 +- src/styles/qmotifplusstyle.cpp | 2 +- src/styles/qmotifstyle.cpp | 2 +- src/styles/qplatinumstyle.cpp | 2 +- src/styles/qsgistyle.cpp | 2 +- src/styles/qwindowsstyle.cpp | 2 +- src/table/qtable.cpp | 2 +- src/tools/qfeatures.txt | 6 +- src/tools/qunicodetables.cpp | 4 +- src/widgets/ntqsyntaxhighlighter.h | 4 +- src/widgets/qbutton.cpp | 2 +- src/widgets/qcheckbox.cpp | 2 +- src/widgets/qcombobox.cpp | 2 +- src/widgets/qdial.cpp | 6 +- src/widgets/qdockarea.cpp | 2 +- src/widgets/qdockwindow.cpp | 2 +- src/widgets/qframe.cpp | 2 +- src/widgets/qgridview.cpp | 2 +- src/widgets/qgroupbox.cpp | 2 +- src/widgets/qheader.cpp | 2 +- src/widgets/qlabel.cpp | 4 +- src/widgets/qlcdnumber.cpp | 2 +- src/widgets/qlineedit.cpp | 4 +- src/widgets/qlistbox.cpp | 4 +- src/widgets/qlistview.cpp | 2 +- src/widgets/qmultilineedit.cpp | 2 +- src/widgets/qprogressbar.cpp | 2 +- src/widgets/qpushbutton.cpp | 4 +- src/widgets/qradiobutton.cpp | 2 +- src/widgets/qscrollbar.cpp | 2 +- src/widgets/qscrollview.cpp | 2 +- src/widgets/qslider.cpp | 2 +- src/widgets/qspinbox.cpp | 2 +- src/widgets/qspinwidget.cpp | 2 +- src/widgets/qsplashscreen.cpp | 2 +- src/widgets/qsplitter.cpp | 2 +- src/widgets/qtabbar.cpp | 2 +- src/widgets/qtabwidget.cpp | 2 +- src/widgets/qtitlebar.cpp | 2 +- src/widgets/qwhatsthis.cpp | 4 +- src/widgets/tqiconview.cpp | 6 +- src/widgets/tqiconview.h | 2 +- src/widgets/tqmainwindow.cpp | 2 +- src/widgets/tqmenubar.cpp | 2 +- src/widgets/tqmenudata.h | 2 +- src/widgets/tqpopupmenu.cpp | 2 +- src/widgets/tqstatusbar.cpp | 2 +- src/widgets/tqtextbrowser.cpp | 2 +- src/widgets/tqtextbrowser.h | 2 +- src/widgets/tqtextedit.cpp | 12 +- src/widgets/tqtoolbar.cpp | 2 +- src/widgets/tqtoolbox.cpp | 2 +- src/widgets/tqtoolbutton.cpp | 2 +- src/xml/qsvgdevice.cpp | 4 +- src/xml/qsvgdevice_p.h | 2 +- 173 files changed, 29755 insertions(+), 29755 deletions(-) delete mode 100644 src/dialogs/ntqcolordialog.h delete mode 100644 src/dialogs/ntqfontdialog.h delete mode 100644 src/dialogs/qcolordialog.cpp delete mode 100644 src/dialogs/qfontdialog.cpp create mode 100644 src/dialogs/tqcolordialog.cpp create mode 100644 src/dialogs/tqcolordialog.h create mode 100644 src/dialogs/tqfontdialog.cpp create mode 100644 src/dialogs/tqfontdialog.h delete mode 100644 src/kernel/ntqbrush.h delete mode 100644 src/kernel/ntqcolor.h delete mode 100644 src/kernel/ntqfont.h delete mode 100644 src/kernel/ntqfontdatabase.h delete mode 100644 src/kernel/ntqfontinfo.h delete mode 100644 src/kernel/ntqfontmetrics.h delete mode 100644 src/kernel/ntqmovie.h delete mode 100644 src/kernel/ntqpaintdevice.h delete mode 100644 src/kernel/ntqpaintdevicemetrics.h delete mode 100644 src/kernel/ntqpainter.h delete mode 100644 src/kernel/qcolor.cpp delete mode 100644 src/kernel/qcolor_p.cpp delete mode 100644 src/kernel/qcolor_p.h delete mode 100644 src/kernel/qcolor_x11.cpp delete mode 100644 src/kernel/qfont.cpp delete mode 100644 src/kernel/qfont_x11.cpp delete mode 100644 src/kernel/qfontdata_p.h delete mode 100644 src/kernel/qfontdatabase.cpp delete mode 100644 src/kernel/qfontdatabase_x11.cpp delete mode 100644 src/kernel/qfontengine_p.h delete mode 100644 src/kernel/qfontengine_x11.cpp delete mode 100644 src/kernel/qmovie.cpp delete mode 100644 src/kernel/qpaintdevice_x11.cpp delete mode 100644 src/kernel/qpaintdevicemetrics.cpp delete mode 100644 src/kernel/qpainter.cpp delete mode 100644 src/kernel/qpainter_p.h delete mode 100644 src/kernel/qpainter_x11.cpp create mode 100644 src/kernel/tqbrush.h create mode 100644 src/kernel/tqcolor.cpp create mode 100644 src/kernel/tqcolor.h create mode 100644 src/kernel/tqcolor_p.cpp create mode 100644 src/kernel/tqcolor_p.h create mode 100644 src/kernel/tqcolor_x11.cpp create mode 100644 src/kernel/tqfont.cpp create mode 100644 src/kernel/tqfont.h create mode 100644 src/kernel/tqfont_x11.cpp create mode 100644 src/kernel/tqfontdata_p.h create mode 100644 src/kernel/tqfontdatabase.cpp create mode 100644 src/kernel/tqfontdatabase.h create mode 100644 src/kernel/tqfontdatabase_x11.cpp create mode 100644 src/kernel/tqfontengine_p.h create mode 100644 src/kernel/tqfontengine_x11.cpp create mode 100644 src/kernel/tqfontinfo.h create mode 100644 src/kernel/tqfontmetrics.h create mode 100644 src/kernel/tqmovie.cpp create mode 100644 src/kernel/tqmovie.h create mode 100644 src/kernel/tqpaintdevice.h create mode 100644 src/kernel/tqpaintdevice_x11.cpp create mode 100644 src/kernel/tqpaintdevicemetrics.cpp create mode 100644 src/kernel/tqpaintdevicemetrics.h create mode 100644 src/kernel/tqpainter.cpp create mode 100644 src/kernel/tqpainter.h create mode 100644 src/kernel/tqpainter_p.h create mode 100644 src/kernel/tqpainter_x11.cpp (limited to 'src') diff --git a/src/canvas/tqcanvas.cpp b/src/canvas/tqcanvas.cpp index e1279bb83..2e0afadb2 100644 --- a/src/canvas/tqcanvas.cpp +++ b/src/canvas/tqcanvas.cpp @@ -44,7 +44,7 @@ #include "tqbitmap.h" #include "tqimage.h" #include "tqptrdict.h" -#include "ntqpainter.h" +#include "tqpainter.h" #include "ntqpolygonscanner.h" #include "tqtimer.h" #include "ntqtl.h" diff --git a/src/canvas/tqcanvas.h b/src/canvas/tqcanvas.h index 2a8475247..28b30c42f 100644 --- a/src/canvas/tqcanvas.h +++ b/src/canvas/tqcanvas.h @@ -45,7 +45,7 @@ #include "ntqscrollview.h" #include "ntqpixmap.h" #include "tqptrlist.h" -#include "ntqbrush.h" +#include "tqbrush.h" #include "ntqpen.h" #include "tqvaluelist.h" #include "ntqpointarray.h" diff --git a/src/dialogs/ntqcolordialog.h b/src/dialogs/ntqcolordialog.h deleted file mode 100644 index 0941a020d..000000000 --- a/src/dialogs/ntqcolordialog.h +++ /dev/null @@ -1,93 +0,0 @@ -/**************************************************************************** -** -** Definition of TQColorDialog class -** -** Created : 990222 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the dialogs module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#ifndef TQCOLORDIALOG_H -#define TQCOLORDIALOG_H - -#ifndef QT_H -#include "ntqdialog.h" -#endif // QT_H - -#ifndef TQT_NO_COLORDIALOG - -class TQColorDialogPrivate; - -class TQ_EXPORT TQColorDialog : public TQDialog -{ - TQ_OBJECT - -public: - static TQColor getColor( const TQColor& init = white, TQWidget* parent=0, const char* name=0 ); - static TQRgb getRgba( TQRgb, bool* ok = 0, - TQWidget* parent=0, const char* name=0 ); - - static int customCount(); - static TQRgb customColor( int ); - static void setCustomColor( int, TQRgb ); - static void setStandardColor( int, TQRgb ); - -private: - ~TQColorDialog(); - TQColorDialog( TQWidget* parent=0, const char* name=0, bool modal=FALSE ); - - void setColor( const TQColor& ); - TQColor color() const; - - bool selectColor( const TQColor& ); - - void setSelectedAlpha( int ); - int selectedAlpha() const; - - void showCustom( bool=TRUE ); - -private: // Disabled copy constructor and operator= - TQColorDialogPrivate *d; - friend class TQColorDialogPrivate; - friend class TQColorShower; - -#if defined(TQ_DISABLE_COPY) - TQColorDialog( const TQColorDialog & ); - TQColorDialog& operator=( const TQColorDialog & ); -#endif -}; - -#endif - -#endif //TQCOLORDIALOG_H diff --git a/src/dialogs/ntqfontdialog.h b/src/dialogs/ntqfontdialog.h deleted file mode 100644 index 743738170..000000000 --- a/src/dialogs/ntqfontdialog.h +++ /dev/null @@ -1,112 +0,0 @@ -/**************************************************************************** -** -** Definition of TQFontDialog -** -** Created : 970605 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the dialogs module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#ifndef TQFONTDIALOG_H -#define TQFONTDIALOG_H - -#include "ntqwindowdefs.h" - -#ifndef TQT_NO_FONTDIALOG - -// -// W A R N I N G -// ------------- -// -// This class is under development and has private constructors. -// -// You may use the public static getFont() functions which are guaranteed -// to be available in the future. -// - -#ifndef QT_H -#include "ntqdialog.h" -#include "ntqfont.h" -#endif // QT_H - -class TQFontDialogPrivate; - -class TQ_EXPORT TQFontDialog: public TQDialog -{ - TQ_OBJECT - -public: - static TQFont getFont( bool *ok, const TQFont &def, - TQWidget* parent=0, const char* name=0); - static TQFont getFont( bool *ok, TQWidget* parent=0, const char* name=0); - -private: - static TQFont getFont( bool *ok, const TQFont *def, - TQWidget* parent=0, const char* name=0); - - TQFontDialog( TQWidget* parent=0, const char* name=0, bool modal=FALSE, - WFlags f=0 ); - ~TQFontDialog(); - - TQFont font() const; - void setFont( const TQFont &font ); - - bool eventFilter( TQObject *, TQEvent * ); - - void updateFamilies(); - void updateStyles(); - void updateSizes(); - -private slots: - void sizeChanged( const TQString &); - void familyHighlighted( int ); - void scriptHighlighted( int ); - void styleHighlighted( int ); - void sizeHighlighted( const TQString & ); - void updateSample(); - -private: - friend class TQFontDialogPrivate; - TQFontDialogPrivate * d; - -private: // Disabled copy constructor and operator= -#if defined(TQ_DISABLE_COPY) - TQFontDialog( const TQFontDialog & ); - TQFontDialog& operator=( const TQFontDialog & ); -#endif -}; - -#endif - -#endif // TQFONTDIALOG_H diff --git a/src/dialogs/qcolordialog.cpp b/src/dialogs/qcolordialog.cpp deleted file mode 100644 index 4f82b6350..000000000 --- a/src/dialogs/qcolordialog.cpp +++ /dev/null @@ -1,1673 +0,0 @@ -/**************************************************************************** -** -** Implementation of TQColorDialog class -** -** Created : 990222 -** -** Copyright (C) 1999-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the dialogs module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#include "ntqcolordialog.h" - -#ifndef TQT_NO_COLORDIALOG - -#include "ntqpainter.h" -#include "ntqlayout.h" -#include "ntqlabel.h" -#include "ntqpushbutton.h" -#include "ntqlineedit.h" -#include "tqimage.h" -#include "ntqpixmap.h" -#include "ntqdrawutil.h" -#include "ntqvalidator.h" -#include "tqdragobject.h" -#include "ntqgridview.h" -#include "ntqapplication.h" -#include "tqstyle.h" -#include "tqsettings.h" -#include "tqpopupmenu.h" - -#ifdef TQ_WS_MAC -TQRgb macGetRgba( TQRgb initial, bool *ok, TQWidget *parent, const char* name ); -TQColor macGetColor( const TQColor& initial, TQWidget *parent, const char *name ); -#endif - -#ifdef TQ_WS_X11 -#include "private/tqttdeintegration_x11_p.h" -#endif - -//////////// TQWellArray BEGIN - -struct TQWellArrayData; - -class TQWellArray : public TQGridView -{ - TQ_OBJECT - TQ_PROPERTY( int selectedColumn READ selectedColumn ) - TQ_PROPERTY( int selectedRow READ selectedRow ) - -public: - TQWellArray( TQWidget* parent=0, const char* name=0, bool popup = FALSE ); - - ~TQWellArray() {} - TQString cellContent( int row, int col ) const; - // ### Paul !!! virtual void setCellContent( int row, int col, const TQString &); - - int selectedColumn() const { return selCol; } - int selectedRow() const { return selRow; } - - virtual void setCurrent( int row, int col ); - virtual void setSelected( int row, int col ); - - TQSize sizeHint() const; - - virtual void setCellBrush( int row, int col, const TQBrush & ); - TQBrush cellBrush( int row, int col ); - -signals: - void selected( int row, int col ); - -protected: - void dimensionChange( int oldRows, int oldCols ); - - virtual void paintCell( TQPainter *, int row, int col ); - virtual void paintCellContents( TQPainter *, int row, int col, const TQRect& ); - - void mousePressEvent( TQMouseEvent* ); - void mouseReleaseEvent( TQMouseEvent* ); - void mouseMoveEvent( TQMouseEvent* ); - void keyPressEvent( TQKeyEvent* ); - void focusInEvent( TQFocusEvent* ); - void focusOutEvent( TQFocusEvent* ); - -private: - int curRow; - int curCol; - int selRow; - int selCol; - bool smallStyle; - TQWellArrayData *d; - -private: // Disabled copy constructor and operator= -#if defined(TQ_DISABLE_COPY) - TQWellArray( const TQWellArray & ); - TQWellArray& operator=( const TQWellArray & ); -#endif -}; - - - -// non-interface ... - - - -struct TQWellArrayData { - TQBrush *brush; -}; - -/*! - \internal - \class TQWellArray qwellarray_p.h - \brief The TQWellArray class provides a well array. - - - \ingroup advanced -*/ - -TQWellArray::TQWellArray( TQWidget *parent, const char * name, bool popup ) - : TQGridView( parent, name, - (popup ? (WStyle_Customize|WStyle_Tool|WStyle_NoBorder) : 0 ) ) -{ - d = 0; - setFocusPolicy( StrongFocus ); - setVScrollBarMode(AlwaysOff); - setHScrollBarMode(AlwaysOff); - viewport()->setBackgroundMode( PaletteBackground ); - setNumCols( 7 ); - setNumRows( 7 ); - setCellWidth( 24 ); - setCellHeight( 21 ); - smallStyle = popup; - - if ( popup ) { - setCellWidth( 18 ); - setCellHeight( 18 ); - setFrameStyle(TQFrame::StyledPanel | TQFrame::Raised); - setMargin( 1 ); - setLineWidth( 2 ); - } else { - setFrameStyle( TQFrame::NoFrame ); - } - curCol = 0; - curRow = 0; - selCol = -1; - selRow = -1; - - if ( smallStyle ) - setMouseTracking( TRUE ); -} - - -TQSize TQWellArray::sizeHint() const -{ - constPolish(); - TQSize s = gridSize().boundedTo( TQSize(640, 480 ) ); - return TQSize( s.width() + 2*frameWidth(), s.height() + 2*frameWidth() ); -} - - -void TQWellArray::paintCell( TQPainter* p, int row, int col ) -{ - int w = cellWidth(); // width of cell in pixels - int h = cellHeight(); // height of cell in pixels - int b = 1; - - if ( !smallStyle ) - b = 3; - - const TQColorGroup & g = colorGroup(); - p->setPen( TQPen( black, 0, SolidLine ) ); - if ( !smallStyle && row ==selRow && col == selCol && - style().styleHint(TQStyle::SH_GUIStyle) != MotifStyle) { - int n = 2; - p->drawRect( n, n, w-2*n, h-2*n ); - } - - style().drawPrimitive(TQStyle::PE_Panel, p, TQRect(b, b, w-2*b, h-2*b), g, - TQStyle::Style_Enabled | TQStyle::Style_Sunken); - - int t = 0; - if (style().styleHint(TQStyle::SH_GUIStyle) == MotifStyle) - t = ( row == selRow && col == selCol ) ? 2 : 0; - b += 2 + t; - - if ( (row == curRow) && (col == curCol) ) { - if ( smallStyle ) { - p->setPen ( white ); - p->drawRect( 1, 1, w-2, h-2 ); - p->setPen ( black ); - p->drawRect( 0, 0, w, h ); - p->drawRect( 2, 2, w-4, h-4 ); - b = 3; - } else if ( hasFocus() ) { - style().drawPrimitive(TQStyle::PE_FocusRect, p, TQRect(0, 0, w, h), g); - } - } - paintCellContents( p, row, col, TQRect(b, b, w - 2*b, h - 2*b) ); -} - -/*! - Reimplement this function to change the contents of the well array. - */ -void TQWellArray::paintCellContents( TQPainter *p, int row, int col, const TQRect &r ) -{ - - if ( d ) { - p->fillRect( r, d->brush[row*numCols()+col] ); - } else { - p->fillRect( r, white ); - p->setPen( black ); - p->drawLine( r.topLeft(), r.bottomRight() ); - p->drawLine( r.topRight(), r.bottomLeft() ); - } -} - - -/*\reimp -*/ -void TQWellArray::mousePressEvent( TQMouseEvent* e ) -{ - // The current cell marker is set to the cell the mouse is pressed - // in. - TQPoint pos = e->pos(); - setCurrent( rowAt( pos.y() ), columnAt( pos.x() ) ); -} - -/*\reimp -*/ -void TQWellArray::mouseReleaseEvent( TQMouseEvent* ) -{ - // The current cell marker is set to the cell the mouse is clicked - // in. - setSelected( curRow, curCol ); -} - - -/*\reimp -*/ -void TQWellArray::mouseMoveEvent( TQMouseEvent* e ) -{ - // The current cell marker is set to the cell the mouse is - // clicked in. - if ( smallStyle ) { - TQPoint pos = e->pos(); - setCurrent( rowAt( pos.y() ), columnAt( pos.x() ) ); - } -} - -/* - Sets the cell currently having the focus. This is not necessarily - the same as the currently selected cell. -*/ - -void TQWellArray::setCurrent( int row, int col ) -{ - - if ( (curRow == row) && (curCol == col) ) - return; - - if ( row < 0 || col < 0 ) - row = col = -1; - - int oldRow = curRow; - int oldCol = curCol; - - curRow = row; - curCol = col; - - updateCell( oldRow, oldCol ); - updateCell( curRow, curCol ); -} - - -/*! - Sets the currently selected cell to \a row, \a col. If \a row or \a - col are less than zero, the current cell is unselected. - - Does not set the position of the focus indicator. -*/ - -void TQWellArray::setSelected( int row, int col ) -{ - if ( (selRow == row) && (selCol == col) ) - return; - - int oldRow = selRow; - int oldCol = selCol; - - if ( row < 0 || col < 0 ) - row = col = -1; - - selCol = col; - selRow = row; - - updateCell( oldRow, oldCol ); - updateCell( selRow, selCol ); - if ( row >= 0 ) - emit selected( row, col ); - - if ( isVisible() && ::tqt_cast(parentWidget()) ) - parentWidget()->close(); -} - - - -/*!\reimp -*/ -void TQWellArray::focusInEvent( TQFocusEvent* ) -{ - updateCell( curRow, curCol ); -} - - -/*! - Sets the size of the well array to be \a rows cells by \a cols. - Resets any brush information set by setCellBrush(). - */ -void TQWellArray::dimensionChange( int, int ) -{ - if ( d ) { - if ( d->brush ) - delete[] d->brush; - delete d; - d = 0; - } -} - -void TQWellArray::setCellBrush( int row, int col, const TQBrush &b ) -{ - if ( !d ) { - d = new TQWellArrayData; - int i = numRows()*numCols(); - d->brush = new TQBrush[i]; - } - if ( row >= 0 && row < numRows() && col >= 0 && col < numCols() ) - d->brush[row*numCols()+col] = b; -#ifdef QT_CHECK_RANGE - else - tqWarning( "TQWellArray::setCellBrush( %d, %d ) out of range", row, col ); -#endif -} - - - -/*! - Returns the brush set for the cell at \a row, \a col. If no brush is set, - \c NoBrush is returned. -*/ - -TQBrush TQWellArray::cellBrush( int row, int col ) -{ - if ( d && row >= 0 && row < numRows() && col >= 0 && col < numCols() ) - return d->brush[row*numCols()+col]; - return NoBrush; -} - - - -/*!\reimp -*/ - -void TQWellArray::focusOutEvent( TQFocusEvent* ) -{ - updateCell( curRow, curCol ); -} - -/*\reimp -*/ -void TQWellArray::keyPressEvent( TQKeyEvent* e ) -{ - switch( e->key() ) { // Look at the key code - case Key_Left: // If 'left arrow'-key, - if( curCol > 0 ) // and cr't not in leftmost col - setCurrent( curRow, curCol - 1); // set cr't to next left column - break; - case Key_Right: // Correspondingly... - if( curCol < numCols()-1 ) - setCurrent( curRow, curCol + 1); - break; - case Key_Up: - if( curRow > 0 ) - setCurrent( curRow - 1, curCol); - else if ( smallStyle ) - focusNextPrevChild( FALSE ); - break; - case Key_Down: - if( curRow < numRows()-1 ) - setCurrent( curRow + 1, curCol); - else if ( smallStyle ) - focusNextPrevChild( TRUE ); - break; - case Key_Space: - case Key_Return: - case Key_Enter: - setSelected( curRow, curCol ); - break; - default: // If not an interesting key, - e->ignore(); // we don't accept the event - return; - } - -} - -//////////// TQWellArray END - -static bool initrgb = FALSE; -static TQRgb stdrgb[6*8]; -static TQRgb cusrgb[2*8]; -static bool customSet = FALSE; - - -static void initRGB() -{ - if ( initrgb ) - return; - initrgb = TRUE; - int i = 0; - for ( int g = 0; g < 4; g++ ) - for ( int r = 0; r < 4; r++ ) - for ( int b = 0; b < 3; b++ ) - stdrgb[i++] = tqRgb( r*255/3, g*255/3, b*255/2 ); - - for ( i = 0; i < 2*8; i++ ) - cusrgb[i] = tqRgb(0xff,0xff,0xff); -} - -/*! - Returns the number of custom colors supported by TQColorDialog. All - color dialogs share the same custom colors. -*/ -int TQColorDialog::customCount() -{ - return 2*8; -} - -/*! - Returns custom color number \a i as a TQRgb. -*/ -TQRgb TQColorDialog::customColor( int i ) -{ - initRGB(); - if ( i < 0 || i >= customCount() ) { -#ifdef QT_CHECK_RANGE - tqWarning( "TQColorDialog::customColor() index %d out of range", i ); -#endif - i = 0; - } - return cusrgb[i]; -} - -/*! - Sets custom color number \a i to the TQRgb value \a c. -*/ -void TQColorDialog::setCustomColor( int i, TQRgb c ) -{ - initRGB(); - if ( i < 0 || i >= customCount() ) { -#ifdef QT_CHECK_RANGE - tqWarning( "TQColorDialog::setCustomColor() index %d out of range", i ); -#endif - return; - } - customSet = TRUE; - cusrgb[i] = c; -} - -/*! - Sets standard color number \a i to the TQRgb value \a c. -*/ - -void TQColorDialog::setStandardColor( int i, TQRgb c ) -{ - initRGB(); - if ( i < 0 || i >= 6*8 ) { -#ifdef QT_CHECK_RANGE - tqWarning( "TQColorDialog::setStandardColor() index %d out of range", i ); -#endif - return; - } - stdrgb[i] = c; -} - -static inline void rgb2hsv( TQRgb rgb, int&h, int&s, int&v ) -{ - TQColor c; - c.setRgb( rgb ); - c.getHsv(h,s,v); -} - -class TQColorWell : public TQWellArray -{ -public: - TQColorWell( TQWidget *parent, int r, int c, TQRgb *vals ) - :TQWellArray( parent, "" ), values( vals ), mousePressed( FALSE ), oldCurrent( -1, -1 ) - { setNumRows(r), setNumCols(c); setSizePolicy( TQSizePolicy( TQSizePolicy::Minimum, TQSizePolicy::Minimum) ); } - -protected: - void paintCellContents( TQPainter *, int row, int col, const TQRect& ); - void mousePressEvent( TQMouseEvent *e ); - void mouseMoveEvent( TQMouseEvent *e ); - void mouseReleaseEvent( TQMouseEvent *e ); -#ifndef TQT_NO_DRAGANDDROP - void dragEnterEvent( TQDragEnterEvent *e ); - void dragLeaveEvent( TQDragLeaveEvent *e ); - void dragMoveEvent( TQDragMoveEvent *e ); - void dropEvent( TQDropEvent *e ); -#endif - -private: - TQRgb *values; - bool mousePressed; - TQPoint pressPos; - TQPoint oldCurrent; - -}; - -void TQColorWell::paintCellContents( TQPainter *p, int row, int col, const TQRect &r ) -{ - int i = row + col*numRows(); - p->fillRect( r, TQColor( values[i] ) ); -} - -void TQColorWell::mousePressEvent( TQMouseEvent *e ) -{ - oldCurrent = TQPoint( selectedRow(), selectedColumn() ); - TQWellArray::mousePressEvent( e ); - mousePressed = TRUE; - pressPos = e->pos(); -} - -void TQColorWell::mouseMoveEvent( TQMouseEvent *e ) -{ - TQWellArray::mouseMoveEvent( e ); -#ifndef TQT_NO_DRAGANDDROP - if ( !mousePressed ) - return; - if ( ( pressPos - e->pos() ).manhattanLength() > TQApplication::startDragDistance() ) { - setCurrent( oldCurrent.x(), oldCurrent.y() ); - int i = rowAt(pressPos.y()) + columnAt(pressPos.x()) * numRows(); - TQColor col( values[ i ] ); - TQColorDrag *drg = new TQColorDrag( col, this ); - TQPixmap pix( cellWidth(), cellHeight() ); - pix.fill( col ); - TQPainter p( &pix ); - p.drawRect( 0, 0, pix.width(), pix.height() ); - p.end(); - drg->setPixmap( pix ); - mousePressed = FALSE; - drg->dragCopy(); - } -#endif -} - -#ifndef TQT_NO_DRAGANDDROP -void TQColorWell::dragEnterEvent( TQDragEnterEvent *e ) -{ - setFocus(); - if ( TQColorDrag::canDecode( e ) ) - e->accept(); - else - e->ignore(); -} - -void TQColorWell::dragLeaveEvent( TQDragLeaveEvent * ) -{ - if ( hasFocus() ) - parentWidget()->setFocus(); -} - -void TQColorWell::dragMoveEvent( TQDragMoveEvent *e ) -{ - if ( TQColorDrag::canDecode( e ) ) { - setCurrent( rowAt( e->pos().y() ), columnAt( e->pos().x() ) ); - e->accept(); - } else - e->ignore(); -} - -void TQColorWell::dropEvent( TQDropEvent *e ) -{ - if ( TQColorDrag::canDecode( e ) ) { - int i = rowAt( e->pos().y() ) + columnAt( e->pos().x() ) * numRows(); - TQColor col; - TQColorDrag::decode( e, col ); - values[ i ] = col.rgb(); - repaintContents( FALSE ); - e->accept(); - } else { - e->ignore(); - } -} - -#endif // TQT_NO_DRAGANDDROP - -void TQColorWell::mouseReleaseEvent( TQMouseEvent *e ) -{ - if ( !mousePressed ) - return; - TQWellArray::mouseReleaseEvent( e ); - mousePressed = FALSE; -} - -class TQColorPicker : public TQFrame -{ - TQ_OBJECT -public: - TQColorPicker(TQWidget* parent=0, const char* name=0); - ~TQColorPicker(); - -public slots: - void setCol( int h, int s ); - -signals: - void newCol( int h, int s ); - -protected: - TQSize sizeHint() const; - void drawContents(TQPainter* p); - void mouseMoveEvent( TQMouseEvent * ); - void mousePressEvent( TQMouseEvent * ); - -private: - int hue; - int sat; - - TQPoint colPt(); - int huePt( const TQPoint &pt ); - int satPt( const TQPoint &pt ); - void setCol( const TQPoint &pt ); - - TQPixmap *pix; -}; - -static int pWidth = 200; -static int pHeight = 200; - -class TQColorLuminancePicker : public TQWidget -{ - TQ_OBJECT -public: - TQColorLuminancePicker(TQWidget* parent=0, const char* name=0); - ~TQColorLuminancePicker(); - -public slots: - void setCol( int h, int s, int v ); - void setCol( int h, int s ); - -signals: - void newHsv( int h, int s, int v ); - -protected: - void paintEvent( TQPaintEvent*); - void mouseMoveEvent( TQMouseEvent * ); - void mousePressEvent( TQMouseEvent * ); - -private: - enum { foff = 3, coff = 4 }; //frame and contents offset - int val; - int hue; - int sat; - - int y2val( int y ); - int val2y( int val ); - void setVal( int v ); - - TQPixmap *pix; -}; - - -int TQColorLuminancePicker::y2val( int y ) -{ - int d = height() - 2*coff - 1; - return 255 - (y - coff)*255/d; -} - -int TQColorLuminancePicker::val2y( int v ) -{ - int d = height() - 2*coff - 1; - return coff + (255-v)*d/255; -} - -TQColorLuminancePicker::TQColorLuminancePicker(TQWidget* parent, - const char* name) - :TQWidget( parent, name ) -{ - hue = 100; val = 100; sat = 100; - pix = 0; - // setBackgroundMode( NoBackground ); -} - -TQColorLuminancePicker::~TQColorLuminancePicker() -{ - delete pix; -} - -void TQColorLuminancePicker::mouseMoveEvent( TQMouseEvent *m ) -{ - setVal( y2val(m->y()) ); -} -void TQColorLuminancePicker::mousePressEvent( TQMouseEvent *m ) -{ - setVal( y2val(m->y()) ); -} - -void TQColorLuminancePicker::setVal( int v ) -{ - if ( val == v ) - return; - val = TQMAX( 0, TQMIN(v,255)); - delete pix; pix=0; - repaint( FALSE ); //### - emit newHsv( hue, sat, val ); -} - -//receives from a hue,sat chooser and relays. -void TQColorLuminancePicker::setCol( int h, int s ) -{ - setCol( h, s, val ); - emit newHsv( h, s, val ); -} - -void TQColorLuminancePicker::paintEvent( TQPaintEvent * ) -{ - int w = width() - 5; - - TQRect r( 0, foff, w, height() - 2*foff ); - int wi = r.width() - 2; - int hi = r.height() - 2; - if ( !pix || pix->height() != hi || pix->width() != wi ) { - delete pix; - TQImage img( wi, hi, 32 ); - int y; - for ( y = 0; y < hi; y++ ) { - TQColor c( hue, sat, y2val(y+coff), TQColor::Hsv ); - TQRgb r = c.rgb(); - int x; - for ( x = 0; x < wi; x++ ) - img.setPixel( x, y, r ); - } - pix = new TQPixmap; - pix->convertFromImage(img); - } - TQPainter p(this); - p.drawPixmap( 1, coff, *pix ); - const TQColorGroup &g = colorGroup(); - qDrawShadePanel( &p, r, g, TRUE ); - p.setPen( g.foreground() ); - p.setBrush( g.foreground() ); - TQPointArray a; - int y = val2y(val); - a.setPoints( 3, w, y, w+5, y+5, w+5, y-5 ); - erase( w, 0, 5, height() ); - p.drawPolygon( a ); -} - -void TQColorLuminancePicker::setCol( int h, int s , int v ) -{ - val = v; - hue = h; - sat = s; - delete pix; pix=0; - repaint( FALSE );//#### -} - -TQPoint TQColorPicker::colPt() -{ return TQPoint( (360-hue)*(pWidth-1)/360, (255-sat)*(pHeight-1)/255 ); } -int TQColorPicker::huePt( const TQPoint &pt ) -{ return 360 - pt.x()*360/(pWidth-1); } -int TQColorPicker::satPt( const TQPoint &pt ) -{ return 255 - pt.y()*255/(pHeight-1) ; } -void TQColorPicker::setCol( const TQPoint &pt ) -{ setCol( huePt(pt), satPt(pt) ); } - -TQColorPicker::TQColorPicker(TQWidget* parent, const char* name ) - : TQFrame( parent, name ) -{ - hue = 0; sat = 0; - setCol( 150, 255 ); - - TQImage img( pWidth, pHeight, 32 ); - int x,y; - for ( y = 0; y < pHeight; y++ ) - for ( x = 0; x < pWidth; x++ ) { - TQPoint p( x, y ); - img.setPixel( x, y, TQColor(huePt(p), satPt(p), - 200, TQColor::Hsv).rgb() ); - } - pix = new TQPixmap; - pix->convertFromImage(img); - setBackgroundMode( NoBackground ); - setSizePolicy( TQSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed ) ); -} - -TQColorPicker::~TQColorPicker() -{ - delete pix; -} - -TQSize TQColorPicker::sizeHint() const -{ - return TQSize( pWidth + 2*frameWidth(), pHeight + 2*frameWidth() ); -} - -void TQColorPicker::setCol( int h, int s ) -{ - int nhue = TQMIN( TQMAX(0,h), 360 ); - int nsat = TQMIN( TQMAX(0,s), 255); - if ( nhue == hue && nsat == sat ) - return; - TQRect r( colPt(), TQSize(20,20) ); - hue = nhue; sat = nsat; - r = r.unite( TQRect( colPt(), TQSize(20,20) ) ); - r.moveBy( contentsRect().x()-9, contentsRect().y()-9 ); - // update( r ); - repaint( r, FALSE ); -} - -void TQColorPicker::mouseMoveEvent( TQMouseEvent *m ) -{ - TQPoint p = m->pos() - contentsRect().topLeft(); - setCol( p ); - emit newCol( hue, sat ); -} - -void TQColorPicker::mousePressEvent( TQMouseEvent *m ) -{ - TQPoint p = m->pos() - contentsRect().topLeft(); - setCol( p ); - emit newCol( hue, sat ); -} - -void TQColorPicker::drawContents(TQPainter* p) -{ - TQRect r = contentsRect(); - - p->drawPixmap( r.topLeft(), *pix ); - TQPoint pt = colPt() + r.topLeft(); - p->setPen( TQPen(black) ); - - p->fillRect( pt.x()-9, pt.y(), 20, 2, black ); - p->fillRect( pt.x(), pt.y()-9, 2, 20, black ); - -} - -class TQColorShowLabel; - - - -class TQColIntValidator: public TQIntValidator -{ -public: - TQColIntValidator( int bottom, int top, - TQWidget * parent, const char *name = 0 ) - :TQIntValidator( bottom, top, parent, name ) {} - - TQValidator::State validate( TQString &, int & ) const; -}; - -TQValidator::State TQColIntValidator::validate( TQString &s, int &pos ) const -{ - State state = TQIntValidator::validate(s,pos); - if ( state == Valid ) { - long int val = s.toLong(); - // This is not a general solution, assumes that top() > 0 and - // bottom >= 0 - if ( val < 0 ) { - s = "0"; - pos = 1; - } else if ( val > top() ) { - s.setNum( top() ); - pos = s.length(); - } - } - return state; -} - - - -class TQColNumLineEdit : public TQLineEdit -{ -public: - TQColNumLineEdit( TQWidget *parent, const char* name=0 ) - : TQLineEdit( parent, name ) { setMaxLength( 3 );} - TQSize sizeHint() const { - return TQSize( fontMetrics().width( "999" ) + 2 * ( margin() + frameWidth() ), - TQLineEdit::sizeHint().height() ); } - void setNum( int i ) { - TQString s; - s.setNum(i); - bool block = signalsBlocked(); - blockSignals(TRUE); - setText( s ); - blockSignals(block); - } - int val() const { return text().toInt(); } -}; - - -class TQColorShower : public TQWidget -{ - TQ_OBJECT -public: - TQColorShower( TQWidget *parent, const char *name=0 ); - - //things that don't emit signals - void setHsv( int h, int s, int v ); - - int currentAlpha() const { return alphaEd->val(); } - void setCurrentAlpha( int a ) { alphaEd->setNum( a ); } - void showAlpha( bool b ); - - - TQRgb currentColor() const { return curCol; } - -public slots: - void setRgb( TQRgb rgb ); - -signals: - void newCol( TQRgb rgb ); -private slots: - void rgbEd(); - void hsvEd(); -private: - void showCurrentColor(); - int hue, sat, val; - TQRgb curCol; - TQColNumLineEdit *hEd; - TQColNumLineEdit *sEd; - TQColNumLineEdit *vEd; - TQColNumLineEdit *rEd; - TQColNumLineEdit *gEd; - TQColNumLineEdit *bEd; - TQColNumLineEdit *alphaEd; - TQLabel *alphaLab; - TQColorShowLabel *lab; - bool rgbOriginal; -}; - -class TQColorShowLabel : public TQFrame -{ - TQ_OBJECT - -public: - TQColorShowLabel( TQWidget *parent ) : TQFrame( parent, "qt_colorshow_lbl" ) { - setFrameStyle( TQFrame::Panel|TQFrame::Sunken ); - setBackgroundMode( PaletteBackground ); - setAcceptDrops( TRUE ); - mousePressed = FALSE; - } - void setColor( TQColor c ) { col = c; } - -signals: - void colorDropped( TQRgb ); - -protected: - void drawContents( TQPainter *p ); - void mousePressEvent( TQMouseEvent *e ); - void mouseMoveEvent( TQMouseEvent *e ); - void mouseReleaseEvent( TQMouseEvent *e ); -#ifndef TQT_NO_DRAGANDDROP - void dragEnterEvent( TQDragEnterEvent *e ); - void dragLeaveEvent( TQDragLeaveEvent *e ); - void dropEvent( TQDropEvent *e ); -#endif - -private: - TQColor col; - bool mousePressed; - TQPoint pressPos; - -}; - -void TQColorShowLabel::drawContents( TQPainter *p ) -{ - p->fillRect( contentsRect(), col ); -} - -void TQColorShower::showAlpha( bool b ) -{ - if ( b ) { - alphaLab->show(); - alphaEd->show(); - } else { - alphaLab->hide(); - alphaEd->hide(); - } -} - -void TQColorShowLabel::mousePressEvent( TQMouseEvent *e ) -{ - mousePressed = TRUE; - pressPos = e->pos(); -} - -void TQColorShowLabel::mouseMoveEvent( TQMouseEvent *e ) -{ -#ifndef TQT_NO_DRAGANDDROP - if ( !mousePressed ) - return; - if ( ( pressPos - e->pos() ).manhattanLength() > TQApplication::startDragDistance() ) { - TQColorDrag *drg = new TQColorDrag( col, this ); - TQPixmap pix( 30, 20 ); - pix.fill( col ); - TQPainter p( &pix ); - p.drawRect( 0, 0, pix.width(), pix.height() ); - p.end(); - drg->setPixmap( pix ); - mousePressed = FALSE; - drg->dragCopy(); - } -#endif -} - -#ifndef TQT_NO_DRAGANDDROP -void TQColorShowLabel::dragEnterEvent( TQDragEnterEvent *e ) -{ - if ( TQColorDrag::canDecode( e ) ) - e->accept(); - else - e->ignore(); -} - -void TQColorShowLabel::dragLeaveEvent( TQDragLeaveEvent * ) -{ -} - -void TQColorShowLabel::dropEvent( TQDropEvent *e ) -{ - if ( TQColorDrag::canDecode( e ) ) { - TQColorDrag::decode( e, col ); - repaint( FALSE ); - emit colorDropped( col.rgb() ); - e->accept(); - } else { - e->ignore(); - } -} -#endif // TQT_NO_DRAGANDDROP - -void TQColorShowLabel::mouseReleaseEvent( TQMouseEvent * ) -{ - if ( !mousePressed ) - return; - mousePressed = FALSE; -} - -TQColorShower::TQColorShower( TQWidget *parent, const char *name ) - :TQWidget( parent, name) -{ - curCol = tqRgb( -1, -1, -1 ); - TQColIntValidator *val256 = new TQColIntValidator( 0, 255, this ); - TQColIntValidator *val360 = new TQColIntValidator( 0, 360, this ); - - TQGridLayout *gl = new TQGridLayout( this, 1, 1, 6 ); - lab = new TQColorShowLabel( this ); - lab->setMinimumWidth( 60 ); //### - gl->addMultiCellWidget(lab, 0,-1,0,0); - connect( lab, TQ_SIGNAL( colorDropped(TQRgb) ), - this, TQ_SIGNAL( newCol(TQRgb) ) ); - connect( lab, TQ_SIGNAL( colorDropped(TQRgb) ), - this, TQ_SLOT( setRgb(TQRgb) ) ); - - hEd = new TQColNumLineEdit( this, "qt_hue_edit" ); - hEd->setValidator( val360 ); - TQLabel *l = new TQLabel( hEd, TQColorDialog::tr("Hu&e:"), this, "qt_hue_lbl" ); - l->setAlignment( AlignRight|AlignVCenter ); - gl->addWidget( l, 0, 1 ); - gl->addWidget( hEd, 0, 2 ); - - sEd = new TQColNumLineEdit( this, "qt_sat_edit" ); - sEd->setValidator( val256 ); - l = new TQLabel( sEd, TQColorDialog::tr("&Sat:"), this, "qt_sat_lbl" ); - l->setAlignment( AlignRight|AlignVCenter ); - gl->addWidget( l, 1, 1 ); - gl->addWidget( sEd, 1, 2 ); - - vEd = new TQColNumLineEdit( this, "qt_val_edit" ); - vEd->setValidator( val256 ); - l = new TQLabel( vEd, TQColorDialog::tr("&Val:"), this, "qt_val_lbl" ); - l->setAlignment( AlignRight|AlignVCenter ); - gl->addWidget( l, 2, 1 ); - gl->addWidget( vEd, 2, 2 ); - - rEd = new TQColNumLineEdit( this, "qt_red_edit" ); - rEd->setValidator( val256 ); - l = new TQLabel( rEd, TQColorDialog::tr("&Red:"), this, "qt_red_lbl" ); - l->setAlignment( AlignRight|AlignVCenter ); - gl->addWidget( l, 0, 3 ); - gl->addWidget( rEd, 0, 4 ); - - gEd = new TQColNumLineEdit( this, "qt_grn_edit" ); - gEd->setValidator( val256 ); - l = new TQLabel( gEd, TQColorDialog::tr("&Green:"), this, "qt_grn_lbl" ); - l->setAlignment( AlignRight|AlignVCenter ); - gl->addWidget( l, 1, 3 ); - gl->addWidget( gEd, 1, 4 ); - - bEd = new TQColNumLineEdit( this, "qt_blue_edit" ); - bEd->setValidator( val256 ); - l = new TQLabel( bEd, TQColorDialog::tr("Bl&ue:"), this, "qt_blue_lbl" ); - l->setAlignment( AlignRight|AlignVCenter ); - gl->addWidget( l, 2, 3 ); - gl->addWidget( bEd, 2, 4 ); - - alphaEd = new TQColNumLineEdit( this, "qt_aplha_edit" ); - alphaEd->setValidator( val256 ); - alphaLab = new TQLabel( alphaEd, TQColorDialog::tr("A&lpha channel:"), this, "qt_alpha_lbl" ); - alphaLab->setAlignment( AlignRight|AlignVCenter ); - gl->addMultiCellWidget( alphaLab, 3, 3, 1, 3 ); - gl->addWidget( alphaEd, 3, 4 ); - alphaEd->hide(); - alphaLab->hide(); - - connect( hEd, TQ_SIGNAL(textChanged(const TQString&)), this, TQ_SLOT(hsvEd()) ); - connect( sEd, TQ_SIGNAL(textChanged(const TQString&)), this, TQ_SLOT(hsvEd()) ); - connect( vEd, TQ_SIGNAL(textChanged(const TQString&)), this, TQ_SLOT(hsvEd()) ); - - connect( rEd, TQ_SIGNAL(textChanged(const TQString&)), this, TQ_SLOT(rgbEd()) ); - connect( gEd, TQ_SIGNAL(textChanged(const TQString&)), this, TQ_SLOT(rgbEd()) ); - connect( bEd, TQ_SIGNAL(textChanged(const TQString&)), this, TQ_SLOT(rgbEd()) ); - connect( alphaEd, TQ_SIGNAL(textChanged(const TQString&)), this, TQ_SLOT(rgbEd()) ); -} - -void TQColorShower::showCurrentColor() -{ - lab->setColor( currentColor() ); - lab->repaint(FALSE); //### -} - -void TQColorShower::rgbEd() -{ - rgbOriginal = TRUE; - if ( alphaEd->isVisible() ) - curCol = tqRgba( rEd->val(), gEd->val(), bEd->val(), currentAlpha() ); - else - curCol = tqRgb( rEd->val(), gEd->val(), bEd->val() ); - - rgb2hsv(currentColor(), hue, sat, val ); - - hEd->setNum( hue ); - sEd->setNum( sat ); - vEd->setNum( val ); - - showCurrentColor(); - emit newCol( currentColor() ); -} - -void TQColorShower::hsvEd() -{ - rgbOriginal = FALSE; - hue = hEd->val(); - sat = sEd->val(); - val = vEd->val(); - - curCol = TQColor( hue, sat, val, TQColor::Hsv ).rgb(); - - rEd->setNum( tqRed(currentColor()) ); - gEd->setNum( tqGreen(currentColor()) ); - bEd->setNum( tqBlue(currentColor()) ); - - showCurrentColor(); - emit newCol( currentColor() ); -} - -void TQColorShower::setRgb( TQRgb rgb ) -{ - rgbOriginal = TRUE; - curCol = rgb; - - rgb2hsv( currentColor(), hue, sat, val ); - - hEd->setNum( hue ); - sEd->setNum( sat ); - vEd->setNum( val ); - - rEd->setNum( tqRed(currentColor()) ); - gEd->setNum( tqGreen(currentColor()) ); - bEd->setNum( tqBlue(currentColor()) ); - - showCurrentColor(); -} - -void TQColorShower::setHsv( int h, int s, int v ) -{ - rgbOriginal = FALSE; - hue = h; val = v; sat = s; //Range check### - curCol = TQColor( hue, sat, val, TQColor::Hsv ).rgb(); - - hEd->setNum( hue ); - sEd->setNum( sat ); - vEd->setNum( val ); - - rEd->setNum( tqRed(currentColor()) ); - gEd->setNum( tqGreen(currentColor()) ); - bEd->setNum( tqBlue(currentColor()) ); - - showCurrentColor(); -} - -class TQColorDialogPrivate : public TQObject -{ -TQ_OBJECT -public: - TQColorDialogPrivate( TQColorDialog *p ); - TQRgb currentColor() const { return cs->currentColor(); } - void setCurrentColor( TQRgb rgb ); - - int currentAlpha() const { return cs->currentAlpha(); } - void setCurrentAlpha( int a ) { cs->setCurrentAlpha( a ); } - void showAlpha( bool b ) { cs->showAlpha( b ); } - -public slots: - void addCustom(); - - void newHsv( int h, int s, int v ); - void newColorTypedIn( TQRgb rgb ); - void newCustom( int, int ); - void newStandard( int, int ); -public: - TQWellArray *custom; - TQWellArray *standard; - - TQColorPicker *cp; - TQColorLuminancePicker *lp; - TQColorShower *cs; - int nextCust; - bool compact; -}; - -//sets all widgets to display h,s,v -void TQColorDialogPrivate::newHsv( int h, int s, int v ) -{ - cs->setHsv( h, s, v ); - cp->setCol( h, s ); - lp->setCol( h, s, v ); -} - -//sets all widgets to display rgb -void TQColorDialogPrivate::setCurrentColor( TQRgb rgb ) -{ - cs->setRgb( rgb ); - newColorTypedIn( rgb ); -} - -//sets all widgets exept cs to display rgb -void TQColorDialogPrivate::newColorTypedIn( TQRgb rgb ) -{ - int h, s, v; - rgb2hsv(rgb, h, s, v ); - cp->setCol( h, s ); - lp->setCol( h, s, v); -} - -void TQColorDialogPrivate::newCustom( int r, int c ) -{ - int i = r+2*c; - setCurrentColor( cusrgb[i] ); - nextCust = i; - if (standard) - standard->setSelected(-1,-1); -} - -void TQColorDialogPrivate::newStandard( int r, int c ) -{ - setCurrentColor( stdrgb[r+c*6] ); - if (custom) - custom->setSelected(-1,-1); -} - -TQColorDialogPrivate::TQColorDialogPrivate( TQColorDialog *dialog ) : - TQObject(dialog) -{ - compact = FALSE; - // small displays (e.g. PDAs cannot fit the full color dialog, - // so just use the color picker. - if ( tqApp->desktop()->width() < 480 || tqApp->desktop()->height() < 350 ) - compact = TRUE; - - nextCust = 0; - const int lumSpace = 3; - int border = 12; - if ( compact ) - border = 6; - TQHBoxLayout *topLay = new TQHBoxLayout( dialog, border, 6 ); - TQVBoxLayout *leftLay = 0; - - if ( !compact ) - leftLay = new TQVBoxLayout( topLay ); - - initRGB(); - - if ( !compact ) { - standard = new TQColorWell( dialog, 6, 8, stdrgb ); - standard->setCellWidth( 28 ); - standard->setCellHeight( 24 ); - TQLabel * lab = new TQLabel( standard, - TQColorDialog::tr( "&Basic colors"), dialog, "qt_basiccolors_lbl" ); - connect( standard, TQ_SIGNAL(selected(int,int)), TQ_SLOT(newStandard(int,int))); - leftLay->addWidget( lab ); - leftLay->addWidget( standard ); - - - leftLay->addStretch(); - - custom = new TQColorWell( dialog, 2, 8, cusrgb ); - custom->setCellWidth( 28 ); - custom->setCellHeight( 24 ); - custom->setAcceptDrops( TRUE ); - - connect( custom, TQ_SIGNAL(selected(int,int)), TQ_SLOT(newCustom(int,int))); - lab = new TQLabel( custom, TQColorDialog::tr( "&Custom colors") , dialog, "qt_custcolors_lbl" ); - leftLay->addWidget( lab ); - leftLay->addWidget( custom ); - - TQPushButton *custbut = - new TQPushButton( TQColorDialog::tr("&Define Custom Colors >>"), - dialog, "qt_def_custcolors_lbl" ); - custbut->setEnabled( FALSE ); - leftLay->addWidget( custbut ); - } else { - // better color picker size for small displays - pWidth = 150; - pHeight = 100; - - custom = 0; - standard = 0; - } - - TQVBoxLayout *rightLay = new TQVBoxLayout( topLay ); - - TQHBoxLayout *pickLay = new TQHBoxLayout( rightLay ); - - - TQVBoxLayout *cLay = new TQVBoxLayout( pickLay ); - cp = new TQColorPicker( dialog, "qt_colorpicker" ); - cp->setFrameStyle( TQFrame::Panel + TQFrame::Sunken ); - cLay->addSpacing( lumSpace ); - cLay->addWidget( cp ); - cLay->addSpacing( lumSpace ); - - lp = new TQColorLuminancePicker( dialog, "qt_luminance_picker" ); - lp->setFixedWidth( 20 ); //### - pickLay->addWidget( lp ); - - connect( cp, TQ_SIGNAL(newCol(int,int)), lp, TQ_SLOT(setCol(int,int)) ); - connect( lp, TQ_SIGNAL(newHsv(int,int,int)), this, TQ_SLOT(newHsv(int,int,int)) ); - - rightLay->addStretch(); - - cs = new TQColorShower( dialog, "qt_colorshower" ); - connect( cs, TQ_SIGNAL(newCol(TQRgb)), this, TQ_SLOT(newColorTypedIn(TQRgb))); - rightLay->addWidget( cs ); - - TQHBoxLayout *buttons; - if ( compact ) - buttons = new TQHBoxLayout( rightLay ); - else - buttons = new TQHBoxLayout( leftLay ); - - TQPushButton *ok, *cancel; - ok = new TQPushButton( TQColorDialog::tr("OK"), dialog, "qt_ok_btn" ); - connect( ok, TQ_SIGNAL(clicked()), dialog, TQ_SLOT(accept()) ); - ok->setDefault(TRUE); - cancel = new TQPushButton( TQColorDialog::tr("Cancel"), dialog, "qt_cancel_btn" ); - connect( cancel, TQ_SIGNAL(clicked()), dialog, TQ_SLOT(reject()) ); - buttons->addWidget( ok ); - buttons->addWidget( cancel ); - buttons->addStretch(); - - if ( !compact ) { - TQPushButton *addCusBt = new TQPushButton( - TQColorDialog::tr("&Add to Custom Colors"), - dialog, "qt_add_btn" ); - rightLay->addWidget( addCusBt ); - connect( addCusBt, TQ_SIGNAL(clicked()), this, TQ_SLOT(addCustom()) ); - } -} - -void TQColorDialogPrivate::addCustom() -{ - cusrgb[nextCust] = cs->currentColor(); - if (custom) - custom->repaintContents( FALSE ); - nextCust = (nextCust+1) % 16; -} - - -/*! - \class TQColorDialog ntqcolordialog.h - \brief The TQColorDialog class provides a dialog widget for specifying colors. - \mainclass - \ingroup dialogs - \ingroup graphics - - The color dialog's function is to allow users to choose colors. - For example, you might use this in a drawing program to allow the - user to set the brush color. - - The static functions provide modal color dialogs. - \omit - If you require a modeless dialog, use the TQColorDialog constructor. - \endomit - - The static getColor() function shows the dialog and allows the - user to specify a color. The getRgba() function does the same but - also allows the user to specify a color with an alpha channel - (transparency) value. - - The user can store customCount() different custom colors. The - custom colors are shared by all color dialogs, and remembered - during the execution of the program. Use setCustomColor() to set - the custom colors, and use customColor() to get them. - - \img qcolordlg-w.png -*/ - -/*! - Constructs a default color dialog with parent \a parent and called - \a name. If \a modal is TRUE the dialog will be modal. Use - setColor() to set an initial value. - - \sa getColor() -*/ - -TQColorDialog::TQColorDialog(TQWidget* parent, const char* name, bool modal) : - TQDialog(parent, name, modal, ( WType_Dialog | WStyle_Customize | WStyle_Title | - WStyle_DialogBorder | WStyle_SysMenu ) ) -{ - setSizeGripEnabled( FALSE ); - d = new TQColorDialogPrivate( this ); - -#ifndef TQT_NO_SETTINGS - if ( !customSet ) { - TQSettings settings; - settings.insertSearchPath( TQSettings::Windows, "/Trolltech" ); - for ( int i = 0; i < 2*8; ++i ) { - bool ok = FALSE; - TQRgb rgb = (TQRgb)settings.readNumEntry( "/TQt/customColors/" + TQString::number( i ), 0, &ok ); - if ( ok ) - cusrgb[i] = rgb; - } - } -#endif -} - -/*! - Pops up a modal color dialog, lets the user choose a color, and - returns that color. The color is initially set to \a initial. The - dialog is a child of \a parent and is called \a name. It returns - an invalid (see TQColor::isValid()) color if the user cancels the - dialog. All colors allocated by the dialog will be deallocated - before this function returns. -*/ - -TQColor TQColorDialog::getColor( const TQColor& initial, TQWidget *parent, - const char *name ) -{ -#if defined(TQ_WS_X11) - if( TQTDEIntegration::enabled()) - return TQTDEIntegration::getColor( initial, parent, name ); -#elif defined(TQ_WS_MAC) - return macGetColor(initial, parent, name); -#endif - - int allocContext = TQColor::enterAllocContext(); - TQColorDialog *dlg = new TQColorDialog( parent, name, TRUE ); //modal -#ifndef TQT_NO_WIDGET_TOPEXTRA - dlg->setCaption( TQColorDialog::tr( "Select color" ) ); -#endif - dlg->setColor( initial ); - dlg->selectColor( initial ); - int resultCode = dlg->exec(); - TQColor::leaveAllocContext(); - TQColor result; - if ( resultCode == TQDialog::Accepted ) - result = dlg->color(); - TQColor::destroyAllocContext(allocContext); - delete dlg; - return result; -} - - -/*! - Pops up a modal color dialog to allow the user to choose a color - and an alpha channel (transparency) value. The color+alpha is - initially set to \a initial. The dialog is a child of \a parent - and called \a name. - - If \a ok is non-null, \e *\a ok is set to TRUE if the user clicked - OK, and to FALSE if the user clicked Cancel. - - If the user clicks Cancel, the \a initial value is returned. -*/ - -TQRgb TQColorDialog::getRgba( TQRgb initial, bool *ok, - TQWidget *parent, const char* name ) -{ -#if defined(TQ_WS_MAC) - if( TQTDEIntegration::enabled()) { - TQColor color = TQTDEIntegration::getColor( TQColor( initial ), parent, name ); - if( ok ) - *ok = color.isValid(); - return color.rgba(); - } -#elif defined(TQ_WS_MAC) - return macGetRgba(initial, ok, parent, name); -#endif - - int allocContext = TQColor::enterAllocContext(); - TQColorDialog *dlg = new TQColorDialog( parent, name, TRUE ); //modal - - TQ_CHECK_PTR( dlg ); -#ifndef TQT_NO_WIDGET_TOPEXTRA - dlg->setCaption( TQColorDialog::tr( "Select color" ) ); -#endif - dlg->setColor( initial ); - dlg->selectColor( initial ); - dlg->setSelectedAlpha( tqAlpha(initial) ); - int resultCode = dlg->exec(); - TQColor::leaveAllocContext(); - TQRgb result = initial; - if ( resultCode == TQDialog::Accepted ) { - TQRgb c = dlg->color().rgb(); - int alpha = dlg->selectedAlpha(); - result = tqRgba( tqRed(c), tqGreen(c), tqBlue(c), alpha ); - } - if ( ok ) - *ok = resultCode == TQDialog::Accepted; - - TQColor::destroyAllocContext(allocContext); - delete dlg; - return result; -} - - - - - -/*! - Returns the color currently selected in the dialog. - - \sa setColor() -*/ - -TQColor TQColorDialog::color() const -{ - return TQColor(d->currentColor()); -} - - -/*! - Destroys the dialog and frees any memory it allocated. -*/ - -TQColorDialog::~TQColorDialog() -{ -#ifndef TQT_NO_SETTINGS - if ( !customSet ) { - TQSettings settings; - settings.insertSearchPath( TQSettings::Windows, "/Trolltech" ); - for ( int i = 0; i < 2*8; ++i ) - settings.writeEntry( "/TQt/customColors/" + TQString::number( i ), (int)cusrgb[i] ); - } -#endif -} - - -/*! - Sets the color shown in the dialog to \a c. - - \sa color() -*/ - -void TQColorDialog::setColor( const TQColor& c ) -{ - d->setCurrentColor( c.rgb() ); -} - - - - -/*! - Sets the initial alpha channel value to \a a, and shows the alpha - channel entry box. -*/ - -void TQColorDialog::setSelectedAlpha( int a ) -{ - d->showAlpha( TRUE ); - d->setCurrentAlpha( a ); -} - - -/*! - Returns the value selected for the alpha channel. -*/ - -int TQColorDialog::selectedAlpha() const -{ - return d->currentAlpha(); -} - -/*! - Sets focus to the corresponding button, if any. -*/ -bool TQColorDialog::selectColor( const TQColor& col ) -{ - TQRgb color = col.rgb(); - int i = 0, j = 0; - // Check standard colors - if (d->standard) { - for ( i = 0; i < 6; i++ ) { - for ( j = 0; j < 8; j++ ) { - if ( color == stdrgb[i + j*6] ) { - d->newStandard( i, j ); - d->standard->setCurrent( i, j ); - d->standard->setSelected( i, j ); - d->standard->setFocus(); - return TRUE; - } - } - } - } - // Check custom colors - if (d->custom) { - for ( i = 0; i < 2; i++ ) { - for ( j = 0; j < 8; j++ ) { - if ( color == cusrgb[i + j*2] ) { - d->newCustom( i, j ); - d->custom->setCurrent( i, j ); - d->custom->setSelected( i, j ); - d->custom->setFocus(); - return TRUE; - } - } - } - } - return FALSE; -} - -#include "qcolordialog.moc" - -#endif diff --git a/src/dialogs/qfontdialog.cpp b/src/dialogs/qfontdialog.cpp deleted file mode 100644 index dfb9731e1..000000000 --- a/src/dialogs/qfontdialog.cpp +++ /dev/null @@ -1,841 +0,0 @@ -/**************************************************************************** -** -** Implementation of TQFontDialog -** -** Created : 970605 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the dialogs module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#include "ntqwindowdefs.h" - -#ifndef TQT_NO_FONTDIALOG - -#include "ntqfontdialog.h" - -#include "ntqlineedit.h" -#include "ntqlistbox.h" -#include "ntqpushbutton.h" -#include "ntqcheckbox.h" -#include "ntqcombobox.h" -#include "ntqlayout.h" -#include "ntqvgroupbox.h" -#include "ntqhgroupbox.h" -#include "ntqlabel.h" -#include "ntqapplication.h" -#include "ntqfontdatabase.h" -#include "tqstyle.h" -#include -#include - -#ifdef TQ_WS_X11 -#include "private/tqttdeintegration_x11_p.h" -#endif - -/*! - \class TQFontDialog ntqfontdialog.h - \ingroup dialogs - \mainclass - \brief The TQFontDialog class provides a dialog widget for selecting a font. - - The usual way to use this class is to call one of the static convenience - functions, e.g. getFont(). - - Examples: - - \code - bool ok; - TQFont font = TQFontDialog::getFont( - &ok, TQFont( "Helvetica [Cronyx]", 10 ), this ); - if ( ok ) { - // font is set to the font the user selected - } else { - // the user canceled the dialog; font is set to the initial - // value, in this case Helvetica [Cronyx], 10 - } - \endcode - - The dialog can also be used to set a widget's font directly: - \code - myWidget.setFont( TQFontDialog::getFont( 0, myWidget.font() ) ); - \endcode - If the user clicks OK the font they chose will be used for myWidget, - and if they click Cancel the original font is used. - - \sa TQFont TQFontInfo TQFontMetrics - - -*/ - -class TQFontDialogPrivate -{ -public: - TQFontDialogPrivate() : script( TQFontPrivate::defaultScript ) {}; - TQLabel * familyAccel; - TQLineEdit * familyEdit; - TQListBox * familyList; - - TQLabel * styleAccel; - TQLineEdit * styleEdit; - TQListBox * styleList; - - TQLabel * sizeAccel; - TQLineEdit * sizeEdit; - TQListBox * sizeList; - - TQVGroupBox * effects; - TQCheckBox * strikeout; - TQCheckBox * underline; - TQComboBox * color; - - TQHGroupBox * sample; - TQLineEdit * sampleEdit; - - TQLabel * scriptAccel; - TQComboBox * scriptCombo; - - TQPushButton * ok; - TQPushButton * cancel; - - TQBoxLayout * buttonLayout; - TQBoxLayout * effectsLayout; - TQBoxLayout * sampleLayout; - TQBoxLayout * sampleEditLayout; - - TQFontDatabase fdb; - - TQString family; - TQFont::Script script; - TQString style; - int size; - - bool smoothScalable; -}; - - -/*! - \internal - Constructs a standard font dialog. - - Use setFont() to set the initial font attributes. - - The \a parent, \a name, \a modal and \a f parameters are passed to - the TQDialog constructor. - - \sa getFont() -*/ - -TQFontDialog::TQFontDialog( TQWidget *parent, const char *name, - bool modal, WFlags f ) - : TQDialog( parent, name, modal, f ) -{ - setSizeGripEnabled( TRUE ); - d = new TQFontDialogPrivate; - // grid - d->familyEdit = new TQLineEdit( this, "font family I" ); - d->familyEdit->setReadOnly( TRUE ); - d->familyList = new TQListBox( this, "font family II" ); - d->familyEdit->setFocusProxy( d->familyList ); - - d->familyAccel - = new TQLabel( d->familyList, tr("&Font"), this, "family accelerator" ); - d->familyAccel->setIndent( 2 ); - - d->styleEdit = new TQLineEdit( this, "font style I" ); - d->styleEdit->setReadOnly( TRUE ); - d->styleList = new TQListBox( this, "font style II" ); - d->styleEdit->setFocusProxy( d->styleList ); - - d->styleAccel - = new TQLabel( d->styleList, tr("Font st&yle"), this, "style accelerator" ); - d->styleAccel->setIndent( 2 ); - - d->sizeEdit = new TQLineEdit( this, "font size I" ); - d->sizeEdit->setFocusPolicy( ClickFocus ); - TQIntValidator *validator = new TQIntValidator( 1, 512, this ); - d->sizeEdit->setValidator( validator ); - d->sizeList = new TQListBox( this, "font size II" ); - - d->sizeAccel - = new TQLabel ( d->sizeEdit, tr("&Size"), this, "size accelerator" ); - d->sizeAccel->setIndent( 2 ); - - // effects box - d->effects = new TQVGroupBox( tr("Effects"), this, "font effects" ); - d->strikeout = new TQCheckBox( d->effects, "strikeout on/off" ); - d->strikeout->setText( tr("Stri&keout") ); - d->underline = new TQCheckBox( d->effects, "underline on/off" ); - d->underline->setText( tr("&Underline") ); - - d->sample = new TQHGroupBox( tr("Sample"), this, "sample text" ); - d->sampleEdit = new TQLineEdit( d->sample, "r/w sample text" ); - d->sampleEdit->setSizePolicy( TQSizePolicy( TQSizePolicy::Ignored, TQSizePolicy::Ignored) ); - d->sampleEdit->setAlignment( AlignCenter ); - // Note that the sample text is *not* translated with tr(), as the - // characters used depend on the charset encoding. - d->sampleEdit->setText( "AaBbYyZz" ); - - d->scriptCombo = new TQComboBox( FALSE, this, "font encoding" ); - - d->scriptAccel - = new TQLabel( d->scriptCombo, tr("Scr&ipt"), this,"encoding label"); - d->scriptAccel->setIndent( 2 ); - - d->size = 0; - d->smoothScalable = FALSE; - - connect( d->scriptCombo, TQ_SIGNAL(activated(int)), - TQ_SLOT(scriptHighlighted(int)) ); - connect( d->familyList, TQ_SIGNAL(highlighted(int)), - TQ_SLOT(familyHighlighted(int)) ); - connect( d->styleList, TQ_SIGNAL(highlighted(int)), - TQ_SLOT(styleHighlighted(int)) ); - connect( d->sizeList, TQ_SIGNAL(highlighted(const TQString&)), - TQ_SLOT(sizeHighlighted(const TQString&)) ); - connect( d->sizeEdit, TQ_SIGNAL(textChanged(const TQString&)), - TQ_SLOT(sizeChanged(const TQString&)) ); - - connect( d->strikeout, TQ_SIGNAL(clicked()), - TQ_SLOT(updateSample()) ); - connect( d->underline, TQ_SIGNAL(clicked()), - TQ_SLOT(updateSample()) ); - - (void)d->familyList->sizeHint(); - (void)d->styleList->sizeHint(); - (void)d->sizeList->sizeHint(); - - for (int i = 0; i < TQFont::NScripts; i++) { - TQString scriptname = TQFontDatabase::scriptName((TQFont::Script) i); - if ( !scriptname.isEmpty() ) - d->scriptCombo->insertItem( scriptname ); - } - - updateFamilies(); - if ( d->familyList->count() != 0 ) - d->familyList->setCurrentItem( 0 ); - - // grid layout - TQGridLayout * mainGrid = new TQGridLayout( this, 9, 6, 12, 0 ); - - mainGrid->addWidget( d->familyAccel, 0, 0 ); - mainGrid->addWidget( d->familyEdit, 1, 0 ); - mainGrid->addWidget( d->familyList, 2, 0 ); - - mainGrid->addWidget( d->styleAccel, 0, 2 ); - mainGrid->addWidget( d->styleEdit, 1, 2 ); - mainGrid->addWidget( d->styleList, 2, 2 ); - - mainGrid->addWidget( d->sizeAccel, 0, 4 ); - mainGrid->addWidget( d->sizeEdit, 1, 4 ); - mainGrid->addWidget( d->sizeList, 2, 4 ); - - mainGrid->setColStretch( 0, 38 ); - mainGrid->setColStretch( 2, 24 ); - mainGrid->setColStretch( 4, 10 ); - - mainGrid->addColSpacing( 1, 6 ); - mainGrid->addColSpacing( 3, 6 ); - mainGrid->addColSpacing( 5, 6 ); - - mainGrid->addRowSpacing( 3, 12 ); - - mainGrid->addWidget( d->effects, 4, 0 ); - - mainGrid->addMultiCellWidget( d->sample, 4, 7, 2, 4 ); - - mainGrid->addWidget( d->scriptAccel, 5, 0 ); - mainGrid->addRowSpacing( 6, 2 ); - mainGrid->addWidget( d->scriptCombo, 7, 0 ); - - mainGrid->addRowSpacing( 8, 12 ); - - TQHBoxLayout *buttonBox = new TQHBoxLayout; - mainGrid->addMultiCell( buttonBox, 9, 9, 0, 4 ); - - buttonBox->addStretch( 1 ); - TQString okt = modal ? tr("OK") : tr("Apply"); - d->ok = new TQPushButton( okt, this, "accept font selection" ); - buttonBox->addWidget( d->ok ); - if ( modal ) - connect( d->ok, TQ_SIGNAL(clicked()), TQ_SLOT(accept()) ); - d->ok->setDefault( TRUE ); - - buttonBox->addSpacing( 12 ); - - TQString cancelt = modal ? tr("Cancel") : tr("Close"); - d->cancel = new TQPushButton( cancelt, this, "cancel/close" ); - buttonBox->addWidget( d->cancel ); - connect( d->cancel, TQ_SIGNAL(clicked()), TQ_SLOT(reject()) ); - - resize( 500, 360 ); - - d->sizeEdit->installEventFilter( this ); - d->familyList->installEventFilter( this ); - d->styleList->installEventFilter( this ); - d->sizeList->installEventFilter( this ); - - d->familyList->setFocus(); -} - -/*! - \internal - Destroys the font dialog and frees up its storage. -*/ - -TQFontDialog::~TQFontDialog() -{ - delete d; - d = 0; -} - -/*! - Executes a modal font dialog and returns a font. - - If the user clicks OK, the selected font is returned. If the user - clicks Cancel, the \a initial font is returned. - - The dialog is called \a name, with the parent \a parent. - \a initial is the initially selected font. - If the \a ok parameter is not-null, \e *\a ok is set to TRUE if the - user clicked OK, and set to FALSE if the user clicked Cancel. - - This static function is less flexible than the full TQFontDialog - object, but is convenient and easy to use. - - Examples: - \code - bool ok; - TQFont font = TQFontDialog::getFont( &ok, TQFont( "Times", 12 ), this ); - if ( ok ) { - // font is set to the font the user selected - } else { - // the user canceled the dialog; font is set to the initial - // value, in this case Times, 12. - } - \endcode - - The dialog can also be used to set a widget's font directly: - \code - myWidget.setFont( TQFontDialog::getFont( 0, myWidget.font() ) ); - \endcode - In this example, if the user clicks OK the font they chose will be - used, and if they click Cancel the original font is used. -*/ -TQFont TQFontDialog::getFont( bool *ok, const TQFont &initial, - TQWidget *parent, const char* name) -{ - return getFont( ok, &initial, parent, name ); -} - -/*! - \overload - - Executes a modal font dialog and returns a font. - - If the user clicks OK, the selected font is returned. If the user - clicks Cancel, the TQt default font is returned. - - The dialog is called \a name, with parent \a parent. - If the \a ok parameter is not-null, \e *\a ok is set to TRUE if the - user clicked OK, and FALSE if the user clicked Cancel. - - This static function is less functional than the full TQFontDialog - object, but is convenient and easy to use. - - Example: - \code - bool ok; - TQFont font = TQFontDialog::getFont( &ok, this ); - if ( ok ) { - // font is set to the font the user selected - } else { - // the user canceled the dialog; font is set to the default - // application font, TQApplication::font() - } - \endcode - -*/ -TQFont TQFontDialog::getFont( bool *ok, TQWidget *parent,const char* name) -{ - return getFont( ok, 0, parent, name ); -} - -extern bool tqt_use_native_dialogs; - -TQFont TQFontDialog::getFont( bool *ok, const TQFont *def, - TQWidget *parent, const char* name) -{ -#if defined(TQ_WS_X11) - if ( tqt_use_native_dialogs && TQTDEIntegration::enabled()) - return TQTDEIntegration::getFont( ok, def, parent, name ); -#endif - TQFont result; - if ( def ) - result = *def; - - TQFontDialog *dlg = new TQFontDialog( parent, name, TRUE ); - - dlg->setFont( ( def ? *def : TQFont() ) ); -#ifndef TQT_NO_WIDGET_TOPEXTRA - dlg->setCaption( tr("Select Font") ); -#endif - - bool res = (dlg->exec() == TQDialog::Accepted); - if ( res ) - result = dlg->font(); - if ( ok ) - *ok = res; - delete dlg; - return result; -} - - -/*! - \internal - An event filter to make the Up, Down, PageUp and PageDown keys work - correctly in the line edits. The source of the event is the object - \a o and the event is \a e. -*/ - -bool TQFontDialog::eventFilter( TQObject * o , TQEvent * e ) -{ - if ( e->type() == TQEvent::KeyPress) { - TQKeyEvent * k = (TQKeyEvent *)e; - if ( o == d->sizeEdit && - (k->key() == Key_Up || - k->key() == Key_Down || - k->key() == Key_Prior || - k->key() == Key_Next) ) { - - int ci = d->sizeList->currentItem(); - (void)TQApplication::sendEvent( d->sizeList, k ); - - if ( ci != d->sizeList->currentItem() && - style().styleHint(TQStyle::SH_FontDialog_SelectAssociatedText, this)) - d->sizeEdit->selectAll(); - return TRUE; - } else if ( ( o == d->familyList || o == d->styleList ) && - ( k->key() == Key_Return || k->key() == Key_Enter) ) { - k->accept(); - accept(); - return TRUE; - } - } else if ( e->type() == TQEvent::FocusIn && - style().styleHint(TQStyle::SH_FontDialog_SelectAssociatedText, this) ) { - if ( o == d->familyList ) - d->familyEdit->selectAll(); - else if ( o == d->styleList ) - d->styleEdit->selectAll(); - else if ( o == d->sizeList ) - d->sizeEdit->selectAll(); - } else if ( e->type() == TQEvent::MouseButtonPress && o == d->sizeList ) { - d->sizeEdit->setFocus(); - } - return TQDialog::eventFilter( o, e ); -} - -#ifdef TQ_WS_MAC -// #define SHOW_FONTS_IN_FAMILIES -#endif - -#ifdef SHOW_FONTS_IN_FAMILIES -#include "ntqpainter.h" -#include - -class TQListBoxFontText : public TQListBoxText -{ - TQFont cfont; -public: - TQListBoxFontText( const TQString & text ); - ~TQListBoxFontText() { } - - int height( const TQListBox * ) const; - int width( const TQListBox * ) const; - -protected: - void paint( TQPainter * ); -}; - -TQListBoxFontText::TQListBoxFontText( const TQString & text ) - : TQListBoxText(text), cfont(text) -{ -} - -int TQListBoxFontText::height( const TQListBox * ) const -{ - TQFontMetrics fm(cfont); - return TQMAX( fm.lineSpacing() + 2, TQApplication::globalStrut().height() ); -} - -int TQListBoxFontText::width( const TQListBox * ) const -{ - TQFontMetrics fm(cfont); - return TQMAX( fm.width( text() ) + 6, TQApplication::globalStrut().width() ); -} - -void TQListBoxFontText::paint( TQPainter *painter ) -{ - painter->save(); - painter->setFont(cfont); - TQListBoxText::paint(painter); - painter->restore(); -} - -#endif - -/*! - \internal - Updates the contents of the "font family" list box. This - function can be reimplemented if you have special requirements. -*/ - -void TQFontDialog::updateFamilies() -{ - d->familyList->blockSignals( TRUE ); - - enum match_t { MATCH_NONE=0, MATCH_LAST_RESORT=1, MATCH_APP=2, MATCH_FALLBACK, MATCH_FAMILY=3 }; - - TQStringList familyNames = d->fdb.families(d->script); - { - // merge the unicode/unknown family list with the above list. - TQStringList l = d->fdb.families(TQFont::Unicode) + - d->fdb.families(TQFont::UnknownScript); - TQStringList::ConstIterator it = l.begin(), end = l.end(); - for (; it != end; ++it) { - if (! familyNames.contains(*it)) - familyNames << *it; - } - } - - familyNames.sort(); - - d->familyList->clear(); -#ifdef SHOW_FONTS_IN_FAMILIES - TQStringList::Iterator it = familyNames.begin(); - int idx = 0; - for( ; it != familyNames.end() ; ++it ) - d->familyList->insertItem(new TQListBoxFontText(*it), idx++); -#else - d->familyList->insertStringList( familyNames ); -#endif - - TQString foundryName1, familyName1, foundryName2, familyName2; - int bestFamilyMatch = -1; - match_t bestFamilyType = MATCH_NONE; - - TQFont f; - - // ##### do the right thing for a list of family names in the font. - TQFontDatabase::parseFontName(d->family, foundryName1, familyName1); - - TQStringList::Iterator it = familyNames.begin(); - int i = 0; - for( ; it != familyNames.end(); ++it, ++i ) { - - TQFontDatabase::parseFontName(*it, foundryName2, familyName2); - - //try to match.. - if ( familyName1 == familyName2 ) { - bestFamilyType = MATCH_FAMILY; - if ( foundryName1 == foundryName2 ) { - bestFamilyMatch = i; - break; - } - if ( bestFamilyMatch < MATCH_FAMILY ) - bestFamilyMatch = i; - } - - //and try some fall backs - match_t type = MATCH_NONE; - if ( bestFamilyType <= MATCH_NONE && familyName2 == f.lastResortFamily() ) - type = MATCH_LAST_RESORT; - if ( bestFamilyType <= MATCH_LAST_RESORT && familyName2 == f.family() ) - type = MATCH_APP; - // ### add fallback for script - if ( type != MATCH_NONE ) { - bestFamilyType = type; - bestFamilyMatch = i; - } - } - - if (i != -1 && bestFamilyType != MATCH_NONE) - d->familyList->setCurrentItem(bestFamilyMatch); - else - d->familyList->setCurrentItem( 0 ); - d->familyEdit->setText( d->familyList->currentText() ); - if ( style().styleHint(TQStyle::SH_FontDialog_SelectAssociatedText, this) && - d->familyList->hasFocus() ) - d->familyEdit->selectAll(); - - d->familyList->blockSignals( FALSE ); - updateStyles(); -} - -/*! - \internal - Updates the contents of the "font style" list box. This - function can be reimplemented if you have special requirements. -*/ - -void TQFontDialog::updateStyles() -{ - d->styleList->blockSignals( TRUE ); - - d->styleList->clear(); - - TQStringList styles = d->fdb.styles( d->familyList->currentText() ); - - if ( styles.isEmpty() ) { - d->styleEdit->clear(); - d->smoothScalable = FALSE; - } else { - d->styleList->insertStringList( styles ); - - if ( !d->style.isEmpty() ) { - bool found = FALSE; - bool first = TRUE; - TQString cstyle = d->style; - redo: - for ( int i = 0 ; i < (int)d->styleList->count() ; i++ ) { - if ( cstyle == d->styleList->text(i) ) { - d->styleList->setCurrentItem( i ); - found = TRUE; - break; - } - } - if (!found && first) { - if (cstyle.contains("Italic")) { - cstyle.replace("Italic", "Oblique"); - first = FALSE; - goto redo; - } else if (cstyle.contains("Oblique")) { - cstyle.replace("Oblique", "Italic"); - first = FALSE; - goto redo; - } - } - if ( !found ) - d->styleList->setCurrentItem( 0 ); - } - - d->styleEdit->setText( d->styleList->currentText() ); - if ( style().styleHint(TQStyle::SH_FontDialog_SelectAssociatedText, this) && - d->styleList->hasFocus() ) - d->styleEdit->selectAll(); - - d->smoothScalable = d->fdb.isSmoothlyScalable( d->familyList->currentText(), d->styleList->currentText() ); - } - - d->styleList->blockSignals( FALSE ); - - updateSizes(); -} - -/*! - \internal - Updates the contents of the "font size" list box. This - function can be reimplemented if you have special requirements. -*/ - -void TQFontDialog::updateSizes() -{ - d->sizeList->blockSignals( TRUE ); - - d->sizeList->clear(); - - if ( !d->familyList->currentText().isEmpty() ) { - TQValueList sizes = d->fdb.pointSizes( d->familyList->currentText(), d->styleList->currentText() ); - - int i = 0; - bool found = FALSE; - for( TQValueList::iterator it = sizes.begin() ; it != sizes.end(); ++it ) { - d->sizeList->insertItem( TQString::number( *it ) ); - if ( !found && *it >= d->size ) { - d->sizeList->setCurrentItem( i ); - found = TRUE; - } - ++i; - } - if ( !found ) { - // we request a size bigger than the ones in the list, select the biggest one - d->sizeList->setCurrentItem( d->sizeList->count() - 1 ); - } - - d->sizeEdit->blockSignals( TRUE ); - d->sizeEdit->setText( ( d->smoothScalable ? TQString::number( d->size ) : d->sizeList->currentText() ) ); - if ( style().styleHint(TQStyle::SH_FontDialog_SelectAssociatedText, this) && - d->sizeList->hasFocus() ) - d->sizeEdit->selectAll(); - d->sizeEdit->blockSignals( FALSE ); - } else { - d->sizeEdit->clear(); - } - - d->sizeList->blockSignals( FALSE ); - updateSample(); -} - -void TQFontDialog::updateSample() -{ - if ( d->familyList->currentText().isEmpty() ) - d->sampleEdit->clear(); - else - d->sampleEdit->setFont( font() ); -} - -/*! - \internal -*/ -void TQFontDialog::scriptHighlighted( int index ) -{ - d->script = (TQFont::Script)index; - d->sampleEdit->setText( d->fdb.scriptSample( d->script ) ); - updateFamilies(); -} - -/*! - \internal -*/ -void TQFontDialog::familyHighlighted( int i ) -{ - d->family = d->familyList->text( i ); - d->familyEdit->setText( d->family ); - if ( style().styleHint(TQStyle::SH_FontDialog_SelectAssociatedText, this) && - d->familyList->hasFocus() ) - d->familyEdit->selectAll(); - - updateStyles(); -} - - -/*! - \internal -*/ - -void TQFontDialog::styleHighlighted( int index ) -{ - TQString s = d->styleList->text( index ); - d->styleEdit->setText( s ); - if ( style().styleHint(TQStyle::SH_FontDialog_SelectAssociatedText, this) && - d->styleList->hasFocus() ) - d->styleEdit->selectAll(); - - d->style = s; - - updateSizes(); -} - - -/*! - \internal -*/ - -void TQFontDialog::sizeHighlighted( const TQString &s ) -{ - d->sizeEdit->setText( s ); - if ( style().styleHint(TQStyle::SH_FontDialog_SelectAssociatedText, this) && - d->sizeEdit->hasFocus() ) - d->sizeEdit->selectAll(); - - d->size = s.toInt(); - updateSample(); -} - -/*! - \internal - This slot is called if the user changes the font size. - The size is passed in the \a s argument as a \e string. -*/ - -void TQFontDialog::sizeChanged( const TQString &s ) -{ - // no need to check if the conversion is valid, since we have an TQIntValidator in the size edit - int size = s.toInt(); - if ( d->size == size ) - return; - - d->size = size; - if ( d->sizeList->count() != 0 ) { - int i; - for ( i = 0 ; i < (int)d->sizeList->count() - 1 ; i++ ) { - if ( d->sizeList->text(i).toInt() >= d->size ) - break; - } - d->sizeList->blockSignals( TRUE ); - d->sizeList->setCurrentItem( i ); - d->sizeList->blockSignals( FALSE ); - } - updateSample(); -} - -/*! - \internal - Sets the font highlighted in the TQFontDialog to font \a f. - - \sa font() -*/ - -void TQFontDialog::setFont( const TQFont &f ) -{ - d->family = f.family(); - d->style = d->fdb.styleString( f ); - d->size = f.pointSize(); - if ( d->size == -1 ) { - TQFontInfo fi( f ); - d->size = fi.pointSize(); - } - d->strikeout->setChecked( f.strikeOut() ); - d->underline->setChecked( f.underline() ); - - updateFamilies(); -} - -/*! - \internal - Returns the font which the user has chosen. - - \sa setFont() -*/ - -TQFont TQFontDialog::font() const -{ - int pSize = d->sizeEdit->text().toInt(); - - TQFont f = d->fdb.font( d->familyList->currentText(), d->style, pSize ); - f.setStrikeOut( d->strikeout->isChecked() ); - f.setUnderline( d->underline->isChecked() ); - return f; -} - -#endif diff --git a/src/dialogs/qprogressdialog.cpp b/src/dialogs/qprogressdialog.cpp index 1202d4b76..0527f17d2 100644 --- a/src/dialogs/qprogressdialog.cpp +++ b/src/dialogs/qprogressdialog.cpp @@ -43,7 +43,7 @@ #ifndef TQT_NO_PROGRESSDIALOG #include "ntqaccel.h" -#include "ntqpainter.h" +#include "tqpainter.h" #include "ntqdrawutil.h" #include "tqdatetime.h" #include "ntqapplication.h" diff --git a/src/dialogs/qt_dialogs.pri b/src/dialogs/qt_dialogs.pri index cfd0f5b06..669dd70a4 100644 --- a/src/dialogs/qt_dialogs.pri +++ b/src/dialogs/qt_dialogs.pri @@ -3,27 +3,27 @@ dialogs { DIALOGS_P = dialogs - HEADERS += $$DIALOGS_H/ntqcolordialog.h \ + HEADERS += $$DIALOGS_H/tqcolordialog.h \ $$DIALOGS_H/ntqdialog.h \ $$DIALOGS_H/ntqerrormessage.h \ $$DIALOGS_H/tqfiledialog.h \ - $$DIALOGS_H/ntqfontdialog.h \ + $$DIALOGS_H/tqfontdialog.h \ $$DIALOGS_H/ntqmessagebox.h \ $$DIALOGS_H/ntqprogressdialog.h \ $$DIALOGS_H/ntqtabdialog.h \ $$DIALOGS_H/ntqwizard.h \ $$DIALOGS_H/ntqinputdialog.h - !embedded:mac:SOURCES += $$DIALOGS_CPP/tqfiledialog_mac.cpp $$DIALOGS_CPP/qcolordialog_mac.cpp + !embedded:mac:SOURCES += $$DIALOGS_CPP/tqfiledialog_mac.cpp $$DIALOGS_CPP/tqcolordialog_mac.cpp win32:SOURCES += $$DIALOGS_CPP/tqfiledialog_win.cpp unix:SOURCES += $$DIALOGS_CPP/qprintdialog.cpp unix:HEADERS += $$DIALOGS_H/ntqprintdialog.h - SOURCES += $$DIALOGS_CPP/qcolordialog.cpp \ + SOURCES += $$DIALOGS_CPP/tqcolordialog.cpp \ $$DIALOGS_CPP/qdialog.cpp \ $$DIALOGS_CPP/qerrormessage.cpp \ $$DIALOGS_CPP/tqfiledialog.cpp \ - $$DIALOGS_CPP/qfontdialog.cpp \ + $$DIALOGS_CPP/tqfontdialog.cpp \ $$DIALOGS_CPP/qmessagebox.cpp \ $$DIALOGS_CPP/qprogressdialog.cpp \ $$DIALOGS_CPP/qtabdialog.cpp \ diff --git a/src/dialogs/qtabdialog.cpp b/src/dialogs/qtabdialog.cpp index f2601cca2..d0aa11e05 100644 --- a/src/dialogs/qtabdialog.cpp +++ b/src/dialogs/qtabdialog.cpp @@ -46,7 +46,7 @@ #include "ntqtabbar.h" #include "ntqtabwidget.h" #include "ntqpushbutton.h" -#include "ntqpainter.h" +#include "tqpainter.h" #include "ntqpixmap.h" #include "ntqapplication.h" #include "ntqtabwidget.h" diff --git a/src/dialogs/qwizard.cpp b/src/dialogs/qwizard.cpp index e5b3f8f46..3f8371ea7 100644 --- a/src/dialogs/qwizard.cpp +++ b/src/dialogs/qwizard.cpp @@ -49,7 +49,7 @@ #include "tqwidgetstack.h" #include "ntqapplication.h" #include "tqptrlist.h" -#include "ntqpainter.h" +#include "tqpainter.h" #include "ntqaccel.h" /*! \file wizard/wizard.cpp */ diff --git a/src/dialogs/tqcolordialog.cpp b/src/dialogs/tqcolordialog.cpp new file mode 100644 index 000000000..09040eef3 --- /dev/null +++ b/src/dialogs/tqcolordialog.cpp @@ -0,0 +1,1673 @@ +/**************************************************************************** +** +** Implementation of TQColorDialog class +** +** Created : 990222 +** +** Copyright (C) 1999-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the dialogs module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#include "tqcolordialog.h" + +#ifndef TQT_NO_COLORDIALOG + +#include "tqpainter.h" +#include "ntqlayout.h" +#include "ntqlabel.h" +#include "ntqpushbutton.h" +#include "ntqlineedit.h" +#include "tqimage.h" +#include "ntqpixmap.h" +#include "ntqdrawutil.h" +#include "ntqvalidator.h" +#include "tqdragobject.h" +#include "ntqgridview.h" +#include "ntqapplication.h" +#include "tqstyle.h" +#include "tqsettings.h" +#include "tqpopupmenu.h" + +#ifdef TQ_WS_MAC +TQRgb macGetRgba( TQRgb initial, bool *ok, TQWidget *parent, const char* name ); +TQColor macGetColor( const TQColor& initial, TQWidget *parent, const char *name ); +#endif + +#ifdef TQ_WS_X11 +#include "private/tqttdeintegration_x11_p.h" +#endif + +//////////// TQWellArray BEGIN + +struct TQWellArrayData; + +class TQWellArray : public TQGridView +{ + TQ_OBJECT + TQ_PROPERTY( int selectedColumn READ selectedColumn ) + TQ_PROPERTY( int selectedRow READ selectedRow ) + +public: + TQWellArray( TQWidget* parent=0, const char* name=0, bool popup = FALSE ); + + ~TQWellArray() {} + TQString cellContent( int row, int col ) const; + // ### Paul !!! virtual void setCellContent( int row, int col, const TQString &); + + int selectedColumn() const { return selCol; } + int selectedRow() const { return selRow; } + + virtual void setCurrent( int row, int col ); + virtual void setSelected( int row, int col ); + + TQSize sizeHint() const; + + virtual void setCellBrush( int row, int col, const TQBrush & ); + TQBrush cellBrush( int row, int col ); + +signals: + void selected( int row, int col ); + +protected: + void dimensionChange( int oldRows, int oldCols ); + + virtual void paintCell( TQPainter *, int row, int col ); + virtual void paintCellContents( TQPainter *, int row, int col, const TQRect& ); + + void mousePressEvent( TQMouseEvent* ); + void mouseReleaseEvent( TQMouseEvent* ); + void mouseMoveEvent( TQMouseEvent* ); + void keyPressEvent( TQKeyEvent* ); + void focusInEvent( TQFocusEvent* ); + void focusOutEvent( TQFocusEvent* ); + +private: + int curRow; + int curCol; + int selRow; + int selCol; + bool smallStyle; + TQWellArrayData *d; + +private: // Disabled copy constructor and operator= +#if defined(TQ_DISABLE_COPY) + TQWellArray( const TQWellArray & ); + TQWellArray& operator=( const TQWellArray & ); +#endif +}; + + + +// non-interface ... + + + +struct TQWellArrayData { + TQBrush *brush; +}; + +/*! + \internal + \class TQWellArray qwellarray_p.h + \brief The TQWellArray class provides a well array. + + + \ingroup advanced +*/ + +TQWellArray::TQWellArray( TQWidget *parent, const char * name, bool popup ) + : TQGridView( parent, name, + (popup ? (WStyle_Customize|WStyle_Tool|WStyle_NoBorder) : 0 ) ) +{ + d = 0; + setFocusPolicy( StrongFocus ); + setVScrollBarMode(AlwaysOff); + setHScrollBarMode(AlwaysOff); + viewport()->setBackgroundMode( PaletteBackground ); + setNumCols( 7 ); + setNumRows( 7 ); + setCellWidth( 24 ); + setCellHeight( 21 ); + smallStyle = popup; + + if ( popup ) { + setCellWidth( 18 ); + setCellHeight( 18 ); + setFrameStyle(TQFrame::StyledPanel | TQFrame::Raised); + setMargin( 1 ); + setLineWidth( 2 ); + } else { + setFrameStyle( TQFrame::NoFrame ); + } + curCol = 0; + curRow = 0; + selCol = -1; + selRow = -1; + + if ( smallStyle ) + setMouseTracking( TRUE ); +} + + +TQSize TQWellArray::sizeHint() const +{ + constPolish(); + TQSize s = gridSize().boundedTo( TQSize(640, 480 ) ); + return TQSize( s.width() + 2*frameWidth(), s.height() + 2*frameWidth() ); +} + + +void TQWellArray::paintCell( TQPainter* p, int row, int col ) +{ + int w = cellWidth(); // width of cell in pixels + int h = cellHeight(); // height of cell in pixels + int b = 1; + + if ( !smallStyle ) + b = 3; + + const TQColorGroup & g = colorGroup(); + p->setPen( TQPen( black, 0, SolidLine ) ); + if ( !smallStyle && row ==selRow && col == selCol && + style().styleHint(TQStyle::SH_GUIStyle) != MotifStyle) { + int n = 2; + p->drawRect( n, n, w-2*n, h-2*n ); + } + + style().drawPrimitive(TQStyle::PE_Panel, p, TQRect(b, b, w-2*b, h-2*b), g, + TQStyle::Style_Enabled | TQStyle::Style_Sunken); + + int t = 0; + if (style().styleHint(TQStyle::SH_GUIStyle) == MotifStyle) + t = ( row == selRow && col == selCol ) ? 2 : 0; + b += 2 + t; + + if ( (row == curRow) && (col == curCol) ) { + if ( smallStyle ) { + p->setPen ( white ); + p->drawRect( 1, 1, w-2, h-2 ); + p->setPen ( black ); + p->drawRect( 0, 0, w, h ); + p->drawRect( 2, 2, w-4, h-4 ); + b = 3; + } else if ( hasFocus() ) { + style().drawPrimitive(TQStyle::PE_FocusRect, p, TQRect(0, 0, w, h), g); + } + } + paintCellContents( p, row, col, TQRect(b, b, w - 2*b, h - 2*b) ); +} + +/*! + Reimplement this function to change the contents of the well array. + */ +void TQWellArray::paintCellContents( TQPainter *p, int row, int col, const TQRect &r ) +{ + + if ( d ) { + p->fillRect( r, d->brush[row*numCols()+col] ); + } else { + p->fillRect( r, white ); + p->setPen( black ); + p->drawLine( r.topLeft(), r.bottomRight() ); + p->drawLine( r.topRight(), r.bottomLeft() ); + } +} + + +/*\reimp +*/ +void TQWellArray::mousePressEvent( TQMouseEvent* e ) +{ + // The current cell marker is set to the cell the mouse is pressed + // in. + TQPoint pos = e->pos(); + setCurrent( rowAt( pos.y() ), columnAt( pos.x() ) ); +} + +/*\reimp +*/ +void TQWellArray::mouseReleaseEvent( TQMouseEvent* ) +{ + // The current cell marker is set to the cell the mouse is clicked + // in. + setSelected( curRow, curCol ); +} + + +/*\reimp +*/ +void TQWellArray::mouseMoveEvent( TQMouseEvent* e ) +{ + // The current cell marker is set to the cell the mouse is + // clicked in. + if ( smallStyle ) { + TQPoint pos = e->pos(); + setCurrent( rowAt( pos.y() ), columnAt( pos.x() ) ); + } +} + +/* + Sets the cell currently having the focus. This is not necessarily + the same as the currently selected cell. +*/ + +void TQWellArray::setCurrent( int row, int col ) +{ + + if ( (curRow == row) && (curCol == col) ) + return; + + if ( row < 0 || col < 0 ) + row = col = -1; + + int oldRow = curRow; + int oldCol = curCol; + + curRow = row; + curCol = col; + + updateCell( oldRow, oldCol ); + updateCell( curRow, curCol ); +} + + +/*! + Sets the currently selected cell to \a row, \a col. If \a row or \a + col are less than zero, the current cell is unselected. + + Does not set the position of the focus indicator. +*/ + +void TQWellArray::setSelected( int row, int col ) +{ + if ( (selRow == row) && (selCol == col) ) + return; + + int oldRow = selRow; + int oldCol = selCol; + + if ( row < 0 || col < 0 ) + row = col = -1; + + selCol = col; + selRow = row; + + updateCell( oldRow, oldCol ); + updateCell( selRow, selCol ); + if ( row >= 0 ) + emit selected( row, col ); + + if ( isVisible() && ::tqt_cast(parentWidget()) ) + parentWidget()->close(); +} + + + +/*!\reimp +*/ +void TQWellArray::focusInEvent( TQFocusEvent* ) +{ + updateCell( curRow, curCol ); +} + + +/*! + Sets the size of the well array to be \a rows cells by \a cols. + Resets any brush information set by setCellBrush(). + */ +void TQWellArray::dimensionChange( int, int ) +{ + if ( d ) { + if ( d->brush ) + delete[] d->brush; + delete d; + d = 0; + } +} + +void TQWellArray::setCellBrush( int row, int col, const TQBrush &b ) +{ + if ( !d ) { + d = new TQWellArrayData; + int i = numRows()*numCols(); + d->brush = new TQBrush[i]; + } + if ( row >= 0 && row < numRows() && col >= 0 && col < numCols() ) + d->brush[row*numCols()+col] = b; +#ifdef QT_CHECK_RANGE + else + tqWarning( "TQWellArray::setCellBrush( %d, %d ) out of range", row, col ); +#endif +} + + + +/*! + Returns the brush set for the cell at \a row, \a col. If no brush is set, + \c NoBrush is returned. +*/ + +TQBrush TQWellArray::cellBrush( int row, int col ) +{ + if ( d && row >= 0 && row < numRows() && col >= 0 && col < numCols() ) + return d->brush[row*numCols()+col]; + return NoBrush; +} + + + +/*!\reimp +*/ + +void TQWellArray::focusOutEvent( TQFocusEvent* ) +{ + updateCell( curRow, curCol ); +} + +/*\reimp +*/ +void TQWellArray::keyPressEvent( TQKeyEvent* e ) +{ + switch( e->key() ) { // Look at the key code + case Key_Left: // If 'left arrow'-key, + if( curCol > 0 ) // and cr't not in leftmost col + setCurrent( curRow, curCol - 1); // set cr't to next left column + break; + case Key_Right: // Correspondingly... + if( curCol < numCols()-1 ) + setCurrent( curRow, curCol + 1); + break; + case Key_Up: + if( curRow > 0 ) + setCurrent( curRow - 1, curCol); + else if ( smallStyle ) + focusNextPrevChild( FALSE ); + break; + case Key_Down: + if( curRow < numRows()-1 ) + setCurrent( curRow + 1, curCol); + else if ( smallStyle ) + focusNextPrevChild( TRUE ); + break; + case Key_Space: + case Key_Return: + case Key_Enter: + setSelected( curRow, curCol ); + break; + default: // If not an interesting key, + e->ignore(); // we don't accept the event + return; + } + +} + +//////////// TQWellArray END + +static bool initrgb = FALSE; +static TQRgb stdrgb[6*8]; +static TQRgb cusrgb[2*8]; +static bool customSet = FALSE; + + +static void initRGB() +{ + if ( initrgb ) + return; + initrgb = TRUE; + int i = 0; + for ( int g = 0; g < 4; g++ ) + for ( int r = 0; r < 4; r++ ) + for ( int b = 0; b < 3; b++ ) + stdrgb[i++] = tqRgb( r*255/3, g*255/3, b*255/2 ); + + for ( i = 0; i < 2*8; i++ ) + cusrgb[i] = tqRgb(0xff,0xff,0xff); +} + +/*! + Returns the number of custom colors supported by TQColorDialog. All + color dialogs share the same custom colors. +*/ +int TQColorDialog::customCount() +{ + return 2*8; +} + +/*! + Returns custom color number \a i as a TQRgb. +*/ +TQRgb TQColorDialog::customColor( int i ) +{ + initRGB(); + if ( i < 0 || i >= customCount() ) { +#ifdef QT_CHECK_RANGE + tqWarning( "TQColorDialog::customColor() index %d out of range", i ); +#endif + i = 0; + } + return cusrgb[i]; +} + +/*! + Sets custom color number \a i to the TQRgb value \a c. +*/ +void TQColorDialog::setCustomColor( int i, TQRgb c ) +{ + initRGB(); + if ( i < 0 || i >= customCount() ) { +#ifdef QT_CHECK_RANGE + tqWarning( "TQColorDialog::setCustomColor() index %d out of range", i ); +#endif + return; + } + customSet = TRUE; + cusrgb[i] = c; +} + +/*! + Sets standard color number \a i to the TQRgb value \a c. +*/ + +void TQColorDialog::setStandardColor( int i, TQRgb c ) +{ + initRGB(); + if ( i < 0 || i >= 6*8 ) { +#ifdef QT_CHECK_RANGE + tqWarning( "TQColorDialog::setStandardColor() index %d out of range", i ); +#endif + return; + } + stdrgb[i] = c; +} + +static inline void rgb2hsv( TQRgb rgb, int&h, int&s, int&v ) +{ + TQColor c; + c.setRgb( rgb ); + c.getHsv(h,s,v); +} + +class TQColorWell : public TQWellArray +{ +public: + TQColorWell( TQWidget *parent, int r, int c, TQRgb *vals ) + :TQWellArray( parent, "" ), values( vals ), mousePressed( FALSE ), oldCurrent( -1, -1 ) + { setNumRows(r), setNumCols(c); setSizePolicy( TQSizePolicy( TQSizePolicy::Minimum, TQSizePolicy::Minimum) ); } + +protected: + void paintCellContents( TQPainter *, int row, int col, const TQRect& ); + void mousePressEvent( TQMouseEvent *e ); + void mouseMoveEvent( TQMouseEvent *e ); + void mouseReleaseEvent( TQMouseEvent *e ); +#ifndef TQT_NO_DRAGANDDROP + void dragEnterEvent( TQDragEnterEvent *e ); + void dragLeaveEvent( TQDragLeaveEvent *e ); + void dragMoveEvent( TQDragMoveEvent *e ); + void dropEvent( TQDropEvent *e ); +#endif + +private: + TQRgb *values; + bool mousePressed; + TQPoint pressPos; + TQPoint oldCurrent; + +}; + +void TQColorWell::paintCellContents( TQPainter *p, int row, int col, const TQRect &r ) +{ + int i = row + col*numRows(); + p->fillRect( r, TQColor( values[i] ) ); +} + +void TQColorWell::mousePressEvent( TQMouseEvent *e ) +{ + oldCurrent = TQPoint( selectedRow(), selectedColumn() ); + TQWellArray::mousePressEvent( e ); + mousePressed = TRUE; + pressPos = e->pos(); +} + +void TQColorWell::mouseMoveEvent( TQMouseEvent *e ) +{ + TQWellArray::mouseMoveEvent( e ); +#ifndef TQT_NO_DRAGANDDROP + if ( !mousePressed ) + return; + if ( ( pressPos - e->pos() ).manhattanLength() > TQApplication::startDragDistance() ) { + setCurrent( oldCurrent.x(), oldCurrent.y() ); + int i = rowAt(pressPos.y()) + columnAt(pressPos.x()) * numRows(); + TQColor col( values[ i ] ); + TQColorDrag *drg = new TQColorDrag( col, this ); + TQPixmap pix( cellWidth(), cellHeight() ); + pix.fill( col ); + TQPainter p( &pix ); + p.drawRect( 0, 0, pix.width(), pix.height() ); + p.end(); + drg->setPixmap( pix ); + mousePressed = FALSE; + drg->dragCopy(); + } +#endif +} + +#ifndef TQT_NO_DRAGANDDROP +void TQColorWell::dragEnterEvent( TQDragEnterEvent *e ) +{ + setFocus(); + if ( TQColorDrag::canDecode( e ) ) + e->accept(); + else + e->ignore(); +} + +void TQColorWell::dragLeaveEvent( TQDragLeaveEvent * ) +{ + if ( hasFocus() ) + parentWidget()->setFocus(); +} + +void TQColorWell::dragMoveEvent( TQDragMoveEvent *e ) +{ + if ( TQColorDrag::canDecode( e ) ) { + setCurrent( rowAt( e->pos().y() ), columnAt( e->pos().x() ) ); + e->accept(); + } else + e->ignore(); +} + +void TQColorWell::dropEvent( TQDropEvent *e ) +{ + if ( TQColorDrag::canDecode( e ) ) { + int i = rowAt( e->pos().y() ) + columnAt( e->pos().x() ) * numRows(); + TQColor col; + TQColorDrag::decode( e, col ); + values[ i ] = col.rgb(); + repaintContents( FALSE ); + e->accept(); + } else { + e->ignore(); + } +} + +#endif // TQT_NO_DRAGANDDROP + +void TQColorWell::mouseReleaseEvent( TQMouseEvent *e ) +{ + if ( !mousePressed ) + return; + TQWellArray::mouseReleaseEvent( e ); + mousePressed = FALSE; +} + +class TQColorPicker : public TQFrame +{ + TQ_OBJECT +public: + TQColorPicker(TQWidget* parent=0, const char* name=0); + ~TQColorPicker(); + +public slots: + void setCol( int h, int s ); + +signals: + void newCol( int h, int s ); + +protected: + TQSize sizeHint() const; + void drawContents(TQPainter* p); + void mouseMoveEvent( TQMouseEvent * ); + void mousePressEvent( TQMouseEvent * ); + +private: + int hue; + int sat; + + TQPoint colPt(); + int huePt( const TQPoint &pt ); + int satPt( const TQPoint &pt ); + void setCol( const TQPoint &pt ); + + TQPixmap *pix; +}; + +static int pWidth = 200; +static int pHeight = 200; + +class TQColorLuminancePicker : public TQWidget +{ + TQ_OBJECT +public: + TQColorLuminancePicker(TQWidget* parent=0, const char* name=0); + ~TQColorLuminancePicker(); + +public slots: + void setCol( int h, int s, int v ); + void setCol( int h, int s ); + +signals: + void newHsv( int h, int s, int v ); + +protected: + void paintEvent( TQPaintEvent*); + void mouseMoveEvent( TQMouseEvent * ); + void mousePressEvent( TQMouseEvent * ); + +private: + enum { foff = 3, coff = 4 }; //frame and contents offset + int val; + int hue; + int sat; + + int y2val( int y ); + int val2y( int val ); + void setVal( int v ); + + TQPixmap *pix; +}; + + +int TQColorLuminancePicker::y2val( int y ) +{ + int d = height() - 2*coff - 1; + return 255 - (y - coff)*255/d; +} + +int TQColorLuminancePicker::val2y( int v ) +{ + int d = height() - 2*coff - 1; + return coff + (255-v)*d/255; +} + +TQColorLuminancePicker::TQColorLuminancePicker(TQWidget* parent, + const char* name) + :TQWidget( parent, name ) +{ + hue = 100; val = 100; sat = 100; + pix = 0; + // setBackgroundMode( NoBackground ); +} + +TQColorLuminancePicker::~TQColorLuminancePicker() +{ + delete pix; +} + +void TQColorLuminancePicker::mouseMoveEvent( TQMouseEvent *m ) +{ + setVal( y2val(m->y()) ); +} +void TQColorLuminancePicker::mousePressEvent( TQMouseEvent *m ) +{ + setVal( y2val(m->y()) ); +} + +void TQColorLuminancePicker::setVal( int v ) +{ + if ( val == v ) + return; + val = TQMAX( 0, TQMIN(v,255)); + delete pix; pix=0; + repaint( FALSE ); //### + emit newHsv( hue, sat, val ); +} + +//receives from a hue,sat chooser and relays. +void TQColorLuminancePicker::setCol( int h, int s ) +{ + setCol( h, s, val ); + emit newHsv( h, s, val ); +} + +void TQColorLuminancePicker::paintEvent( TQPaintEvent * ) +{ + int w = width() - 5; + + TQRect r( 0, foff, w, height() - 2*foff ); + int wi = r.width() - 2; + int hi = r.height() - 2; + if ( !pix || pix->height() != hi || pix->width() != wi ) { + delete pix; + TQImage img( wi, hi, 32 ); + int y; + for ( y = 0; y < hi; y++ ) { + TQColor c( hue, sat, y2val(y+coff), TQColor::Hsv ); + TQRgb r = c.rgb(); + int x; + for ( x = 0; x < wi; x++ ) + img.setPixel( x, y, r ); + } + pix = new TQPixmap; + pix->convertFromImage(img); + } + TQPainter p(this); + p.drawPixmap( 1, coff, *pix ); + const TQColorGroup &g = colorGroup(); + qDrawShadePanel( &p, r, g, TRUE ); + p.setPen( g.foreground() ); + p.setBrush( g.foreground() ); + TQPointArray a; + int y = val2y(val); + a.setPoints( 3, w, y, w+5, y+5, w+5, y-5 ); + erase( w, 0, 5, height() ); + p.drawPolygon( a ); +} + +void TQColorLuminancePicker::setCol( int h, int s , int v ) +{ + val = v; + hue = h; + sat = s; + delete pix; pix=0; + repaint( FALSE );//#### +} + +TQPoint TQColorPicker::colPt() +{ return TQPoint( (360-hue)*(pWidth-1)/360, (255-sat)*(pHeight-1)/255 ); } +int TQColorPicker::huePt( const TQPoint &pt ) +{ return 360 - pt.x()*360/(pWidth-1); } +int TQColorPicker::satPt( const TQPoint &pt ) +{ return 255 - pt.y()*255/(pHeight-1) ; } +void TQColorPicker::setCol( const TQPoint &pt ) +{ setCol( huePt(pt), satPt(pt) ); } + +TQColorPicker::TQColorPicker(TQWidget* parent, const char* name ) + : TQFrame( parent, name ) +{ + hue = 0; sat = 0; + setCol( 150, 255 ); + + TQImage img( pWidth, pHeight, 32 ); + int x,y; + for ( y = 0; y < pHeight; y++ ) + for ( x = 0; x < pWidth; x++ ) { + TQPoint p( x, y ); + img.setPixel( x, y, TQColor(huePt(p), satPt(p), + 200, TQColor::Hsv).rgb() ); + } + pix = new TQPixmap; + pix->convertFromImage(img); + setBackgroundMode( NoBackground ); + setSizePolicy( TQSizePolicy( TQSizePolicy::Fixed, TQSizePolicy::Fixed ) ); +} + +TQColorPicker::~TQColorPicker() +{ + delete pix; +} + +TQSize TQColorPicker::sizeHint() const +{ + return TQSize( pWidth + 2*frameWidth(), pHeight + 2*frameWidth() ); +} + +void TQColorPicker::setCol( int h, int s ) +{ + int nhue = TQMIN( TQMAX(0,h), 360 ); + int nsat = TQMIN( TQMAX(0,s), 255); + if ( nhue == hue && nsat == sat ) + return; + TQRect r( colPt(), TQSize(20,20) ); + hue = nhue; sat = nsat; + r = r.unite( TQRect( colPt(), TQSize(20,20) ) ); + r.moveBy( contentsRect().x()-9, contentsRect().y()-9 ); + // update( r ); + repaint( r, FALSE ); +} + +void TQColorPicker::mouseMoveEvent( TQMouseEvent *m ) +{ + TQPoint p = m->pos() - contentsRect().topLeft(); + setCol( p ); + emit newCol( hue, sat ); +} + +void TQColorPicker::mousePressEvent( TQMouseEvent *m ) +{ + TQPoint p = m->pos() - contentsRect().topLeft(); + setCol( p ); + emit newCol( hue, sat ); +} + +void TQColorPicker::drawContents(TQPainter* p) +{ + TQRect r = contentsRect(); + + p->drawPixmap( r.topLeft(), *pix ); + TQPoint pt = colPt() + r.topLeft(); + p->setPen( TQPen(black) ); + + p->fillRect( pt.x()-9, pt.y(), 20, 2, black ); + p->fillRect( pt.x(), pt.y()-9, 2, 20, black ); + +} + +class TQColorShowLabel; + + + +class TQColIntValidator: public TQIntValidator +{ +public: + TQColIntValidator( int bottom, int top, + TQWidget * parent, const char *name = 0 ) + :TQIntValidator( bottom, top, parent, name ) {} + + TQValidator::State validate( TQString &, int & ) const; +}; + +TQValidator::State TQColIntValidator::validate( TQString &s, int &pos ) const +{ + State state = TQIntValidator::validate(s,pos); + if ( state == Valid ) { + long int val = s.toLong(); + // This is not a general solution, assumes that top() > 0 and + // bottom >= 0 + if ( val < 0 ) { + s = "0"; + pos = 1; + } else if ( val > top() ) { + s.setNum( top() ); + pos = s.length(); + } + } + return state; +} + + + +class TQColNumLineEdit : public TQLineEdit +{ +public: + TQColNumLineEdit( TQWidget *parent, const char* name=0 ) + : TQLineEdit( parent, name ) { setMaxLength( 3 );} + TQSize sizeHint() const { + return TQSize( fontMetrics().width( "999" ) + 2 * ( margin() + frameWidth() ), + TQLineEdit::sizeHint().height() ); } + void setNum( int i ) { + TQString s; + s.setNum(i); + bool block = signalsBlocked(); + blockSignals(TRUE); + setText( s ); + blockSignals(block); + } + int val() const { return text().toInt(); } +}; + + +class TQColorShower : public TQWidget +{ + TQ_OBJECT +public: + TQColorShower( TQWidget *parent, const char *name=0 ); + + //things that don't emit signals + void setHsv( int h, int s, int v ); + + int currentAlpha() const { return alphaEd->val(); } + void setCurrentAlpha( int a ) { alphaEd->setNum( a ); } + void showAlpha( bool b ); + + + TQRgb currentColor() const { return curCol; } + +public slots: + void setRgb( TQRgb rgb ); + +signals: + void newCol( TQRgb rgb ); +private slots: + void rgbEd(); + void hsvEd(); +private: + void showCurrentColor(); + int hue, sat, val; + TQRgb curCol; + TQColNumLineEdit *hEd; + TQColNumLineEdit *sEd; + TQColNumLineEdit *vEd; + TQColNumLineEdit *rEd; + TQColNumLineEdit *gEd; + TQColNumLineEdit *bEd; + TQColNumLineEdit *alphaEd; + TQLabel *alphaLab; + TQColorShowLabel *lab; + bool rgbOriginal; +}; + +class TQColorShowLabel : public TQFrame +{ + TQ_OBJECT + +public: + TQColorShowLabel( TQWidget *parent ) : TQFrame( parent, "qt_colorshow_lbl" ) { + setFrameStyle( TQFrame::Panel|TQFrame::Sunken ); + setBackgroundMode( PaletteBackground ); + setAcceptDrops( TRUE ); + mousePressed = FALSE; + } + void setColor( TQColor c ) { col = c; } + +signals: + void colorDropped( TQRgb ); + +protected: + void drawContents( TQPainter *p ); + void mousePressEvent( TQMouseEvent *e ); + void mouseMoveEvent( TQMouseEvent *e ); + void mouseReleaseEvent( TQMouseEvent *e ); +#ifndef TQT_NO_DRAGANDDROP + void dragEnterEvent( TQDragEnterEvent *e ); + void dragLeaveEvent( TQDragLeaveEvent *e ); + void dropEvent( TQDropEvent *e ); +#endif + +private: + TQColor col; + bool mousePressed; + TQPoint pressPos; + +}; + +void TQColorShowLabel::drawContents( TQPainter *p ) +{ + p->fillRect( contentsRect(), col ); +} + +void TQColorShower::showAlpha( bool b ) +{ + if ( b ) { + alphaLab->show(); + alphaEd->show(); + } else { + alphaLab->hide(); + alphaEd->hide(); + } +} + +void TQColorShowLabel::mousePressEvent( TQMouseEvent *e ) +{ + mousePressed = TRUE; + pressPos = e->pos(); +} + +void TQColorShowLabel::mouseMoveEvent( TQMouseEvent *e ) +{ +#ifndef TQT_NO_DRAGANDDROP + if ( !mousePressed ) + return; + if ( ( pressPos - e->pos() ).manhattanLength() > TQApplication::startDragDistance() ) { + TQColorDrag *drg = new TQColorDrag( col, this ); + TQPixmap pix( 30, 20 ); + pix.fill( col ); + TQPainter p( &pix ); + p.drawRect( 0, 0, pix.width(), pix.height() ); + p.end(); + drg->setPixmap( pix ); + mousePressed = FALSE; + drg->dragCopy(); + } +#endif +} + +#ifndef TQT_NO_DRAGANDDROP +void TQColorShowLabel::dragEnterEvent( TQDragEnterEvent *e ) +{ + if ( TQColorDrag::canDecode( e ) ) + e->accept(); + else + e->ignore(); +} + +void TQColorShowLabel::dragLeaveEvent( TQDragLeaveEvent * ) +{ +} + +void TQColorShowLabel::dropEvent( TQDropEvent *e ) +{ + if ( TQColorDrag::canDecode( e ) ) { + TQColorDrag::decode( e, col ); + repaint( FALSE ); + emit colorDropped( col.rgb() ); + e->accept(); + } else { + e->ignore(); + } +} +#endif // TQT_NO_DRAGANDDROP + +void TQColorShowLabel::mouseReleaseEvent( TQMouseEvent * ) +{ + if ( !mousePressed ) + return; + mousePressed = FALSE; +} + +TQColorShower::TQColorShower( TQWidget *parent, const char *name ) + :TQWidget( parent, name) +{ + curCol = tqRgb( -1, -1, -1 ); + TQColIntValidator *val256 = new TQColIntValidator( 0, 255, this ); + TQColIntValidator *val360 = new TQColIntValidator( 0, 360, this ); + + TQGridLayout *gl = new TQGridLayout( this, 1, 1, 6 ); + lab = new TQColorShowLabel( this ); + lab->setMinimumWidth( 60 ); //### + gl->addMultiCellWidget(lab, 0,-1,0,0); + connect( lab, TQ_SIGNAL( colorDropped(TQRgb) ), + this, TQ_SIGNAL( newCol(TQRgb) ) ); + connect( lab, TQ_SIGNAL( colorDropped(TQRgb) ), + this, TQ_SLOT( setRgb(TQRgb) ) ); + + hEd = new TQColNumLineEdit( this, "qt_hue_edit" ); + hEd->setValidator( val360 ); + TQLabel *l = new TQLabel( hEd, TQColorDialog::tr("Hu&e:"), this, "qt_hue_lbl" ); + l->setAlignment( AlignRight|AlignVCenter ); + gl->addWidget( l, 0, 1 ); + gl->addWidget( hEd, 0, 2 ); + + sEd = new TQColNumLineEdit( this, "qt_sat_edit" ); + sEd->setValidator( val256 ); + l = new TQLabel( sEd, TQColorDialog::tr("&Sat:"), this, "qt_sat_lbl" ); + l->setAlignment( AlignRight|AlignVCenter ); + gl->addWidget( l, 1, 1 ); + gl->addWidget( sEd, 1, 2 ); + + vEd = new TQColNumLineEdit( this, "qt_val_edit" ); + vEd->setValidator( val256 ); + l = new TQLabel( vEd, TQColorDialog::tr("&Val:"), this, "qt_val_lbl" ); + l->setAlignment( AlignRight|AlignVCenter ); + gl->addWidget( l, 2, 1 ); + gl->addWidget( vEd, 2, 2 ); + + rEd = new TQColNumLineEdit( this, "qt_red_edit" ); + rEd->setValidator( val256 ); + l = new TQLabel( rEd, TQColorDialog::tr("&Red:"), this, "qt_red_lbl" ); + l->setAlignment( AlignRight|AlignVCenter ); + gl->addWidget( l, 0, 3 ); + gl->addWidget( rEd, 0, 4 ); + + gEd = new TQColNumLineEdit( this, "qt_grn_edit" ); + gEd->setValidator( val256 ); + l = new TQLabel( gEd, TQColorDialog::tr("&Green:"), this, "qt_grn_lbl" ); + l->setAlignment( AlignRight|AlignVCenter ); + gl->addWidget( l, 1, 3 ); + gl->addWidget( gEd, 1, 4 ); + + bEd = new TQColNumLineEdit( this, "qt_blue_edit" ); + bEd->setValidator( val256 ); + l = new TQLabel( bEd, TQColorDialog::tr("Bl&ue:"), this, "qt_blue_lbl" ); + l->setAlignment( AlignRight|AlignVCenter ); + gl->addWidget( l, 2, 3 ); + gl->addWidget( bEd, 2, 4 ); + + alphaEd = new TQColNumLineEdit( this, "qt_aplha_edit" ); + alphaEd->setValidator( val256 ); + alphaLab = new TQLabel( alphaEd, TQColorDialog::tr("A&lpha channel:"), this, "qt_alpha_lbl" ); + alphaLab->setAlignment( AlignRight|AlignVCenter ); + gl->addMultiCellWidget( alphaLab, 3, 3, 1, 3 ); + gl->addWidget( alphaEd, 3, 4 ); + alphaEd->hide(); + alphaLab->hide(); + + connect( hEd, TQ_SIGNAL(textChanged(const TQString&)), this, TQ_SLOT(hsvEd()) ); + connect( sEd, TQ_SIGNAL(textChanged(const TQString&)), this, TQ_SLOT(hsvEd()) ); + connect( vEd, TQ_SIGNAL(textChanged(const TQString&)), this, TQ_SLOT(hsvEd()) ); + + connect( rEd, TQ_SIGNAL(textChanged(const TQString&)), this, TQ_SLOT(rgbEd()) ); + connect( gEd, TQ_SIGNAL(textChanged(const TQString&)), this, TQ_SLOT(rgbEd()) ); + connect( bEd, TQ_SIGNAL(textChanged(const TQString&)), this, TQ_SLOT(rgbEd()) ); + connect( alphaEd, TQ_SIGNAL(textChanged(const TQString&)), this, TQ_SLOT(rgbEd()) ); +} + +void TQColorShower::showCurrentColor() +{ + lab->setColor( currentColor() ); + lab->repaint(FALSE); //### +} + +void TQColorShower::rgbEd() +{ + rgbOriginal = TRUE; + if ( alphaEd->isVisible() ) + curCol = tqRgba( rEd->val(), gEd->val(), bEd->val(), currentAlpha() ); + else + curCol = tqRgb( rEd->val(), gEd->val(), bEd->val() ); + + rgb2hsv(currentColor(), hue, sat, val ); + + hEd->setNum( hue ); + sEd->setNum( sat ); + vEd->setNum( val ); + + showCurrentColor(); + emit newCol( currentColor() ); +} + +void TQColorShower::hsvEd() +{ + rgbOriginal = FALSE; + hue = hEd->val(); + sat = sEd->val(); + val = vEd->val(); + + curCol = TQColor( hue, sat, val, TQColor::Hsv ).rgb(); + + rEd->setNum( tqRed(currentColor()) ); + gEd->setNum( tqGreen(currentColor()) ); + bEd->setNum( tqBlue(currentColor()) ); + + showCurrentColor(); + emit newCol( currentColor() ); +} + +void TQColorShower::setRgb( TQRgb rgb ) +{ + rgbOriginal = TRUE; + curCol = rgb; + + rgb2hsv( currentColor(), hue, sat, val ); + + hEd->setNum( hue ); + sEd->setNum( sat ); + vEd->setNum( val ); + + rEd->setNum( tqRed(currentColor()) ); + gEd->setNum( tqGreen(currentColor()) ); + bEd->setNum( tqBlue(currentColor()) ); + + showCurrentColor(); +} + +void TQColorShower::setHsv( int h, int s, int v ) +{ + rgbOriginal = FALSE; + hue = h; val = v; sat = s; //Range check### + curCol = TQColor( hue, sat, val, TQColor::Hsv ).rgb(); + + hEd->setNum( hue ); + sEd->setNum( sat ); + vEd->setNum( val ); + + rEd->setNum( tqRed(currentColor()) ); + gEd->setNum( tqGreen(currentColor()) ); + bEd->setNum( tqBlue(currentColor()) ); + + showCurrentColor(); +} + +class TQColorDialogPrivate : public TQObject +{ +TQ_OBJECT +public: + TQColorDialogPrivate( TQColorDialog *p ); + TQRgb currentColor() const { return cs->currentColor(); } + void setCurrentColor( TQRgb rgb ); + + int currentAlpha() const { return cs->currentAlpha(); } + void setCurrentAlpha( int a ) { cs->setCurrentAlpha( a ); } + void showAlpha( bool b ) { cs->showAlpha( b ); } + +public slots: + void addCustom(); + + void newHsv( int h, int s, int v ); + void newColorTypedIn( TQRgb rgb ); + void newCustom( int, int ); + void newStandard( int, int ); +public: + TQWellArray *custom; + TQWellArray *standard; + + TQColorPicker *cp; + TQColorLuminancePicker *lp; + TQColorShower *cs; + int nextCust; + bool compact; +}; + +//sets all widgets to display h,s,v +void TQColorDialogPrivate::newHsv( int h, int s, int v ) +{ + cs->setHsv( h, s, v ); + cp->setCol( h, s ); + lp->setCol( h, s, v ); +} + +//sets all widgets to display rgb +void TQColorDialogPrivate::setCurrentColor( TQRgb rgb ) +{ + cs->setRgb( rgb ); + newColorTypedIn( rgb ); +} + +//sets all widgets exept cs to display rgb +void TQColorDialogPrivate::newColorTypedIn( TQRgb rgb ) +{ + int h, s, v; + rgb2hsv(rgb, h, s, v ); + cp->setCol( h, s ); + lp->setCol( h, s, v); +} + +void TQColorDialogPrivate::newCustom( int r, int c ) +{ + int i = r+2*c; + setCurrentColor( cusrgb[i] ); + nextCust = i; + if (standard) + standard->setSelected(-1,-1); +} + +void TQColorDialogPrivate::newStandard( int r, int c ) +{ + setCurrentColor( stdrgb[r+c*6] ); + if (custom) + custom->setSelected(-1,-1); +} + +TQColorDialogPrivate::TQColorDialogPrivate( TQColorDialog *dialog ) : + TQObject(dialog) +{ + compact = FALSE; + // small displays (e.g. PDAs cannot fit the full color dialog, + // so just use the color picker. + if ( tqApp->desktop()->width() < 480 || tqApp->desktop()->height() < 350 ) + compact = TRUE; + + nextCust = 0; + const int lumSpace = 3; + int border = 12; + if ( compact ) + border = 6; + TQHBoxLayout *topLay = new TQHBoxLayout( dialog, border, 6 ); + TQVBoxLayout *leftLay = 0; + + if ( !compact ) + leftLay = new TQVBoxLayout( topLay ); + + initRGB(); + + if ( !compact ) { + standard = new TQColorWell( dialog, 6, 8, stdrgb ); + standard->setCellWidth( 28 ); + standard->setCellHeight( 24 ); + TQLabel * lab = new TQLabel( standard, + TQColorDialog::tr( "&Basic colors"), dialog, "qt_basiccolors_lbl" ); + connect( standard, TQ_SIGNAL(selected(int,int)), TQ_SLOT(newStandard(int,int))); + leftLay->addWidget( lab ); + leftLay->addWidget( standard ); + + + leftLay->addStretch(); + + custom = new TQColorWell( dialog, 2, 8, cusrgb ); + custom->setCellWidth( 28 ); + custom->setCellHeight( 24 ); + custom->setAcceptDrops( TRUE ); + + connect( custom, TQ_SIGNAL(selected(int,int)), TQ_SLOT(newCustom(int,int))); + lab = new TQLabel( custom, TQColorDialog::tr( "&Custom colors") , dialog, "qt_custcolors_lbl" ); + leftLay->addWidget( lab ); + leftLay->addWidget( custom ); + + TQPushButton *custbut = + new TQPushButton( TQColorDialog::tr("&Define Custom Colors >>"), + dialog, "qt_def_custcolors_lbl" ); + custbut->setEnabled( FALSE ); + leftLay->addWidget( custbut ); + } else { + // better color picker size for small displays + pWidth = 150; + pHeight = 100; + + custom = 0; + standard = 0; + } + + TQVBoxLayout *rightLay = new TQVBoxLayout( topLay ); + + TQHBoxLayout *pickLay = new TQHBoxLayout( rightLay ); + + + TQVBoxLayout *cLay = new TQVBoxLayout( pickLay ); + cp = new TQColorPicker( dialog, "qt_colorpicker" ); + cp->setFrameStyle( TQFrame::Panel + TQFrame::Sunken ); + cLay->addSpacing( lumSpace ); + cLay->addWidget( cp ); + cLay->addSpacing( lumSpace ); + + lp = new TQColorLuminancePicker( dialog, "qt_luminance_picker" ); + lp->setFixedWidth( 20 ); //### + pickLay->addWidget( lp ); + + connect( cp, TQ_SIGNAL(newCol(int,int)), lp, TQ_SLOT(setCol(int,int)) ); + connect( lp, TQ_SIGNAL(newHsv(int,int,int)), this, TQ_SLOT(newHsv(int,int,int)) ); + + rightLay->addStretch(); + + cs = new TQColorShower( dialog, "qt_colorshower" ); + connect( cs, TQ_SIGNAL(newCol(TQRgb)), this, TQ_SLOT(newColorTypedIn(TQRgb))); + rightLay->addWidget( cs ); + + TQHBoxLayout *buttons; + if ( compact ) + buttons = new TQHBoxLayout( rightLay ); + else + buttons = new TQHBoxLayout( leftLay ); + + TQPushButton *ok, *cancel; + ok = new TQPushButton( TQColorDialog::tr("OK"), dialog, "qt_ok_btn" ); + connect( ok, TQ_SIGNAL(clicked()), dialog, TQ_SLOT(accept()) ); + ok->setDefault(TRUE); + cancel = new TQPushButton( TQColorDialog::tr("Cancel"), dialog, "qt_cancel_btn" ); + connect( cancel, TQ_SIGNAL(clicked()), dialog, TQ_SLOT(reject()) ); + buttons->addWidget( ok ); + buttons->addWidget( cancel ); + buttons->addStretch(); + + if ( !compact ) { + TQPushButton *addCusBt = new TQPushButton( + TQColorDialog::tr("&Add to Custom Colors"), + dialog, "qt_add_btn" ); + rightLay->addWidget( addCusBt ); + connect( addCusBt, TQ_SIGNAL(clicked()), this, TQ_SLOT(addCustom()) ); + } +} + +void TQColorDialogPrivate::addCustom() +{ + cusrgb[nextCust] = cs->currentColor(); + if (custom) + custom->repaintContents( FALSE ); + nextCust = (nextCust+1) % 16; +} + + +/*! + \class TQColorDialog tqcolordialog.h + \brief The TQColorDialog class provides a dialog widget for specifying colors. + \mainclass + \ingroup dialogs + \ingroup graphics + + The color dialog's function is to allow users to choose colors. + For example, you might use this in a drawing program to allow the + user to set the brush color. + + The static functions provide modal color dialogs. + \omit + If you require a modeless dialog, use the TQColorDialog constructor. + \endomit + + The static getColor() function shows the dialog and allows the + user to specify a color. The getRgba() function does the same but + also allows the user to specify a color with an alpha channel + (transparency) value. + + The user can store customCount() different custom colors. The + custom colors are shared by all color dialogs, and remembered + during the execution of the program. Use setCustomColor() to set + the custom colors, and use customColor() to get them. + + \img tqcolordlg-w.png +*/ + +/*! + Constructs a default color dialog with parent \a parent and called + \a name. If \a modal is TRUE the dialog will be modal. Use + setColor() to set an initial value. + + \sa getColor() +*/ + +TQColorDialog::TQColorDialog(TQWidget* parent, const char* name, bool modal) : + TQDialog(parent, name, modal, ( WType_Dialog | WStyle_Customize | WStyle_Title | + WStyle_DialogBorder | WStyle_SysMenu ) ) +{ + setSizeGripEnabled( FALSE ); + d = new TQColorDialogPrivate( this ); + +#ifndef TQT_NO_SETTINGS + if ( !customSet ) { + TQSettings settings; + settings.insertSearchPath( TQSettings::Windows, "/Trolltech" ); + for ( int i = 0; i < 2*8; ++i ) { + bool ok = FALSE; + TQRgb rgb = (TQRgb)settings.readNumEntry( "/TQt/customColors/" + TQString::number( i ), 0, &ok ); + if ( ok ) + cusrgb[i] = rgb; + } + } +#endif +} + +/*! + Pops up a modal color dialog, lets the user choose a color, and + returns that color. The color is initially set to \a initial. The + dialog is a child of \a parent and is called \a name. It returns + an invalid (see TQColor::isValid()) color if the user cancels the + dialog. All colors allocated by the dialog will be deallocated + before this function returns. +*/ + +TQColor TQColorDialog::getColor( const TQColor& initial, TQWidget *parent, + const char *name ) +{ +#if defined(TQ_WS_X11) + if( TQTDEIntegration::enabled()) + return TQTDEIntegration::getColor( initial, parent, name ); +#elif defined(TQ_WS_MAC) + return macGetColor(initial, parent, name); +#endif + + int allocContext = TQColor::enterAllocContext(); + TQColorDialog *dlg = new TQColorDialog( parent, name, TRUE ); //modal +#ifndef TQT_NO_WIDGET_TOPEXTRA + dlg->setCaption( TQColorDialog::tr( "Select color" ) ); +#endif + dlg->setColor( initial ); + dlg->selectColor( initial ); + int resultCode = dlg->exec(); + TQColor::leaveAllocContext(); + TQColor result; + if ( resultCode == TQDialog::Accepted ) + result = dlg->color(); + TQColor::destroyAllocContext(allocContext); + delete dlg; + return result; +} + + +/*! + Pops up a modal color dialog to allow the user to choose a color + and an alpha channel (transparency) value. The color+alpha is + initially set to \a initial. The dialog is a child of \a parent + and called \a name. + + If \a ok is non-null, \e *\a ok is set to TRUE if the user clicked + OK, and to FALSE if the user clicked Cancel. + + If the user clicks Cancel, the \a initial value is returned. +*/ + +TQRgb TQColorDialog::getRgba( TQRgb initial, bool *ok, + TQWidget *parent, const char* name ) +{ +#if defined(TQ_WS_MAC) + if( TQTDEIntegration::enabled()) { + TQColor color = TQTDEIntegration::getColor( TQColor( initial ), parent, name ); + if( ok ) + *ok = color.isValid(); + return color.rgba(); + } +#elif defined(TQ_WS_MAC) + return macGetRgba(initial, ok, parent, name); +#endif + + int allocContext = TQColor::enterAllocContext(); + TQColorDialog *dlg = new TQColorDialog( parent, name, TRUE ); //modal + + TQ_CHECK_PTR( dlg ); +#ifndef TQT_NO_WIDGET_TOPEXTRA + dlg->setCaption( TQColorDialog::tr( "Select color" ) ); +#endif + dlg->setColor( initial ); + dlg->selectColor( initial ); + dlg->setSelectedAlpha( tqAlpha(initial) ); + int resultCode = dlg->exec(); + TQColor::leaveAllocContext(); + TQRgb result = initial; + if ( resultCode == TQDialog::Accepted ) { + TQRgb c = dlg->color().rgb(); + int alpha = dlg->selectedAlpha(); + result = tqRgba( tqRed(c), tqGreen(c), tqBlue(c), alpha ); + } + if ( ok ) + *ok = resultCode == TQDialog::Accepted; + + TQColor::destroyAllocContext(allocContext); + delete dlg; + return result; +} + + + + + +/*! + Returns the color currently selected in the dialog. + + \sa setColor() +*/ + +TQColor TQColorDialog::color() const +{ + return TQColor(d->currentColor()); +} + + +/*! + Destroys the dialog and frees any memory it allocated. +*/ + +TQColorDialog::~TQColorDialog() +{ +#ifndef TQT_NO_SETTINGS + if ( !customSet ) { + TQSettings settings; + settings.insertSearchPath( TQSettings::Windows, "/Trolltech" ); + for ( int i = 0; i < 2*8; ++i ) + settings.writeEntry( "/TQt/customColors/" + TQString::number( i ), (int)cusrgb[i] ); + } +#endif +} + + +/*! + Sets the color shown in the dialog to \a c. + + \sa color() +*/ + +void TQColorDialog::setColor( const TQColor& c ) +{ + d->setCurrentColor( c.rgb() ); +} + + + + +/*! + Sets the initial alpha channel value to \a a, and shows the alpha + channel entry box. +*/ + +void TQColorDialog::setSelectedAlpha( int a ) +{ + d->showAlpha( TRUE ); + d->setCurrentAlpha( a ); +} + + +/*! + Returns the value selected for the alpha channel. +*/ + +int TQColorDialog::selectedAlpha() const +{ + return d->currentAlpha(); +} + +/*! + Sets focus to the corresponding button, if any. +*/ +bool TQColorDialog::selectColor( const TQColor& col ) +{ + TQRgb color = col.rgb(); + int i = 0, j = 0; + // Check standard colors + if (d->standard) { + for ( i = 0; i < 6; i++ ) { + for ( j = 0; j < 8; j++ ) { + if ( color == stdrgb[i + j*6] ) { + d->newStandard( i, j ); + d->standard->setCurrent( i, j ); + d->standard->setSelected( i, j ); + d->standard->setFocus(); + return TRUE; + } + } + } + } + // Check custom colors + if (d->custom) { + for ( i = 0; i < 2; i++ ) { + for ( j = 0; j < 8; j++ ) { + if ( color == cusrgb[i + j*2] ) { + d->newCustom( i, j ); + d->custom->setCurrent( i, j ); + d->custom->setSelected( i, j ); + d->custom->setFocus(); + return TRUE; + } + } + } + } + return FALSE; +} + +#include "tqcolordialog.moc" + +#endif diff --git a/src/dialogs/tqcolordialog.h b/src/dialogs/tqcolordialog.h new file mode 100644 index 000000000..0941a020d --- /dev/null +++ b/src/dialogs/tqcolordialog.h @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Definition of TQColorDialog class +** +** Created : 990222 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the dialogs module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef TQCOLORDIALOG_H +#define TQCOLORDIALOG_H + +#ifndef QT_H +#include "ntqdialog.h" +#endif // QT_H + +#ifndef TQT_NO_COLORDIALOG + +class TQColorDialogPrivate; + +class TQ_EXPORT TQColorDialog : public TQDialog +{ + TQ_OBJECT + +public: + static TQColor getColor( const TQColor& init = white, TQWidget* parent=0, const char* name=0 ); + static TQRgb getRgba( TQRgb, bool* ok = 0, + TQWidget* parent=0, const char* name=0 ); + + static int customCount(); + static TQRgb customColor( int ); + static void setCustomColor( int, TQRgb ); + static void setStandardColor( int, TQRgb ); + +private: + ~TQColorDialog(); + TQColorDialog( TQWidget* parent=0, const char* name=0, bool modal=FALSE ); + + void setColor( const TQColor& ); + TQColor color() const; + + bool selectColor( const TQColor& ); + + void setSelectedAlpha( int ); + int selectedAlpha() const; + + void showCustom( bool=TRUE ); + +private: // Disabled copy constructor and operator= + TQColorDialogPrivate *d; + friend class TQColorDialogPrivate; + friend class TQColorShower; + +#if defined(TQ_DISABLE_COPY) + TQColorDialog( const TQColorDialog & ); + TQColorDialog& operator=( const TQColorDialog & ); +#endif +}; + +#endif + +#endif //TQCOLORDIALOG_H diff --git a/src/dialogs/tqfiledialog.cpp b/src/dialogs/tqfiledialog.cpp index 711ce2a73..194d7478a 100644 --- a/src/dialogs/tqfiledialog.cpp +++ b/src/dialogs/tqfiledialog.cpp @@ -79,7 +79,7 @@ #include "tqmime.h" #include "tqnetworkprotocol.h" #include "tqobjectlist.h" -#include "ntqpainter.h" +#include "tqpainter.h" #include "tqpopupmenu.h" #include "ntqprogressbar.h" #include "tqptrvector.h" diff --git a/src/dialogs/tqfontdialog.cpp b/src/dialogs/tqfontdialog.cpp new file mode 100644 index 000000000..8e7999a2b --- /dev/null +++ b/src/dialogs/tqfontdialog.cpp @@ -0,0 +1,841 @@ +/**************************************************************************** +** +** Implementation of TQFontDialog +** +** Created : 970605 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the dialogs module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#include "ntqwindowdefs.h" + +#ifndef TQT_NO_FONTDIALOG + +#include "tqfontdialog.h" + +#include "ntqlineedit.h" +#include "ntqlistbox.h" +#include "ntqpushbutton.h" +#include "ntqcheckbox.h" +#include "ntqcombobox.h" +#include "ntqlayout.h" +#include "ntqvgroupbox.h" +#include "ntqhgroupbox.h" +#include "ntqlabel.h" +#include "ntqapplication.h" +#include "tqfontdatabase.h" +#include "tqstyle.h" +#include +#include + +#ifdef TQ_WS_X11 +#include "private/tqttdeintegration_x11_p.h" +#endif + +/*! + \class TQFontDialog tqfontdialog.h + \ingroup dialogs + \mainclass + \brief The TQFontDialog class provides a dialog widget for selecting a font. + + The usual way to use this class is to call one of the static convenience + functions, e.g. getFont(). + + Examples: + + \code + bool ok; + TQFont font = TQFontDialog::getFont( + &ok, TQFont( "Helvetica [Cronyx]", 10 ), this ); + if ( ok ) { + // font is set to the font the user selected + } else { + // the user canceled the dialog; font is set to the initial + // value, in this case Helvetica [Cronyx], 10 + } + \endcode + + The dialog can also be used to set a widget's font directly: + \code + myWidget.setFont( TQFontDialog::getFont( 0, myWidget.font() ) ); + \endcode + If the user clicks OK the font they chose will be used for myWidget, + and if they click Cancel the original font is used. + + \sa TQFont TQFontInfo TQFontMetrics + + +*/ + +class TQFontDialogPrivate +{ +public: + TQFontDialogPrivate() : script( TQFontPrivate::defaultScript ) {}; + TQLabel * familyAccel; + TQLineEdit * familyEdit; + TQListBox * familyList; + + TQLabel * styleAccel; + TQLineEdit * styleEdit; + TQListBox * styleList; + + TQLabel * sizeAccel; + TQLineEdit * sizeEdit; + TQListBox * sizeList; + + TQVGroupBox * effects; + TQCheckBox * strikeout; + TQCheckBox * underline; + TQComboBox * color; + + TQHGroupBox * sample; + TQLineEdit * sampleEdit; + + TQLabel * scriptAccel; + TQComboBox * scriptCombo; + + TQPushButton * ok; + TQPushButton * cancel; + + TQBoxLayout * buttonLayout; + TQBoxLayout * effectsLayout; + TQBoxLayout * sampleLayout; + TQBoxLayout * sampleEditLayout; + + TQFontDatabase fdb; + + TQString family; + TQFont::Script script; + TQString style; + int size; + + bool smoothScalable; +}; + + +/*! + \internal + Constructs a standard font dialog. + + Use setFont() to set the initial font attributes. + + The \a parent, \a name, \a modal and \a f parameters are passed to + the TQDialog constructor. + + \sa getFont() +*/ + +TQFontDialog::TQFontDialog( TQWidget *parent, const char *name, + bool modal, WFlags f ) + : TQDialog( parent, name, modal, f ) +{ + setSizeGripEnabled( TRUE ); + d = new TQFontDialogPrivate; + // grid + d->familyEdit = new TQLineEdit( this, "font family I" ); + d->familyEdit->setReadOnly( TRUE ); + d->familyList = new TQListBox( this, "font family II" ); + d->familyEdit->setFocusProxy( d->familyList ); + + d->familyAccel + = new TQLabel( d->familyList, tr("&Font"), this, "family accelerator" ); + d->familyAccel->setIndent( 2 ); + + d->styleEdit = new TQLineEdit( this, "font style I" ); + d->styleEdit->setReadOnly( TRUE ); + d->styleList = new TQListBox( this, "font style II" ); + d->styleEdit->setFocusProxy( d->styleList ); + + d->styleAccel + = new TQLabel( d->styleList, tr("Font st&yle"), this, "style accelerator" ); + d->styleAccel->setIndent( 2 ); + + d->sizeEdit = new TQLineEdit( this, "font size I" ); + d->sizeEdit->setFocusPolicy( ClickFocus ); + TQIntValidator *validator = new TQIntValidator( 1, 512, this ); + d->sizeEdit->setValidator( validator ); + d->sizeList = new TQListBox( this, "font size II" ); + + d->sizeAccel + = new TQLabel ( d->sizeEdit, tr("&Size"), this, "size accelerator" ); + d->sizeAccel->setIndent( 2 ); + + // effects box + d->effects = new TQVGroupBox( tr("Effects"), this, "font effects" ); + d->strikeout = new TQCheckBox( d->effects, "strikeout on/off" ); + d->strikeout->setText( tr("Stri&keout") ); + d->underline = new TQCheckBox( d->effects, "underline on/off" ); + d->underline->setText( tr("&Underline") ); + + d->sample = new TQHGroupBox( tr("Sample"), this, "sample text" ); + d->sampleEdit = new TQLineEdit( d->sample, "r/w sample text" ); + d->sampleEdit->setSizePolicy( TQSizePolicy( TQSizePolicy::Ignored, TQSizePolicy::Ignored) ); + d->sampleEdit->setAlignment( AlignCenter ); + // Note that the sample text is *not* translated with tr(), as the + // characters used depend on the charset encoding. + d->sampleEdit->setText( "AaBbYyZz" ); + + d->scriptCombo = new TQComboBox( FALSE, this, "font encoding" ); + + d->scriptAccel + = new TQLabel( d->scriptCombo, tr("Scr&ipt"), this,"encoding label"); + d->scriptAccel->setIndent( 2 ); + + d->size = 0; + d->smoothScalable = FALSE; + + connect( d->scriptCombo, TQ_SIGNAL(activated(int)), + TQ_SLOT(scriptHighlighted(int)) ); + connect( d->familyList, TQ_SIGNAL(highlighted(int)), + TQ_SLOT(familyHighlighted(int)) ); + connect( d->styleList, TQ_SIGNAL(highlighted(int)), + TQ_SLOT(styleHighlighted(int)) ); + connect( d->sizeList, TQ_SIGNAL(highlighted(const TQString&)), + TQ_SLOT(sizeHighlighted(const TQString&)) ); + connect( d->sizeEdit, TQ_SIGNAL(textChanged(const TQString&)), + TQ_SLOT(sizeChanged(const TQString&)) ); + + connect( d->strikeout, TQ_SIGNAL(clicked()), + TQ_SLOT(updateSample()) ); + connect( d->underline, TQ_SIGNAL(clicked()), + TQ_SLOT(updateSample()) ); + + (void)d->familyList->sizeHint(); + (void)d->styleList->sizeHint(); + (void)d->sizeList->sizeHint(); + + for (int i = 0; i < TQFont::NScripts; i++) { + TQString scriptname = TQFontDatabase::scriptName((TQFont::Script) i); + if ( !scriptname.isEmpty() ) + d->scriptCombo->insertItem( scriptname ); + } + + updateFamilies(); + if ( d->familyList->count() != 0 ) + d->familyList->setCurrentItem( 0 ); + + // grid layout + TQGridLayout * mainGrid = new TQGridLayout( this, 9, 6, 12, 0 ); + + mainGrid->addWidget( d->familyAccel, 0, 0 ); + mainGrid->addWidget( d->familyEdit, 1, 0 ); + mainGrid->addWidget( d->familyList, 2, 0 ); + + mainGrid->addWidget( d->styleAccel, 0, 2 ); + mainGrid->addWidget( d->styleEdit, 1, 2 ); + mainGrid->addWidget( d->styleList, 2, 2 ); + + mainGrid->addWidget( d->sizeAccel, 0, 4 ); + mainGrid->addWidget( d->sizeEdit, 1, 4 ); + mainGrid->addWidget( d->sizeList, 2, 4 ); + + mainGrid->setColStretch( 0, 38 ); + mainGrid->setColStretch( 2, 24 ); + mainGrid->setColStretch( 4, 10 ); + + mainGrid->addColSpacing( 1, 6 ); + mainGrid->addColSpacing( 3, 6 ); + mainGrid->addColSpacing( 5, 6 ); + + mainGrid->addRowSpacing( 3, 12 ); + + mainGrid->addWidget( d->effects, 4, 0 ); + + mainGrid->addMultiCellWidget( d->sample, 4, 7, 2, 4 ); + + mainGrid->addWidget( d->scriptAccel, 5, 0 ); + mainGrid->addRowSpacing( 6, 2 ); + mainGrid->addWidget( d->scriptCombo, 7, 0 ); + + mainGrid->addRowSpacing( 8, 12 ); + + TQHBoxLayout *buttonBox = new TQHBoxLayout; + mainGrid->addMultiCell( buttonBox, 9, 9, 0, 4 ); + + buttonBox->addStretch( 1 ); + TQString okt = modal ? tr("OK") : tr("Apply"); + d->ok = new TQPushButton( okt, this, "accept font selection" ); + buttonBox->addWidget( d->ok ); + if ( modal ) + connect( d->ok, TQ_SIGNAL(clicked()), TQ_SLOT(accept()) ); + d->ok->setDefault( TRUE ); + + buttonBox->addSpacing( 12 ); + + TQString cancelt = modal ? tr("Cancel") : tr("Close"); + d->cancel = new TQPushButton( cancelt, this, "cancel/close" ); + buttonBox->addWidget( d->cancel ); + connect( d->cancel, TQ_SIGNAL(clicked()), TQ_SLOT(reject()) ); + + resize( 500, 360 ); + + d->sizeEdit->installEventFilter( this ); + d->familyList->installEventFilter( this ); + d->styleList->installEventFilter( this ); + d->sizeList->installEventFilter( this ); + + d->familyList->setFocus(); +} + +/*! + \internal + Destroys the font dialog and frees up its storage. +*/ + +TQFontDialog::~TQFontDialog() +{ + delete d; + d = 0; +} + +/*! + Executes a modal font dialog and returns a font. + + If the user clicks OK, the selected font is returned. If the user + clicks Cancel, the \a initial font is returned. + + The dialog is called \a name, with the parent \a parent. + \a initial is the initially selected font. + If the \a ok parameter is not-null, \e *\a ok is set to TRUE if the + user clicked OK, and set to FALSE if the user clicked Cancel. + + This static function is less flexible than the full TQFontDialog + object, but is convenient and easy to use. + + Examples: + \code + bool ok; + TQFont font = TQFontDialog::getFont( &ok, TQFont( "Times", 12 ), this ); + if ( ok ) { + // font is set to the font the user selected + } else { + // the user canceled the dialog; font is set to the initial + // value, in this case Times, 12. + } + \endcode + + The dialog can also be used to set a widget's font directly: + \code + myWidget.setFont( TQFontDialog::getFont( 0, myWidget.font() ) ); + \endcode + In this example, if the user clicks OK the font they chose will be + used, and if they click Cancel the original font is used. +*/ +TQFont TQFontDialog::getFont( bool *ok, const TQFont &initial, + TQWidget *parent, const char* name) +{ + return getFont( ok, &initial, parent, name ); +} + +/*! + \overload + + Executes a modal font dialog and returns a font. + + If the user clicks OK, the selected font is returned. If the user + clicks Cancel, the TQt default font is returned. + + The dialog is called \a name, with parent \a parent. + If the \a ok parameter is not-null, \e *\a ok is set to TRUE if the + user clicked OK, and FALSE if the user clicked Cancel. + + This static function is less functional than the full TQFontDialog + object, but is convenient and easy to use. + + Example: + \code + bool ok; + TQFont font = TQFontDialog::getFont( &ok, this ); + if ( ok ) { + // font is set to the font the user selected + } else { + // the user canceled the dialog; font is set to the default + // application font, TQApplication::font() + } + \endcode + +*/ +TQFont TQFontDialog::getFont( bool *ok, TQWidget *parent,const char* name) +{ + return getFont( ok, 0, parent, name ); +} + +extern bool tqt_use_native_dialogs; + +TQFont TQFontDialog::getFont( bool *ok, const TQFont *def, + TQWidget *parent, const char* name) +{ +#if defined(TQ_WS_X11) + if ( tqt_use_native_dialogs && TQTDEIntegration::enabled()) + return TQTDEIntegration::getFont( ok, def, parent, name ); +#endif + TQFont result; + if ( def ) + result = *def; + + TQFontDialog *dlg = new TQFontDialog( parent, name, TRUE ); + + dlg->setFont( ( def ? *def : TQFont() ) ); +#ifndef TQT_NO_WIDGET_TOPEXTRA + dlg->setCaption( tr("Select Font") ); +#endif + + bool res = (dlg->exec() == TQDialog::Accepted); + if ( res ) + result = dlg->font(); + if ( ok ) + *ok = res; + delete dlg; + return result; +} + + +/*! + \internal + An event filter to make the Up, Down, PageUp and PageDown keys work + correctly in the line edits. The source of the event is the object + \a o and the event is \a e. +*/ + +bool TQFontDialog::eventFilter( TQObject * o , TQEvent * e ) +{ + if ( e->type() == TQEvent::KeyPress) { + TQKeyEvent * k = (TQKeyEvent *)e; + if ( o == d->sizeEdit && + (k->key() == Key_Up || + k->key() == Key_Down || + k->key() == Key_Prior || + k->key() == Key_Next) ) { + + int ci = d->sizeList->currentItem(); + (void)TQApplication::sendEvent( d->sizeList, k ); + + if ( ci != d->sizeList->currentItem() && + style().styleHint(TQStyle::SH_FontDialog_SelectAssociatedText, this)) + d->sizeEdit->selectAll(); + return TRUE; + } else if ( ( o == d->familyList || o == d->styleList ) && + ( k->key() == Key_Return || k->key() == Key_Enter) ) { + k->accept(); + accept(); + return TRUE; + } + } else if ( e->type() == TQEvent::FocusIn && + style().styleHint(TQStyle::SH_FontDialog_SelectAssociatedText, this) ) { + if ( o == d->familyList ) + d->familyEdit->selectAll(); + else if ( o == d->styleList ) + d->styleEdit->selectAll(); + else if ( o == d->sizeList ) + d->sizeEdit->selectAll(); + } else if ( e->type() == TQEvent::MouseButtonPress && o == d->sizeList ) { + d->sizeEdit->setFocus(); + } + return TQDialog::eventFilter( o, e ); +} + +#ifdef TQ_WS_MAC +// #define SHOW_FONTS_IN_FAMILIES +#endif + +#ifdef SHOW_FONTS_IN_FAMILIES +#include "tqpainter.h" +#include + +class TQListBoxFontText : public TQListBoxText +{ + TQFont cfont; +public: + TQListBoxFontText( const TQString & text ); + ~TQListBoxFontText() { } + + int height( const TQListBox * ) const; + int width( const TQListBox * ) const; + +protected: + void paint( TQPainter * ); +}; + +TQListBoxFontText::TQListBoxFontText( const TQString & text ) + : TQListBoxText(text), cfont(text) +{ +} + +int TQListBoxFontText::height( const TQListBox * ) const +{ + TQFontMetrics fm(cfont); + return TQMAX( fm.lineSpacing() + 2, TQApplication::globalStrut().height() ); +} + +int TQListBoxFontText::width( const TQListBox * ) const +{ + TQFontMetrics fm(cfont); + return TQMAX( fm.width( text() ) + 6, TQApplication::globalStrut().width() ); +} + +void TQListBoxFontText::paint( TQPainter *painter ) +{ + painter->save(); + painter->setFont(cfont); + TQListBoxText::paint(painter); + painter->restore(); +} + +#endif + +/*! + \internal + Updates the contents of the "font family" list box. This + function can be reimplemented if you have special requirements. +*/ + +void TQFontDialog::updateFamilies() +{ + d->familyList->blockSignals( TRUE ); + + enum match_t { MATCH_NONE=0, MATCH_LAST_RESORT=1, MATCH_APP=2, MATCH_FALLBACK, MATCH_FAMILY=3 }; + + TQStringList familyNames = d->fdb.families(d->script); + { + // merge the unicode/unknown family list with the above list. + TQStringList l = d->fdb.families(TQFont::Unicode) + + d->fdb.families(TQFont::UnknownScript); + TQStringList::ConstIterator it = l.begin(), end = l.end(); + for (; it != end; ++it) { + if (! familyNames.contains(*it)) + familyNames << *it; + } + } + + familyNames.sort(); + + d->familyList->clear(); +#ifdef SHOW_FONTS_IN_FAMILIES + TQStringList::Iterator it = familyNames.begin(); + int idx = 0; + for( ; it != familyNames.end() ; ++it ) + d->familyList->insertItem(new TQListBoxFontText(*it), idx++); +#else + d->familyList->insertStringList( familyNames ); +#endif + + TQString foundryName1, familyName1, foundryName2, familyName2; + int bestFamilyMatch = -1; + match_t bestFamilyType = MATCH_NONE; + + TQFont f; + + // ##### do the right thing for a list of family names in the font. + TQFontDatabase::parseFontName(d->family, foundryName1, familyName1); + + TQStringList::Iterator it = familyNames.begin(); + int i = 0; + for( ; it != familyNames.end(); ++it, ++i ) { + + TQFontDatabase::parseFontName(*it, foundryName2, familyName2); + + //try to match.. + if ( familyName1 == familyName2 ) { + bestFamilyType = MATCH_FAMILY; + if ( foundryName1 == foundryName2 ) { + bestFamilyMatch = i; + break; + } + if ( bestFamilyMatch < MATCH_FAMILY ) + bestFamilyMatch = i; + } + + //and try some fall backs + match_t type = MATCH_NONE; + if ( bestFamilyType <= MATCH_NONE && familyName2 == f.lastResortFamily() ) + type = MATCH_LAST_RESORT; + if ( bestFamilyType <= MATCH_LAST_RESORT && familyName2 == f.family() ) + type = MATCH_APP; + // ### add fallback for script + if ( type != MATCH_NONE ) { + bestFamilyType = type; + bestFamilyMatch = i; + } + } + + if (i != -1 && bestFamilyType != MATCH_NONE) + d->familyList->setCurrentItem(bestFamilyMatch); + else + d->familyList->setCurrentItem( 0 ); + d->familyEdit->setText( d->familyList->currentText() ); + if ( style().styleHint(TQStyle::SH_FontDialog_SelectAssociatedText, this) && + d->familyList->hasFocus() ) + d->familyEdit->selectAll(); + + d->familyList->blockSignals( FALSE ); + updateStyles(); +} + +/*! + \internal + Updates the contents of the "font style" list box. This + function can be reimplemented if you have special requirements. +*/ + +void TQFontDialog::updateStyles() +{ + d->styleList->blockSignals( TRUE ); + + d->styleList->clear(); + + TQStringList styles = d->fdb.styles( d->familyList->currentText() ); + + if ( styles.isEmpty() ) { + d->styleEdit->clear(); + d->smoothScalable = FALSE; + } else { + d->styleList->insertStringList( styles ); + + if ( !d->style.isEmpty() ) { + bool found = FALSE; + bool first = TRUE; + TQString cstyle = d->style; + redo: + for ( int i = 0 ; i < (int)d->styleList->count() ; i++ ) { + if ( cstyle == d->styleList->text(i) ) { + d->styleList->setCurrentItem( i ); + found = TRUE; + break; + } + } + if (!found && first) { + if (cstyle.contains("Italic")) { + cstyle.replace("Italic", "Oblique"); + first = FALSE; + goto redo; + } else if (cstyle.contains("Oblique")) { + cstyle.replace("Oblique", "Italic"); + first = FALSE; + goto redo; + } + } + if ( !found ) + d->styleList->setCurrentItem( 0 ); + } + + d->styleEdit->setText( d->styleList->currentText() ); + if ( style().styleHint(TQStyle::SH_FontDialog_SelectAssociatedText, this) && + d->styleList->hasFocus() ) + d->styleEdit->selectAll(); + + d->smoothScalable = d->fdb.isSmoothlyScalable( d->familyList->currentText(), d->styleList->currentText() ); + } + + d->styleList->blockSignals( FALSE ); + + updateSizes(); +} + +/*! + \internal + Updates the contents of the "font size" list box. This + function can be reimplemented if you have special requirements. +*/ + +void TQFontDialog::updateSizes() +{ + d->sizeList->blockSignals( TRUE ); + + d->sizeList->clear(); + + if ( !d->familyList->currentText().isEmpty() ) { + TQValueList sizes = d->fdb.pointSizes( d->familyList->currentText(), d->styleList->currentText() ); + + int i = 0; + bool found = FALSE; + for( TQValueList::iterator it = sizes.begin() ; it != sizes.end(); ++it ) { + d->sizeList->insertItem( TQString::number( *it ) ); + if ( !found && *it >= d->size ) { + d->sizeList->setCurrentItem( i ); + found = TRUE; + } + ++i; + } + if ( !found ) { + // we request a size bigger than the ones in the list, select the biggest one + d->sizeList->setCurrentItem( d->sizeList->count() - 1 ); + } + + d->sizeEdit->blockSignals( TRUE ); + d->sizeEdit->setText( ( d->smoothScalable ? TQString::number( d->size ) : d->sizeList->currentText() ) ); + if ( style().styleHint(TQStyle::SH_FontDialog_SelectAssociatedText, this) && + d->sizeList->hasFocus() ) + d->sizeEdit->selectAll(); + d->sizeEdit->blockSignals( FALSE ); + } else { + d->sizeEdit->clear(); + } + + d->sizeList->blockSignals( FALSE ); + updateSample(); +} + +void TQFontDialog::updateSample() +{ + if ( d->familyList->currentText().isEmpty() ) + d->sampleEdit->clear(); + else + d->sampleEdit->setFont( font() ); +} + +/*! + \internal +*/ +void TQFontDialog::scriptHighlighted( int index ) +{ + d->script = (TQFont::Script)index; + d->sampleEdit->setText( d->fdb.scriptSample( d->script ) ); + updateFamilies(); +} + +/*! + \internal +*/ +void TQFontDialog::familyHighlighted( int i ) +{ + d->family = d->familyList->text( i ); + d->familyEdit->setText( d->family ); + if ( style().styleHint(TQStyle::SH_FontDialog_SelectAssociatedText, this) && + d->familyList->hasFocus() ) + d->familyEdit->selectAll(); + + updateStyles(); +} + + +/*! + \internal +*/ + +void TQFontDialog::styleHighlighted( int index ) +{ + TQString s = d->styleList->text( index ); + d->styleEdit->setText( s ); + if ( style().styleHint(TQStyle::SH_FontDialog_SelectAssociatedText, this) && + d->styleList->hasFocus() ) + d->styleEdit->selectAll(); + + d->style = s; + + updateSizes(); +} + + +/*! + \internal +*/ + +void TQFontDialog::sizeHighlighted( const TQString &s ) +{ + d->sizeEdit->setText( s ); + if ( style().styleHint(TQStyle::SH_FontDialog_SelectAssociatedText, this) && + d->sizeEdit->hasFocus() ) + d->sizeEdit->selectAll(); + + d->size = s.toInt(); + updateSample(); +} + +/*! + \internal + This slot is called if the user changes the font size. + The size is passed in the \a s argument as a \e string. +*/ + +void TQFontDialog::sizeChanged( const TQString &s ) +{ + // no need to check if the conversion is valid, since we have an TQIntValidator in the size edit + int size = s.toInt(); + if ( d->size == size ) + return; + + d->size = size; + if ( d->sizeList->count() != 0 ) { + int i; + for ( i = 0 ; i < (int)d->sizeList->count() - 1 ; i++ ) { + if ( d->sizeList->text(i).toInt() >= d->size ) + break; + } + d->sizeList->blockSignals( TRUE ); + d->sizeList->setCurrentItem( i ); + d->sizeList->blockSignals( FALSE ); + } + updateSample(); +} + +/*! + \internal + Sets the font highlighted in the TQFontDialog to font \a f. + + \sa font() +*/ + +void TQFontDialog::setFont( const TQFont &f ) +{ + d->family = f.family(); + d->style = d->fdb.styleString( f ); + d->size = f.pointSize(); + if ( d->size == -1 ) { + TQFontInfo fi( f ); + d->size = fi.pointSize(); + } + d->strikeout->setChecked( f.strikeOut() ); + d->underline->setChecked( f.underline() ); + + updateFamilies(); +} + +/*! + \internal + Returns the font which the user has chosen. + + \sa setFont() +*/ + +TQFont TQFontDialog::font() const +{ + int pSize = d->sizeEdit->text().toInt(); + + TQFont f = d->fdb.font( d->familyList->currentText(), d->style, pSize ); + f.setStrikeOut( d->strikeout->isChecked() ); + f.setUnderline( d->underline->isChecked() ); + return f; +} + +#endif diff --git a/src/dialogs/tqfontdialog.h b/src/dialogs/tqfontdialog.h new file mode 100644 index 000000000..2c7d3f9d4 --- /dev/null +++ b/src/dialogs/tqfontdialog.h @@ -0,0 +1,112 @@ +/**************************************************************************** +** +** Definition of TQFontDialog +** +** Created : 970605 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the dialogs module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef TQFONTDIALOG_H +#define TQFONTDIALOG_H + +#include "ntqwindowdefs.h" + +#ifndef TQT_NO_FONTDIALOG + +// +// W A R N I N G +// ------------- +// +// This class is under development and has private constructors. +// +// You may use the public static getFont() functions which are guaranteed +// to be available in the future. +// + +#ifndef QT_H +#include "ntqdialog.h" +#include "tqfont.h" +#endif // QT_H + +class TQFontDialogPrivate; + +class TQ_EXPORT TQFontDialog: public TQDialog +{ + TQ_OBJECT + +public: + static TQFont getFont( bool *ok, const TQFont &def, + TQWidget* parent=0, const char* name=0); + static TQFont getFont( bool *ok, TQWidget* parent=0, const char* name=0); + +private: + static TQFont getFont( bool *ok, const TQFont *def, + TQWidget* parent=0, const char* name=0); + + TQFontDialog( TQWidget* parent=0, const char* name=0, bool modal=FALSE, + WFlags f=0 ); + ~TQFontDialog(); + + TQFont font() const; + void setFont( const TQFont &font ); + + bool eventFilter( TQObject *, TQEvent * ); + + void updateFamilies(); + void updateStyles(); + void updateSizes(); + +private slots: + void sizeChanged( const TQString &); + void familyHighlighted( int ); + void scriptHighlighted( int ); + void styleHighlighted( int ); + void sizeHighlighted( const TQString & ); + void updateSample(); + +private: + friend class TQFontDialogPrivate; + TQFontDialogPrivate * d; + +private: // Disabled copy constructor and operator= +#if defined(TQ_DISABLE_COPY) + TQFontDialog( const TQFontDialog & ); + TQFontDialog& operator=( const TQFontDialog & ); +#endif +}; + +#endif + +#endif // TQFONTDIALOG_H diff --git a/src/kernel/ntqbrush.h b/src/kernel/ntqbrush.h deleted file mode 100644 index 93b375a68..000000000 --- a/src/kernel/ntqbrush.h +++ /dev/null @@ -1,94 +0,0 @@ -/**************************************************************************** -** -** Definition of TQBrush class -** -** Created : 940112 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#ifndef TQBRUSH_H -#define TQBRUSH_H - -#ifndef QT_H -#include "ntqcolor.h" -#include "ntqshared.h" -#endif // QT_H - - -class TQ_EXPORT TQBrush: public TQt -{ -friend class TQPainter; -public: - TQBrush(); - TQBrush( BrushStyle ); - TQBrush( const TQColor &, BrushStyle=SolidPattern ); - TQBrush( const TQColor &, const TQPixmap & ); - TQBrush( const TQBrush & ); - ~TQBrush(); - TQBrush &operator=( const TQBrush & ); - - BrushStyle style() const { return data->style; } - void setStyle( BrushStyle ); - const TQColor &color()const { return data->color; } - void setColor( const TQColor & ); - TQPixmap *pixmap() const { return data->pixmap; } - void setPixmap( const TQPixmap & ); - - bool operator==( const TQBrush &p ) const; - bool operator!=( const TQBrush &b ) const - { return !(operator==(b)); } - -private: - TQBrush copy() const; - void detach(); - void init( const TQColor &, BrushStyle ); - struct TQBrushData : public TQShared { // brush data - BrushStyle style; - TQColor color; - TQPixmap *pixmap; - } *data; -}; - - -/***************************************************************************** - TQBrush stream functions - *****************************************************************************/ - -#ifndef TQT_NO_DATASTREAM -TQ_EXPORT TQDataStream &operator<<( TQDataStream &, const TQBrush & ); -TQ_EXPORT TQDataStream &operator>>( TQDataStream &, TQBrush & ); -#endif - -#endif // TQBRUSH_H diff --git a/src/kernel/ntqcolor.h b/src/kernel/ntqcolor.h deleted file mode 100644 index 0fca55097..000000000 --- a/src/kernel/ntqcolor.h +++ /dev/null @@ -1,229 +0,0 @@ -/**************************************************************************** -** -** Definition of TQColor class -** -** Created : 940112 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#ifndef TQCOLOR_H -#define TQCOLOR_H - -#ifndef QT_H -#include "ntqwindowdefs.h" -#include "tqstringlist.h" -#endif // QT_H - -const TQRgb TQT_RGB_MASK = 0x00ffffff; // masks RGB values - -TQ_EXPORT inline int tqRed( TQRgb rgb ) // get red part of RGB -{ return (int)((rgb >> 16) & 0xff); } - -TQ_EXPORT inline int tqGreen( TQRgb rgb ) // get green part of RGB -{ return (int)((rgb >> 8) & 0xff); } - -TQ_EXPORT inline int tqBlue( TQRgb rgb ) // get blue part of RGB -{ return (int)(rgb & 0xff); } - -TQ_EXPORT inline int tqAlpha( TQRgb rgb ) // get alpha part of RGBA -{ return (int)((rgb >> 24) & 0xff); } - -TQ_EXPORT inline TQRgb tqRgb( int r, int g, int b )// set RGB value -{ return (0xff << 24) | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff); } - -TQ_EXPORT inline TQRgb tqRgba( int r, int g, int b, int a )// set RGBA value -{ return ((a & 0xff) << 24) | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff); } - -TQ_EXPORT inline int tqGray( int r, int g, int b )// convert R,G,B to gray 0..255 -{ return (r*11+g*16+b*5)/32; } - -TQ_EXPORT inline int tqGray( TQRgb rgb ) // convert RGB to gray 0..255 -{ return tqGray( tqRed(rgb), tqGreen(rgb), tqBlue(rgb) ); } - - -class TQ_EXPORT TQColor -{ -public: - enum Spec { Rgb, Hsv }; - - TQColor(); - TQColor( int r, int g, int b ); - TQColor( int x, int y, int z, Spec ); - TQColor( TQRgb rgb, uint pixel=0xffffffff); - TQColor( const TQString& name ); - TQColor( const char *name ); - TQColor( const TQColor & ); - TQColor &operator=( const TQColor & ); - - bool isValid() const; - bool isDirty() const; - TQString name() const; - void setNamedColor( const TQString& name ); - - TQRgb rgb() const; - void setRgb( int r, int g, int b ); - void setRgb( TQRgb rgb ); - void getRgb( int *r, int *g, int *b ) const { rgb( r, g, b ); } - void rgb( int *r, int *g, int *b ) const; // obsolete - - int red() const; - int green() const; - int blue() const; - - void setHsv( int h, int s, int v ); - void getHsv( int *h, int *s, int *v ) const { hsv( h, s, v ); } - void hsv( int *h, int *s, int *v ) const; // obsolete - void getHsv( int &h, int &s, int &v ) const { hsv( &h, &s, &v ); } // obsolete - - TQColor light( int f = 150 ) const; - TQColor dark( int f = 200 ) const; - - bool operator==( const TQColor &c ) const; - bool operator!=( const TQColor &c ) const; - - uint alloc(); - uint pixel() const; - -#if defined(TQ_WS_X11) - // ### in 4.0, make this take a default argument of -1 for default screen? - uint alloc( int screen ); - uint pixel( int screen ) const; -#endif - - static int maxColors(); - static int numBitPlanes(); - - static int enterAllocContext(); - static void leaveAllocContext(); - static int currentAllocContext(); - static void destroyAllocContext( int ); - -#if defined(TQ_WS_WIN) - static const TQRgb* palette( int* numEntries = 0 ); - static int setPaletteEntries( const TQRgb* entries, int numEntries, - int base = -1 ); - static HPALETTE hPal() { return hpal; } - static uint realizePal( TQWidget * ); -#endif - - static void initialize(); - static void cleanup(); -#ifndef TQT_NO_STRINGLIST - static TQStringList colorNames(); -#endif - enum { Dirt = 0x44495254, Invalid = 0x49000000 }; - -private: - void setSystemNamedColor( const TQString& name ); - void setPixel( uint pixel ); - static void initGlobalColors(); - static uint argbToPix32(TQRgb); - static TQColor* globalColors(); - static bool color_init; - static bool globals_init; -#if defined(TQ_WS_WIN) - static HPALETTE hpal; -#endif - static enum ColorModel { d8, d32 } colormodel; - union { - TQRgb argb; - struct D8 { - TQRgb argb; - uchar pix; - uchar invalid; - uchar dirty; - uchar direct; - } d8; - struct D32 { - TQRgb argb; - uint pix; - bool invalid() const { return argb == TQColor::Invalid && pix == TQColor::Dirt; } - bool probablyDirty() const { return pix == TQColor::Dirt; } - } d32; - } d; -}; - - -inline TQColor::TQColor() -{ d.d32.argb = Invalid; d.d32.pix = Dirt; } - -inline TQColor::TQColor( int r, int g, int b ) -{ - d.d32.argb = Invalid; - d.d32.pix = Dirt; - setRgb( r, g, b ); -} - -inline TQRgb TQColor::rgb() const -{ return d.argb; } - -inline int TQColor::red() const -{ return tqRed(d.argb); } - -inline int TQColor::green() const -{ return tqGreen(d.argb); } - -inline int TQColor::blue() const -{ return tqBlue(d.argb); } - -inline bool TQColor::isValid() const -{ - if ( colormodel == d8 ) - return !d.d8.invalid; - else - return !d.d32.invalid(); -} - -inline bool TQColor::operator==( const TQColor &c ) const -{ - return d.argb == c.d.argb && isValid() == c.isValid(); -} - -inline bool TQColor::operator!=( const TQColor &c ) const -{ - return !operator==(c); -} - - -/***************************************************************************** - TQColor stream functions - *****************************************************************************/ - -#ifndef TQT_NO_DATASTREAM -TQ_EXPORT TQDataStream &operator<<( TQDataStream &, const TQColor & ); -TQ_EXPORT TQDataStream &operator>>( TQDataStream &, TQColor & ); -#endif - -#endif // TQCOLOR_H diff --git a/src/kernel/ntqfont.h b/src/kernel/ntqfont.h deleted file mode 100644 index 441b57ddf..000000000 --- a/src/kernel/ntqfont.h +++ /dev/null @@ -1,365 +0,0 @@ -/**************************************************************************** -** -** Definition of TQFont class -** -** Created : 940514 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#ifndef TQFONT_H -#define TQFONT_H - -#ifndef QT_H -#include "ntqwindowdefs.h" -#include "tqstring.h" -#endif // QT_H - - -class TQFontPrivate; /* don't touch */ -class TQStringList; -class TQTextFormatCollection; - -class TQ_EXPORT TQFont -{ -public: - enum StyleHint { - Helvetica, SansSerif = Helvetica, - Times, Serif = Times, - Courier, TypeWriter = Courier, - OldEnglish, Decorative = OldEnglish, - System, - AnyStyle - }; - - enum StyleStrategy { - PreferDefault = 0x0001, - PreferBitmap = 0x0002, - PreferDevice = 0x0004, - PreferOutline = 0x0008, - ForceOutline = 0x0010, - PreferMatch = 0x0020, - PreferQuality = 0x0040, - PreferAntialias = 0x0080, - NoAntialias = 0x0100, - OpenGLCompatible = 0x0200 - }; - - enum Weight { - Light = 25, - Normal = 50, - DemiBold = 63, - Bold = 75, - Black = 87 - }; - - enum Stretch { - UltraCondensed = 50, - ExtraCondensed = 62, - Condensed = 75, - SemiCondensed = 87, - Unstretched = 100, - SemiExpanded = 112, - Expanded = 125, - ExtraExpanded = 150, - UltraExpanded = 200 - }; - - // default font - TQFont(); - // specific font -#ifdef Q_QDOC - TQFont( const TQString &family, int pointSize = 12, int weight = Normal, - bool italic = FALSE ); -#else - TQFont( const TQString &family, int pointSize = -1, int weight = -1, - bool italic = FALSE ); -#endif - // copy constructor - TQFont( const TQFont & ); - - ~TQFont(); - - TQString family() const; - void setFamily( const TQString &); - - int pointSize() const; - float pointSizeFloat() const; - void setPointSize( int ); - void setPointSizeFloat( float ); - - int pixelSize() const; - void setPixelSize( int ); - void setPixelSizeFloat( float ); - - int weight() const; - void setWeight( int ); - - bool bold() const; - void setBold( bool ); - - bool italic() const; - void setItalic( bool ); - - bool underline() const; - void setUnderline( bool ); - - bool overline() const; - void setOverline( bool ); - - bool strikeOut() const; - void setStrikeOut( bool ); - - bool fixedPitch() const; - void setFixedPitch( bool ); - - StyleHint styleHint() const; - StyleStrategy styleStrategy() const; - void setStyleHint( StyleHint, StyleStrategy = PreferDefault ); - void setStyleStrategy( StyleStrategy s ); - - int stretch() const; - void setStretch( int ); - - // is raw mode still needed? - bool rawMode() const; - void setRawMode( bool ); - - // dupicated from TQFontInfo - bool exactMatch() const; - - TQFont &operator=( const TQFont & ); - bool operator==( const TQFont & ) const; - bool operator!=( const TQFont & ) const; - bool isCopyOf( const TQFont & ) const; - - -#ifdef TQ_WS_WIN - HFONT handle() const; -#else // !TQ_WS_WIN - TQt::HANDLE handle() const; -#endif // TQ_WS_WIN - - - // needed for X11 - void setRawName( const TQString & ); - TQString rawName() const; - - TQString key() const; - - TQString toString() const; - bool fromString(const TQString &); - -#ifndef TQT_NO_STRINGLIST - static TQString substitute(const TQString &); - static TQStringList substitutes(const TQString &); - static TQStringList substitutions(); - static void insertSubstitution(const TQString&, const TQString &); - static void insertSubstitutions(const TQString&, const TQStringList &); - static void removeSubstitution(const TQString &); -#endif //TQT_NO_STRINGLIST - static void initialize(); - static void cleanup(); - static void cacheStatistics(); - - // a copy of this lives in qunicodetables.cpp, as we can't include - // ntqfont.h it in tools/. Do not modify without changing the script - // enum in qunicodetable_p.h aswell. - enum Script { - // European Alphabetic Scripts - Latin, - Greek, - Cyrillic, - Armenian, - Georgian, - Runic, - Ogham, - SpacingModifiers, - CombiningMarks, - - // Middle Eastern Scripts - Hebrew, - Arabic, - Syriac, - Thaana, - - // South and Southeast Asian Scripts - Devanagari, - Bengali, - Gurmukhi, - Gujarati, - Oriya, - Tamil, - Telugu, - Kannada, - Malayalam, - Sinhala, - Thai, - Lao, - Tibetan, - Myanmar, - Khmer, - - // East Asian Scripts - Han, - Hiragana, - Katakana, - Hangul, - Bopomofo, - Yi, - - // Additional Scripts - Ethiopic, - Cherokee, - CanadianAboriginal, - Mongolian, - - // Symbols - CurrencySymbols, - LetterlikeSymbols, - NumberForms, - MathematicalOperators, - TechnicalSymbols, - GeometricSymbols, - MiscellaneousSymbols, - EnclosedAndSquare, - Braille, - - Unicode, - - // some scripts added in Unicode 3.2 - Tagalog, - Hanunoo, - Buhid, - Tagbanwa, - - KatakanaHalfWidth, - - // from Unicode 4.0 - Limbu, - TaiLe, - - // End -#if !defined(Q_QDOC) - NScripts, - UnknownScript = NScripts, - - NoScript, - - // ---------------------------------------- - // Dear User, you can see values > NScript, - // but they are internal - do not touch. - - Han_Japanese, - Han_SimplifiedChinese, - Han_TraditionalChinese, - Han_Korean, - - LastPrivateScript -#endif - }; - - TQString defaultFamily() const; - TQString lastResortFamily() const; - TQString lastResortFont() const; - -#ifndef TQT_NO_COMPAT - - static TQFont defaultFont(); - static void setDefaultFont( const TQFont & ); - -#endif // TQT_NO_COMPAT - - TQFont resolve( const TQFont & ) const; - -protected: - // why protected? - bool dirty() const; - int deciPointSize() const; - -private: - TQFont( TQFontPrivate *, TQPaintDevice *pd ); - - void detach(); - -#if defined(TQ_WS_MAC) - void macSetFont(TQPaintDevice *); -#elif defined(TQ_WS_X11) - void x11SetScreen( int screen = -1 ); - int x11Screen() const; -#endif - - friend class TQFontMetrics; - friend class TQFontInfo; - friend class TQPainter; - friend class TQPSPrinterFont; - friend class TQApplication; - friend class TQWidget; - friend class TQTextFormatCollection; - friend class TQTextLayout; - friend class TQTextItem; - friend class TQGLContext; -#if defined(TQ_WS_X11) && !defined(TQT_NO_XFTFREETYPE) - friend TQt::HANDLE qt_xft_handle(const TQFont &font); -#endif -#ifndef TQT_NO_DATASTREAM - friend TQ_EXPORT TQDataStream &operator<<( TQDataStream &, const TQFont & ); - friend TQ_EXPORT TQDataStream &operator>>( TQDataStream &, TQFont & ); -#endif - - TQFontPrivate *d; -}; - - -inline bool TQFont::bold() const -{ return weight() > Normal; } - - -inline void TQFont::setBold( bool enable ) -{ setWeight( enable ? Bold : Normal ); } - - - - -/***************************************************************************** - TQFont stream functions - *****************************************************************************/ - -#ifndef TQT_NO_DATASTREAM -TQ_EXPORT TQDataStream &operator<<( TQDataStream &, const TQFont & ); -TQ_EXPORT TQDataStream &operator>>( TQDataStream &, TQFont & ); -#endif - - -#endif // TQFONT_H diff --git a/src/kernel/ntqfontdatabase.h b/src/kernel/ntqfontdatabase.h deleted file mode 100644 index aa279bfd6..000000000 --- a/src/kernel/ntqfontdatabase.h +++ /dev/null @@ -1,219 +0,0 @@ -/**************************************************************************** -** -** Definition of the TQFontDatabase class -** -** Created : 981126 -** -** Copyright (C) 1999-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#ifndef TQFONTDATABASE_H -#define TQFONTDATABASE_H - -#ifndef QT_H -#include "ntqwindowdefs.h" -#include "tqstring.h" -#include "tqstringlist.h" -#include "ntqfont.h" -#include "tqvaluelist.h" -#endif // QT_H - - -#ifndef TQT_NO_FONTDATABASE - -class TQFontStylePrivate; /* Don't touch! */ -struct TQtFontStyle; -struct TQtFontFamily; -struct TQtFontFoundry; -struct TQFontDef; -class TQFontEngine; -class TQFontDatabasePrivate; - -class TQ_EXPORT TQFontDatabase -{ -public: - static TQValueList standardSizes(); - - TQFontDatabase(); - - TQStringList families() const; - TQStringList families( TQFont::Script ) const; - TQStringList styles( const TQString & ) const; - TQValueList pointSizes( const TQString &, const TQString & = TQString::null); - TQValueList smoothSizes( const TQString &, const TQString &); - TQString styleString( const TQFont &); - - TQFont font( const TQString &, const TQString &, int); - - bool isBitmapScalable( const TQString &, const TQString & = TQString::null) const; - bool isSmoothlyScalable( const TQString &, const TQString & = TQString::null) const; - bool isScalable( const TQString &, const TQString & = TQString::null) const; - bool isFixedPitch( const TQString &, const TQString & = TQString::null) const; - - bool italic( const TQString &, const TQString &) const; - bool bold( const TQString &, const TQString &) const; - int weight( const TQString &, const TQString &) const; - - static TQString scriptName(TQFont::Script); - static TQString scriptSample(TQFont::Script); - - // For source compatibility with < 3.0 -#ifndef TQT_NO_COMPAT - - TQStringList families(bool) const; - TQStringList styles( const TQString &, const TQString & ) const; - TQValueList pointSizes( const TQString &, const TQString &, const TQString & ); - TQValueList smoothSizes( const TQString &, const TQString &, const TQString & ); - - TQFont font( const TQString &, const TQString &, int, const TQString &); - - bool isBitmapScalable( const TQString &, const TQString &, const TQString & ) const; - bool isSmoothlyScalable( const TQString &, const TQString &, const TQString & ) const; - bool isScalable( const TQString &, const TQString &, const TQString & ) const; - bool isFixedPitch( const TQString &, const TQString &, const TQString & ) const; - - bool italic( const TQString &, const TQString &, const TQString & ) const; - bool bold( const TQString &, const TQString &, const TQString & ) const; - int weight( const TQString &, const TQString &, const TQString & ) const; - -#endif // TQT_NO_COMPAT - -private: -#if defined(TQ_WS_X11) || defined(TQ_WS_WIN) - static TQFontEngine *findFont( TQFont::Script script, const TQFontPrivate *fp, - const TQFontDef &request, int force_encoding_id = -1 ); -#endif // TQ_WS_X11 - - static void createDatabase(); - - static void parseFontName(const TQString &name, TQString &foundry, TQString &family); - - friend struct TQFontDef; - friend class TQFontPrivate; - friend class TQFontDialog; - friend class TQFontEngineLatinXLFD; - - TQFontDatabasePrivate *d; -}; - - -#ifndef TQT_NO_COMPAT - -inline TQStringList TQFontDatabase::families( bool ) const -{ - return families(); -} - -inline TQStringList TQFontDatabase::styles( const TQString &family, - const TQString & ) const -{ - return styles(family); -} - -inline TQValueList TQFontDatabase::pointSizes( const TQString &family, - const TQString &style , - const TQString & ) -{ - return pointSizes(family, style); -} - -inline TQValueList TQFontDatabase::smoothSizes( const TQString &family, - const TQString &style, - const TQString & ) -{ - return smoothSizes(family, style); -} - -inline TQFont TQFontDatabase::font( const TQString &familyName, - const TQString &style, - int pointSize, - const TQString &) -{ - return font(familyName, style, pointSize); -} - -inline bool TQFontDatabase::isBitmapScalable( const TQString &family, - const TQString &style, - const TQString & ) const -{ - return isBitmapScalable(family, style); -} - -inline bool TQFontDatabase::isSmoothlyScalable( const TQString &family, - const TQString &style, - const TQString & ) const -{ - return isSmoothlyScalable(family, style); -} - -inline bool TQFontDatabase::isScalable( const TQString &family, - const TQString &style, - const TQString & ) const -{ - return isScalable(family, style); -} - -inline bool TQFontDatabase::isFixedPitch( const TQString &family, - const TQString &style, - const TQString & ) const -{ - return isFixedPitch(family, style); -} - -inline bool TQFontDatabase::italic( const TQString &family, - const TQString &style, - const TQString & ) const -{ - return italic(family, style); -} - -inline bool TQFontDatabase::bold( const TQString &family, - const TQString &style, - const TQString & ) const -{ - return bold(family, style); -} - -inline int TQFontDatabase::weight( const TQString &family, - const TQString &style, - const TQString & ) const -{ - return weight(family, style); -} - -#endif // TQT_NO_COMPAT - -#endif // TQT_NO_FONTDATABASE - -#endif // TQFONTDATABASE_H diff --git a/src/kernel/ntqfontinfo.h b/src/kernel/ntqfontinfo.h deleted file mode 100644 index 25c269ff6..000000000 --- a/src/kernel/ntqfontinfo.h +++ /dev/null @@ -1,91 +0,0 @@ -/**************************************************************************** -** -** Definition of TQFontInfo class -** -** Created : 950131 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#ifndef TQFONTINFO_H -#define TQFONTINFO_H - -#ifndef QT_H -#include "ntqfont.h" -#endif // QT_H - - -class TQ_EXPORT TQFontInfo -{ -public: - TQFontInfo( const TQFont & ); - TQFontInfo( const TQFont &, TQFont::Script ); - TQFontInfo( const TQFontInfo & ); - ~TQFontInfo(); - - TQFontInfo &operator=( const TQFontInfo & ); - - TQString family() const; - int pixelSize() const; - int pointSize() const; - bool italic() const; - int weight() const; - bool bold() const; - bool underline() const; - bool overline() const; - bool strikeOut() const; - bool fixedPitch() const; - TQFont::StyleHint styleHint() const; - bool rawMode() const; - - bool exactMatch() const; - - -private: - TQFontInfo( const TQPainter * ); - - TQFontPrivate *d; - TQPainter *painter; - int fscript; - - friend class TQWidget; - friend class TQPainter; -}; - - -inline bool TQFontInfo::bold() const -{ return weight() > TQFont::Normal; } - - -#endif // TQFONTINFO_H diff --git a/src/kernel/ntqfontmetrics.h b/src/kernel/ntqfontmetrics.h deleted file mode 100644 index 887132553..000000000 --- a/src/kernel/ntqfontmetrics.h +++ /dev/null @@ -1,113 +0,0 @@ -/**************************************************************************** -** -** Definition of TQFontMetrics class -** -** Created : 940514 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#ifndef TQFONTMETRICS_H -#define TQFONTMETRICS_H - -#ifndef QT_H -#include "ntqfont.h" -#include "ntqrect.h" -#endif // QT_H - -class TQTextCodec; -class TQTextParag; - -class TQ_EXPORT TQFontMetrics -{ -public: - TQFontMetrics( const TQFont & ); - TQFontMetrics( const TQFont &, TQFont::Script ); - TQFontMetrics( const TQFontMetrics & ); - ~TQFontMetrics(); - - TQFontMetrics &operator=( const TQFontMetrics & ); - - int ascent() const; - int descent() const; - int height() const; - int leading() const; - int lineSpacing() const; - int minLeftBearing() const; - int minRightBearing() const; - int maxWidth() const; - - bool inFont(TQChar) const; - - int leftBearing(TQChar) const; - int rightBearing(TQChar) const; - int width( const TQString &, int len = -1 ) const; - - int width( TQChar ) const; -#ifndef TQT_NO_COMPAT - int width( char c ) const { return width( (TQChar) c ); } -#endif - - int charWidth( const TQString &str, int pos ) const; - TQRect boundingRect( const TQString &, int len = -1 ) const; - TQRect boundingRect( TQChar ) const; - TQRect boundingRect( int x, int y, int w, int h, int flags, - const TQString& str, int len=-1, int tabstops=0, - int *tabarray=0, TQTextParag **intern=0 ) const; - TQSize size( int flags, - const TQString& str, int len=-1, int tabstops=0, - int *tabarray=0, TQTextParag **intern=0 ) const; - - int underlinePos() const; - int overlinePos() const; - int strikeOutPos() const; - int lineWidth() const; - -private: - TQFontMetrics( const TQPainter * ); - - friend class TQWidget; - friend class TQPainter; - friend class TQTextFormat; -#if defined( TQ_WS_MAC ) - friend class TQFontPrivate; -#endif - - TQFontPrivate *d; - TQPainter *painter; - int fscript; -}; - - -#endif // TQFONTMETRICS_H diff --git a/src/kernel/ntqmovie.h b/src/kernel/ntqmovie.h deleted file mode 100644 index 8e92ec6d4..000000000 --- a/src/kernel/ntqmovie.h +++ /dev/null @@ -1,115 +0,0 @@ -/**************************************************************************** -** -** Definition of movie classes -** -** Created : 970617 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#ifndef TQMOVIE_H -#define TQMOVIE_H - -#ifndef QT_H -#include "ntqpixmap.h" // ### remove or keep for users' convenience? -#endif // QT_H - -#ifndef TQT_NO_MOVIE - -class TQDataSource; -class TQObject; -class TQMoviePrivate; - -class TQ_EXPORT TQMovie { -public: - TQMovie(); - TQMovie(int bufsize); - TQMovie(TQDataSource*, int bufsize=1024); - TQMovie(const TQString &fileName, int bufsize=1024); - TQMovie(TQByteArray data, int bufsize=1024); - TQMovie(const TQMovie&); - ~TQMovie(); - - TQMovie& operator=(const TQMovie&); - - int pushSpace() const; - void pushData(const uchar* data, int length); - - const TQColor& backgroundColor() const; - void setBackgroundColor(const TQColor&); - - const TQRect& getValidRect() const; - const TQPixmap& framePixmap() const; - const TQImage& frameImage() const; - - bool isNull() const; - - int frameNumber() const; - int steps() const; - bool paused() const; - bool finished() const; - bool running() const; - - void unpause(); - void pause(); - void step(); - void step(int); - void restart(); - - int speed() const; - void setSpeed(int); - - void connectResize(TQObject* receiver, const char *member); - void disconnectResize(TQObject* receiver, const char *member=0); - - void connectUpdate(TQObject* receiver, const char *member); - void disconnectUpdate(TQObject* receiver, const char *member=0); - - enum Status { SourceEmpty=-2, - UnrecognizedFormat=-1, - Paused=1, - EndOfFrame=2, - EndOfLoop=3, - EndOfMovie=4, - SpeedChanged=5 }; - void connectStatus(TQObject* receiver, const char *member); - void disconnectStatus(TQObject* receiver, const char *member=0); - -private: - TQMoviePrivate *d; -}; - -#endif // TQT_NO_MOVIE - -#endif diff --git a/src/kernel/ntqnamespace.h b/src/kernel/ntqnamespace.h index 6feb7578c..b056c8363 100644 --- a/src/kernel/ntqnamespace.h +++ b/src/kernel/ntqnamespace.h @@ -106,7 +106,7 @@ public: // the following four enums can be combined to one integer which // is passed as textflag to drawText and qt_format_text. - // documented in qpainter.cpp + // documented in tqpainter.cpp enum AlignmentFlags { AlignAuto = 0x0000, // text alignment AlignLeft = 0x0001, @@ -121,7 +121,7 @@ public: AlignCenter = AlignVCenter | AlignHCenter }; - // documented in qpainter.cpp + // documented in tqpainter.cpp enum TextFlags { SingleLine = 0x0080, // misc. flags DontClip = 0x0100, @@ -299,14 +299,14 @@ public: AvoidDither = 0x00000080 }; - // documented in qpainter.cpp + // documented in tqpainter.cpp enum BGMode { // background mode TransparentMode, OpaqueMode }; #ifndef TQT_NO_COMPAT - // documented in qpainter.cpp + // documented in tqpainter.cpp enum PaintUnit { // paint unit PixelUnit, LoMetricUnit, // OBSOLETE @@ -746,7 +746,7 @@ public: RightArrow }; - // documented in qpainter.cpp + // documented in tqpainter.cpp enum RasterOp { // raster op mode CopyROP, OrROP, @@ -766,7 +766,7 @@ public: NorROP, LastROP=NorROP }; - // documented in qpainter.cpp + // documented in tqpainter.cpp enum PenStyle { // pen style NoPen, SolidLine, @@ -778,7 +778,7 @@ public: MPenStyle = 0x0f }; - // documented in qpainter.cpp + // documented in tqpainter.cpp enum PenCapStyle { // line endcap style FlatCap = 0x00, SquareCap = 0x10, @@ -786,7 +786,7 @@ public: MPenCapStyle = 0x30 }; - // documented in qpainter.cpp + // documented in tqpainter.cpp enum PenJoinStyle { // line join style MiterJoin = 0x00, BevelJoin = 0x40, @@ -794,7 +794,7 @@ public: MPenJoinStyle = 0xc0 }; - // documented in qpainter.cpp + // documented in tqpainter.cpp enum BrushStyle { // brush style NoBrush, SolidPattern, diff --git a/src/kernel/ntqpaintdevice.h b/src/kernel/ntqpaintdevice.h deleted file mode 100644 index 2b9cd421f..000000000 --- a/src/kernel/ntqpaintdevice.h +++ /dev/null @@ -1,407 +0,0 @@ -/**************************************************************************** -** -** Definition of TQPaintDevice class -** -** Created : 940721 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#ifndef TQPAINTDEVICE_H -#define TQPAINTDEVICE_H - -#ifndef QT_H -#include "ntqwindowdefs.h" -#include "ntqrect.h" -#endif // QT_H - -class TQIODevice; -class TQString; -class TQTextItem; - - -#if defined(TQ_WS_X11) -struct TQPaintDeviceX11Data; -#endif - -union TQPDevCmdParam { - int ival; - int *ivec; - TQString *str; - const TQPoint *point; - const TQRect *rect; - const TQPointArray *ptarr; - const TQPixmap *pixmap; - const TQImage *image; - const TQColor *color; - const TQFont *font; - const TQPen *pen; - const TQBrush *brush; - const TQRegion *rgn; - const TQWMatrix *matrix; - const TQTextItem *textItem; - TQIODevice *device; -}; - - - -class TQ_EXPORT TQPaintDevice // device for TQPainter -{ -public: - virtual ~TQPaintDevice(); - - int devType() const; - bool isExtDev() const; - bool paintingActive() const; - - virtual void setResolution( int ); - virtual int resolution() const; - - // Windows: get device context - // X-Windows: get drawable -#if defined(TQ_WS_WIN) - virtual HDC handle() const; -#elif defined(TQ_WS_X11) - virtual TQt::HANDLE handle() const; - virtual TQt::HANDLE x11RenderHandle() const; -#elif defined(TQ_WS_MAC) - virtual TQt::HANDLE handle() const; -#endif - -#if defined(TQ_WS_X11) - Display *x11Display() const; - int x11Screen() const; - int x11Depth() const; - int x11Cells() const; - TQt::HANDLE x11Colormap() const; - bool x11DefaultColormap() const; - void *x11Visual() const; - bool x11DefaultVisual() const; - - static Display *x11AppDisplay(); - static int x11AppScreen(); - - static int x11AppDpiX(); - static int x11AppDpiY(); - static void x11SetAppDpiX(int); - static void x11SetAppDpiY(int); - static int x11AppDepth(); - static int x11AppCells(); - static TQt::HANDLE x11AppRootWindow(); - static TQt::HANDLE x11AppColormap(); - static bool x11AppDefaultColormap(); - static void *x11AppVisual(); - static bool x11AppDefaultVisual(); - - // ### in 4.0, the above need to go away, the below needs to take a -1 default - // argument, signifying the default screen... - static int x11AppDepth( int screen ); - static int x11AppCells( int screen ); - static TQt::HANDLE x11AppRootWindow( int screen ); - static TQt::HANDLE x11AppColormap( int screen ); - static void *x11AppVisual( int screen ); - static bool x11AppDefaultColormap( int screen ); - static bool x11AppDefaultVisual( int screen ); - static int x11AppDpiX( int ); - static int x11AppDpiY( int ); - static void x11SetAppDpiX( int, int ); - static void x11SetAppDpiY( int, int ); -#endif - - enum PDevCmd { - PdcNOP = 0, // - PdcDrawPoint = 1, // point - PdcDrawFirst = PdcDrawPoint, - PdcMoveTo = 2, // point - PdcLineTo = 3, // point - PdcDrawLine = 4, // point,point - PdcDrawRect = 5, // rect - PdcDrawRoundRect = 6, // rect,ival,ival - PdcDrawEllipse = 7, // rect - PdcDrawArc = 8, // rect,ival,ival - PdcDrawPie = 9, // rect,ival,ival - PdcDrawChord = 10, // rect,ival,ival - PdcDrawLineSegments = 11, // ptarr - PdcDrawPolyline = 12, // ptarr - PdcDrawPolygon = 13, // ptarr,ival - PdcDrawCubicBezier = 14, // ptarr - PdcDrawText = 15, // point,str - PdcDrawTextFormatted = 16, // rect,ival,str - PdcDrawPixmap = 17, // rect,pixmap - PdcDrawImage = 18, // rect,image - PdcDrawText2 = 19, // point,str - PdcDrawText2Formatted = 20, // rect,ival,str - PdcDrawTextItem = 21, - PdcDrawLast = PdcDrawTextItem, - - // no painting commands below PdcDrawLast. - - PdcBegin = 30, // - PdcEnd = 31, // - PdcSave = 32, // - PdcRestore = 33, // - PdcSetdev = 34, // device - PRIVATE - PdcSetBkColor = 40, // color - PdcSetBkMode = 41, // ival - PdcSetROP = 42, // ival - PdcSetBrushOrigin = 43, // point - PdcSetFont = 45, // font - PdcSetPen = 46, // pen - PdcSetBrush = 47, // brush - PdcSetTabStops = 48, // ival - PdcSetTabArray = 49, // ival,ivec - PdcSetUnit = 50, // ival - PdcSetVXform = 51, // ival - PdcSetWindow = 52, // rect - PdcSetViewport = 53, // rect - PdcSetWXform = 54, // ival - PdcSetWMatrix = 55, // matrix,ival - PdcSaveWMatrix = 56, - PdcRestoreWMatrix = 57, - PdcSetClip = 60, // ival - PdcSetClipRegion = 61, // rgn,cmode - PdcFlush = 62, // - PdcFlushRegion = 63, // rgn,cmode - - PdcReservedStart = 0, // codes 0-199 are reserved - PdcReservedStop = 199 // for TQt - }; - -protected: - TQPaintDevice( uint devflags ); - -#if defined(TQ_WS_WIN) - HDC hdc; // device context -#elif defined(TQ_WS_X11) - TQt::HANDLE hd; // handle to drawable - TQt::HANDLE rendhd; // handle to RENDER pict - - void copyX11Data( const TQPaintDevice * ); - void cloneX11Data( const TQPaintDevice * ); - virtual void setX11Data( const TQPaintDeviceX11Data* ); - TQPaintDeviceX11Data* getX11Data( bool def=FALSE ) const; -#elif defined(TQ_WS_MAC) -#if !defined( TQMAC_NO_QUARTZ ) - CGContextRef ctx; -#endif - void * hd; -#endif - - virtual bool cmd( int, TQPainter *, TQPDevCmdParam * ); - virtual int metric( int ) const; - virtual int fontMet( TQFont *, int, const char * = 0, int = 0 ) const; - virtual int fontInf( TQFont *, int ) const; - - ushort devFlags; // device flags - ushort painters; // refcount - - friend class TQPainter; - friend class TQPaintDeviceMetrics; -#if defined(TQ_WS_MAC) -#ifndef TQMAC_NO_QUARTZ - virtual CGContextRef macCGContext(bool clipped=TRUE) const; -#endif - friend TQ_EXPORT void unclippedScaledBitBlt( TQPaintDevice *, int, int, int, int, - const TQPaintDevice *, int, int, int, int, TQt::RasterOp, bool, bool ); -#else - friend TQ_EXPORT void bitBlt( TQPaintDevice *, int, int, - const TQPaintDevice *, - int, int, int, int, TQt::RasterOp, bool ); -#endif -#if defined(TQ_WS_X11) - friend void tqt_init_internal( int *, char **, Display *, TQt::HANDLE, TQt::HANDLE ); - friend void tqt_cleanup(); -#endif - -private: -#if defined(TQ_WS_X11) - static Display *x_appdisplay; - static int x_appscreen; - - static int x_appdepth; - static int x_appcells; - static TQt::HANDLE x_approotwindow; - static TQt::HANDLE x_appcolormap; - static bool x_appdefcolormap; - static void *x_appvisual; - static bool x_appdefvisual; - - // ### in 4.0, remove the above, and replace with the below - static int *x_appdepth_arr; - static int *x_appcells_arr; - static TQt::HANDLE *x_approotwindow_arr; - static TQt::HANDLE *x_appcolormap_arr; - static bool *x_appdefcolormap_arr; - static void **x_appvisual_arr; - static bool *x_appdefvisual_arr; - - TQPaintDeviceX11Data* x11Data; -#endif - -private: // Disabled copy constructor and operator= -#if defined(TQ_DISABLE_COPY) - TQPaintDevice( const TQPaintDevice & ); - TQPaintDevice &operator=( const TQPaintDevice & ); -#endif -}; - - -TQ_EXPORT -void bitBlt( TQPaintDevice *dst, int dx, int dy, - const TQPaintDevice *src, int sx=0, int sy=0, int sw=-1, int sh=-1, - TQt::RasterOp = TQt::CopyROP, bool ignoreMask=FALSE ); - -TQ_EXPORT -void bitBlt( TQPaintDevice *dst, int dx, int dy, - const TQImage *src, int sx=0, int sy=0, int sw=-1, int sh=-1, - int conversion_flags=0 ); - - -#if defined(TQ_WS_X11) - -struct TQ_EXPORT TQPaintDeviceX11Data : public TQShared { - Display* x_display; - int x_screen; - int x_depth; - int x_cells; - TQt::HANDLE x_colormap; - bool x_defcolormap; - void* x_visual; - bool x_defvisual; -}; - -#endif - -/***************************************************************************** - Inline functions - *****************************************************************************/ - -inline int TQPaintDevice::devType() const -{ return devFlags & TQInternal::DeviceTypeMask; } - -inline bool TQPaintDevice::isExtDev() const -{ return (devFlags & TQInternal::ExternalDevice) != 0; } - -inline bool TQPaintDevice::paintingActive() const -{ return painters != 0; } - -#if defined(TQ_WS_X11) -inline Display *TQPaintDevice::x11Display() const -{ return x11Data ? x11Data->x_display : x_appdisplay; } - -inline int TQPaintDevice::x11Screen() const -{ return x11Data ? x11Data->x_screen : x_appscreen; } - -inline int TQPaintDevice::x11Depth() const -{ return x11Data ? x11Data->x_depth : x_appdepth; } - -inline int TQPaintDevice::x11Cells() const -{ return x11Data ? x11Data->x_cells : x_appcells; } - -inline TQt::HANDLE TQPaintDevice::x11Colormap() const -{ return x11Data ? x11Data->x_colormap : x_appcolormap; } - -inline bool TQPaintDevice::x11DefaultColormap() const -{ return x11Data ? x11Data->x_defcolormap : x_appdefcolormap; } - -inline void *TQPaintDevice::x11Visual() const -{ return x11Data ? x11Data->x_visual : x_appvisual; } - -inline bool TQPaintDevice::x11DefaultVisual() const -{ return x11Data ? x11Data->x_defvisual : x_appdefvisual; } - -inline Display *TQPaintDevice::x11AppDisplay() -{ return x_appdisplay; } - -inline int TQPaintDevice::x11AppScreen() -{ return x_appscreen; } - -inline int TQPaintDevice::x11AppDepth( int screen ) -{ return x_appdepth_arr[ screen == -1 ? x_appscreen : screen ]; } - -inline int TQPaintDevice::x11AppCells( int screen ) -{ return x_appcells_arr[ screen == -1 ? x_appscreen : screen ]; } - -inline TQt::HANDLE TQPaintDevice::x11AppRootWindow( int screen ) -{ return x_approotwindow_arr[ screen == -1 ? x_appscreen : screen ]; } - -inline TQt::HANDLE TQPaintDevice::x11AppColormap( int screen ) -{ return x_appcolormap_arr[ screen == -1 ? x_appscreen : screen ]; } - -inline bool TQPaintDevice::x11AppDefaultColormap( int screen ) -{ return x_appdefcolormap_arr[ screen == -1 ? x_appscreen : screen ]; } - -inline void *TQPaintDevice::x11AppVisual( int screen ) -{ return x_appvisual_arr[ screen == -1 ? x_appscreen : screen ]; } - -inline bool TQPaintDevice::x11AppDefaultVisual( int screen ) -{ return x_appdefvisual_arr[ screen == -1 ? x_appscreen : screen ]; } - -inline int TQPaintDevice::x11AppDepth() -{ return x_appdepth; } - -inline int TQPaintDevice::x11AppCells() -{ return x_appcells; } - -inline TQt::HANDLE TQPaintDevice::x11AppRootWindow() -{ return x_approotwindow; } - -inline TQt::HANDLE TQPaintDevice::x11AppColormap() -{ return x_appcolormap; } - -inline bool TQPaintDevice::x11AppDefaultColormap() -{ return x_appdefcolormap; } - -inline void *TQPaintDevice::x11AppVisual() -{ return x_appvisual; } - -inline bool TQPaintDevice::x11AppDefaultVisual() -{ return x_appdefvisual; } - -#endif // TQ_WS_X11 - - -TQ_EXPORT -inline void bitBlt( TQPaintDevice *dst, const TQPoint &dp, - const TQPaintDevice *src, const TQRect &sr =TQRect(0,0,-1,-1), - TQt::RasterOp rop=TQt::CopyROP, bool ignoreMask=FALSE ) -{ - bitBlt( dst, dp.x(), dp.y(), src, sr.x(), sr.y(), sr.width(), sr.height(), - rop, ignoreMask ); -} - - - - -#endif // TQPAINTDEVICE_H diff --git a/src/kernel/ntqpaintdevicemetrics.h b/src/kernel/ntqpaintdevicemetrics.h deleted file mode 100644 index 1db8ad7df..000000000 --- a/src/kernel/ntqpaintdevicemetrics.h +++ /dev/null @@ -1,83 +0,0 @@ -/**************************************************************************** -** -** Definition of TQPaintDeviceMetrics class -** -** Created : 941109 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#ifndef TQPAINTDEVICEMETRICS_H -#define TQPAINTDEVICEMETRICS_H - -#ifndef QT_H -#include "ntqpaintdevice.h" -#endif // QT_H - - -class TQ_EXPORT TQPaintDeviceMetrics // paint device metrics -{ -public: - TQPaintDeviceMetrics( const TQPaintDevice * ); - - enum { - PdmWidth = 1, - PdmHeight, - PdmWidthMM, - PdmHeightMM, - PdmNumColors, - PdmDepth, - PdmDpiX, - PdmDpiY, - PdmPhysicalDpiX, - PdmPhysicalDpiY - }; - - int width() const { return (int)pdev->metric(PdmWidth); } - int height() const { return (int)pdev->metric(PdmHeight); } - int widthMM() const { return (int)pdev->metric(PdmWidthMM); } - int heightMM() const { return (int)pdev->metric(PdmHeightMM); } - int logicalDpiX() const { return (int)pdev->metric(PdmDpiX); } - int logicalDpiY() const { return (int)pdev->metric(PdmDpiY); } - int physicalDpiX()const { return (int)pdev->metric(PdmPhysicalDpiX); } - int physicalDpiY()const { return (int)pdev->metric(PdmPhysicalDpiY); } - int numColors() const { return (int)pdev->metric(PdmNumColors); } - int depth() const { return (int)pdev->metric(PdmDepth); } - -private: - TQPaintDevice *pdev; -}; - - -#endif // TQPAINTDEVICEMETRICS_H diff --git a/src/kernel/ntqpainter.h b/src/kernel/ntqpainter.h deleted file mode 100644 index fb73ada58..000000000 --- a/src/kernel/ntqpainter.h +++ /dev/null @@ -1,698 +0,0 @@ -/**************************************************************************** -** -** Definition of TQPainter class -** -** Created : 940112 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#ifndef TQPAINTER_H -#define TQPAINTER_H - - -#ifndef QT_H -#include "ntqcolor.h" -#include "ntqfontmetrics.h" -#include "ntqfontinfo.h" -#include "ntqregion.h" -#include "ntqpen.h" -#include "ntqbrush.h" -#include "ntqpointarray.h" -#include "ntqwmatrix.h" -#endif // QT_H - -class TQTextCodec; -class TQTextParag; -class TQPaintDevice; -class TQTextItem; -#if defined( TQ_WS_MAC ) -class TQMacSavedPortInfo; -#endif -class TQPainterPrivate; - -class TQ_EXPORT TQPainter : public TQt -{ -public: - enum CoordinateMode { CoordDevice, CoordPainter }; - - TQPainter(); - TQPainter( const TQPaintDevice *, bool unclipped = FALSE ); - TQPainter( const TQPaintDevice *, const TQWidget *, bool unclipped = FALSE ); - ~TQPainter(); - - bool begin( const TQPaintDevice *, bool unclipped = FALSE ); - bool begin( const TQPaintDevice *, const TQWidget *, bool unclipped = FALSE ); - bool end(); - TQPaintDevice *device() const; - - static void redirect( TQPaintDevice *pdev, TQPaintDevice *replacement ); - static TQPaintDevice *redirect( TQPaintDevice *pdev ); - - bool isActive() const; - - void flush( const TQRegion ®ion, CoordinateMode cm = CoordDevice ); - void flush(); - void save(); - void restore(); - - // Drawing tools - - TQFontMetrics fontMetrics() const; - TQFontInfo fontInfo() const; - - const TQFont &font() const; - void setFont( const TQFont & ); - const TQPen &pen() const; - void setPen( const TQPen & ); - void setPen( PenStyle ); - void setPen( const TQColor & ); - const TQBrush &brush() const; - void setBrush( const TQBrush & ); - void setBrush( BrushStyle ); - void setBrush( const TQColor & ); - TQPoint pos() const; - - // Drawing attributes/modes - - const TQColor &backgroundColor() const; - void setBackgroundColor( const TQColor & ); - BGMode backgroundMode() const; - void setBackgroundMode( BGMode ); - RasterOp rasterOp() const; - void setRasterOp( RasterOp ); - const TQPoint &brushOrigin() const; - void setBrushOrigin( int x, int y ); - void setBrushOrigin( const TQPoint & ); - - // Scaling and transformations - -// PaintUnit unit() const; // get set painter unit -// void setUnit( PaintUnit ); // NOT IMPLEMENTED!!! - - bool hasViewXForm() const; - bool hasWorldXForm() const; - -#ifndef TQT_NO_TRANSFORMATIONS - void setViewXForm( bool ); // set xform on/off - TQRect window() const; // get window - void setWindow( const TQRect & ); // set window - void setWindow( int x, int y, int w, int h ); - TQRect viewport() const; // get viewport - void setViewport( const TQRect & ); // set viewport - void setViewport( int x, int y, int w, int h ); - - void setWorldXForm( bool ); // set world xform on/off - const TQWMatrix &worldMatrix() const; // get/set world xform matrix - void setWorldMatrix( const TQWMatrix &, bool combine=FALSE ); - - void saveWorldMatrix(); - void restoreWorldMatrix(); - - void scale( double sx, double sy ); - void shear( double sh, double sv ); - void rotate( double a ); -#endif - void translate( double dx, double dy ); - void resetXForm(); - double translationX() const; - double translationY() const; - - TQPoint xForm( const TQPoint & ) const; // map virtual -> device - TQRect xForm( const TQRect & ) const; - TQPointArray xForm( const TQPointArray & ) const; - TQPointArray xForm( const TQPointArray &, int index, int npoints ) const; - TQPoint xFormDev( const TQPoint & ) const; // map device -> virtual - TQRect xFormDev( const TQRect & ) const; - TQPointArray xFormDev( const TQPointArray & ) const; - TQPointArray xFormDev( const TQPointArray &, int index, int npoints ) const; - - // Clipping - - void setClipping( bool ); // set clipping on/off - bool hasClipping() const; - TQRegion clipRegion( CoordinateMode = CoordDevice ) const; - void setClipRect( const TQRect &, CoordinateMode = CoordDevice ); // set clip rectangle - void setClipRect( int x, int y, int w, int h, CoordinateMode = CoordDevice ); - void setClipRegion( const TQRegion &, CoordinateMode = CoordDevice );// set clip region - - // Graphics drawing functions - - void drawPoint( int x, int y ); - void drawPoint( const TQPoint & ); - void drawPoints( const TQPointArray& a, - int index=0, int npoints=-1 ); - void moveTo( int x, int y ); - void moveTo( const TQPoint & ); - void lineTo( int x, int y ); - void lineTo( const TQPoint & ); - void drawLine( int x1, int y1, int x2, int y2 ); - void drawLine( const TQPoint &, const TQPoint & ); - void drawRect( int x, int y, int w, int h ); - void drawRect( const TQRect & ); - void drawWinFocusRect( int x, int y, int w, int h ); - void drawWinFocusRect( int x, int y, int w, int h, - const TQColor &bgColor ); - void drawWinFocusRect( const TQRect & ); - void drawWinFocusRect( const TQRect &, - const TQColor &bgColor ); - void drawRoundRect( int x, int y, int w, int h, int = 25, int = 25 ); - void drawRoundRect( const TQRect &, int = 25, int = 25 ); - void drawEllipse( int x, int y, int w, int h ); - void drawEllipse( const TQRect & ); - void drawArc( int x, int y, int w, int h, int a, int alen ); - void drawArc( const TQRect &, int a, int alen ); - void drawPie( int x, int y, int w, int h, int a, int alen ); - void drawPie( const TQRect &, int a, int alen ); - void drawChord( int x, int y, int w, int h, int a, int alen ); - void drawChord( const TQRect &, int a, int alen ); - void drawLineSegments( const TQPointArray &, - int index=0, int nlines=-1 ); - void drawPolyline( const TQPointArray &, - int index=0, int npoints=-1 ); - void drawPolygon( const TQPointArray &, bool winding=FALSE, - int index=0, int npoints=-1 ); - void drawConvexPolygon( const TQPointArray &, - int index=0, int npoints=-1 ); -#ifndef TQT_NO_BEZIER - void drawCubicBezier( const TQPointArray &, int index=0 ); -#endif - void drawPixmap( int x, int y, const TQPixmap &, - int sx=0, int sy=0, int sw=-1, int sh=-1 ); - void drawPixmap( const TQPoint &, const TQPixmap &, - const TQRect &sr ); - void drawPixmap( const TQPoint &, const TQPixmap & ); - void drawPixmap( const TQRect &, const TQPixmap & ); - void drawImage( int x, int y, const TQImage &, - int sx = 0, int sy = 0, int sw = -1, int sh = -1, - int conversionFlags = 0 ); - void drawImage( const TQPoint &, const TQImage &, - const TQRect &sr, int conversionFlags = 0 ); - void drawImage( const TQPoint &, const TQImage &, - int conversion_flags = 0 ); - void drawImage( const TQRect &, const TQImage & ); - void drawTiledPixmap( int x, int y, int w, int h, const TQPixmap &, - int sx=0, int sy=0 ); - void drawTiledPixmap( const TQRect &, const TQPixmap &, - const TQPoint & ); - void drawTiledPixmap( const TQRect &, const TQPixmap & ); -#ifndef TQT_NO_PICTURE - void drawPicture( const TQPicture & ); - void drawPicture( int x, int y, const TQPicture & ); - void drawPicture( const TQPoint &, const TQPicture & ); -#endif - - void fillRect( int x, int y, int w, int h, const TQBrush & ); - void fillRect( const TQRect &, const TQBrush & ); - void eraseRect( int x, int y, int w, int h ); - void eraseRect( const TQRect & ); - - // Text drawing functions - - enum TextDirection { - Auto, - RTL, - LTR - }; - - void drawText( int x, int y, const TQString &, int len = -1, TextDirection dir = Auto ); - void drawText( const TQPoint &, const TQString &, int len = -1, TextDirection dir = Auto ); - - void drawText( int x, int y, const TQString &, int pos, int len, TextDirection dir = Auto ); - void drawText( const TQPoint &p, const TQString &, int pos, int len, TextDirection dir = Auto ); - - void drawText( int x, int y, int w, int h, int flags, - const TQString&, int len = -1, TQRect *br=0, - TQTextParag **intern=0 ); - void drawText( const TQRect &, int flags, - const TQString&, int len = -1, TQRect *br=0, - TQTextParag **intern=0 ); - - void drawTextItem( int x, int y, const TQTextItem &ti, int textflags = 0 ); - void drawTextItem( const TQPoint& p, const TQTextItem &ti, int textflags = 0 ); - - TQRect boundingRect( int x, int y, int w, int h, int flags, - const TQString&, int len = -1, TQTextParag **intern=0 ); - TQRect boundingRect( const TQRect &, int flags, - const TQString&, int len = -1, TQTextParag **intern=0 ); - - int tabStops() const; - void setTabStops( int ); - int *tabArray() const; - void setTabArray( int * ); - - // Other functions - -#if defined(TQ_WS_WIN) - HDC handle() const; -#elif defined(TQ_WS_X11) || defined(TQ_WS_MAC) - HANDLE handle() const; -#endif - - - static void initialize(); - static void cleanup(); - -private: - void init(); - void destroy(); - void updateFont(); - void updatePen(); - void updateBrush(); -#ifndef TQT_NO_TRANSFORMATIONS - void updateXForm(); - void updateInvXForm(); -#endif - void map( int, int, int *rx, int *ry ) const; - void map( int, int, int, int, int *, int *, int *, int * ) const; - void mapInv( int, int, int *, int * ) const; - void mapInv( int, int, int, int, int *, int *, int *, int * ) const; - void drawPolyInternal( const TQPointArray &, bool close=TRUE ); - void drawWinFocusRect( int x, int y, int w, int h, bool xorPaint, - const TQColor &penColor ); - - enum { IsActive=0x01, ExtDev=0x02, IsStartingUp=0x04, NoCache=0x08, - VxF=0x10, WxF=0x20, ClipOn=0x40, SafePolygon=0x80, MonoDev=0x100, - DirtyFont=0x200, DirtyPen=0x400, DirtyBrush=0x800, - RGBColor=0x1000, FontMet=0x2000, FontInf=0x4000, CtorBegin=0x8000, - UsePrivateCx = 0x10000, VolatileDC = 0x20000, TQt2Compat = 0x40000 }; - uint flags; - bool testf( uint b ) const { return (flags&b)!=0; } - void setf( uint b ) { flags |= b; } - void setf( uint b, bool v ); - void clearf( uint b ) { flags &= (uint)(~b); } - void fix_neg_rect( int *x, int *y, int *w, int *h ); - - TQPainterPrivate *d; - TQPaintDevice *pdev; - TQColor bg_col; - uchar bg_mode; - uchar rop; - uchar pu; - TQPoint bro; - TQFont cfont; - TQFont *pfont; // font used for metrics (might be different for printers) - TQPen cpen; - TQBrush cbrush; - TQRegion crgn; - int tabstops; - int *tabarray; - int tabarraylen; - bool block_ext; // for temporary blocking of external devices - - // Transformations -#ifndef TQT_NO_TRANSFORMATIONS - TQCOORD wx, wy, ww, wh; - TQCOORD vx, vy, vw, vh; - TQWMatrix wxmat; - - // Cached composition (and inverse) of transformations - TQWMatrix xmat; - TQWMatrix ixmat; - - - - double m11() const { return xmat.m11(); } - double m12() const { return xmat.m12(); } - double m21() const { return xmat.m21(); } - double m22() const { return xmat.m22(); } - double dx() const { return xmat.dx(); } - double dy() const { return xmat.dy(); } - double im11() const { return ixmat.m11(); } - double im12() const { return ixmat.m12(); } - double im21() const { return ixmat.m21(); } - double im22() const { return ixmat.m22(); } - double idx() const { return ixmat.dx(); } - double idy() const { return ixmat.dy(); } - - int txop; - bool txinv; - -#else - // even without transformations we still have translations - int xlatex; - int xlatey; -#endif - - void *penRef; // pen cache ref - void *brushRef; // brush cache ref - void *ps_stack; - void *wm_stack; - void killPStack(); - -protected: -#ifdef Q_OS_TEMP - TQPoint internalCurrentPos; - uint old_pix; // ### All win platforms in 4.0 -#endif -#if defined(TQ_WS_WIN) - friend class TQFontEngineWin; - friend class TQFontEngineBox; - QT_WIN_PAINTER_MEMBERS -#elif defined(TQ_WS_X11) - friend class TQFontEngineXLFD; - friend class TQFontEngineXft; - friend class TQFontEngineBox; - Display *dpy; // current display - int scrn; // current screen - TQt::HANDLE hd; // handle to drawable - TQt::HANDLE rendhd; // handle to Xft draw - GC gc; // graphics context (standard) - GC gc_brush; // graphics contect for brush - TQPoint curPt; // current point - uint clip_serial; // clipping serial number -#elif defined(TQ_WS_MAC) - TQt::HANDLE hd; // handle to drawable - void initPaintDevice(bool force=FALSE, TQPoint *off=NULL, TQRegion *rgn=NULL); - friend const TQRegion &qt_mac_update_painter(TQPainter *, bool); - friend class TQFontEngineMac; - friend class TQMacPainter; -#endif - friend class TQFontMetrics; - friend class TQFontInfo; - friend class TQTextLayout; - friend void qt_format_text( const TQFont &, const TQRect &r, - int tf, const TQString& str, int len, TQRect *brect, - int tabstops, int* tabarray, int tabarraylen, - TQTextParag **internal, TQPainter* painter ); - friend void qt_draw_background( TQPainter *p, int x, int y, int w, int h ); - friend void qt_draw_transformed_rect( TQPainter *p, int x, int y, int w, int h, bool fill ); - friend class TQPrinter; - -private: // Disabled copy constructor and operator= -#if defined(TQ_DISABLE_COPY) - TQPainter( const TQPainter & ); - TQPainter &operator=( const TQPainter & ); -#endif - - enum TransformationCodes { - TxNone = 0, // transformation codes - TxTranslate = 1, // copy in qpainter_*.cpp - TxScale = 2, - TxRotShear = 3 - }; -}; - - -/***************************************************************************** - TQPainter member functions - *****************************************************************************/ - -inline TQPaintDevice *TQPainter::device() const -{ - return pdev; -} - -inline bool TQPainter::isActive() const -{ - return testf(IsActive); -} - -inline const TQFont &TQPainter::font() const -{ - return cfont; -} - -inline const TQPen &TQPainter::pen() const -{ - return cpen; -} - -inline const TQBrush &TQPainter::brush() const -{ - return cbrush; -} - -/* -inline PaintUnit TQPainter::unit() const -{ - return (PaintUnit)pu; -} -*/ - -inline const TQColor &TQPainter::backgroundColor() const -{ - return bg_col; -} - -inline TQt::BGMode TQPainter::backgroundMode() const -{ - return (BGMode)bg_mode; -} - -inline TQt::RasterOp TQPainter::rasterOp() const -{ - return (RasterOp)rop; -} - -inline const TQPoint &TQPainter::brushOrigin() const -{ - return bro; -} - -inline bool TQPainter::hasViewXForm() const -{ -#ifndef TQT_NO_TRANSFORMATIONS - return testf(VxF); -#else - return xlatex || xlatey; -#endif -} - -inline bool TQPainter::hasWorldXForm() const -{ -#ifndef TQT_NO_TRANSFORMATIONS - return testf(WxF); -#else - return xlatex || xlatey; -#endif -} - -inline double TQPainter::translationX() const -{ -#ifndef TQT_NO_TRANSFORMATIONS - return worldMatrix().dx(); -#else - return xlatex; -#endif -} - -inline double TQPainter::translationY() const -{ -#ifndef TQT_NO_TRANSFORMATIONS - return worldMatrix().dy(); -#else - return xlatey; -#endif -} - - -inline bool TQPainter::hasClipping() const -{ - return testf(ClipOn); -} - -inline int TQPainter::tabStops() const -{ - return tabstops; -} - -inline int *TQPainter::tabArray() const -{ - return tabarray; -} - -#if defined(TQ_WS_WIN) -inline HDC TQPainter::handle() const -{ - return hdc; -} -#elif defined(TQ_WS_X11) || defined(TQ_WS_MAC) -inline TQt::HANDLE TQPainter::handle() const -{ - return hd; -} -#endif - -inline void TQPainter::setBrushOrigin( const TQPoint &p ) -{ - setBrushOrigin( p.x(), p.y() ); -} - -#ifndef TQT_NO_TRANSFORMATIONS -inline void TQPainter::setWindow( const TQRect &r ) -{ - setWindow( r.x(), r.y(), r.width(), r.height() ); -} - -inline void TQPainter::setViewport( const TQRect &r ) -{ - setViewport( r.x(), r.y(), r.width(), r.height() ); -} -#endif - -inline void TQPainter::setClipRect( int x, int y, int w, int h, CoordinateMode m ) -{ - setClipRect( TQRect(x,y,w,h), m ); -} - -inline void TQPainter::drawPoint( const TQPoint &p ) -{ - drawPoint( p.x(), p.y() ); -} - -inline void TQPainter::moveTo( const TQPoint &p ) -{ - moveTo( p.x(), p.y() ); -} - -inline void TQPainter::lineTo( const TQPoint &p ) -{ - lineTo( p.x(), p.y() ); -} - -inline void TQPainter::drawLine( const TQPoint &p1, const TQPoint &p2 ) -{ - drawLine( p1.x(), p1.y(), p2.x(), p2.y() ); -} - -inline void TQPainter::drawRect( const TQRect &r ) -{ - drawRect( r.x(), r.y(), r.width(), r.height() ); -} - -inline void TQPainter::drawWinFocusRect( const TQRect &r ) -{ - drawWinFocusRect( r.x(), r.y(), r.width(), r.height() ); -} - -inline void TQPainter::drawWinFocusRect( const TQRect &r,const TQColor &penColor ) -{ - drawWinFocusRect( r.x(), r.y(), r.width(), r.height(), penColor ); -} - -inline void TQPainter::drawRoundRect( const TQRect &r, int xRnd, int yRnd ) -{ - drawRoundRect( r.x(), r.y(), r.width(), r.height(), xRnd, yRnd ); -} - -inline void TQPainter::drawEllipse( const TQRect &r ) -{ - drawEllipse( r.x(), r.y(), r.width(), r.height() ); -} - -inline void TQPainter::drawArc( const TQRect &r, int a, int alen ) -{ - drawArc( r.x(), r.y(), r.width(), r.height(), a, alen ); -} - -inline void TQPainter::drawPie( const TQRect &r, int a, int alen ) -{ - drawPie( r.x(), r.y(), r.width(), r.height(), a, alen ); -} - -inline void TQPainter::drawChord( const TQRect &r, int a, int alen ) -{ - drawChord( r.x(), r.y(), r.width(), r.height(), a, alen ); -} - -inline void TQPainter::drawPixmap( const TQPoint &p, const TQPixmap &pm, - const TQRect &sr ) -{ - drawPixmap( p.x(), p.y(), pm, sr.x(), sr.y(), sr.width(), sr.height() ); -} - -inline void TQPainter::drawImage( const TQPoint &p, const TQImage &pm, - const TQRect &sr, int conversionFlags ) -{ - drawImage( p.x(), p.y(), pm, - sr.x(), sr.y(), sr.width(), sr.height(), conversionFlags ); -} - -inline void TQPainter::drawTiledPixmap( const TQRect &r, const TQPixmap &pm, - const TQPoint &sp ) -{ - drawTiledPixmap( r.x(), r.y(), r.width(), r.height(), pm, sp.x(), sp.y() ); -} - -inline void TQPainter::drawTiledPixmap( const TQRect &r, const TQPixmap &pm ) -{ - drawTiledPixmap( r.x(), r.y(), r.width(), r.height(), pm, 0, 0 ); -} - -inline void TQPainter::fillRect( const TQRect &r, const TQBrush &brush ) -{ - fillRect( r.x(), r.y(), r.width(), r.height(), brush ); -} - -inline void TQPainter::eraseRect( int x, int y, int w, int h ) -{ - fillRect( x, y, w, h, backgroundColor() ); -} - -inline void TQPainter::eraseRect( const TQRect &r ) -{ - fillRect( r.x(), r.y(), r.width(), r.height(), backgroundColor() ); -} - -inline void TQPainter::drawText( const TQPoint &p, const TQString &s, int len, TextDirection dir ) -{ - drawText( p.x(), p.y(), s, 0, len, dir ); -} - -inline void TQPainter::drawText( const TQPoint &p, const TQString &s, int pos, int len, TextDirection dir ) -{ - drawText( p.x(), p.y(), s, pos, len, dir ); -} - -inline void TQPainter::drawText( int x, int y, int w, int h, int tf, - const TQString& str, int len, TQRect *br, TQTextParag **i ) -{ - TQRect r(x, y, w, h); - drawText( r, tf, str, len, br, i ); -} - -inline void TQPainter::drawTextItem( const TQPoint& p, const TQTextItem &ti, int textflags ) -{ - drawTextItem( p.x(), p.y(), ti, textflags ); -} - -inline TQRect TQPainter::boundingRect( int x, int y, int w, int h, int tf, - const TQString& str, int len, TQTextParag **i ) -{ - TQRect r(x, y, w, h); - return boundingRect( r, tf, str, len, i ); -} - -#endif // TQPAINTER_H diff --git a/src/kernel/ntqpalette.h b/src/kernel/ntqpalette.h index ba673085f..9f0ca13f0 100644 --- a/src/kernel/ntqpalette.h +++ b/src/kernel/ntqpalette.h @@ -43,9 +43,9 @@ #ifndef QT_H #include "ntqwindowdefs.h" -#include "ntqcolor.h" +#include "tqcolor.h" #include "ntqshared.h" -#include "ntqbrush.h" // TQColor->TQBrush conversion +#include "tqbrush.h" // TQColor->TQBrush conversion #endif // QT_H #ifndef TQT_NO_PALETTE diff --git a/src/kernel/ntqpen.h b/src/kernel/ntqpen.h index 226ff1cf2..3a0a0f8d0 100644 --- a/src/kernel/ntqpen.h +++ b/src/kernel/ntqpen.h @@ -42,7 +42,7 @@ #define TQPEN_H #ifndef QT_H -#include "ntqcolor.h" +#include "tqcolor.h" #include "ntqshared.h" #endif // QT_H diff --git a/src/kernel/ntqpicture.h b/src/kernel/ntqpicture.h index 3ef2867e9..28512b61f 100644 --- a/src/kernel/ntqpicture.h +++ b/src/kernel/ntqpicture.h @@ -42,7 +42,7 @@ #define TQPICTURE_H #ifndef QT_H -#include "ntqpaintdevice.h" +#include "tqpaintdevice.h" #include "tqbuffer.h" #endif // QT_H diff --git a/src/kernel/ntqpixmap.h b/src/kernel/ntqpixmap.h index 0e0e14c4b..70609d4a7 100644 --- a/src/kernel/ntqpixmap.h +++ b/src/kernel/ntqpixmap.h @@ -42,8 +42,8 @@ #define TQPIXMAP_H #ifndef QT_H -#include "ntqpaintdevice.h" -#include "ntqcolor.h" // char*->TQColor conversion +#include "tqpaintdevice.h" +#include "tqcolor.h" // char*->TQColor conversion #include "tqstring.h" // char*->TQString conversion #include "ntqnamespace.h" #endif // QT_H diff --git a/src/kernel/ntqprinter.h b/src/kernel/ntqprinter.h index 5ec2e179c..de561901a 100644 --- a/src/kernel/ntqprinter.h +++ b/src/kernel/ntqprinter.h @@ -42,7 +42,7 @@ #define TQPRINTER_H #ifndef QT_H -#include "ntqpaintdevice.h" +#include "tqpaintdevice.h" #include "tqstring.h" #include "tqstringlist.h" #endif // QT_H diff --git a/src/kernel/ntqt.h b/src/kernel/ntqt.h index 5c9058a14..ae3c2820d 100644 --- a/src/kernel/ntqt.h +++ b/src/kernel/ntqt.h @@ -31,13 +31,13 @@ #include "ntqkeysequence.h" #include "ntqwindowdefs.h" #include "ntqgdict.h" -#include "ntqfont.h" +#include "tqfont.h" #include "tqdatastream.h" #include "tqpair.h" #include "ntqpoint.h" #include #include "tqtextstream.h" -#include "ntqfontinfo.h" +#include "tqfontinfo.h" #include "tqsizepolicy.h" #include "ntqtl.h" #include "tqsize.h" @@ -51,17 +51,17 @@ #include "tqdatetime.h" #include "tqmime.h" #include "tqasciidict.h" -#include "ntqpaintdevice.h" -#include "ntqfontmetrics.h" +#include "tqpaintdevice.h" +#include "tqfontmetrics.h" #include "tqdict.h" #include "ntqevent.h" #include "tqhostaddress.h" #include "tqstringlist.h" -#include "ntqcolor.h" +#include "tqcolor.h" #include #include "tqobject.h" #include -#include "ntqbrush.h" +#include "tqbrush.h" #include "ntqpalette.h" #include "tqwidget.h" #include "tqjpunicode.h" @@ -134,7 +134,7 @@ #include "ntqheader.h" #include #include -#include +#include #include "tqptrvector.h" #include "tqmutex.h" #include @@ -144,8 +144,8 @@ #include "tqsqlfield.h" #include #include -#include -#include +#include +#include #include "ntqpointarray.h" #include "tqmenudata.h" #include @@ -184,7 +184,7 @@ #include #include #include -#include +#include #include "tqtimer.h" #include #include @@ -238,7 +238,7 @@ #include #include "tqwaitcondition.h" #include -#include +#include #include #include #include @@ -267,7 +267,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/kernel/qapplication.cpp b/src/kernel/qapplication.cpp index 8f456790c..d37efef76 100644 --- a/src/kernel/qapplication.cpp +++ b/src/kernel/qapplication.cpp @@ -63,7 +63,7 @@ #ifdef TQ_WS_WIN #include "qinputcontext_p.h" #endif -#include "qfontdata_p.h" +#include "tqfontdata_p.h" #if defined(TQT_THREAD_SUPPORT) # include "tqmutex.h" diff --git a/src/kernel/qapplication_p.h b/src/kernel/qapplication_p.h index 6cb61e4ce..08911eae7 100644 --- a/src/kernel/qapplication_p.h +++ b/src/kernel/qapplication_p.h @@ -47,7 +47,7 @@ // ------------- // // This file is not part of the TQt API. It exists for the convenience -// of qapplication_*.cpp, tqwidget*.cpp, qcolor_x11.cpp, tqfiledialog.cpp +// of qapplication_*.cpp, tqwidget*.cpp, tqcolor_x11.cpp, tqfiledialog.cpp // and many other. This header file may change from version to version // without notice, or even be removed. // diff --git a/src/kernel/qapplication_x11.cpp b/src/kernel/qapplication_x11.cpp index 444271514..3c6e43185 100644 --- a/src/kernel/qapplication_x11.cpp +++ b/src/kernel/qapplication_x11.cpp @@ -63,7 +63,7 @@ #include "ntqapplication.h" #include "qapplication_p.h" -#include "qcolor_p.h" +#include "tqcolor_p.h" #include "ntqcursor.h" #include "tqwidget.h" #include "tqwidget_p.h" @@ -71,7 +71,7 @@ #include "tqwidgetlist.h" #include "tqwidgetintdict.h" #include "tqbitarray.h" -#include "ntqpainter.h" +#include "tqpainter.h" #include "ntqpixmapcache.h" #include "tqdatetime.h" #include "tqtextcodec.h" @@ -441,7 +441,7 @@ extern bool qt_check_selection_sentinel(); //def in tqclipboard_x11.cpp static void qt_save_rootinfo(); bool tqt_try_modal( TQWidget *, XEvent * ); -int qt_ncols_option = 216; // used in qcolor_x11.cpp +int qt_ncols_option = 216; // used in tqcolor_x11.cpp int qt_visual_option = -1; bool qt_cmap_option = FALSE; TQWidget *qt_button_down = 0; // widget got last button-down @@ -1648,7 +1648,7 @@ static KeySym qt_x11_keycode_to_keysym(Display *dpy, KeyCode kc) { #include // ### This should be static but it isn't because of the friend declaration -// ### in ntqpaintdevice.h which then should have a static too but can't have +// ### in tqpaintdevice.h which then should have a static too but can't have // ### it because "storage class specifiers invalid in friend function // ### declarations" :-) Ideas anyone? void tqt_init_internal( int *argcptr, char **argv, @@ -2133,7 +2133,7 @@ void tqt_init_internal( int *argcptr, char **argv, #endif #if !defined(TQT_NO_XFTFREETYPE) - // defined in qfont_x11.cpp + // defined in tqfont_x11.cpp extern bool tqt_has_xft; #ifndef QT_XFT2 if (!tqt_use_xrender) diff --git a/src/kernel/qcolor.cpp b/src/kernel/qcolor.cpp deleted file mode 100644 index 8d7a72935..000000000 --- a/src/kernel/qcolor.cpp +++ /dev/null @@ -1,1030 +0,0 @@ -/**************************************************************************** -** -** Implementation of TQColor class -** -** Created : 940112 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#include "ntqcolor.h" -#include "ntqnamespace.h" -#include "tqdatastream.h" - -#include - - -/*! - \class TQColor ntqcolor.h - \brief The TQColor class provides colors based on RGB or HSV values. - - \ingroup images - \ingroup graphics - \ingroup appearance - - A color is normally specified in terms of RGB (red, green and blue) - components, but it is also possible to specify HSV (hue, saturation - and value) or set a color name (the names are copied from from the - X11 color database). - - In addition to the RGB value, a TQColor also has a pixel value and a - validity. The pixel value is used by the underlying window system - to refer to a color. It can be thought of as an index into the - display hardware's color table. - - The validity (isValid()) indicates whether the color is legal at - all. For example, a RGB color with RGB values out of range is - illegal. For performance reasons, TQColor mostly disregards illegal - colors. The result of using an invalid color is unspecified and - will usually be surprising. - - There are 19 predefined TQColor objects: \c white, \c black, \c - red, \c darkRed, \c green, \c darkGreen, \c blue, \c darkBlue, \c - cyan, \c darkCyan, \c magenta, \c darkMagenta, \c yellow, \c - darkYellow, \c gray, \c darkGray, \c lightGray, \c color0 and \c - color1, accessible as members of the TQt namespace (ie. \c TQt::red). - - \img qt-colors.png TQt Colors - - The colors \c color0 (zero pixel value) and \c color1 (non-zero - pixel value) are special colors for drawing in \link TQBitmap - bitmaps\endlink. Painting with \c color0 sets the bitmap bits to 0 - (transparent, i.e. background), and painting with \c color1 sets the - bits to 1 (opaque, i.e. foreground). - - The TQColor class has an efficient, dynamic color allocation - strategy. A color is normally allocated the first time it is used - (lazy allocation), that is, whenever the pixel() function is called. - The following steps are taken to allocate a color. If, at any point, - a suitable color is found then the appropriate pixel value is - returned and the subsequent steps are not taken: - - \list 1 - \i Is the pixel value valid? If it is, just return it; otherwise, - allocate a pixel value. - \i Check an internal hash table to see if we allocated an equal RGB - value earlier. If we did, set the corresponding pixel value for the - color and return it. - \i Try to allocate the RGB value. If we succeed, we get a pixel value - that we save in the internal table with the RGB value. - Return the pixel value. - \i The color could not be allocated. Find the closest matching - color, save it in the internal table, and return it. - \endlist - - A color can be set by passing setNamedColor() an RGB string like - "#112233", or a color name, e.g. "blue". The names are taken from - X11's rgb.txt database but can also be used under Windows. To get - a lighter or darker color use light() and dark() respectively. - Colors can also be set using setRgb() and setHsv(). The color - components can be accessed in one go with rgb() and hsv(), or - individually with red(), green() and blue(). - - Use maxColors() and numBitPlanes() to determine the maximum number - of colors and the number of bit planes supported by the underlying - window system, - - If you need to allocate many colors temporarily, for example in an - image viewer application, enterAllocContext(), leaveAllocContext() and - destroyAllocContext() will prove useful. - - \section1 HSV Colors - - Because many people don't know the HSV color model very well, we'll - cover it briefly here. - - The RGB model is hardware-oriented. Its representation is close to - what most monitors show. In contrast, HSV represents color in a way - more suited to the human perception of color. For example, the - relationships "stronger than", "darker than" and "the opposite of" - are easily expressed in HSV but are much harder to express in RGB. - - HSV, like RGB, has three components: - - \list - - \i H, for hue, is either 0-359 if the color is chromatic (not - gray), or meaningless if it is gray. It represents degrees on the - color wheel familiar to most people. Red is 0 (degrees), green is - 120 and blue is 240. - - \i S, for saturation, is 0-255, and the bigger it is, the - stronger the color is. Grayish colors have saturation near 0; very - strong colors have saturation near 255. - - \i V, for value, is 0-255 and represents lightness or brightness - of the color. 0 is black; 255 is as far from black as possible. - - \endlist - - Here are some examples: Pure red is H=0, S=255, V=255. A dark red, - moving slightly towards the magenta, could be H=350 (equivalent to - -10), S=255, V=180. A grayish light red could have H about 0 (say - 350-359 or 0-10), S about 50-100, and S=255. - - TQt returns a hue value of -1 for achromatic colors. If you pass a - too-big hue value, TQt forces it into range. Hue 360 or 720 is - treated as 0; hue 540 is treated as 180. - - \sa TQPalette, TQColorGroup, TQApplication::setColorSpec(), - \link http://www.poynton.com/ColorFAQ.html Color FAQ\endlink -*/ - -/***************************************************************************** - Global colors - *****************************************************************************/ - -#if defined(TQ_WS_WIN) -#define COLOR0_PIX 0x00ffffff -#define COLOR1_PIX 0 -#else -#define COLOR0_PIX 0 -#define COLOR1_PIX 1 -#endif - -#if (defined(Q_CC_GNU) && defined(Q_OS_WIN)) -// workaround - bug in mingw -static TQColor stdcol[19] = { - TQColor( 255, 255, 255 ), - TQColor( 0, 0, 0 ), - TQColor( 0, 0, 0 ), - TQColor( 255, 255, 255 ), - TQColor( 128, 128, 128 ), - TQColor( 160, 160, 164 ), - TQColor( 192, 192, 192 ), - TQColor( 255, 0, 0 ), - TQColor( 0, 255, 0 ), - TQColor( 0, 0, 255 ), - TQColor( 0, 255, 255 ), - TQColor( 255, 0, 255 ), - TQColor( 255, 255, 0 ), - TQColor( 128, 0, 0 ), - TQColor( 0, 128, 0 ), - TQColor( 0, 0, 128 ), - TQColor( 0, 128, 128 ), - TQColor( 128, 0, 128 ), - TQColor( 128, 128, 0 ) }; -#else - static TQColor stdcol[19]; -#endif - -const TQColor & TQt::color0 = stdcol[0]; -const TQColor & TQt::color1 = stdcol[1]; -const TQColor & TQt::black = stdcol[2]; -const TQColor & TQt::white = stdcol[3]; -const TQColor & TQt::darkGray = stdcol[4]; -const TQColor & TQt::gray = stdcol[5]; -const TQColor & TQt::lightGray = stdcol[6]; -const TQColor & TQt::red = stdcol[7]; -const TQColor & TQt::green = stdcol[8]; -const TQColor & TQt::blue = stdcol[9]; -const TQColor & TQt::cyan = stdcol[10]; -const TQColor & TQt::magenta = stdcol[11]; -const TQColor & TQt::yellow = stdcol[12]; -const TQColor & TQt::darkRed = stdcol[13]; -const TQColor & TQt::darkGreen = stdcol[14]; -const TQColor & TQt::darkBlue = stdcol[15]; -const TQColor & TQt::darkCyan = stdcol[16]; -const TQColor & TQt::darkMagenta = stdcol[17]; -const TQColor & TQt::darkYellow = stdcol[18]; - - -/***************************************************************************** - TQColor member functions - *****************************************************************************/ - -bool TQColor::color_init = FALSE; // color system not initialized -bool TQColor::globals_init = FALSE; // global color not initialized -TQColor::ColorModel TQColor::colormodel = d32; - - -TQColor* TQColor::globalColors() -{ - return stdcol; -} - - -/*! - Initializes the global colors. This function is called if a global - color variable is initialized before the constructors for our - global color objects are executed. Without this mechanism, - assigning a color might assign an uninitialized value. - - Example: - \code - TQColor myColor = red; // will initialize red etc. - - int main( int argc, char **argc ) - { - } - \endcode -*/ - -void TQColor::initGlobalColors() -{ - globals_init = TRUE; - - #ifdef TQ_WS_X11 - // HACK: we need a way to recognize color0 and color1 uniquely, so - // that we can use color0 and color1 with fixed pixel values on - // all screens - stdcol[ 0].d.argb = tqRgba(255, 255, 255, 1); - stdcol[ 1].d.argb = tqRgba( 0, 0, 0, 1); - #else - stdcol[ 0].d.argb = tqRgb(255,255,255); - stdcol[ 1].d.argb = 0; - #endif // TQ_WS_X11 - stdcol[ 0].setPixel( COLOR0_PIX ); - stdcol[ 1].setPixel( COLOR1_PIX ); - - // From the "The Palette Manager: How and Why" by Ron Gery, March 23, - // 1992, archived on MSDN: - // The Windows system palette is broken up into two sections, - // one with fixed colors and one with colors that can be changed - // by applications. The system palette predefines 20 entries; - // these colors are known as the static or reserved colors and - // consist of the 16 colors found in the Windows version 3.0 VGA - // driver and 4 additional colors chosen for their visual appeal. - // The DEFAULT_PALETTE stock object is, as the name implies, the - // default palette selected into a device context (DC) and consists - // of these static colors. Applications can set the remaining 236 - // colors using the Palette Manager. - // The 20 reserved entries have indices in [0,9] and [246,255]. We - // reuse 17 of them. - stdcol[ 2].setRgb( 0, 0, 0 ); // index 0 black - stdcol[ 3].setRgb( 255, 255, 255 ); // index 255 white - stdcol[ 4].setRgb( 128, 128, 128 ); // index 248 medium gray - stdcol[ 5].setRgb( 160, 160, 164 ); // index 247 light gray - stdcol[ 6].setRgb( 192, 192, 192 ); // index 7 light gray - stdcol[ 7].setRgb( 255, 0, 0 ); // index 249 red - stdcol[ 8].setRgb( 0, 255, 0 ); // index 250 green - stdcol[ 9].setRgb( 0, 0, 255 ); // index 252 blue - stdcol[10].setRgb( 0, 255, 255 ); // index 254 cyan - stdcol[11].setRgb( 255, 0, 255 ); // index 253 magenta - stdcol[12].setRgb( 255, 255, 0 ); // index 251 yellow - stdcol[13].setRgb( 128, 0, 0 ); // index 1 dark red - stdcol[14].setRgb( 0, 128, 0 ); // index 2 dark green - stdcol[15].setRgb( 0, 0, 128 ); // index 4 dark blue - stdcol[16].setRgb( 0, 128, 128 ); // index 6 dark cyan - stdcol[17].setRgb( 128, 0, 128 ); // index 5 dark magenta - stdcol[18].setRgb( 128, 128, 0 ); // index 3 dark yellow -} - -/*! - \enum TQColor::Spec - - The type of color specified, either RGB or HSV, e.g. in the - \c{TQColor::TQColor( x, y, z, colorSpec)} constructor. - - \value Rgb - \value Hsv -*/ - - -/*! - \fn TQColor::TQColor() - - Constructs an invalid color with the RGB value (0, 0, 0). An - invalid color is a color that is not properly set up for the - underlying window system. - - The alpha value of an invalid color is unspecified. - - \sa isValid() -*/ - - -/*! - \fn TQColor::TQColor( int r, int g, int b ) - - Constructs a color with the RGB value \a r, \a g, \a b, in the - same way as setRgb(). - - The color is left invalid if any or the arguments are illegal. - - \sa setRgb() -*/ - - -/*! - Constructs a color with the RGB value \a rgb and a custom pixel - value \a pixel. - - If \a pixel == 0xffffffff (the default), then the color uses the - RGB value in a standard way. If \a pixel is something else, then - the pixel value is set directly to \a pixel, skipping the normal - allocation procedure. -*/ - -TQColor::TQColor( TQRgb rgb, uint pixel ) -{ - if ( pixel == 0xffffffff ) { - setRgb( rgb ); - } else { - d.argb = rgb; - setPixel( pixel ); - } -} - -void TQColor::setPixel( uint pixel ) -{ - switch ( colormodel ) { - case d8: - d.d8.direct = TRUE; - d.d8.invalid = FALSE; - d.d8.dirty = FALSE; - d.d8.pix = pixel; - break; - case d32: - d.d32.pix = pixel; - break; - } -} - - -/*! - Constructs a color with the RGB or HSV value \a x, \a y, \a z. - - The arguments are an RGB value if \a colorSpec is TQColor::Rgb. \a - x (red), \a y (green), and \a z (blue). All of them must be in the - range 0-255. - - The arguments are an HSV value if \a colorSpec is TQColor::Hsv. \a - x (hue) must be -1 for achromatic colors and 0-359 for chromatic - colors; \a y (saturation) and \a z (value) must both be in the - range 0-255. - - \sa setRgb(), setHsv() -*/ - -TQColor::TQColor( int x, int y, int z, Spec colorSpec ) -{ - d.d32.argb = Invalid; - d.d32.pix = Dirt; - if ( colorSpec == Hsv ) - setHsv( x, y, z ); - else - setRgb( x, y, z ); -} - - -/*! - Constructs a named color in the same way as setNamedColor() using - name \a name. - - The color is left invalid if \a name cannot be parsed. - - \sa setNamedColor() -*/ - -TQColor::TQColor( const TQString& name ) -{ - setNamedColor( name ); -} - - -/*! - Constructs a named color in the same way as setNamedColor() using - name \a name. - - The color is left invalid if \a name cannot be parsed. - - \sa setNamedColor() -*/ - -TQColor::TQColor( const char *name ) -{ - setNamedColor( TQString(name) ); -} - - - -/*! - Constructs a color that is a copy of \a c. -*/ - -TQColor::TQColor( const TQColor &c ) -{ - if ( !globals_init ) - initGlobalColors(); - d.argb = c.d.argb; - d.d32.pix = c.d.d32.pix; -} - - -/*! - Assigns a copy of the color \a c and returns a reference to this - color. -*/ - -TQColor &TQColor::operator=( const TQColor &c ) -{ - if ( !globals_init ) - initGlobalColors(); - d.argb = c.d.argb; - d.d32.pix = c.d.d32.pix; - return *this; -} - - -/*! - \fn bool TQColor::isValid() const - - Returns FALSE if the color is invalid, i.e. it was constructed using the - default constructor; otherwise returns TRUE. -*/ - -/*! - \internal -*/ -bool TQColor::isDirty() const -{ - if ( colormodel == d8 ) { - return d.d8.dirty; - } else { - return d.d32.probablyDirty(); - } -} - -/*! - Returns the name of the color in the format "#RRGGBB", i.e. a "#" - character followed by three two-digit hexadecimal numbers. - - \sa setNamedColor() -*/ - -TQString TQColor::name() const -{ -#ifndef TQT_NO_SPRINTF - TQString s; - s.sprintf( "#%02x%02x%02x", red(), green(), blue() ); - return s; -#else - char s[20]; - sprintf( s, "#%02x%02x%02x", red(), green(), blue() ); - return TQString(s); -#endif -} - -static int hex2int( TQChar hexchar ) -{ - int v; - if ( hexchar.isDigit() ) - v = hexchar.digitValue(); - else if ( hexchar >= 'A' && hexchar <= 'F' ) - v = hexchar.cell() - 'A' + 10; - else if ( hexchar >= 'a' && hexchar <= 'f' ) - v = hexchar.cell() - 'a' + 10; - else - v = -1; - return v; -} - - -/*! - Sets the RGB value to \a name, which may be in one of these - formats: - \list - \i #RGB (each of R, G and B is a single hex digit) - \i #RRGGBB - \i #RRRGGGBBB - \i #RRRRGGGGBBBB - \i A name from the X color database (rgb.txt) (e.g. - "steelblue" or "gainsboro"). These color names also work - under Windows. - \endlist - - The color is invalid if \a name cannot be parsed. -*/ - -void TQColor::setNamedColor( const TQString &name ) -{ - if ( name.isEmpty() ) { - d.argb = 0; - if ( colormodel == d8 ) { - d.d8.invalid = TRUE; - } else { - d.d32.argb = Invalid; - } - } else if ( name[0] == '#' ) { - const TQChar *p = name.unicode()+1; - int len = name.length()-1; - int r, g, b; - if ( len == 12 ) { - r = (hex2int(p[0]) << 4) + hex2int(p[1]); - g = (hex2int(p[4]) << 4) + hex2int(p[5]); - b = (hex2int(p[8]) << 4) + hex2int(p[9]); - } else if ( len == 9 ) { - r = (hex2int(p[0]) << 4) + hex2int(p[1]); - g = (hex2int(p[3]) << 4) + hex2int(p[4]); - b = (hex2int(p[6]) << 4) + hex2int(p[7]); - } else if ( len == 6 ) { - r = (hex2int(p[0]) << 4) + hex2int(p[1]); - g = (hex2int(p[2]) << 4) + hex2int(p[3]); - b = (hex2int(p[4]) << 4) + hex2int(p[5]); - } else if ( len == 3 ) { - r = (hex2int(p[0]) << 4) + hex2int(p[0]); - g = (hex2int(p[1]) << 4) + hex2int(p[1]); - b = (hex2int(p[2]) << 4) + hex2int(p[2]); - } else { - r = g = b = -1; - } - if ( (uint)r > 255 || (uint)g > 255 || (uint)b > 255 ) { - d.d32.argb = Invalid; - d.d32.pix = Dirt; -#if defined(QT_CHECK_RANGE) - tqWarning( "TQColor::setNamedColor: could not parse color '%s'", - name.local8Bit().data() ); -#endif - } else { - setRgb( r, g, b ); - } - } else { - setSystemNamedColor( name ); - } -} - - -#undef max -#undef min - -/*! - \fn void TQColor::getHsv( int &h, int &s, int &v ) const - \obsolete -*/ - -/*! \fn void TQColor::getHsv( int *h, int *s, int *v ) const - - Returns the current RGB value as HSV. The contents of the \a h, \a - s and \a v pointers are set to the HSV values. If any of the three - pointers are null, the function does nothing. - - The hue (which \a h points to) is set to -1 if the color is - achromatic. - - \warning Colors are stored internally as RGB values, so getHSv() - may return slightly different values to those set by setHsv(). - - \sa setHsv(), rgb() -*/ - -/*! \obsolete Use getHsv() instead. - */ -void TQColor::hsv( int *h, int *s, int *v ) const -{ - if ( !h || !s || !v ) - return; - int r = tqRed(d.argb); - int g = tqGreen(d.argb); - int b = tqBlue(d.argb); - uint max = r; // maximum RGB component - int whatmax = 0; // r=>0, g=>1, b=>2 - if ( (uint)g > max ) { - max = g; - whatmax = 1; - } - if ( (uint)b > max ) { - max = b; - whatmax = 2; - } - uint min = r; // find minimum value - if ( (uint)g < min ) min = g; - if ( (uint)b < min ) min = b; - int delta = max-min; - *v = max; // calc value - *s = max ? (510*delta+max)/(2*max) : 0; - if ( *s == 0 ) { - *h = -1; // undefined hue - } else { - switch ( whatmax ) { - case 0: // red is max component - if ( g >= b ) - *h = (120*(g-b)+delta)/(2*delta); - else - *h = (120*(g-b+delta)+delta)/(2*delta) + 300; - break; - case 1: // green is max component - if ( b > r ) - *h = 120 + (120*(b-r)+delta)/(2*delta); - else - *h = 60 + (120*(b-r+delta)+delta)/(2*delta); - break; - case 2: // blue is max component - if ( r > g ) - *h = 240 + (120*(r-g)+delta)/(2*delta); - else - *h = 180 + (120*(r-g+delta)+delta)/(2*delta); - break; - } - } -} - - -/*! - Sets a HSV color value. \a h is the hue, \a s is the saturation - and \a v is the value of the HSV color. - - If \a s or \a v are not in the range 0-255, or \a h is < -1, the - color is not changed. - - \warning Colors are stored internally as RGB values, so getHSv() - may return slightly different values to those set by setHsv(). - - \sa hsv(), setRgb() -*/ - -void TQColor::setHsv( int h, int s, int v ) -{ - if ( h < -1 || (uint)s > 255 || (uint)v > 255 ) { -#if defined(QT_CHECK_RANGE) - tqWarning( "TQColor::setHsv: HSV parameters out of range" ); -#endif - return; - } - int r=v, g=v, b=v; - if ( s == 0 || h == -1 ) { // achromatic case - // Ignore - } else { // chromatic case - if ( (uint)h >= 360 ) - h %= 360; - uint f = h%60; - h /= 60; - uint p = (uint)(2*v*(255-s)+255)/510; - uint q, t; - if ( h&1 ) { - q = (uint)(2*v*(15300-s*f)+15300)/30600; - switch( h ) { - case 1: r=(int)q; g=(int)v, b=(int)p; break; - case 3: r=(int)p; g=(int)q, b=(int)v; break; - case 5: r=(int)v; g=(int)p, b=(int)q; break; - } - } else { - t = (uint)(2*v*(15300-(s*(60-f)))+15300)/30600; - switch( h ) { - case 0: r=(int)v; g=(int)t, b=(int)p; break; - case 2: r=(int)p; g=(int)v, b=(int)t; break; - case 4: r=(int)t; g=(int)p, b=(int)v; break; - } - } - } - setRgb( r, g, b ); -} - - -/*! - \fn TQRgb TQColor::rgb() const - - Returns the RGB value. - - The return type \e TQRgb is equivalent to \c unsigned \c int. - - For an invalid color, the alpha value of the returned color is - unspecified. - - \sa setRgb(), hsv(), tqRed(), tqBlue(), tqGreen(), isValid() -*/ - -/*! \fn void TQColor::getRgb( int *r, int *g, int *b ) const - - Sets the contents pointed to by \a r, \a g and \a b to the red, - green and blue components of the RGB value respectively. The value - range for a component is 0..255. - - \sa rgb(), setRgb(), getHsv() -*/ - -/*! \obsolete Use getRgb() instead */ -void TQColor::rgb( int *r, int *g, int *b ) const -{ - *r = tqRed(d.argb); - *g = tqGreen(d.argb); - *b = tqBlue(d.argb); -} - - -/*! - Sets the RGB value to \a r, \a g, \a b. The arguments, \a r, \a g - and \a b must all be in the range 0..255. If any of them are - outside the legal range, the color is not changed. - - \sa rgb(), setHsv() -*/ - -void TQColor::setRgb( int r, int g, int b ) -{ - if ( (uint)r > 255 || (uint)g > 255 || (uint)b > 255 ) { -#if defined(QT_CHECK_RANGE) - tqWarning( "TQColor::setRgb: RGB parameter(s) out of range" ); -#endif - return; - } - d.argb = tqRgb( r, g, b ); - if ( colormodel == d8 ) { - d.d8.invalid = FALSE; - d.d8.direct = FALSE; - d.d8.dirty = TRUE; - } else { - d.d32.pix = Dirt; - } -} - - -/*! - \overload - Sets the RGB value to \a rgb. - - The type \e TQRgb is equivalent to \c unsigned \c int. - - \sa rgb(), setHsv() -*/ - -void TQColor::setRgb( TQRgb rgb ) -{ - d.argb = rgb; - if ( colormodel == d8 ) { - d.d8.invalid = FALSE; - d.d8.direct = FALSE; - d.d8.dirty = TRUE; - } else { - d.d32.pix = Dirt; - } -} - -/*! - \fn int TQColor::red() const - - Returns the R (red) component of the RGB value. -*/ - - -/*! - \fn int TQColor::green() const - - Returns the G (green) component of the RGB value. -*/ - -/*! - \fn int TQColor::blue() const - - Returns the B (blue) component of the RGB value. -*/ - - -/*! - Returns a lighter (or darker) color, but does not change this - object. - - Returns a lighter color if \a factor is greater than 100. Setting - \a factor to 150 returns a color that is 50% brighter. - - Returns a darker color if \a factor is less than 100. We recommend - using dark() for this purpose. If \a factor is 0 or negative, the - return value is unspecified. - - (This function converts the current RGB color to HSV, multiplies V - by \a factor, and converts the result back to RGB.) - - \sa dark() -*/ - -TQColor TQColor::light( int factor ) const -{ - if ( factor <= 0 ) // invalid lightness factor - return *this; - else if ( factor < 100 ) // makes color darker - return dark( 10000/factor ); - - int h, s, v; - hsv( &h, &s, &v ); - v = (factor*v)/100; - if ( v > 255 ) { // overflow - s -= v-255; // adjust saturation - if ( s < 0 ) - s = 0; - v = 255; - } - TQColor c; - c.setHsv( h, s, v ); - return c; -} - - -/*! - Returns a darker (or lighter) color, but does not change this - object. - - Returns a darker color if \a factor is greater than 100. Setting - \a factor to 300 returns a color that has one-third the - brightness. - - Returns a lighter color if \a factor is less than 100. We - recommend using lighter() for this purpose. If \a factor is 0 or - negative, the return value is unspecified. - - (This function converts the current RGB color to HSV, divides V by - \a factor and converts back to RGB.) - - \sa light() -*/ - -TQColor TQColor::dark( int factor ) const -{ - if ( factor <= 0 ) // invalid darkness factor - return *this; - else if ( factor < 100 ) // makes color lighter - return light( 10000/factor ); - int h, s, v; - hsv( &h, &s, &v ); - v = (v*100)/factor; - TQColor c; - c.setHsv( h, s, v ); - return c; -} - - -/*! - \fn bool TQColor::operator==( const TQColor &c ) const - - Returns TRUE if this color has the same RGB value as \a c; - otherwise returns FALSE. -*/ - -/*! - \fn bool TQColor::operator!=( const TQColor &c ) const - Returns TRUE if this color has a different RGB value from \a c; - otherwise returns FALSE. -*/ - -/*! - Returns the pixel value. - - This value is used by the underlying window system to refer to a - color. It can be thought of as an index into the display - hardware's color table, but the value is an arbitrary 32-bit - value. - - \sa alloc() -*/ -uint TQColor::pixel() const -{ - if ( isDirty() ) - return ((TQColor*)this)->alloc(); - else if ( colormodel == d8 ) -#ifdef TQ_WS_WIN - // since d.d8.pix is uchar we have to use the PALETTEINDEX - // macro to get the respective palette entry index. - return (0x01000000 | (int)(short)(d.d8.pix)); -#else - return d.d8.pix; -#endif - else - return d.d32.pix; -} - -/*! - \fn TQStringList TQColor::colorNames() - Returns a TQStringList containing the color names TQt knows about. -*/ - -/***************************************************************************** - TQColor stream functions - *****************************************************************************/ -#ifndef TQT_NO_DATASTREAM -/*! - \relates TQColor - Writes a color object, \a c to the stream, \a s. - - \sa \link datastreamformat.html Format of the TQDataStream operators \endlink -*/ - -TQDataStream &operator<<( TQDataStream &s, const TQColor &c ) -{ - TQ_UINT32 p = (TQ_UINT32)c.rgb(); - if ( s.version() == 1 ) // Swap red and blue - p = ((p << 16) & 0xff0000) | ((p >> 16) & 0xff) | (p & 0xff00ff00); - return s << p; -} - -/*! - \relates TQColor - Reads a color object, \a c, from the stream, \a s. - - \sa \link datastreamformat.html Format of the TQDataStream operators \endlink -*/ - -TQDataStream &operator>>( TQDataStream &s, TQColor &c ) -{ - TQ_UINT32 p; - s >> p; - if ( s.version() == 1 ) // Swap red and blue - p = ((p << 16) & 0xff0000) | ((p >> 16) & 0xff) | (p & 0xff00ff00); - c.setRgb( p ); - return s; -} -#endif - -/***************************************************************************** - TQColor global functions (documentation only) - *****************************************************************************/ - -/*! - \fn int tqRed( TQRgb rgb ) - \relates TQColor - - Returns the red component of the RGB triplet \a rgb. - \sa tqRgb(), TQColor::red() -*/ - -/*! - \fn int tqGreen( TQRgb rgb ) - \relates TQColor - - Returns the green component of the RGB triplet \a rgb. - \sa tqRgb(), TQColor::green() -*/ - -/*! - \fn int tqBlue( TQRgb rgb ) - \relates TQColor - - Returns the blue component of the RGB triplet \a rgb. - \sa tqRgb(), TQColor::blue() -*/ - -/*! - \fn int tqAlpha( TQRgb rgba ) - \relates TQColor - - Returns the alpha component of the RGBA quadruplet \a rgba. - */ - -/*! - \fn TQRgb tqRgb( int r, int g, int b ) - \relates TQColor - - Returns the RGB triplet \a (r,g,b). - - The return type TQRgb is equivalent to \c unsigned \c int. - - \sa tqRgba(), tqRed(), tqGreen(), tqBlue() -*/ - -/*! - \fn TQRgb tqRgba( int r, int g, int b, int a ) - \relates TQColor - - Returns the RGBA quadruplet \a (r,g,b,a). - - The return type TQRgba is equivalent to \c unsigned \c int. - - \sa tqRgb(), tqRed(), tqGreen(), tqBlue() -*/ - -/*! - \fn int tqGray( int r, int g, int b ) - \relates TQColor - - Returns a gray value 0..255 from the (\a r, \a g, \a b) triplet. - - The gray value is calculated using the formula (r*11 + g*16 + - b*5)/32. -*/ - -/*! - \overload int tqGray( tqRgb rgb ) - \relates TQColor - - Returns a gray value 0..255 from the given \a rgb colour. -*/ - diff --git a/src/kernel/qcolor_p.cpp b/src/kernel/qcolor_p.cpp deleted file mode 100644 index e7e33c9cb..000000000 --- a/src/kernel/qcolor_p.cpp +++ /dev/null @@ -1,797 +0,0 @@ -/**************************************************************************** -** -** Named color support for non-X platforms. -** The color names have been borrowed from X. -** -** Created : 000228 -** -** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#include "ntqglobal.h" -#if defined(Q_CC_BOR) -// needed for qsort() because of a std namespace problem on Borland -#include "qplatformdefs.h" -#endif - -#include "ntqcolor.h" - -#ifndef TQT_NO_COLORNAMES - -#include - -#undef TQRGB -#define TQRGB(r,g,b) (r*65536 + g*256 + b) - -const int rgbTblSize = 657; - -static const struct RGBData { - uint value; - const char *name; -} rgbTbl[] = { - { TQRGB(240,248,255), "aliceblue" }, - { TQRGB(250,235,215), "antiquewhite" }, - { TQRGB(255,239,219), "antiquewhite1" }, - { TQRGB(238,223,204), "antiquewhite2" }, - { TQRGB(205,192,176), "antiquewhite3" }, - { TQRGB(139,131,120), "antiquewhite4" }, - { TQRGB(127,255,212), "aquamarine" }, - { TQRGB(127,255,212), "aquamarine1" }, - { TQRGB(118,238,198), "aquamarine2" }, - { TQRGB(102,205,170), "aquamarine3" }, - { TQRGB( 69,139,116), "aquamarine4" }, - { TQRGB(240,255,255), "azure" }, - { TQRGB(240,255,255), "azure1" }, - { TQRGB(224,238,238), "azure2" }, - { TQRGB(193,205,205), "azure3" }, - { TQRGB(131,139,139), "azure4" }, - { TQRGB(245,245,220), "beige" }, - { TQRGB(255,228,196), "bisque" }, - { TQRGB(255,228,196), "bisque1" }, - { TQRGB(238,213,183), "bisque2" }, - { TQRGB(205,183,158), "bisque3" }, - { TQRGB(139,125,107), "bisque4" }, - { TQRGB( 0, 0, 0), "black" }, - { TQRGB(255,235,205), "blanchedalmond" }, - { TQRGB( 0, 0,255), "blue" }, - { TQRGB( 0, 0,255), "blue1" }, - { TQRGB( 0, 0,238), "blue2" }, - { TQRGB( 0, 0,205), "blue3" }, - { TQRGB( 0, 0,139), "blue4" }, - { TQRGB(138, 43,226), "blueviolet" }, - { TQRGB(165, 42, 42), "brown" }, - { TQRGB(255, 64, 64), "brown1" }, - { TQRGB(238, 59, 59), "brown2" }, - { TQRGB(205, 51, 51), "brown3" }, - { TQRGB(139, 35, 35), "brown4" }, - { TQRGB(222,184,135), "burlywood" }, - { TQRGB(255,211,155), "burlywood1" }, - { TQRGB(238,197,145), "burlywood2" }, - { TQRGB(205,170,125), "burlywood3" }, - { TQRGB(139,115, 85), "burlywood4" }, - { TQRGB( 95,158,160), "cadetblue" }, - { TQRGB(152,245,255), "cadetblue1" }, - { TQRGB(142,229,238), "cadetblue2" }, - { TQRGB(122,197,205), "cadetblue3" }, - { TQRGB( 83,134,139), "cadetblue4" }, - { TQRGB(127,255, 0), "chartreuse" }, - { TQRGB(127,255, 0), "chartreuse1" }, - { TQRGB(118,238, 0), "chartreuse2" }, - { TQRGB(102,205, 0), "chartreuse3" }, - { TQRGB( 69,139, 0), "chartreuse4" }, - { TQRGB(210,105, 30), "chocolate" }, - { TQRGB(255,127, 36), "chocolate1" }, - { TQRGB(238,118, 33), "chocolate2" }, - { TQRGB(205,102, 29), "chocolate3" }, - { TQRGB(139, 69, 19), "chocolate4" }, - { TQRGB(255,127, 80), "coral" }, - { TQRGB(255,114, 86), "coral1" }, - { TQRGB(238,106, 80), "coral2" }, - { TQRGB(205, 91, 69), "coral3" }, - { TQRGB(139, 62, 47), "coral4" }, - { TQRGB(100,149,237), "cornflowerblue" }, - { TQRGB(255,248,220), "cornsilk" }, - { TQRGB(255,248,220), "cornsilk1" }, - { TQRGB(238,232,205), "cornsilk2" }, - { TQRGB(205,200,177), "cornsilk3" }, - { TQRGB(139,136,120), "cornsilk4" }, - { TQRGB( 0,255,255), "cyan" }, - { TQRGB( 0,255,255), "cyan1" }, - { TQRGB( 0,238,238), "cyan2" }, - { TQRGB( 0,205,205), "cyan3" }, - { TQRGB( 0,139,139), "cyan4" }, - { TQRGB( 0, 0,139), "darkblue" }, - { TQRGB( 0,139,139), "darkcyan" }, - { TQRGB(184,134, 11), "darkgoldenrod" }, - { TQRGB(255,185, 15), "darkgoldenrod1" }, - { TQRGB(238,173, 14), "darkgoldenrod2" }, - { TQRGB(205,149, 12), "darkgoldenrod3" }, - { TQRGB(139,101, 8), "darkgoldenrod4" }, - { TQRGB(169,169,169), "darkgray" }, - { TQRGB( 0,100, 0), "darkgreen" }, - { TQRGB(169,169,169), "darkgrey" }, - { TQRGB(189,183,107), "darkkhaki" }, - { TQRGB(139, 0,139), "darkmagenta" }, - { TQRGB( 85,107, 47), "darkolivegreen" }, - { TQRGB(202,255,112), "darkolivegreen1" }, - { TQRGB(188,238,104), "darkolivegreen2" }, - { TQRGB(162,205, 90), "darkolivegreen3" }, - { TQRGB(110,139, 61), "darkolivegreen4" }, - { TQRGB(255,140, 0), "darkorange" }, - { TQRGB(255,127, 0), "darkorange1" }, - { TQRGB(238,118, 0), "darkorange2" }, - { TQRGB(205,102, 0), "darkorange3" }, - { TQRGB(139, 69, 0), "darkorange4" }, - { TQRGB(153, 50,204), "darkorchid" }, - { TQRGB(191, 62,255), "darkorchid1" }, - { TQRGB(178, 58,238), "darkorchid2" }, - { TQRGB(154, 50,205), "darkorchid3" }, - { TQRGB(104, 34,139), "darkorchid4" }, - { TQRGB(139, 0, 0), "darkred" }, - { TQRGB(233,150,122), "darksalmon" }, - { TQRGB(143,188,143), "darkseagreen" }, - { TQRGB(193,255,193), "darkseagreen1" }, - { TQRGB(180,238,180), "darkseagreen2" }, - { TQRGB(155,205,155), "darkseagreen3" }, - { TQRGB(105,139,105), "darkseagreen4" }, - { TQRGB( 72, 61,139), "darkslateblue" }, - { TQRGB( 47, 79, 79), "darkslategray" }, - { TQRGB(151,255,255), "darkslategray1" }, - { TQRGB(141,238,238), "darkslategray2" }, - { TQRGB(121,205,205), "darkslategray3" }, - { TQRGB( 82,139,139), "darkslategray4" }, - { TQRGB( 47, 79, 79), "darkslategrey" }, - { TQRGB( 0,206,209), "darkturquoise" }, - { TQRGB(148, 0,211), "darkviolet" }, - { TQRGB(255, 20,147), "deeppink" }, - { TQRGB(255, 20,147), "deeppink1" }, - { TQRGB(238, 18,137), "deeppink2" }, - { TQRGB(205, 16,118), "deeppink3" }, - { TQRGB(139, 10, 80), "deeppink4" }, - { TQRGB( 0,191,255), "deepskyblue" }, - { TQRGB( 0,191,255), "deepskyblue1" }, - { TQRGB( 0,178,238), "deepskyblue2" }, - { TQRGB( 0,154,205), "deepskyblue3" }, - { TQRGB( 0,104,139), "deepskyblue4" }, - { TQRGB(105,105,105), "dimgray" }, - { TQRGB(105,105,105), "dimgrey" }, - { TQRGB( 30,144,255), "dodgerblue" }, - { TQRGB( 30,144,255), "dodgerblue1" }, - { TQRGB( 28,134,238), "dodgerblue2" }, - { TQRGB( 24,116,205), "dodgerblue3" }, - { TQRGB( 16, 78,139), "dodgerblue4" }, - { TQRGB(178, 34, 34), "firebrick" }, - { TQRGB(255, 48, 48), "firebrick1" }, - { TQRGB(238, 44, 44), "firebrick2" }, - { TQRGB(205, 38, 38), "firebrick3" }, - { TQRGB(139, 26, 26), "firebrick4" }, - { TQRGB(255,250,240), "floralwhite" }, - { TQRGB( 34,139, 34), "forestgreen" }, - { TQRGB(220,220,220), "gainsboro" }, - { TQRGB(248,248,255), "ghostwhite" }, - { TQRGB(255,215, 0), "gold" }, - { TQRGB(255,215, 0), "gold1" }, - { TQRGB(238,201, 0), "gold2" }, - { TQRGB(205,173, 0), "gold3" }, - { TQRGB(139,117, 0), "gold4" }, - { TQRGB(218,165, 32), "goldenrod" }, - { TQRGB(255,193, 37), "goldenrod1" }, - { TQRGB(238,180, 34), "goldenrod2" }, - { TQRGB(205,155, 29), "goldenrod3" }, - { TQRGB(139,105, 20), "goldenrod4" }, - { TQRGB(190,190,190), "gray" }, - { TQRGB( 0, 0, 0), "gray0" }, - { TQRGB( 3, 3, 3), "gray1" }, - { TQRGB( 26, 26, 26), "gray10" }, - { TQRGB(255,255,255), "gray100" }, - { TQRGB( 28, 28, 28), "gray11" }, - { TQRGB( 31, 31, 31), "gray12" }, - { TQRGB( 33, 33, 33), "gray13" }, - { TQRGB( 36, 36, 36), "gray14" }, - { TQRGB( 38, 38, 38), "gray15" }, - { TQRGB( 41, 41, 41), "gray16" }, - { TQRGB( 43, 43, 43), "gray17" }, - { TQRGB( 46, 46, 46), "gray18" }, - { TQRGB( 48, 48, 48), "gray19" }, - { TQRGB( 5, 5, 5), "gray2" }, - { TQRGB( 51, 51, 51), "gray20" }, - { TQRGB( 54, 54, 54), "gray21" }, - { TQRGB( 56, 56, 56), "gray22" }, - { TQRGB( 59, 59, 59), "gray23" }, - { TQRGB( 61, 61, 61), "gray24" }, - { TQRGB( 64, 64, 64), "gray25" }, - { TQRGB( 66, 66, 66), "gray26" }, - { TQRGB( 69, 69, 69), "gray27" }, - { TQRGB( 71, 71, 71), "gray28" }, - { TQRGB( 74, 74, 74), "gray29" }, - { TQRGB( 8, 8, 8), "gray3" }, - { TQRGB( 77, 77, 77), "gray30" }, - { TQRGB( 79, 79, 79), "gray31" }, - { TQRGB( 82, 82, 82), "gray32" }, - { TQRGB( 84, 84, 84), "gray33" }, - { TQRGB( 87, 87, 87), "gray34" }, - { TQRGB( 89, 89, 89), "gray35" }, - { TQRGB( 92, 92, 92), "gray36" }, - { TQRGB( 94, 94, 94), "gray37" }, - { TQRGB( 97, 97, 97), "gray38" }, - { TQRGB( 99, 99, 99), "gray39" }, - { TQRGB( 10, 10, 10), "gray4" }, - { TQRGB(102,102,102), "gray40" }, - { TQRGB(105,105,105), "gray41" }, - { TQRGB(107,107,107), "gray42" }, - { TQRGB(110,110,110), "gray43" }, - { TQRGB(112,112,112), "gray44" }, - { TQRGB(115,115,115), "gray45" }, - { TQRGB(117,117,117), "gray46" }, - { TQRGB(120,120,120), "gray47" }, - { TQRGB(122,122,122), "gray48" }, - { TQRGB(125,125,125), "gray49" }, - { TQRGB( 13, 13, 13), "gray5" }, - { TQRGB(127,127,127), "gray50" }, - { TQRGB(130,130,130), "gray51" }, - { TQRGB(133,133,133), "gray52" }, - { TQRGB(135,135,135), "gray53" }, - { TQRGB(138,138,138), "gray54" }, - { TQRGB(140,140,140), "gray55" }, - { TQRGB(143,143,143), "gray56" }, - { TQRGB(145,145,145), "gray57" }, - { TQRGB(148,148,148), "gray58" }, - { TQRGB(150,150,150), "gray59" }, - { TQRGB( 15, 15, 15), "gray6" }, - { TQRGB(153,153,153), "gray60" }, - { TQRGB(156,156,156), "gray61" }, - { TQRGB(158,158,158), "gray62" }, - { TQRGB(161,161,161), "gray63" }, - { TQRGB(163,163,163), "gray64" }, - { TQRGB(166,166,166), "gray65" }, - { TQRGB(168,168,168), "gray66" }, - { TQRGB(171,171,171), "gray67" }, - { TQRGB(173,173,173), "gray68" }, - { TQRGB(176,176,176), "gray69" }, - { TQRGB( 18, 18, 18), "gray7" }, - { TQRGB(179,179,179), "gray70" }, - { TQRGB(181,181,181), "gray71" }, - { TQRGB(184,184,184), "gray72" }, - { TQRGB(186,186,186), "gray73" }, - { TQRGB(189,189,189), "gray74" }, - { TQRGB(191,191,191), "gray75" }, - { TQRGB(194,194,194), "gray76" }, - { TQRGB(196,196,196), "gray77" }, - { TQRGB(199,199,199), "gray78" }, - { TQRGB(201,201,201), "gray79" }, - { TQRGB( 20, 20, 20), "gray8" }, - { TQRGB(204,204,204), "gray80" }, - { TQRGB(207,207,207), "gray81" }, - { TQRGB(209,209,209), "gray82" }, - { TQRGB(212,212,212), "gray83" }, - { TQRGB(214,214,214), "gray84" }, - { TQRGB(217,217,217), "gray85" }, - { TQRGB(219,219,219), "gray86" }, - { TQRGB(222,222,222), "gray87" }, - { TQRGB(224,224,224), "gray88" }, - { TQRGB(227,227,227), "gray89" }, - { TQRGB( 23, 23, 23), "gray9" }, - { TQRGB(229,229,229), "gray90" }, - { TQRGB(232,232,232), "gray91" }, - { TQRGB(235,235,235), "gray92" }, - { TQRGB(237,237,237), "gray93" }, - { TQRGB(240,240,240), "gray94" }, - { TQRGB(242,242,242), "gray95" }, - { TQRGB(245,245,245), "gray96" }, - { TQRGB(247,247,247), "gray97" }, - { TQRGB(250,250,250), "gray98" }, - { TQRGB(252,252,252), "gray99" }, - { TQRGB( 0,255, 0), "green" }, - { TQRGB( 0,255, 0), "green1" }, - { TQRGB( 0,238, 0), "green2" }, - { TQRGB( 0,205, 0), "green3" }, - { TQRGB( 0,139, 0), "green4" }, - { TQRGB(173,255, 47), "greenyellow" }, - { TQRGB(190,190,190), "grey" }, - { TQRGB( 0, 0, 0), "grey0" }, - { TQRGB( 3, 3, 3), "grey1" }, - { TQRGB( 26, 26, 26), "grey10" }, - { TQRGB(255,255,255), "grey100" }, - { TQRGB( 28, 28, 28), "grey11" }, - { TQRGB( 31, 31, 31), "grey12" }, - { TQRGB( 33, 33, 33), "grey13" }, - { TQRGB( 36, 36, 36), "grey14" }, - { TQRGB( 38, 38, 38), "grey15" }, - { TQRGB( 41, 41, 41), "grey16" }, - { TQRGB( 43, 43, 43), "grey17" }, - { TQRGB( 46, 46, 46), "grey18" }, - { TQRGB( 48, 48, 48), "grey19" }, - { TQRGB( 5, 5, 5), "grey2" }, - { TQRGB( 51, 51, 51), "grey20" }, - { TQRGB( 54, 54, 54), "grey21" }, - { TQRGB( 56, 56, 56), "grey22" }, - { TQRGB( 59, 59, 59), "grey23" }, - { TQRGB( 61, 61, 61), "grey24" }, - { TQRGB( 64, 64, 64), "grey25" }, - { TQRGB( 66, 66, 66), "grey26" }, - { TQRGB( 69, 69, 69), "grey27" }, - { TQRGB( 71, 71, 71), "grey28" }, - { TQRGB( 74, 74, 74), "grey29" }, - { TQRGB( 8, 8, 8), "grey3" }, - { TQRGB( 77, 77, 77), "grey30" }, - { TQRGB( 79, 79, 79), "grey31" }, - { TQRGB( 82, 82, 82), "grey32" }, - { TQRGB( 84, 84, 84), "grey33" }, - { TQRGB( 87, 87, 87), "grey34" }, - { TQRGB( 89, 89, 89), "grey35" }, - { TQRGB( 92, 92, 92), "grey36" }, - { TQRGB( 94, 94, 94), "grey37" }, - { TQRGB( 97, 97, 97), "grey38" }, - { TQRGB( 99, 99, 99), "grey39" }, - { TQRGB( 10, 10, 10), "grey4" }, - { TQRGB(102,102,102), "grey40" }, - { TQRGB(105,105,105), "grey41" }, - { TQRGB(107,107,107), "grey42" }, - { TQRGB(110,110,110), "grey43" }, - { TQRGB(112,112,112), "grey44" }, - { TQRGB(115,115,115), "grey45" }, - { TQRGB(117,117,117), "grey46" }, - { TQRGB(120,120,120), "grey47" }, - { TQRGB(122,122,122), "grey48" }, - { TQRGB(125,125,125), "grey49" }, - { TQRGB( 13, 13, 13), "grey5" }, - { TQRGB(127,127,127), "grey50" }, - { TQRGB(130,130,130), "grey51" }, - { TQRGB(133,133,133), "grey52" }, - { TQRGB(135,135,135), "grey53" }, - { TQRGB(138,138,138), "grey54" }, - { TQRGB(140,140,140), "grey55" }, - { TQRGB(143,143,143), "grey56" }, - { TQRGB(145,145,145), "grey57" }, - { TQRGB(148,148,148), "grey58" }, - { TQRGB(150,150,150), "grey59" }, - { TQRGB( 15, 15, 15), "grey6" }, - { TQRGB(153,153,153), "grey60" }, - { TQRGB(156,156,156), "grey61" }, - { TQRGB(158,158,158), "grey62" }, - { TQRGB(161,161,161), "grey63" }, - { TQRGB(163,163,163), "grey64" }, - { TQRGB(166,166,166), "grey65" }, - { TQRGB(168,168,168), "grey66" }, - { TQRGB(171,171,171), "grey67" }, - { TQRGB(173,173,173), "grey68" }, - { TQRGB(176,176,176), "grey69" }, - { TQRGB( 18, 18, 18), "grey7" }, - { TQRGB(179,179,179), "grey70" }, - { TQRGB(181,181,181), "grey71" }, - { TQRGB(184,184,184), "grey72" }, - { TQRGB(186,186,186), "grey73" }, - { TQRGB(189,189,189), "grey74" }, - { TQRGB(191,191,191), "grey75" }, - { TQRGB(194,194,194), "grey76" }, - { TQRGB(196,196,196), "grey77" }, - { TQRGB(199,199,199), "grey78" }, - { TQRGB(201,201,201), "grey79" }, - { TQRGB( 20, 20, 20), "grey8" }, - { TQRGB(204,204,204), "grey80" }, - { TQRGB(207,207,207), "grey81" }, - { TQRGB(209,209,209), "grey82" }, - { TQRGB(212,212,212), "grey83" }, - { TQRGB(214,214,214), "grey84" }, - { TQRGB(217,217,217), "grey85" }, - { TQRGB(219,219,219), "grey86" }, - { TQRGB(222,222,222), "grey87" }, - { TQRGB(224,224,224), "grey88" }, - { TQRGB(227,227,227), "grey89" }, - { TQRGB( 23, 23, 23), "grey9" }, - { TQRGB(229,229,229), "grey90" }, - { TQRGB(232,232,232), "grey91" }, - { TQRGB(235,235,235), "grey92" }, - { TQRGB(237,237,237), "grey93" }, - { TQRGB(240,240,240), "grey94" }, - { TQRGB(242,242,242), "grey95" }, - { TQRGB(245,245,245), "grey96" }, - { TQRGB(247,247,247), "grey97" }, - { TQRGB(250,250,250), "grey98" }, - { TQRGB(252,252,252), "grey99" }, - { TQRGB(240,255,240), "honeydew" }, - { TQRGB(240,255,240), "honeydew1" }, - { TQRGB(224,238,224), "honeydew2" }, - { TQRGB(193,205,193), "honeydew3" }, - { TQRGB(131,139,131), "honeydew4" }, - { TQRGB(255,105,180), "hotpink" }, - { TQRGB(255,110,180), "hotpink1" }, - { TQRGB(238,106,167), "hotpink2" }, - { TQRGB(205, 96,144), "hotpink3" }, - { TQRGB(139, 58, 98), "hotpink4" }, - { TQRGB(205, 92, 92), "indianred" }, - { TQRGB(255,106,106), "indianred1" }, - { TQRGB(238, 99, 99), "indianred2" }, - { TQRGB(205, 85, 85), "indianred3" }, - { TQRGB(139, 58, 58), "indianred4" }, - { TQRGB(255,255,240), "ivory" }, - { TQRGB(255,255,240), "ivory1" }, - { TQRGB(238,238,224), "ivory2" }, - { TQRGB(205,205,193), "ivory3" }, - { TQRGB(139,139,131), "ivory4" }, - { TQRGB(240,230,140), "khaki" }, - { TQRGB(255,246,143), "khaki1" }, - { TQRGB(238,230,133), "khaki2" }, - { TQRGB(205,198,115), "khaki3" }, - { TQRGB(139,134, 78), "khaki4" }, - { TQRGB(230,230,250), "lavender" }, - { TQRGB(255,240,245), "lavenderblush" }, - { TQRGB(255,240,245), "lavenderblush1" }, - { TQRGB(238,224,229), "lavenderblush2" }, - { TQRGB(205,193,197), "lavenderblush3" }, - { TQRGB(139,131,134), "lavenderblush4" }, - { TQRGB(124,252, 0), "lawngreen" }, - { TQRGB(255,250,205), "lemonchiffon" }, - { TQRGB(255,250,205), "lemonchiffon1" }, - { TQRGB(238,233,191), "lemonchiffon2" }, - { TQRGB(205,201,165), "lemonchiffon3" }, - { TQRGB(139,137,112), "lemonchiffon4" }, - { TQRGB(173,216,230), "lightblue" }, - { TQRGB(191,239,255), "lightblue1" }, - { TQRGB(178,223,238), "lightblue2" }, - { TQRGB(154,192,205), "lightblue3" }, - { TQRGB(104,131,139), "lightblue4" }, - { TQRGB(240,128,128), "lightcoral" }, - { TQRGB(224,255,255), "lightcyan" }, - { TQRGB(224,255,255), "lightcyan1" }, - { TQRGB(209,238,238), "lightcyan2" }, - { TQRGB(180,205,205), "lightcyan3" }, - { TQRGB(122,139,139), "lightcyan4" }, - { TQRGB(238,221,130), "lightgoldenrod" }, - { TQRGB(255,236,139), "lightgoldenrod1" }, - { TQRGB(238,220,130), "lightgoldenrod2" }, - { TQRGB(205,190,112), "lightgoldenrod3" }, - { TQRGB(139,129, 76), "lightgoldenrod4" }, - { TQRGB(250,250,210), "lightgoldenrodyellow" }, - { TQRGB(211,211,211), "lightgray" }, - { TQRGB(144,238,144), "lightgreen" }, - { TQRGB(211,211,211), "lightgrey" }, - { TQRGB(255,182,193), "lightpink" }, - { TQRGB(255,174,185), "lightpink1" }, - { TQRGB(238,162,173), "lightpink2" }, - { TQRGB(205,140,149), "lightpink3" }, - { TQRGB(139, 95,101), "lightpink4" }, - { TQRGB(255,160,122), "lightsalmon" }, - { TQRGB(255,160,122), "lightsalmon1" }, - { TQRGB(238,149,114), "lightsalmon2" }, - { TQRGB(205,129, 98), "lightsalmon3" }, - { TQRGB(139, 87, 66), "lightsalmon4" }, - { TQRGB( 32,178,170), "lightseagreen" }, - { TQRGB(135,206,250), "lightskyblue" }, - { TQRGB(176,226,255), "lightskyblue1" }, - { TQRGB(164,211,238), "lightskyblue2" }, - { TQRGB(141,182,205), "lightskyblue3" }, - { TQRGB( 96,123,139), "lightskyblue4" }, - { TQRGB(132,112,255), "lightslateblue" }, - { TQRGB(119,136,153), "lightslategray" }, - { TQRGB(119,136,153), "lightslategrey" }, - { TQRGB(176,196,222), "lightsteelblue" }, - { TQRGB(202,225,255), "lightsteelblue1" }, - { TQRGB(188,210,238), "lightsteelblue2" }, - { TQRGB(162,181,205), "lightsteelblue3" }, - { TQRGB(110,123,139), "lightsteelblue4" }, - { TQRGB(255,255,224), "lightyellow" }, - { TQRGB(255,255,224), "lightyellow1" }, - { TQRGB(238,238,209), "lightyellow2" }, - { TQRGB(205,205,180), "lightyellow3" }, - { TQRGB(139,139,122), "lightyellow4" }, - { TQRGB( 50,205, 50), "limegreen" }, - { TQRGB(250,240,230), "linen" }, - { TQRGB(255, 0,255), "magenta" }, - { TQRGB(255, 0,255), "magenta1" }, - { TQRGB(238, 0,238), "magenta2" }, - { TQRGB(205, 0,205), "magenta3" }, - { TQRGB(139, 0,139), "magenta4" }, - { TQRGB(176, 48, 96), "maroon" }, - { TQRGB(255, 52,179), "maroon1" }, - { TQRGB(238, 48,167), "maroon2" }, - { TQRGB(205, 41,144), "maroon3" }, - { TQRGB(139, 28, 98), "maroon4" }, - { TQRGB(102,205,170), "mediumaquamarine" }, - { TQRGB( 0, 0,205), "mediumblue" }, - { TQRGB(186, 85,211), "mediumorchid" }, - { TQRGB(224,102,255), "mediumorchid1" }, - { TQRGB(209, 95,238), "mediumorchid2" }, - { TQRGB(180, 82,205), "mediumorchid3" }, - { TQRGB(122, 55,139), "mediumorchid4" }, - { TQRGB(147,112,219), "mediumpurple" }, - { TQRGB(171,130,255), "mediumpurple1" }, - { TQRGB(159,121,238), "mediumpurple2" }, - { TQRGB(137,104,205), "mediumpurple3" }, - { TQRGB( 93, 71,139), "mediumpurple4" }, - { TQRGB( 60,179,113), "mediumseagreen" }, - { TQRGB(123,104,238), "mediumslateblue" }, - { TQRGB( 0,250,154), "mediumspringgreen" }, - { TQRGB( 72,209,204), "mediumturquoise" }, - { TQRGB(199, 21,133), "mediumvioletred" }, - { TQRGB( 25, 25,112), "midnightblue" }, - { TQRGB(245,255,250), "mintcream" }, - { TQRGB(255,228,225), "mistyrose" }, - { TQRGB(255,228,225), "mistyrose1" }, - { TQRGB(238,213,210), "mistyrose2" }, - { TQRGB(205,183,181), "mistyrose3" }, - { TQRGB(139,125,123), "mistyrose4" }, - { TQRGB(255,228,181), "moccasin" }, - { TQRGB(255,222,173), "navajowhite" }, - { TQRGB(255,222,173), "navajowhite1" }, - { TQRGB(238,207,161), "navajowhite2" }, - { TQRGB(205,179,139), "navajowhite3" }, - { TQRGB(139,121, 94), "navajowhite4" }, - { TQRGB( 0, 0,128), "navy" }, - { TQRGB( 0, 0,128), "navyblue" }, - { TQRGB(253,245,230), "oldlace" }, - { TQRGB(107,142, 35), "olivedrab" }, - { TQRGB(192,255, 62), "olivedrab1" }, - { TQRGB(179,238, 58), "olivedrab2" }, - { TQRGB(154,205, 50), "olivedrab3" }, - { TQRGB(105,139, 34), "olivedrab4" }, - { TQRGB(255,165, 0), "orange" }, - { TQRGB(255,165, 0), "orange1" }, - { TQRGB(238,154, 0), "orange2" }, - { TQRGB(205,133, 0), "orange3" }, - { TQRGB(139, 90, 0), "orange4" }, - { TQRGB(255, 69, 0), "orangered" }, - { TQRGB(255, 69, 0), "orangered1" }, - { TQRGB(238, 64, 0), "orangered2" }, - { TQRGB(205, 55, 0), "orangered3" }, - { TQRGB(139, 37, 0), "orangered4" }, - { TQRGB(218,112,214), "orchid" }, - { TQRGB(255,131,250), "orchid1" }, - { TQRGB(238,122,233), "orchid2" }, - { TQRGB(205,105,201), "orchid3" }, - { TQRGB(139, 71,137), "orchid4" }, - { TQRGB(238,232,170), "palegoldenrod" }, - { TQRGB(152,251,152), "palegreen" }, - { TQRGB(154,255,154), "palegreen1" }, - { TQRGB(144,238,144), "palegreen2" }, - { TQRGB(124,205,124), "palegreen3" }, - { TQRGB( 84,139, 84), "palegreen4" }, - { TQRGB(175,238,238), "paleturquoise" }, - { TQRGB(187,255,255), "paleturquoise1" }, - { TQRGB(174,238,238), "paleturquoise2" }, - { TQRGB(150,205,205), "paleturquoise3" }, - { TQRGB(102,139,139), "paleturquoise4" }, - { TQRGB(219,112,147), "palevioletred" }, - { TQRGB(255,130,171), "palevioletred1" }, - { TQRGB(238,121,159), "palevioletred2" }, - { TQRGB(205,104,137), "palevioletred3" }, - { TQRGB(139, 71, 93), "palevioletred4" }, - { TQRGB(255,239,213), "papayawhip" }, - { TQRGB(255,218,185), "peachpuff" }, - { TQRGB(255,218,185), "peachpuff1" }, - { TQRGB(238,203,173), "peachpuff2" }, - { TQRGB(205,175,149), "peachpuff3" }, - { TQRGB(139,119,101), "peachpuff4" }, - { TQRGB(205,133, 63), "peru" }, - { TQRGB(255,192,203), "pink" }, - { TQRGB(255,181,197), "pink1" }, - { TQRGB(238,169,184), "pink2" }, - { TQRGB(205,145,158), "pink3" }, - { TQRGB(139, 99,108), "pink4" }, - { TQRGB(221,160,221), "plum" }, - { TQRGB(255,187,255), "plum1" }, - { TQRGB(238,174,238), "plum2" }, - { TQRGB(205,150,205), "plum3" }, - { TQRGB(139,102,139), "plum4" }, - { TQRGB(176,224,230), "powderblue" }, - { TQRGB(160, 32,240), "purple" }, - { TQRGB(155, 48,255), "purple1" }, - { TQRGB(145, 44,238), "purple2" }, - { TQRGB(125, 38,205), "purple3" }, - { TQRGB( 85, 26,139), "purple4" }, - { TQRGB(255, 0, 0), "red" }, - { TQRGB(255, 0, 0), "red1" }, - { TQRGB(238, 0, 0), "red2" }, - { TQRGB(205, 0, 0), "red3" }, - { TQRGB(139, 0, 0), "red4" }, - { TQRGB(188,143,143), "rosybrown" }, - { TQRGB(255,193,193), "rosybrown1" }, - { TQRGB(238,180,180), "rosybrown2" }, - { TQRGB(205,155,155), "rosybrown3" }, - { TQRGB(139,105,105), "rosybrown4" }, - { TQRGB( 65,105,225), "royalblue" }, - { TQRGB( 72,118,255), "royalblue1" }, - { TQRGB( 67,110,238), "royalblue2" }, - { TQRGB( 58, 95,205), "royalblue3" }, - { TQRGB( 39, 64,139), "royalblue4" }, - { TQRGB(139, 69, 19), "saddlebrown" }, - { TQRGB(250,128,114), "salmon" }, - { TQRGB(255,140,105), "salmon1" }, - { TQRGB(238,130, 98), "salmon2" }, - { TQRGB(205,112, 84), "salmon3" }, - { TQRGB(139, 76, 57), "salmon4" }, - { TQRGB(244,164, 96), "sandybrown" }, - { TQRGB( 46,139, 87), "seagreen" }, - { TQRGB( 84,255,159), "seagreen1" }, - { TQRGB( 78,238,148), "seagreen2" }, - { TQRGB( 67,205,128), "seagreen3" }, - { TQRGB( 46,139, 87), "seagreen4" }, - { TQRGB(255,245,238), "seashell" }, - { TQRGB(255,245,238), "seashell1" }, - { TQRGB(238,229,222), "seashell2" }, - { TQRGB(205,197,191), "seashell3" }, - { TQRGB(139,134,130), "seashell4" }, - { TQRGB(160, 82, 45), "sienna" }, - { TQRGB(255,130, 71), "sienna1" }, - { TQRGB(238,121, 66), "sienna2" }, - { TQRGB(205,104, 57), "sienna3" }, - { TQRGB(139, 71, 38), "sienna4" }, - { TQRGB(135,206,235), "skyblue" }, - { TQRGB(135,206,255), "skyblue1" }, - { TQRGB(126,192,238), "skyblue2" }, - { TQRGB(108,166,205), "skyblue3" }, - { TQRGB( 74,112,139), "skyblue4" }, - { TQRGB(106, 90,205), "slateblue" }, - { TQRGB(131,111,255), "slateblue1" }, - { TQRGB(122,103,238), "slateblue2" }, - { TQRGB(105, 89,205), "slateblue3" }, - { TQRGB( 71, 60,139), "slateblue4" }, - { TQRGB(112,128,144), "slategray" }, - { TQRGB(198,226,255), "slategray1" }, - { TQRGB(185,211,238), "slategray2" }, - { TQRGB(159,182,205), "slategray3" }, - { TQRGB(108,123,139), "slategray4" }, - { TQRGB(112,128,144), "slategrey" }, - { TQRGB(255,250,250), "snow" }, - { TQRGB(255,250,250), "snow1" }, - { TQRGB(238,233,233), "snow2" }, - { TQRGB(205,201,201), "snow3" }, - { TQRGB(139,137,137), "snow4" }, - { TQRGB( 0,255,127), "springgreen" }, - { TQRGB( 0,255,127), "springgreen1" }, - { TQRGB( 0,238,118), "springgreen2" }, - { TQRGB( 0,205,102), "springgreen3" }, - { TQRGB( 0,139, 69), "springgreen4" }, - { TQRGB( 70,130,180), "steelblue" }, - { TQRGB( 99,184,255), "steelblue1" }, - { TQRGB( 92,172,238), "steelblue2" }, - { TQRGB( 79,148,205), "steelblue3" }, - { TQRGB( 54,100,139), "steelblue4" }, - { TQRGB(210,180,140), "tan" }, - { TQRGB(255,165, 79), "tan1" }, - { TQRGB(238,154, 73), "tan2" }, - { TQRGB(205,133, 63), "tan3" }, - { TQRGB(139, 90, 43), "tan4" }, - { TQRGB(216,191,216), "thistle" }, - { TQRGB(255,225,255), "thistle1" }, - { TQRGB(238,210,238), "thistle2" }, - { TQRGB(205,181,205), "thistle3" }, - { TQRGB(139,123,139), "thistle4" }, - { TQRGB(255, 99, 71), "tomato" }, - { TQRGB(255, 99, 71), "tomato1" }, - { TQRGB(238, 92, 66), "tomato2" }, - { TQRGB(205, 79, 57), "tomato3" }, - { TQRGB(139, 54, 38), "tomato4" }, - { TQRGB( 64,224,208), "turquoise" }, - { TQRGB( 0,245,255), "turquoise1" }, - { TQRGB( 0,229,238), "turquoise2" }, - { TQRGB( 0,197,205), "turquoise3" }, - { TQRGB( 0,134,139), "turquoise4" }, - { TQRGB(238,130,238), "violet" }, - { TQRGB(208, 32,144), "violetred" }, - { TQRGB(255, 62,150), "violetred1" }, - { TQRGB(238, 58,140), "violetred2" }, - { TQRGB(205, 50,120), "violetred3" }, - { TQRGB(139, 34, 82), "violetred4" }, - { TQRGB(245,222,179), "wheat" }, - { TQRGB(255,231,186), "wheat1" }, - { TQRGB(238,216,174), "wheat2" }, - { TQRGB(205,186,150), "wheat3" }, - { TQRGB(139,126,102), "wheat4" }, - { TQRGB(255,255,255), "white" }, - { TQRGB(245,245,245), "whitesmoke" }, - { TQRGB(255,255, 0), "yellow" }, - { TQRGB(255,255, 0), "yellow1" }, - { TQRGB(238,238, 0), "yellow2" }, - { TQRGB(205,205, 0), "yellow3" }, - { TQRGB(139,139, 0), "yellow4" }, - { TQRGB(154,205, 50), "yellowgreen" } }; - -#if defined(Q_C_CALLBACKS) -extern "C" { -#endif - -#ifdef Q_OS_TEMP -static int __cdecl rgb_cmp( const void *d1, const void *d2 ) -#else -static int rgb_cmp( const void *d1, const void *d2 ) -#endif -{ - return tqstricmp( ((RGBData *)d1)->name, ((RGBData *)d2)->name ); -} - -#if defined(Q_C_CALLBACKS) -} -#endif - -bool qt_get_named_rgb( const char *name, TQRgb* rgb ) -{ - TQ_LONG len = strlen(name)+1; - char *name_no_space = (char *)malloc(len); - for(TQ_LONG o=0,i=0; i < len; i++) { - if(name[i] != '\t' && name[i] != ' ') - name_no_space[o++] = name[i]; - } - - RGBData x; - x.name = name_no_space; - // Funtion bsearch() is supposed to be - // void *bsearch(const void *key, const void *base, ... - // So why (char*)? Are there broken bsearch() declarations out there? - RGBData *r = (RGBData*)bsearch((char*)&x, (char*)rgbTbl, rgbTblSize, - sizeof(RGBData), rgb_cmp); - free(name_no_space); - if ( r ) { - *rgb = r->value; - return TRUE; - } else { - return FALSE; - } -} - -uint qt_get_rgb_val( const char *name ) -{ - TQRgb r = 0; - qt_get_named_rgb(name,&r); - return r; -} -#ifndef TQT_NO_STRINGLIST -TQStringList TQColor::colorNames() -{ - int i = 0; - TQStringList lst; - for ( i = 0; i < rgbTblSize; i++ ) - lst << rgbTbl[i].name; - - return lst; -} -#endif -#else - -bool qt_get_named_rgb( const char *, TQRgb* ) -{ - return FALSE; -} - -uint qt_get_rgb_val( const char * ) -{ - return 0; -} -#ifndef TQT_NO_STRINGLIST -TQStringList TQColor::colorNames() -{ - return TQStringList(); -} -#endif -#endif // TQT_NO_COLORNAMES diff --git a/src/kernel/qcolor_p.h b/src/kernel/qcolor_p.h deleted file mode 100644 index d85cbf362..000000000 --- a/src/kernel/qcolor_p.h +++ /dev/null @@ -1,66 +0,0 @@ -/**************************************************************************** -** -** Named color support for non-X platforms. -** The color names have been borrowed from X. -** -** Created : 000228 -** -** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#ifndef TQCOLOR_P_H -#define TQCOLOR_P_H - - -// -// W A R N I N G -// ------------- -// -// This file is not part of the TQt API. It exists for the convenience -// of tqmenudata.cpp, tqmenubar.cpp, tqmenubar.cpp, tqpopupmenu.cpp, -// qmotifstyle.cpp and qwindowssstyle.cpp. This header file may change -// from version to version without notice, or even be removed. -// -// We mean it. -// -// - -#ifndef QT_H -#endif // QT_H - -extern uint qt_get_rgb_val( const char *name ); -extern bool qt_get_named_rgb( const char *, TQRgb* ); -extern void qt_reset_color_avail(); - -#endif diff --git a/src/kernel/qcolor_x11.cpp b/src/kernel/qcolor_x11.cpp deleted file mode 100644 index b223222a9..000000000 --- a/src/kernel/qcolor_x11.cpp +++ /dev/null @@ -1,841 +0,0 @@ -/**************************************************************************** -** -** Implementation of TQColor class for X11 -** -** Created : 940112 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#include "ntqcolor.h" -#include "qcolor_p.h" -#include "string.h" -#include "ntqpaintdevice.h" -#include "ntqapplication.h" -#include "qapplication_p.h" -#include "qt_x11_p.h" - -// NOT REVISED - -/***************************************************************************** - The color dictionary speeds up color allocation significantly for X11. - When there are no more colors, TQColor::alloc() will set the colors_avail - flag to FALSE and try to find the nearest color. - NOTE: From deep within the event loop, the colors_avail flag is reset to - TRUE (calls the function qt_reset_color_avail()), because some other - application might free its colors, thereby making them available for - this TQt application. - *****************************************************************************/ - -#include "tqintdict.h" - -struct TQColorData { - uint pix; // allocated pixel value - int context; // allocation context -}; - -typedef TQIntDict TQColorDict; -typedef TQIntDictIterator TQColorDictIt; -static int current_alloc_context = 0; // current color alloc context -static const uint col_std_dict = 419; -static const uint col_large_dict = 18397; - -class TQColorScreenData { -public: - TQColorScreenData() - { - colorDict = 0; - colors_avail = TRUE; - g_vis = 0; - g_carr = 0; - g_carr_fetch = TRUE; - g_cells = 0; - g_our_alloc = 0; - color_reduce = FALSE; - } - - TQColorDict *colorDict; // dict of allocated colors - bool colors_avail; // X colors available - bool g_truecolor; // truecolor visual - Visual *g_vis; // visual - XColor *g_carr; // color array - bool g_carr_fetch; // perform XQueryColors? - int g_cells; // number of entries in g_carr - bool *g_our_alloc; // our allocated colors - uint red_mask , green_mask , blue_mask; - int red_shift, green_shift, blue_shift; - bool color_reduce; - int col_div_r; - int col_div_g; - int col_div_b; -}; - -static int screencount = 0; -static TQColorScreenData **screendata = 0; // array of screendata pointers - - -/* - This function is called from the event loop. It resets the colors_avail - flag so that the application can retry to allocate read-only colors - that other applications may have deallocated lately. - - The g_our_alloc and g_carr are global arrays that optimize color - approximation when there are no more colors left to allocate. -*/ - -void qt_reset_color_avail() -{ - int i; - for ( i = 0; i < screencount; i++ ) { - screendata[i]->colors_avail = TRUE; - screendata[i]->g_carr_fetch = TRUE; // do XQueryColors if !colors_avail - } -} - - -/* - Finds the nearest color. -*/ - -static int find_nearest_color( int r, int g, int b, int* mindist_out, - TQColorScreenData *sd ) -{ - int mincol = -1; - int mindist = 200000; - int rx, gx, bx, dist; - XColor *xc = &sd->g_carr[0]; - for ( int i=0; ig_cells; i++ ) { - rx = r - (xc->red >> 8); - gx = g - (xc->green >> 8); - bx = b - (xc->blue>> 8); - dist = rx*rx + gx*gx + bx*bx; // calculate distance - if ( dist < mindist ) { // minimal? - mindist = dist; - mincol = i; - } - xc++; - } - *mindist_out = mindist; - return mincol; -} - - -/***************************************************************************** - TQColor misc internal functions - *****************************************************************************/ - -static int highest_bit( uint v ) -{ - int i; - uint b = (uint)1 << 31; // get pos of highest bit in v - for ( i=31; ((b & v) == 0) && i>=0; i-- ) - b >>= 1; - return i; -} - - -/***************************************************************************** - TQColor static member functions - *****************************************************************************/ - -/*! - Returns the maximum number of colors supported by the underlying - window system if the window system uses a palette. - - Otherwise returns -1. Use numBitPlanes() to calculate the available - colors in that case. -*/ - -int TQColor::maxColors() -{ - Visual *visual = (Visual *) TQPaintDevice::x11AppVisual(); - if (visual->c_class & 1) - return TQPaintDevice::x11AppCells(); - return -1; -} - -/*! - Returns the number of color bit planes for the underlying window - system. - - The returned value is equal to the default pixmap depth. - - \sa TQPixmap::defaultDepth() -*/ - -int TQColor::numBitPlanes() -{ - return TQPaintDevice::x11AppDepth(); -} - - -/*! - Internal initialization required for TQColor. - This function is called from the TQApplication constructor. - - \sa cleanup() -*/ - -void TQColor::initialize() -{ - static const int blackIdx = 2; - static const int whiteIdx = 3; - - if ( color_init ) // already initialized - return; - color_init = TRUE; - - Display *dpy = TQPaintDevice::x11AppDisplay(); - int spec = TQApplication::colorSpec(); - - screencount = ScreenCount( dpy ); - screendata = new TQColorScreenData*[ screencount ]; - - int scr; - for ( scr = 0; scr < screencount; ++scr ) { - screendata[scr] = new TQColorScreenData; - screendata[scr]->g_vis = (Visual *) TQPaintDevice::x11AppVisual( scr ); - screendata[scr]->g_truecolor = screendata[scr]->g_vis->c_class == TrueColor - || screendata[scr]->g_vis->c_class == DirectColor; - - int ncols = TQPaintDevice::x11AppCells( scr ); - - if ( screendata[scr]->g_truecolor ) { - if (scr == DefaultScreen(dpy)) - colormodel = d32; - } else { - if (scr == DefaultScreen(dpy)) - colormodel = d8; - - // Create the g_our_alloc array, which remembers which color pixels - // we allocated. - screendata[scr]->g_cells = TQMIN(ncols,256); - screendata[scr]->g_carr = new XColor[screendata[scr]->g_cells]; - TQ_CHECK_PTR( screendata[scr]->g_carr ); - memset( screendata[scr]->g_carr, 0, - screendata[scr]->g_cells*sizeof(XColor) ); - screendata[scr]->g_carr_fetch = TRUE; // run XQueryColors on demand - screendata[scr]->g_our_alloc = new bool[screendata[scr]->g_cells]; - TQ_CHECK_PTR( screendata[scr]->g_our_alloc ); - memset( screendata[scr]->g_our_alloc, FALSE, - screendata[scr]->g_cells*sizeof(bool) ); - XColor *xc = &screendata[scr]->g_carr[0]; - for ( int i=0; ig_cells; i++ ) { - xc->pixel = i; // g_carr[i] = color i - xc++; - } - } - - int dictsize; - if ( screendata[scr]->g_truecolor ) { // truecolor - dictsize = 1; // will not need color dict - screendata[scr]->red_mask = (uint)screendata[scr]->g_vis->red_mask; - screendata[scr]->green_mask = (uint)screendata[scr]->g_vis->green_mask; - screendata[scr]->blue_mask = (uint)screendata[scr]->g_vis->blue_mask; - screendata[scr]->red_shift = - highest_bit( screendata[scr]->red_mask ) - 7; - screendata[scr]->green_shift = - highest_bit( screendata[scr]->green_mask ) - 7; - screendata[scr]->blue_shift = - highest_bit( screendata[scr]->blue_mask ) - 7; - } else { - dictsize = col_std_dict; - } - screendata[scr]->colorDict = new TQColorDict(dictsize); // create dictionary - TQ_CHECK_PTR( screendata[scr]->colorDict ); - - if ( spec == (int)TQApplication::ManyColor ) { - screendata[scr]->color_reduce = TRUE; - - switch ( qt_ncols_option ) { - case 216: - // 6:6:6 - screendata[scr]->col_div_r = screendata[scr]->col_div_g = - screendata[scr]->col_div_b = (255/(6-1)); - break; - default: { - // 2:3:1 proportions, solved numerically - if ( qt_ncols_option > 255 ) qt_ncols_option = 255; - if ( qt_ncols_option < 1 ) qt_ncols_option = 1; - int nr = 2; - int ng = 2; - int nb = 2; - for (;;) { - if ( nb*2 < nr && (nb+1)*nr*ng < qt_ncols_option ) - nb++; - else if ( nr*3 < ng*2 && nb*(nr+1)*ng < qt_ncols_option ) - nr++; - else if ( nb*nr*(ng+1) < qt_ncols_option ) - ng++; - else break; - } - qt_ncols_option = nr*ng*nb; - screendata[scr]->col_div_r = (255/(nr-1)); - screendata[scr]->col_div_g = (255/(ng-1)); - screendata[scr]->col_div_b = (255/(nb-1)); - } - } - } - } - - scr = TQPaintDevice::x11AppScreen(); - - // Initialize global color objects - if ( TQPaintDevice::x11AppDefaultVisual(scr) && - TQPaintDevice::x11AppDefaultColormap(scr) ) { - globalColors()[blackIdx].setPixel((uint) BlackPixel(dpy, scr)); - globalColors()[whiteIdx].setPixel((uint) WhitePixel(dpy, scr)); - } else { - globalColors()[blackIdx].alloc(scr); - globalColors()[whiteIdx].alloc(scr); - } - -#if 0 /* 0 == allocate colors on demand */ - setLazyAlloc( FALSE ); // allocate global colors - ((TQColor*)(&darkGray))-> alloc(); - ((TQColor*)(&gray))-> alloc(); - ((TQColor*)(&lightGray))-> alloc(); - ((TQColor*)(&::red))-> alloc(); - ((TQColor*)(&::green))-> alloc(); - ((TQColor*)(&::blue))-> alloc(); - ((TQColor*)(&cyan))-> alloc(); - ((TQColor*)(&magenta))-> alloc(); - ((TQColor*)(&yellow))-> alloc(); - ((TQColor*)(&darkRed))-> alloc(); - ((TQColor*)(&darkGreen))-> alloc(); - ((TQColor*)(&darkBlue))-> alloc(); - ((TQColor*)(&darkCyan))-> alloc(); - ((TQColor*)(&darkMagenta))-> alloc(); - ((TQColor*)(&darkYellow))-> alloc(); - setLazyAlloc( TRUE ); -#endif -} - -/*! - Internal clean up required for TQColor. - This function is called from the TQApplication destructor. - - \sa initialize() -*/ - -void TQColor::cleanup() -{ - if ( !color_init ) - return; - color_init = FALSE; - int scr; - for ( scr = 0; scr < screencount; scr++ ) { - if ( screendata[scr]->g_carr ) { - delete [] screendata[scr]->g_carr; - screendata[scr]->g_carr = 0; - } - if ( screendata[scr]->g_our_alloc ) { - delete [] screendata[scr]->g_our_alloc; - screendata[scr]->g_our_alloc = 0; - } - if ( screendata[scr]->colorDict ) { - screendata[scr]->colorDict->setAutoDelete( TRUE ); - screendata[scr]->colorDict->clear(); - delete screendata[scr]->colorDict; - screendata[scr]->colorDict = 0; - } - delete screendata[scr]; - screendata[scr] = 0; - } - delete [] screendata; - screendata = 0; - screencount = 0; -} - - -/***************************************************************************** - TQColor member functions - *****************************************************************************/ - -/*! - \internal - Allocates the color on screen \a screen. Only used in X11. - - \sa alloc(), pixel() -*/ -uint TQColor::alloc( int screen ) -{ - Display *dpy = TQPaintDevice::x11AppDisplay(); - if ( screen < 0 ) - screen = TQPaintDevice::x11AppScreen(); - if ( !color_init ) - return dpy ? (uint)BlackPixel(dpy, screen) : 0; - int r = tqRed(d.argb); - int g = tqGreen(d.argb); - int b = tqBlue(d.argb); - uint pix = 0; - TQColorScreenData *sd = screendata[screen]; - if ( sd->g_truecolor ) { // truecolor: map to pixel - r = sd->red_shift > 0 ? r << sd->red_shift : r >> -sd->red_shift; - g = sd->green_shift > 0 ? g << sd->green_shift : g >> -sd->green_shift; - b = sd->blue_shift > 0 ? b << sd->blue_shift : b >> -sd->blue_shift; - pix = (b & sd->blue_mask) | (g & sd->green_mask) | (r & sd->red_mask) - | ~(sd->blue_mask | sd->green_mask | sd->red_mask); - if (TQPaintDevice::x11AppDepth(screen) == 32) { - int a = tqAlpha(d.argb); - pix = pix & 0x00ffffff; - pix = pix | (a << 24); - } - if ( screen == TQPaintDevice::x11AppScreen() ) { - d.d32.pix = pix; - } - return pix; - } - TQColorData *c = sd->colorDict->find( (long)(d.argb) ); - if ( c ) { // found color in dictionary - pix = c->pix; - if ( screen == TQPaintDevice::x11AppScreen() ) { - d.d8.invalid = FALSE; // color ok - d.d8.dirty = FALSE; - d.d8.pix = pix; // use same pixel value - if ( c->context != current_alloc_context ) { - c->context = 0; // convert to default context - sd->g_our_alloc[pix] = TRUE; // reuse without XAllocColor - } - } - return pix; - } - - XColor col; - col.red = r << 8; - col.green = g << 8; - col.blue = b << 8; - - bool try_again = FALSE; - bool try_alloc = !sd->color_reduce; - int try_count = 0; - - do { - // This loop is run until we manage to either allocate or - // find an approximate color, it stops after a few iterations. - - try_again = FALSE; - - if ( try_alloc && sd->colors_avail && - XAllocColor(dpy, TQPaintDevice::x11AppColormap( screen ),&col) ) { - // We could allocate the color - pix = (uint) col.pixel; - if ( screen == TQPaintDevice::x11AppScreen() ) { - d.d8.pix = pix; - d.d8.invalid = FALSE; - d.d8.dirty = FALSE; - sd->g_carr[d.d8.pix] = col; // update color array - if ( current_alloc_context == 0 ) - sd->g_our_alloc[d.d8.pix] = TRUE; // reuse without XAllocColor - } - } else { - // No available colors, or we did not want to allocate one - int i; - sd->colors_avail = FALSE; // no more available colors - if ( sd->g_carr_fetch ) { // refetch color array - sd->g_carr_fetch = FALSE; - XQueryColors( dpy, TQPaintDevice::x11AppColormap( screen ), sd->g_carr, - sd->g_cells ); - } - int mindist; - i = find_nearest_color( r, g, b, &mindist, sd ); - - if ( mindist != 0 && !try_alloc ) { - // Not an exact match with an existing color - int rr = ((r+sd->col_div_r/2)/sd->col_div_r)*sd->col_div_r; - int rg = ((g+sd->col_div_g/2)/sd->col_div_g)*sd->col_div_g; - int rb = ((b+sd->col_div_b/2)/sd->col_div_b)*sd->col_div_b; - int rx = rr - r; - int gx = rg - g; - int bx = rb - b; - int dist = rx*rx + gx*gx + bx*bx; // calculate distance - if ( dist < mindist ) { - // reduced color is closer - try to alloc it - r = rr; - g = rg; - b = rb; - col.red = r << 8; - col.green = g << 8; - col.blue = b << 8; - try_alloc = TRUE; - try_again = TRUE; - sd->colors_avail = TRUE; - continue; // Try alloc reduced color - } - } - - if ( i == -1 ) { // no nearest color?! - int unused, value; - hsv(&unused, &unused, &value); - if (value < 128) { // dark, use black - d.argb = tqRgb(0,0,0); - pix = (uint)BlackPixel( dpy, screen ); - if ( screen == TQPaintDevice::x11AppScreen() ) { - d.d8.invalid = FALSE; - d.d8.dirty = FALSE; - d.d8.pix = pix; - } - } else { // light, use white - d.argb = tqRgb(0xff,0xff,0xff); - pix = (uint)WhitePixel( dpy, screen ); - if ( screen == TQPaintDevice::x11AppScreen() ) { - d.d8.invalid = FALSE; - d.d8.dirty = FALSE; - d.d8.pix = pix; - } - } - return pix; - } - if ( sd->g_our_alloc[i] ) { // we've already allocated it - ; // i == g_carr[i].pixel - } else { - // Try to allocate existing color - col = sd->g_carr[i]; - if ( XAllocColor(dpy, TQPaintDevice::x11AppColormap( screen ), &col) ) { - i = (uint)col.pixel; - sd->g_carr[i] = col; // update color array - if ( screen == TQPaintDevice::x11AppScreen() ) { - if ( current_alloc_context == 0 ) - sd->g_our_alloc[i] = TRUE; // only in the default context - } - } else { - // Oops, it's gone again - try_count++; - try_again = TRUE; - sd->colors_avail = TRUE; - sd->g_carr_fetch = TRUE; - } - } - if ( !try_again ) { // got it - pix = (uint)sd->g_carr[i].pixel; - if ( screen == TQPaintDevice::x11AppScreen() ) { - d.d8.invalid = FALSE; - d.d8.dirty = FALSE; - d.d8.pix = pix; // allocated X11 color - } - } - } - - } while ( try_again && try_count < 2 ); - - if ( try_again ) { // no hope of allocating color - int unused, value; - hsv(&unused, &unused, &value); - if (value < 128) { // dark, use black - d.argb = tqRgb(0,0,0); - pix = (uint)BlackPixel( dpy, screen ); - if ( screen == TQPaintDevice::x11AppScreen() ) { - d.d8.invalid = FALSE; - d.d8.dirty = FALSE; - d.d8.pix = pix; - } - } else { // light, use white - d.argb = tqRgb(0xff,0xff,0xff); - pix = (uint)WhitePixel( dpy, screen ); - if ( screen == TQPaintDevice::x11AppScreen() ) { - d.d8.invalid = FALSE; - d.d8.dirty = FALSE; - d.d8.pix = pix; - } - } - return pix; - } - // All colors outside context 0 must go into the dictionary - bool many = sd->colorDict->count() >= sd->colorDict->size() * 8; - if ( many && sd->colorDict->size() == col_std_dict ) { - sd->colorDict->resize( col_large_dict ); - } - if ( !many || current_alloc_context != 0 ) { - c = new TQColorData; // insert into color dict - TQ_CHECK_PTR( c ); - c->pix = pix; - c->context = current_alloc_context; - sd->colorDict->insert( (long)d.argb, c ); // store color in dict - } - return pix; -} - -/*! - Allocates the RGB color and returns the pixel value. - - Allocating a color means to obtain a pixel value from the RGB - specification. The pixel value is an index into the global color - table, but should be considered an arbitrary platform-dependent value. - - The pixel() function calls alloc() if necessary, so in general you - don't need to call this function. - - \sa enterAllocContext() -*/ -// ### 4.0 - remove me? -uint TQColor::alloc() -{ - return alloc( -1 ); -} - -/*! - \overload - - Returns the pixel value for screen \a screen. - - This value is used by the underlying window system to refer to a color. - It can be thought of as an index into the display hardware's color table, - but the value is an arbitrary 32-bit value. - - \sa alloc() -*/ -uint TQColor::pixel( int screen ) const -{ - if (screen != TQPaintDevice::x11AppScreen() && - // don't allocate color0 or color1, they have fixed pixel - // values for all screens - d.argb != tqRgba(255, 255, 255, 1) && d.argb != tqRgba(0, 0, 0, 1)) - return ((TQColor*)this)->alloc( screen ); - return pixel(); -} - - -void TQColor::setSystemNamedColor( const TQString& name ) -{ - // setSystemNamedColor should look up rgb values from the built in - // color tables first (see qcolor_p.cpp), and failing that, use - // the window system's interface for translating names to rgb values... - // we do this so that things like uic can load an XPM file with named colors - // and convert it to a png without having to use window system functions... - d.argb = qt_get_rgb_val( name.latin1() ); - TQRgb rgb; - if ( qt_get_named_rgb( name.latin1(), &rgb ) ) { - setRgb( tqRed(rgb), tqGreen(rgb), tqBlue(rgb) ); - if ( colormodel == d8 ) { - d.d8.invalid = FALSE; - d.d8.dirty = TRUE; - d.d8.pix = 0; - } else { - alloc(); - } - } else if ( !color_init ) { -#if defined(QT_CHECK_STATE) - tqWarning( "TQColor::setSystemNamedColor: Cannot perform this operation " - "because TQApplication does not exist" ); -#endif - // set color to invalid - *this = TQColor(); - } else { - XColor col, hw_col; - if ( XLookupColor(TQPaintDevice::x11AppDisplay(), - TQPaintDevice::x11AppColormap(), name.latin1(), - &col, &hw_col) ) { - setRgb( col.red>>8, col.green>>8, col.blue>>8 ); - } else { - // set color to invalid - *this = TQColor(); - } - } -} - - -#define MAX_CONTEXTS 16 -static int context_stack[MAX_CONTEXTS]; -static int context_ptr = 0; - -static void init_context_stack() -{ - static bool did_init = FALSE; - if ( !did_init ) { - did_init = TRUE; - context_stack[0] = current_alloc_context = 0; - } -} - - -/*! - Enters a color allocation context and returns a non-zero unique - identifier. - - Color allocation contexts are useful for programs that need to - allocate many colors and throw them away later, like image - viewers. The allocation context functions work for true color - displays as well as for colormap displays, except that - TQColor::destroyAllocContext() does nothing for true color. - - Example: - \code - TQPixmap loadPixmap( TQString fileName ) - { - static int alloc_context = 0; - if ( alloc_context ) - TQColor::destroyAllocContext( alloc_context ); - alloc_context = TQColor::enterAllocContext(); - TQPixmap pm( fileName ); - TQColor::leaveAllocContext(); - return pm; - } - \endcode - - The example code loads a pixmap from file. It frees up all colors - that were allocated the last time loadPixmap() was called. - - The initial/default context is 0. TQt keeps a list of colors - associated with their allocation contexts. You can call - destroyAllocContext() to get rid of all colors that were allocated - in a specific context. - - Calling enterAllocContext() enters an allocation context. The - allocation context lasts until you call leaveAllocContext(). - TQColor has an internal stack of allocation contexts. Each call to - enterAllocContex() must have a corresponding leaveAllocContext(). - - \code - // context 0 active - int c1 = TQColor::enterAllocContext(); // enter context c1 - // context c1 active - int c2 = TQColor::enterAllocContext(); // enter context c2 - // context c2 active - TQColor::leaveAllocContext(); // leave context c2 - // context c1 active - TQColor::leaveAllocContext(); // leave context c1 - // context 0 active - // Now, free all colors that were allocated in context c2 - TQColor::destroyAllocContext( c2 ); - \endcode - - You may also want to set the application's color specification. - See TQApplication::setColorSpec() for more information. - - \sa leaveAllocContext(), currentAllocContext(), destroyAllocContext(), - TQApplication::setColorSpec() -*/ - -int TQColor::enterAllocContext() -{ - static int context_seq_no = 0; - init_context_stack(); - if ( context_ptr+1 == MAX_CONTEXTS ) { -#if defined(QT_CHECK_STATE) - tqWarning( "TQColor::enterAllocContext: Context stack overflow" ); -#endif - return 0; - } - current_alloc_context = context_stack[++context_ptr] = ++context_seq_no; - return current_alloc_context; -} - - -/*! - Leaves a color allocation context. - - See enterAllocContext() for a detailed explanation. - - \sa enterAllocContext(), currentAllocContext() -*/ - -void TQColor::leaveAllocContext() -{ - init_context_stack(); - if ( context_ptr == 0 ) { -#if defined(QT_CHECK_STATE) - tqWarning( "TQColor::leaveAllocContext: Context stack underflow" ); -#endif - return; - } - current_alloc_context = context_stack[--context_ptr]; -} - - -/*! - Returns the current color allocation context. - - The default context is 0. - - \sa enterAllocContext(), leaveAllocContext() -*/ - -int TQColor::currentAllocContext() -{ - return current_alloc_context; -} - - -/*! - Destroys a color allocation context, \e context. - - This function deallocates all colors that were allocated in the - specified \a context. If \a context == -1, it frees up all colors - that the application has allocated. If \a context == -2, it frees - up all colors that the application has allocated, except those in - the default context. - - The function does nothing for true color displays. - - \sa enterAllocContext(), alloc() -*/ - -void TQColor::destroyAllocContext( int context ) -{ - init_context_stack(); - if ( !color_init ) - return; - - int screen; - for ( screen = 0; screen < screencount; ++screen ) { - if ( screendata[screen]->g_truecolor ) - continue; - - ulong pixels[256]; - bool freeing[256]; - memset( freeing, FALSE, screendata[screen]->g_cells*sizeof(bool) ); - TQColorData *d; - TQColorDictIt it( *screendata[screen]->colorDict ); - int i = 0; - uint rgbv; - while ( (d=it.current()) ) { - rgbv = (uint)it.currentKey(); - if ( (d->context || context==-1) && - (d->context == context || context < 0) ) { - if ( !screendata[screen]->g_our_alloc[d->pix] && !freeing[d->pix] ) { - // will free this color - pixels[i++] = d->pix; - freeing[d->pix] = TRUE; - } - // remove from dict - screendata[screen]->colorDict->remove( (long)rgbv ); - } - ++it; - } - if ( i ) - XFreeColors( TQPaintDevice::x11AppDisplay(), - TQPaintDevice::x11AppColormap( screen ), - pixels, i, 0 ); - } -} diff --git a/src/kernel/qdnd_x11.cpp b/src/kernel/qdnd_x11.cpp index 0a51b9f2e..accf14209 100644 --- a/src/kernel/qdnd_x11.cpp +++ b/src/kernel/qdnd_x11.cpp @@ -53,7 +53,7 @@ #include "tqobjectlist.h" #include "ntqcursor.h" #include "tqbitmap.h" -#include "ntqpainter.h" +#include "tqpainter.h" #include "qt_x11_p.h" diff --git a/src/kernel/qdrawutil.cpp b/src/kernel/qdrawutil.cpp index c98ef3dc4..7e571418f 100644 --- a/src/kernel/qdrawutil.cpp +++ b/src/kernel/qdrawutil.cpp @@ -43,7 +43,7 @@ #include "tqbitmap.h" #include "ntqpixmapcache.h" #include "ntqapplication.h" -#include "ntqpainter.h" +#include "tqpainter.h" /*! \relates TQPainter diff --git a/src/kernel/qeventloop_x11.cpp b/src/kernel/qeventloop_x11.cpp index bb6f343c2..db0bb4e71 100644 --- a/src/kernel/qeventloop_x11.cpp +++ b/src/kernel/qeventloop_x11.cpp @@ -40,7 +40,7 @@ #include "ntqeventloop.h" #include "ntqapplication.h" #include "tqbitarray.h" -#include "qcolor_p.h" +#include "tqcolor_p.h" #include "qt_x11_p.h" #if defined(TQT_THREAD_SUPPORT) diff --git a/src/kernel/qeventloop_x11_glib.cpp b/src/kernel/qeventloop_x11_glib.cpp index e000b0ef4..ff64cb93c 100644 --- a/src/kernel/qeventloop_x11_glib.cpp +++ b/src/kernel/qeventloop_x11_glib.cpp @@ -43,7 +43,7 @@ #include "ntqeventloop.h" #include "ntqapplication.h" #include "tqbitarray.h" -#include "qcolor_p.h" +#include "tqcolor_p.h" #include "qt_x11_p.h" #if defined(TQT_THREAD_SUPPORT) diff --git a/src/kernel/qfont.cpp b/src/kernel/qfont.cpp deleted file mode 100644 index 8910d7a11..000000000 --- a/src/kernel/qfont.cpp +++ /dev/null @@ -1,3313 +0,0 @@ -/**************************************************************************** -** -** Implementation of TQFont, TQFontMetrics and TQFontInfo classes -** -** Created : 941207 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#define QT_FATAL_ASSERT - -#include "ntqfont.h" -#include "ntqfontdatabase.h" -#include "ntqfontmetrics.h" -#include "ntqfontinfo.h" -#include "ntqpainter.h" -#include "tqdict.h" -#include "tqcache.h" -#include "tqdatastream.h" -#include "ntqapplication.h" -#include "ntqcleanuphandler.h" -#include "tqstringlist.h" -#ifdef TQ_WS_MAC -#include "ntqpaintdevicemetrics.h" -#endif - -#include -#include "qfontdata_p.h" -#include "qfontengine_p.h" -#include "qpainter_p.h" -#include "tqtextengine_p.h" - -// #define TQFONTCACHE_DEBUG -#ifdef TQFONTCACHE_DEBUG -# define FC_DEBUG tqDebug -#else -# define FC_DEBUG if (FALSE) tqDebug -#endif - - - - -bool TQFontDef::operator==( const TQFontDef &other ) const -{ - /* - TQFontDef comparison is more complicated than just simple - per-member comparisons. - - When comparing point/pixel sizes, either point or pixelsize - could be -1. in This case we have to compare the non negative - size value. - - This test will fail if the point-sizes differ by 1/2 point or - more or they do not round to the same value. We have to do this - since our API still uses 'int' point-sizes in the API, but store - deci-point-sizes internally. - - To compare the family members, we need to parse the font names - and compare the family/foundry strings separately. This allows - us to compare e.g. "Helvetica" and "Helvetica [Adobe]" with - positive results. - */ - if (pixelSize != -1 && other.pixelSize != -1) { - if (pixelSize != other.pixelSize) - return FALSE; - } else if (pointSize != -1 && other.pointSize != -1) { - if (pointSize != other.pointSize - && (TQABS(pointSize - other.pointSize) >= 5 - || tqRound(pointSize/10.) != tqRound(other.pointSize/10.))) - return FALSE; - } else { - return FALSE; - } - - if (!ignorePitch && !other.ignorePitch && fixedPitch != other.fixedPitch) - return FALSE; - - if (stretch != 0 && other.stretch != 0 && stretch != other.stretch) - return FALSE; - - TQString this_family, this_foundry, other_family, other_foundry; - TQFontDatabase::parseFontName(family, this_foundry, this_family); - TQFontDatabase::parseFontName(other.family, other_foundry, other_family); - - return ( styleHint == other.styleHint - && styleStrategy == other.styleStrategy - && weight == other.weight - && italic == other.italic - && this_family == other_family - && (this_foundry.isEmpty() - || other_foundry.isEmpty() - || this_foundry == other_foundry) -#ifdef TQ_WS_X11 - && addStyle == other.addStyle -#endif // TQ_WS_X11 - ); -} - - - - -TQFontPrivate::TQFontPrivate() - : engineData( 0 ), paintdevice( 0 ), - rawMode( FALSE ), underline( FALSE ), overline( FALSE ), strikeOut( FALSE ), - mask( 0 ) -{ -#ifdef TQ_WS_X11 - screen = TQPaintDevice::x11AppScreen(); -#else - screen = 0; -#endif // TQ_WS_X11 -} - -TQFontPrivate::TQFontPrivate( const TQFontPrivate &other ) - : TQShared(), request( other.request ), engineData( 0 ), - paintdevice( other.paintdevice ), screen( other.screen ), - rawMode( other.rawMode ), underline( other.underline ), overline( other.overline ), - strikeOut( other.strikeOut ), mask( other.mask ) -{ -} - -TQFontPrivate::~TQFontPrivate() -{ - if ( engineData ) - engineData->deref(); - engineData = 0; -} - -void TQFontPrivate::resolve( const TQFontPrivate *other ) -{ -#ifdef QT_CHECK_STATE - Q_ASSERT( other != 0 ); -#endif - - if ( ( mask & Complete ) == Complete ) return; - - // assign the unset-bits with the set-bits of the other font def - if ( ! ( mask & Family ) ) - request.family = other->request.family; - - if ( ! ( mask & Size ) ) { - request.pointSize = other->request.pointSize; - request.pixelSize = other->request.pixelSize; - } - - if ( ! ( mask & StyleHint ) ) - request.styleHint = other->request.styleHint; - - if ( ! ( mask & StyleStrategy ) ) - request.styleStrategy = other->request.styleStrategy; - - if ( ! ( mask & Weight ) ) - request.weight = other->request.weight; - - if ( ! ( mask & Italic ) ) - request.italic = other->request.italic; - - if ( ! ( mask & FixedPitch ) ) - request.fixedPitch = other->request.fixedPitch; - - if ( ! ( mask & Stretch ) ) - request.stretch = other->request.stretch; - - if ( ! ( mask & Underline ) ) - underline = other->underline; - - if ( ! ( mask & Overline ) ) - overline = other->overline; - - if ( ! ( mask & StrikeOut ) ) - strikeOut = other->strikeOut; -} - - - - -TQFontEngineData::TQFontEngineData() - : lineWidth( 1 ) -{ -#if defined(TQ_WS_X11) || defined(TQ_WS_WIN) - memset( engines, 0, TQFont::LastPrivateScript * sizeof( TQFontEngine * ) ); -#else - engine = 0; -#endif // TQ_WS_X11 || TQ_WS_WIN -#ifndef TQ_WS_MAC - memset( widthCache, 0, widthCacheSize*sizeof( uchar ) ); -#endif -} - -TQFontEngineData::~TQFontEngineData() -{ -#if defined(TQ_WS_X11) || defined(TQ_WS_WIN) - for ( int i = 0; i < TQFont::LastPrivateScript; i++ ) { - if ( engines[i] ) - engines[i]->deref(); - engines[i] = 0; - } -#else - if ( engine ) - engine->deref(); - engine = 0; -#endif // TQ_WS_X11 || TQ_WS_WIN -} - - - - -/*! - \class TQFont ntqfont.h - \brief The TQFont class specifies a font used for drawing text. - - \ingroup graphics - \ingroup appearance - \ingroup shared - \mainclass - - When you create a TQFont object you specify various attributes that - you want the font to have. TQt will use the font with the specified - attributes, or if no matching font exists, TQt will use the closest - matching installed font. The attributes of the font that is - actually used are retrievable from a TQFontInfo object. If the - window system provides an exact match exactMatch() returns TRUE. - Use TQFontMetrics to get measurements, e.g. the pixel length of a - string using TQFontMetrics::width(). - - Use TQApplication::setFont() to set the application's default font. - - If a choosen X11 font does not include all the characters that - need to be displayed, TQFont will try to find the characters in the - nearest equivalent fonts. When a TQPainter draws a character from a - font the TQFont will report whether or not it has the character; if - it does not, TQPainter will draw an unfilled square. - - Create TQFonts like this: - \code - TQFont serifFont( "Times", 10, Bold ); - TQFont sansFont( "Helvetica [Cronyx]", 12 ); - \endcode - - The attributes set in the constructor can also be set later, e.g. - setFamily(), setPointSize(), setPointSizeFloat(), setWeight() and - setItalic(). The remaining attributes must be set after - contstruction, e.g. setBold(), setUnderline(), setOverline(), - setStrikeOut() and setFixedPitch(). TQFontInfo objects should be - created \e after the font's attributes have been set. A TQFontInfo - object will not change, even if you change the font's - attributes. The corresponding "get" functions, e.g. family(), - pointSize(), etc., return the values that were set, even though - the values used may differ. The actual values are available from a - TQFontInfo object. - - If the requested font family is unavailable you can influence the - \link #fontmatching font matching algorithm\endlink by choosing a - particular \l{TQFont::StyleHint} and \l{TQFont::StyleStrategy} with - setStyleHint(). The default family (corresponding to the current - style hint) is returned by defaultFamily(). - - The font-matching algorithm has a lastResortFamily() and - lastResortFont() in cases where a suitable match cannot be found. - You can provide substitutions for font family names using - insertSubstitution() and insertSubstitutions(). Substitutions can - be removed with removeSubstitution(). Use substitute() to retrieve - a family's first substitute, or the family name itself if it has - no substitutes. Use substitutes() to retrieve a list of a family's - substitutes (which may be empty). - - Every TQFont has a key() which you can use, for example, as the key - in a cache or dictionary. If you want to store a user's font - preferences you could use TQSettings, writing the font information - with toString() and reading it back with fromString(). The - operator<<() and operator>>() functions are also available, but - they work on a data stream. - - It is possible to set the height of characters shown on the screen - to a specified number of pixels with setPixelSize(); however using - setPointSize() has a similar effect and provides device - independence. - - Under the X Window System you can set a font using its system - specific name with setRawName(). - - Loading fonts can be expensive, especially on X11. TQFont contains - extensive optimizations to make the copying of TQFont objects fast, - and to cache the results of the slow window system functions it - depends upon. - - \target fontmatching - The font matching algorithm works as follows: - \list 1 - \i The specified font family is searched for. - \i If not found, the styleHint() is used to select a replacement - family. - \i Each replacement font family is searched for. - \i If none of these are found or there was no styleHint(), "helvetica" - will be searched for. - \i If "helvetica" isn't found TQt will try the lastResortFamily(). - \i If the lastResortFamily() isn't found TQt will try the - lastResortFont() which will always return a name of some kind. - \endlist - - Once a font is found, the remaining attributes are matched in order of - priority: - \list 1 - \i fixedPitch() - \i pointSize() (see below) - \i weight() - \i italic() - \endlist - - If you have a font which matches on family, even if none of the - other attributes match, this font will be chosen in preference to - a font which doesn't match on family but which does match on the - other attributes. This is because font family is the dominant - search criteria. - - The point size is defined to match if it is within 20% of the - requested point size. When several fonts match and are only - distinguished by point size, the font with the closest point size - to the one requested will be chosen. - - The actual family, font size, weight and other font attributes - used for drawing text will depend on what's available for the - chosen family under the window system. A TQFontInfo object can be - used to determine the actual values used for drawing the text. - - Examples: - - \code - TQFont f("Helvetica"); - \endcode - If you had both an Adobe and a Cronyx Helvetica, you might get - either. - - \code - TQFont f1( "Helvetica [Cronyx]" ); // TQt 3.x - TQFont f2( "Cronyx-Helvetica" ); // TQt 2.x compatibility - \endcode - You can specify the foundry you want in the family name. Both fonts, - f1 and f2, in the above example will be set to "Helvetica - [Cronyx]". - - To determine the attributes of the font actually used in the window - system, use a TQFontInfo object, e.g. - \code - TQFontInfo info( f1 ); - TQString family = info.family(); - \endcode - - To find out font metrics use a TQFontMetrics object, e.g. - \code - TQFontMetrics fm( f1 ); - int pixelWidth = fm.width( "How many pixels wide is this text?" ); - int pixelHeight = fm.height(); - \endcode - - For more general information on fonts, see the - \link http://www.nwalsh.com/comp.fonts/FAQ/ comp.fonts FAQ.\endlink - Information on encodings can be found from - \link http://czyborra.com/ Roman Czyborra's\endlink page. - - \sa TQFontMetrics TQFontInfo TQFontDatabase TQApplication::setFont() - TQWidget::setFont() TQPainter::setFont() TQFont::StyleHint - TQFont::Weight -*/ - -/*! - \enum TQFont::Script - - This enum represents \link unicode.html Unicode \endlink allocated - scripts. For exhaustive coverage see \link - http://www.amazon.com/exec/obidos/ASIN/0201616335/trolltech/t The - Unicode Standard Version 3.0 \endlink. The following scripts are - supported: - - Modern European alphabetic scripts (left to right): - - \value Latin consists of most alphabets based on the original Latin alphabet. - \value Greek covers ancient and modern Greek and Coptic. - \value Cyrillic covers the Slavic and non-Slavic languages using - cyrillic alphabets. - \value Armenian contains the Armenian alphabet used with the - Armenian language. - \value Georgian covers at least the language Georgian. - \value Runic covers the known constituents of the Runic alphabets used - by the early and medieval societies in the Germanic, - Scandinavian, and Anglo-Saxon areas. - \value Ogham is an alphabetical script used to write a very early - form of Irish. - \value SpacingModifiers are small signs indicating modifications - to the preceeding letter. - \value CombiningMarks consist of diacritical marks not specific to - a particular alphabet, diacritical marks used in - combination with mathematical and technical symbols, and - glyph encodings applied to multiple letterforms. - - Middle Eastern scripts (right to left): - - \value Hebrew is used for writing Hebrew, Yiddish, and some other languages. - \value Arabic covers the Arabic language as well as Persian, Urdu, - Kurdish and some others. - \value Syriac is used to write the active liturgical languages and - dialects of several Middle Eastern and Southeast Indian - communities. - \value Thaana is used to write the Maledivian Dhivehi language. - - South and Southeast Asian scripts (left to right with few historical exceptions): - - \value Devanagari covers classical Sanskrit and modern Hindi as - well as several other languages. - \value Bengali is a relative to Devanagari employed to write the - Bengali language used in West Bengal/India and Bangladesh - as well as several minority languages. - \value Gurmukhi is another Devanagari relative used to write Punjabi. - \value Gujarati is closely related to Devanagari and used to write - the Gujarati language of the Gujarat state in India. - \value Oriya is used to write the Oriya language of Orissa state/India. - \value Tamil is used to write the Tamil language of Tamil Nadu state/India, - Sri Lanka, Singapore and parts of Malaysia as well as some - minority languages. - \value Telugu is used to write the Telugu language of Andhra - Pradesh state/India and some minority languages. - \value Kannada is another South Indian script used to write the - Kannada language of Karnataka state/India and some minority - languages. - \value Malayalam is used to write the Malayalam language of Kerala - state/India. - \value Sinhala is used for Sri Lanka's majority language Sinhala - and is also employed to write Pali, Sanskrit, and Tamil. - \value Thai is used to write Thai and other Southeast Asian languages. - \value Lao is a language and script quite similar to Thai. - \value Tibetan is the script used to write Tibetan in several - countries like Tibet, the bordering Indian regions and - Nepal. It is also used in the Buddist philosophy and - liturgy of the Mongolian cultural area. - \value Myanmar is mainly used to write the Burmese language of - Myanmar (former Burma). - \value Khmer is the official language of Kampuchea. - - East Asian scripts (traditionally top-down, right to left, modern - often horizontal left to right): - - \value Han consists of the CJK (Chinese, Japanese, Korean) - idiographic characters. - \value Hiragana is a cursive syllabary used to indicate phonetics - and pronounciation of Japanese words. - \value Katakana is a non-cursive syllabic script used to write - Japanese words with visual emphasis and non-Japanese words - in a phonetical manner. - \value Hangul is a Korean script consisting of alphabetic components. - \value Bopomofo is a phonetic alphabet for Chinese (mainly Mandarin). - \value Yi (also called Cuan or Wei) is a syllabary used to write - the Yi language of Southwestern China, Myanmar, Laos, and Vietnam. - - Additional scripts that do not fit well into the script categories above: - - \value Ethiopic is a syllabary used by several Central East African languages. - \value Cherokee is a left-to-right syllabic script used to write - the Cherokee language. - \value CanadianAboriginal consists of the syllabics used by some - Canadian aboriginal societies. - \value Mongolian is the traditional (and recently reintroduced) - script used to write Mongolian. - - Symbols: - - \value CurrencySymbols contains currency symbols not encoded in other scripts. - \value LetterlikeSymbols consists of symbols derived from - ordinary letters of an alphabetical script. - \value NumberForms are provided for compatibility with other - existing character sets. - \value MathematicalOperators consists of encodings for operators, - relations and other symbols like arrows used in a mathematical context. - \value TechnicalSymbols contains representations for control - codes, the space symbol, APL symbols and other symbols - mainly used in the context of electronic data processing. - \value GeometricSymbols covers block elements and geometric shapes. - \value MiscellaneousSymbols consists of a heterogeneous collection - of symbols that do not fit any other Unicode character - block, e.g. Dingbats. - \value EnclosedAndSquare is provided for compatibility with some - East Asian standards. - \value Braille is an international writing system used by blind - people. This script encodes the 256 eight-dot patterns with - the 64 six-dot patterns as a subset. - - \value Tagalog - \value Hanunoo - \value Buhid - \value Tagbanwa - - \value KatakanaHalfWidth - - \value Limbu (Unicode 4.0) - \value TaiLe (Unicode 4.0) - - \value Unicode includes all the above scripts. -*/ - -/*! \internal - - Constructs a font for use on the paint device \a pd using the - specified font \a data. -*/ -TQFont::TQFont( TQFontPrivate *data, TQPaintDevice *pd ) -{ - d = new TQFontPrivate( *data ); - TQ_CHECK_PTR( d ); - d->paintdevice = pd; - - // now a single reference - d->count = 1; -} - -/*! \internal - Detaches the font object from common font data. -*/ -void TQFont::detach() -{ - if (d->count == 1) { - if ( d->engineData ) - d->engineData->deref(); - d->engineData = 0; - - return; - } - - TQFontPrivate *old_d = d; - d = new TQFontPrivate( *old_d ); - - /* - if this font is a copy of the application default font, set the - fontdef mask to zero to indicate that *nothing* has been - explicitly set by the programmer. - */ - const TQFont appfont = TQApplication::font(); - if ( old_d == appfont.d ) - d->mask = 0; - - if ( old_d->deref() ) - delete old_d; -} - -/*! - Constructs a font object that uses the application's default font. - - \sa TQApplication::setFont(), TQApplication::font() -*/ -TQFont::TQFont() -{ - const TQFont appfont = TQApplication::font(); - d = appfont.d; - d->ref(); -} - -/*! - Constructs a font object with the specified \a family, \a - pointSize, \a weight and \a italic settings. - - If \a pointSize is <= 0 it is set to 1. - - The \a family name may optionally also include a foundry name, - e.g. "Helvetica [Cronyx]". (The TQt 2.x syntax, i.e. - "Cronyx-Helvetica", is also supported.) If the \a family is - available from more than one foundry and the foundry isn't - specified, an arbitrary foundry is chosen. If the family isn't - available a family will be set using the \link #fontmatching font - matching\endlink algorithm. - - \sa Weight, setFamily(), setPointSize(), setWeight(), setItalic(), - setStyleHint() TQApplication::font() -*/ -TQFont::TQFont( const TQString &family, int pointSize, int weight, bool italic ) -{ - - d = new TQFontPrivate; - TQ_CHECK_PTR( d ); - - d->mask = TQFontPrivate::Family; - - if (pointSize <= 0) { - pointSize = 12; - } else { - d->mask |= TQFontPrivate::Size; - } - - if (weight < 0) { - weight = Normal; - } else { - d->mask |= TQFontPrivate::Weight | TQFontPrivate::Italic; - } - - d->request.family = family; - d->request.pointSize = pointSize * 10; - d->request.pixelSize = -1; - d->request.weight = weight; - d->request.italic = italic; -} - -/*! - Constructs a font that is a copy of \a font. -*/ -TQFont::TQFont( const TQFont &font ) -{ - d = font.d; - d->ref(); -} - -/*! - Destroys the font object and frees all allocated resources. -*/ -TQFont::~TQFont() -{ - if ( d->deref() ) - delete d; - d = 0; -} - -/*! - Assigns \a font to this font and returns a reference to it. -*/ -TQFont &TQFont::operator=( const TQFont &font ) -{ - if ( font.d != d ) { - if ( d->deref() ) - delete d; - d = font.d; - d->ref(); - } - - return *this; -} - -/*! - Returns the requested font family name, i.e. the name set in the - constructor or the last setFont() call. - - \sa setFamily() substitutes() substitute() -*/ -TQString TQFont::family() const -{ - return d->request.family; -} - -/*! - Sets the family name of the font. The name is case insensitive and - may include a foundry name. - - The \a family name may optionally also include a foundry name, - e.g. "Helvetica [Cronyx]". (The TQt 2.x syntax, i.e. - "Cronyx-Helvetica", is also supported.) If the \a family is - available from more than one foundry and the foundry isn't - specified, an arbitrary foundry is chosen. If the family isn't - available a family will be set using the \link #fontmatching font - matching\endlink algorithm. - - \sa family(), setStyleHint(), TQFontInfo -*/ -void TQFont::setFamily( const TQString &family ) -{ - detach(); - - d->request.family = family; -#if defined(TQ_WS_X11) - d->request.addStyle = TQString::null; -#endif // TQ_WS_X11 - - d->mask |= TQFontPrivate::Family; -} - -/*! - Returns the point size in 1/10ths of a point. - - The returned value will be -1 if the font size has been specified - in pixels. - - \sa pointSize() pointSizeFloat() - */ -int TQFont::deciPointSize() const -{ - return d->request.pointSize; -} - -/*! - Returns the point size of the font. Returns -1 if the font size - was specified in pixels. - - \sa setPointSize() deciPointSize() pointSizeFloat() -*/ -int TQFont::pointSize() const -{ - return d->request.pointSize == -1 ? -1 : (d->request.pointSize + 5) / 10; -} - -/*! - Sets the point size to \a pointSize. The point size must be - greater than zero. - - \sa pointSize() setPointSizeFloat() -*/ -void TQFont::setPointSize( int pointSize ) -{ - if ( pointSize <= 0 ) { - -#if defined(QT_CHECK_RANGE) - tqWarning( "TQFont::setPointSize: Point size <= 0 (%d)", pointSize ); -#endif - - return; - } - - detach(); - - d->request.pointSize = pointSize * 10; - d->request.pixelSize = -1; - - d->mask |= TQFontPrivate::Size; -} - -/*! - Sets the point size to \a pointSize. The point size must be - greater than zero. The requested precision may not be achieved on - all platforms. - - \sa pointSizeFloat() setPointSize() setPixelSize() -*/ -void TQFont::setPointSizeFloat( float pointSize ) -{ - if ( pointSize <= 0.0 ) { -#if defined(QT_CHECK_RANGE) - tqWarning( "TQFont::setPointSize: Point size <= 0 (%f)", pointSize ); -#endif - return; - } - - detach(); - - d->request.pointSize = tqRound(pointSize * 10.0); - d->request.pixelSize = -1; - - d->mask |= TQFontPrivate::Size; -} - -/*! - Returns the point size of the font. Returns -1 if the font size was - specified in pixels. - - \sa pointSize() setPointSizeFloat() pixelSize() TQFontInfo::pointSize() TQFontInfo::pixelSize() -*/ -float TQFont::pointSizeFloat() const -{ - return float( d->request.pointSize == -1 ? -10 : d->request.pointSize ) / 10.0; -} - -/*! - Sets the font size to \a pixelSize pixels. - - Using this function makes the font device dependent. Use - setPointSize() or setPointSizeFloat() to set the size of the font - in a device independent manner. - - \sa pixelSize() -*/ -void TQFont::setPixelSize( int pixelSize ) -{ - if ( pixelSize <= 0 ) { -#if defined(QT_CHECK_RANGE) - tqWarning( "TQFont::setPixelSize: Pixel size <= 0 (%d)", pixelSize ); -#endif - return; - } - - detach(); - - d->request.pixelSize = pixelSize; - d->request.pointSize = -1; - - d->mask |= TQFontPrivate::Size; -} - -/*! - Returns the pixel size of the font if it was set with - setPixelSize(). Returns -1 if the size was set with setPointSize() - or setPointSizeFloat(). - - \sa setPixelSize() pointSize() TQFontInfo::pointSize() TQFontInfo::pixelSize() -*/ -int TQFont::pixelSize() const -{ - return d->request.pixelSize; -} - -/*! \obsolete - - Sets the logical pixel height of font characters when shown on - the screen to \a pixelSize. -*/ -void TQFont::setPixelSizeFloat( float pixelSize ) -{ - setPixelSize( (int)pixelSize ); -} - -/*! - Returns TRUE if italic has been set; otherwise returns FALSE. - - \sa setItalic() -*/ -bool TQFont::italic() const -{ - return d->request.italic; -} - -/*! - If \a enable is TRUE, italic is set on; otherwise italic is set - off. - - \sa italic(), TQFontInfo -*/ -void TQFont::setItalic( bool enable ) -{ - detach(); - - d->request.italic = enable; - d->mask |= TQFontPrivate::Italic; -} - -/*! - Returns the weight of the font which is one of the enumerated - values from \l{TQFont::Weight}. - - \sa setWeight(), Weight, TQFontInfo -*/ -int TQFont::weight() const -{ - return d->request.weight; -} - -/*! - \enum TQFont::Weight - - TQt uses a weighting scale from 0 to 99 similar to, but not the - same as, the scales used in Windows or CSS. A weight of 0 is - ultralight, whilst 99 will be an extremely black. - - This enum contains the predefined font weights: - - \value Light 25 - \value Normal 50 - \value DemiBold 63 - \value Bold 75 - \value Black 87 -*/ - -/*! - Sets the weight the font to \a weight, which should be a value - from the \l TQFont::Weight enumeration. - - \sa weight(), TQFontInfo -*/ -void TQFont::setWeight( int weight ) -{ - if ( weight < 0 || weight > 99 ) { - -#if defined(QT_CHECK_RANGE) - tqWarning( "TQFont::setWeight: Value out of range (%d)", weight ); -#endif - - return; - } - - detach(); - - d->request.weight = weight; - d->mask |= TQFontPrivate::Weight; -} - -/*! - \fn bool TQFont::bold() const - - Returns TRUE if weight() is a value greater than \link Weight - TQFont::Normal \endlink; otherwise returns FALSE. - - \sa weight(), setBold(), TQFontInfo::bold() -*/ - -/*! - \fn void TQFont::setBold( bool enable ) - - If \a enable is true sets the font's weight to \link Weight - TQFont::Bold \endlink; otherwise sets the weight to \link Weight - TQFont::Normal\endlink. - - For finer boldness control use setWeight(). - - \sa bold(), setWeight() -*/ - -/*! - Returns TRUE if underline has been set; otherwise returns FALSE. - - \sa setUnderline() -*/ -bool TQFont::underline() const -{ - return d->underline; -} - -/*! - If \a enable is TRUE, sets underline on; otherwise sets underline - off. - - \sa underline(), TQFontInfo -*/ -void TQFont::setUnderline( bool enable ) -{ - detach(); - - d->underline = enable; - d->mask |= TQFontPrivate::Underline; -} - -/*! - Returns TRUE if overline has been set; otherwise returns FALSE. - - \sa setOverline() -*/ -bool TQFont::overline() const -{ - return d->overline; -} - -/*! - If \a enable is TRUE, sets overline on; otherwise sets overline off. - - \sa overline(), TQFontInfo -*/ -void TQFont::setOverline( bool enable ) -{ - detach(); - - d->overline = enable; - d->mask |= TQFontPrivate::Overline; -} - -/*! - Returns TRUE if strikeout has been set; otherwise returns FALSE. - - \sa setStrikeOut() -*/ -bool TQFont::strikeOut() const -{ - return d->strikeOut; -} - -/*! - If \a enable is TRUE, sets strikeout on; otherwise sets strikeout - off. - - \sa strikeOut(), TQFontInfo -*/ -void TQFont::setStrikeOut( bool enable ) -{ - detach(); - - d->strikeOut = enable; - d->mask |= TQFontPrivate::StrikeOut; -} - -/*! - Returns TRUE if fixed pitch has been set; otherwise returns FALSE. - - \sa setFixedPitch(), TQFontInfo::fixedPitch() -*/ -bool TQFont::fixedPitch() const -{ - return d->request.fixedPitch; -} - -/*! - If \a enable is TRUE, sets fixed pitch on; otherwise sets fixed - pitch off. - - \sa fixedPitch(), TQFontInfo -*/ -void TQFont::setFixedPitch( bool enable ) -{ - detach(); - - d->request.fixedPitch = enable; - d->request.ignorePitch = FALSE; - d->mask |= TQFontPrivate::FixedPitch; -} - -/*! - Returns the StyleStrategy. - - The style strategy affects the \link #fontmatching font - matching\endlink algorithm. See \l TQFont::StyleStrategy for the - list of strategies. - - \sa setStyleHint() TQFont::StyleHint -*/ -TQFont::StyleStrategy TQFont::styleStrategy() const -{ - return (StyleStrategy) d->request.styleStrategy; -} - -/*! - Returns the StyleHint. - - The style hint affects the \link #fontmatching font - matching\endlink algorithm. See \l TQFont::StyleHint for the list - of strategies. - - \sa setStyleHint(), TQFont::StyleStrategy TQFontInfo::styleHint() -*/ -TQFont::StyleHint TQFont::styleHint() const -{ - return (StyleHint) d->request.styleHint; -} - -/*! - \enum TQFont::StyleHint - - Style hints are used by the \link #fontmatching font - matching\endlink algorithm to find an appropriate default family - if a selected font family is not available. - - \value AnyStyle leaves the font matching algorithm to choose the - family. This is the default. - - \value SansSerif the font matcher prefer sans serif fonts. - \value Helvetica is a synonym for \c SansSerif. - - \value Serif the font matcher prefers serif fonts. - \value Times is a synonym for \c Serif. - - \value TypeWriter the font matcher prefers fixed pitch fonts. - \value Courier a synonym for \c TypeWriter. - - \value OldEnglish the font matcher prefers decorative fonts. - \value Decorative is a synonym for \c OldEnglish. - - \value System the font matcher prefers system fonts. -*/ - -/*! - \enum TQFont::StyleStrategy - - The style strategy tells the \link #fontmatching font - matching\endlink algorithm what type of fonts should be used to - find an appropriate default family. - - The following strategies are available: - - \value PreferDefault the default style strategy. It does not prefer - any type of font. - \value PreferBitmap prefers bitmap fonts (as opposed to outline - fonts). - \value PreferDevice prefers device fonts. - \value PreferOutline prefers outline fonts (as opposed to bitmap fonts). - \value ForceOutline forces the use of outline fonts. - \value NoAntialias don't antialias the fonts. - \value PreferAntialias antialias if possible. - \value OpenGLCompatible forces the use of OpenGL compatible - fonts. - - Any of these may be OR-ed with one of these flags: - - \value PreferMatch prefer an exact match. The font matcher will try to - use the exact font size that has been specified. - \value PreferQuality prefer the best quality font. The font matcher - will use the nearest standard point size that the font - supports. -*/ - -/*! - Sets the style hint and strategy to \a hint and \a strategy, - respectively. - - If these aren't set explicitly the style hint will default to - \c AnyStyle and the style strategy to \c PreferDefault. - - TQt does not support style hints on X11 since this information - is not provided by the window system. - - \sa StyleHint, styleHint(), StyleStrategy, styleStrategy(), TQFontInfo -*/ -void TQFont::setStyleHint( StyleHint hint, StyleStrategy strategy ) -{ - detach(); - - if ( ( d->mask & ( TQFontPrivate::StyleHint | TQFontPrivate::StyleStrategy ) ) && - (StyleHint) d->request.styleHint == hint && - (StyleStrategy) d->request.styleStrategy == strategy ) - return; - - d->request.styleHint = hint; - d->request.styleStrategy = strategy; - d->mask |= TQFontPrivate::StyleHint; - d->mask |= TQFontPrivate::StyleStrategy; - -#if defined(TQ_WS_X11) - d->request.addStyle = TQString::null; -#endif // TQ_WS_X11 -} - -/*! - Sets the style strategy for the font to \a s. - - \sa TQFont::StyleStrategy -*/ -void TQFont::setStyleStrategy( StyleStrategy s ) -{ - detach(); - - if ( ( d->mask & TQFontPrivate::StyleStrategy ) && - s == (StyleStrategy)d->request.styleStrategy ) - return; - - d->request.styleStrategy = s; - d->mask |= TQFontPrivate::StyleStrategy; -} - - -/*! - \enum TQFont::Stretch - - Predefined stretch values that follow the CSS naming convention. - - \value UltraCondensed 50 - \value ExtraCondensed 62 - \value Condensed 75 - \value SemiCondensed 87 - \value Unstretched 100 - \value SemiExpanded 112 - \value Expanded 125 - \value ExtraExpanded 150 - \value UltraExpanded 200 - - \sa setStretch() stretch() -*/ - -/*! - Returns the stretch factor for the font. - - \sa setStretch() - */ -int TQFont::stretch() const -{ - return d->request.stretch; -} - -/*! - Sets the stretch factor for the font. - - The stretch factor changes the width of all characters in the font - by \a factor percent. For example, setting \a factor to 150 - results in all characters in the font being 1.5 times ( ie. 150% ) - wider. The default stretch factor is 100. The minimum stretch - factor is 1, and the maximum stretch factor is 4000. - - The stretch factor is only applied to outline fonts. The stretch - factor is ignored for bitmap fonts. - - NOTE: TQFont cannot stretch XLFD fonts. When loading XLFD fonts on - X11, the stretch factor is matched against a predefined set of - values for the SETWIDTH_NAME field of the XLFD. - - \sa stretch() TQFont::StyleStrategy -*/ -void TQFont::setStretch( int factor ) -{ - if ( factor < 1 || factor > 4000 ) { -#ifdef QT_CHECK_RANGE - tqWarning( "TQFont::setStretch(): parameter '%d' out of range", factor ); -#endif // QT_CHECK_RANGE - - return; - } - - detach(); - - if ( ( d->mask & TQFontPrivate::Stretch ) && - d->request.stretch == (uint)factor ) - return; - - d->request.stretch = (uint)factor; - d->mask |= TQFontPrivate::Stretch; -} - -/*! - If \a enable is TRUE, turns raw mode on; otherwise turns raw mode - off. This function only has an effect under X11. - - If raw mode is enabled, TQt will search for an X font with a - complete font name matching the family name, ignoring all other - values set for the TQFont. If the font name matches several fonts, - TQt will use the first font returned by X. TQFontInfo \e cannot be - used to fetch information about a TQFont using raw mode (it will - return the values set in the TQFont for all parameters, including - the family name). - - \warning Do not use raw mode unless you really, really need it! In - most (if not all) cases, setRawName() is a much better choice. - - \sa rawMode(), setRawName() -*/ -void TQFont::setRawMode( bool enable ) -{ - detach(); - - if ( (bool) d->rawMode == enable ) return; - - d->rawMode = enable; -} - -/*! - Returns TRUE if a window system font exactly matching the settings - of this font is available. - - \sa TQFontInfo -*/ -bool TQFont::exactMatch() const -{ - TQFontEngine *engine = d->engineForScript( TQFont::NoScript ); -#ifdef QT_CHECK_STATE - Q_ASSERT( engine != 0 ); -#endif // QT_CHECK_STATE - - return d->rawMode ? engine->type() != TQFontEngine::Box - : d->request == engine->fontDef; -} - -/*! - Returns TRUE if this font is equal to \a f; otherwise returns - FALSE. - - Two TQFonts are considered equal if their font attributes are - equal. If rawMode() is enabled for both fonts, only the family - fields are compared. - - \sa operator!=() isCopyOf() -*/ -bool TQFont::operator==( const TQFont &f ) const -{ - return f.d == d || ( f.d->request == d->request && - f.d->underline == d->underline && - f.d->overline == d->overline && - f.d->strikeOut == d->strikeOut ); -} - -/*! - Returns TRUE if this font is different from \a f; otherwise - returns FALSE. - - Two TQFonts are considered to be different if their font attributes - are different. If rawMode() is enabled for both fonts, only the - family fields are compared. - - \sa operator==() -*/ -bool TQFont::operator!=( const TQFont &f ) const -{ - return !(operator==( f )); -} - -/*! - Returns TRUE if this font and \a f are copies of each other, i.e. - one of them was created as a copy of the other and neither has - been modified since. This is much stricter than equality. - - \sa operator=() operator==() -*/ -bool TQFont::isCopyOf( const TQFont & f ) const -{ - return d == f.d; -} - -/*! - Returns TRUE if raw mode is used for font name matching; otherwise - returns FALSE. - - \sa setRawMode() rawName() -*/ -bool TQFont::rawMode() const -{ - return d->rawMode; -} - -/*! - Returns a new TQFont that has attributes copied from \a other. -*/ -TQFont TQFont::resolve( const TQFont &other ) const -{ - if ( *this == other && d->mask == other.d->mask ) - return *this; - - TQFont font( *this ); - font.detach(); - - /* - if this font is a copy of the application default font, set the - fontdef mask to zero to indicate that *nothing* has been - explicitly set by the programmer. - */ - const TQFont appfont = TQApplication::font(); - if ( d == appfont.d ) - font.d->mask = 0; - - font.d->resolve( other.d ); - - return font; -} - -#ifndef TQT_NO_COMPAT - -/*! \obsolete - - Please use TQApplication::font() instead. -*/ -TQFont TQFont::defaultFont() -{ - return TQApplication::font(); -} - -/*! \obsolete - - Please use TQApplication::setFont() instead. -*/ -void TQFont::setDefaultFont( const TQFont &f ) -{ - TQApplication::setFont( f ); -} - - -#endif - - - - -#ifndef TQT_NO_STRINGLIST - -/***************************************************************************** - TQFont substitution management - *****************************************************************************/ - -typedef TQDict TQFontSubst; -static TQFontSubst *fontSubst = 0; -static TQSingleCleanupHandler qfont_cleanup_fontsubst; - - -// create substitution dict -static void initFontSubst() -{ - // default substitutions - static const char *initTbl[] = { - -#if defined(TQ_WS_X11) - "arial", "helvetica", - "helv", "helvetica", - "tms rmn", "times", -#elif defined(TQ_WS_WIN) - "times", "Times New Roman", - "courier", "Courier New", - "helvetica", "Arial", -#endif - - 0, 0 - }; - - if (fontSubst) - return; - - fontSubst = new TQFontSubst(17, FALSE); - TQ_CHECK_PTR( fontSubst ); - fontSubst->setAutoDelete( TRUE ); - qfont_cleanup_fontsubst.set(&fontSubst); - - for ( int i=0; initTbl[i] != 0; i += 2 ) - TQFont::insertSubstitution(TQString::fromLatin1(initTbl[i]), - TQString::fromLatin1(initTbl[i+1])); -} - - -/*! - Returns the first family name to be used whenever \a familyName is - specified. The lookup is case insensitive. - - If there is no substitution for \a familyName, \a familyName is - returned. - - To obtain a list of substitutions use substitutes(). - - \sa setFamily() insertSubstitutions() insertSubstitution() removeSubstitution() -*/ -TQString TQFont::substitute( const TQString &familyName ) -{ - initFontSubst(); - - TQStringList *list = fontSubst->find(familyName); - if (list && list->count() > 0) - return *(list->at(0)); - - return familyName; -} - - -/*! - Returns a list of family names to be used whenever \a familyName - is specified. The lookup is case insensitive. - - If there is no substitution for \a familyName, an empty list is - returned. - - \sa substitute() insertSubstitutions() insertSubstitution() removeSubstitution() - */ -TQStringList TQFont::substitutes(const TQString &familyName) -{ - initFontSubst(); - - TQStringList ret, *list = fontSubst->find(familyName); - if (list) - ret += *list; - return ret; -} - - -/*! - Inserts the family name \a substituteName into the substitution - table for \a familyName. - - \sa insertSubstitutions() removeSubstitution() substitutions() substitute() substitutes() -*/ -void TQFont::insertSubstitution(const TQString &familyName, - const TQString &substituteName) -{ - initFontSubst(); - - TQStringList *list = fontSubst->find(familyName); - if (! list) { - list = new TQStringList; - fontSubst->insert(familyName, list); - } - - if (! list->contains(substituteName)) - list->append(substituteName); -} - - -/*! - Inserts the list of families \a substituteNames into the - substitution list for \a familyName. - - \sa insertSubstitution(), removeSubstitution(), substitutions(), substitute() -*/ -void TQFont::insertSubstitutions(const TQString &familyName, - const TQStringList &substituteNames) -{ - initFontSubst(); - - TQStringList *list = fontSubst->find(familyName); - if (! list) { - list = new TQStringList; - fontSubst->insert(familyName, list); - } - - TQStringList::ConstIterator it = substituteNames.begin(); - while (it != substituteNames.end()) { - if (! list->contains(*it)) - list->append(*it); - it++; - } -} - -// ### mark: should be called removeSubstitutions() -/*! - Removes all the substitutions for \a familyName. - - \sa insertSubstitutions(), insertSubstitution(), substitutions(), substitute() -*/ -void TQFont::removeSubstitution( const TQString &familyName ) -{ // ### function name should be removeSubstitutions() or - // ### removeSubstitutionList() - initFontSubst(); - - fontSubst->remove(familyName); -} - - -/*! - Returns a sorted list of substituted family names. - - \sa insertSubstitution(), removeSubstitution(), substitute() -*/ -TQStringList TQFont::substitutions() -{ - initFontSubst(); - - TQStringList ret; - TQDictIterator it(*fontSubst); - - while (it.current()) { - ret.append(it.currentKey()); - ++it; - } - - ret.sort(); - - return ret; -} - -#endif // TQT_NO_STRINGLIST - - -/* \internal - Internal function. Converts boolean font settings to an unsigned - 8-bit number. Used for serialization etc. -*/ -static TQ_UINT8 get_font_bits( const TQFontPrivate *f ) -{ -#ifdef QT_CHECK_STATE - Q_ASSERT( f != 0 ); -#endif - - TQ_UINT8 bits = 0; - if ( f->request.italic ) - bits |= 0x01; - if ( f->underline ) - bits |= 0x02; - if ( f->overline ) - bits |= 0x40; - if ( f->strikeOut ) - bits |= 0x04; - if ( f->request.fixedPitch ) - bits |= 0x08; - // if ( f.hintSetByUser ) - // bits |= 0x10; - if ( f->rawMode ) - bits |= 0x20; - return bits; -} - - -#ifndef TQT_NO_DATASTREAM - -/* \internal - Internal function. Sets boolean font settings from an unsigned - 8-bit number. Used for serialization etc. -*/ -static void set_font_bits( TQ_UINT8 bits, TQFontPrivate *f ) -{ -#ifdef QT_CHECK_STATE - Q_ASSERT( f != 0 ); -#endif - - f->request.italic = (bits & 0x01) != 0; - f->underline = (bits & 0x02) != 0; - f->overline = (bits & 0x40) != 0; - f->strikeOut = (bits & 0x04) != 0; - f->request.fixedPitch = (bits & 0x08) != 0; - // f->hintSetByUser = (bits & 0x10) != 0; - f->rawMode = (bits & 0x20) != 0; -} - -#endif - - -/*! - Returns the font's key, a textual representation of a font. It is - typically used as the key for a cache or dictionary of fonts. - - \sa TQMap -*/ -TQString TQFont::key() const -{ - return toString(); -} - -/*! - Returns a description of the font. The description is a - comma-separated list of the attributes, perfectly suited for use - in TQSettings. - - \sa fromString() operator<<() - */ -TQString TQFont::toString() const -{ - const TQChar comma( ',' ); - return family() + comma + - TQString::number( pointSizeFloat() ) + comma + - TQString::number( pixelSize() ) + comma + - TQString::number( (int) styleHint() ) + comma + - TQString::number( weight() ) + comma + - TQString::number( (int) italic() ) + comma + - TQString::number( (int) underline() ) + comma + - TQString::number( (int) strikeOut() ) + comma + - TQString::number( (int)fixedPitch() ) + comma + - TQString::number( (int) rawMode() ); -} - - -/*! - Sets this font to match the description \a descrip. The description - is a comma-separated list of the font attributes, as returned by - toString(). - - \sa toString() operator>>() - */ -bool TQFont::fromString(const TQString &descrip) -{ -#ifndef TQT_NO_STRINGLIST - TQStringList l(TQStringList::split(',', descrip)); - - int count = (int)l.count(); -#else - int count = 0; - TQString l[11]; - int from = 0; - int to = descrip.find( ',' ); - while ( to > 0 && count < 11 ) { - l[count] = descrip.mid( from, to-from ); - count++; - from = to+1; - to = descrip.find( ',', from ); - } -#endif // TQT_NO_STRINGLIST - if ( !count || ( count > 2 && count < 9 ) || count > 11 ) { - -#ifdef QT_CHECK_STATE - tqWarning("TQFont::fromString: invalid description '%s'", - descrip.isEmpty() ? "(empty)" : descrip.latin1()); -#endif - - return FALSE; - } - - setFamily(l[0]); - if ( count > 1 && l[1].toDouble() > 0.0 ) - setPointSizeFloat(l[1].toDouble()); - if ( count == 9 ) { - setStyleHint((StyleHint) l[2].toInt()); - setWeight(l[3].toInt()); - setItalic(l[4].toInt()); - setUnderline(l[5].toInt()); - setStrikeOut(l[6].toInt()); - setFixedPitch(l[7].toInt()); - setRawMode(l[8].toInt()); - } else if ( count == 10 ) { - if ( l[2].toInt() > 0 ) - setPixelSize( l[2].toInt() ); - setStyleHint((StyleHint) l[3].toInt()); - setWeight(l[4].toInt()); - setItalic(l[5].toInt()); - setUnderline(l[6].toInt()); - setStrikeOut(l[7].toInt()); - setFixedPitch(l[8].toInt()); - setRawMode(l[9].toInt()); - } - - return TRUE; -} - -/*! \internal - - Internal function that dumps font cache statistics. -*/ -void TQFont::cacheStatistics() -{ -} - - - -/***************************************************************************** - TQFont stream functions - *****************************************************************************/ -#ifndef TQT_NO_DATASTREAM - -/*! - \relates TQFont - - Writes the font \a font to the data stream \a s. (toString() - writes to a text stream.) - - \sa \link datastreamformat.html Format of the TQDataStream operators \endlink -*/ -TQDataStream &operator<<( TQDataStream &s, const TQFont &font ) -{ - if ( s.version() == 1 ) { - TQCString fam( font.d->request.family.latin1() ); - s << fam; - } else { - s << font.d->request.family; - } - - if ( s.version() <= 3 ) { - TQ_INT16 pointSize = (TQ_INT16) font.d->request.pointSize; - if ( pointSize == -1 ) { -#ifdef TQ_WS_X11 - pointSize = (TQ_INT16)(font.d->request.pixelSize*720/TQPaintDevice::x11AppDpiY()); -#else - pointSize = (TQ_INT16)TQFontInfo( font ).pointSize() * 10; -#endif - } - s << pointSize; - } else { - s << (TQ_INT16) font.d->request.pointSize; - s << (TQ_INT16) font.d->request.pixelSize; - } - - s << (TQ_UINT8) font.d->request.styleHint; - if ( s.version() >= 5 ) - s << (TQ_UINT8 ) font.d->request.styleStrategy; - return s << (TQ_UINT8) 0 - << (TQ_UINT8) font.d->request.weight - << get_font_bits(font.d); -} - - -/*! - \relates TQFont - - Reads the font \a font from the data stream \a s. (fromString() - reads from a text stream.) - - \sa \link datastreamformat.html Format of the TQDataStream operators \endlink -*/ -TQDataStream &operator>>( TQDataStream &s, TQFont &font ) -{ - if (font.d->deref()) delete font.d; - - font.d = new TQFontPrivate; - font.d->mask = TQFontPrivate::Complete; - - TQ_INT16 pointSize, pixelSize = -1; - TQ_UINT8 styleHint, styleStrategy = TQFont::PreferDefault, charSet, weight, bits; - - if ( s.version() == 1 ) { - TQCString fam; - s >> fam; - font.d->request.family = TQString( fam ); - } else { - s >> font.d->request.family; - } - - s >> pointSize; - if ( s.version() >= 4 ) - s >> pixelSize; - s >> styleHint; - if ( s.version() >= 5 ) - s >> styleStrategy; - s >> charSet; - s >> weight; - s >> bits; - - font.d->request.pointSize = pointSize; - font.d->request.pixelSize = pixelSize; - font.d->request.styleHint = styleHint; - font.d->request.styleStrategy = styleStrategy; - font.d->request.weight = weight; - - set_font_bits( bits, font.d ); - - return s; -} - -#endif // TQT_NO_DATASTREAM - - - - -/***************************************************************************** - TQFontMetrics member functions - *****************************************************************************/ - -/*! - \class TQFontMetrics ntqfontmetrics.h - \brief The TQFontMetrics class provides font metrics information. - - \ingroup graphics - \ingroup shared - - TQFontMetrics functions calculate the size of characters and - strings for a given font. There are three ways you can create a - TQFontMetrics object: - - \list 1 - \i Calling the TQFontMetrics constructor with a TQFont creates a - font metrics object for a screen-compatible font, i.e. the font - cannot be a printer font*. If the font is changed - later, the font metrics object is \e not updated. - - \i TQWidget::fontMetrics() returns the font metrics for a widget's - font. This is equivalent to TQFontMetrics(widget->font()). If the - widget's font is changed later, the font metrics object is \e not - updated. - - \i TQPainter::fontMetrics() returns the font metrics for a - painter's current font. If the painter's font is changed later, the - font metrics object is \e not updated. - \endlist - - * If you use a printer font the values returned may be - inaccurate. Printer fonts are not always accessible so the nearest - screen font is used if a printer font is supplied. - - Once created, the object provides functions to access the - individual metrics of the font, its characters, and for strings - rendered in the font. - - There are several functions that operate on the font: ascent(), - descent(), height(), leading() and lineSpacing() return the basic - size properties of the font. The underlinePos(), overlinePos(), - strikeOutPos() and lineWidth() functions, return the properties of - the line that underlines, overlines or strikes out the - characters. These functions are all fast. - - There are also some functions that operate on the set of glyphs in - the font: minLeftBearing(), minRightBearing() and maxWidth(). - These are by necessity slow, and we recommend avoiding them if - possible. - - For each character, you can get its width(), leftBearing() and - rightBearing() and find out whether it is in the font using - inFont(). You can also treat the character as a string, and use - the string functions on it. - - The string functions include width(), to return the width of a - string in pixels (or points, for a printer), boundingRect(), to - return a rectangle large enough to contain the rendered string, - and size(), to return the size of that rectangle. - - Example: - \code - TQFont font( "times", 24 ); - TQFontMetrics fm( font ); - int pixelsWide = fm.width( "What's the width of this text?" ); - int pixelsHigh = fm.height(); - \endcode - - \sa TQFont TQFontInfo TQFontDatabase -*/ - -/*! - Constructs a font metrics object for \a font. - - The font must be screen-compatible, i.e. a font you use when - drawing text in \link TQWidget widgets\endlink or \link TQPixmap - pixmaps\endlink, not TQPicture or TQPrinter. - - The font metrics object holds the information for the font that is - passed in the constructor at the time it is created, and is not - updated if the font's attributes are changed later. - - Use TQPainter::fontMetrics() to get the font metrics when painting. - This will give correct results also when painting on paint device - that is not screen-compatible. -*/ -TQFontMetrics::TQFontMetrics( const TQFont &font ) - : d( font.d ), painter( 0 ), fscript( TQFont::NoScript ) -{ - d->ref(); -} - -/*! - \overload - - Constructs a font metrics object for \a font using the given \a - script. -*/ -TQFontMetrics::TQFontMetrics( const TQFont &font, TQFont::Script script ) - : d( font.d ), painter( 0 ), fscript( script ) -{ - d->ref(); -} - -/*! \internal - - Constructs a font metrics object for the painter's font \a p. -*/ -TQFontMetrics::TQFontMetrics( const TQPainter *p ) - : painter ( (TQPainter *) p ), fscript( TQFont::NoScript ) -{ -#if defined(CHECK_STATE) - if ( !painter->isActive() ) - tqWarning( "TQFontMetrics: Get font metrics between TQPainter::begin() " - "and TQPainter::end()" ); -#endif - - if ( painter->testf(TQPainter::DirtyFont) ) - painter->updateFont(); - - d = painter->pfont ? painter->pfont->d : painter->cfont.d; - -#if defined(TQ_WS_X11) - if ( d->screen != p->scrn ) { - TQFontPrivate *new_d = new TQFontPrivate( *d ); - TQ_CHECK_PTR( new_d ); - d = new_d; - d->screen = p->scrn; - d->count = 1; - } else -#endif // TQ_WS_X11 - d->ref(); -} - -/*! - Constructs a copy of \a fm. -*/ -TQFontMetrics::TQFontMetrics( const TQFontMetrics &fm ) - : d( fm.d ), painter( 0 ), fscript( fm.fscript ) -{ - d->ref(); -} - -/*! - Destroys the font metrics object and frees all allocated - resources. -*/ -TQFontMetrics::~TQFontMetrics() -{ - if ( d->deref() ) - delete d; -} - -/*! - Assigns the font metrics \a fm. -*/ -TQFontMetrics &TQFontMetrics::operator=( const TQFontMetrics &fm ) -{ - if ( d != fm.d ) { - if ( d->deref() ) - delete d; - d = fm.d; - d->ref(); - } - painter = fm.painter; - return *this; -} - -/*! - Returns the ascent of the font. - - The ascent of a font is the distance from the baseline to the - highest position characters extend to. In practice, some font - designers break this rule, e.g. when they put more than one accent - on top of a character, or to accommodate an unusual character in - an exotic language, so it is possible (though rare) that this - value will be too small. - - \sa descent() -*/ -int TQFontMetrics::ascent() const -{ - TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript ); - TQFontEngine *latin_engine = d->engineForScript( TQFont::Latin ); -#ifdef QT_CHECK_STATE - Q_ASSERT( engine != 0 ); - Q_ASSERT( latin_engine != 0 ); -#endif // QT_CHECK_STATE - - return TQMAX(engine->ascent(), latin_engine->ascent()); -} - - -/*! - Returns the descent of the font. - - The descent is the distance from the base line to the lowest point - characters extend to. (Note that this is different from X, which - adds 1 pixel.) In practice, some font designers break this rule, - e.g. to accommodate an unusual character in an exotic language, so - it is possible (though rare) that this value will be too small. - - \sa ascent() -*/ -int TQFontMetrics::descent() const -{ - TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript ); - TQFontEngine *latin_engine = d->engineForScript( TQFont::Latin ); -#ifdef QT_CHECK_STATE - Q_ASSERT( engine != 0 ); - Q_ASSERT( latin_engine != 0 ); -#endif // QT_CHECK_STATE - - return TQMAX(engine->descent(), latin_engine->descent()); -} - -/*! - Returns the height of the font. - - This is always equal to ascent()+descent()+1 (the 1 is for the - base line). - - \sa leading(), lineSpacing() -*/ -int TQFontMetrics::height() const -{ - TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript ); - TQFontEngine *latin_engine = d->engineForScript( TQFont::Latin ); -#ifdef QT_CHECK_STATE - Q_ASSERT( engine != 0 ); - Q_ASSERT( latin_engine != 0 ); -#endif // QT_CHECK_STATE - - return (TQMAX(engine->ascent(), latin_engine->ascent()) + - TQMAX(engine->descent(), latin_engine->descent()) + 1); -} - -/*! - Returns the leading of the font. - - This is the natural inter-line spacing. - - \sa height(), lineSpacing() -*/ -int TQFontMetrics::leading() const -{ - TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript ); - TQFontEngine *latin_engine = d->engineForScript( TQFont::Latin ); -#ifdef QT_CHECK_STATE - Q_ASSERT( engine != 0 ); - Q_ASSERT( latin_engine != 0 ); -#endif // QT_CHECK_STATE - - return TQMAX(engine->leading(), latin_engine->leading()); -} - -/*! - Returns the distance from one base line to the next. - - This value is always equal to leading()+height(). - - \sa height(), leading() -*/ -int TQFontMetrics::lineSpacing() const -{ - TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript ); - TQFontEngine *latin_engine = d->engineForScript( TQFont::Latin ); -#ifdef QT_CHECK_STATE - Q_ASSERT( engine != 0 ); - Q_ASSERT( latin_engine != 0 ); -#endif // QT_CHECK_STATE - - return (TQMAX(engine->leading(), latin_engine->leading()) + - TQMAX(engine->ascent(), latin_engine->ascent()) + - TQMAX(engine->descent(), latin_engine->descent()) + 1); -} - -/*! - Returns the minimum left bearing of the font. - - This is the smallest leftBearing(char) of all characters in the - font. - - Note that this function can be very slow if the font is large. - - \sa minRightBearing(), leftBearing() -*/ -int TQFontMetrics::minLeftBearing() const -{ - TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript ); - TQFontEngine *latin_engine = d->engineForScript( TQFont::Latin ); -#ifdef QT_CHECK_STATE - Q_ASSERT( engine != 0 ); - Q_ASSERT( latin_engine != 0 ); -#endif // QT_CHECK_STATE - - return TQMIN(engine->minLeftBearing(), latin_engine->minLeftBearing()); -} - -/*! - Returns the minimum right bearing of the font. - - This is the smallest rightBearing(char) of all characters in the - font. - - Note that this function can be very slow if the font is large. - - \sa minLeftBearing(), rightBearing() -*/ -int TQFontMetrics::minRightBearing() const -{ - TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript ); - TQFontEngine *latin_engine = d->engineForScript( TQFont::Latin ); -#ifdef QT_CHECK_STATE - Q_ASSERT( engine != 0 ); - Q_ASSERT( latin_engine != 0 ); -#endif // QT_CHECK_STATE - - return TQMIN(engine->minRightBearing(), latin_engine->minRightBearing()); -} - -/*! - Returns the width of the widest character in the font. -*/ -int TQFontMetrics::maxWidth() const -{ - TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript ); - TQFontEngine *lengine = d->engineForScript( TQFont::Latin ); -#ifdef QT_CHECK_STATE - Q_ASSERT( engine != 0 ); - Q_ASSERT( lengine != 0 ); -#endif // QT_CHECK_STATE - - return TQMAX(engine->maxCharWidth(), lengine->maxCharWidth()); -} - -/*! - Returns TRUE if character \a ch is a valid character in the font; - otherwise returns FALSE. -*/ -bool TQFontMetrics::inFont(TQChar ch) const -{ - TQFont::Script script; - SCRIPT_FOR_CHAR( script, ch ); - - TQFontEngine *engine = d->engineForScript( script ); -#ifdef QT_CHECK_STATE - Q_ASSERT( engine != 0 ); -#endif // QT_CHECK_STATE - - if ( engine->type() == TQFontEngine::Box ) return FALSE; - return engine->canRender( &ch, 1 ); -} - -/*! \fn int TQFontMetrics::leftBearing( TQChar ch ) const - Returns the left bearing of character \a ch in the font. - - The left bearing is the right-ward distance of the left-most pixel - of the character from the logical origin of the character. This - value is negative if the pixels of the character extend to the - left of the logical origin. - - See width(TQChar) for a graphical description of this metric. - - \sa rightBearing(), minLeftBearing(), width() -*/ -#if !defined(TQ_WS_WIN) -int TQFontMetrics::leftBearing(TQChar ch) const -{ - TQFont::Script script; - SCRIPT_FOR_CHAR( script, ch ); - - TQFontEngine *engine = d->engineForScript( script ); -#ifdef QT_CHECK_STATE - Q_ASSERT( engine != 0 ); -#endif // QT_CHECK_STATE - - if ( engine->type() == TQFontEngine::Box ) return 0; - - glyph_t glyphs[10]; - int nglyphs = 9; - engine->stringToCMap( &ch, 1, glyphs, 0, &nglyphs, FALSE ); - // ### can nglyphs != 1 happen at all? Not currently I think - glyph_metrics_t gi = engine->boundingBox( glyphs[0] ); - return gi.x; -} -#endif // !TQ_WS_WIN - -/*! \fn int TQFontMetrics::rightBearing(TQChar ch) const - Returns the right bearing of character \a ch in the font. - - The right bearing is the left-ward distance of the right-most - pixel of the character from the logical origin of a subsequent - character. This value is negative if the pixels of the character - extend to the right of the width() of the character. - - See width() for a graphical description of this metric. - - \sa leftBearing(), minRightBearing(), width() -*/ -#if !defined(TQ_WS_WIN) -int TQFontMetrics::rightBearing(TQChar ch) const -{ - TQFont::Script script; - SCRIPT_FOR_CHAR( script, ch ); - - TQFontEngine *engine = d->engineForScript( script ); -#ifdef QT_CHECK_STATE - Q_ASSERT( engine != 0 ); -#endif // QT_CHECK_STATE - - if ( engine->type() == TQFontEngine::Box ) return 0; - - glyph_t glyphs[10]; - int nglyphs = 9; - engine->stringToCMap( &ch, 1, glyphs, 0, &nglyphs, FALSE ); - // ### can nglyphs != 1 happen at all? Not currently I think - glyph_metrics_t gi = engine->boundingBox( glyphs[0] ); - return gi.xoff - gi.x - gi.width; -} -#endif // !TQ_WS_WIN - - -/*! - Returns the width in pixels of the first \a len characters of \a - str. If \a len is negative (the default), the entire string is - used. - - Note that this value is \e not equal to boundingRect().width(); - boundingRect() returns a rectangle describing the pixels this - string will cover whereas width() returns the distance to where - the next string should be drawn. - - \sa boundingRect() -*/ -int TQFontMetrics::width( const TQString &str, int len ) const -{ - if (len < 0) - len = str.length(); - if (len == 0) - return 0; - - int pos = 0; - int width = 0; -#ifndef TQ_WS_MAC - const TQChar *ch = str.unicode(); - - while (pos < len) { - unsigned short uc = ch->unicode(); - if (uc < TQFontEngineData::widthCacheSize && d->engineData && d->engineData->widthCache[uc]) - width += d->engineData->widthCache[uc]; - else { - TQFont::Script script; - SCRIPT_FOR_CHAR( script, *ch ); - - if (script >= TQFont::Arabic && script <= TQFont::Khmer) - break; - if ( ::category( *ch ) != TQChar::Mark_NonSpacing && !qIsZeroWidthChar(ch->unicode())) { - TQFontEngine *engine = d->engineForScript( script ); -#ifdef QT_CHECK_STATE - Q_ASSERT( engine != 0 ); -#endif // QT_CHECK_STATE - - glyph_t glyphs[8]; - advance_t advances[8]; - int nglyphs = 7; - engine->stringToCMap( ch, 1, glyphs, advances, &nglyphs, FALSE ); - - // ### can nglyphs != 1 happen at all? Not currently I think - if ( uc < TQFontEngineData::widthCacheSize && advances[0] > 0 && advances[0] < 0x100 ) - d->engineData->widthCache[ uc ] = advances[0]; - width += advances[0]; - } - } - ++pos; - ++ch; - } - if ( pos < len ) { -#endif - TQTextEngine layout( str, d ); - layout.itemize( TQTextEngine::WidthOnly ); - width += layout.width( pos, len-pos ); -#ifndef TQ_WS_MAC - } -#endif - return width; -} - -/*! \fn int TQFontMetrics::width( TQChar ch ) const - - - - Returns the logical width of character \a ch in pixels. This is a - distance appropriate for drawing a subsequent character after \a - ch. - - Some of the metrics are described in the image to the right. The - central dark rectangles cover the logical width() of each - character. The outer pale rectangles cover the leftBearing() and - rightBearing() of each character. Notice that the bearings of "f" - in this particular font are both negative, while the bearings of - "o" are both positive. - - \warning This function will produce incorrect results for Arabic - characters or non spacing marks in the middle of a string, as the - glyph shaping and positioning of marks that happens when - processing strings cannot be taken into account. Use charWidth() - instead if you aren't looking for the width of isolated - characters. - - \sa boundingRect(), charWidth() -*/ - -/*! \fn int TQFontMetrics::width( char c ) const - - \overload - \obsolete - - Provided to aid porting from TQt 1.x. -*/ - -/*! \fn int TQFontMetrics::charWidth( const TQString &str, int pos ) const - Returns the width of the character at position \a pos in the - string \a str. - - The whole string is needed, as the glyph drawn may change - depending on the context (the letter before and after the current - one) for some languages (e.g. Arabic). - - This function also takes non spacing marks and ligatures into - account. -*/ - -/*! - Returns the bounding rectangle of the first \a len characters of - \a str, which is the set of pixels the text would cover if drawn - at (0, 0). - - If \a len is negative (the default), the entire string is used. - - Note that the bounding rectangle may extend to the left of (0, 0), - e.g. for italicized fonts, and that the text output may cover \e - all pixels in the bounding rectangle. - - Newline characters are processed as normal characters, \e not as - linebreaks. - - Due to the different actual character heights, the height of the - bounding rectangle of e.g. "Yes" and "yes" may be different. - - \sa width(), TQPainter::boundingRect() -*/ -TQRect TQFontMetrics::boundingRect( const TQString &str, int len ) const -{ - if (len < 0) - len = str.length(); - if (len == 0) - return TQRect(); - - TQTextEngine layout( str, d ); - layout.itemize( TQTextEngine::NoBidi|TQTextEngine::SingleLine ); - glyph_metrics_t gm = layout.boundingBox( 0, len ); - return TQRect( gm.x, gm.y, gm.width, gm.height ); -} - -/*! - Returns the rectangle that is covered by ink if the character - specified by \a ch were to be drawn at the origin of the coordinate - system. - - Note that the bounding rectangle may extend to the left of (0, 0), - e.g. for italicized fonts, and that the text output may cover \e - all pixels in the bounding rectangle. For a space character the rectangle - will usually be empty. - - Note that the rectangle usually extends both above and below the - base line. - - \warning The width of the returned rectangle is not the advance width - of the character. Use boundingRect(const TQString &) or width() instead. - - \sa width() -*/ -TQRect TQFontMetrics::boundingRect( TQChar ch ) const -{ - TQFont::Script script; - SCRIPT_FOR_CHAR( script, ch ); - - TQFontEngine *engine = d->engineForScript( script ); -#ifdef QT_CHECK_STATE - Q_ASSERT( engine != 0 ); -#endif // QT_CHECK_STATE - - glyph_t glyphs[10]; - int nglyphs = 9; - engine->stringToCMap( &ch, 1, glyphs, 0, &nglyphs, FALSE ); - glyph_metrics_t gi = engine->boundingBox( glyphs[0] ); - return TQRect( gi.x, gi.y, gi.width, gi.height ); -} - -/*! - \overload - - Returns the bounding rectangle of the first \a len characters of - \a str, which is the set of pixels the text would cover if drawn - at (0, 0). The drawing, and hence the bounding rectangle, is - constrained to the rectangle (\a x, \a y, \a w, \a h). - - If \a len is negative (which is the default), the entire string is - used. - - The \a flgs argument is the bitwise OR of the following flags: - \list - \i \c AlignAuto aligns to the left border for all languages except - Arabic and Hebrew where it aligns to the right. - \i \c AlignLeft aligns to the left border. - \i \c AlignRight aligns to the right border. - \i \c AlignJustify produces justified text. - \i \c AlignHCenter aligns horizontally centered. - \i \c AlignTop aligns to the top border. - \i \c AlignBottom aligns to the bottom border. - \i \c AlignVCenter aligns vertically centered - \i \c AlignCenter (== \c{AlignHCenter | AlignVCenter}) - \i \c SingleLine ignores newline characters in the text. - \i \c ExpandTabs expands tabs (see below) - \i \c ShowPrefix interprets "&x" as "x", i.e. underlined. - \i \c WordBreak breaks the text to fit the rectangle. - \endlist - - Horizontal alignment defaults to \c AlignAuto and vertical - alignment defaults to \c AlignTop. - - If several of the horizontal or several of the vertical alignment - flags are set, the resulting alignment is undefined. - - These flags are defined in \c ntqnamespace.h. - - If \c ExpandTabs is set in \a flgs, then: if \a tabarray is - non-null, it specifies a 0-terminated sequence of pixel-positions - for tabs; otherwise if \a tabstops is non-zero, it is used as the - tab spacing (in pixels). - - Note that the bounding rectangle may extend to the left of (0, 0), - e.g. for italicized fonts, and that the text output may cover \e - all pixels in the bounding rectangle. - - Newline characters are processed as linebreaks. - - Despite the different actual character heights, the heights of the - bounding rectangles of "Yes" and "yes" are the same. - - The bounding rectangle given by this function is somewhat larger - than that calculated by the simpler boundingRect() function. This - function uses the \link minLeftBearing() maximum left \endlink and - \link minRightBearing() right \endlink font bearings as is - necessary for multi-line text to align correctly. Also, - fontHeight() and lineSpacing() are used to calculate the height, - rather than individual character heights. - - The \a intern argument should not be used. - - \sa width(), TQPainter::boundingRect(), TQt::AlignmentFlags -*/ -TQRect TQFontMetrics::boundingRect( int x, int y, int w, int h, int flgs, - const TQString& str, int len, int tabstops, - int *tabarray, TQTextParag **intern ) const -{ - if ( len < 0 ) - len = str.length(); - - int tabarraylen=0; - if (tabarray) - while (tabarray[tabarraylen]) - tabarraylen++; - - TQRect rb; - TQRect r(x, y, w, h); - qt_format_text( TQFont( d, d->paintdevice ), r, flgs|TQt::DontPrint, str, len, &rb, - tabstops, tabarray, tabarraylen, intern, 0 ); - - return rb; -} - -/*! - Returns the size in pixels of the first \a len characters of \a - str. - - If \a len is negative (the default), the entire string is used. - - The \a flgs argument is the bitwise OR of the following flags: - \list - \i \c SingleLine ignores newline characters. - \i \c ExpandTabs expands tabs (see below) - \i \c ShowPrefix interprets "&x" as "x", i.e. underlined. - \i \c WordBreak breaks the text to fit the rectangle. - \endlist - - These flags are defined in \c ntqnamespace.h. - - If \c ExpandTabs is set in \a flgs, then: if \a tabarray is - non-null, it specifies a 0-terminated sequence of pixel-positions - for tabs; otherwise if \a tabstops is non-zero, it is used as the - tab spacing (in pixels). - - Newline characters are processed as linebreaks. - - Despite the different actual character heights, the heights of the - bounding rectangles of "Yes" and "yes" are the same. - - The \a intern argument should not be used. - - \sa boundingRect() -*/ -TQSize TQFontMetrics::size( int flgs, const TQString &str, int len, int tabstops, - int *tabarray, TQTextParag **intern ) const -{ - return boundingRect(0,0,0,0,flgs,str,len,tabstops,tabarray,intern).size(); -} - -/*! - Returns the distance from the base line to where an underscore - should be drawn. - - \sa overlinePos(), strikeOutPos(), lineWidth() -*/ -int TQFontMetrics::underlinePos() const -{ - TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript ); -#ifdef QT_CHECK_STATE - Q_ASSERT( engine != 0 ); -#endif // QT_CHECK_STATE - - return engine->underlinePosition(); -} - -/*! - Returns the distance from the base line to where an overline - should be drawn. - - \sa underlinePos(), strikeOutPos(), lineWidth() -*/ -int TQFontMetrics::overlinePos() const -{ - int pos = ascent() + 1; - return pos > 0 ? pos : 1; -} - -/*! - Returns the distance from the base line to where the strikeout - line should be drawn. - - \sa underlinePos(), overlinePos(), lineWidth() -*/ -int TQFontMetrics::strikeOutPos() const -{ - int pos = ascent() / 3; - return pos > 0 ? pos : 1; -} - -/*! - Returns the width of the underline and strikeout lines, adjusted - for the point size of the font. - - \sa underlinePos(), overlinePos(), strikeOutPos() -*/ -int TQFontMetrics::lineWidth() const -{ - TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript ); -#ifdef QT_CHECK_STATE - Q_ASSERT( engine != 0 ); -#endif // QT_CHECK_STATE - - return engine->lineThickness(); -} - - - - -/***************************************************************************** - TQFontInfo member functions - *****************************************************************************/ - -/*! - \class TQFontInfo ntqfontinfo.h - - \brief The TQFontInfo class provides general information about fonts. - - \ingroup graphics - \ingroup shared - - The TQFontInfo class provides the same access functions as TQFont, - e.g. family(), pointSize(), italic(), weight(), fixedPitch(), - styleHint() etc. But whilst the TQFont access functions return the - values that were set, a TQFontInfo object returns the values that - apply to the font that will actually be used to draw the text. - - For example, when the program asks for a 25pt Courier font on a - machine that has a non-scalable 24pt Courier font, TQFont will - (normally) use the 24pt Courier for rendering. In this case, - TQFont::pointSize() returns 25 and TQFontInfo::pointSize() returns - 24. - - There are three ways to create a TQFontInfo object. - \list 1 - \i Calling the TQFontInfo constructor with a TQFont creates a font - info object for a screen-compatible font, i.e. the font cannot be - a printer font*. If the font is changed later, the font - info object is \e not updated. - - \i TQWidget::fontInfo() returns the font info for a widget's font. - This is equivalent to calling TQFontInfo(widget->font()). If the - widget's font is changed later, the font info object is \e not - updated. - - \i TQPainter::fontInfo() returns the font info for a painter's - current font. If the painter's font is changed later, the font - info object is \e not updated. - \endlist - - * If you use a printer font the values returned may be - inaccurate. Printer fonts are not always accessible so the nearest - screen font is used if a printer font is supplied. - - \sa TQFont TQFontMetrics TQFontDatabase -*/ - -/*! - Constructs a font info object for \a font. - - The font must be screen-compatible, i.e. a font you use when - drawing text in \link TQWidget widgets\endlink or \link TQPixmap - pixmaps\endlink, not TQPicture or TQPrinter. - - The font info object holds the information for the font that is - passed in the constructor at the time it is created, and is not - updated if the font's attributes are changed later. - - Use TQPainter::fontInfo() to get the font info when painting. - This will give correct results also when painting on paint device - that is not screen-compatible. -*/ -TQFontInfo::TQFontInfo( const TQFont &font ) - : d( font.d ), painter( 0 ), fscript( TQFont::NoScript ) -{ - d->ref(); -} - -/*! - Constructs a font info object for \a font using the specified \a - script. -*/ -TQFontInfo::TQFontInfo( const TQFont &font, TQFont::Script script ) - : d( font.d ), painter( 0 ), fscript( script ) -{ - d->ref(); -} - -/*! \internal - - Constructs a font info object from the painter's font \a p. -*/ -TQFontInfo::TQFontInfo( const TQPainter *p ) - : painter( 0 ), fscript( TQFont::NoScript ) -{ - TQPainter *painter = (TQPainter *) p; - -#if defined(CHECK_STATE) - if ( !painter->isActive() ) - tqWarning( "TQFontInfo: Get font info between TQPainter::begin() " - "and TQPainter::end()" ); -#endif - - painter->setf( TQPainter::FontInf ); - if ( painter->testf(TQPainter::DirtyFont) ) - painter->updateFont(); - if ( painter->pfont ) - d = painter->pfont->d; - else - d = painter->cfont.d; - d->ref(); -} - -/*! - Constructs a copy of \a fi. -*/ -TQFontInfo::TQFontInfo( const TQFontInfo &fi ) - : d(fi.d), painter(0), fscript( fi.fscript ) -{ - d->ref(); -} - -/*! - Destroys the font info object. -*/ -TQFontInfo::~TQFontInfo() -{ - if ( d->deref() ) - delete d; -} - -/*! - Assigns the font info in \a fi. -*/ -TQFontInfo &TQFontInfo::operator=( const TQFontInfo &fi ) -{ - if ( d != fi.d ) { - if ( d->deref() ) - delete d; - d = fi.d; - d->ref(); - } - painter = 0; - fscript = fi.fscript; - return *this; -} - -/*! - Returns the family name of the matched window system font. - - \sa TQFont::family() -*/ -TQString TQFontInfo::family() const -{ - TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript ); -#ifdef QT_CHECK_STATE - Q_ASSERT( engine != 0 ); -#endif // QT_CHECK_STATE - return engine->fontDef.family; -} - -/*! - Returns the point size of the matched window system font. - - \sa TQFont::pointSize() -*/ -int TQFontInfo::pointSize() const -{ - TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript ); -#ifdef QT_CHECK_STATE - Q_ASSERT( engine != 0 ); -#endif // QT_CHECK_STATE - return ( engine->fontDef.pointSize + 5 ) / 10; -} - -/*! - Returns the pixel size of the matched window system font. - - \sa TQFont::pointSize() -*/ -int TQFontInfo::pixelSize() const -{ - TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript ); -#ifdef QT_CHECK_STATE - Q_ASSERT( engine != 0 ); -#endif // QT_CHECK_STATE - return engine->fontDef.pixelSize; -} - -/*! - Returns the italic value of the matched window system font. - - \sa TQFont::italic() -*/ -bool TQFontInfo::italic() const -{ - TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript ); -#ifdef QT_CHECK_STATE - Q_ASSERT( engine != 0 ); -#endif // QT_CHECK_STATE - return engine->fontDef.italic; -} - -/*! - Returns the weight of the matched window system font. - - \sa TQFont::weight(), bold() -*/ -int TQFontInfo::weight() const -{ - TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript ); -#ifdef QT_CHECK_STATE - Q_ASSERT( engine != 0 ); -#endif // QT_CHECK_STATE - return engine->fontDef.weight; - -} - -/*! - \fn bool TQFontInfo::bold() const - - Returns TRUE if weight() would return a value greater than \c - TQFont::Normal; otherwise returns FALSE. - - \sa weight(), TQFont::bold() -*/ - -/*! - Returns the underline value of the matched window system font. - - \sa TQFont::underline() - - \internal - - Here we read the underline flag directly from the TQFont. - This is OK for X11 and for Windows because we always get what we want. -*/ -bool TQFontInfo::underline() const -{ - return d->underline; -} - -/*! - Returns the overline value of the matched window system font. - - \sa TQFont::overline() - - \internal - - Here we read the overline flag directly from the TQFont. - This is OK for X11 and for Windows because we always get what we want. -*/ -bool TQFontInfo::overline() const -{ - return d->overline; -} - -/*! - Returns the strikeout value of the matched window system font. - - \sa TQFont::strikeOut() - - \internal Here we read the strikeOut flag directly from the TQFont. - This is OK for X11 and for Windows because we always get what we want. -*/ -bool TQFontInfo::strikeOut() const -{ - return d->strikeOut; -} - -/*! - Returns the fixed pitch value of the matched window system font. - - \sa TQFont::fixedPitch() -*/ -bool TQFontInfo::fixedPitch() const -{ - TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript ); -#ifdef QT_CHECK_STATE - Q_ASSERT( engine != 0 ); -#endif // QT_CHECK_STATE -#ifdef Q_OS_MAC - if (!engine->fontDef.fixedPitchComputed) { - TQChar ch[2] = { TQChar('i'), TQChar('m') }; - glyph_t g[2]; - int l = 2; - advance_t a[2]; - engine->stringToCMap(ch, 2, g, a, &l, FALSE); - engine->fontDef.fixedPitch = a[0] == a[1]; - engine->fontDef.fixedPitchComputed = TRUE; - } -#endif - return engine->fontDef.fixedPitch; -} - -/*! - Returns the style of the matched window system font. - - Currently only returns the style hint set in TQFont. - - \sa TQFont::styleHint() TQFont::StyleHint -*/ -TQFont::StyleHint TQFontInfo::styleHint() const -{ - TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript ); -#ifdef QT_CHECK_STATE - Q_ASSERT( engine != 0 ); -#endif // QT_CHECK_STATE - return (TQFont::StyleHint) engine->fontDef.styleHint; -} - -/*! - Returns TRUE if the font is a raw mode font; otherwise returns - FALSE. - - If it is a raw mode font, all other functions in TQFontInfo will - return the same values set in the TQFont, regardless of the font - actually used. - - \sa TQFont::rawMode() -*/ -bool TQFontInfo::rawMode() const -{ - return d->rawMode; -} - -/*! - Returns TRUE if the matched window system font is exactly the same - as the one specified by the font; otherwise returns FALSE. - - \sa TQFont::exactMatch() -*/ -bool TQFontInfo::exactMatch() const -{ - TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript ); -#ifdef QT_CHECK_STATE - Q_ASSERT( engine != 0 ); -#endif // QT_CHECK_STATE - - return d->rawMode ? engine->type() != TQFontEngine::Box - : d->request == engine->fontDef; -} - - - - -// ********************************************************************** -// TQFontCache -// ********************************************************************** - -#ifdef TQFONTCACHE_DEBUG -// fast timeouts for debugging -static const int fast_timeout = 1000; // 1s -static const int slow_timeout = 5000; // 5s -#else -static const int fast_timeout = 10000; // 10s -static const int slow_timeout = 300000; // 5m -#endif // TQFONTCACHE_DEBUG - -TQFontCache *TQFontCache::instance = 0; -const uint TQFontCache::min_cost = 4*1024; // 4mb - -static TQSingleCleanupHandler cleanup_fontcache; - - -TQFontCache::TQFontCache() - : TQObject( tqApp, "global font cache" ), total_cost( 0 ), max_cost( min_cost ), - current_timestamp( 0 ), fast( FALSE ), timer_id( -1 ) -{ - Q_ASSERT( instance == 0 ); - instance = this; - cleanup_fontcache.set( &instance ); -} - -TQFontCache::~TQFontCache() -{ - { - EngineDataCache::Iterator it = engineDataCache.begin(), - end = engineDataCache.end(); - while ( it != end ) { - if ( it.data()->count == 0 ) - delete it.data(); - else - FC_DEBUG("TQFontCache::~TQFontCache: engineData %p still has refcount %d", - it.data(), it.data()->count); - ++it; - } - } - EngineCache::Iterator it = engineCache.begin(), - end = engineCache.end(); - while ( it != end ) { - if ( it.data().data->count == 0 ) { - if ( --it.data().data->cache_count == 0 ) { - FC_DEBUG("TQFontCache::~TQFontCache: deleting engine %p key=(%d / %d %d %d %d %d)", - it.data().data, it.key().script, it.key().def.pointSize, - it.key().def.pixelSize, it.key().def.weight, it.key().def.italic, - it.key().def.fixedPitch); - - delete it.data().data; - } - } else { - FC_DEBUG("TQFontCache::~TQFontCache: engine = %p still has refcount %d", - it.data().data, it.data().data->count); - } - ++it; - } - instance = 0; -} - -TQFontEngineData *TQFontCache::findEngineData( const Key &key ) const -{ - EngineDataCache::ConstIterator it = engineDataCache.find( key ), - end = engineDataCache.end(); - if ( it == end ) return 0; - - // found - return it.data(); -} - -void TQFontCache::insertEngineData( const Key &key, TQFontEngineData *engineData ) -{ - FC_DEBUG( "TQFontCache: inserting new engine data %p", engineData ); - - engineDataCache.insert( key, engineData ); - increaseCost( sizeof( TQFontEngineData ) ); -} - -TQFontEngine *TQFontCache::findEngine( const Key &key ) -{ - EngineCache::Iterator it = engineCache.find( key ), - end = engineCache.end(); - if ( it == end ) return 0; - - // found... update the hitcount and timestamp - it.data().hits++; - it.data().timestamp = ++current_timestamp; - - FC_DEBUG( "TQFontCache: found font engine\n" - " %p: timestamp %4u hits %3u ref %2d/%2d, type '%s'", - it.data().data, it.data().timestamp, it.data().hits, - it.data().data->count, it.data().data->cache_count, - it.data().data->name() ); - - return it.data().data; -} - -void TQFontCache::insertEngine( const Key &key, TQFontEngine *engine ) -{ - FC_DEBUG( "TQFontCache: inserting new engine %p", engine ); - - Engine data( engine ); - data.timestamp = ++current_timestamp; - - engineCache.insert( key, data ); - - // only increase the cost if this is the first time we insert the engine - if ( engine->cache_count == 0 ) - increaseCost( engine->cache_cost ); - - ++engine->cache_count; -} - -void TQFontCache::increaseCost( uint cost ) -{ - cost = ( cost + 512 ) / 1024; // store cost in kb - cost = cost > 0 ? cost : 1; - total_cost += cost; - - FC_DEBUG( " COST: increased %u kb, total_cost %u kb, max_cost %u kb", - cost, total_cost, max_cost ); - - if ( total_cost > max_cost) { - max_cost = total_cost; - - if ( timer_id == -1 || ! fast ) { - FC_DEBUG( " TIMER: starting fast timer (%d ms)", fast_timeout ); - - if (timer_id != -1) killTimer( timer_id ); - timer_id = startTimer( fast_timeout ); - fast = TRUE; - } - } -} - -void TQFontCache::decreaseCost( uint cost ) -{ - cost = ( cost + 512 ) / 1024; // cost is stored in kb - cost = cost > 0 ? cost : 1; - Q_ASSERT( cost <= total_cost ); - total_cost -= cost; - - FC_DEBUG( " COST: decreased %u kb, total_cost %u kb, max_cost %u kb", - cost, total_cost, max_cost ); -} - -#if defined(TQ_WS_WIN ) -void TQFontCache::cleanupPrinterFonts() -{ - FC_DEBUG( "TQFontCache::cleanupPrinterFonts" ); - - { - FC_DEBUG( " CLEAN engine data:" ); - - // clean out all unused engine datas - EngineDataCache::Iterator it = engineDataCache.begin(), - end = engineDataCache.end(); - while ( it != end ) { - if ( it.key().screen == 0 ) { - ++it; - continue; - } - - if( it.data()->count > 0 ) { -#ifdef TQ_WS_WIN - for(int i = 0; i < TQFont::LastPrivateScript; ++i) { - if( it.data()->engines[i] ) { - it.data()->engines[i]->deref(); - it.data()->engines[i] = 0; - } - } -#else - if ( it.data()->engine ) { - it.data()->engine->deref(); - it.data()->engine = 0; - } -#endif - ++it; - } else { - - EngineDataCache::Iterator rem = it++; - - decreaseCost( sizeof( TQFontEngineData ) ); - - FC_DEBUG( " %p", rem.data() ); - - delete rem.data(); - engineDataCache.remove( rem ); - } - } - } - - EngineCache::Iterator it = engineCache.begin(), - end = engineCache.end(); - while( it != end ) { - if ( it.data().data->count > 0 || it.key().screen == 0) { - ++it; - continue; - } - - FC_DEBUG( " %p: timestamp %4u hits %2u ref %2d/%2d, type '%s'", - it.data().data, it.data().timestamp, it.data().hits, - it.data().data->count, it.data().data->cache_count, - it.data().data->name() ); - - if ( --it.data().data->cache_count == 0 ) { - FC_DEBUG( " DELETE: last occurence in cache" ); - - decreaseCost( it.data().data->cache_cost ); - delete it.data().data; - } - - engineCache.remove( it++ ); - } -} -#endif - -void TQFontCache::timerEvent( TQTimerEvent * ) -{ - FC_DEBUG( "TQFontCache::timerEvent: performing cache maintenance (timestamp %u)", - current_timestamp ); - - if ( total_cost <= max_cost && max_cost <= min_cost ) { - FC_DEBUG( " cache redused sufficiently, stopping timer" ); - - killTimer( timer_id ); - timer_id = -1; - fast = FALSE; - - return; - } - - // go through the cache and count up everything in use - uint in_use_cost = 0; - - { - FC_DEBUG( " SWEEP engine data:" ); - - // make sure the cost of each engine data is at least 1kb - const uint engine_data_cost = - sizeof( TQFontEngineData ) > 1024 ? sizeof( TQFontEngineData ) : 1024; - - EngineDataCache::ConstIterator it = engineDataCache.begin(), - end = engineDataCache.end(); - for ( ; it != end; ++it ) { -#ifdef TQFONTCACHE_DEBUG - FC_DEBUG( " %p: ref %2d", it.data(), it.data()->count ); - -# if defined(TQ_WS_X11) || defined(TQ_WS_WIN) - // print out all engines - for ( int i = 0; i < TQFont::LastPrivateScript; ++i ) { - if ( ! it.data()->engines[i] ) continue; - FC_DEBUG( " contains %p", it.data()->engines[i] ); - } -# endif // TQ_WS_X11 || TQ_WS_WIN -#endif // TQFONTCACHE_DEBUG - - if ( it.data()->count > 0 ) - in_use_cost += engine_data_cost; - } - } - - { - FC_DEBUG( " SWEEP engine:" ); - - EngineCache::ConstIterator it = engineCache.begin(), - end = engineCache.end(); - for ( ; it != end; ++it ) { - FC_DEBUG( " %p: timestamp %4u hits %2u ref %2d/%2d, cost %u bytes", - it.data().data, it.data().timestamp, it.data().hits, - it.data().data->count, it.data().data->cache_count, - it.data().data->cache_cost ); - - if ( it.data().data->count > 0 ) - in_use_cost += it.data().data->cache_cost / it.data().data->cache_count; - } - - // attempt to make up for rounding errors - in_use_cost += (uint)engineCache.count(); - } - - in_use_cost = ( in_use_cost + 512 ) / 1024; // cost is stored in kb - - /* - calculate the new maximum cost for the cache - - NOTE: in_use_cost is *not* correct due to rounding errors in the - above algorithm. instead of worrying about getting the - calculation correct, we are more interested in speed, and use - in_use_cost as a floor for new_max_cost - */ - uint new_max_cost = TQMAX( TQMAX( max_cost / 2, in_use_cost ), min_cost ); - - FC_DEBUG( " after sweep, in use %u kb, total %u kb, max %u kb, new max %u kb", - in_use_cost, total_cost, max_cost, new_max_cost ); - - if ( new_max_cost == max_cost ) { - if ( fast ) { - FC_DEBUG( " cannot shrink cache, slowing timer" ); - - killTimer( timer_id ); - timer_id = startTimer( slow_timeout ); - fast = FALSE; - } - - return; - } else if ( ! fast ) { - FC_DEBUG( " dropping into passing gear" ); - - killTimer( timer_id ); - timer_id = startTimer( fast_timeout ); - fast = TRUE; - } - - max_cost = new_max_cost; - - { - FC_DEBUG( " CLEAN engine data:" ); - - // clean out all unused engine datas - EngineDataCache::Iterator it = engineDataCache.begin(), - end = engineDataCache.end(); - while ( it != end ) { - if ( it.data()->count > 0 ) { - ++it; - continue; - } - - EngineDataCache::Iterator rem = it++; - - decreaseCost( sizeof( TQFontEngineData ) ); - - FC_DEBUG( " %p", rem.data() ); - - delete rem.data(); - engineDataCache.remove( rem ); - } - } - - // clean out the engine cache just enough to get below our new max cost - uint current_cost; - do { - current_cost = total_cost; - - EngineCache::Iterator it = engineCache.begin(), - end = engineCache.end(); - // determine the oldest and least popular of the unused engines - uint oldest = ~0; - uint least_popular = ~0; - - for ( ; it != end; ++it ) { - if ( it.data().data->count > 0 ) continue; - - if ( it.data().timestamp < oldest && - it.data().hits <= least_popular ) { - oldest = it.data().timestamp; - least_popular = it.data().hits; - } - } - - FC_DEBUG( " oldest %u least popular %u", oldest, least_popular ); - - for ( it = engineCache.begin(); it != end; ++it ) { - if ( it.data().data->count == 0 && - it.data().timestamp == oldest && - it.data().hits == least_popular) - break; - } - - if ( it != end ) { - FC_DEBUG( " %p: timestamp %4u hits %2u ref %2d/%2d, type '%s'", - it.data().data, it.data().timestamp, it.data().hits, - it.data().data->count, it.data().data->cache_count, - it.data().data->name() ); - - if ( --it.data().data->cache_count == 0 ) { - FC_DEBUG( " DELETE: last occurence in cache" ); - - decreaseCost( it.data().data->cache_cost ); - delete it.data().data; - } else { - /* - this particular font engine is in the cache multiple - times... set current_cost to zero, so that we can - keep looping to get rid of all occurences - */ - current_cost = 0; - } - - engineCache.remove( it ); - } - } while ( current_cost != total_cost && total_cost > max_cost ); -} diff --git a/src/kernel/qfont_x11.cpp b/src/kernel/qfont_x11.cpp deleted file mode 100644 index 9f5cd5744..000000000 --- a/src/kernel/qfont_x11.cpp +++ /dev/null @@ -1,738 +0,0 @@ -/**************************************************************************** -** -** Implementation of TQFont, TQFontMetrics and TQFontInfo classes for X11 -** -** Created : 940515 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#define QT_FATAL_ASSERT - -// REVISED: brad - -#include "qplatformdefs.h" - -#include "ntqfont.h" -#include "ntqapplication.h" -#include "ntqcleanuphandler.h" -#include "ntqfontinfo.h" -#include "ntqfontdatabase.h" -#include "ntqfontmetrics.h" -#include "ntqpaintdevice.h" -#include "ntqpaintdevicemetrics.h" -#include "tqtextcodec.h" - -#include -#include -#include "qfontdata_p.h" -#include "qfontengine_p.h" -#include "tqtextengine_p.h" - -#include "qt_x11_p.h" - -#include -#include -#include - -#define TQFONTLOADER_DEBUG -#define TQFONTLOADER_DEBUG_VERBOSE - -TQ_EXPORT bool tqt_has_xft = FALSE; - -#ifndef TQT_NO_XFTFREETYPE -TQt::HANDLE qt_xft_handle(const TQFont &font) -{ - TQFontEngine *engine = font.d->engineForScript( TQFontPrivate::defaultScript ); - if (engine->type() != TQFontEngine::Xft) - return 0; - return (long)static_cast(engine)->font(); -} -#endif - -double qt_pixelSize(double pointSize, TQPaintDevice *paintdevice, int scr) -{ - if (pointSize < 0) return -1.; - - double result = pointSize; - if (paintdevice && TQPaintDeviceMetrics( paintdevice ).logicalDpiY() != 75) - result *= TQPaintDeviceMetrics( paintdevice ).logicalDpiY() / 72.; - else if (TQPaintDevice::x11AppDpiY( scr ) != 75) - result *= TQPaintDevice::x11AppDpiY( scr ) / 72.; - - return result; -} - -double qt_pointSize(double pixelSize, TQPaintDevice *paintdevice, int scr) -{ - if (pixelSize < 0) return -1.; - - double result = pixelSize; - if ( paintdevice && TQPaintDeviceMetrics( paintdevice ).logicalDpiY() != 75) - result *= 72. / TQPaintDeviceMetrics( paintdevice ).logicalDpiY(); - else if (TQPaintDevice::x11AppDpiY(scr) != 75) - result *= 72. / TQPaintDevice::x11AppDpiY( scr ); - - return result; -} - -static inline double pixelSize( const TQFontDef &request, TQPaintDevice *paintdevice, - int scr ) -{ - return ((request.pointSize != -1) ? - qt_pixelSize(request.pointSize / 10., paintdevice, scr) : - (double)request.pixelSize); -} - -static inline double pointSize( const TQFontDef &request, TQPaintDevice *paintdevice, - int scr ) -{ - return ((request.pixelSize != -1) ? - qt_pointSize(request.pixelSize, paintdevice, scr) * 10.: - (double)request.pointSize); -} - - -/* - Removes wildcards from an XLFD. - - Returns \a xlfd with all wildcards removed if a match for \a xlfd is - found, otherwise it returns \a xlfd. -*/ -static TQCString qt_fixXLFD( const TQCString &xlfd ) -{ - TQCString ret = xlfd; - int count = 0; - char **fontNames = - XListFonts( TQPaintDevice::x11AppDisplay(), xlfd, 32768, &count ); - if ( count > 0 ) - ret = fontNames[0]; - XFreeFontNames( fontNames ); - return ret ; -} - -typedef TQMap FallbackMap; -static FallbackMap *fallbackMap = 0; -static TQSingleCleanupHandler qt_fallback_font_family_cleanup; - -static void ensure_fallback_map() -{ - if ( fallbackMap ) return; - fallbackMap = new FallbackMap; - qt_fallback_font_family_cleanup.set( &fallbackMap ); -} - -// Returns the user-configured fallback family for the specified script. -TQString qt_fallback_font_family( TQFont::Script script ) -{ - TQString ret; - - if ( fallbackMap ) { - FallbackMap::ConstIterator it, end = fallbackMap->end(); - it = fallbackMap->find( script ); - if ( it != end ) - ret = it.data(); - } - - return ret; -} - -// Sets the fallback family for the specified script. -void qt_set_fallback_font_family( TQFont::Script script, const TQString &family ) -{ - ensure_fallback_map(); - - if ( ! family.isEmpty() ) - fallbackMap->insert( script, family ); - else - fallbackMap->remove( script ); -} - - -TQFont::Script TQFontPrivate::defaultScript = TQFont::UnknownScript; -int TQFontPrivate::defaultEncodingID = -1; - -/*! - Internal function that initializes the font system. - - \internal - The font cache and font dict do not alloc the keys. The key is a TQString - which is shared between TQFontPrivate and TQXFontName. -*/ -void TQFont::initialize() -{ - // create global font cache - if ( ! TQFontCache::instance ) (void) new TQFontCache; - -#ifndef TQT_NO_CODECS -#ifndef TQT_NO_BIG_CODECS - static bool codecs_once = FALSE; - if ( ! codecs_once ) { - (void) new TQFontJis0201Codec; - (void) new TQFontJis0208Codec; - (void) new TQFontKsc5601Codec; - (void) new TQFontGb2312Codec; - (void) new TQFontGbkCodec; - (void) new TQFontGb18030_0Codec; - (void) new TQFontBig5Codec; - (void) new TQFontBig5hkscsCodec; - (void) new TQFontLaoCodec; - codecs_once = TRUE; - } -#endif // TQT_NO_BIG_CODECS -#endif // TQT_NO_CODECS - - extern int qt_encoding_id_for_mib( int mib ); // from qfontdatabase_x11.cpp - TQTextCodec *codec = TQTextCodec::codecForLocale(); - // determine the default encoding id using the locale, otherwise - // fallback to latin1 ( mib == 4 ) - int mib = codec ? codec->mibEnum() : 4; - - // for asian locales, use the mib for the font codec instead of the locale codec - switch (mib) { - case 38: // eucKR - mib = 36; - break; - - case 2025: // GB2312 - mib = 57; - break; - - case 113: // GBK - mib = -113; - break; - - case 114: // GB18030 - mib = -114; - break; - - case 2026: // Big5 - mib = -2026; - break; - - case 2101: // Big5-HKSCS - mib = -2101; - break; - - case 16: // JIS7 - mib = 15; - break; - - case 17: // SJIS - case 18: // eucJP - mib = 63; - break; - } - - // get the default encoding id for the locale encoding... - TQFontPrivate::defaultEncodingID = qt_encoding_id_for_mib( mib ); - - // get some sample text based on the users locale. we use this to determine the - // default script for the font system - TQCString oldlctime = setlocale(LC_TIME, 0); - TQCString lctime = setlocale(LC_TIME, ""); - - time_t ttmp = time(0); - struct tm *tt = 0; - char samp[64]; - TQString sample; - - if ( ttmp != -1 ) { -#if defined(TQT_THREAD_SUPPORT) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) - // use the reentrant versions of localtime() where available - tm res; - tt = localtime_r( &ttmp, &res ); -#else - tt = localtime( &ttmp ); -#endif // TQT_THREAD_SUPPORT && _POSIX_THREAD_SAFE_FUNCTIONS - - if ( tt != 0 && strftime( samp, 64, "%A%B", tt ) > 0 ) - if ( codec ) - sample = codec->toUnicode( samp ); - } - - if ( ! sample.isNull() && ! sample.isEmpty() ) { - TQFont::Script cs = TQFont::NoScript, tmp; - const TQChar *uc = sample.unicode(); - TQFontPrivate *priv = new TQFontPrivate; - - for ( uint i = 0; i < sample.length(); i++ ) { - SCRIPT_FOR_CHAR( tmp, *uc ); - uc++; - if ( tmp != cs && tmp != TQFont::UnknownScript ) { - cs = tmp; - break; - } - } - delete priv; - - if ( cs != TQFont::UnknownScript ) - TQFontPrivate::defaultScript = cs; - } - - setlocale( LC_TIME, oldlctime.data() ); -} - -/*! \internal - - Internal function that cleans up the font system. -*/ -void TQFont::cleanup() -{ - // delete the global font cache - delete TQFontCache::instance; - TQFontCache::instance = 0; -} - -/*! - \internal - X11 Only: Returns the screen with which this font is associated. -*/ -int TQFont::x11Screen() const -{ - return d->screen; -} - -/*! \internal - X11 Only: Associate the font with the specified \a screen. -*/ -void TQFont::x11SetScreen( int screen ) -{ - if ( screen < 0 ) // assume default - screen = TQPaintDevice::x11AppScreen(); - - if ( screen == d->screen ) - return; // nothing to do - - detach(); - d->screen = screen; -} - -/*! \internal - Returns a TQFontEngine for the specified \a script that matches the - TQFontDef \e request member variable. -*/ -void TQFontPrivate::load( TQFont::Script script ) -{ - // NOTE: the X11 and Windows implementations of this function are - // identical... if you change one, change both. - -#ifdef QT_CHECK_STATE - // sanity checks - if (!TQFontCache::instance) - tqWarning("Must construct a TQApplication before a TQFont"); - Q_ASSERT( script >= 0 && script < TQFont::LastPrivateScript ); -#endif // QT_CHECK_STATE - - TQFontDef req = request; - req.pixelSize = tqRound(pixelSize(req, paintdevice, screen)); - req.pointSize = 0; - - if ( ! engineData ) { - TQFontCache::Key key( req, TQFont::NoScript, screen, paintdevice ); - - // look for the requested font in the engine data cache - engineData = TQFontCache::instance->findEngineData( key ); - - if ( ! engineData ) { - // create a new one - engineData = new TQFontEngineData; - TQFontCache::instance->insertEngineData( key, engineData ); - } else { - engineData->ref(); - } - } - - // the cached engineData could have already loaded the engine we want - if ( engineData->engines[script] ) return; - - // load the font - TQFontEngine *engine = 0; - // double scale = 1.0; // ### TODO: fix the scale calculations - - // list of families to try - TQStringList family_list; - - if (!req.family.isEmpty()) { - family_list = TQStringList::split( ',', req.family ); - - // append the substitute list for each family in family_list - TQStringList subs_list; - TQStringList::ConstIterator it = family_list.begin(), end = family_list.end(); - for ( ; it != end; ++it ) - subs_list += TQFont::substitutes( *it ); - family_list += subs_list; - -#ifndef QT_XFT2 - // with Xft2, we want to use fontconfig to determine better fallbacks, - // otherwise we might run into trouble with default fonts as "serif" - - // append the default fallback font for the specified script - TQString fallback = qt_fallback_font_family( script ); - if ( ! fallback.isEmpty() && ! family_list.contains( fallback ) ) - family_list << fallback; - - // add the default family - TQString defaultFamily = TQApplication::font().family(); - if ( ! family_list.contains( defaultFamily ) ) - family_list << defaultFamily; - - // add TQFont::defaultFamily() to the list, for compatibility with - // previous versions - family_list << TQApplication::font().defaultFamily(); -#endif // QT_XFT2 - } - - // null family means find the first font matching the specified script - family_list << TQString::null; - - TQStringList::ConstIterator it = family_list.begin(), end = family_list.end(); - for ( ; ! engine && it != end; ++it ) { - req.family = *it; - - engine = TQFontDatabase::findFont( script, this, req ); - if ( engine ) { - if ( engine->type() != TQFontEngine::Box ) - break; - - if ( ! req.family.isEmpty() ) - engine = 0; - - continue; - } - } - - engine->ref(); - engineData->engines[script] = engine; -} - -/*! - Returns TRUE if the font attributes have been changed and the font - has to be (re)loaded; otherwise returns FALSE. -*/ -bool TQFont::dirty() const -{ - return d->engineData == 0; -} - -/*! - Returns the window system handle to the font, for low-level - access. Using this function is \e not portable. -*/ -TQt::HANDLE TQFont::handle() const -{ - TQFontEngine *engine = d->engineForScript( TQFontPrivate::defaultScript ); -#ifdef QT_CHECK_STATE - Q_ASSERT( engine != 0 ); -#endif // QT_CHECK_STATE - - switch ( engine->type() ) { - case TQFontEngine::XLFD: - return ((TQFontEngineXLFD *) engine)->handle(); - case TQFontEngine::LatinXLFD: - return ((TQFontEngineLatinXLFD *) engine)->handle(); - - default: break; - } - return 0; -} - -/*! - Returns the name of the font within the underlying window system. - - On Windows, this is usually just the family name of a TrueType - font. - - On X11, it is an XLFD (X Logical Font Description). When TQt is - build with Xft support on X11, the return value can be an Xft - pattern or an XLFD. - - Using the return value of this function is usually \e not \e - portable. - - \sa setRawName() -*/ -TQString TQFont::rawName() const -{ - TQFontEngine *engine = d->engineForScript( TQFontPrivate::defaultScript ); -#ifdef QT_CHECK_STATE - Q_ASSERT( engine != 0 ); -#endif // QT_CHECK_STATE - - return TQString::fromLatin1( engine->name() ); -} - -/*! - Sets a font by its system specific name. The function is - particularly useful under X, where system font settings (for - example X resources) are usually available in XLFD (X Logical Font - Description) form only. You can pass an XLFD as \a name to this - function. - - A font set with setRawName() is still a full-featured TQFont. It can - be queried (for example with italic()) or modified (for example with - setItalic()) and is therefore also suitable for rendering rich text. - - If TQt's internal font database cannot resolve the raw name, the - font becomes a raw font with \a name as its family. - - Note that the present implementation does not handle wildcards in - XLFDs well, and that font aliases (file \c fonts.alias in the font - directory on X11) are not supported. - - \sa rawName(), setRawMode(), setFamily() -*/ -void TQFont::setRawName( const TQString &name ) -{ - detach(); - - // from qfontdatabase_x11.cpp - extern bool qt_fillFontDef( const TQCString &xlfd, TQFontDef *fd, int screen ); - - if ( ! qt_fillFontDef( qt_fixXLFD( name.latin1() ), &d->request, d->screen ) ) { -#ifdef QT_CHECK_STATE - tqWarning("TQFont::setRawName(): Invalid XLFD: \"%s\"", name.latin1()); -#endif // QT_CHECK_STATE - - setFamily( name ); - setRawMode( TRUE ); - } else { - d->mask = TQFontPrivate::Complete; - } -} - -/*! - Returns the "last resort" font family name. - - The current implementation tries a wide variety of common fonts, - returning the first one it finds. Is is possible that no family is - found in which case a null string is returned. - - \sa lastResortFont() -*/ -TQString TQFont::lastResortFamily() const -{ - return TQString::fromLatin1( "Helvetica" ); -} - -/*! - Returns the family name that corresponds to the current style - hint. - - \sa StyleHint styleHint() setStyleHint() -*/ -TQString TQFont::defaultFamily() const -{ - switch ( d->request.styleHint ) { - case TQFont::Times: - return TQString::fromLatin1( "Times" ); - - case TQFont::Courier: - return TQString::fromLatin1( "Courier" ); - - case TQFont::Decorative: - return TQString::fromLatin1( "Old English" ); - - case TQFont::Helvetica: - case TQFont::System: - default: - return TQString::fromLatin1( "Helvetica" ); - } -} - -/* - Returns a last resort raw font name for the font matching algorithm. - This is used if even the last resort family is not available. It - returns \e something, almost no matter what. The current - implementation tries a wide variety of common fonts, returning the - first one it finds. The implementation may change at any time. -*/ -static const char * const tryFonts[] = { - "-*-helvetica-medium-r-*-*-*-120-*-*-*-*-*-*", - "-*-courier-medium-r-*-*-*-120-*-*-*-*-*-*", - "-*-times-medium-r-*-*-*-120-*-*-*-*-*-*", - "-*-lucida-medium-r-*-*-*-120-*-*-*-*-*-*", - "-*-helvetica-*-*-*-*-*-120-*-*-*-*-*-*", - "-*-courier-*-*-*-*-*-120-*-*-*-*-*-*", - "-*-times-*-*-*-*-*-120-*-*-*-*-*-*", - "-*-lucida-*-*-*-*-*-120-*-*-*-*-*-*", - "-*-helvetica-*-*-*-*-*-*-*-*-*-*-*-*", - "-*-courier-*-*-*-*-*-*-*-*-*-*-*-*", - "-*-times-*-*-*-*-*-*-*-*-*-*-*-*", - "-*-lucida-*-*-*-*-*-*-*-*-*-*-*-*", - "-*-fixed-*-*-*-*-*-*-*-*-*-*-*-*", - "6x13", - "7x13", - "8x13", - "9x15", - "fixed", - 0 -}; - -// Returns TRUE if the font exists, FALSE otherwise -static bool fontExists( const TQString &fontName ) -{ - int count; - char **fontNames = XListFonts( TQPaintDevice::x11AppDisplay(), - (char*)fontName.latin1(), 32768, &count ); - if ( fontNames ) XFreeFontNames( fontNames ); - - return count != 0; -} - -/*! - Returns a "last resort" font name for the font matching algorithm. - This is used if the last resort family is not available. It will - always return a name, if necessary returning something like - "fixed" or "system". - - The current implementation tries a wide variety of common fonts, - returning the first one it finds. The implementation may change - at any time, but this function will always return a string - containing something. - - It is theoretically possible that there really isn't a - lastResortFont() in which case TQt will abort with an error - message. We have not been able to identify a case where this - happens. Please \link bughowto.html report it as a bug\endlink if - it does, preferably with a list of the fonts you have installed. - - \sa lastResortFamily() rawName() -*/ -TQString TQFont::lastResortFont() const -{ - static TQString last; - - // already found - if ( ! last.isNull() ) - return last; - - int i = 0; - const char* f; - - while ( ( f = tryFonts[i] ) ) { - last = TQString::fromLatin1( f ); - - if ( fontExists( last ) ) - return last; - - i++; - } - -#if defined(CHECK_NULL) - tqFatal( "TQFontPrivate::lastResortFont: Cannot find any reasonable font" ); -#endif - - return last; -} - - - - -// ********************************************************************** -// TQFontMetrics member methods -// ********************************************************************** - -int TQFontMetrics::width( TQChar ch ) const -{ - unsigned short uc = ch.unicode(); - if ( uc < TQFontEngineData::widthCacheSize && - d->engineData && d->engineData->widthCache[ uc ] ) - return d->engineData->widthCache[ uc ]; - - if ( ::category( ch ) == TQChar::Mark_NonSpacing || qIsZeroWidthChar(ch.unicode())) - return 0; - - TQFont::Script script; - SCRIPT_FOR_CHAR( script, ch ); - - TQFontEngine *engine = d->engineForScript( script ); -#ifdef QT_CHECK_STATE - Q_ASSERT( engine != 0 ); -#endif // QT_CHECK_STATE - - glyph_t glyphs[8]; - advance_t advances[8]; - int nglyphs = 7; - engine->stringToCMap( &ch, 1, glyphs, advances, &nglyphs, FALSE ); - - // ### can nglyphs != 1 happen at all? Not currently I think - if ( uc < TQFontEngineData::widthCacheSize && advances[0] > 0 && advances[0] < 0x100 ) - d->engineData->widthCache[ uc ] = advances[0]; - - return advances[0]; -} - - -int TQFontMetrics::charWidth( const TQString &str, int pos ) const -{ - if ( pos < 0 || pos > (int)str.length() ) - return 0; - - const TQChar &ch = str.unicode()[ pos ]; - if ( ch.unicode() < TQFontEngineData::widthCacheSize && - d->engineData && d->engineData->widthCache[ ch.unicode() ] ) - return d->engineData->widthCache[ ch.unicode() ]; - - TQFont::Script script; - SCRIPT_FOR_CHAR( script, ch ); - - int width; - - if ( script >= TQFont::Arabic && script <= TQFont::Khmer ) { - // complex script shaping. Have to do some hard work - int from = TQMAX( 0, pos - 8 ); - int to = TQMIN( (int)str.length(), pos + 8 ); - TQConstString cstr( str.unicode()+from, to-from); - TQTextEngine layout( cstr.string(), d ); - layout.itemize( TQTextEngine::WidthOnly ); - width = layout.width( pos-from, 1 ); - } else if ( ::category( ch ) == TQChar::Mark_NonSpacing || qIsZeroWidthChar(ch.unicode())) { - width = 0; - } else { - TQFontEngine *engine = d->engineForScript( script ); -#ifdef QT_CHECK_STATE - Q_ASSERT( engine != 0 ); -#endif // QT_CHECK_STATE - - glyph_t glyphs[8]; - advance_t advances[8]; - int nglyphs = 7; - engine->stringToCMap( &ch, 1, glyphs, advances, &nglyphs, FALSE ); - width = advances[0]; - } - if ( ch.unicode() < TQFontEngineData::widthCacheSize && width > 0 && width < 0x100 ) - d->engineData->widthCache[ ch.unicode() ] = width; - return width; -} diff --git a/src/kernel/qfontdata_p.h b/src/kernel/qfontdata_p.h deleted file mode 100644 index 1aae9b76c..000000000 --- a/src/kernel/qfontdata_p.h +++ /dev/null @@ -1,275 +0,0 @@ -/**************************************************************************** -** -** Definition of internal TQFontData struct -** -** Created : 941229 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#ifndef TQFONTDATA_P_H -#define TQFONTDATA_P_H - -// -// W A R N I N G -// ------------- -// -// This file is not part of the TQt API. It exists for the convenience -// of internal files. This header file may change from version to version -// without notice, or even be removed. -// -// We mean it. -// -// - -#include "tqobject.h" -#include "ntqfont.h" -#include "ntqpaintdevicemetrics.h" - -// forwards -class TQFontEngine; -class TQPaintDevice; - - -struct TQFontDef -{ - inline TQFontDef() - : pointSize( -1 ), pixelSize( -1 ), - styleHint( TQFont::AnyStyle ), styleStrategy( TQFont::PreferDefault ), - weight( 50 ), italic( FALSE ), fixedPitch( FALSE ), stretch( 100 ), - ignorePitch(TRUE) -#ifdef TQ_WS_MAC - ,fixedPitchComputed(FALSE) -#endif - { - } - - TQString family; - -#ifdef TQ_WS_X11 - TQString addStyle; -#endif // TQ_WS_X11 - - int pointSize; - int pixelSize; - - uint styleHint : 8; - uint styleStrategy : 16; - - uint weight : 7; // 0-99 - uint italic : 1; - uint fixedPitch : 1; - uint stretch : 12; // 0-400 - - uint ignorePitch : 1; - uint fixedPitchComputed : 1; // for Mac OS X only - uint reserved : 14; // for future extensions - - bool operator==( const TQFontDef &other ) const; - inline bool operator<( const TQFontDef &other ) const - { - if ( pixelSize != other.pixelSize ) return pixelSize < other.pixelSize; - if ( weight != other.weight ) return weight < other.weight; - if ( italic != other.italic ) return italic < other.italic; - if ( stretch != other.stretch ) return stretch < other.stretch; - if ( styleHint != other.styleHint ) return styleHint < other.styleHint; - if ( styleStrategy != other.styleStrategy ) return styleStrategy < other.styleStrategy; - if ( family != other.family ) return family < other.family; - -#ifdef TQ_WS_X11 - if ( addStyle != other.addStyle ) return addStyle < other.addStyle; -#endif // TQ_WS_X11 - - return FALSE; - } -}; - -class TQFontEngineData : public TQShared -{ -public: - TQFontEngineData(); - ~TQFontEngineData(); - - uint lineWidth; - -#if defined(TQ_WS_X11) || defined(TQ_WS_WIN) - TQFontEngine *engines[TQFont::LastPrivateScript]; -#else - TQFontEngine *engine; -#endif // TQ_WS_X11 || TQ_WS_WIN -#ifndef TQ_WS_MAC - enum { widthCacheSize = 0x500 }; - uchar widthCache[widthCacheSize]; -#endif -}; - - -class TQFontPrivate : public TQShared -{ -public: - static TQFont::Script defaultScript; -#ifdef TQ_WS_X11 - static int defaultEncodingID; -#endif // TQ_WS_X11 - - TQFontPrivate(); - TQFontPrivate( const TQFontPrivate &other ); - ~TQFontPrivate(); - - void load( TQFont::Script script ); - TQFontEngine *engineForScript( TQFont::Script script ) const { - if ( script == TQFont::NoScript ) - script = TQFontPrivate::defaultScript; -#if defined(TQ_WS_X11) || defined(TQ_WS_WIN) - if ( ! engineData || ! engineData->engines[script] ) - ((TQFontPrivate *) this)->load( script ); - return engineData->engines[script]; -#else - if ( ! engineData || ! engineData->engine ) - ((TQFontPrivate *) this)->load( script ); - return engineData->engine; -#endif // TQ_WS_X11 || TQ_WS_WIN - } - - TQFontDef request; - TQFontEngineData *engineData; - TQPaintDevice *paintdevice; - int screen; - - uint rawMode : 1; - uint underline : 1; - uint overline : 1; - uint strikeOut : 1; - - enum { - Family = 0x0001, - Size = 0x0002, - StyleHint = 0x0004, - StyleStrategy = 0x0008, - Weight = 0x0010, - Italic = 0x0020, - Underline = 0x0040, - Overline = 0x0080, - StrikeOut = 0x0100, - FixedPitch = 0x0200, - Stretch = 0x0400, - Complete = 0x07ff - }; - - uint mask; - - void resolve( const TQFontPrivate *other ); -}; - - -class TQFontCache : public TQObject -{ -public: - static TQFontCache *instance; - - TQFontCache(); - ~TQFontCache(); - - // universal key structure. TQFontEngineDatas and TQFontEngines are cached using - // the same keys - struct Key { - Key() : script(0), screen( 0 ), dpi(0) { } - Key( const TQFontDef &d, TQFont::Script c, int s, TQPaintDevice *pdev ) - : script(c), screen(s) { - def = d; -#ifdef TQ_WS_X11 - dpi = pdev ? TQPaintDeviceMetrics(pdev).logicalDpiY() : 0; -#else - Q_UNUSED(pdev); - dpi = 0; -#endif - } - - TQFontDef def; - int script; - int screen; - int dpi; - - inline bool operator<( const Key &other ) const - { - if ( script != other.script ) return script < other.script; - if ( screen != other.screen ) return screen < other.screen; - if ( dpi != other.dpi ) return dpi < other.dpi; - return def < other.def; - } - inline bool operator==( const Key &other ) const - { return def == other.def && script == other.script && - screen == other.screen && dpi == other.dpi; } - }; - - // TQFontEngineData cache - typedef TQMap EngineDataCache; - EngineDataCache engineDataCache; - - TQFontEngineData *findEngineData( const Key &key ) const; - void insertEngineData( const Key &key, TQFontEngineData *engineData ); - - // TQFontEngine cache - struct Engine { - Engine() : data( 0 ), timestamp( 0 ), hits( 0 ) { } - Engine( TQFontEngine *d ) : data( d ), timestamp( 0 ), hits( 0 ) { } - - TQFontEngine *data; - uint timestamp; - uint hits; - }; - - typedef TQMap EngineCache; - EngineCache engineCache; - - TQFontEngine *findEngine( const Key &key ); - void insertEngine( const Key &key, TQFontEngine *engine ); - -#if defined(TQ_WS_WIN) - void cleanupPrinterFonts(); -#endif - - private: - void increaseCost( uint cost ); - void decreaseCost( uint cost ); - void timerEvent( TQTimerEvent *event ); - - static const uint min_cost; - uint total_cost, max_cost; - uint current_timestamp; - bool fast; - int timer_id; -}; - -#endif // TQFONTDATA_P_H diff --git a/src/kernel/qfontdatabase.cpp b/src/kernel/qfontdatabase.cpp deleted file mode 100644 index 41aa25431..000000000 --- a/src/kernel/qfontdatabase.cpp +++ /dev/null @@ -1,2489 +0,0 @@ -/**************************************************************************** -** -** Implementation of font database class. -** -** Created : 990603 -** -** Copyright (C) 1999-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#include "ntqfontdatabase.h" - -#ifndef TQT_NO_FONTDATABASE - -#include -#include - -#include -#include "qfontengine_p.h" - -#include - -#ifdef TQ_WS_X11 -#include -#endif -#include - -//#define TQFONTDATABASE_DEBUG -#ifdef TQFONTDATABASE_DEBUG -# define FD_DEBUG tqDebug -#else -# define FD_DEBUG if (FALSE) tqDebug -#endif - -//#define FONT_MATCH_DEBUG -#ifdef FONT_MATCH_DEBUG -# define FM_DEBUG tqDebug -#else -# define FM_DEBUG if (FALSE) tqDebug -#endif - -#if defined(Q_CC_MSVC) && !defined(Q_CC_MSVC_NET) -# define for if(0){}else for -#endif - -static int ucstricmp( const TQString &as, const TQString &bs ) -{ - const TQChar *a = as.unicode(); - const TQChar *b = bs.unicode(); - if ( a == b ) - return 0; - if ( a == 0 ) - return 1; - if ( b == 0 ) - return -1; - int l=TQMIN(as.length(),bs.length()); - while ( l-- && ::lower( *a ) == ::lower( *b ) ) - a++,b++; - if ( l==-1 ) - return ( as.length()-bs.length() ); - return ::lower( *a ).unicode() - ::lower( *b ).unicode(); -} - -static int getFontWeight( const TQString &weightString ) -{ - TQString s = weightString.lower(); - - // Test in decreasing order of commonness - if (s == "medium" || - s == "normal") - return TQFont::Normal; - if (s == "bold") - return TQFont::Bold; - if (s == "demibold" || s == "demi bold") - return TQFont::DemiBold; - if (s == "black") - return TQFont::Black; - if (s == "light") - return TQFont::Light; - - if (s.contains("bold")) { - if (s.contains("demi")) - return (int) TQFont::DemiBold; - return (int) TQFont::Bold; - } - - if (s.contains("light")) - return (int) TQFont::Light; - - if (s.contains("black")) - return (int) TQFont::Black; - - return (int) TQFont::Normal; -} - -#ifdef TQ_WS_X11 -struct TQtFontEncoding -{ - signed int encoding : 16; - - uint xpoint : 16; - uint xres : 8; - uint yres : 8; - uint avgwidth : 16; - uchar pitch : 8; -}; -#endif // TQ_WS_X11 - -struct TQtFontSize -{ - unsigned short pixelSize; - -#ifdef TQ_WS_X11 - int count; - TQtFontEncoding *encodings; - TQtFontEncoding *encodingID( int id, uint xpoint = 0, uint xres = 0, - uint yres = 0, uint avgwidth = 0, bool add = FALSE); -#endif // TQ_WS_X11 -}; - - -#ifdef TQ_WS_X11 -TQtFontEncoding *TQtFontSize::encodingID( int id, uint xpoint, uint xres, - uint yres, uint avgwidth, bool add ) -{ - // we don't match using the xpoint, xres and yres parameters, only the id - for ( int i = 0; i < count; ++i ) { - if ( encodings[i].encoding == id ) - return encodings + i; - } - - if ( !add ) return 0; - - if ( !(count % 4) ) - encodings = ( TQtFontEncoding * ) - realloc( encodings, - (((count+4) >> 2 ) << 2 ) * sizeof( TQtFontEncoding ) ); - encodings[count].encoding = id; - encodings[count].xpoint = xpoint; - encodings[count].xres = xres; - encodings[count].yres = yres; - encodings[count].avgwidth = avgwidth; - encodings[count].pitch = '*'; - return encodings + count++; -} -#endif // TQ_WS_X11 - -struct TQtFontStyle -{ - struct Key { - Key( const TQString &styleString ); - Key() : italic( FALSE ), oblique( FALSE ), - weight( TQFont::Normal ), stretch( 0 ) { } - Key( const Key &o ) : italic( o.italic ), oblique( o.oblique ), - weight( o.weight ), stretch( o.stretch ) { } - uint italic : 1; - uint oblique : 1; - signed int weight : 8; - signed int stretch : 12; - - bool operator==( const Key & other ) { - return ( italic == other.italic && - oblique == other.oblique && - weight == other.weight && - (stretch == 0 || other.stretch == 0 || stretch == other.stretch) ); - } - bool operator!=( const Key &other ) { - return !operator==(other); - } - bool operator <( const Key &o ) { - int x = (italic << 13) + (oblique << 12) + (weight << 14) + stretch; - int y = (o.italic << 13) + (o.oblique << 12) + (o.weight << 14) + o.stretch; - return ( x < y ); - } - }; - - TQtFontStyle( const Key &k ) - : key( k ), bitmapScalable( FALSE ), smoothScalable( FALSE ), - fakeOblique( FALSE ), count( 0 ), pixelSizes( 0 ) - { -#if defined(TQ_WS_X11) - weightName = setwidthName = 0; -#endif // TQ_WS_X11 - } - - ~TQtFontStyle() { -#ifdef TQ_WS_X11 - delete [] weightName; - delete [] setwidthName; - while ( count-- ) - free(pixelSizes[count].encodings); -#endif - free( pixelSizes ); - } - - Key key; - bool bitmapScalable : 1; - bool smoothScalable : 1; - bool fakeOblique : 1; - int count : 29; - TQtFontSize *pixelSizes; - -#ifdef TQ_WS_X11 - const char *weightName; - const char *setwidthName; -#endif // TQ_WS_X11 - - TQtFontSize *pixelSize( unsigned short size, bool = FALSE ); -}; - -TQtFontStyle::Key::Key( const TQString &styleString ) - : italic( FALSE ), oblique( FALSE ), weight( TQFont::Normal ), stretch( 0 ) -{ - weight = getFontWeight( styleString ); - - if ( styleString.contains( "Italic" ) ) - italic = TRUE; - else if ( styleString.contains( "Oblique" ) ) - oblique = TRUE; -} - -TQtFontSize *TQtFontStyle::pixelSize( unsigned short size, bool add ) -{ - for ( int i = 0; i < count; i++ ) { - if ( pixelSizes[i].pixelSize == size ) - return pixelSizes + i; - } - if ( !add ) - return 0; - - if ( !(count % 8) ) - pixelSizes = (TQtFontSize *) - realloc( pixelSizes, - (((count+8) >> 3 ) << 3) * sizeof(TQtFontSize) ); - pixelSizes[count].pixelSize = size; -#ifdef TQ_WS_X11 - pixelSizes[count].count = 0; - pixelSizes[count].encodings = 0; -#endif - return pixelSizes + (count++); -} - -struct TQtFontFoundry -{ - TQtFontFoundry( const TQString &n ) : name( n ), count( 0 ), styles( 0 ) {} - ~TQtFontFoundry() { - while ( count-- ) - delete styles[count]; - free( styles ); - } - - TQString name; - - int count; - TQtFontStyle **styles; - TQtFontStyle *style( const TQtFontStyle::Key &, bool = FALSE ); -}; - -TQtFontStyle *TQtFontFoundry::style( const TQtFontStyle::Key &key, bool create ) -{ - int pos = 0; - if ( count ) { - int low = 0; - int high = count; - pos = count / 2; - while ( high > low ) { - if ( styles[pos]->key == key ) - return styles[pos]; - if ( styles[pos]->key < key ) - low = pos + 1; - else - high = pos; - pos = (high + low) / 2; - }; - pos = low; - } - if ( !create ) - return 0; - -// tqDebug("adding key (weight=%d, italic=%d, oblique=%d stretch=%d) at %d", key.weight, key.italic, key.oblique, key.stretch, pos ); - if ( !(count % 8) ) - styles = (TQtFontStyle **) - realloc( styles, (((count+8) >> 3 ) << 3) * sizeof( TQtFontStyle * ) ); - - memmove( styles + pos + 1, styles + pos, (count-pos)*sizeof(TQtFontStyle *) ); - styles[pos] = new TQtFontStyle( key ); - count++; - return styles[pos]; -} - - -struct TQtFontFamily -{ - enum ScriptStatus { Unknown = 0, Supported = 1, - UnSupported_Xft= 2, UnSupported_Xlfd = 4, UnSupported = 6 }; - - TQtFontFamily(const TQString &n ) - : -#ifdef TQ_WS_X11 - fixedPitch( TRUE ), hasXft( FALSE ), xftScriptCheck( FALSE ), xlfdLoaded( FALSE ), synthetic(FALSE), -#else - fixedPitch( FALSE ), -#endif -#ifdef TQ_WS_WIN - scriptCheck( FALSE ), -#endif -#if defined(Q_OS_MAC) - fixedPitchComputed(FALSE), -#endif - fullyLoaded( FALSE ), - name( n ), count( 0 ), foundries( 0 ) { - memset( scripts, 0, sizeof( scripts ) ); - } - ~TQtFontFamily() { - while ( count-- ) - delete foundries[count]; - free( foundries ); - } - - bool fixedPitch : 1; -#ifdef TQ_WS_X11 - bool hasXft : 1; - bool xftScriptCheck : 1; - bool xlfdLoaded : 1; - bool synthetic : 1; -#endif -#ifdef TQ_WS_WIN - bool scriptCheck : 1; -#endif -#if defined(Q_OS_MAC) - bool fixedPitchComputed : 1; -#endif - bool fullyLoaded : 1; - TQString name; - TQString rawName; -#ifdef TQ_WS_X11 - TQCString fontFilename; - int fontFileIndex; -#endif -#ifdef TQ_WS_MAC - FMFontFamily macFamily; -#endif -#ifdef TQ_WS_WIN - TQString english_name; -#endif - int count; - TQtFontFoundry **foundries; - - unsigned char scripts[TQFont::LastPrivateScript]; - - TQtFontFoundry *foundry( const TQString &f, bool = FALSE ); -}; - -TQtFontFoundry *TQtFontFamily::foundry( const TQString &f, bool create ) -{ - if ( f.isNull() && count == 1 ) - return foundries[0]; - - for ( int i = 0; i < count; i++ ) { - if ( ucstricmp( foundries[i]->name, f ) == 0 ) - return foundries[i]; - } - if ( !create ) - return 0; - - if ( !(count % 8) ) - foundries = (TQtFontFoundry **) - realloc( foundries, - (((count+8) >> 3 ) << 3) * sizeof( TQtFontFoundry * ) ); - - foundries[count] = new TQtFontFoundry( f ); - return foundries[count++]; -} - -class TQFontDatabasePrivate { -public: - TQFontDatabasePrivate() : count( 0 ), families( 0 ) { } - ~TQFontDatabasePrivate() { - while ( count-- ) - delete families[count]; - free( families ); - } - TQtFontFamily *family( const TQString &f, bool = FALSE ); - - int count; - TQtFontFamily **families; -}; - -TQtFontFamily *TQFontDatabasePrivate::family( const TQString &f, bool create ) -{ - int low = 0; - int high = count; - int pos = count / 2; - int res = 1; - if ( count ) { - while ( (res = ucstricmp( families[pos]->name, f )) && pos != low ) { - if ( res > 0 ) - high = pos; - else - low = pos; - pos = (high + low) / 2; - }; - if ( !res ) - return families[pos]; - } - if ( !create ) - return 0; - - if ( res < 0 ) - pos++; - - // tqDebug("adding family %s at %d total=%d", f.latin1(), pos, count); - if ( !(count % 8) ) - families = (TQtFontFamily **) - realloc( families, - (((count+8) >> 3 ) << 3) * sizeof( TQtFontFamily * ) ); - - memmove( families + pos + 1, families + pos, (count-pos)*sizeof(TQtFontFamily *) ); - families[pos] = new TQtFontFamily( f ); - count++; - return families[pos]; -} - - - - -#if defined(TQ_WS_X11) || defined(TQ_WS_WIN) -static const unsigned short sample_chars[TQFont::LastPrivateScript][14] = -{ - // European Alphabetic Scripts - // Latin, - { 0x0041, 0x0 }, - // Greek, - { 0x0391, 0x0 }, - // Cyrillic, - { 0x0410, 0x0 }, - // Armenian, - { 0x0540, 0x0 }, - // Georgian, - { 0x10d0, 0x0 }, - // Runic, - { 0x16a0, 0x0 }, - // Ogham, - { 0x1680, 0x0 }, - // SpacingModifiers, - { 0x02c6, 0x0 }, - // CombiningMarks, - { 0x0300, 0x0 }, - - // Middle Eastern Scripts - // Hebrew, - { 0x05d0, 0x0 }, - // Arabic, - { 0x0630, 0x0 }, - // Syriac, - { 0x0710, 0x0 }, - // Thaana, - { 0x0780, 0x0 }, - - // South and Southeast Asian Scripts - // Devanagari, - { 0x0910, 0x0 }, - // Bengali, - { 0x0990, 0x0 }, - // Gurmukhi, - { 0x0a10, 0x0 }, - // Gujarati, - { 0x0a90, 0x0 }, - // Oriya, - { 0x0b10, 0x0 }, - // Tamil, - { 0x0b90, 0x0 }, - // Telugu, - { 0x0c10, 0x0 }, - // Kannada, - { 0x0c90, 0x0 }, - // Malayalam, - { 0x0d10, 0x0 }, - // Sinhala, - { 0x0d90, 0x0 }, - // Thai, - { 0x0e10, 0x0 }, - // Lao, - { 0x0e81, 0x0 }, - // Tibetan, - { 0x0f00, 0x0 }, - // Myanmar, - { 0x1000, 0x0 }, - // Khmer, - { 0x1780, 0x0 }, - - // East Asian Scripts - // Han, - { 0x4e00, 0x0 }, - // Hiragana, - { 0x3050, 0x4e00, 0x25EF, 0x3012, 0x3013, 0x30FB, 0x30FC, 0x5CE0, 0 }, - // Katakana, - { 0x30b0, 0x4e00, 0x25EF, 0x3012, 0x3013, 0x30FB, 0x30FC, 0x5CE0, 0 }, - // Hangul, - { 0xac00, 0x0 }, - // Bopomofo, - { 0x3110, 0x0 }, - // Yi, - { 0xa000, 0x0 }, - - // Additional Scripts - // Ethiopic, - { 0x1200, 0x0 }, - // Cherokee, - { 0x13a0, 0x0 }, - // CanadianAboriginal, - { 0x1410, 0x0 }, - // Mongolian, - { 0x1800, 0x0 }, - - // Symbols - // CurrencySymbols, - { 0x20aa, 0x0 }, - // LetterlikeSymbols, - { 0x2103, 0x0 }, - // NumberForms, - { 0x2160, 0x0 }, - // MathematicalOperators, - { 0x222b, 0x0 }, - // TechnicalSymbols, - { 0x2312, 0x0 }, - // GeometricSymbols, - { 0x2500, 0x0 }, - // MiscellaneousSymbols, - { 0x2640, 0x2714, 0x0 }, - // EnclosedAndSquare, - { 0x2460, 0x0 }, - // Braille, - { 0x2800, 0x0 }, - - // Unicode, - { 0xfffd, 0x0 }, - - // some scripts added in Unicode 3.2 - // Tagalog, - { 0x1700, 0x0 }, - // Hanunoo, - { 0x1720, 0x0 }, - // Buhid, - { 0x1740, 0x0 }, - // Tagbanwa, - { 0x1770, 0x0 }, - - // KatakanaHalfWidth - { 0xff65, 0x0 }, - - // Limbu - { 0x1901, 0x0 }, - // TaiLe - { 0x1950, 0x0 }, - - // NScripts - { 0x0000, 0x0 }, - // NoScript - { 0x0000, 0x0 }, - - // Han_Japanese - { 0x4e00, 0x25EF, 0x3012, 0x3013, 0x30FB, 0x5CE0, 0 }, - // Han_SimplifiedChinese, 0x3400 is optional - { 0x4e00, 0x201C, 0x3002, 0x6237, 0x9555, 0xFFE5, 0 }, - // Han_TraditionalChinese, 0xF6B1 is optional - // OR Han_HongkongChinese, 0x3435, 0xE000, 0xF6B1 are optional - { 0x4e00, 0x201C, 0x3002, 0x6236, 0x9F98, 0xFFE5, 0 }, - // Han_Korean - { 0x4e00, 0 } - // Taiwan would be 0x201C, 0x3002, 0x4E00, 0x9F98, 0xFFE5 -}; - -#if defined(TQ_WS_X11) && !defined(TQT_NO_XFTFREETYPE) -static inline bool requiresOpenType(TQFont::Script s) -{ - return (s >= TQFont::Syriac && s <= TQFont::Sinhala) - || (s >= TQFont::Myanmar && s <= TQFont::Khmer); -} -#endif - -static inline bool canRender( TQFontEngine *fe, TQFont::Script script ) -{ - if ( !fe ) return FALSE; - - bool hasChar = true; - - if (!sample_chars[script][0]) - hasChar = false; - - int i = 0; - while (hasChar && sample_chars[script][i]){ - TQChar sample(sample_chars[script][i]); - if ( !fe->canRender( &sample, 1 ) ) { - hasChar = false; -#ifdef FONT_MATCH_DEBUG - FM_DEBUG(" font has NOT char 0x%04x", sample.unicode() ); - } else { - FM_DEBUG(" font has char 0x%04x", sample.unicode() ); -#endif - } - ++i; - } -#if defined(TQ_WS_X11) && !defined(TQT_NO_XFTFREETYPE) - if (hasChar && requiresOpenType(script)) { - TQOpenType *ot = fe->openType(); - if (!ot || !ot->supportsScript(script)) - return FALSE; - } -#endif - - return hasChar; -} -#endif // TQ_WS_X11 || TQ_WS_WIN - - -static TQSingleCleanupHandler qfontdatabase_cleanup; -static TQFontDatabasePrivate *db=0; -#define SMOOTH_SCALABLE 0xffff - -#if defined( TQ_WS_X11 ) -# include "qfontdatabase_x11.cpp" -#elif defined( TQ_WS_MAC ) -# include "qfontdatabase_mac.cpp" -#elif defined( TQ_WS_WIN ) -# include "qfontdatabase_win.cpp" -#endif - -static TQtFontStyle *bestStyle(TQtFontFoundry *foundry, const TQtFontStyle::Key &styleKey) -{ - int best = 0; - int dist = 0xffff; - - for ( int i = 0; i < foundry->count; i++ ) { - TQtFontStyle *style = foundry->styles[i]; - - int d = TQABS( styleKey.weight - style->key.weight ); - - if ( styleKey.stretch != 0 && style->key.stretch != 0 ) { - d += TQABS( styleKey.stretch - style->key.stretch ); - } - - if ( styleKey.italic ) { - if ( !style->key.italic ) - d += style->key.oblique ? 0x0001 : 0x1000; - } else if ( styleKey.oblique ) { - if (!style->key.oblique ) - d += style->key.italic ? 0x0001 : 0x1000; - } else if ( style->key.italic || style->key.oblique ) { - d += 0x1000; - } - - if ( d < dist ) { - best = i; - dist = d; - } - } - - FM_DEBUG( " best style has distance 0x%x", dist ); - if (!foundry->count) { - TQtFontStyle *temp = NULL; - return temp; - } - return foundry->styles[best]; -} - -#if defined(TQ_WS_X11) -static TQtFontEncoding *findEncoding(TQFont::Script script, int styleStrategy, - TQtFontSize *size, int force_encoding_id) -{ - TQtFontEncoding *encoding = 0; - - if (force_encoding_id >= 0) { - encoding = size->encodingID(force_encoding_id); - if (!encoding) - FM_DEBUG(" required encoding_id not available"); - return encoding; - } - - if (styleStrategy & (TQFont::OpenGLCompatible | TQFont::PreferBitmap)) { - FM_DEBUG(" PreferBitmap and/or OpenGL set, skipping Xft"); - } else { - encoding = size->encodingID(-1); // -1 == prefer Xft - if (encoding) return encoding; - } - - // Xft not available, find an XLFD font, trying the default encoding first - encoding = size->encodingID(TQFontPrivate::defaultEncodingID); - - if (!encoding || !scripts_for_xlfd_encoding[encoding->encoding][script]) { - // find the first encoding that supports the requested script - encoding = 0; - for (int x = 0; !encoding && x < size->count; ++x) { - const int enc = size->encodings[x].encoding; - if (scripts_for_xlfd_encoding[enc][script]) { - encoding = size->encodings + x; - break; - } - } - } - - return encoding; -} -#endif // TQ_WS_X11 - - -#if defined(TQ_WS_X11) || defined(TQ_WS_WIN) -static -unsigned int bestFoundry( TQFont::Script script, unsigned int score, int styleStrategy, - const TQtFontFamily *family, const TQString &foundry_name, - TQtFontStyle::Key styleKey, int pixelSize, char pitch, - TQtFontFoundry **best_foundry, TQtFontStyle **best_style, - TQtFontSize **best_size -#ifdef TQ_WS_X11 - , TQtFontEncoding **best_encoding, int force_encoding_id -#endif - ) -{ - Q_UNUSED( script ); - Q_UNUSED( pitch ); - - FM_DEBUG( " REMARK: looking for best foundry for family '%s'", family->name.latin1() ); - - for ( int x = 0; x < family->count; ++x ) { - TQtFontFoundry *foundry = family->foundries[x]; - if ( ! foundry_name.isEmpty() && - ucstricmp( foundry->name, foundry_name ) != 0 ) - continue; - - FM_DEBUG( " looking for matching style in foundry '%s'", - foundry->name.isEmpty() ? "-- none --" : foundry->name.latin1() ); - - TQtFontStyle *style = bestStyle(foundry, styleKey); - - if ( ! style->smoothScalable && ( styleStrategy & TQFont::ForceOutline ) ) { - FM_DEBUG( " ForceOutline set, but not smoothly scalable" ); - continue; - } - - int px = -1; - TQtFontSize *size = 0; - - // 1. see if we have an exact matching size - if (! (styleStrategy & TQFont::ForceOutline)) { - size = style->pixelSize(pixelSize); - if (size) { - FM_DEBUG(" found exact size match (%d pixels)", size->pixelSize); - px = size->pixelSize; - } - } - - // 2. see if we have a smoothly scalable font - if (! size && style->smoothScalable && ! (styleStrategy & TQFont::PreferBitmap)) { - size = style->pixelSize(SMOOTH_SCALABLE); - if (size) { - FM_DEBUG(" found smoothly scalable font (%d pixels)", pixelSize); - px = pixelSize; - } - } - - // 3. see if we have a bitmap scalable font - if (! size && style->bitmapScalable && (styleStrategy & TQFont::PreferMatch)) { - size = style->pixelSize(0); - if (size) { - FM_DEBUG(" found bitmap scalable font (%d pixels)", pixelSize); - px = pixelSize; - } - } - -#ifdef TQ_WS_X11 - TQtFontEncoding *encoding = 0; -#endif - - // 4. find closest size match - if (! size) { - unsigned int distance = ~0u; - for (int x = 0; x < style->count; ++x) { -#ifdef TQ_WS_X11 - encoding = - findEncoding(script, styleStrategy, style->pixelSizes + x, force_encoding_id); - if (!encoding) { - FM_DEBUG(" size %3d does not support the script we want", - style->pixelSizes[x].pixelSize); - continue; - } -#endif - - unsigned int d = TQABS(style->pixelSizes[x].pixelSize - pixelSize); - if (d < distance) { - distance = d; - size = style->pixelSizes + x; - FM_DEBUG(" best size so far: %3d (%d)", size->pixelSize, pixelSize); - } - } - - if (!size) { - FM_DEBUG(" no size supports the script we want"); - continue; - } - - if (style->bitmapScalable && ! (styleStrategy & TQFont::PreferQuality) && - (distance * 10 / pixelSize) >= 2) { - // the closest size is not close enough, go ahead and - // use a bitmap scaled font - size = style->pixelSize(0); - px = pixelSize; - } else { - px = size->pixelSize; - } - } - -#ifdef TQ_WS_X11 - if (size) { - encoding = findEncoding(script, styleStrategy, size, force_encoding_id); - if (!encoding) size = 0; - } - if ( ! encoding ) { - FM_DEBUG( " foundry doesn't support the script we want" ); - continue; - } -#endif // TQ_WS_X11 - - unsigned int this_score = 0x0000; - enum { - PitchMismatch = 0x4000, - StyleMismatch = 0x2000, - BitmapScaledPenalty = 0x1000, - EncodingMismatch = 0x0002, - XLFDPenalty = 0x0001 - }; - -#ifdef TQ_WS_X11 - if ( encoding->encoding != -1 ) { - this_score += XLFDPenalty; - if ( encoding->encoding != TQFontPrivate::defaultEncodingID ) - this_score += EncodingMismatch; - } - if (pitch != '*') { - if ( !( pitch == 'm' && encoding->pitch == 'c' ) && pitch != encoding->pitch ) - this_score += PitchMismatch; - } -#else - // ignore pitch for asian fonts, some of them misreport it, and they are all - // fixed pitch anyway. - if (pitch != '*' && (script <= TQFont::NScripts && script != TQFont::KatakanaHalfWidth - && (script < TQFont::Han || script > TQFont::Yi))) { - if ((pitch == 'm' && !family->fixedPitch) - || (pitch == 'p' && family->fixedPitch)) - this_score += PitchMismatch; - } -#endif - if ( styleKey != style->key ) - this_score += StyleMismatch; - if ( !style->smoothScalable && px != size->pixelSize ) // bitmap scaled - this_score += BitmapScaledPenalty; - if (px != pixelSize) // close, but not exact, size match - this_score += TQABS(px - pixelSize); - - if ( this_score < score ) { - FM_DEBUG( " found a match: score %x best score so far %x", - this_score, score ); - - score = this_score; - *best_foundry = foundry; - *best_style = style; - *best_size = size; -#ifdef TQ_WS_X11 - *best_encoding = encoding; -#endif // TQ_WS_X11 - } else { - FM_DEBUG( " score %x no better than best %x", this_score, score); - } - } - - return score; -} - -/*! - \internal -*/ -TQFontEngine * -TQFontDatabase::findFont( TQFont::Script script, const TQFontPrivate *fp, - const TQFontDef &request, int force_encoding_id ) -{ -#ifndef TQ_WS_X11 - Q_UNUSED( force_encoding_id ); -#endif - - if ( !db ) - initializeDb(); - - TQFontEngine *fe = 0; - if ( fp ) { - if ( fp->rawMode ) { - fe = loadEngine( script, fp, request, 0, 0, 0 -#ifdef TQ_WS_X11 - , 0, 0, FALSE -#endif - ); - - // if we fail to load the rawmode font, use a 12pixel box engine instead - if (! fe) fe = new TQFontEngineBox( 12 ); - return fe; - } - - TQFontCache::Key key( request, script, -#ifdef TQ_WS_WIN - (int)fp->paintdevice, -#else - fp->screen, -#endif - fp->paintdevice - ); - fe = TQFontCache::instance->findEngine( key ); - if ( fe ) return fe; - } - -#ifdef TQ_WS_WIN - if (request.styleStrategy & TQFont::PreferDevice) { - TQFontEngine *fe = loadEngine(script, fp, request, 0, 0, 0); - if(fe) - return fe; - } -#endif - - TQString family_name, foundry_name; - TQtFontStyle::Key styleKey; - styleKey.italic = request.italic; - styleKey.weight = request.weight; - styleKey.stretch = request.stretch; - char pitch = request.ignorePitch ? '*' : request.fixedPitch ? 'm' : 'p'; - - parseFontName( request.family, foundry_name, family_name ); - -#ifdef TQ_WS_X11 - if (script == TQFont::Han) { - // modify script according to locale - static TQFont::Script defaultHan; - TQCString locale = setlocale(LC_ALL, NULL); - - if (locale.contains("ko")) - defaultHan = TQFont::Han_Korean; - else if (locale.contains("zh_TW") || locale.contains("zh_HK")) - defaultHan = TQFont::Han_TraditionalChinese; - else if (locale.contains("zh")) - defaultHan = TQFont::Han_SimplifiedChinese; - else if (locale.contains("ja")) - defaultHan = TQFont::Han_Japanese; - else - defaultHan = TQFont::Han; // don't change - - script = defaultHan; - } -#endif - - FM_DEBUG( "TQFontDatabase::findFont\n" - " request:\n" - " family: %s [%s], script: %d (%s)\n" - " weight: %d, italic: %d\n" - " stretch: %d\n" - " pixelSize: %d\n" - " pitch: %c", - family_name.isEmpty() ? "-- first in script --" : family_name.latin1(), - foundry_name.isEmpty() ? "-- any --" : foundry_name.latin1(), - script, scriptName( script ).latin1(), - request.weight, request.italic, request.stretch, request.pixelSize, pitch ); - - bool usesFontConfig = FALSE; -#ifdef QT_XFT2 - if (family_name.isEmpty() - || family_name == "Sans Serif" - || family_name == "Serif" - || family_name == "Monospace") { - fe = loadFontConfigFont(fp, request, script); - usesFontConfig = (fe != 0); - } - if (!fe) -#endif - { - TQtFontFamily *best_family = 0; - TQtFontFoundry *best_foundry = 0; - TQtFontStyle *best_style = 0; - TQtFontSize *best_size = 0; -#ifdef TQ_WS_X11 - TQtFontEncoding *best_encoding = 0; -#endif // TQ_WS_X11 - - unsigned int score = ~0; - - load( family_name, script ); - - for ( int x = 0; x < db->count; ++x ) { - TQtFontFamily *try_family = db->families[x]; -#ifdef TQ_WS_X11 - if (try_family->synthetic) // skip generated fontconfig fonts - continue; -#endif - - if ( !family_name.isEmpty() && - ucstricmp( try_family->name, family_name ) != 0 -#ifdef TQ_WS_WIN - && ucstricmp( try_family->english_name, family_name ) != 0 -#endif - ) - continue; - - if ( family_name.isEmpty() ) - load( try_family->name, script ); - - uint score_adjust = 0; - TQFont::Script override_script = script; - if ( ! ( try_family->scripts[script] & TQtFontFamily::Supported ) - && script != TQFont::Unicode) { - // family not supported in the script we want -#ifdef TQ_WS_X11 - if (script >= TQFont::Han_Japanese && script <= TQFont::Han_Korean - && try_family->scripts[TQFont::Han] == TQtFontFamily::Supported) { - // try with the han script instead, give it a penalty - if (override_script == TQFont::Han_TraditionalChinese - && (try_family->scripts[TQFont::Han_SimplifiedChinese] & TQtFontFamily::Supported)) { - override_script = TQFont::Han_SimplifiedChinese; - score_adjust = 200; - } else if (override_script == TQFont::Han_SimplifiedChinese - && (try_family->scripts[TQFont::Han_TraditionalChinese] & TQtFontFamily::Supported)) { - override_script = TQFont::Han_TraditionalChinese; - score_adjust = 200; - } else { - override_script = TQFont::Han; - score_adjust = 400; - } - } else -#endif - if (family_name.isEmpty()) { - continue; - } else if (try_family->scripts[TQFont::UnknownScript] & TQtFontFamily::Supported) { - // try with the unknown script (for a symbol font) - override_script = TQFont::UnknownScript; -#ifndef QT_XFT2 - } else if (try_family->scripts[TQFont::Unicode] & TQtFontFamily::Supported) { - // try with the unicode script instead - override_script = TQFont::Unicode; -#endif - } else { - // family not supported by unicode/unknown scripts - continue; - } - } - - TQtFontFoundry *try_foundry = 0; - TQtFontStyle *try_style = 0; - TQtFontSize *try_size = 0; -#ifdef TQ_WS_X11 - TQtFontEncoding *try_encoding = 0; -#endif // TQ_WS_X11 - - // as we know the script is supported, we can be sure - // to find a matching font here. - unsigned int newscore = - bestFoundry( override_script, score, request.styleStrategy, - try_family, foundry_name, styleKey, request.pixelSize, pitch, - &try_foundry, &try_style, &try_size -#ifdef TQ_WS_X11 - , &try_encoding, force_encoding_id -#endif - ); - if ( try_foundry == 0 ) { - // the specific foundry was not found, so look for - // any foundry matching our requirements - newscore = bestFoundry( override_script, score, request.styleStrategy, try_family, - TQString::null, styleKey, request.pixelSize, - pitch, &try_foundry, &try_style, &try_size -#ifdef TQ_WS_X11 - , &try_encoding, force_encoding_id -#endif - ); - } - newscore += score_adjust; - - if ( newscore < score ) { - score = newscore; - best_family = try_family; - best_foundry = try_foundry; - best_style = try_style; - best_size = try_size; -#ifdef TQ_WS_X11 - best_encoding = try_encoding; -#endif // TQ_WS_X11 - } - if ( newscore < 10 ) // xlfd instead of xft... just accept it - break; - } - - if ( best_family != 0 && best_foundry != 0 && best_style != 0 -#ifdef TQ_WS_X11 - && best_size != 0 && best_encoding != 0 -#endif - ) { - FM_DEBUG( " BEST:\n" - " family: %s [%s]\n" - " weight: %d, italic: %d, oblique: %d\n" - " stretch: %d\n" - " pixelSize: %d\n" - " pitch: %c\n" - " encoding: %d\n", - best_family->name.latin1(), - best_foundry->name.isEmpty() ? "-- none --" : best_foundry->name.latin1(), - best_style->key.weight, best_style->key.italic, best_style->key.oblique, - best_style->key.stretch, best_size ? best_size->pixelSize : 0xffff, -#ifdef TQ_WS_X11 - best_encoding->pitch, best_encoding->encoding -#else - 'p', 0 -#endif - ); - - fe = loadEngine( script, fp, request, best_family, best_foundry, best_style -#ifdef TQ_WS_X11 - , best_size, best_encoding, ( force_encoding_id >= 0 ) -#endif - ); - } - if (fe) { - fe->fontDef.family = best_family->name; - if ( ! best_foundry->name.isEmpty() ) { - fe->fontDef.family += TQString::fromLatin1( " [" ); - fe->fontDef.family += best_foundry->name; - fe->fontDef.family += TQString::fromLatin1( "]" ); - } - - if ( best_style->smoothScalable ) - fe->fontDef.pixelSize = request.pixelSize; - else if ( best_style->bitmapScalable && - ( request.styleStrategy & TQFont::PreferMatch ) ) - fe->fontDef.pixelSize = request.pixelSize; - else - fe->fontDef.pixelSize = best_size->pixelSize; - - fe->fontDef.styleHint = request.styleHint; - fe->fontDef.styleStrategy = request.styleStrategy; - - fe->fontDef.weight = best_style->key.weight; - fe->fontDef.italic = best_style->key.italic || best_style->key.oblique; - fe->fontDef.fixedPitch = best_family->fixedPitch; - fe->fontDef.stretch = best_style->key.stretch; - fe->fontDef.ignorePitch = FALSE; - } - } - - if ( fe ) { - if ( script != TQFont::Unicode && !canRender( fe, script ) ) { - FM_DEBUG( " WARN: font loaded cannot render a sample char" ); - - delete fe; - fe = 0; - } else if ( fp ) { - TQFontDef def = request; - if (def.family.isEmpty()) { - def.family = fp->request.family; - def.family = def.family.left(def.family.find(',')); - } - TQFontCache::Key key( def, script, -#ifdef TQ_WS_WIN - (int)fp->paintdevice, -#else - fp->screen, -#endif - fp->paintdevice - ); - TQFontCache::instance->insertEngine( key, fe ); - if (!usesFontConfig) { - for ( int i = 0; i < TQFont::NScripts; ++i ) { - if ( i == script ) continue; - - if (!canRender(fe, (TQFont::Script) i)) - continue; - - key.script = i; - TQFontCache::instance->insertEngine( key, fe ); - } - } - } - } - - if (!fe) { - if ( !request.family.isEmpty() ) - return 0; - - FM_DEBUG( "returning box engine" ); - - fe = new TQFontEngineBox( request.pixelSize ); - fe->fontDef = request; - - if ( fp ) { - TQFontCache::Key key( request, script, -#ifdef TQ_WS_WIN - (int)fp->paintdevice, -#else - fp->screen, -#endif - fp->paintdevice - ); - TQFontCache::instance->insertEngine( key, fe ); - } - } - - if ( fp ) { -#if defined(TQ_WS_X11) - fe->fontDef.pointSize = - tqRound(10. * qt_pointSize(fe->fontDef.pixelSize, fp->paintdevice, fp->screen)); -#elif defined(TQ_WS_WIN) - fe->fontDef.pointSize = int( double( fe->fontDef.pixelSize ) * 720.0 / - GetDeviceCaps(shared_dc,LOGPIXELSY) ); -#else - fe->fontDef.pointSize = int( double( fe->fontDef.pixelSize ) * 720.0 / - 96.0 ); -#endif - } else { - fe->fontDef.pointSize = request.pointSize; - } - - return fe; -} -#endif // TQ_WS_X11 || TQ_WS_WIN - - - - -static TQString styleString( int weight, bool italic, bool oblique ) -{ - TQString result; - if ( weight >= TQFont::Black ) - result = "Black"; - else if ( weight >= TQFont::Bold ) - result = "Bold"; - else if ( weight >= TQFont::DemiBold ) - result = "Demi Bold"; - else if ( weight < TQFont::Normal ) - result = "Light"; - - if ( italic ) - result += " Italic"; - else if ( oblique ) - result += " Oblique"; - - if ( result.isEmpty() ) - result = "Normal"; - - return result.simplifyWhiteSpace(); -} - -/*! - Returns a string that describes the style of the font \a f. For - example, "Bold Italic", "Bold", "Italic" or "Normal". An empty - string may be returned. -*/ -TQString TQFontDatabase::styleString( const TQFont &f ) -{ - // ### fix oblique here - return ::styleString( f.weight(), f.italic(), FALSE ); -} - - -/*! - \class TQFontDatabase ntqfontdatabase.h - \brief The TQFontDatabase class provides information about the fonts available in the underlying window system. - - \ingroup environment - \ingroup graphics - - The most common uses of this class are to query the database for - the list of font families() and for the pointSizes() and styles() - that are available for each family. An alternative to pointSizes() - is smoothSizes() which returns the sizes at which a given family - and style will look attractive. - - If the font family is available from two or more foundries the - foundry name is included in the family name, e.g. "Helvetica - [Adobe]" and "Helvetica [Cronyx]". When you specify a family you - can either use the old hyphenated TQt 2.x "foundry-family" format, - e.g. "Cronyx-Helvetica", or the new bracketed TQt 3.x "family - [foundry]" format e.g. "Helvetica [Cronyx]". If the family has a - foundry it is always returned, e.g. by families(), using the - bracketed format. - - The font() function returns a TQFont given a family, style and - point size. - - A family and style combination can be checked to see if it is - italic() or bold(), and to retrieve its weight(). Similarly we can - call isBitmapScalable(), isSmoothlyScalable(), isScalable() and - isFixedPitch(). - - A text version of a style is given by styleString(). - - The TQFontDatabase class also supports some static functions, for - example, standardSizes(). You can retrieve the Unicode 3.0 - description of a \link TQFont::Script script\endlink using - scriptName(), and a sample of characters in a script with - scriptSample(). - - Example: -\code -#include -#include -#include - -int main( int argc, char **argv ) -{ - TQApplication app( argc, argv ); - TQFontDatabase fdb; - TQStringList families = fdb.families(); - for ( TQStringList::Iterator f = families.begin(); f != families.end(); ++f ) { - TQString family = *f; - tqDebug( family ); - TQStringList styles = fdb.styles( family ); - for ( TQStringList::Iterator s = styles.begin(); s != styles.end(); ++s ) { - TQString style = *s; - TQString dstyle = "\t" + style + " ("; - TQValueList smoothies = fdb.smoothSizes( family, style ); - for ( TQValueList::Iterator points = smoothies.begin(); - points != smoothies.end(); ++points ) { - dstyle += TQString::number( *points ) + " "; - } - dstyle = dstyle.left( dstyle.length() - 1 ) + ")"; - tqDebug( dstyle ); - } - } - return 0; -} -\endcode - This example gets the list of font families, then the list of - styles for each family and the point sizes that are available for - each family/style combination. -*/ -/*! - \obsolete - \fn inline TQStringList TQFontDatabase::families( bool ) const -*/ -/*! - \obsolete - \fn inline TQStringList TQFontDatabase::styles( const TQString &family, - const TQString & ) const -*/ -/*! - \obsolete - \fn inline TQValueList TQFontDatabase::pointSizes( const TQString &family, - const TQString &style , - const TQString & ) -*/ - -/*! - \obsolete - \fn inline TQValueList TQFontDatabase::smoothSizes( const TQString &family, - const TQString &style, - const TQString & ) -*/ -/*! - \obsolete - \fn inline TQFont TQFontDatabase::font( const TQString &familyName, - const TQString &style, - int pointSize, - const TQString &) -*/ -/*! - \obsolete - \fn inline bool TQFontDatabase::isBitmapScalable( const TQString &family, - const TQString &style, - const TQString & ) const -*/ - -/*! - \obsolete - \fn inline bool TQFontDatabase::isSmoothlyScalable( const TQString &family, - const TQString &style, - const TQString & ) const -*/ - -/*! - \obsolete - \fn inline bool TQFontDatabase::isScalable( const TQString &family, - const TQString &style, - const TQString & ) const -*/ - -/*! - \obsolete - \fn inline bool TQFontDatabase::isFixedPitch( const TQString &family, - const TQString &style, - const TQString & ) const -*/ - -/*! - \obsolete - \fn inline bool TQFontDatabase::italic( const TQString &family, - const TQString &style, - const TQString & ) const -*/ - -/*! - \obsolete - \fn inline bool TQFontDatabase::bold( const TQString &family, - const TQString &style, - const TQString & ) const -*/ - -/*! - \obsolete - \fn inline int TQFontDatabase::weight( const TQString &family, - const TQString &style, - const TQString & ) const -*/ - - -/*! - Creates a font database object. -*/ -TQFontDatabase::TQFontDatabase() -{ - createDatabase(); - - d = db; -} - - -/*! Returns a sorted list of the names of the available font families. - - If a family exists in several foundries, the returned name for - that font is in the form "family [foundry]". Examples: "Times - [Adobe]", "Times [Cronyx]", "Palatino". -*/ -TQStringList TQFontDatabase::families() const -{ - load(); - - TQStringList flist; - for ( int i = 0; i < d->count; i++ ) { - TQtFontFamily *f = d->families[i]; - if ( f->count == 0 ) - continue; - if ( f->count == 1 ) { - flist.append( f->name ); - } else { - for ( int j = 0; j < f->count; j++ ) { - TQString str = f->name; - TQString foundry = f->foundries[j]->name; - if ( !foundry.isEmpty() ) { - str += " ["; - str += foundry; - str += "]"; - } - flist.append( str ); - } - } - } - return flist; -} - -/*! - \overload - - Returns a sorted list of the available font families which support - the Unicode script \a script. - - If a family exists in several foundries, the returned name for - that font is in the form "family [foundry]". Examples: "Times - [Adobe]", "Times [Cronyx]", "Palatino". -*/ -TQStringList TQFontDatabase::families( TQFont::Script script ) const -{ - load(); - - TQStringList flist; - for ( int i = 0; i < d->count; i++ ) { - TQtFontFamily *f = d->families[i]; - if ( f->count == 0 ) - continue; - if (!(f->scripts[script] & TQtFontFamily::Supported)) - continue; - if ( f->count == 1 ) { - flist.append( f->name ); - } else { - for ( int j = 0; j < f->count; j++ ) { - TQString str = f->name; - TQString foundry = f->foundries[j]->name; - if ( !foundry.isEmpty() ) { - str += " ["; - str += foundry; - str += "]"; - } - flist.append( str ); - } - } - } - return flist; -} - -/*! - Returns a list of the styles available for the font family \a - family. Some example styles: "Light", "Light Italic", "Bold", - "Oblique", "Demi". The list may be empty. -*/ -TQStringList TQFontDatabase::styles( const TQString &family ) const -{ - TQString familyName, foundryName; - parseFontName( family, foundryName, familyName ); - - load( familyName ); - - TQStringList l; - TQtFontFamily *f = d->family( familyName ); - if ( !f ) - return l; - - TQtFontFoundry allStyles( foundryName ); - for ( int j = 0; j < f->count; j++ ) { - TQtFontFoundry *foundry = f->foundries[j]; - if ( foundryName.isEmpty() || ucstricmp( foundry->name, foundryName ) == 0 ) { - for ( int k = 0; k < foundry->count; k++ ) { - TQtFontStyle::Key ke( foundry->styles[k]->key ); - ke.stretch = 0; - allStyles.style( ke, TRUE ); - } - } - } - - for ( int i = 0; i < allStyles.count; i++ ) - l.append( ::styleString( allStyles.styles[i]->key.weight, - allStyles.styles[i]->key.italic, - allStyles.styles[i]->key.oblique ) ); - return l; -} - -/*! - Returns TRUE if the font that has family \a family and style \a - style is fixed pitch; otherwise returns FALSE. -*/ - -bool TQFontDatabase::isFixedPitch(const TQString &family, - const TQString &style) const -{ - Q_UNUSED(style); - - TQString familyName, foundryName; - parseFontName( family, foundryName, familyName ); - - load( familyName ); - - TQtFontFamily *f = d->family( familyName ); -#if defined(Q_OS_MAC) - if (f) { - if (!f->fixedPitchComputed) { - TQFontMetrics fm(familyName); - f->fixedPitch = fm.width('i') == fm.width('m'); - f->fixedPitchComputed = TRUE; - } - } -#endif - - return ( f && f->fixedPitch ); -} - -/*! - Returns TRUE if the font that has family \a family and style \a - style is a scalable bitmap font; otherwise returns FALSE. Scaling - a bitmap font usually produces an unattractive hardly readable - result, because the pixels of the font are scaled. If you need to - scale a bitmap font it is better to scale it to one of the fixed - sizes returned by smoothSizes(). - - \sa isScalable(), isSmoothlyScalable() -*/ -bool TQFontDatabase::isBitmapScalable( const TQString &family, - const TQString &style) const -{ - bool bitmapScalable = FALSE; - TQString familyName, foundryName; - parseFontName( family, foundryName, familyName ); - - load( familyName ); - - TQtFontStyle::Key styleKey( style ); - - TQtFontFamily *f = d->family( familyName ); - if ( !f ) return bitmapScalable; - - for ( int j = 0; j < f->count; j++ ) { - TQtFontFoundry *foundry = f->foundries[j]; - if ( foundryName.isEmpty() || ucstricmp( foundry->name, foundryName ) == 0 ) { - for ( int k = 0; k < foundry->count; k++ ) - if ((style.isEmpty() || foundry->styles[k]->key == styleKey) && - foundry->styles[k]->bitmapScalable && !foundry->styles[k]->smoothScalable) { - bitmapScalable = TRUE; - goto end; - } - } - } - end: - return bitmapScalable; -} - - -/*! - Returns TRUE if the font that has family \a family and style \a - style is smoothly scalable; otherwise returns FALSE. If this - function returns TRUE, it's safe to scale this font to any size, - and the result will always look attractive. - - \sa isScalable(), isBitmapScalable() -*/ -bool TQFontDatabase::isSmoothlyScalable( const TQString &family, - const TQString &style) const -{ - bool smoothScalable = FALSE; - TQString familyName, foundryName; - parseFontName( family, foundryName, familyName ); - - load( familyName ); - - TQtFontStyle::Key styleKey( style ); - - TQtFontFamily *f = d->family( familyName ); - if ( !f ) return smoothScalable; - - for ( int j = 0; j < f->count; j++ ) { - TQtFontFoundry *foundry = f->foundries[j]; - if ( foundryName.isEmpty() || ucstricmp( foundry->name, foundryName ) == 0 ) { - for ( int k = 0; k < foundry->count; k++ ) - if ((style.isEmpty() || foundry->styles[k]->key == styleKey) && foundry->styles[k]->smoothScalable) { - smoothScalable = TRUE; - goto end; - } - } - } - end: - return smoothScalable; -} - -/*! - Returns TRUE if the font that has family \a family and style \a - style is scalable; otherwise returns FALSE. - - \sa isBitmapScalable(), isSmoothlyScalable() -*/ -bool TQFontDatabase::isScalable( const TQString &family, - const TQString &style) const -{ - if ( isSmoothlyScalable( family, style) ) - return TRUE; - - return isBitmapScalable( family, style); -} - - -/*! - Returns a list of the point sizes available for the font that has - family \a family and style \a style. The list may be empty. - - \sa smoothSizes(), standardSizes() -*/ -TQValueList TQFontDatabase::pointSizes( const TQString &family, - const TQString &style) -{ -#if defined(TQ_WS_MAC) - // windows and macosx are always smoothly scalable - Q_UNUSED( family ); - Q_UNUSED( style ); - return standardSizes(); -#else - bool smoothScalable = FALSE; - TQString familyName, foundryName; - parseFontName( family, foundryName, familyName ); - - load( familyName ); - - TQtFontStyle::Key styleKey( style ); - - TQValueList sizes; - - TQtFontFamily *fam = d->family( familyName ); - if ( !fam ) return sizes; - - for ( int j = 0; j < fam->count; j++ ) { - TQtFontFoundry *foundry = fam->foundries[j]; - if ( foundryName.isEmpty() || ucstricmp( foundry->name, foundryName ) == 0 ) { - TQtFontStyle *style = foundry->style( styleKey ); - if ( !style ) continue; - - if ( style->smoothScalable ) { - smoothScalable = TRUE; - goto end; - } - for ( int l = 0; l < style->count; l++ ) { - const TQtFontSize *size = style->pixelSizes + l; - - if (size->pixelSize != 0 && size->pixelSize != USHRT_MAX) { -#ifdef TQ_WS_X11 - const uint pointSize = tqRound(qt_pointSize(size->pixelSize, 0, -1)); -#else - const uint pointSize = size->pixelSize; // embedded uses 72dpi -#endif - if (! sizes.contains(pointSize)) - sizes.append(pointSize); - } - } - } - } - end: - if ( smoothScalable ) - return standardSizes(); - - qHeapSort( sizes ); - return sizes; -#endif -} - -/*! - Returns a TQFont object that has family \a family, style \a style - and point size \a pointSize. If no matching font could be created, - a TQFont object that uses the application's default font is - returned. -*/ -TQFont TQFontDatabase::font( const TQString &family, const TQString &style, - int pointSize) -{ - TQString familyName, foundryName; - parseFontName( family, foundryName, familyName ); - - load( familyName ); - - TQtFontFoundry allStyles( foundryName ); - TQtFontFamily *f = d->family( familyName ); - if ( !f ) return TQApplication::font(); - - for ( int j = 0; j < f->count; j++ ) { - TQtFontFoundry *foundry = f->foundries[j]; - if ( foundryName.isEmpty() || ucstricmp( foundry->name, foundryName ) == 0 ) { - for ( int k = 0; k < foundry->count; k++ ) - allStyles.style( foundry->styles[k]->key, TRUE ); - } - } - - TQtFontStyle::Key styleKey( style ); - TQtFontStyle *s = bestStyle(&allStyles, styleKey); - - if ( !s ) // no styles found? - return TQApplication::font(); - return TQFont( family, pointSize, s->key.weight, - s->key.italic ? TRUE : s->key.oblique ? TRUE : FALSE ); -} - - -/*! - Returns the point sizes of a font that has family \a family and - style \a style that will look attractive. The list may be empty. - For non-scalable fonts and bitmap scalable fonts, this function - is equivalent to pointSizes(). - - \sa pointSizes(), standardSizes() -*/ -TQValueList TQFontDatabase::smoothSizes( const TQString &family, - const TQString &style) -{ -#ifdef TQ_WS_WIN - Q_UNUSED( family ); - Q_UNUSED( style ); - return TQFontDatabase::standardSizes(); -#else - bool smoothScalable = FALSE; - TQString familyName, foundryName; - parseFontName( family, foundryName, familyName ); - - load( familyName ); - - TQtFontStyle::Key styleKey( style ); - - TQValueList sizes; - - TQtFontFamily *fam = d->family( familyName ); - if ( !fam ) - return sizes; - - for ( int j = 0; j < fam->count; j++ ) { - TQtFontFoundry *foundry = fam->foundries[j]; - if ( foundryName.isEmpty() || - ucstricmp( foundry->name, foundryName ) == 0 ) { - TQtFontStyle *style = foundry->style( styleKey ); - if ( !style ) continue; - - if ( style->smoothScalable ) { - smoothScalable = TRUE; - goto end; - } - for ( int l = 0; l < style->count; l++ ) { - const TQtFontSize *size = style->pixelSizes + l; - - if ( size->pixelSize != 0 && size->pixelSize != USHRT_MAX ) { -#ifdef TQ_WS_X11 - const uint pointSize = tqRound(qt_pointSize(size->pixelSize, 0, -1)); -#else - const uint pointSize = size->pixelSize; // embedded uses 72dpi -#endif - if (! sizes.contains(pointSize)) - sizes.append( pointSize ); - } - } - } - } - end: - if ( smoothScalable ) - return TQFontDatabase::standardSizes(); - - qHeapSort( sizes ); - return sizes; -#endif -} - - -/*! - Returns a list of standard font sizes. - - \sa smoothSizes(), pointSizes() -*/ -TQValueList TQFontDatabase::standardSizes() -{ - TQValueList ret; - static const unsigned short standard[] = - { 6, 7, 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72, 0 }; - const unsigned short *sizes = standard; - while ( *sizes ) ret << *sizes++; - return ret; -} - - -/*! - Returns TRUE if the font that has family \a family and style \a - style is italic; otherwise returns FALSE. - - \sa weight(), bold() -*/ -bool TQFontDatabase::italic( const TQString &family, - const TQString &style) const -{ - TQString familyName, foundryName; - parseFontName( family, foundryName, familyName ); - - load( familyName ); - - TQtFontFoundry allStyles( foundryName ); - TQtFontFamily *f = d->family( familyName ); - if ( !f ) return FALSE; - - for ( int j = 0; j < f->count; j++ ) { - TQtFontFoundry *foundry = f->foundries[j]; - if ( foundryName.isEmpty() || ucstricmp( foundry->name, foundryName ) == 0 ) { - for ( int k = 0; k < foundry->count; k++ ) - allStyles.style( foundry->styles[k]->key, TRUE ); - } - } - - TQtFontStyle::Key styleKey( style ); - TQtFontStyle *s = allStyles.style( styleKey ); - return s && s->key.italic; -} - - -/*! - Returns TRUE if the font that has family \a family and style \a - style is bold; otherwise returns FALSE. - - \sa italic(), weight() -*/ -bool TQFontDatabase::bold( const TQString &family, - const TQString &style) const -{ - TQString familyName, foundryName; - parseFontName( family, foundryName, familyName ); - - load( familyName ); - - TQtFontFoundry allStyles( foundryName ); - TQtFontFamily *f = d->family( familyName ); - if ( !f ) return FALSE; - - for ( int j = 0; j < f->count; j++ ) { - TQtFontFoundry *foundry = f->foundries[j]; - if ( foundryName.isEmpty() || - ucstricmp( foundry->name, foundryName ) == 0 ) { - for ( int k = 0; k < foundry->count; k++ ) - allStyles.style( foundry->styles[k]->key, TRUE ); - } - } - - TQtFontStyle::Key styleKey( style ); - TQtFontStyle *s = allStyles.style( styleKey ); - return s && s->key.weight >= TQFont::Bold; -} - - -/*! - Returns the weight of the font that has family \a family and style - \a style. If there is no such family and style combination, - returns -1. - - \sa italic(), bold() -*/ -int TQFontDatabase::weight( const TQString &family, - const TQString &style) const -{ - TQString familyName, foundryName; - parseFontName( family, foundryName, familyName ); - - load( familyName ); - - TQtFontFoundry allStyles( foundryName ); - TQtFontFamily *f = d->family( familyName ); - if ( !f ) return -1; - - for ( int j = 0; j < f->count; j++ ) { - TQtFontFoundry *foundry = f->foundries[j]; - if ( foundryName.isEmpty() || - ucstricmp( foundry->name, foundryName ) == 0 ) { - for ( int k = 0; k < foundry->count; k++ ) - allStyles.style( foundry->styles[k]->key, TRUE ); - } - } - - TQtFontStyle::Key styleKey( style ); - TQtFontStyle *s = allStyles.style( styleKey ); - return s ? s->key.weight : -1; -} - - -/*! - Returns a string that gives a default description of the \a script - (e.g. for displaying to the user in a dialog). The name matches - the name of the script as defined by the Unicode 3.0 standard. - - \sa TQFont::Script -*/ -TQString TQFontDatabase::scriptName(TQFont::Script script) -{ - const char *name = 0; - - switch (script) { - case TQFont::Latin: - name = TQT_TRANSLATE_NOOP("TQFont", "Latin"); - break; - case TQFont::Greek: - name = TQT_TRANSLATE_NOOP("TQFont", "Greek" ); - break; - case TQFont::Cyrillic: - name = TQT_TRANSLATE_NOOP("TQFont", "Cyrillic" ); - break; - case TQFont::Armenian: - name = TQT_TRANSLATE_NOOP("TQFont", "Armenian" ); - break; - case TQFont::Georgian: - name = TQT_TRANSLATE_NOOP("TQFont", "Georgian" ); - break; - case TQFont::Runic: - name = TQT_TRANSLATE_NOOP("TQFont", "Runic" ); - break; - case TQFont::Ogham: - name = TQT_TRANSLATE_NOOP("TQFont", "Ogham" ); - break; - case TQFont::SpacingModifiers: - name = TQT_TRANSLATE_NOOP("TQFont", "SpacingModifiers" ); - break; - case TQFont::CombiningMarks: - name = TQT_TRANSLATE_NOOP("TQFont", "CombiningMarks" ); - break; - case TQFont::Hebrew: - name = TQT_TRANSLATE_NOOP("TQFont", "Hebrew" ); - break; - case TQFont::Arabic: - name = TQT_TRANSLATE_NOOP("TQFont", "Arabic" ); - break; - case TQFont::Syriac: - name = TQT_TRANSLATE_NOOP("TQFont", "Syriac" ); - break; - case TQFont::Thaana: - name = TQT_TRANSLATE_NOOP("TQFont", "Thaana" ); - break; - case TQFont::Devanagari: - name = TQT_TRANSLATE_NOOP("TQFont", "Devanagari" ); - break; - case TQFont::Bengali: - name = TQT_TRANSLATE_NOOP("TQFont", "Bengali" ); - break; - case TQFont::Gurmukhi: - name = TQT_TRANSLATE_NOOP("TQFont", "Gurmukhi" ); - break; - case TQFont::Gujarati: - name = TQT_TRANSLATE_NOOP("TQFont", "Gujarati" ); - break; - case TQFont::Oriya: - name = TQT_TRANSLATE_NOOP("TQFont", "Oriya" ); - break; - case TQFont::Tamil: - name = TQT_TRANSLATE_NOOP("TQFont", "Tamil" ); - break; - case TQFont::Telugu: - name = TQT_TRANSLATE_NOOP("TQFont", "Telugu" ); - break; - case TQFont::Kannada: - name = TQT_TRANSLATE_NOOP("TQFont", "Kannada" ); - break; - case TQFont::Malayalam: - name = TQT_TRANSLATE_NOOP("TQFont", "Malayalam" ); - break; - case TQFont::Sinhala: - name = TQT_TRANSLATE_NOOP("TQFont", "Sinhala" ); - break; - case TQFont::Thai: - name = TQT_TRANSLATE_NOOP("TQFont", "Thai" ); - break; - case TQFont::Lao: - name = TQT_TRANSLATE_NOOP("TQFont", "Lao" ); - break; - case TQFont::Tibetan: - name = TQT_TRANSLATE_NOOP("TQFont", "Tibetan" ); - break; - case TQFont::Myanmar: - name = TQT_TRANSLATE_NOOP("TQFont", "Myanmar" ); - break; - case TQFont::Khmer: - name = TQT_TRANSLATE_NOOP("TQFont", "Khmer" ); - break; - case TQFont::Han: - name = TQT_TRANSLATE_NOOP("TQFont", "Han" ); - break; - case TQFont::Hiragana: - name = TQT_TRANSLATE_NOOP("TQFont", "Hiragana" ); - break; - case TQFont::Katakana: - name = TQT_TRANSLATE_NOOP("TQFont", "Katakana" ); - break; - case TQFont::Hangul: - name = TQT_TRANSLATE_NOOP("TQFont", "Hangul" ); - break; - case TQFont::Bopomofo: - name = TQT_TRANSLATE_NOOP("TQFont", "Bopomofo" ); - break; - case TQFont::Yi: - name = TQT_TRANSLATE_NOOP("TQFont", "Yi" ); - break; - case TQFont::Ethiopic: - name = TQT_TRANSLATE_NOOP("TQFont", "Ethiopic" ); - break; - case TQFont::Cherokee: - name = TQT_TRANSLATE_NOOP("TQFont", "Cherokee" ); - break; - case TQFont::CanadianAboriginal: - name = TQT_TRANSLATE_NOOP("TQFont", "Canadian Aboriginal" ); - break; - case TQFont::Mongolian: - name = TQT_TRANSLATE_NOOP("TQFont", "Mongolian" ); - break; - - case TQFont::CurrencySymbols: - name = TQT_TRANSLATE_NOOP("TQFont", "Currency Symbols" ); - break; - - case TQFont::LetterlikeSymbols: - name = TQT_TRANSLATE_NOOP("TQFont", "Letterlike Symbols" ); - break; - - case TQFont::NumberForms: - name = TQT_TRANSLATE_NOOP("TQFont", "Number Forms" ); - break; - - case TQFont::MathematicalOperators: - name = TQT_TRANSLATE_NOOP("TQFont", "Mathematical Operators" ); - break; - - case TQFont::TechnicalSymbols: - name = TQT_TRANSLATE_NOOP("TQFont", "Technical Symbols" ); - break; - - case TQFont::GeometricSymbols: - name = TQT_TRANSLATE_NOOP("TQFont", "Geometric Symbols" ); - break; - - case TQFont::MiscellaneousSymbols: - name = TQT_TRANSLATE_NOOP("TQFont", "Miscellaneous Symbols" ); - break; - - case TQFont::EnclosedAndSquare: - name = TQT_TRANSLATE_NOOP("TQFont", "Enclosed and Square" ); - break; - - case TQFont::Braille: - name = TQT_TRANSLATE_NOOP("TQFont", "Braille" ); - break; - - case TQFont::Unicode: - name = TQT_TRANSLATE_NOOP("TQFont", "Unicode" ); - break; - - case TQFont::Tagalog: - name = TQT_TRANSLATE_NOOP( "TQFont", "Tagalog" ); - break; - - case TQFont::Hanunoo: - name = TQT_TRANSLATE_NOOP( "TQFont", "Hanunoo" ); - break; - - case TQFont::Buhid: - name = TQT_TRANSLATE_NOOP( "TQFont", "Buhid" ); - break; - - case TQFont::Tagbanwa: - name = TQT_TRANSLATE_NOOP( "TQFont", "Tagbanwa" ); - break; - - case TQFont::KatakanaHalfWidth: - name = TQT_TRANSLATE_NOOP( "TQFont", "Katakana Half-Width Forms" ); - break; - - case TQFont::Han_Japanese: - name = TQT_TRANSLATE_NOOP( "TQFont", "Han (Japanese)" ); - break; - - case TQFont::Han_SimplifiedChinese: - name = TQT_TRANSLATE_NOOP( "TQFont", "Han (Simplified Chinese)" ); - break; - - case TQFont::Han_TraditionalChinese: - name = TQT_TRANSLATE_NOOP( "TQFont", "Han (Traditional Chinese)" ); - break; - - case TQFont::Han_Korean: - name = TQT_TRANSLATE_NOOP( "TQFont", "Han (Korean)" ); - break; - - default: - name = TQT_TRANSLATE_NOOP( "TQFont", "Unknown Script" ); - break; - } - - return tqApp ? tqApp->translate("TQFont", name) : TQString::fromLatin1(name); -} - - -/*! - Returns a string with sample characters from \a script. - - \sa TQFont::Script -*/ -TQString TQFontDatabase::scriptSample(TQFont::Script script) -{ - TQString sample = "AaBb"; - - switch (script) { - case TQFont::Latin: - // This is cheating... we only show latin-1 characters so that we don't - // end up loading lots of fonts - at least on X11... - sample += TQChar(0x00C3); - sample += TQChar(0x00E1); - sample += "Zz"; - break; - case TQFont::Greek: - sample += TQChar(0x0393); - sample += TQChar(0x03B1); - sample += TQChar(0x03A9); - sample += TQChar(0x03C9); - break; - case TQFont::Cyrillic: - sample += TQChar(0x0414); - sample += TQChar(0x0434); - sample += TQChar(0x0436); - sample += TQChar(0x0402); - break; - case TQFont::Armenian: - sample += TQChar(0x053f); - sample += TQChar(0x054f); - sample += TQChar(0x056f); - sample += TQChar(0x057f); - break; - case TQFont::Georgian: - sample += TQChar(0x10a0); - sample += TQChar(0x10b0); - sample += TQChar(0x10c0); - sample += TQChar(0x10d0); - break; - case TQFont::Runic: - sample += TQChar(0x16a0); - sample += TQChar(0x16b0); - sample += TQChar(0x16c0); - sample += TQChar(0x16d0); - break; - case TQFont::Ogham: - sample += TQChar(0x1681); - sample += TQChar(0x1687); - sample += TQChar(0x1693); - sample += TQChar(0x168d); - break; - - - - case TQFont::Hebrew: - sample += TQChar(0x05D0); - sample += TQChar(0x05D1); - sample += TQChar(0x05D2); - sample += TQChar(0x05D3); - break; - case TQFont::Arabic: - sample += TQChar(0x0628); - sample += TQChar(0x0629); - sample += TQChar(0x062A); - sample += TQChar(0x063A); - break; - case TQFont::Syriac: - sample += TQChar(0x0715); - sample += TQChar(0x0725); - sample += TQChar(0x0716); - sample += TQChar(0x0726); - break; - case TQFont::Thaana: - sample += TQChar(0x0784); - sample += TQChar(0x0794); - sample += TQChar(0x078c); - sample += TQChar(0x078d); - break; - - - - case TQFont::Devanagari: - sample += TQChar(0x0905); - sample += TQChar(0x0915); - sample += TQChar(0x0925); - sample += TQChar(0x0935); - break; - case TQFont::Bengali: - sample += TQChar(0x0986); - sample += TQChar(0x0996); - sample += TQChar(0x09a6); - sample += TQChar(0x09b6); - break; - case TQFont::Gurmukhi: - sample += TQChar(0x0a05); - sample += TQChar(0x0a15); - sample += TQChar(0x0a25); - sample += TQChar(0x0a35); - break; - case TQFont::Gujarati: - sample += TQChar(0x0a85); - sample += TQChar(0x0a95); - sample += TQChar(0x0aa5); - sample += TQChar(0x0ab5); - break; - case TQFont::Oriya: - sample += TQChar(0x0b06); - sample += TQChar(0x0b16); - sample += TQChar(0x0b2b); - sample += TQChar(0x0b36); - break; - case TQFont::Tamil: - sample += TQChar(0x0b89); - sample += TQChar(0x0b99); - sample += TQChar(0x0ba9); - sample += TQChar(0x0bb9); - break; - case TQFont::Telugu: - sample += TQChar(0x0c05); - sample += TQChar(0x0c15); - sample += TQChar(0x0c25); - sample += TQChar(0x0c35); - break; - case TQFont::Kannada: - sample += TQChar(0x0c85); - sample += TQChar(0x0c95); - sample += TQChar(0x0ca5); - sample += TQChar(0x0cb5); - break; - case TQFont::Malayalam: - sample += TQChar(0x0d05); - sample += TQChar(0x0d15); - sample += TQChar(0x0d25); - sample += TQChar(0x0d35); - break; - case TQFont::Sinhala: - sample += TQChar(0x0d90); - sample += TQChar(0x0da0); - sample += TQChar(0x0db0); - sample += TQChar(0x0dc0); - break; - case TQFont::Thai: - sample += TQChar(0x0e02); - sample += TQChar(0x0e12); - sample += TQChar(0x0e22); - sample += TQChar(0x0e32); - break; - case TQFont::Lao: - sample += TQChar(0x0e8d); - sample += TQChar(0x0e9d); - sample += TQChar(0x0ead); - sample += TQChar(0x0ebd); - break; - case TQFont::Tibetan: - sample += TQChar(0x0f00); - sample += TQChar(0x0f01); - sample += TQChar(0x0f02); - sample += TQChar(0x0f03); - break; - case TQFont::Myanmar: - sample += TQChar(0x1000); - sample += TQChar(0x1001); - sample += TQChar(0x1002); - sample += TQChar(0x1003); - break; - case TQFont::Khmer: - sample += TQChar(0x1780); - sample += TQChar(0x1790); - sample += TQChar(0x17b0); - sample += TQChar(0x17c0); - break; - - - - case TQFont::Han: - sample += TQChar(0x6f84); - sample += TQChar(0x820a); - sample += TQChar(0x61a9); - sample += TQChar(0x9781); - break; - case TQFont::Hiragana: - sample += TQChar(0x3050); - sample += TQChar(0x3060); - sample += TQChar(0x3070); - sample += TQChar(0x3080); - break; - case TQFont::Katakana: - sample += TQChar(0x30b0); - sample += TQChar(0x30c0); - sample += TQChar(0x30d0); - sample += TQChar(0x30e0); - break; - case TQFont::Hangul: - sample += TQChar(0xac00); - sample += TQChar(0xac11); - sample += TQChar(0xac1a); - sample += TQChar(0xac2f); - break; - case TQFont::Bopomofo: - sample += TQChar(0x3105); - sample += TQChar(0x3115); - sample += TQChar(0x3125); - sample += TQChar(0x3129); - break; - case TQFont::Yi: - sample += TQChar(0xa1a8); - sample += TQChar(0xa1a6); - sample += TQChar(0xa200); - sample += TQChar(0xa280); - break; - - - - case TQFont::Ethiopic: - sample += TQChar(0x1200); - sample += TQChar(0x1240); - sample += TQChar(0x1280); - sample += TQChar(0x12c0); - break; - case TQFont::Cherokee: - sample += TQChar(0x13a0); - sample += TQChar(0x13b0); - sample += TQChar(0x13c0); - sample += TQChar(0x13d0); - break; - case TQFont::CanadianAboriginal: - sample += TQChar(0x1410); - sample += TQChar(0x1500); - sample += TQChar(0x15f0); - sample += TQChar(0x1650); - break; - case TQFont::Mongolian: - sample += TQChar(0x1820); - sample += TQChar(0x1840); - sample += TQChar(0x1860); - sample += TQChar(0x1880); - break; - - - case TQFont::CurrencySymbols: - case TQFont::LetterlikeSymbols: - case TQFont::NumberForms: - case TQFont::MathematicalOperators: - case TQFont::TechnicalSymbols: - case TQFont::GeometricSymbols: - case TQFont::MiscellaneousSymbols: - case TQFont::EnclosedAndSquare: - case TQFont::Braille: - break; - - - case TQFont::Unicode: - sample += TQChar(0x0174); - sample += TQChar(0x0628); - sample += TQChar(0x0e02); - sample += TQChar(0x263A); - sample += TQChar(0x3129); - sample += TQChar(0x61a9); - sample += TQChar(0xac2f); - break; - - - - default: - sample += TQChar(0xfffd); - sample += TQChar(0xfffd); - sample += TQChar(0xfffd); - sample += TQChar(0xfffd); - break; - } - - return sample; -} - - - - -/*! - \internal - - This makes sense of the font family name: - - 1) if the family name contains a '-' (ie. "Adobe-Courier"), then we - split at the '-', and use the string as the foundry, and the string to - the right as the family - - 2) if the family name contains a '[' and a ']', then we take the text - between the square brackets as the foundry, and the text before the - square brackets as the family (ie. "Arial [Monotype]") -*/ -void TQFontDatabase::parseFontName(const TQString &name, TQString &foundry, TQString &family) -{ - if ( name.contains('-') ) { - int i = name.find('-'); - foundry = name.left( i ); - family = name.right( name.length() - i - 1 ); - } else if ( name.contains('[') && name.contains(']')) { - int i = name.find('['); - int li = name.findRev(']'); - - if (i < li) { - foundry = name.mid(i + 1, li - i - 1); - if (name[i - 1] == ' ') - i--; - family = name.left(i); - } - } else { - foundry = TQString::null; - family = name; - } -} - -#endif // TQT_NO_FONTDATABASE diff --git a/src/kernel/qfontdatabase_x11.cpp b/src/kernel/qfontdatabase_x11.cpp deleted file mode 100644 index d1045740d..000000000 --- a/src/kernel/qfontdatabase_x11.cpp +++ /dev/null @@ -1,2031 +0,0 @@ -/**************************************************************************** -** -** Implementation of platform specific TQFontDatabase -** -** Created : 970521 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#include - -#include -#include - -#include "qt_x11_p.h" - -#include -#include - -#include -#include -#include -#include - -#ifndef TQT_NO_XFTFREETYPE -#include -#include FT_FREETYPE_H -#endif - -#ifndef QT_XFT2 -#define FcBool Bool -#define FcTrue True -#define FcFalse False -#endif - -#ifdef TQFONTDATABASE_DEBUG -# define FD_DEBUG tqDebug -#else -# define FD_DEBUG if (FALSE) tqDebug -#endif // TQFONTDATABASE_DEBUG - -// from qfont_x11.cpp -extern double qt_pointSize(double pixelSize, TQPaintDevice *paintdevice, int screen); -extern double qt_pixelSize(double pointSize, TQPaintDevice *paintdevice, int screen); - - -static inline void capitalize ( char *s ) -{ - bool space = TRUE; - while( *s ) { - if ( space ) - *s = toupper( *s ); - space = ( *s == ' ' ); - ++s; - } -} - - -// ----- begin of generated code ----- - -#define make_tag( c1, c2, c3, c4 ) \ -( (((unsigned int)c1)<<24) | (((unsigned int)c2)<<16) | \ -(((unsigned int)c3)<<8) | ((unsigned int)c4) ) - -struct XlfdEncoding { - const char *name; - int id; - int mib; - unsigned int hash1; - unsigned int hash2; -}; - -static const XlfdEncoding xlfd_encoding[] = { - { "iso8859-1", 0, 4, make_tag('i','s','o','8'), make_tag('5','9','-','1') }, - { "iso8859-2", 1, 5, make_tag('i','s','o','8'), make_tag('5','9','-','2') }, - { "iso8859-3", 2, 6, make_tag('i','s','o','8'), make_tag('5','9','-','3') }, - { "iso8859-4", 3, 7, make_tag('i','s','o','8'), make_tag('5','9','-','4') }, - { "iso8859-9", 4, 12, make_tag('i','s','o','8'), make_tag('5','9','-','9') }, - { "iso8859-10", 5, 13, make_tag('i','s','o','8'), make_tag('9','-','1','0') }, - { "iso8859-13", 6, 109, make_tag('i','s','o','8'), make_tag('9','-','1','3') }, - { "iso8859-14", 7, 110, make_tag('i','s','o','8'), make_tag('9','-','1','4') }, - { "iso8859-15", 8, 111, make_tag('i','s','o','8'), make_tag('9','-','1','5') }, - { "hp-roman8", 9, 2004, make_tag('h','p','-','r'), make_tag('m','a','n','8') }, - { "jisx0208*-0", 10, 63, make_tag('j','i','s','x'), 0 }, -#define LAST_LATIN_ENCODING 10 - { "iso8859-5", 11, 8, make_tag('i','s','o','8'), make_tag('5','9','-','5') }, - { "*-cp1251", 12, 2251, 0, make_tag('1','2','5','1') }, - { "koi8-ru", 13, 2084, make_tag('k','o','i','8'), make_tag('8','-','r','u') }, - { "koi8-u", 14, 2088, make_tag('k','o','i','8'), make_tag('i','8','-','u') }, - { "koi8-r", 15, 2084, make_tag('k','o','i','8'), make_tag('i','8','-','r') }, - { "iso8859-7", 16, 10, make_tag('i','s','o','8'), make_tag('5','9','-','7') }, - { "iso10646-1", 17, 0, make_tag('i','s','o','1'), make_tag('4','6','-','1') }, - { "iso8859-8", 18, 85, make_tag('i','s','o','8'), make_tag('5','9','-','8') }, - { "gb18030-0", 19, -114, make_tag('g','b','1','8'), make_tag('3','0','-','0') }, - { "gb18030.2000-0", 20, -113, make_tag('g','b','1','8'), make_tag('0','0','-','0') }, - { "gbk-0", 21, -113, make_tag('g','b','k','-'), make_tag('b','k','-','0') }, - { "gb2312.*-0", 22, 57, make_tag('g','b','2','3'), 0 }, - { "jisx0201*-0", 23, 15, make_tag('j','i','s','x'), 0 }, - { "ksc5601*-*", 24, 36, make_tag('k','s','c','5'), 0 }, - { "big5hkscs-0", 25, -2101, make_tag('b','i','g','5'), make_tag('c','s','-','0') }, - { "hkscs-1", 26, -2101, make_tag('h','k','s','c'), make_tag('c','s','-','1') }, - { "big5*-*", 27, -2026, make_tag('b','i','g','5'), 0 }, - { "tscii-*", 28, 2028, make_tag('t','s','c','i'), 0 }, - { "tis620*-*", 29, 2259, make_tag('t','i','s','6'), 0 }, - { "iso8859-11", 30, 2259, make_tag('i','s','o','8'), make_tag('9','-','1','1') }, - { "mulelao-1", 31, -4242, make_tag('m','u','l','e'), make_tag('a','o','-','1') }, - { "ethiopic-unicode", 32, 0, make_tag('e','t','h','i'), make_tag('c','o','d','e') }, - { "unicode-*", 33, 0, make_tag('u','n','i','c'), 0 }, - { "*-symbol", 34, 0, 0, make_tag('m','b','o','l') }, - { "*-fontspecific", 35, 0, 0, make_tag('i','f','i','c') }, - { "fontspecific-*", 36, 0, make_tag('f','o','n','t'), 0 }, - { 0, 0, 0, 0, 0 } -}; - -static const char scripts_for_xlfd_encoding[37][61] = { - // iso8859-1 - { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0 }, - // iso8859-2 - { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0 }, - // iso8859-3 - { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0 }, - // iso8859-4 - { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0 }, - // iso8859-9 - { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0 }, - // iso8859-10 - { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0 }, - // iso8859-13 - { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0 }, - // iso8859-14 - { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0 }, - // iso8859-15 - { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0 }, - // hp-roman8 - { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0 }, - // jisx0208*-0 - { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, - 0 }, - // iso8859-5 - { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0 }, - // *-cp1251 - { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0 }, - // koi8-ru - { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0 }, - // koi8-u - { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0 }, - // koi8-r - { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0 }, - // iso8859-7 - { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0 }, - // iso10646-1 - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0 }, - // iso8859-8 - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0 }, - // gb18030-0 - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, - 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, - 0 }, - // gb18030.2000-0 - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, - 0 }, - // gbk-0 - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, - 0 }, - // gb2312.*-0 - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, - 0 }, - // jisx0201*-0 - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, - 0 }, - // ksc5601*-* - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, - 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 1 }, - // big5hkscs-0 - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, - 0 }, - // hkscs-1 - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, - 0 }, - // big5*-* - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, - 0 }, - // tscii-* - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0 }, - // tis620*-* - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0 }, - // iso8859-11 - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0 }, - // mulelao-1 - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0 }, - // ethiopic-unicode - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0 }, - // unicode-* - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0 }, - // *-symbol - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, - 0 }, - // *-fontspecific - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, - 0 }, - // fontspecific-* - { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, - 0 } - -}; - -// ----- end of generated code ----- - - -const int numEncodings = sizeof( xlfd_encoding ) / sizeof( XlfdEncoding ) - 1; - -int qt_xlfd_encoding_id( const char *encoding ) -{ - // tqDebug("looking for encoding id for '%s'", encoding ); - int len = strlen( encoding ); - if ( len < 4 ) - return -1; - unsigned int hash1 = make_tag( encoding[0], encoding[1], encoding[2], encoding[3] ); - const char *ch = encoding + len - 4; - unsigned int hash2 = make_tag( ch[0], ch[1], ch[2], ch[3] ); - - const XlfdEncoding *enc = xlfd_encoding; - for ( ; enc->name; ++enc ) { - if ( (enc->hash1 && enc->hash1 != hash1) || - (enc->hash2 && enc->hash2 != hash2) ) - continue; - // hashes match, do a compare if strings match - // the enc->name can contain '*'s we have to interpret correctly - const char *n = enc->name; - const char *e = encoding; - while ( 1 ) { - // tqDebug("bol: *e='%c', *n='%c'", *e, *n ); - if ( *e == '\0' ) { - if ( *n ) - break; - // tqDebug( "found encoding id %d", enc->id ); - return enc->id; - } - if ( *e == *n ) { - ++e; - ++n; - continue; - } - if ( *n != '*' ) - break; - ++n; - // tqDebug("skip: *e='%c', *n='%c'", *e, *n ); - while ( *e && *e != *n ) - ++e; - } - } - // tqDebug( "couldn't find encoding %s", encoding ); - return -1; -} - -int qt_mib_for_xlfd_encoding( const char *encoding ) -{ - int id = qt_xlfd_encoding_id( encoding ); - if ( id != -1 ) return xlfd_encoding[id].mib; - return 0; -} - -int qt_encoding_id_for_mib( int mib ) -{ - const XlfdEncoding *enc = xlfd_encoding; - for ( ; enc->name; ++enc ) { - if ( enc->mib == mib ) - return enc->id; - } - return -1; -} - -static const char * xlfd_for_id( int id ) -{ - // special case: -1 returns the "*-*" encoding, allowing us to do full - // database population in a single X server round trip. - if ( id < 0 || id > numEncodings ) - return "*-*"; - return xlfd_encoding[id].name; -} - -enum XLFDFieldNames { - Foundry, - Family, - Weight, - Slant, - Width, - AddStyle, - PixelSize, - PointSize, - ResolutionX, - ResolutionY, - Spacing, - AverageWidth, - CharsetRegistry, - CharsetEncoding, - NFontFields -}; - -// Splits an X font name into fields separated by '-' -static bool parseXFontName( char *fontName, char **tokens ) -{ - if ( ! fontName || fontName[0] == '0' || fontName[0] != '-' ) { - tokens[0] = 0; - return FALSE; - } - - int i; - ++fontName; - for ( i = 0; i < NFontFields && fontName && fontName[0]; ++i ) { - tokens[i] = fontName; - for ( ;; ++fontName ) { - if ( *fontName == '-' ) - break; - if ( ! *fontName ) { - fontName = 0; - break; - } - } - - if ( fontName ) *fontName++ = '\0'; - } - - if ( i < NFontFields ) { - for ( int j = i ; j < NFontFields; ++j ) - tokens[j] = 0; - return FALSE; - } - - return TRUE; -} - -static inline bool isZero(char *x) -{ - return (x[0] == '0' && x[1] == 0); -} - -static inline bool isScalable( char **tokens ) -{ - return (isZero(tokens[PixelSize]) && - isZero(tokens[PointSize]) && - isZero(tokens[AverageWidth])); -} - -static inline bool isSmoothlyScalable( char **tokens ) -{ - return (isZero(tokens[ResolutionX]) && - isZero(tokens[ResolutionY])); -} - -static inline bool isFixedPitch( char **tokens ) -{ - return (tokens[Spacing][0] == 'm' || - tokens[Spacing][0] == 'c' || - tokens[Spacing][0] == 'M' || - tokens[Spacing][0] == 'C'); -} - -/* - Fills in a font definition (TQFontDef) from an XLFD (X Logical Font - Description). - - Returns TRUE if the the given xlfd is valid. The fields lbearing - and rbearing are not given any values. -*/ -bool qt_fillFontDef( const TQCString &xlfd, TQFontDef *fd, int screen ) -{ - char *tokens[NFontFields]; - TQCString buffer = xlfd.copy(); - if ( ! parseXFontName(buffer.data(), tokens) ) - return FALSE; - - capitalize(tokens[Family]); - capitalize(tokens[Foundry]); - - fd->family = TQString::fromLatin1(tokens[Family]); - TQString foundry = TQString::fromLatin1(tokens[Foundry]); - if ( ! foundry.isEmpty() && foundry != TQString::fromLatin1("*") ) - fd->family += - TQString::fromLatin1(" [") + foundry + TQString::fromLatin1("]"); - - if ( tqstrlen( tokens[AddStyle] ) > 0 ) - fd->addStyle = TQString::fromLatin1(tokens[AddStyle]); - else - fd->addStyle = TQString::null; - - fd->pointSize = atoi(tokens[PointSize]); - fd->styleHint = TQFont::AnyStyle; // ### any until we match families - - char slant = tolower( (uchar) tokens[Slant][0] ); - fd->italic = ( slant == 'o' || slant == 'i' ); - char fixed = tolower( (uchar) tokens[Spacing][0] ); - fd->fixedPitch = ( fixed == 'm' || fixed == 'c' ); - fd->weight = getFontWeight( tokens[Weight] ); - - int r = atoi(tokens[ResolutionY]); - fd->pixelSize = atoi(tokens[PixelSize]); - // not "0" or "*", or required DPI - if ( r && fd->pixelSize && TQPaintDevice::x11AppDpiY( screen ) && - r != TQPaintDevice::x11AppDpiY( screen ) ) { - // calculate actual pointsize for display DPI - fd->pointSize = tqRound(qt_pointSize(fd->pixelSize, 0, screen) * 10.); - } else if ( fd->pixelSize == 0 && fd->pointSize ) { - // calculate pixel size from pointsize/dpi - fd->pixelSize = tqRound(qt_pixelSize(fd->pointSize / 10., 0, screen)); - } - - return TRUE; -} - -/* - Fills in a font definition (TQFontDef) from the font properties in an - XFontStruct. - - Returns TRUE if the TQFontDef could be filled with properties from - the XFontStruct. The fields lbearing and rbearing are not given any - values. -*/ -static bool qt_fillFontDef( XFontStruct *fs, TQFontDef *fd, int screen ) -{ - unsigned long value; - if ( fs && !XGetFontProperty( fs, XA_FONT, &value ) ) - return FALSE; - - char *n = XGetAtomName( TQPaintDevice::x11AppDisplay(), value ); - TQCString xlfd( n ); - if ( n ) - XFree( n ); - return qt_fillFontDef( xlfd.lower(), fd, screen ); -} - - -static TQtFontStyle::Key getStyle( char ** tokens ) -{ - TQtFontStyle::Key key; - - char slant0 = tolower( (uchar) tokens[Slant][0] ); - - if ( slant0 == 'r' ) { - if ( tokens[Slant][1]) { - char slant1 = tolower( (uchar) tokens[Slant][1] ); - - if ( slant1 == 'o' ) - key.oblique = TRUE; - else if ( slant1 == 'i' ) - key.italic = TRUE; - } - } else if ( slant0 == 'o' ) - key.oblique = TRUE; - else if ( slant0 == 'i' ) - key.italic = TRUE; - - key.weight = getFontWeight( tokens[Weight] ); - - if ( qstrcmp( tokens[Width], "normal" ) == 0 ) { - key.stretch = 100; - } else if ( qstrcmp( tokens[Width], "semi condensed" ) == 0 || - qstrcmp( tokens[Width], "semicondensed" ) == 0 ) { - key.stretch = 90; - } else if ( qstrcmp( tokens[Width], "condensed" ) == 0 ) { - key.stretch = 80; - } else if ( qstrcmp( tokens[Width], "narrow" ) == 0 ) { - key.stretch = 60; - } - - return key; -} - - -extern bool tqt_has_xft; // defined in qfont_x11.cpp - -static bool xlfdsFullyLoaded = FALSE; -static unsigned char encodingLoaded[numEncodings]; - -static void loadXlfds( const char *reqFamily, int encoding_id ) -{ - TQtFontFamily *fontFamily = reqFamily ? db->family( reqFamily ) : 0; - - // make sure we don't load twice - if ( (encoding_id == -1 && xlfdsFullyLoaded) || (encoding_id != -1 && encodingLoaded[encoding_id]) ) - return; - if ( fontFamily && fontFamily->xlfdLoaded ) - return; - -#ifdef QT_XFT2 - if ( !tqt_has_xft ) { -#endif // QT_XFT2 - int fontCount; - // force the X server to give us XLFDs - TQCString xlfd_pattern = "-*-"; - xlfd_pattern += reqFamily ? reqFamily : "*"; - xlfd_pattern += "-*-*-*-*-*-*-*-*-*-*-"; - xlfd_pattern += xlfd_for_id( encoding_id ); - - char **fontList = XListFonts( TQPaintDevice::x11AppDisplay(), - xlfd_pattern.data(), - 0xffff, &fontCount ); - // tqDebug("requesting xlfd='%s', got %d fonts", xlfd_pattern.data(), fontCount ); - - - char *tokens[NFontFields]; - - for( int i = 0 ; i < fontCount ; i++ ) { - if ( ! parseXFontName( fontList[i], tokens ) ) continue; - - // get the encoding_id for this xlfd. we need to do this - // here, since we can pass -1 to this function to do full - // database population - *(tokens[CharsetEncoding]-1) = '-'; - int encoding_id = qt_xlfd_encoding_id( tokens[CharsetRegistry] ); - if ( encoding_id == -1 ) - continue; - - char *familyName = tokens[Family]; - capitalize( familyName ); - char *foundryName = tokens[Foundry]; - capitalize( foundryName ); - TQtFontStyle::Key styleKey = getStyle( tokens ); - - bool smooth_scalable = FALSE; - bool bitmap_scalable = FALSE; - if ( isScalable(tokens) ) { - if ( isSmoothlyScalable( tokens ) ) - smooth_scalable = TRUE; - else - bitmap_scalable = TRUE; - } - uint pixelSize = atoi( tokens[PixelSize] ); - uint xpointSize = atoi( tokens[PointSize] ); - uint xres = atoi( tokens[ResolutionX] ); - uint yres = atoi( tokens[ResolutionY] ); - uint avgwidth = atoi( tokens[AverageWidth] ); - bool fixedPitch = isFixedPitch( tokens ); - - if (avgwidth == 0 && pixelSize != 0) { - /* - Ignore bitmap scalable fonts that are automatically - generated by some X servers. We know they are bitmap - scalable because even though they have a specified pixel - size, the average width is zero. - */ - continue; - } - - TQtFontFamily *family = fontFamily ? fontFamily : db->family( familyName, TRUE ); - family->fontFileIndex = -1; - TQtFontFoundry *foundry = family->foundry( foundryName, TRUE ); - TQtFontStyle *style = foundry->style( styleKey, TRUE ); - - delete [] style->weightName; - style->weightName = tqstrdup( tokens[Weight] ); - delete [] style->setwidthName; - style->setwidthName = tqstrdup( tokens[Width] ); - - if ( smooth_scalable ) { - style->smoothScalable = TRUE; - style->bitmapScalable = FALSE; - pixelSize = SMOOTH_SCALABLE; - } - if ( !style->smoothScalable && bitmap_scalable ) - style->bitmapScalable = TRUE; - if ( !fixedPitch ) - family->fixedPitch = FALSE; - - TQtFontSize *size = style->pixelSize( pixelSize, TRUE ); - TQtFontEncoding *enc = - size->encodingID( encoding_id, xpointSize, xres, yres, avgwidth, TRUE ); - enc->pitch = *tokens[Spacing]; - if ( !enc->pitch ) enc->pitch = '*'; - - for ( int script = 0; script < TQFont::LastPrivateScript; ++script ) { - if ( scripts_for_xlfd_encoding[encoding_id][script] ) - family->scripts[script] = TQtFontFamily::Supported; - else - family->scripts[script] |= TQtFontFamily::UnSupported_Xlfd; - } - if ( encoding_id == -1 ) - family->xlfdLoaded = TRUE; - } - if ( !reqFamily ) { - // mark encoding as loaded - if ( encoding_id == -1 ) - xlfdsFullyLoaded = TRUE; - else - encodingLoaded[encoding_id] = TRUE; - } - - XFreeFontNames( fontList ); - -#ifdef QT_XFT2 - } -#endif // QT_XFT2 -} - -#ifndef TQT_NO_XFTFREETYPE -static int getXftWeight(int xftweight) -{ - int qtweight = TQFont::Black; - if (xftweight <= (XFT_WEIGHT_LIGHT + XFT_WEIGHT_MEDIUM) / 2) - qtweight = TQFont::Light; - else if (xftweight <= (XFT_WEIGHT_MEDIUM + XFT_WEIGHT_DEMIBOLD) / 2) - qtweight = TQFont::Normal; - else if (xftweight <= (XFT_WEIGHT_DEMIBOLD + XFT_WEIGHT_BOLD) / 2) - qtweight = TQFont::DemiBold; - else if (xftweight <= (XFT_WEIGHT_BOLD + XFT_WEIGHT_BLACK) / 2) - qtweight = TQFont::Bold; - - return qtweight; -} - -static void loadXft() -{ - if (!tqt_has_xft) - return; - -#ifdef QT_XFT2 - struct XftDefaultFont { - const char *qtname; - const char *rawname; - bool fixed; - }; - const XftDefaultFont defaults[] = { - { "Serif", "serif", FALSE }, - { "Sans Serif", "sans-serif", FALSE }, - { "Monospace", "monospace", TRUE }, - { 0, 0, FALSE } - }; - const XftDefaultFont *f = defaults; - while (f->qtname) { - TQtFontFamily *family = db->family( f->qtname, TRUE ); - family->fixedPitch = f->fixed; - family->rawName = f->rawname; - family->hasXft = TRUE; - family->synthetic = TRUE; - TQtFontFoundry *foundry - = family->foundry( TQString::null, TRUE ); - - for ( int i = 0; i < TQFont::LastPrivateScript; ++i ) { - if (i == TQFont::UnknownScript) - continue; - family->scripts[i] = TQtFontFamily::Supported; - } - - TQtFontStyle::Key styleKey; - styleKey.oblique = FALSE; - for (int i = 0; i < 4; ++i) { - styleKey.italic = (i%2); - styleKey.weight = (i > 1) ? TQFont::Bold : TQFont::Normal; - TQtFontStyle *style = foundry->style( styleKey, TRUE ); - style->smoothScalable = TRUE; - TQtFontSize *size = style->pixelSize( SMOOTH_SCALABLE, TRUE ); - TQtFontEncoding *enc = size->encodingID( -1, 0, 0, 0, 0, TRUE ); - enc->pitch = (f->fixed ? 'm' : 'p'); - } - ++f; - } -#endif -} - -#ifdef XFT_MATRIX -static void checkXftMatrix( TQtFontFamily* family ) { - for ( int j = 0; j < family->count; ++j ) { // each foundry - TQtFontFoundry *foundry = family->foundries[j]; - for ( int k = 0; k < foundry->count; ++k ) { - TQtFontStyle *style = foundry->styles[k]; - if ( style->key.italic || style->key.oblique ) continue; - - TQtFontSize *size = style->pixelSize( SMOOTH_SCALABLE ); - if ( ! size ) continue; - TQtFontEncoding *enc = size->encodingID( -1, 0, 0, 0, 0, TRUE ); - if ( ! enc ) continue; - - TQtFontStyle::Key key = style->key; - - // does this style have an italic equivalent? - key.italic = TRUE; - TQtFontStyle *equiv = foundry->style( key ); - if ( equiv ) continue; - - // does this style have an oblique equivalent? - key.italic = FALSE; - key.oblique = TRUE; - equiv = foundry->style( key ); - if ( equiv ) continue; - - // let's fake one... - equiv = foundry->style( key, TRUE ); - equiv->fakeOblique = TRUE; - equiv->smoothScalable = TRUE; - - TQtFontSize *equiv_size = equiv->pixelSize( SMOOTH_SCALABLE, TRUE ); - TQtFontEncoding *equiv_enc = equiv_size->encodingID( -1, 0, 0, 0, 0, TRUE ); - - // keep the same pitch - equiv_enc->pitch = enc->pitch; - } - } -} -#endif // XFT_MATRIX - -static bool loadXftFont( FcPattern* font ) -{ - TQString familyName; - TQString rawName; - char *value; - int weight_value; - int slant_value; - int spacing_value; - char *file_value; - int index_value; - char *foundry_value = 0; - FcBool scalable = FcTrue; - - if (XftPatternGetString( font, - XFT_FAMILY, 0, &value) != XftResultMatch ) - return false; - // capitalize( value ); - rawName = familyName = TQString::fromUtf8(value); - familyName.replace('-', ' '); - familyName.replace("/", ""); - - slant_value = XFT_SLANT_ROMAN; - weight_value = XFT_WEIGHT_MEDIUM; - spacing_value = XFT_PROPORTIONAL; - file_value = 0; - index_value = 0; - XftPatternGetInteger (font, XFT_SLANT, 0, &slant_value); - XftPatternGetInteger (font, XFT_WEIGHT, 0, &weight_value); - XftPatternGetInteger (font, XFT_SPACING, 0, &spacing_value); - XftPatternGetString (font, XFT_FILE, 0, &file_value); - XftPatternGetInteger (font, XFT_INDEX, 0, &index_value); -#ifdef QT_XFT2 - FcPatternGetBool(font, FC_SCALABLE, 0, &scalable); - foundry_value = 0; - XftPatternGetString(font, FC_FOUNDRY, 0, &foundry_value); -#endif - TQtFontFamily *family = db->family( familyName, TRUE ); - family->rawName = rawName; - family->hasXft = TRUE; - -#ifdef QT_XFT2 - FcCharSet *charset = 0; - FcResult res = FcPatternGetCharSet(font, FC_CHARSET, 0, &charset); - if (res == FcResultMatch && FcCharSetCount(charset) > 1) { - for (int i = 0; i < TQFont::LastPrivateScript; ++i) { - bool supported = sample_chars[i][0]; - for (int j = 0; sample_chars[i][j]; ++j){ - if (!FcCharSetHasChar(charset, sample_chars[i][j])) { - supported = false; - break; - } - } - if ( supported ){ - family->scripts[i] = TQtFontFamily::Supported; - } else { - family->scripts[i] |= TQtFontFamily::UnSupported_Xft; - } - } - family->xftScriptCheck = TRUE; - } else { - // we set UnknownScript to supported for symbol fonts. It makes no sense to merge these - // with other ones, as they are special in a way. - for ( int i = 0; i < TQFont::LastPrivateScript; ++i ) - family->scripts[i] |= TQtFontFamily::UnSupported_Xft; - family->scripts[TQFont::UnknownScript] = TQtFontFamily::Supported; - } -#endif // QT_XFT2 - - TQCString file = (file_value ? file_value : ""); - family->fontFilename = file; - family->fontFileIndex = index_value; - - TQtFontStyle::Key styleKey; - styleKey.italic = (slant_value == XFT_SLANT_ITALIC); - styleKey.oblique = (slant_value == XFT_SLANT_OBLIQUE); - styleKey.weight = getXftWeight( weight_value ); -#ifdef QT_XFT2 - if (!scalable) { - int width = 100; -#if FC_VERSION >= 20193 - XftPatternGetInteger (font, FC_WIDTH, 0, &width); -#endif - styleKey.stretch = width; - } -#endif - - TQtFontFoundry *foundry - = family->foundry( foundry_value ? TQString::fromUtf8(foundry_value) : TQString::null, TRUE ); - TQtFontStyle *style = foundry->style( styleKey, TRUE ); - - if (spacing_value < XFT_MONO ) - family->fixedPitch = FALSE; - - TQtFontSize *size; - if (scalable) { - style->smoothScalable = TRUE; - size = style->pixelSize( SMOOTH_SCALABLE, TRUE ); - } -#ifdef QT_XFT2 - else { - double pixel_size = 0; - XftPatternGetDouble (font, FC_PIXEL_SIZE, 0, &pixel_size); - size = style->pixelSize( (int)pixel_size, TRUE ); - } -#endif - TQtFontEncoding *enc = size->encodingID( -1, 0, 0, 0, 0, TRUE ); - enc->pitch = ( spacing_value >= XFT_CHARCELL ? 'c' : - ( spacing_value >= XFT_MONO ? 'm' : 'p' ) ); - - checkXftMatrix( family ); - - return true; -} - -#ifndef QT_XFT2 - -#define MAKE_TAG( _x1, _x2, _x3, _x4 ) \ - ( ( (TQ_UINT32)_x1 << 24 ) | \ - ( (TQ_UINT32)_x2 << 16 ) | \ - ( (TQ_UINT32)_x3 << 8 ) | \ - (TQ_UINT32)_x4 ) - -#ifdef _POSIX_MAPPED_FILES -static inline TQ_UINT32 getUInt(unsigned char *p) -{ - TQ_UINT32 val; - val = *p++ << 24; - val |= *p++ << 16; - val |= *p++ << 8; - val |= *p; - - return val; -} - -static inline TQ_UINT16 getUShort(unsigned char *p) -{ - TQ_UINT16 val; - val = *p++ << 8; - val |= *p; - - return val; -} - -static inline void tag_to_string( char *string, TQ_UINT32 tag ) -{ - string[0] = (tag >> 24)&0xff; - string[1] = (tag >> 16)&0xff; - string[2] = (tag >> 8)&0xff; - string[3] = tag&0xff; - string[4] = 0; -} - -static TQ_UINT16 getGlyphIndex( unsigned char *table, TQ_UINT16 format, unsigned short unicode ) -{ - if ( format == 0 ) { - if ( unicode < 256 ) - return (int) *(table+6+unicode); - } else if ( format == 2 ) { - tqWarning("format 2 encoding table for Unicode, not implemented!"); - } else if ( format == 4 ) { - TQ_UINT16 segCountX2 = getUShort( table + 6 ); - unsigned char *ends = table + 14; - TQ_UINT16 endIndex = 0; - int i = 0; - for ( ; i < segCountX2/2 && (endIndex = getUShort( ends + 2*i )) < unicode; i++ ); - - unsigned char *idx = ends + segCountX2 + 2 + 2*i; - TQ_UINT16 startIndex = getUShort( idx ); - - if ( startIndex > unicode ) - return 0; - - idx += segCountX2; - TQ_INT16 idDelta = (TQ_INT16)getUShort( idx ); - idx += segCountX2; - TQ_UINT16 idRangeoffset_t = (TQ_UINT16)getUShort( idx ); - - TQ_UINT16 glyphIndex; - if ( idRangeoffset_t ) { - TQ_UINT16 id = getUShort( idRangeoffset_t + 2*(unicode - startIndex) + idx); - if ( id ) - glyphIndex = ( idDelta + id ) % 0x10000; - else - glyphIndex = 0; - } else { - glyphIndex = (idDelta + unicode) % 0x10000; - } - return glyphIndex; - } - - return 0; -} -#endif // _POSIX_MAPPED_FILES - -static inline void checkXftCoverage( TQtFontFamily *family ) -{ -#ifdef _POSIX_MAPPED_FILES - TQCString ext = family->fontFilename.mid( family->fontFilename.findRev( '.' ) ).lower(); - if ( family->fontFileIndex == 0 && ( ext == ".ttf" || ext == ".otf" ) ) { - void *map; - // tqDebug("using own ttf code coverage checking of '%s'!", family->name.latin1() ); - int fd = open( family->fontFilename.data(), O_RDONLY ); - size_t pagesize = getpagesize(); - off_t offset = 0; - size_t length = (8192 / pagesize + 1) * pagesize; - - if ( fd == -1 ) - goto xftCheck; - { - if ( (map = mmap( 0, length, PROT_READ, MAP_SHARED, fd, offset ) ) == MAP_FAILED ) - goto error; - - unsigned char *ttf = (unsigned char *)map; - TQ_UINT32 version = getUInt( ttf ); - if ( version != 0x00010000 ) { - // tqDebug("file has wrong version %x", version ); - goto error1; - } - TQ_UINT16 numTables = getUShort( ttf+4 ); - - unsigned char *table_dir = ttf + 12; - TQ_UINT32 cmap_offset = 0; - TQ_UINT32 cmap_length = 0; - for ( int n = 0; n < numTables; n++ ) { - TQ_UINT32 tag = getUInt( table_dir + 16*n ); - if ( tag == MAKE_TAG( 'c', 'm', 'a', 'p' ) ) { - cmap_offset = getUInt( table_dir + 16*n + 8 ); - cmap_length = getUInt( table_dir + 16*n + 12 ); - break; - } - } - if ( !cmap_offset ) { - // tqDebug("no cmap found" ); - goto error1; - } - - if ( cmap_offset + cmap_length > length ) { - munmap( map, length ); - offset = cmap_offset / pagesize * pagesize; - cmap_offset -= offset; - length = (cmap_offset + cmap_length); - if ( (map = mmap( 0, length, PROT_READ, MAP_SHARED, fd, offset ) ) == MAP_FAILED ) - goto error; - } - - unsigned char *cmap = ((unsigned char *)map) + cmap_offset; - - version = getUShort( cmap ); - if ( version != 0 ) { - // tqDebug("wrong cmap version" ); - goto error1; - } - numTables = getUShort( cmap + 2 ); - unsigned char *unicode_table = 0; - bool symbol_table = TRUE; - for ( int n = 0; n < numTables; n++ ) { - TQ_UINT32 version = getUInt( cmap + 4 + 8*n ); - // accept both symbol and Unicode encodings. prefer unicode. - if ( version == 0x00030001 || version == 0x00030000 ) { - unicode_table = cmap + getUInt( cmap + 4 + 8*n + 4 ); - if ( version == 0x00030001 ) { - symbol_table = FALSE; - break; - } - } - } - - if ( !unicode_table ) { - // tqDebug("no unicode table found" ); - goto error1; - } - - TQ_UINT16 format = getUShort( unicode_table ); - if ( format != 4 ) - goto error1; - - if (symbol_table) { - // we set UnknownScript to supported for symbol fonts. It makes no sense to merge these - // with other ones, as they are special in a way. - for ( int i = 0; i < TQFont::LastPrivateScript; ++i ) - family->scripts[i] |= TQtFontFamily::UnSupported_Xft; - family->scripts[TQFont::UnknownScript] = TQtFontFamily::Supported; - } else { - for ( int i = 0; i < TQFont::LastPrivateScript; ++i ) { - - bool supported = sample_chars[i][0]; - for (int j = 0; sample_chars[i][j]; ++j) { - if (!getGlyphIndex(unicode_table, format, sample_chars[i][j])) { - supported=false; - break; - } - } - if ( supported ){ - // tqDebug("font can render script %d", i ); - family->scripts[i] = TQtFontFamily::Supported; - } else { - family->scripts[i] |= TQtFontFamily::UnSupported_Xft; - } - } - } - family->xftScriptCheck = TRUE; - } - error1: - munmap( map, length ); - error: - close( fd ); - if ( family->xftScriptCheck ) - return; - } - xftCheck: -#endif // _POSIX_MAPPED_FILES - - FD_DEBUG("using Freetype for checking of '%s'", family->name.latin1() ); - - FT_Library ft_lib; - FT_Error error = FT_Init_FreeType( &ft_lib ); - if ( error ) return; - FT_Face face; - error = FT_New_Face( ft_lib, family->fontFilename, family->fontFileIndex, &face ); - if ( error ) return; - - for ( int i = 0; i < TQFont::LastPrivateScript; ++i ) { - bool supported = sample_chars[i][j]; - for (int j = 0; sample_chars[i][j]; ++j){ - if (!FT_Get_Char_Index(face, sample_chars[i][j])) { - supported=false; - break; - } - } - if ( supported ){ - FD_DEBUG("font can render char %04x, %04x script %d '%s'", - ch.unicode(), FT_Get_Char_Index ( face, ch.unicode() ), - i, TQFontDatabase::scriptName( (TQFont::Script)i ).latin1() ); - - family->scripts[i] = TQtFontFamily::Supported; - } else { - family->scripts[i] |= TQtFontFamily::UnSupported_Xft; - } - } - FT_Done_Face( face ); - FT_Done_FreeType( ft_lib ); - family->xftScriptCheck = TRUE; -} -#endif // QT_XFT2 -#endif // TQT_NO_XFTFREETYPE - -static void load( const TQString &family = TQString::null, int script = -1 ) -{ -#ifdef TQFONTDATABASE_DEBUG - TQTime t; - t.start(); -#endif - - if ( family.isNull() ) { -#ifndef TQT_NO_XFTFREETYPE - static bool xft_readall_done = false; - if (tqt_has_xft && !xft_readall_done) { - xft_readall_done = true; - XftFontSet *fonts = - XftListFonts(TQPaintDevice::x11AppDisplay(), - TQPaintDevice::x11AppScreen(), - (const char *)0, - XFT_FAMILY, XFT_WEIGHT, XFT_SLANT, - XFT_SPACING, XFT_FILE, XFT_INDEX, -#ifdef QT_XFT2 - FC_CHARSET, FC_FOUNDRY, FC_SCALABLE, FC_PIXEL_SIZE, -#if FC_VERSION >= 20193 - FC_WIDTH, -#endif -#endif // QT_XFT2 - (const char *)0); - for (int i = 0; i < fonts->nfont; i++) - loadXftFont( fonts->fonts[i] ); - XftFontSetDestroy (fonts); - } -#ifdef QT_XFT2 - if (tqt_has_xft) - return; -#endif -#endif // TQT_NO_XFTFREETYPE - if ( script == -1 ) - loadXlfds( 0, -1 ); - else { - for ( int i = 0; i < numEncodings; i++ ) { - if ( scripts_for_xlfd_encoding[i][script] ) - loadXlfds( 0, i ); - } - } - } else { - TQtFontFamily *f = db->family( family, TRUE ); - if ( !f->fullyLoaded ) { - -#ifndef TQT_NO_XFTFREETYPE - if (tqt_has_xft) { - TQString mfamily = family; - redo: - XftFontSet *fonts = - XftListFonts(TQPaintDevice::x11AppDisplay(), - TQPaintDevice::x11AppScreen(), - XFT_FAMILY, XftTypeString, mfamily.utf8().data(), - (const char *)0, - XFT_FAMILY, XFT_WEIGHT, XFT_SLANT, - XFT_SPACING, XFT_FILE, XFT_INDEX, -#ifdef QT_XFT2 - FC_CHARSET, FC_FOUNDRY, FC_SCALABLE, FC_PIXEL_SIZE, -#if FC_VERSION >= 20193 - FC_WIDTH, -#endif -#endif // QT_XFT2 - (const char *)0); - for (int i = 0; i < fonts->nfont; i++) - loadXftFont( fonts->fonts[i] ); - XftFontSetDestroy (fonts); - if (mfamily.contains(' ')) { - mfamily.replace(TQChar(' '), TQChar('-')); - goto redo; - } - f->fullyLoaded = TRUE; -#ifdef QT_XFT2 - return; -#endif - } -#ifndef QT_XFT2 - // need to check Xft coverage - if ( f->hasXft && !f->xftScriptCheck ) { - checkXftCoverage( f ); - } -#endif -#endif // TQT_NO_XFTFREETYPE - // could reduce this further with some more magic: - // would need to remember the encodings loaded for the family. - if ( ( script == -1 && !f->xlfdLoaded ) || - ( !f->hasXft && !(f->scripts[script] & TQtFontFamily::Supported) && - !(f->scripts[script] & TQtFontFamily::UnSupported_Xlfd) ) ) { - loadXlfds( family, -1 ); - f->fullyLoaded = TRUE; - } - } - } - -#ifdef TQFONTDATABASE_DEBUG - FD_DEBUG("TQFontDatabase: load( %s, %d) took %d ms", family.latin1(), script, t.elapsed() ); -#endif -} - - -static void initializeDb() -{ - if ( db ) return; - db = new TQFontDatabasePrivate; - qfontdatabase_cleanup.set(&db); - -#ifndef QT_XFT2 - memset( encodingLoaded, FALSE, sizeof( encodingLoaded ) ); -#endif - - TQTime t; - t.start(); - -#ifndef TQT_NO_XFTFREETYPE - loadXft(); - FD_DEBUG("TQFontDatabase: loaded Xft: %d ms", t.elapsed() ); -#endif - - t.start(); - -#ifndef TQT_NO_XFTFREETYPE - for ( int i = 0; i < db->count; i++ ) { -#ifndef QT_XFT2 - checkXftCoverage( db->families[i] ); - FD_DEBUG("TQFontDatabase: xft coverage check: %d ms", t.elapsed() ); -#endif // QT_XFT2 - -#ifdef XFT_MATRIX - checkXftMatrix( db->families[i] ); -#endif // XFT_MATRIX - } -#endif - - -#ifdef TQFONTDATABASE_DEBUG -#ifdef QT_XFT2 - if (!tqt_has_xft) -#endif - // load everything at startup in debug mode. - loadXlfds( 0, -1 ); - - // print the database - for ( int f = 0; f < db->count; f++ ) { - TQtFontFamily *family = db->families[f]; - FD_DEBUG("'%s' %s hasXft=%s", family->name.latin1(), (family->fixedPitch ? "fixed" : ""), - (family->hasXft ? "yes" : "no") ); - for ( int i = 0; i < TQFont::LastPrivateScript; ++i ) { - FD_DEBUG("\t%s: %s", TQFontDatabase::scriptName((TQFont::Script) i).latin1(), - ((family->scripts[i] & TQtFontFamily::Supported) ? "Supported" : - (family->scripts[i] & TQtFontFamily::UnSupported) == TQtFontFamily::UnSupported ? - "UnSupported" : "Unknown")); - } - - for ( int fd = 0; fd < family->count; fd++ ) { - TQtFontFoundry *foundry = family->foundries[fd]; - FD_DEBUG("\t\t'%s'", foundry->name.latin1() ); - for ( int s = 0; s < foundry->count; s++ ) { - TQtFontStyle *style = foundry->styles[s]; - FD_DEBUG("\t\t\tstyle: italic=%d oblique=%d (fake=%d) weight=%d (%s)\n" - "\t\t\tstretch=%d (%s)", - style->key.italic, style->key.oblique, style->fakeOblique, style->key.weight, - style->weightName, style->key.stretch, - style->setwidthName ? style->setwidthName : "nil" ); - if ( style->smoothScalable ) - FD_DEBUG("\t\t\t\tsmooth scalable" ); - else if ( style->bitmapScalable ) - FD_DEBUG("\t\t\t\tbitmap scalable" ); - if ( style->pixelSizes ) { - tqDebug("\t\t\t\t%d pixel sizes", style->count ); - for ( int z = 0; z < style->count; ++z ) { - TQtFontSize *size = style->pixelSizes + z; - for ( int e = 0; e < size->count; ++e ) { - FD_DEBUG( "\t\t\t\t size %5d pitch %c encoding %s", - size->pixelSize, - size->encodings[e].pitch, - xlfd_for_id( size->encodings[e].encoding ) ); - } - } - } - } - } - } -#endif // TQFONTDATABASE_DEBUG -} - -void TQFontDatabase::createDatabase() -{ - initializeDb(); -} - - -// -------------------------------------------------------------------------------------- -// font loader -// -------------------------------------------------------------------------------------- -#define MAXFONTSIZE_XFT 256 -#define MAXFONTSIZE_XLFD 128 -#ifndef TQT_NO_XFTFREETYPE -static double addPatternProps(XftPattern *pattern, const TQtFontStyle::Key &key, bool fakeOblique, - bool smoothScalable, const TQFontPrivate *fp, const TQFontDef &request) -{ - int weight_value = XFT_WEIGHT_BLACK; - if ( key.weight == 0 ) - weight_value = XFT_WEIGHT_MEDIUM; - else if ( key.weight < (TQFont::Light + TQFont::Normal) / 2 ) - weight_value = XFT_WEIGHT_LIGHT; - else if ( key.weight < (TQFont::Normal + TQFont::DemiBold) / 2 ) - weight_value = XFT_WEIGHT_MEDIUM; - else if ( key.weight < (TQFont::DemiBold + TQFont::Bold) / 2 ) - weight_value = XFT_WEIGHT_DEMIBOLD; - else if ( key.weight < (TQFont::Bold + TQFont::Black) / 2 ) - weight_value = XFT_WEIGHT_BOLD; - XftPatternAddInteger( pattern, XFT_WEIGHT, weight_value ); - - int slant_value = XFT_SLANT_ROMAN; - if ( key.italic ) - slant_value = XFT_SLANT_ITALIC; - else if ( key.oblique && !fakeOblique ) - slant_value = XFT_SLANT_OBLIQUE; - XftPatternAddInteger( pattern, XFT_SLANT, slant_value ); - - /* - Xft1 doesn't obey user settings for turning off anti-aliasing using - the following: - - match any size > 6 size < 12 edit antialias = false; - - ... if we request pixel sizes. so, work around this limitiation and - convert the pixel size to a point size and request that. - */ - double size_value = request.pixelSize; - double dpi = TQPaintDevice::x11AppDpiY(fp->screen); - double scale = 1.; - if ( size_value > MAXFONTSIZE_XFT ) { - scale = (double)size_value/(double)MAXFONTSIZE_XFT; - size_value = MAXFONTSIZE_XFT; - } - -#ifdef QT_XFT2 - /* - 2006-12-28 If QT is not compiled against xft1, there is no need - for the workaround above (confirmed). Thus, in addition, add - font pixelsize to the pattern to avoid fontconfig making wrong - guesses. Also provide a DPI value for fontconfig so it never - attempts to fallback to its default. - */ - XftPatternAddDouble(pattern, XFT_PIXEL_SIZE, size_value); - XftPatternAddDouble(pattern, XFT_DPI, dpi); -#endif - size_value = size_value*72./dpi; - XftPatternAddDouble( pattern, XFT_SIZE, size_value ); - -#ifdef XFT_MATRIX -# ifdef QT_XFT2 - if (!smoothScalable) { -# if FC_VERSION >= 20193 - int stretch = request.stretch; - if (!stretch) - stretch = 100; - XftPatternAddInteger(pattern, FC_WIDTH, stretch); -# endif - } else -# endif - if ( ( request.stretch > 0 && request.stretch != 100 ) || - ( key.oblique && fakeOblique ) ) { - XftMatrix matrix; - XftMatrixInit( &matrix ); - - if ( request.stretch > 0 && request.stretch != 100 ) - XftMatrixScale( &matrix, double( request.stretch ) / 100.0, 1.0 ); - if ( key.oblique && fakeOblique ) - XftMatrixShear( &matrix, 0.20, 0.0 ); - - XftPatternAddMatrix( pattern, XFT_MATRIX, &matrix ); - } -#endif // XFT_MATRIX - if (request.styleStrategy & (TQFont::PreferAntialias|TQFont::NoAntialias)) { - XftPatternDel(pattern, XFT_ANTIALIAS); - XftPatternAddBool(pattern, XFT_ANTIALIAS, - !(request.styleStrategy & TQFont::NoAntialias)); - } - - return scale; -} -#endif // TQT_NO_XFTFREETYPE - -static -TQFontEngine *loadEngine( TQFont::Script script, - const TQFontPrivate *fp, const TQFontDef &request, - TQtFontFamily *family, TQtFontFoundry *foundry, - TQtFontStyle *style, TQtFontSize *size, - TQtFontEncoding *encoding, bool forced_encoding ) -{ - Q_UNUSED(script); - - if ( fp && fp->rawMode ) { - TQCString xlfd = request.family.latin1(); - FM_DEBUG( "Loading XLFD (rawmode) '%s'", xlfd.data() ); - - XFontStruct *xfs; - if (! (xfs = XLoadQueryFont(TQPaintDevice::x11AppDisplay(), xlfd.data() ) ) ) - return 0; - - TQFontEngine *fe = new TQFontEngineXLFD( xfs, xlfd.data(), 0 ); - if ( ! qt_fillFontDef( xfs, &fe->fontDef, TQPaintDevice::x11AppScreen() ) && - ! qt_fillFontDef( xlfd, &fe->fontDef, TQPaintDevice::x11AppScreen() ) ) - fe->fontDef = TQFontDef(); - - return fe; - } - -#ifndef TQT_NO_XFTFREETYPE - if ( encoding->encoding == -1 ) { - - FM_DEBUG( " using Xft" ); - - XftPattern *pattern = XftPatternCreate(); - if ( !pattern ) return 0; - - bool symbol = (family->scripts[TQFont::UnknownScript] == TQtFontFamily::Supported); -# ifdef QT_XFT2 - if (!symbol && script != TQFont::Unicode) { - FcCharSet *cs = FcCharSetCreate(); - for ( int j=0; sample_chars[script][j]; j++ ) - FcCharSetAddChar(cs, sample_chars[script][j]); - if (script == TQFont::Latin) - // add Euro character - FcCharSetAddChar(cs, 0x20ac); - FcPatternAddCharSet(pattern, FC_CHARSET, cs); - FcCharSetDestroy(cs); - } -# else - XftPatternAddString( pattern, XFT_ENCODING, symbol ? "adobe-fontspecific" : "iso10646-1"); -# endif // QT_XFT2 - - if ( !foundry->name.isEmpty() ) - XftPatternAddString( pattern, XFT_FOUNDRY, - foundry->name.utf8().data() ); - - if ( !family->rawName.isEmpty() ) - XftPatternAddString( pattern, XFT_FAMILY, - family->rawName.utf8().data() ); - - - char pitch_value = ( encoding->pitch == 'c' ? XFT_CHARCELL : - ( encoding->pitch == 'm' ? XFT_MONO : XFT_PROPORTIONAL ) ); - XftPatternAddInteger( pattern, XFT_SPACING, pitch_value ); - - double scale = addPatternProps(pattern, style->key, style->fakeOblique, - style->smoothScalable, fp, request); - - XftResult res; - XftPattern *result = - XftFontMatch( TQPaintDevice::x11AppDisplay(), fp->screen, pattern, &res ); -#ifdef QT_XFT2 - if (result && script == TQFont::Latin) { - // since we added the Euro char on top, check we actually got the family - // we requested. If we didn't get it correctly, remove the Euro from the pattern - // and try again. - FcChar8 *f; - res = FcPatternGetString(result, FC_FAMILY, 0, &f); - if (res == FcResultMatch && TQString::fromUtf8((char *)f) != family->rawName) { - FcPatternDel(pattern, FC_CHARSET); - FcCharSet *cs = FcCharSetCreate(); - for ( int j=0; sample_chars[script][j]; j++ ) - FcCharSetAddChar(cs, sample_chars[script][j]); - FcPatternAddCharSet(pattern, FC_CHARSET, cs); - FcCharSetDestroy(cs); - result = XftFontMatch( TQPaintDevice::x11AppDisplay(), fp->screen, pattern, &res ); - } - } -#endif - XftPatternDestroy(pattern); - if (!result) - return 0; - - // somehow this gets lost in the XftMatch call, reset the anitaliasing property correctly. - if (request.styleStrategy & (TQFont::PreferAntialias|TQFont::NoAntialias)) { - XftPatternDel(result, XFT_ANTIALIAS); - XftPatternAddBool(result, XFT_ANTIALIAS, - !(request.styleStrategy & TQFont::NoAntialias)); - } - // We pass a duplicate to XftFontOpenPattern because either xft font - // will own the pattern after the call or the pattern will be - // destroyed. - XftPattern *dup = XftPatternDuplicate( result ); - XftFont *xftfs = XftFontOpenPattern( TQPaintDevice::x11AppDisplay(), dup ); - - if ( ! xftfs ) // Xft couldn't find a font? - return 0; - - TQFontEngine *fe = new TQFontEngineXft( xftfs, result, symbol ? 1 : 0 ); - if (fp->paintdevice - && TQPaintDeviceMetrics(fp->paintdevice).logicalDpiY() != TQPaintDevice::x11AppDpiY()) { - double px; - XftPatternGetDouble(result, XFT_PIXEL_SIZE, 0, &px); - scale = (double)request.pixelSize/px; - } - fe->setScale( scale ); - return fe; - } -#endif // TQT_NO_XFTFREETYPE - - FM_DEBUG( " using XLFD" ); - - TQCString xlfd = "-"; - xlfd += foundry->name.isEmpty() ? "*" : foundry->name.latin1(); - xlfd += "-"; - xlfd += family->name.isEmpty() ? "*" : family->name.latin1(); - - xlfd += "-"; - xlfd += style->weightName ? style->weightName : "*"; - xlfd += "-"; - xlfd += ( style->key.italic ? "i" : ( style->key.oblique ? "o" : "r" ) ); - - xlfd += "-"; - xlfd += style->setwidthName ? style->setwidthName : "*"; - // ### handle add-style - xlfd += "-*-"; - - int px = size->pixelSize; - if ( style->smoothScalable && px == SMOOTH_SCALABLE ) - px = request.pixelSize; - else if ( style->bitmapScalable && px == 0 ) - px = request.pixelSize; - double scale = 1.; - if ( px > MAXFONTSIZE_XLFD ) { - scale = (double)px/(double)MAXFONTSIZE_XLFD; - px = MAXFONTSIZE_XLFD; - } - if (fp && fp->paintdevice - && TQPaintDeviceMetrics(fp->paintdevice).logicalDpiY() != TQPaintDevice::x11AppDpiY()) - scale = (double)request.pixelSize/(double)px; - - xlfd += TQString::number( px ).latin1(); - xlfd += "-"; - xlfd += TQString::number( encoding->xpoint ); - xlfd += "-"; - xlfd += TQString::number( encoding->xres ); - xlfd += "-"; - xlfd += TQString::number( encoding->yres ); - xlfd += "-"; - - // ### handle cell spaced fonts - xlfd += encoding->pitch; - xlfd += "-"; - xlfd += TQString::number( encoding->avgwidth ); - xlfd += "-"; - xlfd += xlfd_for_id( encoding->encoding ); - - FM_DEBUG( " xlfd: '%s'", xlfd.data() ); - - XFontStruct *xfs; - if (! (xfs = XLoadQueryFont(TQPaintDevice::x11AppDisplay(), xlfd.data() ) ) ) - return 0; - - TQFontEngine *fe = 0; - const int mib = xlfd_encoding[ encoding->encoding ].mib; - if (script == TQFont::Latin && encoding->encoding <= LAST_LATIN_ENCODING && !forced_encoding) { - fe = new TQFontEngineLatinXLFD( xfs, xlfd.data(), mib ); - } else { - fe = new TQFontEngineXLFD( xfs, xlfd.data(), mib ); - } - - fe->setScale( scale ); - - return fe; -} - - -#ifdef QT_XFT2 - -static void parseFontName(const TQString &name, TQString &foundry, TQString &family) -{ - if ( name.contains('[') && name.contains(']')) { - int i = name.find('['); - int li = name.findRev(']'); - - if (i < li) { - foundry = name.mid(i + 1, li - i - 1); - if (name[i - 1] == ' ') - i--; - family = name.left(i); - } - } else { - foundry = TQString::null; - family = name; - } -} - - -static TQFontEngine *loadFontConfigFont(const TQFontPrivate *fp, const TQFontDef &request, TQFont::Script script) -{ - if (!tqt_has_xft) - return 0; - - TQStringList family_list; - if (request.family.isEmpty()) { - family_list = TQStringList::split(TQChar(','), fp->request.family); - - TQString stylehint; - switch ( request.styleHint ) { - case TQFont::SansSerif: - stylehint = "sans-serif"; - break; - case TQFont::Serif: - stylehint = "serif"; - break; - case TQFont::TypeWriter: - stylehint = "monospace"; - break; - default: - if (request.fixedPitch) - stylehint = "monospace"; - break; - } - if (!stylehint.isEmpty()) - family_list << stylehint; - } else { - family_list << request.family; - } - - FcPattern *pattern = FcPatternCreate(); - - { - TQString family, foundry; - for (TQStringList::ConstIterator it = family_list.begin(); it != family_list.end(); ++it) { - parseFontName(*it, foundry, family); - XftPatternAddString(pattern, XFT_FAMILY, family.utf8().data()); - } - } - - TQtFontStyle::Key key; - key.italic = request.italic; - key.weight = request.weight; - key.stretch = request.stretch; - - double scale = addPatternProps(pattern, key, FALSE, TRUE, fp, request); -#ifdef FONT_MATCH_DEBUG - tqDebug("original pattern contains:"); - FcPatternPrint(pattern); -#endif - - // XftFontMatch calls the right ConfigSubstitute variants, but as we use - // FcFontMatch/Sort here we have to do it manually. - FcConfigSubstitute(0, pattern, FcMatchPattern); - XftDefaultSubstitute(TQPaintDevice::x11AppDisplay(), TQPaintDevice::x11AppScreen(), pattern); - -// tqDebug("1: pattern contains:"); -// FcPatternPrint(pattern); - - { - FcValue value; - value.type = FcTypeString; - - // these should only get added to the pattern _after_ substitution - // append the default fallback font for the specified script - extern TQString qt_fallback_font_family( TQFont::Script ); - TQString fallback = qt_fallback_font_family( script ); - if ( ! fallback.isEmpty() && ! family_list.contains( fallback ) ) { - TQCString cs = fallback.utf8(); - value.u.s = (const FcChar8 *)cs.data(); - FcPatternAddWeak(pattern, FC_FAMILY, value, FcTrue); - } - - // add the default family - TQString defaultFamily = TQApplication::font().family(); - if ( ! family_list.contains( defaultFamily ) ) { - TQCString cs = defaultFamily.utf8(); - value.u.s = (const FcChar8 *)cs.data(); - FcPatternAddWeak(pattern, FC_FAMILY, value, FcTrue); - } - - // add TQFont::defaultFamily() to the list, for compatibility with - // previous versions - defaultFamily = TQApplication::font().defaultFamily(); - if ( ! family_list.contains( defaultFamily ) ) { - TQCString cs = defaultFamily.utf8(); - value.u.s = (const FcChar8 *)cs.data(); - FcPatternAddWeak(pattern, FC_FAMILY, value, FcTrue); - } - } - - if (script != TQFont::Unicode) { - FcCharSet *cs = FcCharSetCreate(); - for ( int j=0; sample_chars[script][j]; j++ ) - FcCharSetAddChar(cs, sample_chars[script][j]); - if (script == TQFont::Latin) - // add Euro character - FcCharSetAddChar(cs, 0x20ac); - FcPatternAddCharSet(pattern, FC_CHARSET, cs); - FcCharSetDestroy(cs); - } - -#ifdef FONT_MATCH_DEBUG - printf("final pattern contains:\n"); - FcPatternPrint(pattern); -#endif - - TQFontEngine *fe = 0; - - for( int jj = (FcGetVersion() >= 20392 ? 0 : 1); jj < 2; ++jj ) { - bool use_fontsort = ( jj == 1 ); - - FcResult result; - FcFontSet *fs = 0; - FcPattern *fsp = 0; - - // Properly conform to fontconfig API. We need to call FcDefaultSubstitute() - // before FcFontSort()/FcFontMatch(). - FcDefaultSubstitute(pattern); - - if( use_fontsort ) { - fs = FcFontSort(0, pattern, FcFalse, 0, &result); - if (!fs) - continue; - } else { - fsp = FcFontMatch(0, pattern, &result); - if (!fsp) - continue; - } - -#ifdef FONT_MATCH_DEBUG - if( use_fontsort ) { - printf("fontset contains:\n"); - for (int i = 0; i < fs->nfont; ++i) { - FcPattern *test = fs->fonts[i]; - FcChar8 *fam; - FcPatternGetString(test, FC_FAMILY, 0, &fam); - printf(" %s\n", fam); - } - } else { - printf("fontmatch:"); - FcChar8 *fam; - FcPatternGetString(fsp, FC_FAMILY, 0, &fam); - printf(" %s\n", fam); - } -#endif - - double size_value = request.pixelSize; - if ( size_value > MAXFONTSIZE_XFT ) - size_value = MAXFONTSIZE_XFT; - - int cnt = use_fontsort ? fs->nfont : 1; - - for (int i = 0; i < cnt; ++i) { - FcPattern *font = use_fontsort ? fs->fonts[i] : fsp; - FcCharSet *cs; - FcResult res = FcPatternGetCharSet(font, FC_CHARSET, 0, &cs); - if (res != FcResultMatch) - continue; - bool do_break=true; - for ( int j=0; sample_chars[script][j]; j++ ){ - do_break=false; - if (!FcCharSetHasChar(cs, sample_chars[script][j])) { - do_break=true; - break; - } - } - if ( do_break ) - continue; - FcBool scalable; - res = FcPatternGetBool(font, FC_SCALABLE, 0, &scalable); - if (res != FcResultMatch || !scalable) { - int pixelSize; - res = FcPatternGetInteger(font, FC_PIXEL_SIZE, 0, &pixelSize); - if (res != FcResultMatch || TQABS((size_value-pixelSize)/size_value) > 0.2) - continue; - } - - XftPattern *pattern = XftPatternDuplicate(font); - // add properties back in as the font selected from the list doesn't contain them. - addPatternProps(pattern, key, FALSE, TRUE, fp, request); - - XftPattern *result = - XftFontMatch( TQPaintDevice::x11AppDisplay(), fp->screen, pattern, &res ); - XftPatternDestroy(pattern); - - // We pass a duplicate to XftFontOpenPattern because either xft font - // will own the pattern after the call or the pattern will be - // destroyed. - XftPattern *dup = XftPatternDuplicate( result ); - XftFont *xftfs = XftFontOpenPattern( TQPaintDevice::x11AppDisplay(), dup ); - - if ( !xftfs ) { - // Xft couldn't find a font? - tqDebug("couldn't open fontconfigs chosen font with Xft!!!"); - } else { - fe = new TQFontEngineXft( xftfs, result, 0 ); - if (fp->paintdevice - && TQPaintDeviceMetrics(fp->paintdevice).logicalDpiY() != TQPaintDevice::x11AppDpiY()) { - double px; - XftPatternGetDouble(result, XFT_PIXEL_SIZE, 0, &px); - scale = request.pixelSize/px; - } - fe->setScale( scale ); - fe->fontDef = request; - if ( script != TQFont::Unicode && !canRender(fe, script) ) { - FM_DEBUG( " WARN: font loaded cannot render samples" ); - delete fe; - fe = 0; - }else - FM_DEBUG( " USE: %s", fe->fontDef.family.latin1() ); - } - if (fe) { - TQFontEngineXft *xft = (TQFontEngineXft *)fe; - char *family; - if (XftPatternGetString(xft->pattern(), XFT_FAMILY, 0, &family) == XftResultMatch) - xft->fontDef.family = TQString::fromUtf8(family); - - double px; - if (XftPatternGetDouble(xft->pattern(), XFT_PIXEL_SIZE, 0, &px) == XftResultMatch) - xft->fontDef.pixelSize = tqRound(px); - - int weight = XFT_WEIGHT_MEDIUM; - XftPatternGetInteger(xft->pattern(), XFT_WEIGHT, 0, &weight); - xft->fontDef.weight = getXftWeight(weight); - - int slant = XFT_SLANT_ROMAN; - XftPatternGetInteger(xft->pattern(), XFT_SLANT, 0, &slant); - xft->fontDef.italic = (slant != XFT_SLANT_ROMAN); - - int spacing = XFT_PROPORTIONAL; - XftPatternGetInteger(xft->pattern(), XFT_SPACING, 0, &spacing); - xft->fontDef.fixedPitch = spacing != XFT_PROPORTIONAL; - - xft->fontDef.ignorePitch = FALSE; - break; - } - } - - if( use_fontsort ) - FcFontSetDestroy(fs); - else - FcPatternDestroy(fsp); - - if( fe ) - break; - - } // for( jj ) - - FcPatternDestroy(pattern); - - return fe; -} - -#endif diff --git a/src/kernel/qfontengine_p.h b/src/kernel/qfontengine_p.h deleted file mode 100644 index 3dba677ca..000000000 --- a/src/kernel/qfontengine_p.h +++ /dev/null @@ -1,564 +0,0 @@ -/**************************************************************************** -** -** ??? -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** Licensees holding valid TQt Commercial licenses may use this file in -** accordance with the TQt Commercial License Agreement provided with -** the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#ifndef TQFONTENGINE_P_H -#define TQFONTENGINE_P_H - -#ifndef QT_H -#include "ntqglobal.h" -#endif // QT_H - -#ifdef TQ_WS_WIN -#include "qt_windows.h" -#include "tqptrdict.h" -#endif - -#include "tqtextengine_p.h" - -class TQPaintDevice; - -struct glyph_metrics_t; -class TQChar; -typedef unsigned short glyph_t; -struct qoffset_t; -typedef int advance_t; -class TQOpenType; -struct TransformedFont; - -#if defined( TQ_WS_X11 ) || defined( TQ_WS_WIN) || defined( TQ_WS_MAC ) -class TQFontEngine : public TQShared -{ -public: - enum Error { - NoError, - OutOfMemory - }; - - enum Type { - // X11 types - Box, - XLFD, - LatinXLFD, - Xft, - - // MS Windows types - Win, - Uniscribe, - - // Apple MacOS types - Mac, - }; - - TQFontEngine() { - count = 0; cache_count = 0; -#ifdef TQ_WS_X11 - transformed_fonts = 0; -#endif - } - virtual ~TQFontEngine(); - - /* returns 0 as glyph index for non existant glyphs */ - virtual Error stringToCMap( const TQChar *str, int len, glyph_t *glyphs, - advance_t *advances, int *nglyphs, bool mirrored ) const = 0; - -#ifdef TQ_WS_X11 - virtual int cmap() const { return -1; } - virtual TQOpenType *openType() const { return 0; } -#endif - - virtual void draw( TQPainter *p, int x, int y, const TQTextEngine *engine, const TQScriptItem *si, int textFlags ) = 0; - - virtual glyph_metrics_t boundingBox( const glyph_t *glyphs, - const advance_t *advances, - const qoffset_t *offsets, int numGlyphs ) = 0; - virtual glyph_metrics_t boundingBox( glyph_t glyph ) = 0; - - virtual int ascent() const = 0; - virtual int descent() const = 0; - virtual int leading() const = 0; - - virtual int lineThickness() const; - virtual int underlinePosition() const; - - virtual int maxCharWidth() const = 0; - virtual int minLeftBearing() const { return 0; } - virtual int minRightBearing() const { return 0; } - - virtual const char *name() const = 0; - - virtual bool canRender( const TQChar *string, int len ) = 0; - - virtual void setScale( double ) {} - virtual double scale() const { return 1.; } - - virtual Type type() const = 0; - - TQFontDef fontDef; - uint cache_cost; // amount of mem used in kb by the font - int cache_count; - -#ifdef TQ_WS_WIN - HDC dc() const; - void getGlyphIndexes( const TQChar *ch, int numChars, glyph_t *glyphs, bool mirrored ) const; - void getCMap(); - - TQCString _name; - HDC hdc; - HFONT hfont; - LOGFONT logfont; - uint stockFont : 1; - uint paintDevice : 1; - uint useTextOutA : 1; - uint ttf : 1; - uint symbol : 1; - union { - TEXTMETRICW w; - TEXTMETRICA a; - } tm; - int lw; - unsigned char *cmap; - void *script_cache; - static TQPtrDict cacheDict; - short lbearing; - short rbearing; -#endif // TQ_WS_WIN -#ifdef TQ_WS_X11 - TransformedFont *transformed_fonts; -#endif -}; -#endif // WIN || X11 || MAC - - - -enum IndicFeatures { - CcmpFeature, - InitFeature, - NuktaFeature, - AkhantFeature, - RephFeature, - BelowFormFeature, - HalfFormFeature, - PostFormFeature, - VattuFeature, - PreSubstFeature, - AboveSubstFeature, - BelowSubstFeature, - PostSubstFeature, - HalantFeature -}; - -#if defined(TQ_WS_X11) || defined(TQ_WS_WIN) -class TQFontEngineBox : public TQFontEngine -{ -public: - TQFontEngineBox( int size ); - ~TQFontEngineBox(); - - Error stringToCMap( const TQChar *str, int len, glyph_t *glyphs, advance_t *advances, int *nglyphs, bool mirrored ) const; - - void draw( TQPainter *p, int x, int y, const TQTextEngine *engine, const TQScriptItem *si, int textFlags ); - - virtual glyph_metrics_t boundingBox( const glyph_t *glyphs, - const advance_t *advances, const qoffset_t *offsets, int numGlyphs ); - glyph_metrics_t boundingBox( glyph_t glyph ); - - int ascent() const; - int descent() const; - int leading() const; - int maxCharWidth() const; - int minLeftBearing() const { return 0; } - int minRightBearing() const { return 0; } - -#ifdef TQ_WS_X11 - int cmap() const; -#endif - const char *name() const; - - bool canRender( const TQChar *string, int len ); - - Type type() const; - inline int size() const { return _size; } - -private: - friend class TQFontPrivate; - int _size; -}; -#endif - -#ifdef TQ_WS_X11 -#include "qt_x11_p.h" - - -struct TransformedFont -{ - float xx; - float xy; - float yx; - float yy; - union { - Font xlfd_font; -#ifndef TQT_NO_XFTFREETYPE - XftFont *xft_font; -#endif - }; - TransformedFont *next; -}; - -#ifndef TQT_NO_XFTFREETYPE -#include -#include FT_FREETYPE_H -#include "ftxopen.h" - -class TQTextCodec; - -class TQFontEngineXft : public TQFontEngine -{ -public: - TQFontEngineXft( XftFont *font, XftPattern *pattern, int cmap ); - ~TQFontEngineXft(); - - TQOpenType *openType() const; - - Error stringToCMap( const TQChar *str, int len, glyph_t *glyphs, advance_t *advances, int *nglyphs, bool mirrored ) const; - - void draw( TQPainter *p, int x, int y, const TQTextEngine *engine, const TQScriptItem *si, int textFlags ); - - virtual glyph_metrics_t boundingBox( const glyph_t *glyphs, - const advance_t *advances, const qoffset_t *offsets, int numGlyphs ); - glyph_metrics_t boundingBox( glyph_t glyph ); - - int ascent() const; - int descent() const; - int leading() const; - int lineThickness() const; - int underlinePosition() const; - int maxCharWidth() const; - int minLeftBearing() const; - int minRightBearing() const; - - int cmap() const; - const char *name() const; - - void setScale( double scale ); - double scale() const { return _scale; } - - bool canRender( const TQChar *string, int len ); - - Type type() const; - XftPattern *pattern() const { return _pattern; } - FT_Face face() const { return _face; } - XftFont *font() const { return _font; } - - void recalcAdvances( int len, glyph_t *glyphs, advance_t *advances ); - -private: - friend class TQFontPrivate; - friend class TQOpenType; - XftFont *_font; - XftPattern *_pattern; - FT_Face _face; - TQOpenType *_openType; - int _cmap; - short lbearing; - short rbearing; - float _scale; - enum { widthCacheSize = 0x800, cmapCacheSize = 0x500 }; - unsigned char widthCache[widthCacheSize]; - glyph_t cmapCache[cmapCacheSize]; -}; -#endif - -class TQFontEngineLatinXLFD; - -class TQFontEngineXLFD : public TQFontEngine -{ -public: - TQFontEngineXLFD( XFontStruct *fs, const char *name, int cmap ); - ~TQFontEngineXLFD(); - - Error stringToCMap( const TQChar *str, int len, glyph_t *glyphs, advance_t *advances, int *nglyphs, bool mirrored ) const; - - void draw( TQPainter *p, int x, int y, const TQTextEngine *engine, const TQScriptItem *si, int textFlags ); - - virtual glyph_metrics_t boundingBox( const glyph_t *glyphs, - const advance_t *advances, const qoffset_t *offsets, int numGlyphs ); - glyph_metrics_t boundingBox( glyph_t glyph ); - - int ascent() const; - int descent() const; - int leading() const; - int maxCharWidth() const; - int minLeftBearing() const; - int minRightBearing() const; - - int cmap() const; - const char *name() const; - - bool canRender( const TQChar *string, int len ); - - void setScale( double scale ); - double scale() const { return _scale; } - Type type() const; - - TQt::HANDLE handle() const { return (TQt::HANDLE) _fs->fid; } - -private: - friend class TQFontPrivate; - XFontStruct *_fs; - TQCString _name; - TQTextCodec *_codec; - float _scale; // needed for printing, to correctly scale font metrics for bitmap fonts - int _cmap; - short lbearing; - short rbearing; - enum XlfdTransformations { - XlfdTrUnknown, - XlfdTrSupported, - XlfdTrUnsupported - }; - XlfdTransformations xlfd_transformations; - - friend class TQFontEngineLatinXLFD; -}; - -class TQFontEngineLatinXLFD : public TQFontEngine -{ -public: - TQFontEngineLatinXLFD( XFontStruct *xfs, const char *name, int cmap ); - ~TQFontEngineLatinXLFD(); - - Error stringToCMap( const TQChar *str, int len, glyph_t *glyphs, - advance_t *advances, int *nglyphs, bool mirrored ) const; - - void draw( TQPainter *p, int x, int y, const TQTextEngine *engine, - const TQScriptItem *si, int textFlags ); - - virtual glyph_metrics_t boundingBox( const glyph_t *glyphs, - const advance_t *advances, - const qoffset_t *offsets, int numGlyphs ); - glyph_metrics_t boundingBox( glyph_t glyph ); - - int ascent() const; - int descent() const; - int leading() const; - int maxCharWidth() const; - int minLeftBearing() const; - int minRightBearing() const; - - int cmap() const { return -1; } // ### - const char *name() const; - - bool canRender( const TQChar *string, int len ); - - void setScale( double scale ); - double scale() const { return _engines[0]->scale(); } - Type type() const { return LatinXLFD; } - - TQt::HANDLE handle() const { return ((TQFontEngineXLFD *) _engines[0])->handle(); } - -private: - void findEngine( const TQChar &ch ); - - TQFontEngine **_engines; - int _count; - - glyph_t glyphIndices [0x200]; - advance_t glyphAdvances[0x200]; - glyph_t euroIndex; - advance_t euroAdvance; -}; - -class TQScriptItem; -class TQTextEngine; - -#ifndef TQT_NO_XFTFREETYPE - -#include "qscriptengine_p.h" -#include "tqtextengine_p.h" -#include -#include FT_FREETYPE_H -#include "ftxopen.h" - -enum { PositioningProperties = 0x80000000 }; - -class TQOpenType -{ -public: - TQOpenType(TQFontEngineXft *fe); - ~TQOpenType(); - - struct Features { - uint tag; - uint property; - }; - - bool supportsScript(unsigned int script) { - Q_ASSERT(script < TQFont::NScripts); - return supported_scripts[script]; - } - void selectScript(unsigned int script, const Features *features = 0); - - bool shape(TQShaperItem *item, const unsigned int *properties = 0); - bool positionAndAdd(TQShaperItem *item, bool doLogClusters = TRUE); - - OTL_GlyphItem glyphs() const { return otl_buffer->in_string; } - int len() const { return otl_buffer->in_length; } - void setProperty(int index, uint property) { otl_buffer->in_string[index].properties = property; } - - -private: - bool checkScript(unsigned int script); - TQFontEngine *fontEngine; - FT_Face face; - TTO_GDEF gdef; - TTO_GSUB gsub; - TTO_GPOS gpos; - bool supported_scripts[TQFont::NScripts]; - FT_ULong current_script; - bool positioned : 1; - OTL_Buffer otl_buffer; - GlyphAttributes *tmpAttributes; - unsigned int *tmpLogClusters; - int length; - int orig_nglyphs; - int loadFlags; -}; - -#endif // TQT_NO_XFTFREETYPE - -#elif defined( TQ_WS_MAC ) -#include "qt_mac.h" -#include -#include - -class TQFontEngineMac : public TQFontEngine -{ -#if 0 - ATSFontMetrics *info; -#else - FontInfo *info; -#endif - int psize; - FMFontFamily fmfam; - TQMacFontInfo *internal_fi; - mutable ATSUTextLayout mTextLayout; - enum { widthCacheSize = 0x500 }; - mutable unsigned char widthCache[widthCacheSize]; - friend class TQFont; - friend class TQGLContext; - friend class TQFontPrivate; - friend class TQMacSetFontInfo; - -public: - TQFontEngineMac(); - ~TQFontEngineMac(); - - Error stringToCMap( const TQChar *str, int len, glyph_t *glyphs, advance_t *advances, int *nglyphs, bool mirrored ) const; - - void draw( TQPainter *p, int x, int y, const TQTextEngine *engine, const TQScriptItem *si, int textFlags ); - - glyph_metrics_t boundingBox( const glyph_t *glyphs, - const advance_t *advances, const qoffset_t *offsets, int numGlyphs ); - glyph_metrics_t boundingBox( glyph_t glyph ); - - int ascent() const { return (int)info->ascent; } - int descent() const { return (int)info->descent; } - int leading() const { return (int)info->leading; } -#if 0 - int maxCharWidth() const { return (int)info->maxAdvanceWidth; } -#else - int maxCharWidth() const { return info->widMax; } -#endif - - const char *name() const { return "ATSUI"; } - - bool canRender( const TQChar *string, int len ); - - Type type() const { return TQFontEngine::Mac; } - - void calculateCost(); - - enum { WIDTH=0x01, DRAW=0x02, EXISTS=0x04 }; - int doTextTask(const TQChar *s, int pos, int use_len, int len, uchar task, int =-1, int y=-1, - TQPaintDevice *dev=NULL, const TQRegion *rgn=NULL) const; -}; - -#elif defined( TQ_WS_WIN ) - -class TQFontEngineWin : public TQFontEngine -{ -public: - TQFontEngineWin( const char *name, HDC, HFONT, bool, LOGFONT ); - - Error stringToCMap( const TQChar *str, int len, glyph_t *glyphs, advance_t *advances, int *nglyphs, bool mirrored ) const; - - void draw( TQPainter *p, int x, int y, const TQTextEngine *engine, const TQScriptItem *si, int textFlags ); - - glyph_metrics_t boundingBox( const glyph_t *glyphs, - const advance_t *advances, const qoffset_t *offsets, int numGlyphs ); - glyph_metrics_t boundingBox( glyph_t glyph ); - - int ascent() const; - int descent() const; - int leading() const; - int maxCharWidth() const; - int minLeftBearing() const; - int minRightBearing() const; - - const char *name() const; - - bool canRender( const TQChar *string, int len ); - - Type type() const; - - enum { widthCacheSize = 0x800, cmapCacheSize = 0x500 }; - unsigned char widthCache[widthCacheSize]; -}; - -#if 0 -class TQFontEngineUniscribe : public TQFontEngineWin -{ -public: - void draw( TQPainter *p, int x, int y, const TQTextEngine *engine, const TQScriptItem *si, int textFlags ); - bool canRender( const TQChar *string, int len ); - - Type type() const; -}; -#endif - -#endif // TQ_WS_WIN - -#endif diff --git a/src/kernel/qfontengine_x11.cpp b/src/kernel/qfontengine_x11.cpp deleted file mode 100644 index 0a8164d44..000000000 --- a/src/kernel/qfontengine_x11.cpp +++ /dev/null @@ -1,2724 +0,0 @@ -/**************************************************************************** -** -** ??? -** -** Copyright (C) 2003-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#include "qfontengine_p.h" - -// #define FONTENGINE_DEBUG - -#include -#include -#include - -#include "tqbitmap.h" -#include "ntqfontdatabase.h" -#include "ntqpaintdevice.h" -#include "ntqpaintdevicemetrics.h" -#include "ntqpainter.h" -#include "tqimage.h" - -#include "qt_x11_p.h" - -#include "ntqfont.h" -#include "tqtextengine_p.h" - -#include - -#include - -// defined in qfontdatbase_x11.cpp -extern int qt_mib_for_xlfd_encoding( const char *encoding ); -extern int qt_xlfd_encoding_id( const char *encoding ); - -extern void qt_draw_transformed_rect( TQPainter *p, int x, int y, int w, int h, bool fill ); - -static void drawLines( TQPainter *p, TQFontEngine *fe, int baseline, int x1, int w, int textFlags ) -{ - int lw = fe->lineThickness(); - if ( textFlags & TQt::Underline ) { - int pos = fe->underlinePosition(); - qt_draw_transformed_rect( p, x1, baseline+pos, w, lw, TRUE ); - } - if ( textFlags & TQt::Overline ) { - int pos = fe->ascent()+1; - if ( !pos ) pos = 1; - qt_draw_transformed_rect( p, x1, baseline-pos, w, lw, TRUE ); - } - if ( textFlags & TQt::StrikeOut ) { - int pos = fe->ascent()/3; - if ( !pos ) pos = 1; - qt_draw_transformed_rect( p, x1, baseline-pos, w, lw, TRUE ); - } -} - - -inline static void qSafeXDestroyImage( XImage *x ) -{ - if ( x->data ) { - free( x->data ); - x->data = 0; - } - XDestroyImage( x ); -} - -extern bool qt_xForm_helper( const TQWMatrix &trueMat, int xoffset, - int type, int depth, - uchar *dptr, int dbpl, int p_inc, int dHeight, - uchar *sptr, int sbpl, int sWidth, int sHeight - ); - -static TQBitmap transform(Display *dpy, const TQBitmap &source, int xoff, int yoff, int w, int h, const TQWMatrix &matrix) -{ - int ws = source.width(); - int hs = source.height(); - - bool invertible; - TQWMatrix mat = matrix.invert( &invertible ); // invert matrix - - if (!invertible ) - return TQBitmap(); - mat.translate(xoff, yoff); - - XImage *xi = XGetImage(dpy, source.handle(), 0, 0, ws, hs, AllPlanes, XYPixmap); - - if ( !xi ) - return TQBitmap(); - - int sbpl = xi->bytes_per_line; - uchar *sptr = (uchar *)xi->data; - - int dbpl = (w+7)/8; - int dbytes = dbpl*h; - - uchar *dptr = (uchar *)malloc( dbytes ); // create buffer for bits - memset( dptr, 0, dbytes ); - - int type = xi->bitmap_bit_order == MSBFirst ? QT_XFORM_TYPE_MSBFIRST : QT_XFORM_TYPE_LSBFIRST; - int xbpl, p_inc; - xbpl = (w+7)/8; - p_inc = dbpl - xbpl; - - bool ok = qt_xForm_helper( mat, xi->xoffset, type, 1, dptr, xbpl, p_inc, h, sptr, sbpl, ws, hs ); - qSafeXDestroyImage(xi); - TQBitmap bm; - if (ok) { - bm = TQBitmap( w, h, dptr, TQImage::systemBitOrder() != TQImage::BigEndian ); - } else { -#if defined(QT_CHECK_RANGE) - tqWarning( "TQFontEngineXft::tranform: xform failed"); -#endif - } - - free( dptr ); - return bm; -} - - -static void drawScaled(int x, int y, const TQTextEngine *engine, const TQScriptItem *si, int textFlags, - Display *dpy, GC gc, TQPaintDevice *pdev, TQFontEngine *fe, - const TQWMatrix &xmat, float scale) -{ - // font doesn't support transformations, need to do it by hand - int w = tqRound(si->width/scale); - int h = tqRound((si->ascent + si->descent + 1)/scale); - if (w == 0 || h == 0) - return; - TQWMatrix mat1 = xmat; - mat1.scale(scale, scale); - - w += h; // add some pixels to width because of italic correction - TQBitmap bm( w, h, TRUE ); // create bitmap - TQPainter paint; - paint.begin( &bm ); // draw text in bitmap - fe->draw( &paint, 0, si->ascent/scale, engine, si, textFlags ); - paint.end(); - - TQRect pdevRect; - if (pdev->devType() == TQInternal::Widget) - pdevRect = ((TQWidget *)pdev)->rect(); - else if (pdev->devType() == TQInternal::Pixmap) - pdevRect = ((TQPixmap *)pdev)->rect(); - else - return; - - - TQRect br = mat1.mapRect(TQRect(x, y - si->ascent, w, h)); - TQRect br2 = br & pdevRect; - if (br2.width() <= 0 || br2.height() <= 0 - || br2.width() >= 32768 || br2.height() >= 32768) - return; - TQWMatrix mat = TQPixmap::trueMatrix( mat1, w, h ); - TQBitmap wx_bm = ::transform(dpy, bm, br2.x() - br.x(), br2.y() - br.y(), br2.width(), br2.height(), mat); - if ( wx_bm.isNull() ) - return; - - x = br2.x(); - y = br2.y(); - - TQt::HANDLE hd = pdev->handle(); - XSetFillStyle( dpy, gc, FillStippled ); - XSetStipple( dpy, gc, wx_bm.handle() ); - XSetTSOrigin( dpy, gc, x, y ); - XFillRectangle( dpy, hd, gc, x, y, wx_bm.width(), wx_bm.height() ); - XSetTSOrigin( dpy, gc, 0, 0 ); - XSetFillStyle( dpy, gc, FillSolid ); -} - - -TQFontEngine::~TQFontEngine() -{ -} - -int TQFontEngine::lineThickness() const -{ - // ad hoc algorithm - int score = fontDef.weight * fontDef.pixelSize; - int lw = score / 700; - - // looks better with thicker line for small pointsizes - if ( lw < 2 && score >= 1050 ) lw = 2; - if ( lw == 0 ) lw = 1; - - return lw; -} - -int TQFontEngine::underlinePosition() const -{ - int pos = ( ( lineThickness() * 2 ) + 3 ) / 6; - return pos ? pos : 1; -} - -// ------------------------------------------------------------------ -// The box font engine -// ------------------------------------------------------------------ - - -TQFontEngineBox::TQFontEngineBox( int size ) - : _size( size ) -{ - cache_cost = sizeof( TQFontEngineBox ); -} - -TQFontEngineBox::~TQFontEngineBox() -{ -} - -TQFontEngine::Error TQFontEngineBox::stringToCMap( const TQChar *, int len, glyph_t *glyphs, advance_t *advances, int *nglyphs, bool ) const -{ - if ( *nglyphs < len ) { - *nglyphs = len; - return OutOfMemory; - } - - memset( glyphs, 0, len * sizeof( glyph_t ) ); - *nglyphs = len; - - if ( advances ) { - for ( int i = 0; i < len; i++ ) - *(advances++) = _size; - } - return NoError; -} - -void TQFontEngineBox::draw( TQPainter *p, int x, int y, const TQTextEngine *engine, const TQScriptItem *si, int textFlags ) -{ - Display *dpy = TQPaintDevice::x11AppDisplay(); - TQt::HANDLE hd = p->device()->handle(); - GC gc = p->gc; - -#ifdef FONTENGINE_DEBUG - p->save(); - p->setBrush( TQt::white ); - glyph_metrics_t ci = boundingBox( glyphs, offsets, numGlyphs ); - p->drawRect( x + ci.x, y + ci.y, ci.width, ci.height ); - p->drawRect( x + ci.x, y + 50 + ci.y, ci.width, ci.height ); - tqDebug("bounding rect=%d %d (%d/%d)", ci.x, ci.y, ci.width, ci.height ); - p->restore(); - int xp = x; - int yp = y; -#endif - - GlyphAttributes *glyphAttributes = engine->glyphAttributes( si ); - - if ( p->txop > TQPainter::TxTranslate ) { - int xp = x; - int yp = _size + 2; - int s = _size - 3; - for (int k = 0; k < si->num_glyphs; k++) { - if (!glyphAttributes[k].zeroWidth) - qt_draw_transformed_rect( p, xp, yp, s, s, FALSE ); - xp += _size; - } - } else { - if ( p->txop == TQPainter::TxTranslate ) - p->map( x, y, &x, &y ); - - XRectangle rects[64]; - - int gl = 0; - while (gl < si->num_glyphs) { - int toDraw = TQMIN(64, si->num_glyphs-gl); - int adv = toDraw*_size; - if (x + adv < SHRT_MAX && x > SHRT_MIN) { - int ng = 0; - for (int k = 0; k < toDraw; k++) { - if (!glyphAttributes[gl + k].zeroWidth) { - rects[ng].x = x + (k * _size); - rects[ng].y = y - _size + 2; - rects[ng].width = rects[k].height = _size - 3; - ++ng; - } - } - XDrawRectangles(dpy, hd, gc, rects, ng); - } - gl += toDraw; - x += adv; - } - } - - if ( textFlags != 0 ) - drawLines( p, this, y, x, si->num_glyphs*_size, textFlags ); - -#ifdef FONTENGINE_DEBUG - x = xp; - y = yp; - p->save(); - p->setPen( TQt::red ); - for ( int i = 0; i < numGlyphs; i++ ) { - glyph_metrics_t ci = boundingBox( glyphs[i] ); - x += offsets[i].x; - y += offsets[i].y; - p->drawRect( x + ci.x, y + 50 + ci.y, ci.width, ci.height ); - tqDebug("bounding ci[%d]=%d %d (%d/%d) / %d %d offset=(%d/%d)", i, ci.x, ci.y, ci.width, ci.height, - ci.xoff, ci.yoff, offsets[i].x, offsets[i].y ); - x += ci.xoff; - y += ci.yoff; - } - p->restore(); -#endif -} - -glyph_metrics_t TQFontEngineBox::boundingBox( const glyph_t *, const advance_t *, const qoffset_t *, int numGlyphs ) -{ - glyph_metrics_t overall; - overall.x = overall.y = 0; - overall.width = _size*numGlyphs; - overall.height = _size; - overall.xoff = overall.width; - overall.yoff = 0; - return overall; -} - -glyph_metrics_t TQFontEngineBox::boundingBox( glyph_t ) -{ - return glyph_metrics_t( 0, _size, _size, _size, _size, 0 ); -} - - - -int TQFontEngineBox::ascent() const -{ - return _size; -} - -int TQFontEngineBox::descent() const -{ - return 0; -} - -int TQFontEngineBox::leading() const -{ - int l = tqRound( _size * 0.15 ); - return (l > 0) ? l : 1; -} - -int TQFontEngineBox::maxCharWidth() const -{ - return _size; -} - -int TQFontEngineBox::cmap() const -{ - return -1; -} - -const char *TQFontEngineBox::name() const -{ - return "null"; -} - -bool TQFontEngineBox::canRender( const TQChar *, int ) -{ - return TRUE; -} - -TQFontEngine::Type TQFontEngineBox::type() const -{ - return Box; -} - - - - -// ------------------------------------------------------------------ -// Xlfd cont engine -// ------------------------------------------------------------------ - -static inline XCharStruct *charStruct( XFontStruct *xfs, uint ch ) -{ - XCharStruct *xcs = 0; - unsigned char r = ch>>8; - unsigned char c = ch&0xff; - if ( r >= xfs->min_byte1 && - r <= xfs->max_byte1 && - c >= xfs->min_char_or_byte2 && - c <= xfs->max_char_or_byte2) { - if ( !xfs->per_char ) - xcs = &(xfs->min_bounds); - else { - xcs = xfs->per_char + ((r - xfs->min_byte1) * - (xfs->max_char_or_byte2 - - xfs->min_char_or_byte2 + 1)) + - (c - xfs->min_char_or_byte2); - if (xcs->width == 0 && xcs->ascent == 0 && xcs->descent == 0) - xcs = 0; - } - } - return xcs; -} - -TQFontEngineXLFD::TQFontEngineXLFD( XFontStruct *fs, const char *name, int mib ) - : _fs( fs ), _name( name ), _codec( 0 ), _scale( 1. ), _cmap( mib ) -{ - if ( _cmap ) _codec = TQTextCodec::codecForMib( _cmap ); - - cache_cost = (((fs->max_byte1 - fs->min_byte1) * - (fs->max_char_or_byte2 - fs->min_char_or_byte2 + 1)) + - fs->max_char_or_byte2 - fs->min_char_or_byte2); - cache_cost = ((fs->max_bounds.ascent + fs->max_bounds.descent) * - (fs->max_bounds.width * cache_cost / 8)); - lbearing = SHRT_MIN; - rbearing = SHRT_MIN; - -#if 1 - // Server side transformations do not seem to work correctly for - // all types of fonts (for example, it works for bdf/pcf fonts, - // but not for ttf). It also seems to be extermely server - // dependent. The best thing is to just disable server side - // transformations until either server support matures or we - // figure out a better way to do it. - xlfd_transformations = XlfdTrUnsupported; -#else - xlfd_transformations = XlfdTrUnknown; - - // Hummingbird's Exceed X server will substitute 'fixed' for any - // known fonts, and it doesn't seem to support transformations, so - // we should never try to use xlfd transformations with it - if (strstr(ServerVendor(TQPaintDevice::x11AppDisplay()), "Hummingbird")) - xlfd_transformations = XlfdTrUnsupported; -#endif -} - -TQFontEngineXLFD::~TQFontEngineXLFD() -{ - XFreeFont( TQPaintDevice::x11AppDisplay(), _fs ); - _fs = 0; - TransformedFont *trf = transformed_fonts; - while ( trf ) { - XUnloadFont( TQPaintDevice::x11AppDisplay(), trf->xlfd_font ); - TransformedFont *tmp = trf; - trf = trf->next; - delete tmp; - } -} - -TQFontEngine::Error TQFontEngineXLFD::stringToCMap( const TQChar *str, int len, glyph_t *glyphs, advance_t *advances, int *nglyphs, bool mirrored ) const -{ - if ( *nglyphs < len ) { - *nglyphs = len; - return OutOfMemory; - } - - if ( _codec ) { - bool haveNbsp = FALSE; - for ( int i = 0; i < len; i++ ) - if ( str[i].unicode() == 0xa0 ) { - haveNbsp = TRUE; - break; - } - - TQChar *chars = (TQChar *)str; - if ( haveNbsp || mirrored ) { - chars = (TQChar *)malloc( len*sizeof(TQChar) ); - for ( int i = 0; i < len; i++ ) - chars[i] = (str[i].unicode() == 0xa0 ? 0x20 : - (mirrored ? ::mirroredChar(str[i]).unicode() : str[i].unicode())); - } - _codec->fromUnicodeInternal( chars, glyphs, len ); - if (chars != str) - free( chars ); - } else { - glyph_t *g = glyphs + len; - const TQChar *c = str + len; - if ( mirrored ) { - while ( c != str ) - *(--g) = (--c)->unicode() == 0xa0 ? 0x20 : ::mirroredChar(*c).unicode(); - } else { - while ( c != str ) - *(--g) = (--c)->unicode() == 0xa0 ? 0x20 : c->unicode(); - } - } - *nglyphs = len; - - if ( advances ) { - glyph_t *g = glyphs + len; - advance_t *a = advances + len; - XCharStruct *xcs; - // inlined for better perfomance - if ( !_fs->per_char ) { - xcs = &_fs->min_bounds; - while ( a != advances ) - *(--a) = xcs->width; - } - else if ( !_fs->max_byte1 ) { - XCharStruct *base = _fs->per_char - _fs->min_char_or_byte2; - while ( g-- != glyphs ) { - unsigned int gl = *g; - xcs = (gl >= _fs->min_char_or_byte2 && gl <= _fs->max_char_or_byte2) ? - base + gl : 0; - *(--a) = (!xcs || (!xcs->width && !xcs->ascent && !xcs->descent)) ? _fs->ascent : xcs->width; - } - } - else { - while ( g != glyphs ) { - xcs = charStruct( _fs, *(--g) ); - *(--a) = (xcs ? xcs->width : _fs->ascent); - } - } - if ( _scale != 1. ) { - for ( int i = 0; i < len; i++ ) - advances[i] = tqRound(advances[i]*_scale); - } - } - return NoError; -} - -#if defined(Q_C_CALLBACKS) -extern "C" { -#endif - -static bool x_font_load_error = FALSE; -static int x_font_errorhandler(Display *, XErrorEvent *) -{ - x_font_load_error = TRUE; - return 0; -} - -#if defined(Q_C_CALLBACKS) -} -#endif - - -void TQFontEngineXLFD::draw( TQPainter *p, int x, int y, const TQTextEngine *engine, const TQScriptItem *si, int textFlags ) -{ - if ( !si->num_glyphs ) - return; - -// tqDebug("TQFontEngineXLFD::draw( %d, %d, numglyphs=%d", x, y, si->num_glyphs ); - - Display *dpy = TQPaintDevice::x11AppDisplay(); - TQt::HANDLE hd = p->device()->handle(); - GC gc = p->gc; - - bool transform = FALSE; - int xorig = x; - int yorig = y; - - TQt::HANDLE font_id = _fs->fid; - if ( p->txop > TQPainter::TxTranslate || _scale < 0.9999 || _scale > 1.0001 ) { - bool degenerate = TQABS( p->m11()*p->m22() - p->m12()*p->m21() ) < 0.01; - if ( !degenerate && xlfd_transformations != XlfdTrUnsupported ) { - // need a transformed font from the server - TQCString xlfd_transformed = _name; - int field = 0; - char *data = xlfd_transformed.data(); - int pos = 0; - while ( field < 7 ) { - if ( data[pos] == '-' ) - field++; - pos++; - } - int endPos = pos; - while ( data[endPos] != '-' ) - endPos++; - float size = xlfd_transformed.mid( pos, endPos-pos ).toInt(); - float mat[4]; - mat[0] = p->m11()*size*_scale; - mat[1] = -p->m12()*size*_scale; - mat[2] = -p->m21()*size*_scale; - mat[3] = p->m22()*size*_scale; - - // check if we have it cached - TransformedFont *trf = transformed_fonts; - TransformedFont *prev = 0; - int i = 0; - while ( trf ) { - if ( trf->xx == mat[0] && - trf->xy == mat[1] && - trf->yx == mat[2] && - trf->yy == mat[3] ) - break; - TransformedFont *tmp = trf; - trf = trf->next; - if (i > 10) { - XUnloadFont( TQPaintDevice::x11AppDisplay(), tmp->xlfd_font ); - delete tmp; - prev->next = trf; - } else { - prev = tmp; - } - ++i; - } - if ( trf ) { - if ( prev ) { - // move to beginning of list - prev->next = trf->next; - trf->next = transformed_fonts; - transformed_fonts = trf; - } - font_id = trf->xlfd_font; - } else { - TQCString matrix="["; - for ( int i = 0; i < 4; i++ ) { - float f = mat[i]; - if ( f < 0 ) { - matrix += '~'; - f = -f; - } - matrix += TQString::number( f, 'f', 5 ).latin1(); - matrix += ' '; - } - matrix += ']'; - //tqDebug("m: %2.2f %2.2f %2.2f %2.2f, matrix=%s", p->m11(), p->m12(), p->m21(), p->m22(), matrix.data()); - xlfd_transformed.replace( pos, endPos-pos, matrix ); - - x_font_load_error = FALSE; - XErrorHandler old_handler = XSetErrorHandler( x_font_errorhandler ); - font_id = XLoadFont( dpy, xlfd_transformed.data() ); - XSync( dpy, FALSE ); - XSetErrorHandler( old_handler ); - if ( x_font_load_error ) { - //tqDebug( "couldn't load transformed font" ); - font_id = _fs->fid; - xlfd_transformations = XlfdTrUnsupported; - } else { - TransformedFont *trf = new TransformedFont; - trf->xx = mat[0]; - trf->xy = mat[1]; - trf->yx = mat[2]; - trf->yy = mat[3]; - trf->xlfd_font = font_id; - trf->next = transformed_fonts; - transformed_fonts = trf; - } - } - } - if ( degenerate || xlfd_transformations == XlfdTrUnsupported ) { - // XServer or font don't support server side transformations, need to do it by hand - float tmp = _scale; - _scale = 1.; - drawScaled(x, y, engine, si, textFlags, dpy, p->gc, p->device(), this, p->xmat, tmp); - _scale = tmp; - return; - } - transform = TRUE; - } else if ( p->txop == TQPainter::TxTranslate ) { - p->map( x, y, &x, &y ); - } - - XSetFont(dpy, gc, font_id); - -#ifdef FONTENGINE_DEBUG - p->save(); - p->setBrush( TQt::white ); - glyph_metrics_t ci = boundingBox( glyphs, advances, offsets, si->num_glyphs ); - p->drawRect( x + ci.x, y + ci.y, ci.width, ci.height ); - p->drawRect( x + ci.x, y + 100 + ci.y, ci.width, ci.height ); - tqDebug("bounding rect=%d %d (%d/%d)", ci.x, ci.y, ci.width, ci.height ); - p->restore(); - int xp = x; - int yp = y; -#endif - - glyph_t *glyphs = engine->glyphs( si ); - advance_t *advances = engine->advances( si ); - qoffset_t *offsets = engine->offsets( si ); - - XChar2b ch[256]; - XChar2b *chars = ch; - if ( si->num_glyphs > 255 ) - chars = (XChar2b *)malloc( si->num_glyphs*sizeof(XChar2b) ); - - for (int i = 0; i < si->num_glyphs; i++) { - chars[i].byte1 = glyphs[i] >> 8; - chars[i].byte2 = glyphs[i] & 0xff; - } - - int xpos = x; - GlyphAttributes *glyphAttributes = engine->glyphAttributes( si ); - - if ( si->analysis.bidiLevel % 2 ) { - int i = si->num_glyphs; - while( i-- ) { - advance_t adv = advances[i]; - // tqDebug("advance = %d/%d", adv.x, adv.y ); - x += adv; - glyph_metrics_t gi = boundingBox( glyphs[i] ); - int xp = x-offsets[i].x-gi.xoff; - int yp = y+offsets[i].y-gi.yoff; - if ( transform ) - p->map( xp, yp, &xp, &yp ); - if (!glyphAttributes[i].zeroWidth && xp < SHRT_MAX && xp > SHRT_MIN) - XDrawString16(dpy, hd, gc, xp, yp, chars+i, 1 ); - } - } else { - if ( transform || si->hasPositioning ) { - int i = 0; - while( i < si->num_glyphs ) { - int xp = x+offsets[i].x; - int yp = y+offsets[i].y; - if ( transform ) - p->map( xp, yp, &xp, &yp ); - if (!glyphAttributes[i].zeroWidth && xp < SHRT_MAX && xp > SHRT_MIN) - XDrawString16(dpy, hd, gc, xp, yp, chars+i, 1 ); - advance_t adv = advances[i]; - // tqDebug("advance = %d/%d", adv.x, adv.y ); - x += adv; - i++; - } - } else { - // we can take a shortcut - int gl = 0; - while (gl < si->num_glyphs) { - int toDraw = TQMIN(64, si->num_glyphs-gl); - int adv = 0; - for (int i = gl; i < gl+toDraw; ++i) - adv += advances[i]; - if (x + adv < SHRT_MAX && x > SHRT_MIN) - XDrawString16(dpy, hd, gc, x, y, chars+gl, toDraw); - gl += toDraw; - x += adv; - } - } - } - - if ( chars != ch ) - free( chars ); - - if ( textFlags != 0 ) - drawLines( p, this, yorig, xorig, x-xpos, textFlags ); - -#ifdef FONTENGINE_DEBUG - x = xp; - y = yp; - p->save(); - p->setPen( TQt::red ); - for ( int i = 0; i < si->num_glyphs; i++ ) { - glyph_metrics_t ci = boundingBox( glyphs[i] ); - p->drawRect( x + ci.x + offsets[i].x, y + 100 + ci.y + offsets[i].y, ci.width, ci.height ); - tqDebug("bounding ci[%d]=%d %d (%d/%d) / %d %d offs=(%d/%d) advance=(%d/%d)", i, ci.x, ci.y, ci.width, ci.height, - ci.xoff, ci.yoff, offsets[i].x, offsets[i].y, - advances[i].x, advances[i].y); - x += advances[i].x; - y += advances[i].y; - } - p->restore(); -#endif -} - -glyph_metrics_t TQFontEngineXLFD::boundingBox( const glyph_t *glyphs, const advance_t *advances, const qoffset_t *offsets, int numGlyphs ) -{ - int i; - - glyph_metrics_t overall; - int ymax = 0; - int xmax = 0; - for (i = 0; i < numGlyphs; i++) { - XCharStruct *xcs = charStruct( _fs, glyphs[i] ); - if (xcs) { - int x = overall.xoff + offsets[i].x - xcs->lbearing; - int y = overall.yoff + offsets[i].y - xcs->ascent; - overall.x = TQMIN( overall.x, x ); - overall.y = TQMIN( overall.y, y ); - xmax = TQMAX( xmax, overall.xoff + offsets[i].x + xcs->rbearing ); - ymax = TQMAX( ymax, y + xcs->ascent + xcs->descent ); - overall.xoff += tqRound(advances[i]/_scale); - } else { - int size = _fs->ascent; - overall.x = TQMIN(overall.x, overall.xoff ); - overall.y = TQMIN(overall.y, overall.yoff - size ); - ymax = TQMAX( ymax, overall.yoff ); - overall.xoff += size; - xmax = TQMAX( xmax, overall.xoff ); - } - } - overall.height = ymax - overall.y; - overall.width = xmax - overall.x; - - if ( _scale != 1. ) { - overall.x = tqRound(overall.x * _scale); - overall.y = tqRound(overall.y * _scale); - overall.height = tqRound(overall.height * _scale); - overall.width = tqRound(overall.width * _scale); - overall.xoff = tqRound(overall.xoff * _scale); - overall.yoff = tqRound(overall.yoff * _scale); - } - return overall; -} - -glyph_metrics_t TQFontEngineXLFD::boundingBox( glyph_t glyph ) -{ - glyph_metrics_t gm; - // ### scale missing! - XCharStruct *xcs = charStruct( _fs, glyph ); - if (xcs) { - gm = glyph_metrics_t( xcs->lbearing, -xcs->ascent, xcs->rbearing- xcs->lbearing, xcs->ascent + xcs->descent, xcs->width, 0 ); - } else { - int size = _fs->ascent; - gm = glyph_metrics_t( 0, size, size, size, size, 0 ); - } - if ( _scale != 1. ) { - gm.x = tqRound(gm.x * _scale); - gm.y = tqRound(gm.y * _scale); - gm.height = tqRound(gm.height * _scale); - gm.width = tqRound(gm.width * _scale); - gm.xoff = tqRound(gm.xoff * _scale); - gm.yoff = tqRound(gm.yoff * _scale); - } - return gm; -} - - -int TQFontEngineXLFD::ascent() const -{ - return tqRound(_fs->ascent*_scale); -} - -int TQFontEngineXLFD::descent() const -{ - return tqRound((_fs->descent-1)*_scale); -} - -int TQFontEngineXLFD::leading() const -{ - int l = tqRound((TQMIN(_fs->ascent, _fs->max_bounds.ascent) - + TQMIN(_fs->descent, _fs->max_bounds.descent)) * _scale * 0.15 ); - return (l > 0) ? l : 1; -} - -int TQFontEngineXLFD::maxCharWidth() const -{ - return tqRound(_fs->max_bounds.width*_scale); -} - - -// Loads the font for the specified script -static inline int maxIndex(XFontStruct *f) { - return (((f->max_byte1 - f->min_byte1) * - (f->max_char_or_byte2 - f->min_char_or_byte2 + 1)) + - f->max_char_or_byte2 - f->min_char_or_byte2); -} - -int TQFontEngineXLFD::minLeftBearing() const -{ - if ( lbearing == SHRT_MIN ) { - if ( _fs->per_char ) { - XCharStruct *cs = _fs->per_char; - int nc = maxIndex(_fs) + 1; - int mx = cs->lbearing; - - for (int c = 1; c < nc; c++) { - // ignore the bearings for characters whose ink is - // completely outside the normal bounding box - if ((cs[c].lbearing <= 0 && cs[c].rbearing <= 0) || - (cs[c].lbearing >= cs[c].width && cs[c].rbearing >= cs[c].width)) - continue; - - int nmx = cs[c].lbearing; - - if (nmx < mx) - mx = nmx; - } - - ((TQFontEngineXLFD *)this)->lbearing = mx; - } else - ((TQFontEngineXLFD *)this)->lbearing = _fs->min_bounds.lbearing; - } - return tqRound (lbearing*_scale); -} - -int TQFontEngineXLFD::minRightBearing() const -{ - if ( rbearing == SHRT_MIN ) { - if ( _fs->per_char ) { - XCharStruct *cs = _fs->per_char; - int nc = maxIndex(_fs) + 1; - int mx = cs->rbearing; - - for (int c = 1; c < nc; c++) { - // ignore the bearings for characters whose ink is - // completely outside the normal bounding box - if ((cs[c].lbearing <= 0 && cs[c].rbearing <= 0) || - (cs[c].lbearing >= cs[c].width && cs[c].rbearing >= cs[c].width)) - continue; - - int nmx = cs[c].rbearing; - - if (nmx < mx) - mx = nmx; - } - - ((TQFontEngineXLFD *)this)->rbearing = mx; - } else - ((TQFontEngineXLFD *)this)->rbearing = _fs->min_bounds.rbearing; - } - return tqRound (rbearing*_scale); -} - -int TQFontEngineXLFD::cmap() const -{ - return _cmap; -} - -const char *TQFontEngineXLFD::name() const -{ - return _name; -} - -bool TQFontEngineXLFD::canRender( const TQChar *string, int len ) -{ - glyph_t glyphs[256]; - int nglyphs = 255; - glyph_t *g = glyphs; - if ( stringToCMap( string, len, g, 0, &nglyphs, FALSE ) == OutOfMemory ) { - g = (glyph_t *)malloc( nglyphs*sizeof(glyph_t) ); - stringToCMap( string, len, g, 0, &nglyphs, FALSE ); - } - - bool allExist = TRUE; - for ( int i = 0; i < nglyphs; i++ ) { - if ( !g[i] || !charStruct( _fs, g[i] ) ) { - allExist = FALSE; - break; - } - } - - if ( g != glyphs ) - free( g ); - - return allExist; -} - - -void TQFontEngineXLFD::setScale( double scale ) -{ - _scale = scale; -} - - -TQFontEngine::Type TQFontEngineXLFD::type() const -{ - return XLFD; -} - - -// ------------------------------------------------------------------ -// LatinXLFD engine -// ------------------------------------------------------------------ - -static const int engine_array_inc = 4; - -TQFontEngineLatinXLFD::TQFontEngineLatinXLFD( XFontStruct *xfs, const char *name, - int mib ) -{ - _engines = new TQFontEngine*[ engine_array_inc ]; - _engines[0] = new TQFontEngineXLFD( xfs, name, mib ); - _count = 1; - - cache_cost = _engines[0]->cache_cost; - - memset( glyphIndices, 0, sizeof( glyphIndices ) ); - memset( glyphAdvances, 0, sizeof( glyphAdvances ) ); - euroIndex = 0; - euroAdvance = 0; -} - -TQFontEngineLatinXLFD::~TQFontEngineLatinXLFD() -{ - for ( int i = 0; i < _count; ++i ) { - delete _engines[i]; - _engines[i] = 0; - } - delete [] _engines; - _engines = 0; -} - -void TQFontEngineLatinXLFD::findEngine( const TQChar &ch ) -{ - if ( ch.unicode() == 0 ) return; - - static const char *alternate_encodings[] = { - "iso8859-1", - "iso8859-2", - "iso8859-3", - "iso8859-4", - "iso8859-9", - "iso8859-10", - "iso8859-13", - "iso8859-14", - "iso8859-15", - "hp-roman8" - }; - static const int mib_count = sizeof( alternate_encodings ) / sizeof( const char * ); - - // see if one of the above mibs can map the char we want - TQTextCodec *codec = 0; - int which = -1; - int i; - for ( i = 0; i < mib_count; ++i ) { - const int mib = qt_mib_for_xlfd_encoding( alternate_encodings[i] ); - bool skip = FALSE; - for ( int e = 0; e < _count; ++e ) { - if ( _engines[e]->cmap() == mib ) { - skip = TRUE; - break; - } - } - if ( skip ) continue; - - codec = TQTextCodec::codecForMib( mib ); - if ( codec && codec->canEncode( ch ) ) { - which = i; - break; - } - } - - if ( ! codec || which == -1 ) - return; - - const int enc_id = qt_xlfd_encoding_id( alternate_encodings[which] ); - TQFontDef req = fontDef; - TQFontEngine *engine = TQFontDatabase::findFont( TQFont::Latin, 0, req, enc_id ); - if ( ! engine ) { - req.family = TQString::null; - engine = TQFontDatabase::findFont( TQFont::Latin, 0, req, enc_id ); - if ( ! engine ) return; - } - engine->setScale( scale() ); - - if ( ! ( _count % engine_array_inc ) ) { - // grow the engines array - TQFontEngine **old = _engines; - int new_size = - ( ( ( _count+engine_array_inc ) / engine_array_inc ) * engine_array_inc ); - _engines = new TQFontEngine*[new_size]; - for ( i = 0; i < _count; ++i ) - _engines[i] = old[i]; - delete [] old; - } - - _engines[_count] = engine; - const int hi = _count << 8; - ++_count; - - unsigned short chars[0x201]; - glyph_t glyphs[0x201]; - advance_t advances[0x201]; - for ( i = 0; i < 0x200; ++i ) - chars[i] = i; - chars[0x200] = 0x20ac; - int glyphCount = 0x201; - engine->stringToCMap( (const TQChar *) chars, 0x201, glyphs, advances, &glyphCount, FALSE ); - - // merge member data with the above - for ( i = 0; i < 0x200; ++i ) { - if ( glyphIndices[i] != 0 || glyphs[i] == 0 ) continue; - glyphIndices[i] = glyphs[i] >= 0x2100 ? glyphs[i] : hi | glyphs[i]; - glyphAdvances[i] = advances[i]; - } - if (!euroIndex && glyphs[0x200]) { - euroIndex = hi | glyphs[0x200]; - euroAdvance = advances[0x200]; - } -} - -TQFontEngine::Error -TQFontEngineLatinXLFD::stringToCMap( const TQChar *str, int len, glyph_t *glyphs, - advance_t *advances, int *nglyphs, bool mirrored ) const -{ - if ( *nglyphs < len ) { - *nglyphs = len; - return OutOfMemory; - } - - int i; - bool missing = FALSE; - const TQChar *c = str+len; - glyph_t *g = glyphs+len; - if ( advances ) { - int asc = ascent(); - advance_t *a = advances+len; - if ( mirrored ) { - while ( c != str ) { - --c; - --g; - --a; - if ( c->unicode() < 0x200 ) { - unsigned short ch = ::mirroredChar(*c).unicode(); - *g = glyphIndices[ch]; - *a = glyphAdvances[ch]; - } else { - if ( c->unicode() == 0x20ac ) { - *g = euroIndex; - *a = euroAdvance; - } else { - *g = 0; - *a = asc; - } - } - missing = ( missing || ( *g == 0 ) ); - } - } else { - while ( c != str ) { - --c; - --g; - --a; - if ( c->unicode() < 0x200 ) { - *g = glyphIndices[c->unicode()]; - *a = glyphAdvances[c->unicode()]; - } else { - if ( c->unicode() == 0x20ac ) { - *g = euroIndex; - *a = euroAdvance; - } else { - *g = 0; - *a = asc; - } - } - missing = ( missing || ( *g == 0 ) ); - } - } - } else { - if ( mirrored ) { - while ( c != str ) { - --c; - --g; - *g = ( ( c->unicode() < 0x200 ) ? glyphIndices[::mirroredChar(*c).unicode()] - : (c->unicode() == 0x20ac) ? euroIndex : 0 ); - missing = ( missing || ( *g == 0 ) ); - } - } else { - while ( c != str ) { - --c; - --g; - *g = ( ( c->unicode() < 0x200 ) ? glyphIndices[c->unicode()] - : (c->unicode() == 0x20ac) ? euroIndex : 0 ); - missing = ( missing || ( *g == 0 ) ); - } - } - } - - if ( missing ) { - for ( i = 0; i < len; ++i ) { - unsigned short uc = str[i].unicode(); - if ( glyphs[i] != 0 || (uc >= 0x200 && uc != 0x20ac) ) - continue; - - TQFontEngineLatinXLFD *that = (TQFontEngineLatinXLFD *) this; - that->findEngine( str[i] ); - glyphs[i] = (uc == 0x20ac ? euroIndex : that->glyphIndices[uc]); - if ( advances ) - advances[i] = (uc == 0x20ac ? euroAdvance : glyphAdvances[uc]); - } - } - - *nglyphs = len; - return NoError; -} - -void TQFontEngineLatinXLFD::draw( TQPainter *p, int x, int y, const TQTextEngine *engine, - const TQScriptItem *si, int textFlags ) -{ - if ( !si->num_glyphs ) return; - - glyph_t *glyphs = engine->glyphs( si ); - advance_t *advances = engine->advances( si ); - int which = glyphs[0] >> 8; - if (which > 0x20) - which = 0; - - int start = 0; - int end, i; - for ( end = 0; end < si->num_glyphs; ++end ) { - int e = glyphs[end] >> 8; - if (e > 0x20) - e = 0; - if ( e == which ) continue; - - // set the high byte to zero - if (which != 0) { - for ( i = start; i < end; ++i ) - glyphs[i] = glyphs[i] & 0xff; - } - - // draw the text - TQScriptItem si2 = *si; - si2.glyph_data_offset = si->glyph_data_offset + start; - si2.num_glyphs = end - start; - _engines[which]->draw( p, x, y, engine, &si2, textFlags ); - - // reset the high byte for all glyphs and advance to the next sub-string - const int hi = which << 8; - for ( i = start; i < end; ++i ) { - glyphs[i] = hi | glyphs[i]; - x += advances[i]; - } - - // change engine - start = end; - which = e; - } - - // set the high byte to zero - if (which != 0) { - for ( i = start; i < end; ++i ) - glyphs[i] = glyphs[i] & 0xff; - } - // draw the text - TQScriptItem si2 = *si; - si2.glyph_data_offset = si->glyph_data_offset + start; - si2.num_glyphs = end - start; - _engines[which]->draw( p, x, y, engine, &si2, textFlags ); - - // reset the high byte for all glyphs - if (which != 0) { - const int hi = which << 8; - for ( i = start; i < end; ++i ) - glyphs[i] = hi | glyphs[i]; - } -} - -glyph_metrics_t TQFontEngineLatinXLFD::boundingBox( const glyph_t *glyphs_const, - const advance_t *advances, - const qoffset_t *offsets, - int numGlyphs ) -{ - if ( numGlyphs <= 0 ) return glyph_metrics_t(); - - glyph_metrics_t overall; - - glyph_t *glyphs = (glyph_t *) glyphs_const; - int which = glyphs[0] >> 8; - if (which > 0x20) - which = 0; - - int start = 0; - int end, i; - for ( end = 0; end < numGlyphs; ++end ) { - int e = glyphs[end] >> 8; - if (e > 0x20) - e = 0; - if ( e == which ) continue; - - // set the high byte to zero - if (which != 0) { - for ( i = start; i < end; ++i ) - glyphs[i] = glyphs[i] & 0xff; - } - - // merge the bounding box for this run - const glyph_metrics_t gm = - _engines[which]->boundingBox( glyphs + start, - advances + start, - offsets + start, - end - start ); - - overall.x = TQMIN( overall.x, gm.x ); - overall.y = TQMIN( overall.y, gm.y ); - overall.width = overall.xoff + gm.width; - overall.height = TQMAX( overall.height + overall.y, gm.height + gm.y ) - - TQMIN( overall.y, gm.y ); - overall.xoff += gm.xoff; - overall.yoff += gm.yoff; - - // reset the high byte for all glyphs - if (which != 0) { - const int hi = which << 8; - for ( i = start; i < end; ++i ) - glyphs[i] = hi | glyphs[i]; - } - - // change engine - start = end; - which = e; - } - - // set the high byte to zero - if (which != 0) { - for ( i = start; i < end; ++i ) - glyphs[i] = glyphs[i] & 0xff; - } - - // merge the bounding box for this run - const glyph_metrics_t gm = - _engines[which]->boundingBox( glyphs + start, - advances + start, - offsets + start, - end - start ); - - overall.x = TQMIN( overall.x, gm.x ); - overall.y = TQMIN( overall.y, gm.y ); - overall.width = overall.xoff + gm.width; - overall.height = TQMAX( overall.height + overall.y, gm.height + gm.y ) - - TQMIN( overall.y, gm.y ); - overall.xoff += gm.xoff; - overall.yoff += gm.yoff; - - // reset the high byte for all glyphs - if (which != 0) { - const int hi = which << 8; - for ( i = start; i < end; ++i ) - glyphs[i] = hi | glyphs[i]; - } - - return overall; -} - -glyph_metrics_t TQFontEngineLatinXLFD::boundingBox( glyph_t glyph ) -{ - int engine = glyph >> 8; - if (engine > 0x20) - engine = 0; - Q_ASSERT( engine < _count ); - return _engines[engine]->boundingBox( engine > 0 ? glyph & 0xff : glyph ); -} - -int TQFontEngineLatinXLFD::ascent() const -{ - return _engines[0]->ascent(); -} - -int TQFontEngineLatinXLFD::descent() const -{ - return _engines[0]->descent(); -} - -int TQFontEngineLatinXLFD::leading() const -{ - return _engines[0]->leading(); -} - -int TQFontEngineLatinXLFD::maxCharWidth() const -{ - return _engines[0]->maxCharWidth(); -} - -int TQFontEngineLatinXLFD::minLeftBearing() const -{ - return _engines[0]->minLeftBearing(); -} - -int TQFontEngineLatinXLFD::minRightBearing() const -{ - return _engines[0]->minRightBearing(); -} - -const char *TQFontEngineLatinXLFD::name() const -{ - return _engines[0]->name(); -} - -bool TQFontEngineLatinXLFD::canRender( const TQChar *string, int len ) -{ - bool all = TRUE; - int i; - for ( i = 0; i < len; ++i ) { - if ( string[i].unicode() >= 0x200 || - glyphIndices[string[i].unicode()] == 0 ) { - if (string[i].unicode() != 0x20ac || euroIndex == 0) - all = FALSE; - break; - } - } - - if ( all ) - return TRUE; - - all = TRUE; - for ( i = 0; i < len; ++i ) { - if ( string[i].unicode() >= 0x200 ) { - if (string[i].unicode() == 0x20ac) { - if (euroIndex) - continue; - - findEngine(string[i]); - if (euroIndex) - continue; - } - all = FALSE; - break; - } - if ( glyphIndices[string[i].unicode()] != 0 ) continue; - - findEngine( string[i] ); - if ( glyphIndices[string[i].unicode()] == 0 ) { - all = FALSE; - break; - } - } - - return all; -} - -void TQFontEngineLatinXLFD::setScale( double scale ) -{ - int i; - for ( i = 0; i < _count; ++i ) - _engines[i]->setScale( scale ); - unsigned short chars[0x200]; - for ( i = 0; i < 0x200; ++i ) - chars[i] = i; - int glyphCount = 0x200; - _engines[0]->stringToCMap( (const TQChar *)chars, 0x200, - glyphIndices, glyphAdvances, &glyphCount, FALSE ); -} - - -// ------------------------------------------------------------------ -// Xft cont engine -// ------------------------------------------------------------------ -// #define FONTENGINE_DEBUG - -#ifndef TQT_NO_XFTFREETYPE -class Q_HackPaintDevice : public TQPaintDevice -{ -public: - inline Q_HackPaintDevice() : TQPaintDevice( 0 ) {} - inline XftDraw *xftDrawHandle() const { - return (XftDraw *)rendhd; - } - -}; - -#ifdef QT_XFT2 -static inline void getGlyphInfo( XGlyphInfo *xgi, XftFont *font, int glyph ) -{ - FT_UInt x = glyph; - XftGlyphExtents( TQPaintDevice::x11AppDisplay(), font, &x, 1, xgi ); -} -#else -static inline XftFontStruct *getFontStruct( XftFont *font ) -{ - if (font->core) - return 0; - return font->u.ft.font; -} - -static inline void getGlyphInfo(XGlyphInfo *xgi, XftFont *font, int glyph) -{ - - XftTextExtents32(TQPaintDevice::x11AppDisplay(), font, (XftChar32 *) &glyph, 1, xgi); -} -#endif // QT_XFT2 - -static inline FT_Face lockFTFace( XftFont *font ) -{ -#ifdef QT_XFT2 - return XftLockFace( font ); -#else - if (font->core) return 0; - return font->u.ft.font->face; -#endif // QT_XFT2 -} - -static inline void unlockFTFace( XftFont *font ) -{ -#ifdef QT_XFT2 - XftUnlockFace( font ); -#else - Q_UNUSED( font ); -#endif // QT_XFT2 -} - - - -TQFontEngineXft::TQFontEngineXft( XftFont *font, XftPattern *pattern, int cmap ) - : _font( font ), _pattern( pattern ), _openType( 0 ), _cmap( cmap ) -{ - _face = lockFTFace( _font ); - -#ifndef QT_XFT2 - XftFontStruct *xftfs = getFontStruct( _font ); - if ( xftfs ) { - // dirty hack: we set the charmap in the Xftfreetype to -1, so - // XftFreetype assumes no encoding and really draws glyph - // indices. The FT_Face still has the Unicode encoding to we - // can convert from Unicode to glyph index - xftfs->charmap = -1; - } -#else - _cmap = -1; - // Xft maps Unicode and adobe roman for us. - for (int i = 0; i < _face->num_charmaps; ++i) { - FT_CharMap cm = _face->charmaps[i]; -// tqDebug("font has charmap %x", cm->encoding); - if (cm->encoding == ft_encoding_adobe_custom - || cm->encoding == ft_encoding_symbol) { -// tqDebug("font has adobe custom or ms symbol charmap"); - _cmap = i; - break; - } - } -#endif // QT_XFT2 - - - cache_cost = _font->height * _font->max_advance_width * - ( _face ? _face->num_glyphs : 1024 ); - - // if the Xft font is not antialiased, it uses bitmaps instead of - // 8-bit alpha maps... adjust the cache_cost to reflect this - Bool antialiased = TRUE; - if ( XftPatternGetBool( pattern, XFT_ANTIALIAS, - 0, &antialiased ) == XftResultMatch && - ! antialiased ) { - cache_cost /= 8; - } - lbearing = SHRT_MIN; - rbearing = SHRT_MIN; - - memset( widthCache, 0, sizeof(widthCache) ); - memset( cmapCache, 0, sizeof(cmapCache) ); -} - -TQFontEngineXft::~TQFontEngineXft() -{ - delete _openType; - unlockFTFace( _font ); - - XftFontClose( TQPaintDevice::x11AppDisplay(),_font ); - XftPatternDestroy( _pattern ); - _font = 0; - _pattern = 0; - TransformedFont *trf = transformed_fonts; - while ( trf ) { - XftFontClose( TQPaintDevice::x11AppDisplay(), trf->xft_font ); - TransformedFont *tmp = trf; - trf = trf->next; - delete tmp; - } -} - -#ifdef QT_XFT2 -static glyph_t getAdobeCharIndex(XftFont *font, int cmap, uint ucs4) -{ - FT_Face _face = XftLockFace( font ); - FT_Set_Charmap(_face, _face->charmaps[cmap]); - glyph_t g = FT_Get_Char_Index(_face, ucs4); - XftUnlockFace(font); - return g; -} -#endif - -TQFontEngine::Error TQFontEngineXft::stringToCMap( const TQChar *str, int len, glyph_t *glyphs, advance_t *advances, int *nglyphs, bool mirrored ) const -{ - if ( *nglyphs < len ) { - *nglyphs = len; - return OutOfMemory; - } - -#ifdef QT_XFT2 - if (_cmap != -1) { - for ( int i = 0; i < len; ++i ) { - unsigned short uc = str[i].unicode(); - if (mirrored) - uc = ::mirroredChar(str[i]).unicode(); - glyphs[i] = uc < cmapCacheSize ? cmapCache[uc] : 0; - if ( !glyphs[i] ) { - glyph_t glyph = XftCharIndex(0, _font, uc); - if (!glyph) - glyph = getAdobeCharIndex(_font, _cmap, uc); - glyphs[i] = glyph; - if ( uc < cmapCacheSize ) - ((TQFontEngineXft *)this)->cmapCache[uc] = glyph; - } - } - } else if ( mirrored ) { - for ( int i = 0; i < len; ++i ) { - unsigned short uc = ::mirroredChar(str[i]).unicode(); - glyphs[i] = uc < cmapCacheSize ? cmapCache[uc] : 0; - if ( !glyphs[i] ) { - if (uc == 0xa0) - uc = 0x20; - glyph_t glyph = XftCharIndex(0, _font, uc); - glyphs[i] = glyph; - if ( uc < cmapCacheSize ) - ((TQFontEngineXft *)this)->cmapCache[uc] = glyph; - } - } - } else { - for ( int i = 0; i < len; ++i ) { - unsigned short uc = str[i].unicode(); - glyphs[i] = uc < cmapCacheSize ? cmapCache[uc] : 0; - if ( !glyphs[i] ) { - if (uc == 0xa0) - uc = 0x20; - glyph_t glyph = XftCharIndex(0, _font, uc); - glyphs[i] = glyph; - if ( uc < cmapCacheSize ) - ((TQFontEngineXft *)this)->cmapCache[uc] = glyph; - } - } - } - - if ( advances ) { - for ( int i = 0; i < len; i++ ) { - FT_UInt glyph = *(glyphs + i); - advances[i] = (glyph < widthCacheSize) ? widthCache[glyph] : 0; - if ( !advances[i] ) { - XGlyphInfo gi; - XftGlyphExtents( TQPaintDevice::x11AppDisplay(), _font, &glyph, 1, &gi ); - advances[i] = gi.xOff; - if ( glyph < widthCacheSize && gi.xOff > 0 && gi.xOff < 0x100 ) - ((TQFontEngineXft *)this)->widthCache[glyph] = gi.xOff; - } - } - if ( _scale != 1. ) { - for ( int i = 0; i < len; i++ ) - advances[i] = tqRound(advances[i]*_scale); - } - } -#else - if ( !_face ) { - if ( mirrored ) { - for ( int i = 0; i < len; i++ ) - glyphs[i] = ::mirroredChar(str[i]).unicode(); - } else { - for ( int i = 0; i < len; i++ ) - glyphs[i] = str[i].unicode(); - } - } else { - if ( _cmap == 1 ) { - // symbol font - for ( int i = 0; i < len; i++ ) { - unsigned short uc = str[i].unicode(); - glyphs[i] = uc < cmapCacheSize ? cmapCache[uc] : 0; - if ( !glyphs[i] ) { - glyph_t glyph = FT_Get_Char_Index( _face, uc ); - if(!glyph && uc < 0x100) - glyph = FT_Get_Char_Index( _face, uc+0xf000 ); - glyphs[i] = glyph; - if ( uc < cmapCacheSize ) - ((TQFontEngineXft *)this)->cmapCache[uc] = glyph; - } - } - } else if ( mirrored ) { - for ( int i = 0; i < len; i++ ) { - unsigned short uc = ::mirroredChar(str[i]).unicode(); - glyphs[i] = uc < cmapCacheSize ? cmapCache[uc] : 0; - if ( !glyphs[i] ) { - glyph_t glyph = FT_Get_Char_Index( _face, uc ); - glyphs[i] = glyph; - if ( uc < cmapCacheSize ) - ((TQFontEngineXft *)this)->cmapCache[uc] = glyph; - } - } - } else { - for ( int i = 0; i < len; i++ ) { - unsigned short uc = str[i].unicode(); - glyphs[i] = uc < cmapCacheSize ? cmapCache[uc] : 0; - if ( !glyphs[i] ) { - glyph_t glyph = FT_Get_Char_Index( _face, uc ); - glyphs[i] = glyph; - if ( uc < cmapCacheSize ) - ((TQFontEngineXft *)this)->cmapCache[uc] = glyph; - } - } - } - } - - if ( advances ) { - for ( int i = 0; i < len; i++ ) { - XftChar16 glyph = *(glyphs + i); - advances[i] = (glyph < widthCacheSize) ? widthCache[glyph] : 0; - if ( !advances[i] ) { - XGlyphInfo gi; - XftTextExtents16(TQPaintDevice::x11AppDisplay(), _font, &glyph, 1, &gi); - advances[i] = gi.xOff; - if ( glyph < widthCacheSize && gi.xOff > 0 && gi.xOff < 0x100 ) - ((TQFontEngineXft *)this)->widthCache[glyph] = gi.xOff; - } - } - if ( _scale != 1. ) { - for ( int i = 0; i < len; i++ ) - advances[i] = tqRound(advances[i]*_scale); - } - } -#endif // QT_XFT2 - - *nglyphs = len; - return NoError; -} - - -void TQFontEngineXft::recalcAdvances( int len, glyph_t *glyphs, advance_t *advances ) -{ - -#ifdef QT_XFT2 - for ( int i = 0; i < len; i++ ) { - FT_UInt glyph = *(glyphs + i); - advances[i] = (glyph < widthCacheSize) ? widthCache[glyph] : 0; - if ( !advances[i] ) { - XGlyphInfo gi; - XftGlyphExtents( TQPaintDevice::x11AppDisplay(), _font, &glyph, 1, &gi ); - advances[i] = gi.xOff; - if ( glyph < widthCacheSize && gi.xOff > 0 && gi.xOff < 0x100 ) - ((TQFontEngineXft *)this)->widthCache[glyph] = gi.xOff; - } - if ( _scale != 1. ) { - for ( int i = 0; i < len; i++ ) - advances[i] = tqRound(advances[i]*_scale); - } - } -#else - for ( int i = 0; i < len; i++ ) { - XftChar16 glyph = *(glyphs + i); - advances[i] = (glyph < widthCacheSize) ? widthCache[glyph] : 0; - if ( !advances[i] ) { - XGlyphInfo gi; - XftTextExtents16(TQPaintDevice::x11AppDisplay(), _font, &glyph, 1, &gi); - advances[i] = gi.xOff; - if ( glyph < widthCacheSize && gi.xOff > 0 && gi.xOff < 0x100 ) - ((TQFontEngineXft *)this)->widthCache[glyph] = gi.xOff; - } - } - if ( _scale != 1. ) { - for ( int i = 0; i < len; i++ ) - advances[i] = tqRound(advances[i]*_scale); - } -#endif // QT_XFT2 -} - -//#define FONTENGINE_DEBUG -void TQFontEngineXft::draw( TQPainter *p, int x, int y, const TQTextEngine *engine, const TQScriptItem *si, int textFlags ) -{ - if ( !si->num_glyphs ) - return; - - Display *dpy = TQPaintDevice::x11AppDisplay(); - - int xorig = x; - int yorig = y; - - GlyphAttributes *glyphAttributes = engine->glyphAttributes( si ); - - XftFont *fnt = _font; - bool transform = FALSE; - if ( p->txop >= TQPainter::TxScale || p->rop != TQt::CopyROP || _scale < 0.9999 || _scale > 1.001) { - bool can_scale = (_face->face_flags & FT_FACE_FLAG_SCALABLE) && p->rop == TQt::CopyROP; - double size = (p->m11()*p->m22() - p->m12()*p->m21())*_scale*_scale*fontDef.pixelSize*fontDef.pixelSize; - if (size > 256*256 || _scale < .9999 || _scale > 1.001) - can_scale = FALSE; - if (!can_scale) { - // font doesn't support transformations, need to do it by hand - float tmp = _scale; - _scale = 1.; - drawScaled(x, y, engine, si, textFlags, dpy, p->gc, p->device(), this, p->xmat, tmp); - _scale = tmp; - return; - } - - XftMatrix *mat = 0; - XftPatternGetMatrix( _pattern, XFT_MATRIX, 0, &mat ); - XftMatrix m2; - m2.xx = p->m11()*_scale; - m2.xy = -p->m21()*_scale; - m2.yx = -p->m12()*_scale; - m2.yy = p->m22()*_scale; - - // check if we have it cached - TransformedFont *trf = transformed_fonts; - TransformedFont *prev = 0; - int i = 0; - while ( trf ) { - if ( trf->xx == (float)m2.xx && - trf->xy == (float)m2.xy && - trf->yx == (float)m2.yx && - trf->yy == (float)m2.yy ) - break; - TransformedFont *tmp = trf; - trf = trf->next; - if (i > 10) { - XftFontClose( TQPaintDevice::x11AppDisplay(), tmp->xft_font ); - delete tmp; - prev->next = trf; - } else { - prev = tmp; - } - ++i; - } - if ( trf ) { - if ( prev ) { - // move to beginning of list - prev->next = trf->next; - trf->next = transformed_fonts; - transformed_fonts = trf; - } - fnt = trf->xft_font; - } else { - if ( mat ) - XftMatrixMultiply( &m2, &m2, mat ); - - XftPattern *pattern = XftPatternDuplicate( _pattern ); - XftPatternDel( pattern, XFT_MATRIX ); - XftPatternAddMatrix( pattern, XFT_MATRIX, &m2 ); - - fnt = XftFontOpenPattern( dpy, pattern ); -#ifndef QT_XFT2 - XftFontStruct *xftfs = getFontStruct( fnt ); - if ( xftfs ) { - // dirty hack: we set the charmap in the Xftfreetype to -1, so - // XftFreetype assumes no encoding and really draws glyph - // indices. The FT_Face still has the Unicode encoding to we - // can convert from Unicode to glyph index - xftfs->charmap = -1; - } -#endif // QT_XFT2 - TransformedFont *trf = new TransformedFont; - trf->xx = (float)m2.xx; - trf->xy = (float)m2.xy; - trf->yx = (float)m2.yx; - trf->yy = (float)m2.yy; - trf->xft_font = fnt; - trf->next = transformed_fonts; - transformed_fonts = trf; - } - transform = TRUE; - } else if ( p->txop == TQPainter::TxTranslate ) { - p->map( x, y, &x, &y ); - } - - glyph_t *glyphs = engine->glyphs( si ); - advance_t *advances = engine->advances( si ); - qoffset_t *offsets = engine->offsets( si ); - - const TQColor &pen = p->cpen.color(); - XftDraw *draw = ((Q_HackPaintDevice *)p->pdev)->xftDrawHandle(); - - XftColor col; - col.color.red = pen.red () | pen.red() << 8; - col.color.green = pen.green () | pen.green() << 8; - col.color.blue = pen.blue () | pen.blue() << 8; - col.color.alpha = 0xffff; - col.pixel = pen.pixel(); -#ifdef FONTENGINE_DEBUG - tqDebug("===== drawing %d glyphs reverse=%s ======", si->num_glyphs, si->analysis.bidiLevel % 2?"TRUE":"FALSE" ); - p->save(); - p->setBrush( TQt::white ); - glyph_metrics_t ci = boundingBox( glyphs, advances, offsets, si->num_glyphs ); - p->drawRect( x + ci.x, y + ci.y, ci.width, ci.height ); - p->drawRect( x + ci.x, y + 100 + ci.y, ci.width, ci.height ); - tqDebug("bounding rect=%d %d (%d/%d)", ci.x, ci.y, ci.width, ci.height ); - p->restore(); - int yp = y; - int xp = x; -#endif - - if ( textFlags != 0 ) - drawLines( p, this, yorig, xorig, si->width, textFlags ); - - - if ( si->isSpace ) - return; - - if ( transform || si->hasPositioning ) { - if ( si->analysis.bidiLevel % 2 ) { - int i = si->num_glyphs; - while( i-- ) { - int xp = x + offsets[i].x; - int yp = y + offsets[i].y; - if ( transform ) - p->map( xp, yp, &xp, &yp ); -#ifdef QT_XFT2 - FT_UInt glyph = *(glyphs + i); - if (!glyphAttributes[i].zeroWidth && xp < SHRT_MAX && xp > SHRT_MIN) - XftDrawGlyphs( draw, &col, fnt, xp, yp, &glyph, 1 ); -#else - if (!glyphAttributes[i].zeroWidth && xp < SHRT_MAX && xp > SHRT_MIN) - XftDrawString16( draw, &col, fnt, xp, yp, (XftChar16 *) (glyphs+i), 1); -#endif // QT_XFT2 -#ifdef FONTENGINE_DEBUG - glyph_metrics_t gi = boundingBox( glyphs[i] ); - p->drawRect( x+offsets[i].x+gi.x, y+offsets[i].y+100+gi.y, gi.width, gi.height ); - p->drawLine( x+offsets[i].x, y + 150 + 5*i , x+offsets[i].x+advances[i], y + 150 + 5*i ); - p->drawLine( x+offsets[i].x, y + 152 + 5*i , x+offsets[i].x+gi.xoff, y + 152 + 5*i ); - tqDebug("bounding ci[%d]=%d %d (%d/%d) / %d %d offs=(%d/%d) advance=%d", i, gi.x, gi.y, gi.width, gi.height, - gi.xoff, gi.yoff, offsets[i].x, offsets[i].y, advances[i]); -#endif - x += advances[i]; - } - } else { - int i = 0; - while ( i < si->num_glyphs ) { - int xp = x + offsets[i].x; - int yp = y + offsets[i].y; - if ( transform ) - p->map( xp, yp, &xp, &yp ); -#ifdef QT_XFT2 - FT_UInt glyph = *(glyphs + i); - if (!glyphAttributes[i].zeroWidth && xp < SHRT_MAX && xp > SHRT_MIN) - XftDrawGlyphs( draw, &col, fnt, xp, yp, &glyph, 1 ); -#else - if (!glyphAttributes[i].zeroWidth && xp < SHRT_MAX && xp > SHRT_MIN) - XftDrawString16( draw, &col, fnt, xp, yp, (XftChar16 *) (glyphs+i), 1 ); -#endif // QT_XFT2 - // tqDebug("advance = %d/%d", adv.x, adv.y ); - x += advances[i]; - i++; - } - } - } else { - // Xft has real trouble drawing the glyphs on their own. - // Drawing them as one string increases performance significantly. -#ifdef QT_XFT2 - // #### we should use a different method anyways on Xft2 - FT_UInt g[64]; - int gl = 0; - while (gl < si->num_glyphs) { - int toDraw = TQMIN(64, si->num_glyphs-gl); - int adv = 0; - if ( si->analysis.bidiLevel % 2 ) { - for ( int i = 0; i < toDraw; i++ ) { - g[i] = glyphs[si->num_glyphs-1-(gl+i)]; - adv += advances[si->num_glyphs-1-(gl+i)]; - } - } else { - for ( int i = 0; i < toDraw; i++ ) { - g[i] = glyphs[gl+i]; - adv += advances[gl+i]; - } - } - if (x + adv < SHRT_MAX && x > SHRT_MIN) - XftDrawGlyphs( draw, &col, fnt, x, y, g, toDraw ); - gl += toDraw; - x += adv; - } -#else - XftChar16 g[64]; - int gl = 0; - while (gl < si->num_glyphs) { - int toDraw = TQMIN(64, si->num_glyphs-gl); - int adv = 0; - if ( si->analysis.bidiLevel % 2 ) { - for ( int i = 0; i < toDraw; i++ ) { - g[i] = glyphs[si->num_glyphs-1-(gl+i)]; - adv += advances[si->num_glyphs-1-(gl+i)]; - } - } else { - for ( int i = 0; i < toDraw; i++ ) { - g[i] = glyphs[gl+i]; - adv += advances[gl+i]; - } - } - if (x + adv < SHRT_MAX && x > SHRT_MIN) - XftDrawString16( draw, &col, fnt, x, y, g, toDraw ); - gl += toDraw; - x += adv; - } -#endif // QT_XFT2 - } - -#ifdef FONTENGINE_DEBUG - if ( !si->analysis.bidiLevel % 2 ) { - x = xp; - y = yp; - p->save(); - p->setPen( TQt::red ); - for ( int i = 0; i < si->num_glyphs; i++ ) { - glyph_metrics_t ci = boundingBox( glyphs[i] ); - p->drawRect( x + ci.x + offsets[i].x, y + 100 + ci.y + offsets[i].y, ci.width, ci.height ); - tqDebug("bounding ci[%d]=%d %d (%d/%d) / %d %d offs=(%d/%d) advance=%d", i, ci.x, ci.y, ci.width, ci.height, - ci.xoff, ci.yoff, offsets[i].x, offsets[i].y, advances[i]); - x += advances[i]; - } - p->restore(); - } -#endif -} - -glyph_metrics_t TQFontEngineXft::boundingBox( const glyph_t *glyphs, const advance_t *advances, const qoffset_t *offsets, int numGlyphs ) -{ - XGlyphInfo xgi; - - glyph_metrics_t overall; - int ymax = 0; - int xmax = 0; - if (_scale != 1) { - for (int i = 0; i < numGlyphs; i++) { - getGlyphInfo( &xgi, _font, glyphs[i] ); - int x = overall.xoff + offsets[i].x - xgi.x; - int y = overall.yoff + offsets[i].y - xgi.y; - overall.x = TQMIN( overall.x, x ); - overall.y = TQMIN( overall.y, y ); - xmax = TQMAX( xmax, x + xgi.width ); - ymax = TQMAX( ymax, y + xgi.height ); - overall.xoff += tqRound(advances[i]/_scale); - } - overall.x = tqRound(overall.x * _scale); - overall.y = tqRound(overall.y * _scale); - overall.xoff = tqRound(overall.xoff * _scale); - overall.yoff = tqRound(overall.yoff * _scale); - xmax = tqRound(xmax * _scale); - ymax = tqRound(ymax * _scale); - } else { - for (int i = 0; i < numGlyphs; i++) { - getGlyphInfo( &xgi, _font, glyphs[i] ); - int x = overall.xoff + offsets[i].x - xgi.x; - int y = overall.yoff + offsets[i].y - xgi.y; - overall.x = TQMIN( overall.x, x ); - overall.y = TQMIN( overall.y, y ); - xmax = TQMAX( xmax, x + xgi.width ); - ymax = TQMAX( ymax, y + xgi.height ); - overall.xoff += advances[i]; - } - } - overall.height = ymax - overall.y; - overall.width = xmax - overall.x; - return overall; -} - -glyph_metrics_t TQFontEngineXft::boundingBox( glyph_t glyph ) -{ - XGlyphInfo xgi; - getGlyphInfo( &xgi, _font, glyph ); - glyph_metrics_t gm = glyph_metrics_t( -xgi.x, -xgi.y, xgi.width, xgi.height, xgi.xOff, -xgi.yOff ); - if ( _scale != 1. ) { - gm.x = tqRound(gm.x * _scale); - gm.y = tqRound(gm.y * _scale); - gm.height = tqRound(gm.height * _scale); - gm.width = tqRound(gm.width * _scale); - gm.xoff = tqRound(gm.xoff * _scale); - gm.yoff = tqRound(gm.yoff * _scale); - } - return gm; -} - - - -int TQFontEngineXft::ascent() const -{ - return tqRound(_font->ascent*_scale); -} - -int TQFontEngineXft::descent() const -{ - return tqRound((_font->descent-1)*_scale); -} - -// #### use Freetype to determine this -int TQFontEngineXft::leading() const -{ - int l = tqRound(TQMIN( _font->height - (_font->ascent + _font->descent), - ((_font->ascent + _font->descent) >> 4)*_scale )); - return (l > 0) ? l : 1; -} - -// #### use Freetype to determine this -int TQFontEngineXft::lineThickness() const -{ - // ad hoc algorithm - int score = fontDef.weight * fontDef.pixelSize; - int lw = score / 700; - - // looks better with thicker line for small pointsizes - if ( lw < 2 && score >= 1050 ) lw = 2; - if ( lw == 0 ) lw = 1; - - return lw; -} - -// #### use Freetype to determine this -int TQFontEngineXft::underlinePosition() const -{ - int pos = ( ( lineThickness() * 2 ) + 3 ) / 6; - return pos ? pos : 1; -} - -int TQFontEngineXft::maxCharWidth() const -{ - return tqRound(_font->max_advance_width*_scale); -} - -static const ushort char_table[] = { - 40, - 67, - 70, - 75, - 86, - 88, - 89, - 91, - 102, - 114, - 124, - 127, - 205, - 645, - 884, - 922, - 1070, - 12386 -}; - -static const int char_table_entries = sizeof(char_table)/sizeof(ushort); - - -int TQFontEngineXft::minLeftBearing() const -{ - if ( lbearing == SHRT_MIN ) - minRightBearing(); // calculates both - - return lbearing; -} - -int TQFontEngineXft::minRightBearing() const -{ - if ( rbearing == SHRT_MIN ) { - TQFontEngineXft *that = (TQFontEngineXft *)this; - that->lbearing = that->rbearing = 0; - TQChar *ch = (TQChar *)char_table; - glyph_t glyphs[char_table_entries]; - int ng = char_table_entries; - stringToCMap(ch, char_table_entries, glyphs, 0, &ng, FALSE); - while (--ng) { - if (glyphs[ng]) { - glyph_metrics_t gi = that->boundingBox( glyphs[ng] ); - if (gi.xoff) { - that->lbearing = TQMIN(lbearing, gi.x); - that->rbearing = TQMIN(rbearing, gi.xoff - gi.x - gi.width); - } - } - } - } - - return rbearing; -} - -int TQFontEngineXft::cmap() const -{ - return _cmap; -} - -const char *TQFontEngineXft::name() const -{ - return "xft"; -} - -void TQFontEngineXft::setScale( double scale ) -{ - _scale = scale; -} - -bool TQFontEngineXft::canRender( const TQChar *string, int len ) -{ - bool allExist = TRUE; - -#ifdef QT_XFT2 - if (_cmap != -1) { - for ( int i = 0; i < len; i++ ) { - if (!XftCharExists(0, _font, string[i].unicode()) - && getAdobeCharIndex(_font, _cmap, string[i].unicode()) == 0) { - allExist = FALSE; - break; - } - } - } else { - for ( int i = 0; i < len; i++ ) { - if (!XftCharExists(0, _font, string[i].unicode())) { - allExist = FALSE; - break; - } - } - } -#else - glyph_t glyphs[256]; - int nglyphs = 255; - glyph_t *g = glyphs; - if ( stringToCMap( string, len, g, 0, &nglyphs, FALSE ) == OutOfMemory ) { - g = (glyph_t *)malloc( nglyphs*sizeof(glyph_t) ); - stringToCMap( string, len, g, 0, &nglyphs, FALSE ); - } - - for ( int i = 0; i < nglyphs; i++ ) { - if ( !XftGlyphExists(TQPaintDevice::x11AppDisplay(), _font, g[i]) ) { - allExist = FALSE; - break; - } - } - - if ( g != glyphs ) - free( g ); -#endif // QT_XFT2 - - return allExist; -} - -TQOpenType *TQFontEngineXft::openType() const -{ -// tqDebug("openTypeIface requested!"); - if ( _openType ) - return _openType; - - if ( !_face || ! FT_IS_SFNT( _face ) ) - return 0; - - TQFontEngineXft *that = (TQFontEngineXft *)this; - that->_openType = new TQOpenType(that); - return _openType; -} - - -TQFontEngine::Type TQFontEngineXft::type() const -{ - return Xft; -} -#endif - - -// -------------------------------------------------------------------------------------------------------------------- -// Open type support -// -------------------------------------------------------------------------------------------------------------------- - -#ifndef TQT_NO_XFTFREETYPE - -#include "qscriptengine_p.h" - -//#define OT_DEBUG - -#ifdef OT_DEBUG -static inline char *tag_to_string(FT_ULong tag) -{ - static char string[5]; - string[0] = (tag >> 24)&0xff; - string[1] = (tag >> 16)&0xff; - string[2] = (tag >> 8)&0xff; - string[3] = tag&0xff; - string[4] = 0; - return string; -} -#endif - -#define DefaultLangSys 0xffff -#define DefaultScript FT_MAKE_TAG('D', 'F', 'L', 'T') - -enum { - RequiresGsub = 1, - RequiresGpos = 2 -}; - -struct OTScripts { - unsigned int tag; - int flags; -}; - -static const OTScripts ot_scripts [] = { -// // European Alphabetic Scripts -// Latin, - { FT_MAKE_TAG( 'l', 'a', 't', 'n' ), 0 }, -// Greek, - { FT_MAKE_TAG( 'g', 'r', 'e', 'k' ), 0 }, -// Cyrillic, - { FT_MAKE_TAG( 'c', 'y', 'r', 'l' ), 0 }, -// Armenian, - { FT_MAKE_TAG( 'a', 'r', 'm', 'n' ), 0 }, -// Georgian, - { FT_MAKE_TAG( 'g', 'e', 'o', 'r' ), 0 }, -// Runic, - { FT_MAKE_TAG( 'r', 'u', 'n', 'r' ), 0 }, -// Ogham, - { FT_MAKE_TAG( 'o', 'g', 'a', 'm' ), 0 }, -// SpacingModifiers, - { FT_MAKE_TAG( 'D', 'F', 'L', 'T' ), 0 }, -// CombiningMarks, - { FT_MAKE_TAG( 'D', 'F', 'L', 'T' ), 0 }, - -// // Middle Eastern Scripts -// Hebrew, - { FT_MAKE_TAG( 'h', 'e', 'b', 'r' ), 1 }, -// Arabic, - { FT_MAKE_TAG( 'a', 'r', 'a', 'b' ), 1 }, -// Syriac, - { FT_MAKE_TAG( 's', 'y', 'r', 'c' ), 1 }, -// Thaana, - { FT_MAKE_TAG( 't', 'h', 'a', 'a' ), 1 }, - -// // South and Southeast Asian Scripts -// Devanagari, - { FT_MAKE_TAG( 'd', 'e', 'v', 'a' ), 1 }, -// Bengali, - { FT_MAKE_TAG( 'b', 'e', 'n', 'g' ), 1 }, -// Gurmukhi, - { FT_MAKE_TAG( 'g', 'u', 'r', 'u' ), 1 }, -// Gujarati, - { FT_MAKE_TAG( 'g', 'u', 'j', 'r' ), 1 }, -// Oriya, - { FT_MAKE_TAG( 'o', 'r', 'y', 'a' ), 1 }, -// Tamil, - { FT_MAKE_TAG( 't', 'a', 'm', 'l' ), 1 }, -// Telugu, - { FT_MAKE_TAG( 't', 'e', 'l', 'u' ), 1 }, -// Kannada, - { FT_MAKE_TAG( 'k', 'n', 'd', 'a' ), 1 }, -// Malayalam, - { FT_MAKE_TAG( 'm', 'l', 'y', 'm' ), 1 }, -// Sinhala, - // ### could not find any OT specs on this - { FT_MAKE_TAG( 's', 'i', 'n', 'h' ), 1 }, -// Thai, - { FT_MAKE_TAG( 't', 'h', 'a', 'i' ), 1 }, -// Lao, - { FT_MAKE_TAG( 'l', 'a', 'o', ' ' ), 1 }, -// Tibetan, - { FT_MAKE_TAG( 't', 'i', 'b', 't' ), 1 }, -// Myanmar, - { FT_MAKE_TAG( 'm', 'y', 'm', 'r' ), 1 }, -// Khmer, - { FT_MAKE_TAG( 'k', 'h', 'm', 'r' ), 1 }, - -// // East Asian Scripts -// Han, - { FT_MAKE_TAG( 'h', 'a', 'n', 'i' ), 0 }, -// Hiragana, - { FT_MAKE_TAG( 'k', 'a', 'n', 'a' ), 0 }, -// Katakana, - { FT_MAKE_TAG( 'k', 'a', 'n', 'a' ), 0 }, -// Hangul, - { FT_MAKE_TAG( 'h', 'a', 'n', 'g' ), 1 }, -// Bopomofo, - { FT_MAKE_TAG( 'b', 'o', 'p', 'o' ), 0 }, -// Yi, - { FT_MAKE_TAG( 'y', 'i', ' ', ' ' ), 0 }, - -// // Additional Scripts -// Ethiopic, - { FT_MAKE_TAG( 'e', 't', 'h', 'i' ), 0 }, -// Cherokee, - { FT_MAKE_TAG( 'c', 'h', 'e', 'r' ), 0 }, -// CanadianAboriginal, - { FT_MAKE_TAG( 'c', 'a', 'n', 's' ), 0 }, -// Mongolian, - { FT_MAKE_TAG( 'm', 'o', 'n', 'g' ), 0 }, -// // Symbols -// CurrencySymbols, - { FT_MAKE_TAG( 'D', 'F', 'L', 'T' ), 0 }, -// LetterlikeSymbols, - { FT_MAKE_TAG( 'D', 'F', 'L', 'T' ), 0 }, -// NumberForms, - { FT_MAKE_TAG( 'D', 'F', 'L', 'T' ), 0 }, -// MathematicalOperators, - { FT_MAKE_TAG( 'D', 'F', 'L', 'T' ), 0 }, -// TechnicalSymbols, - { FT_MAKE_TAG( 'D', 'F', 'L', 'T' ), 0 }, -// GeometricSymbols, - { FT_MAKE_TAG( 'D', 'F', 'L', 'T' ), 0 }, -// MiscellaneousSymbols, - { FT_MAKE_TAG( 'D', 'F', 'L', 'T' ), 0 }, -// EnclosedAndSquare, - { FT_MAKE_TAG( 'D', 'F', 'L', 'T' ), 0 }, -// Braille, - { FT_MAKE_TAG( 'b', 'r', 'a', 'i' ), 0 }, -// Unicode, should be used - { FT_MAKE_TAG( 'D', 'F', 'L', 'T' ), 0 } - // ### where are these? -// { FT_MAKE_TAG( 'b', 'y', 'z', 'm' ), 0 }, -// { FT_MAKE_TAG( 'D', 'F', 'L', 'T' ), 0 }, - // ### Hangul Jamo -// { FT_MAKE_TAG( 'j', 'a', 'm', 'o' ), 0 }, -}; - -TQOpenType::TQOpenType(TQFontEngineXft *fe) - : fontEngine(fe), gdef(0), gsub(0), gpos(0), current_script(0) -{ - face = fe->face(); - otl_buffer_new(face->memory, &otl_buffer); - tmpAttributes = 0; - tmpLogClusters = 0; - - FT_Error error; - if ((error = TT_Load_GDEF_Table(face, &gdef))) { -#ifdef OT_DEBUG - tqDebug("error loading gdef table: %d", error); -#endif - gdef = 0; - } - - if ((error = TT_Load_GSUB_Table(face, &gsub, gdef))) { - gsub = 0; -#ifdef OT_DEBUG - if (error != FT_Err_Table_Missing) { - tqDebug("error loading gsub table: %d", error); - } else { - tqDebug("face doesn't have a gsub table"); - } -#endif - } - - if ((error = TT_Load_GPOS_Table(face, &gpos, gdef))) { - gpos = 0; -#ifdef OT_DEBUG - tqDebug("error loading gpos table: %d", error); -#endif - } - - for (uint i = 0; i < TQFont::NScripts; ++i) - supported_scripts[i] = checkScript(i); -} - -TQOpenType::~TQOpenType() -{ - if (gpos) - TT_Done_GPOS_Table(gpos); - if (gsub) - TT_Done_GSUB_Table(gsub); - if (gdef) - TT_Done_GDEF_Table(gdef); - if (otl_buffer) - otl_buffer_free(otl_buffer); - if (tmpAttributes) - free(tmpAttributes); - if (tmpLogClusters) - free(tmpLogClusters); -} - -bool TQOpenType::checkScript(unsigned int script) -{ - assert(script < TQFont::NScripts); - - uint tag = ot_scripts[script].tag; - int requirements = ot_scripts[script].flags; - - if (requirements & RequiresGsub) { - if (!gsub) - return FALSE; - - FT_UShort script_index; - FT_Error error = TT_GSUB_Select_Script(gsub, tag, &script_index); - if (error) { -#ifdef OT_DEBUG - tqDebug("could not select script %d in GSub table: %d", (int)script, error); -#endif - return FALSE; - } - } - - if (requirements & RequiresGpos) { - if (!gpos) - return FALSE; - - FT_UShort script_index; - FT_Error error = TT_GPOS_Select_Script(gpos, script, &script_index); - if (error) { -#ifdef OT_DEBUG - tqDebug("could not select script in gpos table: %d", error); -#endif - return FALSE; - } - - } - return TRUE; -} - - -void TQOpenType::selectScript(unsigned int script, const Features *features) -{ - if (current_script == script) - return; - - assert(script < TQFont::NScripts); - // find script in our list of supported scripts. - uint tag = ot_scripts[script].tag; - - if (gsub && features) { -#ifdef OT_DEBUG - { - TTO_FeatureList featurelist = gsub->FeatureList; - int numfeatures = featurelist.FeatureCount; - tqDebug("gsub table has %d features", numfeatures); - for(int i = 0; i < numfeatures; i++) { - TTO_FeatureRecord *r = featurelist.FeatureRecord + i; - tqDebug(" feature '%s'", tag_to_string(r->FeatureTag)); - } - } -#endif - TT_GSUB_Clear_Features(gsub); - FT_UShort script_index; - FT_Error error = TT_GSUB_Select_Script(gsub, tag, &script_index); - if (!error) { -#ifdef OT_DEBUG - tqDebug("script %s has script index %d", tag_to_string(script), script_index); -#endif - while (features->tag) { - FT_UShort feature_index; - error = TT_GSUB_Select_Feature(gsub, features->tag, script_index, 0xffff, &feature_index); - if (!error) { -#ifdef OT_DEBUG - tqDebug(" adding feature %s", tag_to_string(features->tag)); -#endif - TT_GSUB_Add_Feature(gsub, feature_index, features->property); - } - ++features; - } - } - } - - if (gpos) { - TT_GPOS_Clear_Features(gpos); - FT_UShort script_index; - FT_Error error = TT_GPOS_Select_Script(gpos, tag, &script_index); - if (!error) { -#ifdef OT_DEBUG - { - TTO_FeatureList featurelist = gpos->FeatureList; - int numfeatures = featurelist.FeatureCount; - tqDebug("gpos table has %d features", numfeatures); - for(int i = 0; i < numfeatures; i++) { - TTO_FeatureRecord *r = featurelist.FeatureRecord + i; - FT_UShort feature_index; - TT_GPOS_Select_Feature(gpos, r->FeatureTag, script_index, 0xffff, &feature_index); - tqDebug(" feature '%s'", tag_to_string(r->FeatureTag)); - } - } -#endif - FT_ULong *feature_tag_list; - error = TT_GPOS_Query_Features(gpos, script_index, 0xffff, &feature_tag_list); - if (!error) { - while (*feature_tag_list) { - FT_UShort feature_index; - error = TT_GPOS_Select_Feature(gpos, *feature_tag_list, script_index, 0xffff, &feature_index); - if (!error) - TT_GPOS_Add_Feature(gpos, feature_index, PositioningProperties); - ++feature_tag_list; - } - } - } - } - - current_script = script; -} - -#ifdef OT_DEBUG -static void dump_string(OTL_Buffer buffer) -{ - for (uint i = 0; i < buffer->in_length; ++i) { - tqDebug(" %x: cluster=%d", buffer->in_string[i].gindex, buffer->in_string[i].cluster); - } -} -#endif - -extern void qt_heuristicPosition(TQShaperItem *item); - -bool TQOpenType::shape(TQShaperItem *item, const unsigned int *properties) -{ - length = item->num_glyphs; - - otl_buffer_clear(otl_buffer); - - tmpAttributes = (GlyphAttributes *) realloc(tmpAttributes, length*sizeof(GlyphAttributes)); - tmpLogClusters = (unsigned int *) realloc(tmpLogClusters, length*sizeof(unsigned int)); - for (int i = 0; i < length; ++i) { - otl_buffer_add_glyph(otl_buffer, item->glyphs[i], properties ? properties[i] : 0, i); - tmpAttributes[i] = item->attributes[i]; - tmpLogClusters[i] = item->log_clusters[i]; - } - -#ifdef OT_DEBUG - tqDebug("-----------------------------------------"); -// tqDebug("log clusters before shaping:"); -// for (int j = 0; j < length; j++) -// tqDebug(" log[%d] = %d", j, item->log_clusters[j]); - tqDebug("original glyphs: %p", item->glyphs); - for (int i = 0; i < length; ++i) - tqDebug(" glyph=%4x", otl_buffer->in_string[i].gindex); -// dump_string(otl_buffer); -#endif - - loadFlags = FT_LOAD_DEFAULT; - - if (gsub) { - uint error = TT_GSUB_Apply_String(gsub, otl_buffer); - if (error && error != TTO_Err_Not_Covered) - return false; - } - -#ifdef OT_DEBUG -// tqDebug("log clusters before shaping:"); -// for (int j = 0; j < length; j++) -// tqDebug(" log[%d] = %d", j, item->log_clusters[j]); - tqDebug("shaped glyphs:"); - for (int i = 0; i < length; ++i) - tqDebug(" glyph=%4x", otl_buffer->in_string[i].gindex); - tqDebug("-----------------------------------------"); -// dump_string(otl_buffer); -#endif - - return true; -} - -bool TQOpenType::positionAndAdd(TQShaperItem *item, bool doLogClusters) -{ - if (gpos) { -#ifdef TQ_WS_X11 - Q_ASSERT(fontEngine->type() == TQFontEngine::Xft); - face = lockFTFace(static_cast(fontEngine)->font()); -#endif - memset(otl_buffer->positions, 0, otl_buffer->in_length*sizeof(OTL_PositionRec)); - // #### check that passing "FALSE,FALSE" is correct - TT_GPOS_Apply_String(face, gpos, loadFlags, otl_buffer, FALSE, FALSE); -#ifdef TQ_WS_X11 - unlockFTFace(static_cast(fontEngine)->font()); -#endif - } - - // make sure we have enough space to write everything back - if (item->num_glyphs < (int)otl_buffer->in_length) { - item->num_glyphs = otl_buffer->in_length; - return FALSE; - } - - for (unsigned int i = 0; i < otl_buffer->in_length; ++i) { - item->glyphs[i] = otl_buffer->in_string[i].gindex; - item->attributes[i] = tmpAttributes[otl_buffer->in_string[i].cluster]; - if (i && otl_buffer->in_string[i].cluster == otl_buffer->in_string[i-1].cluster) - item->attributes[i].clusterStart = FALSE; - } - item->num_glyphs = otl_buffer->in_length; - - if (doLogClusters) { - // we can't do this for indic, as we pass the stuf in syllables and it's easier to do it in the shaper. - unsigned short *logClusters = item->log_clusters; - int clusterStart = 0; - int oldCi = 0; - for (unsigned int i = 0; i < otl_buffer->in_length; ++i) { - int ci = otl_buffer->in_string[i].cluster; - // tqDebug(" ci[%d] = %d mark=%d, cmb=%d, cs=%d", - // i, ci, glyphAttributes[i].mark, glyphAttributes[i].combiningClass, glyphAttributes[i].clusterStart); - if (!item->attributes[i].mark && item->attributes[i].clusterStart && ci != oldCi) { - for (int j = oldCi; j < ci; j++) - logClusters[j] = clusterStart; - clusterStart = i; - oldCi = ci; - } - } - for (int j = oldCi; j < length; j++) - logClusters[j] = clusterStart; - } - - // calulate the advances for the shaped glyphs -// tqDebug("unpositioned: "); - static_cast(item->font)->recalcAdvances(item->num_glyphs, item->glyphs, item->advances); - - // positioning code: - if (gpos) { - float scale = item->font->scale(); - OTL_Position positions = otl_buffer->positions; - -// tqDebug("positioned glyphs:"); - for (unsigned int i = 0; i < otl_buffer->in_length; i++) { -// tqDebug(" %d:\t orig advance: (%d/%d)\tadv=(%d/%d)\tpos=(%d/%d)\tback=%d\tnew_advance=%d", i, -// glyphs[i].advance.x.toInt(), glyphs[i].advance.y.toInt(), -// (int)(positions[i].x_advance >> 6), (int)(positions[i].y_advance >> 6), -// (int)(positions[i].x_pos >> 6), (int)(positions[i].y_pos >> 6), -// positions[i].back, positions[i].new_advance); - // ###### fix the case where we have y advances. How do we handle this in Uniscribe????? - if (positions[i].new_advance) { - item->advances[i] = item->flags & TQTextEngine::RightToLeft - ? -tqRound((positions[i].x_advance >> 6)*scale) - : tqRound((positions[i].x_advance >> 6)*scale); - } else { - item->advances[i] += item->flags & TQTextEngine::RightToLeft - ? -tqRound((positions[i].x_advance >> 6)*scale) - : tqRound((positions[i].x_advance >> 6)*scale); - } - item->offsets[i].x = tqRound((positions[i].x_pos >> 6)*scale); - item->offsets[i].y = -tqRound((positions[i].y_pos >> 6)*scale); - int back = positions[i].back; - if (item->flags & TQTextEngine::RightToLeft) { - while (back--) { - item->offsets[i].x -= item->advances[i-back]; - } - } else { - while (back) { - item->offsets[i].x -= item->advances[i-back]; - --back; - } - } -// tqDebug(" ->\tadv=%d\tpos=(%d/%d)", -// glyphs[i].advance.x.toInt(), glyphs[i].offset.x.toInt(), glyphs[i].offset.y.toInt()); - } - item->has_positioning = TRUE; - } else { - qt_heuristicPosition(item); - } - -#ifdef OT_DEBUG -// if (doLogClusters) { -// tqDebug("log clusters after shaping:"); -// for (int j = 0; j < length; j++) -// tqDebug(" log[%d] = %d", j, item->log_clusters[j]); -// } - tqDebug("final glyphs:"); - for (int i = 0; i < (int)otl_buffer->in_length; ++i) - tqDebug(" glyph=%4x char_index=%d mark: %d cmp: %d, clusterStart: %d advance=%d offset=%d/%d", - item->glyphs[i], otl_buffer->in_string[i].cluster, item->attributes[i].mark, - item->attributes[i].combiningClass, item->attributes[i].clusterStart, - item->advances[i], - item->offsets[i].x, item->offsets[i].y); - tqDebug("-----------------------------------------"); -#endif - return TRUE; -} - -#endif diff --git a/src/kernel/qinternal.cpp b/src/kernel/qinternal.cpp index 389c7236c..a714333d9 100644 --- a/src/kernel/qinternal.cpp +++ b/src/kernel/qinternal.cpp @@ -41,7 +41,7 @@ #include "private/qinternal_p.h" #include "tqwidget.h" #include "ntqpixmap.h" -#include "ntqpainter.h" +#include "tqpainter.h" #include "ntqcleanuphandler.h" // Modern systems (year 2011) have very large screens in excess of 1000 pixels wide diff --git a/src/kernel/qmovie.cpp b/src/kernel/qmovie.cpp deleted file mode 100644 index a26f03d7f..000000000 --- a/src/kernel/qmovie.cpp +++ /dev/null @@ -1,1045 +0,0 @@ -/**************************************************************************** -** -** Implementation of movie classes -** -** Created : 970617 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -// #define QT_SAVE_MOVIE_HACK - -#include "tqtimer.h" -#include "ntqpainter.h" -#include "tqptrlist.h" -#include "tqbitmap.h" -#include "ntqmovie.h" -#include "tqfile.h" -#include "tqbuffer.h" -#include "tqobject.h" -#include "ntqpixmapcache.h" - -#ifndef TQT_NO_MOVIE - -#include "ntqasyncio.h" -#include "ntqasyncimageio.h" - -#include - -/*! - \class TQMovie ntqmovie.h - \brief The TQMovie class provides incremental loading of animations or images, signalling as it progresses. - - \ingroup images - \ingroup graphics - \ingroup multimedia - \mainclass - - The simplest way to display a TQMovie is to use a TQLabel and - TQLabel::setMovie(). - - A TQMovie provides a TQPixmap as the framePixmap(); connections can - be made via connectResize() and connectUpdate() to receive - notification of size and pixmap changes. All decoding is driven - by the normal event-processing mechanisms. - - The movie begins playing as soon as the TQMovie is created - (actually, once control returns to the event loop). When the last - frame in the movie has been played, it may loop back to the start - if such looping is defined in the input source. - - TQMovie objects are explicitly shared. This means that a TQMovie - copied from another TQMovie will be displaying the same frame at - all times. If one shared movie pauses, all pause. To make \e - independent movies, they must be constructed separately. - - The set of data formats supported by TQMovie is determined by the - decoder factories that have been installed; the format of the - input is determined as the input is decoded. - - The supported formats are MNG (if TQt is configured with MNG - support enabled) and GIF (if TQt is configured with GIF support - enabled, see ntqgif.h). - - If TQt is configured to support GIF reading, we are required to - state that "The Graphics Interchange Format(c) is the Copyright - property of CompuServe Incorporated. GIF(sm) is a Service Mark - property of CompuServe Incorporated. - - \warning If you are in a country that recognizes software patents - and in which Unisys holds a patent on LZW compression and/or - decompression and you want to use GIF, Unisys may require you to - license that technology. Such countries include Canada, Japan, - the USA, France, Germany, Italy and the UK. - - GIF support may be removed completely in a future version of TQt. - We recommend using the MNG or PNG format. - - \img qmovie.png TQMovie - - \sa TQLabel::setMovie() -*/ - -/*! - \enum TQMovie::Status - - \value SourceEmpty - \value UnrecognizedFormat - \value Paused - \value EndOfFrame - \value EndOfLoop - \value EndOfMovie - \value SpeedChanged -*/ - -class TQMoviePrivate : public TQObject, public TQShared, - private TQDataSink, private TQImageConsumer -{ - TQ_OBJECT - -public: // for TQMovie - - // Creates a null Private - TQMoviePrivate(); - - // NOTE: The ownership of the TQDataSource is transferred to the Private - TQMoviePrivate(TQDataSource* src, TQMovie* movie, int bufsize); - - virtual ~TQMoviePrivate(); - - bool isNull() const; - - // Initialize, possibly to the null state - void init(bool fully); - void flushBuffer(); - void updatePixmapFromImage(); - void updatePixmapFromImage(const TQPoint& off, const TQRect& area); - void showChanges(); - - // This as TQImageConsumer - void changed(const TQRect& rect); - void end(); - void preFrameDone(); //util func - void frameDone(); - void frameDone(const TQPoint&, const TQRect& rect); - void restartTimer(); - void setLooping(int l); - void setFramePeriod(int milliseconds); - void setSize(int w, int h); - - // This as TQDataSink - int readyToReceive(); - void receive(const uchar* b, int bytecount); - void eof(); - void pause(); - -signals: - void sizeChanged(const TQSize&); - void areaChanged(const TQRect&); - void dataStatus(int); - -public slots: - void refresh(); - -public: - TQMovie *that; - TQWidget * display_widget; - - TQImageDecoder *decoder; - - // Cyclic buffer - int buf_size; - uchar *buffer; - int buf_r, buf_w, buf_usage; - - int framenumber; - int frameperiod; - int speed; - TQTimer *frametimer; - int lasttimerinterval; - int loop; - bool movie_ended; - bool dirty_cache; - bool waitingForFrameTick; - int stepping; - TQRect changed_area; - TQRect valid_area; - TQDataPump *pump; - TQDataSource *source; - TQPixmap mypixmap; - TQBitmap mymask; - TQColor bg; - - int error; - bool empty; - -#ifdef QT_SAVE_MOVIE_HACK - bool save_image; - int image_number; -#endif -}; - - -TQMoviePrivate::TQMoviePrivate() -{ - dirty_cache = FALSE; - buffer = 0; - pump = 0; - source = 0; - decoder = 0; - display_widget=0; - buf_size = 0; - init(FALSE); -} - -// NOTE: The ownership of the TQDataSource is transferred to the Private -TQMoviePrivate::TQMoviePrivate(TQDataSource* src, TQMovie* movie, int bufsize) : - that(movie), - buf_size(bufsize) -{ - frametimer = new TQTimer(this); - pump = src ? new TQDataPump(src, this) : 0; - TQObject::connect(frametimer, TQ_SIGNAL(timeout()), this, TQ_SLOT(refresh())); - dirty_cache = FALSE; - source = src; - buffer = 0; - decoder = 0; - speed = 100; - display_widget=0; - init(TRUE); -} - -TQMoviePrivate::~TQMoviePrivate() -{ - if ( buffer ) // Avoid purify complaint - delete [] buffer; - delete pump; - delete decoder; - delete source; - - // Too bad.. but better be safe than sorry - if ( dirty_cache ) - TQPixmapCache::clear(); -} - -bool TQMoviePrivate::isNull() const -{ - return !buf_size; -} - -// Initialize. Only actually allocate any space if \a fully is TRUE, -// otherwise, just enough to be a valid null Private. -void TQMoviePrivate::init(bool fully) -{ -#ifdef QT_SAVE_MOVIE_HACK - save_image = TRUE; - image_number = 0; -#endif - - buf_usage = buf_r = buf_w = 0; - if ( buffer ) // Avoid purify complaint - delete [] buffer; - buffer = fully ? new uchar[buf_size] : 0; - if ( buffer ) - memset( buffer, 0, buf_size ); - - delete decoder; - decoder = fully ? new TQImageDecoder(this) : 0; - -#ifdef AVOID_OPEN_FDS - if ( source && !source->isOpen() ) - source->open(IO_ReadOnly); -#endif - - waitingForFrameTick = FALSE; - stepping = -1; - framenumber = 0; - frameperiod = -1; - if (fully) frametimer->stop(); - lasttimerinterval = -1; - changed_area.setRect(0,0,-1,-1); - valid_area = changed_area; - loop = -1; - movie_ended = FALSE; - error = 0; - empty = TRUE; -} - -void TQMoviePrivate::flushBuffer() -{ - int used; - while (buf_usage && !waitingForFrameTick && stepping != 0 && !error) { - used = decoder->decode(buffer + buf_r, TQMIN(buf_usage, buf_size - buf_r)); - if (used <= 0) { - if ( used < 0 ) { - error = 1; - emit dataStatus(TQMovie::UnrecognizedFormat); - } - break; - } - buf_r = (buf_r + used) % buf_size; - buf_usage -= used; - } - - // Some formats, like MNG, can make stuff happen without any extra data. - // Only do this if the movie hasn't ended, however or we'll never get the end of loop signal. - if (!movie_ended) { - used = decoder->decode(buffer + buf_r, 0); - if (used <= 0) { - if ( used < 0 ) { - error = 1; - emit dataStatus(TQMovie::UnrecognizedFormat); - } - } - } - - if (error) - frametimer->stop(); - maybeReady(); -} - -void TQMoviePrivate::updatePixmapFromImage() -{ - if (changed_area.isEmpty()) return; - updatePixmapFromImage(TQPoint(0,0),changed_area); -} - -void TQMoviePrivate::updatePixmapFromImage(const TQPoint& off, - const TQRect& area) -{ - // Create temporary TQImage to hold the part we want - const TQImage& gimg = decoder->image(); - TQImage img = gimg.copy(area); - -#ifdef QT_SAVE_MOVIE_HACK - if ( save_image ) { - TQString name; - name.sprintf("movie%i.ppm",image_number++); - gimg.save( name, "PPM" ); - } -#endif - - // Resize to size of image - if (mypixmap.width() != gimg.width() || mypixmap.height() != gimg.height()) - mypixmap.resize(gimg.width(), gimg.height()); - - // Convert to pixmap and paste that onto myself - TQPixmap lines; - -#ifndef TQT_NO_SPRINTF - if (!(frameperiod < 0 && loop == -1)) { - // its an animation, lets see if we converted - // this frame already. - TQString key; - key.sprintf( "%08lx:%04d", ( long )this, framenumber ); - if ( !TQPixmapCache::find( key, lines ) ) { - lines.convertFromImage(img, TQt::ColorOnly); - TQPixmapCache::insert( key, lines ); - dirty_cache = TRUE; - } - } else -#endif - { - lines.convertFromImage(img, TQt::ColorOnly); - } - - if (bg.isValid()) { - TQPainter p; - p.begin(&mypixmap); - p.fillRect(area, bg); - p.drawPixmap(area, lines); - p.end(); - } else { - if (gimg.hasAlphaBuffer()) { - // Resize to size of image - if (mymask.isNull()) { - mymask.resize(gimg.width(), gimg.height()); - mymask.fill( TQt::color1 ); - } - } - mypixmap.setMask(TQBitmap()); // Remove reference to my mask - copyBlt( &mypixmap, area.left(), area.top(), - &lines, off.x(), off.y(), area.width(), area.height() ); - } -} - -void TQMoviePrivate::showChanges() -{ - if (changed_area.isValid()) { - updatePixmapFromImage(); - - valid_area = valid_area.unite(changed_area); - emit areaChanged(changed_area); - - changed_area.setWidth(-1); // make empty - } -} - -// Private as TQImageConsumer -void TQMoviePrivate::changed(const TQRect& rect) -{ - if (!frametimer->isActive()) - frametimer->start(0); - changed_area = changed_area.unite(rect); -} - -void TQMoviePrivate::end() -{ - movie_ended = TRUE; -} - -void TQMoviePrivate::preFrameDone() -{ - if (stepping > 0) { - stepping--; - if (!stepping) { - frametimer->stop(); - emit dataStatus( TQMovie::Paused ); - } - } else { - waitingForFrameTick = TRUE; - restartTimer(); - } -} -void TQMoviePrivate::frameDone() -{ - preFrameDone(); - showChanges(); - emit dataStatus(TQMovie::EndOfFrame); - framenumber++; -} -void TQMoviePrivate::frameDone(const TQPoint& p, - const TQRect& rect) -{ - preFrameDone(); - const TQImage& gimg = decoder->image(); - TQPoint point = p - gimg.offset(); - if (framenumber==0) - emit sizeChanged(gimg.size()); - valid_area = valid_area.unite(TQRect(point,rect.size())); - updatePixmapFromImage(point,rect); - emit areaChanged(TQRect(point,rect.size())); - emit dataStatus(TQMovie::EndOfFrame); - framenumber++; -} - -void TQMoviePrivate::restartTimer() -{ - if (speed > 0) { - int i = frameperiod >= 0 ? frameperiod * 100/speed : 0; - if ( i != lasttimerinterval || !frametimer->isActive() ) { - lasttimerinterval = i; - frametimer->start( i ); - } - } else { - frametimer->stop(); - } -} - -void TQMoviePrivate::setLooping(int nloops) -{ - if (loop == -1) { // Only if we don't already know how many loops! - if (source && source->rewindable()) { - source->enableRewind(TRUE); - loop = nloops; - } else { - // Cannot loop from this source - loop = -2; - } - } -} - -void TQMoviePrivate::setFramePeriod(int milliseconds) -{ - // Animation: only show complete frame - frameperiod = milliseconds; - if (stepping<0 && frameperiod >= 0) restartTimer(); -} - -void TQMoviePrivate::setSize(int w, int h) -{ - if (mypixmap.width() != w || mypixmap.height() != h) { - mypixmap.resize(w, h); - emit sizeChanged(TQSize(w, h)); - } -} - - -// Private as TQDataSink - -int TQMoviePrivate::readyToReceive() -{ - // Could pre-fill buffer, but more efficient to just leave the - // data back at the source. - return (waitingForFrameTick || !stepping || buf_usage || error) - ? 0 : buf_size; -} - -void TQMoviePrivate::receive(const uchar* b, int bytecount) -{ - if ( bytecount ) empty = FALSE; - - while (bytecount && !waitingForFrameTick && stepping != 0) { - int used = decoder->decode(b, bytecount); - if (used<=0) { - if ( used < 0 ) { - error = 1; - emit dataStatus(TQMovie::UnrecognizedFormat); - } - break; - } - b+=used; - bytecount-=used; - } - - // Append unused to buffer - while (bytecount--) { - buffer[buf_w] = *b++; - buf_w = (buf_w+1)%buf_size; - buf_usage++; - } -} - -void TQMoviePrivate::eof() -{ - if ( !movie_ended ) - return; - - if ( empty ) - emit dataStatus(TQMovie::SourceEmpty); - -#ifdef QT_SAVE_MOVIE_HACK - save_image = FALSE; -#endif - - emit dataStatus(TQMovie::EndOfLoop); - - if (loop >= 0) { - if (loop) { - loop--; - if (!loop) return; - } - delete decoder; - decoder = new TQImageDecoder(this); - source->rewind(); - framenumber = 0; - movie_ended = FALSE; - } else { - delete decoder; - decoder = 0; - if ( buffer ) // Avoid purify complaint - delete [] buffer; - buffer = 0; - emit dataStatus(TQMovie::EndOfMovie); -#ifdef AVOID_OPEN_FDS - if ( source ) - source->close(); -#endif - } -} - -void TQMoviePrivate::pause() -{ - if ( stepping ) { - stepping = 0; - frametimer->stop(); - emit dataStatus( TQMovie::Paused ); - } -} - -void TQMoviePrivate::refresh() -{ - if (!decoder) { - frametimer->stop(); - return; - } - - if (frameperiod < 0 && loop == -1) { - // Only show changes if probably not an animation - showChanges(); - } - - if (!buf_usage) { - frametimer->stop(); - } - - waitingForFrameTick = FALSE; - flushBuffer(); -} - -///////////////// End of Private ///////////////// - - - - - -/*! - Constructs a null TQMovie. The only interesting thing to do with - such a movie is to assign another movie to it. - - \sa isNull() -*/ -TQMovie::TQMovie() -{ - d = new TQMoviePrivate(); -} - -/*! - Constructs a TQMovie with an external data source. You should later - call pushData() to send incoming animation data to the movie. - - The \a bufsize argument sets the maximum amount of data the movie - will transfer from the data source per event loop. The lower this - value, the better interleaved the movie playback will be with - other event processing, but the slower the overall processing will - be. - - \sa pushData() -*/ -TQMovie::TQMovie(int bufsize) -{ - d = new TQMoviePrivate(0, this, bufsize); -} - -/*! - Returns the maximum amount of data that can currently be pushed - into the movie by a call to pushData(). This is affected by the - initial buffer size, but varies as the movie plays and data is - consumed. -*/ -int TQMovie::pushSpace() const -{ - return d->readyToReceive(); -} - -/*! - Pushes \a length bytes from \a data into the movie. \a length must - be no more than the amount returned by pushSpace() since the - previous call to pushData(). -*/ -void TQMovie::pushData(const uchar* data, int length) -{ - d->receive(data,length); -} - -/*! - Constructs a TQMovie that reads an image sequence from the given - data source, \a src. The source must be allocated dynamically, - because TQMovie will take ownership of it and will destroy it when - the movie is destroyed. The movie starts playing as soon as event - processing continues. - - The \a bufsize argument sets the maximum amount of data the movie - will transfer from the data source per event loop. The lower this - value, the better interleaved the movie playback will be with - other event processing, but the slower the overall processing will - be. -*/ -TQMovie::TQMovie(TQDataSource* src, int bufsize) -{ - d = new TQMoviePrivate(src, this, bufsize); -} - -/*! - Constructs a TQMovie that reads an image sequence from the file, \a - fileName. - - The \a bufsize argument sets the maximum amount of data the movie - will transfer from the data source per event loop. The lower this - value, the better interleaved the movie playback will be with - other event processing, but the slower the overall processing will - be. -*/ -TQMovie::TQMovie(const TQString &fileName, int bufsize) -{ - TQFile* file = new TQFile(fileName); - if ( !fileName.isEmpty() ) - file->open(IO_ReadOnly); - d = new TQMoviePrivate(new TQIODeviceSource(file, bufsize), this, bufsize); -} - -/*! - Constructs a TQMovie that reads an image sequence from the byte - array, \a data. - - The \a bufsize argument sets the maximum amount of data the movie - will transfer from the data source per event loop. The lower this - value, the better interleaved the movie playback will be with - other event processing, but the slower the overall processing will - be. -*/ -TQMovie::TQMovie(TQByteArray data, int bufsize) -{ - TQBuffer* buffer = new TQBuffer(data); - buffer->open(IO_ReadOnly); - d = new TQMoviePrivate(new TQIODeviceSource(buffer, bufsize), this, bufsize); -} - -/*! - Constructs a movie that uses the same data as movie \a movie. - TQMovies use explicit sharing, so operations on the copy will - affect both. -*/ -TQMovie::TQMovie(const TQMovie& movie) -{ - d = movie.d; - d->ref(); -} - -/*! - Destroys the TQMovie. If this is the last reference to the data of - the movie, the data is deallocated. -*/ -TQMovie::~TQMovie() -{ - if (d->deref()) delete d; -} - -/*! - Returns TRUE if the movie is null; otherwise returns FALSE. -*/ -bool TQMovie::isNull() const -{ - return d->isNull(); -} - -/*! - Makes this movie use the same data as movie \a movie. TQMovies use - explicit sharing. -*/ -TQMovie& TQMovie::operator=(const TQMovie& movie) -{ - movie.d->ref(); - if (d->deref()) delete d; - d = movie.d; - return *this; -} - - -/*! - Sets the background color of the pixmap to \a c. If the background - color isValid(), the pixmap will never have a mask because the - background color will be used in transparent regions of the image. - - \sa backgroundColor() -*/ -void TQMovie::setBackgroundColor(const TQColor& c) -{ - d->bg = c; -} - -/*! - Returns the background color of the movie set by - setBackgroundColor(). -*/ -const TQColor& TQMovie::backgroundColor() const -{ - return d->bg; -} - -/*! - Returns the area of the pixmap for which pixels have been - generated. -*/ -const TQRect& TQMovie::getValidRect() const -{ - return d->valid_area; -} - -/*! - Returns the current frame of the movie, as a TQPixmap. It is not - generally useful to keep a copy of this pixmap. It is better to - keep a copy of the TQMovie and get the framePixmap() only when - needed for drawing. - - \sa frameImage() -*/ -const TQPixmap& TQMovie::framePixmap() const -{ - return d->mypixmap; -} - -/*! - Returns the current frame of the movie, as a TQImage. It is not - generally useful to keep a copy of this image. Also note that you - must not call this function if the movie is finished(), since by - then the image will not be available. - - \sa framePixmap() -*/ -const TQImage& TQMovie::frameImage() const -{ - return d->decoder->image(); -} - -/*! - Returns the number of steps remaining after a call to step(). If - the movie is paused, steps() returns 0. If it's running normally - or is finished, steps() returns a negative number. -*/ -int TQMovie::steps() const -{ - return d->stepping; -} - -/*! - Returns the number of times EndOfFrame has been emitted since the - start of the current loop of the movie. Thus, before any - EndOfFrame has been emitted the value will be 0; within slots - processing the first signal, frameNumber() will be 1, and so on. -*/ -int TQMovie::frameNumber() const { return d->framenumber; } - -/*! - Returns TRUE if the image is paused; otherwise returns FALSE. -*/ -bool TQMovie::paused() const -{ - return d->stepping == 0; -} - -/*! - Returns TRUE if the image is no longer playing: this happens when - all loops of all frames are complete; otherwise returns FALSE. -*/ -bool TQMovie::finished() const -{ - return !d->decoder; -} - -/*! - Returns TRUE if the image is not single-stepping, not paused, and - not finished; otherwise returns FALSE. -*/ -bool TQMovie::running() const -{ - return d->stepping<0 && d->decoder; -} - -/*! - Pauses the progress of the animation. - - \sa unpause() -*/ -void TQMovie::pause() -{ - d->pause(); -} - -/*! - Unpauses the progress of the animation. - - \sa pause() -*/ -void TQMovie::unpause() -{ - if ( d->stepping >= 0 ) { - if (d->isNull()) - return; - d->stepping = -1; - d->restartTimer(); - } -} - -/*! - \overload - - Steps forward, showing \a steps frames, and then pauses. -*/ -void TQMovie::step(int steps) -{ - if (d->isNull()) - return; - d->stepping = steps; - d->frametimer->start(0); - d->waitingForFrameTick = FALSE; // Full speed ahead! -} - -/*! - Steps forward 1 frame and then pauses. -*/ -void TQMovie::step() -{ - step(1); -} - -/*! - Rewinds the movie to the beginning. If the movie has not been - paused, it begins playing again. -*/ -void TQMovie::restart() -{ - if (d->isNull()) - return; - if (d->source->rewindable()) { - d->source->enableRewind(TRUE); - d->source->rewind(); - int s = d->stepping; - d->init(TRUE); - if ( s>0 ) - step(s); - else if ( s==0 ) - pause(); - } -} - -/*! - Returns the movie's play speed as a percentage. The default is 100 - percent. - - \sa setSpeed() -*/ -int TQMovie::speed() const -{ - return d->speed; -} - -/*! - Sets the movie's play speed as a percentage, to \a percent. This - is a percentage of the speed dictated by the input data format. - The default is 100 percent. -*/ -void TQMovie::setSpeed(int percent) -{ - int oldspeed = d->speed; - if ( oldspeed != percent && percent >= 0 ) { - d->speed = percent; - // Restart timer only if really needed - if (d->stepping < 0) { - if ( !percent || !oldspeed // To or from zero - || oldspeed*4 / percent > 4 // More than 20% slower - || percent*4 / oldspeed > 4 // More than 20% faster - ) - d->restartTimer(); - } - } -} - -/*! - Connects the \a{receiver}'s \a member of type \c{void member(const - TQSize&)} so that it is signalled when the movie changes size. - - Note that due to the explicit sharing of TQMovie objects, these - connections persist until they are explicitly disconnected with - disconnectResize() or until \e every shared copy of the movie is - deleted. -*/ -void TQMovie::connectResize(TQObject* receiver, const char *member) -{ - TQObject::connect(d, TQ_SIGNAL(sizeChanged(const TQSize&)), receiver, member); -} - -/*! - Disconnects the \a{receiver}'s \a member (or all members if \a - member is zero) that were previously connected by connectResize(). -*/ -void TQMovie::disconnectResize(TQObject* receiver, const char *member) -{ - TQObject::disconnect(d, TQ_SIGNAL(sizeChanged(const TQSize&)), receiver, member); -} - -/*! - Connects the \a{receiver}'s \a member of type \c{void member(const - TQRect&)} so that it is signalled when an area of the framePixmap() - has changed since the previous frame. - - Note that due to the explicit sharing of TQMovie objects, these - connections persist until they are explicitly disconnected with - disconnectUpdate() or until \e every shared copy of the movie is - deleted. -*/ -void TQMovie::connectUpdate(TQObject* receiver, const char *member) -{ - TQObject::connect(d, TQ_SIGNAL(areaChanged(const TQRect&)), receiver, member); -} - -/*! - Disconnects the \a{receiver}'s \a member (or all members if \q - member is zero) that were previously connected by connectUpdate(). -*/ -void TQMovie::disconnectUpdate(TQObject* receiver, const char *member) -{ - TQObject::disconnect(d, TQ_SIGNAL(areaChanged(const TQRect&)), receiver, member); -} - -/*! - Connects the \a{receiver}'s \a member, of type \c{void - member(int)} so that it is signalled when the movie changes - status. The status codes are negative for errors and positive for - information. - - \table - \header \i Status Code \i Meaning - \row \i TQMovie::SourceEmpty - \i signalled if the input cannot be read. - \row \i TQMovie::UnrecognizedFormat - \i signalled if the input data is unrecognized. - \row \i TQMovie::Paused - \i signalled when the movie is paused by a call to paused() - or by after \link step() stepping \endlink pauses. - \row \i TQMovie::EndOfFrame - \i signalled at end-of-frame after any update and Paused signals. - \row \i TQMovie::EndOfLoop - \i signalled at end-of-loop, after any update signals, - EndOfFrame - but before EndOfMovie. - \row \i TQMovie::EndOfMovie - \i signalled when the movie completes and is not about to loop. - \endtable - - More status messages may be added in the future, so a general test - for errors would test for negative. - - Note that due to the explicit sharing of TQMovie objects, these - connections persist until they are explicitly disconnected with - disconnectStatus() or until \e every shared copy of the movie is - deleted. -*/ -void TQMovie::connectStatus(TQObject* receiver, const char *member) -{ - TQObject::connect(d, TQ_SIGNAL(dataStatus(int)), receiver, member); -} - -/*! - Disconnects the \a{receiver}'s \a member (or all members if \a - member is zero) that were previously connected by connectStatus(). -*/ -void TQMovie::disconnectStatus(TQObject* receiver, const char *member) -{ - TQObject::disconnect(d, TQ_SIGNAL(dataStatus(int)), receiver, member); -} - - -#include "qmovie.moc" - -#endif // TQT_NO_MOVIE diff --git a/src/kernel/qpaintdevice_x11.cpp b/src/kernel/qpaintdevice_x11.cpp deleted file mode 100644 index d40d09ba2..000000000 --- a/src/kernel/qpaintdevice_x11.cpp +++ /dev/null @@ -1,1173 +0,0 @@ -/**************************************************************************** -** -** Implementation of TQPaintDevice class for X11 -** -** Created : 940721 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#include "ntqpaintdevice.h" -#include "ntqpaintdevicemetrics.h" -#include "ntqpainter.h" -#include "tqwidget.h" -#include "tqbitmap.h" -#include "ntqapplication.h" -#include "qt_x11_p.h" - - -/*! - \class TQPaintDevice ntqpaintdevice.h - \brief The TQPaintDevice class is the base class of objects that - can be painted. - - \ingroup graphics - \ingroup images - - A paint device is an abstraction of a two-dimensional space that - can be drawn using a TQPainter. The drawing capabilities are - implemented by the subclasses TQWidget, TQPixmap, TQPicture and - TQPrinter. - - The default coordinate system of a paint device has its origin - located at the top-left position. X increases to the right and Y - increases downward. The unit is one pixel. There are several ways - to set up a user-defined coordinate system using the painter, for - example, using TQPainter::setWorldMatrix(). - - Example (draw on a paint device): - \code - void MyWidget::paintEvent( TQPaintEvent * ) - { - TQPainter p; // our painter - p.begin( this ); // start painting the widget - p.setPen( red ); // red outline - p.setBrush( yellow ); // yellow fill - p.drawEllipse( 10, 20, 100,100 ); // 100x100 ellipse at position (10, 20) - p.end(); // painting done - } - \endcode - - The bit block transfer is an extremely useful operation for - copying pixels from one paint device to another (or to itself). It - is implemented as the global function bitBlt(). - - Example (scroll widget contents 10 pixels to the right): - \code - bitBlt( myWidget, 10, 0, myWidget ); - \endcode - - \warning TQt requires that a TQApplication object exists before - any paint devices can be created. Paint devices access window - system resources, and these resources are not initialized before - an application object is created. -*/ - - -// -// Some global variables - these are initialized by TQColor::initialize() -// - -Display *TQPaintDevice::x_appdisplay = 0; -int TQPaintDevice::x_appscreen; - -int TQPaintDevice::x_appdepth; -int TQPaintDevice::x_appcells; -TQt::HANDLE TQPaintDevice::x_approotwindow; -TQt::HANDLE TQPaintDevice::x_appcolormap; -bool TQPaintDevice::x_appdefcolormap; -void *TQPaintDevice::x_appvisual; -bool TQPaintDevice::x_appdefvisual; - -// ### in 4.0, remove the above, and use the below -int *TQPaintDevice::x_appdepth_arr; -int *TQPaintDevice::x_appcells_arr; -TQt::HANDLE *TQPaintDevice::x_approotwindow_arr; -TQt::HANDLE *TQPaintDevice::x_appcolormap_arr; -bool *TQPaintDevice::x_appdefcolormap_arr; -void **TQPaintDevice::x_appvisual_arr; -bool *TQPaintDevice::x_appdefvisual_arr; - -/*! - \enum TQPaintDevice::PDevCmd - \internal -*/ - -/*! - Constructs a paint device with internal flags \a devflags. This - constructor can be invoked only from TQPaintDevice subclasses. -*/ - -TQPaintDevice::TQPaintDevice( uint devflags ) -{ - if ( !tqApp ) { // global constructor -#if defined(QT_CHECK_STATE) - tqFatal( "TQPaintDevice: Must construct a TQApplication before a " - "TQPaintDevice" ); -#endif - return; - } - devFlags = devflags; - painters = 0; - hd = 0; - rendhd = 0; - x11Data = 0; -} - -/*! - Destroys the paint device and frees window system resources. -*/ - -TQPaintDevice::~TQPaintDevice() -{ -#if defined(QT_CHECK_STATE) - if ( paintingActive() ) - tqWarning( "TQPaintDevice: Cannot destroy paint device that is being " - "painted" ); -#endif - if ( x11Data && x11Data->deref() ) { - delete x11Data; - x11Data = 0; - } -} - - -/* - \internal - Makes a shallow copy of the X11-specific data of \a fromDevice, if it is not - null. Otherwise this function sets it to null. -*/ - -void TQPaintDevice::copyX11Data( const TQPaintDevice *fromDevice ) -{ - setX11Data( fromDevice ? fromDevice->x11Data : 0 ); -} - -/* - \internal - Makes a deep copy of the X11-specific data of \a fromDevice, if it is not - null. Otherwise this function sets it to null. -*/ - -void TQPaintDevice::cloneX11Data( const TQPaintDevice *fromDevice ) -{ - if ( fromDevice && fromDevice->x11Data ) { - TQPaintDeviceX11Data *d = new TQPaintDeviceX11Data; - *d = *fromDevice->x11Data; - d->count = 0; - setX11Data( d ); - } else { - setX11Data( 0 ); - } -} - -/* - \internal - Makes a shallow copy of the X11-specific data \a d and assigns it to this - class. This function increments the reference code of \a d. -*/ - -void TQPaintDevice::setX11Data( const TQPaintDeviceX11Data* d ) -{ - if ( x11Data && x11Data->deref() ) - delete x11Data; - x11Data = (TQPaintDeviceX11Data*)d; - if ( x11Data ) - x11Data->ref(); -} - - -/* - \internal - If \a def is FALSE, returns a deep copy of the x11Data, or 0 if x11Data is 0. - If \a def is TRUE, makes a TQPaintDeviceX11Data struct filled with the default - values. - - In either case the caller is responsible for deleting the returned - struct. But notice that the struct is a shared class, so other - classes might also have a reference to it. The reference count of - the returned TQPaintDeviceX11Data* is 0. -*/ - -TQPaintDeviceX11Data* TQPaintDevice::getX11Data( bool def ) const -{ - TQPaintDeviceX11Data* res = 0; - if ( def ) { - res = new TQPaintDeviceX11Data; - res->x_display = x11AppDisplay(); - res->x_screen = x11AppScreen(); - res->x_depth = x11AppDepth(); - res->x_cells = x11AppCells(); - res->x_colormap = x11Colormap(); - res->x_defcolormap = x11AppDefaultColormap(); - res->x_visual = x11AppVisual(); - res->x_defvisual = x11AppDefaultVisual(); - res->deref(); - } else if ( x11Data ) { - res = new TQPaintDeviceX11Data; - *res = *x11Data; - res->count = 0; - } - return res; -} - - -/*! - \fn int TQPaintDevice::devType() const - - \internal - - Returns the device type identifier, which is \c TQInternal::Widget - if the device is a TQWidget, \c TQInternal::Pixmap if it's a - TQPixmap, \c TQInternal::Printer if it's a TQPrinter, \c - TQInternal::Picture if it's a TQPicture or \c - TQInternal::UndefinedDevice in other cases (which should never - happen). -*/ - -/*! - \fn bool TQPaintDevice::isExtDev() const - - Returns TRUE if the device is an external paint device; otherwise - returns FALSE. - - External paint devices cannot be bitBlt()'ed from. TQPicture and - TQPrinter are external paint devices. -*/ - -/*! - Returns the window system handle of the paint device, for - low-level access. Using this function is not portable. - - The HANDLE type varies with platform; see \c ntqpaintdevice.h and - \c ntqwindowdefs.h for details. - - \sa x11Display() -*/ -TQt::HANDLE TQPaintDevice::handle() const -{ - return hd; -} - -/*! - Returns the window system handle of the paint device for XRender - support. Use of this function is not portable. This function will - return 0 if XRender support is not compiled into TQt, if the - XRender extension is not supported on the X11 display, or if the - handle could not be created. -*/ -TQt::HANDLE TQPaintDevice::x11RenderHandle() const -{ -#ifndef TQT_NO_XFTFREETYPE - return rendhd ? XftDrawPicture( (XftDraw *) rendhd ) : 0; -#else - return 0; -#endif // TQT_NO_XFTFREETYPE -} - - -/*! - \fn Display *TQPaintDevice::x11AppDisplay() - - Returns a pointer to the X display global to the application (X11 - only). Using this function is not portable. - - \sa handle() -*/ - -/*! - \fn int TQPaintDevice::x11AppScreen() - - Returns the screen number on the X display global to the - application (X11 only). Using this function is not portable. -*/ - -/*! - \overload - \fn int TQPaintDevice::x11AppDepth() - - Returns the depth for the default screen of the X display global - to the application (X11 only). Using this function is not - portable. - - \sa TQPixmap::defaultDepth() -*/ - -/*! - \fn int TQPaintDevice::x11AppCells() - - Returns the number of entries in the colormap for the default - screen of the X display global to the application (X11 - only). Using this function is not portable. - - \sa x11Colormap() -*/ - -/*! - \fn HANDLE TQPaintDevice::x11AppRootWindow() - - Returns the root window for the default screen of the X display - global to the applicatoin (X11 only). Using this function is not - portable. -*/ - -/*! - \fn HANDLE TQPaintDevice::x11AppColormap() - - Returns the colormap for the default screen of the X display - global to the application (X11 only). Using this function is not - portable. - - \sa x11Cells() -*/ - -/*! - \fn bool TQPaintDevice::x11AppDefaultColormap () - - Returns the default colormap for the default screen of the X - display global to the application (X11 only). Using this function - is not portable. - - \sa x11Cells() -*/ - -/*! - \fn void* TQPaintDevice::x11AppVisual () - - Returns the Visual for the default screen of the X display global - to the application (X11 only). Using this function is not - portable. -*/ - -/*! - \fn bool TQPaintDevice::x11AppDefaultVisual () - - Returns TRUE if the Visual used is the default for the default - screen of the X display global to the application (X11 only); - otherwise returns FALSE. Using this function is not portable. -*/ - -/*! - \fn int TQPaintDevice::x11AppDepth( int screen ) - - Returns the depth for screen \a screen of the X display global to - the application (X11 only). Using this function is not portable. - - \sa TQPixmap::defaultDepth() -*/ - -/*! - \overload - \fn int TQPaintDevice::x11AppCells( int screen ) - - Returns the number of entries in the colormap for screen \a screen - of the X display global to the application (X11 only). Using this - function is not portable. - - \sa x11Colormap() -*/ - -/*! - \overload - \fn HANDLE TQPaintDevice::x11AppRootWindow( int screen ) - - Returns the root window for screen \a screen of the X display - global to the applicatoin (X11 only). Using this function is not - portable. -*/ - -/*! - \overload - \fn HANDLE TQPaintDevice::x11AppColormap( int screen ) - - Returns the colormap for screen \a screen of the X display global - to the application (X11 only). Using this function is not - portable. - - \sa x11Cells() -*/ - -/*! - \overload - \fn bool TQPaintDevice::x11AppDefaultColormap( int screen ) - - Returns the default colormap for screen \a screen of the X display - global to the application (X11 only). Using this function is not - portable. - - \sa x11Cells() -*/ - -/*! - \overload - \fn void* TQPaintDevice::x11AppVisual( int screen ) - - Returns the Visual for screen \a screen of the X display global to - the application (X11 only). Using this function is not portable. -*/ - -/*! - \overload - \fn bool TQPaintDevice::x11AppDefaultVisual( int screen ) - - Returns TRUE if the Visual used is the default for screen - \a screen of the X display global to the application (X11 only); - otherwise returns FALSE. Using this function is not portable. -*/ - - -/*! - \fn Display *TQPaintDevice::x11Display() const - - Returns a pointer to the X display for the paint device (X11 - only). Using this function is not portable. - - \sa handle() -*/ - -/*! - \fn int TQPaintDevice::x11Screen () const - - Returns the screen number on the X display for the paint device - (X11 only). Using this function is not portable. -*/ - -/*! - \fn int TQPaintDevice::x11Depth () const - - Returns the depth of the X display for the paint device (X11 - only). Using this function is not portable. - - \sa TQPixmap::defaultDepth() -*/ - -/*! - \fn int TQPaintDevice::x11Cells () const - - Returns the number of entries in the colormap of the X display for - the paint device (X11 only). Using this function is not portable. - - \sa x11Colormap() -*/ - -/*! - \fn HANDLE TQPaintDevice::x11Colormap () const - - Returns the colormap of the X display for the paint device (X11 - only). Using this function is not portable. - - \sa x11Cells() -*/ - -/*! - \fn bool TQPaintDevice::x11DefaultColormap () const - - Returns the default colormap of the X display for the paint device - (X11 only). Using this function is not portable. - - \sa x11Cells() -*/ - -/*! - \fn void* TQPaintDevice::x11Visual () const - - Returns the Visual of the X display for the paint device (X11 - only). Using this function is not portable. -*/ - -/*! - \fn bool TQPaintDevice::x11DefaultVisual () const - - Returns the default Visual of the X display for the paint device - (X11 only). Using this function is not portable. -*/ - -static int *dpisX=0, *dpisY=0; -static void create_dpis() -{ - if ( dpisX ) - return; - - Display *dpy = TQPaintDevice::x11AppDisplay(); - if ( ! dpy ) - return; - - int i, screens = ScreenCount( dpy ); - dpisX = new int[ screens ]; - dpisY = new int[ screens ]; - TQ_CHECK_PTR( dpisX ); - TQ_CHECK_PTR( dpisY ); - for ( i = 0; i < screens; i++ ) { - if (DisplayWidthMM(dpy,i) < 1) - dpisX[ i ] = 75; // default the dpi to 75. - else - dpisX[ i ] = (DisplayWidth(dpy,i) * 254 + DisplayWidthMM(dpy,i)*5) - / (DisplayWidthMM(dpy,i)*10); - if (DisplayHeightMM(dpy,i) < 1) - dpisY[ i ] = 75; // default the dpi to 75. - else - dpisY[ i ] = (DisplayHeight(dpy,i) * 254 + DisplayHeightMM(dpy,i)*5) - / (DisplayHeightMM(dpy,i)*10); - } -} - -/*! - Sets the value returned by x11AppDpiX() to \a dpi for screen - \a screen. The default is determined by the display configuration. - Changing this value will alter the scaling of fonts and many other - metrics and is not recommended. Using this function is not - portable. - - \sa x11SetAppDpiY() -*/ -void TQPaintDevice::x11SetAppDpiX(int dpi, int screen) -{ - create_dpis(); - if ( ! dpisX ) - return; - if ( screen < 0 ) - screen = TQPaintDevice::x11AppScreen(); - if ( screen > ScreenCount( TQPaintDevice::x11AppDisplay() ) ) - return; - dpisX[ screen ] = dpi; -} - -/*! - \overload - - Sets the value returned by x11AppDpiX() to \a dpi for the default - screen. The default is determined by the display configuration. - Changing this value will alter the scaling of fonts and many other - metrics and is not recommended. Using this function is not - portable. - -*/ -// ### REMOVE 4.0 -void TQPaintDevice::x11SetAppDpiX( int dpi ) -{ - TQPaintDevice::x11SetAppDpiX( dpi, -1 ); -} - -/*! - Sets the value returned by x11AppDpiY() to \a dpi for screen - \a screen. The default is determined by the display configuration. - Changing this value will alter the scaling of fonts and many other - metrics and is not recommended. Using this function is not - portable. - - \sa x11SetAppDpiX() -*/ -void TQPaintDevice::x11SetAppDpiY(int dpi, int screen) -{ - create_dpis(); - if ( ! dpisY ) - return; - if ( screen < 0 ) - screen = TQPaintDevice::x11AppScreen(); - if ( screen > ScreenCount( TQPaintDevice::x11AppDisplay() ) ) - return; - dpisY[ screen ] = dpi; -} - -/*! - \overload - - Sets the value returned by x11AppDpiY() to \a dpi for the default - screen. The default is determined by the display configuration. - Changing this value will alter the scaling of fonts and many other - metrics and is not recommended. Using this function is not - portable. -*/ -// ### REMOVE 4.0 -void TQPaintDevice::x11SetAppDpiY( int dpi ) -{ - TQPaintDevice::x11SetAppDpiY( dpi, -1 ); -} - -/*! - Returns the horizontal DPI of the X display (X11 only) for screen - \a screen. Using this function is not portable. See - TQPaintDeviceMetrics for portable access to related information. - Using this function is not portable. - - \sa x11AppDpiY(), x11SetAppDpiX(), TQPaintDeviceMetrics::logicalDpiX() -*/ -int TQPaintDevice::x11AppDpiX(int screen) -{ - create_dpis(); - if ( ! dpisX ) - return 0; - if ( screen < 0 ) - screen = TQPaintDevice::x11AppScreen(); - if ( screen > ScreenCount( TQPaintDevice::x11AppDisplay() ) ) - return 0; - return dpisX[ screen ]; -} - -/*! - \overload - - Returns the horizontal DPI of the X display (X11 only) for the - default screen. Using this function is not portable. See - TQPaintDeviceMetrics for portable access to related information. - Using this function is not portable. -*/ -int TQPaintDevice::x11AppDpiX() -{ - return TQPaintDevice::x11AppDpiX( -1 ); -} - -/*! - Returns the vertical DPI of the X11 display (X11 only) for screen - \a screen. Using this function is not portable. See - TQPaintDeviceMetrics for portable access to related information. - Using this function is not portable. - - \sa x11AppDpiX(), x11SetAppDpiY(), TQPaintDeviceMetrics::logicalDpiY() -*/ -int TQPaintDevice::x11AppDpiY( int screen ) -{ - create_dpis(); - if ( ! dpisY ) - return 0; - if ( screen < 0 ) - screen = TQPaintDevice::x11AppScreen(); - if ( screen > ScreenCount( TQPaintDevice::x11AppDisplay() ) ) - return 0; - return dpisY[ screen ]; -} - -/*! - \overload - - Returns the vertical DPI of the X11 display (X11 only) for the - default screen. Using this function is not portable. See - TQPaintDeviceMetrics for portable access to related information. - Using this function is not portable. - - \sa x11AppDpiX(), x11SetAppDpiY(), TQPaintDeviceMetrics::logicalDpiY() -*/ -int TQPaintDevice::x11AppDpiY() -{ - return TQPaintDevice::x11AppDpiY( -1 ); -} - -/*! - \fn bool TQPaintDevice::paintingActive() const - - Returns TRUE if the device is being painted, i.e. someone has - called TQPainter::begin() but not yet called TQPainter::end() for - this device; otherwise returns FALSE. - - \sa TQPainter::isActive() -*/ - -/*! - Internal virtual function that interprets drawing commands from - the painter. - - Implemented by subclasses that have no direct support for drawing - graphics (external paint devices, for example, TQPicture). -*/ - -bool TQPaintDevice::cmd( int, TQPainter *, TQPDevCmdParam * ) -{ -#if defined(QT_CHECK_STATE) - tqWarning( "TQPaintDevice::cmd: Device has no command interface" ); -#endif - return FALSE; -} - -/*! - \internal - - Internal virtual function that returns paint device metrics. - - Please use the TQPaintDeviceMetrics class instead. -*/ - -int TQPaintDevice::metric( int ) const -{ -#if defined(QT_CHECK_STATE) - tqWarning( "TQPaintDevice::metrics: Device has no metric information" ); -#endif - return 0; -} - -/*! - \internal - - Internal virtual function. Reserved for future use. - - Please use the TQFontMetrics class instead. -*/ - -int TQPaintDevice::fontMet( TQFont *, int, const char *, int ) const -{ - return 0; -} - -/*! - \internal - - Internal virtual function. Reserved for future use. - - Please use the TQFontInfo class instead. -*/ - -int TQPaintDevice::fontInf( TQFont *, int ) const -{ - return 0; -} - - -// -// Internal functions for simple GC caching for blt'ing masked pixmaps. -// This cache is used when the pixmap optimization is set to Normal -// and the pixmap size doesn't exceed 128x128. -// - -static bool init_mask_gc = FALSE; -static const int max_mask_gcs = 11; // suitable for hashing - -struct mask_gc { - GC gc; - int mask_no; -}; - -static mask_gc gc_vec[max_mask_gcs]; - - -static void cleanup_mask_gc() -{ - Display *dpy = TQPaintDevice::x11AppDisplay(); - init_mask_gc = FALSE; - for ( int i=0; igc || p->mask_no != mask_no ) { // not a perfect match - if ( !p->gc ) { // no GC - p->gc = XCreateGC( dpy, hd, 0, 0 ); - XSetGraphicsExposures( dpy, p->gc, False ); - } - XSetClipMask( dpy, p->gc, mask ); - p->mask_no = mask_no; - } - return p->gc; -} - - -/*! - \relates TQPaintDevice - - Copies a block of pixels from \a src to \a dst, perhaps merging - each pixel according to the \link TQt::RasterOp raster operation \endlink - \a rop. \a sx, \a sy - is the top-left pixel in \a src (0, 0) by default, \a dx, \a dy is - the top-left position in \a dst and \a sw, \a sh is the size of - the copied block (all of \a src by default). - - The most common values for \a rop are CopyROP and XorROP; the \l - TQt::RasterOp documentation defines all the possible values. - - If \a ignoreMask is FALSE (the default) and \a src is a - masked TQPixmap, the entire blit is masked by \a{src}->mask(). - - If \a src, \a dst, \a sw or \a sh is 0, bitBlt() does nothing. If - \a sw or \a sh is negative bitBlt() copies starting at \a sx (and - respectively, \a sy) and ending at the right end (respectively, - bottom) of \a src. - - \a src must be a TQWidget or TQPixmap. You cannot blit from a - TQPrinter, for example. bitBlt() does nothing if you attempt to - blit from an unsupported device. - - bitBlt() does nothing if \a src has a greater depth than \e dst. - If you need to for example, draw a 24-bit pixmap on an 8-bit - widget, you must use drawPixmap(). -*/ - -void bitBlt( TQPaintDevice *dst, int dx, int dy, - const TQPaintDevice *src, int sx, int sy, int sw, int sh, - TQt::RasterOp rop, bool ignoreMask ) -{ - if ( !src || !dst ) { -#if defined(QT_CHECK_NULL) - Q_ASSERT( src != 0 ); - Q_ASSERT( dst != 0 ); -#endif - return; - } - if ( !src->handle() || src->isExtDev() ) - return; - - TQPaintDevice *pdev = TQPainter::redirect( dst ); - if ( pdev ) - dst = pdev; - - int ts = src->devType(); // from device type - int td = dst->devType(); // to device type - Display *dpy = src->x11Display(); - - if ( sw <= 0 ) { // special width - if ( sw < 0 ) - sw = src->metric( TQPaintDeviceMetrics::PdmWidth ) - sx; - else - return; - } - if ( sh <= 0 ) { // special height - if ( sh < 0 ) - sh = src->metric( TQPaintDeviceMetrics::PdmHeight ) - sy; - else - return; - } - - if ( dst->paintingActive() && dst->isExtDev() ) { - TQPixmap *pm; // output to picture/printer - bool tmp_pm = TRUE; - if ( ts == TQInternal::Pixmap ) { - pm = (TQPixmap*)src; - if ( sx != 0 || sy != 0 || - sw != pm->width() || sh != pm->height() || ignoreMask ) { - TQPixmap *tmp = new TQPixmap( sw, sh, pm->depth() ); - bitBlt( tmp, 0, 0, pm, sx, sy, sw, sh, TQt::CopyROP, TRUE ); - if ( pm->mask() && !ignoreMask ) { - TQBitmap mask( sw, sh ); - bitBlt( &mask, 0, 0, pm->mask(), sx, sy, sw, sh, - TQt::CopyROP, TRUE ); - tmp->setMask( mask ); - } - pm = tmp; - } else { - tmp_pm = FALSE; - } - } else if ( ts == TQInternal::Widget ) {// bitBlt to temp pixmap - pm = new TQPixmap( sw, sh ); - TQ_CHECK_PTR( pm ); - bitBlt( pm, 0, 0, src, sx, sy, sw, sh ); - } else { -#if defined(QT_CHECK_RANGE) - tqWarning( "bitBlt: Cannot bitBlt from device" ); -#endif - return; - } - TQPDevCmdParam param[3]; - TQRect r(dx, dy, pm->width(), pm->height()); - param[0].rect = &r; - param[1].pixmap = pm; - dst->cmd( TQPaintDevice::PdcDrawPixmap, 0, param ); - if ( tmp_pm ) - delete pm; - return; - } - - switch ( ts ) { - case TQInternal::Widget: - case TQInternal::Pixmap: - case TQInternal::System: // OK, can blt from these - break; - default: -#if defined(QT_CHECK_RANGE) - tqWarning( "bitBlt: Cannot bitBlt from device type %x", ts ); -#endif - return; - } - switch ( td ) { - case TQInternal::Widget: - case TQInternal::Pixmap: - case TQInternal::System: // OK, can blt to these - break; - default: -#if defined(QT_CHECK_RANGE) - tqWarning( "bitBlt: Cannot bitBlt to device type %x", td ); -#endif - return; - } - - static const short ropCodes[] = { // ROP translation table - GXcopy, GXor, GXxor, GXandInverted, - GXcopyInverted, GXorInverted, GXequiv, GXand, - GXinvert, GXclear, GXset, GXnoop, - GXandReverse, GXorReverse, GXnand, GXnor - }; - if ( rop > TQt::LastROP ) { -#if defined(QT_CHECK_RANGE) - tqWarning( "bitBlt: Invalid ROP code" ); -#endif - return; - } - - if ( dst->handle() == 0 ) { -#if defined(QT_CHECK_NULL) - tqWarning( "bitBlt: Cannot bitBlt to device" ); -#endif - return; - } - - bool mono_src; - bool mono_dst; - bool include_inferiors = FALSE; - bool graphics_exposure = FALSE; - TQPixmap *src_pm; - TQBitmap *mask; - - if ( ts == TQInternal::Pixmap ) { - src_pm = (TQPixmap*)src; - if ( src_pm->x11Screen() != dst->x11Screen() ) - src_pm->x11SetScreen( dst->x11Screen() ); - mono_src = src_pm->depth() == 1; - mask = ignoreMask ? 0 : src_pm->data->mask; - } else { - src_pm = 0; - mono_src = FALSE; - mask = 0; - include_inferiors = ((TQWidget*)src)->testWFlags(TQt::WPaintUnclipped); - graphics_exposure = td == TQInternal::Widget; - } - if ( td == TQInternal::Pixmap ) { - if ( dst->x11Screen() != src->x11Screen() ) - ((TQPixmap*)dst)->x11SetScreen( src->x11Screen() ); - mono_dst = ((TQPixmap*)dst)->depth() == 1; - ((TQPixmap*)dst)->detach(); // changes shared pixmap - } else { - mono_dst = FALSE; - include_inferiors = include_inferiors || - ((TQWidget*)dst)->testWFlags(TQt::WPaintUnclipped); - } - - if ( mono_dst && !mono_src ) { // dest is 1-bit pixmap, source is not -#if defined(QT_CHECK_RANGE) - tqWarning( "bitBlt: Incompatible destination pixmap" ); -#endif - return; - } - -#ifndef TQT_NO_XRENDER - if (src_pm && !mono_src && src_pm->data->alphapm && !ignoreMask ) { - // use RENDER to do the blit - TQPixmap *alpha = src_pm->data->alphapm; - if (src->x11RenderHandle() && - alpha->x11RenderHandle() && - dst->x11RenderHandle()) { - XRenderPictureAttributes pattr; - ulong picmask = 0; - if (include_inferiors) { - pattr.subwindow_mode = IncludeInferiors; - picmask |= CPSubwindowMode; - } - if (graphics_exposure) { - pattr.graphics_exposures = TRUE; - picmask |= CPGraphicsExposure; - } - if (picmask) - XRenderChangePicture(dpy, dst->x11RenderHandle(), picmask, &pattr); - XRenderComposite(dpy, PictOpOver, src->x11RenderHandle(), - alpha->x11RenderHandle(), dst->x11RenderHandle(), - sx, sy, sx, sy, dx, dy, sw, sh); - // restore attributes - pattr.subwindow_mode = ClipByChildren; - pattr.graphics_exposures = FALSE; - if (picmask) - XRenderChangePicture(dpy, dst->x11RenderHandle(), picmask, &pattr); - return; - } - } -#endif - - GC gc; - - if ( mask && !mono_src ) { // fast masked blt - bool temp_gc = FALSE; - if ( mask->data->maskgc ) { - gc = (GC)mask->data->maskgc; // we have a premade mask GC - } else { - if ( FALSE && src_pm->optimization() == TQPixmap::NormalOptim ) { // #### cache disabled - // Compete for the global cache - gc = cache_mask_gc( dpy, dst->handle(), - mask->data->ser_no, - mask->handle() ); - } else { - // Create a new mask GC. If BestOptim, we store the mask GC - // with the mask (not at the pixmap). This way, many pixmaps - // which have a common mask will be optimized at no extra cost. - gc = XCreateGC( dpy, dst->handle(), 0, 0 ); - XSetGraphicsExposures( dpy, gc, False ); - XSetClipMask( dpy, gc, mask->handle() ); - if ( src_pm->optimization() == TQPixmap::BestOptim ) { - mask->data->maskgc = gc; - } else { - temp_gc = TRUE; - } - } - } - XSetClipOrigin( dpy, gc, dx-sx, dy-sy ); - if ( rop != TQt::CopyROP ) // use non-default ROP code - XSetFunction( dpy, gc, ropCodes[rop] ); - if ( include_inferiors ) { - XSetSubwindowMode( dpy, gc, IncludeInferiors ); - XCopyArea( dpy, src->handle(), dst->handle(), gc, sx, sy, sw, sh, - dx, dy ); - XSetSubwindowMode( dpy, gc, ClipByChildren ); - } else { - XCopyArea( dpy, src->handle(), dst->handle(), gc, sx, sy, sw, sh, - dx, dy ); - } - - if ( temp_gc ) // delete temporary GC - XFreeGC( dpy, gc ); - else if ( rop != TQt::CopyROP ) // restore ROP - XSetFunction( dpy, gc, GXcopy ); - return; - } - - gc = tqt_xget_temp_gc( dst->x11Screen(), mono_dst ); // get a reusable GC - - if ( rop != TQt::CopyROP ) // use non-default ROP code - XSetFunction( dpy, gc, ropCodes[rop] ); - - if ( mono_src && mono_dst && src == dst ) { // dst and src are the same bitmap - XCopyArea( dpy, src->handle(), dst->handle(), gc, sx, sy, sw, sh, dx, dy ); - } else if ( mono_src ) { // src is bitmap - XGCValues gcvals; - ulong valmask = GCBackground | GCForeground | GCFillStyle | - GCStipple | GCTileStipXOrigin | GCTileStipYOrigin; - if ( td == TQInternal::Widget ) { // set GC colors - TQWidget *w = (TQWidget *)dst; - gcvals.background = w->backgroundColor().pixel( dst->x11Screen() ); - gcvals.foreground = w->foregroundColor().pixel( dst->x11Screen() ); - if ( include_inferiors ) { - valmask |= GCSubwindowMode; - gcvals.subwindow_mode = IncludeInferiors; - } - } else if ( mono_dst ) { - gcvals.background = 0; - gcvals.foreground = 1; - } else { - gcvals.background = TQt::white.pixel( dst->x11Screen() ); - gcvals.foreground = TQt::black.pixel( dst->x11Screen() ); - } - - gcvals.fill_style = FillOpaqueStippled; - gcvals.stipple = src->handle(); - gcvals.ts_x_origin = dx - sx; - gcvals.ts_y_origin = dy - sy; - - bool clipmask = FALSE; - if ( mask ) { - if ( ((TQPixmap*)src)->data->selfmask ) { - gcvals.fill_style = FillStippled; - } else { - XSetClipMask( dpy, gc, mask->handle() ); - XSetClipOrigin( dpy, gc, dx-sx, dy-sy ); - clipmask = TRUE; - } - } - - XChangeGC( dpy, gc, valmask, &gcvals ); - XFillRectangle( dpy,dst->handle(), gc, dx, dy, sw, sh ); - - valmask = GCFillStyle | GCTileStipXOrigin | GCTileStipYOrigin; - gcvals.fill_style = FillSolid; - gcvals.ts_x_origin = 0; - gcvals.ts_y_origin = 0; - if ( include_inferiors ) { - valmask |= GCSubwindowMode; - gcvals.subwindow_mode = ClipByChildren; - } - XChangeGC( dpy, gc, valmask, &gcvals ); - - if ( clipmask ) { - XSetClipOrigin( dpy, gc, 0, 0 ); - XSetClipMask( dpy, gc, None ); - } - - } else { // src is pixmap/widget - - if ( graphics_exposure ) // widget to widget - XSetGraphicsExposures( dpy, gc, True ); - if ( include_inferiors ) { - XSetSubwindowMode( dpy, gc, IncludeInferiors ); - XCopyArea( dpy, src->handle(), dst->handle(), gc, sx, sy, sw, sh, - dx, dy ); - XSetSubwindowMode( dpy, gc, ClipByChildren ); - } else { - XCopyArea( dpy, src->handle(), dst->handle(), gc, sx, sy, sw, sh, - dx, dy ); - } - if ( graphics_exposure ) // reset graphics exposure - XSetGraphicsExposures( dpy, gc, False ); - } - - if ( rop != TQt::CopyROP ) // restore ROP - XSetFunction( dpy, gc, GXcopy ); -} - - -/*! - \relates TQPaintDevice - - \overload void bitBlt( TQPaintDevice *dst, const TQPoint &dp, const TQPaintDevice *src, const TQRect &sr, RasterOp rop ) - - Overloaded bitBlt() with the destination point \a dp and source - rectangle \a sr. -*/ - - -/*! - \internal -*/ -// makes it possible to add a setResolution as we have in TQPrinter for all -// paintdevices without breaking bin compatibility. -void TQPaintDevice::setResolution( int ) -{ -} - -/*!\internal -*/ -int TQPaintDevice::resolution() const -{ - return metric( TQPaintDeviceMetrics::PdmDpiY ); -} diff --git a/src/kernel/qpaintdevicemetrics.cpp b/src/kernel/qpaintdevicemetrics.cpp deleted file mode 100644 index 046533fbe..000000000 --- a/src/kernel/qpaintdevicemetrics.cpp +++ /dev/null @@ -1,151 +0,0 @@ -/**************************************************************************** -** -** Implementation of TQPaintDeviceMetrics class -** -** Created : 941109 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#include "ntqpaintdevicemetrics.h" - -/*! - \class TQPaintDeviceMetrics ntqpaintdevicemetrics.h - \brief The TQPaintDeviceMetrics class provides information about a - paint device. - - \ingroup graphics - \ingroup images - - Sometimes when drawing graphics it is necessary to obtain - information about the physical characteristics of a paint device. - This class provides the information. For example, to compute the - aspect ratio of a paint device: - - \code - TQPaintDeviceMetrics pdm( myWidget ); - double aspect = (double)pdm.widthMM() / (double)pdm.heightMM(); - \endcode - - TQPaintDeviceMetrics contains methods to provide the width and - height of a device in both pixels (width() and height()) and - millimeters (widthMM() and heightMM()), the number of colors the - device supports (numColors()), the number of bit planes (depth()), - and the resolution of the device (logicalDpiX() and - logicalDpiY()). - - It is not always possible for TQPaintDeviceMetrics to compute the - values you ask for, particularly for external devices. The - ultimate example is asking for the resolution of of a TQPrinter - that is set to "print to file": who knows what printer that file - will end up on? -*/ - -/*! - Constructs a metric for the paint device \a pd. -*/ -TQPaintDeviceMetrics::TQPaintDeviceMetrics( const TQPaintDevice *pd ) -{ - pdev = (TQPaintDevice *)pd; -} - - -/*! - \fn int TQPaintDeviceMetrics::width() const - - Returns the width of the paint device in default coordinate system - units (e.g. pixels for TQPixmap and TQWidget). -*/ - -/*! - \fn int TQPaintDeviceMetrics::height() const - - Returns the height of the paint device in default coordinate - system units (e.g. pixels for TQPixmap and TQWidget). -*/ - -/*! - \fn int TQPaintDeviceMetrics::widthMM() const - - Returns the width of the paint device, measured in millimeters. -*/ - -/*! - \fn int TQPaintDeviceMetrics::heightMM() const - - Returns the height of the paint device, measured in millimeters. -*/ - -/*! - \fn int TQPaintDeviceMetrics::numColors() const - - Returns the number of different colors available for the paint - device. Since this value is an int will not be sufficient to represent - the number of colors on 32 bit displays, in which case INT_MAX is - returned instead. -*/ - -/*! - \fn int TQPaintDeviceMetrics::depth() const - - Returns the bit depth (number of bit planes) of the paint device. -*/ - -/*! - \fn int TQPaintDeviceMetrics::logicalDpiX() const - - Returns the horizontal resolution of the device in dots per inch, - which is used when computing font sizes. For X, this is usually - the same as could be computed from widthMM(), but it varies on - Windows. -*/ - -/*! - \fn int TQPaintDeviceMetrics::logicalDpiY() const - - Returns the vertical resolution of the device in dots per inch, - which is used when computing font sizes. For X, this is usually - the same as could be computed from heightMM(), but it varies on - Windows. -*/ - -/*! - \fn int TQPaintDeviceMetrics::physicalDpiX() const - \internal -*/ -/*! - \fn int TQPaintDeviceMetrics::physicalDpiY() const - \internal -*/ - diff --git a/src/kernel/qpainter.cpp b/src/kernel/qpainter.cpp deleted file mode 100644 index a74ca938a..000000000 --- a/src/kernel/qpainter.cpp +++ /dev/null @@ -1,3910 +0,0 @@ -/**************************************************************************** -** -** Implementation of TQPainter, TQPen and TQBrush classes -** -** Created : 940112 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#include "ntqpainter.h" -#include "qpainter_p.h" -#include "tqbitmap.h" -#include "tqptrstack.h" -#include "tqptrdict.h" -#include "tqdatastream.h" -#include "tqwidget.h" -#include "tqimage.h" -#include "ntqpaintdevicemetrics.h" -#include "ntqapplication.h" -#include "qrichtext_p.h" -#include "tqregexp.h" -#include "ntqcleanuphandler.h" -#include - -#include "tqtextlayout_p.h" -#include "qfontengine_p.h" - -#ifndef TQT_NO_TRANSFORMATIONS -typedef TQPtrStack TQWMatrixStack; -#endif - -// POSIX Large File Support redefines truncate -> truncate64 -#if defined(truncate) -# undef truncate -#endif - -/*! - \class TQPainter ntqpainter.h - \brief The TQPainter class does low-level painting e.g. on widgets. - - \ingroup graphics - \ingroup images - \mainclass - - The painter provides highly optimized functions to do most of the - drawing GUI programs require. TQPainter can draw everything from - simple lines to complex shapes like pies and chords. It can also - draw aligned text and pixmaps. Normally, it draws in a "natural" - coordinate system, but it can also do view and world - transformation. - - The typical use of a painter is: - - \list - \i Construct a painter. - \i Set a pen, a brush etc. - \i Draw. - \i Destroy the painter. - \endlist - - Mostly, all this is done inside a paint event. (In fact, 99% of - all TQPainter use is in a reimplementation of - TQWidget::paintEvent(), and the painter is heavily optimized for - such use.) Here's one very simple example: - - \code - void SimpleExampleWidget::paintEvent() - { - TQPainter paint( this ); - paint.setPen( TQt::blue ); - paint.drawText( rect(), AlignCenter, "The Text" ); - } - \endcode - - Usage is simple, and there are many settings you can use: - - \list - - \i font() is the currently set font. If you set a font that isn't - available, TQt finds a close match. In fact font() returns what - you set using setFont() and fontInfo() returns the font actually - being used (which may be the same). - - \i brush() is the currently set brush; the color or pattern that's - used for filling e.g. circles. - - \i pen() is the currently set pen; the color or stipple that's - used for drawing lines or boundaries. - - \i backgroundMode() is \c Opaque or \c Transparent, i.e. whether - backgroundColor() is used or not. - - \i backgroundColor() only applies when backgroundMode() is Opaque - and pen() is a stipple. In that case, it describes the color of - the background pixels in the stipple. - - \i rasterOp() is how pixels drawn interact with the pixels already - there. - - \i brushOrigin() is the origin of the tiled brushes, normally the - origin of the window. - - \i viewport(), window(), worldMatrix() and many more make up the - painter's coordinate transformation system. See \link - coordsys.html The Coordinate System \endlink for an explanation of - this, or see below for a very brief overview of the functions. - - \i hasClipping() is whether the painter clips at all. (The paint - device clips, too.) If the painter clips, it clips to clipRegion(). - - \i pos() is the current position, set by moveTo() and used by - lineTo(). - - \endlist - - Note that some of these settings mirror settings in some paint - devices, e.g. TQWidget::font(). TQPainter::begin() (or the TQPainter - constructor) copies these attributes from the paint device. - Calling, for example, TQWidget::setFont() doesn't take effect until - the next time a painter begins painting on it. - - save() saves all of these settings on an internal stack, restore() - pops them back. - - The core functionality of TQPainter is drawing, and there are - functions to draw most primitives: drawPoint(), drawPoints(), - drawLine(), drawRect(), drawWinFocusRect(), drawRoundRect(), - drawEllipse(), drawArc(), drawPie(), drawChord(), - drawLineSegments(), drawPolyline(), drawPolygon(), - drawConvexPolygon() and drawCubicBezier(). All of these functions - take integer coordinates; there are no floating-point versions - since we want drawing to be as fast as possible. - - There are functions to draw pixmaps/images, namely drawPixmap(), - drawImage() and drawTiledPixmap(). drawPixmap() and drawImage() - produce the same result, except that drawPixmap() is faster - on-screen and drawImage() faster and sometimes better on TQPrinter - and TQPicture. - - Text drawing is done using drawText(), and when you need - fine-grained positioning, boundingRect() tells you where a given - drawText() command would draw. - - There is a drawPicture() function that draws the contents of an - entire TQPicture using this painter. drawPicture() is the only - function that disregards all the painter's settings: the TQPicture - has its own settings. - - Normally, the TQPainter operates on the device's own coordinate - system (usually pixels), but TQPainter has good support for - coordinate transformation. See \link coordsys.html The Coordinate - System \endlink for a more general overview and a simple example. - - The most common functions used are scale(), rotate(), translate() - and shear(), all of which operate on the worldMatrix(). - setWorldMatrix() can replace or add to the currently set - worldMatrix(). - - setViewport() sets the rectangle on which TQPainter operates. The - default is the entire device, which is usually fine, except on - printers. setWindow() sets the coordinate system, that is, the - rectangle that maps to viewport(). What's drawn inside the - window() ends up being inside the viewport(). The window's - default is the same as the viewport, and if you don't use the - transformations, they are optimized away, gaining another little - bit of speed. - - After all the coordinate transformation is done, TQPainter can clip - the drawing to an arbitrary rectangle or region. hasClipping() is - TRUE if TQPainter clips, and clipRegion() returns the clip region. - You can set it using either setClipRegion() or setClipRect(). - Note that the clipping can be slow. It's all system-dependent, - but as a rule of thumb, you can assume that drawing speed is - inversely proportional to the number of rectangles in the clip - region. - - After TQPainter's clipping, the paint device may also clip. For - example, most widgets clip away the pixels used by child widgets, - and most printers clip away an area near the edges of the paper. - This additional clipping is not reflected by the return value of - clipRegion() or hasClipping(). - - TQPainter also includes some less-used functions that are very - useful on those occasions when they're needed. - - isActive() indicates whether the painter is active. begin() (and - the most usual constructor) makes it active. end() (and the - destructor) deactivates it. If the painter is active, device() - returns the paint device on which the painter paints. - - Sometimes it is desirable to make someone else paint on an unusual - TQPaintDevice. TQPainter supports a static function to do this, - redirect(). We recommend not using it, but for some hacks it's - perfect. - - setTabStops() and setTabArray() can change where the tab stops - are, but these are very seldomly used. - - \warning Note that TQPainter does not attempt to work around - coordinate limitations in the underlying window system. Some - platforms may behave incorrectly with coordinates as small as - +/-4000. - - \headerfile ntqdrawutil.h - - \sa TQPaintDevice TQWidget TQPixmap TQPrinter TQPicture - \link simple-application.html Application Walkthrough \endlink - \link coordsys.html Coordinate System Overview \endlink -*/ - -/*! - \enum TQPainter::CoordinateMode - \value CoordDevice - \value CoordPainter - - \sa clipRegion() -*/ -/*! - \enum TQPainter::TextDirection - \value Auto - \value RTL right to left - \value LTR left to right - - \sa drawText() -*/ - -/*! - \enum TQt::PaintUnit - \value PixelUnit - \value LoMetricUnit \e obsolete - \value HiMetricUnit \e obsolete - \value LoEnglishUnit \e obsolete - \value HiEnglishUnit \e obsolete - \value TwipsUnit \e obsolete -*/ - -/*! - \enum TQt::BrushStyle - - \value NoBrush - \value SolidPattern - \value Dense1Pattern - \value Dense2Pattern - \value Dense3Pattern - \value Dense4Pattern - \value Dense5Pattern - \value Dense6Pattern - \value Dense7Pattern - \value HorPattern - \value VerPattern - \value CrossPattern - \value BDiagPattern - \value FDiagPattern - \value DiagCrossPattern - \value CustomPattern - - \img brush-styles.png Brush Styles - -*/ - -/*! - \enum TQt::RasterOp - - This enum type is used to describe the way things are written to - the paint device. Each bit of the \e src (what you write) - interacts with the corresponding bit of the \e dst pixel. - - \value CopyROP dst = src - \value OrROP dst = src OR dst - \value XorROP dst = src XOR dst - \value NotAndROP dst = (NOT src) AND dst - \value EraseROP an alias for \c NotAndROP - \value NotCopyROP dst = NOT src - \value NotOrROP dst = (NOT src) OR dst - \value NotXorROP dst = (NOT src) XOR dst - \value AndROP dst = src AND dst - \value NotEraseROP an alias for \c AndROP - \value NotROP dst = NOT dst - \value ClearROP dst = 0 - \value SetROP dst = 1 - \value NopROP dst = dst - \value AndNotROP dst = src AND (NOT dst) - \value OrNotROP dst = src OR (NOT dst) - \value NandROP dst = NOT (src AND dst) - \value NorROP dst = NOT (src OR dst) - - By far the most useful ones are \c CopyROP and \c XorROP. -*/ - -/*! - \enum TQt::AlignmentFlags - - This enum type is used to describe alignment. It contains - horizontal and vertical flags. - - The horizontal flags are: - - \value AlignAuto Aligns according to the language. Left for most, - right for Arabic and Hebrew. - \value AlignLeft Aligns with the left edge. - \value AlignRight Aligns with the right edge. - \value AlignHCenter Centers horizontally in the available space. - \value AlignJustify Justifies the text in the available space. - Does not work for everything and may be interpreted as - AlignAuto in some cases. - - The vertical flags are: - - \value AlignTop Aligns with the top. - \value AlignBottom Aligns with the bottom. - \value AlignVCenter Centers vertically in the available space. - - You can use only one of the horizontal flags at a time. There is - one two-dimensional flag: - - \value AlignCenter Centers in both dimensions. - - You can use at most one horizontal and one vertical flag at a time. \c - AlignCenter counts as both horizontal and vertical. - - Masks: - - \value AlignHorizontal_Mask - \value AlignVertical_Mask - - Conflicting combinations of flags have undefined meanings. -*/ - -/*! - \enum TQt::TextFlags - - This enum type is used to define some modifier flags. Some of - these flags only make sense in the context of printing: - - \value SingleLine Treats all whitespace as spaces and prints just - one line. - \value DontClip If it's impossible to stay within the given bounds, - it prints outside. - \value ExpandTabs Makes the U+0009 (ASCII tab) character move to - the next tab stop. - \value ShowPrefix Displays the string "\&P" as P - (see TQButton for an example). For an ampersand, use "\&\&". - \value WordBreak Breaks lines at appropriate points, e.g. at word - boundaries. - \value BreakAnywhere Breaks lines anywhere, even within words. - \value NoAccel Same as ShowPrefix but doesn't draw the underlines. - - You can use as many modifier flags as you want, except that \c - SingleLine and \c WordBreak cannot be combined. - - Flags that are inappropriate for a given use (e.g. ShowPrefix to - TQGridLayout::addWidget()) are generally ignored. - -*/ - -/*! - \enum TQt::PenStyle - - This enum type defines the pen styles that can be drawn using - TQPainter. The styles are - - \value NoPen no line at all. For example, TQPainter::drawRect() - fills but does not draw any boundary line. - - \value SolidLine a simple line. - - \value DashLine dashes separated by a few pixels. - - \value DotLine dots separated by a few pixels. - - \value DashDotLine alternate dots and dashes. - - \value DashDotDotLine one dash, two dots, one dash, two dots. - - \value FineDotLine single pixel dots separated by single pixels. - - \value MPenStyle mask of the pen styles. - - \img pen-styles.png Pen Styles -*/ - -/*! - \enum TQt::PenCapStyle - - This enum type defines the pen cap styles supported by TQt, i.e. - the line end caps that can be drawn using TQPainter. - - \value FlatCap a square line end that does not cover the end - point of the line. - \value SquareCap a square line end that covers the end point and - extends beyond it with half the line width. - \value RoundCap a rounded line end. - \value MPenCapStyle mask of the pen cap styles. - - \img pen-cap-styles.png Pen Cap Styles -*/ - -/*! - \enum TQt::PenJoinStyle - - This enum type defines the pen join styles supported by TQt, i.e. - which joins between two connected lines can be drawn using - TQPainter. - - \value MiterJoin The outer edges of the lines are extended to - meet at an angle, and this area is filled. - \value BevelJoin The triangular notch between the two lines is filled. - \value RoundJoin A circular arc between the two lines is filled. - \value MPenJoinStyle mask of the pen join styles. - - \img pen-join-styles.png Pen Join Styles -*/ - -/*! - \enum TQt::BGMode - - Background mode - - \value TransparentMode - \value OpaqueMode -*/ - -/*! - Constructs a painter. - - Notice that all painter settings (setPen, setBrush etc.) are reset - to default values when begin() is called. - - \sa begin(), end() -*/ - -TQPainter::TQPainter() -{ - init(); -} - - -/*! - Constructs a painter that begins painting the paint device \a pd - immediately. Depending on the underlying graphic system the - painter will paint over children of the paintdevice if \a - unclipped is TRUE. - - This constructor is convenient for short-lived painters, e.g. in a - \link TQWidget::paintEvent() paint event\endlink and should be used - only once. The constructor calls begin() for you and the TQPainter - destructor automatically calls end(). - - Here's an example using begin() and end(): - \code - void MyWidget::paintEvent( TQPaintEvent * ) - { - TQPainter p; - p.begin( this ); - p.drawLine( ... ); // drawing code - p.end(); - } - \endcode - - The same example using this constructor: - \code - void MyWidget::paintEvent( TQPaintEvent * ) - { - TQPainter p( this ); - p.drawLine( ... ); // drawing code - } - \endcode - - Since the constructor cannot provide feedback when the initialization - of the painter failed you should rather use begin() and end() to paint - on external devices, e.g. printers. - - \sa begin(), end() -*/ - -TQPainter::TQPainter( const TQPaintDevice *pd, bool unclipped ) -{ - init(); - if ( begin( pd, unclipped ) ) - flags |= CtorBegin; -} - - -/*! - Constructs a painter that begins painting the paint device \a pd - immediately, with the default arguments taken from \a - copyAttributes. The painter will paint over children of the paint - device if \a unclipped is TRUE (although this is not supported on - all platforms). - - \sa begin() -*/ - -TQPainter::TQPainter( const TQPaintDevice *pd, - const TQWidget *copyAttributes, bool unclipped ) -{ - init(); - if ( begin( pd, copyAttributes, unclipped ) ) - flags |= CtorBegin; -} - - -/*! - Destroys the painter. -*/ - -TQPainter::~TQPainter() -{ - if ( isActive() ) - end(); - else - killPStack(); - if ( tabarray ) // delete tab array - delete [] tabarray; -#ifndef TQT_NO_TRANSFORMATIONS - if ( wm_stack ) - delete (TQWMatrixStack *)wm_stack; -#endif - destroy(); -} - - -/*! - \overload bool TQPainter::begin( const TQPaintDevice *pd, const TQWidget *copyAttributes, bool unclipped ) - - This version opens the painter on a paint device \a pd and sets - the initial pen, background color and font from \a copyAttributes, - painting over the paint device's children when \a unclipped is - TRUE. This is equivalent to: - - \code - TQPainter p; - p.begin( pd ); - p.setPen( copyAttributes->foregroundColor() ); - p.setBackgroundColor( copyAttributes->backgroundColor() ); - p.setFont( copyAttributes->font() ); - \endcode - - This begin function is convenient for double buffering. When you - draw in a pixmap instead of directly in a widget (to later bitBlt - the pixmap into the widget) you will need to set the widget's - font etc. This function does exactly that. - - Example: - \code - void MyWidget::paintEvent( TQPaintEvent * ) - { - TQPixmap pm(size()); - TQPainter p; - p.begin(&pm, this); - // ... potentially flickering paint operation ... - p.end(); - bitBlt(this, 0, 0, &pm); - } - \endcode - - \sa end() -*/ - -bool TQPainter::begin( const TQPaintDevice *pd, const TQWidget *copyAttributes, bool unclipped ) -{ - if ( copyAttributes == 0 ) { -#if defined(QT_CHECK_NULL) - tqWarning( "TQPainter::begin: The widget to copy attributes from cannot " - "be null" ); -#endif - return FALSE; - } - if ( begin( pd, unclipped ) ) { - setPen( copyAttributes->foregroundColor() ); - setBackgroundColor( copyAttributes->backgroundColor() ); - setFont( copyAttributes->font() ); - return TRUE; - } - return FALSE; -} - - -/*! - \internal - Sets or clears a pointer flag. -*/ - -void TQPainter::setf( uint b, bool v ) -{ - if ( v ) - setf( b ); - else - clearf( b ); -} - - -/*! - \fn bool TQPainter::isActive() const - - Returns TRUE if the painter is active painting, i.e. begin() has - been called and end() has not yet been called; otherwise returns - FALSE. - - \sa TQPaintDevice::paintingActive() -*/ - -/*! - \fn TQPaintDevice *TQPainter::device() const - - Returns the paint device on which this painter is currently - painting, or 0 if the painter is not active. - - \sa TQPaintDevice::paintingActive() -*/ - - -struct TQPState { // painter state - TQFont font; - TQPen pen; - TQPoint curPt; - TQBrush brush; - TQColor bgc; - uchar bgm; - uchar rop; - TQPoint bro; - TQRect wr, vr; -#ifndef TQT_NO_TRANSFORMATIONS - TQWMatrix wm; -#else - int xlatex; - int xlatey; -#endif - bool vxf; - bool wxf; - TQRegion rgn; - bool clip; - int ts; - int *ta; - void* wm_stack; -}; - -//TODO lose the worldmatrix stack - -typedef TQPtrStack TQPStateStack; - - -void TQPainter::killPStack() -{ -#if defined(QT_CHECK_STATE) - if ( ps_stack && !((TQPStateStack *)ps_stack)->isEmpty() ) - tqWarning( "TQPainter::killPStack: non-empty save/restore stack when " - "end() was called" ); -#endif - delete (TQPStateStack *)ps_stack; - ps_stack = 0; -} - -/*! - Saves the current painter state (pushes the state onto a stack). A - save() must be followed by a corresponding restore(). end() - unwinds the stack. - - \sa restore() -*/ - -void TQPainter::save() -{ - if ( testf(ExtDev) ) { - if ( testf(DirtyFont) ) - updateFont(); - if ( testf(DirtyPen) ) - updatePen(); - if ( testf(DirtyBrush) ) - updateBrush(); - pdev->cmd( TQPaintDevice::PdcSave, this, 0 ); - } - TQPStateStack *pss = (TQPStateStack *)ps_stack; - if ( pss == 0 ) { - pss = new TQPtrStack; - TQ_CHECK_PTR( pss ); - pss->setAutoDelete( TRUE ); - ps_stack = pss; - } - TQPState *ps = new TQPState; - TQ_CHECK_PTR( ps ); - ps->font = cfont; - ps->pen = cpen; - ps->curPt = pos(); - ps->brush = cbrush; - ps->bgc = bg_col; - ps->bgm = bg_mode; - ps->rop = rop; - ps->bro = bro; -#ifndef TQT_NO_TRANSFORMATIONS - ps->wr = TQRect( wx, wy, ww, wh ); - ps->vr = TQRect( vx, vy, vw, vh ); - ps->wm = wxmat; - ps->vxf = testf(VxF); - ps->wxf = testf(WxF); -#else - ps->xlatex = xlatex; - ps->xlatey = xlatey; -#endif - ps->rgn = crgn; - ps->clip = testf(ClipOn); - ps->ts = tabstops; - ps->ta = tabarray; - ps->wm_stack = wm_stack; - wm_stack = 0; - pss->push( ps ); -} - -/*! - Restores the current painter state (pops a saved state off the - stack). - - \sa save() -*/ - -void TQPainter::restore() -{ - if ( testf(ExtDev) ) { - pdev->cmd( TQPaintDevice::PdcRestore, this, 0 ); - if ( pdev->devType() == TQInternal::Picture ) - block_ext = TRUE; - } - TQPStateStack *pss = (TQPStateStack *)ps_stack; - if ( pss == 0 || pss->isEmpty() ) { -#if defined(QT_CHECK_STATE) - tqWarning( "TQPainter::restore: Empty stack error" ); -#endif - return; - } - TQPState *ps = pss->pop(); - bool hardRestore = testf(VolatileDC); - - if ( ps->font != cfont || hardRestore ) - setFont( ps->font ); - if ( ps->pen != cpen || hardRestore ) - setPen( ps->pen ); - if ( ps->brush != cbrush || hardRestore ) - setBrush( ps->brush ); - if ( ps->bgc != bg_col || hardRestore ) - setBackgroundColor( ps->bgc ); - if ( ps->bgm != bg_mode || hardRestore ) - setBackgroundMode( (BGMode)ps->bgm ); - if ( ps->rop != rop || hardRestore ) - setRasterOp( (RasterOp)ps->rop ); - if ( ps->bro != bro || hardRestore ) - setBrushOrigin( ps->bro ); -#ifndef TQT_NO_TRANSFORMATIONS - TQRect wr( wx, wy, ww, wh ); - TQRect vr( vx, vy, vw, vh ); - if ( ps->wr != wr || hardRestore ) - setWindow( ps->wr ); - if ( ps->vr != vr || hardRestore ) - setViewport( ps->vr ); - if ( ps->wm != wxmat || hardRestore ) - setWorldMatrix( ps->wm ); - if ( ps->vxf != testf(VxF) || hardRestore ) - setViewXForm( ps->vxf ); - if ( ps->wxf != testf(WxF) || hardRestore ) - setWorldXForm( ps->wxf ); -#else - xlatex = ps->xlatex; - xlatey = ps->xlatey; - setf( VxF, xlatex || xlatey ); -#endif - if ( ps->curPt != pos() || hardRestore ) - moveTo( ps->curPt ); - if ( ps->rgn != crgn || hardRestore ) - setClipRegion( ps->rgn ); - if ( ps->clip != testf(ClipOn) || hardRestore ) - setClipping( ps->clip ); - tabstops = ps->ts; - tabarray = ps->ta; - -#ifndef TQT_NO_TRANSFORMATIONS - if ( wm_stack ) - delete (TQWMatrixStack *)wm_stack; - wm_stack = ps->wm_stack; -#endif - delete ps; - block_ext = FALSE; -} - -typedef TQPtrDict TQPaintDeviceDict; -static TQPaintDeviceDict *pdev_dict = 0; - -/*! - Redirects all paint commands for a paint device, \a pdev, to - another paint device, \a replacement, unless \a replacement is 0. - If \a replacement is 0, the redirection for \a pdev is removed. - - In general, you'll probably find calling TQPixmap::grabWidget() or - TQPixmap::grabWindow() is an easier solution. -*/ - -void TQPainter::redirect( TQPaintDevice *pdev, TQPaintDevice *replacement ) -{ - if ( pdev_dict == 0 ) { - if ( replacement == 0 ) - return; - pdev_dict = new TQPaintDeviceDict; - TQ_CHECK_PTR( pdev_dict ); - } -#if defined(QT_CHECK_NULL) - if ( pdev == 0 ) - tqWarning( "TQPainter::redirect: The pdev argument cannot be 0" ); -#endif - if ( replacement ) { - pdev_dict->insert( pdev, replacement ); - } else { - pdev_dict->remove( pdev ); - if ( pdev_dict->count() == 0 ) { - delete pdev_dict; - pdev_dict = 0; - } - } -} - -/*! - \internal - Returns the replacement for \a pdev, or 0 if there is no replacement. -*/ -TQPaintDevice *TQPainter::redirect( TQPaintDevice *pdev ) -{ - return pdev_dict ? pdev_dict->find( pdev ) : 0; -} - -/*! - Returns the font metrics for the painter, if the painter is - active. It is not possible to obtain metrics for an inactive - painter, so the return value is undefined if the painter is not - active. - - \sa fontInfo(), isActive() -*/ - -TQFontMetrics TQPainter::fontMetrics() const -{ - if ( pdev && pdev->devType() == TQInternal::Picture ) - return TQFontMetrics( cfont ); - - return TQFontMetrics(this); -} - -/*! - Returns the font info for the painter, if the painter is active. - It is not possible to obtain font information for an inactive - painter, so the return value is undefined if the painter is not - active. - - \sa fontMetrics(), isActive() -*/ - -TQFontInfo TQPainter::fontInfo() const -{ - if ( pdev && pdev->devType() == TQInternal::Picture ) - return TQFontInfo( cfont ); - - return TQFontInfo(this); -} - - -/*! - \fn const TQPen &TQPainter::pen() const - - Returns the painter's current pen. - - \sa setPen() -*/ - -/*! - Sets a new painter pen. - - The \a pen defines how to draw lines and outlines, and it also - defines the text color. - - \sa pen() -*/ - -void TQPainter::setPen( const TQPen &pen ) -{ -#if defined(QT_CHECK_STATE) - if ( !isActive() ) - tqWarning( "TQPainter::setPen: Will be reset by begin()" ); -#endif - if ( cpen == pen ) - return; - cpen = pen; - updatePen(); -} - -/*! - \overload - - Sets the painter's pen to have style \a style, width 0 and black - color. - - \sa pen(), TQPen -*/ - -void TQPainter::setPen( PenStyle style ) -{ -#if defined(QT_CHECK_STATE) - if ( !isActive() ) - tqWarning( "TQPainter::setPen: Will be reset by begin()" ); -#endif - TQPen::TQPenData *d = cpen.data; // low level access - if ( d->style == style && d->linest == style && !d->width && d->color == TQt::black ) - return; - if ( d->count != 1 ) { - cpen.detach(); - d = cpen.data; - } - d->style = style; - d->width = 0; - d->color = TQt::black; - d->linest = style; - updatePen(); -} - -/*! - \overload - - Sets the painter's pen to have style \c SolidLine, width 0 and the - specified \a color. - - \sa pen(), TQPen -*/ - -void TQPainter::setPen( const TQColor &color ) -{ -#if defined(QT_CHECK_STATE) - if ( !isActive() ) - tqWarning( "TQPainter::setPen: Will be reset by begin()" ); -#endif - TQPen::TQPenData *d = cpen.data; // low level access - if ( d->color == color && !d->width && d->style == SolidLine && d->linest == SolidLine ) - return; - if ( d->count != 1 ) { - cpen.detach(); - d = cpen.data; - } - d->style = SolidLine; - d->width = 0; - d->color = color; - d->linest = SolidLine; - updatePen(); -} - -/*! - \fn const TQBrush &TQPainter::brush() const - - Returns the painter's current brush. - - \sa TQPainter::setBrush() -*/ - -/*! - \overload - - Sets the painter's brush to \a brush. - - The \a brush defines how shapes are filled. - - \sa brush() -*/ - -void TQPainter::setBrush( const TQBrush &brush ) -{ -#if defined(QT_CHECK_STATE) - if ( !isActive() ) - tqWarning( "TQPainter::setBrush: Will be reset by begin()" ); -#endif - if ( cbrush == brush ) - return; - cbrush = brush; - updateBrush(); -} - -/*! - Sets the painter's brush to black color and the specified \a - style. - - \sa brush(), TQBrush -*/ - -void TQPainter::setBrush( BrushStyle style ) -{ -#if defined(QT_CHECK_STATE) - if ( !isActive() ) - tqWarning( "TQPainter::setBrush: Will be reset by begin()" ); -#endif - TQBrush::TQBrushData *d = cbrush.data; // low level access - if ( d->style == style && d->color == TQt::black && !d->pixmap ) - return; - if ( d->count != 1 ) { - cbrush.detach(); - d = cbrush.data; - } - d->style = style; - d->color = TQt::black; - if ( d->pixmap ) { - delete d->pixmap; - d->pixmap = 0; - } - updateBrush(); -} - -/*! - \overload - - Sets the painter's brush to have style \c SolidPattern and the - specified \a color. - - \sa brush(), TQBrush -*/ - -void TQPainter::setBrush( const TQColor &color ) -{ -#if defined(QT_CHECK_STATE) - if ( !isActive() ) - tqWarning( "TQPainter::setBrush: Will be reset by begin()" ); -#endif - TQBrush::TQBrushData *d = cbrush.data; // low level access - if ( d->color == color && d->style == SolidPattern && !d->pixmap ) - return; - if ( d->count != 1 ) { - cbrush.detach(); - d = cbrush.data; - } - d->style = SolidPattern; - d->color = color; - if ( d->pixmap ) { - delete d->pixmap; - d->pixmap = 0; - } - updateBrush(); -} - - -/*! - \fn const TQColor &TQPainter::backgroundColor() const - - Returns the current background color. - - \sa setBackgroundColor() TQColor -*/ - -/*! - \fn BGMode TQPainter::backgroundMode() const - - Returns the current background mode. - - \sa setBackgroundMode() BGMode -*/ - -/*! - \fn RasterOp TQPainter::rasterOp() const - - Returns the current \link TQt::RasterOp raster operation \endlink. - - \sa setRasterOp() RasterOp -*/ - -/*! - \fn const TQPoint &TQPainter::brushOrigin() const - - Returns the brush origin currently set. - - \sa setBrushOrigin() -*/ - - -/*! - \fn int TQPainter::tabStops() const - - Returns the tab stop setting. - - \sa setTabStops() -*/ - -/*! - Set the tab stop width to \a ts, i.e. locates tab stops at \a ts, - 2*\a ts, 3*\a ts and so on. - - Tab stops are used when drawing formatted text with \c ExpandTabs - set. This fixed tab stop value is used only if no tab array is set - (which is the default case). - - A value of 0 (the default) implies a tabstop setting of 8 times the width of the - character 'x' in the font currently set on the painter. - - \sa tabStops(), setTabArray(), drawText(), fontMetrics() -*/ - -void TQPainter::setTabStops( int ts ) -{ -#if defined(QT_CHECK_STATE) - if ( !isActive() ) - tqWarning( "TQPainter::setTabStops: Will be reset by begin()" ); -#endif - tabstops = ts; - if ( isActive() && testf(ExtDev) ) { // tell extended device - TQPDevCmdParam param[1]; - param[0].ival = ts; - pdev->cmd( TQPaintDevice::PdcSetTabStops, this, param ); - } -} - -/*! - \fn int *TQPainter::tabArray() const - - Returns the currently set tab stop array. - - \sa setTabArray() -*/ - -/*! - Sets the tab stop array to \a ta. This puts tab stops at \a ta[0], - \a ta[1] and so on. The array is null-terminated. - - If both a tab array and a tab top size is set, the tab array wins. - - \sa tabArray(), setTabStops(), drawText(), fontMetrics() -*/ - -void TQPainter::setTabArray( int *ta ) -{ -#if defined(QT_CHECK_STATE) - if ( !isActive() ) - tqWarning( "TQPainter::setTabArray: Will be reset by begin()" ); -#endif - if ( ta != tabarray ) { - tabarraylen = 0; - if ( tabarray ) // Avoid purify complaint - delete [] tabarray; // delete old array - if ( ta ) { // tabarray = copy of 'ta' - while ( ta[tabarraylen] ) - tabarraylen++; - tabarraylen++; // and 0 terminator - tabarray = new int[tabarraylen]; // duplicate ta - memcpy( tabarray, ta, sizeof(int)*tabarraylen ); - } else { - tabarray = 0; - } - } - if ( isActive() && testf(ExtDev) ) { // tell extended device - TQPDevCmdParam param[2]; - param[0].ival = tabarraylen; - param[1].ivec = tabarray; - pdev->cmd( TQPaintDevice::PdcSetTabArray, this, param ); - } -} - - -/*! - \fn HANDLE TQPainter::handle() const - - Returns the platform-dependent handle used for drawing. Using this - function is not portable. -*/ - - -/***************************************************************************** - TQPainter xform settings - *****************************************************************************/ - -#ifndef TQT_NO_TRANSFORMATIONS - -/*! - Enables view transformations if \a enable is TRUE, or disables - view transformations if \a enable is FALSE. - - \sa hasViewXForm(), setWindow(), setViewport(), setWorldMatrix(), - setWorldXForm(), xForm() -*/ - -void TQPainter::setViewXForm( bool enable ) -{ -#if defined(QT_CHECK_STATE) - if ( !isActive() ) - tqWarning( "TQPainter::setViewXForm: Will be reset by begin()" ); -#endif - if ( !isActive() || enable == testf(VxF) ) - return; - setf( VxF, enable ); - if ( testf(ExtDev) ) { - TQPDevCmdParam param[1]; - param[0].ival = enable; - pdev->cmd( TQPaintDevice::PdcSetVXform, this, param ); - } - updateXForm(); -} - -/*! - \fn bool TQPainter::hasViewXForm() const - - Returns TRUE if view transformation is enabled; otherwise returns - FALSE. - - \sa setViewXForm(), xForm() -*/ - -/*! - Returns the window rectangle. - - \sa setWindow(), setViewXForm() -*/ - -TQRect TQPainter::window() const -{ - return TQRect( wx, wy, ww, wh ); -} - -/*! - Sets the window rectangle view transformation for the painter and - enables view transformation. - - The window rectangle is part of the view transformation. The - window specifies the logical coordinate system and is specified by - the \a x, \a y, \a w width and \a h height parameters. Its sister, - the viewport(), specifies the device coordinate system. - - The default window rectangle is the same as the device's - rectangle. See the \link coordsys.html Coordinate System Overview - \endlink for an overview of coordinate transformation. - - \sa window(), setViewport(), setViewXForm(), setWorldMatrix(), - setWorldXForm() -*/ - -void TQPainter::setWindow( int x, int y, int w, int h ) -{ -#if defined(QT_CHECK_STATE) - if ( !isActive() ) - tqWarning( "TQPainter::setWindow: Will be reset by begin()" ); -#endif - wx = x; - wy = y; - ww = w; - wh = h; - if ( testf(ExtDev) ) { - TQRect r( x, y, w, h ); - TQPDevCmdParam param[1]; - param[0].rect = (TQRect*)&r; - pdev->cmd( TQPaintDevice::PdcSetWindow, this, param ); - } - if ( testf(VxF) ) - updateXForm(); - else - setViewXForm( TRUE ); -} - -/*! - Returns the viewport rectangle. - - \sa setViewport(), setViewXForm() -*/ - -TQRect TQPainter::viewport() const // get viewport -{ - return TQRect( vx, vy, vw, vh ); -} - -/*! - Sets the viewport rectangle view transformation for the painter - and enables view transformation. - - The viewport rectangle is part of the view transformation. The - viewport specifies the device coordinate system and is specified - by the \a x, \a y, \a w width and \a h height parameters. Its - sister, the window(), specifies the logical coordinate system. - - The default viewport rectangle is the same as the device's - rectangle. See the \link coordsys.html Coordinate System Overview - \endlink for an overview of coordinate transformation. - - \sa viewport(), setWindow(), setViewXForm(), setWorldMatrix(), - setWorldXForm(), xForm() -*/ - -void TQPainter::setViewport( int x, int y, int w, int h ) -{ -#if defined(QT_CHECK_STATE) - if ( !isActive() ) - tqWarning( "TQPainter::setViewport: Will be reset by begin()" ); -#endif - vx = x; - vy = y; - vw = w; - vh = h; - if ( testf(ExtDev) ) { - TQRect r( x, y, w, h ); - TQPDevCmdParam param[1]; - param[0].rect = (TQRect*)&r; - pdev->cmd( TQPaintDevice::PdcSetViewport, this, param ); - } - if ( testf(VxF) ) - updateXForm(); - else - setViewXForm( TRUE ); -} - - -/*! - Enables world transformations if \a enable is TRUE, or disables - world transformations if \a enable is FALSE. The world - transformation matrix is not changed. - - \sa setWorldMatrix(), setWindow(), setViewport(), setViewXForm(), - xForm() -*/ - -void TQPainter::setWorldXForm( bool enable ) -{ -#if defined(QT_CHECK_STATE) - if ( !isActive() ) - tqWarning( "TQPainter::setWorldXForm: Will be reset by begin()" ); -#endif - if ( !isActive() || enable == testf(WxF) ) - return; - setf( WxF, enable ); - if ( testf(ExtDev) && !block_ext ) { - TQPDevCmdParam param[1]; - param[0].ival = enable; - pdev->cmd( TQPaintDevice::PdcSetWXform, this, param ); - } - updateXForm(); -} - -/*! - \fn bool TQPainter::hasWorldXForm() const - - Returns TRUE if world transformation is enabled; otherwise returns - FALSE. - - \sa setWorldXForm() -*/ - -/*! - Returns the world transformation matrix. - - \sa setWorldMatrix() -*/ - -const TQWMatrix &TQPainter::worldMatrix() const -{ - return wxmat; -} - -/*! - Sets the world transformation matrix to \a m and enables world - transformation. - - If \a combine is TRUE, then \a m is combined with the current - transformation matrix, otherwise \a m replaces the current - transformation matrix. - - If \a m is the identity matrix and \a combine is FALSE, this - function calls setWorldXForm(FALSE). (The identity matrix is the - matrix where TQWMatrix::m11() and TQWMatrix::m22() are 1.0 and the - rest are 0.0.) - - World transformations are applied after the view transformations - (i.e. \link setWindow() window\endlink and \link setViewport() - viewport\endlink). - - The following functions can transform the coordinate system without using - a TQWMatrix: - \list - \i translate() - \i scale() - \i shear() - \i rotate() - \endlist - - They operate on the painter's worldMatrix() and are implemented like this: - - \code - void TQPainter::rotate( double a ) - { - TQWMatrix m; - m.rotate( a ); - setWorldMatrix( m, TRUE ); - } - \endcode - - Note that you should always use \a combine when you are drawing - into a TQPicture. Otherwise it may not be possible to replay the - picture with additional transformations. Using translate(), - scale(), etc., is safe. - - For a brief overview of coordinate transformation, see the \link - coordsys.html Coordinate System Overview. \endlink - - \sa worldMatrix() setWorldXForm() setWindow() setViewport() - setViewXForm() xForm() TQWMatrix -*/ - -void TQPainter::setWorldMatrix( const TQWMatrix &m, bool combine ) -{ - if ( !isActive() ) { -#if defined(QT_CHECK_STATE) - tqWarning( "TQPainter::setWorldMatrix: Will be reset by begin()" ); -#endif - return; - } - if ( combine ) - wxmat = m * wxmat; // combines - else - wxmat = m; // set new matrix - bool identity = wxmat.m11() == 1.0F && wxmat.m22() == 1.0F && - wxmat.m12() == 0.0F && wxmat.m21() == 0.0F && - wxmat.dx() == 0.0F && wxmat.dy() == 0.0F; - if ( testf(ExtDev) && !block_ext ) { - TQPDevCmdParam param[2]; - param[0].matrix = &m; - param[1].ival = combine; - pdev->cmd( TQPaintDevice::PdcSetWMatrix, this, param ); - } - if ( identity && pdev->devType() != TQInternal::Picture ) - setWorldXForm( FALSE ); - else if ( !testf(WxF) ) - setWorldXForm( TRUE ); - else - updateXForm(); -} - -/*! \obsolete - - We recommend using save() instead. -*/ - -void TQPainter::saveWorldMatrix() -{ - TQWMatrixStack *stack = (TQWMatrixStack *)wm_stack; - if ( stack == 0 ) { - stack = new TQPtrStack; - TQ_CHECK_PTR( stack ); - stack->setAutoDelete( TRUE ); - wm_stack = stack; - } - - stack->push( new TQWMatrix( wxmat ) ); - -} - -/*! \obsolete - We recommend using restore() instead. -*/ - -void TQPainter::restoreWorldMatrix() -{ - TQWMatrixStack *stack = (TQWMatrixStack *)wm_stack; - if ( stack == 0 || stack->isEmpty() ) { -#if defined(QT_CHECK_STATE) - tqWarning( "TQPainter::restoreWorldMatrix: Empty stack error" ); -#endif - return; - } - TQWMatrix* m = stack->pop(); - setWorldMatrix( *m ); - delete m; -} - -#endif // TQT_NO_TRANSFORMATIONS - -/*! - Translates the coordinate system by \a (dx, dy). After this call, - \a (dx, dy) is added to points. - - For example, the following code draws the same point twice: - \code - void MyWidget::paintEvent() - { - TQPainter paint( this ); - - paint.drawPoint( 0, 0 ); - - paint.translate( 100.0, 40.0 ); - paint.drawPoint( -100, -40 ); - } - \endcode - - \sa scale(), shear(), rotate(), resetXForm(), setWorldMatrix(), xForm() -*/ - -void TQPainter::translate( double dx, double dy ) -{ -#ifndef TQT_NO_TRANSFORMATIONS - TQWMatrix m; - m.translate( dx, dy ); - setWorldMatrix( m, TRUE ); -#else - xlatex += (int)dx; - xlatey += (int)dy; - setf( VxF, xlatex || xlatey ); -#endif -} - - -#ifndef TQT_NO_TRANSFORMATIONS -/*! - Scales the coordinate system by \a (sx, sy). - - \sa translate(), shear(), rotate(), resetXForm(), setWorldMatrix(), - xForm() -*/ - -void TQPainter::scale( double sx, double sy ) -{ - TQWMatrix m; - m.scale( sx, sy ); - setWorldMatrix( m, TRUE ); -} - -/*! - Shears the coordinate system by \a (sh, sv). - - \sa translate(), scale(), rotate(), resetXForm(), setWorldMatrix(), - xForm() -*/ - -void TQPainter::shear( double sh, double sv ) -{ - TQWMatrix m; - m.shear( sv, sh ); - setWorldMatrix( m, TRUE ); -} - -/*! - Rotates the coordinate system \a a degrees counterclockwise. - - \sa translate(), scale(), shear(), resetXForm(), setWorldMatrix(), - xForm() -*/ - -void TQPainter::rotate( double a ) -{ - TQWMatrix m; - m.rotate( a ); - setWorldMatrix( m, TRUE ); -} - - -/*! - Resets any transformations that were made using translate(), scale(), - shear(), rotate(), setWorldMatrix(), setViewport() and - setWindow(). - - \sa worldMatrix(), viewport(), window() -*/ - -void TQPainter::resetXForm() -{ - if ( !isActive() ) - return; - wx = wy = vx = vy = 0; // default view origins - ww = vw = pdev->metric( TQPaintDeviceMetrics::PdmWidth ); - wh = vh = pdev->metric( TQPaintDeviceMetrics::PdmHeight ); - wxmat = TQWMatrix(); - setWorldXForm( FALSE ); - setViewXForm( FALSE ); -} - -/*! - \internal - Updates an internal integer transformation matrix. -*/ - -void TQPainter::updateXForm() -{ - TQWMatrix m; - if ( testf(VxF) ) { - double scaleW = (double)vw/(double)ww; - double scaleH = (double)vh/(double)wh; - m.setMatrix( scaleW, 0, 0, scaleH, vx - wx*scaleW, vy - wy*scaleH ); - } - if ( testf(WxF) ) { - if ( testf(VxF) ) - m = wxmat * m; - else - m = wxmat; - } - xmat = m; - - txinv = FALSE; // no inverted matrix - txop = TxNone; - if ( m12()==0.0 && m21()==0.0 && m11() >= 0.0 && m22() >= 0.0 ) { - if ( m11()==1.0 && m22()==1.0 ) { - if ( dx()!=0.0 || dy()!=0.0 ) - txop = TxTranslate; - } else { - txop = TxScale; -#if defined(TQ_WS_WIN) - setf(DirtyFont); -#endif - } - } else { - txop = TxRotShear; -#if defined(TQ_WS_WIN) - setf(DirtyFont); -#endif - } -} - - -/*! - \internal - Updates an internal integer inverse transformation matrix. -*/ - -void TQPainter::updateInvXForm() -{ -#if defined(QT_CHECK_STATE) - Q_ASSERT( txinv == FALSE ); -#endif - txinv = TRUE; // creating inverted matrix - bool invertible; - TQWMatrix m; - if ( testf(VxF) ) { - m.translate( vx, vy ); - m.scale( 1.0*vw/ww, 1.0*vh/wh ); - m.translate( -wx, -wy ); - } - if ( testf(WxF) ) { - if ( testf(VxF) ) - m = wxmat * m; - else - m = wxmat; - } - ixmat = m.invert( &invertible ); // invert matrix -} - -#else -void TQPainter::resetXForm() -{ - xlatex = 0; - xlatey = 0; - clearf( VxF ); -} -#endif // TQT_NO_TRANSFORMATIONS - - -extern bool qt_old_transformations; - -/*! - \internal - Maps a point from logical coordinates to device coordinates. -*/ - -void TQPainter::map( int x, int y, int *rx, int *ry ) const -{ -#ifndef TQT_NO_TRANSFORMATIONS - if ( qt_old_transformations ) { - switch ( txop ) { - case TxNone: - *rx = x; *ry = y; - break; - case TxTranslate: - // #### "Why no rounding here?", Warwick asked of Haavard. - *rx = int(x + dx()); - *ry = int(y + dy()); - break; - case TxScale: { - double tx = m11()*x + dx(); - double ty = m22()*y + dy(); - *rx = tx >= 0 ? int(tx + 0.5) : int(tx - 0.5); - *ry = ty >= 0 ? int(ty + 0.5) : int(ty - 0.5); - } break; - default: { - double tx = m11()*x + m21()*y+dx(); - double ty = m12()*x + m22()*y+dy(); - *rx = tx >= 0 ? int(tx + 0.5) : int(tx - 0.5); - *ry = ty >= 0 ? int(ty + 0.5) : int(ty - 0.5); - } break; - } - } else { - switch ( txop ) { - case TxNone: - *rx = x; - *ry = y; - break; - case TxTranslate: - *rx = tqRound( x + dx() ); - *ry = tqRound( y + dy() ); - break; - case TxScale: - *rx = tqRound( m11()*x + dx() ); - *ry = tqRound( m22()*y + dy() ); - break; - default: - *rx = tqRound( m11()*x + m21()*y+dx() ); - *ry = tqRound( m12()*x + m22()*y+dy() ); - break; - } - } -#else - *rx = x + xlatex; - *ry = y + xlatey; -#endif -} - -/*! - \internal - Maps a rectangle from logical coordinates to device coordinates. - This internal function does not handle rotation and/or shear. -*/ - -void TQPainter::map( int x, int y, int w, int h, - int *rx, int *ry, int *rw, int *rh ) const -{ -#ifndef TQT_NO_TRANSFORMATIONS - if ( qt_old_transformations ) { - switch ( txop ) { - case TxNone: - *rx = x; *ry = y; - *rw = w; *rh = h; - break; - case TxTranslate: - // #### "Why no rounding here?", Warwick asked of Haavard. - *rx = int(x + dx()); - *ry = int(y + dy()); - *rw = w; *rh = h; - break; - case TxScale: { - double tx1 = m11()*x + dx(); - double ty1 = m22()*y + dy(); - double tx2 = m11()*(x + w - 1) + dx(); - double ty2 = m22()*(y + h - 1) + dy(); - *rx = tqRound( tx1 ); - *ry = tqRound( ty1 ); - *rw = tqRound( tx2 ) - *rx + 1; - *rh = tqRound( ty2 ) - *ry + 1; - } break; - default: -#if defined(QT_CHECK_STATE) - tqWarning( "TQPainter::map: Internal error" ); -#endif - break; - } - } else { - switch ( txop ) { - case TxNone: - *rx = x; *ry = y; - *rw = w; *rh = h; - break; - case TxTranslate: - *rx = tqRound(x + dx() ); - *ry = tqRound(y + dy() ); - *rw = w; *rh = h; - break; - case TxScale: - *rx = tqRound( m11()*x + dx() ); - *ry = tqRound( m22()*y + dy() ); - *rw = tqRound( m11()*w ); - *rh = tqRound( m22()*h ); - break; - default: -#if defined(QT_CHECK_STATE) - tqWarning( "TQPainter::map: Internal error" ); -#endif - break; - } - } -#else - *rx = x + xlatex; - *ry = y + xlatey; - *rw = w; *rh = h; -#endif -} - -/*! - \internal - Maps a point from device coordinates to logical coordinates. -*/ - -void TQPainter::mapInv( int x, int y, int *rx, int *ry ) const -{ -#ifndef TQT_NO_TRANSFORMATIONS -#if defined(QT_CHECK_STATE) - if ( !txinv ) - tqWarning( "TQPainter::mapInv: Internal error" ); -#endif - if ( qt_old_transformations ) { - double tx = im11()*x + im21()*y+idx(); - double ty = im12()*x + im22()*y+idy(); - *rx = tx >= 0 ? int(tx + 0.5) : int(tx - 0.5); - *ry = ty >= 0 ? int(ty + 0.5) : int(ty - 0.5); - } else { - *rx = tqRound( im11()*x + im21()*y + idx() ); - *ry = tqRound( im12()*x + im22()*y + idy() ); - } -#else - *rx = x - xlatex; - *ry = y - xlatey; -#endif -} - -/*! - \internal - Maps a rectangle from device coordinates to logical coordinates. - Cannot handle rotation and/or shear. -*/ - -void TQPainter::mapInv( int x, int y, int w, int h, - int *rx, int *ry, int *rw, int *rh ) const -{ -#ifndef TQT_NO_TRANSFORMATIONS -#if defined(QT_CHECK_STATE) - if ( !txinv || txop == TxRotShear ) - tqWarning( "TQPainter::mapInv: Internal error" ); -#endif - if ( qt_old_transformations ) { - double tx = im11()*x + idx(); - double ty = im22()*y + idy(); - double tw = im11()*w; - double th = im22()*h; - *rx = tx >= 0 ? int(tx + 0.5) : int(tx - 0.5); - *ry = ty >= 0 ? int(ty + 0.5) : int(ty - 0.5); - *rw = tw >= 0 ? int(tw + 0.5) : int(tw - 0.5); - *rh = th >= 0 ? int(th + 0.5) : int(th - 0.5); - } else { - *rx = tqRound( im11()*x + idx() ); - *ry = tqRound( im22()*y + idy() ); - *rw = tqRound( im11()*w ); - *rh = tqRound( im22()*h ); - } -#else - *rx = x - xlatex; - *ry = y - xlatey; - *rw = w; - *rh = h; -#endif -} - - -/*! - Returns the point \a pv transformed from model coordinates to - device coordinates. - - \sa xFormDev(), TQWMatrix::map() -*/ - -TQPoint TQPainter::xForm( const TQPoint &pv ) const -{ -#ifndef TQT_NO_TRANSFORMATIONS - if ( txop == TxNone ) - return pv; - int x=pv.x(), y=pv.y(); - map( x, y, &x, &y ); - return TQPoint( x, y ); -#else - return TQPoint( pv.x()+xlatex, pv.y()+xlatey ); -#endif -} - -/*! - \overload - - Returns the rectangle \a rv transformed from model coordinates to - device coordinates. - - If world transformation is enabled and rotation or shearing has - been specified, then the bounding rectangle is returned. - - \sa xFormDev(), TQWMatrix::map() -*/ - -TQRect TQPainter::xForm( const TQRect &rv ) const -{ -#ifndef TQT_NO_TRANSFORMATIONS - if ( txop == TxNone ) - return rv; - if ( txop == TxRotShear ) { // rotation/shear - return xmat.mapRect( rv ); - } - // Just translation/scale - int x, y, w, h; - rv.rect( &x, &y, &w, &h ); - map( x, y, w, h, &x, &y, &w, &h ); - return TQRect( x, y, w, h ); -#else - return TQRect( rv.x()+xlatex, rv.y()+xlatey, rv.width(), rv.height() ); -#endif -} - -/*! - \overload - - Returns the point array \a av transformed from model coordinates - to device coordinates. - - \sa xFormDev(), TQWMatrix::map() -*/ - -TQPointArray TQPainter::xForm( const TQPointArray &av ) const -{ - TQPointArray a = av; -#ifndef TQT_NO_TRANSFORMATIONS - if ( txop != TxNone ) - { - return xmat * av; - } -#else - a.translate( xlatex, xlatey ); -#endif - return a; -} - -/*! - \overload - - Returns the point array \a av transformed from model coordinates - to device coordinates. The \a index is the first point in the - array and \a npoints denotes the number of points to be - transformed. If \a npoints is negative, all points from \a - av[index] until the last point in the array are transformed. - - The returned point array consists of the number of points that - were transformed. - - Example: - \code - TQPointArray a(10); - TQPointArray b; - b = painter.xForm(a, 2, 4); // b.size() == 4 - b = painter.xForm(a, 2, -1); // b.size() == 8 - \endcode - - \sa xFormDev(), TQWMatrix::map() -*/ - -TQPointArray TQPainter::xForm( const TQPointArray &av, int index, - int npoints ) const -{ - int lastPoint = npoints < 0 ? av.size() : index+npoints; - TQPointArray a( lastPoint-index ); - memcpy( a.data(), av.data()+index, (lastPoint-index)*sizeof( TQPoint ) ); -#ifndef TQT_NO_TRANSFORMATIONS - return xmat*a; -#else - a.translate( xlatex, xlatey ); - return a; -#endif -} - -/*! - \overload - - Returns the point \a pd transformed from device coordinates to - model coordinates. - - \sa xForm(), TQWMatrix::map() -*/ - -TQPoint TQPainter::xFormDev( const TQPoint &pd ) const -{ -#ifndef TQT_NO_TRANSFORMATIONS - if ( txop == TxNone ) - return pd; - if ( !txinv ) { - TQPainter *that = (TQPainter*)this; // mutable - that->updateInvXForm(); - } -#endif - int x=pd.x(), y=pd.y(); - mapInv( x, y, &x, &y ); - return TQPoint( x, y ); -} - -/*! - Returns the rectangle \a rd transformed from device coordinates to - model coordinates. - - If world transformation is enabled and rotation or shearing is - used, then the bounding rectangle is returned. - - \sa xForm(), TQWMatrix::map() -*/ - -TQRect TQPainter::xFormDev( const TQRect &rd ) const -{ -#ifndef TQT_NO_TRANSFORMATIONS - if ( txop == TxNone ) - return rd; - if ( !txinv ) { - TQPainter *that = (TQPainter*)this; // mutable - that->updateInvXForm(); - } - if ( txop == TxRotShear ) { // rotation/shear - return ixmat.mapRect( rd ); - } -#endif - // Just translation/scale - int x, y, w, h; - rd.rect( &x, &y, &w, &h ); - mapInv( x, y, w, h, &x, &y, &w, &h ); - return TQRect( x, y, w, h ); -} - -/*! - \overload - - Returns the point array \a ad transformed from device coordinates - to model coordinates. - - \sa xForm(), TQWMatrix::map() -*/ - -TQPointArray TQPainter::xFormDev( const TQPointArray &ad ) const -{ -#ifndef TQT_NO_TRANSFORMATIONS - if ( txop == TxNone ) - return ad; - if ( !txinv ) { - TQPainter *that = (TQPainter*)this; // mutable - that->updateInvXForm(); - } - return ixmat * ad; -#else - // ### - return ad; -#endif -} - -/*! - \overload - - Returns the point array \a ad transformed from device coordinates - to model coordinates. The \a index is the first point in the array - and \a npoints denotes the number of points to be transformed. If - \a npoints is negative, all points from \a ad[index] until the - last point in the array are transformed. - - The returned point array consists of the number of points that - were transformed. - - Example: - \code - TQPointArray a(10); - TQPointArray b; - b = painter.xFormDev(a, 1, 3); // b.size() == 3 - b = painter.xFormDev(a, 1, -1); // b.size() == 9 - \endcode - - \sa xForm(), TQWMatrix::map() -*/ - -TQPointArray TQPainter::xFormDev( const TQPointArray &ad, int index, - int npoints ) const -{ - int lastPoint = npoints < 0 ? ad.size() : index+npoints; - TQPointArray a( lastPoint-index ); - memcpy( a.data(), ad.data()+index, (lastPoint-index)*sizeof( TQPoint ) ); -#ifndef TQT_NO_TRANSFORMATIONS - if ( txop == TxNone ) - return a; - if ( !txinv ) { - TQPainter *that = (TQPainter*)this; // mutable - that->updateInvXForm(); - } - return ixmat * a; -#else - // ### - return a; -#endif -} - - -/*! - Fills the rectangle \a (x, y, w, h) with the \a brush. - - You can specify a TQColor as \a brush, since there is a TQBrush - constructor that takes a TQColor argument and creates a solid - pattern brush. - - \sa drawRect() -*/ - -void TQPainter::fillRect( int x, int y, int w, int h, const TQBrush &brush ) -{ - TQPen oldPen = pen(); // save pen - TQBrush oldBrush = this->brush(); // save brush - setPen( NoPen ); - setBrush( brush ); - drawRect( x, y, w, h ); // draw filled rect - setBrush( oldBrush ); // restore brush - setPen( oldPen ); // restore pen -} - - -/*! - \overload void TQPainter::setBrushOrigin( const TQPoint &p ) - - Sets the brush origin to point \a p. -*/ - -/*! - \overload void TQPainter::setWindow( const TQRect &r ) - - Sets the painter's window to rectangle \a r. -*/ - - -/*! - \overload void TQPainter::setViewport( const TQRect &r ) - - Sets the painter's viewport to rectangle \a r. -*/ - - -/*! - \fn bool TQPainter::hasClipping() const - - Returns TRUE if clipping has been set; otherwise returns FALSE. - - \sa setClipping() -*/ - -/*! - Returns the currently set clip region. Note that the clip region - is given in physical device coordinates and \e not subject to any - \link coordsys.html coordinate transformation \endlink if \a m is - equal to \c CoordDevice (the default). If \a m equals \c - CoordPainter the returned region is in model coordinates. - - \sa setClipRegion(), setClipRect(), setClipping() TQPainter::CoordinateMode -*/ -TQRegion TQPainter::clipRegion( CoordinateMode m ) const -{ - // ### FIXME in 4.0: - // If the transformation mode is CoordPainter, we should transform the - // clip region with painter transformations. - -#ifndef TQT_NO_TRANSFORMATIONS - TQRegion r; - if ( m == CoordDevice ) { - r = crgn; - } else { - if ( !txinv ) { - TQPainter *that = (TQPainter*)this; // mutable - that->updateInvXForm(); - } - - r = ixmat * crgn; - } - return r; -#else - return crgn; -#endif -} - -/*! - \fn void TQPainter::setClipRect( int x, int y, int w, int h, CoordinateMode m) - - Sets the clip region to the rectangle \a x, \a y, \a w, \a h and - enables clipping. The clip mode is set to \a m. - - If \a m is \c CoordDevice (the default), the coordinates given for - the clip region are taken to be physical device coordinates and - are \e not subject to any \link coordsys.html coordinate - transformations\endlink. If \a m is \c CoordPainter, the - coordinates given for the clip region are taken to be model - coordinates. - - \sa setClipRegion(), clipRegion(), setClipping() TQPainter::CoordinateMode -*/ - -/*! - \overload void TQPainter::drawPoint( const TQPoint &p ) - - Draws the point \a p. -*/ - - -/*! - \overload void TQPainter::moveTo( const TQPoint &p ) - - Moves to the point \a p. -*/ - -/*! - \overload void TQPainter::lineTo( const TQPoint &p ) - - Draws a line to the point \a p. -*/ - -/*! - \overload void TQPainter::drawLine( const TQPoint &p1, const TQPoint &p2 ) - - Draws a line from point \a p1 to point \a p2. -*/ - -/*! - \overload void TQPainter::drawRect( const TQRect &r ) - - Draws the rectangle \a r. -*/ - -/*! - \overload void TQPainter::drawWinFocusRect( const TQRect &r ) - - Draws rectangle \a r as a window focus rectangle. -*/ - -/*! - \overload void TQPainter::drawWinFocusRect( const TQRect &r, const TQColor &bgColor ) - - Draws rectangle \a r as a window focus rectangle using background - color \a bgColor. -*/ - - -#if !defined(TQ_WS_X11) && !defined(TQ_WS_MAC) -// The doc and X implementation of this functions is in qpainter_x11.cpp -void TQPainter::drawWinFocusRect( int, int, int, int, - bool, const TQColor & ) -{ - // do nothing, only called from X11 specific functions -} -#endif - - -/*! - \overload void TQPainter::drawRoundRect( const TQRect &r, int xRnd, int yRnd ) - - Draws a rounded rectangle \a r, rounding to the x position \a xRnd - and the y position \a yRnd on each corner. -*/ - -/*! - \overload void TQPainter::drawEllipse( const TQRect &r ) - - Draws the ellipse that fits inside rectangle \a r. -*/ - -/*! - \overload void TQPainter::drawArc( const TQRect &r, int a, int alen ) - - Draws the arc that fits inside the rectangle \a r with start angle - \a a and arc length \a alen. -*/ - -/*! - \overload void TQPainter::drawPie( const TQRect &r, int a, int alen ) - - Draws a pie segment that fits inside the rectangle \a r with start - angle \a a and arc length \a alen. -*/ - -/*! - \overload void TQPainter::drawChord( const TQRect &r, int a, int alen ) - - Draws a chord that fits inside the rectangle \a r with start angle - \a a and arc length \a alen. -*/ - -/*! - \overload void TQPainter::drawPixmap( const TQPoint &p, const TQPixmap &pm, const TQRect &sr ) - - Draws the rectangle \a sr of pixmap \a pm with its origin at point - \a p. -*/ - -/*! - \overload void TQPainter::drawPixmap( const TQPoint &p, const TQPixmap &pm ) - - Draws the pixmap \a pm with its origin at point \a p. -*/ - -void TQPainter::drawPixmap( const TQPoint &p, const TQPixmap &pm ) -{ - drawPixmap( p.x(), p.y(), pm, 0, 0, pm.width(), pm.height() ); -} - -#if !defined(TQT_NO_IMAGE_SMOOTHSCALE) || !defined(TQT_NO_PIXMAP_TRANSFORMATION) - -/*! - \overload - - Draws the pixmap \a pm into the rectangle \a r. The pixmap is - scaled to fit the rectangle, if image and rectangle size disagree. -*/ -void TQPainter::drawPixmap( const TQRect &r, const TQPixmap &pm ) -{ - int rw = r.width(); - int rh = r.height(); - int iw= pm.width(); - int ih = pm.height(); - if ( rw <= 0 || rh <= 0 || iw <= 0 || ih <= 0 ) - return; - bool scale = ( rw != iw || rh != ih ); - float scaleX = (float)rw/(float)iw; - float scaleY = (float)rh/(float)ih; - bool smooth = ( scaleX < 1.5 || scaleY < 1.5 ); - - if ( testf(ExtDev) ) { - TQPDevCmdParam param[2]; - param[0].rect = &r; - param[1].pixmap = ± -#if defined(TQ_WS_WIN) - if ( !pdev->cmd( TQPaintDevice::PdcDrawPixmap, this, param ) || !hdc ) - return; -#elif defined(TQ_WS_MAC) - if ( !pdev->cmd( TQPaintDevice::PdcDrawPixmap, this, param ) || !pdev->handle()) - return; -#else - if ( !pdev->cmd( TQPaintDevice::PdcDrawPixmap, this, param ) || !hd ) - return; -#endif - } - - TQPixmap pixmap = pm; - - if ( scale ) { -#ifndef TQT_NO_IMAGE_SMOOTHSCALE -# ifndef TQT_NO_PIXMAP_TRANSFORMATION - if ( smooth ) -# endif - { - TQImage i = pm.convertToImage(); - pixmap = TQPixmap( i.smoothScale( rw, rh ) ); - } -# ifndef TQT_NO_PIXMAP_TRANSFORMATION - else -# endif -#endif -#ifndef TQT_NO_PIXMAP_TRANSFORMATION - { - pixmap = pm.xForm( TQWMatrix( scaleX, 0, 0, scaleY, 0, 0 ) ); - } -#endif - } - drawPixmap( r.x(), r.y(), pixmap ); -} - -#endif - -/*! - \overload void TQPainter::drawImage( const TQPoint &, const TQImage &, const TQRect &sr, int conversionFlags = 0 ); - - Draws the rectangle \a sr from the image at the given point. -*/ - -/* - Draws at point \a p the \sr rect from image \a pm, using \a - conversionFlags if the image needs to be converted to a pixmap. - The default value for \a conversionFlags is 0; see - convertFromImage() for information about what other values do. - - This function may convert \a image to a pixmap and then draw it, if - device() is a TQPixmap or a TQWidget, or else draw it directly, if - device() is a TQPrinter or TQPicture. -*/ - -/*! - Draws at (\a x, \a y) the \a sw by \a sh area of pixels from (\a - sx, \a sy) in \a image, using \a conversionFlags if the image - needs to be converted to a pixmap. The default value for \a - conversionFlags is 0; see convertFromImage() for information about - what other values do. - - This function may convert \a image to a pixmap and then draw it, - if device() is a TQPixmap or a TQWidget, or else draw it directly, - if device() is a TQPrinter or TQPicture. - - Currently alpha masks of the image are ignored when painting on a TQPrinter. - - \sa drawPixmap() TQPixmap::convertFromImage() -*/ -void TQPainter::drawImage( int x, int y, const TQImage & image, - int sx, int sy, int sw, int sh, - int conversionFlags ) -{ - if ( !isActive() || image.isNull() ) - return; - - // right/bottom - if ( sw < 0 ) - sw = image.width() - sx; - if ( sh < 0 ) - sh = image.height() - sy; - - // Sanity-check clipping - if ( sx < 0 ) { - x -= sx; - sw += sx; - sx = 0; - } - if ( sw + sx > image.width() ) - sw = image.width() - sx; - if ( sy < 0 ) { - y -= sy; - sh += sy; - sy = 0; - } - if ( sh + sy > image.height() ) - sh = image.height() - sy; - - if ( sw <= 0 || sh <= 0 ) - return; - - bool all = image.rect().intersect(TQRect(sx,sy,sw,sh)) == image.rect(); - TQImage subimage = all ? image : image.copy(sx,sy,sw,sh); - - if ( testf(ExtDev) ) { - TQPDevCmdParam param[2]; - TQRect r( x, y, subimage.width(), subimage.height() ); - param[0].rect = &r; - param[1].image = &subimage; -#if defined(TQ_WS_WIN) - if ( !pdev->cmd( TQPaintDevice::PdcDrawImage, this, param ) || !hdc ) - return; -#elif defined(TQ_WS_MAC) - if(!pdev->cmd( TQPaintDevice::PdcDrawImage, this, param ) || !pdev->handle() ) - return; -#else - if ( !pdev->cmd( TQPaintDevice::PdcDrawImage, this, param ) || !hd ) - return; -#endif - } - - TQPixmap pm; - pm.convertFromImage( subimage, conversionFlags ); - drawPixmap( x, y, pm ); -} - -/*! - \overload void TQPainter::drawImage( const TQPoint &p, const TQImage &i, int conversion_flags ) - - Draws the image \a i at point \a p. - - If the image needs to be modified to fit in a lower-resolution - result (e.g. converting from 32-bit to 8-bit), use the \a - conversion_flags to specify how you'd prefer this to happen. - - \sa TQt::ImageConversionFlags -*/ -void TQPainter::drawImage( const TQPoint & p, const TQImage & i, - int conversion_flags ) -{ - drawImage(p, i, i.rect(), conversion_flags); -} - -#if !defined(TQT_NO_IMAGE_TRANSFORMATION) || !defined(TQT_NO_IMAGE_SMOOTHSCALE) - -/*! - \overload - - Draws the image \a i into the rectangle \a r. The image will be - scaled to fit the rectangle if image and rectangle dimensions - differ. -*/ -void TQPainter::drawImage( const TQRect &r, const TQImage &i ) -{ - int rw = r.width(); - int rh = r.height(); - int iw= i.width(); - int ih = i.height(); - if ( rw <= 0 || rh <= 0 || iw <= 0 || ih <= 0 ) - return; - - if ( testf(ExtDev) ) { - TQPDevCmdParam param[2]; - param[0].rect = &r; - param[1].image = &i; -#if defined(TQ_WS_WIN) - if ( !pdev->cmd( TQPaintDevice::PdcDrawImage, this, param ) || !hdc ) - return; -#elif defined(TQ_WS_MAC) - if ( !pdev->cmd( TQPaintDevice::PdcDrawImage, this, param ) || !pdev->handle() ) - return; -#else - if ( !pdev->cmd( TQPaintDevice::PdcDrawImage, this, param ) || !hd ) - return; -#endif - } - - - bool scale = ( rw != iw || rh != ih ); - float scaleX = (float)rw/(float)iw; - float scaleY = (float)rh/(float)ih; - bool smooth = ( scaleX < 1.5 || scaleY < 1.5 ); - - TQImage img = scale - ? ( -#if defined(TQT_NO_IMAGE_TRANSFORMATION) - i.smoothScale( rw, rh ) -#elif defined(TQT_NO_IMAGE_SMOOTHSCALE) - i.scale( rw, rh ) -#else - smooth ? i.smoothScale( rw, rh ) : i.scale( rw, rh ) -#endif - ) - : i; - - drawImage( r.x(), r.y(), img ); -} - -#endif - - -void bitBlt( TQPaintDevice *dst, int dx, int dy, - const TQImage *src, int sx, int sy, int sw, int sh, - int conversion_flags ) -{ - TQPixmap tmp; - if ( sx == 0 && sy == 0 - && (sw<0 || sw==src->width()) && (sh<0 || sh==src->height()) ) - { - tmp.convertFromImage( *src, conversion_flags ); - } else { - tmp.convertFromImage( src->copy( sx, sy, sw, sh, conversion_flags), - conversion_flags ); - } - bitBlt( dst, dx, dy, &tmp ); -} - - -/*! - \overload void TQPainter::drawTiledPixmap( const TQRect &r, const TQPixmap &pm, const TQPoint &sp ) - - Draws a tiled pixmap, \a pm, inside rectangle \a r with its origin - at point \a sp. -*/ - -/*! - \overload void TQPainter::drawTiledPixmap( const TQRect &r, const TQPixmap &pm ) - - Draws a tiled pixmap, \a pm, inside rectangle \a r. -*/ - -/*! - \overload void TQPainter::fillRect( const TQRect &r, const TQBrush &brush ) - - Fills the rectangle \a r using brush \a brush. -*/ - -/*! - \fn void TQPainter::eraseRect( int x, int y, int w, int h ) - - Erases the area inside \a x, \a y, \a w, \a h. Equivalent to - \c{fillRect( x, y, w, h, backgroundColor() )}. -*/ - -/*! - \overload void TQPainter::eraseRect( const TQRect &r ) - - Erases the area inside the rectangle \a r. -*/ - -/*! - \fn TQPainter::drawText( int x, int y, const TQString &, int len = -1, TextDirection dir = Auto ) - - \overload - - Draws the given text at position \a x, \a y. If \a len is -1 (the - default) all the text is drawn, otherwise the first \a len - characters are drawn. The text's direction is given by \a dir. - - \sa TQPainter::TextDirection -*/ - -/*! - \fn void TQPainter::drawText( int x, int y, int w, int h, int flags, - const TQString&, int len = -1, TQRect *br=0, - TQTextParag **internal=0 ) - - \overload - - Draws the given text within the rectangle starting at \a x, \a y, - with width \a w and height \a h. If \a len is -1 (the default) all - the text is drawn, otherwise the first \a len characters are - drawn. The text's flags that are given in the \a flags parameter - are \l{TQt::AlignmentFlags} and \l{TQt::TextFlags} OR'd together. \a - br (if not null) is set to the actual bounding rectangle of the - output. The \a internal parameter is for internal use only. -*/ - -/*! - \fn void TQPainter::drawText( const TQPoint &, const TQString &, int len = -1, TextDirection dir = Auto ); - - \overload - - Draws the text at the given point. - - \sa TQPainter::TextDirection -*/ - -/* - Draws the text in \a s at point \a p. If \a len is -1 the entire - string is drawn, otherwise just the first \a len characters. The - text's direction is specified by \a dir. -*/ - - -/*! - \fn void TQPainter::drawText( int x, int y, const TQString &, int pos, int len, TextDirection dir = Auto ); - - \overload - - Draws the text from position \a pos, at point \a (x, y). If \a len is - -1 the entire string is drawn, otherwise just the first \a len - characters. The text's direction is specified by \a dir. -*/ - -/*! - \fn void TQPainter::drawText( const TQPoint &p, const TQString &, int pos, int len, TextDirection dir = Auto ); - - Draws the text from position \a pos, at point \a p. If \a len is - -1 the entire string is drawn, otherwise just the first \a len - characters. The text's direction is specified by \a dir. - - Note that the meaning of \e y is not the same for the two - drawText() varieties. For overloads that take a simple \e x, \e y - pair (or a point), the \e y value is the text's baseline; for - overloads that take a rectangle, \e rect.y() is the top of the - rectangle and the text is aligned within that rectangle in - accordance with the alignment flags. - - \sa TQPainter::TextDirection -*/ - -/*! - \fn void TQPainter::drawTextItem(const TQPoint &, const TQTextItem &, int) - \internal -*/ - -static inline void fix_neg_rect( int *x, int *y, int *w, int *h ) -{ - if ( *w < 0 ) { - *w = -*w + 2; - *x -= *w - 1; - } - if ( *h < 0 ) { - *h = -*h + 2; - *y -= *h - 1; - } -} -void TQPainter::fix_neg_rect( int *x, int *y, int *w, int *h ) -{ - ::fix_neg_rect(x,y,w,h); -} - -// -// The drawText function takes two special parameters; 'internal' and 'brect'. -// -// The 'internal' parameter contains a pointer to an array of encoded -// information that keeps internal geometry data. -// If the drawText function is called repeatedly to display the same text, -// it makes sense to calculate text width and linebreaks the first time, -// and use these parameters later to print the text because we save a lot of -// CPU time. -// The 'internal' parameter will not be used if it is a null pointer. -// The 'internal' parameter will be generated if it is not null, but points -// to a null pointer, i.e. internal != 0 && *internal == 0. -// The 'internal' parameter will be used if it contains a non-null pointer. -// -// If the 'brect parameter is a non-null pointer, then the bounding rectangle -// of the text will be returned in 'brect'. -// - -/*! - \overload - - Draws at most \a len characters from \a str in the rectangle \a r. - - This function draws formatted text. The \a tf text format is - really of type \l TQt::AlignmentFlags and \l TQt::TextFlags OR'd - together. - - Horizontal alignment defaults to AlignAuto and vertical alignment - defaults to AlignTop. - - \a brect (if not null) is set to the actual bounding rectangle of - the output. \a internal is, yes, internal. - - \sa boundingRect() -*/ - -void TQPainter::drawText( const TQRect &r, int tf, - const TQString& str, int len, TQRect *brect, - TQTextParag **internal ) -{ - if ( !isActive() ) - return; - if ( len < 0 ) - len = str.length(); - if ( len == 0 ) // empty string - return; - - if ( testf(DirtyFont|ExtDev) ) { - if ( testf(DirtyFont) ) - updateFont(); - if ( testf(ExtDev) && (tf & DontPrint) == 0 ) { - TQPDevCmdParam param[3]; - TQString newstr = str; - newstr.truncate( len ); - param[0].rect = &r; - param[1].ival = tf; - param[2].str = &newstr; - if ( pdev->devType() != TQInternal::Printer ) { -#if defined(TQ_WS_WIN) - if ( !pdev->cmd( TQPaintDevice::PdcDrawText2Formatted, - this, param) || - !hdc ) - return; // TQPrinter wants PdcDrawText2 -#elif defined(TQ_WS_MAC) - if ( !pdev->cmd( TQPaintDevice::PdcDrawText2Formatted, this, param) || - !pdev->handle()) - return; // TQPrinter wants PdcDrawText2 -#else - if ( !pdev->cmd( TQPaintDevice::PdcDrawText2Formatted, - this, param) || - !hd ) - return; // TQPrinter wants PdcDrawText2 -#endif - } - } - } - - qt_format_text(font(), r, tf, str, len, brect, - tabstops, tabarray, tabarraylen, internal, this); -} - -//#define QT_FORMAT_TEXT_DEBUG - -#define TQChar_linesep TQChar(0x2028U) - -void qt_format_text( const TQFont& font, const TQRect &_r, - int tf, const TQString& str, int len, TQRect *brect, - int tabstops, int* tabarray, int tabarraylen, - TQTextParag **, TQPainter* painter ) -{ - // we need to copy r here to protect against the case (&r == brect). - TQRect r( _r ); - - bool dontclip = (tf & TQt::DontClip) == TQt::DontClip; - bool wordbreak = (tf & TQt::WordBreak) == TQt::WordBreak; - bool singleline = (tf & TQt::SingleLine) == TQt::SingleLine; - bool showprefix = (tf & TQt::ShowPrefix) == TQt::ShowPrefix; - bool noaccel = ( tf & TQt::NoAccel ) == TQt::NoAccel; - - bool isRightToLeft = str.isRightToLeft(); - if ( ( tf & TQt::AlignHorizontal_Mask ) == TQt::AlignAuto ) - tf |= isRightToLeft ? TQt::AlignRight : TQt::AlignLeft; - - bool expandtabs = ( (tf & TQt::ExpandTabs) && - ( ( (tf & TQt::AlignLeft) && !isRightToLeft ) || - ( (tf & TQt::AlignRight) && isRightToLeft ) ) ); - - if ( !painter ) - tf |= TQt::DontPrint; - - int maxUnderlines = 0; - int numUnderlines = 0; - int underlinePositionStack[32]; - int *underlinePositions = underlinePositionStack; - - TQFont fnt(painter ? (painter->pfont ? *painter->pfont : painter->cfont) : font); - TQFontMetrics fm( fnt ); - - TQString text = str; - // str.setLength() always does a deep copy, so the replacement - // code below is safe. - text.setLength( len ); - // compatible behaviour to the old implementation. Replace - // tabs by spaces - TQChar *chr = (TQChar*)text.unicode(); - const TQChar *end = chr + len; - bool haveLineSep = FALSE; - while ( chr != end ) { - if ( *chr == '\r' || ( singleline && *chr == '\n' ) ) { - *chr = ' '; - } else if ( *chr == '\n' ) { - *chr = TQChar_linesep; - haveLineSep = TRUE; - } else if ( *chr == '&' ) { - ++maxUnderlines; - } - ++chr; - } - if ( !expandtabs ) { - chr = (TQChar*)text.unicode(); - while ( chr != end ) { - if ( *chr == '\t' ) - *chr = ' '; - ++chr; - } - } else if (!tabarraylen && !tabstops) { - tabstops = fm.width('x')*8; - } - - if ( noaccel || showprefix ) { - if ( maxUnderlines > 32 ) - underlinePositions = new int[maxUnderlines]; - TQChar *cout = (TQChar*)text.unicode(); - TQChar *cin = cout; - int l = len; - while ( l ) { - if ( *cin == '&' ) { - ++cin; - --l; - if ( !l ) - break; - if ( *cin != '&' ) - underlinePositions[numUnderlines++] = cout - text.unicode(); - } - *cout = *cin; - ++cout; - ++cin; - --l; - } - uint newlen = cout - text.unicode(); - if ( newlen != text.length()) - text.setLength( newlen ); - } - - // no need to do extra work for underlines if we don't paint - if ( tf & TQt::DontPrint ) - numUnderlines = 0; - - int height = 0; - int left = r.width(); - int right = 0; - - TQTextLayout textLayout( text, fnt ); - int rb = TQMAX( 0, -fm.minRightBearing() ); - int lb = TQMAX( 0, -fm.minLeftBearing() ); - - if ( text.isEmpty() ) { - height = fm.height(); - left = right = 0; - tf |= TQPainter::DontPrint; - } else { - textLayout.beginLayout((haveLineSep || expandtabs || wordbreak) ? - TQTextLayout::MultiLine : - (tf & TQt::DontPrint) ? TQTextLayout::NoBidi : TQTextLayout::SingleLine ); - - // break underline chars into items of their own - for( int i = 0; i < numUnderlines; i++ ) { - textLayout.setBoundary( underlinePositions[i] ); - textLayout.setBoundary( underlinePositions[i]+1 ); - } - - int lineWidth = wordbreak ? TQMAX(0, r.width()-rb-lb) : INT_MAX; - if(!wordbreak) - tf |= TQt::IncludeTrailingSpaces; - - int leading = fm.leading(); - int asc = fm.ascent(); - int desc = fm.descent(); - height = -leading; - - //tqDebug("\n\nbeginLayout: lw = %d, rectwidth=%d", lineWidth , r.width()); - while ( !textLayout.atEnd() ) { - height += leading; - textLayout.beginLine( lineWidth == INT_MAX ? lineWidth : lineWidth ); - //tqDebug("-----beginLine( %d )-----", lineWidth ); - bool linesep = FALSE; - while ( 1 ) { - TQTextItem ti = textLayout.currentItem(); - //tqDebug("item: from=%d, ch=%x", ti.from(), text.unicode()[ti.from()].unicode() ); - if ( expandtabs && ti.isTab() ) { - int tw = 0; - int x = textLayout.widthUsed(); - if ( tabarraylen ) { -// tqDebug("tabarraylen=%d", tabarraylen ); - int tab = 0; - while ( tab < tabarraylen ) { - if ( tabarray[tab] > x ) { - tw = tabarray[tab] - x; - break; - } - ++tab; - } - } else { - tw = tabstops - (x % tabstops); - } - //tqDebug("tw = %d", tw ); - if ( tw ) - ti.setWidth( tw ); - } - if ( ti.isObject() && text.unicode()[ti.from()] == TQChar_linesep ) - linesep = TRUE; - - if ( linesep || textLayout.addCurrentItem() != TQTextLayout::Ok || textLayout.atEnd() ) - break; - } - - int ascent = asc, descent = desc, lineLeft, lineRight; - textLayout.setLineWidth( r.width()-rb-lb ); - textLayout.endLine( 0, height, tf, &ascent, &descent, - &lineLeft, &lineRight ); - //tqDebug("finalizing line: lw=%d ascent = %d, descent=%d lineleft=%d lineright=%d", lineWidth, ascent, descent,lineLeft, lineRight ); - left = TQMIN( left, lineLeft ); - right = TQMAX( right, lineRight ); - height += ascent + descent + 1; - if ( linesep ) - textLayout.nextItem(); - } - } - - int yoff = 0; - if ( tf & TQt::AlignBottom ) - yoff = r.height() - height; - else if ( tf & TQt::AlignVCenter ) - yoff = (r.height() - height)/2; - - if ( brect ) { - *brect = TQRect( r.x() + left, r.y() + yoff, right-left + lb+rb, height ); - //tqDebug("br = %d %d %d/%d, left=%d, right=%d", brect->x(), brect->y(), brect->width(), brect->height(), left, right); - } - - if (!(tf & TQPainter::DontPrint)) { - bool restoreClipping = FALSE; - bool painterHasClip = FALSE; - TQRegion painterClipRegion; - if ( !dontclip ) { -#ifndef TQT_NO_TRANSFORMATIONS - TQRegion reg = painter->xmat * r; -#else - TQRegion reg = r; - reg.translate( painter->xlatex, painter->xlatey ); -#endif - if ( painter->hasClipping() ) - reg &= painter->clipRegion(); - - painterHasClip = painter->hasClipping(); - painterClipRegion = painter->clipRegion(); - restoreClipping = TRUE; - painter->setClipRegion( reg ); - } else { - if ( painter->hasClipping() ){ - painterHasClip = painter->hasClipping(); - painterClipRegion = painter->clipRegion(); - restoreClipping = TRUE; - painter->setClipping( FALSE ); - } - } - - int cUlChar = 0; - int _tf = 0; - if (fnt.underline()) _tf |= TQt::Underline; - if (fnt.overline()) _tf |= TQt::Overline; - if (fnt.strikeOut()) _tf |= TQt::StrikeOut; - - //tqDebug("have %d items",textLayout.numItems()); - for ( int i = 0; i < textLayout.numItems(); i++ ) { - TQTextItem ti = textLayout.itemAt( i ); - //tqDebug("Item %d: from=%d, length=%d, space=%d x=%d", i, ti.from(), ti.length(), ti.isSpace(), ti.x() ); - if ( ti.isTab() || ti.isObject() ) - continue; - int textFlags = _tf; - if ( !noaccel && numUnderlines > cUlChar && ti.from() == underlinePositions[cUlChar] ) { - textFlags |= TQt::Underline; - cUlChar++; - } -#if defined(TQ_WS_X11) - if ( painter->bg_mode == TQt::OpaqueMode ) { - int h = ti.ascent() + ti.descent() + 1; - if (ti.y() + h < height) - // don't add leading to last line - h += fm.leading(); - qt_draw_background( painter, r.x()+lb + ti.x(), r.y() + yoff + ti.y() - ti.ascent(), - ti.width(), h); - } -#endif - painter->drawTextItem( r.x()+lb, r.y() + yoff, ti, textFlags ); - } - - if ( restoreClipping ) { - painter->setClipRegion( painterClipRegion ); - painter->setClipping( painterHasClip ); - } - } - - if ( underlinePositions != underlinePositionStack ) - delete [] underlinePositions; -} - -/*! - \overload - - Returns the bounding rectangle of the aligned text that would be - printed with the corresponding drawText() function using the first - \a len characters from \a str if \a len is > -1, or the whole of - \a str if \a len is -1. The drawing, and hence the bounding - rectangle, is constrained to the rectangle \a r, or to the - rectangle required to draw the text, whichever is the larger. - - The \a internal parameter should not be used. - - \sa drawText(), fontMetrics(), TQFontMetrics::boundingRect(), TQt::TextFlags -*/ - -TQRect TQPainter::boundingRect( const TQRect &r, int flags, - const TQString& str, int len, TQTextParag **internal ) -{ - TQRect brect; - if ( str.isEmpty() ) - brect.setRect( r.x(),r.y(), 0,0 ); - else - drawText( r, flags | DontPrint, str, len, &brect, internal ); - return brect; -} - -/*! - \fn TQRect TQPainter::boundingRect( int x, int y, int w, int h, int flags, const TQString&, int len = -1, TQTextParag **intern=0 ); - - Returns the bounding rectangle of the aligned text that would be - printed with the corresponding drawText() function using the first - \a len characters of the string if \a len is > -1, or the whole of - the string if \a len is -1. The drawing, and hence the bounding - rectangle, is constrained to the rectangle that begins at point \a - (x, y) with width \a w and hight \a h, or to the - rectangle required to draw the text, whichever is the larger. - - The \a flags argument is - the bitwise OR of the following flags: - \table - \header \i Flag \i Meaning - \row \i \c AlignAuto \i aligns according to the language, usually left. - \row \i \c AlignLeft \i aligns to the left border. - \row \i \c AlignRight \i aligns to the right border. - \row \i \c AlignHCenter \i aligns horizontally centered. - \row \i \c AlignTop \i aligns to the top border. - \row \i \c AlignBottom \i aligns to the bottom border. - \row \i \c AlignVCenter \i aligns vertically centered. - \row \i \c AlignCenter \i (== \c AlignHCenter | \c AlignVCenter). - \row \i \c SingleLine \i ignores newline characters in the text. - \row \i \c ExpandTabs \i expands tabs. - \row \i \c ShowPrefix \i interprets "&x" as "x". - \row \i \c WordBreak \i breaks the text to fit the rectangle. - \endtable - - Horizontal alignment defaults to \c AlignLeft and vertical - alignment defaults to \c AlignTop. - - If several of the horizontal or several of the vertical alignment flags - are set, the resulting alignment is undefined. - - The \a intern parameter should not be used. - - \sa TQt::TextFlags -*/ - - - -/***************************************************************************** - TQPen member functions - *****************************************************************************/ - -/*! - \class TQPen ntqpen.h - \brief The TQPen class defines how a TQPainter should draw lines and outlines - of shapes. - - \ingroup graphics - \ingroup images - \ingroup shared - \mainclass - - A pen has a style, width, color, cap style and join style. - - The pen style defines the line type. The default pen style is \c - TQt::SolidLine. Setting the style to \c NoPen tells the painter to - not draw lines or outlines. - - When drawing 1 pixel wide diagonal lines you can either use a very - fast algorithm (specified by a line width of 0, which is the - default), or a slower but more accurate algorithm (specified by a - line width of 1). For horizontal and vertical lines a line width - of 0 is the same as a line width of 1. The cap and join style have - no effect on 0-width lines. - - The pen color defines the color of lines and text. The default - line color is black. The TQColor documentation lists predefined - colors. - - The cap style defines how the end points of lines are drawn. The - join style defines how the joins between two lines are drawn when - multiple connected lines are drawn (TQPainter::drawPolyline() - etc.). The cap and join styles only apply to wide lines, i.e. when - the width is 1 or greater. - - Use the TQBrush class to specify fill styles. - - Example: - \code - TQPainter painter; - TQPen pen( red, 2 ); // red solid line, 2 pixels wide - painter.begin( &anyPaintDevice ); // paint something - painter.setPen( pen ); // set the red, wide pen - painter.drawRect( 40,30, 200,100 ); // draw a rectangle - painter.setPen( blue ); // set blue pen, 0 pixel width - painter.drawLine( 40,30, 240,130 ); // draw a diagonal in rectangle - painter.end(); // painting done - \endcode - - See the \l TQt::PenStyle enum type for a complete list of pen - styles. - - With reference to the end points of lines, for wide (non-0-width) - pens it depends on the cap style whether the end point is drawn or - not. TQPainter will try to make sure that the end point is drawn - for 0-width pens, but this cannot be absolutely guaranteed because - the underlying drawing engine is free to use any (typically - accelerated) algorithm for drawing 0-width lines. On all tested - systems, however, the end point of at least all non-diagonal lines - are drawn. - - A pen's color(), width(), style(), capStyle() and joinStyle() can - be set in the constructor or later with setColor(), setWidth(), - setStyle(), setCapStyle() and setJoinStyle(). Pens may also be - compared and streamed. - - \img pen-styles.png Pen styles - - \sa TQPainter, TQPainter::setPen() -*/ - - -/*! - \internal - Initializes the pen. -*/ - -void TQPen::init( const TQColor &color, uint width, uint linestyle ) -{ - data = new TQPenData; - TQ_CHECK_PTR( data ); - data->style = (PenStyle)(linestyle & MPenStyle); - data->width = width; - data->color = color; - data->linest = linestyle; -} - -/*! - Constructs a default black solid line pen with 0 width, which - renders lines 1 pixel wide (fast diagonals). -*/ - -TQPen::TQPen() -{ - init( TQt::black, 0, SolidLine ); // default pen -} - -/*! - Constructs a black pen with 0 width (fast diagonals) and style \a - style. - - \sa setStyle() -*/ - -TQPen::TQPen( PenStyle style ) -{ - init( TQt::black, 0, style ); -} - -/*! - Constructs a pen with the specified \a color, \a width and \a - style. - - \sa setWidth(), setStyle(), setColor() -*/ - -TQPen::TQPen( const TQColor &color, uint width, PenStyle style ) -{ - init( color, width, style ); -} - -/*! - Constructs a pen with the specified color \a cl and width \a w. - The pen style is set to \a s, the pen cap style to \a c and the - pen join style to \a j. - - A line width of 0 will produce a 1 pixel wide line using a fast - algorithm for diagonals. A line width of 1 will also produce a 1 - pixel wide line, but uses a slower more accurate algorithm for - diagonals. For horizontal and vertical lines a line width of 0 is - the same as a line width of 1. The cap and join style have no - effect on 0-width lines. - - \sa setWidth(), setStyle(), setColor() -*/ - -TQPen::TQPen( const TQColor &cl, uint w, PenStyle s, PenCapStyle c, - PenJoinStyle j ) -{ - init( cl, w, s | c | j ); -} - -/*! - Constructs a pen that is a copy of \a p. -*/ - -TQPen::TQPen( const TQPen &p ) -{ - data = p.data; - data->ref(); -} - -/*! - Destroys the pen. -*/ - -TQPen::~TQPen() -{ - if ( data->deref() ) - delete data; -} - - -/*! - Detaches from shared pen data to make sure that this pen is the - only one referring the data. - - If multiple pens share common data, this pen dereferences the data - and gets a copy of the data. Nothing is done if there is just a - single reference. -*/ - -void TQPen::detach() -{ - if ( data->count != 1 ) - *this = copy(); -} - - -/*! - Assigns \a p to this pen and returns a reference to this pen. -*/ - -TQPen &TQPen::operator=( const TQPen &p ) -{ - p.data->ref(); - if ( data->deref() ) - delete data; - data = p.data; - return *this; -} - - -/*! - Returns a \link shclass.html deep copy\endlink of the pen. -*/ - -TQPen TQPen::copy() const -{ - TQPen p( data->color, data->width, data->style, capStyle(), joinStyle() ); - return p; -} - - -/*! - \fn PenStyle TQPen::style() const - - Returns the pen style. - - \sa setStyle() -*/ - -/*! - Sets the pen style to \a s. - - See the \l TQt::PenStyle documentation for a list of all the - styles. - - \warning On Mac OS X the style setting (other than \c NoPen and \c - SolidLine) have no effect as they are not implemented by the - underlying system. - - \warning On Windows 95/98, the style setting (other than \c NoPen - and \c SolidLine) has no effect for lines with width greater than - 1. - - \sa style() -*/ - -void TQPen::setStyle( PenStyle s ) -{ - if ( data->style == s ) - return; - detach(); - data->style = s; - data->linest = (data->linest & ~MPenStyle) | s; -} - - -/*! - \fn uint TQPen::width() const - - Returns the pen width. - - \sa setWidth() -*/ - -/*! - Sets the pen width to \a w. - - A line width of 0 will produce a 1 pixel wide line using a fast - algorithm for diagonals. A line width of 1 will also produce a 1 - pixel wide line, but uses a slower more accurate algorithm for - diagonals. For horizontal and vertical lines a line width of 0 is - the same as a line width of 1. The cap and join style have no - effect on 0-width lines. - - \sa width() -*/ - -void TQPen::setWidth( uint w ) -{ - if ( data->width == w ) - return; - detach(); - data->width = w; -} - - -/*! - Returns the pen's cap style. - - \sa setCapStyle() -*/ -TQt::PenCapStyle TQPen::capStyle() const -{ - return (PenCapStyle)(data->linest & MPenCapStyle); -} - -/*! - Sets the pen's cap style to \a c. - - The default value is \c FlatCap. The cap style has no effect on - 0-width pens. - - \img pen-cap-styles.png Pen Cap Styles - - \warning On Windows 95/98 and Macintosh, the cap style setting has - no effect. Wide lines are rendered as if the cap style was \c - SquareCap. - - \sa capStyle() -*/ - -void TQPen::setCapStyle( PenCapStyle c ) -{ - if ( (data->linest & MPenCapStyle) == c ) - return; - detach(); - data->linest = (data->linest & ~MPenCapStyle) | c; -} - -/*! - Returns the pen's join style. - - \sa setJoinStyle() -*/ -TQt::PenJoinStyle TQPen::joinStyle() const -{ - return (PenJoinStyle)(data->linest & MPenJoinStyle); -} - -/*! - Sets the pen's join style to \a j. - - The default value is \c MiterJoin. The join style has no effect on - 0-width pens. - - \img pen-join-styles.png Pen Join Styles - - \warning On Windows 95/98 and Macintosh, the join style setting - has no effect. Wide lines are rendered as if the join style was \c - BevelJoin. - - \sa joinStyle() -*/ - -void TQPen::setJoinStyle( PenJoinStyle j ) -{ - if ( (data->linest & MPenJoinStyle) == j ) - return; - detach(); - data->linest = (data->linest & ~MPenJoinStyle) | j; -} - -/*! - \fn const TQColor &TQPen::color() const - - Returns the pen color. - - \sa setColor() -*/ - -/*! - Sets the pen color to \a c. - - \sa color() -*/ - -void TQPen::setColor( const TQColor &c ) -{ - detach(); - data->color = c; -} - - -/*! - \fn bool TQPen::operator!=( const TQPen &p ) const - - Returns TRUE if the pen is different from \a p; otherwise returns - FALSE. - - Two pens are different if they have different styles, widths or - colors. - - \sa operator==() -*/ - -/*! - Returns TRUE if the pen is equal to \a p; otherwise returns FALSE. - - Two pens are equal if they have equal styles, widths and colors. - - \sa operator!=() -*/ - -bool TQPen::operator==( const TQPen &p ) const -{ - return (p.data == data) || (p.data->linest == data->linest && - p.data->width == data->width && p.data->color == data->color); -} - - -/***************************************************************************** - TQPen stream functions - *****************************************************************************/ -#ifndef TQT_NO_DATASTREAM -/*! - \relates TQPen - - Writes the pen \a p to the stream \a s and returns a reference to - the stream. - - \sa \link datastreamformat.html Format of the TQDataStream operators \endlink -*/ - -TQDataStream &operator<<( TQDataStream &s, const TQPen &p ) -{ - // ### width() should not be restricted to 8-bit values - if ( s.version() < 3 ) - return s << (TQ_UINT8)p.style() << (TQ_UINT8)p.width() << p.color(); - else - return s << (TQ_UINT8)( p.style() | p.capStyle() | p.joinStyle() ) - << (TQ_UINT8)p.width() << p.color(); -} - -/*! - \relates TQPen - - Reads a pen from the stream \a s into \a p and returns a reference - to the stream. - - \sa \link datastreamformat.html Format of the TQDataStream operators \endlink -*/ - -TQDataStream &operator>>( TQDataStream &s, TQPen &p ) -{ - TQ_UINT8 style, width; - TQColor color; - s >> style; - s >> width; - s >> color; - p = TQPen( color, (uint)width, (TQt::PenStyle)style ); // owl - return s; -} -#endif //TQT_NO_DATASTREAM - -/***************************************************************************** - TQBrush member functions - *****************************************************************************/ - -/*! - \class TQBrush ntqbrush.h - - \brief The TQBrush class defines the fill pattern of shapes drawn by a TQPainter. - - \ingroup graphics - \ingroup images - \ingroup shared - - A brush has a style and a color. One of the brush styles is a - custom pattern, which is defined by a TQPixmap. - - The brush style defines the fill pattern. The default brush style - is \c NoBrush (depending on how you construct a brush). This style - tells the painter to not fill shapes. The standard style for - filling is \c SolidPattern. - - The brush color defines the color of the fill pattern. The TQColor - documentation lists the predefined colors. - - Use the TQPen class for specifying line/outline styles. - - Example: - \code - TQPainter painter; - TQBrush brush( yellow ); // yellow solid pattern - painter.begin( &anyPaintDevice ); // paint something - painter.setBrush( brush ); // set the yellow brush - painter.setPen( NoPen ); // do not draw outline - painter.drawRect( 40,30, 200,100 ); // draw filled rectangle - painter.setBrush( NoBrush ); // do not fill - painter.setPen( black ); // set black pen, 0 pixel width - painter.drawRect( 10,10, 30,20 ); // draw rectangle outline - painter.end(); // painting done - \endcode - - See the setStyle() function for a complete list of brush styles. - - \img brush-styles.png Brush Styles - - \sa TQPainter, TQPainter::setBrush(), TQPainter::setBrushOrigin() -*/ - - -/*! - \internal - Initializes the brush. -*/ - -void TQBrush::init( const TQColor &color, BrushStyle style ) -{ - data = new TQBrushData; - TQ_CHECK_PTR( data ); - data->style = style; - data->color = color; - data->pixmap = 0; -} - -/*! - Constructs a default black brush with the style \c NoBrush (will - not fill shapes). -*/ - -TQBrush::TQBrush() -{ - static TQBrushData* defBrushData = 0; - if ( !defBrushData ) { - static TQSharedCleanupHandler defBrushCleanup; - defBrushData = new TQBrushData; - defBrushData->style = NoBrush; - defBrushData->color = TQt::black; - defBrushData->pixmap = 0; - defBrushCleanup.set( &defBrushData ); - } - data = defBrushData; - data->ref(); -} - -/*! - Constructs a black brush with the style \a style. - - \sa setStyle() -*/ - -TQBrush::TQBrush( BrushStyle style ) -{ - init( TQt::black, style ); -} - -/*! - Constructs a brush with the color \a color and the style \a style. - - \sa setColor(), setStyle() -*/ - -TQBrush::TQBrush( const TQColor &color, BrushStyle style ) -{ - init( color, style ); -} - -/*! - Constructs a brush with the color \a color and a custom pattern - stored in \a pixmap. - - The color will only have an effect for monochrome pixmaps, i.e. - for TQPixmap::depth() == 1. - - Pixmap brushes are currently not supported when printing on X11. - - \sa setColor(), setPixmap() -*/ - -TQBrush::TQBrush( const TQColor &color, const TQPixmap &pixmap ) -{ - init( color, CustomPattern ); - setPixmap( pixmap ); -} - -/*! - Constructs a brush that is a \link shclass.html shallow - copy\endlink of \a b. -*/ - -TQBrush::TQBrush( const TQBrush &b ) -{ - data = b.data; - data->ref(); -} - -/*! - Destroys the brush. -*/ - -TQBrush::~TQBrush() -{ - if ( data->deref() ) { - delete data->pixmap; - delete data; - } -} - - -/*! - Detaches from shared brush data to make sure that this brush is - the only one referring the data. - - If multiple brushes share common data, this brush dereferences the - data and gets a copy of the data. Nothing is done if there is just - a single reference. -*/ - -void TQBrush::detach() -{ - if ( data->count != 1 ) - *this = copy(); -} - - -/*! - Assigns \a b to this brush and returns a reference to this brush. -*/ - -TQBrush &TQBrush::operator=( const TQBrush &b ) -{ - b.data->ref(); // beware of b = b - if ( data->deref() ) { - delete data->pixmap; - delete data; - } - data = b.data; - return *this; -} - - -/*! - Returns a \link shclass.html deep copy\endlink of the brush. -*/ - -TQBrush TQBrush::copy() const -{ - if ( data->style == CustomPattern ) { // brush has pixmap - TQBrush b( data->color, *data->pixmap ); - return b; - } else { // brush has std pattern - TQBrush b( data->color, data->style ); - return b; - } -} - - -/*! - \fn BrushStyle TQBrush::style() const - - Returns the brush style. - - \sa setStyle() -*/ - -/*! - Sets the brush style to \a s. - - The brush styles are: - \table - \header \i Pattern \i Meaning - \row \i NoBrush \i will not fill shapes (default). - \row \i SolidPattern \i solid (100%) fill pattern. - \row \i Dense1Pattern \i11 94% fill pattern. - \row \i Dense2Pattern \i11 88% fill pattern. - \row \i Dense3Pattern \i11 63% fill pattern. - \row \i Dense4Pattern \i11 50% fill pattern. - \row \i Dense5Pattern \i11 37% fill pattern. - \row \i Dense6Pattern \i11 12% fill pattern. - \row \i Dense7Pattern \i11 6% fill pattern. - \row \i HorPattern \i horizontal lines pattern. - \row \i VerPattern \i vertical lines pattern. - \row \i CrossPattern \i crossing lines pattern. - \row \i BDiagPattern \i diagonal lines (directed /) pattern. - \row \i FDiagPattern \i diagonal lines (directed \) pattern. - \row \i DiagCrossPattern \i diagonal crossing lines pattern. - \row \i CustomPattern \i set when a pixmap pattern is being used. - \endtable - - On Windows, dense and custom patterns cannot be transparent. - - See the \link #details Detailed Description\endlink for a picture - of all the styles. - - \sa style() -*/ - -void TQBrush::setStyle( BrushStyle s ) // set brush style -{ - if ( data->style == s ) - return; -#if defined(QT_CHECK_RANGE) - if ( s == CustomPattern ) - tqWarning( "TQBrush::setStyle: CustomPattern is for internal use" ); -#endif - detach(); - data->style = s; -} - - -/*! - \fn const TQColor &TQBrush::color() const - - Returns the brush color. - - \sa setColor() -*/ - -/*! - Sets the brush color to \a c. - - \sa color(), setStyle() -*/ - -void TQBrush::setColor( const TQColor &c ) -{ - detach(); - data->color = c; -} - - -/*! - \fn TQPixmap *TQBrush::pixmap() const - - Returns a pointer to the custom brush pattern, or 0 if no custom - brush pattern has been set. - - \sa setPixmap() -*/ - -/*! - Sets the brush pixmap to \a pixmap. The style is set to \c - CustomPattern. - - The current brush color will only have an effect for monochrome - pixmaps, i.e. for TQPixmap::depth() == 1. - - Pixmap brushes are currently not supported when printing on X11. - - \sa pixmap(), color() -*/ - -void TQBrush::setPixmap( const TQPixmap &pixmap ) -{ - detach(); - if ( data->pixmap ) - delete data->pixmap; - if ( pixmap.isNull() ) { - data->style = NoBrush; - data->pixmap = 0; - } else { - data->style = CustomPattern; - data->pixmap = new TQPixmap( pixmap ); - if ( data->pixmap->optimization() == TQPixmap::MemoryOptim ) - data->pixmap->setOptimization( TQPixmap::NormalOptim ); - } -} - - -/*! - \fn bool TQBrush::operator!=( const TQBrush &b ) const - - Returns TRUE if the brush is different from \a b; otherwise - returns FALSE. - - Two brushes are different if they have different styles, colors or - pixmaps. - - \sa operator==() -*/ - -/*! - Returns TRUE if the brush is equal to \a b; otherwise returns - FALSE. - - Two brushes are equal if they have equal styles, colors and - pixmaps. - - \sa operator!=() -*/ - -bool TQBrush::operator==( const TQBrush &b ) const -{ - return (b.data == data) || (b.data->style == data->style && - b.data->color == data->color && - b.data->pixmap == data->pixmap); -} - - -/*! - \fn inline double TQPainter::translationX() const - \internal -*/ - -/*! - \fn inline double TQPainter::translationY() const - \internal -*/ - - -/***************************************************************************** - TQBrush stream functions - *****************************************************************************/ -#ifndef TQT_NO_DATASTREAM -/*! - \relates TQBrush - - Writes the brush \a b to the stream \a s and returns a reference - to the stream. - - \sa \link datastreamformat.html Format of the TQDataStream operators \endlink -*/ - -TQDataStream &operator<<( TQDataStream &s, const TQBrush &b ) -{ - s << (TQ_UINT8)b.style() << b.color(); - if ( b.style() == TQt::CustomPattern ) -#ifndef TQT_NO_IMAGEIO - s << *b.pixmap(); -#else - tqWarning("No Image Brush I/O"); -#endif - return s; -} - -/*! - \relates TQBrush - - Reads the brush \a b from the stream \a s and returns a reference - to the stream. - - \sa \link datastreamformat.html Format of the TQDataStream operators \endlink -*/ - -TQDataStream &operator>>( TQDataStream &s, TQBrush &b ) -{ - TQ_UINT8 style; - TQColor color; - s >> style; - s >> color; - if ( style == TQt::CustomPattern ) { -#ifndef TQT_NO_IMAGEIO - TQPixmap pm; - s >> pm; - b = TQBrush( color, pm ); -#else - tqWarning("No Image Brush I/O"); -#endif - } - else - b = TQBrush( color, (TQt::BrushStyle)style ); - return s; -} -#endif // TQT_NO_DATASTREAM diff --git a/src/kernel/qpainter_p.h b/src/kernel/qpainter_p.h deleted file mode 100644 index 5123a64a4..000000000 --- a/src/kernel/qpainter_p.h +++ /dev/null @@ -1,66 +0,0 @@ -/**************************************************************************** -** -** Definition of some TQt private functions. -** -** Created : 000909 -** -** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#ifndef TQPAINTER_P_H -#define TQPAINTER_P_H - - -// -// W A R N I N G -// ------------- -// -// This file is not part of the TQt API. It exists for the convenience -// of qpainter.cpp and qfont.cpp. This header file may change -// from version to version without notice, or even be removed. -// -// We mean it. -// -// - -#ifndef QT_H -#endif // QT_H - -extern void qt_format_text( const TQFont& f, const TQRect &r, - int tf, const TQString& str, int len, TQRect *brect, - int tabstops, int* tabarray, int tabarraylen, - TQTextParag **internal, TQPainter* painter ); - - -#endif diff --git a/src/kernel/qpainter_x11.cpp b/src/kernel/qpainter_x11.cpp deleted file mode 100644 index bfb62de41..000000000 --- a/src/kernel/qpainter_x11.cpp +++ /dev/null @@ -1,3183 +0,0 @@ -/**************************************************************************** -** -** Implementation of TQPainter class for X11 -** -** Created : 940112 -** -** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. -** -** This file is part of the kernel module of the TQt GUI Toolkit. -** -** This file may be used under the terms of the GNU General -** Public License versions 2.0 or 3.0 as published by the Free -** Software Foundation and appearing in the files LICENSE.GPL2 -** and LICENSE.GPL3 included in the packaging of this file. -** Alternatively you may (at your option) use any later version -** of the GNU General Public License if such license has been -** publicly approved by Trolltech ASA (or its successors, if any) -** and the KDE Free TQt Foundation. -** -** Please review the following information to ensure GNU General -** Public Licensing requirements will be met: -** http://trolltech.com/products/qt/licenses/licensing/opensource/. -** If you are unsure which license is appropriate for your use, please -** review the following information: -** http://trolltech.com/products/qt/licenses/licensing/licensingoverview -** or contact the sales department at sales@trolltech.com. -** -** This file may be used under the terms of the Q Public License as -** defined by Trolltech ASA and appearing in the file LICENSE.TQPL -** included in the packaging of this file. Licensees holding valid TQt -** Commercial licenses may use this file in accordance with the TQt -** Commercial License Agreement provided with the Software. -** -** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, -** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR -** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted -** herein. -** -**********************************************************************/ - -#include "qplatformdefs.h" - -#include "ntqfont.h" -#include "ntqpainter.h" -#include "tqwidget.h" -#include "tqbitmap.h" -#include "ntqpixmapcache.h" -#include "tqtextcodec.h" -#include "ntqpaintdevicemetrics.h" - -#include "qt_x11_p.h" - -#include "tqtextlayout_p.h" -#include "qfontdata_p.h" -#include "qfontengine_p.h" -#include "tqtextengine_p.h" - -#include - -// paintevent magic to provide Windows semantics on X11 -static TQRegion* paintEventClipRegion = 0; -static TQPaintDevice* paintEventDevice = 0; - -void qt_set_paintevent_clipping( TQPaintDevice* dev, const TQRegion& region) -{ - if ( !paintEventClipRegion ) - paintEventClipRegion = new TQRegion( region ); - else - *paintEventClipRegion = region; - paintEventDevice = dev; -} - -void qt_clear_paintevent_clipping() -{ - delete paintEventClipRegion; - paintEventClipRegion = 0; - paintEventDevice = 0; -} - -class TQWFlagWidget : public TQWidget -{ -public: - void setWState( WFlags f ) { TQWidget::setWState(f); } - void clearWState( WFlags f ) { TQWidget::clearWState(f); } - void setWFlags( WFlags f ) { TQWidget::setWFlags(f); } - void clearWFlags( WFlags f ) { TQWidget::clearWFlags(f); } -}; - -void qt_erase_region( TQWidget* w, const TQRegion& region) -{ - TQRegion reg = region; - - if ( TQPainter::redirect(w) || (!w->isTopLevel() && w->backgroundPixmap() - && w->backgroundOrigin() != TQWidget::WidgetOrigin) ) { - TQPoint offset = w->backgroundOffset(); - int ox = offset.x(); - int oy = offset.y(); - - bool unclipped = w->testWFlags( TQt::WPaintUnclipped ); - if ( unclipped ) - ((TQWFlagWidget*)w)->clearWFlags( TQt::WPaintUnclipped ); - TQPainter p( w ); - p.setClipRegion( region ); // automatically includes paintEventDevice if required - if ( w->backgroundPixmap() ) - p.drawTiledPixmap( 0, 0, w->width(), w->height(), - *w->backgroundPixmap(), ox, oy ); - else - p.fillRect( w->rect(), w->eraseColor() ); - if ( unclipped ) - ((TQWFlagWidget*)w)->setWFlags( TQt::WPaintUnclipped ); - return; - } - - if ( w == paintEventDevice && paintEventClipRegion ) - reg = paintEventClipRegion->intersect( reg ); - - TQMemArray r = reg.rects(); - for (uint i=0; ix11Display(), w->winId(), - rr.x(), rr.y(), rr.width(), rr.height(), False ); - } -} - -void qt_erase_rect( TQWidget* w, const TQRect& r) -{ - if ( TQPainter::redirect(w) || w == paintEventDevice - || w->backgroundOrigin() != TQWidget::WidgetOrigin ) - qt_erase_region( w, r ); - else - XClearArea( w->x11Display(), w->winId(), r.x(), r.y(), r.width(), r.height(), False ); - -} - -#ifdef TQT_NO_XFTFREETYPE -static const TQt::HANDLE rendhd = 0; -#endif - -// hack, so we don't have to make TQRegion::clipRectangles() public or include -// X11 headers in ntqregion.h -inline void *qt_getClipRects( const TQRegion &r, int &num ) -{ - return r.clipRectangles( num ); -} - -static inline void x11SetClipRegion(Display *dpy, GC gc, GC gc2, TQt::HANDLE draw, const TQRegion &r) -{ - int num; - XRectangle *rects = (XRectangle *)qt_getClipRects( r, num ); - - if (gc) - XSetClipRectangles( dpy, gc, 0, 0, rects, num, YXBanded ); - if (gc2) - XSetClipRectangles( dpy, gc2, 0, 0, rects, num, YXBanded ); - -#ifndef TQT_NO_XFTFREETYPE - if (draw) - XftDrawSetClipRectangles((XftDraw *) draw, 0, 0, rects, num); -#else - Q_UNUSED(draw); -#endif // TQT_NO_XFTFREETYPE -} - -static inline void x11ClearClipRegion(Display *dpy, GC gc, GC gc2, TQt::HANDLE draw) -{ - if (gc) - XSetClipMask(dpy, gc, None); - if (gc2) - XSetClipMask(dpy, gc2, None); - -#ifndef TQT_NO_XFTFREETYPE - if (draw) { -# ifdef QT_XFT2 - XftDrawSetClip((XftDraw *) draw, None); -# else - // stupid Xft1 - Picture pict = XftDrawPicture((XftDraw *) draw); - XRenderPictureAttributes pattr; - pattr.clip_mask = None; - XRenderChangePicture(dpy, pict, CPClipMask, &pattr); -# endif // QT_XFT2 - } -#else - Q_UNUSED(draw); -#endif // TQT_NO_XFTFREETYPE -} - - -/***************************************************************************** - Trigonometric function for TQPainter - - We have implemented simple sine and cosine function that are called from - TQPainter::drawPie() and TQPainter::drawChord() when drawing the outline of - pies and chords. - These functions are slower and less accurate than math.h sin() and cos(), - but with still around 1/70000th sec. execution time (on a 486DX2-66) and - 8 digits accuracy, it should not be the bottleneck in drawing these shapes. - The advantage is that you don't have to link in the math library. - *****************************************************************************/ - -const double Q_PI = 3.14159265358979323846; // pi -const double Q_2PI = 6.28318530717958647693; // 2*pi -const double Q_PI2 = 1.57079632679489661923; // pi/2 - - -#if defined(Q_CC_GNU) && defined(Q_OS_AIX) -// AIX 4.2 gcc 2.7.2.3 gets internal error. -static int tqRoundAIX( double d ) -{ - return tqRound(d); -} -#define tqRound tqRoundAIX -#endif - - -#if defined(Q_CC_GNU) && defined(__i386__) - -inline double qcos( double a ) -{ - double r; - __asm__ ( - "fcos" - : "=t" (r) : "0" (a) ); - return(r); -} - -inline double qsin( double a ) -{ - double r; - __asm__ ( - "fsin" - : "=t" (r) : "0" (a) ); - return(r); -} - -double qsincos( double a, bool calcCos=FALSE ) -{ - return calcCos ? qcos(a) : qsin(a); -} - -#else - -double qsincos( double a, bool calcCos=FALSE ) -{ - if ( calcCos ) // calculate cosine - a -= Q_PI2; - if ( a >= Q_2PI || a <= -Q_2PI ) { // fix range: -2*pi < a < 2*pi - int m = (int)(a/Q_2PI); - a -= Q_2PI*m; - } - if ( a < 0.0 ) // 0 <= a < 2*pi - a += Q_2PI; - int sign = a > Q_PI ? -1 : 1; - if ( a >= Q_PI ) - a = Q_2PI - a; - if ( a >= Q_PI2 ) - a = Q_PI - a; - if ( calcCos ) - sign = -sign; - double a2 = a*a; // here: 0 <= a < pi/4 - double a3 = a2*a; // make taylor sin sum - double a5 = a3*a2; - double a7 = a5*a2; - double a9 = a7*a2; - double a11 = a9*a2; - return (a-a3/6+a5/120-a7/5040+a9/362880-a11/39916800)*sign; -} - -inline double qsin( double a ) { return qsincos(a, FALSE); } -inline double qcos( double a ) { return qsincos(a, TRUE); } - -#endif - - -/***************************************************************************** - TQPainter internal GC (Graphics Context) allocator. - - The GC allocator offers two functions; alloc_gc() and free_gc() that - reuse GC objects instead of calling XCreateGC() and XFreeGC(), which - are a whole lot slower. - *****************************************************************************/ - -struct TQGC -{ - GC gc; - char in_use; - bool mono; - int scrn; -}; - -const int gc_array_size = 256; -static TQGC gc_array[gc_array_size]; // array of GCs -static bool gc_array_init = FALSE; - - -static void init_gc_array() -{ - if ( !gc_array_init ) { - memset( gc_array, 0, gc_array_size*sizeof(TQGC) ); - gc_array_init = TRUE; - } -} - -static void cleanup_gc_array( Display *dpy ) -{ - TQGC *p = gc_array; - int i = gc_array_size; - if ( gc_array_init ) { - while ( i-- ) { - if ( p->gc ) // destroy GC - XFreeGC( dpy, p->gc ); - p++; - } - gc_array_init = FALSE; - } -} - -// #define DONT_USE_GC_ARRAY - -static GC alloc_gc( Display *dpy, int scrn, Drawable hd, bool monochrome=FALSE, - bool privateGC = FALSE ) -{ -#if defined(DONT_USE_GC_ARRAY) - privateGC = TRUE; // will be slower -#endif - if ( privateGC ) { - GC gc = XCreateGC( dpy, hd, 0, 0 ); - XSetGraphicsExposures( dpy, gc, False ); - return gc; - } - TQGC *p = gc_array; - int i = gc_array_size; - if ( !gc_array_init ) // not initialized - init_gc_array(); - while ( i-- ) { - if ( !p->gc ) { // create GC (once) - p->gc = XCreateGC( dpy, hd, 0, 0 ); - p->scrn = scrn; - XSetGraphicsExposures( dpy, p->gc, False ); - p->in_use = FALSE; - p->mono = monochrome; - } - if ( !p->in_use && p->mono == monochrome && p->scrn == scrn ) { - p->in_use = TRUE; // available/compatible GC - return p->gc; - } - p++; - } -#if defined(QT_CHECK_NULL) - tqWarning( "TQPainter: Internal error; no available GC" ); -#endif - GC gc = XCreateGC( dpy, hd, 0, 0 ); - XSetGraphicsExposures( dpy, gc, False ); - return gc; -} - -static void free_gc( Display *dpy, GC gc, bool privateGC = FALSE ) -{ -#if defined(DONT_USE_GC_ARRAY) - privateGC = TRUE; // will be slower -#endif - if ( privateGC ) { - Q_ASSERT( dpy != 0 ); - XFreeGC( dpy, gc ); - return; - } - TQGC *p = gc_array; - int i = gc_array_size; - if ( gc_array_init ) { - while ( i-- ) { - if ( p->gc == gc ) { - p->in_use = FALSE; // set available - XSetClipMask( dpy, gc, None ); // make it reusable - XSetFunction( dpy, gc, GXcopy ); - XSetFillStyle( dpy, gc, FillSolid ); - XSetTSOrigin( dpy, gc, 0, 0 ); - return; - } - p++; - } - } - - // not found in gc_array - XFreeGC(dpy, gc); -} - - -/***************************************************************************** - TQPainter internal GC (Graphics Context) cache for solid pens and - brushes. - - The GC cache makes a significant contribution to speeding up - drawing. Setting new pen and brush colors will make the painter - look for another GC with the same color instead of changing the - color value of the GC currently in use. The cache structure is - optimized for fast lookup. Only solid line pens with line width 0 - and solid brushes are cached. - - In addition, stored GCs may have an implicit clipping region - set. This prevents any drawing outside paint events. Both - updatePen() and updateBrush() keep track of the validity of this - clipping region by storing the clip_serial number in the cache. - -*****************************************************************************/ - -struct TQGCC // cached GC -{ - GC gc; - uint pix; - int count; - int hits; - uint clip_serial; - int scrn; -}; - -const int gc_cache_size = 29; // multiply by 4 -static TQGCC *gc_cache_buf; -static TQGCC *gc_cache[4*gc_cache_size]; -static bool gc_cache_init = FALSE; -static uint gc_cache_clip_serial = 0; - - -static void init_gc_cache() -{ - if ( !gc_cache_init ) { - gc_cache_init = TRUE; - gc_cache_clip_serial = 0; - TQGCC *g = gc_cache_buf = new TQGCC[4*gc_cache_size]; - memset( g, 0, 4*gc_cache_size*sizeof(TQGCC) ); - for ( int i=0; i<4*gc_cache_size; i++ ) - gc_cache[i] = g++; - } -} - - -// #define GC_CACHE_STAT -#if defined(GC_CACHE_STAT) -#include "tqtextstream.h" -#include "tqbuffer.h" - -static int g_numhits = 0; -static int g_numcreates = 0; -static int g_numfaults = 0; -#endif - - -static void cleanup_gc_cache() -{ - if ( !gc_cache_init ) - return; -#if defined(GC_CACHE_STAT) - tqDebug( "Number of cache hits = %d", g_numhits ); - tqDebug( "Number of cache creates = %d", g_numcreates ); - tqDebug( "Number of cache faults = %d", g_numfaults ); - for ( int i=0; igc ? 'X' : '-') << ',' << g->hits << ',' - << g->count << '\t'; - } - s << '\0'; - tqDebug( str ); - buf.close(); - } -#endif - delete [] gc_cache_buf; - gc_cache_init = FALSE; -} - - -static bool obtain_gc( void **ref, GC *gc, uint pix, Display *dpy, int scrn, - TQt::HANDLE hd, uint painter_clip_serial ) -{ - if ( !gc_cache_init ) - init_gc_cache(); - - int k = (pix % gc_cache_size) * 4; - TQGCC *g = gc_cache[k]; - TQGCC *prev = 0; - -#define NOMATCH (g->gc && (g->pix != pix || g->scrn != scrn || \ - (g->clip_serial > 0 && g->clip_serial != painter_clip_serial))) - - if ( NOMATCH ) { - prev = g; - g = gc_cache[++k]; - if ( NOMATCH ) { - prev = g; - g = gc_cache[++k]; - if ( NOMATCH ) { - prev = g; - g = gc_cache[++k]; - if ( NOMATCH ) { - if ( g->count == 0 && g->scrn == scrn) { // steal this GC - g->pix = pix; - g->count = 1; - g->hits = 1; - g->clip_serial = 0; - XSetForeground( dpy, g->gc, pix ); - XSetClipMask(dpy, g->gc, None); - gc_cache[k] = prev; - gc_cache[k-1] = g; - *ref = (void *)g; - *gc = g->gc; - return TRUE; - } else { // all GCs in use -#if defined(GC_CACHE_STAT) - g_numfaults++; -#endif - *ref = 0; - return FALSE; - } - } - } - } - } - -#undef NOMATCH - - *ref = (void *)g; - - if ( g->gc ) { // reuse existing GC -#if defined(GC_CACHE_STAT) - g_numhits++; -#endif - *gc = g->gc; - g->count++; - g->hits++; - if ( prev && g->hits > prev->hits ) { // maintain LRU order - gc_cache[k] = prev; - gc_cache[k-1] = g; - } - return TRUE; - } else { // create new GC -#if defined(GC_CACHE_STAT) - g_numcreates++; -#endif - g->gc = alloc_gc( dpy, scrn, hd, FALSE ); - g->scrn = scrn; - g->pix = pix; - g->count = 1; - g->hits = 1; - g->clip_serial = 0; - *gc = g->gc; - return FALSE; - } -} - -static inline void release_gc( void *ref ) -{ - ((TQGCC*)ref)->count--; -} - -/***************************************************************************** - TQPainter member functions - *****************************************************************************/ - -/*! - \internal - - Internal function that initializes the painter. -*/ - -void TQPainter::initialize() -{ - init_gc_array(); - init_gc_cache(); -} - -/*! - \internal - - Internal function that cleans up the painter. -*/ - -void TQPainter::cleanup() -{ - cleanup_gc_cache(); - cleanup_gc_array( TQPaintDevice::x11AppDisplay() ); - TQPointArray::cleanBuffers(); -} - -/*! - \internal - - Internal function that destroys up the painter. -*/ - -void TQPainter::destroy() -{ - -} - -void TQPainter::init() -{ - d = 0; - flags = IsStartingUp; - bg_col = white; // default background color - bg_mode = TransparentMode; // default background mode - rop = CopyROP; // default ROP - tabstops = 0; // default tabbing - tabarray = 0; - tabarraylen = 0; - ps_stack = 0; - wm_stack = 0; - gc = gc_brush = 0; - pdev = 0; - dpy = 0; - txop = txinv = 0; - penRef = brushRef = 0; - clip_serial = 0; - pfont = 0; - block_ext = FALSE; -} - - -/*! - \fn const TQFont &TQPainter::font() const - - Returns the currently set painter font. - - \sa setFont(), TQFont -*/ - -/*! - Sets the painter's font to \a font. - - This font is used by subsequent drawText() functions. The text - color is the same as the pen color. - - \sa font(), drawText() -*/ - -void TQPainter::setFont( const TQFont &font ) -{ -#if defined(QT_CHECK_STATE) - if ( !isActive() ) - tqWarning( "TQPainter::setFont: Will be reset by begin()" ); -#endif - if ( cfont.d != font.d ) { - cfont = font; - cfont.x11SetScreen( scrn ); - setf(DirtyFont); - } -} - - -void TQPainter::updateFont() -{ - if (!isActive()) - return; - - clearf(DirtyFont); - if ( testf(ExtDev) ) { - if (pdev->devType() == TQInternal::Printer) { - if ( pfont ) delete pfont; - pfont = new TQFont( cfont.d, pdev ); - } - TQPDevCmdParam param[1]; - param[0].font = &cfont; - if ( !pdev->cmd( TQPaintDevice::PdcSetFont, this, param ) || !hd ) - return; - } - setf(NoCache); - if ( penRef ) - updatePen(); // force a non-cached GC -} - - -void TQPainter::updatePen() -{ - if (!isActive()) - return; - - if ( testf(ExtDev) ) { - TQPDevCmdParam param[1]; - param[0].pen = &cpen; - if ( !pdev->cmd( TQPaintDevice::PdcSetPen, this, param ) || !hd ) - return; - } - - int ps = cpen.style(); - bool cacheIt = !testf(ClipOn|MonoDev|NoCache) && - (ps == NoPen || ps == SolidLine) && - cpen.width() == 0 && rop == CopyROP; - - bool obtained = FALSE; - bool internclipok = hasClipping(); - if ( cacheIt ) { - if ( gc ) { - if ( penRef ) - release_gc( penRef ); - else - free_gc( dpy, gc ); - } - obtained = obtain_gc(&penRef, &gc, cpen.color().pixel(scrn), dpy, scrn, - hd, clip_serial); - if ( !obtained && !penRef ) - gc = alloc_gc( dpy, scrn, hd, FALSE ); - } else { - if ( gc ) { - if ( penRef ) { - release_gc( penRef ); - penRef = 0; - gc = alloc_gc( dpy, scrn, hd, testf(MonoDev) ); - } else { - internclipok = TRUE; - } - } else { - gc = alloc_gc( dpy, scrn, hd, testf(MonoDev), testf(UsePrivateCx) ); - } - } - - if ( !internclipok ) { - if ( pdev == paintEventDevice && paintEventClipRegion ) { - if ( penRef &&((TQGCC*)penRef)->clip_serial < gc_cache_clip_serial ) { - x11SetClipRegion( dpy, gc, 0, rendhd, *paintEventClipRegion ); - ((TQGCC*)penRef)->clip_serial = gc_cache_clip_serial; - } else if ( !penRef ) { - x11SetClipRegion( dpy, gc, 0, rendhd, *paintEventClipRegion ); - } - } else if (penRef && ((TQGCC*)penRef)->clip_serial ) { - x11ClearClipRegion(dpy, gc, 0, rendhd); - ((TQGCC*)penRef)->clip_serial = 0; - } - } - - if ( obtained ) - return; - - char dashes[10]; // custom pen dashes - int dash_len = 0; // length of dash list - int s = LineSolid; - int cp = CapButt; - int jn = JoinMiter; - - /* - We are emulating Windows here. Windows treats cpen.width() == 1 - (or 0) as a very special case. The fudge variable unifies this - case with the general case. - */ - int dot = cpen.width(); // width of a dot - int fudge = 1; - bool allow_zero_lw = TRUE; - if ( dot <= 1 ) { - dot = 3; - fudge = 2; - } - - switch( ps ) { - case NoPen: - case SolidLine: - s = LineSolid; - break; - case DashLine: - dashes[0] = fudge * 3 * dot; - dashes[1] = fudge * dot; - dash_len = 2; - allow_zero_lw = FALSE; - break; - case DotLine: - dashes[0] = dot; - dashes[1] = dot; - dash_len = 2; - allow_zero_lw = FALSE; - break; - case DashDotLine: - dashes[0] = 3 * dot; - dashes[1] = fudge * dot; - dashes[2] = dot; - dashes[3] = fudge * dot; - dash_len = 4; - allow_zero_lw = FALSE; - break; - case DashDotDotLine: - dashes[0] = 3 * dot; - dashes[1] = dot; - dashes[2] = dot; - dashes[3] = dot; - dashes[4] = dot; - dashes[5] = dot; - dash_len = 6; - allow_zero_lw = FALSE; - break; - case FineDotLine: - dot = 1; - dashes[0] = dot; - dashes[1] = dot; - dash_len = 2; - allow_zero_lw = FALSE; - } - Q_ASSERT( dash_len <= (int) sizeof(dashes) ); - - switch ( cpen.capStyle() ) { - case SquareCap: - cp = CapProjecting; - break; - case RoundCap: - cp = CapRound; - break; - case FlatCap: - default: - cp = CapButt; - break; - } - switch ( cpen.joinStyle() ) { - case BevelJoin: - jn = JoinBevel; - break; - case RoundJoin: - jn = JoinRound; - break; - case MiterJoin: - default: - jn = JoinMiter; - break; - } - - XSetForeground( dpy, gc, cpen.color().pixel(scrn) ); - XSetBackground( dpy, gc, bg_col.pixel(scrn) ); - - if ( dash_len ) { // make dash list - XSetDashes( dpy, gc, 0, dashes, dash_len ); - s = bg_mode == TransparentMode ? LineOnOffDash : LineDoubleDash; - } - XSetLineAttributes( dpy, gc, - (! allow_zero_lw && cpen.width() == 0) ? 1 : cpen.width(), - s, cp, jn ); -} - - -void TQPainter::updateBrush() -{ - if (!isActive()) - return; - - static const uchar dense1_pat[] = { 0xff, 0xbb, 0xff, 0xff, 0xff, 0xbb, 0xff, 0xff }; - static const uchar dense2_pat[] = { 0x77, 0xff, 0xdd, 0xff, 0x77, 0xff, 0xdd, 0xff }; - static const uchar dense3_pat[] = { 0x55, 0xbb, 0x55, 0xee, 0x55, 0xbb, 0x55, 0xee }; - static const uchar dense4_pat[] = { 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa }; - static const uchar dense5_pat[] = { 0xaa, 0x44, 0xaa, 0x11, 0xaa, 0x44, 0xaa, 0x11 }; - static const uchar dense6_pat[] = { 0x88, 0x00, 0x22, 0x00, 0x88, 0x00, 0x22, 0x00 }; - static const uchar dense7_pat[] = { 0x00, 0x44, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00 }; - static const uchar hor_pat[] = { // horizontal pattern - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, - 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; - static const uchar ver_pat[] = { // vertical pattern - 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, - 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, - 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, - 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, - 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, - 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20 }; - static const uchar cross_pat[] = { // cross pattern - 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0xff, 0xff, 0xff, - 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, - 0x08, 0x82, 0x20, 0xff, 0xff, 0xff, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, - 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0xff, 0xff, 0xff, - 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, - 0x08, 0x82, 0x20, 0xff, 0xff, 0xff, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20 }; - static const uchar bdiag_pat[] = { // backward diagonal pattern - 0x20, 0x20, 0x10, 0x10, 0x08, 0x08, 0x04, 0x04, 0x02, 0x02, 0x01, 0x01, - 0x80, 0x80, 0x40, 0x40, 0x20, 0x20, 0x10, 0x10, 0x08, 0x08, 0x04, 0x04, - 0x02, 0x02, 0x01, 0x01, 0x80, 0x80, 0x40, 0x40 }; - static const uchar fdiag_pat[] = { // forward diagonal pattern - 0x02, 0x02, 0x04, 0x04, 0x08, 0x08, 0x10, 0x10, 0x20, 0x20, 0x40, 0x40, - 0x80, 0x80, 0x01, 0x01, 0x02, 0x02, 0x04, 0x04, 0x08, 0x08, 0x10, 0x10, - 0x20, 0x20, 0x40, 0x40, 0x80, 0x80, 0x01, 0x01 }; - static const uchar dcross_pat[] = { // diagonal cross pattern - 0x22, 0x22, 0x14, 0x14, 0x08, 0x08, 0x14, 0x14, 0x22, 0x22, 0x41, 0x41, - 0x80, 0x80, 0x41, 0x41, 0x22, 0x22, 0x14, 0x14, 0x08, 0x08, 0x14, 0x14, - 0x22, 0x22, 0x41, 0x41, 0x80, 0x80, 0x41, 0x41 }; - static const uchar * const pat_tbl[] = { - dense1_pat, dense2_pat, dense3_pat, dense4_pat, dense5_pat, - dense6_pat, dense7_pat, - hor_pat, ver_pat, cross_pat, bdiag_pat, fdiag_pat, dcross_pat }; - - if ( testf(ExtDev) ) { - TQPDevCmdParam param[1]; - param[0].brush = &cbrush; - if ( !pdev->cmd( TQPaintDevice::PdcSetBrush, this, param ) || !hd ) - return; - } - - int bs = cbrush.style(); - bool cacheIt = !testf(ClipOn|MonoDev|NoCache) && - (bs == NoBrush || bs == SolidPattern) && - bro.x() == 0 && bro.y() == 0 && rop == CopyROP; - - bool obtained = FALSE; - bool internclipok = hasClipping(); - if ( cacheIt ) { - if ( gc_brush ) { - if ( brushRef ) - release_gc( brushRef ); - else - free_gc( dpy, gc_brush ); - } - obtained = obtain_gc(&brushRef, &gc_brush, cbrush.color().pixel(scrn), dpy, - scrn, hd, clip_serial); - if ( !obtained && !brushRef ) - gc_brush = alloc_gc( dpy, scrn, hd, FALSE ); - } else { - if ( gc_brush ) { - if ( brushRef ) { - release_gc( brushRef ); - brushRef = 0; - gc_brush = alloc_gc( dpy, scrn, hd, testf(MonoDev) ); - } else { - internclipok = TRUE; - } - } else { - gc_brush = alloc_gc( dpy, scrn, hd, testf(MonoDev), testf(UsePrivateCx)); - } - } - - if ( !internclipok ) { - if ( pdev == paintEventDevice && paintEventClipRegion ) { - if ( brushRef &&((TQGCC*)brushRef)->clip_serial < gc_cache_clip_serial ) { - x11SetClipRegion( dpy, gc_brush, 0, rendhd, *paintEventClipRegion ); - ((TQGCC*)brushRef)->clip_serial = gc_cache_clip_serial; - } else if ( !brushRef ){ - x11SetClipRegion( dpy, gc_brush, 0, rendhd, *paintEventClipRegion ); - } - } else if (brushRef && ((TQGCC*)brushRef)->clip_serial ) { - x11ClearClipRegion(dpy, gc_brush, 0, rendhd); - ((TQGCC*)brushRef)->clip_serial = 0; - } - } - - if ( obtained ) - return; - - const uchar *pat = 0; // pattern - int d = 0; // defalt pattern size: d*d - int s = FillSolid; - if ( bs >= Dense1Pattern && bs <= DiagCrossPattern ) { - pat = pat_tbl[ bs-Dense1Pattern ]; - if ( bs <= Dense7Pattern ) - d = 8; - else if ( bs <= CrossPattern ) - d = 24; - else - d = 16; - } - - XSetLineAttributes( dpy, gc_brush, 0, LineSolid, CapButt, JoinMiter ); - XSetForeground( dpy, gc_brush, cbrush.color().pixel(scrn) ); - XSetBackground( dpy, gc_brush, bg_col.pixel(scrn) ); - - if ( bs == CustomPattern || pat ) { - TQPixmap *pm; - if ( pat ) { - TQString key; - key.sprintf( "$qt-brush$%d", bs ); - pm = TQPixmapCache::find( key ); - bool del = FALSE; - if ( !pm ) { // not already in pm dict - pm = new TQBitmap( d, d, pat, TRUE ); - TQ_CHECK_PTR( pm ); - del = !TQPixmapCache::insert( key, pm ); - } - if ( cbrush.data->pixmap ) - delete cbrush.data->pixmap; - cbrush.data->pixmap = new TQPixmap( *pm ); - if (del) delete pm; - } - pm = cbrush.data->pixmap; - pm->x11SetScreen( scrn ); - if ( pm->depth() == 1 ) { - XSetStipple( dpy, gc_brush, pm->handle() ); - s = bg_mode == TransparentMode ? FillStippled : FillOpaqueStippled; - } else { - XSetTile( dpy, gc_brush, pm->handle() ); - s = FillTiled; - } - } - XSetFillStyle( dpy, gc_brush, s ); -} - - -/*! - Begins painting the paint device \a pd and returns TRUE if - successful; otherwise returns FALSE. If \a unclipped is TRUE, the - painting will not be clipped at the paint device's boundaries, - (although this is not supported by all platforms). - - The errors that can occur are serious problems, such as these: - - \code - p->begin( 0 ); // impossible - paint device cannot be 0 - - TQPixmap pm( 0, 0 ); - p->begin( pm ); // impossible - pm.isNull(); - - p->begin( myWidget ); - p2->begin( myWidget ); // impossible - only one painter at a time - \endcode - - Note that most of the time, you can use one of the constructors - instead of begin(), and that end() is automatically done at - destruction. - - \warning A paint device can only be painted by one painter at a - time. - - \sa end(), flush() -*/ - -bool TQPainter::begin( const TQPaintDevice *pd, bool unclipped ) -{ - if ( isActive() ) { // already active painting -#if defined(QT_CHECK_STATE) - tqWarning( "TQPainter::begin: Painter is already active." - "\n\tYou must end() the painter before a second begin()" ); -#endif - return FALSE; - } - if ( pd == 0 ) { -#if defined(QT_CHECK_NULL) - tqWarning( "TQPainter::begin: Paint device cannot be null" ); -#endif - return FALSE; - } - - TQPixmap::x11SetDefaultScreen( pd->x11Screen() ); - - const TQWidget *copyFrom = 0; - pdev = redirect( (TQPaintDevice*)pd ); - if ( pdev ) { // redirected paint device? - if ( pd->devType() == TQInternal::Widget ) - copyFrom = (const TQWidget *)pd; // copy widget settings - } else { - pdev = (TQPaintDevice*)pd; - } - - if ( pdev->isExtDev() && pdev->paintingActive() ) { - // somebody else is already painting -#if defined(QT_CHECK_STATE) - tqWarning( "TQPainter::begin: Another TQPainter is already painting " - "this device;\n\tAn extended paint device can only be " - "painted by one TQPainter at a time." ); -#endif - return FALSE; - } - - bool reinit = flags != IsStartingUp; // 2nd or 3rd etc. time called - flags = IsActive | DirtyFont; // init flags - int dt = pdev->devType(); // get the device type - - if ( (pdev->devFlags & TQInternal::ExternalDevice) != 0 ) - setf(ExtDev); - else if ( dt == TQInternal::Pixmap ) // device is a pixmap - ((TQPixmap*)pdev)->detach(); // will modify it - - dpy = pdev->x11Display(); // get display variable - scrn = pdev->x11Screen(); // get screen variable - hd = pdev->handle(); // get handle to drawable - rendhd = pdev->rendhd; - - if ( testf(ExtDev) ) { // external device - if ( !pdev->cmd( TQPaintDevice::PdcBegin, this, 0 ) ) { - // could not begin painting - if ( reinit ) - clearf( IsActive | DirtyFont ); - else - flags = IsStartingUp; - pdev = 0; - return FALSE; - } - if ( tabstops ) // update tabstops for device - setTabStops( tabstops ); - if ( tabarray ) // update tabarray for device - setTabArray( tabarray ); - } - - if ( pdev->x11Depth() != pdev->x11AppDepth( scrn ) ) { // non-standard depth - setf(NoCache); - setf(UsePrivateCx); - } - - pdev->painters++; // also tell paint device - bro = curPt = TQPoint( 0, 0 ); - if ( reinit ) { - bg_mode = TransparentMode; // default background mode - rop = CopyROP; // default ROP - wxmat.reset(); // reset world xform matrix - xmat.reset(); - ixmat.reset(); - txop = txinv = 0; - if ( dt != TQInternal::Widget ) { - TQFont defaultFont; // default drawing tools - TQPen defaultPen; - TQBrush defaultBrush; - cfont = defaultFont; // set these drawing tools - cpen = defaultPen; - cbrush = defaultBrush; - bg_col = white; // default background color - } - } - wx = wy = vx = vy = 0; // default view origins - - if ( dt == TQInternal::Widget ) { // device is a widget - TQWidget *w = (TQWidget*)pdev; - cfont = w->font(); // use widget font - cpen = TQPen( w->foregroundColor() ); // use widget fg color - if ( reinit ) { - TQBrush defaultBrush; - cbrush = defaultBrush; - } - bg_col = w->backgroundColor(); // use widget bg color - ww = vw = w->width(); // default view size - wh = vh = w->height(); - if ( unclipped || w->testWFlags( WPaintUnclipped ) ) { // paint direct on device - setf( NoCache ); - setf(UsePrivateCx); - updatePen(); - updateBrush(); - XSetSubwindowMode( dpy, gc, IncludeInferiors ); - XSetSubwindowMode( dpy, gc_brush, IncludeInferiors ); -#ifndef TQT_NO_XFTFREETYPE - if (rendhd) - XftDrawSetSubwindowMode((XftDraw *) rendhd, IncludeInferiors); -#endif - } - } else if ( dt == TQInternal::Pixmap ) { // device is a pixmap - TQPixmap *pm = (TQPixmap*)pdev; - if ( pm->isNull() ) { -#if defined(QT_CHECK_NULL) - tqWarning( "TQPainter::begin: Cannot paint null pixmap" ); -#endif - end(); - return FALSE; - } - bool mono = pm->depth() == 1; // monochrome bitmap - if ( mono ) { - setf( MonoDev ); - bg_col = color0; - cpen.setColor( color1 ); - } - ww = vw = pm->width(); // default view size - wh = vh = pm->height(); - } else if ( testf(ExtDev) ) { // external device - ww = vw = pdev->metric( TQPaintDeviceMetrics::PdmWidth ); - wh = vh = pdev->metric( TQPaintDeviceMetrics::PdmHeight ); - } - if ( ww == 0 ) - ww = wh = vw = vh = 1024; - if ( copyFrom ) { // copy redirected widget - cfont = copyFrom->font(); - cpen = TQPen( copyFrom->foregroundColor() ); - bg_col = copyFrom->backgroundColor(); - } - if ( testf(ExtDev) ) { // external device - setBackgroundColor( bg_col ); // default background color - setBackgroundMode( TransparentMode ); // default background mode - setRasterOp( CopyROP ); // default raster operation - } - clip_serial = gc_cache_clip_serial++; - updateBrush(); - updatePen(); - return TRUE; -} - -/*! - Ends painting. Any resources used while painting are released. - - Note that while you mostly don't need to call end(), the - destructor will do it, there is at least one common case when it - is needed, namely double buffering. - - \code - TQPainter p( myPixmap, this ) - // ... - p.end(); // stops drawing on myPixmap - p.begin( this ); - p.drawPixmap( 0, 0, myPixmap ); - \endcode - - Since you can't draw a TQPixmap while it is being painted, it is - necessary to close the active painter. - - \sa begin(), isActive() -*/ - -bool TQPainter::end() // end painting -{ - if ( !isActive() ) { -#if defined(QT_CHECK_STATE) - tqWarning( "TQPainter::end: Missing begin() or begin() failed" ); -#endif - return FALSE; - } - killPStack(); - - //#### This should not be necessary: - if ( pdev->devType() == TQInternal::Widget && // ##### - ((TQWidget*)pdev)->testWFlags(WPaintUnclipped) ) { - if ( gc ) - XSetSubwindowMode( dpy, gc, ClipByChildren ); - if ( gc_brush ) - XSetSubwindowMode( dpy, gc_brush, ClipByChildren ); - } - - if ( gc_brush ) { // restore brush gc - if ( brushRef ) { - release_gc( brushRef ); - brushRef = 0; - } else { - free_gc( dpy, gc_brush, testf(UsePrivateCx) ); - } - gc_brush = 0; - - } - if ( gc ) { // restore pen gc - if ( penRef ) { - release_gc( penRef ); - penRef = 0; - } else { - free_gc( dpy, gc, testf(UsePrivateCx) ); - } - gc = 0; - } - - if ( testf(ExtDev) ) - pdev->cmd( TQPaintDevice::PdcEnd, this, 0 ); - -#ifndef TQT_NO_XFTFREETYPE - if (rendhd) { - // reset clipping/subwindow mode on our render picture - XftDrawSetClip((XftDraw *) rendhd, None); - XftDrawSetSubwindowMode((XftDraw *) rendhd, ClipByChildren); - } -#endif // TQT_NO_XFTFREETYPE - - if ( pfont ) { - delete pfont; - pfont = 0; - } - - flags = 0; - pdev->painters--; - pdev = 0; - dpy = 0; - return TRUE; -} - -/*! - Flushes any buffered drawing operations inside the region \a - region using clipping mode \a cm. - - The flush may update the whole device if the platform does not - support flushing to a specified region. - - \sa flush() CoordinateMode -*/ - -void TQPainter::flush(const TQRegion &rgn, CoordinateMode m) -{ - if ( testf(ExtDev) ) { - TQPDevCmdParam param[2]; - param[0].rgn = &rgn; - param[1].ival = m; - pdev->cmd( TQPaintDevice::PdcFlushRegion, this, param ); - return; - } - - flush(); -} - - -/*! - \overload - - Flushes any buffered drawing operations. -*/ - -void TQPainter::flush() -{ - if ( testf(ExtDev) ) { - pdev->cmd( TQPaintDevice::PdcFlush, this, 0 ); - return; - } - - if ( isActive() && dpy ) - XFlush( dpy ); -} - - -/*! - Sets the background color of the painter to \a c. - - The background color is the color that is filled in when drawing - opaque text, stippled lines and bitmaps. The background color has - no effect in transparent background mode (which is the default). - - \sa backgroundColor() setBackgroundMode() BackgroundMode -*/ - -void TQPainter::setBackgroundColor( const TQColor &c ) -{ - if ( !isActive() ) { -#if defined(QT_CHECK_STATE) - tqWarning( "TQPainter::setBackgroundColor: Call begin() first" ); -#endif - return; - } - bg_col = c; - if ( testf(ExtDev) ) { - TQPDevCmdParam param[1]; - param[0].color = &bg_col; - if ( !pdev->cmd( TQPaintDevice::PdcSetBkColor, this, param ) || !hd ) - return; - } - if ( !penRef ) - updatePen(); // update pen setting - if ( !brushRef ) - updateBrush(); // update brush setting -} - -/*! - Sets the background mode of the painter to \a m, which must be - either \c TransparentMode (the default) or \c OpaqueMode. - - Transparent mode draws stippled lines and text without setting the - background pixels. Opaque mode fills these space with the current - background color. - - Note that in order to draw a bitmap or pixmap transparently, you - must use TQPixmap::setMask(). - - \sa backgroundMode(), setBackgroundColor() -*/ - -void TQPainter::setBackgroundMode( BGMode m ) -{ - if ( !isActive() ) { -#if defined(QT_CHECK_STATE) - tqWarning( "TQPainter::setBackgroundMode: Call begin() first" ); -#endif - return; - } - if ( m != TransparentMode && m != OpaqueMode ) { -#if defined(QT_CHECK_RANGE) - tqWarning( "TQPainter::setBackgroundMode: Invalid mode" ); -#endif - return; - } - bg_mode = m; - if ( testf(ExtDev) ) { - TQPDevCmdParam param[1]; - param[0].ival = m; - if ( !pdev->cmd( TQPaintDevice::PdcSetBkMode, this, param ) || !hd ) - return; - } - if ( !penRef ) - updatePen(); // update pen setting - if ( !brushRef ) - updateBrush(); // update brush setting -} - -static const short ropCodes[] = { // ROP translation table - GXcopy, // CopyROP - GXor, // OrROP - GXxor, // XorROP - GXandInverted, // NotAndROP EraseROP - GXcopyInverted, // NotCopyROP - GXorInverted, // NotOrROP - GXequiv, // NotXorROP - GXand, // AndROP - GXinvert, // NotROP - GXclear, // ClearROP - GXset, // SetROP - GXnoop, // NopROP - GXandReverse, // AndNotROP - GXorReverse, // OrNotROP - GXnand, // NandROP - GXnor // NorROP -}; - - -/*! - Sets the \link TQt::RasterOp raster operation \endlink to \a r. - The default is \c CopyROP. - - \sa rasterOp() TQt::RasterOp -*/ - -void TQPainter::setRasterOp( RasterOp r ) -{ - if ( !isActive() ) { -#if defined(QT_CHECK_STATE) - tqWarning( "TQPainter::setRasterOp: Call begin() first" ); -#endif - return; - } - if ( (uint)r > LastROP ) { -#if defined(QT_CHECK_RANGE) - tqWarning( "TQPainter::setRasterOp: Invalid ROP code" ); -#endif - return; - } - rop = r; - if ( testf(ExtDev) ) { - TQPDevCmdParam param[1]; - param[0].ival = r; - if ( !pdev->cmd( TQPaintDevice::PdcSetROP, this, param ) || !hd ) - return; - } - if ( penRef ) - updatePen(); // get non-cached pen GC - if ( brushRef ) - updateBrush(); // get non-cached brush GC - XSetFunction( dpy, gc, ropCodes[rop] ); - XSetFunction( dpy, gc_brush, ropCodes[rop] ); -} - -// ### matthias - true? - -/*! - Sets the brush origin to \a (x, y). - - The brush origin specifies the (0, 0) coordinate of the painter's - brush. This setting only applies to pattern brushes and pixmap - brushes. - - \sa brushOrigin() -*/ - -void TQPainter::setBrushOrigin( int x, int y ) -{ - if ( !isActive() ) { -#if defined(QT_CHECK_STATE) - tqWarning( "TQPainter::setBrushOrigin: Call begin() first" ); -#endif - return; - } - bro = TQPoint(x, y); - if ( testf(ExtDev) ) { - TQPDevCmdParam param[1]; - param[0].point = &bro; - if ( !pdev->cmd( TQPaintDevice::PdcSetBrushOrigin, this, param ) || - !hd ) - return; - } - if ( brushRef ) - updateBrush(); // get non-cached brush GC - XSetTSOrigin( dpy, gc_brush, x, y ); -} - - -/*! - Enables clipping if \a enable is TRUE, or disables clipping if \a - enable is FALSE. - - \sa hasClipping(), setClipRect(), setClipRegion() -*/ - -void TQPainter::setClipping( bool enable ) -{ - if ( !isActive() ) { -#if defined(QT_CHECK_STATE) - tqWarning( "TQPainter::setClipping: Will be reset by begin()" ); -#endif - return; - } - - if ( enable == testf(ClipOn) ) - return; - - setf( ClipOn, enable ); - if ( testf(ExtDev) ) { - if ( block_ext ) - return; - TQPDevCmdParam param[1]; - param[0].ival = enable; - if ( !pdev->cmd( TQPaintDevice::PdcSetClip, this, param ) || !hd ) - return; - } - if ( enable ) { - TQRegion rgn = crgn; - if ( pdev == paintEventDevice && paintEventClipRegion ) - rgn = rgn.intersect( *paintEventClipRegion ); - if ( penRef ) - updatePen(); - if ( brushRef ) - updateBrush(); - x11SetClipRegion( dpy, gc, gc_brush, rendhd, rgn ); - } else { - if ( pdev == paintEventDevice && paintEventClipRegion ) { - x11SetClipRegion( dpy, gc, gc_brush , rendhd, *paintEventClipRegion ); - } else { - x11ClearClipRegion(dpy, gc, gc_brush, rendhd); - } - } -} - - -/*! - \overload - - Sets the clip region to the rectangle \a r and enables clipping. - The clip mode is set to \a m. - - \sa CoordinateMode -*/ - -void TQPainter::setClipRect( const TQRect &r, CoordinateMode m ) -{ - setClipRegion( TQRegion( r ), m ); -} - -/*! - Sets the clip region to \a rgn and enables clipping. The clip mode - is set to \a m. - - Note that the clip region is given in physical device coordinates - and \e not subject to any \link coordsys.html coordinate - transformation.\endlink - - \sa setClipRect(), clipRegion(), setClipping() CoordinateMode -*/ - -void TQPainter::setClipRegion( const TQRegion &rgn, CoordinateMode m ) -{ -#if defined(QT_CHECK_STATE) - if ( !isActive() ) - tqWarning( "TQPainter::setClipRegion: Will be reset by begin()" ); -#endif - if ( m == CoordDevice ) - crgn = rgn; - else - crgn = xmat * rgn; - - if ( testf(ExtDev) ) { - if ( block_ext ) - return; - TQPDevCmdParam param[2]; - param[0].rgn = &rgn; - param[1].ival = m; - if ( !pdev->cmd( TQPaintDevice::PdcSetClipRegion, this, param ) ) - return; // device cannot clip - } - clearf( ClipOn ); // be sure to update clip rgn - setClipping( TRUE ); -} - - -/*! - \internal - - Internal function for drawing a polygon. -*/ - -void TQPainter::drawPolyInternal( const TQPointArray &a, bool close ) -{ - if ( a.size() < 2 ) - return; - - int x1, y1, x2, y2; // connect last to first point - a.point( a.size()-1, &x1, &y1 ); - a.point( 0, &x2, &y2 ); - bool do_close = close && !(x1 == x2 && y1 == y2); - - if ( close && cbrush.style() != NoBrush ) { // draw filled polygon - XFillPolygon( dpy, hd, gc_brush, (XPoint*)a.shortPoints(), a.size(), - Nonconvex, CoordModeOrigin ); - if ( cpen.style() == NoPen ) { // draw fake outline - XDrawLines( dpy, hd, gc_brush, (XPoint*)a.shortPoints(), a.size(), - CoordModeOrigin ); - if ( do_close ) - XDrawLine( dpy, hd, gc_brush, x1, y1, x2, y2 ); - } - } - if ( cpen.style() != NoPen ) { // draw outline - XDrawLines( dpy, hd, gc, (XPoint*)a.shortPoints(), a.size(), - CoordModeOrigin); - if ( do_close ) - XDrawLine( dpy, hd, gc, x1, y1, x2, y2 ); - } -} - - -/*! - Draws/plots a single point at \a (x, y) using the current pen. - - \sa TQPen -*/ - -void TQPainter::drawPoint( int x, int y ) -{ - if ( !isActive() ) - return; - if ( testf(ExtDev|VxF|WxF) ) { - if ( testf(ExtDev) ) { - TQPDevCmdParam param[1]; - TQPoint p( x, y ); - param[0].point = &p; - if ( !pdev->cmd( TQPaintDevice::PdcDrawPoint, this, param ) || - !hd ) - return; - } - map( x, y, &x, &y ); - } - if ( cpen.style() != NoPen ) - XDrawPoint( dpy, hd, gc, x, y ); -} - - -/*! - Draws/plots an array of points, \a a, using the current pen. - - If \a index is non-zero (the default is zero) only points from \a - index are drawn. If \a npoints is negative (the default) the rest - of the points from \a index are drawn. If \a npoints is zero or - greater, \a npoints points are drawn. - - \warning On X11, coordinates that do not fit into 16-bit signed - values are truncated. This limitation is expected to go away in - TQt 4. -*/ - -void TQPainter::drawPoints( const TQPointArray& a, int index, int npoints ) -{ - if ( npoints < 0 ) - npoints = a.size() - index; - if ( index + npoints > (int)a.size() ) - npoints = a.size() - index; - if ( !isActive() || npoints < 1 || index < 0 ) - return; - TQPointArray pa = a; - if ( testf(ExtDev|VxF|WxF) ) { - if ( testf(ExtDev) ) { - TQPDevCmdParam param[1]; - for (int i=0; icmd( TQPaintDevice::PdcDrawPoint, this, param )) - return; - } - if ( !hd ) return; - } - if ( txop != TxNone ) { - pa = xForm( a, index, npoints ); - if ( pa.size() != a.size() ) { - index = 0; - npoints = pa.size(); - } - } - } - if ( cpen.style() != NoPen ) - XDrawPoints( dpy, hd, gc, (XPoint*)(pa.shortPoints( index, npoints )), - npoints, CoordModeOrigin ); -} - - -/*! \obsolete - Sets the current pen position to \a (x, y) - - \sa lineTo(), pos() -*/ - -void TQPainter::moveTo( int x, int y ) -{ - if ( !isActive() ) - return; - if ( testf(ExtDev|VxF|WxF) ) { - if ( testf(ExtDev) ) { - TQPDevCmdParam param[1]; - TQPoint p( x, y ); - param[0].point = &p; - if ( !pdev->cmd( TQPaintDevice::PdcMoveTo, this, param ) || !hd ) - return; - } - } - curPt = TQPoint( x, y ); -} - -/*! \obsolete - Use drawLine() instead. - - Draws a line from the current pen position to \a (x, y) and sets - \a (x, y) to be the new current pen position. - - \sa TQPen moveTo(), drawLine(), pos() -*/ - -void TQPainter::lineTo( int x, int y ) -{ - if ( !isActive() ) - return; - int cx = curPt.x(), cy = curPt.y(); - curPt = TQPoint( x, y ); - if ( testf(ExtDev|VxF|WxF) ) { - if ( testf(ExtDev) ) { - TQPDevCmdParam param[1]; - TQPoint p( x, y ); - param[0].point = &p; - if ( !pdev->cmd( TQPaintDevice::PdcLineTo, this, param ) || !hd ) - return; - } - map( x, y, &x, &y ); - map( cx, cy, &cx, &cy ); - } - if ( cpen.style() != NoPen ) - XDrawLine( dpy, hd, gc, cx, cy, x, y ); -} - -/*! - Draws a line from (\a x1, \a y1) to (\a x2, \a y2) and sets the - current pen position to (\a x2, \a y2). - - \sa pen() -*/ - -void TQPainter::drawLine( int x1, int y1, int x2, int y2 ) -{ - if ( !isActive() ) - return; - curPt = TQPoint( x2, y2 ); - if ( testf(ExtDev|VxF|WxF) ) { - if ( testf(ExtDev) ) { - TQPDevCmdParam param[2]; - TQPoint p1(x1, y1), p2(x2, y2); - param[0].point = &p1; - param[1].point = &p2; - if ( !pdev->cmd( TQPaintDevice::PdcDrawLine, this, param ) || !hd ) - return; - } - map( x1, y1, &x1, &y1 ); - map( x2, y2, &x2, &y2 ); - } - if ( cpen.style() != NoPen ) - XDrawLine( dpy, hd, gc, x1, y1, x2, y2 ); -} - - - -/*! - Draws a rectangle with upper left corner at \a (x, y) and with - width \a w and height \a h. - - \sa TQPen, drawRoundRect() -*/ - -void TQPainter::drawRect( int x, int y, int w, int h ) -{ - if ( !isActive() ) - return; - if ( testf(ExtDev|VxF|WxF) ) { - if ( testf(ExtDev) ) { - TQPDevCmdParam param[1]; - TQRect r( x, y, w, h ); - param[0].rect = &r; - if ( !pdev->cmd( TQPaintDevice::PdcDrawRect, this, param ) || !hd ) - return; - } - if ( txop == TxRotShear ) { // rotate/shear polygon - TQPointArray pa = xmat.mapToPolygon( TQRect(x, y, w, h) ); - pa.resize( 5 ); - pa.setPoint( 4, pa.point( 0 ) ); - drawPolyInternal( pa ); - return; - } - map( x, y, w, h, &x, &y, &w, &h ); - } - if ( w <= 0 || h <= 0 ) { - if ( w == 0 || h == 0 ) - return; - fix_neg_rect( &x, &y, &w, &h ); - } - if ( cbrush.style() != NoBrush ) { - if ( cpen.style() == NoPen ) { - XFillRectangle( dpy, hd, gc_brush, x, y, w, h ); - return; - } - int lw = cpen.width(); - int lw2 = (lw+1)/2; - if ( w > lw && h > lw ) - XFillRectangle( dpy, hd, gc_brush, x+lw2, y+lw2, w-lw-1, h-lw-1 ); - } - if ( cpen.style() != NoPen ) - XDrawRectangle( dpy, hd, gc, x, y, w-1, h-1 ); -} - -/*! - \overload - - Draws a Windows focus rectangle with upper left corner at (\a x, - \a y) and with width \a w and height \a h. - - This function draws a stippled XOR rectangle that is used to - indicate keyboard focus (when TQApplication::style() is \c - WindowStyle). - - \warning This function draws nothing if the coordinate system has - been \link rotate() rotated\endlink or \link shear() - sheared\endlink. - - \sa drawRect(), TQApplication::style() -*/ - -void TQPainter::drawWinFocusRect( int x, int y, int w, int h ) -{ - drawWinFocusRect( x, y, w, h, TRUE, color0 ); -} - -/*! - Draws a Windows focus rectangle with upper left corner at (\a x, - \a y) and with width \a w and height \a h using a pen color that - contrasts with \a bgColor. - - This function draws a stippled rectangle (XOR is not used) that is - used to indicate keyboard focus (when the TQApplication::style() is - \c WindowStyle). - - The pen color used to draw the rectangle is either white or black - depending on the color of \a bgColor (see TQColor::gray()). - - \warning This function draws nothing if the coordinate system has - been \link rotate() rotated\endlink or \link shear() - sheared\endlink. - - \sa drawRect(), TQApplication::style() -*/ - -void TQPainter::drawWinFocusRect( int x, int y, int w, int h, - const TQColor &bgColor ) -{ - drawWinFocusRect( x, y, w, h, FALSE, bgColor ); -} - - -/*! - \internal -*/ - -void TQPainter::drawWinFocusRect( int x, int y, int w, int h, - bool xorPaint, const TQColor &bgColor ) -{ - if ( !isActive() || txop == TxRotShear ) - return; - static char winfocus_line[] = { 1, 1 }; - - TQPen old_pen = cpen; - TQBrush old_brush = cbrush; - RasterOp old_rop = (RasterOp)rop; - - if ( xorPaint ) { - if ( TQColor::numBitPlanes() <= 8 ) { - setPen( TQPen(color1, 0, TQt::FineDotLine) ); - } - else if ( TQColor::numBitPlanes() <= 8 ) { - setPen( TQPen(white, 0, TQt::FineDotLine) ); - } - else { - setPen( TQPen(TQColor(tqRgba(255,255,255,0)), 0, TQt::FineDotLine) ); - } - setRasterOp( XorROP ); - } - else { - if ( tqGray( bgColor.rgb() ) < 128 ) { - setPen( TQPen(white, 0, TQt::FineDotLine) ); - } - else { - setPen( TQPen(black, 0, TQt::FineDotLine) ); - } - } - - if ( testf(ExtDev|VxF|WxF) ) { - if ( testf(ExtDev) ) { - TQPDevCmdParam param[1]; - TQRect r( x, y, w-1, h-1 ); - TQBrush noBrush; - setBrush( noBrush ); - param[0].rect = &r; - if ( !pdev->cmd( TQPaintDevice::PdcDrawRect, this, param ) || !hd) { - setRasterOp( old_rop ); - setPen( old_pen ); - setBrush( old_brush ); - return; - } - } - map( x, y, w, h, &x, &y, &w, &h ); - } - if ( w <= 0 || h <= 0 ) { - if ( w == 0 || h == 0 ) - return; - fix_neg_rect( &x, &y, &w, &h ); - } - XSetDashes( dpy, gc, 0, winfocus_line, 2 ); - XSetLineAttributes( dpy, gc, 1, LineOnOffDash, CapButt, JoinMiter ); - - XDrawRectangle( dpy, hd, gc, x, y, w-1, h-1 ); - - XSetLineAttributes( dpy, gc, 0, LineSolid, CapButt, JoinMiter ); - setRasterOp( old_rop ); - setPen( old_pen ); -} - - -/*! - Draws a rectangle with rounded corners at \a (x, y), with width \a - w and height \a h. - - The \a xRnd and \a yRnd arguments specify how rounded the corners - should be. 0 is angled corners, 99 is maximum roundedness. - - The width and height include all of the drawn lines. - - \sa drawRect(), TQPen -*/ - -void TQPainter::drawRoundRect( int x, int y, int w, int h, int xRnd, int yRnd ) -{ - if ( !isActive() ) - return; - if ( xRnd <= 0 || yRnd <= 0 ) { - drawRect( x, y, w, h ); // draw normal rectangle - return; - } - if ( xRnd >= 100 ) // fix ranges - xRnd = 99; - if ( yRnd >= 100 ) - yRnd = 99; - if ( testf(ExtDev|VxF|WxF) ) { - if ( testf(ExtDev) ) { - TQPDevCmdParam param[3]; - TQRect r( x, y, w, h ); - param[0].rect = &r; - param[1].ival = xRnd; - param[2].ival = yRnd; - if ( !pdev->cmd( TQPaintDevice::PdcDrawRoundRect, this, param ) || - !hd ) - return; - } - if ( txop == TxRotShear ) { // rotate/shear polygon - if ( w <= 0 || h <= 0 ) - fix_neg_rect( &x, &y, &w, &h ); - w--; - h--; - int rxx = w*xRnd/200; - int ryy = h*yRnd/200; - // were there overflows? - if ( rxx < 0 ) - rxx = w/200*xRnd; - if ( ryy < 0 ) - ryy = h/200*yRnd; - int rxx2 = 2*rxx; - int ryy2 = 2*ryy; - TQPointArray a[4]; - a[0].makeArc( x, y, rxx2, ryy2, 1*16*90, 16*90, xmat ); - a[1].makeArc( x, y+h-ryy2, rxx2, ryy2, 2*16*90, 16*90, xmat ); - a[2].makeArc( x+w-rxx2, y+h-ryy2, rxx2, ryy2, 3*16*90, 16*90, xmat ); - a[3].makeArc( x+w-rxx2, y, rxx2, ryy2, 0*16*90, 16*90, xmat ); - // ### is there a better way to join TQPointArrays? - TQPointArray aa; - aa.resize( a[0].size() + a[1].size() + a[2].size() + a[3].size() ); - uint j = 0; - for ( int k=0; k<4; k++ ) { - for ( uint i=0; ix=px; a->y=py; a->width=w; a->height=h; a->angle1=a1; a->angle2=a2; a++ - XArc arcs[4]; - XArc *a = arcs; - SET_ARC( x+w-rx2, y, rx2, ry2, 0, 90*64 ); - SET_ARC( x, y, rx2, ry2, 90*64, 90*64 ); - SET_ARC( x, y+h-ry2, rx2, ry2, 180*64, 90*64 ); - SET_ARC( x+w-rx2, y+h-ry2, rx2, ry2, 270*64, 90*64 ); - XFillArcs( dpy, hd, gc_brush, arcs, 4 ); -#undef SET_ARC -#define SET_RCT(px, py, w, h) \ - r->x=px; r->y=py; r->width=w; r->height=h; r++ - XRectangle rects[3]; - XRectangle *r = rects; - SET_RCT( x+rx, y+dp, w-rx2, ry ); - SET_RCT( x+dp, y+ry, w+ds, h-ry2 ); - SET_RCT( x+rx, y+h-ry, w-rx2, ry+ds ); - XFillRectangles( dpy, hd, gc_brush, rects, 3 ); -#undef SET_RCT - } - if ( cpen.style() != NoPen ) { // draw outline -#define SET_ARC(px, py, w, h, a1, a2) \ - a->x=px; a->y=py; a->width=w; a->height=h; a->angle1=a1; a->angle2=a2; a++ - XArc arcs[4]; - XArc *a = arcs; - SET_ARC( x+w-rx2, y, rx2, ry2, 0, 90*64 ); - SET_ARC( x, y, rx2, ry2, 90*64, 90*64 ); - SET_ARC( x, y+h-ry2, rx2, ry2, 180*64, 90*64 ); - SET_ARC( x+w-rx2, y+h-ry2, rx2, ry2, 270*64, 90*64 ); - XDrawArcs( dpy, hd, gc, arcs, 4 ); -#undef SET_ARC -#define SET_SEG(xp1, yp1, xp2, yp2) \ - s->x1=xp1; s->y1=yp1; s->x2=xp2; s->y2=yp2; s++ - XSegment segs[4]; - XSegment *s = segs; - SET_SEG( x+rx, y, x+w-rx, y ); - SET_SEG( x+rx, y+h, x+w-rx, y+h ); - SET_SEG( x, y+ry, x, y+h-ry ); - SET_SEG( x+w, y+ry, x+w, y+h-ry ); - XDrawSegments( dpy, hd, gc, segs, 4 ); -#undef SET_SET - } -} - -/*! - Draws an ellipse with center at \a (x + w/2, y + h/2) and size \a - (w, h). -*/ - -void TQPainter::drawEllipse( int x, int y, int w, int h ) -{ - if ( !isActive() ) - return; - if ( testf(ExtDev|VxF|WxF) ) { - if ( testf(ExtDev) ) { - TQPDevCmdParam param[1]; - TQRect r( x, y, w, h ); - param[0].rect = &r; - if ( !pdev->cmd( TQPaintDevice::PdcDrawEllipse, this, param ) || - !hd ) - return; - } - if ( txop == TxRotShear ) { // rotate/shear polygon - TQPointArray a; - a.makeArc( x, y, w, h, 0, 360*16, xmat ); - drawPolyInternal( a ); - return; - } - map( x, y, w, h, &x, &y, &w, &h ); - } - if ( w <= 0 || h <= 0 ) { - if ( w == 0 || h == 0 ) - return; - fix_neg_rect( &x, &y, &w, &h ); - } - if ( w == 1 && h == 1 ) { - XDrawPoint( dpy, hd, (cpen.style() == NoPen)?gc_brush:gc, x, y ); - return; - } - w--; - h--; - if ( cbrush.style() != NoBrush ) { // draw filled ellipse - XFillArc( dpy, hd, gc_brush, x, y, w, h, 0, 360*64 ); - if ( cpen.style() == NoPen ) { - XDrawArc( dpy, hd, gc_brush, x, y, w, h, 0, 360*64 ); - return; - } - } - if ( cpen.style() != NoPen ) // draw outline - XDrawArc( dpy, hd, gc, x, y, w, h, 0, 360*64 ); -} - - -/*! - Draws an arc defined by the rectangle \a (x, y, w, h), the start - angle \a a and the arc length \a alen. - - The angles \a a and \a alen are 1/16th of a degree, i.e. a full - circle equals 5760 (16*360). Positive values of \a a and \a alen - mean counter-clockwise while negative values mean the clockwise - direction. Zero degrees is at the 3 o'clock position. - - Example: - \code - TQPainter p( myWidget ); - p.drawArc( 10,10, 70,100, 100*16, 160*16 ); // draws a "(" arc - \endcode - - \sa drawPie(), drawChord() -*/ - -void TQPainter::drawArc( int x, int y, int w, int h, int a, int alen ) -{ - if ( !isActive() ) - return; - if ( testf(ExtDev|VxF|WxF) ) { - if ( testf(ExtDev) ) { - TQPDevCmdParam param[3]; - TQRect r( x, y, w, h ); - param[0].rect = &r; - param[1].ival = a; - param[2].ival = alen; - if ( !pdev->cmd( TQPaintDevice::PdcDrawArc, this, param ) || - !hd ) - return; - } - if ( txop == TxRotShear ) { // rotate/shear - TQPointArray pa; - pa.makeArc( x, y, w, h, a, alen, xmat ); // arc polyline - drawPolyInternal( pa, FALSE ); - return; - } - map( x, y, w, h, &x, &y, &w, &h ); - } - w--; - h--; - if ( w <= 0 || h <= 0 ) { - if ( w == 0 || h == 0 ) - return; - fix_neg_rect( &x, &y, &w, &h ); - } - if ( cpen.style() != NoPen ) - XDrawArc( dpy, hd, gc, x, y, w, h, a*4, alen*4 ); -} - - -/*! - Draws a pie defined by the rectangle \a (x, y, w, h), the start - angle \a a and the arc length \a alen. - - The pie is filled with the current brush(). - - The angles \a a and \a alen are 1/16th of a degree, i.e. a full - circle equals 5760 (16*360). Positive values of \a a and \a alen - mean counter-clockwise while negative values mean the clockwise - direction. Zero degrees is at the 3 o'clock position. - - \sa drawArc(), drawChord() -*/ - -void TQPainter::drawPie( int x, int y, int w, int h, int a, int alen ) -{ - // Make sure "a" is 0..360*16, as otherwise a*4 may overflow 16 bits. - if ( a > (360*16) ) { - a = a % (360*16); - } else if ( a < 0 ) { - a = a % (360*16); - if ( a < 0 ) a += (360*16); - } - - if ( !isActive() ) - return; - if ( testf(ExtDev|VxF|WxF) ) { - if ( testf(ExtDev) ) { - TQPDevCmdParam param[3]; - TQRect r( x, y, w, h ); - param[0].rect = &r; - param[1].ival = a; - param[2].ival = alen; - if ( !pdev->cmd( TQPaintDevice::PdcDrawPie, this, param ) || !hd ) - return; - } - if ( txop == TxRotShear ) { // rotate/shear - TQPointArray pa; - pa.makeArc( x, y, w, h, a, alen, xmat ); // arc polyline - int n = pa.size(); - int cx, cy; - xmat.map(x+w/2, y+h/2, &cx, &cy); - pa.resize( n+2 ); - pa.setPoint( n, cx, cy ); // add legs - pa.setPoint( n+1, pa.at(0) ); - drawPolyInternal( pa ); - return; - } - map( x, y, w, h, &x, &y, &w, &h ); - } - XSetArcMode( dpy, gc_brush, ArcPieSlice ); - w--; - h--; - if ( w <= 0 || h <= 0 ) { - if ( w == 0 || h == 0 ) - return; - fix_neg_rect( &x, &y, &w, &h ); - } - - GC g = gc; - bool nopen = cpen.style() == NoPen; - - if ( cbrush.style() != NoBrush ) { // draw filled pie - XFillArc( dpy, hd, gc_brush, x, y, w, h, a*4, alen*4 ); - if ( nopen ) { - g = gc_brush; - nopen = FALSE; - } - } - if ( !nopen ) { // draw pie outline - double w2 = 0.5*w; // with, height in ellipsis - double h2 = 0.5*h; - double xc = (double)x+w2; - double yc = (double)y+h2; - double ra1 = Q_PI/2880.0*a; // convert a, alen to radians - double ra2 = ra1 + Q_PI/2880.0*alen; - int xic = tqRound(xc); - int yic = tqRound(yc); - XDrawLine( dpy, hd, g, xic, yic, - tqRound(xc + qcos(ra1)*w2), tqRound(yc - qsin(ra1)*h2)); - XDrawLine( dpy, hd, g, xic, yic, - tqRound(xc + qcos(ra2)*w2), tqRound(yc - qsin(ra2)*h2)); - XDrawArc( dpy, hd, g, x, y, w, h, a*4, alen*4 ); - } -} - - -/*! - Draws a chord defined by the rectangle \a (x, y, w, h), the start - angle \a a and the arc length \a alen. - - The chord is filled with the current brush(). - - The angles \a a and \a alen are 1/16th of a degree, i.e. a full - circle equals 5760 (16*360). Positive values of \a a and \a alen - mean counter-clockwise while negative values mean the clockwise - direction. Zero degrees is at the 3 o'clock position. - - \sa drawArc(), drawPie() -*/ - -void TQPainter::drawChord( int x, int y, int w, int h, int a, int alen ) -{ - if ( !isActive() ) - return; - if ( testf(ExtDev|VxF|WxF) ) { - if ( testf(ExtDev) ) { - TQPDevCmdParam param[3]; - TQRect r( x, y, w, h ); - param[0].rect = &r; - param[1].ival = a; - param[2].ival = alen; - if ( !pdev->cmd(TQPaintDevice::PdcDrawChord, this, param) || !hd ) - return; - } - if ( txop == TxRotShear ) { // rotate/shear - TQPointArray pa; - pa.makeArc( x, y, w-1, h-1, a, alen, xmat ); // arc polygon - int n = pa.size(); - pa.resize( n+1 ); - pa.setPoint( n, pa.at(0) ); // connect endpoints - drawPolyInternal( pa ); - return; - } - map( x, y, w, h, &x, &y, &w, &h ); - } - XSetArcMode( dpy, gc_brush, ArcChord ); - w--; - h--; - if ( w <= 0 || h <= 0 ) { - if ( w == 0 || h == 0 ) - return; - fix_neg_rect( &x, &y, &w, &h ); - } - - GC g = gc; - bool nopen = cpen.style() == NoPen; - - if ( cbrush.style() != NoBrush ) { // draw filled chord - XFillArc( dpy, hd, gc_brush, x, y, w, h, a*4, alen*4 ); - if ( nopen ) { - g = gc_brush; - nopen = FALSE; - } - } - if ( !nopen ) { // draw chord outline - double w2 = 0.5*w; // with, height in ellipsis - double h2 = 0.5*h; - double xc = (double)x+w2; - double yc = (double)y+h2; - double ra1 = Q_PI/2880.0*a; // convert a, alen to radians - double ra2 = ra1 + Q_PI/2880.0*alen; - XDrawLine( dpy, hd, g, - tqRound(xc + qcos(ra1)*w2), tqRound(yc - qsin(ra1)*h2), - tqRound(xc + qcos(ra2)*w2), tqRound(yc - qsin(ra2)*h2)); - XDrawArc( dpy, hd, g, x, y, w, h, a*4, alen*4 ); - } - XSetArcMode( dpy, gc_brush, ArcPieSlice ); -} - - -/*! - Draws \a nlines separate lines from points defined in \a a, - starting at \a a[index] (\a index defaults to 0). If \a nlines is - -1 (the default) all points until the end of the array are used - (i.e. (a.size()-index)/2 lines are drawn). - - Draws the 1st line from \a a[index] to \a a[index+1]. Draws the - 2nd line from \a a[index+2] to \a a[index+3] etc. - - \warning On X11, coordinates that do not fit into 16-bit signed - values are truncated. This limitation is expected to go away in - TQt 4. - - \sa drawPolyline(), drawPolygon(), TQPen -*/ - -void TQPainter::drawLineSegments( const TQPointArray &a, int index, int nlines ) -{ - if ( nlines < 0 ) - nlines = a.size()/2 - index/2; - if ( index + nlines*2 > (int)a.size() ) - nlines = (a.size() - index)/2; - if ( !isActive() || nlines < 1 || index < 0 ) - return; - TQPointArray pa = a; - if ( testf(ExtDev|VxF|WxF) ) { - if ( testf(ExtDev) ) { - if ( 2*nlines != (int)pa.size() ) { - pa = TQPointArray( nlines*2 ); - for ( int i=0; icmd(TQPaintDevice::PdcDrawLineSegments, this, param) || - !hd ) - return; - } - if ( txop != TxNone ) { - pa = xForm( a, index, nlines*2 ); - if ( pa.size() != a.size() ) { - index = 0; - nlines = pa.size()/2; - } - } - } - if ( cpen.style() != NoPen ) - XDrawSegments( dpy, hd, gc, - (XSegment*)(pa.shortPoints( index, nlines*2 )), nlines ); -} - - -/*! - Draws the polyline defined by the \a npoints points in \a a - starting at \a a[index]. (\a index defaults to 0.) - - If \a npoints is -1 (the default) all points until the end of the - array are used (i.e. a.size()-index-1 line segments are drawn). - - \warning On X11, coordinates that do not fit into 16-bit signed - values are truncated. This limitation is expected to go away in - TQt 4. - - \sa drawLineSegments(), drawPolygon(), TQPen -*/ - -void TQPainter::drawPolyline( const TQPointArray &a, int index, int npoints ) -{ - if ( npoints < 0 ) - npoints = a.size() - index; - if ( index + npoints > (int)a.size() ) - npoints = a.size() - index; - if ( !isActive() || npoints < 2 || index < 0 ) - return; - TQPointArray pa = a; - if ( testf(ExtDev|VxF|WxF) ) { - if ( testf(ExtDev) ) { - if ( npoints != (int)pa.size() ) { - pa = TQPointArray( npoints ); - for ( int i=0; icmd(TQPaintDevice::PdcDrawPolyline, this, param) || !hd ) - return; - } - if ( txop != TxNone ) { - pa = xForm( pa, index, npoints ); - if ( pa.size() != a.size() ) { - index = 0; - npoints = pa.size(); - } - } - } - if ( cpen.style() != NoPen ) { - while(npoints>65535) { - XDrawLines( dpy, hd, gc, (XPoint*)(pa.shortPoints( index, 65535 )), - 65535, CoordModeOrigin ); - npoints-=65535; - index+=65535; - } - XDrawLines( dpy, hd, gc, (XPoint*)(pa.shortPoints( index, npoints )), - npoints, CoordModeOrigin ); - } -} - -static int global_polygon_shape = Complex; - -/*! - Draws the polygon defined by the \a npoints points in \a a - starting at \a a[index]. (\a index defaults to 0.) - - If \a npoints is -1 (the default) all points until the end of the - array are used (i.e. a.size()-index line segments define the - polygon). - - The first point is always connected to the last point. - - The polygon is filled with the current brush(). If \a winding is - TRUE, the polygon is filled using the winding fill algorithm. If - \a winding is FALSE, the polygon is filled using the even-odd - (alternative) fill algorithm. - - \warning On X11, coordinates that do not fit into 16-bit signed - values are truncated. This limitation is expected to go away in - TQt 4. - - \sa drawLineSegments(), drawPolyline(), TQPen -*/ - -void TQPainter::drawPolygon( const TQPointArray &a, bool winding, - int index, int npoints ) -{ - if ( npoints < 0 ) - npoints = a.size() - index; - if ( index + npoints > (int)a.size() ) - npoints = a.size() - index; - if ( !isActive() || npoints < 2 || index < 0 ) - return; - TQPointArray pa = a; - if ( testf(ExtDev|VxF|WxF) ) { - if ( testf(ExtDev) ) { - if ( npoints != (int)a.size() ) { - pa = TQPointArray( npoints ); - for ( int i=0; icmd(TQPaintDevice::PdcDrawPolygon, this, param) || !hd ) - return; - } - if ( txop != TxNone ) { - pa = xForm( a, index, npoints ); - if ( pa.size() != a.size() ) { - index = 0; - npoints = pa.size(); - } - } - } - if ( winding ) // set to winding fill rule - XSetFillRule( dpy, gc_brush, WindingRule ); - - if ( pa[index] != pa[index+npoints-1] ){ // close open pointarray - pa.detach(); - pa.resize( index+npoints+1 ); - pa.setPoint( index+npoints, pa[index] ); - npoints++; - } - - if ( cbrush.style() != NoBrush ) { // draw filled polygon - XFillPolygon( dpy, hd, gc_brush, - (XPoint*)(pa.shortPoints( index, npoints )), - npoints, global_polygon_shape, CoordModeOrigin ); - } - if ( cpen.style() != NoPen ) { // draw outline - XDrawLines( dpy, hd, gc, (XPoint*)(pa.shortPoints( index, npoints )), - npoints, CoordModeOrigin ); - } - if ( winding ) // set to normal fill rule - XSetFillRule( dpy, gc_brush, EvenOddRule ); -} - -/*! - Draws the convex polygon defined by the \a npoints points in \a pa - starting at \a pa[index] (\a index defaults to 0). - - If the supplied polygon is not convex, the results are undefined. - - On some platforms (e.g. X Window), this is faster than - drawPolygon(). - - \warning On X11, coordinates that do not fit into 16-bit signed - values are truncated. This limitation is expected to go away in - TQt 4. -*/ -void TQPainter::drawConvexPolygon( const TQPointArray &pa, - int index, int npoints ) -{ - global_polygon_shape = Convex; - drawPolygon(pa, FALSE, index, npoints); - global_polygon_shape = Complex; -} - - - -/*! - Draws a cubic Bezier curve defined by the control points in \a a, - starting at \a a[index] (\a index defaults to 0). - - Control points after \a a[index + 3] are ignored. Nothing happens - if there aren't enough control points. - - \warning On X11, coordinates that do not fit into 16-bit signed - values are truncated. This limitation is expected to go away in - TQt 4. -*/ - -void TQPainter::drawCubicBezier( const TQPointArray &a, int index ) -{ - if ( !isActive() ) - return; - if ( a.size() - index < 4 ) { -#if defined(QT_CHECK_RANGE) - tqWarning( "TQPainter::drawCubicBezier: Cubic Bezier needs 4 control " - "points" ); -#endif - return; - } - TQPointArray pa( a ); - if ( index != 0 || a.size() > 4 ) { - pa = TQPointArray( 4 ); - for ( int i=0; i<4; i++ ) - pa.setPoint( i, a.point(index+i) ); - } - if ( testf(ExtDev|VxF|WxF) ) { - if ( testf(ExtDev) ) { - TQPDevCmdParam param[1]; - param[0].ptarr = (TQPointArray*)&pa; - if ( !pdev->cmd(TQPaintDevice::PdcDrawCubicBezier, this, param) || - !hd ) - return; - } - if ( txop != TxNone ) - pa = xForm( pa ); - } - if ( cpen.style() != NoPen ) { - pa = pa.cubicBezier(); - XDrawLines( dpy, hd, gc, (XPoint*)pa.shortPoints(), pa.size(), - CoordModeOrigin ); - } -} - - -/*! - Draws a pixmap at \a (x, y) by copying a part of \a pixmap into - the paint device. - - \a (x, y) specifies the top-left point in the paint device that is - to be drawn onto. \a (sx, sy) specifies the top-left point in \a - pixmap that is to be drawn. The default is (0, 0). - - \a (sw, sh) specifies the size of the pixmap that is to be drawn. - The default, (-1, -1), means all the way to the bottom right of - the pixmap. - - Currently the mask of the pixmap or it's alpha channel are ignored - when painting on a TQPrinter. - - \sa bitBlt(), TQPixmap::setMask() -*/ - -void TQPainter::drawPixmap( int x, int y, const TQPixmap &pixmap, - int sx, int sy, int sw, int sh ) -{ - if ( !isActive() || pixmap.isNull() ) - return; - - // right/bottom - if ( sw < 0 ) - sw = pixmap.width() - sx; - if ( sh < 0 ) - sh = pixmap.height() - sy; - - // Sanity-check clipping - if ( sx < 0 ) { - x -= sx; - sw += sx; - sx = 0; - } - if ( sw + sx > pixmap.width() ) - sw = pixmap.width() - sx; - if ( sy < 0 ) { - y -= sy; - sh += sy; - sy = 0; - } - if ( sh + sy > pixmap.height() ) - sh = pixmap.height() - sy; - - if ( sw <= 0 || sh <= 0 ) - return; - - if ( pdev->x11Screen() != pixmap.x11Screen() ) { - TQPixmap* p = (TQPixmap*) &pixmap; - p->x11SetScreen( pdev->x11Screen() ); - } - - TQPixmap::x11SetDefaultScreen( pixmap.x11Screen() ); - - if ( testf(ExtDev|VxF|WxF) ) { - if ( testf(ExtDev) || txop == TxScale || txop == TxRotShear ) { - if ( sx != 0 || sy != 0 || - sw != pixmap.width() || sh != pixmap.height() ) { - TQPixmap tmp( sw, sh, pixmap.depth() ); - bitBlt( &tmp, 0, 0, &pixmap, sx, sy, sw, sh, CopyROP, TRUE ); - if ( pixmap.mask() ) { - TQBitmap mask( sw, sh ); - bitBlt( &mask, 0, 0, pixmap.mask(), sx, sy, sw, sh, - CopyROP, TRUE ); - tmp.setMask( mask ); - } - drawPixmap( x, y, tmp ); - return; - } - if ( testf(ExtDev) ) { - TQPDevCmdParam param[2]; - TQRect r(x, y, pixmap.width(), pixmap.height()); - param[0].rect = &r; - param[1].pixmap = &pixmap; - if ( !pdev->cmd(TQPaintDevice::PdcDrawPixmap, this, param) || !hd ) - return; - } - if ( txop == TxScale || txop == TxRotShear ) { - TQWMatrix mat( m11(), m12(), - m21(), m22(), - dx(), dy() ); - mat = TQPixmap::trueMatrix( mat, sw, sh ); - TQPixmap pm = pixmap.xForm( mat ); - if ( !pm.mask() && txop == TxRotShear ) { - TQBitmap bm_clip( sw, sh, 1 ); - bm_clip.fill( color1 ); - pm.setMask( bm_clip.xForm(mat) ); - } - map( x, y, &x, &y ); // compute position of pixmap - int dx, dy; - mat.map( 0, 0, &dx, &dy ); - uint save_flags = flags; - flags = IsActive | (save_flags & ClipOn); - drawPixmap( x-dx, y-dy, pm ); - flags = save_flags; - return; - } - } - map( x, y, &x, &y ); - } - - TQBitmap *mask = (TQBitmap *)pixmap.mask(); - bool mono = pixmap.depth() == 1; - - if ( mask && !hasClipping() && pdev != paintEventDevice ) { - if ( mono ) { // needs GCs pen color - bool selfmask = pixmap.data->selfmask; - if ( selfmask ) { - XSetFillStyle( dpy, gc, FillStippled ); - XSetStipple( dpy, gc, pixmap.handle() ); - } else { - XSetFillStyle( dpy, gc, FillOpaqueStippled ); - XSetStipple( dpy, gc, pixmap.handle() ); - XSetClipMask( dpy, gc, mask->handle() ); - XSetClipOrigin( dpy, gc, x-sx, y-sy ); - } - XSetTSOrigin( dpy, gc, x-sx, y-sy ); - XFillRectangle( dpy, hd, gc, x, y, sw, sh ); - XSetTSOrigin( dpy, gc, 0, 0 ); - XSetFillStyle( dpy, gc, FillSolid ); - if ( !selfmask ) { - if ( pdev == paintEventDevice && paintEventClipRegion ) { - x11SetClipRegion( dpy, gc, 0, rendhd, *paintEventClipRegion ); - } else { - x11ClearClipRegion(dpy, gc, 0, rendhd); - } - } - } else { - bitBlt( pdev, x, y, &pixmap, sx, sy, sw, sh, (RasterOp)rop ); - } - return; - } - - TQRegion rgn = crgn; - - if ( mask ) { // pixmap has clip mask - // Implies that clipping is on, either explicit or implicit - // Create a new mask that combines the mask with the clip region - - if ( pdev == paintEventDevice && paintEventClipRegion ) { - if ( hasClipping() ) - rgn = rgn.intersect( *paintEventClipRegion ); - else - rgn = *paintEventClipRegion; - } - - TQBitmap *comb = new TQBitmap( sw, sh ); - comb->detach(); - GC cgc = tqt_xget_temp_gc( pixmap.x11Screen(), TRUE ); // get temporary mono GC - XSetForeground( dpy, cgc, 0 ); - XFillRectangle( dpy, comb->handle(), cgc, 0, 0, sw, sh ); - XSetBackground( dpy, cgc, 0 ); - XSetForeground( dpy, cgc, 1 ); - int num; - XRectangle *rects = (XRectangle *)qt_getClipRects( rgn, num ); - XSetClipRectangles( dpy, cgc, -x, -y, rects, num, YXBanded ); - XSetFillStyle( dpy, cgc, FillOpaqueStippled ); - XSetStipple( dpy, cgc, mask->handle() ); - XSetTSOrigin( dpy, cgc, -sx, -sy ); - XFillRectangle( dpy, comb->handle(), cgc, 0, 0, sw, sh ); - XSetTSOrigin( dpy, cgc, 0, 0 ); // restore cgc - XSetFillStyle( dpy, cgc, FillSolid ); - XSetClipMask( dpy, cgc, None ); - mask = comb; // it's deleted below - - XSetClipMask( dpy, gc, mask->handle() ); - XSetClipOrigin( dpy, gc, x, y ); - } - - if ( mono ) { - XSetBackground( dpy, gc, bg_col.pixel(scrn) ); - XSetFillStyle( dpy, gc, FillOpaqueStippled ); - XSetStipple( dpy, gc, pixmap.handle() ); - XSetTSOrigin( dpy, gc, x-sx, y-sy ); - XFillRectangle( dpy, hd, gc, x, y, sw, sh ); - XSetTSOrigin( dpy, gc, 0, 0 ); - XSetFillStyle( dpy, gc, FillSolid ); - } else { -#if !defined(TQT_NO_XFTFREETYPE) && !defined(TQT_NO_XRENDER) - Picture pict = rendhd ? XftDrawPicture((XftDraw *) rendhd) : None; - TQPixmap *alpha = pixmap.data->alphapm; - - if ( pict && pixmap.x11RenderHandle() && - alpha && alpha->x11RenderHandle()) { - XRenderComposite(dpy, PictOpOver, pixmap.x11RenderHandle(), - alpha->x11RenderHandle(), pict, - sx, sy, sx, sy, x, y, sw, sh); - } else -#endif // !TQT_NO_XFTFREETYPE && !TQT_NO_XRENDER - { - XCopyArea( dpy, pixmap.handle(), hd, gc, sx, sy, sw, sh, x, y ); - } - } - - if ( mask ) { // restore clipping - XSetClipOrigin( dpy, gc, 0, 0 ); - XSetRegion( dpy, gc, rgn.handle() ); - delete mask; // delete comb, created above - } -} - - -/* Internal, used by drawTiledPixmap */ - -static void drawTile( TQPainter *p, int x, int y, int w, int h, - const TQPixmap &pixmap, int xOffset, int yOffset ) -{ - int yPos, xPos, drawH, drawW, yOff, xOff; - yPos = y; - yOff = yOffset; - while( yPos < y + h ) { - drawH = pixmap.height() - yOff; // Cropping first row - if ( yPos + drawH > y + h ) // Cropping last row - drawH = y + h - yPos; - xPos = x; - xOff = xOffset; - while( xPos < x + w ) { - drawW = pixmap.width() - xOff; // Cropping first column - if ( xPos + drawW > x + w ) // Cropping last column - drawW = x + w - xPos; - p->drawPixmap( xPos, yPos, pixmap, xOff, yOff, drawW, drawH ); - xPos += drawW; - xOff = 0; - } - yPos += drawH; - yOff = 0; - } -} - -#if 0 // see comment in drawTiledPixmap -/* Internal, used by drawTiledPixmap */ - -static void fillTile( TQPixmap *tile, const TQPixmap &pixmap ) -{ - bitBlt( tile, 0, 0, &pixmap, 0, 0, -1, -1, TQt::CopyROP, TRUE ); - int x = pixmap.width(); - while ( x < tile->width() ) { - bitBlt( tile, x,0, tile, 0,0, x,pixmap.height(), TQt::CopyROP, TRUE ); - x *= 2; - } - int y = pixmap.height(); - while ( y < tile->height() ) { - bitBlt( tile, 0,y, tile, 0,0, tile->width(),y, TQt::CopyROP, TRUE ); - y *= 2; - } -} -#endif - -/*! - Draws a tiled \a pixmap in the specified rectangle. - - \a (x, y) specifies the top-left point in the paint device that is - to be drawn onto; with the width and height given by \a w and \a - h. \a (sx, sy) specifies the top-left point in \a pixmap that is - to be drawn. The default is (0, 0). - - Calling drawTiledPixmap() is similar to calling drawPixmap() - several times to fill (tile) an area with a pixmap, but is - potentially much more efficient depending on the underlying window - system. - - \sa drawPixmap() -*/ - -void TQPainter::drawTiledPixmap( int x, int y, int w, int h, - const TQPixmap &pixmap, int sx, int sy ) -{ - int sw = pixmap.width(); - int sh = pixmap.height(); - if (!sw || !sh ) - return; - if ( sx < 0 ) - sx = sw - -sx % sw; - else - sx = sx % sw; - if ( sy < 0 ) - sy = sh - -sy % sh; - else - sy = sy % sh; - /* - Requirements for optimizing tiled pixmaps: - - not an external device - - not scale or rotshear - - not mono pixmap - - no mask - */ - TQBitmap *mask = (TQBitmap *)pixmap.mask(); - if ( !testf(ExtDev) && txop <= TxTranslate && pixmap.depth() > 1 && - mask == 0 ) { - if ( txop == TxTranslate ) - map( x, y, &x, &y ); - -#if !defined(TQT_NO_XFTFREETYPE) && !defined(TQT_NO_XRENDER) - Picture pict = rendhd ? XftDrawPicture((XftDraw *) rendhd) : None; - TQPixmap *alpha = pixmap.data->alphapm; - - if (pict && pixmap.x11RenderHandle() && alpha && alpha->x11RenderHandle()) { - // this is essentially drawTile() from above, inlined for - // the XRenderComposite call - int yPos, xPos, drawH, drawW, yOff, xOff; - yPos = y; - yOff = sy; - while( yPos < y + h ) { - drawH = pixmap.height() - yOff; // Cropping first row - if ( yPos + drawH > y + h ) // Cropping last row - drawH = y + h - yPos; - xPos = x; - xOff = sx; - while( xPos < x + w ) { - drawW = pixmap.width() - xOff; // Cropping first column - if ( xPos + drawW > x + w ) // Cropping last column - drawW = x + w - xPos; - XRenderComposite(dpy, PictOpOver, pixmap.x11RenderHandle(), - alpha->x11RenderHandle(), pict, - xOff, yOff, xOff, yOff, xPos, yPos, drawW, drawH); - xPos += drawW; - xOff = 0; - } - yPos += drawH; - yOff = 0; - } - return; - } -#endif // !TQT_NO_XFTFREETYPE && !TQT_NO_XRENDER - - XSetTile( dpy, gc, pixmap.handle() ); - XSetFillStyle( dpy, gc, FillTiled ); - XSetTSOrigin( dpy, gc, x-sx, y-sy ); - XFillRectangle( dpy, hd, gc, x, y, w, h ); - XSetTSOrigin( dpy, gc, 0, 0 ); - XSetFillStyle( dpy, gc, FillSolid ); - return; - } - -#if 0 - // maybe there'll be point in this again, but for the time all it - // does is make trouble for the postscript code. - if ( sw*sh < 8192 && sw*sh < 16*w*h ) { - int tw = sw; - int th = sh; - while( th * tw < 4096 && ( th < h || tw < w ) ) { - if ( h/th > w/tw ) - th *= 2; - else - tw *= 2; - } - TQPixmap tile( tw, th, pixmap.depth(), TQPixmap::NormalOptim ); - fillTile( &tile, pixmap ); - if ( mask ) { - TQBitmap tilemask( tw, th, TQPixmap::NormalOptim ); - fillTile( &tilemask, *mask ); - tile.setMask( tilemask ); - } - drawTile( this, x, y, w, h, tile, sx, sy ); - } else { - drawTile( this, x, y, w, h, pixmap, sx, sy ); - } -#else - // for now we'll just output the original and let the postscript - // code make what it can of it. qpicture will be unhappy. - drawTile( this, x, y, w, h, pixmap, sx, sy ); -#endif -} - -#if 0 -// -// Generate a string that describes a transformed bitmap. This string is used -// to insert and find bitmaps in the global pixmap cache. -// - -static TQString gen_text_bitmap_key( const TQWMatrix &m, const TQFont &font, - const TQString &str, int pos, int len ) -{ - TQString fk = font.key(); - int sz = 4*2 + len*2 + fk.length()*2 + sizeof(double)*6; - TQByteArray buf(sz); - uchar *p = (uchar *)buf.data(); - *((double*)p)=m.m11(); p+=sizeof(double); - *((double*)p)=m.m12(); p+=sizeof(double); - *((double*)p)=m.m21(); p+=sizeof(double); - *((double*)p)=m.m22(); p+=sizeof(double); - *((double*)p)=m.dx(); p+=sizeof(double); - *((double*)p)=m.dy(); p+=sizeof(double); - TQChar h1( '$' ); - TQChar h2( 'q' ); - TQChar h3( 't' ); - TQChar h4( '$' ); - *((TQChar*)p)=h1; p+=2; - *((TQChar*)p)=h2; p+=2; - *((TQChar*)p)=h3; p+=2; - *((TQChar*)p)=h4; p+=2; - memcpy( (char*)p, (char*)(str.unicode()+pos), len*2 ); p += len*2; - memcpy( (char*)p, (char*)fk.unicode(), fk.length()*2 ); p += fk.length()*2; - return TQString( (TQChar*)buf.data(), buf.size()/2 ); -} - -static TQBitmap *get_text_bitmap( const TQString &key ) -{ - return (TQBitmap*)TQPixmapCache::find( key ); -} - -static void ins_text_bitmap( const TQString &key, TQBitmap *bm ) -{ - if ( !TQPixmapCache::insert(key, bm) ) // cannot insert pixmap - delete bm; -} -#endif - -void qt_draw_transformed_rect( TQPainter *p, int x, int y, int w, int h, bool fill ) -{ - XPoint points[5]; - int xp = x, yp = y; - p->map( xp, yp, &xp, &yp ); - points[0].x = xp; - points[0].y = yp; - xp = x + w; yp = y; - p->map( xp, yp, &xp, &yp ); - points[1].x = xp; - points[1].y = yp; - xp = x + w; yp = y + h; - p->map( xp, yp, &xp, &yp ); - points[2].x = xp; - points[2].y = yp; - xp = x; yp = y + h; - p->map( xp, yp, &xp, &yp ); - points[3].x = xp; - points[3].y = yp; - points[4] = points[0]; - - if ( fill ) - XFillPolygon( p->dpy, p->hd, p->gc, points, 4, Convex, CoordModeOrigin ); - else - XDrawLines( p->dpy, p->hd, p->gc, points, 5, CoordModeOrigin ); -} - -void qt_draw_background( TQPainter *p, int x, int y, int w, int h ) -{ - if (p->testf(TQPainter::ExtDev)) { - if (p->pdev->devType() == TQInternal::Printer) - p->fillRect(x, y, w, h, p->bg_col); - return; - } - XSetForeground( p->dpy, p->gc, p->bg_col.pixel(p->scrn) ); - qt_draw_transformed_rect( p, x, y, w, h, TRUE); - XSetForeground( p->dpy, p->gc, p->cpen.color().pixel(p->scrn) ); -} - -/*! - Draws at most \a len characters of the string \a str at position - \a (x, y). - - \a (x, y) is the base line position. Note that the meaning of \a y - is not the same for the two drawText() varieties. -*/ -void TQPainter::drawText( int x, int y, const TQString &str, int len, TQPainter::TextDirection dir ) -{ - drawText( x, y, str, 0, len, dir ); -} - -/*! - Draws at most \a len characters starting at position \a pos from the - string \a str to position \a (x, y). - - \a (x, y) is the base line position. Note that the meaning of \a y - is not the same for the two drawText() varieties. -*/ -void TQPainter::drawText( int x, int y, const TQString &str, int pos, int len, TQPainter::TextDirection dir ) -{ - if ( !isActive() ) - return; - if (len < 0) - len = str.length() - pos; - if ( len <= 0 || pos >= (int)str.length() ) // empty string - return; - if ( pos + len > (int)str.length() ) - len = str.length() - pos; - - if ( testf(DirtyFont) ) { - updateFont(); - } - - if ( testf(ExtDev) && pdev->devType() != TQInternal::Printer ) { - TQPDevCmdParam param[3]; - TQPoint p(x, y); - TQString string = str.mid( pos, len ); - param[0].point = &p; - param[1].str = &string; - param[2].ival = TQFont::Latin; - if ( !pdev->cmd(TQPaintDevice::PdcDrawText2, this, param) || !hd ) - return; - } - - bool simple = (dir == TQPainter::Auto) && str.simpleText(); - // we can't take the complete string here as we would otherwise - // get quadratic behaviour when drawing long strings in parts. - // we do however need some chars around the part we paint to get arabic shaping correct. - // ### maybe possible to remove after cursor restrictions work in TQRT - int start; - int end; - if ( simple ) { - start = pos; - end = pos+len; - } else { - start = TQMAX( 0, pos - 8 ); - end = TQMIN( (int)str.length(), pos + len + 8 ); - } - TQConstString cstr( str.unicode() + start, end - start ); - pos -= start; - - TQTextEngine engine( cstr.string(), pfont ? pfont->d : cfont.d ); - TQTextLayout layout( &engine ); - - // this is actually what beginLayout does. Inlined here, so we can - // avoid the bidi algorithm if we don't need it. - engine.itemize( simple ? TQTextEngine::NoBidi|TQTextEngine::SingleLine : TQTextEngine::Full|TQTextEngine::SingleLine ); - engine.currentItem = 0; - engine.firstItemInLine = -1; - - if ( dir != Auto ) { - int level = dir == RTL ? 1 : 0; - for ( int i = engine.items.size(); i >= 0; i-- ) - engine.items[i].analysis.bidiLevel = level; - } - - if ( !simple ) { - layout.setBoundary( pos ); - layout.setBoundary( pos + len ); - } - - // small hack to force skipping of unneeded items - start = 0; - while ( engine.items[start].position < pos ) - ++start; - engine.currentItem = start; - layout.beginLine( 0xfffffff ); - end = start; - while ( !layout.atEnd() && layout.currentItem().from() < pos + len ) { - layout.addCurrentItem(); - end++; - } - TQFontMetrics fm(fontMetrics()); - int ascent = fm.ascent(), descent = fm.descent(); - int left, right; - layout.endLine( 0, 0, TQt::SingleLine|TQt::AlignLeft, &ascent, &descent, &left, &right ); - - // do _not_ call endLayout() here, as it would clean up the shaped items and we would do shaping another time - // for painting. - - int textFlags = 0; - if ( cfont.d->underline ) textFlags |= TQt::Underline; - if ( cfont.d->overline ) textFlags |= TQt::Overline; - if ( cfont.d->strikeOut ) textFlags |= TQt::StrikeOut; - - if ( bg_mode == OpaqueMode ) - qt_draw_background( this, x, y-ascent, right-left, ascent+descent+1); - - for ( int i = start; i < end; i++ ) { - TQTextItem ti; - ti.item = i; - ti.engine = &engine; - - drawTextItem( x, y - ascent, ti, textFlags ); - } - layout.d = 0; -} - - -/*! \internal - Draws the text item \a ti at position \a (x, y ). - - This method ignores the painters background mode and - color. drawText and qt_format_text have to do it themselves, as - only they know the extents of the complete string. - - It ignores the font set on the painter as the text item has one of its own. - - The underline and strikeout parameters of the text items font are - ignored aswell. You'll need to pass in the correct flags to get - underlining and strikeout. -*/ -void TQPainter::drawTextItem( int x, int y, const TQTextItem &ti, int textFlags ) -{ - if ( testf(ExtDev) ) { - TQPDevCmdParam param[2]; - TQPoint p(x, y); - param[0].point = &p; - param[1].textItem = &ti; - bool retval = pdev->cmd(TQPaintDevice::PdcDrawTextItem, this, param); - if ( !retval || !hd ) - return; - } - - TQTextEngine *engine = ti.engine; - TQScriptItem *si = &engine->items[ti.item]; - - engine->shape( ti.item ); - TQFontEngine *fe = si->fontEngine; - assert( fe != 0 ); - - x += si->x; - y += si->y; - - fe->draw( this, x, y, engine, si, textFlags ); -} - -/*! - \obsolete - Returns the current position of the pen. - - \sa moveTo() - */ -TQPoint TQPainter::pos() const -{ - return curPt; -} diff --git a/src/kernel/qpicture.cpp b/src/kernel/qpicture.cpp index 45e706cb1..35dd8439a 100644 --- a/src/kernel/qpicture.cpp +++ b/src/kernel/qpicture.cpp @@ -42,12 +42,12 @@ #ifndef TQT_NO_PICTURE -#include "ntqpainter.h" +#include "tqpainter.h" #include "ntqpixmap.h" #include "tqimage.h" #include "tqfile.h" #include "tqdatastream.h" -#include "ntqpaintdevicemetrics.h" +#include "tqpaintdevicemetrics.h" #ifndef TQT_NO_SVG #include "private/qsvgdevice_p.h" diff --git a/src/kernel/qpixmap.cpp b/src/kernel/qpixmap.cpp index c39a86e67..148b06da6 100644 --- a/src/kernel/qpixmap.cpp +++ b/src/kernel/qpixmap.cpp @@ -43,7 +43,7 @@ #include "tqbitmap.h" #include "tqimage.h" #include "tqwidget.h" -#include "ntqpainter.h" +#include "tqpainter.h" #include "tqdatastream.h" #include "tqbuffer.h" #include "tqobjectlist.h" diff --git a/src/kernel/qpixmap_x11.cpp b/src/kernel/qpixmap_x11.cpp index 1ddb18e02..1b5be8410 100644 --- a/src/kernel/qpixmap_x11.cpp +++ b/src/kernel/qpixmap_x11.cpp @@ -68,7 +68,7 @@ #endif #include "tqbitmap.h" -#include "ntqpaintdevicemetrics.h" +#include "tqpaintdevicemetrics.h" #include "tqimage.h" #include "ntqwmatrix.h" #include "ntqapplication.h" @@ -372,7 +372,7 @@ static void build_scale_table( uint **table, uint nBits ) static int defaultScreen = -1; extern bool tqt_use_xrender; // defined in qapplication_x11.cpp -extern bool tqt_has_xft; // defined in qfont_x11.cpp +extern bool tqt_has_xft; // defined in tqfont_x11.cpp #ifndef TQT_NO_XFTFREETYPE #ifndef QT_XFT2 diff --git a/src/kernel/qprinter_unix.cpp b/src/kernel/qprinter_unix.cpp index c5d613827..0c7cdfa6b 100644 --- a/src/kernel/qprinter_unix.cpp +++ b/src/kernel/qprinter_unix.cpp @@ -51,7 +51,7 @@ static inline int qt_open(const char *pathname, int flags, mode_t mode) #ifndef TQT_NO_PRINTER -#include "ntqpaintdevicemetrics.h" +#include "tqpaintdevicemetrics.h" #include "qpsprinter_p.h" #include "ntqprintdialog.h" #include "ntqapplication.h" diff --git a/src/kernel/qpsprinter.cpp b/src/kernel/qpsprinter.cpp index 8bd04b845..3d18d6008 100644 --- a/src/kernel/qpsprinter.cpp +++ b/src/kernel/qpsprinter.cpp @@ -56,9 +56,9 @@ #undef Q_PRINTER_USE_TYPE42 -#include "ntqpainter.h" +#include "tqpainter.h" #include "ntqapplication.h" -#include "ntqpaintdevicemetrics.h" +#include "tqpaintdevicemetrics.h" #include "tqimage.h" #include "tqdatetime.h" #include "tqstring.h" @@ -70,7 +70,7 @@ #include "tqtextcodec.h" #include "tqsettings.h" #include "tqmap.h" -#include "ntqfontdatabase.h" +#include "tqfontdatabase.h" #include "tqregexp.h" #include "tqbitmap.h" #include @@ -96,8 +96,8 @@ #endif #if defined( TQ_WS_X11 ) -#include "qfontdata_p.h" -#include "qfontengine_p.h" +#include "tqfontdata_p.h" +#include "tqfontengine_p.h" #include "tqtextlayout_p.h" #include "tqtextengine_p.h" extern bool tqt_has_xft; diff --git a/src/kernel/qrichtext.cpp b/src/kernel/qrichtext.cpp index eb31aa554..4da7dc3e6 100644 --- a/src/kernel/qrichtext.cpp +++ b/src/kernel/qrichtext.cpp @@ -44,7 +44,7 @@ #include "tqstringlist.h" -#include "ntqfont.h" +#include "tqfont.h" #include "tqtextstream.h" #include "tqfile.h" #include "ntqapplication.h" @@ -54,8 +54,8 @@ #include "tqmime.h" #include "tqimage.h" #include "tqdragobject.h" -#include "ntqpaintdevicemetrics.h" -#include "ntqpainter.h" +#include "tqpaintdevicemetrics.h" +#include "tqpainter.h" #include "ntqdrawutil.h" #include "ntqcursor.h" #include "tqptrstack.h" diff --git a/src/kernel/qrichtext_p.h b/src/kernel/qrichtext_p.h index e9422ec14..c9e40ef84 100644 --- a/src/kernel/qrichtext_p.h +++ b/src/kernel/qrichtext_p.h @@ -57,12 +57,12 @@ #include "tqstring.h" #include "tqptrlist.h" #include "ntqrect.h" -#include "ntqfontmetrics.h" +#include "tqfontmetrics.h" #include "tqintdict.h" #include "tqmap.h" #include "tqstringlist.h" -#include "ntqfont.h" -#include "ntqcolor.h" +#include "tqfont.h" +#include "tqcolor.h" #include "tqsize.h" #include "tqvaluelist.h" #include "tqvaluestack.h" @@ -71,7 +71,7 @@ #include "ntqpixmap.h" #include "tqstylesheet.h" #include "tqptrvector.h" -#include "ntqpainter.h" +#include "tqpainter.h" #include "ntqlayout.h" #include "tqobject.h" #include "ntqapplication.h" diff --git a/src/kernel/qscriptengine.cpp b/src/kernel/qscriptengine.cpp index 0dd19f3c3..b84aab65d 100644 --- a/src/kernel/qscriptengine.cpp +++ b/src/kernel/qscriptengine.cpp @@ -38,10 +38,10 @@ #include "tqstring.h" #include "ntqrect.h" -#include "ntqfont.h" +#include "tqfont.h" #include #include "tqtextengine_p.h" -#include "qfontengine_p.h" +#include "tqfontengine_p.h" #include #undef None diff --git a/src/kernel/qt_kernel.pri b/src/kernel/qt_kernel.pri index 5cbddd2db..946fdbd96 100644 --- a/src/kernel/qt_kernel.pri +++ b/src/kernel/qt_kernel.pri @@ -10,10 +10,10 @@ kernel { $$KERNEL_H/ntqasyncimageio.h \ $$KERNEL_H/ntqasyncio.h \ $$KERNEL_H/tqbitmap.h \ - $$KERNEL_H/ntqbrush.h \ + $$KERNEL_H/tqbrush.h \ $$KERNEL_H/tqclipboard.h \ - $$KERNEL_H/ntqcolor.h \ - $$KERNEL_P/qcolor_p.h \ + $$KERNEL_H/tqcolor.h \ + $$KERNEL_P/tqcolor_p.h \ $$KERNEL_H/ntqconnection.h \ $$KERNEL_H/ntqcursor.h \ $$KERNEL_H/ntqdesktopwidget.h \ @@ -25,10 +25,10 @@ kernel { $$KERNEL_P/qeventloop_p.h \ $$KERNEL_P/qeventloop_glib_p.h \ $$KERNEL_H/ntqfocusdata.h \ - $$KERNEL_H/ntqfont.h \ - $$KERNEL_P/qfontdata_p.h \ - $$KERNEL_H/ntqfontinfo.h \ - $$KERNEL_H/ntqfontmetrics.h \ + $$KERNEL_H/tqfont.h \ + $$KERNEL_P/tqfontdata_p.h \ + $$KERNEL_H/tqfontinfo.h \ + $$KERNEL_H/tqfontmetrics.h \ $$KERNEL_H/ntqguardedptr.h \ $$KERNEL_H/ntqgif.h \ $$KERNEL_H/tqiconset.h \ @@ -42,7 +42,7 @@ kernel { $$KERNEL_H/ntqtranslator.h \ $$KERNEL_H/ntqmetaobject.h \ $$KERNEL_H/tqmime.h \ - $$KERNEL_H/ntqmovie.h \ + $$KERNEL_H/tqmovie.h \ $$KERNEL_H/ntqnamespace.h \ $$KERNEL_H/tqnetworkprotocol.h \ $$KERNEL_H/tqobject.h \ @@ -50,11 +50,11 @@ kernel { $$KERNEL_H/tqobjectdefs.h \ $$KERNEL_H/tqobjectdict.h \ $$KERNEL_H/tqobjectlist.h \ - $$KERNEL_H/ntqpaintdevice.h \ - $$KERNEL_H/ntqpainter.h \ - $$KERNEL_P/qpainter_p.h \ + $$KERNEL_H/tqpaintdevice.h \ + $$KERNEL_H/tqpainter.h \ + $$KERNEL_P/tqpainter_p.h \ $$KERNEL_H/ntqpalette.h \ - $$KERNEL_H/ntqpaintdevicemetrics.h \ + $$KERNEL_H/tqpaintdevicemetrics.h \ $$KERNEL_H/ntqpen.h \ $$KERNEL_H/ntqpicture.h \ $$KERNEL_H/ntqpixmap.h \ @@ -95,7 +95,7 @@ kernel { $$KERNEL_H/ntqsimplerichtext.h \ $$KERNEL_CPP/qscriptengine_p.h \ $$KERNEL_CPP/tqtextengine_p.h \ - $$KERNEL_CPP/qfontengine_p.h \ + $$KERNEL_CPP/tqfontengine_p.h \ $$KERNEL_CPP/tqtextlayout_p.h inputmethod { @@ -112,45 +112,45 @@ kernel { win32:SOURCES += $$KERNEL_CPP/qapplication_win.cpp \ $$KERNEL_CPP/tqclipboard_win.cpp \ - $$KERNEL_CPP/qcolor_win.cpp \ + $$KERNEL_CPP/tqcolor_win.cpp \ $$KERNEL_CPP/qcursor_win.cpp \ $$KERNEL_CPP/qdesktopwidget_win.cpp \ $$KERNEL_CPP/qdnd_win.cpp \ $$KERNEL_CPP/qeventloop_win.cpp \ - $$KERNEL_CPP/qfont_win.cpp \ + $$KERNEL_CPP/tqfont_win.cpp \ $$KERNEL_CPP/qinputcontext_win.cpp \ $$KERNEL_CPP/tqmime_win.cpp \ $$KERNEL_CPP/qpixmap_win.cpp \ $$KERNEL_CPP/qprinter_win.cpp \ $$KERNEL_CPP/tqprocess_win.cpp \ - $$KERNEL_CPP/qpaintdevice_win.cpp \ - $$KERNEL_CPP/qpainter_win.cpp \ + $$KERNEL_CPP/tqpaintdevice_win.cpp \ + $$KERNEL_CPP/tqpainter_win.cpp \ $$KERNEL_CPP/qregion_win.cpp \ $$KERNEL_CPP/qsound_win.cpp \ $$KERNEL_CPP/tqthread_win.cpp \ $$KERNEL_CPP/tqwidget_win.cpp \ $$KERNEL_CPP/qole_win.c \ - $$KERNEL_CPP/qfontengine_win.cpp + $$KERNEL_CPP/tqfontengine_win.cpp unix:x11 { SOURCES += $$KERNEL_CPP/qapplication_x11.cpp \ $$KERNEL_CPP/tqclipboard_x11.cpp \ - $$KERNEL_CPP/qcolor_x11.cpp \ + $$KERNEL_CPP/tqcolor_x11.cpp \ $$KERNEL_CPP/qcursor_x11.cpp \ $$KERNEL_CPP/qdnd_x11.cpp \ $$KERNEL_CPP/qdesktopwidget_x11.cpp \ - $$KERNEL_CPP/qfont_x11.cpp \ + $$KERNEL_CPP/tqfont_x11.cpp \ $$KERNEL_CPP/qinputcontext.cpp \ $$KERNEL_CPP/qinputcontext_x11.cpp \ $$KERNEL_CPP/qmotifdnd_x11.cpp \ $$KERNEL_CPP/qpixmap_x11.cpp \ - $$KERNEL_CPP/qpaintdevice_x11.cpp \ - $$KERNEL_CPP/qpainter_x11.cpp \ + $$KERNEL_CPP/tqpaintdevice_x11.cpp \ + $$KERNEL_CPP/tqpainter_x11.cpp \ $$KERNEL_CPP/qregion_x11.cpp \ $$KERNEL_CPP/qsound_x11.cpp \ $$KERNEL_CPP/tqwidget_x11.cpp \ $$KERNEL_CPP/tqwidgetcreate_x11.cpp \ - $$KERNEL_CPP/qfontengine_x11.cpp + $$KERNEL_CPP/tqfontengine_x11.cpp glibmainloop { SOURCES += $$KERNEL_CPP/qeventloop_x11_glib.cpp } else { @@ -165,20 +165,20 @@ kernel { !embedded:!x11:mac { SOURCES += $$KERNEL_CPP/qapplication_mac.cpp \ $$KERNEL_CPP/tqclipboard_mac.cpp \ - $$KERNEL_CPP/qcolor_mac.cpp \ + $$KERNEL_CPP/tqcolor_mac.cpp \ $$KERNEL_CPP/qcursor_mac.cpp \ $$KERNEL_CPP/tqmime_mac.cpp \ $$KERNEL_CPP/qdnd_mac.cpp \ $$KERNEL_CPP/qdesktopwidget_mac.cpp \ $$KERNEL_CPP/qpixmap_mac.cpp \ $$KERNEL_CPP/qprinter_mac.cpp \ - $$KERNEL_CPP/qpaintdevice_mac.cpp \ - $$KERNEL_CPP/qpainter_mac.cpp \ + $$KERNEL_CPP/tqpaintdevice_mac.cpp \ + $$KERNEL_CPP/tqpainter_mac.cpp \ $$KERNEL_CPP/qregion_mac.cpp \ $$KERNEL_CPP/tqwidget_mac.cpp \ $$KERNEL_CPP/qeventloop_mac.cpp \ - $$KERNEL_CPP/qfont_mac.cpp \ - $$KERNEL_CPP/qfontengine_mac.cpp + $$KERNEL_CPP/tqfont_mac.cpp \ + $$KERNEL_CPP/tqfontengine_mac.cpp DEFINES += QMAC_ONE_PIXEL_LOCK } else:unix { SOURCES += $$KERNEL_CPP/qprinter_unix.cpp \ @@ -201,8 +201,8 @@ kernel { $$KERNEL_CPP/qasyncio.cpp \ $$KERNEL_CPP/tqbitmap.cpp \ $$KERNEL_CPP/tqclipboard.cpp \ - $$KERNEL_CPP/qcolor.cpp \ - $$KERNEL_CPP/qcolor_p.cpp \ + $$KERNEL_CPP/tqcolor.cpp \ + $$KERNEL_CPP/tqcolor_p.cpp \ $$KERNEL_CPP/qconnection.cpp \ $$KERNEL_CPP/qcursor.cpp \ $$KERNEL_CPP/tqdragobject.cpp \ @@ -211,8 +211,8 @@ kernel { $$KERNEL_CPP/qevent.cpp \ $$KERNEL_CPP/qeventloop.cpp \ $$KERNEL_CPP/qfocusdata.cpp \ - $$KERNEL_CPP/qfont.cpp \ - $$KERNEL_CPP/qfontdatabase.cpp \ + $$KERNEL_CPP/tqfont.cpp \ + $$KERNEL_CPP/tqfontdatabase.cpp \ $$KERNEL_CPP/qguardedptr.cpp \ $$KERNEL_CPP/tqiconset.cpp \ $$KERNEL_CPP/tqimage.cpp \ @@ -223,13 +223,13 @@ kernel { $$KERNEL_CPP/qtranslator.cpp \ $$KERNEL_CPP/qmetaobject.cpp \ $$KERNEL_CPP/tqmime.cpp \ - $$KERNEL_CPP/qmovie.cpp \ + $$KERNEL_CPP/tqmovie.cpp \ $$KERNEL_CPP/tqnetworkprotocol.cpp \ $$KERNEL_CPP/tqobject.cpp \ $$KERNEL_CPP/tqobjectcleanuphandler.cpp \ - $$KERNEL_CPP/qpainter.cpp \ + $$KERNEL_CPP/tqpainter.cpp \ $$KERNEL_CPP/qpalette.cpp \ - $$KERNEL_CPP/qpaintdevicemetrics.cpp \ + $$KERNEL_CPP/tqpaintdevicemetrics.cpp \ $$KERNEL_CPP/qpicture.cpp \ $$KERNEL_CPP/qpixmap.cpp \ $$KERNEL_CPP/qpixmapcache.cpp \ @@ -267,7 +267,7 @@ kernel { $$KERNEL_CPP/tqtextengine.cpp unix:HEADERS += $$KERNEL_P/qpsprinter_p.h \ - $$KERNEL_H/ntqfontdatabase.h + $$KERNEL_H/tqfontdatabase.h accessibility { HEADERS += $$KERNEL_H/ntqaccessible.h diff --git a/src/kernel/qt_pch.h b/src/kernel/qt_pch.h index 8222ec592..bfd957097 100644 --- a/src/kernel/qt_pch.h +++ b/src/kernel/qt_pch.h @@ -31,7 +31,7 @@ #include #include // All moc genereated code has this include #include -#include +#include #include #include #include diff --git a/src/kernel/qvariant.cpp b/src/kernel/qvariant.cpp index 19e8f85ac..3f8944ab7 100644 --- a/src/kernel/qvariant.cpp +++ b/src/kernel/qvariant.cpp @@ -44,14 +44,14 @@ #ifndef TQT_NO_VARIANT #include "tqstring.h" #include "tqcstring.h" -#include "ntqfont.h" +#include "tqfont.h" #include "ntqpixmap.h" #include "tqimage.h" -#include "ntqbrush.h" +#include "tqbrush.h" #include "ntqpoint.h" #include "ntqrect.h" #include "tqsize.h" -#include "ntqcolor.h" +#include "tqcolor.h" #include "ntqpalette.h" #include "tqiconset.h" #include "tqdatastream.h" diff --git a/src/kernel/qwmatrix.cpp b/src/kernel/qwmatrix.cpp index 6c881b208..78dc80c0d 100644 --- a/src/kernel/qwmatrix.cpp +++ b/src/kernel/qwmatrix.cpp @@ -42,7 +42,7 @@ #include "tqdatastream.h" #include "ntqregion.h" #if defined(TQ_WS_X11) -double qsincos( double, bool calcCos ); // defined in qpainter_x11.cpp +double qsincos( double, bool calcCos ); // defined in tqpainter_x11.cpp #else #include #endif diff --git a/src/kernel/tqbrush.h b/src/kernel/tqbrush.h new file mode 100644 index 000000000..6ec4424e6 --- /dev/null +++ b/src/kernel/tqbrush.h @@ -0,0 +1,94 @@ +/**************************************************************************** +** +** Definition of TQBrush class +** +** Created : 940112 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef TQBRUSH_H +#define TQBRUSH_H + +#ifndef QT_H +#include "tqcolor.h" +#include "ntqshared.h" +#endif // QT_H + + +class TQ_EXPORT TQBrush: public TQt +{ +friend class TQPainter; +public: + TQBrush(); + TQBrush( BrushStyle ); + TQBrush( const TQColor &, BrushStyle=SolidPattern ); + TQBrush( const TQColor &, const TQPixmap & ); + TQBrush( const TQBrush & ); + ~TQBrush(); + TQBrush &operator=( const TQBrush & ); + + BrushStyle style() const { return data->style; } + void setStyle( BrushStyle ); + const TQColor &color()const { return data->color; } + void setColor( const TQColor & ); + TQPixmap *pixmap() const { return data->pixmap; } + void setPixmap( const TQPixmap & ); + + bool operator==( const TQBrush &p ) const; + bool operator!=( const TQBrush &b ) const + { return !(operator==(b)); } + +private: + TQBrush copy() const; + void detach(); + void init( const TQColor &, BrushStyle ); + struct TQBrushData : public TQShared { // brush data + BrushStyle style; + TQColor color; + TQPixmap *pixmap; + } *data; +}; + + +/***************************************************************************** + TQBrush stream functions + *****************************************************************************/ + +#ifndef TQT_NO_DATASTREAM +TQ_EXPORT TQDataStream &operator<<( TQDataStream &, const TQBrush & ); +TQ_EXPORT TQDataStream &operator>>( TQDataStream &, TQBrush & ); +#endif + +#endif // TQBRUSH_H diff --git a/src/kernel/tqcolor.cpp b/src/kernel/tqcolor.cpp new file mode 100644 index 000000000..59f726694 --- /dev/null +++ b/src/kernel/tqcolor.cpp @@ -0,0 +1,1030 @@ +/**************************************************************************** +** +** Implementation of TQColor class +** +** Created : 940112 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#include "tqcolor.h" +#include "ntqnamespace.h" +#include "tqdatastream.h" + +#include + + +/*! + \class TQColor tqcolor.h + \brief The TQColor class provides colors based on RGB or HSV values. + + \ingroup images + \ingroup graphics + \ingroup appearance + + A color is normally specified in terms of RGB (red, green and blue) + components, but it is also possible to specify HSV (hue, saturation + and value) or set a color name (the names are copied from from the + X11 color database). + + In addition to the RGB value, a TQColor also has a pixel value and a + validity. The pixel value is used by the underlying window system + to refer to a color. It can be thought of as an index into the + display hardware's color table. + + The validity (isValid()) indicates whether the color is legal at + all. For example, a RGB color with RGB values out of range is + illegal. For performance reasons, TQColor mostly disregards illegal + colors. The result of using an invalid color is unspecified and + will usually be surprising. + + There are 19 predefined TQColor objects: \c white, \c black, \c + red, \c darkRed, \c green, \c darkGreen, \c blue, \c darkBlue, \c + cyan, \c darkCyan, \c magenta, \c darkMagenta, \c yellow, \c + darkYellow, \c gray, \c darkGray, \c lightGray, \c color0 and \c + color1, accessible as members of the TQt namespace (ie. \c TQt::red). + + \img qt-colors.png TQt Colors + + The colors \c color0 (zero pixel value) and \c color1 (non-zero + pixel value) are special colors for drawing in \link TQBitmap + bitmaps\endlink. Painting with \c color0 sets the bitmap bits to 0 + (transparent, i.e. background), and painting with \c color1 sets the + bits to 1 (opaque, i.e. foreground). + + The TQColor class has an efficient, dynamic color allocation + strategy. A color is normally allocated the first time it is used + (lazy allocation), that is, whenever the pixel() function is called. + The following steps are taken to allocate a color. If, at any point, + a suitable color is found then the appropriate pixel value is + returned and the subsequent steps are not taken: + + \list 1 + \i Is the pixel value valid? If it is, just return it; otherwise, + allocate a pixel value. + \i Check an internal hash table to see if we allocated an equal RGB + value earlier. If we did, set the corresponding pixel value for the + color and return it. + \i Try to allocate the RGB value. If we succeed, we get a pixel value + that we save in the internal table with the RGB value. + Return the pixel value. + \i The color could not be allocated. Find the closest matching + color, save it in the internal table, and return it. + \endlist + + A color can be set by passing setNamedColor() an RGB string like + "#112233", or a color name, e.g. "blue". The names are taken from + X11's rgb.txt database but can also be used under Windows. To get + a lighter or darker color use light() and dark() respectively. + Colors can also be set using setRgb() and setHsv(). The color + components can be accessed in one go with rgb() and hsv(), or + individually with red(), green() and blue(). + + Use maxColors() and numBitPlanes() to determine the maximum number + of colors and the number of bit planes supported by the underlying + window system, + + If you need to allocate many colors temporarily, for example in an + image viewer application, enterAllocContext(), leaveAllocContext() and + destroyAllocContext() will prove useful. + + \section1 HSV Colors + + Because many people don't know the HSV color model very well, we'll + cover it briefly here. + + The RGB model is hardware-oriented. Its representation is close to + what most monitors show. In contrast, HSV represents color in a way + more suited to the human perception of color. For example, the + relationships "stronger than", "darker than" and "the opposite of" + are easily expressed in HSV but are much harder to express in RGB. + + HSV, like RGB, has three components: + + \list + + \i H, for hue, is either 0-359 if the color is chromatic (not + gray), or meaningless if it is gray. It represents degrees on the + color wheel familiar to most people. Red is 0 (degrees), green is + 120 and blue is 240. + + \i S, for saturation, is 0-255, and the bigger it is, the + stronger the color is. Grayish colors have saturation near 0; very + strong colors have saturation near 255. + + \i V, for value, is 0-255 and represents lightness or brightness + of the color. 0 is black; 255 is as far from black as possible. + + \endlist + + Here are some examples: Pure red is H=0, S=255, V=255. A dark red, + moving slightly towards the magenta, could be H=350 (equivalent to + -10), S=255, V=180. A grayish light red could have H about 0 (say + 350-359 or 0-10), S about 50-100, and S=255. + + TQt returns a hue value of -1 for achromatic colors. If you pass a + too-big hue value, TQt forces it into range. Hue 360 or 720 is + treated as 0; hue 540 is treated as 180. + + \sa TQPalette, TQColorGroup, TQApplication::setColorSpec(), + \link http://www.poynton.com/ColorFAQ.html Color FAQ\endlink +*/ + +/***************************************************************************** + Global colors + *****************************************************************************/ + +#if defined(TQ_WS_WIN) +#define COLOR0_PIX 0x00ffffff +#define COLOR1_PIX 0 +#else +#define COLOR0_PIX 0 +#define COLOR1_PIX 1 +#endif + +#if (defined(Q_CC_GNU) && defined(Q_OS_WIN)) +// workaround - bug in mingw +static TQColor stdcol[19] = { + TQColor( 255, 255, 255 ), + TQColor( 0, 0, 0 ), + TQColor( 0, 0, 0 ), + TQColor( 255, 255, 255 ), + TQColor( 128, 128, 128 ), + TQColor( 160, 160, 164 ), + TQColor( 192, 192, 192 ), + TQColor( 255, 0, 0 ), + TQColor( 0, 255, 0 ), + TQColor( 0, 0, 255 ), + TQColor( 0, 255, 255 ), + TQColor( 255, 0, 255 ), + TQColor( 255, 255, 0 ), + TQColor( 128, 0, 0 ), + TQColor( 0, 128, 0 ), + TQColor( 0, 0, 128 ), + TQColor( 0, 128, 128 ), + TQColor( 128, 0, 128 ), + TQColor( 128, 128, 0 ) }; +#else + static TQColor stdcol[19]; +#endif + +const TQColor & TQt::color0 = stdcol[0]; +const TQColor & TQt::color1 = stdcol[1]; +const TQColor & TQt::black = stdcol[2]; +const TQColor & TQt::white = stdcol[3]; +const TQColor & TQt::darkGray = stdcol[4]; +const TQColor & TQt::gray = stdcol[5]; +const TQColor & TQt::lightGray = stdcol[6]; +const TQColor & TQt::red = stdcol[7]; +const TQColor & TQt::green = stdcol[8]; +const TQColor & TQt::blue = stdcol[9]; +const TQColor & TQt::cyan = stdcol[10]; +const TQColor & TQt::magenta = stdcol[11]; +const TQColor & TQt::yellow = stdcol[12]; +const TQColor & TQt::darkRed = stdcol[13]; +const TQColor & TQt::darkGreen = stdcol[14]; +const TQColor & TQt::darkBlue = stdcol[15]; +const TQColor & TQt::darkCyan = stdcol[16]; +const TQColor & TQt::darkMagenta = stdcol[17]; +const TQColor & TQt::darkYellow = stdcol[18]; + + +/***************************************************************************** + TQColor member functions + *****************************************************************************/ + +bool TQColor::color_init = FALSE; // color system not initialized +bool TQColor::globals_init = FALSE; // global color not initialized +TQColor::ColorModel TQColor::colormodel = d32; + + +TQColor* TQColor::globalColors() +{ + return stdcol; +} + + +/*! + Initializes the global colors. This function is called if a global + color variable is initialized before the constructors for our + global color objects are executed. Without this mechanism, + assigning a color might assign an uninitialized value. + + Example: + \code + TQColor myColor = red; // will initialize red etc. + + int main( int argc, char **argc ) + { + } + \endcode +*/ + +void TQColor::initGlobalColors() +{ + globals_init = TRUE; + + #ifdef TQ_WS_X11 + // HACK: we need a way to recognize color0 and color1 uniquely, so + // that we can use color0 and color1 with fixed pixel values on + // all screens + stdcol[ 0].d.argb = tqRgba(255, 255, 255, 1); + stdcol[ 1].d.argb = tqRgba( 0, 0, 0, 1); + #else + stdcol[ 0].d.argb = tqRgb(255,255,255); + stdcol[ 1].d.argb = 0; + #endif // TQ_WS_X11 + stdcol[ 0].setPixel( COLOR0_PIX ); + stdcol[ 1].setPixel( COLOR1_PIX ); + + // From the "The Palette Manager: How and Why" by Ron Gery, March 23, + // 1992, archived on MSDN: + // The Windows system palette is broken up into two sections, + // one with fixed colors and one with colors that can be changed + // by applications. The system palette predefines 20 entries; + // these colors are known as the static or reserved colors and + // consist of the 16 colors found in the Windows version 3.0 VGA + // driver and 4 additional colors chosen for their visual appeal. + // The DEFAULT_PALETTE stock object is, as the name implies, the + // default palette selected into a device context (DC) and consists + // of these static colors. Applications can set the remaining 236 + // colors using the Palette Manager. + // The 20 reserved entries have indices in [0,9] and [246,255]. We + // reuse 17 of them. + stdcol[ 2].setRgb( 0, 0, 0 ); // index 0 black + stdcol[ 3].setRgb( 255, 255, 255 ); // index 255 white + stdcol[ 4].setRgb( 128, 128, 128 ); // index 248 medium gray + stdcol[ 5].setRgb( 160, 160, 164 ); // index 247 light gray + stdcol[ 6].setRgb( 192, 192, 192 ); // index 7 light gray + stdcol[ 7].setRgb( 255, 0, 0 ); // index 249 red + stdcol[ 8].setRgb( 0, 255, 0 ); // index 250 green + stdcol[ 9].setRgb( 0, 0, 255 ); // index 252 blue + stdcol[10].setRgb( 0, 255, 255 ); // index 254 cyan + stdcol[11].setRgb( 255, 0, 255 ); // index 253 magenta + stdcol[12].setRgb( 255, 255, 0 ); // index 251 yellow + stdcol[13].setRgb( 128, 0, 0 ); // index 1 dark red + stdcol[14].setRgb( 0, 128, 0 ); // index 2 dark green + stdcol[15].setRgb( 0, 0, 128 ); // index 4 dark blue + stdcol[16].setRgb( 0, 128, 128 ); // index 6 dark cyan + stdcol[17].setRgb( 128, 0, 128 ); // index 5 dark magenta + stdcol[18].setRgb( 128, 128, 0 ); // index 3 dark yellow +} + +/*! + \enum TQColor::Spec + + The type of color specified, either RGB or HSV, e.g. in the + \c{TQColor::TQColor( x, y, z, colorSpec)} constructor. + + \value Rgb + \value Hsv +*/ + + +/*! + \fn TQColor::TQColor() + + Constructs an invalid color with the RGB value (0, 0, 0). An + invalid color is a color that is not properly set up for the + underlying window system. + + The alpha value of an invalid color is unspecified. + + \sa isValid() +*/ + + +/*! + \fn TQColor::TQColor( int r, int g, int b ) + + Constructs a color with the RGB value \a r, \a g, \a b, in the + same way as setRgb(). + + The color is left invalid if any or the arguments are illegal. + + \sa setRgb() +*/ + + +/*! + Constructs a color with the RGB value \a rgb and a custom pixel + value \a pixel. + + If \a pixel == 0xffffffff (the default), then the color uses the + RGB value in a standard way. If \a pixel is something else, then + the pixel value is set directly to \a pixel, skipping the normal + allocation procedure. +*/ + +TQColor::TQColor( TQRgb rgb, uint pixel ) +{ + if ( pixel == 0xffffffff ) { + setRgb( rgb ); + } else { + d.argb = rgb; + setPixel( pixel ); + } +} + +void TQColor::setPixel( uint pixel ) +{ + switch ( colormodel ) { + case d8: + d.d8.direct = TRUE; + d.d8.invalid = FALSE; + d.d8.dirty = FALSE; + d.d8.pix = pixel; + break; + case d32: + d.d32.pix = pixel; + break; + } +} + + +/*! + Constructs a color with the RGB or HSV value \a x, \a y, \a z. + + The arguments are an RGB value if \a colorSpec is TQColor::Rgb. \a + x (red), \a y (green), and \a z (blue). All of them must be in the + range 0-255. + + The arguments are an HSV value if \a colorSpec is TQColor::Hsv. \a + x (hue) must be -1 for achromatic colors and 0-359 for chromatic + colors; \a y (saturation) and \a z (value) must both be in the + range 0-255. + + \sa setRgb(), setHsv() +*/ + +TQColor::TQColor( int x, int y, int z, Spec colorSpec ) +{ + d.d32.argb = Invalid; + d.d32.pix = Dirt; + if ( colorSpec == Hsv ) + setHsv( x, y, z ); + else + setRgb( x, y, z ); +} + + +/*! + Constructs a named color in the same way as setNamedColor() using + name \a name. + + The color is left invalid if \a name cannot be parsed. + + \sa setNamedColor() +*/ + +TQColor::TQColor( const TQString& name ) +{ + setNamedColor( name ); +} + + +/*! + Constructs a named color in the same way as setNamedColor() using + name \a name. + + The color is left invalid if \a name cannot be parsed. + + \sa setNamedColor() +*/ + +TQColor::TQColor( const char *name ) +{ + setNamedColor( TQString(name) ); +} + + + +/*! + Constructs a color that is a copy of \a c. +*/ + +TQColor::TQColor( const TQColor &c ) +{ + if ( !globals_init ) + initGlobalColors(); + d.argb = c.d.argb; + d.d32.pix = c.d.d32.pix; +} + + +/*! + Assigns a copy of the color \a c and returns a reference to this + color. +*/ + +TQColor &TQColor::operator=( const TQColor &c ) +{ + if ( !globals_init ) + initGlobalColors(); + d.argb = c.d.argb; + d.d32.pix = c.d.d32.pix; + return *this; +} + + +/*! + \fn bool TQColor::isValid() const + + Returns FALSE if the color is invalid, i.e. it was constructed using the + default constructor; otherwise returns TRUE. +*/ + +/*! + \internal +*/ +bool TQColor::isDirty() const +{ + if ( colormodel == d8 ) { + return d.d8.dirty; + } else { + return d.d32.probablyDirty(); + } +} + +/*! + Returns the name of the color in the format "#RRGGBB", i.e. a "#" + character followed by three two-digit hexadecimal numbers. + + \sa setNamedColor() +*/ + +TQString TQColor::name() const +{ +#ifndef TQT_NO_SPRINTF + TQString s; + s.sprintf( "#%02x%02x%02x", red(), green(), blue() ); + return s; +#else + char s[20]; + sprintf( s, "#%02x%02x%02x", red(), green(), blue() ); + return TQString(s); +#endif +} + +static int hex2int( TQChar hexchar ) +{ + int v; + if ( hexchar.isDigit() ) + v = hexchar.digitValue(); + else if ( hexchar >= 'A' && hexchar <= 'F' ) + v = hexchar.cell() - 'A' + 10; + else if ( hexchar >= 'a' && hexchar <= 'f' ) + v = hexchar.cell() - 'a' + 10; + else + v = -1; + return v; +} + + +/*! + Sets the RGB value to \a name, which may be in one of these + formats: + \list + \i #RGB (each of R, G and B is a single hex digit) + \i #RRGGBB + \i #RRRGGGBBB + \i #RRRRGGGGBBBB + \i A name from the X color database (rgb.txt) (e.g. + "steelblue" or "gainsboro"). These color names also work + under Windows. + \endlist + + The color is invalid if \a name cannot be parsed. +*/ + +void TQColor::setNamedColor( const TQString &name ) +{ + if ( name.isEmpty() ) { + d.argb = 0; + if ( colormodel == d8 ) { + d.d8.invalid = TRUE; + } else { + d.d32.argb = Invalid; + } + } else if ( name[0] == '#' ) { + const TQChar *p = name.unicode()+1; + int len = name.length()-1; + int r, g, b; + if ( len == 12 ) { + r = (hex2int(p[0]) << 4) + hex2int(p[1]); + g = (hex2int(p[4]) << 4) + hex2int(p[5]); + b = (hex2int(p[8]) << 4) + hex2int(p[9]); + } else if ( len == 9 ) { + r = (hex2int(p[0]) << 4) + hex2int(p[1]); + g = (hex2int(p[3]) << 4) + hex2int(p[4]); + b = (hex2int(p[6]) << 4) + hex2int(p[7]); + } else if ( len == 6 ) { + r = (hex2int(p[0]) << 4) + hex2int(p[1]); + g = (hex2int(p[2]) << 4) + hex2int(p[3]); + b = (hex2int(p[4]) << 4) + hex2int(p[5]); + } else if ( len == 3 ) { + r = (hex2int(p[0]) << 4) + hex2int(p[0]); + g = (hex2int(p[1]) << 4) + hex2int(p[1]); + b = (hex2int(p[2]) << 4) + hex2int(p[2]); + } else { + r = g = b = -1; + } + if ( (uint)r > 255 || (uint)g > 255 || (uint)b > 255 ) { + d.d32.argb = Invalid; + d.d32.pix = Dirt; +#if defined(QT_CHECK_RANGE) + tqWarning( "TQColor::setNamedColor: could not parse color '%s'", + name.local8Bit().data() ); +#endif + } else { + setRgb( r, g, b ); + } + } else { + setSystemNamedColor( name ); + } +} + + +#undef max +#undef min + +/*! + \fn void TQColor::getHsv( int &h, int &s, int &v ) const + \obsolete +*/ + +/*! \fn void TQColor::getHsv( int *h, int *s, int *v ) const + + Returns the current RGB value as HSV. The contents of the \a h, \a + s and \a v pointers are set to the HSV values. If any of the three + pointers are null, the function does nothing. + + The hue (which \a h points to) is set to -1 if the color is + achromatic. + + \warning Colors are stored internally as RGB values, so getHSv() + may return slightly different values to those set by setHsv(). + + \sa setHsv(), rgb() +*/ + +/*! \obsolete Use getHsv() instead. + */ +void TQColor::hsv( int *h, int *s, int *v ) const +{ + if ( !h || !s || !v ) + return; + int r = tqRed(d.argb); + int g = tqGreen(d.argb); + int b = tqBlue(d.argb); + uint max = r; // maximum RGB component + int whatmax = 0; // r=>0, g=>1, b=>2 + if ( (uint)g > max ) { + max = g; + whatmax = 1; + } + if ( (uint)b > max ) { + max = b; + whatmax = 2; + } + uint min = r; // find minimum value + if ( (uint)g < min ) min = g; + if ( (uint)b < min ) min = b; + int delta = max-min; + *v = max; // calc value + *s = max ? (510*delta+max)/(2*max) : 0; + if ( *s == 0 ) { + *h = -1; // undefined hue + } else { + switch ( whatmax ) { + case 0: // red is max component + if ( g >= b ) + *h = (120*(g-b)+delta)/(2*delta); + else + *h = (120*(g-b+delta)+delta)/(2*delta) + 300; + break; + case 1: // green is max component + if ( b > r ) + *h = 120 + (120*(b-r)+delta)/(2*delta); + else + *h = 60 + (120*(b-r+delta)+delta)/(2*delta); + break; + case 2: // blue is max component + if ( r > g ) + *h = 240 + (120*(r-g)+delta)/(2*delta); + else + *h = 180 + (120*(r-g+delta)+delta)/(2*delta); + break; + } + } +} + + +/*! + Sets a HSV color value. \a h is the hue, \a s is the saturation + and \a v is the value of the HSV color. + + If \a s or \a v are not in the range 0-255, or \a h is < -1, the + color is not changed. + + \warning Colors are stored internally as RGB values, so getHSv() + may return slightly different values to those set by setHsv(). + + \sa hsv(), setRgb() +*/ + +void TQColor::setHsv( int h, int s, int v ) +{ + if ( h < -1 || (uint)s > 255 || (uint)v > 255 ) { +#if defined(QT_CHECK_RANGE) + tqWarning( "TQColor::setHsv: HSV parameters out of range" ); +#endif + return; + } + int r=v, g=v, b=v; + if ( s == 0 || h == -1 ) { // achromatic case + // Ignore + } else { // chromatic case + if ( (uint)h >= 360 ) + h %= 360; + uint f = h%60; + h /= 60; + uint p = (uint)(2*v*(255-s)+255)/510; + uint q, t; + if ( h&1 ) { + q = (uint)(2*v*(15300-s*f)+15300)/30600; + switch( h ) { + case 1: r=(int)q; g=(int)v, b=(int)p; break; + case 3: r=(int)p; g=(int)q, b=(int)v; break; + case 5: r=(int)v; g=(int)p, b=(int)q; break; + } + } else { + t = (uint)(2*v*(15300-(s*(60-f)))+15300)/30600; + switch( h ) { + case 0: r=(int)v; g=(int)t, b=(int)p; break; + case 2: r=(int)p; g=(int)v, b=(int)t; break; + case 4: r=(int)t; g=(int)p, b=(int)v; break; + } + } + } + setRgb( r, g, b ); +} + + +/*! + \fn TQRgb TQColor::rgb() const + + Returns the RGB value. + + The return type \e TQRgb is equivalent to \c unsigned \c int. + + For an invalid color, the alpha value of the returned color is + unspecified. + + \sa setRgb(), hsv(), tqRed(), tqBlue(), tqGreen(), isValid() +*/ + +/*! \fn void TQColor::getRgb( int *r, int *g, int *b ) const + + Sets the contents pointed to by \a r, \a g and \a b to the red, + green and blue components of the RGB value respectively. The value + range for a component is 0..255. + + \sa rgb(), setRgb(), getHsv() +*/ + +/*! \obsolete Use getRgb() instead */ +void TQColor::rgb( int *r, int *g, int *b ) const +{ + *r = tqRed(d.argb); + *g = tqGreen(d.argb); + *b = tqBlue(d.argb); +} + + +/*! + Sets the RGB value to \a r, \a g, \a b. The arguments, \a r, \a g + and \a b must all be in the range 0..255. If any of them are + outside the legal range, the color is not changed. + + \sa rgb(), setHsv() +*/ + +void TQColor::setRgb( int r, int g, int b ) +{ + if ( (uint)r > 255 || (uint)g > 255 || (uint)b > 255 ) { +#if defined(QT_CHECK_RANGE) + tqWarning( "TQColor::setRgb: RGB parameter(s) out of range" ); +#endif + return; + } + d.argb = tqRgb( r, g, b ); + if ( colormodel == d8 ) { + d.d8.invalid = FALSE; + d.d8.direct = FALSE; + d.d8.dirty = TRUE; + } else { + d.d32.pix = Dirt; + } +} + + +/*! + \overload + Sets the RGB value to \a rgb. + + The type \e TQRgb is equivalent to \c unsigned \c int. + + \sa rgb(), setHsv() +*/ + +void TQColor::setRgb( TQRgb rgb ) +{ + d.argb = rgb; + if ( colormodel == d8 ) { + d.d8.invalid = FALSE; + d.d8.direct = FALSE; + d.d8.dirty = TRUE; + } else { + d.d32.pix = Dirt; + } +} + +/*! + \fn int TQColor::red() const + + Returns the R (red) component of the RGB value. +*/ + + +/*! + \fn int TQColor::green() const + + Returns the G (green) component of the RGB value. +*/ + +/*! + \fn int TQColor::blue() const + + Returns the B (blue) component of the RGB value. +*/ + + +/*! + Returns a lighter (or darker) color, but does not change this + object. + + Returns a lighter color if \a factor is greater than 100. Setting + \a factor to 150 returns a color that is 50% brighter. + + Returns a darker color if \a factor is less than 100. We recommend + using dark() for this purpose. If \a factor is 0 or negative, the + return value is unspecified. + + (This function converts the current RGB color to HSV, multiplies V + by \a factor, and converts the result back to RGB.) + + \sa dark() +*/ + +TQColor TQColor::light( int factor ) const +{ + if ( factor <= 0 ) // invalid lightness factor + return *this; + else if ( factor < 100 ) // makes color darker + return dark( 10000/factor ); + + int h, s, v; + hsv( &h, &s, &v ); + v = (factor*v)/100; + if ( v > 255 ) { // overflow + s -= v-255; // adjust saturation + if ( s < 0 ) + s = 0; + v = 255; + } + TQColor c; + c.setHsv( h, s, v ); + return c; +} + + +/*! + Returns a darker (or lighter) color, but does not change this + object. + + Returns a darker color if \a factor is greater than 100. Setting + \a factor to 300 returns a color that has one-third the + brightness. + + Returns a lighter color if \a factor is less than 100. We + recommend using lighter() for this purpose. If \a factor is 0 or + negative, the return value is unspecified. + + (This function converts the current RGB color to HSV, divides V by + \a factor and converts back to RGB.) + + \sa light() +*/ + +TQColor TQColor::dark( int factor ) const +{ + if ( factor <= 0 ) // invalid darkness factor + return *this; + else if ( factor < 100 ) // makes color lighter + return light( 10000/factor ); + int h, s, v; + hsv( &h, &s, &v ); + v = (v*100)/factor; + TQColor c; + c.setHsv( h, s, v ); + return c; +} + + +/*! + \fn bool TQColor::operator==( const TQColor &c ) const + + Returns TRUE if this color has the same RGB value as \a c; + otherwise returns FALSE. +*/ + +/*! + \fn bool TQColor::operator!=( const TQColor &c ) const + Returns TRUE if this color has a different RGB value from \a c; + otherwise returns FALSE. +*/ + +/*! + Returns the pixel value. + + This value is used by the underlying window system to refer to a + color. It can be thought of as an index into the display + hardware's color table, but the value is an arbitrary 32-bit + value. + + \sa alloc() +*/ +uint TQColor::pixel() const +{ + if ( isDirty() ) + return ((TQColor*)this)->alloc(); + else if ( colormodel == d8 ) +#ifdef TQ_WS_WIN + // since d.d8.pix is uchar we have to use the PALETTEINDEX + // macro to get the respective palette entry index. + return (0x01000000 | (int)(short)(d.d8.pix)); +#else + return d.d8.pix; +#endif + else + return d.d32.pix; +} + +/*! + \fn TQStringList TQColor::colorNames() + Returns a TQStringList containing the color names TQt knows about. +*/ + +/***************************************************************************** + TQColor stream functions + *****************************************************************************/ +#ifndef TQT_NO_DATASTREAM +/*! + \relates TQColor + Writes a color object, \a c to the stream, \a s. + + \sa \link datastreamformat.html Format of the TQDataStream operators \endlink +*/ + +TQDataStream &operator<<( TQDataStream &s, const TQColor &c ) +{ + TQ_UINT32 p = (TQ_UINT32)c.rgb(); + if ( s.version() == 1 ) // Swap red and blue + p = ((p << 16) & 0xff0000) | ((p >> 16) & 0xff) | (p & 0xff00ff00); + return s << p; +} + +/*! + \relates TQColor + Reads a color object, \a c, from the stream, \a s. + + \sa \link datastreamformat.html Format of the TQDataStream operators \endlink +*/ + +TQDataStream &operator>>( TQDataStream &s, TQColor &c ) +{ + TQ_UINT32 p; + s >> p; + if ( s.version() == 1 ) // Swap red and blue + p = ((p << 16) & 0xff0000) | ((p >> 16) & 0xff) | (p & 0xff00ff00); + c.setRgb( p ); + return s; +} +#endif + +/***************************************************************************** + TQColor global functions (documentation only) + *****************************************************************************/ + +/*! + \fn int tqRed( TQRgb rgb ) + \relates TQColor + + Returns the red component of the RGB triplet \a rgb. + \sa tqRgb(), TQColor::red() +*/ + +/*! + \fn int tqGreen( TQRgb rgb ) + \relates TQColor + + Returns the green component of the RGB triplet \a rgb. + \sa tqRgb(), TQColor::green() +*/ + +/*! + \fn int tqBlue( TQRgb rgb ) + \relates TQColor + + Returns the blue component of the RGB triplet \a rgb. + \sa tqRgb(), TQColor::blue() +*/ + +/*! + \fn int tqAlpha( TQRgb rgba ) + \relates TQColor + + Returns the alpha component of the RGBA quadruplet \a rgba. + */ + +/*! + \fn TQRgb tqRgb( int r, int g, int b ) + \relates TQColor + + Returns the RGB triplet \a (r,g,b). + + The return type TQRgb is equivalent to \c unsigned \c int. + + \sa tqRgba(), tqRed(), tqGreen(), tqBlue() +*/ + +/*! + \fn TQRgb tqRgba( int r, int g, int b, int a ) + \relates TQColor + + Returns the RGBA quadruplet \a (r,g,b,a). + + The return type TQRgba is equivalent to \c unsigned \c int. + + \sa tqRgb(), tqRed(), tqGreen(), tqBlue() +*/ + +/*! + \fn int tqGray( int r, int g, int b ) + \relates TQColor + + Returns a gray value 0..255 from the (\a r, \a g, \a b) triplet. + + The gray value is calculated using the formula (r*11 + g*16 + + b*5)/32. +*/ + +/*! + \overload int tqGray( tqRgb rgb ) + \relates TQColor + + Returns a gray value 0..255 from the given \a rgb colour. +*/ + diff --git a/src/kernel/tqcolor.h b/src/kernel/tqcolor.h new file mode 100644 index 000000000..0fca55097 --- /dev/null +++ b/src/kernel/tqcolor.h @@ -0,0 +1,229 @@ +/**************************************************************************** +** +** Definition of TQColor class +** +** Created : 940112 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef TQCOLOR_H +#define TQCOLOR_H + +#ifndef QT_H +#include "ntqwindowdefs.h" +#include "tqstringlist.h" +#endif // QT_H + +const TQRgb TQT_RGB_MASK = 0x00ffffff; // masks RGB values + +TQ_EXPORT inline int tqRed( TQRgb rgb ) // get red part of RGB +{ return (int)((rgb >> 16) & 0xff); } + +TQ_EXPORT inline int tqGreen( TQRgb rgb ) // get green part of RGB +{ return (int)((rgb >> 8) & 0xff); } + +TQ_EXPORT inline int tqBlue( TQRgb rgb ) // get blue part of RGB +{ return (int)(rgb & 0xff); } + +TQ_EXPORT inline int tqAlpha( TQRgb rgb ) // get alpha part of RGBA +{ return (int)((rgb >> 24) & 0xff); } + +TQ_EXPORT inline TQRgb tqRgb( int r, int g, int b )// set RGB value +{ return (0xff << 24) | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff); } + +TQ_EXPORT inline TQRgb tqRgba( int r, int g, int b, int a )// set RGBA value +{ return ((a & 0xff) << 24) | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff); } + +TQ_EXPORT inline int tqGray( int r, int g, int b )// convert R,G,B to gray 0..255 +{ return (r*11+g*16+b*5)/32; } + +TQ_EXPORT inline int tqGray( TQRgb rgb ) // convert RGB to gray 0..255 +{ return tqGray( tqRed(rgb), tqGreen(rgb), tqBlue(rgb) ); } + + +class TQ_EXPORT TQColor +{ +public: + enum Spec { Rgb, Hsv }; + + TQColor(); + TQColor( int r, int g, int b ); + TQColor( int x, int y, int z, Spec ); + TQColor( TQRgb rgb, uint pixel=0xffffffff); + TQColor( const TQString& name ); + TQColor( const char *name ); + TQColor( const TQColor & ); + TQColor &operator=( const TQColor & ); + + bool isValid() const; + bool isDirty() const; + TQString name() const; + void setNamedColor( const TQString& name ); + + TQRgb rgb() const; + void setRgb( int r, int g, int b ); + void setRgb( TQRgb rgb ); + void getRgb( int *r, int *g, int *b ) const { rgb( r, g, b ); } + void rgb( int *r, int *g, int *b ) const; // obsolete + + int red() const; + int green() const; + int blue() const; + + void setHsv( int h, int s, int v ); + void getHsv( int *h, int *s, int *v ) const { hsv( h, s, v ); } + void hsv( int *h, int *s, int *v ) const; // obsolete + void getHsv( int &h, int &s, int &v ) const { hsv( &h, &s, &v ); } // obsolete + + TQColor light( int f = 150 ) const; + TQColor dark( int f = 200 ) const; + + bool operator==( const TQColor &c ) const; + bool operator!=( const TQColor &c ) const; + + uint alloc(); + uint pixel() const; + +#if defined(TQ_WS_X11) + // ### in 4.0, make this take a default argument of -1 for default screen? + uint alloc( int screen ); + uint pixel( int screen ) const; +#endif + + static int maxColors(); + static int numBitPlanes(); + + static int enterAllocContext(); + static void leaveAllocContext(); + static int currentAllocContext(); + static void destroyAllocContext( int ); + +#if defined(TQ_WS_WIN) + static const TQRgb* palette( int* numEntries = 0 ); + static int setPaletteEntries( const TQRgb* entries, int numEntries, + int base = -1 ); + static HPALETTE hPal() { return hpal; } + static uint realizePal( TQWidget * ); +#endif + + static void initialize(); + static void cleanup(); +#ifndef TQT_NO_STRINGLIST + static TQStringList colorNames(); +#endif + enum { Dirt = 0x44495254, Invalid = 0x49000000 }; + +private: + void setSystemNamedColor( const TQString& name ); + void setPixel( uint pixel ); + static void initGlobalColors(); + static uint argbToPix32(TQRgb); + static TQColor* globalColors(); + static bool color_init; + static bool globals_init; +#if defined(TQ_WS_WIN) + static HPALETTE hpal; +#endif + static enum ColorModel { d8, d32 } colormodel; + union { + TQRgb argb; + struct D8 { + TQRgb argb; + uchar pix; + uchar invalid; + uchar dirty; + uchar direct; + } d8; + struct D32 { + TQRgb argb; + uint pix; + bool invalid() const { return argb == TQColor::Invalid && pix == TQColor::Dirt; } + bool probablyDirty() const { return pix == TQColor::Dirt; } + } d32; + } d; +}; + + +inline TQColor::TQColor() +{ d.d32.argb = Invalid; d.d32.pix = Dirt; } + +inline TQColor::TQColor( int r, int g, int b ) +{ + d.d32.argb = Invalid; + d.d32.pix = Dirt; + setRgb( r, g, b ); +} + +inline TQRgb TQColor::rgb() const +{ return d.argb; } + +inline int TQColor::red() const +{ return tqRed(d.argb); } + +inline int TQColor::green() const +{ return tqGreen(d.argb); } + +inline int TQColor::blue() const +{ return tqBlue(d.argb); } + +inline bool TQColor::isValid() const +{ + if ( colormodel == d8 ) + return !d.d8.invalid; + else + return !d.d32.invalid(); +} + +inline bool TQColor::operator==( const TQColor &c ) const +{ + return d.argb == c.d.argb && isValid() == c.isValid(); +} + +inline bool TQColor::operator!=( const TQColor &c ) const +{ + return !operator==(c); +} + + +/***************************************************************************** + TQColor stream functions + *****************************************************************************/ + +#ifndef TQT_NO_DATASTREAM +TQ_EXPORT TQDataStream &operator<<( TQDataStream &, const TQColor & ); +TQ_EXPORT TQDataStream &operator>>( TQDataStream &, TQColor & ); +#endif + +#endif // TQCOLOR_H diff --git a/src/kernel/tqcolor_p.cpp b/src/kernel/tqcolor_p.cpp new file mode 100644 index 000000000..0a91f5c90 --- /dev/null +++ b/src/kernel/tqcolor_p.cpp @@ -0,0 +1,797 @@ +/**************************************************************************** +** +** Named color support for non-X platforms. +** The color names have been borrowed from X. +** +** Created : 000228 +** +** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#include "ntqglobal.h" +#if defined(Q_CC_BOR) +// needed for qsort() because of a std namespace problem on Borland +#include "qplatformdefs.h" +#endif + +#include "tqcolor.h" + +#ifndef TQT_NO_COLORNAMES + +#include + +#undef TQRGB +#define TQRGB(r,g,b) (r*65536 + g*256 + b) + +const int rgbTblSize = 657; + +static const struct RGBData { + uint value; + const char *name; +} rgbTbl[] = { + { TQRGB(240,248,255), "aliceblue" }, + { TQRGB(250,235,215), "antiquewhite" }, + { TQRGB(255,239,219), "antiquewhite1" }, + { TQRGB(238,223,204), "antiquewhite2" }, + { TQRGB(205,192,176), "antiquewhite3" }, + { TQRGB(139,131,120), "antiquewhite4" }, + { TQRGB(127,255,212), "aquamarine" }, + { TQRGB(127,255,212), "aquamarine1" }, + { TQRGB(118,238,198), "aquamarine2" }, + { TQRGB(102,205,170), "aquamarine3" }, + { TQRGB( 69,139,116), "aquamarine4" }, + { TQRGB(240,255,255), "azure" }, + { TQRGB(240,255,255), "azure1" }, + { TQRGB(224,238,238), "azure2" }, + { TQRGB(193,205,205), "azure3" }, + { TQRGB(131,139,139), "azure4" }, + { TQRGB(245,245,220), "beige" }, + { TQRGB(255,228,196), "bisque" }, + { TQRGB(255,228,196), "bisque1" }, + { TQRGB(238,213,183), "bisque2" }, + { TQRGB(205,183,158), "bisque3" }, + { TQRGB(139,125,107), "bisque4" }, + { TQRGB( 0, 0, 0), "black" }, + { TQRGB(255,235,205), "blanchedalmond" }, + { TQRGB( 0, 0,255), "blue" }, + { TQRGB( 0, 0,255), "blue1" }, + { TQRGB( 0, 0,238), "blue2" }, + { TQRGB( 0, 0,205), "blue3" }, + { TQRGB( 0, 0,139), "blue4" }, + { TQRGB(138, 43,226), "blueviolet" }, + { TQRGB(165, 42, 42), "brown" }, + { TQRGB(255, 64, 64), "brown1" }, + { TQRGB(238, 59, 59), "brown2" }, + { TQRGB(205, 51, 51), "brown3" }, + { TQRGB(139, 35, 35), "brown4" }, + { TQRGB(222,184,135), "burlywood" }, + { TQRGB(255,211,155), "burlywood1" }, + { TQRGB(238,197,145), "burlywood2" }, + { TQRGB(205,170,125), "burlywood3" }, + { TQRGB(139,115, 85), "burlywood4" }, + { TQRGB( 95,158,160), "cadetblue" }, + { TQRGB(152,245,255), "cadetblue1" }, + { TQRGB(142,229,238), "cadetblue2" }, + { TQRGB(122,197,205), "cadetblue3" }, + { TQRGB( 83,134,139), "cadetblue4" }, + { TQRGB(127,255, 0), "chartreuse" }, + { TQRGB(127,255, 0), "chartreuse1" }, + { TQRGB(118,238, 0), "chartreuse2" }, + { TQRGB(102,205, 0), "chartreuse3" }, + { TQRGB( 69,139, 0), "chartreuse4" }, + { TQRGB(210,105, 30), "chocolate" }, + { TQRGB(255,127, 36), "chocolate1" }, + { TQRGB(238,118, 33), "chocolate2" }, + { TQRGB(205,102, 29), "chocolate3" }, + { TQRGB(139, 69, 19), "chocolate4" }, + { TQRGB(255,127, 80), "coral" }, + { TQRGB(255,114, 86), "coral1" }, + { TQRGB(238,106, 80), "coral2" }, + { TQRGB(205, 91, 69), "coral3" }, + { TQRGB(139, 62, 47), "coral4" }, + { TQRGB(100,149,237), "cornflowerblue" }, + { TQRGB(255,248,220), "cornsilk" }, + { TQRGB(255,248,220), "cornsilk1" }, + { TQRGB(238,232,205), "cornsilk2" }, + { TQRGB(205,200,177), "cornsilk3" }, + { TQRGB(139,136,120), "cornsilk4" }, + { TQRGB( 0,255,255), "cyan" }, + { TQRGB( 0,255,255), "cyan1" }, + { TQRGB( 0,238,238), "cyan2" }, + { TQRGB( 0,205,205), "cyan3" }, + { TQRGB( 0,139,139), "cyan4" }, + { TQRGB( 0, 0,139), "darkblue" }, + { TQRGB( 0,139,139), "darkcyan" }, + { TQRGB(184,134, 11), "darkgoldenrod" }, + { TQRGB(255,185, 15), "darkgoldenrod1" }, + { TQRGB(238,173, 14), "darkgoldenrod2" }, + { TQRGB(205,149, 12), "darkgoldenrod3" }, + { TQRGB(139,101, 8), "darkgoldenrod4" }, + { TQRGB(169,169,169), "darkgray" }, + { TQRGB( 0,100, 0), "darkgreen" }, + { TQRGB(169,169,169), "darkgrey" }, + { TQRGB(189,183,107), "darkkhaki" }, + { TQRGB(139, 0,139), "darkmagenta" }, + { TQRGB( 85,107, 47), "darkolivegreen" }, + { TQRGB(202,255,112), "darkolivegreen1" }, + { TQRGB(188,238,104), "darkolivegreen2" }, + { TQRGB(162,205, 90), "darkolivegreen3" }, + { TQRGB(110,139, 61), "darkolivegreen4" }, + { TQRGB(255,140, 0), "darkorange" }, + { TQRGB(255,127, 0), "darkorange1" }, + { TQRGB(238,118, 0), "darkorange2" }, + { TQRGB(205,102, 0), "darkorange3" }, + { TQRGB(139, 69, 0), "darkorange4" }, + { TQRGB(153, 50,204), "darkorchid" }, + { TQRGB(191, 62,255), "darkorchid1" }, + { TQRGB(178, 58,238), "darkorchid2" }, + { TQRGB(154, 50,205), "darkorchid3" }, + { TQRGB(104, 34,139), "darkorchid4" }, + { TQRGB(139, 0, 0), "darkred" }, + { TQRGB(233,150,122), "darksalmon" }, + { TQRGB(143,188,143), "darkseagreen" }, + { TQRGB(193,255,193), "darkseagreen1" }, + { TQRGB(180,238,180), "darkseagreen2" }, + { TQRGB(155,205,155), "darkseagreen3" }, + { TQRGB(105,139,105), "darkseagreen4" }, + { TQRGB( 72, 61,139), "darkslateblue" }, + { TQRGB( 47, 79, 79), "darkslategray" }, + { TQRGB(151,255,255), "darkslategray1" }, + { TQRGB(141,238,238), "darkslategray2" }, + { TQRGB(121,205,205), "darkslategray3" }, + { TQRGB( 82,139,139), "darkslategray4" }, + { TQRGB( 47, 79, 79), "darkslategrey" }, + { TQRGB( 0,206,209), "darkturquoise" }, + { TQRGB(148, 0,211), "darkviolet" }, + { TQRGB(255, 20,147), "deeppink" }, + { TQRGB(255, 20,147), "deeppink1" }, + { TQRGB(238, 18,137), "deeppink2" }, + { TQRGB(205, 16,118), "deeppink3" }, + { TQRGB(139, 10, 80), "deeppink4" }, + { TQRGB( 0,191,255), "deepskyblue" }, + { TQRGB( 0,191,255), "deepskyblue1" }, + { TQRGB( 0,178,238), "deepskyblue2" }, + { TQRGB( 0,154,205), "deepskyblue3" }, + { TQRGB( 0,104,139), "deepskyblue4" }, + { TQRGB(105,105,105), "dimgray" }, + { TQRGB(105,105,105), "dimgrey" }, + { TQRGB( 30,144,255), "dodgerblue" }, + { TQRGB( 30,144,255), "dodgerblue1" }, + { TQRGB( 28,134,238), "dodgerblue2" }, + { TQRGB( 24,116,205), "dodgerblue3" }, + { TQRGB( 16, 78,139), "dodgerblue4" }, + { TQRGB(178, 34, 34), "firebrick" }, + { TQRGB(255, 48, 48), "firebrick1" }, + { TQRGB(238, 44, 44), "firebrick2" }, + { TQRGB(205, 38, 38), "firebrick3" }, + { TQRGB(139, 26, 26), "firebrick4" }, + { TQRGB(255,250,240), "floralwhite" }, + { TQRGB( 34,139, 34), "forestgreen" }, + { TQRGB(220,220,220), "gainsboro" }, + { TQRGB(248,248,255), "ghostwhite" }, + { TQRGB(255,215, 0), "gold" }, + { TQRGB(255,215, 0), "gold1" }, + { TQRGB(238,201, 0), "gold2" }, + { TQRGB(205,173, 0), "gold3" }, + { TQRGB(139,117, 0), "gold4" }, + { TQRGB(218,165, 32), "goldenrod" }, + { TQRGB(255,193, 37), "goldenrod1" }, + { TQRGB(238,180, 34), "goldenrod2" }, + { TQRGB(205,155, 29), "goldenrod3" }, + { TQRGB(139,105, 20), "goldenrod4" }, + { TQRGB(190,190,190), "gray" }, + { TQRGB( 0, 0, 0), "gray0" }, + { TQRGB( 3, 3, 3), "gray1" }, + { TQRGB( 26, 26, 26), "gray10" }, + { TQRGB(255,255,255), "gray100" }, + { TQRGB( 28, 28, 28), "gray11" }, + { TQRGB( 31, 31, 31), "gray12" }, + { TQRGB( 33, 33, 33), "gray13" }, + { TQRGB( 36, 36, 36), "gray14" }, + { TQRGB( 38, 38, 38), "gray15" }, + { TQRGB( 41, 41, 41), "gray16" }, + { TQRGB( 43, 43, 43), "gray17" }, + { TQRGB( 46, 46, 46), "gray18" }, + { TQRGB( 48, 48, 48), "gray19" }, + { TQRGB( 5, 5, 5), "gray2" }, + { TQRGB( 51, 51, 51), "gray20" }, + { TQRGB( 54, 54, 54), "gray21" }, + { TQRGB( 56, 56, 56), "gray22" }, + { TQRGB( 59, 59, 59), "gray23" }, + { TQRGB( 61, 61, 61), "gray24" }, + { TQRGB( 64, 64, 64), "gray25" }, + { TQRGB( 66, 66, 66), "gray26" }, + { TQRGB( 69, 69, 69), "gray27" }, + { TQRGB( 71, 71, 71), "gray28" }, + { TQRGB( 74, 74, 74), "gray29" }, + { TQRGB( 8, 8, 8), "gray3" }, + { TQRGB( 77, 77, 77), "gray30" }, + { TQRGB( 79, 79, 79), "gray31" }, + { TQRGB( 82, 82, 82), "gray32" }, + { TQRGB( 84, 84, 84), "gray33" }, + { TQRGB( 87, 87, 87), "gray34" }, + { TQRGB( 89, 89, 89), "gray35" }, + { TQRGB( 92, 92, 92), "gray36" }, + { TQRGB( 94, 94, 94), "gray37" }, + { TQRGB( 97, 97, 97), "gray38" }, + { TQRGB( 99, 99, 99), "gray39" }, + { TQRGB( 10, 10, 10), "gray4" }, + { TQRGB(102,102,102), "gray40" }, + { TQRGB(105,105,105), "gray41" }, + { TQRGB(107,107,107), "gray42" }, + { TQRGB(110,110,110), "gray43" }, + { TQRGB(112,112,112), "gray44" }, + { TQRGB(115,115,115), "gray45" }, + { TQRGB(117,117,117), "gray46" }, + { TQRGB(120,120,120), "gray47" }, + { TQRGB(122,122,122), "gray48" }, + { TQRGB(125,125,125), "gray49" }, + { TQRGB( 13, 13, 13), "gray5" }, + { TQRGB(127,127,127), "gray50" }, + { TQRGB(130,130,130), "gray51" }, + { TQRGB(133,133,133), "gray52" }, + { TQRGB(135,135,135), "gray53" }, + { TQRGB(138,138,138), "gray54" }, + { TQRGB(140,140,140), "gray55" }, + { TQRGB(143,143,143), "gray56" }, + { TQRGB(145,145,145), "gray57" }, + { TQRGB(148,148,148), "gray58" }, + { TQRGB(150,150,150), "gray59" }, + { TQRGB( 15, 15, 15), "gray6" }, + { TQRGB(153,153,153), "gray60" }, + { TQRGB(156,156,156), "gray61" }, + { TQRGB(158,158,158), "gray62" }, + { TQRGB(161,161,161), "gray63" }, + { TQRGB(163,163,163), "gray64" }, + { TQRGB(166,166,166), "gray65" }, + { TQRGB(168,168,168), "gray66" }, + { TQRGB(171,171,171), "gray67" }, + { TQRGB(173,173,173), "gray68" }, + { TQRGB(176,176,176), "gray69" }, + { TQRGB( 18, 18, 18), "gray7" }, + { TQRGB(179,179,179), "gray70" }, + { TQRGB(181,181,181), "gray71" }, + { TQRGB(184,184,184), "gray72" }, + { TQRGB(186,186,186), "gray73" }, + { TQRGB(189,189,189), "gray74" }, + { TQRGB(191,191,191), "gray75" }, + { TQRGB(194,194,194), "gray76" }, + { TQRGB(196,196,196), "gray77" }, + { TQRGB(199,199,199), "gray78" }, + { TQRGB(201,201,201), "gray79" }, + { TQRGB( 20, 20, 20), "gray8" }, + { TQRGB(204,204,204), "gray80" }, + { TQRGB(207,207,207), "gray81" }, + { TQRGB(209,209,209), "gray82" }, + { TQRGB(212,212,212), "gray83" }, + { TQRGB(214,214,214), "gray84" }, + { TQRGB(217,217,217), "gray85" }, + { TQRGB(219,219,219), "gray86" }, + { TQRGB(222,222,222), "gray87" }, + { TQRGB(224,224,224), "gray88" }, + { TQRGB(227,227,227), "gray89" }, + { TQRGB( 23, 23, 23), "gray9" }, + { TQRGB(229,229,229), "gray90" }, + { TQRGB(232,232,232), "gray91" }, + { TQRGB(235,235,235), "gray92" }, + { TQRGB(237,237,237), "gray93" }, + { TQRGB(240,240,240), "gray94" }, + { TQRGB(242,242,242), "gray95" }, + { TQRGB(245,245,245), "gray96" }, + { TQRGB(247,247,247), "gray97" }, + { TQRGB(250,250,250), "gray98" }, + { TQRGB(252,252,252), "gray99" }, + { TQRGB( 0,255, 0), "green" }, + { TQRGB( 0,255, 0), "green1" }, + { TQRGB( 0,238, 0), "green2" }, + { TQRGB( 0,205, 0), "green3" }, + { TQRGB( 0,139, 0), "green4" }, + { TQRGB(173,255, 47), "greenyellow" }, + { TQRGB(190,190,190), "grey" }, + { TQRGB( 0, 0, 0), "grey0" }, + { TQRGB( 3, 3, 3), "grey1" }, + { TQRGB( 26, 26, 26), "grey10" }, + { TQRGB(255,255,255), "grey100" }, + { TQRGB( 28, 28, 28), "grey11" }, + { TQRGB( 31, 31, 31), "grey12" }, + { TQRGB( 33, 33, 33), "grey13" }, + { TQRGB( 36, 36, 36), "grey14" }, + { TQRGB( 38, 38, 38), "grey15" }, + { TQRGB( 41, 41, 41), "grey16" }, + { TQRGB( 43, 43, 43), "grey17" }, + { TQRGB( 46, 46, 46), "grey18" }, + { TQRGB( 48, 48, 48), "grey19" }, + { TQRGB( 5, 5, 5), "grey2" }, + { TQRGB( 51, 51, 51), "grey20" }, + { TQRGB( 54, 54, 54), "grey21" }, + { TQRGB( 56, 56, 56), "grey22" }, + { TQRGB( 59, 59, 59), "grey23" }, + { TQRGB( 61, 61, 61), "grey24" }, + { TQRGB( 64, 64, 64), "grey25" }, + { TQRGB( 66, 66, 66), "grey26" }, + { TQRGB( 69, 69, 69), "grey27" }, + { TQRGB( 71, 71, 71), "grey28" }, + { TQRGB( 74, 74, 74), "grey29" }, + { TQRGB( 8, 8, 8), "grey3" }, + { TQRGB( 77, 77, 77), "grey30" }, + { TQRGB( 79, 79, 79), "grey31" }, + { TQRGB( 82, 82, 82), "grey32" }, + { TQRGB( 84, 84, 84), "grey33" }, + { TQRGB( 87, 87, 87), "grey34" }, + { TQRGB( 89, 89, 89), "grey35" }, + { TQRGB( 92, 92, 92), "grey36" }, + { TQRGB( 94, 94, 94), "grey37" }, + { TQRGB( 97, 97, 97), "grey38" }, + { TQRGB( 99, 99, 99), "grey39" }, + { TQRGB( 10, 10, 10), "grey4" }, + { TQRGB(102,102,102), "grey40" }, + { TQRGB(105,105,105), "grey41" }, + { TQRGB(107,107,107), "grey42" }, + { TQRGB(110,110,110), "grey43" }, + { TQRGB(112,112,112), "grey44" }, + { TQRGB(115,115,115), "grey45" }, + { TQRGB(117,117,117), "grey46" }, + { TQRGB(120,120,120), "grey47" }, + { TQRGB(122,122,122), "grey48" }, + { TQRGB(125,125,125), "grey49" }, + { TQRGB( 13, 13, 13), "grey5" }, + { TQRGB(127,127,127), "grey50" }, + { TQRGB(130,130,130), "grey51" }, + { TQRGB(133,133,133), "grey52" }, + { TQRGB(135,135,135), "grey53" }, + { TQRGB(138,138,138), "grey54" }, + { TQRGB(140,140,140), "grey55" }, + { TQRGB(143,143,143), "grey56" }, + { TQRGB(145,145,145), "grey57" }, + { TQRGB(148,148,148), "grey58" }, + { TQRGB(150,150,150), "grey59" }, + { TQRGB( 15, 15, 15), "grey6" }, + { TQRGB(153,153,153), "grey60" }, + { TQRGB(156,156,156), "grey61" }, + { TQRGB(158,158,158), "grey62" }, + { TQRGB(161,161,161), "grey63" }, + { TQRGB(163,163,163), "grey64" }, + { TQRGB(166,166,166), "grey65" }, + { TQRGB(168,168,168), "grey66" }, + { TQRGB(171,171,171), "grey67" }, + { TQRGB(173,173,173), "grey68" }, + { TQRGB(176,176,176), "grey69" }, + { TQRGB( 18, 18, 18), "grey7" }, + { TQRGB(179,179,179), "grey70" }, + { TQRGB(181,181,181), "grey71" }, + { TQRGB(184,184,184), "grey72" }, + { TQRGB(186,186,186), "grey73" }, + { TQRGB(189,189,189), "grey74" }, + { TQRGB(191,191,191), "grey75" }, + { TQRGB(194,194,194), "grey76" }, + { TQRGB(196,196,196), "grey77" }, + { TQRGB(199,199,199), "grey78" }, + { TQRGB(201,201,201), "grey79" }, + { TQRGB( 20, 20, 20), "grey8" }, + { TQRGB(204,204,204), "grey80" }, + { TQRGB(207,207,207), "grey81" }, + { TQRGB(209,209,209), "grey82" }, + { TQRGB(212,212,212), "grey83" }, + { TQRGB(214,214,214), "grey84" }, + { TQRGB(217,217,217), "grey85" }, + { TQRGB(219,219,219), "grey86" }, + { TQRGB(222,222,222), "grey87" }, + { TQRGB(224,224,224), "grey88" }, + { TQRGB(227,227,227), "grey89" }, + { TQRGB( 23, 23, 23), "grey9" }, + { TQRGB(229,229,229), "grey90" }, + { TQRGB(232,232,232), "grey91" }, + { TQRGB(235,235,235), "grey92" }, + { TQRGB(237,237,237), "grey93" }, + { TQRGB(240,240,240), "grey94" }, + { TQRGB(242,242,242), "grey95" }, + { TQRGB(245,245,245), "grey96" }, + { TQRGB(247,247,247), "grey97" }, + { TQRGB(250,250,250), "grey98" }, + { TQRGB(252,252,252), "grey99" }, + { TQRGB(240,255,240), "honeydew" }, + { TQRGB(240,255,240), "honeydew1" }, + { TQRGB(224,238,224), "honeydew2" }, + { TQRGB(193,205,193), "honeydew3" }, + { TQRGB(131,139,131), "honeydew4" }, + { TQRGB(255,105,180), "hotpink" }, + { TQRGB(255,110,180), "hotpink1" }, + { TQRGB(238,106,167), "hotpink2" }, + { TQRGB(205, 96,144), "hotpink3" }, + { TQRGB(139, 58, 98), "hotpink4" }, + { TQRGB(205, 92, 92), "indianred" }, + { TQRGB(255,106,106), "indianred1" }, + { TQRGB(238, 99, 99), "indianred2" }, + { TQRGB(205, 85, 85), "indianred3" }, + { TQRGB(139, 58, 58), "indianred4" }, + { TQRGB(255,255,240), "ivory" }, + { TQRGB(255,255,240), "ivory1" }, + { TQRGB(238,238,224), "ivory2" }, + { TQRGB(205,205,193), "ivory3" }, + { TQRGB(139,139,131), "ivory4" }, + { TQRGB(240,230,140), "khaki" }, + { TQRGB(255,246,143), "khaki1" }, + { TQRGB(238,230,133), "khaki2" }, + { TQRGB(205,198,115), "khaki3" }, + { TQRGB(139,134, 78), "khaki4" }, + { TQRGB(230,230,250), "lavender" }, + { TQRGB(255,240,245), "lavenderblush" }, + { TQRGB(255,240,245), "lavenderblush1" }, + { TQRGB(238,224,229), "lavenderblush2" }, + { TQRGB(205,193,197), "lavenderblush3" }, + { TQRGB(139,131,134), "lavenderblush4" }, + { TQRGB(124,252, 0), "lawngreen" }, + { TQRGB(255,250,205), "lemonchiffon" }, + { TQRGB(255,250,205), "lemonchiffon1" }, + { TQRGB(238,233,191), "lemonchiffon2" }, + { TQRGB(205,201,165), "lemonchiffon3" }, + { TQRGB(139,137,112), "lemonchiffon4" }, + { TQRGB(173,216,230), "lightblue" }, + { TQRGB(191,239,255), "lightblue1" }, + { TQRGB(178,223,238), "lightblue2" }, + { TQRGB(154,192,205), "lightblue3" }, + { TQRGB(104,131,139), "lightblue4" }, + { TQRGB(240,128,128), "lightcoral" }, + { TQRGB(224,255,255), "lightcyan" }, + { TQRGB(224,255,255), "lightcyan1" }, + { TQRGB(209,238,238), "lightcyan2" }, + { TQRGB(180,205,205), "lightcyan3" }, + { TQRGB(122,139,139), "lightcyan4" }, + { TQRGB(238,221,130), "lightgoldenrod" }, + { TQRGB(255,236,139), "lightgoldenrod1" }, + { TQRGB(238,220,130), "lightgoldenrod2" }, + { TQRGB(205,190,112), "lightgoldenrod3" }, + { TQRGB(139,129, 76), "lightgoldenrod4" }, + { TQRGB(250,250,210), "lightgoldenrodyellow" }, + { TQRGB(211,211,211), "lightgray" }, + { TQRGB(144,238,144), "lightgreen" }, + { TQRGB(211,211,211), "lightgrey" }, + { TQRGB(255,182,193), "lightpink" }, + { TQRGB(255,174,185), "lightpink1" }, + { TQRGB(238,162,173), "lightpink2" }, + { TQRGB(205,140,149), "lightpink3" }, + { TQRGB(139, 95,101), "lightpink4" }, + { TQRGB(255,160,122), "lightsalmon" }, + { TQRGB(255,160,122), "lightsalmon1" }, + { TQRGB(238,149,114), "lightsalmon2" }, + { TQRGB(205,129, 98), "lightsalmon3" }, + { TQRGB(139, 87, 66), "lightsalmon4" }, + { TQRGB( 32,178,170), "lightseagreen" }, + { TQRGB(135,206,250), "lightskyblue" }, + { TQRGB(176,226,255), "lightskyblue1" }, + { TQRGB(164,211,238), "lightskyblue2" }, + { TQRGB(141,182,205), "lightskyblue3" }, + { TQRGB( 96,123,139), "lightskyblue4" }, + { TQRGB(132,112,255), "lightslateblue" }, + { TQRGB(119,136,153), "lightslategray" }, + { TQRGB(119,136,153), "lightslategrey" }, + { TQRGB(176,196,222), "lightsteelblue" }, + { TQRGB(202,225,255), "lightsteelblue1" }, + { TQRGB(188,210,238), "lightsteelblue2" }, + { TQRGB(162,181,205), "lightsteelblue3" }, + { TQRGB(110,123,139), "lightsteelblue4" }, + { TQRGB(255,255,224), "lightyellow" }, + { TQRGB(255,255,224), "lightyellow1" }, + { TQRGB(238,238,209), "lightyellow2" }, + { TQRGB(205,205,180), "lightyellow3" }, + { TQRGB(139,139,122), "lightyellow4" }, + { TQRGB( 50,205, 50), "limegreen" }, + { TQRGB(250,240,230), "linen" }, + { TQRGB(255, 0,255), "magenta" }, + { TQRGB(255, 0,255), "magenta1" }, + { TQRGB(238, 0,238), "magenta2" }, + { TQRGB(205, 0,205), "magenta3" }, + { TQRGB(139, 0,139), "magenta4" }, + { TQRGB(176, 48, 96), "maroon" }, + { TQRGB(255, 52,179), "maroon1" }, + { TQRGB(238, 48,167), "maroon2" }, + { TQRGB(205, 41,144), "maroon3" }, + { TQRGB(139, 28, 98), "maroon4" }, + { TQRGB(102,205,170), "mediumaquamarine" }, + { TQRGB( 0, 0,205), "mediumblue" }, + { TQRGB(186, 85,211), "mediumorchid" }, + { TQRGB(224,102,255), "mediumorchid1" }, + { TQRGB(209, 95,238), "mediumorchid2" }, + { TQRGB(180, 82,205), "mediumorchid3" }, + { TQRGB(122, 55,139), "mediumorchid4" }, + { TQRGB(147,112,219), "mediumpurple" }, + { TQRGB(171,130,255), "mediumpurple1" }, + { TQRGB(159,121,238), "mediumpurple2" }, + { TQRGB(137,104,205), "mediumpurple3" }, + { TQRGB( 93, 71,139), "mediumpurple4" }, + { TQRGB( 60,179,113), "mediumseagreen" }, + { TQRGB(123,104,238), "mediumslateblue" }, + { TQRGB( 0,250,154), "mediumspringgreen" }, + { TQRGB( 72,209,204), "mediumturquoise" }, + { TQRGB(199, 21,133), "mediumvioletred" }, + { TQRGB( 25, 25,112), "midnightblue" }, + { TQRGB(245,255,250), "mintcream" }, + { TQRGB(255,228,225), "mistyrose" }, + { TQRGB(255,228,225), "mistyrose1" }, + { TQRGB(238,213,210), "mistyrose2" }, + { TQRGB(205,183,181), "mistyrose3" }, + { TQRGB(139,125,123), "mistyrose4" }, + { TQRGB(255,228,181), "moccasin" }, + { TQRGB(255,222,173), "navajowhite" }, + { TQRGB(255,222,173), "navajowhite1" }, + { TQRGB(238,207,161), "navajowhite2" }, + { TQRGB(205,179,139), "navajowhite3" }, + { TQRGB(139,121, 94), "navajowhite4" }, + { TQRGB( 0, 0,128), "navy" }, + { TQRGB( 0, 0,128), "navyblue" }, + { TQRGB(253,245,230), "oldlace" }, + { TQRGB(107,142, 35), "olivedrab" }, + { TQRGB(192,255, 62), "olivedrab1" }, + { TQRGB(179,238, 58), "olivedrab2" }, + { TQRGB(154,205, 50), "olivedrab3" }, + { TQRGB(105,139, 34), "olivedrab4" }, + { TQRGB(255,165, 0), "orange" }, + { TQRGB(255,165, 0), "orange1" }, + { TQRGB(238,154, 0), "orange2" }, + { TQRGB(205,133, 0), "orange3" }, + { TQRGB(139, 90, 0), "orange4" }, + { TQRGB(255, 69, 0), "orangered" }, + { TQRGB(255, 69, 0), "orangered1" }, + { TQRGB(238, 64, 0), "orangered2" }, + { TQRGB(205, 55, 0), "orangered3" }, + { TQRGB(139, 37, 0), "orangered4" }, + { TQRGB(218,112,214), "orchid" }, + { TQRGB(255,131,250), "orchid1" }, + { TQRGB(238,122,233), "orchid2" }, + { TQRGB(205,105,201), "orchid3" }, + { TQRGB(139, 71,137), "orchid4" }, + { TQRGB(238,232,170), "palegoldenrod" }, + { TQRGB(152,251,152), "palegreen" }, + { TQRGB(154,255,154), "palegreen1" }, + { TQRGB(144,238,144), "palegreen2" }, + { TQRGB(124,205,124), "palegreen3" }, + { TQRGB( 84,139, 84), "palegreen4" }, + { TQRGB(175,238,238), "paleturquoise" }, + { TQRGB(187,255,255), "paleturquoise1" }, + { TQRGB(174,238,238), "paleturquoise2" }, + { TQRGB(150,205,205), "paleturquoise3" }, + { TQRGB(102,139,139), "paleturquoise4" }, + { TQRGB(219,112,147), "palevioletred" }, + { TQRGB(255,130,171), "palevioletred1" }, + { TQRGB(238,121,159), "palevioletred2" }, + { TQRGB(205,104,137), "palevioletred3" }, + { TQRGB(139, 71, 93), "palevioletred4" }, + { TQRGB(255,239,213), "papayawhip" }, + { TQRGB(255,218,185), "peachpuff" }, + { TQRGB(255,218,185), "peachpuff1" }, + { TQRGB(238,203,173), "peachpuff2" }, + { TQRGB(205,175,149), "peachpuff3" }, + { TQRGB(139,119,101), "peachpuff4" }, + { TQRGB(205,133, 63), "peru" }, + { TQRGB(255,192,203), "pink" }, + { TQRGB(255,181,197), "pink1" }, + { TQRGB(238,169,184), "pink2" }, + { TQRGB(205,145,158), "pink3" }, + { TQRGB(139, 99,108), "pink4" }, + { TQRGB(221,160,221), "plum" }, + { TQRGB(255,187,255), "plum1" }, + { TQRGB(238,174,238), "plum2" }, + { TQRGB(205,150,205), "plum3" }, + { TQRGB(139,102,139), "plum4" }, + { TQRGB(176,224,230), "powderblue" }, + { TQRGB(160, 32,240), "purple" }, + { TQRGB(155, 48,255), "purple1" }, + { TQRGB(145, 44,238), "purple2" }, + { TQRGB(125, 38,205), "purple3" }, + { TQRGB( 85, 26,139), "purple4" }, + { TQRGB(255, 0, 0), "red" }, + { TQRGB(255, 0, 0), "red1" }, + { TQRGB(238, 0, 0), "red2" }, + { TQRGB(205, 0, 0), "red3" }, + { TQRGB(139, 0, 0), "red4" }, + { TQRGB(188,143,143), "rosybrown" }, + { TQRGB(255,193,193), "rosybrown1" }, + { TQRGB(238,180,180), "rosybrown2" }, + { TQRGB(205,155,155), "rosybrown3" }, + { TQRGB(139,105,105), "rosybrown4" }, + { TQRGB( 65,105,225), "royalblue" }, + { TQRGB( 72,118,255), "royalblue1" }, + { TQRGB( 67,110,238), "royalblue2" }, + { TQRGB( 58, 95,205), "royalblue3" }, + { TQRGB( 39, 64,139), "royalblue4" }, + { TQRGB(139, 69, 19), "saddlebrown" }, + { TQRGB(250,128,114), "salmon" }, + { TQRGB(255,140,105), "salmon1" }, + { TQRGB(238,130, 98), "salmon2" }, + { TQRGB(205,112, 84), "salmon3" }, + { TQRGB(139, 76, 57), "salmon4" }, + { TQRGB(244,164, 96), "sandybrown" }, + { TQRGB( 46,139, 87), "seagreen" }, + { TQRGB( 84,255,159), "seagreen1" }, + { TQRGB( 78,238,148), "seagreen2" }, + { TQRGB( 67,205,128), "seagreen3" }, + { TQRGB( 46,139, 87), "seagreen4" }, + { TQRGB(255,245,238), "seashell" }, + { TQRGB(255,245,238), "seashell1" }, + { TQRGB(238,229,222), "seashell2" }, + { TQRGB(205,197,191), "seashell3" }, + { TQRGB(139,134,130), "seashell4" }, + { TQRGB(160, 82, 45), "sienna" }, + { TQRGB(255,130, 71), "sienna1" }, + { TQRGB(238,121, 66), "sienna2" }, + { TQRGB(205,104, 57), "sienna3" }, + { TQRGB(139, 71, 38), "sienna4" }, + { TQRGB(135,206,235), "skyblue" }, + { TQRGB(135,206,255), "skyblue1" }, + { TQRGB(126,192,238), "skyblue2" }, + { TQRGB(108,166,205), "skyblue3" }, + { TQRGB( 74,112,139), "skyblue4" }, + { TQRGB(106, 90,205), "slateblue" }, + { TQRGB(131,111,255), "slateblue1" }, + { TQRGB(122,103,238), "slateblue2" }, + { TQRGB(105, 89,205), "slateblue3" }, + { TQRGB( 71, 60,139), "slateblue4" }, + { TQRGB(112,128,144), "slategray" }, + { TQRGB(198,226,255), "slategray1" }, + { TQRGB(185,211,238), "slategray2" }, + { TQRGB(159,182,205), "slategray3" }, + { TQRGB(108,123,139), "slategray4" }, + { TQRGB(112,128,144), "slategrey" }, + { TQRGB(255,250,250), "snow" }, + { TQRGB(255,250,250), "snow1" }, + { TQRGB(238,233,233), "snow2" }, + { TQRGB(205,201,201), "snow3" }, + { TQRGB(139,137,137), "snow4" }, + { TQRGB( 0,255,127), "springgreen" }, + { TQRGB( 0,255,127), "springgreen1" }, + { TQRGB( 0,238,118), "springgreen2" }, + { TQRGB( 0,205,102), "springgreen3" }, + { TQRGB( 0,139, 69), "springgreen4" }, + { TQRGB( 70,130,180), "steelblue" }, + { TQRGB( 99,184,255), "steelblue1" }, + { TQRGB( 92,172,238), "steelblue2" }, + { TQRGB( 79,148,205), "steelblue3" }, + { TQRGB( 54,100,139), "steelblue4" }, + { TQRGB(210,180,140), "tan" }, + { TQRGB(255,165, 79), "tan1" }, + { TQRGB(238,154, 73), "tan2" }, + { TQRGB(205,133, 63), "tan3" }, + { TQRGB(139, 90, 43), "tan4" }, + { TQRGB(216,191,216), "thistle" }, + { TQRGB(255,225,255), "thistle1" }, + { TQRGB(238,210,238), "thistle2" }, + { TQRGB(205,181,205), "thistle3" }, + { TQRGB(139,123,139), "thistle4" }, + { TQRGB(255, 99, 71), "tomato" }, + { TQRGB(255, 99, 71), "tomato1" }, + { TQRGB(238, 92, 66), "tomato2" }, + { TQRGB(205, 79, 57), "tomato3" }, + { TQRGB(139, 54, 38), "tomato4" }, + { TQRGB( 64,224,208), "turquoise" }, + { TQRGB( 0,245,255), "turquoise1" }, + { TQRGB( 0,229,238), "turquoise2" }, + { TQRGB( 0,197,205), "turquoise3" }, + { TQRGB( 0,134,139), "turquoise4" }, + { TQRGB(238,130,238), "violet" }, + { TQRGB(208, 32,144), "violetred" }, + { TQRGB(255, 62,150), "violetred1" }, + { TQRGB(238, 58,140), "violetred2" }, + { TQRGB(205, 50,120), "violetred3" }, + { TQRGB(139, 34, 82), "violetred4" }, + { TQRGB(245,222,179), "wheat" }, + { TQRGB(255,231,186), "wheat1" }, + { TQRGB(238,216,174), "wheat2" }, + { TQRGB(205,186,150), "wheat3" }, + { TQRGB(139,126,102), "wheat4" }, + { TQRGB(255,255,255), "white" }, + { TQRGB(245,245,245), "whitesmoke" }, + { TQRGB(255,255, 0), "yellow" }, + { TQRGB(255,255, 0), "yellow1" }, + { TQRGB(238,238, 0), "yellow2" }, + { TQRGB(205,205, 0), "yellow3" }, + { TQRGB(139,139, 0), "yellow4" }, + { TQRGB(154,205, 50), "yellowgreen" } }; + +#if defined(Q_C_CALLBACKS) +extern "C" { +#endif + +#ifdef Q_OS_TEMP +static int __cdecl rgb_cmp( const void *d1, const void *d2 ) +#else +static int rgb_cmp( const void *d1, const void *d2 ) +#endif +{ + return tqstricmp( ((RGBData *)d1)->name, ((RGBData *)d2)->name ); +} + +#if defined(Q_C_CALLBACKS) +} +#endif + +bool qt_get_named_rgb( const char *name, TQRgb* rgb ) +{ + TQ_LONG len = strlen(name)+1; + char *name_no_space = (char *)malloc(len); + for(TQ_LONG o=0,i=0; i < len; i++) { + if(name[i] != '\t' && name[i] != ' ') + name_no_space[o++] = name[i]; + } + + RGBData x; + x.name = name_no_space; + // Funtion bsearch() is supposed to be + // void *bsearch(const void *key, const void *base, ... + // So why (char*)? Are there broken bsearch() declarations out there? + RGBData *r = (RGBData*)bsearch((char*)&x, (char*)rgbTbl, rgbTblSize, + sizeof(RGBData), rgb_cmp); + free(name_no_space); + if ( r ) { + *rgb = r->value; + return TRUE; + } else { + return FALSE; + } +} + +uint qt_get_rgb_val( const char *name ) +{ + TQRgb r = 0; + qt_get_named_rgb(name,&r); + return r; +} +#ifndef TQT_NO_STRINGLIST +TQStringList TQColor::colorNames() +{ + int i = 0; + TQStringList lst; + for ( i = 0; i < rgbTblSize; i++ ) + lst << rgbTbl[i].name; + + return lst; +} +#endif +#else + +bool qt_get_named_rgb( const char *, TQRgb* ) +{ + return FALSE; +} + +uint qt_get_rgb_val( const char * ) +{ + return 0; +} +#ifndef TQT_NO_STRINGLIST +TQStringList TQColor::colorNames() +{ + return TQStringList(); +} +#endif +#endif // TQT_NO_COLORNAMES diff --git a/src/kernel/tqcolor_p.h b/src/kernel/tqcolor_p.h new file mode 100644 index 000000000..d85cbf362 --- /dev/null +++ b/src/kernel/tqcolor_p.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Named color support for non-X platforms. +** The color names have been borrowed from X. +** +** Created : 000228 +** +** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef TQCOLOR_P_H +#define TQCOLOR_P_H + + +// +// W A R N I N G +// ------------- +// +// This file is not part of the TQt API. It exists for the convenience +// of tqmenudata.cpp, tqmenubar.cpp, tqmenubar.cpp, tqpopupmenu.cpp, +// qmotifstyle.cpp and qwindowssstyle.cpp. This header file may change +// from version to version without notice, or even be removed. +// +// We mean it. +// +// + +#ifndef QT_H +#endif // QT_H + +extern uint qt_get_rgb_val( const char *name ); +extern bool qt_get_named_rgb( const char *, TQRgb* ); +extern void qt_reset_color_avail(); + +#endif diff --git a/src/kernel/tqcolor_x11.cpp b/src/kernel/tqcolor_x11.cpp new file mode 100644 index 000000000..f5cfc024a --- /dev/null +++ b/src/kernel/tqcolor_x11.cpp @@ -0,0 +1,841 @@ +/**************************************************************************** +** +** Implementation of TQColor class for X11 +** +** Created : 940112 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#include "tqcolor.h" +#include "tqcolor_p.h" +#include "string.h" +#include "tqpaintdevice.h" +#include "ntqapplication.h" +#include "qapplication_p.h" +#include "qt_x11_p.h" + +// NOT REVISED + +/***************************************************************************** + The color dictionary speeds up color allocation significantly for X11. + When there are no more colors, TQColor::alloc() will set the colors_avail + flag to FALSE and try to find the nearest color. + NOTE: From deep within the event loop, the colors_avail flag is reset to + TRUE (calls the function qt_reset_color_avail()), because some other + application might free its colors, thereby making them available for + this TQt application. + *****************************************************************************/ + +#include "tqintdict.h" + +struct TQColorData { + uint pix; // allocated pixel value + int context; // allocation context +}; + +typedef TQIntDict TQColorDict; +typedef TQIntDictIterator TQColorDictIt; +static int current_alloc_context = 0; // current color alloc context +static const uint col_std_dict = 419; +static const uint col_large_dict = 18397; + +class TQColorScreenData { +public: + TQColorScreenData() + { + colorDict = 0; + colors_avail = TRUE; + g_vis = 0; + g_carr = 0; + g_carr_fetch = TRUE; + g_cells = 0; + g_our_alloc = 0; + color_reduce = FALSE; + } + + TQColorDict *colorDict; // dict of allocated colors + bool colors_avail; // X colors available + bool g_truecolor; // truecolor visual + Visual *g_vis; // visual + XColor *g_carr; // color array + bool g_carr_fetch; // perform XQueryColors? + int g_cells; // number of entries in g_carr + bool *g_our_alloc; // our allocated colors + uint red_mask , green_mask , blue_mask; + int red_shift, green_shift, blue_shift; + bool color_reduce; + int col_div_r; + int col_div_g; + int col_div_b; +}; + +static int screencount = 0; +static TQColorScreenData **screendata = 0; // array of screendata pointers + + +/* + This function is called from the event loop. It resets the colors_avail + flag so that the application can retry to allocate read-only colors + that other applications may have deallocated lately. + + The g_our_alloc and g_carr are global arrays that optimize color + approximation when there are no more colors left to allocate. +*/ + +void qt_reset_color_avail() +{ + int i; + for ( i = 0; i < screencount; i++ ) { + screendata[i]->colors_avail = TRUE; + screendata[i]->g_carr_fetch = TRUE; // do XQueryColors if !colors_avail + } +} + + +/* + Finds the nearest color. +*/ + +static int find_nearest_color( int r, int g, int b, int* mindist_out, + TQColorScreenData *sd ) +{ + int mincol = -1; + int mindist = 200000; + int rx, gx, bx, dist; + XColor *xc = &sd->g_carr[0]; + for ( int i=0; ig_cells; i++ ) { + rx = r - (xc->red >> 8); + gx = g - (xc->green >> 8); + bx = b - (xc->blue>> 8); + dist = rx*rx + gx*gx + bx*bx; // calculate distance + if ( dist < mindist ) { // minimal? + mindist = dist; + mincol = i; + } + xc++; + } + *mindist_out = mindist; + return mincol; +} + + +/***************************************************************************** + TQColor misc internal functions + *****************************************************************************/ + +static int highest_bit( uint v ) +{ + int i; + uint b = (uint)1 << 31; // get pos of highest bit in v + for ( i=31; ((b & v) == 0) && i>=0; i-- ) + b >>= 1; + return i; +} + + +/***************************************************************************** + TQColor static member functions + *****************************************************************************/ + +/*! + Returns the maximum number of colors supported by the underlying + window system if the window system uses a palette. + + Otherwise returns -1. Use numBitPlanes() to calculate the available + colors in that case. +*/ + +int TQColor::maxColors() +{ + Visual *visual = (Visual *) TQPaintDevice::x11AppVisual(); + if (visual->c_class & 1) + return TQPaintDevice::x11AppCells(); + return -1; +} + +/*! + Returns the number of color bit planes for the underlying window + system. + + The returned value is equal to the default pixmap depth. + + \sa TQPixmap::defaultDepth() +*/ + +int TQColor::numBitPlanes() +{ + return TQPaintDevice::x11AppDepth(); +} + + +/*! + Internal initialization required for TQColor. + This function is called from the TQApplication constructor. + + \sa cleanup() +*/ + +void TQColor::initialize() +{ + static const int blackIdx = 2; + static const int whiteIdx = 3; + + if ( color_init ) // already initialized + return; + color_init = TRUE; + + Display *dpy = TQPaintDevice::x11AppDisplay(); + int spec = TQApplication::colorSpec(); + + screencount = ScreenCount( dpy ); + screendata = new TQColorScreenData*[ screencount ]; + + int scr; + for ( scr = 0; scr < screencount; ++scr ) { + screendata[scr] = new TQColorScreenData; + screendata[scr]->g_vis = (Visual *) TQPaintDevice::x11AppVisual( scr ); + screendata[scr]->g_truecolor = screendata[scr]->g_vis->c_class == TrueColor + || screendata[scr]->g_vis->c_class == DirectColor; + + int ncols = TQPaintDevice::x11AppCells( scr ); + + if ( screendata[scr]->g_truecolor ) { + if (scr == DefaultScreen(dpy)) + colormodel = d32; + } else { + if (scr == DefaultScreen(dpy)) + colormodel = d8; + + // Create the g_our_alloc array, which remembers which color pixels + // we allocated. + screendata[scr]->g_cells = TQMIN(ncols,256); + screendata[scr]->g_carr = new XColor[screendata[scr]->g_cells]; + TQ_CHECK_PTR( screendata[scr]->g_carr ); + memset( screendata[scr]->g_carr, 0, + screendata[scr]->g_cells*sizeof(XColor) ); + screendata[scr]->g_carr_fetch = TRUE; // run XQueryColors on demand + screendata[scr]->g_our_alloc = new bool[screendata[scr]->g_cells]; + TQ_CHECK_PTR( screendata[scr]->g_our_alloc ); + memset( screendata[scr]->g_our_alloc, FALSE, + screendata[scr]->g_cells*sizeof(bool) ); + XColor *xc = &screendata[scr]->g_carr[0]; + for ( int i=0; ig_cells; i++ ) { + xc->pixel = i; // g_carr[i] = color i + xc++; + } + } + + int dictsize; + if ( screendata[scr]->g_truecolor ) { // truecolor + dictsize = 1; // will not need color dict + screendata[scr]->red_mask = (uint)screendata[scr]->g_vis->red_mask; + screendata[scr]->green_mask = (uint)screendata[scr]->g_vis->green_mask; + screendata[scr]->blue_mask = (uint)screendata[scr]->g_vis->blue_mask; + screendata[scr]->red_shift = + highest_bit( screendata[scr]->red_mask ) - 7; + screendata[scr]->green_shift = + highest_bit( screendata[scr]->green_mask ) - 7; + screendata[scr]->blue_shift = + highest_bit( screendata[scr]->blue_mask ) - 7; + } else { + dictsize = col_std_dict; + } + screendata[scr]->colorDict = new TQColorDict(dictsize); // create dictionary + TQ_CHECK_PTR( screendata[scr]->colorDict ); + + if ( spec == (int)TQApplication::ManyColor ) { + screendata[scr]->color_reduce = TRUE; + + switch ( qt_ncols_option ) { + case 216: + // 6:6:6 + screendata[scr]->col_div_r = screendata[scr]->col_div_g = + screendata[scr]->col_div_b = (255/(6-1)); + break; + default: { + // 2:3:1 proportions, solved numerically + if ( qt_ncols_option > 255 ) qt_ncols_option = 255; + if ( qt_ncols_option < 1 ) qt_ncols_option = 1; + int nr = 2; + int ng = 2; + int nb = 2; + for (;;) { + if ( nb*2 < nr && (nb+1)*nr*ng < qt_ncols_option ) + nb++; + else if ( nr*3 < ng*2 && nb*(nr+1)*ng < qt_ncols_option ) + nr++; + else if ( nb*nr*(ng+1) < qt_ncols_option ) + ng++; + else break; + } + qt_ncols_option = nr*ng*nb; + screendata[scr]->col_div_r = (255/(nr-1)); + screendata[scr]->col_div_g = (255/(ng-1)); + screendata[scr]->col_div_b = (255/(nb-1)); + } + } + } + } + + scr = TQPaintDevice::x11AppScreen(); + + // Initialize global color objects + if ( TQPaintDevice::x11AppDefaultVisual(scr) && + TQPaintDevice::x11AppDefaultColormap(scr) ) { + globalColors()[blackIdx].setPixel((uint) BlackPixel(dpy, scr)); + globalColors()[whiteIdx].setPixel((uint) WhitePixel(dpy, scr)); + } else { + globalColors()[blackIdx].alloc(scr); + globalColors()[whiteIdx].alloc(scr); + } + +#if 0 /* 0 == allocate colors on demand */ + setLazyAlloc( FALSE ); // allocate global colors + ((TQColor*)(&darkGray))-> alloc(); + ((TQColor*)(&gray))-> alloc(); + ((TQColor*)(&lightGray))-> alloc(); + ((TQColor*)(&::red))-> alloc(); + ((TQColor*)(&::green))-> alloc(); + ((TQColor*)(&::blue))-> alloc(); + ((TQColor*)(&cyan))-> alloc(); + ((TQColor*)(&magenta))-> alloc(); + ((TQColor*)(&yellow))-> alloc(); + ((TQColor*)(&darkRed))-> alloc(); + ((TQColor*)(&darkGreen))-> alloc(); + ((TQColor*)(&darkBlue))-> alloc(); + ((TQColor*)(&darkCyan))-> alloc(); + ((TQColor*)(&darkMagenta))-> alloc(); + ((TQColor*)(&darkYellow))-> alloc(); + setLazyAlloc( TRUE ); +#endif +} + +/*! + Internal clean up required for TQColor. + This function is called from the TQApplication destructor. + + \sa initialize() +*/ + +void TQColor::cleanup() +{ + if ( !color_init ) + return; + color_init = FALSE; + int scr; + for ( scr = 0; scr < screencount; scr++ ) { + if ( screendata[scr]->g_carr ) { + delete [] screendata[scr]->g_carr; + screendata[scr]->g_carr = 0; + } + if ( screendata[scr]->g_our_alloc ) { + delete [] screendata[scr]->g_our_alloc; + screendata[scr]->g_our_alloc = 0; + } + if ( screendata[scr]->colorDict ) { + screendata[scr]->colorDict->setAutoDelete( TRUE ); + screendata[scr]->colorDict->clear(); + delete screendata[scr]->colorDict; + screendata[scr]->colorDict = 0; + } + delete screendata[scr]; + screendata[scr] = 0; + } + delete [] screendata; + screendata = 0; + screencount = 0; +} + + +/***************************************************************************** + TQColor member functions + *****************************************************************************/ + +/*! + \internal + Allocates the color on screen \a screen. Only used in X11. + + \sa alloc(), pixel() +*/ +uint TQColor::alloc( int screen ) +{ + Display *dpy = TQPaintDevice::x11AppDisplay(); + if ( screen < 0 ) + screen = TQPaintDevice::x11AppScreen(); + if ( !color_init ) + return dpy ? (uint)BlackPixel(dpy, screen) : 0; + int r = tqRed(d.argb); + int g = tqGreen(d.argb); + int b = tqBlue(d.argb); + uint pix = 0; + TQColorScreenData *sd = screendata[screen]; + if ( sd->g_truecolor ) { // truecolor: map to pixel + r = sd->red_shift > 0 ? r << sd->red_shift : r >> -sd->red_shift; + g = sd->green_shift > 0 ? g << sd->green_shift : g >> -sd->green_shift; + b = sd->blue_shift > 0 ? b << sd->blue_shift : b >> -sd->blue_shift; + pix = (b & sd->blue_mask) | (g & sd->green_mask) | (r & sd->red_mask) + | ~(sd->blue_mask | sd->green_mask | sd->red_mask); + if (TQPaintDevice::x11AppDepth(screen) == 32) { + int a = tqAlpha(d.argb); + pix = pix & 0x00ffffff; + pix = pix | (a << 24); + } + if ( screen == TQPaintDevice::x11AppScreen() ) { + d.d32.pix = pix; + } + return pix; + } + TQColorData *c = sd->colorDict->find( (long)(d.argb) ); + if ( c ) { // found color in dictionary + pix = c->pix; + if ( screen == TQPaintDevice::x11AppScreen() ) { + d.d8.invalid = FALSE; // color ok + d.d8.dirty = FALSE; + d.d8.pix = pix; // use same pixel value + if ( c->context != current_alloc_context ) { + c->context = 0; // convert to default context + sd->g_our_alloc[pix] = TRUE; // reuse without XAllocColor + } + } + return pix; + } + + XColor col; + col.red = r << 8; + col.green = g << 8; + col.blue = b << 8; + + bool try_again = FALSE; + bool try_alloc = !sd->color_reduce; + int try_count = 0; + + do { + // This loop is run until we manage to either allocate or + // find an approximate color, it stops after a few iterations. + + try_again = FALSE; + + if ( try_alloc && sd->colors_avail && + XAllocColor(dpy, TQPaintDevice::x11AppColormap( screen ),&col) ) { + // We could allocate the color + pix = (uint) col.pixel; + if ( screen == TQPaintDevice::x11AppScreen() ) { + d.d8.pix = pix; + d.d8.invalid = FALSE; + d.d8.dirty = FALSE; + sd->g_carr[d.d8.pix] = col; // update color array + if ( current_alloc_context == 0 ) + sd->g_our_alloc[d.d8.pix] = TRUE; // reuse without XAllocColor + } + } else { + // No available colors, or we did not want to allocate one + int i; + sd->colors_avail = FALSE; // no more available colors + if ( sd->g_carr_fetch ) { // refetch color array + sd->g_carr_fetch = FALSE; + XQueryColors( dpy, TQPaintDevice::x11AppColormap( screen ), sd->g_carr, + sd->g_cells ); + } + int mindist; + i = find_nearest_color( r, g, b, &mindist, sd ); + + if ( mindist != 0 && !try_alloc ) { + // Not an exact match with an existing color + int rr = ((r+sd->col_div_r/2)/sd->col_div_r)*sd->col_div_r; + int rg = ((g+sd->col_div_g/2)/sd->col_div_g)*sd->col_div_g; + int rb = ((b+sd->col_div_b/2)/sd->col_div_b)*sd->col_div_b; + int rx = rr - r; + int gx = rg - g; + int bx = rb - b; + int dist = rx*rx + gx*gx + bx*bx; // calculate distance + if ( dist < mindist ) { + // reduced color is closer - try to alloc it + r = rr; + g = rg; + b = rb; + col.red = r << 8; + col.green = g << 8; + col.blue = b << 8; + try_alloc = TRUE; + try_again = TRUE; + sd->colors_avail = TRUE; + continue; // Try alloc reduced color + } + } + + if ( i == -1 ) { // no nearest color?! + int unused, value; + hsv(&unused, &unused, &value); + if (value < 128) { // dark, use black + d.argb = tqRgb(0,0,0); + pix = (uint)BlackPixel( dpy, screen ); + if ( screen == TQPaintDevice::x11AppScreen() ) { + d.d8.invalid = FALSE; + d.d8.dirty = FALSE; + d.d8.pix = pix; + } + } else { // light, use white + d.argb = tqRgb(0xff,0xff,0xff); + pix = (uint)WhitePixel( dpy, screen ); + if ( screen == TQPaintDevice::x11AppScreen() ) { + d.d8.invalid = FALSE; + d.d8.dirty = FALSE; + d.d8.pix = pix; + } + } + return pix; + } + if ( sd->g_our_alloc[i] ) { // we've already allocated it + ; // i == g_carr[i].pixel + } else { + // Try to allocate existing color + col = sd->g_carr[i]; + if ( XAllocColor(dpy, TQPaintDevice::x11AppColormap( screen ), &col) ) { + i = (uint)col.pixel; + sd->g_carr[i] = col; // update color array + if ( screen == TQPaintDevice::x11AppScreen() ) { + if ( current_alloc_context == 0 ) + sd->g_our_alloc[i] = TRUE; // only in the default context + } + } else { + // Oops, it's gone again + try_count++; + try_again = TRUE; + sd->colors_avail = TRUE; + sd->g_carr_fetch = TRUE; + } + } + if ( !try_again ) { // got it + pix = (uint)sd->g_carr[i].pixel; + if ( screen == TQPaintDevice::x11AppScreen() ) { + d.d8.invalid = FALSE; + d.d8.dirty = FALSE; + d.d8.pix = pix; // allocated X11 color + } + } + } + + } while ( try_again && try_count < 2 ); + + if ( try_again ) { // no hope of allocating color + int unused, value; + hsv(&unused, &unused, &value); + if (value < 128) { // dark, use black + d.argb = tqRgb(0,0,0); + pix = (uint)BlackPixel( dpy, screen ); + if ( screen == TQPaintDevice::x11AppScreen() ) { + d.d8.invalid = FALSE; + d.d8.dirty = FALSE; + d.d8.pix = pix; + } + } else { // light, use white + d.argb = tqRgb(0xff,0xff,0xff); + pix = (uint)WhitePixel( dpy, screen ); + if ( screen == TQPaintDevice::x11AppScreen() ) { + d.d8.invalid = FALSE; + d.d8.dirty = FALSE; + d.d8.pix = pix; + } + } + return pix; + } + // All colors outside context 0 must go into the dictionary + bool many = sd->colorDict->count() >= sd->colorDict->size() * 8; + if ( many && sd->colorDict->size() == col_std_dict ) { + sd->colorDict->resize( col_large_dict ); + } + if ( !many || current_alloc_context != 0 ) { + c = new TQColorData; // insert into color dict + TQ_CHECK_PTR( c ); + c->pix = pix; + c->context = current_alloc_context; + sd->colorDict->insert( (long)d.argb, c ); // store color in dict + } + return pix; +} + +/*! + Allocates the RGB color and returns the pixel value. + + Allocating a color means to obtain a pixel value from the RGB + specification. The pixel value is an index into the global color + table, but should be considered an arbitrary platform-dependent value. + + The pixel() function calls alloc() if necessary, so in general you + don't need to call this function. + + \sa enterAllocContext() +*/ +// ### 4.0 - remove me? +uint TQColor::alloc() +{ + return alloc( -1 ); +} + +/*! + \overload + + Returns the pixel value for screen \a screen. + + This value is used by the underlying window system to refer to a color. + It can be thought of as an index into the display hardware's color table, + but the value is an arbitrary 32-bit value. + + \sa alloc() +*/ +uint TQColor::pixel( int screen ) const +{ + if (screen != TQPaintDevice::x11AppScreen() && + // don't allocate color0 or color1, they have fixed pixel + // values for all screens + d.argb != tqRgba(255, 255, 255, 1) && d.argb != tqRgba(0, 0, 0, 1)) + return ((TQColor*)this)->alloc( screen ); + return pixel(); +} + + +void TQColor::setSystemNamedColor( const TQString& name ) +{ + // setSystemNamedColor should look up rgb values from the built in + // color tables first (see tqcolor_p.cpp), and failing that, use + // the window system's interface for translating names to rgb values... + // we do this so that things like uic can load an XPM file with named colors + // and convert it to a png without having to use window system functions... + d.argb = qt_get_rgb_val( name.latin1() ); + TQRgb rgb; + if ( qt_get_named_rgb( name.latin1(), &rgb ) ) { + setRgb( tqRed(rgb), tqGreen(rgb), tqBlue(rgb) ); + if ( colormodel == d8 ) { + d.d8.invalid = FALSE; + d.d8.dirty = TRUE; + d.d8.pix = 0; + } else { + alloc(); + } + } else if ( !color_init ) { +#if defined(QT_CHECK_STATE) + tqWarning( "TQColor::setSystemNamedColor: Cannot perform this operation " + "because TQApplication does not exist" ); +#endif + // set color to invalid + *this = TQColor(); + } else { + XColor col, hw_col; + if ( XLookupColor(TQPaintDevice::x11AppDisplay(), + TQPaintDevice::x11AppColormap(), name.latin1(), + &col, &hw_col) ) { + setRgb( col.red>>8, col.green>>8, col.blue>>8 ); + } else { + // set color to invalid + *this = TQColor(); + } + } +} + + +#define MAX_CONTEXTS 16 +static int context_stack[MAX_CONTEXTS]; +static int context_ptr = 0; + +static void init_context_stack() +{ + static bool did_init = FALSE; + if ( !did_init ) { + did_init = TRUE; + context_stack[0] = current_alloc_context = 0; + } +} + + +/*! + Enters a color allocation context and returns a non-zero unique + identifier. + + Color allocation contexts are useful for programs that need to + allocate many colors and throw them away later, like image + viewers. The allocation context functions work for true color + displays as well as for colormap displays, except that + TQColor::destroyAllocContext() does nothing for true color. + + Example: + \code + TQPixmap loadPixmap( TQString fileName ) + { + static int alloc_context = 0; + if ( alloc_context ) + TQColor::destroyAllocContext( alloc_context ); + alloc_context = TQColor::enterAllocContext(); + TQPixmap pm( fileName ); + TQColor::leaveAllocContext(); + return pm; + } + \endcode + + The example code loads a pixmap from file. It frees up all colors + that were allocated the last time loadPixmap() was called. + + The initial/default context is 0. TQt keeps a list of colors + associated with their allocation contexts. You can call + destroyAllocContext() to get rid of all colors that were allocated + in a specific context. + + Calling enterAllocContext() enters an allocation context. The + allocation context lasts until you call leaveAllocContext(). + TQColor has an internal stack of allocation contexts. Each call to + enterAllocContex() must have a corresponding leaveAllocContext(). + + \code + // context 0 active + int c1 = TQColor::enterAllocContext(); // enter context c1 + // context c1 active + int c2 = TQColor::enterAllocContext(); // enter context c2 + // context c2 active + TQColor::leaveAllocContext(); // leave context c2 + // context c1 active + TQColor::leaveAllocContext(); // leave context c1 + // context 0 active + // Now, free all colors that were allocated in context c2 + TQColor::destroyAllocContext( c2 ); + \endcode + + You may also want to set the application's color specification. + See TQApplication::setColorSpec() for more information. + + \sa leaveAllocContext(), currentAllocContext(), destroyAllocContext(), + TQApplication::setColorSpec() +*/ + +int TQColor::enterAllocContext() +{ + static int context_seq_no = 0; + init_context_stack(); + if ( context_ptr+1 == MAX_CONTEXTS ) { +#if defined(QT_CHECK_STATE) + tqWarning( "TQColor::enterAllocContext: Context stack overflow" ); +#endif + return 0; + } + current_alloc_context = context_stack[++context_ptr] = ++context_seq_no; + return current_alloc_context; +} + + +/*! + Leaves a color allocation context. + + See enterAllocContext() for a detailed explanation. + + \sa enterAllocContext(), currentAllocContext() +*/ + +void TQColor::leaveAllocContext() +{ + init_context_stack(); + if ( context_ptr == 0 ) { +#if defined(QT_CHECK_STATE) + tqWarning( "TQColor::leaveAllocContext: Context stack underflow" ); +#endif + return; + } + current_alloc_context = context_stack[--context_ptr]; +} + + +/*! + Returns the current color allocation context. + + The default context is 0. + + \sa enterAllocContext(), leaveAllocContext() +*/ + +int TQColor::currentAllocContext() +{ + return current_alloc_context; +} + + +/*! + Destroys a color allocation context, \e context. + + This function deallocates all colors that were allocated in the + specified \a context. If \a context == -1, it frees up all colors + that the application has allocated. If \a context == -2, it frees + up all colors that the application has allocated, except those in + the default context. + + The function does nothing for true color displays. + + \sa enterAllocContext(), alloc() +*/ + +void TQColor::destroyAllocContext( int context ) +{ + init_context_stack(); + if ( !color_init ) + return; + + int screen; + for ( screen = 0; screen < screencount; ++screen ) { + if ( screendata[screen]->g_truecolor ) + continue; + + ulong pixels[256]; + bool freeing[256]; + memset( freeing, FALSE, screendata[screen]->g_cells*sizeof(bool) ); + TQColorData *d; + TQColorDictIt it( *screendata[screen]->colorDict ); + int i = 0; + uint rgbv; + while ( (d=it.current()) ) { + rgbv = (uint)it.currentKey(); + if ( (d->context || context==-1) && + (d->context == context || context < 0) ) { + if ( !screendata[screen]->g_our_alloc[d->pix] && !freeing[d->pix] ) { + // will free this color + pixels[i++] = d->pix; + freeing[d->pix] = TRUE; + } + // remove from dict + screendata[screen]->colorDict->remove( (long)rgbv ); + } + ++it; + } + if ( i ) + XFreeColors( TQPaintDevice::x11AppDisplay(), + TQPaintDevice::x11AppColormap( screen ), + pixels, i, 0 ); + } +} diff --git a/src/kernel/tqdragobject.h b/src/kernel/tqdragobject.h index af4a8a995..568e0cbd8 100644 --- a/src/kernel/tqdragobject.h +++ b/src/kernel/tqdragobject.h @@ -49,7 +49,7 @@ class TQImageDragData; #include "tqobject.h" #include "tqimage.h" #include "tqstrlist.h" -#include "ntqcolor.h" +#include "tqcolor.h" #endif // QT_H #ifndef TQT_NO_MIME diff --git a/src/kernel/tqfont.cpp b/src/kernel/tqfont.cpp new file mode 100644 index 000000000..1549b1836 --- /dev/null +++ b/src/kernel/tqfont.cpp @@ -0,0 +1,3313 @@ +/**************************************************************************** +** +** Implementation of TQFont, TQFontMetrics and TQFontInfo classes +** +** Created : 941207 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#define QT_FATAL_ASSERT + +#include "tqfont.h" +#include "tqfontdatabase.h" +#include "tqfontmetrics.h" +#include "tqfontinfo.h" +#include "tqpainter.h" +#include "tqdict.h" +#include "tqcache.h" +#include "tqdatastream.h" +#include "ntqapplication.h" +#include "ntqcleanuphandler.h" +#include "tqstringlist.h" +#ifdef TQ_WS_MAC +#include "tqpaintdevicemetrics.h" +#endif + +#include +#include "tqfontdata_p.h" +#include "tqfontengine_p.h" +#include "tqpainter_p.h" +#include "tqtextengine_p.h" + +// #define TQFONTCACHE_DEBUG +#ifdef TQFONTCACHE_DEBUG +# define FC_DEBUG tqDebug +#else +# define FC_DEBUG if (FALSE) tqDebug +#endif + + + + +bool TQFontDef::operator==( const TQFontDef &other ) const +{ + /* + TQFontDef comparison is more complicated than just simple + per-member comparisons. + + When comparing point/pixel sizes, either point or pixelsize + could be -1. in This case we have to compare the non negative + size value. + + This test will fail if the point-sizes differ by 1/2 point or + more or they do not round to the same value. We have to do this + since our API still uses 'int' point-sizes in the API, but store + deci-point-sizes internally. + + To compare the family members, we need to parse the font names + and compare the family/foundry strings separately. This allows + us to compare e.g. "Helvetica" and "Helvetica [Adobe]" with + positive results. + */ + if (pixelSize != -1 && other.pixelSize != -1) { + if (pixelSize != other.pixelSize) + return FALSE; + } else if (pointSize != -1 && other.pointSize != -1) { + if (pointSize != other.pointSize + && (TQABS(pointSize - other.pointSize) >= 5 + || tqRound(pointSize/10.) != tqRound(other.pointSize/10.))) + return FALSE; + } else { + return FALSE; + } + + if (!ignorePitch && !other.ignorePitch && fixedPitch != other.fixedPitch) + return FALSE; + + if (stretch != 0 && other.stretch != 0 && stretch != other.stretch) + return FALSE; + + TQString this_family, this_foundry, other_family, other_foundry; + TQFontDatabase::parseFontName(family, this_foundry, this_family); + TQFontDatabase::parseFontName(other.family, other_foundry, other_family); + + return ( styleHint == other.styleHint + && styleStrategy == other.styleStrategy + && weight == other.weight + && italic == other.italic + && this_family == other_family + && (this_foundry.isEmpty() + || other_foundry.isEmpty() + || this_foundry == other_foundry) +#ifdef TQ_WS_X11 + && addStyle == other.addStyle +#endif // TQ_WS_X11 + ); +} + + + + +TQFontPrivate::TQFontPrivate() + : engineData( 0 ), paintdevice( 0 ), + rawMode( FALSE ), underline( FALSE ), overline( FALSE ), strikeOut( FALSE ), + mask( 0 ) +{ +#ifdef TQ_WS_X11 + screen = TQPaintDevice::x11AppScreen(); +#else + screen = 0; +#endif // TQ_WS_X11 +} + +TQFontPrivate::TQFontPrivate( const TQFontPrivate &other ) + : TQShared(), request( other.request ), engineData( 0 ), + paintdevice( other.paintdevice ), screen( other.screen ), + rawMode( other.rawMode ), underline( other.underline ), overline( other.overline ), + strikeOut( other.strikeOut ), mask( other.mask ) +{ +} + +TQFontPrivate::~TQFontPrivate() +{ + if ( engineData ) + engineData->deref(); + engineData = 0; +} + +void TQFontPrivate::resolve( const TQFontPrivate *other ) +{ +#ifdef QT_CHECK_STATE + Q_ASSERT( other != 0 ); +#endif + + if ( ( mask & Complete ) == Complete ) return; + + // assign the unset-bits with the set-bits of the other font def + if ( ! ( mask & Family ) ) + request.family = other->request.family; + + if ( ! ( mask & Size ) ) { + request.pointSize = other->request.pointSize; + request.pixelSize = other->request.pixelSize; + } + + if ( ! ( mask & StyleHint ) ) + request.styleHint = other->request.styleHint; + + if ( ! ( mask & StyleStrategy ) ) + request.styleStrategy = other->request.styleStrategy; + + if ( ! ( mask & Weight ) ) + request.weight = other->request.weight; + + if ( ! ( mask & Italic ) ) + request.italic = other->request.italic; + + if ( ! ( mask & FixedPitch ) ) + request.fixedPitch = other->request.fixedPitch; + + if ( ! ( mask & Stretch ) ) + request.stretch = other->request.stretch; + + if ( ! ( mask & Underline ) ) + underline = other->underline; + + if ( ! ( mask & Overline ) ) + overline = other->overline; + + if ( ! ( mask & StrikeOut ) ) + strikeOut = other->strikeOut; +} + + + + +TQFontEngineData::TQFontEngineData() + : lineWidth( 1 ) +{ +#if defined(TQ_WS_X11) || defined(TQ_WS_WIN) + memset( engines, 0, TQFont::LastPrivateScript * sizeof( TQFontEngine * ) ); +#else + engine = 0; +#endif // TQ_WS_X11 || TQ_WS_WIN +#ifndef TQ_WS_MAC + memset( widthCache, 0, widthCacheSize*sizeof( uchar ) ); +#endif +} + +TQFontEngineData::~TQFontEngineData() +{ +#if defined(TQ_WS_X11) || defined(TQ_WS_WIN) + for ( int i = 0; i < TQFont::LastPrivateScript; i++ ) { + if ( engines[i] ) + engines[i]->deref(); + engines[i] = 0; + } +#else + if ( engine ) + engine->deref(); + engine = 0; +#endif // TQ_WS_X11 || TQ_WS_WIN +} + + + + +/*! + \class TQFont tqfont.h + \brief The TQFont class specifies a font used for drawing text. + + \ingroup graphics + \ingroup appearance + \ingroup shared + \mainclass + + When you create a TQFont object you specify various attributes that + you want the font to have. TQt will use the font with the specified + attributes, or if no matching font exists, TQt will use the closest + matching installed font. The attributes of the font that is + actually used are retrievable from a TQFontInfo object. If the + window system provides an exact match exactMatch() returns TRUE. + Use TQFontMetrics to get measurements, e.g. the pixel length of a + string using TQFontMetrics::width(). + + Use TQApplication::setFont() to set the application's default font. + + If a choosen X11 font does not include all the characters that + need to be displayed, TQFont will try to find the characters in the + nearest equivalent fonts. When a TQPainter draws a character from a + font the TQFont will report whether or not it has the character; if + it does not, TQPainter will draw an unfilled square. + + Create TQFonts like this: + \code + TQFont serifFont( "Times", 10, Bold ); + TQFont sansFont( "Helvetica [Cronyx]", 12 ); + \endcode + + The attributes set in the constructor can also be set later, e.g. + setFamily(), setPointSize(), setPointSizeFloat(), setWeight() and + setItalic(). The remaining attributes must be set after + contstruction, e.g. setBold(), setUnderline(), setOverline(), + setStrikeOut() and setFixedPitch(). TQFontInfo objects should be + created \e after the font's attributes have been set. A TQFontInfo + object will not change, even if you change the font's + attributes. The corresponding "get" functions, e.g. family(), + pointSize(), etc., return the values that were set, even though + the values used may differ. The actual values are available from a + TQFontInfo object. + + If the requested font family is unavailable you can influence the + \link #fontmatching font matching algorithm\endlink by choosing a + particular \l{TQFont::StyleHint} and \l{TQFont::StyleStrategy} with + setStyleHint(). The default family (corresponding to the current + style hint) is returned by defaultFamily(). + + The font-matching algorithm has a lastResortFamily() and + lastResortFont() in cases where a suitable match cannot be found. + You can provide substitutions for font family names using + insertSubstitution() and insertSubstitutions(). Substitutions can + be removed with removeSubstitution(). Use substitute() to retrieve + a family's first substitute, or the family name itself if it has + no substitutes. Use substitutes() to retrieve a list of a family's + substitutes (which may be empty). + + Every TQFont has a key() which you can use, for example, as the key + in a cache or dictionary. If you want to store a user's font + preferences you could use TQSettings, writing the font information + with toString() and reading it back with fromString(). The + operator<<() and operator>>() functions are also available, but + they work on a data stream. + + It is possible to set the height of characters shown on the screen + to a specified number of pixels with setPixelSize(); however using + setPointSize() has a similar effect and provides device + independence. + + Under the X Window System you can set a font using its system + specific name with setRawName(). + + Loading fonts can be expensive, especially on X11. TQFont contains + extensive optimizations to make the copying of TQFont objects fast, + and to cache the results of the slow window system functions it + depends upon. + + \target fontmatching + The font matching algorithm works as follows: + \list 1 + \i The specified font family is searched for. + \i If not found, the styleHint() is used to select a replacement + family. + \i Each replacement font family is searched for. + \i If none of these are found or there was no styleHint(), "helvetica" + will be searched for. + \i If "helvetica" isn't found TQt will try the lastResortFamily(). + \i If the lastResortFamily() isn't found TQt will try the + lastResortFont() which will always return a name of some kind. + \endlist + + Once a font is found, the remaining attributes are matched in order of + priority: + \list 1 + \i fixedPitch() + \i pointSize() (see below) + \i weight() + \i italic() + \endlist + + If you have a font which matches on family, even if none of the + other attributes match, this font will be chosen in preference to + a font which doesn't match on family but which does match on the + other attributes. This is because font family is the dominant + search criteria. + + The point size is defined to match if it is within 20% of the + requested point size. When several fonts match and are only + distinguished by point size, the font with the closest point size + to the one requested will be chosen. + + The actual family, font size, weight and other font attributes + used for drawing text will depend on what's available for the + chosen family under the window system. A TQFontInfo object can be + used to determine the actual values used for drawing the text. + + Examples: + + \code + TQFont f("Helvetica"); + \endcode + If you had both an Adobe and a Cronyx Helvetica, you might get + either. + + \code + TQFont f1( "Helvetica [Cronyx]" ); // TQt 3.x + TQFont f2( "Cronyx-Helvetica" ); // TQt 2.x compatibility + \endcode + You can specify the foundry you want in the family name. Both fonts, + f1 and f2, in the above example will be set to "Helvetica + [Cronyx]". + + To determine the attributes of the font actually used in the window + system, use a TQFontInfo object, e.g. + \code + TQFontInfo info( f1 ); + TQString family = info.family(); + \endcode + + To find out font metrics use a TQFontMetrics object, e.g. + \code + TQFontMetrics fm( f1 ); + int pixelWidth = fm.width( "How many pixels wide is this text?" ); + int pixelHeight = fm.height(); + \endcode + + For more general information on fonts, see the + \link http://www.nwalsh.com/comp.fonts/FAQ/ comp.fonts FAQ.\endlink + Information on encodings can be found from + \link http://czyborra.com/ Roman Czyborra's\endlink page. + + \sa TQFontMetrics TQFontInfo TQFontDatabase TQApplication::setFont() + TQWidget::setFont() TQPainter::setFont() TQFont::StyleHint + TQFont::Weight +*/ + +/*! + \enum TQFont::Script + + This enum represents \link unicode.html Unicode \endlink allocated + scripts. For exhaustive coverage see \link + http://www.amazon.com/exec/obidos/ASIN/0201616335/trolltech/t The + Unicode Standard Version 3.0 \endlink. The following scripts are + supported: + + Modern European alphabetic scripts (left to right): + + \value Latin consists of most alphabets based on the original Latin alphabet. + \value Greek covers ancient and modern Greek and Coptic. + \value Cyrillic covers the Slavic and non-Slavic languages using + cyrillic alphabets. + \value Armenian contains the Armenian alphabet used with the + Armenian language. + \value Georgian covers at least the language Georgian. + \value Runic covers the known constituents of the Runic alphabets used + by the early and medieval societies in the Germanic, + Scandinavian, and Anglo-Saxon areas. + \value Ogham is an alphabetical script used to write a very early + form of Irish. + \value SpacingModifiers are small signs indicating modifications + to the preceeding letter. + \value CombiningMarks consist of diacritical marks not specific to + a particular alphabet, diacritical marks used in + combination with mathematical and technical symbols, and + glyph encodings applied to multiple letterforms. + + Middle Eastern scripts (right to left): + + \value Hebrew is used for writing Hebrew, Yiddish, and some other languages. + \value Arabic covers the Arabic language as well as Persian, Urdu, + Kurdish and some others. + \value Syriac is used to write the active liturgical languages and + dialects of several Middle Eastern and Southeast Indian + communities. + \value Thaana is used to write the Maledivian Dhivehi language. + + South and Southeast Asian scripts (left to right with few historical exceptions): + + \value Devanagari covers classical Sanskrit and modern Hindi as + well as several other languages. + \value Bengali is a relative to Devanagari employed to write the + Bengali language used in West Bengal/India and Bangladesh + as well as several minority languages. + \value Gurmukhi is another Devanagari relative used to write Punjabi. + \value Gujarati is closely related to Devanagari and used to write + the Gujarati language of the Gujarat state in India. + \value Oriya is used to write the Oriya language of Orissa state/India. + \value Tamil is used to write the Tamil language of Tamil Nadu state/India, + Sri Lanka, Singapore and parts of Malaysia as well as some + minority languages. + \value Telugu is used to write the Telugu language of Andhra + Pradesh state/India and some minority languages. + \value Kannada is another South Indian script used to write the + Kannada language of Karnataka state/India and some minority + languages. + \value Malayalam is used to write the Malayalam language of Kerala + state/India. + \value Sinhala is used for Sri Lanka's majority language Sinhala + and is also employed to write Pali, Sanskrit, and Tamil. + \value Thai is used to write Thai and other Southeast Asian languages. + \value Lao is a language and script quite similar to Thai. + \value Tibetan is the script used to write Tibetan in several + countries like Tibet, the bordering Indian regions and + Nepal. It is also used in the Buddist philosophy and + liturgy of the Mongolian cultural area. + \value Myanmar is mainly used to write the Burmese language of + Myanmar (former Burma). + \value Khmer is the official language of Kampuchea. + + East Asian scripts (traditionally top-down, right to left, modern + often horizontal left to right): + + \value Han consists of the CJK (Chinese, Japanese, Korean) + idiographic characters. + \value Hiragana is a cursive syllabary used to indicate phonetics + and pronounciation of Japanese words. + \value Katakana is a non-cursive syllabic script used to write + Japanese words with visual emphasis and non-Japanese words + in a phonetical manner. + \value Hangul is a Korean script consisting of alphabetic components. + \value Bopomofo is a phonetic alphabet for Chinese (mainly Mandarin). + \value Yi (also called Cuan or Wei) is a syllabary used to write + the Yi language of Southwestern China, Myanmar, Laos, and Vietnam. + + Additional scripts that do not fit well into the script categories above: + + \value Ethiopic is a syllabary used by several Central East African languages. + \value Cherokee is a left-to-right syllabic script used to write + the Cherokee language. + \value CanadianAboriginal consists of the syllabics used by some + Canadian aboriginal societies. + \value Mongolian is the traditional (and recently reintroduced) + script used to write Mongolian. + + Symbols: + + \value CurrencySymbols contains currency symbols not encoded in other scripts. + \value LetterlikeSymbols consists of symbols derived from + ordinary letters of an alphabetical script. + \value NumberForms are provided for compatibility with other + existing character sets. + \value MathematicalOperators consists of encodings for operators, + relations and other symbols like arrows used in a mathematical context. + \value TechnicalSymbols contains representations for control + codes, the space symbol, APL symbols and other symbols + mainly used in the context of electronic data processing. + \value GeometricSymbols covers block elements and geometric shapes. + \value MiscellaneousSymbols consists of a heterogeneous collection + of symbols that do not fit any other Unicode character + block, e.g. Dingbats. + \value EnclosedAndSquare is provided for compatibility with some + East Asian standards. + \value Braille is an international writing system used by blind + people. This script encodes the 256 eight-dot patterns with + the 64 six-dot patterns as a subset. + + \value Tagalog + \value Hanunoo + \value Buhid + \value Tagbanwa + + \value KatakanaHalfWidth + + \value Limbu (Unicode 4.0) + \value TaiLe (Unicode 4.0) + + \value Unicode includes all the above scripts. +*/ + +/*! \internal + + Constructs a font for use on the paint device \a pd using the + specified font \a data. +*/ +TQFont::TQFont( TQFontPrivate *data, TQPaintDevice *pd ) +{ + d = new TQFontPrivate( *data ); + TQ_CHECK_PTR( d ); + d->paintdevice = pd; + + // now a single reference + d->count = 1; +} + +/*! \internal + Detaches the font object from common font data. +*/ +void TQFont::detach() +{ + if (d->count == 1) { + if ( d->engineData ) + d->engineData->deref(); + d->engineData = 0; + + return; + } + + TQFontPrivate *old_d = d; + d = new TQFontPrivate( *old_d ); + + /* + if this font is a copy of the application default font, set the + fontdef mask to zero to indicate that *nothing* has been + explicitly set by the programmer. + */ + const TQFont appfont = TQApplication::font(); + if ( old_d == appfont.d ) + d->mask = 0; + + if ( old_d->deref() ) + delete old_d; +} + +/*! + Constructs a font object that uses the application's default font. + + \sa TQApplication::setFont(), TQApplication::font() +*/ +TQFont::TQFont() +{ + const TQFont appfont = TQApplication::font(); + d = appfont.d; + d->ref(); +} + +/*! + Constructs a font object with the specified \a family, \a + pointSize, \a weight and \a italic settings. + + If \a pointSize is <= 0 it is set to 1. + + The \a family name may optionally also include a foundry name, + e.g. "Helvetica [Cronyx]". (The TQt 2.x syntax, i.e. + "Cronyx-Helvetica", is also supported.) If the \a family is + available from more than one foundry and the foundry isn't + specified, an arbitrary foundry is chosen. If the family isn't + available a family will be set using the \link #fontmatching font + matching\endlink algorithm. + + \sa Weight, setFamily(), setPointSize(), setWeight(), setItalic(), + setStyleHint() TQApplication::font() +*/ +TQFont::TQFont( const TQString &family, int pointSize, int weight, bool italic ) +{ + + d = new TQFontPrivate; + TQ_CHECK_PTR( d ); + + d->mask = TQFontPrivate::Family; + + if (pointSize <= 0) { + pointSize = 12; + } else { + d->mask |= TQFontPrivate::Size; + } + + if (weight < 0) { + weight = Normal; + } else { + d->mask |= TQFontPrivate::Weight | TQFontPrivate::Italic; + } + + d->request.family = family; + d->request.pointSize = pointSize * 10; + d->request.pixelSize = -1; + d->request.weight = weight; + d->request.italic = italic; +} + +/*! + Constructs a font that is a copy of \a font. +*/ +TQFont::TQFont( const TQFont &font ) +{ + d = font.d; + d->ref(); +} + +/*! + Destroys the font object and frees all allocated resources. +*/ +TQFont::~TQFont() +{ + if ( d->deref() ) + delete d; + d = 0; +} + +/*! + Assigns \a font to this font and returns a reference to it. +*/ +TQFont &TQFont::operator=( const TQFont &font ) +{ + if ( font.d != d ) { + if ( d->deref() ) + delete d; + d = font.d; + d->ref(); + } + + return *this; +} + +/*! + Returns the requested font family name, i.e. the name set in the + constructor or the last setFont() call. + + \sa setFamily() substitutes() substitute() +*/ +TQString TQFont::family() const +{ + return d->request.family; +} + +/*! + Sets the family name of the font. The name is case insensitive and + may include a foundry name. + + The \a family name may optionally also include a foundry name, + e.g. "Helvetica [Cronyx]". (The TQt 2.x syntax, i.e. + "Cronyx-Helvetica", is also supported.) If the \a family is + available from more than one foundry and the foundry isn't + specified, an arbitrary foundry is chosen. If the family isn't + available a family will be set using the \link #fontmatching font + matching\endlink algorithm. + + \sa family(), setStyleHint(), TQFontInfo +*/ +void TQFont::setFamily( const TQString &family ) +{ + detach(); + + d->request.family = family; +#if defined(TQ_WS_X11) + d->request.addStyle = TQString::null; +#endif // TQ_WS_X11 + + d->mask |= TQFontPrivate::Family; +} + +/*! + Returns the point size in 1/10ths of a point. + + The returned value will be -1 if the font size has been specified + in pixels. + + \sa pointSize() pointSizeFloat() + */ +int TQFont::deciPointSize() const +{ + return d->request.pointSize; +} + +/*! + Returns the point size of the font. Returns -1 if the font size + was specified in pixels. + + \sa setPointSize() deciPointSize() pointSizeFloat() +*/ +int TQFont::pointSize() const +{ + return d->request.pointSize == -1 ? -1 : (d->request.pointSize + 5) / 10; +} + +/*! + Sets the point size to \a pointSize. The point size must be + greater than zero. + + \sa pointSize() setPointSizeFloat() +*/ +void TQFont::setPointSize( int pointSize ) +{ + if ( pointSize <= 0 ) { + +#if defined(QT_CHECK_RANGE) + tqWarning( "TQFont::setPointSize: Point size <= 0 (%d)", pointSize ); +#endif + + return; + } + + detach(); + + d->request.pointSize = pointSize * 10; + d->request.pixelSize = -1; + + d->mask |= TQFontPrivate::Size; +} + +/*! + Sets the point size to \a pointSize. The point size must be + greater than zero. The requested precision may not be achieved on + all platforms. + + \sa pointSizeFloat() setPointSize() setPixelSize() +*/ +void TQFont::setPointSizeFloat( float pointSize ) +{ + if ( pointSize <= 0.0 ) { +#if defined(QT_CHECK_RANGE) + tqWarning( "TQFont::setPointSize: Point size <= 0 (%f)", pointSize ); +#endif + return; + } + + detach(); + + d->request.pointSize = tqRound(pointSize * 10.0); + d->request.pixelSize = -1; + + d->mask |= TQFontPrivate::Size; +} + +/*! + Returns the point size of the font. Returns -1 if the font size was + specified in pixels. + + \sa pointSize() setPointSizeFloat() pixelSize() TQFontInfo::pointSize() TQFontInfo::pixelSize() +*/ +float TQFont::pointSizeFloat() const +{ + return float( d->request.pointSize == -1 ? -10 : d->request.pointSize ) / 10.0; +} + +/*! + Sets the font size to \a pixelSize pixels. + + Using this function makes the font device dependent. Use + setPointSize() or setPointSizeFloat() to set the size of the font + in a device independent manner. + + \sa pixelSize() +*/ +void TQFont::setPixelSize( int pixelSize ) +{ + if ( pixelSize <= 0 ) { +#if defined(QT_CHECK_RANGE) + tqWarning( "TQFont::setPixelSize: Pixel size <= 0 (%d)", pixelSize ); +#endif + return; + } + + detach(); + + d->request.pixelSize = pixelSize; + d->request.pointSize = -1; + + d->mask |= TQFontPrivate::Size; +} + +/*! + Returns the pixel size of the font if it was set with + setPixelSize(). Returns -1 if the size was set with setPointSize() + or setPointSizeFloat(). + + \sa setPixelSize() pointSize() TQFontInfo::pointSize() TQFontInfo::pixelSize() +*/ +int TQFont::pixelSize() const +{ + return d->request.pixelSize; +} + +/*! \obsolete + + Sets the logical pixel height of font characters when shown on + the screen to \a pixelSize. +*/ +void TQFont::setPixelSizeFloat( float pixelSize ) +{ + setPixelSize( (int)pixelSize ); +} + +/*! + Returns TRUE if italic has been set; otherwise returns FALSE. + + \sa setItalic() +*/ +bool TQFont::italic() const +{ + return d->request.italic; +} + +/*! + If \a enable is TRUE, italic is set on; otherwise italic is set + off. + + \sa italic(), TQFontInfo +*/ +void TQFont::setItalic( bool enable ) +{ + detach(); + + d->request.italic = enable; + d->mask |= TQFontPrivate::Italic; +} + +/*! + Returns the weight of the font which is one of the enumerated + values from \l{TQFont::Weight}. + + \sa setWeight(), Weight, TQFontInfo +*/ +int TQFont::weight() const +{ + return d->request.weight; +} + +/*! + \enum TQFont::Weight + + TQt uses a weighting scale from 0 to 99 similar to, but not the + same as, the scales used in Windows or CSS. A weight of 0 is + ultralight, whilst 99 will be an extremely black. + + This enum contains the predefined font weights: + + \value Light 25 + \value Normal 50 + \value DemiBold 63 + \value Bold 75 + \value Black 87 +*/ + +/*! + Sets the weight the font to \a weight, which should be a value + from the \l TQFont::Weight enumeration. + + \sa weight(), TQFontInfo +*/ +void TQFont::setWeight( int weight ) +{ + if ( weight < 0 || weight > 99 ) { + +#if defined(QT_CHECK_RANGE) + tqWarning( "TQFont::setWeight: Value out of range (%d)", weight ); +#endif + + return; + } + + detach(); + + d->request.weight = weight; + d->mask |= TQFontPrivate::Weight; +} + +/*! + \fn bool TQFont::bold() const + + Returns TRUE if weight() is a value greater than \link Weight + TQFont::Normal \endlink; otherwise returns FALSE. + + \sa weight(), setBold(), TQFontInfo::bold() +*/ + +/*! + \fn void TQFont::setBold( bool enable ) + + If \a enable is true sets the font's weight to \link Weight + TQFont::Bold \endlink; otherwise sets the weight to \link Weight + TQFont::Normal\endlink. + + For finer boldness control use setWeight(). + + \sa bold(), setWeight() +*/ + +/*! + Returns TRUE if underline has been set; otherwise returns FALSE. + + \sa setUnderline() +*/ +bool TQFont::underline() const +{ + return d->underline; +} + +/*! + If \a enable is TRUE, sets underline on; otherwise sets underline + off. + + \sa underline(), TQFontInfo +*/ +void TQFont::setUnderline( bool enable ) +{ + detach(); + + d->underline = enable; + d->mask |= TQFontPrivate::Underline; +} + +/*! + Returns TRUE if overline has been set; otherwise returns FALSE. + + \sa setOverline() +*/ +bool TQFont::overline() const +{ + return d->overline; +} + +/*! + If \a enable is TRUE, sets overline on; otherwise sets overline off. + + \sa overline(), TQFontInfo +*/ +void TQFont::setOverline( bool enable ) +{ + detach(); + + d->overline = enable; + d->mask |= TQFontPrivate::Overline; +} + +/*! + Returns TRUE if strikeout has been set; otherwise returns FALSE. + + \sa setStrikeOut() +*/ +bool TQFont::strikeOut() const +{ + return d->strikeOut; +} + +/*! + If \a enable is TRUE, sets strikeout on; otherwise sets strikeout + off. + + \sa strikeOut(), TQFontInfo +*/ +void TQFont::setStrikeOut( bool enable ) +{ + detach(); + + d->strikeOut = enable; + d->mask |= TQFontPrivate::StrikeOut; +} + +/*! + Returns TRUE if fixed pitch has been set; otherwise returns FALSE. + + \sa setFixedPitch(), TQFontInfo::fixedPitch() +*/ +bool TQFont::fixedPitch() const +{ + return d->request.fixedPitch; +} + +/*! + If \a enable is TRUE, sets fixed pitch on; otherwise sets fixed + pitch off. + + \sa fixedPitch(), TQFontInfo +*/ +void TQFont::setFixedPitch( bool enable ) +{ + detach(); + + d->request.fixedPitch = enable; + d->request.ignorePitch = FALSE; + d->mask |= TQFontPrivate::FixedPitch; +} + +/*! + Returns the StyleStrategy. + + The style strategy affects the \link #fontmatching font + matching\endlink algorithm. See \l TQFont::StyleStrategy for the + list of strategies. + + \sa setStyleHint() TQFont::StyleHint +*/ +TQFont::StyleStrategy TQFont::styleStrategy() const +{ + return (StyleStrategy) d->request.styleStrategy; +} + +/*! + Returns the StyleHint. + + The style hint affects the \link #fontmatching font + matching\endlink algorithm. See \l TQFont::StyleHint for the list + of strategies. + + \sa setStyleHint(), TQFont::StyleStrategy TQFontInfo::styleHint() +*/ +TQFont::StyleHint TQFont::styleHint() const +{ + return (StyleHint) d->request.styleHint; +} + +/*! + \enum TQFont::StyleHint + + Style hints are used by the \link #fontmatching font + matching\endlink algorithm to find an appropriate default family + if a selected font family is not available. + + \value AnyStyle leaves the font matching algorithm to choose the + family. This is the default. + + \value SansSerif the font matcher prefer sans serif fonts. + \value Helvetica is a synonym for \c SansSerif. + + \value Serif the font matcher prefers serif fonts. + \value Times is a synonym for \c Serif. + + \value TypeWriter the font matcher prefers fixed pitch fonts. + \value Courier a synonym for \c TypeWriter. + + \value OldEnglish the font matcher prefers decorative fonts. + \value Decorative is a synonym for \c OldEnglish. + + \value System the font matcher prefers system fonts. +*/ + +/*! + \enum TQFont::StyleStrategy + + The style strategy tells the \link #fontmatching font + matching\endlink algorithm what type of fonts should be used to + find an appropriate default family. + + The following strategies are available: + + \value PreferDefault the default style strategy. It does not prefer + any type of font. + \value PreferBitmap prefers bitmap fonts (as opposed to outline + fonts). + \value PreferDevice prefers device fonts. + \value PreferOutline prefers outline fonts (as opposed to bitmap fonts). + \value ForceOutline forces the use of outline fonts. + \value NoAntialias don't antialias the fonts. + \value PreferAntialias antialias if possible. + \value OpenGLCompatible forces the use of OpenGL compatible + fonts. + + Any of these may be OR-ed with one of these flags: + + \value PreferMatch prefer an exact match. The font matcher will try to + use the exact font size that has been specified. + \value PreferQuality prefer the best quality font. The font matcher + will use the nearest standard point size that the font + supports. +*/ + +/*! + Sets the style hint and strategy to \a hint and \a strategy, + respectively. + + If these aren't set explicitly the style hint will default to + \c AnyStyle and the style strategy to \c PreferDefault. + + TQt does not support style hints on X11 since this information + is not provided by the window system. + + \sa StyleHint, styleHint(), StyleStrategy, styleStrategy(), TQFontInfo +*/ +void TQFont::setStyleHint( StyleHint hint, StyleStrategy strategy ) +{ + detach(); + + if ( ( d->mask & ( TQFontPrivate::StyleHint | TQFontPrivate::StyleStrategy ) ) && + (StyleHint) d->request.styleHint == hint && + (StyleStrategy) d->request.styleStrategy == strategy ) + return; + + d->request.styleHint = hint; + d->request.styleStrategy = strategy; + d->mask |= TQFontPrivate::StyleHint; + d->mask |= TQFontPrivate::StyleStrategy; + +#if defined(TQ_WS_X11) + d->request.addStyle = TQString::null; +#endif // TQ_WS_X11 +} + +/*! + Sets the style strategy for the font to \a s. + + \sa TQFont::StyleStrategy +*/ +void TQFont::setStyleStrategy( StyleStrategy s ) +{ + detach(); + + if ( ( d->mask & TQFontPrivate::StyleStrategy ) && + s == (StyleStrategy)d->request.styleStrategy ) + return; + + d->request.styleStrategy = s; + d->mask |= TQFontPrivate::StyleStrategy; +} + + +/*! + \enum TQFont::Stretch + + Predefined stretch values that follow the CSS naming convention. + + \value UltraCondensed 50 + \value ExtraCondensed 62 + \value Condensed 75 + \value SemiCondensed 87 + \value Unstretched 100 + \value SemiExpanded 112 + \value Expanded 125 + \value ExtraExpanded 150 + \value UltraExpanded 200 + + \sa setStretch() stretch() +*/ + +/*! + Returns the stretch factor for the font. + + \sa setStretch() + */ +int TQFont::stretch() const +{ + return d->request.stretch; +} + +/*! + Sets the stretch factor for the font. + + The stretch factor changes the width of all characters in the font + by \a factor percent. For example, setting \a factor to 150 + results in all characters in the font being 1.5 times ( ie. 150% ) + wider. The default stretch factor is 100. The minimum stretch + factor is 1, and the maximum stretch factor is 4000. + + The stretch factor is only applied to outline fonts. The stretch + factor is ignored for bitmap fonts. + + NOTE: TQFont cannot stretch XLFD fonts. When loading XLFD fonts on + X11, the stretch factor is matched against a predefined set of + values for the SETWIDTH_NAME field of the XLFD. + + \sa stretch() TQFont::StyleStrategy +*/ +void TQFont::setStretch( int factor ) +{ + if ( factor < 1 || factor > 4000 ) { +#ifdef QT_CHECK_RANGE + tqWarning( "TQFont::setStretch(): parameter '%d' out of range", factor ); +#endif // QT_CHECK_RANGE + + return; + } + + detach(); + + if ( ( d->mask & TQFontPrivate::Stretch ) && + d->request.stretch == (uint)factor ) + return; + + d->request.stretch = (uint)factor; + d->mask |= TQFontPrivate::Stretch; +} + +/*! + If \a enable is TRUE, turns raw mode on; otherwise turns raw mode + off. This function only has an effect under X11. + + If raw mode is enabled, TQt will search for an X font with a + complete font name matching the family name, ignoring all other + values set for the TQFont. If the font name matches several fonts, + TQt will use the first font returned by X. TQFontInfo \e cannot be + used to fetch information about a TQFont using raw mode (it will + return the values set in the TQFont for all parameters, including + the family name). + + \warning Do not use raw mode unless you really, really need it! In + most (if not all) cases, setRawName() is a much better choice. + + \sa rawMode(), setRawName() +*/ +void TQFont::setRawMode( bool enable ) +{ + detach(); + + if ( (bool) d->rawMode == enable ) return; + + d->rawMode = enable; +} + +/*! + Returns TRUE if a window system font exactly matching the settings + of this font is available. + + \sa TQFontInfo +*/ +bool TQFont::exactMatch() const +{ + TQFontEngine *engine = d->engineForScript( TQFont::NoScript ); +#ifdef QT_CHECK_STATE + Q_ASSERT( engine != 0 ); +#endif // QT_CHECK_STATE + + return d->rawMode ? engine->type() != TQFontEngine::Box + : d->request == engine->fontDef; +} + +/*! + Returns TRUE if this font is equal to \a f; otherwise returns + FALSE. + + Two TQFonts are considered equal if their font attributes are + equal. If rawMode() is enabled for both fonts, only the family + fields are compared. + + \sa operator!=() isCopyOf() +*/ +bool TQFont::operator==( const TQFont &f ) const +{ + return f.d == d || ( f.d->request == d->request && + f.d->underline == d->underline && + f.d->overline == d->overline && + f.d->strikeOut == d->strikeOut ); +} + +/*! + Returns TRUE if this font is different from \a f; otherwise + returns FALSE. + + Two TQFonts are considered to be different if their font attributes + are different. If rawMode() is enabled for both fonts, only the + family fields are compared. + + \sa operator==() +*/ +bool TQFont::operator!=( const TQFont &f ) const +{ + return !(operator==( f )); +} + +/*! + Returns TRUE if this font and \a f are copies of each other, i.e. + one of them was created as a copy of the other and neither has + been modified since. This is much stricter than equality. + + \sa operator=() operator==() +*/ +bool TQFont::isCopyOf( const TQFont & f ) const +{ + return d == f.d; +} + +/*! + Returns TRUE if raw mode is used for font name matching; otherwise + returns FALSE. + + \sa setRawMode() rawName() +*/ +bool TQFont::rawMode() const +{ + return d->rawMode; +} + +/*! + Returns a new TQFont that has attributes copied from \a other. +*/ +TQFont TQFont::resolve( const TQFont &other ) const +{ + if ( *this == other && d->mask == other.d->mask ) + return *this; + + TQFont font( *this ); + font.detach(); + + /* + if this font is a copy of the application default font, set the + fontdef mask to zero to indicate that *nothing* has been + explicitly set by the programmer. + */ + const TQFont appfont = TQApplication::font(); + if ( d == appfont.d ) + font.d->mask = 0; + + font.d->resolve( other.d ); + + return font; +} + +#ifndef TQT_NO_COMPAT + +/*! \obsolete + + Please use TQApplication::font() instead. +*/ +TQFont TQFont::defaultFont() +{ + return TQApplication::font(); +} + +/*! \obsolete + + Please use TQApplication::setFont() instead. +*/ +void TQFont::setDefaultFont( const TQFont &f ) +{ + TQApplication::setFont( f ); +} + + +#endif + + + + +#ifndef TQT_NO_STRINGLIST + +/***************************************************************************** + TQFont substitution management + *****************************************************************************/ + +typedef TQDict TQFontSubst; +static TQFontSubst *fontSubst = 0; +static TQSingleCleanupHandler tqfont_cleanup_fontsubst; + + +// create substitution dict +static void initFontSubst() +{ + // default substitutions + static const char *initTbl[] = { + +#if defined(TQ_WS_X11) + "arial", "helvetica", + "helv", "helvetica", + "tms rmn", "times", +#elif defined(TQ_WS_WIN) + "times", "Times New Roman", + "courier", "Courier New", + "helvetica", "Arial", +#endif + + 0, 0 + }; + + if (fontSubst) + return; + + fontSubst = new TQFontSubst(17, FALSE); + TQ_CHECK_PTR( fontSubst ); + fontSubst->setAutoDelete( TRUE ); + tqfont_cleanup_fontsubst.set(&fontSubst); + + for ( int i=0; initTbl[i] != 0; i += 2 ) + TQFont::insertSubstitution(TQString::fromLatin1(initTbl[i]), + TQString::fromLatin1(initTbl[i+1])); +} + + +/*! + Returns the first family name to be used whenever \a familyName is + specified. The lookup is case insensitive. + + If there is no substitution for \a familyName, \a familyName is + returned. + + To obtain a list of substitutions use substitutes(). + + \sa setFamily() insertSubstitutions() insertSubstitution() removeSubstitution() +*/ +TQString TQFont::substitute( const TQString &familyName ) +{ + initFontSubst(); + + TQStringList *list = fontSubst->find(familyName); + if (list && list->count() > 0) + return *(list->at(0)); + + return familyName; +} + + +/*! + Returns a list of family names to be used whenever \a familyName + is specified. The lookup is case insensitive. + + If there is no substitution for \a familyName, an empty list is + returned. + + \sa substitute() insertSubstitutions() insertSubstitution() removeSubstitution() + */ +TQStringList TQFont::substitutes(const TQString &familyName) +{ + initFontSubst(); + + TQStringList ret, *list = fontSubst->find(familyName); + if (list) + ret += *list; + return ret; +} + + +/*! + Inserts the family name \a substituteName into the substitution + table for \a familyName. + + \sa insertSubstitutions() removeSubstitution() substitutions() substitute() substitutes() +*/ +void TQFont::insertSubstitution(const TQString &familyName, + const TQString &substituteName) +{ + initFontSubst(); + + TQStringList *list = fontSubst->find(familyName); + if (! list) { + list = new TQStringList; + fontSubst->insert(familyName, list); + } + + if (! list->contains(substituteName)) + list->append(substituteName); +} + + +/*! + Inserts the list of families \a substituteNames into the + substitution list for \a familyName. + + \sa insertSubstitution(), removeSubstitution(), substitutions(), substitute() +*/ +void TQFont::insertSubstitutions(const TQString &familyName, + const TQStringList &substituteNames) +{ + initFontSubst(); + + TQStringList *list = fontSubst->find(familyName); + if (! list) { + list = new TQStringList; + fontSubst->insert(familyName, list); + } + + TQStringList::ConstIterator it = substituteNames.begin(); + while (it != substituteNames.end()) { + if (! list->contains(*it)) + list->append(*it); + it++; + } +} + +// ### mark: should be called removeSubstitutions() +/*! + Removes all the substitutions for \a familyName. + + \sa insertSubstitutions(), insertSubstitution(), substitutions(), substitute() +*/ +void TQFont::removeSubstitution( const TQString &familyName ) +{ // ### function name should be removeSubstitutions() or + // ### removeSubstitutionList() + initFontSubst(); + + fontSubst->remove(familyName); +} + + +/*! + Returns a sorted list of substituted family names. + + \sa insertSubstitution(), removeSubstitution(), substitute() +*/ +TQStringList TQFont::substitutions() +{ + initFontSubst(); + + TQStringList ret; + TQDictIterator it(*fontSubst); + + while (it.current()) { + ret.append(it.currentKey()); + ++it; + } + + ret.sort(); + + return ret; +} + +#endif // TQT_NO_STRINGLIST + + +/* \internal + Internal function. Converts boolean font settings to an unsigned + 8-bit number. Used for serialization etc. +*/ +static TQ_UINT8 get_font_bits( const TQFontPrivate *f ) +{ +#ifdef QT_CHECK_STATE + Q_ASSERT( f != 0 ); +#endif + + TQ_UINT8 bits = 0; + if ( f->request.italic ) + bits |= 0x01; + if ( f->underline ) + bits |= 0x02; + if ( f->overline ) + bits |= 0x40; + if ( f->strikeOut ) + bits |= 0x04; + if ( f->request.fixedPitch ) + bits |= 0x08; + // if ( f.hintSetByUser ) + // bits |= 0x10; + if ( f->rawMode ) + bits |= 0x20; + return bits; +} + + +#ifndef TQT_NO_DATASTREAM + +/* \internal + Internal function. Sets boolean font settings from an unsigned + 8-bit number. Used for serialization etc. +*/ +static void set_font_bits( TQ_UINT8 bits, TQFontPrivate *f ) +{ +#ifdef QT_CHECK_STATE + Q_ASSERT( f != 0 ); +#endif + + f->request.italic = (bits & 0x01) != 0; + f->underline = (bits & 0x02) != 0; + f->overline = (bits & 0x40) != 0; + f->strikeOut = (bits & 0x04) != 0; + f->request.fixedPitch = (bits & 0x08) != 0; + // f->hintSetByUser = (bits & 0x10) != 0; + f->rawMode = (bits & 0x20) != 0; +} + +#endif + + +/*! + Returns the font's key, a textual representation of a font. It is + typically used as the key for a cache or dictionary of fonts. + + \sa TQMap +*/ +TQString TQFont::key() const +{ + return toString(); +} + +/*! + Returns a description of the font. The description is a + comma-separated list of the attributes, perfectly suited for use + in TQSettings. + + \sa fromString() operator<<() + */ +TQString TQFont::toString() const +{ + const TQChar comma( ',' ); + return family() + comma + + TQString::number( pointSizeFloat() ) + comma + + TQString::number( pixelSize() ) + comma + + TQString::number( (int) styleHint() ) + comma + + TQString::number( weight() ) + comma + + TQString::number( (int) italic() ) + comma + + TQString::number( (int) underline() ) + comma + + TQString::number( (int) strikeOut() ) + comma + + TQString::number( (int)fixedPitch() ) + comma + + TQString::number( (int) rawMode() ); +} + + +/*! + Sets this font to match the description \a descrip. The description + is a comma-separated list of the font attributes, as returned by + toString(). + + \sa toString() operator>>() + */ +bool TQFont::fromString(const TQString &descrip) +{ +#ifndef TQT_NO_STRINGLIST + TQStringList l(TQStringList::split(',', descrip)); + + int count = (int)l.count(); +#else + int count = 0; + TQString l[11]; + int from = 0; + int to = descrip.find( ',' ); + while ( to > 0 && count < 11 ) { + l[count] = descrip.mid( from, to-from ); + count++; + from = to+1; + to = descrip.find( ',', from ); + } +#endif // TQT_NO_STRINGLIST + if ( !count || ( count > 2 && count < 9 ) || count > 11 ) { + +#ifdef QT_CHECK_STATE + tqWarning("TQFont::fromString: invalid description '%s'", + descrip.isEmpty() ? "(empty)" : descrip.latin1()); +#endif + + return FALSE; + } + + setFamily(l[0]); + if ( count > 1 && l[1].toDouble() > 0.0 ) + setPointSizeFloat(l[1].toDouble()); + if ( count == 9 ) { + setStyleHint((StyleHint) l[2].toInt()); + setWeight(l[3].toInt()); + setItalic(l[4].toInt()); + setUnderline(l[5].toInt()); + setStrikeOut(l[6].toInt()); + setFixedPitch(l[7].toInt()); + setRawMode(l[8].toInt()); + } else if ( count == 10 ) { + if ( l[2].toInt() > 0 ) + setPixelSize( l[2].toInt() ); + setStyleHint((StyleHint) l[3].toInt()); + setWeight(l[4].toInt()); + setItalic(l[5].toInt()); + setUnderline(l[6].toInt()); + setStrikeOut(l[7].toInt()); + setFixedPitch(l[8].toInt()); + setRawMode(l[9].toInt()); + } + + return TRUE; +} + +/*! \internal + + Internal function that dumps font cache statistics. +*/ +void TQFont::cacheStatistics() +{ +} + + + +/***************************************************************************** + TQFont stream functions + *****************************************************************************/ +#ifndef TQT_NO_DATASTREAM + +/*! + \relates TQFont + + Writes the font \a font to the data stream \a s. (toString() + writes to a text stream.) + + \sa \link datastreamformat.html Format of the TQDataStream operators \endlink +*/ +TQDataStream &operator<<( TQDataStream &s, const TQFont &font ) +{ + if ( s.version() == 1 ) { + TQCString fam( font.d->request.family.latin1() ); + s << fam; + } else { + s << font.d->request.family; + } + + if ( s.version() <= 3 ) { + TQ_INT16 pointSize = (TQ_INT16) font.d->request.pointSize; + if ( pointSize == -1 ) { +#ifdef TQ_WS_X11 + pointSize = (TQ_INT16)(font.d->request.pixelSize*720/TQPaintDevice::x11AppDpiY()); +#else + pointSize = (TQ_INT16)TQFontInfo( font ).pointSize() * 10; +#endif + } + s << pointSize; + } else { + s << (TQ_INT16) font.d->request.pointSize; + s << (TQ_INT16) font.d->request.pixelSize; + } + + s << (TQ_UINT8) font.d->request.styleHint; + if ( s.version() >= 5 ) + s << (TQ_UINT8 ) font.d->request.styleStrategy; + return s << (TQ_UINT8) 0 + << (TQ_UINT8) font.d->request.weight + << get_font_bits(font.d); +} + + +/*! + \relates TQFont + + Reads the font \a font from the data stream \a s. (fromString() + reads from a text stream.) + + \sa \link datastreamformat.html Format of the TQDataStream operators \endlink +*/ +TQDataStream &operator>>( TQDataStream &s, TQFont &font ) +{ + if (font.d->deref()) delete font.d; + + font.d = new TQFontPrivate; + font.d->mask = TQFontPrivate::Complete; + + TQ_INT16 pointSize, pixelSize = -1; + TQ_UINT8 styleHint, styleStrategy = TQFont::PreferDefault, charSet, weight, bits; + + if ( s.version() == 1 ) { + TQCString fam; + s >> fam; + font.d->request.family = TQString( fam ); + } else { + s >> font.d->request.family; + } + + s >> pointSize; + if ( s.version() >= 4 ) + s >> pixelSize; + s >> styleHint; + if ( s.version() >= 5 ) + s >> styleStrategy; + s >> charSet; + s >> weight; + s >> bits; + + font.d->request.pointSize = pointSize; + font.d->request.pixelSize = pixelSize; + font.d->request.styleHint = styleHint; + font.d->request.styleStrategy = styleStrategy; + font.d->request.weight = weight; + + set_font_bits( bits, font.d ); + + return s; +} + +#endif // TQT_NO_DATASTREAM + + + + +/***************************************************************************** + TQFontMetrics member functions + *****************************************************************************/ + +/*! + \class TQFontMetrics tqfontmetrics.h + \brief The TQFontMetrics class provides font metrics information. + + \ingroup graphics + \ingroup shared + + TQFontMetrics functions calculate the size of characters and + strings for a given font. There are three ways you can create a + TQFontMetrics object: + + \list 1 + \i Calling the TQFontMetrics constructor with a TQFont creates a + font metrics object for a screen-compatible font, i.e. the font + cannot be a printer font*. If the font is changed + later, the font metrics object is \e not updated. + + \i TQWidget::fontMetrics() returns the font metrics for a widget's + font. This is equivalent to TQFontMetrics(widget->font()). If the + widget's font is changed later, the font metrics object is \e not + updated. + + \i TQPainter::fontMetrics() returns the font metrics for a + painter's current font. If the painter's font is changed later, the + font metrics object is \e not updated. + \endlist + + * If you use a printer font the values returned may be + inaccurate. Printer fonts are not always accessible so the nearest + screen font is used if a printer font is supplied. + + Once created, the object provides functions to access the + individual metrics of the font, its characters, and for strings + rendered in the font. + + There are several functions that operate on the font: ascent(), + descent(), height(), leading() and lineSpacing() return the basic + size properties of the font. The underlinePos(), overlinePos(), + strikeOutPos() and lineWidth() functions, return the properties of + the line that underlines, overlines or strikes out the + characters. These functions are all fast. + + There are also some functions that operate on the set of glyphs in + the font: minLeftBearing(), minRightBearing() and maxWidth(). + These are by necessity slow, and we recommend avoiding them if + possible. + + For each character, you can get its width(), leftBearing() and + rightBearing() and find out whether it is in the font using + inFont(). You can also treat the character as a string, and use + the string functions on it. + + The string functions include width(), to return the width of a + string in pixels (or points, for a printer), boundingRect(), to + return a rectangle large enough to contain the rendered string, + and size(), to return the size of that rectangle. + + Example: + \code + TQFont font( "times", 24 ); + TQFontMetrics fm( font ); + int pixelsWide = fm.width( "What's the width of this text?" ); + int pixelsHigh = fm.height(); + \endcode + + \sa TQFont TQFontInfo TQFontDatabase +*/ + +/*! + Constructs a font metrics object for \a font. + + The font must be screen-compatible, i.e. a font you use when + drawing text in \link TQWidget widgets\endlink or \link TQPixmap + pixmaps\endlink, not TQPicture or TQPrinter. + + The font metrics object holds the information for the font that is + passed in the constructor at the time it is created, and is not + updated if the font's attributes are changed later. + + Use TQPainter::fontMetrics() to get the font metrics when painting. + This will give correct results also when painting on paint device + that is not screen-compatible. +*/ +TQFontMetrics::TQFontMetrics( const TQFont &font ) + : d( font.d ), painter( 0 ), fscript( TQFont::NoScript ) +{ + d->ref(); +} + +/*! + \overload + + Constructs a font metrics object for \a font using the given \a + script. +*/ +TQFontMetrics::TQFontMetrics( const TQFont &font, TQFont::Script script ) + : d( font.d ), painter( 0 ), fscript( script ) +{ + d->ref(); +} + +/*! \internal + + Constructs a font metrics object for the painter's font \a p. +*/ +TQFontMetrics::TQFontMetrics( const TQPainter *p ) + : painter ( (TQPainter *) p ), fscript( TQFont::NoScript ) +{ +#if defined(CHECK_STATE) + if ( !painter->isActive() ) + tqWarning( "TQFontMetrics: Get font metrics between TQPainter::begin() " + "and TQPainter::end()" ); +#endif + + if ( painter->testf(TQPainter::DirtyFont) ) + painter->updateFont(); + + d = painter->pfont ? painter->pfont->d : painter->cfont.d; + +#if defined(TQ_WS_X11) + if ( d->screen != p->scrn ) { + TQFontPrivate *new_d = new TQFontPrivate( *d ); + TQ_CHECK_PTR( new_d ); + d = new_d; + d->screen = p->scrn; + d->count = 1; + } else +#endif // TQ_WS_X11 + d->ref(); +} + +/*! + Constructs a copy of \a fm. +*/ +TQFontMetrics::TQFontMetrics( const TQFontMetrics &fm ) + : d( fm.d ), painter( 0 ), fscript( fm.fscript ) +{ + d->ref(); +} + +/*! + Destroys the font metrics object and frees all allocated + resources. +*/ +TQFontMetrics::~TQFontMetrics() +{ + if ( d->deref() ) + delete d; +} + +/*! + Assigns the font metrics \a fm. +*/ +TQFontMetrics &TQFontMetrics::operator=( const TQFontMetrics &fm ) +{ + if ( d != fm.d ) { + if ( d->deref() ) + delete d; + d = fm.d; + d->ref(); + } + painter = fm.painter; + return *this; +} + +/*! + Returns the ascent of the font. + + The ascent of a font is the distance from the baseline to the + highest position characters extend to. In practice, some font + designers break this rule, e.g. when they put more than one accent + on top of a character, or to accommodate an unusual character in + an exotic language, so it is possible (though rare) that this + value will be too small. + + \sa descent() +*/ +int TQFontMetrics::ascent() const +{ + TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript ); + TQFontEngine *latin_engine = d->engineForScript( TQFont::Latin ); +#ifdef QT_CHECK_STATE + Q_ASSERT( engine != 0 ); + Q_ASSERT( latin_engine != 0 ); +#endif // QT_CHECK_STATE + + return TQMAX(engine->ascent(), latin_engine->ascent()); +} + + +/*! + Returns the descent of the font. + + The descent is the distance from the base line to the lowest point + characters extend to. (Note that this is different from X, which + adds 1 pixel.) In practice, some font designers break this rule, + e.g. to accommodate an unusual character in an exotic language, so + it is possible (though rare) that this value will be too small. + + \sa ascent() +*/ +int TQFontMetrics::descent() const +{ + TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript ); + TQFontEngine *latin_engine = d->engineForScript( TQFont::Latin ); +#ifdef QT_CHECK_STATE + Q_ASSERT( engine != 0 ); + Q_ASSERT( latin_engine != 0 ); +#endif // QT_CHECK_STATE + + return TQMAX(engine->descent(), latin_engine->descent()); +} + +/*! + Returns the height of the font. + + This is always equal to ascent()+descent()+1 (the 1 is for the + base line). + + \sa leading(), lineSpacing() +*/ +int TQFontMetrics::height() const +{ + TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript ); + TQFontEngine *latin_engine = d->engineForScript( TQFont::Latin ); +#ifdef QT_CHECK_STATE + Q_ASSERT( engine != 0 ); + Q_ASSERT( latin_engine != 0 ); +#endif // QT_CHECK_STATE + + return (TQMAX(engine->ascent(), latin_engine->ascent()) + + TQMAX(engine->descent(), latin_engine->descent()) + 1); +} + +/*! + Returns the leading of the font. + + This is the natural inter-line spacing. + + \sa height(), lineSpacing() +*/ +int TQFontMetrics::leading() const +{ + TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript ); + TQFontEngine *latin_engine = d->engineForScript( TQFont::Latin ); +#ifdef QT_CHECK_STATE + Q_ASSERT( engine != 0 ); + Q_ASSERT( latin_engine != 0 ); +#endif // QT_CHECK_STATE + + return TQMAX(engine->leading(), latin_engine->leading()); +} + +/*! + Returns the distance from one base line to the next. + + This value is always equal to leading()+height(). + + \sa height(), leading() +*/ +int TQFontMetrics::lineSpacing() const +{ + TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript ); + TQFontEngine *latin_engine = d->engineForScript( TQFont::Latin ); +#ifdef QT_CHECK_STATE + Q_ASSERT( engine != 0 ); + Q_ASSERT( latin_engine != 0 ); +#endif // QT_CHECK_STATE + + return (TQMAX(engine->leading(), latin_engine->leading()) + + TQMAX(engine->ascent(), latin_engine->ascent()) + + TQMAX(engine->descent(), latin_engine->descent()) + 1); +} + +/*! + Returns the minimum left bearing of the font. + + This is the smallest leftBearing(char) of all characters in the + font. + + Note that this function can be very slow if the font is large. + + \sa minRightBearing(), leftBearing() +*/ +int TQFontMetrics::minLeftBearing() const +{ + TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript ); + TQFontEngine *latin_engine = d->engineForScript( TQFont::Latin ); +#ifdef QT_CHECK_STATE + Q_ASSERT( engine != 0 ); + Q_ASSERT( latin_engine != 0 ); +#endif // QT_CHECK_STATE + + return TQMIN(engine->minLeftBearing(), latin_engine->minLeftBearing()); +} + +/*! + Returns the minimum right bearing of the font. + + This is the smallest rightBearing(char) of all characters in the + font. + + Note that this function can be very slow if the font is large. + + \sa minLeftBearing(), rightBearing() +*/ +int TQFontMetrics::minRightBearing() const +{ + TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript ); + TQFontEngine *latin_engine = d->engineForScript( TQFont::Latin ); +#ifdef QT_CHECK_STATE + Q_ASSERT( engine != 0 ); + Q_ASSERT( latin_engine != 0 ); +#endif // QT_CHECK_STATE + + return TQMIN(engine->minRightBearing(), latin_engine->minRightBearing()); +} + +/*! + Returns the width of the widest character in the font. +*/ +int TQFontMetrics::maxWidth() const +{ + TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript ); + TQFontEngine *lengine = d->engineForScript( TQFont::Latin ); +#ifdef QT_CHECK_STATE + Q_ASSERT( engine != 0 ); + Q_ASSERT( lengine != 0 ); +#endif // QT_CHECK_STATE + + return TQMAX(engine->maxCharWidth(), lengine->maxCharWidth()); +} + +/*! + Returns TRUE if character \a ch is a valid character in the font; + otherwise returns FALSE. +*/ +bool TQFontMetrics::inFont(TQChar ch) const +{ + TQFont::Script script; + SCRIPT_FOR_CHAR( script, ch ); + + TQFontEngine *engine = d->engineForScript( script ); +#ifdef QT_CHECK_STATE + Q_ASSERT( engine != 0 ); +#endif // QT_CHECK_STATE + + if ( engine->type() == TQFontEngine::Box ) return FALSE; + return engine->canRender( &ch, 1 ); +} + +/*! \fn int TQFontMetrics::leftBearing( TQChar ch ) const + Returns the left bearing of character \a ch in the font. + + The left bearing is the right-ward distance of the left-most pixel + of the character from the logical origin of the character. This + value is negative if the pixels of the character extend to the + left of the logical origin. + + See width(TQChar) for a graphical description of this metric. + + \sa rightBearing(), minLeftBearing(), width() +*/ +#if !defined(TQ_WS_WIN) +int TQFontMetrics::leftBearing(TQChar ch) const +{ + TQFont::Script script; + SCRIPT_FOR_CHAR( script, ch ); + + TQFontEngine *engine = d->engineForScript( script ); +#ifdef QT_CHECK_STATE + Q_ASSERT( engine != 0 ); +#endif // QT_CHECK_STATE + + if ( engine->type() == TQFontEngine::Box ) return 0; + + glyph_t glyphs[10]; + int nglyphs = 9; + engine->stringToCMap( &ch, 1, glyphs, 0, &nglyphs, FALSE ); + // ### can nglyphs != 1 happen at all? Not currently I think + glyph_metrics_t gi = engine->boundingBox( glyphs[0] ); + return gi.x; +} +#endif // !TQ_WS_WIN + +/*! \fn int TQFontMetrics::rightBearing(TQChar ch) const + Returns the right bearing of character \a ch in the font. + + The right bearing is the left-ward distance of the right-most + pixel of the character from the logical origin of a subsequent + character. This value is negative if the pixels of the character + extend to the right of the width() of the character. + + See width() for a graphical description of this metric. + + \sa leftBearing(), minRightBearing(), width() +*/ +#if !defined(TQ_WS_WIN) +int TQFontMetrics::rightBearing(TQChar ch) const +{ + TQFont::Script script; + SCRIPT_FOR_CHAR( script, ch ); + + TQFontEngine *engine = d->engineForScript( script ); +#ifdef QT_CHECK_STATE + Q_ASSERT( engine != 0 ); +#endif // QT_CHECK_STATE + + if ( engine->type() == TQFontEngine::Box ) return 0; + + glyph_t glyphs[10]; + int nglyphs = 9; + engine->stringToCMap( &ch, 1, glyphs, 0, &nglyphs, FALSE ); + // ### can nglyphs != 1 happen at all? Not currently I think + glyph_metrics_t gi = engine->boundingBox( glyphs[0] ); + return gi.xoff - gi.x - gi.width; +} +#endif // !TQ_WS_WIN + + +/*! + Returns the width in pixels of the first \a len characters of \a + str. If \a len is negative (the default), the entire string is + used. + + Note that this value is \e not equal to boundingRect().width(); + boundingRect() returns a rectangle describing the pixels this + string will cover whereas width() returns the distance to where + the next string should be drawn. + + \sa boundingRect() +*/ +int TQFontMetrics::width( const TQString &str, int len ) const +{ + if (len < 0) + len = str.length(); + if (len == 0) + return 0; + + int pos = 0; + int width = 0; +#ifndef TQ_WS_MAC + const TQChar *ch = str.unicode(); + + while (pos < len) { + unsigned short uc = ch->unicode(); + if (uc < TQFontEngineData::widthCacheSize && d->engineData && d->engineData->widthCache[uc]) + width += d->engineData->widthCache[uc]; + else { + TQFont::Script script; + SCRIPT_FOR_CHAR( script, *ch ); + + if (script >= TQFont::Arabic && script <= TQFont::Khmer) + break; + if ( ::category( *ch ) != TQChar::Mark_NonSpacing && !qIsZeroWidthChar(ch->unicode())) { + TQFontEngine *engine = d->engineForScript( script ); +#ifdef QT_CHECK_STATE + Q_ASSERT( engine != 0 ); +#endif // QT_CHECK_STATE + + glyph_t glyphs[8]; + advance_t advances[8]; + int nglyphs = 7; + engine->stringToCMap( ch, 1, glyphs, advances, &nglyphs, FALSE ); + + // ### can nglyphs != 1 happen at all? Not currently I think + if ( uc < TQFontEngineData::widthCacheSize && advances[0] > 0 && advances[0] < 0x100 ) + d->engineData->widthCache[ uc ] = advances[0]; + width += advances[0]; + } + } + ++pos; + ++ch; + } + if ( pos < len ) { +#endif + TQTextEngine layout( str, d ); + layout.itemize( TQTextEngine::WidthOnly ); + width += layout.width( pos, len-pos ); +#ifndef TQ_WS_MAC + } +#endif + return width; +} + +/*! \fn int TQFontMetrics::width( TQChar ch ) const + + + + Returns the logical width of character \a ch in pixels. This is a + distance appropriate for drawing a subsequent character after \a + ch. + + Some of the metrics are described in the image to the right. The + central dark rectangles cover the logical width() of each + character. The outer pale rectangles cover the leftBearing() and + rightBearing() of each character. Notice that the bearings of "f" + in this particular font are both negative, while the bearings of + "o" are both positive. + + \warning This function will produce incorrect results for Arabic + characters or non spacing marks in the middle of a string, as the + glyph shaping and positioning of marks that happens when + processing strings cannot be taken into account. Use charWidth() + instead if you aren't looking for the width of isolated + characters. + + \sa boundingRect(), charWidth() +*/ + +/*! \fn int TQFontMetrics::width( char c ) const + + \overload + \obsolete + + Provided to aid porting from TQt 1.x. +*/ + +/*! \fn int TQFontMetrics::charWidth( const TQString &str, int pos ) const + Returns the width of the character at position \a pos in the + string \a str. + + The whole string is needed, as the glyph drawn may change + depending on the context (the letter before and after the current + one) for some languages (e.g. Arabic). + + This function also takes non spacing marks and ligatures into + account. +*/ + +/*! + Returns the bounding rectangle of the first \a len characters of + \a str, which is the set of pixels the text would cover if drawn + at (0, 0). + + If \a len is negative (the default), the entire string is used. + + Note that the bounding rectangle may extend to the left of (0, 0), + e.g. for italicized fonts, and that the text output may cover \e + all pixels in the bounding rectangle. + + Newline characters are processed as normal characters, \e not as + linebreaks. + + Due to the different actual character heights, the height of the + bounding rectangle of e.g. "Yes" and "yes" may be different. + + \sa width(), TQPainter::boundingRect() +*/ +TQRect TQFontMetrics::boundingRect( const TQString &str, int len ) const +{ + if (len < 0) + len = str.length(); + if (len == 0) + return TQRect(); + + TQTextEngine layout( str, d ); + layout.itemize( TQTextEngine::NoBidi|TQTextEngine::SingleLine ); + glyph_metrics_t gm = layout.boundingBox( 0, len ); + return TQRect( gm.x, gm.y, gm.width, gm.height ); +} + +/*! + Returns the rectangle that is covered by ink if the character + specified by \a ch were to be drawn at the origin of the coordinate + system. + + Note that the bounding rectangle may extend to the left of (0, 0), + e.g. for italicized fonts, and that the text output may cover \e + all pixels in the bounding rectangle. For a space character the rectangle + will usually be empty. + + Note that the rectangle usually extends both above and below the + base line. + + \warning The width of the returned rectangle is not the advance width + of the character. Use boundingRect(const TQString &) or width() instead. + + \sa width() +*/ +TQRect TQFontMetrics::boundingRect( TQChar ch ) const +{ + TQFont::Script script; + SCRIPT_FOR_CHAR( script, ch ); + + TQFontEngine *engine = d->engineForScript( script ); +#ifdef QT_CHECK_STATE + Q_ASSERT( engine != 0 ); +#endif // QT_CHECK_STATE + + glyph_t glyphs[10]; + int nglyphs = 9; + engine->stringToCMap( &ch, 1, glyphs, 0, &nglyphs, FALSE ); + glyph_metrics_t gi = engine->boundingBox( glyphs[0] ); + return TQRect( gi.x, gi.y, gi.width, gi.height ); +} + +/*! + \overload + + Returns the bounding rectangle of the first \a len characters of + \a str, which is the set of pixels the text would cover if drawn + at (0, 0). The drawing, and hence the bounding rectangle, is + constrained to the rectangle (\a x, \a y, \a w, \a h). + + If \a len is negative (which is the default), the entire string is + used. + + The \a flgs argument is the bitwise OR of the following flags: + \list + \i \c AlignAuto aligns to the left border for all languages except + Arabic and Hebrew where it aligns to the right. + \i \c AlignLeft aligns to the left border. + \i \c AlignRight aligns to the right border. + \i \c AlignJustify produces justified text. + \i \c AlignHCenter aligns horizontally centered. + \i \c AlignTop aligns to the top border. + \i \c AlignBottom aligns to the bottom border. + \i \c AlignVCenter aligns vertically centered + \i \c AlignCenter (== \c{AlignHCenter | AlignVCenter}) + \i \c SingleLine ignores newline characters in the text. + \i \c ExpandTabs expands tabs (see below) + \i \c ShowPrefix interprets "&x" as "x", i.e. underlined. + \i \c WordBreak breaks the text to fit the rectangle. + \endlist + + Horizontal alignment defaults to \c AlignAuto and vertical + alignment defaults to \c AlignTop. + + If several of the horizontal or several of the vertical alignment + flags are set, the resulting alignment is undefined. + + These flags are defined in \c ntqnamespace.h. + + If \c ExpandTabs is set in \a flgs, then: if \a tabarray is + non-null, it specifies a 0-terminated sequence of pixel-positions + for tabs; otherwise if \a tabstops is non-zero, it is used as the + tab spacing (in pixels). + + Note that the bounding rectangle may extend to the left of (0, 0), + e.g. for italicized fonts, and that the text output may cover \e + all pixels in the bounding rectangle. + + Newline characters are processed as linebreaks. + + Despite the different actual character heights, the heights of the + bounding rectangles of "Yes" and "yes" are the same. + + The bounding rectangle given by this function is somewhat larger + than that calculated by the simpler boundingRect() function. This + function uses the \link minLeftBearing() maximum left \endlink and + \link minRightBearing() right \endlink font bearings as is + necessary for multi-line text to align correctly. Also, + fontHeight() and lineSpacing() are used to calculate the height, + rather than individual character heights. + + The \a intern argument should not be used. + + \sa width(), TQPainter::boundingRect(), TQt::AlignmentFlags +*/ +TQRect TQFontMetrics::boundingRect( int x, int y, int w, int h, int flgs, + const TQString& str, int len, int tabstops, + int *tabarray, TQTextParag **intern ) const +{ + if ( len < 0 ) + len = str.length(); + + int tabarraylen=0; + if (tabarray) + while (tabarray[tabarraylen]) + tabarraylen++; + + TQRect rb; + TQRect r(x, y, w, h); + qt_format_text( TQFont( d, d->paintdevice ), r, flgs|TQt::DontPrint, str, len, &rb, + tabstops, tabarray, tabarraylen, intern, 0 ); + + return rb; +} + +/*! + Returns the size in pixels of the first \a len characters of \a + str. + + If \a len is negative (the default), the entire string is used. + + The \a flgs argument is the bitwise OR of the following flags: + \list + \i \c SingleLine ignores newline characters. + \i \c ExpandTabs expands tabs (see below) + \i \c ShowPrefix interprets "&x" as "x", i.e. underlined. + \i \c WordBreak breaks the text to fit the rectangle. + \endlist + + These flags are defined in \c ntqnamespace.h. + + If \c ExpandTabs is set in \a flgs, then: if \a tabarray is + non-null, it specifies a 0-terminated sequence of pixel-positions + for tabs; otherwise if \a tabstops is non-zero, it is used as the + tab spacing (in pixels). + + Newline characters are processed as linebreaks. + + Despite the different actual character heights, the heights of the + bounding rectangles of "Yes" and "yes" are the same. + + The \a intern argument should not be used. + + \sa boundingRect() +*/ +TQSize TQFontMetrics::size( int flgs, const TQString &str, int len, int tabstops, + int *tabarray, TQTextParag **intern ) const +{ + return boundingRect(0,0,0,0,flgs,str,len,tabstops,tabarray,intern).size(); +} + +/*! + Returns the distance from the base line to where an underscore + should be drawn. + + \sa overlinePos(), strikeOutPos(), lineWidth() +*/ +int TQFontMetrics::underlinePos() const +{ + TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript ); +#ifdef QT_CHECK_STATE + Q_ASSERT( engine != 0 ); +#endif // QT_CHECK_STATE + + return engine->underlinePosition(); +} + +/*! + Returns the distance from the base line to where an overline + should be drawn. + + \sa underlinePos(), strikeOutPos(), lineWidth() +*/ +int TQFontMetrics::overlinePos() const +{ + int pos = ascent() + 1; + return pos > 0 ? pos : 1; +} + +/*! + Returns the distance from the base line to where the strikeout + line should be drawn. + + \sa underlinePos(), overlinePos(), lineWidth() +*/ +int TQFontMetrics::strikeOutPos() const +{ + int pos = ascent() / 3; + return pos > 0 ? pos : 1; +} + +/*! + Returns the width of the underline and strikeout lines, adjusted + for the point size of the font. + + \sa underlinePos(), overlinePos(), strikeOutPos() +*/ +int TQFontMetrics::lineWidth() const +{ + TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript ); +#ifdef QT_CHECK_STATE + Q_ASSERT( engine != 0 ); +#endif // QT_CHECK_STATE + + return engine->lineThickness(); +} + + + + +/***************************************************************************** + TQFontInfo member functions + *****************************************************************************/ + +/*! + \class TQFontInfo tqfontinfo.h + + \brief The TQFontInfo class provides general information about fonts. + + \ingroup graphics + \ingroup shared + + The TQFontInfo class provides the same access functions as TQFont, + e.g. family(), pointSize(), italic(), weight(), fixedPitch(), + styleHint() etc. But whilst the TQFont access functions return the + values that were set, a TQFontInfo object returns the values that + apply to the font that will actually be used to draw the text. + + For example, when the program asks for a 25pt Courier font on a + machine that has a non-scalable 24pt Courier font, TQFont will + (normally) use the 24pt Courier for rendering. In this case, + TQFont::pointSize() returns 25 and TQFontInfo::pointSize() returns + 24. + + There are three ways to create a TQFontInfo object. + \list 1 + \i Calling the TQFontInfo constructor with a TQFont creates a font + info object for a screen-compatible font, i.e. the font cannot be + a printer font*. If the font is changed later, the font + info object is \e not updated. + + \i TQWidget::fontInfo() returns the font info for a widget's font. + This is equivalent to calling TQFontInfo(widget->font()). If the + widget's font is changed later, the font info object is \e not + updated. + + \i TQPainter::fontInfo() returns the font info for a painter's + current font. If the painter's font is changed later, the font + info object is \e not updated. + \endlist + + * If you use a printer font the values returned may be + inaccurate. Printer fonts are not always accessible so the nearest + screen font is used if a printer font is supplied. + + \sa TQFont TQFontMetrics TQFontDatabase +*/ + +/*! + Constructs a font info object for \a font. + + The font must be screen-compatible, i.e. a font you use when + drawing text in \link TQWidget widgets\endlink or \link TQPixmap + pixmaps\endlink, not TQPicture or TQPrinter. + + The font info object holds the information for the font that is + passed in the constructor at the time it is created, and is not + updated if the font's attributes are changed later. + + Use TQPainter::fontInfo() to get the font info when painting. + This will give correct results also when painting on paint device + that is not screen-compatible. +*/ +TQFontInfo::TQFontInfo( const TQFont &font ) + : d( font.d ), painter( 0 ), fscript( TQFont::NoScript ) +{ + d->ref(); +} + +/*! + Constructs a font info object for \a font using the specified \a + script. +*/ +TQFontInfo::TQFontInfo( const TQFont &font, TQFont::Script script ) + : d( font.d ), painter( 0 ), fscript( script ) +{ + d->ref(); +} + +/*! \internal + + Constructs a font info object from the painter's font \a p. +*/ +TQFontInfo::TQFontInfo( const TQPainter *p ) + : painter( 0 ), fscript( TQFont::NoScript ) +{ + TQPainter *painter = (TQPainter *) p; + +#if defined(CHECK_STATE) + if ( !painter->isActive() ) + tqWarning( "TQFontInfo: Get font info between TQPainter::begin() " + "and TQPainter::end()" ); +#endif + + painter->setf( TQPainter::FontInf ); + if ( painter->testf(TQPainter::DirtyFont) ) + painter->updateFont(); + if ( painter->pfont ) + d = painter->pfont->d; + else + d = painter->cfont.d; + d->ref(); +} + +/*! + Constructs a copy of \a fi. +*/ +TQFontInfo::TQFontInfo( const TQFontInfo &fi ) + : d(fi.d), painter(0), fscript( fi.fscript ) +{ + d->ref(); +} + +/*! + Destroys the font info object. +*/ +TQFontInfo::~TQFontInfo() +{ + if ( d->deref() ) + delete d; +} + +/*! + Assigns the font info in \a fi. +*/ +TQFontInfo &TQFontInfo::operator=( const TQFontInfo &fi ) +{ + if ( d != fi.d ) { + if ( d->deref() ) + delete d; + d = fi.d; + d->ref(); + } + painter = 0; + fscript = fi.fscript; + return *this; +} + +/*! + Returns the family name of the matched window system font. + + \sa TQFont::family() +*/ +TQString TQFontInfo::family() const +{ + TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript ); +#ifdef QT_CHECK_STATE + Q_ASSERT( engine != 0 ); +#endif // QT_CHECK_STATE + return engine->fontDef.family; +} + +/*! + Returns the point size of the matched window system font. + + \sa TQFont::pointSize() +*/ +int TQFontInfo::pointSize() const +{ + TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript ); +#ifdef QT_CHECK_STATE + Q_ASSERT( engine != 0 ); +#endif // QT_CHECK_STATE + return ( engine->fontDef.pointSize + 5 ) / 10; +} + +/*! + Returns the pixel size of the matched window system font. + + \sa TQFont::pointSize() +*/ +int TQFontInfo::pixelSize() const +{ + TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript ); +#ifdef QT_CHECK_STATE + Q_ASSERT( engine != 0 ); +#endif // QT_CHECK_STATE + return engine->fontDef.pixelSize; +} + +/*! + Returns the italic value of the matched window system font. + + \sa TQFont::italic() +*/ +bool TQFontInfo::italic() const +{ + TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript ); +#ifdef QT_CHECK_STATE + Q_ASSERT( engine != 0 ); +#endif // QT_CHECK_STATE + return engine->fontDef.italic; +} + +/*! + Returns the weight of the matched window system font. + + \sa TQFont::weight(), bold() +*/ +int TQFontInfo::weight() const +{ + TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript ); +#ifdef QT_CHECK_STATE + Q_ASSERT( engine != 0 ); +#endif // QT_CHECK_STATE + return engine->fontDef.weight; + +} + +/*! + \fn bool TQFontInfo::bold() const + + Returns TRUE if weight() would return a value greater than \c + TQFont::Normal; otherwise returns FALSE. + + \sa weight(), TQFont::bold() +*/ + +/*! + Returns the underline value of the matched window system font. + + \sa TQFont::underline() + + \internal + + Here we read the underline flag directly from the TQFont. + This is OK for X11 and for Windows because we always get what we want. +*/ +bool TQFontInfo::underline() const +{ + return d->underline; +} + +/*! + Returns the overline value of the matched window system font. + + \sa TQFont::overline() + + \internal + + Here we read the overline flag directly from the TQFont. + This is OK for X11 and for Windows because we always get what we want. +*/ +bool TQFontInfo::overline() const +{ + return d->overline; +} + +/*! + Returns the strikeout value of the matched window system font. + + \sa TQFont::strikeOut() + + \internal Here we read the strikeOut flag directly from the TQFont. + This is OK for X11 and for Windows because we always get what we want. +*/ +bool TQFontInfo::strikeOut() const +{ + return d->strikeOut; +} + +/*! + Returns the fixed pitch value of the matched window system font. + + \sa TQFont::fixedPitch() +*/ +bool TQFontInfo::fixedPitch() const +{ + TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript ); +#ifdef QT_CHECK_STATE + Q_ASSERT( engine != 0 ); +#endif // QT_CHECK_STATE +#ifdef Q_OS_MAC + if (!engine->fontDef.fixedPitchComputed) { + TQChar ch[2] = { TQChar('i'), TQChar('m') }; + glyph_t g[2]; + int l = 2; + advance_t a[2]; + engine->stringToCMap(ch, 2, g, a, &l, FALSE); + engine->fontDef.fixedPitch = a[0] == a[1]; + engine->fontDef.fixedPitchComputed = TRUE; + } +#endif + return engine->fontDef.fixedPitch; +} + +/*! + Returns the style of the matched window system font. + + Currently only returns the style hint set in TQFont. + + \sa TQFont::styleHint() TQFont::StyleHint +*/ +TQFont::StyleHint TQFontInfo::styleHint() const +{ + TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript ); +#ifdef QT_CHECK_STATE + Q_ASSERT( engine != 0 ); +#endif // QT_CHECK_STATE + return (TQFont::StyleHint) engine->fontDef.styleHint; +} + +/*! + Returns TRUE if the font is a raw mode font; otherwise returns + FALSE. + + If it is a raw mode font, all other functions in TQFontInfo will + return the same values set in the TQFont, regardless of the font + actually used. + + \sa TQFont::rawMode() +*/ +bool TQFontInfo::rawMode() const +{ + return d->rawMode; +} + +/*! + Returns TRUE if the matched window system font is exactly the same + as the one specified by the font; otherwise returns FALSE. + + \sa TQFont::exactMatch() +*/ +bool TQFontInfo::exactMatch() const +{ + TQFontEngine *engine = d->engineForScript( (TQFont::Script) fscript ); +#ifdef QT_CHECK_STATE + Q_ASSERT( engine != 0 ); +#endif // QT_CHECK_STATE + + return d->rawMode ? engine->type() != TQFontEngine::Box + : d->request == engine->fontDef; +} + + + + +// ********************************************************************** +// TQFontCache +// ********************************************************************** + +#ifdef TQFONTCACHE_DEBUG +// fast timeouts for debugging +static const int fast_timeout = 1000; // 1s +static const int slow_timeout = 5000; // 5s +#else +static const int fast_timeout = 10000; // 10s +static const int slow_timeout = 300000; // 5m +#endif // TQFONTCACHE_DEBUG + +TQFontCache *TQFontCache::instance = 0; +const uint TQFontCache::min_cost = 4*1024; // 4mb + +static TQSingleCleanupHandler cleanup_fontcache; + + +TQFontCache::TQFontCache() + : TQObject( tqApp, "global font cache" ), total_cost( 0 ), max_cost( min_cost ), + current_timestamp( 0 ), fast( FALSE ), timer_id( -1 ) +{ + Q_ASSERT( instance == 0 ); + instance = this; + cleanup_fontcache.set( &instance ); +} + +TQFontCache::~TQFontCache() +{ + { + EngineDataCache::Iterator it = engineDataCache.begin(), + end = engineDataCache.end(); + while ( it != end ) { + if ( it.data()->count == 0 ) + delete it.data(); + else + FC_DEBUG("TQFontCache::~TQFontCache: engineData %p still has refcount %d", + it.data(), it.data()->count); + ++it; + } + } + EngineCache::Iterator it = engineCache.begin(), + end = engineCache.end(); + while ( it != end ) { + if ( it.data().data->count == 0 ) { + if ( --it.data().data->cache_count == 0 ) { + FC_DEBUG("TQFontCache::~TQFontCache: deleting engine %p key=(%d / %d %d %d %d %d)", + it.data().data, it.key().script, it.key().def.pointSize, + it.key().def.pixelSize, it.key().def.weight, it.key().def.italic, + it.key().def.fixedPitch); + + delete it.data().data; + } + } else { + FC_DEBUG("TQFontCache::~TQFontCache: engine = %p still has refcount %d", + it.data().data, it.data().data->count); + } + ++it; + } + instance = 0; +} + +TQFontEngineData *TQFontCache::findEngineData( const Key &key ) const +{ + EngineDataCache::ConstIterator it = engineDataCache.find( key ), + end = engineDataCache.end(); + if ( it == end ) return 0; + + // found + return it.data(); +} + +void TQFontCache::insertEngineData( const Key &key, TQFontEngineData *engineData ) +{ + FC_DEBUG( "TQFontCache: inserting new engine data %p", engineData ); + + engineDataCache.insert( key, engineData ); + increaseCost( sizeof( TQFontEngineData ) ); +} + +TQFontEngine *TQFontCache::findEngine( const Key &key ) +{ + EngineCache::Iterator it = engineCache.find( key ), + end = engineCache.end(); + if ( it == end ) return 0; + + // found... update the hitcount and timestamp + it.data().hits++; + it.data().timestamp = ++current_timestamp; + + FC_DEBUG( "TQFontCache: found font engine\n" + " %p: timestamp %4u hits %3u ref %2d/%2d, type '%s'", + it.data().data, it.data().timestamp, it.data().hits, + it.data().data->count, it.data().data->cache_count, + it.data().data->name() ); + + return it.data().data; +} + +void TQFontCache::insertEngine( const Key &key, TQFontEngine *engine ) +{ + FC_DEBUG( "TQFontCache: inserting new engine %p", engine ); + + Engine data( engine ); + data.timestamp = ++current_timestamp; + + engineCache.insert( key, data ); + + // only increase the cost if this is the first time we insert the engine + if ( engine->cache_count == 0 ) + increaseCost( engine->cache_cost ); + + ++engine->cache_count; +} + +void TQFontCache::increaseCost( uint cost ) +{ + cost = ( cost + 512 ) / 1024; // store cost in kb + cost = cost > 0 ? cost : 1; + total_cost += cost; + + FC_DEBUG( " COST: increased %u kb, total_cost %u kb, max_cost %u kb", + cost, total_cost, max_cost ); + + if ( total_cost > max_cost) { + max_cost = total_cost; + + if ( timer_id == -1 || ! fast ) { + FC_DEBUG( " TIMER: starting fast timer (%d ms)", fast_timeout ); + + if (timer_id != -1) killTimer( timer_id ); + timer_id = startTimer( fast_timeout ); + fast = TRUE; + } + } +} + +void TQFontCache::decreaseCost( uint cost ) +{ + cost = ( cost + 512 ) / 1024; // cost is stored in kb + cost = cost > 0 ? cost : 1; + Q_ASSERT( cost <= total_cost ); + total_cost -= cost; + + FC_DEBUG( " COST: decreased %u kb, total_cost %u kb, max_cost %u kb", + cost, total_cost, max_cost ); +} + +#if defined(TQ_WS_WIN ) +void TQFontCache::cleanupPrinterFonts() +{ + FC_DEBUG( "TQFontCache::cleanupPrinterFonts" ); + + { + FC_DEBUG( " CLEAN engine data:" ); + + // clean out all unused engine datas + EngineDataCache::Iterator it = engineDataCache.begin(), + end = engineDataCache.end(); + while ( it != end ) { + if ( it.key().screen == 0 ) { + ++it; + continue; + } + + if( it.data()->count > 0 ) { +#ifdef TQ_WS_WIN + for(int i = 0; i < TQFont::LastPrivateScript; ++i) { + if( it.data()->engines[i] ) { + it.data()->engines[i]->deref(); + it.data()->engines[i] = 0; + } + } +#else + if ( it.data()->engine ) { + it.data()->engine->deref(); + it.data()->engine = 0; + } +#endif + ++it; + } else { + + EngineDataCache::Iterator rem = it++; + + decreaseCost( sizeof( TQFontEngineData ) ); + + FC_DEBUG( " %p", rem.data() ); + + delete rem.data(); + engineDataCache.remove( rem ); + } + } + } + + EngineCache::Iterator it = engineCache.begin(), + end = engineCache.end(); + while( it != end ) { + if ( it.data().data->count > 0 || it.key().screen == 0) { + ++it; + continue; + } + + FC_DEBUG( " %p: timestamp %4u hits %2u ref %2d/%2d, type '%s'", + it.data().data, it.data().timestamp, it.data().hits, + it.data().data->count, it.data().data->cache_count, + it.data().data->name() ); + + if ( --it.data().data->cache_count == 0 ) { + FC_DEBUG( " DELETE: last occurence in cache" ); + + decreaseCost( it.data().data->cache_cost ); + delete it.data().data; + } + + engineCache.remove( it++ ); + } +} +#endif + +void TQFontCache::timerEvent( TQTimerEvent * ) +{ + FC_DEBUG( "TQFontCache::timerEvent: performing cache maintenance (timestamp %u)", + current_timestamp ); + + if ( total_cost <= max_cost && max_cost <= min_cost ) { + FC_DEBUG( " cache redused sufficiently, stopping timer" ); + + killTimer( timer_id ); + timer_id = -1; + fast = FALSE; + + return; + } + + // go through the cache and count up everything in use + uint in_use_cost = 0; + + { + FC_DEBUG( " SWEEP engine data:" ); + + // make sure the cost of each engine data is at least 1kb + const uint engine_data_cost = + sizeof( TQFontEngineData ) > 1024 ? sizeof( TQFontEngineData ) : 1024; + + EngineDataCache::ConstIterator it = engineDataCache.begin(), + end = engineDataCache.end(); + for ( ; it != end; ++it ) { +#ifdef TQFONTCACHE_DEBUG + FC_DEBUG( " %p: ref %2d", it.data(), it.data()->count ); + +# if defined(TQ_WS_X11) || defined(TQ_WS_WIN) + // print out all engines + for ( int i = 0; i < TQFont::LastPrivateScript; ++i ) { + if ( ! it.data()->engines[i] ) continue; + FC_DEBUG( " contains %p", it.data()->engines[i] ); + } +# endif // TQ_WS_X11 || TQ_WS_WIN +#endif // TQFONTCACHE_DEBUG + + if ( it.data()->count > 0 ) + in_use_cost += engine_data_cost; + } + } + + { + FC_DEBUG( " SWEEP engine:" ); + + EngineCache::ConstIterator it = engineCache.begin(), + end = engineCache.end(); + for ( ; it != end; ++it ) { + FC_DEBUG( " %p: timestamp %4u hits %2u ref %2d/%2d, cost %u bytes", + it.data().data, it.data().timestamp, it.data().hits, + it.data().data->count, it.data().data->cache_count, + it.data().data->cache_cost ); + + if ( it.data().data->count > 0 ) + in_use_cost += it.data().data->cache_cost / it.data().data->cache_count; + } + + // attempt to make up for rounding errors + in_use_cost += (uint)engineCache.count(); + } + + in_use_cost = ( in_use_cost + 512 ) / 1024; // cost is stored in kb + + /* + calculate the new maximum cost for the cache + + NOTE: in_use_cost is *not* correct due to rounding errors in the + above algorithm. instead of worrying about getting the + calculation correct, we are more interested in speed, and use + in_use_cost as a floor for new_max_cost + */ + uint new_max_cost = TQMAX( TQMAX( max_cost / 2, in_use_cost ), min_cost ); + + FC_DEBUG( " after sweep, in use %u kb, total %u kb, max %u kb, new max %u kb", + in_use_cost, total_cost, max_cost, new_max_cost ); + + if ( new_max_cost == max_cost ) { + if ( fast ) { + FC_DEBUG( " cannot shrink cache, slowing timer" ); + + killTimer( timer_id ); + timer_id = startTimer( slow_timeout ); + fast = FALSE; + } + + return; + } else if ( ! fast ) { + FC_DEBUG( " dropping into passing gear" ); + + killTimer( timer_id ); + timer_id = startTimer( fast_timeout ); + fast = TRUE; + } + + max_cost = new_max_cost; + + { + FC_DEBUG( " CLEAN engine data:" ); + + // clean out all unused engine datas + EngineDataCache::Iterator it = engineDataCache.begin(), + end = engineDataCache.end(); + while ( it != end ) { + if ( it.data()->count > 0 ) { + ++it; + continue; + } + + EngineDataCache::Iterator rem = it++; + + decreaseCost( sizeof( TQFontEngineData ) ); + + FC_DEBUG( " %p", rem.data() ); + + delete rem.data(); + engineDataCache.remove( rem ); + } + } + + // clean out the engine cache just enough to get below our new max cost + uint current_cost; + do { + current_cost = total_cost; + + EngineCache::Iterator it = engineCache.begin(), + end = engineCache.end(); + // determine the oldest and least popular of the unused engines + uint oldest = ~0; + uint least_popular = ~0; + + for ( ; it != end; ++it ) { + if ( it.data().data->count > 0 ) continue; + + if ( it.data().timestamp < oldest && + it.data().hits <= least_popular ) { + oldest = it.data().timestamp; + least_popular = it.data().hits; + } + } + + FC_DEBUG( " oldest %u least popular %u", oldest, least_popular ); + + for ( it = engineCache.begin(); it != end; ++it ) { + if ( it.data().data->count == 0 && + it.data().timestamp == oldest && + it.data().hits == least_popular) + break; + } + + if ( it != end ) { + FC_DEBUG( " %p: timestamp %4u hits %2u ref %2d/%2d, type '%s'", + it.data().data, it.data().timestamp, it.data().hits, + it.data().data->count, it.data().data->cache_count, + it.data().data->name() ); + + if ( --it.data().data->cache_count == 0 ) { + FC_DEBUG( " DELETE: last occurence in cache" ); + + decreaseCost( it.data().data->cache_cost ); + delete it.data().data; + } else { + /* + this particular font engine is in the cache multiple + times... set current_cost to zero, so that we can + keep looping to get rid of all occurences + */ + current_cost = 0; + } + + engineCache.remove( it ); + } + } while ( current_cost != total_cost && total_cost > max_cost ); +} diff --git a/src/kernel/tqfont.h b/src/kernel/tqfont.h new file mode 100644 index 000000000..43256972b --- /dev/null +++ b/src/kernel/tqfont.h @@ -0,0 +1,365 @@ +/**************************************************************************** +** +** Definition of TQFont class +** +** Created : 940514 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef TQFONT_H +#define TQFONT_H + +#ifndef QT_H +#include "ntqwindowdefs.h" +#include "tqstring.h" +#endif // QT_H + + +class TQFontPrivate; /* don't touch */ +class TQStringList; +class TQTextFormatCollection; + +class TQ_EXPORT TQFont +{ +public: + enum StyleHint { + Helvetica, SansSerif = Helvetica, + Times, Serif = Times, + Courier, TypeWriter = Courier, + OldEnglish, Decorative = OldEnglish, + System, + AnyStyle + }; + + enum StyleStrategy { + PreferDefault = 0x0001, + PreferBitmap = 0x0002, + PreferDevice = 0x0004, + PreferOutline = 0x0008, + ForceOutline = 0x0010, + PreferMatch = 0x0020, + PreferQuality = 0x0040, + PreferAntialias = 0x0080, + NoAntialias = 0x0100, + OpenGLCompatible = 0x0200 + }; + + enum Weight { + Light = 25, + Normal = 50, + DemiBold = 63, + Bold = 75, + Black = 87 + }; + + enum Stretch { + UltraCondensed = 50, + ExtraCondensed = 62, + Condensed = 75, + SemiCondensed = 87, + Unstretched = 100, + SemiExpanded = 112, + Expanded = 125, + ExtraExpanded = 150, + UltraExpanded = 200 + }; + + // default font + TQFont(); + // specific font +#ifdef Q_QDOC + TQFont( const TQString &family, int pointSize = 12, int weight = Normal, + bool italic = FALSE ); +#else + TQFont( const TQString &family, int pointSize = -1, int weight = -1, + bool italic = FALSE ); +#endif + // copy constructor + TQFont( const TQFont & ); + + ~TQFont(); + + TQString family() const; + void setFamily( const TQString &); + + int pointSize() const; + float pointSizeFloat() const; + void setPointSize( int ); + void setPointSizeFloat( float ); + + int pixelSize() const; + void setPixelSize( int ); + void setPixelSizeFloat( float ); + + int weight() const; + void setWeight( int ); + + bool bold() const; + void setBold( bool ); + + bool italic() const; + void setItalic( bool ); + + bool underline() const; + void setUnderline( bool ); + + bool overline() const; + void setOverline( bool ); + + bool strikeOut() const; + void setStrikeOut( bool ); + + bool fixedPitch() const; + void setFixedPitch( bool ); + + StyleHint styleHint() const; + StyleStrategy styleStrategy() const; + void setStyleHint( StyleHint, StyleStrategy = PreferDefault ); + void setStyleStrategy( StyleStrategy s ); + + int stretch() const; + void setStretch( int ); + + // is raw mode still needed? + bool rawMode() const; + void setRawMode( bool ); + + // dupicated from TQFontInfo + bool exactMatch() const; + + TQFont &operator=( const TQFont & ); + bool operator==( const TQFont & ) const; + bool operator!=( const TQFont & ) const; + bool isCopyOf( const TQFont & ) const; + + +#ifdef TQ_WS_WIN + HFONT handle() const; +#else // !TQ_WS_WIN + TQt::HANDLE handle() const; +#endif // TQ_WS_WIN + + + // needed for X11 + void setRawName( const TQString & ); + TQString rawName() const; + + TQString key() const; + + TQString toString() const; + bool fromString(const TQString &); + +#ifndef TQT_NO_STRINGLIST + static TQString substitute(const TQString &); + static TQStringList substitutes(const TQString &); + static TQStringList substitutions(); + static void insertSubstitution(const TQString&, const TQString &); + static void insertSubstitutions(const TQString&, const TQStringList &); + static void removeSubstitution(const TQString &); +#endif //TQT_NO_STRINGLIST + static void initialize(); + static void cleanup(); + static void cacheStatistics(); + + // a copy of this lives in qunicodetables.cpp, as we can't include + // tqfont.h it in tools/. Do not modify without changing the script + // enum in qunicodetable_p.h aswell. + enum Script { + // European Alphabetic Scripts + Latin, + Greek, + Cyrillic, + Armenian, + Georgian, + Runic, + Ogham, + SpacingModifiers, + CombiningMarks, + + // Middle Eastern Scripts + Hebrew, + Arabic, + Syriac, + Thaana, + + // South and Southeast Asian Scripts + Devanagari, + Bengali, + Gurmukhi, + Gujarati, + Oriya, + Tamil, + Telugu, + Kannada, + Malayalam, + Sinhala, + Thai, + Lao, + Tibetan, + Myanmar, + Khmer, + + // East Asian Scripts + Han, + Hiragana, + Katakana, + Hangul, + Bopomofo, + Yi, + + // Additional Scripts + Ethiopic, + Cherokee, + CanadianAboriginal, + Mongolian, + + // Symbols + CurrencySymbols, + LetterlikeSymbols, + NumberForms, + MathematicalOperators, + TechnicalSymbols, + GeometricSymbols, + MiscellaneousSymbols, + EnclosedAndSquare, + Braille, + + Unicode, + + // some scripts added in Unicode 3.2 + Tagalog, + Hanunoo, + Buhid, + Tagbanwa, + + KatakanaHalfWidth, + + // from Unicode 4.0 + Limbu, + TaiLe, + + // End +#if !defined(Q_QDOC) + NScripts, + UnknownScript = NScripts, + + NoScript, + + // ---------------------------------------- + // Dear User, you can see values > NScript, + // but they are internal - do not touch. + + Han_Japanese, + Han_SimplifiedChinese, + Han_TraditionalChinese, + Han_Korean, + + LastPrivateScript +#endif + }; + + TQString defaultFamily() const; + TQString lastResortFamily() const; + TQString lastResortFont() const; + +#ifndef TQT_NO_COMPAT + + static TQFont defaultFont(); + static void setDefaultFont( const TQFont & ); + +#endif // TQT_NO_COMPAT + + TQFont resolve( const TQFont & ) const; + +protected: + // why protected? + bool dirty() const; + int deciPointSize() const; + +private: + TQFont( TQFontPrivate *, TQPaintDevice *pd ); + + void detach(); + +#if defined(TQ_WS_MAC) + void macSetFont(TQPaintDevice *); +#elif defined(TQ_WS_X11) + void x11SetScreen( int screen = -1 ); + int x11Screen() const; +#endif + + friend class TQFontMetrics; + friend class TQFontInfo; + friend class TQPainter; + friend class TQPSPrinterFont; + friend class TQApplication; + friend class TQWidget; + friend class TQTextFormatCollection; + friend class TQTextLayout; + friend class TQTextItem; + friend class TQGLContext; +#if defined(TQ_WS_X11) && !defined(TQT_NO_XFTFREETYPE) + friend TQt::HANDLE qt_xft_handle(const TQFont &font); +#endif +#ifndef TQT_NO_DATASTREAM + friend TQ_EXPORT TQDataStream &operator<<( TQDataStream &, const TQFont & ); + friend TQ_EXPORT TQDataStream &operator>>( TQDataStream &, TQFont & ); +#endif + + TQFontPrivate *d; +}; + + +inline bool TQFont::bold() const +{ return weight() > Normal; } + + +inline void TQFont::setBold( bool enable ) +{ setWeight( enable ? Bold : Normal ); } + + + + +/***************************************************************************** + TQFont stream functions + *****************************************************************************/ + +#ifndef TQT_NO_DATASTREAM +TQ_EXPORT TQDataStream &operator<<( TQDataStream &, const TQFont & ); +TQ_EXPORT TQDataStream &operator>>( TQDataStream &, TQFont & ); +#endif + + +#endif // TQFONT_H diff --git a/src/kernel/tqfont_x11.cpp b/src/kernel/tqfont_x11.cpp new file mode 100644 index 000000000..9acbddd59 --- /dev/null +++ b/src/kernel/tqfont_x11.cpp @@ -0,0 +1,738 @@ +/**************************************************************************** +** +** Implementation of TQFont, TQFontMetrics and TQFontInfo classes for X11 +** +** Created : 940515 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#define QT_FATAL_ASSERT + +// REVISED: brad + +#include "qplatformdefs.h" + +#include "tqfont.h" +#include "ntqapplication.h" +#include "ntqcleanuphandler.h" +#include "tqfontinfo.h" +#include "tqfontdatabase.h" +#include "tqfontmetrics.h" +#include "tqpaintdevice.h" +#include "tqpaintdevicemetrics.h" +#include "tqtextcodec.h" + +#include +#include +#include "tqfontdata_p.h" +#include "tqfontengine_p.h" +#include "tqtextengine_p.h" + +#include "qt_x11_p.h" + +#include +#include +#include + +#define TQFONTLOADER_DEBUG +#define TQFONTLOADER_DEBUG_VERBOSE + +TQ_EXPORT bool tqt_has_xft = FALSE; + +#ifndef TQT_NO_XFTFREETYPE +TQt::HANDLE qt_xft_handle(const TQFont &font) +{ + TQFontEngine *engine = font.d->engineForScript( TQFontPrivate::defaultScript ); + if (engine->type() != TQFontEngine::Xft) + return 0; + return (long)static_cast(engine)->font(); +} +#endif + +double qt_pixelSize(double pointSize, TQPaintDevice *paintdevice, int scr) +{ + if (pointSize < 0) return -1.; + + double result = pointSize; + if (paintdevice && TQPaintDeviceMetrics( paintdevice ).logicalDpiY() != 75) + result *= TQPaintDeviceMetrics( paintdevice ).logicalDpiY() / 72.; + else if (TQPaintDevice::x11AppDpiY( scr ) != 75) + result *= TQPaintDevice::x11AppDpiY( scr ) / 72.; + + return result; +} + +double qt_pointSize(double pixelSize, TQPaintDevice *paintdevice, int scr) +{ + if (pixelSize < 0) return -1.; + + double result = pixelSize; + if ( paintdevice && TQPaintDeviceMetrics( paintdevice ).logicalDpiY() != 75) + result *= 72. / TQPaintDeviceMetrics( paintdevice ).logicalDpiY(); + else if (TQPaintDevice::x11AppDpiY(scr) != 75) + result *= 72. / TQPaintDevice::x11AppDpiY( scr ); + + return result; +} + +static inline double pixelSize( const TQFontDef &request, TQPaintDevice *paintdevice, + int scr ) +{ + return ((request.pointSize != -1) ? + qt_pixelSize(request.pointSize / 10., paintdevice, scr) : + (double)request.pixelSize); +} + +static inline double pointSize( const TQFontDef &request, TQPaintDevice *paintdevice, + int scr ) +{ + return ((request.pixelSize != -1) ? + qt_pointSize(request.pixelSize, paintdevice, scr) * 10.: + (double)request.pointSize); +} + + +/* + Removes wildcards from an XLFD. + + Returns \a xlfd with all wildcards removed if a match for \a xlfd is + found, otherwise it returns \a xlfd. +*/ +static TQCString qt_fixXLFD( const TQCString &xlfd ) +{ + TQCString ret = xlfd; + int count = 0; + char **fontNames = + XListFonts( TQPaintDevice::x11AppDisplay(), xlfd, 32768, &count ); + if ( count > 0 ) + ret = fontNames[0]; + XFreeFontNames( fontNames ); + return ret ; +} + +typedef TQMap FallbackMap; +static FallbackMap *fallbackMap = 0; +static TQSingleCleanupHandler qt_fallback_font_family_cleanup; + +static void ensure_fallback_map() +{ + if ( fallbackMap ) return; + fallbackMap = new FallbackMap; + qt_fallback_font_family_cleanup.set( &fallbackMap ); +} + +// Returns the user-configured fallback family for the specified script. +TQString qt_fallback_font_family( TQFont::Script script ) +{ + TQString ret; + + if ( fallbackMap ) { + FallbackMap::ConstIterator it, end = fallbackMap->end(); + it = fallbackMap->find( script ); + if ( it != end ) + ret = it.data(); + } + + return ret; +} + +// Sets the fallback family for the specified script. +void qt_set_fallback_font_family( TQFont::Script script, const TQString &family ) +{ + ensure_fallback_map(); + + if ( ! family.isEmpty() ) + fallbackMap->insert( script, family ); + else + fallbackMap->remove( script ); +} + + +TQFont::Script TQFontPrivate::defaultScript = TQFont::UnknownScript; +int TQFontPrivate::defaultEncodingID = -1; + +/*! + Internal function that initializes the font system. + + \internal + The font cache and font dict do not alloc the keys. The key is a TQString + which is shared between TQFontPrivate and TQXFontName. +*/ +void TQFont::initialize() +{ + // create global font cache + if ( ! TQFontCache::instance ) (void) new TQFontCache; + +#ifndef TQT_NO_CODECS +#ifndef TQT_NO_BIG_CODECS + static bool codecs_once = FALSE; + if ( ! codecs_once ) { + (void) new TQFontJis0201Codec; + (void) new TQFontJis0208Codec; + (void) new TQFontKsc5601Codec; + (void) new TQFontGb2312Codec; + (void) new TQFontGbkCodec; + (void) new TQFontGb18030_0Codec; + (void) new TQFontBig5Codec; + (void) new TQFontBig5hkscsCodec; + (void) new TQFontLaoCodec; + codecs_once = TRUE; + } +#endif // TQT_NO_BIG_CODECS +#endif // TQT_NO_CODECS + + extern int qt_encoding_id_for_mib( int mib ); // from tqfontdatabase_x11.cpp + TQTextCodec *codec = TQTextCodec::codecForLocale(); + // determine the default encoding id using the locale, otherwise + // fallback to latin1 ( mib == 4 ) + int mib = codec ? codec->mibEnum() : 4; + + // for asian locales, use the mib for the font codec instead of the locale codec + switch (mib) { + case 38: // eucKR + mib = 36; + break; + + case 2025: // GB2312 + mib = 57; + break; + + case 113: // GBK + mib = -113; + break; + + case 114: // GB18030 + mib = -114; + break; + + case 2026: // Big5 + mib = -2026; + break; + + case 2101: // Big5-HKSCS + mib = -2101; + break; + + case 16: // JIS7 + mib = 15; + break; + + case 17: // SJIS + case 18: // eucJP + mib = 63; + break; + } + + // get the default encoding id for the locale encoding... + TQFontPrivate::defaultEncodingID = qt_encoding_id_for_mib( mib ); + + // get some sample text based on the users locale. we use this to determine the + // default script for the font system + TQCString oldlctime = setlocale(LC_TIME, 0); + TQCString lctime = setlocale(LC_TIME, ""); + + time_t ttmp = time(0); + struct tm *tt = 0; + char samp[64]; + TQString sample; + + if ( ttmp != -1 ) { +#if defined(TQT_THREAD_SUPPORT) && defined(_POSIX_THREAD_SAFE_FUNCTIONS) + // use the reentrant versions of localtime() where available + tm res; + tt = localtime_r( &ttmp, &res ); +#else + tt = localtime( &ttmp ); +#endif // TQT_THREAD_SUPPORT && _POSIX_THREAD_SAFE_FUNCTIONS + + if ( tt != 0 && strftime( samp, 64, "%A%B", tt ) > 0 ) + if ( codec ) + sample = codec->toUnicode( samp ); + } + + if ( ! sample.isNull() && ! sample.isEmpty() ) { + TQFont::Script cs = TQFont::NoScript, tmp; + const TQChar *uc = sample.unicode(); + TQFontPrivate *priv = new TQFontPrivate; + + for ( uint i = 0; i < sample.length(); i++ ) { + SCRIPT_FOR_CHAR( tmp, *uc ); + uc++; + if ( tmp != cs && tmp != TQFont::UnknownScript ) { + cs = tmp; + break; + } + } + delete priv; + + if ( cs != TQFont::UnknownScript ) + TQFontPrivate::defaultScript = cs; + } + + setlocale( LC_TIME, oldlctime.data() ); +} + +/*! \internal + + Internal function that cleans up the font system. +*/ +void TQFont::cleanup() +{ + // delete the global font cache + delete TQFontCache::instance; + TQFontCache::instance = 0; +} + +/*! + \internal + X11 Only: Returns the screen with which this font is associated. +*/ +int TQFont::x11Screen() const +{ + return d->screen; +} + +/*! \internal + X11 Only: Associate the font with the specified \a screen. +*/ +void TQFont::x11SetScreen( int screen ) +{ + if ( screen < 0 ) // assume default + screen = TQPaintDevice::x11AppScreen(); + + if ( screen == d->screen ) + return; // nothing to do + + detach(); + d->screen = screen; +} + +/*! \internal + Returns a TQFontEngine for the specified \a script that matches the + TQFontDef \e request member variable. +*/ +void TQFontPrivate::load( TQFont::Script script ) +{ + // NOTE: the X11 and Windows implementations of this function are + // identical... if you change one, change both. + +#ifdef QT_CHECK_STATE + // sanity checks + if (!TQFontCache::instance) + tqWarning("Must construct a TQApplication before a TQFont"); + Q_ASSERT( script >= 0 && script < TQFont::LastPrivateScript ); +#endif // QT_CHECK_STATE + + TQFontDef req = request; + req.pixelSize = tqRound(pixelSize(req, paintdevice, screen)); + req.pointSize = 0; + + if ( ! engineData ) { + TQFontCache::Key key( req, TQFont::NoScript, screen, paintdevice ); + + // look for the requested font in the engine data cache + engineData = TQFontCache::instance->findEngineData( key ); + + if ( ! engineData ) { + // create a new one + engineData = new TQFontEngineData; + TQFontCache::instance->insertEngineData( key, engineData ); + } else { + engineData->ref(); + } + } + + // the cached engineData could have already loaded the engine we want + if ( engineData->engines[script] ) return; + + // load the font + TQFontEngine *engine = 0; + // double scale = 1.0; // ### TODO: fix the scale calculations + + // list of families to try + TQStringList family_list; + + if (!req.family.isEmpty()) { + family_list = TQStringList::split( ',', req.family ); + + // append the substitute list for each family in family_list + TQStringList subs_list; + TQStringList::ConstIterator it = family_list.begin(), end = family_list.end(); + for ( ; it != end; ++it ) + subs_list += TQFont::substitutes( *it ); + family_list += subs_list; + +#ifndef QT_XFT2 + // with Xft2, we want to use fontconfig to determine better fallbacks, + // otherwise we might run into trouble with default fonts as "serif" + + // append the default fallback font for the specified script + TQString fallback = qt_fallback_font_family( script ); + if ( ! fallback.isEmpty() && ! family_list.contains( fallback ) ) + family_list << fallback; + + // add the default family + TQString defaultFamily = TQApplication::font().family(); + if ( ! family_list.contains( defaultFamily ) ) + family_list << defaultFamily; + + // add TQFont::defaultFamily() to the list, for compatibility with + // previous versions + family_list << TQApplication::font().defaultFamily(); +#endif // QT_XFT2 + } + + // null family means find the first font matching the specified script + family_list << TQString::null; + + TQStringList::ConstIterator it = family_list.begin(), end = family_list.end(); + for ( ; ! engine && it != end; ++it ) { + req.family = *it; + + engine = TQFontDatabase::findFont( script, this, req ); + if ( engine ) { + if ( engine->type() != TQFontEngine::Box ) + break; + + if ( ! req.family.isEmpty() ) + engine = 0; + + continue; + } + } + + engine->ref(); + engineData->engines[script] = engine; +} + +/*! + Returns TRUE if the font attributes have been changed and the font + has to be (re)loaded; otherwise returns FALSE. +*/ +bool TQFont::dirty() const +{ + return d->engineData == 0; +} + +/*! + Returns the window system handle to the font, for low-level + access. Using this function is \e not portable. +*/ +TQt::HANDLE TQFont::handle() const +{ + TQFontEngine *engine = d->engineForScript( TQFontPrivate::defaultScript ); +#ifdef QT_CHECK_STATE + Q_ASSERT( engine != 0 ); +#endif // QT_CHECK_STATE + + switch ( engine->type() ) { + case TQFontEngine::XLFD: + return ((TQFontEngineXLFD *) engine)->handle(); + case TQFontEngine::LatinXLFD: + return ((TQFontEngineLatinXLFD *) engine)->handle(); + + default: break; + } + return 0; +} + +/*! + Returns the name of the font within the underlying window system. + + On Windows, this is usually just the family name of a TrueType + font. + + On X11, it is an XLFD (X Logical Font Description). When TQt is + build with Xft support on X11, the return value can be an Xft + pattern or an XLFD. + + Using the return value of this function is usually \e not \e + portable. + + \sa setRawName() +*/ +TQString TQFont::rawName() const +{ + TQFontEngine *engine = d->engineForScript( TQFontPrivate::defaultScript ); +#ifdef QT_CHECK_STATE + Q_ASSERT( engine != 0 ); +#endif // QT_CHECK_STATE + + return TQString::fromLatin1( engine->name() ); +} + +/*! + Sets a font by its system specific name. The function is + particularly useful under X, where system font settings (for + example X resources) are usually available in XLFD (X Logical Font + Description) form only. You can pass an XLFD as \a name to this + function. + + A font set with setRawName() is still a full-featured TQFont. It can + be queried (for example with italic()) or modified (for example with + setItalic()) and is therefore also suitable for rendering rich text. + + If TQt's internal font database cannot resolve the raw name, the + font becomes a raw font with \a name as its family. + + Note that the present implementation does not handle wildcards in + XLFDs well, and that font aliases (file \c fonts.alias in the font + directory on X11) are not supported. + + \sa rawName(), setRawMode(), setFamily() +*/ +void TQFont::setRawName( const TQString &name ) +{ + detach(); + + // from tqfontdatabase_x11.cpp + extern bool qt_fillFontDef( const TQCString &xlfd, TQFontDef *fd, int screen ); + + if ( ! qt_fillFontDef( qt_fixXLFD( name.latin1() ), &d->request, d->screen ) ) { +#ifdef QT_CHECK_STATE + tqWarning("TQFont::setRawName(): Invalid XLFD: \"%s\"", name.latin1()); +#endif // QT_CHECK_STATE + + setFamily( name ); + setRawMode( TRUE ); + } else { + d->mask = TQFontPrivate::Complete; + } +} + +/*! + Returns the "last resort" font family name. + + The current implementation tries a wide variety of common fonts, + returning the first one it finds. Is is possible that no family is + found in which case a null string is returned. + + \sa lastResortFont() +*/ +TQString TQFont::lastResortFamily() const +{ + return TQString::fromLatin1( "Helvetica" ); +} + +/*! + Returns the family name that corresponds to the current style + hint. + + \sa StyleHint styleHint() setStyleHint() +*/ +TQString TQFont::defaultFamily() const +{ + switch ( d->request.styleHint ) { + case TQFont::Times: + return TQString::fromLatin1( "Times" ); + + case TQFont::Courier: + return TQString::fromLatin1( "Courier" ); + + case TQFont::Decorative: + return TQString::fromLatin1( "Old English" ); + + case TQFont::Helvetica: + case TQFont::System: + default: + return TQString::fromLatin1( "Helvetica" ); + } +} + +/* + Returns a last resort raw font name for the font matching algorithm. + This is used if even the last resort family is not available. It + returns \e something, almost no matter what. The current + implementation tries a wide variety of common fonts, returning the + first one it finds. The implementation may change at any time. +*/ +static const char * const tryFonts[] = { + "-*-helvetica-medium-r-*-*-*-120-*-*-*-*-*-*", + "-*-courier-medium-r-*-*-*-120-*-*-*-*-*-*", + "-*-times-medium-r-*-*-*-120-*-*-*-*-*-*", + "-*-lucida-medium-r-*-*-*-120-*-*-*-*-*-*", + "-*-helvetica-*-*-*-*-*-120-*-*-*-*-*-*", + "-*-courier-*-*-*-*-*-120-*-*-*-*-*-*", + "-*-times-*-*-*-*-*-120-*-*-*-*-*-*", + "-*-lucida-*-*-*-*-*-120-*-*-*-*-*-*", + "-*-helvetica-*-*-*-*-*-*-*-*-*-*-*-*", + "-*-courier-*-*-*-*-*-*-*-*-*-*-*-*", + "-*-times-*-*-*-*-*-*-*-*-*-*-*-*", + "-*-lucida-*-*-*-*-*-*-*-*-*-*-*-*", + "-*-fixed-*-*-*-*-*-*-*-*-*-*-*-*", + "6x13", + "7x13", + "8x13", + "9x15", + "fixed", + 0 +}; + +// Returns TRUE if the font exists, FALSE otherwise +static bool fontExists( const TQString &fontName ) +{ + int count; + char **fontNames = XListFonts( TQPaintDevice::x11AppDisplay(), + (char*)fontName.latin1(), 32768, &count ); + if ( fontNames ) XFreeFontNames( fontNames ); + + return count != 0; +} + +/*! + Returns a "last resort" font name for the font matching algorithm. + This is used if the last resort family is not available. It will + always return a name, if necessary returning something like + "fixed" or "system". + + The current implementation tries a wide variety of common fonts, + returning the first one it finds. The implementation may change + at any time, but this function will always return a string + containing something. + + It is theoretically possible that there really isn't a + lastResortFont() in which case TQt will abort with an error + message. We have not been able to identify a case where this + happens. Please \link bughowto.html report it as a bug\endlink if + it does, preferably with a list of the fonts you have installed. + + \sa lastResortFamily() rawName() +*/ +TQString TQFont::lastResortFont() const +{ + static TQString last; + + // already found + if ( ! last.isNull() ) + return last; + + int i = 0; + const char* f; + + while ( ( f = tryFonts[i] ) ) { + last = TQString::fromLatin1( f ); + + if ( fontExists( last ) ) + return last; + + i++; + } + +#if defined(CHECK_NULL) + tqFatal( "TQFontPrivate::lastResortFont: Cannot find any reasonable font" ); +#endif + + return last; +} + + + + +// ********************************************************************** +// TQFontMetrics member methods +// ********************************************************************** + +int TQFontMetrics::width( TQChar ch ) const +{ + unsigned short uc = ch.unicode(); + if ( uc < TQFontEngineData::widthCacheSize && + d->engineData && d->engineData->widthCache[ uc ] ) + return d->engineData->widthCache[ uc ]; + + if ( ::category( ch ) == TQChar::Mark_NonSpacing || qIsZeroWidthChar(ch.unicode())) + return 0; + + TQFont::Script script; + SCRIPT_FOR_CHAR( script, ch ); + + TQFontEngine *engine = d->engineForScript( script ); +#ifdef QT_CHECK_STATE + Q_ASSERT( engine != 0 ); +#endif // QT_CHECK_STATE + + glyph_t glyphs[8]; + advance_t advances[8]; + int nglyphs = 7; + engine->stringToCMap( &ch, 1, glyphs, advances, &nglyphs, FALSE ); + + // ### can nglyphs != 1 happen at all? Not currently I think + if ( uc < TQFontEngineData::widthCacheSize && advances[0] > 0 && advances[0] < 0x100 ) + d->engineData->widthCache[ uc ] = advances[0]; + + return advances[0]; +} + + +int TQFontMetrics::charWidth( const TQString &str, int pos ) const +{ + if ( pos < 0 || pos > (int)str.length() ) + return 0; + + const TQChar &ch = str.unicode()[ pos ]; + if ( ch.unicode() < TQFontEngineData::widthCacheSize && + d->engineData && d->engineData->widthCache[ ch.unicode() ] ) + return d->engineData->widthCache[ ch.unicode() ]; + + TQFont::Script script; + SCRIPT_FOR_CHAR( script, ch ); + + int width; + + if ( script >= TQFont::Arabic && script <= TQFont::Khmer ) { + // complex script shaping. Have to do some hard work + int from = TQMAX( 0, pos - 8 ); + int to = TQMIN( (int)str.length(), pos + 8 ); + TQConstString cstr( str.unicode()+from, to-from); + TQTextEngine layout( cstr.string(), d ); + layout.itemize( TQTextEngine::WidthOnly ); + width = layout.width( pos-from, 1 ); + } else if ( ::category( ch ) == TQChar::Mark_NonSpacing || qIsZeroWidthChar(ch.unicode())) { + width = 0; + } else { + TQFontEngine *engine = d->engineForScript( script ); +#ifdef QT_CHECK_STATE + Q_ASSERT( engine != 0 ); +#endif // QT_CHECK_STATE + + glyph_t glyphs[8]; + advance_t advances[8]; + int nglyphs = 7; + engine->stringToCMap( &ch, 1, glyphs, advances, &nglyphs, FALSE ); + width = advances[0]; + } + if ( ch.unicode() < TQFontEngineData::widthCacheSize && width > 0 && width < 0x100 ) + d->engineData->widthCache[ ch.unicode() ] = width; + return width; +} diff --git a/src/kernel/tqfontdata_p.h b/src/kernel/tqfontdata_p.h new file mode 100644 index 000000000..6b42c6bcf --- /dev/null +++ b/src/kernel/tqfontdata_p.h @@ -0,0 +1,275 @@ +/**************************************************************************** +** +** Definition of internal TQFontData struct +** +** Created : 941229 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef TQFONTDATA_P_H +#define TQFONTDATA_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the TQt API. It exists for the convenience +// of internal files. This header file may change from version to version +// without notice, or even be removed. +// +// We mean it. +// +// + +#include "tqobject.h" +#include "tqfont.h" +#include "tqpaintdevicemetrics.h" + +// forwards +class TQFontEngine; +class TQPaintDevice; + + +struct TQFontDef +{ + inline TQFontDef() + : pointSize( -1 ), pixelSize( -1 ), + styleHint( TQFont::AnyStyle ), styleStrategy( TQFont::PreferDefault ), + weight( 50 ), italic( FALSE ), fixedPitch( FALSE ), stretch( 100 ), + ignorePitch(TRUE) +#ifdef TQ_WS_MAC + ,fixedPitchComputed(FALSE) +#endif + { + } + + TQString family; + +#ifdef TQ_WS_X11 + TQString addStyle; +#endif // TQ_WS_X11 + + int pointSize; + int pixelSize; + + uint styleHint : 8; + uint styleStrategy : 16; + + uint weight : 7; // 0-99 + uint italic : 1; + uint fixedPitch : 1; + uint stretch : 12; // 0-400 + + uint ignorePitch : 1; + uint fixedPitchComputed : 1; // for Mac OS X only + uint reserved : 14; // for future extensions + + bool operator==( const TQFontDef &other ) const; + inline bool operator<( const TQFontDef &other ) const + { + if ( pixelSize != other.pixelSize ) return pixelSize < other.pixelSize; + if ( weight != other.weight ) return weight < other.weight; + if ( italic != other.italic ) return italic < other.italic; + if ( stretch != other.stretch ) return stretch < other.stretch; + if ( styleHint != other.styleHint ) return styleHint < other.styleHint; + if ( styleStrategy != other.styleStrategy ) return styleStrategy < other.styleStrategy; + if ( family != other.family ) return family < other.family; + +#ifdef TQ_WS_X11 + if ( addStyle != other.addStyle ) return addStyle < other.addStyle; +#endif // TQ_WS_X11 + + return FALSE; + } +}; + +class TQFontEngineData : public TQShared +{ +public: + TQFontEngineData(); + ~TQFontEngineData(); + + uint lineWidth; + +#if defined(TQ_WS_X11) || defined(TQ_WS_WIN) + TQFontEngine *engines[TQFont::LastPrivateScript]; +#else + TQFontEngine *engine; +#endif // TQ_WS_X11 || TQ_WS_WIN +#ifndef TQ_WS_MAC + enum { widthCacheSize = 0x500 }; + uchar widthCache[widthCacheSize]; +#endif +}; + + +class TQFontPrivate : public TQShared +{ +public: + static TQFont::Script defaultScript; +#ifdef TQ_WS_X11 + static int defaultEncodingID; +#endif // TQ_WS_X11 + + TQFontPrivate(); + TQFontPrivate( const TQFontPrivate &other ); + ~TQFontPrivate(); + + void load( TQFont::Script script ); + TQFontEngine *engineForScript( TQFont::Script script ) const { + if ( script == TQFont::NoScript ) + script = TQFontPrivate::defaultScript; +#if defined(TQ_WS_X11) || defined(TQ_WS_WIN) + if ( ! engineData || ! engineData->engines[script] ) + ((TQFontPrivate *) this)->load( script ); + return engineData->engines[script]; +#else + if ( ! engineData || ! engineData->engine ) + ((TQFontPrivate *) this)->load( script ); + return engineData->engine; +#endif // TQ_WS_X11 || TQ_WS_WIN + } + + TQFontDef request; + TQFontEngineData *engineData; + TQPaintDevice *paintdevice; + int screen; + + uint rawMode : 1; + uint underline : 1; + uint overline : 1; + uint strikeOut : 1; + + enum { + Family = 0x0001, + Size = 0x0002, + StyleHint = 0x0004, + StyleStrategy = 0x0008, + Weight = 0x0010, + Italic = 0x0020, + Underline = 0x0040, + Overline = 0x0080, + StrikeOut = 0x0100, + FixedPitch = 0x0200, + Stretch = 0x0400, + Complete = 0x07ff + }; + + uint mask; + + void resolve( const TQFontPrivate *other ); +}; + + +class TQFontCache : public TQObject +{ +public: + static TQFontCache *instance; + + TQFontCache(); + ~TQFontCache(); + + // universal key structure. TQFontEngineDatas and TQFontEngines are cached using + // the same keys + struct Key { + Key() : script(0), screen( 0 ), dpi(0) { } + Key( const TQFontDef &d, TQFont::Script c, int s, TQPaintDevice *pdev ) + : script(c), screen(s) { + def = d; +#ifdef TQ_WS_X11 + dpi = pdev ? TQPaintDeviceMetrics(pdev).logicalDpiY() : 0; +#else + Q_UNUSED(pdev); + dpi = 0; +#endif + } + + TQFontDef def; + int script; + int screen; + int dpi; + + inline bool operator<( const Key &other ) const + { + if ( script != other.script ) return script < other.script; + if ( screen != other.screen ) return screen < other.screen; + if ( dpi != other.dpi ) return dpi < other.dpi; + return def < other.def; + } + inline bool operator==( const Key &other ) const + { return def == other.def && script == other.script && + screen == other.screen && dpi == other.dpi; } + }; + + // TQFontEngineData cache + typedef TQMap EngineDataCache; + EngineDataCache engineDataCache; + + TQFontEngineData *findEngineData( const Key &key ) const; + void insertEngineData( const Key &key, TQFontEngineData *engineData ); + + // TQFontEngine cache + struct Engine { + Engine() : data( 0 ), timestamp( 0 ), hits( 0 ) { } + Engine( TQFontEngine *d ) : data( d ), timestamp( 0 ), hits( 0 ) { } + + TQFontEngine *data; + uint timestamp; + uint hits; + }; + + typedef TQMap EngineCache; + EngineCache engineCache; + + TQFontEngine *findEngine( const Key &key ); + void insertEngine( const Key &key, TQFontEngine *engine ); + +#if defined(TQ_WS_WIN) + void cleanupPrinterFonts(); +#endif + + private: + void increaseCost( uint cost ); + void decreaseCost( uint cost ); + void timerEvent( TQTimerEvent *event ); + + static const uint min_cost; + uint total_cost, max_cost; + uint current_timestamp; + bool fast; + int timer_id; +}; + +#endif // TQFONTDATA_P_H diff --git a/src/kernel/tqfontdatabase.cpp b/src/kernel/tqfontdatabase.cpp new file mode 100644 index 000000000..56c1a9ed7 --- /dev/null +++ b/src/kernel/tqfontdatabase.cpp @@ -0,0 +1,2489 @@ +/**************************************************************************** +** +** Implementation of font database class. +** +** Created : 990603 +** +** Copyright (C) 1999-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#include "tqfontdatabase.h" + +#ifndef TQT_NO_FONTDATABASE + +#include +#include + +#include +#include "tqfontengine_p.h" + +#include + +#ifdef TQ_WS_X11 +#include +#endif +#include + +//#define TQFONTDATABASE_DEBUG +#ifdef TQFONTDATABASE_DEBUG +# define FD_DEBUG tqDebug +#else +# define FD_DEBUG if (FALSE) tqDebug +#endif + +//#define FONT_MATCH_DEBUG +#ifdef FONT_MATCH_DEBUG +# define FM_DEBUG tqDebug +#else +# define FM_DEBUG if (FALSE) tqDebug +#endif + +#if defined(Q_CC_MSVC) && !defined(Q_CC_MSVC_NET) +# define for if(0){}else for +#endif + +static int ucstricmp( const TQString &as, const TQString &bs ) +{ + const TQChar *a = as.unicode(); + const TQChar *b = bs.unicode(); + if ( a == b ) + return 0; + if ( a == 0 ) + return 1; + if ( b == 0 ) + return -1; + int l=TQMIN(as.length(),bs.length()); + while ( l-- && ::lower( *a ) == ::lower( *b ) ) + a++,b++; + if ( l==-1 ) + return ( as.length()-bs.length() ); + return ::lower( *a ).unicode() - ::lower( *b ).unicode(); +} + +static int getFontWeight( const TQString &weightString ) +{ + TQString s = weightString.lower(); + + // Test in decreasing order of commonness + if (s == "medium" || + s == "normal") + return TQFont::Normal; + if (s == "bold") + return TQFont::Bold; + if (s == "demibold" || s == "demi bold") + return TQFont::DemiBold; + if (s == "black") + return TQFont::Black; + if (s == "light") + return TQFont::Light; + + if (s.contains("bold")) { + if (s.contains("demi")) + return (int) TQFont::DemiBold; + return (int) TQFont::Bold; + } + + if (s.contains("light")) + return (int) TQFont::Light; + + if (s.contains("black")) + return (int) TQFont::Black; + + return (int) TQFont::Normal; +} + +#ifdef TQ_WS_X11 +struct TQtFontEncoding +{ + signed int encoding : 16; + + uint xpoint : 16; + uint xres : 8; + uint yres : 8; + uint avgwidth : 16; + uchar pitch : 8; +}; +#endif // TQ_WS_X11 + +struct TQtFontSize +{ + unsigned short pixelSize; + +#ifdef TQ_WS_X11 + int count; + TQtFontEncoding *encodings; + TQtFontEncoding *encodingID( int id, uint xpoint = 0, uint xres = 0, + uint yres = 0, uint avgwidth = 0, bool add = FALSE); +#endif // TQ_WS_X11 +}; + + +#ifdef TQ_WS_X11 +TQtFontEncoding *TQtFontSize::encodingID( int id, uint xpoint, uint xres, + uint yres, uint avgwidth, bool add ) +{ + // we don't match using the xpoint, xres and yres parameters, only the id + for ( int i = 0; i < count; ++i ) { + if ( encodings[i].encoding == id ) + return encodings + i; + } + + if ( !add ) return 0; + + if ( !(count % 4) ) + encodings = ( TQtFontEncoding * ) + realloc( encodings, + (((count+4) >> 2 ) << 2 ) * sizeof( TQtFontEncoding ) ); + encodings[count].encoding = id; + encodings[count].xpoint = xpoint; + encodings[count].xres = xres; + encodings[count].yres = yres; + encodings[count].avgwidth = avgwidth; + encodings[count].pitch = '*'; + return encodings + count++; +} +#endif // TQ_WS_X11 + +struct TQtFontStyle +{ + struct Key { + Key( const TQString &styleString ); + Key() : italic( FALSE ), oblique( FALSE ), + weight( TQFont::Normal ), stretch( 0 ) { } + Key( const Key &o ) : italic( o.italic ), oblique( o.oblique ), + weight( o.weight ), stretch( o.stretch ) { } + uint italic : 1; + uint oblique : 1; + signed int weight : 8; + signed int stretch : 12; + + bool operator==( const Key & other ) { + return ( italic == other.italic && + oblique == other.oblique && + weight == other.weight && + (stretch == 0 || other.stretch == 0 || stretch == other.stretch) ); + } + bool operator!=( const Key &other ) { + return !operator==(other); + } + bool operator <( const Key &o ) { + int x = (italic << 13) + (oblique << 12) + (weight << 14) + stretch; + int y = (o.italic << 13) + (o.oblique << 12) + (o.weight << 14) + o.stretch; + return ( x < y ); + } + }; + + TQtFontStyle( const Key &k ) + : key( k ), bitmapScalable( FALSE ), smoothScalable( FALSE ), + fakeOblique( FALSE ), count( 0 ), pixelSizes( 0 ) + { +#if defined(TQ_WS_X11) + weightName = setwidthName = 0; +#endif // TQ_WS_X11 + } + + ~TQtFontStyle() { +#ifdef TQ_WS_X11 + delete [] weightName; + delete [] setwidthName; + while ( count-- ) + free(pixelSizes[count].encodings); +#endif + free( pixelSizes ); + } + + Key key; + bool bitmapScalable : 1; + bool smoothScalable : 1; + bool fakeOblique : 1; + int count : 29; + TQtFontSize *pixelSizes; + +#ifdef TQ_WS_X11 + const char *weightName; + const char *setwidthName; +#endif // TQ_WS_X11 + + TQtFontSize *pixelSize( unsigned short size, bool = FALSE ); +}; + +TQtFontStyle::Key::Key( const TQString &styleString ) + : italic( FALSE ), oblique( FALSE ), weight( TQFont::Normal ), stretch( 0 ) +{ + weight = getFontWeight( styleString ); + + if ( styleString.contains( "Italic" ) ) + italic = TRUE; + else if ( styleString.contains( "Oblique" ) ) + oblique = TRUE; +} + +TQtFontSize *TQtFontStyle::pixelSize( unsigned short size, bool add ) +{ + for ( int i = 0; i < count; i++ ) { + if ( pixelSizes[i].pixelSize == size ) + return pixelSizes + i; + } + if ( !add ) + return 0; + + if ( !(count % 8) ) + pixelSizes = (TQtFontSize *) + realloc( pixelSizes, + (((count+8) >> 3 ) << 3) * sizeof(TQtFontSize) ); + pixelSizes[count].pixelSize = size; +#ifdef TQ_WS_X11 + pixelSizes[count].count = 0; + pixelSizes[count].encodings = 0; +#endif + return pixelSizes + (count++); +} + +struct TQtFontFoundry +{ + TQtFontFoundry( const TQString &n ) : name( n ), count( 0 ), styles( 0 ) {} + ~TQtFontFoundry() { + while ( count-- ) + delete styles[count]; + free( styles ); + } + + TQString name; + + int count; + TQtFontStyle **styles; + TQtFontStyle *style( const TQtFontStyle::Key &, bool = FALSE ); +}; + +TQtFontStyle *TQtFontFoundry::style( const TQtFontStyle::Key &key, bool create ) +{ + int pos = 0; + if ( count ) { + int low = 0; + int high = count; + pos = count / 2; + while ( high > low ) { + if ( styles[pos]->key == key ) + return styles[pos]; + if ( styles[pos]->key < key ) + low = pos + 1; + else + high = pos; + pos = (high + low) / 2; + }; + pos = low; + } + if ( !create ) + return 0; + +// tqDebug("adding key (weight=%d, italic=%d, oblique=%d stretch=%d) at %d", key.weight, key.italic, key.oblique, key.stretch, pos ); + if ( !(count % 8) ) + styles = (TQtFontStyle **) + realloc( styles, (((count+8) >> 3 ) << 3) * sizeof( TQtFontStyle * ) ); + + memmove( styles + pos + 1, styles + pos, (count-pos)*sizeof(TQtFontStyle *) ); + styles[pos] = new TQtFontStyle( key ); + count++; + return styles[pos]; +} + + +struct TQtFontFamily +{ + enum ScriptStatus { Unknown = 0, Supported = 1, + UnSupported_Xft= 2, UnSupported_Xlfd = 4, UnSupported = 6 }; + + TQtFontFamily(const TQString &n ) + : +#ifdef TQ_WS_X11 + fixedPitch( TRUE ), hasXft( FALSE ), xftScriptCheck( FALSE ), xlfdLoaded( FALSE ), synthetic(FALSE), +#else + fixedPitch( FALSE ), +#endif +#ifdef TQ_WS_WIN + scriptCheck( FALSE ), +#endif +#if defined(Q_OS_MAC) + fixedPitchComputed(FALSE), +#endif + fullyLoaded( FALSE ), + name( n ), count( 0 ), foundries( 0 ) { + memset( scripts, 0, sizeof( scripts ) ); + } + ~TQtFontFamily() { + while ( count-- ) + delete foundries[count]; + free( foundries ); + } + + bool fixedPitch : 1; +#ifdef TQ_WS_X11 + bool hasXft : 1; + bool xftScriptCheck : 1; + bool xlfdLoaded : 1; + bool synthetic : 1; +#endif +#ifdef TQ_WS_WIN + bool scriptCheck : 1; +#endif +#if defined(Q_OS_MAC) + bool fixedPitchComputed : 1; +#endif + bool fullyLoaded : 1; + TQString name; + TQString rawName; +#ifdef TQ_WS_X11 + TQCString fontFilename; + int fontFileIndex; +#endif +#ifdef TQ_WS_MAC + FMFontFamily macFamily; +#endif +#ifdef TQ_WS_WIN + TQString english_name; +#endif + int count; + TQtFontFoundry **foundries; + + unsigned char scripts[TQFont::LastPrivateScript]; + + TQtFontFoundry *foundry( const TQString &f, bool = FALSE ); +}; + +TQtFontFoundry *TQtFontFamily::foundry( const TQString &f, bool create ) +{ + if ( f.isNull() && count == 1 ) + return foundries[0]; + + for ( int i = 0; i < count; i++ ) { + if ( ucstricmp( foundries[i]->name, f ) == 0 ) + return foundries[i]; + } + if ( !create ) + return 0; + + if ( !(count % 8) ) + foundries = (TQtFontFoundry **) + realloc( foundries, + (((count+8) >> 3 ) << 3) * sizeof( TQtFontFoundry * ) ); + + foundries[count] = new TQtFontFoundry( f ); + return foundries[count++]; +} + +class TQFontDatabasePrivate { +public: + TQFontDatabasePrivate() : count( 0 ), families( 0 ) { } + ~TQFontDatabasePrivate() { + while ( count-- ) + delete families[count]; + free( families ); + } + TQtFontFamily *family( const TQString &f, bool = FALSE ); + + int count; + TQtFontFamily **families; +}; + +TQtFontFamily *TQFontDatabasePrivate::family( const TQString &f, bool create ) +{ + int low = 0; + int high = count; + int pos = count / 2; + int res = 1; + if ( count ) { + while ( (res = ucstricmp( families[pos]->name, f )) && pos != low ) { + if ( res > 0 ) + high = pos; + else + low = pos; + pos = (high + low) / 2; + }; + if ( !res ) + return families[pos]; + } + if ( !create ) + return 0; + + if ( res < 0 ) + pos++; + + // tqDebug("adding family %s at %d total=%d", f.latin1(), pos, count); + if ( !(count % 8) ) + families = (TQtFontFamily **) + realloc( families, + (((count+8) >> 3 ) << 3) * sizeof( TQtFontFamily * ) ); + + memmove( families + pos + 1, families + pos, (count-pos)*sizeof(TQtFontFamily *) ); + families[pos] = new TQtFontFamily( f ); + count++; + return families[pos]; +} + + + + +#if defined(TQ_WS_X11) || defined(TQ_WS_WIN) +static const unsigned short sample_chars[TQFont::LastPrivateScript][14] = +{ + // European Alphabetic Scripts + // Latin, + { 0x0041, 0x0 }, + // Greek, + { 0x0391, 0x0 }, + // Cyrillic, + { 0x0410, 0x0 }, + // Armenian, + { 0x0540, 0x0 }, + // Georgian, + { 0x10d0, 0x0 }, + // Runic, + { 0x16a0, 0x0 }, + // Ogham, + { 0x1680, 0x0 }, + // SpacingModifiers, + { 0x02c6, 0x0 }, + // CombiningMarks, + { 0x0300, 0x0 }, + + // Middle Eastern Scripts + // Hebrew, + { 0x05d0, 0x0 }, + // Arabic, + { 0x0630, 0x0 }, + // Syriac, + { 0x0710, 0x0 }, + // Thaana, + { 0x0780, 0x0 }, + + // South and Southeast Asian Scripts + // Devanagari, + { 0x0910, 0x0 }, + // Bengali, + { 0x0990, 0x0 }, + // Gurmukhi, + { 0x0a10, 0x0 }, + // Gujarati, + { 0x0a90, 0x0 }, + // Oriya, + { 0x0b10, 0x0 }, + // Tamil, + { 0x0b90, 0x0 }, + // Telugu, + { 0x0c10, 0x0 }, + // Kannada, + { 0x0c90, 0x0 }, + // Malayalam, + { 0x0d10, 0x0 }, + // Sinhala, + { 0x0d90, 0x0 }, + // Thai, + { 0x0e10, 0x0 }, + // Lao, + { 0x0e81, 0x0 }, + // Tibetan, + { 0x0f00, 0x0 }, + // Myanmar, + { 0x1000, 0x0 }, + // Khmer, + { 0x1780, 0x0 }, + + // East Asian Scripts + // Han, + { 0x4e00, 0x0 }, + // Hiragana, + { 0x3050, 0x4e00, 0x25EF, 0x3012, 0x3013, 0x30FB, 0x30FC, 0x5CE0, 0 }, + // Katakana, + { 0x30b0, 0x4e00, 0x25EF, 0x3012, 0x3013, 0x30FB, 0x30FC, 0x5CE0, 0 }, + // Hangul, + { 0xac00, 0x0 }, + // Bopomofo, + { 0x3110, 0x0 }, + // Yi, + { 0xa000, 0x0 }, + + // Additional Scripts + // Ethiopic, + { 0x1200, 0x0 }, + // Cherokee, + { 0x13a0, 0x0 }, + // CanadianAboriginal, + { 0x1410, 0x0 }, + // Mongolian, + { 0x1800, 0x0 }, + + // Symbols + // CurrencySymbols, + { 0x20aa, 0x0 }, + // LetterlikeSymbols, + { 0x2103, 0x0 }, + // NumberForms, + { 0x2160, 0x0 }, + // MathematicalOperators, + { 0x222b, 0x0 }, + // TechnicalSymbols, + { 0x2312, 0x0 }, + // GeometricSymbols, + { 0x2500, 0x0 }, + // MiscellaneousSymbols, + { 0x2640, 0x2714, 0x0 }, + // EnclosedAndSquare, + { 0x2460, 0x0 }, + // Braille, + { 0x2800, 0x0 }, + + // Unicode, + { 0xfffd, 0x0 }, + + // some scripts added in Unicode 3.2 + // Tagalog, + { 0x1700, 0x0 }, + // Hanunoo, + { 0x1720, 0x0 }, + // Buhid, + { 0x1740, 0x0 }, + // Tagbanwa, + { 0x1770, 0x0 }, + + // KatakanaHalfWidth + { 0xff65, 0x0 }, + + // Limbu + { 0x1901, 0x0 }, + // TaiLe + { 0x1950, 0x0 }, + + // NScripts + { 0x0000, 0x0 }, + // NoScript + { 0x0000, 0x0 }, + + // Han_Japanese + { 0x4e00, 0x25EF, 0x3012, 0x3013, 0x30FB, 0x5CE0, 0 }, + // Han_SimplifiedChinese, 0x3400 is optional + { 0x4e00, 0x201C, 0x3002, 0x6237, 0x9555, 0xFFE5, 0 }, + // Han_TraditionalChinese, 0xF6B1 is optional + // OR Han_HongkongChinese, 0x3435, 0xE000, 0xF6B1 are optional + { 0x4e00, 0x201C, 0x3002, 0x6236, 0x9F98, 0xFFE5, 0 }, + // Han_Korean + { 0x4e00, 0 } + // Taiwan would be 0x201C, 0x3002, 0x4E00, 0x9F98, 0xFFE5 +}; + +#if defined(TQ_WS_X11) && !defined(TQT_NO_XFTFREETYPE) +static inline bool requiresOpenType(TQFont::Script s) +{ + return (s >= TQFont::Syriac && s <= TQFont::Sinhala) + || (s >= TQFont::Myanmar && s <= TQFont::Khmer); +} +#endif + +static inline bool canRender( TQFontEngine *fe, TQFont::Script script ) +{ + if ( !fe ) return FALSE; + + bool hasChar = true; + + if (!sample_chars[script][0]) + hasChar = false; + + int i = 0; + while (hasChar && sample_chars[script][i]){ + TQChar sample(sample_chars[script][i]); + if ( !fe->canRender( &sample, 1 ) ) { + hasChar = false; +#ifdef FONT_MATCH_DEBUG + FM_DEBUG(" font has NOT char 0x%04x", sample.unicode() ); + } else { + FM_DEBUG(" font has char 0x%04x", sample.unicode() ); +#endif + } + ++i; + } +#if defined(TQ_WS_X11) && !defined(TQT_NO_XFTFREETYPE) + if (hasChar && requiresOpenType(script)) { + TQOpenType *ot = fe->openType(); + if (!ot || !ot->supportsScript(script)) + return FALSE; + } +#endif + + return hasChar; +} +#endif // TQ_WS_X11 || TQ_WS_WIN + + +static TQSingleCleanupHandler tqfontdatabase_cleanup; +static TQFontDatabasePrivate *db=0; +#define SMOOTH_SCALABLE 0xffff + +#if defined( TQ_WS_X11 ) +# include "tqfontdatabase_x11.cpp" +#elif defined( TQ_WS_MAC ) +# include "tqfontdatabase_mac.cpp" +#elif defined( TQ_WS_WIN ) +# include "tqfontdatabase_win.cpp" +#endif + +static TQtFontStyle *bestStyle(TQtFontFoundry *foundry, const TQtFontStyle::Key &styleKey) +{ + int best = 0; + int dist = 0xffff; + + for ( int i = 0; i < foundry->count; i++ ) { + TQtFontStyle *style = foundry->styles[i]; + + int d = TQABS( styleKey.weight - style->key.weight ); + + if ( styleKey.stretch != 0 && style->key.stretch != 0 ) { + d += TQABS( styleKey.stretch - style->key.stretch ); + } + + if ( styleKey.italic ) { + if ( !style->key.italic ) + d += style->key.oblique ? 0x0001 : 0x1000; + } else if ( styleKey.oblique ) { + if (!style->key.oblique ) + d += style->key.italic ? 0x0001 : 0x1000; + } else if ( style->key.italic || style->key.oblique ) { + d += 0x1000; + } + + if ( d < dist ) { + best = i; + dist = d; + } + } + + FM_DEBUG( " best style has distance 0x%x", dist ); + if (!foundry->count) { + TQtFontStyle *temp = NULL; + return temp; + } + return foundry->styles[best]; +} + +#if defined(TQ_WS_X11) +static TQtFontEncoding *findEncoding(TQFont::Script script, int styleStrategy, + TQtFontSize *size, int force_encoding_id) +{ + TQtFontEncoding *encoding = 0; + + if (force_encoding_id >= 0) { + encoding = size->encodingID(force_encoding_id); + if (!encoding) + FM_DEBUG(" required encoding_id not available"); + return encoding; + } + + if (styleStrategy & (TQFont::OpenGLCompatible | TQFont::PreferBitmap)) { + FM_DEBUG(" PreferBitmap and/or OpenGL set, skipping Xft"); + } else { + encoding = size->encodingID(-1); // -1 == prefer Xft + if (encoding) return encoding; + } + + // Xft not available, find an XLFD font, trying the default encoding first + encoding = size->encodingID(TQFontPrivate::defaultEncodingID); + + if (!encoding || !scripts_for_xlfd_encoding[encoding->encoding][script]) { + // find the first encoding that supports the requested script + encoding = 0; + for (int x = 0; !encoding && x < size->count; ++x) { + const int enc = size->encodings[x].encoding; + if (scripts_for_xlfd_encoding[enc][script]) { + encoding = size->encodings + x; + break; + } + } + } + + return encoding; +} +#endif // TQ_WS_X11 + + +#if defined(TQ_WS_X11) || defined(TQ_WS_WIN) +static +unsigned int bestFoundry( TQFont::Script script, unsigned int score, int styleStrategy, + const TQtFontFamily *family, const TQString &foundry_name, + TQtFontStyle::Key styleKey, int pixelSize, char pitch, + TQtFontFoundry **best_foundry, TQtFontStyle **best_style, + TQtFontSize **best_size +#ifdef TQ_WS_X11 + , TQtFontEncoding **best_encoding, int force_encoding_id +#endif + ) +{ + Q_UNUSED( script ); + Q_UNUSED( pitch ); + + FM_DEBUG( " REMARK: looking for best foundry for family '%s'", family->name.latin1() ); + + for ( int x = 0; x < family->count; ++x ) { + TQtFontFoundry *foundry = family->foundries[x]; + if ( ! foundry_name.isEmpty() && + ucstricmp( foundry->name, foundry_name ) != 0 ) + continue; + + FM_DEBUG( " looking for matching style in foundry '%s'", + foundry->name.isEmpty() ? "-- none --" : foundry->name.latin1() ); + + TQtFontStyle *style = bestStyle(foundry, styleKey); + + if ( ! style->smoothScalable && ( styleStrategy & TQFont::ForceOutline ) ) { + FM_DEBUG( " ForceOutline set, but not smoothly scalable" ); + continue; + } + + int px = -1; + TQtFontSize *size = 0; + + // 1. see if we have an exact matching size + if (! (styleStrategy & TQFont::ForceOutline)) { + size = style->pixelSize(pixelSize); + if (size) { + FM_DEBUG(" found exact size match (%d pixels)", size->pixelSize); + px = size->pixelSize; + } + } + + // 2. see if we have a smoothly scalable font + if (! size && style->smoothScalable && ! (styleStrategy & TQFont::PreferBitmap)) { + size = style->pixelSize(SMOOTH_SCALABLE); + if (size) { + FM_DEBUG(" found smoothly scalable font (%d pixels)", pixelSize); + px = pixelSize; + } + } + + // 3. see if we have a bitmap scalable font + if (! size && style->bitmapScalable && (styleStrategy & TQFont::PreferMatch)) { + size = style->pixelSize(0); + if (size) { + FM_DEBUG(" found bitmap scalable font (%d pixels)", pixelSize); + px = pixelSize; + } + } + +#ifdef TQ_WS_X11 + TQtFontEncoding *encoding = 0; +#endif + + // 4. find closest size match + if (! size) { + unsigned int distance = ~0u; + for (int x = 0; x < style->count; ++x) { +#ifdef TQ_WS_X11 + encoding = + findEncoding(script, styleStrategy, style->pixelSizes + x, force_encoding_id); + if (!encoding) { + FM_DEBUG(" size %3d does not support the script we want", + style->pixelSizes[x].pixelSize); + continue; + } +#endif + + unsigned int d = TQABS(style->pixelSizes[x].pixelSize - pixelSize); + if (d < distance) { + distance = d; + size = style->pixelSizes + x; + FM_DEBUG(" best size so far: %3d (%d)", size->pixelSize, pixelSize); + } + } + + if (!size) { + FM_DEBUG(" no size supports the script we want"); + continue; + } + + if (style->bitmapScalable && ! (styleStrategy & TQFont::PreferQuality) && + (distance * 10 / pixelSize) >= 2) { + // the closest size is not close enough, go ahead and + // use a bitmap scaled font + size = style->pixelSize(0); + px = pixelSize; + } else { + px = size->pixelSize; + } + } + +#ifdef TQ_WS_X11 + if (size) { + encoding = findEncoding(script, styleStrategy, size, force_encoding_id); + if (!encoding) size = 0; + } + if ( ! encoding ) { + FM_DEBUG( " foundry doesn't support the script we want" ); + continue; + } +#endif // TQ_WS_X11 + + unsigned int this_score = 0x0000; + enum { + PitchMismatch = 0x4000, + StyleMismatch = 0x2000, + BitmapScaledPenalty = 0x1000, + EncodingMismatch = 0x0002, + XLFDPenalty = 0x0001 + }; + +#ifdef TQ_WS_X11 + if ( encoding->encoding != -1 ) { + this_score += XLFDPenalty; + if ( encoding->encoding != TQFontPrivate::defaultEncodingID ) + this_score += EncodingMismatch; + } + if (pitch != '*') { + if ( !( pitch == 'm' && encoding->pitch == 'c' ) && pitch != encoding->pitch ) + this_score += PitchMismatch; + } +#else + // ignore pitch for asian fonts, some of them misreport it, and they are all + // fixed pitch anyway. + if (pitch != '*' && (script <= TQFont::NScripts && script != TQFont::KatakanaHalfWidth + && (script < TQFont::Han || script > TQFont::Yi))) { + if ((pitch == 'm' && !family->fixedPitch) + || (pitch == 'p' && family->fixedPitch)) + this_score += PitchMismatch; + } +#endif + if ( styleKey != style->key ) + this_score += StyleMismatch; + if ( !style->smoothScalable && px != size->pixelSize ) // bitmap scaled + this_score += BitmapScaledPenalty; + if (px != pixelSize) // close, but not exact, size match + this_score += TQABS(px - pixelSize); + + if ( this_score < score ) { + FM_DEBUG( " found a match: score %x best score so far %x", + this_score, score ); + + score = this_score; + *best_foundry = foundry; + *best_style = style; + *best_size = size; +#ifdef TQ_WS_X11 + *best_encoding = encoding; +#endif // TQ_WS_X11 + } else { + FM_DEBUG( " score %x no better than best %x", this_score, score); + } + } + + return score; +} + +/*! + \internal +*/ +TQFontEngine * +TQFontDatabase::findFont( TQFont::Script script, const TQFontPrivate *fp, + const TQFontDef &request, int force_encoding_id ) +{ +#ifndef TQ_WS_X11 + Q_UNUSED( force_encoding_id ); +#endif + + if ( !db ) + initializeDb(); + + TQFontEngine *fe = 0; + if ( fp ) { + if ( fp->rawMode ) { + fe = loadEngine( script, fp, request, 0, 0, 0 +#ifdef TQ_WS_X11 + , 0, 0, FALSE +#endif + ); + + // if we fail to load the rawmode font, use a 12pixel box engine instead + if (! fe) fe = new TQFontEngineBox( 12 ); + return fe; + } + + TQFontCache::Key key( request, script, +#ifdef TQ_WS_WIN + (int)fp->paintdevice, +#else + fp->screen, +#endif + fp->paintdevice + ); + fe = TQFontCache::instance->findEngine( key ); + if ( fe ) return fe; + } + +#ifdef TQ_WS_WIN + if (request.styleStrategy & TQFont::PreferDevice) { + TQFontEngine *fe = loadEngine(script, fp, request, 0, 0, 0); + if(fe) + return fe; + } +#endif + + TQString family_name, foundry_name; + TQtFontStyle::Key styleKey; + styleKey.italic = request.italic; + styleKey.weight = request.weight; + styleKey.stretch = request.stretch; + char pitch = request.ignorePitch ? '*' : request.fixedPitch ? 'm' : 'p'; + + parseFontName( request.family, foundry_name, family_name ); + +#ifdef TQ_WS_X11 + if (script == TQFont::Han) { + // modify script according to locale + static TQFont::Script defaultHan; + TQCString locale = setlocale(LC_ALL, NULL); + + if (locale.contains("ko")) + defaultHan = TQFont::Han_Korean; + else if (locale.contains("zh_TW") || locale.contains("zh_HK")) + defaultHan = TQFont::Han_TraditionalChinese; + else if (locale.contains("zh")) + defaultHan = TQFont::Han_SimplifiedChinese; + else if (locale.contains("ja")) + defaultHan = TQFont::Han_Japanese; + else + defaultHan = TQFont::Han; // don't change + + script = defaultHan; + } +#endif + + FM_DEBUG( "TQFontDatabase::findFont\n" + " request:\n" + " family: %s [%s], script: %d (%s)\n" + " weight: %d, italic: %d\n" + " stretch: %d\n" + " pixelSize: %d\n" + " pitch: %c", + family_name.isEmpty() ? "-- first in script --" : family_name.latin1(), + foundry_name.isEmpty() ? "-- any --" : foundry_name.latin1(), + script, scriptName( script ).latin1(), + request.weight, request.italic, request.stretch, request.pixelSize, pitch ); + + bool usesFontConfig = FALSE; +#ifdef QT_XFT2 + if (family_name.isEmpty() + || family_name == "Sans Serif" + || family_name == "Serif" + || family_name == "Monospace") { + fe = loadFontConfigFont(fp, request, script); + usesFontConfig = (fe != 0); + } + if (!fe) +#endif + { + TQtFontFamily *best_family = 0; + TQtFontFoundry *best_foundry = 0; + TQtFontStyle *best_style = 0; + TQtFontSize *best_size = 0; +#ifdef TQ_WS_X11 + TQtFontEncoding *best_encoding = 0; +#endif // TQ_WS_X11 + + unsigned int score = ~0; + + load( family_name, script ); + + for ( int x = 0; x < db->count; ++x ) { + TQtFontFamily *try_family = db->families[x]; +#ifdef TQ_WS_X11 + if (try_family->synthetic) // skip generated fontconfig fonts + continue; +#endif + + if ( !family_name.isEmpty() && + ucstricmp( try_family->name, family_name ) != 0 +#ifdef TQ_WS_WIN + && ucstricmp( try_family->english_name, family_name ) != 0 +#endif + ) + continue; + + if ( family_name.isEmpty() ) + load( try_family->name, script ); + + uint score_adjust = 0; + TQFont::Script override_script = script; + if ( ! ( try_family->scripts[script] & TQtFontFamily::Supported ) + && script != TQFont::Unicode) { + // family not supported in the script we want +#ifdef TQ_WS_X11 + if (script >= TQFont::Han_Japanese && script <= TQFont::Han_Korean + && try_family->scripts[TQFont::Han] == TQtFontFamily::Supported) { + // try with the han script instead, give it a penalty + if (override_script == TQFont::Han_TraditionalChinese + && (try_family->scripts[TQFont::Han_SimplifiedChinese] & TQtFontFamily::Supported)) { + override_script = TQFont::Han_SimplifiedChinese; + score_adjust = 200; + } else if (override_script == TQFont::Han_SimplifiedChinese + && (try_family->scripts[TQFont::Han_TraditionalChinese] & TQtFontFamily::Supported)) { + override_script = TQFont::Han_TraditionalChinese; + score_adjust = 200; + } else { + override_script = TQFont::Han; + score_adjust = 400; + } + } else +#endif + if (family_name.isEmpty()) { + continue; + } else if (try_family->scripts[TQFont::UnknownScript] & TQtFontFamily::Supported) { + // try with the unknown script (for a symbol font) + override_script = TQFont::UnknownScript; +#ifndef QT_XFT2 + } else if (try_family->scripts[TQFont::Unicode] & TQtFontFamily::Supported) { + // try with the unicode script instead + override_script = TQFont::Unicode; +#endif + } else { + // family not supported by unicode/unknown scripts + continue; + } + } + + TQtFontFoundry *try_foundry = 0; + TQtFontStyle *try_style = 0; + TQtFontSize *try_size = 0; +#ifdef TQ_WS_X11 + TQtFontEncoding *try_encoding = 0; +#endif // TQ_WS_X11 + + // as we know the script is supported, we can be sure + // to find a matching font here. + unsigned int newscore = + bestFoundry( override_script, score, request.styleStrategy, + try_family, foundry_name, styleKey, request.pixelSize, pitch, + &try_foundry, &try_style, &try_size +#ifdef TQ_WS_X11 + , &try_encoding, force_encoding_id +#endif + ); + if ( try_foundry == 0 ) { + // the specific foundry was not found, so look for + // any foundry matching our requirements + newscore = bestFoundry( override_script, score, request.styleStrategy, try_family, + TQString::null, styleKey, request.pixelSize, + pitch, &try_foundry, &try_style, &try_size +#ifdef TQ_WS_X11 + , &try_encoding, force_encoding_id +#endif + ); + } + newscore += score_adjust; + + if ( newscore < score ) { + score = newscore; + best_family = try_family; + best_foundry = try_foundry; + best_style = try_style; + best_size = try_size; +#ifdef TQ_WS_X11 + best_encoding = try_encoding; +#endif // TQ_WS_X11 + } + if ( newscore < 10 ) // xlfd instead of xft... just accept it + break; + } + + if ( best_family != 0 && best_foundry != 0 && best_style != 0 +#ifdef TQ_WS_X11 + && best_size != 0 && best_encoding != 0 +#endif + ) { + FM_DEBUG( " BEST:\n" + " family: %s [%s]\n" + " weight: %d, italic: %d, oblique: %d\n" + " stretch: %d\n" + " pixelSize: %d\n" + " pitch: %c\n" + " encoding: %d\n", + best_family->name.latin1(), + best_foundry->name.isEmpty() ? "-- none --" : best_foundry->name.latin1(), + best_style->key.weight, best_style->key.italic, best_style->key.oblique, + best_style->key.stretch, best_size ? best_size->pixelSize : 0xffff, +#ifdef TQ_WS_X11 + best_encoding->pitch, best_encoding->encoding +#else + 'p', 0 +#endif + ); + + fe = loadEngine( script, fp, request, best_family, best_foundry, best_style +#ifdef TQ_WS_X11 + , best_size, best_encoding, ( force_encoding_id >= 0 ) +#endif + ); + } + if (fe) { + fe->fontDef.family = best_family->name; + if ( ! best_foundry->name.isEmpty() ) { + fe->fontDef.family += TQString::fromLatin1( " [" ); + fe->fontDef.family += best_foundry->name; + fe->fontDef.family += TQString::fromLatin1( "]" ); + } + + if ( best_style->smoothScalable ) + fe->fontDef.pixelSize = request.pixelSize; + else if ( best_style->bitmapScalable && + ( request.styleStrategy & TQFont::PreferMatch ) ) + fe->fontDef.pixelSize = request.pixelSize; + else + fe->fontDef.pixelSize = best_size->pixelSize; + + fe->fontDef.styleHint = request.styleHint; + fe->fontDef.styleStrategy = request.styleStrategy; + + fe->fontDef.weight = best_style->key.weight; + fe->fontDef.italic = best_style->key.italic || best_style->key.oblique; + fe->fontDef.fixedPitch = best_family->fixedPitch; + fe->fontDef.stretch = best_style->key.stretch; + fe->fontDef.ignorePitch = FALSE; + } + } + + if ( fe ) { + if ( script != TQFont::Unicode && !canRender( fe, script ) ) { + FM_DEBUG( " WARN: font loaded cannot render a sample char" ); + + delete fe; + fe = 0; + } else if ( fp ) { + TQFontDef def = request; + if (def.family.isEmpty()) { + def.family = fp->request.family; + def.family = def.family.left(def.family.find(',')); + } + TQFontCache::Key key( def, script, +#ifdef TQ_WS_WIN + (int)fp->paintdevice, +#else + fp->screen, +#endif + fp->paintdevice + ); + TQFontCache::instance->insertEngine( key, fe ); + if (!usesFontConfig) { + for ( int i = 0; i < TQFont::NScripts; ++i ) { + if ( i == script ) continue; + + if (!canRender(fe, (TQFont::Script) i)) + continue; + + key.script = i; + TQFontCache::instance->insertEngine( key, fe ); + } + } + } + } + + if (!fe) { + if ( !request.family.isEmpty() ) + return 0; + + FM_DEBUG( "returning box engine" ); + + fe = new TQFontEngineBox( request.pixelSize ); + fe->fontDef = request; + + if ( fp ) { + TQFontCache::Key key( request, script, +#ifdef TQ_WS_WIN + (int)fp->paintdevice, +#else + fp->screen, +#endif + fp->paintdevice + ); + TQFontCache::instance->insertEngine( key, fe ); + } + } + + if ( fp ) { +#if defined(TQ_WS_X11) + fe->fontDef.pointSize = + tqRound(10. * qt_pointSize(fe->fontDef.pixelSize, fp->paintdevice, fp->screen)); +#elif defined(TQ_WS_WIN) + fe->fontDef.pointSize = int( double( fe->fontDef.pixelSize ) * 720.0 / + GetDeviceCaps(shared_dc,LOGPIXELSY) ); +#else + fe->fontDef.pointSize = int( double( fe->fontDef.pixelSize ) * 720.0 / + 96.0 ); +#endif + } else { + fe->fontDef.pointSize = request.pointSize; + } + + return fe; +} +#endif // TQ_WS_X11 || TQ_WS_WIN + + + + +static TQString styleString( int weight, bool italic, bool oblique ) +{ + TQString result; + if ( weight >= TQFont::Black ) + result = "Black"; + else if ( weight >= TQFont::Bold ) + result = "Bold"; + else if ( weight >= TQFont::DemiBold ) + result = "Demi Bold"; + else if ( weight < TQFont::Normal ) + result = "Light"; + + if ( italic ) + result += " Italic"; + else if ( oblique ) + result += " Oblique"; + + if ( result.isEmpty() ) + result = "Normal"; + + return result.simplifyWhiteSpace(); +} + +/*! + Returns a string that describes the style of the font \a f. For + example, "Bold Italic", "Bold", "Italic" or "Normal". An empty + string may be returned. +*/ +TQString TQFontDatabase::styleString( const TQFont &f ) +{ + // ### fix oblique here + return ::styleString( f.weight(), f.italic(), FALSE ); +} + + +/*! + \class TQFontDatabase tqfontdatabase.h + \brief The TQFontDatabase class provides information about the fonts available in the underlying window system. + + \ingroup environment + \ingroup graphics + + The most common uses of this class are to query the database for + the list of font families() and for the pointSizes() and styles() + that are available for each family. An alternative to pointSizes() + is smoothSizes() which returns the sizes at which a given family + and style will look attractive. + + If the font family is available from two or more foundries the + foundry name is included in the family name, e.g. "Helvetica + [Adobe]" and "Helvetica [Cronyx]". When you specify a family you + can either use the old hyphenated TQt 2.x "foundry-family" format, + e.g. "Cronyx-Helvetica", or the new bracketed TQt 3.x "family + [foundry]" format e.g. "Helvetica [Cronyx]". If the family has a + foundry it is always returned, e.g. by families(), using the + bracketed format. + + The font() function returns a TQFont given a family, style and + point size. + + A family and style combination can be checked to see if it is + italic() or bold(), and to retrieve its weight(). Similarly we can + call isBitmapScalable(), isSmoothlyScalable(), isScalable() and + isFixedPitch(). + + A text version of a style is given by styleString(). + + The TQFontDatabase class also supports some static functions, for + example, standardSizes(). You can retrieve the Unicode 3.0 + description of a \link TQFont::Script script\endlink using + scriptName(), and a sample of characters in a script with + scriptSample(). + + Example: +\code +#include +#include +#include + +int main( int argc, char **argv ) +{ + TQApplication app( argc, argv ); + TQFontDatabase fdb; + TQStringList families = fdb.families(); + for ( TQStringList::Iterator f = families.begin(); f != families.end(); ++f ) { + TQString family = *f; + tqDebug( family ); + TQStringList styles = fdb.styles( family ); + for ( TQStringList::Iterator s = styles.begin(); s != styles.end(); ++s ) { + TQString style = *s; + TQString dstyle = "\t" + style + " ("; + TQValueList smoothies = fdb.smoothSizes( family, style ); + for ( TQValueList::Iterator points = smoothies.begin(); + points != smoothies.end(); ++points ) { + dstyle += TQString::number( *points ) + " "; + } + dstyle = dstyle.left( dstyle.length() - 1 ) + ")"; + tqDebug( dstyle ); + } + } + return 0; +} +\endcode + This example gets the list of font families, then the list of + styles for each family and the point sizes that are available for + each family/style combination. +*/ +/*! + \obsolete + \fn inline TQStringList TQFontDatabase::families( bool ) const +*/ +/*! + \obsolete + \fn inline TQStringList TQFontDatabase::styles( const TQString &family, + const TQString & ) const +*/ +/*! + \obsolete + \fn inline TQValueList TQFontDatabase::pointSizes( const TQString &family, + const TQString &style , + const TQString & ) +*/ + +/*! + \obsolete + \fn inline TQValueList TQFontDatabase::smoothSizes( const TQString &family, + const TQString &style, + const TQString & ) +*/ +/*! + \obsolete + \fn inline TQFont TQFontDatabase::font( const TQString &familyName, + const TQString &style, + int pointSize, + const TQString &) +*/ +/*! + \obsolete + \fn inline bool TQFontDatabase::isBitmapScalable( const TQString &family, + const TQString &style, + const TQString & ) const +*/ + +/*! + \obsolete + \fn inline bool TQFontDatabase::isSmoothlyScalable( const TQString &family, + const TQString &style, + const TQString & ) const +*/ + +/*! + \obsolete + \fn inline bool TQFontDatabase::isScalable( const TQString &family, + const TQString &style, + const TQString & ) const +*/ + +/*! + \obsolete + \fn inline bool TQFontDatabase::isFixedPitch( const TQString &family, + const TQString &style, + const TQString & ) const +*/ + +/*! + \obsolete + \fn inline bool TQFontDatabase::italic( const TQString &family, + const TQString &style, + const TQString & ) const +*/ + +/*! + \obsolete + \fn inline bool TQFontDatabase::bold( const TQString &family, + const TQString &style, + const TQString & ) const +*/ + +/*! + \obsolete + \fn inline int TQFontDatabase::weight( const TQString &family, + const TQString &style, + const TQString & ) const +*/ + + +/*! + Creates a font database object. +*/ +TQFontDatabase::TQFontDatabase() +{ + createDatabase(); + + d = db; +} + + +/*! Returns a sorted list of the names of the available font families. + + If a family exists in several foundries, the returned name for + that font is in the form "family [foundry]". Examples: "Times + [Adobe]", "Times [Cronyx]", "Palatino". +*/ +TQStringList TQFontDatabase::families() const +{ + load(); + + TQStringList flist; + for ( int i = 0; i < d->count; i++ ) { + TQtFontFamily *f = d->families[i]; + if ( f->count == 0 ) + continue; + if ( f->count == 1 ) { + flist.append( f->name ); + } else { + for ( int j = 0; j < f->count; j++ ) { + TQString str = f->name; + TQString foundry = f->foundries[j]->name; + if ( !foundry.isEmpty() ) { + str += " ["; + str += foundry; + str += "]"; + } + flist.append( str ); + } + } + } + return flist; +} + +/*! + \overload + + Returns a sorted list of the available font families which support + the Unicode script \a script. + + If a family exists in several foundries, the returned name for + that font is in the form "family [foundry]". Examples: "Times + [Adobe]", "Times [Cronyx]", "Palatino". +*/ +TQStringList TQFontDatabase::families( TQFont::Script script ) const +{ + load(); + + TQStringList flist; + for ( int i = 0; i < d->count; i++ ) { + TQtFontFamily *f = d->families[i]; + if ( f->count == 0 ) + continue; + if (!(f->scripts[script] & TQtFontFamily::Supported)) + continue; + if ( f->count == 1 ) { + flist.append( f->name ); + } else { + for ( int j = 0; j < f->count; j++ ) { + TQString str = f->name; + TQString foundry = f->foundries[j]->name; + if ( !foundry.isEmpty() ) { + str += " ["; + str += foundry; + str += "]"; + } + flist.append( str ); + } + } + } + return flist; +} + +/*! + Returns a list of the styles available for the font family \a + family. Some example styles: "Light", "Light Italic", "Bold", + "Oblique", "Demi". The list may be empty. +*/ +TQStringList TQFontDatabase::styles( const TQString &family ) const +{ + TQString familyName, foundryName; + parseFontName( family, foundryName, familyName ); + + load( familyName ); + + TQStringList l; + TQtFontFamily *f = d->family( familyName ); + if ( !f ) + return l; + + TQtFontFoundry allStyles( foundryName ); + for ( int j = 0; j < f->count; j++ ) { + TQtFontFoundry *foundry = f->foundries[j]; + if ( foundryName.isEmpty() || ucstricmp( foundry->name, foundryName ) == 0 ) { + for ( int k = 0; k < foundry->count; k++ ) { + TQtFontStyle::Key ke( foundry->styles[k]->key ); + ke.stretch = 0; + allStyles.style( ke, TRUE ); + } + } + } + + for ( int i = 0; i < allStyles.count; i++ ) + l.append( ::styleString( allStyles.styles[i]->key.weight, + allStyles.styles[i]->key.italic, + allStyles.styles[i]->key.oblique ) ); + return l; +} + +/*! + Returns TRUE if the font that has family \a family and style \a + style is fixed pitch; otherwise returns FALSE. +*/ + +bool TQFontDatabase::isFixedPitch(const TQString &family, + const TQString &style) const +{ + Q_UNUSED(style); + + TQString familyName, foundryName; + parseFontName( family, foundryName, familyName ); + + load( familyName ); + + TQtFontFamily *f = d->family( familyName ); +#if defined(Q_OS_MAC) + if (f) { + if (!f->fixedPitchComputed) { + TQFontMetrics fm(familyName); + f->fixedPitch = fm.width('i') == fm.width('m'); + f->fixedPitchComputed = TRUE; + } + } +#endif + + return ( f && f->fixedPitch ); +} + +/*! + Returns TRUE if the font that has family \a family and style \a + style is a scalable bitmap font; otherwise returns FALSE. Scaling + a bitmap font usually produces an unattractive hardly readable + result, because the pixels of the font are scaled. If you need to + scale a bitmap font it is better to scale it to one of the fixed + sizes returned by smoothSizes(). + + \sa isScalable(), isSmoothlyScalable() +*/ +bool TQFontDatabase::isBitmapScalable( const TQString &family, + const TQString &style) const +{ + bool bitmapScalable = FALSE; + TQString familyName, foundryName; + parseFontName( family, foundryName, familyName ); + + load( familyName ); + + TQtFontStyle::Key styleKey( style ); + + TQtFontFamily *f = d->family( familyName ); + if ( !f ) return bitmapScalable; + + for ( int j = 0; j < f->count; j++ ) { + TQtFontFoundry *foundry = f->foundries[j]; + if ( foundryName.isEmpty() || ucstricmp( foundry->name, foundryName ) == 0 ) { + for ( int k = 0; k < foundry->count; k++ ) + if ((style.isEmpty() || foundry->styles[k]->key == styleKey) && + foundry->styles[k]->bitmapScalable && !foundry->styles[k]->smoothScalable) { + bitmapScalable = TRUE; + goto end; + } + } + } + end: + return bitmapScalable; +} + + +/*! + Returns TRUE if the font that has family \a family and style \a + style is smoothly scalable; otherwise returns FALSE. If this + function returns TRUE, it's safe to scale this font to any size, + and the result will always look attractive. + + \sa isScalable(), isBitmapScalable() +*/ +bool TQFontDatabase::isSmoothlyScalable( const TQString &family, + const TQString &style) const +{ + bool smoothScalable = FALSE; + TQString familyName, foundryName; + parseFontName( family, foundryName, familyName ); + + load( familyName ); + + TQtFontStyle::Key styleKey( style ); + + TQtFontFamily *f = d->family( familyName ); + if ( !f ) return smoothScalable; + + for ( int j = 0; j < f->count; j++ ) { + TQtFontFoundry *foundry = f->foundries[j]; + if ( foundryName.isEmpty() || ucstricmp( foundry->name, foundryName ) == 0 ) { + for ( int k = 0; k < foundry->count; k++ ) + if ((style.isEmpty() || foundry->styles[k]->key == styleKey) && foundry->styles[k]->smoothScalable) { + smoothScalable = TRUE; + goto end; + } + } + } + end: + return smoothScalable; +} + +/*! + Returns TRUE if the font that has family \a family and style \a + style is scalable; otherwise returns FALSE. + + \sa isBitmapScalable(), isSmoothlyScalable() +*/ +bool TQFontDatabase::isScalable( const TQString &family, + const TQString &style) const +{ + if ( isSmoothlyScalable( family, style) ) + return TRUE; + + return isBitmapScalable( family, style); +} + + +/*! + Returns a list of the point sizes available for the font that has + family \a family and style \a style. The list may be empty. + + \sa smoothSizes(), standardSizes() +*/ +TQValueList TQFontDatabase::pointSizes( const TQString &family, + const TQString &style) +{ +#if defined(TQ_WS_MAC) + // windows and macosx are always smoothly scalable + Q_UNUSED( family ); + Q_UNUSED( style ); + return standardSizes(); +#else + bool smoothScalable = FALSE; + TQString familyName, foundryName; + parseFontName( family, foundryName, familyName ); + + load( familyName ); + + TQtFontStyle::Key styleKey( style ); + + TQValueList sizes; + + TQtFontFamily *fam = d->family( familyName ); + if ( !fam ) return sizes; + + for ( int j = 0; j < fam->count; j++ ) { + TQtFontFoundry *foundry = fam->foundries[j]; + if ( foundryName.isEmpty() || ucstricmp( foundry->name, foundryName ) == 0 ) { + TQtFontStyle *style = foundry->style( styleKey ); + if ( !style ) continue; + + if ( style->smoothScalable ) { + smoothScalable = TRUE; + goto end; + } + for ( int l = 0; l < style->count; l++ ) { + const TQtFontSize *size = style->pixelSizes + l; + + if (size->pixelSize != 0 && size->pixelSize != USHRT_MAX) { +#ifdef TQ_WS_X11 + const uint pointSize = tqRound(qt_pointSize(size->pixelSize, 0, -1)); +#else + const uint pointSize = size->pixelSize; // embedded uses 72dpi +#endif + if (! sizes.contains(pointSize)) + sizes.append(pointSize); + } + } + } + } + end: + if ( smoothScalable ) + return standardSizes(); + + qHeapSort( sizes ); + return sizes; +#endif +} + +/*! + Returns a TQFont object that has family \a family, style \a style + and point size \a pointSize. If no matching font could be created, + a TQFont object that uses the application's default font is + returned. +*/ +TQFont TQFontDatabase::font( const TQString &family, const TQString &style, + int pointSize) +{ + TQString familyName, foundryName; + parseFontName( family, foundryName, familyName ); + + load( familyName ); + + TQtFontFoundry allStyles( foundryName ); + TQtFontFamily *f = d->family( familyName ); + if ( !f ) return TQApplication::font(); + + for ( int j = 0; j < f->count; j++ ) { + TQtFontFoundry *foundry = f->foundries[j]; + if ( foundryName.isEmpty() || ucstricmp( foundry->name, foundryName ) == 0 ) { + for ( int k = 0; k < foundry->count; k++ ) + allStyles.style( foundry->styles[k]->key, TRUE ); + } + } + + TQtFontStyle::Key styleKey( style ); + TQtFontStyle *s = bestStyle(&allStyles, styleKey); + + if ( !s ) // no styles found? + return TQApplication::font(); + return TQFont( family, pointSize, s->key.weight, + s->key.italic ? TRUE : s->key.oblique ? TRUE : FALSE ); +} + + +/*! + Returns the point sizes of a font that has family \a family and + style \a style that will look attractive. The list may be empty. + For non-scalable fonts and bitmap scalable fonts, this function + is equivalent to pointSizes(). + + \sa pointSizes(), standardSizes() +*/ +TQValueList TQFontDatabase::smoothSizes( const TQString &family, + const TQString &style) +{ +#ifdef TQ_WS_WIN + Q_UNUSED( family ); + Q_UNUSED( style ); + return TQFontDatabase::standardSizes(); +#else + bool smoothScalable = FALSE; + TQString familyName, foundryName; + parseFontName( family, foundryName, familyName ); + + load( familyName ); + + TQtFontStyle::Key styleKey( style ); + + TQValueList sizes; + + TQtFontFamily *fam = d->family( familyName ); + if ( !fam ) + return sizes; + + for ( int j = 0; j < fam->count; j++ ) { + TQtFontFoundry *foundry = fam->foundries[j]; + if ( foundryName.isEmpty() || + ucstricmp( foundry->name, foundryName ) == 0 ) { + TQtFontStyle *style = foundry->style( styleKey ); + if ( !style ) continue; + + if ( style->smoothScalable ) { + smoothScalable = TRUE; + goto end; + } + for ( int l = 0; l < style->count; l++ ) { + const TQtFontSize *size = style->pixelSizes + l; + + if ( size->pixelSize != 0 && size->pixelSize != USHRT_MAX ) { +#ifdef TQ_WS_X11 + const uint pointSize = tqRound(qt_pointSize(size->pixelSize, 0, -1)); +#else + const uint pointSize = size->pixelSize; // embedded uses 72dpi +#endif + if (! sizes.contains(pointSize)) + sizes.append( pointSize ); + } + } + } + } + end: + if ( smoothScalable ) + return TQFontDatabase::standardSizes(); + + qHeapSort( sizes ); + return sizes; +#endif +} + + +/*! + Returns a list of standard font sizes. + + \sa smoothSizes(), pointSizes() +*/ +TQValueList TQFontDatabase::standardSizes() +{ + TQValueList ret; + static const unsigned short standard[] = + { 6, 7, 8, 9, 10, 11, 12, 14, 16, 18, 20, 22, 24, 26, 28, 36, 48, 72, 0 }; + const unsigned short *sizes = standard; + while ( *sizes ) ret << *sizes++; + return ret; +} + + +/*! + Returns TRUE if the font that has family \a family and style \a + style is italic; otherwise returns FALSE. + + \sa weight(), bold() +*/ +bool TQFontDatabase::italic( const TQString &family, + const TQString &style) const +{ + TQString familyName, foundryName; + parseFontName( family, foundryName, familyName ); + + load( familyName ); + + TQtFontFoundry allStyles( foundryName ); + TQtFontFamily *f = d->family( familyName ); + if ( !f ) return FALSE; + + for ( int j = 0; j < f->count; j++ ) { + TQtFontFoundry *foundry = f->foundries[j]; + if ( foundryName.isEmpty() || ucstricmp( foundry->name, foundryName ) == 0 ) { + for ( int k = 0; k < foundry->count; k++ ) + allStyles.style( foundry->styles[k]->key, TRUE ); + } + } + + TQtFontStyle::Key styleKey( style ); + TQtFontStyle *s = allStyles.style( styleKey ); + return s && s->key.italic; +} + + +/*! + Returns TRUE if the font that has family \a family and style \a + style is bold; otherwise returns FALSE. + + \sa italic(), weight() +*/ +bool TQFontDatabase::bold( const TQString &family, + const TQString &style) const +{ + TQString familyName, foundryName; + parseFontName( family, foundryName, familyName ); + + load( familyName ); + + TQtFontFoundry allStyles( foundryName ); + TQtFontFamily *f = d->family( familyName ); + if ( !f ) return FALSE; + + for ( int j = 0; j < f->count; j++ ) { + TQtFontFoundry *foundry = f->foundries[j]; + if ( foundryName.isEmpty() || + ucstricmp( foundry->name, foundryName ) == 0 ) { + for ( int k = 0; k < foundry->count; k++ ) + allStyles.style( foundry->styles[k]->key, TRUE ); + } + } + + TQtFontStyle::Key styleKey( style ); + TQtFontStyle *s = allStyles.style( styleKey ); + return s && s->key.weight >= TQFont::Bold; +} + + +/*! + Returns the weight of the font that has family \a family and style + \a style. If there is no such family and style combination, + returns -1. + + \sa italic(), bold() +*/ +int TQFontDatabase::weight( const TQString &family, + const TQString &style) const +{ + TQString familyName, foundryName; + parseFontName( family, foundryName, familyName ); + + load( familyName ); + + TQtFontFoundry allStyles( foundryName ); + TQtFontFamily *f = d->family( familyName ); + if ( !f ) return -1; + + for ( int j = 0; j < f->count; j++ ) { + TQtFontFoundry *foundry = f->foundries[j]; + if ( foundryName.isEmpty() || + ucstricmp( foundry->name, foundryName ) == 0 ) { + for ( int k = 0; k < foundry->count; k++ ) + allStyles.style( foundry->styles[k]->key, TRUE ); + } + } + + TQtFontStyle::Key styleKey( style ); + TQtFontStyle *s = allStyles.style( styleKey ); + return s ? s->key.weight : -1; +} + + +/*! + Returns a string that gives a default description of the \a script + (e.g. for displaying to the user in a dialog). The name matches + the name of the script as defined by the Unicode 3.0 standard. + + \sa TQFont::Script +*/ +TQString TQFontDatabase::scriptName(TQFont::Script script) +{ + const char *name = 0; + + switch (script) { + case TQFont::Latin: + name = TQT_TRANSLATE_NOOP("TQFont", "Latin"); + break; + case TQFont::Greek: + name = TQT_TRANSLATE_NOOP("TQFont", "Greek" ); + break; + case TQFont::Cyrillic: + name = TQT_TRANSLATE_NOOP("TQFont", "Cyrillic" ); + break; + case TQFont::Armenian: + name = TQT_TRANSLATE_NOOP("TQFont", "Armenian" ); + break; + case TQFont::Georgian: + name = TQT_TRANSLATE_NOOP("TQFont", "Georgian" ); + break; + case TQFont::Runic: + name = TQT_TRANSLATE_NOOP("TQFont", "Runic" ); + break; + case TQFont::Ogham: + name = TQT_TRANSLATE_NOOP("TQFont", "Ogham" ); + break; + case TQFont::SpacingModifiers: + name = TQT_TRANSLATE_NOOP("TQFont", "SpacingModifiers" ); + break; + case TQFont::CombiningMarks: + name = TQT_TRANSLATE_NOOP("TQFont", "CombiningMarks" ); + break; + case TQFont::Hebrew: + name = TQT_TRANSLATE_NOOP("TQFont", "Hebrew" ); + break; + case TQFont::Arabic: + name = TQT_TRANSLATE_NOOP("TQFont", "Arabic" ); + break; + case TQFont::Syriac: + name = TQT_TRANSLATE_NOOP("TQFont", "Syriac" ); + break; + case TQFont::Thaana: + name = TQT_TRANSLATE_NOOP("TQFont", "Thaana" ); + break; + case TQFont::Devanagari: + name = TQT_TRANSLATE_NOOP("TQFont", "Devanagari" ); + break; + case TQFont::Bengali: + name = TQT_TRANSLATE_NOOP("TQFont", "Bengali" ); + break; + case TQFont::Gurmukhi: + name = TQT_TRANSLATE_NOOP("TQFont", "Gurmukhi" ); + break; + case TQFont::Gujarati: + name = TQT_TRANSLATE_NOOP("TQFont", "Gujarati" ); + break; + case TQFont::Oriya: + name = TQT_TRANSLATE_NOOP("TQFont", "Oriya" ); + break; + case TQFont::Tamil: + name = TQT_TRANSLATE_NOOP("TQFont", "Tamil" ); + break; + case TQFont::Telugu: + name = TQT_TRANSLATE_NOOP("TQFont", "Telugu" ); + break; + case TQFont::Kannada: + name = TQT_TRANSLATE_NOOP("TQFont", "Kannada" ); + break; + case TQFont::Malayalam: + name = TQT_TRANSLATE_NOOP("TQFont", "Malayalam" ); + break; + case TQFont::Sinhala: + name = TQT_TRANSLATE_NOOP("TQFont", "Sinhala" ); + break; + case TQFont::Thai: + name = TQT_TRANSLATE_NOOP("TQFont", "Thai" ); + break; + case TQFont::Lao: + name = TQT_TRANSLATE_NOOP("TQFont", "Lao" ); + break; + case TQFont::Tibetan: + name = TQT_TRANSLATE_NOOP("TQFont", "Tibetan" ); + break; + case TQFont::Myanmar: + name = TQT_TRANSLATE_NOOP("TQFont", "Myanmar" ); + break; + case TQFont::Khmer: + name = TQT_TRANSLATE_NOOP("TQFont", "Khmer" ); + break; + case TQFont::Han: + name = TQT_TRANSLATE_NOOP("TQFont", "Han" ); + break; + case TQFont::Hiragana: + name = TQT_TRANSLATE_NOOP("TQFont", "Hiragana" ); + break; + case TQFont::Katakana: + name = TQT_TRANSLATE_NOOP("TQFont", "Katakana" ); + break; + case TQFont::Hangul: + name = TQT_TRANSLATE_NOOP("TQFont", "Hangul" ); + break; + case TQFont::Bopomofo: + name = TQT_TRANSLATE_NOOP("TQFont", "Bopomofo" ); + break; + case TQFont::Yi: + name = TQT_TRANSLATE_NOOP("TQFont", "Yi" ); + break; + case TQFont::Ethiopic: + name = TQT_TRANSLATE_NOOP("TQFont", "Ethiopic" ); + break; + case TQFont::Cherokee: + name = TQT_TRANSLATE_NOOP("TQFont", "Cherokee" ); + break; + case TQFont::CanadianAboriginal: + name = TQT_TRANSLATE_NOOP("TQFont", "Canadian Aboriginal" ); + break; + case TQFont::Mongolian: + name = TQT_TRANSLATE_NOOP("TQFont", "Mongolian" ); + break; + + case TQFont::CurrencySymbols: + name = TQT_TRANSLATE_NOOP("TQFont", "Currency Symbols" ); + break; + + case TQFont::LetterlikeSymbols: + name = TQT_TRANSLATE_NOOP("TQFont", "Letterlike Symbols" ); + break; + + case TQFont::NumberForms: + name = TQT_TRANSLATE_NOOP("TQFont", "Number Forms" ); + break; + + case TQFont::MathematicalOperators: + name = TQT_TRANSLATE_NOOP("TQFont", "Mathematical Operators" ); + break; + + case TQFont::TechnicalSymbols: + name = TQT_TRANSLATE_NOOP("TQFont", "Technical Symbols" ); + break; + + case TQFont::GeometricSymbols: + name = TQT_TRANSLATE_NOOP("TQFont", "Geometric Symbols" ); + break; + + case TQFont::MiscellaneousSymbols: + name = TQT_TRANSLATE_NOOP("TQFont", "Miscellaneous Symbols" ); + break; + + case TQFont::EnclosedAndSquare: + name = TQT_TRANSLATE_NOOP("TQFont", "Enclosed and Square" ); + break; + + case TQFont::Braille: + name = TQT_TRANSLATE_NOOP("TQFont", "Braille" ); + break; + + case TQFont::Unicode: + name = TQT_TRANSLATE_NOOP("TQFont", "Unicode" ); + break; + + case TQFont::Tagalog: + name = TQT_TRANSLATE_NOOP( "TQFont", "Tagalog" ); + break; + + case TQFont::Hanunoo: + name = TQT_TRANSLATE_NOOP( "TQFont", "Hanunoo" ); + break; + + case TQFont::Buhid: + name = TQT_TRANSLATE_NOOP( "TQFont", "Buhid" ); + break; + + case TQFont::Tagbanwa: + name = TQT_TRANSLATE_NOOP( "TQFont", "Tagbanwa" ); + break; + + case TQFont::KatakanaHalfWidth: + name = TQT_TRANSLATE_NOOP( "TQFont", "Katakana Half-Width Forms" ); + break; + + case TQFont::Han_Japanese: + name = TQT_TRANSLATE_NOOP( "TQFont", "Han (Japanese)" ); + break; + + case TQFont::Han_SimplifiedChinese: + name = TQT_TRANSLATE_NOOP( "TQFont", "Han (Simplified Chinese)" ); + break; + + case TQFont::Han_TraditionalChinese: + name = TQT_TRANSLATE_NOOP( "TQFont", "Han (Traditional Chinese)" ); + break; + + case TQFont::Han_Korean: + name = TQT_TRANSLATE_NOOP( "TQFont", "Han (Korean)" ); + break; + + default: + name = TQT_TRANSLATE_NOOP( "TQFont", "Unknown Script" ); + break; + } + + return tqApp ? tqApp->translate("TQFont", name) : TQString::fromLatin1(name); +} + + +/*! + Returns a string with sample characters from \a script. + + \sa TQFont::Script +*/ +TQString TQFontDatabase::scriptSample(TQFont::Script script) +{ + TQString sample = "AaBb"; + + switch (script) { + case TQFont::Latin: + // This is cheating... we only show latin-1 characters so that we don't + // end up loading lots of fonts - at least on X11... + sample += TQChar(0x00C3); + sample += TQChar(0x00E1); + sample += "Zz"; + break; + case TQFont::Greek: + sample += TQChar(0x0393); + sample += TQChar(0x03B1); + sample += TQChar(0x03A9); + sample += TQChar(0x03C9); + break; + case TQFont::Cyrillic: + sample += TQChar(0x0414); + sample += TQChar(0x0434); + sample += TQChar(0x0436); + sample += TQChar(0x0402); + break; + case TQFont::Armenian: + sample += TQChar(0x053f); + sample += TQChar(0x054f); + sample += TQChar(0x056f); + sample += TQChar(0x057f); + break; + case TQFont::Georgian: + sample += TQChar(0x10a0); + sample += TQChar(0x10b0); + sample += TQChar(0x10c0); + sample += TQChar(0x10d0); + break; + case TQFont::Runic: + sample += TQChar(0x16a0); + sample += TQChar(0x16b0); + sample += TQChar(0x16c0); + sample += TQChar(0x16d0); + break; + case TQFont::Ogham: + sample += TQChar(0x1681); + sample += TQChar(0x1687); + sample += TQChar(0x1693); + sample += TQChar(0x168d); + break; + + + + case TQFont::Hebrew: + sample += TQChar(0x05D0); + sample += TQChar(0x05D1); + sample += TQChar(0x05D2); + sample += TQChar(0x05D3); + break; + case TQFont::Arabic: + sample += TQChar(0x0628); + sample += TQChar(0x0629); + sample += TQChar(0x062A); + sample += TQChar(0x063A); + break; + case TQFont::Syriac: + sample += TQChar(0x0715); + sample += TQChar(0x0725); + sample += TQChar(0x0716); + sample += TQChar(0x0726); + break; + case TQFont::Thaana: + sample += TQChar(0x0784); + sample += TQChar(0x0794); + sample += TQChar(0x078c); + sample += TQChar(0x078d); + break; + + + + case TQFont::Devanagari: + sample += TQChar(0x0905); + sample += TQChar(0x0915); + sample += TQChar(0x0925); + sample += TQChar(0x0935); + break; + case TQFont::Bengali: + sample += TQChar(0x0986); + sample += TQChar(0x0996); + sample += TQChar(0x09a6); + sample += TQChar(0x09b6); + break; + case TQFont::Gurmukhi: + sample += TQChar(0x0a05); + sample += TQChar(0x0a15); + sample += TQChar(0x0a25); + sample += TQChar(0x0a35); + break; + case TQFont::Gujarati: + sample += TQChar(0x0a85); + sample += TQChar(0x0a95); + sample += TQChar(0x0aa5); + sample += TQChar(0x0ab5); + break; + case TQFont::Oriya: + sample += TQChar(0x0b06); + sample += TQChar(0x0b16); + sample += TQChar(0x0b2b); + sample += TQChar(0x0b36); + break; + case TQFont::Tamil: + sample += TQChar(0x0b89); + sample += TQChar(0x0b99); + sample += TQChar(0x0ba9); + sample += TQChar(0x0bb9); + break; + case TQFont::Telugu: + sample += TQChar(0x0c05); + sample += TQChar(0x0c15); + sample += TQChar(0x0c25); + sample += TQChar(0x0c35); + break; + case TQFont::Kannada: + sample += TQChar(0x0c85); + sample += TQChar(0x0c95); + sample += TQChar(0x0ca5); + sample += TQChar(0x0cb5); + break; + case TQFont::Malayalam: + sample += TQChar(0x0d05); + sample += TQChar(0x0d15); + sample += TQChar(0x0d25); + sample += TQChar(0x0d35); + break; + case TQFont::Sinhala: + sample += TQChar(0x0d90); + sample += TQChar(0x0da0); + sample += TQChar(0x0db0); + sample += TQChar(0x0dc0); + break; + case TQFont::Thai: + sample += TQChar(0x0e02); + sample += TQChar(0x0e12); + sample += TQChar(0x0e22); + sample += TQChar(0x0e32); + break; + case TQFont::Lao: + sample += TQChar(0x0e8d); + sample += TQChar(0x0e9d); + sample += TQChar(0x0ead); + sample += TQChar(0x0ebd); + break; + case TQFont::Tibetan: + sample += TQChar(0x0f00); + sample += TQChar(0x0f01); + sample += TQChar(0x0f02); + sample += TQChar(0x0f03); + break; + case TQFont::Myanmar: + sample += TQChar(0x1000); + sample += TQChar(0x1001); + sample += TQChar(0x1002); + sample += TQChar(0x1003); + break; + case TQFont::Khmer: + sample += TQChar(0x1780); + sample += TQChar(0x1790); + sample += TQChar(0x17b0); + sample += TQChar(0x17c0); + break; + + + + case TQFont::Han: + sample += TQChar(0x6f84); + sample += TQChar(0x820a); + sample += TQChar(0x61a9); + sample += TQChar(0x9781); + break; + case TQFont::Hiragana: + sample += TQChar(0x3050); + sample += TQChar(0x3060); + sample += TQChar(0x3070); + sample += TQChar(0x3080); + break; + case TQFont::Katakana: + sample += TQChar(0x30b0); + sample += TQChar(0x30c0); + sample += TQChar(0x30d0); + sample += TQChar(0x30e0); + break; + case TQFont::Hangul: + sample += TQChar(0xac00); + sample += TQChar(0xac11); + sample += TQChar(0xac1a); + sample += TQChar(0xac2f); + break; + case TQFont::Bopomofo: + sample += TQChar(0x3105); + sample += TQChar(0x3115); + sample += TQChar(0x3125); + sample += TQChar(0x3129); + break; + case TQFont::Yi: + sample += TQChar(0xa1a8); + sample += TQChar(0xa1a6); + sample += TQChar(0xa200); + sample += TQChar(0xa280); + break; + + + + case TQFont::Ethiopic: + sample += TQChar(0x1200); + sample += TQChar(0x1240); + sample += TQChar(0x1280); + sample += TQChar(0x12c0); + break; + case TQFont::Cherokee: + sample += TQChar(0x13a0); + sample += TQChar(0x13b0); + sample += TQChar(0x13c0); + sample += TQChar(0x13d0); + break; + case TQFont::CanadianAboriginal: + sample += TQChar(0x1410); + sample += TQChar(0x1500); + sample += TQChar(0x15f0); + sample += TQChar(0x1650); + break; + case TQFont::Mongolian: + sample += TQChar(0x1820); + sample += TQChar(0x1840); + sample += TQChar(0x1860); + sample += TQChar(0x1880); + break; + + + case TQFont::CurrencySymbols: + case TQFont::LetterlikeSymbols: + case TQFont::NumberForms: + case TQFont::MathematicalOperators: + case TQFont::TechnicalSymbols: + case TQFont::GeometricSymbols: + case TQFont::MiscellaneousSymbols: + case TQFont::EnclosedAndSquare: + case TQFont::Braille: + break; + + + case TQFont::Unicode: + sample += TQChar(0x0174); + sample += TQChar(0x0628); + sample += TQChar(0x0e02); + sample += TQChar(0x263A); + sample += TQChar(0x3129); + sample += TQChar(0x61a9); + sample += TQChar(0xac2f); + break; + + + + default: + sample += TQChar(0xfffd); + sample += TQChar(0xfffd); + sample += TQChar(0xfffd); + sample += TQChar(0xfffd); + break; + } + + return sample; +} + + + + +/*! + \internal + + This makes sense of the font family name: + + 1) if the family name contains a '-' (ie. "Adobe-Courier"), then we + split at the '-', and use the string as the foundry, and the string to + the right as the family + + 2) if the family name contains a '[' and a ']', then we take the text + between the square brackets as the foundry, and the text before the + square brackets as the family (ie. "Arial [Monotype]") +*/ +void TQFontDatabase::parseFontName(const TQString &name, TQString &foundry, TQString &family) +{ + if ( name.contains('-') ) { + int i = name.find('-'); + foundry = name.left( i ); + family = name.right( name.length() - i - 1 ); + } else if ( name.contains('[') && name.contains(']')) { + int i = name.find('['); + int li = name.findRev(']'); + + if (i < li) { + foundry = name.mid(i + 1, li - i - 1); + if (name[i - 1] == ' ') + i--; + family = name.left(i); + } + } else { + foundry = TQString::null; + family = name; + } +} + +#endif // TQT_NO_FONTDATABASE diff --git a/src/kernel/tqfontdatabase.h b/src/kernel/tqfontdatabase.h new file mode 100644 index 000000000..4a5e5c532 --- /dev/null +++ b/src/kernel/tqfontdatabase.h @@ -0,0 +1,219 @@ +/**************************************************************************** +** +** Definition of the TQFontDatabase class +** +** Created : 981126 +** +** Copyright (C) 1999-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef TQFONTDATABASE_H +#define TQFONTDATABASE_H + +#ifndef QT_H +#include "ntqwindowdefs.h" +#include "tqstring.h" +#include "tqstringlist.h" +#include "tqfont.h" +#include "tqvaluelist.h" +#endif // QT_H + + +#ifndef TQT_NO_FONTDATABASE + +class TQFontStylePrivate; /* Don't touch! */ +struct TQtFontStyle; +struct TQtFontFamily; +struct TQtFontFoundry; +struct TQFontDef; +class TQFontEngine; +class TQFontDatabasePrivate; + +class TQ_EXPORT TQFontDatabase +{ +public: + static TQValueList standardSizes(); + + TQFontDatabase(); + + TQStringList families() const; + TQStringList families( TQFont::Script ) const; + TQStringList styles( const TQString & ) const; + TQValueList pointSizes( const TQString &, const TQString & = TQString::null); + TQValueList smoothSizes( const TQString &, const TQString &); + TQString styleString( const TQFont &); + + TQFont font( const TQString &, const TQString &, int); + + bool isBitmapScalable( const TQString &, const TQString & = TQString::null) const; + bool isSmoothlyScalable( const TQString &, const TQString & = TQString::null) const; + bool isScalable( const TQString &, const TQString & = TQString::null) const; + bool isFixedPitch( const TQString &, const TQString & = TQString::null) const; + + bool italic( const TQString &, const TQString &) const; + bool bold( const TQString &, const TQString &) const; + int weight( const TQString &, const TQString &) const; + + static TQString scriptName(TQFont::Script); + static TQString scriptSample(TQFont::Script); + + // For source compatibility with < 3.0 +#ifndef TQT_NO_COMPAT + + TQStringList families(bool) const; + TQStringList styles( const TQString &, const TQString & ) const; + TQValueList pointSizes( const TQString &, const TQString &, const TQString & ); + TQValueList smoothSizes( const TQString &, const TQString &, const TQString & ); + + TQFont font( const TQString &, const TQString &, int, const TQString &); + + bool isBitmapScalable( const TQString &, const TQString &, const TQString & ) const; + bool isSmoothlyScalable( const TQString &, const TQString &, const TQString & ) const; + bool isScalable( const TQString &, const TQString &, const TQString & ) const; + bool isFixedPitch( const TQString &, const TQString &, const TQString & ) const; + + bool italic( const TQString &, const TQString &, const TQString & ) const; + bool bold( const TQString &, const TQString &, const TQString & ) const; + int weight( const TQString &, const TQString &, const TQString & ) const; + +#endif // TQT_NO_COMPAT + +private: +#if defined(TQ_WS_X11) || defined(TQ_WS_WIN) + static TQFontEngine *findFont( TQFont::Script script, const TQFontPrivate *fp, + const TQFontDef &request, int force_encoding_id = -1 ); +#endif // TQ_WS_X11 + + static void createDatabase(); + + static void parseFontName(const TQString &name, TQString &foundry, TQString &family); + + friend struct TQFontDef; + friend class TQFontPrivate; + friend class TQFontDialog; + friend class TQFontEngineLatinXLFD; + + TQFontDatabasePrivate *d; +}; + + +#ifndef TQT_NO_COMPAT + +inline TQStringList TQFontDatabase::families( bool ) const +{ + return families(); +} + +inline TQStringList TQFontDatabase::styles( const TQString &family, + const TQString & ) const +{ + return styles(family); +} + +inline TQValueList TQFontDatabase::pointSizes( const TQString &family, + const TQString &style , + const TQString & ) +{ + return pointSizes(family, style); +} + +inline TQValueList TQFontDatabase::smoothSizes( const TQString &family, + const TQString &style, + const TQString & ) +{ + return smoothSizes(family, style); +} + +inline TQFont TQFontDatabase::font( const TQString &familyName, + const TQString &style, + int pointSize, + const TQString &) +{ + return font(familyName, style, pointSize); +} + +inline bool TQFontDatabase::isBitmapScalable( const TQString &family, + const TQString &style, + const TQString & ) const +{ + return isBitmapScalable(family, style); +} + +inline bool TQFontDatabase::isSmoothlyScalable( const TQString &family, + const TQString &style, + const TQString & ) const +{ + return isSmoothlyScalable(family, style); +} + +inline bool TQFontDatabase::isScalable( const TQString &family, + const TQString &style, + const TQString & ) const +{ + return isScalable(family, style); +} + +inline bool TQFontDatabase::isFixedPitch( const TQString &family, + const TQString &style, + const TQString & ) const +{ + return isFixedPitch(family, style); +} + +inline bool TQFontDatabase::italic( const TQString &family, + const TQString &style, + const TQString & ) const +{ + return italic(family, style); +} + +inline bool TQFontDatabase::bold( const TQString &family, + const TQString &style, + const TQString & ) const +{ + return bold(family, style); +} + +inline int TQFontDatabase::weight( const TQString &family, + const TQString &style, + const TQString & ) const +{ + return weight(family, style); +} + +#endif // TQT_NO_COMPAT + +#endif // TQT_NO_FONTDATABASE + +#endif // TQFONTDATABASE_H diff --git a/src/kernel/tqfontdatabase_x11.cpp b/src/kernel/tqfontdatabase_x11.cpp new file mode 100644 index 000000000..49de442cd --- /dev/null +++ b/src/kernel/tqfontdatabase_x11.cpp @@ -0,0 +1,2031 @@ +/**************************************************************************** +** +** Implementation of platform specific TQFontDatabase +** +** Created : 970521 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#include + +#include +#include + +#include "qt_x11_p.h" + +#include +#include + +#include +#include +#include +#include + +#ifndef TQT_NO_XFTFREETYPE +#include +#include FT_FREETYPE_H +#endif + +#ifndef QT_XFT2 +#define FcBool Bool +#define FcTrue True +#define FcFalse False +#endif + +#ifdef TQFONTDATABASE_DEBUG +# define FD_DEBUG tqDebug +#else +# define FD_DEBUG if (FALSE) tqDebug +#endif // TQFONTDATABASE_DEBUG + +// from tqfont_x11.cpp +extern double qt_pointSize(double pixelSize, TQPaintDevice *paintdevice, int screen); +extern double qt_pixelSize(double pointSize, TQPaintDevice *paintdevice, int screen); + + +static inline void capitalize ( char *s ) +{ + bool space = TRUE; + while( *s ) { + if ( space ) + *s = toupper( *s ); + space = ( *s == ' ' ); + ++s; + } +} + + +// ----- begin of generated code ----- + +#define make_tag( c1, c2, c3, c4 ) \ +( (((unsigned int)c1)<<24) | (((unsigned int)c2)<<16) | \ +(((unsigned int)c3)<<8) | ((unsigned int)c4) ) + +struct XlfdEncoding { + const char *name; + int id; + int mib; + unsigned int hash1; + unsigned int hash2; +}; + +static const XlfdEncoding xlfd_encoding[] = { + { "iso8859-1", 0, 4, make_tag('i','s','o','8'), make_tag('5','9','-','1') }, + { "iso8859-2", 1, 5, make_tag('i','s','o','8'), make_tag('5','9','-','2') }, + { "iso8859-3", 2, 6, make_tag('i','s','o','8'), make_tag('5','9','-','3') }, + { "iso8859-4", 3, 7, make_tag('i','s','o','8'), make_tag('5','9','-','4') }, + { "iso8859-9", 4, 12, make_tag('i','s','o','8'), make_tag('5','9','-','9') }, + { "iso8859-10", 5, 13, make_tag('i','s','o','8'), make_tag('9','-','1','0') }, + { "iso8859-13", 6, 109, make_tag('i','s','o','8'), make_tag('9','-','1','3') }, + { "iso8859-14", 7, 110, make_tag('i','s','o','8'), make_tag('9','-','1','4') }, + { "iso8859-15", 8, 111, make_tag('i','s','o','8'), make_tag('9','-','1','5') }, + { "hp-roman8", 9, 2004, make_tag('h','p','-','r'), make_tag('m','a','n','8') }, + { "jisx0208*-0", 10, 63, make_tag('j','i','s','x'), 0 }, +#define LAST_LATIN_ENCODING 10 + { "iso8859-5", 11, 8, make_tag('i','s','o','8'), make_tag('5','9','-','5') }, + { "*-cp1251", 12, 2251, 0, make_tag('1','2','5','1') }, + { "koi8-ru", 13, 2084, make_tag('k','o','i','8'), make_tag('8','-','r','u') }, + { "koi8-u", 14, 2088, make_tag('k','o','i','8'), make_tag('i','8','-','u') }, + { "koi8-r", 15, 2084, make_tag('k','o','i','8'), make_tag('i','8','-','r') }, + { "iso8859-7", 16, 10, make_tag('i','s','o','8'), make_tag('5','9','-','7') }, + { "iso10646-1", 17, 0, make_tag('i','s','o','1'), make_tag('4','6','-','1') }, + { "iso8859-8", 18, 85, make_tag('i','s','o','8'), make_tag('5','9','-','8') }, + { "gb18030-0", 19, -114, make_tag('g','b','1','8'), make_tag('3','0','-','0') }, + { "gb18030.2000-0", 20, -113, make_tag('g','b','1','8'), make_tag('0','0','-','0') }, + { "gbk-0", 21, -113, make_tag('g','b','k','-'), make_tag('b','k','-','0') }, + { "gb2312.*-0", 22, 57, make_tag('g','b','2','3'), 0 }, + { "jisx0201*-0", 23, 15, make_tag('j','i','s','x'), 0 }, + { "ksc5601*-*", 24, 36, make_tag('k','s','c','5'), 0 }, + { "big5hkscs-0", 25, -2101, make_tag('b','i','g','5'), make_tag('c','s','-','0') }, + { "hkscs-1", 26, -2101, make_tag('h','k','s','c'), make_tag('c','s','-','1') }, + { "big5*-*", 27, -2026, make_tag('b','i','g','5'), 0 }, + { "tscii-*", 28, 2028, make_tag('t','s','c','i'), 0 }, + { "tis620*-*", 29, 2259, make_tag('t','i','s','6'), 0 }, + { "iso8859-11", 30, 2259, make_tag('i','s','o','8'), make_tag('9','-','1','1') }, + { "mulelao-1", 31, -4242, make_tag('m','u','l','e'), make_tag('a','o','-','1') }, + { "ethiopic-unicode", 32, 0, make_tag('e','t','h','i'), make_tag('c','o','d','e') }, + { "unicode-*", 33, 0, make_tag('u','n','i','c'), 0 }, + { "*-symbol", 34, 0, 0, make_tag('m','b','o','l') }, + { "*-fontspecific", 35, 0, 0, make_tag('i','f','i','c') }, + { "fontspecific-*", 36, 0, make_tag('f','o','n','t'), 0 }, + { 0, 0, 0, 0, 0 } +}; + +static const char scripts_for_xlfd_encoding[37][61] = { + // iso8859-1 + { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0 }, + // iso8859-2 + { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0 }, + // iso8859-3 + { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0 }, + // iso8859-4 + { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0 }, + // iso8859-9 + { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0 }, + // iso8859-10 + { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0 }, + // iso8859-13 + { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0 }, + // iso8859-14 + { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0 }, + // iso8859-15 + { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0 }, + // hp-roman8 + { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0 }, + // jisx0208*-0 + { 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, + 0 }, + // iso8859-5 + { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0 }, + // *-cp1251 + { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0 }, + // koi8-ru + { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0 }, + // koi8-u + { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0 }, + // koi8-r + { 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0 }, + // iso8859-7 + { 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0 }, + // iso10646-1 + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0 }, + // iso8859-8 + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0 }, + // gb18030-0 + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, + 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, + 0 }, + // gb18030.2000-0 + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, + 0 }, + // gbk-0 + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, + 0 }, + // gb2312.*-0 + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, + 0 }, + // jisx0201*-0 + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, + 0 }, + // ksc5601*-* + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, + 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1 }, + // big5hkscs-0 + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 0 }, + // hkscs-1 + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 0 }, + // big5*-* + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, + 0 }, + // tscii-* + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0 }, + // tis620*-* + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0 }, + // iso8859-11 + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0 }, + // mulelao-1 + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0 }, + // ethiopic-unicode + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0 }, + // unicode-* + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0 }, + // *-symbol + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, + 0 }, + // *-fontspecific + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, + 0 }, + // fontspecific-* + { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, + 0 } + +}; + +// ----- end of generated code ----- + + +const int numEncodings = sizeof( xlfd_encoding ) / sizeof( XlfdEncoding ) - 1; + +int qt_xlfd_encoding_id( const char *encoding ) +{ + // tqDebug("looking for encoding id for '%s'", encoding ); + int len = strlen( encoding ); + if ( len < 4 ) + return -1; + unsigned int hash1 = make_tag( encoding[0], encoding[1], encoding[2], encoding[3] ); + const char *ch = encoding + len - 4; + unsigned int hash2 = make_tag( ch[0], ch[1], ch[2], ch[3] ); + + const XlfdEncoding *enc = xlfd_encoding; + for ( ; enc->name; ++enc ) { + if ( (enc->hash1 && enc->hash1 != hash1) || + (enc->hash2 && enc->hash2 != hash2) ) + continue; + // hashes match, do a compare if strings match + // the enc->name can contain '*'s we have to interpret correctly + const char *n = enc->name; + const char *e = encoding; + while ( 1 ) { + // tqDebug("bol: *e='%c', *n='%c'", *e, *n ); + if ( *e == '\0' ) { + if ( *n ) + break; + // tqDebug( "found encoding id %d", enc->id ); + return enc->id; + } + if ( *e == *n ) { + ++e; + ++n; + continue; + } + if ( *n != '*' ) + break; + ++n; + // tqDebug("skip: *e='%c', *n='%c'", *e, *n ); + while ( *e && *e != *n ) + ++e; + } + } + // tqDebug( "couldn't find encoding %s", encoding ); + return -1; +} + +int qt_mib_for_xlfd_encoding( const char *encoding ) +{ + int id = qt_xlfd_encoding_id( encoding ); + if ( id != -1 ) return xlfd_encoding[id].mib; + return 0; +} + +int qt_encoding_id_for_mib( int mib ) +{ + const XlfdEncoding *enc = xlfd_encoding; + for ( ; enc->name; ++enc ) { + if ( enc->mib == mib ) + return enc->id; + } + return -1; +} + +static const char * xlfd_for_id( int id ) +{ + // special case: -1 returns the "*-*" encoding, allowing us to do full + // database population in a single X server round trip. + if ( id < 0 || id > numEncodings ) + return "*-*"; + return xlfd_encoding[id].name; +} + +enum XLFDFieldNames { + Foundry, + Family, + Weight, + Slant, + Width, + AddStyle, + PixelSize, + PointSize, + ResolutionX, + ResolutionY, + Spacing, + AverageWidth, + CharsetRegistry, + CharsetEncoding, + NFontFields +}; + +// Splits an X font name into fields separated by '-' +static bool parseXFontName( char *fontName, char **tokens ) +{ + if ( ! fontName || fontName[0] == '0' || fontName[0] != '-' ) { + tokens[0] = 0; + return FALSE; + } + + int i; + ++fontName; + for ( i = 0; i < NFontFields && fontName && fontName[0]; ++i ) { + tokens[i] = fontName; + for ( ;; ++fontName ) { + if ( *fontName == '-' ) + break; + if ( ! *fontName ) { + fontName = 0; + break; + } + } + + if ( fontName ) *fontName++ = '\0'; + } + + if ( i < NFontFields ) { + for ( int j = i ; j < NFontFields; ++j ) + tokens[j] = 0; + return FALSE; + } + + return TRUE; +} + +static inline bool isZero(char *x) +{ + return (x[0] == '0' && x[1] == 0); +} + +static inline bool isScalable( char **tokens ) +{ + return (isZero(tokens[PixelSize]) && + isZero(tokens[PointSize]) && + isZero(tokens[AverageWidth])); +} + +static inline bool isSmoothlyScalable( char **tokens ) +{ + return (isZero(tokens[ResolutionX]) && + isZero(tokens[ResolutionY])); +} + +static inline bool isFixedPitch( char **tokens ) +{ + return (tokens[Spacing][0] == 'm' || + tokens[Spacing][0] == 'c' || + tokens[Spacing][0] == 'M' || + tokens[Spacing][0] == 'C'); +} + +/* + Fills in a font definition (TQFontDef) from an XLFD (X Logical Font + Description). + + Returns TRUE if the the given xlfd is valid. The fields lbearing + and rbearing are not given any values. +*/ +bool qt_fillFontDef( const TQCString &xlfd, TQFontDef *fd, int screen ) +{ + char *tokens[NFontFields]; + TQCString buffer = xlfd.copy(); + if ( ! parseXFontName(buffer.data(), tokens) ) + return FALSE; + + capitalize(tokens[Family]); + capitalize(tokens[Foundry]); + + fd->family = TQString::fromLatin1(tokens[Family]); + TQString foundry = TQString::fromLatin1(tokens[Foundry]); + if ( ! foundry.isEmpty() && foundry != TQString::fromLatin1("*") ) + fd->family += + TQString::fromLatin1(" [") + foundry + TQString::fromLatin1("]"); + + if ( tqstrlen( tokens[AddStyle] ) > 0 ) + fd->addStyle = TQString::fromLatin1(tokens[AddStyle]); + else + fd->addStyle = TQString::null; + + fd->pointSize = atoi(tokens[PointSize]); + fd->styleHint = TQFont::AnyStyle; // ### any until we match families + + char slant = tolower( (uchar) tokens[Slant][0] ); + fd->italic = ( slant == 'o' || slant == 'i' ); + char fixed = tolower( (uchar) tokens[Spacing][0] ); + fd->fixedPitch = ( fixed == 'm' || fixed == 'c' ); + fd->weight = getFontWeight( tokens[Weight] ); + + int r = atoi(tokens[ResolutionY]); + fd->pixelSize = atoi(tokens[PixelSize]); + // not "0" or "*", or required DPI + if ( r && fd->pixelSize && TQPaintDevice::x11AppDpiY( screen ) && + r != TQPaintDevice::x11AppDpiY( screen ) ) { + // calculate actual pointsize for display DPI + fd->pointSize = tqRound(qt_pointSize(fd->pixelSize, 0, screen) * 10.); + } else if ( fd->pixelSize == 0 && fd->pointSize ) { + // calculate pixel size from pointsize/dpi + fd->pixelSize = tqRound(qt_pixelSize(fd->pointSize / 10., 0, screen)); + } + + return TRUE; +} + +/* + Fills in a font definition (TQFontDef) from the font properties in an + XFontStruct. + + Returns TRUE if the TQFontDef could be filled with properties from + the XFontStruct. The fields lbearing and rbearing are not given any + values. +*/ +static bool qt_fillFontDef( XFontStruct *fs, TQFontDef *fd, int screen ) +{ + unsigned long value; + if ( fs && !XGetFontProperty( fs, XA_FONT, &value ) ) + return FALSE; + + char *n = XGetAtomName( TQPaintDevice::x11AppDisplay(), value ); + TQCString xlfd( n ); + if ( n ) + XFree( n ); + return qt_fillFontDef( xlfd.lower(), fd, screen ); +} + + +static TQtFontStyle::Key getStyle( char ** tokens ) +{ + TQtFontStyle::Key key; + + char slant0 = tolower( (uchar) tokens[Slant][0] ); + + if ( slant0 == 'r' ) { + if ( tokens[Slant][1]) { + char slant1 = tolower( (uchar) tokens[Slant][1] ); + + if ( slant1 == 'o' ) + key.oblique = TRUE; + else if ( slant1 == 'i' ) + key.italic = TRUE; + } + } else if ( slant0 == 'o' ) + key.oblique = TRUE; + else if ( slant0 == 'i' ) + key.italic = TRUE; + + key.weight = getFontWeight( tokens[Weight] ); + + if ( qstrcmp( tokens[Width], "normal" ) == 0 ) { + key.stretch = 100; + } else if ( qstrcmp( tokens[Width], "semi condensed" ) == 0 || + qstrcmp( tokens[Width], "semicondensed" ) == 0 ) { + key.stretch = 90; + } else if ( qstrcmp( tokens[Width], "condensed" ) == 0 ) { + key.stretch = 80; + } else if ( qstrcmp( tokens[Width], "narrow" ) == 0 ) { + key.stretch = 60; + } + + return key; +} + + +extern bool tqt_has_xft; // defined in tqfont_x11.cpp + +static bool xlfdsFullyLoaded = FALSE; +static unsigned char encodingLoaded[numEncodings]; + +static void loadXlfds( const char *reqFamily, int encoding_id ) +{ + TQtFontFamily *fontFamily = reqFamily ? db->family( reqFamily ) : 0; + + // make sure we don't load twice + if ( (encoding_id == -1 && xlfdsFullyLoaded) || (encoding_id != -1 && encodingLoaded[encoding_id]) ) + return; + if ( fontFamily && fontFamily->xlfdLoaded ) + return; + +#ifdef QT_XFT2 + if ( !tqt_has_xft ) { +#endif // QT_XFT2 + int fontCount; + // force the X server to give us XLFDs + TQCString xlfd_pattern = "-*-"; + xlfd_pattern += reqFamily ? reqFamily : "*"; + xlfd_pattern += "-*-*-*-*-*-*-*-*-*-*-"; + xlfd_pattern += xlfd_for_id( encoding_id ); + + char **fontList = XListFonts( TQPaintDevice::x11AppDisplay(), + xlfd_pattern.data(), + 0xffff, &fontCount ); + // tqDebug("requesting xlfd='%s', got %d fonts", xlfd_pattern.data(), fontCount ); + + + char *tokens[NFontFields]; + + for( int i = 0 ; i < fontCount ; i++ ) { + if ( ! parseXFontName( fontList[i], tokens ) ) continue; + + // get the encoding_id for this xlfd. we need to do this + // here, since we can pass -1 to this function to do full + // database population + *(tokens[CharsetEncoding]-1) = '-'; + int encoding_id = qt_xlfd_encoding_id( tokens[CharsetRegistry] ); + if ( encoding_id == -1 ) + continue; + + char *familyName = tokens[Family]; + capitalize( familyName ); + char *foundryName = tokens[Foundry]; + capitalize( foundryName ); + TQtFontStyle::Key styleKey = getStyle( tokens ); + + bool smooth_scalable = FALSE; + bool bitmap_scalable = FALSE; + if ( isScalable(tokens) ) { + if ( isSmoothlyScalable( tokens ) ) + smooth_scalable = TRUE; + else + bitmap_scalable = TRUE; + } + uint pixelSize = atoi( tokens[PixelSize] ); + uint xpointSize = atoi( tokens[PointSize] ); + uint xres = atoi( tokens[ResolutionX] ); + uint yres = atoi( tokens[ResolutionY] ); + uint avgwidth = atoi( tokens[AverageWidth] ); + bool fixedPitch = isFixedPitch( tokens ); + + if (avgwidth == 0 && pixelSize != 0) { + /* + Ignore bitmap scalable fonts that are automatically + generated by some X servers. We know they are bitmap + scalable because even though they have a specified pixel + size, the average width is zero. + */ + continue; + } + + TQtFontFamily *family = fontFamily ? fontFamily : db->family( familyName, TRUE ); + family->fontFileIndex = -1; + TQtFontFoundry *foundry = family->foundry( foundryName, TRUE ); + TQtFontStyle *style = foundry->style( styleKey, TRUE ); + + delete [] style->weightName; + style->weightName = tqstrdup( tokens[Weight] ); + delete [] style->setwidthName; + style->setwidthName = tqstrdup( tokens[Width] ); + + if ( smooth_scalable ) { + style->smoothScalable = TRUE; + style->bitmapScalable = FALSE; + pixelSize = SMOOTH_SCALABLE; + } + if ( !style->smoothScalable && bitmap_scalable ) + style->bitmapScalable = TRUE; + if ( !fixedPitch ) + family->fixedPitch = FALSE; + + TQtFontSize *size = style->pixelSize( pixelSize, TRUE ); + TQtFontEncoding *enc = + size->encodingID( encoding_id, xpointSize, xres, yres, avgwidth, TRUE ); + enc->pitch = *tokens[Spacing]; + if ( !enc->pitch ) enc->pitch = '*'; + + for ( int script = 0; script < TQFont::LastPrivateScript; ++script ) { + if ( scripts_for_xlfd_encoding[encoding_id][script] ) + family->scripts[script] = TQtFontFamily::Supported; + else + family->scripts[script] |= TQtFontFamily::UnSupported_Xlfd; + } + if ( encoding_id == -1 ) + family->xlfdLoaded = TRUE; + } + if ( !reqFamily ) { + // mark encoding as loaded + if ( encoding_id == -1 ) + xlfdsFullyLoaded = TRUE; + else + encodingLoaded[encoding_id] = TRUE; + } + + XFreeFontNames( fontList ); + +#ifdef QT_XFT2 + } +#endif // QT_XFT2 +} + +#ifndef TQT_NO_XFTFREETYPE +static int getXftWeight(int xftweight) +{ + int qtweight = TQFont::Black; + if (xftweight <= (XFT_WEIGHT_LIGHT + XFT_WEIGHT_MEDIUM) / 2) + qtweight = TQFont::Light; + else if (xftweight <= (XFT_WEIGHT_MEDIUM + XFT_WEIGHT_DEMIBOLD) / 2) + qtweight = TQFont::Normal; + else if (xftweight <= (XFT_WEIGHT_DEMIBOLD + XFT_WEIGHT_BOLD) / 2) + qtweight = TQFont::DemiBold; + else if (xftweight <= (XFT_WEIGHT_BOLD + XFT_WEIGHT_BLACK) / 2) + qtweight = TQFont::Bold; + + return qtweight; +} + +static void loadXft() +{ + if (!tqt_has_xft) + return; + +#ifdef QT_XFT2 + struct XftDefaultFont { + const char *qtname; + const char *rawname; + bool fixed; + }; + const XftDefaultFont defaults[] = { + { "Serif", "serif", FALSE }, + { "Sans Serif", "sans-serif", FALSE }, + { "Monospace", "monospace", TRUE }, + { 0, 0, FALSE } + }; + const XftDefaultFont *f = defaults; + while (f->qtname) { + TQtFontFamily *family = db->family( f->qtname, TRUE ); + family->fixedPitch = f->fixed; + family->rawName = f->rawname; + family->hasXft = TRUE; + family->synthetic = TRUE; + TQtFontFoundry *foundry + = family->foundry( TQString::null, TRUE ); + + for ( int i = 0; i < TQFont::LastPrivateScript; ++i ) { + if (i == TQFont::UnknownScript) + continue; + family->scripts[i] = TQtFontFamily::Supported; + } + + TQtFontStyle::Key styleKey; + styleKey.oblique = FALSE; + for (int i = 0; i < 4; ++i) { + styleKey.italic = (i%2); + styleKey.weight = (i > 1) ? TQFont::Bold : TQFont::Normal; + TQtFontStyle *style = foundry->style( styleKey, TRUE ); + style->smoothScalable = TRUE; + TQtFontSize *size = style->pixelSize( SMOOTH_SCALABLE, TRUE ); + TQtFontEncoding *enc = size->encodingID( -1, 0, 0, 0, 0, TRUE ); + enc->pitch = (f->fixed ? 'm' : 'p'); + } + ++f; + } +#endif +} + +#ifdef XFT_MATRIX +static void checkXftMatrix( TQtFontFamily* family ) { + for ( int j = 0; j < family->count; ++j ) { // each foundry + TQtFontFoundry *foundry = family->foundries[j]; + for ( int k = 0; k < foundry->count; ++k ) { + TQtFontStyle *style = foundry->styles[k]; + if ( style->key.italic || style->key.oblique ) continue; + + TQtFontSize *size = style->pixelSize( SMOOTH_SCALABLE ); + if ( ! size ) continue; + TQtFontEncoding *enc = size->encodingID( -1, 0, 0, 0, 0, TRUE ); + if ( ! enc ) continue; + + TQtFontStyle::Key key = style->key; + + // does this style have an italic equivalent? + key.italic = TRUE; + TQtFontStyle *equiv = foundry->style( key ); + if ( equiv ) continue; + + // does this style have an oblique equivalent? + key.italic = FALSE; + key.oblique = TRUE; + equiv = foundry->style( key ); + if ( equiv ) continue; + + // let's fake one... + equiv = foundry->style( key, TRUE ); + equiv->fakeOblique = TRUE; + equiv->smoothScalable = TRUE; + + TQtFontSize *equiv_size = equiv->pixelSize( SMOOTH_SCALABLE, TRUE ); + TQtFontEncoding *equiv_enc = equiv_size->encodingID( -1, 0, 0, 0, 0, TRUE ); + + // keep the same pitch + equiv_enc->pitch = enc->pitch; + } + } +} +#endif // XFT_MATRIX + +static bool loadXftFont( FcPattern* font ) +{ + TQString familyName; + TQString rawName; + char *value; + int weight_value; + int slant_value; + int spacing_value; + char *file_value; + int index_value; + char *foundry_value = 0; + FcBool scalable = FcTrue; + + if (XftPatternGetString( font, + XFT_FAMILY, 0, &value) != XftResultMatch ) + return false; + // capitalize( value ); + rawName = familyName = TQString::fromUtf8(value); + familyName.replace('-', ' '); + familyName.replace("/", ""); + + slant_value = XFT_SLANT_ROMAN; + weight_value = XFT_WEIGHT_MEDIUM; + spacing_value = XFT_PROPORTIONAL; + file_value = 0; + index_value = 0; + XftPatternGetInteger (font, XFT_SLANT, 0, &slant_value); + XftPatternGetInteger (font, XFT_WEIGHT, 0, &weight_value); + XftPatternGetInteger (font, XFT_SPACING, 0, &spacing_value); + XftPatternGetString (font, XFT_FILE, 0, &file_value); + XftPatternGetInteger (font, XFT_INDEX, 0, &index_value); +#ifdef QT_XFT2 + FcPatternGetBool(font, FC_SCALABLE, 0, &scalable); + foundry_value = 0; + XftPatternGetString(font, FC_FOUNDRY, 0, &foundry_value); +#endif + TQtFontFamily *family = db->family( familyName, TRUE ); + family->rawName = rawName; + family->hasXft = TRUE; + +#ifdef QT_XFT2 + FcCharSet *charset = 0; + FcResult res = FcPatternGetCharSet(font, FC_CHARSET, 0, &charset); + if (res == FcResultMatch && FcCharSetCount(charset) > 1) { + for (int i = 0; i < TQFont::LastPrivateScript; ++i) { + bool supported = sample_chars[i][0]; + for (int j = 0; sample_chars[i][j]; ++j){ + if (!FcCharSetHasChar(charset, sample_chars[i][j])) { + supported = false; + break; + } + } + if ( supported ){ + family->scripts[i] = TQtFontFamily::Supported; + } else { + family->scripts[i] |= TQtFontFamily::UnSupported_Xft; + } + } + family->xftScriptCheck = TRUE; + } else { + // we set UnknownScript to supported for symbol fonts. It makes no sense to merge these + // with other ones, as they are special in a way. + for ( int i = 0; i < TQFont::LastPrivateScript; ++i ) + family->scripts[i] |= TQtFontFamily::UnSupported_Xft; + family->scripts[TQFont::UnknownScript] = TQtFontFamily::Supported; + } +#endif // QT_XFT2 + + TQCString file = (file_value ? file_value : ""); + family->fontFilename = file; + family->fontFileIndex = index_value; + + TQtFontStyle::Key styleKey; + styleKey.italic = (slant_value == XFT_SLANT_ITALIC); + styleKey.oblique = (slant_value == XFT_SLANT_OBLIQUE); + styleKey.weight = getXftWeight( weight_value ); +#ifdef QT_XFT2 + if (!scalable) { + int width = 100; +#if FC_VERSION >= 20193 + XftPatternGetInteger (font, FC_WIDTH, 0, &width); +#endif + styleKey.stretch = width; + } +#endif + + TQtFontFoundry *foundry + = family->foundry( foundry_value ? TQString::fromUtf8(foundry_value) : TQString::null, TRUE ); + TQtFontStyle *style = foundry->style( styleKey, TRUE ); + + if (spacing_value < XFT_MONO ) + family->fixedPitch = FALSE; + + TQtFontSize *size; + if (scalable) { + style->smoothScalable = TRUE; + size = style->pixelSize( SMOOTH_SCALABLE, TRUE ); + } +#ifdef QT_XFT2 + else { + double pixel_size = 0; + XftPatternGetDouble (font, FC_PIXEL_SIZE, 0, &pixel_size); + size = style->pixelSize( (int)pixel_size, TRUE ); + } +#endif + TQtFontEncoding *enc = size->encodingID( -1, 0, 0, 0, 0, TRUE ); + enc->pitch = ( spacing_value >= XFT_CHARCELL ? 'c' : + ( spacing_value >= XFT_MONO ? 'm' : 'p' ) ); + + checkXftMatrix( family ); + + return true; +} + +#ifndef QT_XFT2 + +#define MAKE_TAG( _x1, _x2, _x3, _x4 ) \ + ( ( (TQ_UINT32)_x1 << 24 ) | \ + ( (TQ_UINT32)_x2 << 16 ) | \ + ( (TQ_UINT32)_x3 << 8 ) | \ + (TQ_UINT32)_x4 ) + +#ifdef _POSIX_MAPPED_FILES +static inline TQ_UINT32 getUInt(unsigned char *p) +{ + TQ_UINT32 val; + val = *p++ << 24; + val |= *p++ << 16; + val |= *p++ << 8; + val |= *p; + + return val; +} + +static inline TQ_UINT16 getUShort(unsigned char *p) +{ + TQ_UINT16 val; + val = *p++ << 8; + val |= *p; + + return val; +} + +static inline void tag_to_string( char *string, TQ_UINT32 tag ) +{ + string[0] = (tag >> 24)&0xff; + string[1] = (tag >> 16)&0xff; + string[2] = (tag >> 8)&0xff; + string[3] = tag&0xff; + string[4] = 0; +} + +static TQ_UINT16 getGlyphIndex( unsigned char *table, TQ_UINT16 format, unsigned short unicode ) +{ + if ( format == 0 ) { + if ( unicode < 256 ) + return (int) *(table+6+unicode); + } else if ( format == 2 ) { + tqWarning("format 2 encoding table for Unicode, not implemented!"); + } else if ( format == 4 ) { + TQ_UINT16 segCountX2 = getUShort( table + 6 ); + unsigned char *ends = table + 14; + TQ_UINT16 endIndex = 0; + int i = 0; + for ( ; i < segCountX2/2 && (endIndex = getUShort( ends + 2*i )) < unicode; i++ ); + + unsigned char *idx = ends + segCountX2 + 2 + 2*i; + TQ_UINT16 startIndex = getUShort( idx ); + + if ( startIndex > unicode ) + return 0; + + idx += segCountX2; + TQ_INT16 idDelta = (TQ_INT16)getUShort( idx ); + idx += segCountX2; + TQ_UINT16 idRangeoffset_t = (TQ_UINT16)getUShort( idx ); + + TQ_UINT16 glyphIndex; + if ( idRangeoffset_t ) { + TQ_UINT16 id = getUShort( idRangeoffset_t + 2*(unicode - startIndex) + idx); + if ( id ) + glyphIndex = ( idDelta + id ) % 0x10000; + else + glyphIndex = 0; + } else { + glyphIndex = (idDelta + unicode) % 0x10000; + } + return glyphIndex; + } + + return 0; +} +#endif // _POSIX_MAPPED_FILES + +static inline void checkXftCoverage( TQtFontFamily *family ) +{ +#ifdef _POSIX_MAPPED_FILES + TQCString ext = family->fontFilename.mid( family->fontFilename.findRev( '.' ) ).lower(); + if ( family->fontFileIndex == 0 && ( ext == ".ttf" || ext == ".otf" ) ) { + void *map; + // tqDebug("using own ttf code coverage checking of '%s'!", family->name.latin1() ); + int fd = open( family->fontFilename.data(), O_RDONLY ); + size_t pagesize = getpagesize(); + off_t offset = 0; + size_t length = (8192 / pagesize + 1) * pagesize; + + if ( fd == -1 ) + goto xftCheck; + { + if ( (map = mmap( 0, length, PROT_READ, MAP_SHARED, fd, offset ) ) == MAP_FAILED ) + goto error; + + unsigned char *ttf = (unsigned char *)map; + TQ_UINT32 version = getUInt( ttf ); + if ( version != 0x00010000 ) { + // tqDebug("file has wrong version %x", version ); + goto error1; + } + TQ_UINT16 numTables = getUShort( ttf+4 ); + + unsigned char *table_dir = ttf + 12; + TQ_UINT32 cmap_offset = 0; + TQ_UINT32 cmap_length = 0; + for ( int n = 0; n < numTables; n++ ) { + TQ_UINT32 tag = getUInt( table_dir + 16*n ); + if ( tag == MAKE_TAG( 'c', 'm', 'a', 'p' ) ) { + cmap_offset = getUInt( table_dir + 16*n + 8 ); + cmap_length = getUInt( table_dir + 16*n + 12 ); + break; + } + } + if ( !cmap_offset ) { + // tqDebug("no cmap found" ); + goto error1; + } + + if ( cmap_offset + cmap_length > length ) { + munmap( map, length ); + offset = cmap_offset / pagesize * pagesize; + cmap_offset -= offset; + length = (cmap_offset + cmap_length); + if ( (map = mmap( 0, length, PROT_READ, MAP_SHARED, fd, offset ) ) == MAP_FAILED ) + goto error; + } + + unsigned char *cmap = ((unsigned char *)map) + cmap_offset; + + version = getUShort( cmap ); + if ( version != 0 ) { + // tqDebug("wrong cmap version" ); + goto error1; + } + numTables = getUShort( cmap + 2 ); + unsigned char *unicode_table = 0; + bool symbol_table = TRUE; + for ( int n = 0; n < numTables; n++ ) { + TQ_UINT32 version = getUInt( cmap + 4 + 8*n ); + // accept both symbol and Unicode encodings. prefer unicode. + if ( version == 0x00030001 || version == 0x00030000 ) { + unicode_table = cmap + getUInt( cmap + 4 + 8*n + 4 ); + if ( version == 0x00030001 ) { + symbol_table = FALSE; + break; + } + } + } + + if ( !unicode_table ) { + // tqDebug("no unicode table found" ); + goto error1; + } + + TQ_UINT16 format = getUShort( unicode_table ); + if ( format != 4 ) + goto error1; + + if (symbol_table) { + // we set UnknownScript to supported for symbol fonts. It makes no sense to merge these + // with other ones, as they are special in a way. + for ( int i = 0; i < TQFont::LastPrivateScript; ++i ) + family->scripts[i] |= TQtFontFamily::UnSupported_Xft; + family->scripts[TQFont::UnknownScript] = TQtFontFamily::Supported; + } else { + for ( int i = 0; i < TQFont::LastPrivateScript; ++i ) { + + bool supported = sample_chars[i][0]; + for (int j = 0; sample_chars[i][j]; ++j) { + if (!getGlyphIndex(unicode_table, format, sample_chars[i][j])) { + supported=false; + break; + } + } + if ( supported ){ + // tqDebug("font can render script %d", i ); + family->scripts[i] = TQtFontFamily::Supported; + } else { + family->scripts[i] |= TQtFontFamily::UnSupported_Xft; + } + } + } + family->xftScriptCheck = TRUE; + } + error1: + munmap( map, length ); + error: + close( fd ); + if ( family->xftScriptCheck ) + return; + } + xftCheck: +#endif // _POSIX_MAPPED_FILES + + FD_DEBUG("using Freetype for checking of '%s'", family->name.latin1() ); + + FT_Library ft_lib; + FT_Error error = FT_Init_FreeType( &ft_lib ); + if ( error ) return; + FT_Face face; + error = FT_New_Face( ft_lib, family->fontFilename, family->fontFileIndex, &face ); + if ( error ) return; + + for ( int i = 0; i < TQFont::LastPrivateScript; ++i ) { + bool supported = sample_chars[i][j]; + for (int j = 0; sample_chars[i][j]; ++j){ + if (!FT_Get_Char_Index(face, sample_chars[i][j])) { + supported=false; + break; + } + } + if ( supported ){ + FD_DEBUG("font can render char %04x, %04x script %d '%s'", + ch.unicode(), FT_Get_Char_Index ( face, ch.unicode() ), + i, TQFontDatabase::scriptName( (TQFont::Script)i ).latin1() ); + + family->scripts[i] = TQtFontFamily::Supported; + } else { + family->scripts[i] |= TQtFontFamily::UnSupported_Xft; + } + } + FT_Done_Face( face ); + FT_Done_FreeType( ft_lib ); + family->xftScriptCheck = TRUE; +} +#endif // QT_XFT2 +#endif // TQT_NO_XFTFREETYPE + +static void load( const TQString &family = TQString::null, int script = -1 ) +{ +#ifdef TQFONTDATABASE_DEBUG + TQTime t; + t.start(); +#endif + + if ( family.isNull() ) { +#ifndef TQT_NO_XFTFREETYPE + static bool xft_readall_done = false; + if (tqt_has_xft && !xft_readall_done) { + xft_readall_done = true; + XftFontSet *fonts = + XftListFonts(TQPaintDevice::x11AppDisplay(), + TQPaintDevice::x11AppScreen(), + (const char *)0, + XFT_FAMILY, XFT_WEIGHT, XFT_SLANT, + XFT_SPACING, XFT_FILE, XFT_INDEX, +#ifdef QT_XFT2 + FC_CHARSET, FC_FOUNDRY, FC_SCALABLE, FC_PIXEL_SIZE, +#if FC_VERSION >= 20193 + FC_WIDTH, +#endif +#endif // QT_XFT2 + (const char *)0); + for (int i = 0; i < fonts->nfont; i++) + loadXftFont( fonts->fonts[i] ); + XftFontSetDestroy (fonts); + } +#ifdef QT_XFT2 + if (tqt_has_xft) + return; +#endif +#endif // TQT_NO_XFTFREETYPE + if ( script == -1 ) + loadXlfds( 0, -1 ); + else { + for ( int i = 0; i < numEncodings; i++ ) { + if ( scripts_for_xlfd_encoding[i][script] ) + loadXlfds( 0, i ); + } + } + } else { + TQtFontFamily *f = db->family( family, TRUE ); + if ( !f->fullyLoaded ) { + +#ifndef TQT_NO_XFTFREETYPE + if (tqt_has_xft) { + TQString mfamily = family; + redo: + XftFontSet *fonts = + XftListFonts(TQPaintDevice::x11AppDisplay(), + TQPaintDevice::x11AppScreen(), + XFT_FAMILY, XftTypeString, mfamily.utf8().data(), + (const char *)0, + XFT_FAMILY, XFT_WEIGHT, XFT_SLANT, + XFT_SPACING, XFT_FILE, XFT_INDEX, +#ifdef QT_XFT2 + FC_CHARSET, FC_FOUNDRY, FC_SCALABLE, FC_PIXEL_SIZE, +#if FC_VERSION >= 20193 + FC_WIDTH, +#endif +#endif // QT_XFT2 + (const char *)0); + for (int i = 0; i < fonts->nfont; i++) + loadXftFont( fonts->fonts[i] ); + XftFontSetDestroy (fonts); + if (mfamily.contains(' ')) { + mfamily.replace(TQChar(' '), TQChar('-')); + goto redo; + } + f->fullyLoaded = TRUE; +#ifdef QT_XFT2 + return; +#endif + } +#ifndef QT_XFT2 + // need to check Xft coverage + if ( f->hasXft && !f->xftScriptCheck ) { + checkXftCoverage( f ); + } +#endif +#endif // TQT_NO_XFTFREETYPE + // could reduce this further with some more magic: + // would need to remember the encodings loaded for the family. + if ( ( script == -1 && !f->xlfdLoaded ) || + ( !f->hasXft && !(f->scripts[script] & TQtFontFamily::Supported) && + !(f->scripts[script] & TQtFontFamily::UnSupported_Xlfd) ) ) { + loadXlfds( family, -1 ); + f->fullyLoaded = TRUE; + } + } + } + +#ifdef TQFONTDATABASE_DEBUG + FD_DEBUG("TQFontDatabase: load( %s, %d) took %d ms", family.latin1(), script, t.elapsed() ); +#endif +} + + +static void initializeDb() +{ + if ( db ) return; + db = new TQFontDatabasePrivate; + tqfontdatabase_cleanup.set(&db); + +#ifndef QT_XFT2 + memset( encodingLoaded, FALSE, sizeof( encodingLoaded ) ); +#endif + + TQTime t; + t.start(); + +#ifndef TQT_NO_XFTFREETYPE + loadXft(); + FD_DEBUG("TQFontDatabase: loaded Xft: %d ms", t.elapsed() ); +#endif + + t.start(); + +#ifndef TQT_NO_XFTFREETYPE + for ( int i = 0; i < db->count; i++ ) { +#ifndef QT_XFT2 + checkXftCoverage( db->families[i] ); + FD_DEBUG("TQFontDatabase: xft coverage check: %d ms", t.elapsed() ); +#endif // QT_XFT2 + +#ifdef XFT_MATRIX + checkXftMatrix( db->families[i] ); +#endif // XFT_MATRIX + } +#endif + + +#ifdef TQFONTDATABASE_DEBUG +#ifdef QT_XFT2 + if (!tqt_has_xft) +#endif + // load everything at startup in debug mode. + loadXlfds( 0, -1 ); + + // print the database + for ( int f = 0; f < db->count; f++ ) { + TQtFontFamily *family = db->families[f]; + FD_DEBUG("'%s' %s hasXft=%s", family->name.latin1(), (family->fixedPitch ? "fixed" : ""), + (family->hasXft ? "yes" : "no") ); + for ( int i = 0; i < TQFont::LastPrivateScript; ++i ) { + FD_DEBUG("\t%s: %s", TQFontDatabase::scriptName((TQFont::Script) i).latin1(), + ((family->scripts[i] & TQtFontFamily::Supported) ? "Supported" : + (family->scripts[i] & TQtFontFamily::UnSupported) == TQtFontFamily::UnSupported ? + "UnSupported" : "Unknown")); + } + + for ( int fd = 0; fd < family->count; fd++ ) { + TQtFontFoundry *foundry = family->foundries[fd]; + FD_DEBUG("\t\t'%s'", foundry->name.latin1() ); + for ( int s = 0; s < foundry->count; s++ ) { + TQtFontStyle *style = foundry->styles[s]; + FD_DEBUG("\t\t\tstyle: italic=%d oblique=%d (fake=%d) weight=%d (%s)\n" + "\t\t\tstretch=%d (%s)", + style->key.italic, style->key.oblique, style->fakeOblique, style->key.weight, + style->weightName, style->key.stretch, + style->setwidthName ? style->setwidthName : "nil" ); + if ( style->smoothScalable ) + FD_DEBUG("\t\t\t\tsmooth scalable" ); + else if ( style->bitmapScalable ) + FD_DEBUG("\t\t\t\tbitmap scalable" ); + if ( style->pixelSizes ) { + tqDebug("\t\t\t\t%d pixel sizes", style->count ); + for ( int z = 0; z < style->count; ++z ) { + TQtFontSize *size = style->pixelSizes + z; + for ( int e = 0; e < size->count; ++e ) { + FD_DEBUG( "\t\t\t\t size %5d pitch %c encoding %s", + size->pixelSize, + size->encodings[e].pitch, + xlfd_for_id( size->encodings[e].encoding ) ); + } + } + } + } + } + } +#endif // TQFONTDATABASE_DEBUG +} + +void TQFontDatabase::createDatabase() +{ + initializeDb(); +} + + +// -------------------------------------------------------------------------------------- +// font loader +// -------------------------------------------------------------------------------------- +#define MAXFONTSIZE_XFT 256 +#define MAXFONTSIZE_XLFD 128 +#ifndef TQT_NO_XFTFREETYPE +static double addPatternProps(XftPattern *pattern, const TQtFontStyle::Key &key, bool fakeOblique, + bool smoothScalable, const TQFontPrivate *fp, const TQFontDef &request) +{ + int weight_value = XFT_WEIGHT_BLACK; + if ( key.weight == 0 ) + weight_value = XFT_WEIGHT_MEDIUM; + else if ( key.weight < (TQFont::Light + TQFont::Normal) / 2 ) + weight_value = XFT_WEIGHT_LIGHT; + else if ( key.weight < (TQFont::Normal + TQFont::DemiBold) / 2 ) + weight_value = XFT_WEIGHT_MEDIUM; + else if ( key.weight < (TQFont::DemiBold + TQFont::Bold) / 2 ) + weight_value = XFT_WEIGHT_DEMIBOLD; + else if ( key.weight < (TQFont::Bold + TQFont::Black) / 2 ) + weight_value = XFT_WEIGHT_BOLD; + XftPatternAddInteger( pattern, XFT_WEIGHT, weight_value ); + + int slant_value = XFT_SLANT_ROMAN; + if ( key.italic ) + slant_value = XFT_SLANT_ITALIC; + else if ( key.oblique && !fakeOblique ) + slant_value = XFT_SLANT_OBLIQUE; + XftPatternAddInteger( pattern, XFT_SLANT, slant_value ); + + /* + Xft1 doesn't obey user settings for turning off anti-aliasing using + the following: + + match any size > 6 size < 12 edit antialias = false; + + ... if we request pixel sizes. so, work around this limitiation and + convert the pixel size to a point size and request that. + */ + double size_value = request.pixelSize; + double dpi = TQPaintDevice::x11AppDpiY(fp->screen); + double scale = 1.; + if ( size_value > MAXFONTSIZE_XFT ) { + scale = (double)size_value/(double)MAXFONTSIZE_XFT; + size_value = MAXFONTSIZE_XFT; + } + +#ifdef QT_XFT2 + /* + 2006-12-28 If QT is not compiled against xft1, there is no need + for the workaround above (confirmed). Thus, in addition, add + font pixelsize to the pattern to avoid fontconfig making wrong + guesses. Also provide a DPI value for fontconfig so it never + attempts to fallback to its default. + */ + XftPatternAddDouble(pattern, XFT_PIXEL_SIZE, size_value); + XftPatternAddDouble(pattern, XFT_DPI, dpi); +#endif + size_value = size_value*72./dpi; + XftPatternAddDouble( pattern, XFT_SIZE, size_value ); + +#ifdef XFT_MATRIX +# ifdef QT_XFT2 + if (!smoothScalable) { +# if FC_VERSION >= 20193 + int stretch = request.stretch; + if (!stretch) + stretch = 100; + XftPatternAddInteger(pattern, FC_WIDTH, stretch); +# endif + } else +# endif + if ( ( request.stretch > 0 && request.stretch != 100 ) || + ( key.oblique && fakeOblique ) ) { + XftMatrix matrix; + XftMatrixInit( &matrix ); + + if ( request.stretch > 0 && request.stretch != 100 ) + XftMatrixScale( &matrix, double( request.stretch ) / 100.0, 1.0 ); + if ( key.oblique && fakeOblique ) + XftMatrixShear( &matrix, 0.20, 0.0 ); + + XftPatternAddMatrix( pattern, XFT_MATRIX, &matrix ); + } +#endif // XFT_MATRIX + if (request.styleStrategy & (TQFont::PreferAntialias|TQFont::NoAntialias)) { + XftPatternDel(pattern, XFT_ANTIALIAS); + XftPatternAddBool(pattern, XFT_ANTIALIAS, + !(request.styleStrategy & TQFont::NoAntialias)); + } + + return scale; +} +#endif // TQT_NO_XFTFREETYPE + +static +TQFontEngine *loadEngine( TQFont::Script script, + const TQFontPrivate *fp, const TQFontDef &request, + TQtFontFamily *family, TQtFontFoundry *foundry, + TQtFontStyle *style, TQtFontSize *size, + TQtFontEncoding *encoding, bool forced_encoding ) +{ + Q_UNUSED(script); + + if ( fp && fp->rawMode ) { + TQCString xlfd = request.family.latin1(); + FM_DEBUG( "Loading XLFD (rawmode) '%s'", xlfd.data() ); + + XFontStruct *xfs; + if (! (xfs = XLoadQueryFont(TQPaintDevice::x11AppDisplay(), xlfd.data() ) ) ) + return 0; + + TQFontEngine *fe = new TQFontEngineXLFD( xfs, xlfd.data(), 0 ); + if ( ! qt_fillFontDef( xfs, &fe->fontDef, TQPaintDevice::x11AppScreen() ) && + ! qt_fillFontDef( xlfd, &fe->fontDef, TQPaintDevice::x11AppScreen() ) ) + fe->fontDef = TQFontDef(); + + return fe; + } + +#ifndef TQT_NO_XFTFREETYPE + if ( encoding->encoding == -1 ) { + + FM_DEBUG( " using Xft" ); + + XftPattern *pattern = XftPatternCreate(); + if ( !pattern ) return 0; + + bool symbol = (family->scripts[TQFont::UnknownScript] == TQtFontFamily::Supported); +# ifdef QT_XFT2 + if (!symbol && script != TQFont::Unicode) { + FcCharSet *cs = FcCharSetCreate(); + for ( int j=0; sample_chars[script][j]; j++ ) + FcCharSetAddChar(cs, sample_chars[script][j]); + if (script == TQFont::Latin) + // add Euro character + FcCharSetAddChar(cs, 0x20ac); + FcPatternAddCharSet(pattern, FC_CHARSET, cs); + FcCharSetDestroy(cs); + } +# else + XftPatternAddString( pattern, XFT_ENCODING, symbol ? "adobe-fontspecific" : "iso10646-1"); +# endif // QT_XFT2 + + if ( !foundry->name.isEmpty() ) + XftPatternAddString( pattern, XFT_FOUNDRY, + foundry->name.utf8().data() ); + + if ( !family->rawName.isEmpty() ) + XftPatternAddString( pattern, XFT_FAMILY, + family->rawName.utf8().data() ); + + + char pitch_value = ( encoding->pitch == 'c' ? XFT_CHARCELL : + ( encoding->pitch == 'm' ? XFT_MONO : XFT_PROPORTIONAL ) ); + XftPatternAddInteger( pattern, XFT_SPACING, pitch_value ); + + double scale = addPatternProps(pattern, style->key, style->fakeOblique, + style->smoothScalable, fp, request); + + XftResult res; + XftPattern *result = + XftFontMatch( TQPaintDevice::x11AppDisplay(), fp->screen, pattern, &res ); +#ifdef QT_XFT2 + if (result && script == TQFont::Latin) { + // since we added the Euro char on top, check we actually got the family + // we requested. If we didn't get it correctly, remove the Euro from the pattern + // and try again. + FcChar8 *f; + res = FcPatternGetString(result, FC_FAMILY, 0, &f); + if (res == FcResultMatch && TQString::fromUtf8((char *)f) != family->rawName) { + FcPatternDel(pattern, FC_CHARSET); + FcCharSet *cs = FcCharSetCreate(); + for ( int j=0; sample_chars[script][j]; j++ ) + FcCharSetAddChar(cs, sample_chars[script][j]); + FcPatternAddCharSet(pattern, FC_CHARSET, cs); + FcCharSetDestroy(cs); + result = XftFontMatch( TQPaintDevice::x11AppDisplay(), fp->screen, pattern, &res ); + } + } +#endif + XftPatternDestroy(pattern); + if (!result) + return 0; + + // somehow this gets lost in the XftMatch call, reset the anitaliasing property correctly. + if (request.styleStrategy & (TQFont::PreferAntialias|TQFont::NoAntialias)) { + XftPatternDel(result, XFT_ANTIALIAS); + XftPatternAddBool(result, XFT_ANTIALIAS, + !(request.styleStrategy & TQFont::NoAntialias)); + } + // We pass a duplicate to XftFontOpenPattern because either xft font + // will own the pattern after the call or the pattern will be + // destroyed. + XftPattern *dup = XftPatternDuplicate( result ); + XftFont *xftfs = XftFontOpenPattern( TQPaintDevice::x11AppDisplay(), dup ); + + if ( ! xftfs ) // Xft couldn't find a font? + return 0; + + TQFontEngine *fe = new TQFontEngineXft( xftfs, result, symbol ? 1 : 0 ); + if (fp->paintdevice + && TQPaintDeviceMetrics(fp->paintdevice).logicalDpiY() != TQPaintDevice::x11AppDpiY()) { + double px; + XftPatternGetDouble(result, XFT_PIXEL_SIZE, 0, &px); + scale = (double)request.pixelSize/px; + } + fe->setScale( scale ); + return fe; + } +#endif // TQT_NO_XFTFREETYPE + + FM_DEBUG( " using XLFD" ); + + TQCString xlfd = "-"; + xlfd += foundry->name.isEmpty() ? "*" : foundry->name.latin1(); + xlfd += "-"; + xlfd += family->name.isEmpty() ? "*" : family->name.latin1(); + + xlfd += "-"; + xlfd += style->weightName ? style->weightName : "*"; + xlfd += "-"; + xlfd += ( style->key.italic ? "i" : ( style->key.oblique ? "o" : "r" ) ); + + xlfd += "-"; + xlfd += style->setwidthName ? style->setwidthName : "*"; + // ### handle add-style + xlfd += "-*-"; + + int px = size->pixelSize; + if ( style->smoothScalable && px == SMOOTH_SCALABLE ) + px = request.pixelSize; + else if ( style->bitmapScalable && px == 0 ) + px = request.pixelSize; + double scale = 1.; + if ( px > MAXFONTSIZE_XLFD ) { + scale = (double)px/(double)MAXFONTSIZE_XLFD; + px = MAXFONTSIZE_XLFD; + } + if (fp && fp->paintdevice + && TQPaintDeviceMetrics(fp->paintdevice).logicalDpiY() != TQPaintDevice::x11AppDpiY()) + scale = (double)request.pixelSize/(double)px; + + xlfd += TQString::number( px ).latin1(); + xlfd += "-"; + xlfd += TQString::number( encoding->xpoint ); + xlfd += "-"; + xlfd += TQString::number( encoding->xres ); + xlfd += "-"; + xlfd += TQString::number( encoding->yres ); + xlfd += "-"; + + // ### handle cell spaced fonts + xlfd += encoding->pitch; + xlfd += "-"; + xlfd += TQString::number( encoding->avgwidth ); + xlfd += "-"; + xlfd += xlfd_for_id( encoding->encoding ); + + FM_DEBUG( " xlfd: '%s'", xlfd.data() ); + + XFontStruct *xfs; + if (! (xfs = XLoadQueryFont(TQPaintDevice::x11AppDisplay(), xlfd.data() ) ) ) + return 0; + + TQFontEngine *fe = 0; + const int mib = xlfd_encoding[ encoding->encoding ].mib; + if (script == TQFont::Latin && encoding->encoding <= LAST_LATIN_ENCODING && !forced_encoding) { + fe = new TQFontEngineLatinXLFD( xfs, xlfd.data(), mib ); + } else { + fe = new TQFontEngineXLFD( xfs, xlfd.data(), mib ); + } + + fe->setScale( scale ); + + return fe; +} + + +#ifdef QT_XFT2 + +static void parseFontName(const TQString &name, TQString &foundry, TQString &family) +{ + if ( name.contains('[') && name.contains(']')) { + int i = name.find('['); + int li = name.findRev(']'); + + if (i < li) { + foundry = name.mid(i + 1, li - i - 1); + if (name[i - 1] == ' ') + i--; + family = name.left(i); + } + } else { + foundry = TQString::null; + family = name; + } +} + + +static TQFontEngine *loadFontConfigFont(const TQFontPrivate *fp, const TQFontDef &request, TQFont::Script script) +{ + if (!tqt_has_xft) + return 0; + + TQStringList family_list; + if (request.family.isEmpty()) { + family_list = TQStringList::split(TQChar(','), fp->request.family); + + TQString stylehint; + switch ( request.styleHint ) { + case TQFont::SansSerif: + stylehint = "sans-serif"; + break; + case TQFont::Serif: + stylehint = "serif"; + break; + case TQFont::TypeWriter: + stylehint = "monospace"; + break; + default: + if (request.fixedPitch) + stylehint = "monospace"; + break; + } + if (!stylehint.isEmpty()) + family_list << stylehint; + } else { + family_list << request.family; + } + + FcPattern *pattern = FcPatternCreate(); + + { + TQString family, foundry; + for (TQStringList::ConstIterator it = family_list.begin(); it != family_list.end(); ++it) { + parseFontName(*it, foundry, family); + XftPatternAddString(pattern, XFT_FAMILY, family.utf8().data()); + } + } + + TQtFontStyle::Key key; + key.italic = request.italic; + key.weight = request.weight; + key.stretch = request.stretch; + + double scale = addPatternProps(pattern, key, FALSE, TRUE, fp, request); +#ifdef FONT_MATCH_DEBUG + tqDebug("original pattern contains:"); + FcPatternPrint(pattern); +#endif + + // XftFontMatch calls the right ConfigSubstitute variants, but as we use + // FcFontMatch/Sort here we have to do it manually. + FcConfigSubstitute(0, pattern, FcMatchPattern); + XftDefaultSubstitute(TQPaintDevice::x11AppDisplay(), TQPaintDevice::x11AppScreen(), pattern); + +// tqDebug("1: pattern contains:"); +// FcPatternPrint(pattern); + + { + FcValue value; + value.type = FcTypeString; + + // these should only get added to the pattern _after_ substitution + // append the default fallback font for the specified script + extern TQString qt_fallback_font_family( TQFont::Script ); + TQString fallback = qt_fallback_font_family( script ); + if ( ! fallback.isEmpty() && ! family_list.contains( fallback ) ) { + TQCString cs = fallback.utf8(); + value.u.s = (const FcChar8 *)cs.data(); + FcPatternAddWeak(pattern, FC_FAMILY, value, FcTrue); + } + + // add the default family + TQString defaultFamily = TQApplication::font().family(); + if ( ! family_list.contains( defaultFamily ) ) { + TQCString cs = defaultFamily.utf8(); + value.u.s = (const FcChar8 *)cs.data(); + FcPatternAddWeak(pattern, FC_FAMILY, value, FcTrue); + } + + // add TQFont::defaultFamily() to the list, for compatibility with + // previous versions + defaultFamily = TQApplication::font().defaultFamily(); + if ( ! family_list.contains( defaultFamily ) ) { + TQCString cs = defaultFamily.utf8(); + value.u.s = (const FcChar8 *)cs.data(); + FcPatternAddWeak(pattern, FC_FAMILY, value, FcTrue); + } + } + + if (script != TQFont::Unicode) { + FcCharSet *cs = FcCharSetCreate(); + for ( int j=0; sample_chars[script][j]; j++ ) + FcCharSetAddChar(cs, sample_chars[script][j]); + if (script == TQFont::Latin) + // add Euro character + FcCharSetAddChar(cs, 0x20ac); + FcPatternAddCharSet(pattern, FC_CHARSET, cs); + FcCharSetDestroy(cs); + } + +#ifdef FONT_MATCH_DEBUG + printf("final pattern contains:\n"); + FcPatternPrint(pattern); +#endif + + TQFontEngine *fe = 0; + + for( int jj = (FcGetVersion() >= 20392 ? 0 : 1); jj < 2; ++jj ) { + bool use_fontsort = ( jj == 1 ); + + FcResult result; + FcFontSet *fs = 0; + FcPattern *fsp = 0; + + // Properly conform to fontconfig API. We need to call FcDefaultSubstitute() + // before FcFontSort()/FcFontMatch(). + FcDefaultSubstitute(pattern); + + if( use_fontsort ) { + fs = FcFontSort(0, pattern, FcFalse, 0, &result); + if (!fs) + continue; + } else { + fsp = FcFontMatch(0, pattern, &result); + if (!fsp) + continue; + } + +#ifdef FONT_MATCH_DEBUG + if( use_fontsort ) { + printf("fontset contains:\n"); + for (int i = 0; i < fs->nfont; ++i) { + FcPattern *test = fs->fonts[i]; + FcChar8 *fam; + FcPatternGetString(test, FC_FAMILY, 0, &fam); + printf(" %s\n", fam); + } + } else { + printf("fontmatch:"); + FcChar8 *fam; + FcPatternGetString(fsp, FC_FAMILY, 0, &fam); + printf(" %s\n", fam); + } +#endif + + double size_value = request.pixelSize; + if ( size_value > MAXFONTSIZE_XFT ) + size_value = MAXFONTSIZE_XFT; + + int cnt = use_fontsort ? fs->nfont : 1; + + for (int i = 0; i < cnt; ++i) { + FcPattern *font = use_fontsort ? fs->fonts[i] : fsp; + FcCharSet *cs; + FcResult res = FcPatternGetCharSet(font, FC_CHARSET, 0, &cs); + if (res != FcResultMatch) + continue; + bool do_break=true; + for ( int j=0; sample_chars[script][j]; j++ ){ + do_break=false; + if (!FcCharSetHasChar(cs, sample_chars[script][j])) { + do_break=true; + break; + } + } + if ( do_break ) + continue; + FcBool scalable; + res = FcPatternGetBool(font, FC_SCALABLE, 0, &scalable); + if (res != FcResultMatch || !scalable) { + int pixelSize; + res = FcPatternGetInteger(font, FC_PIXEL_SIZE, 0, &pixelSize); + if (res != FcResultMatch || TQABS((size_value-pixelSize)/size_value) > 0.2) + continue; + } + + XftPattern *pattern = XftPatternDuplicate(font); + // add properties back in as the font selected from the list doesn't contain them. + addPatternProps(pattern, key, FALSE, TRUE, fp, request); + + XftPattern *result = + XftFontMatch( TQPaintDevice::x11AppDisplay(), fp->screen, pattern, &res ); + XftPatternDestroy(pattern); + + // We pass a duplicate to XftFontOpenPattern because either xft font + // will own the pattern after the call or the pattern will be + // destroyed. + XftPattern *dup = XftPatternDuplicate( result ); + XftFont *xftfs = XftFontOpenPattern( TQPaintDevice::x11AppDisplay(), dup ); + + if ( !xftfs ) { + // Xft couldn't find a font? + tqDebug("couldn't open fontconfigs chosen font with Xft!!!"); + } else { + fe = new TQFontEngineXft( xftfs, result, 0 ); + if (fp->paintdevice + && TQPaintDeviceMetrics(fp->paintdevice).logicalDpiY() != TQPaintDevice::x11AppDpiY()) { + double px; + XftPatternGetDouble(result, XFT_PIXEL_SIZE, 0, &px); + scale = request.pixelSize/px; + } + fe->setScale( scale ); + fe->fontDef = request; + if ( script != TQFont::Unicode && !canRender(fe, script) ) { + FM_DEBUG( " WARN: font loaded cannot render samples" ); + delete fe; + fe = 0; + }else + FM_DEBUG( " USE: %s", fe->fontDef.family.latin1() ); + } + if (fe) { + TQFontEngineXft *xft = (TQFontEngineXft *)fe; + char *family; + if (XftPatternGetString(xft->pattern(), XFT_FAMILY, 0, &family) == XftResultMatch) + xft->fontDef.family = TQString::fromUtf8(family); + + double px; + if (XftPatternGetDouble(xft->pattern(), XFT_PIXEL_SIZE, 0, &px) == XftResultMatch) + xft->fontDef.pixelSize = tqRound(px); + + int weight = XFT_WEIGHT_MEDIUM; + XftPatternGetInteger(xft->pattern(), XFT_WEIGHT, 0, &weight); + xft->fontDef.weight = getXftWeight(weight); + + int slant = XFT_SLANT_ROMAN; + XftPatternGetInteger(xft->pattern(), XFT_SLANT, 0, &slant); + xft->fontDef.italic = (slant != XFT_SLANT_ROMAN); + + int spacing = XFT_PROPORTIONAL; + XftPatternGetInteger(xft->pattern(), XFT_SPACING, 0, &spacing); + xft->fontDef.fixedPitch = spacing != XFT_PROPORTIONAL; + + xft->fontDef.ignorePitch = FALSE; + break; + } + } + + if( use_fontsort ) + FcFontSetDestroy(fs); + else + FcPatternDestroy(fsp); + + if( fe ) + break; + + } // for( jj ) + + FcPatternDestroy(pattern); + + return fe; +} + +#endif diff --git a/src/kernel/tqfontengine_p.h b/src/kernel/tqfontengine_p.h new file mode 100644 index 000000000..3dba677ca --- /dev/null +++ b/src/kernel/tqfontengine_p.h @@ -0,0 +1,564 @@ +/**************************************************************************** +** +** ??? +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** Licensees holding valid TQt Commercial licenses may use this file in +** accordance with the TQt Commercial License Agreement provided with +** the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef TQFONTENGINE_P_H +#define TQFONTENGINE_P_H + +#ifndef QT_H +#include "ntqglobal.h" +#endif // QT_H + +#ifdef TQ_WS_WIN +#include "qt_windows.h" +#include "tqptrdict.h" +#endif + +#include "tqtextengine_p.h" + +class TQPaintDevice; + +struct glyph_metrics_t; +class TQChar; +typedef unsigned short glyph_t; +struct qoffset_t; +typedef int advance_t; +class TQOpenType; +struct TransformedFont; + +#if defined( TQ_WS_X11 ) || defined( TQ_WS_WIN) || defined( TQ_WS_MAC ) +class TQFontEngine : public TQShared +{ +public: + enum Error { + NoError, + OutOfMemory + }; + + enum Type { + // X11 types + Box, + XLFD, + LatinXLFD, + Xft, + + // MS Windows types + Win, + Uniscribe, + + // Apple MacOS types + Mac, + }; + + TQFontEngine() { + count = 0; cache_count = 0; +#ifdef TQ_WS_X11 + transformed_fonts = 0; +#endif + } + virtual ~TQFontEngine(); + + /* returns 0 as glyph index for non existant glyphs */ + virtual Error stringToCMap( const TQChar *str, int len, glyph_t *glyphs, + advance_t *advances, int *nglyphs, bool mirrored ) const = 0; + +#ifdef TQ_WS_X11 + virtual int cmap() const { return -1; } + virtual TQOpenType *openType() const { return 0; } +#endif + + virtual void draw( TQPainter *p, int x, int y, const TQTextEngine *engine, const TQScriptItem *si, int textFlags ) = 0; + + virtual glyph_metrics_t boundingBox( const glyph_t *glyphs, + const advance_t *advances, + const qoffset_t *offsets, int numGlyphs ) = 0; + virtual glyph_metrics_t boundingBox( glyph_t glyph ) = 0; + + virtual int ascent() const = 0; + virtual int descent() const = 0; + virtual int leading() const = 0; + + virtual int lineThickness() const; + virtual int underlinePosition() const; + + virtual int maxCharWidth() const = 0; + virtual int minLeftBearing() const { return 0; } + virtual int minRightBearing() const { return 0; } + + virtual const char *name() const = 0; + + virtual bool canRender( const TQChar *string, int len ) = 0; + + virtual void setScale( double ) {} + virtual double scale() const { return 1.; } + + virtual Type type() const = 0; + + TQFontDef fontDef; + uint cache_cost; // amount of mem used in kb by the font + int cache_count; + +#ifdef TQ_WS_WIN + HDC dc() const; + void getGlyphIndexes( const TQChar *ch, int numChars, glyph_t *glyphs, bool mirrored ) const; + void getCMap(); + + TQCString _name; + HDC hdc; + HFONT hfont; + LOGFONT logfont; + uint stockFont : 1; + uint paintDevice : 1; + uint useTextOutA : 1; + uint ttf : 1; + uint symbol : 1; + union { + TEXTMETRICW w; + TEXTMETRICA a; + } tm; + int lw; + unsigned char *cmap; + void *script_cache; + static TQPtrDict cacheDict; + short lbearing; + short rbearing; +#endif // TQ_WS_WIN +#ifdef TQ_WS_X11 + TransformedFont *transformed_fonts; +#endif +}; +#endif // WIN || X11 || MAC + + + +enum IndicFeatures { + CcmpFeature, + InitFeature, + NuktaFeature, + AkhantFeature, + RephFeature, + BelowFormFeature, + HalfFormFeature, + PostFormFeature, + VattuFeature, + PreSubstFeature, + AboveSubstFeature, + BelowSubstFeature, + PostSubstFeature, + HalantFeature +}; + +#if defined(TQ_WS_X11) || defined(TQ_WS_WIN) +class TQFontEngineBox : public TQFontEngine +{ +public: + TQFontEngineBox( int size ); + ~TQFontEngineBox(); + + Error stringToCMap( const TQChar *str, int len, glyph_t *glyphs, advance_t *advances, int *nglyphs, bool mirrored ) const; + + void draw( TQPainter *p, int x, int y, const TQTextEngine *engine, const TQScriptItem *si, int textFlags ); + + virtual glyph_metrics_t boundingBox( const glyph_t *glyphs, + const advance_t *advances, const qoffset_t *offsets, int numGlyphs ); + glyph_metrics_t boundingBox( glyph_t glyph ); + + int ascent() const; + int descent() const; + int leading() const; + int maxCharWidth() const; + int minLeftBearing() const { return 0; } + int minRightBearing() const { return 0; } + +#ifdef TQ_WS_X11 + int cmap() const; +#endif + const char *name() const; + + bool canRender( const TQChar *string, int len ); + + Type type() const; + inline int size() const { return _size; } + +private: + friend class TQFontPrivate; + int _size; +}; +#endif + +#ifdef TQ_WS_X11 +#include "qt_x11_p.h" + + +struct TransformedFont +{ + float xx; + float xy; + float yx; + float yy; + union { + Font xlfd_font; +#ifndef TQT_NO_XFTFREETYPE + XftFont *xft_font; +#endif + }; + TransformedFont *next; +}; + +#ifndef TQT_NO_XFTFREETYPE +#include +#include FT_FREETYPE_H +#include "ftxopen.h" + +class TQTextCodec; + +class TQFontEngineXft : public TQFontEngine +{ +public: + TQFontEngineXft( XftFont *font, XftPattern *pattern, int cmap ); + ~TQFontEngineXft(); + + TQOpenType *openType() const; + + Error stringToCMap( const TQChar *str, int len, glyph_t *glyphs, advance_t *advances, int *nglyphs, bool mirrored ) const; + + void draw( TQPainter *p, int x, int y, const TQTextEngine *engine, const TQScriptItem *si, int textFlags ); + + virtual glyph_metrics_t boundingBox( const glyph_t *glyphs, + const advance_t *advances, const qoffset_t *offsets, int numGlyphs ); + glyph_metrics_t boundingBox( glyph_t glyph ); + + int ascent() const; + int descent() const; + int leading() const; + int lineThickness() const; + int underlinePosition() const; + int maxCharWidth() const; + int minLeftBearing() const; + int minRightBearing() const; + + int cmap() const; + const char *name() const; + + void setScale( double scale ); + double scale() const { return _scale; } + + bool canRender( const TQChar *string, int len ); + + Type type() const; + XftPattern *pattern() const { return _pattern; } + FT_Face face() const { return _face; } + XftFont *font() const { return _font; } + + void recalcAdvances( int len, glyph_t *glyphs, advance_t *advances ); + +private: + friend class TQFontPrivate; + friend class TQOpenType; + XftFont *_font; + XftPattern *_pattern; + FT_Face _face; + TQOpenType *_openType; + int _cmap; + short lbearing; + short rbearing; + float _scale; + enum { widthCacheSize = 0x800, cmapCacheSize = 0x500 }; + unsigned char widthCache[widthCacheSize]; + glyph_t cmapCache[cmapCacheSize]; +}; +#endif + +class TQFontEngineLatinXLFD; + +class TQFontEngineXLFD : public TQFontEngine +{ +public: + TQFontEngineXLFD( XFontStruct *fs, const char *name, int cmap ); + ~TQFontEngineXLFD(); + + Error stringToCMap( const TQChar *str, int len, glyph_t *glyphs, advance_t *advances, int *nglyphs, bool mirrored ) const; + + void draw( TQPainter *p, int x, int y, const TQTextEngine *engine, const TQScriptItem *si, int textFlags ); + + virtual glyph_metrics_t boundingBox( const glyph_t *glyphs, + const advance_t *advances, const qoffset_t *offsets, int numGlyphs ); + glyph_metrics_t boundingBox( glyph_t glyph ); + + int ascent() const; + int descent() const; + int leading() const; + int maxCharWidth() const; + int minLeftBearing() const; + int minRightBearing() const; + + int cmap() const; + const char *name() const; + + bool canRender( const TQChar *string, int len ); + + void setScale( double scale ); + double scale() const { return _scale; } + Type type() const; + + TQt::HANDLE handle() const { return (TQt::HANDLE) _fs->fid; } + +private: + friend class TQFontPrivate; + XFontStruct *_fs; + TQCString _name; + TQTextCodec *_codec; + float _scale; // needed for printing, to correctly scale font metrics for bitmap fonts + int _cmap; + short lbearing; + short rbearing; + enum XlfdTransformations { + XlfdTrUnknown, + XlfdTrSupported, + XlfdTrUnsupported + }; + XlfdTransformations xlfd_transformations; + + friend class TQFontEngineLatinXLFD; +}; + +class TQFontEngineLatinXLFD : public TQFontEngine +{ +public: + TQFontEngineLatinXLFD( XFontStruct *xfs, const char *name, int cmap ); + ~TQFontEngineLatinXLFD(); + + Error stringToCMap( const TQChar *str, int len, glyph_t *glyphs, + advance_t *advances, int *nglyphs, bool mirrored ) const; + + void draw( TQPainter *p, int x, int y, const TQTextEngine *engine, + const TQScriptItem *si, int textFlags ); + + virtual glyph_metrics_t boundingBox( const glyph_t *glyphs, + const advance_t *advances, + const qoffset_t *offsets, int numGlyphs ); + glyph_metrics_t boundingBox( glyph_t glyph ); + + int ascent() const; + int descent() const; + int leading() const; + int maxCharWidth() const; + int minLeftBearing() const; + int minRightBearing() const; + + int cmap() const { return -1; } // ### + const char *name() const; + + bool canRender( const TQChar *string, int len ); + + void setScale( double scale ); + double scale() const { return _engines[0]->scale(); } + Type type() const { return LatinXLFD; } + + TQt::HANDLE handle() const { return ((TQFontEngineXLFD *) _engines[0])->handle(); } + +private: + void findEngine( const TQChar &ch ); + + TQFontEngine **_engines; + int _count; + + glyph_t glyphIndices [0x200]; + advance_t glyphAdvances[0x200]; + glyph_t euroIndex; + advance_t euroAdvance; +}; + +class TQScriptItem; +class TQTextEngine; + +#ifndef TQT_NO_XFTFREETYPE + +#include "qscriptengine_p.h" +#include "tqtextengine_p.h" +#include +#include FT_FREETYPE_H +#include "ftxopen.h" + +enum { PositioningProperties = 0x80000000 }; + +class TQOpenType +{ +public: + TQOpenType(TQFontEngineXft *fe); + ~TQOpenType(); + + struct Features { + uint tag; + uint property; + }; + + bool supportsScript(unsigned int script) { + Q_ASSERT(script < TQFont::NScripts); + return supported_scripts[script]; + } + void selectScript(unsigned int script, const Features *features = 0); + + bool shape(TQShaperItem *item, const unsigned int *properties = 0); + bool positionAndAdd(TQShaperItem *item, bool doLogClusters = TRUE); + + OTL_GlyphItem glyphs() const { return otl_buffer->in_string; } + int len() const { return otl_buffer->in_length; } + void setProperty(int index, uint property) { otl_buffer->in_string[index].properties = property; } + + +private: + bool checkScript(unsigned int script); + TQFontEngine *fontEngine; + FT_Face face; + TTO_GDEF gdef; + TTO_GSUB gsub; + TTO_GPOS gpos; + bool supported_scripts[TQFont::NScripts]; + FT_ULong current_script; + bool positioned : 1; + OTL_Buffer otl_buffer; + GlyphAttributes *tmpAttributes; + unsigned int *tmpLogClusters; + int length; + int orig_nglyphs; + int loadFlags; +}; + +#endif // TQT_NO_XFTFREETYPE + +#elif defined( TQ_WS_MAC ) +#include "qt_mac.h" +#include +#include + +class TQFontEngineMac : public TQFontEngine +{ +#if 0 + ATSFontMetrics *info; +#else + FontInfo *info; +#endif + int psize; + FMFontFamily fmfam; + TQMacFontInfo *internal_fi; + mutable ATSUTextLayout mTextLayout; + enum { widthCacheSize = 0x500 }; + mutable unsigned char widthCache[widthCacheSize]; + friend class TQFont; + friend class TQGLContext; + friend class TQFontPrivate; + friend class TQMacSetFontInfo; + +public: + TQFontEngineMac(); + ~TQFontEngineMac(); + + Error stringToCMap( const TQChar *str, int len, glyph_t *glyphs, advance_t *advances, int *nglyphs, bool mirrored ) const; + + void draw( TQPainter *p, int x, int y, const TQTextEngine *engine, const TQScriptItem *si, int textFlags ); + + glyph_metrics_t boundingBox( const glyph_t *glyphs, + const advance_t *advances, const qoffset_t *offsets, int numGlyphs ); + glyph_metrics_t boundingBox( glyph_t glyph ); + + int ascent() const { return (int)info->ascent; } + int descent() const { return (int)info->descent; } + int leading() const { return (int)info->leading; } +#if 0 + int maxCharWidth() const { return (int)info->maxAdvanceWidth; } +#else + int maxCharWidth() const { return info->widMax; } +#endif + + const char *name() const { return "ATSUI"; } + + bool canRender( const TQChar *string, int len ); + + Type type() const { return TQFontEngine::Mac; } + + void calculateCost(); + + enum { WIDTH=0x01, DRAW=0x02, EXISTS=0x04 }; + int doTextTask(const TQChar *s, int pos, int use_len, int len, uchar task, int =-1, int y=-1, + TQPaintDevice *dev=NULL, const TQRegion *rgn=NULL) const; +}; + +#elif defined( TQ_WS_WIN ) + +class TQFontEngineWin : public TQFontEngine +{ +public: + TQFontEngineWin( const char *name, HDC, HFONT, bool, LOGFONT ); + + Error stringToCMap( const TQChar *str, int len, glyph_t *glyphs, advance_t *advances, int *nglyphs, bool mirrored ) const; + + void draw( TQPainter *p, int x, int y, const TQTextEngine *engine, const TQScriptItem *si, int textFlags ); + + glyph_metrics_t boundingBox( const glyph_t *glyphs, + const advance_t *advances, const qoffset_t *offsets, int numGlyphs ); + glyph_metrics_t boundingBox( glyph_t glyph ); + + int ascent() const; + int descent() const; + int leading() const; + int maxCharWidth() const; + int minLeftBearing() const; + int minRightBearing() const; + + const char *name() const; + + bool canRender( const TQChar *string, int len ); + + Type type() const; + + enum { widthCacheSize = 0x800, cmapCacheSize = 0x500 }; + unsigned char widthCache[widthCacheSize]; +}; + +#if 0 +class TQFontEngineUniscribe : public TQFontEngineWin +{ +public: + void draw( TQPainter *p, int x, int y, const TQTextEngine *engine, const TQScriptItem *si, int textFlags ); + bool canRender( const TQChar *string, int len ); + + Type type() const; +}; +#endif + +#endif // TQ_WS_WIN + +#endif diff --git a/src/kernel/tqfontengine_x11.cpp b/src/kernel/tqfontengine_x11.cpp new file mode 100644 index 000000000..6363aac97 --- /dev/null +++ b/src/kernel/tqfontengine_x11.cpp @@ -0,0 +1,2724 @@ +/**************************************************************************** +** +** ??? +** +** Copyright (C) 2003-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#include "tqfontengine_p.h" + +// #define FONTENGINE_DEBUG + +#include +#include +#include + +#include "tqbitmap.h" +#include "tqfontdatabase.h" +#include "tqpaintdevice.h" +#include "tqpaintdevicemetrics.h" +#include "tqpainter.h" +#include "tqimage.h" + +#include "qt_x11_p.h" + +#include "tqfont.h" +#include "tqtextengine_p.h" + +#include + +#include + +// defined in tqfontdatbase_x11.cpp +extern int qt_mib_for_xlfd_encoding( const char *encoding ); +extern int qt_xlfd_encoding_id( const char *encoding ); + +extern void qt_draw_transformed_rect( TQPainter *p, int x, int y, int w, int h, bool fill ); + +static void drawLines( TQPainter *p, TQFontEngine *fe, int baseline, int x1, int w, int textFlags ) +{ + int lw = fe->lineThickness(); + if ( textFlags & TQt::Underline ) { + int pos = fe->underlinePosition(); + qt_draw_transformed_rect( p, x1, baseline+pos, w, lw, TRUE ); + } + if ( textFlags & TQt::Overline ) { + int pos = fe->ascent()+1; + if ( !pos ) pos = 1; + qt_draw_transformed_rect( p, x1, baseline-pos, w, lw, TRUE ); + } + if ( textFlags & TQt::StrikeOut ) { + int pos = fe->ascent()/3; + if ( !pos ) pos = 1; + qt_draw_transformed_rect( p, x1, baseline-pos, w, lw, TRUE ); + } +} + + +inline static void qSafeXDestroyImage( XImage *x ) +{ + if ( x->data ) { + free( x->data ); + x->data = 0; + } + XDestroyImage( x ); +} + +extern bool qt_xForm_helper( const TQWMatrix &trueMat, int xoffset, + int type, int depth, + uchar *dptr, int dbpl, int p_inc, int dHeight, + uchar *sptr, int sbpl, int sWidth, int sHeight + ); + +static TQBitmap transform(Display *dpy, const TQBitmap &source, int xoff, int yoff, int w, int h, const TQWMatrix &matrix) +{ + int ws = source.width(); + int hs = source.height(); + + bool invertible; + TQWMatrix mat = matrix.invert( &invertible ); // invert matrix + + if (!invertible ) + return TQBitmap(); + mat.translate(xoff, yoff); + + XImage *xi = XGetImage(dpy, source.handle(), 0, 0, ws, hs, AllPlanes, XYPixmap); + + if ( !xi ) + return TQBitmap(); + + int sbpl = xi->bytes_per_line; + uchar *sptr = (uchar *)xi->data; + + int dbpl = (w+7)/8; + int dbytes = dbpl*h; + + uchar *dptr = (uchar *)malloc( dbytes ); // create buffer for bits + memset( dptr, 0, dbytes ); + + int type = xi->bitmap_bit_order == MSBFirst ? QT_XFORM_TYPE_MSBFIRST : QT_XFORM_TYPE_LSBFIRST; + int xbpl, p_inc; + xbpl = (w+7)/8; + p_inc = dbpl - xbpl; + + bool ok = qt_xForm_helper( mat, xi->xoffset, type, 1, dptr, xbpl, p_inc, h, sptr, sbpl, ws, hs ); + qSafeXDestroyImage(xi); + TQBitmap bm; + if (ok) { + bm = TQBitmap( w, h, dptr, TQImage::systemBitOrder() != TQImage::BigEndian ); + } else { +#if defined(QT_CHECK_RANGE) + tqWarning( "TQFontEngineXft::tranform: xform failed"); +#endif + } + + free( dptr ); + return bm; +} + + +static void drawScaled(int x, int y, const TQTextEngine *engine, const TQScriptItem *si, int textFlags, + Display *dpy, GC gc, TQPaintDevice *pdev, TQFontEngine *fe, + const TQWMatrix &xmat, float scale) +{ + // font doesn't support transformations, need to do it by hand + int w = tqRound(si->width/scale); + int h = tqRound((si->ascent + si->descent + 1)/scale); + if (w == 0 || h == 0) + return; + TQWMatrix mat1 = xmat; + mat1.scale(scale, scale); + + w += h; // add some pixels to width because of italic correction + TQBitmap bm( w, h, TRUE ); // create bitmap + TQPainter paint; + paint.begin( &bm ); // draw text in bitmap + fe->draw( &paint, 0, si->ascent/scale, engine, si, textFlags ); + paint.end(); + + TQRect pdevRect; + if (pdev->devType() == TQInternal::Widget) + pdevRect = ((TQWidget *)pdev)->rect(); + else if (pdev->devType() == TQInternal::Pixmap) + pdevRect = ((TQPixmap *)pdev)->rect(); + else + return; + + + TQRect br = mat1.mapRect(TQRect(x, y - si->ascent, w, h)); + TQRect br2 = br & pdevRect; + if (br2.width() <= 0 || br2.height() <= 0 + || br2.width() >= 32768 || br2.height() >= 32768) + return; + TQWMatrix mat = TQPixmap::trueMatrix( mat1, w, h ); + TQBitmap wx_bm = ::transform(dpy, bm, br2.x() - br.x(), br2.y() - br.y(), br2.width(), br2.height(), mat); + if ( wx_bm.isNull() ) + return; + + x = br2.x(); + y = br2.y(); + + TQt::HANDLE hd = pdev->handle(); + XSetFillStyle( dpy, gc, FillStippled ); + XSetStipple( dpy, gc, wx_bm.handle() ); + XSetTSOrigin( dpy, gc, x, y ); + XFillRectangle( dpy, hd, gc, x, y, wx_bm.width(), wx_bm.height() ); + XSetTSOrigin( dpy, gc, 0, 0 ); + XSetFillStyle( dpy, gc, FillSolid ); +} + + +TQFontEngine::~TQFontEngine() +{ +} + +int TQFontEngine::lineThickness() const +{ + // ad hoc algorithm + int score = fontDef.weight * fontDef.pixelSize; + int lw = score / 700; + + // looks better with thicker line for small pointsizes + if ( lw < 2 && score >= 1050 ) lw = 2; + if ( lw == 0 ) lw = 1; + + return lw; +} + +int TQFontEngine::underlinePosition() const +{ + int pos = ( ( lineThickness() * 2 ) + 3 ) / 6; + return pos ? pos : 1; +} + +// ------------------------------------------------------------------ +// The box font engine +// ------------------------------------------------------------------ + + +TQFontEngineBox::TQFontEngineBox( int size ) + : _size( size ) +{ + cache_cost = sizeof( TQFontEngineBox ); +} + +TQFontEngineBox::~TQFontEngineBox() +{ +} + +TQFontEngine::Error TQFontEngineBox::stringToCMap( const TQChar *, int len, glyph_t *glyphs, advance_t *advances, int *nglyphs, bool ) const +{ + if ( *nglyphs < len ) { + *nglyphs = len; + return OutOfMemory; + } + + memset( glyphs, 0, len * sizeof( glyph_t ) ); + *nglyphs = len; + + if ( advances ) { + for ( int i = 0; i < len; i++ ) + *(advances++) = _size; + } + return NoError; +} + +void TQFontEngineBox::draw( TQPainter *p, int x, int y, const TQTextEngine *engine, const TQScriptItem *si, int textFlags ) +{ + Display *dpy = TQPaintDevice::x11AppDisplay(); + TQt::HANDLE hd = p->device()->handle(); + GC gc = p->gc; + +#ifdef FONTENGINE_DEBUG + p->save(); + p->setBrush( TQt::white ); + glyph_metrics_t ci = boundingBox( glyphs, offsets, numGlyphs ); + p->drawRect( x + ci.x, y + ci.y, ci.width, ci.height ); + p->drawRect( x + ci.x, y + 50 + ci.y, ci.width, ci.height ); + tqDebug("bounding rect=%d %d (%d/%d)", ci.x, ci.y, ci.width, ci.height ); + p->restore(); + int xp = x; + int yp = y; +#endif + + GlyphAttributes *glyphAttributes = engine->glyphAttributes( si ); + + if ( p->txop > TQPainter::TxTranslate ) { + int xp = x; + int yp = _size + 2; + int s = _size - 3; + for (int k = 0; k < si->num_glyphs; k++) { + if (!glyphAttributes[k].zeroWidth) + qt_draw_transformed_rect( p, xp, yp, s, s, FALSE ); + xp += _size; + } + } else { + if ( p->txop == TQPainter::TxTranslate ) + p->map( x, y, &x, &y ); + + XRectangle rects[64]; + + int gl = 0; + while (gl < si->num_glyphs) { + int toDraw = TQMIN(64, si->num_glyphs-gl); + int adv = toDraw*_size; + if (x + adv < SHRT_MAX && x > SHRT_MIN) { + int ng = 0; + for (int k = 0; k < toDraw; k++) { + if (!glyphAttributes[gl + k].zeroWidth) { + rects[ng].x = x + (k * _size); + rects[ng].y = y - _size + 2; + rects[ng].width = rects[k].height = _size - 3; + ++ng; + } + } + XDrawRectangles(dpy, hd, gc, rects, ng); + } + gl += toDraw; + x += adv; + } + } + + if ( textFlags != 0 ) + drawLines( p, this, y, x, si->num_glyphs*_size, textFlags ); + +#ifdef FONTENGINE_DEBUG + x = xp; + y = yp; + p->save(); + p->setPen( TQt::red ); + for ( int i = 0; i < numGlyphs; i++ ) { + glyph_metrics_t ci = boundingBox( glyphs[i] ); + x += offsets[i].x; + y += offsets[i].y; + p->drawRect( x + ci.x, y + 50 + ci.y, ci.width, ci.height ); + tqDebug("bounding ci[%d]=%d %d (%d/%d) / %d %d offset=(%d/%d)", i, ci.x, ci.y, ci.width, ci.height, + ci.xoff, ci.yoff, offsets[i].x, offsets[i].y ); + x += ci.xoff; + y += ci.yoff; + } + p->restore(); +#endif +} + +glyph_metrics_t TQFontEngineBox::boundingBox( const glyph_t *, const advance_t *, const qoffset_t *, int numGlyphs ) +{ + glyph_metrics_t overall; + overall.x = overall.y = 0; + overall.width = _size*numGlyphs; + overall.height = _size; + overall.xoff = overall.width; + overall.yoff = 0; + return overall; +} + +glyph_metrics_t TQFontEngineBox::boundingBox( glyph_t ) +{ + return glyph_metrics_t( 0, _size, _size, _size, _size, 0 ); +} + + + +int TQFontEngineBox::ascent() const +{ + return _size; +} + +int TQFontEngineBox::descent() const +{ + return 0; +} + +int TQFontEngineBox::leading() const +{ + int l = tqRound( _size * 0.15 ); + return (l > 0) ? l : 1; +} + +int TQFontEngineBox::maxCharWidth() const +{ + return _size; +} + +int TQFontEngineBox::cmap() const +{ + return -1; +} + +const char *TQFontEngineBox::name() const +{ + return "null"; +} + +bool TQFontEngineBox::canRender( const TQChar *, int ) +{ + return TRUE; +} + +TQFontEngine::Type TQFontEngineBox::type() const +{ + return Box; +} + + + + +// ------------------------------------------------------------------ +// Xlfd cont engine +// ------------------------------------------------------------------ + +static inline XCharStruct *charStruct( XFontStruct *xfs, uint ch ) +{ + XCharStruct *xcs = 0; + unsigned char r = ch>>8; + unsigned char c = ch&0xff; + if ( r >= xfs->min_byte1 && + r <= xfs->max_byte1 && + c >= xfs->min_char_or_byte2 && + c <= xfs->max_char_or_byte2) { + if ( !xfs->per_char ) + xcs = &(xfs->min_bounds); + else { + xcs = xfs->per_char + ((r - xfs->min_byte1) * + (xfs->max_char_or_byte2 - + xfs->min_char_or_byte2 + 1)) + + (c - xfs->min_char_or_byte2); + if (xcs->width == 0 && xcs->ascent == 0 && xcs->descent == 0) + xcs = 0; + } + } + return xcs; +} + +TQFontEngineXLFD::TQFontEngineXLFD( XFontStruct *fs, const char *name, int mib ) + : _fs( fs ), _name( name ), _codec( 0 ), _scale( 1. ), _cmap( mib ) +{ + if ( _cmap ) _codec = TQTextCodec::codecForMib( _cmap ); + + cache_cost = (((fs->max_byte1 - fs->min_byte1) * + (fs->max_char_or_byte2 - fs->min_char_or_byte2 + 1)) + + fs->max_char_or_byte2 - fs->min_char_or_byte2); + cache_cost = ((fs->max_bounds.ascent + fs->max_bounds.descent) * + (fs->max_bounds.width * cache_cost / 8)); + lbearing = SHRT_MIN; + rbearing = SHRT_MIN; + +#if 1 + // Server side transformations do not seem to work correctly for + // all types of fonts (for example, it works for bdf/pcf fonts, + // but not for ttf). It also seems to be extermely server + // dependent. The best thing is to just disable server side + // transformations until either server support matures or we + // figure out a better way to do it. + xlfd_transformations = XlfdTrUnsupported; +#else + xlfd_transformations = XlfdTrUnknown; + + // Hummingbird's Exceed X server will substitute 'fixed' for any + // known fonts, and it doesn't seem to support transformations, so + // we should never try to use xlfd transformations with it + if (strstr(ServerVendor(TQPaintDevice::x11AppDisplay()), "Hummingbird")) + xlfd_transformations = XlfdTrUnsupported; +#endif +} + +TQFontEngineXLFD::~TQFontEngineXLFD() +{ + XFreeFont( TQPaintDevice::x11AppDisplay(), _fs ); + _fs = 0; + TransformedFont *trf = transformed_fonts; + while ( trf ) { + XUnloadFont( TQPaintDevice::x11AppDisplay(), trf->xlfd_font ); + TransformedFont *tmp = trf; + trf = trf->next; + delete tmp; + } +} + +TQFontEngine::Error TQFontEngineXLFD::stringToCMap( const TQChar *str, int len, glyph_t *glyphs, advance_t *advances, int *nglyphs, bool mirrored ) const +{ + if ( *nglyphs < len ) { + *nglyphs = len; + return OutOfMemory; + } + + if ( _codec ) { + bool haveNbsp = FALSE; + for ( int i = 0; i < len; i++ ) + if ( str[i].unicode() == 0xa0 ) { + haveNbsp = TRUE; + break; + } + + TQChar *chars = (TQChar *)str; + if ( haveNbsp || mirrored ) { + chars = (TQChar *)malloc( len*sizeof(TQChar) ); + for ( int i = 0; i < len; i++ ) + chars[i] = (str[i].unicode() == 0xa0 ? 0x20 : + (mirrored ? ::mirroredChar(str[i]).unicode() : str[i].unicode())); + } + _codec->fromUnicodeInternal( chars, glyphs, len ); + if (chars != str) + free( chars ); + } else { + glyph_t *g = glyphs + len; + const TQChar *c = str + len; + if ( mirrored ) { + while ( c != str ) + *(--g) = (--c)->unicode() == 0xa0 ? 0x20 : ::mirroredChar(*c).unicode(); + } else { + while ( c != str ) + *(--g) = (--c)->unicode() == 0xa0 ? 0x20 : c->unicode(); + } + } + *nglyphs = len; + + if ( advances ) { + glyph_t *g = glyphs + len; + advance_t *a = advances + len; + XCharStruct *xcs; + // inlined for better perfomance + if ( !_fs->per_char ) { + xcs = &_fs->min_bounds; + while ( a != advances ) + *(--a) = xcs->width; + } + else if ( !_fs->max_byte1 ) { + XCharStruct *base = _fs->per_char - _fs->min_char_or_byte2; + while ( g-- != glyphs ) { + unsigned int gl = *g; + xcs = (gl >= _fs->min_char_or_byte2 && gl <= _fs->max_char_or_byte2) ? + base + gl : 0; + *(--a) = (!xcs || (!xcs->width && !xcs->ascent && !xcs->descent)) ? _fs->ascent : xcs->width; + } + } + else { + while ( g != glyphs ) { + xcs = charStruct( _fs, *(--g) ); + *(--a) = (xcs ? xcs->width : _fs->ascent); + } + } + if ( _scale != 1. ) { + for ( int i = 0; i < len; i++ ) + advances[i] = tqRound(advances[i]*_scale); + } + } + return NoError; +} + +#if defined(Q_C_CALLBACKS) +extern "C" { +#endif + +static bool x_font_load_error = FALSE; +static int x_font_errorhandler(Display *, XErrorEvent *) +{ + x_font_load_error = TRUE; + return 0; +} + +#if defined(Q_C_CALLBACKS) +} +#endif + + +void TQFontEngineXLFD::draw( TQPainter *p, int x, int y, const TQTextEngine *engine, const TQScriptItem *si, int textFlags ) +{ + if ( !si->num_glyphs ) + return; + +// tqDebug("TQFontEngineXLFD::draw( %d, %d, numglyphs=%d", x, y, si->num_glyphs ); + + Display *dpy = TQPaintDevice::x11AppDisplay(); + TQt::HANDLE hd = p->device()->handle(); + GC gc = p->gc; + + bool transform = FALSE; + int xorig = x; + int yorig = y; + + TQt::HANDLE font_id = _fs->fid; + if ( p->txop > TQPainter::TxTranslate || _scale < 0.9999 || _scale > 1.0001 ) { + bool degenerate = TQABS( p->m11()*p->m22() - p->m12()*p->m21() ) < 0.01; + if ( !degenerate && xlfd_transformations != XlfdTrUnsupported ) { + // need a transformed font from the server + TQCString xlfd_transformed = _name; + int field = 0; + char *data = xlfd_transformed.data(); + int pos = 0; + while ( field < 7 ) { + if ( data[pos] == '-' ) + field++; + pos++; + } + int endPos = pos; + while ( data[endPos] != '-' ) + endPos++; + float size = xlfd_transformed.mid( pos, endPos-pos ).toInt(); + float mat[4]; + mat[0] = p->m11()*size*_scale; + mat[1] = -p->m12()*size*_scale; + mat[2] = -p->m21()*size*_scale; + mat[3] = p->m22()*size*_scale; + + // check if we have it cached + TransformedFont *trf = transformed_fonts; + TransformedFont *prev = 0; + int i = 0; + while ( trf ) { + if ( trf->xx == mat[0] && + trf->xy == mat[1] && + trf->yx == mat[2] && + trf->yy == mat[3] ) + break; + TransformedFont *tmp = trf; + trf = trf->next; + if (i > 10) { + XUnloadFont( TQPaintDevice::x11AppDisplay(), tmp->xlfd_font ); + delete tmp; + prev->next = trf; + } else { + prev = tmp; + } + ++i; + } + if ( trf ) { + if ( prev ) { + // move to beginning of list + prev->next = trf->next; + trf->next = transformed_fonts; + transformed_fonts = trf; + } + font_id = trf->xlfd_font; + } else { + TQCString matrix="["; + for ( int i = 0; i < 4; i++ ) { + float f = mat[i]; + if ( f < 0 ) { + matrix += '~'; + f = -f; + } + matrix += TQString::number( f, 'f', 5 ).latin1(); + matrix += ' '; + } + matrix += ']'; + //tqDebug("m: %2.2f %2.2f %2.2f %2.2f, matrix=%s", p->m11(), p->m12(), p->m21(), p->m22(), matrix.data()); + xlfd_transformed.replace( pos, endPos-pos, matrix ); + + x_font_load_error = FALSE; + XErrorHandler old_handler = XSetErrorHandler( x_font_errorhandler ); + font_id = XLoadFont( dpy, xlfd_transformed.data() ); + XSync( dpy, FALSE ); + XSetErrorHandler( old_handler ); + if ( x_font_load_error ) { + //tqDebug( "couldn't load transformed font" ); + font_id = _fs->fid; + xlfd_transformations = XlfdTrUnsupported; + } else { + TransformedFont *trf = new TransformedFont; + trf->xx = mat[0]; + trf->xy = mat[1]; + trf->yx = mat[2]; + trf->yy = mat[3]; + trf->xlfd_font = font_id; + trf->next = transformed_fonts; + transformed_fonts = trf; + } + } + } + if ( degenerate || xlfd_transformations == XlfdTrUnsupported ) { + // XServer or font don't support server side transformations, need to do it by hand + float tmp = _scale; + _scale = 1.; + drawScaled(x, y, engine, si, textFlags, dpy, p->gc, p->device(), this, p->xmat, tmp); + _scale = tmp; + return; + } + transform = TRUE; + } else if ( p->txop == TQPainter::TxTranslate ) { + p->map( x, y, &x, &y ); + } + + XSetFont(dpy, gc, font_id); + +#ifdef FONTENGINE_DEBUG + p->save(); + p->setBrush( TQt::white ); + glyph_metrics_t ci = boundingBox( glyphs, advances, offsets, si->num_glyphs ); + p->drawRect( x + ci.x, y + ci.y, ci.width, ci.height ); + p->drawRect( x + ci.x, y + 100 + ci.y, ci.width, ci.height ); + tqDebug("bounding rect=%d %d (%d/%d)", ci.x, ci.y, ci.width, ci.height ); + p->restore(); + int xp = x; + int yp = y; +#endif + + glyph_t *glyphs = engine->glyphs( si ); + advance_t *advances = engine->advances( si ); + qoffset_t *offsets = engine->offsets( si ); + + XChar2b ch[256]; + XChar2b *chars = ch; + if ( si->num_glyphs > 255 ) + chars = (XChar2b *)malloc( si->num_glyphs*sizeof(XChar2b) ); + + for (int i = 0; i < si->num_glyphs; i++) { + chars[i].byte1 = glyphs[i] >> 8; + chars[i].byte2 = glyphs[i] & 0xff; + } + + int xpos = x; + GlyphAttributes *glyphAttributes = engine->glyphAttributes( si ); + + if ( si->analysis.bidiLevel % 2 ) { + int i = si->num_glyphs; + while( i-- ) { + advance_t adv = advances[i]; + // tqDebug("advance = %d/%d", adv.x, adv.y ); + x += adv; + glyph_metrics_t gi = boundingBox( glyphs[i] ); + int xp = x-offsets[i].x-gi.xoff; + int yp = y+offsets[i].y-gi.yoff; + if ( transform ) + p->map( xp, yp, &xp, &yp ); + if (!glyphAttributes[i].zeroWidth && xp < SHRT_MAX && xp > SHRT_MIN) + XDrawString16(dpy, hd, gc, xp, yp, chars+i, 1 ); + } + } else { + if ( transform || si->hasPositioning ) { + int i = 0; + while( i < si->num_glyphs ) { + int xp = x+offsets[i].x; + int yp = y+offsets[i].y; + if ( transform ) + p->map( xp, yp, &xp, &yp ); + if (!glyphAttributes[i].zeroWidth && xp < SHRT_MAX && xp > SHRT_MIN) + XDrawString16(dpy, hd, gc, xp, yp, chars+i, 1 ); + advance_t adv = advances[i]; + // tqDebug("advance = %d/%d", adv.x, adv.y ); + x += adv; + i++; + } + } else { + // we can take a shortcut + int gl = 0; + while (gl < si->num_glyphs) { + int toDraw = TQMIN(64, si->num_glyphs-gl); + int adv = 0; + for (int i = gl; i < gl+toDraw; ++i) + adv += advances[i]; + if (x + adv < SHRT_MAX && x > SHRT_MIN) + XDrawString16(dpy, hd, gc, x, y, chars+gl, toDraw); + gl += toDraw; + x += adv; + } + } + } + + if ( chars != ch ) + free( chars ); + + if ( textFlags != 0 ) + drawLines( p, this, yorig, xorig, x-xpos, textFlags ); + +#ifdef FONTENGINE_DEBUG + x = xp; + y = yp; + p->save(); + p->setPen( TQt::red ); + for ( int i = 0; i < si->num_glyphs; i++ ) { + glyph_metrics_t ci = boundingBox( glyphs[i] ); + p->drawRect( x + ci.x + offsets[i].x, y + 100 + ci.y + offsets[i].y, ci.width, ci.height ); + tqDebug("bounding ci[%d]=%d %d (%d/%d) / %d %d offs=(%d/%d) advance=(%d/%d)", i, ci.x, ci.y, ci.width, ci.height, + ci.xoff, ci.yoff, offsets[i].x, offsets[i].y, + advances[i].x, advances[i].y); + x += advances[i].x; + y += advances[i].y; + } + p->restore(); +#endif +} + +glyph_metrics_t TQFontEngineXLFD::boundingBox( const glyph_t *glyphs, const advance_t *advances, const qoffset_t *offsets, int numGlyphs ) +{ + int i; + + glyph_metrics_t overall; + int ymax = 0; + int xmax = 0; + for (i = 0; i < numGlyphs; i++) { + XCharStruct *xcs = charStruct( _fs, glyphs[i] ); + if (xcs) { + int x = overall.xoff + offsets[i].x - xcs->lbearing; + int y = overall.yoff + offsets[i].y - xcs->ascent; + overall.x = TQMIN( overall.x, x ); + overall.y = TQMIN( overall.y, y ); + xmax = TQMAX( xmax, overall.xoff + offsets[i].x + xcs->rbearing ); + ymax = TQMAX( ymax, y + xcs->ascent + xcs->descent ); + overall.xoff += tqRound(advances[i]/_scale); + } else { + int size = _fs->ascent; + overall.x = TQMIN(overall.x, overall.xoff ); + overall.y = TQMIN(overall.y, overall.yoff - size ); + ymax = TQMAX( ymax, overall.yoff ); + overall.xoff += size; + xmax = TQMAX( xmax, overall.xoff ); + } + } + overall.height = ymax - overall.y; + overall.width = xmax - overall.x; + + if ( _scale != 1. ) { + overall.x = tqRound(overall.x * _scale); + overall.y = tqRound(overall.y * _scale); + overall.height = tqRound(overall.height * _scale); + overall.width = tqRound(overall.width * _scale); + overall.xoff = tqRound(overall.xoff * _scale); + overall.yoff = tqRound(overall.yoff * _scale); + } + return overall; +} + +glyph_metrics_t TQFontEngineXLFD::boundingBox( glyph_t glyph ) +{ + glyph_metrics_t gm; + // ### scale missing! + XCharStruct *xcs = charStruct( _fs, glyph ); + if (xcs) { + gm = glyph_metrics_t( xcs->lbearing, -xcs->ascent, xcs->rbearing- xcs->lbearing, xcs->ascent + xcs->descent, xcs->width, 0 ); + } else { + int size = _fs->ascent; + gm = glyph_metrics_t( 0, size, size, size, size, 0 ); + } + if ( _scale != 1. ) { + gm.x = tqRound(gm.x * _scale); + gm.y = tqRound(gm.y * _scale); + gm.height = tqRound(gm.height * _scale); + gm.width = tqRound(gm.width * _scale); + gm.xoff = tqRound(gm.xoff * _scale); + gm.yoff = tqRound(gm.yoff * _scale); + } + return gm; +} + + +int TQFontEngineXLFD::ascent() const +{ + return tqRound(_fs->ascent*_scale); +} + +int TQFontEngineXLFD::descent() const +{ + return tqRound((_fs->descent-1)*_scale); +} + +int TQFontEngineXLFD::leading() const +{ + int l = tqRound((TQMIN(_fs->ascent, _fs->max_bounds.ascent) + + TQMIN(_fs->descent, _fs->max_bounds.descent)) * _scale * 0.15 ); + return (l > 0) ? l : 1; +} + +int TQFontEngineXLFD::maxCharWidth() const +{ + return tqRound(_fs->max_bounds.width*_scale); +} + + +// Loads the font for the specified script +static inline int maxIndex(XFontStruct *f) { + return (((f->max_byte1 - f->min_byte1) * + (f->max_char_or_byte2 - f->min_char_or_byte2 + 1)) + + f->max_char_or_byte2 - f->min_char_or_byte2); +} + +int TQFontEngineXLFD::minLeftBearing() const +{ + if ( lbearing == SHRT_MIN ) { + if ( _fs->per_char ) { + XCharStruct *cs = _fs->per_char; + int nc = maxIndex(_fs) + 1; + int mx = cs->lbearing; + + for (int c = 1; c < nc; c++) { + // ignore the bearings for characters whose ink is + // completely outside the normal bounding box + if ((cs[c].lbearing <= 0 && cs[c].rbearing <= 0) || + (cs[c].lbearing >= cs[c].width && cs[c].rbearing >= cs[c].width)) + continue; + + int nmx = cs[c].lbearing; + + if (nmx < mx) + mx = nmx; + } + + ((TQFontEngineXLFD *)this)->lbearing = mx; + } else + ((TQFontEngineXLFD *)this)->lbearing = _fs->min_bounds.lbearing; + } + return tqRound (lbearing*_scale); +} + +int TQFontEngineXLFD::minRightBearing() const +{ + if ( rbearing == SHRT_MIN ) { + if ( _fs->per_char ) { + XCharStruct *cs = _fs->per_char; + int nc = maxIndex(_fs) + 1; + int mx = cs->rbearing; + + for (int c = 1; c < nc; c++) { + // ignore the bearings for characters whose ink is + // completely outside the normal bounding box + if ((cs[c].lbearing <= 0 && cs[c].rbearing <= 0) || + (cs[c].lbearing >= cs[c].width && cs[c].rbearing >= cs[c].width)) + continue; + + int nmx = cs[c].rbearing; + + if (nmx < mx) + mx = nmx; + } + + ((TQFontEngineXLFD *)this)->rbearing = mx; + } else + ((TQFontEngineXLFD *)this)->rbearing = _fs->min_bounds.rbearing; + } + return tqRound (rbearing*_scale); +} + +int TQFontEngineXLFD::cmap() const +{ + return _cmap; +} + +const char *TQFontEngineXLFD::name() const +{ + return _name; +} + +bool TQFontEngineXLFD::canRender( const TQChar *string, int len ) +{ + glyph_t glyphs[256]; + int nglyphs = 255; + glyph_t *g = glyphs; + if ( stringToCMap( string, len, g, 0, &nglyphs, FALSE ) == OutOfMemory ) { + g = (glyph_t *)malloc( nglyphs*sizeof(glyph_t) ); + stringToCMap( string, len, g, 0, &nglyphs, FALSE ); + } + + bool allExist = TRUE; + for ( int i = 0; i < nglyphs; i++ ) { + if ( !g[i] || !charStruct( _fs, g[i] ) ) { + allExist = FALSE; + break; + } + } + + if ( g != glyphs ) + free( g ); + + return allExist; +} + + +void TQFontEngineXLFD::setScale( double scale ) +{ + _scale = scale; +} + + +TQFontEngine::Type TQFontEngineXLFD::type() const +{ + return XLFD; +} + + +// ------------------------------------------------------------------ +// LatinXLFD engine +// ------------------------------------------------------------------ + +static const int engine_array_inc = 4; + +TQFontEngineLatinXLFD::TQFontEngineLatinXLFD( XFontStruct *xfs, const char *name, + int mib ) +{ + _engines = new TQFontEngine*[ engine_array_inc ]; + _engines[0] = new TQFontEngineXLFD( xfs, name, mib ); + _count = 1; + + cache_cost = _engines[0]->cache_cost; + + memset( glyphIndices, 0, sizeof( glyphIndices ) ); + memset( glyphAdvances, 0, sizeof( glyphAdvances ) ); + euroIndex = 0; + euroAdvance = 0; +} + +TQFontEngineLatinXLFD::~TQFontEngineLatinXLFD() +{ + for ( int i = 0; i < _count; ++i ) { + delete _engines[i]; + _engines[i] = 0; + } + delete [] _engines; + _engines = 0; +} + +void TQFontEngineLatinXLFD::findEngine( const TQChar &ch ) +{ + if ( ch.unicode() == 0 ) return; + + static const char *alternate_encodings[] = { + "iso8859-1", + "iso8859-2", + "iso8859-3", + "iso8859-4", + "iso8859-9", + "iso8859-10", + "iso8859-13", + "iso8859-14", + "iso8859-15", + "hp-roman8" + }; + static const int mib_count = sizeof( alternate_encodings ) / sizeof( const char * ); + + // see if one of the above mibs can map the char we want + TQTextCodec *codec = 0; + int which = -1; + int i; + for ( i = 0; i < mib_count; ++i ) { + const int mib = qt_mib_for_xlfd_encoding( alternate_encodings[i] ); + bool skip = FALSE; + for ( int e = 0; e < _count; ++e ) { + if ( _engines[e]->cmap() == mib ) { + skip = TRUE; + break; + } + } + if ( skip ) continue; + + codec = TQTextCodec::codecForMib( mib ); + if ( codec && codec->canEncode( ch ) ) { + which = i; + break; + } + } + + if ( ! codec || which == -1 ) + return; + + const int enc_id = qt_xlfd_encoding_id( alternate_encodings[which] ); + TQFontDef req = fontDef; + TQFontEngine *engine = TQFontDatabase::findFont( TQFont::Latin, 0, req, enc_id ); + if ( ! engine ) { + req.family = TQString::null; + engine = TQFontDatabase::findFont( TQFont::Latin, 0, req, enc_id ); + if ( ! engine ) return; + } + engine->setScale( scale() ); + + if ( ! ( _count % engine_array_inc ) ) { + // grow the engines array + TQFontEngine **old = _engines; + int new_size = + ( ( ( _count+engine_array_inc ) / engine_array_inc ) * engine_array_inc ); + _engines = new TQFontEngine*[new_size]; + for ( i = 0; i < _count; ++i ) + _engines[i] = old[i]; + delete [] old; + } + + _engines[_count] = engine; + const int hi = _count << 8; + ++_count; + + unsigned short chars[0x201]; + glyph_t glyphs[0x201]; + advance_t advances[0x201]; + for ( i = 0; i < 0x200; ++i ) + chars[i] = i; + chars[0x200] = 0x20ac; + int glyphCount = 0x201; + engine->stringToCMap( (const TQChar *) chars, 0x201, glyphs, advances, &glyphCount, FALSE ); + + // merge member data with the above + for ( i = 0; i < 0x200; ++i ) { + if ( glyphIndices[i] != 0 || glyphs[i] == 0 ) continue; + glyphIndices[i] = glyphs[i] >= 0x2100 ? glyphs[i] : hi | glyphs[i]; + glyphAdvances[i] = advances[i]; + } + if (!euroIndex && glyphs[0x200]) { + euroIndex = hi | glyphs[0x200]; + euroAdvance = advances[0x200]; + } +} + +TQFontEngine::Error +TQFontEngineLatinXLFD::stringToCMap( const TQChar *str, int len, glyph_t *glyphs, + advance_t *advances, int *nglyphs, bool mirrored ) const +{ + if ( *nglyphs < len ) { + *nglyphs = len; + return OutOfMemory; + } + + int i; + bool missing = FALSE; + const TQChar *c = str+len; + glyph_t *g = glyphs+len; + if ( advances ) { + int asc = ascent(); + advance_t *a = advances+len; + if ( mirrored ) { + while ( c != str ) { + --c; + --g; + --a; + if ( c->unicode() < 0x200 ) { + unsigned short ch = ::mirroredChar(*c).unicode(); + *g = glyphIndices[ch]; + *a = glyphAdvances[ch]; + } else { + if ( c->unicode() == 0x20ac ) { + *g = euroIndex; + *a = euroAdvance; + } else { + *g = 0; + *a = asc; + } + } + missing = ( missing || ( *g == 0 ) ); + } + } else { + while ( c != str ) { + --c; + --g; + --a; + if ( c->unicode() < 0x200 ) { + *g = glyphIndices[c->unicode()]; + *a = glyphAdvances[c->unicode()]; + } else { + if ( c->unicode() == 0x20ac ) { + *g = euroIndex; + *a = euroAdvance; + } else { + *g = 0; + *a = asc; + } + } + missing = ( missing || ( *g == 0 ) ); + } + } + } else { + if ( mirrored ) { + while ( c != str ) { + --c; + --g; + *g = ( ( c->unicode() < 0x200 ) ? glyphIndices[::mirroredChar(*c).unicode()] + : (c->unicode() == 0x20ac) ? euroIndex : 0 ); + missing = ( missing || ( *g == 0 ) ); + } + } else { + while ( c != str ) { + --c; + --g; + *g = ( ( c->unicode() < 0x200 ) ? glyphIndices[c->unicode()] + : (c->unicode() == 0x20ac) ? euroIndex : 0 ); + missing = ( missing || ( *g == 0 ) ); + } + } + } + + if ( missing ) { + for ( i = 0; i < len; ++i ) { + unsigned short uc = str[i].unicode(); + if ( glyphs[i] != 0 || (uc >= 0x200 && uc != 0x20ac) ) + continue; + + TQFontEngineLatinXLFD *that = (TQFontEngineLatinXLFD *) this; + that->findEngine( str[i] ); + glyphs[i] = (uc == 0x20ac ? euroIndex : that->glyphIndices[uc]); + if ( advances ) + advances[i] = (uc == 0x20ac ? euroAdvance : glyphAdvances[uc]); + } + } + + *nglyphs = len; + return NoError; +} + +void TQFontEngineLatinXLFD::draw( TQPainter *p, int x, int y, const TQTextEngine *engine, + const TQScriptItem *si, int textFlags ) +{ + if ( !si->num_glyphs ) return; + + glyph_t *glyphs = engine->glyphs( si ); + advance_t *advances = engine->advances( si ); + int which = glyphs[0] >> 8; + if (which > 0x20) + which = 0; + + int start = 0; + int end, i; + for ( end = 0; end < si->num_glyphs; ++end ) { + int e = glyphs[end] >> 8; + if (e > 0x20) + e = 0; + if ( e == which ) continue; + + // set the high byte to zero + if (which != 0) { + for ( i = start; i < end; ++i ) + glyphs[i] = glyphs[i] & 0xff; + } + + // draw the text + TQScriptItem si2 = *si; + si2.glyph_data_offset = si->glyph_data_offset + start; + si2.num_glyphs = end - start; + _engines[which]->draw( p, x, y, engine, &si2, textFlags ); + + // reset the high byte for all glyphs and advance to the next sub-string + const int hi = which << 8; + for ( i = start; i < end; ++i ) { + glyphs[i] = hi | glyphs[i]; + x += advances[i]; + } + + // change engine + start = end; + which = e; + } + + // set the high byte to zero + if (which != 0) { + for ( i = start; i < end; ++i ) + glyphs[i] = glyphs[i] & 0xff; + } + // draw the text + TQScriptItem si2 = *si; + si2.glyph_data_offset = si->glyph_data_offset + start; + si2.num_glyphs = end - start; + _engines[which]->draw( p, x, y, engine, &si2, textFlags ); + + // reset the high byte for all glyphs + if (which != 0) { + const int hi = which << 8; + for ( i = start; i < end; ++i ) + glyphs[i] = hi | glyphs[i]; + } +} + +glyph_metrics_t TQFontEngineLatinXLFD::boundingBox( const glyph_t *glyphs_const, + const advance_t *advances, + const qoffset_t *offsets, + int numGlyphs ) +{ + if ( numGlyphs <= 0 ) return glyph_metrics_t(); + + glyph_metrics_t overall; + + glyph_t *glyphs = (glyph_t *) glyphs_const; + int which = glyphs[0] >> 8; + if (which > 0x20) + which = 0; + + int start = 0; + int end, i; + for ( end = 0; end < numGlyphs; ++end ) { + int e = glyphs[end] >> 8; + if (e > 0x20) + e = 0; + if ( e == which ) continue; + + // set the high byte to zero + if (which != 0) { + for ( i = start; i < end; ++i ) + glyphs[i] = glyphs[i] & 0xff; + } + + // merge the bounding box for this run + const glyph_metrics_t gm = + _engines[which]->boundingBox( glyphs + start, + advances + start, + offsets + start, + end - start ); + + overall.x = TQMIN( overall.x, gm.x ); + overall.y = TQMIN( overall.y, gm.y ); + overall.width = overall.xoff + gm.width; + overall.height = TQMAX( overall.height + overall.y, gm.height + gm.y ) - + TQMIN( overall.y, gm.y ); + overall.xoff += gm.xoff; + overall.yoff += gm.yoff; + + // reset the high byte for all glyphs + if (which != 0) { + const int hi = which << 8; + for ( i = start; i < end; ++i ) + glyphs[i] = hi | glyphs[i]; + } + + // change engine + start = end; + which = e; + } + + // set the high byte to zero + if (which != 0) { + for ( i = start; i < end; ++i ) + glyphs[i] = glyphs[i] & 0xff; + } + + // merge the bounding box for this run + const glyph_metrics_t gm = + _engines[which]->boundingBox( glyphs + start, + advances + start, + offsets + start, + end - start ); + + overall.x = TQMIN( overall.x, gm.x ); + overall.y = TQMIN( overall.y, gm.y ); + overall.width = overall.xoff + gm.width; + overall.height = TQMAX( overall.height + overall.y, gm.height + gm.y ) - + TQMIN( overall.y, gm.y ); + overall.xoff += gm.xoff; + overall.yoff += gm.yoff; + + // reset the high byte for all glyphs + if (which != 0) { + const int hi = which << 8; + for ( i = start; i < end; ++i ) + glyphs[i] = hi | glyphs[i]; + } + + return overall; +} + +glyph_metrics_t TQFontEngineLatinXLFD::boundingBox( glyph_t glyph ) +{ + int engine = glyph >> 8; + if (engine > 0x20) + engine = 0; + Q_ASSERT( engine < _count ); + return _engines[engine]->boundingBox( engine > 0 ? glyph & 0xff : glyph ); +} + +int TQFontEngineLatinXLFD::ascent() const +{ + return _engines[0]->ascent(); +} + +int TQFontEngineLatinXLFD::descent() const +{ + return _engines[0]->descent(); +} + +int TQFontEngineLatinXLFD::leading() const +{ + return _engines[0]->leading(); +} + +int TQFontEngineLatinXLFD::maxCharWidth() const +{ + return _engines[0]->maxCharWidth(); +} + +int TQFontEngineLatinXLFD::minLeftBearing() const +{ + return _engines[0]->minLeftBearing(); +} + +int TQFontEngineLatinXLFD::minRightBearing() const +{ + return _engines[0]->minRightBearing(); +} + +const char *TQFontEngineLatinXLFD::name() const +{ + return _engines[0]->name(); +} + +bool TQFontEngineLatinXLFD::canRender( const TQChar *string, int len ) +{ + bool all = TRUE; + int i; + for ( i = 0; i < len; ++i ) { + if ( string[i].unicode() >= 0x200 || + glyphIndices[string[i].unicode()] == 0 ) { + if (string[i].unicode() != 0x20ac || euroIndex == 0) + all = FALSE; + break; + } + } + + if ( all ) + return TRUE; + + all = TRUE; + for ( i = 0; i < len; ++i ) { + if ( string[i].unicode() >= 0x200 ) { + if (string[i].unicode() == 0x20ac) { + if (euroIndex) + continue; + + findEngine(string[i]); + if (euroIndex) + continue; + } + all = FALSE; + break; + } + if ( glyphIndices[string[i].unicode()] != 0 ) continue; + + findEngine( string[i] ); + if ( glyphIndices[string[i].unicode()] == 0 ) { + all = FALSE; + break; + } + } + + return all; +} + +void TQFontEngineLatinXLFD::setScale( double scale ) +{ + int i; + for ( i = 0; i < _count; ++i ) + _engines[i]->setScale( scale ); + unsigned short chars[0x200]; + for ( i = 0; i < 0x200; ++i ) + chars[i] = i; + int glyphCount = 0x200; + _engines[0]->stringToCMap( (const TQChar *)chars, 0x200, + glyphIndices, glyphAdvances, &glyphCount, FALSE ); +} + + +// ------------------------------------------------------------------ +// Xft cont engine +// ------------------------------------------------------------------ +// #define FONTENGINE_DEBUG + +#ifndef TQT_NO_XFTFREETYPE +class Q_HackPaintDevice : public TQPaintDevice +{ +public: + inline Q_HackPaintDevice() : TQPaintDevice( 0 ) {} + inline XftDraw *xftDrawHandle() const { + return (XftDraw *)rendhd; + } + +}; + +#ifdef QT_XFT2 +static inline void getGlyphInfo( XGlyphInfo *xgi, XftFont *font, int glyph ) +{ + FT_UInt x = glyph; + XftGlyphExtents( TQPaintDevice::x11AppDisplay(), font, &x, 1, xgi ); +} +#else +static inline XftFontStruct *getFontStruct( XftFont *font ) +{ + if (font->core) + return 0; + return font->u.ft.font; +} + +static inline void getGlyphInfo(XGlyphInfo *xgi, XftFont *font, int glyph) +{ + + XftTextExtents32(TQPaintDevice::x11AppDisplay(), font, (XftChar32 *) &glyph, 1, xgi); +} +#endif // QT_XFT2 + +static inline FT_Face lockFTFace( XftFont *font ) +{ +#ifdef QT_XFT2 + return XftLockFace( font ); +#else + if (font->core) return 0; + return font->u.ft.font->face; +#endif // QT_XFT2 +} + +static inline void unlockFTFace( XftFont *font ) +{ +#ifdef QT_XFT2 + XftUnlockFace( font ); +#else + Q_UNUSED( font ); +#endif // QT_XFT2 +} + + + +TQFontEngineXft::TQFontEngineXft( XftFont *font, XftPattern *pattern, int cmap ) + : _font( font ), _pattern( pattern ), _openType( 0 ), _cmap( cmap ) +{ + _face = lockFTFace( _font ); + +#ifndef QT_XFT2 + XftFontStruct *xftfs = getFontStruct( _font ); + if ( xftfs ) { + // dirty hack: we set the charmap in the Xftfreetype to -1, so + // XftFreetype assumes no encoding and really draws glyph + // indices. The FT_Face still has the Unicode encoding to we + // can convert from Unicode to glyph index + xftfs->charmap = -1; + } +#else + _cmap = -1; + // Xft maps Unicode and adobe roman for us. + for (int i = 0; i < _face->num_charmaps; ++i) { + FT_CharMap cm = _face->charmaps[i]; +// tqDebug("font has charmap %x", cm->encoding); + if (cm->encoding == ft_encoding_adobe_custom + || cm->encoding == ft_encoding_symbol) { +// tqDebug("font has adobe custom or ms symbol charmap"); + _cmap = i; + break; + } + } +#endif // QT_XFT2 + + + cache_cost = _font->height * _font->max_advance_width * + ( _face ? _face->num_glyphs : 1024 ); + + // if the Xft font is not antialiased, it uses bitmaps instead of + // 8-bit alpha maps... adjust the cache_cost to reflect this + Bool antialiased = TRUE; + if ( XftPatternGetBool( pattern, XFT_ANTIALIAS, + 0, &antialiased ) == XftResultMatch && + ! antialiased ) { + cache_cost /= 8; + } + lbearing = SHRT_MIN; + rbearing = SHRT_MIN; + + memset( widthCache, 0, sizeof(widthCache) ); + memset( cmapCache, 0, sizeof(cmapCache) ); +} + +TQFontEngineXft::~TQFontEngineXft() +{ + delete _openType; + unlockFTFace( _font ); + + XftFontClose( TQPaintDevice::x11AppDisplay(),_font ); + XftPatternDestroy( _pattern ); + _font = 0; + _pattern = 0; + TransformedFont *trf = transformed_fonts; + while ( trf ) { + XftFontClose( TQPaintDevice::x11AppDisplay(), trf->xft_font ); + TransformedFont *tmp = trf; + trf = trf->next; + delete tmp; + } +} + +#ifdef QT_XFT2 +static glyph_t getAdobeCharIndex(XftFont *font, int cmap, uint ucs4) +{ + FT_Face _face = XftLockFace( font ); + FT_Set_Charmap(_face, _face->charmaps[cmap]); + glyph_t g = FT_Get_Char_Index(_face, ucs4); + XftUnlockFace(font); + return g; +} +#endif + +TQFontEngine::Error TQFontEngineXft::stringToCMap( const TQChar *str, int len, glyph_t *glyphs, advance_t *advances, int *nglyphs, bool mirrored ) const +{ + if ( *nglyphs < len ) { + *nglyphs = len; + return OutOfMemory; + } + +#ifdef QT_XFT2 + if (_cmap != -1) { + for ( int i = 0; i < len; ++i ) { + unsigned short uc = str[i].unicode(); + if (mirrored) + uc = ::mirroredChar(str[i]).unicode(); + glyphs[i] = uc < cmapCacheSize ? cmapCache[uc] : 0; + if ( !glyphs[i] ) { + glyph_t glyph = XftCharIndex(0, _font, uc); + if (!glyph) + glyph = getAdobeCharIndex(_font, _cmap, uc); + glyphs[i] = glyph; + if ( uc < cmapCacheSize ) + ((TQFontEngineXft *)this)->cmapCache[uc] = glyph; + } + } + } else if ( mirrored ) { + for ( int i = 0; i < len; ++i ) { + unsigned short uc = ::mirroredChar(str[i]).unicode(); + glyphs[i] = uc < cmapCacheSize ? cmapCache[uc] : 0; + if ( !glyphs[i] ) { + if (uc == 0xa0) + uc = 0x20; + glyph_t glyph = XftCharIndex(0, _font, uc); + glyphs[i] = glyph; + if ( uc < cmapCacheSize ) + ((TQFontEngineXft *)this)->cmapCache[uc] = glyph; + } + } + } else { + for ( int i = 0; i < len; ++i ) { + unsigned short uc = str[i].unicode(); + glyphs[i] = uc < cmapCacheSize ? cmapCache[uc] : 0; + if ( !glyphs[i] ) { + if (uc == 0xa0) + uc = 0x20; + glyph_t glyph = XftCharIndex(0, _font, uc); + glyphs[i] = glyph; + if ( uc < cmapCacheSize ) + ((TQFontEngineXft *)this)->cmapCache[uc] = glyph; + } + } + } + + if ( advances ) { + for ( int i = 0; i < len; i++ ) { + FT_UInt glyph = *(glyphs + i); + advances[i] = (glyph < widthCacheSize) ? widthCache[glyph] : 0; + if ( !advances[i] ) { + XGlyphInfo gi; + XftGlyphExtents( TQPaintDevice::x11AppDisplay(), _font, &glyph, 1, &gi ); + advances[i] = gi.xOff; + if ( glyph < widthCacheSize && gi.xOff > 0 && gi.xOff < 0x100 ) + ((TQFontEngineXft *)this)->widthCache[glyph] = gi.xOff; + } + } + if ( _scale != 1. ) { + for ( int i = 0; i < len; i++ ) + advances[i] = tqRound(advances[i]*_scale); + } + } +#else + if ( !_face ) { + if ( mirrored ) { + for ( int i = 0; i < len; i++ ) + glyphs[i] = ::mirroredChar(str[i]).unicode(); + } else { + for ( int i = 0; i < len; i++ ) + glyphs[i] = str[i].unicode(); + } + } else { + if ( _cmap == 1 ) { + // symbol font + for ( int i = 0; i < len; i++ ) { + unsigned short uc = str[i].unicode(); + glyphs[i] = uc < cmapCacheSize ? cmapCache[uc] : 0; + if ( !glyphs[i] ) { + glyph_t glyph = FT_Get_Char_Index( _face, uc ); + if(!glyph && uc < 0x100) + glyph = FT_Get_Char_Index( _face, uc+0xf000 ); + glyphs[i] = glyph; + if ( uc < cmapCacheSize ) + ((TQFontEngineXft *)this)->cmapCache[uc] = glyph; + } + } + } else if ( mirrored ) { + for ( int i = 0; i < len; i++ ) { + unsigned short uc = ::mirroredChar(str[i]).unicode(); + glyphs[i] = uc < cmapCacheSize ? cmapCache[uc] : 0; + if ( !glyphs[i] ) { + glyph_t glyph = FT_Get_Char_Index( _face, uc ); + glyphs[i] = glyph; + if ( uc < cmapCacheSize ) + ((TQFontEngineXft *)this)->cmapCache[uc] = glyph; + } + } + } else { + for ( int i = 0; i < len; i++ ) { + unsigned short uc = str[i].unicode(); + glyphs[i] = uc < cmapCacheSize ? cmapCache[uc] : 0; + if ( !glyphs[i] ) { + glyph_t glyph = FT_Get_Char_Index( _face, uc ); + glyphs[i] = glyph; + if ( uc < cmapCacheSize ) + ((TQFontEngineXft *)this)->cmapCache[uc] = glyph; + } + } + } + } + + if ( advances ) { + for ( int i = 0; i < len; i++ ) { + XftChar16 glyph = *(glyphs + i); + advances[i] = (glyph < widthCacheSize) ? widthCache[glyph] : 0; + if ( !advances[i] ) { + XGlyphInfo gi; + XftTextExtents16(TQPaintDevice::x11AppDisplay(), _font, &glyph, 1, &gi); + advances[i] = gi.xOff; + if ( glyph < widthCacheSize && gi.xOff > 0 && gi.xOff < 0x100 ) + ((TQFontEngineXft *)this)->widthCache[glyph] = gi.xOff; + } + } + if ( _scale != 1. ) { + for ( int i = 0; i < len; i++ ) + advances[i] = tqRound(advances[i]*_scale); + } + } +#endif // QT_XFT2 + + *nglyphs = len; + return NoError; +} + + +void TQFontEngineXft::recalcAdvances( int len, glyph_t *glyphs, advance_t *advances ) +{ + +#ifdef QT_XFT2 + for ( int i = 0; i < len; i++ ) { + FT_UInt glyph = *(glyphs + i); + advances[i] = (glyph < widthCacheSize) ? widthCache[glyph] : 0; + if ( !advances[i] ) { + XGlyphInfo gi; + XftGlyphExtents( TQPaintDevice::x11AppDisplay(), _font, &glyph, 1, &gi ); + advances[i] = gi.xOff; + if ( glyph < widthCacheSize && gi.xOff > 0 && gi.xOff < 0x100 ) + ((TQFontEngineXft *)this)->widthCache[glyph] = gi.xOff; + } + if ( _scale != 1. ) { + for ( int i = 0; i < len; i++ ) + advances[i] = tqRound(advances[i]*_scale); + } + } +#else + for ( int i = 0; i < len; i++ ) { + XftChar16 glyph = *(glyphs + i); + advances[i] = (glyph < widthCacheSize) ? widthCache[glyph] : 0; + if ( !advances[i] ) { + XGlyphInfo gi; + XftTextExtents16(TQPaintDevice::x11AppDisplay(), _font, &glyph, 1, &gi); + advances[i] = gi.xOff; + if ( glyph < widthCacheSize && gi.xOff > 0 && gi.xOff < 0x100 ) + ((TQFontEngineXft *)this)->widthCache[glyph] = gi.xOff; + } + } + if ( _scale != 1. ) { + for ( int i = 0; i < len; i++ ) + advances[i] = tqRound(advances[i]*_scale); + } +#endif // QT_XFT2 +} + +//#define FONTENGINE_DEBUG +void TQFontEngineXft::draw( TQPainter *p, int x, int y, const TQTextEngine *engine, const TQScriptItem *si, int textFlags ) +{ + if ( !si->num_glyphs ) + return; + + Display *dpy = TQPaintDevice::x11AppDisplay(); + + int xorig = x; + int yorig = y; + + GlyphAttributes *glyphAttributes = engine->glyphAttributes( si ); + + XftFont *fnt = _font; + bool transform = FALSE; + if ( p->txop >= TQPainter::TxScale || p->rop != TQt::CopyROP || _scale < 0.9999 || _scale > 1.001) { + bool can_scale = (_face->face_flags & FT_FACE_FLAG_SCALABLE) && p->rop == TQt::CopyROP; + double size = (p->m11()*p->m22() - p->m12()*p->m21())*_scale*_scale*fontDef.pixelSize*fontDef.pixelSize; + if (size > 256*256 || _scale < .9999 || _scale > 1.001) + can_scale = FALSE; + if (!can_scale) { + // font doesn't support transformations, need to do it by hand + float tmp = _scale; + _scale = 1.; + drawScaled(x, y, engine, si, textFlags, dpy, p->gc, p->device(), this, p->xmat, tmp); + _scale = tmp; + return; + } + + XftMatrix *mat = 0; + XftPatternGetMatrix( _pattern, XFT_MATRIX, 0, &mat ); + XftMatrix m2; + m2.xx = p->m11()*_scale; + m2.xy = -p->m21()*_scale; + m2.yx = -p->m12()*_scale; + m2.yy = p->m22()*_scale; + + // check if we have it cached + TransformedFont *trf = transformed_fonts; + TransformedFont *prev = 0; + int i = 0; + while ( trf ) { + if ( trf->xx == (float)m2.xx && + trf->xy == (float)m2.xy && + trf->yx == (float)m2.yx && + trf->yy == (float)m2.yy ) + break; + TransformedFont *tmp = trf; + trf = trf->next; + if (i > 10) { + XftFontClose( TQPaintDevice::x11AppDisplay(), tmp->xft_font ); + delete tmp; + prev->next = trf; + } else { + prev = tmp; + } + ++i; + } + if ( trf ) { + if ( prev ) { + // move to beginning of list + prev->next = trf->next; + trf->next = transformed_fonts; + transformed_fonts = trf; + } + fnt = trf->xft_font; + } else { + if ( mat ) + XftMatrixMultiply( &m2, &m2, mat ); + + XftPattern *pattern = XftPatternDuplicate( _pattern ); + XftPatternDel( pattern, XFT_MATRIX ); + XftPatternAddMatrix( pattern, XFT_MATRIX, &m2 ); + + fnt = XftFontOpenPattern( dpy, pattern ); +#ifndef QT_XFT2 + XftFontStruct *xftfs = getFontStruct( fnt ); + if ( xftfs ) { + // dirty hack: we set the charmap in the Xftfreetype to -1, so + // XftFreetype assumes no encoding and really draws glyph + // indices. The FT_Face still has the Unicode encoding to we + // can convert from Unicode to glyph index + xftfs->charmap = -1; + } +#endif // QT_XFT2 + TransformedFont *trf = new TransformedFont; + trf->xx = (float)m2.xx; + trf->xy = (float)m2.xy; + trf->yx = (float)m2.yx; + trf->yy = (float)m2.yy; + trf->xft_font = fnt; + trf->next = transformed_fonts; + transformed_fonts = trf; + } + transform = TRUE; + } else if ( p->txop == TQPainter::TxTranslate ) { + p->map( x, y, &x, &y ); + } + + glyph_t *glyphs = engine->glyphs( si ); + advance_t *advances = engine->advances( si ); + qoffset_t *offsets = engine->offsets( si ); + + const TQColor &pen = p->cpen.color(); + XftDraw *draw = ((Q_HackPaintDevice *)p->pdev)->xftDrawHandle(); + + XftColor col; + col.color.red = pen.red () | pen.red() << 8; + col.color.green = pen.green () | pen.green() << 8; + col.color.blue = pen.blue () | pen.blue() << 8; + col.color.alpha = 0xffff; + col.pixel = pen.pixel(); +#ifdef FONTENGINE_DEBUG + tqDebug("===== drawing %d glyphs reverse=%s ======", si->num_glyphs, si->analysis.bidiLevel % 2?"TRUE":"FALSE" ); + p->save(); + p->setBrush( TQt::white ); + glyph_metrics_t ci = boundingBox( glyphs, advances, offsets, si->num_glyphs ); + p->drawRect( x + ci.x, y + ci.y, ci.width, ci.height ); + p->drawRect( x + ci.x, y + 100 + ci.y, ci.width, ci.height ); + tqDebug("bounding rect=%d %d (%d/%d)", ci.x, ci.y, ci.width, ci.height ); + p->restore(); + int yp = y; + int xp = x; +#endif + + if ( textFlags != 0 ) + drawLines( p, this, yorig, xorig, si->width, textFlags ); + + + if ( si->isSpace ) + return; + + if ( transform || si->hasPositioning ) { + if ( si->analysis.bidiLevel % 2 ) { + int i = si->num_glyphs; + while( i-- ) { + int xp = x + offsets[i].x; + int yp = y + offsets[i].y; + if ( transform ) + p->map( xp, yp, &xp, &yp ); +#ifdef QT_XFT2 + FT_UInt glyph = *(glyphs + i); + if (!glyphAttributes[i].zeroWidth && xp < SHRT_MAX && xp > SHRT_MIN) + XftDrawGlyphs( draw, &col, fnt, xp, yp, &glyph, 1 ); +#else + if (!glyphAttributes[i].zeroWidth && xp < SHRT_MAX && xp > SHRT_MIN) + XftDrawString16( draw, &col, fnt, xp, yp, (XftChar16 *) (glyphs+i), 1); +#endif // QT_XFT2 +#ifdef FONTENGINE_DEBUG + glyph_metrics_t gi = boundingBox( glyphs[i] ); + p->drawRect( x+offsets[i].x+gi.x, y+offsets[i].y+100+gi.y, gi.width, gi.height ); + p->drawLine( x+offsets[i].x, y + 150 + 5*i , x+offsets[i].x+advances[i], y + 150 + 5*i ); + p->drawLine( x+offsets[i].x, y + 152 + 5*i , x+offsets[i].x+gi.xoff, y + 152 + 5*i ); + tqDebug("bounding ci[%d]=%d %d (%d/%d) / %d %d offs=(%d/%d) advance=%d", i, gi.x, gi.y, gi.width, gi.height, + gi.xoff, gi.yoff, offsets[i].x, offsets[i].y, advances[i]); +#endif + x += advances[i]; + } + } else { + int i = 0; + while ( i < si->num_glyphs ) { + int xp = x + offsets[i].x; + int yp = y + offsets[i].y; + if ( transform ) + p->map( xp, yp, &xp, &yp ); +#ifdef QT_XFT2 + FT_UInt glyph = *(glyphs + i); + if (!glyphAttributes[i].zeroWidth && xp < SHRT_MAX && xp > SHRT_MIN) + XftDrawGlyphs( draw, &col, fnt, xp, yp, &glyph, 1 ); +#else + if (!glyphAttributes[i].zeroWidth && xp < SHRT_MAX && xp > SHRT_MIN) + XftDrawString16( draw, &col, fnt, xp, yp, (XftChar16 *) (glyphs+i), 1 ); +#endif // QT_XFT2 + // tqDebug("advance = %d/%d", adv.x, adv.y ); + x += advances[i]; + i++; + } + } + } else { + // Xft has real trouble drawing the glyphs on their own. + // Drawing them as one string increases performance significantly. +#ifdef QT_XFT2 + // #### we should use a different method anyways on Xft2 + FT_UInt g[64]; + int gl = 0; + while (gl < si->num_glyphs) { + int toDraw = TQMIN(64, si->num_glyphs-gl); + int adv = 0; + if ( si->analysis.bidiLevel % 2 ) { + for ( int i = 0; i < toDraw; i++ ) { + g[i] = glyphs[si->num_glyphs-1-(gl+i)]; + adv += advances[si->num_glyphs-1-(gl+i)]; + } + } else { + for ( int i = 0; i < toDraw; i++ ) { + g[i] = glyphs[gl+i]; + adv += advances[gl+i]; + } + } + if (x + adv < SHRT_MAX && x > SHRT_MIN) + XftDrawGlyphs( draw, &col, fnt, x, y, g, toDraw ); + gl += toDraw; + x += adv; + } +#else + XftChar16 g[64]; + int gl = 0; + while (gl < si->num_glyphs) { + int toDraw = TQMIN(64, si->num_glyphs-gl); + int adv = 0; + if ( si->analysis.bidiLevel % 2 ) { + for ( int i = 0; i < toDraw; i++ ) { + g[i] = glyphs[si->num_glyphs-1-(gl+i)]; + adv += advances[si->num_glyphs-1-(gl+i)]; + } + } else { + for ( int i = 0; i < toDraw; i++ ) { + g[i] = glyphs[gl+i]; + adv += advances[gl+i]; + } + } + if (x + adv < SHRT_MAX && x > SHRT_MIN) + XftDrawString16( draw, &col, fnt, x, y, g, toDraw ); + gl += toDraw; + x += adv; + } +#endif // QT_XFT2 + } + +#ifdef FONTENGINE_DEBUG + if ( !si->analysis.bidiLevel % 2 ) { + x = xp; + y = yp; + p->save(); + p->setPen( TQt::red ); + for ( int i = 0; i < si->num_glyphs; i++ ) { + glyph_metrics_t ci = boundingBox( glyphs[i] ); + p->drawRect( x + ci.x + offsets[i].x, y + 100 + ci.y + offsets[i].y, ci.width, ci.height ); + tqDebug("bounding ci[%d]=%d %d (%d/%d) / %d %d offs=(%d/%d) advance=%d", i, ci.x, ci.y, ci.width, ci.height, + ci.xoff, ci.yoff, offsets[i].x, offsets[i].y, advances[i]); + x += advances[i]; + } + p->restore(); + } +#endif +} + +glyph_metrics_t TQFontEngineXft::boundingBox( const glyph_t *glyphs, const advance_t *advances, const qoffset_t *offsets, int numGlyphs ) +{ + XGlyphInfo xgi; + + glyph_metrics_t overall; + int ymax = 0; + int xmax = 0; + if (_scale != 1) { + for (int i = 0; i < numGlyphs; i++) { + getGlyphInfo( &xgi, _font, glyphs[i] ); + int x = overall.xoff + offsets[i].x - xgi.x; + int y = overall.yoff + offsets[i].y - xgi.y; + overall.x = TQMIN( overall.x, x ); + overall.y = TQMIN( overall.y, y ); + xmax = TQMAX( xmax, x + xgi.width ); + ymax = TQMAX( ymax, y + xgi.height ); + overall.xoff += tqRound(advances[i]/_scale); + } + overall.x = tqRound(overall.x * _scale); + overall.y = tqRound(overall.y * _scale); + overall.xoff = tqRound(overall.xoff * _scale); + overall.yoff = tqRound(overall.yoff * _scale); + xmax = tqRound(xmax * _scale); + ymax = tqRound(ymax * _scale); + } else { + for (int i = 0; i < numGlyphs; i++) { + getGlyphInfo( &xgi, _font, glyphs[i] ); + int x = overall.xoff + offsets[i].x - xgi.x; + int y = overall.yoff + offsets[i].y - xgi.y; + overall.x = TQMIN( overall.x, x ); + overall.y = TQMIN( overall.y, y ); + xmax = TQMAX( xmax, x + xgi.width ); + ymax = TQMAX( ymax, y + xgi.height ); + overall.xoff += advances[i]; + } + } + overall.height = ymax - overall.y; + overall.width = xmax - overall.x; + return overall; +} + +glyph_metrics_t TQFontEngineXft::boundingBox( glyph_t glyph ) +{ + XGlyphInfo xgi; + getGlyphInfo( &xgi, _font, glyph ); + glyph_metrics_t gm = glyph_metrics_t( -xgi.x, -xgi.y, xgi.width, xgi.height, xgi.xOff, -xgi.yOff ); + if ( _scale != 1. ) { + gm.x = tqRound(gm.x * _scale); + gm.y = tqRound(gm.y * _scale); + gm.height = tqRound(gm.height * _scale); + gm.width = tqRound(gm.width * _scale); + gm.xoff = tqRound(gm.xoff * _scale); + gm.yoff = tqRound(gm.yoff * _scale); + } + return gm; +} + + + +int TQFontEngineXft::ascent() const +{ + return tqRound(_font->ascent*_scale); +} + +int TQFontEngineXft::descent() const +{ + return tqRound((_font->descent-1)*_scale); +} + +// #### use Freetype to determine this +int TQFontEngineXft::leading() const +{ + int l = tqRound(TQMIN( _font->height - (_font->ascent + _font->descent), + ((_font->ascent + _font->descent) >> 4)*_scale )); + return (l > 0) ? l : 1; +} + +// #### use Freetype to determine this +int TQFontEngineXft::lineThickness() const +{ + // ad hoc algorithm + int score = fontDef.weight * fontDef.pixelSize; + int lw = score / 700; + + // looks better with thicker line for small pointsizes + if ( lw < 2 && score >= 1050 ) lw = 2; + if ( lw == 0 ) lw = 1; + + return lw; +} + +// #### use Freetype to determine this +int TQFontEngineXft::underlinePosition() const +{ + int pos = ( ( lineThickness() * 2 ) + 3 ) / 6; + return pos ? pos : 1; +} + +int TQFontEngineXft::maxCharWidth() const +{ + return tqRound(_font->max_advance_width*_scale); +} + +static const ushort char_table[] = { + 40, + 67, + 70, + 75, + 86, + 88, + 89, + 91, + 102, + 114, + 124, + 127, + 205, + 645, + 884, + 922, + 1070, + 12386 +}; + +static const int char_table_entries = sizeof(char_table)/sizeof(ushort); + + +int TQFontEngineXft::minLeftBearing() const +{ + if ( lbearing == SHRT_MIN ) + minRightBearing(); // calculates both + + return lbearing; +} + +int TQFontEngineXft::minRightBearing() const +{ + if ( rbearing == SHRT_MIN ) { + TQFontEngineXft *that = (TQFontEngineXft *)this; + that->lbearing = that->rbearing = 0; + TQChar *ch = (TQChar *)char_table; + glyph_t glyphs[char_table_entries]; + int ng = char_table_entries; + stringToCMap(ch, char_table_entries, glyphs, 0, &ng, FALSE); + while (--ng) { + if (glyphs[ng]) { + glyph_metrics_t gi = that->boundingBox( glyphs[ng] ); + if (gi.xoff) { + that->lbearing = TQMIN(lbearing, gi.x); + that->rbearing = TQMIN(rbearing, gi.xoff - gi.x - gi.width); + } + } + } + } + + return rbearing; +} + +int TQFontEngineXft::cmap() const +{ + return _cmap; +} + +const char *TQFontEngineXft::name() const +{ + return "xft"; +} + +void TQFontEngineXft::setScale( double scale ) +{ + _scale = scale; +} + +bool TQFontEngineXft::canRender( const TQChar *string, int len ) +{ + bool allExist = TRUE; + +#ifdef QT_XFT2 + if (_cmap != -1) { + for ( int i = 0; i < len; i++ ) { + if (!XftCharExists(0, _font, string[i].unicode()) + && getAdobeCharIndex(_font, _cmap, string[i].unicode()) == 0) { + allExist = FALSE; + break; + } + } + } else { + for ( int i = 0; i < len; i++ ) { + if (!XftCharExists(0, _font, string[i].unicode())) { + allExist = FALSE; + break; + } + } + } +#else + glyph_t glyphs[256]; + int nglyphs = 255; + glyph_t *g = glyphs; + if ( stringToCMap( string, len, g, 0, &nglyphs, FALSE ) == OutOfMemory ) { + g = (glyph_t *)malloc( nglyphs*sizeof(glyph_t) ); + stringToCMap( string, len, g, 0, &nglyphs, FALSE ); + } + + for ( int i = 0; i < nglyphs; i++ ) { + if ( !XftGlyphExists(TQPaintDevice::x11AppDisplay(), _font, g[i]) ) { + allExist = FALSE; + break; + } + } + + if ( g != glyphs ) + free( g ); +#endif // QT_XFT2 + + return allExist; +} + +TQOpenType *TQFontEngineXft::openType() const +{ +// tqDebug("openTypeIface requested!"); + if ( _openType ) + return _openType; + + if ( !_face || ! FT_IS_SFNT( _face ) ) + return 0; + + TQFontEngineXft *that = (TQFontEngineXft *)this; + that->_openType = new TQOpenType(that); + return _openType; +} + + +TQFontEngine::Type TQFontEngineXft::type() const +{ + return Xft; +} +#endif + + +// -------------------------------------------------------------------------------------------------------------------- +// Open type support +// -------------------------------------------------------------------------------------------------------------------- + +#ifndef TQT_NO_XFTFREETYPE + +#include "qscriptengine_p.h" + +//#define OT_DEBUG + +#ifdef OT_DEBUG +static inline char *tag_to_string(FT_ULong tag) +{ + static char string[5]; + string[0] = (tag >> 24)&0xff; + string[1] = (tag >> 16)&0xff; + string[2] = (tag >> 8)&0xff; + string[3] = tag&0xff; + string[4] = 0; + return string; +} +#endif + +#define DefaultLangSys 0xffff +#define DefaultScript FT_MAKE_TAG('D', 'F', 'L', 'T') + +enum { + RequiresGsub = 1, + RequiresGpos = 2 +}; + +struct OTScripts { + unsigned int tag; + int flags; +}; + +static const OTScripts ot_scripts [] = { +// // European Alphabetic Scripts +// Latin, + { FT_MAKE_TAG( 'l', 'a', 't', 'n' ), 0 }, +// Greek, + { FT_MAKE_TAG( 'g', 'r', 'e', 'k' ), 0 }, +// Cyrillic, + { FT_MAKE_TAG( 'c', 'y', 'r', 'l' ), 0 }, +// Armenian, + { FT_MAKE_TAG( 'a', 'r', 'm', 'n' ), 0 }, +// Georgian, + { FT_MAKE_TAG( 'g', 'e', 'o', 'r' ), 0 }, +// Runic, + { FT_MAKE_TAG( 'r', 'u', 'n', 'r' ), 0 }, +// Ogham, + { FT_MAKE_TAG( 'o', 'g', 'a', 'm' ), 0 }, +// SpacingModifiers, + { FT_MAKE_TAG( 'D', 'F', 'L', 'T' ), 0 }, +// CombiningMarks, + { FT_MAKE_TAG( 'D', 'F', 'L', 'T' ), 0 }, + +// // Middle Eastern Scripts +// Hebrew, + { FT_MAKE_TAG( 'h', 'e', 'b', 'r' ), 1 }, +// Arabic, + { FT_MAKE_TAG( 'a', 'r', 'a', 'b' ), 1 }, +// Syriac, + { FT_MAKE_TAG( 's', 'y', 'r', 'c' ), 1 }, +// Thaana, + { FT_MAKE_TAG( 't', 'h', 'a', 'a' ), 1 }, + +// // South and Southeast Asian Scripts +// Devanagari, + { FT_MAKE_TAG( 'd', 'e', 'v', 'a' ), 1 }, +// Bengali, + { FT_MAKE_TAG( 'b', 'e', 'n', 'g' ), 1 }, +// Gurmukhi, + { FT_MAKE_TAG( 'g', 'u', 'r', 'u' ), 1 }, +// Gujarati, + { FT_MAKE_TAG( 'g', 'u', 'j', 'r' ), 1 }, +// Oriya, + { FT_MAKE_TAG( 'o', 'r', 'y', 'a' ), 1 }, +// Tamil, + { FT_MAKE_TAG( 't', 'a', 'm', 'l' ), 1 }, +// Telugu, + { FT_MAKE_TAG( 't', 'e', 'l', 'u' ), 1 }, +// Kannada, + { FT_MAKE_TAG( 'k', 'n', 'd', 'a' ), 1 }, +// Malayalam, + { FT_MAKE_TAG( 'm', 'l', 'y', 'm' ), 1 }, +// Sinhala, + // ### could not find any OT specs on this + { FT_MAKE_TAG( 's', 'i', 'n', 'h' ), 1 }, +// Thai, + { FT_MAKE_TAG( 't', 'h', 'a', 'i' ), 1 }, +// Lao, + { FT_MAKE_TAG( 'l', 'a', 'o', ' ' ), 1 }, +// Tibetan, + { FT_MAKE_TAG( 't', 'i', 'b', 't' ), 1 }, +// Myanmar, + { FT_MAKE_TAG( 'm', 'y', 'm', 'r' ), 1 }, +// Khmer, + { FT_MAKE_TAG( 'k', 'h', 'm', 'r' ), 1 }, + +// // East Asian Scripts +// Han, + { FT_MAKE_TAG( 'h', 'a', 'n', 'i' ), 0 }, +// Hiragana, + { FT_MAKE_TAG( 'k', 'a', 'n', 'a' ), 0 }, +// Katakana, + { FT_MAKE_TAG( 'k', 'a', 'n', 'a' ), 0 }, +// Hangul, + { FT_MAKE_TAG( 'h', 'a', 'n', 'g' ), 1 }, +// Bopomofo, + { FT_MAKE_TAG( 'b', 'o', 'p', 'o' ), 0 }, +// Yi, + { FT_MAKE_TAG( 'y', 'i', ' ', ' ' ), 0 }, + +// // Additional Scripts +// Ethiopic, + { FT_MAKE_TAG( 'e', 't', 'h', 'i' ), 0 }, +// Cherokee, + { FT_MAKE_TAG( 'c', 'h', 'e', 'r' ), 0 }, +// CanadianAboriginal, + { FT_MAKE_TAG( 'c', 'a', 'n', 's' ), 0 }, +// Mongolian, + { FT_MAKE_TAG( 'm', 'o', 'n', 'g' ), 0 }, +// // Symbols +// CurrencySymbols, + { FT_MAKE_TAG( 'D', 'F', 'L', 'T' ), 0 }, +// LetterlikeSymbols, + { FT_MAKE_TAG( 'D', 'F', 'L', 'T' ), 0 }, +// NumberForms, + { FT_MAKE_TAG( 'D', 'F', 'L', 'T' ), 0 }, +// MathematicalOperators, + { FT_MAKE_TAG( 'D', 'F', 'L', 'T' ), 0 }, +// TechnicalSymbols, + { FT_MAKE_TAG( 'D', 'F', 'L', 'T' ), 0 }, +// GeometricSymbols, + { FT_MAKE_TAG( 'D', 'F', 'L', 'T' ), 0 }, +// MiscellaneousSymbols, + { FT_MAKE_TAG( 'D', 'F', 'L', 'T' ), 0 }, +// EnclosedAndSquare, + { FT_MAKE_TAG( 'D', 'F', 'L', 'T' ), 0 }, +// Braille, + { FT_MAKE_TAG( 'b', 'r', 'a', 'i' ), 0 }, +// Unicode, should be used + { FT_MAKE_TAG( 'D', 'F', 'L', 'T' ), 0 } + // ### where are these? +// { FT_MAKE_TAG( 'b', 'y', 'z', 'm' ), 0 }, +// { FT_MAKE_TAG( 'D', 'F', 'L', 'T' ), 0 }, + // ### Hangul Jamo +// { FT_MAKE_TAG( 'j', 'a', 'm', 'o' ), 0 }, +}; + +TQOpenType::TQOpenType(TQFontEngineXft *fe) + : fontEngine(fe), gdef(0), gsub(0), gpos(0), current_script(0) +{ + face = fe->face(); + otl_buffer_new(face->memory, &otl_buffer); + tmpAttributes = 0; + tmpLogClusters = 0; + + FT_Error error; + if ((error = TT_Load_GDEF_Table(face, &gdef))) { +#ifdef OT_DEBUG + tqDebug("error loading gdef table: %d", error); +#endif + gdef = 0; + } + + if ((error = TT_Load_GSUB_Table(face, &gsub, gdef))) { + gsub = 0; +#ifdef OT_DEBUG + if (error != FT_Err_Table_Missing) { + tqDebug("error loading gsub table: %d", error); + } else { + tqDebug("face doesn't have a gsub table"); + } +#endif + } + + if ((error = TT_Load_GPOS_Table(face, &gpos, gdef))) { + gpos = 0; +#ifdef OT_DEBUG + tqDebug("error loading gpos table: %d", error); +#endif + } + + for (uint i = 0; i < TQFont::NScripts; ++i) + supported_scripts[i] = checkScript(i); +} + +TQOpenType::~TQOpenType() +{ + if (gpos) + TT_Done_GPOS_Table(gpos); + if (gsub) + TT_Done_GSUB_Table(gsub); + if (gdef) + TT_Done_GDEF_Table(gdef); + if (otl_buffer) + otl_buffer_free(otl_buffer); + if (tmpAttributes) + free(tmpAttributes); + if (tmpLogClusters) + free(tmpLogClusters); +} + +bool TQOpenType::checkScript(unsigned int script) +{ + assert(script < TQFont::NScripts); + + uint tag = ot_scripts[script].tag; + int requirements = ot_scripts[script].flags; + + if (requirements & RequiresGsub) { + if (!gsub) + return FALSE; + + FT_UShort script_index; + FT_Error error = TT_GSUB_Select_Script(gsub, tag, &script_index); + if (error) { +#ifdef OT_DEBUG + tqDebug("could not select script %d in GSub table: %d", (int)script, error); +#endif + return FALSE; + } + } + + if (requirements & RequiresGpos) { + if (!gpos) + return FALSE; + + FT_UShort script_index; + FT_Error error = TT_GPOS_Select_Script(gpos, script, &script_index); + if (error) { +#ifdef OT_DEBUG + tqDebug("could not select script in gpos table: %d", error); +#endif + return FALSE; + } + + } + return TRUE; +} + + +void TQOpenType::selectScript(unsigned int script, const Features *features) +{ + if (current_script == script) + return; + + assert(script < TQFont::NScripts); + // find script in our list of supported scripts. + uint tag = ot_scripts[script].tag; + + if (gsub && features) { +#ifdef OT_DEBUG + { + TTO_FeatureList featurelist = gsub->FeatureList; + int numfeatures = featurelist.FeatureCount; + tqDebug("gsub table has %d features", numfeatures); + for(int i = 0; i < numfeatures; i++) { + TTO_FeatureRecord *r = featurelist.FeatureRecord + i; + tqDebug(" feature '%s'", tag_to_string(r->FeatureTag)); + } + } +#endif + TT_GSUB_Clear_Features(gsub); + FT_UShort script_index; + FT_Error error = TT_GSUB_Select_Script(gsub, tag, &script_index); + if (!error) { +#ifdef OT_DEBUG + tqDebug("script %s has script index %d", tag_to_string(script), script_index); +#endif + while (features->tag) { + FT_UShort feature_index; + error = TT_GSUB_Select_Feature(gsub, features->tag, script_index, 0xffff, &feature_index); + if (!error) { +#ifdef OT_DEBUG + tqDebug(" adding feature %s", tag_to_string(features->tag)); +#endif + TT_GSUB_Add_Feature(gsub, feature_index, features->property); + } + ++features; + } + } + } + + if (gpos) { + TT_GPOS_Clear_Features(gpos); + FT_UShort script_index; + FT_Error error = TT_GPOS_Select_Script(gpos, tag, &script_index); + if (!error) { +#ifdef OT_DEBUG + { + TTO_FeatureList featurelist = gpos->FeatureList; + int numfeatures = featurelist.FeatureCount; + tqDebug("gpos table has %d features", numfeatures); + for(int i = 0; i < numfeatures; i++) { + TTO_FeatureRecord *r = featurelist.FeatureRecord + i; + FT_UShort feature_index; + TT_GPOS_Select_Feature(gpos, r->FeatureTag, script_index, 0xffff, &feature_index); + tqDebug(" feature '%s'", tag_to_string(r->FeatureTag)); + } + } +#endif + FT_ULong *feature_tag_list; + error = TT_GPOS_Query_Features(gpos, script_index, 0xffff, &feature_tag_list); + if (!error) { + while (*feature_tag_list) { + FT_UShort feature_index; + error = TT_GPOS_Select_Feature(gpos, *feature_tag_list, script_index, 0xffff, &feature_index); + if (!error) + TT_GPOS_Add_Feature(gpos, feature_index, PositioningProperties); + ++feature_tag_list; + } + } + } + } + + current_script = script; +} + +#ifdef OT_DEBUG +static void dump_string(OTL_Buffer buffer) +{ + for (uint i = 0; i < buffer->in_length; ++i) { + tqDebug(" %x: cluster=%d", buffer->in_string[i].gindex, buffer->in_string[i].cluster); + } +} +#endif + +extern void qt_heuristicPosition(TQShaperItem *item); + +bool TQOpenType::shape(TQShaperItem *item, const unsigned int *properties) +{ + length = item->num_glyphs; + + otl_buffer_clear(otl_buffer); + + tmpAttributes = (GlyphAttributes *) realloc(tmpAttributes, length*sizeof(GlyphAttributes)); + tmpLogClusters = (unsigned int *) realloc(tmpLogClusters, length*sizeof(unsigned int)); + for (int i = 0; i < length; ++i) { + otl_buffer_add_glyph(otl_buffer, item->glyphs[i], properties ? properties[i] : 0, i); + tmpAttributes[i] = item->attributes[i]; + tmpLogClusters[i] = item->log_clusters[i]; + } + +#ifdef OT_DEBUG + tqDebug("-----------------------------------------"); +// tqDebug("log clusters before shaping:"); +// for (int j = 0; j < length; j++) +// tqDebug(" log[%d] = %d", j, item->log_clusters[j]); + tqDebug("original glyphs: %p", item->glyphs); + for (int i = 0; i < length; ++i) + tqDebug(" glyph=%4x", otl_buffer->in_string[i].gindex); +// dump_string(otl_buffer); +#endif + + loadFlags = FT_LOAD_DEFAULT; + + if (gsub) { + uint error = TT_GSUB_Apply_String(gsub, otl_buffer); + if (error && error != TTO_Err_Not_Covered) + return false; + } + +#ifdef OT_DEBUG +// tqDebug("log clusters before shaping:"); +// for (int j = 0; j < length; j++) +// tqDebug(" log[%d] = %d", j, item->log_clusters[j]); + tqDebug("shaped glyphs:"); + for (int i = 0; i < length; ++i) + tqDebug(" glyph=%4x", otl_buffer->in_string[i].gindex); + tqDebug("-----------------------------------------"); +// dump_string(otl_buffer); +#endif + + return true; +} + +bool TQOpenType::positionAndAdd(TQShaperItem *item, bool doLogClusters) +{ + if (gpos) { +#ifdef TQ_WS_X11 + Q_ASSERT(fontEngine->type() == TQFontEngine::Xft); + face = lockFTFace(static_cast(fontEngine)->font()); +#endif + memset(otl_buffer->positions, 0, otl_buffer->in_length*sizeof(OTL_PositionRec)); + // #### check that passing "FALSE,FALSE" is correct + TT_GPOS_Apply_String(face, gpos, loadFlags, otl_buffer, FALSE, FALSE); +#ifdef TQ_WS_X11 + unlockFTFace(static_cast(fontEngine)->font()); +#endif + } + + // make sure we have enough space to write everything back + if (item->num_glyphs < (int)otl_buffer->in_length) { + item->num_glyphs = otl_buffer->in_length; + return FALSE; + } + + for (unsigned int i = 0; i < otl_buffer->in_length; ++i) { + item->glyphs[i] = otl_buffer->in_string[i].gindex; + item->attributes[i] = tmpAttributes[otl_buffer->in_string[i].cluster]; + if (i && otl_buffer->in_string[i].cluster == otl_buffer->in_string[i-1].cluster) + item->attributes[i].clusterStart = FALSE; + } + item->num_glyphs = otl_buffer->in_length; + + if (doLogClusters) { + // we can't do this for indic, as we pass the stuf in syllables and it's easier to do it in the shaper. + unsigned short *logClusters = item->log_clusters; + int clusterStart = 0; + int oldCi = 0; + for (unsigned int i = 0; i < otl_buffer->in_length; ++i) { + int ci = otl_buffer->in_string[i].cluster; + // tqDebug(" ci[%d] = %d mark=%d, cmb=%d, cs=%d", + // i, ci, glyphAttributes[i].mark, glyphAttributes[i].combiningClass, glyphAttributes[i].clusterStart); + if (!item->attributes[i].mark && item->attributes[i].clusterStart && ci != oldCi) { + for (int j = oldCi; j < ci; j++) + logClusters[j] = clusterStart; + clusterStart = i; + oldCi = ci; + } + } + for (int j = oldCi; j < length; j++) + logClusters[j] = clusterStart; + } + + // calulate the advances for the shaped glyphs +// tqDebug("unpositioned: "); + static_cast(item->font)->recalcAdvances(item->num_glyphs, item->glyphs, item->advances); + + // positioning code: + if (gpos) { + float scale = item->font->scale(); + OTL_Position positions = otl_buffer->positions; + +// tqDebug("positioned glyphs:"); + for (unsigned int i = 0; i < otl_buffer->in_length; i++) { +// tqDebug(" %d:\t orig advance: (%d/%d)\tadv=(%d/%d)\tpos=(%d/%d)\tback=%d\tnew_advance=%d", i, +// glyphs[i].advance.x.toInt(), glyphs[i].advance.y.toInt(), +// (int)(positions[i].x_advance >> 6), (int)(positions[i].y_advance >> 6), +// (int)(positions[i].x_pos >> 6), (int)(positions[i].y_pos >> 6), +// positions[i].back, positions[i].new_advance); + // ###### fix the case where we have y advances. How do we handle this in Uniscribe????? + if (positions[i].new_advance) { + item->advances[i] = item->flags & TQTextEngine::RightToLeft + ? -tqRound((positions[i].x_advance >> 6)*scale) + : tqRound((positions[i].x_advance >> 6)*scale); + } else { + item->advances[i] += item->flags & TQTextEngine::RightToLeft + ? -tqRound((positions[i].x_advance >> 6)*scale) + : tqRound((positions[i].x_advance >> 6)*scale); + } + item->offsets[i].x = tqRound((positions[i].x_pos >> 6)*scale); + item->offsets[i].y = -tqRound((positions[i].y_pos >> 6)*scale); + int back = positions[i].back; + if (item->flags & TQTextEngine::RightToLeft) { + while (back--) { + item->offsets[i].x -= item->advances[i-back]; + } + } else { + while (back) { + item->offsets[i].x -= item->advances[i-back]; + --back; + } + } +// tqDebug(" ->\tadv=%d\tpos=(%d/%d)", +// glyphs[i].advance.x.toInt(), glyphs[i].offset.x.toInt(), glyphs[i].offset.y.toInt()); + } + item->has_positioning = TRUE; + } else { + qt_heuristicPosition(item); + } + +#ifdef OT_DEBUG +// if (doLogClusters) { +// tqDebug("log clusters after shaping:"); +// for (int j = 0; j < length; j++) +// tqDebug(" log[%d] = %d", j, item->log_clusters[j]); +// } + tqDebug("final glyphs:"); + for (int i = 0; i < (int)otl_buffer->in_length; ++i) + tqDebug(" glyph=%4x char_index=%d mark: %d cmp: %d, clusterStart: %d advance=%d offset=%d/%d", + item->glyphs[i], otl_buffer->in_string[i].cluster, item->attributes[i].mark, + item->attributes[i].combiningClass, item->attributes[i].clusterStart, + item->advances[i], + item->offsets[i].x, item->offsets[i].y); + tqDebug("-----------------------------------------"); +#endif + return TRUE; +} + +#endif diff --git a/src/kernel/tqfontinfo.h b/src/kernel/tqfontinfo.h new file mode 100644 index 000000000..c02c01762 --- /dev/null +++ b/src/kernel/tqfontinfo.h @@ -0,0 +1,91 @@ +/**************************************************************************** +** +** Definition of TQFontInfo class +** +** Created : 950131 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef TQFONTINFO_H +#define TQFONTINFO_H + +#ifndef QT_H +#include "tqfont.h" +#endif // QT_H + + +class TQ_EXPORT TQFontInfo +{ +public: + TQFontInfo( const TQFont & ); + TQFontInfo( const TQFont &, TQFont::Script ); + TQFontInfo( const TQFontInfo & ); + ~TQFontInfo(); + + TQFontInfo &operator=( const TQFontInfo & ); + + TQString family() const; + int pixelSize() const; + int pointSize() const; + bool italic() const; + int weight() const; + bool bold() const; + bool underline() const; + bool overline() const; + bool strikeOut() const; + bool fixedPitch() const; + TQFont::StyleHint styleHint() const; + bool rawMode() const; + + bool exactMatch() const; + + +private: + TQFontInfo( const TQPainter * ); + + TQFontPrivate *d; + TQPainter *painter; + int fscript; + + friend class TQWidget; + friend class TQPainter; +}; + + +inline bool TQFontInfo::bold() const +{ return weight() > TQFont::Normal; } + + +#endif // TQFONTINFO_H diff --git a/src/kernel/tqfontmetrics.h b/src/kernel/tqfontmetrics.h new file mode 100644 index 000000000..814a411e6 --- /dev/null +++ b/src/kernel/tqfontmetrics.h @@ -0,0 +1,113 @@ +/**************************************************************************** +** +** Definition of TQFontMetrics class +** +** Created : 940514 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef TQFONTMETRICS_H +#define TQFONTMETRICS_H + +#ifndef QT_H +#include "tqfont.h" +#include "ntqrect.h" +#endif // QT_H + +class TQTextCodec; +class TQTextParag; + +class TQ_EXPORT TQFontMetrics +{ +public: + TQFontMetrics( const TQFont & ); + TQFontMetrics( const TQFont &, TQFont::Script ); + TQFontMetrics( const TQFontMetrics & ); + ~TQFontMetrics(); + + TQFontMetrics &operator=( const TQFontMetrics & ); + + int ascent() const; + int descent() const; + int height() const; + int leading() const; + int lineSpacing() const; + int minLeftBearing() const; + int minRightBearing() const; + int maxWidth() const; + + bool inFont(TQChar) const; + + int leftBearing(TQChar) const; + int rightBearing(TQChar) const; + int width( const TQString &, int len = -1 ) const; + + int width( TQChar ) const; +#ifndef TQT_NO_COMPAT + int width( char c ) const { return width( (TQChar) c ); } +#endif + + int charWidth( const TQString &str, int pos ) const; + TQRect boundingRect( const TQString &, int len = -1 ) const; + TQRect boundingRect( TQChar ) const; + TQRect boundingRect( int x, int y, int w, int h, int flags, + const TQString& str, int len=-1, int tabstops=0, + int *tabarray=0, TQTextParag **intern=0 ) const; + TQSize size( int flags, + const TQString& str, int len=-1, int tabstops=0, + int *tabarray=0, TQTextParag **intern=0 ) const; + + int underlinePos() const; + int overlinePos() const; + int strikeOutPos() const; + int lineWidth() const; + +private: + TQFontMetrics( const TQPainter * ); + + friend class TQWidget; + friend class TQPainter; + friend class TQTextFormat; +#if defined( TQ_WS_MAC ) + friend class TQFontPrivate; +#endif + + TQFontPrivate *d; + TQPainter *painter; + int fscript; +}; + + +#endif // TQFONTMETRICS_H diff --git a/src/kernel/tqiconset.cpp b/src/kernel/tqiconset.cpp index f3e8ac123..a327e554f 100644 --- a/src/kernel/tqiconset.cpp +++ b/src/kernel/tqiconset.cpp @@ -46,7 +46,7 @@ #include "tqbitmap.h" #include "ntqcleanuphandler.h" #include "tqimage.h" -#include "ntqpainter.h" +#include "tqpainter.h" enum { NumSizes = 2, NumModes = 3, NumStates = 2 }; diff --git a/src/kernel/tqimage.cpp b/src/kernel/tqimage.cpp index e7afa87f1..58b8a1221 100644 --- a/src/kernel/tqimage.cpp +++ b/src/kernel/tqimage.cpp @@ -96,7 +96,7 @@ An entry in the color table is an RGB triplet encoded as a \c uint. Use the \link ::tqRed() tqRed()\endlink, \link ::tqGreen() tqGreen()\endlink and \link ::tqBlue() tqBlue()\endlink functions (\c - ntqcolor.h) to access the components, and \link ::tqRgb() + tqcolor.h) to access the components, and \link ::tqRgb() tqRgb\endlink to make an RGB triplet (see the TQColor class documentation). @@ -823,7 +823,7 @@ TQImage TQImage::copy(int x, int y, int w, int h, int conversion_flags) const A color value is an RGB triplet. Use the \link ::tqRed() tqRed()\endlink, \link ::tqGreen() tqGreen()\endlink and \link - ::tqBlue() tqBlue()\endlink functions (defined in \c ntqcolor.h) to + ::tqBlue() tqBlue()\endlink functions (defined in \c tqcolor.h) to get the color value components. \sa setColor() numColors() TQColor @@ -835,7 +835,7 @@ TQImage TQImage::copy(int x, int y, int w, int h, int conversion_flags) const Sets a color in the color table at index \a i to \a c. A color value is an RGB triplet. Use the \link ::tqRgb() - tqRgb()\endlink function (defined in \c ntqcolor.h) to make RGB + tqRgb()\endlink function (defined in \c tqcolor.h) to make RGB triplets. \sa color() setNumColors() numColors() @@ -855,7 +855,7 @@ TQImage TQImage::copy(int x, int y, int w, int h, int conversion_flags) const directly, because the pixel format depends on the byte order on the underlying platform. Hint: use \link ::tqRed() tqRed()\endlink, \link ::tqGreen() tqGreen()\endlink and \link ::tqBlue() - tqBlue()\endlink, etc. (ntqcolor.h) to access the pixels. + tqBlue()\endlink, etc. (tqcolor.h) to access the pixels. \sa bytesPerLine() bits() jumpTable() */ @@ -2297,7 +2297,7 @@ TQImage TQImage::convertBitOrder( Endian bitOrder ) const return image; } -// ### Candidate (renamed) for ntqcolor.h +// ### Candidate (renamed) for tqcolor.h static bool isGray(TQRgb c) { diff --git a/src/kernel/tqmovie.cpp b/src/kernel/tqmovie.cpp new file mode 100644 index 000000000..d12ff2f6c --- /dev/null +++ b/src/kernel/tqmovie.cpp @@ -0,0 +1,1045 @@ +/**************************************************************************** +** +** Implementation of movie classes +** +** Created : 970617 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +// #define QT_SAVE_MOVIE_HACK + +#include "tqtimer.h" +#include "tqpainter.h" +#include "tqptrlist.h" +#include "tqbitmap.h" +#include "tqmovie.h" +#include "tqfile.h" +#include "tqbuffer.h" +#include "tqobject.h" +#include "ntqpixmapcache.h" + +#ifndef TQT_NO_MOVIE + +#include "ntqasyncio.h" +#include "ntqasyncimageio.h" + +#include + +/*! + \class TQMovie tqmovie.h + \brief The TQMovie class provides incremental loading of animations or images, signalling as it progresses. + + \ingroup images + \ingroup graphics + \ingroup multimedia + \mainclass + + The simplest way to display a TQMovie is to use a TQLabel and + TQLabel::setMovie(). + + A TQMovie provides a TQPixmap as the framePixmap(); connections can + be made via connectResize() and connectUpdate() to receive + notification of size and pixmap changes. All decoding is driven + by the normal event-processing mechanisms. + + The movie begins playing as soon as the TQMovie is created + (actually, once control returns to the event loop). When the last + frame in the movie has been played, it may loop back to the start + if such looping is defined in the input source. + + TQMovie objects are explicitly shared. This means that a TQMovie + copied from another TQMovie will be displaying the same frame at + all times. If one shared movie pauses, all pause. To make \e + independent movies, they must be constructed separately. + + The set of data formats supported by TQMovie is determined by the + decoder factories that have been installed; the format of the + input is determined as the input is decoded. + + The supported formats are MNG (if TQt is configured with MNG + support enabled) and GIF (if TQt is configured with GIF support + enabled, see ntqgif.h). + + If TQt is configured to support GIF reading, we are required to + state that "The Graphics Interchange Format(c) is the Copyright + property of CompuServe Incorporated. GIF(sm) is a Service Mark + property of CompuServe Incorporated. + + \warning If you are in a country that recognizes software patents + and in which Unisys holds a patent on LZW compression and/or + decompression and you want to use GIF, Unisys may require you to + license that technology. Such countries include Canada, Japan, + the USA, France, Germany, Italy and the UK. + + GIF support may be removed completely in a future version of TQt. + We recommend using the MNG or PNG format. + + \img tqmovie.png TQMovie + + \sa TQLabel::setMovie() +*/ + +/*! + \enum TQMovie::Status + + \value SourceEmpty + \value UnrecognizedFormat + \value Paused + \value EndOfFrame + \value EndOfLoop + \value EndOfMovie + \value SpeedChanged +*/ + +class TQMoviePrivate : public TQObject, public TQShared, + private TQDataSink, private TQImageConsumer +{ + TQ_OBJECT + +public: // for TQMovie + + // Creates a null Private + TQMoviePrivate(); + + // NOTE: The ownership of the TQDataSource is transferred to the Private + TQMoviePrivate(TQDataSource* src, TQMovie* movie, int bufsize); + + virtual ~TQMoviePrivate(); + + bool isNull() const; + + // Initialize, possibly to the null state + void init(bool fully); + void flushBuffer(); + void updatePixmapFromImage(); + void updatePixmapFromImage(const TQPoint& off, const TQRect& area); + void showChanges(); + + // This as TQImageConsumer + void changed(const TQRect& rect); + void end(); + void preFrameDone(); //util func + void frameDone(); + void frameDone(const TQPoint&, const TQRect& rect); + void restartTimer(); + void setLooping(int l); + void setFramePeriod(int milliseconds); + void setSize(int w, int h); + + // This as TQDataSink + int readyToReceive(); + void receive(const uchar* b, int bytecount); + void eof(); + void pause(); + +signals: + void sizeChanged(const TQSize&); + void areaChanged(const TQRect&); + void dataStatus(int); + +public slots: + void refresh(); + +public: + TQMovie *that; + TQWidget * display_widget; + + TQImageDecoder *decoder; + + // Cyclic buffer + int buf_size; + uchar *buffer; + int buf_r, buf_w, buf_usage; + + int framenumber; + int frameperiod; + int speed; + TQTimer *frametimer; + int lasttimerinterval; + int loop; + bool movie_ended; + bool dirty_cache; + bool waitingForFrameTick; + int stepping; + TQRect changed_area; + TQRect valid_area; + TQDataPump *pump; + TQDataSource *source; + TQPixmap mypixmap; + TQBitmap mymask; + TQColor bg; + + int error; + bool empty; + +#ifdef QT_SAVE_MOVIE_HACK + bool save_image; + int image_number; +#endif +}; + + +TQMoviePrivate::TQMoviePrivate() +{ + dirty_cache = FALSE; + buffer = 0; + pump = 0; + source = 0; + decoder = 0; + display_widget=0; + buf_size = 0; + init(FALSE); +} + +// NOTE: The ownership of the TQDataSource is transferred to the Private +TQMoviePrivate::TQMoviePrivate(TQDataSource* src, TQMovie* movie, int bufsize) : + that(movie), + buf_size(bufsize) +{ + frametimer = new TQTimer(this); + pump = src ? new TQDataPump(src, this) : 0; + TQObject::connect(frametimer, TQ_SIGNAL(timeout()), this, TQ_SLOT(refresh())); + dirty_cache = FALSE; + source = src; + buffer = 0; + decoder = 0; + speed = 100; + display_widget=0; + init(TRUE); +} + +TQMoviePrivate::~TQMoviePrivate() +{ + if ( buffer ) // Avoid purify complaint + delete [] buffer; + delete pump; + delete decoder; + delete source; + + // Too bad.. but better be safe than sorry + if ( dirty_cache ) + TQPixmapCache::clear(); +} + +bool TQMoviePrivate::isNull() const +{ + return !buf_size; +} + +// Initialize. Only actually allocate any space if \a fully is TRUE, +// otherwise, just enough to be a valid null Private. +void TQMoviePrivate::init(bool fully) +{ +#ifdef QT_SAVE_MOVIE_HACK + save_image = TRUE; + image_number = 0; +#endif + + buf_usage = buf_r = buf_w = 0; + if ( buffer ) // Avoid purify complaint + delete [] buffer; + buffer = fully ? new uchar[buf_size] : 0; + if ( buffer ) + memset( buffer, 0, buf_size ); + + delete decoder; + decoder = fully ? new TQImageDecoder(this) : 0; + +#ifdef AVOID_OPEN_FDS + if ( source && !source->isOpen() ) + source->open(IO_ReadOnly); +#endif + + waitingForFrameTick = FALSE; + stepping = -1; + framenumber = 0; + frameperiod = -1; + if (fully) frametimer->stop(); + lasttimerinterval = -1; + changed_area.setRect(0,0,-1,-1); + valid_area = changed_area; + loop = -1; + movie_ended = FALSE; + error = 0; + empty = TRUE; +} + +void TQMoviePrivate::flushBuffer() +{ + int used; + while (buf_usage && !waitingForFrameTick && stepping != 0 && !error) { + used = decoder->decode(buffer + buf_r, TQMIN(buf_usage, buf_size - buf_r)); + if (used <= 0) { + if ( used < 0 ) { + error = 1; + emit dataStatus(TQMovie::UnrecognizedFormat); + } + break; + } + buf_r = (buf_r + used) % buf_size; + buf_usage -= used; + } + + // Some formats, like MNG, can make stuff happen without any extra data. + // Only do this if the movie hasn't ended, however or we'll never get the end of loop signal. + if (!movie_ended) { + used = decoder->decode(buffer + buf_r, 0); + if (used <= 0) { + if ( used < 0 ) { + error = 1; + emit dataStatus(TQMovie::UnrecognizedFormat); + } + } + } + + if (error) + frametimer->stop(); + maybeReady(); +} + +void TQMoviePrivate::updatePixmapFromImage() +{ + if (changed_area.isEmpty()) return; + updatePixmapFromImage(TQPoint(0,0),changed_area); +} + +void TQMoviePrivate::updatePixmapFromImage(const TQPoint& off, + const TQRect& area) +{ + // Create temporary TQImage to hold the part we want + const TQImage& gimg = decoder->image(); + TQImage img = gimg.copy(area); + +#ifdef QT_SAVE_MOVIE_HACK + if ( save_image ) { + TQString name; + name.sprintf("movie%i.ppm",image_number++); + gimg.save( name, "PPM" ); + } +#endif + + // Resize to size of image + if (mypixmap.width() != gimg.width() || mypixmap.height() != gimg.height()) + mypixmap.resize(gimg.width(), gimg.height()); + + // Convert to pixmap and paste that onto myself + TQPixmap lines; + +#ifndef TQT_NO_SPRINTF + if (!(frameperiod < 0 && loop == -1)) { + // its an animation, lets see if we converted + // this frame already. + TQString key; + key.sprintf( "%08lx:%04d", ( long )this, framenumber ); + if ( !TQPixmapCache::find( key, lines ) ) { + lines.convertFromImage(img, TQt::ColorOnly); + TQPixmapCache::insert( key, lines ); + dirty_cache = TRUE; + } + } else +#endif + { + lines.convertFromImage(img, TQt::ColorOnly); + } + + if (bg.isValid()) { + TQPainter p; + p.begin(&mypixmap); + p.fillRect(area, bg); + p.drawPixmap(area, lines); + p.end(); + } else { + if (gimg.hasAlphaBuffer()) { + // Resize to size of image + if (mymask.isNull()) { + mymask.resize(gimg.width(), gimg.height()); + mymask.fill( TQt::color1 ); + } + } + mypixmap.setMask(TQBitmap()); // Remove reference to my mask + copyBlt( &mypixmap, area.left(), area.top(), + &lines, off.x(), off.y(), area.width(), area.height() ); + } +} + +void TQMoviePrivate::showChanges() +{ + if (changed_area.isValid()) { + updatePixmapFromImage(); + + valid_area = valid_area.unite(changed_area); + emit areaChanged(changed_area); + + changed_area.setWidth(-1); // make empty + } +} + +// Private as TQImageConsumer +void TQMoviePrivate::changed(const TQRect& rect) +{ + if (!frametimer->isActive()) + frametimer->start(0); + changed_area = changed_area.unite(rect); +} + +void TQMoviePrivate::end() +{ + movie_ended = TRUE; +} + +void TQMoviePrivate::preFrameDone() +{ + if (stepping > 0) { + stepping--; + if (!stepping) { + frametimer->stop(); + emit dataStatus( TQMovie::Paused ); + } + } else { + waitingForFrameTick = TRUE; + restartTimer(); + } +} +void TQMoviePrivate::frameDone() +{ + preFrameDone(); + showChanges(); + emit dataStatus(TQMovie::EndOfFrame); + framenumber++; +} +void TQMoviePrivate::frameDone(const TQPoint& p, + const TQRect& rect) +{ + preFrameDone(); + const TQImage& gimg = decoder->image(); + TQPoint point = p - gimg.offset(); + if (framenumber==0) + emit sizeChanged(gimg.size()); + valid_area = valid_area.unite(TQRect(point,rect.size())); + updatePixmapFromImage(point,rect); + emit areaChanged(TQRect(point,rect.size())); + emit dataStatus(TQMovie::EndOfFrame); + framenumber++; +} + +void TQMoviePrivate::restartTimer() +{ + if (speed > 0) { + int i = frameperiod >= 0 ? frameperiod * 100/speed : 0; + if ( i != lasttimerinterval || !frametimer->isActive() ) { + lasttimerinterval = i; + frametimer->start( i ); + } + } else { + frametimer->stop(); + } +} + +void TQMoviePrivate::setLooping(int nloops) +{ + if (loop == -1) { // Only if we don't already know how many loops! + if (source && source->rewindable()) { + source->enableRewind(TRUE); + loop = nloops; + } else { + // Cannot loop from this source + loop = -2; + } + } +} + +void TQMoviePrivate::setFramePeriod(int milliseconds) +{ + // Animation: only show complete frame + frameperiod = milliseconds; + if (stepping<0 && frameperiod >= 0) restartTimer(); +} + +void TQMoviePrivate::setSize(int w, int h) +{ + if (mypixmap.width() != w || mypixmap.height() != h) { + mypixmap.resize(w, h); + emit sizeChanged(TQSize(w, h)); + } +} + + +// Private as TQDataSink + +int TQMoviePrivate::readyToReceive() +{ + // Could pre-fill buffer, but more efficient to just leave the + // data back at the source. + return (waitingForFrameTick || !stepping || buf_usage || error) + ? 0 : buf_size; +} + +void TQMoviePrivate::receive(const uchar* b, int bytecount) +{ + if ( bytecount ) empty = FALSE; + + while (bytecount && !waitingForFrameTick && stepping != 0) { + int used = decoder->decode(b, bytecount); + if (used<=0) { + if ( used < 0 ) { + error = 1; + emit dataStatus(TQMovie::UnrecognizedFormat); + } + break; + } + b+=used; + bytecount-=used; + } + + // Append unused to buffer + while (bytecount--) { + buffer[buf_w] = *b++; + buf_w = (buf_w+1)%buf_size; + buf_usage++; + } +} + +void TQMoviePrivate::eof() +{ + if ( !movie_ended ) + return; + + if ( empty ) + emit dataStatus(TQMovie::SourceEmpty); + +#ifdef QT_SAVE_MOVIE_HACK + save_image = FALSE; +#endif + + emit dataStatus(TQMovie::EndOfLoop); + + if (loop >= 0) { + if (loop) { + loop--; + if (!loop) return; + } + delete decoder; + decoder = new TQImageDecoder(this); + source->rewind(); + framenumber = 0; + movie_ended = FALSE; + } else { + delete decoder; + decoder = 0; + if ( buffer ) // Avoid purify complaint + delete [] buffer; + buffer = 0; + emit dataStatus(TQMovie::EndOfMovie); +#ifdef AVOID_OPEN_FDS + if ( source ) + source->close(); +#endif + } +} + +void TQMoviePrivate::pause() +{ + if ( stepping ) { + stepping = 0; + frametimer->stop(); + emit dataStatus( TQMovie::Paused ); + } +} + +void TQMoviePrivate::refresh() +{ + if (!decoder) { + frametimer->stop(); + return; + } + + if (frameperiod < 0 && loop == -1) { + // Only show changes if probably not an animation + showChanges(); + } + + if (!buf_usage) { + frametimer->stop(); + } + + waitingForFrameTick = FALSE; + flushBuffer(); +} + +///////////////// End of Private ///////////////// + + + + + +/*! + Constructs a null TQMovie. The only interesting thing to do with + such a movie is to assign another movie to it. + + \sa isNull() +*/ +TQMovie::TQMovie() +{ + d = new TQMoviePrivate(); +} + +/*! + Constructs a TQMovie with an external data source. You should later + call pushData() to send incoming animation data to the movie. + + The \a bufsize argument sets the maximum amount of data the movie + will transfer from the data source per event loop. The lower this + value, the better interleaved the movie playback will be with + other event processing, but the slower the overall processing will + be. + + \sa pushData() +*/ +TQMovie::TQMovie(int bufsize) +{ + d = new TQMoviePrivate(0, this, bufsize); +} + +/*! + Returns the maximum amount of data that can currently be pushed + into the movie by a call to pushData(). This is affected by the + initial buffer size, but varies as the movie plays and data is + consumed. +*/ +int TQMovie::pushSpace() const +{ + return d->readyToReceive(); +} + +/*! + Pushes \a length bytes from \a data into the movie. \a length must + be no more than the amount returned by pushSpace() since the + previous call to pushData(). +*/ +void TQMovie::pushData(const uchar* data, int length) +{ + d->receive(data,length); +} + +/*! + Constructs a TQMovie that reads an image sequence from the given + data source, \a src. The source must be allocated dynamically, + because TQMovie will take ownership of it and will destroy it when + the movie is destroyed. The movie starts playing as soon as event + processing continues. + + The \a bufsize argument sets the maximum amount of data the movie + will transfer from the data source per event loop. The lower this + value, the better interleaved the movie playback will be with + other event processing, but the slower the overall processing will + be. +*/ +TQMovie::TQMovie(TQDataSource* src, int bufsize) +{ + d = new TQMoviePrivate(src, this, bufsize); +} + +/*! + Constructs a TQMovie that reads an image sequence from the file, \a + fileName. + + The \a bufsize argument sets the maximum amount of data the movie + will transfer from the data source per event loop. The lower this + value, the better interleaved the movie playback will be with + other event processing, but the slower the overall processing will + be. +*/ +TQMovie::TQMovie(const TQString &fileName, int bufsize) +{ + TQFile* file = new TQFile(fileName); + if ( !fileName.isEmpty() ) + file->open(IO_ReadOnly); + d = new TQMoviePrivate(new TQIODeviceSource(file, bufsize), this, bufsize); +} + +/*! + Constructs a TQMovie that reads an image sequence from the byte + array, \a data. + + The \a bufsize argument sets the maximum amount of data the movie + will transfer from the data source per event loop. The lower this + value, the better interleaved the movie playback will be with + other event processing, but the slower the overall processing will + be. +*/ +TQMovie::TQMovie(TQByteArray data, int bufsize) +{ + TQBuffer* buffer = new TQBuffer(data); + buffer->open(IO_ReadOnly); + d = new TQMoviePrivate(new TQIODeviceSource(buffer, bufsize), this, bufsize); +} + +/*! + Constructs a movie that uses the same data as movie \a movie. + TQMovies use explicit sharing, so operations on the copy will + affect both. +*/ +TQMovie::TQMovie(const TQMovie& movie) +{ + d = movie.d; + d->ref(); +} + +/*! + Destroys the TQMovie. If this is the last reference to the data of + the movie, the data is deallocated. +*/ +TQMovie::~TQMovie() +{ + if (d->deref()) delete d; +} + +/*! + Returns TRUE if the movie is null; otherwise returns FALSE. +*/ +bool TQMovie::isNull() const +{ + return d->isNull(); +} + +/*! + Makes this movie use the same data as movie \a movie. TQMovies use + explicit sharing. +*/ +TQMovie& TQMovie::operator=(const TQMovie& movie) +{ + movie.d->ref(); + if (d->deref()) delete d; + d = movie.d; + return *this; +} + + +/*! + Sets the background color of the pixmap to \a c. If the background + color isValid(), the pixmap will never have a mask because the + background color will be used in transparent regions of the image. + + \sa backgroundColor() +*/ +void TQMovie::setBackgroundColor(const TQColor& c) +{ + d->bg = c; +} + +/*! + Returns the background color of the movie set by + setBackgroundColor(). +*/ +const TQColor& TQMovie::backgroundColor() const +{ + return d->bg; +} + +/*! + Returns the area of the pixmap for which pixels have been + generated. +*/ +const TQRect& TQMovie::getValidRect() const +{ + return d->valid_area; +} + +/*! + Returns the current frame of the movie, as a TQPixmap. It is not + generally useful to keep a copy of this pixmap. It is better to + keep a copy of the TQMovie and get the framePixmap() only when + needed for drawing. + + \sa frameImage() +*/ +const TQPixmap& TQMovie::framePixmap() const +{ + return d->mypixmap; +} + +/*! + Returns the current frame of the movie, as a TQImage. It is not + generally useful to keep a copy of this image. Also note that you + must not call this function if the movie is finished(), since by + then the image will not be available. + + \sa framePixmap() +*/ +const TQImage& TQMovie::frameImage() const +{ + return d->decoder->image(); +} + +/*! + Returns the number of steps remaining after a call to step(). If + the movie is paused, steps() returns 0. If it's running normally + or is finished, steps() returns a negative number. +*/ +int TQMovie::steps() const +{ + return d->stepping; +} + +/*! + Returns the number of times EndOfFrame has been emitted since the + start of the current loop of the movie. Thus, before any + EndOfFrame has been emitted the value will be 0; within slots + processing the first signal, frameNumber() will be 1, and so on. +*/ +int TQMovie::frameNumber() const { return d->framenumber; } + +/*! + Returns TRUE if the image is paused; otherwise returns FALSE. +*/ +bool TQMovie::paused() const +{ + return d->stepping == 0; +} + +/*! + Returns TRUE if the image is no longer playing: this happens when + all loops of all frames are complete; otherwise returns FALSE. +*/ +bool TQMovie::finished() const +{ + return !d->decoder; +} + +/*! + Returns TRUE if the image is not single-stepping, not paused, and + not finished; otherwise returns FALSE. +*/ +bool TQMovie::running() const +{ + return d->stepping<0 && d->decoder; +} + +/*! + Pauses the progress of the animation. + + \sa unpause() +*/ +void TQMovie::pause() +{ + d->pause(); +} + +/*! + Unpauses the progress of the animation. + + \sa pause() +*/ +void TQMovie::unpause() +{ + if ( d->stepping >= 0 ) { + if (d->isNull()) + return; + d->stepping = -1; + d->restartTimer(); + } +} + +/*! + \overload + + Steps forward, showing \a steps frames, and then pauses. +*/ +void TQMovie::step(int steps) +{ + if (d->isNull()) + return; + d->stepping = steps; + d->frametimer->start(0); + d->waitingForFrameTick = FALSE; // Full speed ahead! +} + +/*! + Steps forward 1 frame and then pauses. +*/ +void TQMovie::step() +{ + step(1); +} + +/*! + Rewinds the movie to the beginning. If the movie has not been + paused, it begins playing again. +*/ +void TQMovie::restart() +{ + if (d->isNull()) + return; + if (d->source->rewindable()) { + d->source->enableRewind(TRUE); + d->source->rewind(); + int s = d->stepping; + d->init(TRUE); + if ( s>0 ) + step(s); + else if ( s==0 ) + pause(); + } +} + +/*! + Returns the movie's play speed as a percentage. The default is 100 + percent. + + \sa setSpeed() +*/ +int TQMovie::speed() const +{ + return d->speed; +} + +/*! + Sets the movie's play speed as a percentage, to \a percent. This + is a percentage of the speed dictated by the input data format. + The default is 100 percent. +*/ +void TQMovie::setSpeed(int percent) +{ + int oldspeed = d->speed; + if ( oldspeed != percent && percent >= 0 ) { + d->speed = percent; + // Restart timer only if really needed + if (d->stepping < 0) { + if ( !percent || !oldspeed // To or from zero + || oldspeed*4 / percent > 4 // More than 20% slower + || percent*4 / oldspeed > 4 // More than 20% faster + ) + d->restartTimer(); + } + } +} + +/*! + Connects the \a{receiver}'s \a member of type \c{void member(const + TQSize&)} so that it is signalled when the movie changes size. + + Note that due to the explicit sharing of TQMovie objects, these + connections persist until they are explicitly disconnected with + disconnectResize() or until \e every shared copy of the movie is + deleted. +*/ +void TQMovie::connectResize(TQObject* receiver, const char *member) +{ + TQObject::connect(d, TQ_SIGNAL(sizeChanged(const TQSize&)), receiver, member); +} + +/*! + Disconnects the \a{receiver}'s \a member (or all members if \a + member is zero) that were previously connected by connectResize(). +*/ +void TQMovie::disconnectResize(TQObject* receiver, const char *member) +{ + TQObject::disconnect(d, TQ_SIGNAL(sizeChanged(const TQSize&)), receiver, member); +} + +/*! + Connects the \a{receiver}'s \a member of type \c{void member(const + TQRect&)} so that it is signalled when an area of the framePixmap() + has changed since the previous frame. + + Note that due to the explicit sharing of TQMovie objects, these + connections persist until they are explicitly disconnected with + disconnectUpdate() or until \e every shared copy of the movie is + deleted. +*/ +void TQMovie::connectUpdate(TQObject* receiver, const char *member) +{ + TQObject::connect(d, TQ_SIGNAL(areaChanged(const TQRect&)), receiver, member); +} + +/*! + Disconnects the \a{receiver}'s \a member (or all members if \q + member is zero) that were previously connected by connectUpdate(). +*/ +void TQMovie::disconnectUpdate(TQObject* receiver, const char *member) +{ + TQObject::disconnect(d, TQ_SIGNAL(areaChanged(const TQRect&)), receiver, member); +} + +/*! + Connects the \a{receiver}'s \a member, of type \c{void + member(int)} so that it is signalled when the movie changes + status. The status codes are negative for errors and positive for + information. + + \table + \header \i Status Code \i Meaning + \row \i TQMovie::SourceEmpty + \i signalled if the input cannot be read. + \row \i TQMovie::UnrecognizedFormat + \i signalled if the input data is unrecognized. + \row \i TQMovie::Paused + \i signalled when the movie is paused by a call to paused() + or by after \link step() stepping \endlink pauses. + \row \i TQMovie::EndOfFrame + \i signalled at end-of-frame after any update and Paused signals. + \row \i TQMovie::EndOfLoop + \i signalled at end-of-loop, after any update signals, + EndOfFrame - but before EndOfMovie. + \row \i TQMovie::EndOfMovie + \i signalled when the movie completes and is not about to loop. + \endtable + + More status messages may be added in the future, so a general test + for errors would test for negative. + + Note that due to the explicit sharing of TQMovie objects, these + connections persist until they are explicitly disconnected with + disconnectStatus() or until \e every shared copy of the movie is + deleted. +*/ +void TQMovie::connectStatus(TQObject* receiver, const char *member) +{ + TQObject::connect(d, TQ_SIGNAL(dataStatus(int)), receiver, member); +} + +/*! + Disconnects the \a{receiver}'s \a member (or all members if \a + member is zero) that were previously connected by connectStatus(). +*/ +void TQMovie::disconnectStatus(TQObject* receiver, const char *member) +{ + TQObject::disconnect(d, TQ_SIGNAL(dataStatus(int)), receiver, member); +} + + +#include "tqmovie.moc" + +#endif // TQT_NO_MOVIE diff --git a/src/kernel/tqmovie.h b/src/kernel/tqmovie.h new file mode 100644 index 000000000..8e92ec6d4 --- /dev/null +++ b/src/kernel/tqmovie.h @@ -0,0 +1,115 @@ +/**************************************************************************** +** +** Definition of movie classes +** +** Created : 970617 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef TQMOVIE_H +#define TQMOVIE_H + +#ifndef QT_H +#include "ntqpixmap.h" // ### remove or keep for users' convenience? +#endif // QT_H + +#ifndef TQT_NO_MOVIE + +class TQDataSource; +class TQObject; +class TQMoviePrivate; + +class TQ_EXPORT TQMovie { +public: + TQMovie(); + TQMovie(int bufsize); + TQMovie(TQDataSource*, int bufsize=1024); + TQMovie(const TQString &fileName, int bufsize=1024); + TQMovie(TQByteArray data, int bufsize=1024); + TQMovie(const TQMovie&); + ~TQMovie(); + + TQMovie& operator=(const TQMovie&); + + int pushSpace() const; + void pushData(const uchar* data, int length); + + const TQColor& backgroundColor() const; + void setBackgroundColor(const TQColor&); + + const TQRect& getValidRect() const; + const TQPixmap& framePixmap() const; + const TQImage& frameImage() const; + + bool isNull() const; + + int frameNumber() const; + int steps() const; + bool paused() const; + bool finished() const; + bool running() const; + + void unpause(); + void pause(); + void step(); + void step(int); + void restart(); + + int speed() const; + void setSpeed(int); + + void connectResize(TQObject* receiver, const char *member); + void disconnectResize(TQObject* receiver, const char *member=0); + + void connectUpdate(TQObject* receiver, const char *member); + void disconnectUpdate(TQObject* receiver, const char *member=0); + + enum Status { SourceEmpty=-2, + UnrecognizedFormat=-1, + Paused=1, + EndOfFrame=2, + EndOfLoop=3, + EndOfMovie=4, + SpeedChanged=5 }; + void connectStatus(TQObject* receiver, const char *member); + void disconnectStatus(TQObject* receiver, const char *member=0); + +private: + TQMoviePrivate *d; +}; + +#endif // TQT_NO_MOVIE + +#endif diff --git a/src/kernel/tqpaintdevice.h b/src/kernel/tqpaintdevice.h new file mode 100644 index 000000000..2b9cd421f --- /dev/null +++ b/src/kernel/tqpaintdevice.h @@ -0,0 +1,407 @@ +/**************************************************************************** +** +** Definition of TQPaintDevice class +** +** Created : 940721 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef TQPAINTDEVICE_H +#define TQPAINTDEVICE_H + +#ifndef QT_H +#include "ntqwindowdefs.h" +#include "ntqrect.h" +#endif // QT_H + +class TQIODevice; +class TQString; +class TQTextItem; + + +#if defined(TQ_WS_X11) +struct TQPaintDeviceX11Data; +#endif + +union TQPDevCmdParam { + int ival; + int *ivec; + TQString *str; + const TQPoint *point; + const TQRect *rect; + const TQPointArray *ptarr; + const TQPixmap *pixmap; + const TQImage *image; + const TQColor *color; + const TQFont *font; + const TQPen *pen; + const TQBrush *brush; + const TQRegion *rgn; + const TQWMatrix *matrix; + const TQTextItem *textItem; + TQIODevice *device; +}; + + + +class TQ_EXPORT TQPaintDevice // device for TQPainter +{ +public: + virtual ~TQPaintDevice(); + + int devType() const; + bool isExtDev() const; + bool paintingActive() const; + + virtual void setResolution( int ); + virtual int resolution() const; + + // Windows: get device context + // X-Windows: get drawable +#if defined(TQ_WS_WIN) + virtual HDC handle() const; +#elif defined(TQ_WS_X11) + virtual TQt::HANDLE handle() const; + virtual TQt::HANDLE x11RenderHandle() const; +#elif defined(TQ_WS_MAC) + virtual TQt::HANDLE handle() const; +#endif + +#if defined(TQ_WS_X11) + Display *x11Display() const; + int x11Screen() const; + int x11Depth() const; + int x11Cells() const; + TQt::HANDLE x11Colormap() const; + bool x11DefaultColormap() const; + void *x11Visual() const; + bool x11DefaultVisual() const; + + static Display *x11AppDisplay(); + static int x11AppScreen(); + + static int x11AppDpiX(); + static int x11AppDpiY(); + static void x11SetAppDpiX(int); + static void x11SetAppDpiY(int); + static int x11AppDepth(); + static int x11AppCells(); + static TQt::HANDLE x11AppRootWindow(); + static TQt::HANDLE x11AppColormap(); + static bool x11AppDefaultColormap(); + static void *x11AppVisual(); + static bool x11AppDefaultVisual(); + + // ### in 4.0, the above need to go away, the below needs to take a -1 default + // argument, signifying the default screen... + static int x11AppDepth( int screen ); + static int x11AppCells( int screen ); + static TQt::HANDLE x11AppRootWindow( int screen ); + static TQt::HANDLE x11AppColormap( int screen ); + static void *x11AppVisual( int screen ); + static bool x11AppDefaultColormap( int screen ); + static bool x11AppDefaultVisual( int screen ); + static int x11AppDpiX( int ); + static int x11AppDpiY( int ); + static void x11SetAppDpiX( int, int ); + static void x11SetAppDpiY( int, int ); +#endif + + enum PDevCmd { + PdcNOP = 0, // + PdcDrawPoint = 1, // point + PdcDrawFirst = PdcDrawPoint, + PdcMoveTo = 2, // point + PdcLineTo = 3, // point + PdcDrawLine = 4, // point,point + PdcDrawRect = 5, // rect + PdcDrawRoundRect = 6, // rect,ival,ival + PdcDrawEllipse = 7, // rect + PdcDrawArc = 8, // rect,ival,ival + PdcDrawPie = 9, // rect,ival,ival + PdcDrawChord = 10, // rect,ival,ival + PdcDrawLineSegments = 11, // ptarr + PdcDrawPolyline = 12, // ptarr + PdcDrawPolygon = 13, // ptarr,ival + PdcDrawCubicBezier = 14, // ptarr + PdcDrawText = 15, // point,str + PdcDrawTextFormatted = 16, // rect,ival,str + PdcDrawPixmap = 17, // rect,pixmap + PdcDrawImage = 18, // rect,image + PdcDrawText2 = 19, // point,str + PdcDrawText2Formatted = 20, // rect,ival,str + PdcDrawTextItem = 21, + PdcDrawLast = PdcDrawTextItem, + + // no painting commands below PdcDrawLast. + + PdcBegin = 30, // + PdcEnd = 31, // + PdcSave = 32, // + PdcRestore = 33, // + PdcSetdev = 34, // device - PRIVATE + PdcSetBkColor = 40, // color + PdcSetBkMode = 41, // ival + PdcSetROP = 42, // ival + PdcSetBrushOrigin = 43, // point + PdcSetFont = 45, // font + PdcSetPen = 46, // pen + PdcSetBrush = 47, // brush + PdcSetTabStops = 48, // ival + PdcSetTabArray = 49, // ival,ivec + PdcSetUnit = 50, // ival + PdcSetVXform = 51, // ival + PdcSetWindow = 52, // rect + PdcSetViewport = 53, // rect + PdcSetWXform = 54, // ival + PdcSetWMatrix = 55, // matrix,ival + PdcSaveWMatrix = 56, + PdcRestoreWMatrix = 57, + PdcSetClip = 60, // ival + PdcSetClipRegion = 61, // rgn,cmode + PdcFlush = 62, // + PdcFlushRegion = 63, // rgn,cmode + + PdcReservedStart = 0, // codes 0-199 are reserved + PdcReservedStop = 199 // for TQt + }; + +protected: + TQPaintDevice( uint devflags ); + +#if defined(TQ_WS_WIN) + HDC hdc; // device context +#elif defined(TQ_WS_X11) + TQt::HANDLE hd; // handle to drawable + TQt::HANDLE rendhd; // handle to RENDER pict + + void copyX11Data( const TQPaintDevice * ); + void cloneX11Data( const TQPaintDevice * ); + virtual void setX11Data( const TQPaintDeviceX11Data* ); + TQPaintDeviceX11Data* getX11Data( bool def=FALSE ) const; +#elif defined(TQ_WS_MAC) +#if !defined( TQMAC_NO_QUARTZ ) + CGContextRef ctx; +#endif + void * hd; +#endif + + virtual bool cmd( int, TQPainter *, TQPDevCmdParam * ); + virtual int metric( int ) const; + virtual int fontMet( TQFont *, int, const char * = 0, int = 0 ) const; + virtual int fontInf( TQFont *, int ) const; + + ushort devFlags; // device flags + ushort painters; // refcount + + friend class TQPainter; + friend class TQPaintDeviceMetrics; +#if defined(TQ_WS_MAC) +#ifndef TQMAC_NO_QUARTZ + virtual CGContextRef macCGContext(bool clipped=TRUE) const; +#endif + friend TQ_EXPORT void unclippedScaledBitBlt( TQPaintDevice *, int, int, int, int, + const TQPaintDevice *, int, int, int, int, TQt::RasterOp, bool, bool ); +#else + friend TQ_EXPORT void bitBlt( TQPaintDevice *, int, int, + const TQPaintDevice *, + int, int, int, int, TQt::RasterOp, bool ); +#endif +#if defined(TQ_WS_X11) + friend void tqt_init_internal( int *, char **, Display *, TQt::HANDLE, TQt::HANDLE ); + friend void tqt_cleanup(); +#endif + +private: +#if defined(TQ_WS_X11) + static Display *x_appdisplay; + static int x_appscreen; + + static int x_appdepth; + static int x_appcells; + static TQt::HANDLE x_approotwindow; + static TQt::HANDLE x_appcolormap; + static bool x_appdefcolormap; + static void *x_appvisual; + static bool x_appdefvisual; + + // ### in 4.0, remove the above, and replace with the below + static int *x_appdepth_arr; + static int *x_appcells_arr; + static TQt::HANDLE *x_approotwindow_arr; + static TQt::HANDLE *x_appcolormap_arr; + static bool *x_appdefcolormap_arr; + static void **x_appvisual_arr; + static bool *x_appdefvisual_arr; + + TQPaintDeviceX11Data* x11Data; +#endif + +private: // Disabled copy constructor and operator= +#if defined(TQ_DISABLE_COPY) + TQPaintDevice( const TQPaintDevice & ); + TQPaintDevice &operator=( const TQPaintDevice & ); +#endif +}; + + +TQ_EXPORT +void bitBlt( TQPaintDevice *dst, int dx, int dy, + const TQPaintDevice *src, int sx=0, int sy=0, int sw=-1, int sh=-1, + TQt::RasterOp = TQt::CopyROP, bool ignoreMask=FALSE ); + +TQ_EXPORT +void bitBlt( TQPaintDevice *dst, int dx, int dy, + const TQImage *src, int sx=0, int sy=0, int sw=-1, int sh=-1, + int conversion_flags=0 ); + + +#if defined(TQ_WS_X11) + +struct TQ_EXPORT TQPaintDeviceX11Data : public TQShared { + Display* x_display; + int x_screen; + int x_depth; + int x_cells; + TQt::HANDLE x_colormap; + bool x_defcolormap; + void* x_visual; + bool x_defvisual; +}; + +#endif + +/***************************************************************************** + Inline functions + *****************************************************************************/ + +inline int TQPaintDevice::devType() const +{ return devFlags & TQInternal::DeviceTypeMask; } + +inline bool TQPaintDevice::isExtDev() const +{ return (devFlags & TQInternal::ExternalDevice) != 0; } + +inline bool TQPaintDevice::paintingActive() const +{ return painters != 0; } + +#if defined(TQ_WS_X11) +inline Display *TQPaintDevice::x11Display() const +{ return x11Data ? x11Data->x_display : x_appdisplay; } + +inline int TQPaintDevice::x11Screen() const +{ return x11Data ? x11Data->x_screen : x_appscreen; } + +inline int TQPaintDevice::x11Depth() const +{ return x11Data ? x11Data->x_depth : x_appdepth; } + +inline int TQPaintDevice::x11Cells() const +{ return x11Data ? x11Data->x_cells : x_appcells; } + +inline TQt::HANDLE TQPaintDevice::x11Colormap() const +{ return x11Data ? x11Data->x_colormap : x_appcolormap; } + +inline bool TQPaintDevice::x11DefaultColormap() const +{ return x11Data ? x11Data->x_defcolormap : x_appdefcolormap; } + +inline void *TQPaintDevice::x11Visual() const +{ return x11Data ? x11Data->x_visual : x_appvisual; } + +inline bool TQPaintDevice::x11DefaultVisual() const +{ return x11Data ? x11Data->x_defvisual : x_appdefvisual; } + +inline Display *TQPaintDevice::x11AppDisplay() +{ return x_appdisplay; } + +inline int TQPaintDevice::x11AppScreen() +{ return x_appscreen; } + +inline int TQPaintDevice::x11AppDepth( int screen ) +{ return x_appdepth_arr[ screen == -1 ? x_appscreen : screen ]; } + +inline int TQPaintDevice::x11AppCells( int screen ) +{ return x_appcells_arr[ screen == -1 ? x_appscreen : screen ]; } + +inline TQt::HANDLE TQPaintDevice::x11AppRootWindow( int screen ) +{ return x_approotwindow_arr[ screen == -1 ? x_appscreen : screen ]; } + +inline TQt::HANDLE TQPaintDevice::x11AppColormap( int screen ) +{ return x_appcolormap_arr[ screen == -1 ? x_appscreen : screen ]; } + +inline bool TQPaintDevice::x11AppDefaultColormap( int screen ) +{ return x_appdefcolormap_arr[ screen == -1 ? x_appscreen : screen ]; } + +inline void *TQPaintDevice::x11AppVisual( int screen ) +{ return x_appvisual_arr[ screen == -1 ? x_appscreen : screen ]; } + +inline bool TQPaintDevice::x11AppDefaultVisual( int screen ) +{ return x_appdefvisual_arr[ screen == -1 ? x_appscreen : screen ]; } + +inline int TQPaintDevice::x11AppDepth() +{ return x_appdepth; } + +inline int TQPaintDevice::x11AppCells() +{ return x_appcells; } + +inline TQt::HANDLE TQPaintDevice::x11AppRootWindow() +{ return x_approotwindow; } + +inline TQt::HANDLE TQPaintDevice::x11AppColormap() +{ return x_appcolormap; } + +inline bool TQPaintDevice::x11AppDefaultColormap() +{ return x_appdefcolormap; } + +inline void *TQPaintDevice::x11AppVisual() +{ return x_appvisual; } + +inline bool TQPaintDevice::x11AppDefaultVisual() +{ return x_appdefvisual; } + +#endif // TQ_WS_X11 + + +TQ_EXPORT +inline void bitBlt( TQPaintDevice *dst, const TQPoint &dp, + const TQPaintDevice *src, const TQRect &sr =TQRect(0,0,-1,-1), + TQt::RasterOp rop=TQt::CopyROP, bool ignoreMask=FALSE ) +{ + bitBlt( dst, dp.x(), dp.y(), src, sr.x(), sr.y(), sr.width(), sr.height(), + rop, ignoreMask ); +} + + + + +#endif // TQPAINTDEVICE_H diff --git a/src/kernel/tqpaintdevice_x11.cpp b/src/kernel/tqpaintdevice_x11.cpp new file mode 100644 index 000000000..7bfbdf239 --- /dev/null +++ b/src/kernel/tqpaintdevice_x11.cpp @@ -0,0 +1,1173 @@ +/**************************************************************************** +** +** Implementation of TQPaintDevice class for X11 +** +** Created : 940721 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#include "tqpaintdevice.h" +#include "tqpaintdevicemetrics.h" +#include "tqpainter.h" +#include "tqwidget.h" +#include "tqbitmap.h" +#include "ntqapplication.h" +#include "qt_x11_p.h" + + +/*! + \class TQPaintDevice tqpaintdevice.h + \brief The TQPaintDevice class is the base class of objects that + can be painted. + + \ingroup graphics + \ingroup images + + A paint device is an abstraction of a two-dimensional space that + can be drawn using a TQPainter. The drawing capabilities are + implemented by the subclasses TQWidget, TQPixmap, TQPicture and + TQPrinter. + + The default coordinate system of a paint device has its origin + located at the top-left position. X increases to the right and Y + increases downward. The unit is one pixel. There are several ways + to set up a user-defined coordinate system using the painter, for + example, using TQPainter::setWorldMatrix(). + + Example (draw on a paint device): + \code + void MyWidget::paintEvent( TQPaintEvent * ) + { + TQPainter p; // our painter + p.begin( this ); // start painting the widget + p.setPen( red ); // red outline + p.setBrush( yellow ); // yellow fill + p.drawEllipse( 10, 20, 100,100 ); // 100x100 ellipse at position (10, 20) + p.end(); // painting done + } + \endcode + + The bit block transfer is an extremely useful operation for + copying pixels from one paint device to another (or to itself). It + is implemented as the global function bitBlt(). + + Example (scroll widget contents 10 pixels to the right): + \code + bitBlt( myWidget, 10, 0, myWidget ); + \endcode + + \warning TQt requires that a TQApplication object exists before + any paint devices can be created. Paint devices access window + system resources, and these resources are not initialized before + an application object is created. +*/ + + +// +// Some global variables - these are initialized by TQColor::initialize() +// + +Display *TQPaintDevice::x_appdisplay = 0; +int TQPaintDevice::x_appscreen; + +int TQPaintDevice::x_appdepth; +int TQPaintDevice::x_appcells; +TQt::HANDLE TQPaintDevice::x_approotwindow; +TQt::HANDLE TQPaintDevice::x_appcolormap; +bool TQPaintDevice::x_appdefcolormap; +void *TQPaintDevice::x_appvisual; +bool TQPaintDevice::x_appdefvisual; + +// ### in 4.0, remove the above, and use the below +int *TQPaintDevice::x_appdepth_arr; +int *TQPaintDevice::x_appcells_arr; +TQt::HANDLE *TQPaintDevice::x_approotwindow_arr; +TQt::HANDLE *TQPaintDevice::x_appcolormap_arr; +bool *TQPaintDevice::x_appdefcolormap_arr; +void **TQPaintDevice::x_appvisual_arr; +bool *TQPaintDevice::x_appdefvisual_arr; + +/*! + \enum TQPaintDevice::PDevCmd + \internal +*/ + +/*! + Constructs a paint device with internal flags \a devflags. This + constructor can be invoked only from TQPaintDevice subclasses. +*/ + +TQPaintDevice::TQPaintDevice( uint devflags ) +{ + if ( !tqApp ) { // global constructor +#if defined(QT_CHECK_STATE) + tqFatal( "TQPaintDevice: Must construct a TQApplication before a " + "TQPaintDevice" ); +#endif + return; + } + devFlags = devflags; + painters = 0; + hd = 0; + rendhd = 0; + x11Data = 0; +} + +/*! + Destroys the paint device and frees window system resources. +*/ + +TQPaintDevice::~TQPaintDevice() +{ +#if defined(QT_CHECK_STATE) + if ( paintingActive() ) + tqWarning( "TQPaintDevice: Cannot destroy paint device that is being " + "painted" ); +#endif + if ( x11Data && x11Data->deref() ) { + delete x11Data; + x11Data = 0; + } +} + + +/* + \internal + Makes a shallow copy of the X11-specific data of \a fromDevice, if it is not + null. Otherwise this function sets it to null. +*/ + +void TQPaintDevice::copyX11Data( const TQPaintDevice *fromDevice ) +{ + setX11Data( fromDevice ? fromDevice->x11Data : 0 ); +} + +/* + \internal + Makes a deep copy of the X11-specific data of \a fromDevice, if it is not + null. Otherwise this function sets it to null. +*/ + +void TQPaintDevice::cloneX11Data( const TQPaintDevice *fromDevice ) +{ + if ( fromDevice && fromDevice->x11Data ) { + TQPaintDeviceX11Data *d = new TQPaintDeviceX11Data; + *d = *fromDevice->x11Data; + d->count = 0; + setX11Data( d ); + } else { + setX11Data( 0 ); + } +} + +/* + \internal + Makes a shallow copy of the X11-specific data \a d and assigns it to this + class. This function increments the reference code of \a d. +*/ + +void TQPaintDevice::setX11Data( const TQPaintDeviceX11Data* d ) +{ + if ( x11Data && x11Data->deref() ) + delete x11Data; + x11Data = (TQPaintDeviceX11Data*)d; + if ( x11Data ) + x11Data->ref(); +} + + +/* + \internal + If \a def is FALSE, returns a deep copy of the x11Data, or 0 if x11Data is 0. + If \a def is TRUE, makes a TQPaintDeviceX11Data struct filled with the default + values. + + In either case the caller is responsible for deleting the returned + struct. But notice that the struct is a shared class, so other + classes might also have a reference to it. The reference count of + the returned TQPaintDeviceX11Data* is 0. +*/ + +TQPaintDeviceX11Data* TQPaintDevice::getX11Data( bool def ) const +{ + TQPaintDeviceX11Data* res = 0; + if ( def ) { + res = new TQPaintDeviceX11Data; + res->x_display = x11AppDisplay(); + res->x_screen = x11AppScreen(); + res->x_depth = x11AppDepth(); + res->x_cells = x11AppCells(); + res->x_colormap = x11Colormap(); + res->x_defcolormap = x11AppDefaultColormap(); + res->x_visual = x11AppVisual(); + res->x_defvisual = x11AppDefaultVisual(); + res->deref(); + } else if ( x11Data ) { + res = new TQPaintDeviceX11Data; + *res = *x11Data; + res->count = 0; + } + return res; +} + + +/*! + \fn int TQPaintDevice::devType() const + + \internal + + Returns the device type identifier, which is \c TQInternal::Widget + if the device is a TQWidget, \c TQInternal::Pixmap if it's a + TQPixmap, \c TQInternal::Printer if it's a TQPrinter, \c + TQInternal::Picture if it's a TQPicture or \c + TQInternal::UndefinedDevice in other cases (which should never + happen). +*/ + +/*! + \fn bool TQPaintDevice::isExtDev() const + + Returns TRUE if the device is an external paint device; otherwise + returns FALSE. + + External paint devices cannot be bitBlt()'ed from. TQPicture and + TQPrinter are external paint devices. +*/ + +/*! + Returns the window system handle of the paint device, for + low-level access. Using this function is not portable. + + The HANDLE type varies with platform; see \c tqpaintdevice.h and + \c ntqwindowdefs.h for details. + + \sa x11Display() +*/ +TQt::HANDLE TQPaintDevice::handle() const +{ + return hd; +} + +/*! + Returns the window system handle of the paint device for XRender + support. Use of this function is not portable. This function will + return 0 if XRender support is not compiled into TQt, if the + XRender extension is not supported on the X11 display, or if the + handle could not be created. +*/ +TQt::HANDLE TQPaintDevice::x11RenderHandle() const +{ +#ifndef TQT_NO_XFTFREETYPE + return rendhd ? XftDrawPicture( (XftDraw *) rendhd ) : 0; +#else + return 0; +#endif // TQT_NO_XFTFREETYPE +} + + +/*! + \fn Display *TQPaintDevice::x11AppDisplay() + + Returns a pointer to the X display global to the application (X11 + only). Using this function is not portable. + + \sa handle() +*/ + +/*! + \fn int TQPaintDevice::x11AppScreen() + + Returns the screen number on the X display global to the + application (X11 only). Using this function is not portable. +*/ + +/*! + \overload + \fn int TQPaintDevice::x11AppDepth() + + Returns the depth for the default screen of the X display global + to the application (X11 only). Using this function is not + portable. + + \sa TQPixmap::defaultDepth() +*/ + +/*! + \fn int TQPaintDevice::x11AppCells() + + Returns the number of entries in the colormap for the default + screen of the X display global to the application (X11 + only). Using this function is not portable. + + \sa x11Colormap() +*/ + +/*! + \fn HANDLE TQPaintDevice::x11AppRootWindow() + + Returns the root window for the default screen of the X display + global to the applicatoin (X11 only). Using this function is not + portable. +*/ + +/*! + \fn HANDLE TQPaintDevice::x11AppColormap() + + Returns the colormap for the default screen of the X display + global to the application (X11 only). Using this function is not + portable. + + \sa x11Cells() +*/ + +/*! + \fn bool TQPaintDevice::x11AppDefaultColormap () + + Returns the default colormap for the default screen of the X + display global to the application (X11 only). Using this function + is not portable. + + \sa x11Cells() +*/ + +/*! + \fn void* TQPaintDevice::x11AppVisual () + + Returns the Visual for the default screen of the X display global + to the application (X11 only). Using this function is not + portable. +*/ + +/*! + \fn bool TQPaintDevice::x11AppDefaultVisual () + + Returns TRUE if the Visual used is the default for the default + screen of the X display global to the application (X11 only); + otherwise returns FALSE. Using this function is not portable. +*/ + +/*! + \fn int TQPaintDevice::x11AppDepth( int screen ) + + Returns the depth for screen \a screen of the X display global to + the application (X11 only). Using this function is not portable. + + \sa TQPixmap::defaultDepth() +*/ + +/*! + \overload + \fn int TQPaintDevice::x11AppCells( int screen ) + + Returns the number of entries in the colormap for screen \a screen + of the X display global to the application (X11 only). Using this + function is not portable. + + \sa x11Colormap() +*/ + +/*! + \overload + \fn HANDLE TQPaintDevice::x11AppRootWindow( int screen ) + + Returns the root window for screen \a screen of the X display + global to the applicatoin (X11 only). Using this function is not + portable. +*/ + +/*! + \overload + \fn HANDLE TQPaintDevice::x11AppColormap( int screen ) + + Returns the colormap for screen \a screen of the X display global + to the application (X11 only). Using this function is not + portable. + + \sa x11Cells() +*/ + +/*! + \overload + \fn bool TQPaintDevice::x11AppDefaultColormap( int screen ) + + Returns the default colormap for screen \a screen of the X display + global to the application (X11 only). Using this function is not + portable. + + \sa x11Cells() +*/ + +/*! + \overload + \fn void* TQPaintDevice::x11AppVisual( int screen ) + + Returns the Visual for screen \a screen of the X display global to + the application (X11 only). Using this function is not portable. +*/ + +/*! + \overload + \fn bool TQPaintDevice::x11AppDefaultVisual( int screen ) + + Returns TRUE if the Visual used is the default for screen + \a screen of the X display global to the application (X11 only); + otherwise returns FALSE. Using this function is not portable. +*/ + + +/*! + \fn Display *TQPaintDevice::x11Display() const + + Returns a pointer to the X display for the paint device (X11 + only). Using this function is not portable. + + \sa handle() +*/ + +/*! + \fn int TQPaintDevice::x11Screen () const + + Returns the screen number on the X display for the paint device + (X11 only). Using this function is not portable. +*/ + +/*! + \fn int TQPaintDevice::x11Depth () const + + Returns the depth of the X display for the paint device (X11 + only). Using this function is not portable. + + \sa TQPixmap::defaultDepth() +*/ + +/*! + \fn int TQPaintDevice::x11Cells () const + + Returns the number of entries in the colormap of the X display for + the paint device (X11 only). Using this function is not portable. + + \sa x11Colormap() +*/ + +/*! + \fn HANDLE TQPaintDevice::x11Colormap () const + + Returns the colormap of the X display for the paint device (X11 + only). Using this function is not portable. + + \sa x11Cells() +*/ + +/*! + \fn bool TQPaintDevice::x11DefaultColormap () const + + Returns the default colormap of the X display for the paint device + (X11 only). Using this function is not portable. + + \sa x11Cells() +*/ + +/*! + \fn void* TQPaintDevice::x11Visual () const + + Returns the Visual of the X display for the paint device (X11 + only). Using this function is not portable. +*/ + +/*! + \fn bool TQPaintDevice::x11DefaultVisual () const + + Returns the default Visual of the X display for the paint device + (X11 only). Using this function is not portable. +*/ + +static int *dpisX=0, *dpisY=0; +static void create_dpis() +{ + if ( dpisX ) + return; + + Display *dpy = TQPaintDevice::x11AppDisplay(); + if ( ! dpy ) + return; + + int i, screens = ScreenCount( dpy ); + dpisX = new int[ screens ]; + dpisY = new int[ screens ]; + TQ_CHECK_PTR( dpisX ); + TQ_CHECK_PTR( dpisY ); + for ( i = 0; i < screens; i++ ) { + if (DisplayWidthMM(dpy,i) < 1) + dpisX[ i ] = 75; // default the dpi to 75. + else + dpisX[ i ] = (DisplayWidth(dpy,i) * 254 + DisplayWidthMM(dpy,i)*5) + / (DisplayWidthMM(dpy,i)*10); + if (DisplayHeightMM(dpy,i) < 1) + dpisY[ i ] = 75; // default the dpi to 75. + else + dpisY[ i ] = (DisplayHeight(dpy,i) * 254 + DisplayHeightMM(dpy,i)*5) + / (DisplayHeightMM(dpy,i)*10); + } +} + +/*! + Sets the value returned by x11AppDpiX() to \a dpi for screen + \a screen. The default is determined by the display configuration. + Changing this value will alter the scaling of fonts and many other + metrics and is not recommended. Using this function is not + portable. + + \sa x11SetAppDpiY() +*/ +void TQPaintDevice::x11SetAppDpiX(int dpi, int screen) +{ + create_dpis(); + if ( ! dpisX ) + return; + if ( screen < 0 ) + screen = TQPaintDevice::x11AppScreen(); + if ( screen > ScreenCount( TQPaintDevice::x11AppDisplay() ) ) + return; + dpisX[ screen ] = dpi; +} + +/*! + \overload + + Sets the value returned by x11AppDpiX() to \a dpi for the default + screen. The default is determined by the display configuration. + Changing this value will alter the scaling of fonts and many other + metrics and is not recommended. Using this function is not + portable. + +*/ +// ### REMOVE 4.0 +void TQPaintDevice::x11SetAppDpiX( int dpi ) +{ + TQPaintDevice::x11SetAppDpiX( dpi, -1 ); +} + +/*! + Sets the value returned by x11AppDpiY() to \a dpi for screen + \a screen. The default is determined by the display configuration. + Changing this value will alter the scaling of fonts and many other + metrics and is not recommended. Using this function is not + portable. + + \sa x11SetAppDpiX() +*/ +void TQPaintDevice::x11SetAppDpiY(int dpi, int screen) +{ + create_dpis(); + if ( ! dpisY ) + return; + if ( screen < 0 ) + screen = TQPaintDevice::x11AppScreen(); + if ( screen > ScreenCount( TQPaintDevice::x11AppDisplay() ) ) + return; + dpisY[ screen ] = dpi; +} + +/*! + \overload + + Sets the value returned by x11AppDpiY() to \a dpi for the default + screen. The default is determined by the display configuration. + Changing this value will alter the scaling of fonts and many other + metrics and is not recommended. Using this function is not + portable. +*/ +// ### REMOVE 4.0 +void TQPaintDevice::x11SetAppDpiY( int dpi ) +{ + TQPaintDevice::x11SetAppDpiY( dpi, -1 ); +} + +/*! + Returns the horizontal DPI of the X display (X11 only) for screen + \a screen. Using this function is not portable. See + TQPaintDeviceMetrics for portable access to related information. + Using this function is not portable. + + \sa x11AppDpiY(), x11SetAppDpiX(), TQPaintDeviceMetrics::logicalDpiX() +*/ +int TQPaintDevice::x11AppDpiX(int screen) +{ + create_dpis(); + if ( ! dpisX ) + return 0; + if ( screen < 0 ) + screen = TQPaintDevice::x11AppScreen(); + if ( screen > ScreenCount( TQPaintDevice::x11AppDisplay() ) ) + return 0; + return dpisX[ screen ]; +} + +/*! + \overload + + Returns the horizontal DPI of the X display (X11 only) for the + default screen. Using this function is not portable. See + TQPaintDeviceMetrics for portable access to related information. + Using this function is not portable. +*/ +int TQPaintDevice::x11AppDpiX() +{ + return TQPaintDevice::x11AppDpiX( -1 ); +} + +/*! + Returns the vertical DPI of the X11 display (X11 only) for screen + \a screen. Using this function is not portable. See + TQPaintDeviceMetrics for portable access to related information. + Using this function is not portable. + + \sa x11AppDpiX(), x11SetAppDpiY(), TQPaintDeviceMetrics::logicalDpiY() +*/ +int TQPaintDevice::x11AppDpiY( int screen ) +{ + create_dpis(); + if ( ! dpisY ) + return 0; + if ( screen < 0 ) + screen = TQPaintDevice::x11AppScreen(); + if ( screen > ScreenCount( TQPaintDevice::x11AppDisplay() ) ) + return 0; + return dpisY[ screen ]; +} + +/*! + \overload + + Returns the vertical DPI of the X11 display (X11 only) for the + default screen. Using this function is not portable. See + TQPaintDeviceMetrics for portable access to related information. + Using this function is not portable. + + \sa x11AppDpiX(), x11SetAppDpiY(), TQPaintDeviceMetrics::logicalDpiY() +*/ +int TQPaintDevice::x11AppDpiY() +{ + return TQPaintDevice::x11AppDpiY( -1 ); +} + +/*! + \fn bool TQPaintDevice::paintingActive() const + + Returns TRUE if the device is being painted, i.e. someone has + called TQPainter::begin() but not yet called TQPainter::end() for + this device; otherwise returns FALSE. + + \sa TQPainter::isActive() +*/ + +/*! + Internal virtual function that interprets drawing commands from + the painter. + + Implemented by subclasses that have no direct support for drawing + graphics (external paint devices, for example, TQPicture). +*/ + +bool TQPaintDevice::cmd( int, TQPainter *, TQPDevCmdParam * ) +{ +#if defined(QT_CHECK_STATE) + tqWarning( "TQPaintDevice::cmd: Device has no command interface" ); +#endif + return FALSE; +} + +/*! + \internal + + Internal virtual function that returns paint device metrics. + + Please use the TQPaintDeviceMetrics class instead. +*/ + +int TQPaintDevice::metric( int ) const +{ +#if defined(QT_CHECK_STATE) + tqWarning( "TQPaintDevice::metrics: Device has no metric information" ); +#endif + return 0; +} + +/*! + \internal + + Internal virtual function. Reserved for future use. + + Please use the TQFontMetrics class instead. +*/ + +int TQPaintDevice::fontMet( TQFont *, int, const char *, int ) const +{ + return 0; +} + +/*! + \internal + + Internal virtual function. Reserved for future use. + + Please use the TQFontInfo class instead. +*/ + +int TQPaintDevice::fontInf( TQFont *, int ) const +{ + return 0; +} + + +// +// Internal functions for simple GC caching for blt'ing masked pixmaps. +// This cache is used when the pixmap optimization is set to Normal +// and the pixmap size doesn't exceed 128x128. +// + +static bool init_mask_gc = FALSE; +static const int max_mask_gcs = 11; // suitable for hashing + +struct mask_gc { + GC gc; + int mask_no; +}; + +static mask_gc gc_vec[max_mask_gcs]; + + +static void cleanup_mask_gc() +{ + Display *dpy = TQPaintDevice::x11AppDisplay(); + init_mask_gc = FALSE; + for ( int i=0; igc || p->mask_no != mask_no ) { // not a perfect match + if ( !p->gc ) { // no GC + p->gc = XCreateGC( dpy, hd, 0, 0 ); + XSetGraphicsExposures( dpy, p->gc, False ); + } + XSetClipMask( dpy, p->gc, mask ); + p->mask_no = mask_no; + } + return p->gc; +} + + +/*! + \relates TQPaintDevice + + Copies a block of pixels from \a src to \a dst, perhaps merging + each pixel according to the \link TQt::RasterOp raster operation \endlink + \a rop. \a sx, \a sy + is the top-left pixel in \a src (0, 0) by default, \a dx, \a dy is + the top-left position in \a dst and \a sw, \a sh is the size of + the copied block (all of \a src by default). + + The most common values for \a rop are CopyROP and XorROP; the \l + TQt::RasterOp documentation defines all the possible values. + + If \a ignoreMask is FALSE (the default) and \a src is a + masked TQPixmap, the entire blit is masked by \a{src}->mask(). + + If \a src, \a dst, \a sw or \a sh is 0, bitBlt() does nothing. If + \a sw or \a sh is negative bitBlt() copies starting at \a sx (and + respectively, \a sy) and ending at the right end (respectively, + bottom) of \a src. + + \a src must be a TQWidget or TQPixmap. You cannot blit from a + TQPrinter, for example. bitBlt() does nothing if you attempt to + blit from an unsupported device. + + bitBlt() does nothing if \a src has a greater depth than \e dst. + If you need to for example, draw a 24-bit pixmap on an 8-bit + widget, you must use drawPixmap(). +*/ + +void bitBlt( TQPaintDevice *dst, int dx, int dy, + const TQPaintDevice *src, int sx, int sy, int sw, int sh, + TQt::RasterOp rop, bool ignoreMask ) +{ + if ( !src || !dst ) { +#if defined(QT_CHECK_NULL) + Q_ASSERT( src != 0 ); + Q_ASSERT( dst != 0 ); +#endif + return; + } + if ( !src->handle() || src->isExtDev() ) + return; + + TQPaintDevice *pdev = TQPainter::redirect( dst ); + if ( pdev ) + dst = pdev; + + int ts = src->devType(); // from device type + int td = dst->devType(); // to device type + Display *dpy = src->x11Display(); + + if ( sw <= 0 ) { // special width + if ( sw < 0 ) + sw = src->metric( TQPaintDeviceMetrics::PdmWidth ) - sx; + else + return; + } + if ( sh <= 0 ) { // special height + if ( sh < 0 ) + sh = src->metric( TQPaintDeviceMetrics::PdmHeight ) - sy; + else + return; + } + + if ( dst->paintingActive() && dst->isExtDev() ) { + TQPixmap *pm; // output to picture/printer + bool tmp_pm = TRUE; + if ( ts == TQInternal::Pixmap ) { + pm = (TQPixmap*)src; + if ( sx != 0 || sy != 0 || + sw != pm->width() || sh != pm->height() || ignoreMask ) { + TQPixmap *tmp = new TQPixmap( sw, sh, pm->depth() ); + bitBlt( tmp, 0, 0, pm, sx, sy, sw, sh, TQt::CopyROP, TRUE ); + if ( pm->mask() && !ignoreMask ) { + TQBitmap mask( sw, sh ); + bitBlt( &mask, 0, 0, pm->mask(), sx, sy, sw, sh, + TQt::CopyROP, TRUE ); + tmp->setMask( mask ); + } + pm = tmp; + } else { + tmp_pm = FALSE; + } + } else if ( ts == TQInternal::Widget ) {// bitBlt to temp pixmap + pm = new TQPixmap( sw, sh ); + TQ_CHECK_PTR( pm ); + bitBlt( pm, 0, 0, src, sx, sy, sw, sh ); + } else { +#if defined(QT_CHECK_RANGE) + tqWarning( "bitBlt: Cannot bitBlt from device" ); +#endif + return; + } + TQPDevCmdParam param[3]; + TQRect r(dx, dy, pm->width(), pm->height()); + param[0].rect = &r; + param[1].pixmap = pm; + dst->cmd( TQPaintDevice::PdcDrawPixmap, 0, param ); + if ( tmp_pm ) + delete pm; + return; + } + + switch ( ts ) { + case TQInternal::Widget: + case TQInternal::Pixmap: + case TQInternal::System: // OK, can blt from these + break; + default: +#if defined(QT_CHECK_RANGE) + tqWarning( "bitBlt: Cannot bitBlt from device type %x", ts ); +#endif + return; + } + switch ( td ) { + case TQInternal::Widget: + case TQInternal::Pixmap: + case TQInternal::System: // OK, can blt to these + break; + default: +#if defined(QT_CHECK_RANGE) + tqWarning( "bitBlt: Cannot bitBlt to device type %x", td ); +#endif + return; + } + + static const short ropCodes[] = { // ROP translation table + GXcopy, GXor, GXxor, GXandInverted, + GXcopyInverted, GXorInverted, GXequiv, GXand, + GXinvert, GXclear, GXset, GXnoop, + GXandReverse, GXorReverse, GXnand, GXnor + }; + if ( rop > TQt::LastROP ) { +#if defined(QT_CHECK_RANGE) + tqWarning( "bitBlt: Invalid ROP code" ); +#endif + return; + } + + if ( dst->handle() == 0 ) { +#if defined(QT_CHECK_NULL) + tqWarning( "bitBlt: Cannot bitBlt to device" ); +#endif + return; + } + + bool mono_src; + bool mono_dst; + bool include_inferiors = FALSE; + bool graphics_exposure = FALSE; + TQPixmap *src_pm; + TQBitmap *mask; + + if ( ts == TQInternal::Pixmap ) { + src_pm = (TQPixmap*)src; + if ( src_pm->x11Screen() != dst->x11Screen() ) + src_pm->x11SetScreen( dst->x11Screen() ); + mono_src = src_pm->depth() == 1; + mask = ignoreMask ? 0 : src_pm->data->mask; + } else { + src_pm = 0; + mono_src = FALSE; + mask = 0; + include_inferiors = ((TQWidget*)src)->testWFlags(TQt::WPaintUnclipped); + graphics_exposure = td == TQInternal::Widget; + } + if ( td == TQInternal::Pixmap ) { + if ( dst->x11Screen() != src->x11Screen() ) + ((TQPixmap*)dst)->x11SetScreen( src->x11Screen() ); + mono_dst = ((TQPixmap*)dst)->depth() == 1; + ((TQPixmap*)dst)->detach(); // changes shared pixmap + } else { + mono_dst = FALSE; + include_inferiors = include_inferiors || + ((TQWidget*)dst)->testWFlags(TQt::WPaintUnclipped); + } + + if ( mono_dst && !mono_src ) { // dest is 1-bit pixmap, source is not +#if defined(QT_CHECK_RANGE) + tqWarning( "bitBlt: Incompatible destination pixmap" ); +#endif + return; + } + +#ifndef TQT_NO_XRENDER + if (src_pm && !mono_src && src_pm->data->alphapm && !ignoreMask ) { + // use RENDER to do the blit + TQPixmap *alpha = src_pm->data->alphapm; + if (src->x11RenderHandle() && + alpha->x11RenderHandle() && + dst->x11RenderHandle()) { + XRenderPictureAttributes pattr; + ulong picmask = 0; + if (include_inferiors) { + pattr.subwindow_mode = IncludeInferiors; + picmask |= CPSubwindowMode; + } + if (graphics_exposure) { + pattr.graphics_exposures = TRUE; + picmask |= CPGraphicsExposure; + } + if (picmask) + XRenderChangePicture(dpy, dst->x11RenderHandle(), picmask, &pattr); + XRenderComposite(dpy, PictOpOver, src->x11RenderHandle(), + alpha->x11RenderHandle(), dst->x11RenderHandle(), + sx, sy, sx, sy, dx, dy, sw, sh); + // restore attributes + pattr.subwindow_mode = ClipByChildren; + pattr.graphics_exposures = FALSE; + if (picmask) + XRenderChangePicture(dpy, dst->x11RenderHandle(), picmask, &pattr); + return; + } + } +#endif + + GC gc; + + if ( mask && !mono_src ) { // fast masked blt + bool temp_gc = FALSE; + if ( mask->data->maskgc ) { + gc = (GC)mask->data->maskgc; // we have a premade mask GC + } else { + if ( FALSE && src_pm->optimization() == TQPixmap::NormalOptim ) { // #### cache disabled + // Compete for the global cache + gc = cache_mask_gc( dpy, dst->handle(), + mask->data->ser_no, + mask->handle() ); + } else { + // Create a new mask GC. If BestOptim, we store the mask GC + // with the mask (not at the pixmap). This way, many pixmaps + // which have a common mask will be optimized at no extra cost. + gc = XCreateGC( dpy, dst->handle(), 0, 0 ); + XSetGraphicsExposures( dpy, gc, False ); + XSetClipMask( dpy, gc, mask->handle() ); + if ( src_pm->optimization() == TQPixmap::BestOptim ) { + mask->data->maskgc = gc; + } else { + temp_gc = TRUE; + } + } + } + XSetClipOrigin( dpy, gc, dx-sx, dy-sy ); + if ( rop != TQt::CopyROP ) // use non-default ROP code + XSetFunction( dpy, gc, ropCodes[rop] ); + if ( include_inferiors ) { + XSetSubwindowMode( dpy, gc, IncludeInferiors ); + XCopyArea( dpy, src->handle(), dst->handle(), gc, sx, sy, sw, sh, + dx, dy ); + XSetSubwindowMode( dpy, gc, ClipByChildren ); + } else { + XCopyArea( dpy, src->handle(), dst->handle(), gc, sx, sy, sw, sh, + dx, dy ); + } + + if ( temp_gc ) // delete temporary GC + XFreeGC( dpy, gc ); + else if ( rop != TQt::CopyROP ) // restore ROP + XSetFunction( dpy, gc, GXcopy ); + return; + } + + gc = tqt_xget_temp_gc( dst->x11Screen(), mono_dst ); // get a reusable GC + + if ( rop != TQt::CopyROP ) // use non-default ROP code + XSetFunction( dpy, gc, ropCodes[rop] ); + + if ( mono_src && mono_dst && src == dst ) { // dst and src are the same bitmap + XCopyArea( dpy, src->handle(), dst->handle(), gc, sx, sy, sw, sh, dx, dy ); + } else if ( mono_src ) { // src is bitmap + XGCValues gcvals; + ulong valmask = GCBackground | GCForeground | GCFillStyle | + GCStipple | GCTileStipXOrigin | GCTileStipYOrigin; + if ( td == TQInternal::Widget ) { // set GC colors + TQWidget *w = (TQWidget *)dst; + gcvals.background = w->backgroundColor().pixel( dst->x11Screen() ); + gcvals.foreground = w->foregroundColor().pixel( dst->x11Screen() ); + if ( include_inferiors ) { + valmask |= GCSubwindowMode; + gcvals.subwindow_mode = IncludeInferiors; + } + } else if ( mono_dst ) { + gcvals.background = 0; + gcvals.foreground = 1; + } else { + gcvals.background = TQt::white.pixel( dst->x11Screen() ); + gcvals.foreground = TQt::black.pixel( dst->x11Screen() ); + } + + gcvals.fill_style = FillOpaqueStippled; + gcvals.stipple = src->handle(); + gcvals.ts_x_origin = dx - sx; + gcvals.ts_y_origin = dy - sy; + + bool clipmask = FALSE; + if ( mask ) { + if ( ((TQPixmap*)src)->data->selfmask ) { + gcvals.fill_style = FillStippled; + } else { + XSetClipMask( dpy, gc, mask->handle() ); + XSetClipOrigin( dpy, gc, dx-sx, dy-sy ); + clipmask = TRUE; + } + } + + XChangeGC( dpy, gc, valmask, &gcvals ); + XFillRectangle( dpy,dst->handle(), gc, dx, dy, sw, sh ); + + valmask = GCFillStyle | GCTileStipXOrigin | GCTileStipYOrigin; + gcvals.fill_style = FillSolid; + gcvals.ts_x_origin = 0; + gcvals.ts_y_origin = 0; + if ( include_inferiors ) { + valmask |= GCSubwindowMode; + gcvals.subwindow_mode = ClipByChildren; + } + XChangeGC( dpy, gc, valmask, &gcvals ); + + if ( clipmask ) { + XSetClipOrigin( dpy, gc, 0, 0 ); + XSetClipMask( dpy, gc, None ); + } + + } else { // src is pixmap/widget + + if ( graphics_exposure ) // widget to widget + XSetGraphicsExposures( dpy, gc, True ); + if ( include_inferiors ) { + XSetSubwindowMode( dpy, gc, IncludeInferiors ); + XCopyArea( dpy, src->handle(), dst->handle(), gc, sx, sy, sw, sh, + dx, dy ); + XSetSubwindowMode( dpy, gc, ClipByChildren ); + } else { + XCopyArea( dpy, src->handle(), dst->handle(), gc, sx, sy, sw, sh, + dx, dy ); + } + if ( graphics_exposure ) // reset graphics exposure + XSetGraphicsExposures( dpy, gc, False ); + } + + if ( rop != TQt::CopyROP ) // restore ROP + XSetFunction( dpy, gc, GXcopy ); +} + + +/*! + \relates TQPaintDevice + + \overload void bitBlt( TQPaintDevice *dst, const TQPoint &dp, const TQPaintDevice *src, const TQRect &sr, RasterOp rop ) + + Overloaded bitBlt() with the destination point \a dp and source + rectangle \a sr. +*/ + + +/*! + \internal +*/ +// makes it possible to add a setResolution as we have in TQPrinter for all +// paintdevices without breaking bin compatibility. +void TQPaintDevice::setResolution( int ) +{ +} + +/*!\internal +*/ +int TQPaintDevice::resolution() const +{ + return metric( TQPaintDeviceMetrics::PdmDpiY ); +} diff --git a/src/kernel/tqpaintdevicemetrics.cpp b/src/kernel/tqpaintdevicemetrics.cpp new file mode 100644 index 000000000..dc456ced3 --- /dev/null +++ b/src/kernel/tqpaintdevicemetrics.cpp @@ -0,0 +1,151 @@ +/**************************************************************************** +** +** Implementation of TQPaintDeviceMetrics class +** +** Created : 941109 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#include "tqpaintdevicemetrics.h" + +/*! + \class TQPaintDeviceMetrics tqpaintdevicemetrics.h + \brief The TQPaintDeviceMetrics class provides information about a + paint device. + + \ingroup graphics + \ingroup images + + Sometimes when drawing graphics it is necessary to obtain + information about the physical characteristics of a paint device. + This class provides the information. For example, to compute the + aspect ratio of a paint device: + + \code + TQPaintDeviceMetrics pdm( myWidget ); + double aspect = (double)pdm.widthMM() / (double)pdm.heightMM(); + \endcode + + TQPaintDeviceMetrics contains methods to provide the width and + height of a device in both pixels (width() and height()) and + millimeters (widthMM() and heightMM()), the number of colors the + device supports (numColors()), the number of bit planes (depth()), + and the resolution of the device (logicalDpiX() and + logicalDpiY()). + + It is not always possible for TQPaintDeviceMetrics to compute the + values you ask for, particularly for external devices. The + ultimate example is asking for the resolution of of a TQPrinter + that is set to "print to file": who knows what printer that file + will end up on? +*/ + +/*! + Constructs a metric for the paint device \a pd. +*/ +TQPaintDeviceMetrics::TQPaintDeviceMetrics( const TQPaintDevice *pd ) +{ + pdev = (TQPaintDevice *)pd; +} + + +/*! + \fn int TQPaintDeviceMetrics::width() const + + Returns the width of the paint device in default coordinate system + units (e.g. pixels for TQPixmap and TQWidget). +*/ + +/*! + \fn int TQPaintDeviceMetrics::height() const + + Returns the height of the paint device in default coordinate + system units (e.g. pixels for TQPixmap and TQWidget). +*/ + +/*! + \fn int TQPaintDeviceMetrics::widthMM() const + + Returns the width of the paint device, measured in millimeters. +*/ + +/*! + \fn int TQPaintDeviceMetrics::heightMM() const + + Returns the height of the paint device, measured in millimeters. +*/ + +/*! + \fn int TQPaintDeviceMetrics::numColors() const + + Returns the number of different colors available for the paint + device. Since this value is an int will not be sufficient to represent + the number of colors on 32 bit displays, in which case INT_MAX is + returned instead. +*/ + +/*! + \fn int TQPaintDeviceMetrics::depth() const + + Returns the bit depth (number of bit planes) of the paint device. +*/ + +/*! + \fn int TQPaintDeviceMetrics::logicalDpiX() const + + Returns the horizontal resolution of the device in dots per inch, + which is used when computing font sizes. For X, this is usually + the same as could be computed from widthMM(), but it varies on + Windows. +*/ + +/*! + \fn int TQPaintDeviceMetrics::logicalDpiY() const + + Returns the vertical resolution of the device in dots per inch, + which is used when computing font sizes. For X, this is usually + the same as could be computed from heightMM(), but it varies on + Windows. +*/ + +/*! + \fn int TQPaintDeviceMetrics::physicalDpiX() const + \internal +*/ +/*! + \fn int TQPaintDeviceMetrics::physicalDpiY() const + \internal +*/ + diff --git a/src/kernel/tqpaintdevicemetrics.h b/src/kernel/tqpaintdevicemetrics.h new file mode 100644 index 000000000..3d219f41e --- /dev/null +++ b/src/kernel/tqpaintdevicemetrics.h @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Definition of TQPaintDeviceMetrics class +** +** Created : 941109 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef TQPAINTDEVICEMETRICS_H +#define TQPAINTDEVICEMETRICS_H + +#ifndef QT_H +#include "tqpaintdevice.h" +#endif // QT_H + + +class TQ_EXPORT TQPaintDeviceMetrics // paint device metrics +{ +public: + TQPaintDeviceMetrics( const TQPaintDevice * ); + + enum { + PdmWidth = 1, + PdmHeight, + PdmWidthMM, + PdmHeightMM, + PdmNumColors, + PdmDepth, + PdmDpiX, + PdmDpiY, + PdmPhysicalDpiX, + PdmPhysicalDpiY + }; + + int width() const { return (int)pdev->metric(PdmWidth); } + int height() const { return (int)pdev->metric(PdmHeight); } + int widthMM() const { return (int)pdev->metric(PdmWidthMM); } + int heightMM() const { return (int)pdev->metric(PdmHeightMM); } + int logicalDpiX() const { return (int)pdev->metric(PdmDpiX); } + int logicalDpiY() const { return (int)pdev->metric(PdmDpiY); } + int physicalDpiX()const { return (int)pdev->metric(PdmPhysicalDpiX); } + int physicalDpiY()const { return (int)pdev->metric(PdmPhysicalDpiY); } + int numColors() const { return (int)pdev->metric(PdmNumColors); } + int depth() const { return (int)pdev->metric(PdmDepth); } + +private: + TQPaintDevice *pdev; +}; + + +#endif // TQPAINTDEVICEMETRICS_H diff --git a/src/kernel/tqpainter.cpp b/src/kernel/tqpainter.cpp new file mode 100644 index 000000000..325d11eea --- /dev/null +++ b/src/kernel/tqpainter.cpp @@ -0,0 +1,3910 @@ +/**************************************************************************** +** +** Implementation of TQPainter, TQPen and TQBrush classes +** +** Created : 940112 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#include "tqpainter.h" +#include "tqpainter_p.h" +#include "tqbitmap.h" +#include "tqptrstack.h" +#include "tqptrdict.h" +#include "tqdatastream.h" +#include "tqwidget.h" +#include "tqimage.h" +#include "tqpaintdevicemetrics.h" +#include "ntqapplication.h" +#include "qrichtext_p.h" +#include "tqregexp.h" +#include "ntqcleanuphandler.h" +#include + +#include "tqtextlayout_p.h" +#include "tqfontengine_p.h" + +#ifndef TQT_NO_TRANSFORMATIONS +typedef TQPtrStack TQWMatrixStack; +#endif + +// POSIX Large File Support redefines truncate -> truncate64 +#if defined(truncate) +# undef truncate +#endif + +/*! + \class TQPainter tqpainter.h + \brief The TQPainter class does low-level painting e.g. on widgets. + + \ingroup graphics + \ingroup images + \mainclass + + The painter provides highly optimized functions to do most of the + drawing GUI programs require. TQPainter can draw everything from + simple lines to complex shapes like pies and chords. It can also + draw aligned text and pixmaps. Normally, it draws in a "natural" + coordinate system, but it can also do view and world + transformation. + + The typical use of a painter is: + + \list + \i Construct a painter. + \i Set a pen, a brush etc. + \i Draw. + \i Destroy the painter. + \endlist + + Mostly, all this is done inside a paint event. (In fact, 99% of + all TQPainter use is in a reimplementation of + TQWidget::paintEvent(), and the painter is heavily optimized for + such use.) Here's one very simple example: + + \code + void SimpleExampleWidget::paintEvent() + { + TQPainter paint( this ); + paint.setPen( TQt::blue ); + paint.drawText( rect(), AlignCenter, "The Text" ); + } + \endcode + + Usage is simple, and there are many settings you can use: + + \list + + \i font() is the currently set font. If you set a font that isn't + available, TQt finds a close match. In fact font() returns what + you set using setFont() and fontInfo() returns the font actually + being used (which may be the same). + + \i brush() is the currently set brush; the color or pattern that's + used for filling e.g. circles. + + \i pen() is the currently set pen; the color or stipple that's + used for drawing lines or boundaries. + + \i backgroundMode() is \c Opaque or \c Transparent, i.e. whether + backgroundColor() is used or not. + + \i backgroundColor() only applies when backgroundMode() is Opaque + and pen() is a stipple. In that case, it describes the color of + the background pixels in the stipple. + + \i rasterOp() is how pixels drawn interact with the pixels already + there. + + \i brushOrigin() is the origin of the tiled brushes, normally the + origin of the window. + + \i viewport(), window(), worldMatrix() and many more make up the + painter's coordinate transformation system. See \link + coordsys.html The Coordinate System \endlink for an explanation of + this, or see below for a very brief overview of the functions. + + \i hasClipping() is whether the painter clips at all. (The paint + device clips, too.) If the painter clips, it clips to clipRegion(). + + \i pos() is the current position, set by moveTo() and used by + lineTo(). + + \endlist + + Note that some of these settings mirror settings in some paint + devices, e.g. TQWidget::font(). TQPainter::begin() (or the TQPainter + constructor) copies these attributes from the paint device. + Calling, for example, TQWidget::setFont() doesn't take effect until + the next time a painter begins painting on it. + + save() saves all of these settings on an internal stack, restore() + pops them back. + + The core functionality of TQPainter is drawing, and there are + functions to draw most primitives: drawPoint(), drawPoints(), + drawLine(), drawRect(), drawWinFocusRect(), drawRoundRect(), + drawEllipse(), drawArc(), drawPie(), drawChord(), + drawLineSegments(), drawPolyline(), drawPolygon(), + drawConvexPolygon() and drawCubicBezier(). All of these functions + take integer coordinates; there are no floating-point versions + since we want drawing to be as fast as possible. + + There are functions to draw pixmaps/images, namely drawPixmap(), + drawImage() and drawTiledPixmap(). drawPixmap() and drawImage() + produce the same result, except that drawPixmap() is faster + on-screen and drawImage() faster and sometimes better on TQPrinter + and TQPicture. + + Text drawing is done using drawText(), and when you need + fine-grained positioning, boundingRect() tells you where a given + drawText() command would draw. + + There is a drawPicture() function that draws the contents of an + entire TQPicture using this painter. drawPicture() is the only + function that disregards all the painter's settings: the TQPicture + has its own settings. + + Normally, the TQPainter operates on the device's own coordinate + system (usually pixels), but TQPainter has good support for + coordinate transformation. See \link coordsys.html The Coordinate + System \endlink for a more general overview and a simple example. + + The most common functions used are scale(), rotate(), translate() + and shear(), all of which operate on the worldMatrix(). + setWorldMatrix() can replace or add to the currently set + worldMatrix(). + + setViewport() sets the rectangle on which TQPainter operates. The + default is the entire device, which is usually fine, except on + printers. setWindow() sets the coordinate system, that is, the + rectangle that maps to viewport(). What's drawn inside the + window() ends up being inside the viewport(). The window's + default is the same as the viewport, and if you don't use the + transformations, they are optimized away, gaining another little + bit of speed. + + After all the coordinate transformation is done, TQPainter can clip + the drawing to an arbitrary rectangle or region. hasClipping() is + TRUE if TQPainter clips, and clipRegion() returns the clip region. + You can set it using either setClipRegion() or setClipRect(). + Note that the clipping can be slow. It's all system-dependent, + but as a rule of thumb, you can assume that drawing speed is + inversely proportional to the number of rectangles in the clip + region. + + After TQPainter's clipping, the paint device may also clip. For + example, most widgets clip away the pixels used by child widgets, + and most printers clip away an area near the edges of the paper. + This additional clipping is not reflected by the return value of + clipRegion() or hasClipping(). + + TQPainter also includes some less-used functions that are very + useful on those occasions when they're needed. + + isActive() indicates whether the painter is active. begin() (and + the most usual constructor) makes it active. end() (and the + destructor) deactivates it. If the painter is active, device() + returns the paint device on which the painter paints. + + Sometimes it is desirable to make someone else paint on an unusual + TQPaintDevice. TQPainter supports a static function to do this, + redirect(). We recommend not using it, but for some hacks it's + perfect. + + setTabStops() and setTabArray() can change where the tab stops + are, but these are very seldomly used. + + \warning Note that TQPainter does not attempt to work around + coordinate limitations in the underlying window system. Some + platforms may behave incorrectly with coordinates as small as + +/-4000. + + \headerfile ntqdrawutil.h + + \sa TQPaintDevice TQWidget TQPixmap TQPrinter TQPicture + \link simple-application.html Application Walkthrough \endlink + \link coordsys.html Coordinate System Overview \endlink +*/ + +/*! + \enum TQPainter::CoordinateMode + \value CoordDevice + \value CoordPainter + + \sa clipRegion() +*/ +/*! + \enum TQPainter::TextDirection + \value Auto + \value RTL right to left + \value LTR left to right + + \sa drawText() +*/ + +/*! + \enum TQt::PaintUnit + \value PixelUnit + \value LoMetricUnit \e obsolete + \value HiMetricUnit \e obsolete + \value LoEnglishUnit \e obsolete + \value HiEnglishUnit \e obsolete + \value TwipsUnit \e obsolete +*/ + +/*! + \enum TQt::BrushStyle + + \value NoBrush + \value SolidPattern + \value Dense1Pattern + \value Dense2Pattern + \value Dense3Pattern + \value Dense4Pattern + \value Dense5Pattern + \value Dense6Pattern + \value Dense7Pattern + \value HorPattern + \value VerPattern + \value CrossPattern + \value BDiagPattern + \value FDiagPattern + \value DiagCrossPattern + \value CustomPattern + + \img brush-styles.png Brush Styles + +*/ + +/*! + \enum TQt::RasterOp + + This enum type is used to describe the way things are written to + the paint device. Each bit of the \e src (what you write) + interacts with the corresponding bit of the \e dst pixel. + + \value CopyROP dst = src + \value OrROP dst = src OR dst + \value XorROP dst = src XOR dst + \value NotAndROP dst = (NOT src) AND dst + \value EraseROP an alias for \c NotAndROP + \value NotCopyROP dst = NOT src + \value NotOrROP dst = (NOT src) OR dst + \value NotXorROP dst = (NOT src) XOR dst + \value AndROP dst = src AND dst + \value NotEraseROP an alias for \c AndROP + \value NotROP dst = NOT dst + \value ClearROP dst = 0 + \value SetROP dst = 1 + \value NopROP dst = dst + \value AndNotROP dst = src AND (NOT dst) + \value OrNotROP dst = src OR (NOT dst) + \value NandROP dst = NOT (src AND dst) + \value NorROP dst = NOT (src OR dst) + + By far the most useful ones are \c CopyROP and \c XorROP. +*/ + +/*! + \enum TQt::AlignmentFlags + + This enum type is used to describe alignment. It contains + horizontal and vertical flags. + + The horizontal flags are: + + \value AlignAuto Aligns according to the language. Left for most, + right for Arabic and Hebrew. + \value AlignLeft Aligns with the left edge. + \value AlignRight Aligns with the right edge. + \value AlignHCenter Centers horizontally in the available space. + \value AlignJustify Justifies the text in the available space. + Does not work for everything and may be interpreted as + AlignAuto in some cases. + + The vertical flags are: + + \value AlignTop Aligns with the top. + \value AlignBottom Aligns with the bottom. + \value AlignVCenter Centers vertically in the available space. + + You can use only one of the horizontal flags at a time. There is + one two-dimensional flag: + + \value AlignCenter Centers in both dimensions. + + You can use at most one horizontal and one vertical flag at a time. \c + AlignCenter counts as both horizontal and vertical. + + Masks: + + \value AlignHorizontal_Mask + \value AlignVertical_Mask + + Conflicting combinations of flags have undefined meanings. +*/ + +/*! + \enum TQt::TextFlags + + This enum type is used to define some modifier flags. Some of + these flags only make sense in the context of printing: + + \value SingleLine Treats all whitespace as spaces and prints just + one line. + \value DontClip If it's impossible to stay within the given bounds, + it prints outside. + \value ExpandTabs Makes the U+0009 (ASCII tab) character move to + the next tab stop. + \value ShowPrefix Displays the string "\&P" as P + (see TQButton for an example). For an ampersand, use "\&\&". + \value WordBreak Breaks lines at appropriate points, e.g. at word + boundaries. + \value BreakAnywhere Breaks lines anywhere, even within words. + \value NoAccel Same as ShowPrefix but doesn't draw the underlines. + + You can use as many modifier flags as you want, except that \c + SingleLine and \c WordBreak cannot be combined. + + Flags that are inappropriate for a given use (e.g. ShowPrefix to + TQGridLayout::addWidget()) are generally ignored. + +*/ + +/*! + \enum TQt::PenStyle + + This enum type defines the pen styles that can be drawn using + TQPainter. The styles are + + \value NoPen no line at all. For example, TQPainter::drawRect() + fills but does not draw any boundary line. + + \value SolidLine a simple line. + + \value DashLine dashes separated by a few pixels. + + \value DotLine dots separated by a few pixels. + + \value DashDotLine alternate dots and dashes. + + \value DashDotDotLine one dash, two dots, one dash, two dots. + + \value FineDotLine single pixel dots separated by single pixels. + + \value MPenStyle mask of the pen styles. + + \img pen-styles.png Pen Styles +*/ + +/*! + \enum TQt::PenCapStyle + + This enum type defines the pen cap styles supported by TQt, i.e. + the line end caps that can be drawn using TQPainter. + + \value FlatCap a square line end that does not cover the end + point of the line. + \value SquareCap a square line end that covers the end point and + extends beyond it with half the line width. + \value RoundCap a rounded line end. + \value MPenCapStyle mask of the pen cap styles. + + \img pen-cap-styles.png Pen Cap Styles +*/ + +/*! + \enum TQt::PenJoinStyle + + This enum type defines the pen join styles supported by TQt, i.e. + which joins between two connected lines can be drawn using + TQPainter. + + \value MiterJoin The outer edges of the lines are extended to + meet at an angle, and this area is filled. + \value BevelJoin The triangular notch between the two lines is filled. + \value RoundJoin A circular arc between the two lines is filled. + \value MPenJoinStyle mask of the pen join styles. + + \img pen-join-styles.png Pen Join Styles +*/ + +/*! + \enum TQt::BGMode + + Background mode + + \value TransparentMode + \value OpaqueMode +*/ + +/*! + Constructs a painter. + + Notice that all painter settings (setPen, setBrush etc.) are reset + to default values when begin() is called. + + \sa begin(), end() +*/ + +TQPainter::TQPainter() +{ + init(); +} + + +/*! + Constructs a painter that begins painting the paint device \a pd + immediately. Depending on the underlying graphic system the + painter will paint over children of the paintdevice if \a + unclipped is TRUE. + + This constructor is convenient for short-lived painters, e.g. in a + \link TQWidget::paintEvent() paint event\endlink and should be used + only once. The constructor calls begin() for you and the TQPainter + destructor automatically calls end(). + + Here's an example using begin() and end(): + \code + void MyWidget::paintEvent( TQPaintEvent * ) + { + TQPainter p; + p.begin( this ); + p.drawLine( ... ); // drawing code + p.end(); + } + \endcode + + The same example using this constructor: + \code + void MyWidget::paintEvent( TQPaintEvent * ) + { + TQPainter p( this ); + p.drawLine( ... ); // drawing code + } + \endcode + + Since the constructor cannot provide feedback when the initialization + of the painter failed you should rather use begin() and end() to paint + on external devices, e.g. printers. + + \sa begin(), end() +*/ + +TQPainter::TQPainter( const TQPaintDevice *pd, bool unclipped ) +{ + init(); + if ( begin( pd, unclipped ) ) + flags |= CtorBegin; +} + + +/*! + Constructs a painter that begins painting the paint device \a pd + immediately, with the default arguments taken from \a + copyAttributes. The painter will paint over children of the paint + device if \a unclipped is TRUE (although this is not supported on + all platforms). + + \sa begin() +*/ + +TQPainter::TQPainter( const TQPaintDevice *pd, + const TQWidget *copyAttributes, bool unclipped ) +{ + init(); + if ( begin( pd, copyAttributes, unclipped ) ) + flags |= CtorBegin; +} + + +/*! + Destroys the painter. +*/ + +TQPainter::~TQPainter() +{ + if ( isActive() ) + end(); + else + killPStack(); + if ( tabarray ) // delete tab array + delete [] tabarray; +#ifndef TQT_NO_TRANSFORMATIONS + if ( wm_stack ) + delete (TQWMatrixStack *)wm_stack; +#endif + destroy(); +} + + +/*! + \overload bool TQPainter::begin( const TQPaintDevice *pd, const TQWidget *copyAttributes, bool unclipped ) + + This version opens the painter on a paint device \a pd and sets + the initial pen, background color and font from \a copyAttributes, + painting over the paint device's children when \a unclipped is + TRUE. This is equivalent to: + + \code + TQPainter p; + p.begin( pd ); + p.setPen( copyAttributes->foregroundColor() ); + p.setBackgroundColor( copyAttributes->backgroundColor() ); + p.setFont( copyAttributes->font() ); + \endcode + + This begin function is convenient for double buffering. When you + draw in a pixmap instead of directly in a widget (to later bitBlt + the pixmap into the widget) you will need to set the widget's + font etc. This function does exactly that. + + Example: + \code + void MyWidget::paintEvent( TQPaintEvent * ) + { + TQPixmap pm(size()); + TQPainter p; + p.begin(&pm, this); + // ... potentially flickering paint operation ... + p.end(); + bitBlt(this, 0, 0, &pm); + } + \endcode + + \sa end() +*/ + +bool TQPainter::begin( const TQPaintDevice *pd, const TQWidget *copyAttributes, bool unclipped ) +{ + if ( copyAttributes == 0 ) { +#if defined(QT_CHECK_NULL) + tqWarning( "TQPainter::begin: The widget to copy attributes from cannot " + "be null" ); +#endif + return FALSE; + } + if ( begin( pd, unclipped ) ) { + setPen( copyAttributes->foregroundColor() ); + setBackgroundColor( copyAttributes->backgroundColor() ); + setFont( copyAttributes->font() ); + return TRUE; + } + return FALSE; +} + + +/*! + \internal + Sets or clears a pointer flag. +*/ + +void TQPainter::setf( uint b, bool v ) +{ + if ( v ) + setf( b ); + else + clearf( b ); +} + + +/*! + \fn bool TQPainter::isActive() const + + Returns TRUE if the painter is active painting, i.e. begin() has + been called and end() has not yet been called; otherwise returns + FALSE. + + \sa TQPaintDevice::paintingActive() +*/ + +/*! + \fn TQPaintDevice *TQPainter::device() const + + Returns the paint device on which this painter is currently + painting, or 0 if the painter is not active. + + \sa TQPaintDevice::paintingActive() +*/ + + +struct TQPState { // painter state + TQFont font; + TQPen pen; + TQPoint curPt; + TQBrush brush; + TQColor bgc; + uchar bgm; + uchar rop; + TQPoint bro; + TQRect wr, vr; +#ifndef TQT_NO_TRANSFORMATIONS + TQWMatrix wm; +#else + int xlatex; + int xlatey; +#endif + bool vxf; + bool wxf; + TQRegion rgn; + bool clip; + int ts; + int *ta; + void* wm_stack; +}; + +//TODO lose the worldmatrix stack + +typedef TQPtrStack TQPStateStack; + + +void TQPainter::killPStack() +{ +#if defined(QT_CHECK_STATE) + if ( ps_stack && !((TQPStateStack *)ps_stack)->isEmpty() ) + tqWarning( "TQPainter::killPStack: non-empty save/restore stack when " + "end() was called" ); +#endif + delete (TQPStateStack *)ps_stack; + ps_stack = 0; +} + +/*! + Saves the current painter state (pushes the state onto a stack). A + save() must be followed by a corresponding restore(). end() + unwinds the stack. + + \sa restore() +*/ + +void TQPainter::save() +{ + if ( testf(ExtDev) ) { + if ( testf(DirtyFont) ) + updateFont(); + if ( testf(DirtyPen) ) + updatePen(); + if ( testf(DirtyBrush) ) + updateBrush(); + pdev->cmd( TQPaintDevice::PdcSave, this, 0 ); + } + TQPStateStack *pss = (TQPStateStack *)ps_stack; + if ( pss == 0 ) { + pss = new TQPtrStack; + TQ_CHECK_PTR( pss ); + pss->setAutoDelete( TRUE ); + ps_stack = pss; + } + TQPState *ps = new TQPState; + TQ_CHECK_PTR( ps ); + ps->font = cfont; + ps->pen = cpen; + ps->curPt = pos(); + ps->brush = cbrush; + ps->bgc = bg_col; + ps->bgm = bg_mode; + ps->rop = rop; + ps->bro = bro; +#ifndef TQT_NO_TRANSFORMATIONS + ps->wr = TQRect( wx, wy, ww, wh ); + ps->vr = TQRect( vx, vy, vw, vh ); + ps->wm = wxmat; + ps->vxf = testf(VxF); + ps->wxf = testf(WxF); +#else + ps->xlatex = xlatex; + ps->xlatey = xlatey; +#endif + ps->rgn = crgn; + ps->clip = testf(ClipOn); + ps->ts = tabstops; + ps->ta = tabarray; + ps->wm_stack = wm_stack; + wm_stack = 0; + pss->push( ps ); +} + +/*! + Restores the current painter state (pops a saved state off the + stack). + + \sa save() +*/ + +void TQPainter::restore() +{ + if ( testf(ExtDev) ) { + pdev->cmd( TQPaintDevice::PdcRestore, this, 0 ); + if ( pdev->devType() == TQInternal::Picture ) + block_ext = TRUE; + } + TQPStateStack *pss = (TQPStateStack *)ps_stack; + if ( pss == 0 || pss->isEmpty() ) { +#if defined(QT_CHECK_STATE) + tqWarning( "TQPainter::restore: Empty stack error" ); +#endif + return; + } + TQPState *ps = pss->pop(); + bool hardRestore = testf(VolatileDC); + + if ( ps->font != cfont || hardRestore ) + setFont( ps->font ); + if ( ps->pen != cpen || hardRestore ) + setPen( ps->pen ); + if ( ps->brush != cbrush || hardRestore ) + setBrush( ps->brush ); + if ( ps->bgc != bg_col || hardRestore ) + setBackgroundColor( ps->bgc ); + if ( ps->bgm != bg_mode || hardRestore ) + setBackgroundMode( (BGMode)ps->bgm ); + if ( ps->rop != rop || hardRestore ) + setRasterOp( (RasterOp)ps->rop ); + if ( ps->bro != bro || hardRestore ) + setBrushOrigin( ps->bro ); +#ifndef TQT_NO_TRANSFORMATIONS + TQRect wr( wx, wy, ww, wh ); + TQRect vr( vx, vy, vw, vh ); + if ( ps->wr != wr || hardRestore ) + setWindow( ps->wr ); + if ( ps->vr != vr || hardRestore ) + setViewport( ps->vr ); + if ( ps->wm != wxmat || hardRestore ) + setWorldMatrix( ps->wm ); + if ( ps->vxf != testf(VxF) || hardRestore ) + setViewXForm( ps->vxf ); + if ( ps->wxf != testf(WxF) || hardRestore ) + setWorldXForm( ps->wxf ); +#else + xlatex = ps->xlatex; + xlatey = ps->xlatey; + setf( VxF, xlatex || xlatey ); +#endif + if ( ps->curPt != pos() || hardRestore ) + moveTo( ps->curPt ); + if ( ps->rgn != crgn || hardRestore ) + setClipRegion( ps->rgn ); + if ( ps->clip != testf(ClipOn) || hardRestore ) + setClipping( ps->clip ); + tabstops = ps->ts; + tabarray = ps->ta; + +#ifndef TQT_NO_TRANSFORMATIONS + if ( wm_stack ) + delete (TQWMatrixStack *)wm_stack; + wm_stack = ps->wm_stack; +#endif + delete ps; + block_ext = FALSE; +} + +typedef TQPtrDict TQPaintDeviceDict; +static TQPaintDeviceDict *pdev_dict = 0; + +/*! + Redirects all paint commands for a paint device, \a pdev, to + another paint device, \a replacement, unless \a replacement is 0. + If \a replacement is 0, the redirection for \a pdev is removed. + + In general, you'll probably find calling TQPixmap::grabWidget() or + TQPixmap::grabWindow() is an easier solution. +*/ + +void TQPainter::redirect( TQPaintDevice *pdev, TQPaintDevice *replacement ) +{ + if ( pdev_dict == 0 ) { + if ( replacement == 0 ) + return; + pdev_dict = new TQPaintDeviceDict; + TQ_CHECK_PTR( pdev_dict ); + } +#if defined(QT_CHECK_NULL) + if ( pdev == 0 ) + tqWarning( "TQPainter::redirect: The pdev argument cannot be 0" ); +#endif + if ( replacement ) { + pdev_dict->insert( pdev, replacement ); + } else { + pdev_dict->remove( pdev ); + if ( pdev_dict->count() == 0 ) { + delete pdev_dict; + pdev_dict = 0; + } + } +} + +/*! + \internal + Returns the replacement for \a pdev, or 0 if there is no replacement. +*/ +TQPaintDevice *TQPainter::redirect( TQPaintDevice *pdev ) +{ + return pdev_dict ? pdev_dict->find( pdev ) : 0; +} + +/*! + Returns the font metrics for the painter, if the painter is + active. It is not possible to obtain metrics for an inactive + painter, so the return value is undefined if the painter is not + active. + + \sa fontInfo(), isActive() +*/ + +TQFontMetrics TQPainter::fontMetrics() const +{ + if ( pdev && pdev->devType() == TQInternal::Picture ) + return TQFontMetrics( cfont ); + + return TQFontMetrics(this); +} + +/*! + Returns the font info for the painter, if the painter is active. + It is not possible to obtain font information for an inactive + painter, so the return value is undefined if the painter is not + active. + + \sa fontMetrics(), isActive() +*/ + +TQFontInfo TQPainter::fontInfo() const +{ + if ( pdev && pdev->devType() == TQInternal::Picture ) + return TQFontInfo( cfont ); + + return TQFontInfo(this); +} + + +/*! + \fn const TQPen &TQPainter::pen() const + + Returns the painter's current pen. + + \sa setPen() +*/ + +/*! + Sets a new painter pen. + + The \a pen defines how to draw lines and outlines, and it also + defines the text color. + + \sa pen() +*/ + +void TQPainter::setPen( const TQPen &pen ) +{ +#if defined(QT_CHECK_STATE) + if ( !isActive() ) + tqWarning( "TQPainter::setPen: Will be reset by begin()" ); +#endif + if ( cpen == pen ) + return; + cpen = pen; + updatePen(); +} + +/*! + \overload + + Sets the painter's pen to have style \a style, width 0 and black + color. + + \sa pen(), TQPen +*/ + +void TQPainter::setPen( PenStyle style ) +{ +#if defined(QT_CHECK_STATE) + if ( !isActive() ) + tqWarning( "TQPainter::setPen: Will be reset by begin()" ); +#endif + TQPen::TQPenData *d = cpen.data; // low level access + if ( d->style == style && d->linest == style && !d->width && d->color == TQt::black ) + return; + if ( d->count != 1 ) { + cpen.detach(); + d = cpen.data; + } + d->style = style; + d->width = 0; + d->color = TQt::black; + d->linest = style; + updatePen(); +} + +/*! + \overload + + Sets the painter's pen to have style \c SolidLine, width 0 and the + specified \a color. + + \sa pen(), TQPen +*/ + +void TQPainter::setPen( const TQColor &color ) +{ +#if defined(QT_CHECK_STATE) + if ( !isActive() ) + tqWarning( "TQPainter::setPen: Will be reset by begin()" ); +#endif + TQPen::TQPenData *d = cpen.data; // low level access + if ( d->color == color && !d->width && d->style == SolidLine && d->linest == SolidLine ) + return; + if ( d->count != 1 ) { + cpen.detach(); + d = cpen.data; + } + d->style = SolidLine; + d->width = 0; + d->color = color; + d->linest = SolidLine; + updatePen(); +} + +/*! + \fn const TQBrush &TQPainter::brush() const + + Returns the painter's current brush. + + \sa TQPainter::setBrush() +*/ + +/*! + \overload + + Sets the painter's brush to \a brush. + + The \a brush defines how shapes are filled. + + \sa brush() +*/ + +void TQPainter::setBrush( const TQBrush &brush ) +{ +#if defined(QT_CHECK_STATE) + if ( !isActive() ) + tqWarning( "TQPainter::setBrush: Will be reset by begin()" ); +#endif + if ( cbrush == brush ) + return; + cbrush = brush; + updateBrush(); +} + +/*! + Sets the painter's brush to black color and the specified \a + style. + + \sa brush(), TQBrush +*/ + +void TQPainter::setBrush( BrushStyle style ) +{ +#if defined(QT_CHECK_STATE) + if ( !isActive() ) + tqWarning( "TQPainter::setBrush: Will be reset by begin()" ); +#endif + TQBrush::TQBrushData *d = cbrush.data; // low level access + if ( d->style == style && d->color == TQt::black && !d->pixmap ) + return; + if ( d->count != 1 ) { + cbrush.detach(); + d = cbrush.data; + } + d->style = style; + d->color = TQt::black; + if ( d->pixmap ) { + delete d->pixmap; + d->pixmap = 0; + } + updateBrush(); +} + +/*! + \overload + + Sets the painter's brush to have style \c SolidPattern and the + specified \a color. + + \sa brush(), TQBrush +*/ + +void TQPainter::setBrush( const TQColor &color ) +{ +#if defined(QT_CHECK_STATE) + if ( !isActive() ) + tqWarning( "TQPainter::setBrush: Will be reset by begin()" ); +#endif + TQBrush::TQBrushData *d = cbrush.data; // low level access + if ( d->color == color && d->style == SolidPattern && !d->pixmap ) + return; + if ( d->count != 1 ) { + cbrush.detach(); + d = cbrush.data; + } + d->style = SolidPattern; + d->color = color; + if ( d->pixmap ) { + delete d->pixmap; + d->pixmap = 0; + } + updateBrush(); +} + + +/*! + \fn const TQColor &TQPainter::backgroundColor() const + + Returns the current background color. + + \sa setBackgroundColor() TQColor +*/ + +/*! + \fn BGMode TQPainter::backgroundMode() const + + Returns the current background mode. + + \sa setBackgroundMode() BGMode +*/ + +/*! + \fn RasterOp TQPainter::rasterOp() const + + Returns the current \link TQt::RasterOp raster operation \endlink. + + \sa setRasterOp() RasterOp +*/ + +/*! + \fn const TQPoint &TQPainter::brushOrigin() const + + Returns the brush origin currently set. + + \sa setBrushOrigin() +*/ + + +/*! + \fn int TQPainter::tabStops() const + + Returns the tab stop setting. + + \sa setTabStops() +*/ + +/*! + Set the tab stop width to \a ts, i.e. locates tab stops at \a ts, + 2*\a ts, 3*\a ts and so on. + + Tab stops are used when drawing formatted text with \c ExpandTabs + set. This fixed tab stop value is used only if no tab array is set + (which is the default case). + + A value of 0 (the default) implies a tabstop setting of 8 times the width of the + character 'x' in the font currently set on the painter. + + \sa tabStops(), setTabArray(), drawText(), fontMetrics() +*/ + +void TQPainter::setTabStops( int ts ) +{ +#if defined(QT_CHECK_STATE) + if ( !isActive() ) + tqWarning( "TQPainter::setTabStops: Will be reset by begin()" ); +#endif + tabstops = ts; + if ( isActive() && testf(ExtDev) ) { // tell extended device + TQPDevCmdParam param[1]; + param[0].ival = ts; + pdev->cmd( TQPaintDevice::PdcSetTabStops, this, param ); + } +} + +/*! + \fn int *TQPainter::tabArray() const + + Returns the currently set tab stop array. + + \sa setTabArray() +*/ + +/*! + Sets the tab stop array to \a ta. This puts tab stops at \a ta[0], + \a ta[1] and so on. The array is null-terminated. + + If both a tab array and a tab top size is set, the tab array wins. + + \sa tabArray(), setTabStops(), drawText(), fontMetrics() +*/ + +void TQPainter::setTabArray( int *ta ) +{ +#if defined(QT_CHECK_STATE) + if ( !isActive() ) + tqWarning( "TQPainter::setTabArray: Will be reset by begin()" ); +#endif + if ( ta != tabarray ) { + tabarraylen = 0; + if ( tabarray ) // Avoid purify complaint + delete [] tabarray; // delete old array + if ( ta ) { // tabarray = copy of 'ta' + while ( ta[tabarraylen] ) + tabarraylen++; + tabarraylen++; // and 0 terminator + tabarray = new int[tabarraylen]; // duplicate ta + memcpy( tabarray, ta, sizeof(int)*tabarraylen ); + } else { + tabarray = 0; + } + } + if ( isActive() && testf(ExtDev) ) { // tell extended device + TQPDevCmdParam param[2]; + param[0].ival = tabarraylen; + param[1].ivec = tabarray; + pdev->cmd( TQPaintDevice::PdcSetTabArray, this, param ); + } +} + + +/*! + \fn HANDLE TQPainter::handle() const + + Returns the platform-dependent handle used for drawing. Using this + function is not portable. +*/ + + +/***************************************************************************** + TQPainter xform settings + *****************************************************************************/ + +#ifndef TQT_NO_TRANSFORMATIONS + +/*! + Enables view transformations if \a enable is TRUE, or disables + view transformations if \a enable is FALSE. + + \sa hasViewXForm(), setWindow(), setViewport(), setWorldMatrix(), + setWorldXForm(), xForm() +*/ + +void TQPainter::setViewXForm( bool enable ) +{ +#if defined(QT_CHECK_STATE) + if ( !isActive() ) + tqWarning( "TQPainter::setViewXForm: Will be reset by begin()" ); +#endif + if ( !isActive() || enable == testf(VxF) ) + return; + setf( VxF, enable ); + if ( testf(ExtDev) ) { + TQPDevCmdParam param[1]; + param[0].ival = enable; + pdev->cmd( TQPaintDevice::PdcSetVXform, this, param ); + } + updateXForm(); +} + +/*! + \fn bool TQPainter::hasViewXForm() const + + Returns TRUE if view transformation is enabled; otherwise returns + FALSE. + + \sa setViewXForm(), xForm() +*/ + +/*! + Returns the window rectangle. + + \sa setWindow(), setViewXForm() +*/ + +TQRect TQPainter::window() const +{ + return TQRect( wx, wy, ww, wh ); +} + +/*! + Sets the window rectangle view transformation for the painter and + enables view transformation. + + The window rectangle is part of the view transformation. The + window specifies the logical coordinate system and is specified by + the \a x, \a y, \a w width and \a h height parameters. Its sister, + the viewport(), specifies the device coordinate system. + + The default window rectangle is the same as the device's + rectangle. See the \link coordsys.html Coordinate System Overview + \endlink for an overview of coordinate transformation. + + \sa window(), setViewport(), setViewXForm(), setWorldMatrix(), + setWorldXForm() +*/ + +void TQPainter::setWindow( int x, int y, int w, int h ) +{ +#if defined(QT_CHECK_STATE) + if ( !isActive() ) + tqWarning( "TQPainter::setWindow: Will be reset by begin()" ); +#endif + wx = x; + wy = y; + ww = w; + wh = h; + if ( testf(ExtDev) ) { + TQRect r( x, y, w, h ); + TQPDevCmdParam param[1]; + param[0].rect = (TQRect*)&r; + pdev->cmd( TQPaintDevice::PdcSetWindow, this, param ); + } + if ( testf(VxF) ) + updateXForm(); + else + setViewXForm( TRUE ); +} + +/*! + Returns the viewport rectangle. + + \sa setViewport(), setViewXForm() +*/ + +TQRect TQPainter::viewport() const // get viewport +{ + return TQRect( vx, vy, vw, vh ); +} + +/*! + Sets the viewport rectangle view transformation for the painter + and enables view transformation. + + The viewport rectangle is part of the view transformation. The + viewport specifies the device coordinate system and is specified + by the \a x, \a y, \a w width and \a h height parameters. Its + sister, the window(), specifies the logical coordinate system. + + The default viewport rectangle is the same as the device's + rectangle. See the \link coordsys.html Coordinate System Overview + \endlink for an overview of coordinate transformation. + + \sa viewport(), setWindow(), setViewXForm(), setWorldMatrix(), + setWorldXForm(), xForm() +*/ + +void TQPainter::setViewport( int x, int y, int w, int h ) +{ +#if defined(QT_CHECK_STATE) + if ( !isActive() ) + tqWarning( "TQPainter::setViewport: Will be reset by begin()" ); +#endif + vx = x; + vy = y; + vw = w; + vh = h; + if ( testf(ExtDev) ) { + TQRect r( x, y, w, h ); + TQPDevCmdParam param[1]; + param[0].rect = (TQRect*)&r; + pdev->cmd( TQPaintDevice::PdcSetViewport, this, param ); + } + if ( testf(VxF) ) + updateXForm(); + else + setViewXForm( TRUE ); +} + + +/*! + Enables world transformations if \a enable is TRUE, or disables + world transformations if \a enable is FALSE. The world + transformation matrix is not changed. + + \sa setWorldMatrix(), setWindow(), setViewport(), setViewXForm(), + xForm() +*/ + +void TQPainter::setWorldXForm( bool enable ) +{ +#if defined(QT_CHECK_STATE) + if ( !isActive() ) + tqWarning( "TQPainter::setWorldXForm: Will be reset by begin()" ); +#endif + if ( !isActive() || enable == testf(WxF) ) + return; + setf( WxF, enable ); + if ( testf(ExtDev) && !block_ext ) { + TQPDevCmdParam param[1]; + param[0].ival = enable; + pdev->cmd( TQPaintDevice::PdcSetWXform, this, param ); + } + updateXForm(); +} + +/*! + \fn bool TQPainter::hasWorldXForm() const + + Returns TRUE if world transformation is enabled; otherwise returns + FALSE. + + \sa setWorldXForm() +*/ + +/*! + Returns the world transformation matrix. + + \sa setWorldMatrix() +*/ + +const TQWMatrix &TQPainter::worldMatrix() const +{ + return wxmat; +} + +/*! + Sets the world transformation matrix to \a m and enables world + transformation. + + If \a combine is TRUE, then \a m is combined with the current + transformation matrix, otherwise \a m replaces the current + transformation matrix. + + If \a m is the identity matrix and \a combine is FALSE, this + function calls setWorldXForm(FALSE). (The identity matrix is the + matrix where TQWMatrix::m11() and TQWMatrix::m22() are 1.0 and the + rest are 0.0.) + + World transformations are applied after the view transformations + (i.e. \link setWindow() window\endlink and \link setViewport() + viewport\endlink). + + The following functions can transform the coordinate system without using + a TQWMatrix: + \list + \i translate() + \i scale() + \i shear() + \i rotate() + \endlist + + They operate on the painter's worldMatrix() and are implemented like this: + + \code + void TQPainter::rotate( double a ) + { + TQWMatrix m; + m.rotate( a ); + setWorldMatrix( m, TRUE ); + } + \endcode + + Note that you should always use \a combine when you are drawing + into a TQPicture. Otherwise it may not be possible to replay the + picture with additional transformations. Using translate(), + scale(), etc., is safe. + + For a brief overview of coordinate transformation, see the \link + coordsys.html Coordinate System Overview. \endlink + + \sa worldMatrix() setWorldXForm() setWindow() setViewport() + setViewXForm() xForm() TQWMatrix +*/ + +void TQPainter::setWorldMatrix( const TQWMatrix &m, bool combine ) +{ + if ( !isActive() ) { +#if defined(QT_CHECK_STATE) + tqWarning( "TQPainter::setWorldMatrix: Will be reset by begin()" ); +#endif + return; + } + if ( combine ) + wxmat = m * wxmat; // combines + else + wxmat = m; // set new matrix + bool identity = wxmat.m11() == 1.0F && wxmat.m22() == 1.0F && + wxmat.m12() == 0.0F && wxmat.m21() == 0.0F && + wxmat.dx() == 0.0F && wxmat.dy() == 0.0F; + if ( testf(ExtDev) && !block_ext ) { + TQPDevCmdParam param[2]; + param[0].matrix = &m; + param[1].ival = combine; + pdev->cmd( TQPaintDevice::PdcSetWMatrix, this, param ); + } + if ( identity && pdev->devType() != TQInternal::Picture ) + setWorldXForm( FALSE ); + else if ( !testf(WxF) ) + setWorldXForm( TRUE ); + else + updateXForm(); +} + +/*! \obsolete + + We recommend using save() instead. +*/ + +void TQPainter::saveWorldMatrix() +{ + TQWMatrixStack *stack = (TQWMatrixStack *)wm_stack; + if ( stack == 0 ) { + stack = new TQPtrStack; + TQ_CHECK_PTR( stack ); + stack->setAutoDelete( TRUE ); + wm_stack = stack; + } + + stack->push( new TQWMatrix( wxmat ) ); + +} + +/*! \obsolete + We recommend using restore() instead. +*/ + +void TQPainter::restoreWorldMatrix() +{ + TQWMatrixStack *stack = (TQWMatrixStack *)wm_stack; + if ( stack == 0 || stack->isEmpty() ) { +#if defined(QT_CHECK_STATE) + tqWarning( "TQPainter::restoreWorldMatrix: Empty stack error" ); +#endif + return; + } + TQWMatrix* m = stack->pop(); + setWorldMatrix( *m ); + delete m; +} + +#endif // TQT_NO_TRANSFORMATIONS + +/*! + Translates the coordinate system by \a (dx, dy). After this call, + \a (dx, dy) is added to points. + + For example, the following code draws the same point twice: + \code + void MyWidget::paintEvent() + { + TQPainter paint( this ); + + paint.drawPoint( 0, 0 ); + + paint.translate( 100.0, 40.0 ); + paint.drawPoint( -100, -40 ); + } + \endcode + + \sa scale(), shear(), rotate(), resetXForm(), setWorldMatrix(), xForm() +*/ + +void TQPainter::translate( double dx, double dy ) +{ +#ifndef TQT_NO_TRANSFORMATIONS + TQWMatrix m; + m.translate( dx, dy ); + setWorldMatrix( m, TRUE ); +#else + xlatex += (int)dx; + xlatey += (int)dy; + setf( VxF, xlatex || xlatey ); +#endif +} + + +#ifndef TQT_NO_TRANSFORMATIONS +/*! + Scales the coordinate system by \a (sx, sy). + + \sa translate(), shear(), rotate(), resetXForm(), setWorldMatrix(), + xForm() +*/ + +void TQPainter::scale( double sx, double sy ) +{ + TQWMatrix m; + m.scale( sx, sy ); + setWorldMatrix( m, TRUE ); +} + +/*! + Shears the coordinate system by \a (sh, sv). + + \sa translate(), scale(), rotate(), resetXForm(), setWorldMatrix(), + xForm() +*/ + +void TQPainter::shear( double sh, double sv ) +{ + TQWMatrix m; + m.shear( sv, sh ); + setWorldMatrix( m, TRUE ); +} + +/*! + Rotates the coordinate system \a a degrees counterclockwise. + + \sa translate(), scale(), shear(), resetXForm(), setWorldMatrix(), + xForm() +*/ + +void TQPainter::rotate( double a ) +{ + TQWMatrix m; + m.rotate( a ); + setWorldMatrix( m, TRUE ); +} + + +/*! + Resets any transformations that were made using translate(), scale(), + shear(), rotate(), setWorldMatrix(), setViewport() and + setWindow(). + + \sa worldMatrix(), viewport(), window() +*/ + +void TQPainter::resetXForm() +{ + if ( !isActive() ) + return; + wx = wy = vx = vy = 0; // default view origins + ww = vw = pdev->metric( TQPaintDeviceMetrics::PdmWidth ); + wh = vh = pdev->metric( TQPaintDeviceMetrics::PdmHeight ); + wxmat = TQWMatrix(); + setWorldXForm( FALSE ); + setViewXForm( FALSE ); +} + +/*! + \internal + Updates an internal integer transformation matrix. +*/ + +void TQPainter::updateXForm() +{ + TQWMatrix m; + if ( testf(VxF) ) { + double scaleW = (double)vw/(double)ww; + double scaleH = (double)vh/(double)wh; + m.setMatrix( scaleW, 0, 0, scaleH, vx - wx*scaleW, vy - wy*scaleH ); + } + if ( testf(WxF) ) { + if ( testf(VxF) ) + m = wxmat * m; + else + m = wxmat; + } + xmat = m; + + txinv = FALSE; // no inverted matrix + txop = TxNone; + if ( m12()==0.0 && m21()==0.0 && m11() >= 0.0 && m22() >= 0.0 ) { + if ( m11()==1.0 && m22()==1.0 ) { + if ( dx()!=0.0 || dy()!=0.0 ) + txop = TxTranslate; + } else { + txop = TxScale; +#if defined(TQ_WS_WIN) + setf(DirtyFont); +#endif + } + } else { + txop = TxRotShear; +#if defined(TQ_WS_WIN) + setf(DirtyFont); +#endif + } +} + + +/*! + \internal + Updates an internal integer inverse transformation matrix. +*/ + +void TQPainter::updateInvXForm() +{ +#if defined(QT_CHECK_STATE) + Q_ASSERT( txinv == FALSE ); +#endif + txinv = TRUE; // creating inverted matrix + bool invertible; + TQWMatrix m; + if ( testf(VxF) ) { + m.translate( vx, vy ); + m.scale( 1.0*vw/ww, 1.0*vh/wh ); + m.translate( -wx, -wy ); + } + if ( testf(WxF) ) { + if ( testf(VxF) ) + m = wxmat * m; + else + m = wxmat; + } + ixmat = m.invert( &invertible ); // invert matrix +} + +#else +void TQPainter::resetXForm() +{ + xlatex = 0; + xlatey = 0; + clearf( VxF ); +} +#endif // TQT_NO_TRANSFORMATIONS + + +extern bool qt_old_transformations; + +/*! + \internal + Maps a point from logical coordinates to device coordinates. +*/ + +void TQPainter::map( int x, int y, int *rx, int *ry ) const +{ +#ifndef TQT_NO_TRANSFORMATIONS + if ( qt_old_transformations ) { + switch ( txop ) { + case TxNone: + *rx = x; *ry = y; + break; + case TxTranslate: + // #### "Why no rounding here?", Warwick asked of Haavard. + *rx = int(x + dx()); + *ry = int(y + dy()); + break; + case TxScale: { + double tx = m11()*x + dx(); + double ty = m22()*y + dy(); + *rx = tx >= 0 ? int(tx + 0.5) : int(tx - 0.5); + *ry = ty >= 0 ? int(ty + 0.5) : int(ty - 0.5); + } break; + default: { + double tx = m11()*x + m21()*y+dx(); + double ty = m12()*x + m22()*y+dy(); + *rx = tx >= 0 ? int(tx + 0.5) : int(tx - 0.5); + *ry = ty >= 0 ? int(ty + 0.5) : int(ty - 0.5); + } break; + } + } else { + switch ( txop ) { + case TxNone: + *rx = x; + *ry = y; + break; + case TxTranslate: + *rx = tqRound( x + dx() ); + *ry = tqRound( y + dy() ); + break; + case TxScale: + *rx = tqRound( m11()*x + dx() ); + *ry = tqRound( m22()*y + dy() ); + break; + default: + *rx = tqRound( m11()*x + m21()*y+dx() ); + *ry = tqRound( m12()*x + m22()*y+dy() ); + break; + } + } +#else + *rx = x + xlatex; + *ry = y + xlatey; +#endif +} + +/*! + \internal + Maps a rectangle from logical coordinates to device coordinates. + This internal function does not handle rotation and/or shear. +*/ + +void TQPainter::map( int x, int y, int w, int h, + int *rx, int *ry, int *rw, int *rh ) const +{ +#ifndef TQT_NO_TRANSFORMATIONS + if ( qt_old_transformations ) { + switch ( txop ) { + case TxNone: + *rx = x; *ry = y; + *rw = w; *rh = h; + break; + case TxTranslate: + // #### "Why no rounding here?", Warwick asked of Haavard. + *rx = int(x + dx()); + *ry = int(y + dy()); + *rw = w; *rh = h; + break; + case TxScale: { + double tx1 = m11()*x + dx(); + double ty1 = m22()*y + dy(); + double tx2 = m11()*(x + w - 1) + dx(); + double ty2 = m22()*(y + h - 1) + dy(); + *rx = tqRound( tx1 ); + *ry = tqRound( ty1 ); + *rw = tqRound( tx2 ) - *rx + 1; + *rh = tqRound( ty2 ) - *ry + 1; + } break; + default: +#if defined(QT_CHECK_STATE) + tqWarning( "TQPainter::map: Internal error" ); +#endif + break; + } + } else { + switch ( txop ) { + case TxNone: + *rx = x; *ry = y; + *rw = w; *rh = h; + break; + case TxTranslate: + *rx = tqRound(x + dx() ); + *ry = tqRound(y + dy() ); + *rw = w; *rh = h; + break; + case TxScale: + *rx = tqRound( m11()*x + dx() ); + *ry = tqRound( m22()*y + dy() ); + *rw = tqRound( m11()*w ); + *rh = tqRound( m22()*h ); + break; + default: +#if defined(QT_CHECK_STATE) + tqWarning( "TQPainter::map: Internal error" ); +#endif + break; + } + } +#else + *rx = x + xlatex; + *ry = y + xlatey; + *rw = w; *rh = h; +#endif +} + +/*! + \internal + Maps a point from device coordinates to logical coordinates. +*/ + +void TQPainter::mapInv( int x, int y, int *rx, int *ry ) const +{ +#ifndef TQT_NO_TRANSFORMATIONS +#if defined(QT_CHECK_STATE) + if ( !txinv ) + tqWarning( "TQPainter::mapInv: Internal error" ); +#endif + if ( qt_old_transformations ) { + double tx = im11()*x + im21()*y+idx(); + double ty = im12()*x + im22()*y+idy(); + *rx = tx >= 0 ? int(tx + 0.5) : int(tx - 0.5); + *ry = ty >= 0 ? int(ty + 0.5) : int(ty - 0.5); + } else { + *rx = tqRound( im11()*x + im21()*y + idx() ); + *ry = tqRound( im12()*x + im22()*y + idy() ); + } +#else + *rx = x - xlatex; + *ry = y - xlatey; +#endif +} + +/*! + \internal + Maps a rectangle from device coordinates to logical coordinates. + Cannot handle rotation and/or shear. +*/ + +void TQPainter::mapInv( int x, int y, int w, int h, + int *rx, int *ry, int *rw, int *rh ) const +{ +#ifndef TQT_NO_TRANSFORMATIONS +#if defined(QT_CHECK_STATE) + if ( !txinv || txop == TxRotShear ) + tqWarning( "TQPainter::mapInv: Internal error" ); +#endif + if ( qt_old_transformations ) { + double tx = im11()*x + idx(); + double ty = im22()*y + idy(); + double tw = im11()*w; + double th = im22()*h; + *rx = tx >= 0 ? int(tx + 0.5) : int(tx - 0.5); + *ry = ty >= 0 ? int(ty + 0.5) : int(ty - 0.5); + *rw = tw >= 0 ? int(tw + 0.5) : int(tw - 0.5); + *rh = th >= 0 ? int(th + 0.5) : int(th - 0.5); + } else { + *rx = tqRound( im11()*x + idx() ); + *ry = tqRound( im22()*y + idy() ); + *rw = tqRound( im11()*w ); + *rh = tqRound( im22()*h ); + } +#else + *rx = x - xlatex; + *ry = y - xlatey; + *rw = w; + *rh = h; +#endif +} + + +/*! + Returns the point \a pv transformed from model coordinates to + device coordinates. + + \sa xFormDev(), TQWMatrix::map() +*/ + +TQPoint TQPainter::xForm( const TQPoint &pv ) const +{ +#ifndef TQT_NO_TRANSFORMATIONS + if ( txop == TxNone ) + return pv; + int x=pv.x(), y=pv.y(); + map( x, y, &x, &y ); + return TQPoint( x, y ); +#else + return TQPoint( pv.x()+xlatex, pv.y()+xlatey ); +#endif +} + +/*! + \overload + + Returns the rectangle \a rv transformed from model coordinates to + device coordinates. + + If world transformation is enabled and rotation or shearing has + been specified, then the bounding rectangle is returned. + + \sa xFormDev(), TQWMatrix::map() +*/ + +TQRect TQPainter::xForm( const TQRect &rv ) const +{ +#ifndef TQT_NO_TRANSFORMATIONS + if ( txop == TxNone ) + return rv; + if ( txop == TxRotShear ) { // rotation/shear + return xmat.mapRect( rv ); + } + // Just translation/scale + int x, y, w, h; + rv.rect( &x, &y, &w, &h ); + map( x, y, w, h, &x, &y, &w, &h ); + return TQRect( x, y, w, h ); +#else + return TQRect( rv.x()+xlatex, rv.y()+xlatey, rv.width(), rv.height() ); +#endif +} + +/*! + \overload + + Returns the point array \a av transformed from model coordinates + to device coordinates. + + \sa xFormDev(), TQWMatrix::map() +*/ + +TQPointArray TQPainter::xForm( const TQPointArray &av ) const +{ + TQPointArray a = av; +#ifndef TQT_NO_TRANSFORMATIONS + if ( txop != TxNone ) + { + return xmat * av; + } +#else + a.translate( xlatex, xlatey ); +#endif + return a; +} + +/*! + \overload + + Returns the point array \a av transformed from model coordinates + to device coordinates. The \a index is the first point in the + array and \a npoints denotes the number of points to be + transformed. If \a npoints is negative, all points from \a + av[index] until the last point in the array are transformed. + + The returned point array consists of the number of points that + were transformed. + + Example: + \code + TQPointArray a(10); + TQPointArray b; + b = painter.xForm(a, 2, 4); // b.size() == 4 + b = painter.xForm(a, 2, -1); // b.size() == 8 + \endcode + + \sa xFormDev(), TQWMatrix::map() +*/ + +TQPointArray TQPainter::xForm( const TQPointArray &av, int index, + int npoints ) const +{ + int lastPoint = npoints < 0 ? av.size() : index+npoints; + TQPointArray a( lastPoint-index ); + memcpy( a.data(), av.data()+index, (lastPoint-index)*sizeof( TQPoint ) ); +#ifndef TQT_NO_TRANSFORMATIONS + return xmat*a; +#else + a.translate( xlatex, xlatey ); + return a; +#endif +} + +/*! + \overload + + Returns the point \a pd transformed from device coordinates to + model coordinates. + + \sa xForm(), TQWMatrix::map() +*/ + +TQPoint TQPainter::xFormDev( const TQPoint &pd ) const +{ +#ifndef TQT_NO_TRANSFORMATIONS + if ( txop == TxNone ) + return pd; + if ( !txinv ) { + TQPainter *that = (TQPainter*)this; // mutable + that->updateInvXForm(); + } +#endif + int x=pd.x(), y=pd.y(); + mapInv( x, y, &x, &y ); + return TQPoint( x, y ); +} + +/*! + Returns the rectangle \a rd transformed from device coordinates to + model coordinates. + + If world transformation is enabled and rotation or shearing is + used, then the bounding rectangle is returned. + + \sa xForm(), TQWMatrix::map() +*/ + +TQRect TQPainter::xFormDev( const TQRect &rd ) const +{ +#ifndef TQT_NO_TRANSFORMATIONS + if ( txop == TxNone ) + return rd; + if ( !txinv ) { + TQPainter *that = (TQPainter*)this; // mutable + that->updateInvXForm(); + } + if ( txop == TxRotShear ) { // rotation/shear + return ixmat.mapRect( rd ); + } +#endif + // Just translation/scale + int x, y, w, h; + rd.rect( &x, &y, &w, &h ); + mapInv( x, y, w, h, &x, &y, &w, &h ); + return TQRect( x, y, w, h ); +} + +/*! + \overload + + Returns the point array \a ad transformed from device coordinates + to model coordinates. + + \sa xForm(), TQWMatrix::map() +*/ + +TQPointArray TQPainter::xFormDev( const TQPointArray &ad ) const +{ +#ifndef TQT_NO_TRANSFORMATIONS + if ( txop == TxNone ) + return ad; + if ( !txinv ) { + TQPainter *that = (TQPainter*)this; // mutable + that->updateInvXForm(); + } + return ixmat * ad; +#else + // ### + return ad; +#endif +} + +/*! + \overload + + Returns the point array \a ad transformed from device coordinates + to model coordinates. The \a index is the first point in the array + and \a npoints denotes the number of points to be transformed. If + \a npoints is negative, all points from \a ad[index] until the + last point in the array are transformed. + + The returned point array consists of the number of points that + were transformed. + + Example: + \code + TQPointArray a(10); + TQPointArray b; + b = painter.xFormDev(a, 1, 3); // b.size() == 3 + b = painter.xFormDev(a, 1, -1); // b.size() == 9 + \endcode + + \sa xForm(), TQWMatrix::map() +*/ + +TQPointArray TQPainter::xFormDev( const TQPointArray &ad, int index, + int npoints ) const +{ + int lastPoint = npoints < 0 ? ad.size() : index+npoints; + TQPointArray a( lastPoint-index ); + memcpy( a.data(), ad.data()+index, (lastPoint-index)*sizeof( TQPoint ) ); +#ifndef TQT_NO_TRANSFORMATIONS + if ( txop == TxNone ) + return a; + if ( !txinv ) { + TQPainter *that = (TQPainter*)this; // mutable + that->updateInvXForm(); + } + return ixmat * a; +#else + // ### + return a; +#endif +} + + +/*! + Fills the rectangle \a (x, y, w, h) with the \a brush. + + You can specify a TQColor as \a brush, since there is a TQBrush + constructor that takes a TQColor argument and creates a solid + pattern brush. + + \sa drawRect() +*/ + +void TQPainter::fillRect( int x, int y, int w, int h, const TQBrush &brush ) +{ + TQPen oldPen = pen(); // save pen + TQBrush oldBrush = this->brush(); // save brush + setPen( NoPen ); + setBrush( brush ); + drawRect( x, y, w, h ); // draw filled rect + setBrush( oldBrush ); // restore brush + setPen( oldPen ); // restore pen +} + + +/*! + \overload void TQPainter::setBrushOrigin( const TQPoint &p ) + + Sets the brush origin to point \a p. +*/ + +/*! + \overload void TQPainter::setWindow( const TQRect &r ) + + Sets the painter's window to rectangle \a r. +*/ + + +/*! + \overload void TQPainter::setViewport( const TQRect &r ) + + Sets the painter's viewport to rectangle \a r. +*/ + + +/*! + \fn bool TQPainter::hasClipping() const + + Returns TRUE if clipping has been set; otherwise returns FALSE. + + \sa setClipping() +*/ + +/*! + Returns the currently set clip region. Note that the clip region + is given in physical device coordinates and \e not subject to any + \link coordsys.html coordinate transformation \endlink if \a m is + equal to \c CoordDevice (the default). If \a m equals \c + CoordPainter the returned region is in model coordinates. + + \sa setClipRegion(), setClipRect(), setClipping() TQPainter::CoordinateMode +*/ +TQRegion TQPainter::clipRegion( CoordinateMode m ) const +{ + // ### FIXME in 4.0: + // If the transformation mode is CoordPainter, we should transform the + // clip region with painter transformations. + +#ifndef TQT_NO_TRANSFORMATIONS + TQRegion r; + if ( m == CoordDevice ) { + r = crgn; + } else { + if ( !txinv ) { + TQPainter *that = (TQPainter*)this; // mutable + that->updateInvXForm(); + } + + r = ixmat * crgn; + } + return r; +#else + return crgn; +#endif +} + +/*! + \fn void TQPainter::setClipRect( int x, int y, int w, int h, CoordinateMode m) + + Sets the clip region to the rectangle \a x, \a y, \a w, \a h and + enables clipping. The clip mode is set to \a m. + + If \a m is \c CoordDevice (the default), the coordinates given for + the clip region are taken to be physical device coordinates and + are \e not subject to any \link coordsys.html coordinate + transformations\endlink. If \a m is \c CoordPainter, the + coordinates given for the clip region are taken to be model + coordinates. + + \sa setClipRegion(), clipRegion(), setClipping() TQPainter::CoordinateMode +*/ + +/*! + \overload void TQPainter::drawPoint( const TQPoint &p ) + + Draws the point \a p. +*/ + + +/*! + \overload void TQPainter::moveTo( const TQPoint &p ) + + Moves to the point \a p. +*/ + +/*! + \overload void TQPainter::lineTo( const TQPoint &p ) + + Draws a line to the point \a p. +*/ + +/*! + \overload void TQPainter::drawLine( const TQPoint &p1, const TQPoint &p2 ) + + Draws a line from point \a p1 to point \a p2. +*/ + +/*! + \overload void TQPainter::drawRect( const TQRect &r ) + + Draws the rectangle \a r. +*/ + +/*! + \overload void TQPainter::drawWinFocusRect( const TQRect &r ) + + Draws rectangle \a r as a window focus rectangle. +*/ + +/*! + \overload void TQPainter::drawWinFocusRect( const TQRect &r, const TQColor &bgColor ) + + Draws rectangle \a r as a window focus rectangle using background + color \a bgColor. +*/ + + +#if !defined(TQ_WS_X11) && !defined(TQ_WS_MAC) +// The doc and X implementation of this functions is in tqpainter_x11.cpp +void TQPainter::drawWinFocusRect( int, int, int, int, + bool, const TQColor & ) +{ + // do nothing, only called from X11 specific functions +} +#endif + + +/*! + \overload void TQPainter::drawRoundRect( const TQRect &r, int xRnd, int yRnd ) + + Draws a rounded rectangle \a r, rounding to the x position \a xRnd + and the y position \a yRnd on each corner. +*/ + +/*! + \overload void TQPainter::drawEllipse( const TQRect &r ) + + Draws the ellipse that fits inside rectangle \a r. +*/ + +/*! + \overload void TQPainter::drawArc( const TQRect &r, int a, int alen ) + + Draws the arc that fits inside the rectangle \a r with start angle + \a a and arc length \a alen. +*/ + +/*! + \overload void TQPainter::drawPie( const TQRect &r, int a, int alen ) + + Draws a pie segment that fits inside the rectangle \a r with start + angle \a a and arc length \a alen. +*/ + +/*! + \overload void TQPainter::drawChord( const TQRect &r, int a, int alen ) + + Draws a chord that fits inside the rectangle \a r with start angle + \a a and arc length \a alen. +*/ + +/*! + \overload void TQPainter::drawPixmap( const TQPoint &p, const TQPixmap &pm, const TQRect &sr ) + + Draws the rectangle \a sr of pixmap \a pm with its origin at point + \a p. +*/ + +/*! + \overload void TQPainter::drawPixmap( const TQPoint &p, const TQPixmap &pm ) + + Draws the pixmap \a pm with its origin at point \a p. +*/ + +void TQPainter::drawPixmap( const TQPoint &p, const TQPixmap &pm ) +{ + drawPixmap( p.x(), p.y(), pm, 0, 0, pm.width(), pm.height() ); +} + +#if !defined(TQT_NO_IMAGE_SMOOTHSCALE) || !defined(TQT_NO_PIXMAP_TRANSFORMATION) + +/*! + \overload + + Draws the pixmap \a pm into the rectangle \a r. The pixmap is + scaled to fit the rectangle, if image and rectangle size disagree. +*/ +void TQPainter::drawPixmap( const TQRect &r, const TQPixmap &pm ) +{ + int rw = r.width(); + int rh = r.height(); + int iw= pm.width(); + int ih = pm.height(); + if ( rw <= 0 || rh <= 0 || iw <= 0 || ih <= 0 ) + return; + bool scale = ( rw != iw || rh != ih ); + float scaleX = (float)rw/(float)iw; + float scaleY = (float)rh/(float)ih; + bool smooth = ( scaleX < 1.5 || scaleY < 1.5 ); + + if ( testf(ExtDev) ) { + TQPDevCmdParam param[2]; + param[0].rect = &r; + param[1].pixmap = ± +#if defined(TQ_WS_WIN) + if ( !pdev->cmd( TQPaintDevice::PdcDrawPixmap, this, param ) || !hdc ) + return; +#elif defined(TQ_WS_MAC) + if ( !pdev->cmd( TQPaintDevice::PdcDrawPixmap, this, param ) || !pdev->handle()) + return; +#else + if ( !pdev->cmd( TQPaintDevice::PdcDrawPixmap, this, param ) || !hd ) + return; +#endif + } + + TQPixmap pixmap = pm; + + if ( scale ) { +#ifndef TQT_NO_IMAGE_SMOOTHSCALE +# ifndef TQT_NO_PIXMAP_TRANSFORMATION + if ( smooth ) +# endif + { + TQImage i = pm.convertToImage(); + pixmap = TQPixmap( i.smoothScale( rw, rh ) ); + } +# ifndef TQT_NO_PIXMAP_TRANSFORMATION + else +# endif +#endif +#ifndef TQT_NO_PIXMAP_TRANSFORMATION + { + pixmap = pm.xForm( TQWMatrix( scaleX, 0, 0, scaleY, 0, 0 ) ); + } +#endif + } + drawPixmap( r.x(), r.y(), pixmap ); +} + +#endif + +/*! + \overload void TQPainter::drawImage( const TQPoint &, const TQImage &, const TQRect &sr, int conversionFlags = 0 ); + + Draws the rectangle \a sr from the image at the given point. +*/ + +/* + Draws at point \a p the \sr rect from image \a pm, using \a + conversionFlags if the image needs to be converted to a pixmap. + The default value for \a conversionFlags is 0; see + convertFromImage() for information about what other values do. + + This function may convert \a image to a pixmap and then draw it, if + device() is a TQPixmap or a TQWidget, or else draw it directly, if + device() is a TQPrinter or TQPicture. +*/ + +/*! + Draws at (\a x, \a y) the \a sw by \a sh area of pixels from (\a + sx, \a sy) in \a image, using \a conversionFlags if the image + needs to be converted to a pixmap. The default value for \a + conversionFlags is 0; see convertFromImage() for information about + what other values do. + + This function may convert \a image to a pixmap and then draw it, + if device() is a TQPixmap or a TQWidget, or else draw it directly, + if device() is a TQPrinter or TQPicture. + + Currently alpha masks of the image are ignored when painting on a TQPrinter. + + \sa drawPixmap() TQPixmap::convertFromImage() +*/ +void TQPainter::drawImage( int x, int y, const TQImage & image, + int sx, int sy, int sw, int sh, + int conversionFlags ) +{ + if ( !isActive() || image.isNull() ) + return; + + // right/bottom + if ( sw < 0 ) + sw = image.width() - sx; + if ( sh < 0 ) + sh = image.height() - sy; + + // Sanity-check clipping + if ( sx < 0 ) { + x -= sx; + sw += sx; + sx = 0; + } + if ( sw + sx > image.width() ) + sw = image.width() - sx; + if ( sy < 0 ) { + y -= sy; + sh += sy; + sy = 0; + } + if ( sh + sy > image.height() ) + sh = image.height() - sy; + + if ( sw <= 0 || sh <= 0 ) + return; + + bool all = image.rect().intersect(TQRect(sx,sy,sw,sh)) == image.rect(); + TQImage subimage = all ? image : image.copy(sx,sy,sw,sh); + + if ( testf(ExtDev) ) { + TQPDevCmdParam param[2]; + TQRect r( x, y, subimage.width(), subimage.height() ); + param[0].rect = &r; + param[1].image = &subimage; +#if defined(TQ_WS_WIN) + if ( !pdev->cmd( TQPaintDevice::PdcDrawImage, this, param ) || !hdc ) + return; +#elif defined(TQ_WS_MAC) + if(!pdev->cmd( TQPaintDevice::PdcDrawImage, this, param ) || !pdev->handle() ) + return; +#else + if ( !pdev->cmd( TQPaintDevice::PdcDrawImage, this, param ) || !hd ) + return; +#endif + } + + TQPixmap pm; + pm.convertFromImage( subimage, conversionFlags ); + drawPixmap( x, y, pm ); +} + +/*! + \overload void TQPainter::drawImage( const TQPoint &p, const TQImage &i, int conversion_flags ) + + Draws the image \a i at point \a p. + + If the image needs to be modified to fit in a lower-resolution + result (e.g. converting from 32-bit to 8-bit), use the \a + conversion_flags to specify how you'd prefer this to happen. + + \sa TQt::ImageConversionFlags +*/ +void TQPainter::drawImage( const TQPoint & p, const TQImage & i, + int conversion_flags ) +{ + drawImage(p, i, i.rect(), conversion_flags); +} + +#if !defined(TQT_NO_IMAGE_TRANSFORMATION) || !defined(TQT_NO_IMAGE_SMOOTHSCALE) + +/*! + \overload + + Draws the image \a i into the rectangle \a r. The image will be + scaled to fit the rectangle if image and rectangle dimensions + differ. +*/ +void TQPainter::drawImage( const TQRect &r, const TQImage &i ) +{ + int rw = r.width(); + int rh = r.height(); + int iw= i.width(); + int ih = i.height(); + if ( rw <= 0 || rh <= 0 || iw <= 0 || ih <= 0 ) + return; + + if ( testf(ExtDev) ) { + TQPDevCmdParam param[2]; + param[0].rect = &r; + param[1].image = &i; +#if defined(TQ_WS_WIN) + if ( !pdev->cmd( TQPaintDevice::PdcDrawImage, this, param ) || !hdc ) + return; +#elif defined(TQ_WS_MAC) + if ( !pdev->cmd( TQPaintDevice::PdcDrawImage, this, param ) || !pdev->handle() ) + return; +#else + if ( !pdev->cmd( TQPaintDevice::PdcDrawImage, this, param ) || !hd ) + return; +#endif + } + + + bool scale = ( rw != iw || rh != ih ); + float scaleX = (float)rw/(float)iw; + float scaleY = (float)rh/(float)ih; + bool smooth = ( scaleX < 1.5 || scaleY < 1.5 ); + + TQImage img = scale + ? ( +#if defined(TQT_NO_IMAGE_TRANSFORMATION) + i.smoothScale( rw, rh ) +#elif defined(TQT_NO_IMAGE_SMOOTHSCALE) + i.scale( rw, rh ) +#else + smooth ? i.smoothScale( rw, rh ) : i.scale( rw, rh ) +#endif + ) + : i; + + drawImage( r.x(), r.y(), img ); +} + +#endif + + +void bitBlt( TQPaintDevice *dst, int dx, int dy, + const TQImage *src, int sx, int sy, int sw, int sh, + int conversion_flags ) +{ + TQPixmap tmp; + if ( sx == 0 && sy == 0 + && (sw<0 || sw==src->width()) && (sh<0 || sh==src->height()) ) + { + tmp.convertFromImage( *src, conversion_flags ); + } else { + tmp.convertFromImage( src->copy( sx, sy, sw, sh, conversion_flags), + conversion_flags ); + } + bitBlt( dst, dx, dy, &tmp ); +} + + +/*! + \overload void TQPainter::drawTiledPixmap( const TQRect &r, const TQPixmap &pm, const TQPoint &sp ) + + Draws a tiled pixmap, \a pm, inside rectangle \a r with its origin + at point \a sp. +*/ + +/*! + \overload void TQPainter::drawTiledPixmap( const TQRect &r, const TQPixmap &pm ) + + Draws a tiled pixmap, \a pm, inside rectangle \a r. +*/ + +/*! + \overload void TQPainter::fillRect( const TQRect &r, const TQBrush &brush ) + + Fills the rectangle \a r using brush \a brush. +*/ + +/*! + \fn void TQPainter::eraseRect( int x, int y, int w, int h ) + + Erases the area inside \a x, \a y, \a w, \a h. Equivalent to + \c{fillRect( x, y, w, h, backgroundColor() )}. +*/ + +/*! + \overload void TQPainter::eraseRect( const TQRect &r ) + + Erases the area inside the rectangle \a r. +*/ + +/*! + \fn TQPainter::drawText( int x, int y, const TQString &, int len = -1, TextDirection dir = Auto ) + + \overload + + Draws the given text at position \a x, \a y. If \a len is -1 (the + default) all the text is drawn, otherwise the first \a len + characters are drawn. The text's direction is given by \a dir. + + \sa TQPainter::TextDirection +*/ + +/*! + \fn void TQPainter::drawText( int x, int y, int w, int h, int flags, + const TQString&, int len = -1, TQRect *br=0, + TQTextParag **internal=0 ) + + \overload + + Draws the given text within the rectangle starting at \a x, \a y, + with width \a w and height \a h. If \a len is -1 (the default) all + the text is drawn, otherwise the first \a len characters are + drawn. The text's flags that are given in the \a flags parameter + are \l{TQt::AlignmentFlags} and \l{TQt::TextFlags} OR'd together. \a + br (if not null) is set to the actual bounding rectangle of the + output. The \a internal parameter is for internal use only. +*/ + +/*! + \fn void TQPainter::drawText( const TQPoint &, const TQString &, int len = -1, TextDirection dir = Auto ); + + \overload + + Draws the text at the given point. + + \sa TQPainter::TextDirection +*/ + +/* + Draws the text in \a s at point \a p. If \a len is -1 the entire + string is drawn, otherwise just the first \a len characters. The + text's direction is specified by \a dir. +*/ + + +/*! + \fn void TQPainter::drawText( int x, int y, const TQString &, int pos, int len, TextDirection dir = Auto ); + + \overload + + Draws the text from position \a pos, at point \a (x, y). If \a len is + -1 the entire string is drawn, otherwise just the first \a len + characters. The text's direction is specified by \a dir. +*/ + +/*! + \fn void TQPainter::drawText( const TQPoint &p, const TQString &, int pos, int len, TextDirection dir = Auto ); + + Draws the text from position \a pos, at point \a p. If \a len is + -1 the entire string is drawn, otherwise just the first \a len + characters. The text's direction is specified by \a dir. + + Note that the meaning of \e y is not the same for the two + drawText() varieties. For overloads that take a simple \e x, \e y + pair (or a point), the \e y value is the text's baseline; for + overloads that take a rectangle, \e rect.y() is the top of the + rectangle and the text is aligned within that rectangle in + accordance with the alignment flags. + + \sa TQPainter::TextDirection +*/ + +/*! + \fn void TQPainter::drawTextItem(const TQPoint &, const TQTextItem &, int) + \internal +*/ + +static inline void fix_neg_rect( int *x, int *y, int *w, int *h ) +{ + if ( *w < 0 ) { + *w = -*w + 2; + *x -= *w - 1; + } + if ( *h < 0 ) { + *h = -*h + 2; + *y -= *h - 1; + } +} +void TQPainter::fix_neg_rect( int *x, int *y, int *w, int *h ) +{ + ::fix_neg_rect(x,y,w,h); +} + +// +// The drawText function takes two special parameters; 'internal' and 'brect'. +// +// The 'internal' parameter contains a pointer to an array of encoded +// information that keeps internal geometry data. +// If the drawText function is called repeatedly to display the same text, +// it makes sense to calculate text width and linebreaks the first time, +// and use these parameters later to print the text because we save a lot of +// CPU time. +// The 'internal' parameter will not be used if it is a null pointer. +// The 'internal' parameter will be generated if it is not null, but points +// to a null pointer, i.e. internal != 0 && *internal == 0. +// The 'internal' parameter will be used if it contains a non-null pointer. +// +// If the 'brect parameter is a non-null pointer, then the bounding rectangle +// of the text will be returned in 'brect'. +// + +/*! + \overload + + Draws at most \a len characters from \a str in the rectangle \a r. + + This function draws formatted text. The \a tf text format is + really of type \l TQt::AlignmentFlags and \l TQt::TextFlags OR'd + together. + + Horizontal alignment defaults to AlignAuto and vertical alignment + defaults to AlignTop. + + \a brect (if not null) is set to the actual bounding rectangle of + the output. \a internal is, yes, internal. + + \sa boundingRect() +*/ + +void TQPainter::drawText( const TQRect &r, int tf, + const TQString& str, int len, TQRect *brect, + TQTextParag **internal ) +{ + if ( !isActive() ) + return; + if ( len < 0 ) + len = str.length(); + if ( len == 0 ) // empty string + return; + + if ( testf(DirtyFont|ExtDev) ) { + if ( testf(DirtyFont) ) + updateFont(); + if ( testf(ExtDev) && (tf & DontPrint) == 0 ) { + TQPDevCmdParam param[3]; + TQString newstr = str; + newstr.truncate( len ); + param[0].rect = &r; + param[1].ival = tf; + param[2].str = &newstr; + if ( pdev->devType() != TQInternal::Printer ) { +#if defined(TQ_WS_WIN) + if ( !pdev->cmd( TQPaintDevice::PdcDrawText2Formatted, + this, param) || + !hdc ) + return; // TQPrinter wants PdcDrawText2 +#elif defined(TQ_WS_MAC) + if ( !pdev->cmd( TQPaintDevice::PdcDrawText2Formatted, this, param) || + !pdev->handle()) + return; // TQPrinter wants PdcDrawText2 +#else + if ( !pdev->cmd( TQPaintDevice::PdcDrawText2Formatted, + this, param) || + !hd ) + return; // TQPrinter wants PdcDrawText2 +#endif + } + } + } + + qt_format_text(font(), r, tf, str, len, brect, + tabstops, tabarray, tabarraylen, internal, this); +} + +//#define QT_FORMAT_TEXT_DEBUG + +#define TQChar_linesep TQChar(0x2028U) + +void qt_format_text( const TQFont& font, const TQRect &_r, + int tf, const TQString& str, int len, TQRect *brect, + int tabstops, int* tabarray, int tabarraylen, + TQTextParag **, TQPainter* painter ) +{ + // we need to copy r here to protect against the case (&r == brect). + TQRect r( _r ); + + bool dontclip = (tf & TQt::DontClip) == TQt::DontClip; + bool wordbreak = (tf & TQt::WordBreak) == TQt::WordBreak; + bool singleline = (tf & TQt::SingleLine) == TQt::SingleLine; + bool showprefix = (tf & TQt::ShowPrefix) == TQt::ShowPrefix; + bool noaccel = ( tf & TQt::NoAccel ) == TQt::NoAccel; + + bool isRightToLeft = str.isRightToLeft(); + if ( ( tf & TQt::AlignHorizontal_Mask ) == TQt::AlignAuto ) + tf |= isRightToLeft ? TQt::AlignRight : TQt::AlignLeft; + + bool expandtabs = ( (tf & TQt::ExpandTabs) && + ( ( (tf & TQt::AlignLeft) && !isRightToLeft ) || + ( (tf & TQt::AlignRight) && isRightToLeft ) ) ); + + if ( !painter ) + tf |= TQt::DontPrint; + + int maxUnderlines = 0; + int numUnderlines = 0; + int underlinePositionStack[32]; + int *underlinePositions = underlinePositionStack; + + TQFont fnt(painter ? (painter->pfont ? *painter->pfont : painter->cfont) : font); + TQFontMetrics fm( fnt ); + + TQString text = str; + // str.setLength() always does a deep copy, so the replacement + // code below is safe. + text.setLength( len ); + // compatible behaviour to the old implementation. Replace + // tabs by spaces + TQChar *chr = (TQChar*)text.unicode(); + const TQChar *end = chr + len; + bool haveLineSep = FALSE; + while ( chr != end ) { + if ( *chr == '\r' || ( singleline && *chr == '\n' ) ) { + *chr = ' '; + } else if ( *chr == '\n' ) { + *chr = TQChar_linesep; + haveLineSep = TRUE; + } else if ( *chr == '&' ) { + ++maxUnderlines; + } + ++chr; + } + if ( !expandtabs ) { + chr = (TQChar*)text.unicode(); + while ( chr != end ) { + if ( *chr == '\t' ) + *chr = ' '; + ++chr; + } + } else if (!tabarraylen && !tabstops) { + tabstops = fm.width('x')*8; + } + + if ( noaccel || showprefix ) { + if ( maxUnderlines > 32 ) + underlinePositions = new int[maxUnderlines]; + TQChar *cout = (TQChar*)text.unicode(); + TQChar *cin = cout; + int l = len; + while ( l ) { + if ( *cin == '&' ) { + ++cin; + --l; + if ( !l ) + break; + if ( *cin != '&' ) + underlinePositions[numUnderlines++] = cout - text.unicode(); + } + *cout = *cin; + ++cout; + ++cin; + --l; + } + uint newlen = cout - text.unicode(); + if ( newlen != text.length()) + text.setLength( newlen ); + } + + // no need to do extra work for underlines if we don't paint + if ( tf & TQt::DontPrint ) + numUnderlines = 0; + + int height = 0; + int left = r.width(); + int right = 0; + + TQTextLayout textLayout( text, fnt ); + int rb = TQMAX( 0, -fm.minRightBearing() ); + int lb = TQMAX( 0, -fm.minLeftBearing() ); + + if ( text.isEmpty() ) { + height = fm.height(); + left = right = 0; + tf |= TQPainter::DontPrint; + } else { + textLayout.beginLayout((haveLineSep || expandtabs || wordbreak) ? + TQTextLayout::MultiLine : + (tf & TQt::DontPrint) ? TQTextLayout::NoBidi : TQTextLayout::SingleLine ); + + // break underline chars into items of their own + for( int i = 0; i < numUnderlines; i++ ) { + textLayout.setBoundary( underlinePositions[i] ); + textLayout.setBoundary( underlinePositions[i]+1 ); + } + + int lineWidth = wordbreak ? TQMAX(0, r.width()-rb-lb) : INT_MAX; + if(!wordbreak) + tf |= TQt::IncludeTrailingSpaces; + + int leading = fm.leading(); + int asc = fm.ascent(); + int desc = fm.descent(); + height = -leading; + + //tqDebug("\n\nbeginLayout: lw = %d, rectwidth=%d", lineWidth , r.width()); + while ( !textLayout.atEnd() ) { + height += leading; + textLayout.beginLine( lineWidth == INT_MAX ? lineWidth : lineWidth ); + //tqDebug("-----beginLine( %d )-----", lineWidth ); + bool linesep = FALSE; + while ( 1 ) { + TQTextItem ti = textLayout.currentItem(); + //tqDebug("item: from=%d, ch=%x", ti.from(), text.unicode()[ti.from()].unicode() ); + if ( expandtabs && ti.isTab() ) { + int tw = 0; + int x = textLayout.widthUsed(); + if ( tabarraylen ) { +// tqDebug("tabarraylen=%d", tabarraylen ); + int tab = 0; + while ( tab < tabarraylen ) { + if ( tabarray[tab] > x ) { + tw = tabarray[tab] - x; + break; + } + ++tab; + } + } else { + tw = tabstops - (x % tabstops); + } + //tqDebug("tw = %d", tw ); + if ( tw ) + ti.setWidth( tw ); + } + if ( ti.isObject() && text.unicode()[ti.from()] == TQChar_linesep ) + linesep = TRUE; + + if ( linesep || textLayout.addCurrentItem() != TQTextLayout::Ok || textLayout.atEnd() ) + break; + } + + int ascent = asc, descent = desc, lineLeft, lineRight; + textLayout.setLineWidth( r.width()-rb-lb ); + textLayout.endLine( 0, height, tf, &ascent, &descent, + &lineLeft, &lineRight ); + //tqDebug("finalizing line: lw=%d ascent = %d, descent=%d lineleft=%d lineright=%d", lineWidth, ascent, descent,lineLeft, lineRight ); + left = TQMIN( left, lineLeft ); + right = TQMAX( right, lineRight ); + height += ascent + descent + 1; + if ( linesep ) + textLayout.nextItem(); + } + } + + int yoff = 0; + if ( tf & TQt::AlignBottom ) + yoff = r.height() - height; + else if ( tf & TQt::AlignVCenter ) + yoff = (r.height() - height)/2; + + if ( brect ) { + *brect = TQRect( r.x() + left, r.y() + yoff, right-left + lb+rb, height ); + //tqDebug("br = %d %d %d/%d, left=%d, right=%d", brect->x(), brect->y(), brect->width(), brect->height(), left, right); + } + + if (!(tf & TQPainter::DontPrint)) { + bool restoreClipping = FALSE; + bool painterHasClip = FALSE; + TQRegion painterClipRegion; + if ( !dontclip ) { +#ifndef TQT_NO_TRANSFORMATIONS + TQRegion reg = painter->xmat * r; +#else + TQRegion reg = r; + reg.translate( painter->xlatex, painter->xlatey ); +#endif + if ( painter->hasClipping() ) + reg &= painter->clipRegion(); + + painterHasClip = painter->hasClipping(); + painterClipRegion = painter->clipRegion(); + restoreClipping = TRUE; + painter->setClipRegion( reg ); + } else { + if ( painter->hasClipping() ){ + painterHasClip = painter->hasClipping(); + painterClipRegion = painter->clipRegion(); + restoreClipping = TRUE; + painter->setClipping( FALSE ); + } + } + + int cUlChar = 0; + int _tf = 0; + if (fnt.underline()) _tf |= TQt::Underline; + if (fnt.overline()) _tf |= TQt::Overline; + if (fnt.strikeOut()) _tf |= TQt::StrikeOut; + + //tqDebug("have %d items",textLayout.numItems()); + for ( int i = 0; i < textLayout.numItems(); i++ ) { + TQTextItem ti = textLayout.itemAt( i ); + //tqDebug("Item %d: from=%d, length=%d, space=%d x=%d", i, ti.from(), ti.length(), ti.isSpace(), ti.x() ); + if ( ti.isTab() || ti.isObject() ) + continue; + int textFlags = _tf; + if ( !noaccel && numUnderlines > cUlChar && ti.from() == underlinePositions[cUlChar] ) { + textFlags |= TQt::Underline; + cUlChar++; + } +#if defined(TQ_WS_X11) + if ( painter->bg_mode == TQt::OpaqueMode ) { + int h = ti.ascent() + ti.descent() + 1; + if (ti.y() + h < height) + // don't add leading to last line + h += fm.leading(); + qt_draw_background( painter, r.x()+lb + ti.x(), r.y() + yoff + ti.y() - ti.ascent(), + ti.width(), h); + } +#endif + painter->drawTextItem( r.x()+lb, r.y() + yoff, ti, textFlags ); + } + + if ( restoreClipping ) { + painter->setClipRegion( painterClipRegion ); + painter->setClipping( painterHasClip ); + } + } + + if ( underlinePositions != underlinePositionStack ) + delete [] underlinePositions; +} + +/*! + \overload + + Returns the bounding rectangle of the aligned text that would be + printed with the corresponding drawText() function using the first + \a len characters from \a str if \a len is > -1, or the whole of + \a str if \a len is -1. The drawing, and hence the bounding + rectangle, is constrained to the rectangle \a r, or to the + rectangle required to draw the text, whichever is the larger. + + The \a internal parameter should not be used. + + \sa drawText(), fontMetrics(), TQFontMetrics::boundingRect(), TQt::TextFlags +*/ + +TQRect TQPainter::boundingRect( const TQRect &r, int flags, + const TQString& str, int len, TQTextParag **internal ) +{ + TQRect brect; + if ( str.isEmpty() ) + brect.setRect( r.x(),r.y(), 0,0 ); + else + drawText( r, flags | DontPrint, str, len, &brect, internal ); + return brect; +} + +/*! + \fn TQRect TQPainter::boundingRect( int x, int y, int w, int h, int flags, const TQString&, int len = -1, TQTextParag **intern=0 ); + + Returns the bounding rectangle of the aligned text that would be + printed with the corresponding drawText() function using the first + \a len characters of the string if \a len is > -1, or the whole of + the string if \a len is -1. The drawing, and hence the bounding + rectangle, is constrained to the rectangle that begins at point \a + (x, y) with width \a w and hight \a h, or to the + rectangle required to draw the text, whichever is the larger. + + The \a flags argument is + the bitwise OR of the following flags: + \table + \header \i Flag \i Meaning + \row \i \c AlignAuto \i aligns according to the language, usually left. + \row \i \c AlignLeft \i aligns to the left border. + \row \i \c AlignRight \i aligns to the right border. + \row \i \c AlignHCenter \i aligns horizontally centered. + \row \i \c AlignTop \i aligns to the top border. + \row \i \c AlignBottom \i aligns to the bottom border. + \row \i \c AlignVCenter \i aligns vertically centered. + \row \i \c AlignCenter \i (== \c AlignHCenter | \c AlignVCenter). + \row \i \c SingleLine \i ignores newline characters in the text. + \row \i \c ExpandTabs \i expands tabs. + \row \i \c ShowPrefix \i interprets "&x" as "x". + \row \i \c WordBreak \i breaks the text to fit the rectangle. + \endtable + + Horizontal alignment defaults to \c AlignLeft and vertical + alignment defaults to \c AlignTop. + + If several of the horizontal or several of the vertical alignment flags + are set, the resulting alignment is undefined. + + The \a intern parameter should not be used. + + \sa TQt::TextFlags +*/ + + + +/***************************************************************************** + TQPen member functions + *****************************************************************************/ + +/*! + \class TQPen ntqpen.h + \brief The TQPen class defines how a TQPainter should draw lines and outlines + of shapes. + + \ingroup graphics + \ingroup images + \ingroup shared + \mainclass + + A pen has a style, width, color, cap style and join style. + + The pen style defines the line type. The default pen style is \c + TQt::SolidLine. Setting the style to \c NoPen tells the painter to + not draw lines or outlines. + + When drawing 1 pixel wide diagonal lines you can either use a very + fast algorithm (specified by a line width of 0, which is the + default), or a slower but more accurate algorithm (specified by a + line width of 1). For horizontal and vertical lines a line width + of 0 is the same as a line width of 1. The cap and join style have + no effect on 0-width lines. + + The pen color defines the color of lines and text. The default + line color is black. The TQColor documentation lists predefined + colors. + + The cap style defines how the end points of lines are drawn. The + join style defines how the joins between two lines are drawn when + multiple connected lines are drawn (TQPainter::drawPolyline() + etc.). The cap and join styles only apply to wide lines, i.e. when + the width is 1 or greater. + + Use the TQBrush class to specify fill styles. + + Example: + \code + TQPainter painter; + TQPen pen( red, 2 ); // red solid line, 2 pixels wide + painter.begin( &anyPaintDevice ); // paint something + painter.setPen( pen ); // set the red, wide pen + painter.drawRect( 40,30, 200,100 ); // draw a rectangle + painter.setPen( blue ); // set blue pen, 0 pixel width + painter.drawLine( 40,30, 240,130 ); // draw a diagonal in rectangle + painter.end(); // painting done + \endcode + + See the \l TQt::PenStyle enum type for a complete list of pen + styles. + + With reference to the end points of lines, for wide (non-0-width) + pens it depends on the cap style whether the end point is drawn or + not. TQPainter will try to make sure that the end point is drawn + for 0-width pens, but this cannot be absolutely guaranteed because + the underlying drawing engine is free to use any (typically + accelerated) algorithm for drawing 0-width lines. On all tested + systems, however, the end point of at least all non-diagonal lines + are drawn. + + A pen's color(), width(), style(), capStyle() and joinStyle() can + be set in the constructor or later with setColor(), setWidth(), + setStyle(), setCapStyle() and setJoinStyle(). Pens may also be + compared and streamed. + + \img pen-styles.png Pen styles + + \sa TQPainter, TQPainter::setPen() +*/ + + +/*! + \internal + Initializes the pen. +*/ + +void TQPen::init( const TQColor &color, uint width, uint linestyle ) +{ + data = new TQPenData; + TQ_CHECK_PTR( data ); + data->style = (PenStyle)(linestyle & MPenStyle); + data->width = width; + data->color = color; + data->linest = linestyle; +} + +/*! + Constructs a default black solid line pen with 0 width, which + renders lines 1 pixel wide (fast diagonals). +*/ + +TQPen::TQPen() +{ + init( TQt::black, 0, SolidLine ); // default pen +} + +/*! + Constructs a black pen with 0 width (fast diagonals) and style \a + style. + + \sa setStyle() +*/ + +TQPen::TQPen( PenStyle style ) +{ + init( TQt::black, 0, style ); +} + +/*! + Constructs a pen with the specified \a color, \a width and \a + style. + + \sa setWidth(), setStyle(), setColor() +*/ + +TQPen::TQPen( const TQColor &color, uint width, PenStyle style ) +{ + init( color, width, style ); +} + +/*! + Constructs a pen with the specified color \a cl and width \a w. + The pen style is set to \a s, the pen cap style to \a c and the + pen join style to \a j. + + A line width of 0 will produce a 1 pixel wide line using a fast + algorithm for diagonals. A line width of 1 will also produce a 1 + pixel wide line, but uses a slower more accurate algorithm for + diagonals. For horizontal and vertical lines a line width of 0 is + the same as a line width of 1. The cap and join style have no + effect on 0-width lines. + + \sa setWidth(), setStyle(), setColor() +*/ + +TQPen::TQPen( const TQColor &cl, uint w, PenStyle s, PenCapStyle c, + PenJoinStyle j ) +{ + init( cl, w, s | c | j ); +} + +/*! + Constructs a pen that is a copy of \a p. +*/ + +TQPen::TQPen( const TQPen &p ) +{ + data = p.data; + data->ref(); +} + +/*! + Destroys the pen. +*/ + +TQPen::~TQPen() +{ + if ( data->deref() ) + delete data; +} + + +/*! + Detaches from shared pen data to make sure that this pen is the + only one referring the data. + + If multiple pens share common data, this pen dereferences the data + and gets a copy of the data. Nothing is done if there is just a + single reference. +*/ + +void TQPen::detach() +{ + if ( data->count != 1 ) + *this = copy(); +} + + +/*! + Assigns \a p to this pen and returns a reference to this pen. +*/ + +TQPen &TQPen::operator=( const TQPen &p ) +{ + p.data->ref(); + if ( data->deref() ) + delete data; + data = p.data; + return *this; +} + + +/*! + Returns a \link shclass.html deep copy\endlink of the pen. +*/ + +TQPen TQPen::copy() const +{ + TQPen p( data->color, data->width, data->style, capStyle(), joinStyle() ); + return p; +} + + +/*! + \fn PenStyle TQPen::style() const + + Returns the pen style. + + \sa setStyle() +*/ + +/*! + Sets the pen style to \a s. + + See the \l TQt::PenStyle documentation for a list of all the + styles. + + \warning On Mac OS X the style setting (other than \c NoPen and \c + SolidLine) have no effect as they are not implemented by the + underlying system. + + \warning On Windows 95/98, the style setting (other than \c NoPen + and \c SolidLine) has no effect for lines with width greater than + 1. + + \sa style() +*/ + +void TQPen::setStyle( PenStyle s ) +{ + if ( data->style == s ) + return; + detach(); + data->style = s; + data->linest = (data->linest & ~MPenStyle) | s; +} + + +/*! + \fn uint TQPen::width() const + + Returns the pen width. + + \sa setWidth() +*/ + +/*! + Sets the pen width to \a w. + + A line width of 0 will produce a 1 pixel wide line using a fast + algorithm for diagonals. A line width of 1 will also produce a 1 + pixel wide line, but uses a slower more accurate algorithm for + diagonals. For horizontal and vertical lines a line width of 0 is + the same as a line width of 1. The cap and join style have no + effect on 0-width lines. + + \sa width() +*/ + +void TQPen::setWidth( uint w ) +{ + if ( data->width == w ) + return; + detach(); + data->width = w; +} + + +/*! + Returns the pen's cap style. + + \sa setCapStyle() +*/ +TQt::PenCapStyle TQPen::capStyle() const +{ + return (PenCapStyle)(data->linest & MPenCapStyle); +} + +/*! + Sets the pen's cap style to \a c. + + The default value is \c FlatCap. The cap style has no effect on + 0-width pens. + + \img pen-cap-styles.png Pen Cap Styles + + \warning On Windows 95/98 and Macintosh, the cap style setting has + no effect. Wide lines are rendered as if the cap style was \c + SquareCap. + + \sa capStyle() +*/ + +void TQPen::setCapStyle( PenCapStyle c ) +{ + if ( (data->linest & MPenCapStyle) == c ) + return; + detach(); + data->linest = (data->linest & ~MPenCapStyle) | c; +} + +/*! + Returns the pen's join style. + + \sa setJoinStyle() +*/ +TQt::PenJoinStyle TQPen::joinStyle() const +{ + return (PenJoinStyle)(data->linest & MPenJoinStyle); +} + +/*! + Sets the pen's join style to \a j. + + The default value is \c MiterJoin. The join style has no effect on + 0-width pens. + + \img pen-join-styles.png Pen Join Styles + + \warning On Windows 95/98 and Macintosh, the join style setting + has no effect. Wide lines are rendered as if the join style was \c + BevelJoin. + + \sa joinStyle() +*/ + +void TQPen::setJoinStyle( PenJoinStyle j ) +{ + if ( (data->linest & MPenJoinStyle) == j ) + return; + detach(); + data->linest = (data->linest & ~MPenJoinStyle) | j; +} + +/*! + \fn const TQColor &TQPen::color() const + + Returns the pen color. + + \sa setColor() +*/ + +/*! + Sets the pen color to \a c. + + \sa color() +*/ + +void TQPen::setColor( const TQColor &c ) +{ + detach(); + data->color = c; +} + + +/*! + \fn bool TQPen::operator!=( const TQPen &p ) const + + Returns TRUE if the pen is different from \a p; otherwise returns + FALSE. + + Two pens are different if they have different styles, widths or + colors. + + \sa operator==() +*/ + +/*! + Returns TRUE if the pen is equal to \a p; otherwise returns FALSE. + + Two pens are equal if they have equal styles, widths and colors. + + \sa operator!=() +*/ + +bool TQPen::operator==( const TQPen &p ) const +{ + return (p.data == data) || (p.data->linest == data->linest && + p.data->width == data->width && p.data->color == data->color); +} + + +/***************************************************************************** + TQPen stream functions + *****************************************************************************/ +#ifndef TQT_NO_DATASTREAM +/*! + \relates TQPen + + Writes the pen \a p to the stream \a s and returns a reference to + the stream. + + \sa \link datastreamformat.html Format of the TQDataStream operators \endlink +*/ + +TQDataStream &operator<<( TQDataStream &s, const TQPen &p ) +{ + // ### width() should not be restricted to 8-bit values + if ( s.version() < 3 ) + return s << (TQ_UINT8)p.style() << (TQ_UINT8)p.width() << p.color(); + else + return s << (TQ_UINT8)( p.style() | p.capStyle() | p.joinStyle() ) + << (TQ_UINT8)p.width() << p.color(); +} + +/*! + \relates TQPen + + Reads a pen from the stream \a s into \a p and returns a reference + to the stream. + + \sa \link datastreamformat.html Format of the TQDataStream operators \endlink +*/ + +TQDataStream &operator>>( TQDataStream &s, TQPen &p ) +{ + TQ_UINT8 style, width; + TQColor color; + s >> style; + s >> width; + s >> color; + p = TQPen( color, (uint)width, (TQt::PenStyle)style ); // owl + return s; +} +#endif //TQT_NO_DATASTREAM + +/***************************************************************************** + TQBrush member functions + *****************************************************************************/ + +/*! + \class TQBrush tqbrush.h + + \brief The TQBrush class defines the fill pattern of shapes drawn by a TQPainter. + + \ingroup graphics + \ingroup images + \ingroup shared + + A brush has a style and a color. One of the brush styles is a + custom pattern, which is defined by a TQPixmap. + + The brush style defines the fill pattern. The default brush style + is \c NoBrush (depending on how you construct a brush). This style + tells the painter to not fill shapes. The standard style for + filling is \c SolidPattern. + + The brush color defines the color of the fill pattern. The TQColor + documentation lists the predefined colors. + + Use the TQPen class for specifying line/outline styles. + + Example: + \code + TQPainter painter; + TQBrush brush( yellow ); // yellow solid pattern + painter.begin( &anyPaintDevice ); // paint something + painter.setBrush( brush ); // set the yellow brush + painter.setPen( NoPen ); // do not draw outline + painter.drawRect( 40,30, 200,100 ); // draw filled rectangle + painter.setBrush( NoBrush ); // do not fill + painter.setPen( black ); // set black pen, 0 pixel width + painter.drawRect( 10,10, 30,20 ); // draw rectangle outline + painter.end(); // painting done + \endcode + + See the setStyle() function for a complete list of brush styles. + + \img brush-styles.png Brush Styles + + \sa TQPainter, TQPainter::setBrush(), TQPainter::setBrushOrigin() +*/ + + +/*! + \internal + Initializes the brush. +*/ + +void TQBrush::init( const TQColor &color, BrushStyle style ) +{ + data = new TQBrushData; + TQ_CHECK_PTR( data ); + data->style = style; + data->color = color; + data->pixmap = 0; +} + +/*! + Constructs a default black brush with the style \c NoBrush (will + not fill shapes). +*/ + +TQBrush::TQBrush() +{ + static TQBrushData* defBrushData = 0; + if ( !defBrushData ) { + static TQSharedCleanupHandler defBrushCleanup; + defBrushData = new TQBrushData; + defBrushData->style = NoBrush; + defBrushData->color = TQt::black; + defBrushData->pixmap = 0; + defBrushCleanup.set( &defBrushData ); + } + data = defBrushData; + data->ref(); +} + +/*! + Constructs a black brush with the style \a style. + + \sa setStyle() +*/ + +TQBrush::TQBrush( BrushStyle style ) +{ + init( TQt::black, style ); +} + +/*! + Constructs a brush with the color \a color and the style \a style. + + \sa setColor(), setStyle() +*/ + +TQBrush::TQBrush( const TQColor &color, BrushStyle style ) +{ + init( color, style ); +} + +/*! + Constructs a brush with the color \a color and a custom pattern + stored in \a pixmap. + + The color will only have an effect for monochrome pixmaps, i.e. + for TQPixmap::depth() == 1. + + Pixmap brushes are currently not supported when printing on X11. + + \sa setColor(), setPixmap() +*/ + +TQBrush::TQBrush( const TQColor &color, const TQPixmap &pixmap ) +{ + init( color, CustomPattern ); + setPixmap( pixmap ); +} + +/*! + Constructs a brush that is a \link shclass.html shallow + copy\endlink of \a b. +*/ + +TQBrush::TQBrush( const TQBrush &b ) +{ + data = b.data; + data->ref(); +} + +/*! + Destroys the brush. +*/ + +TQBrush::~TQBrush() +{ + if ( data->deref() ) { + delete data->pixmap; + delete data; + } +} + + +/*! + Detaches from shared brush data to make sure that this brush is + the only one referring the data. + + If multiple brushes share common data, this brush dereferences the + data and gets a copy of the data. Nothing is done if there is just + a single reference. +*/ + +void TQBrush::detach() +{ + if ( data->count != 1 ) + *this = copy(); +} + + +/*! + Assigns \a b to this brush and returns a reference to this brush. +*/ + +TQBrush &TQBrush::operator=( const TQBrush &b ) +{ + b.data->ref(); // beware of b = b + if ( data->deref() ) { + delete data->pixmap; + delete data; + } + data = b.data; + return *this; +} + + +/*! + Returns a \link shclass.html deep copy\endlink of the brush. +*/ + +TQBrush TQBrush::copy() const +{ + if ( data->style == CustomPattern ) { // brush has pixmap + TQBrush b( data->color, *data->pixmap ); + return b; + } else { // brush has std pattern + TQBrush b( data->color, data->style ); + return b; + } +} + + +/*! + \fn BrushStyle TQBrush::style() const + + Returns the brush style. + + \sa setStyle() +*/ + +/*! + Sets the brush style to \a s. + + The brush styles are: + \table + \header \i Pattern \i Meaning + \row \i NoBrush \i will not fill shapes (default). + \row \i SolidPattern \i solid (100%) fill pattern. + \row \i Dense1Pattern \i11 94% fill pattern. + \row \i Dense2Pattern \i11 88% fill pattern. + \row \i Dense3Pattern \i11 63% fill pattern. + \row \i Dense4Pattern \i11 50% fill pattern. + \row \i Dense5Pattern \i11 37% fill pattern. + \row \i Dense6Pattern \i11 12% fill pattern. + \row \i Dense7Pattern \i11 6% fill pattern. + \row \i HorPattern \i horizontal lines pattern. + \row \i VerPattern \i vertical lines pattern. + \row \i CrossPattern \i crossing lines pattern. + \row \i BDiagPattern \i diagonal lines (directed /) pattern. + \row \i FDiagPattern \i diagonal lines (directed \) pattern. + \row \i DiagCrossPattern \i diagonal crossing lines pattern. + \row \i CustomPattern \i set when a pixmap pattern is being used. + \endtable + + On Windows, dense and custom patterns cannot be transparent. + + See the \link #details Detailed Description\endlink for a picture + of all the styles. + + \sa style() +*/ + +void TQBrush::setStyle( BrushStyle s ) // set brush style +{ + if ( data->style == s ) + return; +#if defined(QT_CHECK_RANGE) + if ( s == CustomPattern ) + tqWarning( "TQBrush::setStyle: CustomPattern is for internal use" ); +#endif + detach(); + data->style = s; +} + + +/*! + \fn const TQColor &TQBrush::color() const + + Returns the brush color. + + \sa setColor() +*/ + +/*! + Sets the brush color to \a c. + + \sa color(), setStyle() +*/ + +void TQBrush::setColor( const TQColor &c ) +{ + detach(); + data->color = c; +} + + +/*! + \fn TQPixmap *TQBrush::pixmap() const + + Returns a pointer to the custom brush pattern, or 0 if no custom + brush pattern has been set. + + \sa setPixmap() +*/ + +/*! + Sets the brush pixmap to \a pixmap. The style is set to \c + CustomPattern. + + The current brush color will only have an effect for monochrome + pixmaps, i.e. for TQPixmap::depth() == 1. + + Pixmap brushes are currently not supported when printing on X11. + + \sa pixmap(), color() +*/ + +void TQBrush::setPixmap( const TQPixmap &pixmap ) +{ + detach(); + if ( data->pixmap ) + delete data->pixmap; + if ( pixmap.isNull() ) { + data->style = NoBrush; + data->pixmap = 0; + } else { + data->style = CustomPattern; + data->pixmap = new TQPixmap( pixmap ); + if ( data->pixmap->optimization() == TQPixmap::MemoryOptim ) + data->pixmap->setOptimization( TQPixmap::NormalOptim ); + } +} + + +/*! + \fn bool TQBrush::operator!=( const TQBrush &b ) const + + Returns TRUE if the brush is different from \a b; otherwise + returns FALSE. + + Two brushes are different if they have different styles, colors or + pixmaps. + + \sa operator==() +*/ + +/*! + Returns TRUE if the brush is equal to \a b; otherwise returns + FALSE. + + Two brushes are equal if they have equal styles, colors and + pixmaps. + + \sa operator!=() +*/ + +bool TQBrush::operator==( const TQBrush &b ) const +{ + return (b.data == data) || (b.data->style == data->style && + b.data->color == data->color && + b.data->pixmap == data->pixmap); +} + + +/*! + \fn inline double TQPainter::translationX() const + \internal +*/ + +/*! + \fn inline double TQPainter::translationY() const + \internal +*/ + + +/***************************************************************************** + TQBrush stream functions + *****************************************************************************/ +#ifndef TQT_NO_DATASTREAM +/*! + \relates TQBrush + + Writes the brush \a b to the stream \a s and returns a reference + to the stream. + + \sa \link datastreamformat.html Format of the TQDataStream operators \endlink +*/ + +TQDataStream &operator<<( TQDataStream &s, const TQBrush &b ) +{ + s << (TQ_UINT8)b.style() << b.color(); + if ( b.style() == TQt::CustomPattern ) +#ifndef TQT_NO_IMAGEIO + s << *b.pixmap(); +#else + tqWarning("No Image Brush I/O"); +#endif + return s; +} + +/*! + \relates TQBrush + + Reads the brush \a b from the stream \a s and returns a reference + to the stream. + + \sa \link datastreamformat.html Format of the TQDataStream operators \endlink +*/ + +TQDataStream &operator>>( TQDataStream &s, TQBrush &b ) +{ + TQ_UINT8 style; + TQColor color; + s >> style; + s >> color; + if ( style == TQt::CustomPattern ) { +#ifndef TQT_NO_IMAGEIO + TQPixmap pm; + s >> pm; + b = TQBrush( color, pm ); +#else + tqWarning("No Image Brush I/O"); +#endif + } + else + b = TQBrush( color, (TQt::BrushStyle)style ); + return s; +} +#endif // TQT_NO_DATASTREAM diff --git a/src/kernel/tqpainter.h b/src/kernel/tqpainter.h new file mode 100644 index 000000000..bd2799577 --- /dev/null +++ b/src/kernel/tqpainter.h @@ -0,0 +1,698 @@ +/**************************************************************************** +** +** Definition of TQPainter class +** +** Created : 940112 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef TQPAINTER_H +#define TQPAINTER_H + + +#ifndef QT_H +#include "tqcolor.h" +#include "tqfontmetrics.h" +#include "tqfontinfo.h" +#include "ntqregion.h" +#include "ntqpen.h" +#include "tqbrush.h" +#include "ntqpointarray.h" +#include "ntqwmatrix.h" +#endif // QT_H + +class TQTextCodec; +class TQTextParag; +class TQPaintDevice; +class TQTextItem; +#if defined( TQ_WS_MAC ) +class TQMacSavedPortInfo; +#endif +class TQPainterPrivate; + +class TQ_EXPORT TQPainter : public TQt +{ +public: + enum CoordinateMode { CoordDevice, CoordPainter }; + + TQPainter(); + TQPainter( const TQPaintDevice *, bool unclipped = FALSE ); + TQPainter( const TQPaintDevice *, const TQWidget *, bool unclipped = FALSE ); + ~TQPainter(); + + bool begin( const TQPaintDevice *, bool unclipped = FALSE ); + bool begin( const TQPaintDevice *, const TQWidget *, bool unclipped = FALSE ); + bool end(); + TQPaintDevice *device() const; + + static void redirect( TQPaintDevice *pdev, TQPaintDevice *replacement ); + static TQPaintDevice *redirect( TQPaintDevice *pdev ); + + bool isActive() const; + + void flush( const TQRegion ®ion, CoordinateMode cm = CoordDevice ); + void flush(); + void save(); + void restore(); + + // Drawing tools + + TQFontMetrics fontMetrics() const; + TQFontInfo fontInfo() const; + + const TQFont &font() const; + void setFont( const TQFont & ); + const TQPen &pen() const; + void setPen( const TQPen & ); + void setPen( PenStyle ); + void setPen( const TQColor & ); + const TQBrush &brush() const; + void setBrush( const TQBrush & ); + void setBrush( BrushStyle ); + void setBrush( const TQColor & ); + TQPoint pos() const; + + // Drawing attributes/modes + + const TQColor &backgroundColor() const; + void setBackgroundColor( const TQColor & ); + BGMode backgroundMode() const; + void setBackgroundMode( BGMode ); + RasterOp rasterOp() const; + void setRasterOp( RasterOp ); + const TQPoint &brushOrigin() const; + void setBrushOrigin( int x, int y ); + void setBrushOrigin( const TQPoint & ); + + // Scaling and transformations + +// PaintUnit unit() const; // get set painter unit +// void setUnit( PaintUnit ); // NOT IMPLEMENTED!!! + + bool hasViewXForm() const; + bool hasWorldXForm() const; + +#ifndef TQT_NO_TRANSFORMATIONS + void setViewXForm( bool ); // set xform on/off + TQRect window() const; // get window + void setWindow( const TQRect & ); // set window + void setWindow( int x, int y, int w, int h ); + TQRect viewport() const; // get viewport + void setViewport( const TQRect & ); // set viewport + void setViewport( int x, int y, int w, int h ); + + void setWorldXForm( bool ); // set world xform on/off + const TQWMatrix &worldMatrix() const; // get/set world xform matrix + void setWorldMatrix( const TQWMatrix &, bool combine=FALSE ); + + void saveWorldMatrix(); + void restoreWorldMatrix(); + + void scale( double sx, double sy ); + void shear( double sh, double sv ); + void rotate( double a ); +#endif + void translate( double dx, double dy ); + void resetXForm(); + double translationX() const; + double translationY() const; + + TQPoint xForm( const TQPoint & ) const; // map virtual -> device + TQRect xForm( const TQRect & ) const; + TQPointArray xForm( const TQPointArray & ) const; + TQPointArray xForm( const TQPointArray &, int index, int npoints ) const; + TQPoint xFormDev( const TQPoint & ) const; // map device -> virtual + TQRect xFormDev( const TQRect & ) const; + TQPointArray xFormDev( const TQPointArray & ) const; + TQPointArray xFormDev( const TQPointArray &, int index, int npoints ) const; + + // Clipping + + void setClipping( bool ); // set clipping on/off + bool hasClipping() const; + TQRegion clipRegion( CoordinateMode = CoordDevice ) const; + void setClipRect( const TQRect &, CoordinateMode = CoordDevice ); // set clip rectangle + void setClipRect( int x, int y, int w, int h, CoordinateMode = CoordDevice ); + void setClipRegion( const TQRegion &, CoordinateMode = CoordDevice );// set clip region + + // Graphics drawing functions + + void drawPoint( int x, int y ); + void drawPoint( const TQPoint & ); + void drawPoints( const TQPointArray& a, + int index=0, int npoints=-1 ); + void moveTo( int x, int y ); + void moveTo( const TQPoint & ); + void lineTo( int x, int y ); + void lineTo( const TQPoint & ); + void drawLine( int x1, int y1, int x2, int y2 ); + void drawLine( const TQPoint &, const TQPoint & ); + void drawRect( int x, int y, int w, int h ); + void drawRect( const TQRect & ); + void drawWinFocusRect( int x, int y, int w, int h ); + void drawWinFocusRect( int x, int y, int w, int h, + const TQColor &bgColor ); + void drawWinFocusRect( const TQRect & ); + void drawWinFocusRect( const TQRect &, + const TQColor &bgColor ); + void drawRoundRect( int x, int y, int w, int h, int = 25, int = 25 ); + void drawRoundRect( const TQRect &, int = 25, int = 25 ); + void drawEllipse( int x, int y, int w, int h ); + void drawEllipse( const TQRect & ); + void drawArc( int x, int y, int w, int h, int a, int alen ); + void drawArc( const TQRect &, int a, int alen ); + void drawPie( int x, int y, int w, int h, int a, int alen ); + void drawPie( const TQRect &, int a, int alen ); + void drawChord( int x, int y, int w, int h, int a, int alen ); + void drawChord( const TQRect &, int a, int alen ); + void drawLineSegments( const TQPointArray &, + int index=0, int nlines=-1 ); + void drawPolyline( const TQPointArray &, + int index=0, int npoints=-1 ); + void drawPolygon( const TQPointArray &, bool winding=FALSE, + int index=0, int npoints=-1 ); + void drawConvexPolygon( const TQPointArray &, + int index=0, int npoints=-1 ); +#ifndef TQT_NO_BEZIER + void drawCubicBezier( const TQPointArray &, int index=0 ); +#endif + void drawPixmap( int x, int y, const TQPixmap &, + int sx=0, int sy=0, int sw=-1, int sh=-1 ); + void drawPixmap( const TQPoint &, const TQPixmap &, + const TQRect &sr ); + void drawPixmap( const TQPoint &, const TQPixmap & ); + void drawPixmap( const TQRect &, const TQPixmap & ); + void drawImage( int x, int y, const TQImage &, + int sx = 0, int sy = 0, int sw = -1, int sh = -1, + int conversionFlags = 0 ); + void drawImage( const TQPoint &, const TQImage &, + const TQRect &sr, int conversionFlags = 0 ); + void drawImage( const TQPoint &, const TQImage &, + int conversion_flags = 0 ); + void drawImage( const TQRect &, const TQImage & ); + void drawTiledPixmap( int x, int y, int w, int h, const TQPixmap &, + int sx=0, int sy=0 ); + void drawTiledPixmap( const TQRect &, const TQPixmap &, + const TQPoint & ); + void drawTiledPixmap( const TQRect &, const TQPixmap & ); +#ifndef TQT_NO_PICTURE + void drawPicture( const TQPicture & ); + void drawPicture( int x, int y, const TQPicture & ); + void drawPicture( const TQPoint &, const TQPicture & ); +#endif + + void fillRect( int x, int y, int w, int h, const TQBrush & ); + void fillRect( const TQRect &, const TQBrush & ); + void eraseRect( int x, int y, int w, int h ); + void eraseRect( const TQRect & ); + + // Text drawing functions + + enum TextDirection { + Auto, + RTL, + LTR + }; + + void drawText( int x, int y, const TQString &, int len = -1, TextDirection dir = Auto ); + void drawText( const TQPoint &, const TQString &, int len = -1, TextDirection dir = Auto ); + + void drawText( int x, int y, const TQString &, int pos, int len, TextDirection dir = Auto ); + void drawText( const TQPoint &p, const TQString &, int pos, int len, TextDirection dir = Auto ); + + void drawText( int x, int y, int w, int h, int flags, + const TQString&, int len = -1, TQRect *br=0, + TQTextParag **intern=0 ); + void drawText( const TQRect &, int flags, + const TQString&, int len = -1, TQRect *br=0, + TQTextParag **intern=0 ); + + void drawTextItem( int x, int y, const TQTextItem &ti, int textflags = 0 ); + void drawTextItem( const TQPoint& p, const TQTextItem &ti, int textflags = 0 ); + + TQRect boundingRect( int x, int y, int w, int h, int flags, + const TQString&, int len = -1, TQTextParag **intern=0 ); + TQRect boundingRect( const TQRect &, int flags, + const TQString&, int len = -1, TQTextParag **intern=0 ); + + int tabStops() const; + void setTabStops( int ); + int *tabArray() const; + void setTabArray( int * ); + + // Other functions + +#if defined(TQ_WS_WIN) + HDC handle() const; +#elif defined(TQ_WS_X11) || defined(TQ_WS_MAC) + HANDLE handle() const; +#endif + + + static void initialize(); + static void cleanup(); + +private: + void init(); + void destroy(); + void updateFont(); + void updatePen(); + void updateBrush(); +#ifndef TQT_NO_TRANSFORMATIONS + void updateXForm(); + void updateInvXForm(); +#endif + void map( int, int, int *rx, int *ry ) const; + void map( int, int, int, int, int *, int *, int *, int * ) const; + void mapInv( int, int, int *, int * ) const; + void mapInv( int, int, int, int, int *, int *, int *, int * ) const; + void drawPolyInternal( const TQPointArray &, bool close=TRUE ); + void drawWinFocusRect( int x, int y, int w, int h, bool xorPaint, + const TQColor &penColor ); + + enum { IsActive=0x01, ExtDev=0x02, IsStartingUp=0x04, NoCache=0x08, + VxF=0x10, WxF=0x20, ClipOn=0x40, SafePolygon=0x80, MonoDev=0x100, + DirtyFont=0x200, DirtyPen=0x400, DirtyBrush=0x800, + RGBColor=0x1000, FontMet=0x2000, FontInf=0x4000, CtorBegin=0x8000, + UsePrivateCx = 0x10000, VolatileDC = 0x20000, TQt2Compat = 0x40000 }; + uint flags; + bool testf( uint b ) const { return (flags&b)!=0; } + void setf( uint b ) { flags |= b; } + void setf( uint b, bool v ); + void clearf( uint b ) { flags &= (uint)(~b); } + void fix_neg_rect( int *x, int *y, int *w, int *h ); + + TQPainterPrivate *d; + TQPaintDevice *pdev; + TQColor bg_col; + uchar bg_mode; + uchar rop; + uchar pu; + TQPoint bro; + TQFont cfont; + TQFont *pfont; // font used for metrics (might be different for printers) + TQPen cpen; + TQBrush cbrush; + TQRegion crgn; + int tabstops; + int *tabarray; + int tabarraylen; + bool block_ext; // for temporary blocking of external devices + + // Transformations +#ifndef TQT_NO_TRANSFORMATIONS + TQCOORD wx, wy, ww, wh; + TQCOORD vx, vy, vw, vh; + TQWMatrix wxmat; + + // Cached composition (and inverse) of transformations + TQWMatrix xmat; + TQWMatrix ixmat; + + + + double m11() const { return xmat.m11(); } + double m12() const { return xmat.m12(); } + double m21() const { return xmat.m21(); } + double m22() const { return xmat.m22(); } + double dx() const { return xmat.dx(); } + double dy() const { return xmat.dy(); } + double im11() const { return ixmat.m11(); } + double im12() const { return ixmat.m12(); } + double im21() const { return ixmat.m21(); } + double im22() const { return ixmat.m22(); } + double idx() const { return ixmat.dx(); } + double idy() const { return ixmat.dy(); } + + int txop; + bool txinv; + +#else + // even without transformations we still have translations + int xlatex; + int xlatey; +#endif + + void *penRef; // pen cache ref + void *brushRef; // brush cache ref + void *ps_stack; + void *wm_stack; + void killPStack(); + +protected: +#ifdef Q_OS_TEMP + TQPoint internalCurrentPos; + uint old_pix; // ### All win platforms in 4.0 +#endif +#if defined(TQ_WS_WIN) + friend class TQFontEngineWin; + friend class TQFontEngineBox; + QT_WIN_PAINTER_MEMBERS +#elif defined(TQ_WS_X11) + friend class TQFontEngineXLFD; + friend class TQFontEngineXft; + friend class TQFontEngineBox; + Display *dpy; // current display + int scrn; // current screen + TQt::HANDLE hd; // handle to drawable + TQt::HANDLE rendhd; // handle to Xft draw + GC gc; // graphics context (standard) + GC gc_brush; // graphics contect for brush + TQPoint curPt; // current point + uint clip_serial; // clipping serial number +#elif defined(TQ_WS_MAC) + TQt::HANDLE hd; // handle to drawable + void initPaintDevice(bool force=FALSE, TQPoint *off=NULL, TQRegion *rgn=NULL); + friend const TQRegion &qt_mac_update_painter(TQPainter *, bool); + friend class TQFontEngineMac; + friend class TQMacPainter; +#endif + friend class TQFontMetrics; + friend class TQFontInfo; + friend class TQTextLayout; + friend void qt_format_text( const TQFont &, const TQRect &r, + int tf, const TQString& str, int len, TQRect *brect, + int tabstops, int* tabarray, int tabarraylen, + TQTextParag **internal, TQPainter* painter ); + friend void qt_draw_background( TQPainter *p, int x, int y, int w, int h ); + friend void qt_draw_transformed_rect( TQPainter *p, int x, int y, int w, int h, bool fill ); + friend class TQPrinter; + +private: // Disabled copy constructor and operator= +#if defined(TQ_DISABLE_COPY) + TQPainter( const TQPainter & ); + TQPainter &operator=( const TQPainter & ); +#endif + + enum TransformationCodes { + TxNone = 0, // transformation codes + TxTranslate = 1, // copy in tqpainter_*.cpp + TxScale = 2, + TxRotShear = 3 + }; +}; + + +/***************************************************************************** + TQPainter member functions + *****************************************************************************/ + +inline TQPaintDevice *TQPainter::device() const +{ + return pdev; +} + +inline bool TQPainter::isActive() const +{ + return testf(IsActive); +} + +inline const TQFont &TQPainter::font() const +{ + return cfont; +} + +inline const TQPen &TQPainter::pen() const +{ + return cpen; +} + +inline const TQBrush &TQPainter::brush() const +{ + return cbrush; +} + +/* +inline PaintUnit TQPainter::unit() const +{ + return (PaintUnit)pu; +} +*/ + +inline const TQColor &TQPainter::backgroundColor() const +{ + return bg_col; +} + +inline TQt::BGMode TQPainter::backgroundMode() const +{ + return (BGMode)bg_mode; +} + +inline TQt::RasterOp TQPainter::rasterOp() const +{ + return (RasterOp)rop; +} + +inline const TQPoint &TQPainter::brushOrigin() const +{ + return bro; +} + +inline bool TQPainter::hasViewXForm() const +{ +#ifndef TQT_NO_TRANSFORMATIONS + return testf(VxF); +#else + return xlatex || xlatey; +#endif +} + +inline bool TQPainter::hasWorldXForm() const +{ +#ifndef TQT_NO_TRANSFORMATIONS + return testf(WxF); +#else + return xlatex || xlatey; +#endif +} + +inline double TQPainter::translationX() const +{ +#ifndef TQT_NO_TRANSFORMATIONS + return worldMatrix().dx(); +#else + return xlatex; +#endif +} + +inline double TQPainter::translationY() const +{ +#ifndef TQT_NO_TRANSFORMATIONS + return worldMatrix().dy(); +#else + return xlatey; +#endif +} + + +inline bool TQPainter::hasClipping() const +{ + return testf(ClipOn); +} + +inline int TQPainter::tabStops() const +{ + return tabstops; +} + +inline int *TQPainter::tabArray() const +{ + return tabarray; +} + +#if defined(TQ_WS_WIN) +inline HDC TQPainter::handle() const +{ + return hdc; +} +#elif defined(TQ_WS_X11) || defined(TQ_WS_MAC) +inline TQt::HANDLE TQPainter::handle() const +{ + return hd; +} +#endif + +inline void TQPainter::setBrushOrigin( const TQPoint &p ) +{ + setBrushOrigin( p.x(), p.y() ); +} + +#ifndef TQT_NO_TRANSFORMATIONS +inline void TQPainter::setWindow( const TQRect &r ) +{ + setWindow( r.x(), r.y(), r.width(), r.height() ); +} + +inline void TQPainter::setViewport( const TQRect &r ) +{ + setViewport( r.x(), r.y(), r.width(), r.height() ); +} +#endif + +inline void TQPainter::setClipRect( int x, int y, int w, int h, CoordinateMode m ) +{ + setClipRect( TQRect(x,y,w,h), m ); +} + +inline void TQPainter::drawPoint( const TQPoint &p ) +{ + drawPoint( p.x(), p.y() ); +} + +inline void TQPainter::moveTo( const TQPoint &p ) +{ + moveTo( p.x(), p.y() ); +} + +inline void TQPainter::lineTo( const TQPoint &p ) +{ + lineTo( p.x(), p.y() ); +} + +inline void TQPainter::drawLine( const TQPoint &p1, const TQPoint &p2 ) +{ + drawLine( p1.x(), p1.y(), p2.x(), p2.y() ); +} + +inline void TQPainter::drawRect( const TQRect &r ) +{ + drawRect( r.x(), r.y(), r.width(), r.height() ); +} + +inline void TQPainter::drawWinFocusRect( const TQRect &r ) +{ + drawWinFocusRect( r.x(), r.y(), r.width(), r.height() ); +} + +inline void TQPainter::drawWinFocusRect( const TQRect &r,const TQColor &penColor ) +{ + drawWinFocusRect( r.x(), r.y(), r.width(), r.height(), penColor ); +} + +inline void TQPainter::drawRoundRect( const TQRect &r, int xRnd, int yRnd ) +{ + drawRoundRect( r.x(), r.y(), r.width(), r.height(), xRnd, yRnd ); +} + +inline void TQPainter::drawEllipse( const TQRect &r ) +{ + drawEllipse( r.x(), r.y(), r.width(), r.height() ); +} + +inline void TQPainter::drawArc( const TQRect &r, int a, int alen ) +{ + drawArc( r.x(), r.y(), r.width(), r.height(), a, alen ); +} + +inline void TQPainter::drawPie( const TQRect &r, int a, int alen ) +{ + drawPie( r.x(), r.y(), r.width(), r.height(), a, alen ); +} + +inline void TQPainter::drawChord( const TQRect &r, int a, int alen ) +{ + drawChord( r.x(), r.y(), r.width(), r.height(), a, alen ); +} + +inline void TQPainter::drawPixmap( const TQPoint &p, const TQPixmap &pm, + const TQRect &sr ) +{ + drawPixmap( p.x(), p.y(), pm, sr.x(), sr.y(), sr.width(), sr.height() ); +} + +inline void TQPainter::drawImage( const TQPoint &p, const TQImage &pm, + const TQRect &sr, int conversionFlags ) +{ + drawImage( p.x(), p.y(), pm, + sr.x(), sr.y(), sr.width(), sr.height(), conversionFlags ); +} + +inline void TQPainter::drawTiledPixmap( const TQRect &r, const TQPixmap &pm, + const TQPoint &sp ) +{ + drawTiledPixmap( r.x(), r.y(), r.width(), r.height(), pm, sp.x(), sp.y() ); +} + +inline void TQPainter::drawTiledPixmap( const TQRect &r, const TQPixmap &pm ) +{ + drawTiledPixmap( r.x(), r.y(), r.width(), r.height(), pm, 0, 0 ); +} + +inline void TQPainter::fillRect( const TQRect &r, const TQBrush &brush ) +{ + fillRect( r.x(), r.y(), r.width(), r.height(), brush ); +} + +inline void TQPainter::eraseRect( int x, int y, int w, int h ) +{ + fillRect( x, y, w, h, backgroundColor() ); +} + +inline void TQPainter::eraseRect( const TQRect &r ) +{ + fillRect( r.x(), r.y(), r.width(), r.height(), backgroundColor() ); +} + +inline void TQPainter::drawText( const TQPoint &p, const TQString &s, int len, TextDirection dir ) +{ + drawText( p.x(), p.y(), s, 0, len, dir ); +} + +inline void TQPainter::drawText( const TQPoint &p, const TQString &s, int pos, int len, TextDirection dir ) +{ + drawText( p.x(), p.y(), s, pos, len, dir ); +} + +inline void TQPainter::drawText( int x, int y, int w, int h, int tf, + const TQString& str, int len, TQRect *br, TQTextParag **i ) +{ + TQRect r(x, y, w, h); + drawText( r, tf, str, len, br, i ); +} + +inline void TQPainter::drawTextItem( const TQPoint& p, const TQTextItem &ti, int textflags ) +{ + drawTextItem( p.x(), p.y(), ti, textflags ); +} + +inline TQRect TQPainter::boundingRect( int x, int y, int w, int h, int tf, + const TQString& str, int len, TQTextParag **i ) +{ + TQRect r(x, y, w, h); + return boundingRect( r, tf, str, len, i ); +} + +#endif // TQPAINTER_H diff --git a/src/kernel/tqpainter_p.h b/src/kernel/tqpainter_p.h new file mode 100644 index 000000000..24edb01e6 --- /dev/null +++ b/src/kernel/tqpainter_p.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Definition of some TQt private functions. +** +** Created : 000909 +** +** Copyright (C) 2005-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#ifndef TQPAINTER_P_H +#define TQPAINTER_P_H + + +// +// W A R N I N G +// ------------- +// +// This file is not part of the TQt API. It exists for the convenience +// of tqpainter.cpp and tqfont.cpp. This header file may change +// from version to version without notice, or even be removed. +// +// We mean it. +// +// + +#ifndef QT_H +#endif // QT_H + +extern void qt_format_text( const TQFont& f, const TQRect &r, + int tf, const TQString& str, int len, TQRect *brect, + int tabstops, int* tabarray, int tabarraylen, + TQTextParag **internal, TQPainter* painter ); + + +#endif diff --git a/src/kernel/tqpainter_x11.cpp b/src/kernel/tqpainter_x11.cpp new file mode 100644 index 000000000..e61b2fab2 --- /dev/null +++ b/src/kernel/tqpainter_x11.cpp @@ -0,0 +1,3183 @@ +/**************************************************************************** +** +** Implementation of TQPainter class for X11 +** +** Created : 940112 +** +** Copyright (C) 1992-2008 Trolltech ASA. All rights reserved. +** +** This file is part of the kernel module of the TQt GUI Toolkit. +** +** This file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free +** Software Foundation and appearing in the files LICENSE.GPL2 +** and LICENSE.GPL3 included in the packaging of this file. +** Alternatively you may (at your option) use any later version +** of the GNU General Public License if such license has been +** publicly approved by Trolltech ASA (or its successors, if any) +** and the KDE Free TQt Foundation. +** +** Please review the following information to ensure GNU General +** Public Licensing requirements will be met: +** http://trolltech.com/products/qt/licenses/licensing/opensource/. +** If you are unsure which license is appropriate for your use, please +** review the following information: +** http://trolltech.com/products/qt/licenses/licensing/licensingoverview +** or contact the sales department at sales@trolltech.com. +** +** This file may be used under the terms of the Q Public License as +** defined by Trolltech ASA and appearing in the file LICENSE.TQPL +** included in the packaging of this file. Licensees holding valid TQt +** Commercial licenses may use this file in accordance with the TQt +** Commercial License Agreement provided with the Software. +** +** This file is provided "AS IS" with NO WARRANTY OF ANY KIND, +** INCLUDING THE WARRANTIES OF DESIGN, MERCHANTABILITY AND FITNESS FOR +** A PARTICULAR PURPOSE. Trolltech reserves all rights not granted +** herein. +** +**********************************************************************/ + +#include "qplatformdefs.h" + +#include "tqfont.h" +#include "tqpainter.h" +#include "tqwidget.h" +#include "tqbitmap.h" +#include "ntqpixmapcache.h" +#include "tqtextcodec.h" +#include "tqpaintdevicemetrics.h" + +#include "qt_x11_p.h" + +#include "tqtextlayout_p.h" +#include "tqfontdata_p.h" +#include "tqfontengine_p.h" +#include "tqtextengine_p.h" + +#include + +// paintevent magic to provide Windows semantics on X11 +static TQRegion* paintEventClipRegion = 0; +static TQPaintDevice* paintEventDevice = 0; + +void qt_set_paintevent_clipping( TQPaintDevice* dev, const TQRegion& region) +{ + if ( !paintEventClipRegion ) + paintEventClipRegion = new TQRegion( region ); + else + *paintEventClipRegion = region; + paintEventDevice = dev; +} + +void qt_clear_paintevent_clipping() +{ + delete paintEventClipRegion; + paintEventClipRegion = 0; + paintEventDevice = 0; +} + +class TQWFlagWidget : public TQWidget +{ +public: + void setWState( WFlags f ) { TQWidget::setWState(f); } + void clearWState( WFlags f ) { TQWidget::clearWState(f); } + void setWFlags( WFlags f ) { TQWidget::setWFlags(f); } + void clearWFlags( WFlags f ) { TQWidget::clearWFlags(f); } +}; + +void qt_erase_region( TQWidget* w, const TQRegion& region) +{ + TQRegion reg = region; + + if ( TQPainter::redirect(w) || (!w->isTopLevel() && w->backgroundPixmap() + && w->backgroundOrigin() != TQWidget::WidgetOrigin) ) { + TQPoint offset = w->backgroundOffset(); + int ox = offset.x(); + int oy = offset.y(); + + bool unclipped = w->testWFlags( TQt::WPaintUnclipped ); + if ( unclipped ) + ((TQWFlagWidget*)w)->clearWFlags( TQt::WPaintUnclipped ); + TQPainter p( w ); + p.setClipRegion( region ); // automatically includes paintEventDevice if required + if ( w->backgroundPixmap() ) + p.drawTiledPixmap( 0, 0, w->width(), w->height(), + *w->backgroundPixmap(), ox, oy ); + else + p.fillRect( w->rect(), w->eraseColor() ); + if ( unclipped ) + ((TQWFlagWidget*)w)->setWFlags( TQt::WPaintUnclipped ); + return; + } + + if ( w == paintEventDevice && paintEventClipRegion ) + reg = paintEventClipRegion->intersect( reg ); + + TQMemArray r = reg.rects(); + for (uint i=0; ix11Display(), w->winId(), + rr.x(), rr.y(), rr.width(), rr.height(), False ); + } +} + +void qt_erase_rect( TQWidget* w, const TQRect& r) +{ + if ( TQPainter::redirect(w) || w == paintEventDevice + || w->backgroundOrigin() != TQWidget::WidgetOrigin ) + qt_erase_region( w, r ); + else + XClearArea( w->x11Display(), w->winId(), r.x(), r.y(), r.width(), r.height(), False ); + +} + +#ifdef TQT_NO_XFTFREETYPE +static const TQt::HANDLE rendhd = 0; +#endif + +// hack, so we don't have to make TQRegion::clipRectangles() public or include +// X11 headers in ntqregion.h +inline void *qt_getClipRects( const TQRegion &r, int &num ) +{ + return r.clipRectangles( num ); +} + +static inline void x11SetClipRegion(Display *dpy, GC gc, GC gc2, TQt::HANDLE draw, const TQRegion &r) +{ + int num; + XRectangle *rects = (XRectangle *)qt_getClipRects( r, num ); + + if (gc) + XSetClipRectangles( dpy, gc, 0, 0, rects, num, YXBanded ); + if (gc2) + XSetClipRectangles( dpy, gc2, 0, 0, rects, num, YXBanded ); + +#ifndef TQT_NO_XFTFREETYPE + if (draw) + XftDrawSetClipRectangles((XftDraw *) draw, 0, 0, rects, num); +#else + Q_UNUSED(draw); +#endif // TQT_NO_XFTFREETYPE +} + +static inline void x11ClearClipRegion(Display *dpy, GC gc, GC gc2, TQt::HANDLE draw) +{ + if (gc) + XSetClipMask(dpy, gc, None); + if (gc2) + XSetClipMask(dpy, gc2, None); + +#ifndef TQT_NO_XFTFREETYPE + if (draw) { +# ifdef QT_XFT2 + XftDrawSetClip((XftDraw *) draw, None); +# else + // stupid Xft1 + Picture pict = XftDrawPicture((XftDraw *) draw); + XRenderPictureAttributes pattr; + pattr.clip_mask = None; + XRenderChangePicture(dpy, pict, CPClipMask, &pattr); +# endif // QT_XFT2 + } +#else + Q_UNUSED(draw); +#endif // TQT_NO_XFTFREETYPE +} + + +/***************************************************************************** + Trigonometric function for TQPainter + + We have implemented simple sine and cosine function that are called from + TQPainter::drawPie() and TQPainter::drawChord() when drawing the outline of + pies and chords. + These functions are slower and less accurate than math.h sin() and cos(), + but with still around 1/70000th sec. execution time (on a 486DX2-66) and + 8 digits accuracy, it should not be the bottleneck in drawing these shapes. + The advantage is that you don't have to link in the math library. + *****************************************************************************/ + +const double Q_PI = 3.14159265358979323846; // pi +const double Q_2PI = 6.28318530717958647693; // 2*pi +const double Q_PI2 = 1.57079632679489661923; // pi/2 + + +#if defined(Q_CC_GNU) && defined(Q_OS_AIX) +// AIX 4.2 gcc 2.7.2.3 gets internal error. +static int tqRoundAIX( double d ) +{ + return tqRound(d); +} +#define tqRound tqRoundAIX +#endif + + +#if defined(Q_CC_GNU) && defined(__i386__) + +inline double qcos( double a ) +{ + double r; + __asm__ ( + "fcos" + : "=t" (r) : "0" (a) ); + return(r); +} + +inline double qsin( double a ) +{ + double r; + __asm__ ( + "fsin" + : "=t" (r) : "0" (a) ); + return(r); +} + +double qsincos( double a, bool calcCos=FALSE ) +{ + return calcCos ? qcos(a) : qsin(a); +} + +#else + +double qsincos( double a, bool calcCos=FALSE ) +{ + if ( calcCos ) // calculate cosine + a -= Q_PI2; + if ( a >= Q_2PI || a <= -Q_2PI ) { // fix range: -2*pi < a < 2*pi + int m = (int)(a/Q_2PI); + a -= Q_2PI*m; + } + if ( a < 0.0 ) // 0 <= a < 2*pi + a += Q_2PI; + int sign = a > Q_PI ? -1 : 1; + if ( a >= Q_PI ) + a = Q_2PI - a; + if ( a >= Q_PI2 ) + a = Q_PI - a; + if ( calcCos ) + sign = -sign; + double a2 = a*a; // here: 0 <= a < pi/4 + double a3 = a2*a; // make taylor sin sum + double a5 = a3*a2; + double a7 = a5*a2; + double a9 = a7*a2; + double a11 = a9*a2; + return (a-a3/6+a5/120-a7/5040+a9/362880-a11/39916800)*sign; +} + +inline double qsin( double a ) { return qsincos(a, FALSE); } +inline double qcos( double a ) { return qsincos(a, TRUE); } + +#endif + + +/***************************************************************************** + TQPainter internal GC (Graphics Context) allocator. + + The GC allocator offers two functions; alloc_gc() and free_gc() that + reuse GC objects instead of calling XCreateGC() and XFreeGC(), which + are a whole lot slower. + *****************************************************************************/ + +struct TQGC +{ + GC gc; + char in_use; + bool mono; + int scrn; +}; + +const int gc_array_size = 256; +static TQGC gc_array[gc_array_size]; // array of GCs +static bool gc_array_init = FALSE; + + +static void init_gc_array() +{ + if ( !gc_array_init ) { + memset( gc_array, 0, gc_array_size*sizeof(TQGC) ); + gc_array_init = TRUE; + } +} + +static void cleanup_gc_array( Display *dpy ) +{ + TQGC *p = gc_array; + int i = gc_array_size; + if ( gc_array_init ) { + while ( i-- ) { + if ( p->gc ) // destroy GC + XFreeGC( dpy, p->gc ); + p++; + } + gc_array_init = FALSE; + } +} + +// #define DONT_USE_GC_ARRAY + +static GC alloc_gc( Display *dpy, int scrn, Drawable hd, bool monochrome=FALSE, + bool privateGC = FALSE ) +{ +#if defined(DONT_USE_GC_ARRAY) + privateGC = TRUE; // will be slower +#endif + if ( privateGC ) { + GC gc = XCreateGC( dpy, hd, 0, 0 ); + XSetGraphicsExposures( dpy, gc, False ); + return gc; + } + TQGC *p = gc_array; + int i = gc_array_size; + if ( !gc_array_init ) // not initialized + init_gc_array(); + while ( i-- ) { + if ( !p->gc ) { // create GC (once) + p->gc = XCreateGC( dpy, hd, 0, 0 ); + p->scrn = scrn; + XSetGraphicsExposures( dpy, p->gc, False ); + p->in_use = FALSE; + p->mono = monochrome; + } + if ( !p->in_use && p->mono == monochrome && p->scrn == scrn ) { + p->in_use = TRUE; // available/compatible GC + return p->gc; + } + p++; + } +#if defined(QT_CHECK_NULL) + tqWarning( "TQPainter: Internal error; no available GC" ); +#endif + GC gc = XCreateGC( dpy, hd, 0, 0 ); + XSetGraphicsExposures( dpy, gc, False ); + return gc; +} + +static void free_gc( Display *dpy, GC gc, bool privateGC = FALSE ) +{ +#if defined(DONT_USE_GC_ARRAY) + privateGC = TRUE; // will be slower +#endif + if ( privateGC ) { + Q_ASSERT( dpy != 0 ); + XFreeGC( dpy, gc ); + return; + } + TQGC *p = gc_array; + int i = gc_array_size; + if ( gc_array_init ) { + while ( i-- ) { + if ( p->gc == gc ) { + p->in_use = FALSE; // set available + XSetClipMask( dpy, gc, None ); // make it reusable + XSetFunction( dpy, gc, GXcopy ); + XSetFillStyle( dpy, gc, FillSolid ); + XSetTSOrigin( dpy, gc, 0, 0 ); + return; + } + p++; + } + } + + // not found in gc_array + XFreeGC(dpy, gc); +} + + +/***************************************************************************** + TQPainter internal GC (Graphics Context) cache for solid pens and + brushes. + + The GC cache makes a significant contribution to speeding up + drawing. Setting new pen and brush colors will make the painter + look for another GC with the same color instead of changing the + color value of the GC currently in use. The cache structure is + optimized for fast lookup. Only solid line pens with line width 0 + and solid brushes are cached. + + In addition, stored GCs may have an implicit clipping region + set. This prevents any drawing outside paint events. Both + updatePen() and updateBrush() keep track of the validity of this + clipping region by storing the clip_serial number in the cache. + +*****************************************************************************/ + +struct TQGCC // cached GC +{ + GC gc; + uint pix; + int count; + int hits; + uint clip_serial; + int scrn; +}; + +const int gc_cache_size = 29; // multiply by 4 +static TQGCC *gc_cache_buf; +static TQGCC *gc_cache[4*gc_cache_size]; +static bool gc_cache_init = FALSE; +static uint gc_cache_clip_serial = 0; + + +static void init_gc_cache() +{ + if ( !gc_cache_init ) { + gc_cache_init = TRUE; + gc_cache_clip_serial = 0; + TQGCC *g = gc_cache_buf = new TQGCC[4*gc_cache_size]; + memset( g, 0, 4*gc_cache_size*sizeof(TQGCC) ); + for ( int i=0; i<4*gc_cache_size; i++ ) + gc_cache[i] = g++; + } +} + + +// #define GC_CACHE_STAT +#if defined(GC_CACHE_STAT) +#include "tqtextstream.h" +#include "tqbuffer.h" + +static int g_numhits = 0; +static int g_numcreates = 0; +static int g_numfaults = 0; +#endif + + +static void cleanup_gc_cache() +{ + if ( !gc_cache_init ) + return; +#if defined(GC_CACHE_STAT) + tqDebug( "Number of cache hits = %d", g_numhits ); + tqDebug( "Number of cache creates = %d", g_numcreates ); + tqDebug( "Number of cache faults = %d", g_numfaults ); + for ( int i=0; igc ? 'X' : '-') << ',' << g->hits << ',' + << g->count << '\t'; + } + s << '\0'; + tqDebug( str ); + buf.close(); + } +#endif + delete [] gc_cache_buf; + gc_cache_init = FALSE; +} + + +static bool obtain_gc( void **ref, GC *gc, uint pix, Display *dpy, int scrn, + TQt::HANDLE hd, uint painter_clip_serial ) +{ + if ( !gc_cache_init ) + init_gc_cache(); + + int k = (pix % gc_cache_size) * 4; + TQGCC *g = gc_cache[k]; + TQGCC *prev = 0; + +#define NOMATCH (g->gc && (g->pix != pix || g->scrn != scrn || \ + (g->clip_serial > 0 && g->clip_serial != painter_clip_serial))) + + if ( NOMATCH ) { + prev = g; + g = gc_cache[++k]; + if ( NOMATCH ) { + prev = g; + g = gc_cache[++k]; + if ( NOMATCH ) { + prev = g; + g = gc_cache[++k]; + if ( NOMATCH ) { + if ( g->count == 0 && g->scrn == scrn) { // steal this GC + g->pix = pix; + g->count = 1; + g->hits = 1; + g->clip_serial = 0; + XSetForeground( dpy, g->gc, pix ); + XSetClipMask(dpy, g->gc, None); + gc_cache[k] = prev; + gc_cache[k-1] = g; + *ref = (void *)g; + *gc = g->gc; + return TRUE; + } else { // all GCs in use +#if defined(GC_CACHE_STAT) + g_numfaults++; +#endif + *ref = 0; + return FALSE; + } + } + } + } + } + +#undef NOMATCH + + *ref = (void *)g; + + if ( g->gc ) { // reuse existing GC +#if defined(GC_CACHE_STAT) + g_numhits++; +#endif + *gc = g->gc; + g->count++; + g->hits++; + if ( prev && g->hits > prev->hits ) { // maintain LRU order + gc_cache[k] = prev; + gc_cache[k-1] = g; + } + return TRUE; + } else { // create new GC +#if defined(GC_CACHE_STAT) + g_numcreates++; +#endif + g->gc = alloc_gc( dpy, scrn, hd, FALSE ); + g->scrn = scrn; + g->pix = pix; + g->count = 1; + g->hits = 1; + g->clip_serial = 0; + *gc = g->gc; + return FALSE; + } +} + +static inline void release_gc( void *ref ) +{ + ((TQGCC*)ref)->count--; +} + +/***************************************************************************** + TQPainter member functions + *****************************************************************************/ + +/*! + \internal + + Internal function that initializes the painter. +*/ + +void TQPainter::initialize() +{ + init_gc_array(); + init_gc_cache(); +} + +/*! + \internal + + Internal function that cleans up the painter. +*/ + +void TQPainter::cleanup() +{ + cleanup_gc_cache(); + cleanup_gc_array( TQPaintDevice::x11AppDisplay() ); + TQPointArray::cleanBuffers(); +} + +/*! + \internal + + Internal function that destroys up the painter. +*/ + +void TQPainter::destroy() +{ + +} + +void TQPainter::init() +{ + d = 0; + flags = IsStartingUp; + bg_col = white; // default background color + bg_mode = TransparentMode; // default background mode + rop = CopyROP; // default ROP + tabstops = 0; // default tabbing + tabarray = 0; + tabarraylen = 0; + ps_stack = 0; + wm_stack = 0; + gc = gc_brush = 0; + pdev = 0; + dpy = 0; + txop = txinv = 0; + penRef = brushRef = 0; + clip_serial = 0; + pfont = 0; + block_ext = FALSE; +} + + +/*! + \fn const TQFont &TQPainter::font() const + + Returns the currently set painter font. + + \sa setFont(), TQFont +*/ + +/*! + Sets the painter's font to \a font. + + This font is used by subsequent drawText() functions. The text + color is the same as the pen color. + + \sa font(), drawText() +*/ + +void TQPainter::setFont( const TQFont &font ) +{ +#if defined(QT_CHECK_STATE) + if ( !isActive() ) + tqWarning( "TQPainter::setFont: Will be reset by begin()" ); +#endif + if ( cfont.d != font.d ) { + cfont = font; + cfont.x11SetScreen( scrn ); + setf(DirtyFont); + } +} + + +void TQPainter::updateFont() +{ + if (!isActive()) + return; + + clearf(DirtyFont); + if ( testf(ExtDev) ) { + if (pdev->devType() == TQInternal::Printer) { + if ( pfont ) delete pfont; + pfont = new TQFont( cfont.d, pdev ); + } + TQPDevCmdParam param[1]; + param[0].font = &cfont; + if ( !pdev->cmd( TQPaintDevice::PdcSetFont, this, param ) || !hd ) + return; + } + setf(NoCache); + if ( penRef ) + updatePen(); // force a non-cached GC +} + + +void TQPainter::updatePen() +{ + if (!isActive()) + return; + + if ( testf(ExtDev) ) { + TQPDevCmdParam param[1]; + param[0].pen = &cpen; + if ( !pdev->cmd( TQPaintDevice::PdcSetPen, this, param ) || !hd ) + return; + } + + int ps = cpen.style(); + bool cacheIt = !testf(ClipOn|MonoDev|NoCache) && + (ps == NoPen || ps == SolidLine) && + cpen.width() == 0 && rop == CopyROP; + + bool obtained = FALSE; + bool internclipok = hasClipping(); + if ( cacheIt ) { + if ( gc ) { + if ( penRef ) + release_gc( penRef ); + else + free_gc( dpy, gc ); + } + obtained = obtain_gc(&penRef, &gc, cpen.color().pixel(scrn), dpy, scrn, + hd, clip_serial); + if ( !obtained && !penRef ) + gc = alloc_gc( dpy, scrn, hd, FALSE ); + } else { + if ( gc ) { + if ( penRef ) { + release_gc( penRef ); + penRef = 0; + gc = alloc_gc( dpy, scrn, hd, testf(MonoDev) ); + } else { + internclipok = TRUE; + } + } else { + gc = alloc_gc( dpy, scrn, hd, testf(MonoDev), testf(UsePrivateCx) ); + } + } + + if ( !internclipok ) { + if ( pdev == paintEventDevice && paintEventClipRegion ) { + if ( penRef &&((TQGCC*)penRef)->clip_serial < gc_cache_clip_serial ) { + x11SetClipRegion( dpy, gc, 0, rendhd, *paintEventClipRegion ); + ((TQGCC*)penRef)->clip_serial = gc_cache_clip_serial; + } else if ( !penRef ) { + x11SetClipRegion( dpy, gc, 0, rendhd, *paintEventClipRegion ); + } + } else if (penRef && ((TQGCC*)penRef)->clip_serial ) { + x11ClearClipRegion(dpy, gc, 0, rendhd); + ((TQGCC*)penRef)->clip_serial = 0; + } + } + + if ( obtained ) + return; + + char dashes[10]; // custom pen dashes + int dash_len = 0; // length of dash list + int s = LineSolid; + int cp = CapButt; + int jn = JoinMiter; + + /* + We are emulating Windows here. Windows treats cpen.width() == 1 + (or 0) as a very special case. The fudge variable unifies this + case with the general case. + */ + int dot = cpen.width(); // width of a dot + int fudge = 1; + bool allow_zero_lw = TRUE; + if ( dot <= 1 ) { + dot = 3; + fudge = 2; + } + + switch( ps ) { + case NoPen: + case SolidLine: + s = LineSolid; + break; + case DashLine: + dashes[0] = fudge * 3 * dot; + dashes[1] = fudge * dot; + dash_len = 2; + allow_zero_lw = FALSE; + break; + case DotLine: + dashes[0] = dot; + dashes[1] = dot; + dash_len = 2; + allow_zero_lw = FALSE; + break; + case DashDotLine: + dashes[0] = 3 * dot; + dashes[1] = fudge * dot; + dashes[2] = dot; + dashes[3] = fudge * dot; + dash_len = 4; + allow_zero_lw = FALSE; + break; + case DashDotDotLine: + dashes[0] = 3 * dot; + dashes[1] = dot; + dashes[2] = dot; + dashes[3] = dot; + dashes[4] = dot; + dashes[5] = dot; + dash_len = 6; + allow_zero_lw = FALSE; + break; + case FineDotLine: + dot = 1; + dashes[0] = dot; + dashes[1] = dot; + dash_len = 2; + allow_zero_lw = FALSE; + } + Q_ASSERT( dash_len <= (int) sizeof(dashes) ); + + switch ( cpen.capStyle() ) { + case SquareCap: + cp = CapProjecting; + break; + case RoundCap: + cp = CapRound; + break; + case FlatCap: + default: + cp = CapButt; + break; + } + switch ( cpen.joinStyle() ) { + case BevelJoin: + jn = JoinBevel; + break; + case RoundJoin: + jn = JoinRound; + break; + case MiterJoin: + default: + jn = JoinMiter; + break; + } + + XSetForeground( dpy, gc, cpen.color().pixel(scrn) ); + XSetBackground( dpy, gc, bg_col.pixel(scrn) ); + + if ( dash_len ) { // make dash list + XSetDashes( dpy, gc, 0, dashes, dash_len ); + s = bg_mode == TransparentMode ? LineOnOffDash : LineDoubleDash; + } + XSetLineAttributes( dpy, gc, + (! allow_zero_lw && cpen.width() == 0) ? 1 : cpen.width(), + s, cp, jn ); +} + + +void TQPainter::updateBrush() +{ + if (!isActive()) + return; + + static const uchar dense1_pat[] = { 0xff, 0xbb, 0xff, 0xff, 0xff, 0xbb, 0xff, 0xff }; + static const uchar dense2_pat[] = { 0x77, 0xff, 0xdd, 0xff, 0x77, 0xff, 0xdd, 0xff }; + static const uchar dense3_pat[] = { 0x55, 0xbb, 0x55, 0xee, 0x55, 0xbb, 0x55, 0xee }; + static const uchar dense4_pat[] = { 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa, 0x55, 0xaa }; + static const uchar dense5_pat[] = { 0xaa, 0x44, 0xaa, 0x11, 0xaa, 0x44, 0xaa, 0x11 }; + static const uchar dense6_pat[] = { 0x88, 0x00, 0x22, 0x00, 0x88, 0x00, 0x22, 0x00 }; + static const uchar dense7_pat[] = { 0x00, 0x44, 0x00, 0x00, 0x00, 0x44, 0x00, 0x00 }; + static const uchar hor_pat[] = { // horizontal pattern + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; + static const uchar ver_pat[] = { // vertical pattern + 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, + 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, + 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, + 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, + 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, + 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20 }; + static const uchar cross_pat[] = { // cross pattern + 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0xff, 0xff, 0xff, + 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, + 0x08, 0x82, 0x20, 0xff, 0xff, 0xff, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, + 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0xff, 0xff, 0xff, + 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20, + 0x08, 0x82, 0x20, 0xff, 0xff, 0xff, 0x08, 0x82, 0x20, 0x08, 0x82, 0x20 }; + static const uchar bdiag_pat[] = { // backward diagonal pattern + 0x20, 0x20, 0x10, 0x10, 0x08, 0x08, 0x04, 0x04, 0x02, 0x02, 0x01, 0x01, + 0x80, 0x80, 0x40, 0x40, 0x20, 0x20, 0x10, 0x10, 0x08, 0x08, 0x04, 0x04, + 0x02, 0x02, 0x01, 0x01, 0x80, 0x80, 0x40, 0x40 }; + static const uchar fdiag_pat[] = { // forward diagonal pattern + 0x02, 0x02, 0x04, 0x04, 0x08, 0x08, 0x10, 0x10, 0x20, 0x20, 0x40, 0x40, + 0x80, 0x80, 0x01, 0x01, 0x02, 0x02, 0x04, 0x04, 0x08, 0x08, 0x10, 0x10, + 0x20, 0x20, 0x40, 0x40, 0x80, 0x80, 0x01, 0x01 }; + static const uchar dcross_pat[] = { // diagonal cross pattern + 0x22, 0x22, 0x14, 0x14, 0x08, 0x08, 0x14, 0x14, 0x22, 0x22, 0x41, 0x41, + 0x80, 0x80, 0x41, 0x41, 0x22, 0x22, 0x14, 0x14, 0x08, 0x08, 0x14, 0x14, + 0x22, 0x22, 0x41, 0x41, 0x80, 0x80, 0x41, 0x41 }; + static const uchar * const pat_tbl[] = { + dense1_pat, dense2_pat, dense3_pat, dense4_pat, dense5_pat, + dense6_pat, dense7_pat, + hor_pat, ver_pat, cross_pat, bdiag_pat, fdiag_pat, dcross_pat }; + + if ( testf(ExtDev) ) { + TQPDevCmdParam param[1]; + param[0].brush = &cbrush; + if ( !pdev->cmd( TQPaintDevice::PdcSetBrush, this, param ) || !hd ) + return; + } + + int bs = cbrush.style(); + bool cacheIt = !testf(ClipOn|MonoDev|NoCache) && + (bs == NoBrush || bs == SolidPattern) && + bro.x() == 0 && bro.y() == 0 && rop == CopyROP; + + bool obtained = FALSE; + bool internclipok = hasClipping(); + if ( cacheIt ) { + if ( gc_brush ) { + if ( brushRef ) + release_gc( brushRef ); + else + free_gc( dpy, gc_brush ); + } + obtained = obtain_gc(&brushRef, &gc_brush, cbrush.color().pixel(scrn), dpy, + scrn, hd, clip_serial); + if ( !obtained && !brushRef ) + gc_brush = alloc_gc( dpy, scrn, hd, FALSE ); + } else { + if ( gc_brush ) { + if ( brushRef ) { + release_gc( brushRef ); + brushRef = 0; + gc_brush = alloc_gc( dpy, scrn, hd, testf(MonoDev) ); + } else { + internclipok = TRUE; + } + } else { + gc_brush = alloc_gc( dpy, scrn, hd, testf(MonoDev), testf(UsePrivateCx)); + } + } + + if ( !internclipok ) { + if ( pdev == paintEventDevice && paintEventClipRegion ) { + if ( brushRef &&((TQGCC*)brushRef)->clip_serial < gc_cache_clip_serial ) { + x11SetClipRegion( dpy, gc_brush, 0, rendhd, *paintEventClipRegion ); + ((TQGCC*)brushRef)->clip_serial = gc_cache_clip_serial; + } else if ( !brushRef ){ + x11SetClipRegion( dpy, gc_brush, 0, rendhd, *paintEventClipRegion ); + } + } else if (brushRef && ((TQGCC*)brushRef)->clip_serial ) { + x11ClearClipRegion(dpy, gc_brush, 0, rendhd); + ((TQGCC*)brushRef)->clip_serial = 0; + } + } + + if ( obtained ) + return; + + const uchar *pat = 0; // pattern + int d = 0; // defalt pattern size: d*d + int s = FillSolid; + if ( bs >= Dense1Pattern && bs <= DiagCrossPattern ) { + pat = pat_tbl[ bs-Dense1Pattern ]; + if ( bs <= Dense7Pattern ) + d = 8; + else if ( bs <= CrossPattern ) + d = 24; + else + d = 16; + } + + XSetLineAttributes( dpy, gc_brush, 0, LineSolid, CapButt, JoinMiter ); + XSetForeground( dpy, gc_brush, cbrush.color().pixel(scrn) ); + XSetBackground( dpy, gc_brush, bg_col.pixel(scrn) ); + + if ( bs == CustomPattern || pat ) { + TQPixmap *pm; + if ( pat ) { + TQString key; + key.sprintf( "$qt-brush$%d", bs ); + pm = TQPixmapCache::find( key ); + bool del = FALSE; + if ( !pm ) { // not already in pm dict + pm = new TQBitmap( d, d, pat, TRUE ); + TQ_CHECK_PTR( pm ); + del = !TQPixmapCache::insert( key, pm ); + } + if ( cbrush.data->pixmap ) + delete cbrush.data->pixmap; + cbrush.data->pixmap = new TQPixmap( *pm ); + if (del) delete pm; + } + pm = cbrush.data->pixmap; + pm->x11SetScreen( scrn ); + if ( pm->depth() == 1 ) { + XSetStipple( dpy, gc_brush, pm->handle() ); + s = bg_mode == TransparentMode ? FillStippled : FillOpaqueStippled; + } else { + XSetTile( dpy, gc_brush, pm->handle() ); + s = FillTiled; + } + } + XSetFillStyle( dpy, gc_brush, s ); +} + + +/*! + Begins painting the paint device \a pd and returns TRUE if + successful; otherwise returns FALSE. If \a unclipped is TRUE, the + painting will not be clipped at the paint device's boundaries, + (although this is not supported by all platforms). + + The errors that can occur are serious problems, such as these: + + \code + p->begin( 0 ); // impossible - paint device cannot be 0 + + TQPixmap pm( 0, 0 ); + p->begin( pm ); // impossible - pm.isNull(); + + p->begin( myWidget ); + p2->begin( myWidget ); // impossible - only one painter at a time + \endcode + + Note that most of the time, you can use one of the constructors + instead of begin(), and that end() is automatically done at + destruction. + + \warning A paint device can only be painted by one painter at a + time. + + \sa end(), flush() +*/ + +bool TQPainter::begin( const TQPaintDevice *pd, bool unclipped ) +{ + if ( isActive() ) { // already active painting +#if defined(QT_CHECK_STATE) + tqWarning( "TQPainter::begin: Painter is already active." + "\n\tYou must end() the painter before a second begin()" ); +#endif + return FALSE; + } + if ( pd == 0 ) { +#if defined(QT_CHECK_NULL) + tqWarning( "TQPainter::begin: Paint device cannot be null" ); +#endif + return FALSE; + } + + TQPixmap::x11SetDefaultScreen( pd->x11Screen() ); + + const TQWidget *copyFrom = 0; + pdev = redirect( (TQPaintDevice*)pd ); + if ( pdev ) { // redirected paint device? + if ( pd->devType() == TQInternal::Widget ) + copyFrom = (const TQWidget *)pd; // copy widget settings + } else { + pdev = (TQPaintDevice*)pd; + } + + if ( pdev->isExtDev() && pdev->paintingActive() ) { + // somebody else is already painting +#if defined(QT_CHECK_STATE) + tqWarning( "TQPainter::begin: Another TQPainter is already painting " + "this device;\n\tAn extended paint device can only be " + "painted by one TQPainter at a time." ); +#endif + return FALSE; + } + + bool reinit = flags != IsStartingUp; // 2nd or 3rd etc. time called + flags = IsActive | DirtyFont; // init flags + int dt = pdev->devType(); // get the device type + + if ( (pdev->devFlags & TQInternal::ExternalDevice) != 0 ) + setf(ExtDev); + else if ( dt == TQInternal::Pixmap ) // device is a pixmap + ((TQPixmap*)pdev)->detach(); // will modify it + + dpy = pdev->x11Display(); // get display variable + scrn = pdev->x11Screen(); // get screen variable + hd = pdev->handle(); // get handle to drawable + rendhd = pdev->rendhd; + + if ( testf(ExtDev) ) { // external device + if ( !pdev->cmd( TQPaintDevice::PdcBegin, this, 0 ) ) { + // could not begin painting + if ( reinit ) + clearf( IsActive | DirtyFont ); + else + flags = IsStartingUp; + pdev = 0; + return FALSE; + } + if ( tabstops ) // update tabstops for device + setTabStops( tabstops ); + if ( tabarray ) // update tabarray for device + setTabArray( tabarray ); + } + + if ( pdev->x11Depth() != pdev->x11AppDepth( scrn ) ) { // non-standard depth + setf(NoCache); + setf(UsePrivateCx); + } + + pdev->painters++; // also tell paint device + bro = curPt = TQPoint( 0, 0 ); + if ( reinit ) { + bg_mode = TransparentMode; // default background mode + rop = CopyROP; // default ROP + wxmat.reset(); // reset world xform matrix + xmat.reset(); + ixmat.reset(); + txop = txinv = 0; + if ( dt != TQInternal::Widget ) { + TQFont defaultFont; // default drawing tools + TQPen defaultPen; + TQBrush defaultBrush; + cfont = defaultFont; // set these drawing tools + cpen = defaultPen; + cbrush = defaultBrush; + bg_col = white; // default background color + } + } + wx = wy = vx = vy = 0; // default view origins + + if ( dt == TQInternal::Widget ) { // device is a widget + TQWidget *w = (TQWidget*)pdev; + cfont = w->font(); // use widget font + cpen = TQPen( w->foregroundColor() ); // use widget fg color + if ( reinit ) { + TQBrush defaultBrush; + cbrush = defaultBrush; + } + bg_col = w->backgroundColor(); // use widget bg color + ww = vw = w->width(); // default view size + wh = vh = w->height(); + if ( unclipped || w->testWFlags( WPaintUnclipped ) ) { // paint direct on device + setf( NoCache ); + setf(UsePrivateCx); + updatePen(); + updateBrush(); + XSetSubwindowMode( dpy, gc, IncludeInferiors ); + XSetSubwindowMode( dpy, gc_brush, IncludeInferiors ); +#ifndef TQT_NO_XFTFREETYPE + if (rendhd) + XftDrawSetSubwindowMode((XftDraw *) rendhd, IncludeInferiors); +#endif + } + } else if ( dt == TQInternal::Pixmap ) { // device is a pixmap + TQPixmap *pm = (TQPixmap*)pdev; + if ( pm->isNull() ) { +#if defined(QT_CHECK_NULL) + tqWarning( "TQPainter::begin: Cannot paint null pixmap" ); +#endif + end(); + return FALSE; + } + bool mono = pm->depth() == 1; // monochrome bitmap + if ( mono ) { + setf( MonoDev ); + bg_col = color0; + cpen.setColor( color1 ); + } + ww = vw = pm->width(); // default view size + wh = vh = pm->height(); + } else if ( testf(ExtDev) ) { // external device + ww = vw = pdev->metric( TQPaintDeviceMetrics::PdmWidth ); + wh = vh = pdev->metric( TQPaintDeviceMetrics::PdmHeight ); + } + if ( ww == 0 ) + ww = wh = vw = vh = 1024; + if ( copyFrom ) { // copy redirected widget + cfont = copyFrom->font(); + cpen = TQPen( copyFrom->foregroundColor() ); + bg_col = copyFrom->backgroundColor(); + } + if ( testf(ExtDev) ) { // external device + setBackgroundColor( bg_col ); // default background color + setBackgroundMode( TransparentMode ); // default background mode + setRasterOp( CopyROP ); // default raster operation + } + clip_serial = gc_cache_clip_serial++; + updateBrush(); + updatePen(); + return TRUE; +} + +/*! + Ends painting. Any resources used while painting are released. + + Note that while you mostly don't need to call end(), the + destructor will do it, there is at least one common case when it + is needed, namely double buffering. + + \code + TQPainter p( myPixmap, this ) + // ... + p.end(); // stops drawing on myPixmap + p.begin( this ); + p.drawPixmap( 0, 0, myPixmap ); + \endcode + + Since you can't draw a TQPixmap while it is being painted, it is + necessary to close the active painter. + + \sa begin(), isActive() +*/ + +bool TQPainter::end() // end painting +{ + if ( !isActive() ) { +#if defined(QT_CHECK_STATE) + tqWarning( "TQPainter::end: Missing begin() or begin() failed" ); +#endif + return FALSE; + } + killPStack(); + + //#### This should not be necessary: + if ( pdev->devType() == TQInternal::Widget && // ##### + ((TQWidget*)pdev)->testWFlags(WPaintUnclipped) ) { + if ( gc ) + XSetSubwindowMode( dpy, gc, ClipByChildren ); + if ( gc_brush ) + XSetSubwindowMode( dpy, gc_brush, ClipByChildren ); + } + + if ( gc_brush ) { // restore brush gc + if ( brushRef ) { + release_gc( brushRef ); + brushRef = 0; + } else { + free_gc( dpy, gc_brush, testf(UsePrivateCx) ); + } + gc_brush = 0; + + } + if ( gc ) { // restore pen gc + if ( penRef ) { + release_gc( penRef ); + penRef = 0; + } else { + free_gc( dpy, gc, testf(UsePrivateCx) ); + } + gc = 0; + } + + if ( testf(ExtDev) ) + pdev->cmd( TQPaintDevice::PdcEnd, this, 0 ); + +#ifndef TQT_NO_XFTFREETYPE + if (rendhd) { + // reset clipping/subwindow mode on our render picture + XftDrawSetClip((XftDraw *) rendhd, None); + XftDrawSetSubwindowMode((XftDraw *) rendhd, ClipByChildren); + } +#endif // TQT_NO_XFTFREETYPE + + if ( pfont ) { + delete pfont; + pfont = 0; + } + + flags = 0; + pdev->painters--; + pdev = 0; + dpy = 0; + return TRUE; +} + +/*! + Flushes any buffered drawing operations inside the region \a + region using clipping mode \a cm. + + The flush may update the whole device if the platform does not + support flushing to a specified region. + + \sa flush() CoordinateMode +*/ + +void TQPainter::flush(const TQRegion &rgn, CoordinateMode m) +{ + if ( testf(ExtDev) ) { + TQPDevCmdParam param[2]; + param[0].rgn = &rgn; + param[1].ival = m; + pdev->cmd( TQPaintDevice::PdcFlushRegion, this, param ); + return; + } + + flush(); +} + + +/*! + \overload + + Flushes any buffered drawing operations. +*/ + +void TQPainter::flush() +{ + if ( testf(ExtDev) ) { + pdev->cmd( TQPaintDevice::PdcFlush, this, 0 ); + return; + } + + if ( isActive() && dpy ) + XFlush( dpy ); +} + + +/*! + Sets the background color of the painter to \a c. + + The background color is the color that is filled in when drawing + opaque text, stippled lines and bitmaps. The background color has + no effect in transparent background mode (which is the default). + + \sa backgroundColor() setBackgroundMode() BackgroundMode +*/ + +void TQPainter::setBackgroundColor( const TQColor &c ) +{ + if ( !isActive() ) { +#if defined(QT_CHECK_STATE) + tqWarning( "TQPainter::setBackgroundColor: Call begin() first" ); +#endif + return; + } + bg_col = c; + if ( testf(ExtDev) ) { + TQPDevCmdParam param[1]; + param[0].color = &bg_col; + if ( !pdev->cmd( TQPaintDevice::PdcSetBkColor, this, param ) || !hd ) + return; + } + if ( !penRef ) + updatePen(); // update pen setting + if ( !brushRef ) + updateBrush(); // update brush setting +} + +/*! + Sets the background mode of the painter to \a m, which must be + either \c TransparentMode (the default) or \c OpaqueMode. + + Transparent mode draws stippled lines and text without setting the + background pixels. Opaque mode fills these space with the current + background color. + + Note that in order to draw a bitmap or pixmap transparently, you + must use TQPixmap::setMask(). + + \sa backgroundMode(), setBackgroundColor() +*/ + +void TQPainter::setBackgroundMode( BGMode m ) +{ + if ( !isActive() ) { +#if defined(QT_CHECK_STATE) + tqWarning( "TQPainter::setBackgroundMode: Call begin() first" ); +#endif + return; + } + if ( m != TransparentMode && m != OpaqueMode ) { +#if defined(QT_CHECK_RANGE) + tqWarning( "TQPainter::setBackgroundMode: Invalid mode" ); +#endif + return; + } + bg_mode = m; + if ( testf(ExtDev) ) { + TQPDevCmdParam param[1]; + param[0].ival = m; + if ( !pdev->cmd( TQPaintDevice::PdcSetBkMode, this, param ) || !hd ) + return; + } + if ( !penRef ) + updatePen(); // update pen setting + if ( !brushRef ) + updateBrush(); // update brush setting +} + +static const short ropCodes[] = { // ROP translation table + GXcopy, // CopyROP + GXor, // OrROP + GXxor, // XorROP + GXandInverted, // NotAndROP EraseROP + GXcopyInverted, // NotCopyROP + GXorInverted, // NotOrROP + GXequiv, // NotXorROP + GXand, // AndROP + GXinvert, // NotROP + GXclear, // ClearROP + GXset, // SetROP + GXnoop, // NopROP + GXandReverse, // AndNotROP + GXorReverse, // OrNotROP + GXnand, // NandROP + GXnor // NorROP +}; + + +/*! + Sets the \link TQt::RasterOp raster operation \endlink to \a r. + The default is \c CopyROP. + + \sa rasterOp() TQt::RasterOp +*/ + +void TQPainter::setRasterOp( RasterOp r ) +{ + if ( !isActive() ) { +#if defined(QT_CHECK_STATE) + tqWarning( "TQPainter::setRasterOp: Call begin() first" ); +#endif + return; + } + if ( (uint)r > LastROP ) { +#if defined(QT_CHECK_RANGE) + tqWarning( "TQPainter::setRasterOp: Invalid ROP code" ); +#endif + return; + } + rop = r; + if ( testf(ExtDev) ) { + TQPDevCmdParam param[1]; + param[0].ival = r; + if ( !pdev->cmd( TQPaintDevice::PdcSetROP, this, param ) || !hd ) + return; + } + if ( penRef ) + updatePen(); // get non-cached pen GC + if ( brushRef ) + updateBrush(); // get non-cached brush GC + XSetFunction( dpy, gc, ropCodes[rop] ); + XSetFunction( dpy, gc_brush, ropCodes[rop] ); +} + +// ### matthias - true? + +/*! + Sets the brush origin to \a (x, y). + + The brush origin specifies the (0, 0) coordinate of the painter's + brush. This setting only applies to pattern brushes and pixmap + brushes. + + \sa brushOrigin() +*/ + +void TQPainter::setBrushOrigin( int x, int y ) +{ + if ( !isActive() ) { +#if defined(QT_CHECK_STATE) + tqWarning( "TQPainter::setBrushOrigin: Call begin() first" ); +#endif + return; + } + bro = TQPoint(x, y); + if ( testf(ExtDev) ) { + TQPDevCmdParam param[1]; + param[0].point = &bro; + if ( !pdev->cmd( TQPaintDevice::PdcSetBrushOrigin, this, param ) || + !hd ) + return; + } + if ( brushRef ) + updateBrush(); // get non-cached brush GC + XSetTSOrigin( dpy, gc_brush, x, y ); +} + + +/*! + Enables clipping if \a enable is TRUE, or disables clipping if \a + enable is FALSE. + + \sa hasClipping(), setClipRect(), setClipRegion() +*/ + +void TQPainter::setClipping( bool enable ) +{ + if ( !isActive() ) { +#if defined(QT_CHECK_STATE) + tqWarning( "TQPainter::setClipping: Will be reset by begin()" ); +#endif + return; + } + + if ( enable == testf(ClipOn) ) + return; + + setf( ClipOn, enable ); + if ( testf(ExtDev) ) { + if ( block_ext ) + return; + TQPDevCmdParam param[1]; + param[0].ival = enable; + if ( !pdev->cmd( TQPaintDevice::PdcSetClip, this, param ) || !hd ) + return; + } + if ( enable ) { + TQRegion rgn = crgn; + if ( pdev == paintEventDevice && paintEventClipRegion ) + rgn = rgn.intersect( *paintEventClipRegion ); + if ( penRef ) + updatePen(); + if ( brushRef ) + updateBrush(); + x11SetClipRegion( dpy, gc, gc_brush, rendhd, rgn ); + } else { + if ( pdev == paintEventDevice && paintEventClipRegion ) { + x11SetClipRegion( dpy, gc, gc_brush , rendhd, *paintEventClipRegion ); + } else { + x11ClearClipRegion(dpy, gc, gc_brush, rendhd); + } + } +} + + +/*! + \overload + + Sets the clip region to the rectangle \a r and enables clipping. + The clip mode is set to \a m. + + \sa CoordinateMode +*/ + +void TQPainter::setClipRect( const TQRect &r, CoordinateMode m ) +{ + setClipRegion( TQRegion( r ), m ); +} + +/*! + Sets the clip region to \a rgn and enables clipping. The clip mode + is set to \a m. + + Note that the clip region is given in physical device coordinates + and \e not subject to any \link coordsys.html coordinate + transformation.\endlink + + \sa setClipRect(), clipRegion(), setClipping() CoordinateMode +*/ + +void TQPainter::setClipRegion( const TQRegion &rgn, CoordinateMode m ) +{ +#if defined(QT_CHECK_STATE) + if ( !isActive() ) + tqWarning( "TQPainter::setClipRegion: Will be reset by begin()" ); +#endif + if ( m == CoordDevice ) + crgn = rgn; + else + crgn = xmat * rgn; + + if ( testf(ExtDev) ) { + if ( block_ext ) + return; + TQPDevCmdParam param[2]; + param[0].rgn = &rgn; + param[1].ival = m; + if ( !pdev->cmd( TQPaintDevice::PdcSetClipRegion, this, param ) ) + return; // device cannot clip + } + clearf( ClipOn ); // be sure to update clip rgn + setClipping( TRUE ); +} + + +/*! + \internal + + Internal function for drawing a polygon. +*/ + +void TQPainter::drawPolyInternal( const TQPointArray &a, bool close ) +{ + if ( a.size() < 2 ) + return; + + int x1, y1, x2, y2; // connect last to first point + a.point( a.size()-1, &x1, &y1 ); + a.point( 0, &x2, &y2 ); + bool do_close = close && !(x1 == x2 && y1 == y2); + + if ( close && cbrush.style() != NoBrush ) { // draw filled polygon + XFillPolygon( dpy, hd, gc_brush, (XPoint*)a.shortPoints(), a.size(), + Nonconvex, CoordModeOrigin ); + if ( cpen.style() == NoPen ) { // draw fake outline + XDrawLines( dpy, hd, gc_brush, (XPoint*)a.shortPoints(), a.size(), + CoordModeOrigin ); + if ( do_close ) + XDrawLine( dpy, hd, gc_brush, x1, y1, x2, y2 ); + } + } + if ( cpen.style() != NoPen ) { // draw outline + XDrawLines( dpy, hd, gc, (XPoint*)a.shortPoints(), a.size(), + CoordModeOrigin); + if ( do_close ) + XDrawLine( dpy, hd, gc, x1, y1, x2, y2 ); + } +} + + +/*! + Draws/plots a single point at \a (x, y) using the current pen. + + \sa TQPen +*/ + +void TQPainter::drawPoint( int x, int y ) +{ + if ( !isActive() ) + return; + if ( testf(ExtDev|VxF|WxF) ) { + if ( testf(ExtDev) ) { + TQPDevCmdParam param[1]; + TQPoint p( x, y ); + param[0].point = &p; + if ( !pdev->cmd( TQPaintDevice::PdcDrawPoint, this, param ) || + !hd ) + return; + } + map( x, y, &x, &y ); + } + if ( cpen.style() != NoPen ) + XDrawPoint( dpy, hd, gc, x, y ); +} + + +/*! + Draws/plots an array of points, \a a, using the current pen. + + If \a index is non-zero (the default is zero) only points from \a + index are drawn. If \a npoints is negative (the default) the rest + of the points from \a index are drawn. If \a npoints is zero or + greater, \a npoints points are drawn. + + \warning On X11, coordinates that do not fit into 16-bit signed + values are truncated. This limitation is expected to go away in + TQt 4. +*/ + +void TQPainter::drawPoints( const TQPointArray& a, int index, int npoints ) +{ + if ( npoints < 0 ) + npoints = a.size() - index; + if ( index + npoints > (int)a.size() ) + npoints = a.size() - index; + if ( !isActive() || npoints < 1 || index < 0 ) + return; + TQPointArray pa = a; + if ( testf(ExtDev|VxF|WxF) ) { + if ( testf(ExtDev) ) { + TQPDevCmdParam param[1]; + for (int i=0; icmd( TQPaintDevice::PdcDrawPoint, this, param )) + return; + } + if ( !hd ) return; + } + if ( txop != TxNone ) { + pa = xForm( a, index, npoints ); + if ( pa.size() != a.size() ) { + index = 0; + npoints = pa.size(); + } + } + } + if ( cpen.style() != NoPen ) + XDrawPoints( dpy, hd, gc, (XPoint*)(pa.shortPoints( index, npoints )), + npoints, CoordModeOrigin ); +} + + +/*! \obsolete + Sets the current pen position to \a (x, y) + + \sa lineTo(), pos() +*/ + +void TQPainter::moveTo( int x, int y ) +{ + if ( !isActive() ) + return; + if ( testf(ExtDev|VxF|WxF) ) { + if ( testf(ExtDev) ) { + TQPDevCmdParam param[1]; + TQPoint p( x, y ); + param[0].point = &p; + if ( !pdev->cmd( TQPaintDevice::PdcMoveTo, this, param ) || !hd ) + return; + } + } + curPt = TQPoint( x, y ); +} + +/*! \obsolete + Use drawLine() instead. + + Draws a line from the current pen position to \a (x, y) and sets + \a (x, y) to be the new current pen position. + + \sa TQPen moveTo(), drawLine(), pos() +*/ + +void TQPainter::lineTo( int x, int y ) +{ + if ( !isActive() ) + return; + int cx = curPt.x(), cy = curPt.y(); + curPt = TQPoint( x, y ); + if ( testf(ExtDev|VxF|WxF) ) { + if ( testf(ExtDev) ) { + TQPDevCmdParam param[1]; + TQPoint p( x, y ); + param[0].point = &p; + if ( !pdev->cmd( TQPaintDevice::PdcLineTo, this, param ) || !hd ) + return; + } + map( x, y, &x, &y ); + map( cx, cy, &cx, &cy ); + } + if ( cpen.style() != NoPen ) + XDrawLine( dpy, hd, gc, cx, cy, x, y ); +} + +/*! + Draws a line from (\a x1, \a y1) to (\a x2, \a y2) and sets the + current pen position to (\a x2, \a y2). + + \sa pen() +*/ + +void TQPainter::drawLine( int x1, int y1, int x2, int y2 ) +{ + if ( !isActive() ) + return; + curPt = TQPoint( x2, y2 ); + if ( testf(ExtDev|VxF|WxF) ) { + if ( testf(ExtDev) ) { + TQPDevCmdParam param[2]; + TQPoint p1(x1, y1), p2(x2, y2); + param[0].point = &p1; + param[1].point = &p2; + if ( !pdev->cmd( TQPaintDevice::PdcDrawLine, this, param ) || !hd ) + return; + } + map( x1, y1, &x1, &y1 ); + map( x2, y2, &x2, &y2 ); + } + if ( cpen.style() != NoPen ) + XDrawLine( dpy, hd, gc, x1, y1, x2, y2 ); +} + + + +/*! + Draws a rectangle with upper left corner at \a (x, y) and with + width \a w and height \a h. + + \sa TQPen, drawRoundRect() +*/ + +void TQPainter::drawRect( int x, int y, int w, int h ) +{ + if ( !isActive() ) + return; + if ( testf(ExtDev|VxF|WxF) ) { + if ( testf(ExtDev) ) { + TQPDevCmdParam param[1]; + TQRect r( x, y, w, h ); + param[0].rect = &r; + if ( !pdev->cmd( TQPaintDevice::PdcDrawRect, this, param ) || !hd ) + return; + } + if ( txop == TxRotShear ) { // rotate/shear polygon + TQPointArray pa = xmat.mapToPolygon( TQRect(x, y, w, h) ); + pa.resize( 5 ); + pa.setPoint( 4, pa.point( 0 ) ); + drawPolyInternal( pa ); + return; + } + map( x, y, w, h, &x, &y, &w, &h ); + } + if ( w <= 0 || h <= 0 ) { + if ( w == 0 || h == 0 ) + return; + fix_neg_rect( &x, &y, &w, &h ); + } + if ( cbrush.style() != NoBrush ) { + if ( cpen.style() == NoPen ) { + XFillRectangle( dpy, hd, gc_brush, x, y, w, h ); + return; + } + int lw = cpen.width(); + int lw2 = (lw+1)/2; + if ( w > lw && h > lw ) + XFillRectangle( dpy, hd, gc_brush, x+lw2, y+lw2, w-lw-1, h-lw-1 ); + } + if ( cpen.style() != NoPen ) + XDrawRectangle( dpy, hd, gc, x, y, w-1, h-1 ); +} + +/*! + \overload + + Draws a Windows focus rectangle with upper left corner at (\a x, + \a y) and with width \a w and height \a h. + + This function draws a stippled XOR rectangle that is used to + indicate keyboard focus (when TQApplication::style() is \c + WindowStyle). + + \warning This function draws nothing if the coordinate system has + been \link rotate() rotated\endlink or \link shear() + sheared\endlink. + + \sa drawRect(), TQApplication::style() +*/ + +void TQPainter::drawWinFocusRect( int x, int y, int w, int h ) +{ + drawWinFocusRect( x, y, w, h, TRUE, color0 ); +} + +/*! + Draws a Windows focus rectangle with upper left corner at (\a x, + \a y) and with width \a w and height \a h using a pen color that + contrasts with \a bgColor. + + This function draws a stippled rectangle (XOR is not used) that is + used to indicate keyboard focus (when the TQApplication::style() is + \c WindowStyle). + + The pen color used to draw the rectangle is either white or black + depending on the color of \a bgColor (see TQColor::gray()). + + \warning This function draws nothing if the coordinate system has + been \link rotate() rotated\endlink or \link shear() + sheared\endlink. + + \sa drawRect(), TQApplication::style() +*/ + +void TQPainter::drawWinFocusRect( int x, int y, int w, int h, + const TQColor &bgColor ) +{ + drawWinFocusRect( x, y, w, h, FALSE, bgColor ); +} + + +/*! + \internal +*/ + +void TQPainter::drawWinFocusRect( int x, int y, int w, int h, + bool xorPaint, const TQColor &bgColor ) +{ + if ( !isActive() || txop == TxRotShear ) + return; + static char winfocus_line[] = { 1, 1 }; + + TQPen old_pen = cpen; + TQBrush old_brush = cbrush; + RasterOp old_rop = (RasterOp)rop; + + if ( xorPaint ) { + if ( TQColor::numBitPlanes() <= 8 ) { + setPen( TQPen(color1, 0, TQt::FineDotLine) ); + } + else if ( TQColor::numBitPlanes() <= 8 ) { + setPen( TQPen(white, 0, TQt::FineDotLine) ); + } + else { + setPen( TQPen(TQColor(tqRgba(255,255,255,0)), 0, TQt::FineDotLine) ); + } + setRasterOp( XorROP ); + } + else { + if ( tqGray( bgColor.rgb() ) < 128 ) { + setPen( TQPen(white, 0, TQt::FineDotLine) ); + } + else { + setPen( TQPen(black, 0, TQt::FineDotLine) ); + } + } + + if ( testf(ExtDev|VxF|WxF) ) { + if ( testf(ExtDev) ) { + TQPDevCmdParam param[1]; + TQRect r( x, y, w-1, h-1 ); + TQBrush noBrush; + setBrush( noBrush ); + param[0].rect = &r; + if ( !pdev->cmd( TQPaintDevice::PdcDrawRect, this, param ) || !hd) { + setRasterOp( old_rop ); + setPen( old_pen ); + setBrush( old_brush ); + return; + } + } + map( x, y, w, h, &x, &y, &w, &h ); + } + if ( w <= 0 || h <= 0 ) { + if ( w == 0 || h == 0 ) + return; + fix_neg_rect( &x, &y, &w, &h ); + } + XSetDashes( dpy, gc, 0, winfocus_line, 2 ); + XSetLineAttributes( dpy, gc, 1, LineOnOffDash, CapButt, JoinMiter ); + + XDrawRectangle( dpy, hd, gc, x, y, w-1, h-1 ); + + XSetLineAttributes( dpy, gc, 0, LineSolid, CapButt, JoinMiter ); + setRasterOp( old_rop ); + setPen( old_pen ); +} + + +/*! + Draws a rectangle with rounded corners at \a (x, y), with width \a + w and height \a h. + + The \a xRnd and \a yRnd arguments specify how rounded the corners + should be. 0 is angled corners, 99 is maximum roundedness. + + The width and height include all of the drawn lines. + + \sa drawRect(), TQPen +*/ + +void TQPainter::drawRoundRect( int x, int y, int w, int h, int xRnd, int yRnd ) +{ + if ( !isActive() ) + return; + if ( xRnd <= 0 || yRnd <= 0 ) { + drawRect( x, y, w, h ); // draw normal rectangle + return; + } + if ( xRnd >= 100 ) // fix ranges + xRnd = 99; + if ( yRnd >= 100 ) + yRnd = 99; + if ( testf(ExtDev|VxF|WxF) ) { + if ( testf(ExtDev) ) { + TQPDevCmdParam param[3]; + TQRect r( x, y, w, h ); + param[0].rect = &r; + param[1].ival = xRnd; + param[2].ival = yRnd; + if ( !pdev->cmd( TQPaintDevice::PdcDrawRoundRect, this, param ) || + !hd ) + return; + } + if ( txop == TxRotShear ) { // rotate/shear polygon + if ( w <= 0 || h <= 0 ) + fix_neg_rect( &x, &y, &w, &h ); + w--; + h--; + int rxx = w*xRnd/200; + int ryy = h*yRnd/200; + // were there overflows? + if ( rxx < 0 ) + rxx = w/200*xRnd; + if ( ryy < 0 ) + ryy = h/200*yRnd; + int rxx2 = 2*rxx; + int ryy2 = 2*ryy; + TQPointArray a[4]; + a[0].makeArc( x, y, rxx2, ryy2, 1*16*90, 16*90, xmat ); + a[1].makeArc( x, y+h-ryy2, rxx2, ryy2, 2*16*90, 16*90, xmat ); + a[2].makeArc( x+w-rxx2, y+h-ryy2, rxx2, ryy2, 3*16*90, 16*90, xmat ); + a[3].makeArc( x+w-rxx2, y, rxx2, ryy2, 0*16*90, 16*90, xmat ); + // ### is there a better way to join TQPointArrays? + TQPointArray aa; + aa.resize( a[0].size() + a[1].size() + a[2].size() + a[3].size() ); + uint j = 0; + for ( int k=0; k<4; k++ ) { + for ( uint i=0; ix=px; a->y=py; a->width=w; a->height=h; a->angle1=a1; a->angle2=a2; a++ + XArc arcs[4]; + XArc *a = arcs; + SET_ARC( x+w-rx2, y, rx2, ry2, 0, 90*64 ); + SET_ARC( x, y, rx2, ry2, 90*64, 90*64 ); + SET_ARC( x, y+h-ry2, rx2, ry2, 180*64, 90*64 ); + SET_ARC( x+w-rx2, y+h-ry2, rx2, ry2, 270*64, 90*64 ); + XFillArcs( dpy, hd, gc_brush, arcs, 4 ); +#undef SET_ARC +#define SET_RCT(px, py, w, h) \ + r->x=px; r->y=py; r->width=w; r->height=h; r++ + XRectangle rects[3]; + XRectangle *r = rects; + SET_RCT( x+rx, y+dp, w-rx2, ry ); + SET_RCT( x+dp, y+ry, w+ds, h-ry2 ); + SET_RCT( x+rx, y+h-ry, w-rx2, ry+ds ); + XFillRectangles( dpy, hd, gc_brush, rects, 3 ); +#undef SET_RCT + } + if ( cpen.style() != NoPen ) { // draw outline +#define SET_ARC(px, py, w, h, a1, a2) \ + a->x=px; a->y=py; a->width=w; a->height=h; a->angle1=a1; a->angle2=a2; a++ + XArc arcs[4]; + XArc *a = arcs; + SET_ARC( x+w-rx2, y, rx2, ry2, 0, 90*64 ); + SET_ARC( x, y, rx2, ry2, 90*64, 90*64 ); + SET_ARC( x, y+h-ry2, rx2, ry2, 180*64, 90*64 ); + SET_ARC( x+w-rx2, y+h-ry2, rx2, ry2, 270*64, 90*64 ); + XDrawArcs( dpy, hd, gc, arcs, 4 ); +#undef SET_ARC +#define SET_SEG(xp1, yp1, xp2, yp2) \ + s->x1=xp1; s->y1=yp1; s->x2=xp2; s->y2=yp2; s++ + XSegment segs[4]; + XSegment *s = segs; + SET_SEG( x+rx, y, x+w-rx, y ); + SET_SEG( x+rx, y+h, x+w-rx, y+h ); + SET_SEG( x, y+ry, x, y+h-ry ); + SET_SEG( x+w, y+ry, x+w, y+h-ry ); + XDrawSegments( dpy, hd, gc, segs, 4 ); +#undef SET_SET + } +} + +/*! + Draws an ellipse with center at \a (x + w/2, y + h/2) and size \a + (w, h). +*/ + +void TQPainter::drawEllipse( int x, int y, int w, int h ) +{ + if ( !isActive() ) + return; + if ( testf(ExtDev|VxF|WxF) ) { + if ( testf(ExtDev) ) { + TQPDevCmdParam param[1]; + TQRect r( x, y, w, h ); + param[0].rect = &r; + if ( !pdev->cmd( TQPaintDevice::PdcDrawEllipse, this, param ) || + !hd ) + return; + } + if ( txop == TxRotShear ) { // rotate/shear polygon + TQPointArray a; + a.makeArc( x, y, w, h, 0, 360*16, xmat ); + drawPolyInternal( a ); + return; + } + map( x, y, w, h, &x, &y, &w, &h ); + } + if ( w <= 0 || h <= 0 ) { + if ( w == 0 || h == 0 ) + return; + fix_neg_rect( &x, &y, &w, &h ); + } + if ( w == 1 && h == 1 ) { + XDrawPoint( dpy, hd, (cpen.style() == NoPen)?gc_brush:gc, x, y ); + return; + } + w--; + h--; + if ( cbrush.style() != NoBrush ) { // draw filled ellipse + XFillArc( dpy, hd, gc_brush, x, y, w, h, 0, 360*64 ); + if ( cpen.style() == NoPen ) { + XDrawArc( dpy, hd, gc_brush, x, y, w, h, 0, 360*64 ); + return; + } + } + if ( cpen.style() != NoPen ) // draw outline + XDrawArc( dpy, hd, gc, x, y, w, h, 0, 360*64 ); +} + + +/*! + Draws an arc defined by the rectangle \a (x, y, w, h), the start + angle \a a and the arc length \a alen. + + The angles \a a and \a alen are 1/16th of a degree, i.e. a full + circle equals 5760 (16*360). Positive values of \a a and \a alen + mean counter-clockwise while negative values mean the clockwise + direction. Zero degrees is at the 3 o'clock position. + + Example: + \code + TQPainter p( myWidget ); + p.drawArc( 10,10, 70,100, 100*16, 160*16 ); // draws a "(" arc + \endcode + + \sa drawPie(), drawChord() +*/ + +void TQPainter::drawArc( int x, int y, int w, int h, int a, int alen ) +{ + if ( !isActive() ) + return; + if ( testf(ExtDev|VxF|WxF) ) { + if ( testf(ExtDev) ) { + TQPDevCmdParam param[3]; + TQRect r( x, y, w, h ); + param[0].rect = &r; + param[1].ival = a; + param[2].ival = alen; + if ( !pdev->cmd( TQPaintDevice::PdcDrawArc, this, param ) || + !hd ) + return; + } + if ( txop == TxRotShear ) { // rotate/shear + TQPointArray pa; + pa.makeArc( x, y, w, h, a, alen, xmat ); // arc polyline + drawPolyInternal( pa, FALSE ); + return; + } + map( x, y, w, h, &x, &y, &w, &h ); + } + w--; + h--; + if ( w <= 0 || h <= 0 ) { + if ( w == 0 || h == 0 ) + return; + fix_neg_rect( &x, &y, &w, &h ); + } + if ( cpen.style() != NoPen ) + XDrawArc( dpy, hd, gc, x, y, w, h, a*4, alen*4 ); +} + + +/*! + Draws a pie defined by the rectangle \a (x, y, w, h), the start + angle \a a and the arc length \a alen. + + The pie is filled with the current brush(). + + The angles \a a and \a alen are 1/16th of a degree, i.e. a full + circle equals 5760 (16*360). Positive values of \a a and \a alen + mean counter-clockwise while negative values mean the clockwise + direction. Zero degrees is at the 3 o'clock position. + + \sa drawArc(), drawChord() +*/ + +void TQPainter::drawPie( int x, int y, int w, int h, int a, int alen ) +{ + // Make sure "a" is 0..360*16, as otherwise a*4 may overflow 16 bits. + if ( a > (360*16) ) { + a = a % (360*16); + } else if ( a < 0 ) { + a = a % (360*16); + if ( a < 0 ) a += (360*16); + } + + if ( !isActive() ) + return; + if ( testf(ExtDev|VxF|WxF) ) { + if ( testf(ExtDev) ) { + TQPDevCmdParam param[3]; + TQRect r( x, y, w, h ); + param[0].rect = &r; + param[1].ival = a; + param[2].ival = alen; + if ( !pdev->cmd( TQPaintDevice::PdcDrawPie, this, param ) || !hd ) + return; + } + if ( txop == TxRotShear ) { // rotate/shear + TQPointArray pa; + pa.makeArc( x, y, w, h, a, alen, xmat ); // arc polyline + int n = pa.size(); + int cx, cy; + xmat.map(x+w/2, y+h/2, &cx, &cy); + pa.resize( n+2 ); + pa.setPoint( n, cx, cy ); // add legs + pa.setPoint( n+1, pa.at(0) ); + drawPolyInternal( pa ); + return; + } + map( x, y, w, h, &x, &y, &w, &h ); + } + XSetArcMode( dpy, gc_brush, ArcPieSlice ); + w--; + h--; + if ( w <= 0 || h <= 0 ) { + if ( w == 0 || h == 0 ) + return; + fix_neg_rect( &x, &y, &w, &h ); + } + + GC g = gc; + bool nopen = cpen.style() == NoPen; + + if ( cbrush.style() != NoBrush ) { // draw filled pie + XFillArc( dpy, hd, gc_brush, x, y, w, h, a*4, alen*4 ); + if ( nopen ) { + g = gc_brush; + nopen = FALSE; + } + } + if ( !nopen ) { // draw pie outline + double w2 = 0.5*w; // with, height in ellipsis + double h2 = 0.5*h; + double xc = (double)x+w2; + double yc = (double)y+h2; + double ra1 = Q_PI/2880.0*a; // convert a, alen to radians + double ra2 = ra1 + Q_PI/2880.0*alen; + int xic = tqRound(xc); + int yic = tqRound(yc); + XDrawLine( dpy, hd, g, xic, yic, + tqRound(xc + qcos(ra1)*w2), tqRound(yc - qsin(ra1)*h2)); + XDrawLine( dpy, hd, g, xic, yic, + tqRound(xc + qcos(ra2)*w2), tqRound(yc - qsin(ra2)*h2)); + XDrawArc( dpy, hd, g, x, y, w, h, a*4, alen*4 ); + } +} + + +/*! + Draws a chord defined by the rectangle \a (x, y, w, h), the start + angle \a a and the arc length \a alen. + + The chord is filled with the current brush(). + + The angles \a a and \a alen are 1/16th of a degree, i.e. a full + circle equals 5760 (16*360). Positive values of \a a and \a alen + mean counter-clockwise while negative values mean the clockwise + direction. Zero degrees is at the 3 o'clock position. + + \sa drawArc(), drawPie() +*/ + +void TQPainter::drawChord( int x, int y, int w, int h, int a, int alen ) +{ + if ( !isActive() ) + return; + if ( testf(ExtDev|VxF|WxF) ) { + if ( testf(ExtDev) ) { + TQPDevCmdParam param[3]; + TQRect r( x, y, w, h ); + param[0].rect = &r; + param[1].ival = a; + param[2].ival = alen; + if ( !pdev->cmd(TQPaintDevice::PdcDrawChord, this, param) || !hd ) + return; + } + if ( txop == TxRotShear ) { // rotate/shear + TQPointArray pa; + pa.makeArc( x, y, w-1, h-1, a, alen, xmat ); // arc polygon + int n = pa.size(); + pa.resize( n+1 ); + pa.setPoint( n, pa.at(0) ); // connect endpoints + drawPolyInternal( pa ); + return; + } + map( x, y, w, h, &x, &y, &w, &h ); + } + XSetArcMode( dpy, gc_brush, ArcChord ); + w--; + h--; + if ( w <= 0 || h <= 0 ) { + if ( w == 0 || h == 0 ) + return; + fix_neg_rect( &x, &y, &w, &h ); + } + + GC g = gc; + bool nopen = cpen.style() == NoPen; + + if ( cbrush.style() != NoBrush ) { // draw filled chord + XFillArc( dpy, hd, gc_brush, x, y, w, h, a*4, alen*4 ); + if ( nopen ) { + g = gc_brush; + nopen = FALSE; + } + } + if ( !nopen ) { // draw chord outline + double w2 = 0.5*w; // with, height in ellipsis + double h2 = 0.5*h; + double xc = (double)x+w2; + double yc = (double)y+h2; + double ra1 = Q_PI/2880.0*a; // convert a, alen to radians + double ra2 = ra1 + Q_PI/2880.0*alen; + XDrawLine( dpy, hd, g, + tqRound(xc + qcos(ra1)*w2), tqRound(yc - qsin(ra1)*h2), + tqRound(xc + qcos(ra2)*w2), tqRound(yc - qsin(ra2)*h2)); + XDrawArc( dpy, hd, g, x, y, w, h, a*4, alen*4 ); + } + XSetArcMode( dpy, gc_brush, ArcPieSlice ); +} + + +/*! + Draws \a nlines separate lines from points defined in \a a, + starting at \a a[index] (\a index defaults to 0). If \a nlines is + -1 (the default) all points until the end of the array are used + (i.e. (a.size()-index)/2 lines are drawn). + + Draws the 1st line from \a a[index] to \a a[index+1]. Draws the + 2nd line from \a a[index+2] to \a a[index+3] etc. + + \warning On X11, coordinates that do not fit into 16-bit signed + values are truncated. This limitation is expected to go away in + TQt 4. + + \sa drawPolyline(), drawPolygon(), TQPen +*/ + +void TQPainter::drawLineSegments( const TQPointArray &a, int index, int nlines ) +{ + if ( nlines < 0 ) + nlines = a.size()/2 - index/2; + if ( index + nlines*2 > (int)a.size() ) + nlines = (a.size() - index)/2; + if ( !isActive() || nlines < 1 || index < 0 ) + return; + TQPointArray pa = a; + if ( testf(ExtDev|VxF|WxF) ) { + if ( testf(ExtDev) ) { + if ( 2*nlines != (int)pa.size() ) { + pa = TQPointArray( nlines*2 ); + for ( int i=0; icmd(TQPaintDevice::PdcDrawLineSegments, this, param) || + !hd ) + return; + } + if ( txop != TxNone ) { + pa = xForm( a, index, nlines*2 ); + if ( pa.size() != a.size() ) { + index = 0; + nlines = pa.size()/2; + } + } + } + if ( cpen.style() != NoPen ) + XDrawSegments( dpy, hd, gc, + (XSegment*)(pa.shortPoints( index, nlines*2 )), nlines ); +} + + +/*! + Draws the polyline defined by the \a npoints points in \a a + starting at \a a[index]. (\a index defaults to 0.) + + If \a npoints is -1 (the default) all points until the end of the + array are used (i.e. a.size()-index-1 line segments are drawn). + + \warning On X11, coordinates that do not fit into 16-bit signed + values are truncated. This limitation is expected to go away in + TQt 4. + + \sa drawLineSegments(), drawPolygon(), TQPen +*/ + +void TQPainter::drawPolyline( const TQPointArray &a, int index, int npoints ) +{ + if ( npoints < 0 ) + npoints = a.size() - index; + if ( index + npoints > (int)a.size() ) + npoints = a.size() - index; + if ( !isActive() || npoints < 2 || index < 0 ) + return; + TQPointArray pa = a; + if ( testf(ExtDev|VxF|WxF) ) { + if ( testf(ExtDev) ) { + if ( npoints != (int)pa.size() ) { + pa = TQPointArray( npoints ); + for ( int i=0; icmd(TQPaintDevice::PdcDrawPolyline, this, param) || !hd ) + return; + } + if ( txop != TxNone ) { + pa = xForm( pa, index, npoints ); + if ( pa.size() != a.size() ) { + index = 0; + npoints = pa.size(); + } + } + } + if ( cpen.style() != NoPen ) { + while(npoints>65535) { + XDrawLines( dpy, hd, gc, (XPoint*)(pa.shortPoints( index, 65535 )), + 65535, CoordModeOrigin ); + npoints-=65535; + index+=65535; + } + XDrawLines( dpy, hd, gc, (XPoint*)(pa.shortPoints( index, npoints )), + npoints, CoordModeOrigin ); + } +} + +static int global_polygon_shape = Complex; + +/*! + Draws the polygon defined by the \a npoints points in \a a + starting at \a a[index]. (\a index defaults to 0.) + + If \a npoints is -1 (the default) all points until the end of the + array are used (i.e. a.size()-index line segments define the + polygon). + + The first point is always connected to the last point. + + The polygon is filled with the current brush(). If \a winding is + TRUE, the polygon is filled using the winding fill algorithm. If + \a winding is FALSE, the polygon is filled using the even-odd + (alternative) fill algorithm. + + \warning On X11, coordinates that do not fit into 16-bit signed + values are truncated. This limitation is expected to go away in + TQt 4. + + \sa drawLineSegments(), drawPolyline(), TQPen +*/ + +void TQPainter::drawPolygon( const TQPointArray &a, bool winding, + int index, int npoints ) +{ + if ( npoints < 0 ) + npoints = a.size() - index; + if ( index + npoints > (int)a.size() ) + npoints = a.size() - index; + if ( !isActive() || npoints < 2 || index < 0 ) + return; + TQPointArray pa = a; + if ( testf(ExtDev|VxF|WxF) ) { + if ( testf(ExtDev) ) { + if ( npoints != (int)a.size() ) { + pa = TQPointArray( npoints ); + for ( int i=0; icmd(TQPaintDevice::PdcDrawPolygon, this, param) || !hd ) + return; + } + if ( txop != TxNone ) { + pa = xForm( a, index, npoints ); + if ( pa.size() != a.size() ) { + index = 0; + npoints = pa.size(); + } + } + } + if ( winding ) // set to winding fill rule + XSetFillRule( dpy, gc_brush, WindingRule ); + + if ( pa[index] != pa[index+npoints-1] ){ // close open pointarray + pa.detach(); + pa.resize( index+npoints+1 ); + pa.setPoint( index+npoints, pa[index] ); + npoints++; + } + + if ( cbrush.style() != NoBrush ) { // draw filled polygon + XFillPolygon( dpy, hd, gc_brush, + (XPoint*)(pa.shortPoints( index, npoints )), + npoints, global_polygon_shape, CoordModeOrigin ); + } + if ( cpen.style() != NoPen ) { // draw outline + XDrawLines( dpy, hd, gc, (XPoint*)(pa.shortPoints( index, npoints )), + npoints, CoordModeOrigin ); + } + if ( winding ) // set to normal fill rule + XSetFillRule( dpy, gc_brush, EvenOddRule ); +} + +/*! + Draws the convex polygon defined by the \a npoints points in \a pa + starting at \a pa[index] (\a index defaults to 0). + + If the supplied polygon is not convex, the results are undefined. + + On some platforms (e.g. X Window), this is faster than + drawPolygon(). + + \warning On X11, coordinates that do not fit into 16-bit signed + values are truncated. This limitation is expected to go away in + TQt 4. +*/ +void TQPainter::drawConvexPolygon( const TQPointArray &pa, + int index, int npoints ) +{ + global_polygon_shape = Convex; + drawPolygon(pa, FALSE, index, npoints); + global_polygon_shape = Complex; +} + + + +/*! + Draws a cubic Bezier curve defined by the control points in \a a, + starting at \a a[index] (\a index defaults to 0). + + Control points after \a a[index + 3] are ignored. Nothing happens + if there aren't enough control points. + + \warning On X11, coordinates that do not fit into 16-bit signed + values are truncated. This limitation is expected to go away in + TQt 4. +*/ + +void TQPainter::drawCubicBezier( const TQPointArray &a, int index ) +{ + if ( !isActive() ) + return; + if ( a.size() - index < 4 ) { +#if defined(QT_CHECK_RANGE) + tqWarning( "TQPainter::drawCubicBezier: Cubic Bezier needs 4 control " + "points" ); +#endif + return; + } + TQPointArray pa( a ); + if ( index != 0 || a.size() > 4 ) { + pa = TQPointArray( 4 ); + for ( int i=0; i<4; i++ ) + pa.setPoint( i, a.point(index+i) ); + } + if ( testf(ExtDev|VxF|WxF) ) { + if ( testf(ExtDev) ) { + TQPDevCmdParam param[1]; + param[0].ptarr = (TQPointArray*)&pa; + if ( !pdev->cmd(TQPaintDevice::PdcDrawCubicBezier, this, param) || + !hd ) + return; + } + if ( txop != TxNone ) + pa = xForm( pa ); + } + if ( cpen.style() != NoPen ) { + pa = pa.cubicBezier(); + XDrawLines( dpy, hd, gc, (XPoint*)pa.shortPoints(), pa.size(), + CoordModeOrigin ); + } +} + + +/*! + Draws a pixmap at \a (x, y) by copying a part of \a pixmap into + the paint device. + + \a (x, y) specifies the top-left point in the paint device that is + to be drawn onto. \a (sx, sy) specifies the top-left point in \a + pixmap that is to be drawn. The default is (0, 0). + + \a (sw, sh) specifies the size of the pixmap that is to be drawn. + The default, (-1, -1), means all the way to the bottom right of + the pixmap. + + Currently the mask of the pixmap or it's alpha channel are ignored + when painting on a TQPrinter. + + \sa bitBlt(), TQPixmap::setMask() +*/ + +void TQPainter::drawPixmap( int x, int y, const TQPixmap &pixmap, + int sx, int sy, int sw, int sh ) +{ + if ( !isActive() || pixmap.isNull() ) + return; + + // right/bottom + if ( sw < 0 ) + sw = pixmap.width() - sx; + if ( sh < 0 ) + sh = pixmap.height() - sy; + + // Sanity-check clipping + if ( sx < 0 ) { + x -= sx; + sw += sx; + sx = 0; + } + if ( sw + sx > pixmap.width() ) + sw = pixmap.width() - sx; + if ( sy < 0 ) { + y -= sy; + sh += sy; + sy = 0; + } + if ( sh + sy > pixmap.height() ) + sh = pixmap.height() - sy; + + if ( sw <= 0 || sh <= 0 ) + return; + + if ( pdev->x11Screen() != pixmap.x11Screen() ) { + TQPixmap* p = (TQPixmap*) &pixmap; + p->x11SetScreen( pdev->x11Screen() ); + } + + TQPixmap::x11SetDefaultScreen( pixmap.x11Screen() ); + + if ( testf(ExtDev|VxF|WxF) ) { + if ( testf(ExtDev) || txop == TxScale || txop == TxRotShear ) { + if ( sx != 0 || sy != 0 || + sw != pixmap.width() || sh != pixmap.height() ) { + TQPixmap tmp( sw, sh, pixmap.depth() ); + bitBlt( &tmp, 0, 0, &pixmap, sx, sy, sw, sh, CopyROP, TRUE ); + if ( pixmap.mask() ) { + TQBitmap mask( sw, sh ); + bitBlt( &mask, 0, 0, pixmap.mask(), sx, sy, sw, sh, + CopyROP, TRUE ); + tmp.setMask( mask ); + } + drawPixmap( x, y, tmp ); + return; + } + if ( testf(ExtDev) ) { + TQPDevCmdParam param[2]; + TQRect r(x, y, pixmap.width(), pixmap.height()); + param[0].rect = &r; + param[1].pixmap = &pixmap; + if ( !pdev->cmd(TQPaintDevice::PdcDrawPixmap, this, param) || !hd ) + return; + } + if ( txop == TxScale || txop == TxRotShear ) { + TQWMatrix mat( m11(), m12(), + m21(), m22(), + dx(), dy() ); + mat = TQPixmap::trueMatrix( mat, sw, sh ); + TQPixmap pm = pixmap.xForm( mat ); + if ( !pm.mask() && txop == TxRotShear ) { + TQBitmap bm_clip( sw, sh, 1 ); + bm_clip.fill( color1 ); + pm.setMask( bm_clip.xForm(mat) ); + } + map( x, y, &x, &y ); // compute position of pixmap + int dx, dy; + mat.map( 0, 0, &dx, &dy ); + uint save_flags = flags; + flags = IsActive | (save_flags & ClipOn); + drawPixmap( x-dx, y-dy, pm ); + flags = save_flags; + return; + } + } + map( x, y, &x, &y ); + } + + TQBitmap *mask = (TQBitmap *)pixmap.mask(); + bool mono = pixmap.depth() == 1; + + if ( mask && !hasClipping() && pdev != paintEventDevice ) { + if ( mono ) { // needs GCs pen color + bool selfmask = pixmap.data->selfmask; + if ( selfmask ) { + XSetFillStyle( dpy, gc, FillStippled ); + XSetStipple( dpy, gc, pixmap.handle() ); + } else { + XSetFillStyle( dpy, gc, FillOpaqueStippled ); + XSetStipple( dpy, gc, pixmap.handle() ); + XSetClipMask( dpy, gc, mask->handle() ); + XSetClipOrigin( dpy, gc, x-sx, y-sy ); + } + XSetTSOrigin( dpy, gc, x-sx, y-sy ); + XFillRectangle( dpy, hd, gc, x, y, sw, sh ); + XSetTSOrigin( dpy, gc, 0, 0 ); + XSetFillStyle( dpy, gc, FillSolid ); + if ( !selfmask ) { + if ( pdev == paintEventDevice && paintEventClipRegion ) { + x11SetClipRegion( dpy, gc, 0, rendhd, *paintEventClipRegion ); + } else { + x11ClearClipRegion(dpy, gc, 0, rendhd); + } + } + } else { + bitBlt( pdev, x, y, &pixmap, sx, sy, sw, sh, (RasterOp)rop ); + } + return; + } + + TQRegion rgn = crgn; + + if ( mask ) { // pixmap has clip mask + // Implies that clipping is on, either explicit or implicit + // Create a new mask that combines the mask with the clip region + + if ( pdev == paintEventDevice && paintEventClipRegion ) { + if ( hasClipping() ) + rgn = rgn.intersect( *paintEventClipRegion ); + else + rgn = *paintEventClipRegion; + } + + TQBitmap *comb = new TQBitmap( sw, sh ); + comb->detach(); + GC cgc = tqt_xget_temp_gc( pixmap.x11Screen(), TRUE ); // get temporary mono GC + XSetForeground( dpy, cgc, 0 ); + XFillRectangle( dpy, comb->handle(), cgc, 0, 0, sw, sh ); + XSetBackground( dpy, cgc, 0 ); + XSetForeground( dpy, cgc, 1 ); + int num; + XRectangle *rects = (XRectangle *)qt_getClipRects( rgn, num ); + XSetClipRectangles( dpy, cgc, -x, -y, rects, num, YXBanded ); + XSetFillStyle( dpy, cgc, FillOpaqueStippled ); + XSetStipple( dpy, cgc, mask->handle() ); + XSetTSOrigin( dpy, cgc, -sx, -sy ); + XFillRectangle( dpy, comb->handle(), cgc, 0, 0, sw, sh ); + XSetTSOrigin( dpy, cgc, 0, 0 ); // restore cgc + XSetFillStyle( dpy, cgc, FillSolid ); + XSetClipMask( dpy, cgc, None ); + mask = comb; // it's deleted below + + XSetClipMask( dpy, gc, mask->handle() ); + XSetClipOrigin( dpy, gc, x, y ); + } + + if ( mono ) { + XSetBackground( dpy, gc, bg_col.pixel(scrn) ); + XSetFillStyle( dpy, gc, FillOpaqueStippled ); + XSetStipple( dpy, gc, pixmap.handle() ); + XSetTSOrigin( dpy, gc, x-sx, y-sy ); + XFillRectangle( dpy, hd, gc, x, y, sw, sh ); + XSetTSOrigin( dpy, gc, 0, 0 ); + XSetFillStyle( dpy, gc, FillSolid ); + } else { +#if !defined(TQT_NO_XFTFREETYPE) && !defined(TQT_NO_XRENDER) + Picture pict = rendhd ? XftDrawPicture((XftDraw *) rendhd) : None; + TQPixmap *alpha = pixmap.data->alphapm; + + if ( pict && pixmap.x11RenderHandle() && + alpha && alpha->x11RenderHandle()) { + XRenderComposite(dpy, PictOpOver, pixmap.x11RenderHandle(), + alpha->x11RenderHandle(), pict, + sx, sy, sx, sy, x, y, sw, sh); + } else +#endif // !TQT_NO_XFTFREETYPE && !TQT_NO_XRENDER + { + XCopyArea( dpy, pixmap.handle(), hd, gc, sx, sy, sw, sh, x, y ); + } + } + + if ( mask ) { // restore clipping + XSetClipOrigin( dpy, gc, 0, 0 ); + XSetRegion( dpy, gc, rgn.handle() ); + delete mask; // delete comb, created above + } +} + + +/* Internal, used by drawTiledPixmap */ + +static void drawTile( TQPainter *p, int x, int y, int w, int h, + const TQPixmap &pixmap, int xOffset, int yOffset ) +{ + int yPos, xPos, drawH, drawW, yOff, xOff; + yPos = y; + yOff = yOffset; + while( yPos < y + h ) { + drawH = pixmap.height() - yOff; // Cropping first row + if ( yPos + drawH > y + h ) // Cropping last row + drawH = y + h - yPos; + xPos = x; + xOff = xOffset; + while( xPos < x + w ) { + drawW = pixmap.width() - xOff; // Cropping first column + if ( xPos + drawW > x + w ) // Cropping last column + drawW = x + w - xPos; + p->drawPixmap( xPos, yPos, pixmap, xOff, yOff, drawW, drawH ); + xPos += drawW; + xOff = 0; + } + yPos += drawH; + yOff = 0; + } +} + +#if 0 // see comment in drawTiledPixmap +/* Internal, used by drawTiledPixmap */ + +static void fillTile( TQPixmap *tile, const TQPixmap &pixmap ) +{ + bitBlt( tile, 0, 0, &pixmap, 0, 0, -1, -1, TQt::CopyROP, TRUE ); + int x = pixmap.width(); + while ( x < tile->width() ) { + bitBlt( tile, x,0, tile, 0,0, x,pixmap.height(), TQt::CopyROP, TRUE ); + x *= 2; + } + int y = pixmap.height(); + while ( y < tile->height() ) { + bitBlt( tile, 0,y, tile, 0,0, tile->width(),y, TQt::CopyROP, TRUE ); + y *= 2; + } +} +#endif + +/*! + Draws a tiled \a pixmap in the specified rectangle. + + \a (x, y) specifies the top-left point in the paint device that is + to be drawn onto; with the width and height given by \a w and \a + h. \a (sx, sy) specifies the top-left point in \a pixmap that is + to be drawn. The default is (0, 0). + + Calling drawTiledPixmap() is similar to calling drawPixmap() + several times to fill (tile) an area with a pixmap, but is + potentially much more efficient depending on the underlying window + system. + + \sa drawPixmap() +*/ + +void TQPainter::drawTiledPixmap( int x, int y, int w, int h, + const TQPixmap &pixmap, int sx, int sy ) +{ + int sw = pixmap.width(); + int sh = pixmap.height(); + if (!sw || !sh ) + return; + if ( sx < 0 ) + sx = sw - -sx % sw; + else + sx = sx % sw; + if ( sy < 0 ) + sy = sh - -sy % sh; + else + sy = sy % sh; + /* + Requirements for optimizing tiled pixmaps: + - not an external device + - not scale or rotshear + - not mono pixmap + - no mask + */ + TQBitmap *mask = (TQBitmap *)pixmap.mask(); + if ( !testf(ExtDev) && txop <= TxTranslate && pixmap.depth() > 1 && + mask == 0 ) { + if ( txop == TxTranslate ) + map( x, y, &x, &y ); + +#if !defined(TQT_NO_XFTFREETYPE) && !defined(TQT_NO_XRENDER) + Picture pict = rendhd ? XftDrawPicture((XftDraw *) rendhd) : None; + TQPixmap *alpha = pixmap.data->alphapm; + + if (pict && pixmap.x11RenderHandle() && alpha && alpha->x11RenderHandle()) { + // this is essentially drawTile() from above, inlined for + // the XRenderComposite call + int yPos, xPos, drawH, drawW, yOff, xOff; + yPos = y; + yOff = sy; + while( yPos < y + h ) { + drawH = pixmap.height() - yOff; // Cropping first row + if ( yPos + drawH > y + h ) // Cropping last row + drawH = y + h - yPos; + xPos = x; + xOff = sx; + while( xPos < x + w ) { + drawW = pixmap.width() - xOff; // Cropping first column + if ( xPos + drawW > x + w ) // Cropping last column + drawW = x + w - xPos; + XRenderComposite(dpy, PictOpOver, pixmap.x11RenderHandle(), + alpha->x11RenderHandle(), pict, + xOff, yOff, xOff, yOff, xPos, yPos, drawW, drawH); + xPos += drawW; + xOff = 0; + } + yPos += drawH; + yOff = 0; + } + return; + } +#endif // !TQT_NO_XFTFREETYPE && !TQT_NO_XRENDER + + XSetTile( dpy, gc, pixmap.handle() ); + XSetFillStyle( dpy, gc, FillTiled ); + XSetTSOrigin( dpy, gc, x-sx, y-sy ); + XFillRectangle( dpy, hd, gc, x, y, w, h ); + XSetTSOrigin( dpy, gc, 0, 0 ); + XSetFillStyle( dpy, gc, FillSolid ); + return; + } + +#if 0 + // maybe there'll be point in this again, but for the time all it + // does is make trouble for the postscript code. + if ( sw*sh < 8192 && sw*sh < 16*w*h ) { + int tw = sw; + int th = sh; + while( th * tw < 4096 && ( th < h || tw < w ) ) { + if ( h/th > w/tw ) + th *= 2; + else + tw *= 2; + } + TQPixmap tile( tw, th, pixmap.depth(), TQPixmap::NormalOptim ); + fillTile( &tile, pixmap ); + if ( mask ) { + TQBitmap tilemask( tw, th, TQPixmap::NormalOptim ); + fillTile( &tilemask, *mask ); + tile.setMask( tilemask ); + } + drawTile( this, x, y, w, h, tile, sx, sy ); + } else { + drawTile( this, x, y, w, h, pixmap, sx, sy ); + } +#else + // for now we'll just output the original and let the postscript + // code make what it can of it. qpicture will be unhappy. + drawTile( this, x, y, w, h, pixmap, sx, sy ); +#endif +} + +#if 0 +// +// Generate a string that describes a transformed bitmap. This string is used +// to insert and find bitmaps in the global pixmap cache. +// + +static TQString gen_text_bitmap_key( const TQWMatrix &m, const TQFont &font, + const TQString &str, int pos, int len ) +{ + TQString fk = font.key(); + int sz = 4*2 + len*2 + fk.length()*2 + sizeof(double)*6; + TQByteArray buf(sz); + uchar *p = (uchar *)buf.data(); + *((double*)p)=m.m11(); p+=sizeof(double); + *((double*)p)=m.m12(); p+=sizeof(double); + *((double*)p)=m.m21(); p+=sizeof(double); + *((double*)p)=m.m22(); p+=sizeof(double); + *((double*)p)=m.dx(); p+=sizeof(double); + *((double*)p)=m.dy(); p+=sizeof(double); + TQChar h1( '$' ); + TQChar h2( 'q' ); + TQChar h3( 't' ); + TQChar h4( '$' ); + *((TQChar*)p)=h1; p+=2; + *((TQChar*)p)=h2; p+=2; + *((TQChar*)p)=h3; p+=2; + *((TQChar*)p)=h4; p+=2; + memcpy( (char*)p, (char*)(str.unicode()+pos), len*2 ); p += len*2; + memcpy( (char*)p, (char*)fk.unicode(), fk.length()*2 ); p += fk.length()*2; + return TQString( (TQChar*)buf.data(), buf.size()/2 ); +} + +static TQBitmap *get_text_bitmap( const TQString &key ) +{ + return (TQBitmap*)TQPixmapCache::find( key ); +} + +static void ins_text_bitmap( const TQString &key, TQBitmap *bm ) +{ + if ( !TQPixmapCache::insert(key, bm) ) // cannot insert pixmap + delete bm; +} +#endif + +void qt_draw_transformed_rect( TQPainter *p, int x, int y, int w, int h, bool fill ) +{ + XPoint points[5]; + int xp = x, yp = y; + p->map( xp, yp, &xp, &yp ); + points[0].x = xp; + points[0].y = yp; + xp = x + w; yp = y; + p->map( xp, yp, &xp, &yp ); + points[1].x = xp; + points[1].y = yp; + xp = x + w; yp = y + h; + p->map( xp, yp, &xp, &yp ); + points[2].x = xp; + points[2].y = yp; + xp = x; yp = y + h; + p->map( xp, yp, &xp, &yp ); + points[3].x = xp; + points[3].y = yp; + points[4] = points[0]; + + if ( fill ) + XFillPolygon( p->dpy, p->hd, p->gc, points, 4, Convex, CoordModeOrigin ); + else + XDrawLines( p->dpy, p->hd, p->gc, points, 5, CoordModeOrigin ); +} + +void qt_draw_background( TQPainter *p, int x, int y, int w, int h ) +{ + if (p->testf(TQPainter::ExtDev)) { + if (p->pdev->devType() == TQInternal::Printer) + p->fillRect(x, y, w, h, p->bg_col); + return; + } + XSetForeground( p->dpy, p->gc, p->bg_col.pixel(p->scrn) ); + qt_draw_transformed_rect( p, x, y, w, h, TRUE); + XSetForeground( p->dpy, p->gc, p->cpen.color().pixel(p->scrn) ); +} + +/*! + Draws at most \a len characters of the string \a str at position + \a (x, y). + + \a (x, y) is the base line position. Note that the meaning of \a y + is not the same for the two drawText() varieties. +*/ +void TQPainter::drawText( int x, int y, const TQString &str, int len, TQPainter::TextDirection dir ) +{ + drawText( x, y, str, 0, len, dir ); +} + +/*! + Draws at most \a len characters starting at position \a pos from the + string \a str to position \a (x, y). + + \a (x, y) is the base line position. Note that the meaning of \a y + is not the same for the two drawText() varieties. +*/ +void TQPainter::drawText( int x, int y, const TQString &str, int pos, int len, TQPainter::TextDirection dir ) +{ + if ( !isActive() ) + return; + if (len < 0) + len = str.length() - pos; + if ( len <= 0 || pos >= (int)str.length() ) // empty string + return; + if ( pos + len > (int)str.length() ) + len = str.length() - pos; + + if ( testf(DirtyFont) ) { + updateFont(); + } + + if ( testf(ExtDev) && pdev->devType() != TQInternal::Printer ) { + TQPDevCmdParam param[3]; + TQPoint p(x, y); + TQString string = str.mid( pos, len ); + param[0].point = &p; + param[1].str = &string; + param[2].ival = TQFont::Latin; + if ( !pdev->cmd(TQPaintDevice::PdcDrawText2, this, param) || !hd ) + return; + } + + bool simple = (dir == TQPainter::Auto) && str.simpleText(); + // we can't take the complete string here as we would otherwise + // get quadratic behaviour when drawing long strings in parts. + // we do however need some chars around the part we paint to get arabic shaping correct. + // ### maybe possible to remove after cursor restrictions work in TQRT + int start; + int end; + if ( simple ) { + start = pos; + end = pos+len; + } else { + start = TQMAX( 0, pos - 8 ); + end = TQMIN( (int)str.length(), pos + len + 8 ); + } + TQConstString cstr( str.unicode() + start, end - start ); + pos -= start; + + TQTextEngine engine( cstr.string(), pfont ? pfont->d : cfont.d ); + TQTextLayout layout( &engine ); + + // this is actually what beginLayout does. Inlined here, so we can + // avoid the bidi algorithm if we don't need it. + engine.itemize( simple ? TQTextEngine::NoBidi|TQTextEngine::SingleLine : TQTextEngine::Full|TQTextEngine::SingleLine ); + engine.currentItem = 0; + engine.firstItemInLine = -1; + + if ( dir != Auto ) { + int level = dir == RTL ? 1 : 0; + for ( int i = engine.items.size(); i >= 0; i-- ) + engine.items[i].analysis.bidiLevel = level; + } + + if ( !simple ) { + layout.setBoundary( pos ); + layout.setBoundary( pos + len ); + } + + // small hack to force skipping of unneeded items + start = 0; + while ( engine.items[start].position < pos ) + ++start; + engine.currentItem = start; + layout.beginLine( 0xfffffff ); + end = start; + while ( !layout.atEnd() && layout.currentItem().from() < pos + len ) { + layout.addCurrentItem(); + end++; + } + TQFontMetrics fm(fontMetrics()); + int ascent = fm.ascent(), descent = fm.descent(); + int left, right; + layout.endLine( 0, 0, TQt::SingleLine|TQt::AlignLeft, &ascent, &descent, &left, &right ); + + // do _not_ call endLayout() here, as it would clean up the shaped items and we would do shaping another time + // for painting. + + int textFlags = 0; + if ( cfont.d->underline ) textFlags |= TQt::Underline; + if ( cfont.d->overline ) textFlags |= TQt::Overline; + if ( cfont.d->strikeOut ) textFlags |= TQt::StrikeOut; + + if ( bg_mode == OpaqueMode ) + qt_draw_background( this, x, y-ascent, right-left, ascent+descent+1); + + for ( int i = start; i < end; i++ ) { + TQTextItem ti; + ti.item = i; + ti.engine = &engine; + + drawTextItem( x, y - ascent, ti, textFlags ); + } + layout.d = 0; +} + + +/*! \internal + Draws the text item \a ti at position \a (x, y ). + + This method ignores the painters background mode and + color. drawText and qt_format_text have to do it themselves, as + only they know the extents of the complete string. + + It ignores the font set on the painter as the text item has one of its own. + + The underline and strikeout parameters of the text items font are + ignored aswell. You'll need to pass in the correct flags to get + underlining and strikeout. +*/ +void TQPainter::drawTextItem( int x, int y, const TQTextItem &ti, int textFlags ) +{ + if ( testf(ExtDev) ) { + TQPDevCmdParam param[2]; + TQPoint p(x, y); + param[0].point = &p; + param[1].textItem = &ti; + bool retval = pdev->cmd(TQPaintDevice::PdcDrawTextItem, this, param); + if ( !retval || !hd ) + return; + } + + TQTextEngine *engine = ti.engine; + TQScriptItem *si = &engine->items[ti.item]; + + engine->shape( ti.item ); + TQFontEngine *fe = si->fontEngine; + assert( fe != 0 ); + + x += si->x; + y += si->y; + + fe->draw( this, x, y, engine, si, textFlags ); +} + +/*! + \obsolete + Returns the current position of the pen. + + \sa moveTo() + */ +TQPoint TQPainter::pos() const +{ + return curPt; +} diff --git a/src/kernel/tqsizegrip.cpp b/src/kernel/tqsizegrip.cpp index 00c994a3a..18ff03d28 100644 --- a/src/kernel/tqsizegrip.cpp +++ b/src/kernel/tqsizegrip.cpp @@ -42,7 +42,7 @@ #ifndef TQT_NO_SIZEGRIP -#include "ntqpainter.h" +#include "tqpainter.h" #include "ntqapplication.h" #include "tqstyle.h" diff --git a/src/kernel/tqstyle.cpp b/src/kernel/tqstyle.cpp index 47755c4ba..a8403969d 100644 --- a/src/kernel/tqstyle.cpp +++ b/src/kernel/tqstyle.cpp @@ -41,7 +41,7 @@ #include "tqstyle.h" #ifndef TQT_NO_STYLE #include "ntqapplication.h" -#include "ntqpainter.h" +#include "tqpainter.h" #include "tqbitmap.h" #include "ntqpixmapcache.h" #include "ntqframe.h" diff --git a/src/kernel/tqstyle.h b/src/kernel/tqstyle.h index bd5987d32..15ecd20fe 100644 --- a/src/kernel/tqstyle.h +++ b/src/kernel/tqstyle.h @@ -43,7 +43,7 @@ #ifndef QT_H #include "tqobject.h" #include "ntqpixmap.h" -#include "ntqcolor.h" +#include "tqcolor.h" #include "tqiconset.h" #include "ntqtabbar.h" #include "tqtoolbutton.h" diff --git a/src/kernel/tqstylesheet.cpp b/src/kernel/tqstylesheet.cpp index 2af221100..b96ffd963 100644 --- a/src/kernel/tqstylesheet.cpp +++ b/src/kernel/tqstylesheet.cpp @@ -44,7 +44,7 @@ #include "private/qrichtext_p.h" #include "ntqlayout.h" -#include "ntqpainter.h" +#include "tqpainter.h" #include "ntqcleanuphandler.h" #include diff --git a/src/kernel/tqtextengine.cpp b/src/kernel/tqtextengine.cpp index 9b1ff2e1b..8280340c9 100644 --- a/src/kernel/tqtextengine.cpp +++ b/src/kernel/tqtextengine.cpp @@ -39,9 +39,9 @@ #include "tqtextengine_p.h" #include "qscriptengine_p.h" -#include -#include "qfontdata_p.h" -#include "qfontengine_p.h" +#include +#include "tqfontdata_p.h" +#include "tqfontengine_p.h" #include #include #include diff --git a/src/kernel/tqtextengine_p.h b/src/kernel/tqtextengine_p.h index 7d641e98e..608bc06de 100644 --- a/src/kernel/tqtextengine_p.h +++ b/src/kernel/tqtextengine_p.h @@ -41,7 +41,7 @@ #include "ntqglobal.h" #include "tqstring.h" #include "ntqnamespace.h" -#include +#include #endif // QT_H #include diff --git a/src/kernel/tqtextlayout.cpp b/src/kernel/tqtextlayout.cpp index 41be6076a..3e71ccd39 100644 --- a/src/kernel/tqtextlayout.cpp +++ b/src/kernel/tqtextlayout.cpp @@ -39,9 +39,9 @@ #include "tqtextlayout_p.h" #include "tqtextengine_p.h" -#include +#include #include -#include +#include TQRect TQTextItem::rect() const diff --git a/src/kernel/tqttdeintegration_x11.cpp b/src/kernel/tqttdeintegration_x11.cpp index c1b99f188..6bd89a390 100644 --- a/src/kernel/tqttdeintegration_x11.cpp +++ b/src/kernel/tqttdeintegration_x11.cpp @@ -3,9 +3,9 @@ #include "tqttdeintegration_x11_p.h" -#include +#include #include -#include +#include #include #include #include diff --git a/src/kernel/tqwidget.cpp b/src/kernel/tqwidget.cpp index d5419c8d0..f1f1798d3 100644 --- a/src/kernel/tqwidget.cpp +++ b/src/kernel/tqwidget.cpp @@ -49,7 +49,7 @@ #include "ntqpixmap.h" #include "ntqapplication.h" #include "qapplication_p.h" -#include "ntqbrush.h" +#include "tqbrush.h" #include "ntqlayout.h" #include "tqstylefactory.h" #include "ntqcleanuphandler.h" @@ -66,7 +66,7 @@ #include "qt_windows.h" #include "qinputcontext_p.h" #endif -#include "qfontdata_p.h" +#include "tqfontdata_p.h" /*! diff --git a/src/kernel/tqwidget.h b/src/kernel/tqwidget.h index 8d9faf00b..9e1c3a07a 100644 --- a/src/kernel/tqwidget.h +++ b/src/kernel/tqwidget.h @@ -44,11 +44,11 @@ #ifndef QT_H #include "ntqwindowdefs.h" #include "tqobject.h" -#include "ntqpaintdevice.h" +#include "tqpaintdevice.h" #include "ntqpalette.h" -#include "ntqfont.h" -#include "ntqfontmetrics.h" -#include "ntqfontinfo.h" +#include "tqfont.h" +#include "tqfontmetrics.h" +#include "tqfontinfo.h" #include "tqsizepolicy.h" #endif // QT_H diff --git a/src/kernel/tqwidget_x11.cpp b/src/kernel/tqwidget_x11.cpp index c3a54d3d8..4e07dd115 100644 --- a/src/kernel/tqwidget_x11.cpp +++ b/src/kernel/tqwidget_x11.cpp @@ -41,8 +41,8 @@ #include "ntqapplication.h" #include "qapplication_p.h" #include "ntqnamespace.h" -#include "ntqpaintdevicemetrics.h" -#include "ntqpainter.h" +#include "tqpaintdevicemetrics.h" +#include "tqpainter.h" #include "tqbitmap.h" #include "tqimage.h" #include "tqobjectlist.h" @@ -95,7 +95,7 @@ extern Atom qt_net_wm_sync_request; extern bool qt_use_xsync; #endif -// defined in qfont_x11.cpp +// defined in tqfont_x11.cpp extern bool tqt_has_xft; int qt_x11_create_desktop_on_screen = -1; diff --git a/src/libqt.map b/src/libqt.map index 999b36eac..9965ec963 100644 --- a/src/libqt.map +++ b/src/libqt.map @@ -8,7 +8,7 @@ extern "C++" { TQClipboardWatcher::*; - QColorLuminancePicker::*; + TQColorLuminancePicker::*; QErrorMessageTextView::*; QETWidget::*; QFDProgress*; @@ -40,9 +40,9 @@ QViewportWidget::*; QWFlagWidget::*; TQWorkspaceChild::*; - QFontDef::*; - QFontStruct::*; - QFont*Codec::*; + TQFontDef::*; + TQFontStruct::*; + TQFont*Codec::*; QInputContext::* }; TT_*; diff --git a/src/opengl/ntqglcolormap.h b/src/opengl/ntqglcolormap.h index a4b2ae0d3..61fbd7c79 100644 --- a/src/opengl/ntqglcolormap.h +++ b/src/opengl/ntqglcolormap.h @@ -42,7 +42,7 @@ #define TQGLCOLORMAP_H #ifndef QT_H -#include "ntqcolor.h" +#include "tqcolor.h" #include "tqmemarray.h" #include "ntqshared.h" #endif // QT_H diff --git a/src/opengl/qgl.cpp b/src/opengl/qgl.cpp index 0436c01c2..8c327941e 100644 --- a/src/opengl/qgl.cpp +++ b/src/opengl/qgl.cpp @@ -40,7 +40,7 @@ #include "ntqgl.h" #include "ntqpixmap.h" -#include "ntqpaintdevicemetrics.h" +#include "tqpaintdevicemetrics.h" #include "tqimage.h" #include "ntqcleanuphandler.h" #include "tqptrdict.h" diff --git a/src/opengl/qgl_x11.cpp b/src/opengl/qgl_x11.cpp index 661c41917..938228346 100644 --- a/src/opengl/qgl_x11.cpp +++ b/src/opengl/qgl_x11.cpp @@ -47,7 +47,7 @@ #include "ntqapplication.h" #include "tqintdict.h" -#include "private/qfontengine_p.h" +#include "private/tqfontengine_p.h" #define INT8 dummy_INT8 #define INT32 dummy_INT32 diff --git a/src/sql/tqdatatable.cpp b/src/sql/tqdatatable.cpp index 9abbc0f9d..20aa7a84b 100644 --- a/src/sql/tqdatatable.cpp +++ b/src/sql/tqdatatable.cpp @@ -47,7 +47,7 @@ #include "tqsqlpropertymap.h" #include "ntqapplication.h" #include "ntqlayout.h" -#include "ntqpainter.h" +#include "tqpainter.h" #include "tqpopupmenu.h" #include "tqvaluelist.h" #include "tqsqlmanager_p.h" diff --git a/src/styles/qcdestyle.cpp b/src/styles/qcdestyle.cpp index 2f49aa752..b258cb679 100644 --- a/src/styles/qcdestyle.cpp +++ b/src/styles/qcdestyle.cpp @@ -42,7 +42,7 @@ #if !defined(TQT_NO_STYLE_CDE) || defined(QT_PLUGIN) -#include "ntqpainter.h" +#include "tqpainter.h" #include "ntqdrawutil.h" #include "ntqbutton.h" #include diff --git a/src/styles/qcommonstyle.cpp b/src/styles/qcommonstyle.cpp index acdf61761..bf3d03f7f 100644 --- a/src/styles/qcommonstyle.cpp +++ b/src/styles/qcommonstyle.cpp @@ -45,7 +45,7 @@ #include "tqmutex.h" #include "tqmenubar.h" #include "ntqapplication.h" -#include "ntqpainter.h" +#include "tqpainter.h" #include "ntqdrawutil.h" #include "ntqpixmap.h" #include "ntqpushbutton.h" diff --git a/src/styles/qcompactstyle.cpp b/src/styles/qcompactstyle.cpp index 4df2fc10f..32dcdb217 100644 --- a/src/styles/qcompactstyle.cpp +++ b/src/styles/qcompactstyle.cpp @@ -42,9 +42,9 @@ #if !defined(TQT_NO_STYLE_COMPACT) || defined(QT_PLUGIN) -#include "ntqfontmetrics.h" +#include "tqfontmetrics.h" #include "ntqpalette.h" -#include "ntqpainter.h" +#include "tqpainter.h" #include "ntqdrawutil.h" #include "tqmenudata.h" #include "tqpopupmenu.h" diff --git a/src/styles/qinterlacestyle.cpp b/src/styles/qinterlacestyle.cpp index b506f1243..cb6aa1124 100644 --- a/src/styles/qinterlacestyle.cpp +++ b/src/styles/qinterlacestyle.cpp @@ -45,7 +45,7 @@ #if !defined(TQT_NO_STYLE_INTERLACE) || defined(QT_PLUGIN) #include "ntqapplication.h" -#include "ntqpainter.h" +#include "tqpainter.h" #include "ntqdrawutil.h" // for now #include "ntqpalette.h" // for now #include "tqwidget.h" diff --git a/src/styles/qmotifplusstyle.cpp b/src/styles/qmotifplusstyle.cpp index 2d081c22a..08308f1ff 100644 --- a/src/styles/qmotifplusstyle.cpp +++ b/src/styles/qmotifplusstyle.cpp @@ -44,7 +44,7 @@ #include "tqmenubar.h" #include "ntqapplication.h" -#include "ntqpainter.h" +#include "tqpainter.h" #include "ntqpalette.h" #include "ntqframe.h" #include "ntqpushbutton.h" diff --git a/src/styles/qmotifstyle.cpp b/src/styles/qmotifstyle.cpp index b412a2442..05424c3f4 100644 --- a/src/styles/qmotifstyle.cpp +++ b/src/styles/qmotifstyle.cpp @@ -44,7 +44,7 @@ #include "tqpopupmenu.h" #include "ntqapplication.h" -#include "ntqpainter.h" +#include "tqpainter.h" #include "ntqdrawutil.h" #include "ntqpixmap.h" #include "ntqpalette.h" diff --git a/src/styles/qplatinumstyle.cpp b/src/styles/qplatinumstyle.cpp index 097198f7b..ebaf85229 100644 --- a/src/styles/qplatinumstyle.cpp +++ b/src/styles/qplatinumstyle.cpp @@ -45,7 +45,7 @@ #include "ntqapplication.h" #include "ntqcombobox.h" #include "ntqdrawutil.h" -#include "ntqpainter.h" +#include "tqpainter.h" #include "ntqpalette.h" #include "ntqpixmap.h" #include "ntqpushbutton.h" diff --git a/src/styles/qsgistyle.cpp b/src/styles/qsgistyle.cpp index 914c508b0..2b273eeaf 100644 --- a/src/styles/qsgistyle.cpp +++ b/src/styles/qsgistyle.cpp @@ -45,7 +45,7 @@ #include "tqpopupmenu.h" #include "ntqapplication.h" #include "ntqbutton.h" -#include "ntqpainter.h" +#include "tqpainter.h" #include "ntqdrawutil.h" #include "ntqpixmap.h" #include "ntqpalette.h" diff --git a/src/styles/qwindowsstyle.cpp b/src/styles/qwindowsstyle.cpp index f8af1f282..efc2597d9 100644 --- a/src/styles/qwindowsstyle.cpp +++ b/src/styles/qwindowsstyle.cpp @@ -44,7 +44,7 @@ #include "tqpopupmenu.h" #include "ntqapplication.h" -#include "ntqpainter.h" +#include "tqpainter.h" #include "ntqdrawutil.h" // for now #include "ntqpixmap.h" // for now #include "tqwidget.h" diff --git a/src/table/qtable.cpp b/src/table/qtable.cpp index 4d00dbe9e..25f906776 100644 --- a/src/table/qtable.cpp +++ b/src/table/qtable.cpp @@ -48,7 +48,7 @@ #ifndef TQT_NO_TABLE -#include +#include #include #include #include diff --git a/src/tools/qfeatures.txt b/src/tools/qfeatures.txt index 2d4027527..e6c69180d 100644 --- a/src/tools/qfeatures.txt +++ b/src/tools/qfeatures.txt @@ -308,7 +308,7 @@ SeeAlso: ??? Feature: FONTDATABASE Section: Fonts Requires: STRINGLIST -Name: QFontDatabase +Name: TQFontDatabase SeeAlso: ??? Feature: TRANSLATION @@ -982,7 +982,7 @@ SeeAlso: ??? Feature: COLORDIALOG Section: Widgets Requires: DIALOG LABEL PUSHBUTTON LINEEDIT VALIDATOR GRIDVIEW LAYOUT -Name: QColorDialog +Name: TQColorDialog SeeAlso: ??? Feature: MESSAGEBOX @@ -1012,7 +1012,7 @@ SeeAlso: ??? Feature: FONTDIALOG Section: Widgets Requires: DIALOG FONTDATABASE COMBOBOX LABEL CHECKBOX PUSHBUTTON VGROUPBOX VALIDATOR -Name: QFontDialog +Name: TQFontDialog SeeAlso: ??? Feature: PRINTDIALOG diff --git a/src/tools/qunicodetables.cpp b/src/tools/qunicodetables.cpp index bb4c58a66..b442bcbff 100644 --- a/src/tools/qunicodetables.cpp +++ b/src/tools/qunicodetables.cpp @@ -13129,8 +13129,8 @@ enum Script { UnknownScript = NScripts }; -// copied form ntqfont.h, as we can't include it in tools. Do not modify without -// changing the script enum in ntqfont.h aswell. +// copied form tqfont.h, as we can't include it in tools. Do not modify without +// changing the script enum in tqfont.h aswell. const unsigned char TQUnicodeTables::otherScripts [128] = { #define SCRIPTS_02 0 0xaf, Latin, 0xff, SpacingModifiers, // row 0x02, index 0 diff --git a/src/widgets/ntqsyntaxhighlighter.h b/src/widgets/ntqsyntaxhighlighter.h index aa4c1ada2..81556553e 100644 --- a/src/widgets/ntqsyntaxhighlighter.h +++ b/src/widgets/ntqsyntaxhighlighter.h @@ -42,8 +42,8 @@ #define TQSYNTAXHIGHLIGHTER_H #ifndef QT_H -#include "ntqfont.h" -#include "ntqcolor.h" +#include "tqfont.h" +#include "tqcolor.h" #include "tqstring.h" #endif // QT_H diff --git a/src/widgets/qbutton.cpp b/src/widgets/qbutton.cpp index edc62375e..a74074121 100644 --- a/src/widgets/qbutton.cpp +++ b/src/widgets/qbutton.cpp @@ -42,7 +42,7 @@ #ifndef TQT_NO_BUTTON #include "ntqbuttongroup.h" #include "tqbitmap.h" -#include "ntqpainter.h" +#include "tqpainter.h" #include "tqtimer.h" #include "ntqaccel.h" #include "ntqpixmapcache.h" diff --git a/src/widgets/qcheckbox.cpp b/src/widgets/qcheckbox.cpp index 7c749998a..00e87041c 100644 --- a/src/widgets/qcheckbox.cpp +++ b/src/widgets/qcheckbox.cpp @@ -40,7 +40,7 @@ #include "ntqcheckbox.h" #ifndef TQT_NO_CHECKBOX -#include "ntqpainter.h" +#include "tqpainter.h" #include "ntqdrawutil.h" #include "ntqpixmap.h" #include "ntqpixmapcache.h" diff --git a/src/widgets/qcombobox.cpp b/src/widgets/qcombobox.cpp index 2e2be8d8f..3a7153f23 100644 --- a/src/widgets/qcombobox.cpp +++ b/src/widgets/qcombobox.cpp @@ -42,7 +42,7 @@ #ifndef TQT_NO_COMBOBOX #include "tqpopupmenu.h" #include "ntqlistbox.h" -#include "ntqpainter.h" +#include "tqpainter.h" #include "ntqdrawutil.h" #include "tqstrlist.h" #include "ntqpixmap.h" diff --git a/src/widgets/qdial.cpp b/src/widgets/qdial.cpp index 741f2c70b..8e2a63b5a 100644 --- a/src/widgets/qdial.cpp +++ b/src/widgets/qdial.cpp @@ -42,9 +42,9 @@ #ifndef TQT_NO_DIAL -#include "ntqpainter.h" +#include "tqpainter.h" #include "ntqpointarray.h" -#include "ntqcolor.h" +#include "tqcolor.h" #include "ntqapplication.h" #include "ntqregion.h" #include "tqbitmap.h" @@ -54,7 +54,7 @@ #endif #include // sin(), cos(), atan() -//### Forutsetter linking med math lib - Jfr kommentar i qpainter_x11.cpp! +//### Forutsetter linking med math lib - Jfr kommentar i tqpainter_x11.cpp! static const double m_pi = 3.14159265358979323846; static const double rad_factor = 180.0 / m_pi; diff --git a/src/widgets/qdockarea.cpp b/src/widgets/qdockarea.cpp index 65b2fe8ae..07ebbaa03 100644 --- a/src/widgets/qdockarea.cpp +++ b/src/widgets/qdockarea.cpp @@ -45,7 +45,7 @@ #include "ntqlayout.h" #include "tqptrvector.h" #include "ntqapplication.h" -#include "ntqpainter.h" +#include "tqpainter.h" #include "tqwidgetlist.h" #include "tqmap.h" #include "tqmainwindow.h" diff --git a/src/widgets/qdockwindow.cpp b/src/widgets/qdockwindow.cpp index df2c2cd7c..c7f6af826 100644 --- a/src/widgets/qdockwindow.cpp +++ b/src/widgets/qdockwindow.cpp @@ -45,7 +45,7 @@ #include "ntqdockarea.h" #include "tqwidgetresizehandler_p.h" #include "qtitlebar_p.h" -#include "ntqpainter.h" +#include "tqpainter.h" #include "ntqapplication.h" #include "tqtoolbutton.h" #include "tqtoolbar.h" diff --git a/src/widgets/qframe.cpp b/src/widgets/qframe.cpp index 4ab1e729e..c07820400 100644 --- a/src/widgets/qframe.cpp +++ b/src/widgets/qframe.cpp @@ -40,7 +40,7 @@ #include "ntqframe.h" #ifndef TQT_NO_FRAME -#include "ntqpainter.h" +#include "tqpainter.h" #include "ntqdrawutil.h" #include "ntqframe.h" #include "tqbitmap.h" diff --git a/src/widgets/qgridview.cpp b/src/widgets/qgridview.cpp index 8776ba843..7210a4d81 100644 --- a/src/widgets/qgridview.cpp +++ b/src/widgets/qgridview.cpp @@ -43,7 +43,7 @@ #ifndef TQT_NO_GRIDVIEW -#include "ntqpainter.h" +#include "tqpainter.h" /*! \class TQGridView ntqgridview.h diff --git a/src/widgets/qgroupbox.cpp b/src/widgets/qgroupbox.cpp index 2803c6760..5145a5698 100644 --- a/src/widgets/qgroupbox.cpp +++ b/src/widgets/qgroupbox.cpp @@ -41,7 +41,7 @@ #include "ntqgroupbox.h" #ifndef TQT_NO_GROUPBOX #include "ntqlayout.h" -#include "ntqpainter.h" +#include "tqpainter.h" #include "tqbitmap.h" #include "ntqaccel.h" #include "ntqradiobutton.h" diff --git a/src/widgets/qheader.cpp b/src/widgets/qheader.cpp index 848ea25cc..c01ae5cc5 100644 --- a/src/widgets/qheader.cpp +++ b/src/widgets/qheader.cpp @@ -40,7 +40,7 @@ #include "ntqheader.h" #ifndef TQT_NO_HEADER -#include "ntqpainter.h" +#include "tqpainter.h" #include "ntqdrawutil.h" #include "ntqpixmap.h" #include "tqbitarray.h" diff --git a/src/widgets/qlabel.cpp b/src/widgets/qlabel.cpp index 948dab440..87ba9da9e 100644 --- a/src/widgets/qlabel.cpp +++ b/src/widgets/qlabel.cpp @@ -40,10 +40,10 @@ #include "ntqlabel.h" #ifndef TQT_NO_LABEL -#include "ntqpainter.h" +#include "tqpainter.h" #include "ntqdrawutil.h" #include "ntqaccel.h" -#include "ntqmovie.h" +#include "tqmovie.h" #include "tqimage.h" #include "tqbitmap.h" #include "ntqpicture.h" diff --git a/src/widgets/qlcdnumber.cpp b/src/widgets/qlcdnumber.cpp index 2036e3a80..246804f45 100644 --- a/src/widgets/qlcdnumber.cpp +++ b/src/widgets/qlcdnumber.cpp @@ -41,7 +41,7 @@ #include "ntqlcdnumber.h" #ifndef TQT_NO_LCDNUMBER #include "tqbitarray.h" -#include "ntqpainter.h" +#include "tqpainter.h" /*! diff --git a/src/widgets/qlineedit.cpp b/src/widgets/qlineedit.cpp index 787f20926..5a3a43ae7 100644 --- a/src/widgets/qlineedit.cpp +++ b/src/widgets/qlineedit.cpp @@ -46,9 +46,9 @@ #include "ntqinputcontext.h" #endif -#include "ntqpainter.h" +#include "tqpainter.h" #include "ntqdrawutil.h" -#include "ntqfontmetrics.h" +#include "tqfontmetrics.h" #include "ntqpixmap.h" #include "tqclipboard.h" #include "ntqapplication.h" diff --git a/src/widgets/qlistbox.cpp b/src/widgets/qlistbox.cpp index 16e1870af..e9167ed62 100644 --- a/src/widgets/qlistbox.cpp +++ b/src/widgets/qlistbox.cpp @@ -47,8 +47,8 @@ #include "ntqlistbox.h" #ifndef TQT_NO_LISTBOX #include "tqmemarray.h" -#include "ntqfontmetrics.h" -#include "ntqpainter.h" +#include "tqfontmetrics.h" +#include "tqpainter.h" #include "tqstrlist.h" #include "ntqpixmap.h" #include "ntqapplication.h" diff --git a/src/widgets/qlistview.cpp b/src/widgets/qlistview.cpp index e0ad57d87..0ad2bc374 100644 --- a/src/widgets/qlistview.cpp +++ b/src/widgets/qlistview.cpp @@ -42,7 +42,7 @@ #ifndef TQT_NO_LISTVIEW #include "tqtimer.h" #include "ntqheader.h" -#include "ntqpainter.h" +#include "tqpainter.h" #include "ntqcursor.h" #include "tqptrstack.h" #include "tqptrlist.h" diff --git a/src/widgets/qmultilineedit.cpp b/src/widgets/qmultilineedit.cpp index e19cae977..a0a7ebee3 100644 --- a/src/widgets/qmultilineedit.cpp +++ b/src/widgets/qmultilineedit.cpp @@ -40,7 +40,7 @@ #include "ntqmultilineedit.h" #ifndef TQT_NO_MULTILINEEDIT -#include "ntqpainter.h" +#include "tqpainter.h" #include "ntqscrollbar.h" #include "ntqcursor.h" #include "tqclipboard.h" diff --git a/src/widgets/qprogressbar.cpp b/src/widgets/qprogressbar.cpp index 86616f0c3..c40bb19e9 100644 --- a/src/widgets/qprogressbar.cpp +++ b/src/widgets/qprogressbar.cpp @@ -40,7 +40,7 @@ #include "ntqprogressbar.h" #ifndef TQT_NO_PROGRESSBAR -#include "ntqpainter.h" +#include "tqpainter.h" #include "ntqdrawutil.h" #include "ntqpixmap.h" #include "tqstyle.h" diff --git a/src/widgets/qpushbutton.cpp b/src/widgets/qpushbutton.cpp index c9c01b86b..d87473237 100644 --- a/src/widgets/qpushbutton.cpp +++ b/src/widgets/qpushbutton.cpp @@ -41,8 +41,8 @@ #include "ntqpushbutton.h" #ifndef TQT_NO_PUSHBUTTON #include "ntqdialog.h" -#include "ntqfontmetrics.h" -#include "ntqpainter.h" +#include "tqfontmetrics.h" +#include "tqpainter.h" #include "ntqdrawutil.h" #include "ntqpixmap.h" #include "tqbitmap.h" diff --git a/src/widgets/qradiobutton.cpp b/src/widgets/qradiobutton.cpp index 681610ffe..a0baddeee 100644 --- a/src/widgets/qradiobutton.cpp +++ b/src/widgets/qradiobutton.cpp @@ -41,7 +41,7 @@ #include "ntqradiobutton.h" #ifndef TQT_NO_RADIOBUTTON #include "ntqbuttongroup.h" -#include "ntqpainter.h" +#include "tqpainter.h" #include "ntqdrawutil.h" #include "ntqpixmap.h" #include "ntqpixmapcache.h" diff --git a/src/widgets/qscrollbar.cpp b/src/widgets/qscrollbar.cpp index 58cb9a3bd..2b350c30a 100644 --- a/src/widgets/qscrollbar.cpp +++ b/src/widgets/qscrollbar.cpp @@ -40,7 +40,7 @@ #include "ntqscrollbar.h" #ifndef TQT_NO_SCROLLBAR -#include "ntqpainter.h" +#include "tqpainter.h" #include "tqbitmap.h" #include "ntqapplication.h" #include "tqtimer.h" diff --git a/src/widgets/qscrollview.cpp b/src/widgets/qscrollview.cpp index a07a3cce5..939f4da12 100644 --- a/src/widgets/qscrollview.cpp +++ b/src/widgets/qscrollview.cpp @@ -42,7 +42,7 @@ #ifndef TQT_NO_SCROLLVIEW #include "ntqscrollbar.h" #include "tqobjectlist.h" -#include "ntqpainter.h" +#include "tqpainter.h" #include "ntqpixmap.h" #include "ntqcursor.h" #include "ntqfocusdata.h" diff --git a/src/widgets/qslider.cpp b/src/widgets/qslider.cpp index 902fda036..df7555031 100644 --- a/src/widgets/qslider.cpp +++ b/src/widgets/qslider.cpp @@ -40,7 +40,7 @@ #include "ntqslider.h" #ifndef TQT_NO_SLIDER -#include "ntqpainter.h" +#include "tqpainter.h" #include "ntqdrawutil.h" #include "tqtimer.h" #include "tqbitmap.h" diff --git a/src/widgets/qspinbox.cpp b/src/widgets/qspinbox.cpp index d068a581b..f11d42c8c 100644 --- a/src/widgets/qspinbox.cpp +++ b/src/widgets/qspinbox.cpp @@ -43,7 +43,7 @@ #include "ntqcursor.h" #include "ntqpushbutton.h" -#include "ntqpainter.h" +#include "tqpainter.h" #include "tqbitmap.h" #include "ntqlineedit.h" #include "ntqvalidator.h" diff --git a/src/widgets/qspinwidget.cpp b/src/widgets/qspinwidget.cpp index e2d67796d..f46dfc40f 100644 --- a/src/widgets/qspinwidget.cpp +++ b/src/widgets/qspinwidget.cpp @@ -43,7 +43,7 @@ #include "ntqrect.h" #include "tqtimer.h" #include "tqstyle.h" -#include "ntqpainter.h" +#include "tqpainter.h" class TQSpinWidgetPrivate { diff --git a/src/widgets/qsplashscreen.cpp b/src/widgets/qsplashscreen.cpp index 6468a2508..fa9e6a49d 100644 --- a/src/widgets/qsplashscreen.cpp +++ b/src/widgets/qsplashscreen.cpp @@ -41,7 +41,7 @@ #ifndef TQT_NO_SPLASHSCREEN #include "ntqapplication.h" -#include "ntqpainter.h" +#include "tqpainter.h" #include "ntqpixmap.h" class TQSplashScreenPrivate diff --git a/src/widgets/qsplitter.cpp b/src/widgets/qsplitter.cpp index 0994e892a..2a4a193bb 100644 --- a/src/widgets/qsplitter.cpp +++ b/src/widgets/qsplitter.cpp @@ -48,7 +48,7 @@ #include "ntqdrawutil.h" #include "tqmemarray.h" #include "tqobjectlist.h" -#include "ntqpainter.h" +#include "tqpainter.h" #include "tqptrlist.h" #include "tqstyle.h" diff --git a/src/widgets/qtabbar.cpp b/src/widgets/qtabbar.cpp index 50c452489..e740a4782 100644 --- a/src/widgets/qtabbar.cpp +++ b/src/widgets/qtabbar.cpp @@ -44,7 +44,7 @@ #include "tqtooltip.h" #include "ntqapplication.h" #include "tqstyle.h" -#include "ntqpainter.h" +#include "tqpainter.h" #include "tqiconset.h" #include "ntqcursor.h" #include "../kernel/qinternal_p.h" diff --git a/src/widgets/qtabwidget.cpp b/src/widgets/qtabwidget.cpp index be6186222..bd698765f 100644 --- a/src/widgets/qtabwidget.cpp +++ b/src/widgets/qtabwidget.cpp @@ -47,7 +47,7 @@ #include "tqbitmap.h" #include "ntqaccel.h" #include "tqstyle.h" -#include "ntqpainter.h" +#include "tqpainter.h" #include "tqtoolbutton.h" #ifdef Q_OS_MACX diff --git a/src/widgets/qtitlebar.cpp b/src/widgets/qtitlebar.cpp index 444a12115..c97c47320 100644 --- a/src/widgets/qtitlebar.cpp +++ b/src/widgets/qtitlebar.cpp @@ -52,7 +52,7 @@ #include "tqtooltip.h" #include "tqimage.h" #include "tqtimer.h" -#include "ntqpainter.h" +#include "tqpainter.h" #include "tqstyle.h" #include "private/qinternal_p.h" #ifndef TQT_NO_WORKSPACE diff --git a/src/widgets/qwhatsthis.cpp b/src/widgets/qwhatsthis.cpp index 41f9aa9d5..82f645830 100644 --- a/src/widgets/qwhatsthis.cpp +++ b/src/widgets/qwhatsthis.cpp @@ -39,9 +39,9 @@ #include "ntqwhatsthis.h" #ifndef TQT_NO_WHATSTHIS #include "ntqapplication.h" -#include "ntqpaintdevicemetrics.h" +#include "tqpaintdevicemetrics.h" #include "ntqpixmap.h" -#include "ntqpainter.h" +#include "tqpainter.h" #include "tqtimer.h" #include "tqptrdict.h" #include "tqtoolbutton.h" diff --git a/src/widgets/tqiconview.cpp b/src/widgets/tqiconview.cpp index 0c42ab611..f79ac974a 100644 --- a/src/widgets/tqiconview.cpp +++ b/src/widgets/tqiconview.cpp @@ -48,14 +48,14 @@ #ifndef TQT_NO_ICONVIEW -#include "ntqfontmetrics.h" -#include "ntqpainter.h" +#include "tqfontmetrics.h" +#include "tqpainter.h" #include "ntqevent.h" #include "ntqpalette.h" #include "tqmime.h" #include "tqimage.h" #include "ntqpen.h" -#include "ntqbrush.h" +#include "tqbrush.h" #include "tqtimer.h" #include "ntqcursor.h" #include "ntqapplication.h" diff --git a/src/widgets/tqiconview.h b/src/widgets/tqiconview.h index 7b52985b7..625f18d54 100644 --- a/src/widgets/tqiconview.h +++ b/src/widgets/tqiconview.h @@ -47,7 +47,7 @@ #include "ntqrect.h" #include "ntqpoint.h" #include "tqsize.h" -#include "ntqfont.h" // TQString->TQFont conversion +#include "tqfont.h" // TQString->TQFont conversion #include "tqdragobject.h" #include "tqbitmap.h" #include "ntqpicture.h" diff --git a/src/widgets/tqmainwindow.cpp b/src/widgets/tqmainwindow.cpp index be6f08cd2..071a330ff 100644 --- a/src/widgets/tqmainwindow.cpp +++ b/src/widgets/tqmainwindow.cpp @@ -49,7 +49,7 @@ #include "tqptrlist.h" #include "tqmap.h" #include "ntqcursor.h" -#include "ntqpainter.h" +#include "tqpainter.h" #include "tqmenubar.h" #include "tqpopupmenu.h" #include "tqtoolbar.h" diff --git a/src/widgets/tqmenubar.cpp b/src/widgets/tqmenubar.cpp index 82734d688..1f1dc08c5 100644 --- a/src/widgets/tqmenubar.cpp +++ b/src/widgets/tqmenubar.cpp @@ -46,7 +46,7 @@ #include "tqmenubar.h" #include "tqpopupmenu.h" #include "ntqaccel.h" -#include "ntqpainter.h" +#include "tqpainter.h" #include "ntqdrawutil.h" #include "ntqapplication.h" #include "ntqguardedptr.h" diff --git a/src/widgets/tqmenudata.h b/src/widgets/tqmenudata.h index 69ab1ca5b..5abace6a2 100644 --- a/src/widgets/tqmenudata.h +++ b/src/widgets/tqmenudata.h @@ -47,7 +47,7 @@ #include "ntqkeysequence.h" #include "tqstring.h" #include "tqsignal.h" -#include "ntqfont.h" +#include "tqfont.h" #endif // QT_H #ifndef TQT_NO_MENUDATA diff --git a/src/widgets/tqpopupmenu.cpp b/src/widgets/tqpopupmenu.cpp index 2da9a89de..5be453508 100644 --- a/src/widgets/tqpopupmenu.cpp +++ b/src/widgets/tqpopupmenu.cpp @@ -42,7 +42,7 @@ #ifndef TQT_NO_POPUPMENU #include "tqmenubar.h" #include "ntqaccel.h" -#include "ntqpainter.h" +#include "tqpainter.h" #include "ntqdrawutil.h" #include "ntqapplication.h" #include "ntqpixmap.h" diff --git a/src/widgets/tqstatusbar.cpp b/src/widgets/tqstatusbar.cpp index d4193d937..746f45e5a 100644 --- a/src/widgets/tqstatusbar.cpp +++ b/src/widgets/tqstatusbar.cpp @@ -43,7 +43,7 @@ #include "tqptrlist.h" #include "ntqlayout.h" -#include "ntqpainter.h" +#include "tqpainter.h" #include "tqtimer.h" #include "ntqdrawutil.h" #include "tqstyle.h" diff --git a/src/widgets/tqtextbrowser.cpp b/src/widgets/tqtextbrowser.cpp index 03152ac1a..fd4bced0a 100644 --- a/src/widgets/tqtextbrowser.cpp +++ b/src/widgets/tqtextbrowser.cpp @@ -44,7 +44,7 @@ #include "ntqapplication.h" #include "ntqlayout.h" -#include "ntqpainter.h" +#include "tqpainter.h" #include "tqvaluestack.h" #include "stdio.h" diff --git a/src/widgets/tqtextbrowser.h b/src/widgets/tqtextbrowser.h index c68031ff1..659ff5d15 100644 --- a/src/widgets/tqtextbrowser.h +++ b/src/widgets/tqtextbrowser.h @@ -44,7 +44,7 @@ #ifndef QT_H #include "tqptrlist.h" #include "ntqpixmap.h" -#include "ntqcolor.h" +#include "tqcolor.h" #include "tqtextedit.h" #endif // QT_H diff --git a/src/widgets/tqtextedit.cpp b/src/widgets/tqtextedit.cpp index dd7c1116b..a966110ce 100644 --- a/src/widgets/tqtextedit.cpp +++ b/src/widgets/tqtextedit.cpp @@ -48,12 +48,12 @@ #endif #include "../kernel/qrichtext_p.h" -#include "ntqpainter.h" +#include "tqpainter.h" #include "ntqpen.h" -#include "ntqbrush.h" +#include "tqbrush.h" #include "ntqpixmap.h" -#include "ntqfont.h" -#include "ntqcolor.h" +#include "tqfont.h" +#include "tqcolor.h" #include "tqstyle.h" #include "tqsize.h" #include "ntqevent.h" @@ -63,8 +63,8 @@ #include "ntqvbox.h" #include "ntqapplication.h" #include "tqclipboard.h" -#include "ntqcolordialog.h" -#include "ntqfontdialog.h" +#include "tqcolordialog.h" +#include "tqfontdialog.h" #include "tqstylesheet.h" #include "tqdragobject.h" #include "tqurl.h" diff --git a/src/widgets/tqtoolbar.cpp b/src/widgets/tqtoolbar.cpp index 819bc0e5e..a94185bec 100644 --- a/src/widgets/tqtoolbar.cpp +++ b/src/widgets/tqtoolbar.cpp @@ -47,7 +47,7 @@ #include "ntqlayout.h" #include "ntqframe.h" #include "tqobjectlist.h" -#include "ntqpainter.h" +#include "tqpainter.h" #include "ntqdrawutil.h" #include "tqtoolbutton.h" #include "tqpopupmenu.h" diff --git a/src/widgets/tqtoolbox.cpp b/src/widgets/tqtoolbox.cpp index f67486a4a..17580a0e7 100644 --- a/src/widgets/tqtoolbox.cpp +++ b/src/widgets/tqtoolbox.cpp @@ -45,7 +45,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/src/widgets/tqtoolbutton.cpp b/src/widgets/tqtoolbutton.cpp index 222c608a7..78becfbe3 100644 --- a/src/widgets/tqtoolbutton.cpp +++ b/src/widgets/tqtoolbutton.cpp @@ -42,7 +42,7 @@ #ifndef TQT_NO_TOOLBUTTON #include "ntqdrawutil.h" -#include "ntqpainter.h" +#include "tqpainter.h" #include "ntqpixmap.h" #include "ntqwmatrix.h" #include "ntqapplication.h" diff --git a/src/xml/qsvgdevice.cpp b/src/xml/qsvgdevice.cpp index 9997a741d..4de514c42 100644 --- a/src/xml/qsvgdevice.cpp +++ b/src/xml/qsvgdevice.cpp @@ -40,8 +40,8 @@ #ifndef TQT_NO_SVG -#include "ntqpainter.h" -#include "ntqpaintdevicemetrics.h" +#include "tqpainter.h" +#include "tqpaintdevicemetrics.h" #include "tqfile.h" #include "tqmap.h" #include "tqregexp.h" diff --git a/src/xml/qsvgdevice_p.h b/src/xml/qsvgdevice_p.h index cf56c649f..c70fbe43d 100644 --- a/src/xml/qsvgdevice_p.h +++ b/src/xml/qsvgdevice_p.h @@ -54,7 +54,7 @@ // #ifndef QT_H -#include "ntqpaintdevice.h" +#include "tqpaintdevice.h" #include "ntqrect.h" #include "tqdom.h" #endif // QT_H -- cgit v1.2.1