diff --git a/pdf/api.js b/pdf/api.js index b5729dbc71..be1dada1e6 100644 --- a/pdf/api.js +++ b/pdf/api.js @@ -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; }; diff --git a/pdf/src/document.js b/pdf/src/document.js index 864f38a37f..2db0e07ae1 100644 --- a/pdf/src/document.js +++ b/pdf/src/document.js @@ -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()) diff --git a/pdf/src/forms/combobox.js b/pdf/src/forms/combobox.js index 4e47606ac4..0754864efb 100644 --- a/pdf/src/forms/combobox.js +++ b/pdf/src/forms/combobox.js @@ -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(); @@ -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) { @@ -134,6 +141,7 @@ }); } + this.SetNeedRecalc(false); }; @@ -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; }; @@ -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 /* diff --git a/pdf/src/forms/text.js b/pdf/src/forms/text.js index aaaf35d853..66120969fd 100644 --- a/pdf/src/forms/text.js +++ b/pdf/src/forms/text.js @@ -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; @@ -460,8 +449,6 @@ }); } - if (this.GetTextSize() == 0) - this.ProcessAutoFitContent(); this.SetNeedRecalc(false); }; @@ -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); diff --git a/pdf/src/viewer.js b/pdf/src/viewer.js index c3fe5c6adc..d0c2bce1af 100644 --- a/pdf/src/viewer.js +++ b/pdf/src/viewer.js @@ -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(); @@ -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();