Commit c4e612d6 authored by Christophe Devriese's avatar Christophe Devriese

bugfixes, removed a lot of processEvent calls that caused crashes

svn path=/trunk/kdegraphics/kpdf/; revision=242829
parent 100be6fa
......@@ -71,7 +71,11 @@ struct QOutFontSubst {
};
static QOutFontSubst qStdFonts [] = {
{ "Helvetica", "Helvetica", false, false, QFont::Helvetica },
{ "Helvetica",
"Helvetica",
false,
false,
QFont::Helvetica },
{ "Helvetica-Oblique", "Helvetica", false, true, QFont::Helvetica },
{ "Helvetica-Bold", "Helvetica", true, false, QFont::Helvetica },
{ "Helvetica-BoldOblique", "Helvetica", true, true, QFont::Helvetica },
......@@ -86,25 +90,19 @@ static QOutFontSubst qStdFonts [] = {
{ "Symbol", 0, false, false, QFont::AnyStyle },
{ "Zapf-Dingbats", 0, false, false, QFont::AnyStyle },
{ 0, 0, false, false, QFont::AnyStyle }
};
QFont QOutputDev::matchFont ( GfxFont *gfxFont, fp_t m11, fp_t m12, fp_t m21, fp_t m22 )
QFont QOutputDev::matchFont ( GfxFont *gfxFont, fp_t m11, fp_t m12, fp_t m21, fp_t m22 )
{
static QDict<QOutFontSubst> stdfonts;
// build dict for std. fonts on first invocation
// build dict for std. fonts on first invocation
if ( stdfonts. isEmpty ( )) {
for ( QOutFontSubst *ptr = qStdFonts; ptr-> m_name; ptr++ ) {
stdfonts. insert ( QString ( ptr-> m_name ), ptr );
}
}
}
// compute size and normalized transform matrix
......@@ -130,32 +128,32 @@ QFont QOutputDev::matchFont ( GfxFont *gfxFont, fp_t m11, fp_t m12, fp_t m21, fp
// fast lookup for std. fonts
QOutFontSubst *subst = stdfonts [fname];
if ( subst ) {
if ( subst-> m_sname )
f. setFamily ( subst-> m_sname );
f. setStyleHint ( subst-> m_hint, (QFont::StyleStrategy) ( QFont::PreferOutline | QFont::PreferQuality ));
f. setStyleHint ( subst-> m_hint, (QFont::StyleStrategy) ( QFont::PreferOutline | QFont::PreferQuality ));
f. setBold ( subst-> m_bold );
f. setItalic ( subst-> m_italic );
}
else {
QFont::StyleHint sty;
if ( gfxFont-> isSerif ( ))
sty = QFont::Serif;
else if ( gfxFont-> isFixedWidth ( ))
sty = QFont::TypeWriter;
else
sty = QFont::Helvetica;
f. setStyleHint ( sty, (QFont::StyleStrategy) ( QFont::PreferOutline | QFont::PreferQuality ));
f. setStyleHint ( sty, (QFont::StyleStrategy) ( QFont::PreferOutline | QFont::PreferQuality ));
f. setBold ( gfxFont-> isBold ( ) > 0 );
f. setItalic ( gfxFont-> isItalic ( ) > 0 );
f. setFixedPitch ( gfxFont-> isFixedWidth ( ) > 0 );
// common specifiers in font names
// common specifiers in font names
if ( fname. contains ( "Oblique" ) || fname. contains ( "Italic" ))
f. setItalic ( true );
f. setItalic ( true );
if ( fname. contains ( "Bold" ))
f. setWeight ( QFont::Bold );
if ( fname. contains ( "Demi" ))
......@@ -164,11 +162,11 @@ QFont QOutputDev::matchFont ( GfxFont *gfxFont, fp_t m11, fp_t m12, fp_t m21, fp
f. setWeight ( QFont::Light );
if ( fname. contains ( "Black" ))
f. setWeight ( QFont::Black );
}
}
// Treat x-sheared fonts as italic
if (( m12 > -0.1 ) && ( m12 < 0.1 ) && ((( m21 > -5.0 ) && ( m21 < -0.1 )) || (( m21 > 0.1 ) && ( m21 < 5.0 )))) {
f. setItalic ( true );
}
f. setItalic ( true );
}
return f;
}
......@@ -182,7 +180,7 @@ QOutputDev::QOutputDev ( QWidget *parent, const char *name, int flags ) : QScrol
{
m_pixmap = 0;
m_painter = 0;
// create text object
m_text = new TextPage ( gFalse );
......@@ -190,7 +188,7 @@ QOutputDev::QOutputDev ( QWidget *parent, const char *name, int flags ) : QScrol
setMouseTracking(true);
}
QOutputDev::~QOutputDev ( )
QOutputDev::~QOutputDev ( )
{
delete m_painter;
delete m_pixmap;
......@@ -198,46 +196,46 @@ QOutputDev::~QOutputDev ( )
}
void QOutputDev::startPage ( int /*pageNum*/, GfxState *state )
void QOutputDev::startPage ( int /*pageNum*/, GfxState *state )
{
delete m_pixmap;
delete m_painter;
m_pixmap = new QPixmap ( lrint ( state-> getPageWidth ( )), lrint ( state-> getPageHeight ( )));
m_painter = new QPainter ( m_pixmap );
QPDFDBG( printf ( "NEW PIXMAP (%ld x %ld)\n", lrint ( state-> getPageWidth ( )), lrint ( state-> getPageHeight ( ))));
resizeContents ( m_pixmap-> width ( ), m_pixmap-> height ( ));
setContentsPos ( 0, 0 );
m_pixmap-> fill ( white ); // clear window
m_text-> clear ( ); // cleat text object
viewport ( )-> repaint ( );
m_text-> clear ( ); // cleat text object
viewport ( )-> repaint ( );
}
void QOutputDev::endPage ( )
void QOutputDev::endPage ( )
{
m_text-> coalesce ( );
delete m_painter;
m_painter = 0;
updateContents ( 0, 0, contentsWidth ( ), contentsHeight ( ));
}
void QOutputDev::drawLink ( Link *link, Catalog */*catalog*/ )
void QOutputDev::drawLink ( Link *link, Catalog */*catalog*/ )
{
fp_t x1, y1, x2, y2, w;
link-> getBorder ( &x1, &y1, &x2, &y2, &w );
if ( w > 0 ) {
int x, y, dx, dy;
cvtUserToDev ( x1, y1, &x, &y );
cvtUserToDev ( x2, y2, &dx, &dy );
QPen oldpen = m_painter-> pen ( );
m_painter-> setPen ( blue );
m_painter-> drawRect ( x, y, dx, dy );
......@@ -245,23 +243,23 @@ void QOutputDev::drawLink ( Link *link, Catalog */*catalog*/ )
}
}
void QOutputDev::saveState ( GfxState */*state*/ )
void QOutputDev::saveState ( GfxState */*state*/ )
{
QPDFDBG( printf ( "SAVE (CLIP=%d/%d)\n", m_painter-> hasClipping ( ), !m_painter-> clipRegion ( ). isEmpty ( )));
m_painter-> save ( );
m_painter-> save ( );
}
void QOutputDev::restoreState ( GfxState */*state*/ )
void QOutputDev::restoreState ( GfxState */*state*/ )
{
m_painter-> restore ( );
// m_painter-> setClipRegion ( QRect ( 0, 0, m_pixmap-> width ( ), m_pixmap-> height ( )));
// m_painter-> setClipping ( false );
QPDFDBG ( printf ( "RESTORE (CLIP=%d/%d)\n", m_painter-> hasClipping ( ), !m_painter-> clipRegion ( ). isEmpty ( )));
}
void QOutputDev::updateAll ( GfxState *state )
void QOutputDev::updateAll ( GfxState *state )
{
updateLineAttrs ( state, gTrue );
// updateFlatness ( state );
......@@ -271,44 +269,44 @@ void QOutputDev::updateAll ( GfxState *state )
updateFont ( state );
}
void QOutputDev::updateCTM ( GfxState *state, fp_t /*m11*/, fp_t /*m12*/, fp_t /*m21*/, fp_t /*m22*/, fp_t /*m31*/, fp_t /*m32*/ )
void QOutputDev::updateCTM ( GfxState *state, fp_t /*m11*/, fp_t /*m12*/, fp_t /*m21*/, fp_t /*m22*/, fp_t /*m31*/, fp_t /*m32*/ )
{
updateLineAttrs ( state, gTrue );
}
void QOutputDev::updateLineDash ( GfxState *state )
void QOutputDev::updateLineDash ( GfxState *state )
{
updateLineAttrs ( state, gTrue );
}
void QOutputDev::updateFlatness ( GfxState */*state*/ )
void QOutputDev::updateFlatness ( GfxState */*state*/ )
{
// not supported
QPDFDBG( printf ( "updateFlatness not supported !\n" ));
}
void QOutputDev::updateLineJoin ( GfxState *state )
void QOutputDev::updateLineJoin ( GfxState *state )
{
updateLineAttrs ( state, gFalse );
}
void QOutputDev::updateLineCap ( GfxState *state )
void QOutputDev::updateLineCap ( GfxState *state )
{
updateLineAttrs ( state, gFalse );
}
// unimplemented
void QOutputDev::updateMiterLimit ( GfxState */*state*/ )
void QOutputDev::updateMiterLimit ( GfxState */*state*/ )
{
QPDFDBG( printf ( "updateMiterLimit not supported !\n" ));
}
void QOutputDev::updateLineWidth ( GfxState *state )
void QOutputDev::updateLineWidth ( GfxState *state )
{
updateLineAttrs ( state, gFalse );
}
void QOutputDev::updateLineAttrs ( GfxState *state, GBool updateDash )
void QOutputDev::updateLineAttrs ( GfxState *state, GBool updateDash )
{
fp_t *dashPattern;
int dashLength;
......@@ -319,7 +317,7 @@ void QOutputDev::updateLineAttrs ( GfxState *state, GBool updateDash )
int width;
width = lrint ( state-> getTransformedLineWidth ( ));
switch ( state-> getLineCap ( )) {
case 0: cap = FlatCap; break;
case 1: cap = RoundCap; break;
......@@ -329,7 +327,7 @@ void QOutputDev::updateLineAttrs ( GfxState *state, GBool updateDash )
cap = FlatCap;
break;
}
switch (state->getLineJoin()) {
case 0: join = MiterJoin; break;
case 1: join = RoundJoin; break;
......@@ -339,7 +337,7 @@ void QOutputDev::updateLineAttrs ( GfxState *state, GBool updateDash )
join = MiterJoin;
break;
}
state-> getLineDash ( &dashPattern, &dashLength, &dashStart );
QColor oldcol = m_painter-> pen ( ). color ( );
......@@ -352,7 +350,7 @@ void QOutputDev::updateLineAttrs ( GfxState *state, GBool updateDash )
if ( updateDash && ( dashLength > 0 )) {
// Not supported by QT
/*
/*
char dashList[20];
if (dashLength > 20)
dashLength = 20;
......@@ -366,7 +364,7 @@ void QOutputDev::updateLineAttrs ( GfxState *state, GBool updateDash )
}
}
void QOutputDev::updateFillColor ( GfxState *state )
void QOutputDev::updateFillColor ( GfxState *state )
{
GfxRGB rgb;
state-> getFillRGB ( &rgb );
......@@ -374,35 +372,35 @@ void QOutputDev::updateFillColor ( GfxState *state )
m_painter-> setBrush ( q_col ( rgb ));
}
void QOutputDev::updateStrokeColor ( GfxState *state )
void QOutputDev::updateStrokeColor ( GfxState *state )
{
GfxRGB rgb;
state-> getStrokeRGB ( &rgb );
QPen pen = m_painter-> pen ( );
pen. setColor ( q_col ( rgb ));
m_painter-> setPen ( pen );
}
void QOutputDev::updateFont ( GfxState *state )
void QOutputDev::updateFont ( GfxState *state )
{
fp_t m11, m12, m21, m22;
GfxFont *gfxFont = state-> getFont ( );
if ( !gfxFont )
return;
state-> getFontTransMat ( &m11, &m12, &m21, &m22 );
m11 *= state-> getHorizScaling ( );
m12 *= state-> getHorizScaling ( );
QFont font = matchFont ( gfxFont, m11, m12, m21, m22 );
m_painter-> setFont ( font );
m_text-> updateFont ( state );
}
void QOutputDev::stroke ( GfxState *state )
void QOutputDev::stroke ( GfxState *state )
{
QPointArray points;
QArray<int> lengths;
......@@ -411,31 +409,30 @@ void QOutputDev::stroke ( GfxState *state )
int n = convertPath ( state, points, lengths );
QPDFDBG( printf ( "DRAWING: %d POLYS\n", n ));
// draw each subpath
int j = 0;
for ( int i = 0; i < n; i++ ) {
int len = lengths [i];
if ( len >= 2 ) {
QPDFDBG( printf ( " - POLY %d: ", i ));
QPDFDBG( for ( int ii = 0; ii < len; ii++ ))
QPDFDBG( printf ( "(%d/%d) ", points [j+ii]. x ( ), points [j+ii]. y ( )));
QPDFDBG( printf ( "\n" ));
m_painter-> drawPolyline ( points, j, len );
}
}
j += len;
}
qApp-> processEvents ( );
}
void QOutputDev::fill ( GfxState *state )
void QOutputDev::fill ( GfxState *state )
{
doFill ( state, true );
}
void QOutputDev::eoFill ( GfxState *state )
void QOutputDev::eoFill ( GfxState *state )
{
doFill ( state, false );
}
......@@ -449,7 +446,7 @@ void QOutputDev::eoFill ( GfxState *state )
// only for single-component polygons, since it's not very
// compatible with the compound polygon kludge (see convertPath()).
//
void QOutputDev::doFill ( GfxState *state, bool winding )
void QOutputDev::doFill ( GfxState *state, bool winding )
{
QPointArray points;
QArray<int> lengths;
......@@ -458,41 +455,39 @@ void QOutputDev::doFill ( GfxState *state, bool winding )
int n = convertPath ( state, points, lengths );
QPDFDBG( printf ( "FILLING: %d POLYS\n", n ));
QPen oldpen = m_painter-> pen ( );
m_painter-> setPen ( QPen ( NoPen ));
// draw each subpath
int j = 0;
for ( int i = 0; i < n; i++ ) {
int len = lengths [i];
if ( len >= 3 ) {
QPDFDBG( printf ( " - POLY %d: ", i ));
QPDFDBG( for ( int ii = 0; ii < len; ii++ ))
QPDFDBG( printf ( "(%d/%d) ", points [j+ii]. x ( ), points [j+ii]. y ( )));
QPDFDBG( printf ( "\n" ));
m_painter-> drawPolygon ( points, winding, j, len );
}
}
j += len;
}
m_painter-> setPen ( oldpen );
qApp-> processEvents ( );
}
void QOutputDev::clip ( GfxState *state )
void QOutputDev::clip ( GfxState *state )
{
doClip ( state, true );
}
void QOutputDev::eoClip ( GfxState *state )
void QOutputDev::eoClip ( GfxState *state )
{
doClip ( state, false );
}
void QOutputDev::doClip ( GfxState *state, bool winding )
void QOutputDev::doClip ( GfxState *state, bool winding )
{
QPointArray points;
QArray<int> lengths;
......@@ -501,38 +496,37 @@ void QOutputDev::doClip ( GfxState *state, bool winding )
int n = convertPath ( state, points, lengths );
QRegion region;
QPDFDBG( printf ( "CLIPPING: %d POLYS\n", n ));
// draw each subpath
int j = 0;
for ( int i = 0; i < n; i++ ) {
int len = lengths [i];
if ( len >= 3 ) {
if ( len >= 3 ) {
QPointArray dummy;
dummy. setRawData ( points. data ( ) + j, len );
QPDFDBG( printf ( " - POLY %d: ", i ));
QPDFDBG( for ( int ii = 0; ii < len; ii++ ) printf ( "(%d/%d) ", points [j+ii]. x ( ), points [j+ii]. y ( )));
QPDFDBG( printf ( "\n" ));
region |= QRegion ( dummy, winding );
dummy. resetRawData ( points. data ( ) + j, len );
}
}
j += len;
}
if ( m_painter-> hasClipping ( ))
region &= m_painter-> clipRegion ( );
// m_painter-> setClipRegion ( region );
// m_painter-> setClipping ( true );
// m_painter-> fillRect ( 0, 0, m_pixmap-> width ( ), m_pixmap-> height ( ), red );
// m_painter-> drawText ( points [0]. x ( ) + 10, points [0]. y ( ) + 10, "Bla bla" );
qApp-> processEvents ( );
}
//
......@@ -544,7 +538,7 @@ void QOutputDev::doClip ( GfxState *state, bool winding )
// Then it connects subaths within a single compound polygon to a single
// point so that X can fill the polygon (sort of).
//
int QOutputDev::convertPath ( GfxState *state, QPointArray &points, QArray<int> &lengths )
int QOutputDev::convertPath ( GfxState *state, QPointArray &points, QArray<int> &lengths )
{
GfxPath *path = state-> getPath ( );
int n = path-> getNumSubpaths ( );
......@@ -572,36 +566,36 @@ int QOutputDev::convertSubpath ( GfxState *state, GfxSubpath *subpath, QPointArr
int m = subpath-> getNumPoints ( );
int i = 0;
while ( i < m ) {
if ( i >= 1 && subpath-> getCurve ( i )) {
state-> transform ( subpath-> getX ( i - 1 ), subpath-> getY ( i - 1 ), &x0, &y0 );
state-> transform ( subpath-> getX ( i ), subpath-> getY ( i ), &x1, &y1 );
state-> transform ( subpath-> getX ( i + 1 ), subpath-> getY ( i + 1 ), &x2, &y2 );
state-> transform ( subpath-> getX ( i + 2 ), subpath-> getY ( i + 2 ), &x3, &y3 );
QPointArray tmp;
tmp. setPoints ( 4, lrint ( x0 ), lrint ( y0 ), lrint ( x1 ), lrint ( y1 ),
lrint ( x2 ), lrint ( y2 ), lrint ( x3 ), lrint ( y3 ));
#if QT_VERSION < 300
tmp = tmp. quadBezier ( );
for ( uint loop = 0; loop < tmp. count ( ); loop++ ) {
QPoint p = tmp. point ( loop );
points. putPoints ( points. count ( ), 1, p. x ( ), p. y ( ));
}
#else
tmp = tmp. cubicBezier ( );
points. putPoints ( points. count ( ), tmp. count ( ), tmp );
points. putPoints ( points. count ( ), tmp. count ( ), tmp );
#endif
i += 3;
}
}
else {
state-> transform ( subpath-> getX ( i ), subpath-> getY ( i ), &x1, &y1 );
points. putPoints ( points. count ( ), 1, lrint ( x1 ), lrint ( y1 ));
points. putPoints ( points. count ( ), 1, lrint ( x1 ), lrint ( y1 ));
++i;
}
}
......@@ -609,22 +603,22 @@ int QOutputDev::convertSubpath ( GfxState *state, GfxSubpath *subpath, QPointArr
}
void QOutputDev::beginString ( GfxState *state, GString */*s*/ )
void QOutputDev::beginString ( GfxState *state, GString */*s*/ )
{
m_text-> beginString ( state, state->getCurX(), state->getCurY() );
}
void QOutputDev::endString ( GfxState */*state*/ )
void QOutputDev::endString ( GfxState */*state*/ )
{
m_text-> endString ( );
}
void QOutputDev::drawChar ( GfxState *state, fp_t x, fp_t y,
fp_t dx, fp_t dy, fp_t originX, fp_t originY,
CharCode code, Unicode *u, int uLen )
CharCode code, Unicode *u, int uLen )
{
fp_t x1, y1, dx1, dy1;
if ( uLen > 0 )
m_text-> addChar ( state, x, y, dx, dy, u, uLen );
......@@ -642,10 +636,10 @@ void QOutputDev::drawChar ( GfxState *state, fp_t x, fp_t y,
if ( uLen > 0 ) {
QString str;
QFontMetrics fm = m_painter-> fontMetrics ( );
for ( int i = 0; i < uLen; i++ ) {
QChar c = QChar ( u [i] );
if ( fm. inFont ( c )) {
str [i] = QChar ( u [i] );
}
......@@ -654,78 +648,77 @@ void QOutputDev::drawChar ( GfxState *state, fp_t x, fp_t y,
QPDFDBG( printf ( "CHARACTER NOT IN FONT: %hx\n", c. unicode ( )));
}
}
if (( uLen == 1 ) && ( str [0] == ' ' ))
return;
fp_t m11, m12, m21, m22;
state-> getFontTransMat ( &m11, &m12, &m21, &m22 );
m11 *= state-> getHorizScaling ( );
m12 *= state-> getHorizScaling ( );
fp_t fsize = m_painter-> font ( ). pixelSize ( );
#ifndef QT_NO_TRANSFORMATIONS
QWMatrix oldmat;
bool dorot = (( m12 < -0.1 ) || ( m12 > 0.1 )) && (( m21 < -0.1 ) || ( m21 > 0.1 ));
if ( dorot ) {
bool dorot = (( m12 < -0.1 ) || ( m12 > 0.1 )) && (( m21 < -0.1 ) || ( m21 > 0.1 ));
if ( dorot ) {
oldmat = m_painter-> worldMatrix ( );
// std::cerr << std::endl << "ROTATED: " << m11 << ", " << m12 << ", " << m21 << ", " << m22 << " / SIZE: " << fsize << " / TEXT: " << str. local8Bit ( ) << endl << endl;
QWMatrix mat ( lrint ( m11 / fsize ), lrint ( m12 / fsize ), -lrint ( m21 / fsize ), -lrint ( m22 / fsize ), lrint ( x1 ), lrint ( y1 ));
m_painter-> setWorldMatrix ( mat );
x1 = 0;
y1 = 0;
y1 = 0;
}
#endif
QPen oldpen = m_painter-> pen ( );