• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2025 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef MEDIAPROVIDER_PDF_JNI_PDFCLIENT_TEXT_OBJECT_H_
18 #define MEDIAPROVIDER_PDF_JNI_PDFCLIENT_TEXT_OBJECT_H_
19 
20 #include <stdint.h>
21 
22 #include <string>
23 #include <unordered_map>
24 #include <vector>
25 
26 #include "cpp/fpdf_scopers.h"
27 #include "fpdfview.h"
28 #include "page_object.h"
29 
30 namespace pdfClient {
31 
32 class Font {
33   public:
34     enum class Family {
35         Unknown = -1,
36         Courier,
37         Helvetica,
38         Symbol,
39         TimesRoman,
40     };
41 
Font()42     Font() : family_(Family::Unknown), bold_(false), italic_(false) {};
43     Font(const std::string& font_name, Family family = Family::Unknown, bool bold = false,
44          bool italic = false);
45 
46     std::string GetName();
GetFamily()47     Family GetFamily() const { return family_; }
IsBold()48     bool IsBold() const { return bold_; }
IsItalic()49     bool IsItalic() const { return italic_; }
50 
51   private:
52     std::string font_name_;
53     Family family_;
54     bool bold_;
55     bool italic_;
56 };
57 
58 class TextObject : public PageObject {
59   public:
60     TextObject();
61 
62     ScopedFPDFPageObject CreateFPDFInstance(FPDF_DOCUMENT document, FPDF_PAGE page) override;
63     bool UpdateFPDFInstance(FPDF_PAGEOBJECT text_object, FPDF_PAGE page) override;
64     bool PopulateFromFPDFInstance(FPDF_PAGEOBJECT text_object, FPDF_PAGE page) override;
65 
66     ~TextObject();
67 
68     enum class RenderMode {
69         Unknown = -1,
70         Fill,
71         Stroke,
72         FillStroke,
73     };
74 
75     Font font_;
76     float font_size_;
77     RenderMode render_mode_;
78     std::wstring text_;
79 };
80 
81 // Define font names as constants
82 const std::string Courier = "Courier";
83 const std::string CourierNew = "CourierNew";
84 const std::string Helvetica = "Helvetica";
85 const std::string Symbol = "Symbol";
86 const std::string Times = "Times";
87 const std::string TimesRoman = "Times-Roman";
88 const std::string TimesNewRoman = "TimesNewRoman";
89 
90 // Define font variants as constants
91 const std::string Bold = "-Bold";
92 const std::string Italic = "-Italic";
93 const std::string Oblique = "-Oblique";
94 const std::string BoldItalic = "-BoldItalic";
95 const std::string BoldOblique = "-BoldOblique";
96 
97 // Font Mapper
98 extern std::unordered_map<std::string, Font> font_mapper;
99 
100 // Standard Font Names
101 extern std::vector<std::string> font_names;
102 
103 }  // namespace pdfClient
104 
105 #endif  // MEDIAPROVIDER_PDF_JNI_PDFCLIENT_TEXT_OBJECT_H_