| OLD | NEW |
| 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 "core/fxge/include/fx_font.h" | 7 #include "core/fxge/include/fx_font.h" |
| 8 | 8 |
| 9 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" | 9 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" |
| 10 #include "core/fxge/ge/fx_text_int.h" | 10 #include "core/fxge/ge/fx_text_int.h" |
| 11 #include "core/fxge/include/cfx_facecache.h" |
| 12 #include "core/fxge/include/cfx_fontcache.h" |
| 11 #include "core/fxge/include/cfx_fontmgr.h" | 13 #include "core/fxge/include/cfx_fontmgr.h" |
| 12 #include "core/fxge/include/cfx_gemodule.h" | 14 #include "core/fxge/include/cfx_gemodule.h" |
| 13 #include "core/fxge/include/cfx_pathdata.h" | 15 #include "core/fxge/include/cfx_pathdata.h" |
| 14 #include "core/fxge/include/cfx_substfont.h" | 16 #include "core/fxge/include/cfx_substfont.h" |
| 15 #include "core/fxge/include/fx_freetype.h" | 17 #include "core/fxge/include/fx_freetype.h" |
| 16 | 18 |
| 17 #define EM_ADJUST(em, a) (em == 0 ? (a) : (a)*1000 / em) | 19 #define EM_ADJUST(em, a) (em == 0 ? (a) : (a)*1000 / em) |
| 18 | 20 |
| 19 namespace { | 21 namespace { |
| 20 | 22 |
| (...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 217 59, 59, 59, 59, 59, 59, 59, 60, 60, 60, 60, 60, 60, 60, 60, | 219 59, 59, 59, 59, 59, 59, 59, 60, 60, 60, 60, 60, 60, 60, 60, |
| 218 }; | 220 }; |
| 219 | 221 |
| 220 CFX_Font::CFX_Font() | 222 CFX_Font::CFX_Font() |
| 221 : | 223 : |
| 222 #ifdef PDF_ENABLE_XFA | 224 #ifdef PDF_ENABLE_XFA |
| 223 m_bShallowCopy(false), | 225 m_bShallowCopy(false), |
| 224 m_pOwnedStream(nullptr), | 226 m_pOwnedStream(nullptr), |
| 225 #endif // PDF_ENABLE_XFA | 227 #endif // PDF_ENABLE_XFA |
| 226 m_Face(nullptr), | 228 m_Face(nullptr), |
| 229 m_FaceCache(nullptr), |
| 227 m_pFontData(nullptr), | 230 m_pFontData(nullptr), |
| 228 m_pGsubData(nullptr), | 231 m_pGsubData(nullptr), |
| 229 m_dwSize(0), | 232 m_dwSize(0), |
| 230 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 233 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
| 231 m_pPlatformFont(nullptr), | 234 m_pPlatformFont(nullptr), |
| 232 #endif | 235 #endif |
| 233 m_bEmbedded(FALSE), | 236 m_bEmbedded(FALSE), |
| 234 m_bVertical(FALSE) { | 237 m_bVertical(FALSE) { |
| 235 } | 238 } |
| 236 | 239 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 255 m_Face = pFont->m_Face; | 258 m_Face = pFont->m_Face; |
| 256 m_bEmbedded = pFont->m_bEmbedded; | 259 m_bEmbedded = pFont->m_bEmbedded; |
| 257 m_bVertical = pFont->m_bVertical; | 260 m_bVertical = pFont->m_bVertical; |
| 258 m_dwSize = pFont->m_dwSize; | 261 m_dwSize = pFont->m_dwSize; |
| 259 m_pFontData = pFont->m_pFontData; | 262 m_pFontData = pFont->m_pFontData; |
| 260 m_pGsubData = pFont->m_pGsubData; | 263 m_pGsubData = pFont->m_pGsubData; |
| 261 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 264 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
| 262 m_pPlatformFont = pFont->m_pPlatformFont; | 265 m_pPlatformFont = pFont->m_pPlatformFont; |
| 263 #endif | 266 #endif |
| 264 m_pOwnedStream = pFont->m_pOwnedStream; | 267 m_pOwnedStream = pFont->m_pOwnedStream; |
| 268 m_FaceCache = pFont->GetFaceCache(); |
| 265 return TRUE; | 269 return TRUE; |
| 266 } | 270 } |
| 271 |
| 272 void CFX_Font::SetFace(FXFT_Face face) { |
| 273 ClearFaceCache(); |
| 274 m_Face = face; |
| 275 } |
| 276 |
| 267 #endif // PDF_ENABLE_XFA | 277 #endif // PDF_ENABLE_XFA |
| 268 | 278 |
| 269 CFX_Font::~CFX_Font() { | 279 CFX_Font::~CFX_Font() { |
| 270 #ifdef PDF_ENABLE_XFA | 280 #ifdef PDF_ENABLE_XFA |
| 271 if (m_bShallowCopy) { | 281 if (m_bShallowCopy) { |
| 272 m_OtfFontData.DetachBuffer(); | 282 m_OtfFontData.DetachBuffer(); |
| 273 return; | 283 return; |
| 274 } | 284 } |
| 275 #endif // PDF_ENABLE_XFA | 285 #endif // PDF_ENABLE_XFA |
| 276 if (m_Face) { | 286 if (m_Face) { |
| 277 #ifndef PDF_ENABLE_XFA | 287 #ifndef PDF_ENABLE_XFA |
| 278 if (FXFT_Get_Face_External_Stream(m_Face)) { | 288 if (FXFT_Get_Face_External_Stream(m_Face)) { |
| 279 FXFT_Clear_Face_External_Stream(m_Face); | 289 FXFT_Clear_Face_External_Stream(m_Face); |
| 280 } | 290 } |
| 281 #endif // PDF_ENABLE_XFA | 291 #endif // PDF_ENABLE_XFA |
| 282 if (m_bEmbedded) | 292 DeleteFace(); |
| 283 DeleteFace(); | |
| 284 else | |
| 285 CFX_GEModule::Get()->GetFontMgr()->ReleaseFace(m_Face); | |
| 286 } | 293 } |
| 287 #ifdef PDF_ENABLE_XFA | 294 #ifdef PDF_ENABLE_XFA |
| 288 delete m_pOwnedStream; | 295 delete m_pOwnedStream; |
| 289 #endif // PDF_ENABLE_XFA | 296 #endif // PDF_ENABLE_XFA |
| 290 FX_Free(m_pGsubData); | 297 FX_Free(m_pGsubData); |
| 291 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ && !defined _SKIA_SUPPORT_ | 298 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ && !defined _SKIA_SUPPORT_ |
| 292 ReleasePlatformResource(); | 299 ReleasePlatformResource(); |
| 293 #endif | 300 #endif |
| 294 } | 301 } |
| 295 | 302 |
| 296 void CFX_Font::DeleteFace() { | 303 void CFX_Font::DeleteFace() { |
| 297 FXFT_Done_Face(m_Face); | 304 ClearFaceCache(); |
| 305 if (m_bEmbedded) { |
| 306 FXFT_Done_Face(m_Face); |
| 307 } else { |
| 308 CFX_GEModule::Get()->GetFontMgr()->ReleaseFace(m_Face); |
| 309 } |
| 298 m_Face = nullptr; | 310 m_Face = nullptr; |
| 299 } | 311 } |
| 300 | 312 |
| 301 void CFX_Font::LoadSubst(const CFX_ByteString& face_name, | 313 void CFX_Font::LoadSubst(const CFX_ByteString& face_name, |
| 302 FX_BOOL bTrueType, | 314 FX_BOOL bTrueType, |
| 303 uint32_t flags, | 315 uint32_t flags, |
| 304 int weight, | 316 int weight, |
| 305 int italic_angle, | 317 int italic_angle, |
| 306 int CharsetCP, | 318 int CharsetCP, |
| 307 FX_BOOL bVertical) { | 319 FX_BOOL bVertical) { |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 530 } | 542 } |
| 531 | 543 |
| 532 int CFX_Font::GetMaxAdvanceWidth() const { | 544 int CFX_Font::GetMaxAdvanceWidth() const { |
| 533 if (!m_Face) | 545 if (!m_Face) |
| 534 return 0; | 546 return 0; |
| 535 | 547 |
| 536 return EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), | 548 return EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), |
| 537 FXFT_Get_Face_MaxAdvanceWidth(m_Face)); | 549 FXFT_Get_Face_MaxAdvanceWidth(m_Face)); |
| 538 } | 550 } |
| 539 | 551 |
| 552 CFX_FaceCache* CFX_Font::GetFaceCache() const { |
| 553 if (!m_FaceCache) { |
| 554 m_FaceCache = CFX_GEModule::Get()->GetFontCache()->GetCachedFace(this); |
| 555 } |
| 556 return m_FaceCache; |
| 557 } |
| 558 |
| 559 void CFX_Font::ClearFaceCache() { |
| 560 if (!m_FaceCache) |
| 561 return; |
| 562 CFX_GEModule::Get()->GetFontCache()->ReleaseCachedFace(this); |
| 563 m_FaceCache = nullptr; |
| 564 } |
| 565 |
| 540 int CFX_Font::GetULPos() const { | 566 int CFX_Font::GetULPos() const { |
| 541 if (!m_Face) | 567 if (!m_Face) |
| 542 return 0; | 568 return 0; |
| 543 | 569 |
| 544 return EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), | 570 return EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), |
| 545 FXFT_Get_Face_UnderLinePosition(m_Face)); | 571 FXFT_Get_Face_UnderLinePosition(m_Face)); |
| 546 } | 572 } |
| 547 | 573 |
| 548 int CFX_Font::GetULthickness() const { | 574 int CFX_Font::GetULthickness() const { |
| 549 if (!m_Face) | 575 if (!m_Face) |
| 550 return 0; | 576 return 0; |
| 551 | 577 |
| 552 return EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), | 578 return EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), |
| 553 FXFT_Get_Face_UnderLineThickness(m_Face)); | 579 FXFT_Get_Face_UnderLineThickness(m_Face)); |
| 554 } | 580 } |
| 555 | 581 |
| 556 void CFX_Font::AdjustMMParams(int glyph_index, int dest_width, int weight) { | 582 void CFX_Font::AdjustMMParams(int glyph_index, |
| 583 int dest_width, |
| 584 int weight) const { |
| 557 FXFT_MM_Var pMasters = nullptr; | 585 FXFT_MM_Var pMasters = nullptr; |
| 558 FXFT_Get_MM_Var(m_Face, &pMasters); | 586 FXFT_Get_MM_Var(m_Face, &pMasters); |
| 559 if (!pMasters) | 587 if (!pMasters) |
| 560 return; | 588 return; |
| 561 long coords[2]; | 589 long coords[2]; |
| 562 if (weight == 0) | 590 if (weight == 0) |
| 563 coords[0] = FXFT_Get_MM_Axis_Def(FXFT_Get_MM_Axis(pMasters, 0)) / 65536; | 591 coords[0] = FXFT_Get_MM_Axis_Def(FXFT_Get_MM_Axis(pMasters, 0)) / 65536; |
| 564 else | 592 else |
| 565 coords[0] = weight; | 593 coords[0] = weight; |
| 566 if (dest_width == 0) { | 594 if (dest_width == 0) { |
| (...skipping 19 matching lines...) Expand all Loading... |
| 586 } | 614 } |
| 587 int param = min_param + | 615 int param = min_param + |
| 588 (max_param - min_param) * (dest_width - min_width) / | 616 (max_param - min_param) * (dest_width - min_width) / |
| 589 (max_width - min_width); | 617 (max_width - min_width); |
| 590 coords[1] = param; | 618 coords[1] = param; |
| 591 } | 619 } |
| 592 FXFT_Free(m_Face, pMasters); | 620 FXFT_Free(m_Face, pMasters); |
| 593 FXFT_Set_MM_Design_Coordinates(m_Face, 2, coords); | 621 FXFT_Set_MM_Design_Coordinates(m_Face, 2, coords); |
| 594 } | 622 } |
| 595 | 623 |
| 596 CFX_PathData* CFX_Font::LoadGlyphPath(uint32_t glyph_index, int dest_width) { | 624 CFX_PathData* CFX_Font::LoadGlyphPathImpl(uint32_t glyph_index, |
| 625 int dest_width) const { |
| 597 if (!m_Face) | 626 if (!m_Face) |
| 598 return nullptr; | 627 return nullptr; |
| 599 FXFT_Set_Pixel_Sizes(m_Face, 0, 64); | 628 FXFT_Set_Pixel_Sizes(m_Face, 0, 64); |
| 600 FXFT_Matrix ft_matrix = {65536, 0, 0, 65536}; | 629 FXFT_Matrix ft_matrix = {65536, 0, 0, 65536}; |
| 601 if (m_pSubstFont) { | 630 if (m_pSubstFont) { |
| 602 if (m_pSubstFont->m_ItalicAngle) { | 631 if (m_pSubstFont->m_ItalicAngle) { |
| 603 int skew = m_pSubstFont->m_ItalicAngle; | 632 int skew = m_pSubstFont->m_ItalicAngle; |
| 604 // |skew| is nonpositive so |-skew| is used as the index. We need to make | 633 // |skew| is nonpositive so |-skew| is used as the index. We need to make |
| 605 // sure |skew| != INT_MIN since -INT_MIN is undefined. | 634 // sure |skew| != INT_MIN since -INT_MIN is undefined. |
| 606 if (skew <= 0 && skew != std::numeric_limits<int>::min() && | 635 if (skew <= 0 && skew != std::numeric_limits<int>::min() && |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 655 params.m_pPoints = pPath->GetPoints(); | 684 params.m_pPoints = pPath->GetPoints(); |
| 656 params.m_CurX = params.m_CurY = 0; | 685 params.m_CurX = params.m_CurY = 0; |
| 657 params.m_CoordUnit = 64 * 64.0; | 686 params.m_CoordUnit = 64 * 64.0; |
| 658 FXFT_Outline_Decompose(FXFT_Get_Glyph_Outline(m_Face), &funcs, ¶ms); | 687 FXFT_Outline_Decompose(FXFT_Get_Glyph_Outline(m_Face), &funcs, ¶ms); |
| 659 Outline_CheckEmptyContour(¶ms); | 688 Outline_CheckEmptyContour(¶ms); |
| 660 pPath->TrimPoints(params.m_PointCount); | 689 pPath->TrimPoints(params.m_PointCount); |
| 661 if (params.m_PointCount) | 690 if (params.m_PointCount) |
| 662 pPath->GetPoints()[params.m_PointCount - 1].m_Flag |= FXPT_CLOSEFIGURE; | 691 pPath->GetPoints()[params.m_PointCount - 1].m_Flag |= FXPT_CLOSEFIGURE; |
| 663 return pPath; | 692 return pPath; |
| 664 } | 693 } |
| 694 |
| 695 const CFX_GlyphBitmap* CFX_Font::LoadGlyphBitmap(uint32_t glyph_index, |
| 696 FX_BOOL bFontStyle, |
| 697 const CFX_Matrix* pMatrix, |
| 698 int dest_width, |
| 699 int anti_alias, |
| 700 int& text_flags) const { |
| 701 return GetFaceCache()->LoadGlyphBitmap(this, glyph_index, bFontStyle, pMatrix, |
| 702 dest_width, anti_alias, text_flags); |
| 703 } |
| 704 |
| 705 const CFX_PathData* CFX_Font::LoadGlyphPath(uint32_t glyph_index, |
| 706 int dest_width) const { |
| 707 return GetFaceCache()->LoadGlyphPath(this, glyph_index, dest_width); |
| 708 } |
| 709 |
| 710 #ifdef _SKIA_SUPPORT_ |
| 711 CFX_TypeFace* CFX_Font::GetDeviceCache() const { |
| 712 return GetFaceCache()->GetDeviceCache(this); |
| 713 } |
| 714 #endif |
| OLD | NEW |