diff --git a/itext.tests/itext.forms.tests/itext/forms/PdfChoiceFieldTest.cs b/itext.tests/itext.forms.tests/itext/forms/PdfChoiceFieldTest.cs index 364383b52e..189c503a6a 100644 --- a/itext.tests/itext.forms.tests/itext/forms/PdfChoiceFieldTest.cs +++ b/itext.tests/itext.forms.tests/itext/forms/PdfChoiceFieldTest.cs @@ -270,5 +270,22 @@ public virtual void LongOptionWrappedIntoTwoLinesTest() { NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outFileName, cmpFileName, destinationFolder )); } + + [NUnit.Framework.Test] + public virtual void SetFontSizeChoiceFieldTest() { + String outPdf = destinationFolder + "setFontSizeChoiceField.pdf"; + String cmpPdf = sourceFolder + "cmp_setFontSizeChoiceField.pdf"; + using (PdfDocument doc = new PdfDocument(CompareTool.CreateTestPdfWriter(outPdf))) { + doc.AddNewPage(); + Rectangle rectangle = new Rectangle(150, 500, 200, 150); + PdfChoiceFormField choiceBoxField = new ChoiceFormFieldBuilder(doc, "choiceBox").SetPage(1).SetWidgetRectangle + (rectangle).SetOptions(new String[] { "option1", "option2", "option3" }).CreateList(); + choiceBoxField.SetFontSize(40); + PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(doc, true); + acroForm.AddField(choiceBoxField); + } + NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, destinationFolder, "diff_" + )); + } } } diff --git a/itext.tests/itext.forms.tests/itext/forms/PdfPushButtonTest.cs b/itext.tests/itext.forms.tests/itext/forms/PdfPushButtonTest.cs new file mode 100644 index 0000000000..3aebc2802e --- /dev/null +++ b/itext.tests/itext.forms.tests/itext/forms/PdfPushButtonTest.cs @@ -0,0 +1,62 @@ +/* +This file is part of the iText (R) project. +Copyright (c) 1998-2024 Apryse Group NV +Authors: Apryse Software. + +This program is offered under a commercial and under the AGPL license. +For commercial licensing, contact us at https://itextpdf.com/sales. For AGPL licensing, see below. + +AGPL licensing: +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ +using System; +using iText.Forms.Fields; +using iText.Kernel.Geom; +using iText.Kernel.Pdf; +using iText.Kernel.Utils; +using iText.Test; + +namespace iText.Forms { + [NUnit.Framework.Category("IntegrationTest")] + public class PdfPushButtonTest : ExtendedITextTest { + public static readonly String DESTINATION_FOLDER = NUnit.Framework.TestContext.CurrentContext.TestDirectory + + "/test/itext/forms/PdfPushButtonTest/"; + + public static readonly String SOURCE_FOLDER = iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext + .CurrentContext.TestDirectory) + "/resources/itext/forms/PdfPushButtonTest/"; + + [NUnit.Framework.OneTimeSetUp] + public static void BeforeClass() { + CreateOrClearDestinationFolder(DESTINATION_FOLDER); + } + + [NUnit.Framework.Test] + public virtual void SetFontSizePushButtonWithDisplayTest() { + String outPdf = DESTINATION_FOLDER + "pushButtonWithDisplay.pdf"; + String cmpPdf = SOURCE_FOLDER + "cmp_pushButtonWithDisplay.pdf"; + using (PdfDocument doc = new PdfDocument(CompareTool.CreateTestPdfWriter(outPdf))) { + doc.AddNewPage(); + Rectangle rectangle = new Rectangle(150, 400, 400, 100); + PdfButtonFormField button = new PushButtonFormFieldBuilder(doc, "button").SetWidgetRectangle(rectangle).SetPage + (1).CreatePushButton(); + button.SetFontSize(50); + button.SetValue("value", "some display text"); + PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(doc, true); + acroForm.AddField(button); + } + NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, DESTINATION_FOLDER, "diff_" + )); + } + } +} diff --git a/itext.tests/itext.forms.tests/itext/forms/fields/FieldsRotationTest.cs b/itext.tests/itext.forms.tests/itext/forms/fields/FieldsRotationTest.cs index c3f2863c73..d7cb73df01 100644 --- a/itext.tests/itext.forms.tests/itext/forms/fields/FieldsRotationTest.cs +++ b/itext.tests/itext.forms.tests/itext/forms/fields/FieldsRotationTest.cs @@ -24,6 +24,7 @@ You should have received a copy of the GNU Affero General Public License using System.Collections.Generic; using iText.Commons.Utils; using iText.Forms; +using iText.Forms.Fields.Properties; using iText.Forms.Form.Element; using iText.Kernel.Colors; using iText.Kernel.Geom; @@ -99,6 +100,140 @@ private void FillForm(int[] pageRotation, int[] fieldRotation, bool ignorePageRo } } + [NUnit.Framework.Test] + public virtual void FillRotated90TextFormFieldTest() { + String inPdf = SOURCE_FOLDER + "rotated90TextFormField.pdf"; + String outPdf = DESTINATION_FOLDER + "filledRotated90TextFormField.pdf"; + String cmpPdf = SOURCE_FOLDER + "cmp_filledRotated90TextFormField.pdf"; + using (PdfDocument pdfDoc = new PdfDocument(new PdfReader(inPdf), CompareTool.CreateTestPdfWriter(outPdf)) + ) { + IDictionary fieldValues = new Dictionary(); + fieldValues.Put("textForm", "some text"); + FillAndFlattenForm(pdfDoc, fieldValues); + } + NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, DESTINATION_FOLDER, "diff_" + )); + } + + [NUnit.Framework.Test] + public virtual void FillRotated270TextFormFieldTest() { + String inPdf = SOURCE_FOLDER + "rotated270TextFormField.pdf"; + String outPdf = DESTINATION_FOLDER + "filledRotated270TextFormField.pdf"; + String cmpPdf = SOURCE_FOLDER + "cmp_filledRotated270TextFormField.pdf"; + using (PdfDocument pdfDoc = new PdfDocument(new PdfReader(inPdf), CompareTool.CreateTestPdfWriter(outPdf)) + ) { + IDictionary fieldValues = new Dictionary(); + fieldValues.Put("textForm", "some text"); + FillAndFlattenForm(pdfDoc, fieldValues); + } + NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, DESTINATION_FOLDER, "diff_" + )); + } + + [NUnit.Framework.Test] + public virtual void RotatedButtonWithDisplayValueTest() { + String outPdf = DESTINATION_FOLDER + "rotatedButtonWithDisplayValue.pdf"; + String cmpPdf = SOURCE_FOLDER + "cmp_rotatedButtonWithDisplayValue.pdf"; + using (PdfDocument doc = new PdfDocument(CompareTool.CreateTestPdfWriter(outPdf))) { + doc.AddNewPage(); + Rectangle rectangle = new Rectangle(150, 300, 150, 400); + PdfDictionary chars = new PdfDictionary(); + chars.Put(PdfName.R, new PdfNumber(90)); + PdfButtonFormField button = new PushButtonFormFieldBuilder(doc, "button").SetWidgetRectangle(rectangle).SetPage + (1).CreatePushButton(); + button.GetWidgets()[0].SetAppearanceCharacteristics(chars); + button.SetFontSize(0); + button.SetValue("value", "this text should take all space"); + PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(doc, true); + acroForm.AddField(button); + } + NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, DESTINATION_FOLDER, "diff_" + )); + } + + [NUnit.Framework.Test] + public virtual void RotatedCheckBoxTest() { + String outPdf = DESTINATION_FOLDER + "rotatedCheckBox.pdf"; + String cmpPdf = SOURCE_FOLDER + "cmp_rotatedCheckBox.pdf"; + using (PdfDocument doc = new PdfDocument(CompareTool.CreateTestPdfWriter(outPdf))) { + doc.AddNewPage(); + PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(doc, true); + PdfDictionary chars = new PdfDictionary(); + chars.Put(PdfName.R, new PdfNumber(90)); + Rectangle rectangle1 = new Rectangle(0, 300, 100, 100); + PdfButtonFormField box1 = new CheckBoxFormFieldBuilder(doc, "checkBox1").SetPage(1).SetWidgetRectangle(rectangle1 + ).CreateCheckBox(); + box1.GetWidgets()[0].SetAppearanceCharacteristics(chars); + box1.SetCheckType(CheckBoxType.CHECK); + box1.SetValue("ON"); + box1.SetFontSize(0); + acroForm.AddField(box1); + Rectangle rectangle2 = new Rectangle(100, 300, 100, 100); + PdfButtonFormField box2 = new CheckBoxFormFieldBuilder(doc, "checkBox2").SetPage(1).SetWidgetRectangle(rectangle2 + ).CreateCheckBox(); + box2.GetWidgets()[0].SetAppearanceCharacteristics(chars); + box2.SetCheckType(CheckBoxType.STAR); + box2.SetValue("ON"); + box2.SetFontSize(0); + acroForm.AddField(box2); + } + NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, DESTINATION_FOLDER, "diff_" + )); + } + + [NUnit.Framework.Test] + public virtual void RotatedChoiceBoxTest() { + String outPdf = DESTINATION_FOLDER + "rotatedChoiceBox.pdf"; + String cmpPdf = SOURCE_FOLDER + "cmp_rotatedChoiceBox.pdf"; + using (PdfDocument doc = new PdfDocument(CompareTool.CreateTestPdfWriter(outPdf))) { + doc.AddNewPage(); + Rectangle rectangle = new Rectangle(150, 500, 200, 150); + PdfDictionary chars = new PdfDictionary(); + chars.Put(PdfName.R, new PdfNumber(90)); + PdfChoiceFormField choiceBoxField = new ChoiceFormFieldBuilder(doc, "choiceBox").SetPage(1).SetWidgetRectangle + (rectangle).SetOptions(new String[] { "option1", "option2", "option3", "option4", "option5" }).CreateList + (); + choiceBoxField.GetWidgets()[0].SetAppearanceCharacteristics(chars); + choiceBoxField.SetFontSize(0); + PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(doc, true); + acroForm.AddField(choiceBoxField); + } + NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, DESTINATION_FOLDER, "diff_" + )); + } + + [NUnit.Framework.Test] + public virtual void RotatedComboBoxTest() { + String outPdf = DESTINATION_FOLDER + "rotatedComboBox.pdf"; + String cmpPdf = SOURCE_FOLDER + "cmp_rotatedComboBox.pdf"; + using (PdfDocument doc = new PdfDocument(CompareTool.CreateTestPdfWriter(outPdf))) { + doc.AddNewPage(); + Rectangle rectangle = new Rectangle(150, 500, 75, 150); + PdfDictionary chars = new PdfDictionary(); + chars.Put(PdfName.R, new PdfNumber(90)); + PdfChoiceFormField choiceBoxField = new ChoiceFormFieldBuilder(doc, "choiceBox").SetPage(1).SetWidgetRectangle + (rectangle).SetOptions(new String[] { "option1", "option2", "longOption", "option3", "option4", "option5" + }).CreateComboBox(); + choiceBoxField.GetWidgets()[0].SetAppearanceCharacteristics(chars); + choiceBoxField.SetValue("option1", true); + choiceBoxField.SetFontSize(0); + PdfAcroForm acroForm = PdfAcroForm.GetAcroForm(doc, true); + acroForm.AddField(choiceBoxField); + } + NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, DESTINATION_FOLDER, "diff_" + )); + } + + private static void FillAndFlattenForm(PdfDocument document, IDictionary fields) { + PdfAcroForm form = PdfAcroForm.GetAcroForm(document, true); + form.SetNeedAppearances(true); + foreach (KeyValuePair field in fields) { + PdfFormField acroField = form.GetField(field.Key); + acroField.SetValue(field.Value); + } + form.FlattenFields(); + } + private String GenerateCaption(int pageRotation, int fieldRotation) { String caption = ", page rotation: " + pageRotation + ", field rotation: " + fieldRotation; for (int i = 0; i < 3; ++i) { diff --git a/itext.tests/itext.forms.tests/resources/itext/forms/PdfChoiceFieldTest/cmp_setFontSizeChoiceField.pdf b/itext.tests/itext.forms.tests/resources/itext/forms/PdfChoiceFieldTest/cmp_setFontSizeChoiceField.pdf new file mode 100644 index 0000000000..9c534de5dc Binary files /dev/null and b/itext.tests/itext.forms.tests/resources/itext/forms/PdfChoiceFieldTest/cmp_setFontSizeChoiceField.pdf differ diff --git a/itext.tests/itext.forms.tests/resources/itext/forms/PdfFormFieldTest/cmp_choiceFieldAutoSize01Test.pdf b/itext.tests/itext.forms.tests/resources/itext/forms/PdfFormFieldTest/cmp_choiceFieldAutoSize01Test.pdf index 9f66295c44..565aed3477 100644 Binary files a/itext.tests/itext.forms.tests/resources/itext/forms/PdfFormFieldTest/cmp_choiceFieldAutoSize01Test.pdf and b/itext.tests/itext.forms.tests/resources/itext/forms/PdfFormFieldTest/cmp_choiceFieldAutoSize01Test.pdf differ diff --git a/itext.tests/itext.forms.tests/resources/itext/forms/PdfPushButtonTest/cmp_pushButtonWithDisplay.pdf b/itext.tests/itext.forms.tests/resources/itext/forms/PdfPushButtonTest/cmp_pushButtonWithDisplay.pdf new file mode 100644 index 0000000000..8b48f5a0d2 Binary files /dev/null and b/itext.tests/itext.forms.tests/resources/itext/forms/PdfPushButtonTest/cmp_pushButtonWithDisplay.pdf differ diff --git a/itext.tests/itext.forms.tests/resources/itext/forms/XfdfReaderTest/cmp_xfdfCheckBox.pdf b/itext.tests/itext.forms.tests/resources/itext/forms/XfdfReaderTest/cmp_xfdfCheckBox.pdf index be6edb7fa6..cb07c6bd16 100644 Binary files a/itext.tests/itext.forms.tests/resources/itext/forms/XfdfReaderTest/cmp_xfdfCheckBox.pdf and b/itext.tests/itext.forms.tests/resources/itext/forms/XfdfReaderTest/cmp_xfdfCheckBox.pdf differ diff --git a/itext.tests/itext.forms.tests/resources/itext/forms/fields/FieldsRotationTest/cmp_filledRotated270TextFormField.pdf b/itext.tests/itext.forms.tests/resources/itext/forms/fields/FieldsRotationTest/cmp_filledRotated270TextFormField.pdf new file mode 100644 index 0000000000..a810b96477 Binary files /dev/null and b/itext.tests/itext.forms.tests/resources/itext/forms/fields/FieldsRotationTest/cmp_filledRotated270TextFormField.pdf differ diff --git a/itext.tests/itext.forms.tests/resources/itext/forms/fields/FieldsRotationTest/cmp_filledRotated90TextFormField.pdf b/itext.tests/itext.forms.tests/resources/itext/forms/fields/FieldsRotationTest/cmp_filledRotated90TextFormField.pdf new file mode 100644 index 0000000000..665851a2de Binary files /dev/null and b/itext.tests/itext.forms.tests/resources/itext/forms/fields/FieldsRotationTest/cmp_filledRotated90TextFormField.pdf differ diff --git a/itext.tests/itext.forms.tests/resources/itext/forms/fields/FieldsRotationTest/cmp_rotatedButtonWithDisplayValue.pdf b/itext.tests/itext.forms.tests/resources/itext/forms/fields/FieldsRotationTest/cmp_rotatedButtonWithDisplayValue.pdf new file mode 100644 index 0000000000..906197c291 Binary files /dev/null and b/itext.tests/itext.forms.tests/resources/itext/forms/fields/FieldsRotationTest/cmp_rotatedButtonWithDisplayValue.pdf differ diff --git a/itext.tests/itext.forms.tests/resources/itext/forms/fields/FieldsRotationTest/cmp_rotatedCheckBox.pdf b/itext.tests/itext.forms.tests/resources/itext/forms/fields/FieldsRotationTest/cmp_rotatedCheckBox.pdf new file mode 100644 index 0000000000..ac39977b26 Binary files /dev/null and b/itext.tests/itext.forms.tests/resources/itext/forms/fields/FieldsRotationTest/cmp_rotatedCheckBox.pdf differ diff --git a/itext.tests/itext.forms.tests/resources/itext/forms/fields/FieldsRotationTest/cmp_rotatedChoiceBox.pdf b/itext.tests/itext.forms.tests/resources/itext/forms/fields/FieldsRotationTest/cmp_rotatedChoiceBox.pdf new file mode 100644 index 0000000000..6cfe1d69d9 Binary files /dev/null and b/itext.tests/itext.forms.tests/resources/itext/forms/fields/FieldsRotationTest/cmp_rotatedChoiceBox.pdf differ diff --git a/itext.tests/itext.forms.tests/resources/itext/forms/fields/FieldsRotationTest/cmp_rotatedComboBox.pdf b/itext.tests/itext.forms.tests/resources/itext/forms/fields/FieldsRotationTest/cmp_rotatedComboBox.pdf new file mode 100644 index 0000000000..022187f85e Binary files /dev/null and b/itext.tests/itext.forms.tests/resources/itext/forms/fields/FieldsRotationTest/cmp_rotatedComboBox.pdf differ diff --git a/itext.tests/itext.forms.tests/resources/itext/forms/fields/FieldsRotationTest/rotated270TextFormField.pdf b/itext.tests/itext.forms.tests/resources/itext/forms/fields/FieldsRotationTest/rotated270TextFormField.pdf new file mode 100644 index 0000000000..0c3e346b20 Binary files /dev/null and b/itext.tests/itext.forms.tests/resources/itext/forms/fields/FieldsRotationTest/rotated270TextFormField.pdf differ diff --git a/itext.tests/itext.forms.tests/resources/itext/forms/fields/FieldsRotationTest/rotated90TextFormField.pdf b/itext.tests/itext.forms.tests/resources/itext/forms/fields/FieldsRotationTest/rotated90TextFormField.pdf new file mode 100644 index 0000000000..6c8ea3e1e9 Binary files /dev/null and b/itext.tests/itext.forms.tests/resources/itext/forms/fields/FieldsRotationTest/rotated90TextFormField.pdf differ diff --git a/itext/itext.forms/itext/forms/fields/PdfFormAnnotation.cs b/itext/itext.forms/itext/forms/fields/PdfFormAnnotation.cs index 7ae69cf250..c9f3aec820 100644 --- a/itext/itext.forms/itext/forms/fields/PdfFormAnnotation.cs +++ b/itext/itext.forms/itext/forms/fields/PdfFormAnnotation.cs @@ -658,13 +658,16 @@ protected internal virtual void DrawPushButtonFieldAndSaveAppearance() { if (rectangle == null) { return; } + //Apply rotation int fieldRotation = GetRotation(); PdfArray matrix = GetRotationMatrix(fieldRotation, rectangle.GetHeight(), rectangle.GetWidth()); rectangle = ApplyRotation(fieldRotation, rectangle); - float width = rectangle.GetWidth(); - float height = rectangle.GetHeight(); CreateInputButton(); SetModelElementProperties(rectangle); + float fontSize = GetFontSize(new PdfArray(rectangle), parent.GetDisplayValue()); + formFieldElement.SetProperty(Property.FONT_SIZE, UnitValue.CreatePointValue(fontSize)); + float width = rectangle.GetWidth(); + float height = rectangle.GetHeight(); PdfFormXObject xObject = new PdfFormXObject(new Rectangle(0, 0, width, height)); if (matrix != null) { xObject.Put(PdfName.Matrix, matrix); @@ -805,6 +808,10 @@ protected internal virtual void DrawListFormFieldAndSaveAppearance() { if (rectangle == null) { return; } + //Apply rotation + int fieldRotation = GetRotation(); + PdfArray matrix = GetRotationMatrix(fieldRotation, rectangle.GetHeight(), rectangle.GetWidth()); + rectangle = ApplyRotation(fieldRotation, rectangle); bool multiselect = parent.GetFieldFlag(PdfChoiceFormField.FF_MULTI_SELECT); if (!(formFieldElement is ListBoxField)) { // Create it once and reset properties during each widget regeneration. @@ -815,12 +822,16 @@ protected internal virtual void DrawListFormFieldAndSaveAppearance() { GetTopIndex() != null ? ((PdfChoiceFormField)parent).GetTopIndex().IntValue() : 0); PdfArray indices = GetParent().GetAsArray(PdfName.I); PdfArray options = parent.GetOptions(); + String longestOption = ""; for (int index = 0; index < options.Size(); ++index) { PdfObject option = options.Get(index); String exportValue = null; String displayValue = null; if (option.IsString()) { exportValue = option.ToString(); + if (longestOption.Length < exportValue.Length) { + longestOption = exportValue; + } } else { if (option.IsArray()) { @@ -828,6 +839,9 @@ protected internal virtual void DrawListFormFieldAndSaveAppearance() { if (optionArray.Size() > 1) { exportValue = optionArray.Get(0).ToString(); displayValue = optionArray.Get(1).ToString(); + if (longestOption.Length < displayValue.Length) { + longestOption = displayValue; + } } } } @@ -857,6 +871,9 @@ protected internal virtual void DrawListFormFieldAndSaveAppearance() { existingItem.GetElement().SetProperty(Property.BACKGROUND, null); } } + float fontSize = GetFontSize(new PdfArray(rectangle), longestOption); + formFieldElement.SetProperty(Property.FONT_SIZE, UnitValue.CreatePointValue(fontSize)); + UpdateParentFontSize(fontSize); formFieldElement.SetProperty(Property.FONT, GetFont()); if (GetColor() != null) { formFieldElement.SetProperty(Property.FONT_COLOR, new TransparentColor(GetColor())); @@ -864,6 +881,9 @@ protected internal virtual void DrawListFormFieldAndSaveAppearance() { SetModelElementProperties(rectangle); PdfFormXObject xObject = new PdfFormXObject(new Rectangle(0, 0, rectangle.GetWidth(), rectangle.GetHeight( ))); + if (matrix != null) { + xObject.Put(PdfName.Matrix, matrix); + } iText.Layout.Canvas canvas = new iText.Layout.Canvas(xObject, this.GetDocument()); SetMetaInfoToCanvas(canvas); canvas.SetProperty(Property.APPEARANCE_STREAM_LAYOUT, true); @@ -880,6 +900,10 @@ protected internal virtual void DrawTextFormFieldAndSaveAppearance() { if (rectangle == null) { return; } + //Apply rotation + int fieldRotation = GetRotation(); + PdfArray matrix = GetRotationMatrix(fieldRotation, rectangle.GetHeight(), rectangle.GetWidth()); + rectangle = ApplyRotation(fieldRotation, rectangle); String value = parent.GetDisplayValue(); if (!(parent.IsMultiline() && formFieldElement is TextArea || !parent.IsMultiline() && formFieldElement is InputField)) { @@ -911,10 +935,6 @@ protected internal virtual void DrawTextFormFieldAndSaveAppearance() { if (GetColor() != null) { formFieldElement.SetProperty(Property.FONT_COLOR, new TransparentColor(GetColor())); } - // Rotation - int fieldRotation = GetRotation(); - PdfArray matrix = GetRotationMatrix(fieldRotation, rectangle.GetHeight(), rectangle.GetWidth()); - rectangle = ApplyRotation(fieldRotation, rectangle); SetModelElementProperties(rectangle); PdfFormXObject xObject = new PdfFormXObject(new Rectangle(0, 0, rectangle.GetWidth(), rectangle.GetHeight( ))); @@ -938,6 +958,10 @@ protected internal virtual void DrawComboBoxAndSaveAppearance() { if (!(formFieldElement is ComboBoxField)) { formFieldElement = new ComboBoxField(parent.GetPartialFieldName().ToUnicodeString()); } + //Apply rotation + int fieldRotation = GetRotation(); + PdfArray matrix = GetRotationMatrix(fieldRotation, rectangle.GetHeight(), rectangle.GetWidth()); + rectangle = ApplyRotation(fieldRotation, rectangle); ComboBoxField comboBoxField = (ComboBoxField)formFieldElement; PrepareComboBoxFieldWithCorrectOptionsAndValues(comboBoxField); comboBoxField.SetFont(GetFont()); @@ -960,6 +984,9 @@ protected internal virtual void DrawComboBoxAndSaveAppearance() { comboBoxField.SetTextAlignment(parent.GetJustification()); Rectangle pdfXobjectRectangle = new Rectangle(0, 0, rectangle.GetWidth(), rectangle.GetHeight()); PdfFormXObject xObject = new PdfFormXObject(pdfXobjectRectangle); + if (matrix != null) { + xObject.Put(PdfName.Matrix, matrix); + } iText.Layout.Canvas canvas = new iText.Layout.Canvas(xObject, GetDocument()); canvas.SetProperty(Property.APPEARANCE_STREAM_LAYOUT, true); SetMetaInfoToCanvas(canvas); @@ -1001,12 +1028,20 @@ protected internal virtual void DrawCheckBoxAndSaveAppearance(String onStateName if (rect == null) { return; } + //Apply rotation + int fieldRotation = GetRotation(); + PdfArray matrix = GetRotationMatrix(fieldRotation, rect.GetHeight(), rect.GetWidth()); + rect = ApplyRotation(fieldRotation, rect); ReconstructCheckBoxType(); CreateCheckBox(); + SetModelElementProperties(rect); bool wasChecked = true.Equals(formFieldElement.GetProperty(FormProperty.FORM_FIELD_CHECKED)); PdfDictionary normalAppearance = new PdfDictionary(); ((CheckBox)formFieldElement).SetChecked(false); PdfFormXObject xObjectOff = new PdfFormXObject(new Rectangle(0, 0, rect.GetWidth(), rect.GetHeight())); + if (matrix != null) { + xObjectOff.Put(PdfName.Matrix, matrix); + } iText.Layout.Canvas canvasOff = new iText.Layout.Canvas(xObjectOff, GetDocument()); SetMetaInfoToCanvas(canvasOff); canvasOff.Add(formFieldElement); @@ -1021,6 +1056,9 @@ protected internal virtual void DrawCheckBoxAndSaveAppearance(String onStateName } ((CheckBox)formFieldElement).SetChecked(true); PdfFormXObject xObject = new PdfFormXObject(new Rectangle(0, 0, rect.GetWidth(), rect.GetHeight())); + if (matrix != null) { + xObject.Put(PdfName.Matrix, matrix); + } iText.Layout.Canvas canvas = new iText.Layout.Canvas(xObject, this.GetDocument()); SetMetaInfoToCanvas(canvas); canvas.Add(formFieldElement); @@ -1031,6 +1069,9 @@ protected internal virtual void DrawCheckBoxAndSaveAppearance(String onStateName // to retrieve the checkbox type even if the appearance is not present. mk.Put(PdfName.CA, new PdfString(PdfCheckBoxRenderingStrategy.ZAPFDINGBATS_CHECKBOX_MAPPING.GetByKey(parent .checkType.GetValue()))); + if (fieldRotation != 0) { + mk.Put(PdfName.R, new PdfNumber(fieldRotation)); + } GetWidget().Put(PdfName.MK, mk); formFieldElement.SetInteractive(true); ((CheckBox)formFieldElement).SetChecked(wasChecked); @@ -1118,8 +1159,6 @@ internal virtual void CreateInputButton() { formFieldElement = new Button(parent.GetPartialFieldName().ToUnicodeString()); } ((Button)formFieldElement).SetFont(GetFont()); - ((Button)formFieldElement).SetFontSize(GetFontSize(GetPdfObject().GetAsArray(PdfName.Rect), parent.GetDisplayValue - ())); if (GetColor() != null) { ((Button)formFieldElement).SetFontColor(color); } @@ -1239,7 +1278,6 @@ private void CreateCheckBox() { formFieldElement = new CheckBox(""); } formFieldElement.SetProperty(Property.FONT_SIZE, UnitValue.CreatePointValue(GetFontSize())); - SetModelElementProperties(GetRect(GetPdfObject())); ((CheckBox)formFieldElement).SetPdfConformance(GetPdfConformance()); ((CheckBox)formFieldElement).SetCheckBoxType(parent.checkType.GetValue()); } @@ -1480,5 +1518,12 @@ private Rectangle ApplyRotation(int fieldRotation, Rectangle rectangle) { } return rectangle; } + + private void UpdateParentFontSize(float fontSize) { + if (parent != null) { + parent.UpdateFontAndFontSize(parent.GetFont(), fontSize); + parent.UpdateDefaultAppearance(); + } + } } } diff --git a/port-hash b/port-hash index e018d37b82..f77132cd6c 100644 --- a/port-hash +++ b/port-hash @@ -1 +1 @@ -40d73e9d7d6d3a88afc6d27275c504597b8a8c4e +6799b9f8eba4ba1c8c7d6398674d44ee972e39b2