/src/poppler/poppler/MarkedContentOutputDev.h
Line | Count | Source |
1 | | //======================================================================== |
2 | | // |
3 | | // MarkedContentOutputDev.h |
4 | | // |
5 | | // This file is licensed under the GPLv2 or later |
6 | | // |
7 | | // Copyright 2013 Igalia S.L. |
8 | | // Copyright 2018-2021, 2024, 2025 Albert Astals Cid <aacid@kde.org> |
9 | | // Copyright 2021, 2023 Adrian Johnson <ajohnson@redneon.com> |
10 | | // Copyright 2022 Oliver Sander <oliver.sander@tu-dresden.de> |
11 | | // Copyright 2025 g10 Code GmbH, Author: Sune Stolborg Vuorela <sune@vuorela.dk> |
12 | | // |
13 | | //======================================================================== |
14 | | |
15 | | #ifndef MARKEDCONTENTOUTPUTDEV_H |
16 | | #define MARKEDCONTENTOUTPUTDEV_H |
17 | | |
18 | | #include "poppler_private_export.h" |
19 | | #include "OutputDev.h" |
20 | | #include "GfxState.h" |
21 | | #include "GfxFont.h" |
22 | | #include <vector> |
23 | | |
24 | | class Dict; |
25 | | class UnicodeMap; |
26 | | |
27 | | class TextSpan |
28 | | { |
29 | | public: |
30 | 45.3k | TextSpan(const TextSpan &other) = default; |
31 | | |
32 | | TextSpan &operator=(const TextSpan &other) = default; |
33 | | |
34 | 86.1k | ~TextSpan() = default; |
35 | | |
36 | 0 | const std::shared_ptr<GfxFont> &getFont() const { return data->font; } |
37 | 40.7k | const GooString *getText() const { return data->text.get(); } |
38 | 0 | GfxRGB &getColor() const { return data->color; } |
39 | | |
40 | | private: |
41 | | // Note: Takes ownership of strings, increases refcount for font. |
42 | 40.7k | TextSpan(std::unique_ptr<GooString> text, std::shared_ptr<GfxFont> font, const GfxRGB color) : data(std::make_shared<Data>()) |
43 | 40.7k | { |
44 | 40.7k | data->text = std::move(text); |
45 | 40.7k | data->font = std::move(font); |
46 | 40.7k | data->color = color; |
47 | 40.7k | } |
48 | | |
49 | | struct Data |
50 | | { |
51 | | std::shared_ptr<GfxFont> font; |
52 | | std::unique_ptr<const GooString> text; |
53 | | GfxRGB color; |
54 | | |
55 | 40.7k | Data() = default; |
56 | | |
57 | 40.7k | ~Data() = default; |
58 | | |
59 | | Data(const Data &) = delete; |
60 | | Data &operator=(const Data &) = delete; |
61 | | }; |
62 | | |
63 | | std::shared_ptr<Data> data; |
64 | | |
65 | | friend class MarkedContentOutputDev; |
66 | | }; |
67 | | |
68 | | using TextSpanArray = std::vector<TextSpan>; |
69 | | |
70 | | class POPPLER_PRIVATE_EXPORT MarkedContentOutputDev : public OutputDev |
71 | | { |
72 | | public: |
73 | | explicit MarkedContentOutputDev(int mcidA, const Object &stmObj); |
74 | | ~MarkedContentOutputDev() override; |
75 | | |
76 | 0 | virtual bool isOk() { return true; } |
77 | 547k | bool upsideDown() override { return true; } |
78 | 6.12M | bool useDrawChar() override { return true; } |
79 | 510 | bool interpretType3Chars() override { return false; } |
80 | 27.9k | bool needNonText() override { return false; } |
81 | 0 | bool needCharCount() override { return false; } |
82 | | |
83 | | void startPage(int pageNum, GfxState *state, XRef *xref) override; |
84 | | void endPage() override; |
85 | | |
86 | | void beginForm(Object * /* obj */, Ref id) override; |
87 | | void endForm(Object * /* obj */, Ref id) override; |
88 | | |
89 | | void drawChar(GfxState *state, double xx, double yy, double dx, double dy, double ox, double oy, CharCode c, int nBytes, const Unicode *u, int uLen) override; |
90 | | |
91 | | void beginMarkedContent(const char *name, Dict *properties) override; |
92 | | void endMarkedContent(GfxState *state) override; |
93 | | |
94 | | const TextSpanArray &getTextSpans() const; |
95 | | |
96 | | private: |
97 | | void endSpan(); |
98 | 13.7M | bool inMarkedContent() const { return !mcidStack.empty(); } |
99 | | bool contentStreamMatch(); |
100 | | bool needFontChange(const std::shared_ptr<const GfxFont> &font) const; |
101 | | |
102 | | std::shared_ptr<GfxFont> currentFont; |
103 | | std::unique_ptr<GooString> currentText; |
104 | | GfxRGB currentColor; |
105 | | TextSpanArray textSpans; |
106 | | int mcid; |
107 | | std::vector<int> mcidStack; |
108 | | std::vector<Ref> formStack; |
109 | | double pageWidth = 0.0; |
110 | | double pageHeight = 0.0; |
111 | | const UnicodeMap *unicodeMap = nullptr; |
112 | | Object stmRef; |
113 | | }; |
114 | | |
115 | | #endif /* !MARKEDCONTENTOUTPUTDEV_H */ |