| 281 | } |
| 282 | |
| 283 | Document::OpenResult TextDocumentGenerator::loadDocumentWithPassword(const QString &fileName, QList<Okular::Page *> &pagesVector, const QString &password) |
| 284 | { |
| 285 | Q_D(TextDocumentGenerator); |
| 286 | const Document::OpenResult openResult = d->mConverter->convertWithPassword(fileName, password); |
| 287 | |
| 288 | if (openResult != Document::OpenSuccess) { |
| 289 | d->mDocument = nullptr; |
| 290 | |
| 291 | // loading failed, cleanup all the stuff eventually gathered from the converter |
| 292 | d->mTitlePositions.clear(); |
| 293 | for (const TextDocumentGeneratorPrivate::LinkPosition &linkPos : std::as_const(d->mLinkPositions)) { |
| 294 | delete linkPos.link; |
| 295 | } |
| 296 | d->mLinkPositions.clear(); |
| 297 | for (const TextDocumentGeneratorPrivate::AnnotationPosition &annPos : std::as_const(d->mAnnotationPositions)) { |
| 298 | delete annPos.annotation; |
| 299 | } |
| 300 | d->mAnnotationPositions.clear(); |
| 301 | |
| 302 | return openResult; |
| 303 | } |
| 304 | d->mDocument = d->mConverter->document(); |
| 305 | if (d->mDocument) { |
| 306 | d->mDocument->setDefaultFont(d->mFont); |
| 307 | } |
| 308 | d->generateTitleInfos(); |
| 309 | const QList<TextDocumentGeneratorPrivate::LinkInfo> linkInfos = d->generateLinkInfos(); |
| 310 | const QList<TextDocumentGeneratorPrivate::AnnotationInfo> annotationInfos = d->generateAnnotationInfos(); |
| 311 | |
| 312 | pagesVector.resize(d->mDocument->pageCount()); |
| 313 | |
| 314 | const QSize size = d->mDocument->pageSize().toSize(); |
| 315 | |
| 316 | QList<QList<Okular::ObjectRect *>> objects(d->mDocument->pageCount()); |
| 317 | for (const TextDocumentGeneratorPrivate::LinkInfo &info : linkInfos) { |
| 318 | // in case that the converter report bogus link info data, do not assert here |
| 319 | if (info.page < 0 || info.page >= objects.count()) { |
| 320 | continue; |
| 321 | } |
| 322 | |
| 323 | const QRectF rect = info.boundingRect; |
| 324 | if (info.ownsLink) { |
| 325 | objects[info.page].append(new Okular::ObjectRect(rect.left(), rect.top(), rect.right(), rect.bottom(), false, Okular::ObjectRect::Action, info.link)); |
| 326 | } else { |
| 327 | objects[info.page].append(new Okular::NonOwningObjectRect(rect.left(), rect.top(), rect.right(), rect.bottom(), false, Okular::ObjectRect::Action, info.link)); |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | QList<QList<Okular::Annotation *>> annots(d->mDocument->pageCount()); |
| 332 | for (const TextDocumentGeneratorPrivate::AnnotationInfo &info : annotationInfos) { |
| 333 | annots[info.page].append(info.annotation); |
| 334 | } |
| 335 | |
| 336 | for (int i = 0; i < d->mDocument->pageCount(); ++i) { |
| 337 | Okular::Page *page = new Okular::Page(i, size.width(), size.height(), Okular::Rotation0); |
| 338 | pagesVector[i] = page; |
| 339 | |
| 340 | if (!objects.at(i).isEmpty()) { |
nothing calls this directly
no test coverage detected