Beispiel #1
0
int main(int argc, char * argv[]) {
    int i;
    const void * error;

    for (i = 0; i < numtests8; ++i)
    {
        int res = gr_count_unicode_characters(gr_utf8, tests8[i].str, tests8[i].str + sizeof(tests8[i].str), &error);
        if (tests8[i].error >= 0)
        {
        	if (!error)
        	{
				fprintf(stderr, "%s: test 8:%d failed: expected error condition did not occur\n", argv[0], i + 1);
				return (i+1);
        	}
        	else if (ptrdiff_t(error) - ptrdiff_t(tests8[i].str) != tests8[i].error)
            {
        		fprintf(stderr, "%s: test 8:%d failed: error at codepoint %d expected at codepoint %d\n", argv[0], i + 1, int(ptrdiff_t(error) - ptrdiff_t(tests8[i].str)), tests8[i].error);
                return (i+1);
            }
        }
        else if (error)
		{
			fprintf(stderr, "%s: test 8:%d failed: unexpected error occured at codepoint %d\n", argv[0], i + 1, int(ptrdiff_t(error) - ptrdiff_t(tests8[i].str)));
			return (i+1);
		}
        if (res != tests8[i].len)
        {
            fprintf(stderr, "%s: test 8:%d failed: character count failure %d != %d\n", argv[0], i + 1, res, tests8[i].len);
            return (i+1);
        }
    }

    for (i = 0; i < numtests16; ++i)
    {
        int res = gr_count_unicode_characters(gr_utf16, tests16[i].str, tests16[i].str + sizeof(tests16[i].str), &error);
        if (tests16[i].error >= 0)
        {
        	if (!error)
        	{
				fprintf(stderr, "%s: test 16:%d failed: expected error condition did not occur\n", argv[0], i + 1);
				return (i+1);
        	}
        	else if (ptrdiff_t(error) - ptrdiff_t(tests16[i].str) != tests16[i].error)
            {
        		fprintf(stderr, "%s: test 16:%d failed: error at codepoint %d expected at codepoint %d\n", argv[0], i + 1, int(ptrdiff_t(error) - ptrdiff_t(tests16[i].str)), tests16[i].error);
                return (i+1);
            }
        }
        else if (error)
		{
			fprintf(stderr, "%s: test 16:%d failed: unexpected error occured at codepoint %d\n", argv[0], i + 1, int(ptrdiff_t(error) - ptrdiff_t(tests16[i].str)));
			return (i+1);
		}
        if (res != tests16[i].len)
        {
            fprintf(stderr, "%s: test 16:%d failed: character count failure %d != %d\n", argv[0], i + 1, res, tests16[i].len);
            return (i+1);
        }
    }
    return 0;
}
Beispiel #2
0
jfloat GraphiteLayoutShaper::shapeScriptRun(const SkPaint* paint, const UChar* chars,
        size_t count, bool isRTL, Vector<jfloat>* const outAdvances,
        Vector<jchar>* const outGlyphs, Vector<jfloat>* const outPos,
        jfloat startXPosition, uint32_t startScriptRun, size_t glyphBaseCount) {
    ALOGD("Shape Scrit Run with Graphite");
    SkTypeface *typeface = paint->getTypeface();
    mShapingGrFace = getCachedGrFace(typeface);

    unsigned int x_ppem;
    unsigned int y_ppem;
    int x_scale;
    int y_scale;
    getConversionFactor(x_ppem, y_ppem, x_scale, y_scale, paint);

    mShapingGrFont = gr_make_font_with_ops(x_ppem, paint, &GraphiteFontOps, mShapingGrFace);

    const uint16_t *charsScriptStart = chars ;
    const uint16_t *charsScriptEnd = chars + count;

    size_t numCP;
    char *pError;

    numCP = gr_count_unicode_characters(gr_utf16, charsScriptStart, charsScriptEnd, (const void **)(&pError));

#if DEBUG_GLYPHS
    ALOGD("Myanmar shape with Graphite, numCP = %d, grFont = %p, grFace = %p, pError = %p",
            numCP, mShapingGrFont, mShapingGrFace, pError);
#endif

    if(!mShapingGrFont || !mShapingGrFace || pError) {
        ALOGD("Invalid grFont is NULL, grFace is NULL or parse string error.");
        return 0.0;
    }

    mShapingSegment = gr_make_seg(mShapingGrFont, mShapingGrFace, 0, 0,
            gr_utf16, charsScriptStart, numCP, isRTL);
    cluster_t *clusters = getCluster(mShapingSegment, numCP);

#if DEBUG_GLYPHS
        ALOGD("Got from Graphite");
#endif

    const gr_slot *slot;
    size_t glyphIndex, clusterIndex = 0;
    jfloat totalFontRunAdvance = 0;
    for (slot = gr_seg_first_slot(mShapingSegment), glyphIndex = 0; slot;
            slot = gr_slot_next_in_segment(slot), ++ glyphIndex) {
#if DEBUG_GLYPHS
        ALOGD("         -- Glyph = %d, origin = (%f, %f), advance = (%f, %f)\n",
                gr_slot_gid(slot), gr_slot_origin_X(slot),
                gr_slot_origin_Y(slot),
                gr_slot_advance_X(slot, mShapingGrFace, mShapingGrFont),
                gr_slot_advance_Y(slot, mShapingGrFace, mShapingGrFont));
#endif
        if(glyphIndex == clusters[clusterIndex].base_glyph + clusters[clusterIndex].num_glyphs) {
            uint32_t clusterStart = clusters[clusterIndex].base_char + startScriptRun;
            jfloat startOrigin = outAdvances->itemAt(clusterStart);
            jfloat advance = gr_slot_origin_X(slot) - startOrigin;
            outAdvances->replaceAt(advance, clusterStart);

            ++ clusterIndex;
            clusterStart = clusters[clusterIndex].base_char + startScriptRun;
            outAdvances->replaceAt(gr_slot_origin_X(slot), clusterStart);
        }

        jfloat charRight = gr_slot_origin_X(slot) + gr_slot_advance_X(slot, mShapingGrFace, mShapingGrFont);
        if (charRight > totalFontRunAdvance) {
            totalFontRunAdvance = charRight;
        }

        jchar glyph = glyphBaseCount + gr_slot_gid(slot);
        outGlyphs->add(glyph);

        outPos->add(startXPosition + gr_slot_origin_X(slot));
        outPos->add(gr_slot_origin_Y(slot));
    }

    uint32_t clusterStart = clusters[clusterIndex].base_char + startScriptRun;
    jfloat startOrigin = outAdvances->itemAt(clusterStart);
    jfloat advance = totalFontRunAdvance - startOrigin;
    outAdvances->replaceAt(advance, clusterStart);

    if(mShapingSegment) {
        gr_seg_destroy(mShapingSegment);
        mShapingSegment = NULL;
    }

    if(mShapingGrFont) {
        gr_font_destroy(mShapingGrFont);
        mShapingGrFont = NULL;
    }
#if DEBUG_GLYPHS
    ALOGD("         -- totalFontRunAdvance = %f", totalFontRunAdvance);
#endif
    return totalFontRunAdvance;
}