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 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
565 nChars == 1 ? (uint32_t)(uintptr_t)pCharCodes : pCharCodes[iChar]; | 566 nChars == 1 ? (uint32_t)(uintptr_t)pCharCodes : pCharCodes[iChar]; |
566 if (CharCode == (uint32_t)-1) { | 567 if (CharCode == (uint32_t)-1) { |
567 continue; | 568 continue; |
568 } | 569 } |
569 bool bVert = false; | 570 bool bVert = false; |
570 FXTEXT_CHARPOS& charpos = m_pCharPos[m_nChars++]; | 571 FXTEXT_CHARPOS& charpos = m_pCharPos[m_nChars++]; |
571 if (pCIDFont) { | 572 if (pCIDFont) { |
572 charpos.m_bFontStyle = true; | 573 charpos.m_bFontStyle = true; |
573 } | 574 } |
574 charpos.m_GlyphIndex = pFont->GlyphFromCharCode(CharCode, &bVert); | 575 charpos.m_GlyphIndex = pFont->GlyphFromCharCode(CharCode, &bVert); |
576 if (charpos.m_GlyphIndex != static_cast<uint32_t>(-1)) { | |
577 charpos.m_FallbackFontPosition = -1; | |
578 } else { | |
579 charpos.m_FallbackFontPosition = | |
580 pFont->FallbackFontFromCharcode(CharCode, &bVert); | |
581 charpos.m_GlyphIndex = pFont->FallbackGlyphFromCharcode( | |
582 charpos.m_FallbackFontPosition, CharCode, &bVert); | |
583 } | |
584 // TODO(npm): Figure out how this affects m_ExtGID | |
575 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 585 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
576 charpos.m_ExtGID = pFont->GlyphFromCharCodeExt(CharCode); | 586 charpos.m_ExtGID = pFont->GlyphFromCharCodeExt(CharCode); |
577 #endif | 587 #endif |
578 if (!pFont->IsEmbedded() && !pFont->IsCIDFont()) { | 588 if (!pFont->IsEmbedded() && !pFont->IsCIDFont()) { |
579 charpos.m_FontCharWidth = pFont->GetCharWidthF(CharCode); | 589 charpos.m_FontCharWidth = pFont->GetCharWidthF(CharCode); |
580 } else { | 590 } else { |
581 charpos.m_FontCharWidth = 0; | 591 charpos.m_FontCharWidth = 0; |
582 } | 592 } |
583 charpos.m_OriginX = iChar ? pCharPos[iChar - 1] : 0; | 593 charpos.m_OriginX = iChar ? pCharPos[iChar - 1] : 0; |
584 charpos.m_OriginY = 0; | 594 charpos.m_OriginY = 0; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
622 const CFX_GraphStateData* pGraphState, | 632 const CFX_GraphStateData* pGraphState, |
623 FX_ARGB fill_argb, | 633 FX_ARGB fill_argb, |
624 FX_ARGB stroke_argb, | 634 FX_ARGB stroke_argb, |
625 CFX_PathData* pClippingPath, | 635 CFX_PathData* pClippingPath, |
626 int nFlag) { | 636 int nFlag) { |
627 CFX_FontCache* pCache = | 637 CFX_FontCache* pCache = |
628 pFont->m_pDocument ? pFont->m_pDocument->GetRenderData()->GetFontCache() | 638 pFont->m_pDocument ? pFont->m_pDocument->GetRenderData()->GetFontCache() |
629 : nullptr; | 639 : nullptr; |
630 CPDF_CharPosList CharPosList; | 640 CPDF_CharPosList CharPosList; |
631 CharPosList.Load(nChars, pCharCodes, pCharPos, pFont, font_size); | 641 CharPosList.Load(nChars, pCharCodes, pCharPos, pFont, font_size); |
632 return pDevice->DrawTextPath(CharPosList.m_nChars, CharPosList.m_pCharPos, | 642 if (CharPosList.m_nChars == 0) |
633 &pFont->m_Font, pCache, font_size, pText2User, | 643 return TRUE; |
634 pUser2Device, pGraphState, fill_argb, | 644 FX_BOOL bDraw = TRUE; |
Tom Sepez
2016/08/24 16:23:49
nit: this should be a bool if we are going to &= i
npm
2016/08/24 17:47:15
Done.
| |
635 stroke_argb, pClippingPath, nFlag); | 645 int32_t fontPosition = CharPosList.m_pCharPos[0].m_FallbackFontPosition; |
646 uint32_t startIndex = 0; | |
647 for (uint32_t i = 0; i < CharPosList.m_nChars; i++) { | |
648 int32_t curFontPosition = CharPosList.m_pCharPos[i].m_FallbackFontPosition; | |
649 if (fontPosition == curFontPosition) | |
650 continue; | |
651 auto* font = fontPosition == -1 | |
Tom Sepez
2016/08/24 16:23:49
Is there a reason to separate default fonts from f
npm
2016/08/24 17:47:15
CPDF_Font already has m_Font for its main font. If
| |
652 ? &pFont->m_Font | |
653 : pFont->m_FontFallbacks[fontPosition].get(); | |
654 bDraw &= pDevice->DrawTextPath( | |
655 i - startIndex, CharPosList.m_pCharPos + startIndex, font, pCache, | |
656 font_size, pText2User, pUser2Device, pGraphState, fill_argb, | |
657 stroke_argb, pClippingPath, nFlag); | |
658 fontPosition = curFontPosition; | |
659 startIndex = i; | |
660 } | |
661 auto* font = fontPosition == -1 ? &pFont->m_Font | |
662 : pFont->m_FontFallbacks[fontPosition].get(); | |
663 bDraw &= pDevice->DrawTextPath( | |
664 CharPosList.m_nChars - startIndex, CharPosList.m_pCharPos + startIndex, | |
665 font, pCache, font_size, pText2User, pUser2Device, pGraphState, fill_argb, | |
666 stroke_argb, pClippingPath, nFlag); | |
667 return bDraw; | |
636 } | 668 } |
637 | 669 |
638 // static | 670 // static |
639 void CPDF_TextRenderer::DrawTextString(CFX_RenderDevice* pDevice, | 671 void CPDF_TextRenderer::DrawTextString(CFX_RenderDevice* pDevice, |
640 FX_FLOAT origin_x, | 672 FX_FLOAT origin_x, |
641 FX_FLOAT origin_y, | 673 FX_FLOAT origin_y, |
642 CPDF_Font* pFont, | 674 CPDF_Font* pFont, |
643 FX_FLOAT font_size, | 675 FX_FLOAT font_size, |
644 const CFX_Matrix* pMatrix, | 676 const CFX_Matrix* pMatrix, |
645 const CFX_ByteString& str, | 677 const CFX_ByteString& str, |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
701 CPDF_Font* pFont, | 733 CPDF_Font* pFont, |
702 FX_FLOAT font_size, | 734 FX_FLOAT font_size, |
703 const CFX_Matrix* pText2Device, | 735 const CFX_Matrix* pText2Device, |
704 FX_ARGB fill_argb, | 736 FX_ARGB fill_argb, |
705 const CPDF_RenderOptions* pOptions) { | 737 const CPDF_RenderOptions* pOptions) { |
706 CFX_FontCache* pCache = | 738 CFX_FontCache* pCache = |
707 pFont->m_pDocument ? pFont->m_pDocument->GetRenderData()->GetFontCache() | 739 pFont->m_pDocument ? pFont->m_pDocument->GetRenderData()->GetFontCache() |
708 : nullptr; | 740 : nullptr; |
709 CPDF_CharPosList CharPosList; | 741 CPDF_CharPosList CharPosList; |
710 CharPosList.Load(nChars, pCharCodes, pCharPos, pFont, font_size); | 742 CharPosList.Load(nChars, pCharCodes, pCharPos, pFont, font_size); |
743 if (CharPosList.m_nChars == 0) | |
744 return TRUE; | |
711 int FXGE_flags = 0; | 745 int FXGE_flags = 0; |
712 if (pOptions) { | 746 if (pOptions) { |
713 uint32_t dwFlags = pOptions->m_Flags; | 747 uint32_t dwFlags = pOptions->m_Flags; |
714 if (dwFlags & RENDER_CLEARTYPE) { | 748 if (dwFlags & RENDER_CLEARTYPE) { |
715 FXGE_flags |= FXTEXT_CLEARTYPE; | 749 FXGE_flags |= FXTEXT_CLEARTYPE; |
716 if (dwFlags & RENDER_BGR_STRIPE) { | 750 if (dwFlags & RENDER_BGR_STRIPE) { |
717 FXGE_flags |= FXTEXT_BGR_STRIPE; | 751 FXGE_flags |= FXTEXT_BGR_STRIPE; |
718 } | 752 } |
719 } | 753 } |
720 if (dwFlags & RENDER_NOTEXTSMOOTH) { | 754 if (dwFlags & RENDER_NOTEXTSMOOTH) { |
721 FXGE_flags |= FXTEXT_NOSMOOTH; | 755 FXGE_flags |= FXTEXT_NOSMOOTH; |
722 } | 756 } |
723 if (dwFlags & RENDER_PRINTGRAPHICTEXT) { | 757 if (dwFlags & RENDER_PRINTGRAPHICTEXT) { |
724 FXGE_flags |= FXTEXT_PRINTGRAPHICTEXT; | 758 FXGE_flags |= FXTEXT_PRINTGRAPHICTEXT; |
725 } | 759 } |
726 if (dwFlags & RENDER_NO_NATIVETEXT) { | 760 if (dwFlags & RENDER_NO_NATIVETEXT) { |
727 FXGE_flags |= FXTEXT_NO_NATIVETEXT; | 761 FXGE_flags |= FXTEXT_NO_NATIVETEXT; |
728 } | 762 } |
729 if (dwFlags & RENDER_PRINTIMAGETEXT) { | 763 if (dwFlags & RENDER_PRINTIMAGETEXT) { |
730 FXGE_flags |= FXTEXT_PRINTIMAGETEXT; | 764 FXGE_flags |= FXTEXT_PRINTIMAGETEXT; |
731 } | 765 } |
732 } else { | 766 } else { |
733 FXGE_flags = FXTEXT_CLEARTYPE; | 767 FXGE_flags = FXTEXT_CLEARTYPE; |
734 } | 768 } |
735 if (pFont->IsCIDFont()) { | 769 if (pFont->IsCIDFont()) { |
736 FXGE_flags |= FXFONT_CIDFONT; | 770 FXGE_flags |= FXFONT_CIDFONT; |
737 } | 771 } |
738 return pDevice->DrawNormalText(CharPosList.m_nChars, CharPosList.m_pCharPos, | 772 FX_BOOL bDraw = TRUE; |
Tom Sepez
2016/08/24 16:23:49
nit: same here.
npm
2016/08/24 17:47:15
Done.
| |
739 &pFont->m_Font, pCache, font_size, | 773 int32_t fontPosition = CharPosList.m_pCharPos[0].m_FallbackFontPosition; |
740 pText2Device, fill_argb, FXGE_flags); | 774 uint32_t startIndex = 0; |
775 for (uint32_t i = 0; i < CharPosList.m_nChars; i++) { | |
776 int32_t curFontPosition = CharPosList.m_pCharPos[i].m_FallbackFontPosition; | |
777 if (fontPosition == curFontPosition) | |
778 continue; | |
779 auto* font = fontPosition == -1 | |
780 ? &pFont->m_Font | |
781 : pFont->m_FontFallbacks[fontPosition].get(); | |
782 bDraw &= pDevice->DrawNormalText( | |
783 i - startIndex, CharPosList.m_pCharPos + startIndex, font, pCache, | |
784 font_size, pText2Device, fill_argb, FXGE_flags); | |
785 fontPosition = curFontPosition; | |
786 startIndex = i; | |
787 } | |
788 auto* font = fontPosition == -1 ? &pFont->m_Font | |
789 : pFont->m_FontFallbacks[fontPosition].get(); | |
790 bDraw &= pDevice->DrawNormalText( | |
791 CharPosList.m_nChars - startIndex, CharPosList.m_pCharPos + startIndex, | |
792 font, pCache, font_size, pText2Device, fill_argb, FXGE_flags); | |
793 return bDraw; | |
741 } | 794 } |
742 | 795 |
743 void CPDF_RenderStatus::DrawTextPathWithPattern(const CPDF_TextObject* textobj, | 796 void CPDF_RenderStatus::DrawTextPathWithPattern(const CPDF_TextObject* textobj, |
744 const CFX_Matrix* pObj2Device, | 797 const CFX_Matrix* pObj2Device, |
745 CPDF_Font* pFont, | 798 CPDF_Font* pFont, |
746 FX_FLOAT font_size, | 799 FX_FLOAT font_size, |
747 const CFX_Matrix* pTextMatrix, | 800 const CFX_Matrix* pTextMatrix, |
748 FX_BOOL bFill, | 801 FX_BOOL bFill, |
749 FX_BOOL bStroke) { | 802 FX_BOOL bStroke) { |
750 if (!bStroke) { | 803 if (!bStroke) { |
(...skipping 12 matching lines...) Expand all Loading... | |
763 path.m_Top = textobj->m_Top; | 816 path.m_Top = textobj->m_Top; |
764 RenderSingleObject(&path, pObj2Device); | 817 RenderSingleObject(&path, pObj2Device); |
765 return; | 818 return; |
766 } | 819 } |
767 CFX_FontCache* pCache; | 820 CFX_FontCache* pCache; |
768 if (pFont->m_pDocument) { | 821 if (pFont->m_pDocument) { |
769 pCache = pFont->m_pDocument->GetRenderData()->GetFontCache(); | 822 pCache = pFont->m_pDocument->GetRenderData()->GetFontCache(); |
770 } else { | 823 } else { |
771 pCache = CFX_GEModule::Get()->GetFontCache(); | 824 pCache = CFX_GEModule::Get()->GetFontCache(); |
772 } | 825 } |
773 CFX_FaceCache* pFaceCache = pCache->GetCachedFace(&pFont->m_Font); | |
774 CFX_AutoFontCache autoFontCache(pCache, &pFont->m_Font); | |
775 CPDF_CharPosList CharPosList; | 826 CPDF_CharPosList CharPosList; |
776 CharPosList.Load(textobj->m_nChars, textobj->m_pCharCodes, | 827 CharPosList.Load(textobj->m_nChars, textobj->m_pCharCodes, |
777 textobj->m_pCharPos, pFont, font_size); | 828 textobj->m_pCharPos, pFont, font_size); |
829 std::vector<CFX_FaceCache*> faceCaches; | |
830 std::vector<CFX_AutoFontCache> autoFontCaches; | |
831 faceCaches.push_back(pCache->GetCachedFace(&pFont->m_Font)); | |
832 autoFontCaches.push_back(CFX_AutoFontCache(pCache, &pFont->m_Font)); | |
833 for (auto& font : pFont->m_FontFallbacks) { | |
Tom Sepez
2016/08/24 16:23:49
nit: can this be const auto& font ?
npm
2016/08/24 17:47:15
Done.
| |
834 faceCaches.push_back(pCache->GetCachedFace(font.get())); | |
835 autoFontCaches.push_back(CFX_AutoFontCache(pCache, font.get())); | |
836 } | |
778 for (uint32_t i = 0; i < CharPosList.m_nChars; i++) { | 837 for (uint32_t i = 0; i < CharPosList.m_nChars; i++) { |
779 FXTEXT_CHARPOS& charpos = CharPosList.m_pCharPos[i]; | 838 FXTEXT_CHARPOS& charpos = CharPosList.m_pCharPos[i]; |
780 const CFX_PathData* pPath = pFaceCache->LoadGlyphPath( | 839 auto font = |
781 &pFont->m_Font, charpos.m_GlyphIndex, charpos.m_FontCharWidth); | 840 charpos.m_FallbackFontPosition == -1 |
841 ? &pFont->m_Font | |
842 : pFont->m_FontFallbacks[charpos.m_FallbackFontPosition].get(); | |
843 const CFX_PathData* pPath = | |
844 faceCaches[charpos.m_FallbackFontPosition + 1]->LoadGlyphPath( | |
845 font, charpos.m_GlyphIndex, charpos.m_FontCharWidth); | |
782 if (!pPath) { | 846 if (!pPath) { |
783 continue; | 847 continue; |
784 } | 848 } |
785 CPDF_PathObject path; | 849 CPDF_PathObject path; |
786 path.m_GraphState = textobj->m_GraphState; | 850 path.m_GraphState = textobj->m_GraphState; |
787 path.m_ColorState = textobj->m_ColorState; | 851 path.m_ColorState = textobj->m_ColorState; |
788 CFX_Matrix matrix; | 852 CFX_Matrix matrix; |
789 if (charpos.m_bGlyphAdjust) | 853 if (charpos.m_bGlyphAdjust) |
790 matrix.Set(charpos.m_AdjustMatrix[0], charpos.m_AdjustMatrix[1], | 854 matrix.Set(charpos.m_AdjustMatrix[0], charpos.m_AdjustMatrix[1], |
791 charpos.m_AdjustMatrix[2], charpos.m_AdjustMatrix[3], 0, 0); | 855 charpos.m_AdjustMatrix[2], charpos.m_AdjustMatrix[3], 0, 0); |
792 matrix.Concat(font_size, 0, 0, font_size, charpos.m_OriginX, | 856 matrix.Concat(font_size, 0, 0, font_size, charpos.m_OriginX, |
793 charpos.m_OriginY); | 857 charpos.m_OriginY); |
794 path.m_Path.New()->Append(pPath, &matrix); | 858 path.m_Path.New()->Append(pPath, &matrix); |
795 path.m_Matrix = *pTextMatrix; | 859 path.m_Matrix = *pTextMatrix; |
796 path.m_bStroke = bStroke; | 860 path.m_bStroke = bStroke; |
797 path.m_FillType = bFill ? FXFILL_WINDING : 0; | 861 path.m_FillType = bFill ? FXFILL_WINDING : 0; |
798 path.CalcBoundingBox(); | 862 path.CalcBoundingBox(); |
799 ProcessPath(&path, pObj2Device); | 863 ProcessPath(&path, pObj2Device); |
800 } | 864 } |
801 } | 865 } |
OLD | NEW |