function CDrawingStreamSerializer()
{
    this.Memory = [];
}

CDrawingStreamSerializer.prototype["PD_put_GlobalAlpha"] = function(enable, alpha)
{
    this.Memory.push(0);
    this.Memory.push(enable);
    this.Memory.push(alpha);
};
CDrawingStreamSerializer.prototype["PD_End_GlobalAlpha"] = function()
{
    this.Memory.push(1);
};
CDrawingStreamSerializer.prototype["PD_p_color"] = function(r,g,b,a)
{
    this.Memory.push(2);
    this.Memory.push(r);
    this.Memory.push(g);
    this.Memory.push(b);
    this.Memory.push(a);
};
CDrawingStreamSerializer.prototype["PD_p_width"] = function(w)
{
    this.Memory.push(3);
    this.Memory.push(w);
};
CDrawingStreamSerializer.prototype["PD_b_color1"] = function(r,g,b,a)
{
    this.Memory.push(4);
    this.Memory.push(r);
    this.Memory.push(g);
    this.Memory.push(b);
    this.Memory.push(a);
};
CDrawingStreamSerializer.prototype["PD_b_color2"] = function(r,g,b,a)
{
    this.Memory.push(5);
    this.Memory.push(r);
    this.Memory.push(g);
    this.Memory.push(b);
    this.Memory.push(a);
};
CDrawingStreamSerializer.prototype["PD_transform"] = function(sx,shy,shx,sy,tx,ty)
{
    this.Memory.push(6);
    this.Memory.push(sx);
    this.Memory.push(shy);
    this.Memory.push(shx);
    this.Memory.push(sy);
    this.Memory.push(tx);
    this.Memory.push(ty);
};
CDrawingStreamSerializer.prototype["PD_PathStart"] = function()
{
    this.Memory.push(11);
};
CDrawingStreamSerializer.prototype["PD_PathEnd"] = function()
{
    this.Memory.push(12);
};
CDrawingStreamSerializer.prototype["PD_PathClose"] = function()
{
    this.Memory.push(13);
};
CDrawingStreamSerializer.prototype["PD_PathMoveTo"] = function(x,y)
{
    this.Memory.push(7);
    this.Memory.push(x);
    this.Memory.push(y);
};
CDrawingStreamSerializer.prototype["PD_PathLineTo"] = function(x,y)
{
    this.Memory.push(8);
    this.Memory.push(x);
    this.Memory.push(y);
};
CDrawingStreamSerializer.prototype["PD_PathCurveTo"] = function(x1,y1,x2,y2,x3,y3)
{
    this.Memory.push(9);
    this.Memory.push(x1);
    this.Memory.push(y1);
    this.Memory.push(x2);
    this.Memory.push(y2);
    this.Memory.push(x3);
    this.Memory.push(y3);
};
CDrawingStreamSerializer.prototype["PD_PathCurveTo2"] = function(x1,y1,x2,y2)
{
    this.Memory.push(10);
    this.Memory.push(x1);
    this.Memory.push(y1);
    this.Memory.push(x2);
    this.Memory.push(y2);
};
CDrawingStreamSerializer.prototype["PD_Stroke"] = function()
{
    this.Memory.push(14);
};
CDrawingStreamSerializer.prototype["PD_Fill"] = function()
{
    this.Memory.push(15);
};
CDrawingStreamSerializer.prototype["PD_Save"] = function()
{
    this.Memory.push(16);
};
CDrawingStreamSerializer.prototype["PD_Restore"] = function()
{
    this.Memory.push(17);
};
CDrawingStreamSerializer.prototype["PD_clip"] = function()
{
    this.Memory.push(18);
};
CDrawingStreamSerializer.prototype["PD_reset"] = function()
{
    this.Memory.push(19);
};
CDrawingStreamSerializer.prototype["PD_transform3"] = function(sx,shy,shx,sy,tx,ty,isNeedInvert)
{
    this.Memory.push(20);
    this.Memory.push(sx);
    this.Memory.push(shy);
    this.Memory.push(shx);
    this.Memory.push(sy);
    this.Memory.push(tx);
    this.Memory.push(ty);
    this.Memory.push(isNeedInvert);
};
CDrawingStreamSerializer.prototype["PD_FreeFont"] = function()
{
    // none
};
CDrawingStreamSerializer.prototype["PD_drawImage"] = function(img,x,y,w,h,alpha,srcRect_l,srcRect_t,srcRect_r,srcRect_b)
{
    if (srcRect_l === undefined)
    {
        this.Memory.push(22);
        this.Memory.push(img);
        this.Memory.push(x);
        this.Memory.push(y);
        this.Memory.push(w);
        this.Memory.push(h);
        this.Memory.push(alpha);
        return;
    }
    this.Memory.push(23);
    this.Memory.push(img);
    this.Memory.push(x);
    this.Memory.push(y);
    this.Memory.push(w);
    this.Memory.push(h);
    this.Memory.push(alpha);
    this.Memory.push(srcRect_l);
    this.Memory.push(srcRect_t);
    this.Memory.push(srcRect_r);
    this.Memory.push(srcRect_b);
};
CDrawingStreamSerializer.prototype["PD_font"] = function(font_id, font_size)
{
    // nothing
};
CDrawingStreamSerializer.prototype["PD_LoadFont"] = function(Path, FaceIndex, FontSize, flag)
{
    this.Memory.push(25);
    this.Memory.push(Path);
    this.Memory.push(FaceIndex);
    this.Memory.push(FontSize);
    this.Memory.push(flag);
};
CDrawingStreamSerializer.prototype["PD_FillText"] = function(x,y,text_code)
{
    this.Memory.push(26);
    this.Memory.push(x);
    this.Memory.push(y);
    this.Memory.push(text_code);
};
CDrawingStreamSerializer.prototype["PD_Text"] = function(x,y,_arr)
{
    // not used.
};
CDrawingStreamSerializer.prototype["PD_FillText2"] = function(x,y,text_code,cropX,cropW)
{
    this.Memory.push(28);
    this.Memory.push(x);
    this.Memory.push(y);
    this.Memory.push(text_code);
    this.Memory.push(cropX);
    this.Memory.push(cropW);
};
CDrawingStreamSerializer.prototype["PD_Text2"] = function(x,y,_arr,cropX,cropW)
{
    // not used.
};
CDrawingStreamSerializer.prototype["PD_FillTextG"] = function(x,y,text_code)
{
    this.Memory.push(31);
    this.Memory.push(x);
    this.Memory.push(y);
    this.Memory.push(text_code);
};
CDrawingStreamSerializer.prototype["PD_SetIntegerGrid"] = function(param)
{
    this.Memory.push(32);
    this.Memory.push(param);
};
CDrawingStreamSerializer.prototype["PD_DrawHeaderEdit"] = function(yPos, lock_type)
{
    this.Memory.push(33);
    this.Memory.push(yPos);
    this.Memory.push(lock_type);
};
CDrawingStreamSerializer.prototype["PD_DrawFooterEdit"] = function(yPos, lock_type)
{
    this.Memory.push(34);
    this.Memory.push(yPos);
    this.Memory.push(lock_type);
};
CDrawingStreamSerializer.prototype["PD_DrawLockParagraph"] = function(lock_type, x, y1, y2)
{
    this.Memory.push(35);
    this.Memory.push(lock_type);
    this.Memory.push(x);
    this.Memory.push(y1);
    this.Memory.push(y2);
};
CDrawingStreamSerializer.prototype["PD_DrawLockObjectRect"] = function(lock_type, x, y, w, h)
{
    this.Memory.push(36);
    this.Memory.push(lock_type);
    this.Memory.push(x);
    this.Memory.push(y);
    this.Memory.push(w);
    this.Memory.push(h);
};
CDrawingStreamSerializer.prototype["PD_DrawEmptyTableLine"] = function(x1,y1,x2,y2)
{
    this.Memory.push(37);
    this.Memory.push(x1);
    this.Memory.push(y1);
    this.Memory.push(x2);
    this.Memory.push(y2);
};
CDrawingStreamSerializer.prototype["PD_DrawSpellingLine"] = function(y0, x0, x1, w)
{
    this.Memory.push(38);
    this.Memory.push(y0);
    this.Memory.push(x0);
    this.Memory.push(x1);
    this.Memory.push(w);
};
CDrawingStreamSerializer.prototype["PD_drawHorLine"] = function(align, y, x, r, penW)
{
    this.Memory.push(39);
    this.Memory.push(align);
    this.Memory.push(y);
    this.Memory.push(x);
    this.Memory.push(r);
    this.Memory.push(penW);
};
CDrawingStreamSerializer.prototype["PD_drawHorLine2"] = function(align, y, x, r, penW)
{
    this.Memory.push(40);
    this.Memory.push(align);
    this.Memory.push(y);
    this.Memory.push(x);
    this.Memory.push(r);
    this.Memory.push(penW);
};
CDrawingStreamSerializer.prototype["PD_drawVerLine"] = function(align, x, y, b, penW)
{
    this.Memory.push(41);
    this.Memory.push(align);
    this.Memory.push(x);
    this.Memory.push(y);
    this.Memory.push(b);
    this.Memory.push(penW);
};
CDrawingStreamSerializer.prototype["PD_drawHorLineExt"] = function(align, y, x, r, penW, leftMW, rightMW)
{
    this.Memory.push(42);
    this.Memory.push(align);
    this.Memory.push(y);
    this.Memory.push(x);
    this.Memory.push(r);
    this.Memory.push(penW);
    this.Memory.push(leftMW);
    this.Memory.push(rightMW);
};
CDrawingStreamSerializer.prototype["PD_rect"] = function(x,y,w,h)
{
    this.Memory.push(43);
    this.Memory.push(x);
    this.Memory.push(y);
    this.Memory.push(w);
    this.Memory.push(h);
};
CDrawingStreamSerializer.prototype["PD_TableRect"] = function(x,y,w,h)
{
    this.Memory.push(44);
    this.Memory.push(x);
    this.Memory.push(y);
    this.Memory.push(w);
    this.Memory.push(h);
};
CDrawingStreamSerializer.prototype["PD_AddClipRect"] = function(x,y,w,h)
{
    this.Memory.push(45);
    this.Memory.push(x);
    this.Memory.push(y);
    this.Memory.push(w);
    this.Memory.push(h);
};
CDrawingStreamSerializer.prototype["PD_SetClip"] = function(x,y,w,h)
{
    this.Memory.push(46);
    this.Memory.push(x);
    this.Memory.push(y);
    this.Memory.push(w);
    this.Memory.push(h);
};
CDrawingStreamSerializer.prototype["PD_RemoveClip"] = function()
{
    this.Memory.push(47);
};
CDrawingStreamSerializer.prototype["PD_drawCollaborativeChanges"] = function(x, y, w, h)
{
    this.Memory.push(48);
    this.Memory.push(x);
    this.Memory.push(y);
    this.Memory.push(w);
    this.Memory.push(h);
};
CDrawingStreamSerializer.prototype["PD_drawSearchResult"] = function(x, y, w, h)
{
    this.Memory.push(49);
    this.Memory.push(x);
    this.Memory.push(y);
    this.Memory.push(w);
    this.Memory.push(h);
};
CDrawingStreamSerializer.prototype["PD_drawFlowAnchor"] = function(x, y)
{
    this.Memory.push(50);
    this.Memory.push(x);
    this.Memory.push(y);
};
CDrawingStreamSerializer.prototype["PD_SavePen"] = function()
{
    this.Memory.push(51);
};
CDrawingStreamSerializer.prototype["PD_RestorePen"] = function()
{
    this.Memory.push(52);
};
CDrawingStreamSerializer.prototype["PD_SaveBrush"] = function()
{
    this.Memory.push(53);
};
CDrawingStreamSerializer.prototype["PD_RestoreBrush"] = function()
{
    this.Memory.push(54);
};
CDrawingStreamSerializer.prototype["PD_SavePenBrush"] = function()
{
    this.Memory.push(55);
};
CDrawingStreamSerializer.prototype["PD_RestorePenBrush"] = function()
{
    this.Memory.push(56);
};
CDrawingStreamSerializer.prototype["PD_SaveGrState"] = function()
{
    this.Memory.push(57);
};
CDrawingStreamSerializer.prototype["PD_RestoreGrState"] = function()
{
    this.Memory.push(58);
};
CDrawingStreamSerializer.prototype["PD_StartClipPath"] = function()
{
    this.Memory.push(59);
};
CDrawingStreamSerializer.prototype["PD_EndClipPath"] = function()
{
    this.Memory.push(65);
};
CDrawingStreamSerializer.prototype["PD_StartCheckTableDraw"] = function()
{
    this.Memory.push(60);
};
CDrawingStreamSerializer.prototype["PD_EndCheckTableDraw"] = function(bIsRestore)
{
    this.Memory.push(61);
};
CDrawingStreamSerializer.prototype["PD_SetTextClipRect"] = function(_l, _t, _r, _b)
{
    this.Memory.push(62);
    this.Memory.push(_l);
    this.Memory.push(_t);
    this.Memory.push(_r);
    this.Memory.push(_b);
};
CDrawingStreamSerializer.prototype["PD_AddSmartRect"] = function(x, y, w, h, pen_w)
{
    this.Memory.push(63);
    this.Memory.push(x);
    this.Memory.push(y);
    this.Memory.push(w);
    this.Memory.push(h);
    this.Memory.push(pen_w);
};
CDrawingStreamSerializer.prototype["PD_DrawPresentationComment"] = function(type, x, y, w, h)
{
    this.Memory.push(64);
    this.Memory.push(type);
    this.Memory.push(x);
    this.Memory.push(y);
    this.Memory.push(w);
    this.Memory.push(h);
};
CDrawingStreamSerializer.prototype["PD_StartShapeDraw"] = function(IsRectShape)
{
    this.Memory.push(70);
    this.Memory.push(IsRectShape);
};
CDrawingStreamSerializer.prototype["PD_EndShapeDraw"] = function()
{
    this.Memory.push(71);
};
CDrawingStreamSerializer.prototype["PD_put_BrushTextute"] = function(id, l, t, r, b)
{
    if (l === undefined)
    {
        this.Memory.push(72);
        this.Memory.push(id);
        return;
    }
    this.Memory.push(73);
    this.Memory.push(id);
    this.Memory.push(l);
    this.Memory.push(t);
    this.Memory.push(r);
    this.Memory.push(b);
};
CDrawingStreamSerializer.prototype["PD_put_BrushTextureMode"] = function(mode)
{
    this.Memory.push(74);
    this.Memory.push(mode);
};
CDrawingStreamSerializer.prototype["PD_put_BrushBounds"] = function(x, y, w, h)
{
    this.Memory.push(75);
    this.Memory.push(x);
    this.Memory.push(y);
    this.Memory.push(w);
    this.Memory.push(h);
};
CDrawingStreamSerializer.prototype["PD_put_BrushGradientLinear"] = function(x0, y0, x1, y1)
{
    this.Memory.push(76);
    this.Memory.push(x0);
    this.Memory.push(y0);
    this.Memory.push(x1);
    this.Memory.push(y1);
};
CDrawingStreamSerializer.prototype["PD_put_BrushGragientColors"] = function(arr_pos, arr_colors)
{
    this.Memory.push(77);
    this.Memory.push(arr_colors.length);

    for (var i = 0; i < arr_colors.length; i++)
    {
        this.Memory.push(arr_pos[i].pos / 100000);

        var _rgba = arr_colors[i].color.RGBA;
        this.Memory.push(_rgba.R * 256*256*256 + _rgba.G * 256*256 + _rgba.B * 256 + _rgba.A);
    }
};
CDrawingStreamSerializer.prototype["PD_put_BrushPattern"] = function(_patt_name)
{
    this.Memory.push(78);
    this.Memory.push(_patt_name);
};
CDrawingStreamSerializer.prototype["PD_lineJoin"] = function(_join)
{
    this.Memory.push(79);
    this.Memory.push(_join);
};
CDrawingStreamSerializer.prototype["PD_put_BrushGradientRadial"] = function(x1, y1, r1, x2, y2, r2)
{
    this.Memory.push(80);
    this.Memory.push(x1);
    this.Memory.push(y1);
    this.Memory.push(r1);
    this.Memory.push(x2);
    this.Memory.push(y2);
    this.Memory.push(r2);
};

