question

EmonHaque-1485 avatar image
0 Votes"
EmonHaque-1485 asked EmonHaque-1485 edited

Retaining cursive style

Previously I'd issue with that and that was solved with this approach for xaml and in code behind I don't have to do anything other than adding Run in TextBlock or Paragraph in a loop and everything works as expected so far except this:

137114-capture1.png

Here the selected word وَلَكِنّي has 4 parts and the rule is if there is two consecutive ن then replace the last one with ّ. In my code I've done that like this:

 ...   
 foreach (var ayah in surah) {
     var para = new Paragraph() { Tag = ayahNo++ };
     para.Inlines.Add(ayah.Words.First().Segments.First().Ayah + ") ");
     foreach (var word in ayah.Words) {
        ...
         foreach (var segment in word.Segments) {
             var text = new Run(segment.Content);
             ...
             if (text.Text.StartsWith("ن")) {
                 var last = (Run)para.Inlines.Last();
                 if(last.Text.EndsWith("ن")) {
                     text.Text = text.Text.Replace("ن", "ّ" /*shadda*/);
                 }
             }
             ...
             para.Inlines.Add(text);
         }
         para.Inlines.Add(" ");
     }
     doc.Blocks.Add(para);

for the FlowDocument BUT instead of joining the last segment ي with the previous نّ it renders it separately. In a separate project I've tested with TextBlock with Run as suggested before. These are in my MainWindow.xaml:

 <Grid ShowGridLines="True">
     <Grid.ColumnDefinitions>
         <ColumnDefinition/>
         <ColumnDefinition/>
     </Grid.ColumnDefinitions>
     <Grid.Resources>
         <Style TargetType="TextBlock">
             <Setter Property="FontFamily" Value="Scheherazade"/>
             <Setter Property="FontSize" Value="150"/>
             <Setter Property="HorizontalAlignment" Value="Center"/>
             <Setter Property="VerticalAlignment" Value="Center"/>
         </Style>
     </Grid.Resources>
     <TextBlock Text="لَكِنّي"/>
     <TextBlock Grid.Column="1" >
         <Run Text="لَكِن"/><Run Text="ّ"/><Run Text="ي"/>
     </TextBlock>
 </Grid>

ant this is what it produces:

137085-capture2.png

The correct style is on the left and the word on the right gets broken! How to fix that?

EDIT


One way to fix is, remove the first character from following Run and add the shadda in the previous Run. If the Text of the following Run is empty then ignore it like this:

 if (text.Text.StartsWith("ن")) {
     var last = (Run)para.Inlines.Last();
     if (last.Text.EndsWith("ن")) {
         last.Text += 'ّ' /*shadda*/;
         text.Text = text.Text.Remove(0, 1);
     }
 }
 ---
 if(!string.IsNullOrEmpty(text.Text)) para.Inlines.Add(text);

137048-capture3.png

It works BUT I don't get a separate color for the character ّ (shadda). Is it possible to get a separate color for that? I'm using this phonetic keyboard and to get the Arabic word, type lakinVy.

EDIT


Need a way to have separate colors for the diacritical marks. In some cases the conjugation is bit more complex where more than one character has to be dropped. For example these two كُنَّ and يُؤمِنَّ:

137033-x1.gif

only the َّ parts need a separate color (ie. كُن and يُؤمِن should have one color and َّ another color) BUT if I put these in separate Run with different Foreground, it renders those as separate blocks instead of retaining the original cursive style, there's a clear gap:

137029-capture4.png

between the styles of words on left and right. These are the xaml:

 <Grid ShowGridLines="True">
     <Grid.ColumnDefinitions>
         <ColumnDefinition/>
         <ColumnDefinition/>
     </Grid.ColumnDefinitions>
     <Grid.Resources>
         <Style TargetType="TextBlock">
             <Setter Property="FontFamily" Value="Scheherazade"/>
             <Setter Property="FontSize" Value="150"/>
             <Setter Property="HorizontalAlignment" Value="Center"/>
             <Setter Property="VerticalAlignment" Value="Center"/>
         </Style>
     </Grid.Resources>
     <StackPanel>
         <TextBlock Text="كُنَّ"/>
         <TextBlock Text="يُؤمِنَّ"/>
     </StackPanel>
     <StackPanel Grid.Column="1">
         <TextBlock>
             <Run Text="كُن"/><Run Foreground="Red" Text="َّ"/>
         </TextBlock>
         <TextBlock>
             <Run Text="يُؤمِن"/><Run Foreground="Red" Text="َّ"/>
         </TextBlock>
     </StackPanel>
 </Grid>

that produces that. Is there a way to fix this issue?

windows-wpf
x1.gif (231.2 KiB)
capture1.png (212.1 KiB)
capture2.png (36.3 KiB)
capture3.png (209.8 KiB)
capture4.png (57.8 KiB)
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

0 Answers