Page 1 of 2

Author:  kamran [ 2009-06-16 10:07:29 ]
Post subject:  kashida

I am looking for a way to auto insert kashida (tatweel) in frasi/arabic. Help.

Author:  martin [ 2009-06-16 10:22:01 ]
Post subject:  Re: kashida

The macro code to insert a tatweel character (unicode code point U+0640) is:
Type Text "ـ"

Or if you prefer:
Type Text "\u0640"

Author:  kamran [ 2009-06-16 11:16:51 ]
Post subject:  Re: kashida

Thank you Martin and Hamid.

I guess I should have emphasized AUTO insertion. In the olden/classic days, there was a ruler macro (I think) that could be used to randomly insert kashida to balance the lines. I was/am hoping if someone has done something similar for Nisus Pro. Thanks.

Author:  Hamid [ 2009-06-16 11:28:12 ]
Post subject:  Re: kashida

In NWE/NWP there is nothing which corresponds to Forced Justify Tab of NW Classic. This feature is crucial for justifying symmetrically two hemistichs of Arabic/Persian poetry on a single line.
I made this feature request a long time ago.

In the meantime you can try the Format:Kern:Loosen menu.

Author:  kamran [ 2009-06-16 11:47:07 ]
Post subject:  Re: kashida

Thanks, Hamid. May be it is time to learn perl :)

Author:  martin [ 2009-06-16 11:55:15 ]
Post subject:  Re: kashida

Hamid is right, there's no way to automatically force kashidas for a single line. However, they should appear for justified text that has wrapped to the next line.

Author:  kamran [ 2009-06-16 12:22:09 ]
Post subject:  Re: kashida

But, Martin, if you wrap-justify poetry to next line, someone is bound to come looking for you with a hatchet!

Author:  martin [ 2009-06-16 13:29:17 ]
Post subject:  Re: kashida

haha, sorry I wasn't thinking about your safety :P Consider me freshly educated.

Author:  kamran [ 2009-06-16 14:19:57 ]
Post subject:  Re: kashida

Now that I have dodged the hatchet...

I have no idea how nisus macros work or written - but this is what I would like to do:

for selected text,
(a) find maximum width of line from the ruler (between the margins or between two tabs) - in points?,
(b) for each line in selection (marked by tabs or paragraph mark at end) (1) find its length, (2) while insertion of a character (kashida) will not make the line wrap over, insert kashida at the first possible insertion point (kashida can only be inserted after certain characters), (3) then at the next possible insertion point, (4) loop over the line if necessary, (5) endwhile

Is that easy to do?

Author:  martin [ 2009-06-16 16:05:48 ]
Post subject:  Re: kashida

There's definitely no way to do that now, though the idea is quite interesting. I'll file some enhancement requests that would allow the writing of such a macro, thanks.

Author:  Hamid [ 2009-06-17 00:38:32 ]
Post subject:  Re: kashida

Here is an example to show how kerning, both Tighten and Loosen as appropriate, can be used to workaround this layout problem.
The following screenshot shows Layout 1 entered without kerning, and Layout 2 with kerning applied:

kerning.png [ 26.08 KiB | Viewed 8283 times ]

Author:  kamran [ 2009-06-17 08:32:21 ]
Post subject:  Re: kashida

Thanks, Hamid.

Use of kerning is nice, but manual. In the similar vein, one could insert the Kashida manually as well - and that is what I currently do .


Perhaps I was too ambitious :) . How about

For selected text

for each line delimited by a paragraph mark
if (line has not wrapped over)
(1) Move insertion point after the NEXT character in a <list of possible unicode ranges: u0628, u062a-e, 0633-a, etc.>
(2) If insertion point at the paragraph mark, move to the beginning of line and do (1)
(3) Insert "\u0640"
undo last Insert "\u0640"

Author:  martin [ 2009-06-17 12:08:53 ]
Post subject:  Re: kashida

Thanks for the more detailed list of steps, but the problem is checking whether or not the line has wrapped. There's currently no way for a macro to check that state. I'll file it as something we should add, thanks!

Author:  kamran [ 2009-06-18 09:46:04 ]
Post subject:  Re: kashida

No instant gratification? seriously, thanks for listening - let me know when it happens.

Author:  martin [ 2009-07-06 16:57:30 ]
Post subject:  Re: kashida

It should now be possible to write such a macro using NWP 1.3. Here's one that does so for English text by inserting spaces between words. It always works on the last line of the current paragraph:
$insertChar = " "
$insertAfterPattern = ' '
$clearPattern = ' {2,}'
$clearReplacement = ' '

# check to make sure we have a text selection with some text in it
$sel =
If ! $sel
$text = $sel.text
If 0 == $text.length
$loc = $sel.location
If $loc >= $text.length
   $loc = $text.length - 1

# find last line in the paragraph
$paraRange = $text.rangeOfParagraphAtIndex($loc)
$lineRange = $paraRange
$nextAt = $paraRange.location
While $nextAt < $paraRange.bound
   $lineRange = $text.rangeOfLineAtIndex($nextAt)
   $nextAt = $lineRange.bound

# remove all insertions from the last time the macro was run
Replace All $clearPattern, $clearReplacement, 'EsS'
$lineRange = $text.rangeOfLineAtIndex($lineRange.location)

# expand the line by inserting the character until the line wraps over
$lastInsertedRange =$lineRange.location, 0)
$expectedLineLen = $lineRange.length
While $lineRange.length == $expectedLineLen
   # find the next valid insertion location
   $scanRange = Range.newWithLocationAndBound($lastInsertedRange.bound, $lineRange.bound)
   $found = Find Next $insertAfterPattern, 'Es'
   If ! $found
      If $scanRange.location != $lineRange.location
         $found = Find Next $insertAfterPattern, 'Es'
      If ! $found
         Die "No suitable place to insert the '$insertChar' character."
   # insert the character and adjust line info
   Select End
   Insert Text $insertChar
   $lastInsertedRange = TextSelection.activeRange
   $expectedLineLen += $insertChar.length
   $lineRange = $text.rangeOfLineAtIndex($lineRange.location)

# delete the insertion that pushed us over the edge of the line

For Arabic, you'd just want to change the top part. I don't know all the characters it's legal to insert a kashida after, so I've just used the few you gave me so far:
$insertChar = "\u0640"
$insertAfterPattern = '[\u0628\u062a-\u062e\u0633-\u063a]'
$clearPattern = $insertChar
$clearReplacement = ''

If you let me know the rest of the Arabic characters, I'd like to add them and post the full macro in our repository. Thanks!

Page 1 of 2 All times are UTC - 8 hours
Powered by phpBB® Forum Software © phpBB Group