Bug 1719544 - part 2 - Convert gfxHarfBuzzShaper normalization callbacks from direct ICU access to mozilla::intl::String APIs. r=platform-i18n-reviewers,dminor

Depends on D126259

Differential Revision: https://phabricator.services.mozilla.com/D126260
This commit is contained in:
Jonathan Kew 2021-09-22 18:48:53 +00:00
Родитель 2cfc8b9513
Коммит 71ac7ba474
1 изменённых файлов: 13 добавлений и 44 удалений

Просмотреть файл

@ -10,17 +10,13 @@
#include "gfxFontUtils.h"
#include "gfxTextRun.h"
#include "mozilla/Sprintf.h"
#include "mozilla/intl/String.h"
#include "nsUnicodeProperties.h"
#include "nsUnicodeScriptCodes.h"
#include "harfbuzz/hb.h"
#include "harfbuzz/hb-ot.h"
#include "unicode/unorm.h"
#include "unicode/utext.h"
static const UNormalizer2* sNormalizer = nullptr;
#include <algorithm>
#define FloatToFixed(f) (65536 * (f))
@ -1038,12 +1034,10 @@ static const char16_t sDageshForms[0x05EA - 0x05D0 + 1] = {
static hb_bool_t HBUnicodeCompose(hb_unicode_funcs_t* ufuncs, hb_codepoint_t a,
hb_codepoint_t b, hb_codepoint_t* ab,
void* user_data) {
if (sNormalizer) {
UChar32 ch = unorm2_composePair(sNormalizer, a, b);
if (ch >= 0) {
*ab = ch;
return true;
}
char32_t ch = mozilla::intl::String::ComposePairNFC(a, b);
if (ch > 0) {
*ab = ch;
return true;
}
return false;
@ -1062,37 +1056,16 @@ static hb_bool_t HBUnicodeDecompose(hb_unicode_funcs_t* ufuncs,
}
#endif
if (!sNormalizer) {
return false;
char32_t decomp[2] = {0};
if (mozilla::intl::String::DecomposeRawNFD(ab, decomp)) {
if (decomp[1] || decomp[0] != ab) {
*a = decomp[0];
*b = decomp[1];
return true;
}
}
// Canonical decompositions are never more than two characters,
// or a maximum of 4 utf-16 code units.
const unsigned MAX_DECOMP_LENGTH = 4;
UErrorCode error = U_ZERO_ERROR;
UChar decomp[MAX_DECOMP_LENGTH];
int32_t len = unorm2_getRawDecomposition(sNormalizer, ab, decomp,
MAX_DECOMP_LENGTH, &error);
if (U_FAILURE(error) || len < 0) {
return false;
}
UText text = UTEXT_INITIALIZER;
utext_openUChars(&text, decomp, len, &error);
NS_ASSERTION(U_SUCCESS(error), "UText failure?");
UChar32 ch = UTEXT_NEXT32(&text);
if (ch != U_SENTINEL) {
*a = ch;
}
ch = UTEXT_NEXT32(&text);
if (ch != U_SENTINEL) {
*b = ch;
}
utext_close(&text);
return *b != 0 || *a != ab;
return false;
}
static void AddOpenTypeFeature(const uint32_t& aTag, uint32_t& aValue,
@ -1164,10 +1137,6 @@ bool gfxHarfBuzzShaper::Initialize() {
hb_unicode_funcs_set_decompose_func(sHBUnicodeFuncs, HBUnicodeDecompose,
nullptr, nullptr);
hb_unicode_funcs_make_immutable(sHBUnicodeFuncs);
UErrorCode error = U_ZERO_ERROR;
sNormalizer = unorm2_getNFCInstance(&error);
MOZ_ASSERT(U_SUCCESS(error), "failed to get ICU normalizer");
}
gfxFontEntry* entry = mFont->GetFontEntry();