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

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

Issue 14759021: Use more fields from OutlineFontMEtrics: linegap, bbox. (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Created 7 years, 7 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 | Annotate | Revision Log
« 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 /* 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
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;
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 714 matching lines...) Expand 10 before | Expand all | Expand 10 after
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) {
838 // Note: This code was borrowed from generateLineHeight, which has a note 841 if (!(mx || my)) {
839 // stating that it may be incorrect.
840 if (!(mx || my))
841 return; 842 return;
843 }
844
845 if (mx) {
846 sk_bzero(mx, sizeof(*mx));
847 }
848 if (my) {
849 sk_bzero(my, sizeof(*my));
850 }
842 851
843 SkASSERT(fDDC); 852 SkASSERT(fDDC);
844 853
845 if (fType == SkScalerContext_Windows::kBitmap_Type) { 854 if (fType == SkScalerContext_Windows::kBitmap_Type) {
846 if (mx) { 855 if (mx) {
847 mx->fTop = SkIntToScalar(-fTM.tmAscent); 856 mx->fTop = SkIntToScalar(-fTM.tmAscent);
848 mx->fAscent = SkIntToScalar(-fTM.tmAscent); 857 mx->fAscent = SkIntToScalar(-fTM.tmAscent);
849 mx->fDescent = -SkIntToScalar(fTM.tmDescent); 858 mx->fDescent = -SkIntToScalar(fTM.tmDescent);
850 mx->fBottom = SkIntToScalar(fTM.tmDescent); 859 mx->fBottom = SkIntToScalar(fTM.tmDescent);
851 mx->fLeading = SkIntToScalar(fTM.tmInternalLeading 860 mx->fLeading = SkIntToScalar(fTM.tmExternalLeading);
852 + fTM.tmExternalLeading);
853 } 861 }
854 862
855 if (my) { 863 if (my) {
856 my->fTop = SkIntToScalar(-fTM.tmAscent); 864 my->fTop = SkIntToScalar(-fTM.tmAscent);
857 my->fAscent = SkIntToScalar(-fTM.tmAscent); 865 my->fAscent = SkIntToScalar(-fTM.tmAscent);
858 my->fDescent = SkIntToScalar(-fTM.tmDescent); 866 my->fDescent = SkIntToScalar(-fTM.tmDescent);
859 my->fBottom = SkIntToScalar(fTM.tmDescent); 867 my->fBottom = SkIntToScalar(fTM.tmDescent);
860 my->fLeading = SkIntToScalar(fTM.tmInternalLeading 868 my->fLeading = SkIntToScalar(fTM.tmExternalLeading);
bungeman-skia 2013/05/08 02:40:40 tmAveCharWidth is also available here. There is no
861 + fTM.tmExternalLeading);
862 } 869 }
863 return; 870 return;
864 } 871 }
865 872
866 OUTLINETEXTMETRIC otm; 873 OUTLINETEXTMETRIC otm;
867 874
868 uint32_t ret = GetOutlineTextMetrics(fDDC, sizeof(otm), &otm); 875 uint32_t ret = GetOutlineTextMetrics(fDDC, sizeof(otm), &otm);
869 if (GDI_ERROR == ret) { 876 if (GDI_ERROR == ret) {
870 LogFontTypeface::EnsureAccessible(this->getTypeface()); 877 LogFontTypeface::EnsureAccessible(this->getTypeface());
871 ret = GetOutlineTextMetrics(fDDC, sizeof(otm), &otm); 878 ret = GetOutlineTextMetrics(fDDC, sizeof(otm), &otm);
872 } 879 }
873 if (sizeof(otm) != ret) { 880 if (sizeof(otm) != ret) {
874 return; 881 return;
875 } 882 }
876 883
877 if (mx) { 884 if (mx) {
878 mx->fTop = -fScale * otm.otmTextMetrics.tmAscent; 885 mx->fTop = -fScale * otm.otmrcFontBox.left;
879 mx->fAscent = -fScale * otm.otmAscent; 886 mx->fAscent = -fScale * otm.otmAscent;
880 mx->fDescent = -fScale * otm.otmDescent; 887 mx->fDescent = -fScale * otm.otmDescent;
881 mx->fBottom = fScale * otm.otmTextMetrics.tmDescent; 888 mx->fBottom = fScale * otm.otmrcFontBox.right;
882 mx->fLeading = fScale * (otm.otmTextMetrics.tmInternalLeading 889 mx->fLeading = fScale * otm.otmLineGap;
883 + otm.otmTextMetrics.tmExternalLeading);
884 } 890 }
885 891
886 if (my) { 892 if (my) {
887 my->fTop = -fScale * otm.otmTextMetrics.tmAscent; 893 my->fTop = -fScale * otm.otmrcFontBox.top;
888 my->fAscent = -fScale * otm.otmAscent; 894 my->fAscent = -fScale * otm.otmAscent;
889 my->fDescent = -fScale * otm.otmDescent; 895 my->fDescent = -fScale * otm.otmDescent;
890 my->fBottom = fScale * otm.otmTextMetrics.tmDescent; 896 my->fBottom = fScale * otm.otmrcFontBox.bottom;
891 my->fLeading = fScale * (otm.otmTextMetrics.tmInternalLeading 897 my->fLeading = fScale * otm.otmLineGap;
892 + otm.otmTextMetrics.tmExternalLeading); 898 my->fAvgCharWidth = fScale * otm.otmTextMetrics.tmAveCharWidth;
899 my->fXHeight = fScale * otm.otmsXHeight;
893 } 900 }
894 } 901 }
895 902
896 //////////////////////////////////////////////////////////////////////////////// //////// 903 //////////////////////////////////////////////////////////////////////////////// ////////
897 904
898 static void build_power_table(uint8_t table[], float ee) { 905 static void build_power_table(uint8_t table[], float ee) {
899 for (int i = 0; i < 256; i++) { 906 for (int i = 0; i < 256; i++) {
900 float x = i / 255.f; 907 float x = i / 255.f;
901 x = sk_float_pow(x, ee); 908 x = sk_float_pow(x, ee);
902 int xx = SkScalarRound(SkFloatToScalar(x * 255)); 909 int xx = SkScalarRound(SkFloatToScalar(x * 255));
(...skipping 955 matching lines...) Expand 10 before | Expand all | Expand 10 after
1858 return this->createFromStream(stream); 1865 return this->createFromStream(stream);
1859 } 1866 }
1860 1867
1861 private: 1868 private:
1862 SkTDArray<ENUMLOGFONTEX> fLogFontArray; 1869 SkTDArray<ENUMLOGFONTEX> fLogFontArray;
1863 }; 1870 };
1864 1871
1865 SkFontMgr* SkFontMgr::Factory() { 1872 SkFontMgr* SkFontMgr::Factory() {
1866 return SkNEW(SkFontMgrGDI); 1873 return SkNEW(SkFontMgrGDI);
1867 } 1874 }
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