Chromium Code Reviews| 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!!) | |
|
Lei Zhang
2016/08/24 04:43:11
TODO(username): Comment.
npm
2016/08/24 14:39:22
Done.
| |
| 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 if (charpos.m_FallbackFontPosition >= 0) { | |
| 582 charpos.m_GlyphIndex = pFont->FallbackGlyphFromCharcode( | |
| 583 charpos.m_FallbackFontPosition, CharCode, &bVert); | |
| 584 } | |
| 585 } | |
| 586 // TODO(npm) Figure out how this affects m_ExtGID | |
| 575 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ | 587 #if _FXM_PLATFORM_ == _FXM_PLATFORM_APPLE_ |
| 576 charpos.m_ExtGID = pFont->GlyphFromCharCodeExt(CharCode); | 588 charpos.m_ExtGID = pFont->GlyphFromCharCodeExt(CharCode); |
| 577 #endif | 589 #endif |
| 578 if (!pFont->IsEmbedded() && !pFont->IsCIDFont()) { | 590 if (!pFont->IsEmbedded() && !pFont->IsCIDFont()) { |
| 579 charpos.m_FontCharWidth = pFont->GetCharWidthF(CharCode); | 591 charpos.m_FontCharWidth = pFont->GetCharWidthF(CharCode); |
| 580 } else { | 592 } else { |
| 581 charpos.m_FontCharWidth = 0; | 593 charpos.m_FontCharWidth = 0; |
| 582 } | 594 } |
| 583 charpos.m_OriginX = iChar ? pCharPos[iChar - 1] : 0; | 595 charpos.m_OriginX = iChar ? pCharPos[iChar - 1] : 0; |
| 584 charpos.m_OriginY = 0; | 596 charpos.m_OriginY = 0; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 622 const CFX_GraphStateData* pGraphState, | 634 const CFX_GraphStateData* pGraphState, |
| 623 FX_ARGB fill_argb, | 635 FX_ARGB fill_argb, |
| 624 FX_ARGB stroke_argb, | 636 FX_ARGB stroke_argb, |
| 625 CFX_PathData* pClippingPath, | 637 CFX_PathData* pClippingPath, |
| 626 int nFlag) { | 638 int nFlag) { |
| 627 CFX_FontCache* pCache = | 639 CFX_FontCache* pCache = |
| 628 pFont->m_pDocument ? pFont->m_pDocument->GetRenderData()->GetFontCache() | 640 pFont->m_pDocument ? pFont->m_pDocument->GetRenderData()->GetFontCache() |
| 629 : nullptr; | 641 : nullptr; |
| 630 CPDF_CharPosList CharPosList; | 642 CPDF_CharPosList CharPosList; |
| 631 CharPosList.Load(nChars, pCharCodes, pCharPos, pFont, font_size); | 643 CharPosList.Load(nChars, pCharCodes, pCharPos, pFont, font_size); |
| 632 return pDevice->DrawTextPathWithFlags( | 644 FX_BOOL bDraw = TRUE; |
|
Lei Zhang
2016/08/24 04:43:11
Use bool?
npm
2016/08/24 14:39:22
DrawTextPath returns FX_BOOL
| |
| 633 CharPosList.m_nChars, CharPosList.m_pCharPos, &pFont->m_Font, pCache, | 645 int32_t pFontPosition = CharPosList.m_pCharPos[0].m_FallbackFontPosition; |
|
dsinclair
2016/08/23 20:58:02
can m_pCharPos length be 0?
npm
2016/08/24 14:39:22
Done.
| |
| 634 font_size, pText2User, pUser2Device, pGraphState, fill_argb, stroke_argb, | 646 uint32_t pStartIndex = 0; |
|
Lei Zhang
2016/08/24 04:43:11
Not a pointer, ditto for |pFontPosition| above.
npm
2016/08/24 14:39:22
Done.
| |
| 635 pClippingPath, nFlag); | 647 for (uint32_t i = 0; i < CharPosList.m_nChars; i++) { |
| 648 int32_t pCurFontPosition = CharPosList.m_pCharPos[i].m_FallbackFontPosition; | |
| 649 if (pFontPosition != pCurFontPosition) { | |
|
dsinclair
2016/08/23 20:58:01
if (pFontPosition == pCurFontPosition)
continue;
npm
2016/08/24 14:39:22
Done.
| |
| 650 auto font = pFontPosition == -1 | |
|
Lei Zhang
2016/08/24 04:43:11
Is |font| a pointer? Use auto*
npm
2016/08/24 14:39:22
Done.
| |
| 651 ? &pFont->m_Font | |
| 652 : pFont->m_FontFallbacks[pFontPosition].get(); | |
| 653 bDraw &= pDevice->DrawTextPathWithFlags( | |
| 654 i - pStartIndex, CharPosList.m_pCharPos + pStartIndex, font, pCache, | |
| 655 font_size, pText2User, pUser2Device, pGraphState, fill_argb, | |
| 656 stroke_argb, pClippingPath, nFlag); | |
| 657 pFontPosition = pCurFontPosition; | |
| 658 pStartIndex = i; | |
| 659 } | |
| 660 } | |
| 661 auto font = pFontPosition == -1 ? &pFont->m_Font | |
| 662 : pFont->m_FontFallbacks[pFontPosition].get(); | |
| 663 bDraw &= pDevice->DrawTextPathWithFlags( | |
| 664 CharPosList.m_nChars - pStartIndex, CharPosList.m_pCharPos + pStartIndex, | |
| 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 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 728 } | 760 } |
| 729 if (dwFlags & RENDER_PRINTIMAGETEXT) { | 761 if (dwFlags & RENDER_PRINTIMAGETEXT) { |
| 730 FXGE_flags |= FXTEXT_PRINTIMAGETEXT; | 762 FXGE_flags |= FXTEXT_PRINTIMAGETEXT; |
| 731 } | 763 } |
| 732 } else { | 764 } else { |
| 733 FXGE_flags = FXTEXT_CLEARTYPE; | 765 FXGE_flags = FXTEXT_CLEARTYPE; |
| 734 } | 766 } |
| 735 if (pFont->IsCIDFont()) { | 767 if (pFont->IsCIDFont()) { |
| 736 FXGE_flags |= FXFONT_CIDFONT; | 768 FXGE_flags |= FXFONT_CIDFONT; |
| 737 } | 769 } |
| 738 return pDevice->DrawNormalText(CharPosList.m_nChars, CharPosList.m_pCharPos, | 770 FX_BOOL bDraw = TRUE; |
| 739 &pFont->m_Font, pCache, font_size, | 771 int32_t pFontPosition = CharPosList.m_pCharPos[0].m_FallbackFontPosition; |
|
dsinclair
2016/08/23 20:58:01
Same comments as above.
npm
2016/08/24 14:39:22
Done.
| |
| 740 pText2Device, fill_argb, FXGE_flags); | 772 uint32_t pStartIndex = 0; |
| 773 for (uint32_t i = 0; i < CharPosList.m_nChars; i++) { | |
| 774 int32_t pCurFontPosition = CharPosList.m_pCharPos[i].m_FallbackFontPosition; | |
| 775 if (pFontPosition != pCurFontPosition) { | |
| 776 auto font = pFontPosition == -1 | |
| 777 ? &pFont->m_Font | |
| 778 : pFont->m_FontFallbacks[pFontPosition].get(); | |
| 779 bDraw &= pDevice->DrawNormalText( | |
| 780 i - pStartIndex, CharPosList.m_pCharPos + pStartIndex, font, pCache, | |
| 781 font_size, pText2Device, fill_argb, FXGE_flags); | |
| 782 pFontPosition = pCurFontPosition; | |
| 783 pStartIndex = i; | |
| 784 } | |
| 785 } | |
| 786 auto font = pFontPosition == -1 ? &pFont->m_Font | |
| 787 : pFont->m_FontFallbacks[pFontPosition].get(); | |
| 788 bDraw &= pDevice->DrawNormalText( | |
| 789 CharPosList.m_nChars - pStartIndex, CharPosList.m_pCharPos + pStartIndex, | |
| 790 font, pCache, font_size, pText2Device, fill_argb, FXGE_flags); | |
| 791 return bDraw; | |
| 741 } | 792 } |
| 742 | 793 |
| 743 void CPDF_RenderStatus::DrawTextPathWithPattern(const CPDF_TextObject* textobj, | 794 void CPDF_RenderStatus::DrawTextPathWithPattern(const CPDF_TextObject* textobj, |
| 744 const CFX_Matrix* pObj2Device, | 795 const CFX_Matrix* pObj2Device, |
| 745 CPDF_Font* pFont, | 796 CPDF_Font* pFont, |
| 746 FX_FLOAT font_size, | 797 FX_FLOAT font_size, |
| 747 const CFX_Matrix* pTextMatrix, | 798 const CFX_Matrix* pTextMatrix, |
| 748 FX_BOOL bFill, | 799 FX_BOOL bFill, |
| 749 FX_BOOL bStroke) { | 800 FX_BOOL bStroke) { |
| 750 if (!bStroke) { | 801 if (!bStroke) { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 763 path.m_Top = textobj->m_Top; | 814 path.m_Top = textobj->m_Top; |
| 764 RenderSingleObject(&path, pObj2Device); | 815 RenderSingleObject(&path, pObj2Device); |
| 765 return; | 816 return; |
| 766 } | 817 } |
| 767 CFX_FontCache* pCache; | 818 CFX_FontCache* pCache; |
| 768 if (pFont->m_pDocument) { | 819 if (pFont->m_pDocument) { |
| 769 pCache = pFont->m_pDocument->GetRenderData()->GetFontCache(); | 820 pCache = pFont->m_pDocument->GetRenderData()->GetFontCache(); |
| 770 } else { | 821 } else { |
| 771 pCache = CFX_GEModule::Get()->GetFontCache(); | 822 pCache = CFX_GEModule::Get()->GetFontCache(); |
| 772 } | 823 } |
| 773 CFX_FaceCache* pFaceCache = pCache->GetCachedFace(&pFont->m_Font); | |
| 774 CFX_AutoFontCache autoFontCache(pCache, &pFont->m_Font); | |
| 775 CPDF_CharPosList CharPosList; | 824 CPDF_CharPosList CharPosList; |
| 776 CharPosList.Load(textobj->m_nChars, textobj->m_pCharCodes, | 825 CharPosList.Load(textobj->m_nChars, textobj->m_pCharCodes, |
| 777 textobj->m_pCharPos, pFont, font_size); | 826 textobj->m_pCharPos, pFont, font_size); |
| 827 std::vector<CFX_FaceCache*> pFaceCaches; | |
|
Lei Zhang
2016/08/24 04:43:11
Also not a pointer, thus the p-prefix is slightly
npm
2016/08/24 14:39:22
Done.
| |
| 828 std::vector<CFX_AutoFontCache> autoFontCaches; | |
| 829 pFaceCaches.push_back(pCache->GetCachedFace(&pFont->m_Font)); | |
| 830 autoFontCaches.push_back(CFX_AutoFontCache(pCache, &pFont->m_Font)); | |
| 831 for (auto& font : pFont->m_FontFallbacks) { | |
| 832 pFaceCaches.push_back(pCache->GetCachedFace(font.get())); | |
| 833 autoFontCaches.push_back(CFX_AutoFontCache(pCache, font.get())); | |
| 834 } | |
| 778 for (uint32_t i = 0; i < CharPosList.m_nChars; i++) { | 835 for (uint32_t i = 0; i < CharPosList.m_nChars; i++) { |
| 779 FXTEXT_CHARPOS& charpos = CharPosList.m_pCharPos[i]; | 836 FXTEXT_CHARPOS& charpos = CharPosList.m_pCharPos[i]; |
| 780 const CFX_PathData* pPath = pFaceCache->LoadGlyphPath( | 837 auto font = |
| 781 &pFont->m_Font, charpos.m_GlyphIndex, charpos.m_FontCharWidth); | 838 charpos.m_FallbackFontPosition == -1 |
| 839 ? &pFont->m_Font | |
| 840 : pFont->m_FontFallbacks[charpos.m_FallbackFontPosition].get(); | |
| 841 const CFX_PathData* pPath = | |
| 842 pFaceCaches[charpos.m_FallbackFontPosition + 1]->LoadGlyphPath( | |
| 843 font, charpos.m_GlyphIndex, charpos.m_FontCharWidth); | |
| 782 if (!pPath) { | 844 if (!pPath) { |
| 783 continue; | 845 continue; |
| 784 } | 846 } |
| 785 CPDF_PathObject path; | 847 CPDF_PathObject path; |
| 786 path.m_GraphState = textobj->m_GraphState; | 848 path.m_GraphState = textobj->m_GraphState; |
| 787 path.m_ColorState = textobj->m_ColorState; | 849 path.m_ColorState = textobj->m_ColorState; |
| 788 CFX_Matrix matrix; | 850 CFX_Matrix matrix; |
| 789 if (charpos.m_bGlyphAdjust) | 851 if (charpos.m_bGlyphAdjust) |
| 790 matrix.Set(charpos.m_AdjustMatrix[0], charpos.m_AdjustMatrix[1], | 852 matrix.Set(charpos.m_AdjustMatrix[0], charpos.m_AdjustMatrix[1], |
| 791 charpos.m_AdjustMatrix[2], charpos.m_AdjustMatrix[3], 0, 0); | 853 charpos.m_AdjustMatrix[2], charpos.m_AdjustMatrix[3], 0, 0); |
| 792 matrix.Concat(font_size, 0, 0, font_size, charpos.m_OriginX, | 854 matrix.Concat(font_size, 0, 0, font_size, charpos.m_OriginX, |
| 793 charpos.m_OriginY); | 855 charpos.m_OriginY); |
| 794 path.m_Path.New()->Append(pPath, &matrix); | 856 path.m_Path.New()->Append(pPath, &matrix); |
| 795 path.m_Matrix = *pTextMatrix; | 857 path.m_Matrix = *pTextMatrix; |
| 796 path.m_bStroke = bStroke; | 858 path.m_bStroke = bStroke; |
| 797 path.m_FillType = bFill ? FXFILL_WINDING : 0; | 859 path.m_FillType = bFill ? FXFILL_WINDING : 0; |
| 798 path.CalcBoundingBox(); | 860 path.CalcBoundingBox(); |
| 799 ProcessPath(&path, pObj2Device); | 861 ProcessPath(&path, pObj2Device); |
| 800 } | 862 } |
| 801 } | 863 } |
| OLD | NEW |