// we have to check font/color etc at every character, not only at new positon because
//pos doesent change at tspans without new posinfo
//check if equal to last used font and if equal original text font
if ( fontChanged || textPositionChanged
){ //Make a new textarea if the text position changed or if the font changed at the current character
MTTextArea previousTextArea = null;
if (!textAreas.isEmpty()){
previousTextArea = textAreas.get(textAreas.size()-1);
}
float newXPos = 0;
float newYPos = 0 ;
//If there is a previous text, get its ending coordinates
//for the DX and DY shift info for the next text area
if (previousTextArea != null){
PositionAnchor oldAnchor = previousTextArea.getAnchor();
// previousTextArea.setAnchor(PositionAnchor.LOWER_RIGHT);
previousTextArea.setAnchor(PositionAnchor.UPPER_LEFT);
//Calculate last/current textposition for DX and DY use
//add up the last textareas start position end position(width)
Vector3D lastPos = previousTextArea.getPosition(TransformSpace.LOCAL);
// lastPos.addLocal(new Vector3D(previousTextArea.getWidthXY(TransformSpace.LOCAL) - 1 * previousTextArea.getInnerPaddingLeft(),0));
lastPos.addLocal(new Vector3D(previousTextArea.getWidthXY(TransformSpace.LOCAL) - 2 * previousTextArea.getInnerPaddingLeft(),0));
// newXPos = lastPos.x - previousTextArea.getInnerPaddingLeft();
newXPos = lastPos.x;
newXPos += (Float)previousTextArea.getUserData("XPos");
newYPos = lastPos.y;
// newYPos -= previousTextArea.getInnerPaddingTop();
// newYPos += fontToUse.getFontMaxDescent(); //FIXME WHY NEVESSARY?
newYPos += (Float)previousTextArea.getUserData("YPos");
previousTextArea.setAnchor(oldAnchor);
}
//IF absolute x or y is present overwrite the position values from the last textarea
if (charX != null)
newXPos = (Float)charX;
if (charY != null)
newYPos = (Float)charY;
if (charDX != null)
newXPos += (Float)charDX;
if (charDY != null)
newYPos += (Float)charDY;
// Create the text area \\
MTTextArea t = new MTTextArea(pa, fontToUse);
t.setNoFill(true);
t.setNoStroke(true);
textAreas.add(t);
try{
t.setLocalMatrix(new Matrix(currentLocalTransformMatrix));
}catch(Exception e){
logger.error(e.getMessage());
}
//FIXME TEST
// if (previousTextArea != null && !textPositionChange){
// t.setAnchor(PositionAnchor.LOWER_LEFT);
// t.setUserData("posRelParent", new Vector3D(newXPos , newYPos - fontToUse.getFontMaxDescent() , 0));
// logger.debug("Character '" + currentChar + "' -> Anchor: LOWER_LEFT");
// }else{
Value v = CSSUtilities.getComputedStyle(textElement, SVGCSSEngine.TEXT_ANCHOR_INDEX);
//INFO: we have to move the BASELINE of the text to the svg position
//The textarea is usually fontmaxascent+fontmaxdescent+2*innerPadding big!
switch (v.getStringValue().charAt(0)) {
case 'e':
t.setAnchor(PositionAnchor.LOWER_RIGHT);
t.setUserData("posRelParent", new Vector3D((newXPos + t.getInnerPaddingLeft()) , newYPos - fontToUse.getFontMaxDescent() + t.getInnerPaddingTop() , 0));
// t.setPositionRelativeToParent(new Vector3D(newXPos, newYPos - font.getFontMaxDescent() , 0));
logger.debug("Character '" + currentChar + "' -> Anchor: LOWER_RIGHT");
break;
case 'm': //text-anchor="middle"
t.setAnchor(PositionAnchor.CENTER);
// t.setUserData("posRelParent", new Vector3D(newXPos, newYPos - fontToUse.getFontMaxAscent()*0.5f - fontToUse.getFontMaxDescent()*0.5f , 0));
// t.setUserData("posRelParent", new Vector3D(newXPos, newYPos - fontToUse.getFontAbsoluteHeight()*0.5f + t.getInnerPaddingTop() , 0));
// t.setPositionRelativeToParent(new Vector3D(newXPos, newYPos - font.getFontMaxAscent()*0.5f - font.getFontMaxDescent()*0.5f, 0)); //- font.getFontMaxAscent()*0.5f
logger.debug("Character '" + currentChar + "' -> Anchor: CENTER");
t.setUserData("posRelParent", new Vector3D((newXPos), (newYPos - fontToUse.getFontMaxDescent() + t.getInnerPaddingTop()) - t.getHeightXY(TransformSpace.LOCAL)/2f , 0));
break;
default: //text-anchor="start" //default!
t.setAnchor(PositionAnchor.LOWER_LEFT);
// t.setUserData("posRelParent", new Vector3D(newXPos -t.getInnerPaddingLeft(), newYPos - fontToUse.getFontMaxDescent() + t.getInnerPaddingTop() , 0));
t.setUserData("posRelParent", new Vector3D(newXPos -t.getInnerPaddingLeft(), newYPos - fontToUse.getFontMaxDescent() + t.getInnerPaddingTop() , 0));
// t.setAnchor(PositionAnchor.UPPER_LEFT);
// t.setUserData("posRelParent", new Vector3D(newXPos -t.getInnerPaddingLeft(), newYPos, 0));
// t.setPositionRelativeToParent(new Vector3D(newXPos, newYPos - font.getFontMaxDescent() , 0));
logger.debug("Character '" + currentChar + "' -> Anchor: LOWER_LEFT");
}
t.setUserData("XPos", newXPos);
t.setUserData("YPos", newYPos);
// }
}
//Add character to the current textarea in the list
if (!textAreas.isEmpty()){
textAreas.get(textAreas.size()-1).appendCharByUnicode(new Character(currentChar).toString());
}
}
//Set the positions of the textareas
for (Iterator<MTTextArea> iterator = textAreas.iterator(); iterator.hasNext();) {
MTTextArea textArea = (MTTextArea) iterator.next();
logger.debug("Adding text area at: " + (Vector3D) textArea.getUserData("posRelParent"));
textArea.setPositionRelativeToParent((Vector3D) textArea.getUserData("posRelParent"));
}
comps.addAll(textAreas);
}
/*