xref: /aosp_15_r20/external/pdfium/samples/helpers/page_renderer.h (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
1 // Copyright 2023 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 #ifndef SAMPLES_HELPERS_PAGE_RENDERER_H_
6 #define SAMPLES_HELPERS_PAGE_RENDERER_H_
7 
8 #include <string>
9 
10 #include "public/fpdfview.h"
11 
12 // Renderer for a single page.
13 class PageRenderer {
14  public:
15   virtual ~PageRenderer();
16 
17   // Returns `true` if the rendered output exists. Must call `Finish()` first.
18   virtual bool HasOutput() const = 0;
19 
20   // Starts rendering the page, returning `false` on failure.
21   virtual bool Start() = 0;
22 
23   // Continues rendering the page, returning `false` when complete.
24   virtual bool Continue();
25 
26   // Finishes rendering the page.
27   virtual void Finish(FPDF_FORMHANDLE form) = 0;
28 
29   // Writes rendered output to a file, returning `false` on failure.
30   virtual bool Write(const std::string& name, int page_index, bool md5) = 0;
31 
32  protected:
33   PageRenderer(FPDF_PAGE page, int width, int height, int flags);
34 
page()35   FPDF_PAGE page() { return page_; }
width()36   int width() const { return width_; }
height()37   int height() const { return height_; }
flags()38   int flags() const { return flags_; }
39 
40  private:
41   FPDF_PAGE page_;
42   int width_;
43   int height_;
44   int flags_;
45 };
46 
47 #endif  // SAMPLES_HELPERS_PAGE_RENDERER_H_
48