Skip to content

Commit

Permalink
Support grid-gap, grid-column-gap and grid-row-gap and log unsupporte…
Browse files Browse the repository at this point in the history
…d properties

DEVSIX-8376

Autoported commit.
Original commit hash: [5a8f86d5e]
  • Loading branch information
introfog authored and iText-CI committed Jul 9, 2024
1 parent 8ade291 commit c6432b3
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,18 @@ public virtual void GapWithTwoValidValuesTest() {
NUnit.Framework.Assert.AreEqual("15px", resolvedShorthand[1].GetExpression());
}

[NUnit.Framework.Test]
public virtual void GridGapWithTwoValidValuesTest() {
IShorthandResolver resolver = new GapShorthandResolver(CommonCssConstants.GRID_GAP);
String shorthand = "10px 15px";
IList<CssDeclaration> resolvedShorthand = resolver.ResolveShorthand(shorthand);
NUnit.Framework.Assert.AreEqual(2, resolvedShorthand.Count);
NUnit.Framework.Assert.AreEqual(CommonCssConstants.ROW_GAP, resolvedShorthand[0].GetProperty());
NUnit.Framework.Assert.AreEqual("10px", resolvedShorthand[0].GetExpression());
NUnit.Framework.Assert.AreEqual(CommonCssConstants.COLUMN_GAP, resolvedShorthand[1].GetProperty());
NUnit.Framework.Assert.AreEqual("15px", resolvedShorthand[1].GetExpression());
}

[NUnit.Framework.Test]
[LogMessage(iText.StyledXmlParser.Logs.StyledXmlParserLogMessageConstant.INVALID_CSS_PROPERTY_DECLARATION)]
public virtual void GapWithValidAndInvalidValuesTest() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,24 @@ public virtual void MulticolValidationTest() {
.COLUMN_GAP, "10")));
}

[NUnit.Framework.Test]
public virtual void GridRowColumnGapTest() {
NUnit.Framework.Assert.IsTrue(CssDeclarationValidationMaster.CheckDeclaration(new CssDeclaration(CommonCssConstants
.GRID_ROW_GAP, "normal")));
NUnit.Framework.Assert.IsTrue(CssDeclarationValidationMaster.CheckDeclaration(new CssDeclaration(CommonCssConstants
.GRID_COLUMN_GAP, "30px")));
NUnit.Framework.Assert.IsTrue(CssDeclarationValidationMaster.CheckDeclaration(new CssDeclaration(CommonCssConstants
.GRID_ROW_GAP, "15%")));
NUnit.Framework.Assert.IsTrue(CssDeclarationValidationMaster.CheckDeclaration(new CssDeclaration(CommonCssConstants
.GRID_ROW_GAP, "2em")));
NUnit.Framework.Assert.IsTrue(CssDeclarationValidationMaster.CheckDeclaration(new CssDeclaration(CommonCssConstants
.GRID_COLUMN_GAP, "3rem")));
NUnit.Framework.Assert.IsFalse(CssDeclarationValidationMaster.CheckDeclaration(new CssDeclaration(CommonCssConstants
.GRID_COLUMN_GAP, "-5em")));
NUnit.Framework.Assert.IsFalse(CssDeclarationValidationMaster.CheckDeclaration(new CssDeclaration(CommonCssConstants
.GRID_ROW_GAP, "10")));
}

