DIB Engine: fixes clipping, text and more
[wine/hacks.git] / dlls / winedib.drv / font.c
blobf7ea8dc965a599baa15537f20977838cdde2834b
1 /*
2 * DIBDRV font objects
4 * Copyright 2009 Massimo Del Fedele
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "config.h"
23 #include "wine/port.h"
25 #include "dibdrv.h"
27 WINE_DEFAULT_DEBUG_CHANNEL(dibdrv);
30 #if 0
31 /* prints out some info about face */
32 void PrintFaceInfo(FT_Face face)
34 int i;
36 fprintf(stderr, "----------------------------------------------------------\n");
37 fprintf(stderr, "Family name :%s\n", face->family_name);
38 fprintf(stderr, "Style name :%s\n", face->style_name);
39 fprintf(stderr, "Num fixed sizes : %d\n", face->num_fixed_sizes);
40 if(face->num_fixed_sizes)
42 fprintf(stderr, "Fixed sizes :");
43 for(i = 0; i < face->num_fixed_sizes; i++)
44 fprintf(stderr, " (%d, %d)", face->available_sizes[i].width, face->available_sizes[i].height);
45 fprintf(stderr, "\n");
47 fprintf(stderr, "Face flags: ");
48 if(face->face_flags & FT_FACE_FLAG_SCALABLE ) fprintf(stderr, "FT_FACE_FLAG_SCALABLE ");
49 if(face->face_flags & FT_FACE_FLAG_FIXED_SIZES ) fprintf(stderr, "FT_FACE_FLAG_FIXED_SIZES ");
50 if(face->face_flags & FT_FACE_FLAG_FIXED_WIDTH ) fprintf(stderr, "FT_FACE_FLAG_FIXED_WIDTH ");
51 if(face->face_flags & FT_FACE_FLAG_SFNT ) fprintf(stderr, "FT_FACE_FLAG_SFNT ");
52 if(face->face_flags & FT_FACE_FLAG_HORIZONTAL ) fprintf(stderr, "FT_FACE_FLAG_HORIZONTAL ");
53 if(face->face_flags & FT_FACE_FLAG_VERTICAL ) fprintf(stderr, "FT_FACE_FLAG_VERTICAL ");
54 if(face->face_flags & FT_FACE_FLAG_KERNING ) fprintf(stderr, "FT_FACE_FLAG_KERNING ");
55 if(face->face_flags & FT_FACE_FLAG_FAST_GLYPHS ) fprintf(stderr, "FT_FACE_FLAG_FAST_GLYPHS ");
56 if(face->face_flags & FT_FACE_FLAG_MULTIPLE_MASTERS ) fprintf(stderr, "FT_FACE_FLAG_MULTIPLE_MASTERS ");
57 if(face->face_flags & FT_FACE_FLAG_GLYPH_NAMES ) fprintf(stderr, "FT_FACE_FLAG_GLYPH_NAMES ");
58 if(face->face_flags & FT_FACE_FLAG_EXTERNAL_STREAM ) fprintf(stderr, "FT_FACE_FLAG_EXTERNAL_STREAM ");
59 if(face->face_flags & FT_FACE_FLAG_HINTER ) fprintf(stderr, "FT_FACE_FLAG_HINTER ");
60 if(face->face_flags & FT_FACE_FLAG_CID_KEYED ) fprintf(stderr, "FT_FACE_FLAG_CID_KEYED ");
61 if(face->face_flags & FT_FACE_FLAG_TRICKY ) fprintf(stderr, "FT_FACE_FLAG_TRICKY ");
62 fprintf(stderr, "\n");
64 fprintf(stderr, "Style flags: ");
65 if(face->style_flags & FT_STYLE_FLAG_ITALIC) fprintf(stderr, "FT_STYLE_FLAG_ITALIC ");
66 if(face->style_flags & FT_STYLE_FLAG_BOLD) fprintf(stderr, "FT_STYLE_FLAG_BOLD ");
67 fprintf(stderr, "\n");
68 fprintf(stderr, "----------------------------------------------------------\n");
70 #endif
73 /**********************************************************************
74 * DIBDRV_SetTextColor
76 COLORREF DIBDRV_SetTextColor( DIBDRVPHYSDEV *physDev, COLORREF color )
78 COLORREF res;
80 MAYBE(TRACE("physDev:%p, color:%08x\n", physDev, color));
82 if(physDev->hasDIB)
84 /* DIB section selected in, use DIB Engine */
86 /* do nothing if color is the same as actual one */
87 if(color == physDev->textColor)
88 return color;
90 /* stores old color and sets new one */
91 res = physDev->textColor;
92 physDev->textColor = color;
94 #ifdef DIBDRV_ANTIALIASED_FONTS
95 /* fills the text color table used on antialiased font display */
96 if(physDev->physBitmap.funcs)
98 BYTE r, g, b;
99 INT i;
101 r = GetRValue(color);
102 g = GetGValue(color);
103 b = GetBValue(color);
104 for(i = 0; i < 256; i++)
106 physDev->textColorTable[i] = physDev->physBitmap.funcs->ColorToPixel(&physDev->physBitmap, RGB(
107 MulDiv(r, i, 255),
108 MulDiv(g, i, 255),
109 MulDiv(b, i, 255)
110 ));
113 #endif
115 /* returns previous text color */
116 return res;
118 else
120 /* DDB selected in, use X11 driver */
121 res = _DIBDRV_GetDisplayDriver()->pSetTextColor(physDev->X11PhysDev, color);
123 return res;
126 /***********************************************************************
127 * DIBDRV_SelectFont
129 HFONT DIBDRV_SelectFont( DIBDRVPHYSDEV *physDev, HFONT hfont, GdiFont *gdiFont )
131 HFONT res;
132 FT_Int i;
133 FT_Error error;
134 FT_CharMap charmap = NULL;
135 LOGFONTW lf;
137 MAYBE(TRACE("physDev:%p, hfont:%p, gdiFont:%p\n", physDev, hfont, gdiFont));
139 if(physDev->hasDIB)
141 /* DIB section selected in, use DIB Engine */
143 /* gets font information */
144 GetObjectW(hfont, sizeof(lf), &lf);
145 MAYBE(TRACE("Font is : '%s'\n", debugstr_w(lf.lfFaceName)));
147 /* FIXME: just handles gdifont, don't know if it needs to handle hfont too
148 BTW, still don't know how to get FT_Face from non-gdi font here
150 if(!gdiFont)
152 FIXME("No gdi font - unhandled by now.\n");
153 return hfont;
156 physDev->face = gdiFont->ft_face;
157 if(!physDev->face)
159 FIXME("Error, null Ft_Face\n");
160 return hfont;
163 #if 0
164 /* prints out some info about face */
165 if(TRACE_ON(dibdrv)) MAYBE(PrintFaceInfo(physDev->face));
166 #endif
167 /* setup the correct charmap.... maybe */
168 for (i = 0; i < physDev->face->num_charmaps; ++i)
170 if (physDev->face->charmaps[i]->platform_id != TT_PLATFORM_MICROSOFT)
171 continue;
173 if (physDev->face->charmaps[i]->encoding_id == TT_MS_ID_UNICODE_CS)
175 charmap = physDev->face->charmaps[i];
176 break;
179 if (charmap == NULL)
181 WARN("Selected fallout charmap #%d\n", i);
182 charmap = physDev->face->charmaps[i];
185 if (charmap == NULL)
187 WARN("No Windows character map found\n");
188 charmap = physDev->face->charmaps[0];
189 return 0;
192 error = pFT_Set_Charmap(physDev->face, charmap);
193 if (error != FT_Err_Ok)
195 ERR("%s returned %i\n", "FT_Set_Charmap", error);
196 return 0;
199 /* we use GDI fonts, so just return false */
200 return 0;
203 else
205 /* DDB selected in, use X11 driver */
206 res = _DIBDRV_GetDisplayDriver()->pSelectFont(physDev->X11PhysDev, hfont, gdiFont);
208 return res;
211 /***********************************************************************
212 * DIBDRV_EnumDeviceFonts
214 BOOL DIBDRV_EnumDeviceFonts( DIBDRVPHYSDEV *physDev, LPLOGFONTW plf,
215 FONTENUMPROCW proc, LPARAM lp )
217 BOOL res;
219 MAYBE(TRACE("physDev:%p, plf:%p, proc:%p, lp:%lx\n", physDev, plf, proc, lp));
221 if(physDev->hasDIB)
223 /* DIB section selected in, use DIB Engine */
224 ONCE(FIXME("STUB\n"));
225 res = 0;
227 else
229 /* DDB selected in, use X11 driver */
230 res = _DIBDRV_GetDisplayDriver()->pEnumDeviceFonts(physDev->X11PhysDev, plf, proc, lp);
232 return res;
235 /***********************************************************************
236 * DIBDRV_GetTextMetrics
238 BOOL DIBDRV_GetTextMetrics( DIBDRVPHYSDEV *physDev, TEXTMETRICW *metrics )
240 BOOL res;
242 MAYBE(TRACE("physDev:%p, metrics:%p\n", physDev, metrics));
244 if(physDev->hasDIB)
246 /* DIB section selected in, use DIB Engine */
247 ONCE(FIXME("STUB\n"));
248 res = 0;
250 else
252 /* DDB selected in, use X11 driver */
253 res = _DIBDRV_GetDisplayDriver()->pGetTextMetrics(physDev->X11PhysDev, metrics);
255 return res;
258 /***********************************************************************
259 * DIBDRV_GetCharWidth
261 BOOL DIBDRV_GetCharWidth( DIBDRVPHYSDEV *physDev, UINT firstChar, UINT lastChar,
262 LPINT buffer )
264 BOOL res;
266 MAYBE(TRACE("physDev:%p, firstChar:%d, lastChar:%d, buffer:%pn", physDev, firstChar, lastChar, buffer));
268 if(physDev->hasDIB)
270 /* DIB section selected in, use DIB Engine */
271 ONCE(FIXME("STUB\n"));
272 res = 0;
274 else
276 /* DDB selected in, use X11 driver */
277 res = _DIBDRV_GetDisplayDriver()->pGetCharWidth(physDev->X11PhysDev, firstChar, lastChar, buffer);
279 return res;