[jawsscripts] FindRichText function

  • From: "Veli" <vebazu@xxxxxxxxxxx>
  • To: <jawsscripts@xxxxxxxxxxxxx>
  • Date: Mon, 14 Apr 2008 16:39:29 +0300

Hello,

Now I've implemented in JAWS scripting language the FindRichText
function described at:

http://msdn2.microsoft.com/en-us/library/bb787724(VS.85).aspx#tom_finding_rich_text

However, there are still two problems to solve; i.e. input dialog that
supports rich text, and how to get cursor to the found string (at the
moment, the function returns the length of matched string).

Here is the JAWS code of this function:

int Function FindRichText (
object ppr, ;Pointer to range to search
object pr1) ;Range with rich text to find
var
string bstr, ;pr1 plain-text to search for
int cch, ;Text string count
int cch1, int cch2, ;tomCharFormat run char counts
int cchMatch, ;Length of matched string
int cp, ;Handy char position
int cpFirst1, ;pr1 cpFirst
int cpFirst2, ;pr2 cpFirst
object pf1, object pf2, ;Fonts corresponding to IPs prip1 and prip2
object pr2, ;Range duplicate to search with
object prip1, object prip2, ;Insertion points to walk pr1, pr2
object oNull, int cfMatch, int iNull, int nBreak
If (!ppr || !ppr || !pr1) Then
SayString("Invalid argument")
Return 0 ;E_INVALIDARG;
EndIf
; Initialize range and font objects used in search
Let pr2 = ppr.Duplicate
Let prip1 = pr1.Duplicate
Let prip2 = pr2.Duplicate
Let pf1 = prip1.Font
Let pf2 = prip2.Font
Let bstr = pr1.Text
If (!pr2 || !prip1 || !prip2 || !pf1 || !pf2 || !bstr) Then
SayString("Out of memory")
Return 0 ;E_OUTOFMEMORY;
EndIf
Let cpFirst1 = pr1.Start
; Keep searching till rich text is matched or no more plain-text hits
Let nBreak = false
Let cchMatch = 0 ;Nothing matched yet
Let cch = pr2.FindText(bstr, tomForward, 0)
While (!cchMatch && (cch == StringLength(bstr)))
Let cpFirst2 = pr2.Start ;pr2 is a new trial range
prip1.SetRange(cpFirst1, cpFirst1) ;Set up IPs to scan match
prip2.SetRange(cpFirst2, cpFirst2) ;and trial ranges
Let nBreak = false
While (!nBreak && cch > 0 && pf1.IsEqual(pf2)) ;Walk match & trial
ranges together comparing font properties
Let cch1 = prip1.Start
Let iNull = prip1.Move(tomCharFormat, 1)
Let cp = prip1.Start
Let cch1 = cp - cch1 ;cch of next match font run
Let cch2 = prip2.Start
Let iNull = prip2.Move(tomCharFormat, 1)
Let cp = prip2.Start
Let cch2 = cp - cch2 ;cch of next trial font run
If (cch1 < cch) Then ;There is more to compare
If (cch1 != cch2) Then ;Different run lengths: no formatting match
Let cch = pr2.FindText(bstr, cpFirst2+1, 0)
Let nBreak = true
Else
Let cch = cch - cch1 ;Matched format run
EndIf
ElIf (cch2 < cch) Then ;Trial range format run too short
Let nBreak = true
Else ;Both match and trial runs reach at least to match
Let cp = pr2.End ;text end: rich-text match
ppr.SetRange(cpFirst2, cp) ;Set input range to hit
Let cchMatch = cp - cpFirst2 ;coordinates and return length of matched
string
Let nBreak = true
EndIf
EndWhile
EndWhile
Let pr2 = oNull
Let prip1 = oNull
Let prip2 = oNull
Let pf1 = oNull
Let pf2 = oNull
Let bstr = ""
Return cchMatch
EndFunction

--
Veli



__________ 
View the list's information and change your settings at //www.freelists.org/list/jawsscripts

Other related posts:

  • » [jawsscripts] FindRichText function