Commit 6247a98d authored by Oleg.Korshul's avatar Oleg.Korshul Committed by Alexander.Trofimov

новый функционал: отрисовка глифов по векторным путям. Печать формул

git-svn-id: svn://192.168.3.15/activex/AVS/Sources/TeamlabOffice/trunk/OfficeWeb@58841 954022d7-b5bf-4e40-9824-e11837661b57
parent 034b1f8f
......@@ -5,6 +5,117 @@ function CCMapIndex()
this.index = 0;
}
function CGlyphVectorPainter()
{
// сдвиг
this.X = 0;
this.Y = 0;
// scale
this.KoefX = 25.4 / 72;
this.KoefY = 25.4 / 72;
this.NeedClosed = false;
this.shift = 0;
this.delta = 0;
this.CurX = 0;
this.CurY = 0;
}
CGlyphVectorPainter.prototype =
{
start : function()
{
},
move_to : function(to, worker)
{
if (this.NeedClosed)
{
worker._z();
this.NeedClosed = false;
}
this.CurX = this.X + this.KoefX * (to.x / 64.0);
this.CurY = this.Y - this.KoefY * (to.y / 64.0);
worker._m(this.CurX, this.CurY);
return 0;
},
line_to : function(to, worker)
{
this.CurX = this.X + this.KoefX * (to.x / 64.0);
this.CurY = this.Y - this.KoefY * (to.y / 64.0);
worker._l(this.CurX, this.CurY);
this.NeedClosed = true;
return 0;
},
conic_to : function(control, to, worker)
{
var dX0 = this.CurX;
var dY0 = this.CurY;
var dXc = this.X + this.KoefX * (control.x / 64.0);
var dYc = this.Y - this.KoefY * (control.y / 64.0);
var dX3 = this.X + this.KoefX * (to.x / 64.0);
var dY3 = this.Y - this.KoefY * (to.y / 64.0);
// Строим кривую Безье второго порядка, с помощью кривой Безье третего порядка. Если p0, pC, p3 -
// начальная, контрольная и конечная точки, соответственно, для кривой Безье второго порядка. Тогда
// для этой же кривой, рассматриваемой как кривая Безье третьего порядка, точки p0, p1, p2, p3 будут
// начальной, две контрольные, конечная точки. Где p1 и p2 рассчитываются по следующим формулам:
// p1 = (1/3) * (p0 + 2pС)
// p2 = (1/3) * (2pС + p3)
var dX1 = (1.0 / 3.0) * (dX0 + 2 * dXc);
var dY1 = (1.0 / 3.0) * (dY0 + 2 * dYc);
var dX2 = (1.0 / 3.0) * (2 * dXc + dX3);
var dY2 = (1.0 / 3.0) * (2 * dYc + dY3);
worker._c(dX1, dY1, dX2, dY2, dX3, dY3);
this.CurX = dX3;
this.CurY = dY3;
this.NeedClosed = true;
return 0;
},
cubic_to : function(control1, control2, to, worker)
{
this.CurX = this.X + this.KoefX * (to.x / 64.0);
this.CurY = this.Y - this.KoefY * (to.y / 64.0);
worker._c(
this.X + this.KoefX * (control1.x / 64.0),
this.Y - this.KoefY * (control1.y / 64.0),
this.X + this.KoefX * (control2.x / 64.0),
this.Y - this.KoefY * (control2.y / 64.0),
this.CurX,
this.CurY);
this.NeedClosed = true;
return 0;
},
end : function(worker)
{
if (this.NeedClosed)
{
worker._z();
this.NeedClosed = false;
}
}
};
function CFontFile(fileName, faceIndex)
{
this.m_arrdFontMatrix = new Array(6);
......@@ -1521,4 +1632,98 @@ function CFontFile(fileName, faceIndex)
if (this.m_pFace.family_name == "MS Mincho" || this.m_pFace.family_name == "Castellar")
this.HintsSupport = false;
}
this.GetCharPath = function(lUnicode, worker, x, y)
{
var pFace = this.m_pFace;
var pCurentGliph = pFace.glyph;
var Result;
var ushUnicode = lUnicode;
// Сначала мы все рассчитываем исходя только из матрицы шрифта FontMatrix
if (this.m_bIsNeedUpdateMatrix12)
{
if (this.m_pDefaultFont)
this.m_pDefaultFont.UpdateMatrix1();
this.UpdateMatrix1();
}
var unGID = 0;
var nCMapIndex = new CCMapIndex();
unGID = this.SetCMapForCharCode(ushUnicode, nCMapIndex);
if (!((unGID > 0) || (-1 != this.m_nSymbolic && (ushUnicode < 0xF000) &&
0 < (unGID = this.SetCMapForCharCode(ushUnicode + 0xF000, nCMapIndex)))))
{
// Пробуем загрузить через стандартный шрифт
if (false === this.m_bUseDefaultFont || null == this.m_pDefaultFont ||
0 >= (unGID = this.m_pDefaultFont.SetCMapForCharCode(ushUnicode, nCMapIndex)))
{
if (this.m_nDefaultChar < 0)
{
return;
}
else
{
unGID = this.m_nDefaultChar;
pFace = this.m_pFace;
pCurentGliph = pFace.glyph;
}
}
else
{
pFace = this.m_pDefaultFont.m_pFace;
pCurentGliph = this.m_pDefaultFont.m_pGlyph;
}
}
var _LOAD_MODE = this.HintsSupport ? this.m_oFontManager.LOAD_MODE : 40970;
if (0 != FT_Load_Glyph(pFace, unGID, _LOAD_MODE))
return;
var pGlyph = FT_Get_Glyph(pCurentGliph);
if (null == pGlyph)
return;
var _painter = new CGlyphVectorPainter();
_painter.KoefX = 25.4 / this.m_unHorDpi;
_painter.KoefY = 25.4 / this.m_unVerDpi;
if (x !== undefined)
_painter.X = x;
if (y !== undefined)
_painter.Y = y;
_painter.start(worker);
FT_Outline_Decompose(pGlyph.outline, _painter, worker);
_painter.end(worker);
if (this.m_bIsNeedUpdateMatrix12)
{
if (this.m_pDefaultFont)
this.m_pDefaultFont.UpdateMatrix2();
this.UpdateMatrix2();
}
}
this.GetStringPath = function(string, worker)
{
var _len = string.GetLength();
if (_len <= 0)
return true;
for (var nIndex = 0; nIndex < _len; ++nIndex)
{
var _glyph = string.m_pGlyphsBuffer[nIndex];
var _x = string.m_fX + 25.4 * _glyph.fX / this.m_unHorDpi;
var _y = string.m_fY + 25.4 * _glyph.fY / this.m_unVerDpi;
worker._s();
this.GetCharPath(_glyph.lUnicode, worker, _x, _y);
worker.df();
worker._e();
}
}
};
\ No newline at end of file
......@@ -1476,6 +1476,39 @@ function CFontManager()
return string.m_fEndX;
}
this.LoadStringPathCode = function(code, isGid, fX, fY, worker)
{
if (!this.m_pFont)
return false;
this.SetStringGID(isGid);
// это SetString
var string = this.m_oGlyphString;
string.m_fX = fX + string.m_fTransX;
string.m_fY = fY + string.m_fTransY;
string.m_nGlyphsCount = 1;
string.m_nGlyphIndex = 0;
var buffer = string.m_pGlyphsBuffer;
if (buffer[0] == undefined)
buffer[0] = new TGlyph();
var _g = buffer[0];
_g.bBitmap = false;
_g.oBitmap = null;
_g.eState = EGlyphState.glyphstateNormal;
_g.lUnicode = code;
this.m_pFont.GetStringPath(string, worker);
this.SetStringGID(false);
return true;
}
this.LoadChar = function(lUnicode)
{
if (!this.m_pFont)
......
......@@ -313,12 +313,6 @@ CGrState.prototype =
var _r = _c[j].Rect;
//this.Parent.AddClipRect(_r.x, _r.y, _r.w, _r.h);
var _restoreDumpedVectors = null;
if (this.Parent.private_removeVectors !== undefined)
{
_restoreDumpedVectors = this.Parent.private_removeVectors();
}
this.Parent.StartClipPath();
this.Parent._s();
......@@ -329,9 +323,6 @@ CGrState.prototype =
this.Parent._l(_r.x, _r.y);
this.Parent.EndClipPath();
if (null != _restoreDumpedVectors)
this.Parent.private_restoreVectors(_restoreDumpedVectors);
}
}
}
......@@ -1126,6 +1117,13 @@ CMetafile.prototype =
this.Memory.WriteLong(256);
}
},
WriteVectorMemoryForPrint : function()
{
if (null != this.VectorMemoryForPrint)
{
this.Memory.Copy(this.VectorMemoryForPrint, 0, this.VectorMemoryForPrint.pos);
}
},
drawpath : function(type)
{
if (null == this.VectorMemoryForPrint)
......@@ -1221,6 +1219,13 @@ CMetafile.prototype =
if (font.FontFamily.Name == "" && 0 <= font.FontFamily.Index)
font.FontFamily.Name = window.g_font_infos[font.FontFamily.Index].Name;
if (font.FontFamily.Index == -1 || font.FontFamily.Index === undefined)
{
if (undefined !== window.g_map_font_index[font.FontFamily.Name])
font.FontFamily.Index = window.g_map_font_index[font.FontFamily.Name];
}
var style = 0;
if (font.Italic == true)
style += 2;
......@@ -1283,17 +1288,54 @@ CMetafile.prototype =
},
FillTextCode : function(x,y,code)
{
if (code < 0xFFFF)
return this.FillText(x, y, String.fromCharCode(code));
var _font = this.m_oLastFont;
var _old_pos = this.Memory.pos;
window.g_font_infos[_font.SetUpIndex].LoadFont(window.g_font_loader,
g_oTextMeasurer.m_oManager,
_font.SetUpSize,
_font.SetUpStyle, 72, 72);
g_oTextMeasurer.m_oManager.LoadStringPathCode(code, false, x, y, this);
// start (1) + draw(1) + typedraw(4) + end(1) = 7!
if ((this.Memory.pos - _old_pos) < 8)
this.Memory.pos = _old_pos;
/*
this.Memory.WriteByte(CommandType.ctDrawTextCode);
this.Memory.WriteLong(code);
this.Memory.WriteDouble(x);
this.Memory.WriteDouble(y);
*/
},
tg : function(gid,x,y)
{
var _font = this.m_oLastFont;
var _old_pos = this.Memory.pos;
window.g_font_infos[_font.SetUpIndex].LoadFont(window.g_font_loader,
g_oTextMeasurer.m_oManager,
_font.SetUpSize,
_font.SetUpStyle, 72, 72);
g_oTextMeasurer.m_oManager.LoadStringPathCode(gid, true, x, y, this);
// start (1) + draw(1) + typedraw(4) + end(1) = 7!
if ((this.Memory.pos - _old_pos) < 8)
this.Memory.pos = _old_pos;
/*
this.Memory.WriteByte(CommandType.ctDrawTextCodeGid);
this.Memory.WriteLong(gid);
this.Memory.WriteDouble(x);
this.Memory.WriteDouble(y);
*/
},
charspace : function(space)
{
......@@ -1492,6 +1534,8 @@ function CDocumentRenderer()
this.m_oPen = null;
this.m_oBrush = null;
this.m_oTransform = null;
this._restoreDumpedVectors = null;
}
CDocumentRenderer.prototype =
......@@ -2112,6 +2156,8 @@ CDocumentRenderer.prototype =
StartClipPath : function()
{
this.private_removeVectors();
if (0 != this.m_lPagesCount)
this.m_arrayPages[this.m_lPagesCount - 1].beginCommand(32);
},
......@@ -2120,6 +2166,8 @@ CDocumentRenderer.prototype =
{
if (0 != this.m_lPagesCount)
this.m_arrayPages[this.m_lPagesCount - 1].endCommand(32);
this.private_restoreVectors();
},
SetTextPr : function(textPr, theme)
......@@ -2156,25 +2204,24 @@ CDocumentRenderer.prototype =
private_removeVectors : function()
{
var _ret = this.VectorMemoryForPrint;
this._restoreDumpedVectors = this.VectorMemoryForPrint;
if (_ret != null)
if (this._restoreDumpedVectors != null)
{
this.VectorMemoryForPrint = null;
if (0 != this.m_lPagesCount)
this.m_arrayPages[this.m_lPagesCount - 1].VectorMemoryForPrint = null;
}
return _ret;
},
private_restoreVectors : function(_vectors)
private_restoreVectors : function()
{
if (null != _vectors)
if (null != this._restoreDumpedVectors)
{
this.VectorMemoryForPrint = _vectors;
this.VectorMemoryForPrint = this._restoreDumpedVectors;
if (0 != this.m_lPagesCount)
this.m_arrayPages[this.m_lPagesCount - 1].VectorMemoryForPrint = _vectors;
this.m_arrayPages[this.m_lPagesCount - 1].VectorMemoryForPrint = this._restoreDumpedVectors;
}
this._restoreDumpedVectors = null;
}
};
\ No newline at end of file
......@@ -1301,18 +1301,8 @@ CShapeDrawer.prototype =
{
if (this.UniFill.fill.RasterImageId && this.UniFill.fill.RasterImageId.indexOf(".svg") != 0)
{
this.Graphics.SaveGrState();
this.Graphics.StartClipPath();
this.Graphics.EndClipPath();
this.Graphics.drawImage(_getFullImageSrc(this.UniFill.fill.RasterImageId), this.min_x, this.min_y, (this.max_x - this.min_x), (this.max_y - this.min_y), undefined, undefined);
bIsFill = false;
// это чтобы слипы были не пустые - и отменились при восстановлении
var _histClip = new CHist_Clip();
this.Graphics.GrState.Clips.push(_histClip);
this.Graphics.RestoreGrState();
}
else
{
......@@ -1328,18 +1318,8 @@ CShapeDrawer.prototype =
}
else
{
this.Graphics.SaveGrState();
this.Graphics.StartClipPath();
this.Graphics.EndClipPath();
this.Graphics.drawImage(_getFullImageSrc(this.UniFill.fill.RasterImageId), this.min_x, this.min_y, (this.max_x - this.min_x), (this.max_y - this.min_y), undefined, this.UniFill.fill.srcRect);
bIsFill = false;
// это чтобы слипы были не пустые - и отменились при восстановлении
var _histClip = new CHist_Clip();
this.Graphics.GrState.Clips.push(_histClip);
this.Graphics.RestoreGrState();
}
}
else
......
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