1//========================================================================
2//
3// This file comes from pdftohtml project
4// http://pdftohtml.sourceforge.net
5//
6// Copyright from:
7// Gueorgui Ovtcharov
8// Rainer Dorsch <http://www.ra.informatik.uni-stuttgart.de/~rainer/>
9// Mikhail Kruk <meshko@cs.brandeis.edu>
10//
11//========================================================================
12
13//========================================================================
14//
15// Modified under the Poppler project - http://poppler.freedesktop.org
16//
17// All changes made under the Poppler project to this file are licensed
18// under GPL version 2 or later
19//
20// Copyright (C) 2010 OSSD CDAC Mumbai by Leena Chourey (leenac@cdacmumbai.in) and Onkar Potdar (onkar@cdacmumbai.in)
21// Copyright (C) 2010, 2012, 2017, 2018, 2020 Albert Astals Cid <aacid@kde.org>
22// Copyright (C) 2011 Steven Murdoch <Steven.Murdoch@cl.cam.ac.uk>
23// Copyright (C) 2011 Joshua Richardson <jric@chegg.com>
24// Copyright (C) 2012 Igor Slepchin <igor.slepchin@gmail.com>
25// Copyright (C) 2018 Adam Reichold <adam.reichold@t-online.de>
26// Copyright (C) 2020 Eddie Kohler <ekohler@gmail.com>
27// Copyright (C) 2022 Oliver Sander <oliver.sander@tu-dresden.de>
28// Copyright (C) 2024 g10 Code GmbH, Author: Sune Stolborg Vuorela <sune@vuorela.dk>
29//
30// To see a description of the changes please see the Changelog file that
31// came with your tarball or type make ChangeLog if you are building from git
32//
33//========================================================================
34
35#ifndef _HTML_FONTS_H
36#define _HTML_FONTS_H
37#include "goo/GooString.h"
38#include "GfxState.h"
39#include "CharTypes.h"
40#include <vector>
41
42class HtmlFontColor
43{
44private:
45 unsigned int r;
46 unsigned int g;
47 unsigned int b;
48 unsigned int opacity;
49 bool Ok(unsigned int xcol) { return xcol <= 255; }
50 GooString *convtoX(unsigned int xcol) const;
51
52public:
53 HtmlFontColor() : r(0), g(0), b(0), opacity(255) { }
54 HtmlFontColor(GfxRGB rgb, double opacity);
55 HtmlFontColor(const HtmlFontColor &x)
56 {
57 r = x.r;
58 g = x.g;
59 b = x.b;
60 opacity = x.opacity;
61 }
62 HtmlFontColor &operator=(const HtmlFontColor &x)
63 {
64 r = x.r;
65 g = x.g;
66 b = x.b;
67 opacity = x.opacity;
68 return *this;
69 }
70 ~HtmlFontColor() {};
71 GooString *toString() const;
72 double getOpacity() const { return opacity / 255.0; }
73 bool isEqual(const HtmlFontColor &col) const { return ((r == col.r) && (g == col.g) && (b == col.b) && (opacity == col.opacity)); }
74};
75
76class HtmlFont
77{
78private:
79 int size;
80 int lineSize;
81 bool italic;
82 bool bold;
83 bool rotOrSkewed;
84 std::string familyName;
85 GooString *FontName;
86 HtmlFontColor color;
87 double rotSkewMat[4]; // only four values needed for rotation and skew
88public:
89 HtmlFont(const GfxFont &font, int _size, GfxRGB rgb, double opacity);
90 HtmlFont(const HtmlFont &x);
91 HtmlFont &operator=(const HtmlFont &x);
92 HtmlFontColor getColor() const { return color; }
93 ~HtmlFont();
94 GooString *getFullName();
95 bool isItalic() const { return italic; }
96 bool isBold() const { return bold; }
97 bool isRotOrSkewed() const { return rotOrSkewed; }
98 int getSize() const { return size; }
99 int getLineSize() const { return lineSize; }
100 void setLineSize(int _lineSize) { lineSize = _lineSize; }
101 void setRotMat(const double *const mat)
102 {
103 rotOrSkewed = true;
104 memcpy(dest: rotSkewMat, src: mat, n: sizeof(rotSkewMat));
105 }
106 const double *getRotMat() const { return rotSkewMat; }
107 GooString *getFontName();
108 static std::unique_ptr<GooString> HtmlFilter(const Unicode *u, int uLen); // char* s);
109 bool isEqual(const HtmlFont &x) const;
110 bool isEqualIgnoreBold(const HtmlFont &x) const;
111 void print() const { printf(format: "font: %s (%s) %d %s%s\n", FontName->c_str(), familyName.c_str(), size, bold ? "bold " : "", italic ? "italic " : ""); };
112};
113
114class HtmlFontAccu
115{
116private:
117 std::vector<HtmlFont> accu;
118
119public:
120 HtmlFontAccu();
121 ~HtmlFontAccu();
122 HtmlFontAccu(const HtmlFontAccu &) = delete;
123 HtmlFontAccu &operator=(const HtmlFontAccu &) = delete;
124 int AddFont(const HtmlFont &font);
125 const HtmlFont *Get(int i) const { return &accu[i]; }
126 GooString *CSStyle(int i, int j = 0);
127 int size() const { return accu.size(); }
128};
129#endif
130

source code of poppler/utils/HtmlFonts.h