Skip to content

Commit

Permalink
[pdf] Fixed entering into combobox filed
Browse files Browse the repository at this point in the history
  • Loading branch information
KhromovNikita committed Oct 24, 2023
1 parent 0ca8c24 commit a22cf74
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 61 deletions.
10 changes: 6 additions & 4 deletions pdf/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,15 +370,17 @@
return false;
}

oDoc.activeForm.EnterText(text);
let isEntered = oDoc.activeForm.EnterText(text);
if (viewer.pagesInfo.pages[oDoc.activeForm._page].needRedrawForms) {
viewer._paint();
viewer.onUpdateOverlay();
}

this.WordControl.m_oDrawingDocument.TargetStart();
// Чтобы при зажатой клавише курсор не пропадал
this.WordControl.m_oDrawingDocument.showTarget(true);
if (isEntered) {
this.WordControl.m_oDrawingDocument.TargetStart();
// Чтобы при зажатой клавише курсор не пропадал
this.WordControl.m_oDrawingDocument.showTarget(true);
}

return true;
};
Expand Down
5 changes: 4 additions & 1 deletion pdf/src/document.js
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,10 @@ var CPresentation = CPresentation || function(){};
if (!this.checkDefaultFieldFonts(function(){_t.OnMouseDownField(oField, event)}))
return;

oField.Recalculate();
if (oField.IsNeedDrawFromStream()) {
oField.Recalculate();
oField.SetNeedRecalc(true);
}

// суть в том, что мы рисуем background только когда форма активна, если неактивна - рисуем highlight вместо него.
if (oField.GetBackgroundColor())
Expand Down
103 changes: 67 additions & 36 deletions pdf/src/forms/combobox.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@
this.DrawBorders(oGraphicsPDF);
};
CComboBoxField.prototype.Recalculate = function() {
if (this.IsNeedRecalc() == false)
return;

let oViewer = editor.getDocumentRenderer();
let nScale = AscCommon.AscBrowser.retinaPixelRatio * oViewer.zoom;
let aRect = this.GetRect();
Expand All @@ -103,18 +106,22 @@
let contentXLimit = (X + nWidth - 2 * oMargins.left - (18 / nScale)) * g_dKoef_pix_to_mm; // 18 / nScale --> Размер маркера комбобокса
let contentYLimit = (Y + nHeight - oMargins.bottom) * g_dKoef_pix_to_mm;

let nContentH = this.content.GetElement(0).Get_EmptyHeight();
contentY = (Y + nHeight / 2) * g_dKoef_pix_to_mm - nContentH / 2;
this.contentRect.X = contentX;
this.contentRect.Y = contentY;
this.contentRect.W = contentXLimit - this.contentRect.X;
this.contentRect.H = contentYLimit - this.contentRect.Y;

if (this.GetTextSize() == 0)
this.ProcessAutoFitContent();

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

this._formRect.X = X * g_dKoef_pix_to_mm;
this._formRect.Y = Y * g_dKoef_pix_to_mm;
this._formRect.W = nWidth * g_dKoef_pix_to_mm;
this._formRect.H = nHeight * g_dKoef_pix_to_mm;

this.contentRect.X = contentX;
this.contentRect.Y = contentY;
this.contentRect.W = contentXLimit - contentX;
this.contentRect.H = contentYLimit - contentY;

if (contentX != this._oldContentPos.X || contentY != this._oldContentPos.Y ||
contentXLimit != this._oldContentPos.XLimit) {
Expand All @@ -134,6 +141,7 @@
});
}


this.SetNeedRecalc(false);
};

