Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
xf360 committed Feb 8, 2024
1 parent 7ab0689 commit 2abc5af
Show file tree
Hide file tree
Showing 35 changed files with 15,633 additions and 8,262 deletions.
25 changes: 24 additions & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,27 @@ js入口:apps/api/documents/api.js
14.ws 服务(server项目canvasservice.js文件)会将文档docx转为bin文件,然后把下载路径返回给前端,前端在下载该bin文档打开。
15.word 正文渲染为文件 word\Drawing\HtmlPage.js 中的OnPaint方法
16.OnPaint按元素类型调用各自的draw方法绘制canvas(段落调用word\Editor\Paragraph.js的draw方法,table调用word\Editor\Table\TableDraw.js的draw方法)
17.字符渲染是通过字符的unicode编码在对应的字库中找到字符,然后转为图片,字体管理js: common\libfont\manager.js
17.字符渲染是通过字符的unicode编码在对应的字库中找到字符,然后转为图片,字体管理js: common\libfont\manager.js
18.系统所用字体在core-fonts文件夹下,通过工具allfontsgen会将系统字体和corefonts目录下的字体生成为索引文件 /sdkjs/common/AllFonts.js和server/FileConverter/bin/AllFonts.js,以及fonts目录下编译后的字体文件。web-apps项目会加载/sdkjs/common/AllFonts.js字体索引文件,然后根据索引加载fonts目录编译后的字体文件。在docker中如果要新增或重新生成字体,请将新字体放在/var/www/onlyoffice/docmentserver/core-fonts/目录下,然后执行命令/usr/bin/documentserver-generate-allfonts.sh 重新生成字体索引;linux系统字体在目录/usr/share/fonts目录。如果编辑器字体列表中无新字体,请打开开发者工具强制刷新。
19./sdkjs/common/AllFonts.js 文件解析:该文件为字体索引文件,由工具allfontsgen自动生成。其会插入全局变量window["__fonts_files"],表示所有字体列表,每一项的key对应服务端fonts目录下的字体文件名。window["__fonts_infos"] 全局变量为字体名称和字体文件名对应关系:["品如手写体",194,0,-1,-1,-1,-1,-1,-1] 第一项为字体名字,第二项为window["__fonts_files"]的下标号,也对应fonts目录字体文件名,第三项起为faceIndexR indexI faceIndexI indexB faceIndexB indexBI faceIndexBI。window["__fonts_ranges"]不明。window["g_fonts_selection_bin"] 为base64编码的二进制格式,包含字体中文名称,字体路径、字体Unicode编码范围等信息,在/sdkjs/common/libfont/map.js文件中的CFontSelectList.init方法会解析该内容。
20.sdkjs/common/AllFonts.js加载完成后会加载/sdkjs/common/Drawings/Externals.js文件,并执行checkAllFonts()方法,该方法会对AllFonts.js中的字体列表进行进一步转换,最终创建全局对象window['AscFonts'].g_font_files,window['AscFonts'].g_font_infos,window['AscFonts'].g_map_font_index等字体信息对象。
20.特殊字体asc.ttf,作用不明
21.字体渲染过程,在加载完文档的bin二进制文件后,解析为cdocment对象,然后调用WordControl.m_oDrawingDocument.CheckFontNeeds方法遍历cdocment对象,计算出整个文档用到的所有字体列表并存在WordControl.m_oLogicDocument.Fonts变量中,然后调用GlobalLoaders.LoadDocumentFonts方法加载字体资源并设置定时器check_loaded_list异步判断fonts_loading列表字体是否下载完成,字体资源下载完成后会将stream缓存到全局变量g_fonts_streams中, 然后按 prograph->run->text等结构依次调用draw函数,text对象里面的value值为字符的unicode编码,然后调用_font_manager.LoadString3C将unicode编码转为图片,
_font_manager.LoadString3C继续调用m_pFont.GetString2C,m_pFont.GetString2C先从缓存中判断有没当前字形图片,没有就调用CacheGlyph方法获取字形图片,CacheGlyph内部调用AscFonts.FT_Get_Glyph_Render_Buffer->AscFonts.FT_Get_Glyph_Render_Buffer->Module["_ASC_FT_Get_Glyph_Render_Buffer"],Module["_ASC_FT_Get_Glyph_Render_Buffer"]为freetype模块导出的方法,最终实现为通过freetype模块加载字体并获取对应的字形数据。
23.freetype加载字体过程:在check_loaded_list定时器判断fonts_loading列表字体加载完成后,调用asc_docs_api.asyncFontsDocumentEndLoaded->CStylesPainter.drawStyle->g_fontApplication.LoadFont->CFontFilesCache.LoadFontFile->CFontManagerEngine.openFont->AscFonts.FT_Open_Face,传入字体文件的stream流调用freetype的_ASC_FT_Open_Face方法完成字体加载。
24.common\libfont\engine.js为自动生成,具体由哪个脚本生成待完善
25.common\libfont\loader.js用于加载字体引擎freetype wasm在web-app中由script标签引入


