Skip to content

Commit

Permalink
[de] Implement rendering inline content controls with the custom bord…
Browse files Browse the repository at this point in the history
…er color
  • Loading branch information
KirillovIlya committed Feb 7, 2025
1 parent f9727cc commit ac19db2
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 54 deletions.
16 changes: 13 additions & 3 deletions common/Drawings/GraphicsBase.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@
};
CGraphicsBase.prototype.p_width = function(w)
{
this.textAlpha = undefined;
};
CGraphicsBase.prototype.p_dash = function(params)
{
Expand Down Expand Up @@ -589,9 +588,9 @@
this.drawHorLine(align, y, x + leftMW, r + rightMW, penW);
};

CGraphicsBase.prototype.DrawPolygon = function(oPath, lineWidth, shift)
CGraphicsBase.prototype.drawPolygon = function(oPath, lineWidth, shift)
{
this.p_width(lineWidth);
this.p_width(lineWidth * 1000);
this._s();

let Points = oPath.Points;
Expand Down Expand Up @@ -644,6 +643,17 @@
this.ds();
this._e();
};

CGraphicsBase.prototype.drawPolygonByRects = function(rects, lineWidth, shift)
{
let polygon = new AscCommon.CPolygon();
polygon.fill(rects);
let paths = polygon.GetPaths(shift ? shift : 0);
for (let i = 0, count = paths.length; i < count; ++i)
{
this.drawPolygon(paths[i], lineWidth, 0);
}
};

