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), | |
230 m_FontCache(new CFX_FontCacheItem(this)), | |
227 m_pFontData(nullptr), | 231 m_pFontData(nullptr), |
228 m_pGsubData(nullptr), | 232 m_pGsubData(nullptr), |
229 m_dwSize(0), | 233 m_dwSize(0), |
230 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 234 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
231 m_pPlatformFont(nullptr), | 235 m_pPlatformFont(nullptr), |
232 #endif | 236 #endif |
233 m_bEmbedded(FALSE), | 237 m_bEmbedded(FALSE), |
234 m_bVertical(FALSE) { | 238 m_bVertical(FALSE) { |
235 } | 239 } |
236 | 240 |
(...skipping 18 matching lines...) Expand all Loading... | |
255 m_Face = pFont->m_Face; | 259 m_Face = pFont->m_Face; |
256 m_bEmbedded = pFont->m_bEmbedded; | 260 m_bEmbedded = pFont->m_bEmbedded; |
257 m_bVertical = pFont->m_bVertical; | 261 m_bVertical = pFont->m_bVertical; |
258 m_dwSize = pFont->m_dwSize; | 262 m_dwSize = pFont->m_dwSize; |
259 m_pFontData = pFont->m_pFontData; | 263 m_pFontData = pFont->m_pFontData; |
260 m_pGsubData = pFont->m_pGsubData; | 264 m_pGsubData = pFont->m_pGsubData; |
261 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 265 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
262 m_pPlatformFont = pFont->m_pPlatformFont; | 266 m_pPlatformFont = pFont->m_pPlatformFont; |
263 #endif | 267 #endif |
264 m_pOwnedStream = pFont->m_pOwnedStream; | 268 m_pOwnedStream = pFont->m_pOwnedStream; |
269 m_FaceCache = pFont->GetFaceCache(); | |
dsinclair
2016/09/14 17:51:50
What about m_FontCache?
snake
2016/09/14 19:06:29
m_FontCache it is just wrapper (which will never c
| |
265 return TRUE; | 270 return TRUE; |
266 } | 271 } |
267 #endif // PDF_ENABLE_XFA | 272 #endif // PDF_ENABLE_XFA |
268 | 273 |
269 CFX_Font::~CFX_Font() { | 274 CFX_Font::~CFX_Font() { |
270 #ifdef PDF_ENABLE_XFA | 275 #ifdef PDF_ENABLE_XFA |
271 if (m_bShallowCopy) { | 276 if (m_bShallowCopy) { |
272 m_OtfFontData.DetachBuffer(); | 277 m_OtfFontData.DetachBuffer(); |
273 return; | 278 return; |
274 } | 279 } |
275 #endif // PDF_ENABLE_XFA | 280 #endif // PDF_ENABLE_XFA |
276 if (m_Face) { | 281 if (m_Face) { |
277 #ifndef PDF_ENABLE_XFA | 282 #ifndef PDF_ENABLE_XFA |
278 if (FXFT_Get_Face_External_Stream(m_Face)) { | 283 if (FXFT_Get_Face_External_Stream(m_Face)) { |
279 FXFT_Clear_Face_External_Stream(m_Face); | 284 FXFT_Clear_Face_External_Stream(m_Face); |
280 } | 285 } |
281 #endif // PDF_ENABLE_XFA | 286 #endif // PDF_ENABLE_XFA |
282 if (m_bEmbedded) | 287 DeleteFace(); |
283 DeleteFace(); | |
284 else | |
285 CFX_GEModule::Get()->GetFontMgr()->ReleaseFace(m_Face); | |
286 } | 288 } |
287 #ifdef PDF_ENABLE_XFA | 289 #ifdef PDF_ENABLE_XFA |
288 delete m_pOwnedStream; | 290 delete m_pOwnedStream; |
289 #endif // PDF_ENABLE_XFA | 291 #endif // PDF_ENABLE_XFA |
290 FX_Free(m_pGsubData); | 292 FX_Free(m_pGsubData); |
291 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ && !defined _SKIA_SUPPORT_ | 293 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ && !defined _SKIA_SUPPORT_ |
292 ReleasePlatformResource(); | 294 ReleasePlatformResource(); |
293 #endif | 295 #endif |
294 } | 296 } |
295 | 297 |
296 void CFX_Font::DeleteFace() { | 298 void CFX_Font::DeleteFace() { |
297 FXFT_Done_Face(m_Face); | 299 ClearFaceCache(); |
300 if (m_bEmbedded) { | |
301 FXFT_Done_Face(m_Face); | |
302 } else { | |
303 CFX_GEModule::Get()->GetFontMgr()->ReleaseFace(m_Face); | |
304 } | |
298 m_Face = nullptr; | 305 m_Face = nullptr; |
299 } | 306 } |
300 | 307 |
301 void CFX_Font::LoadSubst(const CFX_ByteString& face_name, | 308 void CFX_Font::LoadSubst(const CFX_ByteString& face_name, |
302 FX_BOOL bTrueType, | 309 FX_BOOL bTrueType, |
303 uint32_t flags, | 310 uint32_t flags, |
304 int weight, | 311 int weight, |
305 int italic_angle, | 312 int italic_angle, |
306 int CharsetCP, | 313 int CharsetCP, |
307 FX_BOOL bVertical) { | 314 FX_BOOL bVertical) { |
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
530 } | 537 } |
531 | 538 |
532 int CFX_Font::GetMaxAdvanceWidth() const { | 539 int CFX_Font::GetMaxAdvanceWidth() const { |
533 if (!m_Face) | 540 if (!m_Face) |
534 return 0; | 541 return 0; |
535 | 542 |
536 return EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), | 543 return EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), |
537 FXFT_Get_Face_MaxAdvanceWidth(m_Face)); | 544 FXFT_Get_Face_MaxAdvanceWidth(m_Face)); |
538 } | 545 } |
539 | 546 |
547 CFX_FaceCache* CFX_Font::GetFaceCache() const { | |
548 if (!m_FaceCache) { | |
549 m_FaceCache = CFX_GEModule::Get()->GetFontCache()->GetCachedFace( | |
550 const_cast<CFX_Font*>(this)); | |
dsinclair
2016/09/14 17:51:50
We should remove the const from the signature inst
snake
2016/09/14 19:06:29
Done
| |
551 } | |
552 return m_FaceCache; | |
553 } | |
554 | |
555 void CFX_Font::ClearFaceCache() { | |
556 if (!m_FaceCache) | |
557 return; | |
558 CFX_GEModule::Get()->GetFontCache()->ReleaseCachedFace(this); | |
559 m_FaceCache = nullptr; | |
560 } | |
561 | |
540 int CFX_Font::GetULPos() const { | 562 int CFX_Font::GetULPos() const { |
541 if (!m_Face) | 563 if (!m_Face) |
542 return 0; | 564 return 0; |
543 | 565 |
544 return EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), | 566 return EM_ADJUST(FXFT_Get_Face_UnitsPerEM(m_Face), |
545 FXFT_Get_Face_UnderLinePosition(m_Face)); | 567 FXFT_Get_Face_UnderLinePosition(m_Face)); |
546 } | 568 } |
547 | 569 |
548 int CFX_Font::GetULthickness() const { | 570 int CFX_Font::GetULthickness() const { |
549 if (!m_Face) | 571 if (!m_Face) |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
655 params.m_pPoints = pPath->GetPoints(); | 677 params.m_pPoints = pPath->GetPoints(); |
656 params.m_CurX = params.m_CurY = 0; | 678 params.m_CurX = params.m_CurY = 0; |
657 params.m_CoordUnit = 64 * 64.0; | 679 params.m_CoordUnit = 64 * 64.0; |
658 FXFT_Outline_Decompose(FXFT_Get_Glyph_Outline(m_Face), &funcs, ¶ms); | 680 FXFT_Outline_Decompose(FXFT_Get_Glyph_Outline(m_Face), &funcs, ¶ms); |
659 Outline_CheckEmptyContour(¶ms); | 681 Outline_CheckEmptyContour(¶ms); |
660 pPath->TrimPoints(params.m_PointCount); | 682 pPath->TrimPoints(params.m_PointCount); |
661 if (params.m_PointCount) | 683 if (params.m_PointCount) |
662 pPath->GetPoints()[params.m_PointCount - 1].m_Flag |= FXPT_CLOSEFIGURE; | 684 pPath->GetPoints()[params.m_PointCount - 1].m_Flag |= FXPT_CLOSEFIGURE; |
663 return pPath; | 685 return pPath; |
664 } | 686 } |
687 | |
688 CFX_FontCacheItem::CFX_FontCacheItem(CFX_Font* font) : m_Font(font) {} | |
689 | |
690 CFX_FontCacheItem::~CFX_FontCacheItem() {} | |
691 | |
692 const CFX_GlyphBitmap* CFX_FontCacheItem::LoadGlyphBitmap( | |
693 uint32_t glyph_index, | |
694 FX_BOOL bFontStyle, | |
695 const CFX_Matrix* pMatrix, | |
696 int dest_width, | |
697 int anti_alias, | |
698 int& text_flags) const { | |
699 return m_Font->GetFaceCache()->LoadGlyphBitmap( | |
700 m_Font, glyph_index, bFontStyle, pMatrix, dest_width, anti_alias, | |
701 text_flags); | |
702 } | |
703 | |
704 const CFX_PathData* CFX_FontCacheItem::LoadGlyphPath(uint32_t glyph_index, | |
705 int dest_width) const { | |
706 return m_Font->GetFaceCache()->LoadGlyphPath(m_Font, glyph_index, dest_width); | |
707 } | |
708 | |
709 #ifdef _SKIA_SUPPORT_ | |
710 CFX_TypeFace* CFX_FontCacheItem::GetDeviceCache() const { | |
711 return m_Font->GetFaceCache()->GetDeviceCache(m_Font); | |
712 } | |
713 #endif | |
OLD | NEW |