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

Side by Side Diff: xfa/fgas/font/fgas_gefont.cpp

Issue 2362063003: Clean up xfa_fontmgr.cpp. (Closed)
Patch Set: nits Created 4 years, 2 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
« no previous file with comments | « xfa/fgas/font/fgas_gefont.h ('k') | xfa/fgas/layout/fgas_rtfbreak.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "xfa/fgas/font/fgas_gefont.h" 7 #include "xfa/fgas/font/fgas_gefont.h"
8 8
9 #include <memory>
10 #include <utility>
11
9 #include "core/fxge/include/cfx_substfont.h" 12 #include "core/fxge/include/cfx_substfont.h"
10 #include "core/fxge/include/cfx_unicodeencoding.h" 13 #include "core/fxge/include/cfx_unicodeencoding.h"
11 #include "core/fxge/include/cfx_unicodeencodingex.h" 14 #include "core/fxge/include/cfx_unicodeencodingex.h"
12 #include "xfa/fgas/crt/fgas_codepage.h" 15 #include "xfa/fgas/crt/fgas_codepage.h"
13 #include "xfa/fgas/font/fgas_fontutils.h" 16 #include "xfa/fgas/font/fgas_fontutils.h"
14 #include "xfa/fxfa/include/xfa_fontmgr.h" 17 #include "xfa/fxfa/include/xfa_fontmgr.h"
15 18
16 // static 19 // static
17 CFGAS_GEFont* CFGAS_GEFont::LoadFont(const FX_WCHAR* pszFontFamily, 20 CFGAS_GEFont* CFGAS_GEFont::LoadFont(const FX_WCHAR* pszFontFamily,
18 uint32_t dwFontStyles, 21 uint32_t dwFontStyles,
19 uint16_t wCodePage, 22 uint16_t wCodePage,
20 IFGAS_FontMgr* pFontMgr) { 23 IFGAS_FontMgr* pFontMgr) {
21 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ 24 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
22 if (pFontMgr) { 25 if (pFontMgr)
23 return pFontMgr->GetFontByCodePage(wCodePage, dwFontStyles, pszFontFamily); 26 return pFontMgr->GetFontByCodePage(wCodePage, dwFontStyles, pszFontFamily);
24 }
25 return nullptr; 27 return nullptr;
26 #else 28 #else
27 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr); 29 CFGAS_GEFont* pFont = new CFGAS_GEFont(pFontMgr);
28 if (!pFont->LoadFontInternal(pszFontFamily, dwFontStyles, wCodePage)) { 30 if (!pFont->LoadFontInternal(pszFontFamily, dwFontStyles, wCodePage)) {
29 pFont->Release(); 31 pFont->Release();
30 return nullptr; 32 return nullptr;
31 } 33 }
32 return pFont; 34 return pFont;
33 #endif 35 #endif
34 } 36 }
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 wsFamily = CFX_WideString::FromLocal(m_pFont->GetFamilyName().AsStringC()); 279 wsFamily = CFX_WideString::FromLocal(m_pFont->GetFamilyName().AsStringC());
278 } else { 280 } else {
279 wsFamily = CFX_WideString::FromLocal( 281 wsFamily = CFX_WideString::FromLocal(
280 m_pFont->GetSubstFont()->m_Family.AsStringC()); 282 m_pFont->GetSubstFont()->m_Family.AsStringC());
281 } 283 }
282 } 284 }
283 285
284 uint32_t CFGAS_GEFont::GetFontStyles() const { 286 uint32_t CFGAS_GEFont::GetFontStyles() const {
285 ASSERT(m_pFont); 287 ASSERT(m_pFont);
286 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ 288 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_
287 if (m_bUseLogFontStyle) { 289 if (m_bUseLogFontStyle)
288 return m_dwLogFontStyle; 290 return m_dwLogFontStyle;
289 }
290 #endif 291 #endif
292
291 uint32_t dwStyles = 0; 293 uint32_t dwStyles = 0;
292 if (!m_pFont->GetSubstFont()) { 294 auto* pSubstFont = m_pFont->GetSubstFont();
293 if (m_pFont->IsBold()) { 295 if (pSubstFont) {
296 if (pSubstFont->m_Weight == FXFONT_FW_BOLD)
294 dwStyles |= FX_FONTSTYLE_Bold; 297 dwStyles |= FX_FONTSTYLE_Bold;
295 } 298 if (pSubstFont->m_SubstFlags & FXFONT_SUBST_ITALIC)
296 if (m_pFont->IsItalic()) {
297 dwStyles |= FX_FONTSTYLE_Italic; 299 dwStyles |= FX_FONTSTYLE_Italic;
298 }
299 } else { 300 } else {
300 if (m_pFont->GetSubstFont()->m_Weight == FXFONT_FW_BOLD) { 301 if (m_pFont->IsBold())
301 dwStyles |= FX_FONTSTYLE_Bold; 302 dwStyles |= FX_FONTSTYLE_Bold;
302 } 303 if (m_pFont->IsItalic())
303 if (m_pFont->GetSubstFont()->m_SubstFlags & FXFONT_SUBST_ITALIC) {
304 dwStyles |= FX_FONTSTYLE_Italic; 304 dwStyles |= FX_FONTSTYLE_Italic;
305 }
306 } 305 }
307 return dwStyles; 306 return dwStyles;
308 } 307 }
308
309 FX_BOOL CFGAS_GEFont::GetCharWidth(FX_WCHAR wUnicode, 309 FX_BOOL CFGAS_GEFont::GetCharWidth(FX_WCHAR wUnicode,
310 int32_t& iWidth, 310 int32_t& iWidth,
311 FX_BOOL bCharCode) { 311 bool bCharCode) {
312 return GetCharWidthInternal(wUnicode, iWidth, TRUE, bCharCode); 312 return GetCharWidthInternal(wUnicode, iWidth, true, bCharCode);
313 } 313 }
314
314 FX_BOOL CFGAS_GEFont::GetCharWidthInternal(FX_WCHAR wUnicode, 315 FX_BOOL CFGAS_GEFont::GetCharWidthInternal(FX_WCHAR wUnicode,
315 int32_t& iWidth, 316 int32_t& iWidth,
316 FX_BOOL bRecursive, 317 bool bRecursive,
317 FX_BOOL bCharCode) { 318 bool bCharCode) {
318 ASSERT(m_pCharWidthMap); 319 ASSERT(m_pCharWidthMap);
319 iWidth = m_pCharWidthMap->GetAt(wUnicode, 0); 320 iWidth = m_pCharWidthMap->GetAt(wUnicode, 0);
320 if (iWidth < 1) { 321 if (iWidth == 65535)
321 if (!m_pProvider || 322 return FALSE;
322 !m_pProvider->GetCharWidth(this, wUnicode, iWidth, bCharCode)) { 323
323 CFGAS_GEFont* pFont = nullptr; 324 if (iWidth > 0)
324 int32_t iGlyph = GetGlyphIndex(wUnicode, TRUE, &pFont, bCharCode); 325 return TRUE;
325 if (iGlyph != 0xFFFF && pFont) { 326
326 if (pFont == this) { 327 if (!m_pProvider ||
327 iWidth = m_pFont->GetGlyphWidth(iGlyph); 328 !m_pProvider->GetCharWidth(this, wUnicode, bCharCode, &iWidth)) {
328 if (iWidth < 0) { 329 CFGAS_GEFont* pFont = nullptr;
329 iWidth = -1; 330 int32_t iGlyph = GetGlyphIndex(wUnicode, TRUE, &pFont, bCharCode);
330 } 331 if (iGlyph != 0xFFFF && pFont) {
331 } else if (pFont->GetCharWidthInternal(wUnicode, iWidth, FALSE, 332 if (pFont == this) {
332 bCharCode)) { 333 iWidth = m_pFont->GetGlyphWidth(iGlyph);
333 return TRUE; 334 if (iWidth < 0) {
335 iWidth = -1;
334 } 336 }
335 } else { 337 } else if (pFont->GetCharWidthInternal(wUnicode, iWidth, false,
336 iWidth = -1; 338 bCharCode)) {
339 return TRUE;
337 } 340 }
341 } else {
342 iWidth = -1;
338 } 343 }
339 m_pCharWidthMap->SetAtGrow(wUnicode, (int16_t)iWidth);
340 } else if (iWidth == 65535) {
341 iWidth = -1;
342 } 344 }
345 m_pCharWidthMap->SetAtGrow(wUnicode, iWidth);
343 return iWidth > 0; 346 return iWidth > 0;
344 } 347 }
348
345 FX_BOOL CFGAS_GEFont::GetCharBBox(FX_WCHAR wUnicode, 349 FX_BOOL CFGAS_GEFont::GetCharBBox(FX_WCHAR wUnicode,
346 CFX_Rect& bbox, 350 CFX_Rect& bbox,
347 FX_BOOL bCharCode) { 351 FX_BOOL bCharCode) {
348 return GetCharBBoxInternal(wUnicode, bbox, TRUE, bCharCode); 352 return GetCharBBoxInternal(wUnicode, bbox, TRUE, bCharCode);
349 } 353 }
354
350 FX_BOOL CFGAS_GEFont::GetCharBBoxInternal(FX_WCHAR wUnicode, 355 FX_BOOL CFGAS_GEFont::GetCharBBoxInternal(FX_WCHAR wUnicode,
351 CFX_Rect& bbox, 356 CFX_Rect& bbox,
352 FX_BOOL bRecursive, 357 FX_BOOL bRecursive,
353 FX_BOOL bCharCode) { 358 FX_BOOL bCharCode) {
354 ASSERT(m_pRectArray); 359 ASSERT(m_pRectArray);
355 ASSERT(m_pBBoxMap); 360 ASSERT(m_pBBoxMap);
356 void* pRect = nullptr; 361 void* pRect = nullptr;
357 if (!m_pBBoxMap->Lookup((void*)(uintptr_t)wUnicode, pRect)) { 362 if (!m_pBBoxMap->Lookup((void*)(uintptr_t)wUnicode, pRect)) {
358 CFGAS_GEFont* pFont = nullptr; 363 CFGAS_GEFont* pFont = nullptr;
359 int32_t iGlyph = GetGlyphIndex(wUnicode, TRUE, &pFont, bCharCode); 364 int32_t iGlyph = GetGlyphIndex(wUnicode, TRUE, &pFont, bCharCode);
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
480 } 485 }
481 if (m_pRectArray) { 486 if (m_pRectArray) {
482 m_pRectArray->RemoveAll(FALSE); 487 m_pRectArray->RemoveAll(FALSE);
483 } 488 }
484 } 489 }
485 CFGAS_GEFont* CFGAS_GEFont::GetSubstFont(int32_t iGlyphIndex) const { 490 CFGAS_GEFont* CFGAS_GEFont::GetSubstFont(int32_t iGlyphIndex) const {
486 iGlyphIndex = ((uint32_t)iGlyphIndex) >> 24; 491 iGlyphIndex = ((uint32_t)iGlyphIndex) >> 24;
487 return iGlyphIndex == 0 ? const_cast<CFGAS_GEFont*>(this) 492 return iGlyphIndex == 0 ? const_cast<CFGAS_GEFont*>(this)
488 : m_SubstFonts[iGlyphIndex - 1]; 493 : m_SubstFonts[iGlyphIndex - 1];
489 } 494 }
OLDNEW
« no previous file with comments | « xfa/fgas/font/fgas_gefont.h ('k') | xfa/fgas/layout/fgas_rtfbreak.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698