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