[GDI32]
[reactos.git] / reactos / dll / win32 / gdi32 / objects / text.c
index 33e5a0e..d64e012 100644 (file)
@@ -1,18 +1,17 @@
 #include "precomp.h"
 
 
-
 /*
  * @implemented
  */
 BOOL
-STDCALL
+WINAPI
 TextOutA(
        HDC  hdc,
        int  nXStart,
        int  nYStart,
        LPCSTR  lpString,
-       int  cbString)
+       int  cchString)
 {
         ANSI_STRING StringA;
         UNICODE_STRING StringU;
@@ -25,7 +24,7 @@ TextOutA(
        } else
                StringU.Buffer = NULL;
 
-       ret = TextOutW(hdc, nXStart, nYStart, StringU.Buffer, cbString);
+       ret = TextOutW(hdc, nXStart, nYStart, StringU.Buffer, cchString);
        RtlFreeUnicodeString(&StringU);
        return ret;
 }
@@ -35,15 +34,15 @@ TextOutA(
  * @implemented
  */
 BOOL
-STDCALL
+WINAPI
 TextOutW(
        HDC  hdc,
        int  nXStart,
        int  nYStart,
        LPCWSTR  lpString,
-       int  cbString)
+       int  cchString)
 {
-  return NtGdiExtTextOut(hdc, nXStart, nYStart, 0, NULL, lpString, cbString, NULL);
+  return NtGdiExtTextOutW(hdc, nXStart, nYStart, 0, NULL, (LPWSTR)lpString, cchString, NULL, 0);
 }
 
 
