Skip to content

Commit

Permalink
[de] Improve the view of the document in reading mode
Browse files Browse the repository at this point in the history
  • Loading branch information
KirillovIlya committed Feb 13, 2024
1 parent 61ef142 commit 6050cb5
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 20 deletions.
6 changes: 3 additions & 3 deletions word/Editor/Layout/Base.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,11 @@
return 1;
};
/**
* @returns {boolean}
* @returns {number}
*/
CDocumentLayoutBase.prototype.isZeroIndents = function()
CDocumentLayoutBase.prototype.calculateIndent = function(ind, sectPr)
{
return false;
return ind;
};
//--------------------------------------------------------export----------------------------------------------------
AscWord.CDocumentLayoutBase = CDocumentLayoutBase;
Expand Down
3 changes: 2 additions & 1 deletion word/Editor/Layout/PrintView.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@
};
CDocumentPrintView.prototype.GetSectionByPos = function(nContentIndex)
{
return this.SectionsInfo.Get_SectPr(nContentIndex).SectPr;
let sectInfo = this.SectionsInfo.Get_SectPr(nContentIndex);
return sectInfo ? sectInfo.SectPr : null;
};
CDocumentPrintView.prototype.GetSectionInfo = function(nContentIndex)
{
Expand Down
25 changes: 14 additions & 11 deletions word/Editor/Layout/ReadView.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,21 @@
function CDocumentReadView(oLogicDocument)
{
AscWord.CDocumentLayoutBase.call(this, oLogicDocument);

this.W = 297;
this.H = 210;
this.Scale = 1;
this.SectPr = null;
this.SectInfo = null;

let oThis = this;
AscCommon.ExecuteNoHistory(function()
{
oThis.SectPr = new CSectionPr(oLogicDocument);
oThis.SectInfo = new CDocumentSectionsInfoElement(oThis.SectPr, 0);
}, oLogicDocument);
}

CDocumentReadView.prototype = Object.create(AscWord.CDocumentLayoutBase.prototype);
CDocumentReadView.prototype.constructor = CDocumentReadView;
CDocumentReadView.prototype.IsReadMode = function()
Expand All @@ -68,9 +69,9 @@
this.W = nW;
this.H = nH;
this.Scale = nScale;

let oSectPr = this.SectPr;

AscCommon.ExecuteNoHistory(function()
{
oSectPr.SetPageSize(nW, nH);
Expand All @@ -96,7 +97,6 @@
CDocumentReadView.prototype.GetPageContentFrame = function(nPageAbs, oSectPr)
{
let oFrame = this.SectPr.GetContentFrame(0);

return {
X : oFrame.Left,
Y : oFrame.Top,
Expand All @@ -107,7 +107,6 @@
CDocumentReadView.prototype.GetColumnContentFrame = function(nPageAbs, nColumnAbs, oSectPr)
{
let oFrame = oSectPr.GetContentFrame(nPageAbs);

return {
X : oFrame.Left,
Y : oFrame.Top,
Expand Down Expand Up @@ -141,20 +140,24 @@
{
let nW = oSectPr.GetPageWidth();
let nH = oSectPr.GetPageHeight();

let nCoef = 1;
if (this.W < nW)
nCoef = this.W / nW;

if (this.H < nH)
nCoef = Math.min(this.H / nH, nCoef);

return nCoef;
};
CDocumentReadView.prototype.isZeroIndents = function()
CDocumentReadView.prototype.calculateIndent = function(ind, sectPr)
{
return true;
if (ind > 0 && sectPr)
return ind * this.W / sectPr.GetPageWidth();

return Math.max(ind, -2);
};

//--------------------------------------------------------export----------------------------------------------------
window['AscWord'].CDocumentReadView = CDocumentReadView;

Expand Down
9 changes: 6 additions & 3 deletions word/Editor/Paragraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -10854,10 +10854,13 @@ Paragraph.prototype.Internal_CompileParaPr2 = function()
Pr.ParaPr.NumPr = undefined;

let logicDocument = this.GetLogicDocument();
if (logicDocument && logicDocument.IsDocumentEditor() && logicDocument.Layout.isZeroIndents())
if (logicDocument && logicDocument.IsDocumentEditor())
{
Pr.ParaPr.Ind.Left = 0;
Pr.ParaPr.Ind.Right = 0;
let sectPr = this.Get_SectPr();
let left = Pr.ParaPr.Ind.Left;
Pr.ParaPr.Ind.Left = logicDocument.Layout.calculateIndent(Pr.ParaPr.Ind.Left, sectPr);
Pr.ParaPr.Ind.Right = logicDocument.Layout.calculateIndent(Pr.ParaPr.Ind.Right, sectPr);
Pr.ParaPr.Ind.FirstLine = logicDocument.Layout.calculateIndent(left + Pr.ParaPr.Ind.FirstLine, sectPr) - Pr.ParaPr.Ind.Left;
}

return Pr;
Expand Down
4 changes: 2 additions & 2 deletions word/Editor/Table.js
Original file line number Diff line number Diff line change
Expand Up @@ -8537,8 +8537,8 @@ CTable.prototype.Internal_Compile_Pr = function()
Pr.TablePr.Merge(this.Pr);

let logicDocument = this.GetLogicDocument();
if (logicDocument && logicDocument.IsDocumentEditor() && logicDocument.Layout.isZeroIndents())
Pr.TablePr.TableInd = 0;
if (logicDocument && logicDocument.IsDocumentEditor())
Pr.TablePr.TableInd = logicDocument.Layout.calculateIndent(Pr.TablePr.TableInd, this.Get_SectPr());

return Pr;
};
Expand Down

0 comments on commit 6050cb5

Please sign in to comment.