mirror of https://github.com/kiwix/libkiwix.git
Add a method to get the a book illustration for a specific size.
This commit is contained in:
parent
66c40817ee
commit
9482bfb95b
|
@ -100,6 +100,7 @@ class Book
|
|||
const std::string& getFaviconMimeType() const;
|
||||
|
||||
Illustrations getIllustrations() const;
|
||||
std::shared_ptr<const Illustration> getIllustration(unsigned int size) const;
|
||||
|
||||
const std::string& getDownloadId() const { return m_downloadId; }
|
||||
|
||||
|
|
15
src/book.cpp
15
src/book.cpp
|
@ -217,14 +217,23 @@ void Book::setPath(const std::string& path)
|
|||
|
||||
const Book::Illustration Book::missingDefaultIllustration;
|
||||
|
||||
const Book::Illustration& Book::getDefaultIllustration() const
|
||||
std::shared_ptr<const Book::Illustration> Book::getIllustration(unsigned int size) const
|
||||
{
|
||||
for ( const auto& ilPtr : m_illustrations ) {
|
||||
if (ilPtr->width == 48 && ilPtr->height == 48) {
|
||||
return *ilPtr;
|
||||
if (ilPtr->width == size && ilPtr->height == size) {
|
||||
return ilPtr;
|
||||
}
|
||||
}
|
||||
throw std::runtime_error("Cannot find illustration");
|
||||
}
|
||||
|
||||
const Book::Illustration& Book::getDefaultIllustration() const
|
||||
{
|
||||
try {
|
||||
return *getIllustration(48);
|
||||
} catch (...) {
|
||||
return missingDefaultIllustration;
|
||||
}
|
||||
}
|
||||
|
||||
const std::string& Book::Illustration::getData() const
|
||||
|
|
Loading…
Reference in New Issue