loolwsd: add parameter char to render font

This commit is contained in:
Henry Castro 2016-11-11 13:24:13 -04:00
parent b7d3ea63ff
commit 4ea95ff330
4 changed files with 17 additions and 10 deletions

View file

@ -356,15 +356,17 @@ bool ChildSession::loadDocument(const char * /*buffer*/, int /*length*/, StringT
bool ChildSession::sendFontRendering(const char* /*buffer*/, int /*length*/, StringTokenizer& tokens)
{
std::string font, decodedFont;
std::string font, text, decodedFont;
if (tokens.count() < 2 ||
if (tokens.count() < 3 ||
!getTokenString(tokens[1], "font", font))
{
sendTextFrame("error: cmd=renderfont kind=syntax");
return false;
}
getTokenString(tokens[2], "char", text);
URI::decode(font, decodedFont);
std::string response = "renderfont: " + Poco::cat(std::string(" "), tokens.begin() + 1, tokens.end()) + "\n";
@ -381,7 +383,7 @@ bool ChildSession::sendFontRendering(const char* /*buffer*/, int /*length*/, Str
_loKitDocument->setView(_viewId);
ptrFont = _loKitDocument->renderFont(decodedFont.c_str(), &width, &height);
ptrFont = _loKitDocument->renderFont(decodedFont.c_str(), text.c_str(), &width, &height);
}
LOG_TRC("renderFont [" << font << "] rendered in " << (timestamp.elapsed()/1000.) << "ms");
@ -394,7 +396,7 @@ bool ChildSession::sendFontRendering(const char* /*buffer*/, int /*length*/, Str
}
std::free(ptrFont);
return sendBinaryFrame(output.data(), output.size());
return sendTextFrame(output.data(), output.size());
}
bool ChildSession::getStatus(const char* /*buffer*/, int /*length*/)

View file

@ -319,20 +319,22 @@ bool ClientSession::getPartPageRectangles(const char *buffer, int length,
bool ClientSession::sendFontRendering(const char *buffer, int length, StringTokenizer& tokens,
const std::shared_ptr<DocumentBroker>& docBroker)
{
std::string font;
std::string font, text, encodedChar;
if (tokens.count() < 2 ||
!getTokenString(tokens[1], "font", font))
{
return sendTextFrame("error: cmd=renderfont kind=syntax");
}
getTokenString(tokens[2], "char", text);
Poco::URI::encode(text, "", encodedChar);
const std::string response = "renderfont: " + Poco::cat(std::string(" "), tokens.begin() + 1, tokens.end()) + "\n";
std::vector<char> output;
output.resize(response.size());
std::memcpy(output.data(), response.data(), response.size());
std::unique_ptr<std::fstream> cachedRendering = docBroker->tileCache().lookupCachedFile(font, "font");
std::unique_ptr<std::fstream> cachedRendering = docBroker->tileCache().lookupCachedFile(font+encodedChar, "font");
if (cachedRendering && cachedRendering->is_open())
{
cachedRendering->seekg(0, std::ios_base::end);

View file

@ -461,10 +461,11 @@ public:
* @param pFontName the font to be painted
*/
inline unsigned char* renderFont(const char *pFontName,
const char *pChar,
int *pFontWidth,
int *pFontHeight)
{
return _pDoc->pClass->renderFont(_pDoc, pFontName, pFontWidth, pFontHeight);
return _pDoc->pClass->renderFont(_pDoc, pFontName, pChar, pFontWidth, pFontHeight);
}
/**

View file

@ -231,16 +231,18 @@ bool PrisonerSession::_handleInput(const char *buffer, int length)
}
else if (tokens[0] == "renderfont:")
{
std::string font;
if (tokens.count() < 2 ||
std::string font, text, encodedChar;
if (tokens.count() < 3 ||
!getTokenString(tokens[1], "font", font))
{
LOG_ERR("Bad syntax for: " << firstLine);
return false;
}
getTokenString(tokens[2], "char", text);
Poco::URI::encode(text, "", encodedChar);
assert(firstLine.size() < static_cast<std::string::size_type>(length));
_docBroker->tileCache().saveRendering(font, "font", buffer + firstLine.size() + 1, length - firstLine.size() - 1);
_docBroker->tileCache().saveRendering(font+encodedChar, "font", buffer + firstLine.size() + 1, length - firstLine.size() - 1);
}
}
else