From 850b7b7f530e206b2caf7e00db3d8e696bc625a0 Mon Sep 17 00:00:00 2001 From: Enrico Ros Date: Fri, 8 Apr 2005 08:58:49 +0000 Subject: [PATCH] Added 3 custom attributes to the Highlight annotation. Adapted pdf parser and xml storage stuff. svn path=/branches/kpdf_annotations/kdegraphics/kpdf/; revision=403983 --- core/annotations.cpp | 48 ++++++++++++++++------------ core/annotations.h | 9 +++++- core/generator_pdf/generator_pdf.cpp | 14 +++++--- 3 files changed, 45 insertions(+), 26 deletions(-) diff --git a/core/annotations.cpp b/core/annotations.cpp index 9b9c96247..cb678d96a 100644 --- a/core/annotations.cpp +++ b/core/annotations.cpp @@ -604,16 +604,19 @@ HighlightAnnotation::HighlightAnnotation( const QDomNode & node ) if ( qe.tagName() != "quad" ) continue; - NormalizedPoint p[4]; - p[0].x = qe.attribute( "ax", "0.0" ).toDouble(); - p[0].y = qe.attribute( "ay", "0.0" ).toDouble(); - p[1].x = qe.attribute( "bx", "0.0" ).toDouble(); - p[1].y = qe.attribute( "by", "0.0" ).toDouble(); - p[2].x = qe.attribute( "cx", "0.0" ).toDouble(); - p[2].y = qe.attribute( "cy", "0.0" ).toDouble(); - p[3].x = qe.attribute( "dx", "0.0" ).toDouble(); - p[3].y = qe.attribute( "dy", "0.0" ).toDouble(); - highlightQuads.append( p ); + Quad q; + q.points[0].x = qe.attribute( "ax", "0.0" ).toDouble(); + q.points[0].y = qe.attribute( "ay", "0.0" ).toDouble(); + q.points[1].x = qe.attribute( "bx", "0.0" ).toDouble(); + q.points[1].y = qe.attribute( "by", "0.0" ).toDouble(); + q.points[2].x = qe.attribute( "cx", "0.0" ).toDouble(); + q.points[2].y = qe.attribute( "cy", "0.0" ).toDouble(); + q.points[3].x = qe.attribute( "dx", "0.0" ).toDouble(); + q.points[3].y = qe.attribute( "dy", "0.0" ).toDouble(); + q.capStart = qe.hasAttribute( "start" ); + q.capEnd = qe.hasAttribute( "end" ); + q.feather = qe.attribute( "feather", "0.1" ).toDouble(); + highlightQuads.append( q ); } // loading complete @@ -636,20 +639,25 @@ void HighlightAnnotation::store( QDomNode & node, QDomDocument & document ) cons if ( highlightQuads.count() < 1 ) return; // append highlight quads, all children describe quads - QValueList::const_iterator it = highlightQuads.begin(), end = highlightQuads.end(); + QValueList< Quad >::const_iterator it = highlightQuads.begin(), end = highlightQuads.end(); for ( ; it != end; ++it ) { QDomElement quadElement = document.createElement( "quad" ); hlElement.appendChild( quadElement ); - const NormalizedPoint * p = *it; - quadElement.setAttribute( "ax", p[0].x ); - quadElement.setAttribute( "ay", p[0].y ); - quadElement.setAttribute( "bx", p[1].x ); - quadElement.setAttribute( "by", p[1].y ); - quadElement.setAttribute( "cx", p[2].x ); - quadElement.setAttribute( "cy", p[2].y ); - quadElement.setAttribute( "dx", p[3].x ); - quadElement.setAttribute( "dy", p[3].y ); + const Quad & q = *it; + quadElement.setAttribute( "ax", q.points[0].x ); + quadElement.setAttribute( "ay", q.points[0].y ); + quadElement.setAttribute( "bx", q.points[1].x ); + quadElement.setAttribute( "by", q.points[1].y ); + quadElement.setAttribute( "cx", q.points[2].x ); + quadElement.setAttribute( "cy", q.points[2].y ); + quadElement.setAttribute( "dx", q.points[3].x ); + quadElement.setAttribute( "dy", q.points[3].y ); + if ( q.capStart ) + quadElement.setAttribute( "start", 1 ); + if ( q.capEnd ) + quadElement.setAttribute( "end", 1 ); + quadElement.setAttribute( "feather", q.feather ); } } diff --git a/core/annotations.h b/core/annotations.h index 3adbcfef0..62c4349f6 100644 --- a/core/annotations.h +++ b/core/annotations.h @@ -210,7 +210,14 @@ struct HighlightAnnotation : public Annotation // data fields HighlightType highlightType; // Highlight - QValueList highlightQuads; + struct Quad + { + NormalizedPoint points[4]; // 8 valid coords + bool capStart; // false (vtx 1-4) [K] + bool capEnd; // false (vtx 2-3) [K] + double feather; // 0.1 (in range 0..1) [K] + }; + QValueList< Quad > highlightQuads; // not empty }; struct StampAnnotation : public Annotation diff --git a/core/generator_pdf/generator_pdf.cpp b/core/generator_pdf/generator_pdf.cpp index bdb224285..1d3ae3a70 100644 --- a/core/generator_pdf/generator_pdf.cpp +++ b/core/generator_pdf/generator_pdf.cpp @@ -1068,12 +1068,16 @@ void PDFGenerator::addAnnotations( Page * pdfPage, KPDFPage * page ) annot.free(); continue; } - for ( int p = 0; p < num; p += 8 ) + for ( int q = 0; q < num; q += 8 ) { - NormalizedPoint quad[4]; - for ( int q = 0; q < 4; q++ ) - XPDFReader::transform( MTX, c[ p + q*2 ], c[ p + q*2 + 1 ], &quad[q].x, &quad[q].y ); - h->highlightQuads.push_back( quad ); + HighlightAnnotation::Quad quad; + for ( int p = 0; p < 4; p++ ) + XPDFReader::transform( MTX, c[ q + p*2 ], c[ q + p*2 + 1 ], + &quad.points[ p ].x, &quad.points[ p ].y ); + quad.capStart = true; // unlinked quads are always capped + quad.capEnd = true; // unlinked quads are always capped + quad.feather = 0.1; // default feather + h->highlightQuads.append( quad ); } } else if ( subType == "Stamp" )