2 * Windows driver font functions
4 * Copyright 1996 John Harvey
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 #include "wine/winbase16.h"
25 #include "win16drv/win16drv.h"
28 #include "wine/debug.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(win16drv);
33 /***********************************************************************
34 * WIN16DRV_GetTextExtentPoint
36 BOOL WIN16DRV_GetTextExtentPoint( PHYSDEV dev, LPCWSTR wstr, INT count,
39 WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dev;
44 TRACE("%04x %s %d %p\n", physDev->hdc, debugstr_wn(wstr, count), count, size);
47 len = WideCharToMultiByte( CP_ACP, 0, wstr, count, NULL, 0, NULL, NULL );
48 str = HeapAlloc( GetProcessHeap(), 0, len );
49 WideCharToMultiByte( CP_ACP, 0, wstr, count, str, len, NULL, NULL );
51 dwRet = PRTDRV_ExtTextOut(physDev->segptrPDEVICE, 0, 0,
52 NULL, str, -len, physDev->FontInfo,
53 win16drv_SegPtr_DrawMode,
54 win16drv_SegPtr_TextXForm, NULL, NULL, 0);
55 size->cx = XDSTOLS(dc,LOWORD(dwRet));
56 size->cy = YDSTOLS(dc,HIWORD(dwRet));
57 TRACE("cx=%ld, cy=%ld\n", size->cx, size->cy );
58 HeapFree( GetProcessHeap(), 0, str );
63 /***********************************************************************
64 * WIN16DRV_GetTextMetrics
66 BOOL WIN16DRV_GetTextMetrics( PHYSDEV dev, TEXTMETRICW *metrics )
68 WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dev;
70 TRACE("%04x \n", physDev->hdc);
72 FONT_TextMetric16ToW( &physDev->tm, metrics );
75 "H %ld, A %ld, D %ld, Int %ld, Ext %ld, AW %ld, MW %ld, W %ld\n",
79 metrics->tmInternalLeading,
80 metrics->tmExternalLeading,
81 metrics->tmAveCharWidth,
82 metrics->tmMaxCharWidth,
88 /***********************************************************************
91 HFONT WIN16DRV_SelectFont( PHYSDEV dev, HFONT hfont)
93 WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dev;
97 if (!GetObject16( hfont, sizeof(physDev->lf), &physDev->lf ))
100 TRACE("WIN16DRV_FONT_SelectObject %s h=%d\n",
101 debugstr_a(physDev->lf.lfFaceName), physDev->lf.lfHeight);
103 if( physDev->FontInfo )
105 TRACE("UnRealizing FontInfo\n");
106 nSize = PRTDRV_RealizeObject (physDev->segptrPDEVICE, -DRVOBJ_FONT,
108 physDev->FontInfo, 0);
111 nSize = PRTDRV_RealizeObject (physDev->segptrPDEVICE, DRVOBJ_FONT,
114 if( physDev->FontInfo &&
115 HeapSize( GetProcessHeap(), 0, physDev->FontInfo ) < nSize )
117 HeapFree( GetProcessHeap(), 0, physDev->FontInfo );
118 physDev->FontInfo = NULL;
121 if( !physDev->FontInfo )
122 physDev->FontInfo = HeapAlloc( GetProcessHeap(), 0, nSize );
125 nSize = PRTDRV_RealizeObject(physDev->segptrPDEVICE, DRVOBJ_FONT,
128 win16drv_SegPtr_TextXForm );
130 #define fi physDev->FontInfo
131 physDev->tm.tmHeight = YDSTOLS(dc, fi->dfPixHeight);
132 physDev->tm.tmAscent = YDSTOLS(dc, fi->dfAscent);
133 physDev->tm.tmDescent = physDev->tm.tmHeight -
134 physDev->tm.tmAscent;
135 physDev->tm.tmInternalLeading = YDSTOLS(dc, fi->dfInternalLeading);
136 physDev->tm.tmExternalLeading = YDSTOLS(dc, fi->dfExternalLeading);
137 physDev->tm.tmAveCharWidth = XDSTOLS(dc, fi->dfAvgWidth);
138 physDev->tm.tmMaxCharWidth = XDSTOLS(dc, fi->dfMaxWidth);
139 physDev->tm.tmWeight = fi->dfWeight;
140 physDev->tm.tmOverhang = 0; /*FIXME*/
141 physDev->tm.tmDigitizedAspectX = fi->dfHorizRes;
142 physDev->tm.tmDigitizedAspectY = fi->dfVertRes;
143 physDev->tm.tmFirstChar = fi->dfFirstChar;
144 physDev->tm.tmLastChar = fi->dfLastChar;
145 physDev->tm.tmDefaultChar = fi->dfDefaultChar;
146 physDev->tm.tmBreakChar = fi->dfBreakChar;
147 physDev->tm.tmItalic = fi->dfItalic;
148 physDev->tm.tmUnderlined = fi->dfUnderline;
149 physDev->tm.tmStruckOut = fi->dfStrikeOut;
150 physDev->tm.tmPitchAndFamily = fi->dfPitchAndFamily;
151 physDev->tm.tmCharSet = fi->dfCharSet;
154 TRACE("H %d, A %d, D %d, Int %d, Ext %d, AW %d, MW %d, W %d\n",
155 physDev->tm.tmHeight,
156 physDev->tm.tmAscent,
157 physDev->tm.tmDescent,
158 physDev->tm.tmInternalLeading,
159 physDev->tm.tmExternalLeading,
160 physDev->tm.tmAveCharWidth,
161 physDev->tm.tmMaxCharWidth,
162 physDev->tm.tmWeight);
164 return TRUE; /* We'll use a device font */
167 /***********************************************************************
168 * WIN16DRV_GetCharWidth
170 BOOL WIN16DRV_GetCharWidth( PHYSDEV dev, UINT firstChar, UINT lastChar,
175 WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dev;
177 TRACE("%d - %d into %p\n", firstChar, lastChar, buffer );
179 wRet = PRTDRV_GetCharWidth( physDev->segptrPDEVICE, buffer, firstChar,
180 lastChar, physDev->FontInfo,
181 win16drv_SegPtr_DrawMode,
182 win16drv_SegPtr_TextXForm );
183 if( TRACE_ON(win16drv) ){
184 for(i = 0; i <= lastChar - firstChar; i++)
185 TRACE("Char %x: width %d\n", i + firstChar,
192 /***********************************************************************
194 * WIN16DRV_EnumDeviceFonts
197 BOOL WIN16DRV_EnumDeviceFonts( PHYSDEV dev, LPLOGFONTW plf,
198 DEVICEFONTENUMPROC proc, LPARAM lp )
200 WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dev;
203 char *FaceNameA = NULL;
204 /* EnumDFontCallback is GDI.158 */
205 FARPROC16 pfnCallback = GetProcAddress16( GetModuleHandle16("GDI"), (LPCSTR)158 );
210 if(plf->lfFaceName[0]) {
212 len = WideCharToMultiByte(CP_ACP, 0, plf->lfFaceName, -1, NULL, 0,
214 FaceNameA = HeapAlloc(GetProcessHeap(), 0, len);
215 WideCharToMultiByte(CP_ACP, 0, plf->lfFaceName, -1, FaceNameA, len,
218 wRet = PRTDRV_EnumDFonts(physDev->segptrPDEVICE, FaceNameA, pfnCallback,
220 if(FaceNameA) HeapFree(GetProcessHeap(), 0, FaceNameA);
224 /***********************************************************************
225 * EnumCallback (GDI.158)
227 * This is the callback function used when EnumDFonts is called.
228 * (The printer drivers uses it to pass info on available fonts).
230 * lpvClientData is the pointer passed to EnumDFonts, which points to a WEPFC
231 * structure (WEPFC = WINE_ENUM_PRINTER_FONT_CALLBACK).
234 WORD WINAPI EnumCallback16(LPENUMLOGFONT16 lpLogFont,
235 LPNEWTEXTMETRIC16 lpTextMetrics,
236 WORD wFontType, LONG lpClientData)
239 ENUMLOGFONTEX16 lf16;
241 NEWTEXTMETRICEXW tmW;
242 NEWTEXTMETRICEX16 tm16;
244 TRACE("In EnumCallback16 plf=%p\n", lpLogFont);
246 /* we have a ENUMLOGFONT16 which is a subset of ENUMLOGFONTEX16,
247 so we copy it into one of these and then convert to ENUMLOGFONTEXW */
249 memset(&lf16, 0, sizeof(lf16));
250 memcpy(&lf16, lpLogFont, sizeof(*lpLogFont));
251 FONT_EnumLogFontEx16ToW(&lf16, &lfW);
253 /* and a similar idea for NEWTEXTMETRIC16 */
254 memset(&tm16, 0, sizeof(tm16));
255 memcpy(&tm16, lpTextMetrics, sizeof(*lpTextMetrics));
256 FONT_NewTextMetricEx16ToW(&tm16, &tmW);
258 return (*(((WEPFC *)lpClientData)->proc))( &lfW, &tmW, wFontType,
259 ((WEPFC *)lpClientData)->lp );