Skip to content

Commit

Permalink
Fixed NumberFormatException for CSS image height auto.
Browse files Browse the repository at this point in the history
  • Loading branch information
ylussaud committed Nov 6, 2024
1 parent b0df89d commit 8517d18
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1920,9 +1920,13 @@ private void setOrderedListNumbering(Context context, Element element) {
type = STNumberFormat.NONE;
}

final long start;
long start;
if (element.hasAttr("start")) {
start = Long.valueOf(element.attr("start"));
try {
start = Long.valueOf(element.attr("start"));
} catch (NumberFormatException e) {
start = 1;
}
} else {
start = 1;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -504,11 +504,17 @@ protected void setCellWidth(MCell mCell, String width) {
} else {
int pixels = getPixels(width);
if (pixels == -1) {
pixels = Integer.valueOf(width);
try {
pixels = Integer.valueOf(width);
} catch (NumberFormatException e) {
pixels = -1;
}
}
if (pixels != -1) {
final double twipSize = pixels / (1d + 1d / 3d) * 20d;
mCell.setWidth((int) twipSize);
mCell.setWidthType(WidthType.DXA);
}
final double twipSize = pixels / (1d + 1d / 3d) * 20d;
mCell.setWidth((int) twipSize);
mCell.setWidthType(WidthType.DXA);
}
}

Expand All @@ -525,10 +531,16 @@ protected void setRowHeight(MRow row, String height) {
if (relativeHeight == -1) {
int pixels = getPixels(height);
if (pixels == -1) {
pixels = Integer.valueOf(height);
try {
pixels = Integer.valueOf(height);
} catch (NumberFormatException e) {
pixels = -1;
}
}
if (pixels != -1) {
row.setHeight(pixels * 10);
row.setHeightRule(HeightRule.AT_LEAST);
}
row.setHeight(pixels * 10);
row.setHeightRule(HeightRule.AT_LEAST);
}
}

Expand Down Expand Up @@ -572,9 +584,15 @@ private void setImageHeight(final MImage mImage, final String height) {
} else {
int pixels = getPixels(height);
if (pixels == -1) {
pixels = Integer.valueOf(height);
try {
pixels = Integer.valueOf(height);
} catch (NumberFormatException e) {
pixels = -1;
}
}
if (pixels != -1) {
mImage.setHeight(pixels);
}
mImage.setHeight(pixels);
}
}

Expand All @@ -593,9 +611,15 @@ private void setImageWidth(final MImage mImage, final String width) {
} else {
int pixels = getPixels(width);
if (pixels == -1) {
pixels = Integer.valueOf(width);
try {
pixels = Integer.valueOf(width);
} catch (NumberFormatException e) {
pixels = -1;
}
}
if (pixels != -1) {
mImage.setWidth(pixels);
}
mImage.setWidth(pixels);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,7 @@ public static void cleanResourceSetForModels(Object key, ResourceSet resourceSet
* Creates a sample template {@link XWPFDocument}.
*
* @param variableName
* the varaible name
* the variable name
* @param eCls
* the variable {@link EClass}
* @return the created sample template {@link XWPFDocument}
Expand Down

0 comments on commit 8517d18

Please sign in to comment.