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/fpdfapi/fpdf_render/render_int.h" | 7 #include "core/fpdfapi/fpdf_render/render_int.h" |
8 | 8 |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 353 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
364 : m_dwCount(0), m_pType3Font(pType3Font) {} | 364 : m_dwCount(0), m_pType3Font(pType3Font) {} |
365 ~CPDF_RefType3Cache() { | 365 ~CPDF_RefType3Cache() { |
366 while (m_dwCount--) { | 366 while (m_dwCount--) { |
367 ReleaseCachedType3(m_pType3Font); | 367 ReleaseCachedType3(m_pType3Font); |
368 } | 368 } |
369 } | 369 } |
370 uint32_t m_dwCount; | 370 uint32_t m_dwCount; |
371 CPDF_Type3Font* const m_pType3Font; | 371 CPDF_Type3Font* const m_pType3Font; |
372 }; | 372 }; |
373 | 373 |
374 // TODO(npm) Font fallback for type 3 fonts? (Completely separate code!!) | |
374 FX_BOOL CPDF_RenderStatus::ProcessType3Text(const CPDF_TextObject* textobj, | 375 FX_BOOL CPDF_RenderStatus::ProcessType3Text(const CPDF_TextObject* textobj, |
375 const CFX_Matrix* pObj2Device) { | 376 const CFX_Matrix* pObj2Device) { |
376 CPDF_Type3Font* pType3Font = textobj->m_TextState.GetFont()->AsType3Font(); | 377 CPDF_Type3Font* pType3Font = textobj->m_TextState.GetFont()->AsType3Font(); |
377 for (int i = 0; i < m_Type3FontCache.GetSize(); ++i) { | 378 for (int i = 0; i < m_Type3FontCache.GetSize(); ++i) { |
378 if (m_Type3FontCache.GetAt(i) == pType3Font) | 379 if (m_Type3FontCache.GetAt(i) == pType3Font) |
379 return TRUE; | 380 return TRUE; |
380 } | 381 } |
381 | 382 |
382 CFX_Matrix dCTM = m_pDevice->GetCTM(); | 383 CFX_Matrix dCTM = m_pDevice->GetCTM(); |
383 FX_FLOAT sa = FXSYS_fabs(dCTM.a); | 384 FX_FLOAT sa = FXSYS_fabs(dCTM.a); |
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
553 | 554 |
554 void CPDF_CharPosList::Load(int nChars, | 555 void CPDF_CharPosList::Load(int nChars, |
555 uint32_t* pCharCodes, | 556 uint32_t* pCharCodes, |
556 FX_FLOAT* pCharPos, | 557 FX_FLOAT* pCharPos, |
557 CPDF_Font* pFont, | 558 CPDF_Font* pFont, |
558 FX_FLOAT FontSize) { | 559 FX_FLOAT FontSize) { |
559 m_pCharPos = FX_Alloc(FXTEXT_CHARPOS, nChars); | 560 m_pCharPos = FX_Alloc(FXTEXT_CHARPOS, nChars); |
560 m_nChars = 0; | 561 m_nChars = 0; |
561 CPDF_CIDFont* pCIDFont = pFont->AsCIDFont(); | 562 CPDF_CIDFont* pCIDFont = pFont->AsCIDFont(); |
562 FX_BOOL bVertWriting = pCIDFont && pCIDFont->IsVertWriting(); | 563 FX_BOOL bVertWriting = pCIDFont && pCIDFont->IsVertWriting(); |
564 if (pFont->m_FontPlusFallbacks.size() == 0) | |
565 pFont->m_FontPlusFallbacks.push_back(&pFont->m_Font); | |
dsinclair
2016/08/23 19:41:18
Actually, can you just remove this font from the l
npm
2016/08/23 20:36:57
Done.
| |
563 for (int iChar = 0; iChar < nChars; iChar++) { | 566 for (int iChar = 0; iChar < nChars; iChar++) { |
564 uint32_t CharCode = | 567 uint32_t CharCode = |
565 nChars == 1 ? (uint32_t)(uintptr_t)pCharCodes : pCharCodes[iChar]; | 568 nChars == 1 ? (uint32_t)(uintptr_t)pCharCodes : pCharCodes[iChar]; |
566 if (CharCode == (uint32_t)-1) { | 569 if (CharCode == (uint32_t)-1) { |
567 continue; | 570 continue; |
568 } | 571 } |
569 bool bVert = false; | 572 bool bVert = false; |
570 FXTEXT_CHARPOS& charpos = m_pCharPos[m_nChars++]; | 573 FXTEXT_CHARPOS& charpos = m_pCharPos[m_nChars++]; |
571 if (pCIDFont) { | 574 if (pCIDFont) { |
572 charpos.m_bFontStyle = true; | 575 charpos.m_bFontStyle = true; |
573 } | 576 } |
574 charpos.m_GlyphIndex = pFont->GlyphFromCharCode(CharCode, &bVert); | 577 charpos.m_GlyphIndex = pFont->GlyphFromCharCode(CharCode, &bVert); |
578 if (charpos.m_GlyphIndex != (uint32_t)-1) { | |
dsinclair
2016/08/23 19:41:18
static_cast<uint32_t>(-1)
npm
2016/08/23 20:36:57
Done.
| |
579 charpos.m_FallbackFontPosition = 0; | |
580 } else { | |
581 charpos.m_FallbackFontPosition = | |
582 pFont->FallbackFontFromCharcode(CharCode, &bVert); | |
583 if (charpos.m_FallbackFontPosition > 0) { | |
584 charpos.m_GlyphIndex = pFont->FallbackGlyphFromCharcode( | |
585 charpos.m_FallbackFontPosition, CharCode, &bVert); | |
586 } | |
587 } | |
588 // TODO(npm) Figure out how this affects m_ExtGID | |
575 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 589 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
576 charpos.m_ExtGID = pFont->GlyphFromCharCodeExt(CharCode); | 590 charpos.m_ExtGID = pFont->GlyphFromCharCodeExt(CharCode); |
577 #endif | 591 #endif |
578 if (!pFont->IsEmbedded() && !pFont->IsCIDFont()) { | 592 if (!pFont->IsEmbedded() && !pFont->IsCIDFont()) { |
579 charpos.m_FontCharWidth = pFont->GetCharWidthF(CharCode); | 593 charpos.m_FontCharWidth = pFont->GetCharWidthF(CharCode); |
580 } else { | 594 } else { |
581 charpos.m_FontCharWidth = 0; | 595 charpos.m_FontCharWidth = 0; |
582 } | 596 } |
583 charpos.m_OriginX = iChar ? pCharPos[iChar - 1] : 0; | 597 charpos.m_OriginX = iChar ? pCharPos[iChar - 1] : 0; |
584 charpos.m_OriginY = 0; | 598 charpos.m_OriginY = 0; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
622 const CFX_GraphStateData* pGraphState, | 636 const CFX_GraphStateData* pGraphState, |
623 FX_ARGB fill_argb, | 637 FX_ARGB fill_argb, |
624 FX_ARGB stroke_argb, | 638 FX_ARGB stroke_argb, |
625 CFX_PathData* pClippingPath, | 639 CFX_PathData* pClippingPath, |
626 int nFlag) { | 640 int nFlag) { |
627 CFX_FontCache* pCache = | 641 CFX_FontCache* pCache = |
628 pFont->m_pDocument ? pFont->m_pDocument->GetRenderData()->GetFontCache() | 642 pFont->m_pDocument ? pFont->m_pDocument->GetRenderData()->GetFontCache() |
629 : nullptr; | 643 : nullptr; |
630 CPDF_CharPosList CharPosList; | 644 CPDF_CharPosList CharPosList; |
631 CharPosList.Load(nChars, pCharCodes, pCharPos, pFont, font_size); | 645 CharPosList.Load(nChars, pCharCodes, pCharPos, pFont, font_size); |
632 return pDevice->DrawTextPathWithFlags( | 646 FX_BOOL bDraw = TRUE; |
633 CharPosList.m_nChars, CharPosList.m_pCharPos, &pFont->m_Font, pCache, | 647 uint32_t pFontPosition = CharPosList.m_pCharPos[0].m_FallbackFontPosition; |
dsinclair
2016/08/23 19:41:18
This bit would have to become a bit smarter to han
npm
2016/08/23 20:36:57
Done.
| |
634 font_size, pText2User, pUser2Device, pGraphState, fill_argb, stroke_argb, | 648 uint32_t pStartIndex = 0; |
635 pClippingPath, nFlag); | 649 for (uint32_t i = 0; i < CharPosList.m_nChars; i++) { |
650 uint32_t pCurFontPosition = | |
651 CharPosList.m_pCharPos[i].m_FallbackFontPosition; | |
652 if (pFontPosition != pCurFontPosition) { | |
653 bDraw &= pDevice->DrawTextPathWithFlags( | |
654 i - pStartIndex, CharPosList.m_pCharPos + pStartIndex, | |
655 pFont->m_FontPlusFallbacks[pFontPosition], pCache, font_size, | |
656 pText2User, pUser2Device, pGraphState, fill_argb, stroke_argb, | |
657 pClippingPath, nFlag); | |
658 pFontPosition = pCurFontPosition; | |
659 pStartIndex = i; | |
660 } | |
661 } | |
662 bDraw &= pDevice->DrawTextPathWithFlags( | |
663 CharPosList.m_nChars - pStartIndex, CharPosList.m_pCharPos + pStartIndex, | |
664 pFont->m_FontPlusFallbacks[pFontPosition], pCache, font_size, pText2User, | |
665 pUser2Device, pGraphState, fill_argb, stroke_argb, pClippingPath, nFlag); | |
666 return bDraw; | |
636 } | 667 } |
637 | 668 |
638 // static | 669 // static |
639 void CPDF_TextRenderer::DrawTextString(CFX_RenderDevice* pDevice, | 670 void CPDF_TextRenderer::DrawTextString(CFX_RenderDevice* pDevice, |
640 FX_FLOAT origin_x, | 671 FX_FLOAT origin_x, |
641 FX_FLOAT origin_y, | 672 FX_FLOAT origin_y, |
642 CPDF_Font* pFont, | 673 CPDF_Font* pFont, |
643 FX_FLOAT font_size, | 674 FX_FLOAT font_size, |
644 const CFX_Matrix* pMatrix, | 675 const CFX_Matrix* pMatrix, |
645 const CFX_ByteString& str, | 676 const CFX_ByteString& str, |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
728 } | 759 } |
729 if (dwFlags & RENDER_PRINTIMAGETEXT) { | 760 if (dwFlags & RENDER_PRINTIMAGETEXT) { |
730 FXGE_flags |= FXTEXT_PRINTIMAGETEXT; | 761 FXGE_flags |= FXTEXT_PRINTIMAGETEXT; |
731 } | 762 } |
732 } else { | 763 } else { |
733 FXGE_flags = FXTEXT_CLEARTYPE; | 764 FXGE_flags = FXTEXT_CLEARTYPE; |
734 } | 765 } |
735 if (pFont->IsCIDFont()) { | 766 if (pFont->IsCIDFont()) { |
736 FXGE_flags |= FXFONT_CIDFONT; | 767 FXGE_flags |= FXFONT_CIDFONT; |
737 } | 768 } |
738 return pDevice->DrawNormalText(CharPosList.m_nChars, CharPosList.m_pCharPos, | 769 FX_BOOL bDraw = TRUE; |
739 &pFont->m_Font, pCache, font_size, | 770 uint32_t pFontPosition = CharPosList.m_pCharPos[0].m_FallbackFontPosition; |
740 pText2Device, fill_argb, FXGE_flags); | 771 uint32_t pStartIndex = 0; |
772 for (uint32_t i = 0; i < CharPosList.m_nChars; i++) { | |
773 uint32_t pCurFontPosition = | |
774 CharPosList.m_pCharPos[i].m_FallbackFontPosition; | |
775 if (pFontPosition != pCurFontPosition) { | |
776 bDraw &= pDevice->DrawNormalText( | |
777 i - pStartIndex, CharPosList.m_pCharPos + pStartIndex, | |
778 pFont->m_FontPlusFallbacks[pFontPosition], pCache, font_size, | |
779 pText2Device, fill_argb, FXGE_flags); | |
780 pFontPosition = pCurFontPosition; | |
781 pStartIndex = i; | |
782 } | |
783 } | |
784 bDraw &= pDevice->DrawNormalText( | |
785 CharPosList.m_nChars - pStartIndex, CharPosList.m_pCharPos + pStartIndex, | |
786 pFont->m_FontPlusFallbacks[pFontPosition], pCache, font_size, | |
787 pText2Device, fill_argb, FXGE_flags); | |
788 return bDraw; | |
741 } | 789 } |
742 | 790 |
743 void CPDF_RenderStatus::DrawTextPathWithPattern(const CPDF_TextObject* textobj, | 791 void CPDF_RenderStatus::DrawTextPathWithPattern(const CPDF_TextObject* textobj, |
744 const CFX_Matrix* pObj2Device, | 792 const CFX_Matrix* pObj2Device, |
745 CPDF_Font* pFont, | 793 CPDF_Font* pFont, |
746 FX_FLOAT font_size, | 794 FX_FLOAT font_size, |
747 const CFX_Matrix* pTextMatrix, | 795 const CFX_Matrix* pTextMatrix, |
748 FX_BOOL bFill, | 796 FX_BOOL bFill, |
749 FX_BOOL bStroke) { | 797 FX_BOOL bStroke) { |
750 if (!bStroke) { | 798 if (!bStroke) { |
(...skipping 12 matching lines...) Expand all Loading... | |
763 path.m_Top = textobj->m_Top; | 811 path.m_Top = textobj->m_Top; |
764 RenderSingleObject(&path, pObj2Device); | 812 RenderSingleObject(&path, pObj2Device); |
765 return; | 813 return; |
766 } | 814 } |
767 CFX_FontCache* pCache; | 815 CFX_FontCache* pCache; |
768 if (pFont->m_pDocument) { | 816 if (pFont->m_pDocument) { |
769 pCache = pFont->m_pDocument->GetRenderData()->GetFontCache(); | 817 pCache = pFont->m_pDocument->GetRenderData()->GetFontCache(); |
770 } else { | 818 } else { |
771 pCache = CFX_GEModule::Get()->GetFontCache(); | 819 pCache = CFX_GEModule::Get()->GetFontCache(); |
772 } | 820 } |
773 CFX_FaceCache* pFaceCache = pCache->GetCachedFace(&pFont->m_Font); | |
774 CFX_AutoFontCache autoFontCache(pCache, &pFont->m_Font); | |
775 CPDF_CharPosList CharPosList; | 821 CPDF_CharPosList CharPosList; |
776 CharPosList.Load(textobj->m_nChars, textobj->m_pCharCodes, | 822 CharPosList.Load(textobj->m_nChars, textobj->m_pCharCodes, |
777 textobj->m_pCharPos, pFont, font_size); | 823 textobj->m_pCharPos, pFont, font_size); |
824 std::vector<CFX_FaceCache*> pFaceCaches; | |
825 std::vector<CFX_AutoFontCache> autoFontCaches; | |
826 for (auto& font : pFont->m_FontPlusFallbacks) { | |
827 pFaceCaches.push_back(pCache->GetCachedFace(font)); | |
828 autoFontCaches.push_back(CFX_AutoFontCache(pCache, font)); | |
829 } | |
778 for (uint32_t i = 0; i < CharPosList.m_nChars; i++) { | 830 for (uint32_t i = 0; i < CharPosList.m_nChars; i++) { |
779 FXTEXT_CHARPOS& charpos = CharPosList.m_pCharPos[i]; | 831 FXTEXT_CHARPOS& charpos = CharPosList.m_pCharPos[i]; |
780 const CFX_PathData* pPath = pFaceCache->LoadGlyphPath( | 832 const CFX_PathData* pPath = |
781 &pFont->m_Font, charpos.m_GlyphIndex, charpos.m_FontCharWidth); | 833 pFaceCaches[charpos.m_FallbackFontPosition]->LoadGlyphPath( |
834 pFont->m_FontPlusFallbacks[charpos.m_FallbackFontPosition], | |
835 charpos.m_GlyphIndex, charpos.m_FontCharWidth); | |
782 if (!pPath) { | 836 if (!pPath) { |
783 continue; | 837 continue; |
784 } | 838 } |
785 CPDF_PathObject path; | 839 CPDF_PathObject path; |
786 path.m_GraphState = textobj->m_GraphState; | 840 path.m_GraphState = textobj->m_GraphState; |
787 path.m_ColorState = textobj->m_ColorState; | 841 path.m_ColorState = textobj->m_ColorState; |
788 CFX_Matrix matrix; | 842 CFX_Matrix matrix; |
789 if (charpos.m_bGlyphAdjust) | 843 if (charpos.m_bGlyphAdjust) |
790 matrix.Set(charpos.m_AdjustMatrix[0], charpos.m_AdjustMatrix[1], | 844 matrix.Set(charpos.m_AdjustMatrix[0], charpos.m_AdjustMatrix[1], |
791 charpos.m_AdjustMatrix[2], charpos.m_AdjustMatrix[3], 0, 0); | 845 charpos.m_AdjustMatrix[2], charpos.m_AdjustMatrix[3], 0, 0); |
792 matrix.Concat(font_size, 0, 0, font_size, charpos.m_OriginX, | 846 matrix.Concat(font_size, 0, 0, font_size, charpos.m_OriginX, |
793 charpos.m_OriginY); | 847 charpos.m_OriginY); |
794 path.m_Path.New()->Append(pPath, &matrix); | 848 path.m_Path.New()->Append(pPath, &matrix); |
795 path.m_Matrix = *pTextMatrix; | 849 path.m_Matrix = *pTextMatrix; |
796 path.m_bStroke = bStroke; | 850 path.m_bStroke = bStroke; |
797 path.m_FillType = bFill ? FXFILL_WINDING : 0; | 851 path.m_FillType = bFill ? FXFILL_WINDING : 0; |
798 path.CalcBoundingBox(); | 852 path.CalcBoundingBox(); |
799 ProcessPath(&path, pObj2Device); | 853 ProcessPath(&path, pObj2Device); |
800 } | 854 } |
801 } | 855 } |
OLD | NEW |