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

Side by Side Diff: core/src/fxge/android/fpf_skiafont.cpp

Issue 1265503005: clang-format all pdfium code. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: sigh Created 5 years, 4 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
OLDNEW
1 // Copyright 2014 PDFium Authors. All rights reserved. 1 // Copyright 2014 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 6
7 #include "fx_fpf.h" 7 #include "fx_fpf.h"
8 #if _FX_OS_ == _FX_ANDROID_ 8 #if _FX_OS_ == _FX_ANDROID_
9 #include "fpf_skiafont.h" 9 #include "fpf_skiafont.h"
10 #include "fpf_skiafontmgr.h" 10 #include "fpf_skiafontmgr.h"
11 #define FPF_EM_ADJUST(em, a) (em == 0 ? (a) : (a) * 1000 / em) 11 #define FPF_EM_ADJUST(em, a) (em == 0 ? (a) : (a)*1000 / em)
12 CFPF_SkiaFont::CFPF_SkiaFont() 12 CFPF_SkiaFont::CFPF_SkiaFont()
13 : m_pFontMgr(NULL) 13 : m_pFontMgr(NULL),
14 , m_pFontDes(NULL) 14 m_pFontDes(NULL),
15 , m_Face(NULL) 15 m_Face(NULL),
16 , m_dwStyle(0) 16 m_dwStyle(0),
17 , m_uCharset(0) 17 m_uCharset(0),
18 , m_dwRefCount(0) 18 m_dwRefCount(0) {}
19 { 19 CFPF_SkiaFont::~CFPF_SkiaFont() {
20 } 20 if (m_Face) {
21 CFPF_SkiaFont::~CFPF_SkiaFont() 21 FXFT_Done_Face(m_Face);
22 { 22 }
23 if (m_Face) { 23 }
24 FXFT_Done_Face(m_Face); 24 void CFPF_SkiaFont::Release() {
25 if (--m_dwRefCount == 0) {
26 delete this;
27 }
28 }
29 IFPF_Font* CFPF_SkiaFont::Retain() {
30 m_dwRefCount++;
31 return (IFPF_Font*)this;
32 }
33 FPF_HFONT CFPF_SkiaFont::GetHandle() {
34 return NULL;
35 }
36 CFX_ByteString CFPF_SkiaFont::GetFamilyName() {
37 if (!m_Face) {
38 return CFX_ByteString();
39 }
40 return CFX_ByteString(FXFT_Get_Face_Family_Name(m_Face));
41 }
42 CFX_WideString CFPF_SkiaFont::GetPsName() {
43 if (!m_Face) {
44 return CFX_WideString();
45 }
46 return CFX_WideString::FromLocal(FXFT_Get_Postscript_Name(m_Face));
47 }
48 int32_t CFPF_SkiaFont::GetGlyphIndex(FX_WCHAR wUnicode) {
49 if (!m_Face) {
50 return wUnicode;
51 }
52 if (FXFT_Select_Charmap(m_Face, FXFT_ENCODING_UNICODE)) {
53 return 0;
54 }
55 return FXFT_Get_Char_Index(m_Face, wUnicode);
56 }
57 int32_t CFPF_SkiaFont::GetGlyphWidth(int32_t iGlyphIndex) {
58 if (!m_Face) {
59 return 0;
60 }
61 if (FXFT_Load_Glyph(
62 m_Face, iGlyphIndex,
63 FXFT_LOAD_NO_SCALE | FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH)) {
64 return 0;
65 }
66 return FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face),
67 FXFT_Get_Glyph_HoriAdvance(m_Face));
68 }
69 int32_t CFPF_SkiaFont::GetAscent() const {
70 if (!m_Face) {
71 return 0;
72 }
73 return FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face),
74 FXFT_Get_Face_Ascender(m_Face));
75 }
76 int32_t CFPF_SkiaFont::GetDescent() const {
77 if (!m_Face) {
78 return 0;
79 }
80 return FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face),
81 FXFT_Get_Face_Descender(m_Face));
82 }
83 FX_BOOL CFPF_SkiaFont::GetGlyphBBox(int32_t iGlyphIndex, FX_RECT& rtBBox) {
84 if (!m_Face) {
85 return FALSE;
86 }
87 if (FXFT_Is_Face_Tricky(m_Face)) {
88 if (FXFT_Set_Char_Size(m_Face, 0, 1000 * 64, 72, 72)) {
89 return FALSE;
25 } 90 }
26 } 91 if (FXFT_Load_Glyph(m_Face, iGlyphIndex,
27 void CFPF_SkiaFont::Release() 92 FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH)) {
28 { 93 FXFT_Set_Pixel_Sizes(m_Face, 0, 64);
29 if (--m_dwRefCount == 0) { 94 return FALSE;
30 delete this;
31 } 95 }
32 } 96 FXFT_Glyph glyph;
33 IFPF_Font* CFPF_SkiaFont::Retain() 97 if (FXFT_Get_Glyph(m_Face->glyph, &glyph)) {
34 { 98 FXFT_Set_Pixel_Sizes(m_Face, 0, 64);
35 m_dwRefCount++; 99 return FALSE;
36 return (IFPF_Font*)this;
37 }
38 FPF_HFONT CFPF_SkiaFont::GetHandle()
39 {
40 return NULL;
41 }
42 CFX_ByteString CFPF_SkiaFont::GetFamilyName()
43 {
44 if (!m_Face) {
45 return CFX_ByteString();
46 } 100 }
47 return CFX_ByteString(FXFT_Get_Face_Family_Name(m_Face)); 101 FXFT_BBox cbox;
48 } 102 FXFT_Glyph_Get_CBox(glyph, FXFT_GLYPH_BBOX_PIXELS, &cbox);
49 CFX_WideString CFPF_SkiaFont::GetPsName() 103 int32_t x_ppem = m_Face->size->metrics.x_ppem;
50 { 104 int32_t y_ppem = m_Face->size->metrics.y_ppem;
51 if (!m_Face) { 105 rtBBox.left = FPF_EM_ADJUST(x_ppem, cbox.xMin);
52 return CFX_WideString(); 106 rtBBox.right = FPF_EM_ADJUST(x_ppem, cbox.xMax);
53 } 107 rtBBox.top = FPF_EM_ADJUST(y_ppem, cbox.yMax);
54 return CFX_WideString::FromLocal(FXFT_Get_Postscript_Name(m_Face)); 108 rtBBox.bottom = FPF_EM_ADJUST(y_ppem, cbox.yMin);
55 } 109 rtBBox.top = FX_MIN(rtBBox.top, GetAscent());
56 int32_t CFPF_SkiaFont::GetGlyphIndex(FX_WCHAR wUnicode) 110 rtBBox.bottom = FX_MAX(rtBBox.bottom, GetDescent());
57 { 111 FXFT_Done_Glyph(glyph);
58 if (!m_Face) { 112 return FXFT_Set_Pixel_Sizes(m_Face, 0, 64) == 0;
59 return wUnicode; 113 }
60 } 114 if (FXFT_Load_Glyph(
61 if (FXFT_Select_Charmap(m_Face, FXFT_ENCODING_UNICODE)) { 115 m_Face, iGlyphIndex,
62 return 0; 116 FXFT_LOAD_NO_SCALE | FXFT_LOAD_IGNORE_GLOBAL_ADVANCE_WIDTH)) {
63 } 117 return FALSE;
64 return FXFT_Get_Char_Index(m_Face, wUnicode); 118 }
65 } 119 rtBBox.left = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face),
66 int32_t CFPF_SkiaFont::GetGlyphWidth(int32_t iGlyphIndex) 120 FXFT_Get_Glyph_HoriBearingX(m_Face));
67 { 121 rtBBox.bottom = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face),
68 if (!m_Face) { 122 FXFT_Get_Glyph_HoriBearingY(m_Face));
69 return 0; 123 rtBBox.right = FPF_EM_ADJUST(
70 } 124 FXFT_Get_Face_UnitsPerEM(m_Face),
71 if (FXFT_Load_Glyph(m_Face, iGlyphIndex, FXFT_LOAD_NO_SCALE | FXFT_LOAD_IGNO RE_GLOBAL_ADVANCE_WIDTH)) { 125 FXFT_Get_Glyph_HoriBearingX(m_Face) + FXFT_Get_Glyph_Width(m_Face));
72 return 0; 126 rtBBox.top = FPF_EM_ADJUST(
73 } 127 FXFT_Get_Face_UnitsPerEM(m_Face),
74 return FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Glyph_HoriAd vance(m_Face)); 128 FXFT_Get_Glyph_HoriBearingY(m_Face) - FXFT_Get_Glyph_Height(m_Face));
75 } 129 return TRUE;
76 int32_t CFPF_SkiaFont::GetAscent() const 130 }
77 { 131 FX_BOOL CFPF_SkiaFont::GetBBox(FX_RECT& rtBBox) {
78 if (!m_Face) { 132 if (!m_Face) {
79 return 0; 133 return FALSE;
80 } 134 }
81 return FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Face_Ascende r(m_Face)); 135 rtBBox.left = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face),
82 } 136 FXFT_Get_Face_xMin(m_Face));
83 int32_t CFPF_SkiaFont::GetDescent() const 137 rtBBox.top = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face),
84 { 138 FXFT_Get_Face_yMin(m_Face));
85 if (!m_Face) { 139 rtBBox.right = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face),
86 return 0; 140 FXFT_Get_Face_xMax(m_Face));
87 } 141 rtBBox.bottom = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face),
88 return FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Face_Descend er(m_Face)); 142 FXFT_Get_Face_yMax(m_Face));
89 } 143 return TRUE;
90 FX_BOOL CFPF_SkiaFont::GetGlyphBBox(int32_t iGlyphIndex, FX_RECT &rtBBox) 144 }
91 { 145 int32_t CFPF_SkiaFont::GetHeight() const {
92 if (!m_Face) { 146 if (!m_Face) {
93 return FALSE; 147 return 0;
94 } 148 }
95 if (FXFT_Is_Face_Tricky(m_Face)) { 149 return FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face),
96 if (FXFT_Set_Char_Size(m_Face, 0, 1000 * 64, 72, 72)) { 150 FXFT_Get_Face_Height(m_Face));
97 return FALSE; 151 }
98 } 152 int32_t CFPF_SkiaFont::GetItalicAngle() const {
99 if (FXFT_Load_Glyph(m_Face, iGlyphIndex, FXFT_LOAD_IGNORE_GLOBAL_ADVANCE _WIDTH)) { 153 if (!m_Face) {
100 FXFT_Set_Pixel_Sizes(m_Face, 0, 64); 154 return 0;
101 return FALSE; 155 }
102 } 156 TT_Postscript* ttInfo =
103 FXFT_Glyph glyph; 157 (TT_Postscript*)FT_Get_Sfnt_Table(m_Face, ft_sfnt_post);
104 if (FXFT_Get_Glyph(m_Face->glyph, &glyph)) { 158 if (ttInfo) {
105 FXFT_Set_Pixel_Sizes(m_Face, 0, 64); 159 return ttInfo->italicAngle;
106 return FALSE; 160 }
107 } 161 return 0;
108 FXFT_BBox cbox; 162 }
109 FXFT_Glyph_Get_CBox(glyph, FXFT_GLYPH_BBOX_PIXELS, &cbox); 163 FX_DWORD CFPF_SkiaFont::GetFontData(FX_DWORD dwTable,
110 int32_t x_ppem = m_Face->size->metrics.x_ppem; 164 uint8_t* pBuffer,
111 int32_t y_ppem = m_Face->size->metrics.y_ppem; 165 FX_DWORD dwSize) {
112 rtBBox.left = FPF_EM_ADJUST(x_ppem, cbox.xMin); 166 if (!m_Face) {
113 rtBBox.right = FPF_EM_ADJUST(x_ppem, cbox.xMax); 167 return 0;
114 rtBBox.top = FPF_EM_ADJUST(y_ppem, cbox.yMax); 168 }
115 rtBBox.bottom = FPF_EM_ADJUST(y_ppem, cbox.yMin); 169 FT_ULong ulSize = pdfium::base::checked_cast<FT_ULong>(dwSize);
116 rtBBox.top = FX_MIN(rtBBox.top, GetAscent()); 170 if (FXFT_Load_Sfnt_Table(m_Face, dwTable, 0, pBuffer, &ulSize)) {
117 rtBBox.bottom = FX_MAX(rtBBox.bottom, GetDescent()); 171 return 0;
118 FXFT_Done_Glyph(glyph); 172 }
119 return FXFT_Set_Pixel_Sizes(m_Face, 0, 64) == 0; 173 return pdfium::base::checked_cast<FX_DWORD>(ulSize);
120 } 174 }
121 if (FXFT_Load_Glyph(m_Face, iGlyphIndex, FXFT_LOAD_NO_SCALE | FXFT_LOAD_IGNO RE_GLOBAL_ADVANCE_WIDTH)) { 175 FX_BOOL CFPF_SkiaFont::InitFont(CFPF_SkiaFontMgr* pFontMgr,
122 return FALSE; 176 CFPF_SkiaFontDescriptor* pFontDes,
123 } 177 const CFX_ByteStringC& bsFamily,
124 rtBBox.left = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Glyph _HoriBearingX(m_Face)); 178 FX_DWORD dwStyle,
125 rtBBox.bottom = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Gly ph_HoriBearingY(m_Face)); 179 uint8_t uCharset) {
126 rtBBox.right = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Glyp h_HoriBearingX(m_Face) + FXFT_Get_Glyph_Width(m_Face)); 180 if (!pFontMgr || !pFontDes) {
127 rtBBox.top = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Glyph_ HoriBearingY(m_Face) - FXFT_Get_Glyph_Height(m_Face)); 181 return FALSE;
128 return TRUE; 182 }
129 } 183 switch (pFontDes->GetType()) {
130 FX_BOOL CFPF_SkiaFont::GetBBox(FX_RECT &rtBBox) 184 case FPF_SKIAFONTTYPE_Path: {
131 { 185 CFPF_SkiaPathFont* pFont = (CFPF_SkiaPathFont*)pFontDes;
132 if (!m_Face) { 186 m_Face = pFontMgr->GetFontFace(pFont->m_pPath, pFont->m_iFaceIndex);
133 return FALSE; 187 } break;
134 } 188 case FPF_SKIAFONTTYPE_File: {
135 rtBBox.left = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Face_ xMin(m_Face)); 189 CFPF_SkiaFileFont* pFont = (CFPF_SkiaFileFont*)pFontDes;
136 rtBBox.top = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Face_y Min(m_Face)); 190 m_Face = pFontMgr->GetFontFace(pFont->m_pFile, pFont->m_iFaceIndex);
137 rtBBox.right = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Face _xMax(m_Face)); 191 } break;
138 rtBBox.bottom = FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Fac e_yMax(m_Face)); 192 case FPF_SKIAFONTTYPE_Buffer: {
139 return TRUE; 193 CFPF_SkiaBufferFont* pFont = (CFPF_SkiaBufferFont*)pFontDes;
140 } 194 m_Face = pFontMgr->GetFontFace((const uint8_t*)pFont->m_pBuffer,
141 int32_t CFPF_SkiaFont::GetHeight() const 195 pFont->m_szBuffer, pFont->m_iFaceIndex);
142 { 196 } break;
143 if (!m_Face) { 197 default:
144 return 0; 198 return FALSE;
145 } 199 }
146 return» FPF_EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), FXFT_Get_Face_He ight(m_Face)); 200 if (!m_Face) {
147 } 201 return FALSE;
148 int32_t CFPF_SkiaFont::GetItalicAngle() const 202 }
149 { 203 m_dwStyle = dwStyle;
150 if (!m_Face) { 204 m_uCharset = uCharset;
151 return 0; 205 m_pFontMgr = pFontMgr;
152 } 206 m_pFontDes = pFontDes;
153 TT_Postscript *ttInfo = (TT_Postscript*)FT_Get_Sfnt_Table(m_Face, ft_sfnt_po st); 207 m_dwRefCount = 1;
154 if (ttInfo) { 208 return TRUE;
155 return ttInfo->italicAngle;
156 }
157 return 0;
158 }
159 FX_DWORD CFPF_SkiaFont::GetFontData(FX_DWORD dwTable, uint8_t* pBuffer, FX_DWORD dwSize)
160 {
161 if (!m_Face) {
162 return 0;
163 }
164 FT_ULong ulSize = pdfium::base::checked_cast<FT_ULong>(dwSize);
165 if (FXFT_Load_Sfnt_Table(m_Face, dwTable, 0, pBuffer, &ulSize)) {
166 return 0;
167 }
168 return pdfium::base::checked_cast<FX_DWORD>(ulSize);
169 }
170 FX_BOOL CFPF_SkiaFont::InitFont(CFPF_SkiaFontMgr *pFontMgr, CFPF_SkiaFontDescrip tor *pFontDes, const CFX_ByteStringC& bsFamily, FX_DWORD dwStyle, uint8_t uChars et)
171 {
172 if (!pFontMgr || !pFontDes) {
173 return FALSE;
174 }
175 switch (pFontDes->GetType()) {
176 case FPF_SKIAFONTTYPE_Path: {
177 CFPF_SkiaPathFont *pFont = (CFPF_SkiaPathFont*)pFontDes;
178 m_Face = pFontMgr->GetFontFace(pFont->m_pPath, pFont->m_iFaceInd ex);
179 }
180 break;
181 case FPF_SKIAFONTTYPE_File: {
182 CFPF_SkiaFileFont *pFont = (CFPF_SkiaFileFont*)pFontDes;
183 m_Face = pFontMgr->GetFontFace(pFont->m_pFile, pFont->m_iFaceInd ex);
184 }
185 break;
186 case FPF_SKIAFONTTYPE_Buffer: {
187 CFPF_SkiaBufferFont *pFont = (CFPF_SkiaBufferFont*)pFontDes;
188 m_Face = pFontMgr->GetFontFace((const uint8_t*)pFont->m_pBuffer, pFont->m_szBuffer, pFont->m_iFaceIndex);
189 }
190 break;
191 default:
192 return FALSE;
193 }
194 if (!m_Face) {
195 return FALSE;
196 }
197 m_dwStyle = dwStyle;
198 m_uCharset = uCharset;
199 m_pFontMgr = pFontMgr;
200 m_pFontDes = pFontDes;
201 m_dwRefCount = 1;
202 return TRUE;
203 } 209 }
204 #endif 210 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698