Exemple #1
0
void TestHasScript() {
    if(!(
        !uscript_hasScript(0x063f, USCRIPT_COMMON) &&
        uscript_hasScript(0x063f, USCRIPT_ARABIC) &&  /* main Script value */
        !uscript_hasScript(0x063f, USCRIPT_SYRIAC) &&
        !uscript_hasScript(0x063f, USCRIPT_THAANA))
    ) {
        log_err("uscript_hasScript(U+063F, ...) is wrong\n");
    }
    if(!(
        !uscript_hasScript(0x0640, USCRIPT_COMMON) &&  /* main Script value */
        uscript_hasScript(0x0640, USCRIPT_ARABIC) &&
        uscript_hasScript(0x0640, USCRIPT_SYRIAC) &&
        !uscript_hasScript(0x0640, USCRIPT_THAANA))
    ) {
        log_err("uscript_hasScript(U+0640, ...) is wrong\n");
    }
    if(!(
        !uscript_hasScript(0x0650, USCRIPT_INHERITED) &&  /* main Script value */
        uscript_hasScript(0x0650, USCRIPT_ARABIC) &&
        uscript_hasScript(0x0650, USCRIPT_SYRIAC) &&
        !uscript_hasScript(0x0650, USCRIPT_THAANA))
    ) {
        log_err("uscript_hasScript(U+0650, ...) is wrong\n");
    }
    if(!(
        !uscript_hasScript(0x0660, USCRIPT_COMMON) &&  /* main Script value */
        uscript_hasScript(0x0660, USCRIPT_ARABIC) &&
        !uscript_hasScript(0x0660, USCRIPT_SYRIAC) &&
        uscript_hasScript(0x0660, USCRIPT_THAANA))
    ) {
        log_err("uscript_hasScript(U+0660, ...) is wrong\n");
    }
    if(!(
        !uscript_hasScript(0xfdf2, USCRIPT_COMMON) &&
        uscript_hasScript(0xfdf2, USCRIPT_ARABIC) &&  /* main Script value */
        !uscript_hasScript(0xfdf2, USCRIPT_SYRIAC) &&
        uscript_hasScript(0xfdf2, USCRIPT_THAANA))
    ) {
        log_err("uscript_hasScript(U+FDF2, ...) is wrong\n");
    }
    if(uscript_hasScript(0x0640, 0xaffe)) {
        /* An unguarded implementation might go into an infinite loop. */
        log_err("uscript_hasScript(U+0640, bogus 0xaffe) is wrong\n");
    }
}
Exemple #2
0
static UBool scriptExtensionsFilter(UChar32 ch, void* context) {
    return uscript_hasScript(ch, *(UScriptCode*)context);
}
Exemple #3
0
bool HarfBuzzShaper::collectHarfBuzzRuns()
{
    const UChar* normalizedBufferEnd = m_normalizedBuffer.get() + m_normalizedBufferLength;
    SurrogatePairAwareTextIterator iterator(m_normalizedBuffer.get(), 0, m_normalizedBufferLength, m_normalizedBufferLength);
    UChar32 character;
    unsigned clusterLength = 0;
    unsigned startIndexOfCurrentRun = 0;
    if (!iterator.consume(character, clusterLength))
        return false;

    const SimpleFontData* nextFontData = m_font->glyphDataForCharacter(character, false).fontData;
    UErrorCode errorCode = U_ZERO_ERROR;
    UScriptCode nextScript = uscript_getScript(character, &errorCode);
    if (U_FAILURE(errorCode))
        return false;

    do {
        const UChar* currentCharacterPosition = iterator.characters();
        const SimpleFontData* currentFontData = nextFontData;
        UScriptCode currentScript = nextScript;

        for (iterator.advance(clusterLength); iterator.consume(character, clusterLength); iterator.advance(clusterLength)) {
            if (Font::treatAsZeroWidthSpace(character))
                continue;

            if (U_GET_GC_MASK(character) & U_GC_M_MASK) {
                int markLength = clusterLength;
                const UChar* markCharactersEnd = iterator.characters() + clusterLength;
                while (markCharactersEnd < normalizedBufferEnd) {
                    UChar32 nextCharacter;
                    int nextCharacterLength = 0;
                    U16_NEXT(markCharactersEnd, nextCharacterLength, normalizedBufferEnd - markCharactersEnd, nextCharacter);
                    if (!(U_GET_GC_MASK(nextCharacter) & U_GC_M_MASK))
                        break;
                    markLength += nextCharacterLength;
                    markCharactersEnd += nextCharacterLength;
                }

                if (currentFontData->canRenderCombiningCharacterSequence(currentCharacterPosition, markCharactersEnd - currentCharacterPosition)) {
                    clusterLength = markLength;
                    continue;
                }
                nextFontData = m_font->glyphDataForCharacter(character, false).fontData;
            } else
                nextFontData = m_font->glyphDataForCharacter(character, false).fontData;

            nextScript = uscript_getScript(character, &errorCode);
            if (U_FAILURE(errorCode))
                return false;
            if ((nextFontData != currentFontData) || ((currentScript != nextScript) && (nextScript != USCRIPT_INHERITED) && (!uscript_hasScript(character, currentScript))))
                break;
            if (nextScript == USCRIPT_INHERITED)
                nextScript = currentScript;
            currentCharacterPosition = iterator.characters();
        }
        unsigned numCharactersOfCurrentRun = iterator.currentCharacter() - startIndexOfCurrentRun;
        hb_script_t script = hb_icu_script_to_script(currentScript);
        m_harfBuzzRuns.append(HarfBuzzRun::create(currentFontData, startIndexOfCurrentRun, numCharactersOfCurrentRun, m_run.direction(), script));
        currentFontData = nextFontData;
        startIndexOfCurrentRun = iterator.currentCharacter();
    } while (iterator.consume(character, clusterLength));

    return !m_harfBuzzRuns.isEmpty();
}