ReactOS  0.4.14-dev-52-g6116262
text.c
Go to the documentation of this file.
1 /*
2  * PROJECT: ReactOS win32 kernel mode subsystem
3  * LICENSE: GPL - See COPYING in the top level directory
4  * FILE: win32ss/gdi/ntgdi/text.c
5  * PURPOSE: Text/Font
6  * PROGRAMMER:
7  */
8 
11 #include <win32k.h>
12 
13 #define NDEBUG
14 #include <debug.h>
15 
20  HDC hdc,
21  int nXStart,
22  int nYStart,
23  LPCWSTR lpString,
24  int cchString)
25 {
26  return GreExtTextOutW(hdc, nXStart, nYStart, 0, NULL, lpString, cchString, NULL, 0);
27 }
28 
29 /*
30  flOpts :
31  GetTextExtentPoint32W = 0
32  GetTextExtentPointW = 1
33  */
34 BOOL
37  HDC hDC,
38  LPCWSTR lpwsz,
39  INT cwc,
40  LPSIZE psize,
41  UINT flOpts)
42 {
43  PDC pdc;
44  PDC_ATTR pdcattr;
45  BOOL Result;
46  PTEXTOBJ TextObj;
47 
48  if (!cwc)
49  {
50  psize->cx = 0;
51  psize->cy = 0;
52  return TRUE;
53  }
54 
55  pdc = DC_LockDc(hDC);
56  if (!pdc)
57  {
59  return FALSE;
60  }
61 
62  pdcattr = pdc->pdcattr;
63 
64  TextObj = RealizeFontInit(pdcattr->hlfntNew);
65  if ( TextObj )
66  {
68  TextObj,
69  lpwsz,
70  cwc,
71  0,
72  NULL,
73  0,
74  psize,
75  flOpts);
76  TEXTOBJ_UnlockText(TextObj);
77  }
78  else
79  Result = FALSE;
80 
81  DC_UnlockDc(pdc);
82  return Result;
83 }
84 
85 
86 /*
87  fl :
88  GetTextExtentExPointW = 0 and everything else that uses this.
89  GetTextExtentExPointI = 1
90  */
91 BOOL
94  HDC hDC,
96  ULONG Count,
97  ULONG MaxExtent,
98  PULONG Fit,
99  PULONG Dx,
100  LPSIZE pSize,
101  FLONG fl)
102 {
103  PDC pdc;
104  PDC_ATTR pdcattr;
105  BOOL Result;
106  PTEXTOBJ TextObj;
107 
108  if ( (!String && Count ) || !pSize )
109  {
111  return FALSE;
112  }
113 
114  if ( !Count )
115  {
116  if ( Fit ) Fit = 0;
117  return TRUE;
118  }
119 
120  pdc = DC_LockDc(hDC);
121  if (NULL == pdc)
122  {
124  return FALSE;
125  }
126  pdcattr = pdc->pdcattr;
127 
128  TextObj = RealizeFontInit(pdcattr->hlfntNew);
129  if ( TextObj )
130  {
132  TextObj,
133  String,
134  Count,
135  MaxExtent,
136  (LPINT)Fit,
137  (LPINT)Dx,
138  pSize,
139  fl);
140  TEXTOBJ_UnlockText(TextObj);
141  }
142  else
143  Result = FALSE;
144 
145  DC_UnlockDc(pdc);
146  return Result;
147 }
148 
149 BOOL
150 WINAPI
152  _In_ HDC hdc,
154 {
155  TMW_INTERNAL tmwi;
156  if (!ftGdiGetTextMetricsW(hdc, &tmwi)) return FALSE;
157  *lptm = tmwi.TextMetric;
158  return TRUE;
159 }
160 
161 DWORD
162 APIENTRY
164 {
165  PDC Dc;
166  PDC_ATTR pdcattr;
167  DWORD cscp;
168  // If here, update everything!
169  Dc = DC_LockDc(hDC);
170  if (!Dc)
171  {
173  return 0;
174  }
175  cscp = ftGdiGetTextCharsetInfo(Dc, NULL, 0);
176  pdcattr = Dc->pdcattr;
177  pdcattr->iCS_CP = cscp;
178  pdcattr->ulDirty_ &= ~DIRTY_CHARSET;
179  DC_UnlockDc( Dc );
180  return cscp;
181 }
182 
183 BOOL
184 APIENTRY
186  OUT LPRASTERIZER_STATUS praststat,
187  IN ULONG cjBytes)
188 {
190  RASTERIZER_STATUS rsSafe;
191 
192  if (praststat && cjBytes)
193  {
194  if ( cjBytes >= sizeof(RASTERIZER_STATUS) ) cjBytes = sizeof(RASTERIZER_STATUS);
195  if ( ftGdiGetRasterizerCaps(&rsSafe))
196  {
197  _SEH2_TRY
198  {
199  ProbeForWrite( praststat,
200  sizeof(RASTERIZER_STATUS),
201  1);
202  RtlCopyMemory(praststat, &rsSafe, cjBytes );
203  }
205  {
207  }
208  _SEH2_END;
209 
210  if (!NT_SUCCESS(Status))
211  {
213  return FALSE;
214  }
215 
216  return TRUE;
217  }
218  }
219  return FALSE;
220 }
221 
222 INT
223 APIENTRY
225  IN HDC hdc,
227  IN DWORD dwFlags)
228 {
229  PDC Dc;
230  INT Ret;
231  FONTSIGNATURE fsSafe;
232  PFONTSIGNATURE pfsSafe = &fsSafe;
234 
235  Dc = DC_LockDc(hdc);
236  if (!Dc)
237  {
239  return DEFAULT_CHARSET;
240  }
241 
242  if (!lpSig) pfsSafe = NULL;
243 
244  Ret = HIWORD(ftGdiGetTextCharsetInfo( Dc, pfsSafe, dwFlags));
245 
246  if (lpSig)
247  {
248  if (Ret == DEFAULT_CHARSET)
249  RtlZeroMemory(pfsSafe, sizeof(FONTSIGNATURE));
250 
251  _SEH2_TRY
252  {
253  ProbeForWrite( lpSig,
254  sizeof(FONTSIGNATURE),
255  1);
256  RtlCopyMemory(lpSig, pfsSafe, sizeof(FONTSIGNATURE));
257  }
259  {
261  }
262  _SEH2_END;
263 
264  if (!NT_SUCCESS(Status))
265  {
267  return DEFAULT_CHARSET;
268  }
269  }
270  DC_UnlockDc(Dc);
271  return Ret;
272 }
273 
274 
275 /*
276  fl :
277  GetTextExtentExPointW = 0 and everything else that uses this.
278  GetTextExtentExPointI = 1
279  */
280 W32KAPI
281 BOOL
282 APIENTRY
284  IN HDC hDC,
285  IN OPTIONAL LPWSTR UnsafeString,
286  IN ULONG Count,
287  IN ULONG MaxExtent,
288  OUT OPTIONAL PULONG UnsafeFit,
289  OUT OPTIONAL PULONG UnsafeDx,
290  OUT LPSIZE UnsafeSize,
291  IN FLONG fl
292 )
293 {
294  PDC dc;
295  PDC_ATTR pdcattr;
296  LPWSTR String;
297  SIZE Size;
299  BOOLEAN Result;
300  INT Fit;
301  LPINT Dx;
302  PTEXTOBJ TextObj;
303 
304  if ((LONG)Count < 0)
305  {
307  return FALSE;
308  }
309 
310  /* FIXME: Handle fl */
311 
312  if (0 == Count)
313  {
314  Size.cx = 0;
315  Size.cy = 0;
316  Status = MmCopyToCaller(UnsafeSize, &Size, sizeof(SIZE));
317  if (! NT_SUCCESS(Status))
318  {
320  return FALSE;
321  }
322  return TRUE;
323  }
324 
326  if (NULL == String)
327  {
329  return FALSE;
330  }
331 
332  if (NULL != UnsafeDx)
333  {
335  if (NULL == Dx)
336  {
339  return FALSE;
340  }
341  }
342  else
343  {
344  Dx = NULL;
345  }
346 
347  Status = MmCopyFromCaller(String, UnsafeString, Count * sizeof(WCHAR));
348  if (! NT_SUCCESS(Status))
349  {
350  if (NULL != Dx)
351  {
353  }
356  return FALSE;
357  }
358 
359  dc = DC_LockDc(hDC);
360  if (NULL == dc)
361  {
362  if (NULL != Dx)
363  {
365  }
368  return FALSE;
369  }
370  pdcattr = dc->pdcattr;
371  TextObj = RealizeFontInit(pdcattr->hlfntNew);
372  if ( TextObj )
373  {
375  TextObj,
376  String,
377  Count,
378  MaxExtent,
379  NULL == UnsafeFit ? NULL : &Fit,
380  Dx,
381  &Size,
382  fl);
383  TEXTOBJ_UnlockText(TextObj);
384  }
385  else
386  Result = FALSE;
387  DC_UnlockDc(dc);
388 
390  if (! Result)
391  {
392  if (NULL != Dx)
393  {
395  }
396  return FALSE;
397  }
398 
399  if (NULL != UnsafeFit)
400  {
401  Status = MmCopyToCaller(UnsafeFit, &Fit, sizeof(INT));
402  if (! NT_SUCCESS(Status))
403  {
404  if (NULL != Dx)
405  {
407  }
409  return FALSE;
410  }
411  }
412 
413  if (NULL != UnsafeDx)
414  {
415  Status = MmCopyToCaller(UnsafeDx, Dx, Count * sizeof(INT));
416  if (! NT_SUCCESS(Status))
417  {
418  if (NULL != Dx)
419  {
421  }
423  return FALSE;
424  }
425  }
426  if (NULL != Dx)
427  {
429  }
430 
431  Status = MmCopyToCaller(UnsafeSize, &Size, sizeof(SIZE));
432  if (! NT_SUCCESS(Status))
433  {
435  return FALSE;
436  }
437 
438  return TRUE;
439 }
440 
441 
442 /*
443  flOpts :
444  GetTextExtentPoint32W = 0
445  GetTextExtentPointW = 1
446  */
447 BOOL
448 APIENTRY
450  LPWSTR lpwsz,
451  INT cwc,
452  LPSIZE psize,
453  UINT flOpts)
454 {
455  return NtGdiGetTextExtentExW(hdc, lpwsz, cwc, 0, NULL, NULL, psize, flOpts);
456 }
457 
458 BOOL
459 APIENTRY
461  int BreakExtra,
462  int BreakCount)
463 {
464  PDC pDc;
465  PDC_ATTR pdcattr;
466 
467  pDc = DC_LockDc(hDC);
468  if (!pDc)
469  {
471  return FALSE;
472  }
473 
474  pdcattr = pDc->pdcattr;
475 
476  pdcattr->lBreakExtra = BreakExtra;
477  pdcattr->cBreak = BreakCount;
478 
479  DC_UnlockDc(pDc);
480  return TRUE;
481 }
482 
483 
484 W32KAPI
485 INT
486 APIENTRY
488  IN HDC hDC,
489  IN INT Count,
490  OUT OPTIONAL LPWSTR FaceName,
491  IN BOOL bAliasName
492 )
493 {
494  PDC Dc;
495  PDC_ATTR pdcattr;
496  HFONT hFont;
497  PTEXTOBJ TextObj;
499  SIZE_T fLen;
500  INT ret;
501 
502  /* FIXME: Handle bAliasName */
503 
504  Dc = DC_LockDc(hDC);
505  if (Dc == NULL)
506  {
508  return FALSE;
509  }
510  pdcattr = Dc->pdcattr;
511  hFont = pdcattr->hlfntNew;
512  DC_UnlockDc(Dc);
513 
514  TextObj = RealizeFontInit(hFont);
515  ASSERT(TextObj != NULL);
516  fLen = wcslen(TextObj->TextFace) + 1;
517 
518  if (FaceName != NULL)
519  {
520  Count = min(Count, fLen);
521  Status = MmCopyToCaller(FaceName, TextObj->TextFace, Count * sizeof(WCHAR));
522  if (!NT_SUCCESS(Status))
523  {
524  TEXTOBJ_UnlockText(TextObj);
526  return 0;
527  }
528  /* Terminate if we copied only part of the font name */
529  if (Count > 0 && Count < fLen)
530  {
531  FaceName[Count - 1] = '\0';
532  }
533  ret = Count;
534  }
535  else
536  {
537  ret = fLen;
538  }
539 
540  TEXTOBJ_UnlockText(TextObj);
541  return ret;
542 }
543 
544 W32KAPI
545 BOOL
546 APIENTRY
548  IN HDC hDC,
549  OUT TMW_INTERNAL * pUnsafeTmwi,
550  IN ULONG cj)
551 {
552  TMW_INTERNAL Tmwi;
553 
554  if ( cj <= sizeof(TMW_INTERNAL) )
555  {
556  if (ftGdiGetTextMetricsW(hDC, &Tmwi))
557  {
558  _SEH2_TRY
559  {
560  ProbeForWrite(pUnsafeTmwi, cj, 1);
561  RtlCopyMemory(pUnsafeTmwi, &Tmwi, cj);
562  }
564  {
566  _SEH2_YIELD(return FALSE);
567  }
568  _SEH2_END
569 
570  return TRUE;
571  }
572  }
573  return FALSE;
574 }
575 
576 /* EOF */
TEXTMETRICW TextMetric
Definition: ntgdityp.h:369
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#define IN
Definition: typedefs.h:38
#define TRUE
Definition: types.h:120
NTSYSAPI VOID NTAPI RtlCopyMemory(VOID UNALIGNED *Destination, CONST VOID UNALIGNED *Source, ULONG Length)
_In_ ULONG cj
Definition: winddi.h:3540
_Must_inspect_result_ _Out_ LPSIZE psize
Definition: ntgdi.h:1569
FORCEINLINE PDC DC_LockDc(HDC hdc)
Definition: dc.h:219
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
FORCEINLINE VOID TEXTOBJ_UnlockText(PLFONT plfnt)
Definition: text.h:96
LONG lBreakExtra
Definition: ntgdihdl.h:332
#define DIRTY_CHARSET
Definition: ntgdihdl.h:149
BOOL FASTCALL GreGetTextExtentW(HDC hDC, LPCWSTR lpwsz, INT cwc, LPSIZE psize, UINT flOpts)
Definition: text.c:36
#define ERROR_INVALID_HANDLE
Definition: compat.h:88
LONG NTSTATUS
Definition: precomp.h:26
static HDC
Definition: imagelist.c:92
BOOL APIENTRY NtGdiGetRasterizerCaps(OUT LPRASTERIZER_STATUS praststat, IN ULONG cjBytes)
Definition: text.c:185
struct _RASTERIZER_STATUS RASTERIZER_STATUS
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
_Inout_ __drv_aliasesMem PSLIST_ENTRY _Inout_ PSLIST_ENTRY _In_ ULONG Count
Definition: exfuncs.h:1015
#define MmCopyFromCaller
Definition: polytest.cpp:29
HDC dc
Definition: cylfrac.c:34
#define MmCopyToCaller(x, y, z)
Definition: mmcopy.h:19
static WCHAR String[]
Definition: stringtable.c:55
#define DEFAULT_CHARSET
Definition: wingdi.h:383
#define FASTCALL
Definition: nt_native.h:50
int32_t INT
Definition: typedefs.h:56
VOID NTAPI ProbeForWrite(IN PVOID Address, IN SIZE_T Length, IN ULONG Alignment)
Definition: exintrin.c:143
HFONT hFont
Definition: main.c:53
_SEH2_TRY
Definition: create.c:4250
_In_ FLONG fl
Definition: winddi.h:1279
Definition: text.h:59
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
HANDLE hlfntNew
Definition: ntgdihdl.h:334
#define EXCEPTION_EXECUTE_HANDLER
Definition: excpt.h:85
unsigned char BOOLEAN
BOOL FASTCALL ftGdiGetRasterizerCaps(LPRASTERIZER_STATUS lprs)
Definition: freetype.c:3279
smooth NULL
Definition: ftsmooth.c:416
_At_(*)(_In_ PWSK_CLIENT Client, _In_opt_ PUNICODE_STRING NodeName, _In_opt_ PUNICODE_STRING ServiceName, _In_opt_ ULONG NameSpace, _In_opt_ GUID *Provider, _In_opt_ PADDRINFOEXW Hints, _Outptr_ PADDRINFOEXW *Result, _In_opt_ PEPROCESS OwningProcess, _In_opt_ PETHREAD OwningThread, _Inout_ PIRP Irp Result)(Mem)) NTSTATUS(WSKAPI *PFN_WSK_GET_ADDRESS_INFO
Definition: wsk.h:426
#define _Out_
Definition: no_sal2.h:323
LONG cx
Definition: windef.h:319
BOOL FASTCALL GreTextOutW(HDC hdc, int nXStart, int nYStart, LPCWSTR lpString, int cchString)
Definition: text.c:19
unsigned long FLONG
Definition: ntbasedef.h:373
ULONG ulDirty_
Definition: ntgdihdl.h:298
Definition: polytest.cpp:40
#define _SEH2_YIELD(STMT_)
Definition: pseh2_64.h:8
BOOL WINAPI GreGetTextMetricsW(_In_ HDC hdc, _Out_ LPTEXTMETRICW lptm)
Definition: text.c:151
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
W32KAPI BOOL APIENTRY NtGdiGetTextMetricsW(IN HDC hDC, OUT TMW_INTERNAL *pUnsafeTmwi, IN ULONG cj)
Definition: text.c:547
#define WINAPI
Definition: msvc.h:8
BOOL APIENTRY GreExtTextOutW(IN HDC hDC, IN INT XStart, IN INT YStart, IN UINT fuOptions, IN OPTIONAL PRECTL lprc, IN LPCWSTR String, IN INT Count, IN OPTIONAL LPINT Dx, IN DWORD dwCodePage)
Definition: freetype.c:6765
DWORD iCS_CP
Definition: ntgdihdl.h:309
unsigned long DWORD
Definition: ntddk_ex.h:95
LONG cBreak
Definition: ntgdihdl.h:333
ASSERT((InvokeOnSuccess||InvokeOnError||InvokeOnCancel) ?(CompletionRoutine !=NULL) :TRUE)
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
int ret
HDC hdc
Definition: main.c:9
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
BOOL FASTCALL ftGdiGetTextMetricsW(HDC hDC, PTMW_INTERNAL ptmwi)
Definition: freetype.c:4704
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
BOOL APIENTRY NtGdiGetTextExtent(HDC hdc, LPWSTR lpwsz, INT cwc, LPSIZE psize, UINT flOpts)
Definition: text.c:449
VOID FASTCALL SetLastNtError(NTSTATUS Status)
Definition: error.c:36
Status
Definition: gdiplustypes.h:24
#define _In_
Definition: no_sal2.h:204
static HDC hDC
Definition: 3dtext.c:33
ULONG_PTR SIZE_T
Definition: typedefs.h:78
_SEH2_END
Definition: create.c:4424
#define GDITAG_TEXT
Definition: tags.h:171
FORCEINLINE VOID DC_UnlockDc(PDC pdc)
Definition: dc.h:237
PTEXTOBJ FASTCALL RealizeFontInit(HFONT hFont)
Definition: font.c:422
BOOL APIENTRY NtGdiSetTextJustification(HDC hDC, int BreakExtra, int BreakCount)
Definition: text.c:460
WCHAR TextFace[LF_FACESIZE]
Definition: text.h:67
unsigned int * PULONG
Definition: retypes.h:1
#define min(a, b)
Definition: monoChain.cc:55
unsigned int UINT
Definition: ndis.h:50
W32KAPI INT APIENTRY NtGdiGetTextFaceW(IN HDC hDC, IN INT Count, OUT OPTIONAL LPWSTR FaceName, IN BOOL bAliasName)
Definition: text.c:487
DWORD APIENTRY NtGdiGetCharSet(HDC hDC)
Definition: text.c:163
W32KAPI BOOL APIENTRY NtGdiGetTextExtentExW(IN HDC hDC, IN OPTIONAL LPWSTR UnsafeString, IN ULONG Count, IN ULONG MaxExtent, OUT OPTIONAL PULONG UnsafeFit, OUT OPTIONAL PULONG UnsafeDx, OUT LPSIZE UnsafeSize, IN FLONG fl)
Definition: text.c:283
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
#define OUT
Definition: typedefs.h:39
#define HIWORD(l)
Definition: typedefs.h:246
unsigned int ULONG
Definition: retypes.h:1
#define W32KAPI
Definition: ntgdi.h:9
#define RtlZeroMemory(Destination, Length)
Definition: typedefs.h:261
INT APIENTRY NtGdiGetTextCharsetInfo(IN HDC hdc, OUT OPTIONAL LPFONTSIGNATURE lpSig, IN DWORD dwFlags)
Definition: text.c:224
#define _SEH2_EXCEPT(...)
Definition: pseh2_64.h:6
#define ExFreePoolWithTag(_P, _T)
Definition: module.h:1099
#define _SEH2_GetExceptionCode()
Definition: pseh2_64.h:12
WCHAR * LPWSTR
Definition: xmlstorage.h:184
BOOL FASTCALL TextIntGetTextExtentPoint(PDC dc, PTEXTOBJ TextObj, LPCWSTR String, INT Count, ULONG MaxExtent, LPINT Fit, LPINT Dx, LPSIZE Size, FLONG fl)
Definition: freetype.c:4383
return STATUS_SUCCESS
Definition: btrfs.c:2966
INT FASTCALL ftGdiGetTextCharsetInfo(PDC Dc, LPFONTSIGNATURE lpSig, DWORD dwFlags)
Definition: freetype.c:4523
LONG cy
Definition: windef.h:320
BOOL FASTCALL GreGetTextExtentExW(HDC hDC, LPCWSTR String, ULONG Count, ULONG MaxExtent, PULONG Fit, PULONG Dx, LPSIZE pSize, FLONG fl)
Definition: text.c:93
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
ENGAPI VOID APIENTRY EngSetLastError(_In_ ULONG iError)
Definition: error.c:27
static LPTEXTMETRICW lptm
Definition: font.c:42
#define APIENTRY
Definition: api.h:79
int * LPINT
Definition: windef.h:178
PULONG MinorVersion OPTIONAL
Definition: CrossNt.h:68