OLD | NEW |
---|---|
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 #include "SkAdvancedTypefaceMetrics.h" | 9 #include "SkAdvancedTypefaceMetrics.h" |
10 #include "SkBase64.h" | 10 #include "SkBase64.h" |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
92 using namespace skia_advanced_typeface_metrics_utils; | 92 using namespace skia_advanced_typeface_metrics_utils; |
93 | 93 |
94 static const uint16_t BUFFERSIZE = (16384 - 32); | 94 static const uint16_t BUFFERSIZE = (16384 - 32); |
95 static uint8_t glyphbuf[BUFFERSIZE]; | 95 static uint8_t glyphbuf[BUFFERSIZE]; |
96 | 96 |
97 /** | 97 /** |
98 * Since LOGFONT wants its textsize as an int, and we support fractional sizes, | 98 * Since LOGFONT wants its textsize as an int, and we support fractional sizes, |
99 * and since we have a cache of LOGFONTs for our tyepfaces, we always set the | 99 * and since we have a cache of LOGFONTs for our tyepfaces, we always set the |
100 * lfHeight to a canonical size, and then we use the 2x2 matrix to achieve the | 100 * lfHeight to a canonical size, and then we use the 2x2 matrix to achieve the |
101 * actual requested size. | 101 * actual requested size. |
102 * | |
103 * Not critical to match the font's upem, but we want it big enough to avoid | |
104 * precision loss for GDI calls that return ints (e.g. GetOutlineFontMetrics). | |
102 */ | 105 */ |
103 static const int gCanonicalTextSize = 64; | 106 static const int gCanonicalTextSize = 2048; |
bungeman-skia
2013/05/07 19:56:08
Ick! Ah well, it used to be the magic number 64, t
| |
104 | 107 |
105 static void tchar_to_skstring(const TCHAR t[], SkString* s) { | 108 static void tchar_to_skstring(const TCHAR t[], SkString* s) { |
106 #ifdef UNICODE | 109 #ifdef UNICODE |
107 size_t sSize = WideCharToMultiByte(CP_UTF8, 0, t, -1, NULL, 0, NULL, NULL); | 110 size_t sSize = WideCharToMultiByte(CP_UTF8, 0, t, -1, NULL, 0, NULL, NULL); |
108 s->resize(sSize); | 111 s->resize(sSize); |
109 WideCharToMultiByte(CP_UTF8, 0, t, -1, s->writable_str(), sSize, NULL, NULL) ; | 112 WideCharToMultiByte(CP_UTF8, 0, t, -1, s->writable_str(), sSize, NULL, NULL) ; |
110 #else | 113 #else |
111 s->set(t); | 114 s->set(t); |
112 #endif | 115 #endif |
113 } | 116 } |
(...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
827 if (GDI_ERROR != status) { | 830 if (GDI_ERROR != status) { |
828 SkPoint advance; | 831 SkPoint advance; |
829 fHiResMatrix.mapXY(SkIntToScalar(gm.gmCellIncX), SkIntToScalar(gm.gm CellIncY), &advance); | 832 fHiResMatrix.mapXY(SkIntToScalar(gm.gmCellIncX), SkIntToScalar(gm.gm CellIncY), &advance); |
830 glyph->fAdvanceX = SkScalarToFixed(advance.fX); | 833 glyph->fAdvanceX = SkScalarToFixed(advance.fX); |
831 glyph->fAdvanceY = SkScalarToFixed(advance.fY); | 834 glyph->fAdvanceY = SkScalarToFixed(advance.fY); |
832 } | 835 } |
833 SelectObject(fDDC, fFont); | 836 SelectObject(fDDC, fFont); |
834 } | 837 } |
835 } | 838 } |
836 | 839 |
837 void SkScalerContext_Windows::generateFontMetrics(SkPaint::FontMetrics* mx, SkPa int::FontMetrics* my) { | 840 void SkScalerContext_Windows::generateFontMetrics(SkPaint::FontMetrics* mx, SkPa int::FontMetrics* my) { |
bungeman-skia
2013/05/07 19:56:08
Just wanted to comment here so we don't forget. Ha
reed1
2013/05/07 21:04:49
That CL is on the way
| |
838 // Note: This code was borrowed from generateLineHeight, which has a note | 841 // Note: This code was borrowed from generateLineHeight, which has a note |
bungeman-skia
2013/05/07 19:56:08
Now that there is nothing left of the original cod
reed1
2013/05/07 21:04:49
Done.
| |
839 // stating that it may be incorrect. | 842 // stating that it may be incorrect. |
840 if (!(mx || my)) | 843 if (!(mx || my)) |
841 return; | 844 return; |
842 | 845 |
846 if (mx) { | |
847 sk_bzero(mx, sizeof(*mx)); | |
848 } | |
849 if (my) { | |
850 sk_bzero(my, sizeof(*my)); | |
851 } | |
852 | |
843 SkASSERT(fDDC); | 853 SkASSERT(fDDC); |
844 | 854 |
845 if (fType == SkScalerContext_Windows::kBitmap_Type) { | 855 if (fType == SkScalerContext_Windows::kBitmap_Type) { |
846 if (mx) { | 856 if (mx) { |
847 mx->fTop = SkIntToScalar(-fTM.tmAscent); | 857 mx->fTop = SkIntToScalar(-fTM.tmAscent); |
848 mx->fAscent = SkIntToScalar(-fTM.tmAscent); | 858 mx->fAscent = SkIntToScalar(-fTM.tmAscent); |
849 mx->fDescent = -SkIntToScalar(fTM.tmDescent); | 859 mx->fDescent = -SkIntToScalar(fTM.tmDescent); |
850 mx->fBottom = SkIntToScalar(fTM.tmDescent); | 860 mx->fBottom = SkIntToScalar(fTM.tmDescent); |
851 mx->fLeading = SkIntToScalar(fTM.tmInternalLeading | 861 mx->fLeading = SkIntToScalar(fTM.tmExternalLeading); |
852 + fTM.tmExternalLeading); | |
853 } | 862 } |
854 | 863 |
855 if (my) { | 864 if (my) { |
856 my->fTop = SkIntToScalar(-fTM.tmAscent); | 865 my->fTop = SkIntToScalar(-fTM.tmAscent); |
857 my->fAscent = SkIntToScalar(-fTM.tmAscent); | 866 my->fAscent = SkIntToScalar(-fTM.tmAscent); |
858 my->fDescent = SkIntToScalar(-fTM.tmDescent); | 867 my->fDescent = SkIntToScalar(-fTM.tmDescent); |
859 my->fBottom = SkIntToScalar(fTM.tmDescent); | 868 my->fBottom = SkIntToScalar(fTM.tmDescent); |
860 my->fLeading = SkIntToScalar(fTM.tmInternalLeading | 869 my->fLeading = SkIntToScalar(fTM.tmExternalLeading); |
861 + fTM.tmExternalLeading); | |
862 } | 870 } |
863 return; | 871 return; |
864 } | 872 } |
865 | 873 |
866 OUTLINETEXTMETRIC otm; | 874 OUTLINETEXTMETRIC otm; |
867 | 875 |
868 uint32_t ret = GetOutlineTextMetrics(fDDC, sizeof(otm), &otm); | 876 uint32_t ret = GetOutlineTextMetrics(fDDC, sizeof(otm), &otm); |
869 if (GDI_ERROR == ret) { | 877 if (GDI_ERROR == ret) { |
870 LogFontTypeface::EnsureAccessible(this->getTypeface()); | 878 LogFontTypeface::EnsureAccessible(this->getTypeface()); |
871 ret = GetOutlineTextMetrics(fDDC, sizeof(otm), &otm); | 879 ret = GetOutlineTextMetrics(fDDC, sizeof(otm), &otm); |
872 } | 880 } |
873 if (sizeof(otm) != ret) { | 881 if (sizeof(otm) != ret) { |
874 return; | 882 return; |
875 } | 883 } |
876 | 884 |
877 if (mx) { | 885 if (mx) { |
878 mx->fTop = -fScale * otm.otmTextMetrics.tmAscent; | 886 mx->fTop = -fScale * otm.otmrcFontBox.left; |
879 mx->fAscent = -fScale * otm.otmAscent; | 887 mx->fAscent = -fScale * otm.otmAscent; |
880 mx->fDescent = -fScale * otm.otmDescent; | 888 mx->fDescent = -fScale * otm.otmDescent; |
881 mx->fBottom = fScale * otm.otmTextMetrics.tmDescent; | 889 mx->fBottom = fScale * otm.otmrcFontBox.right; |
882 mx->fLeading = fScale * (otm.otmTextMetrics.tmInternalLeading | 890 mx->fLeading = fScale * otm.otmLineGap; |
883 + otm.otmTextMetrics.tmExternalLeading); | |
884 } | 891 } |
885 | 892 |
886 if (my) { | 893 if (my) { |
887 my->fTop = -fScale * otm.otmTextMetrics.tmAscent; | 894 my->fTop = -fScale * otm.otmrcFontBox.top; |
888 my->fAscent = -fScale * otm.otmAscent; | 895 my->fAscent = -fScale * otm.otmAscent; |
bungeman-skia
2013/05/07 19:56:08
This ascent, descent, and leading look like they m
reed1
2013/05/07 21:04:49
x-height and avecharwidth -- done
SkFontMetrics d
| |
889 my->fDescent = -fScale * otm.otmDescent; | 896 my->fDescent = -fScale * otm.otmDescent; |
890 my->fBottom = fScale * otm.otmTextMetrics.tmDescent; | 897 my->fBottom = fScale * otm.otmrcFontBox.bottom; |
891 my->fLeading = fScale * (otm.otmTextMetrics.tmInternalLeading | 898 my->fLeading = fScale * otm.otmLineGap; |
892 + otm.otmTextMetrics.tmExternalLeading); | |
893 } | 899 } |
894 } | 900 } |
895 | 901 |
896 //////////////////////////////////////////////////////////////////////////////// //////// | 902 //////////////////////////////////////////////////////////////////////////////// //////// |
897 | 903 |
898 static void build_power_table(uint8_t table[], float ee) { | 904 static void build_power_table(uint8_t table[], float ee) { |
899 for (int i = 0; i < 256; i++) { | 905 for (int i = 0; i < 256; i++) { |
900 float x = i / 255.f; | 906 float x = i / 255.f; |
901 x = sk_float_pow(x, ee); | 907 x = sk_float_pow(x, ee); |
902 int xx = SkScalarRound(SkFloatToScalar(x * 255)); | 908 int xx = SkScalarRound(SkFloatToScalar(x * 255)); |
(...skipping 955 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1858 return this->createFromStream(stream); | 1864 return this->createFromStream(stream); |
1859 } | 1865 } |
1860 | 1866 |
1861 private: | 1867 private: |
1862 SkTDArray<ENUMLOGFONTEX> fLogFontArray; | 1868 SkTDArray<ENUMLOGFONTEX> fLogFontArray; |
1863 }; | 1869 }; |
1864 | 1870 |
1865 SkFontMgr* SkFontMgr::Factory() { | 1871 SkFontMgr* SkFontMgr::Factory() { |
1866 return SkNEW(SkFontMgrGDI); | 1872 return SkNEW(SkFontMgrGDI); |
1867 } | 1873 } |
OLD | NEW |