-rw-r--r-- | freetype/config.in | 2 | ||||
-rw-r--r-- | freetype/fontfactoryttf_qws.cpp | 18 | ||||
-rw-r--r-- | freetype/freetype.pro | 8 |
3 files changed, 14 insertions, 14 deletions
diff --git a/freetype/config.in b/freetype/config.in index 71c5df7..68b659a 100644 --- a/freetype/config.in +++ b/freetype/config.in | |||
@@ -1,4 +1,4 @@ | |||
1 | config FREETYPE | 1 | config FREETYPE |
2 | boolean "opie-freetype (support for fonts used via the freetype library)" | 2 | boolean "opie-freetype (support for fonts used via the freetype library)" |
3 | default "y" | 3 | default "y" |
4 | depends ( LIBQPE || LIBQPE-X11 ) | 4 | depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE2CORE |
diff --git a/freetype/fontfactoryttf_qws.cpp b/freetype/fontfactoryttf_qws.cpp index 1f082a9..1ed0d2c 100644 --- a/freetype/fontfactoryttf_qws.cpp +++ b/freetype/fontfactoryttf_qws.cpp | |||
@@ -1,245 +1,247 @@ | |||
1 | /********************************************************************** | 1 | /********************************************************************** |
2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. | 2 | ** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. |
3 | ** | 3 | ** |
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 | |||
22 | #include "fontfactoryttf_qws.h" | 21 | #include "fontfactoryttf_qws.h" |
23 | 22 | ||
23 | #include <opie2/odebug.h> | ||
24 | using namespace Opie::Core; | ||
25 | |||
24 | #ifdef QT_NO_FREETYPE | 26 | #ifdef QT_NO_FREETYPE |
25 | 27 | ||
26 | #include "qfontdata_p.h" | 28 | #include "qfontdata_p.h" |
27 | #include <string.h> | 29 | #include <string.h> |
28 | #include <stdio.h> | 30 | #include <stdio.h> |
29 | 31 | ||
30 | #define FLOOR(x) ((x) & -64) | 32 | #define FLOOR(x) ((x) & -64) |
31 | #define CEIL(x) (((x)+63) & -64) | 33 | #define CEIL(x) (((x)+63) & -64) |
32 | #define TRUNC(x) ((x) >> 6) | 34 | #define TRUNC(x) ((x) >> 6) |
33 | 35 | ||
34 | 36 | ||
35 | extern "C" { | 37 | extern "C" { |
36 | #include <freetype/freetype.h> | 38 | #include <freetype/freetype.h> |
37 | #include <freetype/ftglyph.h> | 39 | #include <freetype/ftglyph.h> |
38 | #include <freetype/ftoutln.h> | 40 | #include <freetype/ftoutln.h> |
39 | #include <freetype/ftbbox.h> | 41 | #include <freetype/ftbbox.h> |
40 | } | 42 | } |
41 | 43 | ||
42 | class QDiskFontFT : public QDiskFontPrivate { | 44 | class QDiskFontFT : public QDiskFontPrivate { |
43 | public: | 45 | public: |
44 | FT_Face face; | 46 | FT_Face face; |
45 | }; | 47 | }; |
46 | 48 | ||
47 | class QRenderedFontFT : public QRenderedFont { | 49 | class QRenderedFontFT : public QRenderedFont { |
48 | public: | 50 | public: |
49 | QRenderedFontFT(QDiskFont* f, const QFontDef &d) : | 51 | QRenderedFontFT(QDiskFont* f, const QFontDef &d) : |
50 | QRenderedFont(f,d) | 52 | QRenderedFont(f,d) |
51 | { | 53 | { |
52 | QDiskFontFT *df = (QDiskFontFT*)(f->p); | 54 | QDiskFontFT *df = (QDiskFontFT*)(f->p); |
53 | myface=df->face; | 55 | myface=df->face; |
54 | selectThisSize(); | 56 | selectThisSize(); |
55 | // A 1-pixel baseline is excluded in Qt/Windows/X11 fontmetrics | 57 | // A 1-pixel baseline is excluded in Qt/Windows/X11 fontmetrics |
56 | // (see QFontMetrics::height()) | 58 | // (see QFontMetrics::height()) |
57 | // | 59 | // |
58 | fascent=CEIL(myface->size->metrics.ascender)/64; | 60 | fascent=CEIL(myface->size->metrics.ascender)/64; |
59 | fdescent=-FLOOR(myface->size->metrics.descender)/64-1; | 61 | fdescent=-FLOOR(myface->size->metrics.descender)/64-1; |
60 | fmaxwidth=CEIL(myface->size->metrics.max_advance)/64; | 62 | fmaxwidth=CEIL(myface->size->metrics.max_advance)/64; |
61 | fleading=CEIL(myface->size->metrics.height)/64 | 63 | fleading=CEIL(myface->size->metrics.height)/64 |
62 | - fascent - fdescent + 1; | 64 | - fascent - fdescent + 1; |
63 | 65 | ||
64 | // FT has these in font units | 66 | // FT has these in font units |
65 | funderlinepos = ptsize/200+1; | 67 | funderlinepos = ptsize/200+1; |
66 | funderlinewidth = ptsize/200+1; | 68 | funderlinewidth = ptsize/200+1; |
67 | } | 69 | } |
68 | 70 | ||
69 | ~QRenderedFontFT() | 71 | ~QRenderedFontFT() |
70 | { | 72 | { |
71 | // When inter-process glyph sharing is implemented, the glyph data | 73 | // When inter-process glyph sharing is implemented, the glyph data |
72 | // for this font can be dereferenced here. | 74 | // for this font can be dereferenced here. |
73 | } | 75 | } |
74 | 76 | ||
75 | bool unicode(int & i) const | 77 | bool unicode(int & i) const |
76 | { | 78 | { |
77 | int ret; | 79 | int ret; |
78 | 80 | ||
79 | FT_Face theface=myface; | 81 | FT_Face theface=myface; |
80 | 82 | ||
81 | ret=FT_Get_Char_Index(theface,i); | 83 | ret=FT_Get_Char_Index(theface,i); |
82 | 84 | ||
83 | if (ret==0) { | 85 | if (ret==0) { |
84 | return FALSE; | 86 | return FALSE; |
85 | } else { | 87 | } else { |
86 | i=ret; | 88 | i=ret; |
87 | return TRUE; | 89 | return TRUE; |
88 | } | 90 | } |
89 | } | 91 | } |
90 | 92 | ||
91 | bool inFont(QChar ch) const | 93 | bool inFont(QChar ch) const |
92 | { | 94 | { |
93 | int index = ch.unicode(); | 95 | int index = ch.unicode(); |
94 | return unicode(index); | 96 | return unicode(index); |
95 | } | 97 | } |
96 | 98 | ||
97 | QGlyph render(QChar ch) | 99 | QGlyph render(QChar ch) |
98 | { | 100 | { |
99 | selectThisSize(); | 101 | selectThisSize(); |
100 | 102 | ||
101 | int index = ch.unicode(); | 103 | int index = ch.unicode(); |
102 | if ( !unicode(index) ) | 104 | if ( !unicode(index) ) |
103 | index = 0; | 105 | index = 0; |
104 | QGlyph result; | 106 | QGlyph result; |
105 | 107 | ||
106 | FT_Error err; | 108 | FT_Error err; |
107 | 109 | ||
108 | err=FT_Load_Glyph(myface,index,FT_LOAD_DEFAULT); | 110 | err=FT_Load_Glyph(myface,index,FT_LOAD_DEFAULT); |
109 | if(err) | 111 | if(err) |
110 | qFatal("Load glyph error %x",err); | 112 | ofatal << "Load glyph error " << err << "" << oendl; |
111 | 113 | ||
112 | int width=0,height=0,pitch=0,size=0; | 114 | int width=0,height=0,pitch=0,size=0; |
113 | FT_Glyph glyph; | 115 | FT_Glyph glyph; |
114 | err=FT_Get_Glyph( myface->glyph, &glyph ); | 116 | err=FT_Get_Glyph( myface->glyph, &glyph ); |
115 | if(err) | 117 | if(err) |
116 | qFatal("Get glyph error %x",err); | 118 | ofatal << "Get glyph error " << err << "" << oendl; |
117 | 119 | ||
118 | FT_BBox bbox; | 120 | FT_BBox bbox; |
119 | FT_Glyph_Get_CBox(glyph, ft_glyph_bbox_gridfit, &bbox); | 121 | FT_Glyph_Get_CBox(glyph, ft_glyph_bbox_gridfit, &bbox); |
120 | 122 | ||
121 | FT_Vector origin; | 123 | FT_Vector origin; |
122 | origin.x = -bbox.xMin; | 124 | origin.x = -bbox.xMin; |
123 | origin.y = -bbox.yMin; | 125 | origin.y = -bbox.yMin; |
124 | 126 | ||
125 | if ( FT_IS_SCALABLE(myface) ) { | 127 | if ( FT_IS_SCALABLE(myface) ) { |
126 | err=FT_Glyph_To_Bitmap(&glyph, | 128 | err=FT_Glyph_To_Bitmap(&glyph, |
127 | smooth ? ft_render_mode_normal : ft_render_mode_mono, | 129 | smooth ? ft_render_mode_normal : ft_render_mode_mono, |
128 | &origin, 1); // destroy original glyph | 130 | &origin, 1); // destroy original glyph |
129 | if(err) | 131 | if(err) |
130 | qWarning("Get bitmap error %d",err); | 132 | owarn << "Get bitmap error " << err << "" << oendl; |
131 | } | 133 | } |
132 | 134 | ||
133 | if ( !err ) { | 135 | if ( !err ) { |
134 | FT_Bitmap bm = ((FT_BitmapGlyph)glyph)->bitmap; | 136 | FT_Bitmap bm = ((FT_BitmapGlyph)glyph)->bitmap; |
135 | pitch = bm.pitch; | 137 | pitch = bm.pitch; |
136 | size=pitch*bm.rows; | 138 | size=pitch*bm.rows; |
137 | result.data = new uchar[size]; // XXX memory manage me | 139 | result.data = new uchar[size]; // XXX memory manage me |
138 | width=bm.width; | 140 | width=bm.width; |
139 | height=bm.rows; | 141 | height=bm.rows; |
140 | if ( size ) { | 142 | if ( size ) { |
141 | memcpy( result.data, bm.buffer, size ); | 143 | memcpy( result.data, bm.buffer, size ); |
142 | } else { | 144 | } else { |
143 | result.data = new uchar[0]; // XXX memory manage me | 145 | result.data = new uchar[0]; // XXX memory manage me |
144 | } | 146 | } |
145 | } else { | 147 | } else { |
146 | result.data = new uchar[0]; // XXX memory manage me | 148 | result.data = new uchar[0]; // XXX memory manage me |
147 | } | 149 | } |
148 | 150 | ||
149 | result.metrics = new QGlyphMetrics; | 151 | result.metrics = new QGlyphMetrics; |
150 | memset((char*)result.metrics, 0, sizeof(QGlyphMetrics)); | 152 | memset((char*)result.metrics, 0, sizeof(QGlyphMetrics)); |
151 | result.metrics->bearingx=myface->glyph->metrics.horiBearingX/64; | 153 | result.metrics->bearingx=myface->glyph->metrics.horiBearingX/64; |
152 | result.metrics->advance=myface->glyph->metrics.horiAdvance/64; | 154 | result.metrics->advance=myface->glyph->metrics.horiAdvance/64; |
153 | result.metrics->bearingy=myface->glyph->metrics.horiBearingY/64; | 155 | result.metrics->bearingy=myface->glyph->metrics.horiBearingY/64; |
154 | 156 | ||
155 | result.metrics->linestep=pitch; | 157 | result.metrics->linestep=pitch; |
156 | result.metrics->width=width; | 158 | result.metrics->width=width; |
157 | result.metrics->height=height; | 159 | result.metrics->height=height; |
158 | 160 | ||
159 | // XXX memory manage me | 161 | // XXX memory manage me |
160 | // At some point inter-process glyph data sharing must be implemented | 162 | // 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 | 163 | // and the flag below can be set to prevent Qt from deleting the glyph |
162 | // data. | 164 | // data. |
163 | // result.metrics->flags = QGlyphMetrics::RendererOwnsData; | 165 | // result.metrics->flags = QGlyphMetrics::RendererOwnsData; |
164 | 166 | ||
165 | FT_Done_Glyph( glyph ); | 167 | FT_Done_Glyph( glyph ); |
166 | 168 | ||
167 | return result; | 169 | return result; |
168 | } | 170 | } |
169 | 171 | ||
170 | FT_Face myface; | 172 | FT_Face myface; |
171 | 173 | ||
172 | private: | 174 | private: |
173 | void selectThisSize() | 175 | void selectThisSize() |
174 | { | 176 | { |
175 | int psize=(ptsize<<6)/10; | 177 | int psize=(ptsize<<6)/10; |
176 | 178 | ||
177 | // Assume 72 dpi for now | 179 | // Assume 72 dpi for now |
178 | const int dpi=72; | 180 | const int dpi=72; |
179 | FT_Error err; | 181 | FT_Error err; |
180 | err=FT_Set_Char_Size(myface, psize,psize,dpi,dpi); | 182 | err=FT_Set_Char_Size(myface, psize,psize,dpi,dpi); |
181 | if (err) { | 183 | if (err) { |
182 | if (FT_IS_SCALABLE(myface) ) { | 184 | if (FT_IS_SCALABLE(myface) ) { |
183 | qWarning("Set char size error %x for size %d",err,ptsize); | 185 | owarn << "Set char size error " << err << " for size " << ptsize << "" << oendl; |
184 | } else { | 186 | } else { |
185 | int best=-1; | 187 | int best=-1; |
186 | int bdh=99; | 188 | int bdh=99; |
187 | for (int i=0; i<myface->num_fixed_sizes; i++) { | 189 | for (int i=0; i<myface->num_fixed_sizes; i++) { |
188 | FT_Bitmap_Size& sz=myface->available_sizes[i]; | 190 | FT_Bitmap_Size& sz=myface->available_sizes[i]; |
189 | int dh = sz.height - ptsize*dpi/72/10; | 191 | int dh = sz.height - ptsize*dpi/72/10; |
190 | dh = QABS(dh); | 192 | dh = QABS(dh); |
191 | if ( dh < bdh ) { | 193 | if ( dh < bdh ) { |
192 | bdh=dh; | 194 | bdh=dh; |
193 | best=i; | 195 | best=i; |
194 | } | 196 | } |
195 | } | 197 | } |
196 | if ( best >= 0 ) | 198 | if ( best >= 0 ) |
197 | err=FT_Set_Pixel_Sizes(myface, | 199 | err=FT_Set_Pixel_Sizes(myface, |
198 | myface->available_sizes[best].width, | 200 | myface->available_sizes[best].width, |
199 | myface->available_sizes[best].height); | 201 | myface->available_sizes[best].height); |
200 | if ( err ) | 202 | if ( err ) |
201 | qWarning("Set char size error %x for size %d",err,ptsize); | 203 | owarn << "Set char size error " << err << " for size " << ptsize << "" << oendl; |
202 | } | 204 | } |
203 | } | 205 | } |
204 | } | 206 | } |
205 | }; | 207 | }; |
206 | 208 | ||
207 | QFontFactoryFT::QFontFactoryFT() | 209 | QFontFactoryFT::QFontFactoryFT() |
208 | { | 210 | { |
209 | FT_Error err; | 211 | FT_Error err; |
210 | err=FT_Init_FreeType(&library); | 212 | err=FT_Init_FreeType(&library); |
211 | if(err) { | 213 | if(err) { |
212 | qFatal("Couldn't initialise Freetype library"); | 214 | ofatal << "Couldn't initialise Freetype library" << oendl; |
213 | } | 215 | } |
214 | } | 216 | } |
215 | 217 | ||
216 | QFontFactoryFT::~QFontFactoryFT() | 218 | QFontFactoryFT::~QFontFactoryFT() |
217 | { | 219 | { |
218 | } | 220 | } |
219 | 221 | ||
220 | QString QFontFactoryFT::name() | 222 | QString QFontFactoryFT::name() |
221 | { | 223 | { |
222 | return "FT"; | 224 | return "FT"; |
223 | } | 225 | } |
224 | 226 | ||
225 | QRenderedFont * QFontFactoryFT::get(const QFontDef & f,QDiskFont * f2) | 227 | QRenderedFont * QFontFactoryFT::get(const QFontDef & f,QDiskFont * f2) |
226 | { | 228 | { |
227 | return new QRenderedFontFT(f2, f); | 229 | return new QRenderedFontFT(f2, f); |
228 | } | 230 | } |
229 | 231 | ||
230 | void QFontFactoryFT::load(QDiskFont * qdf) const | 232 | void QFontFactoryFT::load(QDiskFont * qdf) const |
231 | { | 233 | { |
232 | if(qdf->loaded) | 234 | if(qdf->loaded) |
233 | return; | 235 | return; |
234 | QDiskFontFT *f = new QDiskFontFT; | 236 | QDiskFontFT *f = new QDiskFontFT; |
235 | qdf->p=f; | 237 | qdf->p=f; |
236 | FT_Error err; | 238 | FT_Error err; |
237 | err=FT_New_Face(library,qdf->file.ascii(),0,&(f->face)); | 239 | err=FT_New_Face(library,qdf->file.ascii(),0,&(f->face)); |
238 | if(err) { | 240 | if(err) { |
239 | qFatal("Error %d opening face",err); | 241 | ofatal << "Error " << err << " opening face" << oendl; |
240 | } | 242 | } |
241 | qdf->loaded=true; | 243 | qdf->loaded=true; |
242 | } | 244 | } |
243 | 245 | ||
244 | 246 | ||
245 | #endif // QT_NO_FREETYPE | 247 | #endif // QT_NO_FREETYPE |
diff --git a/freetype/freetype.pro b/freetype/freetype.pro index bdc37f6..ca2841c 100644 --- a/freetype/freetype.pro +++ b/freetype/freetype.pro | |||
@@ -1,15 +1,13 @@ | |||
1 | TEMPLATE= lib | 1 | TEMPLATE= lib |
2 | CONFIG += qt warn_on release | 2 | CONFIG += qt warn_on |
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+= $(QTDIR)/src/3rdparty/freetype/include $(QTDIR)/src/3rdparty/freetype/include/freetype/config $(OPIEDIR)/include | 8 | INCLUDEPATH+= $(QTDIR)/src/3rdparty/freetype/include $(QTDIR)/src/3rdparty/freetype/include/freetype/config $(OPIEDIR)/include |
9 | DEPENDPATH += $(OPIEDIR)/include | 9 | DEPENDPATH += $(OPIEDIR)/include |
10 | LIBS += -lqpe -lfreetype | 10 | LIBS += -lqpe -lfreetype -lopiecore2 |
11 | VERSION = 1.0.0 | 11 | VERSION = 1.0.1 |
12 | |||
13 | |||
14 | 12 | ||
15 | include ( $(OPIEDIR)/include.pro ) | 13 | include ( $(OPIEDIR)/include.pro ) |