void Font::renderText(const string& text, float x, float y, float width, float height) throw(runtime_error) { renderText(UTF8_to_UTF16(text), x, y, width, height); }
FileStream::FileStream(const std::string& path, const uint32 mode, const int do_lock) : OpenedMode(mode), mapping(NULL), mapping_size(0), locked(false), prev_was_write(-1) { const char* fpom; int open_flags; path_save = path; switch(mode) { default: throw MDFN_Error(0, _("Unknown FileStream mode.")); case MODE_READ: fpom = "rb"; open_flags = O_RDONLY; break; case MODE_READ_WRITE: fpom = "r+b"; open_flags = O_RDWR | O_CREAT; break; case MODE_WRITE: // Truncation is handled near the end of the constructor. case MODE_WRITE_INPLACE: fpom = "wb"; open_flags = O_WRONLY | O_CREAT; break; case MODE_WRITE_SAFE: fpom = "wb"; open_flags = O_WRONLY | O_CREAT | O_EXCL; break; } #ifdef O_BINARY open_flags |= O_BINARY; #elif defined(_O_BINARY) open_flags |= _O_BINARY; #endif #ifdef WIN32 auto perm_mode = _S_IREAD | _S_IWRITE; #else auto perm_mode = S_IRUSR | S_IWUSR; #endif #if defined(S_IRGRP) perm_mode |= S_IRGRP; #endif #if defined(S_IROTH) perm_mode |= S_IROTH; #endif if(path.find('\0') != std::string::npos) throw MDFN_Error(EINVAL, _("Error opening file \"%s\": %s"), path_save.c_str(), _("Null character in path.")); int tmpfd; #ifdef WIN32 { bool invalid_utf8; std::u16string u16path = UTF8_to_UTF16(path, &invalid_utf8, true); if(invalid_utf8) throw MDFN_Error(EINVAL, _("Error opening file \"%s\": %s"), path_save.c_str(), _("Invalid UTF-8 in path.")); tmpfd = ::_wopen((const wchar_t*)u16path.c_str(), open_flags, perm_mode); } #else tmpfd = ::open(path.c_str(), open_flags, perm_mode); #endif if(tmpfd == -1) { ErrnoHolder ene(errno); throw MDFN_Error(ene.Errno(), _("Error opening file \"%s\": %s"), path_save.c_str(), ene.StrError()); } fp = ::fdopen(tmpfd, fpom); if(!fp) { ErrnoHolder ene(errno); ::close(tmpfd); throw MDFN_Error(ene.Errno(), _("Error opening file \"%s\": %s"), path_save.c_str(), ene.StrError()); } // if(do_lock) // Lock before truncation { try { lock(do_lock < 0); } catch(...) { try { close(); } catch(...) { } throw; } } if(mode == MODE_WRITE) { try { truncate(0); } catch(...) { try { close(); } catch(...) { } throw; } } }
Font::FONT_RECT Font::measureText(const string& text) throw(runtime_error) { return measureText(UTF8_to_UTF16(text)); }
wstring UTF8_to_UTF16(const string& utf8) { return UTF8_to_UTF16(utf8.c_str(), utf8.length()); }