wordcopypaste.js 304 KB
Newer Older
1 2 3
"use strict";

function CDocumentReaderMode()
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
{
    this.DefaultFontSize = 12;

    this.CorrectDefaultFontSize = function(size)
    {
        if (size < 6)
            return;

        this.DefaultFontSize = size;
    }

    this.CorrectFontSize = function(size)
    {
        var dRes = size / this.DefaultFontSize;
        dRes = (1 + dRes) / 2;
        dRes = (100 * dRes) >> 0;
        dRes /= 100;

        return "" + dRes + "em";
    }
}

Oleg.Korshul's avatar
Oleg.Korshul committed
26 27 28 29
window.USER_AGENT_MACOS = AscBrowser.isMacOs;
window.USER_AGENT_SAFARI_MACOS = AscBrowser.isSafariMacOs;
window.USER_AGENT_IE = AscBrowser.isIE || AscBrowser.isOpera;
window.USER_AGENT_WEBKIT = AscBrowser.isWebkit;
Oleg.Korshul's avatar
 
Oleg.Korshul committed
30

Oleg.Korshul's avatar
 
Oleg.Korshul committed
31
window.GlobalPasteFlagCounter = 0;
Oleg.Korshul's avatar
 
Oleg.Korshul committed
32
window.GlobalPasteFlag = false;
Oleg.Korshul's avatar
Oleg.Korshul committed
33

34 35
window.PasteEndTimerId = -1;

Oleg.Korshul's avatar
Oleg.Korshul committed
36 37 38
var COPY_ELEMENT_ID = "SelectId";
var PASTE_ELEMENT_ID = "wrd_pastebin";
var ELEMENT_DISPAY_STYLE = "none";
Igor.Zotov's avatar
Igor.Zotov committed
39
var copyPasteUseBinary = true;
Oleg.Korshul's avatar
Oleg.Korshul committed
40

41
if (window.USER_AGENT_SAFARI_MACOS)
Oleg.Korshul's avatar
Oleg.Korshul committed
42 43 44 45 46
{
    var PASTE_ELEMENT_ID = "SelectId";
    var ELEMENT_DISPAY_STYLE = "block";
}

47 48 49 50
var PASTE_EMPTY_COUNTER_MAX = 10;
var PASTE_EMPTY_COUNTER     = 0;
var PASTE_EMPTY_USE         = AscBrowser.isMozilla;

