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