X-Git-Url: https://git.saurik.com/apple/icu.git/blobdiff_plain/b75a7d8f3b4adbae880cab104ce2c6a50eee4db2..f3c0d7a59d99c2a94c6b8822291f0e42be3773c9:/icuSources/samples/layout/FontMap.cpp diff --git a/icuSources/samples/layout/FontMap.cpp b/icuSources/samples/layout/FontMap.cpp index 00e3c4dc..1ca98df2 100644 --- a/icuSources/samples/layout/FontMap.cpp +++ b/icuSources/samples/layout/FontMap.cpp @@ -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); }