| 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 "SkBounder.h" | 10 #include "SkBounder.h" |
| (...skipping 1823 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1834 fy += glyph.fAdvanceY; | 1834 fy += glyph.fAdvanceY; |
| 1835 #endif | 1835 #endif |
| 1836 } | 1836 } |
| 1837 } | 1837 } |
| 1838 | 1838 |
| 1839 // last parameter is interpreted as SkFixed [x, y] | 1839 // last parameter is interpreted as SkFixed [x, y] |
| 1840 // return the fixed position, which may be rounded or not by the caller | 1840 // return the fixed position, which may be rounded or not by the caller |
| 1841 // e.g. subpixel doesn't round | 1841 // e.g. subpixel doesn't round |
| 1842 typedef void (*AlignProc)(const SkPoint&, const SkGlyph&, SkIPoint*); | 1842 typedef void (*AlignProc)(const SkPoint&, const SkGlyph&, SkIPoint*); |
| 1843 | 1843 |
| 1844 static void leftAlignProc(const SkPoint& loc, const SkGlyph& glyph, | 1844 static void leftAlignProc(const SkPoint& loc, const SkGlyph& glyph, SkIPoint* ds
t) { |
| 1845 SkIPoint* dst) { | |
| 1846 dst->set(SkScalarToFixed(loc.fX), SkScalarToFixed(loc.fY)); | 1845 dst->set(SkScalarToFixed(loc.fX), SkScalarToFixed(loc.fY)); |
| 1847 } | 1846 } |
| 1848 | 1847 |
| 1849 static void centerAlignProc(const SkPoint& loc, const SkGlyph& glyph, | 1848 static void centerAlignProc(const SkPoint& loc, const SkGlyph& glyph, SkIPoint*
dst) { |
| 1850 SkIPoint* dst) { | |
| 1851 dst->set(SkScalarToFixed(loc.fX) - (glyph.fAdvanceX >> 1), | 1849 dst->set(SkScalarToFixed(loc.fX) - (glyph.fAdvanceX >> 1), |
| 1852 SkScalarToFixed(loc.fY) - (glyph.fAdvanceY >> 1)); | 1850 SkScalarToFixed(loc.fY) - (glyph.fAdvanceY >> 1)); |
| 1853 } | 1851 } |
| 1854 | 1852 |
| 1855 static void rightAlignProc(const SkPoint& loc, const SkGlyph& glyph, | 1853 static void rightAlignProc(const SkPoint& loc, const SkGlyph& glyph, SkIPoint* d
st) { |
| 1856 SkIPoint* dst) { | |
| 1857 dst->set(SkScalarToFixed(loc.fX) - glyph.fAdvanceX, | 1854 dst->set(SkScalarToFixed(loc.fX) - glyph.fAdvanceX, |
| 1858 SkScalarToFixed(loc.fY) - glyph.fAdvanceY); | 1855 SkScalarToFixed(loc.fY) - glyph.fAdvanceY); |
| 1859 } | 1856 } |
| 1860 | 1857 |
| 1861 static AlignProc pick_align_proc(SkPaint::Align align) { | 1858 static AlignProc pick_align_proc(SkPaint::Align align) { |
| 1862 static const AlignProc gProcs[] = { | 1859 static const AlignProc gProcs[] = { |
| 1863 leftAlignProc, centerAlignProc, rightAlignProc | 1860 leftAlignProc, centerAlignProc, rightAlignProc |
| 1864 }; | 1861 }; |
| 1865 | 1862 |
| 1866 SkASSERT((unsigned)align < SK_ARRAY_COUNT(gProcs)); | 1863 SkASSERT((unsigned)align < SK_ARRAY_COUNT(gProcs)); |
| 1867 | 1864 |
| 1868 return gProcs[align]; | 1865 return gProcs[align]; |
| 1869 } | 1866 } |
| 1870 | 1867 |
| 1868 typedef void (*AlignProc_scalar)(const SkPoint&, const SkGlyph&, SkPoint*); |
| 1869 |
| 1870 static void leftAlignProc_scalar(const SkPoint& loc, const SkGlyph& glyph, SkPoi
nt* dst) { |
| 1871 dst->set(loc.fX, loc.fY); |
| 1872 } |
| 1873 |
| 1874 static void centerAlignProc_scalar(const SkPoint& loc, const SkGlyph& glyph, SkP
oint* dst) { |
| 1875 dst->set(loc.fX - SkFixedToScalar(glyph.fAdvanceX >> 1), |
| 1876 loc.fY - SkFixedToScalar(glyph.fAdvanceY >> 1)); |
| 1877 } |
| 1878 |
| 1879 static void rightAlignProc_scalar(const SkPoint& loc, const SkGlyph& glyph, SkPo
int* dst) { |
| 1880 dst->set(loc.fX - SkFixedToScalar(glyph.fAdvanceX), |
| 1881 loc.fY - SkFixedToScalar(glyph.fAdvanceY)); |
| 1882 } |
| 1883 |
| 1884 static AlignProc_scalar pick_align_proc_scalar(SkPaint::Align align) { |
| 1885 static const AlignProc_scalar gProcs[] = { |
| 1886 leftAlignProc_scalar, centerAlignProc_scalar, rightAlignProc_scalar |
| 1887 }; |
| 1888 |
| 1889 SkASSERT((unsigned)align < SK_ARRAY_COUNT(gProcs)); |
| 1890 |
| 1891 return gProcs[align]; |
| 1892 } |
| 1893 |
| 1871 class TextMapState { | 1894 class TextMapState { |
| 1872 public: | 1895 public: |
| 1873 mutable SkPoint fLoc; | 1896 mutable SkPoint fLoc; |
| 1874 | 1897 |
| 1875 TextMapState(const SkMatrix& matrix, SkScalar y) | 1898 TextMapState(const SkMatrix& matrix, SkScalar y) |
| 1876 : fMatrix(matrix), fProc(matrix.getMapXYProc()), fY(y) {} | 1899 : fMatrix(matrix), fProc(matrix.getMapXYProc()), fY(y) {} |
| 1877 | 1900 |
| 1878 typedef void (*Proc)(const TextMapState&, const SkScalar pos[]); | 1901 typedef void (*Proc)(const TextMapState&, const SkScalar pos[]); |
| 1879 | 1902 |
| 1880 Proc pickProc(int scalarsPerPosition); | 1903 Proc pickProc(int scalarsPerPosition); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1937 SkScalar matrixScale = paint.setupForAsPaths(); | 1960 SkScalar matrixScale = paint.setupForAsPaths(); |
| 1938 | 1961 |
| 1939 SkMatrix matrix; | 1962 SkMatrix matrix; |
| 1940 matrix.setScale(matrixScale, matrixScale); | 1963 matrix.setScale(matrixScale, matrixScale); |
| 1941 | 1964 |
| 1942 SkDrawCacheProc glyphCacheProc = paint.getDrawCacheProc(); | 1965 SkDrawCacheProc glyphCacheProc = paint.getDrawCacheProc(); |
| 1943 SkAutoGlyphCache autoCache(paint, NULL, NULL); | 1966 SkAutoGlyphCache autoCache(paint, NULL, NULL); |
| 1944 SkGlyphCache* cache = autoCache.getCache(); | 1967 SkGlyphCache* cache = autoCache.getCache(); |
| 1945 | 1968 |
| 1946 const char* stop = text + byteLength; | 1969 const char* stop = text + byteLength; |
| 1947 AlignProc alignProc = pick_align_proc(paint.getTextAlign()); | 1970 AlignProc_scalar alignProc = pick_align_proc_scalar(paint.getTextAlign()); |
| 1948 TextMapState tms(SkMatrix::I(), constY); | 1971 TextMapState tms(SkMatrix::I(), constY); |
| 1949 TextMapState::Proc tmsProc = tms.pickProc(scalarsPerPosition); | 1972 TextMapState::Proc tmsProc = tms.pickProc(scalarsPerPosition); |
| 1950 | 1973 |
| 1951 while (text < stop) { | 1974 while (text < stop) { |
| 1952 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); | 1975 const SkGlyph& glyph = glyphCacheProc(cache, &text, 0, 0); |
| 1953 if (glyph.fWidth) { | 1976 if (glyph.fWidth) { |
| 1954 const SkPath* path = cache->findPath(glyph); | 1977 const SkPath* path = cache->findPath(glyph); |
| 1955 if (path) { | 1978 if (path) { |
| 1956 tmsProc(tms, pos); | 1979 tmsProc(tms, pos); |
| 1957 SkIPoint fixedLoc; | 1980 SkPoint loc; |
| 1958 alignProc(tms.fLoc, glyph, &fixedLoc); | 1981 alignProc(tms.fLoc, glyph, &loc); |
| 1959 | 1982 |
| 1960 matrix[SkMatrix::kMTransX] = SkFixedToScalar(fixedLoc.fX); | 1983 matrix[SkMatrix::kMTransX] = loc.fX; |
| 1961 matrix[SkMatrix::kMTransY] = SkFixedToScalar(fixedLoc.fY); | 1984 matrix[SkMatrix::kMTransY] = loc.fY; |
| 1962 if (fDevice) { | 1985 if (fDevice) { |
| 1963 fDevice->drawPath(*this, *path, paint, &matrix, false); | 1986 fDevice->drawPath(*this, *path, paint, &matrix, false); |
| 1964 } else { | 1987 } else { |
| 1965 this->drawPath(*path, paint, &matrix, false); | 1988 this->drawPath(*path, paint, &matrix, false); |
| 1966 } | 1989 } |
| 1967 } | 1990 } |
| 1968 } | 1991 } |
| 1969 pos += scalarsPerPosition; | 1992 pos += scalarsPerPosition; |
| 1970 } | 1993 } |
| 1971 } | 1994 } |
| (...skipping 900 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2872 mask->fImage = SkMask::AllocImage(size); | 2895 mask->fImage = SkMask::AllocImage(size); |
| 2873 memset(mask->fImage, 0, mask->computeImageSize()); | 2896 memset(mask->fImage, 0, mask->computeImageSize()); |
| 2874 } | 2897 } |
| 2875 | 2898 |
| 2876 if (SkMask::kJustComputeBounds_CreateMode != mode) { | 2899 if (SkMask::kJustComputeBounds_CreateMode != mode) { |
| 2877 draw_into_mask(*mask, devPath, style); | 2900 draw_into_mask(*mask, devPath, style); |
| 2878 } | 2901 } |
| 2879 | 2902 |
| 2880 return true; | 2903 return true; |
| 2881 } | 2904 } |
| OLD | NEW |