kit/ChildSession.cpp                          |   17 ++++++++--
 loleaflet/dist/images/loading.gif             |binary
 loleaflet/src/control/Control.CharacterMap.js |   41 ++++++++++++++++++--------
 loleaflet/src/core/Socket.js                  |    5 ++-
 loleaflet/src/layer/tile/TileLayer.js         |    1 
 wsd/ClientSession.cpp                         |    5 +--
 wsd/PrisonerSession.cpp                       |    7 ++--
 wsd/protocol.txt                              |    3 +
 8 files changed, 56 insertions(+), 23 deletions(-)

New commits:
commit 6947e914e1d71ed8ec228f2a524faff383c006c0
Author: Henry Castro <[email protected]>
Date:   Sun Nov 27 22:47:36 2016 -0400

    loleaflet: re-work special character dialog to render all glyphs
    
    .. on server side

diff --git a/loleaflet/dist/images/loading.gif 
b/loleaflet/dist/images/loading.gif
new file mode 100755
index 0000000..f8f3dff
Binary files /dev/null and b/loleaflet/dist/images/loading.gif differ
diff --git a/loleaflet/src/control/Control.CharacterMap.js 
b/loleaflet/src/control/Control.CharacterMap.js
index 550fff6..c17c443 100644
--- a/loleaflet/src/control/Control.CharacterMap.js
+++ b/loleaflet/src/control/Control.CharacterMap.js
@@ -274,22 +274,34 @@ L.Control.CharacterMap = L.Control.extend({
        ],
 
        cacheSubset: {},
+       cacheGlyph: {},
 
        fillCharacters: function (index) {
                var start = this.unicodeBlocks[index].start;
                var end = this.unicodeBlocks[index].end;
+               var encodedFont = 
window.encodeURIComponent(this._fontNames.options[this._fontNames.selectedIndex].value);
                var it = 0;
-               var tr, td;
+               var tr, td, img, encodedChar;
                L.DomUtil.empty(this._tbody);
                while (start <= end) {
                        if (it % 20 === 0) {
                                tr = L.DomUtil.create('tr', '', this._tbody);
                        }
                        td = L.DomUtil.create('td', '', tr);
-                       td.innerHTML = '&#x' + start.toString(16);
-                       td.data = start;
+                       encodedChar = 
window.encodeURIComponent(String.fromCharCode(start));
+                       if (this.cacheGlyph[encodedFont + encodedChar]) {
+                               img = this.cacheGlyph[encodedFont + 
encodedChar];
+                       } else {
+                               img = document.createElement('img');
+                               img.data = start;
+                               img.src = L.Icon.Default.imagePath + 
'/loading.gif';
+                               this.cacheGlyph[encodedFont + encodedChar] = 
img;
+                               this._map._socket.sendMessage('renderfont 
font=' + encodedFont + ' char=' + encodedChar);
+                               console.log('send=' + 
start.toString(16).toUpperCase() + ' encoded='  +encodedFont + encodedChar);
+                       }
                        L.DomEvent.on(td, 'click', this._onSymbolClick, this);
                        L.DomEvent.on(td, 'dblclick', this._onSymbolDblClick, 
this);
+                       td.appendChild(img);
                        start++;
                        it++;
                }
@@ -363,15 +375,12 @@ L.Control.CharacterMap = L.Control.extend({
                L.DomEvent.on(this._unicodeSubset, 'change', 
this._onUnicodeSubsetChange, this);
                content.appendChild(document.createElement('br'));
                content.appendChild(document.createElement('br'));
-               label = L.DomUtil.create('span', 'loleaflet-controls', content);
-               label.innerHTML = '<b>' + _('Special Characters rendered by the 
User Agent:') + '</b>';
-               content.appendChild(document.createElement('br'));
                var table = L.DomUtil.create('table', 'loleaflet-character', 
content);
                this._tbody = L.DomUtil.create('tbody', '', table);
                content.appendChild(document.createElement('br'));
                content.appendChild(document.createElement('br'));
                label = L.DomUtil.create('span', 'loleaflet-controls', content);
-               label.innerHTML = '<b>' + _('Special Character rendered by 
Server Side:') + '</b>';
+               label.innerHTML = '<b>' + _('Selected Character:') + '</b>';
                this._preview = L.DomUtil.create('img', '', content);
                content.appendChild(document.createElement('br'));
                content.appendChild(document.createElement('br'));
@@ -431,16 +440,24 @@ L.Control.CharacterMap = L.Control.extend({
        },
 
        _onRenderFontPreview: function (e) {
-               this._preview.src = e.img;
+               if (this.cacheGlyph[e.font + e.char]) {
+                       this.cacheGlyph[e.font + e.char].src = e.img;
+               } else {
+                       console.log('failed to get font image' + e.font + 
e.char);
+               }
        },
 
        _onSymbolClick: function (e) {
                var target = e.target || e.srcElement;
+               var encodedFont = 
window.encodeURIComponent(this._fontNames.options[this._fontNames.selectedIndex].value);
+               var encodedChar = 
window.encodeURIComponent(String.fromCharCode(target.data));
                this._hexa.data = target.data;
-               this._hexa.innerHTML = 'U+' + 
target.data.toString(16).toUpperCase();
-               this._map._socket.sendMessage('renderfont font=' +
-                       
window.encodeURIComponent(this._fontNames.options[this._fontNames.selectedIndex].value)
 +
-                       ' char=' + String.fromCharCode(this._hexa.data));
+               if (this.cacheGlyph[encodedFont + encodedChar]) {
+                       this._preview.src = this.cacheGlyph[encodedFont + 
encodedChar].src;
+               } else {
+                       this._preview.src = L.Icon.Default.imagePath + 
'/loading.gif';
+               }
+               this._hexa.innerHTML = 'U+' + 
this._hexa.data.toString(16).toUpperCase();
        },
 
        _onSymbolDblClick: function (e) {
diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js
index 5c0d834..e3799b6 100644
--- a/loleaflet/src/core/Socket.js
+++ b/loleaflet/src/core/Socket.js
@@ -532,7 +532,10 @@ L.Socket = L.Class.extend({
                                command.port = tokens[i].substring(5);
                        }
                        else if (tokens[i].substring(0, 5) === 'font=') {
-                               command.font = 
window.decodeURIComponent(tokens[i].substring(5));
+                               command.font = tokens[i].substring(5);
+                       }
+                       else if (tokens[i].substring(0, 5) === 'char=') {
+                               command.char = tokens[i].substring(5);
                        }
                        else if (tokens[i].substring(0, 7) === 'viewid=') {
                                command.viewid = tokens[i].substring(7);
diff --git a/loleaflet/src/layer/tile/TileLayer.js 
b/loleaflet/src/layer/tile/TileLayer.js
index d47a6e5..ba5e5d7 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -876,6 +876,7 @@ L.TileLayer = L.GridLayer.extend({
                var command = this._map._socket.parseServerCmd(textMsg);
                this._map.fire('renderfont', {
                        font: command.font,
+                       char: command.char,
                        img: img
                });
        },
commit 7234db931733a27b67622b8add85274ef6104b2a
Author: Henry Castro <[email protected]>
Date:   Sun Nov 27 22:39:50 2016 -0400

    wsd: fix sending wrong UTF-8 string to the client
    
    Client side console error "ws stopped cannot read
    utf8 string", the cause it is sending special character '{',
    '}',

diff --git a/wsd/PrisonerSession.cpp b/wsd/PrisonerSession.cpp
index 9132cae..bbfd902 100644
--- a/wsd/PrisonerSession.cpp
+++ b/wsd/PrisonerSession.cpp
@@ -242,6 +242,8 @@ bool PrisonerSession::_handleInput(const char *buffer, int 
length)
             getTokenString(tokens[2], "char", text);
             assert(firstLine.size() < 
static_cast<std::string::size_type>(length));
             _docBroker->tileCache().saveRendering(font+text, "font", buffer + 
firstLine.size() + 1, length - firstLine.size() - 1);
+            forwardToPeer(_peer, buffer, length, true);
+            return true;
         }
     }
     else
commit 7760d6d6d5fbe89ccca9732302933e52eee3bad1
Author: Henry Castro <[email protected]>
Date:   Sun Nov 27 19:49:17 2016 -0400

    wsd: fix URL encoded char parameter

diff --git a/kit/ChildSession.cpp b/kit/ChildSession.cpp
index 5e364ae..66e532b 100644
--- a/kit/ChildSession.cpp
+++ b/kit/ChildSession.cpp
@@ -358,7 +358,7 @@ bool ChildSession::loadDocument(const char * /*buffer*/, 
int /*length*/, StringT
 
 bool ChildSession::sendFontRendering(const char* /*buffer*/, int /*length*/, 
StringTokenizer& tokens)
 {
-    std::string font, text, decodedFont;
+    std::string font, text, decodedFont, decodedChar;
 
     if (tokens.count() < 3 ||
         !getTokenString(tokens[1], "font", font))
@@ -369,7 +369,18 @@ bool ChildSession::sendFontRendering(const char* 
/*buffer*/, int /*length*/, Str
 
     getTokenString(tokens[2], "char", text);
 
-    URI::decode(font, decodedFont);
+    try
+    {
+        URI::decode(font, decodedFont);
+        URI::decode(text, decodedChar);
+    }
+    catch (Poco::SyntaxException& exc)
+    {
+        LOG_DBG(exc.message());
+        sendTextFrame("error: cmd=renderfont kind=syntax");
+        return false;
+    }
+
     std::string response = "renderfont: " + Poco::cat(std::string(" "), 
tokens.begin() + 1, tokens.end()) + "\n";
 
     std::vector<char> output;
@@ -385,7 +396,7 @@ bool ChildSession::sendFontRendering(const char* 
/*buffer*/, int /*length*/, Str
 
         getLOKitDocument()->setView(_viewId);
 
-        ptrFont = getLOKitDocument()->renderFont(decodedFont.c_str(), 
text.c_str(), &width, &height);
+        ptrFont = getLOKitDocument()->renderFont(decodedFont.c_str(), 
decodedChar.c_str(), &width, &height);
     }
 
     LOG_TRC("renderFont [" << font << "] rendered in " << 
(timestamp.elapsed()/1000.) << "ms");
diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp
index cedbc5e..0d86109 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -319,7 +319,7 @@ 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, text, encodedChar;
+    std::string font, text;
     if (tokens.count() < 2 ||
         !getTokenString(tokens[1], "font", font))
     {
@@ -327,14 +327,13 @@ bool ClientSession::sendFontRendering(const char *buffer, 
int length, StringToke
     }
 
     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+encodedChar, "font");
+    std::unique_ptr<std::fstream> cachedRendering = 
docBroker->tileCache().lookupCachedFile(font+text, "font");
     if (cachedRendering && cachedRendering->is_open())
     {
         cachedRendering->seekg(0, std::ios_base::end);
diff --git a/wsd/PrisonerSession.cpp b/wsd/PrisonerSession.cpp
index faf8232..9132cae 100644
--- a/wsd/PrisonerSession.cpp
+++ b/wsd/PrisonerSession.cpp
@@ -231,7 +231,7 @@ bool PrisonerSession::_handleInput(const char *buffer, int 
length)
         }
         else if (tokens[0] == "renderfont:")
         {
-            std::string font, text, encodedChar;
+            std::string font, text;
             if (tokens.count() < 3 ||
                 !getTokenString(tokens[1], "font", font))
             {
@@ -240,9 +240,8 @@ bool PrisonerSession::_handleInput(const char *buffer, int 
length)
             }
 
             getTokenString(tokens[2], "char", text);
-            Poco::URI::encode(text, "", encodedChar);
             assert(firstLine.size() < 
static_cast<std::string::size_type>(length));
-            _docBroker->tileCache().saveRendering(font+encodedChar, "font", 
buffer + firstLine.size() + 1, length - firstLine.size() - 1);
+            _docBroker->tileCache().saveRendering(font+text, "font", buffer + 
firstLine.size() + 1, length - firstLine.size() - 1);
         }
     }
     else
diff --git a/wsd/protocol.txt b/wsd/protocol.txt
index 5ac2e0e..85470a4 100644
--- a/wsd/protocol.txt
+++ b/wsd/protocol.txt
@@ -89,10 +89,11 @@ ping
 
     requests a 'pong' server message.
 
-renderfont font=<font>
+renderfont font=<font> char=<characters>
 
     requests the rendering of the given font.
     The font parameter is URL encoded
+    The char parameter is URL encoded
 
 requestloksession
 
_______________________________________________
Libreoffice-commits mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to