From 94e9682e651f2ebc4c2edcbe37d3d77a6137cc40 Mon Sep 17 00:00:00 2001 From: Fabrice Wieser Date: Mon, 3 Jul 2023 15:41:29 +0200 Subject: [PATCH] Extends the functionality of radio buttons with another type of check Colored background, border and check possible. Printable check mark RadioTest extended. Test is also template. --- .cr/personal/FavoritesList/List.xml | 6 + iTextCore.sln | 83 ++++++----- .../itext/forms/form/element/RadioTest.cs | 133 ++++++++++++++++++ .../cmp_radioButtonCheckTypeCheck.pdf | Bin 0 -> 2762 bytes .../cmp_radioButtonCheckTypeSquare.pdf | Bin 0 -> 2690 bytes ...radioButtonCheckTypeSquare_NoSelection.pdf | Bin 0 -> 2690 bytes ...p_radioButtonCheckTypeStar_NoSelection.pdf | Bin 0 -> 2751 bytes .../itext/forms/fields/PdfFormAnnotation.cs | 44 +++++- .../forms/fields/RadioFormFieldBuilder.cs | 19 +++ .../itext/forms/form/element/Radio.cs | 53 ++++++- .../forms/form/renderer/RadioRenderer.cs | 113 ++++++++++++++- .../itext/forms/util/DrawingUtil.cs | 125 ++++++++++++++++ 12 files changed, 521 insertions(+), 55 deletions(-) create mode 100644 .cr/personal/FavoritesList/List.xml create mode 100644 itext.tests/itext.forms.tests/resources/itext/forms/form/element/RadioTest/cmp_radioButtonCheckTypeCheck.pdf create mode 100644 itext.tests/itext.forms.tests/resources/itext/forms/form/element/RadioTest/cmp_radioButtonCheckTypeSquare.pdf create mode 100644 itext.tests/itext.forms.tests/resources/itext/forms/form/element/RadioTest/cmp_radioButtonCheckTypeSquare_NoSelection.pdf create mode 100644 itext.tests/itext.forms.tests/resources/itext/forms/form/element/RadioTest/cmp_radioButtonCheckTypeStar_NoSelection.pdf diff --git a/.cr/personal/FavoritesList/List.xml b/.cr/personal/FavoritesList/List.xml new file mode 100644 index 0000000000..a60e5ed6c7 --- /dev/null +++ b/.cr/personal/FavoritesList/List.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/iTextCore.sln b/iTextCore.sln index 59f42ac0b2..62abcf51cd 100644 --- a/iTextCore.sln +++ b/iTextCore.sln @@ -1,61 +1,60 @@ - Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.26430.15 +# Visual Studio Version 17 +VisualStudioVersion = 17.6.33815.320 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "itext.io.netstandard", "itext\itext.io\itext.io.csproj", "{4C4C74D4-00E2-43A4-9D7A-54352096DE32}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "itext.io", "itext\itext.io\itext.io.csproj", "{4C4C74D4-00E2-43A4-9D7A-54352096DE32}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "itext.pdftest.netstandard", "itext\itext.pdftest\itext.pdftest.csproj", "{9BE8BB63-8A73-4348-9387-F47377B9F1BF}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "itext.pdftest", "itext\itext.pdftest\itext.pdftest.csproj", "{9BE8BB63-8A73-4348-9387-F47377B9F1BF}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "itext.io.tests.netstandard", "itext.tests\itext.io.tests\itext.io.tests.csproj", "{DC025E65-67E8-47BD-B135-1B71C05EE35E}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "itext.io.tests", "itext.tests\itext.io.tests\itext.io.tests.csproj", "{DC025E65-67E8-47BD-B135-1B71C05EE35E}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "itext.kernel.netstandard", "itext\itext.kernel\itext.kernel.csproj", "{76166842-A194-43B3-B5C0-4C78B845DABA}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "itext.kernel", "itext\itext.kernel\itext.kernel.csproj", "{76166842-A194-43B3-B5C0-4C78B845DABA}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "itext.kernel.tests.netstandard", "itext.tests\itext.kernel.tests\itext.kernel.tests.csproj", "{9EB233B4-5821-49DC-959E-F7BBA3D6DEB0}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "itext.kernel.tests", "itext.tests\itext.kernel.tests\itext.kernel.tests.csproj", "{9EB233B4-5821-49DC-959E-F7BBA3D6DEB0}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "itext.layout.netstandard", "itext\itext.layout\itext.layout.csproj", "{7CACC13D-D87F-4AE3-9B07-6B94F1798AE8}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "itext.layout", "itext\itext.layout\itext.layout.csproj", "{7CACC13D-D87F-4AE3-9B07-6B94F1798AE8}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "itext.pdfa.netstandard", "itext\itext.pdfa\itext.pdfa.csproj", "{6BF0A6C3-8982-4507-B704-C0878243B322}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "itext.pdfa", "itext\itext.pdfa\itext.pdfa.csproj", "{6BF0A6C3-8982-4507-B704-C0878243B322}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "itext.forms.netstandard", "itext\itext.forms\itext.forms.csproj", "{22FE2361-9580-43BC-98A7-608CFCAE4E8F}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "itext.forms", "itext\itext.forms\itext.forms.csproj", "{22FE2361-9580-43BC-98A7-608CFCAE4E8F}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "itext.barcodes.netstandard", "itext\itext.barcodes\itext.barcodes.csproj", "{ED4A03D3-DFC7-4760-9066-D01D4134627D}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "itext.barcodes", "itext\itext.barcodes\itext.barcodes.csproj", "{ED4A03D3-DFC7-4760-9066-D01D4134627D}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "itext.font-asian.netstandard", "itext\itext.font-asian\itext.font-asian.csproj", "{C3D759CE-C105-4566-A125-FBD77CFC7A82}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "itext.font-asian", "itext\itext.font-asian\itext.font-asian.csproj", "{C3D759CE-C105-4566-A125-FBD77CFC7A82}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "itext.hyph.netstandard", "itext\itext.hyph\itext.hyph.csproj", "{9AB67CFB-6695-4769-8E21-9BA0A12BD67C}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "itext.hyph", "itext\itext.hyph\itext.hyph.csproj", "{9AB67CFB-6695-4769-8E21-9BA0A12BD67C}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "itext.sign.netstandard", "itext\itext.sign\itext.sign.csproj", "{F284CE2A-821F-4B04-8CE3-558DAC5F8674}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "itext.sign", "itext\itext.sign\itext.sign.csproj", "{F284CE2A-821F-4B04-8CE3-558DAC5F8674}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "itext.barcodes.tests.netstandard", "itext.tests\itext.barcodes.tests\itext.barcodes.tests.csproj", "{4BB4B5FD-1EE1-4558-B126-E9E18BC45876}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "itext.barcodes.tests", "itext.tests\itext.barcodes.tests\itext.barcodes.tests.csproj", "{4BB4B5FD-1EE1-4558-B126-E9E18BC45876}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "itext.forms.tests.netstandard", "itext.tests\itext.forms.tests\itext.forms.tests.csproj", "{732D6882-40DF-41CB-8A18-ED43D4757177}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "itext.forms.tests", "itext.tests\itext.forms.tests\itext.forms.tests.csproj", "{732D6882-40DF-41CB-8A18-ED43D4757177}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "itext.layout.tests.netstandard", "itext.tests\itext.layout.tests\itext.layout.tests.csproj", "{620C13EC-D9B8-4F49-B536-5DD7E08B3984}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "itext.layout.tests", "itext.tests\itext.layout.tests\itext.layout.tests.csproj", "{620C13EC-D9B8-4F49-B536-5DD7E08B3984}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "itext.pdfa.tests.netstandard", "itext.tests\itext.pdfa.tests\itext.pdfa.tests.csproj", "{BA6474C1-E64B-4522-8D8B-A7AE10D2ED86}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "itext.pdfa.tests", "itext.tests\itext.pdfa.tests\itext.pdfa.tests.csproj", "{BA6474C1-E64B-4522-8D8B-A7AE10D2ED86}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "itext.sign.tests.netstandard", "itext.tests\itext.sign.tests\itext.sign.tests.csproj", "{22C91DB4-51CD-4339-B904-E5FE38B271CD}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "itext.sign.tests", "itext.tests\itext.sign.tests\itext.sign.tests.csproj", "{22C91DB4-51CD-4339-B904-E5FE38B271CD}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "itext.styledxmlparser.netstandard", "itext\itext.styledxmlparser\itext.styledxmlparser.csproj", "{6894C148-5379-4D63-AC21-D67BD04AA064}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "itext.styledxmlparser", "itext\itext.styledxmlparser\itext.styledxmlparser.csproj", "{6894C148-5379-4D63-AC21-D67BD04AA064}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "itext.styledxmlparser.tests.netstandard", "itext.tests\itext.styledxmlparser.tests\itext.styledxmlparser.tests.csproj", "{2785E385-0940-4023-9868-8CDD25998176}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "itext.styledxmlparser.tests", "itext.tests\itext.styledxmlparser.tests\itext.styledxmlparser.tests.csproj", "{2785E385-0940-4023-9868-8CDD25998176}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "itext.svg.netstandard", "itext\itext.svg\itext.svg.csproj", "{8D69BA6B-D165-45C1-B144-F187B72850B9}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "itext.svg", "itext\itext.svg\itext.svg.csproj", "{8D69BA6B-D165-45C1-B144-F187B72850B9}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "itext.svg.tests.netstandard", "itext.tests\itext.svg.tests\itext.svg.tests.csproj", "{9F61F451-EC4F-4D1A-B339-CEDD5FA4257C}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "itext.svg.tests", "itext.tests\itext.svg.tests\itext.svg.tests.csproj", "{9F61F451-EC4F-4D1A-B339-CEDD5FA4257C}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "itext.pdftest.tests.netstandard", "itext.tests\itext.pdftest.tests\itext.pdftest.tests.csproj", "{46C393D2-BFAB-473A-AF06-E5FB586493FD}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "itext.pdftest.tests", "itext.tests\itext.pdftest.tests\itext.pdftest.tests.csproj", "{46C393D2-BFAB-473A-AF06-E5FB586493FD}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "itext.commons.netstandard", "itext\itext.commons\itext.commons.csproj", "{6DBE9C11-7C0D-4039-B8B1-01AC743D5309}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "itext.commons", "itext\itext.commons\itext.commons.csproj", "{6DBE9C11-7C0D-4039-B8B1-01AC743D5309}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "itext.commons.tests.netstandard", "itext.tests\itext.commons.tests\itext.commons.tests.csproj", "{726AEDB2-0B0D-45B8-A744-BFFEE36A187E}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "itext.commons.tests", "itext.tests\itext.commons.tests\itext.commons.tests.csproj", "{726AEDB2-0B0D-45B8-A744-BFFEE36A187E}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "itext.bouncy-castle-adapter.netstandard", "itext\itext.bouncy-castle-adapter\itext.bouncy-castle-adapter.csproj", "{3A5D9DAC-A654-4542-8114-1D5B2F153D69}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "itext.bouncy-castle-adapter", "itext\itext.bouncy-castle-adapter\itext.bouncy-castle-adapter.csproj", "{3A5D9DAC-A654-4542-8114-1D5B2F153D69}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "itext.bouncy-castle-fips-adapter.netstandard", "itext\itext.bouncy-castle-fips-adapter\itext.bouncy-castle-fips-adapter.csproj", "{3B634E19-5522-4907-8EE4-3FB017A4FC86}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "itext.bouncy-castle-fips-adapter", "itext\itext.bouncy-castle-fips-adapter\itext.bouncy-castle-fips-adapter.csproj", "{3B634E19-5522-4907-8EE4-3FB017A4FC86}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "itext.bouncy-castle-connector.netstandard", "itext\itext.bouncy-castle-connector\itext.bouncy-castle-connector.csproj", "{C68E3329-A2E4-4B33-BADE-0521B8E832AD}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "itext.bouncy-castle-connector", "itext\itext.bouncy-castle-connector\itext.bouncy-castle-connector.csproj", "{C68E3329-A2E4-4B33-BADE-0521B8E832AD}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -355,18 +354,6 @@ Global {726AEDB2-0B0D-45B8-A744-BFFEE36A187E}.Release|x64.Build.0 = Release|Any CPU {726AEDB2-0B0D-45B8-A744-BFFEE36A187E}.Release|x86.ActiveCfg = Release|Any CPU {726AEDB2-0B0D-45B8-A744-BFFEE36A187E}.Release|x86.Build.0 = Release|Any CPU - {3B634E19-5522-4907-8EE4-3FB017A4FC86}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {3B634E19-5522-4907-8EE4-3FB017A4FC86}.Debug|Any CPU.Build.0 = Debug|Any CPU - {3B634E19-5522-4907-8EE4-3FB017A4FC86}.Debug|x64.ActiveCfg = Debug|Any CPU - {3B634E19-5522-4907-8EE4-3FB017A4FC86}.Debug|x64.Build.0 = Debug|Any CPU - {3B634E19-5522-4907-8EE4-3FB017A4FC86E}.Debug|x86.ActiveCfg = Debug|Any CPU - {3B634E19-5522-4907-8EE4-3FB017A4FC86}.Debug|x86.Build.0 = Debug|Any CPU - {3B634E19-5522-4907-8EE4-3FB017A4FC86}.Release|Any CPU.ActiveCfg = Release|Any CPU - {3B634E19-5522-4907-8EE4-3FB017A4FC86}.Release|Any CPU.Build.0 = Release|Any CPU - {3B634E19-5522-4907-8EE4-3FB017A4FC86}.Release|x64.ActiveCfg = Release|Any CPU - {3B634E19-5522-4907-8EE4-3FB017A4FC86}.Release|x64.Build.0 = Release|Any CPU - {3B634E19-5522-4907-8EE4-3FB017A4FC86}.Release|x86.ActiveCfg = Release|Any CPU - {3B634E19-5522-4907-8EE4-3FB017A4FC86}.Release|x86.Build.0 = Release|Any CPU {3A5D9DAC-A654-4542-8114-1D5B2F153D69}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {3A5D9DAC-A654-4542-8114-1D5B2F153D69}.Debug|Any CPU.Build.0 = Debug|Any CPU {3A5D9DAC-A654-4542-8114-1D5B2F153D69}.Debug|x64.ActiveCfg = Debug|Any CPU @@ -379,6 +366,18 @@ Global {3A5D9DAC-A654-4542-8114-1D5B2F153D69}.Release|x64.Build.0 = Release|Any CPU {3A5D9DAC-A654-4542-8114-1D5B2F153D69}.Release|x86.ActiveCfg = Release|Any CPU {3A5D9DAC-A654-4542-8114-1D5B2F153D69}.Release|x86.Build.0 = Release|Any CPU + {3B634E19-5522-4907-8EE4-3FB017A4FC86}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {3B634E19-5522-4907-8EE4-3FB017A4FC86}.Debug|Any CPU.Build.0 = Debug|Any CPU + {3B634E19-5522-4907-8EE4-3FB017A4FC86}.Debug|x64.ActiveCfg = Debug|Any CPU + {3B634E19-5522-4907-8EE4-3FB017A4FC86}.Debug|x64.Build.0 = Debug|Any CPU + {3B634E19-5522-4907-8EE4-3FB017A4FC86}.Debug|x86.ActiveCfg = Debug|Any CPU + {3B634E19-5522-4907-8EE4-3FB017A4FC86}.Debug|x86.Build.0 = Debug|Any CPU + {3B634E19-5522-4907-8EE4-3FB017A4FC86}.Release|Any CPU.ActiveCfg = Release|Any CPU + {3B634E19-5522-4907-8EE4-3FB017A4FC86}.Release|Any CPU.Build.0 = Release|Any CPU + {3B634E19-5522-4907-8EE4-3FB017A4FC86}.Release|x64.ActiveCfg = Release|Any CPU + {3B634E19-5522-4907-8EE4-3FB017A4FC86}.Release|x64.Build.0 = Release|Any CPU + {3B634E19-5522-4907-8EE4-3FB017A4FC86}.Release|x86.ActiveCfg = Release|Any CPU + {3B634E19-5522-4907-8EE4-3FB017A4FC86}.Release|x86.Build.0 = Release|Any CPU {C68E3329-A2E4-4B33-BADE-0521B8E832AD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {C68E3329-A2E4-4B33-BADE-0521B8E832AD}.Debug|Any CPU.Build.0 = Debug|Any CPU {C68E3329-A2E4-4B33-BADE-0521B8E832AD}.Debug|x64.ActiveCfg = Debug|Any CPU diff --git a/itext.tests/itext.forms.tests/itext/forms/form/element/RadioTest.cs b/itext.tests/itext.forms.tests/itext/forms/form/element/RadioTest.cs index b0bbcd9669..4e9af7c37d 100644 --- a/itext.tests/itext.forms.tests/itext/forms/form/element/RadioTest.cs +++ b/itext.tests/itext.forms.tests/itext/forms/form/element/RadioTest.cs @@ -23,10 +23,14 @@ You should have received a copy of the GNU Affero General Public License using System; using System.IO; using iText.Forms.Exceptions; +using iText.Forms.Fields; +using iText.Forms.Fields.Properties; using iText.Forms.Form; +using iText.Forms.Form.Renderer.Checkboximpl; using iText.Forms.Logs; using iText.Kernel.Colors; using iText.Kernel.Exceptions; +using iText.Kernel.Geom; using iText.Kernel.Pdf; using iText.Kernel.Utils; using iText.Layout; @@ -282,6 +286,135 @@ public virtual void RadioWithPaddingsTest() { } NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, DESTINATION_FOLDER)); } + [NUnit.Framework.Test] + public virtual void RadioButtonCheckTypeCheckTest() + { + String outPdf = DESTINATION_FOLDER + "radioButtonCheckTypeCheck.pdf"; + String cmpPdf = SOURCE_FOLDER + "cmp_radioButtonCheckTypeCheck.pdf"; + SolidBorder border = new SolidBorder(ColorConstants.BLUE, 3); + Color checkColor = ColorConstants.BLUE; + Color backColor = ColorConstants.GREEN; + CheckBoxType checkType = Fields.Properties.CheckBoxType.CHECK; + PdfString caValue = new PdfString(PdfCheckBoxRenderingStrategy.ZAPFDINGBATS_CHECKBOX_MAPPING.GetByKey(checkType)); + using(PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outPdf))) + { + PdfButtonFormField btnGroup = CreateRadioButtonGroup(border, checkColor, backColor, checkType, caValue, pdfDocument); + // set selected radio button + btnGroup.SetValue("formRadio1"); + pdfDocument.Close(); + } + + NUnit.Framework.Assert.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, DESTINATION_FOLDER)); + } + [NUnit.Framework.Test] + public virtual void RadioButtonCheckTypSquare() + { + String outPdf = DESTINATION_FOLDER + "radioButtonCheckTypeSquare.pdf"; + String cmpPdf = SOURCE_FOLDER + "cmp_radioButtonCheckTypeSquare.pdf"; + SolidBorder border = new SolidBorder(ColorConstants.ORANGE, 3); + Color checkColor = ColorConstants.ORANGE; + Color backColor = ColorConstants.GRAY; + CheckBoxType checkType = Fields.Properties.CheckBoxType.SQUARE; + PdfString caValue = new PdfString(PdfCheckBoxRenderingStrategy.ZAPFDINGBATS_CHECKBOX_MAPPING.GetByKey(checkType)); + using(PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outPdf))) + { + PdfButtonFormField btnGroup = CreateRadioButtonGroup(border, checkColor, backColor, checkType, caValue, pdfDocument); + // change btnGroup to allow unselect + btnGroup.SetRadio(false); + btnGroup.SetValue("formRadio2", false); + pdfDocument.Close(); + } + + NUnit.Framework.Assert.IsTrue(File.Exists(outPdf));//.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, DESTINATION_FOLDER)); + } + [NUnit.Framework.Test] + public virtual void RadioButtonCheckTypSquare_NoSelection() + { + String outPdf = DESTINATION_FOLDER + "radioButtonCheckTypeSquare_NoSelection.pdf"; + String cmpPdf = SOURCE_FOLDER + "cmp_radioButtonCheckTypeSquare_NoSelection.pdf"; + SolidBorder border = new SolidBorder(ColorConstants.ORANGE, 3); + Color checkColor = ColorConstants.ORANGE; + Color backColor = ColorConstants.GRAY; + CheckBoxType checkType = Fields.Properties.CheckBoxType.SQUARE; + PdfString caValue = new PdfString(PdfCheckBoxRenderingStrategy.ZAPFDINGBATS_CHECKBOX_MAPPING.GetByKey(checkType)); + using(PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outPdf))) + { + PdfButtonFormField btnGroup = CreateRadioButtonGroup(border, checkColor, backColor, checkType, caValue, pdfDocument); + // change btnGroup to allow unselect + btnGroup.SetRadio(false); + btnGroup.SetValue("formRadio2", false); + pdfDocument.Close(); + } + + NUnit.Framework.Assert.IsTrue(File.Exists(outPdf));//.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, DESTINATION_FOLDER)); + } + + [NUnit.Framework.Test] + public virtual void RadioButtonCheckTypeStar_NoSelectionTest() + { + String outPdf = DESTINATION_FOLDER + "radioButtonCheckTypeStar_NoSelection.pdf"; + String cmpPdf = SOURCE_FOLDER + "cmp_radioButtonCheckTypeStar_NoSelection.pdf"; + SolidBorder border = new SolidBorder(ColorConstants.ORANGE, 3); + Color checkColor = ColorConstants.ORANGE; + Color backColor = ColorConstants.GRAY; + CheckBoxType checkType = Fields.Properties.CheckBoxType.STAR; + PdfString caValue = new PdfString(PdfCheckBoxRenderingStrategy.ZAPFDINGBATS_CHECKBOX_MAPPING.GetByKey(checkType)); + using(PdfDocument pdfDocument = new PdfDocument(new PdfWriter(outPdf))) + { + PdfButtonFormField btnGroup = CreateRadioButtonGroup(border, checkColor, backColor, checkType, caValue, pdfDocument); + // change btnGroup to allow unselect + btnGroup.SetRadio(false); + btnGroup.SetValue("", false); + pdfDocument.Close(); + } + + NUnit.Framework.Assert.IsTrue(File.Exists(outPdf));//.IsNull(new CompareTool().CompareByContent(outPdf, cmpPdf, DESTINATION_FOLDER)); //.IsTrue(File.Exists(outPdf));// + } + private static PdfButtonFormField CreateRadioButtonGroup(SolidBorder border, Color checkColor, Color backColor, CheckBoxType checkType, PdfString caValue, PdfDocument pdfDocument) + { + pdfDocument.AddNewPage(PageSize.A4); + var form = PdfAcroForm.GetAcroForm(pdfDocument, true); + // create group + var radioBuilder1 = new RadioFormFieldBuilder(pdfDocument, "form radio group"); + radioBuilder1.SetCheckType(checkType); + var btnGroup = radioBuilder1.CreateRadioGroup(); + btnGroup.SetColor(ColorConstants.BLUE); + var formField = btnGroup; + formField.SetCheckType(checkType); + // create button1 + var btn1 = radioBuilder1.CreateRadioButton("formRadio1", new Rectangle(0, 800, 20, 20)); + btn1.SetPage(1); + btn1.SetBorderColor(border.GetColor()); + btn1.SetBorderWidth(border.GetWidth()); + btn1.SetBackgroundColor(backColor); + btn1.SetColor(checkColor); + btn1.SetParent(formField); + btnGroup.AddKid(btn1); + // set visible check type (highlight appearance in Acrobat) + var mk1 = btn1.GetWidget().GetAppearanceCharacteristics(); + if(mk1 == null) + mk1 = new PdfDictionary(); + mk1.Put(PdfName.CA, caValue); + btn1.Put(PdfName.MK, mk1); + // create button2 + var btn2 = radioBuilder1.CreateRadioButton("formRadio2", new Rectangle(22, 800, 20, 20)); + btn2.SetPage(1); + btn2.SetBorderColor(border.GetColor()); + btn2.SetBorderWidth(border.GetWidth()); + btn2.SetBackgroundColor(backColor); + btn2.SetColor(checkColor); + btn2.SetParent(formField); + // set visible check type (highlight appearance in Acrobat) + var mk2 = btn2.GetWidget().GetAppearanceCharacteristics(); + if(mk2 == null) + mk2 = new PdfDictionary(); + mk2.Put(PdfName.CA, caValue); + btn2.Put(PdfName.MK, mk2); + btnGroup.AddKid(btn2); + form.AddField(btnGroup); + return btnGroup; + } + private static Radio CreateRadioButton(String name, String groupName, Border border, Color backgroundColor , bool @checked, bool flatten) { diff --git a/itext.tests/itext.forms.tests/resources/itext/forms/form/element/RadioTest/cmp_radioButtonCheckTypeCheck.pdf b/itext.tests/itext.forms.tests/resources/itext/forms/form/element/RadioTest/cmp_radioButtonCheckTypeCheck.pdf new file mode 100644 index 0000000000000000000000000000000000000000..f6c7cf39fa73a013f47c0d5181812e5facdb5704 GIT binary patch literal 2762 zcmeHJYitx%6fQQFuokT(C=DT8g_dpCcJ96NCfn8Bty@Z8+ubd%vWD56J9TTjQ)j2O zB|e~#fF|IRXsT%l7>ODhV${UMKZ+J95=o#Km6(9lA6WeXL4Wwbd#Ag7B0gebV!X-j z%$)hoz27Y3&{cEJZCc^*-(iaiVFs;sr zrl(8<5MmY|9h^Tp?FAQzQlIsJr!N}n=xrd_%A8T03)Ij%>K5mMez#CY0bw9G^M*Bx zq-`KO4-t~IDNunBV0yt6AMH-qeO-iGpVHfi?en=vT4yv>>TpfE*qLdPE(VBamKbG?N*?7L0HWL{Dh}v)8GBsER-laGc9#dm={> zk}-7n)j0!~hlHoF7Vs6JVsM%VF**4|N zDv|XK(rE3JnXaa}a96L!5c5!mJX8=bKo7*LAY4_(HJJMK0b$G3yOYFnr(&en9s)tr zB0#Bxm8c@x=nqHNG{wMXx4$M_4|<4|p$l#<1FvETVFgOU=up{gE6oNhH5HT)br@4>;cq~iG z#N;z78gnxh1B>lC(8d^+aqFh-x2b8JJ(`_2kSikHK}?swFFFK8Zl(run~fE9BEk(# ziFUdvr^(YZhQlxnZ#Z}$HqW=Uc_p+ACJ)WYw=09`eNU>+hfM?8_w*ZWs z?{}X#-yaz+Y8I-BKHSnUTvS!CW|J1u+Ht`}RPey|Z@0C>;h0(2aP_vO0}ZW+mc zC+{49^>g*_96NtGNQ~6K5hMxMrjNqHcP}sg`JRPqSB#wHw_eQeuiW+Ww#!$8$DdBV zxo~Cc;ONdCBpyEZ<3oMVnxE|`_kVf!)%N9=)>e$3+D}Gb{J`@=%PZfNAKQNX*Aw-8 z@P*=^7C#cJ+Er8xtJ{qOgnl0 ze31WZ=MS{gYZ1dm8@u452WoZzNfdbz7$9d8C3@& zbA1(&erU|XDGEKRXW1a4-Eo!;sdIf*nYOu^I7FMq9GfUmVa>wH@-)u2rKLKE#lEU) zt3j(*(GtW+D6*mHijD*U@x08dhHS_>FDp0lIYWwnWt+%KEwrsFr1)Yz4X(U%K?n&gCxvZ_DE7Q z^A-jeGf9Xp7)~)A7)ep(eL$d+o-X<`63tK@zpRJ?-Lo*#kwJb5VKqRd8}=-WhCKx@ zHB11}Jt(2sq~HMA{gWhylR-d12=H{{sjpN?caDq_xG!%G5+@YmNWo-rtJGl2_<7gU zTKqh~0+UqYuRi#P)8KhG50P#+%0sH=5zh}h#D?)<%^@*jSSEqpq%i0_4U|x*=-5OX z;l^ISWgA^}42H6(30!X1?ImHYsaS||~k`#BV;8388fE}2GJ;cmw5o?U1jew*| zKoR*YEEi)H!XznLCEFmyV35`;ZRba7^wX>|32l&6>%z!V3B$0hIOP$bG@wT^y&_ok z?HWckM;o>VtG29AW!ost*2!Ci7{$U9+sz|hKr#}Lim;$QjQBQ$+PtvGGH z5ZjYalQHK#5VdRq6hHD~U#d5pNIl+{1_PdON1_`XCU%h?IN$|mc!ZFT9SOpt_K_k1 z9kx{(1-*MIaVz{|c~oMxN|eDEcIC}t#$|ODt|3#bnlKp3ChVP4!*~pA)}dgKMdyWkt4+&SUAp~T_8F-ZkTw_N_N$IV$0nNId@ykR)%XMVpZ;V2 zsBgBv-`jA>k3aWzdKN#v`hfuFuWWn2UiqlD4cy!6=JS=%-^uq>*Y@M6K6WiM0TT=J zr)Kc<&vl9K?mpAF_{r3xcRqASuoQMWO^$UDvQ8%cdln5)w64HDo=I!@6$pGByNB z$?>WwNup*bSR{gB@MeI{T~$_OLDqR)k&%Lks+p>Qa(d|Bk01*>3poq8FHbOOS#-kD q>6C=2{5YXhq7$ao9jZPyQ+*p}Dpzzg+i_{fBT?X5TOaF-bAJLoQbzay literal 0 HcmV?d00001 diff --git a/itext.tests/itext.forms.tests/resources/itext/forms/form/element/RadioTest/cmp_radioButtonCheckTypeSquare_NoSelection.pdf b/itext.tests/itext.forms.tests/resources/itext/forms/form/element/RadioTest/cmp_radioButtonCheckTypeSquare_NoSelection.pdf new file mode 100644 index 0000000000000000000000000000000000000000..fc98a55063251f80abf40a30e70b58f40e18d999 GIT binary patch literal 2690 zcmd^BZD?Cn7+w*-u60_ebTA61vf4yR?m6dvW~OoZFtzq8P2x65vvF_kxiwvzTW@Yg zSC~3x2TrPkp}+j6NT<#}I+232Km4JrIR^HhdLTK; zd!P3`@5l3=_qHZtaUb$4T{?p$ z9|I&XNyY!_gMT;-jNLdyy4@%asTxN-KkN{jj}L1OiIJRT5Wbrf2A!vY8VVI1n`k54 z*z31!qpOakp)4vVgr&2RkV3(7iWyeoBw&e3(!5&*hbFoR*nvsDhZuP+VvW&kLm&kt zpo%!lmy5BQ!XznLB|Aro!62%z!VaU*A2amph=X+V!;xFT4! z?J7n!M;o>VtGcXEW!)%^*2!Ci7|n$zwi`n%Km`gg0Fe-Q7~(bv+q`^_W!xB$uq~sM zBeo}>CS%TfAZpnJsD9{2zEp2Gk$Su@4F){njzl*&Oza{(aKH=BUU`y}IclVjb#ZRUlz4M_v8ZW$|{vO}U-Fx4qv)?oYFW+_R)J{)#!z^2Z~E!8=&!{OFHcVIXgfWBzWd@mPuiUaw#djjs{St+udSC$w7cbj$Ul#1!PGQBw&JyOh$AvumuWhGF7BE(k7X#)Z#>yj*(3`5!ULe0eXvV z!UY7%&rLG8g)g|)9@+wjuvFt8k}#cu8_z(ByiVrWT7H<=>}{ws1~NfGg^~beMTfGC zHK-F2E4qnPtVyCQ=1da_l0tM*&6%1ck({9_lAtMyiA^FYW)2#nrW-j!K$58%SWzKS zG*iFCo>sE>Hq)$ literal 0 HcmV?d00001 diff --git a/itext.tests/itext.forms.tests/resources/itext/forms/form/element/RadioTest/cmp_radioButtonCheckTypeStar_NoSelection.pdf b/itext.tests/itext.forms.tests/resources/itext/forms/form/element/RadioTest/cmp_radioButtonCheckTypeStar_NoSelection.pdf new file mode 100644 index 0000000000000000000000000000000000000000..bdf675fab1ce61979111f2dcb72ec8f4d766ae99 GIT binary patch literal 2751 zcmeHJTTC2P7^XI{x~RJC#10aErMhBYSvfeayF$;J{}ZT%@{un#jGrrw1ezu$$^I*nT)3b%}(&01QH zp9P4cl7B9Kmdz%>lkIj12rCIh%pM2ZOr%G3a2RWrj+sWB?sA?2vfrO^Y^?UW22N}& zB5MQ9KPSpng4Qu#iFDd>G6~w-7@!r3k%C)khg3KNsKXf3gmqI5S_7oa5D1C@WS&hj zxh^c#E`~E!zpden&qo>+x6R%He4Mr!+E&*R2c7OfZL|^W!*+%^?5qOsu@FKJbqNA}_Fx8sTHEUH z1I_J(v3cUrJo2$x{e-%RX)yInB1`8avs{_XiV7`5P9f6-b}4U6x-GPk&S$3f@F)5R^#L#12yEpD243B1a8f3vV>s=TogpM*znndEZpVddH=f@;)x5Yrarh5z%MZTyzpCv%I8yrVW8%W`$fFM(o8Q^zxzO5L z^}uB>I$u@qzWV94GaNHLTXecu{-}`r*~{t9^Ocpqlkdw7CBv{dJm()_ijK_A%aM+< zcYf;HaQw>6qua%3bxrv7i*HF!j82Y)#=8$x-~Y(yt=Bv6 zI@-Re0+$8ET^mOShiWdKeXc&V8CP8LK6&3K!CiIjeX|e0IPTsJKEHI;{I+xKL3ZYq zp_$59?_BH6j?xMI!iUqI^Wiru_*1`^n;(>YJl**A>Em0*hfjztH}0)*ADcORretiM zeIt3#$iV2cmw&VN*Dah2uzQAYQMgq+{!b8P)g5yO`TkFo0UH}G2oUcgmt$@LQ4lx* z7$7ebA-SdK0_kO$%##tbP9}3^rS&pdAtPoTPGQMZTPK64P{u-X!>+?A zN%1yUhOQ$hNjSwL60w>x zctzxSY)F{XHOOI(6C{q86(}e?uPUm}3W$?s$Y}yX5|%VklMqU!3|-?nPKU%ElyrrY z6@kSNVM$?GR@P)u*JMrf|N9XnnfkP0f$WU5Em{5t#tIF(P_RzWP YSv!|q8Ar99EbUkXc~@m+O-sb}CoL6jlmGw# literal 0 HcmV?d00001 diff --git a/itext/itext.forms/itext/forms/fields/PdfFormAnnotation.cs b/itext/itext.forms/itext/forms/fields/PdfFormAnnotation.cs index 9eeaee57c1..81a0f6c7b3 100644 --- a/itext/itext.forms/itext/forms/fields/PdfFormAnnotation.cs +++ b/itext/itext.forms/itext/forms/fields/PdfFormAnnotation.cs @@ -719,16 +719,45 @@ protected internal virtual void DrawPushButtonFieldAndSaveAppearance() { /// the value of the radio button. protected internal virtual void DrawRadioButtonAndSaveAppearance(String value) { Rectangle rectangle = GetRect(this.GetPdfObject()); - if (rectangle == null) { + if(rectangle == null) { return; } - if (!(formFieldElement is Radio)) { + + // Custom >>>>>>>>>>>>>> + var fontColor = ColorConstants.BLACK; + CheckBoxType? checkType = null; + if(parent != null && parent.checkType != null) + { + fontColor = GetParentField().GetColor(); + checkType = parent.checkType.GetValue(); + } + if(this.GetColor() != null) + fontColor = this.GetColor(); + // Custom<<<<<<<<<<<<<<<<<<<<< + + + if(!(formFieldElement is Radio)) { // Create it one time and re-set properties during each widget regeneration. - formFieldElement = new Radio(""); + if(checkType != null) + formFieldElement = new Radio("", checkType.Value); + else + formFieldElement = new Radio(""); } SetModelElementProperties(GetRect(GetPdfObject())); // First draw off appearance ((Radio)formFieldElement).SetChecked(false); + + // Custom >>>>>>>>>>>>>> + if(checkType != null) + { + if(((Radio)formFieldElement).HasProperty(FormProperty.FORM_CHECKBOX_TYPE)) + ((Radio)formFieldElement).SetCheckBoxType(checkType.Value); + + ((Radio)formFieldElement).SetFontColor(fontColor); + } + // Custom<<<<<<<<<<<<<<<<<<<<< + + PdfFormXObject xObjectOff = new PdfFormXObject(new Rectangle(0, 0, rectangle.GetWidth(), rectangle.GetHeight ())); iText.Layout.Canvas canvasOff = new iText.Layout.Canvas(xObjectOff, this.GetDocument()); @@ -740,6 +769,15 @@ protected internal virtual void DrawRadioButtonAndSaveAppearance(String value) { if (value != null && !String.IsNullOrEmpty(value) && !iText.Forms.Fields.PdfFormAnnotation.OFF_STATE_VALUE .Equals(value)) { ((Radio)formFieldElement).SetChecked(true); + if(checkType != null) + { + if(((Radio)formFieldElement).HasProperty(FormProperty.FORM_CHECKBOX_TYPE)) + ((Radio)formFieldElement).SetCheckBoxType(checkType.Value); + + ((Radio)formFieldElement).SetFontColor(fontColor); + } + // Custom<<<<<<<<<<<<<<<<<<<<< + PdfFormXObject xObject = new PdfFormXObject(new Rectangle(0, 0, rectangle.GetWidth(), rectangle.GetHeight( ))); iText.Layout.Canvas canvas = new iText.Layout.Canvas(xObject, this.GetDocument()); diff --git a/itext/itext.forms/itext/forms/fields/RadioFormFieldBuilder.cs b/itext/itext.forms/itext/forms/fields/RadioFormFieldBuilder.cs index 9bebc3ee4d..eef9998378 100644 --- a/itext/itext.forms/itext/forms/fields/RadioFormFieldBuilder.cs +++ b/itext/itext.forms/itext/forms/fields/RadioFormFieldBuilder.cs @@ -22,6 +22,7 @@ You should have received a copy of the GNU Affero General Public License */ using System; using iText.Forms.Exceptions; +using iText.Forms.Fields.Properties; using iText.Kernel.Exceptions; using iText.Kernel.Geom; using iText.Kernel.Pdf; @@ -37,6 +38,8 @@ public RadioFormFieldBuilder(PdfDocument document, String radioGroupFormFieldNam : base(document, radioGroupFormFieldName) { } + private CheckBoxType checkType = CheckBoxType.CIRCLE; + /// Creates radio group form field instance based on provided parameters. /// /// new @@ -82,5 +85,21 @@ public virtual PdfFormAnnotation CreateRadioButton(String appearanceName, Rectan protected internal override iText.Forms.Fields.RadioFormFieldBuilder GetThis() { return this; } + + /// Gets check type for checkbox form field. + /// check type to be set for checkbox form field + public virtual CheckBoxType GetCheckType() + { + return checkType; + } + public virtual RadioFormFieldBuilder SetCheckType(CheckBoxType checkType) + { + if(GetConformanceLevel() != null) + this.checkType = CheckBoxType.CIRCLE; + else + this.checkType = checkType; + + return this; + } } } diff --git a/itext/itext.forms/itext/forms/form/element/Radio.cs b/itext/itext.forms/itext/forms/form/element/Radio.cs index a467684c10..f60a47c8e4 100644 --- a/itext/itext.forms/itext/forms/form/element/Radio.cs +++ b/itext/itext.forms/itext/forms/form/element/Radio.cs @@ -21,8 +21,10 @@ 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.Properties; using iText.Forms.Form; using iText.Forms.Form.Renderer; +using iText.Kernel.Colors; using iText.Layout.Properties; using iText.Layout.Renderer; @@ -44,14 +46,26 @@ public class Radio : FormField { /// the id. public Radio(String id) : base(id) { + // Draw the borders inside the element by default SetProperty(Property.BOX_SIZING, BoxSizingPropertyValue.BORDER_BOX); - // Rounded border - SetBorderRadius(new BorderRadius(UnitValue.CreatePercentValue(50))); + //// Rounded border + //SetBorderRadius(new BorderRadius(UnitValue.CreatePercentValue(50))); // Draw border as a circle by default SetProperty(FormProperty.FORM_FIELD_RADIO_BORDER_CIRCLE, true); } - + /// + /// Creates a new + /// + /// instance. + /// + /// the id + /// CheckBoxType + public Radio(String id, CheckBoxType checkBoxType) + : base(id) + { + SetCheckBoxType(checkBoxType); + } /// /// Creates a new /// @@ -102,5 +116,38 @@ public override T1 GetProperty(int property) { protected override IRenderer MakeNewRenderer() { return new RadioRenderer(this); } + /// Sets the icon of the radio. + /// the type of the radio to set + /// this Radio instance + public Radio SetCheckBoxType(CheckBoxType checkBoxType) + { + SetProperty(FormProperty.FORM_CHECKBOX_TYPE, checkBoxType); + if(checkBoxType != CheckBoxType.CIRCLE) + { + // Rounded border + //SetBorderRadius(null); + DeleteOwnProperty(Property.BORDER_RADIUS); + DeleteOwnProperty(Property.BOX_SIZING); + DeleteOwnProperty(FormProperty.FORM_FIELD_RADIO_BORDER_CIRCLE); + SetProperty(Property.BOX_SIZING, BoxSizingPropertyValue.CONTENT_BOX); + SetProperty(FormProperty.FORM_FIELD_RADIO_BORDER_CIRCLE, false); + } + + return this; + } + /// + /// Sets the chech mark color + /// + /// The selected iText color + /// + public override Radio SetFontColor(Color color) + { + if(color == null) + color = ColorConstants.BLACK; + + DeleteOwnProperty(Property.FONT_COLOR); + SetProperty(Property.FONT_COLOR, color); + return this; + } } } diff --git a/itext/itext.forms/itext/forms/form/renderer/RadioRenderer.cs b/itext/itext.forms/itext/forms/form/renderer/RadioRenderer.cs index bd96223b4c..de80dcf84c 100644 --- a/itext/itext.forms/itext/forms/form/renderer/RadioRenderer.cs +++ b/itext/itext.forms/itext/forms/form/renderer/RadioRenderer.cs @@ -24,6 +24,7 @@ You should have received a copy of the GNU Affero General Public License using iText.Forms; using iText.Forms.Exceptions; using iText.Forms.Fields; +using iText.Forms.Fields.Properties; using iText.Forms.Form; using iText.Forms.Form.Element; using iText.Forms.Util; @@ -113,10 +114,17 @@ protected override Rectangle ApplyBorderBox(Rectangle rect, Border[] borders, bo /// protected internal override IRenderer CreateFlatRenderer() { UnitValue heightUV = GetPropertyAsUnitValue(Property.HEIGHT); - UnitValue widthUV = GetPropertyAsUnitValue(Property.WIDTH); - float height = null == heightUV ? DEFAULT_SIZE : heightUV.GetValue(); - float width = null == widthUV ? DEFAULT_SIZE : widthUV.GetValue(); - float size = Math.Min(height, width); + UnitValue widthUV = GetPropertyAsUnitValue(Property.WIDTH); + float height = null == heightUV ? DEFAULT_SIZE : heightUV.GetValue(); + float width = null == widthUV ? DEFAULT_SIZE : widthUV.GetValue(); + float size = Math.Min(height, width); + var border = this.GetProperty(Property.BORDER); + var checkType = (int)CheckBoxType.CIRCLE; + if(this.HasProperty(FormProperty.FORM_CHECKBOX_TYPE)) + checkType = ((IFormField)this.modelElement).GetProperty(FormProperty.FORM_CHECKBOX_TYPE); + var backGround = this.GetProperty(Property.BACKGROUND); + + // Set size to current renderer SetProperty(Property.HEIGHT, UnitValue.CreatePointValue(height)); SetProperty(Property.WIDTH, UnitValue.CreatePointValue(width)); @@ -124,8 +132,13 @@ protected internal override IRenderer CreateFlatRenderer() { ).SetVerticalAlignment(DEFAULT_VERTICAL_ALIGNMENT).SetMargin(0); paragraph.SetProperty(Property.BOX_SIZING, this.GetProperty(Property.BOX_SIZING)); paragraph.SetBorder(this.GetProperty(Property.BORDER)); - paragraph.SetProperty(Property.BACKGROUND, this.GetProperty(Property.BACKGROUND)); - paragraph.SetBorderRadius(new BorderRadius(UnitValue.CreatePercentValue(50))); + + if(backGround != null) + { + paragraph.SetProperty(Property.BACKGROUND, backGround); + } + if(checkType == (int)CheckBoxType.CIRCLE) + paragraph.SetBorderRadius(new BorderRadius(UnitValue.CreatePercentValue(50))); return new RadioRenderer.FlatParagraphRenderer(this, paragraph); } @@ -204,10 +217,95 @@ public override void DrawChildren(DrawContext drawContext) { // Nothing to draw return; } + var checkType = (int)CheckBoxType.CIRCLE; + if(this._enclosing.HasProperty(FormProperty.FORM_CHECKBOX_TYPE)) + { + checkType = ((IFormField)this._enclosing.modelElement).GetProperty(FormProperty.FORM_CHECKBOX_TYPE); + var fontColor = this.GetProperty(Property.FONT_COLOR); + if(checkType == (int)CheckBoxType.CIRCLE && (fontColor == null || fontColor == DEFAULT_CHECKED_COLOR)) + { + // classic circle + DrawChildren_Classic(drawContext); + } + else + DrawChildren_Custom(drawContext); + } + else + DrawChildren_Classic(drawContext); + } + + private void DrawChildren_Custom(DrawContext drawContext) + { + ((IFormField)this._enclosing.modelElement).SetProperty(Property.BOX_SIZING, BoxSizingPropertyValue.CONTENT_BOX); + var checkType = ((IFormField)this._enclosing.modelElement).GetProperty(FormProperty.FORM_CHECKBOX_TYPE); + PdfCanvas pdfCanvas = drawContext.GetCanvas(); + Rectangle rectangle = this.GetOccupiedArea().GetBBox().Clone(); + Border border = this.GetProperty(Property.BORDER); + var fontColor = this.GetProperty(Property.FONT_COLOR); + var annotationFontColor = this._enclosing.GetProperty(Property.FONT_COLOR); + var borderWith = 0f; + if(border != null) + { + borderWith = border.GetWidth(); + var db = border.GetWidth() * 2; + if(checkType == (int)CheckBoxType.CIRCLE) + rectangle.ApplyMargins(borderWith, borderWith, borderWith, borderWith, false); + else + rectangle = new Rectangle(rectangle.GetWidth() - db, rectangle.GetHeight() - db); + } + else + { + borderWith = 1f; + } + + if(annotationFontColor != null) + fontColor = annotationFontColor; + if(fontColor == null && annotationFontColor == null) + fontColor = DEFAULT_CHECKED_COLOR; + + pdfCanvas.SetFillColor(fontColor); + pdfCanvas.SaveState(); + + DrawCheckType(checkType, pdfCanvas, rectangle, borderWith); + pdfCanvas.RestoreState(); + } + private static void DrawCheckType(int checkType, PdfCanvas pdfCanvas, Rectangle rectangle, float borderWith) + { + switch(checkType) + { + case (int)CheckBoxType.CHECK: + DrawingUtil.DrawPdfCheck(pdfCanvas, rectangle.GetWidth(), rectangle.GetHeight(), borderWith, borderWith); + break; + case (int)CheckBoxType.CIRCLE: + DrawingUtil.DrawPdfCircle(pdfCanvas, rectangle.GetWidth(), rectangle.GetHeight(), borderWith, borderWith); + break; + case (int)CheckBoxType.CROSS: + DrawingUtil.DrawPdfCross(pdfCanvas, rectangle.GetWidth(), rectangle.GetHeight(), borderWith, borderWith); + break; + case (int)CheckBoxType.DIAMOND: + DrawingUtil.DrawPdfDiamond(pdfCanvas, rectangle.GetWidth(), rectangle.GetHeight(), borderWith, borderWith); + break; + case (int)CheckBoxType.SQUARE: + DrawingUtil.DrawPdfSquare(pdfCanvas, rectangle.GetWidth(), rectangle.GetHeight(), borderWith, borderWith); + break; + case (int)CheckBoxType.STAR: + DrawingUtil.DrawPdfStar(pdfCanvas, rectangle.GetWidth(), rectangle.GetHeight(), borderWith, borderWith); + break; + } + } + + public void DrawChildren_Classic(DrawContext drawContext) + { + if(!this._enclosing.IsBoxChecked()) + { + // Nothing to draw + return; + } PdfCanvas canvas = drawContext.GetCanvas(); Rectangle rectangle = this.GetOccupiedArea().GetBBox().Clone(); Border border = this.GetProperty(Property.BORDER); - if (border != null) { + if(border != null) + { rectangle.ApplyMargins(border.GetWidth(), border.GetWidth(), border.GetWidth(), border.GetWidth(), false); } float radius = Math.Min(rectangle.GetWidth(), rectangle.GetHeight()) / 2; @@ -217,6 +315,7 @@ public override void DrawChildren(DrawContext drawContext) { canvas.RestoreState(); } + /// /// /// diff --git a/itext/itext.forms/itext/forms/util/DrawingUtil.cs b/itext/itext.forms/itext/forms/util/DrawingUtil.cs index ac208f2f27..d643fb623d 100644 --- a/itext/itext.forms/itext/forms/util/DrawingUtil.cs +++ b/itext/itext.forms/itext/forms/util/DrawingUtil.cs @@ -52,6 +52,129 @@ public class DrawingUtil { + "-0.47 0 l\n" + "-0.761 0 l\n" + "-0.526 -0.171 l\n" + "-0.616 -0.448 l\n" + "-0.381 -0.277 l\n" + "-0.145 -0.448 l\n" + "-0.236 -0.171 l\n" + "h\n" + "f\n"; + #region PDF Custom Appearance + private static void DrawPdfAppearanceString(PdfCanvas canvas, float width, float height, float moveX, float moveY, String appearanceString) + { + canvas.SaveState(); + canvas.ConcatMatrix(width, 0, 0, height, moveX, moveY); + canvas.GetContentStream().GetOutputStream().WriteBytes(appearanceString.GetBytes(iText.Commons.Utils.EncodingUtil.ISO_8859_1)); + canvas.RestoreState(); + } + /// Draws a PDF check mark in the specified rectangle. + /// the canvas to draw on + /// the width of the rectangle + /// the height of the rectangle + /// the x coordinate of the bottom left corner of the rectangle + /// the y coordinate of the bottom left corner of the rectangle + public static void DrawPdfCheck(PdfCanvas canvas, float width, float height, float moveX, float moveY) + { + DrawPdfAppearanceString(canvas, width, height, moveX, moveY, check); + } + + /// Draws a PDF check mark in the specified rectangle. + /// the canvas to draw on + /// the width of the rectangle + /// the height of the rectangle + public static void DrawPdfCheck(PdfCanvas canvas, float width, float height) + { + DrawPdfAppearanceString(canvas, width, height, 0, 0, check); + } + + /// Draws a PDF circle in the specified rectangle. + /// the canvas to draw on + /// the width of the rectangle + /// the height of the rectangle + /// the x coordinate of the bottom left corner of the rectangle + /// the y coordinate of the bottom left corner of the rectangle + public static void DrawPdfCircle(PdfCanvas canvas, float width, float height, float moveX, float moveY) + { + DrawPdfAppearanceString(canvas, width, height, moveX, moveY, circle); + } + + /// Draws a PDFcircle in the specified rectangle. + /// the canvas to draw on + /// the width of the rectangle + /// the height of the rectangle + public static void DrawPdfCircle(PdfCanvas canvas, float width, float height) + { + DrawPdfAppearanceString(canvas, width, height, 0, 0, circle); + } + + /// Draws a PDF cross in the specified rectangle. + /// the canvas to draw on + /// the width of the rectangle + /// the height of the rectangle + /// the x coordinate of the bottom left corner of the rectangle + /// the y coordinate of the bottom left corner of the rectangle + public static void DrawPdfCross(PdfCanvas canvas, float width, float height, float moveX, float moveY) + { + DrawPdfAppearanceString(canvas, width, height, moveX, moveY, cross); + } + + /// Draws a PDF cross in the specified rectangle. + /// the canvas to draw on + /// the width of the rectangle + /// the height of the rectangle + public static void DrawPdfCross(PdfCanvas canvas, float width, float height) + { + DrawPdfAppearanceString(canvas, width, height, 0, 0, cross); + } + + /// Draws a PDF diamond in the specified rectangle. + /// the canvas to draw on + /// the width of the rectangle + /// the height of the rectangle + /// the x coordinate of the bottom left corner of the rectangle + /// the y coordinate of the bottom left corner of the rectangle + public static void DrawPdfDiamond(PdfCanvas canvas, float width, float height, float moveX, float moveY) + { + DrawPdfAppearanceString(canvas, width, height, moveX, moveY, diamond); + } + + /// Draws a PDF diamond in the specified rectangle. + /// the canvas to draw on + /// the width of the rectangle + /// the height of the rectangle + public static void DrawPdfDiamond(PdfCanvas canvas, float width, float height) + { + DrawPdfAppearanceString(canvas, width, height, 0, 0, diamond); + } + + /// Draws a PDF square in the specified rectangle. + /// the canvas to draw on + /// the width of the rectangle + /// the height of the rectangle + /// the x coordinate of the bottom left corner of the rectangle + /// the y coordinate of the bottom left corner of the rectangle + public static void DrawPdfSquare(PdfCanvas canvas, float width, float height, float moveX, float moveY) + { + DrawPdfAppearanceString(canvas, width, height, moveX, moveY, square); + } + + + + /// Draws a PDF star in the specified rectangle. + /// the canvas to draw on + /// the width of the rectangle + /// the height of the rectangle + /// the x coordinate of the bottom left corner of the rectangle + /// the y coordinate of the bottom left corner of the rectangle + public static void DrawPdfStar(PdfCanvas canvas, float width, float height, float moveX, float moveY) + { + DrawPdfAppearanceString(canvas, width, height, moveX, moveY, star); + } + + /// Draws a PDF star in the specified rectangle. + /// the canvas to draw on + /// the width of the rectangle + /// the height of the rectangle + public static void DrawPdfStar(PdfCanvas canvas, float width, float height) + { + DrawPdfAppearanceString(canvas, width, height, 0, 0, star); + } + #endregion + + #region PDF A Appearance private static void DrawPdfAAppearanceString(PdfCanvas canvas, float width, float height, float moveX, float moveY, String appearanceString) { canvas.SaveState(); @@ -190,5 +313,7 @@ public static void DrawCross(PdfCanvas canvas, float width, float height, float public static void DrawCircle(PdfCanvas canvas, float centerX, float centerY, float radius) { canvas.Circle(centerX, centerY, radius).Fill(); } + + #endregion } }