Skip to main content
Participant
May 22, 2014
Answered

Merging diagonal text together

  • May 22, 2014
  • 1 reply
  • 488 views

Hi I'm trying to merge these groups of text together but i'm having trouble keeping the spaces after i merge it with my current code.

BEFORE

AFTER

here is my current code

var textLayer = idoc.layers[0]

textLayer.name = "Text";

for (var i = 0; i < textLayer.groupItems.length; i++){

    var tempText = ""

   

    var anchor1 = textLayer.groupItems.textFrames[0].anchor

    var anchor2 = textLayer.groupItems.textFrames[1].anchor

   

    var TextOnAngle = IsTextOnAngle(anchor1[0],anchor1[1],anchor2[0],anchor2[1])

   

    var TextAngleDeg = TextAngle(anchor1[0],anchor1[1],anchor2[0],anchor2[1])

    for (var j = 0; j < textLayer.groupItems.textFrames.length; j++){

        if (j == 1){

            var newText = textLayer.groupItems.textFrames.duplicate(textLayer, ElementPlacement.INSIDE)

           

        }

        if (tempText == "") {

                tempText = textLayer.groupItems.textFrames.contents;

          } else {

                tempText = tempText + textLayer.groupItems.textFrames.contents;

               

                if(TextOnAngle){

                   

                    if(j+1 < textLayer.groupItems.textFrames.length){

                        var tempAnchor1 = textLayer.groupItems.textFrames.anchor

                        var tempAnchor2 = textLayer.groupItems.textFrames[j+1].anchor

                           

                        var CurrentAngle = TextAngle(tempAnchor1[0],tempAnchor1[1],tempAnchor2[0],tempAnchor2[1])

                           

                        if(!(CurrentAngle <= TextAngleDeg+5 && CurrentAngle >= TextAngleDeg-5)){

                           

                            //alert(CurrentAngle)

                                tempText = tempText + '\r'

                           

                        }

                    }

                }

           }

    };

    //var newText = textLayer.textFrames.add()

        newText.contents = tempText

};

textLayer.groupItems.removeAll()

//gets the angle of the text

function TextAngle(x1,y1,x2,y2){

    var xDiff = x1 - x2

    var yDiff = y1 - y2

    return Math.atan2(yDiff, xDiff) * (180 / Math.PI)

}

// works out if text is on an angle or not

function IsTextOnAngle(x1,y1,x2,y2){

    if((x1 >= x2-0.1 && x1 <= x2+0.1) || (y1 >= y2-0.1 && y1 <= y2+0.1)){

        return false

    }else{

        return true   

    }

}

//gets the angle of the text

function TextAngle(x1,y1,x2,y2){

    var xDiff = x1 - x2

    var yDiff = y1 - y2

    return Math.atan2(yDiff, xDiff) * (180 / Math.PI)

}

// works out if text is on an angle or not

function IsTextOnAngle(x1,y1,x2,y2){

    if((x1 >= x2-0.1 && x1 <= x2+0.1) || (y1 >= y2-0.1 && y1 <= y2+0.1)){

        return false

    }else{

        return true   

    }

}

}

if anyone has any ideas on how i can go about working out where to insert the spaces that would be great.

thanks in advance

This topic has been closed for replies.
Correct answer Larry G. Schneider

It may be easiest to rotate the text to horizontal, do the replacement of spaces and re-rotate the text. You could use a variable to store the rotation value.

1 reply

Larry G. Schneider
Community Expert
Community Expert
May 22, 2014

There are no spaces in your text right now. Notice there are no anchors indicated at the right side of the d and the 5 below it. The text is just being concatenated as is. What is generating the individual characters in the text now?

grimbotoAuthor
Participant
May 23, 2014

thanks larry it is being produced by a CAD program printing to PDF, I did realize there where no actual spaces but i don't know how i could work out where to insert a new space, If its horizontal you can just see if the next letters anchor point is at the current anchor point plus the width of the letter and if not add another space. But I'm not sure how to go about it for diagonal Text

Larry G. Schneider
Community Expert
Larry G. SchneiderCommunity ExpertCorrect answer
Community Expert
May 23, 2014

It may be easiest to rotate the text to horizontal, do the replacement of spaces and re-rotate the text. You could use a variable to store the rotation value.