]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/samples/layout/GDIFontInstance.cpp
ICU-551.51.4.tar.gz
[apple/icu.git] / icuSources / samples / layout / GDIFontInstance.cpp
index d3451e9a575bede0b3385f413b8113d791dd37b4..5e94e5d2ffbd2d2522a33caae9b08ba583bf9b0d 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *******************************************************************************
  *
- *   Copyright (C) 1999-2006, International Business Machines
+ *   Copyright (C) 1999-2008, International Business Machines
  *   Corporation and others.  All Rights Reserved.
  *
  *******************************************************************************
@@ -250,15 +250,39 @@ GDIFontInstance::GDIFontInstance(GDISurface *surface, const char *faceName, le_i
 
     UINT ret = GetOutlineTextMetrics(hdc, sizeof otm, &otm);
 
-    if (ret == 0) {
-        status = LE_MISSING_FONT_TABLE_ERROR;
-        goto restore;
-    }
+    if (ret != 0) {
+        fUnitsPerEM = otm.otmEMSquare;
+        fAscent  = otm.otmTextMetrics.tmAscent;
+        fDescent = otm.otmTextMetrics.tmDescent;
+        fLeading = otm.otmTextMetrics.tmExternalLeading;
+    } else {
+        const HEADTable *headTable = NULL;
+        const HHEATable *hheaTable = NULL;
+
+        // read unitsPerEm from 'head' table
+        headTable = (const HEADTable *) readFontTable(LE_HEAD_TABLE_TAG);
+
+        if (headTable == NULL) {
+            status = LE_MISSING_FONT_TABLE_ERROR;
+            goto restore;
+        }
 
-    fUnitsPerEM = otm.otmEMSquare;
-    fAscent  = otm.otmTextMetrics.tmAscent;
-    fDescent = otm.otmTextMetrics.tmDescent;
-    fLeading = otm.otmTextMetrics.tmExternalLeading;
+        fUnitsPerEM   = SWAPW(headTable->unitsPerEm);
+        freeFontTable((const void *)headTable);
+
+        hheaTable = (HHEATable *) readFontTable(LE_HHEA_TABLE_TAG);
+
+        if (hheaTable == NULL) {
+            status = LE_MISSING_FONT_TABLE_ERROR;
+            goto restore;
+        }
+
+        fAscent  = (le_int32) yUnitsToPoints((float) SWAPW(hheaTable->ascent));
+        fDescent = (le_int32) yUnitsToPoints((float) SWAPW(hheaTable->descent));
+        fLeading = (le_int32) yUnitsToPoints((float) SWAPW(hheaTable->lineGap));
+
+        freeFontTable((const void *) hheaTable);
+    }
 
     status = initMapper();