private static void adjustBoxForFloatRight(Rectangle layoutBox, float blockWidth) { layoutBox.setX(layoutBox.getRight() - blockWidth); layoutBox.setWidth(blockWidth); }
private static void adjustBoxForFloatRight(Rectangle layoutBox, float blockWidth) { layoutBox.setX(layoutBox.getRight() - blockWidth); layoutBox.setWidth(blockWidth); }
protected LineRenderer trimLast() { int lastIndex = childRenderers.size(); IRenderer lastRenderer = null; while (--lastIndex >= 0) { lastRenderer = childRenderers.get(lastIndex); if (!FloatingHelper.isRendererFloating(lastRenderer)) { break; } } if (lastRenderer instanceof TextRenderer && lastIndex >= 0) { float trimmedSpace = ((TextRenderer) lastRenderer).trimLast(); occupiedArea.getBBox().setWidth(occupiedArea.getBBox().getWidth() - trimmedSpace); } return this; }
private void adjustPositionedRendererLayoutBoxWidth(IRenderer renderer, Rectangle fullBbox, Float left, Float right) { if (left != null) { fullBbox.setWidth(fullBbox.getWidth() - (float) left).setX(fullBbox.getX() + (float) left); } if (right != null) { fullBbox.setWidth(fullBbox.getWidth() - (float) right); } if (left == null && right == null && !renderer.hasProperty(Property.WIDTH)) { // Other, non-block renderers won't occupy full width anyway MinMaxWidth minMaxWidth = renderer instanceof BlockRenderer ? ((BlockRenderer) renderer).getMinMaxWidth() : null; if (minMaxWidth != null && minMaxWidth.getMaxWidth() < fullBbox.getWidth()) { fullBbox.setWidth(minMaxWidth.getMaxWidth() + AbstractRenderer.EPS); } } }
protected LineRenderer trimLast() { int lastIndex = childRenderers.size(); IRenderer lastRenderer = null; while (--lastIndex >= 0) { lastRenderer = childRenderers.get(lastIndex); if (!FloatingHelper.isRendererFloating(lastRenderer)) { break; } } if (lastRenderer instanceof TextRenderer && lastIndex >= 0) { float trimmedSpace = ((TextRenderer) lastRenderer).trimLast(); occupiedArea.getBBox().setWidth(occupiedArea.getBBox().getWidth() - trimmedSpace); } return this; }
private void adjustPositionedRendererLayoutBoxWidth(IRenderer renderer, Rectangle fullBbox, Float left, Float right) { if (left != null) { fullBbox.setWidth(fullBbox.getWidth() - (float) left).setX(fullBbox.getX() + (float) left); } if (right != null) { fullBbox.setWidth(fullBbox.getWidth() - (float) right); } if (left == null && right == null && !renderer.hasProperty(Property.WIDTH)) { // Other, non-block renderers won't occupy full width anyway MinMaxWidth minMaxWidth = renderer instanceof BlockRenderer ? ((BlockRenderer) renderer).getMinMaxWidth() : null; if (minMaxWidth != null && minMaxWidth.getMaxWidth() < fullBbox.getWidth()) { fullBbox.setWidth(minMaxWidth.getMaxWidth() + AbstractRenderer.EPS); } } }
/** * Gets the maximum area that the barcode and the text, if * any, will occupy. The lower left corner is always (0, 0). * * @return the size the barcode occupies. */ public Rectangle getBarcodeSize() { Rectangle rect = ean.getBarcodeSize(); rect.setWidth(rect.getWidth() + supp.getBarcodeSize().getWidth() + n); return rect; }
@Override public Rectangle getOccupiedAreaBBox() { Rectangle bBox = occupiedArea.getBBox().clone(); Float rotationAngle = this.<Float>getProperty(Property.ROTATION_ANGLE); if (rotationAngle != null) { if (!hasOwnProperty(Property.ROTATION_INITIAL_WIDTH) || !hasOwnProperty(Property.ROTATION_INITIAL_HEIGHT)) { Logger logger = LoggerFactory.getLogger(BlockRenderer.class); logger.error(MessageFormatUtil.format(LogMessageConstant.ROTATION_WAS_NOT_CORRECTLY_PROCESSED_FOR_RENDERER, getClass().getSimpleName())); } else { bBox.setWidth((float) this.getPropertyAsFloat(Property.ROTATION_INITIAL_WIDTH)); bBox.setHeight((float) this.getPropertyAsFloat(Property.ROTATION_INITIAL_HEIGHT)); } } return bBox; }
@Override public Rectangle getOccupiedAreaBBox() { Rectangle bBox = occupiedArea.getBBox().clone(); Float rotationAngle = this.<Float>getProperty(Property.ROTATION_ANGLE); if (rotationAngle != null) { if (!hasOwnProperty(Property.ROTATION_INITIAL_WIDTH) || !hasOwnProperty(Property.ROTATION_INITIAL_HEIGHT)) { Logger logger = LoggerFactory.getLogger(BlockRenderer.class); logger.error(MessageFormatUtil.format(LogMessageConstant.ROTATION_WAS_NOT_CORRECTLY_PROCESSED_FOR_RENDERER, getClass().getSimpleName())); } else { bBox.setWidth((float) this.getPropertyAsFloat(Property.ROTATION_INITIAL_WIDTH)); bBox.setHeight((float) this.getPropertyAsFloat(Property.ROTATION_INITIAL_HEIGHT)); } } return bBox; }
void applyWidth(Rectangle parentBBox, Float blockWidth, OverflowPropertyValue overflowX) { // maxWidth has already taken in attention in blockWidth, // therefore only `parentBBox > minWidth` needs to be checked. Float rotation = this.getPropertyAsFloat(Property.ROTATION_ANGLE); if (blockWidth != null && ( blockWidth < parentBBox.getWidth() || isPositioned() || rotation != null || (!isOverflowFit(overflowX)))) { parentBBox.setWidth((float) blockWidth); } else { Float minWidth = retrieveMinWidth(parentBBox.getWidth()); //Shall we check overflow-x here? if (minWidth != null && minWidth > parentBBox.getWidth()) { parentBBox.setWidth((float) minWidth); } } }
void applyWidth(Rectangle parentBBox, Float blockWidth, OverflowPropertyValue overflowX) { // maxWidth has already taken in attention in blockWidth, // therefore only `parentBBox > minWidth` needs to be checked. Float rotation = this.getPropertyAsFloat(Property.ROTATION_ANGLE); if (blockWidth != null && ( blockWidth < parentBBox.getWidth() || isPositioned() || rotation != null || (!isOverflowFit(overflowX)))) { parentBBox.setWidth((float) blockWidth); } else { Float minWidth = retrieveMinWidth(parentBBox.getWidth()); //Shall we check overflow-x here? if (minWidth != null && minWidth > parentBBox.getWidth()) { parentBBox.setWidth((float) minWidth); } } }
void shrinkOccupiedAreaForAbsolutePosition() { // In case of absolute positioning and not specified left, right, width values, the parent box is shrunk to fit // the children. It does not occupy all the available width if it does not need to. if (isAbsolutePosition()) { Float left = this.getPropertyAsFloat(Property.LEFT); Float right = this.getPropertyAsFloat(Property.RIGHT); UnitValue width = this.<UnitValue>getProperty(Property.WIDTH); if (left == null && right == null && width == null) { occupiedArea.getBBox().setWidth(0); } } }
void shrinkOccupiedAreaForAbsolutePosition() { // In case of absolute positioning and not specified left, right, width values, the parent box is shrunk to fit // the children. It does not occupy all the available width if it does not need to. if (isAbsolutePosition()) { Float left = this.getPropertyAsFloat(Property.LEFT); Float right = this.getPropertyAsFloat(Property.RIGHT); UnitValue width = this.<UnitValue>getProperty(Property.WIDTH); if (left == null && right == null && width == null) { occupiedArea.getBBox().setWidth(0); } } }
private void adjustLineOnFloatPlaced(Rectangle layoutBox, int childPos, FloatPropertyValue kidFloatPropertyVal, Rectangle justPlacedFloatBox) { if (justPlacedFloatBox.getBottom() >= layoutBox.getTop() || justPlacedFloatBox.getTop() < layoutBox.getTop()) { return; } boolean ltr = true; // TODO handle it float floatWidth = justPlacedFloatBox.getWidth(); if (kidFloatPropertyVal.equals(FloatPropertyValue.LEFT)) { layoutBox.setWidth(layoutBox.getWidth() - floatWidth).moveRight(floatWidth); occupiedArea.getBBox().moveRight(floatWidth); if (ltr) { for (int i = 0; i < childPos; ++i) { IRenderer prevChild = childRenderers.get(i); if (!FloatingHelper.isRendererFloating(prevChild)) { prevChild.move(floatWidth, 0); } } } } else { layoutBox.setWidth(layoutBox.getWidth() - floatWidth); if (!ltr) { // TODO } } }
private void adjustLineOnFloatPlaced(Rectangle layoutBox, int childPos, FloatPropertyValue kidFloatPropertyVal, Rectangle justPlacedFloatBox) { if (justPlacedFloatBox.getBottom() >= layoutBox.getTop() || justPlacedFloatBox.getTop() < layoutBox.getTop()) { return; } boolean ltr = true; // TODO handle it float floatWidth = justPlacedFloatBox.getWidth(); if (kidFloatPropertyVal.equals(FloatPropertyValue.LEFT)) { layoutBox.setWidth(layoutBox.getWidth() - floatWidth).moveRight(floatWidth); occupiedArea.getBBox().moveRight(floatWidth); if (ltr) { for (int i = 0; i < childPos; ++i) { IRenderer prevChild = childRenderers.get(i); if (!FloatingHelper.isRendererFloating(prevChild)) { prevChild.move(floatWidth, 0); } } } } else { layoutBox.setWidth(layoutBox.getWidth() - floatWidth); if (!ltr) { // TODO } } }
private void restoreLayoutBoxAfterFailedLayoutAttempt(Rectangle layoutBox) { layoutBox.setX(backupLayoutBox.getX()).setY(backupLayoutBox.getY()) .setWidth(backupLayoutBox.getWidth()).setHeight(backupLayoutBox.getHeight()); backupCollapseInfo.copyTo(collapseInfo); backupLayoutBox = null; backupCollapseInfo = null; }
private void restoreLayoutBoxAfterFailedLayoutAttempt(Rectangle layoutBox) { layoutBox.setX(backupLayoutBox.getX()).setY(backupLayoutBox.getY()) .setWidth(backupLayoutBox.getWidth()).setHeight(backupLayoutBox.getHeight()); backupCollapseInfo.copyTo(collapseInfo); backupLayoutBox = null; backupCollapseInfo = null; }
void fixOccupiedAreaIfOverflowedX(OverflowPropertyValue overflowX, Rectangle layoutBox) { if (isOverflowFit(overflowX)) { return; } if ((occupiedArea.getBBox().getWidth() > layoutBox.getWidth() || occupiedArea.getBBox().getLeft() < layoutBox.getLeft())) { occupiedArea.getBBox().setX(layoutBox.getX()).setWidth(layoutBox.getWidth()); } }
void fixOccupiedAreaIfOverflowedX(OverflowPropertyValue overflowX, Rectangle layoutBox) { if (isOverflowFit(overflowX)) { return; } if ((occupiedArea.getBBox().getWidth() > layoutBox.getWidth() || occupiedArea.getBBox().getLeft() < layoutBox.getLeft())) { occupiedArea.getBBox().setX(layoutBox.getX()).setWidth(layoutBox.getWidth()); } }
float trimLast() { float trimmedSpace = 0; if (line.end <= 0) return trimmedSpace; UnitValue fontSize = (UnitValue) this.getPropertyAsUnitValue(Property.FONT_SIZE); if (!fontSize.isPointValue()) { Logger logger = LoggerFactory.getLogger(TextRenderer.class); logger.error(MessageFormatUtil.format(LogMessageConstant.PROPERTY_IN_PERCENTS_NOT_SUPPORTED, Property.FONT_SIZE)); } Float characterSpacing = this.getPropertyAsFloat(Property.CHARACTER_SPACING); Float wordSpacing = this.getPropertyAsFloat(Property.WORD_SPACING); float hScale = (float) this.getPropertyAsFloat(Property.HORIZONTAL_SCALING, 1f); int firstNonSpaceCharIndex = line.end - 1; while (firstNonSpaceCharIndex >= line.start) { Glyph currentGlyph = line.get(firstNonSpaceCharIndex); if (!TextUtil.isWhitespace(currentGlyph)) { break; } saveWordBreakIfNotYetSaved(currentGlyph); float currentCharWidth = getCharWidth(currentGlyph, fontSize.getValue(), hScale, characterSpacing, wordSpacing) / TEXT_SPACE_COEFF; float xAdvance = firstNonSpaceCharIndex > line.start ? scaleXAdvance(line.get(firstNonSpaceCharIndex - 1).getXAdvance(), fontSize.getValue(), hScale) / TEXT_SPACE_COEFF : 0; trimmedSpace += currentCharWidth - xAdvance; occupiedArea.getBBox().setWidth(occupiedArea.getBBox().getWidth() - currentCharWidth); firstNonSpaceCharIndex--; } line.end = firstNonSpaceCharIndex + 1; return trimmedSpace; }