Consolidate filling of TEXTMETRICS to a single location.
authorGé van Geldorp <ge@gse.nl>
Mon, 27 Dec 2004 20:06:55 +0000 (20:06 +0000)
committerGé van Geldorp <ge@gse.nl>
Mon, 27 Dec 2004 20:06:55 +0000 (20:06 +0000)
svn path=/trunk/; revision=12369

reactos/subsys/win32k/objects/text.c

index 6dbdd9f..31804df 100644 (file)
@@ -22,7 +22,7 @@
  * along with this program; if not, write to the Free Software
  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
-/* $Id: text.c,v 1.122 2004/12/18 21:35:35 royce Exp $ */
+/* $Id: text.c,v 1.123 2004/12/27 20:06:55 gvg Exp $ */
 #include <w32k.h>
 
 #include <ft2build.h>
@@ -694,90 +694,14 @@ NtGdiTranslateCharsetInfo(PDWORD Src,
   return (BOOL) Ret;
 }
 
-
-/*************************************************************
- * IntGetOutlineTextMetrics
- *
- */
-static unsigned FASTCALL
-IntGetOutlineTextMetrics(PFONTGDI FontGDI, UINT Size,
-                         OUTLINETEXTMETRICW *Otm)
+static void FASTCALL
+FillTM(TEXTMETRICW *TM, FT_Face Face, TT_OS2 *pOS2, TT_HoriHeader *pHori)
 {
-  unsigned Needed;
-  TT_OS2 *pOS2;
-  TT_HoriHeader *pHori;
-  TT_Postscript *pPost;
   FT_Fixed XScale, YScale;
-  ANSI_STRING FamilyNameA, StyleNameA;
-  UNICODE_STRING FamilyNameW, StyleNameW, Regular;
-  char *Cp;
   int Ascent, Descent;
-  TEXTMETRICW *TM;
-
-  Needed = sizeof(OUTLINETEXTMETRICW);
-
-  RtlInitAnsiString(&FamilyNameA, FontGDI->face->family_name);
-  RtlAnsiStringToUnicodeString(&FamilyNameW, &FamilyNameA, TRUE);
-
-  RtlInitAnsiString(&StyleNameA, FontGDI->face->style_name);
-  RtlAnsiStringToUnicodeString(&StyleNameW, &StyleNameA, TRUE);
-
-  /* These names should be read from the TT name table */
-
-  /* length of otmpFamilyName */
-  Needed += FamilyNameW.Length + sizeof(WCHAR);
-
-  RtlInitUnicodeString(&Regular, L"regular");
-  /* length of otmpFaceName */
-  if (0 == RtlCompareUnicodeString(&StyleNameW, &Regular, TRUE))
-    {
-      Needed += FamilyNameW.Length + sizeof(WCHAR); /* just the family name */
-    }
-  else
-    {
-      Needed += FamilyNameW.Length + StyleNameW.Length + (sizeof(WCHAR) << 1); /* family + " " + style */
-    }
-
-  /* length of otmpStyleName */
-  Needed += StyleNameW.Length + sizeof(WCHAR);
-
-  /* length of otmpFullName */
-  Needed += FamilyNameW.Length + StyleNameW.Length + (sizeof(WCHAR) << 1);
-
-  if (Size < Needed)
-    {
-      RtlFreeUnicodeString(&FamilyNameW);
-      RtlFreeUnicodeString(&StyleNameW);
-      return Needed;
-    }
-
-  XScale = FontGDI->face->size->metrics.x_scale;
-  YScale = FontGDI->face->size->metrics.y_scale;
-
-  IntLockFreeType;
-  pOS2 = FT_Get_Sfnt_Table(FontGDI->face, ft_sfnt_os2);
-  if (NULL == pOS2)
-    {
-      IntUnLockFreeType;
-      DPRINT1("Can't find OS/2 table - not TT font?\n");
-      RtlFreeUnicodeString(&StyleNameW);
-      RtlFreeUnicodeString(&FamilyNameW);
-      return 0;
-    }
 
-  pHori = FT_Get_Sfnt_Table(FontGDI->face, ft_sfnt_hhea);
-  if (NULL == pHori)
-    {
-      IntUnLockFreeType;
-      DPRINT1("Can't find HHEA table - not TT font?\n");
-      RtlFreeUnicodeString(&StyleNameW);
-      RtlFreeUnicodeString(&FamilyNameW);
-      return 0;
-    }
-
-  pPost = FT_Get_Sfnt_Table(FontGDI->face, ft_sfnt_post); /* we can live with this failing */
-
-  Otm->otmSize = Needed;
+  XScale = Face->size->metrics.x_scale;
+  YScale = Face->size->metrics.y_scale;
 
   if (0 == pOS2->usWinAscent + pOS2->usWinDescent)
     {
@@ -790,11 +714,10 @@ IntGetOutlineTextMetrics(PFONTGDI FontGDI, UINT Size,
       Descent = pOS2->usWinDescent;
     }
 
-  TM = &Otm->otmTextMetrics;
   TM->tmAscent = (FT_MulFix(Ascent, YScale) + 32) >> 6;
   TM->tmDescent = (FT_MulFix(Descent, YScale) + 32) >> 6;
   TM->tmInternalLeading = (FT_MulFix(Ascent + Descent
-                                     - FontGDI->face->units_per_EM, YScale) + 32) >> 6;
+                                     - Face->units_per_EM, YScale) + 32) >> 6;
 
   TM->tmHeight = TM->tmAscent + TM->tmDescent;
 