51
var g_bIsDocumentCopyPaste = true;
52
var isOnlyLocalBufferSafariWord = false;
53 54
function Editor_Copy_GetElem(api)
{
Oleg.Korshul's avatar
Oleg.Korshul committed
55
    var ElemToSelect = document.getElementById( COPY_ELEMENT_ID );
56 57 58
    if ( !ElemToSelect )
    {
        ElemToSelect = document.createElement("div");
Oleg.Korshul's avatar
Oleg.Korshul committed
59
        ElemToSelect.id = COPY_ELEMENT_ID;
Oleg.Korshul's avatar
 
Oleg.Korshul committed
60
        ElemToSelect.className = "sdk-element";
61 62 63 64 65 66
        ElemToSelect.style.position = "absolute";
        //���� ������� width ���������, �� �������� ����� ��������� ������������ �� span
        //� �������� � ����� ������ ��������� ������ <span>1</span><span> </span><span>2</span>
        //style.left = 0px, ���� ������� ���������� ������ ������� ������� ����, �� ����� ������� ������ �������� �����, �� � ����������� ����(� iframe) ������� ������������� � ����� ������ ��� ����� ������� ������ ����������.
        ElemToSelect.style.left = '0px';
        ElemToSelect.style.top = '-100px';
67
        ElemToSelect.style.width = '10000px';
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
        ElemToSelect.style.height = '100px';
        ElemToSelect.style.overflow = 'hidden';
        ElemToSelect.style.zIndex = -1000;
        ElemToSelect.style.MozUserSelect = "text";
        ElemToSelect.style["-khtml-user-select"] = "text";
        ElemToSelect.style["-o-user-select"] = "text";
        ElemToSelect.style["user-select"] = "text";
        ElemToSelect.style["-webkit-user-select"] = "text";
        ElemToSelect.setAttribute("contentEditable", true);

        if (!api || !api.GetCopyPasteDivId)
            document.body.appendChild( ElemToSelect );
        else
        {
            var _div_id = api.GetCopyPasteDivId();
            if ("" == _div_id)
                document.body.appendChild( ElemToSelect );
            else
            {
                var _div = document.getElementById(_div_id);
                _div.appendChild( ElemToSelect );
            }
        }
    }
    return ElemToSelect;
}
function Editor_Copy_Button(api, bCut)
{
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
96
    /*if(false == g_bIsDocumentCopyPaste)
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
    {
        switch(api.WordControl.Thumbnails.FocusObjType)
        {
            case FOCUS_OBJECT_MAIN:
            {
                var _logic_document = api.WordControl.m_oLogicDocument;
                if(_logic_document && _logic_document.CurPos.Type != docpostype_FlowObjects )
                {
                    _logic_document.slidesBuffer.length = 0;
                    _logic_document.glyphsBuffer = _logic_document.Slides[_logic_document.CurPage].elementsManipulator.glyphsCopy();
                    return true;
                }
                break;
            }
            case FOCUS_OBJECT_THUMBNAILS :
            {
                var _selected_array = api.WordControl.m_oLogicDocument.DrawingDocument.m_oWordControl.Thumbnails.GetSelectedArray();
                api.WordControl.m_oLogicDocument.glyphsBuffer.length = 0;
                api.WordControl.m_oLogicDocument.slidesCopy(_selected_array);
                return true;
            }
        }
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
119
    }*/
120 121 122 123
	
	if(bCut)
		History.Create_NewPoint();
	
Oleg.Korshul's avatar
Oleg.Korshul committed
124
    if(AscBrowser.isIE)
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151
    {
        var ElemToSelect = Editor_Copy_GetElem(api);
        ElemToSelect.style.display  = "block";

        while ( ElemToSelect.hasChildNodes() )
            ElemToSelect.removeChild( ElemToSelect.lastChild );

        //������ ��������� ���������
        document.body.style.MozUserSelect = "text";
        delete document.body.style["-khtml-user-select"];
        delete document.body.style["-o-user-select"];
        delete document.body.style["user-select"];
        document.body.style["-webkit-user-select"] = "text";

        if (null != api.WordControl.m_oLogicDocument)
        {
            var oCopyProcessor = new CopyProcessor(api, ElemToSelect);
            oCopyProcessor.Start();
        }
        else
        {
            ElemToSelect.innerHTML = api.WordControl.m_oDrawingDocument.m_oDocumentRenderer.Copy();
        }

        var selection = window.getSelection();
        var rangeToSelect = document.createRange();
        rangeToSelect.selectNodeContents (ElemToSelect);
Oleg.Korshul's avatar
 
Oleg.Korshul committed
152 153 154 155

        if (ElemToSelect.childElementCount !== 0)
            selection.removeAllRanges ();

156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216
        selection.addRange(rangeToSelect);

        document.execCommand("copy");
        //rangeToSelect.execCommand("copy");

        //�������� ����������� ���������
        ElemToSelect.style.display  = "none";
        document.body.style.MozUserSelect = "none";
        document.body.style["-khtml-user-select"] = "none";
        document.body.style["-o-user-select"] = "none";
        document.body.style["user-select"] = "none";
        document.body.style["-webkit-user-select"] = "none";

        if(true == bCut)
        {
            //������� ���������� ��������
            api.WordControl.m_oLogicDocument.Remove(1, true, true);
            api.WordControl.m_oLogicDocument.Document_UpdateSelectionState();
        }
        return true;
    }
	else
	{
		var ElemToSelect = Editor_Copy_GetElem(api);
		while ( ElemToSelect.hasChildNodes() )
			ElemToSelect.removeChild( ElemToSelect.lastChild );
		if (null != api.WordControl.m_oLogicDocument)
		{
			var oCopyProcessor = new CopyProcessor(api, ElemToSelect);
			oCopyProcessor.Start();
		}
		else
		{
			ElemToSelect.innerHTML = api.WordControl.m_oDrawingDocument.m_oDocumentRenderer.Copy();
		}
		if(true == bCut)
        {
            //������� ���������� ��������
            api.WordControl.m_oLogicDocument.Remove(1, true, true);
            api.WordControl.m_oLogicDocument.Document_UpdateSelectionState();
        }
		return true;
	}
    return false;
}
function Editor_Copy(api, bCut)
{
    //todo ��������� �����
    //������� ������� ����� ����������� ����������
    var ElemToSelect = Editor_Copy_GetElem(api);
    ElemToSelect.style.display  = "block";

    while ( ElemToSelect.hasChildNodes() )
        ElemToSelect.removeChild( ElemToSelect.lastChild );

    //������ ��������� ���������
    document.body.style.MozUserSelect = "text";
    delete document.body.style["-khtml-user-select"];
    delete document.body.style["-o-user-select"];
    delete document.body.style["user-select"];
    document.body.style["-webkit-user-select"] = "text";
217
	
218
	var oldBackgroundcolor = document.body.style["background-color"];
219
	//var oldColor = document.body.style["color"];
220
	document.body.style["background-color"] = "transparent";
221
	//document.body.style["color"] = "transparent";
222
	
223 224
	ElemToSelect.style.MozUserSelect = "all";
	
225 226 227 228 229 230 231 232
    if (null != api.WordControl.m_oLogicDocument)
    {
        var oCopyProcessor = new CopyProcessor(api, ElemToSelect);
        oCopyProcessor.Start();
    }
    else
    {
        ElemToSelect.innerHTML = api.WordControl.m_oDrawingDocument.m_oDocumentRenderer.Copy();
233 234
    };
	
235 236 237 238 239 240 241 242
    //��������
    if (window.getSelection) // all browsers, except IE before version 9
    {
        var selection = window.getSelection ();
        var rangeToSelect = document.createRange ();

        //� FF 8 ����� ��������� selectNodeContents ���������� � ������������ div, ����� ����� �������� � FF8 � ������ ��������� ����� ��� ����� ������ ��������� �������������� node
        //�������� ���� ��� ��� ��������� ��������� �� ����������. Chrome ������ ��������� ������ ����� ����� ������ ����������
Oleg.Korshul's avatar
Oleg.Korshul committed
243
        var is_gecko = AscBrowser.isGecko;
244 245 246 247 248 249 250 251 252 253 254
        if(is_gecko)
        {
            ElemToSelect.appendChild( document.createTextNode( '\xa0' ) );
            ElemToSelect.insertBefore( document.createTextNode( '\xa0' ), ElemToSelect.firstChild );
            rangeToSelect.setStartAfter (ElemToSelect.firstChild);
            rangeToSelect.setEndBefore (ElemToSelect.lastChild);
        }
        else
        {
            //�������� � webkit: ���� ���������� ����� ���� ��������, �� ���������� ������ ��� ������������
            //������ ��� docs.google ����������� ��� � ��� <b>
Oleg.Korshul's avatar
Oleg.Korshul committed
255
            if(window.USER_AGENT_WEBKIT && (true !== window.USER_AGENT_SAFARI_MACOS))
256 257 258 259 260 261
            {
                var aChildNodes = ElemToSelect.childNodes;
                if(aChildNodes.length == 1)
                {
                    var elem = aChildNodes[0];
                    var wrap = document.createElement("b");
262
                    wrap.setAttribute("style", "font-weight:normal; background-color: transparent; color: transparent;");
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
                    elem = ElemToSelect.removeChild(elem);
                    wrap.appendChild(elem);
                    ElemToSelect.appendChild(wrap);
                }
            }
            rangeToSelect.selectNodeContents (ElemToSelect);
        }

        selection.removeAllRanges ();
        selection.addRange (rangeToSelect);
    }
    else
    {
        if (document.body.createTextRange) // Internet Explorer
        {
            var rangeToSelect = document.body.createTextRange ();
            rangeToSelect.moveToElementText (ElemToSelect);
            rangeToSelect.select ();
        }
    }
283

284
    //���� ���������� copy
Oleg.Korshul's avatar
 
Oleg.Korshul committed
285
    var time_interval = 200;
286 287 288
    if (window.USER_AGENT_SAFARI_MACOS)
        time_interval = 200;

289 290 291
    window.setTimeout( function()
    {
        //�������� ����������� ���������
Oleg.Korshul's avatar
Oleg.Korshul committed
292
        ElemToSelect.style.display  = ELEMENT_DISPAY_STYLE;
293 294 295 296 297
        document.body.style.MozUserSelect = "none";
        document.body.style["-khtml-user-select"] = "none";
        document.body.style["-o-user-select"] = "none";
        document.body.style["user-select"] = "none";
        document.body.style["-webkit-user-select"] = "none";
298
		
299
		document.body.style["background-color"] = oldBackgroundcolor;
300
		//document.body.style["color"] = oldColor;
301
		
302
		ElemToSelect.style.MozUserSelect = "none";
Oleg.Korshul's avatar
 
Oleg.Korshul committed
303

304 305 306
        if(true == bCut)
        {
            //������� ���������� ��������
307
            api.WordControl.m_oLogicDocument.Remove(1, true, true);
308 309
            api.WordControl.m_oLogicDocument.Document_UpdateSelectionState();
        }
310
    }, time_interval);
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
    /*
     if (e.dataTransfer)
     {
     e.dataTransfer.setData('text', '2|16|190');
     }

     if (e.clipboardData)
     {
     e.preventDefault();
     e.clipboardData.setData('text/xcustom', 'Added this custom data at copy');
     e.clipboardData.setData('text/plain', 'This is not the text you copied, it was changed by the copy event handler');

     var TempXCustom = e.clipboardData.getData('text/xcustom');
     var TempPlain = e.clipboardData.getData('text/plain');
     var Temp = "sdf";
     }
     if (window.clipboardData)
     {
     e.returnValue = false;
     var setStatus = window.clipboardData.setData('Text', 'This is not the text you copied, it was changed by the copy event handler');
     }
     */
};
function CopyProcessor(api, ElemToSelect)
{
	this.api = api;
    this.oDocument = api.WordControl.m_oLogicDocument;
338
	this.oBinaryFileWriter = new BinaryFileWriter(this.oDocument);
339 340 341
    this.fontsArray = api.FontLoader.fontInfos;
    this.ElemToSelect = ElemToSelect;
    this.Ul = document.createElement( "ul" );
342
    this.Ol = document.createElement( "ol" );
343 344 345 346
    this.Para;
    this.bOccurEndPar;
    this.oCurHyperlink = null;
    this.oCurHyperlinkElem = null;
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
347
    this.oPresentationWriter = new CBinaryFileWriter();
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
348
    this.oPresentationWriter.Start_UseFullUrl(documentOrigin + editor.DocumentUrl);
Oleg.Korshul's avatar
 
Oleg.Korshul committed
349
    this.oPresentationWriter.Start_UseDocumentOrigin(documentOrigin);
350 351 352 353 354 355 356 357 358 359 360 361 362
};
CopyProcessor.prototype =
{
    getSrc : function(src)
    {
        //������� ����������� �� �� ��� editor.DocumentUrl ������������� ����.
        //���������� ����� ����� ��� ����������� � word � docs.google
        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:"))
            return documentOrigin + src;
        else
            return src;
    },
363
    RGBToCSS : function(rgb, unifill)
364
    {
365 366 367 368 369
        if (null == rgb && null != unifill) {
            unifill.check(this.oDocument.Get_Theme(), this.oDocument.Get_ColorMap());
            var RGBA = unifill.getRGBAColor();
            rgb = new CDocumentColor(RGBA.R, RGBA.G, RGBA.B);
        }
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385
        var sResult = "#";
        var sR = rgb.r.toString(16);
        if(sR.length == 1)
            sR = "0" + sR;
        var sG = rgb.g.toString(16);
        if(sG.length == 1)
            sG = "0" + sG;
        var sB = rgb.b.toString(16);
        if(sB.length == 1)
            sB = "0" + sB;
        return "#" + sR + sG + sB;
    },
    CommitList : function(oDomTarget)
    {
        if(this.Ul.childNodes.length > 0)
        {
386
			this.Ul.style.paddingLeft = "40px";
387 388 389 390 391
            oDomTarget.appendChild( this.Ul );
            this.Ul = document.createElement( "ul" );
        }
        if(this.Ol.childNodes.length > 0)
        {
392
			this.Ol.style.paddingLeft = "40px";
393 394 395 396 397 398 399
            oDomTarget.appendChild( this.Ol );
            this.Ol = document.createElement( "ol" );
        }
    },
    Commit_pPr : function(Item)
    {
        //pPr
Alexander.Trofimov's avatar
Alexander.Trofimov committed
400
        var apPr = [];
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455
        var Def_pPr = this.oDocument.Styles.Default.ParaPr;
        var Item_pPr = Item.CompiledPr.Pr.ParaPr;
        if(Item_pPr)
        {
            //Ind
            if(Def_pPr.Ind.Left != Item_pPr.Ind.Left)
                apPr.push("margin-left:" + (Item_pPr.Ind.Left * g_dKoef_mm_to_pt) + "pt");
            if(Def_pPr.Ind.Right != Item_pPr.Ind.Right)
                apPr.push("margin-right:" + ( Item_pPr.Ind.Right * g_dKoef_mm_to_pt) + "pt");
            if(Def_pPr.Ind.FirstLine != Item_pPr.Ind.FirstLine)
                apPr.push("text-indent:" + (Item_pPr.Ind.FirstLine * g_dKoef_mm_to_pt) + "pt");
            //Jc
            if(Def_pPr.Jc != Item_pPr.Jc){
                switch(Item_pPr.Jc)
                {
                    case align_Left: apPr.push("text-align:left");break;
                    case align_Center: apPr.push("text-align:center");break;
                    case align_Right: apPr.push("text-align:right");break;
                    case align_Justify: apPr.push("text-align:justify");break;
                }
            }
            //KeepLines , WidowControl
            if(Def_pPr.KeepLines != Item_pPr.KeepLines || Def_pPr.WidowControl != Item_pPr.WidowControl)
            {
                if(Def_pPr.KeepLines != Item_pPr.KeepLines && Def_pPr.WidowControl != Item_pPr.WidowControl)
                    apPr.push("mso-pagination:none lines-together");
                else if(Def_pPr.KeepLines != Item_pPr.KeepLines)
                    apPr.push("mso-pagination:widow-orphan lines-together");
                else if(Def_pPr.WidowControl != Item_pPr.WidowControl)
                    apPr.push("mso-pagination:none");
            }
            //KeepNext
            if(Def_pPr.KeepNext != Item_pPr.KeepNext)
                apPr.push("page-break-after:avoid");
            //PageBreakBefore
            if(Def_pPr.PageBreakBefore != Item_pPr.PageBreakBefore)
                apPr.push("page-break-before:always");
            //Spacing
            if(Def_pPr.Spacing.Line != Item_pPr.Spacing.Line)
            {
                if(linerule_AtLeast == Item_pPr.Spacing.LineRule)
                    apPr.push("line-height:"+(Item_pPr.Spacing.Line * g_dKoef_mm_to_pt)+"pt");
                else if( linerule_Auto == Item_pPr.Spacing.LineRule)
                {
                    if(1 == Item_pPr.Spacing.Line)
                        apPr.push("line-height:normal");
                    else
                        apPr.push("line-height:"+parseInt(Item_pPr.Spacing.Line * 100)+"%");
                }
            }
            if(Def_pPr.Spacing.LineRule != Item_pPr.Spacing.LineRule)
            {
                if(linerule_Exact == Item_pPr.Spacing.LineRule)
                    apPr.push("mso-line-height-rule:exactly");
            }
456
			//TODO при вставке в EXCEL(внутрь ячейки) появляются лишние пустые строки из-за того, что в HTML пишутся отступы - BUG #14663
457 458 459 460 461 462
            //��� ������� � word ����� ����� ��� �������� ������������ ������
            //if(Def_pPr.Spacing.Before != Item_pPr.Spacing.Before)
            apPr.push("margin-top:" + (Item_pPr.Spacing.Before * g_dKoef_mm_to_pt) + "pt");
            //if(Def_pPr.Spacing.After != Item_pPr.Spacing.After)
            apPr.push("margin-bottom:" + (Item_pPr.Spacing.After * g_dKoef_mm_to_pt) + "pt");
            //Shd
463 464
            if (null != Item_pPr.Shd && shd_Nil != Item_pPr.Shd.Value && (null != Item_pPr.Shd.Color || null != Item_pPr.Shd.Unifill))
                apPr.push("background-color:" + this.RGBToCSS(Item_pPr.Shd.Color, Item_pPr.Shd.Unifill));
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481
            //Tabs
            if(Item_pPr.Tabs.Get_Count() > 0)
            {
                var sRes = "";
                //tab-stops:1.0cm 3.0cm 5.0cm
                for(var i = 0, length = Item_pPr.Tabs.Get_Count(); i < length; i++)
                {
                    if(0 != i)
                        sRes += " ";
                    sRes += Item_pPr.Tabs.Get(i).Pos / 10 + "cm";
                }
                apPr.push("tab-stops:" + sRes);
            }
            //Border
            if(null != Item_pPr.Brd)
            {
                apPr.push("border:none");
482
                var borderStyle = this._BordersToStyle(Item_pPr.Brd, false, true, "mso-", "-alt");
483 484 485 486 487 488 489 490 491 492 493 494
                if(null != borderStyle)
                {
                    var nborderStyleLength = borderStyle.length;
                    if(nborderStyleLength> 0)
                        borderStyle = borderStyle.substring(0, nborderStyleLength - 1);
                    apPr.push(borderStyle);
                }
            }
        }
        if(apPr.length > 0)
            this.Para.setAttribute("style", apPr.join(';'));
    },
495
    parse_para_TextPr : function(Value)
496
    {
497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516
        var aProp = [];
        var aTagStart = [];
        var aTagEnd = [];
        var sRes = "";
        if (null != Value.RFonts) {
            var sFontName = null;
            if (null != Value.RFonts.Ascii)
                sFontName = Value.RFonts.Ascii.Name;
            else if (null != Value.RFonts.HAnsi)
                sFontName = Value.RFonts.HAnsi.Name;
            else if (null != Value.RFonts.EastAsia)
                sFontName = Value.RFonts.EastAsia.Name;
            else if (null != Value.RFonts.CS)
                sFontName = Value.RFonts.CS.Name;
            if (null != sFontName)
                aProp.push("font-family:" + "'" + CopyPasteCorrectString(sFontName) + "'");
        }
        if (null != Value.FontSize) {
            if (!this.api.DocumentReaderMode)
                aProp.push("font-size:" + Value.FontSize + "pt");//font-size � pt ��� ��������� ������� � mm
517
            else
518
                aProp.push("font-size:" + this.api.DocumentReaderMode.CorrectFontSize(Value.FontSize));
519
        }
520 521 522
        if (true == Value.Bold) {
            aTagStart.push("<b>");
            aTagEnd.push("</b>");
523
        }
524 525 526 527 528 529 530 531
        if (true == Value.Italic) {
            aTagStart.push("<i>");
            aTagEnd.push("</i>");
        }
        if (true == Value.Strikeout) {
            aTagStart.push("<u>");
            aTagEnd.push("</u>");
        }
532 533 534 535 536
        if (null != Value.Shd && shd_Nil != Value.Shd.Value && (null != Value.Shd.Color || null != Value.Shd.Unifill))
            aProp.push("background-color:" + this.RGBToCSS(Value.Shd.Color, Value.Shd.Unifill));
        else if (null != Value.HighLight && highlight_None != Value.HighLight)
            aProp.push("background-color:" + this.RGBToCSS(Value.HighLight, null));
        if (null != Value.Color || null != Value.Unifill) {
537 538 539 540 541 542 543
			var color;
			//TODO правка того, что в полученной html цвет текста всегда чёрный. стоит пересмотреть.
			if(null != Value.Unifill)
				color = this.RGBToCSS(null, Value.Unifill);
			else
				color = this.RGBToCSS(Value.Color, Value.Unifill);
   
544 545
            aProp.push("color:" + color);
            aProp.push("mso-style-textfill-fill-color:" + color);
546
        }
547 548 549 550 551 552 553 554
        if (null != Value.VertAlign) {
            if(vertalign_SuperScript == Value.VertAlign)
                aProp.push("vertical-align:super");
            else if(vertalign_SubScript == Value.VertAlign)
                aProp.push("vertical-align:sub");
        }

        return { style: aProp.join(';'), tagstart: aTagStart.join(''), tagend: aTagEnd.join('') };
555
    },
556
    ParseItem : function(ParaItem)
557
    {
558
        var sRes = "";
559 560 561 562
        switch ( ParaItem.Type )
        {
            case para_Text:
                //���������� �����������
563
                var sValue = String.fromCharCode(ParaItem.Value);
564
                if(sValue)
565
                    sRes += CopyPasteCorrectString(sValue);
566
                break;
567
            case para_Space:    sRes += " "; break;
568
			case para_Tab: sRes += "<span style='white-space:pre;'>" + String.fromCharCode(0x09) + "</span>"; break;
569 570 571 572
            case para_NewLine:
                if( break_Page == ParaItem.BreakType)
                {
                    //todo ��������� ���� �������� � ������ �����
573
                    sRes += "<br clear=\"all\" style=\"mso-special-character:line-break;page-break-before:always;\" />";
574 575
                }
                else
576
                    sRes += "<br style=\"mso-special-character:line-break;\" />";
577 578 579 580 581 582 583 584 585
                break;
            //������� ������� ����� ��������� ������ �� ���������� ��������
            case para_End:        this.bOccurEndPar = true; break;
            case para_Drawing:
                var oGraphicObj = ParaItem.GraphicObj;
                var sSrc = oGraphicObj.getBase64Img();
                if(sSrc.length > 0)
                {
                    sSrc = this.getSrc(sSrc);
586
                    sRes += "<img style=\"max-width:100%;\" width=\""+Math.round(ParaItem.W * g_dKoef_mm_to_pix)+"\" height=\""+Math.round(ParaItem.H * g_dKoef_mm_to_pix)+"\" src=\""+sSrc+"\" />";
Oleg.Korshul's avatar
Oleg.Korshul committed
587
                    break;
588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625
                }
                // var _canvas     = document.createElement('canvas');
                // var w = img.width;
                // var h = img.height;

                // _canvas.width   = w;
                // _canvas.height  = h;

                // var _ctx        = _canvas.getContext('2d');
                // _ctx.globalCompositeOperation = "copy";
                // _ctx.drawImage(img, 0, 0);

                // var _data = _ctx.getImageData(0, 0, w, h);
                // _ctx = null;
                // delete _canvas;
                break;
            case para_FlowObjectAnchor:
                var oFlowObj = ParaItem.FlowObject;
                if(flowobject_Image == oFlowObj.Get_Type())
                {
                    var sSrc = oFlowObj.Img;
                    if(sSrc.length > 0)
                    {
                        sSrc = this.getSrc(sSrc);
						var sStyle = "";
						var nLeft = oFlowObj.X;
						var nRight = nLeft + oFlowObj.W;
						if(Math.abs(nLeft - X_Left_Margin) < Math.abs(Page_Width - nRight - X_Right_Margin))
							sStyle = "float:left;";
						else
							sStyle = "float:right;";
						if(!this.api.DocumentReaderMode)
						{
							if(null != oFlowObj.Paddings)
								sStyle += "margin:" + (oFlowObj.Paddings.Top * g_dKoef_mm_to_pt) + "pt " + (oFlowObj.Paddings.Right * g_dKoef_mm_to_pt) + "pt " +  + (oFlowObj.Paddings.Bottom * g_dKoef_mm_to_pt) + "pt " + + (oFlowObj.Paddings.Left * g_dKoef_mm_to_pt) + "pt;";
						}
						else
							sStyle += "margin:0pt 10pt 0pt 10pt;";
Oleg.Korshul's avatar
Oleg.Korshul committed
626 627 628 629

                        if (this.api.DocumentReaderMode)
                            sStyle += "max-width:100%;";

630
                        sRes += "<img style=\""+sStyle+"\" width=\""+Math.round(oFlowObj.W * g_dKoef_mm_to_pix)+"\" height=\""+Math.round(oFlowObj.H * g_dKoef_mm_to_pix)+"\" src=\""+sSrc+"\" />"; break;
631 632 633
                    }
                }
                break;
634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653
        }
        return sRes;
    },
    CopyRun: function (Item, bUseSelection) {
        var sRes = "";
        var ParaStart = 0;
        var ParaEnd = Item.Content.length;
        if (true == bUseSelection) {
            ParaStart = Item.Selection.StartPos;
            ParaEnd = Item.Selection.EndPos;
            if (ParaStart > ParaEnd) {
                var Temp2 = ParaEnd;
                ParaEnd = ParaStart;
                ParaStart = Temp2;
            }
        }
        for (var i = ParaStart; i < ParaEnd; i++)
            sRes += this.ParseItem(Item.Content[i]);
        return sRes;
    },
654
    CopyRunContent: function (Container, bUseSelection, bOmitHyperlink) {
655 656 657 658 659 660 661 662 663 664 665
        var sRes = "";
        var ParaStart = 0;
        var ParaEnd = Container.Content.length - 1;
        if (true == bUseSelection) {
            ParaStart = Container.Selection.StartPos;
            ParaEnd = Container.Selection.EndPos;
            if (ParaStart > ParaEnd) {
                var Temp2 = ParaEnd;
                ParaEnd = ParaStart;
                ParaStart = Temp2;
            }
666
        };
667

668 669 670 671 672 673
		//TODO Стоит пересмотреть флаг bUseSelection и учитывать внутри Selection флаг use.
		if(ParaEnd < 0)
			ParaEnd = 0;
		if(ParaStart < 0)
			ParaStart = 0;	
		
674 675 676 677 678
        for (var i = ParaStart; i <= ParaEnd; i++) {
            var item = Container.Content[i];
            if (para_Run == item.Type) {
                var sRunContent = this.CopyRun(item, bUseSelection);
                if(sRunContent)
679
                {
680 681 682 683 684 685 686 687 688 689 690
                    sRes += "<span";
                    var oStyle = this.parse_para_TextPr(item.CompiledPr);
                    if (oStyle && oStyle.style)
                        sRes += " style=\"" + oStyle.style + "\"";
                    sRes += ">";
                    if (oStyle.tagstart)
                        sRes += oStyle.tagstart;
                    sRes += sRunContent;
                    if (oStyle.tagend)
                        sRes += oStyle.tagend;
                    sRes += "</span>";
691
                }
692 693
            }
            else if (para_Hyperlink == item.Type) {
694 695 696 697 698 699 700 701 702 703 704 705 706 707
                if (!bOmitHyperlink) {
                    sRes += "<a";
                    var sValue = item.Get_Value();
                    var sToolTip = item.Get_ToolTip();
                    if (null != sValue && "" != sValue)
                        sRes += " href=\"" + CopyPasteCorrectString(sValue) + "\"";
                    if (null != sToolTip && "" != sToolTip)
                        sRes += " title=\"" + CopyPasteCorrectString(sToolTip) + "\"";
                    sRes += ">";
                }
                //вложенные ссылки в html запрещены.
                sRes += this.CopyRunContent(item, bUseSelection, true);
                if (!bOmitHyperlink)
                    sRes += "</a>";
708
            }
709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725
			else if(para_Math == item.Type){
                var sSrc = item.MathToImageConverter();
				var width = item.Width;
				var height = item.Height;
				
				sRes += "<img";
				
                if (null != width && "" != width)
                    sRes += " width=\"" + width + "\"";
                if (null != height && "" != height)
                    sRes += " height=\"" + height + "\"";
				if (null != sSrc && "" != sSrc && null != sSrc.ImageUrl)
                    sRes += " src=\"" + sSrc.ImageUrl + "\"";
				
                sRes += ">";
                sRes += "</img>";
			}
726
        }
727
        return sRes;
728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834
    },
    CopyParagraph : function(oDomTarget, Item, bLast, bUseSelection, aDocumentContent, nDocumentContentIndex)
    {
        var oDocument = this.oDocument;
        this.Para = null;
        //��� heading ����� � h1
        var styleId = Item.Style_Get();
        if(styleId)
        {
            var styleName = oDocument.Styles.Get_Name( styleId ).toLowerCase();
            //������ "heading n" (n=1:6)
            if(0 == styleName.indexOf("heading"))
            {
                var nLevel = parseInt(styleName.substring("heading".length));
                if(1 <= nLevel && nLevel <= 6)
                    this.Para = document.createElement( "h" + nLevel );
            }
        }
        if(null == this.Para)
            this.Para = document.createElement( "p" );

        this.bOccurEndPar = false;
        var oNumPr;
        var bIsNullNumPr = false;
        if(g_bIsDocumentCopyPaste)
        {
            oNumPr = Item.Numbering_Get();
            bIsNullNumPr = (null == oNumPr || 0 == oNumPr.NumId);
        }
        else
        {
            oNumPr = Item.PresentationPr.Bullet;
            bIsNullNumPr = (0 == oNumPr.m_nType);
        }
        if(bIsNullNumPr)
            this.CommitList(oDomTarget);
        else
        {
            var bBullet = false;
            var sListStyle = "";
            if(g_bIsDocumentCopyPaste)
            {
				var aNum = this.oDocument.Numbering.Get_AbstractNum( oNumPr.NumId );
				if(null != aNum)
				{
					var LvlPr = aNum.Lvl[oNumPr.Lvl];
					if(null != LvlPr)
					{
						switch(LvlPr.Format)
						{
							case numbering_numfmt_Decimal: sListStyle = "decimal";break;
							case numbering_numfmt_LowerRoman: sListStyle = "lower-roman";break;
							case numbering_numfmt_UpperRoman: sListStyle = "upper-roman";break;
							case numbering_numfmt_LowerLetter: sListStyle = "lower-alpha";break;
							case numbering_numfmt_UpperLetter: sListStyle = "upper-alpha";break;
							default:
								sListStyle = "disc";
								bBullet = true;
								break;
						}
					}
				}
            }
            else
            {
                var _presentation_bullet = Item.PresentationPr.Bullet;
                switch(_presentation_bullet.m_nType)
                {
                    case numbering_presentationnumfrmt_ArabicPeriod:
                    case numbering_presentationnumfrmt_ArabicParenR:
                    {
                        sListStyle = "decimal";
                        break;
                    }
                    case numbering_presentationnumfrmt_RomanLcPeriod: sListStyle = "lower-roman";break;
                    case numbering_presentationnumfrmt_RomanUcPeriod: sListStyle = "upper-roman";break;

                    case numbering_presentationnumfrmt_AlphaLcParenR:
                    case numbering_presentationnumfrmt_AlphaLcPeriod:
                    {
                        sListStyle = "lower-alpha";
                        break;
                    }
                    case numbering_presentationnumfrmt_AlphaUcParenR:
                    case numbering_presentationnumfrmt_AlphaUcPeriod:
                    {
                        sListStyle = "upper-alpha";
                        break;
                    }

                    default:
                        sListStyle = "disc";
                        bBullet = true;
                        break;
                }
            }
            var Li = document.createElement( "li" );
            Li.setAttribute("style", "list-style-type: " + sListStyle);
            Li.appendChild( this.Para );
            if(bBullet)
                this.Ul.appendChild( Li );
            else
                this.Ol.appendChild( Li );
        }
        //pPr
        this.Commit_pPr(Item);

835
        this.Para.innerHTML = this.CopyRunContent(Item, bUseSelection, false);
836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866

        if(bLast && false == this.bOccurEndPar)
        {
            if(false == bIsNullNumPr)
            {
                //������ �������� � ������. ������� ������� �� ������. ���������� ����� ��� span
                var li = this.Para.parentNode;
                var ul = li.parentNode;
                ul.removeChild(li);
                this.CommitList(oDomTarget);
            }
            for(var i = 0; i < this.Para.childNodes.length; i++)
                oDomTarget.appendChild( this.Para.childNodes[i].cloneNode(true) );
        }
        else
        {
            //����� ��������� ������ ���������
            if(this.Para.childNodes.length == 0)
                this.Para.appendChild( document.createTextNode( '\xa0' ) );
            if(bIsNullNumPr)
                oDomTarget.appendChild( this.Para );
        }
    },
    _BorderToStyle : function(border, name)
    {
        var res = "";
        if(border_None == border.Value)
            res += name + ":none;";
        else
        {
            var size = 0.5;
867 868
            var color = border.Color;
            var unifill = border.Unifill;
869 870
            if(null != border.Size)
                size = border.Size * g_dKoef_mm_to_pt;
871 872 873
            if (null == color)
                color = { r: 0, g: 0, b: 0 };
            res += name + ":" + size + "pt solid " + this.RGBToCSS(color, unifill) + ";";
874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894
        }
        return res;
    },
    _MarginToStyle : function(margins, styleName)
    {
        var res = "";
        var nMarginLeft = 1.9;
        var nMarginTop = 0;
        var nMarginRight = 1.9;
        var nMarginBottom = 0;
        if(null != margins.Left && tblwidth_Mm == margins.Left.Type && null != margins.Left.W)
            nMarginLeft = margins.Left.W;
        if(null != margins.Top && tblwidth_Mm == margins.Top.Type && null != margins.Top.W)
            nMarginTop = margins.Top.W;
        if(null != margins.Right && tblwidth_Mm == margins.Right.Type && null != margins.Right.W)
            nMarginRight = margins.Right.W;
        if(null != margins.Bottom && tblwidth_Mm == margins.Bottom.Type && null != margins.Bottom.W)
            nMarginBottom = margins.Bottom.W;
        res = styleName + ":"+(nMarginTop * g_dKoef_mm_to_pt)+"pt "+(nMarginRight * g_dKoef_mm_to_pt)+"pt "+(nMarginBottom * g_dKoef_mm_to_pt)+"pt "+(nMarginLeft * g_dKoef_mm_to_pt)+"pt;";
        return res;
    },
895
    _BordersToStyle : function(borders, bUseInner, bUseBetween, mso, alt)
896 897 898 899 900 901 902 903 904 905 906 907 908 909
    {
        var res = "";
        if(null == mso)
            mso = "";
        if(null == alt)
            alt = "";
        if(null != borders.Left)
            res += this._BorderToStyle(borders.Left, mso + "border-left" + alt);
        if(null != borders.Top)
            res += this._BorderToStyle(borders.Top, mso + "border-top" + alt);
        if(null != borders.Right)
            res += this._BorderToStyle(borders.Right, mso + "border-right" + alt);
        if(null != borders.Bottom)
            res += this._BorderToStyle(borders.Bottom, mso + "border-bottom" + alt);
910 911 912 913 914 915 916 917 918 919 920 921
		if(bUseInner)
		{
			if(null != borders.InsideV)
				res += this._BorderToStyle(borders.InsideV, "mso-border-insidev");
			if(null != borders.InsideH)
				res += this._BorderToStyle(borders.InsideH, "mso-border-insideh");
		}
		if(bUseBetween)
		{
			if(null != borders.Between)
				res += this._BorderToStyle(borders.Between, "mso-border-between");
		}
922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963
        return res;
    },
    _MergeProp : function(elem1, elem2)
    {
        if( !elem1 || !elem2 )
        {
            return;
        }

        var p, v;
        for(p in elem2)
        {
            if(elem2.hasOwnProperty(p) && false == elem1.hasOwnProperty(p))
            {
                v = elem2[p];
                if(null != v)
                    elem1[p] = v;
            }
        }
    },
    CopyCell : function(tr, cell, tablePr, width, rowspan)
    {
        var tc = document.createElement( "td" );
        //Pr
        var tcStyle = "";
        if(width > 0)
        {
            tc.setAttribute("width", Math.round(width * g_dKoef_mm_to_pix));
            tcStyle += "width:"+(width * g_dKoef_mm_to_pt)+"pt;";
        }
        if(rowspan > 1)
            tc.setAttribute("rowspan", rowspan);
        var cellPr = null;
        if(null != cell.CompiledPr && null != cell.CompiledPr.Pr)
        {
            cellPr = cell.CompiledPr.Pr;
            //��� ������ � �������� ����� ������������ margin � �� colspan
            if(null != cellPr.GridSpan && cellPr.GridSpan > 1)
                tc.setAttribute("colspan", cellPr.GridSpan);
        }
        if(null != cellPr && null != cellPr.Shd)
        {
964 965
            if (shd_Nil != cellPr.Shd.Value && (null != cellPr.Shd.Color || null != cellPr.Shd.Unifill))
                tcStyle += "background-color:" + this.RGBToCSS(cellPr.Shd.Color, cellPr.Shd.Unifill) + ";";
966 967 968
        }
        else if(null != tablePr && null != tablePr.Shd)
        {
969 970
            if (shd_Nil != tablePr.Shd.Value && (null != tablePr.Shd.Color || null != tablePr.Shd.Unifill))
                tcStyle += "background-color:" + this.RGBToCSS(tablePr.Shd.Color, tablePr.Shd.Unifill) + ";";
971
        }
Alexander.Trofimov's avatar
Alexander.Trofimov committed
972
        var oCellMar = {};
973 974 975 976 977 978
        if(null != cellPr && null != cellPr.TableCellMar)
            this._MergeProp(oCellMar, cellPr.TableCellMar);
        if(null != tablePr && null != tablePr.TableCellMar)
            this._MergeProp(oCellMar, tablePr.TableCellMar);
        tcStyle += this._MarginToStyle(oCellMar, "padding");

Alexander.Trofimov's avatar
Alexander.Trofimov committed
979
        var oCellBorder = {};
980 981 982 983
        if(null != cellPr && null != cellPr.TableCellBorders)
            this._MergeProp(oCellBorder, cellPr.TableCellBorders);
        if(null != tablePr && null != tablePr.TableBorders)
            this._MergeProp(oCellBorder, tablePr.TableBorders);
984
        tcStyle += this._BordersToStyle(oCellBorder, false, false);
985 986 987 988 989 990 991 992

        if("" != tcStyle)
            tc.setAttribute("style", tcStyle);
        //Content
        this.CopyDocument(tc, cell.Content, false);

        tr.appendChild(tc);
    },
993
    CopyRow : function(oDomTarget, table, nCurRow, elems, nMaxRow)
994 995
    {
        var row = table.Content[nCurRow];
996
		if(null == elems)
997
			elems = {gridStart: 0, gridEnd: table.TableGrid.length - 1, indexStart: null, indexEnd: null, after: null, before: null, cells: row.Content};
998 999
        var tr = document.createElement( "tr" );
        //Pr
1000
		var gridSum = table.TableSumGrid;
1001 1002 1003 1004 1005 1006 1007
        var trStyle = "";
        var nGridBefore = 0;
		var rowPr = null;
		if(null != row.CompiledPr && null != row.CompiledPr.Pr)
			rowPr = row.CompiledPr.Pr;
        if(null != rowPr)
        {
1008 1009 1010 1011 1012 1013 1014 1015 1016 1017
			if(null == elems.before && null != rowPr.GridBefore && rowPr.GridBefore > 0)
			{
                elems.before = rowPr.GridBefore;
				elems.gridStart += rowPr.GridBefore;
			}
			if(null == elems.after && null != rowPr.GridAfter && rowPr.GridAfter > 0)
			{
                elems.after = rowPr.GridAfter;
				elems.gridEnd -= rowPr.GridAfter;
			}
1018 1019 1020
            //height
            if(null != rowPr.Height && heightrule_Auto != rowPr.Height.HRule && null != rowPr.Height.Value)
            {
1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043
                trStyle += "height:"+(rowPr.Height.Value * g_dKoef_mm_to_pt)+"pt;";
            }
        }
		//WBefore
        if(null != elems.before)
        {
            if(elems.before > 0)
            {
                nGridBefore = elems.before;
                var nWBefore = gridSum[elems.gridStart - 1] - gridSum[elems.gridStart - nGridBefore - 1];
                //���������� margin
                trStyle += "mso-row-margin-left:"+(nWBefore * g_dKoef_mm_to_pt)+"pt;";
                //��������� td ��� ��� ��� �� �������� mso-row-margin-left
                var oNewTd = document.createElement( "td" );
                oNewTd.setAttribute("style", "mso-cell-special:placeholder;border:none;padding:0cm 0cm 0cm 0cm");
                oNewTd.setAttribute("width", Math.round(nWBefore * g_dKoef_mm_to_pix));
                if(nGridBefore > 1)
                    oNewTd.setAttribute("colspan", nGridBefore);
                var oNewP = document.createElement( "p" );
				oNewP.setAttribute("style", "margin:0cm");
                oNewP.appendChild(document.createTextNode( '\xa0' ));
                oNewTd.appendChild(oNewP);
                tr.appendChild(oNewTd);
1044 1045 1046
            }
        }
        //tc
1047
        for(var i in elems.cells)
1048 1049
        {
            var cell = row.Content[i];
1050
			if(vmerge_Continue != cell.Get_VMerge())
1051
			{
1052 1053 1054 1055 1056 1057
				var StartGridCol = cell.Metrics.StartGridCol;
				var GridSpan = cell.Get_GridSpan();
				var width = gridSum[StartGridCol + GridSpan - 1] - gridSum[StartGridCol - 1];
				//��������� rowspan
				var nRowSpan = table.Internal_GetVertMergeCount(nCurRow, StartGridCol, GridSpan);
				if(nCurRow + nRowSpan - 1 > nMaxRow)
1058
				{
1059 1060 1061
					nRowSpan = nMaxRow - nCurRow + 1;
					if(nRowSpan <= 0)
						nRowSpan = 1;
1062
				}
1063 1064 1065 1066 1067
				var tablePr = null;
				if(null != table.CompiledPr && null != table.CompiledPr.Pr && null != table.CompiledPr.Pr.TablePr)
					tablePr = table.CompiledPr.Pr.TablePr;
				this.CopyCell(tr, cell, tablePr, width, nRowSpan);
			}
1068 1069
        }
        //WAfter
1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088
        if(null != elems.after)
        {
            if(elems.after > 0)
            {
                var nGridAfter = elems.after;
                var nWAfter = gridSum[elems.gridEnd + nGridAfter] - gridSum[elems.gridEnd];
                //���������� margin
                trStyle += "mso-row-margin-right:"+(nWAfter * g_dKoef_mm_to_pt)+"pt;";
                //��������� td ��� ��� ��� �� �������� mso-row-margin-left
                var oNewTd = document.createElement( "td" );
                oNewTd.setAttribute("style", "mso-cell-special:placeholder;border:none;padding:0cm 0cm 0cm 0cm");
                oNewTd.setAttribute("width", Math.round(nWAfter * g_dKoef_mm_to_pix));
                if(nGridAfter > 1)
                    oNewTd.setAttribute("colspan", nGridAfter);
                var oNewP = document.createElement( "p" );
				oNewP.setAttribute("style", "margin:0cm");
                oNewP.appendChild(document.createTextNode( '\xa0' ));
                oNewTd.appendChild(oNewP);
                tr.appendChild(oNewTd);
1089 1090
            }
        }
1091 1092 1093
        if("" != trStyle)
            tr.setAttribute("style", trStyle);
			
1094 1095
        oDomTarget.appendChild(tr);
    },
1096
    CopyTable : function(oDomTarget, table, aRowElems)
1097 1098 1099 1100 1101 1102 1103 1104 1105 1106
    {
        this.CommitList(oDomTarget);
        var DomTable = document.createElement( "table" );
        var Pr = null;
        if(null != table.CompiledPr && null != table.CompiledPr.Pr && null != table.CompiledPr.Pr.TablePr)
            Pr = table.CompiledPr.Pr.TablePr;
        var tblStyle = "";
        var bBorder = false;
        if(null != Pr)
        {
1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137
			var align = "";
            if(true != table.Inline && null != table.PositionH)
			{
				var PositionH = table.PositionH;
				if(true == PositionH.Align)
				{
					switch(PositionH.Value)
					{
						case c_oAscXAlign.Outside:
						case c_oAscXAlign.Right: align = "right";break;
						case c_oAscXAlign.Center: align = "center";break;
					}
				}
				else if(table.TableSumGrid)
				{
					var TableWidth = table.TableSumGrid[ table.TableSumGrid.length - 1 ];
					var nLeft = PositionH.Value;
					var nRight = nLeft + TableWidth;
					var nFromLeft = Math.abs(nLeft - X_Left_Margin);
					var nFromCenter = Math.abs((Page_Width - X_Right_Margin + X_Left_Margin) / 2 - (nLeft + nRight) / 2);
					var nFromRight = Math.abs(Page_Width - nRight - X_Right_Margin);
					if(nFromRight < nFromLeft || nFromCenter < nFromLeft)
					{
						if(nFromRight < nFromCenter)
							align = "right";
						else
							align = "center";
					}
				}
			}
			else if(null != Pr.Jc)
1138 1139 1140 1141 1142 1143 1144
            {
                switch(Pr.Jc)
                {
                    case align_Center:align = "center";break;
                    case align_Right:align = "right";break;
                }
            }
1145 1146
			if("" != align)
				DomTable.setAttribute("align", align);
1147 1148
            if(null != Pr.TableInd)
                tblStyle += "margin-left:"+(Pr.TableInd * g_dKoef_mm_to_pt)+"pt;";
1149 1150
            if (null != Pr.Shd && shd_Nil != Pr.Shd.Value && (null != Pr.Shd.Color || null != Pr.Shd.Unifill))
                tblStyle += "background:" + this.RGBToCSS(Pr.Shd.Color, Pr.Shd.Unifill) + ";";
1151 1152 1153
            if(null != Pr.TableCellMar)
                tblStyle += this._MarginToStyle(Pr.TableCellMar, "mso-padding-alt");
            if(null != Pr.TableBorders)
1154
                tblStyle += this._BordersToStyle(Pr.TableBorders, true, false);
1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176
        }
        //���� cellSpacing
        var bAddSpacing = false;
        if(table.Content.length > 0)
        {
            var firstRow = table.Content[0];
            if(null != firstRow.Pr && null != firstRow.Pr.TableCellSpacing)
            {
                bAddSpacing = true;
                var cellSpacingMM = firstRow.Pr.TableCellSpacing;
                tblStyle += "mso-cellspacing:"+(cellSpacingMM * g_dKoef_mm_to_pt)+"pt;";
                DomTable.setAttribute("cellspacing", Math.round(cellSpacingMM * g_dKoef_mm_to_pix));
            }
        }
        if(!bAddSpacing)
            DomTable.setAttribute("cellspacing", 0);
        DomTable.setAttribute("border", false == bBorder ? 0 : 1);
        DomTable.setAttribute("cellpadding", 0);
        if("" != tblStyle)
            DomTable.setAttribute("style", tblStyle);

        //rows
1177
		if(null == aRowElems)
1178 1179 1180 1181 1182 1183 1184
		{
			for(var i = 0, length = table.Content.length; i < length; i++)
				this.CopyRow(DomTable, table, i , null, table.Content.length - 1);
		}
		else
		{
			var nMaxRow = 0;
1185
			for(var i = 0, length = aRowElems.length; i < length; ++i)
1186
			{
1187 1188 1189 1190 1191 1192 1193 1194
				var elem = aRowElems[i];
				if(elem.row > nMaxRow)
					nMaxRow = elem.row;
			}
			for(var i = 0, length = aRowElems.length; i < length; ++i)
			{
				var elem = aRowElems[i];
				this.CopyRow(DomTable, table, elem.row, elem, nMaxRow);
1195 1196
			}
		}
1197

1198
        oDomTarget.appendChild(DomTable);
1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209
    },
    CopyDocument : function(oDomTarget, oDocument, bUseSelection)
    {
        var Start = 0;
        var End = 0;
        if(bUseSelection)
        {
            if ( true === oDocument.Selection.Use)
            {
                if ( selectionflag_DrawingObject === oDocument.Selection.Flag )
                {
1210 1211
                    this.Para = document.createElement("p");
                    this.Para.innerHTML = this.ParseItem(oDocument.Selection.Data.DrawingObject);
1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259

                    for(var i = 0; i < this.Para.childNodes.length; i++)
                        this.ElemToSelect.appendChild( this.Para.childNodes[i].cloneNode(true) );
                }
                else
                {
                    Start = oDocument.Selection.StartPos;
                    End = oDocument.Selection.EndPos;
                    if ( Start > End )
                    {
                        var Temp = End;
                        End = Start;
                        Start = Temp;
                    }
                }
            }
        }
        else
        {
            Start = 0;
            End = oDocument.Content.length - 1;
        }
        // HtmlText
        for ( var Index = Start; Index <= End; Index++ )
        {
            var Item = oDocument.Content[Index];
            if(type_Table === Item.GetType() )
            {
                if(bUseSelection)
                {
                    if(table_Selection_Text == Item.Selection.Type)
                    {
                        //������� ����� � ������.
                        var rowIndex = Item.Selection.StartPos.Pos.Row;
                        var colIndex = Item.Selection.StartPos.Pos.Cell;
                        if(rowIndex < Item.Content.length)
                        {
                            var row = Item.Content[rowIndex];
                            if(colIndex < row.Content.length)
                            {
                                var cell = row.Content[colIndex];
                                this.CopyDocument(oDomTarget, cell.Content, bUseSelection);
                            }
                        }
                    }
                    else if(table_Selection_Cell == Item.Selection.Type)
                    {
                        //������� �������� �����
Alexander.Trofimov's avatar
Alexander.Trofimov committed
1260
						var aSelectedRows = [];
Alexander.Trofimov's avatar
Alexander.Trofimov committed
1261
						var oRowElems = {};
1262
						if(Item.Selection.Data.length > 0)
1263
						{
1264 1265 1266 1267 1268 1269
							for(var i = 0, length = Item.Selection.Data.length; i < length; ++i)
							{
								var elem = Item.Selection.Data[i];
								var rowElem = oRowElems[elem.Row];
								if(null == rowElem)
								{
1270
									rowElem = {row: elem.Row, gridStart: null, gridEnd: null, indexStart: null, indexEnd: null, after: null, before: null, cells: {}};
1271
									oRowElems[elem.Row] = rowElem;
1272
									aSelectedRows.push(rowElem);
1273 1274 1275 1276 1277 1278 1279 1280
								}
								if(null == rowElem.indexEnd || elem.Cell > rowElem.indexEnd)
									rowElem.indexEnd = elem.Cell;
								if(null == rowElem.indexStart || elem.Cell < rowElem.indexStart)
									rowElem.indexStart = elem.Cell;
								rowElem.cells[elem.Cell] = 1;
							}
						}
1281 1282 1283
						aSelectedRows.sort(function(a,b){
							return a.row - b.row;
						});
1284 1285 1286
						var nMinGrid = null;
						var nMaxGrid = null;
						var nPrevStartGrid = null;
1287
						var nPrevEndGrid = null;
1288 1289 1290
						var nPrevRowIndex = null;
						for(var i = 0, length = aSelectedRows.length; i < length; ++i)
						{
1291 1292
							var elem = aSelectedRows[i];
							var nRowIndex = elem.row;
1293 1294 1295 1296 1297 1298 1299
							if(null != nPrevRowIndex)
							{
								if(nPrevRowIndex + 1 != nRowIndex)
								{
									nMinGrid = null;
									nMaxGrid = null;
									break;
1300 1301
								}
							}
1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319
							nPrevRowIndex = nRowIndex;
							var row = Item.Content[nRowIndex];
							var cellFirst = row.Get_Cell(elem.indexStart);
							var cellLast = row.Get_Cell(elem.indexEnd);
							var nCurStartGrid = cellFirst.Metrics.StartGridCol;
							var nCurEndGrid = cellLast.Metrics.StartGridCol + cellLast.Get_GridSpan() - 1;
							if(null != nPrevStartGrid && null != nPrevEndGrid)
							{
								//учитываем вертикальный merge, раздвигаем границы
								if(nCurStartGrid > nPrevStartGrid)
								{
									for(var j = elem.indexStart - 1; j >= 0; --j)
									{
										var cellCur = row.Get_Cell(j);
										if(vmerge_Continue == cellCur.Get_VMerge())
										{
											var nCurGridCol = cellCur.Metrics.StartGridCol;
											if(nCurGridCol >= nPrevStartGrid)
1320
											{
1321
												nCurStartGrid = nCurGridCol;
1322 1323
												elem.indexStart = j;
											}
1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339
											else
												break;
										}
										else
											break;
									}
								}
								if(nCurEndGrid < nPrevEndGrid)
								{
									for(var j = elem.indexEnd + 1; j < row.Get_CellsCount(); ++j)
									{
										var cellCur = row.Get_Cell(j);
										if(vmerge_Continue == cellCur.Get_VMerge())
										{
											var nCurGridCol = cellCur.Metrics.StartGridCol + cellCur.Get_GridSpan() - 1;
											if(nCurGridCol <= nPrevEndGrid)
1340
											{
1341
												nCurEndGrid = nCurGridCol;
1342 1343
												elem.indexEnd = j;
											}
1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361
											else
												break;
										}
										else
											break;
									}
								}
							}
							elem.gridStart = nPrevStartGrid = nCurStartGrid;
							elem.gridEnd = nPrevEndGrid = nCurEndGrid;
							if(null == nMinGrid || nMinGrid > nCurStartGrid)
								nMinGrid = nCurStartGrid;
							if(null == nMaxGrid || nMaxGrid < nCurEndGrid)
								nMaxGrid = nCurEndGrid;
						}
						if(null != nMinGrid && null != nMaxGrid)
						{
							//выставляем after, before
1362
							for(var i = 0 ,length = aSelectedRows.length; i < length; ++i)
1363
							{
1364
								var elem = aSelectedRows[i];
1365 1366 1367
								elem.before = elem.gridStart - nMinGrid;
								elem.after = nMaxGrid - elem.gridEnd;
							}
1368
							this.oBinaryFileWriter.copyParams.bLockCopyElems++;
1369
							this.CopyTable(oDomTarget, Item, aSelectedRows);
1370
							this.oBinaryFileWriter.copyParams.bLockCopyElems--;
1371
							this.oBinaryFileWriter.CopyTable(Item, aSelectedRows, nMinGrid, nMaxGrid);
1372 1373 1374 1375
						}
                    }
                }
                else
1376
				{
1377
					this.oBinaryFileWriter.copyParams.bLockCopyElems++;
1378
                    this.CopyTable(oDomTarget, Item, null);
1379
					this.oBinaryFileWriter.copyParams.bLockCopyElems--;
1380
					this.oBinaryFileWriter.CopyTable(Item, null);
1381
				}
1382 1383 1384 1385
            }
            else if ( type_Paragraph === Item.GetType() )
            {
                //todo ����� ������ ��� �������� ������ ���� Index == End
1386
				this.oBinaryFileWriter.CopyParagraph(Item);
1387 1388 1389 1390 1391 1392 1393
                this.CopyParagraph(oDomTarget, Item, Index == End, bUseSelection, oDocument.Content, Index);
            }
        }
        this.CommitList(oDomTarget);
    },
    Start : function(node)
    {
1394
		this.oBinaryFileWriter.CopyStart();
1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412
        var oDocument = this.oDocument;
        if(g_bIsDocumentCopyPaste)
        {
			if(!this.api.DocumentReaderMode)
			{
				var Def_pPr = oDocument.Styles.Default.ParaPr;
				if(docpostype_HdrFtr === oDocument.CurPos.Type)
				{
					if(null != oDocument.HdrFtr && null != oDocument.HdrFtr.CurHdrFtr && null != oDocument.HdrFtr.CurHdrFtr.Content)
						oDocument = oDocument.HdrFtr.CurHdrFtr.Content;
				}
				if ( oDocument.CurPos.Type == docpostype_FlowObjects )
				{
					var oData = oDocument.Selection.Data.FlowObject;
					switch ( oData.Get_Type() )
					{
						case flowobject_Image:
						{
1413 1414
						    this.Para = document.createElement("p");
						    var sInnerHtml = this.ParseItem(oData);
1415 1416 1417 1418 1419
							var oImg = oData;
							var sSrc = oImg.Img;
							if(sSrc.length > 0)
							{
								sSrc = this.getSrc(sSrc);
Oleg.Korshul's avatar
Oleg.Korshul committed
1420 1421

                                if (this.api.DocumentReaderMode)
1422
                                    sInnerHtml += "<img style=\"max-width:100%;\" width=\""+Math.round(oImg.W * g_dKoef_mm_to_pix)+"\" height=\""+Math.round(oImg.H * g_dKoef_mm_to_pix)+"\" src=\""+sSrc+"\" />";
Oleg.Korshul's avatar
Oleg.Korshul committed
1423
                                else
1424
                                    sInnerHtml += "<img width=\""+Math.round(oImg.W * g_dKoef_mm_to_pix)+"\" height=\""+Math.round(oImg.H * g_dKoef_mm_to_pix)+"\" src=\""+sSrc+"\" />";
1425
							}
1426
							this.Para.innerHTML = sInnerHtml;
1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440
							this.ElemToSelect.appendChild( this.Para );
							return;
						}
						case flowobject_Table:
						{
							if(null != oData.Table && null != oData.Table.CurCell && null != oData.Table.CurCell.Content)
								oDocument = oData.Table.CurCell.Content;
							break;
						}
					}
				}

                if(oDocument.CurPos.Type === docpostype_DrawingObjects)
                {
1441 1442 1443 1444 1445
                    var content = oDocument.DrawingObjects.getTargetDocContent();
                    if(content)
                    {
                        oDocument = content;
                    }
1446
                    else if(oDocument.DrawingObjects.selection.groupSelection && oDocument.DrawingObjects.selection.groupSelection.selectedObjects && oDocument.DrawingObjects.selection.groupSelection.selectedObjects.length)
1447 1448
                    {

1449
                            var s_arr = oDocument.DrawingObjects.selection.groupSelection.selectedObjects;
1450

Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1451
                            this.Para = document.createElement( "p" );
1452

Igor.Zotov's avatar
Igor.Zotov committed
1453
                            if(copyPasteUseBinary)
1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464
                            {
                                var newArr = null;
                                var tempAr = null;
                                if(s_arr)
                                {
                                    tempAr = [];
                                    for(var k = 0; k < s_arr.length; k++)
                                    {
                                        tempAr[k] = s_arr[k].y;
                                    }
                                }
1465
                                tempAr.sort(fSortAscending);
1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481
                                newArr = [];
                                for(var k = 0; k < tempAr.length; k++)
                                {
                                    var absOffsetY = tempAr[k];
                                    for(var i = 0; i < s_arr.length; i++)
                                    {
                                        if(absOffsetY == s_arr[i].y)
                                        {
                                            newArr[k] = s_arr[i];
                                        }
                                    }
                                }
                                if(newArr != null)
                                    s_arr = newArr;
                            }

1482 1483
                            for(var i = 0; i < s_arr.length; ++i)
                            {
1484 1485 1486 1487
                                var paraDrawing = s_arr[i].parent ? s_arr[i].parent : s_arr[i].group.parent;
								var graphicObj = s_arr[i];
								
                                if(isRealObject(paraDrawing.Parent))
1488
                                {
1489
                                    var base64_img = paraDrawing.getBase64Img();
1490

Igor.Zotov's avatar
Igor.Zotov committed
1491
                                    if(copyPasteUseBinary)
1492
                                    {
1493
										var wrappingType = oDocument.DrawingObjects.selection.groupSelection.parent.wrappingType;
1494 1495 1496
                                        var DrawingType = oDocument.DrawingObjects.selection.groupSelection.parent.DrawingType;
                                        var tempParagraph = new Paragraph(oDocument, oDocument, 0, 0, 0, 0, 0);
                                        var index = 0;
1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509
										
										tempParagraph.Content.unshift(new ParaRun());
										
										var paraRun = tempParagraph.Content[index];
                                        paraRun.Content.unshift(new ParaDrawing());
                                        paraRun.Content[index].wrappingType = wrappingType;
                                        paraRun.Content[index].DrawingType = DrawingType;
                                        paraRun.Content[index].GraphicObj = graphicObj;
										
										paraRun.Selection.EndPos = index + 1;
										paraRun.Selection.StartPos = index;
										paraRun.Selection.Use = true;
										
1510 1511
                                        tempParagraph.Selection.EndPos = index + 1;
                                        tempParagraph.Selection.StartPos = index;
1512 1513
										tempParagraph.Selection.Use = true;
										tempParagraph.bFromDocument = true;
1514 1515

                                        this.oBinaryFileWriter.CopyParagraph(tempParagraph);
1516
                                    };
1517 1518

                                    var src = this.getSrc(base64_img);
1519
                                    this.Para.innerHTML += "<img style=\"max-width:100%;\" width=\""+Math.round(paraDrawing.absExtX * g_dKoef_mm_to_pix)+"\" height=\""+Math.round(paraDrawing.absExtY * g_dKoef_mm_to_pix)+"\" src=\""+src+"\" />";
1520 1521 1522 1523 1524

                                    this.ElemToSelect.appendChild( this.Para );
                                }

                            }
1525

Igor.Zotov's avatar
Igor.Zotov committed
1526
                            if(copyPasteUseBinary)
1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547
                            {
                                this.oBinaryFileWriter.CopyEnd();
                                var sBase64 = this.oBinaryFileWriter.GetResult();
                                if(this.ElemToSelect.children && this.ElemToSelect.children.length == 1 && window.USER_AGENT_SAFARI_MACOS)
                                {
                                    $(this.ElemToSelect.children[0]).css("font-weight", "normal");
                                    $(this.ElemToSelect.children[0]).wrap(document.createElement("b"));
                                }
                                if(this.ElemToSelect.children[0])
                                    $(this.ElemToSelect.children[0]).addClass("docData;" + sBase64);
                            }
                    }
                    else
                    {
                        var gr_objects = oDocument.DrawingObjects;
                        var selection_array = gr_objects.selectedObjects;

                        this.Para = document.createElement( "span" );
                        var selectionTrue;
                        var selectIndex;
                        for(var i = 0; i < selection_array.length; ++i)
1548
                        {
1549 1550 1551 1552 1553 1554 1555
                            var cur_element = selection_array[i].parent;
                            var base64_img = cur_element.getBase64Img();
                            var src = this.getSrc(base64_img);

                            this.Para.innerHTML = "<img style=\"max-width:100%;\" width=\""+Math.round(cur_element.W * g_dKoef_mm_to_pix)+"\" height=\""+Math.round(cur_element.H * g_dKoef_mm_to_pix)+"\" src=\""+src+"\" />";

                            this.ElemToSelect.appendChild( this.Para );
1556

Igor.Zotov's avatar
Igor.Zotov committed
1557
                            if(copyPasteUseBinary)
1558
                            {
1559 1560 1561 1562 1563 1564 1565
                                var paragraph = cur_element.Parent;
                                
								var inIndex;
								var paragraphIndex;
								var content;
								var curParaRun;
                                for(var k = 0; k < paragraph.Content.length;k++)
1566
                                {
1567
                                    content = paragraph.Content[k].Content;
1568 1569 1570
									if(!content)
										continue;
									
1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590
									for(var n = 0; n < content.length; n++)
									{
										if(content[n] == cur_element)
										{
											curParaRun = paragraph.Content[k];
											inIndex = n;
											paragraphIndex = k;
											break;
										};
									};
                                };
								
								selectionTrue =
                                {
                                    EndPos : curParaRun.Selection.EndPos,
                                    StartPos: curParaRun.Selection.StartPos,
									EndPosParagraph : paragraph.Selection.EndPos,
                                    StartPosParagraph: paragraph.Selection.StartPos
                                };
								
1591
                                //меняем Selection
1592 1593 1594 1595
                                curParaRun.Selection.EndPos = inIndex + 1;
                                curParaRun.Selection.StartPos = inIndex;
                                curParaRun.Selection.Use = true;
								
1596
								paragraph.Selection.EndPos = paragraphIndex;
1597 1598
                                paragraph.Selection.StartPos = paragraphIndex;
                                paragraph.Selection.Use = true;
1599

1600
                                this.oBinaryFileWriter.CopyParagraph(paragraph);
1601 1602

                                //возвращаем Selection
1603 1604 1605 1606 1607
                                curParaRun.Selection.StartPos = selectionTrue.StartPos;
                                curParaRun.Selection.EndPos = selectionTrue.EndPos;
								
								paragraph.Selection.StartPos = selectionTrue.StartPosParagraph;
                                paragraph.Selection.EndPos = selectionTrue.EndPosParagraph;
1608 1609
                            }
                        }
1610
                        
Igor.Zotov's avatar
Igor.Zotov committed
1611
						if(copyPasteUseBinary)
1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623
                        {
                            this.oBinaryFileWriter.CopyEnd();
                            var sBase64 = this.oBinaryFileWriter.GetResult();
                            if(this.ElemToSelect.children && this.ElemToSelect.children.length == 1 && window.USER_AGENT_SAFARI_MACOS)
                            {
                                $(this.ElemToSelect.children[0]).css("font-weight", "normal");
                                $(this.ElemToSelect.children[0]).wrap(document.createElement("b"));
                            }
                            if(this.ElemToSelect.children[0])
                                $(this.ElemToSelect.children[0]).addClass("docData;" + sBase64);
                        }
                        return;
1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635
                    }
                }
				if ( true === oDocument.Selection.Use )
				{
					this.CopyDocument(this.ElemToSelect, oDocument, true);
				}
			}
			else
				this.CopyDocument(this.ElemToSelect, oDocument, false);
        }
        else
        {
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1636 1637 1638
            var presentation = editor.WordControl.m_oLogicDocument;
            var pasteString = "";
            switch(editor.WordControl.Thumbnails.FocusObjType)
1639
            {
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1640
                case FOCUS_OBJECT_MAIN:
1641
                {
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1642 1643 1644 1645
                    var slide = presentation.Slides[presentation.CurPage];
                    var graphicObjects = slide.graphicObjects;

                    switch(graphicObjects.State.id)
1646
                    {
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1647 1648
                        case STATES_ID_TEXT_ADD:
                        case STATES_ID_TEXT_ADD_IN_GROUP:
1649
                        case STATES_ID_CHART_TEXT_ADD:
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1650
                        {
1651
                            if(graphicObjects.State.textObject instanceof CShape || graphicObjects.State.textObject instanceof CChartTitle)
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679
                            {
                                this.oPresentationWriter.WriteString2("TeamLab1");
                                this.oPresentationWriter.WriteString2(editor.DocumentUrl);
                                this.oPresentationWriter.WriteDouble(presentation.Width);
                                this.oPresentationWriter.WriteDouble(presentation.Height);
                                this.CopyPresentationText(this.ElemToSelect, graphicObjects.State.textObject.txBody.content, true);
                            }
                            else  if(graphicObjects.State.textObject instanceof CGraphicFrame)
                            {
                                var table = graphicObjects.State.textObject.graphicObject;
                                switch(table.Selection.Type)
                                {
                                    case table_Selection_Text:
                                    {
                                        this.oPresentationWriter.WriteString2("TeamLab1");
                                        this.oPresentationWriter.WriteString2(editor.DocumentUrl);
                                        this.oPresentationWriter.WriteDouble(presentation.Width);
                                        this.oPresentationWriter.WriteDouble(presentation.Height);
                                        this.CopyPresentationText(this.ElemToSelect, graphicObjects.State.textObject.graphicObject.CurCell.Content, true);
                                        break;
                                    }
                                    case table_Selection_Cell:
                                    {
                                        this.oPresentationWriter.WriteString2("TeamLab4");
                                        this.oPresentationWriter.WriteString2(editor.DocumentUrl);
                                        this.oPresentationWriter.WriteDouble(presentation.Width);
                                        this.oPresentationWriter.WriteDouble(presentation.Height);
                                        this.CopyPresentationTableCells(this.ElemToSelect, graphicObjects.State.textObject);
1680 1681 1682 1683 1684 1685 1686 1687 1688
                                        var selected_objects = graphicObjects.State.id === STATES_ID_GROUP ? graphicObjects.State.group.selectedObjects : graphicObjects.selectedObjects;
                                        for(var i = 0; i < selected_objects.length; ++i)
                                        {
                                            var selected_object = selected_objects[i];
                                            this.oPresentationWriter.WriteDouble(selected_object.x);
                                            this.oPresentationWriter.WriteDouble(selected_object.y);
                                            this.oPresentationWriter.WriteDouble(selected_object.extX);
                                            this.oPresentationWriter.WriteDouble(selected_object.extY);
                                        }
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1689 1690 1691 1692
                                        break;
                                    }
                                }
                            }
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1693 1694 1695 1696 1697 1698 1699 1700
                            break;
                        }
                        default :
                        {
                            if(graphicObjects.selectedObjects.length > 0)
                            {
                                this.Para = document.createElement("p");
                                this.oPresentationWriter.WriteString2("TeamLab2");
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1701 1702 1703
                                this.oPresentationWriter.WriteString2(editor.DocumentUrl);
                                this.oPresentationWriter.WriteDouble(presentation.Width);
                                this.oPresentationWriter.WriteDouble(presentation.Height);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1704
                                var selected_objects = graphicObjects.State.id === STATES_ID_GROUP ? graphicObjects.State.group.selectedObjects : graphicObjects.selectedObjects;
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1705 1706
                                this.oPresentationWriter.WriteULong(selected_objects.length);

Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1707
                                for(var i = 0; i < selected_objects.length; ++i)
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1708
                                {
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1709
                                    if(!(selected_objects[i] instanceof CGraphicFrame))
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1710 1711
                                    {
                                        this.oPresentationWriter.WriteBool(true);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1712
                                        this.CopyGraphicObject(this.ElemToSelect, selected_objects[i]);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1713 1714 1715 1716
                                    }
                                    else
                                    {
                                        this.oPresentationWriter.WriteBool(false);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1717
                                        this.CopyPresentationTableFull(this.ElemToSelect, selected_objects[i]);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1718 1719
                                    }
                                }
1720 1721 1722 1723 1724 1725 1726 1727
                                for(var i = 0; i < selected_objects.length; ++i)
                                {
                                    var selected_object = selected_objects[i];
                                    this.oPresentationWriter.WriteDouble(selected_object.x);
                                    this.oPresentationWriter.WriteDouble(selected_object.y);
                                    this.oPresentationWriter.WriteDouble(selected_object.extX);
                                    this.oPresentationWriter.WriteDouble(selected_object.extY);
                                }
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1728

Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1729 1730 1731 1732 1733
                                for(var i = 0; i < this.Para.childNodes.length; i++)
                                    this.ElemToSelect.appendChild( this.Para.childNodes[i].cloneNode(true));
                            }
                            break;
                        }
1734
                    }
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1735
                    break;
1736
                }
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1737
                case FOCUS_OBJECT_THUMBNAILS :
1738
                {
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1739 1740
                    var selected_slides = editor.WordControl.Thumbnails.GetSelectedArray();
                    if(selected_slides.length > 0)
1741
                    {
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1742 1743
                        this.Para = document.createElement( "p" );
                        this.oPresentationWriter.WriteString2("TeamLab3");
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1744 1745 1746
                        this.oPresentationWriter.WriteString2(editor.DocumentUrl);
                        this.oPresentationWriter.WriteDouble(presentation.Width);
                        this.oPresentationWriter.WriteDouble(presentation.Height);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1747
                        this.oPresentationWriter.WriteULong(selected_slides.length);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1748 1749
                        var layouts_map = {};
                        var layout_count = 0;
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1750
                        editor.WordControl.m_oLogicDocument.CalculateComments();
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1751
                        for(var i = 0; i < selected_slides.length; ++i)
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1752
                        {
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1753
                            this.CopySlide(this.ElemToSelect, editor.WordControl.m_oLogicDocument.Slides[selected_slides[i]]);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784
                            if(!layouts_map[editor.WordControl.m_oLogicDocument.Slides[selected_slides[i]].Layout.Get_Id()])
                                ++layout_count;
                            layouts_map[editor.WordControl.m_oLogicDocument.Slides[selected_slides[i]].Layout.Get_Id()] = editor.WordControl.m_oLogicDocument.Slides[selected_slides[i]].Layout;
                        }

                        this.oPresentationWriter.WriteULong(layout_count);
                        var arr_layouts_id = [];
                        var t = 0;
                        for(var key in layouts_map)
                        {
                            this.CopyLayout(layouts_map[key]);
                            arr_layouts_id[t] = layouts_map[key];
                            ++t;
                        }

                        var arr_ind = [];
                        for(var i = 0; i < selected_slides.length; ++i)
                        {
                            for(t = 0; t < arr_layouts_id.length; ++t)
                            {
                                if(editor.WordControl.m_oLogicDocument.Slides[selected_slides[i]].Layout === arr_layouts_id[t])
                                {
                                    arr_ind[i] = t;
                                    break;
                                }
                            }
                        }
                        for(var i = 0; i < arr_ind.length; ++i)
                        {
                            this.oPresentationWriter.WriteULong(arr_ind[i]);
                        }
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1785 1786
                        for(var i = 0; i < this.Para.childNodes.length; i++)
                            this.ElemToSelect.appendChild( this.Para.childNodes[i].cloneNode(true) );
1787
                    }
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1788
                    break;
1789 1790
                }
            }
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1791
            var sBase64 = this.oPresentationWriter.GetBase64Memory();
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1792
            sBase64 = "" + this.oPresentationWriter.pos + ";" + sBase64;
1793 1794 1795 1796 1797
			if(this.ElemToSelect.children && this.ElemToSelect.children.length == 1 && window.USER_AGENT_SAFARI_MACOS)
			{
				$(this.ElemToSelect.children[0]).css("font-weight", "normal");;
				$(this.ElemToSelect.children[0]).wrap(document.createElement("b"));
			}
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1798
            if(this.ElemToSelect.children[0])
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1799
                $(this.ElemToSelect.children[0]).addClass("pptData;" + sBase64);
1800
        }
1801
		this.oBinaryFileWriter.CopyEnd();
Igor.Zotov's avatar
Igor.Zotov committed
1802
		if(copyPasteUseBinary && this.oBinaryFileWriter.copyParams.itemCount > 0)
1803 1804
		{
			var sBase64 = this.oBinaryFileWriter.GetResult();
1805 1806 1807 1808 1809
			if(this.ElemToSelect.children && this.ElemToSelect.children.length == 1 && window.USER_AGENT_SAFARI_MACOS)
			{
				$(this.ElemToSelect.children[0]).css("font-weight", "normal");;
				$(this.ElemToSelect.children[0]).wrap(document.createElement("b"));
			}
1810 1811
			if(this.ElemToSelect.children[0])
				$(this.ElemToSelect.children[0]).addClass("docData;" + sBase64);
1812
		}
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1813 1814 1815 1816 1817 1818
    },


    CopySlide: function(oDomTarget, slide)
    {
        var sSrc = slide.getBase64Img();
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1819
        //if(sSrc.length > 0)
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1820
        {
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1821
           // sSrc = this.getSrc(sSrc);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1822 1823
            var _bounds_cheker = new CSlideBoundsChecker();
            slide.draw(_bounds_cheker, 0);
1824
            this.Para.innerHTML += "<img width=\""+Math.round((_bounds_cheker.Bounds.max_x - _bounds_cheker.Bounds.min_x + 1) * g_dKoef_mm_to_pix)+"\" height=\""+Math.round((_bounds_cheker.Bounds.max_y - _bounds_cheker.Bounds.min_y + 1) * g_dKoef_mm_to_pix)+"\" src=\""+sSrc+"\" />";
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1825
            this.oPresentationWriter.WriteString2(slide.Layout.Get_Id());
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1826 1827 1828 1829 1830 1831 1832 1833 1834 1835
            var table_styles_ids = [];
            var sp_tree = slide.cSld.spTree;
            for(var i = 0; i < sp_tree.length; ++i)
            {
                if(sp_tree[i] instanceof CGraphicFrame)
                {
                    table_styles_ids.push(sp_tree[i].graphicObject.styleIndex);
                    sp_tree[i].graphicObject.styleIndex = -1;
                }
            }
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1836 1837 1838 1839 1840 1841 1842 1843 1844
            this.oPresentationWriter.WriteULong(table_styles_ids.length);
            for(var i = 0; i < table_styles_ids.length; ++i)
            {
                this.oPresentationWriter.WriteBool(isRealNumber(table_styles_ids[i]) && table_styles_ids[i] > -1)
                if(isRealNumber(table_styles_ids[i]) && table_styles_ids[i] > -1)
                {
                    this.oPresentationWriter.WriteULong(table_styles_ids[i]);
                }
            }
1845

Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1846
            this.oPresentationWriter.WriteSlide(slide);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1847

1848 1849 1850 1851 1852 1853 1854 1855 1856
            this.oPresentationWriter.WriteULong(sp_tree.length);
            for(var i = 0; i < sp_tree.length; ++i)
            {
                var sp = sp_tree[i];
                this.oPresentationWriter.WriteDouble(sp.x);
                this.oPresentationWriter.WriteDouble(sp.y);
                this.oPresentationWriter.WriteDouble(sp.extX);
                this.oPresentationWriter.WriteDouble(sp.extY);
            }
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1857 1858 1859 1860 1861 1862 1863 1864 1865
            var  j = 0;
            for(var i = 0; i < sp_tree.length; ++i)
            {
                if(sp_tree[i] instanceof CGraphicFrame)
                {
                    sp_tree[i].graphicObject.styleIndex = table_styles_ids[j];
                    ++j;
                }
            }
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1866 1867 1868
        }
    },

Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1869 1870 1871 1872 1873
    CopyLayout: function(layout)
    {
        this.oPresentationWriter.WriteSlideLayout(layout);
    },

Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1874 1875 1876

    CopyPresentationTableCells: function(oDomTarget, graphicFrame)
    {
Alexander.Trofimov's avatar
Alexander.Trofimov committed
1877
        var aSelectedRows = [];
Alexander.Trofimov's avatar
Alexander.Trofimov committed
1878
        var oRowElems = {};
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029
        var Item = graphicFrame.graphicObject;
        if(Item.Selection.Data.length > 0)
        {
            for(var i = 0, length = Item.Selection.Data.length; i < length; ++i)
            {
                var elem = Item.Selection.Data[i];
                var rowElem = oRowElems[elem.Row];
                if(null == rowElem)
                {
                    rowElem = {row: elem.Row, gridStart: null, gridEnd: null, indexStart: null, indexEnd: null, after: null, before: null, cells: {}};
                    oRowElems[elem.Row] = rowElem;
                    aSelectedRows.push(rowElem);
                }
                if(null == rowElem.indexEnd || elem.Cell > rowElem.indexEnd)
                    rowElem.indexEnd = elem.Cell;
                if(null == rowElem.indexStart || elem.Cell < rowElem.indexStart)
                    rowElem.indexStart = elem.Cell;
                rowElem.cells[elem.Cell] = 1;
            }
        }
        aSelectedRows.sort(function(a,b){
            return a.row - b.row;
        });
        var nMinGrid = null;
        var nMaxGrid = null;
        var nPrevStartGrid = null;
        var nPrevEndGrid = null;
        var nPrevRowIndex = null;
        for(var i = 0, length = aSelectedRows.length; i < length; ++i)
        {
            var elem = aSelectedRows[i];
            var nRowIndex = elem.row;
            if(null != nPrevRowIndex)
            {
                if(nPrevRowIndex + 1 != nRowIndex)
                {
                    nMinGrid = null;
                    nMaxGrid = null;
                    break;
                }
            }
            nPrevRowIndex = nRowIndex;
            var row = Item.Content[nRowIndex];
            var cellFirst = row.Get_Cell(elem.indexStart);
            var cellLast = row.Get_Cell(elem.indexEnd);
            var nCurStartGrid = cellFirst.Metrics.StartGridCol;
            var nCurEndGrid = cellLast.Metrics.StartGridCol + cellLast.Get_GridSpan() - 1;
            if(null != nPrevStartGrid && null != nPrevEndGrid)
            {
                //учитываем вертикальный merge, раздвигаем границы
                if(nCurStartGrid > nPrevStartGrid)
                {
                    for(var j = elem.indexStart - 1; j >= 0; --j)
                    {
                        var cellCur = row.Get_Cell(j);
                        if(vmerge_Continue == cellCur.Get_VMerge())
                        {
                            var nCurGridCol = cellCur.Metrics.StartGridCol;
                            if(nCurGridCol >= nPrevStartGrid)
                            {
                                nCurStartGrid = nCurGridCol;
                                elem.indexStart = j;
                            }
                            else
                                break;
                        }
                        else
                            break;
                    }
                }
                if(nCurEndGrid < nPrevEndGrid)
                {
                    for(var j = elem.indexEnd + 1; j < row.Get_CellsCount(); ++j)
                    {
                        var cellCur = row.Get_Cell(j);
                        if(vmerge_Continue == cellCur.Get_VMerge())
                        {
                            var nCurGridCol = cellCur.Metrics.StartGridCol + cellCur.Get_GridSpan() - 1;
                            if(nCurGridCol <= nPrevEndGrid)
                            {
                                nCurEndGrid = nCurGridCol;
                                elem.indexEnd = j;
                            }
                            else
                                break;
                        }
                        else
                            break;
                    }
                }
            }
            elem.gridStart = nPrevStartGrid = nCurStartGrid;
            elem.gridEnd = nPrevEndGrid = nCurEndGrid;
            if(null == nMinGrid || nMinGrid > nCurStartGrid)
                nMinGrid = nCurStartGrid;
            if(null == nMaxGrid || nMaxGrid < nCurEndGrid)
                nMaxGrid = nCurEndGrid;
        }
        if(null != nMinGrid && null != nMaxGrid)
        {
            //выставляем after, before
            for(var i = 0 ,length = aSelectedRows.length; i < length; ++i)
            {
                var elem = aSelectedRows[i];
                elem.before = elem.gridStart - nMinGrid;
                elem.after = nMaxGrid - elem.gridEnd;
            }
            this.CopyTable(oDomTarget, Item, aSelectedRows);
        }
        var is_on = History.Is_On();
        if(is_on)
        {
            History.TurnOff();
        }
        var graphic_frame = new CGraphicFrame(graphicFrame.parent);
        var grid = [];

        for(var i = nMinGrid; i <= nMaxGrid; ++i)
        {
            grid.push(graphicFrame.graphicObject.TableGrid[i]);
        }
        var table = new CTable(editor.WordControl.m_oDrawingDocument, graphicFrame, false, 0, 0, 0, 0, 0, aSelectedRows.length, nMaxGrid - nMinGrid+1, grid);
        table.setStyleIndex(graphicFrame.graphicObject.styleIndex);
        graphic_frame.setGraphicObject(table);
        graphic_frame.setXfrm(0, 0, 20, 30, 0, false, false);
        var  b_style_index = false;
        if(isRealNumber(graphic_frame.graphicObject.styleIndex) && graphic_frame.graphicObject.styleIndex > -1)
        {
            b_style_index = true;
        }

        this.oPresentationWriter.WriteULong(1);
        this.oPresentationWriter.WriteBool(false);
        this.oPresentationWriter.WriteBool(b_style_index);
        if(b_style_index)
        {
            this.oPresentationWriter.WriteULong(graphic_frame.graphicObject.styleIndex);
        }
        var old_style_index = graphic_frame.graphicObject.styleIndex;
        graphic_frame.graphicObject.styleIndex = -1;
        this.oPresentationWriter.WriteTable(graphic_frame);
        graphic_frame.graphicObject.styleIndex = old_style_index;
        if(is_on)
        {
            History.TurnOn();
        }
        this.oBinaryFileWriter.copyParams.itemCount = 0;
    },

    CopyPresentationTableFull: function(oDomTarget, graphicFrame)
    {
Alexander.Trofimov's avatar
Alexander.Trofimov committed
2030
        var aSelectedRows = [];
Alexander.Trofimov's avatar
Alexander.Trofimov committed
2031
        var oRowElems = {};
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053
        var Item = graphicFrame.graphicObject;

        this.CopyTable(oDomTarget, Item, null);
        var b_style_index = false;
        if(isRealNumber(graphicFrame.graphicObject.styleIndex) && graphicFrame.graphicObject.styleIndex > -1)
        {
            b_style_index = true;
        }

        this.oPresentationWriter.WriteBool(b_style_index);
        if(b_style_index)
        {
            this.oPresentationWriter.WriteULong(graphicFrame.graphicObject.styleIndex);
        }
        var old_style_index = graphicFrame.graphicObject.styleIndex;

        graphicFrame.graphicObject.styleIndex = -1;
        this.oPresentationWriter.WriteTable(graphicFrame);
        graphicFrame.graphicObject.styleIndex = old_style_index;
        this.oBinaryFileWriter.copyParams.itemCount = 0;
    },

Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065
    CopyPresentationText : function(oDomTarget, oDocument, bUseSelection)
    {
        var Start = 0;
        var End = 0;
        if(bUseSelection)
        {
            if ( true === oDocument.Selection.Use)
            {
                if ( selectionflag_DrawingObject === oDocument.Selection.Flag )
                {
                    this.Para = document.createElement( "p" );
                    //������ ���� �������� ������ ���� ��������
2066
                    this.Para.innerHTML = this.ParseItem(oDocument.Selection.Data.DrawingObject);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089

                    for(var i = 0; i < this.Para.childNodes.length; i++)
                        this.ElemToSelect.appendChild( this.Para.childNodes[i].cloneNode(true) );
                }
                else
                {
                    Start = oDocument.Selection.StartPos;
                    End = oDocument.Selection.EndPos;
                    if ( Start > End )
                    {
                        var Temp = End;
                        End = Start;
                        Start = Temp;
                    }
                }
            }
        }
        else
        {
            Start = 0;
            End = oDocument.Content.length - 1;
        }
        // HtmlText
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
2090 2091

        this.oPresentationWriter.WriteULong(End - Start + 1);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
2092 2093 2094
        for ( var Index = Start; Index <= End; Index++ )
        {
            var Item = oDocument.Content[Index];
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
2095 2096 2097 2098
            var selectStart = Item.Selection.Use ? Item.Selection.StartPos : 0;
            var selectEnd = Item.Selection.Use ? Item.Selection.EndPos : Item.Content.length;

            if ( selectStart > selectEnd )
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
2099
            {
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
2100 2101 2102
                var Temp = selectEnd;
                selectEnd = selectStart;
                selectStart = Temp;
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
2103
            }
2104 2105 2106 2107 2108 2109 2110 2111 2112 2113
            for(var i = 0;  i < selectStart; ++i)
            {
                var content = Item.Content;
                if(content instanceof ParaText)
                    break;
            }
            if(i == selectStart)
            {
                selectStart = 0;
            }
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
2114 2115 2116 2117 2118
            this.oPresentationWriter.StartRecord(0);
            this.oPresentationWriter.WriteParagraph(Item, selectStart, selectEnd);
            this.oPresentationWriter.EndRecord();

            this.CopyParagraph(oDomTarget, Item, Index == End, bUseSelection, oDocument.Content, Index);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131
        }
        this.CommitList(oDomTarget);
    },


    CopyGraphicObject: function(oDomTarget, oGraphicObj)
    {
        var sSrc = oGraphicObj.getBase64Img();
        if(sSrc.length > 0)
        {
            sSrc = this.getSrc(sSrc);
            var _bounds_cheker = new CSlideBoundsChecker();
            oGraphicObj.draw(_bounds_cheker, 0);
Oleg.Korshul's avatar
Oleg.Korshul committed
2132 2133

            if (this.api.DocumentReaderMode)
2134
                this.Para.innerHTML += "<img style=\"max-width:100%;\" width=\""+Math.round((_bounds_cheker.Bounds.max_x - _bounds_cheker.Bounds.min_x + 1) * g_dKoef_mm_to_pix)+"\" height=\""+Math.round((_bounds_cheker.Bounds.max_y - _bounds_cheker.Bounds.min_y + 1) * g_dKoef_mm_to_pix)+"\" src=\""+sSrc+"\" />";
Oleg.Korshul's avatar
Oleg.Korshul committed
2135
            else
2136
                this.Para.innerHTML += "<img width=\""+Math.round((_bounds_cheker.Bounds.max_x - _bounds_cheker.Bounds.min_x + 1) * g_dKoef_mm_to_pix)+"\" height=\""+Math.round((_bounds_cheker.Bounds.max_y - _bounds_cheker.Bounds.min_y + 1) * g_dKoef_mm_to_pix)+"\" src=\""+sSrc+"\" />";
Oleg.Korshul's avatar
Oleg.Korshul committed
2137

Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149
            if(oGraphicObj instanceof CShape)
            {
                this.oPresentationWriter.WriteShape(oGraphicObj);
            }
            else if(oGraphicObj instanceof CImageShape)
            {
                this.oPresentationWriter.WriteImage(oGraphicObj);
            }
            else if(oGraphicObj instanceof CGroupShape)
            {
                this.oPresentationWriter.WriteGroupShape(oGraphicObj);
            }
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
2150
            else if(typeof CChartAsGroup != "undefined" && oGraphicObj instanceof CChartAsGroup)
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
2151 2152 2153
            {
                this.oPresentationWriter.WriteChart(oGraphicObj);
            }
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
2154
        }
2155 2156 2157 2158 2159 2160
    }
};

