]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/samples/layout/FontMap.cpp
ICU-59117.0.1.tar.gz
[apple/icu.git] / icuSources / samples / layout / FontMap.cpp
index 00e3c4dcc9695296938e4e8893e0b92851821891..1ca98df28eb5f801dd36e08d3d00d3e8b72037d6 100644 (file)
@@ -1,6 +1,10 @@
 /*
  ******************************************************************************
- * Copyright (C) 1998-2003, International Business Machines Corporation and   *
+ * © 2016 and later: Unicode, Inc. and others.                    *
+ * License & terms of use: http://www.unicode.org/copyright.html#License      *
+ ******************************************************************************
+ ******************************************************************************
+ * Copyright (C) 1998-2006, International Business Machines Corporation and   *
  * others. All Rights Reserved.                                               *
  ******************************************************************************
  */
@@ -23,12 +27,15 @@ FontMap::FontMap(const char *fileName, le_int16 pointSize, GUISupport *guiSuppor
     : fPointSize(pointSize), fFontCount(0), fAscent(0), fDescent(0), fLeading(0), fGUISupport(guiSupport)
 {
     le_int32 defaultFont = -1, i, script;
+    le_bool haveFonts = FALSE;
 
+/**/
     for (i = 0; i < scriptCodeCount; i += 1) {
         fFontIndices[i] = -1;
         fFontNames[i] = NULL;
         fFontInstances[i] = NULL;
     }
+ /**/
 
     if (LE_FAILURE(status)) {
         return;
@@ -63,18 +70,17 @@ FontMap::FontMap(const char *fileName, le_int16 pointSize, GUISupport *guiSuppor
 
         if (strcmp(scriptName, "DEFAULT") == 0) {
             defaultFont = getFontIndex(fontName);
+            haveFonts = TRUE;
             continue;
         }
 
-        uscript_getCode(scriptName, &scriptCode, 1, &scriptStatus);
+        le_int32 fillCount = uscript_getCode(scriptName, &scriptCode, 1, &scriptStatus);
 
-        if (U_FAILURE(scriptStatus) || scriptStatus == U_USING_FALLBACK_WARNING ||
-            scriptStatus == U_USING_DEFAULT_WARNING) {
+        if (U_FAILURE(scriptStatus) || fillCount <= 0 ||
+            scriptStatus == U_USING_FALLBACK_WARNING || scriptStatus == U_USING_DEFAULT_WARNING) {
             sprintf(errorMessage, "The script name %s is invalid.", line);
             fGUISupport->postErrorMessage(errorMessage, "Font Map Error");
-            status = LE_ILLEGAL_ARGUMENT_ERROR;
-            fclose(file);
-            return;
+            continue;
         }
 
         script = (le_int32) scriptCode;
@@ -85,6 +91,7 @@ FontMap::FontMap(const char *fileName, le_int16 pointSize, GUISupport *guiSuppor
         }
 
         fFontIndices[script] = getFontIndex(fontName);
+        haveFonts = TRUE;
     }
 
     if (defaultFont >= 0) {
@@ -95,6 +102,12 @@ FontMap::FontMap(const char *fileName, le_int16 pointSize, GUISupport *guiSuppor
         }
     }
 
+    if (! haveFonts) {
+        sprintf(errorMessage, "The font map file %s does not contain any valid scripts.", fileName);
+        fGUISupport->postErrorMessage(errorMessage, "Font Map Error");
+        status = LE_ILLEGAL_ARGUMENT_ERROR;
+    }
+
     fclose(file);
 }