Question about wordOffset

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Jellobus
Posts: 317
Joined: Tue Dec 10, 2013 2:53 pm

Question about wordOffset

Post by Jellobus » Fri Sep 12, 2014 4:58 am

Hi All,

I have a word in the field to make it "italic". I used wordOffset function. Number of the "TITLES" constantly change in the field and all "TITLES" must be in italic.
I found that wordOffset returns only first value of "TITLES" but not second and third "TITLES" in the field. And what if there are 10 "TITLES" in the field? I need your advice. :mrgreen: Please see attached stack file.

Thanks in advance,

Louis
Attachments
wordOffset.zip
wordOffset
(823 Bytes) Downloaded 178 times
Last edited by Jellobus on Fri Sep 12, 2014 6:09 pm, edited 1 time in total.

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am
Location: Palo Alto

Re: Question about wordOffset

Post by Simon » Fri Sep 12, 2014 7:15 am

Great sample!

Here you go:

Code: Select all

   repeat with x = 1 to the number of words in fld "text"
   put wordoffset("title",field "text", tTitle)  into title1
   set the textstyle of word title1+ tTitle  of field "text" to "italic"
   put title1  + tTitle into tTitle
   end repeat
that words-to-skip always messes with me.

Mind you that makes italics out of any word that contains "title'

Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Jellobus
Posts: 317
Joined: Tue Dec 10, 2013 2:53 pm

Re: Question about wordOffset

Post by Jellobus » Fri Sep 12, 2014 8:32 am

Wow Thanks Simon!! :lol:

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4003
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Question about wordOffset

Post by bn » Fri Sep 12, 2014 8:59 am

Hi Louis,

try this:

Code: Select all

on mouseUp
   put 0 into tWordOffset
   put 0 into tLastWordFound
   set the caseSensitive to true
   lock screen
   repeat
      put wordOffset("TITLE",field "text",tLastWordFound) into tWordOffset
      if tWordOffset = 0 then -- no more found, exit but change last word found.
         set the textStyle of word tLastWordFound of field "text" to "italic"
         exit repeat
      end if
      set the textStyle of word tLastWordFound of field "text" to "italic"
      add tWordOffset  to tLastWordFound
   end repeat
   unlock screen
end mouseUp
BUT it will also italicize TITLE in your comment.

To achieve what your are after I would need to understand better what "TITLE" is. Apparently you know the complete title and the title is on a line on its own.

then you can use lineOffset

Code: Select all

on mouseUp
   put "TITLE1,TITLE2" into tTitleList
   
   set the caseSensitive to true
   lock screen
   repeat for each item aTitle in tTitleLIst
      put 0 into tLineOffset
      put 0 into tLastLIneFound
      repeat
         put lineOffset(aTitle,field "text",tLastLIneFound) into tLineOffset
         if tLineOffset = 0 then -- no more found, exit but change last line found.
            set the textStyle of line tLastLIneFound of field "text" to "italic"
            exit repeat
         end if
         set the textStyle of line tLastLIneFound of field "text" to "italic"
         add tLineOffset  to tLastLIneFound
      end repeat
   end repeat
   unlock screen
end mouseUp
The bad news is that currently 6.7RC1 and 7.0RC1 do not work with "italic". Probably a bug.

Kind regards

Bernd

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: Question about wordOffset

Post by Thierry » Fri Sep 12, 2014 9:17 am

... is that currently 6.7RC1 and 7.0RC1 do not work with "italic". Probably a bug.
Thanks Bernd,

I am doing massive html translation with LC7 and you saved me a lot of time
with this information :)

Freundliche Grüsse

Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

FredBeck
Posts: 77
Joined: Fri Nov 01, 2013 3:07 pm
Location: Paris
Contact:

Re: Question about wordOffset

Post by FredBeck » Fri Sep 12, 2014 9:30 am

Hi,
I found somewhere this function :
(sorry I can't remember where...)

Code: Select all

function FullOffset pWord pText
   local tList
   local tOffset
   repeat while tOffset <the number of words in pText
      get wordOffset(pWord, pText, tOffset)
      if it <> 0 then
         add it to tOffset
         put tOffset & cr after tList
      else
         exit repeat
      end if
   end repeat
   return tList
end FullOffset
so you can just paste it in your main stack script (or a library stack) and use it in place of wordOffset
and then loop the resulting list. Could be easier to write if you have a lot of formatting to do.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4003
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Question about wordOffset

Post by bn » Fri Sep 12, 2014 10:22 am

Hi Thierry,

I can not get italicize to work in 7.0 at all, not even when setting the htmlText. Only when using a font that is italic.

I don't know if it is a bug or has to do with the new font handling. Maybe if a font has no italic variant it will not work?
I am doing massive html translation with LC7
is this on a famous book from centuries ago? :)

Kind regards

Bernd

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: Question about wordOffset

Post by Thierry » Fri Sep 12, 2014 10:37 am

bn wrote:Hi Thierry,
I can not get italicize to work in 7.0 at all,
not even when setting the htmlText. Only when using a font that is italic.

I don't know if it is a bug or has to do with the new font handling.
Maybe if a font has no italic variant it will not work?
I've noticed this doesn't work
and put aside some notes to work on it later.
Seems that I will have nothing to do.
is this on a famous book from centuries ago? :)
Well, even a bit older I guess..

Now, I'm doing some hard regex to deal with
right to left language injected in a left to right one..

By the way,
KUDOS to LC7 Unicode runrev developers :)

Regards,
Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4003
Joined: Sun Jan 07, 2007 9:12 pm
Location: Bochum, Germany

Re: Question about wordOffset

Post by bn » Fri Sep 12, 2014 11:04 am

Hi Thierry and all,

I just looked up Quality Control Center and there is a bug report from Colin Holgate regarding italic

Bug 13392

Mark Waddingham answered:
I suspect this is to do with the font you are using.

We've upgraded Mac to use CoreText which doesn't support synthesized text styles unlike QuickDraw did.

The default Mac interface font (Lucida Grande) does *not* have an italic variant, hence why italic has no effect. (You can see exactly the same effect in Text Edit - if you attempt to italicize that font, it has no effect, and no Italic style is listed in the font inspector).
and further down
I have changed this report to an enhancement request so that we can look into changing the way the selection of font styles is presented.
I should have looked this up earlier.

So this means that one currently has to use a font that supports italic. But which ones do?

Thierry, you can go on working once you have found a font that supports plain and italic :)

I just tried on my Mac and these fonts work with italicize

Courier
Garamond
Helvetica
Helvetica Neue
Lucida Sans Regular
Arial
Verdana

many others might also work but I did not try all. Just the default font on Mac "Lucida Grande" does not work with italic.


Kind regards

Bernd

Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: Question about wordOffset

Post by Thierry » Fri Sep 12, 2014 11:10 am

bn wrote: I just looked up Quality Control Center and there is a bug report from Colin Holgate regarding italic
Bug 13392

Mark Waddingham answered:
I suspect this is to do with the font you are using.
I just tried on my Mac and these fonts work with italicize

Courier
Garamond
Helvetica
Helvetica Neue
Lucida Sans Regular
Arial
Verdana

many others might also work but I did not try all. Just the default font on Mac
"Lucida Grande" does not work with italic.
Thanks Bernd for this useful information!

Regards,

Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”