@@ -811,8 +734,8 @@ IntGetOutlineTextMetrics(PFONTGDI FontGDI, UINT Size,
     {
       TM->tmAveCharWidth = 1;
     }
-  TM->tmMaxCharWidth = (FT_MulFix(FontGDI->face->bbox.xMax - FontGDI->face->bbox.xMin,
-                                 XScale) + 32) >> 6;
+  TM->tmMaxCharWidth = (FT_MulFix(Face->bbox.xMax - Face->bbox.xMin,
+                                  XScale) + 32) >> 6;
   TM->tmWeight = pOS2->usWeightClass;
   TM->tmOverhang = 0;
   TM->tmDigitizedAspectX = 300;
@@ -821,12 +744,12 @@ IntGetOutlineTextMetrics(PFONTGDI FontGDI, UINT Size,
   TM->tmLastChar = pOS2->usLastCharIndex;
   TM->tmDefaultChar = pOS2->usDefaultChar;
   TM->tmBreakChar = L'\0' != pOS2->usBreakChar ? pOS2->usBreakChar : ' ';
-  TM->tmItalic = (FontGDI->face->style_flags & FT_STYLE_FLAG_ITALIC) ? 255 : 0;
+  TM->tmItalic = (Face->style_flags & FT_STYLE_FLAG_ITALIC) ? 255 : 0;
   TM->tmUnderlined = 0; /* entry in OS2 table */
   TM->tmStruckOut = 0; /* entry in OS2 table */
 
   /* Yes TPMF_FIXED_PITCH is correct; braindead api */
-  if (! FT_IS_FIXED_WIDTH(FontGDI->face))
+  if (! FT_IS_FIXED_WIDTH(Face))
     {
       TM->tmPitchAndFamily = TMPF_FIXED_PITCH;
     }
@@ -868,18 +791,101 @@ IntGetOutlineTextMetrics(PFONTGDI FontGDI, UINT Size,
         TM->tmPitchAndFamily |= FF_DONTCARE;
     }
 
-  if (FT_IS_SCALABLE(FontGDI->face))
+  if (FT_IS_SCALABLE(Face))
     {
       TM->tmPitchAndFamily |= TMPF_VECTOR;
     }
-  if (FT_IS_SFNT(FontGDI->face))
+  if (FT_IS_SFNT(Face))
     {
       TM->tmPitchAndFamily |= TMPF_TRUETYPE;
     }
 
-#ifndef TODO
   TM->tmCharSet = DEFAULT_CHARSET;
-#endif
+}
+
+/*************************************************************
+ * IntGetOutlineTextMetrics
+ *
+ */
+static unsigned FASTCALL
+IntGetOutlineTextMetrics(PFONTGDI FontGDI, UINT Size,
+                         OUTLINETEXTMETRICW *Otm)
+{
+  unsigned Needed;
+  TT_OS2 *pOS2;
+  TT_HoriHeader *pHori;
+  TT_Postscript *pPost;
+  FT_Fixed XScale, YScale;
+  ANSI_STRING FamilyNameA, StyleNameA;
+  UNICODE_STRING FamilyNameW, StyleNameW, Regular;
+  char *Cp;
+
+  Needed = sizeof(OUTLINETEXTMETRICW);
+
+  RtlInitAnsiString(&FamilyNameA, FontGDI->face->family_name);
+  RtlAnsiStringToUnicodeString(&FamilyNameW, &FamilyNameA, TRUE);
+
+  RtlInitAnsiString(&StyleNameA, FontGDI->face->style_name);
+  RtlAnsiStringToUnicodeString(&StyleNameW, &StyleNameA, TRUE);
+
+  /* These names should be read from the TT name table */
+
+  /* length of otmpFamilyName */
+  Needed += FamilyNameW.Length + sizeof(WCHAR);
+
+  RtlInitUnicodeString(&Regular, L"regular");
+  /* length of otmpFaceName */
+  if (0 == RtlCompareUnicodeString(&StyleNameW, &Regular, TRUE))
+    {
+      Needed += FamilyNameW.Length + sizeof(WCHAR); /* just the family name */
+    }
+  else
+    {
+      Needed += FamilyNameW.Length + StyleNameW.Length + (sizeof(WCHAR) << 1); /* family + " " + style */
+    }
+
+  /* length of otmpStyleName */
+  Needed += StyleNameW.Length + sizeof(WCHAR);
+
+  /* length of otmpFullName */
+  Needed += FamilyNameW.Length + StyleNameW.Length + (sizeof(WCHAR) << 1);
+
+  if (Size < Needed)
+    {
+      RtlFreeUnicodeString(&FamilyNameW);
+      RtlFreeUnicodeString(&StyleNameW);
+      return Needed;
+    }
+
+  XScale = FontGDI->face->size->metrics.x_scale;
+  YScale = FontGDI->face->size->metrics.y_scale;
+
+  IntLockFreeType;
+  pOS2 = FT_Get_Sfnt_Table(FontGDI->face, ft_sfnt_os2);
+  if (NULL == pOS2)
+    {
+      IntUnLockFreeType;
+      DPRINT1("Can't find OS/2 table - not TT font?\n");
+      RtlFreeUnicodeString(&StyleNameW);
+      RtlFreeUnicodeString(&FamilyNameW);
+      return 0;
+    }
+
+  pHori = FT_Get_Sfnt_Table(FontGDI->face, ft_sfnt_hhea);
+  if (NULL == pHori)
+    {
+      IntUnLockFreeType;
+      DPRINT1("Can't find HHEA table - not TT font?\n");
+      RtlFreeUnicodeString(&StyleNameW);
+      RtlFreeUnicodeString(&FamilyNameW);
+      return 0;
+    }
+
+  pPost = FT_Get_Sfnt_Table(FontGDI->face, ft_sfnt_post); /* we can live with this failing */
+
+  Otm->otmSize = Needed;
+
+  FillTM(&Otm->otmTextMetrics, FontGDI->face, pOS2, pHori);
 
   Otm->otmFiller = 0;
   memcpy(&Otm->otmPanoseNumber, pOS2->panose, PANOSE_COUNT);
@@ -2548,7 +2554,7 @@ NtGdiGetTextFace(HDC hDC, INT Count, LPWSTR FaceName)
 BOOL
 STDCALL
 NtGdiGetTextMetrics(HDC hDC,
-                   LPTEXTMETRICW tm)
+                    LPTEXTMETRICW tm)
 {
   PDC dc;
   PTEXTOBJ TextObj;
@@ -2557,6 +2563,7 @@ NtGdiGetTextMetrics(HDC hDC,
   TEXTMETRICW SafeTm;
   FT_Face Face;
   TT_OS2 *pOS2;
+  TT_HoriHeader *pHori;
   ULONG Error;
 
   if (NULL == tm)
@@ -2573,7 +2580,7 @@ NtGdiGetTextMetrics(HDC hDC,
 
   TextObj = TEXTOBJ_LockText(dc->w.hFont);
   if (NULL != TextObj)
-  {
+    {
       FontGDI = ObjToGDI(TextObj->Font, FONT);
 
       Face = FontGDI->face;
@@ -2587,47 +2594,50 @@ NtGdiGetTextMetrics(HDC hDC,
       IntUnLockFreeType;
       if (0 != Error)
        {
-       DPRINT1("Error in setting pixel sizes: %u\n", Error);
-       Status = STATUS_UNSUCCESSFUL;
+          DPRINT1("Error in setting pixel sizes: %u\n", Error);
+          Status = STATUS_UNSUCCESSFUL;
        }
       else
        {
-       memcpy(&SafeTm, &FontGDI->TextMetric, sizeof(TEXTMETRICW));
-        IntLockFreeType;
-        pOS2 = FT_Get_Sfnt_Table(Face, ft_sfnt_os2);
-        IntUnLockFreeType;
-        if (NULL == pOS2)
-          {
-            DPRINT1("Can't find OS/2 table - not TT font?\n");
-            Status = STATUS_UNSUCCESSFUL;
-          }
-        else
-          {
-            SafeTm.tmAveCharWidth = (pOS2->xAvgCharWidth + 32) >> 6;
-          }
-       SafeTm.tmAscent = (Face->size->metrics.ascender + 32) >> 6; // units above baseline
-       SafeTm.tmDescent = (32 - Face->size->metrics.descender) >> 6; // units below baseline
-       SafeTm.tmHeight = SafeTm.tmAscent + SafeTm.tmDescent;
-    SafeTm.tmMaxCharWidth = (Face->size->metrics.max_advance + 32) >> 6;
-    if (FT_IS_SFNT(FontGDI->face))
-    {
-      SafeTm.tmPitchAndFamily |= TMPF_TRUETYPE;
-    }
-       Status = MmCopyToCaller(tm, &SafeTm, sizeof(TEXTMETRICW));
+          memcpy(&SafeTm, &FontGDI->TextMetric, sizeof(TEXTMETRICW));
+
+          Status = STATUS_SUCCESS;
+          IntLockFreeType;
+          pOS2 = FT_Get_Sfnt_Table(FontGDI->face, ft_sfnt_os2);
+          if (NULL == pOS2)
+            {
+              DPRINT1("Can't find OS/2 table - not TT font?\n");
+              Status = STATUS_INTERNAL_ERROR;
+            }
+
+          pHori = FT_Get_Sfnt_Table(FontGDI->face, ft_sfnt_hhea);
+          if (NULL == pHori)
+            {
+              DPRINT1("Can't find HHEA table - not TT font?\n");
+              Status = STATUS_INTERNAL_ERROR;
+            }
+
+          IntUnLockFreeType;
+
+          if (NT_SUCCESS(Status))
+            {
+              FillTM(&SafeTm, FontGDI->face, pOS2, pHori);
+              Status = MmCopyToCaller(tm, &SafeTm, sizeof(TEXTMETRICW));
+            }
        }
-    TEXTOBJ_UnlockText(dc->w.hFont);
-  }
+      TEXTOBJ_UnlockText(dc->w.hFont);
+    }
   else
-  {
-    Status = STATUS_INVALID_HANDLE;
-  }
+    {
+      Status = STATUS_INVALID_HANDLE;
+    }
   DC_UnlockDc(hDC);
 
   if(!NT_SUCCESS(Status))
-  {
-    SetLastNtError(Status);
-    return FALSE;
-  }
+    {
+      SetLastNtError(Status);
+      return FALSE;
+    }
 
   return TRUE;
 }