@@ -253,110 +253,40 @@ void TextLayout::drawTextRun(SkPaint* paint, const jchar* chars,
253253
254254void TextLayout::getTextRunAdvances (SkPaint* paint, const jchar* chars, jint start,
255255 jint count, jint contextCount, jint dirFlags,
256- jfloat* resultAdvances, jfloat* resultTotalAdvance) {
256+ jfloat* resultAdvances, jfloat& resultTotalAdvance) {
257257 sp<TextLayoutCacheValue> value;
258258#if USE_TEXT_LAYOUT_CACHE
259259 // Return advances from the cache. Compute them if needed
260- value = TextLayoutCache::getInstance ().getValue (paint, chars, contextCount, dirFlags);
260+ value = TextLayoutCache::getInstance ().getValue (
261+ paint, chars, start, count, contextCount, dirFlags);
261262#else
262263 value = new TextLayoutCacheValue ();
263- value->computeValues (paint, chars, contextCount, dirFlags);
264+ value->computeValues (paint, chars, start, count, contextCount, dirFlags);
264265#endif
265266 if (value != NULL ) {
266- if (resultAdvances) {
267- value->getAdvances (start, count, resultAdvances);
268- }
269- if (resultTotalAdvance) {
270- *resultTotalAdvance = value->getTotalAdvance (start, count);
267+ if (resultAdvances != NULL ) {
268+ memcpy (resultAdvances, value->getAdvances (), value->getAdvancesCount () * sizeof (jfloat));
271269 }
270+ resultTotalAdvance = value->getTotalAdvance ();
272271 }
273272}
274273
275274void TextLayout::getTextRunAdvancesHB (SkPaint* paint, const jchar* chars, jint start,
276275 jint count, jint contextCount, jint dirFlags,
277276 jfloat* resultAdvances, jfloat& resultTotalAdvance) {
278277 // Compute advances and return them
279- TextLayoutCacheValue::computeValuesWithHarfbuzz (paint, chars, contextCount,
280- dirFlags, resultAdvances, &resultTotalAdvance, NULL , NULL , NULL );
278+ TextLayoutCacheValue::computeValuesWithHarfbuzz (paint, chars, start, count, contextCount,
279+ dirFlags, resultAdvances, &resultTotalAdvance, NULL , NULL );
281280}
282281
283282void TextLayout::getTextRunAdvancesICU (SkPaint* paint, const jchar* chars, jint start,
284283 jint count, jint contextCount, jint dirFlags,
285284 jfloat* resultAdvances, jfloat& resultTotalAdvance) {
286285 // Compute advances and return them
287- computeAdvancesWithICU (paint, chars, start, count, contextCount, dirFlags,
286+ TextLayoutCacheValue:: computeAdvancesWithICU (paint, chars, start, count, contextCount, dirFlags,
288287 resultAdvances, &resultTotalAdvance);
289288}
290289
291- void TextLayout::computeAdvancesWithICU (SkPaint* paint, const UChar* chars,
292- size_t start, size_t count, size_t contextCount, int dirFlags,
293- jfloat* outAdvances, jfloat* outTotalAdvance) {
294- SkAutoSTMalloc<CHAR_BUFFER_SIZE, jchar> tempBuffer (contextCount);
295- jchar* buffer = tempBuffer.get ();
296- SkScalar* scalarArray = (SkScalar*)outAdvances;
297-
298- // this is where we'd call harfbuzz
299- // for now we just use ushape.c
300- size_t widths;
301- const jchar* text;
302- if (dirFlags & 0x1 ) { // rtl, call arabic shaping in case
303- UErrorCode status = U_ZERO_ERROR;
304- // Use fixed length since we need to keep start and count valid
305- u_shapeArabic (chars, contextCount, buffer, contextCount,
306- U_SHAPE_LENGTH_FIXED_SPACES_NEAR |
307- U_SHAPE_TEXT_DIRECTION_LOGICAL | U_SHAPE_LETTERS_SHAPE |
308- U_SHAPE_X_LAMALEF_SUB_ALTERNATE, &status);
309- // we shouldn't fail unless there's an out of memory condition,
310- // in which case we're hosed anyway
311- for (int i = start, e = i + count; i < e; ++i) {
312- if (buffer[i] == UNICODE_NOT_A_CHAR) {
313- buffer[i] = UNICODE_ZWSP; // zero-width-space for skia
314- }
315- }
316- text = buffer + start;
317- widths = paint->getTextWidths (text, count << 1 , scalarArray);
318- } else {
319- text = chars + start;
320- widths = paint->getTextWidths (text, count << 1 , scalarArray);
321- }
322-
323- jfloat totalAdvance = 0 ;
324- if (widths < count) {
325- #if DEBUG_ADVANCES
326- LOGD (" ICU -- count=%d" , widths);
327- #endif
328- // Skia operates on code points, not code units, so surrogate pairs return only
329- // one value. Expand the result so we have one value per UTF-16 code unit.
330-
331- // Note, skia's getTextWidth gets confused if it encounters a surrogate pair,
332- // leaving the remaining widths zero. Not nice.
333- for (size_t i = 0 , p = 0 ; i < widths; ++i) {
334- totalAdvance += outAdvances[p++] = SkScalarToFloat (scalarArray[i]);
335- if (p < count &&
336- text[p] >= UNICODE_FIRST_LOW_SURROGATE &&
337- text[p] < UNICODE_FIRST_PRIVATE_USE &&
338- text[p-1 ] >= UNICODE_FIRST_HIGH_SURROGATE &&
339- text[p-1 ] < UNICODE_FIRST_LOW_SURROGATE) {
340- outAdvances[p++] = 0 ;
341- }
342- #if DEBUG_ADVANCES
343- LOGD (" icu-adv = %f - total = %f" , outAdvances[i], totalAdvance);
344- #endif
345- }
346- } else {
347- #if DEBUG_ADVANCES
348- LOGD (" ICU -- count=%d" , count);
349- #endif
350- for (size_t i = 0 ; i < count; i++) {
351- totalAdvance += outAdvances[i] = SkScalarToFloat (scalarArray[i]);
352- #if DEBUG_ADVANCES
353- LOGD (" icu-adv = %f - total = %f" , outAdvances[i], totalAdvance);
354- #endif
355- }
356- }
357- *outTotalAdvance = totalAdvance;
358- }
359-
360290// Draws a paragraph of text on a single line, running bidi and shaping
361291void TextLayout::drawText (SkPaint* paint, const jchar* text, jsize len,
362292 int bidiFlags, jfloat x, jfloat y, SkCanvas* canvas) {
0 commit comments