Move GetTextFaceAliasW to text.c.
[reactos.git] / reactos / dll / win32 / gdi32 / objects / text.c
1 #include "precomp.h"
2
3
4
5 /*
6 * @implemented
7 */
8 BOOL
9 STDCALL
10 TextOutA(
11 HDC hdc,
12 int nXStart,
13 int nYStart,
14 LPCSTR lpString,
15 int cbString)
16 {
17 ANSI_STRING StringA;
18 UNICODE_STRING StringU;
19 BOOL ret;
20
21 if (NULL != lpString)
22 {
23 RtlInitAnsiString(&StringA, (LPSTR)lpString);
24 RtlAnsiStringToUnicodeString(&StringU, &StringA, TRUE);
25 } else
26 StringU.Buffer = NULL;
27
28 ret = TextOutW(hdc, nXStart, nYStart, StringU.Buffer, cbString);
29 RtlFreeUnicodeString(&StringU);
30 return ret;
31 }
32
33
34 /*
35 * @implemented
36 */
37 BOOL
38 STDCALL
39 TextOutW(
40 HDC hdc,
41 int nXStart,
42 int nYStart,
43 LPCWSTR lpString,
44 int cbString)
45 {
46 return NtGdiExtTextOutW(hdc, nXStart, nYStart, 0, NULL, (LPWSTR)lpString, cbString, NULL, 0);
47 }
48
49
50 /*
51 * @implemented
52 */
53 DWORD
54 STDCALL
55 GdiGetCodePage(HDC hdc)
56 {
57 PDC_ATTR Dc_Attr;
58 if (!GdiGetHandleUserData((HGDIOBJ) hdc, GDI_OBJECT_TYPE_DC, (PVOID) &Dc_Attr)) return 0;
59 if (Dc_Attr->ulDirty_ & DIRTY_CHARSET) return LOWORD(NtGdiGetCharSet(hdc));
60 return LOWORD(Dc_Attr->iCS_CP);
61 }
62
63
64 /*
65 * @unimplemented
66 */
67 int
68 STDCALL
69 GetTextCharacterExtra(
70 HDC hDc
71 )
72 {
73 PDC_ATTR Dc_Attr;
74
75 if (!GdiGetHandleUserData((HGDIOBJ) hDc, GDI_OBJECT_TYPE_DC, (PVOID) &Dc_Attr)) return 0;
76 return Dc_Attr->lTextExtra;
77 // return GetDCDWord( hDc, GdiGetTextCharExtra, 0);
78 }
79
80
81 /*
82 * @implemented
83 */
84 int
85 STDCALL
86 GetTextCharset(HDC hdc)
87 {
88 /* MSDN docs say this is equivalent */
89 return NtGdiGetTextCharsetInfo(hdc,NULL,0);
90 }
91
92
93
94
95 /*
96 * @implemented
97 */
98 BOOL
99 STDCALL
100 GetTextMetricsA(
101 HDC hdc,
102 LPTEXTMETRICA lptm
103 )
104 {
105 TMW_INTERNAL tmwi;
106
107 if (! NtGdiGetTextMetricsW(hdc, &tmwi, sizeof(TMW_INTERNAL)))
108 {
109 return FALSE;
110 }
111
112 return TextMetricW2A(lptm, &tmwi.TextMetric);
113 }
114
115
116 /*
117 * @implemented
118 */
119 BOOL
120 STDCALL
121 GetTextMetricsW(
122 HDC hdc,
123 LPTEXTMETRICW lptm
124 )
125 {
126 TMW_INTERNAL tmwi;
127
128 if (! NtGdiGetTextMetricsW(hdc, &tmwi, sizeof(TMW_INTERNAL)))
129 {
130 return FALSE;
131 }
132
133 *lptm = tmwi.TextMetric;
134 return TRUE;
135 }
136
137
138 /*
139 * @implemented
140 */
141 BOOL
142 APIENTRY
143 GetTextExtentPointA(
144 HDC hdc,
145 LPCSTR lpString,
146 int cbString,
147 LPSIZE lpSize
148 )
149 {
150 ANSI_STRING StringA;
151 UNICODE_STRING StringU;
152 BOOL ret;
153
154 RtlInitAnsiString(&StringA, (LPSTR)lpString);
155 RtlAnsiStringToUnicodeString(&StringU, &StringA, TRUE);
156
157 ret = GetTextExtentPointW(hdc, StringU.Buffer, cbString, lpSize);
158
159 RtlFreeUnicodeString(&StringU);
160
161 return ret;
162 }
163
164
165 /*
166 * @implemented
167 */
168 BOOL
169 APIENTRY
170 GetTextExtentPointW(
171 HDC hdc,
172 LPCWSTR lpString,
173 int cbString,
174 LPSIZE lpSize
175 )
176 {
177 return NtGdiGetTextExtent(hdc, (LPWSTR)lpString, cbString, lpSize, 0);
178 }
179
180
181 /*
182 * @implemented
183 */
184 BOOL
185 APIENTRY
186 GetTextExtentExPointW(
187 HDC hdc,
188 LPCWSTR lpszStr,
189 int cchString,
190 int nMaxExtent,
191 LPINT lpnFit,
192 LPINT alpDx,
193 LPSIZE lpSize
194 )
195 {
196 return NtGdiGetTextExtentExW (
197 hdc, (LPWSTR)lpszStr, cchString, nMaxExtent, (PULONG)lpnFit, (PULONG)alpDx, lpSize, 0 );
198 }
199
200
201 /*
202 * @implemented
203 */
204 BOOL
205 APIENTRY
206 GetTextExtentExPointA(
207 HDC hdc,
208 LPCSTR lpszStr,
209 int cchString,
210 int nMaxExtent,
211 LPINT lpnFit,
212 LPINT alpDx,
213 LPSIZE lpSize
214 )
215 {
216 NTSTATUS Status;
217 LPWSTR lpszStrW;
218 BOOL rc = 0;
219
220 Status = HEAP_strdupA2W ( &lpszStrW, lpszStr );
221 if (!NT_SUCCESS (Status))
222 SetLastError (RtlNtStatusToDosError(Status));
223 else
224 {
225 rc = NtGdiGetTextExtentExW (
226 hdc, lpszStrW, cchString, nMaxExtent, (PULONG)lpnFit, (PULONG)alpDx, lpSize, 0 );
227
228 HEAP_free ( lpszStrW );
229 }
230
231 return rc;
232 }
233
234
235 /*
236 * @implemented
237 */
238 BOOL
239 APIENTRY
240 GetTextExtentPoint32A(
241 HDC hdc,
242 LPCSTR lpString,
243 int cbString,
244 LPSIZE lpSize
245 )
246 {
247 ANSI_STRING StringA;
248 UNICODE_STRING StringU;
249 BOOL ret;
250
251 RtlInitAnsiString(&StringA, (LPSTR)lpString);
252 RtlAnsiStringToUnicodeString(&StringU, &StringA, TRUE);
253
254 ret = GetTextExtentPoint32W(hdc, StringU.Buffer, cbString, lpSize);
255
256 RtlFreeUnicodeString(&StringU);
257
258 return ret;
259 }
260
261
262 /*
263 * @implemented
264 */
265 BOOL
266 APIENTRY
267 GetTextExtentPoint32W(
268 HDC hdc,
269 LPCWSTR lpString,
270 int cbString,
271 LPSIZE lpSize
272 )
273 {
274 return NtGdiGetTextExtent(hdc, (LPWSTR)lpString, cbString, lpSize, 0);
275 }
276
277 /*
278 * @implemented
279 */
280 BOOL
281 STDCALL
282 GetTextExtentExPointI(HDC hdc,
283 LPWORD pgiIn,
284 int cgi,
285 int nMaxExtent,
286 LPINT lpnFit,
287 LPINT alpDx,
288 LPSIZE lpSize)
289 {
290 return NtGdiGetTextExtentExW(hdc,pgiIn,cgi,nMaxExtent,(ULONG *)lpnFit, (PULONG) alpDx,lpSize,1);
291 }
292
293 /*
294 * @implemented
295 */
296 BOOL
297 STDCALL
298 GetTextExtentPointI(HDC hdc,
299 LPWORD pgiIn,
300 int cgi,
301 LPSIZE lpSize)
302 {
303 return NtGdiGetTextExtent(hdc,pgiIn,cgi,lpSize,2);
304 }
305
306 /*
307 * @implemented
308 */
309 BOOL
310 STDCALL
311 ExtTextOutA(
312 HDC hdc,
313 int X,
314 int Y,
315 UINT fuOptions,
316 CONST RECT *lprc,
317 LPCSTR lpString,
318 UINT cbCount,
319 CONST INT *lpDx
320 )
321 {
322 ANSI_STRING StringA;
323 UNICODE_STRING StringU;
324 BOOL ret;
325
326 RtlInitAnsiString(&StringA, (LPSTR)lpString);
327 RtlAnsiStringToUnicodeString(&StringU, &StringA, TRUE);
328
329 ret = ExtTextOutW(hdc, X, Y, fuOptions, lprc, StringU.Buffer, cbCount, lpDx);
330
331 RtlFreeUnicodeString(&StringU);
332
333 return ret;
334 }
335
336
337 /*
338 * @implemented
339 */
340 BOOL
341 STDCALL
342 ExtTextOutW(
343 HDC hdc,
344 int X,
345 int Y,
346 UINT fuOptions,
347 CONST RECT *lprc,
348 LPCWSTR lpString,
349 UINT cbCount,
350 CONST INT *lpDx
351 )
352 {
353 return NtGdiExtTextOutW(hdc, X, Y, fuOptions, (LPRECT)lprc, (LPWSTR)lpString, cbCount, (LPINT)lpDx, 0);
354 }
355
356
357 /*
358 * @implemented
359 */
360 INT
361 WINAPI
362 GetTextFaceW(HDC hDC,
363 INT nCount,
364 PWSTR pFaceName)
365 {
366 if (pFaceName && nCount <= 0)
367 {
368 // GdiSetLastError(ERROR_INVALID_PARAMETER);
369 return 0;
370 }
371 return NtGdiGetTextFaceW(hDC, nCount, pFaceName, FALSE);
372 }
373
374
375 /*
376 * @implemented
377 */
378 int
379 STDCALL
380 GetTextFaceA( HDC hdc, INT count, LPSTR name )
381 {
382 INT res = GetTextFaceW(hdc, 0, NULL);
383 LPWSTR nameW = HeapAlloc( GetProcessHeap(), 0, res * 2 );
384 GetTextFaceW( hdc, res, nameW );
385
386 if (name)
387 {
388 if (count && !WideCharToMultiByte( CP_ACP, 0, nameW, -1, name, count, NULL, NULL))
389 name[count-1] = 0;
390 res = strlen(name);
391 }
392 else
393 res = WideCharToMultiByte( CP_ACP, 0, nameW, -1, NULL, 0, NULL, NULL);
394 HeapFree( GetProcessHeap(), 0, nameW );
395 return res;
396 }
397
398
399 /*
400 * @implemented
401 */
402 INT
403 STDCALL
404 GetTextFaceAliasW(HDC hdc,
405 int cChar,
406 LPWSTR pszOut)
407 {
408 if ( pszOut && !cChar )
409 {
410 GdiSetLastError(ERROR_INVALID_PARAMETER);
411 return 0;
412 }
413 return NtGdiGetTextFaceW(hdc,cChar,pszOut,TRUE);
414 }
415
416
417 BOOL
418 STDCALL
419 GetFontResourceInfoW(
420 LPCWSTR lpFileName,
421 DWORD *pdwBufSize,
422 void* lpBuffer,
423 DWORD dwType
424 )
425 {
426 BOOL bRet;
427 UNICODE_STRING NtFileName;
428
429 if (!lpFileName || !pdwBufSize || !lpBuffer)
430 {
431 SetLastError(ERROR_INVALID_PARAMETER);
432 return FALSE;
433 }
434
435 if (!RtlDosPathNameToNtPathName_U(lpFileName,
436 &NtFileName,
437 NULL,
438 NULL))
439 {
440 SetLastError(ERROR_PATH_NOT_FOUND);
441 return FALSE;
442 }
443
444 bRet = NtGdiGetFontResourceInfoInternalW(
445 NtFileName.Buffer,
446 (NtFileName.Length / sizeof(WCHAR)) + 1,
447 1,
448 *pdwBufSize,
449 pdwBufSize,
450 lpBuffer,
451 dwType);
452
453 RtlFreeHeap(RtlGetProcessHeap(), 0, NtFileName.Buffer);
454
455 if (!bRet)
456 {
457 return FALSE;
458 }
459
460 return TRUE;
461 }
462
463
464 /*
465 * @unimplemented
466 */
467 int
468 STDCALL
469 SetTextCharacterExtra(
470 HDC hDC,
471 int CharExtra
472 )
473 {
474 INT cExtra = 0x80000000;
475 PDC_ATTR Dc_Attr;
476
477 if (CharExtra == cExtra)
478 {
479 SetLastError(ERROR_INVALID_PARAMETER);
480 return cExtra;
481 }
482 #if 0
483 if (GDI_HANDLE_GET_TYPE(hDC) == GDI_OBJECT_TYPE_METADC)
484 {
485 return MFDRV_SetTextCharacterExtra( hDC, CharExtra ); // Wine port.
486 }
487 #endif
488 if (!GdiGetHandleUserData((HGDIOBJ) hDC, GDI_OBJECT_TYPE_DC, (PVOID) &Dc_Attr)) return cExtra;
489
490 if (NtCurrentTeb()->GdiTebBatch.HDC == hDC)
491 {
492 if (Dc_Attr->ulDirty_ & DC_FONTTEXT_DIRTY)
493 {
494 NtGdiFlush(); // Sync up Dc_Attr from Kernel space.
495 Dc_Attr->ulDirty_ &= ~(DC_MODE_DIRTY|DC_FONTTEXT_DIRTY);
496 }
497 }
498 cExtra = Dc_Attr->lTextExtra;
499 Dc_Attr->lTextExtra = CharExtra;
500 return cExtra;
501 // return GetAndSetDCDWord( hDC, GdiGetSetTextCharExtra, CharExtra, 0, 0, 0 );
502 }
503
504 /*
505 * @implemented
506 *
507 */
508 UINT
509 STDCALL
510 GetTextAlign(HDC hdc)
511 {
512 PDC_ATTR Dc_Attr;
513 if (!GdiGetHandleUserData((HGDIOBJ) hdc, GDI_OBJECT_TYPE_DC, (PVOID) &Dc_Attr)) return 0;
514 return Dc_Attr->lTextAlign;
515 }
516
517
518 /*
519 * @implemented
520 *
521 */
522 COLORREF
523 STDCALL
524 GetTextColor(HDC hdc)
525 {
526 PDC_ATTR Dc_Attr;
527 if (!GdiGetHandleUserData((HGDIOBJ) hdc, GDI_OBJECT_TYPE_DC, (PVOID) &Dc_Attr)) return 0;
528 return Dc_Attr->ulForegroundClr;
529 }
530
531
532
533 /*
534 * @unimplemented
535 */
536 UINT
537 STDCALL
538 SetTextAlign(HDC hdc,
539 UINT fMode)
540 {
541 PDC_ATTR Dc_Attr;
542 INT OldMode = 0;
543 #if 0
544 if (GDI_HANDLE_GET_TYPE(hDC) != GDI_OBJECT_TYPE_DC)
545 {
546 if (GDI_HANDLE_GET_TYPE(hDC) == GDI_OBJECT_TYPE_METADC)
547 return MFDRV_SetTextAlign( hdc, fMode )
548 else
549 {
550 PLDC pLDC = Dc_Attr->pvLDC;
551 if ( !pLDC )
552 {
553 SetLastError(ERROR_INVALID_HANDLE);
554 return FALSE;
555 }
556 if (pLDC->iType == LDC_EMFLDC)
557 {
558 if return EMFDRV_SetTextAlign( hdc, fMode )
559 }
560 }
561 }
562 #endif
563 if (!GdiGetHandleUserData((HGDIOBJ) hdc, GDI_OBJECT_TYPE_DC, (PVOID) &Dc_Attr)) return OldMode;
564
565 OldMode = Dc_Attr->lTextAlign;
566 Dc_Attr->lTextAlign = fMode; // Raw
567 if (Dc_Attr->dwLayout & LAYOUT_RTL)
568 {
569 if(!(fMode & TA_CENTER)) fMode |= TA_RIGHT;
570 }
571 Dc_Attr->flTextAlign = fMode & (TA_BASELINE|TA_UPDATECP|TA_CENTER);
572 return OldMode;
573
574 }
575
576
577 /*
578 * @implemented
579 */
580 COLORREF
581 STDCALL
582 SetTextColor(
583 HDC hdc,
584 COLORREF crColor
585 )
586 {
587 PDC_ATTR Dc_Attr;
588 COLORREF OldColor = CLR_INVALID;
589 #if 0
590 if (GDI_HANDLE_GET_TYPE(hDC) != GDI_OBJECT_TYPE_DC)
591 {
592 if (GDI_HANDLE_GET_TYPE(hDC) == GDI_OBJECT_TYPE_METADC)
593 return MFDRV_SetTextColor( hDC, crColor );
594 else
595 {
596 PLDC pLDC = Dc_Attr->pvLDC;
597 if ( !pLDC )
598 {
599 SetLastError(ERROR_INVALID_HANDLE);
600 return FALSE;
601 }
602 if (pLDC->iType == LDC_EMFLDC)
603 {
604 if return EMFDRV_SetTextColor( hDC, crColor );
605 }
606 }
607 }
608 #endif
609 if (!GdiGetHandleUserData((HGDIOBJ) hdc, GDI_OBJECT_TYPE_DC, (PVOID) &Dc_Attr)) return OldColor;
610
611 OldColor = (COLORREF) Dc_Attr->ulForegroundClr;
612 Dc_Attr->ulForegroundClr = (ULONG) crColor;
613
614 if ( Dc_Attr->crForegroundClr != crColor )
615 {
616 Dc_Attr->ulDirty_ |= DIRTY_TEXT;
617 Dc_Attr->crForegroundClr = crColor;
618 }
619 return OldColor;
620 }
621
622 /*
623 * @implemented
624 */
625 BOOL
626 STDCALL
627 SetTextJustification(
628 HDC hdc,
629 int extra,
630 int breaks
631 )
632 {
633 PDC_ATTR Dc_Attr;
634 #if 0
635 if (GDI_HANDLE_GET_TYPE(hDC) != GDI_OBJECT_TYPE_DC)
636 {
637 if (GDI_HANDLE_GET_TYPE(hDC) == GDI_OBJECT_TYPE_METADC)
638 return MFDRV_SetTextJustification( hdc, extra, breaks )
639 else
640 {
641 SetLastError(ERROR_INVALID_HANDLE);
642 return FALSE;
643 }
644 #endif
645 if (!GdiGetHandleUserData((HGDIOBJ) hdc, GDI_OBJECT_TYPE_DC, (PVOID) &Dc_Attr)) return FALSE;
646
647 if (NtCurrentTeb()->GdiTebBatch.HDC == hdc)
648 {
649 if (Dc_Attr->ulDirty_ & DC_FONTTEXT_DIRTY)
650 {
651 NtGdiFlush(); // Sync up Dc_Attr from Kernel space.
652 Dc_Attr->ulDirty_ &= ~(DC_MODE_DIRTY|DC_FONTTEXT_DIRTY);
653 }
654 }
655 Dc_Attr->cBreak = breaks;
656 Dc_Attr->lBreakExtra = extra;
657 return TRUE;
658 }