@@ -181,24 +181,19 @@ namespace zim
181181 }
182182
183183 Item Archive::getIllustrationItem (unsigned int size) const {
184- auto r = m_impl->findx (' M' , Formatter () << " Illustration_" << size << " x"
185- << size << " @" << 1 );
184+ // XXX: A square illustration of the requested size may exist with
185+ // XXX: non-empty attributes or at a scale different from 1. Shouldn't
186+ // XXX: we test for it too, if the {size}x{size}@1 one is not available?
187+ return getIllustrationItem (IllustrationInfo{size, size, 1.0 , {}});
188+ }
189+
190+ Item Archive::getIllustrationItem (const IllustrationInfo& ii) const {
191+ auto r = m_impl->findx (' M' , ii.asMetadataItemName ());
186192 if (r.first ) {
187193 return getEntryByPath (entry_index_type (r.second )).getItem ();
188194 }
189- // We haven't found the exact entry. Let's "search" for a illustration and
190- // use the first one we found.
191- #if 0
192- // We have decided to not implement fallback in case of wrong resolution for now.
193- // We keep this code for reference.
194- r = m_impl->findx('M', "Illustration");
195- auto entry = getEntryByPath(entry_index_type(r.second));
196- if (entry.getPath().find("Illustration") == 0) {
197- return entry.getItem();
198- }
199- #endif
200195 // For 48x48 illustration, return favicon for older zims.
201- if (size == 48 ) {
196+ if ( ii == IllustrationInfo{ 48 , 48 , 1.0 , {}} ) {
202197 auto r = findFavicon (*m_impl);
203198 return getEntryByPath (entry_index_type (r.second )).getItem (true );
204199 }
@@ -233,6 +228,45 @@ namespace zim
233228 return ret;
234229 }
235230
231+ Archive::IllustrationInfos Archive::getIllustrationInfos () const {
232+ IllustrationInfos r;
233+ for (auto e = m_impl->findx (' M' , " Illustration_" ).second ; ; ++e ) {
234+ try {
235+ const auto path = getEntryByPath (entry_index_type (e)).getPath ();
236+ if (path.find (" Illustration_" ) != 0 ) {
237+ break ;
238+ }
239+ try {
240+ r.push_back (zim::IllustrationInfo::fromMetadataItemName (path));
241+ } catch (...) {}
242+ } catch (const std::out_of_range& e) {
243+ break ;
244+ }
245+ }
246+ const IllustrationInfo faviconLikeIllustration{48 , 48 , 1.0 , {}};
247+ if (std::find (r.begin (), r.end (), faviconLikeIllustration) == r.end ()) {
248+ try {
249+ // raise a exception if we cannot find the (old format) favicon.
250+ findFavicon (*m_impl);
251+ r.push_back (faviconLikeIllustration);
252+ } catch (EntryNotFound&) {}
253+ }
254+ return r;
255+ }
256+
257+ Archive::IllustrationInfos Archive::getIllustrationInfos (uint32_t w,
258+ uint32_t h,
259+ float minScale) const
260+ {
261+ IllustrationInfos r;
262+ for ( const auto & ii : getIllustrationInfos () ) {
263+ if ( ii.width == w && ii.height == h && ii.scale >= minScale ) {
264+ r.push_back (ii);
265+ }
266+ }
267+ return r;
268+ }
269+
236270 bool Archive::hasIllustration (unsigned int size) const {
237271 try {
238272 getIllustrationItem (size);
0 commit comments