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

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

Issue 2163633002: Make SkFont a bit more useable (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Fix bug Created 4 years, 5 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/SkFont.cpp ('k') | src/gpu/text/GrStencilAndCoverTextContext.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 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 "SkPaint.h" 8 #include "SkPaint.h"
9 #include "SkAutoKern.h" 9 #include "SkAutoKern.h"
10 #include "SkChecksum.h" 10 #include "SkChecksum.h"
(...skipping 643 matching lines...) Expand 10 before | Expand all | Expand 10 after
654 SkASSERT(cache != nullptr); 654 SkASSERT(cache != nullptr);
655 SkASSERT(text != nullptr); 655 SkASSERT(text != nullptr);
656 656
657 const uint16_t* ptr = *(const uint16_t**)text; 657 const uint16_t* ptr = *(const uint16_t**)text;
658 unsigned glyphID = *ptr; 658 unsigned glyphID = *ptr;
659 ptr += 1; 659 ptr += 1;
660 *text = (const char*)ptr; 660 *text = (const char*)ptr;
661 return cache->getGlyphIDAdvance(glyphID); 661 return cache->getGlyphIDAdvance(glyphID);
662 } 662 }
663 663
664 SkPaint::GlyphCacheProc SkPaint::getGlyphCacheProc(bool needFullMetrics) const { 664 SkPaint::GlyphCacheProc SkPaint::GetGlyphCacheProc(TextEncoding encoding,
665 bool isDevKern,
666 bool needFullMetrics) {
665 static const GlyphCacheProc gGlyphCacheProcs[] = { 667 static const GlyphCacheProc gGlyphCacheProcs[] = {
666 sk_getMetrics_utf8_next, 668 sk_getMetrics_utf8_next,
667 sk_getMetrics_utf16_next, 669 sk_getMetrics_utf16_next,
668 sk_getMetrics_utf32_next, 670 sk_getMetrics_utf32_next,
669 sk_getMetrics_glyph_next, 671 sk_getMetrics_glyph_next,
670 672
671 sk_getAdvance_utf8_next, 673 sk_getAdvance_utf8_next,
672 sk_getAdvance_utf16_next, 674 sk_getAdvance_utf16_next,
673 sk_getAdvance_utf32_next, 675 sk_getAdvance_utf32_next,
674 sk_getAdvance_glyph_next, 676 sk_getAdvance_glyph_next,
675 }; 677 };
676 678
677 unsigned index = this->getTextEncoding(); 679 unsigned index = encoding;
678 680
679 if (!needFullMetrics && !this->isDevKernText()) { 681 if (!needFullMetrics && !isDevKern) {
680 index += 4; 682 index += 4;
681 } 683 }
682 684
683 SkASSERT(index < SK_ARRAY_COUNT(gGlyphCacheProcs)); 685 SkASSERT(index < SK_ARRAY_COUNT(gGlyphCacheProcs));
684 return gGlyphCacheProcs[index]; 686 return gGlyphCacheProcs[index];
685 } 687 }
686 688
687 /////////////////////////////////////////////////////////////////////////////// 689 ///////////////////////////////////////////////////////////////////////////////
688 690
689 #define TEXT_AS_PATHS_PAINT_FLAGS_TO_IGNORE ( \ 691 #define TEXT_AS_PATHS_PAINT_FLAGS_TO_IGNORE ( \
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 int* count, SkRect* bounds) const { 769 int* count, SkRect* bounds) const {
768 SkASSERT(count); 770 SkASSERT(count);
769 if (byteLength == 0) { 771 if (byteLength == 0) {
770 *count = 0; 772 *count = 0;
771 if (bounds) { 773 if (bounds) {
772 bounds->setEmpty(); 774 bounds->setEmpty();
773 } 775 }
774 return 0; 776 return 0;
775 } 777 }
776 778
777 GlyphCacheProc glyphCacheProc = this->getGlyphCacheProc(nullptr != bounds); 779 GlyphCacheProc glyphCacheProc = SkPaint::GetGlyphCacheProc(this->getTextEnco ding(),
780 this->isDevKernTe xt(),
781 nullptr != bounds );
778 782
779 int xyIndex; 783 int xyIndex;
780 JoinBoundsProc joinBoundsProc; 784 JoinBoundsProc joinBoundsProc;
781 if (this->isVerticalText()) { 785 if (this->isVerticalText()) {
782 xyIndex = 1; 786 xyIndex = 1;
783 joinBoundsProc = join_bounds_y; 787 joinBoundsProc = join_bounds_y;
784 } else { 788 } else {
785 xyIndex = 0; 789 xyIndex = 0;
786 joinBoundsProc = join_bounds_x; 790 joinBoundsProc = join_bounds_x;
787 } 791 }
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
885 SkScalar scale = canon.getScale(); 889 SkScalar scale = canon.getScale();
886 890
887 // adjust max in case we changed the textSize in paint 891 // adjust max in case we changed the textSize in paint
888 if (scale) { 892 if (scale) {
889 maxWidth /= scale; 893 maxWidth /= scale;
890 } 894 }
891 895
892 SkAutoGlyphCache autoCache(paint, nullptr, nullptr); 896 SkAutoGlyphCache autoCache(paint, nullptr, nullptr);
893 SkGlyphCache* cache = autoCache.getCache(); 897 SkGlyphCache* cache = autoCache.getCache();
894 898
895 GlyphCacheProc glyphCacheProc = paint.getGlyphCacheProc(false); 899 GlyphCacheProc glyphCacheProc = SkPaint::GetGlyphCacheProc(paint.getTextEn coding(),
900 paint.isDevKern Text(),
901 false);
896 const int xyIndex = paint.isVerticalText() ? 1 : 0; 902 const int xyIndex = paint.isVerticalText() ? 1 : 0;
897 SkScalar width = 0; 903 SkScalar width = 0;
898 904
899 if (this->isDevKernText()) { 905 if (this->isDevKernText()) {
900 int rsb = 0; 906 int rsb = 0;
901 while (text < stop) { 907 while (text < stop) {
902 const char* curr = text; 908 const char* curr = text;
903 const SkGlyph& g = glyphCacheProc(cache, &text); 909 const SkGlyph& g = glyphCacheProc(cache, &text);
904 SkScalar x = SkAutoKern_Adjust(rsb, g.fLsbDelta) + advance(g, xyInde x); 910 SkScalar x = SkAutoKern_Adjust(rsb, g.fLsbDelta) + advance(g, xyInde x);
905 if ((width += x) > maxWidth) { 911 if ((width += x) > maxWidth) {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
998 if (nullptr == widths && nullptr == bounds) { 1004 if (nullptr == widths && nullptr == bounds) {
999 return this->countText(textData, byteLength); 1005 return this->countText(textData, byteLength);
1000 } 1006 }
1001 1007
1002 SkCanonicalizePaint canon(*this); 1008 SkCanonicalizePaint canon(*this);
1003 const SkPaint& paint = canon.getPaint(); 1009 const SkPaint& paint = canon.getPaint();
1004 SkScalar scale = canon.getScale(); 1010 SkScalar scale = canon.getScale();
1005 1011
1006 SkAutoGlyphCache autoCache(paint, nullptr, nullptr); 1012 SkAutoGlyphCache autoCache(paint, nullptr, nullptr);
1007 SkGlyphCache* cache = autoCache.getCache(); 1013 SkGlyphCache* cache = autoCache.getCache();
1008 GlyphCacheProc glyphCacheProc = paint.getGlyphCacheProc(nullptr != boun ds); 1014 GlyphCacheProc glyphCacheProc = SkPaint::GetGlyphCacheProc(paint.getTex tEncoding(),
1015 paint.isDevK ernText(),
1016 nullptr != b ounds);
1009 1017
1010 const char* text = (const char*)textData; 1018 const char* text = (const char*)textData;
1011 const char* stop = text + byteLength; 1019 const char* stop = text + byteLength;
1012 int count = 0; 1020 int count = 0;
1013 const int xyIndex = paint.isVerticalText() ? 1 : 0; 1021 const int xyIndex = paint.isVerticalText() ? 1 : 0;
1014 1022
1015 if (this->isDevKernText()) { 1023 if (this->isDevKernText()) {
1016 // we adjust the widths returned here through auto-kerning 1024 // we adjust the widths returned here through auto-kerning
1017 SkAutoKern autokern; 1025 SkAutoKern autokern;
1018 SkScalar prevWidth = 0; 1026 SkScalar prevWidth = 0;
(...skipping 1156 matching lines...) Expand 10 before | Expand all | Expand 10 after
2175 2183
2176 static bool has_thick_frame(const SkPaint& paint) { 2184 static bool has_thick_frame(const SkPaint& paint) {
2177 return paint.getStrokeWidth() > 0 && 2185 return paint.getStrokeWidth() > 0 &&
2178 paint.getStyle() != SkPaint::kFill_Style; 2186 paint.getStyle() != SkPaint::kFill_Style;
2179 } 2187 }
2180 2188
2181 SkTextBaseIter::SkTextBaseIter(const char text[], size_t length, 2189 SkTextBaseIter::SkTextBaseIter(const char text[], size_t length,
2182 const SkPaint& paint, 2190 const SkPaint& paint,
2183 bool applyStrokeAndPathEffects) 2191 bool applyStrokeAndPathEffects)
2184 : fPaint(paint) { 2192 : fPaint(paint) {
2185 fGlyphCacheProc = paint.getGlyphCacheProc(true); 2193 fGlyphCacheProc = SkPaint::GetGlyphCacheProc(paint.getTextEncoding(),
2194 paint.isDevKernText(),
2195 true);
2186 2196
2187 fPaint.setLinearText(true); 2197 fPaint.setLinearText(true);
2188 fPaint.setMaskFilter(nullptr); // don't want this affecting our path-cache lookup 2198 fPaint.setMaskFilter(nullptr); // don't want this affecting our path-cache lookup
2189 2199
2190 if (fPaint.getPathEffect() == nullptr && !has_thick_frame(fPaint)) { 2200 if (fPaint.getPathEffect() == nullptr && !has_thick_frame(fPaint)) {
2191 applyStrokeAndPathEffects = false; 2201 applyStrokeAndPathEffects = false;
2192 } 2202 }
2193 2203
2194 // can't use our canonical size if we need to apply patheffects 2204 // can't use our canonical size if we need to apply patheffects
2195 if (fPaint.getPathEffect() == nullptr) { 2205 if (fPaint.getPathEffect() == nullptr) {
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
2322 } 2332 }
2323 2333
2324 uint32_t SkPaint::getHash() const { 2334 uint32_t SkPaint::getHash() const {
2325 // We're going to hash 10 pointers and 7 32-bit values, finishing up with fB itfields, 2335 // We're going to hash 10 pointers and 7 32-bit values, finishing up with fB itfields,
2326 // so fBitfields should be 10 pointers and 6 32-bit values from the start. 2336 // so fBitfields should be 10 pointers and 6 32-bit values from the start.
2327 static_assert(offsetof(SkPaint, fBitfields) == 9 * sizeof(void*) + 6 * sizeo f(uint32_t), 2337 static_assert(offsetof(SkPaint, fBitfields) == 9 * sizeof(void*) + 6 * sizeo f(uint32_t),
2328 "SkPaint_notPackedTightly"); 2338 "SkPaint_notPackedTightly");
2329 return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(this), 2339 return SkChecksum::Murmur3(reinterpret_cast<const uint32_t*>(this),
2330 offsetof(SkPaint, fBitfields) + sizeof(fBitfields )); 2340 offsetof(SkPaint, fBitfields) + sizeof(fBitfields ));
2331 } 2341 }
OLDNEW
« no previous file with comments | « src/core/SkFont.cpp ('k') | src/gpu/text/GrStencilAndCoverTextContext.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698