OLD | NEW |
1 /* libs/graphics/ports/SkFontHost_FreeType.cpp | 1 /* libs/graphics/ports/SkFontHost_FreeType.cpp |
2 ** | 2 ** |
3 ** Copyright 2006, The Android Open Source Project | 3 ** Copyright 2006, The Android Open Source Project |
4 ** | 4 ** |
5 ** Licensed under the Apache License, Version 2.0 (the "License"); | 5 ** Licensed under the Apache License, Version 2.0 (the "License"); |
6 ** you may not use this file except in compliance with the License. | 6 ** you may not use this file except in compliance with the License. |
7 ** You may obtain a copy of the License at | 7 ** You may obtain a copy of the License at |
8 ** | 8 ** |
9 ** http://www.apache.org/licenses/LICENSE-2.0 | 9 ** http://www.apache.org/licenses/LICENSE-2.0 |
10 ** | 10 ** |
(...skipping 852 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
863 SkPoint pts[7]; | 863 SkPoint pts[7]; |
864 SkFixed ys[7]; | 864 SkFixed ys[7]; |
865 FT_Face face = fFace; | 865 FT_Face face = fFace; |
866 int upem = face->units_per_EM; | 866 int upem = face->units_per_EM; |
867 SkFixed scaleY = fScaleY; | 867 SkFixed scaleY = fScaleY; |
868 SkFixed mxy = fMatrix22.xy; | 868 SkFixed mxy = fMatrix22.xy; |
869 SkFixed myy = fMatrix22.yy; | 869 SkFixed myy = fMatrix22.yy; |
870 SkScalar xmin = static_cast<SkScalar>(face->bbox.xMin) / upem; | 870 SkScalar xmin = static_cast<SkScalar>(face->bbox.xMin) / upem; |
871 SkScalar xmax = static_cast<SkScalar>(face->bbox.xMax) / upem; | 871 SkScalar xmax = static_cast<SkScalar>(face->bbox.xMax) / upem; |
872 | 872 |
873 int leading = face->height - face->ascender + face->descender; | 873 int leading = face->height - (face->ascender + face->descender); |
874 if (leading < 0) { | 874 if (leading < 0) { |
875 leading = 0; | 875 leading = 0; |
876 } | 876 } |
877 | 877 |
878 // Try to get the OS/2 table from the font. This contains the specific | 878 // Try to get the OS/2 table from the font. This contains the specific |
879 // average font width metrics which Windows uses. | 879 // average font width metrics which Windows uses. |
880 TT_OS2* os2 = (TT_OS2*) FT_Get_Sfnt_Table(face, ft_sfnt_os2); | 880 TT_OS2* os2 = (TT_OS2*) FT_Get_Sfnt_Table(face, ft_sfnt_os2); |
881 | 881 |
882 ys[0] = -face->bbox.yMax; | 882 ys[0] = -face->bbox.yMax; |
883 ys[1] = -face->ascender; | 883 ys[1] = -face->ascender; |
884 ys[2] = -face->descender; | 884 ys[2] = -face->descender; |
885 ys[3] = -face->bbox.yMin; | 885 ys[3] = -face->bbox.yMin; |
886 ys[4] = leading; | 886 ys[4] = leading; |
887 ys[5] = face->height; | 887 ys[5] = os2 ? os2->xAvgCharWidth : 0; |
888 ys[6] = os2 ? os2->xAvgCharWidth : 0; | |
889 | 888 |
890 SkScalar x_height; | 889 SkScalar x_height; |
891 if (os2 && os2->sxHeight) { | 890 if (os2 && os2->sxHeight) { |
892 x_height = (static_cast<SkScalar>(os2->sxHeight) / upem) * | 891 x_height = (static_cast<SkScalar>(os2->sxHeight) / upem) * |
893 (static_cast<SkScalar>(fScaleX) / 65536); | 892 (static_cast<SkScalar>(fScaleX) / 65536); |
894 } else { | 893 } else { |
895 const FT_UInt x_glyph = FT_Get_Char_Index(fFace, 'x'); | 894 const FT_UInt x_glyph = FT_Get_Char_Index(fFace, 'x'); |
896 if (x_glyph) { | 895 if (x_glyph) { |
897 FT_BBox bbox; | 896 FT_BBox bbox; |
898 FT_Load_Glyph(fFace, x_glyph, fLoadGlyphFlags); | 897 FT_Load_Glyph(fFace, x_glyph, fLoadGlyphFlags); |
899 FT_Outline_Get_CBox(&fFace->glyph->outline, &bbox); | 898 FT_Outline_Get_CBox(&fFace->glyph->outline, &bbox); |
900 x_height = static_cast<SkScalar>(bbox.yMax) / 64; | 899 x_height = static_cast<SkScalar>(bbox.yMax) / 64; |
901 } else { | 900 } else { |
902 x_height = 0; | 901 x_height = 0; |
903 } | 902 } |
904 } | 903 } |
905 | 904 |
906 // convert upem-y values into scalar points | 905 // convert upem-y values into scalar points |
907 for (int i = 0; i < 7; i++) { | 906 for (int i = 0; i < 6; i++) { |
908 SkFixed y = SkMulDiv(scaleY, ys[i], upem); | 907 SkFixed y = SkMulDiv(scaleY, ys[i], upem); |
909 SkFixed x = SkFixedMul(mxy, y); | 908 SkFixed x = SkFixedMul(mxy, y); |
910 y = SkFixedMul(myy, y); | 909 y = SkFixedMul(myy, y); |
911 pts[i].set(SkFixedToScalar(x), SkFixedToScalar(y)); | 910 pts[i].set(SkFixedToScalar(x), SkFixedToScalar(y)); |
912 } | 911 } |
913 | 912 |
914 if (mx) { | 913 if (mx) { |
915 mx->fTop = pts[0].fX; | 914 mx->fTop = pts[0].fX; |
916 mx->fAscent = pts[1].fX; | 915 mx->fAscent = pts[1].fX; |
917 mx->fDescent = pts[2].fX; | 916 mx->fDescent = pts[2].fX; |
918 mx->fBottom = pts[3].fX; | 917 mx->fBottom = pts[3].fX; |
919 mx->fLeading = pts[4].fX; | 918 mx->fLeading = pts[4].fX; |
920 mx->fHeight = pts[5].fX; | 919 mx->fAvgCharWidth = pts[5].fX; |
921 mx->fAvgCharWidth = pts[6].fX; | |
922 mx->fXMin = xmin; | 920 mx->fXMin = xmin; |
923 mx->fXMax = xmax; | 921 mx->fXMax = xmax; |
924 mx->fXHeight = x_height; | 922 mx->fXHeight = x_height; |
925 | 923 |
926 // The VDMX metrics only make sense in the horizontal direction | 924 // The VDMX metrics only make sense in the horizontal direction |
927 // I believe | 925 // I believe |
928 my->fVDMXMetricsValid = false; | 926 my->fVDMXMetricsValid = false; |
929 } | 927 } |
930 if (my) { | 928 if (my) { |
931 my->fTop = pts[0].fY; | 929 my->fTop = pts[0].fY; |
932 my->fAscent = pts[1].fY; | 930 my->fAscent = pts[1].fY; |
933 my->fDescent = pts[2].fY; | 931 my->fDescent = pts[2].fY; |
934 my->fBottom = pts[3].fY; | 932 my->fBottom = pts[3].fY; |
935 my->fLeading = pts[4].fY; | 933 my->fLeading = pts[4].fY; |
936 my->fHeight = pts[5].fY; | 934 my->fAvgCharWidth = pts[5].fY; |
937 my->fAvgCharWidth = pts[6].fY; | |
938 my->fXMin = xmin; | 935 my->fXMin = xmin; |
939 my->fXMax = xmax; | 936 my->fXMax = xmax; |
940 my->fXHeight = x_height; | 937 my->fXHeight = x_height; |
941 my->fVDMXMetricsValid = false; | 938 my->fVDMXMetricsValid = false; |
942 | 939 |
943 // Attempt to parse the VDMX table to get exact metrics | 940 // Attempt to parse the VDMX table to get exact metrics |
944 unsigned pelsize = (fScaleY + 0x8000) >> 16; | 941 unsigned pelsize = (fScaleY + 0x8000) >> 16; |
945 int ymax, ymin; | 942 int ymax, ymin; |
946 if (SkFontHost_VDMX_Parse(&ymax, &ymin, face, pelsize)) { | 943 if (SkFontHost_VDMX_Parse(&ymax, &ymin, face, pelsize)) { |
947 my->fVDMXMetricsValid = true; | 944 my->fVDMXMetricsValid = true; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1011 } | 1008 } |
1012 if (face->style_flags & FT_STYLE_FLAG_ITALIC) { | 1009 if (face->style_flags & FT_STYLE_FLAG_ITALIC) { |
1013 style |= SkTypeface::kItalic; | 1010 style |= SkTypeface::kItalic; |
1014 } | 1011 } |
1015 | 1012 |
1016 FT_Done_Face(face); | 1013 FT_Done_Face(face); |
1017 FT_Done_FreeType(library); | 1014 FT_Done_FreeType(library); |
1018 return (SkTypeface::Style)style; | 1015 return (SkTypeface::Style)style; |
1019 } | 1016 } |
1020 | 1017 |
OLD | NEW |