Fix font_metrics::width crashing on strings it doesn't understand

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@10386 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
John Spray 2005-08-03 07:47:54 +00:00
parent f5ad20538a
commit 7454536793
2 changed files with 14 additions and 3 deletions

View File

@ -1,3 +1,8 @@
2005-07-02 John Spray <spray@lyx.org>
* xftFontMetrics.C: Add error checking to call to mbstowcs
in font_metrics::width, estimate width for strings that
mbstowcs doesn't like.
2005-07-31 John Spray <spray_john@users.sf.net>
* GToc.C: unbreak viewing lists other than TOC by storing
integer index of entries in Type combobox.

View File

@ -27,6 +27,7 @@
#include "codeConvert.h"
#include "support/lstrings.h"
#include "debug.h"
#include <gtkmm.h>
@ -225,15 +226,20 @@ int width(wchar_t c,LyXFont const & f)
int width(char const * s, size_t n, LyXFont const & f)
{
boost::scoped_array<wchar_t> wcs(new wchar_t[n]);
size_t len;
int len; // Signed to handle error retvals
if (fontLoader.isSpecial(f)) {
unsigned char const * us =
reinterpret_cast<unsigned char const *>(s);
len = n;
std::copy(us, us + n, wcs.get());
} else
} else {
len = mbstowcs(wcs.get(), s, n);
return width(wcs.get(), len, f);
if (len < 0) {
lyxerr[Debug::FONT] << "Invalid multibyte encoding! '" << s << "'\n";
return n * width("0", 1, f);
}
}
return width(wcs.get(), static_cast<size_t>(len), f);
}