Commit 888d7ed2 authored by Oleg.Korshul's avatar Oleg.Korshul

поддержка прозрачности открытие/сохранение в градиентах и паттернах

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@50244 954022d7-b5bf-4e40-9824-e11837661b57
parent b85b0bae
......@@ -1910,6 +1910,35 @@ function CBinaryFileWriter()
oThis.EndRecord();
}
this.CorrectUniColorAlpha = function(color, trans)
{
// делаем прозрачность
var mods = color.Mods.Mods;
var _len = mods.length;
if (trans != null)
{
var nIndex = -1;
for (var i = 0; i < _len; i++)
{
if (mods[i].name == "alpha")
{
nIndex = i;
break;
}
}
if (-1 != nIndex)
{
--_len;
mods.splice(nIndex, 1);
}
mods[_len] = new CColorMod();
mods[_len].name = "alpha";
mods[_len].val = (trans * 100000 / 255) >> 0;
}
}
this.WriteUniFill = function(unifill)
{
if (undefined === unifill || null == unifill)
......@@ -1948,6 +1977,9 @@ function CBinaryFileWriter()
oThis._WriteInt1(0, fill.colors[i].pos);
oThis.WriteUChar(g_nodeAttributeEnd);
// делаем прозрачность
oThis.CorrectUniColorAlpha(fill.colors[i].color, trans);
oThis.WriteRecord1(0, fill.colors[i].color, oThis.WriteUniColor);
oThis.EndRecord();
......@@ -1983,6 +2015,9 @@ function CBinaryFileWriter()
oThis._WriteLimit2(0, fill.ftype);
oThis.WriteUChar(g_nodeAttributeEnd);
oThis.CorrectUniColorAlpha(fill.fgClr, trans);
oThis.CorrectUniColorAlpha(fill.bgClr, trans);
oThis.WriteRecord1(0, fill.fgClr, oThis.WriteUniColor);
oThis.WriteRecord1(1, fill.bgClr, oThis.WriteUniColor);
......@@ -2087,34 +2122,7 @@ function CBinaryFileWriter()
{
oThis.StartRecord(FILL_TYPE_SOLID);
var mods = fill.color.Mods.Mods;
var _len = mods.length;
if (trans != null)
{
var nIndex = -1;
for (var i = 0; i < _len; i++)
{
if (mods[i].name == "alpha")
{
nIndex = i;
break;
}
}
if (-1 != nIndex)
{
--_len;
mods.splice(nIndex, 1);
}
}
if (null != trans)
{
mods[_len] = new CColorMod();
mods[_len].name = "alpha";
mods[_len].val = (trans * 100000 / 255) >> 0;
}
oThis.CorrectUniColorAlpha(fill.color, trans);
oThis.WriteRecord1(0, fill.color, oThis.WriteUniColor);
oThis.EndRecord();
break;
......
......@@ -1089,8 +1089,13 @@ function CUniColor()
CUniColor.prototype =
{
getCSSColor : function()
getCSSColor : function(transparent)
{
if (transparent != null)
{
var _css = "rgba(" + this.RGBA.R + "," + this.RGBA.G + "," + this.RGBA.B + ",1)";
return _css;
}
var _css = "rgba(" + this.RGBA.R + "," + this.RGBA.G + "," + this.RGBA.B + "," + (this.RGBA.A / 255) + ")";
return _css;
},
......
......@@ -937,7 +937,10 @@ CShapeDrawer.prototype =
var _fc = _fill.fgClr.RGBA;
var _bc = _fill.bgClr.RGBA;
var _test_pattern = GetHatchBrush(_patt_name, _fc.R, _fc.G, _fc.B, _bc.R, _bc.G, _bc.B);
var __fa = (null === this.UniFill.transparent) ? _fc.A : 255;
var __ba = (null === this.UniFill.transparent) ? _bc.A : 255;
var _test_pattern = GetHatchBrush(_patt_name, _fc.R, _fc.G, _fc.B, __fa, _bc.R, _bc.G, _bc.B, __ba);
var patt = _ctx.createPattern(_test_pattern.Canvas, "repeat");
_ctx.save();
......@@ -961,7 +964,10 @@ CShapeDrawer.prototype =
if (_is_ctx === true)
{
var _old_global_alpha = _ctx.globalAlpha;
if (null != this.UniFill.transparent)
_ctx.globalAlpha = this.UniFill.transparent / 255;
_ctx.fillStyle = patt;
_ctx.fill();
_ctx.globalAlpha = _old_global_alpha;
......@@ -1011,7 +1017,7 @@ CShapeDrawer.prototype =
for (var i = 0; i < _fill.colors.length; i++)
{
gradObj.addColorStop(_fill.colors[i].pos / 100000, _fill.colors[i].color.getCSSColor());
gradObj.addColorStop(_fill.colors[i].pos / 100000, _fill.colors[i].color.getCSSColor(this.UniFill.transparent));
}
_ctx.fillStyle = gradObj;
......@@ -1290,7 +1296,10 @@ CShapeDrawer.prototype =
var _fc = _fill.fgClr.RGBA;
var _bc = _fill.bgClr.RGBA;
var _pattern = GetHatchBrush(_patt_name, _fc.R, _fc.G, _fc.B, _bc.R, _bc.G, _bc.B);
var __fa = (null === this.UniFill.transparent) ? _fc.A : 255;
var __ba = (null === this.UniFill.transparent) ? _bc.A : 255;
var _pattern = GetHatchBrush(_patt_name, _fc.R, _fc.G, _fc.B, __fa, _bc.R, _bc.G, _bc.B, __ba);
var _url64 = "";
try
......@@ -1303,7 +1312,11 @@ CShapeDrawer.prototype =
}
this.Graphics.put_brushTexture(_url64, 1);
if (null != this.UniFill.transparent)
this.Graphics.put_BrushTextureAlpha(this.UniFill.transparent);
else
this.Graphics.put_BrushTextureAlpha(255);
bIsPattern = true;
}
......@@ -1327,7 +1340,7 @@ CShapeDrawer.prototype =
points = this.getGradientPoints(this.min_x, this.min_y, this.max_x, this.max_y, 90 * 60000, false);
}
this.Graphics.put_BrushGradient(_fill, points);
this.Graphics.put_BrushGradient(_fill, points, this.UniFill.transparent);
}
else
{
......@@ -1669,6 +1682,10 @@ CShapeDrawer.prototype =
}
// никогда сюда не зайдем
return points;
},
DrawPresentationComment : function(type, x, y, w, h)
{
}
};
......
......@@ -976,8 +976,13 @@ CUniColor.prototype =
return _ret;
},
getCSSColor : function()
getCSSColor : function(transparent)
{
if (transparent != null)
{
var _css = "rgba(" + this.RGBA.R + "," + this.RGBA.G + "," + this.RGBA.B + ",1)";
return _css;
}
var _css = "rgba(" + this.RGBA.R + "," + this.RGBA.G + "," + this.RGBA.B + "," + (this.RGBA.A / 255) + ")";
return _css;
}
......
......@@ -665,8 +665,8 @@ function CHatchBrush()
this.Ctx = null;
this.Data = null;
this.fgClr = { R : -1, G : -1, B : -1 };
this.bgClr = { R : -1, G : -1, B : -1 };
this.fgClr = { R : -1, G : -1, B : -1, A : 255 };
this.bgClr = { R : -1, G : -1, B : -1, A : 255 };
}
CHatchBrush.prototype =
{
......@@ -685,21 +685,24 @@ CHatchBrush.prototype =
this.Data = this.Ctx.createImageData(HATCH_TX_SIZE, HATCH_TX_SIZE);
},
CheckColors : function(r,g,b,br,bg,bb)
CheckColors : function(r,g,b,a,br,bg,bb,ba)
{
if (null == this.Canvas)
return;
if (this.fgClr.R == r && this.fgClr.G == g && this.fgClr.B == b && this.bgClr.R == br && this.bgClr.G == bg && this.bgClr.B == bb)
if (this.fgClr.R == r && this.fgClr.G == g && this.fgClr.B == b && this.fgClr.A == a &&
this.bgClr.R == br && this.bgClr.G == bg && this.bgClr.B == bb && this.bgClr.A == ba)
return;
this.fgClr.R = r;
this.fgClr.G = g;
this.fgClr.B = b;
this.fgClr.A = a;
this.bgClr.R = br;
this.bgClr.G = bg;
this.bgClr.B = bb;
this.bgClr.A = ba;
var _len = HATCH_TX_SIZE * HATCH_TX_SIZE;
var _src_data_offset = global_hatch_offsets[this.Name] * _len;
......@@ -714,14 +717,14 @@ CHatchBrush.prototype =
_dst_data[_ind++] = r;
_dst_data[_ind++] = g;
_dst_data[_ind++] = b;
_dst_data[_ind++] = 255;
_dst_data[_ind++] = a;
}
else
{
_dst_data[_ind++] = br;
_dst_data[_ind++] = bg;
_dst_data[_ind++] = bb;
_dst_data[_ind++] = 255;
_dst_data[_ind++] = ba;
}
}
......@@ -729,18 +732,18 @@ CHatchBrush.prototype =
}
};
function GetHatchBrush(name, r, g, b, br, bg, bb)
function GetHatchBrush(name, r, g, b, a, br, bg, bb, ba)
{
var _brush = global_hatch_brushes[name];
if (_brush !== undefined)
{
_brush.CheckColors(r, g, b, br, bg, bb);
_brush.CheckColors(r, g, b, a, br, bg, bb, ba);
return _brush;
}
_brush = new CHatchBrush();
_brush.Create(name);
_brush.CheckColors(r, g, b, br, bg, bb);
_brush.CheckColors(r, g, b, a, br, bg, bb, ba);
global_hatch_brushes[name] = _brush;
return _brush;
}
......@@ -901,7 +901,7 @@ CMetafile.prototype =
this.Memory.WriteByte(write);
},
put_BrushGradient : function(gradFill, points)
put_BrushGradient : function(gradFill, points, transparent)
{
this.BrushType = MetaBrushType.Gradient;
......@@ -952,7 +952,11 @@ CMetafile.prototype =
this.Memory.WriteByte(_colors[i].color.RGBA.R);
this.Memory.WriteByte(_colors[i].color.RGBA.G);
this.Memory.WriteByte(_colors[i].color.RGBA.B);
if (null == transparent)
this.Memory.WriteByte(_colors[i].color.RGBA.A);
else
this.Memory.WriteByte(transparent);
}
this.Memory.WriteByte(g_nodeAttributeEnd);
......@@ -1871,10 +1875,10 @@ CDocumentRenderer.prototype =
if (0 != this.m_lPagesCount)
this.m_arrayPages[this.m_lPagesCount - 1].put_BrushTextureAlpha(alpha);
},
put_BrushGradient : function(gradFill, points)
put_BrushGradient : function(gradFill, points, transparent)
{
if (0 != this.m_lPagesCount)
this.m_arrayPages[this.m_lPagesCount - 1].put_BrushGradient(gradFill, points);
this.m_arrayPages[this.m_lPagesCount - 1].put_BrushGradient(gradFill, points, transparent);
},
// функции клиппирования
......
......@@ -897,7 +897,10 @@ CShapeDrawer.prototype =
var _fc = _fill.fgClr.RGBA;
var _bc = _fill.bgClr.RGBA;
var _test_pattern = GetHatchBrush(_patt_name, _fc.R, _fc.G, _fc.B, _bc.R, _bc.G, _bc.B);
var __fa = (null === this.UniFill.transparent) ? _fc.A : 255;
var __ba = (null === this.UniFill.transparent) ? _bc.A : 255;
var _test_pattern = GetHatchBrush(_patt_name, _fc.R, _fc.G, _fc.B, __fa, _bc.R, _bc.G, _bc.B, __ba);
var patt = _ctx.createPattern(_test_pattern.Canvas, "repeat");
_ctx.save();
......@@ -920,7 +923,10 @@ CShapeDrawer.prototype =
if (_is_ctx === true)
{
var _old_global_alpha = _ctx.globalAlpha;
if (null != this.UniFill.transparent)
_ctx.globalAlpha = this.UniFill.transparent / 255;
_ctx.fillStyle = patt;
_ctx.fill();
_ctx.globalAlpha = _old_global_alpha;
......@@ -970,7 +976,7 @@ CShapeDrawer.prototype =
for (var i = 0; i < _fill.colors.length; i++)
{
gradObj.addColorStop(_fill.colors[i].pos / 100000, _fill.colors[i].color.getCSSColor());
gradObj.addColorStop(_fill.colors[i].pos / 100000, _fill.colors[i].color.getCSSColor(this.UniFill.transparent));
}
_ctx.fillStyle = gradObj;
......@@ -1249,7 +1255,10 @@ CShapeDrawer.prototype =
var _fc = _fill.fgClr.RGBA;
var _bc = _fill.bgClr.RGBA;
var _pattern = GetHatchBrush(_patt_name, _fc.R, _fc.G, _fc.B, _bc.R, _bc.G, _bc.B);
var __fa = (null === this.UniFill.transparent) ? _fc.A : 255;
var __ba = (null === this.UniFill.transparent) ? _bc.A : 255;
var _pattern = GetHatchBrush(_patt_name, _fc.R, _fc.G, _fc.B, __fa, _bc.R, _bc.G, _bc.B, __ba);
var _url64 = "";
try
......@@ -1262,7 +1271,11 @@ CShapeDrawer.prototype =
}
this.Graphics.put_brushTexture(_url64, 1);
if (null != this.UniFill.transparent)
this.Graphics.put_BrushTextureAlpha(this.UniFill.transparent);
else
this.Graphics.put_BrushTextureAlpha(255);
bIsPattern = true;
}
......@@ -1286,7 +1299,7 @@ CShapeDrawer.prototype =
points = this.getGradientPoints(this.min_x, this.min_y, this.max_x, this.max_y, 90 * 60000, false);
}
this.Graphics.put_BrushGradient(_fill, points);
this.Graphics.put_BrushGradient(_fill, points, this.UniFill.transparent);
}
else
{
......
......@@ -835,8 +835,13 @@ function CUniColor()
CUniColor.prototype =
{
getCSSColor : function()
getCSSColor : function(transparent)
{
if (transparent != null)
{
var _css = "rgba(" + this.RGBA.R + "," + this.RGBA.G + "," + this.RGBA.B + ",1)";
return _css;
}
var _css = "rgba(" + this.RGBA.R + "," + this.RGBA.G + "," + this.RGBA.B + "," + (this.RGBA.A / 255) + ")";
return _css;
},
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment