Skip to content

Commit

Permalink
Fix bug 33571
Browse files Browse the repository at this point in the history
- add processing for small caps, caps and position offset
  • Loading branch information
IgolJack committed Sep 17, 2024
1 parent 68b999b commit f5b8767
Showing 1 changed file with 151 additions and 110 deletions.
261 changes: 151 additions & 110 deletions word/Math/mathText.js
Original file line number Diff line number Diff line change
Expand Up @@ -704,47 +704,67 @@ CMathText.prototype.IsAccent = function ()
}
CMathText.prototype.Measure = function(oMeasure, TextPr, InfoMathText)
{
/*
var metricsTxt = g_oTextMeasurer.Measure2Code(letter);
var _width = metricsTxt.Width;
height = g_oTextMeasurer.GetHeight();
*/
/*
var metricsTxt = g_oTextMeasurer.Measure2Code(letter);
var _width = metricsTxt.Width;
height = g_oTextMeasurer.GetHeight();
*/

var metricsTxt;
var metricsTxt;

// measure
if(this.bJDraw)
{
// Font выставляется на соответствующей функции SetFont в родительском классе (в общем случае в CMathBase)
// measure
if(this.bJDraw)
{
// Font выставляется на соответствующей функции SetFont в родительском классе (в общем случае в CMathBase)

this.RecalcInfo.StyleCode = this.value;
metricsTxt = oMeasure.Measure2Code(this.value);
}
else
{
var ascent, width, height, descent;
this.RecalcInfo.StyleCode = this.value;
metricsTxt = oMeasure.Measure2Code(this.value);
}
else
{
var ascent, width, height, descent;

var letter = this.private_getCode();
var letter = this.private_getCode();

this.FontSlot = InfoMathText.GetFontSlot(letter); // возвращает AscWord.fontslot_ASCII || AscWord.fontslot_EastAsia || AscWord.fontslot_CS || AscWord.fontslot_HAnsi
this.FontSlot = InfoMathText.GetFontSlot(letter); // возвращает AscWord.fontslot_ASCII || AscWord.fontslot_EastAsia || AscWord.fontslot_CS || AscWord.fontslot_HAnsi

// в не математическом тексте i и j не подменяются на i и j без точек
var bAccentIJ = !InfoMathText.bNormalText && this.Parent.IsAccent() && (this.value == 0x69 || this.value == 0x6A);
// в не математическом тексте i и j не подменяются на i и j без точек
var bAccentIJ = !InfoMathText.bNormalText && this.Parent.IsAccent() && (this.value == 0x69 || this.value == 0x6A);

this.RecalcInfo.StyleCode = letter;
this.RecalcInfo.bAccentIJ = bAccentIJ;
this.RecalcInfo.StyleCode = letter;
this.RecalcInfo.bAccentIJ = bAccentIJ;

var bApostrophe = 1 == q_Math_Apostrophe[letter] && this.bJDraw == false;
var bApostrophe = 1 == q_Math_Apostrophe[letter] && this.bJDraw == false;

if(bAccentIJ)
oMeasure.SetStringGid(true);
if(bAccentIJ)
oMeasure.SetStringGid(true);

if( InfoMathText.NeedUpdateFont(letter, this.FontSlot, this.IsPlaceholder(), bApostrophe) )
{
g_oTextMeasurer.SetFont(InfoMathText.Font);
//g_oTextMeasurer.SetTextPr(InfoTextPr.CurrentTextPr, InfoTextPr.Theme);
}
else if(InfoMathText.CurrType == MathTextInfo_NormalText)
else if( InfoMathText.NeedUpdateFont(letter, this.FontSlot, this.IsPlaceholder(), bApostrophe) )
{
if (this.Parent.Pr.SmallCaps || this.Parent.Pr.Caps)
{
let symbol;

if (this.Parent.Pr.SmallCaps)
symbol = String.fromCharCode(this.value).toLowerCase();
else if (this.Parent.Pr.Caps)
symbol = String.fromCharCode(this.value).toUpperCase();

letter = symbol.charCodeAt(0);
this.RecalcInfo.StyleCode = letter;
InfoMathText.bApostrophe = false;

var FontKoef = InfoMathText.GetFontKoef(this.FontSlot);

g_oTextMeasurer.SetFontSlot(this.FontSlot, FontKoef);
}
else
{
g_oTextMeasurer.SetFont(InfoMathText.Font);
}
//g_oTextMeasurer.SetTextPr(InfoTextPr.CurrentTextPr, InfoTextPr.Theme);
}
else if(InfoMathText.CurrType == MathTextInfo_NormalText)
{
letter = this.value;
this.RecalcInfo.StyleCode = letter;
Expand All @@ -755,56 +775,56 @@ CMathText.prototype.Measure = function(oMeasure, TextPr, InfoMathText)
g_oTextMeasurer.SetFontSlot(this.FontSlot, FontKoef);
}

this.RecalcInfo.bApostrophe = InfoMathText.bApostrophe;
this.RecalcInfo.bSpaceSpecial = letter == 0x2061;
this.RecalcInfo.bApostrophe = InfoMathText.bApostrophe;
this.RecalcInfo.bSpaceSpecial = letter == 0x2061;

metricsTxt = oMeasure.MeasureCode(letter);
metricsTxt = oMeasure.MeasureCode(letter);

if(bAccentIJ)
oMeasure.SetStringGid(false);
}
if(bAccentIJ)
oMeasure.SetStringGid(false);
}

if(this.RecalcInfo.bApostrophe)
{
width = metricsTxt.Width;
height = metricsTxt.Height;
if(this.RecalcInfo.bApostrophe)
{
width = metricsTxt.Width;
height = metricsTxt.Height;

InfoMathText.NeedUpdateFont(0x1D44E, this.FontSlot, false, false); // a
g_oTextMeasurer.SetFont(InfoMathText.Font);
InfoMathText.NeedUpdateFont(0x1D44E, this.FontSlot, false, false); // a
g_oTextMeasurer.SetFont(InfoMathText.Font);

var metricsA = oMeasure.MeasureCode(0x1D44E); // a
this.rasterOffsetY = metricsA.Height - metricsTxt.Ascent; // смещение для позиции
var metricsA = oMeasure.MeasureCode(0x1D44E); // a
this.rasterOffsetY = metricsA.Height - metricsTxt.Ascent; // смещение для позиции

ascent = metricsA.Height;
}
// else if(this.RecalcInfo.bSpaceSpecial) // show funcapply
// {
// width = 0;
// height = 0;
// ascent = 0;
// }
else
{
// смещения
this.rasterOffsetX = metricsTxt.rasterOffsetX;
this.rasterOffsetY = metricsTxt.rasterOffsetY;
ascent = metricsA.Height;
}
// else if(this.RecalcInfo.bSpaceSpecial) // show funcapply
// {
// width = 0;
// height = 0;
// ascent = 0;
// }
else
{
// смещения
this.rasterOffsetX = metricsTxt.rasterOffsetX;
this.rasterOffsetY = metricsTxt.rasterOffsetY;

ascent = metricsTxt.Ascent;
descent = (metricsTxt.Height - metricsTxt.Ascent);
height = ascent + descent;
ascent = metricsTxt.Ascent;
descent = (metricsTxt.Height - metricsTxt.Ascent);
height = ascent + descent;


if(this.bJDraw)
width = metricsTxt.WidthG;
else
width = metricsTxt.Width;
}
if(this.bJDraw)
width = metricsTxt.WidthG;
else
width = metricsTxt.Width;
}

this.size.width = width;
this.size.height = height;
this.size.ascent = ascent;
this.size.width = width;
this.size.height = height;
this.size.ascent = ascent;

this.Width = (this.size.width * AscWord.TEXTWIDTH_DIVIDER) | 0;
this.Width = (this.size.width * AscWord.TEXTWIDTH_DIVIDER) | 0;

};
CMathText.prototype.PreRecalc = function(Parent, ParaMath)
Expand All @@ -823,53 +843,55 @@ CMathText.prototype.Draw = function(x, y, pGraphics, InfoTextPr)
// 0x200C has a non-empty glyph in CambriaMath
if (this.value === 0x200C)
return;

