in

connecting users of the CorelDRAW family of products

VBA TextRange class TextLineRects property returns incorrect values

Last post 07-23-2008 10:56 by janga. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 07-18-2008 12:20

    • janga
    • Not Ranked
    • Joined on 07-18-2008

    VBA TextRange class TextLineRects property returns incorrect values

    I am writing a program using the VBA interface (through VB.NET) to determine the bounding box dimensions of individual lines in an artistic text box so that I can determine if the text will fit within an ellipse and which lines will or will not fit. I have used both Chr(13) Chr(10) and Chr(13) as the line break characters and the result is the same.

    I'm using the TextRange.TextLineRects property to get the BoundingBox, but theTextLineRects property is undocumented in both the user guide and the draw_vba.chm file. The problem is the BoundingBox values are incorrect.

    Also the results differ depending on if your textbox contains 2 or more lines. After 2 lines some of the BoundingBox properties go to the correct values, but the bottom 2 lines are always incorrect.

    This is a list of the BoundingBox properties that are usually incorrect (especially on the last 2 lines)

    - Bottom
    - CenterY
    - Height
    - Left
    - Right
    - x
    - y

    I have checked tons of forums and submitted this to Corel but no one will talk to me. Does anyone know if this behaviour been reported? Am I using the feature incorrectly or has a fix been proposed?

    Any help you can give would be great.

    Code Sample:

    ' Where shape is an existing shape referenced earlier in the code
    ' I suggest using breakpoints or console print statements to evaluate the individual properties of the BoundingBox
    Dim lines As CorelDRAW.TextLines = Shape.Text.Frame.Range.Lines
    Dim line As CorelDRAW.TextRange

    Dim startNum
    Dim endNum
    Dim position
    Dim size
    Dim textLineRec
    Dim text

    For Each line In lines
    startNum = line.Start
    endNum = line.End
    position = line.Position
    size = line.Size

    ' returns the BoundingBox with incorrect values
    textLineRec = line.TextLineRects.BoundingBox
    text = line.Text
    Next

    End Sample:

  • 07-22-2008 8:47 In reply to

    Re: VBA TextRange class TextLineRects property returns incorrect values

     Have you checked oberonplace?  http://forum.oberonplace.com/forumdisplay.php?s=09cf12dd090d3ad8763c3df5b016e8a1&f=5

    Alex and the forum members have a great deal of knowledge to offer.Geeked

    HTH

    Andy

  • 07-22-2008 14:06 In reply to

    • janga
    • Not Ranked
    • Joined on 07-18-2008

    Re: VBA TextRange class TextLineRects property returns incorrect values

    Andy,

    Thank you for your response, I will see what the OberonPlace forum has to offer.

    If anyone else has a suggestion or fix I would still love to know.

     

  • 07-23-2008 10:56 In reply to

    • janga
    • Not Ranked
    • Joined on 07-18-2008

    Re: VBA TextRange class TextLineRects property returns incorrect values

    I've found a work around to this problem. As far as I can tell when the line is selected the line seperator is also selected and throughs off the calculations. This code returns correct dimensions for the entire line segment (although it doesn't look like it should). I have tested it with the following.

    • VB.NET and VBA
    • Artistic text boxes containing one or more lines of text (various sizes illustrates the point better)

    Try the following code to see the fix work.

    Sub CreateAllTextLineRects()
     Dim sTextLineRects As Shape
     Dim line As TextRange
     Dim newRange As TextRange
     Dim text As String

     For Each line In ActiveShape.text.Story.Lines
       ' redimension the TextRange to recalculate the dimensions
       line.SetRange line.Start, line.Start
       Set sTextLineRects = ActiveLayer.CreateCurve(line.TextLineRects)
     Next
    End Sub

    This also works,

    line.SetRange line.Start, line.End - 2

    but this doesn't

    line.SetRange line.Start, line.End - 1

    Please try this out and let me know if there are any holes in the work around. Also note this is a work around, not a solution. For a real solution please ask Corel!

Page 1 of 1 (4 items)
© 2008 Corel Corporation. CorelDRAW and the CorelDRAW Balloon are trademarks or registered trademarks of Corel Corporation. The content herein is in the form of a personal web log ("Blog") or forum posting. As such, the views expressed in this site are those of the participants and do not necessarily reflect the views of Corel Corporation, or its affiliates and their respective officers, directors, employees and agents. Terms and Conditions.