Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(419)

Side by Side Diff: core/fpdfapi/fpdf_render/fpdf_render_text.cpp

Issue 2350763002: Revert of Pdfium: Fix fonts leaking on ClosePage. (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/fpdfapi/fpdf_render/fpdf_render.cpp ('k') | core/fpdfapi/fpdf_render/render_int.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 #include "core/fpdfapi/fpdf_font/cpdf_cidfont.h" 11 #include "core/fpdfapi/fpdf_font/cpdf_cidfont.h"
12 #include "core/fpdfapi/fpdf_font/cpdf_type3char.h" 12 #include "core/fpdfapi/fpdf_font/cpdf_type3char.h"
13 #include "core/fpdfapi/fpdf_font/cpdf_type3font.h" 13 #include "core/fpdfapi/fpdf_font/cpdf_type3font.h"
14 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h" 14 #include "core/fpdfapi/fpdf_font/include/cpdf_font.h"
15 #include "core/fpdfapi/fpdf_page/include/cpdf_form.h" 15 #include "core/fpdfapi/fpdf_page/include/cpdf_form.h"
16 #include "core/fpdfapi/fpdf_page/include/cpdf_imageobject.h" 16 #include "core/fpdfapi/fpdf_page/include/cpdf_imageobject.h"
17 #include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h" 17 #include "core/fpdfapi/fpdf_page/include/cpdf_pageobject.h"
18 #include "core/fpdfapi/fpdf_page/include/cpdf_pathobject.h" 18 #include "core/fpdfapi/fpdf_page/include/cpdf_pathobject.h"
19 #include "core/fpdfapi/fpdf_page/include/cpdf_textobject.h" 19 #include "core/fpdfapi/fpdf_page/include/cpdf_textobject.h"
20 #include "core/fpdfapi/fpdf_page/pageint.h" 20 #include "core/fpdfapi/fpdf_page/pageint.h"
21 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" 21 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h"
22 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h" 22 #include "core/fpdfapi/fpdf_parser/include/cpdf_document.h"
23 #include "core/fpdfapi/fpdf_render/cpdf_type3cache.h" 23 #include "core/fpdfapi/fpdf_render/cpdf_type3cache.h"
24 #include "core/fpdfapi/fpdf_render/include/cpdf_renderoptions.h" 24 #include "core/fpdfapi/fpdf_render/include/cpdf_renderoptions.h"
25 #include "core/fpdfapi/fpdf_render/include/cpdf_textrenderer.h" 25 #include "core/fpdfapi/fpdf_render/include/cpdf_textrenderer.h"
26 #include "core/fxge/include/cfx_autofontcache.h" 26 #include "core/fxge/include/cfx_autofontcache.h"
27 #include "core/fxge/include/cfx_facecache.h" 27 #include "core/fxge/include/cfx_facecache.h"
28 #include "core/fxge/include/cfx_fontcache.h"
28 #include "core/fxge/include/cfx_fxgedevice.h" 29 #include "core/fxge/include/cfx_fxgedevice.h"
29 #include "core/fxge/include/cfx_gemodule.h" 30 #include "core/fxge/include/cfx_gemodule.h"
30 #include "core/fxge/include/cfx_graphstatedata.h" 31 #include "core/fxge/include/cfx_graphstatedata.h"
31 #include "core/fxge/include/cfx_pathdata.h" 32 #include "core/fxge/include/cfx_pathdata.h"
32 #include "core/fxge/include/cfx_renderdevice.h" 33 #include "core/fxge/include/cfx_renderdevice.h"
33 34
34 FX_BOOL CPDF_RenderStatus::ProcessText(CPDF_TextObject* textobj, 35 FX_BOOL CPDF_RenderStatus::ProcessText(CPDF_TextObject* textobj,
35 const CFX_Matrix* pObj2Device, 36 const CFX_Matrix* pObj2Device,
36 CFX_PathData* pClippingPath) { 37 CFX_PathData* pClippingPath) {
37 if (textobj->m_nChars == 0) 38 if (textobj->m_nChars == 0)
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
427 FX_FLOAT* pCharPos, 428 FX_FLOAT* pCharPos,
428 CPDF_Font* pFont, 429 CPDF_Font* pFont,
429 FX_FLOAT font_size, 430 FX_FLOAT font_size,
430 const CFX_Matrix* pText2User, 431 const CFX_Matrix* pText2User,
431 const CFX_Matrix* pUser2Device, 432 const CFX_Matrix* pUser2Device,
432 const CFX_GraphStateData* pGraphState, 433 const CFX_GraphStateData* pGraphState,
433 FX_ARGB fill_argb, 434 FX_ARGB fill_argb,
434 FX_ARGB stroke_argb, 435 FX_ARGB stroke_argb,
435 CFX_PathData* pClippingPath, 436 CFX_PathData* pClippingPath,
436 int nFlag) { 437 int nFlag) {
438 CFX_FontCache* pCache =
439 pFont->m_pDocument ? pFont->m_pDocument->GetRenderData()->GetFontCache()
440 : nullptr;
437 CPDF_CharPosList CharPosList; 441 CPDF_CharPosList CharPosList;
438 CharPosList.Load(nChars, pCharCodes, pCharPos, pFont, font_size); 442 CharPosList.Load(nChars, pCharCodes, pCharPos, pFont, font_size);
439 if (CharPosList.m_nChars == 0) 443 if (CharPosList.m_nChars == 0)
440 return TRUE; 444 return TRUE;
441 bool bDraw = true; 445 bool bDraw = true;
442 int32_t fontPosition = CharPosList.m_pCharPos[0].m_FallbackFontPosition; 446 int32_t fontPosition = CharPosList.m_pCharPos[0].m_FallbackFontPosition;
443 uint32_t startIndex = 0; 447 uint32_t startIndex = 0;
444 for (uint32_t i = 0; i < CharPosList.m_nChars; i++) { 448 for (uint32_t i = 0; i < CharPosList.m_nChars; i++) {
445 int32_t curFontPosition = CharPosList.m_pCharPos[i].m_FallbackFontPosition; 449 int32_t curFontPosition = CharPosList.m_pCharPos[i].m_FallbackFontPosition;
446 if (fontPosition == curFontPosition) 450 if (fontPosition == curFontPosition)
447 continue; 451 continue;
448 auto* font = fontPosition == -1 452 auto* font = fontPosition == -1
449 ? &pFont->m_Font 453 ? &pFont->m_Font
450 : pFont->m_FontFallbacks[fontPosition].get(); 454 : pFont->m_FontFallbacks[fontPosition].get();
451 if (!pDevice->DrawTextPath(i - startIndex, 455 if (!pDevice->DrawTextPath(
452 CharPosList.m_pCharPos + startIndex, font, 456 i - startIndex, CharPosList.m_pCharPos + startIndex, font, pCache,
453 font_size, pText2User, pUser2Device, pGraphState, 457 font_size, pText2User, pUser2Device, pGraphState, fill_argb,
454 fill_argb, stroke_argb, pClippingPath, nFlag)) { 458 stroke_argb, pClippingPath, nFlag)) {
455 bDraw = false; 459 bDraw = false;
456 } 460 }
457 fontPosition = curFontPosition; 461 fontPosition = curFontPosition;
458 startIndex = i; 462 startIndex = i;
459 } 463 }
460 auto* font = fontPosition == -1 ? &pFont->m_Font 464 auto* font = fontPosition == -1 ? &pFont->m_Font
461 : pFont->m_FontFallbacks[fontPosition].get(); 465 : pFont->m_FontFallbacks[fontPosition].get();
462 if (!pDevice->DrawTextPath(CharPosList.m_nChars - startIndex, 466 if (!pDevice->DrawTextPath(CharPosList.m_nChars - startIndex,
463 CharPosList.m_pCharPos + startIndex, font, 467 CharPosList.m_pCharPos + startIndex, font, pCache,
464 font_size, pText2User, pUser2Device, pGraphState, 468 font_size, pText2User, pUser2Device, pGraphState,
465 fill_argb, stroke_argb, pClippingPath, nFlag)) { 469 fill_argb, stroke_argb, pClippingPath, nFlag)) {
466 bDraw = false; 470 bDraw = false;
467 } 471 }
468 return bDraw; 472 return bDraw;
469 } 473 }
470 474
471 // static 475 // static
472 void CPDF_TextRenderer::DrawTextString(CFX_RenderDevice* pDevice, 476 void CPDF_TextRenderer::DrawTextString(CFX_RenderDevice* pDevice,
473 FX_FLOAT origin_x, 477 FX_FLOAT origin_x,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 // static 533 // static
530 FX_BOOL CPDF_TextRenderer::DrawNormalText(CFX_RenderDevice* pDevice, 534 FX_BOOL CPDF_TextRenderer::DrawNormalText(CFX_RenderDevice* pDevice,
531 int nChars, 535 int nChars,
532 uint32_t* pCharCodes, 536 uint32_t* pCharCodes,
533 FX_FLOAT* pCharPos, 537 FX_FLOAT* pCharPos,
534 CPDF_Font* pFont, 538 CPDF_Font* pFont,
535 FX_FLOAT font_size, 539 FX_FLOAT font_size,
536 const CFX_Matrix* pText2Device, 540 const CFX_Matrix* pText2Device,
537 FX_ARGB fill_argb, 541 FX_ARGB fill_argb,
538 const CPDF_RenderOptions* pOptions) { 542 const CPDF_RenderOptions* pOptions) {
543 CFX_FontCache* pCache =
544 pFont->m_pDocument ? pFont->m_pDocument->GetRenderData()->GetFontCache()
545 : nullptr;
539 CPDF_CharPosList CharPosList; 546 CPDF_CharPosList CharPosList;
540 CharPosList.Load(nChars, pCharCodes, pCharPos, pFont, font_size); 547 CharPosList.Load(nChars, pCharCodes, pCharPos, pFont, font_size);
541 if (CharPosList.m_nChars == 0) 548 if (CharPosList.m_nChars == 0)
542 return TRUE; 549 return TRUE;
543 int FXGE_flags = 0; 550 int FXGE_flags = 0;
544 if (pOptions) { 551 if (pOptions) {
545 uint32_t dwFlags = pOptions->m_Flags; 552 uint32_t dwFlags = pOptions->m_Flags;
546 if (dwFlags & RENDER_CLEARTYPE) { 553 if (dwFlags & RENDER_CLEARTYPE) {
547 FXGE_flags |= FXTEXT_CLEARTYPE; 554 FXGE_flags |= FXTEXT_CLEARTYPE;
548 if (dwFlags & RENDER_BGR_STRIPE) { 555 if (dwFlags & RENDER_BGR_STRIPE) {
(...skipping 22 matching lines...) Expand all
571 int32_t fontPosition = CharPosList.m_pCharPos[0].m_FallbackFontPosition; 578 int32_t fontPosition = CharPosList.m_pCharPos[0].m_FallbackFontPosition;
572 uint32_t startIndex = 0; 579 uint32_t startIndex = 0;
573 for (uint32_t i = 0; i < CharPosList.m_nChars; i++) { 580 for (uint32_t i = 0; i < CharPosList.m_nChars; i++) {
574 int32_t curFontPosition = CharPosList.m_pCharPos[i].m_FallbackFontPosition; 581 int32_t curFontPosition = CharPosList.m_pCharPos[i].m_FallbackFontPosition;
575 if (fontPosition == curFontPosition) 582 if (fontPosition == curFontPosition)
576 continue; 583 continue;
577 auto* font = fontPosition == -1 584 auto* font = fontPosition == -1
578 ? &pFont->m_Font 585 ? &pFont->m_Font
579 : pFont->m_FontFallbacks[fontPosition].get(); 586 : pFont->m_FontFallbacks[fontPosition].get();
580 if (!pDevice->DrawNormalText( 587 if (!pDevice->DrawNormalText(
581 i - startIndex, CharPosList.m_pCharPos + startIndex, font, 588 i - startIndex, CharPosList.m_pCharPos + startIndex, font, pCache,
582 font_size, pText2Device, fill_argb, FXGE_flags)) { 589 font_size, pText2Device, fill_argb, FXGE_flags)) {
583 bDraw = false; 590 bDraw = false;
584 } 591 }
585 fontPosition = curFontPosition; 592 fontPosition = curFontPosition;
586 startIndex = i; 593 startIndex = i;
587 } 594 }
588 auto* font = fontPosition == -1 ? &pFont->m_Font 595 auto* font = fontPosition == -1 ? &pFont->m_Font
589 : pFont->m_FontFallbacks[fontPosition].get(); 596 : pFont->m_FontFallbacks[fontPosition].get();
590 if (!pDevice->DrawNormalText(CharPosList.m_nChars - startIndex, 597 if (!pDevice->DrawNormalText(CharPosList.m_nChars - startIndex,
591 CharPosList.m_pCharPos + startIndex, font, 598 CharPosList.m_pCharPos + startIndex, font,
592 font_size, pText2Device, fill_argb, 599 pCache, font_size, pText2Device, fill_argb,
593 FXGE_flags)) { 600 FXGE_flags)) {
594 bDraw = false; 601 bDraw = false;
595 } 602 }
596 return bDraw; 603 return bDraw;
597 } 604 }
598 605
599 void CPDF_RenderStatus::DrawTextPathWithPattern(const CPDF_TextObject* textobj, 606 void CPDF_RenderStatus::DrawTextPathWithPattern(const CPDF_TextObject* textobj,
600 const CFX_Matrix* pObj2Device, 607 const CFX_Matrix* pObj2Device,
601 CPDF_Font* pFont, 608 CPDF_Font* pFont,
602 FX_FLOAT font_size, 609 FX_FLOAT font_size,
(...skipping 10 matching lines...) Expand all
613 path.m_ColorState = textobj->m_ColorState; 620 path.m_ColorState = textobj->m_ColorState;
614 path.m_Path.AppendRect(textobj->m_Left, textobj->m_Bottom, textobj->m_Right, 621 path.m_Path.AppendRect(textobj->m_Left, textobj->m_Bottom, textobj->m_Right,
615 textobj->m_Top); 622 textobj->m_Top);
616 path.m_Left = textobj->m_Left; 623 path.m_Left = textobj->m_Left;
617 path.m_Bottom = textobj->m_Bottom; 624 path.m_Bottom = textobj->m_Bottom;
618 path.m_Right = textobj->m_Right; 625 path.m_Right = textobj->m_Right;
619 path.m_Top = textobj->m_Top; 626 path.m_Top = textobj->m_Top;
620 RenderSingleObject(&path, pObj2Device); 627 RenderSingleObject(&path, pObj2Device);
621 return; 628 return;
622 } 629 }
630 CFX_FontCache* pCache;
631 if (pFont->m_pDocument) {
632 pCache = pFont->m_pDocument->GetRenderData()->GetFontCache();
633 } else {
634 pCache = CFX_GEModule::Get()->GetFontCache();
635 }
623 CPDF_CharPosList CharPosList; 636 CPDF_CharPosList CharPosList;
624 CharPosList.Load(textobj->m_nChars, textobj->m_pCharCodes, 637 CharPosList.Load(textobj->m_nChars, textobj->m_pCharCodes,
625 textobj->m_pCharPos, pFont, font_size); 638 textobj->m_pCharPos, pFont, font_size);
639 std::vector<CFX_FaceCache*> faceCaches;
640 std::vector<CFX_AutoFontCache> autoFontCaches;
641 faceCaches.push_back(pCache->GetCachedFace(&pFont->m_Font));
642 autoFontCaches.push_back(CFX_AutoFontCache(pCache, &pFont->m_Font));
643 for (const auto& font : pFont->m_FontFallbacks) {
644 faceCaches.push_back(pCache->GetCachedFace(font.get()));
645 autoFontCaches.push_back(CFX_AutoFontCache(pCache, font.get()));
646 }
626 for (uint32_t i = 0; i < CharPosList.m_nChars; i++) { 647 for (uint32_t i = 0; i < CharPosList.m_nChars; i++) {
627 FXTEXT_CHARPOS& charpos = CharPosList.m_pCharPos[i]; 648 FXTEXT_CHARPOS& charpos = CharPosList.m_pCharPos[i];
628 auto font = 649 auto font =
629 charpos.m_FallbackFontPosition == -1 650 charpos.m_FallbackFontPosition == -1
630 ? &pFont->m_Font 651 ? &pFont->m_Font
631 : pFont->m_FontFallbacks[charpos.m_FallbackFontPosition].get(); 652 : pFont->m_FontFallbacks[charpos.m_FallbackFontPosition].get();
632 const CFX_PathData* pPath = 653 const CFX_PathData* pPath =
633 font->LoadGlyphPath(charpos.m_GlyphIndex, charpos.m_FontCharWidth); 654 faceCaches[charpos.m_FallbackFontPosition + 1]->LoadGlyphPath(
655 font, charpos.m_GlyphIndex, charpos.m_FontCharWidth);
634 if (!pPath) { 656 if (!pPath) {
635 continue; 657 continue;
636 } 658 }
637 CPDF_PathObject path; 659 CPDF_PathObject path;
638 path.m_GraphState = textobj->m_GraphState; 660 path.m_GraphState = textobj->m_GraphState;
639 path.m_ColorState = textobj->m_ColorState; 661 path.m_ColorState = textobj->m_ColorState;
640 CFX_Matrix matrix; 662 CFX_Matrix matrix;
641 if (charpos.m_bGlyphAdjust) 663 if (charpos.m_bGlyphAdjust)
642 matrix.Set(charpos.m_AdjustMatrix[0], charpos.m_AdjustMatrix[1], 664 matrix.Set(charpos.m_AdjustMatrix[0], charpos.m_AdjustMatrix[1],
643 charpos.m_AdjustMatrix[2], charpos.m_AdjustMatrix[3], 0, 0); 665 charpos.m_AdjustMatrix[2], charpos.m_AdjustMatrix[3], 0, 0);
644 matrix.Concat(font_size, 0, 0, font_size, charpos.m_OriginX, 666 matrix.Concat(font_size, 0, 0, font_size, charpos.m_OriginX,
645 charpos.m_OriginY); 667 charpos.m_OriginY);
646 path.m_Path.Append(pPath, &matrix); 668 path.m_Path.Append(pPath, &matrix);
647 path.m_Matrix = *pTextMatrix; 669 path.m_Matrix = *pTextMatrix;
648 path.m_bStroke = bStroke; 670 path.m_bStroke = bStroke;
649 path.m_FillType = bFill ? FXFILL_WINDING : 0; 671 path.m_FillType = bFill ? FXFILL_WINDING : 0;
650 path.CalcBoundingBox(); 672 path.CalcBoundingBox();
651 ProcessPath(&path, pObj2Device); 673 ProcessPath(&path, pObj2Device);
652 } 674 }
653 } 675 }
OLDNEW
« no previous file with comments | « core/fpdfapi/fpdf_render/fpdf_render.cpp ('k') | core/fpdfapi/fpdf_render/render_int.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698