Small fix.
[wine/multimedia.git] / graphics / win16drv / font.c
blobca1a4bf1757da16eb77da7ec9ee1d93237a7bc40
1 /*
2 * Windows driver font functions
4 * Copyright 1996 John Harvey
5 * 1998 Huw Davies
6 */
8 #include <string.h>
9 #include "wine/winbase16.h"
10 #include "win16drv.h"
11 #include "module.h"
12 #include "font.h"
13 #include "heap.h"
14 #include "debugtools.h"
16 DEFAULT_DEBUG_CHANNEL(win16drv)
19 /***********************************************************************
20 * WIN16DRV_GetTextExtentPoint
22 BOOL WIN16DRV_GetTextExtentPoint( DC *dc, LPCWSTR wstr, INT count,
23 LPSIZE size )
25 WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dc->physDev;
26 DWORD dwRet;
27 char *str;
29 TRACE("%04x %s %d %p\n",
30 dc->hSelf, debugstr_wn(wstr, count), count, size);
32 str = HeapAlloc( GetProcessHeap(), 0, count+1 );
33 lstrcpynWtoA( str, wstr, count+1 );
34 dwRet = PRTDRV_ExtTextOut(physDev->segptrPDEVICE, 0, 0,
35 NULL, str,
36 -count, physDev->FontInfo,
37 win16drv_SegPtr_DrawMode,
38 win16drv_SegPtr_TextXForm, NULL, NULL, 0);
39 size->cx = XDSTOLS(dc,LOWORD(dwRet));
40 size->cy = YDSTOLS(dc,HIWORD(dwRet));
41 TRACE("cx=0x%x, cy=0x%x\n",
42 size->cx, size->cy );
43 HeapFree( GetProcessHeap(), 0, str );
44 return TRUE;
48 /***********************************************************************
49 * WIN16DRV_GetTextMetrics
51 BOOL WIN16DRV_GetTextMetrics( DC *dc, TEXTMETRICA *metrics )
53 WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dc->physDev;
55 TRACE("%04x \n", dc->hSelf);
57 FONT_TextMetric16to32A( &physDev->tm, metrics );
59 TRACE(
60 "H %ld, A %ld, D %ld, Int %ld, Ext %ld, AW %ld, MW %ld, W %ld\n",
61 metrics->tmHeight,
62 metrics->tmAscent,
63 metrics->tmDescent,
64 metrics->tmInternalLeading,
65 metrics->tmExternalLeading,
66 metrics->tmAveCharWidth,
67 metrics->tmMaxCharWidth,
68 metrics->tmWeight);
70 return TRUE;
73 HFONT WIN16DRV_FONT_SelectObject( DC * dc, HFONT hfont, FONTOBJ * font)
75 WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dc->physDev;
76 HPEN prevHandle = dc->w.hFont;
77 int nSize;
79 dc->w.hFont = hfont;
81 TRACE("WIN16DRV_FONT_SelectObject '%s' h=%d\n",
82 font->logfont.lfFaceName, font->logfont.lfHeight);
85 if( physDev->FontInfo )
87 TRACE("UnRealizing FontInfo\n");
88 nSize = PRTDRV_RealizeObject (physDev->segptrPDEVICE, -DRVOBJ_FONT,
89 physDev->FontInfo,
90 physDev->FontInfo, 0);
93 memcpy(&physDev->lf, &font->logfont, sizeof(LOGFONT16));
94 nSize = PRTDRV_RealizeObject (physDev->segptrPDEVICE, DRVOBJ_FONT,
95 &physDev->lf, 0, 0);
97 if( physDev->FontInfo &&
98 HeapSize( SegptrHeap, 0, physDev->FontInfo ) < nSize )
100 SEGPTR_FREE( physDev->FontInfo );
101 physDev->FontInfo = NULL;
104 if( !physDev->FontInfo )
105 physDev->FontInfo = SEGPTR_ALLOC( nSize );
108 nSize = PRTDRV_RealizeObject(physDev->segptrPDEVICE, DRVOBJ_FONT,
109 &physDev->lf,
110 physDev->FontInfo,
111 win16drv_SegPtr_TextXForm );
113 #define fi physDev->FontInfo
114 physDev->tm.tmHeight = YDSTOLS(dc, fi->dfPixHeight);
115 physDev->tm.tmAscent = YDSTOLS(dc, fi->dfAscent);
116 physDev->tm.tmDescent = physDev->tm.tmHeight -
117 physDev->tm.tmAscent;
118 physDev->tm.tmInternalLeading = YDSTOLS(dc, fi->dfInternalLeading);
119 physDev->tm.tmExternalLeading = YDSTOLS(dc, fi->dfExternalLeading);
120 physDev->tm.tmAveCharWidth = XDSTOLS(dc, fi->dfAvgWidth);
121 physDev->tm.tmMaxCharWidth = XDSTOLS(dc, fi->dfMaxWidth);
122 physDev->tm.tmWeight = fi->dfWeight;
123 physDev->tm.tmOverhang = 0; /*FIXME*/
124 physDev->tm.tmDigitizedAspectX = fi->dfHorizRes;
125 physDev->tm.tmDigitizedAspectY = fi->dfVertRes;
126 physDev->tm.tmFirstChar = fi->dfFirstChar;
127 physDev->tm.tmLastChar = fi->dfLastChar;
128 physDev->tm.tmDefaultChar = fi->dfDefaultChar;
129 physDev->tm.tmBreakChar = fi->dfBreakChar;
130 physDev->tm.tmItalic = fi->dfItalic;
131 physDev->tm.tmUnderlined = fi->dfUnderline;
132 physDev->tm.tmStruckOut = fi->dfStrikeOut;
133 physDev->tm.tmPitchAndFamily = fi->dfPitchAndFamily;
134 physDev->tm.tmCharSet = fi->dfCharSet;
135 #undef fi
137 TRACE("H %d, A %d, D %d, Int %d, Ext %d, AW %d, MW %d, W %d\n",
138 physDev->tm.tmHeight,
139 physDev->tm.tmAscent,
140 physDev->tm.tmDescent,
141 physDev->tm.tmInternalLeading,
142 physDev->tm.tmExternalLeading,
143 physDev->tm.tmAveCharWidth,
144 physDev->tm.tmMaxCharWidth,
145 physDev->tm.tmWeight);
147 return prevHandle;
150 /***********************************************************************
151 * GetCharWidth32A (GDI32.155)
153 BOOL WIN16DRV_GetCharWidth( DC *dc, UINT firstChar, UINT lastChar,
154 LPINT buffer )
156 int i;
157 WORD wRet;
159 WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dc->physDev;
161 TRACE("%d - %d into %p\n",
162 firstChar, lastChar, buffer );
164 wRet = PRTDRV_GetCharWidth( physDev->segptrPDEVICE, buffer, firstChar,
165 lastChar, physDev->FontInfo,
166 win16drv_SegPtr_DrawMode,
167 win16drv_SegPtr_TextXForm );
168 if( TRACE_ON(win16drv) ){
169 for(i = 0; i <= lastChar - firstChar; i++)
170 TRACE("Char %x: width %d\n", i + firstChar,
171 buffer[i]);
174 return wRet;
177 /***********************************************************************
179 * WIN16DRV_EnumDeviceFonts
182 BOOL WIN16DRV_EnumDeviceFonts( DC* dc, LPLOGFONT16 plf,
183 DEVICEFONTENUMPROC proc, LPARAM lp )
185 WIN16DRV_PDEVICE *physDev = (WIN16DRV_PDEVICE *)dc->physDev;
186 WORD wRet;
187 WEPFC wepfc;
188 /* EnumDFontCallback is GDI.158 */
189 FARPROC16 pfnCallback = NE_GetEntryPoint( GetModuleHandle16("GDI"), 158 );
191 wepfc.proc = (int (*)(LPENUMLOGFONT16,LPNEWTEXTMETRIC16,UINT16,LPARAM))proc;
192 wepfc.lp = lp;
194 wRet = PRTDRV_EnumDFonts(physDev->segptrPDEVICE, plf->lfFaceName[0] ?
195 plf->lfFaceName : NULL , pfnCallback , &wepfc );
196 return wRet;
200 * EnumCallback (GDI.158)
202 * This is the callback function used when EnumDFonts is called.
203 * (The printer drivers uses it to pass info on available fonts).
205 * lpvClientData is the pointer passed to EnumDFonts, which points to a WEPFC
206 * structure (WEPFC = WINE_ENUM_PRINTER_FONT_CALLBACK).
211 WORD WINAPI WineEnumDFontCallback(LPENUMLOGFONT16 lpLogFont,
212 LPNEWTEXTMETRIC16 lpTextMetrics,
213 WORD wFontType, LONG lpClientData)
215 TRACE("In WineEnumDFontCallback plf=%p\n", lpLogFont);
216 return (*(((WEPFC *)lpClientData)->proc))( lpLogFont, lpTextMetrics,
217 wFontType, ((WEPFC *)lpClientData)->lp );