Commit ae25e43c authored by Alexander.Trofimov's avatar Alexander.Trofimov Committed by Alexander.Trofimov

asc_CHandlersList перевел на prototype

DrawingContext перевел на prototype

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@56953 954022d7-b5bf-4e40-9824-e11837661b57
parent 8904ff9f
...@@ -7,175 +7,169 @@ ...@@ -7,175 +7,169 @@
*/ */
(function (/** jQuery */$, /** Window */window, undefined) { (function (/** jQuery */$, /** Window */window, undefined) {
/* /*
* Import * Import
* ----------------------------------------------------------------------------- * -----------------------------------------------------------------------------
*/ */
var asc = window["Asc"]; var asc = window["Asc"];
var asc_round = asc.round; var asc_round = asc.round;
var asc_floor = asc.floor; var asc_floor = asc.floor;
function colorObjToAscColor(color) { function colorObjToAscColor(color) {
var oRes = null; var oRes = null;
var r = color.getR(); var r = color.getR();
var g = color.getG(); var g = color.getG();
var b = color.getB(); var b = color.getB();
var bTheme = false; var bTheme = false;
if(color instanceof ThemeColor && null != color.theme) if(color instanceof ThemeColor && null != color.theme)
{
var array_colors_types = [6, 15, 7, 16, 0, 1, 2, 3, 4, 5];
var themePresentation = array_colors_types[color.theme];
var tintExcel = 0;
if(null != color.tint)
tintExcel = color.tint;
var tintPresentation = 0;
var basecolor = g_oColorManager.getThemeColor(color.theme);
var oThemeColorTint = g_oThemeColorsDefaultModsSpreadsheet[GetDefaultColorModsIndex(basecolor.getR(), basecolor.getG(), basecolor.getB())];
if(null != oThemeColorTint)
{ {
for(var i = 0 , length = oThemeColorTint.length; i < length; ++i) var array_colors_types = [6, 15, 7, 16, 0, 1, 2, 3, 4, 5];
var themePresentation = array_colors_types[color.theme];
var tintExcel = 0;
if(null != color.tint)
tintExcel = color.tint;
var tintPresentation = 0;
var basecolor = g_oColorManager.getThemeColor(color.theme);
var oThemeColorTint = g_oThemeColorsDefaultModsSpreadsheet[GetDefaultColorModsIndex(basecolor.getR(), basecolor.getG(), basecolor.getB())];
if(null != oThemeColorTint)
{ {
var cur = oThemeColorTint[i]; for(var i = 0 , length = oThemeColorTint.length; i < length; ++i)
//0.005 установлено экспериментально
if(Math.abs(cur - tintExcel) < 0.005)
{ {
bTheme = true; var cur = oThemeColorTint[i];
tintPresentation = i; //0.005 установлено экспериментально
break; if(Math.abs(cur - tintExcel) < 0.005)
{
bTheme = true;
tintPresentation = i;
break;
}
} }
} }
if(bTheme)
{
oRes = new CAscColor();
oRes.r = r;
oRes.g = g;
oRes.b = b;
oRes.a = 255;
oRes.type = c_oAscColor.COLOR_TYPE_SCHEME;
oRes.value = themePresentation;
}
} }
if(bTheme) if(false == bTheme)
{ oRes = CreateAscColorCustom(r, g, b);
oRes = new CAscColor(); return oRes;
oRes.r = r;
oRes.g = g;
oRes.b = b;
oRes.a = 255;
oRes.type = c_oAscColor.COLOR_TYPE_SCHEME;
oRes.value = themePresentation;
}
}
if(false == bTheme)
oRes = CreateAscColorCustom(r, g, b);
return oRes;
}
var oldPpi = undefined,
cvt = undefined;
/**
* Gets ratio to convert units
* @param {Number} fromUnits Units (0=px, 1=pt, 2=in, 3=mm)
* @param {Number} toUnits Units (0=px, 1=pt, 2=in, 3=mm)
* @param {Number} ppi Points per inch
* @return {Number} Ratio
*/
function getCvtRatio(fromUnits, toUnits, ppi) {
if (ppi !== oldPpi || oldPpi === undefined) {
var _ppi = 1 / ppi,
_72 = 1 / 72,
_25_4 = 1 / 25.4;
cvt = [
/* px pt in mm */
/*px*/[ 1, 72*_ppi, _ppi, 25.4*_ppi ],
/*pt*/[ ppi*_72, 1, _72, 25.4*_72 ],
/*in*/[ ppi, 72, 1, 25.4 ],
/*mm*/[ ppi*_25_4, 72*_25_4, _25_4, 1 ]
];
oldPpi = ppi;
} }
return cvt[fromUnits][toUnits];
}
/**
* Округляет текущее значение в pt таким образом, чтобы при переводе его в px при указанном DPI получалось
* целое число пикселей
* @param {type} origPt
* @param {type} ppi
* @param {type} pxAddon
* @returns {Number}
*/
function calcNearestPt(origPt, ppi, pxAddon) {
var a = pxAddon !== undefined ? pxAddon : 0,
x = origPt * ppi / 72,
y = x | x,
p = x - y < .000000001 ? 0 : 1; // to fix float number precision caused by binary presentation
return (y + p + a) / ppi * 72;
}
function deg2rad(deg){ var oldPpi = undefined,
return deg * Math.PI / 180.0; cvt = undefined;
}
function rad2deg(rad){
return rad * 180.0 / Math.PI;
}
/**
* Gets ratio to convert units
* @param {Number} fromUnits Units (0=px, 1=pt, 2=in, 3=mm)
* @param {Number} toUnits Units (0=px, 1=pt, 2=in, 3=mm)
* @param {Number} ppi Points per inch
* @return {Number} Ratio
*/
function getCvtRatio(fromUnits, toUnits, ppi) {
if (ppi !== oldPpi || oldPpi === undefined) {
var _ppi = 1 / ppi,
_72 = 1 / 72,
_25_4 = 1 / 25.4;
cvt = [
/* px pt in mm */
/*px*/[ 1, 72*_ppi, _ppi, 25.4*_ppi ],
/*pt*/[ ppi*_72, 1, _72, 25.4*_72 ],
/*in*/[ ppi, 72, 1, 25.4 ],
/*mm*/[ ppi*_25_4, 72*_25_4, _25_4, 1 ]
];
oldPpi = ppi;
}
return cvt[fromUnits][toUnits];
}
/**
* Округляет текущее значение в pt таким образом, чтобы при переводе его в px при указанном DPI получалось
* целое число пикселей
* @param {type} origPt
* @param {type} ppi
* @param {type} pxAddon
* @returns {Number}
*/
function calcNearestPt(origPt, ppi, pxAddon) {
var a = pxAddon !== undefined ? pxAddon : 0,
x = origPt * ppi / 72,
y = x | x,
p = x - y < .000000001 ? 0 : 1; // to fix float number precision caused by binary presentation
return (y + p + a) / ppi * 72;
}
/** @const */ function deg2rad(deg){
var MATRIX_ORDER_PREPEND = 0, return deg * Math.PI / 180.0;
MATRIX_ORDER_APPEND = 1; }
/** function rad2deg(rad){
* @constructor return rad * 180.0 / Math.PI;
*/
function Matrix() {
if ( !(this instanceof Matrix) ) {
return new Matrix();
} }
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 this;
}
Matrix.prototype = { /** @const */
var MATRIX_ORDER_PREPEND = 0,
MATRIX_ORDER_APPEND = 1;
/**
* @constructor
*/
function Matrix() {
if ( !(this instanceof Matrix) ) {
return new Matrix();
}
/** @type Matrix */ this.sx = 1.0;
constructor: Matrix, this.shx = 0.0;
this.shy = 0.0;
this.sy = 1.0;
this.tx = 0.0;
this.ty = 0.0;
reset: function () { return this;
}
Matrix.prototype.reset = function () {
this.sx = 1.0; this.sx = 1.0;
this.shx = 0.0; this.shx = 0.0;
this.shy = 0.0; this.shy = 0.0;
this.sy = 1.0; this.sy = 1.0;
this.tx = 0.0; this.tx = 0.0;
this.ty = 0.0; this.ty = 0.0;
}, };
assign: function (sx, shx, shy, sy, tx, ty) { Matrix.prototype.assign = function (sx, shx, shy, sy, tx, ty) {
this.sx = sx; this.sx = sx;
this.shx = shx; this.shx = shx;
this.shy = shy; this.shy = shy;
this.sy = sy; this.sy = sy;
this.tx = tx; this.tx = tx;
this.ty = ty; this.ty = ty;
}, };
copyFrom: function (matrix) { Matrix.prototype.copyFrom = function (matrix) {
this.sx = matrix.sx; this.sx = matrix.sx;
this.shx = matrix.shx; this.shx = matrix.shx;
this.shy = matrix.shy; this.shy = matrix.shy;
this.sy = matrix.sy; this.sy = matrix.sy;
this.tx = matrix.tx; this.tx = matrix.tx;
this.ty = matrix.ty; this.ty = matrix.ty;
}, };
clone: function () { Matrix.prototype.clone = function () {
var m = new Matrix(); var m = new Matrix();
m.copyFrom(this); m.copyFrom(this);
return m; return m;
}, };
multiply: function (matrix, order) { Matrix.prototype.multiply = function (matrix, order) {
if (MATRIX_ORDER_PREPEND === order) { if (MATRIX_ORDER_PREPEND === order) {
var m = matrix.clone(); var m = matrix.clone();
m.multiply(this, MATRIX_ORDER_APPEND); m.multiply(this, MATRIX_ORDER_APPEND);
...@@ -191,23 +185,23 @@ Matrix.prototype = { ...@@ -191,23 +185,23 @@ Matrix.prototype = {
this.shx = t2; this.shx = t2;
this.tx = t4; this.tx = t4;
} }
}, };
translate: function (x, y, order) { Matrix.prototype.translate = function (x, y, order) {
var m = new Matrix(); var m = new Matrix();
m.tx = x; m.tx = x;
m.ty = y; m.ty = y;
this.multiply(m, order); this.multiply(m, order);
}, };
scale: function (x, y, order) { Matrix.prototype.scale = function (x, y, order) {
var m = new Matrix(); var m = new Matrix();
m.sx = x; m.sx = x;
m.sy = y; m.sy = y;
this.multiply(m, order); this.multiply(m, order);
}, };
rotate: function (a, order) { Matrix.prototype.rotate = function (a, order) {
var m = new Matrix(); var m = new Matrix();
var rad = deg2rad(a); var rad = deg2rad(a);
m.sx = Math.cos(rad); m.sx = Math.cos(rad);
...@@ -215,19 +209,19 @@ Matrix.prototype = { ...@@ -215,19 +209,19 @@ Matrix.prototype = {
m.shy = -Math.sin(rad); m.shy = -Math.sin(rad);
m.sy = Math.cos(rad); m.sy = Math.cos(rad);
this.multiply(m, order); this.multiply(m, order);
}, };
rotateAt: function (a, x, y, order) { Matrix.prototype.rotateAt = function (a, x, y, order) {
this.translate(-x, -y, order); this.translate(-x, -y, order);
this.rotate(a, order); this.rotate(a, order);
this.translate(x, y, order); this.translate(x, y, order);
}, };
determinant: function () { Matrix.prototype.determinant = function () {
return this.sx * this.sy - this.shy * this.shx; return this.sx * this.sy - this.shy * this.shx;
}, };
invert: function () { Matrix.prototype.invert = function () {
var det = this.determinant(); var det = this.determinant();
if (0.0001 > det) {return;} if (0.0001 > det) {return;}
var d = 1 / det; var d = 1 / det;
...@@ -242,18 +236,18 @@ Matrix.prototype = { ...@@ -242,18 +236,18 @@ Matrix.prototype = {
this.sx = t0; this.sx = t0;
this.tx = t4; this.tx = t4;
}, };
transformPointX: function (x, y) { Matrix.prototype.transformPointX = function (x, y) {
return x * this.sx + y * this.shx + this.tx; return x * this.sx + y * this.shx + this.tx;
}, };
transformPointY: function (x, y) { Matrix.prototype.transformPointY = function (x, y) {
return x * this.shy + y * this.sy + this.ty; return x * this.shy + y * this.sy + this.ty;
}, };
/** Calculates rotation angle */ /** Calculates rotation angle */
getRotation: function () { Matrix.prototype.getRotation = function () {
var x1 = 0.0; var x1 = 0.0;
var y1 = 0.0; var y1 = 0.0;
var x2 = 1.0; var x2 = 1.0;
...@@ -262,50 +256,40 @@ Matrix.prototype = { ...@@ -262,50 +256,40 @@ Matrix.prototype = {
this.transformPoint(x2, y2); this.transformPoint(x2, y2);
var a = Math.atan2(y2-y1, x2-x1); var a = Math.atan2(y2-y1, x2-x1);
return rad2deg(a); return rad2deg(a);
} };
};
/**
* Creates font properties
* -----------------------------------------------------------------------------
* @constructor
* @param {String} family Font family
* @param {Number} size Font size
* @param {Boolean} bold Font style - bold
* @param {Boolean} italic Font style - italic
* @param {String} underline Font style - type of underline
* @param {String} strikeout Font style - type of strike-out
*
* @memberOf Asc
*/
function FontProperties(family, size, bold, italic, underline, strikeout) {
if ( !(this instanceof FontProperties) ) {
return new FontProperties(family, size, bold, italic, underline, strikeout);
}
this.FontFamily = {Name: family, Index: -1, Angle : 0};
this.FontSize = size;
this.Bold = !!bold;
this.Italic = !!italic;
this.Underline = underline;
this.Strikeout = strikeout;
/** return this;
* Creates font properties
* -----------------------------------------------------------------------------
* @constructor
* @param {String} family Font family
* @param {Number} size Font size
* @param {Boolean} bold Font style - bold
* @param {Boolean} italic Font style - italic
* @param {String} underline Font style - type of underline
* @param {String} strikeout Font style - type of strike-out
*
* @memberOf Asc
*/
function FontProperties(family, size, bold, italic, underline, strikeout) {
if ( !(this instanceof FontProperties) ) {
return new FontProperties(family, size, bold, italic, underline, strikeout);
} }
this.FontFamily = {Name: family, Index: -1, Angle : 0};
this.FontSize = size;
this.Bold = !!bold;
this.Italic = !!italic;
this.Underline = underline;
this.Strikeout = strikeout;
return this;
}
FontProperties.prototype = {
/** @type FontProperties */
constructor: FontProperties,
/** /**
* Assigns font preperties from another object * Assigns font preperties from another object
* @param {FontProperties} font * @param {FontProperties} font
*/ */
copyFrom: function (font) { FontProperties.prototype.copyFrom = function (font) {
this.FontFamily.Name = font.FontFamily.Name; this.FontFamily.Name = font.FontFamily.Name;
this.FontFamily.Index = font.FontFamily.Index; this.FontFamily.Index = font.FontFamily.Index;
this.FontSize = font.FontSize; this.FontSize = font.FontSize;
...@@ -313,237 +297,230 @@ FontProperties.prototype = { ...@@ -313,237 +297,230 @@ FontProperties.prototype = {
this.Italic = font.Italic; this.Italic = font.Italic;
this.Underline = font.Underline; this.Underline = font.Underline;
this.Strikeout = font.Strikeout; this.Strikeout = font.Strikeout;
}, };
/** @return {FontProperties} */ /** @return {FontProperties} */
clone: function () { FontProperties.prototype.clone = function () {
return new FontProperties(this.FontFamily.Name, this.FontSize, return new FontProperties(this.FontFamily.Name, this.FontSize,
this.Bold, this.Italic, this.Underline, this.Strikeout); this.Bold, this.Italic, this.Underline, this.Strikeout);
}, };
isEqual: function (font) { FontProperties.prototype.isEqual = function (font) {
return font !== undefined && return font !== undefined &&
this.FontFamily.Name.toLowerCase() === font.FontFamily.Name.toLowerCase() && this.FontFamily.Name.toLowerCase() === font.FontFamily.Name.toLowerCase() &&
this.FontSize === font.FontSize && this.FontSize === font.FontSize &&
this.Bold === font.Bold && this.Bold === font.Bold &&
this.Italic === font.Italic; this.Italic === font.Italic;
} };
};
/**
* Creates text metrics
* -----------------------------------------------------------------------------
* @constructor
* @param {Number} width
* @param {Number} height
* @param {Number} lineHeight
* @param {Number} baseline
* @param {Number} descender
* @param {Number} fontSize
* @param {Number} centerline
* @param {Number} widthBB
*
* @memberOf Asc
*/
function TextMetrics(width, height, lineHeight, baseline, descender, fontSize, centerline, widthBB) {
if ( !(this instanceof TextMetrics) ) {
return new TextMetrics(width, height, lineHeight, baseline, descender, fontSize, centerline, widthBB);
}
this.width = width !== undefined ? width : 0;
this.height = height !== undefined ? height : 0;
this.lineHeight = lineHeight !== undefined ? lineHeight : 0;
this.baseline = baseline !== undefined ? baseline : 0;
this.descender = descender !== undefined ? descender : 0;
this.fontSize = fontSize !== undefined ? fontSize : 0;
this.centerline = centerline !== undefined ? centerline : 0;
this.widthBB = widthBB !== undefined ? widthBB : 0;
/** return this;
* Creates text metrics
* -----------------------------------------------------------------------------
* @constructor
* @param {Number} width
* @param {Number} height
* @param {Number} lineHeight
* @param {Number} baseline
* @param {Number} descender
* @param {Number} fontSize
* @param {Number} centerline
* @param {Number} widthBB
*
* @memberOf Asc
*/
function TextMetrics(width, height, lineHeight, baseline, descender, fontSize, centerline, widthBB) {
if ( !(this instanceof TextMetrics) ) {
return new TextMetrics(width, height, lineHeight, baseline, descender, fontSize, centerline, widthBB);
} }
this.width = width !== undefined ? width : 0;
this.height = height !== undefined ? height : 0;
this.lineHeight = lineHeight !== undefined ? lineHeight : 0;
this.baseline = baseline !== undefined ? baseline : 0;
this.descender = descender !== undefined ? descender : 0;
this.fontSize = fontSize !== undefined ? fontSize : 0;
this.centerline = centerline !== undefined ? centerline : 0;
this.widthBB = widthBB !== undefined ? widthBB : 0;
return this;
}
/**
* Creates font metrics
* -----------------------------------------------------------------------------
* @constructor
*
* @memberOf Asc
*/
function FontMetrics () {
this.ascender = 0;
this.descender = 0;
this.lineGap = 0;
this.nat_scale = 0;
this.nat_y1 = 0;
this.nat_y2 = 0;
}
FontMetrics.prototype.clone = function () {
var res = new FontMetrics();
res.ascender = this.ascender;
res.descender = this.descender;
res.lineGap = this.lineGap;
/** res.nat_scale = this.nat_scale;
* Creates font metrics res.nat_y1 = this.nat_y1;
* ----------------------------------------------------------------------------- res.nat_y2 = this.nat_y2;
* @constructor return res;
* };
* @memberOf Asc
*/
function FontMetrics () {
this.ascender = 0;
this.descender = 0;
this.lineGap = 0;
this.nat_scale = 0;
this.nat_y1 = 0;
this.nat_y2 = 0;
}
FontMetrics.prototype.clone = function () {
var res = new FontMetrics();
res.ascender = this.ascender;
res.descender = this.descender;
res.lineGap = this.lineGap;
res.nat_scale = this.nat_scale;
res.nat_y1 = this.nat_y1;
res.nat_y2 = this.nat_y2;
return res;
};
/**
* Emulates scalable canvas context
* -----------------------------------------------------------------------------
* @constructor
* @param {Object} settings Settings : {
* canvas : HTMLElement
* units : units (0=px, 1=pt, 2=in, 3=mm)
* font : FontProperties
* }
*
* @memberOf Asc
*/
function DrawingContext(settings) {
if ( !(this instanceof DrawingContext) ) {
return new DrawingContext(settings);
}
this.canvas = null;
this.ctx = null;
this.setCanvas(settings.canvas);
var ppiTest = /**
$('<div style="position: absolute; width: 10in; height:10in; visibility:hidden; padding:0;"/>') * Emulates scalable canvas context
.appendTo("body"); * -----------------------------------------------------------------------------
this.ppiX = asc_round(ppiTest[0] ? (ppiTest[0].offsetWidth * 0.1) : 96); * @constructor
this.ppiY = asc_round(ppiTest[0] ? (ppiTest[0].offsetHeight * 0.1) : 96); * @param {Object} settings Settings : {
* canvas : HTMLElement
* units : units (0=px, 1=pt, 2=in, 3=mm)
* font : FontProperties
* }
*
* @memberOf Asc
*/
function DrawingContext(settings) {
if ( !(this instanceof DrawingContext) ) {
return new DrawingContext(settings);
}
this.canvas = null;
this.ctx = null;
if (AscBrowser.isRetina) { this.setCanvas(settings.canvas);
this.ppiX <<= 1;
this.ppiY <<= 1;
}
ppiTest.remove(); var ppiTest =
$('<div style="position: absolute; width: 10in; height:10in; visibility:hidden; padding:0;"/>')
.appendTo("body");
this.ppiX = asc_round(ppiTest[0] ? (ppiTest[0].offsetWidth * 0.1) : 96);
this.ppiY = asc_round(ppiTest[0] ? (ppiTest[0].offsetHeight * 0.1) : 96);
this._mct = new Matrix(); // units transform if (AscBrowser.isRetina) {
this._mt = new Matrix(); // user transform this.ppiX <<= 1;
this._mbt = new Matrix(); // bound transform this.ppiY <<= 1;
this._mft = new Matrix(); // full transform }
this._mift = new Matrix(); // inverted full transform
this._im = new Matrix();
this.scaleFactor = 1; ppiTest.remove();
this._1px_x = getCvtRatio(0/*px*/, 3/*mm*/, this.ppiX); this._mct = new Matrix(); // units transform
this._1px_y = getCvtRatio(0/*px*/, 3/*mm*/, this.ppiY); this._mt = new Matrix(); // user transform
this.units = 3/*mm*/; this._mbt = new Matrix(); // bound transform
this.changeUnits(undefined !== settings.units ? settings.units : this.units); this._mft = new Matrix(); // full transform
this._mift = new Matrix(); // inverted full transform
this._im = new Matrix();
this.fmgrGraphics = undefined !== settings.fmgrGraphics ? settings.fmgrGraphics : null; this.scaleFactor = 1;
if (null === this.fmgrGraphics) {
throw "Can not set graphics in DrawingContext";
}
/** @type FontProperties */ this._1px_x = getCvtRatio(0/*px*/, 3/*mm*/, this.ppiX);
this.font = undefined !== settings.font ? settings.font : null; this._1px_y = getCvtRatio(0/*px*/, 3/*mm*/, this.ppiY);
// Font должен быть передан (он общий для всех DrawingContext, т.к. может возникнуть ситуация как в баге http://bugzserver/show_bug.cgi?id=19784) this.units = 3/*mm*/;
if (null === this.font) { this.changeUnits(undefined !== settings.units ? settings.units : this.units);
throw "Can not set font in DrawingContext";
}
// CColor this.fmgrGraphics = undefined !== settings.fmgrGraphics ? settings.fmgrGraphics : null;
this.fillColor = new CColor(255, 255, 255); if (null === this.fmgrGraphics) {
return this; throw "Can not set graphics in DrawingContext";
} }
DrawingContext.prototype = { /** @type FontProperties */
this.font = undefined !== settings.font ? settings.font : null;
// Font должен быть передан (он общий для всех DrawingContext, т.к. может возникнуть ситуация как в баге http://bugzserver/show_bug.cgi?id=19784)
if (null === this.font) {
throw "Can not set font in DrawingContext";
}
/** @type DrawingContext */ // CColor
constructor: DrawingContext, this.fillColor = new CColor(255, 255, 255);
return this;
}
/** /**
* Returns width of drawing context in current units * Returns width of drawing context in current units
* @param {Number} units Единицы измерения (0=px, 1=pt, 2=in, 3=mm) в которых будет возвращена ширина * @param {Number} units Единицы измерения (0=px, 1=pt, 2=in, 3=mm) в которых будет возвращена ширина
* @return {Number} * @return {Number}
*/ */
getWidth: function (units) { DrawingContext.prototype.getWidth = function (units) {
var i = units >= 0 && units <=3 ? units : this.units; var i = units >= 0 && units <=3 ? units : this.units;
return this.canvas.width * getCvtRatio(0/*px*/, i, this.ppiX); return this.canvas.width * getCvtRatio(0/*px*/, i, this.ppiX);
}, };
/** /**
* Returns height of drawing context in current units * Returns height of drawing context in current units
* @param {Number} units Единицы измерения (0=px, 1=pt, 2=in, 3=mm) в которых будет возвращена высота * @param {Number} units Единицы измерения (0=px, 1=pt, 2=in, 3=mm) в которых будет возвращена высота
* @return {Number} * @return {Number}
*/ */
getHeight: function (units) { DrawingContext.prototype.getHeight = function (units) {
var i = units >= 0 && units <=3 ? units : this.units; var i = units >= 0 && units <=3 ? units : this.units;
return this.canvas.height * getCvtRatio(0/*px*/, i, this.ppiY); return this.canvas.height * getCvtRatio(0/*px*/, i, this.ppiY);
}, };
/** /**
* Returns canvas element * Returns canvas element
* @type {Element} * @type {Element}
*/ */
getCanvas: function () { DrawingContext.prototype.getCanvas = function () {
return this.canvas; return this.canvas;
}, };
/** /**
* *
* @param canvas * @param canvas
*/ */
setCanvas: function (canvas) { DrawingContext.prototype.setCanvas = function (canvas) {
if (null == canvas) {return;} if (null == canvas) {return;}
this.canvas = canvas; this.canvas = canvas;
this.ctx = this.canvas.getContext("2d"); this.ctx = this.canvas.getContext("2d");
this.initContextSmoothing(); this.initContextSmoothing();
}, };
/** /**
* Returns pixels per inch ratio * Returns pixels per inch ratio
* @type {Number} * @type {Number}
*/ */
getPPIX: function () { DrawingContext.prototype.getPPIX = function () {
return this.ppiX; return this.ppiX;
}, };
/** /**
* Returns pixels per inch ratio * Returns pixels per inch ratio
* @type {Number} * @type {Number}
*/ */
getPPIY: function () { DrawingContext.prototype.getPPIY = function () {
return this.ppiY; return this.ppiY;
}, };
/** /**
* Returns currrent units (0=px, 1=pt, 2=in, 3=mm) * Returns currrent units (0=px, 1=pt, 2=in, 3=mm)
* @type {Number} * @type {Number}
*/ */
getUnits: function () { DrawingContext.prototype.getUnits = function () {
return this.units; return this.units;
}, };
moveImageData: function (sx, sy, w, h, x, y) { DrawingContext.prototype.moveImageData = function (sx, sy, w, h, x, y) {
var sr = this._calcRect(sx, sy, w, h); var sr = this._calcRect(sx, sy, w, h);
var r = this._calcRect(x, y); var r = this._calcRect(x, y);
var imgData = this.ctx.getImageData(sr.x, sr.y, sr.w, sr.h); var imgData = this.ctx.getImageData(sr.x, sr.y, sr.w, sr.h);
this.clear(); this.clear();
this.ctx.putImageData(imgData, r.x, r.y); this.ctx.putImageData(imgData, r.x, r.y);
return this; return this;
}, };
/** /**
* Changes units of drawing context * Changes units of drawing context
* @param {Number} units New units of drawing context (0=px, 1=pt, 2=in, 3=mm) * @param {Number} units New units of drawing context (0=px, 1=pt, 2=in, 3=mm)
*/ */
changeUnits: function (units) { DrawingContext.prototype.changeUnits = function (units) {
var i = units >= 0 && units <=3 ? units : 0; var i = units >= 0 && units <=3 ? units : 0;
this._mct.sx = getCvtRatio(i, 0/*px*/, this.ppiX); this._mct.sx = getCvtRatio(i, 0/*px*/, this.ppiX);
this._mct.sy = getCvtRatio(i, 0/*px*/, this.ppiY); this._mct.sy = getCvtRatio(i, 0/*px*/, this.ppiY);
...@@ -552,21 +529,21 @@ DrawingContext.prototype = { ...@@ -552,21 +529,21 @@ DrawingContext.prototype = {
this._1px_y = getCvtRatio(0/*px*/, i, this.ppiY); this._1px_y = getCvtRatio(0/*px*/, i, this.ppiY);
this.units = units; this.units = units;
return this; return this;
}, };
/** /**
* Returns currrent zoom ratio * Returns currrent zoom ratio
* @type {Number} * @type {Number}
*/ */
getZoom: function () { DrawingContext.prototype.getZoom = function () {
return this.scaleFactor; return this.scaleFactor;
}, };
/** /**
* Changes scale factor of drawing context by changing its PPI * Changes scale factor of drawing context by changing its PPI
* @param {Number} factor * @param {Number} factor
*/ */
changeZoom: function (factor) { DrawingContext.prototype.changeZoom = function (factor) {
if (factor <= 0) {throw "Scale factor must be >= 0";} if (factor <= 0) {throw "Scale factor must be >= 0";}
factor = asc_round(factor * 1000) / 1000; factor = asc_round(factor * 1000) / 1000;
...@@ -580,16 +557,16 @@ DrawingContext.prototype = { ...@@ -580,16 +557,16 @@ DrawingContext.prototype = {
this.setFont(this.font); this.setFont(this.font);
return this; return this;
}, };
/** /**
* Resets dimensions of drawing context (canvas 'width' and 'height' attributes) * Resets dimensions of drawing context (canvas 'width' and 'height' attributes)
* @param {Number} width New width in current units * @param {Number} width New width in current units
* @param {Number} height New height in current units * @param {Number} height New height in current units
*/ */
resetSize: function (width, height) { DrawingContext.prototype.resetSize = function (width, height) {
var w = asc_round( width * getCvtRatio(this.units, 0/*px*/, this.ppiX) ), var w = asc_round( width * getCvtRatio(this.units, 0/*px*/, this.ppiX) ),
h = asc_round( height * getCvtRatio(this.units, 0/*px*/, this.ppiY) ); h = asc_round( height * getCvtRatio(this.units, 0/*px*/, this.ppiY) );
if (w !== this.canvas.width) { if (w !== this.canvas.width) {
this.canvas.width = w; this.canvas.width = w;
} }
...@@ -597,16 +574,16 @@ DrawingContext.prototype = { ...@@ -597,16 +574,16 @@ DrawingContext.prototype = {
this.canvas.height = h; this.canvas.height = h;
} }
return this; return this;
}, };
/** /**
* Expands dimensions of drawing context (canvas 'width' and 'height' attributes) * Expands dimensions of drawing context (canvas 'width' and 'height' attributes)
* @param {Number} width New width in current units * @param {Number} width New width in current units
* @param {Number} height New height in current units * @param {Number} height New height in current units
*/ */
expand: function (width, height) { DrawingContext.prototype.expand = function (width, height) {
var w = asc_round( width * getCvtRatio(this.units, 0/*px*/, this.ppiX) ), var w = asc_round( width * getCvtRatio(this.units, 0/*px*/, this.ppiX) ),
h = asc_round( height * getCvtRatio(this.units, 0/*px*/, this.ppiY) ); h = asc_round( height * getCvtRatio(this.units, 0/*px*/, this.ppiY) );
if (w > this.canvas.width) { if (w > this.canvas.width) {
this.canvas.width = w; this.canvas.width = w;
} }
...@@ -614,12 +591,12 @@ DrawingContext.prototype = { ...@@ -614,12 +591,12 @@ DrawingContext.prototype = {
this.canvas.height = h; this.canvas.height = h;
} }
return this; return this;
}, };
/** /**
* Delete smoothing * Delete smoothing
*/ */
initContextSmoothing: function () { DrawingContext.prototype.initContextSmoothing = function () {
var ctx = this.ctx; var ctx = this.ctx;
if (!window.g_isMobileVersion || null === ctx) if (!window.g_isMobileVersion || null === ctx)
return; return;
...@@ -633,94 +610,94 @@ DrawingContext.prototype = { ...@@ -633,94 +610,94 @@ DrawingContext.prototype = {
ctx.oImageSmoothingEnabled = false; ctx.oImageSmoothingEnabled = false;
if (ctx.webkitImageSmoothingEnabled) if (ctx.webkitImageSmoothingEnabled)
ctx.webkitImageSmoothingEnabled = false; ctx.webkitImageSmoothingEnabled = false;
}, };
// Canvas methods // Canvas methods
clear: function () { DrawingContext.prototype.clear = function () {
this.clearRect(0, 0, this.getWidth(), this.getHeight()); this.clearRect(0, 0, this.getWidth(), this.getHeight());
return this; return this;
}, };
save: function () { DrawingContext.prototype.save = function () {
this.ctx.save(); this.ctx.save();
return this; return this;
}, };
restore: function () { DrawingContext.prototype.restore = function () {
this.ctx.restore(); this.ctx.restore();
return this; return this;
}, };
scale: function (kx, ky) { DrawingContext.prototype.scale = function (kx, ky) {
//TODO: implement scale() //TODO: implement scale()
return this; return this;
}, };
rotate: function (a) { DrawingContext.prototype.rotate = function (a) {
//TODO: implement rotate() //TODO: implement rotate()
return this; return this;
}, };
translate: function (dx, dy) { DrawingContext.prototype.translate = function (dx, dy) {
//TODO: implement translate() //TODO: implement translate()
return this; return this;
}, };
transform: function (sx, shy, shx, sy, tx, ty) { DrawingContext.prototype.transform = function (sx, shy, shx, sy, tx, ty) {
//TODO: implement transform() //TODO: implement transform()
return this; return this;
}, };
setTransform: function(sx, shy, shx, sy, tx, ty) { DrawingContext.prototype.setTransform = function(sx, shy, shx, sy, tx, ty) {
this._mbt.assign(sx, shx, shy, sy, tx, ty); this._mbt.assign(sx, shx, shy, sy, tx, ty);
return this; return this;
}, };
setTextTransform: function(sx, shy, shx, sy, tx, ty) { DrawingContext.prototype.setTextTransform = function(sx, shy, shx, sy, tx, ty) {
this._mt.assign(sx, shx, shy, sy, tx, ty); this._mt.assign(sx, shx, shy, sy, tx, ty);
return this; return this;
}, };
updateTransforms: function() { DrawingContext.prototype.updateTransforms = function() {
this._calcMFT(); this._calcMFT();
this.fmgrGraphics[1].SetTextMatrix( this.fmgrGraphics[1].SetTextMatrix(
this._mt.sx, this._mt.shy, this._mt.shx, this._mt.sy, this._mt.tx, this._mt.ty); this._mt.sx, this._mt.shy, this._mt.shx, this._mt.sy, this._mt.tx, this._mt.ty);
}, };
resetTransforms: function(){ DrawingContext.prototype.resetTransforms = function(){
this.setTransform(this._im.sx, this._im.shy, this._im.shx, this._im.sy, this._im.tx, this._im.ty); this.setTransform(this._im.sx, this._im.shy, this._im.shx, this._im.sy, this._im.tx, this._im.ty);
this.setTextTransform(this._im.sx, this._im.shy, this._im.shx, this._im.sy, this._im.tx, this._im.ty); this.setTextTransform(this._im.sx, this._im.shy, this._im.shx, this._im.sy, this._im.tx, this._im.ty);
this._calcMFT(); this._calcMFT();
}, };
// Style methods // Style methods
getFillStyle: function () { DrawingContext.prototype.getFillStyle = function () {
return this.ctx.fillStyle; return this.ctx.fillStyle;
}, };
getStrokeStyle: function () { DrawingContext.prototype.getStrokeStyle = function () {
return this.ctx.strokeStyle; return this.ctx.strokeStyle;
}, };
getLineWidth: function () { DrawingContext.prototype.getLineWidth = function () {
return this.ctx.lineWidth; return this.ctx.lineWidth;
}, };
getLineCap: function () { DrawingContext.prototype.getLineCap = function () {
return this.ctx.lineCap; return this.ctx.lineCap;
}, };
getLineJoin: function () { DrawingContext.prototype.getLineJoin = function () {
return this.ctx.lineJoin; return this.ctx.lineJoin;
}, };
/** /**
* @param {RgbColor || ThemeColor || CColor} val * @param {RgbColor || ThemeColor || CColor} val
* @returns {DrawingContext} * @returns {DrawingContext}
*/ */
setFillStyle: function (val) { DrawingContext.prototype.setFillStyle = function (val) {
var _r = val.getR(); var _r = val.getR();
var _g = val.getG(); var _g = val.getG();
var _b = val.getB(); var _b = val.getB();
...@@ -728,88 +705,88 @@ DrawingContext.prototype = { ...@@ -728,88 +705,88 @@ DrawingContext.prototype = {
this.fillColor = new CColor(_r, _g, _b, _a); this.fillColor = new CColor(_r, _g, _b, _a);
this.ctx.fillStyle = "rgba(" + _r + "," + _g + "," + _b + "," + _a + ")"; this.ctx.fillStyle = "rgba(" + _r + "," + _g + "," + _b + "," + _a + ")";
return this; return this;
}, };
setFillPattern: function (val) { DrawingContext.prototype.setFillPattern = function (val) {
this.ctx.fillStyle = val; this.ctx.fillStyle = val;
return this; return this;
}, };
/** /**
* @param {RgbColor || ThemeColor || CColor} val * @param {RgbColor || ThemeColor || CColor} val
* @returns {DrawingContext} * @returns {DrawingContext}
*/ */
setStrokeStyle: function (val) { DrawingContext.prototype.setStrokeStyle = function (val) {
var _r = val.getR(); var _r = val.getR();
var _g = val.getG(); var _g = val.getG();
var _b = val.getB(); var _b = val.getB();
var _a = val.getA(); var _a = val.getA();
this.ctx.strokeStyle = "rgba(" + _r + "," + _g + "," + _b + "," + _a + ")"; this.ctx.strokeStyle = "rgba(" + _r + "," + _g + "," + _b + "," + _a + ")";
return this; return this;
}, };
setLineWidth: function (width) { DrawingContext.prototype.setLineWidth = function (width) {
this.ctx.lineWidth = width; this.ctx.lineWidth = width;
return this; return this;
}, };
setLineCap: function (cap) { DrawingContext.prototype.setLineCap = function (cap) {
this.ctx.lineCap = cap; this.ctx.lineCap = cap;
return this; return this;
}, };
setLineJoin: function (join) { DrawingContext.prototype.setLineJoin = function (join) {
this.ctx.lineJoin = join; this.ctx.lineJoin = join;
return this; return this;
}, };
fillRect: function (x, y, w, h) { DrawingContext.prototype.fillRect = function (x, y, w, h) {
var r = this._calcRect(x, y, w, h); var r = this._calcRect(x, y, w, h);
this.ctx.fillRect(r.x, r.y, r.w, r.h); this.ctx.fillRect(r.x, r.y, r.w, r.h);
return this; return this;
}, };
strokeRect: function (x, y, w, h) { DrawingContext.prototype.strokeRect = function (x, y, w, h) {
var r = this._calcRect(x, y, w, h); var r = this._calcRect(x, y, w, h);
this.ctx.strokeRect(r.x+0.5, r.y+0.5, r.w-1, r.h-1); this.ctx.strokeRect(r.x+0.5, r.y+0.5, r.w-1, r.h-1);
return this; return this;
}, };
clearRect: function (x, y, w, h) { DrawingContext.prototype.clearRect = function (x, y, w, h) {
var r = this._calcRect(x, y, w, h); var r = this._calcRect(x, y, w, h);
this.ctx.clearRect(r.x, r.y, r.w, r.h); this.ctx.clearRect(r.x, r.y, r.w, r.h);
return this; return this;
}, };
// Font and text methods // Font and text methods
getFont: function () { DrawingContext.prototype.getFont = function () {
return this.font.clone(); return this.font.clone();
}, };
getFontFamily: function () { DrawingContext.prototype.getFontFamily = function () {
return this.font.FontFamily.Name; return this.font.FontFamily.Name;
}, };
getFontSize: function () { DrawingContext.prototype.getFontSize = function () {
return this.font.FontSize; return this.font.FontSize;
}, };
/** /**
* @param {Number} units Units of result (0=px, 1=pt, 2=in, 3=mm) * @param {Number} units Units of result (0=px, 1=pt, 2=in, 3=mm)
* @return {FontMetrics} * @return {FontMetrics}
*/ */
getFontMetrics: function (units) { DrawingContext.prototype.getFontMetrics = function (units) {
var fm = this.fmgrGraphics[0]; var fm = this.fmgrGraphics[0];
var d = Math.abs(fm.m_lDescender); var d = Math.abs(fm.m_lDescender);
var r = getCvtRatio(0/*px*/, units >= 0 && units <=3 ? units : this.units, this.ppiX); var r = getCvtRatio(0/*px*/, units >= 0 && units <=3 ? units : this.units, this.ppiX);
var factor = this.getFontSize() * r / fm.m_lUnits_Per_Em; var factor = this.getFontSize() * r / fm.m_lUnits_Per_Em;
var res = new FontMetrics(); var res = new FontMetrics();
res.ascender = factor * fm.m_lAscender; res.ascender = factor * fm.m_lAscender;
res.descender = factor * d; res.descender = factor * d;
res.lineGap = factor * (fm.m_lLineHeight - fm.m_lAscender - d); res.lineGap = factor * (fm.m_lLineHeight - fm.m_lAscender - d);
var face = fm.m_pFont.m_pFace; var face = fm.m_pFont.m_pFace;
res.nat_scale = face.header.Units_Per_EM; res.nat_scale = face.header.Units_Per_EM;
...@@ -821,47 +798,53 @@ DrawingContext.prototype = { ...@@ -821,47 +798,53 @@ DrawingContext.prototype = {
res.nat_y2 = face.header.yMin; res.nat_y2 = face.header.yMin;
} }
return res; return res;
}, };
setFont: function (font, angle) { /**
var italic, bold, fontStyle, r; *
* @param font
* @param angle
* @returns {DrawingContext}
*/
DrawingContext.prototype.setFont = function (font, angle) {
var italic, bold, fontStyle, r;
if (font.FontFamily.Index === undefined || if (font.FontFamily.Index === undefined ||
font.FontFamily.Index === null || font.FontFamily.Index === null ||
font.FontFamily.Index === -1) { font.FontFamily.Index === -1) {
font.FontFamily.Index = window.g_map_font_index[font.FontFamily.Name]; font.FontFamily.Index = window.g_map_font_index[font.FontFamily.Name];
} }
this.font.copyFrom(font); this.font.copyFrom(font);
italic = true === font.Italic; italic = true === font.Italic;
bold = true === font.Bold; bold = true === font.Bold;
fontStyle = FontStyle.FontStyleRegular; fontStyle = FontStyle.FontStyleRegular;
if ( !italic && bold ) if ( !italic && bold )
fontStyle = FontStyle.FontStyleBold; fontStyle = FontStyle.FontStyleBold;
else if ( italic && !bold ) else if ( italic && !bold )
fontStyle = FontStyle.FontStyleItalic; fontStyle = FontStyle.FontStyleItalic;
else if ( italic && bold ) else if ( italic && bold )
fontStyle = FontStyle.FontStyleBoldItalic; fontStyle = FontStyle.FontStyleBoldItalic;
if (angle && 0 != angle) { if (angle && 0 != angle) {
r = window.g_font_infos[ font.FontFamily.Index ].LoadFont( r = window.g_font_infos[ font.FontFamily.Index ].LoadFont(
window.g_font_loader, this.fmgrGraphics[1], font.FontSize, fontStyle, this.ppiX, this.ppiY); window.g_font_loader, this.fmgrGraphics[1], font.FontSize, fontStyle, this.ppiX, this.ppiY);
this.fmgrGraphics[1].SetTextMatrix( this.fmgrGraphics[1].SetTextMatrix(
this._mt.sx, this._mt.shy, this._mt.shx, this._mt.sy, this._mt.tx, this._mt.ty); this._mt.sx, this._mt.shy, this._mt.shx, this._mt.sy, this._mt.tx, this._mt.ty);
} else { } else {
r = window.g_font_infos[ font.FontFamily.Index ].LoadFont( r = window.g_font_infos[ font.FontFamily.Index ].LoadFont(
window.g_font_loader, this.fmgrGraphics[0], font.FontSize, fontStyle, this.ppiX, this.ppiY); window.g_font_loader, this.fmgrGraphics[0], font.FontSize, fontStyle, this.ppiX, this.ppiY);
} }
if (r === false) { if (r === false) {
throw "Can not use " + font.FontFamily.Name + " font. (Check whether font file is loaded)"; throw "Can not use " + font.FontFamily.Name + " font. (Check whether font file is loaded)";
} }
return this; return this;
}, };
/** /**
* Returns dimensions of first char of string * Returns dimensions of first char of string
...@@ -869,9 +852,9 @@ DrawingContext.prototype = { ...@@ -869,9 +852,9 @@ DrawingContext.prototype = {
* @param {Number} units Units (0 = px, 1 = pt, 2 = in, 3 = mm) * @param {Number} units Units (0 = px, 1 = pt, 2 = in, 3 = mm)
* @return {TextMetrics} Returns the char dimension * @return {TextMetrics} Returns the char dimension
*/ */
measureChar: function (text, units) { DrawingContext.prototype.measureChar = function (text, units) {
return this.measureText(text.charAt(0), units); return this.measureText(text.charAt(0), units);
}, };
/** /**
* Returns dimensions of string * Returns dimensions of string
...@@ -879,27 +862,26 @@ DrawingContext.prototype = { ...@@ -879,27 +862,26 @@ DrawingContext.prototype = {
* @param {Number} units Units (0 = px, 1 = pt, 2 = in, 3 = mm) * @param {Number} units Units (0 = px, 1 = pt, 2 = in, 3 = mm)
* @return {TextMetrics} Returns the dimension of string {width: w, height: h} * @return {TextMetrics} Returns the dimension of string {width: w, height: h}
*/ */
measureText: function (text, units) { DrawingContext.prototype.measureText = function (text, units) {
var fm = this.fmgrGraphics[0], var fm = this.fmgrGraphics[0],
r = getCvtRatio(0/*px*/, units >= 0 && units <=3 ? units : this.units, this.ppiX); r = getCvtRatio(0/*px*/, units >= 0 && units <=3 ? units : this.units, this.ppiX);
for (var tmp, w = 0, w2 = 0, i = 0; i < text.length; ++i) { for (var tmp, w = 0, w2 = 0, i = 0; i < text.length; ++i) {
tmp = fm.MeasureChar( text.charCodeAt(i) ); tmp = fm.MeasureChar( text.charCodeAt(i) );
w += tmp.fAdvanceX; w += tmp.fAdvanceX;
} }
w2 = w - tmp.fAdvanceX + tmp.oBBox.fMaxX - tmp.oBBox.fMinX + 1; w2 = w - tmp.fAdvanceX + tmp.oBBox.fMaxX - tmp.oBBox.fMinX + 1;
return this._calcTextMetrics(w * r, w2 * r, fm, r); return this._calcTextMetrics(w * r, w2 * r, fm, r);
}, };
getHeightText: function() DrawingContext.prototype.getHeightText = function() {
{ var fm = this.fmgrGraphics[0];
var fm = this.fmgrGraphics[0];
var UnitsPerEm = fm.m_lUnits_Per_Em; var UnitsPerEm = fm.m_lUnits_Per_Em;
var Height = fm.m_lLineHeight; var Height = fm.m_lLineHeight;
var setUpSize = this.font.FontSize; var setUpSize = this.font.FontSize;
return Height * setUpSize / UnitsPerEm; return Height * setUpSize / UnitsPerEm;
}, };
fillGlyph: function (pGlyph, fmgr) { DrawingContext.prototype.fillGlyph = function (pGlyph, fmgr) {
var nW = pGlyph.oBitmap.nWidth; var nW = pGlyph.oBitmap.nWidth;
var nH = pGlyph.oBitmap.nHeight; var nH = pGlyph.oBitmap.nHeight;
...@@ -939,80 +921,80 @@ DrawingContext.prototype = { ...@@ -939,80 +921,80 @@ DrawingContext.prototype = {
pGlyph.oBitmap.oGlyphData.checkColor(_r, _g, _b, nW, nH); pGlyph.oBitmap.oGlyphData.checkColor(_r, _g, _b, nW, nH);
pGlyph.oBitmap.draw(this.ctx, nX, nY); pGlyph.oBitmap.draw(this.ctx, nX, nY);
} }
}, };
fillText: function (text, x, y, maxWidth, charWidths, angle) { DrawingContext.prototype.fillText = function (text, x, y, maxWidth, charWidths, angle) {
var manager = angle ? this.fmgrGraphics[1] : this.fmgrGraphics[0]; var manager = angle ? this.fmgrGraphics[1] : this.fmgrGraphics[0];
var _x = this._mift.transformPointX(x, y); var _x = this._mift.transformPointX(x, y);
var _y = this._mift.transformPointY(x, y); var _y = this._mift.transformPointY(x, y);
var length = text.length; var length = text.length;
for (var i = 0; i < length; ++i) { for (var i = 0; i < length; ++i) {
try { try {
_x = manager.LoadString2C(text.charAt(i), _x, _y); _x = manager.LoadString2C(text.charAt(i), _x, _y);
} catch(err) { } catch(err) {
// do nothing // do nothing
} }
var pGlyph = manager.m_oGlyphString.m_pGlyphsBuffer[0]; var pGlyph = manager.m_oGlyphString.m_pGlyphsBuffer[0];
if (null === pGlyph || null === pGlyph.oBitmap) {continue;} if (null === pGlyph || null === pGlyph.oBitmap) {continue;}
this.fillGlyph(pGlyph, manager); this.fillGlyph(pGlyph, manager);
} }
return this; return this;
}, };
// Path methods // Path methods
beginPath: function () { DrawingContext.prototype.beginPath = function () {
this.ctx.beginPath(); this.ctx.beginPath();
return this; return this;
}, };
closePath: function () { DrawingContext.prototype.closePath = function () {
this.ctx.closePath(); this.ctx.closePath();
return this; return this;
}, };
moveTo: function (x, y) { DrawingContext.prototype.moveTo = function (x, y) {
var r = this._calcRect(x, y); var r = this._calcRect(x, y);
this.ctx.moveTo(r.x, r.y); this.ctx.moveTo(r.x, r.y);
return this; return this;
}, };
lineTo: function (x, y) { DrawingContext.prototype.lineTo = function (x, y) {
var r = this._calcRect(x, y); var r = this._calcRect(x, y);
this.ctx.lineTo(r.x, r.y); this.ctx.lineTo(r.x, r.y);
return this; return this;
}, };
lineDiag : function (x1, y1, x2, y2) { DrawingContext.prototype.lineDiag = function (x1, y1, x2, y2) {
var isEven = 0 !== this.ctx.lineWidth % 2 ? 0.5 : 0; var isEven = 0 !== this.ctx.lineWidth % 2 ? 0.5 : 0;
var r1 = this._calcRect(x1, y1); var r1 = this._calcRect(x1, y1);
var r2 = this._calcRect(x2, y2); var r2 = this._calcRect(x2, y2);
this.ctx.moveTo(r1.x + isEven, r1.y + isEven); this.ctx.moveTo(r1.x + isEven, r1.y + isEven);
this.ctx.lineTo(r2.x + isEven, r2.y + isEven); this.ctx.lineTo(r2.x + isEven, r2.y + isEven);
return this; return this;
}, };
lineHor : function (x1, y, x2) { DrawingContext.prototype.lineHor = function (x1, y, x2) {
var isEven = 0 !== this.ctx.lineWidth % 2 ? 0.5 : 0; var isEven = 0 !== this.ctx.lineWidth % 2 ? 0.5 : 0;
var r1 = this._calcRect(x1, y); var r1 = this._calcRect(x1, y);
var r2 = this._calcRect(x2, y); var r2 = this._calcRect(x2, y);
this.ctx.moveTo(r1.x, r1.y + isEven); this.ctx.moveTo(r1.x, r1.y + isEven);
this.ctx.lineTo(r2.x, r2.y + isEven); this.ctx.lineTo(r2.x, r2.y + isEven);
return this; return this;
}, };
lineVer : function (x, y1, y2) { DrawingContext.prototype.lineVer = function (x, y1, y2) {
var isEven = 0 !== this.ctx.lineWidth % 2 ? 0.5 : 0; var isEven = 0 !== this.ctx.lineWidth % 2 ? 0.5 : 0;
var r1 = this._calcRect(x, y1); var r1 = this._calcRect(x, y1);
var r2 = this._calcRect(x, y2); var r2 = this._calcRect(x, y2);
this.ctx.moveTo(r1.x + isEven, r1.y); this.ctx.moveTo(r1.x + isEven, r1.y);
this.ctx.lineTo(r2.x + isEven, r2.y); this.ctx.lineTo(r2.x + isEven, r2.y);
return this; return this;
}, };
dashLineCleverHor : function (x1, y, x2) { DrawingContext.prototype.dashLineCleverHor = function (x1, y, x2) {
var w_dot = c_oAscCoAuthoringDottedWidth, w_dist = c_oAscCoAuthoringDottedDistance; var w_dot = c_oAscCoAuthoringDottedWidth, w_dist = c_oAscCoAuthoringDottedDistance;
var _x1 = this._mct.transformPointX(x1, y); var _x1 = this._mct.transformPointX(x1, y);
var _y = this._mct.transformPointY(x1, y); var _y = this._mct.transformPointY(x1, y);
...@@ -1032,8 +1014,8 @@ DrawingContext.prototype = { ...@@ -1032,8 +1014,8 @@ DrawingContext.prototype = {
ctx.lineTo(_x1, _y); ctx.lineTo(_x1, _y);
} }
}, };
dashLineCleverVer : function (x, y1, y2) { DrawingContext.prototype.dashLineCleverVer = function (x, y1, y2) {
var w_dot = c_oAscCoAuthoringDottedWidth, w_dist = c_oAscCoAuthoringDottedDistance; var w_dot = c_oAscCoAuthoringDottedWidth, w_dist = c_oAscCoAuthoringDottedDistance;
var _y1 = this._mct.transformPointY(x, y1); var _y1 = this._mct.transformPointY(x, y1);
var _x = this._mct.transformPointX(x, y1); var _x = this._mct.transformPointX(x, y1);
...@@ -1053,9 +1035,9 @@ DrawingContext.prototype = { ...@@ -1053,9 +1035,9 @@ DrawingContext.prototype = {
ctx.lineTo(_x, _y1); ctx.lineTo(_x, _y1);
} }
}, };
dashLine: function (x1, y1, x2, y2, w_dot, w_dist) { DrawingContext.prototype.dashLine = function (x1, y1, x2, y2, w_dot, w_dist) {
var len = Math.sqrt ((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1)); var len = Math.sqrt ((x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1));
if (len < 1) if (len < 1)
len = 1; len = 1;
...@@ -1120,89 +1102,88 @@ DrawingContext.prototype = { ...@@ -1120,89 +1102,88 @@ DrawingContext.prototype = {
if (j < y2) if (j < y2)
j = y2; j = y2;
this.lineTo(i, j); this.lineTo(i, j);
} }
} }
}, };
dashRect: function (x1, y1, x2, y2, x3, y3, x4, y4, w_dot, w_dist) { DrawingContext.prototype.dashRect = function (x1, y1, x2, y2, x3, y3, x4, y4, w_dot, w_dist) {
this.dashLine(x1, y1, x2, y2, w_dot, w_dist); this.dashLine(x1, y1, x2, y2, w_dot, w_dist);
this.dashLine(x2, y2, x4, y4, w_dot, w_dist); this.dashLine(x2, y2, x4, y4, w_dot, w_dist);
this.dashLine(x4, y4, x3, y3, w_dot, w_dist); this.dashLine(x4, y4, x3, y3, w_dot, w_dist);
this.dashLine(x3, y3, x1, y1, w_dot, w_dist); this.dashLine(x3, y3, x1, y1, w_dot, w_dist);
}, };
rect: function (x, y, w, h) { DrawingContext.prototype.rect = function (x, y, w, h) {
var r = this._calcRect(x, y, w, h); var r = this._calcRect(x, y, w, h);
this.ctx.rect(r.x, r.y, r.w, r.h); this.ctx.rect(r.x, r.y, r.w, r.h);
return this; return this;
}, };
arc: function (x, y, radius, startAngle, endAngle, antiClockwise, dx, dy) { DrawingContext.prototype.arc = function (x, y, radius, startAngle, endAngle, antiClockwise, dx, dy) {
var r = this._calcRect(x, y); var r = this._calcRect(x, y);
dx = typeof dx !== "undefined" ? dx : 0; dx = typeof dx !== "undefined" ? dx : 0;
dy = typeof dy !== "undefined" ? dy : 0; dy = typeof dy !== "undefined" ? dy : 0;
this.ctx.arc(r.x + dx, r.y + dy, radius, startAngle, endAngle, antiClockwise); this.ctx.arc(r.x + dx, r.y + dy, radius, startAngle, endAngle, antiClockwise);
return this; return this;
}, };
bezierCurveTo: function (x1, y1, x2, y2, x3, y3) { DrawingContext.prototype.bezierCurveTo = function (x1, y1, x2, y2, x3, y3) {
var p1 = this._calcRect(x1, y1), var p1 = this._calcRect(x1, y1),
p2 = this._calcRect(x2, y2), p2 = this._calcRect(x2, y2),
p3 = this._calcRect(x3, y3); p3 = this._calcRect(x3, y3);
this.ctx.bezierCurveTo(p1.x, p1.y, p2.x, p2.y, p3.x, p3.y); this.ctx.bezierCurveTo(p1.x, p1.y, p2.x, p2.y, p3.x, p3.y);
return this; return this;
}, };
fill: function () { DrawingContext.prototype.fill = function () {
this.ctx.fill(); this.ctx.fill();
return this; return this;
}, };
stroke: function () { DrawingContext.prototype.stroke = function () {
this.ctx.stroke(); this.ctx.stroke();
return this; return this;
}, };
clip: function () { DrawingContext.prototype.clip = function () {
this.ctx.clip(); this.ctx.clip();
return this; return this;
}, };
// Image methods // Image methods
DrawingContext.prototype.drawImage = function (img, sx, sy, sw, sh, dx, dy, dw, dh) {
drawImage: function (img, sx, sy, sw, sh, dx, dy, dw, dh) {
var sr = this._calcRect(sx, sy, sw, sh), var sr = this._calcRect(sx, sy, sw, sh),
dr = this._calcRect(dx, dy, dw, dh); dr = this._calcRect(dx, dy, dw, dh);
this.ctx.drawImage(img, sr.x, sr.y, sr.w, sr.h, dr.x, dr.y, dr.w, dr.h); this.ctx.drawImage(img, sr.x, sr.y, sr.w, sr.h, dr.x, dr.y, dr.w, dr.h);
return this; return this;
}, };
// Private methods // Private methods
_calcRect: function (x, y, w, h) { DrawingContext.prototype._calcRect = function (x, y, w, h) {
var wh = w !== undefined && h !== undefined, var wh = w !== undefined && h !== undefined,
x2 = x + w - this._1px_x, x2 = x + w - this._1px_x,
y2 = y + h - this._1px_y, y2 = y + h - this._1px_y,
_x = this._mft.transformPointX(x, y), _x = this._mft.transformPointX(x, y),
_y = this._mft.transformPointY(x, y); _y = this._mft.transformPointY(x, y);
return { return {
x: asc_round(_x), x: asc_round(_x),
y: asc_round(_y), y: asc_round(_y),
w: wh ? asc_round(this._mft.transformPointX(x2, y2) - _x + 1) : undefined, w: wh ? asc_round(this._mft.transformPointX(x2, y2) - _x + 1) : undefined,
h: wh ? asc_round(this._mft.transformPointY(x2, y2) - _y + 1) : undefined h: wh ? asc_round(this._mft.transformPointY(x2, y2) - _y + 1) : undefined
}; };
}, };
_calcMFT: function () { DrawingContext.prototype._calcMFT = function () {
this._mft = this._mct.clone(); this._mft = this._mct.clone();
this._mft.multiply(this._mbt, MATRIX_ORDER_PREPEND); this._mft.multiply(this._mbt, MATRIX_ORDER_PREPEND);
this._mft.multiply(this._mt, MATRIX_ORDER_PREPEND); this._mft.multiply(this._mt, MATRIX_ORDER_PREPEND);
this._mift = this._mt.clone(); this._mift = this._mt.clone();
this._mift.invert(); this._mift.invert();
this._mift.multiply(this._mft, MATRIX_ORDER_PREPEND); this._mift.multiply(this._mft, MATRIX_ORDER_PREPEND);
}, };
/** /**
* @param {Number} w Ширина текста * @param {Number} w Ширина текста
...@@ -1211,29 +1192,28 @@ DrawingContext.prototype = { ...@@ -1211,29 +1192,28 @@ DrawingContext.prototype = {
* @param {Number} r Коэффициент перевода pt -> в текущие единицы измерения (this.units) * @param {Number} r Коэффициент перевода pt -> в текущие единицы измерения (this.units)
* @return {TextMetrics} * @return {TextMetrics}
*/ */
_calcTextMetrics: function (w, wBB, fm, r) { DrawingContext.prototype._calcTextMetrics = function (w, wBB, fm, r) {
var factor = this.getFontSize() * r / fm.m_lUnits_Per_Em, var factor = this.getFontSize() * r / fm.m_lUnits_Per_Em,
l = fm.m_lLineHeight * factor, l = fm.m_lLineHeight * factor,
b = fm.m_lAscender * factor, b = fm.m_lAscender * factor,
d = Math.abs(fm.m_lDescender * factor); d = Math.abs(fm.m_lDescender * factor);
return new TextMetrics(w, b + d, l, b, d, this.font.FontSize, 0, wBB); return new TextMetrics(w, b + d, l, b, d, this.font.FontSize, 0, wBB);
} };
};
/* /*
* Export * Export
* ----------------------------------------------------------------------------- * -----------------------------------------------------------------------------
*/ */
window["Asc"].getCvtRatio = getCvtRatio; window["Asc"].getCvtRatio = getCvtRatio;
window["Asc"].calcNearestPt = calcNearestPt; window["Asc"].calcNearestPt = calcNearestPt;
window["Asc"].colorObjToAscColor = colorObjToAscColor; window["Asc"].colorObjToAscColor = colorObjToAscColor;
window["Asc"].FontProperties = FontProperties; window["Asc"].FontProperties = FontProperties;
window["Asc"].TextMetrics = TextMetrics; window["Asc"].TextMetrics = TextMetrics;
window["Asc"].FontMetrics = FontMetrics; window["Asc"].FontMetrics = FontMetrics;
window["Asc"].DrawingContext = DrawingContext; window["Asc"].DrawingContext = DrawingContext;
window["Asc"].Matrix = Matrix; window["Asc"].Matrix = Matrix;
})(jQuery, window); })(jQuery, window);
...@@ -34,7 +34,7 @@ function Common_CopyObj(Obj) ...@@ -34,7 +34,7 @@ function Common_CopyObj(Obj)
} }
} }
return c; return c;
}; }
var vector_koef = 25.4 / 72; var vector_koef = 25.4 / 72;
......
...@@ -17,80 +17,63 @@ ...@@ -17,80 +17,63 @@
* ----------------------------------------------------------------------------- * -----------------------------------------------------------------------------
*/ */
var asc = window["Asc"], var asc = window["Asc"],
asc_typeOf = asc.typeOf; asc_typeOf = asc.typeOf;
/** @constructor */ /** @constructor */
function asc_CHandlersList(handlers) { function asc_CHandlersList(handlers) {
if ( !(this instanceof asc_CHandlersList) ) {
return new asc_CHandlersList(handlers);
}
this.handlers = handlers || {}; this.handlers = handlers || {};
return this; return this;
} }
asc_CHandlersList.prototype = { asc_CHandlersList.prototype.trigger = function (eventName) {
var h = this.handlers[eventName], t = asc_typeOf(h), a = Array.prototype.slice.call(arguments, 1), i;
trigger: function (eventName) { if (t === "function") {
var h = this.handlers[eventName], t = asc_typeOf(h), a = Array.prototype.slice.call(arguments, 1), i; return h.apply(this, a);
if (t === "function") { }
return h.apply(this, a); if (t === "array") {
for (i = 0; i < h.length; i += 1) {
if (asc_typeOf(h[i]) === "function") {h[i].apply(this, a);}
} }
if (t === "array") { return true;
for (i = 0; i < h.length; i += 1) { }
if (asc_typeOf(h[i]) === "function") {h[i].apply(this, a);} return false;
} };
return true; asc_CHandlersList.prototype.add = function (eventName, eventHandler, replaceOldHandler) {
var th = this.handlers, h, old, t;
if (replaceOldHandler || !th.hasOwnProperty(eventName)) {
th[eventName] = eventHandler;
} else {
old = h = th[eventName];
t = asc_typeOf(old);
if (t !== "array") {
h = th[eventName] = [];
if (t === "function") {h.push(old);}
} }
return false; h.push(eventHandler);
}, }
};
add: function (eventName, eventHandler, replaceOldHandler) { asc_CHandlersList.prototype.remove = function (eventName, eventHandler) {
var th = this.handlers, h, old, t; var th = this.handlers, h = th[eventName], i;
if (replaceOldHandler || !th.hasOwnProperty(eventName)) { if (th.hasOwnProperty(eventName)) {
th[eventName] = eventHandler; if (asc_typeOf(h) !== "array" || asc_typeOf(eventHandler) !== "function") {
} else { delete th[eventName];
old = h = th[eventName]; return true;
t = asc_typeOf(old);
if (t !== "array") {
h = th[eventName] = [];
if (t === "function") {h.push(old);}
}
h.push(eventHandler);
} }
}, for (i = h.length - 1; i >= 0; i -= 1) {
if (h[i] === eventHandler) {
remove: function (eventName, eventHandler) { delete h[i];
var th = this.handlers, h = th[eventName], i;
if (th.hasOwnProperty(eventName)) {
if (asc_typeOf(h) !== "array" || asc_typeOf(eventHandler) !== "function") {
delete th[eventName];
return true; return true;
} }
for (i = h.length - 1; i >= 0; i -= 1) {
if (h[i] === eventHandler) {
delete h[i];
return true;
}
}
} }
return false;
} }
return false;
}; };
/* /*
* Export * Export
* ----------------------------------------------------------------------------- * -----------------------------------------------------------------------------
*/ */
var prot; asc.asc_CHandlersList = asc_CHandlersList;
window["Asc"]["asc_CHandlersList"] = window["Asc"].asc_CHandlersList = asc_CHandlersList;
prot = asc_CHandlersList.prototype;
prot["trigger"] = prot.trigger = prot.trigger;
prot["add"] = prot.add = prot.add;
prot["remove"] = prot.remove = prot.remove;
} }
)(jQuery, window); )(jQuery, window);
\ No newline at end of file
...@@ -1988,13 +1988,10 @@ ...@@ -1988,13 +1988,10 @@
if (!this.maxDigitWidth) {throw "Error: can't measure text string";} if (!this.maxDigitWidth) {throw "Error: can't measure text string";}
}; };
/* /*
* Export * Export
* ----------------------------------------------------------------------------- * -----------------------------------------------------------------------------
*/ */
window["Asc"].WorkbookView = WorkbookView; window["Asc"].WorkbookView = WorkbookView;
} }
)(jQuery, window); )(jQuery, window);
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