Expand Down Expand Up @@ -377,49 +385,46 @@
}
}
};
CComboBoxField.prototype.EnterText = function(aChars, bForce)
CComboBoxField.prototype.EnterText = function(aChars)
{
if (this.IsEditable() == false && !bForce)
return false;
let oDoc = this.GetDocument();
this.CreateNewHistoryPoint(true);

if (aChars.length > 0)
this.CreateNewHistoryPoint(true);
else
if (this.DoKeystrokeAction(aChars) == false) {
AscCommon.History.Remove_LastPoint();
return false;

let oDoc = this.GetDocument();

// Если у нас что-то заселекчено и мы вводим текст или пробел
// и т.д., тогда сначала удаляем весь селект.
if (this.content.IsSelectionUse()) {
if (this.content.IsSelectionEmpty())
this.content.RemoveSelection();
else
this.content.Remove(1, true, false, true);
}

let nSelStart = oDoc.event["selStart"];
let nSelEnd = oDoc.event["selEnd"];

// убираем селект, выставляем из nSelStart/nSelEnd
if (this.content.IsSelectionUse())
this.content.RemoveSelection();

let oDocPos = this.CalcDocPos(nSelStart, nSelEnd);
let startPos = oDocPos.startPos;
let endPos = oDocPos.endPos;

let isCanEnter = this.DoKeystrokeAction(aChars);
if (isCanEnter) {
this.content.Remove(1, true, false, false);
if (nSelStart == nSelEnd) {
this.content.SetContentPosition(startPos, 0, 0);
this.content.RecalculateCurPos();
}
else
this.content.SetSelectionByContentPositions(startPos, endPos);

if (isCanEnter == false) {
return false;
}
if (nSelStart != nSelEnd)
this.content.Remove(-1, true, false, false, false);

aChars = AscWord.CTextFormFormat.prototype.GetBuffer(oDoc.event["change"].toString());
this.SetNeedRecalc(true);
aChars = AscWord.CTextFormFormat.prototype.GetBuffer(oDoc.event["change"]);
if (aChars.length == 0) {
return false;
}

this.CreateNewHistoryPoint(true);
this.InsertChars(aChars);

this.SetNeedRecalc(true);
this.SetNeedCommit(true); // флаг что значение будет применено к остальным формам с таким именем

if (this.IsChanged() == false)
this.SetWasChanged(true);
this._bAutoShiftContentView = true && this._doNotScroll == false;

return true;
};
Expand Down Expand Up @@ -614,6 +619,32 @@
return -1;
};

CComboBoxField.prototype.ProcessAutoFitContent = function() {
let oPara = this.content.GetElement(0);
let oRun = oPara.GetElement(0);
let oTextPr = oRun.Get_CompiledPr(true);
let oBounds = this.getFormRelRect();

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

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

if (nMaxWidth < 0.001 || nTextHeight < 0.001 || oBounds.W < 0.001 || oBounds.H < 0.001)
return nTextHeight;

let nNewFontSize = (Math.min(nFontSize * oBounds.H / nTextHeight * 0.9, 100, nFontSize * oBounds.W / nMaxWidth) * 100 >> 0) / 100;
oRun.SetFontSize(nNewFontSize);
oPara.Recalculate_Page(0);

oTextPr.FontSize = nNewFontSize;
oTextPr.FontSizeCS = nNewFontSize;

this.AddToRedraw();
};

CComboBoxField.prototype.WriteToBinary = function(memory) {
// TODO
/*
Expand Down
22 changes: 4 additions & 18 deletions pdf/src/forms/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,23 +418,12 @@
}

if (this.IsMultiline() == false) {
let oRect = this.getFormRelRect();
if (this.GetTextSize() == 0)
this.ProcessAutoFitContent();

let oPara = this.content.GetElement(0);
oPara.Pr.Spacing.Before = 0;
oPara.Pr.Spacing.After = 0;
oPara.CompiledPr.NeedRecalc = true;

this.content.Recalculate_Page(0, true);
let oContentBounds = this.content.GetContentBounds(0);
let oContentH = oContentBounds.Bottom - oContentBounds.Top;

oPara.Pr.Spacing.Before = (oRect.H - oContentH) / 2;
oPara.CompiledPr.NeedRecalc = true;

// // выставляем текст посередине
// let nContentH = this.content.GetElement(0).Get_EmptyHeight();
// contentY = (Y + nHeight / 2) * g_dKoef_pix_to_mm - nContentH / 2;
let nContentH = oContentBounds.Bottom - oContentBounds.Top;
contentY = (Y + nHeight / 2) * g_dKoef_pix_to_mm - nContentH / 2;
}

this._formRect.X = X * g_dKoef_pix_to_mm;
Expand All @@ -460,8 +449,6 @@
});
}

if (this.GetTextSize() == 0)
this.ProcessAutoFitContent();
this.SetNeedRecalc(false);
};

Expand Down Expand Up @@ -700,7 +687,6 @@
if (this._charLimit != 0)
this.content.CheckRunContent(countChars);


// считаем максимум символов для вставки
let nSelChars = this.content.GetSelectedText(true, {NewLine: true}).length;
let nMaxCharsToAdd = Math.min(this._charLimit != 0 ? this._charLimit - (nChars - nSelChars) : aChars.length, aChars.length);
Expand Down
4 changes: 2 additions & 2 deletions pdf/src/viewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -3082,7 +3082,7 @@
this.Api.WordControl.m_oDrawingDocument.TargetEnd();

let nCursorH = g_oTextMeasurer.GetHeight();
if ((oCurPos.X < oFieldBounds.X || oCurPos.Y - nCursorH < oFieldBounds.Y) && oDoc.activeForm._doNotScroll != true)
if ((oCurPos.X < oFieldBounds.X || oCurPos.Y - nCursorH * 0.75 < oFieldBounds.Y) && oDoc.activeForm._doNotScroll != true)
{
oDoc.activeForm.AddToRedraw();
this._paint();
Expand Down Expand Up @@ -3125,7 +3125,7 @@
this.Api.WordControl.m_oDrawingDocument.TargetEnd();

let nCursorH = g_oTextMeasurer.GetHeight();
if (oCurPos.Y - nCursorH < oFieldBounds.Y && oDoc.activeForm._doNotScroll != true)
if (oCurPos.Y - nCursorH * 0.75 < oFieldBounds.Y && oDoc.activeForm._doNotScroll != true)
{
oDoc.activeForm.AddToRedraw();
this._paint();
Expand Down

0 comments on commit a22cf74

Please sign in to comment.