Changeset View
Changeset View
Standalone View
Standalone View
ui/pagepainter.cpp
| Show All 13 Lines | |||||
| 14 | #include <qpainter.h> | 14 | #include <qpainter.h> | ||
| 15 | #include <qpalette.h> | 15 | #include <qpalette.h> | ||
| 16 | #include <qpixmap.h> | 16 | #include <qpixmap.h> | ||
| 17 | #include <qvarlengtharray.h> | 17 | #include <qvarlengtharray.h> | ||
| 18 | #include <kiconloader.h> | 18 | #include <kiconloader.h> | ||
| 19 | #include <QDebug> | 19 | #include <QDebug> | ||
| 20 | #include <QApplication> | 20 | #include <QApplication> | ||
| 21 | #include <QIcon> | 21 | #include <QIcon> | ||
| 22 | #include <QTransform> | ||||
| 22 | 23 | | |||
| 23 | // system includes | 24 | // system includes | ||
| 24 | #include <math.h> | 25 | #include <math.h> | ||
| 25 | 26 | | |||
| 26 | // local includes | 27 | // local includes | ||
| 27 | #include "core/area.h" | 28 | #include "core/area.h" | ||
| 28 | #include "core/page.h" | 29 | #include "core/page.h" | ||
| 29 | #include "core/page_p.h" | 30 | #include "core/page_p.h" | ||
| ▲ Show 20 Lines • Show All 410 Lines • ▼ Show 20 Line(s) | 424 | { | |||
| 440 | { | 441 | { | ||
| 441 | Okular::Annotation * a = *aIt; | 442 | Okular::Annotation * a = *aIt; | ||
| 442 | Okular::Annotation::SubType type = a->subType(); | 443 | Okular::Annotation::SubType type = a->subType(); | ||
| 443 | QColor acolor = a->style().color(); | 444 | QColor acolor = a->style().color(); | ||
| 444 | if ( !acolor.isValid() ) | 445 | if ( !acolor.isValid() ) | ||
| 445 | acolor = Qt::yellow; | 446 | acolor = Qt::yellow; | ||
| 446 | acolor.setAlphaF( a->style().opacity() ); | 447 | acolor.setAlphaF( a->style().opacity() ); | ||
| 447 | 448 | | |||
| 448 | // draw LineAnnotation MISSING: all | 449 | // draw LineAnnotation MISSING: caption, dash pattern, endings for multipoint lines | ||
| 449 | if ( type == Okular::Annotation::ALine ) | 450 | if ( type == Okular::Annotation::ALine ) | ||
| 450 | { | 451 | { | ||
| 451 | // get the annotation | 452 | LineAnnotPainter linepainter { (Okular::LineAnnotation *) a, | ||
| 452 | Okular::LineAnnotation * la = (Okular::LineAnnotation *) a; | 453 | { page->width(), page->height() }, pageScale, | ||
| 453 | 454 | { xScale, 0., 0., yScale, -xOffset * xScale, -yOffset * yScale } }; | |||
| 454 | NormalizedPath path; | 455 | linepainter.draw( backImage ); | ||
| 455 | // normalize page point to image | | |||
| 456 | const QLinkedList<Okular::NormalizedPoint> points = la->transformedLinePoints(); | | |||
| 457 | QLinkedList<Okular::NormalizedPoint>::const_iterator it = points.constBegin(); | | |||
| 458 | QLinkedList<Okular::NormalizedPoint>::const_iterator itEnd = points.constEnd(); | | |||
| 459 | for ( ; it != itEnd; ++it ) | | |||
| 460 | { | | |||
| 461 | Okular::NormalizedPoint point; | | |||
| 462 | point.x = ( (*it).x - xOffset) * xScale; | | |||
| 463 | point.y = ( (*it).y - yOffset) * yScale; | | |||
| 464 | path.append( point ); | | |||
| 465 | } | | |||
| 466 | | ||||
| 467 | const QPen linePen = buildPen( a, a->style().width(), a->style().color() ); | | |||
| 468 | QBrush fillBrush; | | |||
| 469 | | ||||
| 470 | if ( la->lineClosed() && la->lineInnerColor().isValid() ) | | |||
| 471 | fillBrush = QBrush( la->lineInnerColor() ); | | |||
| 472 | | ||||
| 473 | // draw the line as normalized path into image | | |||
| 474 | drawShapeOnImage( backImage, path, la->lineClosed(), | | |||
| 475 | linePen, | | |||
| 476 | fillBrush, pageScale ,Multiply); | | |||
| 477 | | ||||
| 478 | if ( path.count() == 2 && fabs( la->lineLeadingForwardPoint() ) > 0.1 ) | | |||
| 479 | { | | |||
| 480 | Okular::NormalizedPoint delta( la->transformedLinePoints().last().x - la->transformedLinePoints().first().x, la->transformedLinePoints().first().y - la->transformedLinePoints().last().y ); | | |||
| 481 | double angle = atan2( delta.y * page->height(), delta.x * page->width() ); | | |||
| 482 | if ( delta.y < 0 ) | | |||
| 483 | angle += 2 * M_PI; | | |||
| 484 | | ||||
| 485 | int sign = la->lineLeadingForwardPoint() > 0.0 ? 1 : -1; | | |||
| 486 | double LLx = fabs( la->lineLeadingForwardPoint() ) * cos( angle + sign * M_PI_2 + 2 * M_PI ) / page->width(); | | |||
| 487 | double LLy = fabs( la->lineLeadingForwardPoint() ) * sin( angle + sign * M_PI_2 + 2 * M_PI ) / page->height(); | | |||
| 488 | | ||||
| 489 | NormalizedPath path2; | | |||
| 490 | NormalizedPath path3; | | |||
| 491 | | ||||
| 492 | Okular::NormalizedPoint point; | | |||
| 493 | point.x = ( la->transformedLinePoints().first().x + LLx - xOffset ) * xScale; | | |||
| 494 | point.y = ( la->transformedLinePoints().first().y - LLy - yOffset ) * yScale; | | |||
| 495 | path2.append( point ); | | |||
| 496 | point.x = ( la->transformedLinePoints().last().x + LLx - xOffset ) * xScale; | | |||
| 497 | point.y = ( la->transformedLinePoints().last().y - LLy - yOffset ) * yScale; | | |||
| 498 | path3.append( point ); | | |||
| 499 | // do we have the extension on the "back"? | | |||
| 500 | if ( fabs( la->lineLeadingBackwardPoint() ) > 0.1 ) | | |||
| 501 | { | | |||
| 502 | double LLEx = la->lineLeadingBackwardPoint() * cos( angle - sign * M_PI_2 + 2 * M_PI ) / page->width(); | | |||
| 503 | double LLEy = la->lineLeadingBackwardPoint() * sin( angle - sign * M_PI_2 + 2 * M_PI ) / page->height(); | | |||
| 504 | point.x = ( la->transformedLinePoints().first().x + LLEx - xOffset ) * xScale; | | |||
| 505 | point.y = ( la->transformedLinePoints().first().y - LLEy - yOffset ) * yScale; | | |||
| 506 | path2.append( point ); | | |||
| 507 | point.x = ( la->transformedLinePoints().last().x + LLEx - xOffset ) * xScale; | | |||
| 508 | point.y = ( la->transformedLinePoints().last().y - LLEy - yOffset ) * yScale; | | |||
| 509 | path3.append( point ); | | |||
| 510 | } | | |||
| 511 | else | | |||
| 512 | { | | |||
| 513 | path2.append( path[0] ); | | |||
| 514 | path3.append( path[1] ); | | |||
| 515 | } | | |||
| 516 | | ||||
| 517 | drawShapeOnImage( backImage, path2, false, linePen, QBrush(), pageScale, Multiply ); | | |||
| 518 | drawShapeOnImage( backImage, path3, false, linePen, QBrush(), pageScale, Multiply ); | | |||
| 519 | } | | |||
| 520 | } | 456 | } | ||
| 521 | // draw HighlightAnnotation MISSING: under/strike width, feather, capping | 457 | // draw HighlightAnnotation MISSING: under/strike width, feather, capping | ||
| 522 | else if ( type == Okular::Annotation::AHighlight ) | 458 | else if ( type == Okular::Annotation::AHighlight ) | ||
| 523 | { | 459 | { | ||
| 524 | // get the annotation | 460 | // get the annotation | ||
| 525 | Okular::HighlightAnnotation * ha = (Okular::HighlightAnnotation *) a; | 461 | Okular::HighlightAnnotation * ha = (Okular::HighlightAnnotation *) a; | ||
| 526 | Okular::HighlightAnnotation::HighlightType type = ha->highlightType(); | 462 | Okular::HighlightAnnotation::HighlightType type = ha->highlightType(); | ||
| 527 | 463 | | |||
| ▲ Show 20 Lines • Show All 467 Lines • ▼ Show 20 Line(s) | 922 | { | |||
| 995 | } | 931 | } | ||
| 996 | if ( closeShape ) | 932 | if ( closeShape ) | ||
| 997 | path.closeSubpath(); | 933 | path.closeSubpath(); | ||
| 998 | 934 | | |||
| 999 | painter.drawPath( path ); | 935 | painter.drawPath( path ); | ||
| 1000 | } | 936 | } | ||
| 1001 | } | 937 | } | ||
| 1002 | 938 | | |||
| 939 | void PagePainter::drawEllipseOnImage( | ||||
| 940 | QImage & image, | ||||
| 941 | const NormalizedPath & rect, | ||||
| 942 | const QPen & pen, | ||||
| 943 | const QBrush & brush, | ||||
| 944 | double penWidthMultiplier, | ||||
| 945 | RasterOperation op | ||||
| 946 | ) | ||||
| 947 | { | ||||
| 948 | const double fImageWidth = (double) image.width(); | ||||
| 949 | const double fImageHeight = (double) image.height(); | ||||
| 950 | | ||||
| 951 | // stroke outline | ||||
| 952 | const double penWidth = (double)pen.width() * penWidthMultiplier; | ||||
| 953 | QPainter painter(&image); | ||||
| 954 | painter.setRenderHint(QPainter::Antialiasing); | ||||
| 955 | QPen pen2 = pen; | ||||
| 956 | pen2.setWidthF(penWidth); | ||||
| 957 | painter.setPen(pen2); | ||||
| 958 | painter.setBrush(brush); | ||||
| 959 | | ||||
| 960 | if ( op == Multiply ) { | ||||
| 961 | painter.setCompositionMode(QPainter::CompositionMode_Multiply); | ||||
| 962 | } | ||||
| 963 | | ||||
| 964 | const QPointF &topLeft { rect[0].x * fImageWidth, rect[0].y * fImageHeight }; | ||||
| 965 | const QSizeF &size { (rect[1].x - rect[0].x) * fImageWidth, (rect[1].y - rect[0].y) * fImageHeight }; | ||||
| 966 | const QRectF imgRect { topLeft, size }; | ||||
| 967 | if ( brush.style() == Qt::NoBrush ) | ||||
| 968 | { | ||||
| 969 | painter.drawArc( imgRect, 0, 16*360 ); | ||||
| 970 | } else { | ||||
| 971 | painter.drawEllipse( imgRect ); | ||||
| 972 | } | ||||
| 973 | } | ||||
| 974 | | ||||
| 975 | LineAnnotPainter::LineAnnotPainter( const Okular::LineAnnotation * a, QSizeF pageSize, double pageScale, const QTransform &toNormalizedImage ) | ||||
| 976 | : la { a } | ||||
| 977 | , pageSize { pageSize } | ||||
| 978 | , pageScale { pageScale } | ||||
| 979 | , toNormalizedImage { toNormalizedImage } | ||||
| 980 | , aspectRatio { pageSize.height() / pageSize.width() } | ||||
| 981 | , linePen { buildPen( a, a->style().width(), a->style().color() ) } | ||||
| 982 | { | ||||
| 983 | if ( ( la->lineClosed() || la->transformedLinePoints().count() == 2 ) && | ||||
| 984 | la->lineInnerColor().isValid() ) | ||||
| 985 | { | ||||
| 986 | fillBrush = QBrush( la->lineInnerColor() ); | ||||
| 987 | } | ||||
| 988 | } | ||||
| 989 | | ||||
| 990 | void LineAnnotPainter::draw( QImage &image ) const | ||||
| 991 | { | ||||
| 992 | if ( la->transformedLinePoints().count() == 2 ) | ||||
| 993 | { | ||||
| 994 | const Okular::NormalizedPoint delta { | ||||
| 995 | la->transformedLinePoints().last().x - la->transformedLinePoints().first().x, | ||||
| 996 | la->transformedLinePoints().first().y - la->transformedLinePoints().last().y | ||||
| 997 | }; | ||||
| 998 | const double angle { atan2( delta.y * aspectRatio, delta.x ) }; | ||||
| 999 | const double cosA { cos( -angle ) }; | ||||
| 1000 | const double sinA { sin( -angle ) }; | ||||
| 1001 | const QTransform tmpMatrix = QTransform { | ||||
| 1002 | cosA, sinA / aspectRatio, | ||||
| 1003 | -sinA, cosA / aspectRatio, | ||||
| 1004 | la->transformedLinePoints().first().x, | ||||
| 1005 | la->transformedLinePoints().first().y }; | ||||
| 1006 | const double deaspectedY { delta.y * aspectRatio }; | ||||
| 1007 | const double mainSegmentLength { sqrt( delta.x * delta.x + deaspectedY * deaspectedY ) }; | ||||
| 1008 | const double lineendSize { std::min( 6. * la->style().width() / pageSize.width(), mainSegmentLength / 2. ) }; | ||||
| 1009 | | ||||
| 1010 | drawShortenedLine( mainSegmentLength, lineendSize, image, tmpMatrix ); | ||||
| 1011 | drawLineEnds( mainSegmentLength, lineendSize, image, tmpMatrix ); | ||||
| 1012 | drawLeaderLine( 0., image, tmpMatrix ); | ||||
| 1013 | drawLeaderLine( mainSegmentLength, image, tmpMatrix ); | ||||
| 1014 | } | ||||
| 1015 | else if ( la->transformedLinePoints().count() > 2 ) | ||||
| 1016 | { | ||||
| 1017 | drawMainLine( image ); | ||||
| 1018 | } | ||||
| 1019 | } | ||||
| 1020 | | ||||
| 1021 | void LineAnnotPainter::drawMainLine( QImage &image ) const | ||||
| 1022 | { | ||||
| 1023 | // draw the line as normalized path into image | ||||
| 1024 | PagePainter::drawShapeOnImage( image, transformPath( | ||||
| 1025 | la->transformedLinePoints(), toNormalizedImage ), la->lineClosed(), | ||||
| 1026 | linePen, fillBrush, pageScale, PagePainter::Multiply ); | ||||
| 1027 | } | ||||
| 1028 | | ||||
| 1029 | void LineAnnotPainter::drawShortenedLine( double mainSegmentLength, double size, QImage &image, const QTransform& toNormalizedPage ) const | ||||
| 1030 | { | ||||
| 1031 | const QTransform combinedTransform { toNormalizedPage * toNormalizedImage }; | ||||
| 1032 | const QList<Okular::NormalizedPoint> path { | ||||
| 1033 | { shortenForArrow(size, la->lineStartStyle()), 0 }, | ||||
| 1034 | { mainSegmentLength - shortenForArrow(size, la->lineEndStyle()), 0 } | ||||
| 1035 | }; | ||||
| 1036 | PagePainter::drawShapeOnImage( image, transformPath(path, combinedTransform), | ||||
| 1037 | la->lineClosed(), linePen, fillBrush, pageScale, PagePainter::Multiply ); | ||||
| 1038 | } | ||||
| 1039 | | ||||
| 1040 | void LineAnnotPainter::drawLineEnds( double mainSegmentLength, double size, QImage &image, const QTransform& transform ) const | ||||
| 1041 | { | ||||
| 1042 | switch ( la->lineStartStyle() ) { | ||||
| 1043 | case Okular::LineAnnotation::Square: | ||||
| 1044 | drawLineEndSquare( 0, -size, transform, image ); | ||||
| 1045 | break; | ||||
| 1046 | case Okular::LineAnnotation::Circle: | ||||
| 1047 | drawLineEndCircle( 0, -size, transform, image ); | ||||
| 1048 | break; | ||||
| 1049 | case Okular::LineAnnotation::Diamond: | ||||
| 1050 | drawLineEndDiamond( 0, -size, transform, image ); | ||||
| 1051 | break; | ||||
| 1052 | case Okular::LineAnnotation::OpenArrow: | ||||
| 1053 | drawLineEndArrow( 0, -size, 1., false, transform, image ); | ||||
| 1054 | break; | ||||
| 1055 | case Okular::LineAnnotation::ClosedArrow: | ||||
| 1056 | drawLineEndArrow( 0, -size, 1., true, transform, image ); | ||||
| 1057 | break; | ||||
| 1058 | case Okular::LineAnnotation::None: | ||||
| 1059 | break; | ||||
| 1060 | case Okular::LineAnnotation::Butt: | ||||
| 1061 | drawLineEndButt( 0, size, transform, image ); | ||||
| 1062 | break; | ||||
| 1063 | case Okular::LineAnnotation::ROpenArrow: | ||||
| 1064 | drawLineEndArrow( 0, size, 1., false, transform, image ); | ||||
| 1065 | break; | ||||
| 1066 | case Okular::LineAnnotation::RClosedArrow: | ||||
| 1067 | drawLineEndArrow( 0, size, 1., true, transform, image ); | ||||
| 1068 | break; | ||||
| 1069 | case Okular::LineAnnotation::Slash: | ||||
| 1070 | drawLineEndSlash( 0, -size, transform, image ); | ||||
| 1071 | break; | ||||
| 1072 | } | ||||
| 1073 | switch ( la->lineEndStyle() ) { | ||||
| 1074 | case Okular::LineAnnotation::Square: | ||||
| 1075 | drawLineEndSquare( mainSegmentLength, size, transform, image ); | ||||
| 1076 | break; | ||||
| 1077 | case Okular::LineAnnotation::Circle: | ||||
| 1078 | drawLineEndCircle( mainSegmentLength, size, transform, image ); | ||||
| 1079 | break; | ||||
| 1080 | case Okular::LineAnnotation::Diamond: | ||||
| 1081 | drawLineEndDiamond( mainSegmentLength, size, transform, image ); | ||||
| 1082 | break; | ||||
| 1083 | case Okular::LineAnnotation::OpenArrow: | ||||
| 1084 | drawLineEndArrow( mainSegmentLength, size, 1., false, transform, image ); | ||||
| 1085 | break; | ||||
| 1086 | case Okular::LineAnnotation::ClosedArrow: | ||||
| 1087 | drawLineEndArrow( mainSegmentLength, size, 1., true, transform, image ); | ||||
| 1088 | break; | ||||
| 1089 | case Okular::LineAnnotation::None: | ||||
| 1090 | break; | ||||
| 1091 | case Okular::LineAnnotation::Butt: | ||||
| 1092 | drawLineEndButt( mainSegmentLength, size, transform, image ); | ||||
| 1093 | break; | ||||
| 1094 | case Okular::LineAnnotation::ROpenArrow: | ||||
| 1095 | drawLineEndArrow( mainSegmentLength, size, -1., false, transform, image ); | ||||
| 1096 | break; | ||||
| 1097 | case Okular::LineAnnotation::RClosedArrow: | ||||
| 1098 | drawLineEndArrow( mainSegmentLength, size, -1., true, transform, image ); | ||||
| 1099 | break; | ||||
| 1100 | case Okular::LineAnnotation::Slash: | ||||
| 1101 | drawLineEndSlash( mainSegmentLength, size, transform, image ); | ||||
| 1102 | break; | ||||
| 1103 | } | ||||
| 1104 | } | ||||
| 1105 | | ||||
| 1106 | void LineAnnotPainter::drawLineEndArrow( double xEndPos, double size, double flipX, bool close, const QTransform& toNormalizedPage, QImage &image ) const | ||||
| 1107 | { | ||||
| 1108 | const QTransform combinedTransform { toNormalizedPage * toNormalizedImage }; | ||||
| 1109 | const QList<Okular::NormalizedPoint> path { | ||||
| 1110 | { xEndPos - size * flipX, size / 2. }, | ||||
| 1111 | { xEndPos, 0 }, | ||||
| 1112 | { xEndPos - size * flipX, -size / 2. }, | ||||
| 1113 | }; | ||||
| 1114 | PagePainter::drawShapeOnImage( image, transformPath(path, combinedTransform), | ||||
| 1115 | close, linePen, fillBrush, pageScale, PagePainter::Multiply); | ||||
| 1116 | } | ||||
| 1117 | | ||||
| 1118 | void LineAnnotPainter::drawLineEndButt( double xEndPos, double size, const QTransform& toNormalizedPage, QImage &image ) const | ||||
| 1119 | { | ||||
| 1120 | const QTransform combinedTransform { toNormalizedPage * toNormalizedImage }; | ||||
| 1121 | const double halfSize { size / 2. }; | ||||
| 1122 | const QList<Okular::NormalizedPoint> path { | ||||
| 1123 | { xEndPos, halfSize }, | ||||
| 1124 | { xEndPos, -halfSize }, | ||||
| 1125 | }; | ||||
| 1126 | PagePainter::drawShapeOnImage( image, transformPath(path, combinedTransform), | ||||
| 1127 | true, linePen, fillBrush, pageScale, PagePainter::Multiply); | ||||
| 1128 | } | ||||
| 1129 | | ||||
| 1130 | void LineAnnotPainter::drawLineEndCircle( double xEndPos, double size, const QTransform& toNormalizedPage, QImage &image ) const | ||||
| 1131 | { | ||||
| 1132 | /* transform the circle midpoint to intermediate normalized coordinates | ||||
| 1133 | * where it's easy to construct the bounding rect of the circle */ | ||||
| 1134 | Okular::NormalizedPoint center; | ||||
| 1135 | toNormalizedPage.map( xEndPos - size / 2., 0, ¢er.x, ¢er.y ); | ||||
| 1136 | const double halfSize { size / 2. }; | ||||
| 1137 | const QList<Okular::NormalizedPoint> path { | ||||
| 1138 | { center.x - halfSize, center.y - halfSize / aspectRatio }, | ||||
| 1139 | { center.x + halfSize, center.y + halfSize / aspectRatio }, | ||||
| 1140 | }; | ||||
| 1141 | | ||||
| 1142 | /* then transform bounding rect with toNormalizedImage */ | ||||
| 1143 | PagePainter::drawEllipseOnImage( | ||||
| 1144 | image, | ||||
| 1145 | transformPath(path, toNormalizedImage), | ||||
| 1146 | linePen, | ||||
| 1147 | fillBrush, | ||||
| 1148 | pageScale, | ||||
| 1149 | PagePainter::Multiply); | ||||
| 1150 | } | ||||
| 1151 | | ||||
| 1152 | void LineAnnotPainter::drawLineEndSquare( double xEndPos, double size, const QTransform& toNormalizedPage, QImage &image ) const | ||||
| 1153 | { | ||||
| 1154 | const QTransform combinedTransform { toNormalizedPage * toNormalizedImage }; | ||||
| 1155 | const QList<Okular::NormalizedPoint> path { | ||||
| 1156 | { xEndPos, size / 2. }, | ||||
| 1157 | { xEndPos - size, size / 2. }, | ||||
| 1158 | { xEndPos - size, -size / 2. }, | ||||
| 1159 | { xEndPos, -size / 2. } | ||||
| 1160 | }; | ||||
| 1161 | PagePainter::drawShapeOnImage( image, transformPath(path, combinedTransform), | ||||
| 1162 | true, linePen, fillBrush, pageScale, PagePainter::Multiply); | ||||
| 1163 | } | ||||
| 1164 | | ||||
| 1165 | void LineAnnotPainter::drawLineEndDiamond( double xEndPos, double size, const QTransform& toNormalizedPage, QImage &image ) const | ||||
| 1166 | { | ||||
| 1167 | const QTransform combinedTransform { toNormalizedPage * toNormalizedImage }; | ||||
| 1168 | const QList<Okular::NormalizedPoint> path { | ||||
| 1169 | { xEndPos, 0 }, | ||||
| 1170 | { xEndPos - size / 2., size / 2. }, | ||||
| 1171 | { xEndPos - size, 0 }, | ||||
| 1172 | { xEndPos - size / 2., -size / 2. } | ||||
| 1173 | }; | ||||
| 1174 | PagePainter::drawShapeOnImage( image, transformPath(path, combinedTransform), | ||||
| 1175 | true, linePen, fillBrush, pageScale, PagePainter::Multiply); | ||||
| 1176 | } | ||||
| 1177 | | ||||
| 1178 | void LineAnnotPainter::drawLineEndSlash( double xEndPos, double size, const QTransform& toNormalizedPage, QImage &image ) const | ||||
| 1179 | { | ||||
| 1180 | const QTransform combinedTransform { toNormalizedPage * toNormalizedImage }; | ||||
| 1181 | const double halfSize { size / 2. }; | ||||
| 1182 | const double xOffset { cos(M_PI/3.) * halfSize }; | ||||
| 1183 | const QList<Okular::NormalizedPoint> path { | ||||
| 1184 | { xEndPos - xOffset, halfSize }, | ||||
| 1185 | { xEndPos + xOffset, -halfSize }, | ||||
| 1186 | }; | ||||
| 1187 | PagePainter::drawShapeOnImage( image, transformPath(path, combinedTransform), | ||||
| 1188 | true, linePen, fillBrush, pageScale, PagePainter::Multiply); | ||||
| 1189 | } | ||||
| 1190 | | ||||
| 1191 | void LineAnnotPainter::drawLeaderLine( double xEndPos, QImage &image, const QTransform& toNormalizedPage ) const | ||||
| 1192 | { | ||||
| 1193 | const QTransform combinedTransform = toNormalizedPage * toNormalizedImage; | ||||
| 1194 | const double ll = aspectRatio * la->lineLeadingForwardPoint() / pageSize.height(); | ||||
| 1195 | const double lle = aspectRatio * la->lineLeadingBackwardPoint() / pageSize.height(); | ||||
| 1196 | const int sign { ll > 0 ? -1 : 1 }; | ||||
| 1197 | QList<Okular::NormalizedPoint> path; | ||||
| 1198 | | ||||
| 1199 | if ( fabs( ll ) > 0 ) { | ||||
| 1200 | path.append( { xEndPos, ll } ); | ||||
| 1201 | // do we have the extension on the "back"? | ||||
| 1202 | if ( fabs( lle ) > 0 ) | ||||
| 1203 | { | ||||
| 1204 | path.append( { xEndPos, sign * lle } ); | ||||
| 1205 | } else { | ||||
| 1206 | path.append( { xEndPos, 0 } ); | ||||
| 1207 | } | ||||
| 1208 | } | ||||
| 1209 | PagePainter::drawShapeOnImage( image, transformPath(path, combinedTransform), false, | ||||
| 1210 | linePen, fillBrush, pageScale, PagePainter::Multiply); | ||||
| 1211 | } | ||||
| 1212 | | ||||
| 1213 | double LineAnnotPainter::shortenForArrow( double size, Okular::LineAnnotation::TermStyle endStyle ) | ||||
| 1214 | { | ||||
| 1215 | double shortenBy { 0 }; | ||||
| 1216 | | ||||
| 1217 | if ( endStyle == Okular::LineAnnotation::Square || | ||||
| 1218 | endStyle == Okular::LineAnnotation::Circle || | ||||
| 1219 | endStyle == Okular::LineAnnotation::Diamond || | ||||
| 1220 | endStyle == Okular::LineAnnotation::ClosedArrow ) | ||||
| 1221 | { | ||||
| 1222 | shortenBy = size; | ||||
| 1223 | } | ||||
| 1224 | | ||||
| 1225 | return shortenBy; | ||||
| 1226 | } | ||||
| 1227 | | ||||
| 1003 | /* kate: replace-tabs on; indent-width 4; */ | 1228 | /* kate: replace-tabs on; indent-width 4; */ | ||
| 1004 | 1229 | | |||