remember, pino, remember: djvu coordinates refer to the lower-left corner of a page.

fix the coordinate loading for the annotations

svn path=/trunk/playground/graphics/okular/; revision=604204
remotes/origin/KDE/4.0
Pino Toscano 20 years ago
parent 28c63b44e8
commit cb414fbf1d
  1. 36
      generators/djvu/generator_djvu.cpp
  2. 25
      generators/djvu/kdjvu.cpp
  3. 8
      generators/djvu/kdjvu.h

@ -260,12 +260,22 @@ void DjVuGenerator::djvuImageGenerated( int page, const QImage & img )
{ {
KDjVu::Annotation *ann = (*it); KDjVu::Annotation *ann = (*it);
Okular::Annotation *newann = 0; Okular::Annotation *newann = 0;
const KDjVu::Page* p = m_djvu->pages().at( page );
int width = p->width();
int height = p->height();
bool scape_orientation = false; // hack by tokoe, should always create default page
if ( scape_orientation )
qSwap( width, height );
switch ( ann->type() ) switch ( ann->type() )
{ {
case KDjVu::Annotation::TextAnnotation: case KDjVu::Annotation::TextAnnotation:
{ {
KDjVu::TextAnnotation* txtann = static_cast<KDjVu::TextAnnotation*>( ann ); KDjVu::TextAnnotation* txtann = static_cast<KDjVu::TextAnnotation*>( ann );
Okular::TextAnnotation * newtxtann = new Okular::TextAnnotation(); Okular::TextAnnotation * newtxtann = new Okular::TextAnnotation();
// boundary
QRect rect( QPoint( txtann->point().x(), height - txtann->point().y() - txtann->size().height() ), txtann->size() );
newtxtann->boundary = Okular::NormalizedRect( Okular::Utils::rotateRect( rect, width, height, 0 ), width, height );
// type
newtxtann->textType = txtann->inlineText() ? Okular::TextAnnotation::InPlace : Okular::TextAnnotation::Linked; newtxtann->textType = txtann->inlineText() ? Okular::TextAnnotation::InPlace : Okular::TextAnnotation::Linked;
newtxtann->style.opacity = txtann->color().alphaF(); newtxtann->style.opacity = txtann->color().alphaF();
newann = newtxtann; newann = newtxtann;
@ -275,17 +285,18 @@ void DjVuGenerator::djvuImageGenerated( int page, const QImage & img )
{ {
KDjVu::LineAnnotation* lineann = static_cast<KDjVu::LineAnnotation*>( ann ); KDjVu::LineAnnotation* lineann = static_cast<KDjVu::LineAnnotation*>( ann );
Okular::LineAnnotation * newlineann = new Okular::LineAnnotation(); Okular::LineAnnotation * newlineann = new Okular::LineAnnotation();
const KDjVu::Page* p = m_djvu->pages().at( page ); // boundary
int width = p->width(); QPoint a( lineann->point().x(), height - lineann->point().y() );
int height = p->height(); QPoint b( lineann->point2().x(), height - lineann->point2().y() );
bool scape_orientation = false; // hack by tokoe, should always create default page QRect rect = QRect( a, b ).normalized();
if ( scape_orientation ) newlineann->boundary = Okular::NormalizedRect( Okular::Utils::rotateRect( rect, width, height, 0 ), width, height );
qSwap( width, height ); // line points
Okular::NormalizedRect tmprect( ann->rect(), width, height ); newlineann->linePoints.append( Okular::NormalizedPoint( a.x(), a.y(), width, height ) );
newlineann->linePoints.append( Okular::NormalizedPoint( tmprect.left, tmprect.top ) ); newlineann->linePoints.append( Okular::NormalizedPoint( b.x(), b.y(), width, height ) );
newlineann->linePoints.append( Okular::NormalizedPoint( tmprect.right, tmprect.bottom ) ); // arrow?
if ( lineann->isArrow() ) if ( lineann->isArrow() )
newlineann->lineEndStyle = Okular::LineAnnotation::OpenArrow; newlineann->lineEndStyle = Okular::LineAnnotation::OpenArrow;
// width
newlineann->style.width = lineann->width(); newlineann->style.width = lineann->width();
newann = newlineann; newann = newlineann;
break; break;
@ -294,13 +305,6 @@ void DjVuGenerator::djvuImageGenerated( int page, const QImage & img )
if ( newann ) if ( newann )
{ {
// setting the common parameters // setting the common parameters
const KDjVu::Page* p = m_djvu->pages().at( page );
int width = p->width();
int height = p->height();
bool scape_orientation = false; // hack by tokoe, should always create default page
if ( scape_orientation )
qSwap( width, height );
newann->boundary = Okular::NormalizedRect( ann->rect(), width, height );
newann->style.color = ann->color(); newann->style.color = ann->color();
newann->contents = ann->comment(); newann->contents = ann->comment();

@ -201,9 +201,9 @@ KDjVu::Annotation::~Annotation()
{ {
} }
QRect KDjVu::Annotation::rect() const QPoint KDjVu::Annotation::point() const
{ {
return m_rect; return m_point;
} }
QString KDjVu::Annotation::comment() const QString KDjVu::Annotation::comment() const
@ -223,6 +223,11 @@ KDjVu::TextAnnotation::TextAnnotation()
{ {
} }
QSize KDjVu::TextAnnotation::size() const
{
return m_size;
}
int KDjVu::TextAnnotation::type() const int KDjVu::TextAnnotation::type() const
{ {
return KDjVu::Annotation::TextAnnotation; return KDjVu::Annotation::TextAnnotation;
@ -245,6 +250,11 @@ int KDjVu::LineAnnotation::type() const
return KDjVu::Annotation::LineAnnotation; return KDjVu::Annotation::LineAnnotation;
} }
QPoint KDjVu::LineAnnotation::point2() const
{
return m_point2;
}
bool KDjVu::LineAnnotation::isArrow() const bool KDjVu::LineAnnotation::isArrow() const
{ {
return m_isArrow; return m_isArrow;
@ -577,14 +587,17 @@ void KDjVu::linksAndAnnotationsForPage( int pageNum, QList<KDjVu::Link*>& links,
int d = miniexp_to_int( miniexp_nth( 4, area ) ); int d = miniexp_to_int( miniexp_nth( 4, area ) );
if ( type == QLatin1String( "text" ) ) if ( type == QLatin1String( "text" ) )
{ {
ann = new KDjVu::TextAnnotation(); KDjVu::TextAnnotation * textann = new KDjVu::TextAnnotation();
ann->m_rect = QRect( a, b - d, c, d ); textann->m_size = QSize( c, d );
ann = textann;
} }
else if ( type == QLatin1String( "line" ) ) else if ( type == QLatin1String( "line" ) )
{ {
ann = new KDjVu::LineAnnotation(); KDjVu::LineAnnotation * lineann = new KDjVu::LineAnnotation();
ann->m_rect = QRect( a, b, c - a, b - d ); lineann->m_point2 = QPoint( c, d );
ann = lineann;
} }
ann->m_point = QPoint( a, b );
ann->m_comment = QString::fromUtf8( miniexp_to_str( miniexp_nth( 2, cur ) ) ); ann->m_comment = QString::fromUtf8( miniexp_to_str( miniexp_nth( 2, cur ) ) );
} }
if ( link ) if ( link )

@ -124,12 +124,12 @@ class KDjVu : public QObject
enum AnnotationType { TextAnnotation, LineAnnotation }; enum AnnotationType { TextAnnotation, LineAnnotation };
virtual int type() const = 0; virtual int type() const = 0;
QRect rect() const; QPoint point() const;
QString comment() const; QString comment() const;
QColor color() const; QColor color() const;
private: private:
QRect m_rect; QPoint m_point;
QString m_comment; QString m_comment;
QColor m_color; QColor m_color;
}; };
@ -143,10 +143,12 @@ class KDjVu : public QObject
public: public:
virtual int type() const; virtual int type() const;
QSize size() const;
bool inlineText() const; bool inlineText() const;
private: private:
TextAnnotation(); TextAnnotation();
QSize m_size;
bool m_inlineText; bool m_inlineText;
}; };
@ -159,11 +161,13 @@ class KDjVu : public QObject
public: public:
virtual int type() const; virtual int type() const;
QPoint point2() const;
bool isArrow() const; bool isArrow() const;
int width() const; int width() const;
private: private:
LineAnnotation(); LineAnnotation();
QPoint m_point2;
bool m_isArrow; bool m_isArrow;
int m_width; int m_width;
}; };

Loading…
Cancel
Save