mirror of
https://github.com/kiwix/libkiwix.git
synced 2025-06-26 10:11:30 +00:00
Add a method to get the a book illustration for a specific size.
This commit is contained in:
@ -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; }
|
||||
|
||||
|
17
src/book.cpp
17
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;
|
||||
}
|
||||
}
|
||||
return missingDefaultIllustration;
|
||||
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
|
||||
|
Reference in New Issue
Block a user