Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(91)

Side by Side Diff: src/gpu/text/GrTextUtils.cpp

Issue 1737693006: Change type of SkGlyph::fAdvance[XY] to float. (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: Should be float, not SkScalar. Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/gpu/text/GrStencilAndCoverTextContext.cpp ('k') | src/pdf/SkPDFDevice.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright 2015 Google Inc. 2 * Copyright 2015 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 "GrTextUtils.h" 8 #include "GrTextUtils.h"
9 9
10 #include "GrAtlasTextBlob.h" 10 #include "GrAtlasTextBlob.h"
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 260
261 SkPaint::GlyphCacheProc glyphCacheProc = skPaint.getGlyphCacheProc(true); 261 SkPaint::GlyphCacheProc glyphCacheProc = skPaint.getGlyphCacheProc(true);
262 SkAutoDescriptor desc; 262 SkAutoDescriptor desc;
263 skPaint.getScalerContextDescriptor(&desc, props, SkPaint::FakeGamma::Off, nu llptr); 263 skPaint.getScalerContextDescriptor(&desc, props, SkPaint::FakeGamma::Off, nu llptr);
264 SkGlyphCache* origPaintCache = SkGlyphCache::DetachCache(skPaint.getTypeface (), 264 SkGlyphCache* origPaintCache = SkGlyphCache::DetachCache(skPaint.getTypeface (),
265 desc.getDesc()); 265 desc.getDesc());
266 266
267 SkTArray<SkScalar> positions; 267 SkTArray<SkScalar> positions;
268 268
269 const char* textPtr = text; 269 const char* textPtr = text;
270 SkFixed stopX = 0; 270 SkScalar stopX = 0;
271 SkFixed stopY = 0; 271 SkScalar stopY = 0;
272 SkFixed origin = 0; 272 SkScalar origin = 0;
273 switch (skPaint.getTextAlign()) { 273 switch (skPaint.getTextAlign()) {
274 case SkPaint::kRight_Align: origin = SK_Fixed1; break; 274 case SkPaint::kRight_Align: origin = SK_Scalar1; break;
275 case SkPaint::kCenter_Align: origin = SK_FixedHalf; break; 275 case SkPaint::kCenter_Align: origin = SK_ScalarHalf; break;
276 case SkPaint::kLeft_Align: origin = 0; break; 276 case SkPaint::kLeft_Align: origin = 0; break;
277 } 277 }
278 278
279 SkAutoKern autokern; 279 SkAutoKern autokern;
280 const char* stop = text + byteLength; 280 const char* stop = text + byteLength;
281 while (textPtr < stop) { 281 while (textPtr < stop) {
282 // don't need x, y here, since all subpixel variants will have the 282 // don't need x, y here, since all subpixel variants will have the
283 // same advance 283 // same advance
284 const SkGlyph& glyph = glyphCacheProc(origPaintCache, &textPtr); 284 const SkGlyph& glyph = glyphCacheProc(origPaintCache, &textPtr);
285 285
286 SkFixed width = glyph.fAdvanceX + autokern.adjust(glyph); 286 SkScalar width = SkFloatToScalar(glyph.fAdvanceX) + autokern.adjust(glyp h);
287 positions.push_back(SkFixedToScalar(stopX + SkFixedMul(origin, width))); 287 positions.push_back(stopX + origin * width);
288 288
289 SkFixed height = glyph.fAdvanceY; 289 SkScalar height = SkFloatToScalar(glyph.fAdvanceY);
290 positions.push_back(SkFixedToScalar(stopY + SkFixedMul(origin, height))) ; 290 positions.push_back(stopY + origin * height);
291 291
292 stopX += width; 292 stopX += width;
293 stopY += height; 293 stopY += height;
294 } 294 }
295 SkASSERT(textPtr == stop); 295 SkASSERT(textPtr == stop);
296 296
297 SkGlyphCache::AttachCache(origPaintCache); 297 SkGlyphCache::AttachCache(origPaintCache);
298 298
299 // now adjust starting point depending on alignment 299 // now adjust starting point depending on alignment
300 SkScalar alignX = SkFixedToScalar(stopX); 300 SkScalar alignX = stopX;
301 SkScalar alignY = SkFixedToScalar(stopY); 301 SkScalar alignY = stopY;
302 if (skPaint.getTextAlign() == SkPaint::kCenter_Align) { 302 if (skPaint.getTextAlign() == SkPaint::kCenter_Align) {
303 alignX = SkScalarHalf(alignX); 303 alignX = SkScalarHalf(alignX);
304 alignY = SkScalarHalf(alignY); 304 alignY = SkScalarHalf(alignY);
305 } else if (skPaint.getTextAlign() == SkPaint::kLeft_Align) { 305 } else if (skPaint.getTextAlign() == SkPaint::kLeft_Align) {
306 alignX = 0; 306 alignX = 0;
307 alignY = 0; 307 alignY = 0;
308 } 308 }
309 x -= alignX; 309 x -= alignX;
310 y -= alignY; 310 y -= alignY;
311 SkPoint offset = SkPoint::Make(x, y); 311 SkPoint offset = SkPoint::Make(x, y);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 : S K_Scalar1; 380 : S K_Scalar1;
381 while (text < stop) { 381 while (text < stop) {
382 const char* lastText = text; 382 const char* lastText = text;
383 // the last 2 parameters are ignored 383 // the last 2 parameters are ignored
384 const SkGlyph& glyph = glyphCacheProc(cache, &text); 384 const SkGlyph& glyph = glyphCacheProc(cache, &text);
385 385
386 if (glyph.fWidth) { 386 if (glyph.fWidth) {
387 SkScalar x = offset.x() + pos[0]; 387 SkScalar x = offset.x() + pos[0];
388 SkScalar y = offset.y() + (2 == scalarsPerPosition ? pos[1] : 0) ; 388 SkScalar y = offset.y() + (2 == scalarsPerPosition ? pos[1] : 0) ;
389 389
390 SkScalar advanceX = SkFixedToScalar(glyph.fAdvanceX) * alignMul * textRatio; 390 SkScalar advanceX = SkFloatToScalar(glyph.fAdvanceX) * alignMul * textRatio;
391 SkScalar advanceY = SkFixedToScalar(glyph.fAdvanceY) * alignMul * textRatio; 391 SkScalar advanceY = SkFloatToScalar(glyph.fAdvanceY) * alignMul * textRatio;
392 392
393 if (!DfAppendGlyph(blob, 393 if (!DfAppendGlyph(blob,
394 runIndex, 394 runIndex,
395 fontCache, 395 fontCache,
396 &currStrike, 396 &currStrike,
397 glyph, 397 glyph,
398 x - advanceX, y - advanceY, color, 398 x - advanceX, y - advanceY, color,
399 fontScaler, 399 fontScaler,
400 textRatio, 400 textRatio,
401 viewMatrix)) { 401 viewMatrix)) {
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
575 if (cache->getAuxProcData(glyph_cache_aux_proc, &auxData)) { 575 if (cache->getAuxProcData(glyph_cache_aux_proc, &auxData)) {
576 scaler = (GrFontScaler*)auxData; 576 scaler = (GrFontScaler*)auxData;
577 } 577 }
578 if (nullptr == scaler) { 578 if (nullptr == scaler) {
579 scaler = new GrFontScaler(cache); 579 scaler = new GrFontScaler(cache);
580 cache->setAuxProc(glyph_cache_aux_proc, scaler); 580 cache->setAuxProc(glyph_cache_aux_proc, scaler);
581 } 581 }
582 582
583 return scaler; 583 return scaler;
584 } 584 }
OLDNEW
« no previous file with comments | « src/gpu/text/GrStencilAndCoverTextContext.cpp ('k') | src/pdf/SkPDFDevice.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698