@@ -51,12 +50,11 @@ TextOutW(
  * @implemented
  */
 DWORD
-STDCALL
+WINAPI
 GdiGetCodePage(HDC hdc)
 {
   PDC_ATTR Dc_Attr;
-  if (!GdiGetHandleUserData((HGDIOBJ) hdc, (PVOID) &Dc_Attr) ||
-       (GDI_HANDLE_GET_TYPE(hdc) != GDI_OBJECT_TYPE_DC)) return 0;
+  if (!GdiGetHandleUserData((HGDIOBJ) hdc, GDI_OBJECT_TYPE_DC, (PVOID) &Dc_Attr)) return 0;
   if (Dc_Attr->ulDirty_ & DIRTY_CHARSET) return LOWORD(NtGdiGetCharSet(hdc));
   return LOWORD(Dc_Attr->iCS_CP);
 }
@@ -66,15 +64,14 @@ GdiGetCodePage(HDC hdc)
  * @unimplemented
  */
 int
-STDCALL
+WINAPI
 GetTextCharacterExtra(
        HDC     hDc
        )
 {
   PDC_ATTR Dc_Attr;
 
-  if (!GdiGetHandleUserData((HGDIOBJ) hDc, (PVOID) &Dc_Attr) ||
-      (GDI_HANDLE_GET_TYPE(hDc) != GDI_OBJECT_TYPE_DC)) return 0;
+  if (!GdiGetHandleUserData((HGDIOBJ) hDc, GDI_OBJECT_TYPE_DC, (PVOID) &Dc_Attr)) return 0;
   return Dc_Attr->lTextExtra;
 // return GetDCDWord( hDc, GdiGetTextCharExtra, 0);
 }
@@ -84,7 +81,7 @@ GetTextCharacterExtra(
  * @implemented
  */
 int
-STDCALL
+WINAPI
 GetTextCharset(HDC hdc)
 {
     /* MSDN docs say this is equivalent */
@@ -93,12 +90,11 @@ GetTextCharset(HDC hdc)
 
 
 
-
 /*
  * @implemented
  */
 BOOL
-STDCALL
+WINAPI
 GetTextMetricsA(
        HDC             hdc,
        LPTEXTMETRICA   lptm
@@ -111,7 +107,8 @@ GetTextMetricsA(
     return FALSE;
   }
 
-  return TextMetricW2A(lptm, &tmwi.TextMetric);
+  FONT_TextMetricWToA(&tmwi.TextMetric, lptm);
+  return TRUE;
 }
 
 
@@ -119,7 +116,7 @@ GetTextMetricsA(
  * @implemented
  */
 BOOL
-STDCALL
+WINAPI
 GetTextMetricsW(
        HDC             hdc,
        LPTEXTMETRICW   lptm
@@ -145,7 +142,7 @@ APIENTRY
 GetTextExtentPointA(
        HDC             hdc,
        LPCSTR          lpString,
-       int             cbString,
+       int             cchString,
        LPSIZE          lpSize
        )
 {
@@ -156,7 +153,7 @@ GetTextExtentPointA(
        RtlInitAnsiString(&StringA, (LPSTR)lpString);
        RtlAnsiStringToUnicodeString(&StringU, &StringA, TRUE);
 
-        ret = GetTextExtentPointW(hdc, StringU.Buffer, cbString, lpSize);
+        ret = GetTextExtentPointW(hdc, StringU.Buffer, cchString, lpSize);
 
        RtlFreeUnicodeString(&StringU);
 
@@ -172,11 +169,11 @@ APIENTRY
 GetTextExtentPointW(
        HDC             hdc,
        LPCWSTR         lpString,
-       int             cbString,
+       int             cchString,
        LPSIZE          lpSize
        )
 {
-  return NtGdiGetTextExtent(hdc, (LPWSTR)lpString, cbString, lpSize, 0);
+  return NtGdiGetTextExtent(hdc, (LPWSTR)lpString, cchString, lpSize, 1);
 }
 
 
@@ -186,15 +183,22 @@ GetTextExtentPointW(
 BOOL
 APIENTRY
 GetTextExtentExPointW(
-       HDC             hdc,
-       LPCWSTR         lpszStr,
-       int             cchString,
-       int             nMaxExtent,
-       LPINT           lpnFit,
-       LPINT           alpDx,
-       LPSIZE          lpSize
+       HDC     hdc,
+       LPCWSTR lpszStr,
+       int     cchString,
+       int     nMaxExtent,
+       LPINT   lpnFit,
+       LPINT   alpDx,
+       LPSIZE  lpSize
        )
 {
+
+  if(nMaxExtent < -1)
+  {
+    SetLastError(ERROR_INVALID_PARAMETER);
+    return FALSE;
+  }
+
   return NtGdiGetTextExtentExW (
     hdc, (LPWSTR)lpszStr, cchString, nMaxExtent, (PULONG)lpnFit, (PULONG)alpDx, lpSize, 0 );
 }
@@ -219,6 +223,12 @@ GetTextExtentExPointA(
   LPWSTR lpszStrW;
   BOOL rc = 0;
 
+  if(nMaxExtent < -1)
+  {
+    SetLastError(ERROR_INVALID_PARAMETER);
+    return FALSE;
+  }
+
   Status = HEAP_strdupA2W ( &lpszStrW, lpszStr );
   if (!NT_SUCCESS (Status))
     SetLastError (RtlNtStatusToDosError(Status));
@@ -242,7 +252,7 @@ APIENTRY
 GetTextExtentPoint32A(
        HDC             hdc,
        LPCSTR          lpString,
-       int             cbString,
+       int             cchString,
        LPSIZE          lpSize
        )
 {
@@ -253,7 +263,7 @@ GetTextExtentPoint32A(
   RtlInitAnsiString(&StringA, (LPSTR)lpString);
   RtlAnsiStringToUnicodeString(&StringU, &StringA, TRUE);
 
-  ret = GetTextExtentPoint32W(hdc, StringU.Buffer, cbString, lpSize);
+  ret = GetTextExtentPoint32W(hdc, StringU.Buffer, cchString, lpSize);
 
   RtlFreeUnicodeString(&StringU);
 
@@ -269,19 +279,47 @@ APIENTRY
 GetTextExtentPoint32W(
        HDC             hdc,
        LPCWSTR         lpString,
-       int             cbString,
+       int             cchString,
        LPSIZE          lpSize
        )
 {
-  return NtGdiGetTextExtentPoint32(hdc, lpString, cbString, lpSize);
+       return NtGdiGetTextExtent(hdc, (LPWSTR)lpString, cchString, lpSize, 0);
 }
 
+/*
+ * @implemented
+ */
+BOOL
+WINAPI
+GetTextExtentExPointI(HDC hdc,
+                      LPWORD pgiIn,
+                      int cgi,
+                      int nMaxExtent,
+                      LPINT lpnFit,
+                      LPINT alpDx,
+                      LPSIZE lpSize)
+{
+    return NtGdiGetTextExtentExW(hdc,pgiIn,cgi,nMaxExtent,(ULONG *)lpnFit, (PULONG) alpDx,lpSize,1);
+}
 
 /*
  * @implemented
  */
 BOOL
-STDCALL
+WINAPI
+GetTextExtentPointI(HDC hdc,
+                    LPWORD pgiIn,
+                    int cgi,
+                    LPSIZE lpSize)
+{
+    return NtGdiGetTextExtent(hdc,pgiIn,cgi,lpSize,2);
+}
+
+/*
+ * @implemented
+ */
+BOOL
+WINAPI
 ExtTextOutA(
        HDC             hdc,
        int             X,
@@ -289,7 +327,7 @@ ExtTextOutA(
        UINT            fuOptions,
        CONST RECT      *lprc,
        LPCSTR          lpString,
-       UINT            cbCount,
+       UINT            cchString,
        CONST INT       *lpDx
        )
 {
@@ -300,7 +338,7 @@ ExtTextOutA(
        RtlInitAnsiString(&StringA, (LPSTR)lpString);
        RtlAnsiStringToUnicodeString(&StringU, &StringA, TRUE);
 
-        ret = ExtTextOutW(hdc, X, Y, fuOptions, lprc, StringU.Buffer, cbCount, lpDx);
+        ret = ExtTextOutW(hdc, X, Y, fuOptions, lprc, StringU.Buffer, cchString, lpDx);
 
        RtlFreeUnicodeString(&StringU);
 
@@ -312,7 +350,7 @@ ExtTextOutA(
  * @implemented
  */
 BOOL
-STDCALL
+WINAPI
 ExtTextOutW(
        HDC             hdc,
        int             X,
@@ -320,11 +358,11 @@ ExtTextOutW(
        UINT            fuOptions,
        CONST RECT      *lprc,
        LPCWSTR         lpString,
-       UINT            cbCount,
+       UINT            cchString,
        CONST INT       *lpDx
        )
 {
-  return NtGdiExtTextOut(hdc, X, Y, fuOptions, lprc, lpString, cbCount, lpDx);
+  return NtGdiExtTextOutW(hdc, X, Y, fuOptions, (LPRECT)lprc, (LPWSTR)lpString, cchString, (LPINT)lpDx, 0);
 }
 
 
@@ -332,21 +370,21 @@ ExtTextOutW(
  * @implemented
  */
 INT
-STDCALL
+WINAPI
 GetTextFaceW(HDC hDC,
-             int nCount,
-             LPWSTR    lpFaceName)
+             INT nCount,
+             PWSTR pFaceName)
 {
-    INT retValue = 0;
-    if ((!lpFaceName) || (nCount))
-    {
-        retValue = NtGdiGetTextFaceW(hDC,nCount,lpFaceName,0);
-    }
-    else
+    /* Validate parameters */
+    if (pFaceName && nCount <= 0)
     {
-        SetLastError(ERROR_INVALID_PARAMETER);
+        /* Set last error and return failure */
+        GdiSetLastError(ERROR_INVALID_PARAMETER);
+        return 0;
     }
-    return retValue;
+
+    /* Forward to kernel */
+    return NtGdiGetTextFaceW(hDC, nCount, pFaceName, FALSE);
 }
 
 
@@ -354,11 +392,26 @@ GetTextFaceW(HDC hDC,
  * @implemented
  */
 int
-STDCALL
+WINAPI
 GetTextFaceA( HDC hdc, INT count, LPSTR name )
 {
-    INT res = GetTextFaceW(hdc, 0, NULL);
-    LPWSTR nameW = HeapAlloc( GetProcessHeap(), 0, res * 2 );
+    INT res;
+    LPWSTR nameW;
+
+    /* Validate parameters */
+    if (name && count <= 0)
+    {
+        /* Set last error and return failure */
+        GdiSetLastError(ERROR_INVALID_PARAMETER);
+        return 0;
+    }
+
+    res = GetTextFaceW(hdc, 0, NULL);
+    nameW = HeapAlloc( GetProcessHeap(), 0, res * 2 );
+    if (nameW == NULL)
+    {
+        return 0;
+    }
     GetTextFaceW( hdc, res, nameW );
 
     if (name)
@@ -373,8 +426,27 @@ GetTextFaceA( HDC hdc, INT count, LPSTR name )
     return res;
 }
 
+
+/*
+ * @implemented
+ */
+INT
+WINAPI
+GetTextFaceAliasW(HDC hdc,
+                  int cChar,
+                  LPWSTR pszOut)
+{
+   if ( pszOut && !cChar )
+   {
+      GdiSetLastError(ERROR_INVALID_PARAMETER);
+      return 0;
+   }
+   return NtGdiGetTextFaceW(hdc,cChar,pszOut,TRUE);
+}
+
+
 BOOL
-STDCALL
+WINAPI
 GetFontResourceInfoW(
     LPCWSTR lpFileName,
     DWORD *pdwBufSize,
@@ -402,7 +474,7 @@ GetFontResourceInfoW(
 
     bRet = NtGdiGetFontResourceInfoInternalW(
         NtFileName.Buffer,
-        NtFileName.Length,
+        (NtFileName.Length / sizeof(WCHAR)) + 1,
         1,
         *pdwBufSize,
         pdwBufSize,
@@ -424,7 +496,7 @@ GetFontResourceInfoW(
  * @unimplemented
  */
 int
-STDCALL
+WINAPI
 SetTextCharacterExtra(
        HDC     hDC,
        int     CharExtra
@@ -444,10 +516,9 @@ SetTextCharacterExtra(
     return MFDRV_SetTextCharacterExtra( hDC, CharExtra ); // Wine port.
   }
 #endif
-  if (!GdiGetHandleUserData((HGDIOBJ) hDC, (PVOID) &Dc_Attr) ||
-      (GDI_HANDLE_GET_TYPE(hDC) != GDI_OBJECT_TYPE_DC)) return cExtra;
+  if (!GdiGetHandleUserData((HGDIOBJ) hDC, GDI_OBJECT_TYPE_DC, (PVOID) &Dc_Attr)) return cExtra;
 
-  if (NtCurrentTeb()->GdiTebBatch.HDC == (ULONG)hDC)
+  if (NtCurrentTeb()->GdiTebBatch.HDC == hDC)
   {
      if (Dc_Attr->ulDirty_ & DC_FONTTEXT_DIRTY)
      {
@@ -466,12 +537,11 @@ SetTextCharacterExtra(
  *
  */
 UINT
-STDCALL
+WINAPI
 GetTextAlign(HDC hdc)
 {
   PDC_ATTR Dc_Attr;
-  if (!GdiGetHandleUserData((HGDIOBJ) hdc, (PVOID) &Dc_Attr) ||
-      (GDI_HANDLE_GET_TYPE(hdc) != GDI_OBJECT_TYPE_DC)) return 0;
+  if (!GdiGetHandleUserData((HGDIOBJ) hdc, GDI_OBJECT_TYPE_DC, (PVOID) &Dc_Attr)) return 0;
   return Dc_Attr->lTextAlign;
 }
 
@@ -481,12 +551,11 @@ GetTextAlign(HDC hdc)
  *
  */
 COLORREF
-STDCALL
+WINAPI
 GetTextColor(HDC hdc)
 {
   PDC_ATTR Dc_Attr;
-  if (!GdiGetHandleUserData((HGDIOBJ) hdc, (PVOID) &Dc_Attr) ||
-      (GDI_HANDLE_GET_TYPE(hdc) != GDI_OBJECT_TYPE_DC)) return 0;
+  if (!GdiGetHandleUserData((HGDIOBJ) hdc, GDI_OBJECT_TYPE_DC, (PVOID) &Dc_Attr)) return 0;
   return Dc_Attr->ulForegroundClr;
 }
 
@@ -496,7 +565,7 @@ GetTextColor(HDC hdc)
  * @unimplemented
  */
 UINT
-STDCALL
+WINAPI
 SetTextAlign(HDC hdc,
              UINT fMode)
 {
@@ -522,8 +591,7 @@ SetTextAlign(HDC hdc,
     }
   }
 #endif
-  if (!GdiGetHandleUserData((HGDIOBJ) hdc, (PVOID) &Dc_Attr) ||
-       (GDI_HANDLE_GET_TYPE(hdc) != GDI_OBJECT_TYPE_DC)) return OldMode;
+  if (!GdiGetHandleUserData((HGDIOBJ) hdc, GDI_OBJECT_TYPE_DC, (PVOID) &Dc_Attr)) return OldMode;
 
   OldMode = Dc_Attr->lTextAlign;
   Dc_Attr->lTextAlign = fMode; // Raw
@@ -541,7 +609,7 @@ SetTextAlign(HDC hdc,
  * @implemented
  */
 COLORREF
-STDCALL
+WINAPI
 SetTextColor(
        HDC hdc,
        COLORREF crColor
@@ -569,15 +637,14 @@ SetTextColor(
     }
   }
 #endif
-  if (!GdiGetHandleUserData((HGDIOBJ) hdc, (PVOID) &Dc_Attr) ||
-       (GDI_HANDLE_GET_TYPE(hdc) != GDI_OBJECT_TYPE_DC)) return OldColor;
+  if (!GdiGetHandleUserData((HGDIOBJ) hdc, GDI_OBJECT_TYPE_DC, (PVOID) &Dc_Attr)) return OldColor;
 
   OldColor = (COLORREF) Dc_Attr->ulForegroundClr;
   Dc_Attr->ulForegroundClr = (ULONG) crColor;
 
   if ( Dc_Attr->crForegroundClr != crColor )
   {
-     Dc_Attr->ulDirty_ |= DIRTY_TEXT;
+     Dc_Attr->ulDirty_ |= (DIRTY_TEXT|DIRTY_LINE|DIRTY_FILL);
      Dc_Attr->crForegroundClr = crColor;
   }
   return OldColor;
@@ -587,7 +654,7 @@ SetTextColor(
  * @implemented
  */
 BOOL
-STDCALL
+WINAPI
 SetTextJustification(
        HDC     hdc,
        int     extra,
@@ -606,10 +673,9 @@ SetTextJustification(
       return FALSE;
     }
 #endif
-  if (!GdiGetHandleUserData((HGDIOBJ) hdc, (PVOID) &Dc_Attr) ||
-      (GDI_HANDLE_GET_TYPE(hdc) != GDI_OBJECT_TYPE_DC)) return FALSE;
+  if (!GdiGetHandleUserData((HGDIOBJ) hdc, GDI_OBJECT_TYPE_DC, (PVOID) &Dc_Attr)) return FALSE;
 
-  if (NtCurrentTeb()->GdiTebBatch.HDC == (ULONG)hdc)
+  if (NtCurrentTeb()->GdiTebBatch.HDC == hdc)
   {
      if (Dc_Attr->ulDirty_ & DC_FONTTEXT_DIRTY)
      {
@@ -621,5 +687,3 @@ SetTextJustification(
   Dc_Attr->lBreakExtra = extra;
   return TRUE;
 }
-
-