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

Side by Side Diff: src/ports/SkFontHost_FreeType.cpp

Issue 1711053004: Change type of SkScalerContext_FreeType::fScaleX/Y. All uses want FT_F26Dot6. (Closed) Base URL: https://skia.googlesource.com/skia@master
Patch Set: Fix scaleGlyphMetrics; reposition args to SkDEBUGF. Created 4 years, 10 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 | « no previous file | no next file » | 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 "SkAdvancedTypefaceMetrics.h" 8 #include "SkAdvancedTypefaceMetrics.h"
9 #include "SkBitmap.h" 9 #include "SkBitmap.h"
10 #include "SkCanvas.h" 10 #include "SkCanvas.h"
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 void generateMetrics(SkGlyph* glyph) override; 193 void generateMetrics(SkGlyph* glyph) override;
194 void generateImage(const SkGlyph& glyph) override; 194 void generateImage(const SkGlyph& glyph) override;
195 void generatePath(const SkGlyph& glyph, SkPath* path) override; 195 void generatePath(const SkGlyph& glyph, SkPath* path) override;
196 void generateFontMetrics(SkPaint::FontMetrics*) override; 196 void generateFontMetrics(SkPaint::FontMetrics*) override;
197 SkUnichar generateGlyphToChar(uint16_t glyph) override; 197 SkUnichar generateGlyphToChar(uint16_t glyph) override;
198 198
199 private: 199 private:
200 FT_Face fFace; // reference to shared face in gFaceRecHead 200 FT_Face fFace; // reference to shared face in gFaceRecHead
201 FT_Size fFTSize; // our own copy 201 FT_Size fFTSize; // our own copy
202 FT_Int fStrikeIndex; 202 FT_Int fStrikeIndex;
203 SkFixed fScaleX, fScaleY; 203 FT_F26Dot6 fScaleX, fScaleY;
204 FT_Matrix fMatrix22; 204 FT_Matrix fMatrix22;
205 uint32_t fLoadGlyphFlags; 205 uint32_t fLoadGlyphFlags;
206 bool fDoLinearMetrics; 206 bool fDoLinearMetrics;
207 bool fLCDIsVert; 207 bool fLCDIsVert;
208 208
209 // Need scalar versions for generateFontMetrics 209 // Need scalar versions for generateFontMetrics
210 SkVector fScale; 210 SkVector fScale;
211 SkMatrix fMatrix22Scalar; 211 SkMatrix fMatrix22Scalar;
212 212
213 FT_Error setupSize(); 213 FT_Error setupSize();
(...skipping 519 matching lines...) Expand 10 before | Expand all | Expand 10 after
733 FT_Error err = FT_Get_Kerning(face, glyphs[i], glyphs[i+1], 733 FT_Error err = FT_Get_Kerning(face, glyphs[i], glyphs[i+1],
734 FT_KERNING_UNSCALED, &delta); 734 FT_KERNING_UNSCALED, &delta);
735 if (err) { 735 if (err) {
736 return false; 736 return false;
737 } 737 }
738 adjustments[i] = delta.x; 738 adjustments[i] = delta.x;
739 } 739 }
740 return true; 740 return true;
741 } 741 }
742 742
743 static FT_Int chooseBitmapStrike(FT_Face face, SkFixed scaleY) { 743 static FT_Int chooseBitmapStrike(FT_Face face, FT_F26Dot6 scaleY) {
744 // early out if face is bad 744 // early out if face is bad
745 if (face == nullptr) { 745 if (face == nullptr) {
746 SkDEBUGF(("chooseBitmapStrike aborted due to nullptr face\n")); 746 SkDEBUGF(("chooseBitmapStrike aborted due to nullptr face\n"));
747 return -1; 747 return -1;
748 } 748 }
749 // determine target ppem 749 // determine target ppem
750 FT_Pos targetPPEM = SkFixedToFDot6(scaleY); 750 FT_Pos targetPPEM = scaleY;
751 // find a bitmap strike equal to or just larger than the requested size 751 // find a bitmap strike equal to or just larger than the requested size
752 FT_Int chosenStrikeIndex = -1; 752 FT_Int chosenStrikeIndex = -1;
753 FT_Pos chosenPPEM = 0; 753 FT_Pos chosenPPEM = 0;
754 for (FT_Int strikeIndex = 0; strikeIndex < face->num_fixed_sizes; ++strikeIn dex) { 754 for (FT_Int strikeIndex = 0; strikeIndex < face->num_fixed_sizes; ++strikeIn dex) {
755 FT_Pos thisPPEM = face->available_sizes[strikeIndex].y_ppem; 755 FT_Pos thisPPEM = face->available_sizes[strikeIndex].y_ppem;
756 if (thisPPEM == targetPPEM) { 756 if (thisPPEM == targetPPEM) {
757 // exact match - our search stops here 757 // exact match - our search stops here
758 chosenPPEM = thisPPEM; 758 chosenPPEM = thisPPEM;
759 chosenStrikeIndex = strikeIndex; 759 chosenStrikeIndex = strikeIndex;
760 break; 760 break;
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 fFTSize = nullptr; 798 fFTSize = nullptr;
799 fFace = ref_ft_face(typeface); 799 fFace = ref_ft_face(typeface);
800 if (nullptr == fFace) { 800 if (nullptr == fFace) {
801 return; 801 return;
802 } 802 }
803 803
804 fRec.computeMatrices(SkScalerContextRec::kFull_PreMatrixScale, &fScale, &fMa trix22Scalar); 804 fRec.computeMatrices(SkScalerContextRec::kFull_PreMatrixScale, &fScale, &fMa trix22Scalar);
805 fMatrix22Scalar.setSkewX(-fMatrix22Scalar.getSkewX()); 805 fMatrix22Scalar.setSkewX(-fMatrix22Scalar.getSkewX());
806 fMatrix22Scalar.setSkewY(-fMatrix22Scalar.getSkewY()); 806 fMatrix22Scalar.setSkewY(-fMatrix22Scalar.getSkewY());
807 807
808 fScaleX = SkScalarToFixed(fScale.fX); 808 fScaleX = SkScalarToFDot6(fScale.fX);
809 fScaleY = SkScalarToFixed(fScale.fY); 809 fScaleY = SkScalarToFDot6(fScale.fY);
810 fMatrix22.xx = SkScalarToFixed(fMatrix22Scalar.getScaleX()); 810 fMatrix22.xx = SkScalarToFixed(fMatrix22Scalar.getScaleX());
811 fMatrix22.xy = SkScalarToFixed(fMatrix22Scalar.getSkewX()); 811 fMatrix22.xy = SkScalarToFixed(fMatrix22Scalar.getSkewX());
812 fMatrix22.yx = SkScalarToFixed(fMatrix22Scalar.getSkewY()); 812 fMatrix22.yx = SkScalarToFixed(fMatrix22Scalar.getSkewY());
813 fMatrix22.yy = SkScalarToFixed(fMatrix22Scalar.getScaleY()); 813 fMatrix22.yy = SkScalarToFixed(fMatrix22Scalar.getScaleY());
814 814
815 fLCDIsVert = SkToBool(fRec.fFlags & SkScalerContext::kLCD_Vertical_Flag); 815 fLCDIsVert = SkToBool(fRec.fFlags & SkScalerContext::kLCD_Vertical_Flag);
816 816
817 // compute the flags we send to Load_Glyph 817 // compute the flags we send to Load_Glyph
818 bool linearMetrics = SkToBool(fRec.fFlags & SkScalerContext::kSubpixelPositi oning_Flag); 818 bool linearMetrics = SkToBool(fRec.fFlags & SkScalerContext::kSubpixelPositi oning_Flag);
819 { 819 {
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
891 } 891 }
892 err = FT_Activate_Size(fFTSize); 892 err = FT_Activate_Size(fFTSize);
893 if (err != 0) { 893 if (err != 0) {
894 SkDEBUGF(("FT_Activate_Size(%08x, 0x%x, 0x%x) returned 0x%x\n", fFace, f ScaleX, fScaleY, 894 SkDEBUGF(("FT_Activate_Size(%08x, 0x%x, 0x%x) returned 0x%x\n", fFace, f ScaleX, fScaleY,
895 err)); 895 err));
896 fFTSize = nullptr; 896 fFTSize = nullptr;
897 return; 897 return;
898 } 898 }
899 899
900 if (FT_IS_SCALABLE(fFace)) { 900 if (FT_IS_SCALABLE(fFace)) {
901 err = FT_Set_Char_Size(fFace, SkFixedToFDot6(fScaleX), SkFixedToFDot6(fS caleY), 72, 72); 901 err = FT_Set_Char_Size(fFace, fScaleX, fScaleY, 72, 72);
902 if (err != 0) { 902 if (err != 0) {
903 SkDEBUGF(("FT_Set_CharSize(%08x, 0x%x, 0x%x) returned 0x%x\n", 903 SkDEBUGF(("FT_Set_CharSize(%08x, 0x%x, 0x%x) returned 0x%x\n",
904 fFace, fScaleX, fScaleY, err)); 904 fFace, fScaleX, fScaleY, err));
905 fFace = nullptr; 905 fFace = nullptr;
906 return; 906 return;
907 } 907 }
908 FT_Set_Transform(fFace, &fMatrix22, nullptr); 908 FT_Set_Transform(fFace, &fMatrix22, nullptr);
909 } else if (FT_HAS_FIXED_SIZES(fFace)) { 909 } else if (FT_HAS_FIXED_SIZES(fFace)) {
910 fStrikeIndex = chooseBitmapStrike(fFace, fScaleY); 910 fStrikeIndex = chooseBitmapStrike(fFace, fScaleY);
911 if (fStrikeIndex == -1) { 911 if (fStrikeIndex == -1) {
912 SkDEBUGF(("no glyphs for font \"%s\" size %f?\n", 912 SkDEBUGF(("no glyphs for font \"%s\" size %f?\n",
913 fFace->family_name, SkFixedToScalar(fScaleY))) ; 913 fFace->family_name, SkFDot6ToScalar(fScaleY))) ;
914 } else { 914 } else {
915 // FreeType does no provide linear metrics for bitmap fonts. 915 // FreeType does no provide linear metrics for bitmap fonts.
916 linearMetrics = false; 916 linearMetrics = false;
917 917
918 // FreeType documentation says: 918 // FreeType documentation says:
919 // FT_LOAD_NO_BITMAP -- Ignore bitmap strikes when loading. 919 // FT_LOAD_NO_BITMAP -- Ignore bitmap strikes when loading.
920 // Bitmap-only fonts ignore this flag. 920 // Bitmap-only fonts ignore this flag.
921 // 921 //
922 // However, in FreeType 2.5.1 color bitmap only fonts do not ignore this flag. 922 // However, in FreeType 2.5.1 color bitmap only fonts do not ignore this flag.
923 // Force this flag off for bitmap only fonts. 923 // Force this flag off for bitmap only fonts.
924 fLoadGlyphFlags &= ~FT_LOAD_NO_BITMAP; 924 fLoadGlyphFlags &= ~FT_LOAD_NO_BITMAP;
925 } 925 }
926 } else { 926 } else {
927 SkDEBUGF(("unknown kind of font \"%s\" size %f?\n", 927 SkDEBUGF(("unknown kind of font \"%s\" size %f?\n",
928 fFace->family_name, SkFixedToScalar(fScaleY))) ; 928 fFace->family_name, SkFDot6ToScalar(fScaleY)));
929 } 929 }
930 930
931 fDoLinearMetrics = linearMetrics; 931 fDoLinearMetrics = linearMetrics;
932 } 932 }
933 933
934 SkScalerContext_FreeType::~SkScalerContext_FreeType() { 934 SkScalerContext_FreeType::~SkScalerContext_FreeType() {
935 SkAutoMutexAcquire ac(gFTMutex); 935 SkAutoMutexAcquire ac(gFTMutex);
936 936
937 if (fFTSize != nullptr) { 937 if (fFTSize != nullptr) {
938 FT_Done_Size(fFTSize); 938 FT_Done_Size(fFTSize);
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
1180 1180
1181 if (fRec.fFlags & kDevKernText_Flag) { 1181 if (fRec.fFlags & kDevKernText_Flag) {
1182 glyph->fRsbDelta = SkToS8(fFace->glyph->rsb_delta); 1182 glyph->fRsbDelta = SkToS8(fFace->glyph->rsb_delta);
1183 glyph->fLsbDelta = SkToS8(fFace->glyph->lsb_delta); 1183 glyph->fLsbDelta = SkToS8(fFace->glyph->lsb_delta);
1184 } 1184 }
1185 } 1185 }
1186 } 1186 }
1187 1187
1188 // If the font isn't scalable, scale the metrics from the non-scalable strik e. 1188 // If the font isn't scalable, scale the metrics from the non-scalable strik e.
1189 // This means do not try to scale embedded bitmaps; only scale bitmaps in bi tmap only fonts. 1189 // This means do not try to scale embedded bitmaps; only scale bitmaps in bi tmap only fonts.
1190 if (!FT_IS_SCALABLE(fFace) && fScaleY && fFace->size->metrics.y_ppem) { 1190 if (!FT_IS_SCALABLE(fFace) && !SkScalarNearlyZero(fScale.fY) && fFace->size- >metrics.y_ppem) {
1191 // NOTE: both dimensions are scaled by y_ppem. this is WAI. 1191 // NOTE: both dimensions are scaled by y_ppem. this is WAI.
1192 scaleGlyphMetrics(*glyph, SkFixedToScalar(fScaleY) / fFace->size->metric s.y_ppem); 1192 scaleGlyphMetrics(*glyph, fScale.fY / fFace->size->metrics.y_ppem);
1193 } 1193 }
1194 1194
1195 #ifdef ENABLE_GLYPH_SPEW 1195 #ifdef ENABLE_GLYPH_SPEW
1196 SkDEBUGF(("FT_Set_Char_Size(this:%p sx:%x sy:%x ", this, fScaleX, fScaleY)); 1196 SkDEBUGF(("FT_Set_Char_Size(this:%p sx:%x sy:%x ", this, fScaleX, fScaleY));
1197 SkDEBUGF(("Metrics(glyph:%d flags:0x%x) w:%d\n", glyph->getGlyphID(), fLoadG lyphFlags, glyph->fWidth)); 1197 SkDEBUGF(("Metrics(glyph:%d flags:0x%x) w:%d\n", glyph->getGlyphID(), fLoadG lyphFlags, glyph->fWidth));
1198 #endif 1198 #endif
1199 } 1199 }
1200 1200
1201 static void clear_glyph_image(const SkGlyph& glyph) { 1201 static void clear_glyph_image(const SkGlyph& glyph) {
1202 sk_bzero(glyph.fImage, glyph.rowBytes() * glyph.fHeight); 1202 sk_bzero(glyph.fImage, glyph.rowBytes() * glyph.fHeight);
(...skipping 585 matching lines...) Expand 10 before | Expand all | Expand 10 after
1788 SkDEBUGF(("Requested font axis not found: %s '%c%c%c%c'\n", 1788 SkDEBUGF(("Requested font axis not found: %s '%c%c%c%c'\n",
1789 name.c_str(), 1789 name.c_str(),
1790 (skTag >> 24) & 0xFF, 1790 (skTag >> 24) & 0xFF,
1791 (skTag >> 16) & 0xFF, 1791 (skTag >> 16) & 0xFF,
1792 (skTag >> 8) & 0xFF, 1792 (skTag >> 8) & 0xFF,
1793 (skTag) & 0xFF)); 1793 (skTag) & 0xFF));
1794 } 1794 }
1795 } 1795 }
1796 ) 1796 )
1797 } 1797 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698