Commit 6db470fe authored by Alexander.Trofimov's avatar Alexander.Trofimov Committed by Alexander.Trofimov

FT_Stream2 через прототипы

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@53666 954022d7-b5bf-4e40-9824-e11837661b57
parent e5ebcc45
...@@ -202,7 +202,7 @@ function BinaryCommonWriter(memory) ...@@ -202,7 +202,7 @@ function BinaryCommonWriter(memory)
this.memory.WriteLong(color.getRgb()); this.memory.WriteLong(color.getRgb());
} }
}; };
}; }
function Binary_CommonReader(stream) function Binary_CommonReader(stream)
{ {
this.stream = stream; this.stream = stream;
...@@ -366,190 +366,158 @@ function Binary_CommonReader(stream) ...@@ -366,190 +366,158 @@ function Binary_CommonReader(stream)
} }
} }
/** @constructor */ /** @constructor */
function FT_Stream2(data, size) function FT_Stream2(data, size) {
{
this.obj = null; this.obj = null;
this.data = data; this.data = data;
this.size = size; this.size = size;
this.pos = 0; this.pos = 0;
this.cur = 0; this.cur = 0;
}
this.Seek = function(_pos) FT_Stream2.prototype.Seek = function(_pos) {
{ if (_pos > this.size)
if (_pos > this.size) return c_oSerConstants.ErrorStream;
return c_oSerConstants.ErrorStream; this.pos = _pos;
this.pos = _pos; return c_oSerConstants.ReadOk;
return c_oSerConstants.ReadOk; };
} FT_Stream2.prototype.Seek2 = function(_cur) {
this.Seek2 = function(_cur) if (_cur > this.size)
{ return c_oSerConstants.ErrorStream;
if (_cur > this.size) this.cur = _cur;
return c_oSerConstants.ErrorStream; return c_oSerConstants.ReadOk;
this.cur = _cur; };
return c_oSerConstants.ReadOk; FT_Stream2.prototype.Skip = function(_skip) {
} if (_skip < 0)
this.Skip = function(_skip) return c_oSerConstants.ErrorStream;
{ return this.Seek(this.pos + _skip);
if (_skip < 0) };
return c_oSerConstants.ErrorStream; FT_Stream2.prototype.Skip2 = function(_skip) {
return this.Seek(this.pos + _skip); if (_skip < 0)
} return c_oSerConstants.ErrorStream;
this.Skip2 = function(_skip) return this.Seek2(this.cur + _skip);
{ };
if (_skip < 0)
return c_oSerConstants.ErrorStream;
return this.Seek2(this.cur + _skip);
}
// 1 bytes
this.GetUChar = function()
{
if (this.cur >= this.size)
return 0;
return this.data[this.cur++];
}
this.GetByte = function()
{
return this.GetUChar();
}
this.GetBool = function()
{
var Value = this.GetUChar();
return ( Value == 0 ? false : true );
}
// 2 byte
this.GetUShortLE = function()
{
if (this.cur + 1 >= this.size)
return 0;
return (this.data[this.cur++] | this.data[this.cur++] << 8);
}
// 4 byte
this.GetULongLE = function()
{
if (this.cur + 3 >= this.size)
return 0;
return (this.data[this.cur++] | this.data[this.cur++] << 8 | this.data[this.cur++] << 16 | this.data[this.cur++] << 24);
}
this.GetLongLE = function()
{
return this.GetULongLE();
}
this.GetLong = function()
{
return this.GetULongLE();
};
this.GetDoubleLE = function()
{
if (this.cur + 7 >= this.size)
return 0;
var arr = [];
for(var i = 0; i < 8; ++i)
arr.push(this.GetUChar());
var dRes = this.doubleDecodeLE754(arr);
return dRes;
}
this.doubleDecodeLE754 = function(a)
{
var s, e, m, i, d, nBits, mLen, eLen, eBias, eMax;
var el = {len:8, mLen:52, rt:0};
mLen = el.mLen, eLen = el.len*8-el.mLen-1, eMax = (1<<eLen)-1, eBias = eMax>>1;
i = (el.len-1); d = -1; s = a[i]; i+=d; nBits = -7;
for (e = s&((1<<(-nBits))-1), s>>=(-nBits), nBits += eLen; nBits > 0; e=e*256+a[i], i+=d, nBits-=8);
for (m = e&((1<<(-nBits))-1), e>>=(-nBits), nBits += mLen; nBits > 0; m=m*256+a[i], i+=d, nBits-=8);
switch (e) // 1 bytes
{ FT_Stream2.prototype.GetUChar = function() {
case 0: if (this.cur >= this.size)
// Zero, or denormalized number return 0;
e = 1-eBias; return this.data[this.cur++];
break; };
case eMax: FT_Stream2.prototype.GetByte = function() {
// NaN, or +/-Infinity return this.GetUChar();
return m?NaN:((s?-1:1)*Infinity); };
default: FT_Stream2.prototype.GetBool = function() {
// Normalized number var Value = this.GetUChar();
m = m + Math.pow(2, mLen); return ( Value == 0 ? false : true );
e = e - eBias; };
break; // 2 byte
} FT_Stream2.prototype.GetUShortLE = function() {
return (s?-1:1) * m * Math.pow(2, e-mLen); if (this.cur + 1 >= this.size)
}; return 0;
// 3 byte return (this.data[this.cur++] | this.data[this.cur++] << 8);
this.GetUOffsetLE = function() };
{ // 4 byte
if (this.cur + 2 >= this.size) FT_Stream2.prototype.GetULongLE = function() {
return c_oSerConstants.ReadOk; if (this.cur + 3 >= this.size)
return (this.data[this.cur++] | this.data[this.cur++] << 8 | this.data[this.cur++] << 16); return 0;
} return (this.data[this.cur++] | this.data[this.cur++] << 8 | this.data[this.cur++] << 16 | this.data[this.cur++] << 24);
};
FT_Stream2.prototype.GetLongLE = function() {
return this.GetULongLE();
};
FT_Stream2.prototype.GetLong = function() {
return this.GetULongLE();
};
FT_Stream2.prototype.GetDoubleLE = function() {
if (this.cur + 7 >= this.size)
return 0;
var arr = [];
for(var i = 0; i < 8; ++i)
arr.push(this.GetUChar());
return this.doubleDecodeLE754(arr);
};
FT_Stream2.prototype.doubleDecodeLE754 = function(a) {
var s, e, m, i, d, nBits, mLen, eLen, eBias, eMax;
var el = {len:8, mLen:52, rt:0};
mLen = el.mLen, eLen = el.len*8-el.mLen-1, eMax = (1<<eLen)-1, eBias = eMax>>1;
this.GetString2 = function() i = (el.len-1); d = -1; s = a[i]; i+=d; nBits = -7;
{ for (e = s&((1<<(-nBits))-1), s>>=(-nBits), nBits += eLen; nBits > 0; e=e*256+a[i], i+=d, nBits-=8);
var Len = this.GetLong(); for (m = e&((1<<(-nBits))-1), e>>=(-nBits), nBits += mLen; nBits > 0; m=m*256+a[i], i+=d, nBits-=8);
return this.GetString2LE(Len);
}
//String switch (e)
this.GetString2LE = function(len)
{
if (this.cur + len > this.size)
return "";
var a = [];
for (var i = 0; i + 1 < len; i+=2)
a.push(String.fromCharCode(this.data[this.cur + i] | this.data[this.cur + i + 1] << 8));
this.cur += len;
return a.join("");
}
this.GetString = function()
{
var Len = this.GetLong();
if (this.cur + 2 * Len > this.size)
return "";
var t = "";
for (var i = 0; i + 1 < 2 * Len; i+=2)
{
var uni = this.data[this.cur + i];
uni |= this.data[this.cur + i + 1] << 8;
t += String.fromCharCode(uni);
}
this.cur += 2 * Len;
return t;
}
this.GetCurPos = function()
{ {
return this.cur; case 0:
// Zero, or denormalized number
e = 1-eBias;
break;
case eMax:
// NaN, or +/-Infinity
return m?NaN:((s?-1:1)*Infinity);
default:
// Normalized number
m = m + Math.pow(2, mLen);
e = e - eBias;
break;
} }
this.GetSize = function() return (s?-1:1) * m * Math.pow(2, e-mLen);
{ };
return this.size; // 3 byte
FT_Stream2.prototype.GetUOffsetLE = function() {
if (this.cur + 2 >= this.size)
return c_oSerConstants.ReadOk;
return (this.data[this.cur++] | this.data[this.cur++] << 8 | this.data[this.cur++] << 16);
};
FT_Stream2.prototype.GetString2 = function() {
var Len = this.GetLong();
return this.GetString2LE(Len);
};
//String
FT_Stream2.prototype.GetString2LE = function(len) {
if (this.cur + len > this.size)
return "";
var a = [];
for (var i = 0; i + 1 < len; i+=2)
a.push(String.fromCharCode(this.data[this.cur + i] | this.data[this.cur + i + 1] << 8));
this.cur += len;
return a.join("");
};
FT_Stream2.prototype.GetString = function() {
var Len = this.GetLong();
if (this.cur + 2 * Len > this.size)
return "";
var t = "";
for (var i = 0; i + 1 < 2 * Len; i+=2) {
var uni = this.data[this.cur + i];
uni |= this.data[this.cur + i + 1] << 8;
t += String.fromCharCode(uni);
} }
this.EnterFrame = function(count) this.cur += 2 * Len;
{ return t;
if (this.size - this.pos < count) };
return c_oSerConstants.ErrorStream; FT_Stream2.prototype.GetCurPos = function() {
return this.cur;
this.cur = this.pos; };
this.pos += count; FT_Stream2.prototype.GetSize = function() {
return c_oSerConstants.ReadOk; return this.size;
} };
FT_Stream2.prototype.EnterFrame = function(count) {
if (this.size - this.pos < count)
return c_oSerConstants.ErrorStream;
this.GetDouble = function() this.cur = this.pos;
{ this.pos += count;
var dRes = 0.0; return c_oSerConstants.ReadOk;
dRes |= this.GetUChar(); };
dRes |= this.GetUChar() << 8; FT_Stream2.prototype.GetDouble = function() {
dRes |= this.GetUChar() << 16; var dRes = 0.0;
dRes |= this.GetUChar() << 24; dRes |= this.GetUChar();
dRes /= 100000; dRes |= this.GetUChar() << 8;
return dRes; dRes |= this.GetUChar() << 16;
} dRes |= this.GetUChar() << 24;
} dRes /= 100000;
return dRes;
};
var gc_nMaxRow = 1048576; var gc_nMaxRow = 1048576;
var gc_nMaxCol = 16384; var gc_nMaxCol = 16384;
var gc_nMaxRow0 = gc_nMaxRow - 1; var gc_nMaxRow0 = gc_nMaxRow - 1;
...@@ -599,7 +567,7 @@ function CellAddressUtils(){ ...@@ -599,7 +567,7 @@ function CellAddressUtils(){
} }
return oRes; return oRes;
} }
}; }
var g_oCellAddressUtils = new CellAddressUtils(); var g_oCellAddressUtils = new CellAddressUtils();
/** /**
* @constructor * @constructor
...@@ -637,7 +605,7 @@ function CellAddress(){ ...@@ -637,7 +605,7 @@ function CellAddress(){
this._checkCoord(); this._checkCoord();
this._invalidId = true; this._invalidId = true;
} }
}; }
CellAddress.prototype._isDigit=function(symbol){ CellAddress.prototype._isDigit=function(symbol){
return '0' <= symbol && symbol <= '9'; return '0' <= symbol && symbol <= '9';
}; };
......
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