init repo

This commit is contained in:
nikolay ivanov
2014-07-05 18:22:49 +00:00
commit a8be6b9e72
17348 changed files with 9229832 additions and 0 deletions

View File

@@ -0,0 +1,458 @@
/*
* (c) Copyright Ascensio System SIA 2010-2014
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
var ArcToCurvers = null;
var ArcToOnCanvas = null;
var HitToArc = null;
(function () {
function Arc3(ctx, fX, fY, fWidth, fHeight, fStartAngle, fSweepAngle) {
var sin1 = Math.sin(fStartAngle);
var cos1 = Math.cos(fStartAngle);
var __x = cos1 / fWidth;
var __y = sin1 / fHeight;
var l = 1 / Math.sqrt(__x * __x + __y * __y);
var cx = fX - l * cos1;
var cy = fY - l * sin1;
Arc2(ctx, cx - fWidth, cy - fHeight, 2 * fWidth, 2 * fHeight, fStartAngle, fSweepAngle);
}
function Arc2(ctx, fX, fY, fWidth, fHeight, fStartAngle, fSweepAngle) {
if (0 >= fWidth || 0 >= fHeight) {
return;
}
fStartAngle = -fStartAngle;
fSweepAngle = -fSweepAngle;
if (false) {
var fStartX = fX + fWidth / 2 + fWidth / 2 * Math.cos(AngToEllPrm(fStartAngle, fWidth / 2, fHeight / 2));
var fStartY = fY + fHeight / 2 - fHeight / 2 * Math.sin(AngToEllPrm(fStartAngle, fWidth / 2, fHeight / 2));
if (fSweepAngle < (2 * Math.PI)) {
ctx._m(fStartX, fStartY);
}
}
var bClockDirection = false;
var fEndAngle = (2 * Math.PI) - (fSweepAngle + fStartAngle);
var fSrtAngle = (2 * Math.PI) - fStartAngle;
if (fSweepAngle > 0) {
bClockDirection = true;
}
if (Math.abs(fSweepAngle) >= (2 * Math.PI)) {
Ellipse(ctx, fX + fWidth / 2, fY + fHeight / 2, fWidth / 2, fHeight / 2);
} else {
EllipseArc(ctx, fX + fWidth / 2, fY + fHeight / 2, fWidth / 2, fHeight / 2, fSrtAngle, fEndAngle, bClockDirection);
}
}
function AngToEllPrm(fAngle, fXRad, fYRad) {
return Math.atan2(Math.sin(fAngle) / fYRad, Math.cos(fAngle) / fXRad);
}
function Ellipse(ctx, fX, fY, fXRad, fYRad) {
ctx._m(fX - fXRad, fY);
var c_fKappa = 0.5520000000000001;
ctx._c(fX - fXRad, fY + fYRad * c_fKappa, fX - fXRad * c_fKappa, fY + fYRad, fX, fY + fYRad);
ctx._c(fX + fXRad * c_fKappa, fY + fYRad, fX + fXRad, fY + fYRad * c_fKappa, fX + fXRad, fY);
ctx._c(fX + fXRad, fY - fYRad * c_fKappa, fX + fXRad * c_fKappa, fY - fYRad, fX, fY - fYRad);
ctx._c(fX - fXRad * c_fKappa, fY - fYRad, fX - fXRad, fY - fYRad * c_fKappa, fX - fXRad, fY);
}
function EllipseArc(ctx, fX, fY, fXRad, fYRad, fAngle1, fAngle2, bClockDirection) {
while (fAngle1 < 0) {
fAngle1 += (2 * Math.PI);
}
while (fAngle1 > (2 * Math.PI)) {
fAngle1 -= (2 * Math.PI);
}
while (fAngle2 < 0) {
fAngle2 += (2 * Math.PI);
}
while (fAngle2 >= (2 * Math.PI)) {
fAngle2 -= (2 * Math.PI);
}
if (!bClockDirection) {
if (fAngle1 <= fAngle2) {
EllipseArc2(ctx, fX, fY, fXRad, fYRad, fAngle1, fAngle2, false);
} else {
EllipseArc2(ctx, fX, fY, fXRad, fYRad, fAngle1, 2 * Math.PI, false);
EllipseArc2(ctx, fX, fY, fXRad, fYRad, 0, fAngle2, false);
}
} else {
if (fAngle1 >= fAngle2) {
EllipseArc2(ctx, fX, fY, fXRad, fYRad, fAngle1, fAngle2, true);
} else {
EllipseArc2(ctx, fX, fY, fXRad, fYRad, fAngle1, 0, true);
EllipseArc2(ctx, fX, fY, fXRad, fYRad, 2 * Math.PI, fAngle2, true);
}
}
}
function EllipseArc2(ctx, fX, fY, fXRad, fYRad, dAngle1, dAngle2, bClockDirection) {
var nFirstPointQuard = ((2 * dAngle1 / Math.PI) >> 0) + 1;
var nSecondPointQuard = ((2 * dAngle2 / Math.PI) >> 0) + 1;
nSecondPointQuard = Math.min(4, Math.max(1, nSecondPointQuard));
nFirstPointQuard = Math.min(4, Math.max(1, nFirstPointQuard));
var fStartX = fX + fXRad * Math.cos(AngToEllPrm(dAngle1, fXRad, fYRad));
var fStartY = fY + fYRad * Math.sin(AngToEllPrm(dAngle1, fXRad, fYRad));
var EndPoint = {
X: 0,
Y: 0
};
var fCurX = fStartX,
fCurY = fStartY;
var dStartAngle = dAngle1;
var dEndAngle = 0;
if (!bClockDirection) {
for (var nIndex = nFirstPointQuard; nIndex <= nSecondPointQuard; nIndex++) {
if (nIndex == nSecondPointQuard) {
dEndAngle = dAngle2;
} else {
dEndAngle = nIndex * Math.PI / 2;
}
if (! (nIndex == nFirstPointQuard)) {
dStartAngle = (nIndex - 1) * Math.PI / 2;
}
EndPoint = EllipseArc3(ctx, fX, fY, fXRad, fYRad, AngToEllPrm(dStartAngle, fXRad, fYRad), AngToEllPrm(dEndAngle, fXRad, fYRad), false);
}
} else {
for (var nIndex = nFirstPointQuard; nIndex >= nSecondPointQuard; nIndex--) {
if (nIndex == nFirstPointQuard) {
dStartAngle = dAngle1;
} else {
dStartAngle = nIndex * Math.PI / 2;
}
if (! (nIndex == nSecondPointQuard)) {
dEndAngle = (nIndex - 1) * Math.PI / 2;
} else {
dEndAngle = dAngle2;
}
EndPoint = EllipseArc3(ctx, fX, fY, fXRad, fYRad, AngToEllPrm(dStartAngle, fXRad, fYRad), AngToEllPrm(dEndAngle, fXRad, fYRad), false);
}
}
}
function EllipseArc3(ctx, fX, fY, fXRad, fYRad, dAngle1, dAngle2, bClockDirection) {
var fAlpha = Math.sin(dAngle2 - dAngle1) * (Math.sqrt(4 + 3 * Math.tan((dAngle2 - dAngle1) / 2) * Math.tan((dAngle2 - dAngle1) / 2)) - 1) / 3;
var sin1 = Math.sin(dAngle1);
var cos1 = Math.cos(dAngle1);
var sin2 = Math.sin(dAngle2);
var cos2 = Math.cos(dAngle2);
var fX1 = fX + fXRad * cos1;
var fY1 = fY + fYRad * sin1;
var fX2 = fX + fXRad * cos2;
var fY2 = fY + fYRad * sin2;
var fCX1 = fX1 - fAlpha * fXRad * sin1;
var fCY1 = fY1 + fAlpha * fYRad * cos1;
var fCX2 = fX2 + fAlpha * fXRad * sin2;
var fCY2 = fY2 - fAlpha * fYRad * cos2;
if (!bClockDirection) {
ctx._c(fCX1, fCY1, fCX2, fCY2, fX2, fY2);
return {
X: fX2,
Y: fY2
};
} else {
ctx._c(fCX2, fCY2, fCX1, fCY1, fX1, fY1);
return {
X: fX1,
Y: fY1
};
}
}
ArcToCurvers = Arc3;
function _ArcToOnCanvas(context, start_x, start_y, width_r, height_r, start_ang, sweep_ang) {
var _sin = Math.sin(start_ang);
var _cos = Math.cos(start_ang);
var _x = _cos / width_r;
var _y = _sin / height_r;
var _l = 1 / Math.sqrt(_x * _x + _y * _y);
var _cx = start_x - _l * _cos;
var _cy = start_y - _l * _sin;
ArcTo2OnCanvas(context, _cx - width_r, _cy - height_r, 2 * width_r, 2 * height_r, start_ang, sweep_ang);
}
function ArcTo2OnCanvas(context, _l_c_x, _l_c_y, width, height, start_ang, sweep_ang) {
if (0 >= width || 0 >= height) {
return;
}
start_ang = -start_ang;
sweep_ang = -sweep_ang;
var bClockDirection = false;
var fEndAngle = (2 * Math.PI) - (sweep_ang + start_ang);
var fSrtAngle = (2 * Math.PI) - start_ang;
if (sweep_ang > 0) {
bClockDirection = true;
}
if (Math.abs(sweep_ang) >= (2 * Math.PI)) {
EllipseOnCanvas(context, _l_c_x + width / 2, _l_c_y + height / 2, width / 2, height / 2);
} else {
EllipseArcOnCanvas(context, _l_c_x + width / 2, _l_c_y + height / 2, width / 2, height / 2, fSrtAngle, fEndAngle, bClockDirection);
}
}
function EllipseOnCanvas(ctx, fX, fY, fXRad, fYRad) {
ctx.moveTo(fX - fXRad, fY);
var c_fKappa = 0.5520000000000001;
ctx.bezierCurveTo(fX - fXRad, fY + fYRad * c_fKappa, fX - fXRad * c_fKappa, fY + fYRad, fX, fY + fYRad);
ctx.bezierCurveTo(fX + fXRad * c_fKappa, fY + fYRad, fX + fXRad, fY + fYRad * c_fKappa, fX + fXRad, fY);
ctx.bezierCurveTo(fX + fXRad, fY - fYRad * c_fKappa, fX + fXRad * c_fKappa, fY - fYRad, fX, fY - fYRad);
ctx.bezierCurveTo(fX - fXRad * c_fKappa, fY - fYRad, fX - fXRad, fY - fYRad * c_fKappa, fX - fXRad, fY);
}
function EllipseArcOnCanvas(ctx, fX, fY, fXRad, fYRad, fAngle1, fAngle2, bClockDirection) {
while (fAngle1 < 0) {
fAngle1 += (2 * Math.PI);
}
while (fAngle1 > (2 * Math.PI)) {
fAngle1 -= (2 * Math.PI);
}
while (fAngle2 < 0) {
fAngle2 += (2 * Math.PI);
}
while (fAngle2 >= (2 * Math.PI)) {
fAngle2 -= (2 * Math.PI);
}
if (!bClockDirection) {
if (fAngle1 <= fAngle2) {
EllipseArc2OnCanvas(ctx, fX, fY, fXRad, fYRad, fAngle1, fAngle2, false);
} else {
EllipseArc2OnCanvas(ctx, fX, fY, fXRad, fYRad, fAngle1, 2 * Math.PI, false);
EllipseArc2OnCanvas(ctx, fX, fY, fXRad, fYRad, 0, fAngle2, false);
}
} else {
if (fAngle1 >= fAngle2) {
EllipseArc2OnCanvas(ctx, fX, fY, fXRad, fYRad, fAngle1, fAngle2, true);
} else {
EllipseArc2OnCanvas(ctx, fX, fY, fXRad, fYRad, fAngle1, 0, true);
EllipseArc2OnCanvas(ctx, fX, fY, fXRad, fYRad, 2 * Math.PI, fAngle2, true);
}
}
}
function EllipseArc2OnCanvas(ctx, fX, fY, fXRad, fYRad, dAngle1, dAngle2, bClockDirection) {
var nFirstPointQuard = ((2 * dAngle1 / Math.PI) >> 0) + 1;
var nSecondPointQuard = ((2 * dAngle2 / Math.PI) >> 0) + 1;
nSecondPointQuard = Math.min(4, Math.max(1, nSecondPointQuard));
nFirstPointQuard = Math.min(4, Math.max(1, nFirstPointQuard));
var fStartX = fX + fXRad * Math.cos(AngToEllPrm(dAngle1, fXRad, fYRad));
var fStartY = fY + fYRad * Math.sin(AngToEllPrm(dAngle1, fXRad, fYRad));
var EndPoint = {
X: 0,
Y: 0
};
ctx.lineTo(fStartX, fStartY);
var fCurX = fStartX,
fCurY = fStartY;
var dStartAngle = dAngle1;
var dEndAngle = 0;
if (!bClockDirection) {
for (var nIndex = nFirstPointQuard; nIndex <= nSecondPointQuard; nIndex++) {
if (nIndex == nSecondPointQuard) {
dEndAngle = dAngle2;
} else {
dEndAngle = nIndex * Math.PI / 2;
}
if (! (nIndex == nFirstPointQuard)) {
dStartAngle = (nIndex - 1) * Math.PI / 2;
}
EndPoint = EllipseArc3OnCanvas(ctx, fX, fY, fXRad, fYRad, AngToEllPrm(dStartAngle, fXRad, fYRad), AngToEllPrm(dEndAngle, fXRad, fYRad), false);
}
} else {
for (var nIndex = nFirstPointQuard; nIndex >= nSecondPointQuard; nIndex--) {
if (nIndex == nFirstPointQuard) {
dStartAngle = dAngle1;
} else {
dStartAngle = nIndex * Math.PI / 2;
}
if (! (nIndex == nSecondPointQuard)) {
dEndAngle = (nIndex - 1) * Math.PI / 2;
} else {
dEndAngle = dAngle2;
}
EndPoint = EllipseArc3OnCanvas(ctx, fX, fY, fXRad, fYRad, AngToEllPrm(dStartAngle, fXRad, fYRad), AngToEllPrm(dEndAngle, fXRad, fYRad), false);
}
}
}
function EllipseArc3OnCanvas(ctx, fX, fY, fXRad, fYRad, dAngle1, dAngle2, bClockDirection) {
var fAlpha = Math.sin(dAngle2 - dAngle1) * (Math.sqrt(4 + 3 * Math.tan((dAngle2 - dAngle1) / 2) * Math.tan((dAngle2 - dAngle1) / 2)) - 1) / 3;
var sin1 = Math.sin(dAngle1);
var cos1 = Math.cos(dAngle1);
var sin2 = Math.sin(dAngle2);
var cos2 = Math.cos(dAngle2);
var fX1 = fX + fXRad * cos1;
var fY1 = fY + fYRad * sin1;
var fX2 = fX + fXRad * cos2;
var fY2 = fY + fYRad * sin2;
var fCX1 = fX1 - fAlpha * fXRad * sin1;
var fCY1 = fY1 + fAlpha * fYRad * cos1;
var fCX2 = fX2 + fAlpha * fXRad * sin2;
var fCY2 = fY2 - fAlpha * fYRad * cos2;
if (!bClockDirection) {
ctx.bezierCurveTo(fCX1, fCY1, fCX2, fCY2, fX2, fY2);
return {
X: fX2,
Y: fY2
};
} else {
ctx.bezierCurveTo(fCX2, fCY2, fCX1, fCY1, fX1, fY1);
return {
X: fX1,
Y: fY1
};
}
}
function _HitToArc(context, px, py, start_x, start_y, width_r, height_r, start_ang, sweep_ang) {
var _sin = Math.sin(start_ang);
var _cos = Math.cos(start_ang);
var _x = _cos / width_r;
var _y = _sin / height_r;
var _l = 1 / Math.sqrt(_x * _x + _y * _y);
var _cx = start_x - _l * _cos;
var _cy = start_y - _l * _sin;
return HitToArc2(px, py, context, _cx - width_r, _cy - height_r, 2 * width_r, 2 * height_r, start_ang, sweep_ang);
}
function HitToArc2(px, py, context, _l_c_x, _l_c_y, width, height, start_ang, sweep_ang) {
if (0 >= width || 0 >= height) {
return;
}
start_ang = -start_ang;
sweep_ang = -sweep_ang;
var bClockDirection = false;
var fEndAngle = (2 * Math.PI) - (sweep_ang + start_ang);
var fSrtAngle = (2 * Math.PI) - start_ang;
if (sweep_ang > 0) {
bClockDirection = true;
}
if (Math.abs(sweep_ang) >= (2 * Math.PI)) {
return HitToEllipseOnCanvas(px, py, context, _l_c_x + width / 2, _l_c_y + height / 2, width / 2, height / 2);
} else {
return HitToEllipseArcOnCanvas(px, py, context, _l_c_x + width / 2, _l_c_y + height / 2, width / 2, height / 2, fSrtAngle, fEndAngle, bClockDirection);
}
}
function HitToEllipseOnCanvas(px, py, ctx, fX, fY, fXRad, fYRad) {
var c_fKappa = 0.5520000000000001;
return HitInBezier4(ctx, px, py, fX - fXRad, fY, fX - fXRad, fY + fYRad * c_fKappa, fX - fXRad * c_fKappa, fY + fYRad, fX, fY + fYRad) || HitInBezier4(ctx, px, py, fX, fY + fYRad, fX + fXRad * c_fKappa, fY + fYRad, fX + fXRad, fY + fYRad * c_fKappa, fX + fXRad, fY) || HitInBezier4(ctx, px, py, fX + fXRad, fY, fX + fXRad, fY - fYRad * c_fKappa, fX + fXRad * c_fKappa, fY - fYRad, fX, fY - fYRad) || HitInBezier4(ctx, px, py, fX, fY - fYRad, fX - fXRad * c_fKappa, fY - fYRad, fX - fXRad, fY - fYRad * c_fKappa, fX - fXRad, fY);
}
function HitToEllipseArcOnCanvas(px, py, ctx, fX, fY, fXRad, fYRad, fAngle1, fAngle2, bClockDirection) {
while (fAngle1 < 0) {
fAngle1 += (2 * Math.PI);
}
while (fAngle1 > (2 * Math.PI)) {
fAngle1 -= (2 * Math.PI);
}
while (fAngle2 < 0) {
fAngle2 += (2 * Math.PI);
}
while (fAngle2 >= (2 * Math.PI)) {
fAngle2 -= (2 * Math.PI);
}
if (!bClockDirection) {
if (fAngle1 <= fAngle2) {
return HitToEllipseArc2OnCanvas(px, py, ctx, fX, fY, fXRad, fYRad, fAngle1, fAngle2, false);
} else {
return HitToEllipseArc2OnCanvas(px, py, ctx, fX, fY, fXRad, fYRad, fAngle1, 2 * Math.PI, false) || HitToEllipseArc2OnCanvas(px, py, ctx, fX, fY, fXRad, fYRad, 0, fAngle2, false);
}
} else {
if (fAngle1 >= fAngle2) {
return HitToEllipseArc2OnCanvas(px, py, ctx, fX, fY, fXRad, fYRad, fAngle1, fAngle2, true);
} else {
return HitToEllipseArc2OnCanvas(px, py, ctx, fX, fY, fXRad, fYRad, fAngle1, 0, true) || HitToEllipseArc2OnCanvas(px, py, ctx, fX, fY, fXRad, fYRad, 2 * Math.PI, fAngle2, true);
}
}
}
function HitToEllipseArc2OnCanvas(px, py, ctx, fX, fY, fXRad, fYRad, dAngle1, dAngle2, bClockDirection) {
var nFirstPointQuard = ((2 * dAngle1 / Math.PI) >> 0) + 1;
var nSecondPointQuard = ((2 * dAngle2 / Math.PI) >> 0) + 1;
nSecondPointQuard = Math.min(4, Math.max(1, nSecondPointQuard));
nFirstPointQuard = Math.min(4, Math.max(1, nFirstPointQuard));
var fStartX = fX + fXRad * Math.cos(AngToEllPrm(dAngle1, fXRad, fYRad));
var fStartY = fY + fYRad * Math.sin(AngToEllPrm(dAngle1, fXRad, fYRad));
var EndPoint = {
X: fStartX,
Y: fStartY,
hit: false
};
var dStartAngle = dAngle1;
var dEndAngle = 0;
if (!bClockDirection) {
for (var nIndex = nFirstPointQuard; nIndex <= nSecondPointQuard; nIndex++) {
if (nIndex == nSecondPointQuard) {
dEndAngle = dAngle2;
} else {
dEndAngle = nIndex * Math.PI / 2;
}
if (! (nIndex == nFirstPointQuard)) {
dStartAngle = (nIndex - 1) * Math.PI / 2;
}
EndPoint = HitToEllipseArc3OnCanvas(px, py, EndPoint, ctx, fX, fY, fXRad, fYRad, AngToEllPrm(dStartAngle, fXRad, fYRad), AngToEllPrm(dEndAngle, fXRad, fYRad), false);
if (EndPoint.hit) {
return true;
}
}
} else {
for (var nIndex = nFirstPointQuard; nIndex >= nSecondPointQuard; nIndex--) {
if (nIndex == nFirstPointQuard) {
dStartAngle = dAngle1;
} else {
dStartAngle = nIndex * Math.PI / 2;
}
if (! (nIndex == nSecondPointQuard)) {
dEndAngle = (nIndex - 1) * Math.PI / 2;
} else {
dEndAngle = dAngle2;
}
EndPoint = HitToEllipseArc3OnCanvas(px, py, EndPoint, ctx, fX, fY, fXRad, fYRad, AngToEllPrm(dStartAngle, fXRad, fYRad), AngToEllPrm(dEndAngle, fXRad, fYRad), false);
if (EndPoint.hit) {
return true;
}
}
}
return false;
}
function HitToEllipseArc3OnCanvas(px, py, EndPoint, ctx, fX, fY, fXRad, fYRad, dAngle1, dAngle2, bClockDirection) {
var fAlpha = Math.sin(dAngle2 - dAngle1) * (Math.sqrt(4 + 3 * Math.tan((dAngle2 - dAngle1) / 2) * Math.tan((dAngle2 - dAngle1) / 2)) - 1) / 3;
var sin1 = Math.sin(dAngle1);
var cos1 = Math.cos(dAngle1);
var sin2 = Math.sin(dAngle2);
var cos2 = Math.cos(dAngle2);
var fX1 = fX + fXRad * cos1;
var fY1 = fY + fYRad * sin1;
var fX2 = fX + fXRad * cos2;
var fY2 = fY + fYRad * sin2;
var fCX1 = fX1 - fAlpha * fXRad * sin1;
var fCY1 = fY1 + fAlpha * fYRad * cos1;
var fCX2 = fX2 + fAlpha * fXRad * sin2;
var fCY2 = fY2 - fAlpha * fYRad * cos2;
if (!bClockDirection) {
return {
X: fX2,
Y: fY2,
hit: HitInBezier4(ctx, px, py, EndPoint.X, EndPoint.Y, fCX1, fCY1, fCX2, fCY2, fX2, fY2)
};
} else {
return {
X: fX1,
Y: fY1,
hit: HitInBezier4(ctx, px, py, EndPoint.X, EndPoint.Y, fCX2, fCY2, fCX1, fCY1, fX1, fY1)
};
}
}
ArcToOnCanvas = _ArcToOnCanvas;
HitToArc = _HitToArc;
})();

View File

@@ -0,0 +1,97 @@
/*
* (c) Copyright Ascensio System SIA 2010-2014
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
function CompareImageProperties(imgProps1, imgProps2) {
var _result_image_properties = {};
if (imgProps1.Width == null || imgProps2.Width == null) {
_result_image_properties.Width = null;
} else {
_result_image_properties.Width = (imgProps1.Width === imgProps2.Width) ? imgProps1.Width : null;
}
if (imgProps1.Height == null || imgProps2.Height == null) {
_result_image_properties.Height = null;
} else {
_result_image_properties.Height = (imgProps1.Height === imgProps2.Height) ? imgProps1.Height : null;
}
_result_image_properties.Paddings = ComparePaddings(imgProps1.Paddings, imgProps2.Paddings);
_result_image_properties.Position = CompareImgPosition(imgProps1.Position, imgProps2.Position);
if (! (typeof imgProps1.ImageUrl === "string") || !(typeof imgProps2.ImageUrl === "string") || imgProps1.ImageUrl !== imgProps2.ImageUrl) {
_result_image_properties.ImageUrl = null;
} else {
_result_image_properties = imgProps1.ImageUrl;
}
_result_image_properties.IsLocked = imgProps1.IsLocked === true || imgProps2.IsLocked === true;
return _result_image_properties;
}
function ComparePaddings(paddings1, paddings2) {
if ((paddings1 === null || !(typeof paddings1 === "object")) || (paddings2 === null || !(typeof paddings2 === "object"))) {
return null;
}
var _result_paddings = {};
if (! (typeof paddings1.Left === "number") && !(typeof paddings2.Left === "number") || (paddings1.Left !== paddings2.Left)) {
_result_paddings.Left = null;
} else {
_result_paddings.Left = paddings1.Left;
}
if (! (typeof paddings1.Top === "number") && !(typeof paddings2.Top === "number") || (paddings1.Top !== paddings2.Top)) {
_result_paddings.Top = null;
} else {
_result_paddings.Top = paddings1.Top;
}
if (! (typeof paddings1.Right === "number") && !(typeof paddings2.Right === "number") || (paddings1.Right !== paddings2.Right)) {
_result_paddings.Right = null;
} else {
_result_paddings.Right = paddings1.Right;
}
if (! (typeof paddings1.Bottom === "number") && !(typeof paddings2.Bottom === "number") || (paddings1.Bottom !== paddings2.Bottom)) {
_result_paddings.Bottom = null;
} else {
_result_paddings.Bottom = paddings1.Bottom;
}
return _result_paddings;
}
function CompareImgPosition(pos1, pos2) {
if ((pos1 === null || !(typeof pos1 === "object")) || (pos2 === null || !(typeof pos2 === "object"))) {
return null;
}
var _result_position = {};
if (! (typeof pos1.X === "number") && !(typeof pos1.X === "number") || (pos1.X !== pos1.X)) {
_result_position.X = null;
} else {
_result_position.X = pos1.X;
}
if (! (typeof pos1.Y === "number") && !(typeof pos1.Y === "number") || (pos1.Y !== pos1.Y)) {
_result_position.Y = null;
} else {
_result_position.Y = pos1.Y;
}
return _result_position;
}

View File

@@ -0,0 +1,127 @@
/*
* (c) Copyright Ascensio System SIA 2010-2014
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
function clone(obj) {
if (obj == null || typeof(obj) != "object") {
return obj;
}
if (obj.constructor == Array) {
var clonedArray = [];
for (var i = 0, length = obj.length; i < length; ++i) {
clonedArray[i] = clone(obj[i]);
}
return clonedArray;
}
var clonedObject = {};
var copyFunc = function (obj) {
return obj;
};
var nullFunc = function (obj) {
return null;
};
var undefinedFunc = function (obj) {
return undefined;
};
var FuncMap = {
Parent: copyFunc,
DrawingDocument: copyFunc,
Document: copyFunc,
Container: copyFunc,
parent: copyFunc,
slide: copyFunc,
slideLayout: copyFunc,
LogicDocument: copyFunc,
table: nullFunc,
txBody: undefinedFunc,
graphicObject: nullFunc
};
for (var key in obj) {
if (undefined !== FuncMap[key]) {
clonedObject[key] = FuncMap[key](obj[key]);
} else {
clonedObject[key] = clone(obj[key]);
}
if (clonedObject.IsGroup && clonedObject.IsGroup()) {
for (i = 0; i < clonedObject.ArrGlyph.length; ++i) {
clonedObject.ArrGlyph[i].Container = clonedObject;
}
}
}
return clonedObject;
}
function cloneDC(obj) {
if (obj == null || typeof(obj) != "object") {
return obj;
}
if (obj.constructor == Array) {
var t = [];
for (var i = 0; i < obj.length; ++i) {
t[i] = clone(obj[i]);
}
return t;
}
var temp = {};
var copyFunc = function (obj) {
return obj;
};
var FuncMap = {
Parent: copyFunc,
DrawingDocument: copyFunc,
Document: copyFunc,
DocumentContent: copyFunc,
Container: copyFunc
};
for (var key in obj) {
if (undefined !== FuncMap[key]) {
temp[key] = FuncMap[key](obj[key]);
} else {
temp[key] = clone(obj[key]);
}
}
return temp;
}
function clonePrototype(obj) {
if (obj == null || typeof(obj) != "object") {
return obj;
}
if (obj.constructor == Array) {
var clonedArray = [];
for (var i = 0; i < obj.length; ++i) {
clonedArray[i] = clone(obj[i]);
}
return clonedArray;
}
var clonedObj = {};
for (var key in obj) {
clonedObj[key] = clone(obj[key]);
}
return clonedObj;
}

View File

@@ -0,0 +1,136 @@
/*
* (c) Copyright Ascensio System SIA 2010-2014
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
function CShapeColor(r, g, b) {
this.r = r;
this.g = g;
this.b = b;
this.darken = function () {
var hslColor = RGBToHSL(this);
hslColor.l *= 0.9;
return HSLToRGB(hslColor);
};
this.darkenLess = function () {
var hslColor = RGBToHSL(this);
hslColor.l *= 0.85;
return HSLToRGB(hslColor);
};
this.lighten = function () {
var hslColor = RGBToHSL(this);
hslColor.l *= 1.1;
if (hslColor.l > 1) {
hslColor.l = 1;
}
return HSLToRGB(hslColor);
};
this.lightenLess = function () {
var hslColor = RGBToHSL(this);
hslColor.l *= 1.1;
if (hslColor.l > 1) {
hslColor.l = 1;
}
return HSLToRGB(hslColor);
};
this.norm = function (a) {
return this;
};
}
function RGBToHSL(RGBColor) {
var r, g, b;
r = RGBColor.r / 255;
g = RGBColor.g / 255;
b = RGBColor.b / 255;
var max, min;
max = Math.max(r, g, b);
min = Math.min(r, g, b);
var h, s, l;
h = max === min ? 0 : (max == r && g >= b) ? 60 * (g - b) / (max - min) : (max == r && g < b) ? 60 * (g - b) / (max - min) + 360 : (max == g) ? 60 * (b - r) / (max - min) + 120 : 60 * (r - g) / (max - min) + 240;
l = (max + min) * 0.5;
s = l > 0.5 ? (max - min) / (2 - max - min) : (max - min) / (max + min);
while (h < 0) {
h += 360;
}
while (h >= 360) {
h -= 360;
}
return {
h: h,
s: s,
l: l
};
}
function HSLToRGB(HSLColor) {
var h, s, l, r, g, b;
h = HSLColor.h / 360;
s = HSLColor.s;
l = HSLColor.l;
var q, p, tr, tg, tb;
q = l < 0.5 ? (l * (1 + s)) : l + s - l * s;
p = 2 * l - q;
tr = h + 1 / 3;
tg = h;
tb = h - 1 / 3;
if (tr < 0) {
tr += 1;
}
if (tr > 1) {
tr -= 1;
}
if (tg < 0) {
tg += 1;
}
if (tg > 1) {
tg -= 1;
}
if (tb < 0) {
tb += 1;
}
if (tb > 1) {
tb -= 1;
}
r = Math.round(255 * (tr < 1 / 6 ? p + ((q - p) * 6 * tr) : (1 / 6 < tr && tr < 1 / 2) ? q : (1 / 2 < tr && tr < 2 / 3) ? (p + ((q - p) * (2 / 3 - tr) * 6)) : p));
g = Math.round(255 * (tg < 1 / 6 ? p + ((q - p) * 6 * tg) : (1 / 6 < tg && tg < 1 / 2) ? q : (1 / 2 < tg && tg < 2 / 3) ? (p + ((q - p) * (2 / 3 - tg) * 6)) : p));
b = Math.round(255 * (tb < 1 / 6 ? p + ((q - p) * 6 * tb) : (1 / 6 < tb && tb < 1 / 2) ? q : (1 / 2 < tb && tb < 2 / 3) ? (p + ((q - p) * (2 / 3 - tb) * 6)) : p));
if (r > 255) {
r = 255;
}
if (g > 255) {
g = 255;
}
if (b > 255) {
b = 255;
}
return {
r: r,
g: g,
b: b
};
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,59 @@
/*
* (c) Copyright Ascensio System SIA 2010-2014
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
function circle(graphics, xc, yc, r) {
graphics._s();
ArcToCurvers(graphics, xc + r, yc, r, r, 0, 2 * Math.PI);
graphics._z();
graphics.ds();
graphics.df();
}
function diamond(graphics, xc, yc, d) {
d *= 0.5;
graphics._s();
graphics._m(xc, yc - d);
graphics._l(xc + d, yc);
graphics._l(xc, yc + d);
graphics._l(xc - d, yc);
graphics._z();
graphics.ds();
graphics.df();
}
function square(graphics, xc, yc, d) {
graphics._s();
graphics._m(xc - d, yc - d);
graphics._l(xc + d, yc - d);
graphics._l(xc + d, yc + d);
graphics._l(xc - d, yc + d);
graphics._z();
graphics.ds();
graphics.df();
}

View File

@@ -0,0 +1,79 @@
/*
* (c) Copyright Ascensio System SIA 2010-2014
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
function HitInLine(context, px, py, x0, y0, x1, y1) {
var tx, ty, dx, dy, d;
tx = x1 - x0;
ty = y1 - y0;
d = 1.5 / Math.sqrt(tx * tx + ty * ty);
dx = -ty * d;
dy = tx * d;
context.beginPath();
context.moveTo(x0, y0);
context.lineTo(x0 + dx, y0 + dy);
context.lineTo(x1 + dx, y1 + dy);
context.lineTo(x1 - dx, y1 - dy);
context.lineTo(x0 - dx, y0 - dy);
context.closePath();
return context.isPointInPath(px, py);
}
function HitInBezier4(context, px, py, x0, y0, x1, y1, x2, y2, x3, y3) {
var tx, ty, dx, dy, d;
tx = x3 - x0;
ty = y3 - y0;
d = 1.5 / Math.sqrt(tx * tx + ty * ty);
dx = -ty * d;
dy = tx * d;
context.beginPath();
context.moveTo(x0, y0);
context.lineTo(x0 + dx, y0 + dy);
context.bezierCurveTo(x1 + dx, y1 + dy, x2 + dx, y2 + dy, x3 + dx, y3 + dy);
context.lineTo(x3 - dx, y3 - dy);
context.bezierCurveTo(x2 - dx, y2 - dy, x1 - dx, y1 - dy, x0 - dx, y0 - dy);
context.closePath();
return context.isPointInPath(px, py);
}
function HitInBezier3(context, px, py, x0, y0, x1, y1, x2, y2) {
var tx, ty, dx, dy, d;
tx = x2 - x0;
ty = y2 - y0;
d = 1.5 / Math.sqrt(tx * tx + ty * ty);
dx = -ty * d;
dy = tx * d;
context.beginPath();
context.moveTo(x0, y0);
context.lineTo(x0 + dx, y0 + dy);
context.quadraticCurveTo(x1 + dx, y1 + dy, x2 + dx, y2 + dy);
context.lineTo(x2 - dx, y2 - dy);
context.quadraticCurveTo(x1 - dx, y1 - dy, x0 - dx, y0 - dy);
context.closePath();
return context.isPointInPath(px, py);
}

View File

@@ -0,0 +1,108 @@
/*
* (c) Copyright Ascensio System SIA 2010-2014
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
var min_distance_joined = 2;
function JoinedH(shape1, shape2) {
var l, r, l2, r2;
l = shape1.x;
r = l + shape1.extX;
l2 = shape2.x;
r2 = l2 + shape2.extX;
var d = l - l2;
if (Math.abs(d) < min_distance_joined) {
return d;
}
d = l - r2;
if (Math.abs(d) < min_distance_joined) {
return d;
}
d = r - l2;
if (Math.abs(d) < min_distance_joined) {
return d;
}
d = r - r2;
if (Math.abs(d) < min_distance_joined) {
return d;
}
return 0;
}
function JoinedV(shape1, shape2) {
var t, b, t2, b2;
t = shape1.y;
b = t + shape1.extY;
t2 = shape2.y;
b2 = t2 + shape2.extY;
var d = t - t2;
if (Math.abs(d) < min_distance_joined) {
return d;
}
d = t - b2;
if (Math.abs(d) < min_distance_joined) {
return d;
}
d = b - t2;
if (Math.abs(d) < min_distance_joined) {
return d;
}
d = b - b2;
if (Math.abs(d) < min_distance_joined) {
return d;
}
return 0;
}
function JoinedPointH(X, shape2) {
var l2, r2;
l2 = shape2.x;
r2 = l2 + shape2.extX;
var d = X - l2;
if (Math.abs(d) < min_distance_joined) {
return d;
}
d = X - r2;
if (Math.abs(d) < min_distance_joined) {
return d;
}
return 0;
}
function JoinedPointV(Y, shape2) {
var t2, b2;
t2 = shape2.y;
b2 = t2 + shape2.extY;
var d = Y - t2;
if (Math.abs(d) < min_distance_joined) {
return d;
}
d = Y - b2;
if (Math.abs(d) < min_distance_joined) {
return d;
}
return 0;
}

View File

@@ -0,0 +1,54 @@
/*
* (c) Copyright Ascensio System SIA 2010-2014
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
var cToRad = Math.PI / (60000 * 180);
var cToDeg = 1 / cToRad;
function Cos(angle) {
return Math.cos(cToRad * angle);
}
function Sin(angle) {
return Math.sin(cToRad * angle);
}
function Tan(angle) {
return Math.tan(cToRad * angle);
}
function ATan(x) {
return cToDeg * Math.atan(x);
}
function ATan2(y, x) {
return cToDeg * Math.atan2(y, x);
}
function CAt2(x, y, z) {
return x * (Cos(ATan2(z, y)));
}
function SAt2(x, y, z) {
return x * (Sin(ATan2(z, y)));
}

View File

@@ -0,0 +1,974 @@
/*
* (c) Copyright Ascensio System SIA 2010-2014
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
var moveTo = 0,
lineTo = 1,
arcTo = 2,
bezier3 = 3,
bezier4 = 4,
close = 5;
var PATH_COMMAND_START = 257;
var PATH_COMMAND_END = 258;
var cToRad = Math.PI / 10800000;
var cToDeg = 1 / cToRad;
function Path(extrusionOk, fill, stroke, w, h) {
if (stroke != undefined) {
this.stroke = stroke;
} else {
this.stroke = true;
}
this.extrusionOk = extrusionOk || false;
this.fill = fill || "norm";
this.pathW = w;
this.pathH = h;
if (this.pathW != undefined) {
this.divPW = 1 / w;
}
if (this.pathH != undefined) {
this.divPH = 1 / h;
}
this.ArrPathCommandInfo = new Array();
this.ArrPathCommand = new Array();
this.createDuplicate = function () {
var duplicate = new Path(this.extrusionOk, this.fill, this.stroke, this.pathW, this.pathH);
for (var i = 0; i < this.ArrPathCommandInfo.length; ++i) {
duplicate.ArrPathCommandInfo[i] = clonePrototype(this.ArrPathCommandInfo[i]);
}
return duplicate;
};
}
Path.prototype = {
getObjectType: function () {
return CLASS_TYPE_PATH;
},
Write_ToBinary2: function (writer) {
writer.WriteBool(this.stroke);
writer.WriteBool(this.extrusionOk);
writer.WriteString2(this.fill);
var flag = this.pathW != undefined;
writer.WriteBool(flag);
if (flag) {
writer.WriteLong(this.pathW);
}
flag = this.pathH != undefined;
writer.WriteBool(flag);
if (flag) {
writer.WriteLong(this.pathH);
}
flag = this.divPW != undefined;
writer.WriteBool(flag);
if (flag) {
writer.WriteDouble(this.divPW);
}
flag = this.divPH != undefined;
writer.WriteBool(flag);
if (flag) {
writer.WriteDouble(this.divPH);
}
var path_command_count = this.ArrPathCommandInfo.length;
writer.WriteLong(path_command_count);
var write_function = writer.WriteString2;
for (var index = 0; index < path_command_count; ++index) {
var c = this.ArrPathCommandInfo[index];
switch (c.id) {
case moveTo:
case lineTo:
writer.WriteLong(c.id);
write_function.call(writer, c.X);
write_function.call(writer, c.Y);
break;
case bezier3:
writer.WriteLong(c.id);
write_function.call(writer, c.X0);
write_function.call(writer, c.Y0);
write_function.call(writer, c.X1);
write_function.call(writer, c.Y1);
break;
case bezier4:
writer.WriteLong(c.id);
write_function.call(writer, c.X0);
write_function.call(writer, c.Y0);
write_function.call(writer, c.X1);
write_function.call(writer, c.Y1);
write_function.call(writer, c.X2);
write_function.call(writer, c.Y2);
break;
case arcTo:
writer.WriteLong(c.id);
write_function.call(writer, c.hR);
write_function.call(writer, c.wR);
write_function.call(writer, c.stAng);
write_function.call(writer, c.swAng);
break;
case close:
writer.WriteLong(c.id);
break;
}
}
for (index = 0; index < path_command_count; ++index) {
WriteObjectLong(writer, this.ArrPathCommand[index]);
}
},
Read_FromBinary2: function (Reader) {
this.stroke = Reader.GetBool();
this.extrusionOk = Reader.GetBool();
this.fill = Reader.GetString2();
var flag = Reader.GetBool();
if (flag) {
this.pathW = Reader.GetLong();
}
flag = Reader.GetBool();
if (flag) {
this.pathH = Reader.GetLong();
}
flag = Reader.GetBool();
if (flag) {
this.divPW = Reader.GetDouble();
}
flag = Reader.GetBool();
if (flag) {
this.divPH = Reader.GetDouble();
}
if (typeof this.pathW === "number") {
this.divPW = 1 / this.pathW;
}
if (typeof this.pathH === "number") {
this.divPH = 1 / this.pathH;
}
var path_command_count = Reader.GetLong();
var read_function = Reader.GetString2;
for (var index = 0; index < path_command_count; ++index) {
var c = {};
var id = Reader.GetLong();
c.id = id;
switch (id) {
case moveTo:
case lineTo:
c.X = read_function.call(Reader);
c.Y = read_function.call(Reader);
break;
case bezier3:
c.X0 = read_function.call(Reader);
c.Y0 = read_function.call(Reader);
c.X1 = read_function.call(Reader);
c.Y1 = read_function.call(Reader);
break;
case bezier4:
c.X0 = read_function.call(Reader);
c.Y0 = read_function.call(Reader);
c.X1 = read_function.call(Reader);
c.Y1 = read_function.call(Reader);
c.X2 = read_function.call(Reader);
c.Y2 = read_function.call(Reader);
break;
case arcTo:
c.hR = read_function.call(Reader);
c.wR = read_function.call(Reader);
c.stAng = read_function.call(Reader);
c.swAng = read_function.call(Reader);
break;
case close:
break;
}
for (var key in c) {
if (!isNaN(parseInt(c[key], 10))) {
c[key] = parseInt(c[key], 10);
}
}
this.ArrPathCommandInfo.push(c);
}
for (index = 0; index < path_command_count; ++index) {
this.ArrPathCommand[index] = ReadObjectLong(Reader);
}
},
moveTo: function (x, y) {
if (!isNaN(parseInt(x, 10))) {
x = parseInt(x, 10);
}
if (!isNaN(parseInt(y, 10))) {
y = parseInt(y, 10);
}
this.ArrPathCommandInfo.push({
id: moveTo,
X: x,
Y: y
});
},
lnTo: function (x, y) {
if (!isNaN(parseInt(x, 10))) {
x = parseInt(x, 10);
}
if (!isNaN(parseInt(y, 10))) {
y = parseInt(y, 10);
}
this.ArrPathCommandInfo.push({
id: lineTo,
X: x,
Y: y
});
},
arcTo: function (wR, hR, stAng, swAng) {
if (!isNaN(parseInt(wR, 10))) {
wR = parseInt(wR, 10);
}
if (!isNaN(parseInt(hR, 10))) {
hR = parseInt(hR, 10);
}
if (!isNaN(parseInt(stAng, 10))) {
stAng = parseInt(stAng, 10);
}
if (!isNaN(parseInt(swAng, 10))) {
swAng = parseInt(swAng, 10);
}
this.ArrPathCommandInfo.push({
id: arcTo,
wR: wR,
hR: hR,
stAng: stAng,
swAng: swAng
});
},
quadBezTo: function (x0, y0, x1, y1) {
if (!isNaN(parseInt(x0, 10))) {
x0 = parseInt(x0, 10);
}
if (!isNaN(parseInt(y0, 10))) {
y0 = parseInt(y0, 10);
}
if (!isNaN(parseInt(x1, 10))) {
x1 = parseInt(x1, 10);
}
if (!isNaN(parseInt(y1, 10))) {
y1 = parseInt(y1, 10);
}
this.ArrPathCommandInfo.push({
id: bezier3,
X0: x0,
Y0: y0,
X1: x1,
Y1: y1
});
},
cubicBezTo: function (x0, y0, x1, y1, x2, y2) {
if (!isNaN(parseInt(x0, 10))) {
x0 = parseInt(x0, 10);
}
if (!isNaN(parseInt(y0, 10))) {
y0 = parseInt(y0, 10);
}
if (!isNaN(parseInt(x1, 10))) {
x1 = parseInt(x1, 10);
}
if (!isNaN(parseInt(y1, 10))) {
y1 = parseInt(y1, 10);
}
if (!isNaN(parseInt(x2, 10))) {
x2 = parseInt(x2, 10);
}
if (!isNaN(parseInt(y2, 10))) {
y2 = parseInt(y2, 10);
}
this.ArrPathCommandInfo.push({
id: bezier4,
X0: x0,
Y0: y0,
X1: x1,
Y1: y1,
X2: x2,
Y2: y2
});
},
close: function () {
this.ArrPathCommandInfo.push({
id: close
});
},
init: function (gdLst) {
if (this.ArrPathCommandInfo.length === this.ArrPathCommand.length) {
this.ArrPathCommand.length = 0;
}
var ch, cw;
if (this.pathW != undefined) {
cw = (gdLst["w"] / this.pathW);
} else {
cw = 1;
}
if (this.pathH != undefined) {
ch = (gdLst["h"] / this.pathH);
} else {
ch = 1;
}
var APCI = this.ArrPathCommandInfo,
n = APCI.length,
cmd;
var x0, y0, x1, y1, x2, y2, wR, hR, stAng, swAng, lastX, lastY;
for (var i = 0; i < n; i++) {
cmd = APCI[i];
switch (cmd.id) {
case moveTo:
case lineTo:
x0 = parseInt(cmd.X);
if (isNaN(x0)) {
x0 = gdLst[cmd.X];
}
y0 = parseInt(cmd.Y);
if (isNaN(y0)) {
y0 = gdLst[cmd.Y];
}
this.ArrPathCommand.push({
id: cmd.id,
X: x0 * cw,
Y: y0 * ch
});
lastX = x0 * cw;
lastY = y0 * ch;
break;
case bezier3:
x0 = parseInt(cmd.X0);
if (isNaN(x0)) {
x0 = gdLst[cmd.X0];
}
y0 = parseInt(cmd.Y0);
if (isNaN(y0)) {
y0 = gdLst[cmd.Y0];
}
x1 = parseInt(cmd.X1);
if (isNaN(x1)) {
x1 = gdLst[cmd.X1];
}
y1 = parseInt(cmd.Y1);
if (isNaN(y1)) {
y1 = gdLst[cmd.Y1];
}
this.ArrPathCommand.push({
id: bezier3,
X0: x0 * cw,
Y0: y0 * ch,
X1: x1 * cw,
Y1: y1 * ch
});
lastX = x1 * cw;
lastY = y1 * ch;
break;
case bezier4:
x0 = parseInt(cmd.X0);
if (isNaN(x0)) {
x0 = gdLst[cmd.X0];
}
y0 = parseInt(cmd.Y0);
if (isNaN(y0)) {
y0 = gdLst[cmd.Y0];
}
x1 = parseInt(cmd.X1);
if (isNaN(x1)) {
x1 = gdLst[cmd.X1];
}
y1 = parseInt(cmd.Y1);
if (isNaN(y1)) {
y1 = gdLst[cmd.Y1];
}
x2 = parseInt(cmd.X2);
if (isNaN(x2)) {
x2 = gdLst[cmd.X2];
}
y2 = parseInt(cmd.Y2);
if (isNaN(y2)) {
y2 = gdLst[cmd.Y2];
}
this.ArrPathCommand.push({
id: bezier4,
X0: x0 * cw,
Y0: y0 * ch,
X1: x1 * cw,
Y1: y1 * ch,
X2: x2 * cw,
Y2: y2 * ch
});
lastX = x2 * cw;
lastY = y2 * ch;
break;
case arcTo:
hR = parseInt(cmd.hR);
if (isNaN(hR)) {
hR = gdLst[cmd.hR];
}
wR = parseInt(cmd.wR);
if (isNaN(wR)) {
wR = gdLst[cmd.wR];
}
stAng = parseInt(cmd.stAng);
if (isNaN(stAng)) {
stAng = gdLst[cmd.stAng];
}
swAng = parseInt(cmd.swAng);
if (isNaN(swAng)) {
swAng = gdLst[cmd.swAng];
}
var a1 = stAng;
var a2 = stAng + swAng;
var a3 = swAng;
stAng = Math.atan2(ch * Math.sin(a1 * cToRad), cw * Math.cos(a1 * cToRad)) / cToRad;
swAng = Math.atan2(ch * Math.sin(a2 * cToRad), cw * Math.cos(a2 * cToRad)) / cToRad - stAng;
if ((swAng > 0) && (a3 < 0)) {
swAng -= 21600000;
}
if ((swAng < 0) && (a3 > 0)) {
swAng += 21600000;
}
if (swAng == 0) {
swAng = 21600000;
}
var a = wR * cw;
var b = hR * ch;
var sin2 = Math.sin(stAng * cToRad);
var cos2 = Math.cos(stAng * cToRad);
var _xrad = cos2 / a;
var _yrad = sin2 / b;
var l = 1 / Math.sqrt(_xrad * _xrad + _yrad * _yrad);
var xc = lastX - l * cos2;
var yc = lastY - l * sin2;
var sin1 = Math.sin((stAng + swAng) * cToRad);
var cos1 = Math.cos((stAng + swAng) * cToRad);
var _xrad1 = cos1 / a;
var _yrad1 = sin1 / b;
var l1 = 1 / Math.sqrt(_xrad1 * _xrad1 + _yrad1 * _yrad1);
this.ArrPathCommand[i] = {
id: arcTo,
stX: lastX,
stY: lastY,
wR: wR * cw,
hR: hR * ch,
stAng: stAng * cToRad,
swAng: swAng * cToRad
};
lastX = xc + l1 * cos1;
lastY = yc + l1 * sin1;
break;
case close:
this.ArrPathCommand.push({
id: close
});
break;
default:
break;
}
}
},
recalculate: function (gdLst) {
var ch, cw;
if (this.pathW != undefined) {
cw = (gdLst["w"] / this.pathW);
} else {
cw = 1;
}
if (this.pathH != undefined) {
ch = (gdLst["h"] / this.pathH);
} else {
ch = 1;
}
var APCI = this.ArrPathCommandInfo,
n = APCI.length,
cmd;
var x0, y0, x1, y1, x2, y2, wR, hR, stAng, swAng, lastX, lastY;
for (var i = 0; i < n; ++i) {
cmd = APCI[i];
switch (cmd.id) {
case moveTo:
case lineTo:
x0 = gdLst[cmd.X];
if (x0 === undefined) {
x0 = cmd.X;
}
y0 = gdLst[cmd.Y];
if (y0 === undefined) {
y0 = cmd.Y;
}
this.ArrPathCommand[i] = {
id: cmd.id,
X: x0 * cw,
Y: y0 * ch
};
lastX = x0 * cw;
lastY = y0 * ch;
break;
case bezier3:
x0 = gdLst[cmd.X0];
if (x0 === undefined) {
x0 = cmd.X0;
}
y0 = gdLst[cmd.Y0];
if (y0 === undefined) {
y0 = cmd.Y0;
}
x1 = gdLst[cmd.X1];
if (x1 === undefined) {
x1 = cmd.X1;
}
y1 = gdLst[cmd.Y1];
if (y1 === undefined) {
y1 = cmd.Y1;
}
this.ArrPathCommand[i] = {
id: bezier3,
X0: x0 * cw,
Y0: y0 * ch,
X1: x1 * cw,
Y1: y1 * ch
};
lastX = x1 * cw;
lastY = y1 * ch;
break;
case bezier4:
x0 = gdLst[cmd.X0];
if (x0 === undefined) {
x0 = cmd.X0;
}
y0 = gdLst[cmd.Y0];
if (y0 === undefined) {
y0 = cmd.Y0;
}
x1 = gdLst[cmd.X1];
if (x1 === undefined) {
x1 = cmd.X1;
}
y1 = gdLst[cmd.Y1];
if (y1 === undefined) {
y1 = cmd.Y1;
}
x2 = gdLst[cmd.X2];
if (x2 === undefined) {
x2 = cmd.X2;
}
y2 = gdLst[cmd.Y2];
if (y2 === undefined) {
y2 = cmd.Y2;
}
this.ArrPathCommand[i] = {
id: bezier4,
X0: x0 * cw,
Y0: y0 * ch,
X1: x1 * cw,
Y1: y1 * ch,
X2: x2 * cw,
Y2: y2 * ch
};
lastX = x2 * cw;
lastY = y2 * ch;
break;
case arcTo:
hR = gdLst[cmd.hR];
if (hR === undefined) {
hR = cmd.hR;
}
wR = gdLst[cmd.wR];
if (wR === undefined) {
wR = cmd.wR;
}
stAng = gdLst[cmd.stAng];
if (stAng === undefined) {
stAng = cmd.stAng;
}
swAng = gdLst[cmd.swAng];
if (swAng === undefined) {
swAng = cmd.swAng;
}
var a1 = stAng;
var a2 = stAng + swAng;
var a3 = swAng;
stAng = Math.atan2(ch * Math.sin(a1 * cToRad), cw * Math.cos(a1 * cToRad)) / cToRad;
swAng = Math.atan2(ch * Math.sin(a2 * cToRad), cw * Math.cos(a2 * cToRad)) / cToRad - stAng;
if ((swAng > 0) && (a3 < 0)) {
swAng -= 21600000;
}
if ((swAng < 0) && (a3 > 0)) {
swAng += 21600000;
}
if (swAng == 0) {
swAng = 21600000;
}
var a = wR * cw;
var b = hR * ch;
var sin2 = Math.sin(stAng * cToRad);
var cos2 = Math.cos(stAng * cToRad);
var _xrad = cos2 / a;
var _yrad = sin2 / b;
var l = 1 / Math.sqrt(_xrad * _xrad + _yrad * _yrad);
var xc = lastX - l * cos2;
var yc = lastY - l * sin2;
var sin1 = Math.sin((stAng + swAng) * cToRad);
var cos1 = Math.cos((stAng + swAng) * cToRad);
var _xrad1 = cos1 / a;
var _yrad1 = sin1 / b;
var l1 = 1 / Math.sqrt(_xrad1 * _xrad1 + _yrad1 * _yrad1);
this.ArrPathCommand[i] = {
id: arcTo,
stX: lastX,
stY: lastY,
wR: wR * cw,
hR: hR * ch,
stAng: stAng * cToRad,
swAng: swAng * cToRad
};
lastX = xc + l1 * cos1;
lastY = yc + l1 * sin1;
break;
case close:
this.ArrPathCommand[i] = {
id: close
};
break;
default:
break;
}
}
},
draw: function (shape_drawer) {
if (shape_drawer.bIsCheckBounds === true && this.fill == "none") {
return;
}
var bIsDrawLast = false;
var path = this.ArrPathCommand;
shape_drawer._s();
for (var j = 0, l = path.length; j < l; ++j) {
var cmd = path[j];
switch (cmd.id) {
case moveTo:
bIsDrawLast = true;
shape_drawer._m(cmd.X, cmd.Y);
break;
case lineTo:
bIsDrawLast = true;
shape_drawer._l(cmd.X, cmd.Y);
break;
case bezier3:
bIsDrawLast = true;
shape_drawer._c2(cmd.X0, cmd.Y0, cmd.X1, cmd.Y1);
break;
case bezier4:
bIsDrawLast = true;
shape_drawer._c(cmd.X0, cmd.Y0, cmd.X1, cmd.Y1, cmd.X2, cmd.Y2);
break;
case arcTo:
bIsDrawLast = true;
ArcToCurvers(shape_drawer, cmd.stX, cmd.stY, cmd.wR, cmd.hR, cmd.stAng, cmd.swAng);
break;
case close:
shape_drawer._z();
break;
}
}
if (bIsDrawLast) {
shape_drawer.drawFillStroke(true, this.fill, this.stroke && !shape_drawer.bIsNoStrokeAttack);
}
shape_drawer._e();
},
check_bounds: function (checker) {
var path = this.ArrPathCommand;
for (var j = 0, l = path.length; j < l; ++j) {
var cmd = path[j];
switch (cmd.id) {
case moveTo:
checker._m(cmd.X, cmd.Y);
break;
case lineTo:
checker._l(cmd.X, cmd.Y);
break;
case bezier3:
checker._c2(cmd.X0, cmd.Y0, cmd.X1, cmd.Y1);
break;
case bezier4:
checker._c(cmd.X0, cmd.Y0, cmd.X1, cmd.Y1, cmd.X2, cmd.Y2);
break;
case arcTo:
ArcToCurvers(checker, cmd.stX, cmd.stY, cmd.wR, cmd.hR, cmd.stAng, cmd.swAng);
break;
case close:
checker._z();
break;
}
}
},
hitInInnerArea: function (canvasContext, x, y) {
if (this.fill === "none") {
return false;
}
var _arr_commands = this.ArrPathCommand;
var _commands_count = _arr_commands.length;
var _command_index;
var _command;
canvasContext.beginPath();
for (_command_index = 0; _command_index < _commands_count; ++_command_index) {
_command = _arr_commands[_command_index];
switch (_command.id) {
case moveTo:
canvasContext.moveTo(_command.X, _command.Y);
break;
case lineTo:
canvasContext.lineTo(_command.X, _command.Y);
break;
case arcTo:
ArcToOnCanvas(canvasContext, _command.stX, _command.stY, _command.wR, _command.hR, _command.stAng, _command.swAng);
break;
case bezier3:
canvasContext.quadraticCurveTo(_command.X0, _command.Y0, _command.X1, _command.Y1);
break;
case bezier4:
canvasContext.bezierCurveTo(_command.X0, _command.Y0, _command.X1, _command.Y1, _command.X2, _command.Y2);
break;
case close:
canvasContext.closePath();
if (canvasContext.isPointInPath(x, y)) {
return true;
}
}
}
return false;
},
hitInPath: function (canvasContext, x, y) {
var _arr_commands = this.ArrPathCommand;
var _commands_count = _arr_commands.length;
var _command_index;
var _command;
var _last_x, _last_y;
var _begin_x, _begin_y;
for (_command_index = 0; _command_index < _commands_count; ++_command_index) {
_command = _arr_commands[_command_index];
switch (_command.id) {
case moveTo:
_last_x = _command.X;
_last_y = _command.Y;
_begin_x = _command.X;
_begin_y = _command.Y;
break;
case lineTo:
if (HitInLine(canvasContext, x, y, _last_x, _last_y, _command.X, _command.Y)) {
return true;
}
_last_x = _command.X;
_last_y = _command.Y;
break;
case arcTo:
if (HitToArc(canvasContext, x, y, _command.stX, _command.stY, _command.wR, _command.hR, _command.stAng, _command.swAng)) {
return true;
}
_last_x = (_command.stX - _command.wR * Math.cos(_command.stAng) + _command.wR * Math.cos(_command.swAng));
_last_y = (_command.stY - _command.hR * Math.sin(_command.stAng) + _command.hR * Math.sin(_command.swAng));
break;
case bezier3:
if (HitInBezier3(canvasContext, x, y, _last_x, _last_y, _command.X0, _command.Y0, _command.X1, _command.Y1)) {
return true;
}
_last_x = _command.X1;
_last_y = _command.Y1;
break;
case bezier4:
if (HitInBezier4(canvasContext, x, y, _last_x, _last_y, _command.X0, _command.Y0, _command.X1, _command.Y1, _command.X2, _command.Y2)) {
return true;
}
_last_x = _command.X2;
_last_y = _command.Y2;
break;
case close:
if (HitInLine(canvasContext, x, y, _last_x, _last_y, _begin_x, _begin_y)) {
return true;
}
}
}
return false;
},
calculateWrapPolygon: function (epsilon, graphics) {
var arr_polygons = [];
var cur_polygon = [];
var path_commands = this.ArrPathCommand;
var path_commands_count = path_commands.length;
var last_x, last_y;
for (var index = 0; index < path_commands_count; ++index) {
var cur_command = path_commands[index];
switch (cur_command.id) {
case moveTo:
case lineTo:
cur_polygon.push({
x: cur_command.X,
y: cur_command.Y
});
last_x = cur_command.X;
last_y = cur_command.Y;
break;
case bezier3:
cur_polygon = cur_polygon.concat(partition_bezier3(last_x, last_y, cur_command.X0, cur_command.Y0, cur_command.X1, cur_command.Y1, epsilon));
last_x = cur_command.X1;
last_y = cur_command.Y1;
break;
case bezier4:
cur_polygon = cur_polygon.concat(partition_bezier4(last_x, last_y, cur_command.X0, cur_command.Y0, cur_command.X1, cur_command.Y1, cur_command.X2, cur_command.Y2, epsilon));
last_x = cur_command.X2;
last_y = cur_command.Y2;
break;
case arcTo:
var arr_curve_bezier = getArrayPointsCurveBezierAtArcTo(last_x, last_y, cur_command.stX, cur_command.stY, cur_command.wR, cur_command.hR, cur_command.stAng, cur_command.swAng);
if (arr_curve_bezier.length > 0) {
last_x = arr_curve_bezier[arr_curve_bezier.length - 1].x4;
last_y = arr_curve_bezier[arr_curve_bezier.length - 1].y4;
for (var i = 0; i < arr_curve_bezier.length; ++i) {
var cur_curve_bezier = arr_curve_bezier[i];
cur_polygon = cur_polygon.concat(partition_bezier4(cur_curve_bezier.x0, cur_curve_bezier.y0, cur_curve_bezier.x1, cur_curve_bezier.y1, cur_curve_bezier.x2, cur_curve_bezier.y2, cur_curve_bezier.x3, cur_curve_bezier.y3, epsilon));
}
}
break;
case close:
arr_polygons.push(cur_polygon);
cur_polygon = [];
}
}
for (i = 0; i < arr_polygons.length; ++i) {
var cur_polygon = arr_polygons[i];
graphics._m(cur_polygon[0].x, cur_polygon[0].y);
for (var j = 0; j < cur_polygon.length; ++j) {
graphics._l(cur_polygon[j].x, cur_polygon[j].y);
}
graphics._z();
graphics.ds();
}
},
Undo: function (type, data) {
switch (type) {
case historyitem_AutoShapes_Add_PathMoveTo:
case historyitem_AutoShapes_Add_PathLineTo:
case historyitem_AutoShapes_Add_PathArcTo:
case historyitem_AutoShapes_Add_PathQuadBezTo:
case historyitem_AutoShapes_Add_PathCubicBezTo:
this.ArrPathCommandInfo.splice(this.ArrPathCommandInfo.length - 1, 1);
}
},
Redo: function (type, data) {
switch (type) {
case historyitem_AutoShapes_Add_PathMoveTo:
this.ArrPathCommandInfo.push({
id: moveTo,
X: data.x,
Y: data.y
});
break;
case historyitem_AutoShapes_Add_PathLineTo:
this.ArrPathCommandInfo.push({
id: lineTo,
X: data.x,
Y: data.y
});
break;
case historyitem_AutoShapes_Add_PathArcTo:
this.ArrPathCommandInfo.push({
id: arcTo,
wR: data.wR,
hR: data.hR,
stAng: data.stAng,
swAng: data.swAng
});
break;
case historyitem_AutoShapes_Add_PathClose:
this.ArrPathCommandInfo.push({
id: close
});
break;
}
}
};
function partition_bezier3(x0, y0, x1, y1, x2, y2, epsilon) {
var dx01 = x1 - x0;
var dy01 = y1 - y0;
var dx12 = x2 - x1;
var dy12 = y2 - y1;
var r01 = Math.sqrt(dx01 * dx01 + dy01 * dy01);
var r12 = Math.sqrt(dx12 * dx12 + dy12 * dy12);
if (Math.max(r01, r12) < epsilon) {
return [{
x: x0,
y: y0
},
{
x: x1,
y: y1
},
{
x: x2,
y: y2
}];
}
var x01 = (x0 + x1) * 0.5;
var y01 = (y0 + y1) * 0.5;
var x12 = (x1 + x2) * 0.5;
var y12 = (y1 + y2) * 0.5;
var x012 = (x01 + x12) * 0.5;
var y012 = (y01 + y12) * 0.5;
return partition_bezier3(x0, y0, x01, y01, x012, y012, epsilon).concat(partition_bezier3(x012, y012, x12, y12, x2, y2, epsilon));
}
function partition_bezier4(x0, y0, x1, y1, x2, y2, x3, y3, epsilon) {
var dx01 = x1 - x0;
var dy01 = y1 - y0;
var dx12 = x2 - x1;
var dy12 = y2 - y1;
var dx23 = x3 - x2;
var dy23 = y3 - y2;
var r01 = Math.sqrt(dx01 * dx01 + dy01 * dy01);
var r12 = Math.sqrt(dx12 * dx12 + dy12 * dy12);
var r23 = Math.sqrt(dx23 * dx23 + dy23 * dy23);
if (Math.max(r01, r12, r23) < epsilon) {
return [{
x: x0,
y: y0
},
{
x: x1,
y: y1
},
{
x: x2,
y: y2
},
{
x: x3,
y: y3
}];
}
var x01 = (x0 + x1) * 0.5;
var y01 = (y0 + y1) * 0.5;
var x12 = (x1 + x2) * 0.5;
var y12 = (y1 + y2) * 0.5;
var x23 = (x2 + x3) * 0.5;
var y23 = (y2 + y3) * 0.5;
var x012 = (x01 + x12) * 0.5;
var y012 = (y01 + y12) * 0.5;
var x123 = (x12 + x23) * 0.5;
var y123 = (y12 + y23) * 0.5;
var x0123 = (x012 + x123) * 0.5;
var y0123 = (y012 + y123) * 0.5;
return partition_bezier4(x0, y0, x01, y01, x012, y012, x0123, y0123, epsilon).concat(partition_bezier4(x0123, y0123, x123, y123, x23, y23, x3, y3, epsilon));
}

View File

@@ -0,0 +1,183 @@
/*
* (c) Copyright Ascensio System SIA 2010-2014
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
function PolyLine(drawingObjects) {
this.drawingObjects = drawingObjects;
this.arrPoint = [];
this.Matrix = new CMatrixL();
this.TransformMatrix = new CMatrixL();
this.style = CreateDefaultShapeStyle();
var _calculated_line;
var theme = drawingObjects.Layout.Master.Theme;
var slide = drawingObjects;
var layout = drawingObjects.Layout;
var masterSlide = drawingObjects.Layout.Master;
var RGBA = {
R: 0,
G: 0,
B: 0,
A: 255
};
if (isRealObject(theme) && typeof theme.getLnStyle === "function" && isRealObject(this.style) && isRealObject(this.style.lnRef) && isRealNumber(this.style.lnRef.idx) && isRealObject(this.style.lnRef.Color) && typeof this.style.lnRef.Color.Calculate === "function") {
_calculated_line = theme.getLnStyle(this.style.lnRef.idx);
this.style.lnRef.Color.Calculate(theme, slide, layout, masterSlide, RGBA);
RGBA = this.style.lnRef.Color.RGBA;
} else {
_calculated_line = new CLn();
}
if (isRealObject(_calculated_line.Fill)) {
_calculated_line.Fill.calculate(theme, slide, layout, masterSlide, RGBA);
}
this.pen = _calculated_line;
this.polylineForDrawer = new PolylineForDrawer(this);
this.Draw = function (graphics) {
graphics.SetIntegerGrid(false);
graphics.transform3(this.Matrix);
var shape_drawer = new CShapeDrawer();
shape_drawer.fromShape(this, graphics);
shape_drawer.draw(this);
};
this.draw = function (g) {
this.polylineForDrawer.Draw(g);
return;
if (this.arrPoint.length < 2) {
return;
}
g._m(this.arrPoint[0].x, this.arrPoint[0].y);
for (var i = 1; i < this.arrPoint.length; ++i) {
g._l(this.arrPoint[i].x, this.arrPoint[i].y);
}
g.ds();
};
this.getLeftTopPoint = function () {
if (this.arrPoint.length < 1) {
return {
x: 0,
y: 0
};
}
var xMax = this.arrPoint[0].x,
yMax = this.arrPoint[0].y,
xMin = xMax,
yMin = yMax;
var i;
for (i = 1; i < this.arrPoint.length; ++i) {
if (this.arrPoint[i].x > xMax) {
xMax = this.arrPoint[i].x;
}
if (this.arrPoint[i].y > yMax) {
yMax = this.arrPoint[i].y;
}
if (this.arrPoint[i].x < xMin) {
xMin = this.arrPoint[i].x;
}
if (this.arrPoint[i].y < yMin) {
yMin = this.arrPoint[i].y;
}
}
return {
x: xMin,
y: yMin
};
};
this.createShape = function (document) {
var xMax = this.arrPoint[0].x,
yMax = this.arrPoint[0].y,
xMin = xMax,
yMin = yMax;
var i;
var bClosed = false;
if (this.arrPoint.length > 2) {
var dx = this.arrPoint[0].x - this.arrPoint[this.arrPoint.length - 1].x;
var dy = this.arrPoint[0].y - this.arrPoint[this.arrPoint.length - 1].y;
var dd = editor.WordControl.m_oDrawingDocument;
if (Math.sqrt(dx * dx + dy * dy) < dd.GetMMPerDot(3)) {
bClosed = true;
}
}
var _n = bClosed ? this.arrPoint.length - 1 : this.arrPoint.length;
for (i = 1; i < _n; ++i) {
if (this.arrPoint[i].x > xMax) {
xMax = this.arrPoint[i].x;
}
if (this.arrPoint[i].y > yMax) {
yMax = this.arrPoint[i].y;
}
if (this.arrPoint[i].x < xMin) {
xMin = this.arrPoint[i].x;
}
if (this.arrPoint[i].y < yMin) {
yMin = this.arrPoint[i].y;
}
}
var shape = new CShape(this.drawingObjects);
shape.setOffset(xMin, yMin);
shape.setExtents(xMax - xMin, yMax - yMin);
shape.setStyle(CreateDefaultShapeStyle());
var geometry = new Geometry();
geometry.AddPathCommand(0, undefined, bClosed ? "norm" : "none", undefined, xMax - xMin, yMax - yMin);
geometry.AddRect("l", "t", "r", "b");
geometry.AddPathCommand(1, (this.arrPoint[0].x - xMin) + "", (this.arrPoint[0].y - yMin) + "");
for (i = 1; i < _n; ++i) {
geometry.AddPathCommand(2, (this.arrPoint[i].x - xMin) + "", (this.arrPoint[i].y - yMin) + "");
}
if (bClosed) {
geometry.AddPathCommand(6);
}
shape.setGeometry(geometry);
return shape;
};
}
function PolylineForDrawer(polyline) {
this.polyline = polyline;
this.pen = polyline.pen;
this.brush = polyline.brush;
this.TransformMatrix = polyline.TransformMatrix;
this.Matrix = polyline.Matrix;
this.Draw = function (graphics) {
graphics.SetIntegerGrid(false);
graphics.transform3(this.Matrix);
var shape_drawer = new CShapeDrawer();
shape_drawer.fromShape(this, graphics);
shape_drawer.draw(this);
};
this.draw = function (g) {
g._e();
if (this.polyline.arrPoint.length < 2) {
return;
}
g._m(this.polyline.arrPoint[0].x, this.polyline.arrPoint[0].y);
for (var i = 1; i < this.polyline.arrPoint.length; ++i) {
g._l(this.polyline.arrPoint[i].x, this.polyline.arrPoint[i].y);
}
g.ds();
};
}

View File

@@ -0,0 +1,321 @@
/*
* (c) Copyright Ascensio System SIA 2010-2014
*
* This program is a free software product. You can redistribute it and/or
* modify it under the terms of the GNU Affero General Public License (AGPL)
* version 3 as published by the Free Software Foundation. In accordance with
* Section 7(a) of the GNU AGPL its Section 15 shall be amended to the effect
* that Ascensio System SIA expressly excludes the warranty of non-infringement
* of any third-party rights.
*
* This program is distributed WITHOUT ANY WARRANTY; without even the implied
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For
* details, see the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html
*
* You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia,
* EU, LV-1021.
*
* The interactive user interfaces in modified source and object code versions
* of the Program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU AGPL version 3.
*
* Pursuant to Section 7(b) of the License you must retain the original Product
* logo when distributing the program. Pursuant to Section 7(e) we decline to
* grant you any rights under trademark law for use of our trademarks.
*
* All the Product's GUI elements, including illustrations and icon sets, as
* well as technical writing content are licensed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International. See the License
* terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode
*
*/
var K = 1 / 4;
var mt = 0,
lt = 1,
cb = 2,
cl = 3;
function SplineCommandMoveTo(x, y) {
this.id = 0;
this.x = x;
this.y = y;
}
function SplineCommandLineTo(x, y) {
this.id = 1;
this.x = x;
this.y = y;
this.changeLastPoint = function (x, y) {
this.x = x;
this.y = y;
};
}
function SplineCommandBezier(x1, y1, x2, y2, x3, y3) {
this.id = 2;
this.x1 = x1;
this.y1 = y1;
this.x2 = x2;
this.y2 = y2;
this.x3 = x3;
this.y3 = y3;
this.changeLastPoint = function (x, y) {
this.x3 = x;
this.y3 = y;
this.x2 = this.x1 + (this.x3 - this.x1) * 0.5;
this.y2 = this.y1 + (this.y3 - this.y1) * 0.5;
};
}
function Spline(drawingObjects) {
this.path = [];
this.drawingObjects = drawingObjects;
this.Matrix = new CMatrix();
this.TransformMatrix = new CMatrix();
this.style = CreateDefaultShapeStyle();
var _calculated_line;
var theme = drawingObjects.Layout.Master.Theme;
var slide = drawingObjects;
var layout = drawingObjects.Layout;
var masterSlide = drawingObjects.Layout.Master;
var RGBA = {
R: 0,
G: 0,
B: 0,
A: 255
};
if (isRealObject(theme) && typeof theme.getLnStyle === "function" && isRealObject(this.style) && isRealObject(this.style.lnRef) && isRealNumber(this.style.lnRef.idx) && isRealObject(this.style.lnRef.Color) && typeof this.style.lnRef.Color.Calculate === "function") {
_calculated_line = theme.getLnStyle(this.style.lnRef.idx);
this.style.lnRef.Color.Calculate(theme, slide, layout, masterSlide, RGBA);
RGBA = this.style.lnRef.Color.RGBA;
} else {
_calculated_line = new CLn();
}
if (isRealObject(_calculated_line.Fill)) {
_calculated_line.Fill.calculate(theme, slide, layout, masterSlide, RGBA);
}
this.pen = _calculated_line;
this.splineForDraw = new SplineForDrawer(this);
this.Draw = function (graphics) {
graphics.SetIntegerGrid(false);
graphics.transform3(this.Matrix);
var shape_drawer = new CShapeDrawer();
shape_drawer.fromShape(this, graphics);
shape_drawer.draw(this);
};
this.draw = function (g) {
this.splineForDraw.Draw(g);
return;
for (var i = 0; i < this.path.length; ++i) {
var lastX, lastY;
switch (this.path[i].id) {
case 0:
g._m(this.path[i].x, this.path[i].y);
lastX = this.path[i].x;
lastY = this.path[i].y;
break;
case 1:
g._l(this.path[i].x, this.path[i].y);
lastX = this.path[i].x;
lastY = this.path[i].y;
break;
case 2:
g._c(this.path[i].x1, this.path[i].y1, this.path[i].x2, this.path[i].y2, this.path[i].x3, this.path[i].y3);
lastX = this.path[i].x3;
lastY = this.path[i].y3;
break;
}
}
g.ds();
};
this.getLeftTopPoint = function () {
if (this.path.length < 1) {
return {
x: 0,
y: 0
};
}
var min_x = this.path[0].x;
var max_x = min_x;
var min_y = this.path[0].y;
var max_y = min_y;
var last_x = this.path[0].x,
last_y = this.path[0].y;
for (var index = 1; index < this.path.length; ++index) {
var path_command = this.path[index];
if (path_command.id === 1) {
if (min_x > path_command.x) {
min_x = path_command.x;
}
if (max_x < path_command.x) {
max_x = path_command.x;
}
if (min_y > path_command.y) {
min_y = path_command.y;
}
if (max_y < path_command.y) {
max_y = path_command.y;
}
} else {
var bezier_polygon = partition_bezier4(last_x, last_y, path_command.x1, path_command.y1, path_command.x2, path_command.y2, path_command.x3, path_command.y3, APPROXIMATE_EPSILON);
for (var point_index = 1; point_index < bezier_polygon.length; ++point_index) {
var cur_point = bezier_polygon[point_index];
if (min_x > cur_point.x) {
min_x = cur_point.x;
}
if (max_x < cur_point.x) {
max_x = cur_point.x;
}
if (min_y > cur_point.y) {
min_y = cur_point.y;
}
if (max_y < cur_point.y) {
max_y = cur_point.y;
}
}
}
}
return {
x: min_x,
y: min_y
};
};
this.createShape = function (drawingObjects) {
var xMax = this.path[0].x,
yMax = this.path[0].y,
xMin = xMax,
yMin = yMax;
var i;
var bClosed = false;
if (this.path.length > 2) {
var dx = this.path[0].x - this.path[this.path.length - 1].x3;
var dy = this.path[0].y - this.path[this.path.length - 1].y3;
if (Math.sqrt(dx * dx + dy * dy) < 3) {
bClosed = true;
this.path[this.path.length - 1].x3 = this.path[0].x;
this.path[this.path.length - 1].y3 = this.path[0].y;
if (this.path.length > 3) {
var vx = (this.path[1].x3 - this.path[this.path.length - 2].x3) / 6;
var vy = (this.path[1].y3 - this.path[this.path.length - 2].y3) / 6;
} else {
vx = -(this.path[1].y3 - this.path[0].y) / 6;
vy = (this.path[1].x3 - this.path[0].x) / 6;
}
this.path[1].x1 = this.path[0].x + vx;
this.path[1].y1 = this.path[0].y + vy;
this.path[this.path.length - 1].x2 = this.path[0].x - vx;
this.path[this.path.length - 1].y2 = this.path[0].y - vy;
}
}
var min_x = this.path[0].x;
var max_x = min_x;
var min_y = this.path[0].y;
var max_y = min_y;
var last_x = this.path[0].x,
last_y = this.path[0].y;
for (var index = 1; index < this.path.length; ++index) {
var path_command = this.path[index];
if (path_command.id === 1) {
if (min_x > path_command.x) {
min_x = path_command.x;
}
if (max_x < path_command.x) {
max_x = path_command.x;
}
if (min_y > path_command.y) {
min_y = path_command.y;
}
if (max_y < path_command.y) {
max_y = path_command.y;
}
last_x = path_command.x;
last_y = path_command.y;
} else {
var bezier_polygon = partition_bezier4(last_x, last_y, path_command.x1, path_command.y1, path_command.x2, path_command.y2, path_command.x3, path_command.y3, APPROXIMATE_EPSILON);
for (var point_index = 1; point_index < bezier_polygon.length; ++point_index) {
var cur_point = bezier_polygon[point_index];
if (min_x > cur_point.x) {
min_x = cur_point.x;
}
if (max_x < cur_point.x) {
max_x = cur_point.x;
}
if (min_y > cur_point.y) {
min_y = cur_point.y;
}
if (max_y < cur_point.y) {
max_y = cur_point.y;
}
last_x = path_command.x3;
last_y = path_command.y3;
}
}
}
xMin = min_x;
xMax = max_x;
yMin = min_y;
yMax = max_y;
var shape = new CShape(this.drawingObjects);
shape.setOffset(xMin, yMin);
shape.setExtents(xMax - xMin, yMax - yMin);
shape.setStyle(CreateDefaultShapeStyle());
var geometry = new Geometry();
geometry.AddPathCommand(0, undefined, bClosed ? "norm" : "none", undefined, xMax - xMin, yMax - yMin);
geometry.AddRect("l", "t", "r", "b");
for (i = 0; i < this.path.length; ++i) {
switch (this.path[i].id) {
case 0:
geometry.AddPathCommand(1, (this.path[i].x - xMin) + "", (this.path[i].y - yMin) + "");
break;
case 1:
geometry.AddPathCommand(2, (this.path[i].x - xMin) + "", (this.path[i].y - yMin) + "");
break;
case 2:
geometry.AddPathCommand(5, (this.path[i].x1 - xMin) + "", (this.path[i].y1 - yMin) + "", (this.path[i].x2 - xMin) + "", (this.path[i].y2 - yMin) + "", (this.path[i].x3 - xMin) + "", (this.path[i].y3 - yMin) + "");
break;
}
}
if (bClosed) {
geometry.AddPathCommand(6);
}
shape.setGeometry(geometry);
return shape;
};
this.addPathCommand = function (pathCommand) {
this.path.push(pathCommand);
};
}
function SplineForDrawer(spline) {
this.spline = spline;
this.pen = spline.pen;
this.brush = spline.brush;
this.TransformMatrix = spline.TransformMatrix;
this.Matrix = spline.Matrix;
this.Draw = function (graphics) {
graphics.SetIntegerGrid(false);
graphics.transform3(this.Matrix);
var shape_drawer = new CShapeDrawer();
shape_drawer.fromShape(this, graphics);
shape_drawer.draw(this);
};
this.draw = function (g) {
g._e();
for (var i = 0; i < this.spline.path.length; ++i) {
var lastX, lastY;
switch (this.spline.path[i].id) {
case 0:
g._m(this.spline.path[i].x, this.spline.path[i].y);
lastX = this.spline.path[i].x;
lastY = this.spline.path[i].y;
break;
case 1:
g._l(this.spline.path[i].x, this.spline.path[i].y);
lastX = this.spline.path[i].x;
lastY = this.spline.path[i].y;
break;
case 2:
g._c(this.spline.path[i].x1, this.spline.path[i].y1, this.spline.path[i].x2, this.spline.path[i].y2, this.spline.path[i].x3, this.spline.path[i].y3);
lastX = this.spline.path[i].x3;
lastY = this.spline.path[i].y3;
break;
}
}
g.ds();
};
}