📜 ⬆️ ⬇️

ONLYOFFICE. Naked Truth About Cloud Office Source Code


In early July, Teamlab was renamed ONLYOFFICE and fully opened the source code of its application, including online document editors, collaborative editing, Gantt chart and billing functionality.
In two weeks we received a lot of questions on this topic, therefore, as an employee of the company, I will undertake to explain what is what. If you do not have time to read the post, simply download the ONLYOFFICE installation from Sourceforge. Deploy on your server. Done! You have your own cloud office. You are wonderful.

Why Teamlab became ONLYOFFICE

The idea of ​​rebranding existed for a long time. In our blog, we wrote a whole post about why we chose ONLY as a new set-top box for our office, however, there were very specific reasons. First, the name Teamlab has ceased to reflect the idea of ​​a product, because the “team” is associated with a small team, while among our customers there are more and more companies with 300 and 400 people. Secondly, besides us, unfortunately, this word was chosen by designers of interactive hangers from Japan.

Why we opened the source code (Honesty is the best policy because)

The main reason is, of course, trust. Not only from clients, but also from our partners . In today's situation, we get quite a lot of questions about the security of corporate data storage, especially from foreign customers. By publishing the ONLYOFFICE code on Sourceforge and GitHub , we take another step towards them.

License selection

Publishing the source codes of our product, we pursued several goals:

After weighing all the pros and cons, we chose AGPL v3 . In a nutshell, it means the following: you can use ONLYOFFICE in your company for free and without restrictions, but if you want to embed our code in your own application, you will have to open the source codes of your product under the same license. Read more here .
')

What our programmers say

Go to the most interesting part of our post. The Open Source version of ONLYOFFICE has been preparing for release for quite a while - the text editor alone contains over 500,000 lines of code! Of course, we have something to talk about:

Special attention to Internet Explorer
The basis of the rasterization algorithm is taken from freetype, as this is a high-quality, time-tested open font engine. The algorithms themselves changed a bit so that the execution speed was higher exactly in the browser, since we write in javascript.

But, for example, we had to write a cache of letters in two versions: for Internet Explorer and for all others. Due to the specifics of the browser in IE, the first implementation was slow.
Oleg, lead programmer

What do you know about the width of columns in Excel?
There are two main scenarios for using Excel:
  • financial calculations
  • creating forms (invoices) for further filling and printing.

A large number of forms were created before the appearance of our table editor, so our task was not only to learn how to open them correctly, but also correctly calculate column widths and row heights. Otherwise, when printing, the form might not get on the sheet.
For example, the standard column width in Microsoft Excel is 8.43 characters. It is calculated from the default width of 8 characters, which is converted to pixels depending on the Normal style. Then, as it turned out, the resulting number is rounded to the nearest multiple of 8.
Another feature is the height of the line. In Excel, you cannot set the line spacing, as, for example, in Word, so the calculation of the height of a line in Excel is different from the calculation of the height of a line in Word. For example, the comparison in the Cambria Math 11 font:

As a result, we implemented the calculation so that not a single character was cut off.
Alexander, leading programmer

How we linked a dependency tree and topological sorting
Most of the spreadsheets one way or another contains the formula. To solve the problems of parsing and counting formulas, a parser and a calculator were implemented. Also in the work with formulas, the construction of dependencies between cells deserves special attention. For this purpose, a topological sorting algorithm was used, which allows building a dependency tree traversal order.
Dmitry, programmer

Fifteen thousand tests and 80 cars
To test the ONLYOFFICE installation, we deployed it and started the familiar process. In total, about 15,000 tests ran, which run on 80 machines. By the way, we host them now on the Digital Ocean and in the near future we will tell how the entire test structure was transferred there.
Stas, Head of Testing

Hopes & Fears
Are we afraid of someone borrowing our code for personal gain? Not. The use of the ONLYOFFICE code is clearly stated in the license, and here we are protected by international law.
Do we think that someone will “watch” and make a similar product? Of course, we think. But the guys will take at least 3 years to do this, so we don’t really worry too much. However, we have long been accustomed to be and survive in a highly competitive environment.
Alexandra, head of the promotion department

