File indexing completed on 2026-09-06 12:46:09

0001 #ifndef FOPCOLORFORMAT_H
0002 #define FOPCOLORFORMAT_H
0003 
0004 #include "rwidgets_global.h"
0005 #include <QColor>
0006 #include <QCoreApplication>
0007 #include <QDebug>
0008 #include <QDomDocument>
0009 #include <QMap>
0010 #include <QPixmap>
0011 #include <QTextDocument>
0012 #include <QTextFrame>
0013 #include <QTextFrameFormat>
0014 #include <QTextTableFormat>
0015 #include <QtCore>
0016 
0017 #define POINT_TO_CM(cm) ((cm) / 28.3465058)
0018 #define POINT_TO_MM(mm) ((mm) / 2.83465058) ////////  0.352777778
0019 #define POINT_TO_DM(dm) ((dm) / 283.465058)
0020 #define POINT_TO_INCH(inch) ((inch) / 72.0)
0021 #define POINT_TO_PI(pi) ((pi) / 12)
0022 #define POINT_TO_DD(dd) ((dd) / 154.08124)
0023 #define POINT_TO_CC(cc) ((cc) / 12.840103)
0024 
0025 #define MM_TO_POINT(mm) ((mm)*2.83465058)
0026 #define CM_TO_POINT(cm) ((cm)*28.3465058) ///// 28.346456693
0027 #define DM_TO_POINT(dm) ((dm)*283.465058)
0028 #define INCH_TO_POINT(inch) ((inch)*72.0)
0029 #define PI_TO_POINT(pi) ((pi)*12)
0030 #define DD_TO_POINT(dd) ((dd)*154.08124)
0031 #define CC_TO_POINT(cc) ((cc)*12.840103)
0032 
0033 /*  QColor  alpha color 0 - 100%  100% = full transparent */
0034 #define ALPHACOLPER(aa) ((aa)*2.555555)
0035 static inline qreal OoColorAlpha(const int i)
0036 {
0037     if(i > 0 && i < 101)
0038     {
0039         return 255 - ALPHACOLPER(i);
0040     }
0041     else
0042     {
0043         return 255;
0044     }
0045 }
0046 
0047 #define _USELISTAPACHECOLOR_ 1
0048 
0049 /*
0050 
0051     QTextEdit t;
0052     FopColor *fc = new FopColor();
0053     QStringList items = fc->fopListColor();
0054     for (int i = 0; i < items.size(); ++i)  {
0055         const QString name = items.at(i);
0056         QTextCursor c = t.textCursor();
0057         QPixmap e =  fc->createColorMap(name);
0058         t.document()->addResource(QTextDocument::ImageResource,QUrl(name),e);
0059         QTextImageFormat format;
0060         format.setName( name );
0061         format.setHeight ( e.height() );
0062         format.setWidth ( e.width() );
0063         format.setToolTip(name);
0064         t.textCursor().insertImage( format );
0065     }
0066 
0067     t.show();
0068 */
0069 
0070 /*  grab color from fop format ;
0071     alpha color only on rgb(11,11,11,110)  last
0072 
0073 
0074 */
0075 /* fix from Peter Hohl to make image running on dpi unit! */
0076 static inline qreal DPIactualDiff()
0077 {
0078     QPixmap pixmap(50, 80);
0079     pixmap.fill(Qt::transparent);
0080     int hi= qMax(pixmap.logicalDpiY(), 72);
0081     int mi= qMin(pixmap.logicalDpiY(), 72);
0082     if(hi == mi)
0083     {
0084         return 1; /* no difference increase or degrease 1:1 running 72 DPI  */
0085     }
0086     const qreal precision= 0.09741; /* gimp precision to image */
0087     ////////return 1;   /* 1:1 to test */
0088     int diff= hi - mi;
0089     qreal increments= 1.;
0090     if(mi == 72)
0091     { //////  more >>>
0092         return increments + (diff / 100.0) + precision;
0093     }
0094     else
0095     { ///////////// down <<<
0096         return increments - (diff / 100.0) + precision;
0097     }
0098 }
0099 
0100 #define PDIFIX(ii) ((ii)*DPIactualDiff())
0101 
0102 QString metrics(const qreal screenpoint);
0103 /* metric conversion from and to */
0104 qreal Unit(const QString datain);
0105 qreal Pointo(qreal unit, const QString unita);
0106 qreal ToUnit(qreal unit, const QString unita);
0107 qreal ToPoint(qreal unit, const QString unita);
0108 
0109 class RWIDGET_EXPORT FopColor
0110 {
0111 public:
0112     typedef enum
0113     {
0114         DarkColor= 100,
0115         LightColor= 200,
0116         Transparent= 300
0117     } AlternateColor;
0118     /// static
0119     FopColor(const QString colorchunk= QString(), FopColor::AlternateColor col= Transparent);
0120     QColor foColor(const QString colorchunk, FopColor::AlternateColor col= DarkColor);
0121     QString foName(const QColor e);
0122     QPixmap createColorMap(const QString colorchunk);
0123     /////  static to retun name human readable ?
0124     inline QStringList fopListColor() { return fopcolorNames; }
0125     inline QColor color() { return currentcolor; }
0126     inline int size() { return fopcolorNames.count(); }
0127 
0128 protected:
0129     QMap<QString, QColor> foplist; /* forever clear only construct */
0130     QMap<QString, QColor> avaiablelist;
0131     QStringList fopcolorNames;
0132 
0133 private:
0134     QColor alternateColor(FopColor::AlternateColor col);
0135     QColor currentcolor;
0136     void record(const QString colorchunk, QColor item);
0137 };
0138 
0139 class RWIDGET_EXPORT FoRegion
0140 {
0141 public:
0142     FoRegion();
0143     FoRegion& operator=(const FoRegion& d);
0144     operator QVariant() const { return QVariant::fromValue(*this); }
0145     QString hash() const;
0146     void styleContainer(QDomElement e, const qreal height= 0);
0147     void styleSmallDocument(QTextDocument* doc);
0148     void styleReadDocument(const QTextDocument* doc);
0149     void fomax(FoRegion& m, FoRegion& d);
0150     /* same margin to all */
0151     void toAll(const qreal unique);
0152     void marginNoBody();
0153     QMap<QString, QPen> penstyle(); /* return avaiable pen */
0154     QColor bg;                      /* background color */
0155     QColor bog;                     /* border color */
0156     qreal margin_top;
0157     qreal margin_bottom;
0158     qreal margin_left;
0159     qreal margin_right;
0160     qreal border;
0161     qreal padding;
0162     QPen rpen;
0163     bool enable;
0164     QByteArray edom; /* dome element*/
0165 };
0166 
0167 Q_DECLARE_METATYPE(FoRegion)
0168 
0169 #endif