word.object.model how to detect if range's word is hyphenated

113 Views Asked by At

I'm writing a spellchecker in VB.NET. To highlight the words, I use the GetPoint() method to get the coordinates/bounding box of that word. A problem occurs when the misspelled word is hyphenated as GetPoint() returns a huge box (containing both lines of the hyphenated word from start to end of the line).

I have not yet found a way to detect whether a range is hyphenated and if so, get the coordinates of both boxes. Both boxes here meaning, the box for the first part of the hyphenated word at the end of the line and the second box being the box of the second part of the word in the new line.

I have tried both TextRetrievalMode and IncludeHiddenText and checked if the .Text of the range has any hidden characters, but there isn't any such thing. Is there a way to do this? Ideally, I would like to have two boxes for each part of the hyphenated word.

As you can see in the image, when the misspelled word ανθρπος is hyphenated, the orange box is huge, contains two document lines and starts from the beginning and up to the end. The word καλλός is also misspelled. It's there just as a reference as a second misspelled word.

ms

This is the function that gets the current word's (range) rectangle:

Public Function getRangeRectangle(w As Word.Window, r As Word.Range) As System.Drawing.Rectangle
    Dim left As Integer
    Dim top As Integer
    Dim width As Integer
    Dim height As Integer
    Try
        'r.TextRetrievalMode.IncludeFieldCodes = True
        'r.TextRetrievalMode.IncludeHiddenText = True
        w.GetPoint(left, top, width, height, r)

        'getRangeRectangle = New System.Drawing.Rectangle(left, top, width, (wa.PointsToPixels(r.Font.Size) + 3) * (wa.ActiveDocument.ActiveWindow.View.Zoom.Percentage / 100))
        getRangeRectangle = New System.Drawing.Rectangle(left, top, width, height)
        gfrm_Drawing.DrawRectangle(getRangeRectangle, System.Drawing.Color.Orange)
        'If (i > 0) Then r.MoveEnd(Word.WdUnits.wdCharacter, i)
    Catch ex As Exception
        getRangeRectangle = New System.Drawing.Rectangle()
        'MsgBox(getRangeRectangle.X & ":" & getRangeRectangle.Y & ":" & getRangeRectangle.Height & ":" & getRangeRectangle.Width)
        'MsgBox("getRangeRectangle: " & r.Text & r.Start & ":" & ex.ToString())
    Finally
    End Try
End Function
0

There are 0 best solutions below