From 2d64d446d7ec51b59ff3d7aa73a7b68d3e69ca1f Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Thu, 13 Jul 2006 16:08:50 +0000 Subject: [PATCH] Read correctly the 'poly' links for DjVu documents. svn path=/trunk/playground/graphics/okular/; revision=561918 --- generators/djvu/generator_djvu.cpp | 26 +++++++++++++++++++++++++- generators/djvu/kdjvu.cpp | 17 +++++++++++++++-- generators/djvu/kdjvu.h | 6 +++--- 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/generators/djvu/generator_djvu.cpp b/generators/djvu/generator_djvu.cpp index 3fa22e580..9ddac8b7b 100644 --- a/generators/djvu/generator_djvu.cpp +++ b/generators/djvu/generator_djvu.cpp @@ -194,7 +194,8 @@ void DjVuGenerator::djvuPixmapGenerated( int page, const QPixmap & pix ) const KDjVu::Page* p = m_djvu->pages().at( newpage == -1 ? page : newpage ); int width = p->width(); int height = p->height(); - if ( m_request->documentRotation % 2 == 1 ) + bool scape_orientation = ( m_request->documentRotation % 2 == 1 ); + if ( scape_orientation ) qSwap( width, height ); ObjectRect *newrect = 0; switch ( curlink->areaType() ) @@ -207,6 +208,29 @@ void DjVuGenerator::djvuPixmapGenerated( int page, const QPixmap & pix ) newrect = new ObjectRect( NormalizedRect( okularUtils::rotateRect( r, width, height, m_request->documentRotation ), width, height ), ellipse, ObjectRect::Link, newlink ); break; } + case KDjVu::Link::PolygonArea: + { + QPolygon poly = curlink->polygon(); + QPolygonF newpoly; + for ( int i = 0; i < poly.count(); ++i ) + { + int x = poly.at(i).x(); + int y = poly.at(i).y(); + if ( scape_orientation ) + qSwap( x, y ); + else + { + y = height - y; + } + newpoly << QPointF( (double)(x)/width, (double)(y)/height ); + } + if ( !newpoly.isEmpty() ) + { + newpoly << newpoly.first(); + newrect = new ObjectRect( newpoly, ObjectRect::Link, newlink ); + } + break; + } default: ; } if ( newrect ) diff --git a/generators/djvu/kdjvu.cpp b/generators/djvu/kdjvu.cpp index 1ea80774e..0055e45f7 100644 --- a/generators/djvu/kdjvu.cpp +++ b/generators/djvu/kdjvu.cpp @@ -159,7 +159,7 @@ QSize KDjVu::Link::size() const return m_size; } -QPolygonF KDjVu::Link::polygon() const +QPolygon KDjVu::Link::polygon() const { return m_poly; } @@ -498,6 +498,7 @@ QList KDjVu::linksForPage( int pageNum ) const } if ( link ) { + link->m_area = KDjVu::Link::UnknownArea; miniexp_t area = miniexp_nth( 3, cur ); int arealength = miniexp_length( area ); if ( ( arealength == 5 ) && miniexp_symbolp( miniexp_nth( 0, area ) ) && @@ -515,9 +516,21 @@ QList KDjVu::linksForPage( int pageNum ) const link->m_area = KDjVu::Link::EllipseArea; } } + else if ( ( arealength > 0 ) && ( arealength % 2 == 1 ) && + miniexp_symbolp( miniexp_nth( 0, area ) ) && + ( qstrncmp( miniexp_to_name( miniexp_nth( 0, area ) ), "poly", 4 ) == 0 ) ) + { + link->m_area = KDjVu::Link::PolygonArea; + QPolygon poly; + for ( int j = 1; j < arealength; j += 2 ) + { + poly << QPoint( miniexp_to_int( miniexp_nth( j, area ) ), miniexp_to_int( miniexp_nth( j + 1, area ) ) ); + } + link->m_poly = poly; + } // TODO: other link shapes - if ( !( link->m_point.isNull() || link->m_size.isNull() ) ) + if ( link->m_area != KDjVu::Link::UnknownArea ) ret.append( link ); } } diff --git a/generators/djvu/kdjvu.h b/generators/djvu/kdjvu.h index 457302d5a..31ffe3a1e 100644 --- a/generators/djvu/kdjvu.h +++ b/generators/djvu/kdjvu.h @@ -63,18 +63,18 @@ class KDjVu : public QObject virtual ~Link(); enum LinkType { PageLink, UrlLink }; - enum LinkArea { RectArea, EllipseArea, PolygonArea }; + enum LinkArea { UnknownArea, RectArea, EllipseArea, PolygonArea }; virtual int type() const = 0; LinkArea areaType() const; QPoint point() const; QSize size() const; - QPolygonF polygon() const; + QPolygon polygon() const; private: LinkArea m_area; QPoint m_point; QSize m_size; - QPolygonF m_poly; + QPolygon m_poly; }; /**