文档解析过程,
1.将文件url传给后台,后台转码后生成二进制bin文件,并将文件下载地址返回给前端。
2.前端下载完bin文件后,调用二进制文件类 oBinaryFileReader.Read->word\Editor\Serialize2.js的ReadMainTable读取二进制内容,并生成为文档对象CDocment。


后端生成bin文件逻辑:
在core项目中
1.先将docx文件解压
2.调用docx_dir2doct_bin->BinDocxRW::CDocxSerializer::saveToFile()(路径:D:\project\onlyoffice-windows\core\OOXML\Binary\Document\DocWrapper\DocxSerializer.cpp)将解压的文件夹转为bin格式
3.生成bin二进制文件的核心逻辑在(D:\project\onlyoffice-windows\core\OOXML\Binary\Document\BinWriter\BinWriters.cpp)中的BinaryFileWriter::intoBindoc()方法。
4.doc转docx:调用LoadAndConvert(D:\project\onlyoffice-windows\core\MsBinaryFile\DocFile\Converter.cpp)将doc转为docxdir格式然后在压缩为zip。
5.doc转pdf:和上面一样先将doc转为docxdir,然后在docxdir转为bin(docx_dir2doct_bin),再将bin转为pdf(doct_bin2pdf)
2 changes: 1 addition & 1 deletion apps/common/main/lib/core/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
},

start: function() {
debugger;
// debugger;
console.log('---5.1 backone应用启动:')
// initialize controllers
this.initializeControllers(this.controllers || {});
Expand Down
4 changes: 2 additions & 2 deletions apps/documenteditor/main/app/controller/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ define([

loadDocument: function(data) {
console.log('loadDocument加载文档')
debugger;
// debugger;
this.permissions = {};
this.document = data.doc;

Expand Down Expand Up @@ -1194,7 +1194,7 @@ define([
},

onDocumentContentReady: function() {
debugger;
// debugger;
console.log('onDocumentContentReady')
if (this._isDocReady)
return;
Expand Down
2 changes: 1 addition & 1 deletion apps/documenteditor/main/app/controller/ViewTab.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ define([

onChangeRulers: function (btn, checked) {
console.log('切换是否显示标尺');
debugger;
// debugger;
Common.localStorage.setBool('de-hidden-rulers', !checked);
Common.Utils.InternalSettings.set("de-hidden-rulers", !checked);
this.api.asc_SetViewRulers(checked);
Expand Down
6 changes: 3 additions & 3 deletions apps/documenteditor/main/app/controller/Viewport.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ define([
// When controller is created let's setup view event listeners
initialize: function() {
// This most important part when we will tell our controller what events should be handled
debugger;
// debugger;
var me = this;
this.addListeners({
'FileMenu': {
Expand Down Expand Up @@ -129,10 +129,10 @@ define([

// When our application is ready, lets get started
onLaunch: function() {
debugger;
// debugger;
// Create and render main view
this.viewport = this.createView('Viewport').render();
debugger;
// debugger;
this.api = new Asc.asc_docs_api({
'id-view' : 'editor_sdk',
'translate': this.getApplication().getController('Main').translationTable
Expand Down
2 changes: 1 addition & 1 deletion apps/documenteditor/main/app/view/Viewport.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ define([

// Render layout
render: function() {
debugger;
// debugger;
this.$el.html(this.template({}));

// Workaround Safari's scrolling problem
Expand Down
6 changes: 6 additions & 0 deletions apps/documenteditor/mobile/css/964.css

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions apps/documenteditor/mobile/css/framework7-rtl.css

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions apps/documenteditor/mobile/css/framework7.css

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions apps/documenteditor/mobile/dist/js/964.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions apps/documenteditor/mobile/dist/js/964.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/*!
*
* * Version: d (build: undefined)
*
*/
2 changes: 2 additions & 0 deletions apps/documenteditor/mobile/dist/js/app.js

Large diffs are not rendered by default.

47 changes: 47 additions & 0 deletions apps/documenteditor/mobile/dist/js/app.js.LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*!
*
* * Version: d (build: undefined)
*
*/

/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */

/**
* @license React
* react-dom.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/**
* @license React
* react.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/**
* @license React
* scheduler.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

/**
* @license React
* use-sync-external-store-shim.production.min.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
Loading

0 comments on commit 2abc5af

Please sign in to comment.