Skip to content

Commit

Permalink
[pdf] Fixed vert align text in text/combobox form
Browse files Browse the repository at this point in the history
  • Loading branch information
KhromovNikita committed Oct 25, 2023
1 parent a22cf74 commit 092797f
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 10 deletions.
41 changes: 38 additions & 3 deletions pdf/src/forms/base/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -1822,14 +1822,14 @@
let oPara = this.content.GetElement(0);
let oApiPara = editor.private_CreateApiParagraph(oPara);

oApiPara.SetFontSize(nSize);
oApiPara.SetFontSize(nSize * 2);
oPara.RecalcCompiledPr(true);
}
if (this.contentFormat) {
let oPara = this.contentFormat.GetElement(0);
let oApiPara = editor.private_CreateApiParagraph(oPara);

oApiPara.SetFontSize(nSize);
oApiPara.SetFontSize(nSize * 2);
oPara.RecalcCompiledPr(true);
}
}
Expand Down Expand Up @@ -1997,8 +1997,42 @@
memory.WriteLong(annotFlags);
memory.Seek(nEndPos);
};
CBaseField.prototype.GetFontSizeAP = function() {
let oPara = this.content.GetElement(0);
let oRun = oPara.GetElement(0);
let oTextPr = oRun.Get_CompiledPr(true);

return oTextPr.FontSize;
};
CBaseField.prototype.WriteToBinaryBase2 = function(memory) {
// font name
let sFontName = this.GetTextFont();
if (sFontName != null) {
memory.WriteString(sFontName);
}

// text size
let nFontSize = this.GetTextSize();
if (nFontSize != null) {
memory.WriteDouble(nFontSize);
}

// text size for ap
memory.WriteDouble(this.GetFontSizeAP());

// text style
let nStyle = 0;
let isBold = true;
let isItalic = true;
if (isBold) {
nStyle |= (1 << 0);
}
if (isItalic) {
nStyle |= (1 << 1);
}
memory.WriteLong(nStyle);

// text color
let aTextColor = this.GetTextColor();
if (aTextColor && aTextColor.length != 0) {
memory.WriteLong(aTextColor.length);
Expand All @@ -2007,7 +2041,8 @@
memory.WriteDouble(aTextColor[i]);
}
}


// align
if (this.GetType() == AscPDF.FIELD_TYPES.text) {
let nAlignType = this.GetAlign();
memory.WriteByte(nAlignType);
Expand Down
3 changes: 3 additions & 0 deletions pdf/src/forms/base/basecheckbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,9 @@
this.AddActionsToQueue(AscPDF.FORMS_TRIGGERS_TYPES.OnFocus);
oDoc.activeForm = this;
};
CBaseCheckBoxField.prototype.GetFontSizeAP = function() {
return 12;
};
CBaseCheckBoxField.prototype.onMouseEnter = function() {
this.AddActionsToQueue(AscPDF.FORMS_TRIGGERS_TYPES.MouseEnter);

Expand Down
14 changes: 11 additions & 3 deletions pdf/src/forms/combobox.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@
if (this.GetTextSize() == 0)
this.ProcessAutoFitContent();

let oContentBounds = this.content.GetContentBounds(0);
let nContentH = oContentBounds.Bottom - oContentBounds.Top;
let nContentH = this.GetTextHeight();
contentY = (Y + nHeight / 2) * g_dKoef_pix_to_mm - nContentH / 2;

this._formRect.X = X * g_dKoef_pix_to_mm;
Expand Down Expand Up @@ -630,7 +629,7 @@

var nTextHeight = g_oTextMeasurer.GetHeight();
var nMaxWidth = oPara.RecalculateMinMaxContentWidth(false).Max;
var nFontSize = Math.max(oTextPr.FontSize);
var nFontSize = oTextPr.FontSize;

if (nMaxWidth < 0.001 || nTextHeight < 0.001 || oBounds.W < 0.001 || oBounds.H < 0.001)
return nTextHeight;
Expand All @@ -644,7 +643,16 @@

this.AddToRedraw();
};
CComboBoxField.prototype.GetTextHeight = function() {
let oPara = this.content.GetElement(0);
let oRun = oPara.GetElement(0);
let oTextPr = oRun.Get_CompiledPr(true);

g_oTextMeasurer.SetTextPr(oTextPr, null);
g_oTextMeasurer.SetFontSlot(AscWord.fontslot_ASCII);

return g_oTextMeasurer.GetHeight();
};
CComboBoxField.prototype.WriteToBinary = function(memory) {
// TODO
/*
Expand Down
15 changes: 12 additions & 3 deletions pdf/src/forms/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@

var nTextHeight = g_oTextMeasurer.GetHeight();
var nMaxWidth = oPara.RecalculateMinMaxContentWidth(false).Max;
var nFontSize = Math.max(oTextPr.FontSize);
var nFontSize = oTextPr.FontSize;

if (nMaxWidth < 0.001 || nTextHeight < 0.001 || oBounds.W < 0.001 || oBounds.H < 0.001)
return nTextHeight;
Expand Down Expand Up @@ -380,6 +380,16 @@

this.AddToRedraw();
};
CTextField.prototype.GetTextHeight = function() {
let oPara = this.content.GetElement(0);
let oRun = oPara.GetElement(0);
let oTextPr = oRun.Get_CompiledPr(true);

g_oTextMeasurer.SetTextPr(oTextPr, null);
g_oTextMeasurer.SetFontSlot(AscWord.fontslot_ASCII);

return g_oTextMeasurer.GetHeight();
};
CTextField.prototype.Recalculate = function() {
if (this.IsNeedRecalc() == false)
return;
Expand Down Expand Up @@ -421,8 +431,7 @@
if (this.GetTextSize() == 0)
this.ProcessAutoFitContent();

let oContentBounds = this.content.GetContentBounds(0);
let nContentH = oContentBounds.Bottom - oContentBounds.Top;
let nContentH = this.GetTextHeight();
contentY = (Y + nHeight / 2) * g_dKoef_pix_to_mm - nContentH / 2;
}

Expand Down
2 changes: 1 addition & 1 deletion pdf/src/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@
// if (oFormInfo["font"]["name"] != null)
// oForm.SetTextFont(oFormInfo["font"]["name"]);
if (oFormInfo["font"]["size"] != null)
oForm.SetTextSize(oFormInfo["font"]["size"] * 2);
oForm.SetTextSize(oFormInfo["font"]["size"]);
}

if (oFormInfo["AP"] != null) {
Expand Down

0 comments on commit 092797f

Please sign in to comment.