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 //
28 // To see a description of the changes please see the Changelog file that
29 // came with your tarball or type make ChangeLog if you are building from git
30 //
31 //========================================================================
32 
33 #ifndef _HTML_FONTS_H
34 #define _HTML_FONTS_H
35 #include "goo/GooString.h"
36 #include "GfxState.h"
37 #include "CharTypes.h"
38 #include <vector>
39 
40 class HtmlFontColor
41 {
42 private:
43     unsigned int r;
44     unsigned int g;
45     unsigned int b;
46     unsigned int opacity;
Ok(unsigned int xcol)47     bool Ok(unsigned int xcol) { return xcol <= 255; }
48     GooString *convtoX(unsigned int xcol) const;
49 
50 public:
HtmlFontColor()51     HtmlFontColor() : r(0), g(0), b(0), opacity(255) { }
52     HtmlFontColor(GfxRGB rgb, double opacity);
HtmlFontColor(const HtmlFontColor & x)53     HtmlFontColor(const HtmlFontColor &x)
54     {
55         r = x.r;
56         g = x.g;
57         b = x.b;
58         opacity = x.opacity;
59     }
60     HtmlFontColor &operator=(const HtmlFontColor &x)
61     {
62         r = x.r;
63         g = x.g;
64         b = x.b;
65         opacity = x.opacity;
66         return *this;
67     }
~HtmlFontColor()68     ~HtmlFontColor() {};
69     GooString *toString() const;
getOpacity()70     double getOpacity() const { return opacity / 255.0; }
isEqual(const HtmlFontColor & col)71     bool isEqual(const HtmlFontColor &col) const { return ((r == col.r) && (g == col.g) && (b == col.b) && (opacity == col.opacity)); }
72 };
73 
74 class HtmlFont
75 {
76 private:
77     int size;
78     int lineSize;
79     bool italic;
80     bool bold;
81     bool rotOrSkewed;
82     std::string familyName;
83     GooString *FontName;
84     HtmlFontColor color;
85     double rotSkewMat[4]; // only four values needed for rotation and skew
86 public:
87     HtmlFont(GfxFont *font, int _size, GfxRGB rgb, double opacity);
88     HtmlFont(const HtmlFont &x);
89     HtmlFont &operator=(const HtmlFont &x);
getColor()90     HtmlFontColor getColor() const { return color; }
91     ~HtmlFont();
92     GooString *getFullName();
isItalic()93     bool isItalic() const { return italic; }
isBold()94     bool isBold() const { return bold; }
isRotOrSkewed()95     bool isRotOrSkewed() const { return rotOrSkewed; }
getSize()96     int getSize() const { return size; }
getLineSize()97     int getLineSize() const { return lineSize; }
setLineSize(int _lineSize)98     void setLineSize(int _lineSize) { lineSize = _lineSize; }
setRotMat(const double * const mat)99     void setRotMat(const double *const mat)
100     {
101         rotOrSkewed = true;
102         memcpy(rotSkewMat, mat, sizeof(rotSkewMat));
103     }
getRotMat()104     const double *getRotMat() const { return rotSkewMat; }
105     GooString *getFontName();
106     static GooString *HtmlFilter(const Unicode *u, int uLen); // char* s);
107     bool isEqual(const HtmlFont &x) const;
108     bool isEqualIgnoreBold(const HtmlFont &x) const;
print()109     void print() const { printf("font: %s (%s) %d %s%s\n", FontName->c_str(), familyName.c_str(), size, bold ? "bold " : "", italic ? "italic " : ""); };
110 };
111 
112 class HtmlFontAccu
113 {
114 private:
115     std::vector<HtmlFont> accu;
116 
117 public:
118     HtmlFontAccu();
119     ~HtmlFontAccu();
120     HtmlFontAccu(const HtmlFontAccu &) = delete;
121     HtmlFontAccu &operator=(const HtmlFontAccu &) = delete;
122     int AddFont(const HtmlFont &font);
Get(int i)123     const HtmlFont *Get(int i) const { return &accu[i]; }
124     GooString *CSStyle(int i, int j = 0);
size()125     int size() const { return accu.size(); }
126 };
127 #endif
128