DIB Engine: implement most engine functions
[wine/hacks.git] / dlls / winedib.drv / font.c
blob215b27dff9afdfbf0fe6c183abb802a0d3df887d
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);
29 /**********************************************************************
30 * DIBDRV_SetTextColor
32 COLORREF DIBDRV_SetTextColor( DIBDRVPHYSDEV *physDev, COLORREF color )
34 COLORREF res;
35 INT r, g, b;
36 INT i;
38 MAYBE(TRACE("physDev:%p, color:%08x\n", physDev, color));
40 if(physDev->hasDIB)
42 /* DIB section selected in, use DIB Engine */
44 /* do nothing if color is the same as actual one */
45 if(color == physDev->textColor)
46 return color;
48 /* stores old color */
49 res = physDev->textColor;
51 /* fills the text color table used on antialiased font display */
52 if(physDev->physBitmap.funcs)
54 r = GetRValue(color);
55 g = GetGValue(color);
56 b = GetBValue(color);
57 for(i = 0; i < 256; i++)
59 physDev->textColorTable[i] = physDev->physBitmap.funcs->ColorToPixel(&physDev->physBitmap, RGB(
60 MulDiv(r, i, 256),
61 MulDiv(g, i, 256),
62 MulDiv(b, i, 256)
63 ));
67 /* returns previous text color */
68 return res;
70 else
72 /* DDB selected in, use X11 driver */
73 res = _DIBDRV_GetDisplayDriver()->pSetTextColor(physDev->X11PhysDev, color);
75 return res;
78 /***********************************************************************
79 * DIBDRV_SelectFont
81 HFONT DIBDRV_SelectFont( DIBDRVPHYSDEV *physDev, HFONT hfont, GdiFont *gdiFont )
83 HFONT res;
84 FT_Int i;
85 FT_Error error;
86 FT_CharMap charmap = NULL;
87 LOGFONTW lf;
89 MAYBE(TRACE("physDev:%p, hfont:%p, gdiFont:%p\n", physDev, hfont, gdiFont));
91 if(physDev->hasDIB)
93 /* DIB section selected in, use DIB Engine */
95 /* gets font information */
96 GetObjectW(hfont, sizeof(lf), &lf);
97 MAYBE(TRACE("Font is : '%s'\n", debugstr_w(lf.lfFaceName)));
99 /* FIXME: just handles gdifont, don't know if it needs to handle hfont too
100 BTW, still don't know how to get FT_Face from non-gdi font here
102 if(!gdiFont)
104 FIXME("No gdi font - unhandled by now.\n");
105 return hfont;
108 physDev->face = gdiFont->ft_face;
109 if(!physDev->face)
111 FIXME("Error, null Ft_Face\n");
112 return hfont;
115 /* setup the correct charmap.... maybe */
116 for (i = 0; i < physDev->face->num_charmaps; ++i)
118 if (physDev->face->charmaps[i]->platform_id != TT_PLATFORM_MICROSOFT)
119 continue;
121 if (physDev->face->charmaps[i]->encoding_id == TT_MS_ID_UNICODE_CS)
123 charmap = physDev->face->charmaps[i];
124 break;
127 if (charmap == NULL)
129 WARN("Selected fallout charmap #%d\n", i);
130 charmap = physDev->face->charmaps[i];
133 if (charmap == NULL)
135 WARN("No Windows character map found\n");
136 charmap = physDev->face->charmaps[0];
137 return 0;
140 error = pFT_Set_Charmap(physDev->face, charmap);
141 if (error != FT_Err_Ok)
143 ERR("%s returned %i\n", "FT_Set_Charmap", error);
144 return 0;
147 /* we use GDI fonts, so just return false */
148 return 0;
151 else
153 /* DDB selected in, use X11 driver */
154 res = _DIBDRV_GetDisplayDriver()->pSelectFont(physDev->X11PhysDev, hfont, gdiFont);
156 return res;
159 /***********************************************************************
160 * DIBDRV_EnumDeviceFonts
162 BOOL DIBDRV_EnumDeviceFonts( DIBDRVPHYSDEV *physDev, LPLOGFONTW plf,
163 FONTENUMPROCW proc, LPARAM lp )
165 BOOL res;
167 MAYBE(TRACE("physDev:%p, plf:%p, proc:%p, lp:%lx\n", physDev, plf, proc, lp));
169 if(physDev->hasDIB)
171 /* DIB section selected in, use DIB Engine */
172 ONCE(FIXME("STUB\n"));
173 res = 0;
175 else
177 /* DDB selected in, use X11 driver */
178 res = _DIBDRV_GetDisplayDriver()->pEnumDeviceFonts(physDev->X11PhysDev, plf, proc, lp);
180 return res;
183 /***********************************************************************
184 * DIBDRV_GetTextMetrics
186 BOOL DIBDRV_GetTextMetrics( DIBDRVPHYSDEV *physDev, TEXTMETRICW *metrics )
188 BOOL res;
190 MAYBE(TRACE("physDev:%p, metrics:%p\n", physDev, metrics));
192 if(physDev->hasDIB)
194 /* DIB section selected in, use DIB Engine */
195 ONCE(FIXME("STUB\n"));
196 res = 0;
198 else
200 /* DDB selected in, use X11 driver */
201 res = _DIBDRV_GetDisplayDriver()->pGetTextMetrics(physDev->X11PhysDev, metrics);
203 return res;
206 /***********************************************************************
207 * DIBDRV_GetCharWidth
209 BOOL DIBDRV_GetCharWidth( DIBDRVPHYSDEV *physDev, UINT firstChar, UINT lastChar,
210 LPINT buffer )
212 BOOL res;
214 MAYBE(TRACE("physDev:%p, firstChar:%d, lastChar:%d, buffer:%pn", physDev, firstChar, lastChar, buffer));
216 if(physDev->hasDIB)
218 /* DIB section selected in, use DIB Engine */
219 ONCE(FIXME("STUB\n"));
220 res = 0;
222 else
224 /* DDB selected in, use X11 driver */
225 res = _DIBDRV_GetDisplayDriver()->pGetCharWidth(physDev->X11PhysDev, firstChar, lastChar, buffer);
227 return res;