Commit 07c15a9a authored by Sergey.Luzyanin's avatar Sergey.Luzyanin

remove Drawing

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@58061 954022d7-b5bf-4e40-9824-e11837661b57
parent 01c8938f
"use strict";
var ArcToCurvers = null;
var ArcToOnCanvas = null;
var HitToArc = null;
(function(){
// arcTo new version
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 /*is path closed*/ )
{
var fStartX = fX + fWidth / 2.0 + fWidth / 2 * Math.cos( AngToEllPrm( fStartAngle, fWidth / 2, fHeight / 2 ) );
var fStartY = fY + fHeight / 2.0 - 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.552;
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};
//ctx._l(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 = 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.0 + 3.0 * Math.tan( (dAngle2 - dAngle1) / 2.0 ) * Math.tan( (dAngle2 - dAngle1) / 2.0 ) ) - 1.0 ) / 3.0;
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.552;
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.0 + 3.0 * Math.tan( (dAngle2 - dAngle1) / 2.0 ) * Math.tan( (dAngle2 - dAngle1) / 2.0 ) ) - 1.0 ) / 3.0;
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.552;
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.0 + 3.0 * Math.tan( (dAngle2 - dAngle1) / 2.0 ) * Math.tan( (dAngle2 - dAngle1) / 2.0 ) ) - 1.0 ) / 3.0;
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;
// ----------------------------------------------------------------------- //
})();
\ No newline at end of file
"use strict";
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;
}
"use strict";
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;
}
"use strict";
/**
* Created by JetBrains WebStorm.
* User: Sergey.Luzyanin
* Date: 2/24/12
* Time: 12:41 PM
* To change this template use File | Settings | File Templates.
*/
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)//{r : 0..255, g : 0..255, b: 0..255}
{
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}; //{h : 0..360, s : 0..1, l : 0..1}
}
function HSLToRGB(HSLColor) { //{h : 0..360, s : 0..1, l : 0..1}
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};//{r : 0..255, g : 0..255, b : 0..255}
}
\ No newline at end of file
This source diff could not be displayed because it is too large. You can view the blob instead.
"use strict";
var FORMULA_TYPE_MULT_DIV = 0,
FORMULA_TYPE_PLUS_MINUS = 1,
FORMULA_TYPE_PLUS_DIV = 2,
FORMULA_TYPE_IF_ELSE =3,
FORMULA_TYPE_ABS = 4,
FORMULA_TYPE_AT2 = 5,
FORMULA_TYPE_CAT2 = 6,
FORMULA_TYPE_COS = 7,
FORMULA_TYPE_MAX = 8,
FORMULA_TYPE_MOD = 9,
FORMULA_TYPE_PIN = 10,
FORMULA_TYPE_SAT2 = 11,
FORMULA_TYPE_SIN = 12,
FORMULA_TYPE_SQRT = 13,
FORMULA_TYPE_TAN = 14,
FORMULA_TYPE_VALUE = 15,
FORMULA_TYPE_MIN = 16;
var APPROXIMATE_EPSILON = 1;
var APPROXIMATE_EPSILON2 = 3;
var APPROXIMATE_EPSILON3 = 5;
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] = clonePrototype(obj[key]);
}
return clonedObj;
}
function CalculateGuideValue(name, formula, x, y, z, gdLst)
{
var xt, yt, zt;
xt=gdLst[x]; //TODO : возможно, что gdLst[x] еще не расчитан
if(xt===undefined)
xt=parseInt(x,10);
yt=gdLst[y];
if(yt===undefined)
yt=parseInt(y,10);
zt=gdLst[z];
if(zt===undefined)
zt=parseInt(z,10);
switch(formula)
{
case FORMULA_TYPE_MULT_DIV:
{
gdLst[name]=xt*yt/zt;
break;
}
case FORMULA_TYPE_PLUS_MINUS:
{
gdLst[name] = xt+yt-zt;
break;
}
case FORMULA_TYPE_PLUS_DIV:
{
gdLst[name] = (xt+yt)/zt;
break;
}
case FORMULA_TYPE_IF_ELSE:
{
if(xt>0)
gdLst[name] = yt;
else
gdLst[name] = zt;
break;
}
case FORMULA_TYPE_ABS:
{
gdLst[name] = Math.abs(xt);
break;
}
case FORMULA_TYPE_AT2:
{
gdLst[name] = ATan2(yt, xt);
break;
}
case FORMULA_TYPE_CAT2:
{
gdLst[name] = CAt2(xt,yt,zt);
break;
}
case FORMULA_TYPE_COS:
{
gdLst[name] = xt*Cos(yt);
break;
}
case FORMULA_TYPE_MAX:
{
gdLst[name] = Math.max(xt, yt);
break;
}
case FORMULA_TYPE_MOD:
{
gdLst[name] = Math.sqrt(xt*xt+yt*yt+zt*zt);
break;
}
case FORMULA_TYPE_PIN:
{
if (yt < xt)
gdLst[name] = xt;
else if (yt > zt)
gdLst[name] = zt;
else
gdLst[name] = yt;
break;
}
case FORMULA_TYPE_SAT2:
{
gdLst[name] = SAt2(xt,yt,zt);
break;
}
case FORMULA_TYPE_SIN:
{
gdLst[name] = xt*Sin(yt);
break;
}
case FORMULA_TYPE_SQRT:
{
gdLst[name] = Math.sqrt(xt);
break;
}
case FORMULA_TYPE_TAN:
{
gdLst[name] = xt*Tan(yt);
break;
}
case FORMULA_TYPE_VALUE:
{
gdLst[name] = xt;
break;
}
case FORMULA_TYPE_MIN:
{
gdLst[name] = Math.min(xt, yt);
}
}
}
function CalculateGuideLst(gdLstInfo, gdLst)
{
var info;
for(var i=0, n=gdLstInfo.length; i<n;i++)
{
info=gdLstInfo[i];
CalculateGuideValue(info.name, info.formula, info.x, info.y, info.z, gdLst);
}
}
function CalculateCnxLst(cnxLstInfo, cnxLst, gdLst)
{
var x_, y_, ang_;
for(var i=0, n=cnxLstInfo.length; i<n;i++)
{
ang_=parseInt(cnxLstInfo[i].ang);
if(isNaN(ang_))
ang_=gdLst[cnxLstInfo[i].ang];
x_=gdLst[cnxLstInfo[i].x];
if(x_===undefined)
x_=parseInt(cnxLstInfo[i].x);
y_=gdLst[cnxLstInfo[i].y];
if(y_===undefined)
y_=parseInt(cnxLstInfo[i].y);
if(cnxLst[i]==undefined)
cnxLst[i]={};
cnxLst[i].ang=ang_;
cnxLst[i].x=x_;
cnxLst[i].y=y_;
}
}
function CalculateAhXYList(ahXYListInfo, ahXYLst, gdLst)
{
var minX, maxX, minY, maxY, posX, posY;
for(var i=0, n=ahXYListInfo.length; i<n;i++)
{
minX=parseInt(ahXYListInfo[i].minX);
if(isNaN(minX))
minX=gdLst[ahXYListInfo[i].minX];
maxX=parseInt(ahXYListInfo[i].maxX);
if(isNaN(maxX))
maxX=gdLst[ahXYListInfo[i].maxX];
minY=parseInt(ahXYListInfo[i].minY);
if(isNaN(minY))
minY=gdLst[ahXYListInfo[i].minY];
maxY=parseInt(ahXYListInfo[i].maxY);
if(isNaN(maxY))
maxY=gdLst[ahXYListInfo[i].maxY];
posX=parseInt(ahXYListInfo[i].posX);
if(isNaN(posX))
{
posX=gdLst[ahXYListInfo[i].posX];
}
posY=parseInt(ahXYListInfo[i].posY);
if(isNaN(posY))
{
posY=gdLst[ahXYListInfo[i].posY];
}
if(ahXYLst[i]==undefined)
ahXYLst[i]={};
ahXYLst[i].gdRefX=ahXYListInfo[i].gdRefX;
ahXYLst[i].minX= minX;
ahXYLst[i].maxX= maxX;
ahXYLst[i].gdRefY=ahXYListInfo[i].gdRefY;
ahXYLst[i].minY= minY;
ahXYLst[i].maxY= maxY;
ahXYLst[i].posX= posX;
ahXYLst[i].posY= posY;
}
}
function CalculateAhPolarList(ahPolarListInfo, ahPolarLst, gdLst)
{
var minR, maxR, minAng, maxAng, posX, posY;
for(var i=0, n=ahPolarListInfo.length; i<n;i++)
{
minR=parseInt(ahPolarListInfo[i].minR);
if(isNaN(minR))
minR=gdLst[ahPolarListInfo[i].minR];
maxR=parseInt(ahPolarListInfo[i].maxR);
if(isNaN(maxR))
maxR=gdLst[ahPolarListInfo[i].maxR];
minAng=parseInt(ahPolarListInfo[i].minAng);
if(isNaN(minAng))
minAng=gdLst[ahPolarListInfo[i].minAng];
maxAng=parseInt(ahPolarListInfo[i].maxAng);
if(isNaN(maxAng))
maxAng=gdLst[ahPolarListInfo[i].maxAng];
posX=parseInt(ahPolarListInfo[i].posX);
if(isNaN(posX))
{
posX=gdLst[ahPolarListInfo[i].posX]
}
posY=parseInt(ahPolarListInfo[i].posY);
if(isNaN(posY))
{
posY=gdLst[ahPolarListInfo[i].posY];
}
if(ahPolarLst[i]==undefined)
{
ahPolarLst[i]={};
}
ahPolarLst[i].gdRefR=ahPolarListInfo[i].gdRefR;
ahPolarLst[i].minR = minR;
ahPolarLst[i].maxR = maxR;
ahPolarLst[i].gdRefAng = ahPolarListInfo[i].gdRefAng;
ahPolarLst[i].minAng = minAng;
ahPolarLst[i].maxAng = maxAng;
ahPolarLst[i].posX=posX;
ahPolarLst[i].posY=posY;
}
}
function Geometry()
{
this.gdLstInfo=[];
this.gdLst={};
this.avLst = {};
this.cnxLstInfo=[];
this.cnxLst=[];
this.ahXYLstInfo=[];
this.ahXYLst=[];
this.ahPolarLstInfo=[];
this.ahPolarLst=[];
this.pathLst = [];
this.isLine = false;
this.preset = null;
this.createDuplicate = function()
{
var duplicate = new Geometry();
for(var i = 0; i < this.gdLstInfo.length; ++i)
{
duplicate.gdLstInfo[i] = clonePrototype(this.gdLstInfo[i]);
}
duplicate.gdLst = clonePrototype(this.gdLst);
for(i = 0; i < this.cnxLstInfo.length; ++i)
{
duplicate.cnxLstInfo[i] = clonePrototype(this.cnxLstInfo[i]) ;
}
for(i = 0; i < this.cnxLst.length; ++i)
{
duplicate.cnxLst[i] = clonePrototype(this.cnxLst[i]);
}
for(i = 0; i < this.ahXYLstInfo.length; ++i)
{
duplicate.ahXYLstInfo[i] = clonePrototype(this.ahXYLstInfo[i]);
}
for(i = 0; i < this.ahXYLst.length; ++i)
{
duplicate.ahXYLst[i] = clonePrototype(this.ahXYLst[i]);
}
for(i = 0; i < this.ahPolarLstInfo.length; ++i)
{
duplicate.ahPolarLstInfo[i] = clonePrototype(this.ahPolarLstInfo[i]);
}
for(i = 0; i < this.ahPolarLst.length; ++i)
{
duplicate.ahPolarLst[i] = clonePrototype(this.ahPolarLst[i]);
}
for(i = 0; i < this.pathLst.length; ++i)
{
duplicate.pathLst[i] = this.pathLst[i].createDuplicate();
}
for (var i in this.avLst)
{
duplicate.avLst[i] = this.avLst[i];
}
duplicate.rectS = clonePrototype(this.rectS);
duplicate.rect = clonePrototype(this.rect);
duplicate.isLine = this.isLine;
duplicate.preset = this.preset;
return duplicate;
};
this.createDuplicateForTrack = function()
{
var _duplicate = new Geometry();
_duplicate.gdLst["_3cd4"] = 16200000;
_duplicate.gdLst["_3cd8"] = 8100000;
_duplicate.gdLst["_5cd8"] = 13500000;
_duplicate.gdLst["_7cd8"] = 18900000;
_duplicate.gdLst["cd2"] = 10800000;
_duplicate.gdLst["cd4"] = 5400000;
_duplicate.gdLst["cd8"] = 2700000;
_duplicate.gdLst["l"] = 0;
_duplicate.gdLst["t"] = 0;
var _adj_key;
for(_adj_key in this.avLst)
{
if(this.avLst[_adj_key] === true)
{
_duplicate.gdLst[_adj_key] = this.gdLst[_adj_key];
}
}
var _gd_index;
var _cur_guide;
var _duplicate_guide;
var _gd_count = this.gdLstInfo.length;
for(_gd_index = 0; _gd_index < _gd_count; ++_gd_index)
{
_cur_guide = this.gdLstInfo[_gd_index];
_duplicate_guide = {};
_duplicate_guide.name = _cur_guide.name;
_duplicate_guide.formula = _cur_guide.formula;
_duplicate_guide.x = _cur_guide.x;
_duplicate_guide.y = _cur_guide.y;
_duplicate_guide.z = _cur_guide.z;
_duplicate_guide.isAdj = _cur_guide.isAdj;
_duplicate.gdLstInfo.push(_duplicate_guide);
}
var _path_index;
for(_path_index = 0; _path_index < this.pathLst.length; ++_path_index)
{
_duplicate.pathLst[_path_index] = this.pathLst[_path_index].createDuplicate();
}
var _ah_index;
var _adjustment;
var _duplicate_adj;
for(_ah_index = 0; _ah_index < this.ahXYLstInfo.length; ++_ah_index)
{
_adjustment = this.ahXYLstInfo[_ah_index];
_duplicate_adj = {};
_duplicate_adj.gdRefX = _adjustment.gdRefX;
_duplicate_adj.gdRefY = _adjustment.gdRefY;
_duplicate_adj.maxX = _adjustment.maxX;
_duplicate_adj.minX = _adjustment.minX;
_duplicate_adj.maxY = _adjustment.maxY;
_duplicate_adj.minY = _adjustment.minY;
_duplicate_adj.posX = _adjustment.posX;
_duplicate_adj.posY = _adjustment.posY;
_duplicate.ahXYLstInfo.push(_duplicate_adj);
}
for(_ah_index = 0; _ah_index < this.ahPolarLstInfo.length; ++_ah_index)
{
_adjustment = this.ahPolarLstInfo[_ah_index];
_duplicate_adj = {};
_duplicate_adj.gdRefR = _adjustment.gdRefR;
_duplicate_adj.gdRefAng = _adjustment.gdRefAng;
_duplicate_adj.maxR = _adjustment.maxR;
_duplicate_adj.minR = _adjustment.minR;
_duplicate_adj.maxAng = _adjustment.maxAng;
_duplicate_adj.minAng = _adjustment.minAng;
_duplicate_adj.posX = _adjustment.posX;
_duplicate_adj.posY = _adjustment.posY;
_duplicate.ahPolarLstInfo.push(_duplicate_adj);
}
_duplicate.isLine = this.isLine;
return _duplicate;
};
}
Geometry.prototype=
{
Write_ToBinary: function(Writer)
{
},
Write_ToBinary2: function(Writer)
{
var w = Writer;
var count = 0;
for(var key in this.avLst)
{
++count;
}
w.WriteLong(count);
for(key in this.avLst)
{
w.WriteString2(key);
}
var gd_lst_info_count = this.gdLstInfo.length;
Writer.WriteLong(gd_lst_info_count);
var bool;
for(var index = 0; index < gd_lst_info_count; ++index)
{
var g = this.gdLstInfo[index];
w.WriteString2(g.name);
w.WriteLong(g.formula);
bool = typeof g.x === "string";
w.WriteBool(bool);
if(bool)
w.WriteString2(g.x);
bool = typeof g.y === "string";
w.WriteBool(bool);
if(bool)
w.WriteString2(g.y);
bool = typeof g.z === "string";
w.WriteBool(bool);
if(bool)
w.WriteString2(g.z);
}
WriteObjectLong(w, this.gdLst);
var cnx_lst_count = this.cnxLstInfo.length;
Writer.WriteLong(cnx_lst_count);
for(index = 0; index < cnx_lst_count; ++index)
{
WriteObjectString(Writer, this.cnxLstInfo[index]);
}
var ah_xy_count = this.ahXYLstInfo.length;
Writer.WriteLong(ah_xy_count);
for(index = 0; index < ah_xy_count; ++index)
{
var o = this.ahXYLstInfo[index];
bool = typeof o.gdRefX === "string";
w.WriteBool(bool);
if(bool)
w.WriteString2(o.gdRefX);
bool = typeof o.gdRefY === "string";
w.WriteBool(bool);
if(bool)
w.WriteString2(o.gdRefY);
bool = typeof o.minX === "string";
w.WriteBool(bool);
if(bool)
w.WriteString2(o.minX);
bool = typeof o.maxX === "string";
w.WriteBool(bool);
if(bool)
w.WriteString2(o.maxX);
bool = typeof o.minY === "string";
w.WriteBool(bool);
if(bool)
w.WriteString2(o.minY);
bool = typeof o.maxY === "string";
w.WriteBool(bool);
if(bool)
w.WriteString2(o.maxY);
bool = typeof o.posX === "string";
w.WriteBool(bool);
if(bool)
w.WriteString2(o.posX);
bool = typeof o.posY === "string";
w.WriteBool(bool);
if(bool)
w.WriteString2(o.posY);
}
var ah_polar_count = this.ahPolarLstInfo.length;
Writer.WriteLong(ah_polar_count);
for(index = 0; index < ah_polar_count; ++index)
{
o = this.ahPolarLstInfo[index];
bool = typeof o.gdRefR === "string";
w.WriteBool(bool);
if(bool)
w.WriteString2(o.gdRefR);
bool = typeof o.gdRefAng === "string";
w.WriteBool(bool);
if(bool)
w.WriteString2(o.gdRefAng);
bool = typeof o.minR === "string";
w.WriteBool(bool);
if(bool)
w.WriteString2(o.minR);
bool = typeof o.maxR === "string";
w.WriteBool(bool);
if(bool)
w.WriteString2(o.maxR);
bool = typeof o.minAng === "string";
w.WriteBool(bool);
if(bool)
w.WriteString2(o.minAng);
bool = typeof o.maxAng === "string";
w.WriteBool(bool);
if(bool)
w.WriteString2(o.maxAng);
bool = typeof o.posX === "string";
w.WriteBool(bool);
if(bool)
w.WriteString2(o.posX);
bool = typeof o.posY === "string";
w.WriteBool(bool);
if(bool)
w.WriteString2(o.posY);
}
var path_count = this.pathLst.length;
Writer.WriteLong(path_count);
for(index = 0; index < path_count; ++index)
{
this.pathLst[index].Write_ToBinary2(Writer);
}
Writer.WriteBool(typeof this.preset === "string");
if(typeof this.preset === "string")
{
Writer.WriteString2(this.preset);
}
var w = Writer;
w.WriteBool(isRealObject(this.rectS));
if(isRealObject(this.rectS))
{
w.WriteString2(this.rectS.l);
w.WriteString2(this.rectS.t);
w.WriteString2(this.rectS.r);
w.WriteString2(this.rectS.b);
}
// WriteObjectString(Writer, this.rectS);
//WriteObjectDouble(Writer, this.rect);
},
Read_FromBinary2: function(Reader)
{
var r = Reader;
var count = r.GetLong();
for(index = 0; index < count; ++index)
{
this.avLst[r.GetString2()] = true;
}
var gd_lst_info_count = Reader.GetLong();
for(var index = 0; index < gd_lst_info_count; ++index)
{
var gd_info = {};
gd_info.name = r.GetString2();
gd_info.formula = r.GetLong();
if(r.GetBool())
gd_info.x = r.GetString2();
if(r.GetBool())
gd_info.y = r.GetString2();
if(r.GetBool())
gd_info.z = r.GetString2();
this.gdLstInfo.push(gd_info);
}
this.gdLst = ReadObjectLong(r);
var cnx_lst_count = Reader.GetLong();
for(index = 0; index < cnx_lst_count; ++index)
{
this.cnxLstInfo[index] = ReadObjectString(Reader);
}
var ah_xy_count = Reader.GetLong();
for(index = 0; index < ah_xy_count; ++index)
{
var o = {};
if(r.GetBool())
o.gdRefX = r.GetString2();
if(r.GetBool())
o.gdRefY = r.GetString2();
if(r.GetBool())
o.minX = r.GetString2();
if(r.GetBool())
o.maxX = r.GetString2();
if(r.GetBool())
o.minY = r.GetString2();
if(r.GetBool())
o.maxY = r.GetString2();
if(r.GetBool())
o.posX = r.GetString2();
if(r.GetBool())
o.posY = r.GetString2();
this.ahXYLstInfo.push(o);
}
var ah_polar_count = Reader.GetLong();
for(index = 0; index < ah_polar_count; ++index)
{
o = {};
if(r.GetBool())
o.gdRefR = r.GetString2();
if(r.GetBool())
o.gdRefAng = r.GetString2();
if(r.GetBool())
o.minR = r.GetString2();
if(r.GetBool())
o.maxR = r.GetString2();
if(r.GetBool())
o.minAng = r.GetString2();
if(r.GetBool())
o.maxAng = r.GetString2();
if(r.GetBool())
o.posX = r.GetString2();
if(r.GetBool())
o.posY = r.GetString2();
this.ahPolarLstInfo.push(o);
}
var path_count = Reader.GetLong();
for(index = 0; index < path_count; ++index)
{
this.pathLst[index] = new Path();
this.pathLst[index].Read_FromBinary2(Reader);
}
if(r.GetBool())
{
this.preset = r.GetString2();
}
if(r.GetBool())
{
this.rectS = {};
this.rectS.l = r.GetString2();
this.rectS.t = r.GetString2();
this.rectS.r = r.GetString2();
this.rectS.b = r.GetString2();
}
//this.rect = ReadObjectDouble(r);
},
AddAdj: function(name, formula, x, y, z)
{
this.gdLst[name] = parseInt(x);
this.avLst[name]=true;
},
AddGuide: function(name, formula, x, y, z)
{
this.gdLstInfo.push(
{
name: name,
formula: formula,
x: x,
y: y,
z: z,
isAdj: false
});
},
AddCnx: function(ang, x, y)
{
this.cnxLstInfo.push(
{
ang:ang,
x:x,
y:y
});
},
AddHandleXY: function(gdRefX, minX, maxX, gdRefY, minY, maxY, posX, posY)
{
this.ahXYLstInfo.push(
{
gdRefX:gdRefX,
minX:minX,
maxX:maxX,
gdRefY:gdRefY,
minY:minY,
maxY:maxY,
posX:posX,
posY:posY
});
},
AddHandlePolar: function(gdRefAng, minAng, maxAng, gdRefR, minR, maxR, posX, posY)
{
this.ahPolarLstInfo.push(
{
gdRefAng:gdRefAng,
minAng:minAng,
maxAng:maxAng,
gdRefR:gdRefR,
minR:minR,
maxR:maxR,
posX:posX,
posY:posY
})
},
AddPathCommand: function(command, x1, y1, x2, y2, x3, y3)
{
switch(command)
{
case 0:
{ /* extrusionOk, fill, stroke, w, h*/
this.pathLst[this.pathLst.length] = new Path(x1, y1, x2, y2, x3);
break;
}
case 1:
{
this.pathLst[this.pathLst.length-1].moveTo(x1, y1);
break;
}
case 2:
{
this.pathLst[this.pathLst.length-1].lnTo(x1, y1);
break;
}
case 3:
{
this.pathLst[this.pathLst.length-1].arcTo(x1/*wR*/, y1/*hR*/, x2/*stAng*/, y2/*swAng*/);
break;
}
case 4:
{
this.pathLst[this.pathLst.length-1].quadBezTo(x1, y1, x2, y2);
break;
}
case 5:
{
this.pathLst[this.pathLst.length-1].cubicBezTo(x1, y1, x2, y2, x3, y3);
break;
}
case 6:
{
this.pathLst[this.pathLst.length-1].close();
}
}
},
AddRect: function(l, t, r, b)
{
this.rectS = {};
this.rectS.l = l;
this.rectS.t = t;
this.rectS.r = r;
this.rectS.b = b;
},
Init: function(w, h)
{
this.gdLst["_3cd4"]=16200000;
this.gdLst["_3cd8"]=8100000;
this.gdLst["_5cd8"]=13500000;
this.gdLst["_7cd8"]=18900000;
this.gdLst["cd2"]=10800000;
this.gdLst["cd4"]=5400000;
this.gdLst["cd8"]=2700000;
this.gdLst["l"]=0;
this.gdLst["t"]=0;
this.gdLst["h"]=h;
this.gdLst["b"]=h;
this.gdLst["hd2"]=h/2;
this.gdLst["hd3"]=h/3;
this.gdLst["hd4"]=h/4;
this.gdLst["hd5"]=h/5;
this.gdLst["hd6"]=h/6;
this.gdLst["hd8"]=h/8;
this.gdLst["hd10"]=h/10;
this.gdLst["hd12"]=h/12;
this.gdLst["hd32"]=h/32;
this.gdLst["vc"]=h/2;
this.gdLst["w"]=w;
this.gdLst["r"]=w;
this.gdLst["wd2"]=w/2;
this.gdLst["wd3"]=w/3;
this.gdLst["wd4"]=w/4;
this.gdLst["wd5"]=w/4;
this.gdLst["wd6"]=w/6;
this.gdLst["wd8"]=w/8;
this.gdLst["wd10"]=w/10;
this.gdLst["wd12"]=w/12;
this.gdLst["wd32"]=w/32;
this.gdLst["hc"]=w/2;
this.gdLst["ls"]=Math.max(w,h);
this.gdLst["ss"]=Math.min(w,h);
this.gdLst["ssd2"]=this.gdLst["ss"]/2;
this.gdLst["ssd4"]=this.gdLst["ss"]/4;
this.gdLst["ssd6"]=this.gdLst["ss"]/6;
this.gdLst["ssd8"]=this.gdLst["ss"]/8;
this.gdLst["ssd16"]=this.gdLst["ss"]/16;
this.gdLst["ssd32"]=this.gdLst["ss"]/32;
CalculateGuideLst(this.gdLstInfo, this.gdLst);
CalculateCnxLst(this.cnxLstInfo, this.cnxLst, this.gdLst);
CalculateAhXYList(this.ahXYLstInfo, this.ahXYLst, this.gdLst);
CalculateAhPolarList(this.ahPolarLstInfo, this.ahPolarLst, this.gdLst);
for(var i=0, n=this.pathLst.length; i<n; i++)
this.pathLst[i].init(this.gdLst);
if(this.rectS!=undefined)
{
this.rect={};
this.rect.l=this.gdLst[this.rectS.l];
if(this.rect.l===undefined)
{
this.rect.l=parseInt(this.rectS.l);
}
this.rect.t=this.gdLst[this.rectS.t];
if(this.rect.t===undefined)
{
this.rect.t=parseInt(this.rectS.t);
}
this.rect.r=this.gdLst[this.rectS.r];
if(this.rect.r===undefined)
{
this.rect.r=parseInt(this.rectS.r);
}
this.rect.b=this.gdLst[this.rectS.b];
if(this.rect.b===undefined)
{
this.rect.b=parseInt(this.rectS.b);
}
}
},
Recalculate: function(w, h)
{
this.gdLst["_3cd4"]=16200000;
this.gdLst["_3cd8"]=8100000;
this.gdLst["_5cd8"]=13500000;
this.gdLst["_7cd8"]=18900000;
this.gdLst["cd2"]=10800000;
this.gdLst["cd4"]=5400000;
this.gdLst["cd8"]=2700000;
this.gdLst["l"]=0;
this.gdLst["t"]=0;
this.gdLst["h"]=h;
this.gdLst["b"]=h;
this.gdLst["hd2"]=h*0.5;
this.gdLst["hd3"]=h*0.3333;
this.gdLst["hd4"]=h*0.25;
this.gdLst["hd5"]=h*0.2;
this.gdLst["hd6"]=h*0.1666666;
this.gdLst["hd8"]=h*0.125;
this.gdLst["hd10"]=h*0.1;
this.gdLst["hd12"]=h/12;
this.gdLst["hd32"]=h/32;
this.gdLst["vc"]=h*0.5;
this.gdLst["w"]=w;
this.gdLst["r"]=w;
this.gdLst["wd2"]=w*0.5;
this.gdLst["wd3"]=w/3;
this.gdLst["wd4"]=w*0.25;
this.gdLst["wd5"]=w*0.2;
this.gdLst["wd6"]=w*0.166666;
this.gdLst["wd8"]=w*0.125;
this.gdLst["wd10"]=w*0.1;
this.gdLst["wd12"]=w/12;
this.gdLst["wd32"]=w*0.03125;
this.gdLst["hc"]=w*0.5;
this.gdLst["ls"]=Math.max(w,h);
this.gdLst["ss"]=Math.min(w,h);
this.gdLst["ssd2"]=this.gdLst["ss"]*0.5;
this.gdLst["ssd4"]=this.gdLst["ss"]*0.25;
this.gdLst["ssd6"]=this.gdLst["ss"]*0.166666;
this.gdLst["ssd8"]=this.gdLst["ss"]*0.125;
this.gdLst["ssd16"]=this.gdLst["ss"]*0.0625;
this.gdLst["ssd32"]=this.gdLst["ss"]*0.03125;
CalculateGuideLst(this.gdLstInfo, this.gdLst);
CalculateCnxLst(this.cnxLstInfo, this.cnxLst, this.gdLst);
CalculateAhXYList(this.ahXYLstInfo, this.ahXYLst, this.gdLst);
CalculateAhPolarList(this.ahPolarLstInfo, this.ahPolarLst, this.gdLst);
for(var i=0, n=this.pathLst.length; i<n; i++)
this.pathLst[i].recalculate(this.gdLst);
if(this.rectS!=undefined)
{
this.rect={};
this.rect.l=this.gdLst[this.rectS.l];
if(this.rect.l===undefined)
{
this.rect.l=parseInt(this.rectS.l);
}
this.rect.t=this.gdLst[this.rectS.t];
if(this.rect.t===undefined)
{
this.rect.t=parseInt(this.rectS.t);
}
this.rect.r=this.gdLst[this.rectS.r];
if(this.rect.r===undefined)
{
this.rect.r=parseInt(this.rectS.r);
}
this.rect.b=this.gdLst[this.rectS.b];
if(this.rect.b===undefined)
{
this.rect.b=parseInt(this.rectS.b);
}
}
},
/*
draw: function(graphics, line_color, line_width, fill_color, alpha, fillAlpha, lineAlpha)
{
//graphics.m_oContext.shadowOffsetX = shadow.length*Math.cos(shadow.angle)*100/(g_dKoef_pix_to_mm*zoom);
//graphics.m_oContext.shadowOffsetY = shadow.length*Math.sin(shadow.angle)*100/(g_dKoef_pix_to_mm*zoom);
//graphics.m_oContext.shadowBlur = shadow.blur;
//graphics.m_oContext.shadowColor = shadow.color.norm(shadow.alpha);
graphics.p_width(line_width);
for(var i=0, n=this.pathLst.length; i<n;++i)
this.pathLst[i].draw(graphics, line_color, line_width, fill_color, alpha, fillAlpha*255, lineAlpha*255);
//if(shadow.length>0||shadow.blur>0)
//{
// graphics.m_oContext.shadowOffsetX = 0;
// graphics.m_oContext.shadowOffsetY = 0;
// graphics.m_oContext.shadowBlur = 0;
// graphics.m_oContext.shadowColor = 0;
// graphics.p_width(line_width*10000/(g_dKoef_pix_to_mm*zoom));
// for(i=0; i<n;++i)
// this.pathLst[i].draw(graphics, line_color, line_width, fill_color, alpha, fillAlpha*255, lineAlpha*255);
//}
},
*/
draw: function(shape_drawer)
{
for (var i=0, n=this.pathLst.length; i<n;++i)
this.pathLst[i].draw(shape_drawer);
},
check_bounds: function(checker)
{
for(var i=0, n=this.pathLst.length; i<n;++i)
this.pathLst[i].check_bounds(checker);
},
drawAdjustments: function(drawingDocument, transform)
{
var _adjustments = this.ahXYLst;
var _adj_count = _adjustments.length;
var _adj_index;
for(_adj_index = 0; _adj_index < _adj_count; ++_adj_index)
drawingDocument.DrawAdjustment(transform, _adjustments[_adj_index].posX, _adjustments[_adj_index].posY);
_adjustments = this.ahPolarLst;
_adj_count = _adjustments.length;
for(_adj_index = 0; _adj_index < _adj_count; ++_adj_index)
drawingDocument.DrawAdjustment(transform, _adjustments[_adj_index].posX, _adjustments[_adj_index].posY);
},
hitToPath: function(hitCanvasContext, x, y)
{
return false;
},
setPolarAdjustments: function(refR, rValue, refAng, angValue)
{
var history_data;
if(typeof refR === "string" && typeof this.gdLst[refR] === "number" && typeof rValue === "number")
{
history_data = {};
history_data.Type = historyitem_SetGuideValue;
history_data.guideName = refR;
history_data.oldGdValue = this.gdLst[refR];
history_data.newGdValue = rValue;
History.Add(this, history_data);
this.gdLst[refR] = rValue;
}
if( typeof refAng === "string" && typeof this.gdLst[refAng] === "number" && typeof angValue === "number")
{
history_data = {};
history_data.Type = historyitem_SetGuideValue;
history_data.guideName = refAng;
history_data.oldGdValue = this.gdLst[refAng];
history_data.newGdValue = angValue;
History.Add(this, history_data);
this.gdLst[refAng] = angValue;
}
},
setXYAdjustments: function(refX, xValue, refY, yValue)
{
var history_data;
if(typeof refX === "string" && typeof this.gdLst[refX] === "number" && typeof xValue === "number")
{
history_data = {};
history_data.Type = historyitem_SetGuideValue;
history_data.guideName = refX;
history_data.oldGdValue = this.gdLst[refX];
history_data.newGdValue = xValue;
History.Add(this, history_data);
this.gdLst[refX] = xValue;
}
if( typeof refY === "string" && typeof this.gdLst[refY] === "number" && typeof yValue === "number")
{
history_data = {};
history_data.Type = historyitem_SetGuideValue;
history_data.guideName = refY;
history_data.refAng = refY;
history_data.oldGdValue = this.gdLst[refY];
history_data.newGdValue = yValue;
History.Add(this, history_data);
this.gdLst[refY] = yValue;
}
},
canFill: function()
{
if(this.preset === "line")
return false;
for(var i = 0; i < this.pathLst.length; ++i)
{
if(this.pathLst[i].fill !== "none")
return true;
}
return false;
},
setAdjustmentValue: function(ref1, value1, ref2, value2)
{
},
setGuideValue: function(gdRef, gdValue)
{
if(isRealNumber(this.gdLst[gdRef]))
{
this.gdLst[gdRef] = gdValue;
}
},
Save_Changes: function(data, writer)
{
writer.WriteLong(historyitem_type_Geometry);
writer.WriteLong(data.Type);
switch (data.Type)
{
case historyitem_SetGuideValue:
{
writer.WriteString2(data.guideName);
writer.WriteDouble(data.newGdValue);
break;
}
}
},
Load_Changes: function(reader)
{
var type = reader.GetLong();
switch (type)
{
case historyitem_SetGuideValue:
{
var name = reader.GetString2();
this.gdLst[name] = reader.GetDouble();
break;
}
}
},
Undo: function(data)
{
switch(data.Type)
{
case historyitem_SetGuideValue:
{
this.gdLst[data.guideName] = data.oldValue;
break;
}
}
},
Redo: function(data)
{
switch(data.Type)
{
case historyitem_SetGuideValue:
{
this.gdLst[data.guideName] = data.newValue;
break;
}
}
},
hit: function(x, y)
{
},
hitInInnerArea: function(canvasContext, x, y)
{
var _path_list = this.pathLst;
var _path_count = _path_list.length;
var _path_index;
for(_path_index = 0; _path_index < _path_count; ++_path_index)
{
if(_path_list[_path_index].hitInInnerArea(canvasContext, x, y) === true)
return true;
}
return false;
},
hitInPath: function(canvasContext, x, y)
{
var _path_list = this.pathLst;
var _path_count = _path_list.length;
var _path_index;
for(_path_index = 0; _path_index < _path_count; ++_path_index)
{
if(_path_list[_path_index].hitInPath(canvasContext, x, y) === true)
return true;
}
return false;
},
hitToAdj: function(x, y, distanse)
{
var dx, dy;
for(var i=0; i<this.ahXYLst.length; i++)
{
dx=x-this.ahXYLst[i].posX;
dy=y-this.ahXYLst[i].posY;
if(Math.sqrt(dx*dx+dy*dy) < distanse)
{
return {hit: true, adjPolarFlag: false, adjNum: i};
}
}
for( i=0; i<this.ahPolarLst.length; i++)
{
dx=x-this.ahPolarLst[i].posX;
dy=y-this.ahPolarLst[i].posY;
if(Math.sqrt(dx*dx+dy*dy) < distanse)
{
return {hit: true, adjPolarFlag: true, adjNum: i};
}
}
return {hit: false, adjPolarFlag: null, adjNum: null};
},
getArrayPolygons: function(epsilon)
{
var used_epsilon;
if(typeof epsilon !== "number" || isNaN(epsilon))
used_epsilon = APPROXIMATE_EPSILON;
else
used_epsilon = epsilon;
var arr_polygons = [];
var cur_polygon = [];
for(var path_index = 0; path_index < this.pathLst.length; ++path_index)
{
var arr_cur_path_commands = this.pathLst[path_index].ArrPathCommand;
var last_command = null, last_point_x = null, last_point_y = null;
var first_point_x = null, first_point_y = null;
var bezier_polygon = null;
for(var command_index = 0; command_index < arr_cur_path_commands.length; ++command_index)
{
var cur_command = arr_cur_path_commands[command_index];
switch(cur_command.id)
{
case moveTo:
{
if(last_command === null || last_command.id === close)
{
cur_polygon.push({x: cur_command.X, y: cur_command.Y});
last_command = cur_command;
last_point_x = cur_command.X;
last_point_y = cur_command.Y;
first_point_x = cur_command.X;
first_point_y = cur_command.Y;
}
break;
}
case lineTo:
{
cur_polygon.push({x: cur_command.X, y: cur_command.Y});
last_command = cur_command;
last_point_x = cur_command.X;
last_point_y = cur_command.Y;
break;
}
case bezier3:
{
bezier_polygon = partition_bezier3(last_point_x, last_point_y, cur_command.X0, cur_command.Y0, cur_command.X1, cur_command.Y1, used_epsilon);
for(var point_index = 1; point_index < bezier_polygon.length; ++point_index)
{
cur_polygon.push(bezier_polygon[point_index]);
}
last_command = cur_command;
last_point_x = cur_command.X1;
last_point_y = cur_command.Y1;
break;
}
case bezier4:
{
bezier_polygon = partition_bezier4(last_point_x, last_point_y, cur_command.X0, cur_command.Y0, cur_command.X1, cur_command.Y1, cur_command.X2, cur_command.Y2, used_epsilon);
for(point_index = 1; point_index < bezier_polygon.length; ++point_index)
{
cur_polygon.push(bezier_polygon[point_index]);
}
last_command = cur_command;
last_point_x = cur_command.X2;
last_point_y = cur_command.Y2;
break;
}
case arcTo:
{
var path_accumulator = new PathAccumulator();
ArcToCurvers(path_accumulator, cur_command.stX, cur_command.stY, cur_command.wR, cur_command.hR, cur_command.stAng, cur_command.swAng);
var arc_to_path_commands = path_accumulator.pathCommand;
for(var arc_to_path_index = 0; arc_to_path_index < arc_to_path_commands.length; ++arc_to_path_index)
{
var cur_arc_to_command = arc_to_path_commands[arc_to_path_index];
switch (cur_arc_to_command.id)
{
case moveTo:
{
cur_polygon.push({x: cur_arc_to_command.X, y: cur_arc_to_command.Y});
last_command = cur_arc_to_command;
last_point_x = cur_arc_to_command.X;
last_point_y = cur_arc_to_command.Y;
break;
}
case bezier4:
{
bezier_polygon = partition_bezier4(last_point_x, last_point_y, cur_arc_to_command.X0, cur_arc_to_command.Y0, cur_arc_to_command.X1, cur_arc_to_command.Y1, cur_arc_to_command.X2, cur_arc_to_command.Y2, used_epsilon);
for(point_index = 0; point_index < bezier_polygon.length; ++point_index)
{
cur_polygon.push(bezier_polygon[point_index]);
}
last_command = cur_arc_to_command;
last_point_x = cur_arc_to_command.X2;
last_point_y = cur_arc_to_command.Y2;
break;
}
}
}
break;
}
case close:
{
if(last_command.id !== moveTo)
{
if(cur_polygon.length >= 2)
{
if(first_point_x !== null && first_point_y !== null)
{
cur_polygon.push({x: first_point_x, y: first_point_y});
}
arr_polygons.push(cur_polygon);
}
cur_polygon = [];
last_command = cur_command;
}
break;
}
}
}
if(cur_polygon.length >= 2)
{
/*if(first_point_x !== null && first_point_y !== null)
{
cur_polygon.push({x: first_point_x, y: first_point_y});
} */
arr_polygons.push(cur_polygon);
}
}
return arr_polygons;
},
getBounds: function()
{
}
};
function WriteGdInfo(Writer, gdInfo)
{
Writer.WriteString2(gdInfo.name);
Writer.WriteLong(gdInfo.formula);
var flag = typeof gdInfo.x === "string";
Writer.WriteBool(flag);
if(flag)
Writer.WriteString2(gdInfo.x);
else
return;
flag = typeof gdInfo.y === "string";
Writer.WriteBool(flag);
if(flag)
Writer.WriteString2(gdInfo.y);
else
return;
flag = typeof gdInfo.z === "string";
Writer.WriteBool(flag);
if(flag)
Writer.WriteString2(gdInfo.z);
}
function ReadGdInfo(Reader)
{
var ret = {};
ret.name = Reader.GetString2();
ret.formula = Reader.GetLong();
if(Reader.GetBool())
ret.x = Reader.GetString2();
else
return;
if(Reader.GetBool())
ret.y = Reader.GetString2();
else
return;
if(Reader.GetBool())
ret.z = Reader.GetString2();
}
function WriteObjectDouble(Writer, Object)
{
var field_count = 0;
for(var key in Object)
{
++field_count;
}
Writer.WriteLong(field_count);
for(key in Object)
{
Writer.WriteString2(key);
Writer.WriteDouble(Object[key]);
}
}
function ReadObjectDouble(Reader)
{
var ret = {};
var field_count = Reader.GetLong();
for(var index =0; index < field_count; ++index)
{
var key = Reader.GetString2();
ret[key] = Reader.GetDouble();
}
return ret;
}
function WriteObjectString(Writer, Object)
{
var field_count = 0;
for(var key in Object)
{
++field_count;
}
Writer.WriteLong(field_count);
for(key in Object)
{
Writer.WriteString2(key);
Writer.WriteString2(Object[key]);
}
}
function ReadObjectString(Reader)
{
var ret = {};
var field_count = Reader.GetLong();
for(var index = 0; index < field_count; ++index)
{
var key = Reader.GetString2();
ret[key] = Reader.GetString2();
}
return ret;
}
function WriteObjectBool(Writer, Object)
{
var field_count = 0;
for(var key in Object)
{
++field_count;
}
Writer.WriteLong(field_count);
for(key in Object)
{
Writer.WriteString2(key);
Writer.WriteBool(Object[key]);
}
}
function ReadObjectBool(Reader)
{
var ret = {};
var field_count = Reader.GetLong();
for(var index =0; index < field_count; ++index)
{
var key = Reader.GetString2();
ret[key] = Reader.GetBool();
}
return ret;
}
function PathAccumulator()
{
this.pathCommand = [];
}
PathAccumulator.prototype =
{
_m: function(x, y)
{
this.pathCommand.push({id: moveTo, X: x, Y: y});
},
_c: function(x0, y0, x1, y1, x2, y2)
{
this.pathCommand.push({id: bezier4, X0: x0, Y0: y0, X1: x1, Y1: y1, X2: x2, Y2: y2});
}
};
function GraphEdge(point1, point2)
{
if(point1.y <= point2.y)
{
this.point1 = point1;
this.point2 = point2;
}
else
{
this.point1 = point2;
this.point2 = point1;
}
this.getIntersectionPointX = function(y)
{
var ret = [];
if(this.point2.y < y || this.point1.y > y)
{
return ret;
}
else
{
if(this.point1.y === this.point2.y)
{
if(this.point1.x <= this.point2.x)
{
ret.push(this.point1.x);
ret.push(this.point2.x);
return ret;
}
else
{
ret.push(this.point2.x);
ret.push(this.point1.x);
return ret;
}
}
else
{
if(!(this.point1.x === this.point2.x))
{
var ret_x = this.point1.x + ((y - this.point1.y)/(this.point2.y - this.point1.y))*(this.point2.x - this.point1.x);
ret.push(ret_x);
return ret;
}
else
{
ret.push(this.point1.x);
return ret;
}
}
}
}
}
function ComparisonEdgeByTopPoint(graphEdge1, graphEdge2)
{
return Math.min(graphEdge1.point1.y, graphEdge1.point2.y) - Math.min(graphEdge2.point1.y, graphEdge2.point2.y);
}
\ No newline at end of file
"use strict";
/**
* Created by JetBrains WebStorm.
* User: Sergey.Luzyanin
* Date: 3/30/12
* Time: 5:21 PM
* To change graphics template use File | Settings | File Templates.
*/
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();
}
"use strict";
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);
}
"use strict";
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;
}
\ No newline at end of file
"use strict";
/**
* Created by JetBrains WebStorm.
* User: Sergey.Luzyanin
* Date: 2/24/12
* Time: 10:06 AM
* To change this template use File | Settings | File Templates.
*/
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)));
}
\ No newline at end of file
"use strict";
var moveTo=0,
lineTo=1,
arcTo=2,
bezier3=3,
bezier4=4,
close=5;
var PATH_COMMAND_START = 0x101;
var PATH_COMMAND_END = 0x102;
var cToRad = Math.PI / 10800000.0;
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 = [];
this.ArrPathCommand = [];
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]);
}
/*for (i = 0; i < this.ArrPathCommand.length; ++i)
{
duplicate.ArrPathCommand[i] = clonePrototype(this.ArrPathCommand[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 = /*typeof this.pathH === "number" ? writer.WriteLong :*/ 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 = /*typeof this.pathH === "number" ? Reader.GetLong :*/ 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);
//History.Add(g_oUndoRedoGraphicObjects, historyitem_AutoShapes_Add_PathMoveTo, null, null, new UndoRedoDataGraphicObjects(this.Id, new UndoRedoDataMoveToLineTo(x, y, true)), null);
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);
//History.Add(g_oUndoRedoGraphicObjects, historyitem_AutoShapes_Add_PathLineTo, null, null, new UndoRedoDataGraphicObjects(this.Id, new UndoRedoDataMoveToLineTo(x, y, false)), null);
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);
//History.Add(g_oUndoRedoGraphicObjects, historyitem_AutoShapes_Add_PathArcTo, null, null, new UndoRedoDataGraphicObjects(this.Id, new UndoRedoDataArcTo(wR, hR, stAng, swAng)), null);
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);
//History.Add(g_oUndoRedoGraphicObjects, historyitem_AutoShapes_Add_PathQuadBezTo, null, null, new UndoRedoDataGraphicObjects(this.Id, new UndoRedoDataQuadBezTo(x0, y0, x1, y1)), null);
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);
//History.Add(g_oUndoRedoGraphicObjects, historyitem_AutoShapes_Add_PathCubicBezTo, null, null, new UndoRedoDataGraphicObjects(this.Id, new UndoRedoDataCubicBezTo(x0, y0, x1, y1, x2, y2)), null);
this.ArrPathCommandInfo.push({id:bezier4, X0:x0, Y0:y0, X1:x1, Y1:y1, X2:x2, Y2:y2});
},
close: function()
{
//History.Add(g_oUndoRedoGraphicObjects, historyitem_AutoShapes_Add_PathClose, null, null, new UndoRedoDataGraphicObjects(this.Id, new UndoRedoDataClosePath()), null);
this.ArrPathCommandInfo.push({id:close});
},
init: function(gdLst)
{
if(this.ArrPathCommandInfo.length === this.ArrPathCommand.length)
{
this.ArrPathCommand.length = 0;
/*this.recalculate(gdLst);
return; */
}
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;
/*
var sin1 = Math.sin(stAng+swAng);
var cos1 = Math.cos(stAng+swAng);
var __x = cos1 / (wR*cw);
var __y = sin1 / (hR*ch);
var l = 1 / Math.sqrt(__x * __x + __y * __y);
var xc = lastX - l * cos1;
var yc = lastY - l * sin1;
lastX=xc+cw*wR*Math.cos(AngToEllPrm(stAng+swAng, wR, hR));
lastY=yc+ch*hR*Math.sin(AngToEllPrm(stAng+swAng, wR, hR));
*/
//lastX=lastX+wR*cw*(-Math.cos(stAng*cToRad)+Math.cos((stAng+swAng)*cToRad));
//lastY=lastY+hR*ch*(-Math.sin(stAng*cToRad)+Math.sin((stAng+swAng)*cToRad));
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();
//shape_drawer.drawFillStroke(true, this.fill, this.stroke && !shape_drawer.bIsNoStrokeAttack);
//bIsDrawLast = false;
//if (j < (l-1))
// shape_drawer._s();
break;
}
}
}
if (bIsDrawLast)
{
shape_drawer.drawFillStroke(true, this.fill, this.stroke && !shape_drawer.bIsNoStrokeAttack);
}
shape_drawer._e();
/*
shape_drawer.df(this.fill);
if (this.stroke && !shape_drawer.bIsNoStrokeAttack)
{
shape_drawer.ds();
}
*/
},
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));
}
"use strict";
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();
};
}
\ No newline at end of file
"use strict";
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();
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment