Skip to content

Commit c6432b3

Browse files
introfogiText-CI
authored andcommitted
Support grid-gap, grid-column-gap and grid-row-gap and log unsupported properties
DEVSIX-8376 Autoported commit. Original commit hash: [5a8f86d5e]
1 parent 8ade291 commit c6432b3

File tree

8 files changed

+84
-11
lines changed

8 files changed

+84
-11
lines changed

itext.tests/itext.styledxmlparser.tests/itext/styledxmlparser/css/resolve/shorthand/GapShorthandResolverTest.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,18 @@ public virtual void GapWithTwoValidValuesTest() {
131131
NUnit.Framework.Assert.AreEqual("15px", resolvedShorthand[1].GetExpression());
132132
}
133133

134+
[NUnit.Framework.Test]
135+
public virtual void GridGapWithTwoValidValuesTest() {
136+
IShorthandResolver resolver = new GapShorthandResolver(CommonCssConstants.GRID_GAP);
137+
String shorthand = "10px 15px";
138+
IList<CssDeclaration> resolvedShorthand = resolver.ResolveShorthand(shorthand);
139+
NUnit.Framework.Assert.AreEqual(2, resolvedShorthand.Count);
140+
NUnit.Framework.Assert.AreEqual(CommonCssConstants.ROW_GAP, resolvedShorthand[0].GetProperty());
141+
NUnit.Framework.Assert.AreEqual("10px", resolvedShorthand[0].GetExpression());
142+
NUnit.Framework.Assert.AreEqual(CommonCssConstants.COLUMN_GAP, resolvedShorthand[1].GetProperty());
143+
NUnit.Framework.Assert.AreEqual("15px", resolvedShorthand[1].GetExpression());
144+
}
145+
134146
[NUnit.Framework.Test]
135147
[LogMessage(iText.StyledXmlParser.Logs.StyledXmlParserLogMessageConstant.INVALID_CSS_PROPERTY_DECLARATION)]
136148
public virtual void GapWithValidAndInvalidValuesTest() {

itext.tests/itext.styledxmlparser.tests/itext/styledxmlparser/css/validate/CssDeclarationValidationMasterTest.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,24 @@ public virtual void MulticolValidationTest() {
426426
.COLUMN_GAP, "10")));
427427
}
428428

429+
[NUnit.Framework.Test]
430+
public virtual void GridRowColumnGapTest() {
431+
NUnit.Framework.Assert.IsTrue(CssDeclarationValidationMaster.CheckDeclaration(new CssDeclaration(CommonCssConstants
432+
.GRID_ROW_GAP, "normal")));
433+
NUnit.Framework.Assert.IsTrue(CssDeclarationValidationMaster.CheckDeclaration(new CssDeclaration(CommonCssConstants
434+
.GRID_COLUMN_GAP, "30px")));
435+
NUnit.Framework.Assert.IsTrue(CssDeclarationValidationMaster.CheckDeclaration(new CssDeclaration(CommonCssConstants
436+
.GRID_ROW_GAP, "15%")));
437+
NUnit.Framework.Assert.IsTrue(CssDeclarationValidationMaster.CheckDeclaration(new CssDeclaration(CommonCssConstants
438+
.GRID_ROW_GAP, "2em")));
439+
NUnit.Framework.Assert.IsTrue(CssDeclarationValidationMaster.CheckDeclaration(new CssDeclaration(CommonCssConstants
440+
.GRID_COLUMN_GAP, "3rem")));
441+
NUnit.Framework.Assert.IsFalse(CssDeclarationValidationMaster.CheckDeclaration(new CssDeclaration(CommonCssConstants
442+
.GRID_COLUMN_GAP, "-5em")));
443+
NUnit.Framework.Assert.IsFalse(CssDeclarationValidationMaster.CheckDeclaration(new CssDeclaration(CommonCssConstants
444+
.GRID_ROW_GAP, "10")));
445+
}
446+
429447
[NUnit.Framework.Test]
430448
public virtual void ChangeValidatorTest() {
431449
try {

itext/itext.kernel/itext/kernel/pdf/canvas/parser/data/ImageRenderInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ public ImageRenderInfo(Stack<CanvasTag> canvasTagHierarchy, CanvasGraphicsState
9696
/// <see cref="System.Drawing.Bitmap"/>
9797
/// with
9898
/// <see cref="iText.Kernel.Pdf.Xobject.PdfImageXObject.GetBufferedImage()"/>
99-
/// ;
99+
/// ; // Android-Conversion-Skip-Line (java.awt library isn't available on Android)
100100
/// </description></item>
101101
/// </list>
102102
/// </remarks>

itext/itext.styledxmlparser/itext/styledxmlparser/css/CommonCssConstants.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,12 +331,21 @@ static CommonCssConstants() {
331331
/// <summary>The Constant GRID_COLUMN_END.</summary>
332332
public const String GRID_COLUMN_END = "grid-column-end";
333333

334+
/// <summary>The Constant GRID_COLUMN_GAP.</summary>
335+
public const String GRID_COLUMN_GAP = "grid-column-gap";
336+
334337
/// <summary>The Constant GRID_COLUMN_START.</summary>
335338
public const String GRID_COLUMN_START = "grid-column-start";
336339

340+
/// <summary>The Constant GRID_GAP.</summary>
341+
public const String GRID_GAP = "grid-gap";
342+
337343
/// <summary>The Constant GRID_ROW_END.</summary>
338344
public const String GRID_ROW_END = "grid-row-end";
339345

346+
/// <summary>The Constant GRID_ROW_GAP.</summary>
347+
public const String GRID_ROW_GAP = "grid-row-gap";
348+
340349
/// <summary>The Constant GRID_ROW_START.</summary>
341350
public const String GRID_ROW_START = "grid-row-start";
342351

itext/itext.styledxmlparser/itext/styledxmlparser/css/resolve/shorthand/ShorthandResolverFactory.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@ static ShorthandResolverFactory() {
5252
shorthandResolvers.Put(CommonCssConstants.TEXT_DECORATION, new TextDecorationShorthandResolver());
5353
shorthandResolvers.Put(CommonCssConstants.FLEX, new FlexShorthandResolver());
5454
shorthandResolvers.Put(CommonCssConstants.FLEX_FLOW, new FlexFlowShorthandResolver());
55-
shorthandResolvers.Put(CommonCssConstants.GAP, new GapShorthandResolver());
55+
shorthandResolvers.Put(CommonCssConstants.GAP, new GapShorthandResolver(CommonCssConstants.GAP));
56+
shorthandResolvers.Put(CommonCssConstants.GRID_GAP, new GapShorthandResolver(CommonCssConstants.GRID_GAP));
5657
shorthandResolvers.Put(CommonCssConstants.PLACE_ITEMS, new PlaceItemsShorthandResolver());
5758
shorthandResolvers.Put(CommonCssConstants.COLUMNS, new ColumnsShorthandResolver());
5859
shorthandResolvers.Put(CommonCssConstants.COLUMN_RULE, new ColumnRuleShortHandResolver());

itext/itext.styledxmlparser/itext/styledxmlparser/css/resolve/shorthand/impl/GapShorthandResolver.cs

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,39 @@ You should have received a copy of the GNU Affero General Public License
3131
using iText.StyledXmlParser.Css.Validate;
3232

3333
namespace iText.StyledXmlParser.Css.Resolve.Shorthand.Impl {
34+
/// <summary>
35+
/// Shorthand resolver for gap shorthand properties, can be used for
36+
/// different gap properties like
37+
/// <c>gap</c>
38+
/// or
39+
/// <c>grid-gap</c>.
40+
/// </summary>
3441
public class GapShorthandResolver : IShorthandResolver {
35-
private static readonly ILogger LOGGER = ITextLogManager.GetLogger(typeof(GapShorthandResolver));
42+
private readonly String gapShorthandProperty;
43+
44+
/// <summary>
45+
/// Instantiates default
46+
/// <see cref="GapShorthandResolver"/>
47+
/// for
48+
/// <c>gap</c>
49+
/// shorthand.
50+
/// </summary>
51+
public GapShorthandResolver()
52+
: this(CommonCssConstants.GAP) {
53+
}
54+
55+
/// <summary>
56+
/// Instantiates default
57+
/// <see cref="GapShorthandResolver"/>
58+
/// for passed gap shorthand.
59+
/// </summary>
60+
/// <param name="gapShorthandProperty">the name of the gap shorthand property</param>
61+
public GapShorthandResolver(String gapShorthandProperty) {
62+
this.gapShorthandProperty = gapShorthandProperty;
63+
}
64+
65+
private static readonly ILogger LOGGER = ITextLogManager.GetLogger(typeof(iText.StyledXmlParser.Css.Resolve.Shorthand.Impl.GapShorthandResolver
66+
));
3667

3768
/// <summary><inheritDoc/></summary>
3869
public virtual IList<CssDeclaration> ResolveShorthand(String shorthandExpression) {
@@ -43,11 +74,11 @@ public virtual IList<CssDeclaration> ResolveShorthand(String shorthandExpression
4374
}
4475
if (CssTypesValidationUtils.ContainsInitialOrInheritOrUnset(shorthandExpression)) {
4576
return HandleExpressionError(iText.StyledXmlParser.Logs.StyledXmlParserLogMessageConstant.INVALID_CSS_PROPERTY_DECLARATION
46-
, CommonCssConstants.GAP, shorthandExpression);
77+
, gapShorthandProperty, shorthandExpression);
4778
}
4879
if (String.IsNullOrEmpty(shorthandExpression)) {
4980
return HandleExpressionError(iText.StyledXmlParser.Logs.StyledXmlParserLogMessageConstant.SHORTHAND_PROPERTY_CANNOT_BE_EMPTY
50-
, CommonCssConstants.GAP, shorthandExpression);
81+
, gapShorthandProperty, shorthandExpression);
5182
}
5283
String[] gapProps = iText.Commons.Utils.StringUtil.Split(shorthandExpression, " ");
5384
if (gapProps.Length == 1) {
@@ -59,7 +90,7 @@ public virtual IList<CssDeclaration> ResolveShorthand(String shorthandExpression
5990
}
6091
else {
6192
return HandleExpressionError(iText.StyledXmlParser.Logs.StyledXmlParserLogMessageConstant.INVALID_CSS_PROPERTY_DECLARATION
62-
, CommonCssConstants.GAP, shorthandExpression);
93+
, gapShorthandProperty, shorthandExpression);
6394
}
6495
}
6596
}

itext/itext.styledxmlparser/itext/styledxmlparser/css/validate/impl/CssDefaultValidator.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,16 @@ public CssDefaultValidator() {
8585
defaultValidators.Put(CommonCssConstants.LINE_HEIGHT, new MultiTypeDeclarationValidator(new CssNumberValueValidator
8686
(false), new CssLengthValueValidator(false), new CssPercentageValueValidator(false), normalValidator,
8787
inheritInitialUnsetValidator));
88-
defaultValidators.Put(CommonCssConstants.COLUMN_GAP, new MultiTypeDeclarationValidator(new CssLengthValueValidator
89-
(false), new CssPercentageValueValidator(false), normalValidator));
88+
MultiTypeDeclarationValidator gapValidator = new MultiTypeDeclarationValidator(new CssLengthValueValidator
89+
(false), new CssPercentageValueValidator(false), normalValidator, inheritInitialUnsetValidator);
90+
defaultValidators.Put(CommonCssConstants.COLUMN_GAP, gapValidator);
91+
defaultValidators.Put(CommonCssConstants.GRID_COLUMN_GAP, gapValidator);
9092
defaultValidators.Put(CommonCssConstants.COLUMN_WIDTH, new MultiTypeDeclarationValidator(new CssLengthValueValidator
9193
(false), new CssPercentageValueValidator(false), new CssEnumValidator(CommonCssConstants.AUTO)));
9294
defaultValidators.Put(CommonCssConstants.COLUMN_COUNT, new MultiTypeDeclarationValidator(new CssIntegerNumberValueValidator
9395
(false, false), new CssEnumValidator(CommonCssConstants.AUTO)));
94-
defaultValidators.Put(CommonCssConstants.ROW_GAP, new MultiTypeDeclarationValidator(new CssLengthValueValidator
95-
(false), new CssPercentageValueValidator(false), normalValidator, inheritInitialUnsetValidator));
96+
defaultValidators.Put(CommonCssConstants.ROW_GAP, gapValidator);
97+
defaultValidators.Put(CommonCssConstants.GRID_ROW_GAP, gapValidator);
9698
defaultValidators.Put(CommonCssConstants.FLEX_GROW, new MultiTypeDeclarationValidator(new CssNumberValueValidator
9799
(false), inheritInitialUnsetValidator));
98100
defaultValidators.Put(CommonCssConstants.FLEX_SHRINK, new MultiTypeDeclarationValidator(new CssNumberValueValidator

port-hash

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
14594176c3df587ff53e54994152bf09ca64d596
1+
5a8f86d5e1ee424e95f9bae23d0ae30f8a971989

0 commit comments

Comments
 (0)