lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[lmi] Failing more gracefully with missing PNG files


From: Greg Chicares
Subject: [lmi] Failing more gracefully with missing PNG files
Date: Tue, 15 Sep 2015 22:56:57 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.3.0

Anyone should be able to use lmi just by building from the public repository.
Right now, that doesn't work very well for group premium quotes if they don't
have the two PNG files used for creating PDF output. In that case, I'd rather
issue a diagnostic from lmi (not from wx: from lmi, so that I can control and
customize it easily) and proceed using empty images.

icon_monger::CreateBitmap() seems to do something suitable already, and it has
another desirable feature--it looks for PNG files in lmi's data directory--so
I tried to reuse that code. But in 'group_quote_pdf_gen_wx.cpp', if I 
reimplement
the following function this way:

  wxImage load_image(char const* file)
  {
      return wxArtProvider::GetBitmap(file).ConvertToImage();
  }

(and drop the ".png" extension from the two hardcoded PNG names), then I get
this messagebox (three times):

  Error
  Assertion '"hbmp"' failed
  (wxDIB::Create(): invalid bitmap).
  [file ../src/msw/dib.cpp, line 139]

whether or not those two PNG files are present. If they are present, then I
get these additional diagnostics first [they reflect the renaming
  background.png --> group_quote_banner.png
  logo.png       --> company_logo.png
that I'm about to commit separately]:

  Warning
  Image 'C:/opt/lmi/data/group_quote_banner.png' of size 1056 by 105 has been 
scaled because no bitmap of requested size -1 by -1 was found.
  [file /lmi/src/lmi/icon_monger.cpp, line 246]

  Error
  Assertion '"(width > 0) && (height > 0)"' failed
  (invalid new image size).
  [file ../src/common/image.cpp, line 433]

I can see that this is caused by code in class icon_monger, which assumes a
size of (-1, -1) in this case, but I don't even know what class wxArtClient
*is*, so I figured I'd better ask for help instead of trying to figure this
out myself. I'm not sure class icon_monger is the right tool for this job;
maybe I should really factor out the part of icon_monger::CreateBitmap()
that tests for file existence (in two places) and loads the PNG image if
a valid one is found, otherwise returning wxNullBitmap. This seems to work:

#include "data_directory.hpp"           // AddDataDir()
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/path.hpp>
...
wxImage load_image(char const* file)
{
    fs::path image_path(file);
    if(!fs::exists(image_path))
        {
        image_path = AddDataDir(file);
        }
    if(!fs::exists(image_path))
        {
        warning()
            << "Unable to find image '"
            << image_path.string()
            << "'. Try reinstalling."
            << "\nA blank image will be used instead."
            << LMI_FLUSH
            ;
        return wxImage();
        }
    wxImage image(image_path.string());
    if(!image.IsOk())
        {
        warning()
            << "Unable to load image '"
            << image_path.string()
            << "'. Try reinstalling."
            << "\nA blank image will be used instead."
            << LMI_FLUSH
            ;
        return wxImage();
        }

    return image;
}

though the code duplication is regrettable; should I just put aside my
regrets and commit that, or is there a better way?



reply via email to

[Prev in Thread] Current Thread [Next in Thread]