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

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

Issue 2350243002: Make CFX_FontCache global (Closed)
Patch Set: Remove fix leaks code. 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"
29 #include "core/fxge/include/cfx_fxgedevice.h" 28 #include "core/fxge/include/cfx_fxgedevice.h"
30 #include "core/fxge/include/cfx_gemodule.h" 29 #include "core/fxge/include/cfx_gemodule.h"
31 #include "core/fxge/include/cfx_graphstatedata.h" 30 #include "core/fxge/include/cfx_graphstatedata.h"
32 #include "core/fxge/include/cfx_pathdata.h" 31 #include "core/fxge/include/cfx_pathdata.h"
33 #include "core/fxge/include/cfx_renderdevice.h" 32 #include "core/fxge/include/cfx_renderdevice.h"
34 33
35 FX_BOOL CPDF_RenderStatus::ProcessText(CPDF_TextObject* textobj, 34 FX_BOOL CPDF_RenderStatus::ProcessText(CPDF_TextObject* textobj,
36 const CFX_Matrix* pObj2Device, 35 const CFX_Matrix* pObj2Device,
37 CFX_PathData* pClippingPath) { 36 CFX_PathData* pClippingPath) {
38 if (textobj->m_nChars == 0) 37 if (textobj->m_nChars == 0)
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 FX_FLOAT* pCharPos, 427 FX_FLOAT* pCharPos,
429 CPDF_Font* pFont, 428 CPDF_Font* pFont,
430 FX_FLOAT font_size, 429 FX_FLOAT font_size,
431 const CFX_Matrix* pText2User, 430 const CFX_Matrix* pText2User,
432 const CFX_Matrix* pUser2Device, 431 const CFX_Matrix* pUser2Device,
433 const CFX_GraphStateData* pGraphState, 432 const CFX_GraphStateData* pGraphState,
434 FX_ARGB fill_argb, 433 FX_ARGB fill_argb,
435 FX_ARGB stroke_argb, 434 FX_ARGB stroke_argb,
436 CFX_PathData* pClippingPath, 435 CFX_PathData* pClippingPath,
437 int nFlag) { 436 int nFlag) {
438 CFX_FontCache* pCache =
439 pFont->m_pDocument ? pFont->m_pDocument->GetRenderData()->GetFontCache()
440 : nullptr;
441 CPDF_CharPosList CharPosList; 437 CPDF_CharPosList CharPosList;
442 CharPosList.Load(nChars, pCharCodes, pCharPos, pFont, font_size); 438 CharPosList.Load(nChars, pCharCodes, pCharPos, pFont, font_size);
443 if (CharPosList.m_nChars == 0) 439 if (CharPosList.m_nChars == 0)
444 return TRUE; 440 return TRUE;
445 bool bDraw = true; 441 bool bDraw = true;
446 int32_t fontPosition = CharPosList.m_pCharPos[0].m_FallbackFontPosition; 442 int32_t fontPosition = CharPosList.m_pCharPos[0].m_FallbackFontPosition;
447 uint32_t startIndex = 0; 443 uint32_t startIndex = 0;
448 for (uint32_t i = 0; i < CharPosList.m_nChars; i++) { 444 for (uint32_t i = 0; i < CharPosList.m_nChars; i++) {
449 int32_t curFontPosition = CharPosList.m_pCharPos[i].m_FallbackFontPosition; 445 int32_t curFontPosition = CharPosList.m_pCharPos[i].m_FallbackFontPosition;
450 if (fontPosition == curFontPosition) 446 if (fontPosition == curFontPosition)
451 continue; 447 continue;
452 auto* font = fontPosition == -1 448 auto* font = fontPosition == -1
453 ? &pFont->m_Font 449 ? &pFont->m_Font
454 : pFont->m_FontFallbacks[fontPosition].get(); 450 : pFont->m_FontFallbacks[fontPosition].get();
455 if (!pDevice->DrawTextPath( 451 if (!pDevice->DrawTextPath(i - startIndex,
456 i - startIndex, CharPosList.m_pCharPos + startIndex, font, pCache, 452 CharPosList.m_pCharPos + startIndex, font,
457 font_size, pText2User, pUser2Device, pGraphState, fill_argb, 453 font_size, pText2User, pUser2Device, pGraphState,
458 stroke_argb, pClippingPath, nFlag)) { 454 fill_argb, stroke_argb, pClippingPath, nFlag)) {
459 bDraw = false; 455 bDraw = false;
460 } 456 }
461 fontPosition = curFontPosition; 457 fontPosition = curFontPosition;
462 startIndex = i; 458 startIndex = i;
463 } 459 }
464 auto* font = fontPosition == -1 ? &pFont->m_Font 460 auto* font = fontPosition == -1 ? &pFont->m_Font
465 : pFont->m_FontFallbacks[fontPosition].get(); 461 : pFont->m_FontFallbacks[fontPosition].get();
466 if (!pDevice->DrawTextPath(CharPosList.m_nChars - startIndex, 462 if (!pDevice->DrawTextPath(CharPosList.m_nChars - startIndex,
467 CharPosList.m_pCharPos + startIndex, font, pCache, 463 CharPosList.m_pCharPos + startIndex, font,
468 font_size, pText2User, pUser2Device, pGraphState, 464 font_size, pText2User, pUser2Device, pGraphState,
469 fill_argb, stroke_argb, pClippingPath, nFlag)) { 465 fill_argb, stroke_argb, pClippingPath, nFlag)) {
470 bDraw = false; 466 bDraw = false;
471 } 467 }
472 return bDraw; 468 return bDraw;
473 } 469 }
474 470
475 // static 471 // static
476 void CPDF_TextRenderer::DrawTextString(CFX_RenderDevice* pDevice, 472 void CPDF_TextRenderer::DrawTextString(CFX_RenderDevice* pDevice,
477 FX_FLOAT origin_x, 473 FX_FLOAT origin_x,
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
533 // static 529 // static
534 FX_BOOL CPDF_TextRenderer::DrawNormalText(CFX_RenderDevice* pDevice, 530 FX_BOOL CPDF_TextRenderer::DrawNormalText(CFX_RenderDevice* pDevice,
535 int nChars, 531 int nChars,
536 uint32_t* pCharCodes, 532 uint32_t* pCharCodes,
537 FX_FLOAT* pCharPos, 533 FX_FLOAT* pCharPos,
538 CPDF_Font* pFont, 534 CPDF_Font* pFont,
539 FX_FLOAT font_size, 535 FX_FLOAT font_size,
540 const CFX_Matrix* pText2Device, 536 const CFX_Matrix* pText2Device,
541 FX_ARGB fill_argb, 537 FX_ARGB fill_argb,
542 const CPDF_RenderOptions* pOptions) { 538 const CPDF_RenderOptions* pOptions) {
543 CFX_FontCache* pCache =
544 pFont->m_pDocument ? pFont->m_pDocument->GetRenderData()->GetFontCache()
545 : nullptr;
546 CPDF_CharPosList CharPosList; 539 CPDF_CharPosList CharPosList;
547 CharPosList.Load(nChars, pCharCodes, pCharPos, pFont, font_size); 540 CharPosList.Load(nChars, pCharCodes, pCharPos, pFont, font_size);
548 if (CharPosList.m_nChars == 0) 541 if (CharPosList.m_nChars == 0)
549 return TRUE; 542 return TRUE;
550 int FXGE_flags = 0; 543 int FXGE_flags = 0;
551 if (pOptions) { 544 if (pOptions) {
552 uint32_t dwFlags = pOptions->m_Flags; 545 uint32_t dwFlags = pOptions->m_Flags;
553 if (dwFlags & RENDER_CLEARTYPE) { 546 if (dwFlags & RENDER_CLEARTYPE) {
554 FXGE_flags |= FXTEXT_CLEARTYPE; 547 FXGE_flags |= FXTEXT_CLEARTYPE;
555 if (dwFlags & RENDER_BGR_STRIPE) { 548 if (dwFlags & RENDER_BGR_STRIPE) {
(...skipping 22 matching lines...) Expand all
578 int32_t fontPosition = CharPosList.m_pCharPos[0].m_FallbackFontPosition; 571 int32_t fontPosition = CharPosList.m_pCharPos[0].m_FallbackFontPosition;
579 uint32_t startIndex = 0; 572 uint32_t startIndex = 0;
580 for (uint32_t i = 0; i < CharPosList.m_nChars; i++) { 573 for (uint32_t i = 0; i < CharPosList.m_nChars; i++) {
581 int32_t curFontPosition = CharPosList.m_pCharPos[i].m_FallbackFontPosition; 574 int32_t curFontPosition = CharPosList.m_pCharPos[i].m_FallbackFontPosition;
582 if (fontPosition == curFontPosition) 575 if (fontPosition == curFontPosition)
583 continue; 576 continue;
584 auto* font = fontPosition == -1 577 auto* font = fontPosition == -1
585 ? &pFont->m_Font 578 ? &pFont->m_Font
586 : pFont->m_FontFallbacks[fontPosition].get(); 579 : pFont->m_FontFallbacks[fontPosition].get();
587 if (!pDevice->DrawNormalText( 580 if (!pDevice->DrawNormalText(
588 i - startIndex, CharPosList.m_pCharPos + startIndex, font, pCache, 581 i - startIndex, CharPosList.m_pCharPos + startIndex, font,
589 font_size, pText2Device, fill_argb, FXGE_flags)) { 582 font_size, pText2Device, fill_argb, FXGE_flags)) {
590 bDraw = false; 583 bDraw = false;
591 } 584 }
592 fontPosition = curFontPosition; 585 fontPosition = curFontPosition;
593 startIndex = i; 586 startIndex = i;
594 } 587 }
595 auto* font = fontPosition == -1 ? &pFont->m_Font 588 auto* font = fontPosition == -1 ? &pFont->m_Font
596 : pFont->m_FontFallbacks[fontPosition].get(); 589 : pFont->m_FontFallbacks[fontPosition].get();
597 if (!pDevice->DrawNormalText(CharPosList.m_nChars - startIndex, 590 if (!pDevice->DrawNormalText(CharPosList.m_nChars - startIndex,
598 CharPosList.m_pCharPos + startIndex, font, 591 CharPosList.m_pCharPos + startIndex, font,
599 pCache, font_size, pText2Device, fill_argb, 592 font_size, pText2Device, fill_argb,
600 FXGE_flags)) { 593 FXGE_flags)) {
601 bDraw = false; 594 bDraw = false;
602 } 595 }
603 return bDraw; 596 return bDraw;
604 } 597 }
605 598
606 void CPDF_RenderStatus::DrawTextPathWithPattern(const CPDF_TextObject* textobj, 599 void CPDF_RenderStatus::DrawTextPathWithPattern(const CPDF_TextObject* textobj,
607 const CFX_Matrix* pObj2Device, 600 const CFX_Matrix* pObj2Device,
608 CPDF_Font* pFont, 601 CPDF_Font* pFont,
609 FX_FLOAT font_size, 602 FX_FLOAT font_size,
(...skipping 10 matching lines...) Expand all
620 path.m_ColorState = textobj->m_ColorState; 613 path.m_ColorState = textobj->m_ColorState;
621 path.m_Path.AppendRect(textobj->m_Left, textobj->m_Bottom, textobj->m_Right, 614 path.m_Path.AppendRect(textobj->m_Left, textobj->m_Bottom, textobj->m_Right,
622 textobj->m_Top); 615 textobj->m_Top);
623 path.m_Left = textobj->m_Left; 616 path.m_Left = textobj->m_Left;
624 path.m_Bottom = textobj->m_Bottom; 617 path.m_Bottom = textobj->m_Bottom;
625 path.m_Right = textobj->m_Right; 618 path.m_Right = textobj->m_Right;
626 path.m_Top = textobj->m_Top; 619 path.m_Top = textobj->m_Top;
627 RenderSingleObject(&path, pObj2Device); 620 RenderSingleObject(&path, pObj2Device);
628 return; 621 return;
629 } 622 }
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 }
636 CPDF_CharPosList CharPosList; 623 CPDF_CharPosList CharPosList;
637 CharPosList.Load(textobj->m_nChars, textobj->m_pCharCodes, 624 CharPosList.Load(textobj->m_nChars, textobj->m_pCharCodes,
638 textobj->m_pCharPos, pFont, font_size); 625 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 }
647 for (uint32_t i = 0; i < CharPosList.m_nChars; i++) { 626 for (uint32_t i = 0; i < CharPosList.m_nChars; i++) {
648 FXTEXT_CHARPOS& charpos = CharPosList.m_pCharPos[i]; 627 FXTEXT_CHARPOS& charpos = CharPosList.m_pCharPos[i];
649 auto font = 628 auto font =
650 charpos.m_FallbackFontPosition == -1 629 charpos.m_FallbackFontPosition == -1
651 ? &pFont->m_Font 630 ? &pFont->m_Font
652 : pFont->m_FontFallbacks[charpos.m_FallbackFontPosition].get(); 631 : pFont->m_FontFallbacks[charpos.m_FallbackFontPosition].get();
653 const CFX_PathData* pPath = 632 const CFX_PathData* pPath =
654 faceCaches[charpos.m_FallbackFontPosition + 1]->LoadGlyphPath( 633 font->LoadGlyphPath(charpos.m_GlyphIndex, charpos.m_FontCharWidth);
655 font, charpos.m_GlyphIndex, charpos.m_FontCharWidth);
656 if (!pPath) { 634 if (!pPath) {
657 continue; 635 continue;
658 } 636 }
659 CPDF_PathObject path; 637 CPDF_PathObject path;
660 path.m_GraphState = textobj->m_GraphState; 638 path.m_GraphState = textobj->m_GraphState;
661 path.m_ColorState = textobj->m_ColorState; 639 path.m_ColorState = textobj->m_ColorState;
662 CFX_Matrix matrix; 640 CFX_Matrix matrix;
663 if (charpos.m_bGlyphAdjust) 641 if (charpos.m_bGlyphAdjust)
664 matrix.Set(charpos.m_AdjustMatrix[0], charpos.m_AdjustMatrix[1], 642 matrix.Set(charpos.m_AdjustMatrix[0], charpos.m_AdjustMatrix[1],
665 charpos.m_AdjustMatrix[2], charpos.m_AdjustMatrix[3], 0, 0); 643 charpos.m_AdjustMatrix[2], charpos.m_AdjustMatrix[3], 0, 0);
666 matrix.Concat(font_size, 0, 0, font_size, charpos.m_OriginX, 644 matrix.Concat(font_size, 0, 0, font_size, charpos.m_OriginX,
667 charpos.m_OriginY); 645 charpos.m_OriginY);
668 path.m_Path.Append(pPath, &matrix); 646 path.m_Path.Append(pPath, &matrix);
669 path.m_Matrix = *pTextMatrix; 647 path.m_Matrix = *pTextMatrix;
670 path.m_bStroke = bStroke; 648 path.m_bStroke = bStroke;
671 path.m_FillType = bFill ? FXFILL_WINDING : 0; 649 path.m_FillType = bFill ? FXFILL_WINDING : 0;
672 path.CalcBoundingBox(); 650 path.CalcBoundingBox();
673 ProcessPath(&path, pObj2Device); 651 ProcessPath(&path, pObj2Device);
674 } 652 }
675 } 653 }
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