<html>
    <head>
      <base href="https://bugs.freedesktop.org/">
    </head>
    <body>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Add font color in Poppler Qt5 frontend"
   href="https://bugs.freedesktop.org/show_bug.cgi?id=107151#c8">Comment # 8</a>
              on <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Add font color in Poppler Qt5 frontend"
   href="https://bugs.freedesktop.org/show_bug.cgi?id=107151">bug 107151</a>
              from <span class="vcard"><a class="email" href="mailto:haxtibal@posteo.de" title="Tobias Deiminger <haxtibal@posteo.de>"> <span class="fn">Tobias Deiminger</span></a>
</span></b>
        <pre>Ok, here's my take. Problems with solutions (draft).

Problem 1: Qt5 shouldn't care about low-level DA creation

GooString * TextAnnotationPrivate::toAppearanceString(const QFont &font)
...
  // Qt5 shouldn't need to know how to create Tf operator
  GooString * s = GooString::format("{0:f} {1:f} {2:f} rg /Invalid_font {3:d}
Tf", r, g, b, font.pointSize());

used like

GooString * da = toAppearanceString(textFont, textColor);
pdfAnnot = new AnnotFreeText(destPage->getDoc(), &rect, da);
  ... or ...
ftextann->setAppearanceString(da);


Problem 2: Qt5 shouldn't care about low level DA parsing

QFont TextAnnotation::textFont() const    // existing code
...
  QString style = QString::fromLatin1( da->getCString() );
  // Qt5 shouldn't need to know how to parse Tf operator
  QRegExp rx(QStringLiteral("(\\d+)(\\.\\d*)? Tf")); 

and

QColor TextAnnotation::textColor() const  // new code
...
  QString style = QString::fromLatin1( da->getCString() );
  // Qt5 shouldn't need to know how to parse rg operator
  QRegExp rx(QStringLiteral("(\\d\\.\\d*) (\\d\\.\\d*) (\\d\\.\\d*) rg"));


Solution 1

Don't consume raw DA GooString in class AnnotFreeText, but take higher level
data

Instead of
  AnnotFreeText(PDFDoc *docA, PDFRectangle *rect, GooString *da);
  AnnotFreeText::setAppearanceString(GooString *new_string)

make it like

  struct AppearanceStringData {
    GooString *fontTag;
    int fontPtSize;
    AnnotColor* fontColor;
  };

  AnnotFreeText(PDFDoc *docA, PDFRectangle *rect, const AppearanceStringData&
apStr);
  AnnotFreeText::setAppearanceString(const AppearanceStringData& apStr);

and do all the low level stuff like Tf construction and invalidating appearance
in the changed AnnotFreeText methods.


Solution 2

Add a new method to class AnnotFreeText
  AnnotFreeText::getAppearanceString(AppearanceStringData& apStr) const;

Fill apStr with data from parseAppearanceString (protected function)
  static void parseAppearanceString(GooString *da, double &fontsize,
AnnotColor* &fontcolor);

How about it? Abert?</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>