var X = this.pos.x + x,
Y = this.pos.y + y;

if(this.bEmptyGapLeft == false)
X += this.GapLeft;
y -= this.Parent.getYOffset()

/*var tx = 0;
var ty = 0;
var X = this.pos.x + x,
Y = this.pos.y + y;

var x = (X*sy - Y*shx - tx*sy)/(sx*sy- shy*shx);
var y = (Y - x*shy - ty*shx)/sy;*/
if(this.bEmptyGapLeft == false)
X += this.GapLeft;

/*var invert = new CMatrix();
invert.sx = this.transform.sx;
invert.sy = this.transform.sy;
invert.shx = this.transform.shx;
invert.shy = this.transform.shy;
invert.tx = 0;
invert.ty = 0;
invert.Invert();
/*var tx = 0;
var ty = 0;
var xx = invert.TransformPointX(X, Y);
var yy = invert.TransformPointY(X, Y);
var x = (X*sy - Y*shx - tx*sy)/(sx*sy- shy*shx);
var y = (Y - x*shy - ty*shx)/sy;*/

/*var invert = new CMatrix();
invert.sx = this.transform.sx;
invert.sy = this.transform.sy;
invert.shx = this.transform.shx;
invert.shy = this.transform.shy;
invert.tx = 0;
invert.ty = 0;
invert.Invert();
var sx = this.transform.sx, shx = this.transform.shx,
shy = this.transform.shy, sy = this.transform.sy;
var xx = invert.TransformPointX(X, Y);
var yy = invert.TransformPointY(X, Y);
pGraphics.transform(sx, shy, shx, sy, 0, 0);*/
if(this.bJDraw)
{
pGraphics.FillTextCode(X, Y, this.RecalcInfo.StyleCode); //на отрисовку символа отправляем положение baseLine
}
else if(this.RecalcInfo.bSpaceSpecial == false)
{
if( InfoTextPr.NeedUpdateFont(this.RecalcInfo.StyleCode, this.FontSlot, this.IsPlaceholder(), this.RecalcInfo.bApostrophe) )
{
pGraphics.SetFont(InfoTextPr.Font);
//pGraphics.SetTextPr(InfoTextPr.CurrentTextPr, InfoTextPr.Theme);
}
else if(InfoTextPr.CurrType == MathTextInfo_NormalText)
{
var FontKoef = InfoTextPr.GetFontKoef(this.FontSlot);
pGraphics.SetFontSlot(this.FontSlot, FontKoef);
}
var sx = this.transform.sx, shx = this.transform.shx,
shy = this.transform.shy, sy = this.transform.sy;
pGraphics.transform(sx, shy, shx, sy, 0, 0);*/

if(this.bJDraw)
{
pGraphics.FillTextCode(X, Y, this.RecalcInfo.StyleCode); //на отрисовку символа отправляем положение baseLine
}
else if(this.RecalcInfo.bSpaceSpecial == false)
{
if( InfoTextPr.NeedUpdateFont(this.RecalcInfo.StyleCode, this.FontSlot, this.IsPlaceholder(), this.RecalcInfo.bApostrophe) )
{
pGraphics.SetFont(InfoTextPr.Font);
//pGraphics.SetTextPr(InfoTextPr.CurrentTextPr, InfoTextPr.Theme);
}
else if(InfoTextPr.CurrType == MathTextInfo_NormalText)
{
var FontKoef = InfoTextPr.GetFontKoef(this.FontSlot);
pGraphics.SetFontSlot(this.FontSlot, FontKoef);
}

if (this.RecalcInfo.bAccentIJ)
{
Expand Down Expand Up @@ -902,9 +924,28 @@ CMathText.prototype.Draw = function(x, y, pGraphics, InfoTextPr)
pGraphics.drawHorLine(0, y2, x1, x2, penW);
pGraphics.drawVerLine(0, x1, y1, y2, penW);
pGraphics.drawVerLine(0, x2, y1, y2, penW);
} else
}
else
{
pGraphics.FillTextCode(X, Y, this.RecalcInfo.StyleCode); //на отрисовку символа отправляем положение baseLine}
let strOriginal = String.fromCharCode(this.value);
let strUpper = strOriginal.toUpperCase();
let strLower = strOriginal.toLowerCase();
let nUpperStr = strUpper.charCodeAt(0);
let nLowerStr = strLower.charCodeAt(0);

if (InfoTextPr.TextPr.Caps && nUpperStr !== this.value)
{
pGraphics.FillTextCode(X, Y, nUpperStr);
}
else if (InfoTextPr.TextPr.SmallCaps && nLowerStr !== this.value)
{
pGraphics.FillTextCode(X, Y, nLowerStr);
}
else
{
// на отрисовку символа отправляем положение baseLine
pGraphics.FillTextCode(X, Y, this.RecalcInfo.StyleCode);
}
}
}
};
Expand Down

0 comments on commit f5b8767

Please sign in to comment.