| OLD | NEW | 
|    1 /* |    1 /* | 
|    2  * Copyright 2010 Google Inc. |    2  * Copyright 2010 Google Inc. | 
|    3  * |    3  * | 
|    4  * Use of this source code is governed by a BSD-style license that can be |    4  * Use of this source code is governed by a BSD-style license that can be | 
|    5  * found in the LICENSE file. |    5  * found in the LICENSE file. | 
|    6  */ |    6  */ | 
|    7  |    7  | 
|    8 #include "GrTextContext.h" |    8 #include "GrTextContext.h" | 
|    9 #include "GrContext.h" |    9 #include "GrContext.h" | 
|   10  |   10  | 
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   69             return true; |   69             return true; | 
|   70         } |   70         } | 
|   71         textContext = textContext->fFallbackTextContext; |   71         textContext = textContext->fFallbackTextContext; | 
|   72     } while (textContext); |   72     } while (textContext); | 
|   73  |   73  | 
|   74     return false; |   74     return false; | 
|   75 } |   75 } | 
|   76  |   76  | 
|   77  |   77  | 
|   78 //*** change to output positions? |   78 //*** change to output positions? | 
|   79 void GrTextContext::MeasureText(SkGlyphCache* cache, SkDrawCacheProc glyphCacheP
     roc, |   79 int GrTextContext::MeasureText(SkGlyphCache* cache, SkDrawCacheProc glyphCachePr
     oc, | 
|   80                                 const char text[], size_t byteLength, SkVector* 
     stopVector) { |   80                                 const char text[], size_t byteLength, SkVector* 
     stopVector) { | 
|   81     SkFixed     x = 0, y = 0; |   81     SkFixed     x = 0, y = 0; | 
|   82     const char* stop = text + byteLength; |   82     const char* stop = text + byteLength; | 
|   83  |   83  | 
|   84     SkAutoKern  autokern; |   84     SkAutoKern  autokern; | 
|   85  |   85  | 
 |   86     int numGlyphs = 0; | 
|   86     while (text < stop) { |   87     while (text < stop) { | 
|   87         // don't need x, y here, since all subpixel variants will have the |   88         // don't need x, y here, since all subpixel variants will have the | 
|   88         // same advance |   89         // same advance | 
|   89         const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); |   90         const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); | 
|   90  |   91  | 
|   91         x += autokern.adjust(glyph) + glyph.fAdvanceX; |   92         x += autokern.adjust(glyph) + glyph.fAdvanceX; | 
|   92         y += glyph.fAdvanceY; |   93         y += glyph.fAdvanceY; | 
 |   94         ++numGlyphs; | 
|   93     } |   95     } | 
|   94     stopVector->set(SkFixedToScalar(x), SkFixedToScalar(y)); |   96     stopVector->set(SkFixedToScalar(x), SkFixedToScalar(y)); | 
|   95  |   97  | 
|   96     SkASSERT(text == stop); |   98     SkASSERT(text == stop); | 
 |   99      | 
 |  100     return numGlyphs; | 
|   97 } |  101 } | 
|   98  |  102  | 
|   99 static void GlyphCacheAuxProc(void* data) { |  103 static void GlyphCacheAuxProc(void* data) { | 
|  100     GrFontScaler* scaler = (GrFontScaler*)data; |  104     GrFontScaler* scaler = (GrFontScaler*)data; | 
|  101     SkSafeUnref(scaler); |  105     SkSafeUnref(scaler); | 
|  102 } |  106 } | 
|  103  |  107  | 
|  104 GrFontScaler* GrTextContext::GetGrFontScaler(SkGlyphCache* cache) { |  108 GrFontScaler* GrTextContext::GetGrFontScaler(SkGlyphCache* cache) { | 
|  105     void* auxData; |  109     void* auxData; | 
|  106     GrFontScaler* scaler = NULL; |  110     GrFontScaler* scaler = NULL; | 
|  107  |  111  | 
|  108     if (cache->getAuxProcData(GlyphCacheAuxProc, &auxData)) { |  112     if (cache->getAuxProcData(GlyphCacheAuxProc, &auxData)) { | 
|  109         scaler = (GrFontScaler*)auxData; |  113         scaler = (GrFontScaler*)auxData; | 
|  110     } |  114     } | 
|  111     if (NULL == scaler) { |  115     if (NULL == scaler) { | 
|  112         scaler = SkNEW_ARGS(GrFontScaler, (cache)); |  116         scaler = SkNEW_ARGS(GrFontScaler, (cache)); | 
|  113         cache->setAuxProc(GlyphCacheAuxProc, scaler); |  117         cache->setAuxProc(GlyphCacheAuxProc, scaler); | 
|  114     } |  118     } | 
|  115  |  119  | 
|  116     return scaler; |  120     return scaler; | 
|  117 } |  121 } | 
| OLD | NEW |