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

Side by Side Diff: src/core/SkDraw.cpp

Issue 605533002: Fix SkTextBlob offset semantics. (Closed) Base URL: https://chromium.googlesource.com/skia.git@master
Patch Set: default run positioning fix Created 6 years, 3 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/core/SkDevice.cpp ('k') | src/core/SkTextMapStateProc.h » ('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 2006 The Android Open Source Project 2 * Copyright 2006 The Android Open Source Project
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 "SkDraw.h" 8 #include "SkDraw.h"
9 #include "SkBlitter.h" 9 #include "SkBlitter.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 1637 matching lines...) Expand 10 before | Expand all | Expand 10 after
1648 } 1648 }
1649 1649
1650 fx += glyph.fAdvanceX; 1650 fx += glyph.fAdvanceX;
1651 fy += glyph.fAdvanceY; 1651 fy += glyph.fAdvanceY;
1652 } 1652 }
1653 } 1653 }
1654 1654
1655 ////////////////////////////////////////////////////////////////////////////// 1655 //////////////////////////////////////////////////////////////////////////////
1656 1656
1657 void SkDraw::drawPosText_asPaths(const char text[], size_t byteLength, 1657 void SkDraw::drawPosText_asPaths(const char text[], size_t byteLength,
1658 const SkScalar pos[], SkScalar constY, 1658 const SkScalar pos[], int scalarsPerPosition,
1659 int scalarsPerPosition, 1659 const SkPoint& offset, const SkPaint& origPaint ) const {
1660 const SkPaint& origPaint) const {
1661 // setup our std paint, in hopes of getting hits in the cache 1660 // setup our std paint, in hopes of getting hits in the cache
1662 SkPaint paint(origPaint); 1661 SkPaint paint(origPaint);
1663 SkScalar matrixScale = paint.setupForAsPaths(); 1662 SkScalar matrixScale = paint.setupForAsPaths();
1664 1663
1665 SkMatrix matrix; 1664 SkMatrix matrix;
1666 matrix.setScale(matrixScale, matrixScale); 1665 matrix.setScale(matrixScale, matrixScale);
1667 1666
1668 // Temporarily jam in kFill, so we only ever ask for the raw outline from th e cache. 1667 // Temporarily jam in kFill, so we only ever ask for the raw outline from th e cache.
1669 paint.setStyle(SkPaint::kFill_Style); 1668 paint.setStyle(SkPaint::kFill_Style);
1670 paint.setPathEffect(NULL); 1669 paint.setPathEffect(NULL);
1671 1670
1672 SkDrawCacheProc glyphCacheProc = paint.getDrawCacheProc(); 1671 SkDrawCacheProc glyphCacheProc = paint.getDrawCacheProc();
1673 SkAutoGlyphCache autoCache(paint, NULL, NULL); 1672 SkAutoGlyphCache autoCache(paint, NULL, NULL);
1674 SkGlyphCache* cache = autoCache.getCache(); 1673 SkGlyphCache* cache = autoCache.getCache();
1675 1674
1676 const char* stop = text + byteLength; 1675 const char* stop = text + byteLength;
1677 SkTextAlignProcScalar alignProc(paint.getTextAlign()); 1676 SkTextAlignProcScalar alignProc(paint.getTextAlign());
1678 SkTextMapStateProc tmsProc(SkMatrix::I(), constY, scalarsPerPosition); 1677 SkTextMapStateProc tmsProc(SkMatrix::I(), offset, scalarsPerPosition);
1679 1678
1680 // Now restore the original settings, so we "draw" with whatever style/strok ing. 1679 // Now restore the original settings, so we "draw" with whatever style/strok ing.
1681 paint.setStyle(origPaint.getStyle()); 1680 paint.setStyle(origPaint.getStyle());
1682 paint.setPathEffect(origPaint.getPathEffect()); 1681 paint.setPathEffect(origPaint.getPathEffect());
1683 1682
1684 while (text < stop) { 1683 while (text < stop) {
1685 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); 1684 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0);
1686 if (glyph.fWidth) { 1685 if (glyph.fWidth) {
1687 const SkPath* path = cache->findPath(glyph); 1686 const SkPath* path = cache->findPath(glyph);
1688 if (path) { 1687 if (path) {
1689 SkPoint tmsLoc; 1688 SkPoint tmsLoc;
1690 tmsProc(pos, &tmsLoc); 1689 tmsProc(pos, &tmsLoc);
1691 SkPoint loc; 1690 SkPoint loc;
1692 alignProc(tmsLoc, glyph, &loc); 1691 alignProc(tmsLoc, glyph, &loc);
1693 1692
1694 matrix[SkMatrix::kMTransX] = loc.fX; 1693 matrix[SkMatrix::kMTransX] = loc.fX;
1695 matrix[SkMatrix::kMTransY] = loc.fY; 1694 matrix[SkMatrix::kMTransY] = loc.fY;
1696 if (fDevice) { 1695 if (fDevice) {
1697 fDevice->drawPath(*this, *path, paint, &matrix, false); 1696 fDevice->drawPath(*this, *path, paint, &matrix, false);
1698 } else { 1697 } else {
1699 this->drawPath(*path, paint, &matrix, false); 1698 this->drawPath(*path, paint, &matrix, false);
1700 } 1699 }
1701 } 1700 }
1702 } 1701 }
1703 pos += scalarsPerPosition; 1702 pos += scalarsPerPosition;
1704 } 1703 }
1705 } 1704 }
1706 1705
1707 void SkDraw::drawPosText(const char text[], size_t byteLength, 1706 void SkDraw::drawPosText(const char text[], size_t byteLength,
1708 const SkScalar pos[], SkScalar constY, 1707 const SkScalar pos[], int scalarsPerPosition,
1709 int scalarsPerPosition, const SkPaint& paint) const { 1708 const SkPoint& offset, const SkPaint& paint) const {
1710 SkASSERT(byteLength == 0 || text != NULL); 1709 SkASSERT(byteLength == 0 || text != NULL);
1711 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition); 1710 SkASSERT(1 == scalarsPerPosition || 2 == scalarsPerPosition);
1712 1711
1713 SkDEBUGCODE(this->validate();) 1712 SkDEBUGCODE(this->validate();)
1714 1713
1715 // nothing to draw 1714 // nothing to draw
1716 if (text == NULL || byteLength == 0 || fRC->isEmpty()) { 1715 if (text == NULL || byteLength == 0 || fRC->isEmpty()) {
1717 return; 1716 return;
1718 } 1717 }
1719 1718
1720 if (ShouldDrawTextAsPaths(paint, *fMatrix)) { 1719 if (ShouldDrawTextAsPaths(paint, *fMatrix)) {
1721 this->drawPosText_asPaths(text, byteLength, pos, constY, 1720 this->drawPosText_asPaths(text, byteLength, pos, scalarsPerPosition, off set, paint);
1722 scalarsPerPosition, paint);
1723 return; 1721 return;
1724 } 1722 }
1725 1723
1726 SkDrawCacheProc glyphCacheProc = paint.getDrawCacheProc(); 1724 SkDrawCacheProc glyphCacheProc = paint.getDrawCacheProc();
1727 SkAutoGlyphCache autoCache(paint, &fDevice->getLeakyProperties(), fMatrix ); 1725 SkAutoGlyphCache autoCache(paint, &fDevice->getLeakyProperties(), fMatrix );
1728 SkGlyphCache* cache = autoCache.getCache(); 1726 SkGlyphCache* cache = autoCache.getCache();
1729 1727
1730 SkAAClipBlitterWrapper wrapper; 1728 SkAAClipBlitterWrapper wrapper;
1731 SkAutoBlitterChoose blitterChooser; 1729 SkAutoBlitterChoose blitterChooser;
1732 SkBlitter* blitter = NULL; 1730 SkBlitter* blitter = NULL;
1733 if (needsRasterTextBlit(*this)) { 1731 if (needsRasterTextBlit(*this)) {
1734 blitterChooser.choose(*fBitmap, *fMatrix, paint); 1732 blitterChooser.choose(*fBitmap, *fMatrix, paint);
1735 blitter = blitterChooser.get(); 1733 blitter = blitterChooser.get();
1736 if (fRC->isAA()) { 1734 if (fRC->isAA()) {
1737 wrapper.init(*fRC, blitter); 1735 wrapper.init(*fRC, blitter);
1738 blitter = wrapper.getBlitter(); 1736 blitter = wrapper.getBlitter();
1739 } 1737 }
1740 } 1738 }
1741 1739
1742 const char* stop = text + byteLength; 1740 const char* stop = text + byteLength;
1743 SkTextAlignProc alignProc(paint.getTextAlign()); 1741 SkTextAlignProc alignProc(paint.getTextAlign());
1744 SkDraw1Glyph d1g; 1742 SkDraw1Glyph d1g;
1745 SkDraw1Glyph::Proc proc = d1g.init(this, blitter, cache, paint); 1743 SkDraw1Glyph::Proc proc = d1g.init(this, blitter, cache, paint);
1746 SkTextMapStateProc tmsProc(*fMatrix, constY, scalarsPerPosition); 1744 SkTextMapStateProc tmsProc(*fMatrix, offset, scalarsPerPosition);
1747 1745
1748 if (cache->isSubpixel()) { 1746 if (cache->isSubpixel()) {
1749 // maybe we should skip the rounding if linearText is set 1747 // maybe we should skip the rounding if linearText is set
1750 SkAxisAlignment baseline = SkComputeAxisAlignmentForHText(*fMatrix); 1748 SkAxisAlignment baseline = SkComputeAxisAlignmentForHText(*fMatrix);
1751 1749
1752 SkFixed fxMask = ~0; 1750 SkFixed fxMask = ~0;
1753 SkFixed fyMask = ~0; 1751 SkFixed fyMask = ~0;
1754 if (kX_SkAxisAlignment == baseline) { 1752 if (kX_SkAxisAlignment == baseline) {
1755 fyMask = 0; 1753 fyMask = 0;
1756 #ifndef SK_IGNORE_SUBPIXEL_AXIS_ALIGN_FIX 1754 #ifndef SK_IGNORE_SUBPIXEL_AXIS_ALIGN_FIX
(...skipping 621 matching lines...) Expand 10 before | Expand all | Expand 10 after
2378 mask->fImage = SkMask::AllocImage(size); 2376 mask->fImage = SkMask::AllocImage(size);
2379 memset(mask->fImage, 0, mask->computeImageSize()); 2377 memset(mask->fImage, 0, mask->computeImageSize());
2380 } 2378 }
2381 2379
2382 if (SkMask::kJustComputeBounds_CreateMode != mode) { 2380 if (SkMask::kJustComputeBounds_CreateMode != mode) {
2383 draw_into_mask(*mask, devPath, style); 2381 draw_into_mask(*mask, devPath, style);
2384 } 2382 }
2385 2383
2386 return true; 2384 return true;
2387 } 2385 }
OLDNEW
« no previous file with comments | « src/core/SkDevice.cpp ('k') | src/core/SkTextMapStateProc.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698