DIB Engine: fixed nasty font bug
[wine/dibdrv-max.git] / dlls / winedib.drv / font.c
blob116f5da4717fa91f9b748d7be25f8982ac27a96c
1 /*
2 * DIBDRV font objects
4 * Copyright 2007 Jesse Allen
5 * Copyright 2008 Massimo Del Fedele
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "config.h"
24 #include "wine/port.h"
26 #include "dibdrv.h"
28 WINE_DEFAULT_DEBUG_CHANNEL(dibdrv);
30 /**********************************************************************
31 * DIBDRV_SetTextColor
33 COLORREF DIBDRV_SetTextColor( DIBDRVPHYSDEV *physDev, COLORREF color )
35 COLORREF oldColor;
36 INT r, g, b;
37 INT i;
39 TRACE("physDev:%p, color:%x\n", physDev, color);
41 /* do nothing if color is the same as actual one */
42 if(color == physDev->textColor)
43 return color;
45 /* stores old color */
46 oldColor = physDev->textColor;
48 /* fills the text color table used on antialiased font display */
49 if(physDev->bmp.funcs)
51 r = GetRValue(color);
52 g = GetGValue(color);
53 b = GetBValue(color);
54 for(i = 0; i < 256; i++)
56 physDev->bmp.textColorTable[i] = physDev->bmp.funcs->colorref_to_pixel(&physDev->bmp, RGB(
57 MulDiv(r, i, 256),
58 MulDiv(g, i, 256),
59 MulDiv(b, i, 256)
60 ));
65 /* returns previous text color */
66 return oldColor;
69 /***********************************************************************
70 * DIBDRV_SelectFont
72 HFONT DIBDRV_SelectFont( DIBDRVPHYSDEV *physDev, HFONT hfont, GdiFont *gdiFont )
74 FT_Int i;
75 FT_Error error;
76 FT_CharMap charmap = NULL;
77 LOGFONTW lf;
78 GdiFont *curFont;
80 FIXME("physDev:%p, hfont:%p, gdiFont:%p\n", physDev, hfont, gdiFont);
82 /* gets font information */
83 GetObjectW(hfont, sizeof(lf), &lf);
84 TRACE("Font is : '%s'\n", debugstr_w(lf.lfFaceName));
86 /* FIXME: just handles gdifont, don't know if it needs to handle hfont too
87 BTW, still don't know how to get FT_Face from non-gdi font here
89 if(!gdiFont)
91 FIXME("No gdi font - unhandled by now.\n");
92 return hfont;
95 physDev->face = gdiFont->ft_face;
96 if(!physDev->face)
98 FIXME("Error, null Ft_Face\n");
99 return hfont;
102 /* setup the correct charmap.... maybe */
103 for (i = 0; i < physDev->face->num_charmaps; ++i)
105 if (physDev->face->charmaps[i]->platform_id != TT_PLATFORM_MICROSOFT)
106 continue;
108 if (physDev->face->charmaps[i]->encoding_id == TT_MS_ID_UNICODE_CS)
110 charmap = physDev->face->charmaps[i];
111 break;
114 if (charmap == NULL)
116 WARN("Selected fallout charmap #%d\n", i);
117 charmap = physDev->face->charmaps[i];
120 if (charmap == NULL)
122 WARN("No Windows character map found\n");
123 charmap = physDev->face->charmaps[0];
124 return FALSE;
127 error = pFT_Set_Charmap(physDev->face, charmap);
128 if (error != FT_Err_Ok)
130 ERR("%s returned %i\n", "FT_Set_Charmap", error);
131 return FALSE;
134 /* we use GDI fonts, so just return false */
135 return 0;
138 /***********************************************************************
139 * DIBDRV_EnumDeviceFonts
141 BOOL DIBDRV_EnumDeviceFonts( DIBDRVPHYSDEV *physDev, LPLOGFONTW plf,
142 FONTENUMPROCW proc, LPARAM lp )
144 TRACE("physDev:%p, plf:%p, proc:%p, lp:%lx\n", physDev, plf, proc, lp);
146 /* don't enumerate x11 fonts, we're using client side fonts */
147 return FALSE;
150 /***********************************************************************
151 * DIBDRV_GetTextMetrics
153 BOOL DIBDRV_GetTextMetrics( DIBDRVPHYSDEV *physDev, TEXTMETRICW *metrics )
155 TRACE("physDev:%p, metrics:%p\n", physDev, metrics);
157 /* no need for this one, as we use GDI fonts */
158 return FALSE;
161 /***********************************************************************
162 * DIBDRV_GetCharWidth
164 BOOL DIBDRV_GetCharWidth( DIBDRVPHYSDEV *physDev, UINT firstChar, UINT lastChar,
165 LPINT buffer )
167 TRACE("physDev:%p, firstChar:%d, lastChar:%d, buffer:%pn", physDev, firstChar, lastChar, buffer);
169 /* no need for this one, as we use GDI fonts */
170 return FALSE;