OLD | NEW |
1 /* libs/graphics/ports/SkFontHost_FreeType.cpp | 1 /* libs/graphics/ports/SkFontHost_FreeType.cpp |
2 ** | 2 ** |
3 ** Copyright 2006, Google Inc. | 3 ** Copyright 2006, Google Inc. |
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 767 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
778 | 778 |
779 if (this->setupSize()) | 779 if (this->setupSize()) |
780 { | 780 { |
781 if (mx) | 781 if (mx) |
782 memset(mx, 0, sizeof(SkPaint::FontMetrics)); | 782 memset(mx, 0, sizeof(SkPaint::FontMetrics)); |
783 if (my) | 783 if (my) |
784 memset(my, 0, sizeof(SkPaint::FontMetrics)); | 784 memset(my, 0, sizeof(SkPaint::FontMetrics)); |
785 return; | 785 return; |
786 } | 786 } |
787 | 787 |
788 SkPoint pts[6]; | 788 SkPoint pts[7]; |
789 SkFixed ys[6]; | 789 SkFixed ys[7]; |
790 FT_Face face = fFace; | 790 FT_Face face = fFace; |
791 int upem = face->units_per_EM; | 791 int upem = face->units_per_EM; |
792 SkFixed scaleY = fScaleY; | 792 SkFixed scaleY = fScaleY; |
793 SkFixed mxy = fMatrix22.xy; | 793 SkFixed mxy = fMatrix22.xy; |
794 SkFixed myy = fMatrix22.yy; | 794 SkFixed myy = fMatrix22.yy; |
795 | 795 |
796 int leading = face->height - face->ascender + face->descender; | 796 int leading = face->height - face->ascender + face->descender; |
797 if (leading < 0) | 797 if (leading < 0) |
798 leading = 0; | 798 leading = 0; |
799 | 799 |
| 800 // Try to get the OS/2 table from the font. This contains the specific |
| 801 // average font width metrics which Windows uses. |
| 802 TT_OS2* os2 = (TT_OS2*) FT_Get_Sfnt_Table(face, ft_sfnt_os2); |
| 803 |
800 ys[0] = -face->bbox.yMax; | 804 ys[0] = -face->bbox.yMax; |
801 ys[1] = -face->ascender; | 805 ys[1] = -face->ascender; |
802 ys[2] = -face->descender; | 806 ys[2] = -face->descender; |
803 ys[3] = -face->bbox.yMin; | 807 ys[3] = -face->bbox.yMin; |
804 ys[4] = leading; | 808 ys[4] = leading; |
805 ys[5] = face->height; | 809 ys[5] = face->height; |
| 810 ys[6] = os2 ? os2->xAvgCharWidth : 0; |
806 | 811 |
807 // convert upem-y values into scalar points | 812 // convert upem-y values into scalar points |
808 for (int i = 0; i < 6; i++) | 813 for (int i = 0; i < 7; i++) |
809 { | 814 { |
810 SkFixed y = SkMulDiv(scaleY, ys[i], upem); | 815 SkFixed y = SkMulDiv(scaleY, ys[i], upem); |
811 SkFixed x = SkFixedMul(mxy, y); | 816 SkFixed x = SkFixedMul(mxy, y); |
812 y = SkFixedMul(myy, y); | 817 y = SkFixedMul(myy, y); |
813 pts[i].set(SkFixedToScalar(x), SkFixedToScalar(y)); | 818 pts[i].set(SkFixedToScalar(x), SkFixedToScalar(y)); |
814 } | 819 } |
815 | 820 |
816 if (mx) | 821 if (mx) |
817 { | 822 { |
818 mx->fTop = pts[0].fX; | 823 mx->fTop = pts[0].fX; |
819 mx->fAscent = pts[1].fX; | 824 mx->fAscent = pts[1].fX; |
820 mx->fDescent = pts[2].fX; | 825 mx->fDescent = pts[2].fX; |
821 mx->fBottom = pts[3].fX; | 826 mx->fBottom = pts[3].fX; |
822 mx->fLeading = pts[4].fX; | 827 mx->fLeading = pts[4].fX; |
823 mx->fHeight = pts[5].fX; | 828 mx->fHeight = pts[5].fX; |
| 829 mx->fAvgCharWidth = pts[6].fX; |
824 | 830 |
825 // The VDMX metrics only make sense in the horizontal direction | 831 // The VDMX metrics only make sense in the horizontal direction |
826 // I believe | 832 // I believe |
827 my->fVDMXMetricsValid = false; | 833 my->fVDMXMetricsValid = false; |
828 } | 834 } |
829 if (my) | 835 if (my) |
830 { | 836 { |
831 my->fTop = pts[0].fY; | 837 my->fTop = pts[0].fY; |
832 my->fAscent = pts[1].fY; | 838 my->fAscent = pts[1].fY; |
833 my->fDescent = pts[2].fY; | 839 my->fDescent = pts[2].fY; |
834 my->fBottom = pts[3].fY; | 840 my->fBottom = pts[3].fY; |
835 my->fLeading = pts[4].fY; | 841 my->fLeading = pts[4].fY; |
836 my->fHeight = pts[5].fY; | 842 my->fHeight = pts[5].fY; |
| 843 my->fAvgCharWidth = pts[6].fY; |
837 my->fVDMXMetricsValid = false; | 844 my->fVDMXMetricsValid = false; |
838 | 845 |
839 // Attempt to parse the VDMX table to get exact metrics | 846 // Attempt to parse the VDMX table to get exact metrics |
840 unsigned pelsize = (fScaleY + 0x8000) >> 16; | 847 unsigned pelsize = (fScaleY + 0x8000) >> 16; |
841 int ymax, ymin; | 848 int ymax, ymin; |
842 if (SkFontHost_VDMX_Parse(&ymax, &ymin, face, pelsize)) { | 849 if (SkFontHost_VDMX_Parse(&ymax, &ymin, face, pelsize)) { |
843 my->fVDMXMetricsValid = true; | 850 my->fVDMXMetricsValid = true; |
844 my->fVDMXAscent = ymax; | 851 my->fVDMXAscent = ymax; |
845 my->fVDMXDescent = -ymin; | 852 my->fVDMXDescent = -ymin; |
846 } | 853 } |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
904 } | 911 } |
905 if (face->style_flags & FT_STYLE_FLAG_ITALIC) { | 912 if (face->style_flags & FT_STYLE_FLAG_ITALIC) { |
906 style |= SkTypeface::kItalic; | 913 style |= SkTypeface::kItalic; |
907 } | 914 } |
908 | 915 |
909 FT_Done_Face(face); | 916 FT_Done_Face(face); |
910 FT_Done_FreeType(library); | 917 FT_Done_FreeType(library); |
911 return (SkTypeface::Style)style; | 918 return (SkTypeface::Style)style; |
912 } | 919 } |
913 | 920 |
OLD | NEW |