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) (unidiff)
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 @@
1#############################################################################
2
3####### Compiler, tools and options
4
5 CXX =$(SYSCONF_CXX) $(QT_CXX_MT)
6 CXXFLAGS=$(SYSCONF_CXXFLAGS_QT) $(SYSCONF_CXXFLAGS) $(SYSCONF_CXXFLAGS_LIB)
7 CC =$(SYSCONF_CC) $(QT_C_MT)
8 CFLAGS =$(SYSCONF_CFLAGS) $(SYSCONF_CFLAGS_LIB)
9 INCPATH =-I../library
10 LFLAGS =$(SYSCONF_LFLAGS_QT) $(SYSCONF_RPATH_QT) $(SYSCONF_LFLAGS) $(QT_LFLAGS_MT)
11 LIBS =$(SUBLIBS) -lqpe -lfreetype $(SYSCONF_LIBS_QT) $(SYSCONF_LIBS_QTAPP)
12 MOC =$(SYSCONF_MOC)
13 UIC =$(SYSCONF_UIC)
14
15####### Target
16
17DESTDIR = ../plugins/fontfactories/
18VER_MAJ = 1
19VER_MIN = 0
20VER_PATCH = 0
21 TARGET= freetypefactory
22TARGET1 = lib$(TARGET).so.$(VER_MAJ)
23
24####### Files
25
26 HEADERS =fontfactoryttf_qws.h \
27 freetypefactoryimpl.h \
28 qfontdata_p.h
29 SOURCES =fontfactoryttf_qws.cpp \
30 freetypefactoryimpl.cpp
31 OBJECTS =fontfactoryttf_qws.o \
32 freetypefactoryimpl.o
33INTERFACES =
34UICDECLS =
35UICIMPLS =
36 SRCMOC =
37 OBJMOC =
38
39
40####### Implicit rules
41
42.SUFFIXES: .cpp .cxx .cc .C .c
43
44.cpp.o:
45 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
46
47.cxx.o:
48 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
49
50.cc.o:
51 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
52
53.C.o:
54 $(CXX) -c $(CXXFLAGS) $(INCPATH) -o $@ $<
55
56.c.o:
57 $(CC) -c $(CFLAGS) $(INCPATH) -o $@ $<
58
59####### Build rules
60
61
62all: $(DESTDIR)$(SYSCONF_LINK_TARGET)
63
64$(DESTDIR)$(SYSCONF_LINK_TARGET): $(UICDECLS) $(OBJECTS) $(OBJMOC) $(SUBLIBS)
65 $(SYSCONF_LINK_LIB)
66
67moc: $(SRCMOC)
68
69tmake: Makefile.in
70
71Makefile.in: freetype.pro
72 tmake freetype.pro -o Makefile.in
73
74clean:
75 -rm -f $(OBJECTS) $(OBJMOC) $(SRCMOC) $(UICIMPLS) $(UICDECLS)
76 -rm -f *~ core
77 -rm -f allmoc.cpp
78
79####### Extension Modules
80
81listpromodules:
82 @echo
83
84listallmodules:
85 @echo
86
87listaddonpromodules:
88 @echo
89
90listaddonentmodules:
91 @echo
92
93
94REQUIRES=
95
96####### Sub-libraries
97
98
99###### Combined headers
100
101
102
103####### Compile
104
105fontfactoryttf_qws.o: fontfactoryttf_qws.cpp \
106 fontfactoryttf_qws.h \
107 qfontdata_p.h
108
109freetypefactoryimpl.o: freetypefactoryimpl.cpp \
110 fontfactoryttf_qws.h \
111 qfontdata_p.h \
112 freetypefactoryimpl.h \
113 ../library/fontfactoryinterface.h \
114 ../library/qcom.h \
115 ../library/quuid.h
116
117
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 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21
22#include "fontfactoryttf_qws.h"
23
24#ifdef QT_NO_FREETYPE
25
26#include "qfontdata_p.h"
27#include <string.h>
28#include <stdio.h>
29
30#define FLOOR(x) ((x) & -64)
31#define CEIL(x) (((x)+63) & -64)
32#define TRUNC(x) ((x) >> 6)
33
34
35extern "C" {
36#include <ft2build.h>
37#include FT_FREETYPE_H
38#include FT_GLYPH_H
39#include FT_OUTLINE_H
40#include FT_BBOX_H
41}
42
43class QDiskFontFT : public QDiskFontPrivate {
44public:
45 FT_Face face;
46};
47
48class QRenderedFontFT : public QRenderedFont {
49public:
50 QRenderedFontFT(QDiskFont* f, const QFontDef &d) :
51 QRenderedFont(f,d)
52 {
53 QDiskFontFT *df = (QDiskFontFT*)(f->p);
54 myface=df->face;
55 selectThisSize();
56 // A 1-pixel baseline is excluded in Qt/Windows/X11 fontmetrics
57 // (see QFontMetrics::height())
58 //
59 fascent=CEIL(myface->size->metrics.ascender)/64;
60 fdescent=-FLOOR(myface->size->metrics.descender)/64-1;
61 fmaxwidth=CEIL(myface->size->metrics.max_advance)/64;
62 fleading=CEIL(myface->size->metrics.height)/64
63 - fascent - fdescent + 1;
64
65 // FT has these in font units
66 funderlinepos = ptsize/200+1;
67 funderlinewidth = ptsize/200+1;
68 }
69
70 ~QRenderedFontFT()
71 {
72 }
73
74 bool unicode(int & i) const
75 {
76 int ret;
77
78 FT_Face theface=myface;
79
80 ret=FT_Get_Char_Index(theface,i);
81
82 if (ret==0) {
83 return FALSE;
84 } else {
85 i=ret;
86 return TRUE;
87 }
88 }
89
90 bool inFont(QChar ch) const
91 {
92 int index = ch.unicode();
93 return unicode(index);
94 }
95
96 QGlyph render(QChar ch)
97 {
98 selectThisSize();
99
100 int index = ch.unicode();
101 if ( !unicode(index) )
102 index = 0;
103 QGlyph result;
104
105 FT_Error err;
106
107 err=FT_Load_Glyph(myface,index,FT_LOAD_DEFAULT);
108 if(err)
109 qFatal("Load glyph error %x",err);
110
111 int width,height,pitch,size = 0;
112 FT_Glyph glyph;
113 err=FT_Get_Glyph( myface->glyph, &glyph );
114 if(err)
115 qFatal("Get glyph error %x",err);
116
117 FT_BBox bbox;
118 FT_Glyph_Get_CBox(glyph, ft_glyph_bbox_gridfit, &bbox);
119
120 FT_Vector origin;
121 origin.x = -bbox.xMin;
122 origin.y = -bbox.yMin;
123
124 if ( FT_IS_SCALABLE(myface) ) {
125 err=FT_Glyph_To_Bitmap(&glyph,
126 smooth ? ft_render_mode_normal : ft_render_mode_mono,
127 &origin, 1); // destroy original glyph
128 if(err)
129 qWarning("Get bitmap error %d",err);
130 }
131
132 if ( !err ) {
133 FT_Bitmap bm = ((FT_BitmapGlyph)glyph)->bitmap;
134 pitch = bm.pitch;
135 size=pitch*bm.rows;
136 result.data = new uchar[size]; // XXX memory manage me
137 width=bm.width;
138 height=bm.rows;
139 if ( size ) {
140 memcpy( result.data, bm.buffer, size );
141 } else {
142 result.data = new uchar[0]; // XXX memory manage me
143 }
144 } else {
145 result.data = new uchar[0]; // XXX memory manage me
146 }
147
148 result.metrics = new QGlyphMetrics;
149 memset((char*)result.metrics, 0, sizeof(QGlyphMetrics));
150 result.metrics->bearingx=myface->glyph->metrics.horiBearingX/64;
151 result.metrics->advance=myface->glyph->metrics.horiAdvance/64;
152 result.metrics->bearingy=myface->glyph->metrics.horiBearingY/64;
153
154 result.metrics->linestep=pitch;
155 result.metrics->width=width;
156 result.metrics->height=height;
157
158 FT_Done_Glyph( glyph );
159
160 return result;
161 }
162
163 FT_Face myface;
164
165private:
166 void selectThisSize()
167 {
168 int psize=(ptsize<<6)/10;
169
170 // Assume 72 dpi for now
171 const int dpi=72;
172 FT_Error err;
173 err=FT_Set_Char_Size(myface, psize,psize,dpi,dpi);
174 if (err) {
175 if (FT_IS_SCALABLE(myface) ) {
176 qWarning("Set char size error %x for size %d",err,ptsize);
177 } else {
178 int best=-1;
179 int bdh=99;
180 for (int i=0; i<myface->num_fixed_sizes; i++) {
181 FT_Bitmap_Size& sz=myface->available_sizes[i];
182 int dh = sz.height - ptsize*dpi/72/10;
183 dh = QABS(dh);
184 if ( dh < bdh ) {
185 bdh=dh;
186 best=i;
187 }
188 }
189 if ( best >= 0 )
190 err=FT_Set_Pixel_Sizes(myface,
191 myface->available_sizes[best].width,
192 myface->available_sizes[best].height);
193 if ( err )
194 qWarning("Set char size error %x for size %d",err,ptsize);
195 }
196 }
197 }
198};
199
200QFontFactoryFT::QFontFactoryFT()
201{
202 FT_Error err;
203 err=FT_Init_FreeType(&library);
204 if(err) {
205 qFatal("Couldn't initialise Freetype library");
206 }
207}
208
209QFontFactoryFT::~QFontFactoryFT()
210{
211}
212
213QString QFontFactoryFT::name()
214{
215 return "FT";
216}
217
218QRenderedFont * QFontFactoryFT::get(const QFontDef & f,QDiskFont * f2)
219{
220 return new QRenderedFontFT(f2, f);
221}
222
223void QFontFactoryFT::load(QDiskFont * qdf) const
224{
225 if(qdf->loaded)
226 return;
227 QDiskFontFT *f = new QDiskFontFT;
228 qdf->p=f;
229 FT_Error err;
230 err=FT_New_Face(library,qdf->file.ascii(),0,&(f->face));
231 if(err) {
232 qFatal("Error %d opening face",err);
233 }
234 qdf->loaded=true;
235}
236
237
238#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 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21
22#ifndef FONTFACTORY_FT_H
23#define FONTFACTORY_FT_H
24
25#include <qfontmanager_qws.h>
26#if QT_VERSION >= 300
27# include <private/qfontdata_p.h>
28#else
29# include "qfontdata_p.h"
30#endif
31
32
33#ifdef QT_NO_FREETYPE
34
35extern "C" {
36#include <ft2build.h>
37#include FT_FREETYPE_H
38}
39
40// ascent, descent, width(ch), width(string), maxwidth?
41// leftbearing, rightbearing, minleftbearing,minrightbearing
42// leading
43
44class QFontFactoryFT : public QFontFactory {
45
46public:
47
48 QFontFactoryFT();
49 virtual ~QFontFactoryFT();
50
51 QRenderedFont * get(const QFontDef &,QDiskFont *);
52 virtual void load(QDiskFont *) const;
53 virtual QString name();
54
55private:
56
57 friend class QRenderedFontFT;
58 FT_Library library;
59};
60
61#endif // QT_NO_FREETYPE
62
63#endif // QFONTFACTORY_FT_H
64
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 @@
1 TEMPLATE= lib
2 CONFIG += qt warn_on release
3 HEADERS =fontfactoryttf_qws.h freetypefactoryimpl.h
4 SOURCES =fontfactoryttf_qws.cpp freetypefactoryimpl.cpp
5 qt2:HEADERS+= qfontdata_p.h
6 TARGET = freetypefactory
7 DESTDIR = ../plugins/fontfactories
8INCLUDEPATH += $(QPEDIR)/include
9DEPENDPATH += $(QPEDIR)/include
10#INCLUDEPATH += $(QPEDIR)/include
11 #DEPENDPATH+= /usr/local/include/freetype2
12LIBS += -lqpe -lfreetype
13 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 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20#include "fontfactoryttf_qws.h"
21#include "freetypefactoryimpl.h"
22
23
24FreeTypeFactoryImpl::FreeTypeFactoryImpl()
25 : factory(0), ref(0)
26{
27}
28
29FreeTypeFactoryImpl::~FreeTypeFactoryImpl()
30{
31 delete factory;
32}
33
34QFontFactory *FreeTypeFactoryImpl::fontFactory()
35{
36 if ( !factory )
37 factory = new QFontFactoryFT();
38 return factory;
39}
40
41QRESULT FreeTypeFactoryImpl::queryInterface( const QUuid &uuid, QUnknownInterface **iface )
42{
43 *iface = 0;
44 if ( uuid == IID_QUnknown )
45 *iface = this;
46 else if ( uuid == IID_FontFactory )
47 *iface = this;
48
49 if ( *iface )
50 (*iface)->addRef();
51 return QS_OK;
52}
53
54Q_EXPORT_INTERFACE()
55{
56 Q_CREATE_INSTANCE( FreeTypeFactoryImpl )
57}
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 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21
22#include <fontfactoryinterface.h>
23
24class QFontFactoryFT;
25
26class FreeTypeFactoryImpl : public FontFactoryInterface
27{
28public:
29 FreeTypeFactoryImpl();
30 virtual ~FreeTypeFactoryImpl();
31
32 QRESULT queryInterface( const QUuid&, QUnknownInterface** );
33 Q_REFCOUNT
34
35 virtual QFontFactory *fontFactory();
36
37private:
38 QFontFactoryFT *factory;
39 ulong ref;
40};
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 @@
1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3**
4** This file is part of Qtopia Environment.
5**
6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file.
10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15**
16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you.
18**
19**********************************************************************/
20
21
22#ifndef QFONTDATA_P_H
23#define QFONTDATA_P_H
24
25
26//
27// W A R N I N G
28// -------------
29//
30// This file is not part of the Qt API. It exists for the convenience
31// of qmenudata.cpp, qmenubar.cpp, qmenubar.cpp, qpopupmenu.cpp,
32// qmotifstyle.cpp and qwindowssstyle.cpp. This header file may change
33// from version to version without notice, or even be removed.
34//
35// We mean it.
36//
37//
38
39#ifndef QT_H
40#endif // QT_H
41
42 struct QFontDef { // font definition
43 QStringfamily;
44 QStringaddStyle;
45 int pointSize;
46 uint styleHint: 8;
47 uint styleStrategy: 8;
48 uint charSet : 8;
49 uint weight : 8;
50 uint italic : 1;
51 uint underline: 1;
52 uint strikeOut: 1;
53 uint fixedPitch: 1;
54 uint hintSetByUser: 1;
55 uint rawMode : 1;
56 uint dirty : 1;
57 shortlbearing;
58 shortrbearing;
59};
60
61
62class QFontInternal;
63class QTextCodec;
64
65struct QFontData : public QShared {
66 QFontData()
67 : exactMatch(FALSE), fin(0), printerHackFont( 0 )
68 {}
69 QFontData( const QFontData &d )
70 : QShared(d), req(d.req), exactMatch(d.exactMatch), fin(d.fin),
71 printerHackFont(0)
72 // Copy the QShared count as well. The count may need to be
73 // reset when using the QFontData class, see QFont::QFont(QFontData*)
74 {}
75 ~QFontData()
76 {}
77 QFontData &operator=( const QFontData &d )
78 {
79 req = d.req;
80 exactMatch = d.exactMatch;
81 fin = d.fin;
82 printerHackFont=d.printerHackFont;
83 return *this;
84 }
85 QFontDef req; // requested font
86 bool exactMatch;
87 QFontInternal *fin;
88 QFont *printerHackFont;
89 const QTextCodec *mapper() const;
90 void *fontSet() const;
91};
92
93
94#endif // QFONTDATA_P_H