private void handleLine( Settings elementSettings, String line, PropertiesConfig propCfg, BaseDrawHandler drawer) { boolean drawText = true; for (Facet facet : elementSettings.getFacets()) { if (facet.checkStart(line)) { facet.handleLine(line, drawer, propCfg); if (facet.replacesText(line)) { drawText = false; } } } if (drawText) { XPoints xLimitsForText = propCfg.getXLimitsForArea(propCfg.getyPos(), drawer.textHeight()); Float spaceNotUsedForText = propCfg.getGridElementSize().width - xLimitsForText.getSpace(); if (!spaceNotUsedForText.equals( Float.NaN)) { // NaN is possible if xlimits calculation contains e.g. a division by zero propCfg.calcMaxTextWidth(spaceNotUsedForText + drawer.textWidth(line)); } drawer.print( line, calcHorizontalTextBoundaries(xLimitsForText, propCfg), propCfg.getyPos(), propCfg.gethAlign()); propCfg.addToYPos(drawer.textHeightWithSpace()); } }
private float calcHorizontalTextBoundaries(XPoints xLimitsForText, PropertiesConfig propCfg) { float x; if (propCfg.gethAlign() == AlignHorizontal.LEFT) { x = xLimitsForText.getLeft() + drawer.getDistanceBetweenTexts(); } else if (propCfg.gethAlign() == AlignHorizontal.CENTER) { x = propCfg.getGridElementSize().width / 2; } else /*if (propCfg.gethAlign() == AlignHorizontal.RIGHT)*/ { x = xLimitsForText.getRight() - drawer.getDistanceBetweenTexts(); } return x; }
private DimensionFloat getExpectedElementDimensionsOnDefaultZoom(NewGridElement element) { // add all ypos changes to simulate the real ypos for xlimit calculation etc. PropertiesConfig tmpPropCfg = new PropertiesConfig(element.getSettings(), element.getRealSize()); tmpPropCfg.addToYPos( calcTopDisplacementToFitLine(calcStartPointFromVAlign(tmpPropCfg), tmpPropCfg)); handleWordWrapAndIterate(elementSettings, tmpPropCfg, drawer.getPseudoDrawHandler()); float textHeight = tmpPropCfg.getyPos() - drawer .textHeight(); // subtract last ypos step (because the print-text pos is always on // the bottom) return new DimensionFloat(tmpPropCfg.getMaxTextWidth(), textHeight); }
private void handleAutoresize(NewGridElement element) { if (getElementStyle() == ElementStyleEnum.AUTORESIZE) { DimensionFloat dim = getExpectedElementDimensionsOnDefaultZoom(element); float hSpaceLeftAndRight = drawer.getDistanceBetweenTexts() * 2; float width = dim.getWidth() + hSpaceLeftAndRight; float height = dim.getHeight() + drawer.textHeight() / 2; float diffw = width - element.getRealSize().width; float diffh = height - element.getRealSize().height; float diffwInCurrentZoom = diffw * element.getHandler().getZoomFactor(); float diffhInCurrentZoom = diffh * element.getHandler().getZoomFactor(); int diffwRealigned = element.getHandler().realignToGrid(false, diffwInCurrentZoom, true); int diffhRealigned = element.getHandler().realignToGrid(false, diffhInCurrentZoom, true); // use resize command to move sticked relations correctly with the element new Resize(element, 0, 0, diffwRealigned, diffhRealigned).execute(element.getHandler()); } }
private float calcTopDisplacementToFitLine(float startPoint, PropertiesConfig propCfg) { int BUFFER = 2; // a small buffer between text and outer border float displacement = startPoint; float textHeight = drawer.textHeight(); boolean wordwrap = getElementStyle() == ElementStyleEnum.WORDWRAP; if (!wordwrap && !propertiesTextToDraw .isEmpty()) { // in case of wordwrap or no text, there is no top displacement String firstLine = propertiesTextToDraw.iterator().next(); float availableWidthSpace = propCfg.getXLimitsForArea(displacement, textHeight).getSpace() - BUFFER; float accumulator = displacement; while (accumulator < propCfg.getGridElementSize().height && !TextManipulator.checkifStringFits(firstLine, availableWidthSpace, drawer)) { accumulator += textHeight / 2; float previousWidthSpace = availableWidthSpace; availableWidthSpace = propCfg.getXLimitsForArea(accumulator, textHeight).getSpace() - BUFFER; // only set displacement if the last iteration resulted in a space gain (eg: for UseCase // until the middle, for Class: stays on top because on a rectangle there is never a // width-space gain) if (availableWidthSpace > previousWidthSpace) displacement = accumulator; } } return displacement; }
private void handleWordWrapAndIterate( Settings elementSettings, PropertiesConfig propCfg, BaseDrawHandler drawer) { boolean wordwrap = getElementStyle() == ElementStyleEnum.WORDWRAP; for (String line : propertiesTextToDraw) { if (wordwrap) { String wrappedLine; while (propCfg.getyPos() < propCfg.getGridElementSize().height && !line.trim().isEmpty()) { Float spaceForText = propCfg.getXLimitsForArea(propCfg.getyPos(), drawer.textHeight()).getSpace() - drawer.getDistanceBetweenTexts() * 2; wrappedLine = TextManipulator.splitString(line, spaceForText, drawer); handleLine(elementSettings, wrappedLine, propCfg, drawer); line = line.substring(wrappedLine.length()).trim(); } } else handleLine(elementSettings, line, propCfg, drawer); } }
private float calcStartPointFromVAlign(PropertiesConfig propCfg) { float returnVal = drawer .textHeight(); // print method is located at the bottom of the text therefore add text // height (important for UseCase etc where text must not reach out of the // border) if (propCfg.getvAlign() == AlignVertical.TOP) { returnVal += drawer.textHeight() / 2; } else if (propCfg.getvAlign() == AlignVertical.CENTER) { returnVal += (propCfg.getGridElementSize().height - getTextBlockHeight(propCfg)) / 2; } else /*if (propCfg.getvAlign() == AlignVertical.BOTTOM)*/ { returnVal += propCfg.getGridElementSize().height - getTextBlockHeight(propCfg) - drawer.textHeight() / 2; } return returnVal; }
public float getTextBlockHeight(PropertiesConfig propCfg) { PropertiesConfig tmpPropCfg = new PropertiesConfig(elementSettings, propCfg.getGridElementSize()); handleWordWrapAndIterate(elementSettings, tmpPropCfg, drawer.getPseudoDrawHandler()); return tmpPropCfg.getyPos(); }