Commit 2eb55c87 authored by Dmitry.Vikulov's avatar Dmitry.Vikulov Committed by Alexander.Trofimov

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@47640 954022d7-b5bf-4e40-9824-e11837661b57
parent 22f31835
......@@ -2023,6 +2023,8 @@ function DrawingObjects() {
var overlayCtx = null;
var shapeCtx = null;
var shapeOverlayCtx = null;
var trackOverlay = null;
var autoShapeTrack = null;
var aObjects = null;
......@@ -2055,8 +2057,12 @@ function DrawingObjects() {
overlayCtx = currentSheet.overlayCtx;
shapeCtx = currentSheet.shapeCtx;
shapeOverlayCtx = currentSheet.shapeOverlayCtx;
trackOverlay = new COverlay();
trackOverlay.init( shapeOverlayCtx.m_oContext, "ws-canvas-overlay", 0, 0, shapeOverlayCtx.m_lWidthPix, shapeOverlayCtx.m_lHeightPix, shapeOverlayCtx.m_dWidthMM, shapeOverlayCtx.m_dHeightMM );
autoShapeTrack = new CAutoshapeTrack();
autoShapeTrack.init( shapeOverlayCtx, 0, 0, shapeOverlayCtx.m_dWidthMM, shapeOverlayCtx.m_dHeightMM, shapeOverlayCtx.m_lWidthPix , shapeOverlayCtx.m_lHeightPix );
autoShapeTrack.init( trackOverlay, 0, 0, shapeOverlayCtx.m_lWidthPix, shapeOverlayCtx.m_lHeightPix, shapeOverlayCtx.m_dWidthMM, shapeOverlayCtx.m_dHeightMM );
isViewerMode = function() { return worksheet._trigger("getViewerMode"); };
......@@ -3809,6 +3815,9 @@ function DrawingObjects() {
_this.showDrawingObjects(false);
}
_this.addGraphicGroup = function() {
}
_this.insertUngroupedObjects = function(idGroup, aGraphics) {
if ( idGroup && aGraphics.length ) {
......
......@@ -157,8 +157,9 @@
<script src="../Common/Charts/libraries/rgbcolor.js"></script>
<!--for shapes-->
<script src="../Word/Drawing/Graphics.js"></script>
<script src="../Word/Drawing/Overlay.js"></script>
<script src="model/DrawingObjects/Graphics.js"></script>
<script src="model/DrawingObjects/Overlay.js"></script>
<script src="model/DrawingObjects/Controls.js"></script>
<script src="model/DrawingObjects/DrawingObjectsController.js"></script>
<script src="model/DrawingObjects/States.js"></script>
......
function CBounds()
{
this.L = 0; // ����� �������
this.T = 0; // ������� �������
this.R = 0; // ������ ������� (���� ������ ���� isAbsR, �� ��� ���������� ������, � �� R)
this.B = 0; // ������� ������� (���� ������ ���� isAbsB, �� ��� ���������� ������, � �� B)
this.isAbsL = false;
this.isAbsT = false;
this.isAbsR = false;
this.isAbsB = false;
this.AbsW = -1;
this.AbsH = -1;
this.SetParams = function(_l,_t,_r,_b,abs_l,abs_t,abs_r,abs_b,absW,absH)
{
this.L = _l;
this.T = _t;
this.R = _r;
this.B = _b;
this.isAbsL = abs_l;
this.isAbsT = abs_t;
this.isAbsR = abs_r;
this.isAbsB = abs_b;
this.AbsW = absW;
this.AbsH = absH;
}
}
function CAbsolutePosition()
{
this.L = 0;
this.T = 0;
this.R = 0;
this.B = 0;
}
var g_anchor_left = 1;
var g_anchor_top = 2;
var g_anchor_right = 4;
var g_anchor_bottom = 8;
function CControl()
{
this.Bounds = new CBounds();
this.Anchor = g_anchor_left | g_anchor_top;
this.Name = null;
this.Parent = null;
this.TabIndex = null;
this.HtmlElement = null;
this.AbsolutePosition = new CBounds();
this.Resize = function(_width,_height,api)
{
if ((null == this.Parent) || (null == this.HtmlElement))
return;
var _x = 0;
var _y = 0;
var _r = 0;
var _b = 0;
var hor_anchor = (this.Anchor & 0x05);
var ver_anchor = (this.Anchor & 0x0A);
if (g_anchor_left == hor_anchor)
{
if (this.Bounds.isAbsL)
_x = this.Bounds.L;
else
_x = (this.Bounds.L * _width / 1000);
if (-1 != this.Bounds.AbsW)
_r = _x + this.Bounds.AbsW;
else
{
if (this.Bounds.isAbsR)
_r = (_width - this.Bounds.R);
else
_r = this.Bounds.R * _width / 1000;
}
}
else if (g_anchor_right == hor_anchor)
{
if (this.Bounds.isAbsR)
_r = (_width - this.Bounds.R);
else
_r = (this.Bounds.R * _width / 1000);
if (-1 != this.Bounds.AbsW)
_x = _r - this.Bounds.AbsW;
else
{
if (this.Bounds.isAbsL)
_x = this.Bounds.L;
else
_x = this.Bounds.L * _width / 1000;
}
}
else if ((g_anchor_left | g_anchor_right) == hor_anchor)
{
if (this.Bounds.isAbsL)
_x = this.Bounds.L;
else
_x = (this.Bounds.L * _width / 1000);
if (this.Bounds.isAbsR)
_r = (_width - this.Bounds.R);
else
_r = (this.Bounds.R * _width / 1000);
}
else
{
_x = this.Bounds.L;
_r = this.Bounds.R;
}
if (g_anchor_top == ver_anchor)
{
if (this.Bounds.isAbsT)
_y = this.Bounds.T;
else
_y = (this.Bounds.T * _height / 1000);
if (-1 != this.Bounds.AbsH)
_b = _y + this.Bounds.AbsH;
else
{
if (this.Bounds.isAbsB)
_b = (_height - this.Bounds.B);
else
_b = this.Bounds.B * _height / 1000;
}
}
else if (g_anchor_bottom == ver_anchor)
{
if (this.Bounds.isAbsB)
_b = (_height - this.Bounds.B);
else
_b = (this.Bounds.B * _height / 1000);
if (-1 != this.Bounds.AbsH)
_y = _b - this.Bounds.AbsH;
else
{
if (this.Bounds.isAbsT)
_y = this.Bounds.T;
else
_y = this.Bounds.T * _height / 1000;
}
}
else if ((g_anchor_top | g_anchor_bottom) == ver_anchor)
{
if (this.Bounds.isAbsT)
_y = this.Bounds.T;
else
_y = (this.Bounds.T * _height / 1000);
if (this.Bounds.isAbsB)
_b = (_height - this.Bounds.B);
else
_b = (this.Bounds.B * _height / 1000);
}
else
{
_y = this.Bounds.T;
_b = this.Bounds.B;
}
if (_r < _x)
_r = _x;
if (_b < _y)
_b = _y;
this.AbsolutePosition.L = _x;
this.AbsolutePosition.T = _y;
this.AbsolutePosition.R = _r;
this.AbsolutePosition.B = _b;
this.HtmlElement.style.left = ((_x * g_dKoef_mm_to_pix + 0.5) >> 0) + "px";
this.HtmlElement.style.top = ((_y * g_dKoef_mm_to_pix + 0.5) >> 0) + "px";
this.HtmlElement.style.width = (((_r - _x) * g_dKoef_mm_to_pix + 0.5) >> 0) + "px";
this.HtmlElement.style.height = (((_b - _y) * g_dKoef_mm_to_pix + 0.5) >> 0) + "px";
if (api !== undefined && api.CheckRetinaElement && api.CheckRetinaElement(this.HtmlElement))
{
var _W = ((_r - _x) * g_dKoef_mm_to_pix + 0.5) >> 0;
var _H = ((_b - _y) * g_dKoef_mm_to_pix + 0.5) >> 0;
this.HtmlElement.width = _W << 1;
this.HtmlElement.height = _H << 1;
}
else
{
this.HtmlElement.width = ((_r - _x) * g_dKoef_mm_to_pix + 0.5) >> 0;
this.HtmlElement.height = ((_b - _y) * g_dKoef_mm_to_pix + 0.5) >> 0;
}
}
}
function CControlContainer()
{
this.Bounds = new CBounds();
this.Anchor = g_anchor_left | g_anchor_top;
this.Name = null;
this.Parent = null;
this.TabIndex = null;
this.HtmlElement = null;
this.AbsolutePosition = new CBounds();
this.Controls = new Array();
this.AddControl = function(ctrl)
{
ctrl.Parent = this;
this.Controls[this.Controls.length] = ctrl;
}
this.Resize = function(_width,_height,api)
{
if (null == this.Parent)
{
this.AbsolutePosition.L = 0;
this.AbsolutePosition.T = 0;
this.AbsolutePosition.R = _width;
this.AbsolutePosition.B = _height;
if (null != this.HtmlElement)
{
var lCount = this.Controls.length;
for (var i = 0; i < lCount; i++)
{
this.Controls[i].Resize(_width,_height,api);
}
}
return;
}
var _x = 0;
var _y = 0;
var _r = 0;
var _b = 0;
var hor_anchor = (this.Anchor & 0x05);
var ver_anchor = (this.Anchor & 0x0A);
if (g_anchor_left == hor_anchor)
{
if (this.Bounds.isAbsL)
_x = this.Bounds.L;
else
_x = (this.Bounds.L * _width / 1000);
if (-1 != this.Bounds.AbsW)
_r = _x + this.Bounds.AbsW;
else
{
if (this.Bounds.isAbsR)
_r = (_width - this.Bounds.R);
else
_r = this.Bounds.R * _width / 1000;
}
}
else if (g_anchor_right == hor_anchor)
{
if (this.Bounds.isAbsR)
_r = (_width - this.Bounds.R);
else
_r = (this.Bounds.R * _width / 1000);
if (-1 != this.Bounds.AbsW)
_x = _r - this.Bounds.AbsW;
else
{
if (this.Bounds.isAbsL)
_x = this.Bounds.L;
else
_x = this.Bounds.L * _width / 1000;
}
}
else if ((g_anchor_left | g_anchor_right) == hor_anchor)
{
if (this.Bounds.isAbsL)
_x = this.Bounds.L;
else
_x = (this.Bounds.L * _width / 1000);
if (this.Bounds.isAbsR)
_r = (_width - this.Bounds.R);
else
_r = (this.Bounds.R * _width / 1000);
}
else
{
_x = this.Bounds.L;
_r = this.Bounds.R;
}
if (g_anchor_top == ver_anchor)
{
if (this.Bounds.isAbsT)
_y = this.Bounds.T;
else
_y = (this.Bounds.T * _height / 1000);
if (-1 != this.Bounds.AbsH)
_b = _y + this.Bounds.AbsH;
else
{
if (this.Bounds.isAbsB)
_b = (_height - this.Bounds.B);
else
_b = this.Bounds.B * _height / 1000;
}
}
else if (g_anchor_bottom == ver_anchor)
{
if (this.Bounds.isAbsB)
_b = (_height - this.Bounds.B);
else
_b = (this.Bounds.B * _height / 1000);
if (-1 != this.Bounds.AbsH)
_y = _b - this.Bounds.AbsH;
else
{
if (this.Bounds.isAbsT)
_y = this.Bounds.T;
else
_y = this.Bounds.T * _height / 1000;
}
}
else if ((g_anchor_top | g_anchor_bottom) == ver_anchor)
{
if (this.Bounds.isAbsT)
_y = this.Bounds.T;
else
_y = (this.Bounds.T * _height / 1000);
if (this.Bounds.isAbsB)
_b = (_height - this.Bounds.B);
else
_b = (this.Bounds.B * _height / 1000);
}
else
{
_y = this.Bounds.T;
_b = this.Bounds.B;
}
if (_r < _x)
_r = _x;
if (_b < _y)
_b = _y;
this.AbsolutePosition.L = _x;
this.AbsolutePosition.T = _y;
this.AbsolutePosition.R = _r;
this.AbsolutePosition.B = _b;
this.HtmlElement.style.left = ((_x * g_dKoef_mm_to_pix + 0.5) >> 0) + "px";
this.HtmlElement.style.top = ((_y * g_dKoef_mm_to_pix + 0.5) >> 0) + "px";
this.HtmlElement.style.width = (((_r - _x) * g_dKoef_mm_to_pix + 0.5) >> 0) + "px";
this.HtmlElement.style.height = (((_b - _y) * g_dKoef_mm_to_pix + 0.5) >> 0) + "px";
var lCount = this.Controls.length;
for (var i = 0; i < lCount; i++)
{
this.Controls[i].Resize(_r - _x,_b - _y, api);
}
}
}
function CreateControlContainer(name)
{
var ctrl = new CControlContainer();
ctrl.Name = name;
ctrl.HtmlElement = document.getElementById(name);
return ctrl;
}
function CreateControl(name)
{
var ctrl = new CControl();
ctrl.Name = name;
ctrl.HtmlElement = document.getElementById(name);
return ctrl;
}
\ No newline at end of file
function CClipManager()
{
this.clipRects = [];
this.curRect = new _rect();
this.BaseObject = null;
this.AddRect = function(x, y, w, h)
{
var _count = this.clipRects.length;
if (0 == _count)
{
this.curRect.x = x;
this.curRect.y = y;
this.curRect.w = w;
this.curRect.h = h;
var _r = new _rect();
_r.x = x;
_r.y = y;
_r.w = w;
_r.h = h;
this.clipRects[_count] = _r;
this.BaseObject.SetClip(this.curRect);
}
else
{
this.BaseObject.RemoveClip();
var _r = new _rect();
_r.x = x;
_r.y = y;
_r.w = w;
_r.h = h;
this.clipRects[_count] = _r;
this.curRect = this.IntersectRect(this.curRect, _r);
this.BaseObject.SetClip(this.curRect);
}
}
this.RemoveRect = function()
{
var _count = this.clipRects.length;
if (0 != _count)
{
this.clipRects.splice(_count - 1, 1);
--_count;
this.BaseObject.RemoveClip();
if (0 != _count)
{
this.curRect.x = this.clipRects[0].x;
this.curRect.y = this.clipRects[0].y;
this.curRect.w = this.clipRects[0].w;
this.curRect.h = this.clipRects[0].h;
for (var i = 1; i < _count; i++)
this.curRect = this.IntersectRect(this.curRect, this.clipRects[i]);
this.BaseObject.SetClip(this.curRect);
}
}
}
this.IntersectRect = function(r1, r2)
{
var res = new _rect();
res.x = Math.max(r1.x, r2.x);
res.y = Math.max(r1.y, r2.y);
res.w = Math.min(r1.x + r1.w, r2.x + r2.w) - res.x;
res.h = Math.min(r1.y + r1.h, r2.y + r2.h) - res.y;
if (0 > res.w)
res.w = 0;
if (0 > res.h)
res.h = 0;
return res;
}
}
function CPen()
{
this.Color = { R : 255, G : 255, B : 255, A : 255 };
this.Style = 0;
this.LineCap = 0;
this.LineJoin = 0;
this.LineWidth = 1;
}
function CBrush()
{
this.Color1 = { R : 255, G : 255, B : 255, A : 255 };
this.Color2 = { R : 255, G : 255, B : 255, A : 255 };
this.Type = 0;
}
var MATRIX_ORDER_PREPEND = 0;
var MATRIX_ORDER_APPEND = 1;
var bIsChrome = (null == window.chrome) ? 0 : 1;
var bIsSafari = (null == window.safari) ? 0 : 1;
var bIsIE = (/MSIE/g.test(navigator.userAgent)) ? true : false;
var bIsAndroid = (navigator.userAgent.indexOf("Android") >= 0 || navigator.userAgent.indexOf("android") >= 0) ? true : false;
function deg2rad(deg){
return deg * Math.PI / 180.0;
}
function rad2deg(rad){
return rad * 180.0 / Math.PI;
}
function CMatrix()
{
this.sx = 1.0;
this.shx = 0.0;
this.shy = 0.0;
this.sy = 1.0;
this.tx = 0.0;
this.ty = 0.0;
}
CMatrix.prototype =
{
Reset : function(){
this.sx = 1.0;
this.shx = 0.0;
this.shy = 0.0;
this.sy = 1.0;
this.tx = 0.0;
this.ty = 0.0;
},
// ���������
Multiply : function(matrix,order){
if (MATRIX_ORDER_PREPEND == order)
{
var m = new CMatrix();
m.sx = matrix.sx;
m.shx = matrix.shx;
m.shy = matrix.shy;
m.sy = matrix.sy;
m.tx = matrix.tx;
m.ty = matrix.ty;
m.Multiply(this, MATRIX_ORDER_APPEND);
this.sx = m.sx;
this.shx = m.shx;
this.shy = m.shy;
this.sy = m.sy;
this.tx = m.tx;
this.ty = m.ty;
}
else
{
var t0 = this.sx * matrix.sx + this.shy * matrix.shx;
var t2 = this.shx * matrix.sx + this.sy * matrix.shx;
var t4 = this.tx * matrix.sx + this.ty * matrix.shx + matrix.tx;
this.shy = this.sx * matrix.shy + this.shy * matrix.sy;
this.sy = this.shx * matrix.shy + this.sy * matrix.sy;
this.ty = this.tx * matrix.shy + this.ty * matrix.sy + matrix.ty;
this.sx = t0;
this.shx = t2;
this.tx = t4;
}
return this;
},
// � ������ ������� ������ ���������� (��� �������� �����������)
Translate : function(x,y,order){
var m = new CMatrix();
m.tx = x;
m.ty = y;
this.Multiply(m,order);
},
Scale : function(x,y,order){
var m = new CMatrix();
m.sx = x;
m.sy = y;
this.Multiply(m,order);
},
Rotate : function(a,order){
var m = new CMatrix();
var rad = deg2rad(a);
m.sx = Math.cos(rad);
m.shx = Math.sin(rad);
m.shy = -Math.sin(rad);
m.sy = Math.cos(rad);
this.Multiply(m,order);
},
RotateAt : function(a,x,y,order){
this.Translate(-x,-y,order);
this.Rotate(a,order);
this.Translate(x,y,order);
},
// determinant
Determinant : function(){
return this.sx * this.sy - this.shy * this.shx;
},
// invert
Invert : function(){
var det = this.Determinant();
if (0.0001 > Math.abs(det))
return;
var d = 1 / det;
var t0 = this.sy * d;
this.sy = this.sx * d;
this.shy = -this.shy * d;
this.shx = -this.shx * d;
var t4 = -this.tx * t0 - this.ty * this.shx;
this.ty = -this.tx * this.shy - this.ty * this.sy;
this.sx = t0;
this.tx = t4;
return this;
},
// transform point
TransformPointX : function(x,y){
return x * this.sx + y * this.shx + this.tx;
},
TransformPointY : function(x,y){
return x * this.shy + y * this.sy + this.ty;
},
// calculate rotate angle
GetRotation : function(){
var x1 = 0.0;
var y1 = 0.0;
var x2 = 1.0;
var y2 = 0.0;
this.TransformPoint(x1, y1);
this.TransformPoint(x2, y2);
var a = Math.atan2(y2-y1,x2-x1);
return rad2deg(a);
},
// ������� ���������
CreateDublicate : function(){
var m = new CMatrix();
m.sx = this.sx;
m.shx = this.shx;
m.shy = this.shy;
m.sy = this.sy;
m.tx = this.tx;
m.ty = this.ty;
return m;
},
IsIdentity : function()
{
if (this.sx == 1.0 &&
this.shx == 0.0 &&
this.shy == 0.0 &&
this.sy == 1.0 &&
this.tx == 0.0 &&
this.ty == 0.0)
{
return true;
}
return false;
},
IsIdentity2 : function()
{
if (this.sx == 1.0 &&
this.shx == 0.0 &&
this.shy == 0.0 &&
this.sy == 1.0)
{
return true;
}
return false;
}
};
function CMatrixL()
{
this.sx = 1.0;
this.shx = 0.0;
this.shy = 0.0;
this.sy = 1.0;
this.tx = 0.0;
this.ty = 0.0;
}
CMatrixL.prototype =
{
CreateDublicate : function()
{
var m = new CMatrixL();
m.sx = this.sx;
m.shx = this.shx;
m.shy = this.shy;
m.sy = this.sy;
m.tx = this.tx;
m.ty = this.ty;
return m;
},
Reset : function()
{
this.sx = 1.0;
this.shx = 0.0;
this.shy = 0.0;
this.sy = 1.0;
this.tx = 0.0;
this.ty = 0.0;
},
TransformPointX : function(x,y)
{
return x * this.sx + y * this.shx + this.tx;
},
TransformPointY : function(x,y)
{
return x * this.shy + y * this.sy + this.ty;
}
};
function CGlobalMatrixTransformer()
{
this.TranslateAppend = function(m, _tx, _ty)
{
m.tx += _tx;
m.ty += _ty;
}
this.ScaleAppend = function(m, _sx, _sy)
{
m.sx *= _sx;
m.shx *= _sx;
m.shy *= _sy;
m.sy *= _sy;
m.tx *= _sx;
m.ty *= _sy;
}
this.RotateRadAppend = function(m, _rad)
{
var _sx = Math.cos(_rad);
var _shx = Math.sin(_rad);
var _shy = -Math.sin(_rad);
var _sy = Math.cos(_rad);
var t0 = m.sx * _sx + m.shy * _shx;
var t2 = m.shx * _sx + m.sy * _shx;
var t4 = m.tx * _sx + m.ty * _shx;
m.shy = m.sx * _shy + m.shy * _sy;
m.sy = m.shx * _shy + m.sy * _sy;
m.ty = m.tx * _shy + m.ty * _sy;
m.sx = t0;
m.shx = t2;
m.tx = t4;
}
this.MultiplyAppend = function(m1, m2)
{
var t0 = m1.sx * m2.sx + m1.shy * m2.shx;
var t2 = m1.shx * m2.sx + m1.sy * m2.shx;
var t4 = m1.tx * m2.sx + m1.ty * m2.shx + m2.tx;
m1.shy = m1.sx * m2.shy + m1.shy * m2.sy;
m1.sy = m1.shx * m2.shy + m1.sy * m2.sy;
m1.ty = m1.tx * m2.shy + m1.ty * m2.sy + m2.ty;
m1.sx = t0;
m1.shx = t2;
m1.tx = t4;
}
this.Invert = function(m)
{
var newM = m.CreateDublicate();
var det = newM.sx * newM.sy - newM.shy * newM.shx;
if (0.0001 > Math.abs(det))
return newM;
var d = 1 / det;
var t0 = newM.sy * d;
newM.sy = newM.sx * d;
newM.shy = -newM.shy * d;
newM.shx = -newM.shx * d;
var t4 = -newM.tx * t0 - newM.ty * newM.shx;
newM.ty = -newM.tx * newM.shy - newM.ty * newM.sy;
newM.sx = t0;
newM.tx = t4;
return newM;
}
this.MultiplyAppendInvert = function(m1, m2)
{
var m = this.Invert(m2);
this.MultiplyAppend(m1, m);
}
this.MultiplyPrepend = function(m1, m2)
{
var m = new CMatrixL();
m.sx = m2.sx;
m.shx = m2.shx;
m.shy = m2.shy;
m.sy = m2.sy;
m.tx = m2.tx;
m.ty = m2.ty;
this.MultiplyAppend(m, m1);
m1.sx = m.sx;
m1.shx = m.shx;
m1.shy = m.shy;
m1.sy = m.sy;
m1.tx = m.tx;
m1.ty = m.ty;
}
this.CreateDublicateM = function(matrix)
{
var m = new CMatrixL();
m.sx = matrix.sx;
m.shx = matrix.shx;
m.shy = matrix.shy;
m.sy = matrix.sy;
m.tx = matrix.tx;
m.ty = matrix.ty;
}
this.IsIdentity = function(m)
{
if (m.sx == 1.0 &&
m.shx == 0.0 &&
m.shy == 0.0 &&
m.sy == 1.0 &&
m.tx == 0.0 &&
m.ty == 0.0)
{
return true;
}
return false;
}
this.IsIdentity2 = function(m)
{
if (m.sx == 1.0 &&
m.shx == 0.0 &&
m.shy == 0.0 &&
m.sy == 1.0)
{
return true;
}
return false;
}
}
var global_MatrixTransformer = new CGlobalMatrixTransformer();
function CGraphics()
{
this.m_oContext = null;
this.m_dWidthMM = 0;
this.m_dHeightMM = 0;
this.m_lWidthPix = 0;
this.m_lHeightPix = 0;
this.m_dDpiX = 96.0;
this.m_dDpiY = 96.0;
this.m_bIsBreak = false;
this.textBB_l = 10000;
this.textBB_t = 10000;
this.textBB_r = -10000;
this.textBB_b = -10000;
this.m_oPen = new CPen();
this.m_oBrush = new CBrush();
this.m_oFontManager = null;
this.m_bIsFillTextCanvasColor = 0;
this.m_oCoordTransform = new CMatrixL();
this.m_oBaseTransform = new CMatrixL();
this.m_oTransform = new CMatrixL();
this.m_oFullTransform = new CMatrixL();
this.m_oInvertFullTransform = new CMatrixL();
this.ArrayPoints = null;
this.m_oCurFont = null;
// RFonts
this.m_oTextPr = null;
this.m_oLastFont = new CFontSetup();
this.m_bIntegerGrid = true;
this.ClipManager = new CClipManager();
this.ClipManager.BaseObject = this;
this.TextureFillTransformScaleX = 1;
this.TextureFillTransformScaleY = 1;
this.IsThumbnail = false;
this.GrState = new CGrState();
this.GrState.Parent = this;
this.globalAlpha = 1;
this.TextClipRect = null;
this.IsClipContext = false;
}
CGraphics.prototype =
{
init : function(context,width_px,height_px,width_mm,height_mm)
{
this.m_oContext = context;
this.m_lHeightPix = height_px;
this.m_lWidthPix = width_px;
this.m_dWidthMM = width_mm;
this.m_dHeightMM = height_mm;
this.m_dDpiX = 25.4 * this.m_lWidthPix / this.m_dWidthMM;
this.m_dDpiY = 25.4 * this.m_lHeightPix / this.m_dHeightMM;
this.m_oCoordTransform.sx = this.m_dDpiX / 25.4;
this.m_oCoordTransform.sy = this.m_dDpiY / 25.4;
this.TextureFillTransformScaleX = 1 / this.m_oCoordTransform.sx;
this.TextureFillTransformScaleY = 1 / this.m_oCoordTransform.sy;
if (this.IsThumbnail)
{
this.TextureFillTransformScaleX *= (width_px / (width_mm * g_dKoef_mm_to_pix));
this.TextureFillTransformScaleY *= (height_px / (height_mm * g_dKoef_mm_to_pix))
}
if (true == this.m_oContext.mozImageSmoothingEnabled)
this.m_oContext.mozImageSmoothingEnabled = false;
this.m_oContext.save();
},
EndDraw : function()
{
},
put_GlobalAlpha : function(enable, alpha)
{
if (false === enable)
{
this.globalAlpha = 1;
this.m_oContext.globalAlpha = 1;
}
else
{
this.globalAlpha = alpha;
this.m_oContext.globalAlpha = alpha;
}
},
// pen methods
p_color : function(r,g,b,a)
{
var _c = this.m_oPen.Color;
_c.R = r;
_c.G = g;
_c.B = b;
_c.A = a;
this.m_oContext.strokeStyle = "rgba(" + _c.R + "," + _c.G + "," + _c.B + "," + (_c.A / 255) + ")";
},
p_width : function(w)
{
this.m_oPen.LineWidth = w / 1000;
if (!this.m_bIntegerGrid)
this.m_oContext.lineWidth = this.m_oPen.LineWidth;
else
{
var _m = this.m_oFullTransform;
var x = _m.sx + _m.shx;
var y = _m.sy + _m.shy;
var koef = Math.sqrt((x * x + y * y) / 2);
this.m_oContext.lineWidth = this.m_oPen.LineWidth * koef;
}
},
// brush methods
b_color1 : function(r,g,b,a)
{
var _c = this.m_oBrush.Color1;
_c.R = r;
_c.G = g;
_c.B = b;
_c.A = a;
this.m_oContext.fillStyle = "rgba(" + _c.R + "," + _c.G + "," + _c.B + "," + (_c.A / 255) + ")";
this.m_bIsFillTextCanvasColor = 0;
},
b_color2 : function(r,g,b,a)
{
var _c = this.m_oBrush.Color2;
_c.R = r;
_c.G = g;
_c.B = b;
_c.A = a;
},
transform : function(sx,shy,shx,sy,tx,ty)
{
var _t = this.m_oTransform;
_t.sx = sx;
_t.shx = shx;
_t.shy = shy;
_t.sy = sy;
_t.tx = tx;
_t.ty = ty;
this.CalculateFullTransform();
if (false === this.m_bIntegerGrid)
{
var _ft = this.m_oFullTransform;
this.m_oContext.setTransform(_ft.sx,_ft.shy,_ft.shx,_ft.sy,_ft.tx,_ft.ty);
}
if (null != this.m_oFontManager)
{
this.m_oFontManager.SetTextMatrix(_t.sx,_t.shy,_t.shx,_t.sy,_t.tx,_t.ty);
}
},
CalculateFullTransform : function(isInvertNeed)
{
var _ft = this.m_oFullTransform;
var _t = this.m_oTransform;
_ft.sx = _t.sx;
_ft.shx = _t.shx;
_ft.shy = _t.shy;
_ft.sy = _t.sy;
_ft.tx = _t.tx;
_ft.ty = _t.ty;
global_MatrixTransformer.MultiplyAppend(_ft, this.m_oCoordTransform);
var _it = this.m_oInvertFullTransform;
_it.sx = _ft.sx;
_it.shx = _ft.shx;
_it.shy = _ft.shy;
_it.sy = _ft.sy;
_it.tx = _ft.tx;
_it.ty = _ft.ty;
if (false !== isInvertNeed)
{
global_MatrixTransformer.MultiplyAppendInvert(_it, _t);
}
},
// path commands
_s : function()
{
this.m_oContext.beginPath();
},
_e : function()
{
this.m_oContext.beginPath();
},
_z : function()
{
this.m_oContext.closePath();
},
_m : function(x,y)
{
if (false === this.m_bIntegerGrid)
{
this.m_oContext.moveTo(x,y);
if (this.ArrayPoints != null)
this.ArrayPoints[this.ArrayPoints.length] = {x: x, y: y};
}
else
{
var _x = (this.m_oFullTransform.TransformPointX(x,y)) >> 0;
var _y = (this.m_oFullTransform.TransformPointY(x,y)) >> 0;
this.m_oContext.moveTo(_x + 0.5,_y + 0.5);
}
},
_l : function(x,y)
{
if (false === this.m_bIntegerGrid)
{
this.m_oContext.lineTo(x,y);
if (this.ArrayPoints != null)
this.ArrayPoints[this.ArrayPoints.length] = {x: x, y: y};
}
else
{
var _x = (this.m_oFullTransform.TransformPointX(x,y)) >> 0;
var _y = (this.m_oFullTransform.TransformPointY(x,y)) >> 0;
this.m_oContext.lineTo(_x + 0.5,_y + 0.5);
}
},
_c : function(x1,y1,x2,y2,x3,y3)
{
if (false === this.m_bIntegerGrid)
{
this.m_oContext.bezierCurveTo(x1,y1,x2,y2,x3,y3);
if (this.ArrayPoints != null)
{
this.ArrayPoints[this.ArrayPoints.length] = {x: x1, y: y1};
this.ArrayPoints[this.ArrayPoints.length] = {x: x2, y: y2};
this.ArrayPoints[this.ArrayPoints.length] = {x: x3, y: y3};
}
}
else
{
var _x1 = (this.m_oFullTransform.TransformPointX(x1,y1)) >> 0;
var _y1 = (this.m_oFullTransform.TransformPointY(x1,y1)) >> 0;
var _x2 = (this.m_oFullTransform.TransformPointX(x2,y2)) >> 0;
var _y2 = (this.m_oFullTransform.TransformPointY(x2,y2)) >> 0;
var _x3 = (this.m_oFullTransform.TransformPointX(x3,y3)) >> 0;
var _y3 = (this.m_oFullTransform.TransformPointY(x3,y3)) >> 0;
this.m_oContext.bezierCurveTo(_x1 + 0.5,_y1 + 0.5,_x2 + 0.5,_y2 + 0.5,_x3 + 0.5,_y3 + 0.5);
}
},
_c2 : function(x1,y1,x2,y2)
{
if (false === this.m_bIntegerGrid)
{
this.m_oContext.quadraticCurveTo(x1,y1,x2,y2);
if (this.ArrayPoints != null)
{
this.ArrayPoints[this.ArrayPoints.length] = {x: x1, y: y1};
this.ArrayPoints[this.ArrayPoints.length] = {x: x2, y: y2};
}
}
else
{
var _x1 = (this.m_oFullTransform.TransformPointX(x1,y1)) >> 0;
var _y1 = (this.m_oFullTransform.TransformPointY(x1,y1)) >> 0;
var _x2 = (this.m_oFullTransform.TransformPointX(x2,y2)) >> 0;
var _y2 = (this.m_oFullTransform.TransformPointY(x2,y2)) >> 0;
this.m_oContext.quadraticCurveTo(_x1 + 0.5,_y1 + 0.5,_x2 + 0.5,_y2 + 0.5);
}
},
ds : function()
{
this.m_oContext.stroke();
},
df : function()
{
this.m_oContext.fill();
},
// canvas state
save : function()
{
this.m_oContext.save();
},
restore : function()
{
this.m_oContext.restore();
},
clip : function()
{
this.m_oContext.clip();
},
reset : function()
{
this.m_oTransform.Reset();
this.CalculateFullTransform(false);
this.m_oContext.setTransform(this.m_oCoordTransform.sx,0,0,this.m_oCoordTransform.sy,0, 0);
},
transform3 : function(m, isNeedInvert)
{
var _t = this.m_oTransform;
_t.sx = m.sx;
_t.shx = m.shx;
_t.shy = m.shy;
_t.sy = m.sy;
_t.tx = m.tx;
_t.ty = m.ty;
this.CalculateFullTransform(isNeedInvert);
var _ft = this.m_oFullTransform;
this.m_oContext.setTransform(_ft.sx,_ft.shy,_ft.shx,_ft.sy,_ft.tx,_ft.ty);
// теперь трансформ выставляется ТОЛЬКО при загрузке шрифта. Здесь другого быть и не может
/*
if (null != this.m_oFontManager && false !== isNeedInvert)
{
this.m_oFontManager.SetTextMatrix(this.m_oTransform.sx,this.m_oTransform.shy,this.m_oTransform.shx,
this.m_oTransform.sy,this.m_oTransform.tx,this.m_oTransform.ty);
}
*/
},
FreeFont : function()
{
// это чтобы не сбросился кэш при отрисовке следующего шейпа
this.m_oFontManager.m_pFont = null;
},
// images
drawImage2 : function(img,x,y,w,h,alpha,srcRect)
{
var isA = (undefined !== alpha && null != alpha && 255 != alpha);
var _oldGA = 0;
if (isA)
{
_oldGA = this.m_oContext.globalAlpha;
this.m_oContext.globalAlpha = alpha / 255;
}
if (false === this.m_bIntegerGrid)
{
if (!srcRect)
{
// тут нужно проверить, можно ли нарисовать точно. т.е. может картинка ровно такая, какая нужна.
if (!global_MatrixTransformer.IsIdentity2(this.m_oTransform))
{
this.m_oContext.drawImage(img,x,y,w,h);
}
else
{
var xx = this.m_oFullTransform.TransformPointX(x, y);
var yy = this.m_oFullTransform.TransformPointY(x, y);
var rr = this.m_oFullTransform.TransformPointX(x + w, y + h);
var bb = this.m_oFullTransform.TransformPointY(x + w, y + h);
var ww = rr - xx;
var hh = bb - yy;
if (Math.abs(img.width - ww) < 2 && Math.abs(img.height - hh) < 2)
{
// рисуем точно
this.m_oContext.setTransform(1, 0, 0, 1, 0, 0);
this.m_oContext.drawImage(img, xx >> 0, yy >> 0);
var _ft = this.m_oFullTransform;
this.m_oContext.setTransform(_ft.sx,_ft.shy,_ft.shx,_ft.sy,_ft.tx,_ft.ty);
}
else
{
this.m_oContext.drawImage(img,x,y,w,h);
}
}
}
else
{
var _w = img.width;
var _h = img.height;
if (_w > 0 && _h > 0)
{
var __w = w;
var __h = h;
var _delW = Math.max(0, -srcRect.l) + Math.max(0, srcRect.r - 100) + 100;
var _delH = Math.max(0, -srcRect.t) + Math.max(0, srcRect.b - 100) + 100;
var _sx = 0;
if (srcRect.l > 0 && srcRect.l < 100)
_sx = Math.min((_w * srcRect.l / 100) >> 0, _w - 1);
else if (srcRect.l < 0)
{
var _off = ((-srcRect.l / _delW) * __w);
x += _off;
w -= _off;
}
var _sy = 0;
if (srcRect.t > 0 && srcRect.t < 100)
_sy = Math.min((_h * srcRect.t / 100) >> 0, _h - 1);
else if (srcRect.t < 0)
{
var _off = ((-srcRect.t / _delH) * __h);
y += _off;
h -= _off;
}
var _sr = _w;
if (srcRect.r > 0 && srcRect.r < 100)
_sr = Math.max(Math.min((_w * srcRect.r / 100) >> 0, _w - 1), _sx);
else if (srcRect.r > 100)
{
var _off = ((srcRect.r - 100) / _delW) * __w;
w -= _off;
}
var _sb = _h;
if (srcRect.b > 0 && srcRect.b < 100)
_sb = Math.max(Math.min((_h * srcRect.b / 100) >> 0, _h - 1), _sy);
else if (srcRect.b > 100)
{
var _off = ((srcRect.b - 100) / _delH) * __h;
h -= _off;
}
this.m_oContext.drawImage(img,_sx,_sy,_sr-_sx,_sb-_sy,x,y,w,h);
}
else
{
this.m_oContext.drawImage(img,x,y,w,h);
}
}
}
else
{
var _x1 = (this.m_oFullTransform.TransformPointX(x,y)) >> 0;
var _y1 = (this.m_oFullTransform.TransformPointY(x,y)) >> 0;
var _x2 = (this.m_oFullTransform.TransformPointX(x+w,y+h)) >> 0;
var _y2 = (this.m_oFullTransform.TransformPointY(x+w,y+h)) >> 0;
x = _x1;
y = _y1;
w = _x2 - _x1;
h = _y2 - _y1;
if (!srcRect)
{
// тут нужно проверить, можно ли нарисовать точно. т.е. может картинка ровно такая, какая нужна.
if (!global_MatrixTransformer.IsIdentity2(this.m_oTransform))
{
this.m_oContext.drawImage(img,_x1,_y1,w,h);
}
else
{
if (Math.abs(img.width - w) < 2 && Math.abs(img.height - h) < 2)
{
// рисуем точно
this.m_oContext.drawImage(img, x, y);
}
else
{
this.m_oContext.drawImage(img,_x1,_y1,w,h);
}
}
}
else
{
var _w = img.width;
var _h = img.height;
if (_w > 0 && _h > 0)
{
var __w = w;
var __h = h;
var _delW = Math.max(0, -srcRect.l) + Math.max(0, srcRect.r - 100) + 100;
var _delH = Math.max(0, -srcRect.t) + Math.max(0, srcRect.b - 100) + 100;
var _sx = 0;
if (srcRect.l > 0 && srcRect.l < 100)
_sx = Math.min((_w * srcRect.l / 100) >> 0, _w - 1);
else if (srcRect.l < 0)
{
var _off = ((-srcRect.l / _delW) * __w);
x += _off;
w -= _off;
}
var _sy = 0;
if (srcRect.t > 0 && srcRect.t < 100)
_sy = Math.min((_h * srcRect.t / 100) >> 0, _h - 1);
else if (srcRect.t < 0)
{
var _off = ((-srcRect.t / _delH) * __h);
y += _off;
h -= _off;
}
var _sr = _w;
if (srcRect.r > 0 && srcRect.r < 100)
_sr = Math.max(Math.min((_w * srcRect.r / 100) >> 0, _w - 1), _sx);
else if (srcRect.r > 100)
{
var _off = ((srcRect.r - 100) / _delW) * __w;
w -= _off;
}
var _sb = _h;
if (srcRect.b > 0 && srcRect.b < 100)
_sb = Math.max(Math.min((_h * srcRect.b / 100) >> 0, _h - 1), _sy);
else if (srcRect.b > 100)
{
var _off = ((srcRect.b - 100) / _delH) * __h;
h -= _off;
}
this.m_oContext.drawImage(img,_sx,_sy,_sr-_sx,_sb-_sy,x,y,w,h);
}
else
{
this.m_oContext.drawImage(img,x,y,w,h);
}
}
}
if (isA)
{
this.m_oContext.globalAlpha = _oldGA;
}
},
drawImage : function(img,x,y,w,h,alpha,srcRect,nativeImage)
{
if (nativeImage)
{
this.drawImage2(nativeImage,x,y,w,h,alpha,srcRect);
return;
}
var _img = editor.ImageLoader.map_image_index[img];
if (_img != undefined && _img.Status == ImageLoadStatus.Loading)
{
// TODO: IMAGE_LOADING
}
else if (_img != undefined && _img.Image != null)
{
this.drawImage2(_img.Image,x,y,w,h,alpha,srcRect);
}
else
{
var _x = x;
var _y = y;
var _r = x+w;
var _b = y+h;
if (this.m_bIntegerGrid)
{
_x = this.m_oFullTransform.TransformPointX(x,y);
_y = this.m_oFullTransform.TransformPointY(x,y);
_r = this.m_oFullTransform.TransformPointX(x+w,y+h);
_b = this.m_oFullTransform.TransformPointY(x+w,y+h);
}
var ctx = this.m_oContext;
var old_p = ctx.lineWidth;
ctx.beginPath();
ctx.moveTo(_x,_y);
ctx.lineTo(_r,_b);
ctx.moveTo(_r,_y);
ctx.lineTo(_x,_b);
ctx.strokeStyle = "#FF0000";
ctx.stroke();
ctx.beginPath();
ctx.moveTo(_x,_y);
ctx.lineTo(_r,_y);
ctx.lineTo(_r,_b);
ctx.lineTo(_x,_b);
ctx.closePath();
ctx.lineWidth = 1;
ctx.strokeStyle = "#000000";
ctx.stroke();
ctx.beginPath();
ctx.lineWidth = old_p;
ctx.strokeStyle = "rgba(" + this.m_oPen.Color.R + "," + this.m_oPen.Color.G + "," +
this.m_oPen.Color.B + "," + (this.m_oPen.Color.A / 255) + ")";
}
},
// text
GetFont : function()
{
return this.m_oCurFont;
},
font : function(font_id,font_size,matrix)
{
g_font_infos[g_map_font_index[font_id]].LoadFont(editor.FontLoader, this.m_oFontManager, font_size, 0, this.m_dDpiX, this.m_dDpiY, /*matrix*/undefined);
},
SetFont : function(font)
{
if (null == font)
return;
this.m_oCurFont =
{
FontFamily :
{
Index : font.FontFamily.Index,
Name : font.FontFamily.Name
},
FontSize : font.FontSize,
Bold : font.Bold,
Italic : font.Italic
};
if (-1 == font.FontFamily.Index || undefined === font.FontFamily.Index || null == font.FontFamily.Index)
font.FontFamily.Index = g_map_font_index[font.FontFamily.Name];
if (font.FontFamily.Index == undefined || font.FontFamily.Index == -1)
return;
var bItalic = true === font.Italic;
var bBold = true === font.Bold;
var oFontStyle = FontStyle.FontStyleRegular;
if ( !bItalic && bBold )
oFontStyle = FontStyle.FontStyleBold;
else if ( bItalic && !bBold )
oFontStyle = FontStyle.FontStyleItalic;
else if ( bItalic && bBold )
oFontStyle = FontStyle.FontStyleBoldItalic;
this.m_oLastFont.SetUpIndex = font.FontFamily.Index;
this.m_oLastFont.SetUpSize = font.FontSize;
this.m_oLastFont.SetUpStyle = oFontStyle;
g_font_infos[font.FontFamily.Index].LoadFont(g_font_loader, this.m_oFontManager, font.FontSize, oFontStyle, this.m_dDpiX, this.m_dDpiY, this.m_oTransform);
var _mD = this.m_oLastFont.SetUpMatrix;
var _mS = this.m_oTransform;
_mD.sx = _mS.sx;
_mD.sy = _mS.sy;
_mD.shx = _mS.shx;
_mD.shy = _mS.shy;
_mD.tx = _mS.tx;
_mD.ty = _mS.ty;
//this.m_oFontManager.SetTextMatrix(this.m_oTransform.sx,this.m_oTransform.shy,this.m_oTransform.shx,
// this.m_oTransform.sy,this.m_oTransform.tx,this.m_oTransform.ty);
},
SetTextPr : function(textPr)
{
this.m_oTextPr = textPr.Copy();
},
SetFontSlot : function(slot, fontSizeKoef)
{
var _rfonts = this.m_oTextPr.RFonts;
var _lastFont = this.m_oLastFont;
switch (slot)
{
case fontslot_ASCII:
{
_lastFont.Name = _rfonts.Ascii.Name;
_lastFont.Index = _rfonts.Ascii.Index;
if (_lastFont.Index == -1 || _lastFont.Index === undefined)
{
_lastFont.Index = g_map_font_index[_lastFont.Name];
}
_lastFont.Size = this.m_oTextPr.FontSize;
_lastFont.Bold = this.m_oTextPr.Bold;
_lastFont.Italic = this.m_oTextPr.Italic;
break;
}
case fontslot_CS:
{
_lastFont.Name = _rfonts.CS.Name;
_lastFont.Index = _rfonts.CS.Index;
if (_lastFont.Index == -1 || _lastFont.Index === undefined)
{
_lastFont.Index = g_map_font_index[_lastFont.Name];
}
_lastFont.Size = this.m_oTextPr.FontSizeCS;
_lastFont.Bold = this.m_oTextPr.BoldCS;
_lastFont.Italic = this.m_oTextPr.ItalicCS;
break;
}
case fontslot_EastAsia:
{
_lastFont.Name = _rfonts.EastAsia.Name;
_lastFont.Index = _rfonts.EastAsia.Index;
if (_lastFont.Index == -1 || _lastFont.Index === undefined)
{
_lastFont.Index = g_map_font_index[_lastFont.Name];
}
_lastFont.Size = this.m_oTextPr.FontSize;
_lastFont.Bold = this.m_oTextPr.Bold;
_lastFont.Italic = this.m_oTextPr.Italic;
break;
}
case fontslot_HAnsi:
default:
{
_lastFont.Name = _rfonts.HAnsi.Name;
_lastFont.Index = _rfonts.HAnsi.Index;
if (_lastFont.Index == -1 || _lastFont.Index === undefined)
{
_lastFont.Index = g_map_font_index[_lastFont.Name];
}
_lastFont.Size = this.m_oTextPr.FontSize;
_lastFont.Bold = this.m_oTextPr.Bold;
_lastFont.Italic = this.m_oTextPr.Italic;
break;
}
}
if (undefined !== fontSizeKoef)
_lastFont.Size *= fontSizeKoef;
var _style = 0;
if (_lastFont.Italic)
_style += 2;
if (_lastFont.Bold)
_style += 1;
if (_lastFont.Index != _lastFont.SetUpIndex || _lastFont.Size != _lastFont.SetUpSize || _style != _lastFont.SetUpStyle)
{
_lastFont.SetUpIndex = _lastFont.Index;
_lastFont.SetUpSize = _lastFont.Size;
_lastFont.SetUpStyle = _style;
g_font_infos[_lastFont.SetUpIndex].LoadFont(g_font_loader, this.m_oFontManager, _lastFont.SetUpSize, _lastFont.SetUpStyle, this.m_dDpiX, this.m_dDpiY, this.m_oTransform);
}
else
{
var _mD = this.m_oLastFont.SetUpMatrix;
var _mS = this.m_oTransform;
if (_mD.sx != _mS.sx || _mD.sy != _mS.sy || _mD.shx != _mS.shx || _mD.shy != _mS.shy || _mD.tx != _mS.tx || _mD.ty != _mS.ty)
{
_mD.sx = _mS.sx;
_mD.sy = _mS.sy;
_mD.shx = _mS.shx;
_mD.shy = _mS.shy;
_mD.tx = _mS.tx;
_mD.ty = _mS.ty;
this.m_oFontManager.SetTextMatrix(_mD.sx,_mD.shy,_mD.shx,_mD.sy,_mD.tx,_mD.ty);
}
}
//this.m_oFontManager.SetTextMatrix(this.m_oTransform.sx,this.m_oTransform.shy,this.m_oTransform.shx,
// this.m_oTransform.sy,this.m_oTransform.tx,this.m_oTransform.ty);
},
GetTextPr : function()
{
return this.m_oTextPr;
},
FillText : function(x,y,text)
{
// убыстеренный вариант. здесь везде заточка на то, что приходит одна буква
if (this.m_bIsBreak)
return;
var _x = this.m_oInvertFullTransform.TransformPointX(x,y);
var _y = this.m_oInvertFullTransform.TransformPointY(x,y);
try
{
this.m_oFontManager.LoadString2C(text,_x,_y);
}
catch(err)
{
}
if (false === this.m_bIntegerGrid)
{
this.m_oContext.setTransform(1,0,0,1,0,0);
}
var pGlyph = this.m_oFontManager.m_oGlyphString.m_pGlyphsBuffer[0];
if (null == pGlyph)
return;
if (null != pGlyph.oBitmap)
{
this.private_FillGlyph(pGlyph);
}
if (false === this.m_bIntegerGrid)
{
this.m_oContext.setTransform(this.m_oFullTransform.sx,this.m_oFullTransform.shy,this.m_oFullTransform.shx,
this.m_oFullTransform.sy,this.m_oFullTransform.tx,this.m_oFullTransform.ty);
}
},
t : function(text,x,y)
{
if (this.m_bIsBreak)
return;
var _x = this.m_oInvertFullTransform.TransformPointX(x,y);
var _y = this.m_oInvertFullTransform.TransformPointY(x,y);
try
{
this.m_oFontManager.LoadString2(text,_x,_y);
}
catch(err)
{
}
this.m_oContext.setTransform(1,0,0,1,0,0);
while (true)
{
var pGlyph = this.m_oFontManager.GetNextChar2();
if (null == pGlyph)
break;
if (null != pGlyph.oBitmap)
{
this.private_FillGlyph(pGlyph);
}
}
if (false === this.m_bIntegerGrid)
{
this.m_oContext.setTransform(this.m_oFullTransform.sx,this.m_oFullTransform.shy,this.m_oFullTransform.shx,
this.m_oFullTransform.sy,this.m_oFullTransform.tx,this.m_oFullTransform.ty);
}
},
FillText2 : function(x,y,text,cropX,cropW)
{
// убыстеренный вариант. здесь везде заточка на то, что приходит одна буква
if (this.m_bIsBreak)
return;
var _x = this.m_oInvertFullTransform.TransformPointX(x,y);
var _y = this.m_oInvertFullTransform.TransformPointY(x,y);
try
{
this.m_oFontManager.LoadString2C(text,_x,_y);
}
catch(err)
{
}
this.m_oContext.setTransform(1,0,0,1,0,0);
var pGlyph = this.m_oFontManager.m_oGlyphString.m_pGlyphsBuffer[0];
if (null == pGlyph)
return;
if (null != pGlyph.oBitmap)
{
this.private_FillGlyphC(pGlyph,cropX,cropW);
}
if (false === this.m_bIntegerGrid)
{
this.m_oContext.setTransform(this.m_oFullTransform.sx,this.m_oFullTransform.shy,this.m_oFullTransform.shx,
this.m_oFullTransform.sy,this.m_oFullTransform.tx,this.m_oFullTransform.ty);
}
},
t2 : function(text,x,y,cropX,cropW)
{
if (this.m_bIsBreak)
return;
var _x = this.m_oInvertFullTransform.TransformPointX(x,y);
var _y = this.m_oInvertFullTransform.TransformPointY(x,y);
try
{
this.m_oFontManager.LoadString2(text,_x,_y);
}
catch(err)
{
}
this.m_oContext.setTransform(1,0,0,1,0,0);
while (true)
{
var pGlyph = this.m_oFontManager.GetNextChar2();
if (null == pGlyph)
break;
if (null != pGlyph.oBitmap)
{
this.private_FillGlyphC(pGlyph,cropX,cropW);
}
}
if (false === this.m_bIntegerGrid)
{
this.m_oContext.setTransform(this.m_oFullTransform.sx,this.m_oFullTransform.shy,this.m_oFullTransform.shx,
this.m_oFullTransform.sy,this.m_oFullTransform.tx,this.m_oFullTransform.ty);
}
},
FillTextCode : function(x,y,lUnicode)
{
// убыстеренный вариант. здесь везде заточка на то, что приходит одна буква
if (this.m_bIsBreak)
return;
var _x = this.m_oInvertFullTransform.TransformPointX(x,y);
var _y = this.m_oInvertFullTransform.TransformPointY(x,y);
try
{
this.m_oFontManager.LoadString4C(lUnicode,_x,_y);
}
catch(err)
{
}
if (false === this.m_bIntegerGrid)
{
this.m_oContext.setTransform(1,0,0,1,0,0);
}
var pGlyph = this.m_oFontManager.m_oGlyphString.m_pGlyphsBuffer[0];
if (null == pGlyph)
return;
if (null != pGlyph.oBitmap)
{
this.private_FillGlyph(pGlyph);
}
if (false === this.m_bIntegerGrid)
{
this.m_oContext.setTransform(this.m_oFullTransform.sx,this.m_oFullTransform.shy,this.m_oFullTransform.shx,
this.m_oFullTransform.sy,this.m_oFullTransform.tx,this.m_oFullTransform.ty);
}
},
tg : function(text,x,y)
{
if (this.m_bIsBreak)
return;
var _x = this.m_oInvertFullTransform.TransformPointX(x,y);
var _y = this.m_oInvertFullTransform.TransformPointY(x,y);
try
{
this.m_oFontManager.LoadString3C(text,_x,_y);
}
catch(err)
{
}
if (false === this.m_bIntegerGrid)
{
this.m_oContext.setTransform(1,0,0,1,0,0);
}
var pGlyph = this.m_oFontManager.m_oGlyphString.m_pGlyphsBuffer[0];
if (null == pGlyph)
return;
if (null != pGlyph.oBitmap)
{
var _a = this.m_oBrush.Color1.A;
if (255 != _a)
this.m_oContext.globalAlpha = _a / 255;
this.private_FillGlyph(pGlyph);
if (255 != _a)
this.m_oContext.globalAlpha = 1.0;
}
if (false === this.m_bIntegerGrid)
{
this.m_oContext.setTransform(this.m_oFullTransform.sx,this.m_oFullTransform.shy,this.m_oFullTransform.shx,
this.m_oFullTransform.sy,this.m_oFullTransform.tx,this.m_oFullTransform.ty);
}
},
charspace : function(space)
{
},
// private methods
private_FillGlyph : function(pGlyph)
{
// new scheme
var nW = pGlyph.oBitmap.nWidth;
var nH = pGlyph.oBitmap.nHeight;
if (0 == nW || 0 == nH)
return;
var nX = (this.m_oFontManager.m_oGlyphString.m_fX + pGlyph.fX + pGlyph.oBitmap.nX) >> 0;
var nY = (this.m_oFontManager.m_oGlyphString.m_fY + pGlyph.fY - pGlyph.oBitmap.nY) >> 0;
pGlyph.oBitmap.oGlyphData.checkColor(this.m_oBrush.Color1.R,this.m_oBrush.Color1.G,this.m_oBrush.Color1.B,nW,nH);
if (null == this.TextClipRect)
pGlyph.oBitmap.draw(this.m_oContext, nX, nY, this.TextClipRect);
else
pGlyph.oBitmap.drawCropInRect(this.m_oContext, nX, nY, this.TextClipRect);
},
private_FillGlyphC : function(pGlyph,cropX,cropW)
{
// new scheme
var nW = pGlyph.oBitmap.nWidth;
var nH = pGlyph.oBitmap.nHeight;
if (0 == nW || 0 == nH)
return;
var nX = (this.m_oFontManager.m_oGlyphString.m_fX + pGlyph.fX + pGlyph.oBitmap.nX) >> 0;
var nY = (this.m_oFontManager.m_oGlyphString.m_fY + pGlyph.fY - pGlyph.oBitmap.nY) >> 0;
var d_koef = this.m_dDpiX / 25.4;
var cX = Math.max((cropX * d_koef) >> 0, 0);
var cW = Math.min((cropW * d_koef) >> 0, nW);
if (cW <= 0)
cW = 1;
pGlyph.oBitmap.oGlyphData.checkColor(this.m_oBrush.Color1.R,this.m_oBrush.Color1.G,this.m_oBrush.Color1.B,nW,nH);
pGlyph.oBitmap.drawCrop(this.m_oContext, nX, nY, cW, nH, cX);
},
private_FillGlyph2 : function(pGlyph)
{
var i = 0;
var j = 0;
var nW = pGlyph.oBitmap.nWidth;
var nH = pGlyph.oBitmap.nHeight;
if (0 == nW || 0 == nH)
return;
var nX = parseInt(this.m_oFontManager.m_oGlyphString.m_fX + pGlyph.fX + pGlyph.oBitmap.nX);
var nY = parseInt(this.m_oFontManager.m_oGlyphString.m_fY + pGlyph.fY - pGlyph.oBitmap.nY);
var imageData = this.m_oContext.getImageData(nX,nY,nW,nH);
var pPixels = imageData.data;
var _r = this.m_oBrush.Color1.R;
var _g = this.m_oBrush.Color1.G;
var _b = this.m_oBrush.Color1.B;
for (; j < nH; ++j)
{
var indx = 4 * j * nW;
for (i = 0; i < nW; ++i)
{
var weight = pGlyph.oBitmap.pData[j * pGlyph.oBitmap.nWidth + i];
if (255 == weight)
{
pPixels[indx] = _r;
pPixels[indx + 1] = _g;
pPixels[indx + 2] = _b;
pPixels[indx + 3] = 255;
}
else
{
var r = pPixels[indx];
var g = pPixels[indx + 1];
var b = pPixels[indx + 2];
var a = pPixels[indx + 3];
pPixels[indx] = ((_r - r) * weight + (r << 8)) >>> 8;
pPixels[indx + 1] = ((_g - g) * weight + (g << 8)) >>> 8;
pPixels[indx + 2] = ((_b - b) * weight + (b << 8)) >>> 8;
pPixels[indx + 3] = (weight + a) - ((weight * a + 256) >>> 8);
}
indx += 4;
}
}
this.m_oContext.putImageData(imageData,nX,nY);
},
SetIntegerGrid : function(param)
{
if (true == param)
{
this.m_bIntegerGrid = true;
this.m_oContext.setTransform(1,0,0,1,0,0);
}
else
{
this.m_bIntegerGrid = false;
this.m_oContext.setTransform(this.m_oFullTransform.sx,this.m_oFullTransform.shy,this.m_oFullTransform.shx,
this.m_oFullTransform.sy,this.m_oFullTransform.tx,this.m_oFullTransform.ty);
}
},
GetIntegerGrid : function()
{
return this.m_bIntegerGrid;
},
DrawHeaderEdit : function(yPos, lock_type)
{
var _y = this.m_oFullTransform.TransformPointY(0,yPos);
_y = (_y >> 0) + 0.5;
var _x = 0;
var _wmax = this.m_lWidthPix;
var _w1 = 6;
var _w2 = 3;
var ctx = this.m_oContext;
switch (lock_type)
{
case locktype_None:
case locktype_Mine:
{
this.p_color(155, 187, 277, 255);
ctx.lineWidth = 2;
break;
}
case locktype_Other:
case locktype_Other2:
{
this.p_color(238, 53, 37, 255);
ctx.lineWidth = 1;
_w1 = 2;
_w2 = 1;
break;
}
default:
{
this.p_color(155, 187, 277, 255);
ctx.lineWidth = 2;
_w1 = 2;
_w2 = 1;
}
}
if (true === this.m_bIntegerGrid)
{
this._s();
while (true)
{
if (_x > _wmax)
break;
ctx.moveTo(_x,_y);
_x+=_w1;
ctx.lineTo(_x,_y);
_x+=_w2;
}
this.ds();
}
else
{
this.SetIntegerGrid(true);
this._s();
while (true)
{
if (_x > _wmax)
break;
ctx.moveTo(_x,_y);
_x+=_w1;
ctx.lineTo(_x,_y);
_x+=_w2;
}
this.ds();
this.SetIntegerGrid(false);
}
},
DrawFooterEdit : function(yPos, lock_type)
{
var _y = this.m_oFullTransform.TransformPointY(0,yPos);
_y = (_y >> 0) + 0.5;
var _x = 0;
var _w1 = 6;
var _w2 = 3;
var ctx = this.m_oContext;
switch (lock_type)
{
case locktype_None:
case locktype_Mine:
{
this.p_color(155, 187, 277, 255);
ctx.lineWidth = 2;
break;
}
case locktype_Other:
case locktype_Other2:
{
this.p_color(238, 53, 37, 255);
ctx.lineWidth = 1;
_w1 = 2;
_w2 = 1;
break;
}
default:
{
this.p_color(155, 187, 277, 255);
ctx.lineWidth = 2;
_w1 = 2;
_w2 = 1;
}
}
var _wmax = this.m_lWidthPix;
if (true === this.m_bIntegerGrid)
{
this._s();
while (true)
{
if (_x > _wmax)
break;
ctx.moveTo(_x,_y);
_x+=_w1;
ctx.lineTo(_x,_y);
_x+=_w2;
}
this.ds();
}
else
{
this.SetIntegerGrid(true);
this._s();
while (true)
{
if (_x > _wmax)
break;
ctx.moveTo(_x,_y);
_x+=_w1;
ctx.lineTo(_x,_y);
_x+=_w2;
}
this.ds();
this.SetIntegerGrid(false);
}
},
DrawLockParagraph : function(lock_type, x, y1, y2)
{
if (lock_type == locktype_None || editor.WordControl.m_oDrawingDocument.IsLockObjectsEnable === false || editor.isViewMode)
return;
if (lock_type == locktype_Mine)
{
this.p_color(22, 156, 0, 255);
//this.p_color(155, 187, 277, 255);
}
else
this.p_color(238, 53, 37, 255);
var _x = this.m_oFullTransform.TransformPointX(x, y1) >> 0;
var _xT = this.m_oFullTransform.TransformPointX(x, y2) >> 0;
var _y1 = (this.m_oFullTransform.TransformPointY(x, y1) >> 0) + 0.5;
var _y2 = (this.m_oFullTransform.TransformPointY(x, y2) >> 0) - 1.5;
var ctx = this.m_oContext;
if (_x != _xT)
{
// значит какой-то трансформ
var dKoefMMToPx = 1 / Math.max(this.m_oCoordTransform.sx, 0.001);
this.p_width(1000 * dKoefMMToPx);
var w_dot = 2 * dKoefMMToPx;
var w_dist = 1 * dKoefMMToPx;
var w_len_indent = 3;
var _interf = editor.WordControl.m_oDrawingDocument.AutoShapesTrack;
this._s();
_interf.AddLineDash(ctx, x, y1, x, y2, w_dot, w_dist);
_interf.AddLineDash(ctx, x, y1, x + w_len_indent, y1, w_dot, w_dist);
_interf.AddLineDash(ctx, x, y2, x + w_len_indent, y2, w_dot, w_dist);
this.ds();
return;
}
var bIsInt = this.m_bIntegerGrid;
if (!bIsInt)
this.SetIntegerGrid(true);
ctx.lineWidth = 1;
var w_dot = 2;
var w_dist = 1;
var w_len_indent = (3 * this.m_oCoordTransform.sx) >> 0;
this._s();
var y_mem = _y1 - 0.5;
while (true)
{
if ((y_mem + w_dot) > _y2)
break;
ctx.moveTo(_x + 0.5,y_mem);
y_mem+=w_dot;
ctx.lineTo(_x + 0.5,y_mem);
y_mem+=w_dist;
}
var x_max = _x + w_len_indent;
var x_mem = _x;
while (true)
{
if (x_mem > x_max)
break;
ctx.moveTo(x_mem,_y1);
x_mem+=w_dot;
ctx.lineTo(x_mem,_y1);
x_mem+=w_dist;
}
x_mem = _x;
while (true)
{
if (x_mem > x_max)
break;
ctx.moveTo(x_mem,_y2);
x_mem+=w_dot;
ctx.lineTo(x_mem,_y2);
x_mem+=w_dist;
}
this.ds();
if (!bIsInt)
this.SetIntegerGrid(false);
},
DrawLockObjectRect : function(lock_type, x, y, w, h)
{
if (lock_type == locktype_None || editor.WordControl.m_oDrawingDocument.IsLockObjectsEnable === false || editor.isViewMode)
return;
if (lock_type == locktype_Mine)
{
this.p_color(22, 156, 0, 255);
//this.p_color(155, 187, 277, 255);
}
else
this.p_color(238, 53, 37, 255);
var ctx = this.m_oContext;
var _m = this.m_oTransform;
if (_m.sx != 1.0 || _m.shx != 0.0 || _m.shy != 0.0 && _m.sy != 1.0)
{
// значит какой-то трансформ
var dKoefMMToPx = 1 / Math.max(this.m_oCoordTransform.sx, 0.001);
this.p_width(1000 * dKoefMMToPx);
var w_dot = 2 * dKoefMMToPx;
var w_dist = 1 * dKoefMMToPx;
var _interf = editor.WordControl.m_oDrawingDocument.AutoShapesTrack;
var eps = 5 * dKoefMMToPx;
var _x = x - eps;
var _y = y - eps;
var _r = x + w + eps;
var _b = y + h + eps;
this._s();
_interf.AddRectDash(ctx, _x, _y, _r, _y, _x, _b, _r, _b, w_dot, w_dist);
this.ds();
return;
}
var bIsInt = this.m_bIntegerGrid;
if (!bIsInt)
this.SetIntegerGrid(true);
ctx.lineWidth = 1;
var w_dot = 2;
var w_dist = 1;
var eps = 5;
var _x = (this.m_oFullTransform.TransformPointX(x, y) >> 0) - eps + 0.5;
var _y = (this.m_oFullTransform.TransformPointY(x, y) >> 0) - eps + 0.5;
var _r = (this.m_oFullTransform.TransformPointX(x+w, y+h) >> 0) + eps + 0.5;
var _b = (this.m_oFullTransform.TransformPointY(x+w, y+h) >> 0) + eps + 0.5;
this._s();
for (var i = _x; i < _r; i += w_dist)
{
ctx.moveTo(i, _y);
i += w_dot;
if (i > _r)
i = _r;
ctx.lineTo(i, _y);
}
for (var i = _y; i < _b; i += w_dist)
{
ctx.moveTo(_r, i);
i += w_dot;
if (i > _b)
i = _b;
ctx.lineTo(_r, i);
}
for (var i = _r; i > _x; i -= w_dist)
{
ctx.moveTo(i, _b);
i -= w_dot;
if (i < _x)
i = _x;
ctx.lineTo(i, _b);
}
for (var i = _b; i > _y; i -= w_dist)
{
ctx.moveTo(_x, i);
i -= w_dot;
if (i < _y)
i = _y;
ctx.lineTo(_x, i);
}
this.ds();
if (!bIsInt)
this.SetIntegerGrid(false);
},
DrawEmptyTableLine : function(x1,y1,x2,y2)
{
if (!editor.isShowTableEmptyLine)
return;
var _x1 = this.m_oFullTransform.TransformPointX(x1,y1);
var _y1 = this.m_oFullTransform.TransformPointY(x1,y1);
var _x2 = this.m_oFullTransform.TransformPointX(x2,y2);
var _y2 = this.m_oFullTransform.TransformPointY(x2,y2);
_x1 = (_x1 >> 0) + 0.5;
_y1 = (_y1 >> 0) + 0.5;
_x2 = (_x2 >> 0) + 0.5;
_y2 = (_y2 >> 0) + 0.5;
this.p_color(138, 162, 191, 255);
var ctx = this.m_oContext;
if (_x1 != _x2 && _y1 != _y2)
{
// значит какой-то трансформ
var dKoefMMToPx = 1 / Math.max(this.m_oCoordTransform.sx, 0.001);
this.p_width(1000 * dKoefMMToPx);
this._s();
editor.WordControl.m_oDrawingDocument.AutoShapesTrack.AddLineDash(ctx, x1, y1, x2, y2, 2 * dKoefMMToPx, 2 * dKoefMMToPx);
this.ds();
return;
}
ctx.lineWidth = 1;
var bIsInt = this.m_bIntegerGrid;
if (!bIsInt)
this.SetIntegerGrid(true);
if (_x1 == _x2)
{
var _y = Math.min(_y1, _y2) + 0.5;
var _w1 = 2;
var _w2 = 2;
var _wmax = Math.max(_y1, _y2) - 0.5;
this._s();
while (true)
{
if (_y > _wmax)
break;
ctx.moveTo(_x1,_y);
_y+=_w1;
if (_y > _wmax)
{
ctx.lineTo(_x1,_y - _w1 + 1);
}
else
{
ctx.lineTo(_x1,_y);
}
_y+=_w2;
}
this.ds();
}
else if (_y1 == _y2)
{
var _x = Math.min(_x1, _x2) + 0.5;
var _w1 = 2;
var _w2 = 2;
var _wmax = Math.max(_x1, _x2) - 0.5;
this._s();
while (true)
{
if (_x > _wmax)
break;
ctx.moveTo(_x,_y1);
_x+=_w1;
if (_x > _wmax)
{
ctx.lineTo(_x - _w2 + 1,_y1);
}
else
{
ctx.lineTo(_x,_y1);
}
_x+=_w2;
}
this.ds();
}
else
{
// значит какой-то трансформ
this._s();
editor.WordControl.m_oDrawingDocument.AutoShapesTrack.AddLineDash(ctx, _x1, _y1, _x2, _y2, 2, 2);
this.ds();
}
if (!bIsInt)
this.SetIntegerGrid(false);
},
// smart methods for horizontal / vertical lines
drawHorLine : function(align, y, x, r, penW)
{
if (!this.m_bIntegerGrid)
{
this.p_width(penW * 1000);
this._s();
this._m(x, y);
this._l(r, y);
this.ds();
return;
}
var pen_w = parseInt((this.m_dDpiX * penW / g_dKoef_in_to_mm) + 0.5);
if (0 == pen_w)
pen_w = 1;
var _x = (this.m_oFullTransform.TransformPointX(x,y) >> 0) + 0.5 - 0.5;
var _r = (this.m_oFullTransform.TransformPointX(r,y) >> 0) + 0.5 + 0.5;
var ctx = this.m_oContext;
ctx.setTransform(1,0,0,1,0,0);
ctx.lineWidth = pen_w;
switch (align)
{
case 0:
{
// top
var _top = (this.m_oFullTransform.TransformPointY(x,y) >> 0) + 0.5;
ctx.beginPath();
ctx.moveTo(_x, _top + pen_w / 2 - 0.5);
ctx.lineTo(_r, _top + pen_w / 2 - 0.5);
ctx.stroke();
break;
}
case 1:
{
// center
var _center = (this.m_oFullTransform.TransformPointY(x,y) >> 0) + 0.5;
ctx.beginPath();
if (0 == (pen_w % 2))
{
ctx.moveTo(_x, _center - 0.5);
ctx.lineTo(_r, _center - 0.5);
}
else
{
ctx.moveTo(_x, _center);
ctx.lineTo(_r, _center);
}
ctx.stroke();
break;
}
case 2:
{
// bottom
var _bottom = (this.m_oFullTransform.TransformPointY(x,y) >> 0) + 0.5;
ctx.beginPath();
ctx.moveTo(_x, _bottom - pen_w / 2 + 0.5);
ctx.lineTo(_r, _bottom - pen_w / 2 + 0.5);
ctx.stroke();
break;
}
}
},
drawHorLine2 : function(align, y, x, r, penW)
{
if (!this.m_bIntegerGrid)
{
var _y1 = y - penW / 2;
var _y2 = _y1 + 2 * penW;
this.p_width(penW * 1000);
this._s();
this._m(x, _y1);
this._l(r, _y1);
this.ds();
this._s();
this._m(x, _y2);
this._l(r, _y2);
this.ds();
return;
}
var pen_w = ((this.m_dDpiX * penW / g_dKoef_in_to_mm) + 0.5) >> 0;
if (0 == pen_w)
pen_w = 1;
var _x = (this.m_oFullTransform.TransformPointX(x,y) >> 0) + 0.5 - 0.5;
var _r = (this.m_oFullTransform.TransformPointX(r,y) >> 0) + 0.5 + 0.5;
var ctx = this.m_oContext;
ctx.lineWidth = pen_w;
switch (align)
{
case 0:
{
// top
var _top = (this.m_oFullTransform.TransformPointY(x,y) >> 0) + 0.5;
var _pos1 = _top + pen_w / 2 - 0.5 - pen_w;
var _pos2 = _pos1 + pen_w * 2;
ctx.beginPath();
ctx.moveTo(_x, _pos1);
ctx.lineTo(_r, _pos1);
ctx.stroke();
ctx.beginPath();
ctx.moveTo(_x, _pos2);
ctx.lineTo(_r, _pos2);
ctx.stroke();
break;
}
case 1:
{
// center
// TODO:
break;
}
case 2:
{
// bottom
// TODO:
break;
}
}
},
drawVerLine : function(align, x, y, b, penW)
{
if (!this.m_bIntegerGrid)
{
this.p_width(penW * 1000);
this._s();
this._m(x, y);
this._l(x, b);
this.ds();
return;
}
var pen_w = ((this.m_dDpiX * penW / g_dKoef_in_to_mm) + 0.5) >> 0;
if (0 == pen_w)
pen_w = 1;
var _y = (this.m_oFullTransform.TransformPointY(x,y) >> 0) + 0.5 - 0.5;
var _b = (this.m_oFullTransform.TransformPointY(x,b) >> 0) + 0.5 + 0.5;
var ctx = this.m_oContext;
ctx.lineWidth = pen_w;
switch (align)
{
case 0:
{
// left
var _left = (this.m_oFullTransform.TransformPointX(x,y) >> 0) + 0.5;
ctx.beginPath();
ctx.moveTo(_left + pen_w / 2 - 0.5, _y);
ctx.lineTo(_left + pen_w / 2 - 0.5, _b);
ctx.stroke();
break;
}
case 1:
{
// center
var _center = (this.m_oFullTransform.TransformPointX(x,y) >> 0) + 0.5;
ctx.beginPath();
if (0 == (pen_w % 2))
{
ctx.moveTo(_center - 0.5, _y);
ctx.lineTo(_center - 0.5, _b);
}
else
{
ctx.moveTo(_center, _y);
ctx.lineTo(_center, _b);
}
ctx.stroke();
break;
}
case 2:
{
// right
var _right = (this.m_oFullTransform.TransformPointX(x,y) >> 0) + 0.5;
ctx.beginPath();
ctx.moveTo(_right - pen_w / 2 + 0.5, _y);
ctx.lineTo(_right - pen_w / 2 + 0.5, _b);
ctx.stroke();
break;
}
}
},
// мега крутые функции для таблиц
drawHorLineExt : function(align, y, x, r, penW, leftMW, rightMW)
{
if (!this.m_bIntegerGrid)
{
this.p_width(penW * 1000);
this._s();
this._m(x, y);
this._l(r, y);
this.ds();
return;
}
var pen_w = Math.max(((this.m_dDpiX * penW / g_dKoef_in_to_mm) + 0.5) >> 0, 1);
var _x = (this.m_oFullTransform.TransformPointX(x,y) >> 0) + 0.5;
var _r = (this.m_oFullTransform.TransformPointX(r,y) >> 0) + 0.5;
if (leftMW != 0)
{
var _center = _x;
var pen_mw = Math.max(((this.m_dDpiX * Math.abs(leftMW) * 2 / g_dKoef_in_to_mm) + 0.5) >> 0, 1);
if (leftMW < 0)
{
if ((pen_mw % 2) == 0)
{
_x = _center - (pen_mw / 2);
}
else
{
_x = _center - ((pen_mw / 2) >> 0);
}
}
else
{
if ((pen_mw % 2) == 0)
{
_x = _center + ((pen_mw / 2) - 1.0);
}
else
{
_x = _center + ((pen_mw / 2) >> 0);
}
}
}
if (rightMW != 0)
{
var _center = _r;
var pen_mw = Math.max(((this.m_dDpiX * Math.abs(rightMW) * 2 / g_dKoef_in_to_mm) + 0.5) >> 0, 1);
if (rightMW < 0)
{
if ((pen_mw % 2) == 0)
{
_r = _center - (pen_mw / 2);
}
else
{
_r = _center - ((pen_mw / 2) >> 0);
}
}
else
{
if ((pen_mw % 2) == 0)
{
_r = _center + (pen_mw / 2) - 1.0;
}
else
{
_r = _center + ((pen_mw / 2) >> 0);
}
}
}
var ctx = this.m_oContext;
ctx.lineWidth = pen_w;
_x -= 0.5;
_r += 0.5;
switch (align)
{
case 0:
{
// top
var _top = (this.m_oFullTransform.TransformPointY(x,y) >> 0) + 0.5;
ctx.beginPath();
ctx.moveTo(_x, _top + pen_w / 2 - 0.5);
ctx.lineTo(_r, _top + pen_w / 2 - 0.5);
ctx.stroke();
break;
}
case 1:
{
// center
var _center = (this.m_oFullTransform.TransformPointY(x,y) >> 0) + 0.5;
ctx.beginPath();
if (0 == (pen_w % 2))
{
ctx.moveTo(_x, _center - 0.5);
ctx.lineTo(_r, _center - 0.5);
}
else
{
ctx.moveTo(_x, _center);
ctx.lineTo(_r, _center);
}
ctx.stroke();
break;
}
case 2:
{
// bottom
var _bottom = (this.m_oFullTransform.TransformPointY(x,y) >> 0) + 0.5;
ctx.beginPath();
ctx.moveTo(_x, _bottom - pen_w / 2 + 0.5);
ctx.lineTo(_r, _bottom - pen_w / 2 + 0.5);
ctx.stroke();
break;
}
}
},
rect : function(x,y,w,h)
{
var ctx = this.m_oContext;
ctx.beginPath();
if (this.m_bIntegerGrid)
{
var _x = (this.m_oFullTransform.TransformPointX(x,y) + 0.5) >> 0;
var _y = (this.m_oFullTransform.TransformPointY(x,y) + 0.5) >> 0;
var _r = (this.m_oFullTransform.TransformPointX(x+w,y) + 0.5) >> 0;
var _b = (this.m_oFullTransform.TransformPointY(x,y+h) + 0.5) >> 0;
ctx.rect(_x, _y, _r - _x, _b - _y);
}
else
{
ctx.rect(x, y, w, h);
}
},
TableRect : function(x,y,w,h)
{
var ctx = this.m_oContext;
if (this.m_bIntegerGrid)
{
var _x = (this.m_oFullTransform.TransformPointX(x,y) >> 0) + 0.5;
var _y = (this.m_oFullTransform.TransformPointY(x,y) >> 0) + 0.5;
var _r = (this.m_oFullTransform.TransformPointX(x+w,y) >> 0) + 0.5;
var _b = (this.m_oFullTransform.TransformPointY(x,y+h) >> 0) + 0.5;
ctx.fillRect(_x - 0.5, _y - 0.5, _r - _x + 1, _b - _y + 1);
}
else
{
ctx.fillRect(x, y, w, h);
}
},
// функции клиппирования
AddClipRect : function(x, y, w, h)
{
//this.ClipManager.AddRect(x, y, w, h);
var __rect = new _rect();
__rect.x = x;
__rect.y = y;
__rect.w = w;
__rect.h = h;
this.GrState.AddClipRect(__rect);
},
RemoveClipRect : function()
{
//this.ClipManager.RemoveRect();
},
SetClip : function(r)
{
var ctx = this.m_oContext;
ctx.save();
ctx.beginPath();
if (!global_MatrixTransformer.IsIdentity(this.m_oTransform))
{
ctx.rect(r.x, r.y, r.w, r.h);
}
else
{
var _x = (this.m_oFullTransform.TransformPointX(r.x,r.y) + 1) >> 0;
var _y = (this.m_oFullTransform.TransformPointY(r.x,r.y) + 1) >> 0;
var _r = (this.m_oFullTransform.TransformPointX(r.x+r.w,r.y) - 1) >> 0;
var _b = (this.m_oFullTransform.TransformPointY(r.x,r.y+r.h) - 1) >> 0;
ctx.rect(_x, _y, _r - _x + 1, _b - _y + 1);
}
this.clip();
ctx.beginPath();
},
RemoveClip : function()
{
this.m_oContext.restore();
this.m_oContext.save();
if (this.m_oContext.globalAlpha != this.globalAlpha)
this.m_oContext.globalAlpha = this.globalAlpha;
},
drawCollaborativeChanges : function(x, y, w, h)
{
this.b_color1( 0, 255, 0, 64 );
this.rect( x, y, w, h );
this.df();
},
drawSearchResult : function(x, y, w, h)
{
this.b_color1( 255, 220, 0, 200 );
this.rect( x, y, w, h );
this.df();
},
drawFlowAnchor : function(x, y)
{
if (!window.g_flow_anchor || !window.g_flow_anchor.asc_complete || (!editor || !editor.ShowParaMarks))
return;
if (false === this.m_bIntegerGrid)
{
this.m_oContext.setTransform(1,0,0,1,0,0);
}
var _x = this.m_oFullTransform.TransformPointX(x,y) >> 0;
var _y = this.m_oFullTransform.TransformPointY(x,y) >> 0;
this.m_oContext.drawImage(window.g_flow_anchor, _x, _y);
if (false === this.m_bIntegerGrid)
{
this.m_oContext.setTransform(this.m_oFullTransform.sx,this.m_oFullTransform.shy,this.m_oFullTransform.shx,
this.m_oFullTransform.sy,this.m_oFullTransform.tx,this.m_oFullTransform.ty);
}
},
SavePen : function()
{
this.GrState.SavePen();
},
RestorePen : function()
{
this.GrState.RestorePen();
},
SaveBrush : function()
{
this.GrState.SaveBrush();
},
RestoreBrush : function()
{
this.GrState.RestoreBrush();
},
SavePenBrush : function()
{
this.GrState.SavePenBrush();
},
RestorePenBrush : function()
{
this.GrState.RestorePenBrush();
},
SaveGrState : function()
{
this.GrState.SaveGrState();
},
RestoreGrState : function()
{
this.GrState.RestoreGrState();
},
StartClipPath : function()
{
},
EndClipPath : function()
{
this.m_oContext.clip();
},
StartCheckTableDraw : function()
{
if (!this.m_bIntegerGrid && global_MatrixTransformer.IsIdentity2(this.m_oTransform))
{
this.SaveGrState();
this.SetIntegerGrid(true);
return true;
}
return false;
},
EndCheckTableDraw : function(bIsRestore)
{
if (bIsRestore)
this.RestoreGrState();
},
SetTextClipRect : function(_l, _t, _r, _b)
{
this.TextClipRect = {
l : (_l * this.m_oCoordTransform.sx) >> 0,
t : (_t * this.m_oCoordTransform.sy) >> 0,
r : (_r * this.m_oCoordTransform.sx) >> 0,
b : (_b * this.m_oCoordTransform.sy) >> 0
};
}
};
\ No newline at end of file
var TRACK_CIRCLE_RADIUS = 5;
var TRACK_RECT_SIZE2 = 4;
var TRACK_RECT_SIZE = 8;
var TRACK_DISTANCE_ROTATE = 25;
var TRACK_ADJUSTMENT_SIZE = 10;
var TRACK_WRAPPOINTS_SIZE = 6;
// заглушка
function CHtmlPage()
{
var drawingPage = { top: 0, left: 0, right: 0, bottom: 0 };
var width_mm, height_mm;
this.init = function(x, y, w_pix, h_pix, w_mm, h_mm) {
drawingPage.top = y;
drawingPage.left = x;
drawingPage.right = w_pix;
drawingPage.bottom = h_pix;
width_mm = w_mm;
height_mm = h_mm;
}
this.GetDrawingPageInfo = function() {
return { drawingPage: drawingPage, width_mm: width_mm, height_mm: height_mm };
}
}
function COverlay()
{
this.m_oControl = null;
this.m_oContext = null;
this.min_x = 0xFFFF;
this.min_y = 0xFFFF;
this.max_x = -0xFFFF;
this.max_y = -0xFFFF;
this.m_bIsShow = false;
this.m_bIsAlwaysUpdateOverlay = false;
this.m_oHtmlPage = null;
}
COverlay.prototype =
{
init : function(context, controlName, x, y, w_pix, h_pix, w_mm, h_mm)
{
this.m_oContext = context;
this.m_oControl = CreateControl(controlName);
this.m_oHtmlPage = new CHtmlPage();
this.m_oHtmlPage.init(x, y, w_pix, h_pix, w_mm, h_mm);
},
Clear : function()
{
if (null == this.m_oContext)
{
this.m_oContext = this.m_oControl.HtmlElement.getContext('2d');
}
this.m_oContext.beginPath();
if (this.max_x != -0xFFFF && this.max_y != -0xFFFF)
{
this.m_oContext.clearRect(this.min_x - 5, this.min_y - 5, this.max_x - this.min_x + 10, this.max_y - this.min_y + 10);
}
this.min_x = 0xFFFF;
this.min_y = 0xFFFF;
this.max_x = -0xFFFF;
this.max_y = -0xFFFF;
},
Show : function()
{
if (this.m_bIsShow)
return;
this.m_bIsShow = true;
this.m_oControl.HtmlElement.style.display = "block";
},
UnShow : function()
{
if (!this.m_bIsShow)
return;
this.m_bIsShow = false;
this.m_oControl.HtmlElement.style.display = "none";
},
VertLine : function(position)
{
this.Clear();
if (this.m_bIsAlwaysUpdateOverlay || editor.WordControl.m_oDrawingDocument.m_bIsSelection)
{
if (!editor.WordControl.OnUpdateOverlay())
{
editor.WordControl.EndUpdateOverlay();
}
}
if (this.min_x > position)
this.min_x = position;
if (this.max_x < position)
this.max_x = position;
//this.min_x = position;
//this.max_x = position;
this.min_y = 0;
this.max_y = this.m_oControl.HtmlElement.height;
this.m_oContext.lineWidth = 1;
var x = parseInt(position + 0.5) + 0.5;
var y = 0;
this.m_oContext.strokeStyle = "#000000";
this.m_oContext.beginPath();
while (y < this.max_y)
{
this.m_oContext.moveTo(x, y); y++;
this.m_oContext.lineTo(x, y); y+=1;
this.m_oContext.moveTo(x, y); y++;
this.m_oContext.lineTo(x, y); y+=1;
this.m_oContext.moveTo(x, y); y++;
this.m_oContext.lineTo(x, y); y++;
y += 5;
}
this.m_oContext.stroke();
y = 1;
this.m_oContext.strokeStyle = "#FFFFFF";
this.m_oContext.beginPath();
while (y < this.max_y)
{
this.m_oContext.moveTo(x, y); y++;
this.m_oContext.lineTo(x, y); y+=1;
this.m_oContext.moveTo(x, y); y++;
this.m_oContext.lineTo(x, y); y+=1;
this.m_oContext.moveTo(x, y); y++;
this.m_oContext.lineTo(x, y); y++;
y += 5;
}
this.m_oContext.stroke();
this.Show();
},
HorLine : function(position)
{
this.Clear();
if (this.m_bIsAlwaysUpdateOverlay || editor.WordControl.m_oDrawingDocument.m_bIsSelection)
{
if (!editor.WordControl.OnUpdateOverlay())
{
editor.WordControl.EndUpdateOverlay();
}
}
this.min_x = 0;
this.max_x = this.m_oControl.HtmlElement.width;
//this.min_y = position;
//this.max_y = position;
if (this.min_y > position)
this.min_y = position;
if (this.max_y < position)
this.max_y = position;
this.m_oContext.lineWidth = 1;
var y = parseInt(position + 0.5) + 0.5;
var x = 0;
this.m_oContext.strokeStyle = "#000000";
this.m_oContext.beginPath();
while (x < this.max_x)
{
this.m_oContext.moveTo(x, y); x++;
this.m_oContext.lineTo(x, y); x+=1;
this.m_oContext.moveTo(x, y); x++;
this.m_oContext.lineTo(x, y); x+=1;
this.m_oContext.moveTo(x, y); x++;
this.m_oContext.lineTo(x, y); x++;
x += 5;
}
this.m_oContext.stroke();
x = 1;
this.m_oContext.strokeStyle = "#FFFFFF";
this.m_oContext.beginPath();
while (x < this.max_x)
{
this.m_oContext.moveTo(x, y); x++;
this.m_oContext.lineTo(x, y); x+=1;
this.m_oContext.moveTo(x, y); x++;
this.m_oContext.lineTo(x, y); x+=1;
this.m_oContext.moveTo(x, y); x++;
this.m_oContext.lineTo(x, y); x++;
x += 5;
}
this.m_oContext.stroke();
this.Show();
},
CheckPoint1 : function(x,y)
{
if (x < this.min_x)
this.min_x = x;
if (y < this.min_y)
this.min_y = y;
},
CheckPoint2 : function(x,y)
{
if (x > this.max_x)
this.max_x = x;
if (y > this.max_y)
this.max_y = y;
},
CheckPoint : function(x,y)
{
if (x < this.min_x)
this.min_x = x;
if (y < this.min_y)
this.min_y = y;
if (x > this.max_x)
this.max_x = x;
if (y > this.max_y)
this.max_y = y;
},
AddRect2 : function(x,y,r)
{
var _x = x - ((r / 2) >> 0);
var _y = y - ((r / 2) >> 0);
this.CheckPoint1(_x,_y);
this.CheckPoint2(_x+r,_y+r);
this.m_oContext.moveTo(_x,_y);
this.m_oContext.rect(_x,_y,r,r);
},
AddRect3 : function(x,y,r, ex1, ey1, ex2, ey2)
{
var _r = r / 2;
var x1 = x + _r * (ex2 - ex1);
var y1 = y + _r * (ey2 - ey1);
var x2 = x + _r * (ex2 + ex1);
var y2 = y + _r * (ey2 + ey1);
var x3 = x + _r * (-ex2 + ex1);
var y3 = y + _r * (-ey2 + ey1);
var x4 = x + _r * (-ex2 - ex1);
var y4 = y + _r * (-ey2 - ey1);
this.CheckPoint(x1,y1);
this.CheckPoint(x2,y2);
this.CheckPoint(x3,y3);
this.CheckPoint(x4,y4);
var ctx = this.m_oContext;
ctx.moveTo(x1,y1);
ctx.lineTo(x2,y2);
ctx.lineTo(x3,y3);
ctx.lineTo(x4,y4);
ctx.closePath();
},
AddRect : function(x,y,w,h)
{
this.CheckPoint1(x,y);
this.CheckPoint2(x + w,y + h);
this.m_oContext.moveTo(x,y);
this.m_oContext.rect(x,y,w,h);
//this.m_oContext.closePath();
},
CheckRectT : function(x,y,w,h,trans,eps)
{
var x1 = trans.TransformPointX(x, y);
var y1 = trans.TransformPointY(x, y);
var x2 = trans.TransformPointX(x+w, y);
var y2 = trans.TransformPointY(x+w, y);
var x3 = trans.TransformPointX(x+w, y+h);
var y3 = trans.TransformPointY(x+w, y+h);
var x4 = trans.TransformPointX(x, y+h);
var y4 = trans.TransformPointY(x, y+h);
this.CheckPoint(x1, y1);
this.CheckPoint(x2, y2);
this.CheckPoint(x3, y3);
this.CheckPoint(x4, y4);
if (eps !== undefined)
{
this.min_x -= eps;
this.min_y -= eps;
this.max_x += eps;
this.max_y += eps;
}
},
CheckRect : function(x,y,w,h)
{
this.CheckPoint1(x,y);
this.CheckPoint2(x + w,y + h);
},
AddEllipse : function(x,y,r)
{
this.CheckPoint1(x-r,y-r);
this.CheckPoint2(x+r,y+r);
this.m_oContext.moveTo(x+r,y);
this.m_oContext.arc(x,y,r,0,Math.PI*2,false);
//this.m_oContext.closePath();
},
AddRoundRect : function(x, y, w, h, r)
{
if (w < (2 * r) || h < (2 * r))
return this.AddRect(x, y, w, h);
this.CheckPoint1(x,y);
this.CheckPoint2(x + w,y + h);
var _ctx = this.m_oContext;
_ctx.moveTo(x + r, y);
_ctx.lineTo(x + w - r, y);
_ctx.quadraticCurveTo(x + w, y, x + w, y + r);
_ctx.lineTo(x + w, y + h - r);
_ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);
_ctx.lineTo(x + r, y + h);
_ctx.quadraticCurveTo(x, y + h, x, y + h - r);
_ctx.lineTo(x, y + r);
_ctx.quadraticCurveTo(x, y, x + r, y);
},
AddRoundRectCtx : function(ctx, x, y, w, h, r)
{
if (w < (2 * r) || h < (2 * r))
return ctx.rect(x, y, w, h);
var _ctx = this.m_oContext;
_ctx.moveTo(x + r, y);
_ctx.lineTo(x + w - r, y);
_ctx.quadraticCurveTo(x + w, y, x + w, y + r);
_ctx.lineTo(x + w, y + h - r);
_ctx.quadraticCurveTo(x + w, y + h, x + w - r, y + h);
_ctx.lineTo(x + r, y + h);
_ctx.quadraticCurveTo(x, y + h, x, y + h - r);
_ctx.lineTo(x, y + r);
_ctx.quadraticCurveTo(x, y, x + r, y);
}
};
function CBoundsController()
{
this.min_x = 0xFFFF;
this.min_y = 0xFFFF;
this.max_x = -0xFFFF;
this.max_y = -0xFFFF;
}
CBoundsController.prototype =
{
ClearNoAttack : function()
{
this.min_x = 0xFFFF;
this.min_y = 0xFFFF;
this.max_x = -0xFFFF;
this.max_y = -0xFFFF;
},
Clear : function(ctx)
{
if (this.max_x != -0xFFFF && this.max_y != -0xFFFF)
{
ctx.fillRect(this.min_x - 5, this.min_y - 5, this.max_x - this.min_x + 10, this.max_y - this.min_y + 10);
}
this.min_x = 0xFFFF;
this.min_y = 0xFFFF;
this.max_x = -0xFFFF;
this.max_y = -0xFFFF;
},
CheckPoint1 : function(x,y)
{
if (x < this.min_x)
this.min_x = x;
if (y < this.min_y)
this.min_y = y;
},
CheckPoint2 : function(x,y)
{
if (x > this.max_x)
this.max_x = x;
if (y > this.max_y)
this.max_y = y;
},
CheckPoint : function(x,y)
{
if (x < this.min_x)
this.min_x = x;
if (y < this.min_y)
this.min_y = y;
if (x > this.max_x)
this.max_x = x;
if (y > this.max_y)
this.max_y = y;
},
CheckRect : function(x,y,w,h)
{
this.CheckPoint1(x,y);
this.CheckPoint2(x + w,y + h);
}
};
function CAutoshapeTrack()
{
this.m_oContext = null;
this.m_oOverlay = null;
this.Graphics = null;
this.MaxEpsLine = 0;
this.IsTrack = true;
this.PageIndex = -1;
this.CurrentPageInfo = null;
}
CAutoshapeTrack.prototype =
{
SetFont : function(font)
{
},
init : function(overlay, x, y, r, b, w_mm, h_mm)
{
this.m_oOverlay = overlay;
this.m_oContext = this.m_oOverlay.m_oContext;
this.Graphics = new CGraphics();
this.Graphics.init(this.m_oContext, r - x, b - y, w_mm, h_mm);
this.Graphics.m_oCoordTransform.tx = x;
this.Graphics.m_oCoordTransform.ty = y;
this.Graphics.SetIntegerGrid(false);
this.m_oContext.globalAlpha = 0.5;
},
SetIntegerGrid : function(b)
{
},
// draw styles
p_color : function(r,g,b,a)
{
this.Graphics.p_color(r, g, b, a);
},
p_width : function(w)
{
this.Graphics.p_width(w);
var xx1 = 0;
var yy1 = 0;
var xx2 = 1;
var yy2 = 1;
var xxx1 = this.Graphics.m_oFullTransform.TransformPointX(xx1, yy1);
var yyy1 = this.Graphics.m_oFullTransform.TransformPointY(xx1, yy1);
var xxx2 = this.Graphics.m_oFullTransform.TransformPointX(xx2, yy2);
var yyy2 = this.Graphics.m_oFullTransform.TransformPointY(xx2, yy2);
var _len2 = ((xxx2 - xxx1)*(xxx2 - xxx1) + (yyy2 - yyy1)*(yyy2 - yyy1));
var koef = Math.sqrt(_len2 / 2);
var _EpsLine = (w * koef / 1000) >> 0;
_EpsLine += 5;
if (_EpsLine > this.MaxEpsLine)
this.MaxEpsLine = _EpsLine;
},
b_color1 : function(r,g,b,a)
{
this.Graphics.b_color1(r,g,b,a);
},
// path commands
_s : function()
{
this.Graphics._s();
},
_e : function()
{
this.Graphics._e();
},
_z : function()
{
this.Graphics._z();
},
_m : function(x,y)
{
this.Graphics._m(x,y);
var _x = this.Graphics.m_oFullTransform.TransformPointX(x,y);
var _y = this.Graphics.m_oFullTransform.TransformPointY(x,y);
this.m_oOverlay.CheckPoint(_x, _y);
},
_l : function(x,y)
{
this.Graphics._l(x,y);
var _x = this.Graphics.m_oFullTransform.TransformPointX(x,y);
var _y = this.Graphics.m_oFullTransform.TransformPointY(x,y);
this.m_oOverlay.CheckPoint(_x, _y);
},
_c : function(x1,y1,x2,y2,x3,y3)
{
this.Graphics._c(x1,y1,x2,y2,x3,y3);
var _x1 = this.Graphics.m_oFullTransform.TransformPointX(x1,y1);
var _y1 = this.Graphics.m_oFullTransform.TransformPointY(x1,y1);
var _x2 = this.Graphics.m_oFullTransform.TransformPointX(x2,y2);
var _y2 = this.Graphics.m_oFullTransform.TransformPointY(x2,y2);
var _x3 = this.Graphics.m_oFullTransform.TransformPointX(x3,y3);
var _y3 = this.Graphics.m_oFullTransform.TransformPointY(x3,y3);
this.m_oOverlay.CheckPoint(_x1, _y1);
this.m_oOverlay.CheckPoint(_x2, _y2);
this.m_oOverlay.CheckPoint(_x3, _y3);
},
_c2 : function(x1,y1,x2,y2)
{
this.Graphics._c2(x1,y1,x2,y2);
var _x1 = this.Graphics.m_oFullTransform.TransformPointX(x1,y1);
var _y1 = this.Graphics.m_oFullTransform.TransformPointY(x1,y1);
var _x2 = this.Graphics.m_oFullTransform.TransformPointX(x2,y2);
var _y2 = this.Graphics.m_oFullTransform.TransformPointY(x2,y2);
this.m_oOverlay.CheckPoint(_x1, _y1);
this.m_oOverlay.CheckPoint(_x2, _y2);
},
ds : function()
{
this.Graphics.ds();
},
df : function()
{
this.Graphics.df();
},
// canvas state
save : function()
{
this.Graphics.save();
},
restore : function()
{
this.Graphics.restore();
},
clip : function()
{
this.Graphics.clip();
},
// transform
reset : function()
{
this.Graphics.reset();
},
transform3 : function(m)
{
this.Graphics.transform3(m);
},
transform : function(sx,shy,shx,sy,tx,ty)
{
this.Graphics.transform(sx,shy,shx,sy,tx,ty);
},
drawImage : function(image, x, y, w, h, alpha, srcRect, nativeImage)
{
this.Graphics.drawImage(image, x, y, w, h, undefined, srcRect, nativeImage);
var _x1 = this.Graphics.m_oFullTransform.TransformPointX(x,y);
var _y1 = this.Graphics.m_oFullTransform.TransformPointY(x,y);
var _x2 = this.Graphics.m_oFullTransform.TransformPointX(x+w,y);
var _y2 = this.Graphics.m_oFullTransform.TransformPointY(x+w,y);
var _x3 = this.Graphics.m_oFullTransform.TransformPointX(x+w,(y+h));
var _y3 = this.Graphics.m_oFullTransform.TransformPointY(x+w,(y+h));
var _x4 = this.Graphics.m_oFullTransform.TransformPointX(x,(y+h));
var _y4 = this.Graphics.m_oFullTransform.TransformPointY(x,(y+h));
this.m_oOverlay.CheckPoint(_x1, _y1);
this.m_oOverlay.CheckPoint(_x2, _y2);
this.m_oOverlay.CheckPoint(_x3, _y3);
this.m_oOverlay.CheckPoint(_x4, _y4);
},
CorrectOverlayBounds : function()
{
this.m_oContext.setTransform(1,0,0,1,0,0);
this.m_oOverlay.min_x -= this.MaxEpsLine;
this.m_oOverlay.min_y -= this.MaxEpsLine;
this.m_oOverlay.max_x += this.MaxEpsLine;
this.m_oOverlay.max_y += this.MaxEpsLine;
},
SetCurrentPage : function(nPageIndex)
{
if (nPageIndex == this.PageIndex)
return;
var oPage = this.m_oOverlay.m_oHtmlPage.GetDrawingPageInfo(nPageIndex);
this.PageIndex = nPageIndex;
var drawPage = oPage.drawingPage;
this.Graphics = new CGraphics();
this.Graphics.init(this.m_oContext, drawPage.right - drawPage.left, drawPage.bottom - drawPage.top, oPage.width_mm, oPage.height_mm);
this.Graphics.m_oCoordTransform.tx = drawPage.left;
this.Graphics.m_oCoordTransform.ty = drawPage.top;
this.Graphics.SetIntegerGrid(false);
this.m_oContext.globalAlpha = 0.5;
},
init2 : function(overlay)
{
this.m_oOverlay = overlay;
this.m_oContext = this.m_oOverlay.m_oContext;
this.PageIndex = -1;
},
SetClip : function(r)
{
},
RemoveClip : function()
{
},
SavePen : function()
{
this.Graphics.SavePen();
},
RestorePen : function()
{
this.Graphics.RestorePen();
},
SaveBrush : function()
{
this.Graphics.SaveBrush();
},
RestoreBrush : function()
{
this.Graphics.RestoreBrush();
},
SavePenBrush : function()
{
this.Graphics.SavePenBrush();
},
RestorePenBrush : function()
{
this.Graphics.RestorePenBrush();
},
SaveGrState : function()
{
this.Graphics.SaveGrState();
},
RestoreGrState : function()
{
this.Graphics.RestoreGrState();
},
StartClipPath : function()
{
this.Graphics.StartClipPath();
},
EndClipPath : function()
{
this.Graphics.EndClipPath();
},
/*************************************************************************/
/******************************** TRACKS *********************************/
/*************************************************************************/
DrawTrack : function(type, matrix, left, top, width, height, isLine)
{
// с самого начала нужно понять, есть ли поворот. Потому что если его нет, то можно
// (и нужно!) рисовать все по-умному
var overlay = this.m_oOverlay;
overlay.Show();
var bIsClever = false;
this.CurrentPageInfo = overlay.m_oHtmlPage.GetDrawingPageInfo(this.PageIndex);
var drPage = this.CurrentPageInfo.drawingPage;
var xDst = drPage.left;
var yDst = drPage.top;
var wDst = drPage.right - drPage.left;
var hDst = drPage.bottom - drPage.top;
var dKoefX = wDst / this.CurrentPageInfo.width_mm;
var dKoefY = hDst / this.CurrentPageInfo.height_mm;
var r = left + width;
var b = top + height;
// (x1,y1) --------- (x2,y2)
// | |
// | |
// (x3,y3) --------- (x4,y4)
var x1 = (xDst + dKoefX * (matrix.TransformPointX(left, top))) >> 0;
var y1 = (yDst + dKoefY * (matrix.TransformPointY(left, top))) >> 0;
var x2 = (xDst + dKoefX * (matrix.TransformPointX(r, top))) >> 0;
var y2 = (yDst + dKoefY * (matrix.TransformPointY(r, top))) >> 0;
var x3 = (xDst + dKoefX * (matrix.TransformPointX(left, b))) >> 0;
var y3 = (yDst + dKoefY * (matrix.TransformPointY(left, b))) >> 0;
var x4 = (xDst + dKoefX * (matrix.TransformPointX(r, b))) >> 0;
var y4 = (yDst + dKoefY * (matrix.TransformPointY(r, b))) >> 0;
var ctx = overlay.m_oContext;
if (x1 == x3 && x2 == x4 && y1 == y2 && y3 == y4 && x1 < x2 && y1 < y3)
bIsClever = true;
var _style_blue = "#4D7399";
var _style_green = "#84E036";
var _style_white = "#FFFFFF";
var _len_x = Math.sqrt((x1 - x2)*(x1 - x2) + (y1 - y2)*(y1 - y2));
var _len_y = Math.sqrt((x1 - x3)*(x1 - x3) + (y1 - y3)*(y1 - y3));
if (_len_x < 1)
_len_x = 1;
if (_len_y < 1)
_len_y = 1;
var bIsRectsTrack = ((_len_x >= 30) && (_len_y >= 30)) ? true : false;
ctx.lineWidth = 1;
ctx.beginPath();
var _oldGlobalAlpha = ctx.globalAlpha;
ctx.globalAlpha = 1;
switch (type)
{
case TYPE_TRACK_SHAPE:
case TYPE_TRACK_GROUP:
{
if (bIsClever)
{
overlay.CheckRect(x1, y1, x4 - x1, y4 - y1);
ctx.strokeStyle = _style_blue;
if (!isLine)
{
ctx.rect(x1 + 0.5, y2 + 0.5, x4 - x1, y4 - y1);
ctx.stroke();
ctx.beginPath();
}
var xC = ((x1 + x2) / 2) >> 0;
if (!isLine)
{
ctx.moveTo(xC + 0.5, y1);
ctx.lineTo(xC + 0.5, y1 - TRACK_DISTANCE_ROTATE);
ctx.stroke();
ctx.beginPath();
}
ctx.fillStyle = _style_white;
overlay.AddEllipse(x1, y1, TRACK_CIRCLE_RADIUS);
if (!isLine)
{
overlay.AddEllipse(x2, y2, TRACK_CIRCLE_RADIUS);
overlay.AddEllipse(x3, y3, TRACK_CIRCLE_RADIUS);
}
overlay.AddEllipse(x4, y4, TRACK_CIRCLE_RADIUS);
if (bIsRectsTrack && !isLine)
{
var _xC = (((x1 + x2) / 2) >> 0) + 0.5;
var _yC = (((y1 + y3) / 2) >> 0) + 0.5;
overlay.AddRect2(_xC, y1+0.5, TRACK_RECT_SIZE);
overlay.AddRect2(x2+0.5, _yC, TRACK_RECT_SIZE);
overlay.AddRect2(_xC, y3+0.5, TRACK_RECT_SIZE);
overlay.AddRect2(x1+0.5, _yC, TRACK_RECT_SIZE);
}
ctx.fill();
ctx.stroke();
if (!isLine)
{
ctx.beginPath();
overlay.AddEllipse(xC, y1 - TRACK_DISTANCE_ROTATE, TRACK_CIRCLE_RADIUS);
ctx.fillStyle = _style_green;
ctx.fill();
ctx.stroke();
}
ctx.beginPath();
}
else
{
ctx.strokeStyle = _style_blue;
if (!isLine)
{
ctx.moveTo(x1, y1);
ctx.lineTo(x2, y2);
ctx.lineTo(x4, y4);
ctx.lineTo(x3, y3);
ctx.closePath();
ctx.stroke();
}
overlay.CheckPoint(x1, y1);
overlay.CheckPoint(x2, y2);
overlay.CheckPoint(x3, y3);
overlay.CheckPoint(x4, y4);
var ex1 = (x2 - x1) / _len_x;
var ey1 = (y2 - y1) / _len_x;
var ex2 = (x1 - x3) / _len_y;
var ey2 = (y1 - y3) / _len_y;
var xc1 = (x1 + x2) / 2;
var yc1 = (y1 + y2) / 2;
if (!isLine)
{
ctx.beginPath();
ctx.moveTo(xc1, yc1);
ctx.lineTo(xc1 + ex2 * TRACK_DISTANCE_ROTATE, yc1 + ey2 * TRACK_DISTANCE_ROTATE);
ctx.stroke();
}
ctx.beginPath();
ctx.fillStyle = _style_white;
overlay.AddEllipse(x1, y1, TRACK_CIRCLE_RADIUS);
if (!isLine)
{
overlay.AddEllipse(x2, y2, TRACK_CIRCLE_RADIUS);
overlay.AddEllipse(x3, y3, TRACK_CIRCLE_RADIUS);
}
overlay.AddEllipse(x4, y4, TRACK_CIRCLE_RADIUS);
if (bIsRectsTrack && !isLine)
{
overlay.AddRect3((x1 + x2) / 2, (y1 + y2) / 2, TRACK_RECT_SIZE, ex1, ey1, ex2, ey2);
overlay.AddRect3((x2 + x4) / 2, (y2 + y4) / 2, TRACK_RECT_SIZE, ex1, ey1, ex2, ey2);
overlay.AddRect3((x3 + x4) / 2, (y3 + y4) / 2, TRACK_RECT_SIZE, ex1, ey1, ex2, ey2);
overlay.AddRect3((x3 + x1) / 2, (y3 + y1) / 2, TRACK_RECT_SIZE, ex1, ey1, ex2, ey2);
}
ctx.fill();
ctx.stroke();
if (!isLine)
{
ctx.beginPath();
overlay.AddEllipse(xc1 + ex2 * TRACK_DISTANCE_ROTATE, yc1 + ey2 * TRACK_DISTANCE_ROTATE, TRACK_CIRCLE_RADIUS);
ctx.fillStyle = _style_green;
ctx.fill();
ctx.stroke();
}
ctx.beginPath();
}
break;
}
case TYPE_TRACK_TEXT:
case TYPE_TRACK_GROUP_PASSIVE:
{
if (bIsClever)
{
overlay.CheckRect(x1, y1, x4 - x1, y4 - y1);
this.AddRectDashClever(ctx, x1, y1, x4, y4, 8, 3);
ctx.strokeStyle = _style_blue;
ctx.stroke();
var xC = ((x1 + x2) / 2) >> 0;
ctx.moveTo(xC + 0.5, y1);
ctx.lineTo(xC + 0.5, y1 - TRACK_DISTANCE_ROTATE);
ctx.stroke();
ctx.beginPath();
ctx.fillStyle = _style_white;
overlay.AddEllipse(x1, y1, TRACK_CIRCLE_RADIUS);
overlay.AddEllipse(x2, y2, TRACK_CIRCLE_RADIUS);
overlay.AddEllipse(x3, y3, TRACK_CIRCLE_RADIUS);
overlay.AddEllipse(x4, y4, TRACK_CIRCLE_RADIUS);
if (bIsRectsTrack)
{
var _xC = (((x1 + x2) / 2) >> 0) + 0.5;
var _yC = (((y1 + y3) / 2) >> 0) + 0.5;
overlay.AddRect2(_xC, y1+0.5, TRACK_RECT_SIZE);
overlay.AddRect2(x2+0.5, _yC, TRACK_RECT_SIZE);
overlay.AddRect2(_xC, y3+0.5, TRACK_RECT_SIZE);
overlay.AddRect2(x1+0.5, _yC, TRACK_RECT_SIZE);
}
ctx.fill();
ctx.stroke();
ctx.beginPath();
overlay.AddEllipse(xC, y1 - TRACK_DISTANCE_ROTATE, TRACK_CIRCLE_RADIUS);
ctx.fillStyle = _style_green;
ctx.fill();
ctx.stroke();
ctx.beginPath();
}
else
{
overlay.CheckPoint(x1, y1);
overlay.CheckPoint(x2, y2);
overlay.CheckPoint(x3, y3);
overlay.CheckPoint(x4, y4);
this.AddRectDash(ctx, x1, y1, x2, y2, x3, y3, x4, y4, 8, 3);
ctx.strokeStyle = _style_blue;
ctx.stroke();
var ex1 = (x2 - x1) / _len_x;
var ey1 = (y2 - y1) / _len_x;
var ex2 = (x1 - x3) / _len_y;
var ey2 = (y1 - y3) / _len_y;
ctx.beginPath();
var xc1 = (x1 + x2) / 2;
var yc1 = (y1 + y2) / 2;
ctx.moveTo(xc1, yc1);
ctx.lineTo(xc1 + ex2 * TRACK_DISTANCE_ROTATE, yc1 + ey2 * TRACK_DISTANCE_ROTATE);
ctx.stroke();
ctx.beginPath();
ctx.fillStyle = _style_white;
overlay.AddEllipse(x1, y1, TRACK_CIRCLE_RADIUS);
overlay.AddEllipse(x2, y2, TRACK_CIRCLE_RADIUS);
overlay.AddEllipse(x3, y3, TRACK_CIRCLE_RADIUS);
overlay.AddEllipse(x4, y4, TRACK_CIRCLE_RADIUS);
if (bIsRectsTrack)
{
overlay.AddRect3((x1 + x2) / 2, (y1 + y2) / 2, TRACK_RECT_SIZE, ex1, ey1, ex2, ey2);
overlay.AddRect3((x2 + x4) / 2, (y2 + y4) / 2, TRACK_RECT_SIZE, ex1, ey1, ex2, ey2);
overlay.AddRect3((x3 + x4) / 2, (y3 + y4) / 2, TRACK_RECT_SIZE, ex1, ey1, ex2, ey2);
overlay.AddRect3((x3 + x1) / 2, (y3 + y1) / 2, TRACK_RECT_SIZE, ex1, ey1, ex2, ey2);
}
ctx.fill();
ctx.stroke();
ctx.beginPath();
overlay.AddEllipse(xc1 + ex2 * TRACK_DISTANCE_ROTATE, yc1 + ey2 * TRACK_DISTANCE_ROTATE, TRACK_CIRCLE_RADIUS);
ctx.fillStyle = _style_green;
ctx.fill();
ctx.stroke();
ctx.beginPath();
}
break;
}
case TYPE_TRACK_EMPTY_PH:
{
if (bIsClever)
{
overlay.CheckRect(x1, y1, x4 - x1, y4 - y1);
ctx.rect(x1 + 0.5, y2 + 0.5, x4 - x1 + 1, y4 - y1);
ctx.fillStyle = _style_white;
ctx.stroke();
ctx.beginPath();
this.AddRectDashClever(ctx, x1, y1, x4, y4, 8, 3);
ctx.strokeStyle = _style_blue;
ctx.stroke();
var xC = ((x1 + x2) / 2) >> 0;
ctx.moveTo(xC + 0.5, y1);
ctx.lineTo(xC + 0.5, y1 - TRACK_DISTANCE_ROTATE);
ctx.stroke();
ctx.beginPath();
ctx.fillStyle = _style_white;
overlay.AddEllipse(x1, y1, TRACK_CIRCLE_RADIUS);
overlay.AddEllipse(x2, y2, TRACK_CIRCLE_RADIUS);
overlay.AddEllipse(x3, y3, TRACK_CIRCLE_RADIUS);
overlay.AddEllipse(x4, y4, TRACK_CIRCLE_RADIUS);
if (bIsRectsTrack && false)
{
var _xC = (((x1 + x2) / 2) >> 0) + 0.5;
var _yC = (((y1 + y3) / 2) >> 0) + 0.5;
overlay.AddRect2(_xC, y1+0.5, TRACK_RECT_SIZE);
overlay.AddRect2(x2+0.5, _yC, TRACK_RECT_SIZE);
overlay.AddRect2(_xC, y3+0.5, TRACK_RECT_SIZE);
overlay.AddRect2(x1+0.5, _yC, TRACK_RECT_SIZE);
}
ctx.fill();
ctx.stroke();
ctx.beginPath();
overlay.AddEllipse(xC, y1 - TRACK_DISTANCE_ROTATE);
ctx.fillStyle = _style_green;
ctx.fill();
ctx.stroke();
ctx.beginPath();
}
else
{
overlay.CheckPoint(x1, y1);
overlay.CheckPoint(x2, y2);
overlay.CheckPoint(x3, y3);
overlay.CheckPoint(x4, y4);
ctx.moveTo(x1, y1);
ctx.lineTo(x2, y2);
ctx.lineTo(x3, y3);
ctx.lineTo(x4, y4);
ctx.closePath();
overlay.CheckPoint(x1, y1);
overlay.CheckPoint(x2, y2);
overlay.CheckPoint(x3, y3);
overlay.CheckPoint(x4, y4);
ctx.strokeStyle = _style_white;
ctx.stroke();
ctx.beginPath();
this.AddRectDash(ctx, x1, y1, x2, y2, x3, y3, x4, y4, 8, 3);
ctx.strokeStyle = _style_blue;
ctx.stroke();
var ex1 = (x2 - x1) / _len_x;
var ey1 = (y2 - y1) / _len_x;
var ex2 = (x1 - x3) / _len_y;
var ey2 = (y1 - y3) / _len_y;
ctx.beginPath();
var xc1 = (x1 + x2) / 2;
var yc1 = (y1 + y2) / 2;
ctx.moveTo(xc1, yc1);
ctx.lineTo(xc1 + ex2 * TRACK_DISTANCE_ROTATE, yc1 + ey2 * TRACK_DISTANCE_ROTATE);
ctx.stroke();
ctx.beginPath();
ctx.fillStyle = _style_white;
overlay.AddEllipse(x1, y1, TRACK_CIRCLE_RADIUS);
overlay.AddEllipse(x2, y2, TRACK_CIRCLE_RADIUS);
overlay.AddEllipse(x3, y3, TRACK_CIRCLE_RADIUS);
overlay.AddEllipse(x4, y4, TRACK_CIRCLE_RADIUS);
if (bIsRectsTrack)
{
overlay.AddRect3((x1 + x2) / 2, (y1 + y2) / 2, TRACK_RECT_SIZE, ex1, ey1, ex2, ey2);
overlay.AddRect3((x2 + x4) / 2, (y2 + y4) / 2, TRACK_RECT_SIZE, ex1, ey1, ex2, ey2);
overlay.AddRect3((x3 + x4) / 2, (y3 + y4) / 2, TRACK_RECT_SIZE, ex1, ey1, ex2, ey2);
overlay.AddRect3((x3 + x1) / 2, (y3 + y1) / 2, TRACK_RECT_SIZE, ex1, ey1, ex2, ey2);
}
ctx.fill();
ctx.stroke();
ctx.beginPath();
overlay.AddEllipse(xc1 + ex2 * TRACK_DISTANCE_ROTATE, yc1 + ey2 * TRACK_DISTANCE_ROTATE, TRACK_DISTANCE_ROTATE);
ctx.fillStyle = _style_green;
ctx.fill();
ctx.stroke();
ctx.beginPath();
}
break;
}
default:
break;
}
ctx.globalAlpha = _oldGlobalAlpha;
},
DrawTrackSelectShapes : function(x, y, w, h)
{
var overlay = this.m_oOverlay;
overlay.Show();
this.CurrentPageInfo = overlay.m_oHtmlPage.GetDrawingPageInfo(this.PageIndex);
var drPage = this.CurrentPageInfo.drawingPage;
var xDst = drPage.left;
var yDst = drPage.top;
var wDst = drPage.right - drPage.left;
var hDst = drPage.bottom - drPage.top;
var dKoefX = wDst / this.CurrentPageInfo.width_mm;
var dKoefY = hDst / this.CurrentPageInfo.height_mm;
var x1 = (xDst + dKoefX * x) >> 0;
var y1 = (yDst + dKoefY * y) >> 0;
var x2 = (xDst + dKoefX * (x + w)) >> 0;
var y2 = (yDst + dKoefY * (y + h)) >> 0;
if (x1 > x2)
{
var tmp = x1;
x1 = x2;
x2 = tmp;
}
if (y1 > y2)
{
var tmp = y1;
y1 = y2;
y2 = tmp;
}
overlay.CheckRect(x1, y1, x2 - x1, y2 - y1);
var ctx = overlay.m_oContext;
ctx.setTransform(1, 0, 0, 1, 0, 0);
var globalAlphaOld = ctx.globalAlpha;
ctx.globalAlpha = 0.5;
ctx.beginPath();
ctx.fillStyle = "rgba(51,102,204,255)";
ctx.strokeStyle = "#9ADBFE";
ctx.lineWidth = 1;
ctx.fillRect(x1, y1, x2 - x1, y2 - y1);
ctx.beginPath();
ctx.strokeRect(x1 - 0.5, y1 - 0.5, x2 - x1 + 1, y2 - y1 + 1);
ctx.globalAlpha = globalAlphaOld;
},
AddRect : function(ctx, x, y, r, b, bIsClever)
{
if (bIsClever)
ctx.rect(x + 0.5, y + 0.5, r - x + 1, b - y + 1);
else
{
ctx.moveTo(x,y);
ctx.rect(x, y, r - x + 1, b - y + 1);
}
},
AddRectDashClever : function(ctx, x, y, r, b, w_dot, w_dist)
{
var _x = x + 0.5;
var _y = y + 0.5;
var _r = r + 0.5;
var _b = b + 0.5;
for (var i = _x; i < _r; i += w_dist)
{
ctx.moveTo(i, _y);
i += w_dot;
if (i > _r)
i = _r;
ctx.lineTo(i, _y);
}
for (var i = _y; i < _b; i += w_dist)
{
ctx.moveTo(_r, i);
i += w_dot;
if (i > _b)
i = _b;
ctx.lineTo(_r, i);
}
for (var i = _r; i > _x; i -= w_dist)
{
ctx.moveTo(i, _b);
i -= w_dot;
if (i < _x)
i = _x;
ctx.lineTo(i, _b);
}
for (var i = _b; i > _y; i -= w_dist)
{
ctx.moveTo(_x, i);
i -= w_dot;
if (i < _y)
i = _y;
ctx.lineTo(_x, i);
}
},
AddLineDash : function(ctx, x1, y1, x2, y2, w_dot, w_dist)
{
var len = Math.sqrt((x2-x1)*(x2-x1) + (y2-y1)*(y2-y1));
if (len < 1)
len = 1;
var len_x1 = Math.abs(w_dot*(x2-x1)/len);
var len_y1 = Math.abs(w_dot*(y2-y1)/len);
var len_x2 = Math.abs(w_dist*(x2-x1)/len);
var len_y2 = Math.abs(w_dist*(y2-y1)/len);
if (x1 <= x2 && y1 <= y2)
{
for (var i = x1, j = y1; i < x2 || j < y2; i += len_x2, j += len_y2)
{
ctx.moveTo(i, j);
i += len_x1;
j += len_y1;
if (i > x2)
i = x2;
if (j > y2)
j = y2;
ctx.lineTo(i, j);
}
}
else if (x1 <= x2 && y1 > y2)
{
for (var i = x1, j = y1; i < x2 || j > y2; i += len_x2, j -= len_y2)
{
ctx.moveTo(i, j);
i += len_x1;
j -= len_y1;
if (i > x2)
i = x2;
if (j < y2)
j = y2;
ctx.lineTo(i, j);
}
}
else if (x1 > x2 && y1 <= y2)
{
for (var i = x1, j = y1; i > x2 || j < y2; i -= len_x2, j += len_y2)
{
ctx.moveTo(i, j);
i -= len_x1;
j += len_y1;
if (i < x2)
i = x2;
if (j > y2)
j = y2;
ctx.lineTo(i, j);
}
}
else
{
for (var i = x1, j = y1; i > x2 || j > y2; i -= len_x2, j -= len_y2)
{
ctx.moveTo(i, j);
i -= len_x1;
j -= len_y1;
if (i < x2)
i = x2;
if (j < y2)
j = y2;
ctx.lineTo(i, j);
}
}
},
AddRectDash : function(ctx, x1, y1, x2, y2, x3, y3, x4, y4, w_dot, w_dist)
{
this.AddLineDash(ctx, x1, y1, x2, y2, w_dot, w_dist);
this.AddLineDash(ctx, x2, y2, x4, y4, w_dot, w_dist);
this.AddLineDash(ctx, x4, y4, x3, y3, w_dot, w_dist);
this.AddLineDash(ctx, x3, y3, x1, y1, w_dot, w_dist);
},
DrawAdjustment : function(matrix, x, y)
{
var overlay = this.m_oOverlay;
this.CurrentPageInfo = overlay.m_oHtmlPage.GetDrawingPageInfo(this.PageIndex);
var drPage = this.CurrentPageInfo.drawingPage;
var xDst = drPage.left;
var yDst = drPage.top;
var wDst = drPage.right - drPage.left;
var hDst = drPage.bottom - drPage.top;
var dKoefX = wDst / this.CurrentPageInfo.width_mm;
var dKoefY = hDst / this.CurrentPageInfo.height_mm;
var cx = (xDst + dKoefX * (matrix.TransformPointX(x, y))) >> 0;
var cy = (yDst + dKoefY * (matrix.TransformPointY(x, y))) >> 0;
var _style_blue = "#4D7399";
var _style_yellow = "#FDF54A";
var ctx = overlay.m_oContext;
var dist = TRACK_ADJUSTMENT_SIZE / 2;
ctx.moveTo(cx - dist, cy);
ctx.lineTo(cx, cy - dist);
ctx.lineTo(cx + dist, cy);
ctx.lineTo(cx, cy + dist);
ctx.closePath();
overlay.CheckRect(cx - dist, cy - dist, TRACK_ADJUSTMENT_SIZE, TRACK_ADJUSTMENT_SIZE);
ctx.fillStyle = _style_yellow;
ctx.strokeStyle = _style_blue;
ctx.fill();
ctx.stroke();
},
DrawEditWrapPointsPolygon : function(points, matrix)
{
var _len = points.length;
if (0 == _len)
return;
var overlay = this.m_oOverlay;
var ctx = overlay.m_oContext;
this.CurrentPageInfo = overlay.m_oHtmlPage.GetDrawingPageInfo(this.PageIndex);
var drPage = this.CurrentPageInfo.drawingPage;
var xDst = drPage.left;
var yDst = drPage.top;
var wDst = drPage.right - drPage.left;
var hDst = drPage.bottom - drPage.top;
var dKoefX = wDst / this.CurrentPageInfo.width_mm;
var dKoefY = hDst / this.CurrentPageInfo.height_mm;
var _tr_points_x = new Array(_len);
var _tr_points_y = new Array(_len);
for (var i = 0; i < _len; i++)
{
_tr_points_x[i] = (xDst + dKoefX * (matrix.TransformPointX(points[i].x, points[i].y))) >> 0;
_tr_points_y[i] = (yDst + dKoefY * (matrix.TransformPointY(points[i].x, points[i].y))) >> 0;
}
ctx.beginPath();
for (var i = 0; i < _len; i++)
{
if (0 == i)
ctx.moveTo(_tr_points_x[i], _tr_points_y[i]);
else
ctx.lineTo(_tr_points_x[i], _tr_points_y[i]);
overlay.CheckPoint(_tr_points_x[i], _tr_points_y[i]);
}
ctx.closePath();
ctx.lineWidth = 1;
ctx.strokeStyle = "#FF0000";
ctx.stroke();
ctx.beginPath();
for (var i = 0; i < _len; i++)
{
overlay.AddRect2(_tr_points_x[i] + 0.5, _tr_points_y[i] + 0.5, TRACK_WRAPPOINTS_SIZE);
}
ctx.strokeStyle = "#FFFFFF";
ctx.fillStyle = "#000000";
ctx.fill();
ctx.stroke();
ctx.beginPath();
},
DrawEditWrapPointsTrackLines : function(points, matrix)
{
var _len = points.length;
if (0 == _len)
return;
var overlay = this.m_oOverlay;
var ctx = overlay.m_oContext;
this.CurrentPageInfo = overlay.m_oHtmlPage.GetDrawingPageInfo(this.PageIndex);
var drPage = this.CurrentPageInfo.drawingPage;
var xDst = drPage.left;
var yDst = drPage.top;
var wDst = drPage.right - drPage.left;
var hDst = drPage.bottom - drPage.top;
var dKoefX = wDst / this.CurrentPageInfo.width_mm;
var dKoefY = hDst / this.CurrentPageInfo.height_mm;
var _tr_points_x = new Array(_len);
var _tr_points_y = new Array(_len);
for (var i = 0; i < _len; i++)
{
_tr_points_x[i] = (xDst + dKoefX * (matrix.TransformPointX(points[i].x, points[i].y))) >> 0;
_tr_points_y[i] = (yDst + dKoefY * (matrix.TransformPointY(points[i].x, points[i].y))) >> 0;
}
var globalAlpha = ctx.globalAlpha;
ctx.globalAlpha = 1.0;
ctx.beginPath();
for (var i = 0; i < _len; i++)
{
if (0 == i)
ctx.moveTo(_tr_points_x[i], _tr_points_y[i]);
else
ctx.lineTo(_tr_points_x[i], _tr_points_y[i]);
overlay.CheckPoint(_tr_points_x[i], _tr_points_y[i]);
}
ctx.lineWidth = 1;
ctx.strokeStyle = "#FFFFFF";
ctx.stroke();
ctx.beginPath();
for (var i = 1; i < _len; i++)
{
this.AddLineDash(ctx, _tr_points_x[i-1], _tr_points_y[i-1], _tr_points_x[i], _tr_points_y[i], 4, 4);
}
ctx.lineWidth = 1;
ctx.strokeStyle = "#000000";
ctx.stroke();
ctx.beginPath();
ctx.globalAlpha = globalAlpha;
},
DrawInlineMoveCursor : function(x, y, h, matrix)
{
var overlay = this.m_oOverlay;
this.CurrentPageInfo = overlay.m_oHtmlPage.GetDrawingPageInfo(this.PageIndex);
var drPage = this.CurrentPageInfo.drawingPage;
var xDst = drPage.left;
var yDst = drPage.top;
var wDst = drPage.right - drPage.left;
var hDst = drPage.bottom - drPage.top;
var dKoefX = wDst / this.CurrentPageInfo.width_mm;
var dKoefY = hDst / this.CurrentPageInfo.height_mm;
var bIsIdentMatr = true;
if (matrix !== undefined && matrix != null)
{
if (matrix.IsIdentity2())
{
x += matrix.tx;
y += matrix.ty;
}
else
{
bIsIdentMatr = false;
}
}
if (bIsIdentMatr)
{
var __x = (xDst + dKoefX * x) >> 0;
var __y = (yDst + dKoefY * y) >> 0;
var __h = (h * dKoefY) >> 0;
overlay.CheckRect(__x,__y,2,__h);
var ctx = overlay.m_oContext;
var _oldAlpha = ctx.globalAlpha;
ctx.globalAlpha = 1;
ctx.lineWidth = 1;
ctx.strokeStyle = "#000000";
for (var i = 0; i < __h; i+=2)
{
ctx.moveTo(__x,__y+i+0.5);
ctx.lineTo(__x+2,__y+i+0.5);
}
ctx.stroke();
ctx.beginPath();
ctx.strokeStyle = "#FFFFFF";
for (var i = 1; i < __h; i+=2)
{
ctx.moveTo(__x,__y+i+0.5);
ctx.lineTo(__x+2,__y+i+0.5);
}
ctx.stroke();
ctx.globalAlpha = _oldAlpha;
}
else
{
var _x1 = matrix.TransformPointX(x, y);
var _y1 = matrix.TransformPointY(x, y);
var _x2 = matrix.TransformPointX(x, y + h);
var _y2 = matrix.TransformPointY(x, y + h);
_x1 = xDst + dKoefX * _x1;
_y1 = yDst + dKoefY * _y1;
_x2 = xDst + dKoefX * _x2;
_y2 = yDst + dKoefY * _y2;
overlay.CheckPoint(_x1, _y1);
overlay.CheckPoint(_x2, _y2);
var ctx = overlay.m_oContext;
var _oldAlpha = ctx.globalAlpha;
ctx.globalAlpha = 1;
ctx.lineWidth = 2;
ctx.beginPath();
ctx.strokeStyle = "#FFFFFF";
ctx.moveTo(_x1, _y1);
ctx.lineTo(_x2, _y2);
ctx.stroke();
ctx.beginPath();
ctx.strokeStyle = "#000000";
var _vec_len = Math.sqrt((_x2 - _x1)*(_x2 - _x1) + (_y2 - _y1)*(_y2 - _y1));
var _dx = (_x2 - _x1) / _vec_len;
var _dy = (_y2 - _y1) / _vec_len;
var __x = _x1;
var __y = _y1;
for (var i = 0; i < _vec_len; i += 2)
{
ctx.moveTo(__x, __y);
__x += _dx;
__y += _dy;
ctx.lineTo(__x, __y);
__x += _dx;
__y += _dy;
}
ctx.stroke();
ctx.globalAlpha = _oldAlpha;
}
},
drawFlowAnchor : function(x, y)
{
if (!window.g_flow_anchor || !window.g_flow_anchor.asc_complete || (!editor || !editor.ShowParaMarks))
return;
var overlay = this.m_oOverlay;
this.CurrentPageInfo = overlay.m_oHtmlPage.GetDrawingPageInfo(this.PageIndex);
var drPage = this.CurrentPageInfo.drawingPage;
var xDst = drPage.left;
var yDst = drPage.top;
var wDst = drPage.right - drPage.left;
var hDst = drPage.bottom - drPage.top;
var dKoefX = wDst / this.CurrentPageInfo.width_mm;
var dKoefY = hDst / this.CurrentPageInfo.height_mm;
var __x = (xDst + dKoefX * x) >> 0;
var __y = (yDst + dKoefY * y) >> 0;
__x -= 8;
overlay.CheckRect(__x,__y,16,17);
var ctx = overlay.m_oContext;
var _oldAlpha = ctx.globalAlpha;
ctx.globalAlpha = 1;
ctx.setTransform(1,0,0,1,0,0);
ctx.drawImage(window.g_flow_anchor, __x, __y);
ctx.globalAlpha = _oldAlpha;
}
};
function CSlideBoundsChecker()
{
this.map_bounds_shape = {};
this.map_bounds_shape["heart"] = true;
this.IsSlideBoundsCheckerType = true;
this.Bounds = new CBoundsController();
this.m_oCurFont = null;
this.m_oCoordTransform = new CMatrixL();
this.m_oTransform = new CMatrixL();
this.m_oFullTransform = new CMatrixL();
this.IsNoSupportTextDraw = true;
this.LineWidth = null;
this.AutoCheckLineWidth = false;
}
CSlideBoundsChecker.prototype =
{
IsShapeNeedBounds : function(preset)
{
if (preset === undefined || preset == null)
return true;
return (true === this.map_bounds_shape[preset]) ? false : true;
},
init : function(width_px, height_px, width_mm, height_mm)
{
this.m_lHeightPix = height_px;
this.m_lWidthPix = width_px;
this.m_dWidthMM = width_mm;
this.m_dHeightMM = height_mm;
this.m_dDpiX = 25.4 * this.m_lWidthPix / this.m_dWidthMM;
this.m_dDpiY = 25.4 * this.m_lHeightPix / this.m_dHeightMM;
this.m_oCoordTransform.sx = this.m_dDpiX / 25.4;
this.m_oCoordTransform.sy = this.m_dDpiY / 25.4;
this.Bounds.ClearNoAttack();
},
SetCurrentPage: function()
{},
EndDraw : function(){},
put_GlobalAlpha : function(enable, alpha)
{
},
// pen methods
p_color : function(r,g,b,a)
{
},
p_width : function(w)
{
},
// brush methods
b_color1 : function(r,g,b,a)
{
},
b_color2 : function(r,g,b,a)
{
},
SetIntegerGrid : function()
{
},
transform : function(sx,shy,shx,sy,tx,ty)
{
this.m_oTransform.sx = sx;
this.m_oTransform.shx = shx;
this.m_oTransform.shy = shy;
this.m_oTransform.sy = sy;
this.m_oTransform.tx = tx;
this.m_oTransform.ty = ty;
this.CalculateFullTransform();
},
CalculateFullTransform : function()
{
this.m_oFullTransform.sx = this.m_oTransform.sx;
this.m_oFullTransform.shx = this.m_oTransform.shx;
this.m_oFullTransform.shy = this.m_oTransform.shy;
this.m_oFullTransform.sy = this.m_oTransform.sy;
this.m_oFullTransform.tx = this.m_oTransform.tx;
this.m_oFullTransform.ty = this.m_oTransform.ty;
global_MatrixTransformer.MultiplyAppend(this.m_oFullTransform, this.m_oCoordTransform);
},
// path commands
_s : function()
{
},
_e : function()
{
},
_z : function()
{
},
_m : function(x,y)
{
var _x = this.m_oFullTransform.TransformPointX(x,y);
var _y = this.m_oFullTransform.TransformPointY(x,y);
this.Bounds.CheckPoint(_x, _y);
},
_l : function(x,y)
{
var _x = this.m_oFullTransform.TransformPointX(x,y);
var _y = this.m_oFullTransform.TransformPointY(x,y);
this.Bounds.CheckPoint(_x, _y);
},
_c : function(x1,y1,x2,y2,x3,y3)
{
var _x1 = this.m_oFullTransform.TransformPointX(x1,y1);
var _y1 = this.m_oFullTransform.TransformPointY(x1,y1);
var _x2 = this.m_oFullTransform.TransformPointX(x2,y2);
var _y2 = this.m_oFullTransform.TransformPointY(x2,y2);
var _x3 = this.m_oFullTransform.TransformPointX(x3,y3);
var _y3 = this.m_oFullTransform.TransformPointY(x3,y3);
this.Bounds.CheckPoint(_x1, _y1);
this.Bounds.CheckPoint(_x2, _y2);
this.Bounds.CheckPoint(_x3, _y3);
},
_c2 : function(x1,y1,x2,y2)
{
var _x1 = this.m_oFullTransform.TransformPointX(x1,y1);
var _y1 = this.m_oFullTransform.TransformPointY(x1,y1);
var _x2 = this.m_oFullTransform.TransformPointX(x2,y2);
var _y2 = this.m_oFullTransform.TransformPointY(x2,y2);
this.Bounds.CheckPoint(_x1, _y1);
this.Bounds.CheckPoint(_x2, _y2);
},
ds : function()
{
},
df : function()
{
},
// canvas state
save : function()
{
},
restore : function()
{
},
clip : function()
{
},
reset : function()
{
this.m_oTransform.Reset();
this.CalculateFullTransform();
},
transform3 : function(m)
{
this.m_oTransform = m.CreateDublicate();
this.CalculateFullTransform();
},
transform00 : function(m)
{
this.m_oTransform = m.CreateDublicate();
this.m_oTransform.tx = 0;
this.m_oTransform.ty = 0;
this.CalculateFullTransform();
},
// images
drawImage2 : function(img,x,y,w,h)
{
var _x1 = this.m_oFullTransform.TransformPointX(x,y);
var _y1 = this.m_oFullTransform.TransformPointY(x,y);
var _x2 = this.m_oFullTransform.TransformPointX(x+w,y);
var _y2 = this.m_oFullTransform.TransformPointY(x+w,y);
var _x3 = this.m_oFullTransform.TransformPointX(x+w,y+h);
var _y3 = this.m_oFullTransform.TransformPointY(x+w,y+h);
var _x4 = this.m_oFullTransform.TransformPointX(x,y+h);
var _y4 = this.m_oFullTransform.TransformPointY(x,y+h);
this.Bounds.CheckPoint(_x1, _y1);
this.Bounds.CheckPoint(_x2, _y2);
this.Bounds.CheckPoint(_x3, _y3);
this.Bounds.CheckPoint(_x4, _y4);
},
drawImage : function(img,x,y,w,h)
{
return this.drawImage2(img, x, y, w, h);
},
// text
font : function(font_id,font_size)
{
this.m_oFontManager.LoadFontFromFile(font_id, font_size, this.m_dDpiX, this.m_dDpiY);
},
GetFont : function()
{
return this.m_oCurFont;
},
SetFont : function(font)
{
this.m_oCurFont = font;
},
FillText : function(x,y,text)
{
// убыстеренный вариант. здесь везде заточка на то, что приходит одна буква
if (this.m_bIsBreak)
return;
// TODO: нужен другой метод отрисовки!!!
var _x = this.m_oFullTransform.TransformPointX(x, y);
var _y = this.m_oFullTransform.TransformPointY(x, y);
this.Bounds.CheckRect(_x, _y, 1, 1);
},
t : function(text,x,y)
{
if (this.m_bIsBreak)
return;
// TODO: нужен другой метод отрисовки!!!
var _x = this.m_oFullTransform.TransformPointX(x, y);
var _y = this.m_oFullTransform.TransformPointY(x, y);
this.Bounds.CheckRect(_x, _y, 1, 1);
},
FillText2 : function(x,y,text,cropX,cropW)
{
// убыстеренный вариант. здесь везде заточка на то, что приходит одна буква
if (this.m_bIsBreak)
return;
// TODO: нужен другой метод отрисовки!!!
var _x = this.m_oFullTransform.TransformPointX(x, y);
var _y = this.m_oFullTransform.TransformPointY(x, y);
this.Bounds.CheckRect(_x, _y, 1, 1);
},
t2 : function(text,x,y,cropX,cropW)
{
if (this.m_bIsBreak)
return;
// TODO: нужен другой метод отрисовки!!!
var _x = this.m_oFullTransform.TransformPointX(x, y);
var _y = this.m_oFullTransform.TransformPointY(x, y);
this.Bounds.CheckRect(_x, _y, 1, 1);
},
charspace : function(space)
{
},
// private methods
DrawHeaderEdit : function(yPos)
{
},
DrawFooterEdit : function(yPos)
{
},
DrawEmptyTableLine : function(x1,y1,x2,y2)
{
},
// smart methods for horizontal / vertical lines
drawHorLine : function(align, y, x, r, penW)
{
var _x1 = this.m_oFullTransform.TransformPointX(x,y-penW);
var _y1 = this.m_oFullTransform.TransformPointY(x,y-penW);
var _x2 = this.m_oFullTransform.TransformPointX(x,y+penW);
var _y2 = this.m_oFullTransform.TransformPointY(x,y+penW);
var _x3 = this.m_oFullTransform.TransformPointX(r,y-penW);
var _y3 = this.m_oFullTransform.TransformPointY(r,y-penW);
var _x4 = this.m_oFullTransform.TransformPointX(r,y+penW);
var _y4 = this.m_oFullTransform.TransformPointY(r,y+penW);
this.Bounds.CheckPoint(_x1, _y1);
this.Bounds.CheckPoint(_x2, _y2);
this.Bounds.CheckPoint(_x3, _y3);
this.Bounds.CheckPoint(_x4, _y4);
},
drawVerLine : function(align, x, y, b, penW)
{
var _x1 = this.m_oFullTransform.TransformPointX(x-penW,y);
var _y1 = this.m_oFullTransform.TransformPointY(x-penW,y);
var _x2 = this.m_oFullTransform.TransformPointX(x+penW,y);
var _y2 = this.m_oFullTransform.TransformPointY(x+penW,y);
var _x3 = this.m_oFullTransform.TransformPointX(x-penW,b);
var _y3 = this.m_oFullTransform.TransformPointY(x-penW,b);
var _x4 = this.m_oFullTransform.TransformPointX(x+penW,b);
var _y4 = this.m_oFullTransform.TransformPointY(x+penW,b);
this.Bounds.CheckPoint(_x1, _y1);
this.Bounds.CheckPoint(_x2, _y2);
this.Bounds.CheckPoint(_x3, _y3);
this.Bounds.CheckPoint(_x4, _y4);
},
// мега крутые функции для таблиц
drawHorLineExt : function(align, y, x, r, penW, leftMW, rightMW)
{
this.drawHorLine(align, y, x + leftMW, r + rightMW);
},
rect : function(x,y,w,h)
{
var _x1 = this.m_oFullTransform.TransformPointX(x,y);
var _y1 = this.m_oFullTransform.TransformPointY(x,y);
var _x2 = this.m_oFullTransform.TransformPointX(x+w,y);
var _y2 = this.m_oFullTransform.TransformPointY(x+w,y);
var _x3 = this.m_oFullTransform.TransformPointX(x+w,y+h);
var _y3 = this.m_oFullTransform.TransformPointY(x+w,y+h);
var _x4 = this.m_oFullTransform.TransformPointX(x,y+h);
var _y4 = this.m_oFullTransform.TransformPointY(x,y+h);
this.Bounds.CheckPoint(_x1, _y1);
this.Bounds.CheckPoint(_x2, _y2);
this.Bounds.CheckPoint(_x3, _y3);
this.Bounds.CheckPoint(_x4, _y4);
},
rect2 : function(x,y,w,h)
{
var _x1 = this.m_oFullTransform.TransformPointX(x,y);
var _y1 = this.m_oFullTransform.TransformPointY(x,y);
var _x2 = this.m_oFullTransform.TransformPointX(x+w,y);
var _y2 = this.m_oFullTransform.TransformPointY(x+w,y);
var _x3 = this.m_oFullTransform.TransformPointX(x+w,y-h);
var _y3 = this.m_oFullTransform.TransformPointY(x+w,y-h);
var _x4 = this.m_oFullTransform.TransformPointX(x,y-h);
var _y4 = this.m_oFullTransform.TransformPointY(x,y-h);
this.Bounds.CheckPoint(_x1, _y1);
this.Bounds.CheckPoint(_x2, _y2);
this.Bounds.CheckPoint(_x3, _y3);
this.Bounds.CheckPoint(_x4, _y4);
},
TableRect : function(x,y,w,h)
{
this.rect(x, y, w, h);
},
// функции клиппирования
AddClipRect : function(x, y, w, h)
{
},
RemoveClipRect : function()
{
},
SetClip : function(r)
{
},
RemoveClip : function()
{
},
SavePen : function()
{
},
RestorePen : function()
{
},
SaveBrush : function()
{
},
RestoreBrush : function()
{
},
SavePenBrush : function()
{
},
RestorePenBrush : function()
{
},
SaveGrState : function()
{
},
RestoreGrState : function()
{
},
StartClipPath : function()
{
},
EndClipPath : function()
{
},
CorrectBounds : function()
{
if (this.LineWidth != null)
{
var _correct = this.LineWidth / 2.0;
this.Bounds.min_x -= _correct;
this.Bounds.min_y -= _correct;
this.Bounds.max_x += _correct;
this.Bounds.max_y += _correct;
}
},
CorrectBounds2 : function()
{
if (this.LineWidth != null)
{
var _correct = this.LineWidth * this.m_oCoordTransform.sx / 2;
this.Bounds.min_x -= _correct;
this.Bounds.min_y -= _correct;
this.Bounds.max_x += _correct;
this.Bounds.max_y += _correct;
}
}
};
\ No newline at end of file
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