Commit facaeba5 authored by Alexey.Musinov's avatar Alexey.Musinov Committed by Alexander.Trofimov

[ios] таблицы

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@62374 954022d7-b5bf-4e40-9824-e11837661b57
parent c14b9755
"use strict";
/* DrawingContext.js
*
* Author: Dmitry.Sokolov@avsmedia.net
* Date: Nov 21, 2011
*/
(function (/** jQuery */$, /** Window */window, undefined) {
/*
* Import
* -----------------------------------------------------------------------------
*/
var asc = window["Asc"];
var asc_round = asc.round;
var asc_floor = asc.floor;
function colorObjToAscColor(color) {
var oRes = null;
var r = color.getR();
var g = color.getG();
var b = color.getB();
var bTheme = false;
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 cur = oThemeColorTint[i];
//0.005 установлено экспериментально
if(Math.abs(cur - tintExcel) < 0.005)
{
bTheme = true;
tintPresentation = i;
break;
}
}
}
if(bTheme)
{
oRes = new asc_CColor();
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){
return deg * Math.PI / 180.0;
}
function rad2deg(rad){
return rad * 180.0 / Math.PI;
}
/** @const */
var MATRIX_ORDER_PREPEND = 0,
MATRIX_ORDER_APPEND = 1;
/**
* @constructor
*/
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.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;
};
Matrix.prototype.assign = function (sx, shx, shy, sy, tx, ty) {
this.sx = sx;
this.shx = shx;
this.shy = shy;
this.sy = sy;
this.tx = tx;
this.ty = ty;
};
Matrix.prototype.copyFrom = function (matrix) {
this.sx = matrix.sx;
this.shx = matrix.shx;
this.shy = matrix.shy;
this.sy = matrix.sy;
this.tx = matrix.tx;
this.ty = matrix.ty;
};
Matrix.prototype.clone = function () {
var m = new Matrix();
m.copyFrom(this);
return m;
};
Matrix.prototype.multiply = function (matrix, order) {
if (MATRIX_ORDER_PREPEND === order) {
var m = matrix.clone();
m.multiply(this, MATRIX_ORDER_APPEND);
this.copyFrom(m);
} 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;
}
};
Matrix.prototype.translate = function (x, y, order) {
var m = new Matrix();
m.tx = x;
m.ty = y;
this.multiply(m, order);
};
Matrix.prototype.scale = function (x, y, order) {
var m = new Matrix();
m.sx = x;
m.sy = y;
this.multiply(m, order);
};
Matrix.prototype.rotate = function (a, order) {
var m = new Matrix();
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);
};
Matrix.prototype.rotateAt = function (a, x, y, order) {
this.translate(-x, -y, order);
this.rotate(a, order);
this.translate(x, y, order);
};
Matrix.prototype.determinant = function () {
return this.sx * this.sy - this.shy * this.shx;
};
Matrix.prototype.invert = function () {
var det = this.determinant();
if (0.0001 > 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;
};
Matrix.prototype.transformPointX = function (x, y) {
return x * this.sx + y * this.shx + this.tx;
};
Matrix.prototype.transformPointY = function (x, y) {
return x * this.shy + y * this.sy + this.ty;
};
/** Calculates rotation angle */
Matrix.prototype.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);
};
/**
* 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) {
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;
}
/**
* Assigns font preperties from another object
* @param {FontProperties} font
*/
FontProperties.prototype.copyFrom = function (font) {
this.FontFamily.Name = font.FontFamily.Name;
this.FontFamily.Index = font.FontFamily.Index;
this.FontSize = font.FontSize;
this.Bold = font.Bold;
this.Italic = font.Italic;
this.Underline = font.Underline;
this.Strikeout = font.Strikeout;
};
/** @return {FontProperties} */
FontProperties.prototype.clone = function () {
return new FontProperties(this.FontFamily.Name, this.FontSize,
this.Bold, this.Italic, this.Underline, this.Strikeout);
};
FontProperties.prototype.isEqual = function (font) {
return font !== undefined &&
this.FontFamily.Name.toLowerCase() === font.FontFamily.Name.toLowerCase() &&
this.FontSize === font.FontSize &&
this.Bold === font.Bold &&
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 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;
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) {
this.canvas = null;
this.ctx = null;
// JS TO BRIDGE
this.nctx = window["native"];
this.napi_fmt = [{},{},{},{}];
this.deviceDPI = this.nctx["GetDeviceDPI"]();
this.deviceScale = this.nctx["GetDeviceScale"]();
this.setCanvas(settings.canvas);
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);
if (AscBrowser.isRetina) {
this.ppiX <<= 1;
this.ppiY <<= 1;
}
this.ppiX = parseInt(this.ppiX * this.deviceScale, 10);
this.ppiY = parseInt(this.ppiY * this.deviceScale, 10);
ppiTest.remove();
this._mct = new Matrix(); // units transform
this._mt = new Matrix(); // user transform
this._mbt = new Matrix(); // bound transform
this._mft = new Matrix(); // full transform
this._mift = new Matrix(); // inverted full transform
this._im = new Matrix();
this.scaleFactor = 1;
this.units = 3/*mm*/;
this.changeUnits(undefined !== settings.units ? settings.units : this.units);
this.fmgrGraphics = undefined !== settings.fmgrGraphics ? settings.fmgrGraphics : null;
if (null === this.fmgrGraphics) {
throw "Can not set graphics in DrawingContext";
}
/** @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";
}
// CColor
this.fillColor = new CColor(255, 255, 255);
return this;
}
/**
* Returns width of drawing context in current units
* @param {Number} [units] Единицы измерения (0=px, 1=pt, 2=in, 3=mm) в которых будет возвращена ширина
* @return {Number}
*/
DrawingContext.prototype.getWidth = function (units) {
var i = units >= 0 && units <=3 ? units : this.units;
return this.canvas.width * getCvtRatio(0/*px*/, i, this.ppiX);
};
/**
* Returns height of drawing context in current units
* @param {Number} [units] Единицы измерения (0=px, 1=pt, 2=in, 3=mm) в которых будет возвращена высота
* @return {Number}
*/
DrawingContext.prototype.getHeight = function (units) {
var i = units >= 0 && units <=3 ? units : this.units;
return this.canvas.height * getCvtRatio(0/*px*/, i, this.ppiY);
};
/**
* Returns canvas element
* @type {Element}
*/
DrawingContext.prototype.getCanvas = function () {
return this.canvas;
};
/**
*
* @param canvas
*/
DrawingContext.prototype.setCanvas = function (canvas) { // NOT USE
if (null == canvas) {return;}
this.canvas = canvas;
this.ctx = this.canvas.getContext("2d");
//this.initContextSmoothing();
};
/**
* Returns pixels per inch ratio
* @type {Number}
*/
DrawingContext.prototype.getPPIX = function () {
return this.ppiX;
};
/**
* Returns pixels per inch ratio
* @type {Number}
*/
DrawingContext.prototype.getPPIY = function () {
return this.ppiY;
};
/**
* Returns currrent units (0=px, 1=pt, 2=in, 3=mm)
* @type {Number}
*/
DrawingContext.prototype.getUnits = function () {
return this.units;
};
DrawingContext.prototype.moveImageDataSafari = function (sx, sy, w, h, x, y) {
var sr = this._calcRect(sx, sy, w, h);
var r = this._calcRect(x, y);
var imgData = this.ctx.getImageData(sr.x, sr.y, sr.w, sr.h);
var minX, maxX, minY, maxY;
if (sx < x) {
minX = sr.x;
maxX = r.x;
} else {
minX = r.x;
maxX = sr.x;
}
if (sy < y) {
minY = sr.y;
maxY = r.y;
} else {
minY = r.y;
maxY = sr.y;
}
this.ctx.clearRect(minX, minY, maxX + sr.w, maxY + sr.h);
this.ctx.putImageData(imgData, r.x, r.y);
return this;
};
DrawingContext.prototype.moveImageData = function (sx, sy, w, h, x, y) {
var sr = this._calcRect(sx, sy, w, h);
var r = this._calcRect(x, y);
this.ctx.save();
this.ctx.globalCompositeOperation = 'copy';
this.ctx.beginPath();
this.ctx.rect(r.x, r.y, sr.w, sr.h);
this.ctx.clip();
this.ctx.drawImage(this.getCanvas(), sr.x, sr.y, sr.w, sr.h, r.x, r.y, sr.w, sr.h);
this.ctx.restore();
this.ctx.beginPath();
return this;
};
/**
* Changes units of drawing context
* @param {Number} units New units of drawing context (0=px, 1=pt, 2=in, 3=mm)
*/
DrawingContext.prototype.changeUnits = function (units) {
var i = units >= 0 && units <=3 ? units : 0;
this._mct.sx = getCvtRatio(i, 0/*px*/, this.ppiX);
this._mct.sy = getCvtRatio(i, 0/*px*/, this.ppiY);
this._calcMFT();
this.units = units;
return this;
};
/**
* Returns currrent zoom ratio
* @type {Number}
*/
DrawingContext.prototype.getZoom = function () {
return this.scaleFactor;
};
/**
* Changes scale factor of drawing context by changing its PPI
* @param {Number} factor
*/
DrawingContext.prototype.changeZoom = function (factor) {
if (factor <= 0) {throw "Scale factor must be >= 0";}
factor = asc_round(factor * 1000) / 1000;
this.ppiX = asc_round(this.ppiX / this.scaleFactor * factor * 1000) / 1000;
this.ppiY = asc_round(this.ppiY / this.scaleFactor * factor * 1000) / 1000;
this.scaleFactor = factor;
// reinitialize
this.changeUnits(this.units);
this.setFont(this.font);
return this;
};
/**
* Resets dimensions of drawing context (canvas 'width' and 'height' attributes)
* @param {Number} width New width in current units
* @param {Number} height New height in current units
*/
DrawingContext.prototype.resetSize = function (width, height) {
var w = asc_round( width * getCvtRatio(this.units, 0/*px*/, this.ppiX) ),
h = asc_round( height * getCvtRatio(this.units, 0/*px*/, this.ppiY) );
if (w !== this.canvas.width) {
this.canvas.width = w;
}
if (h !== this.canvas.height) {
this.canvas.height = h;
}
return this;
};
/**
* Expands dimensions of drawing context (canvas 'width' and 'height' attributes)
* @param {Number} width New width in current units
* @param {Number} height New height in current units
*/
DrawingContext.prototype.expand = function (width, height) {
var w = asc_round( width * getCvtRatio(this.units, 0/*px*/, this.ppiX) ),
h = asc_round( height * getCvtRatio(this.units, 0/*px*/, this.ppiY) );
if (w > this.canvas.width) {
this.canvas.width = w;
}
if (h > this.canvas.height) {
this.canvas.height = h;
}
return this;
};
/**
* Delete smoothing
*/
/*DrawingContext.prototype.initContextSmoothing = function () {
var ctx = this.ctx;
if (!AscBrowser.isMobileVersion || null === ctx)
return;
// Не убирать. Баг на android при scroll!!!
if (ctx.imageSmoothingEnabled)
ctx.imageSmoothingEnabled = false;
if (ctx.mozImageSmoothingEnabled)
ctx.mozImageSmoothingEnabled = false;
if (ctx.oImageSmoothingEnabled)
ctx.oImageSmoothingEnabled = false;
if (ctx.webkitImageSmoothingEnabled)
ctx.webkitImageSmoothingEnabled = false;
};*/
// Canvas methods
DrawingContext.prototype.clear = function () {
this.clearRect(0, 0, this.getWidth(), this.getHeight());
return this;
};
DrawingContext.prototype.save = function () {
this.nctx["PD_Save"]();
return this;
};
DrawingContext.prototype.restore = function () {
this.nctx["PD_Restore"]();
return this;
};
DrawingContext.prototype.scale = function (kx, ky) {
//TODO: implement scale()
return this;
};
DrawingContext.prototype.rotate = function (a) {
//TODO: implement rotate()
return this;
};
DrawingContext.prototype.translate = function (dx, dy) {
//TODO: implement translate()
return this;
};
DrawingContext.prototype.transform = function (sx, shy, shx, sy, tx, ty) {
//TODO: implement transform()
return this;
};
DrawingContext.prototype.setTransform = function(sx, shy, shx, sy, tx, ty) {
this._mbt.assign(sx, shx, shy, sy, tx, ty);
return this;
};
DrawingContext.prototype.setTextTransform = function(sx, shy, shx, sy, tx, ty) {
this._mt.assign(sx, shx, shy, sy, tx, ty);
return this;
};
DrawingContext.prototype.updateTransforms = function() {
this._calcMFT();
this.fmgrGraphics[1].SetTextMatrix(
this._mt.sx, this._mt.shy, this._mt.shx, this._mt.sy, this._mt.tx, this._mt.ty);
};
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.setTextTransform(this._im.sx, this._im.shy, this._im.shx, this._im.sy, this._im.tx, this._im.ty);
this._calcMFT();
};
// Style methods
DrawingContext.prototype.getFillStyle = function () {
return this.ctx.fillStyle;
};
DrawingContext.prototype.getStrokeStyle = function () {
return this.ctx.strokeStyle;
};
DrawingContext.prototype.getLineWidth = function () {
return this.ctx.lineWidth;
};
DrawingContext.prototype.getLineCap = function () {
return this.ctx.lineCap;
};
DrawingContext.prototype.getLineJoin = function () {
return this.ctx.lineJoin;
};
/**
* @param {RgbColor || ThemeColor || CColor} val
* @returns {DrawingContext}
*/
DrawingContext.prototype.setFillStyle = function (val) {
var _r = val.getR();
var _g = val.getG();
var _b = val.getB();
var _a = val.getA();
//this.fillColor = new CColor(_r, _g, _b, _a);
//this.ctx.fillStyle = "rgba(" + _r + "," + _g + "," + _b + "," + _a + ")";
this.nctx["PD_b_color1"](_r,_g,_b,_a * 255);
return this;
};
DrawingContext.prototype.setFillPattern = function (val) {
this.ctx.fillStyle = val;
return this;
};
/**
* @param {RgbColor || ThemeColor || CColor} val
* @returns {DrawingContext}
*/
DrawingContext.prototype.setStrokeStyle = function (val) {
var _r = val.getR();
var _g = val.getG();
var _b = val.getB();
var _a = val.getA();
this.nctx["PD_p_color"](_r,_g,_b,_a * 255);
return this;
};
DrawingContext.prototype.setLineWidth = function (width) {
this.nctx["PD_p_width"](width);
return this;
};
DrawingContext.prototype.setLineCap = function (cap) {
this.ctx.lineCap = cap;
return this;
};
DrawingContext.prototype.setLineJoin = function (join) {
this.ctx.lineJoin = join;
return this;
};
DrawingContext.prototype.fillRect = function (x, y, w, h) {
var r = this._calcRect(x, y, w, h);
this.nctx["PD_rect"](r.x, r.y, r.w, r.h);
this.nctx["PD_Fill"]();
return this;
};
DrawingContext.prototype.strokeRect = function (x, y, w, h) {
var isEven = 0 !== this.ctx.lineWidth % 2 ? 0.5 : 0;
var r = this._calcRect(x, y, w, h);
this.nctx["PD_rect"](r.x + isEven, r.y + isEven, r.w, r.h);
this.nctx["PD_Stroke"]();
return this;
};
DrawingContext.prototype.clearRect = function (x, y, w, h) {
var r = this._calcRect(x, y, w, h);
this.ctx.clearRect(r.x, r.y, r.w, r.h);
return this;
};
DrawingContext.prototype.clearRectByX = function (x, y, w, h) {
var r = this._calcRect(x, y, w, h);
this.ctx.clearRect(r.x - 1, r.y, r.w + 1, r.h);
};
DrawingContext.prototype.clearRectByY = function (x, y, w, h) {
var r = this._calcRect(x, y, w, h);
this.ctx.clearRect(r.x, r.y - 1, r.w, r.h + 1);
};
// Font and text methods
DrawingContext.prototype.getFont = function () {
return this.font.clone();
};
DrawingContext.prototype.getFontFamily = function () {
return this.font.FontFamily.Name;
};
DrawingContext.prototype.getFontSize = function () {
return this.font.FontSize;
};
/**
* @param {Number} [units] Units of result (0=px, 1=pt, 2=in, 3=mm)
* @return {FontMetrics}
*/
DrawingContext.prototype.getFontMetrics = function (units) {
var fm = this.napi_fmt[3];//this.fmgrGraphics[3];
var d = Math.abs(fm.m_lDescender);
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 res = new FontMetrics();
res.ascender = factor * fm.m_lAscender;
res.descender = factor * d;
res.lineGap = factor * (fm.m_lLineHeight - fm.m_lAscender - d);
//var face = fm.m_pFont.m_pFace;
res.nat_scale = 2048;//face.header.Units_Per_EM;
res.nat_y1 = 2000;
res.nat_y2 = -500;
// if (face.os2) {
// res.nat_y1 = face.os2.usWinAscent;
// res.nat_y2 = -face.os2.usWinDescent;
// } else {
// res.nat_y1 = face.header.yMax;
// res.nat_y2 = face.header.yMin;
// }
return res;
};
/**
*
* @param font
* @param [angle]
* @returns {DrawingContext}
*/
DrawingContext.prototype.setFont = function (font, angle) {
var italic, bold, fontStyle, r;
this.font.copyFrom(font);
// sample: 132 (ipad) * device_scale(is_retina=2) / 96 (default) * 2.54
this.font.FontSize = this.font.FontSize * this.deviceDPI * this.deviceScale / this.ppiX * 2.54;
italic = true === font.Italic;
bold = true === font.Bold;
fontStyle = FontStyle.FontStyleRegular;
if ( !italic && bold )
fontStyle = FontStyle.FontStyleBold;
else if ( italic && !bold )
fontStyle = FontStyle.FontStyleItalic;
else if ( italic && bold )
fontStyle = FontStyle.FontStyleBoldItalic;
var _fontinfo, _info, flag, napi_fontInfo;
if (angle && 0 != angle) {
//r = g_fontApplication.LoadFont(font.FontFamily.Name, window.g_font_loader, this.fmgrGraphics[1], font.FontSize, fontStyle, this.ppiX, this.ppiY);
//===================================================================
_fontinfo = g_fontApplication.GetFontInfo(this.font.FontFamily.Name, fontStyle, this.LastFontOriginInfo);
_info = GetLoadInfoForMeasurer(_fontinfo, fontStyle);
flag = 0;
if (_info.NeedBold) flag |= 0x01;
if (_info.NeedItalic) flag |= 0x02;
if (_info.SrcBold) flag |= 0x04;
if (_info.SrcItalic) flag |= 0x08;
napi_fontInfo = g_oTextMeasurer.Measurer["LoadFont"](_info.Path, _info.FaceIndex, this.font.FontSize, flag);
this.napi_fmt[1].m_lUnits_Per_Em = napi_fontInfo[3];
this.napi_fmt[1].m_lAscender = napi_fontInfo[0];
this.napi_fmt[1].m_lDescender = napi_fontInfo[2];
this.napi_fmt[1].m_lLineHeight = napi_fontInfo[2];
r = true;
//===================================================================
this.fmgrGraphics[1].SetTextMatrix(
this._mt.sx, this._mt.shy, this._mt.shx, this._mt.sy, this._mt.tx, this._mt.ty);
} else {
// r = g_fontApplication.LoadFont(font.FontFamily.Name, window.g_font_loader, this.fmgrGraphics[0], font.FontSize, fontStyle, this.ppiX, this.ppiY);
// g_fontApplication.LoadFont(font.FontFamily.Name, window.g_font_loader, this.fmgrGraphics[3], font.FontSize, fontStyle, this.ppiX, this.ppiY);
//===================================================================
_fontinfo = g_fontApplication.GetFontInfo(this.font.FontFamily.Name, fontStyle, this.LastFontOriginInfo);
_info = GetLoadInfoForMeasurer(_fontinfo, fontStyle);
flag = 0;
if (_info.NeedBold) flag |= 0x01;
if (_info.NeedItalic) flag |= 0x02;
if (_info.SrcBold) flag |= 0x04;
if (_info.SrcItalic) flag |= 0x08;
napi_fontInfo = g_oTextMeasurer.Measurer["LoadFont"](_info.Path, _info.FaceIndex, this.font.FontSize, flag);
this.nctx["PD_LoadFont"](_info.Path, _info.FaceIndex, this.font.FontSize, flag);
var dKoef = g_dKoef_pt_to_mm * font.FontSize / napi_fontInfo[3];
this.napi_fmt[0].m_lUnits_Per_Em = napi_fontInfo[3];
this.napi_fmt[0].m_lAscender = napi_fontInfo[0];// * dKoef;
this.napi_fmt[0].m_lDescender = napi_fontInfo[2];// * dKoef;
this.napi_fmt[0].m_lLineHeight = napi_fontInfo[2];// * dKoef;
this.napi_fmt[3].m_lUnits_Per_Em = napi_fontInfo[3];
this.napi_fmt[3].m_lAscender = napi_fontInfo[0];// * dKoef;
this.napi_fmt[3].m_lDescender = napi_fontInfo[2];// * dKoef;
this.napi_fmt[3].m_lLineHeight = napi_fontInfo[2];// * dKoef;
r = true;
//===================================================================
}
if (r === false) {
throw "Can not use " + font.FontFamily.Name + " font. (Check whether font file is loaded)";
}
return this;
};
/**
* Returns dimensions of first char of string
* @param {String} text Character to measure
* @param {Number} units Units (0 = px, 1 = pt, 2 = in, 3 = mm)
* @return {TextMetrics} Returns the char dimension
*/
DrawingContext.prototype.measureChar = function (text, units) {
return this.measureText(text.charAt(0), units);
};
/**
* Returns dimensions of string
* @param {String} text String to measure
* @param {Number} units Units (0 = px, 1 = pt, 2 = in, 3 = mm)
* @return {TextMetrics} Returns the dimension of string {width: w, height: h}
*/
DrawingContext.prototype.measureText = function (text, units) {
var fm = this.napi_fmt[3], //this.fmgrGraphics[3],
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) {
//tmp = fm.MeasureChar(text.charCodeAt(i));
var bounds = g_oTextMeasurer.Measurer["GetDrawingBox"](text.charCodeAt(i));
tmp = {
fAdvanceX: bounds[0],
oBBox: {
fMinX: bounds[1],
fMaxX: bounds[2],
fMinY: bounds[3],
fMaxY: bounds[4]
}
};
w += asc_round(tmp.fAdvanceX);
}
w2 = w - tmp.fAdvanceX + tmp.oBBox.fMaxX - tmp.oBBox.fMinX + 1;
return this._calcTextMetrics(w * r, w2 * r, fm, r);
};
DrawingContext.prototype.fillGlyph = function (pGlyph, fmgr) {
var nW = pGlyph.oBitmap.nWidth;
var nH = pGlyph.oBitmap.nHeight;
if ( !(nW > 0 && nH > 0) ) {return;}
var nX = asc_floor(fmgr.m_oGlyphString.m_fX + pGlyph.fX + pGlyph.oBitmap.nX);
var nY = asc_floor(fmgr.m_oGlyphString.m_fY + pGlyph.fY - pGlyph.oBitmap.nY);
var _r = this.fillColor.r;
var _g = this.fillColor.g;
var _b = this.fillColor.b;
if (AscBrowser.isMobileVersion) {
// Special for iPad (5.1)
if (!_r && !_g && !_b) {
this.ctx.drawImage(pGlyph.oBitmap.oGlyphData.m_oCanvas, 0, 0, nW, nH, nX, nY, nW, nH);
} else {
var canvD = $("<canvas width='"+nW+"' height='"+nH+"'/>")[0];
var ctxD = canvD.getContext("2d");
var pixDst = ctxD.getImageData(0, 0, nW, nH);
var dstP = pixDst.data;
var data = pGlyph.oBitmap.oGlyphData.m_oContext.getImageData(0, 0, nW, nH);
var dataPx = data.data;
var cur = 0;
var cnt = 4 * nW * nH;
for (var i = 3; i < cnt; i += 4) {
dstP[cur++] = _r;
dstP[cur++] = _g;
dstP[cur++] = _b;
dstP[cur++] = dataPx[i];
}
ctxD.putImageData(pixDst, 0, 0, 0, 0, nW, nH);
this.ctx.drawImage(canvD, 0, 0, nW, nH, nX, nY, nW, nH);
}
} else {
pGlyph.oBitmap.oGlyphData.checkColor(_r, _g, _b, nW, nH);
pGlyph.oBitmap.draw(this.ctx, nX, nY);
}
};
DrawingContext.prototype.fillText = function (text, x, y, maxWidth, charWidths, angle) {
//var manager = angle ? this.fmgrGraphics[1] : this.fmgrGraphics[0];
var _x = this._mift.transformPointX(x, y);
var _y = this._mift.transformPointY(x, y);
var length = text.length, lUnicode;
for (var i = 0; i < length; ++i) {
lUnicode = text.charCodeAt(i);
//TODO: cache
// if (null != this.LastFontOriginInfo.Replace)
// lUnicode = g_fontApplication.GetReplaceGlyph(lUnicode, this.LastFontOriginInfo.Replace);
this.nctx["PD_FillText"](_x, _y, lUnicode);
_x += asc_round(g_oTextMeasurer.Measurer["MeasureChar"](lUnicode));
}
return this;
};
// Path methods
DrawingContext.prototype.beginPath = function () {
this.nctx["PD_PathStart"]();
return this;
};
DrawingContext.prototype.closePath = function () {
this.nctx["PD_PathClose"]();
return this;
};
DrawingContext.prototype.moveTo = function (x, y) {
var r = this._calcRect(x, y);
this.nctx["PD_PathMoveTo"](r.x, r.y);
return this;
};
DrawingContext.prototype.lineTo = function (x, y) {
var r = this._calcRect(x, y);
this.nctx["PD_PathLineTo"](r.x, r.y);
return this;
};
DrawingContext.prototype.lineDiag = function (x1, y1, x2, y2) {
var isEven = 0 !== this.ctx.lineWidth % 2 ? 0.5 : 0;
var r1 = this._calcRect(x1, y1);
var r2 = this._calcRect(x2, y2);
this.nctx["PD_PathMoveTo"](r1.x + isEven, r1.y + isEven);
this.nctx["PD_PathLineTo"](r2.x + isEven, r2.y + isEven);
return this;
};
DrawingContext.prototype.lineHor = function (x1, y, x2) {
var isEven = 0 !== this.ctx.lineWidth % 2 ? 0.5 : 0;
var r1 = this._calcRect(x1, y);
var r2 = this._calcRect(x2, y);
this.nctx["PD_PathMoveTo"](r1.x, r1.y + isEven);
this.nctx["PD_PathLineTo"](r2.x, r2.y + isEven);
return this;
};
DrawingContext.prototype.lineVer = function (x, y1, y2) {
var isEven = 0 !== this.ctx.lineWidth % 2 ? 0.5 : 0;
var r1 = this._calcRect(x, y1);
var r2 = this._calcRect(x, y2);
this.nctx["PD_PathMoveTo"](r1.x + isEven, r1.y);
this.nctx["PD_PathLineTo"](r2.x + isEven, r2.y);
return this;
};
// Отрисовка на 1px меньше
DrawingContext.prototype.lineHorPrevPx = function (x1, y, x2) {
var isEven = (0 !== this.ctx.lineWidth % 2 ? 0.5 : 0) - 1;
var r1 = this._calcRect(x1, y);
var r2 = this._calcRect(x2, y);
this.nctx["PD_PathMoveTo"](r1.x, r1.y + isEven);
this.nctx["PD_PathLineTo"](r2.x, r2.y + isEven);
return this;
};
DrawingContext.prototype.lineVerPrevPx = function (x, y1, y2) {
var isEven = (0 !== this.ctx.lineWidth % 2 ? 0.5 : 0) - 1;
var r1 = this._calcRect(x, y1);
var r2 = this._calcRect(x, y2);
this.nctx["PD_PathMoveTo"](r1.x + isEven, r1.y);
this.nctx["PD_PathLineTo"](r2.x + isEven, r2.y);
return this;
};
DrawingContext.prototype.dashLineCleverHor = function (x1, y, x2) {
var w_dot = c_oAscCoAuthoringDottedWidth, w_dist = c_oAscCoAuthoringDottedDistance;
var _x1 = this._mct.transformPointX(x1, y);
var _y = this._mct.transformPointY(x1, y) - 1;
var _x2 = this._mct.transformPointX(x2, y);
var ctx = this.ctx;
_x1 = (_x1 >> 0) + 0.5;
_y = (_y >> 0) + 0.5;
_x2 = (_x2 >> 0) + 0.5;
for (; _x1 < _x2; _x1 += w_dist) {
this.nctx["PD_PathMoveTo"](_x1, _y);
_x1 += w_dot;
if (_x1 > _x2)
_x1 = _x2;
this.nctx["PD_PathLineTo"](_x1, _y);
}
};
DrawingContext.prototype.dashLineCleverVer = function (x, y1, y2) {
var w_dot = c_oAscCoAuthoringDottedWidth, w_dist = c_oAscCoAuthoringDottedDistance;
var _y1 = this._mct.transformPointY(x, y1);
var _x = this._mct.transformPointX(x, y1) - 1;
var _y2 = this._mct.transformPointY(x, y2);
var ctx = this.ctx;
_y1 = (_y1 >> 0) + 0.5;
_x = (_x >> 0) + 0.5;
_y2 = (_y2 >> 0) + 0.5;
for (; _y1 < _y2; _y1 += w_dist) {
this.nctx["PD_PathMoveTo"](_x, _y1);
_y1 += w_dot;
if (_y1 > _y2)
_y1 = _y2;
this.nctx["PD_PathLineTo"](_x, _y1);
}
};
DrawingContext.prototype.dashLine = function (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);
var i, j;
if (x1 <= x2 && y1 <= y2) {
for (i = x1, j = y1; i < x2 || j < y2; i += len_x2, j += len_y2) {
this.nctx["PD_PathMoveTo"](i, j);
i += len_x1;
j += len_y1;
if (i > x2)
i = x2;
if (j > y2)
j = y2;
this.nctx["PD_PathLineTo"](i, j);
}
} else if (x1 <= x2 && y1 > y2) {
for (i = x1, j = y1; i < x2 || j > y2; i += len_x2, j -= len_y2) {
this.nctx["PD_PathMoveTo"](i, j);
i += len_x1;
j -= len_y1;
if (i > x2)
i = x2;
if (j < y2)
j = y2;
this.nctx["PD_PathLineTo"](i, j);
}
} else if (x1 > x2 && y1 <= y2) {
for (i = x1, j = y1; i > x2 || j < y2; i -= len_x2, j += len_y2) {
this.nctx["PD_PathMoveTo"](i, j);
i -= len_x1;
j += len_y1;
if (i < x2)
i = x2;
if (j > y2)
j = y2;
this.nctx["PD_PathLineTo"](i, j);
}
} else {
for (i = x1, j = y1; i > x2 || j > y2; i -= len_x2, j -= len_y2) {
this.nctx["PD_PathMoveTo"](i, j);
i -= len_x1;
j -= len_y1;
if (i < x2)
i = x2;
if (j < y2)
j = y2;
this.nctx["PD_PathLineTo"](i, j);
}
}
};
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(x2, y2, x4, y4, w_dot, w_dist);
this.dashLine(x4, y4, x3, y3, w_dot, w_dist);
this.dashLine(x3, y3, x1, y1, w_dot, w_dist);
};
DrawingContext.prototype.rect = function (x, y, w, h) {
var r = this._calcRect(x, y, w, h);
this.nctx["PD_rect"](r.x, r.y, r.w, r.h);
return this;
};
DrawingContext.prototype.arc = function (x, y, radius, startAngle, endAngle, antiClockwise, dx, dy) {
var r = this._calcRect(x, y);
dx = typeof dx !== "undefined" ? dx : 0;
dy = typeof dy !== "undefined" ? dy : 0;
this.ctx.arc(r.x + dx, r.y + dy, radius, startAngle, endAngle, antiClockwise);
return this;
};
DrawingContext.prototype.bezierCurveTo = function (x1, y1, x2, y2, x3, y3) {
var p1 = this._calcRect(x1, y1),
p2 = this._calcRect(x2, y2),
p3 = this._calcRect(x3, y3);
this.nctx["PD_PathCurveTo"](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;
};
DrawingContext.prototype.fill = function () {
this.nctx["PD_Fill"]();
return this;
};
DrawingContext.prototype.stroke = function () {
this.nctx["PD_Stroke"]();
return this;
};
DrawingContext.prototype.clip = function () {
this.nctx["PD_clip"]();
return this;
};
// Image methods
DrawingContext.prototype.drawImage = function (img, sx, sy, sw, sh, dx, dy, dw, dh) {
var sr = this._calcRect(sx, sy, sw, sh),
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);
return this;
};
// Private methods
DrawingContext.prototype._calcRect = function (x, y, w, h) {
var wh = w !== undefined && h !== undefined,
x2 = x + w,
y2 = y + h,
_x = this._mft.transformPointX(x, y),
_y = this._mft.transformPointY(x, y);
return {
x: asc_round(_x),
y: asc_round(_y),
w: wh ? asc_round(this._mft.transformPointX(x2, y2) - _x) : undefined,
h: wh ? asc_round(this._mft.transformPointY(x2, y2) - _y) : undefined
};
};
DrawingContext.prototype._calcMFT = function () {
this._mft = this._mct.clone();
this._mft.multiply(this._mbt, MATRIX_ORDER_PREPEND);
this._mft.multiply(this._mt, MATRIX_ORDER_PREPEND);
this._mift = this._mt.clone();
this._mift.invert();
this._mift.multiply(this._mft, MATRIX_ORDER_PREPEND);
};
/**
* @param {Number} w Ширина текста
* @param {Number} wBB Ширина Bound Box текста
* @param {CFontManager} fm Объект CFontManager для получения метрик шрифта
* @param {Number} r Коэффициент перевода pt -> в текущие единицы измерения (this.units)
* @return {TextMetrics}
*/
DrawingContext.prototype._calcTextMetrics = function (w, wBB, fm, r) {
var factor = this.getFontSize() * r / fm.m_lUnits_Per_Em,
l = fm.m_lLineHeight * factor,
b = fm.m_lAscender * factor,
d = Math.abs(fm.m_lDescender * factor);
return new TextMetrics(w, b + d, l, b, d, this.font.FontSize, 0, wBB);
};
/*
* Export
* -----------------------------------------------------------------------------
*/
window["Asc"].getCvtRatio = getCvtRatio;
window["Asc"].calcNearestPt = calcNearestPt;
window["Asc"].colorObjToAscColor = colorObjToAscColor;
window["Asc"].FontProperties = FontProperties;
window["Asc"].TextMetrics = TextMetrics;
window["Asc"].FontMetrics = FontMetrics;
window["Asc"].DrawingContext = DrawingContext;
window["Asc"].Matrix = Matrix;
})(jQuery, window);
This source diff could not be displayed because it is too large. You can view the blob instead.
/**
* native.js
*
* Created by Alexey Musinov on 14 April 2015
* Copyright (c) 2015 Ascensio System SIA. All rights reserved.
*
*/
var editor = undefined;
var window = {};
var navigator = {};
navigator.userAgent = "chrome";
window.navigator = navigator;
window.location = {};
window.location.protocol = "";
window.location.host = "";
window.location.href = "";
window.NATIVE_EDITOR_ENJINE = true;
window.NATIVE_EDITOR_ENJINE_SYNC_RECALC = true;
var document = {};
window.document = document;
function ConvertJSC_Array(_array)
{
var _len = _array.length;
var ret = new Uint8Array(_len);
for (var i = 0; i < _len; i++)
ret[i] = _array.getAt(i);
return ret;
}
function Image()
{
this.src = "";
this.onload = function()
{
}
this.onerror = function()
{
}
}
function _image_data()
{
this.data = null;
this.length = 0;
}
function native_pattern_fill()
{
}
native_pattern_fill.prototype =
{
setTransform : function(transform) {}
};
function native_gradient_fill()
{
}
native_gradient_fill.prototype =
{
addColorStop : function(offset,color) {}
};
function native_context2d(parent)
{
this.canvas = parent;
this.globalAlpha = 0;
this.globalCompositeOperation = "";
this.fillStyle = "";
this.strokeStyle = "";
this.lineWidth = 0;
this.lineCap = 0;
this.lineJoin = 0;
this.miterLimit = 0;
this.shadowOffsetX = 0;
this.shadowOffsetY = 0;
this.shadowBlur = 0;
this.shadowColor = 0;
this.font = "";
this.textAlign = 0;
this.textBaseline = 0;
}
native_context2d.prototype =
{
save : function() {},
restore : function() {},
scale : function(x,y) {},
rotate : function(angle) {},
translate : function(x,y) {},
transform : function(m11,m12,m21,m22,dx,dy) {},
setTransform : function(m11,m12,m21,m22,dx,dy) {},
createLinearGradient : function(x0,y0,x1,y1) { return new native_gradient_fill(); },
createRadialGradient : function(x0,y0,r0,x1,y1,r1) { return null; },
createPattern : function(image,repetition) { return new native_pattern_fill(); },
clearRect : function(x,y,w,h) {},
fillRect : function(x,y,w,h) {},
strokeRect : function(x,y,w,h) {},
beginPath : function() {},
closePath : function() {},
moveTo : function(x,y) {},
lineTo : function(x,y) {},
quadraticCurveTo : function(cpx,cpy,x,y) {},
bezierCurveTo : function(cp1x,cp1y,cp2x,cp2y,x,y) {},
arcTo : function(x1,y1,x2,y2,radius) {},
rect : function(x,y,w,h) {},
arc : function(x,y,radius,startAngle,endAngle,anticlockwise) {},
fill : function() {},
stroke : function() {},
clip : function() {},
isPointInPath : function(x,y) {},
drawFocusRing : function(element,xCaret,yCaret,canDrawCustom) {},
fillText : function(text,x,y,maxWidth) {},
strokeText : function(text,x,y,maxWidth) {},
measureText : function(text) {},
drawImage : function(img_elem,dx_or_sx,dy_or_sy,dw_or_sw,dh_or_sh,dx,dy,dw,dh) {},
createImageData : function(imagedata_or_sw,sh)
{
var _data = new _image_data();
_data.length = imagedata_or_sw * sh * 4;
_data.data = (typeof(Uint8Array) != 'undefined') ? new Uint8Array(_data.length) : new Array(_data.length);
return _data;
},
getImageData : function(sx,sy,sw,sh) {},
putImageData : function(image_data,dx,dy,dirtyX,dirtyY,dirtyWidth,dirtyHeight) {}
};
function native_canvas()
{
this.id = "";
this.width = 300;
this.height = 150;
this.nodeType = 1;
}
native_canvas.prototype =
{
getContext : function(type)
{
if (type == "2d")
return new native_context2d(this);
return null;
},
toDataUrl : function(type)
{
return "";
},
addEventListener : function()
{
},
attr : function()
{
}
};
window["Asc"] = {};
var _null_object = {};
_null_object.length = 0;
_null_object.nodeType = 1;
_null_object.offsetWidth = 1;
_null_object.offsetHeight = 1;
_null_object.clientWidth = 1;
_null_object.clientHeight = 1;
_null_object.scrollWidth = 1;
_null_object.scrollHeight = 1;
_null_object.style = {};
_null_object.documentElement = _null_object;
_null_object.body = _null_object;
_null_object.ownerDocument = _null_object;
_null_object.defaultView = _null_object;
_null_object.addEventListener = function(){};
_null_object.setAttribute = function(){};
_null_object.getElementsByTagName = function() { return []; };
_null_object.appendChild = function() {};
_null_object.removeChild = function() {};
_null_object.insertBefore = function() {};
_null_object.childNodes = [];
_null_object.parent = _null_object;
_null_object.parentNode = _null_object;
_null_object.find = function() { return this; };
_null_object.appendTo = function() { return this; };
_null_object.css = function() { return this; };
_null_object.width = function() { return 1; };
_null_object.height = function() { return 1; };
_null_object.attr = function() { return this; };
_null_object.prop = function() { return this; };
_null_object.val = function() { return this; };
_null_object.remove = function() {};
_null_object.getComputedStyle = function() { return null; };
_null_object.getContext = function(type) {
if (type == "2d")
return new native_context2d(this);
return null;
};
window._null_object = _null_object;
document.createElement = function(type)
{
if (type && type.toLowerCase)
{
if (type.toLowerCase() == "canvas")
return new native_canvas();
}
return _null_object;
}
function _return_empty_html_element() { return _null_object; };
document.createDocumentFragment = _return_empty_html_element;
document.getElementsByTagName = function(tag) {
var ret = [];
if ("head" == tag)
ret.push(_null_object);
return ret;
};
document.insertBefore = function() {};
document.appendChild = function() {};
document.removeChild = function() {};
document.getElementById = function() { return _null_object; };
document.createComment = function() { return undefined; };
document.documentElement = _null_object;
document.body = _null_object;
var native = CreateNativeEngine();
window.native = native;
window["native"] = native;
function GetNativeEngine()
{
return window.native;
}
var native_renderer = null;
var _api = null;
var Asc = window["Asc"];
function NativeOpenFileData(data, version)
{
window.NATIVE_DOCUMENT_TYPE = window.native.GetEditorType();
if (window.NATIVE_DOCUMENT_TYPE == "presentation" || window.NATIVE_DOCUMENT_TYPE == "document")
{
_api = new window["asc_docs_api"]("");
_api.asc_nativeOpenFile(data, version);
}
else
{
_api = new window["Asc"]["spreadsheet_api"]();
_api.asc_nativeOpenFile(data, version);
}
}
function NativeOpenFile(arguments)
{
window["CreateMainTextMeasurerWrapper"]();
var doc_bin = window.native.GetFileString(window.native.GetFilePath());
window.NATIVE_DOCUMENT_TYPE = window.native.GetEditorType();
if (window.NATIVE_DOCUMENT_TYPE == "presentation" || window.NATIVE_DOCUMENT_TYPE == "document")
{
_api = new window["asc_docs_api"]("");
_api.asc_nativeOpenFile(doc_bin);
}
else
{
_api = new window["Asc"]["spreadsheet_api"]();
_api.asc_nativeOpenFile(doc_bin);
}
}
function NativeOpenFile2(_params)
{
window["CreateMainTextMeasurerWrapper"]();
window.g_file_path = "native_open_file";
window.NATIVE_DOCUMENT_TYPE = window.native.GetEditorType();
var doc_bin = window.native.GetFileString(window.g_file_path);
if (window.NATIVE_DOCUMENT_TYPE == "presentation" || window.NATIVE_DOCUMENT_TYPE == "document")
{
_api = new window["asc_docs_api"]("");
if (undefined !== _api.Native_Editor_Initialize_Settings)
{
_api.Native_Editor_Initialize_Settings(_params);
}
_api.asc_nativeOpenFile(doc_bin);
if (_api.NativeAfterLoad)
_api.NativeAfterLoad();
}
else
{
_api = new window["Asc"]["spreadsheet_api"]();
_api.asc_nativeOpenFile(doc_bin);
}
}
// open file
function SEOpenFile()
{
window["CreateMainTextMeasurerWrapper"]();
window.g_file_path = "native_open_file";
window.NATIVE_DOCUMENT_TYPE = window.native.GetEditorType();
_api = new window["Asc"]["spreadsheet_api"]();
_api.asc_nativeOpenFile(window.native["GetFileString"]());
}
function NativeCalculateFile()
{
_api.asc_nativeCalculateFile();
}
function NativeApplyChangesData(data, isFull)
{
if (window.NATIVE_DOCUMENT_TYPE == "presentation" || window.NATIVE_DOCUMENT_TYPE == "document")
{
_api.asc_nativeApplyChanges2(data, isFull);
}
else
{
_api.asc_nativeApplyChanges2(data, isFull);
}
}
function NativeApplyChanges()
{
if (window.NATIVE_DOCUMENT_TYPE == "presentation" || window.NATIVE_DOCUMENT_TYPE == "document")
{
var __changes = [];
var _count_main = window.native.GetCountChanges();
for (var i = 0; i < _count_main; i++)
{
var _changes_file = window.native.GetChangesFile(i);
var _changes = JSON.parse(window.native.GetFileString(_changes_file));
for (var j = 0; j < _changes.length; j++)
{
__changes.push(_changes[j]);
}
}
_api.asc_nativeApplyChanges(__changes);
}
else
{
var __changes = [];
var _count_main = window.native.GetCountChanges();
for (var i = 0; i < _count_main; i++)
{
var _changes_file = window.native.GetChangesFile(i);
var _changes = JSON.parse(window.native.GetFileString(_changes_file));
for (var j = 0; j < _changes.length; j++)
{
__changes.push(_changes[j]);
}
}
_api.asc_nativeApplyChanges(__changes);
}
}
function NativeGetFileString()
{
return _api.asc_nativeGetFile();
}
function NativeGetFileData()
{
return _api.asc_nativeGetFileData();
}
function GetNativeCountPages()
{
return _api.asc_nativePrintPagesCount();
}
window.memory1 = null;
window.memory2 = null;
function GetNativePageBase64(pageIndex)
{
if (null == window.memory1)
window.memory1 = CreateNativeMemoryStream();
else
window.memory1.ClearNoAttack();
if (null == window.memory2)
window.memory2 = CreateNativeMemoryStream();
else
window.memory2.ClearNoAttack();
if (native_renderer == null)
{
native_renderer = _api.asc_nativeCheckPdfRenderer(window.memory1, window.memory2);
}
else
{
window.memory1.ClearNoAttack();
window.memory2.ClearNoAttack();
}
_api.asc_nativePrint(native_renderer, pageIndex);
return window.memory1;
}
function GetNativePageMeta(pageIndex)
{
return _api.GetNativePageMeta(pageIndex);
}
function GetNativeId()
{
return window.native.GetFileId();
}
// для работы с таймерами
window.NativeSupportTimeouts = false;
window.NativeTimeoutObject = {};
function clearTimeout(_id)
{
if (!window.NativeSupportTimeouts)
return;
window.NativeTimeoutObject["" + _id] = undefined;
window.native["ClearTimeout"](_id);
}
function setTimeout(func, interval)
{
if (!window.NativeSupportTimeouts)
return;
var _id = window.native["GenerateTimeoutId"](interval);
window.NativeTimeoutObject["" + _id] = func;
return _id;
}
window.native.Call_TimeoutFire = function(_id)
{
if (!window.NativeSupportTimeouts)
return;
var _prop = "" + _id;
var _func = window.NativeTimeoutObject[_prop];
window.NativeTimeoutObject[_prop] = undefined;
if (!_func)
return;
_func.call(null);
_func = null;
};
function clearInterval(_id)
{
if (!window.NativeSupportTimeouts)
return;
window.NativeTimeoutObject["" + _id] = undefined;
window.native["ClearTimeout"](_id);
}
function setInterval(func, interval)
{
if (!window.NativeSupportTimeouts)
return;
var _intervalFunc = function()
{
func.call(null);
setTimeout(func, interval);
};
var _id = window.native["GenerateTimeoutId"](interval);
window.NativeTimeoutObject["" + _id] = _intervalFunc;
return _id;
}
window.clearTimeout = clearTimeout;
window.setTimeout = setTimeout;
window.clearInterval = clearInterval;
window.setInterval = setInterval;
var console = {
log : function(param) { window.native.consoleLog(param); }
};
// HTML page interface
window.native.Call_OnUpdateOverlay = function(param)
{
return _api.Call_OnUpdateOverlay(param);
};
window.native.Call_OnMouseDown = function(e)
{
return _api.Call_OnMouseDown(e);
};
window.native.Call_OnMouseUp = function(e)
{
return _api.Call_OnMouseUp(e);
};
window.native.Call_OnMouseMove = function(e)
{
return _api.Call_OnMouseMove(e);
};
window.native.Call_OnCheckMouseDown = function(e)
{
return _api.Call_OnCheckMouseDown(e);
};
window.native.Call_OnKeyDown = function(e)
{
return _api.Call_OnKeyDown(e);
};
window.native.Call_OnKeyPress = function(e)
{
return _api.Call_OnKeyPress(e);
};
window.native.Call_OnKeyUp = function(e)
{
return _api.Call_OnKeyUp(e);
};
window.native.Call_OnKeyboardEvent = function(e)
{
return _api.Call_OnKeyboardEvent(e);
};
window.native.Call_CalculateResume = function()
{
return _api.Call_CalculateResume();
};
window.native.Call_TurnOffRecalculate = function()
{
return _api.Call_TurnOffRecalculate();
};
window.native.Call_TurnOnRecalculate = function()
{
return _api.Call_TurnOnRecalculate();
};
window.native.Call_CheckTargetUpdate = function()
{
return _api.Call_CheckTargetUpdate();
};
window.native.Call_Common = function(type, param)
{
return _api.Call_Common(type, param);
};
window.native.Call_HR_Tabs = function(arrT, arrP)
{
return _api.Call_HR_Tabs(arrT, arrP);
};
window.native.Call_HR_Pr = function(_indent_left, _indent_right, _indent_first)
{
return _api.Call_HR_Pr(_indent_left, _indent_right, _indent_first);
};
window.native.Call_HR_Margins = function(_margin_left, _margin_right)
{
return _api.Call_HR_Margins(_margin_left, _margin_right);
};
window.native.Call_HR_Table = function(_params, _cols, _margins, _rows)
{
return _api.Call_HR_Table(_params, _cols, _margins, _rows);
};
window.native.Call_VR_Margins = function(_top, _bottom)
{
return _api.Call_VR_Margins(_top, _bottom);
};
window.native.Call_VR_Header = function(_header_top, _header_bottom)
{
return _api.Call_VR_Header(_header_top, _header_bottom);
};
window.native.Call_VR_Table = function(_params, _cols, _margins, _rows)
{
return _api.Call_VR_Table(_params, _cols, _margins, _rows);
};
window.native.Call_Menu_Event = function(type, _params)
{
return _api.Call_Menu_Event(type, _params);
};
// FT_Common
function _FT_Common()
{
this.UintToInt = function(v)
{
return (v>2147483647)?v-4294967296:v;
};
this.UShort_To_Short = function(v)
{
return (v>32767)?v-65536:v;
};
this.IntToUInt = function(v)
{
return (v<0)?v+4294967296:v;
};
this.Short_To_UShort = function(v)
{
return (v<0)?v+65536:v;
};
this.memset = function(d,v,s)
{
for (var i=0;i<s;i++)
d[i]=v;
};
this.memcpy = function(d,s,l)
{
for (var i=0;i<l;i++)
d[i]=s[i];
};
this.memset_p = function(d,v,s)
{
var _d = d.data;
var _e = d.pos+s;
for (var i=d.pos;i<_e;i++)
_d[i]=v;
};
this.memcpy_p = function(d,s,l)
{
var _d1=d.data;
var _p1=d.pos;
var _d2=s.data;
var _p2=s.pos;
for (var i=0;i<l;i++)
_d1[_p1++]=_d2[_p2++];
};
this.memcpy_p2 = function(d,s,p,l)
{
var _d1=d.data;
var _p1=d.pos;
var _p2=p;
for (var i=0;i<l;i++)
_d1[_p1++]=s[_p2++];
};
this.realloc = function(memory, pointer, cur_count, new_count)
{
var ret = { block: null, err : 0, size : new_count};
if (cur_count < 0 || new_count < 0)
{
/* may help catch/prevent nasty security issues */
ret.err = 6;
}
else if (new_count == 0)
{
ret.block = null;
}
else if (cur_count == 0)
{
ret.block = memory.Alloc(new_count);
}
else
{
var block2 = memory.Alloc(new_count);
FT_Common.memcpy_p(block2, pointer, cur_count);
ret.block = block2;
}
return ret;
};
this.realloc_long = function(memory, pointer, cur_count, new_count)
{
var ret = { block: null, err : 0, size : new_count};
if (cur_count < 0 || new_count < 0)
{
/* may help catch/prevent nasty security issues */
ret.err = 6;
}
else if (new_count == 0)
{
ret.block = null;
}
else if (cur_count == 0)
{
ret.block = CreateIntArray(new_count);
}
else
{
var block2 = CreateIntArray(new_count);
for (var i = 0; i < cur_count; i++)
block2[i] = pointer[i];
ret.block = block2;
}
return ret;
};
}
//--------------------------------------------------------------------------------
// font engine
//--------------------------------------------------------------------------------
var FONT_ITALIC_ANGLE = 0.3090169943749;
var FT_ENCODING_UNICODE = 1970170211;
var FT_ENCODING_NONE = 0;
var FT_ENCODING_MS_SYMBOL = 1937337698;
var FT_ENCODING_APPLE_ROMAN = 1634889070;
var LOAD_MODE = 40970;
var REND_MODE = 0;
var FontStyle =
{
FontStyleRegular: 0,
FontStyleBold: 1,
FontStyleItalic: 2,
FontStyleBoldItalic: 3,
FontStyleUnderline: 4,
FontStyleStrikeout: 8
};
var EGlyphState =
{
glyphstateNormal: 0,
glyphstateDeafault: 1,
glyphstateMiss: 2
};
function CPoint1()
{
this.fX = 0;
this.fY = 0;
this.fWidth = 0;
this.fHeight = 0;
};
function CPoint2()
{
this.fLeft = 0;
this.fTop = 0;
this.fRight = 0;
this.fBottom = 0;
};
function CFontManager()
{
this.m_oLibrary = {};
this.Initialize = function(){};
};
function CStylesPainter()
{
this.STYLE_THUMBNAIL_WIDTH = GlobalSkin.STYLE_THUMBNAIL_WIDTH;
this.STYLE_THUMBNAIL_HEIGHT = GlobalSkin.STYLE_THUMBNAIL_HEIGHT;
this.CurrentTranslate = null;
this.IsRetinaEnabled = false;
this.defaultStyles = [];
this.docStyles = [];
this.mergedStyles = [];
}
CStylesPainter.prototype =
{
GenerateStyles: function(_api, ds)
{
if (_api.WordControl.bIsRetinaSupport)
{
this.STYLE_THUMBNAIL_WIDTH <<= 1;
this.STYLE_THUMBNAIL_HEIGHT <<= 1;
this.IsRetinaEnabled = true;
}
this.CurrentTranslate = _api.CurrentTranslate;
var _stream = global_memory_stream_menu;
var _graphics = new CDrawingStream();
_api.WordControl.m_oDrawingDocument.Native["DD_PrepareNativeDraw"]();
this.GenerateDefaultStyles(_api, ds, _graphics);
this.GenerateDocumentStyles(_api, _graphics);
// стили сформированы. осталось просто сформировать единый список
var _count_default = this.defaultStyles.length;
var _count_doc = 0;
if (null != this.docStyles)
_count_doc = this.docStyles.length;
var aPriorityStyles = [];
var fAddToPriorityStyles = function(style){
var index = style.Style.uiPriority;
if(null == index)
index = 0;
var aSubArray = aPriorityStyles[index];
if(null == aSubArray)
{
aSubArray = [];
aPriorityStyles[index] = aSubArray;
}
aSubArray.push(style);
};
var _map_document = {};
for (var i = 0; i < _count_doc; i++)
{
var style = this.docStyles[i];
_map_document[style.Name] = 1;
fAddToPriorityStyles(style);
}
for (var i = 0; i < _count_default; i++)
{
var style = this.defaultStyles[i];
if(null == _map_document[style.Name])
fAddToPriorityStyles(style);
}
this.mergedStyles = [];
for(var index in aPriorityStyles)
{
var aSubArray = aPriorityStyles[index];
aSubArray.sort(function(a, b){
if(a.Name < b.Name)
return -1;
else if(a.Name > b.Name)
return 1;
else
return 0;
});
for(var i = 0, length = aSubArray.length; i < length; ++i)
{
this.mergedStyles.push(aSubArray[i]);
}
}
var _count = this.mergedStyles.length;
for (var i = 0; i < _count; i++)
{
this.drawStyle(_graphics, this.mergedStyles[i].Style, _api);
}
_stream["ClearNoAttack"]();
_stream["WriteByte"](1);
_api.WordControl.m_oDrawingDocument.Native["DD_EndNativeDraw"](_stream);
},
GenerateDefaultStyles: function(_api, ds, _graphics)
{
var styles = ds;
for (var i in styles)
{
var style = styles[i];
if (true == style.qFormat)
{
this.defaultStyles.push({ Name: style.Name, Style: style });
//this.drawStyle(_graphics, style, _api);
}
}
},
GenerateDocumentStyles: function(_api, _graphics)
{
if (_api.WordControl.m_oLogicDocument == null)
return;
var __Styles = _api.WordControl.m_oLogicDocument.Get_Styles();
var styles = __Styles.Style;
if (styles == null)
return;
for (var i in styles)
{
var style = styles[i];
if (true == style.qFormat)
{
// как только меняется сериалайзер - меняется и код здесь. Да, не очень удобно,
// зато быстро делается
var formalStyle = i.toLowerCase().replace(/\s/g, "");
var res = formalStyle.match(/^heading([1-9][0-9]*)$/);
var index = (res) ? res[1] - 1 : -1;
var _dr_style = __Styles.Get_Pr(i, styletype_Paragraph);
_dr_style.Name = style.Name;
_dr_style.Id = i;
//this.drawStyle(_graphics, _dr_style, _api);
var _name = _dr_style.Name;
// алгоритм смены имени
if (style.Default)
{
switch (style.Default)
{
case 1:
break;
case 2:
_name = "No List";
break;
case 3:
_name = "Normal";
break;
case 4:
_name = "Normal Table";
break;
}
}
else if (index != -1)
{
_name = "Heading ".concat(index + 1);
}
this.docStyles.push({ Name: _name, Style: _dr_style });
}
}
},
drawStyle: function(graphics, style, _api)
{
var _w_px = this.STYLE_THUMBNAIL_WIDTH;
var _h_px = this.STYLE_THUMBNAIL_HEIGHT;
var dKoefToMM = g_dKoef_pix_to_mm;
if (AscBrowser.isRetina)
{
_w_px *= 2;
_h_px *= 2;
dKoefToMM /= 2;
}
_api.WordControl.m_oDrawingDocument.Native["DD_StartNativeDraw"](_w_px, _h_px, _w_px * dKoefToMM, _h_px * dKoefToMM);
g_oTableId.m_bTurnOff = true;
History.TurnOff();
var oldDefTabStop = Default_Tab_Stop;
Default_Tab_Stop = 1;
var hdr = new CHeaderFooter(_api.WordControl.m_oLogicDocument.HdrFtr, _api.WordControl.m_oLogicDocument, _api.WordControl.m_oDrawingDocument, hdrftr_Header);
var _dc = hdr.Content;//new CDocumentContent(editor.WordControl.m_oLogicDocument, editor.WordControl.m_oDrawingDocument, 0, 0, 0, 0, false, true, false);
var par = new Paragraph(_api.WordControl.m_oDrawingDocument, _dc, 0, 0, 0, 0, false);
var run = new ParaRun(par, false);
for (var i = 0; i < style.Name.length; i++)
{
run.Add_ToContent(i, new ParaText(style.Name.charAt(i)), false);
}
_dc.Internal_Content_Add(0, par, false);
par.Add_ToContent(0, run);
par.Style_Add(style.Id, false);
par.Set_Align(align_Left);
par.Set_Tabs(new CParaTabs());
var _brdL = style.ParaPr.Brd.Left;
if ( undefined !== _brdL && null !== _brdL )
{
var brdL = new CDocumentBorder();
brdL.Set_FromObject(_brdL);
brdL.Space = 0;
par.Set_Border(brdL, historyitem_Paragraph_Borders_Left);
}
var _brdT = style.ParaPr.Brd.Top;
if ( undefined !== _brdT && null !== _brdT )
{
var brd = new CDocumentBorder();
brd.Set_FromObject(_brdT);
brd.Space = 0;
par.Set_Border(brd, historyitem_Paragraph_Borders_Top);
}
var _brdB = style.ParaPr.Brd.Bottom;
if ( undefined !== _brdB && null !== _brdB )
{
var brd = new CDocumentBorder();
brd.Set_FromObject(_brdB);
brd.Space = 0;
par.Set_Border(brd, historyitem_Paragraph_Borders_Bottom);
}
var _brdR = style.ParaPr.Brd.Right;
if ( undefined !== _brdR && null !== _brdR )
{
var brd = new CDocumentBorder();
brd.Set_FromObject(_brdR);
brd.Space = 0;
par.Set_Border(brd, historyitem_Paragraph_Borders_Right);
}
var _ind = new CParaInd();
_ind.FirstLine = 0;
_ind.Left = 0;
_ind.Right = 0;
par.Set_Ind(_ind, false);
var _sp = new CParaSpacing();
_sp.Line = 1;
_sp.LineRule = linerule_Auto;
_sp.Before = 0;
_sp.BeforeAutoSpacing = false;
_sp.After = 0;
_sp.AfterAutoSpacing = false;
par.Set_Spacing(_sp, false);
_dc.Reset(0, 0, 10000, 10000);
_dc.Recalculate_Page(0, true);
_dc.Reset(0, 0, par.Lines[0].Ranges[0].W + 0.001, 10000);
_dc.Recalculate_Page(0, true);
var y = 0;
var b = dKoefToMM * _h_px;
var w = dKoefToMM * _w_px;
var off = 10 * dKoefToMM;
var off2 = 5 * dKoefToMM;
var off3 = 1 * dKoefToMM;
graphics.transform(1,0,0,1,0,0);
graphics.save();
graphics._s();
graphics._m(off2, y + off3);
graphics._l(w - off, y + off3);
graphics._l(w - off, b - off3);
graphics._l(off2, b - off3);
graphics._z();
graphics.clip();
var baseline = par.Lines[0].Y;
par.Shift(0, off + 0.5, y + 0.75 * (b - y) - baseline);
par.Draw(0, graphics);
graphics.restore();
Default_Tab_Stop = oldDefTabStop;
g_oTableId.m_bTurnOff = false;
History.TurnOn();
var _stream = global_memory_stream_menu;
_stream["ClearNoAttack"]();
_stream["WriteByte"](0);
_stream["WriteString2"](style.Name);
_api.WordControl.m_oDrawingDocument.Native["DD_EndNativeDraw"](_stream);
graphics.ClearParams();
}
};
window["use_native_fonts_only"] = true;
//--------------------------------------------------------------------------------
// declarate unused methods and objects
window["ftm"] = FT_Memory;
// FT_Common
function _FT_Common()
{
this.UintToInt = function(v)
{
return (v>2147483647)?v-4294967296:v;
};
this.UShort_To_Short = function(v)
{
return (v>32767)?v-65536:v;
};
this.IntToUInt = function(v)
{
return (v<0)?v+4294967296:v;
};
this.Short_To_UShort = function(v)
{
return (v<0)?v+65536:v;
};
this.memset = function(d,v,s)
{
for (var i=0;i<s;i++)
d[i]=v;
};
this.memcpy = function(d,s,l)
{
for (var i=0;i<l;i++)
d[i]=s[i];
};
this.memset_p = function(d,v,s)
{
var _d = d.data;
var _e = d.pos+s;
for (var i=d.pos;i<_e;i++)
_d[i]=v;
};
this.memcpy_p = function(d,s,l)
{
var _d1=d.data;
var _p1=d.pos;
var _d2=s.data;
var _p2=s.pos;
for (var i=0;i<l;i++)
_d1[_p1++]=_d2[_p2++];
};
this.memcpy_p2 = function(d,s,p,l)
{
var _d1=d.data;
var _p1=d.pos;
var _p2=p;
for (var i=0;i<l;i++)
_d1[_p1++]=s[_p2++];
};
this.realloc = function(memory, pointer, cur_count, new_count)
{
var ret = { block: null, err : 0, size : new_count};
if (cur_count < 0 || new_count < 0)
{
/* may help catch/prevent nasty security issues */
ret.err = 6;
}
else if (new_count == 0)
{
ret.block = null;
}
else if (cur_count == 0)
{
ret.block = memory.Alloc(new_count);
}
else
{
var block2 = memory.Alloc(new_count);
FT_Common.memcpy_p(block2, pointer, cur_count);
ret.block = block2;
}
return ret;
};
this.realloc_long = function(memory, pointer, cur_count, new_count)
{
var ret = { block: null, err : 0, size : new_count};
if (cur_count < 0 || new_count < 0)
{
/* may help catch/prevent nasty security issues */
ret.err = 6;
}
else if (new_count == 0)
{
ret.block = null;
}
else if (cur_count == 0)
{
ret.block = CreateIntArray(new_count);
}
else
{
var block2 = CreateIntArray(new_count);
for (var i = 0; i < cur_count; i++)
block2[i] = pointer[i];
ret.block = block2;
}
return ret;
};
}
var FT_Common = new _FT_Common();
//--------------------------------------------------------------------------------
// internal invoke
//--------------------------------------------------------------------------------
function internal_drawWorksheet(sheet, corner, frozenPaneLines) {
sheet._clean();
if (corner) sheet._drawCorner();
sheet._drawColumnHeaders();
sheet._drawRowHeaders();
sheet._drawGrid();
sheet._drawCellsAndBorders();
sheet._drawFrozenPane();
if (frozenPaneLines) sheet._drawFrozenPaneLines();
sheet._fixSelectionOfMergedCells();
sheet._drawAutoF();
sheet.cellCommentator.drawCommentCells();
// sheet.objectRender.showDrawingObjectsEx(true);
if (sheet.overlayCtx) {
sheet._drawSelection();
}
}
//--------------------------------------------------------------------------------
// native invoke
//--------------------------------------------------------------------------------
var scrollIndX = 0;
var scrollIndY = 0;
var deviceScale = 1;
var cellsLeft = undefined;
var cellsTop = undefined;
function napi_openFile() {
window["CreateMainTextMeasurerWrapper"]();
deviceScale = window.native["GetDeviceScale"]();
window.g_file_path = "native_open_file";
window.NATIVE_DOCUMENT_TYPE = window.native.GetEditorType();
_api = new window["Asc"]["spreadsheet_api"]();
_api.asc_nativeOpenFile(window.native["GetFileString"]());
}
function napi_drawWorksheet(x, y, width, height, xind, yind) {
if (_api) {
_null_object.width = width;
_null_object.height = height;
var worksheet = _api.wb.getWorksheet(0), indX = 0, indY = 0, offX = 0, offY = 0;
x = x / deviceScale * (72.0 / 96.0) + worksheet.headersWidth;
y = y / deviceScale * (72.0 / 96.0) + worksheet.headersHeight;
// сброс текущего отступа по ячейке (пока через костыль делаем скроллы)
if (undefined == cellsLeft) {
cellsLeft = worksheet.cellsLeft; //console.log('left: ' + cellsLeft);
}
if (undefined == cellsTop) {
cellsTop = worksheet.cellsTop; //console.log('top: ' + cellsTop);
}
worksheet.cellsLeft = cellsLeft;
worksheet.cellsTop = cellsTop;
if (0 == xind && scrollIndX != 0)
{
for (var i = scrollIndX; i >= 0; --i)
worksheet.scrollHorizontal(-1);
scrollIndX = 0;
}
if (0 == yind && scrollIndY != 0)
{
for (var i = scrollIndY; i >= 0; --i)
worksheet.scrollVertical(-1);
scrollIndY = 0;
}
// ищем ячейку для начальной точки отрисовки
for (var i = 0; i < worksheet.cols.length; ++i) {
if (worksheet.cols[i].left <= x && x < worksheet.cols[i].left + worksheet.cols[i].width) {
// if (xind == 1 && yind == 1) {
// console.log('x: ' + x +
// ' worksheet.cols[i].left: ' + worksheet.cols[i].left+
// ' worksheet.cols[i].width: ' + worksheet.cols[i].width
// );
// }
indX = i;
offX = x - worksheet.cols[i].left;
break;
}
}
for (var i = 0; i < worksheet.rows.length; ++i) {
// if ((xind == 1 || xind == 0)&& yind == 1)
// console.log('top-height: ' + worksheet.rows[i].top + ',' + worksheet.rows[i].height);
if (worksheet.rows[i].top <= y && y < worksheet.rows[i].top + worksheet.rows[i].height) {
// if ((xind == 1 || xind == 0)&& yind == 1) {
// console.log('y: ' + y +
// ' worksheet.rows[i].top: ' + worksheet.rows[i].top +
// ' worksheet.rows[i].height: ' + worksheet.rows[i].height +
// ' bottom: ' + ( worksheet.rows[i].top + worksheet.rows[i].height) +
// ' indY: ' + i + ' offY: ' + offY
// );
// //}
indY = i;
offY = y - worksheet.rows[i].top;
break;
}
}
// for (var i = 0; i < worksheet.rows.length; ++i)
// console.log(xind + ',' + yind + ' before top-height: ' + worksheet.rows[i].top + ',' + worksheet.rows[i].height);
//
//
if (indX - scrollIndX > 0) {
for (var i = scrollIndX; i < indX; ++i)
worksheet.scrollHorizontal(1);
scrollIndX = indX;
}
if (indY - scrollIndY > 0) {
for (var i = scrollIndY; i < indY; ++i)
worksheet.scrollVertical(1);
scrollIndY = indY;
}
//
// for (var i = 0; i < worksheet.rows.length; ++i)
// console.log(xind + ',' + yind + ' after top-height: ' + worksheet.rows[i].top + ',' + worksheet.rows[i].height);
worksheet.cellsLeft = -offX;
worksheet.cellsTop = -offY;
internal_drawWorksheet(worksheet);
}
}
function napi_drawWorksheetHeader(x, y, width, height, xind, yind, type) {
// direction
// 0 - default
// 1 - top pages
// -1 - left pages
// 2 - top_left rectangle
if (_api) {
_null_object.width = width;
_null_object.height = height;
var worksheet = _api.wb.getWorksheet(0), indX = 0, indY = 0, offX = 0, offY = 0;
x = x / deviceScale * (72.0 / 96.0) + worksheet.headersWidth;
y = y / deviceScale * (72.0 / 96.0) + worksheet.headersHeight;
// сброс текущего отступа по ячейке (пока через костыль делаем скроллы)
if (undefined == cellsLeft) {
cellsLeft = worksheet.cellsLeft; //console.log('left: ' + cellsLeft);
}
if (undefined == cellsTop) {
cellsTop = worksheet.cellsTop; //console.log('top: ' + cellsTop);
}
worksheet.cellsLeft = cellsLeft;
worksheet.cellsTop = cellsTop;
if (0 == xind && scrollIndX != 0)
{
for (var i = scrollIndX; i >= 0; --i)
worksheet.scrollHorizontal(-1);
scrollIndX = 0;
}
if (0 == yind && scrollIndY != 0)
{
for (var i = scrollIndY; i >= 0; --i)
worksheet.scrollVertical(-1);
scrollIndY = 0;
}
// ищем ячейку для начальной точки отрисовки
for (var i = 0; i < worksheet.cols.length; ++i) {
if (worksheet.cols[i].left <= x && x < worksheet.cols[i].left + worksheet.cols[i].width) {
indX = i;
offX = x - worksheet.cols[i].left;
break;
}
}
for (var i = 0; i < worksheet.rows.length; ++i) {
if (worksheet.rows[i].top <= y && y < worksheet.rows[i].top + worksheet.rows[i].height) {
indY = i;
offY = y - worksheet.rows[i].top;
break;
}
}
if (indX - scrollIndX > 0) {
for (var i = scrollIndX; i < indX; ++i)
worksheet.scrollHorizontal(1);
scrollIndX = indX;
}
if (indY - scrollIndY > 0) {
for (var i = scrollIndY; i < indY; ++i)
worksheet.scrollVertical(1);
scrollIndY = indY;
}
worksheet.cellsLeft = -offX;
worksheet.cellsTop = -offY;
if ((0 == yind && type == 1) || type == 2) {
worksheet.cellsTop += worksheet.headersHeight;
}
if ((0 == xind && type == -1) || type == 2) {
worksheet.cellsLeft += worksheet.headersWidth;
}
if (type == 2)
{
internal_drawWorksheet(worksheet, true);
}
else
{
internal_drawWorksheet(worksheet);
}
}
}
function napi_getContentMaxSizeX() {
// ширина таблицы с учетом размеров ячеек
// var gc_nMaxRow = 1048576;
// var gc_nMaxCol = 16384;
return 50000;
}
function napi_getContentMaxSizeY() {
// высота таблицы с учетом размеров ячеек
//var gc_nMaxRow = 1048576;
//var gc_nMaxCol = 16384;
return 50000;
}
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