summaryrefslogtreecommitdiff
path: root/freetype
authorkergoth <kergoth>2002-01-25 22:14:26 (UTC)
committer kergoth <kergoth>2002-01-25 22:14:26 (UTC)
commit15318cad33835e4e2dc620d033e43cd930676cdd (patch) (side-by-side diff)
treec2fa0399a2c47fda8e2cd0092c73a809d17f68eb /freetype
downloadopie-15318cad33835e4e2dc620d033e43cd930676cdd.zip
opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.gz
opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.bz2
Initial revision
Diffstat (limited to 'freetype') (more/less context) (ignore whitespace changes)
-rw-r--r--freetype/Makefile.in117
-rw-r--r--freetype/fontfactoryttf_qws.cpp238
-rw-r--r--freetype/fontfactoryttf_qws.h64
-rw-r--r--freetype/freetype.pro13
-rw-r--r--freetype/freetypefactoryimpl.cpp57
-rw-r--r--freetype/freetypefactoryimpl.h40
-rw-r--r--freetype/qfontdata_p.h94
7 files changed, 623 insertions, 0 deletions
diff --git a/freetype/Makefile.in b/freetype/Makefile.in
new file mode 100644
index 0000000..ba4c829
--- a/dev/null
+++ b/freetype/Makefile.in
@@ -0,0 +1,117 @@
+#############################################################################
+
+####### Compiler, tools and options
+
+CXX = $(SYSCONF_CXX) $(QT_CXX_MT)
+CXXFLAGS= $(SYSCONF_CXXFLAGS_QT) $(SYSCONF_CXXFLAGS) $(SYSCONF_CXXFLAGS_LIB)
+CC = $(SYSCONF_CC) $(QT_C_MT)
+CFLAGS = $(SYSCONF_CFLAGS) $(SYSCONF_CFLAGS_LIB)
+INCPATH = -I../library
+LFLAGS = $(SYSCONF_LFLAGS_QT) $(SYSCONF_RPATH_QT) $(SYSCONF_LFLAGS) $(QT_LFLAGS_MT)
+LIBS = $(SUBLIBS) -lqpe -lfreetype $(SYSCONF_LIBS_QT) $(SYSCONF_LIBS_QTAPP)
+MOC = $(SYSCONF_MOC)
+UIC = $(SYSCONF_UIC)
+
+####### Target
+
+DESTDIR = ../plugins/fontfactories/
+VER_MAJ = 1
+VER_MIN = 0
+VER_PATCH = 0
+TARGET = freetypefactory
+TARGET1 = lib$(TARGET).so.$(VER_MAJ)
+
+####### Files
+
+HEADERS = fontfactoryttf_qws.h \
+ freetypefactoryimpl.h \
+ qfontdata_p.h
+SOURCES = fontfactoryttf_qws.cpp \
+ freetypefactoryimpl.cpp
+OBJECTS = fontfactoryttf_qws.o \
+ freetypefactoryimpl.o
+INTERFACES =
+UICDECLS =
+UICIMPLS =
+SRCMOC =
+OBJMOC =
+
+
+####### Implicit rules
+
+.SUFFIXES: .cpp .cxx .cc .C .c
+
+.cpp.o:
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
+
+.cxx.o:
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
+
+.cc.o:
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
+
+.C.o:
+ $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
+
+.c.o:
+ $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $<
+
+####### Build rules
+
+
+all: $(DESTDIR)$(SYSCONF_LINK_TARGET)
+
+$(DESTDIR)$(SYSCONF_LINK_TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC) $(SUBLIBS)
+ $(SYSCONF_LINK_LIB)
+
+moc: $(SRCMOC)
+
+tmake: Makefile.in
+
+Makefile.in: freetype.pro
+ tmake freetype.pro -o Makefile.in
+
+clean:
+ -rm -f $(OBJECTS) $(OBJMOC) $(SRCMOC) $(UICIMPLS) $(UICDECLS)
+ -rm -f *~ core
+ -rm -f allmoc.cpp
+
+####### Extension Modules
+
+listpromodules:
+ @echo
+
+listallmodules:
+ @echo
+
+listaddonpromodules:
+ @echo
+
+listaddonentmodules:
+ @echo
+
+
+REQUIRES=
+
+####### Sub-libraries
+
+
+###### Combined headers
+
+
+
+####### Compile
+
+fontfactoryttf_qws.o: fontfactoryttf_qws.cpp \
+ fontfactoryttf_qws.h \
+ qfontdata_p.h
+
+freetypefactoryimpl.o: freetypefactoryimpl.cpp \
+ fontfactoryttf_qws.h \
+ qfontdata_p.h \
+ freetypefactoryimpl.h \
+ ../library/fontfactoryinterface.h \
+ ../library/qcom.h \
+ ../library/quuid.h
+
+
diff --git a/freetype/fontfactoryttf_qws.cpp b/freetype/fontfactoryttf_qws.cpp
new file mode 100644
index 0000000..66fd96a
--- a/dev/null
+++ b/freetype/fontfactoryttf_qws.cpp
@@ -0,0 +1,238 @@
+/**********************************************************************
+** Copyright (C) 2000 Trolltech AS. All rights reserved.
+**
+** This file is part of Qtopia Environment.
+**
+** This file may be distributed and/or modified under the terms of the
+** GNU General Public License version 2 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+** See http://www.trolltech.com/gpl/ for GPL licensing information.
+**
+** Contact info@trolltech.com if any conditions of this licensing are
+** not clear to you.
+**
+**********************************************************************/
+
+
+#include "fontfactoryttf_qws.h"
+
+#ifdef QT_NO_FREETYPE
+
+#include "qfontdata_p.h"
+#include <string.h>
+#include <stdio.h>
+
+#define FLOOR(x) ((x) & -64)
+#define CEIL(x) (((x)+63) & -64)
+#define TRUNC(x) ((x) >> 6)
+
+
+extern "C" {
+#include <ft2build.h>
+#include FT_FREETYPE_H
+#include FT_GLYPH_H
+#include FT_OUTLINE_H
+#include FT_BBOX_H
+}
+
+class QDiskFontFT : public QDiskFontPrivate {
+public:
+ FT_Face face;
+};
+
+class QRenderedFontFT : public QRenderedFont {
+public:
+ QRenderedFontFT(QDiskFont* f, const QFontDef &d) :
+ QRenderedFont(f,d)
+ {
+ QDiskFontFT *df = (QDiskFontFT*)(f->p);
+ myface=df->face;
+ selectThisSize();
+ // A 1-pixel baseline is excluded in Qt/Windows/X11 fontmetrics
+ // (see QFontMetrics::height())
+ //
+ fascent=CEIL(myface->size->metrics.ascender)/64;
+ fdescent=-FLOOR(myface->size->metrics.descender)/64-1;
+ fmaxwidth=CEIL(myface->size->metrics.max_advance)/64;
+ fleading=CEIL(myface->size->metrics.height)/64
+ - fascent - fdescent + 1;
+
+ // FT has these in font units
+ funderlinepos = ptsize/200+1;
+ funderlinewidth = ptsize/200+1;
+ }
+
+ ~QRenderedFontFT()
+ {
+ }
+
+ bool unicode(int & i) const
+ {
+ int ret;
+
+ FT_Face theface=myface;
+
+ ret=FT_Get_Char_Index(theface,i);
+
+ if (ret==0) {
+ return FALSE;
+ } else {
+ i=ret;
+ return TRUE;
+ }
+ }
+
+ bool inFont(QChar ch) const
+ {
+ int index = ch.unicode();
+ return unicode(index);
+ }
+
+ QGlyph render(QChar ch)
+ {
+ selectThisSize();
+
+ int index = ch.unicode();
+ if ( !unicode(index) )
+ index = 0;
+ QGlyph result;
+
+ FT_Error err;
+
+ err=FT_Load_Glyph(myface,index,FT_LOAD_DEFAULT);
+ if(err)
+ qFatal("Load glyph error %x",err);
+
+ int width,height,pitch,size = 0;
+ FT_Glyph glyph;
+ err=FT_Get_Glyph( myface->glyph, &glyph );
+ if(err)
+ qFatal("Get glyph error %x",err);
+
+ FT_BBox bbox;
+ FT_Glyph_Get_CBox(glyph, ft_glyph_bbox_gridfit, &bbox);
+
+ FT_Vector origin;
+ origin.x = -bbox.xMin;
+ origin.y = -bbox.yMin;
+
+ if ( FT_IS_SCALABLE(myface) ) {
+ err=FT_Glyph_To_Bitmap(&glyph,
+ smooth ? ft_render_mode_normal : ft_render_mode_mono,
+ &origin, 1); // destroy original glyph
+ if(err)
+ qWarning("Get bitmap error %d",err);
+ }
+
+ if ( !err ) {
+ FT_Bitmap bm = ((FT_BitmapGlyph)glyph)->bitmap;
+ pitch = bm.pitch;
+ size=pitch*bm.rows;
+ result.data = new uchar[size]; // XXX memory manage me
+ width=bm.width;
+ height=bm.rows;
+ if ( size ) {
+ memcpy( result.data, bm.buffer, size );
+ } else {
+ result.data = new uchar[0]; // XXX memory manage me
+ }
+ } else {
+ result.data = new uchar[0]; // XXX memory manage me
+ }
+
+ result.metrics = new QGlyphMetrics;
+ memset((char*)result.metrics, 0, sizeof(QGlyphMetrics));
+ result.metrics->bearingx=myface->glyph->metrics.horiBearingX/64;
+ result.metrics->advance=myface->glyph->metrics.horiAdvance/64;
+ result.metrics->bearingy=myface->glyph->metrics.horiBearingY/64;
+
+ result.metrics->linestep=pitch;
+ result.metrics->width=width;
+ result.metrics->height=height;
+
+ FT_Done_Glyph( glyph );
+
+ return result;
+ }
+
+ FT_Face myface;
+
+private:
+ void selectThisSize()
+ {
+ int psize=(ptsize<<6)/10;
+
+ // Assume 72 dpi for now
+ const int dpi=72;
+ FT_Error err;
+ err=FT_Set_Char_Size(myface, psize,psize,dpi,dpi);
+ if (err) {
+ if (FT_IS_SCALABLE(myface) ) {
+ qWarning("Set char size error %x for size %d",err,ptsize);
+ } else {
+ int best=-1;
+ int bdh=99;
+ for (int i=0; i<myface->num_fixed_sizes; i++) {
+ FT_Bitmap_Size& sz=myface->available_sizes[i];
+ int dh = sz.height - ptsize*dpi/72/10;
+ dh = QABS(dh);
+ if ( dh < bdh ) {
+ bdh=dh;
+ best=i;
+ }
+ }
+ if ( best >= 0 )
+ err=FT_Set_Pixel_Sizes(myface,
+ myface->available_sizes[best].width,
+ myface->available_sizes[best].height);
+ if ( err )
+ qWarning("Set char size error %x for size %d",err,ptsize);
+ }
+ }
+ }
+};
+
+QFontFactoryFT::QFontFactoryFT()
+{
+ FT_Error err;
+ err=FT_Init_FreeType(&library);
+ if(err) {
+ qFatal("Couldn't initialise Freetype library");
+ }
+}
+
+QFontFactoryFT::~QFontFactoryFT()
+{
+}
+
+QString QFontFactoryFT::name()
+{
+ return "FT";
+}
+
+QRenderedFont * QFontFactoryFT::get(const QFontDef & f,QDiskFont * f2)
+{
+ return new QRenderedFontFT(f2, f);
+}
+
+void QFontFactoryFT::load(QDiskFont * qdf) const
+{
+ if(qdf->loaded)
+ return;
+ QDiskFontFT *f = new QDiskFontFT;
+ qdf->p=f;
+ FT_Error err;
+ err=FT_New_Face(library,qdf->file.ascii(),0,&(f->face));
+ if(err) {
+ qFatal("Error %d opening face",err);
+ }
+ qdf->loaded=true;
+}
+
+
+#endif // QT_NO_FREETYPE
diff --git a/freetype/fontfactoryttf_qws.h b/freetype/fontfactoryttf_qws.h
new file mode 100644
index 0000000..82b7e49
--- a/dev/null
+++ b/freetype/fontfactoryttf_qws.h
@@ -0,0 +1,64 @@
+/**********************************************************************
+** Copyright (C) 2000 Trolltech AS. All rights reserved.
+**
+** This file is part of Qtopia Environment.
+**
+** This file may be distributed and/or modified under the terms of the
+** GNU General Public License version 2 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+** See http://www.trolltech.com/gpl/ for GPL licensing information.
+**
+** Contact info@trolltech.com if any conditions of this licensing are
+** not clear to you.
+**
+**********************************************************************/
+
+
+#ifndef FONTFACTORY_FT_H
+#define FONTFACTORY_FT_H
+
+#include <qfontmanager_qws.h>
+#if QT_VERSION >= 300
+# include <private/qfontdata_p.h>
+#else
+# include "qfontdata_p.h"
+#endif
+
+
+#ifdef QT_NO_FREETYPE
+
+extern "C" {
+#include <ft2build.h>
+#include FT_FREETYPE_H
+}
+
+// ascent, descent, width(ch), width(string), maxwidth?
+// leftbearing, rightbearing, minleftbearing,minrightbearing
+// leading
+
+class QFontFactoryFT : public QFontFactory {
+
+public:
+
+ QFontFactoryFT();
+ virtual ~QFontFactoryFT();
+
+ QRenderedFont * get(const QFontDef &,QDiskFont *);
+ virtual void load(QDiskFont *) const;
+ virtual QString name();
+
+private:
+
+ friend class QRenderedFontFT;
+ FT_Library library;
+};
+
+#endif // QT_NO_FREETYPE
+
+#endif // QFONTFACTORY_FT_H
+
diff --git a/freetype/freetype.pro b/freetype/freetype.pro
new file mode 100644
index 0000000..841f6d4
--- a/dev/null
+++ b/freetype/freetype.pro
@@ -0,0 +1,13 @@
+TEMPLATE = lib
+CONFIG += qt warn_on release
+HEADERS = fontfactoryttf_qws.h freetypefactoryimpl.h
+SOURCES = fontfactoryttf_qws.cpp freetypefactoryimpl.cpp
+qt2:HEADERS += qfontdata_p.h
+TARGET = freetypefactory
+DESTDIR = ../plugins/fontfactories
+INCLUDEPATH += $(QPEDIR)/include
+DEPENDPATH += $(QPEDIR)/include
+#INCLUDEPATH += $(QPEDIR)/include
+#DEPENDPATH += /usr/local/include/freetype2
+LIBS += -lqpe -lfreetype
+VERSION = 1.0.0
diff --git a/freetype/freetypefactoryimpl.cpp b/freetype/freetypefactoryimpl.cpp
new file mode 100644
index 0000000..8c1afab
--- a/dev/null
+++ b/freetype/freetypefactoryimpl.cpp
@@ -0,0 +1,57 @@
+/**********************************************************************
+** Copyright (C) 2000 Trolltech AS. All rights reserved.
+**
+** This file is part of Qtopia Environment.
+**
+** This file may be distributed and/or modified under the terms of the
+** GNU General Public License version 2 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+** See http://www.trolltech.com/gpl/ for GPL licensing information.
+**
+** Contact info@trolltech.com if any conditions of this licensing are
+** not clear to you.
+**
+**********************************************************************/
+#include "fontfactoryttf_qws.h"
+#include "freetypefactoryimpl.h"
+
+
+FreeTypeFactoryImpl::FreeTypeFactoryImpl()
+ : factory(0), ref(0)
+{
+}
+
+FreeTypeFactoryImpl::~FreeTypeFactoryImpl()
+{
+ delete factory;
+}
+
+QFontFactory *FreeTypeFactoryImpl::fontFactory()
+{
+ if ( !factory )
+ factory = new QFontFactoryFT();
+ return factory;
+}
+
+QRESULT FreeTypeFactoryImpl::queryInterface( const QUuid &uuid, QUnknownInterface **iface )
+{
+ *iface = 0;
+ if ( uuid == IID_QUnknown )
+ *iface = this;
+ else if ( uuid == IID_FontFactory )
+ *iface = this;
+
+ if ( *iface )
+ (*iface)->addRef();
+ return QS_OK;
+}
+
+Q_EXPORT_INTERFACE()
+{
+ Q_CREATE_INSTANCE( FreeTypeFactoryImpl )
+}
diff --git a/freetype/freetypefactoryimpl.h b/freetype/freetypefactoryimpl.h
new file mode 100644
index 0000000..d7c376e
--- a/dev/null
+++ b/freetype/freetypefactoryimpl.h
@@ -0,0 +1,40 @@
+/**********************************************************************
+** Copyright (C) 2000 Trolltech AS. All rights reserved.
+**
+** This file is part of Qtopia Environment.
+**
+** This file may be distributed and/or modified under the terms of the
+** GNU General Public License version 2 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+** See http://www.trolltech.com/gpl/ for GPL licensing information.
+**
+** Contact info@trolltech.com if any conditions of this licensing are
+** not clear to you.
+**
+**********************************************************************/
+
+
+#include <fontfactoryinterface.h>
+
+class QFontFactoryFT;
+
+class FreeTypeFactoryImpl : public FontFactoryInterface
+{
+public:
+ FreeTypeFactoryImpl();
+ virtual ~FreeTypeFactoryImpl();
+
+ QRESULT queryInterface( const QUuid&, QUnknownInterface** );
+ Q_REFCOUNT
+
+ virtual QFontFactory *fontFactory();
+
+private:
+ QFontFactoryFT *factory;
+ ulong ref;
+};
diff --git a/freetype/qfontdata_p.h b/freetype/qfontdata_p.h
new file mode 100644
index 0000000..fc22c72
--- a/dev/null
+++ b/freetype/qfontdata_p.h
@@ -0,0 +1,94 @@
+/**********************************************************************
+** Copyright (C) 2000 Trolltech AS. All rights reserved.
+**
+** This file is part of Qtopia Environment.
+**
+** This file may be distributed and/or modified under the terms of the
+** GNU General Public License version 2 as published by the Free Software
+** Foundation and appearing in the file LICENSE.GPL included in the
+** packaging of this file.
+**
+** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
+** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+**
+** See http://www.trolltech.com/gpl/ for GPL licensing information.
+**
+** Contact info@trolltech.com if any conditions of this licensing are
+** not clear to you.
+**
+**********************************************************************/
+
+
+#ifndef QFONTDATA_P_H
+#define QFONTDATA_P_H
+
+
+//
+// W A R N I N G
+// -------------
+//
+// This file is not part of the Qt API. It exists for the convenience
+// of qmenudata.cpp, qmenubar.cpp, qmenubar.cpp, qpopupmenu.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
+
+struct QFontDef { // font definition
+ QString family;
+ QString addStyle;
+ int pointSize;
+ uint styleHint : 8;
+ uint styleStrategy : 8;
+ uint charSet : 8;
+ uint weight : 8;
+ uint italic : 1;
+ uint underline : 1;
+ uint strikeOut : 1;
+ uint fixedPitch : 1;
+ uint hintSetByUser : 1;
+ uint rawMode : 1;
+ uint dirty : 1;
+ short lbearing;
+ short rbearing;
+};
+
+
+class QFontInternal;
+class QTextCodec;
+
+struct QFontData : public QShared {
+ QFontData()
+ : exactMatch(FALSE), fin(0), printerHackFont( 0 )
+ {}
+ QFontData( const QFontData &d )
+ : QShared(d), req(d.req), exactMatch(d.exactMatch), fin(d.fin),
+ printerHackFont(0)
+ // Copy the QShared count as well. The count may need to be
+ // reset when using the QFontData class, see QFont::QFont(QFontData*)
+ {}
+ ~QFontData()
+ {}
+ QFontData &operator=( const QFontData &d )
+ {
+ req = d.req;
+ exactMatch = d.exactMatch;
+ fin = d.fin;
+ printerHackFont=d.printerHackFont;
+ return *this;
+ }
+ QFontDef req; // requested font
+ bool exactMatch;
+ QFontInternal *fin;
+ QFont *printerHackFont;
+ const QTextCodec *mapper() const;
+ void *fontSet() const;
+};
+
+
+#endif // QFONTDATA_P_H