function CDrawingStream(_writer)
{
    this.Native = (undefined === _writer) ? window["native"] : _writer;

    this.m_oTextPr      = null;
    this.m_oGrFonts     = new CGrRFonts();
    this.m_oLastFont    = new CFontSetup();

    this.LastFontOriginInfo = { Name : "", Replace : null };

    this.IsUseFonts2    = false;
    this.m_oLastFont2   = null;

    this.m_bIntegerGrid = true;

    this.m_oPen     = new CPen();
    this.m_oBrush   = new CBrush();
}

CDrawingStream.prototype =
{
    ClearParams : function()
    {
        this.m_oTextPr      = null;
        this.m_oGrFonts     = new CGrRFonts();
        this.m_oLastFont    = new CFontSetup();

        this.IsUseFonts2    = false;
        this.m_oLastFont2   = null;

        this.m_bIntegerGrid = true;
    },

    EndDraw : function()
    {
        // not used
    },

    put_GlobalAlpha : function(enable, alpha)
    {
        this.Native["PD_put_GlobalAlpha"](enable, alpha);
    },
    Start_GlobalAlpha : function()
    {
        // nothing
    },
    End_GlobalAlpha : function()
    {
        this.Native["PD_End_GlobalAlpha"]();
    },
    // pen methods
    p_color : function(r,g,b,a)
    {
        var _c = this.m_oPen.Color;
        _c.R = r;
        _c.G = g;
        _c.B = b;
        _c.A = a;
        this.Native["PD_p_color"](r,g,b,a);
    },
    p_width : function(w)
    {
        this.Native["PD_p_width"](w / 1000);
    },
    // brush methods
    b_color1 : function(r,g,b,a)
    {
        var _c = this.m_oBrush.Color1;
        _c.R = r;
        _c.G = g;
        _c.B = b;
        _c.A = a;
        this.Native["PD_b_color1"](r,g,b,a);
    },
    b_color2 : function(r,g,b,a)
    {
        this.Native["PD_b_color2"](r,g,b,a);
    },

    transform : function(sx,shy,shx,sy,tx,ty)
    {
        this.Native["PD_transform"](sx,shy,shx,sy,tx,ty);
    },
    // path commands
    _s : function()
    {
        this.Native["PD_PathStart"]();
    },
    _e : function()
    {
        this.Native["PD_PathEnd"]();
    },
    _z : function()
    {
        this.Native["PD_PathClose"]();
    },
    _m : function(x,y)
    {
        this.Native["PD_PathMoveTo"](x,y);
    },
    _l : function(x,y)
    {
        this.Native["PD_PathLineTo"](x,y);
    },
    _c : function(x1,y1,x2,y2,x3,y3)
    {
        this.Native["PD_PathCurveTo"](x1,y1,x2,y2,x3,y3);
    },
    _c2 : function(x1,y1,x2,y2)
    {
        this.Native["PD_PathCurveTo2"](x1,y1,x2,y2);
    },
    ds : function()
    {
        this.Native["PD_Stroke"]();
    },
    df : function()
    {
        this.Native["PD_Fill"]();
    },

    // canvas state
    save : function()
    {
        this.Native["PD_Save"]();
    },
    restore : function()
    {
        this.Native["PD_Restore"]();
    },
    clip : function()
    {
        this.Native["PD_clip"]();
    },

    reset : function()
    {
        this.Native["PD_reset"]();
    },

    transform3 : function(m, isNeedInvert)
    {
        this.Native["PD_transform3"](m.sx,m.shy,m.shx,m.sy,m.tx,m.ty,isNeedInvert);
    },

    FreeFont : function()
    {
        this.Native["PD_FreeFont"]();
    },

    // images
    drawImage : function(img,x,y,w,h,alpha,srcRect)
    {
        if (!srcRect)
            return this.Native["PD_drawImage"](img,x,y,w,h,alpha);

        return this.Native["PD_drawImage"](img,x,y,w,h,alpha,srcRect.l,srcRect.t,srcRect.r,srcRect.b);
    },

    // text
    GetFont : function()
    {
        return this.m_oCurFont;
    },
    font : function(font_id,font_size)
    {
        this.Native["PD_font"](font_id, font_size);
    },
    SetFont : function(font)
    {
        if (null == font)
            return;

        this.m_oCurFont =
        {
            FontFamily :
            {
                Index : font.FontFamily.Index,
                Name  : font.FontFamily.Name
            },

            FontSize : font.FontSize,
            Bold     : font.Bold,
            Italic   : font.Italic
        };

        var bItalic = true === font.Italic;
        var bBold   = true === font.Bold;

        var oFontStyle = FontStyle.FontStyleRegular;
        if ( !bItalic && bBold )
            oFontStyle = FontStyle.FontStyleBold;
        else if ( bItalic && !bBold )
            oFontStyle = FontStyle.FontStyleItalic;
        else if ( bItalic && bBold )
            oFontStyle = FontStyle.FontStyleBoldItalic;

        var _fontinfo = g_fontApplication.GetFontInfo(font.FontFamily.Name, oFontStyle, this.LastFontOriginInfo);
        var _info = GetLoadInfoForMeasurer(_fontinfo, oFontStyle);

        var flag = 0;
        if (_info.NeedBold)     flag |= 0x01;
        if (_info.NeedItalic)   flag |= 0x02;
        if (_info.SrcBold)      flag |= 0x04;
        if (_info.SrcItalic)    flag |= 0x08;

        this.Native["PD_LoadFont"](_info.Path, _info.FaceIndex, font.FontSize, flag);
    },

    SetTextPr : function(textPr, theme)
    {
        this.m_oTextPr = textPr;
        if (theme)
            this.m_oGrFonts.checkFromTheme(theme.themeElements.fontScheme, this.m_oTextPr.RFonts);
        else
            this.m_oGrFonts = this.m_oTextPr.RFonts;
    },
    GetTextPr : function()
    {
        return this.m_oTextPr;
    },

    SetFontSlot : function(slot, fontSizeKoef)
    {
        var _rfonts = this.m_oGrFonts;
        var _lastFont = this.IsUseFonts2 ? this.m_oLastFont2 : this.m_oLastFont;

        switch (slot)
        {
            case fontslot_ASCII:
            {
                _lastFont.Name   = _rfonts.Ascii.Name;
                _lastFont.Size = this.m_oTextPr.FontSize;
                _lastFont.Bold = this.m_oTextPr.Bold;
                _lastFont.Italic = this.m_oTextPr.Italic;

                break;
            }
            case fontslot_CS:
            {
                _lastFont.Name   = _rfonts.CS.Name;
                _lastFont.Size = this.m_oTextPr.FontSizeCS;
                _lastFont.Bold = this.m_oTextPr.BoldCS;
                _lastFont.Italic = this.m_oTextPr.ItalicCS;

                break;
            }
            case fontslot_EastAsia:
            {
                _lastFont.Name   = _rfonts.EastAsia.Name;
                _lastFont.Size = this.m_oTextPr.FontSize;
                _lastFont.Bold = this.m_oTextPr.Bold;
                _lastFont.Italic = this.m_oTextPr.Italic;

                break;
            }
            case fontslot_HAnsi:
            default:
            {
                _lastFont.Name   = _rfonts.HAnsi.Name;
                _lastFont.Size = this.m_oTextPr.FontSize;
                _lastFont.Bold = this.m_oTextPr.Bold;
                _lastFont.Italic = this.m_oTextPr.Italic;

                break;
            }
        }

        if (undefined !== fontSizeKoef)
            _lastFont.Size *= fontSizeKoef;

        var _style = 0;
        if (_lastFont.Italic)
            _style += 2;
        if (_lastFont.Bold)
            _style += 1;

        if (_lastFont.Name != _lastFont.SetUpName || _lastFont.Size != _lastFont.SetUpSize || _style != _lastFont.SetUpStyle)
        {
            _lastFont.SetUpName = _lastFont.Name;
            _lastFont.SetUpSize = _lastFont.Size;
            _lastFont.SetUpStyle = _style;

            var _fontinfo = g_fontApplication.GetFontInfo(_lastFont.SetUpName, _lastFont.SetUpStyle, this.LastFontOriginInfo);
            var _info = GetLoadInfoForMeasurer(_fontinfo, _lastFont.SetUpStyle);

            var flag = 0;
            if (_info.NeedBold)     flag |= 0x01;
            if (_info.NeedItalic)   flag |= 0x02;
            if (_info.SrcBold)      flag |= 0x04;
            if (_info.SrcItalic)    flag |= 0x08;

            this.Native["PD_LoadFont"](_info.Path, _info.FaceIndex, _lastFont.SetUpSize, flag);
        }
    },

    FillText : function(x,y,text)
    {
        var _code = text.charCodeAt(0);
        if (null != this.LastFontOriginInfo.Replace)
            _code = g_fontApplication.GetReplaceGlyph(_code, this.LastFontOriginInfo.Replace);

        this.Native["PD_FillText"](x,y,_code);
    },
    t : function(text,x,y)
    {
        var _arr = [];
        var _len = text.length;
        for (var i = 0; i < _len; i++)
            _arr.push(text.charCodeAt(i));
        this.Native["PD_Text"](x,y,_arr);
    },
    FillText2 : function(x,y,text,cropX,cropW)
    {
        var _code = text.charCodeAt(0);
        if (null != this.LastFontOriginInfo.Replace)
            _code = g_fontApplication.GetReplaceGlyph(_code, this.LastFontOriginInfo.Replace);

        this.Native["PD_FillText2"](x,y,_code,cropX,cropW);
    },
    t2 : function(text,x,y,cropX,cropW)
    {
        var _arr = [];
        var _len = text.length;
        for (var i = 0; i < _len; i++)
            _arr.push(text.charCodeAt(i));
        this.Native["PD_Text2"](x,y,_arr,cropX,cropW);
    },
    FillTextCode : function(x,y,lUnicode)
    {
        if (null != this.LastFontOriginInfo.Replace)
            lUnicode = g_fontApplication.GetReplaceGlyph(lUnicode, this.LastFontOriginInfo.Replace);

        this.Native["PD_FillText"](x,y,lUnicode);
    },

    tg : function(text,x,y)
    {
        this.Native["PD_FillTextG"](x,y,text);
    },
    charspace : function(space)
    {
        // nothing
    },

    SetIntegerGrid : function(param)
    {
        this.m_bIntegerGrid = param;
        this.Native["PD_SetIntegerGrid"](param);
    },
    GetIntegerGrid : function()
    {
        return this.m_bIntegerGrid;
    },

    DrawHeaderEdit : function(yPos, lock_type)
    {
        this.Native["PD_DrawHeaderEdit"](yPos, lock_type);
    },

    DrawFooterEdit : function(yPos, lock_type)
    {
        this.Native["PD_DrawFooterEdit"](yPos, lock_type);
    },

    DrawLockParagraph : function(lock_type, x, y1, y2)
    {
        this.Native["PD_DrawLockParagraph"](lock_type, x, y1, y2);
    },

    DrawLockObjectRect : function(lock_type, x, y, w, h)
    {
        this.Native["PD_DrawLockObjectRect"](lock_type, x, y, w, h);
    },

    DrawEmptyTableLine : function(x1,y1,x2,y2)
    {
        this.Native["PD_DrawEmptyTableLine"](x1,y1,x2,y2);
    },

    DrawSpellingLine : function(y0, x0, x1, w)
    {
        this.Native["PD_DrawSpellingLine"](y0, x0, x1, w);
    },

    // smart methods for horizontal / vertical lines
    drawHorLine : function(align, y, x, r, penW)
    {
        this.Native["PD_drawHorLine"](align, y, x, r, penW);
    },
    drawHorLine2 : function(align, y, x, r, penW)
    {
        this.Native["PD_drawHorLine2"](align, y, x, r, penW);
    },
    drawVerLine : function(align, x, y, b, penW)
    {
        this.Native["PD_drawVerLine"](align, x, y, b, penW);
    },

    // мега крутые функции для таблиц
    drawHorLineExt : function(align, y, x, r, penW, leftMW, rightMW)
    {
        this.Native["PD_drawHorLineExt"](align, y, x, r, penW, leftMW, rightMW);
    },

    rect : function(x,y,w,h)
    {
        this.Native["PD_rect"](x,y,w,h);
    },

    TableRect : function(x,y,w,h)
    {
        this.Native["PD_TableRect"](x,y,w,h);
    },

    // функции клиппирования
    AddClipRect : function(x, y, w, h)
    {
        this.Native["PD_AddClipRect"](x,y,w,h);
    },
    RemoveClipRect : function()
    {
        // nothing
    },

    SetClip : function(r)
    {
        this.Native["PD_SetClip"](r.x, r.y, r.w, r.h);
    },

    RemoveClip : function()
    {
        this.Native["PD_RemoveClip"]();
    },

    drawCollaborativeChanges : function(x, y, w, h)
    {
        this.Native["PD_drawCollaborativeChanges"](x, y, w, h);
    },

    drawSearchResult : function(x, y, w, h)
    {
        this.Native["PD_drawSearchResult"](x, y, w, h);
    },

    drawFlowAnchor : function(x, y)
    {
        this.Native["PD_drawFlowAnchor"](x, y);
    },

    SavePen : function()
    {
        this.Native["PD_SavePen"]();
    },
    RestorePen : function()
    {
        this.Native["PD_RestorePen"]();
    },

    SaveBrush : function()
    {
        this.Native["PD_SaveBrush"]();
    },
    RestoreBrush : function()
    {
        this.Native["PD_RestoreBrush"]();
    },

    SavePenBrush : function()
    {
        this.Native["PD_SavePenBrush"]();
    },
    RestorePenBrush : function()
    {
        this.Native["PD_RestorePenBrush"]();
    },

    SaveGrState : function()
    {
        this.Native["PD_SaveGrState"]();
    },
    RestoreGrState : function()
    {
        this.Native["PD_RestoreGrState"]();
    },

    StartClipPath : function()
    {
        this.Native["PD_StartClipPath"]();
    },

    EndClipPath : function()
    {
        this.Native["PD_EndClipPath"]();
    },

    StartCheckTableDraw : function()
    {
        return this.Native["PD_StartCheckTableDraw"]();
    },

    EndCheckTableDraw : function(bIsRestore)
    {
        return this.Native["PD_EndCheckTableDraw"](bIsRestore);
    },

    SetTextClipRect : function(_l, _t, _r, _b)
    {
        return this.Native["PD_SetTextClipRect"](_l, _t, _r, _b);
    },

    AddSmartRect : function(x, y, w, h, pen_w)
    {
        return this.Native["PD_AddSmartRect"](x, y, w, h, pen_w);
    },

    Drawing_StartCheckBounds : function(x, y, w, h)
    {

    },

    Drawing_EndCheckBounds : function()
    {

    },

    DrawPresentationComment : function(type, x, y, w, h)
    {
        return this.Native["PD_DrawPresentationComment"](type, x, y, w, h);
    }
};