Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
cpdfsdk_renderpage.cpp
Go to the documentation of this file.
1// Copyright 2020 The PDFium Authors
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6
7#include "fpdfsdk/cpdfsdk_renderpage.h"
8
9#include <memory>
10#include <utility>
11
12#include "core/fpdfapi/page/cpdf_pageimagecache.h"
13#include "core/fpdfapi/render/cpdf_pagerendercontext.h"
14#include "core/fpdfapi/render/cpdf_progressiverenderer.h"
15#include "core/fpdfapi/render/cpdf_renderoptions.h"
16#include "core/fpdfdoc/cpdf_annotlist.h"
17#include "core/fxge/cfx_renderdevice.h"
18#include "fpdfsdk/cpdfsdk_helpers.h"
19#include "fpdfsdk/cpdfsdk_pauseadapter.h"
20
21namespace {
22
23void RenderPageImpl(CPDF_PageRenderContext* pContext,
24 CPDF_Page* pPage,
25 const CFX_Matrix& matrix,
26 const FX_RECT& clipping_rect,
27 int flags,
28 const FPDF_COLORSCHEME* color_scheme,
29 bool need_to_restore,
30 CPDFSDK_PauseAdapter* pause) {
31 if (!pContext->m_pOptions)
32 pContext->m_pOptions = std::make_unique<CPDF_RenderOptions>();
33
34 auto& options = pContext->m_pOptions->GetOptions();
35 options.bClearType = !!(flags & FPDF_LCD_TEXT);
36 options.bNoNativeText = !!(flags & FPDF_NO_NATIVETEXT);
37 options.bLimitedImageCache = !!(flags & FPDF_RENDER_LIMITEDIMAGECACHE);
38 options.bForceHalftone = !!(flags & FPDF_RENDER_FORCEHALFTONE);
39 options.bNoTextSmooth = !!(flags & FPDF_RENDER_NO_SMOOTHTEXT);
40 options.bNoImageSmooth = !!(flags & FPDF_RENDER_NO_SMOOTHIMAGE);
41 options.bNoPathSmooth = !!(flags & FPDF_RENDER_NO_SMOOTHPATH);
42
43 // Grayscale output
44 if (flags & FPDF_GRAYSCALE)
45 pContext->m_pOptions->SetColorMode(CPDF_RenderOptions::kGray);
46
47 if (color_scheme) {
48 pContext->m_pOptions->SetColorMode(CPDF_RenderOptions::kForcedColor);
49 SetColorFromScheme(color_scheme, pContext->m_pOptions.get());
50 options.bConvertFillToStroke = !!(flags & FPDF_CONVERT_FILL_TO_STROKE);
51 }
52
53 const CPDF_OCContext::UsageType usage =
54 (flags & FPDF_PRINTING) ? CPDF_OCContext::kPrint : CPDF_OCContext::kView;
55 pContext->m_pOptions->SetOCContext(
56 pdfium::MakeRetain<CPDF_OCContext>(pPage->GetDocument(), usage));
57
58 pContext->m_pDevice->SaveState();
59 pContext->m_pDevice->SetBaseClip(clipping_rect);
60 pContext->m_pDevice->SetClip_Rect(clipping_rect);
61 pContext->m_pContext = std::make_unique<CPDF_RenderContext>(
62 pPage->GetDocument(), pPage->GetMutablePageResources(),
64
65 pContext->m_pContext->AppendLayer(pPage, matrix);
66
67 if (flags & FPDF_ANNOT) {
68 auto pOwnedList = std::make_unique<CPDF_AnnotList>(pPage);
69 CPDF_AnnotList* pList = pOwnedList.get();
70 pContext->m_pAnnots = std::move(pOwnedList);
71 bool bPrinting =
72 (flags & FPDF_PRINTING) ||
73 pContext->m_pDevice->GetDeviceType() != DeviceType::kDisplay;
74
75 // TODO(https://crbug.com/pdfium/993) - maybe pass true here.
76 const bool bShowWidget = false;
77 pList->DisplayAnnots(pPage, pContext->m_pDevice.get(),
78 pContext->m_pContext.get(), bPrinting, matrix,
79 bShowWidget);
80 }
81
82 pContext->m_pRenderer = std::make_unique<CPDF_ProgressiveRenderer>(
83 pContext->m_pContext.get(), pContext->m_pDevice.get(),
84 pContext->m_pOptions.get());
85 pContext->m_pRenderer->Start(pause);
86 if (need_to_restore)
87 pContext->m_pDevice->RestoreState(false);
88}
89
90} // namespace
91
92void CPDFSDK_RenderPage(CPDF_PageRenderContext* pContext,
93 CPDF_Page* pPage,
94 const CFX_Matrix& matrix,
95 const FX_RECT& clipping_rect,
96 int flags,
97 const FPDF_COLORSCHEME* color_scheme) {
98 RenderPageImpl(pContext, pPage, matrix, clipping_rect, flags, color_scheme,
99 /*need_to_restore=*/true, /*pause=*/nullptr);
100}
101
102void CPDFSDK_RenderPageWithContext(CPDF_PageRenderContext* pContext,
103 CPDF_Page* pPage,
104 int start_x,
105 int start_y,
106 int size_x,
107 int size_y,
108 int rotate,
109 int flags,
110 const FPDF_COLORSCHEME* color_scheme,
111 bool need_to_restore,
112 CPDFSDK_PauseAdapter* pause) {
113 const FX_RECT rect(start_x, start_y, start_x + size_x, start_y + size_y);
114 RenderPageImpl(pContext, pPage, pPage->GetDisplayMatrix(rect, rotate), rect,
115 flags, color_scheme, need_to_restore, pause);
116}
void DisplayAnnots(CPDF_Page *pPage, CFX_RenderDevice *pDevice, CPDF_RenderContext *pContext, bool bPrinting, const CFX_Matrix &mtUser2Device, bool bShowWidget)
CPDF_Document * GetDocument() const override
Definition cpdf_page.cpp:51
CFX_Matrix GetDisplayMatrix(const FX_RECT &rect, int iRotate) const override
CPDF_PageImageCache * GetPageImageCache()
Definition cpdf_page.h:83
void CPDFSDK_RenderPageWithContext(CPDF_PageRenderContext *pContext, CPDF_Page *pPage, int start_x, int start_y, int size_x, int size_y, int rotate, int flags, const FPDF_COLORSCHEME *color_scheme, bool need_to_restore, CPDFSDK_PauseAdapter *pause)
void CPDFSDK_RenderPage(CPDF_PageRenderContext *pContext, CPDF_Page *pPage, const CFX_Matrix &matrix, const FX_RECT &clipping_rect, int flags, const FPDF_COLORSCHEME *color_scheme)
#define FPDF_RENDER_LIMITEDIMAGECACHE
Definition fpdfview.h:817
#define FPDF_RENDER_NO_SMOOTHTEXT
Definition fpdfview.h:824
#define FPDF_PRINTING
Definition fpdfview.h:821
#define FPDF_RENDER_NO_SMOOTHIMAGE
Definition fpdfview.h:826
#define FPDF_CONVERT_FILL_TO_STROKE
Definition fpdfview.h:835
#define FPDF_RENDER_FORCEHALFTONE
Definition fpdfview.h:819
#define FPDF_GRAYSCALE
Definition fpdfview.h:811
#define FPDF_NO_NATIVETEXT
Definition fpdfview.h:809
#define FPDF_ANNOT
Definition fpdfview.h:804
#define FPDF_LCD_TEXT
Definition fpdfview.h:807
#define FPDF_RENDER_NO_SMOOTHPATH
Definition fpdfview.h:828
constexpr FX_RECT(int l, int t, int r, int b)