From 6fccbd1e569ae88b76a66571252bbc4b203272f9 Mon Sep 17 00:00:00 2001 From: "bungeman@google.com" Date: Tue, 24 Jul 2012 16:08:45 +0000 Subject: [PATCH] SkTextBox to use public interfaces for line layout. https://codereview.appspot.com/6438044/ git-svn-id: http://skia.googlecode.com/svn/trunk@4731 2bbb7eff-a529-9590-31e7-b0007b416f81 --- src/views/SkTextBox.cpp | 49 +---------------------------------------- 1 file changed, 1 insertion(+), 48 deletions(-) diff --git a/src/views/SkTextBox.cpp b/src/views/SkTextBox.cpp index 6a88c6ce39..47237a905e 100644 --- a/src/views/SkTextBox.cpp +++ b/src/views/SkTextBox.cpp @@ -1,4 +1,3 @@ - /* * Copyright 2006 The Android Open Source Project * @@ -6,11 +5,8 @@ * found in the LICENSE file. */ - #include "SkTextBox.h" -#include "../core/SkGlyphCache.h" #include "SkUtils.h" -#include "SkAutoKern.h" static inline int is_ws(int c) { @@ -19,50 +15,7 @@ static inline int is_ws(int c) static size_t linebreak(const char text[], const char stop[], const SkPaint& paint, SkScalar margin) { - const char* start = text; - - SkAutoGlyphCache ac(paint, NULL); - SkGlyphCache* cache = ac.getCache(); - SkFixed w = 0; - SkFixed limit = SkScalarToFixed(margin); - SkAutoKern autokern; - - const char* word_start = text; - int prevWS = true; - - while (text < stop) - { - const char* prevText = text; - SkUnichar uni = SkUTF8_NextUnichar(&text); - int currWS = is_ws(uni); - const SkGlyph& glyph = cache->getUnicharMetrics(uni); - - if (!currWS && prevWS) - word_start = prevText; - prevWS = currWS; - - w += autokern.adjust(glyph) + glyph.fAdvanceX; - if (w > limit) - { - if (currWS) // eat the rest of the whitespace - { - while (text < stop && is_ws(SkUTF8_ToUnichar(text))) - text += SkUTF8_CountUTF8Bytes(text); - } - else // backup until a whitespace (or 1 char) - { - if (word_start == start) - { - if (prevText > start) - text = prevText; - } - else - text = word_start; - } - break; - } - } - return text - start; + return paint.breakText(text, stop - text, margin); } int SkTextLineBreaker::CountLines(const char text[], size_t len, const SkPaint& paint, SkScalar width)