/**
* made with the use of:
Expand Down
59 changes: 22 additions & 37 deletions word/Editor/Paragraph.js
Original file line number Diff line number Diff line change
Expand Up @@ -3298,7 +3298,6 @@ Paragraph.prototype.drawRunContentLines = function(CurPage, pGraphics, drawState
var arrFormAreasColors = [];
var arrFormAreas = [];
var arrFormRects = [];
var arrFormAreasWidths = [];

let drawRunPrReview = !pGraphics.isPrintMode && !pGraphics.isPdf();

Expand Down Expand Up @@ -3425,7 +3424,7 @@ Paragraph.prototype.drawRunContentLines = function(CurPage, pGraphics, drawState
RunPrReview = Element.Additional.RunPr;
arrRunReviewRects = [];
arrRunReviewAreas.push(arrRunReviewRects);
arrRunReviewAreasColors.push(new CDocumentColor(Element.r, Element.g, Element.b));
arrRunReviewAreasColors.push(new AscWord.CDocumentColorA(Element.r, Element.g, Element.b, 255));
}

arrRunReviewRectsLine.push({
Expand Down Expand Up @@ -3568,8 +3567,7 @@ Paragraph.prototype.drawRunContentLines = function(CurPage, pGraphics, drawState
}
arrFormRects = [];
arrFormAreas.push(arrFormRects);
arrFormAreasColors.push(new CDocumentColor(Element.r, Element.g, Element.b));
arrFormAreasWidths.push(Element.w);
arrFormAreasColors.push(new AscWord.CDocumentColorA(Element.r, Element.g, Element.b, Element.a));
}

arrFormRectsLine.push({
Expand All @@ -3590,37 +3588,16 @@ Paragraph.prototype.drawRunContentLines = function(CurPage, pGraphics, drawState

pGraphics.End_Command();
}

if (pGraphics.DrawPolygon)

this.drawPolygons(pGraphics, arrRunReviewAreas, arrRunReviewAreasColors, 0, 0);
this.drawPolygons(pGraphics, arrFormAreas, arrFormAreasColors, 0, 0);
};
Paragraph.prototype.drawPolygons = function(graphics, areas, colors, lineWidth, shift)
{
for (let i = 0, areaCount = areas.length; i < areaCount; ++i)
{
for (var ReviewAreaIndex = 0, ReviewAreasCount = arrRunReviewAreas.length; ReviewAreaIndex < ReviewAreasCount; ++ReviewAreaIndex)
{
var arrRunReviewRects = arrRunReviewAreas[ReviewAreaIndex];
var oRunReviewColor = arrRunReviewAreasColors[ReviewAreaIndex];
var ReviewPolygon = new AscCommon.CPolygon();
ReviewPolygon.fill(arrRunReviewRects);
var PolygonPaths = ReviewPolygon.GetPaths(0);
pGraphics.p_color(oRunReviewColor.r, oRunReviewColor.g, oRunReviewColor.b, 255);
for (var PolygonIndex = 0, PolygonsCount = PolygonPaths.length; PolygonIndex < PolygonsCount; ++PolygonIndex)
{
var Path = PolygonPaths[PolygonIndex];
pGraphics.DrawPolygon(Path, 1, 0);
}
}

for (var nFormAreaIndex = 0, nFormAreasCount = arrFormAreas.length; nFormAreaIndex < nFormAreasCount; ++nFormAreaIndex)
{
var arrFormRects = arrFormAreas[nFormAreaIndex];
var oFormColor = arrFormAreasColors[nFormAreaIndex];
var oPolygon = new AscCommon.CPolygon();
oPolygon.fill(arrFormRects);
var arrPolygonPaths = oPolygon.GetPaths(0);
pGraphics.p_color(oFormColor.r, oFormColor.g, oFormColor.b, 255);
for (var nPolygonIndex = 0, nPolygonsCount = arrPolygonPaths.length; nPolygonIndex < nPolygonsCount; ++nPolygonIndex)
{
pGraphics.DrawPolygon(arrPolygonPaths[nPolygonIndex], 1, 0);//arrFormAreasWidths[nFormAreaIndex], 0);
}
}
graphics.p_color(colors[i].r, colors[i].g, colors[i].b, colors[i].a);
graphics.drawPolygonByRects(areas[i], lineWidth, shift);
}
};
Paragraph.prototype.Internal_Draw_6 = function(CurPage, pGraphics, Pr)
Expand Down Expand Up @@ -19285,7 +19262,7 @@ CParaPos.prototype.IsValid = function(oParagraph)


// используется в Internal_Draw_3 и Internal_Draw_5
function CParaDrawingRangeLinesElement(y0, y1, x0, x1, w, r, g, b, Additional, Additional2)
function CParaDrawingRangeLinesElement(y0, y1, x0, x1, w, r, g, b, a, Additional, Additional2)
{
this.y0 = y0;
this.y1 = y1;
Expand All @@ -19295,6 +19272,7 @@ function CParaDrawingRangeLinesElement(y0, y1, x0, x1, w, r, g, b, Additional, A
this.r = r;
this.g = g;
this.b = b;
this.a = a;

this.Additional = Additional;
this.Additional2 = Additional2;
Expand All @@ -19316,8 +19294,14 @@ CParaDrawingRangeLines.prototype =

Add : function (y0, y1, x0, x1, w, r, g, b, Additional, Additional2)
{
this.Elements.push( new CParaDrawingRangeLinesElement(y0, y1, x0, x1, w, r, g, b, Additional, Additional2) );
this.Elements.push( new CParaDrawingRangeLinesElement(y0, y1, x0, x1, w, r, g, b, 255, Additional, Additional2) );
},

// TODO: Unite Add and addWithAlpha methods
addWithAlpha : function(y0, y1, x0, x1, w, r, g, b, a, Additional, Additional2)
{
this.Elements.push(new CParaDrawingRangeLinesElement(y0, y1, x0, x1, w, r, g, b, a, Additional, Additional2));
},

Get_Next : function(isSaveIntermediate)
{
Expand Down Expand Up @@ -19391,7 +19375,8 @@ CParaDrawingRangeLines.prototype =
&& Math.abs(PrevEl.w - Element.w) < 0.001
&& PrevEl.r === Element.r
&& PrevEl.g === Element.g
&& PrevEl.b === Element.b)
&& PrevEl.b === Element.b
&& PrevEl.a === Element.a)
{
if (undefined === PrevEl.Additional && undefined === Element.Additional)
return true;
Expand Down
53 changes: 41 additions & 12 deletions word/Editor/Paragraph/draw/line-draw-state.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
this.Spaces = 0;

this.complexFields = new AscWord.ParagraphComplexFieldStack();
this.contentControls = [];

this.run = null;

Expand All @@ -89,9 +90,10 @@
this.isStrikeout = false;
this.isDStrikeout = false;

this.form = null;
this.formBorder = null;
this.combMax = -1;
this.form = null;
this.formBorderColor = null;
this.formBorderWidth = 0;
this.combMax = -1;

this.reviewAdd = false;
this.reviewRem = false;
Expand Down Expand Up @@ -320,9 +322,33 @@
this.isFormPlaceholder = true;
}

this.form = form;
this.formBorder = formBorder;
this.combMax = combMax;
this.form = form;
this.combMax = combMax;

this.formBorderWidth = 0;
this.formBorderColor = null;

if (this.form)
{
this.formBorderWidth = formBorder.GetWidth();
this.formBorderColor = AscWord.CDocumentColorA.fromObjectRgb(formBorder.GetColor());
}
else
{
// TODO: It's better to handle CC stack on the fly instead of getting it for each run
let contentControls = run.GetParentContentControls();
for (let i = contentControls.length - 1; i >= 0; --i)
{
let cc = contentControls[i];
if (cc instanceof AscWord.CInlineLevelSdt && cc.getBorderColor())
{
this.form = cc;
this.formBorderWidth = 0;
this.formBorderColor = cc.getBorderColor();
break;
}
}
}

this.yOffset = run.getYOffset();

Expand Down Expand Up @@ -352,11 +378,11 @@
ParagraphLineDrawState.prototype.handleFormBorder = function(item, run, inRunPos)
{
let itemWidth = item.GetWidthVisible();
if (!this.formBorder || itemWidth <= 0.001)
if (!this.form || itemWidth <= 0.001)
return;

let borderW = this.formBorder.GetWidth();
let borderColor = this.formBorder.GetColor();
let borderW = this.formBorderWidth;
let borderColor = this.formBorderColor;

let Y = this.Baseline;
let X = this.X;
Expand All @@ -381,32 +407,35 @@
if (item.RGapCount)
{
var nGapEnd = X + itemWidth;
this.FormBorder.Add(Y, Y, X, nGapEnd - item.RGapCount * item.RGapShift,
this.FormBorder.addWithAlpha(Y, Y, X, nGapEnd - item.RGapCount * item.RGapShift,
borderW,
borderColor.r,
borderColor.g,
borderColor.b,
borderColor.a,
additional
);

for (var nGapIndex = 0; nGapIndex < item.RGapCount; ++nGapIndex)
{
this.FormBorder.Add(Y, Y, nGapEnd - (item.RGapCount - nGapIndex) * item.RGapShift, nGapEnd - (item.RGapCount - nGapIndex - 1) * item.RGapShift,
this.FormBorder.addWithAlpha(Y, Y, nGapEnd - (item.RGapCount - nGapIndex) * item.RGapShift, nGapEnd - (item.RGapCount - nGapIndex - 1) * item.RGapShift,
borderW,
borderColor.r,
borderColor.g,
borderColor.b,
borderColor.a,
additional
);
}
}
else
{
this.FormBorder.Add(Y, Y, X, X + itemWidth,
this.FormBorder.addWithAlpha(Y, Y, X, X + itemWidth,
borderW,
borderColor.r,
borderColor.g,
borderColor.b,
borderColor.a,
additional
);
}
Expand Down
4 changes: 2 additions & 2 deletions word/Editor/StructuredDocumentTags/SdtPr.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ function CSdtPr()

this.OForm = undefined;

this.BorderColor = new AscWord.CDocumentColorA(0, 255, 255, 125);
this.ShdColor = new AscWord.CDocumentColorA(41, 52, 136, 125);
this.BorderColor = new AscWord.CDocumentColorA(Math.random() * 255 | 0, Math.random() * 255 | 0, Math.random() * 255 | 0, Math.random() * 255 | 0);
this.ShdColor = new AscWord.CDocumentColorA(Math.random() * 255 | 0, Math.random() * 255 | 0, Math.random() * 255 | 0, Math.random() * 255 | 0);
}

CSdtPr.prototype.Copy = function()
Expand Down
8 changes: 8 additions & 0 deletions word/Editor/Styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -9557,6 +9557,14 @@ AscWord.CDocumentColor = CDocumentColor;
let a = reader.GetByte();
return new CDocumentColorA(r, g, b, a);
};
CDocumentColorA.fromObjectRgb = function(obj)
{
return new CDocumentColorA(obj.r, obj.g, obj.b, 255);
};
CDocumentColorA.fromObjectRgba = function(obj)
{
return new CDocumentColorA(obj.r, obj.g, obj.b, obj.a);
};
CDocumentColorA.prototype.toBinary = function(writer)
{
writer.WriteByte(this.r);
Expand Down

0 comments on commit ac19db2

Please sign in to comment.