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

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

Issue 748883005: Factor text size device mapping in SkScalerContext. (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Add comments, clarify names. Created 6 years 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
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 799 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 // load the font file 810 // load the font file
811 fStrikeIndex = -1; 811 fStrikeIndex = -1;
812 fFTSize = NULL; 812 fFTSize = NULL;
813 fFace = NULL; 813 fFace = NULL;
814 fFaceRec = ref_ft_face(typeface); 814 fFaceRec = ref_ft_face(typeface);
815 if (NULL == fFaceRec) { 815 if (NULL == fFaceRec) {
816 return; 816 return;
817 } 817 }
818 fFace = fFaceRec->fFace; 818 fFace = fFaceRec->fFace;
819 819
820 // A is the total matrix. 820 fRec.computeMatrices(SkScalerContextRec::kFull_PreMatrixScale, &fScale, &fMa trix22Scalar);
821 SkMatrix A; 821 fMatrix22Scalar.setSkewX(-fMatrix22Scalar.getSkewX());
822 fRec.getSingleMatrix(&A); 822 fMatrix22Scalar.setSkewY(-fMatrix22Scalar.getSkewY());
823 823
824 SkScalar sx = A.getScaleX(); 824 fScaleX = SkScalarToFixed(fScale.fX);
825 SkScalar sy = A.getScaleY(); 825 fScaleY = SkScalarToFixed(fScale.fY);
826 fMatrix22Scalar.reset();
827
828 // In GDI, the hinter is aware of the current transformation
829 // (the transform is in some sense applied before/with the hinting).
830 // The bytecode can then test if it is rotated or stretched and decide
831 // to apply instructions or not.
832 //
833 // FreeType, however, always does the transformation strictly after hinting.
834 // It just sets 'rotated' and 'stretched' to false and only applies the
835 // size before hinting.
836 //
837 // Also, FreeType respects the head::flags::IntegerScaling flag,
838 // (although this is patched out on most major distros)
839 // so it is critical to get the size correct on the request.
840 //
841 // This also gets us the actual closest size on bitmap fonts as well.
842 if (A.getSkewX() || A.getSkewY() || sx < 0 || sy < 0) {
843 // h is where A maps the horizontal baseline.
844 SkPoint h = SkPoint::Make(SK_Scalar1, 0);
845 A.mapPoints(&h, 1);
846
847 // G is the Givens Matrix for A (rotational matrix where GA[0][1] == 0).
848 SkMatrix G;
849 SkComputeGivensRotation(h, &G);
850
851 // GA is the matrix A with rotation removed.
852 SkMatrix GA(G);
853 GA.preConcat(A);
854
855 sx = SkScalarAbs(GA.get(SkMatrix::kMScaleX));
856 sy = SkScalarAbs(GA.get(SkMatrix::kMScaleY));
857
858 // sA is the total matrix A without the text scale.
859 SkMatrix sA(A);
860 sA.preScale(SkScalarInvert(sx), SkScalarInvert(sy)); //remove text size
861
862 fMatrix22Scalar.setScaleX(sA.getScaleX());
863 fMatrix22Scalar.setSkewX(-sA.getSkewX());
864 fMatrix22Scalar.setSkewY(-sA.getSkewY());
865 fMatrix22Scalar.setScaleY(sA.getScaleY());
866 }
867 fScale.set(sx, sy);
868 fScaleX = SkScalarToFixed(sx);
869 fScaleY = SkScalarToFixed(sy);
870 fMatrix22.xx = SkScalarToFixed(fMatrix22Scalar.getScaleX()); 826 fMatrix22.xx = SkScalarToFixed(fMatrix22Scalar.getScaleX());
871 fMatrix22.xy = SkScalarToFixed(fMatrix22Scalar.getSkewX()); 827 fMatrix22.xy = SkScalarToFixed(fMatrix22Scalar.getSkewX());
872 fMatrix22.yx = SkScalarToFixed(fMatrix22Scalar.getSkewY()); 828 fMatrix22.yx = SkScalarToFixed(fMatrix22Scalar.getSkewY());
873 fMatrix22.yy = SkScalarToFixed(fMatrix22Scalar.getScaleY()); 829 fMatrix22.yy = SkScalarToFixed(fMatrix22Scalar.getScaleY());
874 830
875 fLCDIsVert = SkToBool(fRec.fFlags & SkScalerContext::kLCD_Vertical_Flag); 831 fLCDIsVert = SkToBool(fRec.fFlags & SkScalerContext::kLCD_Vertical_Flag);
876 832
877 // compute the flags we send to Load_Glyph 833 // compute the flags we send to Load_Glyph
878 bool linearMetrics = SkToBool(fRec.fFlags & SkScalerContext::kSubpixelPositi oning_Flag); 834 bool linearMetrics = SkToBool(fRec.fFlags & SkScalerContext::kSubpixelPositi oning_Flag);
879 { 835 {
(...skipping 867 matching lines...) Expand 10 before | Expand all | Expand 10 after
1747 if (style) { 1703 if (style) {
1748 *style = SkFontStyle(weight, width, slant); 1704 *style = SkFontStyle(weight, width, slant);
1749 } 1705 }
1750 if (isFixedPitch) { 1706 if (isFixedPitch) {
1751 *isFixedPitch = FT_IS_FIXED_WIDTH(face); 1707 *isFixedPitch = FT_IS_FIXED_WIDTH(face);
1752 } 1708 }
1753 1709
1754 FT_Done_Face(face); 1710 FT_Done_Face(face);
1755 return true; 1711 return true;
1756 } 1712 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698