What do you need to build your editor on the canvas?
Any text editor begins with splitting the text into lines and rendering. The first working version consisted of 150 lines of code and was implemented as follows:

//  ParaText function ParaText(value) { this.Value = value; this.Type = para_Text; this.Width = 0; this.Height = 0; } ParaText.prototype.Draw = function(X, Y, Context); ParaText.prototype.Measure = function(Context); 

140 more lines of code
 //  ParaSpace function ParaSpace() { this.Type = para_Space; this.Width = 0; this.Height = 0; } ParaSpace.prototype.Draw = function(X,Y, Context); ParaSpace.prototype.Measure = function(Context); //  ParaNewLineRendered function ParaNewLineRendered() { this.Type = para_NewLineRendered; this.Width = 0; this.Height = 0; } ParaNewLineRendered.prototype.Draw = function(); ParaNewLineRendered.prototype.Measure = function(); //  Paragraph function CParagraph() { //................... //   this.X = 0; this.Y = 0; //   this.XLimit = 0; //  ,     ParaText, ParaSpace  ParaNewLineRendered this.Content = new Array(); //  .          this.dLineHeight = 0; //................... } CParagraph.prototype.Recalculate = function() { //    .      ParaNewLineRendered //.............................. //     var X = this.X, Y = this.Y; //   var CurLine = 0; var bNewLine = false; var bFirstItemOnLine = true; var bWord = false; var nWordStartPos = 0; var dWordLen = 0; for ( var nPos = 0; nPos < this.Content.length; nPos++ ) { var Item = this.Content[nPos]; switch( Item.Type ) { case para_Text: { var dLetterLen = Item.Measure( Context ).Width; if ( !bWord ) { //    ,        ,         . if ( !bFirstItemOnLine ) { if ( X + dLetterLen > this.XLimit ) { //          -    this.Content.splice( nPos, 0, new ParaNewLineRendered() ); bNewLine = true; } } if ( !bNewLine ) { nWordStartPos = nPos; dWordLen = dLetterLen; bWord = true; } } else { if ( X + dWordLen + dLetterLen > this.XLimit ) { if ( bFirstItemOnLine ) { //         //   .      . X += dWordLen; this.Content.splice( nPos, 0, new ParaNewLineRendered() ); bNewLine = true; } else { //           this.Content.splice( nWordStartPos, 0, new ParaNewLineRendered() ); nPos = nWordStartPos; bNewLine = true; } } if ( !bNewLine ) { dWordLen += dLetterLen; } } break; } case para_Space: { bFirstItemOnLine = false; var dSpaceLen = Item.Measure( Canvas ).Width; if ( bWord ) { //   ,    -       X += dWordLen; bWord = false; dWordLen = 0; } if ( X + dSpaceLen > this.XLimit ) { bNewLine = true; } else X += dSpaceLen; break; } } //     if ( bNewLine ) { bNewLine = false; bFirstItemOnLine = true; bWord = false; dWordLen = 0; //      ,         X = this.X; Y += this.dLineHeight; CurLine++; } } } CParagraph.prototype.Draw = function(Context) { var Y = this.Y; var X = this.X; var nCount = this.Content.length; for ( var nPos = 0; nPos < nCount; nPos++ ) { var Item = this.Content[nPos]; Item.Draw( X, Y, Context ); X += Item.Width; if ( para_NewLineRendered == Item.Type ) { Y += this.dLineHeight; X = this.X; } } } 


Ilya, leading programmer

Two weeks after the start of development, the first test case was ready:


Download and test an example here .
There is nothing more pleasant than comparing it with what we have achieved in a few years. And so, at what stage are the editors of competitors.


You can test all editors without registering on personal.teamlab.com . By the way, they generally can be actively used - it is free.

Our goal? ONLYOFFICE users worldwide

We really have a lot of plans. Already, we are actively working on mobile and desktop applications, in addition to this, office editors 3.0 will be released by the fall, and we are also thinking about committing development on GitHub in real time.

It seems everything. We move discussion in the comment)

Source: https://habr.com/ru/post/231747/


All Articles