Subversion Repositories Scribus

Compare Revisions

Ignore whitespace Rev 10201 → Rev 10203

/trunk/Scribus/scribus/colorutil.h
File deleted
Property changes:
Deleted: svn:eol-style
## -1 +0,0 ##
-native
\ No newline at end of property
Deleted: svn:keywords
## -1 +0,0 ##
-Author Date Id Revision
\ No newline at end of property
Index: Scribus/scribus/colorutil.cpp
===================================================================
--- Scribus/scribus/colorutil.cpp (revision 10201)
+++ Scribus/scribus/colorutil.cpp (nonexistent)
@@ -1,626 +0,0 @@
-/*
-For general Scribus (>=1.3.2) copyright and licensing information please refer
-to the COPYING file provided with the program. Following this notice may exist
-a copyright and/or license notice that predates the release of Scribus 1.3.2
-for which a new license (GPL+exception) is in place.
-*/
-/***************************************************************************
- util.cpp - description
- -------------------
- begin : Fri Sep 14 2001
- copyright : (C) 2001 by Franz Schmid
- email : Franz.Schmid@altmuehlnet.de
- ***************************************************************************/
-
-/***************************************************************************
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. *
- * *
- ***************************************************************************/
-
-#include "colorutil.h"
-
-#include <qbitmap.h>
-#include <qdatetime.h>
-#include <qpainter.h>
-#include <qcheckbox.h>
-//Added by qt3to4:
-#include <QPixmap>
-// #include <algorithm>
-// #include <cstdlib>
-// #include <cmath>
-
-#include "scconfig.h"
-
-//#ifdef HAVE_UNISTD_H
-//#include <unistd.h>
-//#endif
-
-#if defined(_WIN32)
-#if defined(_MSC_VER)
-#define __STDC__ 1 // hack to get md5_buffer correctly identified
-#endif
-#include <valarray>
-#include <windows.h>
-#endif
-
-#include "md5.h"
-
-// #include <setjmp.h>
-// #include "commonstrings.h"
-// #include "pagestructs.h"
-// #include "prefsfile.h"
-// #include "prefscontext.h"
-// #include "prefstable.h"
-// #include "prefsmanager.h"
-// #include "qprocess.h"
-// #include "scmessagebox.h"
-#include "scribusdoc.h"
-#include "scpixmapcache.h"
-#include "commonstrings.h"
-// #include "scpaths.h"
-// #include "text/nlsconfig.h"
-#include "util_icon.h"
-#include "util.h"
-#include "sccolorengine.h"
-
-extern "C"
-{
-#define XMD_H // shut JPEGlib up
-#if defined(Q_OS_UNIXWARE)
-# define HAVE_BOOLEAN // libjpeg under Unixware seems to need this
-#endif
-#include <jpeglib.h>
-#include <jerror.h>
-#undef HAVE_STDLIB_H
-#ifdef const
-# undef const // remove crazy C hackery in jconfig.h
-#endif
-}
-
-#include CMS_INC
-using namespace std;
-
-void handleOldColorShade(ScribusDoc* doc, QString& colName, int& shade)
-{
- int r, g, b;
- bool found = false;
- if( colName.isEmpty() || colName == CommonStrings::None || !doc->PageColors.contains(colName))
- return;
-
- const ScColor& scCol1(doc->PageColors[colName]);
-
- if( (shade == 100) || (scCol1.getColorModel() != colorModelRGB) )
- return;
- scCol1.getRGB(&r, &g, &b);
- QColor col1 = getOldColorShade(r, g, b, shade), col2;
- ColorList::Iterator it, itEnd = doc->PageColors.end();
- for( it = doc->PageColors.begin(); it != itEnd; it++)
- {
- if ( it.data().getColorModel() == colorModelRGB )
- {
- it.data().getRGB(&r, &g, &b);
- col2.setRgb(r, g, b);
- if( col1 == col2 )
- {
- found = true;
- break;
- }
- }
- }
- if(!found)
- {
- ScColor tmp;
- tmp.fromQColor(col1);
- colName = QString("%1 %2%").arg(colName).arg(shade);
- doc->PageColors.insert(colName, tmp);
- }
- else
- colName = it.key();
- shade = 100;
-}
-
-QColor getOldColorShade(const QColor& color, int shade)
-{
- int r, g, b;
- color.getRgb(&r, &g, &b);
- return getOldColorShade(r, g, b, shade);
-}
-
-QColor getOldColorShade(uchar red, uchar green, uchar blue, int shade)
-{
- int h, s, v, snew;
- QColor color(red, green, blue);
- color.hsv(&h, &s, &v);
- if (red == green && green == blue)
- {
- snew = 255 - ((255 - v) * shade / 100);
- color.setHsv(h, s, snew);
- }
- else
- {
- snew = s * shade / 100;
- color.setHsv(h, snew, v);
- }
- return color;
-}
-
-QImage ProofImage(QImage *Image, ScribusDoc* doc)
-{
- QImage out = Image->copy();
- bool cmsUse = doc ? doc->HasCMS : false;
- bool softProofing = doc ? doc->SoftProofing : false;
- if (cmsUse && softProofing)
- {
- int outheight=out.height();
- for (int i=0; i < outheight; ++i)
- {
- LPBYTE ptr = out.scanLine(i);
- cmsDoTransform(doc->stdProofImg, ptr, ptr, out.width());
- }
- }
- else
- {
- if (cmsUse)
- {
- int outheight=out.height();
- for (int i=0; i < outheight; ++i)
- {
- LPBYTE ptr = out.scanLine(i);
- cmsDoTransform(doc->stdTransImg, ptr, ptr, out.width());
- }
- }
- }
- return out;
-}
-
-QColor SetColor(ScribusDoc *currentDoc, QString color, int shad)
-{
- const ScColor& col = currentDoc->PageColors[color];
- return ScColorEngine::getShadeColorProof(col, currentDoc, shad);
-}
-
-
-/**
- * QPixmaps are really slow with Qt/Mac 3.3.4. Really, *really*, slow.
- * So we better cache them.
- */
-QPixmap * getSmallPixmap(QColor rgb)
-{
- static ScPixmapCache<QRgb> pxCache;
-
- QRgb index=rgb.rgb();
- if (pxCache.contains(index))
- return pxCache[index];
-
- QPixmap *pm = new QPixmap(15, 15);
- pm->fill(rgb);
- QPainter p;
- p.begin(pm);
- p.setBrush(Qt::NoBrush);
- QPen b(Qt::black, 1);
- p.setPen(b);
- p.drawRect(0, 0, 15, 15);
- p.end();
- pxCache.insert(index, pm);
- return pm;
-}
-
-QPixmap * getWidePixmap(QColor rgb)
-{
- static ScPixmapCache<QRgb> pxCache;
-
- QRgb index=rgb.rgb();
- if (pxCache.contains(index))
- return pxCache[index];
-
- QPixmap *pm = new QPixmap(30, 15);
- pm->fill(rgb);
- pxCache.insert(index, pm);
- return pm;
-}
-
-static Q_UINT64 code64(const ScColor & col) {
- int C, M, Y, K, R, G, B;
- Q_UINT64 result=0;
- col.getRGB( &R, &G, &B );
- col.getCMYK( &C, &M, &Y, &K );
- result |= col.getColorModel() == colorModelRGB ? 1 : 0;
- result |= col.isSpotColor() ? 64 : 0;
- result |= col.isRegistrationColor() ? 32 : 0;
- result <<= 8;
- result |= C;
- result <<= 8;
- result |= M;
- result <<= 8;
- result |= Y;
- result <<= 8;
- result |= K;
- result <<= 8;
- result |= R;
- result <<= 8;
- result |= G;
- result <<= 8;
- result |= B;
- return result;
-}
-
-QPixmap * getFancyPixmap(const ScColor& col, ScribusDoc* doc) {
- static ScPixmapCache<Q_UINT64> pxCache;
-
- static QPixmap alertIcon;
- static QPixmap cmykIcon;
- static QPixmap rgbIcon;
- static QPixmap spotIcon;
- static QPixmap regIcon;
- static bool iconsInitialized = false;
-
- if ( !iconsInitialized ) {
- alertIcon = loadIcon("alert.png");
- cmykIcon = loadIcon("cmyk.png");
- rgbIcon = loadIcon("rgb.png");
- spotIcon = loadIcon("spot.png");
- regIcon = loadIcon("register.png");
- iconsInitialized = true;
- }
-
- Q_UINT64 res=code64(col);
- if (pxCache.contains(res))
- return pxCache[res];
-
- QPixmap *pa=new QPixmap(60, 15);
- QPixmap *pm=getSmallPixmap(col.getRawRGBColor());
- pa->fill(Qt::white);
- paintAlert(*pm, *pa, 0, 0);
- if (ScColorEngine::isOutOfGamut(col, doc))
- paintAlert(alertIcon, *pa, 15, 0);
- if ((col.getColorModel() == colorModelCMYK) || (col.isSpotColor()))
- paintAlert(cmykIcon, *pa, 30, 0);
- else
- paintAlert(rgbIcon, *pa, 30, 0);
- if (col.isSpotColor())
- paintAlert(spotIcon, *pa, 46, 2);
- if (col.isRegistrationColor())
- paintAlert(regIcon, *pa, 45, 0);
- pxCache.insert(res, pa);
- return pa;
-}
-
-
-void paintAlert(QPixmap &toPaint, QPixmap &target, int x, int y, bool useMask)
-{
- // there is no alpha mask in the beginning
- if (useMask)
- {
- if (target.mask().isNull())
- target.setMask(QBitmap(target.width(), target.height(), useMask));
- }
- QPainter p;
- p.begin(&target);
- p.drawPixmap(x, y, toPaint);
- if (useMask)
- {
-// Qt4 FIXME: Qt4 can use better alpha setting. see colorlistbox.cpp
-// QPainter alpha; // transparency handling
-// alpha.begin(target.mask());
-// alpha.setBrush(Qt::color1);
-// alpha.setPen(Qt::color1);
-// alpha.drawRect(x, y, 15, 15);
-// if (!toPaint.mask().isNull())
-// alpha.drawPixmap(x, y, toPaint.mask());
-// alpha.end();
- }
- p.end();
-}
-
-unsigned char INT_MULT ( unsigned char a, unsigned char b )
-{
- int c = a * b + 0x80;
- return (unsigned char)(( ( c >> 8 ) + c ) >> 8);
-}
-
-void RGBTOHSV ( uchar& red, uchar& green, uchar& blue )
-{
- int r, g, b;
- double h, s, v;
- int min, max;
- h = 0.;
- r = red;
- g = green;
- b = blue;
- if ( r > g )
- {
- max = qMax( r, b );
- min = qMin( g, b );
- }
- else
- {
- max = qMax( g, b );
- min = qMin( r, b );
- }
- v = max;
- if ( max != 0 )
- s = ( ( max - min ) * 255 ) / (double)max;
- else
- s = 0;
- if ( s == 0 )
- h = 0;
- else
- {
- int delta = max - min;
- if ( r == max )
- h = ( g - b ) / (double)delta;
- else if ( g == max )
- h = 2 + ( b - r ) / (double)delta;
- else if ( b == max )
- h = 4 + ( r - g ) / (double)delta;
- h *= 42.5;
- if ( h < 0 )
- h += 255;
- if ( h > 255 )
- h -= 255;
- }
- red = (uchar)h;
- green = (uchar)s;
- blue = (uchar)v;
-}
-
-void HSVTORGB ( uchar& hue, uchar& saturation, uchar& value )
-{
- if ( saturation == 0 )
- {
- hue = value;
- saturation = value;
- value = value;
- }
- else
- {
- double h = hue * 6. / 255.;
- double s = saturation / 255.;
- double v = value / 255.;
-
- double f = h - (int)h;
- double p = v * ( 1. - s );
- double q = v * ( 1. - ( s * f ) );
- double t = v * ( 1. - ( s * ( 1. - f ) ) );
- // Worth a note here that gcc 2.96 will generate different results
- // depending on optimization mode on i386.
- switch ((int)h)
- {
- case 0:
- hue = (uchar)( v * 255 );
- saturation = (uchar)( t * 255 );
- value = (uchar)( p * 255 );
- break;
- case 1:
- hue = (uchar)( q * 255 );
- saturation = (uchar)( v * 255 );
- value = (uchar)( p * 255 );
- break;
- case 2:
- hue = (uchar)( p * 255 );
- saturation = (uchar)( v * 255 );
- value = (uchar)( t * 255 );
- break;
- case 3:
- hue = (uchar)( p * 255 );
- saturation = (uchar)( q * 255 );
- value = (uchar)( v * 255 );
- break;
- case 4:
- hue = (uchar)( t * 255 );
- saturation = (uchar)( p * 255 );
- value = (uchar)( v * 255 );
- break;
- case 5:
- hue = (uchar)( v * 255 );
- saturation = (uchar)( p * 255 );
- value = (uchar)( q * 255 );
- }
- }
-}
-
-void RGBTOHLS ( uchar& red, uchar& green, uchar& blue )
-{
- double var_R = ( red / 255.0 );
- double var_G = ( green / 255.0 );
- double var_B = ( blue / 255.0 );
- double var_Min = qMin( var_R, qMin(var_G, var_B) ); //Min. value of RGB
- double var_Max = qMax( var_R, qMax(var_G, var_B) ); //Max. value of RGB
- double del_Max = var_Max - var_Min; //Delta RGB value
- double L = ( var_Max + var_Min ) / 2.0;
- double H = 0;
- double S = 0;
- double del_R = 0;
- double del_G = 0;
- double del_B = 0;
- if ( del_Max == 0 )
- {
- H = 0;
- S = 0;
- }
- else
- {
- if ( L < 0.5 )
- S = del_Max / ( var_Max + var_Min );
- else
- S = del_Max / ( 2 - var_Max - var_Min );
- del_R = ( ( ( var_Max - var_R ) / 6.0 ) + ( del_Max / 2.0 ) ) / del_Max;
- del_G = ( ( ( var_Max - var_G ) / 6.0 ) + ( del_Max / 2.0 ) ) / del_Max;
- del_B = ( ( ( var_Max - var_B ) / 6.0 ) + ( del_Max / 2.0 ) ) / del_Max;
- if ( var_R == var_Max )
- H = del_B - del_G;
- else if ( var_G == var_Max )
- H = ( 1.0 / 3.0 ) + del_R - del_B;
- else if ( var_B == var_Max )
- H = ( 2.0 / 3.0 ) + del_G - del_R;
- if ( H < 0 )
- H += 1;
- if ( H > 1 )
- H -= 1;
- }
- red = qRound(H * 255);
- green = qRound(L * 255);
- blue = qRound(S * 255);
-}
-
-double HLSVALUE ( double n1, double n2, double hue )
-{
- if ( hue < 0 )
- hue += 1;
- if ( hue > 1 )
- hue -= 1;
- if ( ( 6 * hue ) < 1 )
- return n1 + ( n2 - n1 ) * 6 * hue;
- if ( ( 2 * hue ) < 1 )
- return n2;
- if ( ( 3 * hue ) < 2 )
- return n1 + ( n2 - n1 ) * ( ( 2.0 / 3.0 ) - hue ) * 6;
- return n1;
-}
-
-void HLSTORGB ( uchar& hue, uchar& lightness, uchar& saturation )
-{
- double H = ( hue / 255.0 );
- double L = ( lightness / 255.0 );
- double S = ( saturation / 255.0 );
- if (S == 0)
- {
- hue = qRound(255 * L);
- saturation = qRound(255 * L);
- return;
- }
- double var_1 = 0;
- double var_2 = 0;
- if ( L < 0.5 )
- var_2 = L * ( 1 + S );
- else
- var_2 = ( L + S ) - ( S * L );
- var_1 = 2 * L - var_2;
- hue = qRound(255 * HLSVALUE( var_1, var_2, H + ( 1.0 / 3.0 ) ));
- lightness = qRound(255 * HLSVALUE( var_1, var_2, H ));
- saturation = qRound(255 * HLSVALUE( var_1, var_2, H - ( 1.0 / 3.0 ) ));
-}
-
-double getCurveYValue(FPointArray &curve, double x, bool linear)
-{
- double t;
- FPoint p;
- FPoint p0,p1,p2,p3;
- double c0,c1,c2,c3;
- double val = 0.5;
- if(curve.size() == 0)
- return 0.5;
- // First find curve segment
- p = curve.point(0);
- if(x < p.x())
- return p.y();
- p = curve.point(curve.size()-1);
- if(x >= p.x())
- return p.y();
- uint cc = 0;
- // Find the four control points (two on each side of x)
- p = curve.point(0);
- while(x >= p.x())
- {
- cc++;
- p = curve.point(cc);
- }
- if (cc > 1)
- {
- p0 = curve.point(cc-2);
- p1 = curve.point(cc-1);
- }
- else
- p1 = p0 = curve.point(0);
- p2 = p;
- if (cc < curve.size()-1)
- p3 = curve.point(cc+1);
- else
- p3 = p;
- // Calculate the value
- if (linear)
- {
- double mc;
- if (p1.x() - p2.x() != 0.0)
- mc = (p1.y() - p2.y()) / (p1.x() - p2.x());
- else
- mc = p2.y() / p2.x();
- val = (x - p1.x()) * mc + p1.y();
- }
- else
- {
- t = (x - p1.x()) / (p2.x() - p1.x());
- c2 = (p2.y() - p0.y()) * (p2.x()-p1.x()) / (p2.x()-p0.x());
- c3 = p1.y();
- c0 = -2*p2.y() + 2*c3 + c2 + (p3.y() - p1.y()) * (p2.x() - p1.x()) / (p3.x() - p1.x());
- c1 = p2.y() - c3 - c2 - c0;
- val = ((c0*t + c1)*t + c2)*t + c3;
- }
- if(val < 0.0)
- val = 0.0;
- if(val > 1.0)
- val = 1.0;
- return val;
-}
-
-double Lum(uchar red, uchar green, uchar blue)
-{
- return 0.3 * (red / 255.0) + 0.59 * (green / 255.0) + 0.11 * (blue / 255.0);
-}
-
-double LumD(double red, double green, double blue)
-{
- return 0.3 * red + 0.59 * green + 0.11 * blue;
-}
-
-void setLum(uchar& red, uchar& green, uchar& blue, double lum)
-{
- double rP = (red / 255.0);
- double gP = (green / 255.0);
- double bP = (blue / 255.0);
- double d = lum - Lum(red, green, blue);
- rP += d;
- gP += d;
- bP += d;
- clipColor(rP, gP, bP);
- red = qRound(rP * 255);
- green = qRound(gP * 255);
- blue = qRound(bP * 255);
- return;
-}
-
-void clipColor(double& red, double& green, double& blue)
-{
- double l = LumD(red, green, blue);
- double n = qMin(red, qMin(green, blue));
- double x = qMax(red, qMax(green, blue));
- if (n < 0.0)
- {
- red = l + (((red - l) * l) / (l - n));
- green = l + (((green - l) * l) / (l - n));
- blue = l + (((blue - l) * l) / (l - n));
- }
- if (x > 1.0)
- {
- red = l + (((red - l) * (1.0 - l)) / (x - l));
- green = l + (((green - l) * (1.0 - l)) / (x - l));
- blue = l + (((blue - l) * (1.0 - l)) / (x - l));
- }
-}
-
-QString colorSpaceText(int cs)
-{
- if (cs==0)
- return CommonStrings::trRGB;
- if (cs==1)
- return CommonStrings::trCMYK;
- if (cs==2)
- return CommonStrings::trGrayscale;
- if (cs==3)
- return CommonStrings::trDuotone;
- return CommonStrings::trUnknownCS;
-}
/Scribus/scribus/colorutil.cpp
Property changes:
Deleted: svn:eol-style
## -1 +0,0 ##
-native
\ No newline at end of property
Deleted: svn:keywords
## -1 +0,0 ##
-Author Date Id Revision
\ No newline at end of property
Index: Scribus/scribus/util.cpp
===================================================================
--- Scribus/scribus/util.cpp (revision 10201)
+++ Scribus/scribus/util.cpp (revision 10203)
@@ -21,27 +21,25 @@
* *
***************************************************************************/
-#include "util.h"
-#include <qbitmap.h>
-#include <qfile.h>
-#include <qfileinfo.h>
-// #include <qdatastream.h>
-// #include <qregexp.h>
-#include <qdir.h>
-#include <qdom.h>
-#include <qcheckbox.h>
-#include <qwidget.h>
-//Added by qt3to4:
-#include <QPixmap>
-#include <QList>
+
+#include <QBitmap>
#include <QByteArray>
-#include <Q3PointArray>
+#include <QCheckBox>
+#include <QDomElement>
+#include <QFile>
+#include <QFileInfo>
#include <QImageReader>
+#include <QList>
+#include <QPixmap>
+#include <QWidget>
+#include <qdir.h>
-// #include <algorithm>
-// #include <cstdlib>
+
#include <cmath>
#include <algorithm>
+
+#include "util.h"
+
#include "scconfig.h"
//#ifdef HAVE_UNISTD_H
@@ -64,7 +62,7 @@
// #include "prefsfile.h"
// #include "prefscontext.h"
// #include "prefstable.h"
-// #include "prefsmanager.h"
+#include "prefsmanager.h"
#include <QProcess>
#include <q3process.h>
#include "scmessagebox.h"
@@ -229,40 +227,6 @@
return el->attribute(at, def);
}
-uint getDouble(QString in, bool raw)
-{
- QByteArray bb(4);
- if (raw)
- {
- // Qt4
-/* bb[3] = static_cast<uchar>(QChar(in.at(0)));
- bb[2] = static_cast<uchar>(QChar(in.at(1)));
- bb[1] = static_cast<uchar>(QChar(in.at(2)));
- bb[0] = static_cast<uchar>(QChar(in.at(3)));*/
- bb = bb.insert(3, in.at(0));
- bb = bb.insert(2, in.at(1));
- bb = bb.insert(1, in.at(2));
- bb = bb.insert(0, in.at(3));
- }
- else
- {
- // Qt4
-// bb[0] = static_cast<uchar>(QChar(in.at(0)));
-// bb[1] = static_cast<uchar>(QChar(in.at(1)));
-// bb[2] = static_cast<uchar>(QChar(in.at(2)));
-// bb[3] = static_cast<uchar>(QChar(in.at(3)));
- bb = bb.insert(0, in.at(0));
- bb = bb.insert(1, in.at(1));
- bb = bb.insert(2, in.at(2));
- bb = bb.insert(3, in.at(3));
- }
- uint ret;
- ret = bb[0] & 0xff;
- ret |= (bb[1] << 8) & 0xff00;
- ret |= (bb[2] << 16) & 0xff0000;
- ret |= (bb[3] << 24) & 0xff000000;
- return ret;
-}
// Legacy implementation of LoadText with incorrect
// handling of unicode data. This should be retired.
@@ -344,159 +308,7 @@
return ret;
}
-Q3PointArray RegularPolygon(double w, double h, uint c, bool star, double factor, double rota)
-{
- uint cx = star ? c * 2 : c;
- double seg = 360.0 / cx;
- double sc = rota + 180.0;
- double di = factor;
- int mx = 0;
- int my = 0;
- //QPointArray pts = QPointArray();
- Q3PointArray pts(cx);
- for (uint x = 0; x < cx; ++x)
- {
- sc = seg * x + 180.0 + rota;
- if (star)
- {
- double wf = x % 2 == 0 ? w / 2 : w / 2 * di;
- double hf = x % 2 == 0 ? h / 2 : h / 2 * di;
- mx = qRound(sin(sc / 180 * M_PI) * (wf) + (w/2));
- my = qRound(cos(sc / 180 * M_PI) * (hf) + (h/2));
- }
- else
- {
- mx = qRound(sin(sc / 180 * M_PI) * (w/2) + (w/2));
- my = qRound(cos(sc / 180 * M_PI) * (h/2) + (h/2));
- }
- //pts.resize(x+1);
- pts.setPoint(x, mx, my);
- }
- return pts;
-}
-FPointArray RegularPolygonF(double w, double h, uint c, bool star, double factor, double rota)
-{
- uint cx = star ? c * 2 : c;
- double seg = 360.0 / cx;
- double sc = rota + 180.0;
- double di = factor;
- double mx = 0;
- double my = 0;
- //FPointArray pts;
- FPointArray pts(cx);
- for (uint x = 0; x < cx; ++x)
- {
- sc = seg * x + 180.0 + rota;
- if (star)
- {
- double wf = x % 2 == 0 ? w / 2 : w / 2 * di;
- double hf = x % 2 == 0 ? h / 2 : h / 2 * di;
- mx = qRound(sin(sc / 180 * M_PI) * (wf) + (w/2));
- my = qRound(cos(sc / 180 * M_PI) * (hf) + (h/2));
- }
- else
- {
- mx = sin(sc / 180 * M_PI) * (w/2) + (w/2);
- my = cos(sc / 180 * M_PI) * (h/2) + (h/2);
- }
- //pts.resize(x+1);
- pts.setPoint(x, mx, my);
- }
- return pts;
-}
-
-QList<QPainterPath> decomposePath(QPainterPath &path)
-{
- QList<QPainterPath> ret;
- ret.clear();
- QPainterPath part;
- part = QPainterPath();
- bool first = true;
- for (int i = 0; i < path.elementCount(); ++i)
- {
- const QPainterPath::Element &elm = path.elementAt(i);
- if ((first) && (elm.type != QPainterPath::MoveToElement))
- part.moveTo(elm.x, elm.y);
- switch (elm.type)
- {
- case QPainterPath::MoveToElement:
- if (!first)
- {
- ret.append(part);
- part = QPainterPath();
- }
- first = false;
- part.moveTo(elm.x, elm.y);
- break;
- case QPainterPath::LineToElement:
- part.lineTo(elm.x, elm.y);
- break;
- case QPainterPath::CurveToElement:
- part.cubicTo(elm.x, elm.y, path.elementAt(i+1).x, path.elementAt(i+1).y, path.elementAt(i+2).x, path.elementAt(i+2).y );
- break;
- default:
- break;
- }
- }
- if (!part.isEmpty())
- ret.append(part);
- return ret;
-}
-
-Q3PointArray FlattenPath(FPointArray ina, QList<uint> &Segs)
-{
- Q3PointArray Bez(4);
- Q3PointArray outa, cli;
- Segs.clear();
- if (ina.size() > 3)
- {
- for (uint poi=0; poi<ina.size()-3; poi += 4)
- {
- if (ina.point(poi).x() > 900000 && cli.size() > 0)
- {
- outa.resize(outa.size()+1);
- outa.setPoint(outa.size()-1, cli.point(cli.size()-1));
- Segs.append(outa.size());
- continue;
- }
- BezierPoints(&Bez, ina.pointQ(poi), ina.pointQ(poi+1), ina.pointQ(poi+3), ina.pointQ(poi+2));
- cli = Bez.cubicBezier();
- outa.putPoints(outa.size(), cli.size()-1, cli);
- }
- outa.resize(outa.size()+1);
- outa.setPoint(outa.size()-1, cli.point(cli.size()-1));
- }
- return outa;
-}
-
-double xy2Deg(double x, double y)
-{
- return (atan2(y,x)*(180.0/M_PI));
-}
-
-void BezierPoints(Q3PointArray *ar, QPoint n1, QPoint n2, QPoint n3, QPoint n4)
-{
- ar->setPoint(0, n1);
- ar->setPoint(1, n2);
- ar->setPoint(2, n3);
- ar->setPoint(3, n4);
- return;
-}
-
-/* CB Replaced by ScribusDoc::layerLevelFromNumber
-int Layer2Level(ScribusDoc *currentDoc, int LayerNr)
-{
- int retVal=currentDoc->layerLevelFromNumber(LayerNr);
- int layerCount=currentDoc->layerCount();
- for (uint la2 = 0; la2 < layerCount; ++la2)
-{
- if (currentDoc->Layers[la2].LNr == LayerNr)
- return currentDoc->Layers[la2].Level;
-}
- return 0;
-}
-*/
QString CompressStr(QString *in)
{
QString out = "";
@@ -1070,46 +882,6 @@
OB->DashOffset = obj->attribute("DASHOFF", "0.0").toDouble();
}
-FPoint getMaxClipF(FPointArray* Clip)
-{
- FPoint np, rp;
- double mx = 0;
- double my = 0;
- uint clipSize=Clip->size();
- for (uint c = 0; c < clipSize; ++c)
- {
- np = Clip->point(c);
- if (np.x() > 900000)
- continue;
- if (np.x() > mx)
- mx = np.x();
- if (np.y() > my)
- my = np.y();
- }
- rp.setXY(mx, my);
- return rp;
-}
-
-FPoint getMinClipF(FPointArray* Clip)
-{
- FPoint np, rp;
- double mx = 99999;
- double my = 99999;
- uint clipSize=Clip->size();
- for (uint c = 0; c < clipSize; ++c)
- {
- np = Clip->point(c);
- if (np.x() > 900000)
- continue;
- if (np.x() < mx)
- mx = np.x();
- if (np.y() < my)
- my = np.y();
- }
- rp.setXY(mx, my);
- return rp;
-}
-
QString checkFileExtension(const QString &currName, const QString &extension)
{
QString newName(currName);
@@ -1140,62 +912,6 @@
return QString("%1-%2%3.%4").arg(defaultName).arg(QObject::tr("page", "page export")).arg(number, 3, 10, QChar('0')).arg(extension);
}
-bool compareDouble(double a, double b)
-{
- if(a > -21473 && b > -21473 && a < 21474 && b < 21474)
- {
- long al = static_cast<long>(10000 * a);
- long bl = static_cast<long>(10000 * b);
- return al == bl;
- }
- return a == b;
-}
-
-inline double square(double x)
-{
- return x*x;
-}
-
-inline double distance(double x, double y)
-{
- return sqrt(x*x+y*y);
-}
-
-double constrainAngle(double angle, double constrain)
-{
- double newAngle=angle;
- double constrainTo=constrain;
- if (newAngle<0.0)
- newAngle+=360.0;
- newAngle=qRound(angle/constrainTo)*constrainTo;
- if (newAngle==360.0)
- newAngle=0.0;
- return newAngle;
-}
-
-double getRotationFromMatrix(QMatrix& matrix, double def)
-{
- double value = def;
- double norm = sqrt(fabs(matrix.det()));
- if (norm > 0.0000001)
- {
- double m11 = matrix.m11() / norm;
- double m12 = matrix.m12() / norm;
- double m21 = matrix.m21() / norm;
- double m22 = matrix.m22() / norm;
- if (fabs(m11) <= 1.0 && fabs(m12) <= 1.0 && fabs(m21) <= 1.0 && fabs(m22) <= 1.0)
- {
- QMatrix mat(m11, m12, m21, m22, 0, 0);
- if (abs(mat.det()-1.0) < 0.00001 && (mat.m12() == -mat.m21()))
- {
- double ac = acos(mat.m11());
- value = (mat.m21() >= 0.0) ? ac : (-ac);
- }
- }
- }
- return value;
-}
-
const QString getStringFromSequence(DocumentSectionType type, uint position)
{
QString retVal("");
/trunk/Scribus/scribus/colorchart.cpp
23,7 → 23,7
 
#include "colorchart.h"
#include <QPainter>
#include "colorutil.h"
#include "util_color.h"
#include "scribusdoc.h"
 
ColorChart::ColorChart(QWidget *parent, ScribusDoc* doc) : QWidget(parent), m_doc(doc)
/trunk/Scribus/scribus/util_math.cpp
0,0 → 1,378
/*
For general Scribus (>=1.3.2) copyright and licensing information please refer
to the COPYING file provided with the program. Following this notice may exist
a copyright and/or license notice that predates the release of Scribus 1.3.2
for which a new license (GPL+exception) is in place.
*/
/***************************************************************************
util.cpp - description
-------------------
begin : Fri Sep 14 2001
copyright : (C) 2001 by Franz Schmid
email : Franz.Schmid@altmuehlnet.de
***************************************************************************/
 
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
 
#include "util_math.h"
#include <qbitmap.h>
#include <qfile.h>
#include <qfileinfo.h>
// #include <qdatastream.h>
// #include <qregexp.h>
#include <qdir.h>
#include <qdom.h>
#include <qcheckbox.h>
#include <qwidget.h>
//Added by qt3to4:
#include <QPixmap>
#include <QList>
#include <QByteArray>
#include <Q3PointArray>
#include <QImageReader>
 
// #include <algorithm>
// #include <cstdlib>
#include <cmath>
#include <algorithm>
#include "scconfig.h"
 
//#ifdef HAVE_UNISTD_H
//#include <unistd.h>
//#endif
 
#if defined(_WIN32)
#if defined(_MSC_VER)
#define __STDC__ 1 // hack to get md5_buffer correctly identified
#endif
#include <valarray>
#include <windows.h>
#endif
 
#include "md5.h"
 
// #include <setjmp.h>
#include "commonstrings.h"
// #include "pagestructs.h"
// #include "prefsfile.h"
// #include "prefscontext.h"
// #include "prefstable.h"
// #include "prefsmanager.h"
#include <QProcess>
#include <q3process.h>
#include "scmessagebox.h"
#include "scpixmapcache.h"
#include "scpaths.h"
// #include "text/nlsconfig.h"
 
extern "C"
{
#define XMD_H // shut JPEGlib up
#if defined(Q_OS_UNIXWARE)
# define HAVE_BOOLEAN // libjpeg under Unixware seems to need this
#endif
#include <jpeglib.h>
#include <jerror.h>
#undef HAVE_STDLIB_H
#ifdef const
# undef const // remove crazy C hackery in jconfig.h
#endif
}
 
#include "pageitem.h"
#include "scribus.h"
#include "scribusdoc.h"
#include "scribusview.h"
/*#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_OUTLINE_H
#include FT_GLYPH_H
*/
#include <zlib.h>
 
 
using namespace std;
 
 
 
uint getDouble(QString in, bool raw)
{
QByteArray bb(4);
if (raw)
{
// Qt4
/* bb[3] = static_cast<uchar>(QChar(in.at(0)));
bb[2] = static_cast<uchar>(QChar(in.at(1)));
bb[1] = static_cast<uchar>(QChar(in.at(2)));
bb[0] = static_cast<uchar>(QChar(in.at(3)));*/
bb = bb.insert(3, in.at(0));
bb = bb.insert(2, in.at(1));
bb = bb.insert(1, in.at(2));
bb = bb.insert(0, in.at(3));
}
else
{
// Qt4
// bb[0] = static_cast<uchar>(QChar(in.at(0)));
// bb[1] = static_cast<uchar>(QChar(in.at(1)));
// bb[2] = static_cast<uchar>(QChar(in.at(2)));
// bb[3] = static_cast<uchar>(QChar(in.at(3)));
bb = bb.insert(0, in.at(0));
bb = bb.insert(1, in.at(1));
bb = bb.insert(2, in.at(2));
bb = bb.insert(3, in.at(3));
}
uint ret;
ret = bb[0] & 0xff;
ret |= (bb[1] << 8) & 0xff00;
ret |= (bb[2] << 16) & 0xff0000;
ret |= (bb[3] << 24) & 0xff000000;
return ret;
}
 
Q3PointArray RegularPolygon(double w, double h, uint c, bool star, double factor, double rota)
{
uint cx = star ? c * 2 : c;
double seg = 360.0 / cx;
double sc = rota + 180.0;
double di = factor;
int mx = 0;
int my = 0;
//QPointArray pts = QPointArray();
Q3PointArray pts(cx);
for (uint x = 0; x < cx; ++x)
{
sc = seg * x + 180.0 + rota;
if (star)
{
double wf = x % 2 == 0 ? w / 2 : w / 2 * di;
double hf = x % 2 == 0 ? h / 2 : h / 2 * di;
mx = qRound(sin(sc / 180 * M_PI) * (wf) + (w/2));
my = qRound(cos(sc / 180 * M_PI) * (hf) + (h/2));
}
else
{
mx = qRound(sin(sc / 180 * M_PI) * (w/2) + (w/2));
my = qRound(cos(sc / 180 * M_PI) * (h/2) + (h/2));
}
//pts.resize(x+1);
pts.setPoint(x, mx, my);
}
return pts;
}
 
FPointArray RegularPolygonF(double w, double h, uint c, bool star, double factor, double rota)
{
uint cx = star ? c * 2 : c;
double seg = 360.0 / cx;
double sc = rota + 180.0;
double di = factor;
double mx = 0;
double my = 0;
//FPointArray pts;
FPointArray pts(cx);
for (uint x = 0; x < cx; ++x)
{
sc = seg * x + 180.0 + rota;
if (star)
{
double wf = x % 2 == 0 ? w / 2 : w / 2 * di;
double hf = x % 2 == 0 ? h / 2 : h / 2 * di;
mx = qRound(sin(sc / 180 * M_PI) * (wf) + (w/2));
my = qRound(cos(sc / 180 * M_PI) * (hf) + (h/2));
}
else
{
mx = sin(sc / 180 * M_PI) * (w/2) + (w/2);
my = cos(sc / 180 * M_PI) * (h/2) + (h/2);
}
//pts.resize(x+1);
pts.setPoint(x, mx, my);
}
return pts;
}
 
QList<QPainterPath> decomposePath(QPainterPath &path)
{
QList<QPainterPath> ret;
ret.clear();
QPainterPath part;
part = QPainterPath();
bool first = true;
for (int i = 0; i < path.elementCount(); ++i)
{
const QPainterPath::Element &elm = path.elementAt(i);
if ((first) && (elm.type != QPainterPath::MoveToElement))
part.moveTo(elm.x, elm.y);
switch (elm.type)
{
case QPainterPath::MoveToElement:
if (!first)
{
ret.append(part);
part = QPainterPath();
}
first = false;
part.moveTo(elm.x, elm.y);
break;
case QPainterPath::LineToElement:
part.lineTo(elm.x, elm.y);
break;
case QPainterPath::CurveToElement:
part.cubicTo(elm.x, elm.y, path.elementAt(i+1).x, path.elementAt(i+1).y, path.elementAt(i+2).x, path.elementAt(i+2).y );
break;
default:
break;
}
}
if (!part.isEmpty())
ret.append(part);
return ret;
}
 
Q3PointArray FlattenPath(FPointArray ina, QList<uint> &Segs)
{
Q3PointArray Bez(4);
Q3PointArray outa, cli;
Segs.clear();
if (ina.size() > 3)
{
for (uint poi=0; poi<ina.size()-3; poi += 4)
{
if (ina.point(poi).x() > 900000 && cli.size() > 0)
{
outa.resize(outa.size()+1);
outa.setPoint(outa.size()-1, cli.point(cli.size()-1));
Segs.append(outa.size());
continue;
}
BezierPoints(&Bez, ina.pointQ(poi), ina.pointQ(poi+1), ina.pointQ(poi+3), ina.pointQ(poi+2));
cli = Bez.cubicBezier();
outa.putPoints(outa.size(), cli.size()-1, cli);
}
outa.resize(outa.size()+1);
outa.setPoint(outa.size()-1, cli.point(cli.size()-1));
}
return outa;
}
 
double xy2Deg(double x, double y)
{
return (atan2(y,x)*(180.0/M_PI));
}
 
void BezierPoints(Q3PointArray *ar, QPoint n1, QPoint n2, QPoint n3, QPoint n4)
{
ar->setPoint(0, n1);
ar->setPoint(1, n2);
ar->setPoint(2, n3);
ar->setPoint(3, n4);
return;
}
 
 
 
FPoint getMaxClipF(FPointArray* Clip)
{
FPoint np, rp;
double mx = 0;
double my = 0;
uint clipSize=Clip->size();
for (uint c = 0; c < clipSize; ++c)
{
np = Clip->point(c);
if (np.x() > 900000)
continue;
if (np.x() > mx)
mx = np.x();
if (np.y() > my)
my = np.y();
}
rp.setXY(mx, my);
return rp;
}
 
FPoint getMinClipF(FPointArray* Clip)
{
FPoint np, rp;
double mx = 99999;
double my = 99999;
uint clipSize=Clip->size();
for (uint c = 0; c < clipSize; ++c)
{
np = Clip->point(c);
if (np.x() > 900000)
continue;
if (np.x() < mx)
mx = np.x();
if (np.y() < my)
my = np.y();
}
rp.setXY(mx, my);
return rp;
}
 
 
bool compareDouble(double a, double b)
{
if(a > -21473 && b > -21473 && a < 21474 && b < 21474)
{
long al = static_cast<long>(10000 * a);
long bl = static_cast<long>(10000 * b);
return al == bl;
}
return a == b;
}
 
inline double square(double x)
{
return x*x;
}
 
inline double distance(double x, double y)
{
return sqrt(x*x+y*y);
}
 
double constrainAngle(double angle, double constrain)
{
double newAngle=angle;
double constrainTo=constrain;
if (newAngle<0.0)
newAngle+=360.0;
newAngle=qRound(angle/constrainTo)*constrainTo;
if (newAngle==360.0)
newAngle=0.0;
return newAngle;
}
 
double getRotationFromMatrix(QMatrix& matrix, double def)
{
double value = def;
double norm = sqrt(fabs(matrix.det()));
if (norm > 0.0000001)
{
double m11 = matrix.m11() / norm;
double m12 = matrix.m12() / norm;
double m21 = matrix.m21() / norm;
double m22 = matrix.m22() / norm;
if (fabs(m11) <= 1.0 && fabs(m12) <= 1.0 && fabs(m21) <= 1.0 && fabs(m22) <= 1.0)
{
QMatrix mat(m11, m12, m21, m22, 0, 0);
if (abs(mat.det()-1.0) < 0.00001 && (mat.m12() == -mat.m21()))
{
double ac = acos(mat.m11());
value = (mat.m21() >= 0.0) ? ac : (-ac);
}
}
}
return value;
}
 
/trunk/Scribus/scribus/serializer.cpp
29,7 → 29,8
#include <QList>
#include "sccolor.h"
#include "util.h"
#include "colorutil.h"
#include "util_math.h"
#include "util_color.h"
#include "resourcecollection.h"
 
#include "desaxe/simple_actions.h"
/trunk/Scribus/scribus/fonts/scfontmetrics.cpp
4,24 → 4,25
a copyright and/or license notice that predates the release of Scribus 1.3.2
for which a new license (GPL+exception) is in place.
*/
#include <qpainter.h>
#include <qcolor.h>
#include <qmatrix.h>
#include <qpixmap.h>
#include <qstringlist.h>
#include <qmap.h>
#include <qregexp.h>
#include <QColor>
#include <QMap>
#include <QMatrix>
#include <QPainter>
#include <QPixmap>
#include <QRegExp>
#include <QStringList>
 
#include "scribusdoc.h"
#include "scfonts.h"
#include "style.h"
#include "scfontmetrics.h"
#include "scpainter.h"
#include "fpoint.h"
#include "fpointarray.h"
#include "page.h"
#include "util.h"
#include "scfontmetrics.h"
#include "scfonts.h"
#include "scpainter.h"
#include "scribusdoc.h"
#include "style.h"
#include "util_math.h"
 
 
// this code contains a set of font related functions
// that don't really fit within ScFonts.
 
/trunk/Scribus/scribus/scribusXml.cpp
43,7 → 43,8
 
#include <zlib.h>
#include "util.h"
#include "colorutil.h"
#include "util_math.h"
#include "util_color.h"
#include "scpattern.h"
 
using namespace std;
/trunk/Scribus/scribus/pageitem_pathtext.cpp
22,7 → 22,6
***************************************************************************/
 
#include "pageitem_pathtext.h"
//#include "pageitem_pathtext.moc"
#include <qpainter.h>
#include <qpen.h>
#include <qfont.h>
51,7 → 50,7
#include "undostate.h"
#include "scconfig.h"
 
#include "util.h"
#include "util_math.h"
 
#include "text/nlsconfig.h"
 
/trunk/Scribus/scribus/scimgdataloader_psd.cpp
6,7 → 6,7
*/
#include "scconfig.h"
#include "scimgdataloader_psd.h"
#include "colorutil.h"
#include "util_color.h"
#include "sccolorengine.h"
 
#include <QFile>
/trunk/Scribus/scribus/picstatus.cpp
33,19 → 33,20
#include <QPainter>
#include <cstdio>
 
#include "colorutil.h"
#include "commonstrings.h"
#include "effectsdialog.h"
#include "extimageprops.h"
#include "filesearch.h"
#include "formatutils.h"
#include "pageitem.h"
#include "picsearch.h"
#include "picsearchoptions.h"
#include "scribuscore.h"
#include "scribusdoc.h"
#include "pageitem.h"
#include "filesearch.h"
#include "scribuscore.h"
#include "commonstrings.h"
#include "effectsdialog.h"
#include "extimageprops.h"
#include "util_color.h"
#include "util_icon.h"
 
 
PicItem::PicItem(QListWidget* parent, QString text, QPixmap pix, PageItem* pgItem)
: QListWidgetItem(pix, text, parent)
{
/trunk/Scribus/scribus/extimageprops.cpp
28,7 → 28,7
#include "scribusdoc.h"
#include "scribusview.h"
#include "util_icon.h"
#include "util.h"
#include "util_math.h"
 
ExtImageProps::ExtImageProps( QWidget* parent, ImageInfoRecord *info, PageItem *item, ScribusView *view ) : QDialog( parent )
{
/trunk/Scribus/scribus/pageitem.cpp
64,6 → 64,7
#include "resourcecollection.h"
 
#include "util.h"
#include "util_math.h"
#include "scpattern.h"
#include "colorblind.h"
 
/trunk/Scribus/scribus/scribusview.cpp
75,7 → 75,7
#endif
#include "scribus.h"
 
#include "colorutil.h"
#include "util_color.h"
#include "formatutils.h"
#include "mpalette.h"
#include "scribusXml.h"
117,6 → 117,7
#include "scrap.h"
#include "stencilreader.h"
#include "util_icon.h"
#include "util_math.h"
 
using namespace std;
 
/trunk/Scribus/scribus/pageitem_textframe.cpp
22,7 → 22,6
***************************************************************************/
 
#include "pageitem_textframe.h"
//#include "pageitem_textframe.moc"
#include <qpainter.h>
#include <qpen.h>
#include <qfont.h>
33,7 → 32,6
#include <qbitmap.h>
#include <qregexp.h>
#include <qmessagebox.h>
//Added by qt3to4:
#include <QList>
#include <QKeyEvent>
#include <Q3PointArray>
56,7 → 54,7
#include "commonstrings.h"
#include "guidemanager.h"
 
#include "util.h"
#include "util_math.h"
#include "text/nlsconfig.h"
 
using namespace std;
/trunk/Scribus/scribus/util_color.h
0,0 → 1,105
/*
For general Scribus (>=1.3.2) copyright and licensing information please refer
to the COPYING file provided with the program. Following this notice may exist
a copyright and/or license notice that predates the release of Scribus 1.3.2
for which a new license (GPL+exception) is in place.
*/
#ifndef _UTIL_COLOR_H
#define _UTIL_COLOR_H
 
#include <QColor>
#include <QImage>
#include <QPixmap>
#include <QString>
 
#include "fpointarray.h"
#include "sccolor.h"
#include "scribusapi.h"
 
class ScribusDoc;
 
QColor SCRIBUS_API SetColor(ScribusDoc *currentDoc, QString color, int shad);
 
/*! \brief Create a cool all-infos pixmaps for the specified color.
\param col Scribus color
\retval QPixmap image with various icons depending on the col properties.
*/
QPixmap SCRIBUS_API *getSmallPixmap(QColor rgb);
QPixmap SCRIBUS_API *getWidePixmap(QColor rgb);
QPixmap SCRIBUS_API *getFancyPixmap(const ScColor& col, ScribusDoc* doc);
/*! \brief Put toPaint pixmap into target at the x, y place.
There is handled the alpha channel/transparency too. In the beginning
is the target pixmap filled with all_transparent mask. In the case of
the painting of tiPaint into x, y place, there is this pixmap enabled
in alpha mask too.
\param toPaint a pixmap to be painted into target
\param target a base pixmap. Some kind of painter.
\param x coordinate
\param y coordinate
*/
void SCRIBUS_API paintAlert(QPixmap &toPaint, QPixmap &target, int x = 0, int y = 0, bool useMask = true);
QImage SCRIBUS_API ProofImage(QImage *Im, ScribusDoc* doc);
 
/*! \brief Associate a color shade to a document color according to pre-1.3.4cvs rgb shade calculation method,
creating new document color if necessary
* \param doc the scribus document
* \param colName the color name (modified in place)
* \param shade the color level (modified in place)
*/
void SCRIBUS_API handleOldColorShade(ScribusDoc* doc, QString& colName, int& shade);
 
/*! \brief Compute color shade of a rgb color using pre-1.3.4 method
* \param color the base color
* \param shade shade value.
*/
QColor SCRIBUS_API getOldColorShade(const QColor& color, int shade);
/*! \brief Compute color shade of a rgb color using pre-1.3.4 method
* \param red the red component.
* \param green the green component.
* \param blue the blue component.
* \param shade shade value.
*/
QColor SCRIBUS_API getOldColorShade(uchar red, uchar green, uchar blue, int shade);
/*! \brief Convert a color in RGB space to HSV space (Hue, Saturation, Value).
* \param red the red component (modified in place).
* \param green the green component (modified in place).
* \param blue the blue component (modified in place).
*/
unsigned char SCRIBUS_API INT_MULT ( unsigned char a, unsigned char b );
/*! \brief Convert a color in HSV space to RGB space.
* \param hue the hue component (modified in place).
* \param saturation the saturation component (modified in place).
* \param value the value component (modified in place).
*/
void SCRIBUS_API RGBTOHSV ( uchar& red, uchar& green, uchar& blue );
/*! \brief Convert a color in RGB space to HLS space (Hue, Lightness, Saturation).
* \param red the red component (modified in place).
* \param green the green component (modified in place).
* \param blue the blue component (modified in place).
*/
void SCRIBUS_API HSVTORGB ( uchar& hue, uchar& saturation, uchar& value );
void SCRIBUS_API RGBTOHLS ( uchar& red, uchar& green, uchar& blue );
/*! \brief Implement the HLS "double hex-cone".
* \param n1 lightness fraction (?)
* \param n2 saturation fraction (?)
* \param hue hue "angle".
* \return HLS value.
*/
double SCRIBUS_API HLSVALUE ( double n1, double n2, double hue );
/*! \brief Convert a color in HLS space to RGB space.
* \param hue the hue component (modified in place).
* \param lightness the lightness component (modified in place).
* \param saturation the saturation component (modified in place).
*/
void SCRIBUS_API HLSTORGB ( uchar& hue, uchar& lightness, uchar& saturation );
 
double SCRIBUS_API getCurveYValue(FPointArray &curve, double x, bool linear = false);
 
double SCRIBUS_API Lum(uchar red, uchar green, uchar blue);
double SCRIBUS_API LumD(double red, double green, double blue);
void SCRIBUS_API setLum(uchar& red, uchar& green, uchar& blue, double lum);
void SCRIBUS_API clipColor(double& red, double& green, double& blue);
/*! \brief return the translated colorspace name */
QString SCRIBUS_API colorSpaceText(int cs);
 
#endif
Property changes:
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Revision
\ No newline at end of property
Index: Scribus/scribus/util.h
===================================================================
--- Scribus/scribus/util.h (revision 10201)
+++ Scribus/scribus/util.h (revision 10203)
@@ -9,20 +9,15 @@
#include <vector>
-#include <qcolor.h>
-#include <qstring.h>
-#include <qpixmap.h>
-#include <qstringlist.h>
-#include <q3pointarray.h>
-#include <qpoint.h>
-//Added by qt3to4:
+#include <QColor>
+#include <QString>
+#include <QPixmap>
+#include <QStringList>
#include <QByteArray>
#include <QList>
#include <QPainterPath>
#include <QTextStream>
-#include "fpoint.h"
-#include "fpointarray.h"
#include "pagestructs.h"
#include "style.h"
#include "styles/charstyle.h"
@@ -54,21 +49,11 @@
void SCRIBUS_API ReOrderText(ScribusDoc *currentDoc, ScribusView *view);
void SCRIBUS_API WordAndPara(PageItem *currItem, int *w, int *p, int *c, int *wN, int *pN, int *cN);
bool SCRIBUS_API overwrite(QWidget *parent, QString filename);
-FPoint SCRIBUS_API getMaxClipF(FPointArray* Clip);
-FPoint SCRIBUS_API getMinClipF(FPointArray* Clip);
-QString SCRIBUS_API Path2Relative(QString Path);
QByteArray SCRIBUS_API ComputeMD5Sum(QByteArray *in);
char SCRIBUS_API *toHex( uchar u );
QString SCRIBUS_API String2Hex(QString *in, bool lang = true);
QString SCRIBUS_API CompressStr(QString *in);
QByteArray SCRIBUS_API CompressArray(QByteArray *in);
-void SCRIBUS_API BezierPoints(Q3PointArray *ar, QPoint n1, QPoint n2, QPoint n3, QPoint n4);
-double SCRIBUS_API xy2Deg(double x, double y);
-Q3PointArray SCRIBUS_API FlattenPath(FPointArray ina, QList<uint> &Segs);
-QList<QPainterPath> SCRIBUS_API decomposePath(QPainterPath &path);
-Q3PointArray SCRIBUS_API RegularPolygon(double w, double h, uint c, bool star, double factor, double rota);
-FPointArray SCRIBUS_API RegularPolygonF(double w, double h, uint c, bool star, double factor, double rota);
-uint SCRIBUS_API getDouble(QString in, bool raw);
//! \brief WARNING: loadText is INCORRECT - use loadRawText instead!
bool SCRIBUS_API loadText(QString nam, QString *Buffer);
/*! \brief Replacement version of loadText that returns a QCString as an out parameter.
@@ -122,22 +107,6 @@
*/
QString SCRIBUS_API getFileNameByPage(ScribusDoc* currDoc, uint pageNo, QString extension);
void SCRIBUS_API sDebug(QString message);
-inline double SCRIBUS_API square(double);
-inline double SCRIBUS_API distance(double, double);
-/*! \brief Constrains an angle of rotation to 45 degree intervals
- Will make code simpler and reduce interval or provide as a parameter
- \param double angle Angle in degrees
- \param double contrain value in degrees
- \retval double Constrained angle
- */
-double SCRIBUS_API constrainAngle(double angle, double constrain);
-/*! \brief Get the rotation angle (in radian) from a transformation matrix
- Will make code simpler and reduce interval or provide as a parameter
- \param matrix the transformation matrix
- \param def the value that should be return if matrix is not a rotation matrix
- \retval double the rotation angle
- */
-double SCRIBUS_API getRotationFromMatrix(QMatrix& matrix, double def);
const QString SCRIBUS_API getStringFromSequence(DocumentSectionType type, uint position);
const QString SCRIBUS_API arabicToRoman(uint i);
const QString SCRIBUS_API numberToLetterSequence(uint i);
/trunk/Scribus/scribus/colorlistbox.cpp
15,14 → 15,16
#include <QHelpEvent>
 
#include "qdebug.h"
 
#include "commonstrings.h"
#include "sccolorengine.h"
#include "scconfig.h"
#include "commonstrings.h"
#include "scribusdoc.h"
#include "colorutil.h"
#include "util_color.h"
#include "util_icon.h"
#include "sccolorengine.h"
 
 
 
ColorPixmapValue::ColorPixmapValue() : m_color(), m_doc(NULL), m_name("invalid")
{}
 
/trunk/Scribus/scribus/curvewidget.cpp
19,14 → 19,15
#include <QToolTip>
#include <QApplication>
#include <QTextStream>
#include "colorutil.h"
#include "commonstrings.h"
#include "customfdialog.h"
#include "prefsfile.h"
#include "prefsmanager.h"
#include "util.h"
#include "util_color.h"
#include "util_icon.h"
#include "prefsmanager.h"
#include "prefsfile.h"
#include "commonstrings.h"
 
 
KCurve::KCurve(QWidget *parent) : QWidget(parent)
{
m_grab_point = FPoint();
/trunk/Scribus/scribus/cmykfw.cpp
31,19 → 31,20
#include <QAction>
#include <cstdlib>
 
#include "colorchart.h"
#include "colorlistbox.h"
#include "commonstrings.h"
#include "sccolorengine.h"
#include "sccombobox.h"
#include "scrspinbox.h"
#include "scconfig.h"
#include "scpaths.h"
#include "scribusdoc.h"
#include "colorutil.h"
#include "colorlistbox.h"
#include "colorchart.h"
#include "scrspinbox.h"
#include "util.h"
#include "util_color.h"
#include "util_icon.h"
#include "sccolorengine.h"
 
 
CMYKChoose::CMYKChoose( QWidget* parent, ScribusDoc* doc, ScColor orig, QString name, ColorList *Colors, QStringList Cust, bool newCol )
: QDialog( parent ), CurrSwatch(doc)
{
/trunk/Scribus/scribus/pageitem_desaxe.cpp
1,20 → 1,21
 
 
 
#include "desaxe/saxiohelper.h"
#include "desaxe/simple_actions.h"
#include "pageitem.h"
#include "util.h"
#include "desaxe/simple_actions.h"
#include "desaxe/saxiohelper.h"
#include "pageitem_imageframe.h"
#include "pageitem_textframe.h"
#include "pageitem_line.h"
#include "pageitem_pathtext.h"
#include "pageitem_polygon.h"
#include "pageitem_polyline.h"
#include "pageitem_polygon.h"
#include "pageitem_line.h"
#include "pageitem_textframe.h"
#include "scribusdoc.h"
#include "colorutil.h"
#include "util_color.h"
#include "util_math.h"
 
 
 
using namespace desaxe;
 
 
/trunk/Scribus/scribus/pdflib_core.cpp
58,6 → 58,7
#include "bookpalette.h"
#include "scfonts.h"
#include "util.h"
#include "util_math.h"
#include "prefsmanager.h"
#include "prefscontext.h"
#include "pdfoptions.h"
/trunk/Scribus/scribus/scimgdataloader_ps.cpp
18,6 → 18,7
#include "scimgdataloader_ps.h"
#include "prefsmanager.h"
#include "util.h"
#include "util_math.h"
#include "cmsettings.h"
#include "scimage.h"
 
/trunk/Scribus/scribus/polygonwidget.cpp
20,7 → 20,7
#include <QSlider>
#include <QCheckBox>
#include <cmath>
#include "util.h"
#include "util_math.h"
 
using namespace std;
 
/trunk/Scribus/scribus/customfdialog.cpp
43,7 → 43,6
#include "customfdialog.h"
 
#include "cmsettings.h"
#include "colorutil.h"
#include "commonstrings.h"
#include "formatutils.h"
#include "sccombobox.h"
50,9 → 49,11
#include "scimage.h"
#include "scribusstructs.h"
#include "util.h"
#include "util_color.h"
#include "util_icon.h"
 
 
 
extern QString DocDir;
 
ImIconProvider::ImIconProvider() : QFileIconProvider()
/trunk/Scribus/scribus/annotation.cpp
3,6 → 3,7
 
#include "annotation.h"
#include "util.h"
#include "util_math.h"
 
void Annotation::saxx(SaxHandler& handler, const Xml_string& elemtag) const
{
/trunk/Scribus/scribus/arrowchooser.cpp
9,7 → 9,7
#include <QImage>
#include "fpointarray.h"
#include "scpainter.h"
#include "util.h"
#include "util_math.h"
#include "commonstrings.h"
 
ArrowChooser::ArrowChooser(QWidget* pa, bool direction) : QComboBox(pa)
/trunk/Scribus/scribus/effectsdialog.cpp
24,17 → 24,19
#include <QTime>
#include <QStackedWidget>
#include <QTextStream>
 
#include "cmsettings.h"
#include "colorcombo.h"
#include "cmsettings.h"
#include "curvewidget.h"
#include "page.h"
#include "sccombobox.h"
#include "scribusdoc.h"
#include "scrspinbox.h"
#include "shadebutton.h"
#include "scrspinbox.h"
#include "page.h"
#include "colorutil.h"
#include "curvewidget.h"
#include "util_color.h"
#include "util_icon.h"
 
 
EffectsDialog::EffectsDialog( QWidget* parent, PageItem* item, ScribusDoc* docc ) : QDialog( parent )
{
setModal(true);
/trunk/Scribus/scribus/scribusdoc.cpp
70,6 → 70,7
#include "undostate.h"
#include "units.h"
#include "util.h"
#include "util_math.h"
#include "commonstrings.h"
#include "sccolorengine.h"
 
/trunk/Scribus/scribus/stencilreader.cpp
11,7 → 11,7
#include "sccolor.h"
#include "scribus.h"
#include "splash.h"
#include "util.h"
#include "util_math.h"
#include "prefsmanager.h"
#include "scpainter.h"
#include "commonstrings.h"
/trunk/Scribus/scribus/scimgdataloader_tiff.cpp
11,7 → 11,7
#include <QList>
#include "scconfig.h"
#include "scimgdataloader_tiff.h"
#include "colorutil.h"
#include "util_color.h"
#include CMS_INC
 
static void TagExtender(TIFF *tiff)
/trunk/Scribus/scribus/colorcombo.cpp
14,7 → 14,6
*/
 
#include "colorcombo.h"
//#include "colorcombo.moc"
#include "commonstrings.h"
#include "qdebug.h"
 
/trunk/Scribus/scribus/smlinestyle.cpp
5,30 → 5,31
for which a new license (GPL+exception) is in place.
*/
 
#include "smlinestyle.h"
#include "scribusdoc.h"
#include "linecombo.h"
#include "scrspinbox.h"
 
#include "colorcombo.h"
#include "colorlistbox.h"
#include "colorutil.h"
#include "commonstrings.h"
#include "linecombo.h"
#include "mpalette.h"
#include "sccolorengine.h"
#include "scribus.h"
#include "scribusdoc.h"
#include "scribusview.h"
#include "scrspinbox.h"
#include "selection.h"
#include "scribusview.h"
#include "scribus.h"
#include "sccolorengine.h"
#include "mpalette.h"
#include "smlinestyle.h"
#include "util.h"
#include "util_color.h"
#include "util_icon.h"
#include <q3header.h>
#include <q3listbox.h>
#include <q3listview.h>
#include <qlayout.h>
#include <qlineedit.h>
#include <q3listview.h>
#include <qpixmap.h>
#include <qpushbutton.h>
#include <qpixmap.h>
#include <qtabwidget.h>
#include <qlayout.h>
#include <q3listbox.h>
 
#include "util.h"
#include "util_icon.h"
 
/*** LineStyleWidget *******************************************************/
 
/trunk/Scribus/scribus/scpainter.cpp
6,7 → 6,7
*/
 
#include "scpainter.h"
#include "colorutil.h"
#include "util_color.h"
 
#ifdef HAVE_CAIRO
#include <cairo.h>
/trunk/Scribus/scribus/scimage.cpp
24,15 → 24,16
#include <cassert>
#include CMS_INC
#include "cmsutil.h"
#include "gsutil.h"
#include "commonstrings.h"
#include "exif.h"
#include "formatutils.h"
#include "commonstrings.h"
#include "colorutil.h"
#include "util.h"
#include "gsutil.h"
#include "rawimage.h"
#include "sccolorengine.h"
#include "util.h"
#include "util_color.h"
 
 
using namespace std;
 
typedef struct my_error_mgr
/trunk/Scribus/scribus/util_color.cpp
0,0 → 1,626
/*
For general Scribus (>=1.3.2) copyright and licensing information please refer
to the COPYING file provided with the program. Following this notice may exist
a copyright and/or license notice that predates the release of Scribus 1.3.2
for which a new license (GPL+exception) is in place.
*/
/***************************************************************************
util.cpp - description
-------------------
begin : Fri Sep 14 2001
copyright : (C) 2001 by Franz Schmid
email : Franz.Schmid@altmuehlnet.de
***************************************************************************/
 
/***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
 
#include "util_color.h"
 
#include <qbitmap.h>
#include <qdatetime.h>
#include <qpainter.h>
#include <qcheckbox.h>
//Added by qt3to4:
#include <QPixmap>
// #include <algorithm>
// #include <cstdlib>
// #include <cmath>
 
#include "scconfig.h"
 
//#ifdef HAVE_UNISTD_H
//#include <unistd.h>
//#endif
 
#if defined(_WIN32)
#if defined(_MSC_VER)
#define __STDC__ 1 // hack to get md5_buffer correctly identified
#endif
#include <valarray>
#include <windows.h>
#endif
 
#include "md5.h"
 
// #include <setjmp.h>
// #include "commonstrings.h"
// #include "pagestructs.h"
// #include "prefsfile.h"
// #include "prefscontext.h"
// #include "prefstable.h"
// #include "prefsmanager.h"
// #include "qprocess.h"
// #include "scmessagebox.h"
#include "scribusdoc.h"
#include "scpixmapcache.h"
#include "commonstrings.h"
// #include "scpaths.h"
// #include "text/nlsconfig.h"
#include "util_icon.h"
#include "util.h"
#include "sccolorengine.h"
 
extern "C"
{
#define XMD_H // shut JPEGlib up
#if defined(Q_OS_UNIXWARE)
# define HAVE_BOOLEAN // libjpeg under Unixware seems to need this
#endif
#include <jpeglib.h>
#include <jerror.h>
#undef HAVE_STDLIB_H
#ifdef const
# undef const // remove crazy C hackery in jconfig.h
#endif
}
 
#include CMS_INC
using namespace std;
 
void handleOldColorShade(ScribusDoc* doc, QString& colName, int& shade)
{
int r, g, b;
bool found = false;
if( colName.isEmpty() || colName == CommonStrings::None || !doc->PageColors.contains(colName))
return;
 
const ScColor& scCol1(doc->PageColors[colName]);
if( (shade == 100) || (scCol1.getColorModel() != colorModelRGB) )
return;
scCol1.getRGB(&r, &g, &b);
QColor col1 = getOldColorShade(r, g, b, shade), col2;
ColorList::Iterator it, itEnd = doc->PageColors.end();
for( it = doc->PageColors.begin(); it != itEnd; it++)
{
if ( it.data().getColorModel() == colorModelRGB )
{
it.data().getRGB(&r, &g, &b);
col2.setRgb(r, g, b);
if( col1 == col2 )
{
found = true;
break;
}
}
}
if(!found)
{
ScColor tmp;
tmp.fromQColor(col1);
colName = QString("%1 %2%").arg(colName).arg(shade);
doc->PageColors.insert(colName, tmp);
}
else
colName = it.key();
shade = 100;
}
 
QColor getOldColorShade(const QColor& color, int shade)
{
int r, g, b;
color.getRgb(&r, &g, &b);
return getOldColorShade(r, g, b, shade);
}
 
QColor getOldColorShade(uchar red, uchar green, uchar blue, int shade)
{
int h, s, v, snew;
QColor color(red, green, blue);
color.hsv(&h, &s, &v);
if (red == green && green == blue)
{
snew = 255 - ((255 - v) * shade / 100);
color.setHsv(h, s, snew);
}
else
{
snew = s * shade / 100;
color.setHsv(h, snew, v);
}
return color;
}
 
QImage ProofImage(QImage *Image, ScribusDoc* doc)
{
QImage out = Image->copy();
bool cmsUse = doc ? doc->HasCMS : false;
bool softProofing = doc ? doc->SoftProofing : false;
if (cmsUse && softProofing)
{
int outheight=out.height();
for (int i=0; i < outheight; ++i)
{
LPBYTE ptr = out.scanLine(i);
cmsDoTransform(doc->stdProofImg, ptr, ptr, out.width());
}
}
else
{
if (cmsUse)
{
int outheight=out.height();
for (int i=0; i < outheight; ++i)
{
LPBYTE ptr = out.scanLine(i);
cmsDoTransform(doc->stdTransImg, ptr, ptr, out.width());
}
}
}
return out;
}
 
QColor SetColor(ScribusDoc *currentDoc, QString color, int shad)
{
const ScColor& col = currentDoc->PageColors[color];
return ScColorEngine::getShadeColorProof(col, currentDoc, shad);
}
 
 
/**
* QPixmaps are really slow with Qt/Mac 3.3.4. Really, *really*, slow.
* So we better cache them.
*/
QPixmap * getSmallPixmap(QColor rgb)
{
static ScPixmapCache<QRgb> pxCache;
 
QRgb index=rgb.rgb();
if (pxCache.contains(index))
return pxCache[index];
 
QPixmap *pm = new QPixmap(15, 15);
pm->fill(rgb);
QPainter p;
p.begin(pm);
p.setBrush(Qt::NoBrush);
QPen b(Qt::black, 1);
p.setPen(b);
p.drawRect(0, 0, 15, 15);
p.end();
pxCache.insert(index, pm);
return pm;
}
 
QPixmap * getWidePixmap(QColor rgb)
{
static ScPixmapCache<QRgb> pxCache;
 
QRgb index=rgb.rgb();
if (pxCache.contains(index))
return pxCache[index];
 
QPixmap *pm = new QPixmap(30, 15);
pm->fill(rgb);
pxCache.insert(index, pm);
return pm;
}
 
static Q_UINT64 code64(const ScColor & col) {
int C, M, Y, K, R, G, B;
Q_UINT64 result=0;
col.getRGB( &R, &G, &B );
col.getCMYK( &C, &M, &Y, &K );
result |= col.getColorModel() == colorModelRGB ? 1 : 0;
result |= col.isSpotColor() ? 64 : 0;
result |= col.isRegistrationColor() ? 32 : 0;
result <<= 8;
result |= C;
result <<= 8;
result |= M;
result <<= 8;
result |= Y;
result <<= 8;
result |= K;
result <<= 8;
result |= R;
result <<= 8;
result |= G;
result <<= 8;
result |= B;
return result;
}
 
QPixmap * getFancyPixmap(const ScColor& col, ScribusDoc* doc) {
static ScPixmapCache<Q_UINT64> pxCache;
 
static QPixmap alertIcon;
static QPixmap cmykIcon;
static QPixmap rgbIcon;
static QPixmap spotIcon;
static QPixmap regIcon;
static bool iconsInitialized = false;
 
if ( !iconsInitialized ) {
alertIcon = loadIcon("alert.png");
cmykIcon = loadIcon("cmyk.png");
rgbIcon = loadIcon("rgb.png");
spotIcon = loadIcon("spot.png");
regIcon = loadIcon("register.png");
iconsInitialized = true;
}
 
Q_UINT64 res=code64(col);
if (pxCache.contains(res))
return pxCache[res];
 
QPixmap *pa=new QPixmap(60, 15);
QPixmap *pm=getSmallPixmap(col.getRawRGBColor());
pa->fill(Qt::white);
paintAlert(*pm, *pa, 0, 0);
if (ScColorEngine::isOutOfGamut(col, doc))
paintAlert(alertIcon, *pa, 15, 0);
if ((col.getColorModel() == colorModelCMYK) || (col.isSpotColor()))
paintAlert(cmykIcon, *pa, 30, 0);
else
paintAlert(rgbIcon, *pa, 30, 0);
if (col.isSpotColor())
paintAlert(spotIcon, *pa, 46, 2);
if (col.isRegistrationColor())
paintAlert(regIcon, *pa, 45, 0);
pxCache.insert(res, pa);
return pa;
}
 
 
void paintAlert(QPixmap &toPaint, QPixmap &target, int x, int y, bool useMask)
{
// there is no alpha mask in the beginning
if (useMask)
{
if (target.mask().isNull())
target.setMask(QBitmap(target.width(), target.height(), useMask));
}
QPainter p;
p.begin(&target);
p.drawPixmap(x, y, toPaint);
if (useMask)
{
// Qt4 FIXME: Qt4 can use better alpha setting. see colorlistbox.cpp
// QPainter alpha; // transparency handling
// alpha.begin(target.mask());
// alpha.setBrush(Qt::color1);
// alpha.setPen(Qt::color1);
// alpha.drawRect(x, y, 15, 15);
// if (!toPaint.mask().isNull())
// alpha.drawPixmap(x, y, toPaint.mask());
// alpha.end();
}
p.end();
}
 
unsigned char INT_MULT ( unsigned char a, unsigned char b )
{
int c = a * b + 0x80;
return (unsigned char)(( ( c >> 8 ) + c ) >> 8);
}
 
void RGBTOHSV ( uchar& red, uchar& green, uchar& blue )
{
int r, g, b;
double h, s, v;
int min, max;
h = 0.;
r = red;
g = green;
b = blue;
if ( r > g )
{
max = qMax( r, b );
min = qMin( g, b );
}
else
{
max = qMax( g, b );
min = qMin( r, b );
}
v = max;
if ( max != 0 )
s = ( ( max - min ) * 255 ) / (double)max;
else
s = 0;
if ( s == 0 )
h = 0;
else
{
int delta = max - min;
if ( r == max )
h = ( g - b ) / (double)delta;
else if ( g == max )
h = 2 + ( b - r ) / (double)delta;
else if ( b == max )
h = 4 + ( r - g ) / (double)delta;
h *= 42.5;
if ( h < 0 )
h += 255;
if ( h > 255 )
h -= 255;
}
red = (uchar)h;
green = (uchar)s;
blue = (uchar)v;
}
 
void HSVTORGB ( uchar& hue, uchar& saturation, uchar& value )
{
if ( saturation == 0 )
{
hue = value;
saturation = value;
value = value;
}
else
{
double h = hue * 6. / 255.;
double s = saturation / 255.;
double v = value / 255.;
 
double f = h - (int)h;
double p = v * ( 1. - s );
double q = v * ( 1. - ( s * f ) );
double t = v * ( 1. - ( s * ( 1. - f ) ) );
// Worth a note here that gcc 2.96 will generate different results
// depending on optimization mode on i386.
switch ((int)h)
{
case 0:
hue = (uchar)( v * 255 );
saturation = (uchar)( t * 255 );
value = (uchar)( p * 255 );
break;
case 1:
hue = (uchar)( q * 255 );
saturation = (uchar)( v * 255 );
value = (uchar)( p * 255 );
break;
case 2:
hue = (uchar)( p * 255 );
saturation = (uchar)( v * 255 );
value = (uchar)( t * 255 );
break;
case 3:
hue = (uchar)( p * 255 );
saturation = (uchar)( q * 255 );
value = (uchar)( v * 255 );
break;
case 4:
hue = (uchar)( t * 255 );
saturation = (uchar)( p * 255 );
value = (uchar)( v * 255 );
break;
case 5:
hue = (uchar)( v * 255 );
saturation = (uchar)( p * 255 );
value = (uchar)( q * 255 );
}
}
}
 
void RGBTOHLS ( uchar& red, uchar& green, uchar& blue )
{
double var_R = ( red / 255.0 );
double var_G = ( green / 255.0 );
double var_B = ( blue / 255.0 );
double var_Min = qMin( var_R, qMin(var_G, var_B) ); //Min. value of RGB
double var_Max = qMax( var_R, qMax(var_G, var_B) ); //Max. value of RGB
double del_Max = var_Max - var_Min; //Delta RGB value
double L = ( var_Max + var_Min ) / 2.0;
double H = 0;
double S = 0;
double del_R = 0;
double del_G = 0;
double del_B = 0;
if ( del_Max == 0 )
{
H = 0;
S = 0;
}
else
{
if ( L < 0.5 )
S = del_Max / ( var_Max + var_Min );
else
S = del_Max / ( 2 - var_Max - var_Min );
del_R = ( ( ( var_Max - var_R ) / 6.0 ) + ( del_Max / 2.0 ) ) / del_Max;
del_G = ( ( ( var_Max - var_G ) / 6.0 ) + ( del_Max / 2.0 ) ) / del_Max;
del_B = ( ( ( var_Max - var_B ) / 6.0 ) + ( del_Max / 2.0 ) ) / del_Max;
if ( var_R == var_Max )
H = del_B - del_G;
else if ( var_G == var_Max )
H = ( 1.0 / 3.0 ) + del_R - del_B;
else if ( var_B == var_Max )
H = ( 2.0 / 3.0 ) + del_G - del_R;
if ( H < 0 )
H += 1;
if ( H > 1 )
H -= 1;
}
red = qRound(H * 255);
green = qRound(L * 255);
blue = qRound(S * 255);
}
 
double HLSVALUE ( double n1, double n2, double hue )
{
if ( hue < 0 )
hue += 1;
if ( hue > 1 )
hue -= 1;
if ( ( 6 * hue ) < 1 )
return n1 + ( n2 - n1 ) * 6 * hue;
if ( ( 2 * hue ) < 1 )
return n2;
if ( ( 3 * hue ) < 2 )
return n1 + ( n2 - n1 ) * ( ( 2.0 / 3.0 ) - hue ) * 6;
return n1;
}
 
void HLSTORGB ( uchar& hue, uchar& lightness, uchar& saturation )
{
double H = ( hue / 255.0 );
double L = ( lightness / 255.0 );
double S = ( saturation / 255.0 );
if (S == 0)
{
hue = qRound(255 * L);
saturation = qRound(255 * L);
return;
}
double var_1 = 0;
double var_2 = 0;
if ( L < 0.5 )
var_2 = L * ( 1 + S );
else
var_2 = ( L + S ) - ( S * L );
var_1 = 2 * L - var_2;
hue = qRound(255 * HLSVALUE( var_1, var_2, H + ( 1.0 / 3.0 ) ));
lightness = qRound(255 * HLSVALUE( var_1, var_2, H ));
saturation = qRound(255 * HLSVALUE( var_1, var_2, H - ( 1.0 / 3.0 ) ));
}
 
double getCurveYValue(FPointArray &curve, double x, bool linear)
{
double t;
FPoint p;
FPoint p0,p1,p2,p3;
double c0,c1,c2,c3;
double val = 0.5;
if(curve.size() == 0)
return 0.5;
// First find curve segment
p = curve.point(0);
if(x < p.x())
return p.y();
p = curve.point(curve.size()-1);
if(x >= p.x())
return p.y();
uint cc = 0;
// Find the four control points (two on each side of x)
p = curve.point(0);
while(x >= p.x())
{
cc++;
p = curve.point(cc);
}
if (cc > 1)
{
p0 = curve.point(cc-2);
p1 = curve.point(cc-1);
}
else
p1 = p0 = curve.point(0);
p2 = p;
if (cc < curve.size()-1)
p3 = curve.point(cc+1);
else
p3 = p;
// Calculate the value
if (linear)
{
double mc;
if (p1.x() - p2.x() != 0.0)
mc = (p1.y() - p2.y()) / (p1.x() - p2.x());
else
mc = p2.y() / p2.x();
val = (x - p1.x()) * mc + p1.y();
}
else
{
t = (x - p1.x()) / (p2.x() - p1.x());
c2 = (p2.y() - p0.y()) * (p2.x()-p1.x()) / (p2.x()-p0.x());
c3 = p1.y();
c0 = -2*p2.y() + 2*c3 + c2 + (p3.y() - p1.y()) * (p2.x() - p1.x()) / (p3.x() - p1.x());
c1 = p2.y() - c3 - c2 - c0;
val = ((c0*t + c1)*t + c2)*t + c3;
}
if(val < 0.0)
val = 0.0;
if(val > 1.0)
val = 1.0;
return val;
}
 
double Lum(uchar red, uchar green, uchar blue)
{
return 0.3 * (red / 255.0) + 0.59 * (green / 255.0) + 0.11 * (blue / 255.0);
}
 
double LumD(double red, double green, double blue)
{
return 0.3 * red + 0.59 * green + 0.11 * blue;
}
 
void setLum(uchar& red, uchar& green, uchar& blue, double lum)
{
double rP = (red / 255.0);
double gP = (green / 255.0);
double bP = (blue / 255.0);
double d = lum - Lum(red, green, blue);
rP += d;
gP += d;
bP += d;
clipColor(rP, gP, bP);
red = qRound(rP * 255);
green = qRound(gP * 255);
blue = qRound(bP * 255);
return;
}
 
void clipColor(double& red, double& green, double& blue)
{
double l = LumD(red, green, blue);
double n = qMin(red, qMin(green, blue));
double x = qMax(red, qMax(green, blue));
if (n < 0.0)
{
red = l + (((red - l) * l) / (l - n));
green = l + (((green - l) * l) / (l - n));
blue = l + (((blue - l) * l) / (l - n));
}
if (x > 1.0)
{
red = l + (((red - l) * (1.0 - l)) / (x - l));
green = l + (((green - l) * (1.0 - l)) / (x - l));
blue = l + (((blue - l) * (1.0 - l)) / (x - l));
}
}
 
QString colorSpaceText(int cs)
{
if (cs==0)
return CommonStrings::trRGB;
if (cs==1)
return CommonStrings::trCMYK;
if (cs==2)
return CommonStrings::trGrayscale;
if (cs==3)
return CommonStrings::trDuotone;
return CommonStrings::trUnknownCS;
}
Property changes:
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Revision
\ No newline at end of property
Index: Scribus/scribus/plugins/scriptplugin/cmdobj.cpp
===================================================================
--- Scribus/scribus/plugins/scriptplugin/cmdobj.cpp (revision 10201)
+++ Scribus/scribus/plugins/scriptplugin/cmdobj.cpp (revision 10203)
@@ -7,7 +7,7 @@
#include "cmdobj.h"
#include "cmdutil.h"
#include "selection.h"
-#include "util.h"
+#include "util_math.h"
#include "commonstrings.h"
#include "scribuscore.h"
/trunk/Scribus/scribus/plugins/wmfimplugin/wmfimport.cpp
38,6 → 38,7
#include "loadsaveplugin.h"
#include "util.h"
#include "util_icon.h"
#include "util_math.h"
#include "fonts/scfontmetrics.h"
 
using namespace std;
/trunk/Scribus/scribus/plugins/colorwheel/cwdialog.cpp
14,7 → 14,7
#include "prefsfile.h"
#include "mpalette.h"
#include "colorblind.h"
#include "colorutil.h"
#include "util_color.h"
#include "colorlistbox.h"
#include "sccolorengine.h"
 
/trunk/Scribus/scribus/plugins/svgimplugin/svgplugin.cpp
36,6 → 36,7
#include "loadsaveplugin.h"
#include "util.h"
#include "util_icon.h"
#include "util_math.h"
#include "fonts/scfontmetrics.h"
#include "sccolorengine.h"
 
/trunk/Scribus/scribus/plugins/fileloader/scribus12format/scribus12format.cpp
18,7 → 18,7
 
#include "units.h"
#include "util.h"
#include "colorutil.h"
#include "util_color.h"
#include "scgzfile.h"
#include <qcursor.h>
#include <qfileinfo.h>
/trunk/Scribus/scribus/plugins/fileloader/scribus13format/scribus13format.cpp
19,7 → 19,8
 
#include "units.h"
#include "util.h"
#include "colorutil.h"
#include "util_math.h"
#include "util_color.h"
#include "scgzfile.h"
#include <qcursor.h>
#include <qfileinfo.h>
/trunk/Scribus/scribus/plugins/fileloader/oodraw/oodrawimp.cpp
39,6 → 39,7
#include "pluginmanager.h"
#include "util.h"
#include "util_icon.h"
#include "util_math.h"
#include "stylestack.h"
#include "scraction.h"
#include "menumanager.h"
/trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format_save.cpp
18,7 → 18,8
 
#include "units.h"
#include "util.h"
#include "colorutil.h"
#include "util_math.h"
#include "util_color.h"
#include "scgzfile.h"
#include <QCursor>
#include <QFileInfo>
/trunk/Scribus/scribus/plugins/fileloader/scribus134format/scribus134format.cpp
19,7 → 19,8
 
#include "units.h"
#include "util.h"
#include "colorutil.h"
#include "util_math.h"
#include "util_color.h"
#include "scgzfile.h"
#include <QCursor>
#include <QFileInfo>
/trunk/Scribus/scribus/plugins/psimport/importps.cpp
40,6 → 40,7
#include "loadsaveplugin.h"
#include "util.h"
#include "util_icon.h"
#include "util_math.h"
 
extern SCRIBUS_API ScribusQApp * ScQApp;
 
/trunk/Scribus/scribus/fontprefs.cpp
29,8 → 29,8
#include "scribusdoc.h"
#include "prefsmanager.h"
#include "scconfig.h"
#include "colorutil.h"
#include "util.h"
#include "util_color.h"
#include "util_icon.h"
#include "scpaths.h"
 
/trunk/Scribus/scribus/util_math.h
0,0 → 1,55
/*
For general Scribus (>=1.3.2) copyright and licensing information please refer
to the COPYING file provided with the program. Following this notice may exist
a copyright and/or license notice that predates the release of Scribus 1.3.2
for which a new license (GPL+exception) is in place.
*/
#ifndef _UTIL_MATH_H
#define _UTIL_MATH_H
 
#include <vector>
 
#include <QString>
#include <QStringList>
#include <Q3PointArray>
#include <QPoint>
#include <QList>
#include <QPainterPath>
#include <QTextStream>
 
#include "fpoint.h"
#include "fpointarray.h"
#include "scribusapi.h"
 
/*! \brief Compare double values by pre-multiplying by 10000 and converting to long if possible.
If premultiplication does not allow to store result in a long value, perform a standard comparison.
*/
bool SCRIBUS_API compareDouble(double a, double b);
FPoint SCRIBUS_API getMaxClipF(FPointArray* Clip);
FPoint SCRIBUS_API getMinClipF(FPointArray* Clip);
QString SCRIBUS_API Path2Relative(QString Path);
void SCRIBUS_API BezierPoints(Q3PointArray *ar, QPoint n1, QPoint n2, QPoint n3, QPoint n4);
double SCRIBUS_API xy2Deg(double x, double y);
Q3PointArray SCRIBUS_API FlattenPath(FPointArray ina, QList<uint> &Segs);
QList<QPainterPath> SCRIBUS_API decomposePath(QPainterPath &path);
Q3PointArray SCRIBUS_API RegularPolygon(double w, double h, uint c, bool star, double factor, double rota);
FPointArray SCRIBUS_API RegularPolygonF(double w, double h, uint c, bool star, double factor, double rota);
uint SCRIBUS_API getDouble(QString in, bool raw);
inline double SCRIBUS_API square(double);
inline double SCRIBUS_API distance(double, double);
/*! \brief Constrains an angle of rotation to 45 degree intervals
Will make code simpler and reduce interval or provide as a parameter
\param double angle Angle in degrees
\param double contrain value in degrees
\retval double Constrained angle
*/
double SCRIBUS_API constrainAngle(double angle, double constrain);
/*! \brief Get the rotation angle (in radian) from a transformation matrix
Will make code simpler and reduce interval or provide as a parameter
\param matrix the transformation matrix
\param def the value that should be return if matrix is not a rotation matrix
\retval double the rotation angle
*/
double SCRIBUS_API getRotationFromMatrix(QMatrix& matrix, double def);
 
#endif
/trunk/Scribus/scribus/tree.cpp
22,7 → 22,7
#include "tree.h"
 
#include "actionmanager.h"
#include "colorutil.h"
#include "util_color.h"
#include "commonstrings.h"
#include "formatutils.h"
#include "mpalette.h"
/trunk/Scribus/scribus/scpreview.cpp
29,6 → 29,7
#include "scribuscore.h"
#include "splash.h"
#include "util.h"
#include "util_math.h"
#include "prefsmanager.h"
#include "scpainter.h"
#include "commonstrings.h"
/trunk/Scribus/scribus/pslib.cpp
47,6 → 47,7
#include "selection.h"
#include <cmath>
#include "util.h"
#include "util_math.h"
#include "multiprogressdialog.h"
#include "scribusapp.h"
#include "scpattern.h"
/trunk/Scribus/scribus/CMakeLists.txt
266,7 → 266,6
colorlistbox.cpp
colorm.cpp
colorsetmanager.cpp
colorutil.cpp
commonstrings.cpp
cpalette.cpp
createrange.cpp
489,7 → 488,9
upgradechecker.cpp
useprintermarginsdialog.cpp
util.cpp
util_color.cpp
util_icon.cpp
util_math.cpp
vgradient.cpp
vgradientex.cpp
vruler.cpp
/trunk/Scribus/scribus/picsearch.cpp
8,15 → 8,16
#include <qpixmap.h>
#include <qpainter.h>
 
#include "colorutil.h"
#include "commonstrings.h"
#include "formatutils.h"
#include "scribusstructs.h"
#include "scimage.h"
#include "commonstrings.h"
#include "scpaths.h"
#include "scribusstructs.h"
#include "util.h"
#include "util_color.h"
#include "util_icon.h"
 
 
PicSearch::PicSearch(QWidget* parent, const QString & fileName, const QStringList & avalableFiles)
: QDialog( parent, "PicSearch", true, 0 ),
currentImage(QString())