public:
///
Impl(PreviewImage & p, PreviewLoader & l,
- string const & s, FileName const & f, double af);
+ docstring const & s, FileName const & f, double af);
///
~Impl();
///
///
Loader iloader_;
///
- string const snippet_;
+ docstring const snippet_;
///
double const ascent_frac_;
};
PreviewImage::PreviewImage(PreviewLoader & l,
- string const & s,
+ docstring const & s,
FileName const & f,
double af)
: pimpl_(new Impl(*this, l, s, f, af))
}
-string const & PreviewImage::snippet() const
+docstring const & PreviewImage::snippet() const
{
return pimpl_->snippet_;
}
}
-PreviewImage::Impl::Impl(PreviewImage & p, PreviewLoader & l, string const & s,
+PreviewImage::Impl::Impl(PreviewImage & p, PreviewLoader & l, docstring const & s,
FileName const & bf, double af)
: parent_(p), ploader_(l), iloader_(l.buffer().fileName(), bf),
snippet_(s), ascent_frac_(af)
#include <QTimer>
using namespace std;
+using namespace lyx;
using namespace lyx::support;
namespace {
-typedef pair<string, FileName> SnippetPair;
+typedef pair<docstring, FileName> SnippetPair;
// A list of all snippets to be converted to previews
-typedef list<string> PendingSnippets;
+typedef list<docstring> PendingSnippets;
// Each item in the vector is a pair<snippet, image file name>.
typedef vector<SnippetPair> BitmapFile;
}
-std::function <bool (SnippetPair const &)> FindFirst(string const & comp)
+std::function <bool (SnippetPair const &)> FindFirst(docstring const & comp)
{
return [&comp](SnippetPair const & sp) { return sp.first == comp; };
}
/// Stop any InProgress items still executing.
~Impl();
///
- PreviewImage const * preview(string const & latex_snippet) const;
+ PreviewImage const * preview(docstring const & latex_snippet) const;
///
- PreviewLoader::Status status(string const & latex_snippet) const;
+ PreviewLoader::Status status(docstring const & latex_snippet) const;
///
- void add(string const & latex_snippet);
+ void add(docstring const & latex_snippet);
///
- void remove(string const & latex_snippet);
+ void remove(docstring const & latex_snippet);
/// \p wait whether to wait for the process to complete or, instead,
/// to do it in the background.
void startLoading(bool wait = false);
*/
typedef std::shared_ptr<PreviewImage> PreviewImagePtr;
///
- typedef map<string, PreviewImagePtr> Cache;
+ typedef map<docstring, PreviewImagePtr> Cache;
///
Cache cache_;
{}
-PreviewImage const * PreviewLoader::preview(string const & latex_snippet) const
+PreviewImage const * PreviewLoader::preview(docstring const & latex_snippet) const
{
return pimpl_->preview(latex_snippet);
}
-PreviewLoader::Status PreviewLoader::status(string const & latex_snippet) const
+PreviewLoader::Status PreviewLoader::status(docstring const & latex_snippet) const
{
return pimpl_->status(latex_snippet);
}
-void PreviewLoader::add(string const & latex_snippet) const
+void PreviewLoader::add(docstring const & latex_snippet) const
{
pimpl_->add(latex_snippet);
}
-void PreviewLoader::remove(string const & latex_snippet) const
+void PreviewLoader::remove(docstring const & latex_snippet) const
{
pimpl_->remove(latex_snippet);
}
: to_format_(to_format), base_(filename_base), counter_(1)
{}
- SnippetPair const operator()(string const & snippet)
+ SnippetPair const operator()(docstring const & snippet)
{
ostringstream os;
os << base_ << counter_++ << '.' << to_format_;
PreviewImage const *
-PreviewLoader::Impl::preview(string const & latex_snippet) const
+PreviewLoader::Impl::preview(docstring const & latex_snippet) const
{
int fs = int(buffer_.fontScalingFactor());
int fg = 0x0;
namespace {
-std::function<bool (InProgressProcess const &)> FindSnippet(string const & s)
+std::function<bool (InProgressProcess const &)> FindSnippet(docstring const & s)
{
return [&s](InProgressProcess const & process) {
BitmapFile const & snippets = process.second.snippets;
} // namespace
PreviewLoader::Status
-PreviewLoader::Impl::status(string const & latex_snippet) const
+PreviewLoader::Impl::status(docstring const & latex_snippet) const
{
Cache::const_iterator cit = cache_.find(latex_snippet);
if (cit != cache_.end())
}
-void PreviewLoader::Impl::add(string const & latex_snippet)
+void PreviewLoader::Impl::add(docstring const & latex_snippet)
{
if (!pconverter_ || status(latex_snippet) != NotFound)
return;
- string const snippet = trim(latex_snippet);
+ docstring const snippet = trim(latex_snippet);
if (snippet.empty())
return;
namespace {
-std::function<void (InProgressProcess &)> EraseSnippet(string const & s)
+std::function<void (InProgressProcess &)> EraseSnippet(docstring const & s)
{
return [&s](InProgressProcess & process) {
BitmapFile & snippets = process.second.snippets;
} // namespace
-void PreviewLoader::Impl::remove(string const & latex_snippet)
+void PreviewLoader::Impl::remove(docstring const & latex_snippet)
{
Cache::iterator cit = cache_.find(latex_snippet);
if (cit != cache_.end())
size_t metrics_counter = 0;
for (; it != end; ++it, ++metrics_counter) {
- string const & snip = it->first;
+ docstring const & snip = it->first;
FileName const & file = it->second;
double af = ascent_fractions[metrics_counter];
// FIXME: the preview loader should be able
// to handle multiple encodings
// or we should generally use utf8
- for (char_type n : from_utf8(it->first)) {
+ for (char_type n : it->first) {
if (!enc.encodable(n)) {
LYXERR0("Uncodable character '"
<< docstring(1, n)
<< "' in preview snippet!");
uncodable_content = true;
+ break;
}
}
- // FIXME UNICODE
os << "\\begin{preview}\n";
// do not show incomplete preview
if (!uncodable_content)
- os << from_utf8(it->first);
+ os << it->first;
os << "\n\\end{preview}\n\n";
}
}
#define PREVIEWLOADER_H
#include "ColorCode.h"
+#include "support/docstring.h"
#include "support/signals.h"
#include <QObject>
/** Is there an image already associated with this snippet of LaTeX?
* If so, returns a pointer to it, else returns 0.
*/
- PreviewImage const * preview(std::string const & latex_snippet) const;
+ PreviewImage const * preview(docstring const & latex_snippet) const;
///
enum Status {
};
/// How far have we got in loading the image?
- Status status(std::string const & latex_snippet) const;
+ Status status(docstring const & latex_snippet) const;
/// Add a snippet of LaTeX to the queue for processing.
- void add(std::string const & latex_snippet) const;
+ void add(docstring const & latex_snippet) const;
/// Remove this snippet of LaTeX from the PreviewLoader.
- void remove(std::string const & latex_snippet) const;
+ void remove(docstring const & latex_snippet) const;
/** We have accumulated several latex snippets with status "InQueue".
* Initiate their transformation into bitmap images.
// Also, the image must be generated before the DocBook output is finished,
// unlike a preview that is not immediately required for display.
docstring const latex_snippet = insetToLaTeXSnippet(&buffer(), this);
- std::string const snippet = support::trim(to_utf8(latex_snippet));
+ docstring const snippet = support::trim(latex_snippet);
// TODO: no real support for Unicode. This code is very similar to RenderPreview::addPreview, the same gotcha applies.
graphics::PreviewLoader* loader = buffer().loader();
// same hash (by design of cryptographic hash functions). Computing a hash
// is typically slow, but extremely fast compared to compilation of the
// preview and image rendering.
- std::string newFileName = "lyx_" + sanitizeFileName(toHexHash(snippet)) + "." + filename.extension();
+ std::string newFileName = "lyx_" + sanitizeFileName(toHexHash(to_utf8(snippet))) + "." + filename.extension();
// Copy the image into the right folder.
rp.exportdata->addExternalFile("docbook5", filename, newFileName);