[NUnit.Framework.Test]
public virtual void ChangeValidatorTest() {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public ImageRenderInfo(Stack<CanvasTag> canvasTagHierarchy, CanvasGraphicsState
/// <see cref="System.Drawing.Bitmap"/>
/// with
/// <see cref="iText.Kernel.Pdf.Xobject.PdfImageXObject.GetBufferedImage()"/>
/// ;
/// ; // Android-Conversion-Skip-Line (java.awt library isn't available on Android)
/// </description></item>
/// </list>
/// </remarks>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,21 @@ static CommonCssConstants() {
/// <summary>The Constant GRID_COLUMN_END.</summary>
public const String GRID_COLUMN_END = "grid-column-end";

/// <summary>The Constant GRID_COLUMN_GAP.</summary>
public const String GRID_COLUMN_GAP = "grid-column-gap";

/// <summary>The Constant GRID_COLUMN_START.</summary>
public const String GRID_COLUMN_START = "grid-column-start";

/// <summary>The Constant GRID_GAP.</summary>
public const String GRID_GAP = "grid-gap";

/// <summary>The Constant GRID_ROW_END.</summary>
public const String GRID_ROW_END = "grid-row-end";

/// <summary>The Constant GRID_ROW_GAP.</summary>
public const String GRID_ROW_GAP = "grid-row-gap";

/// <summary>The Constant GRID_ROW_START.</summary>
public const String GRID_ROW_START = "grid-row-start";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ static ShorthandResolverFactory() {
shorthandResolvers.Put(CommonCssConstants.TEXT_DECORATION, new TextDecorationShorthandResolver());
shorthandResolvers.Put(CommonCssConstants.FLEX, new FlexShorthandResolver());
shorthandResolvers.Put(CommonCssConstants.FLEX_FLOW, new FlexFlowShorthandResolver());
shorthandResolvers.Put(CommonCssConstants.GAP, new GapShorthandResolver());
shorthandResolvers.Put(CommonCssConstants.GAP, new GapShorthandResolver(CommonCssConstants.GAP));
shorthandResolvers.Put(CommonCssConstants.GRID_GAP, new GapShorthandResolver(CommonCssConstants.GRID_GAP));
shorthandResolvers.Put(CommonCssConstants.PLACE_ITEMS, new PlaceItemsShorthandResolver());
shorthandResolvers.Put(CommonCssConstants.COLUMNS, new ColumnsShorthandResolver());
shorthandResolvers.Put(CommonCssConstants.COLUMN_RULE, new ColumnRuleShortHandResolver());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,39 @@ You should have received a copy of the GNU Affero General Public License
using iText.StyledXmlParser.Css.Validate;

namespace iText.StyledXmlParser.Css.Resolve.Shorthand.Impl {
/// <summary>
/// Shorthand resolver for gap shorthand properties, can be used for
/// different gap properties like
/// <c>gap</c>
/// or
/// <c>grid-gap</c>.
/// </summary>
public class GapShorthandResolver : IShorthandResolver {
private static readonly ILogger LOGGER = ITextLogManager.GetLogger(typeof(GapShorthandResolver));
private readonly String gapShorthandProperty;

/// <summary>
/// Instantiates default
/// <see cref="GapShorthandResolver"/>
/// for
/// <c>gap</c>
/// shorthand.
/// </summary>
public GapShorthandResolver()
: this(CommonCssConstants.GAP) {
}

/// <summary>
/// Instantiates default
/// <see cref="GapShorthandResolver"/>
/// for passed gap shorthand.
/// </summary>
/// <param name="gapShorthandProperty">the name of the gap shorthand property</param>
public GapShorthandResolver(String gapShorthandProperty) {
this.gapShorthandProperty = gapShorthandProperty;
}

private static readonly ILogger LOGGER = ITextLogManager.GetLogger(typeof(iText.StyledXmlParser.Css.Resolve.Shorthand.Impl.GapShorthandResolver
));

/// <summary><inheritDoc/></summary>
public virtual IList<CssDeclaration> ResolveShorthand(String shorthandExpression) {
Expand All @@ -43,11 +74,11 @@ public virtual IList<CssDeclaration> ResolveShorthand(String shorthandExpression
}
if (CssTypesValidationUtils.ContainsInitialOrInheritOrUnset(shorthandExpression)) {
return HandleExpressionError(iText.StyledXmlParser.Logs.StyledXmlParserLogMessageConstant.INVALID_CSS_PROPERTY_DECLARATION
, CommonCssConstants.GAP, shorthandExpression);
, gapShorthandProperty, shorthandExpression);
}
if (String.IsNullOrEmpty(shorthandExpression)) {
return HandleExpressionError(iText.StyledXmlParser.Logs.StyledXmlParserLogMessageConstant.SHORTHAND_PROPERTY_CANNOT_BE_EMPTY
, CommonCssConstants.GAP, shorthandExpression);
, gapShorthandProperty, shorthandExpression);
}
String[] gapProps = iText.Commons.Utils.StringUtil.Split(shorthandExpression, " ");
if (gapProps.Length == 1) {
Expand All @@ -59,7 +90,7 @@ public virtual IList<CssDeclaration> ResolveShorthand(String shorthandExpression
}
else {
return HandleExpressionError(iText.StyledXmlParser.Logs.StyledXmlParserLogMessageConstant.INVALID_CSS_PROPERTY_DECLARATION
, CommonCssConstants.GAP, shorthandExpression);
, gapShorthandProperty, shorthandExpression);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,14 +85,16 @@ public CssDefaultValidator() {
defaultValidators.Put(CommonCssConstants.LINE_HEIGHT, new MultiTypeDeclarationValidator(new CssNumberValueValidator
(false), new CssLengthValueValidator(false), new CssPercentageValueValidator(false), normalValidator,
inheritInitialUnsetValidator));
defaultValidators.Put(CommonCssConstants.COLUMN_GAP, new MultiTypeDeclarationValidator(new CssLengthValueValidator
(false), new CssPercentageValueValidator(false), normalValidator));
MultiTypeDeclarationValidator gapValidator = new MultiTypeDeclarationValidator(new CssLengthValueValidator
(false), new CssPercentageValueValidator(false), normalValidator, inheritInitialUnsetValidator);
defaultValidators.Put(CommonCssConstants.COLUMN_GAP, gapValidator);
defaultValidators.Put(CommonCssConstants.GRID_COLUMN_GAP, gapValidator);
defaultValidators.Put(CommonCssConstants.COLUMN_WIDTH, new MultiTypeDeclarationValidator(new CssLengthValueValidator
(false), new CssPercentageValueValidator(false), new CssEnumValidator(CommonCssConstants.AUTO)));
defaultValidators.Put(CommonCssConstants.COLUMN_COUNT, new MultiTypeDeclarationValidator(new CssIntegerNumberValueValidator
(false, false), new CssEnumValidator(CommonCssConstants.AUTO)));
defaultValidators.Put(CommonCssConstants.ROW_GAP, new MultiTypeDeclarationValidator(new CssLengthValueValidator
(false), new CssPercentageValueValidator(false), normalValidator, inheritInitialUnsetValidator));
defaultValidators.Put(CommonCssConstants.ROW_GAP, gapValidator);
defaultValidators.Put(CommonCssConstants.GRID_ROW_GAP, gapValidator);
defaultValidators.Put(CommonCssConstants.FLEX_GROW, new MultiTypeDeclarationValidator(new CssNumberValueValidator
(false), inheritInitialUnsetValidator));
defaultValidators.Put(CommonCssConstants.FLEX_SHRINK, new MultiTypeDeclarationValidator(new CssNumberValueValidator
Expand Down
2 changes: 1 addition & 1 deletion port-hash
Original file line number Diff line number Diff line change
@@ -1 +1 @@
14594176c3df587ff53e54994152bf09ca64d596
5a8f86d5e1ee424e95f9bae23d0ae30f8a971989

0 comments on commit c6432b3

Please sign in to comment.