[poppler] utils/HtmlFonts.cc utils/HtmlFonts.h utils/HtmlOutputDev.cc

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Oct 26 21:27:08 UTC 2020


 utils/HtmlFonts.cc     |   20 +++++++++++++++-----
 utils/HtmlFonts.h      |   12 ++++++++----
 utils/HtmlOutputDev.cc |    2 +-
 3 files changed, 24 insertions(+), 10 deletions(-)

New commits:
commit 47550058463d181096770624aad811ae4eaf2688
Author: Eddie Kohler <ekohler at gmail.com>
Date:   Mon Oct 26 14:06:03 2020 -0400

    HTML and XML output includes opacity.
    
    In HTML output, the opacity attribute is added to CSS. In XML output,
    opacity is a separate XML attribute on <fontspec>.

diff --git a/utils/HtmlFonts.cc b/utils/HtmlFonts.cc
index bb46c152..23f7dee0 100644
--- a/utils/HtmlFonts.cc
+++ b/utils/HtmlFonts.cc
@@ -69,17 +69,19 @@ void removeStyleSuffix(std::string &familyName)
 extern bool xml;
 extern bool fontFullName;
 
-HtmlFontColor::HtmlFontColor(GfxRGB rgb)
+HtmlFontColor::HtmlFontColor(GfxRGB rgb, double opacity_)
 {
     r = static_cast<int>(rgb.r / 65535.0 * 255.0);
     g = static_cast<int>(rgb.g / 65535.0 * 255.0);
     b = static_cast<int>(rgb.b / 65535.0 * 255.0);
-    if (!(Ok(r) && Ok(b) && Ok(g))) {
+    opacity = static_cast<int>(opacity_ * 255.999);
+    if (!(Ok(r) && Ok(b) && Ok(g) && Ok(opacity))) {
         if (!globalParams->getErrQuiet())
-            fprintf(stderr, "Error : Bad color (%d,%d,%d) reset to (0,0,0)\n", r, g, b);
+            fprintf(stderr, "Error : Bad color (%d,%d,%d,%d) reset to (0,0,0,255)\n", r, g, b, opacity);
         r = 0;
         g = 0;
         b = 0;
+        opacity = 255;
     }
 }
 
@@ -118,9 +120,9 @@ GooString *HtmlFontColor::toString() const
     return tmp;
 }
 
-HtmlFont::HtmlFont(GfxFont *font, int _size, GfxRGB rgb)
+HtmlFont::HtmlFont(GfxFont *font, int _size, GfxRGB rgb, double opacity)
 {
-    color = HtmlFontColor(rgb);
+    color = HtmlFontColor(rgb, opacity);
 
     lineSize = -1;
 
@@ -310,6 +312,10 @@ GooString *HtmlFontAccu::CSStyle(int i, int j)
         tmp->append(fontName); // font.getFontName());
         tmp->append(";color:");
         tmp->append(colorStr);
+        if (font.getColor().getOpacity() != 1.0) {
+            tmp->append(";opacity:");
+            tmp->append(std::to_string(font.getColor().getOpacity()));
+        }
         // if there is rotation or skew, include the matrix
         if (font.isRotOrSkewed()) {
             const double *const text_mat = font.getRotMat();
@@ -343,6 +349,10 @@ GooString *HtmlFontAccu::CSStyle(int i, int j)
         tmp->append(fontName);
         tmp->append("\" color=\"");
         tmp->append(colorStr);
+        if (font.getColor().getOpacity() != 1.0) {
+            tmp->append("\" opacity=\"");
+            tmp->append(std::to_string(font.getColor().getOpacity()));
+        }
         tmp->append("\"/>");
     }
 
diff --git a/utils/HtmlFonts.h b/utils/HtmlFonts.h
index 6f410262..6b5bb372 100644
--- a/utils/HtmlFonts.h
+++ b/utils/HtmlFonts.h
@@ -42,28 +42,32 @@ private:
     unsigned int r;
     unsigned int g;
     unsigned int b;
+    unsigned int opacity;
     bool Ok(unsigned int xcol) { return xcol <= 255; }
     GooString *convtoX(unsigned int xcol) const;
 
 public:
-    HtmlFontColor() : r(0), g(0), b(0) { }
-    HtmlFontColor(GfxRGB rgb);
+    HtmlFontColor() : r(0), g(0), b(0), opacity(255) { }
+    HtmlFontColor(GfxRGB rgb, double opacity);
     HtmlFontColor(const HtmlFontColor &x)
     {
         r = x.r;
         g = x.g;
         b = x.b;
+        opacity = x.opacity;
     }
     HtmlFontColor &operator=(const HtmlFontColor &x)
     {
         r = x.r;
         g = x.g;
         b = x.b;
+        opacity = x.opacity;
         return *this;
     }
     ~HtmlFontColor() {};
     GooString *toString() const;
-    bool isEqual(const HtmlFontColor &col) const { return ((r == col.r) && (g == col.g) && (b == col.b)); }
+    double getOpacity() const { return opacity / 255.0; }
+    bool isEqual(const HtmlFontColor &col) const { return ((r == col.r) && (g == col.g) && (b == col.b) && (opacity == col.opacity)); }
 };
 
 class HtmlFont
@@ -79,7 +83,7 @@ private:
     HtmlFontColor color;
     double rotSkewMat[4]; // only four values needed for rotation and skew
 public:
-    HtmlFont(GfxFont *font, int _size, GfxRGB rgb);
+    HtmlFont(GfxFont *font, int _size, GfxRGB rgb, double opacity);
     HtmlFont(const HtmlFont &x);
     HtmlFont &operator=(const HtmlFont &x);
     HtmlFontColor getColor() const { return color; }
diff --git a/utils/HtmlOutputDev.cc b/utils/HtmlOutputDev.cc
index 27a7f11a..1572c6a1 100644
--- a/utils/HtmlOutputDev.cc
+++ b/utils/HtmlOutputDev.cc
@@ -189,7 +189,7 @@ HtmlString::HtmlString(GfxState *state, double fontSize, HtmlFontAccu *_fonts) :
         yMax = y - descent * fontSize;
         GfxRGB rgb;
         state->getFillRGB(&rgb);
-        HtmlFont hfont = HtmlFont(font, static_cast<int>(fontSize), rgb);
+        HtmlFont hfont = HtmlFont(font, static_cast<int>(fontSize), rgb, state->getFillOpacity());
         if (isMatRotOrSkew(state->getTextMat())) {
             double normalizedMatrix[4];
             memcpy(normalizedMatrix, state->getTextMat(), sizeof(normalizedMatrix));


More information about the poppler mailing list