Commit ec67506c authored by Masamichi Hosoda's avatar Masamichi Hosoda Committed by Albert Astals Cid

cpp: Add document::create_destination_map()

Creates a map of all the named destinations in the document.
parent dbed0702
......@@ -3,6 +3,7 @@
* Copyright (C) 2016 Jakub Alba <jakubalba@gmail.com>
* Copyright (C) 2017, Albert Astals Cid <aacid@kde.org>
* Copyright (C) 2018, Adam Reichold <adam.reichold@t-online.de>
* Copyright (C) 2019, Masamichi Hosoda <trueroad@trueroad.jp>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -19,11 +20,13 @@
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "poppler-destination.h"
#include "poppler-document.h"
#include "poppler-embedded-file.h"
#include "poppler-page.h"
#include "poppler-toc.h"
#include "poppler-destination-private.h"
#include "poppler-document-private.h"
#include "poppler-embedded-file-private.h"
#include "poppler-page-private.h"
......@@ -34,6 +37,7 @@
#include "DateInfo.h"
#include "ErrorCodes.h"
#include "GlobalParams.h"
#include "Link.h"
#include "Outline.h"
#include <algorithm>
......@@ -1022,6 +1026,58 @@ std::vector<embedded_file *> document::embedded_files() const
return d->embedded_files;
}
/**
Creates a map of all the named destinations in the %document.
\note The destination names may contain \\0 and other binary values
so they are not printable and cannot convert to null-terminated C strings.
\returns the map of the each name and destination
\since 0.74
*/
std::map<std::string, destination> document::create_destination_map() const
{
std::map<std::string, destination> m;
Catalog *catalog = d->doc->getCatalog();
if (!catalog)
return m;
// Iterate from name-dict
const int nDests = catalog->numDests();
for (int i = 0; i < nDests; ++i ) {
std::string key(catalog->getDestsName (i));
LinkDest *link_dest = catalog->getDestsDest (i);
if (link_dest) {
destination dest(new destination_private(link_dest, d->doc));
m.emplace(std::move(key), std::move(dest));
delete link_dest;
}
}
// Iterate from name-tree
const int nDestsNameTree = catalog->numDestNameTree();
for (int i = 0; i < nDestsNameTree; ++i ) {
std::string key(catalog->getDestNameTreeName (i)->c_str (),
catalog->getDestNameTreeName (i)->getLength ());
LinkDest *link_dest = catalog->getDestNameTreeDest (i);
if (link_dest) {
destination dest(new destination_private(link_dest, d->doc));
m.emplace(std::move(key), std::move(dest));
delete link_dest;
}
}
return m;
}
/**
Saves the %document to file \p file_name.
......
/*
* Copyright (C) 2009-2010, Pino Toscano <pino@kde.org>
* Copyright (C) 2016 Jakub Alba <jakubalba@gmail.com>
* Copyright (C) 2019, Masamichi Hosoda <trueroad@trueroad.jp>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -23,9 +24,12 @@
#include "poppler-global.h"
#include "poppler-font.h"
#include <map>
namespace poppler
{
class destination;
class document_private;
class embedded_file;
class page;
......@@ -106,6 +110,10 @@ public:
bool has_embedded_files() const;
std::vector<embedded_file *> embedded_files() const;
// Named destinations are bytestrings, not string.
// So we use std::string instead of ustring.
std::map<std::string, destination> create_destination_map() const;
bool save(const std::string &filename) const;
bool save_a_copy(const std::string &filename) const;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment