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

- переход на CImage

- добавлен ImageLoader
- convertMetric

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@47732 954022d7-b5bf-4e40-9824-e11837661b57
parent 75f7393f
...@@ -42,10 +42,10 @@ function convertFormula(formula, ws) { ...@@ -42,10 +42,10 @@ function convertFormula(formula, ws) {
function _getFullImageSrc(src) { function _getFullImageSrc(src) {
var start = src.substring(0, 6); var start = src.substring(0, 6);
if ( 0 != src.indexOf("http:") && 0 != src.indexOf("data:") && 0 != src.indexOf("https:") && 0 != src.indexOf("ftp:") && 0 != src.indexOf("file:") ) { if ( 0 != src.indexOf("http:") && 0 != src.indexOf("data:") && 0 != src.indexOf("https:") && 0 != src.indexOf("ftp:") && 0 != src.indexOf("file:") ) {
var editor = window["Asc"]["editor"]; var api = window["Asc"]["editor"];
if ( 0 == src.indexOf(g_sResourceServiceLocalUrl + editor.documentId) ) if ( 0 == src.indexOf(g_sResourceServiceLocalUrl + api.documentId) )
return src; return src;
return g_sResourceServiceLocalUrl + editor.documentId + "/media/" + src; return g_sResourceServiceLocalUrl + api.documentId + "/media/" + src;
} }
else else
return src; return src;
...@@ -2049,7 +2049,8 @@ function DrawingObjects() { ...@@ -2049,7 +2049,8 @@ function DrawingObjects() {
// Private // Private
//----------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------
var _this = this; var _this = this;
var api = window["Asc"]["editor"];
var chartRender = new ChartRender(); var chartRender = new ChartRender();
var worksheet = null; var worksheet = null;
var isViewerMode = null; var isViewerMode = null;
...@@ -2076,6 +2077,9 @@ function DrawingObjects() { ...@@ -2076,6 +2077,9 @@ function DrawingObjects() {
// Все изменения, связанные с image.src прогоняем через этот класс // Все изменения, связанные с image.src прогоняем через этот класс
var imageLoader = new ImageLoader(); var imageLoader = new ImageLoader();
_this.asyncImageLoadedEvent = null;
//----------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------
// Public methods // Public methods
...@@ -2083,7 +2087,6 @@ function DrawingObjects() { ...@@ -2083,7 +2087,6 @@ function DrawingObjects() {
_this.init = function(currentSheet) { _this.init = function(currentSheet) {
var api = window["Asc"]["editor"];
userId = api.User.asc_getId(); userId = api.User.asc_getId();
documentId = api.documentId; documentId = api.documentId;
worksheet = currentSheet; worksheet = currentSheet;
...@@ -3086,9 +3089,95 @@ function DrawingObjects() { ...@@ -3086,9 +3089,95 @@ function DrawingObjects() {
if (imageUrl && !isViewerMode()) { if (imageUrl && !isViewerMode()) {
imageLoader.addImage(imageUrl); //imageLoader.addImage(imageUrl);
var _image = api.ImageLoader.LoadImage(imageUrl, 1);
if (null != _image) {
addImageObject(_image);
}
else {
_this.asyncImageLoadedEvent = function(_image) {
addImageObject(_image);
}
}
function addImageObject(_image) {
var obj = _this.createDrawingObject(); var obj = _this.createDrawingObject();
obj.id = generateId();
obj.worksheet = worksheet;
obj.from.col = worksheet.getSelectedColumnIndex();
obj.from.row = worksheet.getSelectedRowIndex();
// Проверяем начальные координаты при вставке
while ( !worksheet.cols[obj.from.col] ) {
worksheet.expandColsOnScroll(true);
}
worksheet.expandColsOnScroll(true); // для colOff
while ( !worksheet.rows[obj.from.row] ) {
worksheet.expandRowsOnScroll(true);
}
worksheet.expandRowsOnScroll(true); // для rowOff
calculateObjectMetrics(obj, _image.Image.width, _image.Image.height);
// CImage
obj.graphicObject = new CImage(obj, _this);
obj.graphicObject.initDefault( pxToMm(obj.getVisibleLeftOffset()), pxToMm(obj.getVisibleTopOffset()), pxToMm(obj.getWidthFromTo()), pxToMm(obj.getHeightFromTo()), _image.Image.src );
obj.graphicObject.select(_this.controller);
aObjects.push(obj);
_this.showDrawingObjects(false);
}
function calculateObjectMetrics(object, width, height) {
// Обработка картинок большого разрешения
var metricCoeff = 1;
var realTopOffset = object.getRealTopOffset();
var realLeftOffset = object.getRealLeftOffset();
var areaWidth = worksheet.getCellLeft(worksheet.getLastVisibleCol(), 0) - worksheet.getCellLeft(worksheet.getFirstVisibleCol(), 0); // по ширине
if (areaWidth < width) {
metricCoeff = width / areaWidth;
width = areaWidth;
height /= metricCoeff;
}
var areaHeight = worksheet.getCellTop(worksheet.getLastVisibleRow(), 0) - worksheet.getCellTop(worksheet.getFirstVisibleRow(), 0); // по высоте
if (areaHeight < height) {
metricCoeff = height / areaHeight;
height = areaHeight;
width /= metricCoeff;
}
var endPoint = worksheet._findColUnderCursor(pxToPt(realLeftOffset + width), true);
while (endPoint == null) {
worksheet.expandColsOnScroll(true);
endPoint = worksheet._findColUnderCursor(pxToPt(realLeftOffset + width), true);
}
worksheet.expandColsOnScroll(true); // для colOff
object.to.col = worksheet._findColUnderCursor(pxToPt(realLeftOffset + width), true).col;
object.to.colOff = pxToMm(realLeftOffset + width - worksheet.getCellLeft(object.to.col, 0));
endPoint = worksheet._findRowUnderCursor(pxToPt(realTopOffset + height), true);
while (endPoint == null) {
worksheet.expandRowsOnScroll(true);
endPoint = worksheet._findRowUnderCursor(pxToPt(realTopOffset + height), true);
}
worksheet.expandRowsOnScroll(true); // для rowOff
object.to.row = worksheet._findRowUnderCursor(pxToPt(realTopOffset + height), true).row;
object.to.rowOff = pxToMm(realTopOffset + height - worksheet.getCellTop(object.to.row, 0));
worksheet._trigger("reinitializeScroll");
}
/*var obj = _this.createDrawingObject();
obj.id = generateId(); obj.id = generateId();
obj.worksheet = worksheet; obj.worksheet = worksheet;
...@@ -3180,17 +3269,17 @@ function DrawingObjects() { ...@@ -3180,17 +3269,17 @@ function DrawingObjects() {
aObjects.push(obj); aObjects.push(obj);
_this.showDrawingObjects(false); _this.showDrawingObjects(false);
/*aObjects.push(obj); // aObjects.push(obj);
_this.selectDrawingObject(aObjects.length - 1); // _this.selectDrawingObject(aObjects.length - 1);
History.Create_NewPoint(); // History.Create_NewPoint();
var copyObject = _this.cloneDrawingObject(obj); // var copyObject = _this.cloneDrawingObject(obj);
History.Add(g_oUndoRedoDrawingObject, historyitem_DrawingObject_Add, worksheet.model.getId(), null, copyObject); // History.Add(g_oUndoRedoDrawingObject, historyitem_DrawingObject_Add, worksheet.model.getId(), null, copyObject);
_this.showDrawingObjects(true); // _this.showDrawingObjects(true);
worksheet.model.workbook.handlers.trigger("asc_onEndAction", c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.LoadImage); // worksheet.model.workbook.handlers.trigger("asc_onEndAction", c_oAscAsyncActionType.BlockInteraction, c_oAscAsyncAction.LoadImage);
worksheet.autoFilters.drawAutoF(worksheet); // worksheet.autoFilters.drawAutoF(worksheet);
worksheet.cellCommentator.drawCommentCells(false);*/ // worksheet.cellCommentator.drawCommentCells(false);
} }
obj.image.onerror = function() { obj.image.onerror = function() {
...@@ -3201,7 +3290,7 @@ function DrawingObjects() { ...@@ -3201,7 +3290,7 @@ function DrawingObjects() {
obj.imageUrl = imageUrl; obj.imageUrl = imageUrl;
} }
_this.lockDrawingObject(obj.id, bPackage ? false : true, bPackage ? false : true); _this.lockDrawingObject(obj.id, bPackage ? false : true, bPackage ? false : true);*/
} }
} }
...@@ -3220,7 +3309,6 @@ function DrawingObjects() { ...@@ -3220,7 +3309,6 @@ function DrawingObjects() {
// Инжектим тему и перестраиваем превью диаграмм // Инжектим тему и перестраиваем превью диаграмм
if ( wordChart.themeColors ) { if ( wordChart.themeColors ) {
var api = window["Asc"]["editor"];
api.GuiControlColorsMap = []; api.GuiControlColorsMap = [];
for (var i = 0; i < wordChart.themeColors.length; i++) { for (var i = 0; i < wordChart.themeColors.length; i++) {
...@@ -3895,8 +3983,13 @@ function DrawingObjects() { ...@@ -3895,8 +3983,13 @@ function DrawingObjects() {
for (var i = 0; i < aObjects.length; i++) { for (var i = 0; i < aObjects.length; i++) {
if ( idGroup == aObjects[i].id ) { if ( idGroup == aObjects[i].id ) {
aObjects.splice(i, 1, aSingleObjects);
_this.showDrawingObjects(false); aObjects.splice(i, 1);
for (var j = aSingleObjects.length - 1; j > -1; j--) {
aObjects.splice(i, 0, aSingleObjects[j]);
}
_this.showDrawingObjects(true);
break; break;
} }
} }
...@@ -3968,6 +4061,12 @@ function DrawingObjects() { ...@@ -3968,6 +4061,12 @@ function DrawingObjects() {
} }
} }
_this.convertMetric = function(val, from, to) {
/* Параметры конвертирования (from/to)
0 - px, 1 - pt, 2 - in, 3 - mm
*/
return val * ascCvtRatio(from, to);
}
//----------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------
// Graphic object mouse events // Graphic object mouse events
//----------------------------------------------------------------------------------- //-----------------------------------------------------------------------------------
......
...@@ -162,6 +162,7 @@ ...@@ -162,6 +162,7 @@
<script src="model/DrawingObjects/Controls.js"></script> <script src="model/DrawingObjects/Controls.js"></script>
<script src="model/DrawingObjects/DrawingObjectsController.js"></script> <script src="model/DrawingObjects/DrawingObjectsController.js"></script>
<script src="model/DrawingObjects/States.js"></script> <script src="model/DrawingObjects/States.js"></script>
<script src="model/DrawingObjects/GlobalLoaders.js"></script>
<script src="model/DrawingObjects/Format/GroupShape.js"></script> <script src="model/DrawingObjects/Format/GroupShape.js"></script>
<script src="model/DrawingObjects/Format/Image.js"></script> <script src="model/DrawingObjects/Format/Image.js"></script>
......
...@@ -111,6 +111,8 @@ var ASC_DOCS_API_USE_EMBEDDED_FONTS = "@@ASC_DOCS_API_USE_EMBEDDED_FONTS"; ...@@ -111,6 +111,8 @@ var ASC_DOCS_API_USE_EMBEDDED_FONTS = "@@ASC_DOCS_API_USE_EMBEDDED_FONTS";
// Shapes // Shapes
this.isStartAddShape = false; this.isStartAddShape = false;
this.addShapePreset = ""; this.addShapePreset = "";
this.ImageLoader = window.g_image_loader;
this.ImageLoader.put_Api(this);
/**************************************/ /**************************************/
this.OpenDocumentProgress = { this.OpenDocumentProgress = {
...@@ -2085,6 +2087,15 @@ var ASC_DOCS_API_USE_EMBEDDED_FONTS = "@@ASC_DOCS_API_USE_EMBEDDED_FONTS"; ...@@ -2085,6 +2087,15 @@ var ASC_DOCS_API_USE_EMBEDDED_FONTS = "@@ASC_DOCS_API_USE_EMBEDDED_FONTS";
ws.objectRender.unGroupGraphicObjects(); ws.objectRender.unGroupGraphicObjects();
}, },
asyncImageStartLoaded: function() {
// здесь прокинуть евент о заморозке меню
},
asyncImageEndLoaded: function(_image) {
var ws = this.wb.getWorksheet();
ws.objectRender.asyncImageLoadedEvent(_image);
},
// Cell interface // Cell interface
asc_getCellInfo: function (bExt) { asc_getCellInfo: function (bExt) {
return this.wb.getWorksheet().getSelectionInfo(!!bExt); return this.wb.getWorksheet().getSelectionInfo(!!bExt);
......
function CClipManager() function CClipManager()
{ {
this.clipRects = []; this.clipRects = [];
...@@ -991,6 +992,7 @@ CGraphics.prototype = ...@@ -991,6 +992,7 @@ CGraphics.prototype =
return; return;
} }
var editor = window["Asc"]["editor"];
var _img = editor.ImageLoader.map_image_index[img]; var _img = editor.ImageLoader.map_image_index[img];
if (_img != undefined && _img.Status == ImageLoadStatus.Loading) if (_img != undefined && _img.Status == ImageLoadStatus.Loading)
{ {
......
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