summaryrefslogtreecommitdiff
authorsandman <sandman>2002-10-22 18:58:52 (UTC)
committer sandman <sandman>2002-10-22 18:58:52 (UTC)
commit3f8157f49267d07a8e3263fedeb4da32ddbc951e (patch) (unidiff)
treeab9e8bac8f0484339f48294709d3eb9288d5783e
parentd7cca919f20d602bd755b7690c25e31f6e9520b1 (diff)
downloadopie-3f8157f49267d07a8e3263fedeb4da32ddbc951e.zip
opie-3f8157f49267d07a8e3263fedeb4da32ddbc951e.tar.gz
opie-3f8157f49267d07a8e3263fedeb4da32ddbc951e.tar.bz2
*** empty log message ***
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--freetype/fontfactoryttf_qws.cpp19
-rw-r--r--freetype/fontfactoryttf_qws.h3
-rw-r--r--freetype/freetype.pro2
-rw-r--r--freetype/freetypefactoryimpl.cpp2
-rw-r--r--freetype/opie-freetype.control2
5 files changed, 17 insertions, 11 deletions
diff --git a/freetype/fontfactoryttf_qws.cpp b/freetype/fontfactoryttf_qws.cpp
index 5aa53fb..1f082a9 100644
--- a/freetype/fontfactoryttf_qws.cpp
+++ b/freetype/fontfactoryttf_qws.cpp
@@ -4,186 +4,193 @@
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 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 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 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 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. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21 21
22#include "fontfactoryttf_qws.h" 22#include "fontfactoryttf_qws.h"
23 23
24#ifdef QT_NO_FREETYPE 24#ifdef QT_NO_FREETYPE
25 25
26#include "qfontdata_p.h" 26#include "qfontdata_p.h"
27#include <string.h> 27#include <string.h>
28#include <stdio.h> 28#include <stdio.h>
29 29
30#define FLOOR(x) ((x) & -64) 30#define FLOOR(x) ((x) & -64)
31#define CEIL(x) (((x)+63) & -64) 31#define CEIL(x) (((x)+63) & -64)
32#define TRUNC(x) ((x) >> 6) 32#define TRUNC(x) ((x) >> 6)
33 33
34 34
35extern "C" { 35extern "C" {
36#include <ft2build.h> 36#include <freetype/freetype.h>
37#include FT_FREETYPE_H 37#include <freetype/ftglyph.h>
38#include FT_GLYPH_H 38#include <freetype/ftoutln.h>
39#include FT_OUTLINE_H 39#include <freetype/ftbbox.h>
40#include FT_BBOX_H
41} 40}
42 41
43class QDiskFontFT : public QDiskFontPrivate { 42class QDiskFontFT : public QDiskFontPrivate {
44public: 43public:
45 FT_Face face; 44 FT_Face face;
46}; 45};
47 46
48class QRenderedFontFT : public QRenderedFont { 47class QRenderedFontFT : public QRenderedFont {
49public: 48public:
50 QRenderedFontFT(QDiskFont* f, const QFontDef &d) : 49 QRenderedFontFT(QDiskFont* f, const QFontDef &d) :
51 QRenderedFont(f,d) 50 QRenderedFont(f,d)
52 { 51 {
53 QDiskFontFT *df = (QDiskFontFT*)(f->p); 52 QDiskFontFT *df = (QDiskFontFT*)(f->p);
54 myface=df->face; 53 myface=df->face;
55 selectThisSize(); 54 selectThisSize();
56 // A 1-pixel baseline is excluded in Qt/Windows/X11 fontmetrics 55 // A 1-pixel baseline is excluded in Qt/Windows/X11 fontmetrics
57 // (see QFontMetrics::height()) 56 // (see QFontMetrics::height())
58 // 57 //
59 fascent=CEIL(myface->size->metrics.ascender)/64; 58 fascent=CEIL(myface->size->metrics.ascender)/64;
60 fdescent=-FLOOR(myface->size->metrics.descender)/64-1; 59 fdescent=-FLOOR(myface->size->metrics.descender)/64-1;
61 fmaxwidth=CEIL(myface->size->metrics.max_advance)/64; 60 fmaxwidth=CEIL(myface->size->metrics.max_advance)/64;
62 fleading=CEIL(myface->size->metrics.height)/64 61 fleading=CEIL(myface->size->metrics.height)/64
63 - fascent - fdescent + 1; 62 - fascent - fdescent + 1;
64 63
65 // FT has these in font units 64 // FT has these in font units
66 funderlinepos = ptsize/200+1; 65 funderlinepos = ptsize/200+1;
67 funderlinewidth = ptsize/200+1; 66 funderlinewidth = ptsize/200+1;
68 } 67 }
69 68
70 ~QRenderedFontFT() 69 ~QRenderedFontFT()
71 { 70 {
71 // When inter-process glyph sharing is implemented, the glyph data
72 // for this font can be dereferenced here.
72 } 73 }
73 74
74 bool unicode(int & i) const 75 bool unicode(int & i) const
75 { 76 {
76 int ret; 77 int ret;
77 78
78 FT_Face theface=myface; 79 FT_Face theface=myface;
79 80
80 ret=FT_Get_Char_Index(theface,i); 81 ret=FT_Get_Char_Index(theface,i);
81 82
82 if (ret==0) { 83 if (ret==0) {
83 return FALSE; 84 return FALSE;
84 } else { 85 } else {
85 i=ret; 86 i=ret;
86 return TRUE; 87 return TRUE;
87 } 88 }
88 } 89 }
89 90
90 bool inFont(QChar ch) const 91 bool inFont(QChar ch) const
91 { 92 {
92 int index = ch.unicode(); 93 int index = ch.unicode();
93 return unicode(index); 94 return unicode(index);
94 } 95 }
95 96
96 QGlyph render(QChar ch) 97 QGlyph render(QChar ch)
97 { 98 {
98 selectThisSize(); 99 selectThisSize();
99 100
100 int index = ch.unicode(); 101 int index = ch.unicode();
101 if ( !unicode(index) ) 102 if ( !unicode(index) )
102 index = 0; 103 index = 0;
103 QGlyph result; 104 QGlyph result;
104 105
105 FT_Error err; 106 FT_Error err;
106 107
107 err=FT_Load_Glyph(myface,index,FT_LOAD_DEFAULT); 108 err=FT_Load_Glyph(myface,index,FT_LOAD_DEFAULT);
108 if(err) 109 if(err)
109 qFatal("Load glyph error %x",err); 110 qFatal("Load glyph error %x",err);
110 111
111 int width,height,pitch,size = 0; 112 int width=0,height=0,pitch=0,size=0;
112 FT_Glyph glyph; 113 FT_Glyph glyph;
113 err=FT_Get_Glyph( myface->glyph, &glyph ); 114 err=FT_Get_Glyph( myface->glyph, &glyph );
114 if(err) 115 if(err)
115 qFatal("Get glyph error %x",err); 116 qFatal("Get glyph error %x",err);
116 117
117 FT_BBox bbox; 118 FT_BBox bbox;
118 FT_Glyph_Get_CBox(glyph, ft_glyph_bbox_gridfit, &bbox); 119 FT_Glyph_Get_CBox(glyph, ft_glyph_bbox_gridfit, &bbox);
119 120
120 FT_Vector origin; 121 FT_Vector origin;
121 origin.x = -bbox.xMin; 122 origin.x = -bbox.xMin;
122 origin.y = -bbox.yMin; 123 origin.y = -bbox.yMin;
123 124
124 if ( FT_IS_SCALABLE(myface) ) { 125 if ( FT_IS_SCALABLE(myface) ) {
125 err=FT_Glyph_To_Bitmap(&glyph, 126 err=FT_Glyph_To_Bitmap(&glyph,
126 smooth ? ft_render_mode_normal : ft_render_mode_mono, 127 smooth ? ft_render_mode_normal : ft_render_mode_mono,
127 &origin, 1); // destroy original glyph 128 &origin, 1); // destroy original glyph
128 if(err) 129 if(err)
129 qWarning("Get bitmap error %d",err); 130 qWarning("Get bitmap error %d",err);
130 } 131 }
131 132
132 if ( !err ) { 133 if ( !err ) {
133 FT_Bitmap bm = ((FT_BitmapGlyph)glyph)->bitmap; 134 FT_Bitmap bm = ((FT_BitmapGlyph)glyph)->bitmap;
134 pitch = bm.pitch; 135 pitch = bm.pitch;
135 size=pitch*bm.rows; 136 size=pitch*bm.rows;
136 result.data = new uchar[size]; // XXX memory manage me 137 result.data = new uchar[size]; // XXX memory manage me
137 width=bm.width; 138 width=bm.width;
138 height=bm.rows; 139 height=bm.rows;
139 if ( size ) { 140 if ( size ) {
140 memcpy( result.data, bm.buffer, size ); 141 memcpy( result.data, bm.buffer, size );
141 } else { 142 } else {
142 result.data = new uchar[0]; // XXX memory manage me 143 result.data = new uchar[0]; // XXX memory manage me
143 } 144 }
144 } else { 145 } else {
145 result.data = new uchar[0]; // XXX memory manage me 146 result.data = new uchar[0]; // XXX memory manage me
146 } 147 }
147 148
148 result.metrics = new QGlyphMetrics; 149 result.metrics = new QGlyphMetrics;
149 memset((char*)result.metrics, 0, sizeof(QGlyphMetrics)); 150 memset((char*)result.metrics, 0, sizeof(QGlyphMetrics));
150 result.metrics->bearingx=myface->glyph->metrics.horiBearingX/64; 151 result.metrics->bearingx=myface->glyph->metrics.horiBearingX/64;
151 result.metrics->advance=myface->glyph->metrics.horiAdvance/64; 152 result.metrics->advance=myface->glyph->metrics.horiAdvance/64;
152 result.metrics->bearingy=myface->glyph->metrics.horiBearingY/64; 153 result.metrics->bearingy=myface->glyph->metrics.horiBearingY/64;
153 154
154 result.metrics->linestep=pitch; 155 result.metrics->linestep=pitch;
155 result.metrics->width=width; 156 result.metrics->width=width;
156 result.metrics->height=height; 157 result.metrics->height=height;
157 158
159 // XXX memory manage me
160 // At some point inter-process glyph data sharing must be implemented
161 // and the flag below can be set to prevent Qt from deleting the glyph
162 // data.
163 // result.metrics->flags = QGlyphMetrics::RendererOwnsData;
164
158 FT_Done_Glyph( glyph ); 165 FT_Done_Glyph( glyph );
159 166
160 return result; 167 return result;
161 } 168 }
162 169
163 FT_Face myface; 170 FT_Face myface;
164 171
165private: 172private:
166 void selectThisSize() 173 void selectThisSize()
167 { 174 {
168 int psize=(ptsize<<6)/10; 175 int psize=(ptsize<<6)/10;
169 176
170 // Assume 72 dpi for now 177 // Assume 72 dpi for now
171 const int dpi=72; 178 const int dpi=72;
172 FT_Error err; 179 FT_Error err;
173 err=FT_Set_Char_Size(myface, psize,psize,dpi,dpi); 180 err=FT_Set_Char_Size(myface, psize,psize,dpi,dpi);
174 if (err) { 181 if (err) {
175 if (FT_IS_SCALABLE(myface) ) { 182 if (FT_IS_SCALABLE(myface) ) {
176 qWarning("Set char size error %x for size %d",err,ptsize); 183 qWarning("Set char size error %x for size %d",err,ptsize);
177 } else { 184 } else {
178 int best=-1; 185 int best=-1;
179 int bdh=99; 186 int bdh=99;
180 for (int i=0; i<myface->num_fixed_sizes; i++) { 187 for (int i=0; i<myface->num_fixed_sizes; i++) {
181 FT_Bitmap_Size& sz=myface->available_sizes[i]; 188 FT_Bitmap_Size& sz=myface->available_sizes[i];
182 int dh = sz.height - ptsize*dpi/72/10; 189 int dh = sz.height - ptsize*dpi/72/10;
183 dh = QABS(dh); 190 dh = QABS(dh);
184 if ( dh < bdh ) { 191 if ( dh < bdh ) {
185 bdh=dh; 192 bdh=dh;
186 best=i; 193 best=i;
187 } 194 }
188 } 195 }
189 if ( best >= 0 ) 196 if ( best >= 0 )
diff --git a/freetype/fontfactoryttf_qws.h b/freetype/fontfactoryttf_qws.h
index 4ba8ce5..208ab61 100644
--- a/freetype/fontfactoryttf_qws.h
+++ b/freetype/fontfactoryttf_qws.h
@@ -4,61 +4,60 @@
4** This file is part of the Qtopia Environment. 4** This file is part of the Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 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 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 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 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. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20 20
21 21
22#ifndef FONTFACTORY_FT_H 22#ifndef FONTFACTORY_FT_H
23#define FONTFACTORY_FT_H 23#define FONTFACTORY_FT_H
24 24
25#include <qfontmanager_qws.h> 25#include <qfontmanager_qws.h>
26#if QT_VERSION >= 300 26#if QT_VERSION >= 300
27# include <private/qfontdata_p.h> 27# include <private/qfontdata_p.h>
28#else 28#else
29# include "qfontdata_p.h" 29# include "qfontdata_p.h"
30#endif 30#endif
31 31
32 32
33#ifdef QT_NO_FREETYPE 33#ifdef QT_NO_FREETYPE
34 34
35extern "C" { 35extern "C" {
36#include <ft2build.h> 36#include <freetype/freetype.h>
37#include FT_FREETYPE_H
38} 37}
39 38
40// ascent, descent, width(ch), width(string), maxwidth? 39// ascent, descent, width(ch), width(string), maxwidth?
41// leftbearing, rightbearing, minleftbearing,minrightbearing 40// leftbearing, rightbearing, minleftbearing,minrightbearing
42// leading 41// leading
43 42
44class QFontFactoryFT : public QFontFactory { 43class QFontFactoryFT : public QFontFactory {
45 44
46public: 45public:
47 46
48 QFontFactoryFT(); 47 QFontFactoryFT();
49 virtual ~QFontFactoryFT(); 48 virtual ~QFontFactoryFT();
50 49
51 QRenderedFont * get(const QFontDef &,QDiskFont *); 50 QRenderedFont * get(const QFontDef &,QDiskFont *);
52 virtual void load(QDiskFont *) const; 51 virtual void load(QDiskFont *) const;
53 virtual QString name(); 52 virtual QString name();
54 53
55private: 54private:
56 55
57 friend class QRenderedFontFT; 56 friend class QRenderedFontFT;
58 FT_Library library; 57 FT_Library library;
59}; 58};
60 59
61#endif // QT_NO_FREETYPE 60#endif // QT_NO_FREETYPE
62 61
63#endif // QFONTFACTORY_FT_H 62#endif // QFONTFACTORY_FT_H
64 63
diff --git a/freetype/freetype.pro b/freetype/freetype.pro
index 5800b48..ca7edd3 100644
--- a/freetype/freetype.pro
+++ b/freetype/freetype.pro
@@ -1,11 +1,11 @@
1 TEMPLATE= lib 1 TEMPLATE= lib
2 CONFIG += qt warn_on release 2 CONFIG += qt warn_on release
3 HEADERS = fontfactoryttf_qws.h freetypefactoryimpl.h 3 HEADERS = fontfactoryttf_qws.h freetypefactoryimpl.h
4 SOURCES = fontfactoryttf_qws.cpp freetypefactoryimpl.cpp 4 SOURCES = fontfactoryttf_qws.cpp freetypefactoryimpl.cpp
5 qt2:HEADERS+= qfontdata_p.h 5 qt2:HEADERS+= qfontdata_p.h
6 TARGET = freetypefactory 6 TARGET = freetypefactory
7 DESTDIR = $(OPIEDIR)/plugins/fontfactories 7 DESTDIR = $(OPIEDIR)/plugins/fontfactories
8 INCLUDEPATH+= $(OPIEDIR)/include 8 INCLUDEPATH+= $(QTDIR)/src/3rdparty/freetype/include $(QTDIR)/src/3rdparty/freetype/include/freetype/config $(OPIEDIR)/include
9DEPENDPATH += $(OPIEDIR)/include 9DEPENDPATH += $(OPIEDIR)/include
10LIBS += -lqpe -lfreetype 10LIBS += -lqpe -lfreetype
11 VERSION = 1.0.0 11 VERSION = 1.0.0
diff --git a/freetype/freetypefactoryimpl.cpp b/freetype/freetypefactoryimpl.cpp
index 71460b2..24fb13a 100644
--- a/freetype/freetypefactoryimpl.cpp
+++ b/freetype/freetypefactoryimpl.cpp
@@ -19,39 +19,39 @@
19**********************************************************************/ 19**********************************************************************/
20#include "fontfactoryttf_qws.h" 20#include "fontfactoryttf_qws.h"
21#include "freetypefactoryimpl.h" 21#include "freetypefactoryimpl.h"
22 22
23 23
24FreeTypeFactoryImpl::FreeTypeFactoryImpl() 24FreeTypeFactoryImpl::FreeTypeFactoryImpl()
25 : factory(0), ref(0) 25 : factory(0), ref(0)
26{ 26{
27} 27}
28 28
29FreeTypeFactoryImpl::~FreeTypeFactoryImpl() 29FreeTypeFactoryImpl::~FreeTypeFactoryImpl()
30{ 30{
31 delete factory; 31 delete factory;
32} 32}
33 33
34QFontFactory *FreeTypeFactoryImpl::fontFactory() 34QFontFactory *FreeTypeFactoryImpl::fontFactory()
35{ 35{
36 if ( !factory ) 36 if ( !factory )
37 factory = new QFontFactoryFT(); 37 factory = new QFontFactoryFT();
38 return factory; 38 return factory;
39} 39}
40 40
41QRESULT FreeTypeFactoryImpl::queryInterface( const QUuid &uuid, QUnknownInterface **iface ) 41QRESULT FreeTypeFactoryImpl::queryInterface( const QUuid &uuid, QUnknownInterface **iface )
42{ 42{
43 *iface = 0; 43 *iface = 0;
44 if ( uuid == IID_QUnknown ) 44 if ( uuid == IID_QUnknown )
45 *iface = this; 45 *iface = this;
46 else if ( uuid == IID_FontFactory ) 46 else if ( uuid == IID_FontFactory )
47 *iface = this; 47 *iface = this;
48 48
49 if ( *iface ) 49 if ( *iface )
50 (*iface)->addRef(); 50 (*iface)->addRef();
51 return QS_OK; 51 return (*iface) ? QS_OK : QS_FALSE;
52} 52}
53 53
54Q_EXPORT_INTERFACE() 54Q_EXPORT_INTERFACE()
55{ 55{
56 Q_CREATE_INSTANCE( FreeTypeFactoryImpl ) 56 Q_CREATE_INSTANCE( FreeTypeFactoryImpl )
57} 57}
diff --git a/freetype/opie-freetype.control b/freetype/opie-freetype.control
index f1ce408..2863adb 100644
--- a/freetype/opie-freetype.control
+++ b/freetype/opie-freetype.control
@@ -1,8 +1,8 @@
1Files: plugins/fontfactories/libfreetypefactory* 1Files: plugins/fontfactories/libfreetypefactory*
2Priority: optional 2Priority: optional
3Section: opie/plugins 3Section: opie/plugins
4Maintainer: Opie <opie@llornkcor.com> 4Maintainer: Opie <opie@llornkcor.com>
5Architecture: arm 5Architecture: arm
6Version: $QPE_VERSION-$SUB_VERSION 6Version: $QPE_VERSION-$SUB_VERSION
7Depends: opie-base ($QPE_VERSION) 7Depends: opie-base ($QPE_VERSION), libfreetype6
8Description: Freetype fontfactory plugin 8Description: Freetype fontfactory plugin