 My name is Matt. I work for Calabra Software Engineer. Today I want to talk about watermarks. Before I go into that, I will do a quick overview of how LibreOffice Online works and how the rendering first gets started. So the online has two parts, the server obviously and the client. The server basically creates a review of its instances by reviewing and controlling life cycles. By that it takes care of the rendering. It's taking care of the rendering of the document and handles communication with file storage by a popular protocol. We use it for which I'm going to explain in a minute. It takes a bridge between the users and the LibreOffice kit. I'm in the UI. The bridge is passing commands to the LibreOffice kit and it passes a codex from LibreOffice kit back to the client. These parts are all done in C++. And the client communicates with LibreOffice Online WebSock FDM. It's written in double script and base font. LibreOffice is a map rendering framework. Why we use it? Because the document is rendering to tiles. And the way it works is also the tiles. So it's a great framework for us to use it. So the mission here is available for next cloud and all cloud. It basically handles the storage and the users obviously. And it enables to work with the document on cloud. It handles the request, popular request from the client. The client here is not the user itself. LibreOffice actually, LibreOffice Online, as I mentioned earlier, it handles communication with file storage by API protocol. And the online is like a typical line as well to communicate with the file server. So with this protocol, it can pass user permissions to the LibreOffice server. And permissions like if the document is read-only, or if you allow printing of the document or don't need. And also auto-marks, which is available in secure view mode in the script and stack. So the rendering, kind of texture. It starts with JS. Obviously, we can connect to the web so get the amount through JS. And it sends a message to the document. It is both in the background and LibreOffice kit, what it does is it renders the document into tiles. And it sends it back to the client, actually. And also the tiles are stored in the cache. It knows what tile to be rendered. As it's seen here, tiles to be rendered are requested between the web so get the amount and the kit. There's a communication socket between them. Basically, we want to render the document to be a standard request like the first one, the co-tile online. It has the information about the tile itself. There's two types of rendering requests, one of them is tile, the other one is tile. It can be understood from its name. It is more than one tile to be rendered because it changes the document and it is more likely to change more than one tile, actually. So instead of sending the tiles one by one to render them, we put them in one message and render it. So as it's seen in the message, if you look at the word parameter, it has eight data separated by commas, which means that we have eight tiles to be rendered. So the other one has the positions and the offsets. So if you get the image size, it's zero, zero, zero. So what it means is this is just a rendering request. There's no tile is rendered, so far so good image size is zero. So we have this function called a part tile. After we pass this message and we send the information to this function and just paint the tile. So after the render tiles are rendered, they should be sent back to the demo, eventually to the UI. So as you can see, the message has changed a little bit. So the image size has not rose. So what it means is the first tile is 8,311 bytes. The second one is 8,375. So this message is not sent by itself, but also we add it to the image data below this message. So we use this image sizes to pass it correctly. So how do the watermarks are rendered? We render the watermarks in all the tiles that are requested. So it is done after the tile is rendered in core, and we check if the document has watermark. If so, we just paint it with the watermark. So this is done in online, not in core, but the original rendering is in core. After the rendering of the watermark, it looks like this. As you can see, each tile has a watermark rendered in the account. So how about PDF export? This is the new feature we implemented this year by request. So when the document has watermarks, it wasn't visible in the PDF export, so we implemented it, followed it. It's done in the core. There's a function in which you say it's a great function for converting the document formats in this way, in this case it's PDF. You just pass PDF in the format and rename it as the PDF extension. So the problem was sending the watermark text to the PDF rendering function. So we used the filter options parameter to pass it. This function is not actually made for this, but you just send the watermark text and pass it and remove the watermark info in the parameter. It's because it's not made for it. So, tiles in PDF. So we have three implement in a way that it would look like they are tiled in the document. So this is how it looks after the PDF export, very similar to how it looks like in the actual document. So how it is done in desktop is the other story. There's an option in the PDF export. You just check, sign the watermark and put the watermark text and it will look like this. So I basically took this function and turned it into this. So the problems with it and the current status. The current status is as I explained, watermarks are rendered in each tile of the document and the watermark object is created once and used globally. And the problems come with this actually. They are shown for every user regardless of their permissions. So let's say you're a document owner and there's a secure remote user reading the document at the same time with you. So the watermark object will be created for the user and since it's not checking whether you are a document owner or not, it will render the whole tile. So even if you are a document owner you will see the watermarks on your document which is silly because you are a document owner and you are editing your document and you will see the watermarks. It doesn't make any sense. So it's once created. The other problem is it once created always visible. So when a secure user will open after they open the document since the object is created even if they close it, the object will be still there. So you will see the watermarks. You will continue seeing the watermarks. So the plan to fix this we should obviously render the tiles according to the users. So each tile will have their own state ID which will include the user's permissions. So it doesn't have to be just a permission. We can add all kinds of stuff what we want to render into tile. The tiles will be requested by this state ID. This ID should be in the tile message as I showed you earlier. So we can decide if the tile has a watermark or not and we can render it accordingly. So we can also, as I said, we can render all the stuff like not creating characters etc. And this should be so greatly from cache because we don't want to render the tiles over the same let's say the state ID users, you know, if they have the same state ID the other one should be served from cache. What I did is extended the tile message with this state ID also and render the tiles according to it. So what's missing is the caching. I don't know if you noticed but the image sizes, I mean the zoom of the two documents were not the same. It's because when we rendered the tile we stored it in the cache. When I already used this the tile we first look into the cache and if there is the tile we take it. So since there is no information about the tile the state ID in the tile in the cache, so if they have the same zoom level the names will be the same. So the document will be mixed with what am I saying and not what am I saying. The feature I will be working on. So thanks for listening.