function Editor_Paste_GetElem(api, bClean)
{
    var oWordControl = api.WordControl;
Oleg.Korshul's avatar
Oleg.Korshul committed
2161
    var pastebin = document.getElementById(PASTE_ELEMENT_ID);
2162 2163
    if(!pastebin){
        pastebin = document.createElement("div");
Oleg.Korshul's avatar
Oleg.Korshul committed
2164
        pastebin.setAttribute( 'id', PASTE_ELEMENT_ID );
Oleg.Korshul's avatar
 
Oleg.Korshul committed
2165
        pastebin.className = "sdk-element";
Oleg.Korshul's avatar
 
Oleg.Korshul committed
2166

Oleg.Korshul's avatar
Oleg.Korshul committed
2167
        if (AscBrowser.isIE)
Oleg.Korshul's avatar
 
Oleg.Korshul committed
2168 2169 2170 2171
            pastebin.style.position = 'fixed';
        else
            pastebin.style.position = 'absolute';

2172 2173
        pastebin.style.top = '-100px';
        pastebin.style.left = '0px';
2174
        pastebin.style.width = '10000px';
2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205
        pastebin.style.height = '100px';
        pastebin.style.overflow = 'hidden';
        pastebin.style.zIndex = -1000;
        //��������� ������ ������������, ����� �������� �������� ����� pastebin �������� span � ������� ��� �������� ������ � computedStyle ���������� ����������� ��������� ��������� �� ���������
        var Def_rPr = oWordControl.m_oLogicDocument.Styles.Default.TextPr;
        pastebin.style.fontFamily = Def_rPr.FontFamily.Name;

        if (!api.DocumentReaderMode)
            pastebin.style.fontSize = Def_rPr.FontSize + "pt";
        else
        {
            api.DocumentReaderMode.CorrectDefaultFontSize(Def_rPr.FontSize);
            pastebin.style.fontSize = "1em";
        }
        pastebin.style.MozUserSelect = "text";
        pastebin.style["-khtml-user-select"] = "text";
        pastebin.style["-o-user-select"] = "text";
        pastebin.style["user-select"] = "text";
        pastebin.style["-webkit-user-select"] = "text";
        pastebin.setAttribute("contentEditable", true);

        document.body.appendChild( pastebin );
    }
    else if(bClean){
        //������� ����������
        var aChildNodes = pastebin.childNodes;
        for (var length = aChildNodes.length, i = length - 1; i >= 0; i--)
        {
            pastebin.removeChild(aChildNodes[i]);
        }
    }
Oleg.Korshul's avatar
 
Oleg.Korshul committed
2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217

    if (!window.USER_AGENT_SAFARI_MACOS)
    {
        pastebin.onpaste = function(e){
            if (!window.GlobalPasteFlag)
                return;

            Body_Paste(api,e);
            pastebin.onpaste = null;
        };
    }

2218 2219 2220 2221
    return pastebin;
}
function Editor_Paste_Button(api)
{
Oleg.Korshul's avatar
Oleg.Korshul committed
2222
    if(AscBrowser.isIE)
2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243
    {
        document.body.style.MozUserSelect = "text";
        delete document.body.style["-khtml-user-select"];
        delete document.body.style["-o-user-select"];
        delete document.body.style["user-select"];
        document.body.style["-webkit-user-select"] = "text";

        var pastebin = Editor_Paste_GetElem(api, true);

        pastebin.style.display  = "block";
        pastebin.focus();

        var selection = window.getSelection();
        var rangeToSelect = document.createRange();
        rangeToSelect.selectNodeContents (pastebin);
        selection.removeAllRanges ();
        selection.addRange(rangeToSelect);

        //rangeToSelect.execCommand("paste", false);
        document.execCommand("paste");

2244
        if (!window.USER_AGENT_SAFARI_MACOS)
Oleg.Korshul's avatar
Oleg.Korshul committed
2245 2246 2247
            pastebin.blur();

        pastebin.style.display  = ELEMENT_DISPAY_STYLE;
2248 2249 2250 2251 2252 2253 2254

        document.body.style.MozUserSelect = "none";
        document.body.style["-khtml-user-select"] = "none";
        document.body.style["-o-user-select"] = "none";
        document.body.style["user-select"] = "none";
        document.body.style["-webkit-user-select"] = "none";

2255
		History.Create_NewPoint();
2256 2257 2258 2259 2260
        Editor_Paste(api, false);
        return true;
    }
	else
	{
2261 2262 2263 2264 2265 2266
		var ElemToSelect = document.getElementById( COPY_ELEMENT_ID );
		if(ElemToSelect)
		{
			History.Create_NewPoint();
			Editor_Paste_Exec(api, ElemToSelect);
		}
2267 2268 2269 2270 2271 2272
		else
		{
			window.GlobalPasteFlagCounter = 0;
			window.GlobalPasteFlag = false;
		};
		
2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320
		return true;
	}
    return false;
}
function CanPaste(oDocument)
{
    //����� ������ paste ����� Select � ���������
    //�� ����� ������ paste ����� select �� ������� �������, ��������, ������
    var oTargetDoc = oDocument;
    if(g_bIsDocumentCopyPaste)
    {
        if ( docpostype_HdrFtr === oTargetDoc.CurPos.Type )
        {
            if(null != oTargetDoc.HdrFtr.CurHdrFtr)
                oTargetDoc = oTargetDoc.HdrFtr.CurHdrFtr.Content;
            else
                return false;
        }
        if ( docpostype_FlowObjects == oTargetDoc.CurPos.Type )
        {
            var nType = oTargetDoc.Selection.Data.FlowObject.Get_Type();
            if(flowobject_Table == nType)
            {
                var oTable = oTargetDoc.Selection.Data.FlowObject.Table;
                if(true == oTable.Selection.Use && table_Selection_Cell == oTable.Selection.Type)
                    return false;
                if(null != oTable.CurCell && null != oTable.CurCell.Content)
                {
                    oTargetDoc = oTable.CurCell.Content;
                }
            }
        }
    }
    else
    {
        if ( docpostype_FlowObjects == oTargetDoc.CurPos.Type )
        {
            var _cur_slide_elements = oTargetDoc.Slides[oTargetDoc.CurPage].elementsManipulator;
            if(_cur_slide_elements.obj != undefined && _cur_slide_elements.obj.txBody && _cur_slide_elements.obj.txBody.content)
            {
                return true;
            }
        }
    }
    return true;
};
function Editor_Paste(api, bClean)
{
Oleg.Korshul's avatar
 
Oleg.Korshul committed
2321
    window.GlobalPasteFlagCounter = 1;
2322 2323 2324
    var oWordControl = api.WordControl;
    oWordControl.bIsEventPaste = false;
    var oDocument = oWordControl.m_oLogicDocument;
Oleg.Korshul's avatar
Oleg.Korshul committed
2325

2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337
    if(false == CanPaste(oDocument))
        return;

    document.body.style.MozUserSelect = "text";
    delete document.body.style["-khtml-user-select"];
    delete document.body.style["-o-user-select"];
    delete document.body.style["user-select"];
    document.body.style["-webkit-user-select"] = "text";

    var Text;
    var pastebin = Editor_Paste_GetElem(api, bClean);
    pastebin.style.display  = "block";
2338
    pastebin.focus();
2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357
    // Safari requires a filler node inside the div to have the content pasted into it. (#4882)
    pastebin.appendChild( document.createTextNode( '\xa0' ) );

    if (window.getSelection) {  // all browsers, except IE before version 9
        var selection = document.defaultView.getSelection ();
        selection.removeAllRanges ();
        var rangeToSelect = document.createRange ();
        rangeToSelect.selectNodeContents (pastebin);

        selection.removeAllRanges ();
        selection.addRange (rangeToSelect);
    } else {
        if (document.body.createTextRange) {    // Internet Explorer
            var rangeToSelect = document.body.createTextRange ();
            rangeToSelect.moveToElementText (pastebin);
            rangeToSelect.select ();
        }
    }
    //���� ���������� paste
Oleg.Korshul's avatar
 
Oleg.Korshul committed
2358 2359
    var func_timeout = function() {

2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376
        if (PASTE_EMPTY_USE && !oWordControl.bIsEventPaste)
        {
            // не править. это сделано для фаерфокса. ну не успевает он вставить
            // в дивку контент. и получалось, что мы через раз вставляем пробел.
            // тут идет надежда на то, что вставлять пробел не будут. А если будут - то он вставится,
            // но может с задержкой 1-2 секунды.
            if (pastebin.innerHTML == "&nbsp;")
            {
                PASTE_EMPTY_COUNTER++;
                if (PASTE_EMPTY_COUNTER < PASTE_EMPTY_COUNTER_MAX)
                {
                    window.PasteEndTimerId = window.setTimeout( func_timeout, 100 );
                    return;
                }
            }
        }

Oleg.Korshul's avatar
 
Oleg.Korshul committed
2377 2378
        if (window.USER_AGENT_SAFARI_MACOS)
        {
Oleg.Korshul's avatar
 
Oleg.Korshul committed
2379
            if (window.GlobalPasteFlagCounter != 2 && !window.GlobalPasteFlag)
Oleg.Korshul's avatar
 
Oleg.Korshul committed
2380
            {
2381
                window.PasteEndTimerId = window.setTimeout(func_timeout, 10);
Oleg.Korshul's avatar
 
Oleg.Korshul committed
2382 2383 2384 2385
                return;
            }
        }

2386 2387 2388 2389 2390 2391
        document.body.style.MozUserSelect = "none";
        document.body.style["-khtml-user-select"] = "none";
        document.body.style["-o-user-select"] = "none";
        document.body.style["user-select"] = "none";
        document.body.style["-webkit-user-select"] = "none";

Oleg.Korshul's avatar
 
Oleg.Korshul committed
2392 2393 2394
        if (!window.USER_AGENT_SAFARI_MACOS)
            pastebin.onpaste = null;

2395
        if(!oWordControl.bIsEventPaste)
Oleg.Korshul's avatar
 
Oleg.Korshul committed
2396
        {
2397
            Editor_Paste_Exec(api, pastebin);
Oleg.Korshul's avatar
 
Oleg.Korshul committed
2398
        }
2399
        else
Oleg.Korshul's avatar
Oleg.Korshul committed
2400
            pastebin.style.display  = ELEMENT_DISPAY_STYLE;
2401 2402

        window.PasteEndTimerId = -1;
Oleg.Korshul's avatar
 
Oleg.Korshul committed
2403
    };
Oleg.Korshul's avatar
 
Oleg.Korshul committed
2404

2405
    var _interval_time = window.USER_AGENT_MACOS ? 200 : 0;
2406 2407 2408 2409

    if (-1 != window.PasteEndTimerId)
        clearTimeout(window.PasteEndTimerId);

2410
    PASTE_EMPTY_COUNTER = 0;
2411
    window.PasteEndTimerId = window.setTimeout( func_timeout, _interval_time );
2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428
};
function CopyPasteCorrectString(str)
{
    var res = str;
    res = res.replace(/&/g,'&amp;');
    res = res.replace(/</g,'&lt;');
    res = res.replace(/>/g,'&gt;');
    res = res.replace(/'/g,'&apos;');
    res = res.replace(/"/g,'&quot;');
    return res;
};
function Body_Paste(api, e)
{
    var oWordControl = api.WordControl;
    if (e && e.clipboardData && e.clipboardData.getData) {// Webkit - get data from clipboard, put into editdiv, cleanup, then cancel event
        var bExist = false;
        //������ chrome ��������� �������� 'text/html', safari ������ 'text/plain'
Oleg.Korshul's avatar
Oleg.Korshul committed
2429
        var is_chrome = AscBrowser.isChrome;
2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445
        var sHtml = null;

        var fPasteHtml = function(sHtml)
        {
            if(null != sHtml)
            {
                //���������� html � IFrame
                var ifr = document.getElementById("pasteFrame");
                if (!ifr)
                {
                    ifr = document.createElement("iframe");
                    ifr.name = "pasteFrame";
                    ifr.id = "pasteFrame";
                    ifr.style.position = 'absolute';
                    ifr.style.top = '-100px';
                    ifr.style.left = '0px';
2446
                    ifr.style.width = '10000px';
2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459
                    ifr.style.height = '100px';
                    ifr.style.overflow = 'hidden';
                    ifr.style.zIndex = -1000;
                    document.body.appendChild(ifr);
                }
                var frameWindow = window.frames["pasteFrame"];
                if(frameWindow)
                {
                    frameWindow.document.open();
                    frameWindow.document.write(sHtml);
                    frameWindow.document.close();
					if(null != frameWindow.document && null != frameWindow.document.body)
					{
2460 2461
						ifr.style.display  = "block";
						Editor_Paste_Exec(api, frameWindow.document.body, ifr);
2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477
						bExist = true;
					}
                }
            }

            if(bExist)
            {
                oWordControl.bIsEventPaste = true;
                if (e.preventDefault)
                {
                    e.stopPropagation();
                    e.preventDefault();
                }
                return false;
            }
        }
2478 2479
		var fTest = function(types, sPattern)
		{
Oleg.Korshul's avatar
 
Oleg.Korshul committed
2480 2481
            if (!types)
                return false;
2482 2483 2484 2485 2486 2487 2488 2489
			for(var i = 0, length = types.length; i < length; ++i)
			{
				if(sPattern == types[i])
					return true;
			}
			return false;
		}
        if (fTest(e.clipboardData.types, "text/html"))
2490 2491 2492 2493 2494 2495 2496
        {
            var sHtml = e.clipboardData.getData('text/html');
            //������ ��� ��������� ����� ������ �� Word � chrome ��������� ���������� ������� ����� </html>, �������� ��.
            var nIndex = sHtml.lastIndexOf("</html>");
            if(-1 != nIndex)
                sHtml = sHtml.substring(0, nIndex + "</html>".length);
        }
2497
        else if (is_chrome && fTest(e.clipboardData.types, "text/plain"))
2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568
        {
            bExist = true;
            var sText = e.clipboardData.getData('text/plain');
            sHtml = "<html><body>";
            var sCurPar = "";
            var nParCount = 0;
            for ( var i = 0, length = sText.length; i < length; i++ )
            {
                var Char = sText.charAt(i);
                var Code = sText.charCodeAt(i);
                var Item = null;

                if ( '\n' === Char )
                {
                    if("" == sCurPar)
                        sHtml += "<p><span>&nbsp;</span></p>";
                    else
                    {
                        sHtml += "<p><span>" + sCurPar + "</span></p>";
                        sCurPar = "";
                    }
                    nParCount++;
                }
                else if ( 13 === Code )
                {
                    continue;
                }
                else
                {
                    if(32 == Code || 160 == Code) //160 - nbsp
                        sCurPar += " ";
                    else if ( 9 === Code )
                        sCurPar += "<span style='mso-tab-count:1'>    </span>";
                    else
                        sCurPar += CopyPasteCorrectString(Char);
                }
            }
            if("" != sCurPar)
            {
                if(0 == nParCount)
                    sHtml += "<span>" + sCurPar + "</span>";
                else
                    sHtml += "<p><span>" + sCurPar + "</span></p>";
                sCurPar = "";
            }
            sHtml += "</body></html>";
        }
        if(sHtml)
            fPasteHtml(sHtml);
        else
        {
            var items = e.clipboardData.items;
            if(null != items)
            {
                for (var i = 0; i < items.length; ++i) {
                    if (items[i].kind == 'file' &&
                        items[i].type.indexOf('image/') !== -1) {

                        var blob = items[i].getAsFile();
                        var reader = new FileReader();

                        reader.onload = function(evt) {
                            fPasteHtml("<html><body><img src=\"" + evt.target.result + "\"/></body></html>");
                        };
                        reader.readAsDataURL(blob);
                    }
                }
            }
        }
    }
}
2569
function Editor_Paste_Exec(api, pastebin, nodeDisplay)
2570 2571
{
    var oPasteProcessor = new PasteProcessor(api, true, true, false);
2572
    oPasteProcessor.Start(pastebin, nodeDisplay);
2573 2574 2575 2576
};
function trimString( str ){
    return str.replace(/^\s+|\s+$/g, '') ;
};
2577
function PasteProcessor(api, bUploadImage, bUploadFonts, bNested, pasteInExcel)
2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588
{
    this.oRootNode = null;
    this.api = api;
    this.bIsDoublePx  = api.WordControl.bIsDoublePx;
    this.oDocument = api.WordControl.m_oLogicDocument;
    this.oLogicDocument = this.oDocument;
    this.oRecalcDocument = this.oDocument;
    this.map_font_index = api.FontLoader.map_font_index;
    this.bUploadImage = bUploadImage;
    this.bUploadFonts = bUploadFonts;
    this.bNested = bNested;//��� ���������� � ��������
Alexander.Trofimov's avatar
Alexander.Trofimov committed
2589 2590
    this.oFonts = {};
    this.oImages = {};
Alexander.Trofimov's avatar
Alexander.Trofimov committed
2591
	this.aContent = [];
2592
	
2593
	this.pasteInExcel = pasteInExcel;
2594
	this.pasteInPresentationShape = null;
2595
	
2596 2597 2598
    //��� ������� ������ � ������, ��� ����������� �� word � chrome ���������� ������ ������� ��� <p>
    this.bIgnoreNoBlockText = false;

2599 2600
    this.oCurRun = null;
    this.oCurRunContentPos = 0;
2601
    this.oCurPar = null;
2602 2603 2604
    this.oCurParContentPos = 0;
    this.oCurHyperlink = null;
    this.oCurHyperlinkContentPos = 0;
2605 2606 2607 2608 2609 2610 2611 2612 2613
    this.oCur_rPr = new CTextPr();

    //Br ������� ������ ��� ���� ������ ����� �� ���� �������� br, ���� �� � ������������.
    this.nBrCount = 0;
    //bInBlock ��������� ������� �� �������(��������������� ������ �������� �������� �� child)
    //���� ����� ��������� ������� true != this.bInBlock ������ ��������� ������� �� �������� � �� ���� ��������� ����� ��������
    this.bInBlock = null;

    //������ �������� � ������� ��������� �������� ��� ������
2614
    this.dMaxWidth = Page_Width - X_Left_Margin - X_Right_Margin;
2615 2616 2617
    //���������� ������(�������� ��� ������� ������� �������, ������ ��� ������� ����������� ������ � ��������� � ������� ����� �������� ���� �����������)
    this.dScaleKoef = 1;
    this.bUseScaleKoef = false;
2618
	this.bIsPlainText = false;
2619 2620

    this.MsoStyles = {"mso-style-type": 1, "mso-pagination": 1, "mso-line-height-rule": 1, "mso-style-textfill-fill-color": 1, "mso-tab-count": 1,
2621
        "tab-stops": 1, "list-style-type": 1, "mso-special-character": 1, "mso-column-break-before": 1, "mso-break-type": 1, "mso-padding-alt": 1, "mso-border-insidev": 1,
2622 2623
        "mso-border-insideh": 1, "mso-row-margin-left": 1, "mso-row-margin-right": 1, "mso-cellspacing": 1, "mso-border-alt": 1,
        "mso-border-left-alt": 1, "mso-border-top-alt": 1, "mso-border-right-alt": 1, "mso-border-bottom-alt": 1, "mso-border-between": 1};
Alexander.Trofimov's avatar
Alexander.Trofimov committed
2624
    this.oBorderCache = {};
2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660
}
PasteProcessor.prototype =
{
    _GetTargetDocument : function(oDocument)
    {
        if(g_bIsDocumentCopyPaste)
        {
            if(docpostype_HdrFtr === oDocument.CurPos.Type)
            {
                if(null != oDocument.HdrFtr && null != oDocument.HdrFtr.CurHdrFtr && null != oDocument.HdrFtr.CurHdrFtr.Content)
                {
                    oDocument = oDocument.HdrFtr.CurHdrFtr.Content;
                    this.oRecalcDocument = oDocument;
                }
            }
            
            if ( docpostype_FlowObjects == oDocument.CurPos.Type )
            {
                var oData = oDocument.Selection.Data.FlowObject;
                switch ( oData.Get_Type() )
                {
                    case flowobject_Table:
                    {
                        if(null != oData.Table && null != oData.Table.CurCell && null != oData.Table.CurCell.Content)
                        {
                            oDocument = this._GetTargetDocument(oData.Table.CurCell.Content);
                            this.oRecalcDocument = oDocument;
                            this.dMaxWidth = this._CalcMaxWidthByCell(oData.Table.CurCell);
                        }
                        break;
                    }
                }
            }

            if(oDocument.CurPos.Type === docpostype_DrawingObjects)
            {
2661
                var content = oDocument.DrawingObjects.getTargetDocContent(true);
2662
                if(content)
2663
                {
2664
                    oDocument = content;
2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677
                }
            }

            //��� ��������� ������
            var Item = oDocument.Content[oDocument.CurPos.ContentPos];
            if( type_Table == Item.GetType() && null != Item.CurCell)
            {
                this.dMaxWidth = this._CalcMaxWidthByCell(Item.CurCell);
                oDocument = this._GetTargetDocument(Item.CurCell.Content);
            }
        }
        else
        {
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
2678

2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743
        }
        return oDocument;
    },
    _CalcMaxWidthByCell : function(cell)
    {
        var row = cell.Row;
        var table = row.Table;
        var grid = table.TableGrid;
        var nGridBefore = 0;
        if(null != row.Pr && null != row.Pr.GridBefore)
            nGridBefore = row.Pr.GridBefore;
        var nCellIndex = cell.Index;
        var nCellGrid = 1;
        if(null != cell.Pr && null != cell.Pr.GridSpan)
            nCellGrid = cell.Pr.GridSpan;
        var nMarginLeft = 0;
        if(null != cell.Pr && null != cell.Pr.TableCellMar && null != cell.Pr.TableCellMar.Left && tblwidth_Mm == cell.Pr.TableCellMar.Left.Type && null != cell.Pr.TableCellMar.Left.W)
            nMarginLeft = cell.Pr.TableCellMar.Left.W;
        else if(null != table.Pr && null != table.Pr.TableCellMar && null != table.Pr.TableCellMar.Left && tblwidth_Mm == table.Pr.TableCellMar.Left.Type && null != table.Pr.TableCellMar.Left.W)
            nMarginLeft = table.Pr.TableCellMar.Left.W;
        var nMarginRight = 0;
        if(null != cell.Pr && null != cell.Pr.TableCellMar && null != cell.Pr.TableCellMar.Right && tblwidth_Mm == cell.Pr.TableCellMar.Right.Type && null != cell.Pr.TableCellMar.Right.W)
            nMarginRight = cell.Pr.TableCellMar.Right.W;
        else if(null != table.Pr && null != table.Pr.TableCellMar && null != table.Pr.TableCellMar.Right && tblwidth_Mm == table.Pr.TableCellMar.Right.Type && null != table.Pr.TableCellMar.Right.W)
            nMarginRight = table.Pr.TableCellMar.Right.W;
        var nPrevSumGrid = nGridBefore;
        for(var i = 0; i < nCellIndex; ++i)
        {
            var oTmpCell = row.Content[i];
            var nGridSpan = 1;
            if(null != cell.Pr && null != cell.Pr.GridSpan)
                nGridSpan = cell.Pr.GridSpan;
            nPrevSumGrid += nGridSpan;
        }
        var dCellWidth = 0;
        for(var i = nPrevSumGrid, length = grid.length; i < nPrevSumGrid + nCellGrid && i < length; ++i)
            dCellWidth += grid[i];

        if(dCellWidth - nMarginLeft - nMarginRight <= 0)
            dCellWidth = 4;
        else
            dCellWidth -= nMarginLeft + nMarginRight;
        return dCellWidth;
    },
    InsertInDocument : function()
    {
        var oDocument = this.oDocument;

        var nInsertLength = this.aContent.length;
        if(nInsertLength > 0)
        {
            this.InsertInPlace(oDocument, this.aContent);
            if(false == g_bIsDocumentCopyPaste)
            {
                oDocument.Recalculate();
                if(oDocument.Parent != null && oDocument.Parent.txBody != null)
                {
                    oDocument.Parent.txBody.recalculate();
                }
            }
        }

        if(false == this.bNested && nInsertLength > 0)
        {
            this.oRecalcDocument.Recalculate();
2744
            
2745
            if( oDocument.CurPos.Type !== docpostype_DrawingObjects || true === this.oLogicDocument.DrawingObjects.isSelectedText() )
2746
            {
2747
                this.oLogicDocument.Cursor_MoveRight(false, false, true);
2748
            }
2749
            
2750 2751
            this.oLogicDocument.Document_UpdateInterfaceState();
        }
Oleg.Korshul's avatar
 
Oleg.Korshul committed
2752 2753

        window.GlobalPasteFlagCounter = 0;
2754 2755 2756
    },
    InsertInPlace : function(oDoc, aNewContent)
    {
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
2757 2758
        if(!g_bIsDocumentCopyPaste)
            return;
2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773
        var paragraph = oDoc.Content[oDoc.CurPos.ContentPos];
        if (null != paragraph && type_Paragraph == paragraph.GetType()) {
            var NearPos = { Paragraph: paragraph, ContentPos: paragraph.Get_ParaContentPos(false, false) };
            paragraph.Check_NearestPos(NearPos);
            //делаем небольшой сдвиг по y, потому что сама точка TargetPos для двухстрочного параграфа определяется как верхняя
            //var NearPos = oDoc.Get_NearestPos(this.oLogicDocument.TargetPos.PageNum, this.oLogicDocument.TargetPos.X, this.oLogicDocument.TargetPos.Y + 0.05);//0.05 == 2pix
            var oSelectedContent = new CSelectedContent();
            for (var i = 0, length = aNewContent.length; i < length; ++i) {
                var oSelectedElement = new CSelectedElement();
                oSelectedElement.Element = aNewContent[i];
                if (i == length - 1 && true != this.bInBlock && type_Paragraph == oSelectedElement.Element.GetType())
                    oSelectedElement.SelectedAll = false;
                else
                    oSelectedElement.SelectedAll = true;
                oSelectedContent.Add(oSelectedElement);
Sergey.Konovalov's avatar
Sergey.Konovalov committed
2774
            }
2775
            oDoc.Insert_Content(oSelectedContent, NearPos);
2776 2777 2778 2779
			
			this._selectShapesBeforeInsert(aNewContent, oDoc);
			
            paragraph.Clear_NearestPosArray(aNewContent);
2780 2781
        }
    },
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
2782 2783 2784 2785 2786 2787


    insertInPlace2: function(oDoc, aNewContent)
    {
        var nNewContentLength = aNewContent.length;
        //����� ���� �� Document.Add_NewParagraph
2788

Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
2789 2790 2791
        for(var i = 0; i < aNewContent.length; ++i)
        {
            aNewContent[i].Clear_TextFormatting();
2792
            aNewContent[i].Clear_Formatting(true);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
2793
        }
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
2794
        oDoc.Remove(1, true, true);
2795
        var Item = oDoc.Content[oDoc.CurPos.ContentPos];
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
2796 2797
        if( type_Paragraph == Item.GetType() )
        {
2798
            if(/*true != this.bInBlock &&*/ 1 == nNewContentLength && type_Paragraph == aNewContent[0].GetType() && Item.CurPos.ContentPos != 1)
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
2799 2800 2801 2802 2803 2804
            {
                //������� ������ � ��������
                var oInsertPar = aNewContent[0];
                var nContentLength = oInsertPar.Content.length;
                if(nContentLength > 2)
                {
2805 2806 2807 2808 2809 2810
                    var oFindObj = Item.Internal_FindBackward(Item.CurPos.ContentPos, [para_TextPr]);
                    var TextPr = null;
					if ( true === oFindObj.Found && para_TextPr === oFindObj.Type )
						TextPr = Item.Content[oFindObj.LetterPos].Copy();
					else
						TextPr = new ParaTextPr();
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
2811 2812 2813 2814 2815 2816 2817 2818 2819 2820
                    var nContentPos = Item.CurPos.ContentPos;
                    for(var i = 0; i < nContentLength - 2; ++i)// -2 �� ����������� ����� ���������
                    {
                        var oCurInsItem = oInsertPar.Content[i];
                        if(para_Numbering != oCurInsItem.Type)
                        {
                            Item.Internal_Content_Add(nContentPos, oCurInsItem);
                            nContentPos++;
                        }
                    }
2821
                    Item.Internal_Content_Add(nContentPos, TextPr);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833
                }
                Item.RecalcInfo.Set_Type_0(pararecalc_0_All);
                Item.RecalcInfo.Set_Type_0_Spell(pararecalc_0_Spell_All);
                this.oRecalcDocument.ContentLastChangePos = this.oRecalcDocument.CurPos.ContentPos;
            }
            else
            {
                var LastPos = this.oRecalcDocument.CurPos.ContentPos;
                var LastPosCurDoc = oDoc.CurPos.ContentPos;
                //����� ��������� ��������
                var oSourceFirstPar = Item;
                var oSourceLastPar = new Paragraph(oDoc.DrawingDocument, oDoc, 0, 50, 50, X_Right_Field, Y_Bottom_Field );
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
2834
                if(true !== oSourceFirstPar.Cursor_IsEnd() || oSourceFirstPar.IsEmpty())
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850
                    oSourceFirstPar.Split(oSourceLastPar);
                var oInsFirstPar = aNewContent[0];
                var oInsLastPar = null;
                if(nNewContentLength > 1)
                    oInsLastPar = aNewContent[nNewContentLength - 1];

                var nStartIndex = 0;
                var nEndIndex = nNewContentLength - 1;

                if(type_Paragraph == oInsFirstPar.GetType())
                {
                    //�������� �������� ������� ������������ ��������� � ������ �������� ��������
                    //CopyPr_Open - ������� � �������, �.�. ���� �������� ��� � ���������
                    oInsFirstPar.CopyPr_Open( oSourceFirstPar );
                    //�������� ���������� ������������ ���������
                    oSourceFirstPar.Concat(oInsFirstPar);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
2851 2852 2853 2854
                    if(isRealObject(oInsFirstPar.bullet))
                    {
                        oSourceFirstPar.setPresentationBullet(oInsFirstPar.bullet.createDuplicate());
                    }
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871
                    //�������� ��������� ������ ����� ������ �� ��������� ���� ��������
                    nStartIndex++;
                }
                else if(type_Table == oInsFirstPar.GetType())
                {
                    //���� ��������� ������� � ������ ��������, �� �� ��������� ���
                    if(oSourceFirstPar.IsEmpty())
                    {
                        oSourceFirstPar = null;
                    }
                }
                //���� �� ���������� ������ ����� ���������, �� ��������� ���������� ���������� ��������� � ������ ������ �������� ��������� ���������
                if(null != oInsLastPar && type_Paragraph == oInsLastPar.GetType() && true != this.bInBlock)
                {
                    var nNewContentPos = oInsLastPar.Content.length - 2;
                    //�������� �������� ���������� ��������� ��������� � ���������  ����������� ��������
                    //CopyPr - �� ������� � �������, �.�. � ������� ��������� ������� ����� ��������� � ��������
2872
                    var ind = oInsLastPar.Pr.Ind;
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
2873 2874
                    if(null != oInsLastPar)
                        oSourceLastPar.CopyPr( oInsLastPar );
2875 2876 2877 2878
                    if(oInsLastPar.bullet)
                    {
                        oInsLastPar.Set_Ind(ind);
                    }
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908
                    oInsLastPar.Concat(oSourceLastPar);
                    oInsLastPar.CurPos.ContentPos = nNewContentPos;
                    oSourceLastPar = oInsLastPar;
                    nEndIndex--;
                }
                //���������
                for(var i = nStartIndex; i <= nEndIndex; ++i )
                {
                    var oElemToAdd = aNewContent[i];
                    LastPosCurDoc++;
                    oDoc.Internal_Content_Add(LastPosCurDoc, oElemToAdd);
                }
                if(null != oSourceLastPar)
                {
                    //��������� ��������� ��������
                    LastPosCurDoc++;
                    oDoc.Internal_Content_Add(LastPosCurDoc, oSourceLastPar);
                }
                if(null == oSourceFirstPar)
                {
                    //������� ������ ��������, ������ ��� ����� ������ ���� � ��������� �� ����� �� ������ ���������
                    oDoc.Internal_Content_Remove(LastPosCurDoc, 1);
                    LastPosCurDoc--;
                }
                this.oRecalcDocument.ContentLastChangePos = LastPos;
                Item.RecalcInfo.Set_Type_0(pararecalc_0_All);
                Item.RecalcInfo.Set_Type_0_Spell(pararecalc_0_Spell_All);
                oDoc.CurPos.ContentPos = LastPosCurDoc;
            }
        }
2909 2910 2911 2912
		
		var content = oDoc.Content;
		for(var  i = 0;  i < content.length; ++i)
		{
2913
            content[i].Recalc_CompiledPr();
2914 2915 2916
			content[i].RecalcInfo.Set_Type_0(pararecalc_0_All);
		}
	},
2917 2918
    ReadFromBinary : function(sBase64)
	{
2919 2920
        var openParams = { checkFileSize: false, charCount: 0, parCount: 0 };
        var oBinaryFileReader = new BinaryFileReader(this.oDocument, openParams);
Igor.Zotov's avatar
Igor.Zotov committed
2921
        var oRes = oBinaryFileReader.ReadFromString(sBase64, true);
2922 2923
        this.bInBlock = oRes.bInBlock;
        return oRes;
2924
	},
2925
	Start : function(node, nodeDisplay, bDuplicate)
2926
    {
2927 2928
		if(null == nodeDisplay)
			nodeDisplay = node;
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
2929 2930 2931
		if(g_bIsDocumentCopyPaste)
        {
            var oThis = this;
2932 2933 2934
			//удаляем в начале, иначе может получиться что будем вставлять в элементы, которое потом удалим.
			//todo с удалением в начале есть проблема, что удаляем элементы даже при пустом буфере
			this.oLogicDocument.Remove(1, true, true, true);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947
            this.oDocument = this._GetTargetDocument(this.oDocument);
            // var oPasteContent = this.ReadFromBinary(node.innerText);
            // this.aContent = oPasteContent.content;
            // oThis.api.pre_Paste(oPasteContent.fonts, oPasteContent.images, function(){
            // if(false == oThis.bNested)
            // {
            // oThis.InsertInDocument();
            // node.blur();
            // node.style.display  = ELEMENT_DISPAY_STYLE;
            // }
            // });
            // return;

Igor.Zotov's avatar
Igor.Zotov committed
2948
            if(copyPasteUseBinary)
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
2949
            {
Igor.Zotov's avatar
Igor.Zotov committed
2950
                var base64 = null, base64FromExcel = null,classNode, aContent, aContentExcel, pasteFromBinary = false;
2951 2952
				
				if(node.children[0] && node.children[0].getAttribute("class") != null && (node.children[0].getAttribute("class").indexOf("xslData;") > -1 || node.children[0].getAttribute("class").indexOf("docData;") > -1))
Igor.Zotov's avatar
Igor.Zotov committed
2953
					classNode = node.children[0].getAttribute("class");
2954
				else if(node.children[0] && node.children[0].children[0] && node.children[0].children[0].getAttribute("class") != null && (node.children[0].children[0].getAttribute("class").indexOf("xslData;") > -1 || node.children[0].children[0].getAttribute("class").indexOf("docData;") > -1))
Igor.Zotov's avatar
Igor.Zotov committed
2955
					classNode = node.children[0].children[0].getAttribute("class");
2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971
				else if(node.children[0] && node.children[0].children[0] && node.children[0].children[0].children[0] && node.children[0].children[0].children[0].getAttribute("class") != null && (node.children[0].children[0].children[0].getAttribute("class").indexOf("xslData;") > -1 || node.children[0].children[0].children[0].getAttribute("class").indexOf("docData;") > -1))
					classNode = node.children[0].children[0].children[0].getAttribute("class");
				
				if( classNode != null ){
					var cL = classNode.split(" ");
					for (var i = 0; i < cL.length; i++){
						if(cL[i].indexOf("xslData;") > -1)
						{
							base64FromExcel = cL[i].split('xslData;')[1];
						}
						else if(cL[i].indexOf("docData;") > -1)
						{
							base64 = cL[i].split('docData;')[1];
						}
					}
				};
Igor.Zotov's avatar
Igor.Zotov committed
2972
				
Oleg.Korshul's avatar
 
Oleg.Korshul committed
2973
				//если находимся внутри шейп, вставляем html
2974
				if(this.oDocument.Parent && this.oDocument.Parent instanceof CShape)
2975
				{
2976 2977
					if(oThis.oDocument && oThis.oDocument.Parent && oThis.oDocument.Parent.parent && oThis.oDocument.Parent.parent.parent && oThis.oDocument.Parent.parent.parent.getObjectType && oThis.oDocument.Parent.parent.parent.getObjectType() == historyitem_type_Chart)
						base64 = null;
2978 2979
					base64FromExcel = null;
				}
2980 2981 2982 2983 2984 2985
				else if(this.oDocument.bPresentation)
				{
					base64 = null;
					base64FromExcel = null;
					this.pasteInPresentationShape = true;
				};
2986 2987
				
				var isImageInNode = node.getElementsByTagName('img') && node.getElementsByTagName('img').length ? true : false;
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
2988 2989
                if(base64 != null)
                    aContent = this.ReadFromBinary(base64);
2990
				else if(base64FromExcel != null && isImageInNode)
2991 2992 2993 2994
					aContentExcel = this._readFromBinaryExcel(base64FromExcel);
				
				if(aContentExcel)
					aContent = this._convertExcelBinary(aContentExcel);
2995
					
Igor.Zotov's avatar
Igor.Zotov committed
2996 2997 2998 2999 3000 3001
				if(base64 != null && aContent)
					pasteFromBinary = true;
				else if(aContentExcel != null && aContent && aContent.content)
					pasteFromBinary = true;
				
				if(pasteFromBinary)
3002
                {
3003
					var fPrepasteCallback = function(){
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3004 3005 3006
                        if(false == oThis.bNested)
                        {
                            oThis.InsertInDocument();
3007 3008
                            nodeDisplay.blur();
                            nodeDisplay.style.display  = ELEMENT_DISPAY_STYLE;
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029
                            if(aContent.bAddNewStyles)
                                oThis.api.GenerateStyles();
                        }
                    }
                    this.aContent = aContent.content;
                    var oImagesToDownload = {};
                    if(aContent.aPastedImages.length > 0)
                    {
                        for(var i = 0, length = aContent.aPastedImages.length; i < length; ++i)
                        {
                            var imageElem = aContent.aPastedImages[i];
                            var src = imageElem.Url;
                            if(false == (0 == src.indexOf("data:") || 0 == src.indexOf(documentOrigin + this.api.DocumentUrl) || 0 == src.indexOf(this.api.DocumentUrl)))
                                oImagesToDownload[src] = 1;
                        }
                    }
                    var aImagesToDownload = [];
                    for(var i in oImagesToDownload)
                        aImagesToDownload.push(i);
                    if(aImagesToDownload.length > 0)
                    {
3030
                        var rData = {"id":documentId, "c":"imgurls", "vkey": documentVKey, "data": JSON.stringify(aImagesToDownload)};
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053
                        sendCommand( this.api, function(incomeObject){
                            if(incomeObject && "imgurls" == incomeObject.type)
                            {
                                var oFromTo = JSON.parse(incomeObject.data);
                                for(var i = 0, length = aContent.images.length; i < length; ++i)
                                {
                                    var sFrom = aContent.images[i];
                                    var sTo = oFromTo[sFrom];
                                    if(sTo)
                                        aContent.images[i] = sTo;
                                }
                                for(var i = 0, length = aContent.aPastedImages.length; i < length; ++i)
                                {
                                    var imageElem = aContent.aPastedImages[i];
                                    if(null != imageElem)
                                    {
                                        var sNewSrc = oFromTo[imageElem.Url];
                                        if(null != sNewSrc)
                                            imageElem.SetUrl(sNewSrc);
                                    }
                                }
                            }
                            oThis.api.pre_Paste(aContent.fonts, aContent.images, fPrepasteCallback);
Sergey.Konovalov's avatar
 
Sergey.Konovalov committed
3054
                        }, rData );
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3055 3056 3057 3058
                    }
                    else
                        oThis.api.pre_Paste(aContent.fonts, aContent.images, fPrepasteCallback);
                    return;
3059 3060
                };
            };
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3061

Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3062
            var presentation = editor.WordControl.m_oLogicDocument;
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3063
            this.oRootNode = node;
3064
			this.bIsPlainText = this._CheckIsPlainText(node);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3065 3066
            this._Prepeare(node,
                function(){
Alexander.Trofimov's avatar
Alexander.Trofimov committed
3067
                    oThis.aContent = [];
3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098
                    
					//если находимся внутри текстовой области диаграммы, то не вставляем ссылки
					if(oThis.oDocument && oThis.oDocument.Parent && oThis.oDocument.Parent.parent && oThis.oDocument.Parent.parent.parent && oThis.oDocument.Parent.parent.parent.getObjectType && oThis.oDocument.Parent.parent.parent.getObjectType() == historyitem_type_Chart)
					{
						var hyperlinks = node.getElementsByTagName("a");
						if(hyperlinks && hyperlinks.length)
						{
							var newElement;
							for(var i = 0; i < hyperlinks.length; i++)
							{
								newElement = document.createElement("span");
								newElement.style = hyperlinks[i].style;
								
								$(newElement).append(hyperlinks[i].children);
								
								hyperlinks[i].parentNode.replaceChild(newElement, hyperlinks[i]);
							}
						}
						
						//Todo пока сделал так, чтобы не вставлялись графические объекты в название диаграммы, потом нужно будет сделать так же запутанно, как в MS
						var images = node.getElementsByTagName("img");
						if(images && images.length)
						{
							for(var i = 0; i < images.length; i++)
							{	
								images[i].parentNode.removeChild(images[i]);
							}
						}
					}
					
					//�� ����� ���������� �������� ��� ������� ��������� �������
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3099
                    oThis._Execute(node, {}, true, true, false);
3100
						
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3101 3102 3103 3104
                    oThis._AddNextPrevToContent(oThis.oDocument);
                    if(false == oThis.bNested)
                    {
                        oThis.InsertInDocument();
3105 3106
						nodeDisplay.blur();
						nodeDisplay.style.display  = ELEMENT_DISPAY_STYLE;
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3107 3108 3109 3110 3111
                    }
                });
        }
        else
        {
Oleg.Korshul's avatar
 
Oleg.Korshul committed
3112
            var oThis = this;
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3113
            var presentation = editor.WordControl.m_oLogicDocument;
Igor.Zotov's avatar
Igor.Zotov committed
3114
            if(copyPasteUseBinary)
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3115 3116 3117 3118 3119 3120 3121 3122 3123 3124
            {
                var base64 = null;
                var classNode;
                if(node.children[0] && node.children[0].getAttribute("class") != null)
                    classNode = node.children[0].getAttribute("class");
                else if(node.children[0] && node.children[0].children[0] && node.children[0].children[0].getAttribute("class") != null)
                    classNode = node.children[0].children[0].getAttribute("class");
                if( classNode != null ){
                    cL = classNode.split(" ");
                    for (var i = 0; i < cL.length; i++){
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3125
                        if(cL[i].indexOf("pptData;") > -1)
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3126
                        {
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3127
                            base64 = cL[i].split('pptData;')[1];
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3128 3129
                        }
                    }
3130
                }
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3131 3132 3133 3134 3135 3136 3137 3138 3139 3140
                if(typeof base64 === "string")
                {
                    var _stream = CreateBinaryReader(base64, 0, base64.length);
                    var stream = new FileStream(_stream.data, _stream.size);
                    var first_string = stream.GetString2();
                    var p_url = stream.GetString2();
                    var p_width = stream.GetULong()/100000;
                    var p_height = stream.GetULong()/100000;
                    var kw = presentation.Width/p_width;
                    var kh = presentation.Height/p_height;
3141
                    var fonts = [];
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3142 3143 3144 3145 3146
                    switch(first_string)
                    {
                        case "TeamLab1":
                        {
                            var shape = this.ReadPresentationText(stream);
3147
                            var font_map = {};
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3148
                            var images = [];
3149
                            shape.getAllFonts(font_map);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3150 3151
                            if(shape.getAllImages)
                                shape.getAllImages(images);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3152 3153 3154 3155 3156 3157
                            var presentation = editor.WordControl.m_oLogicDocument;
                            oThis = this;
                            var paste_callback = function()
                            {
                                if(false == oThis.bNested)
                                {
3158 3159 3160 3161 3162 3163
                                    var b_add_slide = false;
                                    if(presentation.Slides.length === 0)
                                    {
                                        presentation.addNextSlide();
                                        b_add_slide = true;
                                    }
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3164 3165 3166 3167 3168
                                    var slide = presentation.Slides[presentation.CurPage];
                                    switch(slide.graphicObjects.State.id)
                                    {
                                        case STATES_ID_TEXT_ADD:
                                        case STATES_ID_TEXT_ADD_IN_GROUP:
3169
                                        case STATES_ID_CHART_TEXT_ADD:
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3170 3171 3172
                                        {
                                            if(presentation.Document_Is_SelectionLocked(changestype_Drawing_Props) === false)
                                            {
3173
                                                var content = (slide.graphicObjects.State.textObject instanceof CShape || slide.graphicObjects.State.textObject instanceof CChartTitle) ? slide.graphicObjects.State.textObject.txBody.content : slide.graphicObjects.State.textObject.graphicObject.CurCell.Content;
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3174
                                                oThis.insertInPlace2(content, shape.txBody.content.Content);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3175 3176
                                                shape.txBody.content = new CDocumentContent(shape.txBody, editor.WordControl.m_oDrawingDocument, 0 , 0, 0, 0, false, false);
                                                shape.txBody.setDocContent(shape.txBody.content);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3177 3178 3179 3180 3181 3182
                                                if(slide.graphicObjects.State.textObject instanceof CShape)
                                                    slide.graphicObjects.State.textObject.txBody.bRecalculateNumbering = true;
                                                else
                                                    slide.graphicObjects.State.textObject.recalcInfo.recalculateNumbering = true
                                                var content2 = content.Content;
                                                for(var j = 0; j < content2.length; ++j)
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3183
                                                {
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3184 3185
                                                    content2[j].RecalcInfo.Set_Type_0(pararecalc_0_All);
                                                    content2[j].Set_Parent(content);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3186 3187 3188
                                                }
                                                slide.graphicObjects.State.textObject.recalcInfo.recalculateContent = true;
                                                slide.graphicObjects.State.textObject.recalcInfo.recalculateTransformText = true;
3189 3190 3191

                                                var recalc_object = !(slide.graphicObjects.State.textObject instanceof CChartTitle) ? slide.graphicObjects.State.textObject : slide.graphicObjects.State.textObject.chartGroup;
                                                editor.WordControl.m_oLogicDocument.recalcMap[recalc_object.Id] = recalc_object;
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3192 3193 3194 3195 3196
                                            }
                                            break;
                                        }
                                        default :
                                        {
3197
                                            if(presentation.Document_Is_SelectionLocked(changestype_AddShape, shape) === false)
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3198
                                            {
3199 3200 3201
                                                if(b_add_slide)
                                                {
                                                    shape.setParent(presentation.Slides[0]);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3202
                                                    slide = presentation.Slides[0];
3203
                                                }
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3204 3205
                                                slide.graphicObjects.resetSelectionState();
                                                shape.select(slide.graphicObjects);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3206 3207 3208 3209
                                                slide.addToSpTreeToPos(slide.cSld.spTree.length, shape);
                                                var w =  shape.txBody.getRectWidth(presentation.Width*2/3);
                                                var h = shape.txBody.getRectHeight(2000, w);
                                                shape.setXfrm((presentation.Width - w)/2, (presentation.Height - h)/2, w, h, null, null, null);
3210 3211 3212
                                                shape.getAllFonts(font_map);
                                                for(var i in font_map)
                                                    fonts.push(new CFont(i, 0, "", 0));
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3213 3214 3215 3216 3217 3218
                                                editor.WordControl.m_oLogicDocument.recalcMap[shape.Id] = shape;
                                            }
                                            break;
                                        }
                                    }
                                    presentation.Recalculate();
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3219 3220
                                    presentation.Document_UpdateInterfaceState();

3221 3222
                                    nodeDisplay.blur();
                                    nodeDisplay.style.display  = ELEMENT_DISPAY_STYLE;
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3223 3224
                                }
                            };
3225

Alexander.Trofimov's avatar
Alexander.Trofimov committed
3226
                            var oPrepeareImages = {};
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3227
                            this.api.pre_Paste(fonts, oPrepeareImages, paste_callback);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3228 3229 3230 3231
                            return;
                        }
                        case "TeamLab2":
                        {
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3232 3233
                            var objects = this.ReadPresentationShapes(stream);
                            var arr_shapes = objects.arrShapes;
3234
                            var arrTransforms = objects.arrTransforms;
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3235 3236
                            var presentation = editor.WordControl.m_oLogicDocument;
                            oThis = this;
3237
                            var font_map = {};
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3238
                            var images = [];
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3239 3240 3241
                            for(var i = 0; i < arr_shapes.length; ++i)
                            {
                                if(arr_shapes[i].getAllFonts)
3242
                                    arr_shapes[i].getAllFonts(font_map);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3243 3244
                                if(arr_shapes[i].getAllImages)
                                    arr_shapes[i].getAllImages(images);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3245 3246 3247 3248 3249
                            }
                            var paste_callback = function()
                            {
                                if(false == oThis.bNested)
                                {
3250 3251 3252 3253 3254 3255
                                    var b_add_slide = false;
                                    if(presentation.Slides.length === 0)
                                    {
                                        presentation.addNextSlide();
                                        b_add_slide = true;
                                    }
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3256
                                    var slide = presentation.Slides[presentation.CurPage];
3257
                                    if(presentation.Document_Is_SelectionLocked(changestype_AddShapes, arr_shapes) === false)
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3258
                                    {
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3259
                                        slide.graphicObjects.resetSelectionState();
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3260 3261
                                        for(var i = 0; i < arr_shapes.length; ++i)
                                        {
3262 3263 3264 3265
                                            if(b_add_slide)
                                            {
                                                arr_shapes[i].setParent(presentation.Slides[0]);
                                            }
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3266
                                            arr_shapes[i].changeSize(kw, kh);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3267
                                            slide.addToSpTreeToPos(slide.cSld.spTree.length, arr_shapes[i]);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3268
                                            arr_shapes[i].select(slide.graphicObjects);
3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280
                                            var current_shape = arr_shapes[i];
                                            if(!current_shape.checkNotNullTransform() && arrTransforms[i])
                                            {
                                                var t = arrTransforms[i];
                                                current_shape.setOffset(t.x, t.y);
                                                current_shape.setExtents(t.extX, t.extY);
                                                if(current_shape instanceof CGroupShape)
                                                {
                                                    current_shape.setChildOffset(0, 0);
                                                    current_shape.setChildExtents(t.extX, t.extY);
                                                }
                                            }
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3281 3282 3283
                                        }
                                    }
                                    presentation.Recalculate();
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3284 3285
                                    presentation.Document_UpdateInterfaceState();

3286 3287
                                    nodeDisplay.blur();
                                    nodeDisplay.style.display  = ELEMENT_DISPAY_STYLE;
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3288 3289 3290
                                }
                            };

Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302
                            var oImagesToDownload = {};
                            if(objects.arrImages.length > 0)
                            {
                                for(var i = 0, length = objects.arrImages.length; i < length; ++i)
                                {
                                    var imageElem = objects.arrImages[i];
                                    var src = imageElem.Url;
                                    if(false == (0 == src.indexOf("data:") || 0 == src.indexOf(documentOrigin + this.api.DocumentUrl) || 0 == src.indexOf(this.api.DocumentUrl)))
                                        oImagesToDownload[src] = 1;
                                }
                            }

3303 3304
                            for(var i in font_map)
                                fonts.push(new CFont(i, 0, "", 0));
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3305 3306 3307 3308 3309
                            var aImagesToDownload = [];
                            for(var i in oImagesToDownload)
                                aImagesToDownload.push(i);
                            if(aImagesToDownload.length > 0)
                            {
3310
                                var rData = {"id":documentId, "c":"imgurls", "vkey": documentVKey, "data": JSON.stringify(aImagesToDownload)};
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335
                                sendCommand( this.api, function(incomeObject){
                                    if(incomeObject && "imgurls" == incomeObject.type)
                                    {
                                        var oFromTo = JSON.parse(incomeObject.data);

                                        var arr_images =[];
                                        var image_map = {};
                                        for(var i = 0, length = objects.arrImages.length; i < length; ++i)
                                        {
                                            var sFrom = objects.arrImages[i].Url;
                                            var sTo = oFromTo[sFrom];
                                            if(sTo)
                                                arr_images.push(sTo);
                                        }
                                        for(var i = 0, length = objects.arrImages.length; i < length; ++i)
                                        {
                                            var imageElem = objects.arrImages[i];
                                            if(null != imageElem)
                                            {
                                                var sNewSrc = oFromTo[imageElem.Url];
                                                if(null != sNewSrc)
                                                {
                                                    image_map[sNewSrc] = sNewSrc;
                                                    imageElem.SetUrl(sNewSrc);
                                                }
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3336 3337 3338 3339
                                                else
                                                {
                                                    image_map[imageElem.Url] = imageElem.Url;
                                                }
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3340 3341 3342 3343
                                            }
                                        }
                                    }
                                    oThis.api.pre_Paste(fonts, image_map, paste_callback);
Sergey.Konovalov's avatar
 
Sergey.Konovalov committed
3344
                                }, rData );
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3345 3346 3347
                            }
                            else
                            {
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3348 3349 3350 3351
                                var im_arr = [];
                                for(var key  in images)
                                    im_arr.push(key);
                                this.api.pre_Paste(fonts, im_arr, paste_callback);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3352
                            }
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3353 3354 3355 3356 3357 3358 3359
                            return;
                        }
                        case "TeamLab3":
                        {
                            var arr_layouts_id = [];
                            var arr_slides = [];
                            var loader = new BinaryPPTYLoader();
3360 3361
                            if(!(bDuplicate === true))
                                loader.Start_UseFullUrl();
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3362 3363 3364
                            loader.stream = stream;
                            loader.presentation = editor.WordControl.m_oLogicDocument;
                            var slide_count = stream.GetULong();
3365
                            var arr_arrTransforms = [];
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3366 3367 3368
                            for(var i = 0; i < slide_count; ++i)
                            {
                                arr_layouts_id[i] = stream.GetString2();
3369
                                var table_style_ids_len = stream.GetULong();
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3370
                                var table_style_ids = [];
3371
                                for(var j = 0; j < table_style_ids_len; ++j)
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3372 3373 3374 3375 3376 3377
                                {
                                    if(stream.GetBool())
                                        table_style_ids.push(stream.GetULong());
                                    else
                                        table_style_ids.push(-1);
                                }
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3378
                                arr_slides[i] = loader.ReadSlide(0);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3379 3380 3381 3382 3383 3384 3385 3386 3387 3388
                                var sp_tree = arr_slides[i].cSld.spTree;
                                var t = 0;
                                for(var s = 0; s < sp_tree.length; ++s)
                                {
                                    if(sp_tree[s] instanceof CGraphicFrame)
                                    {
                                        sp_tree[s].graphicObject.setStyleIndex(table_style_ids[t]);
                                        ++t;
                                    }
                                }
3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400
                                var arrTransforms = [];
                                var sp_tree_length = stream.GetULong();
                                for(s = 0; s < sp_tree_length; ++s)
                                {
                                    var transform_object = {};
                                    transform_object.x = stream.GetULong()/100000;
                                    transform_object.y = stream.GetULong()/100000;
                                    transform_object.extX = stream.GetULong()/100000;
                                    transform_object.extY = stream.GetULong()/100000;
                                    arrTransforms.push(transform_object);
                                }
                                arr_arrTransforms.push(arrTransforms);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3401 3402 3403
                            }

                            var arr_layouts = [];
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3404 3405 3406 3407 3408 3409

                            var master;
                            if(presentation.Slides[presentation.CurPage])
                                master = presentation.Slides[presentation.CurPage].Layout.Master;
                            else
                                master = presentation.slideMasters[0];
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421
                            if(editor.DocumentUrl !== p_url)
                            {
                                var layouts_count = stream.GetULong();
                                for(var i = 0; i < layouts_count; ++i)
                                {
                                    arr_layouts[i] = loader.ReadSlideLayout()
                                }
                                var arr_indexes = [];
                                for(var i = 0; i < slide_count; ++i)
                                {
                                    arr_indexes.push(stream.GetULong());
                                }
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3422

Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3423 3424 3425 3426
                                for(var i = 0; i < layouts_count; ++i)
                                {
                                    arr_layouts[i].setMaster(master);
                                    arr_layouts[i].changeSize(kw, kh);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3427 3428
                                    arr_layouts[i].Width = presentation.Width;
                                    arr_layouts[i].Height = presentation.Height;
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3429 3430 3431 3432 3433 3434
                                    master.addLayout(arr_layouts[i]);
                                }
                                for(var i =0; i < slide_count; ++i)
                                {
                                    arr_slides[i].changeSize(kw, kh);
                                    arr_slides[i].setLayout(arr_layouts[arr_indexes[i]]);
3435
                                    arr_slides[i].setSlideSize(presentation.Width, presentation.Height);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3436 3437 3438 3439
                                }
                            }
                            else
                            {
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461
                                var arr_matched_layout = [];
                                var b_read_layouts = false;
                                for(var i = 0; i < arr_layouts_id.length; ++i)
                                {
                                    if(!isRealObject(g_oTableId.Get_ById(arr_layouts_id[i])))
                                    {
                                        b_read_layouts = true;
                                        break;
                                    }
                                }
                                if(b_read_layouts)
                                {
                                    var layouts_count = stream.GetULong();
                                    for(var i = 0; i < layouts_count; ++i)
                                    {
                                        arr_layouts[i] = loader.ReadSlideLayout()
                                    }
                                    var arr_indexes = [];
                                    for(var i = 0; i < slide_count; ++i)
                                    {
                                        arr_indexes.push(stream.GetULong());
                                    }
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3462

Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3463 3464 3465 3466 3467 3468
                                    var addedLayouts = [];
                                    for(var i = 0; i < slide_count; ++i)
                                    {
                                        if(isRealObject(g_oTableId.Get_ById(arr_layouts_id[i])))
                                        {
                                            arr_slides[i].changeSize(kw, kh);
3469
                                            arr_slides[i].setSlideSize(presentation.Width, presentation.Height);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3470 3471 3472 3473 3474
                                            arr_slides[i].setLayout(g_oTableId.Get_ById(arr_layouts_id[i]));
                                        }
                                        else
                                        {
                                            arr_slides[i].changeSize(kw, kh);
3475
                                            arr_slides[i].setSlideSize(presentation.Width, presentation.Height);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497
                                            arr_slides[i].setLayout(arr_layouts[arr_indexes[i]]);
                                            for(var j = 0; j < addedLayouts.length; ++j)
                                            {
                                                if(addedLayouts[j] === arr_layouts[arr_indexes[i]])
                                                    break;
                                            }
                                            if(j === addedLayouts.length)
                                            {
                                                addedLayouts.push(arr_layouts[arr_indexes[i]]);
                                                arr_layouts[arr_indexes[i]].setMaster(master);
                                                arr_layouts[arr_indexes[i]].changeSize(kw, kh);
                                                arr_layouts[arr_indexes[i]].Width = presentation.Width;
                                                arr_layouts[arr_indexes[i]].Height = presentation.Height;
                                            }
                                        }
                                    }
                                }
                                else
                                {
                                    for(var i =0; i < slide_count; ++i)
                                    {
                                        arr_slides[i].changeSize(kw, kh);
3498
                                        arr_slides[i].setSlideSize(presentation.Width, presentation.Height);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3499 3500 3501 3502 3503
                                        arr_slides[i].setLayout(g_oTableId.Get_ById(arr_layouts_id[i]));
                                        arr_slides[i].Width = presentation.Width;
                                        arr_slides[i].Height = presentation.Height;
                                    }
                                }
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3504 3505 3506
                            }


Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3507

Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3508 3509
                            var presentation = editor.WordControl.m_oLogicDocument;
                            oThis = this;
3510
                            var font_map = {};
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3511
                            var images = [];
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3512 3513 3514
                            for(var i = 0; i < arr_slides.length; ++i)
                            {
                                if(arr_slides[i].getAllFonts)
3515
                                    arr_slides[i].getAllFonts(font_map);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3516 3517
                                if(arr_slides[i].getAllImages)
                                    arr_slides[i].getAllImages(images);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3518
                            }
3519 3520 3521 3522 3523 3524 3525 3526 3527 3528

                            for(var i = 0; i < arr_layouts.length; ++i)
                            {
                                if(arr_layouts[i].getAllFonts)
                                    arr_layouts[i].getAllFonts(font_map);
                                if(arr_layouts[i].getAllImages)
                                    arr_layouts[i].getAllImages(images);
                            }
                            for(var i in font_map)
                                fonts.push(new CFont(i, 0, "", 0));
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3529 3530 3531 3532 3533 3534
                            var paste_callback = function()
                            {
                                if(false == oThis.bNested)
                                {
                                    for(var i = 0; i < arr_slides.length; ++i)
                                    {
3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553
                                        var cur_arr_transform = arr_arrTransforms[i];
                                        var cur_slide = arr_slides[i];
                                        var sp_tree = cur_slide.cSld.spTree;
                                        for(var j = 0; j < sp_tree.length; ++j)
                                        {
                                            var sp = sp_tree[j];
                                            if(!sp.checkNotNullTransform() && cur_arr_transform && cur_arr_transform[j])
                                            {
                                                var t_object = cur_arr_transform[j];
                                                sp.setOffset(t_object.x, t_object.y);
                                                sp.setExtents(t_object.extX, t_object.extY);
                                                if(sp instanceof CGroupShape)
                                                {
                                                    sp.setChildOffset(0, 0);
                                                    sp.setChildExtents(t_object.extX, t_object.extY);
                                                }
                                            }
                                        }
                                        presentation.insertSlide(presentation.CurPage + i+1, cur_slide);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3554 3555
                                    }
                                    presentation.Recalculate();
3556 3557
                                    nodeDisplay.blur();
                                    nodeDisplay.style.display  = ELEMENT_DISPAY_STYLE;
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3558 3559 3560
                                }
                            };

Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3561
                            var image_objects = loader.End_UseFullUrl();
3562
                            var objects = {arrImages:image_objects};
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579
                            var oImagesToDownload = {};
                            if(objects.arrImages.length > 0)
                            {
                                for(var i = 0, length = objects.arrImages.length; i < length; ++i)
                                {
                                    var imageElem = objects.arrImages[i];
                                    var src = imageElem.Url;
                                    if(false == (0 == src.indexOf("data:") || 0 == src.indexOf(documentOrigin + this.api.DocumentUrl) || 0 == src.indexOf(this.api.DocumentUrl)))
                                        oImagesToDownload[src] = 1;
                                }
                            }

                            var aImagesToDownload = [];
                            for(var i in oImagesToDownload)
                                aImagesToDownload.push(i);
                            if(aImagesToDownload.length > 0)
                            {
3580
                                var rData = {"id":documentId, "c":"imgurls", "vkey": documentVKey, "data": JSON.stringify(aImagesToDownload)};
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602
                                sendCommand( this.api, function(incomeObject){
                                    if(incomeObject && "imgurls" == incomeObject.type)
                                    {
                                        var oFromTo = JSON.parse(incomeObject.data);

                                        var image_map = {};
                                        for(var i = 0, length = objects.arrImages.length; i < length; ++i)
                                        {
                                            var sFrom = objects.arrImages[i].Url;
                                            var sTo = oFromTo[sFrom];
                                        }
                                        for(var i = 0, length = objects.arrImages.length; i < length; ++i)
                                        {
                                            var imageElem = objects.arrImages[i];
                                            if(null != imageElem)
                                            {
                                                var sNewSrc = oFromTo[imageElem.Url];
                                                if(null != sNewSrc)
                                                {
                                                    image_map[sNewSrc] = sNewSrc;
                                                    imageElem.SetUrl(sNewSrc);
                                                }
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3603 3604 3605 3606
                                                else
                                                {
                                                    image_map[imageElem.Url] = imageElem.Url;
                                                }
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3607 3608 3609 3610
                                            }
                                        }
                                    }
                                    oThis.api.pre_Paste(fonts, image_map, paste_callback);
Sergey.Konovalov's avatar
 
Sergey.Konovalov committed
3611
                                }, rData );
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3612 3613 3614
                            }
                            else
                            {
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3615 3616 3617 3618
                                var im_arr = [];
                                for(var key  in images)
                                    im_arr.push(key);
                                this.api.pre_Paste(fonts, im_arr, paste_callback);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3619
                            }
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3620 3621 3622 3623
                            return;
                        }
                        case "TeamLab4":
                        {
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3624 3625
                            var objects = this.ReadPresentationShapes(stream);
                            var arr_shapes = objects.arrShapes;
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3626 3627 3628
                            var presentation = editor.WordControl.m_oLogicDocument;
                            oThis = this;
                            var fonts = [];
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3629
                            var images = [];
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3630 3631 3632 3633
                            for(var i = 0; i < arr_shapes.length; ++i)
                            {
                                if(arr_shapes[i].getAllFonts)
                                    arr_shapes[i].getAllFonts(fonts);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3634 3635
                                if(arr_shapes[i].getAllImages)
                                    arr_shapes[i].getAllImages(images);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3636 3637 3638 3639 3640
                            }
                            var paste_callback = function()
                            {
                                if(false == oThis.bNested)
                                {
3641 3642
                                    var b_add_slide = false;

Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3643
                                    if(presentation.Slides.length === 0)
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3644
                                    {
3645 3646 3647 3648 3649 3650 3651
                                        presentation.addNextSlide();
                                        b_add_slide = true;
                                    }
                                    if(presentation.Document_Is_SelectionLocked(changestype_AddShapes, arr_shapes) === false)
                                    {
                                        var slide = presentation.Slides[presentation.CurPage];
                                        if(presentation.Document_Is_SelectionLocked(changestype_Drawing_Props) === false)
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3652
                                        {
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3653
                                            slide.graphicObjects.resetSelectionState();
3654 3655 3656 3657 3658 3659 3660 3661
                                            for(var i = 0; i < arr_shapes.length; ++i)
                                            {
                                                if(b_add_slide)
                                                {
                                                    arr_shapes[i].setParent(presentation.Slides[0]);
                                                }
                                                arr_shapes[i].changeSize(kw, kh);
                                                slide.addToSpTreeToPos(slide.cSld.spTree.length, arr_shapes[i]);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3662 3663
                                                arr_shapes[i].select(slide.graphicObjects);

3664
                                            }
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3665
                                        }
3666
                                        presentation.Recalculate();
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3667
                                    }
3668 3669
                                    nodeDisplay.blur();
                                    nodeDisplay.style.display  = ELEMENT_DISPAY_STYLE;
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3670 3671 3672
                                }
                            };

Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3673 3674 3675
                            var aImagesToDownload = [];
                            for(var i in images)
                                aImagesToDownload.push(i);
Alexander.Trofimov's avatar
Alexander.Trofimov committed
3676
                            var oPrepeareImages = {};
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3677 3678
                            if(aImagesToDownload.length > 0)
                            {
3679
                                var rData = {"id":documentId, "c":"imgurls", "vkey": documentVKey, "data": JSON.stringify(aImagesToDownload)};
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691
                                sendCommand( this.api, function(incomeObject){
                                    if(incomeObject && "imgurls" == incomeObject.type)
                                    {
                                        var oFromTo = JSON.parse(incomeObject.data);
                                        for(var i = 0, length = aImagesToDownload.length; i < length; ++i)
                                        {
                                            var sFrom = aImagesToDownload[i];
                                            var sTo = oFromTo[sFrom];
                                            if(sTo)
                                            {									oThis.oImages[sFrom] = sTo;									oPrepeareImages[i] = sTo;								}							}
                                    }
                                    oThis.api.pre_Paste(fonts, oPrepeareImages, paste_callback);
Sergey.Konovalov's avatar
 
Sergey.Konovalov committed
3692
                                }, rData );
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3693 3694
                            }
                            else
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3695 3696 3697
                            {
                                this.api.pre_Paste(fonts, [], paste_callback);
                            }
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3698 3699 3700 3701 3702 3703
                            return;
                        }
                    }
                }
            }

Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3704 3705 3706
            this.oRootNode = node;
            this._Prepeare(node,
                function(){
Alexander.Trofimov's avatar
Alexander.Trofimov committed
3707
                     oThis.aContent = [];
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3708
                     //�� ����� ���������� �������� ��� ������� ��������� �������
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3709 3710
                     var arrShapes = [], arrImages = [], arrTables = [];
                    var presentation = editor.WordControl.m_oLogicDocument;
3711 3712 3713 3714 3715 3716
                    var b_add_slide = false;
                    if(presentation.Slides.length === 0)
                    {
                        presentation.addNextSlide();
                        b_add_slide = true;
                    }
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3717 3718 3719 3720 3721 3722 3723 3724 3725 3726
                    var shape = new CShape(presentation.Slides[presentation.CurPage]);
                    shape.setTextBody(new CTextBody(shape));
                    var dd = presentation.DrawingDocument;
                    arrShapes.push(shape);
                    shape.setXfrm(dd.GetMMPerDot(node["offsetLeft"]), dd.GetMMPerDot(node["offsetTop"]), null, null, null, null, null);
                     var ret = oThis._ExecutePresentation(node, {}, true, true, false, arrShapes, arrImages, arrTables);

                    for(var i = 0; i < arrShapes.length; ++i)
                    {
                        shape = arrShapes[i];
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3727 3728 3729 3730
                        if(shape.txBody.content.Content.length > 1)
                        {
                            shape.txBody.content.Internal_Content_Remove(0, 1);
                        }
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3731 3732 3733 3734 3735
                        var w =  shape.txBody.getRectWidth(presentation.Width*2/3);
                        var h = shape.txBody.getRectHeight(2000, w);
                        shape.setXfrm(null, null, w, h, null, null, null);
                    }
                     //oThis._AddNextPrevToContent(oThis.oDocument);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3736 3737
                     if(false == oThis.bNested)
                     {
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3738
                         var slide = presentation.Slides[presentation.CurPage];
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3739
                         if((slide.graphicObjects.State.id === STATES_ID_TEXT_ADD || slide.graphicObjects.State.id === STATES_ID_TEXT_ADD_IN_GROUP)
3740
                             && arrShapes.length === 1 && arrImages.length === 0 && arrTables.length === 0)
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3741
                         {
3742
                             if(presentation.Document_Is_SelectionLocked(changestype_Drawing_Props) === false)
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3743
                             {
3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756
                                 var content;
                                 var textObject = slide.graphicObjects.State.textObject;

                                 if(textObject instanceof CShape)
                                 {
                                    content = textObject.txBody.content;
                                 }
                                 else
                                 {
                                    content = textObject.graphicObject.CurCell.Content;
                                 }
                                 presentation.recalcMap[textObject.Get_Id()] = textObject;
                                 oThis.insertInPlace2(content, arrShapes[0].txBody.content.Content);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3757 3758
                                 arrShapes[0].txBody.content = new CDocumentContent(arrShapes[0].txBody, editor.WordControl.m_oDrawingDocument, 0 , 0, 0, 0, false, false);
                                 arrShapes[0].txBody.setDocContent(shape.txBody.content);
3759
                                 presentation.Recalculate();
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3760 3761
                                 presentation.Document_UpdateInterfaceState();

Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3762
                             }
3763 3764 3765 3766 3767
                         }
                         else
                         {
                             var check_objectcs = arrShapes.concat(arrImages).concat(arrTables);
                             if(presentation.Document_Is_SelectionLocked(changestype_AddShapes, check_objectcs) === false)
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3768
                             {
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3769 3770 3771 3772 3773
                                 slide.graphicObjects.resetSelectionState();
                                 if(arrShapes.length ===1 && arrShapes[0].txBody.content.Is_Empty())
                                 {
                                     arrShapes.length = 0;
                                 }
3774 3775
                                 for(var i = 0; i < arrShapes.length; ++i)
                                 {
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3776 3777 3778 3779
                                     var new_pos_x = (presentation.Width -  arrShapes[i].spPr.xfrm.extX)/2;
                                     var new_pos_y = (presentation.Height -  arrShapes[i].spPr.xfrm.extY)/2;
                                     arrShapes[i].setOffset(new_pos_x, new_pos_y);
                                     arrShapes[i].select(slide.graphicObjects);
3780 3781 3782 3783 3784
                                     slide.addToSpTreeToPos(slide.cSld.spTree.length, arrShapes[i]);
                                     presentation.recalcMap[arrShapes[i].Get_Id()] = arrShapes[i];
                                 }
                                 for(var i = 0; i < arrImages.length; ++i)
                                 {
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3785 3786

                                     arrImages[i].select(slide.graphicObjects);
3787 3788 3789 3790 3791
                                     slide.addToSpTreeToPos(slide.cSld.spTree.length, arrImages[i]);
                                     presentation.recalcMap[arrImages[i].Get_Id()] = arrImages[i];
                                 }
                                 for(var i = 0; i < arrTables.length; ++i)
                                 {
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3792
                                     arrTables[i].select(slide.graphicObjects);
3793 3794 3795 3796 3797
                                     slide.addToSpTreeToPos(slide.cSld.spTree.length, arrTables[i]);
                                     arrTables[i].recalcAll();
                                     presentation.recalcMap[arrTables[i].Get_Id()] = arrTables[i];
                                 }
                                 presentation.Recalculate();
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3798 3799
                                 presentation.Document_UpdateInterfaceState();

Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3800 3801 3802
                             }
                         }
                         //oThis.InsertInDocument();
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3803 3804
                     }

3805 3806
                     nodeDisplay.blur();
                     nodeDisplay.style.display  = ELEMENT_DISPAY_STYLE;
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3807 3808 3809

                });

Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3810
        }
3811
    },
3812 3813 3814 3815 3816
	
	_convertExcelBinary: function(aContentExcel)
	{
		//пока только распознаём только графические объекты
		var aContent = null;
3817 3818
		var aPastedImages = [];
		var imageUrl, images = [];
3819 3820
		
		var drawings = aContentExcel.aWorksheets[0].Drawings;
Igor.Zotov's avatar
Igor.Zotov committed
3821
		if(drawings && drawings.length)
3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833
		{
			var drawing, graphicObj, paraRun, tempParaRun;
			
			//var wrappingType = this.oDocument.DrawingObjects.selection.groupSelection.parent.wrappingType;
			//var DrawingType = this.oDocument.DrawingObjects.selection.groupSelection.parent.DrawingType;
			
			var tempParagraph = new Paragraph(this.oDocument, this.oDocument, 0, 0, 0, 0, 0);
			
			//из excel в word они вставляются в один параграф
			for(var i = 0; i < drawings.length; i++)
			{
				drawing = drawings[i];
Igor.Zotov's avatar
Igor.Zotov committed
3834
				graphicObj = drawing.graphicObject.convertToWord(this.oLogicDocument);
3835 3836
				
				tempParaRun = new ParaRun();
3837 3838
				tempParaRun.Paragraph = null;
				tempParaRun.Add_ToContent( 0, new ParaDrawing(), false );//tempParaRun.Content.unshift(new ParaDrawing());
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3839

3840 3841 3842
				//paraRun.Content[index].wrappingType = wrappingType;
				//paraRun.Content[index].DrawingType = DrawingType;
				
3843 3844
				tempParaRun.Content[0].Set_GraphicObject(graphicObj);
				tempParaRun.Content[0].GraphicObj.setParent(tempParaRun.Content[0]);
3845
				
3846 3847 3848 3849 3850 3851 3852 3853 3854
				tempParagraph.Content.splice(tempParagraph.Content.length - 1, 0, tempParaRun);
				
				if(graphicObj.isImage())
				{	
					imageUrl = graphicObj.getImageUrl();
					
					aPastedImages[aPastedImages.length] = new CBuilderImages(graphicObj.blipFill, imageUrl);
					images[images.length] = imageUrl;
				}
3855 3856 3857 3858 3859 3860
				else if(graphicObj.spPr && graphicObj.spPr.Fill && graphicObj.spPr.Fill.fill && graphicObj.spPr.Fill.fill.RasterImageId && graphicObj.spPr.Fill.fill.RasterImageId != null)
				{
					imageUrl = graphicObj.spPr.Fill.fill.RasterImageId;
					
					//aPastedImages[aPastedImages.length] = new CBuilderImages(graphicObj.blipFill, imageUrl);
					images[images.length] = imageUrl;
3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872
				}
				else if(graphicObj.isGroup() && graphicObj.spTree && graphicObj.spTree.length)
				{
					var spTree = graphicObj.spTree;
					for(var j = 0; j < spTree.length; j++)
					{
						if(spTree[j].isImage())
						{
							images.push(spTree[j].getImageUrl());
						}
					}
				}				
3873 3874 3875 3876 3877 3878
			};
			
			aContent = [];
			aContent[0] = tempParagraph;
		};
		
3879
		return {content: aContent, aPastedImages: aPastedImages, images: images};			
3880 3881
	},
	
3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902
	_selectShapesBeforeInsert: function(aNewContent, oDoc)
	{
		var content, drawingObj, allDrawingObj = [];
		for(var i = 0; i < aNewContent.length; i++)
		{
			content = aNewContent[i];
			drawingObj = content.Get_AllDrawingObjects();
			
			if(!drawingObj || (drawingObj && !drawingObj.length) || content.GetType() == type_Table)
			{
				allDrawingObj = null;
				break;
			}
			
			for(var n = 0; n < drawingObj.length; n++)
			{
				allDrawingObj[allDrawingObj.length] = drawingObj[n];
			};
		};
		
		if(allDrawingObj && allDrawingObj.length)
3903
            this.oLogicDocument.Select_Drawings(allDrawingObj, oDoc);
3904 3905
	},
	
3906 3907 3908
	_readFromBinaryExcel: function(base64)
	{
		var oBinaryFileReader = new Asc.BinaryFileReader(null, true);
3909
		var tempWorkbook = new Workbook();
3910
        tempWorkbook.theme = this.oDocument.theme ? this.oDocument.theme : this.oLogicDocument.theme;
3911 3912 3913 3914 3915 3916
		Asc.getBinaryOtherTableGVar(tempWorkbook);
		oBinaryFileReader.Read(base64, tempWorkbook);
		
		return tempWorkbook;
	},
	
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3917 3918 3919
    ReadPresentationText: function(stream)
    {
        var loader = new BinaryPPTYLoader();
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3920
        loader.Start_UseFullUrl();
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3921 3922 3923 3924 3925 3926
        loader.stream = stream;
        loader.presentation = editor.WordControl.m_oLogicDocument;
        var presentation = editor.WordControl.m_oLogicDocument;
        var shape = new CShape(presentation.Slides[presentation.CurPage]);
        shape.setTextBody(new CTextBody(shape));
        var count = stream.GetULong();
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3927
        shape.txBody.content.Internal_Content_RemoveAll();
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939
        for(var i = 0; i < count; ++i)
        {
            loader.stream.Skip2(1); // must be 0
            var _paragraph = loader.ReadParagraph(shape.txBody.content);
            shape.txBody.content.Internal_Content_Add(shape.txBody.content.Content.length, _paragraph);
        }
        return shape;
    },

    ReadPresentationShapes: function(stream)
    {
        var loader = new BinaryPPTYLoader();
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3940
        loader.Start_UseFullUrl();
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3941 3942 3943 3944 3945
        loader.stream = stream;
        loader.presentation = editor.WordControl.m_oLogicDocument;
        var presentation = editor.WordControl.m_oLogicDocument;
        var count = stream.GetULong();
        var arr_shapes = [];
3946
        var arr_transforms = [];
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3947 3948 3949
        for(var i = 0; i < count; ++i)
        {
            loader.TempMainObject = presentation.Slides[presentation.CurPage];
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3950 3951 3952 3953 3954 3955 3956 3957
            var style_index = null;
            if(!loader.stream.GetBool())
            {
                if(loader.stream.GetBool())
                {
                    style_index = stream.GetULong();
                }
            }
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3958
            arr_shapes.push(loader.ReadGraphicObject());
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3959 3960 3961 3962 3963 3964 3965 3966 3967 3968
            if(isRealNumber(style_index))
            {
                if(arr_shapes[arr_shapes.length - 1] instanceof  CGraphicFrame)
                {
                    if(loader.presentation.globalTableStyles[style_index])
                    {
                        arr_shapes[arr_shapes.length - 1].graphicObject.setStyleIndex(style_index);
                    }
                }
            }
3969 3970 3971 3972
            if(arr_shapes[arr_shapes.length - 1] instanceof  CGraphicFrame)
            {
                arr_shapes[arr_shapes.length - 1].setGraphicObject(arr_shapes[arr_shapes.length - 1].graphicObject.Copy(arr_shapes[arr_shapes.length - 1]));
            }
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3973
            if(typeof CChartAsGroup != "undefined" && arr_shapes[arr_shapes.length - 1] instanceof  CChartAsGroup)
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3974 3975 3976 3977 3978
            {
                var chart = arr_shapes[arr_shapes.length - 1];
                var copy = chart.copy(chart.parent);
                arr_shapes[arr_shapes.length - 1] = copy;
            }
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3979
        }
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3980

3981 3982 3983 3984 3985 3986 3987 3988 3989 3990
        for(var i = 0; i < count; ++i)
        {
            var x = stream.GetULong()/100000;
            var y = stream.GetULong()/100000;
            var extX = stream.GetULong()/100000;
            var extY = stream.GetULong()/100000;
            arr_transforms.push({x:x, y:y, extX: extX, extY:extY});
        }

        return {arrShapes: arr_shapes, arrImages: loader.End_UseFullUrl(), arrTransforms: arr_transforms};
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3991 3992 3993 3994 3995
    },

    ReadPresentationSlides: function(stream)
    {
        var loader = new BinaryPPTYLoader();
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3996
        loader.Start_UseFullUrl();
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012
        loader.stream = stream;
        loader.presentation = editor.WordControl.m_oLogicDocument;
        var presentation = editor.WordControl.m_oLogicDocument;
        var count = stream.GetULong();
        var arr_slides = [];
        for(var i = 0; i < count; ++i)
        {
            arr_slides.push(loader.ReadSlide(0));
        }
        return arr_slides;
    },


    ReadSlide: function(stream)
    {
        var loader = new BinaryPPTYLoader();
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
4013
        loader.Start_UseFullUrl();
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
4014 4015 4016 4017 4018 4019
        loader.stream = stream;
        loader.presentation = editor.WordControl.m_oLogicDocument;
        var presentation = editor.WordControl.m_oLogicDocument;
        return loader.ReadSlide(0);
    },

4020 4021
    _Prepeare : function(node, fCallback)
    {
4022
		var oThis = this;
4023 4024 4025
        if(true == this.bUploadImage || true == this.bUploadFonts)
        {
            //����������� �� ��������� �������� ������ ������� � ��������.
4026 4027
            var aPrepeareFonts = this._Prepeare_recursive(node, true, true);
     
Alexander.Trofimov's avatar
Alexander.Trofimov committed
4028
			var aImagesToDownload = [];
4029
			for(var image in this.oImages)
4030 4031 4032 4033
            {
				var src = this.oImages[image];
				if(0 == src.indexOf("file:"))
					this.oImages[image] = "local";
4034
				else if(false == (0 == src.indexOf("data:") || 0 == src.indexOf(documentOrigin + this.api.DocumentUrl) || 0 == src.indexOf(this.api.DocumentUrl)))
4035 4036
					aImagesToDownload.push(src);
			}
Alexander.Trofimov's avatar
Alexander.Trofimov committed
4037
			var oPrepeareImages = {};
4038 4039
			if(aImagesToDownload.length > 0)
			{
4040
				var rData = {"id":documentId, "c":"imgurls", "vkey": documentVKey, "data": JSON.stringify(aImagesToDownload)};
4041 4042 4043
				sendCommand( this.api, function(incomeObject){
						if(incomeObject && "imgurls" == incomeObject.type)
						{
4044 4045
							var oFromTo = JSON.parse(incomeObject.data);
							for(var i = 0, length = aImagesToDownload.length; i < length; ++i)
4046
							{
4047 4048 4049
								var sFrom = aImagesToDownload[i];
								var sTo = oFromTo[sFrom];
								if(sTo)
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
4050
								{									oThis.oImages[sFrom] = sTo;									oPrepeareImages[i] = sTo;								}							}
4051 4052
						}
						oThis.api.pre_Paste(aPrepeareFonts, oPrepeareImages, fCallback);
Sergey.Konovalov's avatar
 
Sergey.Konovalov committed
4053
					}, rData );
4054 4055
			}
			else
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
4056
				this.api.pre_Paste(aPrepeareFonts, this.oImages, fCallback);
4057 4058 4059 4060
        }
        else
            fCallback();
    },
4061
    _Prepeare_recursive : function(node, bIgnoreStyle, isCheckFonts)
4062 4063 4064 4065 4066 4067 4068 4069
    {
        //����������� �� ����� ������, �������� ��� ������ � ��������
        var nodeName = node.nodeName.toLowerCase();
        var nodeType = node.nodeType;
        if(!bIgnoreStyle)
        {
            if(Node.TEXT_NODE == nodeType)
            {
4070
                var computedStyle = this._getComputedStyle(node.parentNode);
4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129
                if ( computedStyle )
                {
                    var fontFamily = computedStyle.getPropertyValue( "font-family" );
                    var sNewFF;
                    var nIndex = fontFamily.indexOf(",");
                    if(-1 != nIndex)
                        sNewFF = fontFamily.substring(0, nIndex);
                    else
                        sNewFF = fontFamily;
                    //trim ' � "
                    var nLength = sNewFF.length
                    if(nLength >= 2)
                    {
                        var nStart = 0;
                        var nStop = nLength;
                        var cFirstChar = sNewFF[0];
                        var cLastChar = sNewFF[nLength - 1];
                        var bTrim = false;
                        if('\'' == cFirstChar || '\"' == cFirstChar)
                        {
                            bTrim = true;
                            nStart = 1;
                        }
                        if('\'' == cLastChar || '\"' == cLastChar)
                        {
                            bTrim = true;
                            nStop = nLength - 1;
                        }
                        if(bTrim)
                            sNewFF = sNewFF.substring(nStart, nStop);
                    }
                    this.oFonts[fontFamily] = {Name:sNewFF, Index: -1};
                }
            }
            else
            {
                var src = node.getAttribute("src");
                if(src)
                    this.oImages[src] = src;
            }
        }
        for(var i = 0, length = node.childNodes.length; i < length; i++)
        {
            var child = node.childNodes[i];
            var child_nodeType = child.nodeType;
            if(!(Node.ELEMENT_NODE == child_nodeType || Node.TEXT_NODE == child_nodeType))
                continue;
            //�������� ������� ��������� ������ �� \t,\n,\r
            if( Node.TEXT_NODE == child.nodeType)
            {
                var value = child.nodeValue;
                if(!value)
                    continue;
                value = value.replace(/(\r|\t|\n)/g, '');
                if("" == value)
                    continue;
            }
            this._Prepeare_recursive(child, false);
        }
4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153
		
		if(isCheckFonts)
		{
			var aPrepeareFonts = [];
            for(var font_family in this.oFonts)
            {
                //todo ��������� �����, ������ �� ��������
                var oFontItem = this.oFonts[font_family];
                //���� ����� ����� �������
                var index = this.map_font_index[oFontItem.Name];
                if(null != index)
                {
                    this.oFonts[font_family].Index = index;
                    aPrepeareFonts.push(new CFont(oFontItem.Name, 0, "", 0));
                }
                else
                {
                    this.oFonts[font_family] = {Name:"Arial", Index: -1};
                    aPrepeareFonts.push(new CFont("Arial", 0, "", 0));
                }
            };
			
			return aPrepeareFonts;
		};
4154 4155 4156 4157 4158 4159 4160 4161
    },
    _IsBlockElem : function(name)
    {
        if( "p" == name || "div" == name || "ul" == name || "ol" == name || "li" == name || "table" == name || "tbody" == name || "tr" == name || "td" == name || "th" == name ||
            "h1" == name || "h2" == name || "h3" == name || "h4" == name || "h5" == name || "h6" == name || "center" == name)
            return true;
        return false;
    },
4162 4163 4164 4165 4166 4167 4168 4169 4170
	_getComputedStyle : function(node){
		var computedStyle = null;
		if(null != node && Node.ELEMENT_NODE == node.nodeType)
		{
			var defaultView = node.ownerDocument.defaultView;
            computedStyle = defaultView.getComputedStyle( node, null );
		}
		return computedStyle;
	},
4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181
    _ValueToMm : function(value)
    {
        var obj = this._ValueToMmType(value);
        if(obj && "%" != obj.type && "none" != obj.type)
            return obj.val;
        return null;
    },
    _ValueToMmType : function(value)
    {
        var oVal = parseFloat(value);
        var oType;
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
4182
        if(!isNaN(oVal))
4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331
        {
            if(-1 != value.indexOf("%"))
            {
                oType = "%";
                oVal /= 100;
            }
            else if(-1 != value.indexOf("px"))
            {
                oType = "px";
                oVal *= g_dKoef_pix_to_mm;
            }
            else if(-1 != value.indexOf("in"))
            {
                oType = "in";
                oVal *= g_dKoef_in_to_mm;
            }
            else if(-1 != value.indexOf("cm"))
            {
                oType = "cm";
                oVal *= 10;
            }
            else if(-1 != value.indexOf("mm"))
            {
                oType = "mm";
            }
            else if(-1 != value.indexOf("pt"))
            {
                oType = "pt";
                oVal *= g_dKoef_pt_to_mm;
            }
            else if(-1 != value.indexOf("pc"))
            {
                oType = "pc";
                oVal *= g_dKoef_pc_to_mm;
            }
            else
                oType = "none";
            return {val: oVal, type: oType};
        }
        return null;
    },
    _ParseColor : function(color)
    {
        if(!color || color.length == 0)
            return null;
        if("transparent" == color)
            return null;
        if("aqua" == color)
            return new CDocumentColor(0, 255, 255);
        else if("black" == color)
            return new CDocumentColor(0, 0, 0);
        else if("blue" == color)
            return new CDocumentColor(0, 0, 255);
        else if("fuchsia" == color)
            return new CDocumentColor(255, 0, 255);
        else if("gray" == color)
            return new CDocumentColor(128, 128, 128);
        else if("green" == color)
            return new CDocumentColor(0, 128, 0);
        else if("lime" == color)
            return new CDocumentColor(0, 255, 0);
        else if("maroon" == color)
            return new CDocumentColor(128, 0, 0);
        else if("navy" == color)
            return new CDocumentColor(0, 0, 128);
        else if("olive" == color)
            return new CDocumentColor(128, 128, 0);
        else if("purple" == color)
            return new CDocumentColor(128, 0, 128);
        else if("red" == color)
            return new CDocumentColor(255, 0, 0);
        else if("silver" == color)
            return new CDocumentColor(192, 192, 192);
        else if("teal" == color)
            return new CDocumentColor(0, 128, 128);
        else if("white" == color)
            return new CDocumentColor(255, 255, 255);
        else if("yellow" == color)
            return new CDocumentColor(255, 255, 0);
        else
        {
            if(0 == color.indexOf("#"))
            {
                var hex = color.substring(1);
                if(hex.length == 3)
                    hex = hex.charAt(0) + hex.charAt(0) + hex.charAt(1) + hex.charAt(1) + hex.charAt(2) + hex.charAt(2);
                if(hex.length == 6)
                {
                    var r = parseInt("0x" + hex.substring(0,2));
                    var g = parseInt("0x" + hex.substring(2,4));
                    var b = parseInt("0x" + hex.substring(4,6));
                    return new CDocumentColor(r, g, b);
                }
            }
            if(0 == color.indexOf("rgb"))
            {
                var nStart = color.indexOf('(');
                var nEnd = color.indexOf(')');
                if(-1 != nStart && -1 != nEnd && nStart < nEnd)
                {
                    var temp = color.substring(nStart + 1, nEnd);
                    var aParems = temp.split(',');
                    if(aParems.length >= 3)
                    {
                        if(aParems.length >= 4)
                        {
                            var oA = this._ValueToMmType(aParems[3]);
                            if(0 == oA .val)//��������� ����������
                                return null;
                        }
                        var oR = this._ValueToMmType(aParems[0]);
                        var oG = this._ValueToMmType(aParems[1]);
                        var oB = this._ValueToMmType(aParems[2]);
                        var r,g,b;
                        if(oR && "%" == oR.type)
                            r = parseInt(255 * oR.val / 100);
                        else
                            r = oR.val;
                        if(oG && "%" == oG.type)
                            g = parseInt(255 * oG.val / 100);
                        else
                            g = oG.val;
                        if(oB && "%" == oB.type)
                            b = parseInt(255 * oB.val / 100);
                        else
                            b = oB.val;
                        return new CDocumentColor(r, g, b);
                    }
                }
            }
        }
        return null;
    },
    _isEmptyProperty : function(prop)
    {
        var bIsEmpty = true;
        for(var i in prop)
        {
            if(null != prop[i])
            {
                bIsEmpty = false;
                break;
            }
        }
        return bIsEmpty;
    },
    _set_pPr : function(node, Para,  pNoHtmlPr)
    {
        //����������� ����� �� ������ � ������� �������� ��������
4332
		var sNodeName = node.nodeName.toLowerCase();
4333 4334
        if(node != this.oRootNode)
        {
4335
            while(false == this._IsBlockElem(sNodeName))
4336 4337
            {
                if(this.oRootNode != node.parentNode)
4338
				{
4339
                    node = node.parentNode;
4340 4341
					sNodeName = node.nodeName.toLowerCase();
				}
4342 4343 4344 4345
                else
                    break;
            }
        }
4346 4347 4348 4349 4350 4351 4352 4353
		if("td" == sNodeName || "th" == sNodeName)
		{
			//для случая <td>br<span></span></td> без текста в ячейке
			var oNewSpacing = new CParaSpacing();
			oNewSpacing.Set_FromObject({After: 0, Before: 0, Line: linerule_Auto});
            Para.Set_Spacing(oNewSpacing);
			return;
		}
4354 4355
        var oDocument = this.oDocument;
        //Heading
4356
        if(null != pNoHtmlPr.hLevel && oDocument.Styles)
4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405
            Para.Style_Add(oDocument.Styles.Get_Default_Heading(pNoHtmlPr.hLevel));

        var pPr = Para.Pr;

        //Borders
        var oNewBorder = {Left: null, Top: null, Right: null, Bottom: null, Between: null};
        var sBorder = pNoHtmlPr["mso-border-alt"];
        if(null != sBorder)
        {
            var oNewBrd = this._ExecuteParagraphBorder(sBorder);
            oNewBorder.Left = oNewBrd;
            oNewBorder.Top = oNewBrd.Copy();
            oNewBorder.Right = oNewBrd.Copy();
            oNewBorder.Bottom = oNewBrd.Copy();
        }
        else
        {
            sBorder = pNoHtmlPr["mso-border-left-alt"];
            if(null != sBorder)
            {
                var oNewBrd = this._ExecuteParagraphBorder(sBorder);
                oNewBorder.Left = oNewBrd;
            }
            sBorder = pNoHtmlPr["mso-border-top-alt"];
            if(null != sBorder)
            {
                var oNewBrd = this._ExecuteParagraphBorder(sBorder);
                oNewBorder.Top = oNewBrd;
            }
            sBorder = pNoHtmlPr["mso-border-right-alt"];
            if(null != sBorder)
            {
                var oNewBrd = this._ExecuteParagraphBorder(sBorder);
                oNewBorder.Right = oNewBrd;
            }
            sBorder = pNoHtmlPr["mso-border-bottom-alt"];
            if(null != sBorder)
            {
                var oNewBrd = this._ExecuteParagraphBorder(sBorder);
                oNewBorder.Bottom = oNewBrd;
            }
        }
        sBorder = pNoHtmlPr["mso-border-between"];
        if(null != sBorder)
        {
            var oNewBrd = this._ExecuteParagraphBorder(sBorder);
            oNewBorder.Between = oNewBrd;
        }

4406
        var computedStyle = this._getComputedStyle(node);
4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452
        if (computedStyle)
        {
            //Ind
            var Ind = new CParaInd();
            var margin_left = computedStyle.getPropertyValue( "margin-left" );
            if(margin_left && null != (margin_left = this._ValueToMm(margin_left)))
                Ind.Left = margin_left;
            var margin_right = computedStyle.getPropertyValue( "margin-right" );
            if(margin_right && null != (margin_right = this._ValueToMm(margin_right)))
                Ind.Right = margin_right;
            //scale
            // if(null != pPr.Ind.Left && true == this.bUseScaleKoef)
            // pPr.Ind.Left = pPr.Ind.Left * this.dScaleKoef;
            // if(null != pPr.Ind.Right && true == this.bUseScaleKoef)
            // pPr.Ind.Right = pPr.Ind.Right * this.dScaleKoef;
            //�������� ����� ������ margin �� ������� �� ����� ��� �� ����������� ����� ��� �� �������
            if(null != Ind.Left && null != Ind.Right)
            {
                //30 ����������� ��� � �� �������
                var dif = Page_Width - X_Left_Margin - X_Right_Margin - Ind.Left - Ind.Right;
                if(dif < 30)
                    Ind.Right = Page_Width - X_Left_Margin - X_Right_Margin - Ind.Left - 30;
            }
            var text_indent = computedStyle.getPropertyValue( "text-indent" );
            if(text_indent && null != (text_indent = this._ValueToMm(text_indent)))
                Ind.FirstLine = text_indent;
            // if(null != pPr.Ind.FirstLine && true == this.bUseScaleKoef)
            // pPr.Ind.FirstLine = pPr.Ind.FirstLine * this.dScaleKoef;
            if(false == this._isEmptyProperty(Ind))
                Para.Set_Ind(Ind);
            //Jc
            var text_align = computedStyle.getPropertyValue( "text-align" );
            if(text_align)
            {
                //����� ��������� -webkit-right
                var Jc = null;
                if(-1 != text_align.indexOf('center'))
                    Jc = align_Center;
                else if(-1 != text_align.indexOf('right'))
                    Jc = align_Right;
                else if(-1 != text_align.indexOf('justify'))
                    Jc = align_Justify;
                if(null != Jc)
                    Para.Set_Align(Jc, false);
            }
            //Spacing
4453
			var Spacing = new CParaSpacing();
4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467
            var margin_top = computedStyle.getPropertyValue( "margin-top" );
            if(margin_top && null != (margin_top = this._ValueToMm(margin_top)))
                Spacing.Before = margin_top;
            var margin_bottom = computedStyle.getPropertyValue( "margin-bottom" );
            if(margin_bottom && null != (margin_bottom = this._ValueToMm(margin_bottom)))
                Spacing.After = margin_bottom;
            if(false == this._isEmptyProperty(Spacing))
                Para.Set_Spacing(Spacing);
            //Shd
            //background-color �� ����������� ��������� ��������, ���� �������� ������������ ��������
            var background_color = null;
            var oTempNode = node;
            while(true)
            {
4468
                var tempComputedStyle = this._getComputedStyle(oTempNode);
4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575
                if(null == tempComputedStyle)
                    break;
                background_color = tempComputedStyle.getPropertyValue( "background-color" );
                if(null != background_color && (background_color = this._ParseColor(background_color)))
                    break;
                oTempNode = oTempNode.parentNode;
                if(this.oRootNode == oTempNode || "body" == oTempNode.nodeName.toLowerCase() || true == this._IsBlockElem(oTempNode.nodeName.toLowerCase()))
                    break;
            }
            if(g_bIsDocumentCopyPaste)
            {
                if(background_color)
                {
                    var Shd = new CDocumentShd();
                    Shd.Value = shd_Clear;
                    Shd.Color = background_color;
                    Para.Set_Shd(Shd);
                }
            }

            if(null == oNewBorder.Left)
                oNewBorder.Left = this._ExecuteBorder(computedStyle, node, "left", "Left", false);
            if(null == oNewBorder.Top)
                oNewBorder.Top = this._ExecuteBorder(computedStyle, node, "top", "Top", false);
            if(null == oNewBorder.Right)
                oNewBorder.Right = this._ExecuteBorder(computedStyle, node, "left", "Left", false);
            if(null == oNewBorder.Bottom)
                oNewBorder.Bottom = this._ExecuteBorder(computedStyle, node, "bottom", "Bottom", false);
        }
        if(false == this._isEmptyProperty(oNewBorder))
            Para.Set_Borders(oNewBorder);

        //KeepLines , WidowControl
        var pagination = pNoHtmlPr["mso-pagination"];
        if(pagination)
        {
            //todo WidowControl
            if("none" == pagination)
                ;//pPr.WidowControl = !Def_pPr.WidowControl;
            else if(-1 != pagination.indexOf("widow-orphan") && -1 != pagination.indexOf("lines-together"))
                Para.Set_KeepLines(true);
            else if(-1 != pagination.indexOf("none") && -1 != pagination.indexOf("lines-together"))
            {
                ;//pPr.WidowControl = !Def_pPr.WidowControl;
                Para.Set_KeepLines(true);
            }
        }
        //todo KeepNext
        if("avoid" == pNoHtmlPr["page-break-after"])
            ;//pPr.KeepNext = !Def_pPr.KeepNext;
        //PageBreakBefore
        if("always" == pNoHtmlPr["page-break-before"])
            Para.Set_PageBreakBefore(true);
        //Tabs
        var tab_stops = pNoHtmlPr["tab-stops"]
        if(tab_stops && "" != pNoHtmlPr["tab-stops"])
        {
            var aTabs = tab_stops.split(' ');
            var nTabLen = aTabs.length;
            if(nTabLen > 0)
            {
                var Tabs = new CParaTabs();
                for(var i = 0; i < nTabLen; i++)
                {
                    var val = this._ValueToMm(aTabs[i]);
                    if(val)
                        Tabs.Add(new CParaTab(tab_Left, val));
                }
                Para.Set_Tabs(Tabs);
            }
        }

        //num
        if(g_bIsDocumentCopyPaste)
        {
            if(true == pNoHtmlPr.bNum)
            {
                var num = numbering_numfmt_Bullet;
                if(null != pNoHtmlPr.numType)
                    num = pNoHtmlPr.numType;
                var type = pNoHtmlPr["list-style-type"];
                if(type)
                {
                    switch(type)
                    {
                        case "disc": num = numbering_numfmt_Bullet;break;
                        case "decimal": num = numbering_numfmt_Decimal;break;
                        case "lower-roman": num = numbering_numfmt_LowerRoman;break;
                        case "upper-roman": num = numbering_numfmt_UpperRoman;break;
                        case "lower-alpha": num = numbering_numfmt_LowerLetter;break;
                        case "upper-alpha": num = numbering_numfmt_UpperLetter;break;
                    }
                }
                //����� ���� ����������� �� Document.Set_ParagraphNumbering
                
                //������� ����������� ��������, ���� ��� ������ ���������, �� ����� ��� ������ �� ����������� ���������
                var NumId = null;
                if(this.aContent.length > 1)
                {
                    var prevElem = this.aContent[this.aContent.length - 2];
                    if(null != prevElem && type_Paragraph === prevElem.GetType())
                    {
                        var PrevNumPr = prevElem.Numbering_Get();
                        if ( null != PrevNumPr && true === this.oLogicDocument.Numbering.Check_Format( PrevNumPr.NumId, PrevNumPr.Lvl, num ) )
                            NumId  = PrevNumPr.NumId;
                    }
                }
4576
                if(null == NumId && this.pasteInExcel !== true)
4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624
                {
                    //������� ����� ������
                    NumId  = this.oLogicDocument.Numbering.Create_AbstractNum();

                    var AbstractNum = this.oLogicDocument.Numbering.Get_AbstractNum( NumId );
                    AbstractNum.Create_Default_Bullet();
                    switch(num)
                    {
                        case numbering_numfmt_Decimal: AbstractNum.Set_Lvl_Numbered_2(0);break;
                        case numbering_numfmt_LowerRoman: AbstractNum.Set_Lvl_Numbered_5(0);break;
                        case numbering_numfmt_UpperRoman: AbstractNum.Set_Lvl_Numbered_9(0);break;
                        case numbering_numfmt_LowerLetter: AbstractNum.Set_Lvl_Numbered_8(0);break;
                        case numbering_numfmt_UpperLetter: AbstractNum.Set_Lvl_Numbered_6(0);break;
                    }
                    //��������� ��������� ������ ����� �� ���������� ������� ���������� ��������
                    var oFirstTextChild = node;
                    while(true)
                    {
                        var bContinue = false;
                        for(var i = 0, length = oFirstTextChild.childNodes.length; i < length; i++)
                        {
                            var child = oFirstTextChild.childNodes[i];
                            var nodeType = child.nodeType;

                            if(!(Node.ELEMENT_NODE == nodeType || Node.TEXT_NODE == nodeType))
                                continue;
                            //�������� ������� ��������� ������ �� \t,\n,\r
                            if( Node.TEXT_NODE == child.nodeType)
                            {
                                var value = child.nodeValue;
                                if(!value)
                                    continue;
                                value = value.replace(/(\r|\t|\n)/g, '');
                                if("" == value)
                                    continue;
                            }
                            if(Node.ELEMENT_NODE == nodeType)
                            {
                                oFirstTextChild = child;
                                bContinue = true;
                                break;
                            }
                        }
                        if(false == bContinue)
                            break;
                    }
                    if(node != oFirstTextChild)
                    {
4625 4626 4627 4628 4629 4630 4631 4632 4633
						if(!this.bIsPlainText)
						{
							var oLvl = AbstractNum.Lvl[0];
							var oTextPr = this._read_rPr(oFirstTextChild);
							if(numbering_numfmt_Bullet == num)
								oTextPr.RFonts = oLvl.TextPr.RFonts.Copy();
							//�������� ��������� �� node
							AbstractNum.Apply_TextPr(0, oTextPr);
						}
4634 4635
                    }
                }
4636 4637
				if(this.pasteInExcel !== true)
					Para.Numbering_Add( NumId, 0 );
4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685
            }
            else
            {
                var numPr = Para.Numbering_Get();
                if(numPr)
                    Para.Numbering_Remove();
            }
        }
        else
        {
            if(true == pNoHtmlPr.bNum)
            {
                var num = numbering_presentationnumfrmt_Char;
                if(null != pNoHtmlPr.numType)
                    num = pNoHtmlPr.numType;
                var type = pNoHtmlPr["list-style-type"];
                if(type)
                {
                    switch(type)
                    {
                        case "disc": num = numbering_presentationnumfrmt_Char;break;
                        case "decimal": num = numbering_presentationnumfrmt_ArabicPeriod;break;
                        case "lower-roman": num = numbering_presentationnumfrmt_RomanLcPeriod;break;
                        case "upper-roman": num = numbering_presentationnumfrmt_RomanUcPeriod;break;
                        case "lower-alpha": num = numbering_presentationnumfrmt_AlphaLcPeriod;break;
                        case "upper-alpha": num = numbering_presentationnumfrmt_AlphaUcPeriod;break;
                        default:
                        {
                            num = numbering_presentationnumfrmt_Char;
                        }
                    }
                }
                var _bullet = new CPresentationBullet();
                _bullet.m_nType = num;
                if(num == numbering_presentationnumfrmt_Char)
                {
                    _bullet.m_sChar = "";
                }
                _bullet.m_nStartAt = 1;
                Para.Add_PresentationNumbering2(_bullet );
            }
            else
            {
               Para.Remove_PresentationNumbering();
            }
        }
        Para.CompiledPr.NeedRecalc = true;
    },
4686
    _commit_rPr: function (node, bUseOnlyInherit)
4687
    {
4688 4689
		if(!this.bIsPlainText)
		{
4690
		    var rPr = this._read_rPr(node, bUseOnlyInherit);
4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703
			
			//заглушка для вставки в excel внутрь шейпа
			var tempRpr;
			if(this.pasteInExcel === true && this.oDocument && this.oDocument.Parent && this.oDocument.Parent.parent && this.oDocument.Parent.parent.getObjectType() == historyitem_type_Shape)
			{
				tempRpr = new CTextPr();
				tempRpr.Underline = rPr.Underline;
				tempRpr.Bold = rPr.Bold;
				tempRpr.Italic = rPr.Italic;
				
				rPr = tempRpr;
			}
			
4704 4705 4706
			//���� ��������� ��������� ���������� ��������� �������
			if(false == Common_CmpObj2(this.oCur_rPr, rPr))
			{
4707
			    this._Set_Run_Pr(rPr);
4708 4709 4710
				this.oCur_rPr = rPr;
			}
		}
4711
    },
4712
    _read_rPr : function(node, bUseOnlyInherit)
4713 4714 4715 4716 4717 4718 4719 4720 4721 4722
    {
        var oDocument = this.oDocument;
        var rPr = new CTextPr();
        if(false == g_bIsDocumentCopyPaste)
        {
            rPr.Set_FromObject({
                Bold       : false,
                Italic     : false,
                Underline  : false,
                Strikeout  : false,
4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741
				RFonts :
				{
					Ascii: {
						Name  : "Arial",
						Index : -1
					},
					EastAsia: {
						Name  : "Arial",
						Index : -1
					},
					HAnsi: {
						Name  : "Arial",
						Index : -1
					},
					CS: {
						Name  : "Arial",
						Index : -1
					}
				},
4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752
                FontSize   : 11,
                Color      :
                {
                    r : 0,
                    g : 0,
                    b : 0
                },
                VertAlign : vertalign_Baseline,
                HighLight : highlight_None
            });
        }
4753
        var computedStyle = this._getComputedStyle(node);
4754 4755 4756 4757 4758 4759 4760
        if ( computedStyle )
        {
            var font_family = computedStyle.getPropertyValue( "font-family" );
            if(font_family && "" != font_family)
            {
                var oFontItem = this.oFonts[font_family];
                if(null != oFontItem && null != oFontItem.Name)
4761 4762 4763 4764 4765 4766
				{
					rPr.RFonts.Ascii = {Name: oFontItem.Name, Index: oFontItem.Index};
					rPr.RFonts.HAnsi = {Name: oFontItem.Name, Index: oFontItem.Index};
					rPr.RFonts.CS = {Name: oFontItem.Name, Index: oFontItem.Index};
					rPr.RFonts.EastAsia = {Name: oFontItem.Name, Index: oFontItem.Index};
				}
4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804
            }
            var font_size = node.style.fontSize;
            if(!font_size)
                font_size = computedStyle.getPropertyValue( "font-size" );
            if(font_size)
            {
                var obj = this._ValueToMmType(font_size);
                if(obj && "%" != obj.type && "none" != obj.type)
                {
                    font_size = obj.val;
                    //���� ������� �� ������������ ������� ������� �������� ���������� ������, ��� ���������� ��� ������� 8, 11, 14, 20, 26pt
                    if("px" == obj.type && false == this.bIsDoublePx)
                        font_size = Math.round(font_size * g_dKoef_mm_to_pt);
                    else
                        font_size = Math.round(2 * font_size * g_dKoef_mm_to_pt) / 2;//���������� �������� ���������.
                    rPr.FontSize = font_size;
                }
            }
            var font_weight = computedStyle.getPropertyValue( "font-weight" );
            if(font_weight)
            {
                if("bold" == font_weight || "bolder" == font_weight || 400 < font_weight)
                    rPr.Bold = true;
            }
            var font_style = computedStyle.getPropertyValue( "font-style" );
            if("italic" == font_style)
                rPr.Italic = true;
            var color = computedStyle.getPropertyValue( "color" );
            if(color && (color = this._ParseColor(color)))
            {
                rPr.Color = color;
            }
            //������� �� ��������, ������� �� �����������, ���� �������� ������������ ��������
            var background_color = null;
            var underline = null;
            var Strikeout = null;
            var vertical_align = null;
            var oTempNode = node;
4805
            while (true != bUseOnlyInherit && true)
4806
            {
4807
                var tempComputedStyle = this._getComputedStyle(oTempNode);
4808 4809 4810 4811
                if(null == tempComputedStyle)
                    break;
                if(null == underline || null == Strikeout)
                {
4812
                    var text_decoration = tempComputedStyle.getPropertyValue( "text-decoration" );
4813 4814 4815
                    if(text_decoration)
                    {
                        if(-1 != text_decoration.indexOf("underline"))
4816 4817 4818 4819
                            underline = true;
						else if(-1 != text_decoration.indexOf("none") && node.parentElement && node.parentElement.nodeName.toLowerCase() == "a")
							underline = false;	
							
4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906
                        if(-1 != text_decoration.indexOf("line-through"))
                            Strikeout = true;
                    }
                }
                if(null == background_color)
                {
                    background_color = tempComputedStyle.getPropertyValue( "background-color" );
                    if(background_color)
                        background_color = this._ParseColor(background_color);
                    else
                        background_color = null;
                }
                if(null == vertical_align || "baseline" == vertical_align)
                {
                    vertical_align = tempComputedStyle.getPropertyValue( "vertical-align" );
                    if(!vertical_align)
                        vertical_align = null;
                }
                if(vertical_align && background_color && Strikeout && underline)
                    break;
                oTempNode = oTempNode.parentNode;
                if(this.oRootNode == oTempNode || "body" == oTempNode.nodeName.toLowerCase()  || true == this._IsBlockElem(oTempNode.nodeName.toLowerCase()))
                    break;
            }
            if(g_bIsDocumentCopyPaste)
            {
                if(background_color)
                    rPr.HighLight = background_color;
            }
            else
                delete rPr.HighLight;
            if(null != underline)
                rPr.Underline = underline;
            if(null != Strikeout)
                rPr.Strikeout = Strikeout;
            switch(vertical_align)
            {
                case "sub": rPr.VertAlign = vertalign_SubScript;break;
                case "super": rPr.VertAlign = vertalign_SuperScript;break;
            }
        }
        return rPr;
    },
    _parseCss : function(sStyles, pPr)
    {
        var aStyles = sStyles.split(';');
        if(aStyles)
        {
            for(var i = 0, length = aStyles.length; i < length; i++)
            {
                var style = aStyles[i];
                var aPair = style.split(':');
                if(aPair && aPair.length > 1)
                {
                    var prop_name = trimString(aPair[0]);
                    var prop_value = trimString(aPair[1]);
                    if(null != this.MsoStyles[prop_name])
                        pPr[prop_name] = prop_value;
                }
            }
        }
    },
    _PrepareContent : function()
    {
        //�� �������� ����� ������� ������������ �� �������, ����� ������ �������� �������� �����
        if(this.aContent.length > 0)
        {
            var last = this.aContent[this.aContent.length - 1];
            if(type_Table == last.GetType())
            {
                this._Add_NewParagraph();
            }
        }
    },
    _AddNextPrevToContent : function(oDoc)
    {
        var prev = null;
        for(var i = 0, length = this.aContent.length; i < length; ++i)
        {
            var cur = this.aContent[i];
            cur.Set_DocumentPrev( prev );
            cur.Parent = oDoc;
            if(prev)
                prev.Set_DocumentNext( cur );
            prev = cur;
        }
    },
4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920
    _Set_Run_Pr: function (oPr) {
        this._CommitRunToParagraph(false);
        if (null != this.oCurRun) {
            this.oCurRun.Set_Pr(oPr);
        }
    },
    _CommitRunToParagraph: function (bCreateNew) {
        if (bCreateNew || this.oCurRun.Content.length > 0) {
            this.oCurRun = new ParaRun(this.oCurPar);
            this.oCurRunContentPos = 0;
        }
    },
    _CommitElemToParagraph: function (elem) {
        if (null != this.oCurHyperlink) {
4921
            this.oCurHyperlink.Add_ToContent(this.oCurHyperlinkContentPos, elem, false);
4922 4923 4924 4925 4926 4927 4928 4929
            this.oCurHyperlinkContentPos++;
        }
        else {
            this.oCurPar.Internal_Content_Add(this.oCurParContentPos, elem, false);
            this.oCurParContentPos++;
        }
    },
    _Paragraph_Add: function (elem)
4930
    {
4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941
        if (null != this.oCurRun) {
            if (para_Hyperlink == elem.Type) {
                this._CommitRunToParagraph(true);
                this._CommitElemToParagraph(elem);
            }
            else {
                this.oCurRun.Add_ToContent(this.oCurRunContentPos, elem, false);
                this.oCurRunContentPos++;
                if (1 == this.oCurRun.Content.length)
                    this._CommitElemToParagraph(this.oCurRun);
            }
4942
		}
4943 4944 4945
    },
    _Add_NewParagraph : function()
    {
4946 4947 4948 4949
        var bFromPresentation = false;
		if(this.pasteInPresentationShape)
			bFromPresentation = true;
			
4950
		this.oCurPar = new Paragraph(this.oDocument.DrawingDocument, this.oDocument, 0, 50, 50, X_Right_Field, Y_Bottom_Field, this.oDocument.bPresentation === true );
4951 4952 4953
        this.oCurParContentPos = this.oCurPar.CurPos.ContentPos;
        this.oCurRun = new ParaRun(this.oCurPar);
        this.oCurRunContentPos = 0;
4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980
        this.aContent.push(this.oCurPar);
        //���������� ��������� �����
        this.oCur_rPr = new CTextPr();
    },
    _Execute_AddParagraph : function(node, pPr)
    {
        this._Add_NewParagraph();
        //������������� ����� ���������
        this._set_pPr(node, this.oCurPar, pPr);
    },
    _Decide_AddParagraph : function(node, pPr, bParagraphAdded, bCommitBr)
    {
        //���������� ������ ���������(��� ��������, ��� MS), ��������� �������� ������ ����� ������ �����
        if(true == bParagraphAdded)
        {
            if(false != bCommitBr)
                this._Commit_Br(2, node, pPr);//word ���������� 2 ��������� br
            this._Execute_AddParagraph(node, pPr);
        }
        else if(false != bCommitBr)
            this._Commit_Br(0, node, pPr);
        return false;
    },
    _Commit_Br : function(nIgnore, node, pPr)
    {
        for(var i = 0, length = this.nBrCount - nIgnore; i < length; i++)
        {
4981 4982 4983 4984 4985 4986 4987 4988
            if ("always" == pPr["mso-column-break-before"])
                this._Paragraph_Add(new ParaNewLine(break_Page));
            else{
                if (this.bInBlock)
                    this._Paragraph_Add(new ParaNewLine(break_Line));
                else
                    this._Execute_AddParagraph(node, pPr);
            }
4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008
        }
        this.nBrCount = 0;
    },
    _StartExecuteTable : function(node, pPr)
    {
        var oDocument = this.oDocument;
        var tableNode = node;
        //���� ���� ���� tbody
        for(var i = 0, length = node.childNodes.length; i < length; ++i)
        {
            if("tbody" == node.childNodes[i].nodeName.toLowerCase())
            {
                node = node.childNodes[i];
                break;
            }
        }
        //��������� �����. � ������� �� ����� ���� ����� ��������� �� ����������� ���������� �����.
        var nRowCount = 0;
        var nMinColCount = 0;
        var nMaxColCount = 0;
Alexander.Trofimov's avatar
Alexander.Trofimov committed
5009
        var aColsCountByRow = [];
Alexander.Trofimov's avatar
Alexander.Trofimov committed
5010
        var oRowSums = {};
5011 5012 5013 5014
        oRowSums[0] = 0;
        var dMaxSum = 0;
        var nCurColWidth = 0;
        var nCurSum = 0;
Alexander.Trofimov's avatar
Alexander.Trofimov committed
5015
        var oRowSpans = {};
5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043
        var fParseSpans = function()
        {
            var spans = oRowSpans[nCurColWidth];
            while(null != spans && spans.row > 0)
            {
                spans.row--;
                nCurColWidth += spans.col;
                nCurSum += spans.width;
                spans = oRowSpans[nCurColWidth];
            }
        };
        for(var i = 0, length = node.childNodes.length; i < length; ++i)
        {
            var tr = node.childNodes[i];
            if("tr" == tr.nodeName.toLowerCase())
            {
                nCurSum = 0;
                nCurColWidth = 0;
                var nMinRowSpanCount = null;//����������� rowspan ����� ������
                for(var j = 0, length2 = tr.childNodes.length; j < length2; ++j)
                {
                    var tc = tr.childNodes[j];
                    var tcName = tc.nodeName.toLowerCase();
                    if("td" == tcName || "th" == tcName)
                    {
                        fParseSpans();

                        var dWidth = null;
5044
                        var computedStyle = this._getComputedStyle(tc);
5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129
                        if ( computedStyle )
                        {
                            var computedWidth = computedStyle.getPropertyValue( "width" );
                            if(null != computedWidth && null != (computedWidth = this._ValueToMm(computedWidth)))
                                dWidth = computedWidth;
                        }
                        if(null == dWidth)
                            dWidth = tc.clientWidth * g_dKoef_pix_to_mm;

                        var nColSpan = tc.getAttribute("colspan");
                        if(null != nColSpan)
                            nColSpan = nColSpan - 0;
                        else
                            nColSpan = 1;
                        var nCurRowSpan = tc.getAttribute("rowspan");
                        if(null != nCurRowSpan)
                        {
                            nCurRowSpan = nCurRowSpan - 0;
                            if(null == nMinRowSpanCount)
                                nMinRowSpanCount = nCurRowSpan;
                            else if(nMinRowSpanCount > nCurRowSpan)
                                nMinRowSpanCount = nCurRowSpan;
                            if(nCurRowSpan > 1)
                                oRowSpans[nCurColWidth] = {row: nCurRowSpan - 1, col: nColSpan, width: dWidth};
                        }
                        else
                            nMinRowSpanCount = 0;

                        nCurSum += dWidth;
                        if(null == oRowSums[nCurColWidth + nColSpan])
                            oRowSums[nCurColWidth + nColSpan] = nCurSum;
                        nCurColWidth += nColSpan;
                    }
                }
                fParseSpans();
                //������� ������ rowspan
                if(nMinRowSpanCount > 1)
                {
                    for(var j = 0, length2 = tr.childNodes.length; j < length2; ++j)
                    {
                        var tc = tr.childNodes[j];
                        var tcName = tc.nodeName.toLowerCase();
                        if("td" == tcName || "th" == tcName)
                        {
                            var nCurRowSpan = tc.getAttribute("rowspan");
                            if(null != nCurRowSpan)
                                tc.setAttribute("rowspan", nCurRowSpan - nMinRowSpanCount);
                        }
                    }
                }
                if(dMaxSum < nCurSum)
                    dMaxSum = nCurSum;
                //������� ������ tr
                if(0 == nCurColWidth)
				{
                    node.removeChild(tr);
					length--;
					i--;
				}
                else
                {
                    if(0 == nMinColCount || nMinColCount > nCurColWidth)
                        nMinColCount = nCurColWidth;
                    if(nMaxColCount < nCurColWidth)
                        nMaxColCount = nCurColWidth;
                    nRowCount++;
                    aColsCountByRow.push(nCurColWidth);
                }
            }
        }
        if(nMaxColCount != nMinColCount)
        {
            for(var i = 0, length = aColsCountByRow.length; i < length; ++i)
                aColsCountByRow[i] = nMaxColCount - aColsCountByRow[i];
        }
        if(nRowCount > 0 && nMaxColCount > 0)
        {
            var bUseScaleKoef = this.bUseScaleKoef;
            var dScaleKoef = this.dScaleKoef;
            if(dMaxSum * dScaleKoef > this.dMaxWidth)
            {
                dScaleKoef = dScaleKoef * this.dMaxWidth / dMaxSum;
                bUseScaleKoef = true;
            }
            //������ Grid
Alexander.Trofimov's avatar
Alexander.Trofimov committed
5130
            var aGrid = [];
5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155
            var nPrevIndex = null;
            var nPrevVal = 0;
            for(var i in oRowSums)
            {
                var nCurIndex = i - 0;
                var nCurVal = oRowSums[i];
                var nCurWidth = nCurVal - nPrevVal;
                if(bUseScaleKoef)
                    nCurWidth *= dScaleKoef;
                if(null != nPrevIndex)
                {
                    var nDif = nCurIndex - nPrevIndex;
                    if(1 == nDif)
                        aGrid.push(nCurWidth);
                    else
                    {
                        var nPartVal = nCurWidth / nDif;
                        for(var i = 0; i < nDif; ++i)
                            aGrid.push(nPartVal);
                    }
                }
                nPrevVal = nCurVal;
                nPrevIndex = nCurIndex;
            }
			var CurPage = 0;
5156 5157
            var table = new CTable(oDocument.DrawingDocument, oDocument, true, 0, 0, 0, X_Right_Field, Y_Bottom_Field, 0, 0, aGrid);
			//считаем aSumGrid
Alexander.Trofimov's avatar
Alexander.Trofimov committed
5158
			var aSumGrid = [];
5159 5160 5161
			aSumGrid[-1] = 0;
			var nSum = 0;
			for(var i = 0, length = aGrid.length; i < length; ++i)
5162
			{
5163 5164
				nSum += aGrid[i];
				aSumGrid[i] = nSum;
5165 5166
			}
            //�������� content
5167
            this._ExecuteTable(tableNode, node, table, aSumGrid, nMaxColCount != nMinColCount ? aColsCountByRow : null, pPr, bUseScaleKoef, dScaleKoef);
5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210
            table.Cursor_MoveToStartPos();
            this.aContent.push(table);
        }
    },
    _ExecuteBorder : function(computedStyle, node, type, type2, bAddIfNull)
    {
        var res = null;
        var style = computedStyle.getPropertyValue( "border-"+type+"-style" );
        if(null != style)
        {
            res = new CDocumentBorder();
            if("none" == style)
                res.Value = border_None;
            else
            {
                res.Value = border_Single;
                var width = node.style["border"+type2+"Width"];
                if(!width)
                    computedStyle.getPropertyValue( "border-"+type+"-width" );
                if(null != width && null != (width = this._ValueToMm(width)))
                    res.Size = width;
                var color = computedStyle.getPropertyValue( "border-"+type+"-color" );
                if(null != color && (color = this._ParseColor(color)))
                    res.Color = color;
            }
        }
        if(bAddIfNull && null == res)
            res = new CDocumentBorder();
        return res;
    },
    _ExecuteParagraphBorder : function(border)
    {
        var res = this.oBorderCache[border];
        if(null != res)
            return res.Copy();
        else
        {
            //������� ����� dom ����� �� ������ ������� ������� ������� ������
            //todo ������� ��� dom, ���������� �����.
            res = new CDocumentBorder();;
            var oTestDiv = document.createElement("div");
            oTestDiv.setAttribute("style", "border-left:"+border);
            document.body.appendChild( oTestDiv );
5211
            var computedStyle = this._getComputedStyle(oTestDiv);
5212 5213 5214 5215 5216 5217 5218 5219 5220
            if(null != computedStyle)
            {
                res = this._ExecuteBorder(computedStyle, oTestDiv, "left", "Left", true);
            }
            document.body.removeChild( oTestDiv );
            this.oBorderCache[border] = res;
            return res;
        }
    },
5221
    _ExecuteTable : function(tableNode, node, table, aSumGrid, aColsCountByRow, pPr, bUseScaleKoef, dScaleKoef)
5222
    {
5223 5224
		//из-за проблем со вставкой больших таблиц, не вставляем tbllayout_AutoFit
		table.Set_TableLayout(tbllayout_Fixed);
5225 5226 5227 5228 5229 5230 5231 5232
        //Pr
        var Pr = table.Pr;
        //align ������� � parent tableNode
		var sTableAlign = null;
		if(null != tableNode.align)
			sTableAlign = tableNode.align
        else if(null != tableNode.parentNode && this.oRootNode != tableNode.parentNode)
        {
5233
            var computedStyleParent = this._getComputedStyle(tableNode.parentNode);
5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253
            if(null != computedStyleParent)
            {
                //����� ��������� -webkit-right
                sTableAlign = computedStyleParent.getPropertyValue( "text-align" );
            }
        }
		if(null != sTableAlign)
		{
			if(-1 != sTableAlign.indexOf('center'))
				table.Set_TableAlign(align_Center);
			else if(-1 != sTableAlign.indexOf('right'))
				table.Set_TableAlign(align_Right);
		}
        var spacing = null;
        table.Set_TableBorder_InsideH(new CDocumentBorder());
        table.Set_TableBorder_InsideV(new CDocumentBorder());

        var style = tableNode.getAttribute("style");
        if(style)
        {
Alexander.Trofimov's avatar
Alexander.Trofimov committed
5254
            var tblPrMso = {};
5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295
            this._parseCss(style, tblPrMso);
            var spacing = tblPrMso["mso-cellspacing"];
            if(null != spacing && null != (spacing = this._ValueToMm(spacing)))
                ;
            var padding = tblPrMso["mso-padding-alt"];
            if(null != padding)
            {
                padding = trimString(padding);
                var aMargins = padding.split(" ");
                if(4 == aMargins.length)
                {
                    var top = aMargins[0];
                    if(null != top && null != (top = this._ValueToMm(top)))
                        ;
                    else
                        top = Pr.TableCellMar.Top.W;
                    var right = aMargins[1];
                    if(null != right && null != (right = this._ValueToMm(right)))
                        ;
                    else
                        right = Pr.TableCellMar.Right.W;
                    var bottom = aMargins[2];
                    if(null != bottom && null != (bottom = this._ValueToMm(bottom)))
                        ;
                    else
                        bottom = Pr.TableCellMar.Bottom.W;
                    var left = aMargins[3];
                    if(null != left && null != (left = this._ValueToMm(left)))
                        ;
                    else
                        left = Pr.TableCellMar.Left.W;
                    table.Set_TableCellMar(left, top, right, bottom);
                }
            }
            var insideh = tblPrMso["mso-border-insideh"];
            if(null != insideh)
                table.Set_TableBorder_InsideH(this._ExecuteParagraphBorder(insideh));
            var insidev = tblPrMso["mso-border-insidev"];
            if(null != insidev)
                table.Set_TableBorder_InsideV(this._ExecuteParagraphBorder(insidev));
        }
5296
		var computedStyle = this._getComputedStyle(tableNode);
5297 5298 5299 5300 5301 5302 5303 5304 5305
        if(computedStyle)
        {
			if(align_Left == table.Get_TableAlign())
			{
				var margin_left = computedStyle.getPropertyValue( "margin-left" );
				//todo возможно надо еще учесть ширину таблицы
				if(margin_left && null != (margin_left = this._ValueToMm(margin_left)) && margin_left < Page_Width - X_Left_Margin)
					table.Set_TableInd(margin_left);
			}
5306
            var background_color = computedStyle.getPropertyValue( "background-color" );
5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334
            if(null != background_color && (background_color = this._ParseColor(background_color)))
                table.Set_TableShd(shd_Clear, background_color.r, background_color.g, background_color.b);
            var oLeftBorder = this._ExecuteBorder(computedStyle, tableNode, "left", "Left", false);
            if(null != oLeftBorder)
                table.Set_TableBorder_Left(oLeftBorder);
            var oTopBorder = this._ExecuteBorder(computedStyle, tableNode, "top", "Top", false);
            if(null != oTopBorder)
                table.Set_TableBorder_Top(oTopBorder);
            var oRightBorder = this._ExecuteBorder(computedStyle, tableNode, "right", "Right", false);
            if(null != oRightBorder)
                table.Set_TableBorder_Right(oRightBorder);
            var oBottomBorder = this._ExecuteBorder(computedStyle, tableNode, "bottom", "Bottom", false);
            if(null != oBottomBorder)
                table.Set_TableBorder_Bottom(oBottomBorder);

            if(null == spacing)
            {
                spacing = computedStyle.getPropertyValue( "padding" );
                if(!spacing)
                    spacing = tableNode.style.padding;
                if(!spacing)
                    spacing = null;
                if(spacing && null != (spacing = this._ValueToMm(spacing)))
                    ;
            }
        }

        //content
Alexander.Trofimov's avatar
Alexander.Trofimov committed
5335
        var oRowSpans = {};
5336 5337 5338
        for(var i = 0, length = node.childNodes.length; i < length; ++i)
        {
            var tr = node.childNodes[i];
5339 5340
			//TODO временная правка в условии для того, чтобы избежать ошибки при копировании из excel мерженной ячейки
            if("tr" == tr.nodeName.toLowerCase() && tr.childNodes && tr.childNodes.length)
5341
            {
5342 5343
				var row = table.Internal_Add_Row(table.Content.length, 0);
                this._ExecuteTableRow(tr, row, aSumGrid, spacing, oRowSpans, bUseScaleKoef, dScaleKoef);
5344 5345 5346
            }
        }
    },
5347
    _ExecuteTableRow : function(node, row, aSumGrid, spacing, oRowSpans, bUseScaleKoef, dScaleKoef)
5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358
    {
        var oThis = this;
        var table = row.Table;
        if(null != spacing && spacing >= tableSpacingMinValue)
            row.Set_CellSpacing(spacing);
        if(node.style.height)
        {
            var height = node.style.height;
            if(!("auto" == height || "inherit" == height || -1 != height.indexOf("%")) && null != (height = this._ValueToMm(height)))
                row.Set_Height(height, heightrule_AtLeast);
        }
5359 5360
		var bBefore = false;
		var bAfter = false;
5361 5362 5363
        var style = node.getAttribute("style");
        if(null != style)
        {
Alexander.Trofimov's avatar
Alexander.Trofimov committed
5364
            var tcPr = {};
5365 5366 5367
            this._parseCss(style, tcPr);
            var margin_left = tcPr["mso-row-margin-left"];
            if(margin_left && null != (margin_left = this._ValueToMm(margin_left)))
5368
                bBefore = true;
5369 5370
            var margin_right = tcPr["mso-row-margin-right"];
            if(margin_right && null != (margin_right = this._ValueToMm(margin_right)))
5371
                bAfter = true;
5372 5373 5374 5375 5376 5377 5378 5379
        }

        //content
        var nCellIndex = 0;
        var nCellIndexSpan = 0;
        var fParseSpans = function()
        {
            var spans = oRowSpans[nCellIndexSpan];
5380
            while(null != spans)
5381
            {
5382 5383
				var oCurCell = row.Add_Cell(row.Get_CellsCount(), row, null, false);
				oCurCell.Set_VMerge(vmerge_Continue);
5384
                if(spans.col > 1)
5385
                    oCurCell.Set_GridSpan(spans.col);
5386
                spans.row--;
5387 5388 5389
				if(spans.row <= 0)
					delete oRowSpans[nCellIndexSpan];
                nCellIndexSpan += spans.col;
5390 5391 5392
                spans = oRowSpans[nCellIndexSpan];
            }
        };
5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409
		var oBeforeCell = null;
		var oAfterCell = null;
		if(bBefore || bAfter)
		{
			for(var i = 0, length = node.childNodes.length; i < length; ++i)
			{
				var tc = node.childNodes[i];
				var tcName = tc.nodeName.toLowerCase();
				if("td" == tcName || "th" == tcName)
				{
					if(bBefore && null != oBeforeCell)
						oBeforeCell = tc;
					else if(bAfter)
						oAfterCell = tc;
				}
			}
		}
5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423
        for(var i = 0, length = node.childNodes.length; i < length; ++i)
        {
            //����� ����� ���� ��� ��� ����� ����������� td, ������ ��� ����������� ���������� ������ ����������� � dom
            fParseSpans();

            var tc = node.childNodes[i];
            var tcName = tc.nodeName.toLowerCase();
            if("td" == tcName || "th" == tcName)
            {
                var nColSpan = tc.getAttribute("colspan");
                if(null != nColSpan)
                    nColSpan = nColSpan - 0;
                else
                    nColSpan = 1;
5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443
				if(tc == oBeforeCell)
					row.Set_Before(nColSpan);
				else if(tc == oAfterCell)
					row.Set_After(nColSpan);
				else
				{
					var oCurCell = row.Add_Cell(row.Get_CellsCount(), row, null, false);
					if(nColSpan > 1)
						oCurCell.Set_GridSpan(nColSpan);
					var width = aSumGrid[nCellIndexSpan + nColSpan - 1] - aSumGrid[nCellIndexSpan - 1];
					oCurCell.Set_W(new CTableMeasurement(tblwidth_Mm, width));
					var nRowSpan = tc.getAttribute("rowspan");
					if(null != nRowSpan)
						nRowSpan = nRowSpan - 0;
					else
						nRowSpan = 1;
					if(nRowSpan > 1)
						oRowSpans[nCellIndexSpan] = {row: nRowSpan - 1, col: nColSpan};
					this._ExecuteTableCell(tc, oCurCell, bUseScaleKoef, dScaleKoef, spacing);
				}
5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455
                nCellIndexSpan+=nColSpan;
            }
        }
        fParseSpans();
    },
    _ExecuteTableCell : function(node, cell, bUseScaleKoef, dScaleKoef, spacing)
    {
        //Pr
        var Pr = cell.Pr;
        var bAddIfNull = false;
        if(null != spacing)
            bAddIfNull = true;
5456
		var computedStyle = this._getComputedStyle(node);
5457 5458
        if(null != computedStyle)
        {
5459
            var background_color = computedStyle.getPropertyValue( "background-color" );
5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505
            if(null != background_color && (background_color = this._ParseColor(background_color)))
            {
                var Shd = new CDocumentShd();
                Shd.Value = shd_Clear;
                Shd.Color = background_color;
                cell.Set_Shd(Shd);
            }
            var border = this._ExecuteBorder(computedStyle, node, "left", "Left", bAddIfNull);
            if(null != border)
                cell.Set_Border(border, 3);
            var border = this._ExecuteBorder(computedStyle, node, "top", "Top", bAddIfNull);
            if(null != border)
                cell.Set_Border(border, 0);
            var border = this._ExecuteBorder(computedStyle, node, "right", "Right", bAddIfNull);
            if(null != border)
                cell.Set_Border(border, 1);
            var border = this._ExecuteBorder(computedStyle, node, "bottom", "Bottom", bAddIfNull);
            if(null != border)
                cell.Set_Border(border, 2);

            var top = computedStyle.getPropertyValue( "padding-top" );
            if(null != top && null != (top = this._ValueToMm(top)))
                cell.Set_Margins({ W : top, Type : tblwidth_Mm }, 0);
            var right = computedStyle.getPropertyValue( "padding-right" );
            if(null != right && null != (right = this._ValueToMm(right)))
                cell.Set_Margins({ W : right, Type : tblwidth_Mm }, 1);
            var bottom = computedStyle.getPropertyValue( "padding-bottom" );
            if(null != bottom && null != (bottom = this._ValueToMm(bottom)))
                cell.Set_Margins({ W : bottom, Type : tblwidth_Mm }, 2);
            var left = computedStyle.getPropertyValue( "padding-left" );
            if(null != left && null != (left = this._ValueToMm(left)))
                cell.Set_Margins({ W : left, Type : tblwidth_Mm }, 3);
        }

        //content
        var oPasteProcessor = new PasteProcessor(this.api, false, false, true);
        oPasteProcessor.oFonts = this.oFonts;
        oPasteProcessor.oImages = this.oImages;
        oPasteProcessor.oDocument = cell.Content;
        oPasteProcessor.bIgnoreNoBlockText = true;
        oPasteProcessor.dMaxWidth = this._CalcMaxWidthByCell(cell);
        if(true == bUseScaleKoef)
        {
            oPasteProcessor.bUseScaleKoef = bUseScaleKoef;
            oPasteProcessor.dScaleKoef = dScaleKoef;
        }
5506
		oPasteProcessor._Execute(node, {}, true, true, false);
5507 5508 5509 5510 5511 5512 5513
        oPasteProcessor._PrepareContent();
        oPasteProcessor._AddNextPrevToContent(cell.Content);
        if(0 == oPasteProcessor.aContent.length)
        {
            var oDocContent = cell.Content;
            var oNewPar = new Paragraph(oDocContent.DrawingDocument, oDocContent, 0, 50, 50, X_Right_Field, Y_Bottom_Field );
            //���������� ��������� ��������� - ����� ��� ����������� �� ������ � ������ ���� ��� ����������� ������ ������
5514 5515 5516
			var oNewSpacing = new CParaSpacing();
			oNewSpacing.Set_FromObject({After: 0, Before: 0, Line: linerule_Auto});
            oNewPar.Set_Spacing(oNewSpacing);
5517 5518 5519 5520
            oPasteProcessor.aContent.push(oNewPar);
        }
        //��������� ����� ���������
        for(var i = 0, length = oPasteProcessor.aContent.length; i < length; ++i)
5521 5522 5523 5524 5525 5526
		{
			if(i == length - 1)
				cell.Content.Internal_Content_Add(i + 1, oPasteProcessor.aContent[i], true);
			else
				cell.Content.Internal_Content_Add(i + 1, oPasteProcessor.aContent[i], false);
		}
5527 5528 5529
        //������� ��������, ������� ��������� � ������� �� ���������
        cell.Content.Internal_Content_Remove(0, 1);
    },
5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554
	_CheckIsPlainText : function(node)
	{
		var bIsPlainText = true;
		for(var i = 0, length = node.childNodes.length; i < length; i++)
		{
			var child = node.childNodes[i];
			if(Node.ELEMENT_NODE == child.nodeType)
			{
				var sClass = child.getAttribute("class");
				var sStyle = child.getAttribute("style");
				if(sClass || sStyle)
				{
					bIsPlainText = false;
					break;
				}
				else if(!this._CheckIsPlainText(child))
				{
					bIsPlainText = false;
					break;
				}
					
			}
		}
		return bIsPlainText;
	},
5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594
    _Execute : function(node, pPr, bRoot, bAddParagraph, bInBlock)
    {
        //bAddParagraph ���� �������� �� ������� _Decide_AddParagraph, ��������� �������� ��� ���.
        //bAddParagraph ������������ � true, ����� ���������� ������� ������� � �� ��������� �������� ��������
        var oDocument = this.oDocument;
        var bRootHasBlock = false;//���� root ���� ������� �������, �� ���� ��� child ������� �����������
        //��� Root node �� ������� ����� � �� ��������� �����
        if(true == bRoot)
        {
            //���� ������� ��������� ���, �� �������� ����
            var bExist = false;
            for(var i = 0, length = node.childNodes.length; i < length; i++)
            {
                var child = node.childNodes[i];
                var bIsBlockChild = this._IsBlockElem(child.nodeName.toLowerCase());
                if(true == bIsBlockChild)
                {
                    bRootHasBlock = true;
                    bExist = true;
                    break;
                }
            }
            if(false == bExist && true == this.bIgnoreNoBlockText)
                this.bIgnoreNoBlockText = false;
        }
        else
        {
            if(Node.TEXT_NODE == node.nodeType)
            {
                if(false == this.bIgnoreNoBlockText || true == bInBlock)
                {
                    var value = node.nodeValue;
                    if(!value)
                        value = "";
                    //������� � ����� �������� \r|\t|\n, � �������� ������ �������� �� �� �������
                    //������ ���(�������� ������ chrome ��� ������� ��������� ������ � ������� \n)
                    value = value.replace(/^(\r|\t|\n)+|(\r|\t|\n)+$/g, '') ;
                    value = value.replace(/(\r|\t|\n)/g, ' ');
                    if(value.length > 0)
                    {
5595 5596 5597 5598
                        var oTargetNode = node.parentNode;
                        var bUseOnlyInherit = false;
                        if (this._IsBlockElem(oTargetNode.nodeName.toLowerCase()))
                            bUseOnlyInherit = true;
5599
                        bAddParagraph = this._Decide_AddParagraph(oTargetNode, pPr, bAddParagraph);
5600 5601

                        //��������� ������� ����� ���� �� ���������
5602
                        this._commit_rPr(oTargetNode, bUseOnlyInherit);
5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618
                        for(var i = 0, length = value.length; i < length; i++)
                        {
                            var Char = value.charAt(i);
                            var Code = value.charCodeAt(i);
                            var Item;
                            if(32 == Code || 160 == Code) //160 - nbsp
                                Item = new ParaSpace();
                            else
                                Item = new ParaText( value[i] );
                            this._Paragraph_Add( Item );
                        }
                    }
                }
                return bAddParagraph;
            }
            var sNodeName = node.nodeName.toLowerCase();
5619
            if("table" == sNodeName && this.pasteInExcel !== true)
5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666
            {
                if(g_bIsDocumentCopyPaste)
                {
                    this._StartExecuteTable(node, pPr);
                    return bAddParagraph;
                }
                else
                    return false;
            }

            //�������� �� html �������� ���������(�� ��� ������ �������� �� getComputedStyle)
            var style = node.getAttribute("style");
            if(style)
                this._parseCss(style, pPr);

            if("h1" == sNodeName)
                pPr.hLevel = 0;
            else if("h2" == sNodeName)
                pPr.hLevel = 1;
            else if("h3" == sNodeName)
                pPr.hLevel = 2;
            else if("h4" == sNodeName)
                pPr.hLevel = 3;
            else if("h5" == sNodeName)
                pPr.hLevel = 4;
            else if("h6" == sNodeName)
                pPr.hLevel = 5;

            if("ul" == sNodeName || "ol" == sNodeName || "li" == sNodeName)
            {
                pPr.bNum = true;
                if(g_bIsDocumentCopyPaste)
                {
                    if("ul" == sNodeName)
                        pPr.numType = numbering_numfmt_Bullet;
                    else if("ol" == sNodeName)
                        pPr.numType = numbering_numfmt_Decimal;
                }
                else
                {
                    if("ul" == sNodeName)
                        pPr.numType = numbering_presentationnumfrmt_Char;
                    else if("ol" == sNodeName)
                        pPr.numType = numbering_presentationnumfrmt_ArabicPeriod;
                }
            }

5667
            if("img" == sNodeName && this.pasteInExcel !== true)
5668 5669 5670 5671 5672 5673 5674 5675 5676
            {
                if(g_bIsDocumentCopyPaste)
                {
                    bAddParagraph = this._Decide_AddParagraph(node, pPr, bAddParagraph);
                    
                    var nWidth = parseInt(node.getAttribute("width"));
                    var nHeight = parseInt(node.getAttribute("height"));
                    if(!nWidth || !nHeight)
                    {
5677
						var computedStyle = this._getComputedStyle(node);
5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708
                        if ( computedStyle )
                        {
                            nWidth = parseInt(computedStyle.getPropertyValue("width"));
                            nHeight = parseInt(computedStyle.getPropertyValue("height"));
                        }
                    }
                    var sSrc = node.getAttribute("src");
                    if(isNaN(nWidth) || isNaN(nHeight) || !(typeof nWidth === "number") || !(typeof nHeight === "number")
                        ||  nWidth === 0 ||  nHeight === 0)
                    {
                        var img_prop = new CImgProperty();
                        img_prop.put_ImageUrl(sSrc);
                        var or_sz = img_prop.get_OriginSize(editor);
                        nWidth = or_sz.Width / g_dKoef_pix_to_mm;
                        nHeight = or_sz.Height / g_dKoef_pix_to_mm;
                    }
                    if(nWidth && nHeight && sSrc)
                    {
                        var sSrc = this.oImages[sSrc];
                        if(sSrc)
                        {
                            nWidth = nWidth * g_dKoef_pix_to_mm;
                            nHeight = nHeight * g_dKoef_pix_to_mm;
                            //��������� � this.dMaxWidth
                            var bUseScaleKoef = this.bUseScaleKoef;
                            var dScaleKoef = this.dScaleKoef;
                            if(nWidth * dScaleKoef > this.dMaxWidth)
                            {
                                dScaleKoef = dScaleKoef * this.dMaxWidth / nWidth;
                                bUseScaleKoef = true;
                            }
5709 5710
                            //закомментировал, потому что при вставке получаем изображения измененного размера
							/*if(bUseScaleKoef)
5711 5712 5713 5714
                            {
                                var dTemp = nWidth;
                                nWidth *= dScaleKoef;
                                nHeight *= dScaleKoef;
5715
                            }*/
5716 5717 5718 5719
                            var oTargetDocument = this.oDocument;
                            var oDrawingDocument = this.oDocument.DrawingDocument;
                            if(oTargetDocument && oDrawingDocument)
                            {
5720
								var Drawing = CreateImageFromBinary(sSrc, nWidth, nHeight);
5721
								// oTargetDocument.DrawingObjects.Add( Drawing );
5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736

                                this._Paragraph_Add( Drawing );

                                    //oDocument.Add_InlineImage(nWidth, nHeight, img);
                            }
                        }
                    }

                    return bAddParagraph;
                }
                else
                    return false;
            }

            //��������� linebreak, ���� �� �� ��������� ������� �������� � �� ����� ��� ������� �������
5737 5738
            var bPageBreakBefore = "always" == node.style.pageBreakBefore || "left" == node.style.pageBreakBefore || "right" == node.style.pageBreakBefore;
            if ("br" == sNodeName || bPageBreakBefore)
5739
            {
5740
                if (bPageBreakBefore)
5741 5742 5743 5744 5745 5746 5747 5748 5749 5750
                {
                    bAddParagraph = this._Decide_AddParagraph(node.parentNode, pPr, bAddParagraph);
                    bAddParagraph = true;
                    this._Commit_Br(0, node, pPr);
                    this._Paragraph_Add( new ParaNewLine( break_Page ) );
                }
                else
                {
                    bAddParagraph = this._Decide_AddParagraph(node.parentNode, pPr, bAddParagraph, false);
                    this.nBrCount++;//this._Paragraph_Add( new ParaNewLine( break_Line ) );
5751
                    if("line-break" == pPr["mso-special-character"] || "always" == pPr["mso-column-break-before"])
5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833
                        this._Commit_Br(0, node, pPr);
					return bAddParagraph;
                }
            }

            //�������� �� tab
            if("span" == sNodeName)
            {
                var nTabCount = parseInt(pPr["mso-tab-count"] || 0);
                if(nTabCount > 0)
                {
                    bAddParagraph = this._Decide_AddParagraph(node, pPr, bAddParagraph);
                    this._commit_rPr(node);
                    for(var i = 0; i < nTabCount; i++)
                        this._Paragraph_Add( new ParaTab() );
                    return bAddParagraph;
                }
            }
        }
        //���������� �������� ��� childNodes
        for(var i = 0, length = node.childNodes.length; i < length; i++)
        {
            var child = node.childNodes[i];
            var nodeType = child.nodeType;
            //��� ����������� �� word ����� ����������� ����������� �� �������
            //����������� ����������, ������ ������ ������
            if(Node.COMMENT_NODE == nodeType)
            {
                var value = child.nodeValue;
                var bSkip = false;
                if(value)
                {
                    if(-1 != value.indexOf("supportLists"))
                    {
                        //todo ���������� ��� ������
                        pPr.bNum = true;
                        bSkip = true;
                    }
                    if(-1 != value.indexOf("supportLineBreakNewLine"))
                        bSkip = true;
                }
                if(true == bSkip)
                {
                    //���������� ��� �� �������������� �����������
                    var j = i + 1;
                    for(; j < length; j++)
                    {
                        var tempNode = node.childNodes[j];
                        var tempNodeType = tempNode.nodeType;
                        if(Node.COMMENT_NODE == tempNodeType)
                        {
                            var tempvalue = tempNode.nodeValue;
                            if(tempvalue && -1 != tempvalue.indexOf("endif"))
                                break;
                        }
                    }
                    i = j;
                    continue;
                }
            }

            if(!(Node.ELEMENT_NODE == nodeType || Node.TEXT_NODE == nodeType))
                continue;
            //�������� ������� ��������� ������ �� \t,\n,\r
            if( Node.TEXT_NODE == child.nodeType)
            {
                var value = child.nodeValue;
                if(!value)
                    continue;
                value = value.replace(/(\r|\t|\n)/g, '');
                if("" == value)
                    continue;
            }
            var sChildNodeName = child.nodeName.toLowerCase();
            var bIsBlockChild = this._IsBlockElem(sChildNodeName);
            if(bRoot)
                this.bInBlock = false;
            if(bIsBlockChild)
            {
                bAddParagraph = true;
                this.bInBlock = true;
            }
5834 5835 5836
            var oOldHyperlink = null;
            var oOldHyperlinkContentPos = null;
            var oHyperlink = null;
5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852
            if("a" == sChildNodeName)
            {
                var href = child.href;
                if(null != href)
                {
                    var sDecoded;
                    //decodeURI ����� �������� malformed exception, ������ ��� ��� ���� � utf8, � ��������� ����� ����� ���������� url � ����� ���������(�������� windows-1251)
                    try
                    {
                        sDecoded = decodeURI(href);
                    }
                    catch(e) { sDecoded = href; }
                    href = sDecoded;
                    var title = child.getAttribute("title");

                    bAddParagraph = this._Decide_AddParagraph(child, pPr, bAddParagraph);
5853 5854
                    oHyperlink = new ParaHyperlink();
                    oHyperlink.Set_Paragraph(this.oCurPar);
5855 5856 5857
                    oHyperlink.Set_Value( href );
                    if(null != title)
                        oHyperlink.Set_ToolTip(title);
5858 5859 5860 5861
                    oOldHyperlink = this.oCurHyperlink;
                    oOldHyperlinkContentPos = this.oCurHyperlinkContentPos;
                    this.oCurHyperlink = oHyperlink;
                    this.oCurHyperlinkContentPos = 0;
5862 5863 5864 5865 5866
                }
            }
            bAddParagraph = this._Execute(child, Common_CopyObj(pPr), false, bAddParagraph, bIsBlockChild || bInBlock);
            if(bIsBlockChild)
                bAddParagraph = true;
5867 5868 5869 5870
            if ("a" == sChildNodeName && null != oHyperlink) {
                this.oCurHyperlink = oOldHyperlink;
                this.oCurHyperlinkContentPos = oOldHyperlinkContentPos;
                if(oHyperlink.Content.length > 0)
5871 5872 5873 5874 5875 5876 5877
                {
                    if(this.pasteInExcel)
                    {
                        var TextPr = new CTextPr();
                        TextPr.Unifill = CreateUniFillSchemeColorWidthTint(11, 0);
                        TextPr.Underline = true;
                        oHyperlink.Apply_TextPr( TextPr, undefined, true );
5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894
                    }
					
					//проставляем rStyle
					if(oHyperlink.Content && oHyperlink.Content.length)
					{
						if(this.oLogicDocument && this.oLogicDocument.Styles && this.oLogicDocument.Styles.Default && this.oLogicDocument.Styles.Default.Hyperlink && this.oLogicDocument.Styles.Style)
						{
							var hyperLinkStyle = this.oLogicDocument.Styles.Default.Hyperlink;
							
							for(var k = 0; k < oHyperlink.Content.length; k++)
							{
								if(oHyperlink.Content[k].Type == para_Run)
									oHyperlink.Content[k].Set_RStyle(hyperLinkStyle);
							}
						}
					}
					
5895
                    this._Paragraph_Add(oHyperlink);
5896
                }
5897
            }
5898 5899 5900 5901 5902 5903
        }
        if(bRoot)
        {
            this._Commit_Br(2, node, pPr);//word ���������� 2 ��������� br
        }
        return bAddParagraph;
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960
    },

    _ExecutePresentation : function(node, pPr, bRoot, bAddParagraph, bInBlock, arrShapes, arrImages, arrTables)
    {
        //bAddParagraph ���� �������� �� ������� _Decide_AddParagraph, ��������� �������� ��� ���.
        //bAddParagraph ������������ � true, ����� ���������� ������� ������� � �� ��������� �������� ��������
        var arr_shapes = [];
        var arr_images = [];
        var arr_tables = [];
        var oDocument = this.oDocument;
        var bRootHasBlock = false;//���� root ���� ������� �������, �� ���� ��� child ������� �����������
        //��� Root node �� ������� ����� � �� ��������� �����
        var presentation = editor.WordControl.m_oLogicDocument;

        var shape = arrShapes[arrShapes.length - 1];

        this.aContent = shape.txBody.content.Content;
        if(true == bRoot)
        {
            //���� ������� ��������� ���, �� �������� ����
            var bExist = false;
            for(var i = 0, length = node.childNodes.length; i < length; i++)
            {
                var child = node.childNodes[i];
                var bIsBlockChild = this._IsBlockElem(child.nodeName.toLowerCase());
                if(true == bIsBlockChild)
                {
                    bRootHasBlock = true;
                    bExist = true;
                    break;
                }
            }
            if(false == bExist && true == this.bIgnoreNoBlockText)
                this.bIgnoreNoBlockText = false;
        }
        else
        {
            if(Node.TEXT_NODE == node.nodeType)
            {
                if(false == this.bIgnoreNoBlockText || true == bInBlock)
                {
                    var value = node.nodeValue;
                    if(!value)
                        value = "";
                    //������� � ����� �������� \r|\t|\n, � �������� ������ �������� �� �� �������
                    //������ ���(�������� ������ chrome ��� ������� ��������� ������ � ������� \n)
                    value = value.replace(/^(\r|\t|\n)+|(\r|\t|\n)+$/g, '') ;
                    value = value.replace(/(\r|\t|\n)/g, ' ');
                    if(value.length > 0)
                    {
                        this.oDocument = shape.txBody.content;
                        shape.txBody.content.Add_NewParagraph();
                       // bAddParagraph = this._Decide_AddParagraph(node.parentNode, pPr, bAddParagraph);

                        //��������� ������� ����� ���� �� ���������
                        //this._commit_rPr(node.parentNode);

5961 5962 5963 5964 5965 5966
						if(!this.bIsPlainText)
						{
							var rPr = this._read_rPr(node.parentNode);
							var Item = new ParaTextPr( rPr);
							shape.paragraphAdd(Item);
						}
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035
                        for(var i = 0, length = value.length; i < length; i++)
                        {
                            var Char = value.charAt(i);
                            var Code = value.charCodeAt(i);
                            var Item;
                            if(32 == Code || 160 == Code) //160 - nbsp
                                Item = new ParaSpace();
                            else
                                Item = new ParaText( value[i] );
                            shape.paragraphAdd(Item);
                        }

                    }
                }
                return;
            }
            var sNodeName = node.nodeName.toLowerCase();
            if("table" == sNodeName)
            {
                this._StartExecuteTablePresentation(node, pPr, arrShapes, arrImages, arrTables);
                return;
            }

            //�������� �� html �������� ���������(�� ��� ������ �������� �� getComputedStyle)
            var style = node.getAttribute("style");
            if(style)
                this._parseCss(style, pPr);

            if("h1" == sNodeName)
                pPr.hLevel = 0;
            else if("h2" == sNodeName)
                pPr.hLevel = 1;
            else if("h3" == sNodeName)
                pPr.hLevel = 2;
            else if("h4" == sNodeName)
                pPr.hLevel = 3;
            else if("h5" == sNodeName)
                pPr.hLevel = 4;
            else if("h6" == sNodeName)
                pPr.hLevel = 5;

            if("ul" == sNodeName || "ol" == sNodeName || "li" == sNodeName)
            {
                pPr.bNum = true;
                if(g_bIsDocumentCopyPaste)
                {
                    if("ul" == sNodeName)
                        pPr.numType = numbering_numfmt_Bullet;
                    else if("ol" == sNodeName)
                        pPr.numType = numbering_numfmt_Decimal;
                }
                else
                {
                    if("ul" == sNodeName)
                        pPr.numType = numbering_presentationnumfrmt_Char;
                    else if("ol" == sNodeName)
                        pPr.numType = numbering_presentationnumfrmt_ArabicPeriod;
                }
            }

            if("img" == sNodeName)
            {

                //bAddParagraph = this._Decide_AddParagraph(node, pPr, bAddParagraph);

                var nWidth = parseInt(node.getAttribute("width"));
                var nHeight = parseInt(node.getAttribute("height"));
                if(!nWidth || !nHeight)
                {
6036
					var computedStyle = this._getComputedStyle(node);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096
                    if ( computedStyle )
                    {
                        nWidth = parseInt(computedStyle.getPropertyValue("width"));
                        nHeight = parseInt(computedStyle.getPropertyValue("height"));
                    }
                }
                var sSrc = node.getAttribute("src");
                if(isNaN(nWidth) || isNaN(nHeight) || !(typeof nWidth === "number") || !(typeof nHeight === "number")
                    ||  nWidth === 0 ||  nHeight === 0)
                {
                    var img_prop = new CImgProperty();
                    img_prop.put_ImageUrl(sSrc);
                    var or_sz = img_prop.get_OriginSize(editor);
                    nWidth = or_sz.Width / g_dKoef_pix_to_mm;
                    nHeight = or_sz.Height / g_dKoef_pix_to_mm;
                }
                else
                {
                    nWidth *= g_dKoef_pix_to_mm;
                    nHeight *= g_dKoef_pix_to_mm;
                }
                if(nWidth && nHeight && sSrc)
                {
                    var sSrc = this.oImages[sSrc];
                    if(sSrc)
                    {
                        var image = new CImageShape(presentation.Slides[presentation.CurPage]);
                        var blipFill = new CUniFill();
                        blipFill.fill = new CBlipFill();
                        blipFill.fill.RasterImageId = sSrc;
                        image.setBlipFill(blipFill);
                        image.setGeometry( CreateGeometry("rect"));
                        image.spPr.geometry.Init(5, 5);
                        image.setXfrm(node["offsetLeft"], node["offsetTop"], nWidth, nHeight, null, null, null);
                        arrImages.push(image);
                    }
                }
                return bAddParagraph;

            }

            //��������� linebreak, ���� �� �� ��������� ������� �������� � �� ����� ��� ������� �������
            if("br" == sNodeName || "always" == node.style.pageBreakBefore)
            {
                if("always" == node.style.pageBreakBefore)
                {
                    shape.paragraphAdd(new ParaNewLine( break_Line ));
                }
                else
                {
                    shape.paragraphAdd(new ParaNewLine( break_Line ));
                }
            }

            //�������� �� tab
            if("span" == sNodeName)
            {
                var nTabCount = parseInt(pPr["mso-tab-count"] || 0);
                if(nTabCount > 0)
                {
6097 6098 6099 6100 6101 6102
					if(!this.bIsPlainText)
					{
						var rPr = this._read_rPr(node);
						var Item = new ParaText( rPr);
						shape.paragraphAdd(Item);
					}
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229
                    for(var i = 0; i < nTabCount; i++)
                        shape.paragraphAdd( new ParaTab() );
                    return;
                }
            }
        }
        //���������� �������� ��� childNodes
        for(var i = 0, length = node.childNodes.length; i < length; i++)
        {
            var child = node.childNodes[i];
            var nodeType = child.nodeType;
            //��� ����������� �� word ����� ����������� ����������� �� �������
            //����������� ����������, ������ ������ ������
            if(Node.COMMENT_NODE == nodeType)
            {
                var value = child.nodeValue;
                var bSkip = false;
                if(value)
                {
                    if(-1 != value.indexOf("supportLists"))
                    {
                        //todo ���������� ��� ������
                        pPr.bNum = true;
                        bSkip = true;
                    }
                    if(-1 != value.indexOf("supportLineBreakNewLine"))
                        bSkip = true;
                }
                if(true == bSkip)
                {
                    //���������� ��� �� �������������� �����������
                    var j = i + 1;
                    for(; j < length; j++)
                    {
                        var tempNode = node.childNodes[j];
                        var tempNodeType = tempNode.nodeType;
                        if(Node.COMMENT_NODE == tempNodeType)
                        {
                            var tempvalue = tempNode.nodeValue;
                            if(tempvalue && -1 != tempvalue.indexOf("endif"))
                                break;
                        }
                    }
                    i = j;
                    continue;
                }
            }

            if(!(Node.ELEMENT_NODE == nodeType || Node.TEXT_NODE == nodeType))
                continue;
            //�������� ������� ��������� ������ �� \t,\n,\r
            if( Node.TEXT_NODE == child.nodeType)
            {
                var value = child.nodeValue;
                if(!value)
                    continue;
                value = value.replace(/(\r|\t|\n)/g, '');
                if("" == value)
                    continue;
            }
            var sChildNodeName = child.nodeName.toLowerCase();
            var bIsBlockChild = this._IsBlockElem(sChildNodeName);
            if(bRoot)
                this.bInBlock = false;
            if(bIsBlockChild)
            {
                bAddParagraph = true;
                this.bInBlock = true;
            }

            var bHyperlink = false;
            if("a" == sChildNodeName)
            {
                var href = child.href;
                if(null != href)
                {
                    var sDecoded;
                    //decodeURI ����� �������� malformed exception, ������ ��� ��� ���� � utf8, � ��������� ����� ����� ���������� url � ����� ���������(�������� windows-1251)
                    try
                    {
                        sDecoded = decodeURI(href);
                    }
                    catch(e) { sDecoded = href; }
                    href = sDecoded;
                    bHyperlink = true;
                    var title = child.getAttribute("title");

                    this.oDocument = shape.txBody.content;
                   // bAddParagraph = this._Decide_AddParagraph(child, pPr, bAddParagraph);
                    var oHyperlink = new ParaHyperlinkStart();
                    oHyperlink.Set_Value( href );
                    if(null != title)
                        oHyperlink.Set_ToolTip(title);
                    shape.paragraphAdd( oHyperlink );
                }
            }

            bAddParagraph = this._ExecutePresentation(child, Common_CopyObj(pPr), false, bAddParagraph, bIsBlockChild || bInBlock, arrShapes, arrImages, arrTables);
            if(bIsBlockChild)
                bAddParagraph = true;
            if("a" == sChildNodeName && true == bHyperlink)
                shape.paragraphAdd( new ParaHyperlinkEnd() );
        }
        if(bRoot)
        {
            //this._Commit_Br(2, node, pPr);//word ���������� 2 ��������� br
        }
        return;
    },

    _StartExecuteTablePresentation : function(node, pPr, arrShapes, arrImages, arrTables)
    {
        var oDocument = this.oDocument;
        var tableNode = node;
        //���� ���� ���� tbody
        for(var i = 0, length = node.childNodes.length; i < length; ++i)
        {
            if("tbody" == node.childNodes[i].nodeName.toLowerCase())
            {
                node = node.childNodes[i];
                break;
            }
        }
        //��������� �����. � ������� �� ����� ���� ����� ��������� �� ����������� ���������� �����.
        var nRowCount = 0;
        var nMinColCount = 0;
        var nMaxColCount = 0;
Alexander.Trofimov's avatar
Alexander.Trofimov committed
6230
        var aColsCountByRow = [];
Alexander.Trofimov's avatar
Alexander.Trofimov committed
6231
        var oRowSums = {};
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
6232 6233 6234 6235
        oRowSums[0] = 0;
        var dMaxSum = 0;
        var nCurColWidth = 0;
        var nCurSum = 0;
Alexander.Trofimov's avatar
Alexander.Trofimov committed
6236
        var oRowSpans = {};
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264
        var fParseSpans = function()
        {
            var spans = oRowSpans[nCurColWidth];
            while(null != spans && spans.row > 0)
            {
                spans.row--;
                nCurColWidth += spans.col;
                nCurSum += spans.width;
                spans = oRowSpans[nCurColWidth];
            }
        };
        for(var i = 0, length = node.childNodes.length; i < length; ++i)
        {
            var tr = node.childNodes[i];
            if("tr" == tr.nodeName.toLowerCase())
            {
                nCurSum = 0;
                nCurColWidth = 0;
                var nMinRowSpanCount = null;//����������� rowspan ����� ������
                for(var j = 0, length2 = tr.childNodes.length; j < length2; ++j)
                {
                    var tc = tr.childNodes[j];
                    var tcName = tc.nodeName.toLowerCase();
                    if("td" == tcName || "th" == tcName)
                    {
                        fParseSpans();

                        var dWidth = null;
6265
						var computedStyle = this._getComputedStyle(tc);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350
                        if ( computedStyle )
                        {
                            var computedWidth = computedStyle.getPropertyValue( "width" );
                            if(null != computedWidth && null != (computedWidth = this._ValueToMm(computedWidth)))
                                dWidth = computedWidth;
                        }
                        if(null == dWidth)
                            dWidth = tc.clientWidth * g_dKoef_pix_to_mm;

                        var nColSpan = tc.getAttribute("colspan");
                        if(null != nColSpan)
                            nColSpan = nColSpan - 0;
                        else
                            nColSpan = 1;
                        var nCurRowSpan = tc.getAttribute("rowspan");
                        if(null != nCurRowSpan)
                        {
                            nCurRowSpan = nCurRowSpan - 0;
                            if(null == nMinRowSpanCount)
                                nMinRowSpanCount = nCurRowSpan;
                            else if(nMinRowSpanCount > nCurRowSpan)
                                nMinRowSpanCount = nCurRowSpan;
                            if(nCurRowSpan > 1)
                                oRowSpans[nCurColWidth] = {row: nCurRowSpan - 1, col: nColSpan, width: dWidth};
                        }
                        else
                            nMinRowSpanCount = 0;

                        nCurSum += dWidth;
                        if(null == oRowSums[nCurColWidth + nColSpan])
                            oRowSums[nCurColWidth + nColSpan] = nCurSum;
                        nCurColWidth += nColSpan;
                    }
                }
                fParseSpans();
                //������� ������ rowspan
                if(nMinRowSpanCount > 1)
                {
                    for(var j = 0, length2 = tr.childNodes.length; j < length2; ++j)
                    {
                        var tc = tr.childNodes[j];
                        var tcName = tc.nodeName.toLowerCase();
                        if("td" == tcName || "th" == tcName)
                        {
                            var nCurRowSpan = tc.getAttribute("rowspan");
                            if(null != nCurRowSpan)
                                tc.setAttribute("rowspan", nCurRowSpan - nMinRowSpanCount);
                        }
                    }
                }
                if(dMaxSum < nCurSum)
                    dMaxSum = nCurSum;
                //������� ������ tr
                if(0 == nCurColWidth)
                {
                    node.removeChild(tr);
                    length--;
                    i--;
                }
                else
                {
                    if(0 == nMinColCount || nMinColCount > nCurColWidth)
                        nMinColCount = nCurColWidth;
                    if(nMaxColCount < nCurColWidth)
                        nMaxColCount = nCurColWidth;
                    nRowCount++;
                    aColsCountByRow.push(nCurColWidth);
                }
            }
        }
        if(nMaxColCount != nMinColCount)
        {
            for(var i = 0, length = aColsCountByRow.length; i < length; ++i)
                aColsCountByRow[i] = nMaxColCount - aColsCountByRow[i];
        }
        if(nRowCount > 0 && nMaxColCount > 0)
        {
            var bUseScaleKoef = this.bUseScaleKoef;
            var dScaleKoef = this.dScaleKoef;
            if(dMaxSum * dScaleKoef > this.dMaxWidth)
            {
                dScaleKoef = dScaleKoef * this.dMaxWidth / dMaxSum;
                bUseScaleKoef = true;
            }
            //������ Grid
Alexander.Trofimov's avatar
Alexander.Trofimov committed
6351
            var aGrid = [];
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387
            var nPrevIndex = null;
            var nPrevVal = 0;
            for(var i in oRowSums)
            {
                var nCurIndex = i - 0;
                var nCurVal = oRowSums[i];
                var nCurWidth = nCurVal - nPrevVal;
                if(bUseScaleKoef)
                    nCurWidth *= dScaleKoef;
                if(null != nPrevIndex)
                {
                    var nDif = nCurIndex - nPrevIndex;
                    if(1 == nDif)
                        aGrid.push(nCurWidth);
                    else
                    {
                        var nPartVal = nCurWidth / nDif;
                        for(var i = 0; i < nDif; ++i)
                            aGrid.push(nPartVal);
                    }
                }
                nPrevVal = nCurVal;
                nPrevIndex = nCurIndex;
            }
            var CurPage = 0;
            var presentation = editor.WordControl.m_oLogicDocument;
            var graphicFrame = new CGraphicFrame(presentation.Slides[presentation.CurPage]);

            var table = new CTable(presentation.DrawingDocument, graphicFrame, true, 0, 0, 0, X_Right_Field, Y_Bottom_Field, 0, 0, aGrid);
            table.Set_TableStyle(0);
            var dd = editor.WordControl.m_oDrawingDocument;
            graphicFrame.setGraphicObject(table);
            arrTables.push(graphicFrame);
            graphicFrame.setXfrm(dd.GetMMPerDot(node["offsetLeft"]), dd.GetMMPerDot(node["offsetTop"]), dd.GetMMPerDot(node["offsetWidth"]), dd.GetMMPerDot(node["offsetHeight"]), null, null, null);

            //считаем aSumGrid
Alexander.Trofimov's avatar
Alexander.Trofimov committed
6388
            var aSumGrid = [];
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414
            aSumGrid[-1] = 0;
            var nSum = 0;
            for(var i = 0, length = aGrid.length; i < length; ++i)
            {
                nSum += aGrid[i];
                aSumGrid[i] = nSum;
            }
            //�������� content
             this._ExecuteTablePresentation(tableNode, node, table, aSumGrid, nMaxColCount != nMinColCount ? aColsCountByRow : null, pPr, bUseScaleKoef, dScaleKoef, arrShapes, arrImages, arrTables);
            table.Cursor_MoveToStartPos();
            return;
        }
    },

    _ExecuteTablePresentation : function(tableNode, node, table, aSumGrid, aColsCountByRow, pPr, bUseScaleKoef, dScaleKoef, arrShapes, arrImages, arrTables)
    {
        //из-за проблем со вставкой больших таблиц, не вставляем tbllayout_AutoFit
        table.Set_TableLayout(tbllayout_Fixed);
        //Pr
        var Pr = table.Pr;
        //align ������� � parent tableNode
        var sTableAlign = null;
        if(null != tableNode.align)
            sTableAlign = tableNode.align
        else if(null != tableNode.parentNode && this.oRootNode != tableNode.parentNode)
        {
6415
			var computedStyleParent = this._getComputedStyle(tableNode.parentNode);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435
            if(null != computedStyleParent)
            {
                //����� ��������� -webkit-right
                sTableAlign = computedStyleParent.getPropertyValue( "text-align" );
            }
        }
        if(null != sTableAlign)
        {
            if(-1 != sTableAlign.indexOf('center'))
                table.Set_TableAlign(align_Center);
            else if(-1 != sTableAlign.indexOf('right'))
                table.Set_TableAlign(align_Right);
        }
        var spacing = null;
        table.Set_TableBorder_InsideH(new CDocumentBorder());
        table.Set_TableBorder_InsideV(new CDocumentBorder());

        var style = tableNode.getAttribute("style");
        if(style)
        {
Alexander.Trofimov's avatar
Alexander.Trofimov committed
6436
            var tblPrMso = {};
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477
            this._parseCss(style, tblPrMso);
            var spacing = tblPrMso["mso-cellspacing"];
            if(null != spacing && null != (spacing = this._ValueToMm(spacing)))
                ;
            var padding = tblPrMso["mso-padding-alt"];
            if(null != padding)
            {
                padding = trimString(padding);
                var aMargins = padding.split(" ");
                if(4 == aMargins.length)
                {
                    var top = aMargins[0];
                    if(null != top && null != (top = this._ValueToMm(top)))
                        ;
                    else
                        top = Pr.TableCellMar.Top.W;
                    var right = aMargins[1];
                    if(null != right && null != (right = this._ValueToMm(right)))
                        ;
                    else
                        right = Pr.TableCellMar.Right.W;
                    var bottom = aMargins[2];
                    if(null != bottom && null != (bottom = this._ValueToMm(bottom)))
                        ;
                    else
                        bottom = Pr.TableCellMar.Bottom.W;
                    var left = aMargins[3];
                    if(null != left && null != (left = this._ValueToMm(left)))
                        ;
                    else
                        left = Pr.TableCellMar.Left.W;
                    table.Set_TableCellMar(left, top, right, bottom);
                }
            }
            var insideh = tblPrMso["mso-border-insideh"];
            if(null != insideh)
                table.Set_TableBorder_InsideH(this._ExecuteParagraphBorder(insideh));
            var insidev = tblPrMso["mso-border-insidev"];
            if(null != insidev)
                table.Set_TableBorder_InsideV(this._ExecuteParagraphBorder(insidev));
        }
6478
		var computedStyle = this._getComputedStyle(tableNode);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
6479 6480 6481 6482 6483 6484 6485 6486 6487
        if(computedStyle)
        {
            if(align_Left == table.Get_TableAlign())
            {
                var margin_left = computedStyle.getPropertyValue( "margin-left" );
                //todo возможно надо еще учесть ширину таблицы
                if(margin_left && null != (margin_left = this._ValueToMm(margin_left)) && margin_left < Page_Width - X_Left_Margin)
                    table.Set_TableInd(margin_left);
            }
6488
            var background_color = computedStyle.getPropertyValue( "background-color" );
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516
            if(null != background_color && (background_color = this._ParseColor(background_color)))
                table.Set_TableShd(shd_Clear, background_color.r, background_color.g, background_color.b);
            var oLeftBorder = this._ExecuteBorder(computedStyle, tableNode, "left", "Left", false);
            if(null != oLeftBorder)
                table.Set_TableBorder_Left(oLeftBorder);
            var oTopBorder = this._ExecuteBorder(computedStyle, tableNode, "top", "Top", false);
            if(null != oTopBorder)
                table.Set_TableBorder_Top(oTopBorder);
            var oRightBorder = this._ExecuteBorder(computedStyle, tableNode, "right", "Right", false);
            if(null != oRightBorder)
                table.Set_TableBorder_Right(oRightBorder);
            var oBottomBorder = this._ExecuteBorder(computedStyle, tableNode, "bottom", "Bottom", false);
            if(null != oBottomBorder)
                table.Set_TableBorder_Bottom(oBottomBorder);

            if(null == spacing)
            {
                spacing = computedStyle.getPropertyValue( "padding" );
                if(!spacing)
                    spacing = tableNode.style.padding;
                if(!spacing)
                    spacing = null;
                if(spacing && null != (spacing = this._ValueToMm(spacing)))
                    ;
            }
        }

        //content
Alexander.Trofimov's avatar
Alexander.Trofimov committed
6517
        var oRowSpans = {};
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544
        for(var i = 0, length = node.childNodes.length; i < length; ++i)
        {
            var tr = node.childNodes[i];
            if("tr" == tr.nodeName.toLowerCase())
            {
                var row = table.Internal_Add_Row(table.Content.length, 0);
                this._ExecuteTableRowPresentation(tr, row, aSumGrid, spacing, oRowSpans, bUseScaleKoef, dScaleKoef, arrShapes, arrImages, arrTables);
            }
        }
    },
    _ExecuteTableRowPresentation : function(node, row, aSumGrid, spacing, oRowSpans, bUseScaleKoef, dScaleKoef, arrShapes, arrImages, arrTables)
    {
        var oThis = this;
        var table = row.Table;
        if(null != spacing && spacing >= tableSpacingMinValue)
            row.Set_CellSpacing(spacing);
        if(node.style.height)
        {
            var height = node.style.height;
            if(!("auto" == height || "inherit" == height || -1 != height.indexOf("%")) && null != (height = this._ValueToMm(height)))
                row.Set_Height(height, heightrule_AtLeast);
        }
        var bBefore = false;
        var bAfter = false;
        var style = node.getAttribute("style");
        if(null != style)
        {
Alexander.Trofimov's avatar
Alexander.Trofimov committed
6545
            var tcPr = {};
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636
            this._parseCss(style, tcPr);
            var margin_left = tcPr["mso-row-margin-left"];
            if(margin_left && null != (margin_left = this._ValueToMm(margin_left)))
                bBefore = true;
            var margin_right = tcPr["mso-row-margin-right"];
            if(margin_right && null != (margin_right = this._ValueToMm(margin_right)))
                bAfter = true;
        }

        //content
        var nCellIndex = 0;
        var nCellIndexSpan = 0;
        var fParseSpans = function()
        {
            var spans = oRowSpans[nCellIndexSpan];
            while(null != spans)
            {
                var oCurCell = row.Add_Cell(row.Get_CellsCount(), row, null, false);
                oCurCell.Set_VMerge(vmerge_Continue);
                if(spans.col > 1)
                    oCurCell.Set_GridSpan(spans.col);
                spans.row--;
                if(spans.row <= 0)
                    delete oRowSpans[nCellIndexSpan];
                nCellIndexSpan += spans.col;
                spans = oRowSpans[nCellIndexSpan];
            }
        };
        var oBeforeCell = null;
        var oAfterCell = null;
        if(bBefore || bAfter)
        {
            for(var i = 0, length = node.childNodes.length; i < length; ++i)
            {
                var tc = node.childNodes[i];
                var tcName = tc.nodeName.toLowerCase();
                if("td" == tcName || "th" == tcName)
                {
                    if(bBefore && null != oBeforeCell)
                        oBeforeCell = tc;
                    else if(bAfter)
                        oAfterCell = tc;
                }
            }
        }
        for(var i = 0, length = node.childNodes.length; i < length; ++i)
        {
            //����� ����� ���� ��� ��� ����� ����������� td, ������ ��� ����������� ���������� ������ ����������� � dom
            fParseSpans();

            var tc = node.childNodes[i];
            var tcName = tc.nodeName.toLowerCase();
            if("td" == tcName || "th" == tcName)
            {
                var nColSpan = tc.getAttribute("colspan");
                if(null != nColSpan)
                    nColSpan = nColSpan - 0;
                else
                    nColSpan = 1;
                if(tc == oBeforeCell)
                    row.Set_Before(nColSpan);
                else if(tc == oAfterCell)
                    row.Set_After(nColSpan);
                else
                {
                    var oCurCell = row.Add_Cell(row.Get_CellsCount(), row, null, false);
                    if(nColSpan > 1)
                        oCurCell.Set_GridSpan(nColSpan);
                    var width = aSumGrid[nCellIndexSpan + nColSpan - 1] - aSumGrid[nCellIndexSpan - 1];
                    oCurCell.Set_W(new CTableMeasurement(tblwidth_Mm, width));
                    var nRowSpan = tc.getAttribute("rowspan");
                    if(null != nRowSpan)
                        nRowSpan = nRowSpan - 0;
                    else
                        nRowSpan = 1;
                    if(nRowSpan > 1)
                        oRowSpans[nCellIndexSpan] = {row: nRowSpan - 1, col: nColSpan};
                    this._ExecuteTableCellPresentation(tc, oCurCell, bUseScaleKoef, dScaleKoef, spacing, arrShapes, arrImages, arrTables);
                }
                nCellIndexSpan+=nColSpan;
            }
        }
        fParseSpans();
    },
    _ExecuteTableCellPresentation : function(node, cell, bUseScaleKoef, dScaleKoef, spacing, arrShapes, arrImages, arrTables)
    {
        //Pr
        var Pr = cell.Pr;
        var bAddIfNull = false;
        if(null != spacing)
            bAddIfNull = true;
6637
		var computedStyle = this._getComputedStyle(node);
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
6638 6639
        if(null != computedStyle)
        {
6640
            var background_color = computedStyle.getPropertyValue( "background-color" );
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689
            if(null != background_color && (background_color = this._ParseColor(background_color)))
            {
                var Shd = new CDocumentShd();
                Shd.Value = shd_Clear;
                Shd.Color = background_color;
                cell.Set_Shd(Shd);
            }
            var border = this._ExecuteBorder(computedStyle, node, "left", "Left", bAddIfNull);
            if(null != border)
                cell.Set_Border(border, 3);
            var border = this._ExecuteBorder(computedStyle, node, "top", "Top", bAddIfNull);
            if(null != border)
                cell.Set_Border(border, 0);
            var border = this._ExecuteBorder(computedStyle, node, "right", "Right", bAddIfNull);
            if(null != border)
                cell.Set_Border(border, 1);
            var border = this._ExecuteBorder(computedStyle, node, "bottom", "Bottom", bAddIfNull);
            if(null != border)
                cell.Set_Border(border, 2);

            var top = computedStyle.getPropertyValue( "padding-top" );
            if(null != top && null != (top = this._ValueToMm(top)))
                cell.Set_Margins({ W : top, Type : tblwidth_Mm }, 0);
            var right = computedStyle.getPropertyValue( "padding-right" );
            if(null != right && null != (right = this._ValueToMm(right)))
                cell.Set_Margins({ W : right, Type : tblwidth_Mm }, 1);
            var bottom = computedStyle.getPropertyValue( "padding-bottom" );
            if(null != bottom && null != (bottom = this._ValueToMm(bottom)))
                cell.Set_Margins({ W : bottom, Type : tblwidth_Mm }, 2);
            var left = computedStyle.getPropertyValue( "padding-left" );
            if(null != left && null != (left = this._ValueToMm(left)))
                cell.Set_Margins({ W : left, Type : tblwidth_Mm }, 3);
        }

        var arrShapes2 = [], arrImages2 = [], arrTables2 = [];
        var presentation = editor.WordControl.m_oLogicDocument;
        var shape = new CShape(presentation.Slides[presentation.CurPage]);
        var dd = presentation.DrawingDocument;
        shape.setTextBody(new CTextBody(shape));
        shape.setXfrm(dd.GetMMPerDot(node["offsetLeft"]), dd.GetMMPerDot(node["offsetTop"]), dd.GetMMPerDot(node["offsetWidth"]), dd.GetMMPerDot(node["offsetHeight"]), null, null, null);
        arrShapes2.push(shape);
        this._ExecutePresentation(node, {}, true, true, false, arrShapes2, arrImages2, arrTables);
        if(arrShapes2.length > 0)
        {
            var first_shape = arrShapes2[0];
            var content = first_shape.txBody.content;

            //��������� ����� ���������
            for(var i = 0, length = content.Content.length; i < length; ++i)
6690 6691 6692 6693 6694 6695
			{
				if(i == length - 1)
					cell.Content.Internal_Content_Add(i + 1, content.Content[i], true);
				else
					cell.Content.Internal_Content_Add(i + 1, content.Content[i], false);
			}
Sergey.Luzyanin's avatar
 
Sergey.Luzyanin committed
6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711
            //������� ��������, ������� ��������� � ������� �� ���������
            cell.Content.Internal_Content_Remove(0, 1);
            arrShapes2.splice(0, 1);
        }
        for(var i = 0;  i< arrShapes2.length; ++i)
        {
            arrShapes.push(arrShapes2[i]);
        }
        for(var i = 0;  i< arrImages2.length; ++i)
        {
            arrImages.push(arrImages2[i]);
        }
        for(var i = 0;  i< arrTables2.length; ++i)
        {
            arrTables.push(arrTables2[i]);
        }
6712
    }
Oleg.Korshul's avatar
Oleg.Korshul committed
6713 6714 6715 6716
};

function SafariIntervalFocus()
{
Oleg.Korshul's avatar
 
Oleg.Korshul committed
6717
    if (window.editor && window.editor.WordControl && window.editor.WordControl.IsFocus && (!window.editor.WordControl.TextBoxInputFocus))
Oleg.Korshul's avatar
Oleg.Korshul committed
6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733
    {
        var pastebin = document.getElementById(COPY_ELEMENT_ID);
        if (pastebin)
            pastebin.focus();
        else
        {
            // create
            Editor_CopyPaste_Create(window.editor);
        }
    }
}

function Editor_CopyPaste_Create(api)
{
    var ElemToSelect = document.createElement("div");
    ElemToSelect.id = COPY_ELEMENT_ID;
Oleg.Korshul's avatar
 
Oleg.Korshul committed
6734
    ElemToSelect.className = "sdk-element";
Oleg.Korshul's avatar
Oleg.Korshul committed
6735 6736 6737
    ElemToSelect.style.position = "absolute";

    ElemToSelect.style.left = '0px';
Oleg.Korshul's avatar
 
Oleg.Korshul committed
6738
    ElemToSelect.style.top = '-100px';
6739
    ElemToSelect.style.width = '10000px';
Oleg.Korshul's avatar
Oleg.Korshul committed
6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761
    ElemToSelect.style.height = '100px';
    ElemToSelect.style.overflow = 'hidden';
    ElemToSelect.style.zIndex = -1000;
    ElemToSelect.style.MozUserSelect = "text";
    ElemToSelect.style["-khtml-user-select"] = "text";
    ElemToSelect.style["-o-user-select"] = "text";
    ElemToSelect.style["user-select"] = "text";
    ElemToSelect.style["-webkit-user-select"] = "text";
    ElemToSelect.setAttribute("contentEditable", true);

    var Def_rPr = api.WordControl.m_oLogicDocument.Styles.Default.TextPr;
    ElemToSelect.style.fontFamily = Def_rPr.FontFamily.Name;

    if (!api.DocumentReaderMode)
        ElemToSelect.style.fontSize = Def_rPr.FontSize + "pt";
    else
    {
        api.DocumentReaderMode.CorrectDefaultFontSize(Def_rPr.FontSize);
        ElemToSelect.style.fontSize = "1em";
    }

    ElemToSelect.onpaste = function(e){
Oleg.Korshul's avatar
 
Oleg.Korshul committed
6762 6763 6764 6765
        if (!window.GlobalPasteFlag)
            return;

        // тут onpaste не обрубаем, так как он в сафари под macos приходить должен
Oleg.Korshul's avatar
 
Oleg.Korshul committed
6766 6767 6768
        if (window.GlobalPasteFlagCounter == 1)
        {
            Body_Paste(api,e);
Oleg.Korshul's avatar
 
Oleg.Korshul committed
6769 6770 6771

            if (window.GlobalPasteFlag)
                window.GlobalPasteFlagCounter = 2;
Oleg.Korshul's avatar
 
Oleg.Korshul committed
6772
        }
Oleg.Korshul's avatar
Oleg.Korshul committed
6773 6774
    };

6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790
    var TIME_PREVIOS_ONBEFORE_EVENTS = new Date().getTime();
    // не разобравшись не править!
    // эти евенты приходят дважды. так как операции могут быть длительтными,
    // то смотрится время окончания предыдущего и начало следующего евента

    ElemToSelect["onbeforecut"] = function(e){
        var _time = new Date().getTime();
        if (_time - TIME_PREVIOS_ONBEFORE_EVENTS < 100)
            return;

        api.WordControl.m_oLogicDocument.Create_NewHistoryPoint();
        Editor_Copy(api,true);

        TIME_PREVIOS_ONBEFORE_EVENTS = new Date().getTime();
    };

Oleg.Korshul's avatar
 
Oleg.Korshul committed
6791
    ElemToSelect["onbeforecopy"] = function(e){
6792 6793 6794 6795
        var _time = new Date().getTime();
        if (_time - TIME_PREVIOS_ONBEFORE_EVENTS < 100)
            return;

Oleg.Korshul's avatar
Oleg.Korshul committed
6796
        Editor_Copy(api,false);
6797 6798

        TIME_PREVIOS_ONBEFORE_EVENTS = new Date().getTime();
Oleg.Korshul's avatar
Oleg.Korshul committed
6799 6800 6801 6802
    };

    document.body.appendChild( ElemToSelect );
}